| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559 |
- /*
- ** 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/>.
- */
- /***********************************************************************************************
- *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
- ***********************************************************************************************
- * *
- * Project Name : Combat *
- * *
- * $Archive:: /Commando/Code/commando/dlgcontrolsaveload.cpp $*
- * *
- * Author:: Patrick Smith *
- * *
- * $Modtime:: 1/09/02 11:43a $*
- * *
- * $Revision:: 8 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "dlgcontrolsaveload.h"
- #include "resource.h"
- #include "listctrl.h"
- #include "dialogresource.h"
- #include "inputconfigmgr.h"
- #include "string_ids.h"
- #include "translatedb.h"
- ////////////////////////////////////////////////////////////////
- // Local constants
- ////////////////////////////////////////////////////////////////
- static enum
- {
- MBEVENT_DELETE_PROMPT = 1,
- MBEVENT_SAVE_PROMPT
- };
- ////////////////////////////////////////////////////////////////
- //
- // ControlSaveLoadMenuClass
- //
- ////////////////////////////////////////////////////////////////
- ControlSaveLoadMenuClass::ControlSaveLoadMenuClass (void) :
- MenuDialogClass (IDD_MENU_CONTROL_SAVELOAD)
- {
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // On_Init_Dialog
- //
- ////////////////////////////////////////////////////////////////
- void
- ControlSaveLoadMenuClass::On_Init_Dialog (void)
- {
- ListCtrlClass *list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_LIST_CTRL);
- if (list_ctrl != NULL) {
- //
- // Configure the column
- //
- list_ctrl->Add_Column (L"", 1.0F, Vector3 (1, 1, 1));
-
- //
- // Loop over all the configurations
- //
- int count = InputConfigMgrClass::Get_Configuration_Count ();
- for (int index = 0; index < count; index ++) {
-
- //
- // Get information about this configuration
- //
- InputConfigClass config;
- InputConfigMgrClass::Get_Configuration (index, config);
- Insert_Configuration (config);
- }
- //
- // Add an entry so the user can add new configurations
- //
- int item_index = list_ctrl->Insert_Entry (index, TRANSLATE (IDS_MENU_EMPTY_SLOT));
- list_ctrl->Set_Curr_Sel (item_index);
- //
- // Sort the entries
- //
- list_ctrl->Sort (ListSortCallback, 0);
- }
- MenuDialogClass::On_Init_Dialog ();
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // On_Command
- //
- ////////////////////////////////////////////////////////////////
- void
- ControlSaveLoadMenuClass::On_Command (int ctrl_id, int message_id, DWORD param)
- {
- switch (ctrl_id)
- {
- case IDC_DELETE_BUTTON:
- Delete_Config ();
- break;
- case IDC_SAVE_BUTTON:
- Save_Config (true);
- break;
- case IDC_LOAD_BUTTON:
- Load_Config ();
- break;
- }
- MenuDialogClass::On_Command (ctrl_id, message_id, param);
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Delete_Config
- //
- ////////////////////////////////////////////////////////////////
- void
- ControlSaveLoadMenuClass::Delete_Config (void)
- {
- ListCtrlClass *list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_LIST_CTRL);
- if (list_ctrl == NULL) {
- return ;
- }
- //
- // Get the current selection
- //
- int curr_sel = list_ctrl->Get_Curr_Sel ();
- if (curr_sel != -1) {
- //
- // Get the configuration object associated with this entry
- //
- InputConfigClass *config = (InputConfigClass *)list_ctrl->Get_Entry_Data (curr_sel, 0);
- if (config != NULL) {
- //
- // Delete the configuration (if possible)
- //
- if (config->Is_Custom ()) {
- //
- // Build a confirmation message to display to the user
- //
- WideStringClass message;
- message.Format (TRANSLATE (IDS_MENU_DELETE_SAVE_MSG),
- list_ctrl->Get_Entry_Text (curr_sel, 0));
- //
- // Display a message to the user asking if they really want to do this...
- //
- DlgMsgBox::DoDialog (TRANSLATE (IDS_MENU_DELETE_SAVE_TITLE), message, DlgMsgBox::YesNo,
- this, MBEVENT_DELETE_PROMPT);
- }
- }
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // HandleNotification
- //
- ////////////////////////////////////////////////////////////////
- void
- ControlSaveLoadMenuClass::HandleNotification (DlgMsgBoxEvent &event)
- {
- if (event.Get_User_Data () == MBEVENT_DELETE_PROMPT) {
-
- //
- // The user has confirmed the delete, so delete the configuration
- //
- if (event.Event () == DlgMsgBoxEvent::Yes) {
- ListCtrlClass *list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_LIST_CTRL);
- if (list_ctrl != NULL) {
- //
- // Get the current selection
- //
- int curr_sel = list_ctrl->Get_Curr_Sel ();
- if (curr_sel != -1) {
- //
- // Get the configuration object associated with this entry
- //
- InputConfigClass *config = (InputConfigClass *)list_ctrl->Get_Entry_Data (curr_sel, 0);
- if (config != NULL) {
- InputConfigMgrClass::Delete_Configuration (config->Get_Filename ());
- list_ctrl->Delete_Entry (curr_sel);
- }
- }
- }
- }
- } else if (event.Get_User_Data () == MBEVENT_SAVE_PROMPT) {
- //
- // The user has confirmed the overwrite, so save the configuration
- //
- if (event.Event () == DlgMsgBoxEvent::Yes) {
- Save_Config (false);
- }
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Load_Config
- //
- ////////////////////////////////////////////////////////////////
- void
- ControlSaveLoadMenuClass::Load_Config (void)
- {
- ListCtrlClass *list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_LIST_CTRL);
- if (list_ctrl == NULL) {
- return ;
- }
- //
- // Get the current selection
- //
- int curr_sel = list_ctrl->Get_Curr_Sel ();
- if (curr_sel != -1) {
-
- //
- // Get the configuration object associated with this entry
- //
- InputConfigClass *config = (InputConfigClass *)list_ctrl->Get_Entry_Data (curr_sel, 0);
- if (config != NULL) {
-
- //
- // Load this configuration
- //
- InputConfigMgrClass::Load_Configuration (*config);
- End_Dialog ();
- }
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Save_Config
- //
- ////////////////////////////////////////////////////////////////
- void
- ControlSaveLoadMenuClass::Save_Config (bool prompt)
- {
- ListCtrlClass *list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_LIST_CTRL);
- if (list_ctrl == NULL) {
- return ;
- }
- //
- // Get the current selection
- //
- int curr_sel = list_ctrl->Get_Curr_Sel ();
- if (curr_sel != -1) {
-
- //
- // Get the configuration object associated with this entry
- //
- InputConfigClass *config = (InputConfigClass *)list_ctrl->Get_Entry_Data (curr_sel, 0);
- if (config != NULL) {
-
- //
- // We can only save custom configurations...
- //
- if (config->Is_Custom ()) {
- //
- // Get the new display name for this configuration
- //
- const WCHAR *display_name = Get_Dlg_Item_Text (IDC_NAME_EDIT);
- if (display_name[0] != 0) {
- //
- // Display a message to the user asking if they really want to do this...
- //
- bool save_file = true;
- if (prompt) {
- DlgMsgBox::DoDialog (IDS_MENU_CONTROLS_OVERWRITE_PROMPT_TITLE, IDS_MENU_CONTROLS_OVERWRITE_PROMPT_MSG,
- DlgMsgBox::YesNo, this, MBEVENT_SAVE_PROMPT);
- save_file = false;
- }
- if (save_file) {
- //
- // Update the name of this configuration
- //
- config->Set_Display_Name (display_name);
- list_ctrl->Set_Entry_Text (curr_sel, 0, display_name);
-
- //
- // Save the configuration
- //
- InputConfigMgrClass::Save_Configuration (*config);
- End_Dialog ();
- }
- } else {
-
- //
- // Let the user know they can't save a configuration without a name
- //
- DlgMsgBox::DoDialog (IDS_MENU_CANT_SAVE_CONFIG, IDS_MENU_CONFIG_NEEDS_NAME, DlgMsgBox::Okay, NULL, 0);
- }
- }
- } else {
- //
- // Get the new display name for this configuration
- //
- const WCHAR *display_name = Get_Dlg_Item_Text (IDC_NAME_EDIT);
- if (display_name[0] != 0) {
- //
- // Add a new configuration
- //
- InputConfigMgrClass::Add_Configuration (display_name);
- End_Dialog ();
- } else {
- //
- // Let the user know they can't save a configuration without a name
- //
- DlgMsgBox::DoDialog (IDS_MENU_CANT_SAVE_CONFIG, IDS_MENU_CONFIG_NEEDS_NAME, DlgMsgBox::Okay, NULL, 0);
- }
- }
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // On_ListCtrl_Delete_Entry
- //
- ////////////////////////////////////////////////////////////////
- void
- ControlSaveLoadMenuClass::On_ListCtrl_Delete_Entry
- (
- ListCtrlClass *list_ctrl,
- int ctrl_id,
- int item_index
- )
- {
- //
- // Remove the data we associated with this entry
- //
- InputConfigClass *config = (InputConfigClass *)list_ctrl->Get_Entry_Data (item_index, 0);
- list_ctrl->Set_Entry_Data (item_index, 0, NULL);
- //
- // Free the config object
- //
- if (config != NULL) {
- delete config;
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Insert_Configuration
- //
- ////////////////////////////////////////////////////////////////
- int
- ControlSaveLoadMenuClass::Insert_Configuration (const InputConfigClass &config)
- {
- ListCtrlClass *list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_LIST_CTRL);
- if (list_ctrl == NULL) {
- return -1;
- }
- //
- // Add an entry for this configuration to the list
- //
- int item_index = list_ctrl->Insert_Entry (0xFFFF, config.Get_Display_Name ());
- if (item_index != -1) {
- //
- // Make a copy of the config object and store it with the entry
- //
- InputConfigClass *local_copy = new InputConfigClass (config);
- list_ctrl->Set_Entry_Data (item_index, 0, (DWORD)local_copy);
- //
- // Change the color of this configuration if the user cannot edit it
- //
- if (config.Is_Custom () == false) {
- list_ctrl->Set_Entry_Color (item_index, 0, Vector3 (1.0F, 1.0F, 1.0F));
- }
- }
- return item_index;
- }
- ////////////////////////////////////////////////////////////////
- //
- // On_ListCtrl_Sel_Change
- //
- ////////////////////////////////////////////////////////////////
- void
- ControlSaveLoadMenuClass::On_ListCtrl_Sel_Change
- (
- ListCtrlClass * list_ctrl,
- int ctrl_id,
- int old_index,
- int new_index
- )
- {
- bool enable_edit = true;
- //
- // Remove the data we associated with this entry
- //
- InputConfigClass *config = (InputConfigClass *)list_ctrl->Get_Entry_Data (new_index, 0);
- if (config != NULL) {
-
- //
- // We want to disable the edit control if the user can't edit this entry
- //
- if (config->Is_Custom () == false) {
- enable_edit = false;
- }
- //
- // Put the name of the currently selected configuration in the control
- //
- Set_Dlg_Item_Text (IDC_NAME_EDIT, config->Get_Display_Name ());
- } else {
- //
- // Clear the name of the current configuration
- //
- Set_Dlg_Item_Text (IDC_NAME_EDIT, L"");
- }
- //
- // Fix the enable state of the edit control
- //
- Enable_Dlg_Item (IDC_NAME_EDIT, enable_edit);
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // ListSortCallback
- //
- ////////////////////////////////////////////////////////////////
- int CALLBACK
- ControlSaveLoadMenuClass::ListSortCallback
- (
- ListCtrlClass * list_ctrl,
- int item_index1,
- int item_index2,
- uint32 user_param
- )
- {
- int retval = 0;
- if (list_ctrl->Get_Entry_Data (item_index1, 0) == NULL) {
- retval = 1;
- } else if (list_ctrl->Get_Entry_Data (item_index2, 0) == NULL) {
- retval = -1;
- } else {
- InputConfigClass *config1 = (InputConfigClass *)list_ctrl->Get_Entry_Data (item_index1, 0);
- InputConfigClass *config2 = (InputConfigClass *)list_ctrl->Get_Entry_Data (item_index2, 0);
- //
- // Sort based on the type of configuration
- //
- if (config1->Is_Default () && config2->Is_Default () == false) {
- retval = -1;
- } else if (config1->Is_Default () == false && config2->Is_Default ()) {
- retval = 1;
- } else if (config1->Is_Custom () && config2->Is_Custom () == false) {
- retval = -1;
- } else if (config1->Is_Custom () == false && config2->Is_Custom ()) {
- retval = 1;
- } else {
-
- //
- // Sort based on the names
- //
- retval = ::wcsicmp (config1->Get_Display_Name (), config2->Get_Display_Name ());
- }
- }
- return retval;
- }
- ////////////////////////////////////////////////////////////////
- //
- // On_EditCtrl_Enter_Pressed
- //
- ////////////////////////////////////////////////////////////////
- void
- ControlSaveLoadMenuClass::On_EditCtrl_Enter_Pressed (EditCtrlClass *edit_ctrl, int ctrl_id)
- {
- if (ctrl_id == IDC_NAME_EDIT) {
- Save_Config (true);
- }
- return ;
- }
|