Add a way to edit credits.

This commit is contained in:
Guillaume Jacquemin 2021-05-12 20:21:35 +02:00
parent 171fee333f
commit 13b2614af0
7 changed files with 140 additions and 17 deletions

View file

@ -210,6 +210,30 @@ void EvtMainFrame::companyRenameEvent(wxCommandEvent&) {
}
}
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.");
}
}
void EvtMainFrame::storyProgressSelectionEvent(wxCommandEvent& event) {
const static std::string error_prefix = "StoryProgress change failed:\n\n";
@ -787,6 +811,7 @@ void EvtMainFrame::updateCommandsState() {
MassState mass_state = _massManager->massState(selection);
_companyRenameButton->Enable(_unsafeMode == true || game_state == GameState::NotRunning);
_creditsEditButton->Enable(_unsafeMode == true || game_state == GameState::NotRunning);
_storyProgressChangeButton->Enable(_unsafeMode == true || game_state == GameState::NotRunning);
wxPropertyGridConstIterator it = _researchInventoryPropGrid->GetIterator(wxPG_ITERATE_NORMAL);

View file

@ -42,33 +42,34 @@ class EvtMainFrame: public MainFrame {
protected:
// Profile-related events
void profileSelectionEvent(wxCommandEvent&);
void backupSelectedProfileEvent(wxCommandEvent&);
void companyRenameEvent(wxCommandEvent&);
void profileSelectionEvent(wxCommandEvent&) override;
void backupSelectedProfileEvent(wxCommandEvent&) override;
void companyRenameEvent(wxCommandEvent&) override;
void creditsEditEvent(wxCommandEvent&) override;
void storyProgressSelectionEvent(wxCommandEvent& event);
void openStoryProgressMenuEvent(wxCommandEvent&);
void inventoryChangeEvent(wxPropertyGridEvent& event);
void openStoryProgressMenuEvent(wxCommandEvent&) override;
void inventoryChangeEvent(wxPropertyGridEvent& event) override;
// M.A.S.S.-related events
void importMassEvent(wxCommandEvent&);
void exportMassEvent(wxCommandEvent&);
void moveMassEvent(wxCommandEvent&);
void deleteMassEvent(wxCommandEvent&);
void renameMassEvent(wxCommandEvent&);
void openSaveDirEvent(wxCommandEvent&);
void stagingSelectionEvent(wxCommandEvent&);
void deleteStagedEvent(wxCommandEvent&);
void openStagingDirEvent(wxCommandEvent&);
void importMassEvent(wxCommandEvent&) override;
void exportMassEvent(wxCommandEvent&) override;
void moveMassEvent(wxCommandEvent&) override;
void deleteMassEvent(wxCommandEvent&) override;
void renameMassEvent(wxCommandEvent&) override;
void openSaveDirEvent(wxCommandEvent&) override;
void stagingSelectionEvent(wxCommandEvent&) override;
void deleteStagedEvent(wxCommandEvent&) override;
void openStagingDirEvent(wxCommandEvent&) override;
void installedSelectionEvent(wxListEvent&);
void listColumnDragEvent(wxListEvent&);
// Screenshot-related events
void openScreenshotDirEvent(wxCommandEvent&);
void openScreenshotDirEvent(wxCommandEvent&) override;
// General events
void fileUpdateEvent(wxFileSystemWatcherEvent& event);
void gameCheckTimerEvent(wxTimerEvent&);
void unsafeCheckboxEvent(wxCommandEvent& event);
void gameCheckTimerEvent(wxTimerEvent&) override;
void unsafeCheckboxEvent(wxCommandEvent& event) override;
private:
void saveFileEventHandler(int event_type, const wxString& event_file, const wxFileSystemWatcherEvent& event);

View file

@ -114,6 +114,9 @@ MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, co
_companyRenameButton = new wxButton( sbSizerGeneralInfo->GetStaticBox(), wxID_ANY, wxT("Rename company"), wxDefaultPosition, wxDefaultSize, 0 );
bSizerProfileCommands->Add( _companyRenameButton, 0, wxALL, 5 );
_creditsEditButton = new wxButton( sbSizerGeneralInfo->GetStaticBox(), wxID_ANY, wxT("Edit credits"), wxDefaultPosition, wxDefaultSize, 0 );
bSizerProfileCommands->Add( _creditsEditButton, 0, wxALL, 5 );
_storyProgressChangeButton = new wxButton( sbSizerGeneralInfo->GetStaticBox(), wxID_ANY, wxT("Change story progress"), wxDefaultPosition, wxDefaultSize, 0 );
bSizerProfileCommands->Add( _storyProgressChangeButton, 0, wxALL, 5 );
@ -298,6 +301,7 @@ MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, co
_openScreenshotDirButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::openScreenshotDirEvent ), NULL, this );
_unsafeCheckbox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( MainFrame::unsafeCheckboxEvent ), NULL, this );
_companyRenameButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::companyRenameEvent ), NULL, this );
_creditsEditButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::creditsEditEvent ), NULL, this );
_storyProgressChangeButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::openStoryProgressMenuEvent ), NULL, this );
_researchInventoryPropGrid->Connect( wxEVT_PG_CHANGING, wxPropertyGridEventHandler( MainFrame::inventoryChangeEvent ), NULL, this );
_moveButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::moveMassEvent ), NULL, this );
@ -320,6 +324,7 @@ MainFrame::~MainFrame()
_openScreenshotDirButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::openScreenshotDirEvent ), NULL, this );
_unsafeCheckbox->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( MainFrame::unsafeCheckboxEvent ), NULL, this );
_companyRenameButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::companyRenameEvent ), NULL, this );
_creditsEditButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::creditsEditEvent ), NULL, this );
_storyProgressChangeButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::openStoryProgressMenuEvent ), NULL, this );
_researchInventoryPropGrid->Disconnect( wxEVT_PG_CHANGING, wxPropertyGridEventHandler( MainFrame::inventoryChangeEvent ), NULL, this );
_moveButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::moveMassEvent ), NULL, this );

