From d0d49da906c2d3403feb256503e2cf3548c82e05 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Mon, 1 Apr 2024 12:10:24 +0300 Subject: [PATCH] resource ammount incrementation and decrementation buttons --- Assets/Scripts/Gui/main.lua | 3 ++- Assets/Scripts/Gui/tradingScreen.lua | 8 ++++---- CMakeLists.txt | 2 +- concreteGuiManager.cpp | 4 ++++ concreteGuiManager.h | 3 ++- resourceAmmountButton.cpp | 25 +++++++++++++++++++++++++ resourceAmmountButton.h | 21 +++++++++++++++++++++ 7 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 resourceAmmountButton.cpp create mode 100644 resourceAmmountButton.h diff --git a/Assets/Scripts/Gui/main.lua b/Assets/Scripts/Gui/main.lua index 532731d..bf9ba09 100644 --- a/Assets/Scripts/Gui/main.lua +++ b/Assets/Scripts/Gui/main.lua @@ -36,7 +36,8 @@ ButtonType = { ACTIVE_GAME_STATE = 32, PLAYER_TRADE = 33, TRADING_SCREEN = 34, - TRADE_OFFER = 35 + TRADE_OFFER = 35, + RESOURCE_AMMOUNT = 36 } ListboxType = { diff --git a/Assets/Scripts/Gui/tradingScreen.lua b/Assets/Scripts/Gui/tradingScreen.lua index 6fe56d7..f1b042a 100644 --- a/Assets/Scripts/Gui/tradingScreen.lua +++ b/Assets/Scripts/Gui/tradingScreen.lua @@ -37,9 +37,9 @@ function createResourceTrayGui(cpuPlayer, lineId, guiId, imgPath) return { guiType = GuiType.BUTTON, - buttonType = ButtonType.ACTIVE_GAME_STATE, + buttonType = ButtonType.RESOURCE_AMMOUNT, + ammount = 10, name = '+', - guiScreen = 'tradingScreen.lua', pos = guiElPos, size = iconSize, trigger = 10 @@ -49,9 +49,9 @@ function createResourceTrayGui(cpuPlayer, lineId, guiId, imgPath) return { guiType = GuiType.BUTTON, - buttonType = ButtonType.ACTIVE_GAME_STATE, + buttonType = ButtonType.RESOURCE_AMMOUNT, + ammount = -10, name = '-', - guiScreen = 'tradingScreen.lua', pos = guiElPos, size = iconSize, trigger = 10 diff --git a/CMakeLists.txt b/CMakeLists.txt index c187b31..dae23e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ cmake_policy(SET CMP0015 NEW) set(UNIT_BUTTONS unitButton.cpp tradeButton.cpp buildButton.cpp trainButton.cpp researchButton.cpp) set(OPTIONS_BUTTONS optionsButton.cpp tabButton.cpp okButton.cpp defaultsButton.cpp) -set(TRADING_BUTTONS playerTradeButton.cpp tradingScreenButton.cpp offerButton.cpp) +set(TRADING_BUTTONS playerTradeButton.cpp tradingScreenButton.cpp offerButton.cpp resourceAmmountButton.cpp) set(MENU_BUTTONS mainMenuButton.cpp singlePlayerButton.cpp exitButton.cpp backButton.cpp playButton.cpp) set(MAP_EDITOR_BUTTONS mapEditorButton.cpp newMapButton.cpp loadMapButton.cpp exportButton.cpp) set(BUTTONS statsButton.cpp activeStateButton.cpp ${TRADING_BUTTONS} ${OPTIONS_BUTTONS} ${MENU_BUTTONS} ${MAP_EDITOR_BUTTONS} ${UNIT_BUTTONS}) diff --git a/concreteGuiManager.cpp b/concreteGuiManager.cpp index f6746bf..d3ab17d 100644 --- a/concreteGuiManager.cpp +++ b/concreteGuiManager.cpp @@ -30,6 +30,7 @@ #include "playerTradeButton.h" #include "tradingScreenButton.h" #include "offerButton.h" +#include "resourceAmmountButton.h" namespace battleship{ using namespace std; @@ -241,6 +242,9 @@ namespace battleship{ case TRADE_OFFER: button = new OfferButton(pos, size, (int)SOL_LUA_STATE["playerId"], name, (int)guiTable["trigger"], imagePath); break; + case RESOURCE_AMMOUNT: + button = new ResourceAmmountButton(pos, size, name, (int)guiTable["ammount"], (int)guiTable["trigger"], imagePath); + break; } int typeArr[2]{(int)GuiElementType::BUTTON, (int)type}; diff --git a/concreteGuiManager.h b/concreteGuiManager.h index f2ed7b4..bc6c8e4 100644 --- a/concreteGuiManager.h +++ b/concreteGuiManager.h @@ -50,7 +50,8 @@ namespace battleship{ ACTIVE_GAME_STATE, PLAYER_TRADE, TRADING_SCREEN, - TRADE_OFFER + TRADE_OFFER, + RESOURCE_AMMOUNT }; enum ListboxType { CONTROLS, diff --git a/resourceAmmountButton.cpp b/resourceAmmountButton.cpp new file mode 100644 index 0000000..e9721ee --- /dev/null +++ b/resourceAmmountButton.cpp @@ -0,0 +1,25 @@ +#include "resourceAmmountButton.h" +#include "concreteGuiManager.h" +#include "gameManager.h" + +#include + +namespace battleship{ + using namespace std; + using namespace vb01; + using namespace vb01Gui; + + ResourceAmmountButton::ResourceAmmountButton(Vector2 pos, Vector2 size, string name, int amm, int trigger, string imagePath) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, true, imagePath), ammount(amm) { + ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); + int numTextboxes = guiManager->getTextboxes().size(); + textbox = guiManager->getTextboxes()[numTextboxes - 1]; + } + + void ResourceAmmountButton::onClick(){ + wstring text = textbox->getText(); + int amm = (text != L"" ? stoi(text) : 0) + ammount; + + if(minAmmount <= amm && amm <= maxAmmount) + textbox->setEntry(to_wstring(amm)); + } +} diff --git a/resourceAmmountButton.h b/resourceAmmountButton.h new file mode 100644 index 0000000..8296170 --- /dev/null +++ b/resourceAmmountButton.h @@ -0,0 +1,21 @@ +#ifndef RESOURCE_AMMOUNT_BUTTON_H +#define RESOURCE_AMMOUNT_BUTTON_H + +#include + +namespace vb01Gui{ + class Textbox; +} + +namespace battleship{ + class ResourceAmmountButton : public vb01Gui::Button{ + public: + ResourceAmmountButton(vb01::Vector2, vb01::Vector2, std::string, int, int, std::string); + void onClick(); + private: + vb01Gui::Textbox *textbox = nullptr; + int ammount, minAmmount = 0, maxAmmount = 10000; + }; +} + +#endif