diff --git a/source/code/HelpAboutState.cpp b/source/code/HelpAboutState.cpp index 6be988c..24d0666 100644 --- a/source/code/HelpAboutState.cpp +++ b/source/code/HelpAboutState.cpp @@ -89,13 +89,3 @@ HelpAboutState::HelpAboutState() { HelpAboutState::~HelpAboutState() { } - - -void HelpAboutState::Draw(SDL_Renderer* target) { - DrawBackground(target); - titleField.Draw(target, 50, 50); - DrawRectYellow(target, 40, 90, 600, 900); - infoBox.SetMaxWidth(850); - infoBox.Draw(target, 50, 100); - HelpCommonState::Draw(target); -} diff --git a/source/code/HelpAboutState.hpp b/source/code/HelpAboutState.hpp index 9e0978e..c558147 100644 --- a/source/code/HelpAboutState.hpp +++ b/source/code/HelpAboutState.hpp @@ -28,18 +28,11 @@ https://blockattack.net #include "sago/SagoTextBox.hpp" #include "sago/SagoTextField.hpp" -class HelpAboutState : public HelpCommonState { +class HelpAboutState : public HelpTextBoxState { public: HelpAboutState(); HelpAboutState(const HelpAboutState& orig) = delete; virtual ~HelpAboutState(); - - void Draw(SDL_Renderer* target) override; -private: - bool isActive = true; - bool bMouseUp = true; - sago::SagoTextField titleField; - sago::SagoTextBox infoBox; }; #endif /* HELPABOUT_HPP */ diff --git a/source/code/HelpCommon.cpp b/source/code/HelpCommon.cpp index c9191f1..3f7a514 100644 --- a/source/code/HelpCommon.cpp +++ b/source/code/HelpCommon.cpp @@ -24,6 +24,7 @@ https://blockattack.net #include "HelpCommon.hpp" #include "MenuSystem.h" #include "global.hpp" +#include "DialogBox.hpp" @@ -59,12 +60,6 @@ void setHelp30FontThinOutline(const sago::SagoDataHolder* holder, sago::SagoText field.SetOutline(1, {128,128,128,255}); } -HelpCommonState::HelpCommonState() { -} - -HelpCommonState::~HelpCommonState() { -} - bool HelpCommonState::IsActive() { return isActive; } @@ -94,6 +89,19 @@ void HelpCommonState::Draw(SDL_Renderer* target) { #endif } +void HelpTextBoxState::Draw(SDL_Renderer* target) { + DrawBackground(target); + titleField.Draw(target, 50, 50); + DrawRectYellow(target, 40, 90, 600, 900); + infoBox.SetMaxWidth(850); + infoBox.Draw(target, 50, 100); + if (filenameField.GetText().length() > 0) { + DrawRectYellow(target, 40, 700, 50, 900); + filenameField.Draw(target, 50, 715); + } + HelpCommonState::Draw(target); +} + void HelpCommonState::Update() { // If the mouse button is released, make bMouseUp equal true diff --git a/source/code/HelpCommon.hpp b/source/code/HelpCommon.hpp index 2ada98d..080fe55 100644 --- a/source/code/HelpCommon.hpp +++ b/source/code/HelpCommon.hpp @@ -38,9 +38,9 @@ void setHelpBoxFont(const sago::SagoDataHolder* holder, sago::SagoTextBox& field class HelpCommonState : public sago::GameStateInterface { public: - HelpCommonState(); + HelpCommonState() = default; HelpCommonState(const HelpCommonState& orig) = delete; - virtual ~HelpCommonState(); + virtual ~HelpCommonState() = default; bool IsActive() override; void ProcessInput(const SDL_Event& event, bool &processed) override; @@ -53,4 +53,16 @@ private: bool bMouseUp = true; }; +class HelpTextBoxState : public HelpCommonState { +public: + HelpTextBoxState() = default; + HelpTextBoxState(const HelpTextBoxState& orig) = delete; + virtual ~HelpTextBoxState() = default; + void Draw(SDL_Renderer* target) override; +protected: + sago::SagoTextField titleField; + sago::SagoTextBox infoBox; + sago::SagoTextBox filenameField; +}; + #endif //_HELP_COMMON_HPP diff --git a/source/code/HelpGamepadState.hpp b/source/code/HelpGamepadState.hpp index 383f10e..1ecb0e0 100644 --- a/source/code/HelpGamepadState.hpp +++ b/source/code/HelpGamepadState.hpp @@ -36,8 +36,6 @@ public: void Draw(SDL_Renderer* target) override; void ProcessInput(const SDL_Event& event, bool &processed) override; private: - bool isActive = true; - bool bMouseUp = true; sago::SagoTextField moveLabel; sago::SagoTextField pushLabel; sago::SagoTextField backLabel; diff --git a/source/code/HelpHowtoState.hpp b/source/code/HelpHowtoState.hpp index dfef89d..11fc945 100644 --- a/source/code/HelpHowtoState.hpp +++ b/source/code/HelpHowtoState.hpp @@ -35,10 +35,6 @@ public: virtual ~HelpHowtoState(); void Draw(SDL_Renderer* target) override; void Update() override; - -private: - bool isActive = true; - bool bMouseUp = true; }; #endif /* HELPHOWTOSTATE_HPP */ diff --git a/source/code/HelpModInfoState.cpp b/source/code/HelpModInfoState.cpp new file mode 100644 index 0000000..f29e7be --- /dev/null +++ b/source/code/HelpModInfoState.cpp @@ -0,0 +1,109 @@ +/* +=========================================================================== +blockattack - Block Attack - Rise of the Blocks +Copyright (C) 2005-2022 Poul Sander + +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 2 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/ + +Source information and contacts persons can be found at +https://blockattack.net +=========================================================================== +*/ + +#include "DialogBox.hpp" +#include "HelpModInfoState.hpp" +#include "global.hpp" +#include "common.h" +#include "sago/SagoMisc.hpp" +#include "os.hpp" +#include +#include + +struct Mod { + std::string name; + std::string filename; + bool enabled = false; + int order = 0; +}; + +static bool sort_mods_enabled_order (const Mod& i,const Mod& j) { + if (i.enabled && !j.enabled) { + //Enabled mods always goes before disabled ones + return true; + } + if (i.enabled) { + return i.order < j.order; + } + return i.name < j.name; +} + +static void initMods(std::vector& mod_list) { + for (size_t i=0; i < globalData.modList.size(); ++i) { + for (Mod& m : mod_list) { + if (m.name == globalData.modList[i]) { + m.order = i; + m.enabled = true; + } + } + } + std::sort(mod_list.begin(), mod_list.end(), sort_mods_enabled_order); +} + +static void appendMods(const std::vector& mod_files, const std::string& dir, std::vector& mods_available) { + for (const std::string& mod : mod_files) { + if (!boost::ends_with(mod, ".data")) { + continue; + } + Mod m; + m.name = mod.substr(0, mod.length()-5); + m.filename = dir + "/" + mod; + mods_available.push_back(m); + } +} + +static std::vector get_mods() { + std::vector mods_available; + std::string baseMods = std::string(PHYSFS_getBaseDir())+ "/mods"; + std::vector baseModFiles = OsGetDirFileList(baseMods); + appendMods(baseModFiles, baseMods, mods_available); + std::string sharedMods = std::string(SHAREDIR)+ "/mods"; + std::vector sharedModFiles = OsGetDirFileList(sharedMods); + appendMods(sharedModFiles, sharedMods, mods_available); + std::string userMods = getPathToSaveFiles()+"/mods"; + std::vector userModFiles = OsGetDirFileList(userMods); + appendMods(userModFiles, userMods, mods_available); + initMods(mods_available); + return mods_available; +} + +HelpModInfoState::HelpModInfoState() { + std::vector mods_available = get_mods(); + std::stringstream infoStream; + infoStream << _("Load order:") << "\n"; + for (size_t i=0; i < mods_available.size(); ++i) { + const Mod& mod = mods_available[i]; + if (mod.enabled) { + infoStream << mod.order << " : " << mod.name << " "; + } + else { + infoStream << "- : " << mod.name << " " << _("(Disabled)"); + } + infoStream << "\n"; + } + setHelp30FontThinOutline(&globalData.spriteHolder->GetDataHolder(), titleField, _("Mod info")); + setHelpBoxFont(&globalData.spriteHolder->GetDataHolder(), infoBox, infoStream.str().c_str()); +} + +HelpModInfoState::~HelpModInfoState() { +} \ No newline at end of file diff --git a/source/code/HelpModInfoState.hpp b/source/code/HelpModInfoState.hpp new file mode 100644 index 0000000..1435bc7 --- /dev/null +++ b/source/code/HelpModInfoState.hpp @@ -0,0 +1,38 @@ +/* +=========================================================================== +blockattack - Block Attack - Rise of the Blocks +Copyright (C) 2005-2022 Poul Sander + +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 2 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/ + +Source information and contacts persons can be found at +https://blockattack.net +=========================================================================== +*/ + +#ifndef HELPMODINFOSTATE_HPP +#define HELPMODINFOSTATE_HPP + +#include "HelpCommon.hpp" +#include "sago/SagoTextField.hpp" +#include "sago/SagoTextBox.hpp" + +class HelpModInfoState : public HelpTextBoxState { +public: + HelpModInfoState(); + virtual ~HelpModInfoState(); +}; + +#endif /* HELPMODINFOSTATE_HPP */ + diff --git a/source/code/ModConfigMenuState.cpp b/source/code/ModConfigMenuState.cpp deleted file mode 100644 index 0400c07..0000000 --- a/source/code/ModConfigMenuState.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* -=========================================================================== -blockattack - Block Attack - Rise of the Blocks -Copyright (C) 2005-2020 Poul Sander - -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 2 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/ - -Source information and contacts persons can be found at -https://blockattack.net -=========================================================================== -*/ - -#include "ModConfigMenuState.hpp" -#include "MenuSystem.h" -#include "global.hpp" -#include "MenuSystem.h" -#include "sago/SagoMisc.hpp" -#include "os.hpp" -#include - -const int buttonOffset = 160; -extern sago::SagoSprite bExit; - -bool sort_mods_enabled_order (const Mod& i,const Mod& j) { - if (i.enabled && !j.enabled) { - //Enabled mods always goes before disabled ones - return true; - } - if (i.enabled) { - return i.order < j.order; - } - return i.name < j.name; -} - -static void initMods(std::vector& mod_list) { - for (size_t i=0; i < globalData.modList.size(); ++i) { - for (Mod& m : mod_list) { - if (m.name == globalData.modList[i]) { - m.order = i; - m.enabled = true; - } - } - } - std::sort(mod_list.begin(), mod_list.end(), sort_mods_enabled_order); -} - -static void appendMods(const std::vector& mod_files, const std::string& dir, std::vector& mods_available) { - for (const std::string& mod : mod_files) { - if (!boost::ends_with(mod, ".data")) { - continue; - } - Mod m; - m.name = mod.substr(0, mod.length()-5); - m.filename = dir + "/" + mod; - mods_available.push_back(m); - } -} - - -ModConfigMenuState::ModConfigMenuState() { - mods_available.clear(); - std::string baseMods = std::string(PHYSFS_getBaseDir())+ "/mods"; - std::vector baseModFiles = OsGetDirFileList(baseMods); - appendMods(baseModFiles, baseMods, mods_available); - std::string sharedMods = std::string(SHAREDIR)+ "/mods"; - std::vector sharedModFiles = OsGetDirFileList(sharedMods); - appendMods(sharedModFiles, sharedMods, mods_available); - std::string userMods = getPathToSaveFiles()+"/mods"; - std::vector userModFiles = OsGetDirFileList(userMods); - appendMods(userModFiles, userMods, mods_available); - initMods(mods_available); -} - -ModConfigMenuState::~ModConfigMenuState() {} - -bool ModConfigMenuState::IsActive() { - return isActive; -} - -void ModConfigMenuState::Draw(SDL_Renderer* target) { - DrawBackground(target); - standardButton.getLabel(_("Mod config"))->Draw(target, 50, 50); - for (size_t i = 0; i < mods_available.size(); ++i) { - standardButton.getLabel(mods_available[i].name)->Draw(target, 60, 160+30*i); - standardButton.getLabel(mods_available[i].enabled ? _("Yes") : _("No"))->Draw(target, 600, 160+30*i); - if (mods_available[i].enabled) { - standardButton.getLabel(std::to_string(mods_available[i].order))->Draw(target, 700, 160+30*i); - } - } - bExit.Draw(globalData.screen, SDL_GetTicks(), globalData.xsize-buttonOffset, globalData.ysize-buttonOffset); -} - -void ModConfigMenuState::ProcessInput(const SDL_Event& event, bool& processed) { - if (isEscapeEvent(event)) { - isActive = false; - processed = true; - } -} - -void ModConfigMenuState::Update() { - // If the mouse button is released, make bMouseUp equal true - if ( !(SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(1)) ) { - bMouseUp=true; - } - - if (SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(1) && bMouseUp) { - bMouseUp = false; - - //The Score button: - if ((globalData.mousex>globalData.xsize-buttonOffset) && (globalData.mousexglobalData.ysize-buttonOffset) && (globalData.mousey mods_available; -}; - -#endif /* MODCONFIG_HPP */ diff --git a/source/code/ShowFileState.cpp b/source/code/ShowFileState.cpp index e420562..cd92c7f 100644 --- a/source/code/ShowFileState.cpp +++ b/source/code/ShowFileState.cpp @@ -17,7 +17,6 @@ https://blockattack.net =========================================================================== */ -#include "DialogBox.hpp" #include "HelpCommon.hpp" #include "ShowFileState.hpp" #include "global.hpp" @@ -39,15 +38,3 @@ void ShowFileState::SetData(const std::string& filename, const std::string& head infoBox.SetText(sago::GetFileContent(filename)); filenameField.SetText(fmt::format(_("Showing content of: {}"), filename)); } - -void ShowFileState::Draw(SDL_Renderer* target) { - DrawBackground(target); - titleField.Draw(target, 50, 50); - DrawRectYellow(target, 40, 90, 600, 900); - infoBox.SetMaxWidth(850); - infoBox.Draw(target, 50, 100); - DrawRectYellow(target, 40, 700, 50, 900); - filenameField.Draw(target, 50, 715); - HelpCommonState::Draw(target); -} - diff --git a/source/code/ShowFileState.hpp b/source/code/ShowFileState.hpp index de558b7..13063d1 100644 --- a/source/code/ShowFileState.hpp +++ b/source/code/ShowFileState.hpp @@ -28,22 +28,13 @@ https://blockattack.net #include #include "common.h" -class ShowFileState : public HelpCommonState { +class ShowFileState : public HelpTextBoxState { public: ShowFileState(); ShowFileState(const ShowFileState& orig) = delete; virtual ~ShowFileState(); - void Draw(SDL_Renderer* target) override; - void SetData(const std::string& filename, const std::string& header); - -private: - bool isActive = true; - bool bMouseUp = true; - sago::SagoTextField titleField; - sago::SagoTextBox filenameField; - sago::SagoTextBox infoBox; }; #endif /* SHOWFILESTATE_HPP */ diff --git a/source/code/menudef.cpp b/source/code/menudef.cpp index 13fb9b1..d371236 100644 --- a/source/code/menudef.cpp +++ b/source/code/menudef.cpp @@ -26,10 +26,10 @@ http://blockattack.net #include "MenuSystem.h" #include "common.h" #include "HelpHowtoState.hpp" +#include "HelpModInfoState.hpp" #include "HelpGamepadState.hpp" #include "HelpAboutState.hpp" #include "ShowFileState.hpp" -#include "ModConfigMenuState.hpp" #include @@ -435,11 +435,6 @@ static void PlayerConfigMenu() { RunGameState(pcm); } -static void runModConfigMenu() { - ModConfigMenuState modmenu; - RunGameState(modmenu); -} - static void ConfigureMenu() { Menu cm(globalData.screen,_("Configuration"),true); AlwaysSoftwareRenderButton bSoftware; @@ -447,11 +442,8 @@ static void ConfigureMenu() { SoundButton bSound; FullscreenButton buttonFullscreen; Button bPlayerConfig; - Button bModConfig; bPlayerConfig.setLabel(_("Player configuration") ); bPlayerConfig.setAction(PlayerConfigMenu); - bModConfig.setLabel(_("Configure mods")); - bModConfig.setAction(&runModConfigMenu); SetAlwaysSoftwareLabel(&bSoftware); SetMusicLabel(&bMusic); SetSoundLabel(&bSound); @@ -461,7 +453,6 @@ static void ConfigureMenu() { cm.addButton(&bSoftware); cm.addButton(&buttonFullscreen); cm.addButton(&bPlayerConfig); - cm.addButton(&bModConfig); RunGameState(cm); } @@ -516,6 +507,11 @@ static void runHowto() { RunGameState(howto); } +static void runHelpModInfo() { + HelpModInfoState modInfo; + RunGameState(modInfo); +} + static void runHelpGamepad() { HelpGamepadState helpGamepad; RunGameState(helpGamepad); @@ -542,6 +538,10 @@ static void HelpMenu() { bGamepad.setLabel(_("Gamepad")); bGamepad.setAction(runHelpGamepad); m.addButton(&bGamepad); + Button bModInfo; + bModInfo.setLabel(_("Mod info")); + bModInfo.setAction(runHelpModInfo); + m.addButton(&bModInfo); Button bCredits; bCredits.setLabel(_("Credits")); bCredits.setAction(runCredits);