mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
refactored InGameAppState and its button classes
This commit is contained in:
+23
-22
@@ -15,16 +15,17 @@ namespace battleship{
|
||||
|
||||
const std::string DEFAULT_TEXTURE = GameManager::getSingleton()->getPath() + "Textures/defaultTexture.jpg";
|
||||
const double camPanSpeed = .1;
|
||||
const int maxNumGroups = 10;
|
||||
|
||||
const static int numAppStates = 3;
|
||||
const static int numStaticBinds[numAppStates]{6, 0, 5};
|
||||
const static int numConfBinds[numAppStates]{0, 1, 20};
|
||||
const static int maxStaticBinds = 6;
|
||||
const static int maxConfBinds = 20;
|
||||
const static int maxStaticBinds = 6;
|
||||
const static int maxConfBinds = 20;
|
||||
|
||||
const static Bind staticBinds[numAppStates][maxStaticBinds]{
|
||||
{
|
||||
Bind::LEFT_CLICK,
|
||||
Bind::LEFT_CLICK,
|
||||
Bind::SCROLLING_UP,
|
||||
Bind::SCROLLING_DOWN,
|
||||
Bind::LEFT,
|
||||
@@ -43,12 +44,12 @@ namespace battleship{
|
||||
const static Bind confBinds[numAppStates][maxConfBinds]{
|
||||
{},
|
||||
{
|
||||
Bind::TOGGLE_MAIN_MENU
|
||||
Bind::TOGGLE_MAIN_MENU
|
||||
},
|
||||
{
|
||||
Bind::DRAG_BOX,
|
||||
Bind::DESELECT,
|
||||
Bind::HALT,
|
||||
Bind::HALT,
|
||||
Bind::ZOOM_IN,
|
||||
Bind::ZOOM_OUT,
|
||||
Bind::LEFT_CONTROL,
|
||||
@@ -72,19 +73,19 @@ namespace battleship{
|
||||
const static int staticTriggers[numAppStates][maxStaticBinds]{
|
||||
{
|
||||
0,
|
||||
GLFW_KEY_W,
|
||||
GLFW_KEY_S,
|
||||
GLFW_KEY_W,
|
||||
GLFW_KEY_S,
|
||||
GLFW_KEY_LEFT,
|
||||
GLFW_KEY_RIGHT,
|
||||
GLFW_KEY_BACKSPACE
|
||||
},
|
||||
{},
|
||||
{
|
||||
Mapping::MOUSE_AXIS_UP,
|
||||
Mapping::MOUSE_AXIS_DOWN,
|
||||
Mapping::MOUSE_AXIS_LEFT,
|
||||
Mapping::MOUSE_AXIS_RIGHT,
|
||||
0
|
||||
Mapping::MOUSE_AXIS_UP,
|
||||
Mapping::MOUSE_AXIS_DOWN,
|
||||
Mapping::MOUSE_AXIS_LEFT,
|
||||
Mapping::MOUSE_AXIS_RIGHT,
|
||||
0
|
||||
}
|
||||
};
|
||||
const static int confTriggers[numAppStates][maxConfBinds]{
|
||||
@@ -93,7 +94,7 @@ namespace battleship{
|
||||
GLFW_KEY_ESCAPE
|
||||
},
|
||||
{
|
||||
GLFW_KEY_LEFT,
|
||||
GLFW_KEY_LEFT,
|
||||
GLFW_KEY_RIGHT,
|
||||
GLFW_KEY_H,
|
||||
3,
|
||||
@@ -119,28 +120,28 @@ namespace battleship{
|
||||
const static bool isStaticKey[numAppStates][maxStaticBinds]{
|
||||
{0, 1, 1, 1, 1, 1},
|
||||
{},
|
||||
{0, 0, 0, 0, 1}
|
||||
{0, 0, 0, 0, 1}
|
||||
};
|
||||
const static bool isConfKey[numAppStates][maxConfBinds]{
|
||||
{},
|
||||
{},
|
||||
{1},
|
||||
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
|
||||
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
|
||||
};
|
||||
|
||||
const static bool isStaticAction[numAppStates][maxStaticBinds]{
|
||||
{1, 1, 1, 1, 1, 1},
|
||||
{},
|
||||
{0, 0, 0, 0, 1}
|
||||
{0, 0, 0, 0, 1}
|
||||
};
|
||||
const static bool isConfAction[numAppStates][maxConfBinds]{
|
||||
{},
|
||||
{},
|
||||
{1},
|
||||
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
|
||||
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
|
||||
};
|
||||
|
||||
int calcSumStaticBinds(int, bool);
|
||||
int calcSumConfBinds(int, bool);
|
||||
int calcSumBinds(int, bool);
|
||||
int calcSumStaticBinds(int, bool);
|
||||
int calcSumConfBinds(int, bool);
|
||||
int calcSumBinds(int, bool);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -7,8 +7,7 @@ using namespace std;
|
||||
using namespace vb01;
|
||||
|
||||
namespace battleship{
|
||||
ExitButton::ExitButton(Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, separate) {
|
||||
}
|
||||
ExitButton::ExitButton(Vector2 pos, Vector2 size) : Button(pos, size, "Exit", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) {}
|
||||
|
||||
void ExitButton::onClick() {
|
||||
//Root::getSingleton()->set
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@
|
||||
namespace battleship {
|
||||
class ExitButton : public vb01Gui::Button {
|
||||
public:
|
||||
ExitButton(vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
ExitButton(vb01::Vector2, vb01::Vector2);
|
||||
void onClick();
|
||||
};
|
||||
}
|
||||
|
||||
+115
-184
@@ -1,4 +1,5 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include <button.h>
|
||||
|
||||
#include <util.h>
|
||||
@@ -17,9 +18,9 @@ using namespace vb01Gui;
|
||||
using namespace std;
|
||||
|
||||
namespace battleship{
|
||||
using namespace configData;
|
||||
using namespace configData;
|
||||
|
||||
InGameAppState::ResumeButton::ResumeButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, separate) {
|
||||
InGameAppState::ResumeButton::ResumeButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size) : Button(pos, size, "Resume", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) {
|
||||
this->guiState = guiState;
|
||||
this->inGameState = inGameState;
|
||||
}
|
||||
@@ -32,31 +33,12 @@ namespace battleship{
|
||||
return guiState;
|
||||
}
|
||||
|
||||
InGameAppState::ConsoleButton::ConsoleButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, separate) {
|
||||
InGameAppState::ConsoleButton::ConsoleButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size) : Button(pos, size, "Console", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) {
|
||||
this->guiState = guiState;
|
||||
this->inGameState = inGameState;
|
||||
}
|
||||
|
||||
void InGameAppState::ConsoleButton::onClick() {
|
||||
|
||||
class ConsoleCommandEntryButton : public Button {
|
||||
public:
|
||||
|
||||
ConsoleCommandEntryButton(InGameAppState *inGameState, Textbox *t, Listbox *l, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, separate) {
|
||||
this->inGameState = inGameState;
|
||||
textbox = t;
|
||||
listbox = l;
|
||||
}
|
||||
|
||||
void onClick() {
|
||||
ConsoleCommand::execute(wstringToString(textbox->getText()));
|
||||
}
|
||||
private:
|
||||
InGameAppState *inGameState;
|
||||
Textbox *textbox;
|
||||
Listbox *listbox;
|
||||
};
|
||||
|
||||
vector<string> list;
|
||||
int emptyEntries = 20;
|
||||
|
||||
@@ -64,15 +46,45 @@ namespace battleship{
|
||||
list.push_back("");
|
||||
|
||||
Vector2 pos = Vector2(300, 100);
|
||||
Listbox *consoleListbox = new Listbox(Vector2(pos.x, pos.y), Vector2(420, 20), list, 20, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf");
|
||||
Listbox *consoleListbox = new Listbox(
|
||||
Vector2(pos.x, pos.y),
|
||||
Vector2(420, 20),
|
||||
list,
|
||||
20,
|
||||
GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"
|
||||
);
|
||||
consoleListbox->openUp();
|
||||
guiState->addListbox(consoleListbox);
|
||||
Textbox *consoleTextbox = new Textbox(Vector2(pos.x, pos.y + 20 * (emptyEntries + 1)), Vector2(300, 20), GameManager::getSingleton()->getPath() + "Fonts/batang.ttf");
|
||||
|
||||
Textbox *consoleTextbox = new Textbox(
|
||||
Vector2(pos.x, pos.y + 20 * (emptyEntries + 1)),
|
||||
Vector2(300, 20),
|
||||
GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"
|
||||
);
|
||||
guiState->addTextbox(consoleTextbox);
|
||||
ConsoleCommandEntryButton *entryButton = new ConsoleCommandEntryButton(inGameState, consoleTextbox, consoleListbox, Vector2(pos.x + 320, pos.y + 20 * (emptyEntries + 1)), Vector2(100, 20), "Enter", true);
|
||||
|
||||
entryButton = new ConsoleCommandEntryButton(
|
||||
inGameState,
|
||||
consoleTextbox,
|
||||
consoleListbox,
|
||||
Vector2(pos.x + 320, pos.y + 20 * (emptyEntries + 1)),
|
||||
Vector2(100, 20),
|
||||
"Enter",
|
||||
true
|
||||
);
|
||||
guiState->addButton(entryButton);
|
||||
}
|
||||
|
||||
InGameAppState::ConsoleButton::ConsoleButton::ConsoleCommandEntryButton::ConsoleCommandEntryButton(InGameAppState *inGameState, Textbox *t, Listbox *l, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, separate) {
|
||||
this->inGameState = inGameState;
|
||||
textbox = t;
|
||||
listbox = l;
|
||||
}
|
||||
|
||||
void InGameAppState::ConsoleButton::ConsoleButton::ConsoleCommandEntryButton::onClick() {
|
||||
ConsoleCommand::execute(wstringToString(textbox->getText()));
|
||||
}
|
||||
|
||||
InGameAppState::InGameOptionsButton::ReturnButton::ReturnButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, separate) {
|
||||
this->guiState = guiState;
|
||||
this->inGameState = inGameState;
|
||||
@@ -88,26 +100,30 @@ namespace battleship{
|
||||
guiState->removeButton("Video");
|
||||
guiState->removeButton("Audio");
|
||||
guiState->removeButton("Multiplayer");
|
||||
Vector2 pos = Vector2(100, 100);
|
||||
ResumeButton *resumeButton = new ResumeButton(guiState, inGameState, Vector2(pos.x, pos.y), Vector2(150, 50), "Resume", true);
|
||||
ConsoleButton *consoleButton = new ConsoleButton(guiState, inGameState, Vector2(pos.x, pos.y + 60), Vector2(150, 50), "Console", true);
|
||||
InGameOptionsButton *optionsButton = new InGameOptionsButton(guiState, inGameState, Vector2(pos.x, pos.y + 120), Vector2(150, 50), "Options", true);
|
||||
MainMenuButton *mainMenuButton = new MainMenuButton(guiState, inGameState, Vector2(pos.x, pos.y + 180), Vector2(150, 50), "Main menu", true);
|
||||
ExitButton *exitButton = new ExitButton(Vector2(pos.x, pos.y + 240), Vector2(150, 50), "Exit", true);
|
||||
|
||||
Vector2 pos = Vector2(100, 100), size = Vector2(150, 50);
|
||||
ResumeButton *resumeButton = new ResumeButton(guiState, inGameState, Vector2(pos.x, pos.y), size);
|
||||
ConsoleButton *consoleButton = new ConsoleButton(guiState, inGameState, Vector2(pos.x, pos.y + 60), size);
|
||||
InGameOptionsButton *optionsButton = new InGameOptionsButton(guiState, inGameState, Vector2(pos.x, pos.y + 120), size);
|
||||
MainMenuButton *mainMenuButton = new MainMenuButton(guiState, inGameState, Vector2(pos.x, pos.y + 180), size);
|
||||
ExitButton *exitButton = new ExitButton(Vector2(pos.x, pos.y + 240), size);
|
||||
|
||||
inGameState->setResumeButton(resumeButton);
|
||||
inGameState->setConsoleButton(consoleButton);
|
||||
inGameState->setOptionsButton(optionsButton);
|
||||
inGameState->setMainMenuButton(mainMenuButton);
|
||||
inGameState->setExitButton(exitButton);
|
||||
|
||||
guiState->addButton(resumeButton);
|
||||
guiState->addButton(consoleButton);
|
||||
guiState->addButton(optionsButton);
|
||||
guiState->addButton(mainMenuButton);
|
||||
guiState->addButton(exitButton);
|
||||
|
||||
guiState->removeButton("Back");
|
||||
}
|
||||
|
||||
InGameAppState::InGameOptionsButton::InGameOptionsButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : OptionsButton(pos, size, name, separate) {
|
||||
InGameAppState::InGameOptionsButton::InGameOptionsButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size) : OptionsButton(pos, size, "Options", true) {
|
||||
this->guiState = guiState;
|
||||
this->inGameState = inGameState;
|
||||
}
|
||||
@@ -115,14 +131,14 @@ namespace battleship{
|
||||
void InGameAppState::InGameOptionsButton::onClick() {
|
||||
returnButton = new ReturnButton(guiState, inGameState, Vector2(50, GameManager::getSingleton()->getHeight() - 150), Vector2(150, 50), "Back", true);
|
||||
guiState->addButton(returnButton);
|
||||
guiState->removeButton("Resume");
|
||||
guiState->removeButton("Console");
|
||||
guiState->removeButton("Main menu");
|
||||
guiState->removeButton("Exit");
|
||||
guiState->removeButton(inGameState->getResumeButton());
|
||||
guiState->removeButton(inGameState->getConsoleButton());
|
||||
guiState->removeButton(inGameState->getMainMenuButton());
|
||||
guiState->removeButton(inGameState->getExitButton());
|
||||
OptionsButton::onClick();
|
||||
}
|
||||
|
||||
InGameAppState::MainMenuButton::MainMenuButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, separate) {
|
||||
InGameAppState::MainMenuButton::MainMenuButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size) : Button(pos, size, "Main menu", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) {
|
||||
this->guiState = guiState;
|
||||
this->inGameState = inGameState;
|
||||
}
|
||||
@@ -131,50 +147,6 @@ namespace battleship{
|
||||
|
||||
}
|
||||
|
||||
InGameAppState::UnitCreationButton::UnitCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, separate) {}
|
||||
|
||||
void InGameAppState::UnitCreationButton::onClick() {
|
||||
}
|
||||
|
||||
void InGameAppState::UnitCreationButton::update() {
|
||||
Button::update();
|
||||
}
|
||||
|
||||
InGameAppState::BattleshipCreationButton::BattleshipCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate)
|
||||
: InGameAppState::UnitCreationButton(icon, pos, size, name, separate) {
|
||||
}
|
||||
|
||||
void InGameAppState::BattleshipCreationButton::onClick() {
|
||||
}
|
||||
|
||||
InGameAppState::DestroyerCreationButton::DestroyerCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate)
|
||||
: InGameAppState::UnitCreationButton(icon, pos, size, name, separate) {
|
||||
}
|
||||
|
||||
void InGameAppState::DestroyerCreationButton::onClick() {
|
||||
}
|
||||
|
||||
InGameAppState::CruiserCreationButton::CruiserCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate)
|
||||
: InGameAppState::UnitCreationButton(icon, pos, size, name, separate) {
|
||||
}
|
||||
|
||||
void InGameAppState::CruiserCreationButton::onClick() {
|
||||
}
|
||||
|
||||
InGameAppState::CarrierCreationButton::CarrierCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate)
|
||||
: InGameAppState::UnitCreationButton(icon, pos, size, name, separate) {
|
||||
}
|
||||
|
||||
void InGameAppState::CarrierCreationButton::onClick() {
|
||||
}
|
||||
|
||||
InGameAppState::SubmarineCreationButton::SubmarineCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate)
|
||||
: InGameAppState::UnitCreationButton(icon, pos, size, name, separate) {
|
||||
}
|
||||
|
||||
void InGameAppState::SubmarineCreationButton::onClick() {
|
||||
}
|
||||
|
||||
InGameAppState::InGameAppState(vector<string> difficultyLevels, vector<string> factions, string mapName) : AbstractAppState(
|
||||
AppStateType::IN_GAME_STATE,
|
||||
configData::calcSumBinds(AppStateType::IN_GAME_STATE, true),
|
||||
@@ -195,8 +167,7 @@ namespace battleship{
|
||||
Map::getSingleton()->load(mapName);
|
||||
|
||||
for (int i = 0; i < factions.size(); i++) {
|
||||
int faction;
|
||||
int difficulty;
|
||||
int faction, difficulty;
|
||||
|
||||
if (i == 0)
|
||||
difficulty = -1;
|
||||
@@ -216,10 +187,12 @@ namespace battleship{
|
||||
}
|
||||
|
||||
mainPlayer = players[playerId];
|
||||
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
|
||||
|
||||
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
|
||||
guiState = ((GuiAppState*)stateManager->getAppStateByType((int)AppStateType::GUI_STATE));
|
||||
activeState = new ActiveGameState(guiState, players, playerId);
|
||||
stateManager->attachAppState(activeState);
|
||||
|
||||
AssetManager *assetManager = AssetManager::getSingleton();
|
||||
assetManager->load(DEFAULT_TEXTURE);
|
||||
|
||||
@@ -232,75 +205,44 @@ namespace battleship{
|
||||
assetManager->load(basePaths[i] + meshPaths[i]);
|
||||
}
|
||||
|
||||
void InGameAppState::onDettached() {
|
||||
void InGameAppState::onDettached() {}
|
||||
|
||||
}
|
||||
|
||||
void InGameAppState::update() {
|
||||
for (Player *p : players)
|
||||
if (p) {
|
||||
p->update();
|
||||
|
||||
for (int i = 0; i < p->getNumberOfUnits(); i++){
|
||||
Unit *u = p->getUnit(i);
|
||||
|
||||
if(u->isWorking())
|
||||
u->update();
|
||||
else{
|
||||
int selectedId = -1;
|
||||
std::vector<Unit*> &units = p->getUnits(), &selectedUnits = activeState->getSelectedUnits();
|
||||
units.erase(units.begin() + i);
|
||||
|
||||
if(u->getUnitClass() == UnitClass::MISSILE_JET || u->getUnitClass() == UnitClass::DEMO_JET){
|
||||
AircraftCarrier *carrier = nullptr;
|
||||
|
||||
for(int i2 = 0; i2 < p->getUnits().size() && !carrier; i2++){
|
||||
AircraftCarrier *a = ((Jet*)u)->getAircraftCarrier();
|
||||
|
||||
if(a)
|
||||
carrier = a;
|
||||
}
|
||||
|
||||
if(carrier){
|
||||
Jet** jets = carrier->getJets();
|
||||
jets[((Jet*)u)->getJetId()] = nullptr;
|
||||
}
|
||||
}
|
||||
else if(u->getUnitClass() == UnitClass::AIRCRAFT_CARRIER){
|
||||
AircraftCarrier *carrier = (AircraftCarrier*)u;
|
||||
|
||||
for(int i2 = 0; i2 < carrier->getMaxNumJets(); i2++){
|
||||
Jet *j = carrier->getJet(i2);
|
||||
|
||||
if(j && j->isOnBoard())
|
||||
j->blowUp();
|
||||
}
|
||||
}
|
||||
|
||||
for(int i2 = 0; i2 < 10; i2++){
|
||||
int id = -1;
|
||||
std::vector<Unit*> &group = activeState->getUnitGroup(i2);
|
||||
|
||||
for(int i3 = 0; i3 < group.size() && id == -1; i3++)
|
||||
if(group[i3] == u)
|
||||
id = i3;
|
||||
|
||||
if(id != -1)
|
||||
group.erase(group.begin() + id);
|
||||
}
|
||||
|
||||
for(int i2 = 0; i2 < selectedUnits.size() && selectedId == -1; i2++)
|
||||
if(selectedUnits[i2] == u)
|
||||
selectedId = i2;
|
||||
|
||||
if(selectedId != -1)
|
||||
selectedUnits.erase(selectedUnits.begin() + selectedId);
|
||||
|
||||
delete u;
|
||||
}
|
||||
}
|
||||
}
|
||||
void InGameAppState::updateUnits(Player *p){
|
||||
for (int i = 0; i < p->getNumberOfUnits(); i++){
|
||||
Unit *u = p->getUnit(i);
|
||||
|
||||
if(u->isWorking())
|
||||
u->update();
|
||||
else{
|
||||
int selectedId = -1;
|
||||
std::vector<Unit*> &units = p->getUnits(), &selectedUnits = activeState->getSelectedUnits();
|
||||
units.erase(units.begin() + i);
|
||||
|
||||
for(int j = 0; j < maxNumGroups; j++){
|
||||
int id = -1;
|
||||
std::vector<Unit*> &group = activeState->getUnitGroup(j);
|
||||
|
||||
for(int k = 0; k < group.size() && id == -1; k++)
|
||||
if(group[k] == u)
|
||||
id = k;
|
||||
|
||||
if(id != -1)
|
||||
group.erase(group.begin() + id);
|
||||
}
|
||||
|
||||
for(int j = 0; j < selectedUnits.size() && selectedId == -1; j++)
|
||||
if(selectedUnits[j] == u)
|
||||
selectedId = j;
|
||||
|
||||
if(selectedId != -1)
|
||||
selectedUnits.erase(selectedUnits.begin() + selectedId);
|
||||
|
||||
delete u;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InGameAppState::updateProjectiles(){
|
||||
for(int i = 0; i < projectiles.size(); i++){
|
||||
Projectile *p = projectiles[i];
|
||||
|
||||
@@ -311,42 +253,31 @@ namespace battleship{
|
||||
projectiles.erase(projectiles.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InGameAppState::attachGui() {
|
||||
int idOffset = 0;
|
||||
void InGameAppState::update() {
|
||||
for (Player *p : players)
|
||||
if (p) {
|
||||
p->update();
|
||||
updateUnits(p);
|
||||
}
|
||||
|
||||
if (mainPlayer->getFaction() == 1)
|
||||
idOffset += 7;
|
||||
|
||||
guiState->addButton(bcb);
|
||||
guiState->addButton(dcb);
|
||||
guiState->addButton(crcb);
|
||||
guiState->addButton(ccb);
|
||||
guiState->addButton(scb);
|
||||
}
|
||||
|
||||
void InGameAppState::detachGui() {
|
||||
guiState->removeButton(bcb);
|
||||
guiState->removeButton(dcb);
|
||||
guiState->removeButton(crcb);
|
||||
guiState->removeButton(ccb);
|
||||
guiState->removeButton(scb);
|
||||
updateProjectiles();
|
||||
}
|
||||
|
||||
void InGameAppState::toggleMainMenu() {
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
|
||||
if (!isMainMenuActive) {
|
||||
isMainMenuActive = true;
|
||||
gm->getStateManager()->dettachAppState(activeState);
|
||||
|
||||
Vector2 pos = Vector2(100, 100);
|
||||
resumeButton = new ResumeButton(guiState, this, Vector2(pos.x, pos.y), Vector2(150, 50), "Resume", true);
|
||||
consoleButton = new ConsoleButton(guiState, this, Vector2(pos.x, pos.y + 60), Vector2(150, 50), "Console", true);
|
||||
optionsButton = new InGameOptionsButton(guiState, this, Vector2(pos.x, pos.y + 120), Vector2(150, 50), "Options", true);
|
||||
mainMenuButton = new MainMenuButton(guiState, this, Vector2(pos.x, pos.y + 180), Vector2(150, 50), "Main menu", true);
|
||||
exitButton = new ExitButton(Vector2(pos.x, pos.y + 240), Vector2(150, 50), "Exit", true);
|
||||
resumeButton = new ResumeButton(guiState, this, Vector2(pos.x, pos.y), Vector2(150, 50));
|
||||
consoleButton = new ConsoleButton(guiState, this, Vector2(pos.x, pos.y + 60), Vector2(150, 50));
|
||||
optionsButton = new InGameOptionsButton(guiState, this, Vector2(pos.x, pos.y + 120), Vector2(150, 50));
|
||||
mainMenuButton = new MainMenuButton(guiState, this, Vector2(pos.x, pos.y + 180), Vector2(150, 50));
|
||||
exitButton = new ExitButton(Vector2(pos.x, pos.y + 240), Vector2(150, 50));
|
||||
guiState->addButton(resumeButton);
|
||||
guiState->addButton(consoleButton);
|
||||
guiState->addButton(optionsButton);
|
||||
@@ -361,19 +292,19 @@ namespace battleship{
|
||||
guiState->removeAllListboxes();
|
||||
guiState->removeAllSliders();
|
||||
guiState->removeAllTextboxes();
|
||||
guiState->removeButton("Enter");
|
||||
guiState->removeButton("Console");
|
||||
guiState->removeButton("Main menu");
|
||||
guiState->removeButton("Options");
|
||||
guiState->removeButton("Exit");
|
||||
guiState->removeButton("Resume");
|
||||
guiState->removeButton(consoleButton->getEntryButton());
|
||||
guiState->removeButton(consoleButton);
|
||||
guiState->removeButton(mainMenuButton);
|
||||
guiState->removeButton(optionsButton);
|
||||
guiState->removeButton(exitButton);
|
||||
guiState->removeButton(resumeButton);
|
||||
}
|
||||
}
|
||||
|
||||
void InGameAppState::onAction(int bind, bool isPressed) {
|
||||
switch((Bind)bind){
|
||||
case Bind::TOGGLE_MAIN_MENU:
|
||||
if(isPressed)toggleMainMenu();
|
||||
case Bind::TOGGLE_MAIN_MENU:
|
||||
if(isPressed)toggleMainMenu();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+31
-55
@@ -35,7 +35,7 @@ namespace battleship{
|
||||
private:
|
||||
class ResumeButton : public vb01Gui::Button {
|
||||
public:
|
||||
ResumeButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
ResumeButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2);
|
||||
void onClick();
|
||||
GuiAppState *getGuiState();
|
||||
private:
|
||||
@@ -45,16 +45,28 @@ namespace battleship{
|
||||
|
||||
class ConsoleButton : public vb01Gui::Button {
|
||||
public:
|
||||
ConsoleButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
class ConsoleCommandEntryButton : public Button {
|
||||
public:
|
||||
ConsoleCommandEntryButton(InGameAppState*, vb01Gui::Textbox*, vb01Gui::Listbox*, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
private:
|
||||
InGameAppState *inGameState;
|
||||
vb01Gui::Textbox *textbox;
|
||||
vb01Gui::Listbox *listbox;
|
||||
};
|
||||
|
||||
ConsoleButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2);
|
||||
void onClick();
|
||||
inline ConsoleCommandEntryButton* getEntryButton(){return entryButton;}
|
||||
private:
|
||||
GuiAppState *guiState;
|
||||
InGameAppState *inGameState;
|
||||
ConsoleCommandEntryButton *entryButton = nullptr;
|
||||
};
|
||||
|
||||
class MainMenuButton : public vb01Gui::Button {
|
||||
public:
|
||||
MainMenuButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
MainMenuButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2);
|
||||
void onClick();
|
||||
private:
|
||||
GuiAppState *guiState;
|
||||
@@ -63,7 +75,7 @@ namespace battleship{
|
||||
|
||||
class InGameOptionsButton : public OptionsButton {
|
||||
public:
|
||||
InGameOptionsButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
InGameOptionsButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2);
|
||||
void onClick();
|
||||
private:
|
||||
class ReturnButton : public vb01Gui::Button {
|
||||
@@ -74,63 +86,18 @@ namespace battleship{
|
||||
GuiAppState *guiState;
|
||||
InGameAppState *inGameState;
|
||||
};
|
||||
|
||||
GuiAppState *guiState;
|
||||
InGameAppState *inGameState;
|
||||
ReturnButton *returnButton;
|
||||
};
|
||||
|
||||
class UnitCreationButton : public vb01Gui::Button {
|
||||
public:
|
||||
UnitCreationButton(std::string, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
void update();
|
||||
private:
|
||||
};
|
||||
|
||||
class BattleshipCreationButton : public UnitCreationButton {
|
||||
public:
|
||||
BattleshipCreationButton(std::string, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
};
|
||||
|
||||
class DestroyerCreationButton : public UnitCreationButton {
|
||||
public:
|
||||
DestroyerCreationButton(std::string, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
};
|
||||
|
||||
class CruiserCreationButton : public UnitCreationButton {
|
||||
public:
|
||||
CruiserCreationButton(std::string, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
};
|
||||
|
||||
class CarrierCreationButton : public UnitCreationButton {
|
||||
public:
|
||||
CarrierCreationButton(std::string, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
};
|
||||
|
||||
class SubmarineCreationButton : public UnitCreationButton {
|
||||
public:
|
||||
SubmarineCreationButton(std::string, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
};
|
||||
|
||||
ResumeButton *resumeButton;
|
||||
ConsoleButton *consoleButton;
|
||||
InGameOptionsButton *optionsButton;
|
||||
MainMenuButton *mainMenuButton;
|
||||
ExitButton *exitButton;
|
||||
BattleshipCreationButton *bcb;
|
||||
DestroyerCreationButton *dcb;
|
||||
CruiserCreationButton *crcb;
|
||||
CarrierCreationButton *ccb;
|
||||
SubmarineCreationButton *scb;
|
||||
bool isMainMenuActive = false;
|
||||
void toggleMainMenu();
|
||||
void attachGui();
|
||||
void detachGui();
|
||||
std::vector<Player*> players;
|
||||
std::vector<std::string> difficultyLevels, factions;
|
||||
std::vector<Projectile*> projectiles;
|
||||
@@ -140,12 +107,21 @@ namespace battleship{
|
||||
int playerId;
|
||||
ActiveGameState* activeState;
|
||||
GuiAppState* guiState;
|
||||
|
||||
void toggleMainMenu();
|
||||
void updateUnits(Player*);
|
||||
void updateProjectiles();
|
||||
public:
|
||||
inline void setResumeButton(ResumeButton *r){this->resumeButton=r;}
|
||||
inline void setConsoleButton(ConsoleButton *c){this->consoleButton=c;}
|
||||
inline void setOptionsButton(InGameOptionsButton *o){this->optionsButton=o;}
|
||||
inline void setMainMenuButton(MainMenuButton *m){this->mainMenuButton=m;}
|
||||
inline void setExitButton(ExitButton *e){this->exitButton=e;}
|
||||
inline void setResumeButton(ResumeButton *r){this->resumeButton = r;}
|
||||
inline void setConsoleButton(ConsoleButton *c){this->consoleButton = c;}
|
||||
inline void setOptionsButton(InGameOptionsButton *o){this->optionsButton = o;}
|
||||
inline void setMainMenuButton(MainMenuButton *m){this->mainMenuButton = m;}
|
||||
inline void setExitButton(ExitButton *e){this->exitButton = e;}
|
||||
inline ResumeButton* getResumeButton(){return resumeButton;}
|
||||
inline ConsoleButton* getConsoleButton(){return consoleButton;}
|
||||
inline InGameOptionsButton* getOptionsButton(){return optionsButton;}
|
||||
inline MainMenuButton* getMainMenuButton(){return mainMenuButton;}
|
||||
inline ExitButton* getExitButton(){return exitButton;}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ namespace battleship{
|
||||
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);
|
||||
state->addButton(optionsButton);
|
||||
ExitButton *exitButton = new ExitButton(Vector2(gm->getWidth() / 16, gm->getHeight() / 12 * 3), Vector2(150, 40), "Exit", true);
|
||||
ExitButton *exitButton = new ExitButton(Vector2(gm->getWidth() / 16, gm->getHeight() / 12 * 3), Vector2(150, 40));
|
||||
state->addButton(spButton);
|
||||
state->addButton(exitButton);
|
||||
state->removeButton("Back");
|
||||
@@ -221,7 +221,7 @@ namespace battleship{
|
||||
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), "Exit", true);
|
||||
ExitButton *exitButton = new ExitButton(Vector2(gm->getWidth() / 16, gm->getHeight() / 12 * 3), Vector2(150, 40));
|
||||
state->addButton(spButton);
|
||||
state->addButton(optionsButton);
|
||||
state->addButton(exitButton);
|
||||
|
||||
Reference in New Issue
Block a user