map editor buttons on the title screen

This commit is contained in:
devZoGok
2022-12-28 15:45:24 +02:00
parent 87503c7b48
commit d6ae678ce6
3 changed files with 75 additions and 10 deletions
+14 -6
View File
@@ -1,4 +1,6 @@
#include <sstream>
#include <algorithm>
#include <vector.h>
#include <util.h>
@@ -327,12 +329,18 @@ namespace battleship{
}
}
void GuiAppState::removeAllButtons() {
while (buttons.size() > 0) {
delete buttons[buttons.size() - 1];
buttons.pop_back();
}
}
void GuiAppState::removeAllButtons(vector<Button*> exceptions){
int targetId = 0;
while(targetId != buttons.size()){
if(find(exceptions.begin(), exceptions.end(), buttons[targetId]) == exceptions.end()){
delete buttons[targetId];
buttons.erase(buttons.begin() + targetId);
}
else
targetId++;
}
}
void GuiAppState::removeAllListboxes() {
while (listboxes.size() > 0) {
+1 -1
View File
@@ -36,7 +36,7 @@ namespace battleship{
void addTooltip(Tooltip*);
void removeTooltip(Tooltip*);
void removeSlider(vb01Gui::Slider*);
void removeAllButtons();
void removeAllButtons(std::vector<vb01Gui::Button*> = std::vector<vb01Gui::Button*>{});
void removeAllListboxes();
void removeAllCheckboxes();
void removeAllSliders();
+60 -3
View File
@@ -216,14 +216,71 @@ namespace battleship{
};
};
class NewMapButton : public Button{
public:
NewMapButton(Vector2 pos, Vector2 size) : Button(pos, size, "New map", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true){}
void onClick(){
class OkButton : public Button{
public:
OkButton(Vector2 pos, Vector2 size, Textbox *sx, Textbox *sy) : Button(pos, size, "Ok", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true){
this->sizeX = sx;
this->sizeY = sy;
}
void onClick(){
}
private:
Textbox *sizeX, *sizeY;
};
GameManager *gm = GameManager::getSingleton();
StateManager *stateManager = gm->getStateManager();
GuiAppState *state = (GuiAppState*)stateManager->getAppStateByType((int)AppStateType::GUI_STATE);
state->removeAllButtons(vector<Button*>{this});
Vector2 size = Vector2(140, 20);
string fontPath = gm->getPath() + "Fonts/batang.ttf";
Textbox *name = new Textbox(Vector2(100, 150), size, fontPath);
Textbox *sizeX = new Textbox(Vector2(100, 150 + (size.y + 10)), size, fontPath);
Textbox *sizeY = new Textbox(Vector2(100, 150 + 2 * (size.y + 10)), size, fontPath);
state->addTextbox(name);
state->addTextbox(sizeX);
state->addTextbox(sizeY);
state->addButton(new OkButton(Vector2(200, gm->getHeight() - 150), Vector2(140, 50), sizeX, sizeY));
state->removeButton(this);
}
private:
};
class LoadMapButton : public Button{
public:
LoadMapButton(Vector2 pos, Vector2 size) : Button(pos, size, "Load map", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true){}
void onClick(){
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
GuiAppState *state = (GuiAppState*)stateManager->getAppStateByType((int)AppStateType::GUI_STATE);
state->removeAllButtons();
}
private:
};
GameManager *gm = GameManager::getSingleton();
string font = gm->getPath() + "Fonts/batang.ttf";
int width = gm->getWidth(), height = gm->getHeight();
Vector2 size = Vector2(150, 40);
AssetManager::getSingleton()->load(font);
SpButton *spButton = new SpButton(state, Vector2(gm->getWidth() / 16, gm->getHeight() / 12), Vector2(150, 40), "Singleplayer", true);
MainMenuOptionsButton *optionsButton = new MainMenuOptionsButton(state, Vector2(gm->getWidth() / 16, gm->getHeight() / 12 * 2), Vector2(150, 40), "Options", true);
ExitButton *exitButton = new ExitButton(Vector2(gm->getWidth() / 16, gm->getHeight() / 12 * 3), Vector2(150, 40));
SpButton *spButton = new SpButton(state, Vector2(width / 16, height / 12), size, "Singleplayer", true);
MainMenuOptionsButton *optionsButton = new MainMenuOptionsButton(state, Vector2(width / 16, height / 12 * 2), size, "Options", true);
NewMapButton *newMapButton = new NewMapButton(Vector2(width / 16, height / 12 * 3), size);
LoadMapButton *loadMapButton = new LoadMapButton(Vector2(width / 16, height / 12 * 4), size);
ExitButton *exitButton = new ExitButton(Vector2(width / 16, height / 12 * 5), size);
state->addButton(spButton);
state->addButton(optionsButton);
state->addButton(newMapButton);
state->addButton(loadMapButton);
state->addButton(exitButton);
}