2020-01-09 13:59:19 +01:00
// wxMASSManager
// Copyright (C) 2020 Guillaume Jacquemin
//
// 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 <https://www.gnu.org/licenses/>.
2020-09-30 16:27:26 +02:00
# include <Corrade/version.h>
# if !(CORRADE_VERSION_YEAR * 100 + CORRADE_VERSION_MONTH >= 202006)
# error This application requires Corrade 2020.06 or later to build.
# endif
# include <wx/busyinfo.h>
2020-01-09 13:59:19 +01:00
# include <wx/filedlg.h>
2021-05-11 14:54:33 +02:00
# include <wx/menu.h>
2020-01-09 13:59:19 +01:00
# include <wx/msgdlg.h>
# include <wx/numdlg.h>
# include <wx/regex.h>
2020-06-20 10:45:49 +02:00
# include <wx/scrolwin.h>
2020-01-09 13:59:19 +01:00
2020-01-12 14:54:23 +01:00
# include <Corrade/Containers/Optional.h>
2020-09-30 16:27:26 +02:00
# include <Corrade/Utility/DebugStl.h>
2020-01-09 13:59:19 +01:00
# include <Corrade/Utility/Directory.h>
2020-09-30 16:27:26 +02:00
# include <Corrade/Utility/FormatStl.h>
2020-01-09 13:59:19 +01:00
2020-06-13 22:29:23 +02:00
# include "EvtNameChangeDialog.h"
2020-01-09 13:59:19 +01:00
# include "EvtMainFrame.h"
2021-04-20 15:54:07 +02:00
# include "../Maps/LastMissionId.h"
2021-04-20 15:55:41 +02:00
# include "../Maps/StoryProgress.h"
2020-10-05 00:55:08 +02:00
2020-09-30 16:27:26 +02:00
EvtMainFrame : : EvtMainFrame ( wxWindow * parent ) :
MainFrame ( parent ) ,
_profileManager { _mbManager . saveDirectory ( ) }
{
2020-01-09 13:59:19 +01:00
SetIcon ( wxIcon ( " MAINICON " ) ) ;
2021-03-05 14:19:14 +01:00
warningMessage ( wxString : : FromUTF8 ( " Before you start using this app, a few things you should know: \n \n "
2021-05-10 18:39:28 +02:00
" For this application to work properly, it is recommended to disable Steam Cloud syncing for the game. \n To disable it, right-click the game in your Steam library, click \" Properties \" , go to the \" General \" tab, and uncheck \" Keep game saves in the Steam Cloud for M.A.S.S. Builder \" . \n \n "
2021-03-05 14:19:14 +01:00
" DISCLAIMER: The developer of this application (Guillaume Jacquemin) isn't associated with Vermillion Digital, and both parties cannot be held responsible for data loss or corruption this app might cause. PLEASE USE AT YOUR OWN RISK! \n \n "
" Last but not least, this application is released under the terms of the GNU General Public Licence version 3. Please see the COPYING file for more details. " ) ) ;
2020-09-30 16:27:26 +02:00
if ( ! _mbManager . ready ( ) ) {
errorMessage ( " There was an error initialising the manager: \n \n " + _mbManager . lastError ( ) ) ;
return ;
}
2020-07-22 16:03:11 +02:00
2020-09-30 16:27:26 +02:00
if ( ! _profileManager . ready ( ) ) {
errorMessage ( " There was an error initialising the manager: \n \n " + _profileManager . lastError ( ) ) ;
2020-01-12 14:54:23 +01:00
return ;
}
2021-03-05 14:20:02 +01:00
std : : size_t default_profile = 0 ;
int counter = 0 ;
2020-09-30 16:27:26 +02:00
for ( const Profile & p : _profileManager . profiles ( ) ) {
if ( p . valid ( ) ) {
_profileChoice - > Append ( wxString : : Format ( " %s%s " , p . companyName ( ) , p . type ( ) = = ProfileType : : Demo ? " (Demo) " : " " ) ) ;
2021-03-05 14:20:02 +01:00
if ( p . type ( ) = = ProfileType : : FullGame & & default_profile = = 0 ) {
default_profile = counter ;
}
counter + + ;
2020-09-30 16:27:26 +02:00
}
}
2021-03-05 14:20:02 +01:00
_profileManager . setProfile ( default_profile ) ;
_profileChoice - > SetSelection ( default_profile ) ;
2020-09-30 16:27:26 +02:00
_massManager . emplace ( _profileManager . profileDirectory ( ) ,
_profileManager . currentProfile ( ) - > steamId ( ) ,
_profileManager . currentProfile ( ) - > type ( ) = = ProfileType : : Demo ) ;
updateProfileStats ( ) ;
2020-01-09 13:59:19 +01:00
initialiseListView ( ) ;
2020-01-10 12:23:25 +01:00
isGameRunning ( ) ;
2020-01-09 13:59:19 +01:00
_installedListView - > Connect ( wxEVT_LIST_ITEM_SELECTED , wxListEventHandler ( EvtMainFrame : : installedSelectionEvent ) , nullptr , this ) ;
_installedListView - > Connect ( wxEVT_LIST_ITEM_DESELECTED , wxListEventHandler ( EvtMainFrame : : installedSelectionEvent ) , nullptr , this ) ;
_installedListView - > Connect ( wxEVT_LIST_BEGIN_DRAG , wxListEventHandler ( EvtMainFrame : : listColumnDragEvent ) , nullptr , this ) ;
_installedListView - > Connect ( wxEVT_LIST_COL_BEGIN_DRAG , wxListEventHandler ( EvtMainFrame : : listColumnDragEvent ) , nullptr , this ) ;
2020-01-10 00:01:24 +01:00
_watcher . Connect ( wxEVT_FSWATCHER , wxFileSystemWatcherEventHandler ( EvtMainFrame : : fileUpdateEvent ) , nullptr , this ) ;
2020-09-30 16:27:26 +02:00
_watcher . AddTree ( wxFileName { Utility : : Directory : : toNativeSeparators ( _massManager - > saveDirectory ( ) ) , wxPATH_WIN } ,
wxFSW_EVENT_CREATE | wxFSW_EVENT_DELETE | wxFSW_EVENT_MODIFY | wxFSW_EVENT_RENAME ,
wxString : : Format ( " %s*%s.sav " , _profileManager . currentProfile ( ) - > type ( ) = = ProfileType : : Demo ? " Demo " : " " , _profileManager . currentProfile ( ) - > steamId ( ) ) ) ;
2020-01-16 00:35:43 +01:00
2020-09-30 16:27:26 +02:00
auto staged_masses = _massManager - > stagedMasses ( ) ;
for ( const auto & s : staged_masses ) {
_stagingList - > Append ( wxString : : Format ( " %s (%s) " , s . second , s . first ) ) ;
2020-01-16 00:35:43 +01:00
}
2020-01-10 12:23:25 +01:00
2020-09-30 16:27:26 +02:00
_watcher . AddTree ( wxFileName ( Utility : : Directory : : toNativeSeparators ( _massManager - > stagingAreaDirectory ( ) ) , wxPATH_WIN ) ,
2020-07-22 08:55:12 +02:00
wxFSW_EVENT_CREATE | wxFSW_EVENT_DELETE | wxFSW_EVENT_MODIFY | wxFSW_EVENT_RENAME , " *.sav " ) ;
2020-09-30 16:27:26 +02:00
_gameCheckTimer . Start ( 2000 ) ;
2021-05-11 14:54:33 +02:00
initStoryProgressMenu ( ) ;
2020-01-09 13:59:19 +01:00
}
EvtMainFrame : : ~ EvtMainFrame ( ) {
2020-09-30 16:27:26 +02:00
_watcher . RemoveAll ( ) ;
_watcher . Disconnect ( wxEVT_FSWATCHER , wxFileSystemWatcherEventHandler ( EvtMainFrame : : fileUpdateEvent ) , nullptr , this ) ;
2020-01-09 13:59:19 +01:00
_installedListView - > Disconnect ( wxEVT_LIST_ITEM_SELECTED , wxListEventHandler ( EvtMainFrame : : installedSelectionEvent ) , nullptr , this ) ;
_installedListView - > Disconnect ( wxEVT_LIST_ITEM_DESELECTED , wxListEventHandler ( EvtMainFrame : : installedSelectionEvent ) , nullptr , this ) ;
_installedListView - > Disconnect ( wxEVT_LIST_BEGIN_DRAG , wxListEventHandler ( EvtMainFrame : : listColumnDragEvent ) , nullptr , this ) ;
_installedListView - > Disconnect ( wxEVT_LIST_COL_BEGIN_DRAG , wxListEventHandler ( EvtMainFrame : : listColumnDragEvent ) , nullptr , this ) ;
}
2020-01-12 14:54:23 +01:00
bool EvtMainFrame : : ready ( ) {
2020-09-30 16:27:26 +02:00
return _mbManager . ready ( ) & & _profileManager . ready ( ) ;
}
void EvtMainFrame : : profileSelectionEvent ( wxCommandEvent & ) {
_watcher . Remove ( wxFileName { Utility : : Directory : : toNativeSeparators ( Utility : : Directory : : path ( _massManager - > saveDirectory ( ) ) ) + " \\ " , wxPATH_WIN } ) ;
// Yeah, I really need that `+ "\\"`, because wxWidgets is *that* stupid.
int selection = _profileChoice - > GetSelection ( ) ;
if ( _profileManager . setProfile ( selection ) ) {
_massManager . emplace ( _profileManager . profileDirectory ( ) ,
_profileManager . currentProfile ( ) - > steamId ( ) ,
_profileManager . currentProfile ( ) - > type ( ) = = ProfileType : : Demo ) ;
_watcher . AddTree ( wxFileName { Utility : : Directory : : toNativeSeparators ( _massManager - > saveDirectory ( ) ) , wxPATH_WIN } ,
wxFSW_EVENT_CREATE | wxFSW_EVENT_DELETE | wxFSW_EVENT_MODIFY | wxFSW_EVENT_RENAME ,
wxString : : Format ( " %s*%s.sav " , _profileManager . currentProfile ( ) - > type ( ) = = ProfileType : : Demo ? " Demo " : " " , _profileManager . currentProfile ( ) - > steamId ( ) ) ) ;
updateProfileStats ( ) ;
refreshListView ( ) ;
}
}
void EvtMainFrame : : backupSelectedProfileEvent ( wxCommandEvent & ) {
const static std : : string error_prefix = " Backup failed: \n \n " ;
wxString current_timestamp = wxDateTime : : Now ( ) . Format ( " %Y-%m-%d_%H-%M-%S " ) ;
wxFileDialog save_dialog { this , " Choose output location " , _massManager - > saveDirectory ( ) ,
wxString : : Format ( " backup_%s%s_%s_%s.zip " ,
_profileManager . currentProfile ( ) - > type ( ) = = ProfileType : : Demo ? " demo_ " : " " ,
_profileManager . currentProfile ( ) - > companyName ( ) ,
_profileManager . currentProfile ( ) - > steamId ( ) ,
current_timestamp ) ,
" Zip archive (*.zip)|*.zip " ,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT } ;
if ( save_dialog . ShowModal ( ) = = wxID_CANCEL ) {
return ;
}
if ( ! _profileManager . currentProfile ( ) - > backup ( save_dialog . GetPath ( ) . ToStdString ( ) ) ) {
errorMessage ( error_prefix + _massManager - > lastError ( ) ) ;
}
2020-01-12 14:54:23 +01:00
}
2021-05-12 15:11:05 +02:00
void EvtMainFrame : : companyRenameEvent ( wxCommandEvent & ) {
2020-10-05 10:36:08 +02:00
const static std : : string error_prefix = " Rename failed: \n \n " ;
EvtNameChangeDialog dialog { this } ;
dialog . setName ( _profileManager . currentProfile ( ) - > companyName ( ) ) ;
int result = dialog . ShowModal ( ) ;
if ( result = = wxID_OK ) {
2021-03-05 14:56:28 +01:00
if ( _unsafeMode = = false ) {
switch ( _mbManager . gameState ( ) ) {
case GameState : : Unknown :
errorMessage ( error_prefix + " For security reasons, renaming the company is disabled if the game's status is unknown. " ) ;
break ;
case GameState : : NotRunning :
if ( ! _profileManager . currentProfile ( ) - > renameCompany ( dialog . getName ( ) ) ) {
errorMessage ( error_prefix + _profileManager . currentProfile ( ) - > lastError ( ) ) ;
}
else {
_profileChoice - > SetString ( _profileChoice - > GetCurrentSelection ( ) ,
wxString : : Format ( " %s%s " ,
_profileManager . currentProfile ( ) - > companyName ( ) ,
_profileManager . currentProfile ( ) - > type ( ) = = ProfileType : : Demo ? " (Demo) " : " " ) ) ;
}
break ;
case GameState : : Running :
errorMessage ( error_prefix + " Renaming the company is disabled while the game is running. " ) ;
break ;
}
}
else {
if ( ! _profileManager . currentProfile ( ) - > renameCompany ( dialog . getName ( ) ) ) {
errorMessage ( error_prefix + _profileManager . currentProfile ( ) - > lastError ( ) ) ;
}
else {
_profileChoice - > SetString ( _profileChoice - > GetCurrentSelection ( ) ,
wxString : : Format ( " %s%s " ,
_profileManager . currentProfile ( ) - > companyName ( ) ,
_profileManager . currentProfile ( ) - > type ( ) = = ProfileType : : Demo ? " (Demo) " : " " ) ) ;
}
2020-10-05 10:36:08 +02:00
}
}
}
2021-05-12 20:21:35 +02:00
void EvtMainFrame : : creditsEditEvent ( wxCommandEvent & ) {
const static std : : string error_prefix = " Credits change failed: \n \n " ;
if ( _unsafeMode = = true | | _mbManager . gameState ( ) = = GameState : : NotRunning ) {
long number = wxGetNumberFromUser ( " Please enter a number of credits between 0 and 2 000 000 000 included: " , " Credits: " , " Input credits " ,
_profileManager . currentProfile ( ) - > credits ( ) , 0 , 2000000000 , this ) ;
if ( number = = - 1 | | number = = _profileManager . currentProfile ( ) - > credits ( ) ) {
return ;
}
if ( ! _profileManager . currentProfile ( ) - > setCredits ( number ) ) {
errorMessage ( error_prefix + _profileManager . currentProfile ( ) - > lastError ( ) ) ;
}
updateProfileStats ( ) ;
}
else if ( _mbManager . gameState ( ) = = GameState : : Unknown ) {
errorMessage ( error_prefix + " For security reasons, changing credits is disabled if the game's status is unknown. " ) ;
}
else if ( _mbManager . gameState ( ) = = GameState : : Running ) {
errorMessage ( error_prefix + " For security reasons, changing credits is disabled if the game is running. " ) ;
}
}
2021-05-11 14:54:33 +02:00
void EvtMainFrame : : storyProgressSelectionEvent ( wxCommandEvent & event ) {
const static std : : string error_prefix = " StoryProgress change failed: \n \n " ;
std : : int32_t story_progress = event . GetId ( ) ^ ( - 10000 ) ;
if ( _unsafeMode = = false ) {
switch ( _mbManager . gameState ( ) ) {
case GameState : : Unknown :
errorMessage ( error_prefix + " For security reasons, changing the story progression is disabled if the game's status is unknown. " ) ;
break ;
case GameState : : NotRunning :
if ( ! _profileManager . currentProfile ( ) - > setStoryProgress ( story_progress ) ) {
errorMessage ( error_prefix + _profileManager . currentProfile ( ) - > lastError ( ) ) ;
}
break ;
case GameState : : Running :
errorMessage ( error_prefix + " Changing the story progression is disabled while the game is running. " ) ;
break ;
}
}
else if ( ! _profileManager . currentProfile ( ) - > setStoryProgress ( story_progress ) ) {
errorMessage ( error_prefix + _profileManager . currentProfile ( ) - > lastError ( ) ) ;
}
updateProfileStats ( ) ;
}
void EvtMainFrame : : openStoryProgressMenuEvent ( wxCommandEvent & ) {
PopupMenu ( _storyProgressSelectionMenu . get ( ) ) ;
}
2021-05-12 13:53:51 +02:00
void EvtMainFrame : : inventoryChangeEvent ( wxPropertyGridEvent & event ) {
const static std : : string error_prefix = " Inventory change failed: \n \n " ;
std : : int32_t value = event . GetPropertyValue ( ) . GetInteger ( ) ;
Profile * profile = _profileManager . currentProfile ( ) ;
if ( value > 1000000 | | value < 0 ) {
event . SetValidationFailureMessage ( error_prefix + " The value must not be higher than 1 million or lower than 0 " ) ;
event . Veto ( ) ;
return ;
}
if ( _unsafeMode = = true | | _mbManager . gameState ( ) = = GameState : : NotRunning ) {
wxPGProperty * prop = event . GetProperty ( ) ;
bool success = false ;
if ( prop = = _verseSteel ) { success = profile - > setVerseSteel ( value ) ; }
else if ( prop = = _undinium ) { success = profile - > setUndinium ( value ) ; }
else if ( prop = = _necriumAlloy ) { success = profile - > setNecriumAlloy ( value ) ; }
else if ( prop = = _lunarite ) { success = profile - > setLunarite ( value ) ; }
else if ( prop = = _asterite ) { success = profile - > setAsterite ( value ) ; }
else if ( prop = = _ednil ) { success = profile - > setEdnil ( value ) ; }
else if ( prop = = _nuflalt ) { success = profile - > setNuflalt ( value ) ; }
else if ( prop = = _aurelene ) { success = profile - > setAurelene ( value ) ; }
else if ( prop = = _soldus ) { success = profile - > setSoldus ( value ) ; }
else if ( prop = = _synthesizedN ) { success = profile - > setSynthesizedN ( value ) ; }
else if ( prop = = _alcarbonite ) { success = profile - > setAlcarbonite ( value ) ; }
else if ( prop = = _keriphene ) { success = profile - > setKeriphene ( value ) ; }
else if ( prop = = _nitinolCM ) { success = profile - > setNitinolCM ( value ) ; }
else if ( prop = = _quarkium ) { success = profile - > setQuarkium ( value ) ; }
else if ( prop = = _alterene ) { success = profile - > setAlterene ( value ) ; }
else if ( prop = = _mixedComposition ) { success = profile - > setMixedComposition ( value ) ; }
else if ( prop = = _voidResidue ) { success = profile - > setVoidResidue ( value ) ; }
else if ( prop = = _muscularConstruction ) { success = profile - > setMuscularConstruction ( value ) ; }
else if ( prop = = _mineralExoskeletology ) { success = profile - > setMineralExoskeletology ( value ) ; }
else if ( prop = = _carbonizedSkin ) { success = profile - > setCarbonizedSkin ( value ) ; }
if ( ! success ) {
event . SetValidationFailureMessage ( error_prefix + profile - > lastError ( ) ) ;
event . Veto ( ) ;
}
}
else if ( _mbManager . gameState ( ) = = GameState : : Unknown ) {
event . SetValidationFailureMessage ( error_prefix + " For security reasons, changing the inventory is disabled if the game's status is unknown. " ) ;
event . Veto ( ) ;
}
else if ( _mbManager . gameState ( ) = = GameState : : Running ) {
event . SetValidationFailureMessage ( error_prefix + " For security reasons, changing the inventory is disabled if the game is running. " ) ;
event . Veto ( ) ;
}
}
2020-06-21 21:39:39 +02:00
void EvtMainFrame : : importMassEvent ( wxCommandEvent & ) {
2020-01-12 14:54:23 +01:00
const static std : : string error_prefix = " Importing failed: \n \n " ;
long selected_hangar = _installedListView - > GetFirstSelected ( ) ;
2020-09-30 16:27:26 +02:00
MassState mass_state = _massManager - > massState ( selected_hangar ) ;
2020-01-09 13:59:19 +01:00
2020-01-16 00:35:43 +01:00
int staged_selection = _stagingList - > GetSelection ( ) ;
2020-01-09 13:59:19 +01:00
2020-01-16 00:35:43 +01:00
int confirmation ;
2020-01-09 13:59:19 +01:00
2020-09-30 16:27:26 +02:00
if ( mass_state = = MassState : : Valid ) {
2020-01-16 00:35:43 +01:00
confirmation = wxMessageBox ( wxString : : Format ( " Hangar %.2d is already occupied by the M.A.S.S. named \" %s \" . Are you sure you want to import the M.A.S.S. named \" %s \" to this hangar ? " ,
2020-09-30 16:27:26 +02:00
selected_hangar + 1 , _massManager - > massName ( selected_hangar ) , _massManager - > stagedMassName ( staged_selection ) ) ,
2020-01-16 00:35:43 +01:00
" Question " , wxYES_NO | wxCENTRE | wxICON_QUESTION , this ) ;
2020-01-09 13:59:19 +01:00
}
2020-01-16 00:35:43 +01:00
else {
2020-09-30 16:27:26 +02:00
confirmation = wxMessageBox ( wxString : : Format ( " Are you sure you want to import the M.A.S.S. named \" %s \" to hangar %.2d ? " , _massManager - > stagedMassName ( staged_selection ) , selected_hangar + 1 ) ,
2020-01-16 00:35:43 +01:00
" Question " , wxYES_NO | wxCENTRE | wxICON_QUESTION , this ) ;
2020-01-09 13:59:19 +01:00
}
2020-01-16 00:35:43 +01:00
if ( confirmation = = wxNO ) {
2020-01-09 13:59:19 +01:00
return ;
}
2021-03-05 14:56:28 +01:00
if ( _unsafeMode = = false ) {
switch ( _mbManager . gameState ( ) ) {
case GameState : : Unknown :
errorMessage ( error_prefix + " For security reasons, importing is disabled if the game's status is unknown. " ) ;
break ;
case GameState : : NotRunning :
if ( ! _massManager - > importMass ( staged_selection , selected_hangar ) ) {
errorMessage ( error_prefix + _massManager - > lastError ( ) ) ;
}
break ;
case GameState : : Running :
errorMessage ( error_prefix + " Importing a M.A.S.S. is disabled while the game is running. " ) ;
break ;
}
}
else {
if ( ! _massManager - > importMass ( staged_selection , selected_hangar ) ) {
errorMessage ( error_prefix + _massManager - > lastError ( ) ) ;
}
2020-01-09 13:59:19 +01:00
}
}
2020-06-21 21:39:39 +02:00
void EvtMainFrame : : exportMassEvent ( wxCommandEvent & ) {
2020-01-16 00:35:43 +01:00
const static std : : string error_prefix = " Export failed: \n \n " ;
long slot = _installedListView - > GetFirstSelected ( ) ;
2020-09-30 16:27:26 +02:00
if ( ! _massManager - > exportMass ( slot ) ) {
errorMessage ( error_prefix + _massManager - > lastError ( ) ) ;
2020-01-16 00:35:43 +01:00
}
}
2020-06-21 21:39:39 +02:00
void EvtMainFrame : : moveMassEvent ( wxCommandEvent & ) {
2020-01-12 14:54:23 +01:00
const static std : : string error_prefix = " Move failed: \n \n " ;
2020-01-09 13:59:19 +01:00
long source_slot = _installedListView - > GetFirstSelected ( ) ;
2020-01-12 14:54:23 +01:00
long choice = wxGetNumberFromUser ( wxString : : Format ( " Which hangar do you want to move the M.A.S.S. named \" %s \" to ? \n Notes: \n "
" - If the destination hangar is the same as the source, nothing will happen. \n "
" - If the destination already contains a M.A.S.S., the two will be swapped. \n "
" - If the destination contains invalid data, it will be cleared first. " ,
2020-09-30 16:27:26 +02:00
_massManager - > massName ( source_slot ) ) ,
2020-06-24 10:02:30 +02:00
" Slot " , " Choose a slot " , source_slot + 1 , 1 , 32 , this ) ;
2020-01-09 13:59:19 +01:00
if ( choice = = - 1 | | choice = = source_slot ) {
return ;
}
2021-03-05 14:56:28 +01:00
if ( _unsafeMode = = false ) {
switch ( _mbManager . gameState ( ) ) {
case GameState : : Unknown :
errorMessage ( error_prefix + " For security reasons, moving a M.A.S.S. is disabled if the game's status is unknown. " ) ;
break ;
case GameState : : NotRunning :
if ( ! _massManager - > moveMass ( source_slot , choice - 1 ) ) {
errorMessage ( error_prefix + _massManager - > lastError ( ) ) ;
}
break ;
case GameState : : Running :
errorMessage ( error_prefix + " Moving a M.A.S.S. is disabled while the game is running. " ) ;
break ;
}
}
else {
if ( ! _massManager - > moveMass ( source_slot , choice - 1 ) ) {
errorMessage ( error_prefix + _massManager - > lastError ( ) ) ;
}
2020-01-09 13:59:19 +01:00
}
}
2020-06-21 21:39:39 +02:00
void EvtMainFrame : : deleteMassEvent ( wxCommandEvent & ) {
2020-01-12 14:54:23 +01:00
const static std : : string error_prefix = " Deletion failed: \n \n " ;
2020-01-09 13:59:19 +01:00
if ( wxMessageBox ( wxString : : Format ( " Are you sure you want to delete the data in hangar %.2d ? This operation cannot be undone. " , _installedListView - > GetFirstSelected ( ) + 1 ) ,
" Are you sure ? " , wxYES_NO | wxCENTRE | wxICON_QUESTION , this ) = = wxNO ) {
return ;
}
2021-03-05 14:56:28 +01:00
if ( _unsafeMode = = false ) {
switch ( _mbManager . gameState ( ) ) {
case GameState : : Unknown :
errorMessage ( error_prefix + " For security reasons, deleting a M.A.S.S. is disabled if the game's status is unknown. " ) ;
break ;
case GameState : : NotRunning :
if ( ! _massManager - > deleteMass ( _installedListView - > GetFirstSelected ( ) ) ) {
errorMessage ( error_prefix + _massManager - > lastError ( ) ) ;
}
break ;
case GameState : : Running :
errorMessage ( error_prefix + " Deleting a M.A.S.S. is disabled while the game is running. " ) ;
break ;
}
}
else {
if ( ! _massManager - > deleteMass ( _installedListView - > GetFirstSelected ( ) ) ) {
errorMessage ( error_prefix + _massManager - > lastError ( ) ) ;
}
2020-01-09 13:59:19 +01:00
}
}
2020-06-13 22:29:23 +02:00
void EvtMainFrame : : renameMassEvent ( wxCommandEvent & ) {
const static std : : string error_prefix = " Rename failed: \n \n " ;
EvtNameChangeDialog dialog { this } ;
2020-09-30 16:27:26 +02:00
dialog . setName ( _massManager - > massName ( _installedListView - > GetFirstSelected ( ) ) ) ;
2020-06-13 22:29:23 +02:00
int result = dialog . ShowModal ( ) ;
if ( result = = wxID_OK ) {
2021-03-05 14:56:28 +01:00
if ( _unsafeMode = = false ) {
switch ( _mbManager . gameState ( ) ) {
case GameState : : Unknown :
errorMessage ( error_prefix + " For security reasons, renaming a M.A.S.S. is disabled if the game's status is unknown. " ) ;
break ;
case GameState : : NotRunning :
if ( ! _massManager - > renameMass ( _installedListView - > GetFirstSelected ( ) , dialog . getName ( ) ) ) {
errorMessage ( error_prefix + _massManager - > lastError ( ) ) ;
}
break ;
case GameState : : Running :
errorMessage ( error_prefix + " Renaming a M.A.S.S. is disabled while the game is running. " ) ;
break ;
}
}
else {
if ( ! _massManager - > renameMass ( _installedListView - > GetFirstSelected ( ) , dialog . getName ( ) ) ) {
errorMessage ( error_prefix + _massManager - > lastError ( ) ) ;
}
2020-06-13 22:29:23 +02:00
}
}
}
2020-01-09 13:59:19 +01:00
void EvtMainFrame : : openSaveDirEvent ( wxCommandEvent & ) {
2020-09-30 16:27:26 +02:00
wxExecute ( " explorer.exe " + Utility : : Directory : : toNativeSeparators ( _massManager - > saveDirectory ( ) ) ) ;
2020-01-09 13:59:19 +01:00
}
2020-01-16 01:21:25 +01:00
void EvtMainFrame : : stagingSelectionEvent ( wxCommandEvent & ) {
updateCommandsState ( ) ;
}
2020-01-16 01:21:47 +01:00
void EvtMainFrame : : deleteStagedEvent ( wxCommandEvent & ) {
2020-06-20 10:45:49 +02:00
if ( wxMessageBox ( " Are you sure you want to delete the selected M.A.S.S. ? This operation cannot be undone. " ,
" Are you sure ? " , wxYES_NO | wxCENTRE | wxICON_QUESTION , this ) = = wxNO ) {
return ;
}
2020-01-16 01:21:47 +01:00
int selection = _stagingList - > GetSelection ( ) ;
if ( selection ! = wxNOT_FOUND ) {
2020-09-30 16:27:26 +02:00
_massManager - > deleteStagedMass ( selection ) ;
2020-01-16 01:21:47 +01:00
}
}
2020-06-21 21:39:39 +02:00
void EvtMainFrame : : openStagingDirEvent ( wxCommandEvent & ) {
2020-09-30 16:27:26 +02:00
wxExecute ( " explorer.exe " + Utility : : Directory : : toNativeSeparators ( _massManager - > stagingAreaDirectory ( ) ) ) ;
2020-01-16 00:04:51 +01:00
}
2020-01-09 13:59:19 +01:00
void EvtMainFrame : : installedSelectionEvent ( wxListEvent & ) {
updateCommandsState ( ) ;
}
void EvtMainFrame : : listColumnDragEvent ( wxListEvent & event ) {
event . Veto ( ) ;
}
2020-06-20 10:45:49 +02:00
void EvtMainFrame : : openScreenshotDirEvent ( wxCommandEvent & ) {
2021-05-10 21:20:13 +02:00
wxExecute ( " explorer.exe " + Utility : : Directory : : toNativeSeparators ( Utility : : Directory : : join ( _profileManager . profileDirectory ( ) , " ../Screenshots/WindowsNoEditor " ) ) ) ;
2020-06-20 10:45:49 +02:00
}
2020-01-10 00:01:24 +01:00
void EvtMainFrame : : fileUpdateEvent ( wxFileSystemWatcherEvent & event ) {
int event_type = event . GetChangeType ( ) ;
2020-01-12 14:54:23 +01:00
wxString event_file = event . GetPath ( ) . GetFullName ( ) ;
2020-01-10 00:01:24 +01:00
if ( event_type = = wxFSW_EVENT_MODIFY & & _lastWatcherEventType = = wxFSW_EVENT_RENAME ) {
_lastWatcherEventType = event_type ;
return ;
}
2020-10-02 12:53:55 +02:00
wxMilliSleep ( 100 ) ;
2020-01-10 00:01:24 +01:00
2020-09-30 16:27:26 +02:00
wxString event_path = event . GetPath ( ) . GetPath ( wxPATH_GET_VOLUME , wxPATH_WIN ) ;
if ( event_path = = Utility : : Directory : : toNativeSeparators ( _massManager - > saveDirectory ( ) ) ) {
2020-10-02 12:55:52 +02:00
saveFileEventHandler ( event_type , event_file , event ) ;
2020-06-20 10:45:49 +02:00
}
2020-10-05 10:36:23 +02:00
else if ( _massManager & & event_path = = Utility : : Directory : : toNativeSeparators ( _massManager - > stagingAreaDirectory ( ) ) ) {
2020-06-20 10:45:49 +02:00
stagingFileEventHandler ( event_type , event_file , event ) ;
}
_lastWatcherEventType = event_type ;
updateCommandsState ( ) ;
}
void EvtMainFrame : : gameCheckTimerEvent ( wxTimerEvent & ) {
isGameRunning ( ) ;
}
2021-03-05 14:56:28 +01:00
void EvtMainFrame : : unsafeCheckboxEvent ( wxCommandEvent & event ) {
if ( event . IsChecked ( ) = = true ) {
int confirmation = wxMessageBox ( " Are you sure you want to enable unsafe mode ? \n \n "
" Unsafe mode will allow you to perform changes even while the game is running, which can result in weird behaviour or even data corruption. " ,
" Question " , wxYES_NO | wxCENTRE | wxICON_WARNING , this ) ;
if ( confirmation = = wxYES ) {
_unsafeMode = true ;
}
else {
_unsafeCheckbox - > SetValue ( false ) ;
}
}
else {
_unsafeMode = false ;
}
updateCommandsState ( ) ;
}
2020-10-02 12:55:52 +02:00
void EvtMainFrame : : saveFileEventHandler ( int event_type , const wxString & event_file , const wxFileSystemWatcherEvent & event ) {
2020-06-20 10:45:49 +02:00
wxRegEx regex ;
2020-01-10 00:01:24 +01:00
2020-06-20 10:45:49 +02:00
switch ( event_type ) {
case wxFSW_EVENT_CREATE :
case wxFSW_EVENT_DELETE :
2020-09-30 16:27:26 +02:00
regex . Compile ( wxString : : Format ( " %sUnit([0-3][0-9])%s \\ .sav " , _profileManager . currentProfile ( ) - > type ( ) = = ProfileType : : Demo ? " Demo " : " " , _profileManager . currentProfile ( ) - > steamId ( ) ) , wxRE_ADVANCED ) ;
2020-06-20 10:45:49 +02:00
if ( regex . Matches ( event_file ) ) {
long slot ;
if ( regex . GetMatch ( event_file , 1 ) . ToLong ( & slot ) & & slot > = 0 & & slot < 32 ) {
refreshHangar ( slot ) ;
}
}
break ;
case wxFSW_EVENT_MODIFY :
if ( _lastWatcherEventType = = wxFSW_EVENT_RENAME ) {
break ;
}
2020-09-30 16:27:26 +02:00
if ( event_file = = _profileManager . currentProfile ( ) - > filename ( ) ) {
2020-10-02 12:56:22 +02:00
updateProfileStats ( ) ;
2020-06-20 10:45:49 +02:00
getActiveSlot ( ) ;
}
else {
2020-09-30 16:27:26 +02:00
regex . Compile ( wxString : : Format ( " %sUnit([0-3][0-9])%s \\ .sav " , _profileManager . currentProfile ( ) - > type ( ) = = ProfileType : : Demo ? " Demo " : " " , _profileManager . currentProfile ( ) - > steamId ( ) ) , wxRE_ADVANCED ) ;
2020-01-12 14:54:23 +01:00
if ( regex . Matches ( event_file ) ) {
long slot ;
if ( regex . GetMatch ( event_file , 1 ) . ToLong ( & slot ) & & slot > = 0 & & slot < 32 ) {
refreshHangar ( slot ) ;
}
}
2020-06-20 10:45:49 +02:00
}
break ;
case wxFSW_EVENT_RENAME :
wxString new_name = event . GetNewPath ( ) . GetFullName ( ) ;
long slot ;
2020-09-30 16:27:26 +02:00
if ( regex . Compile ( wxString : : Format ( " %sUnit([0-3][0-9])%s \\ .sav \\ .tmp " , _profileManager . currentProfile ( ) - > type ( ) = = ProfileType : : Demo ? " Demo " : " " , _profileManager . currentProfile ( ) - > steamId ( ) ) , wxRE_ADVANCED ) , regex . Matches ( new_name ) ) {
2020-06-20 10:45:49 +02:00
if ( regex . GetMatch ( new_name , 1 ) . ToLong ( & slot ) & & slot > = 0 & & slot < 32 ) {
refreshHangar ( slot ) ;
2020-01-16 00:35:43 +01:00
}
2020-06-20 10:45:49 +02:00
}
2020-09-30 16:27:26 +02:00
else if ( regex . Compile ( wxString : : Format ( " %sUnit([0-3][0-9]) % s \ \ . sav " , _profileManager.currentProfile()->type() == ProfileType::Demo ? " Demo " : " " , _profileManager.currentProfile()->steamId()), wxRE_ADVANCED), regex.Matches(new_name)) {
2020-06-20 10:45:49 +02:00
if ( regex . GetMatch ( new_name , 1 ) . ToLong ( & slot ) & & slot > = 0 & & slot < 32 ) {
refreshHangar ( slot ) ;
2020-01-12 14:54:23 +01:00
if ( regex . Matches ( event_file ) ) {
if ( regex . GetMatch ( event_file , 1 ) . ToLong ( & slot ) & & slot > = 0 & & slot < 32 ) {
refreshHangar ( slot ) ;
}
}
}
2020-06-20 10:45:49 +02:00
}
break ;
2020-01-10 22:50:41 +01:00
}
2020-06-20 10:45:49 +02:00
}
2020-01-10 00:01:24 +01:00
2020-06-20 10:45:49 +02:00
void EvtMainFrame : : stagingFileEventHandler ( int event_type , const wxString & event_file , const wxFileSystemWatcherEvent & event ) {
int index ;
2020-01-12 14:54:23 +01:00
2020-06-20 10:45:49 +02:00
switch ( event_type ) {
case wxFSW_EVENT_CREATE :
2020-09-30 16:27:26 +02:00
index = _massManager - > updateStagedMass ( event_file . ToUTF8 ( ) . data ( ) ) ;
2020-06-20 10:45:49 +02:00
if ( index ! = - 1 ) {
2020-09-30 16:27:26 +02:00
_stagingList - > Insert ( wxString : : Format ( " %s (%s) " , _massManager - > stagedMassName ( index ) , event_file ) , index ) ;
2020-06-20 10:45:49 +02:00
}
break ;
case wxFSW_EVENT_DELETE :
2020-09-30 16:27:26 +02:00
index = _massManager - > removeStagedMass ( event_file . ToUTF8 ( ) . data ( ) ) ;
2020-06-20 10:45:49 +02:00
if ( index ! = - 1 ) {
_stagingList - > Delete ( index ) ;
}
break ;
case wxFSW_EVENT_MODIFY :
2020-09-30 16:27:26 +02:00
index = _massManager - > updateStagedMass ( event_file . ToUTF8 ( ) . data ( ) ) ;
2020-06-20 10:45:49 +02:00
if ( index ! = - 1 ) {
2020-09-30 16:27:26 +02:00
_stagingList - > SetString ( index , wxString : : Format ( " %s (%s) " , _massManager - > stagedMassName ( index ) , event_file ) ) ;
2020-06-20 10:45:49 +02:00
}
break ;
case wxFSW_EVENT_RENAME :
2020-09-30 16:27:26 +02:00
index = _massManager - > removeStagedMass ( event_file . ToUTF8 ( ) . data ( ) ) ;
2020-06-20 10:45:49 +02:00
if ( index ! = - 1 ) {
_stagingList - > Delete ( index ) ;
}
2020-09-30 16:27:26 +02:00
index = _massManager - > updateStagedMass ( event . GetNewPath ( ) . GetFullName ( ) . ToUTF8 ( ) . data ( ) ) ;
2020-06-20 10:45:49 +02:00
if ( index ! = - 1 ) {
2020-09-30 16:27:26 +02:00
_stagingList - > Insert ( wxString : : Format ( " %s (%s) " , _massManager - > stagedMassName ( index ) , event . GetNewPath ( ) . GetFullName ( ) ) , index ) ;
2020-06-20 10:45:49 +02:00
}
break ;
}
2020-01-09 13:59:19 +01:00
}
2020-09-30 16:27:26 +02:00
void EvtMainFrame : : updateProfileStats ( ) {
2020-10-02 12:54:38 +02:00
Profile * current_profile = _profileManager . currentProfile ( ) ;
2020-10-05 10:36:08 +02:00
_companyName - > SetLabel ( current_profile - > getCompanyName ( ) ) ;
2021-05-10 19:54:46 +02:00
2020-10-02 12:54:38 +02:00
_credits - > SetLabel ( wxString : : Format ( " %i " , current_profile - > getCredits ( ) ) ) ;
2021-05-10 19:54:46 +02:00
if ( story_progress_map . find ( current_profile - > getStoryProgress ( ) ) ! = story_progress_map . end ( ) ) {
_storyProgress - > SetLabel ( story_progress_map . at ( current_profile - > storyProgress ( ) ) ) ;
}
else {
_storyProgress - > SetLabel ( wxString : : Format ( " 0x%X " , current_profile - > storyProgress ( ) ) ) ;
}
if ( mission_id_map . find ( current_profile - > getLastMissionId ( ) ) ! = mission_id_map . end ( ) ) {
_lastMissionId - > SetLabel ( mission_id_map . at ( current_profile - > lastMissionId ( ) ) ) ;
}
else {
_lastMissionId - > SetLabel ( wxString : : Format ( " 0x%X " , current_profile - > lastMissionId ( ) ) ) ;
}
2021-05-12 13:53:51 +02:00
_verseSteel - > SetValueFromInt ( current_profile - > getVerseSteel ( ) ) ;
_undinium - > SetValueFromInt ( current_profile - > getUndinium ( ) ) ;
_necriumAlloy - > SetValueFromInt ( current_profile - > getNecriumAlloy ( ) ) ;
_lunarite - > SetValueFromInt ( current_profile - > getLunarite ( ) ) ;
_asterite - > SetValueFromInt ( current_profile - > getAsterite ( ) ) ;
_ednil - > SetValueFromInt ( current_profile - > getEdnil ( ) ) ;
_nuflalt - > SetValueFromInt ( current_profile - > getNuflalt ( ) ) ;
_aurelene - > SetValueFromInt ( current_profile - > getAurelene ( ) ) ;
_soldus - > SetValueFromInt ( current_profile - > getSoldus ( ) ) ;
_synthesizedN - > SetValueFromInt ( current_profile - > getSynthesizedN ( ) ) ;
_alcarbonite - > SetValueFromInt ( current_profile - > getAlcarbonite ( ) ) ;
_keriphene - > SetValueFromInt ( current_profile - > getKeriphene ( ) ) ;
_nitinolCM - > SetValueFromInt ( current_profile - > getNitinolCM ( ) ) ;
_quarkium - > SetValueFromInt ( current_profile - > getQuarkium ( ) ) ;
_alterene - > SetValueFromInt ( current_profile - > getAlterene ( ) ) ;
_mixedComposition - > SetValueFromInt ( current_profile - > getMixedComposition ( ) ) ;
_voidResidue - > SetValueFromInt ( current_profile - > getVoidResidue ( ) ) ;
_muscularConstruction - > SetValueFromInt ( current_profile - > getMuscularConstruction ( ) ) ;
_mineralExoskeletology - > SetValueFromInt ( current_profile - > getMineralExoskeletology ( ) ) ;
_carbonizedSkin - > SetValueFromInt ( current_profile - > getCarbonizedSkin ( ) ) ;
2021-05-12 20:39:48 +02:00
updateCommandsState ( ) ;
2020-09-30 16:27:26 +02:00
}
2021-05-11 14:54:33 +02:00
void EvtMainFrame : : initStoryProgressMenu ( ) {
_storyProgressSelectionMenu . emplace ( ) ;
if ( ! _storyProgressSelectionMenu ) {
errorMessage ( " Error initialising the story progress selection menu. " ) ;
this - > Destroy ( ) ;
return ;
}
wxMenu * submenu = nullptr ;
for ( const auto & pair : story_progress_map ) {
if ( std : : strncmp ( pair . second + 10 , " start " , 5 ) = = 0 ) {
submenu = new wxMenu ( ) ;
if ( ! submenu ) {
errorMessage ( " Error initialising the story progress selection menu. " ) ;
this - > Destroy ( ) ;
return ;
}
_storyProgressSelectionMenu - > Append ( wxID_ANY , wxString { pair . second , 9 } , submenu ) ;
wxMenuItem * item = submenu - > Append ( pair . first ^ ( - 10000 ) , " Chapter start " ) ;
if ( ! item ) {
errorMessage ( " Error initialising the story progress selection menu. " ) ;
this - > Destroy ( ) ;
return ;
}
}
else {
if ( ! submenu ) {
errorMessage ( " Error initialising the story progress selection menu. " ) ;
this - > Destroy ( ) ;
return ;
}
wxMenuItem * item = submenu - > Append ( pair . first ^ ( - 10000 ) , wxString { pair . second + 12 } ) ;
if ( ! item ) {
errorMessage ( " Error initialising the story progress selection menu. " ) ;
this - > Destroy ( ) ;
return ;
}
}
}
_storyProgressSelectionMenu - > Connect ( wxEVT_COMMAND_MENU_SELECTED , wxCommandEventHandler ( EvtMainFrame : : storyProgressSelectionEvent ) , nullptr , this ) ;
}
2020-01-09 13:59:19 +01:00
void EvtMainFrame : : initialiseListView ( ) {
for ( long i = 0 ; i < 32 ; i + + ) {
_installedListView - > InsertItem ( i , wxString : : Format ( " %.2i " , i + 1 ) ) ;
}
_installedListView - > SetColumnWidth ( 0 , wxLIST_AUTOSIZE_USEHEADER ) ;
_installedListView - > SetColumnWidth ( 1 , wxLIST_AUTOSIZE_USEHEADER ) ;
refreshListView ( ) ;
2020-06-20 10:45:49 +02:00
getActiveSlot ( ) ;
2020-01-09 13:59:19 +01:00
}
2020-01-10 12:23:25 +01:00
void EvtMainFrame : : isGameRunning ( ) {
2020-09-30 16:27:26 +02:00
_gameStatus - > SetLabel ( " checking... " ) ;
_gameStatus - > SetForegroundColour ( wxSystemSettings : : GetColour ( wxSYS_COLOUR_CAPTIONTEXT ) ) ;
GameState state = _mbManager . checkGameState ( ) ;
2020-01-12 14:54:23 +01:00
switch ( state ) {
case GameState : : Unknown :
_gameStatus - > SetLabel ( " unknown " ) ;
_gameStatus - > SetForegroundColour ( wxColour ( " orange " ) ) ;
break ;
case GameState : : NotRunning :
2020-01-10 12:23:25 +01:00
_gameStatus - > SetLabel ( " not running " ) ;
_gameStatus - > SetForegroundColour ( wxSystemSettings : : GetColour ( wxSYS_COLOUR_CAPTIONTEXT ) ) ;
2020-01-12 14:54:23 +01:00
break ;
case GameState : : Running :
_gameStatus - > SetLabel ( " running " ) ;
_gameStatus - > SetForegroundColour ( wxColour ( " red " ) ) ;
break ;
2020-01-10 12:23:25 +01:00
}
updateCommandsState ( ) ;
}
2020-01-09 13:59:19 +01:00
void EvtMainFrame : : refreshListView ( ) {
2020-01-12 14:54:23 +01:00
for ( int i = 0 ; i < 32 ; i + + ) {
refreshHangar ( i ) ;
2020-01-09 13:59:19 +01:00
}
updateCommandsState ( ) ;
}
2020-01-10 22:50:41 +01:00
void EvtMainFrame : : getActiveSlot ( ) {
2020-09-30 16:27:26 +02:00
auto slot = _profileManager . currentProfile ( ) - > activeFrameSlot ( ) ;
2020-01-10 22:50:41 +01:00
2020-06-20 10:45:49 +02:00
if ( slot ! = - 1 ) {
wxFont tmp_font = _installedListView - > GetItemFont ( slot ) ;
tmp_font . SetWeight ( wxFONTWEIGHT_NORMAL ) ;
_installedListView - > SetItemFont ( slot , tmp_font ) ;
}
2020-01-12 14:54:23 +01:00
2020-09-30 16:27:26 +02:00
slot = _profileManager . currentProfile ( ) - > getActiveFrameSlot ( ) ;
2020-01-11 11:02:45 +01:00
2020-01-12 14:54:23 +01:00
if ( slot ! = - 1 ) {
_installedListView - > SetItemFont ( slot , _installedListView - > GetItemFont ( slot ) . Bold ( ) ) ;
2020-01-11 11:02:45 +01:00
}
2020-01-10 22:50:41 +01:00
}
2020-01-09 13:59:19 +01:00
void EvtMainFrame : : updateCommandsState ( ) {
long selection = _installedListView - > GetFirstSelected ( ) ;
2020-01-16 01:21:25 +01:00
int staged_selection = _stagingList - > GetSelection ( ) ;
2020-09-30 16:27:26 +02:00
GameState game_state = _mbManager . gameState ( ) ;
MassState mass_state = _massManager - > massState ( selection ) ;
2020-01-10 12:23:25 +01:00
2021-05-11 14:52:52 +02:00
_companyRenameButton - > Enable ( _unsafeMode = = true | | game_state = = GameState : : NotRunning ) ;
2021-05-12 20:21:35 +02:00
_creditsEditButton - > Enable ( _unsafeMode = = true | | game_state = = GameState : : NotRunning ) ;
2021-05-11 14:54:33 +02:00
_storyProgressChangeButton - > Enable ( _unsafeMode = = true | | game_state = = GameState : : NotRunning ) ;
2021-05-11 14:52:52 +02:00
2021-05-12 13:53:51 +02:00
wxPropertyGridConstIterator it = _researchInventoryPropGrid - > GetIterator ( wxPG_ITERATE_NORMAL ) ;
while ( ! it . AtEnd ( ) ) {
if ( it . GetProperty ( ) - > IsCategory ( ) = = false ) {
2021-05-12 20:39:48 +02:00
it . GetProperty ( ) - > Enable ( it . GetProperty ( ) - > GetValue ( ) . GetInteger ( ) ! = - 1 & & ( _unsafeMode = = true | | game_state = = GameState : : NotRunning ) ) ;
2021-05-12 13:53:51 +02:00
}
it . Next ( ) ;
}
2021-03-05 14:56:28 +01:00
_importButton - > Enable ( selection ! = - 1 & & staged_selection ! = - 1 & & ( _unsafeMode = = true | | game_state = = GameState : : NotRunning ) ) ;
2020-01-14 12:26:05 +01:00
_exportButton - > Enable ( selection ! = - 1 ) ;
2021-03-05 14:56:28 +01:00
_moveButton - > Enable ( selection ! = - 1 & & ( _unsafeMode = = true | | game_state = = GameState : : NotRunning ) & & mass_state = = MassState : : Valid ) ;
_deleteButton - > Enable ( selection ! = - 1 & & ( _unsafeMode = = true | | game_state = = GameState : : NotRunning ) & & mass_state ! = MassState : : Empty ) ;
_renameButton - > Enable ( selection ! = - 1 & & ( _unsafeMode = = true | | game_state = = GameState : : NotRunning ) & & mass_state = = MassState : : Valid ) ;
2020-01-16 09:36:46 +01:00
_deleteStagedButton - > Enable ( staged_selection ! = - 1 ) ;
2020-01-09 13:59:19 +01:00
}
2020-01-12 14:54:23 +01:00
void EvtMainFrame : : refreshHangar ( int slot ) {
if ( slot < 0 & & slot > = 32 ) {
return ;
2020-01-09 13:59:19 +01:00
}
2020-09-30 16:27:26 +02:00
_massManager - > refreshHangar ( slot ) ;
2020-01-09 13:59:19 +01:00
2020-09-30 16:27:26 +02:00
switch ( _massManager - > massState ( slot ) ) {
case MassState : : Empty :
2020-01-12 14:54:23 +01:00
_installedListView - > SetItem ( slot , 1 , " <Empty> " ) ;
break ;
2020-09-30 16:27:26 +02:00
case MassState : : Invalid :
2020-01-12 14:54:23 +01:00
_installedListView - > SetItem ( slot , 1 , " <Invalid> " ) ;
break ;
2020-09-30 16:27:26 +02:00
case MassState : : Valid :
_installedListView - > SetItem ( slot , 1 , _massManager - > massName ( slot ) ) ;
2020-01-12 14:54:23 +01:00
break ;
2020-01-09 13:59:19 +01:00
}
}
void EvtMainFrame : : infoMessage ( const wxString & message ) {
wxMessageBox ( message , " Information " , wxOK | wxCENTRE | wxICON_INFORMATION , this ) ;
}
void EvtMainFrame : : warningMessage ( const wxString & message ) {
wxMessageBox ( message , " Warning " , wxOK | wxCENTRE | wxICON_WARNING , this ) ;
}
void EvtMainFrame : : errorMessage ( const wxString & message ) {
wxMessageBox ( message , " Error " , wxOK | wxCENTRE | wxICON_ERROR , this ) ;
}