From ca2d492efcd9ec46b513f13feb843a243e92b99a Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 2 Jul 2023 08:17:19 +0300 Subject: [PATCH] reimplemented unit listboxes in the map editor --- CMakeLists.txt | 2 +- concreteGuiManager.cpp | 3 ++- mapEditorAppState.cpp | 16 ---------------- mapEditorAppState.h | 8 -------- unitListbox.cpp | 26 ++++++++++++++++++++++++++ unitListbox.h | 15 +++++++++++++++ 6 files changed, 44 insertions(+), 26 deletions(-) create mode 100644 unitListbox.cpp create mode 100644 unitListbox.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d51a410..a2d2e32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ set(BUILD_TESTS ON) cmake_policy(SET CMP0015 NEW) set(BUTTONS singlePlayerButton.cpp mapEditorButton.cpp newMapButton.cpp loadMapButton.cpp optionsButton.cpp exitButton.cpp tabButton.cpp okButton.cpp defaultsButton.cpp backButton.cpp consoleCommand.cpp exportButton.cpp) -set(LISTBOXES skyboxTextureListbox.cpp landTextureListbox.cpp) +set(LISTBOXES skyboxTextureListbox.cpp landTextureListbox.cpp unitListbox.cpp) set(GUI tooltip.cpp concreteGuiManager.cpp ${BUTTONS} ${LISTBOXES}) set(STATES activeGameState.cpp inGameAppState.cpp guiAppState.cpp mapEditorAppState.cpp) diff --git a/concreteGuiManager.cpp b/concreteGuiManager.cpp index 4234e44..086e635 100644 --- a/concreteGuiManager.cpp +++ b/concreteGuiManager.cpp @@ -15,6 +15,7 @@ #include "exportButton.h" #include "skyboxTextureListbox.h" #include "landTextureListbox.h" +#include "unitListbox.h" namespace battleship{ using namespace std; @@ -196,7 +197,7 @@ namespace battleship{ closable = true; maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines); - listbox = new Listbox(pos, size, lines, maxDisplay, fontPath, closable); + listbox = new UnitListbox(pos, size, lines, maxDisplay, fontPath); break; } case SKYBOX_TEXTURES: diff --git a/mapEditorAppState.cpp b/mapEditorAppState.cpp index 3ce5053..969547c 100644 --- a/mapEditorAppState.cpp +++ b/mapEditorAppState.cpp @@ -37,21 +37,6 @@ namespace battleship{ using namespace std; using namespace std::filesystem; - MapEditorAppState::MapEditor::UnitListbox::UnitListbox(int startId, Vector2 pos, Vector2 size, vector lines, int maxDisplay, string fontPath) : Listbox(pos, size, lines, maxDisplay, fontPath){ - this->startId = startId; - } - - void MapEditorAppState::MapEditor::UnitListbox::onClose(){ - UnitFrameController *ufCtr = UnitFrameController::getSingleton(); - - int id = startId + selectedOption; - LuaManager *lm = LuaManager::getSingleton(); - string modelPath = lm->getStringFromTable("basePath", vector{Index(id + 1)}) + lm->getStringFromTable("meshPath", vector{Index(id + 1)}); - ufCtr->addUnitFrame(UnitFrameController::UnitFrame(modelPath, id, (int)UnitType::LAND)); - - ufCtr->setPlacingFrames(true); - } - MapEditorAppState::MapEditor::MapEditor(string name, Vector2 size, bool newMap){ this->newMap = newMap; this->mapSize = size; @@ -111,7 +96,6 @@ namespace battleship{ } } - void MapEditorAppState::MapEditor::createWaterbody(){ Material *mat = new Material(Root::getSingleton()->getLibPath() + "texture"); mat->addBoolUniform("lightingEnabled", false); diff --git a/mapEditorAppState.h b/mapEditorAppState.h index c301190..7a17369 100644 --- a/mapEditorAppState.h +++ b/mapEditorAppState.h @@ -24,13 +24,6 @@ namespace battleship{ public: class MapEditor{ public: - class UnitListbox : public vb01Gui::Listbox{ - public: - UnitListbox(int, vb01::Vector2, vb01::Vector2, std::vector, int, std::string); - void onClose(); - private: - int startId; - }; enum MovementAxis{ X_AXIS, Y_AXIS, @@ -81,7 +74,6 @@ namespace battleship{ vb01::Vector3 pushPos = vb01::Vector3::VEC_ZERO; vb01::Vector2 mapSize; std::vector skyTextures, landmassTextures, waterTextures; - UnitListbox *vehicleListbox = nullptr, *structureListbox = nullptr; }; MapEditorAppState(std::string, vb01::Vector2, bool); diff --git a/unitListbox.cpp b/unitListbox.cpp new file mode 100644 index 0000000..07e2915 --- /dev/null +++ b/unitListbox.cpp @@ -0,0 +1,26 @@ +#include "unitListbox.h" +#include "unit.h" +#include "unitFrameController.h" + +#include + +namespace battleship{ + using namespace std; + using namespace vb01; + using namespace vb01Gui; + using namespace gameBase; + + UnitListbox::UnitListbox(Vector2 pos, Vector2 size, vector lines, int maxDisplay, string fontPath) : Listbox(pos, size, lines, maxDisplay, fontPath){ + } + + void UnitListbox::onClose(){ + UnitFrameController *ufCtr = UnitFrameController::getSingleton(); + + int id = selectedOption; + LuaManager *lm = LuaManager::getSingleton(); + string modelPath = lm->getStringFromTable("basePath", vector{Index(id + 1)}) + lm->getStringFromTable("meshPath", vector{Index(id + 1)}); + ufCtr->addUnitFrame(UnitFrameController::UnitFrame(modelPath, id, (int)UnitType::LAND)); + + ufCtr->setPlacingFrames(true); + } +} diff --git a/unitListbox.h b/unitListbox.h new file mode 100644 index 0000000..ab66a7f --- /dev/null +++ b/unitListbox.h @@ -0,0 +1,15 @@ +#ifndef UNIT_LISTBOX_H +#define UNIT_LISTBOX_H + +#include + +namespace battleship{ + class UnitListbox : public vb01Gui::Listbox{ + public: + UnitListbox(vb01::Vector2, vb01::Vector2, std::vector, int, std::string); + void onClose(); + private: + }; +} + +#endif