mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
resource ammount incrementation and decrementation buttons
This commit is contained in:
@@ -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 = {
|
||||
|
||||
@@ -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
|
||||
|
||||
+1
-1
@@ -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})
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -50,7 +50,8 @@ namespace battleship{
|
||||
ACTIVE_GAME_STATE,
|
||||
PLAYER_TRADE,
|
||||
TRADING_SCREEN,
|
||||
TRADE_OFFER
|
||||
TRADE_OFFER,
|
||||
RESOURCE_AMMOUNT
|
||||
};
|
||||
enum ListboxType {
|
||||
CONTROLS,
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#include "resourceAmmountButton.h"
|
||||
#include "concreteGuiManager.h"
|
||||
#include "gameManager.h"
|
||||
|
||||
#include <textbox.h>
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef RESOURCE_AMMOUNT_BUTTON_H
|
||||
#define RESOURCE_AMMOUNT_BUTTON_H
|
||||
|
||||
#include <button.h>
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user