View file

@ -1194,6 +1194,79 @@
<event name="OnButtonClick">companyRenameEvent</event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="current"></property>
<property name="default">0</property>
<property name="default_pane">0</property>
<property name="disabled"></property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="focus"></property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Edit credits</property>
<property name="margins"></property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">_creditsEditButton</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="position"></property>
<property name="pressed"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick">creditsEditEvent</event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</property>

View file

@ -61,6 +61,7 @@ class MainFrame : public wxFrame
wxStaticText* _lastMissionIdLabel;
wxStaticText* _lastMissionId;
wxButton* _companyRenameButton;
wxButton* _creditsEditButton;
wxButton* _storyProgressChangeButton;
wxPropertyGrid* _researchInventoryPropGrid;
wxPGProperty* _materialsCategory;
@ -109,6 +110,7 @@ class MainFrame : public wxFrame
virtual void openScreenshotDirEvent( wxCommandEvent& event ) { event.Skip(); }
virtual void unsafeCheckboxEvent( wxCommandEvent& event ) { event.Skip(); }
virtual void companyRenameEvent( wxCommandEvent& event ) { event.Skip(); }
virtual void creditsEditEvent( wxCommandEvent& event ) { event.Skip(); }
virtual void openStoryProgressMenuEvent( wxCommandEvent& event ) { event.Skip(); }
virtual void inventoryChangeEvent( wxPropertyGridEvent& event ) { event.Skip(); }
virtual void moveMassEvent( wxCommandEvent& event ) { event.Skip(); }

View file

@ -187,6 +187,22 @@ auto Profile::getCredits() -> std::int32_t {
return _credits;
}
auto Profile::setCredits(std::int32_t amount) -> bool {
auto mmap = Utility::Directory::map(Utility::Directory::join(_profileDirectory, _filename));
auto iter = std::search(mmap.begin(), mmap.end(), &credits_locator[0], &credits_locator[22]);
if(iter != mmap.end()) {
*reinterpret_cast<std::int32_t*>(iter + 0x20) = amount;
_credits = amount;
return true;
}
else {
_lastError = "The profile save seems to be corrupted or the game didn't release the handle on the file.";
return false;
}
}
auto Profile::storyProgress() const -> std::int32_t {
return _storyProgress;
}

View file

@ -33,6 +33,7 @@ class Profile {
auto credits() const -> std::int32_t;
auto getCredits() -> std::int32_t;
auto setCredits(std::int32_t) -> bool;
auto storyProgress() const -> std::int32_t;
auto getStoryProgress() -> std::int32_t;