diff --git a/CMakeLists.txt b/CMakeLists.txt index 24a8004b..0c7353be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -404,6 +404,7 @@ set(GAME_HEADERS src/game/gui/ingame/map.h src/game/gui/ingame/messages.h src/game/gui/ingame/options.h + src/game/gui/levelup.h src/game/gui/loadscreen.h src/game/gui/mainmenu.h src/game/gui/partyselect.h @@ -501,6 +502,7 @@ set(GAME_SOURCES src/game/gui/ingame/map.cpp src/game/gui/ingame/messages.cpp src/game/gui/ingame/options.cpp + src/game/gui/levelup.cpp src/game/gui/loadscreen.cpp src/game/gui/mainmenu.cpp src/game/gui/partyselect.cpp diff --git a/src/game/game.cpp b/src/game/game.cpp index d025f3da..70a52f91 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -200,6 +200,9 @@ void Game::loadModule(const string &name, string entry) { if (!_partySelect) { loadPartySelection(); } + if (!_levelUp) { + loadLevelUp(); + } Models::instance().invalidateCache(); Walkmeshes::instance().invalidateCache(); @@ -392,6 +395,11 @@ void Game::loadSaveLoad() { _saveLoad->load(); } +void Game::loadLevelUp() { + _levelUp.reset(new LevelUpMenu(this)); + _levelUp->load(); +} + void Game::loadInGame() { _inGame.reset(new InGameMenu(this)); _inGame->load(); @@ -417,6 +425,8 @@ GUI *Game::getScreenGUI() const { return _partySelect.get(); case GameScreen::SaveLoad: return _saveLoad.get(); + case GameScreen::LevelUp: + return _levelUp.get(); default: return nullptr; } @@ -615,10 +625,15 @@ void Game::openPartySelection(const PartySelection::Context &ctx) { void Game::openSaveLoad(SaveLoad::Mode mode) { setCursorType(CursorType::Default); _saveLoad->setMode(mode); - _saveLoad->update(); + _saveLoad->refresh(); changeScreen(GameScreen::SaveLoad); } +void Game::openLevelUp() { + setCursorType(CursorType::Default); + changeScreen(GameScreen::LevelUp); +} + void Game::scheduleModuleTransition(const string &moduleName, const string &entry) { _nextModule = moduleName; _nextEntry = entry; diff --git a/src/game/game.h b/src/game/game.h index 47fa9c4b..38c3e107 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -36,6 +36,7 @@ #include "gui/dialog.h" #include "gui/hud.h" #include "gui/ingame/ingame.h" +#include "gui/levelup.h" #include "gui/loadscreen.h" #include "gui/mainmenu.h" #include "gui/partyselect.h" @@ -138,6 +139,7 @@ public: void openInGameMenu(InGameMenu::Tab tab); void openContainer(const std::shared_ptr &container); void openPartySelection(const PartySelection::Context &ctx); + void openLevelUp(); void startCharacterGeneration(); void startDialog(const std::shared_ptr &owner, const std::string &resRef); @@ -185,7 +187,8 @@ private: Dialog, Container, PartySelection, - SaveLoad + SaveLoad, + LevelUp }; boost::filesystem::path _path; @@ -227,6 +230,7 @@ private: std::unique_ptr _container; std::unique_ptr _partySelect; std::unique_ptr _saveLoad; + std::unique_ptr _levelUp; // END GUI @@ -287,6 +291,7 @@ private: void loadMainMenu(); void loadPartySelection(); void loadSaveLoad(); + void loadLevelUp(); // END Loading diff --git a/src/game/gui/ingame/abilities.cpp b/src/game/gui/ingame/abilities.cpp index c0770fc0..3a9ac25c 100644 --- a/src/game/gui/ingame/abilities.cpp +++ b/src/game/gui/ingame/abilities.cpp @@ -61,7 +61,7 @@ void AbilitiesMenu::load() { disableControl("BTN_FEATS"); } -void AbilitiesMenu::updatePortraits() { +void AbilitiesMenu::refreshPortraits() { if (_version != GameVersion::KotOR) return; Party &party = _game->party(); diff --git a/src/game/gui/ingame/abilities.h b/src/game/gui/ingame/abilities.h index d687d1ca..038a35db 100644 --- a/src/game/gui/ingame/abilities.h +++ b/src/game/gui/ingame/abilities.h @@ -31,7 +31,7 @@ public: void load() override; - void updatePortraits(); + void refreshPortraits(); private: Game *_game { nullptr }; diff --git a/src/game/gui/ingame/character.cpp b/src/game/gui/ingame/character.cpp index 094d6526..4157673a 100644 --- a/src/game/gui/ingame/character.cpp +++ b/src/game/gui/ingame/character.cpp @@ -94,12 +94,17 @@ void CharacterMenu::load() { hideControl("LBL_EXPERIENCE_STAT"); hideControl("LBL_NEEDED_XP"); - disableControl("BTN_LEVELUP"); disableControl("BTN_AUTO"); disableControl("BTN_SCRIPTS"); } -void CharacterMenu::updatePortraits() { +void CharacterMenu::update(float dt) { + shared_ptr leader(_game->party().leader()); + setControlVisible("BTN_LEVELUP", leader->isLevelUpPending()); + setControlVisible("BTN_AUTO", leader->isLevelUpPending()); +} + +void CharacterMenu::refreshPortraits() { if (_version != GameVersion::KotOR) return; Party &party = _game->party(); @@ -116,6 +121,8 @@ void CharacterMenu::updatePortraits() { void CharacterMenu::onClick(const string &control) { if (control == "BTN_EXIT") { _game->openInGame(); + } else if (control == "BTN_LEVELUP") { + _game->openLevelUp(); } } diff --git a/src/game/gui/ingame/character.h b/src/game/gui/ingame/character.h index 5b45fe8e..377c02af 100644 --- a/src/game/gui/ingame/character.h +++ b/src/game/gui/ingame/character.h @@ -30,8 +30,9 @@ public: CharacterMenu(Game *game); void load() override; + void update(float dt) override; - void updatePortraits(); + void refreshPortraits(); private: Game *_game { nullptr }; diff --git a/src/game/gui/ingame/ingame.cpp b/src/game/gui/ingame/ingame.cpp index 7814d28a..fab33a73 100644 --- a/src/game/gui/ingame/ingame.cpp +++ b/src/game/gui/ingame/ingame.cpp @@ -190,17 +190,17 @@ void InGameMenu::updateTabButtons() { } void InGameMenu::openInventory() { - _inventory->updatePortraits(); + _inventory->refreshPortraits(); changeTab(Tab::Inventory); } void InGameMenu::openCharacter() { - _character->updatePortraits(); + _character->refreshPortraits(); changeTab(Tab::Character); } void InGameMenu::openAbilities() { - _abilities->updatePortraits(); + _abilities->refreshPortraits(); changeTab(Tab::Abilities); } diff --git a/src/game/gui/ingame/inventory.cpp b/src/game/gui/ingame/inventory.cpp index c77f731d..47f952e8 100644 --- a/src/game/gui/ingame/inventory.cpp +++ b/src/game/gui/ingame/inventory.cpp @@ -63,7 +63,7 @@ void InventoryMenu::load() { setControlFocusable("BTN_CHANGE2", false); } -void InventoryMenu::updatePortraits() { +void InventoryMenu::refreshPortraits() { if (_version != GameVersion::KotOR) return; Party &party = _game->party(); diff --git a/src/game/gui/ingame/inventory.h b/src/game/gui/ingame/inventory.h index d45ec172..d0d746e9 100644 --- a/src/game/gui/ingame/inventory.h +++ b/src/game/gui/ingame/inventory.h @@ -31,7 +31,7 @@ public: void load() override; - void updatePortraits(); + void refreshPortraits(); private: Game *_game { nullptr }; diff --git a/src/game/gui/levelup.cpp b/src/game/gui/levelup.cpp new file mode 100644 index 00000000..a7ffe903 --- /dev/null +++ b/src/game/gui/levelup.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2020-2021 The reone project contributors + * + * 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 . + */ + +#include "levelup.h" + +#include "../game.h" + +using namespace reone::gui; + +namespace reone { + +namespace game { + +LevelUpMenu::LevelUpMenu(Game *game) : + GUI(game->version(), game->options().graphics), + _game(game) { + + _resRef = getResRef("leveluppnl"); + _backgroundType = BackgroundType::Menu; +} + +void LevelUpMenu::onClick(const std::string &control) { + if (control == "BTN_BACK") { + _game->openInGame(); + } +} + +} // namespace game + +} // namespace reone diff --git a/src/game/gui/levelup.h b/src/game/gui/levelup.h new file mode 100644 index 00000000..88ac63f2 --- /dev/null +++ b/src/game/gui/levelup.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020-2021 The reone project contributors + * + * 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 . + */ + +#pragma once + +#include "../../gui/gui.h" + +namespace reone { + +namespace game { + +class Game; + +class LevelUpMenu : public gui::GUI { +public: + LevelUpMenu(Game *game); + +private: + Game *_game; + + void onClick(const std::string &control) override; +}; + +} // namespace game + +} // namespace reone diff --git a/src/game/gui/saveload.cpp b/src/game/gui/saveload.cpp index 87eb49a1..c0b7ed46 100644 --- a/src/game/gui/saveload.cpp +++ b/src/game/gui/saveload.cpp @@ -79,7 +79,7 @@ void SaveLoad::load() { protoItem.setHilightColor(_defaultHilightColor); } -void SaveLoad::update() { +void SaveLoad::refresh() { string panelName(Resources::instance().getString(_mode == Mode::Save ? kStrRefSaveGame : kStrRefLoadGame)); Control &lblPanelName = getControl("LBL_PANELNAME"); @@ -157,7 +157,7 @@ void SaveLoad::onClick(const string &control) { saveIdx = getNewSaveIndex(); } saveGame(saveIdx); - update(); + refresh(); break; default: if (saveIdx != -1) { @@ -169,7 +169,7 @@ void SaveLoad::onClick(const string &control) { int saveIdx = getSelectedSaveIndex(); if (saveIdx != -1) { deleteGame(saveIdx); - update(); + refresh(); } } else if (control == "BTN_BACK") { ListBox &lbGames = getControl("LB_GAMES"); diff --git a/src/game/gui/saveload.h b/src/game/gui/saveload.h index 1b3214b4..969e71e2 100644 --- a/src/game/gui/saveload.h +++ b/src/game/gui/saveload.h @@ -39,7 +39,7 @@ public: void load() override; - void update(); + void refresh(); void setMode(Mode mode); diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 93537f2d..71228e9c 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -17,6 +17,8 @@ #include "gui.h" +#include + #include "../common/log.h" #include "../render/mesh/quad.h" #include "../render/shaders.h" @@ -44,6 +46,9 @@ string GUI::getResRef(const string &base) const { } void GUI::load() { + if (_resRef.empty()) { + throw logic_error("resRef must not be empty"); + } info("GUI: load " + _resRef); shared_ptr gui(Resources::instance().getGFF(_resRef, ResourceType::Gui));