| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412 |
- /*
- ** Command & Conquer Renegade(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- // SelectPresetDialog.cpp : implementation file
- //
- #include "stdafx.h"
- #include "leveledit.h"
- #include "SelectPresetDialog.h"
- #include "presetmgr.h"
- #include "preset.h"
- #include "icons.h"
- #include "nodecategories.h"
- #include "definitionfactory.h"
- #include "definitionfactorymgr.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- //
- // SelectPresetDialogClass
- //
- /////////////////////////////////////////////////////////////////////////////
- SelectPresetDialogClass::SelectPresetDialogClass(CWnd* pParent /*=NULL*/)
- : m_ClassID (0),
- m_Preset (NULL),
- m_IconIndex (0),
- m_InitialSelection (NULL),
- m_AllowNoneSelection (true),
- CDialog(SelectPresetDialogClass::IDD, pParent)
- {
- //{{AFX_DATA_INIT(SelectPresetDialogClass)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // DoDataExchange
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- SelectPresetDialogClass::DoDataExchange (CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(SelectPresetDialogClass)
- DDX_Control(pDX, IDC_PRESET_TREE, m_TreeCtrl);
- //}}AFX_DATA_MAP
- return ;
- }
- BEGIN_MESSAGE_MAP(SelectPresetDialogClass, CDialog)
- //{{AFX_MSG_MAP(SelectPresetDialogClass)
- ON_WM_DESTROY()
- ON_NOTIFY(TVN_SELCHANGED, IDC_PRESET_TREE, OnSelchangedPresetTree)
- ON_BN_CLICKED(IDC_INFO, OnInfo)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnInitDialog
- //
- /////////////////////////////////////////////////////////////////////////////
- BOOL
- SelectPresetDialogClass::OnInitDialog (void)
- {
- CDialog::OnInitDialog ();
- CWaitCursor wait_cursor;
- //
- // Configure the tree control
- //
- m_TreeCtrl.SetImageList (::Get_Global_Image_List (), TVSIL_NORMAL);
- //
- // Determine if we should display all presets or just a specific branch
- // of the tree.
- //
- if (m_ClassID == 0) {
-
- //
- // Build the complete preset tree
- //
- Build_Full_Preset_Tree ();
- } else {
- //
- // Build the tree for just this branch of presets
- //
- Generate_Tree (m_ClassID, TVI_ROOT);
- }
- //
- // Add a way for the user to clear the selection
- //
- HTREEITEM none_entry = NULL;
- if (m_AllowNoneSelection) {
- none_entry = m_TreeCtrl.InsertItem ("<None>", NULL_ICON, NULL_ICON, TVI_ROOT, TVI_FIRST);
- }
- //
- // Select the correct entry (if necessary)
- //
- if (m_InitialSelection != NULL) {
- m_TreeCtrl.EnsureVisible (m_InitialSelection);
- m_TreeCtrl.SelectItem (m_InitialSelection);
- } else if (none_entry != NULL) {
- m_TreeCtrl.SelectItem (none_entry);
- }
- //
- // Change the window title if necessary
- //
- if (m_Title.GetLength () > 0) {
- SetWindowText (m_Title);
- }
- //
- // Change the dialog message if necessary
- //
- if (m_Message.GetLength () > 0) {
- SetDlgItemText (IDC_MESSAGE, m_Message);
- }
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Fill_Tree
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- SelectPresetDialogClass::Fill_Tree (NTreeLeafClass<PresetClass *> *leaf, HTREEITEM parent_item)
- {
- //
- // Loop over all the presets
- //
- for ( ; leaf != NULL; leaf = leaf->Peek_Next ()) {
- PresetClass *preset = leaf->Get_Value ();
- ASSERT (preset != NULL);
- if (preset != NULL) {
- //
- // Insert the new preset into the tree
- //
- int icon_index = preset->Get_Icon_Index ();
- HTREEITEM new_item = m_TreeCtrl.InsertItem (preset->Get_Name (), icon_index, icon_index, parent_item);
- if (new_item != NULL) {
- //
- // Associate the preset with its tree entry
- //
- m_TreeCtrl.SetItemData (new_item, (LONG)preset);
- //
- // Recurse if necessary
- //
- NTreeLeafClass<PresetClass *> *child = leaf->Peek_Child ();
- if (child != NULL) {
- Fill_Tree (child, new_item);
- m_TreeCtrl.SortChildren (parent_item);
- }
- //
- // Remember that we need to select this item
- //
- if (preset == m_Preset) {
- m_InitialSelection = new_item;
- }
- }
- }
- }
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnOK
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- SelectPresetDialogClass::OnOK (void)
- {
- //
- // Save the selected preset
- //
- HTREEITEM selected_item = m_TreeCtrl.GetSelectedItem ();
- if (selected_item != NULL) {
- m_Preset = (PresetClass *)m_TreeCtrl.GetItemData (selected_item);
- }
- CDialog::OnOK ();
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnDestroy
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- SelectPresetDialogClass::OnDestroy (void)
- {
- //
- // Remove the main image list we associated with the control
- //
- m_TreeCtrl.SetImageList (NULL, TVSIL_NORMAL);
- CDialog::OnDestroy ();
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Build_Full_Preset_Tree
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- SelectPresetDialogClass::Build_Full_Preset_Tree (void)
- {
- //
- // Add all the node categories to the list control
- //
- for (int index = 0; index < PRESET_CATEGORY_COUNT; index ++) {
- //
- // Add this factory to the tree
- //
- HTREEITEM tree_item = m_TreeCtrl.InsertItem (PRESET_CATEGORIES[index].name, FOLDER_ICON, FOLDER_ICON);
- m_IconIndex = PRESET_CATEGORIES[index].icon;
-
- //
- // Add all presets for this factory into the tree
- //
- Generate_Tree (PRESET_CATEGORIES[index].clsid, tree_item);
- //
- // Is there a factory to create this class of defintion?
- //
- /*DefinitionFactoryClass *factory = DefinitionFactoryMgrClass::Find_Factory (PRESET_CATEGORIES[index].clsid);
- if (factory == NULL) {
-
- //
- // Find all the sub-factories
- //
- for ( factory = DefinitionFactoryMgrClass::Get_First (PRESET_CATEGORIES[index].clsid);
- factory != NULL;
- factory = DefinitionFactoryMgrClass::Get_Next (factory, PRESET_CATEGORIES[index].clsid))
- {
- //
- // Add this sub-factory and all its definitions to the tree
- //
- LPCTSTR name = factory->Get_Name ();
- HTREEITEM child_item = m_TreeCtrl.InsertItem (factory->Get_Name (), FOLDER_ICON, FOLDER_ICON, tree_item);
- Generate_Tree (factory->Get_Class_ID (), child_item);
- }
- //
- // Sort the entries we just made
- //
- m_TreeCtrl.SortChildren (tree_item);
- }*/
- }
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Generate_Tree
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- SelectPresetDialogClass::Generate_Tree (int class_id, HTREEITEM parent_item)
- {
- //
- // Is there a factory to create this class of defintion?
- //
- DefinitionFactoryClass *factory = DefinitionFactoryMgrClass::Find_Factory (class_id);
- if (factory == NULL) {
-
- //
- // Find all the sub-factories
- //
- for ( factory = DefinitionFactoryMgrClass::Get_First (class_id);
- factory != NULL;
- factory = DefinitionFactoryMgrClass::Get_Next (factory, class_id))
- {
- //
- // Add this sub-factory and all its definitions to the tree
- //
- if (factory->Is_Displayed ()) {
- LPCTSTR name = factory->Get_Name ();
- HTREEITEM child_item = m_TreeCtrl.InsertItem (factory->Get_Name (), FOLDER_ICON, FOLDER_ICON, parent_item);
- Generate_Tree (factory->Get_Class_ID (), child_item);
- }
- }
- //
- // Sort the entries we just made
- //
- m_TreeCtrl.SortChildren (parent_item);
- } else {
- //
- // Generate the tree of presets
- //
- PRESET_TREE preset_tree;
- PresetMgrClass::Build_Preset_Tree (class_id, preset_tree);
- //
- // Populate the tree control
- //
- Fill_Tree (preset_tree.Peek_Root (), parent_item);
- }
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnSelchangedPresetTree
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- SelectPresetDialogClass::OnSelchangedPresetTree
- (
- NMHDR * pNMHDR,
- LRESULT * pResult
- )
- {
- NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
- (*pResult) = 0;
- //
- // Either disable or enable the OK button depending on if the user selected
- // a real preset or not...
- //
- HTREEITEM selected_item = m_TreeCtrl.GetSelectedItem ();
- if (selected_item != NULL) {
- PresetClass *preset = (PresetClass *)m_TreeCtrl.GetItemData (selected_item);
-
- if (m_AllowNoneSelection == false) {
- ::EnableWindow (::GetDlgItem (m_hWnd, IDOK), preset != NULL);
- }
- ::EnableWindow (::GetDlgItem (m_hWnd, IDC_INFO), preset != NULL);
- }
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnInfo
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- SelectPresetDialogClass::OnInfo (void)
- {
- HTREEITEM selected_item = m_TreeCtrl.GetSelectedItem ();
- if (selected_item != NULL) {
- PresetClass *preset = (PresetClass *)m_TreeCtrl.GetItemData (selected_item);
- if (preset != NULL) {
-
- //
- // Show the settings for this preset
- //
- preset->Show_Properties (true);
- }
- }
- return ;
- }
|