diff --git a/Assets/Scripts/Gui/mainMenu.lua b/Assets/Scripts/Gui/mainMenu.lua index f3243f8..ba8edbe 100644 --- a/Assets/Scripts/Gui/mainMenu.lua +++ b/Assets/Scripts/Gui/mainMenu.lua @@ -30,7 +30,16 @@ gui = { size = Size, guiType = GuiType.BUTTON, name = 'Single player', - buttonType = ButtonType.SINGLE_PLAYER + buttonType = ButtonType.SINGLE_PLAYER, + baseColor = {x = .6, y = .6, z = .6, w = 1}, + hoveredOnColor = {x = .8, y = .8, z = .8, w = 1}, + tooltip = { + offset = {x = 100, y = 100}, + size = {x = 300, y = 200}, + lines = { + {entry = {text = 'Play with computer opponents'}}, + } + } }, { pos = {x = 20, y = 160, z = 0}, diff --git a/CMakeLists.txt b/CMakeLists.txt index 554c9c1..b12443e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ set(OPTIONS_BUTTONS optionsButton.cpp tabButton.cpp okButton.cpp defaultsButton. set(TRADING_BUTTONS activeStateBackButton.cpp 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 minimapButton.cpp ${TRADING_BUTTONS} ${OPTIONS_BUTTONS} ${MENU_BUTTONS} ${MAP_EDITOR_BUTTONS} ${UNIT_BUTTONS}) +set(BUTTONS pfButtonBase.cpp statsButton.cpp activeStateButton.cpp minimapButton.cpp ${TRADING_BUTTONS} ${OPTIONS_BUTTONS} ${MENU_BUTTONS} ${MAP_EDITOR_BUTTONS} ${UNIT_BUTTONS}) set(LISTBOXES skyboxTextureListbox.cpp landTextureListbox.cpp gameObjectListbox.cpp mapListbox.cpp) set(GUI tooltip.cpp concreteGuiManager.cpp ${BUTTONS} ${LISTBOXES}) diff --git a/activeStateButton.cpp b/activeStateButton.cpp index 703b6f7..79c5a3a 100644 --- a/activeStateButton.cpp +++ b/activeStateButton.cpp @@ -19,7 +19,7 @@ namespace battleship{ using namespace gameBase; ActiveStateButton::ActiveStateButton(Vector3 pos, Vector2 size, string gs, string name, string fontPath, int trigger, string imagePath) : - Button(pos, size, name, fontPath, trigger, true, imagePath), guiScreen(gs){} + PfButtonBase(pos, size, name, fontPath, trigger, true, imagePath), guiScreen(gs){} void ActiveStateButton::onClick(){ StateManager *stateManager = GameManager::getSingleton()->getStateManager(); diff --git a/activeStateButton.h b/activeStateButton.h index 48a7c14..7433673 100644 --- a/activeStateButton.h +++ b/activeStateButton.h @@ -1,10 +1,10 @@ #ifndef ACTIVE_STATE_BUTTON_H #define ACTIVE_STATE_BUTTON_H -#include +#include "pfButtonBase.h" namespace battleship{ - class ActiveStateButton : public vb01Gui::Button{ + class ActiveStateButton : public PfButtonBase{ public: ActiveStateButton(vb01::Vector3, vb01::Vector2, std::string, std::string, std::string, int = -1, std::string = ""); void onClick(); diff --git a/backButton.cpp b/backButton.cpp index e221666..09cc4f6 100644 --- a/backButton.cpp +++ b/backButton.cpp @@ -8,7 +8,7 @@ namespace battleship{ using namespace vb01Gui; BackButton::BackButton(Vector3 pos, Vector2 size, string name, string scr) : - Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true), + PfButtonBase(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true), screen(scr){} void BackButton::onClick() { diff --git a/backButton.h b/backButton.h index 504eef7..86b3760 100644 --- a/backButton.h +++ b/backButton.h @@ -1,10 +1,10 @@ #ifndef BACK_BUTTON_H #define BACK_BUTTON_H -#include +#include "pfButtonBase.h" namespace battleship{ - class BackButton : public vb01Gui::Button{ + class BackButton : public PfButtonBase{ public: BackButton(vb01::Vector3, vb01::Vector2, std::string, std::string); void onClick(); diff --git a/concreteGuiManager.cpp b/concreteGuiManager.cpp index f6affcf..4a86acd 100644 --- a/concreteGuiManager.cpp +++ b/concreteGuiManager.cpp @@ -5,6 +5,7 @@ #include "concreteGuiManager.h" #include "unit.h" #include "gameManager.h" +#include "pfButtonBase.h" #include "singlePlayerButton.h" #include "mapEditorButton.h" #include "optionsButton.h" @@ -134,13 +135,12 @@ namespace battleship{ tooltip = parseTooltip(tbl, pos); } - Button *button = nullptr; + PfButtonBase *button = nullptr; string guiScreen = ""; switch(type){ case SINGLE_PLAYER: button = new SinglePlayerButton(pos, size, name); - ((SinglePlayerButton*)button)->setTooltip(tooltip); break; case EDITOR: button = new MapEditorButton(pos, size); @@ -290,6 +290,23 @@ namespace battleship{ } } + sol::optional baseColorTblOpt = guiTable["baseColor"], hoveredColorTblOpt = guiTable["hoveredOnColor"]; + + if(baseColorTblOpt != sol::nullopt){ + sol::table baseColorTbl = guiTable["baseColor"]; + Vector4 color = Vector4(baseColorTbl["x"], baseColorTbl["y"], baseColorTbl["z"], baseColorTbl["w"]); + button->setBaseColor(color); + button->setColor(color); + } + + if(hoveredColorTblOpt != sol::nullopt){ + sol::table hoveredColorTbl = guiTable["hoveredOnColor"]; + button->setHoveredOnColor(Vector4(hoveredColorTbl["x"], hoveredColorTbl["y"], hoveredColorTbl["z"], hoveredColorTbl["w"])); + button->setEnabledHoverdOn(true); + } + + button->setTooltip(tooltip); + int typeArr[2]{(int)GuiElementType::BUTTON, (int)type}; guiElements.push_back(make_pair(typeArr, (void*)button)); diff --git a/defaultsButton.cpp b/defaultsButton.cpp index 8658e2c..21f91b9 100644 --- a/defaultsButton.cpp +++ b/defaultsButton.cpp @@ -6,7 +6,7 @@ namespace battleship{ using namespace vb01; using namespace vb01Gui; - DefaultsButton::DefaultsButton(Vector3 pos, Vector2 size, string name) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) {} + DefaultsButton::DefaultsButton(Vector3 pos, Vector2 size, string name) : PfButtonBase(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) {} void DefaultsButton::onClick() {} } diff --git a/defaultsButton.h b/defaultsButton.h index f7ac6dd..4c722ed 100644 --- a/defaultsButton.h +++ b/defaultsButton.h @@ -1,10 +1,10 @@ #ifndef DEFAULTS_BUTTON_H #define DEFAULTS_BUTTON_H -#include +#include "pfButtonBase.h" namespace battleship{ - class DefaultsButton : public vb01Gui::Button{ + class DefaultsButton : public PfButtonBase{ public: DefaultsButton(vb01::Vector3, vb01::Vector2, std::string); void onClick(); diff --git a/exitButton.cpp b/exitButton.cpp index b1b895c..a1684d1 100755 --- a/exitButton.cpp +++ b/exitButton.cpp @@ -5,7 +5,7 @@ using namespace std; using namespace vb01; namespace battleship{ - ExitButton::ExitButton(Vector3 pos, Vector2 size) : Button(pos, size, "Exit", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) {} + ExitButton::ExitButton(Vector3 pos, Vector2 size) : PfButtonBase(pos, size, "Exit", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) {} void ExitButton::onClick() { GameManager::getSingleton()->setRunning(false); diff --git a/exitButton.h b/exitButton.h index c845342..54d17f2 100755 --- a/exitButton.h +++ b/exitButton.h @@ -1,11 +1,12 @@ #ifndef EXIT_BUTTON_H #define EXIT_BUTTON_H -#include +#include "pfButtonBase.h" + #include namespace battleship { - class ExitButton : public vb01Gui::Button { + class ExitButton : public PfButtonBase { public: ExitButton(vb01::Vector3, vb01::Vector2); void onClick(); diff --git a/exportButton.cpp b/exportButton.cpp index f38eea6..debb69a 100644 --- a/exportButton.cpp +++ b/exportButton.cpp @@ -10,7 +10,7 @@ namespace battleship{ using namespace vb01Gui; using namespace gameBase; - ExportButton::ExportButton(Vector3 pos, Vector2 size) : Button(pos, size, "Export", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){} + ExportButton::ExportButton(Vector3 pos, Vector2 size) : PfButtonBase(pos, size, "Export", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true){} void ExportButton::onClick(){ StateManager *sm = GameManager::getSingleton()->getStateManager(); diff --git a/exportButton.h b/exportButton.h index 6066051..20db0e1 100644 --- a/exportButton.h +++ b/exportButton.h @@ -1,10 +1,10 @@ #ifndef EXPORT_BUTTON_H #define EXPORT_BUTTON_H -#include +#include "pfButtonBase.h" namespace battleship{ - class ExportButton : public vb01Gui::Button{ + class ExportButton : public PfButtonBase{ public: ExportButton(vb01::Vector3 pos, vb01::Vector2 size); void onClick(); diff --git a/inGameAppState.cpp b/inGameAppState.cpp index 3212658..76a610f 100755 --- a/inGameAppState.cpp +++ b/inGameAppState.cpp @@ -1,6 +1,5 @@ #include -#include #include #include @@ -11,6 +10,7 @@ #include "defConfigs.h" #include "inGameAppState.h" +#include "pfButtonBase.h" #include "game.h" #include "console.h" #include "gameObjectFrameController.h" @@ -27,22 +27,23 @@ namespace battleship{ using namespace configData; using namespace gameBase; - InGameAppState::ResumeButton::ResumeButton(Vector3 pos, Vector2 size) : Button(pos, size, "Resume", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) {} + InGameAppState::ResumeButton::ResumeButton(Vector3 pos, Vector2 size) : PfButtonBase(pos, size, "Resume", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) {} void InGameAppState::ResumeButton::onClick() { Game::getSingleton()->togglePause(); } - InGameAppState::ConsoleButton::ConsoleButton(Vector3 pos, Vector2 size) : Button(pos, size, "Console", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) { } + InGameAppState::ConsoleButton::ConsoleButton(Vector3 pos, Vector2 size) : PfButtonBase(pos, size, "Console", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) {} void InGameAppState::ConsoleButton::onClick() { ConcreteGuiManager::getSingleton()->readLuaScreenScript("console.lua"); } - InGameAppState::ConsoleButton::ConsoleButton::ConsoleCommandEntryButton::ConsoleCommandEntryButton(Textbox *t, Listbox *l, Vector3 pos, Vector2 size, string name) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", 257, true) { - textbox = t; - listbox = l; - } + InGameAppState::ConsoleButton::ConsoleButton::ConsoleCommandEntryButton::ConsoleCommandEntryButton(Textbox *t, Listbox *l, Vector3 pos, Vector2 size, string name) : + PfButtonBase(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", 257, true), + textbox(t), + listbox(l) + {} void InGameAppState::ConsoleButton::ConsoleButton::ConsoleCommandEntryButton::onClick() { Console::execute(wstringToString(textbox->getText())); diff --git a/inGameAppState.h b/inGameAppState.h index 14172d5..04a15fb 100755 --- a/inGameAppState.h +++ b/inGameAppState.h @@ -16,16 +16,16 @@ namespace battleship{ class InGameAppState : public gameBase::AbstractAppState { public: - class ResumeButton : public vb01Gui::Button { + class ResumeButton : public PfButtonBase { public: ResumeButton(vb01::Vector3, vb01::Vector2); void onClick(); private: }; - class ConsoleButton : public vb01Gui::Button { + class ConsoleButton : public PfButtonBase { public: - class ConsoleCommandEntryButton : public Button { + class ConsoleCommandEntryButton : public PfButtonBase { public: ConsoleCommandEntryButton(vb01Gui::Textbox*, vb01Gui::Listbox*, vb01::Vector3, vb01::Vector2, std::string); void onClick(); diff --git a/loadMapButton.cpp b/loadMapButton.cpp index 9d16784..6c5d6de 100644 --- a/loadMapButton.cpp +++ b/loadMapButton.cpp @@ -12,7 +12,10 @@ namespace battleship{ using namespace vb01Gui; using namespace gameBase; - LoadMapButton::OkButton::OkButton(vb01::Vector3 pos, vb01::Vector2 size, vb01Gui::Listbox *listbox) : Button(pos, size, "Ok", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){ this->listbox = listbox; } + LoadMapButton::OkButton::OkButton(Vector3 pos, Vector2 size, Listbox *lb) : + PfButtonBase(pos, size, "Ok", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true), + listbox(lb) + {} void LoadMapButton::OkButton::onClick(){ StateManager *sm = GameManager::getSingleton()->getStateManager(); @@ -20,7 +23,7 @@ namespace battleship{ handleLoadingGui(new LoadingAppState(new MapEditorAppState(name, Vector2::VEC_ZERO, false), "mapEditor.lua")); } - LoadMapButton::LoadMapButton(Vector3 pos, Vector2 size) : Button(pos, size, "Load map", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){} + LoadMapButton::LoadMapButton(Vector3 pos, Vector2 size) : PfButtonBase(pos, size, "Load map", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true){} void LoadMapButton::onClick(){ ConcreteGuiManager::getSingleton()->readLuaScreenScript("loadMap.lua"); diff --git a/loadMapButton.h b/loadMapButton.h index 997fea3..3a8f2fa 100644 --- a/loadMapButton.h +++ b/loadMapButton.h @@ -1,16 +1,16 @@ #ifndef LOAD_MAP_BUTTON_H #define LOAD_MAP_BUTTON_H -#include +#include "pfButtonBase.h" namespace vb01Gui{ class Listbox; } namespace battleship{ - class LoadMapButton : public vb01Gui::Button{ + class LoadMapButton : public PfButtonBase{ public: - class OkButton : public vb01Gui::Button{ + class OkButton : public PfButtonBase{ public: OkButton(vb01::Vector3, vb01::Vector2, vb01Gui::Listbox*); void onClick(); diff --git a/mainMenuButton.cpp b/mainMenuButton.cpp index f7516c9..5ec3615 100644 --- a/mainMenuButton.cpp +++ b/mainMenuButton.cpp @@ -7,7 +7,7 @@ namespace battleship{ using namespace vb01; using namespace vb01Gui; - MainMenuButton::MainMenuButton(Vector3 pos, Vector2 size, string name) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true){} + MainMenuButton::MainMenuButton(Vector3 pos, Vector2 size, string name) : PfButtonBase(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true){} void MainMenuButton::onClick(){ } diff --git a/mainMenuButton.h b/mainMenuButton.h index dff8db3..3ed0aa7 100644 --- a/mainMenuButton.h +++ b/mainMenuButton.h @@ -1,10 +1,10 @@ #ifndef MAIN_MENU_BUTTON_H #define MAIN_MENU_BUTTON_H -#include +#include "pfButtonBase.h" namespace battleship{ - class MainMenuButton : public vb01Gui::Button{ + class MainMenuButton : public PfButtonBase{ public: MainMenuButton(vb01::Vector3, vb01::Vector2, std::string); void onClick(); diff --git a/mapEditorButton.h b/mapEditorButton.h index 5c3be9d..1d63cdd 100644 --- a/mapEditorButton.h +++ b/mapEditorButton.h @@ -1,14 +1,13 @@ #ifndef MAP_EDITOR_BUTTON_H #define MAP_EDITOR_BUTTON_H -#include - +#include "pfButtonBase.h" #include "gameManager.h" namespace battleship{ - class MapEditorButton : public vb01Gui::Button{ + class MapEditorButton : public PfButtonBase{ public: - MapEditorButton(vb01::Vector3 pos, vb01::Vector2 size) : vb01Gui::Button(pos, size, "Map editor", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){} + MapEditorButton(vb01::Vector3 pos, vb01::Vector2 size) : PfButtonBase(pos, size, "Map editor", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true){} void onClick(); private: }; diff --git a/newMapButton.cpp b/newMapButton.cpp index f85fee5..754aa0d 100644 --- a/newMapButton.cpp +++ b/newMapButton.cpp @@ -15,11 +15,12 @@ namespace battleship{ using namespace vb01Gui; using namespace gameBase; - NewMapButton::OkButton::OkButton(vb01::Vector3 pos, vb01::Vector2 size, vb01Gui::Textbox *name, vb01Gui::Textbox *sx, vb01Gui::Textbox *sy) : Button(pos, size, "Ok", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true){ - this->name = name; - this->sizeX = sx; - this->sizeY = sy; - } + NewMapButton::OkButton::OkButton(Vector3 pos, Vector2 size, Textbox *nm, Textbox *sx, Textbox *sy) : + PfButtonBase(pos, size, "Ok", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true), + name(nm), + sizeX(sx), + sizeY(sy) + {} void NewMapButton::OkButton::onClick(){ Vector2 size = Vector2( @@ -29,7 +30,7 @@ namespace battleship{ handleLoadingGui(new LoadingAppState(new MapEditorAppState(wstringToString(name->getText()), size, true), "mapEditor.lua")); } - NewMapButton::NewMapButton(Vector3 pos, Vector2 size) : Button(pos, size, "New map", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){} + NewMapButton::NewMapButton(Vector3 pos, Vector2 size) : PfButtonBase(pos, size, "New map", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true){} void NewMapButton::onClick(){ ConcreteGuiManager::getSingleton()->readLuaScreenScript("newMap.lua"); diff --git a/newMapButton.h b/newMapButton.h index fd48fb0..300ff7d 100644 --- a/newMapButton.h +++ b/newMapButton.h @@ -1,16 +1,16 @@ #ifndef NEW_MAP_BUTTON_H #define NEW_MAP_BUTTON_H -#include +#include "pfButtonBase.h" namespace vb01Gui{ class Textbox; } namespace battleship{ - class NewMapButton : public vb01Gui::Button{ + class NewMapButton : public PfButtonBase{ public: - class OkButton : public vb01Gui::Button{ + class OkButton : public PfButtonBase{ public: OkButton(vb01::Vector3, vb01::Vector2, vb01Gui::Textbox*, vb01Gui::Textbox*, vb01Gui::Textbox*); void onClick(); diff --git a/offerButton.cpp b/offerButton.cpp index c9bf9f7..b3f2c81 100644 --- a/offerButton.cpp +++ b/offerButton.cpp @@ -17,7 +17,7 @@ namespace battleship{ using namespace gameBase; OfferButton::OfferButton(Vector3 pos, Vector2 size, int plId, string name, int trigger, string imagePath) : - Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, true, imagePath), + PfButtonBase(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, true, imagePath), playerId(plId){} void OfferButton::onClick(){ diff --git a/offerButton.h b/offerButton.h index 6de5592..07b3d08 100644 --- a/offerButton.h +++ b/offerButton.h @@ -1,10 +1,10 @@ #ifndef OFFER_BUTTON_H #define OFFER_BUTTON_H -#include +#include "pfButtonBase.h" namespace battleship{ - class OfferButton : public vb01Gui::Button{ + class OfferButton : public PfButtonBase{ public: OfferButton(vb01::Vector3, vb01::Vector2, int, std::string, int, std::string); void onClick(); diff --git a/okButton.cpp b/okButton.cpp index 91aa580..12bf6af 100644 --- a/okButton.cpp +++ b/okButton.cpp @@ -6,7 +6,7 @@ namespace battleship{ using namespace vb01; using namespace vb01Gui; - OkButton::OkButton(Vector3 pos, Vector2 size, string name) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) {} + OkButton::OkButton(Vector3 pos, Vector2 size, string name) : PfButtonBase(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) {} void OkButton::onClick() {} } diff --git a/okButton.h b/okButton.h index 9aedbd7..4b130cb 100644 --- a/okButton.h +++ b/okButton.h @@ -1,10 +1,10 @@ #ifndef OK_BUTTON_H #define OK_BUTTON_H -#include +#include "pfButtonBase.h" namespace battleship{ - class OkButton : public vb01Gui::Button{ + class OkButton : public PfButtonBase{ public: OkButton(vb01::Vector3, vb01::Vector2, std::string); void onClick(); diff --git a/optionsButton.cpp b/optionsButton.cpp index d7297c7..151c49b 100755 --- a/optionsButton.cpp +++ b/optionsButton.cpp @@ -7,7 +7,7 @@ using namespace vb01; using namespace std; namespace battleship{ - OptionsButton::OptionsButton(Vector3 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, separate) {} + OptionsButton::OptionsButton(Vector3 pos, Vector2 size, string name, bool separate) : PfButtonBase(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, separate) {} void OptionsButton::onClick() { ConcreteGuiManager::getSingleton()->readLuaScreenScript("options.lua"); diff --git a/optionsButton.h b/optionsButton.h index 98a5681..5415806 100755 --- a/optionsButton.h +++ b/optionsButton.h @@ -1,11 +1,10 @@ -#pragma once #ifndef OPTIONS_BUTTON_H #define OPTIONS_BUTTON_H -#include +#include "pfButtonBase.h" namespace battleship { - class OptionsButton : public vb01Gui::Button { + class OptionsButton : public PfButtonBase { public: OptionsButton(vb01::Vector3, vb01::Vector2, std::string, bool); virtual void onClick(); diff --git a/orderButton.cpp b/orderButton.cpp index 0251c06..147e3ba 100644 --- a/orderButton.cpp +++ b/orderButton.cpp @@ -13,7 +13,7 @@ namespace battleship{ using namespace gameBase; OrderButton::OrderButton(Vector3 pos, Vector2 size, string name, int trigger, string imagePath, int oid) : - Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, true, imagePath), + PfButtonBase(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, true, imagePath), orderId(oid) {} diff --git a/orderButton.h b/orderButton.h index fa05fc0..015bdcb 100644 --- a/orderButton.h +++ b/orderButton.h @@ -1,10 +1,10 @@ #ifndef ORDER_BUTTON_H #define ORDER_BUTTON_H -#include +#include "pfButtonBase.h" namespace battleship{ - class OrderButton : public vb01Gui::Button{ + class OrderButton : public PfButtonBase{ public: OrderButton(vb01::Vector3, vb01::Vector2, std::string, int, std::string, int); void onClick(); diff --git a/pfButtonBase.cpp b/pfButtonBase.cpp new file mode 100644 index 0000000..d7504a4 --- /dev/null +++ b/pfButtonBase.cpp @@ -0,0 +1,23 @@ +#include "pfButtonBase.h" +#include "tooltip.h" + +#include +#include + +namespace battleship{ + using namespace std; + using namespace vb01; + + PfButtonBase::PfButtonBase(Vector3 pos, Vector2 size, string name, string fontPath, int trigger, bool separate, string imagePath) : Button(pos, size, name, fontPath, trigger, separate, imagePath){} + + PfButtonBase::~PfButtonBase(){ + if(tooltip) delete tooltip; + } + + void PfButtonBase::update() { + if(enabledHoveredOn) + setColor(mouseOver ? hoveredOnColor : baseColor); + + if(tooltip) tooltip->getBackground()->getNode()->setVisible(mouseOver); + } +} diff --git a/pfButtonBase.h b/pfButtonBase.h new file mode 100644 index 0000000..01a50e9 --- /dev/null +++ b/pfButtonBase.h @@ -0,0 +1,25 @@ +#ifndef PF_BUTTON_BASE_H +#define PF_BUTTON_BASE_H + +#include + +namespace battleship{ + class Tooltip; + + class PfButtonBase : public vb01Gui::Button{ + public: + PfButtonBase(vb01::Vector3, vb01::Vector2, std::string, std::string, int, bool, std::string = ""); + ~PfButtonBase(); + virtual void update(); + inline void setTooltip(Tooltip *t){this->tooltip = t;} + inline void setEnabledHoverdOn(bool e){this->enabledHoveredOn = e;} + inline void setHoveredOnColor(vb01::Vector4 hc){this->hoveredOnColor = hc;} + inline void setBaseColor(vb01::Vector4 bc){this->baseColor = bc;} + private: + bool enabledHoveredOn = false; + vb01::Vector4 baseColor, hoveredOnColor; + Tooltip *tooltip = nullptr; + }; +} + +#endif diff --git a/playButton.cpp b/playButton.cpp index 1374d72..9dc7070 100644 --- a/playButton.cpp +++ b/playButton.cpp @@ -15,7 +15,7 @@ namespace battleship{ using namespace vb01Gui; using namespace gameBase; - PlayButton::PlayButton(Listbox *ml, Vector3 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", GLFW_KEY_P, separate), mapListbox(ml) {} + PlayButton::PlayButton(Listbox *ml, Vector3 pos, Vector2 size, string name, bool separate) : PfButtonBase(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", GLFW_KEY_P, separate), mapListbox(ml) {} void PlayButton::onClick() { ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); diff --git a/playButton.h b/playButton.h index d265cdc..5eecd69 100644 --- a/playButton.h +++ b/playButton.h @@ -1,14 +1,14 @@ #ifndef PLAY_BUTTON_H #define PLAY_BUTTON_H -#include +#include "pfButtonBase.h" namespace vb01Gui{ class Listbox; } namespace battleship{ - class PlayButton : public vb01Gui::Button { + class PlayButton : public PfButtonBase { public: PlayButton(vb01Gui::Listbox*, vb01::Vector3, vb01::Vector2, std::string, bool); void onClick(); diff --git a/resourceAmmountButton.cpp b/resourceAmmountButton.cpp index 2d1448f..8af5cf9 100644 --- a/resourceAmmountButton.cpp +++ b/resourceAmmountButton.cpp @@ -9,7 +9,9 @@ namespace battleship{ using namespace vb01; using namespace vb01Gui; - ResourceAmmountButton::ResourceAmmountButton(Vector3 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) { + ResourceAmmountButton::ResourceAmmountButton(Vector3 pos, Vector2 size, string name, int amm, int trigger, string imagePath) : + PfButtonBase(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]; diff --git a/resourceAmmountButton.h b/resourceAmmountButton.h index 390dedd..502a88c 100644 --- a/resourceAmmountButton.h +++ b/resourceAmmountButton.h @@ -1,14 +1,14 @@ #ifndef RESOURCE_AMMOUNT_BUTTON_H #define RESOURCE_AMMOUNT_BUTTON_H -#include +#include "pfButtonBase.h" namespace vb01Gui{ class Textbox; } namespace battleship{ - class ResourceAmmountButton : public vb01Gui::Button{ + class ResourceAmmountButton : public PfButtonBase{ public: ResourceAmmountButton(vb01::Vector3, vb01::Vector2, std::string, int, int, std::string); void onClick(); diff --git a/singlePlayerButton.cpp b/singlePlayerButton.cpp index 11819be..0d0cc62 100644 --- a/singlePlayerButton.cpp +++ b/singlePlayerButton.cpp @@ -15,9 +15,7 @@ namespace battleship{ using namespace vb01; using namespace vb01Gui; - SinglePlayerButton::SinglePlayerButton(Vector3 pos, Vector2 size, string name) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", GLFW_KEY_S, true) {} - - SinglePlayerButton::~SinglePlayerButton(){delete tooltip;} + SinglePlayerButton::SinglePlayerButton(Vector3 pos, Vector2 size, string name) : PfButtonBase(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", GLFW_KEY_S, true) {} void SinglePlayerButton::onClick() { ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); @@ -29,10 +27,4 @@ namespace battleship{ guiManager->getText("_mainPlayer")->setText(GameManager::getSingleton()->getMainPlayerName()); } - - void SinglePlayerButton::update() { - setColor(mouseOver ? Vector4(.8, .8, .8, 1) : Vector4(.6, .6, .6, 1)); - - if(tooltip) tooltip->getBackground()->getNode()->setVisible(mouseOver); - } } diff --git a/singlePlayerButton.h b/singlePlayerButton.h index 4a5bf52..0fde367 100644 --- a/singlePlayerButton.h +++ b/singlePlayerButton.h @@ -3,20 +3,16 @@ #include -#include +#include "pfButtonBase.h" namespace battleship{ class Tooltip; - class SinglePlayerButton : public vb01Gui::Button { + class SinglePlayerButton : public PfButtonBase { public: SinglePlayerButton(vb01::Vector3, vb01::Vector2, std::string); - ~SinglePlayerButton(); + ~SinglePlayerButton(){} void onClick(); - void update(); - inline void setTooltip(Tooltip *t){this->tooltip = t;} - private: - Tooltip *tooltip = nullptr; }; } diff --git a/stateToggleButton.cpp b/stateToggleButton.cpp index 52b09af..580c58f 100644 --- a/stateToggleButton.cpp +++ b/stateToggleButton.cpp @@ -12,7 +12,7 @@ namespace battleship{ using namespace vb01Gui; using namespace gameBase; - StateToggleButton::StateToggleButton(Vector3 pos, Vector2 size, string name, int trigger, string imagePath) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, true, imagePath) { + StateToggleButton::StateToggleButton(Vector3 pos, Vector2 size, string name, int trigger, string imagePath) : PfButtonBase(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, true, imagePath) { updateStateId(); toggleImage(); } diff --git a/stateToggleButton.h b/stateToggleButton.h index 774e087..a3cf846 100644 --- a/stateToggleButton.h +++ b/stateToggleButton.h @@ -1,10 +1,10 @@ #ifndef STATE_TOGGLE_BUTTON_H #define STATE_TOGGLE_BUTTON_H -#include +#include "pfButtonBase.h" namespace battleship{ - class StateToggleButton : public vb01Gui::Button{ + class StateToggleButton : public PfButtonBase{ public: StateToggleButton(vb01::Vector3, vb01::Vector2, std::string, int, std::string); void onClick(); diff --git a/statsButton.cpp b/statsButton.cpp index 3495f1f..f1aa455 100644 --- a/statsButton.cpp +++ b/statsButton.cpp @@ -13,7 +13,7 @@ namespace battleship{ using namespace vb01; using namespace gameBase; - StatsButton::StatsButton(Vector3 pos, Vector2 size, string name, int trigger, string imagePath) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, true, imagePath){} + StatsButton::StatsButton(Vector3 pos, Vector2 size, string name, int trigger, string imagePath) : PfButtonBase(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, true, imagePath){} void StatsButton::addPlayerDataGuiElements(int playerId){ const int numPairs = 7; diff --git a/statsButton.h b/statsButton.h index 57e73cf..f593319 100644 --- a/statsButton.h +++ b/statsButton.h @@ -1,10 +1,10 @@ #ifndef STATS_BUTTON_H #define STATS_BUTTON_H -#include +#include "pfButtonBase.h" namespace battleship { - class StatsButton : public vb01Gui::Button{ + class StatsButton : public PfButtonBase{ public: StatsButton(vb01::Vector3, vb01::Vector2, std::string, int, std::string); void onClick(); diff --git a/tabButton.cpp b/tabButton.cpp index 64cf1cd..52f75a6 100644 --- a/tabButton.cpp +++ b/tabButton.cpp @@ -7,7 +7,7 @@ namespace battleship{ using namespace vb01; using namespace vb01Gui; - TabButton::TabButton(Vector3 pos, Vector2 size, string name, string screenScript) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) { + TabButton::TabButton(Vector3 pos, Vector2 size, string name, string screenScript) : PfButtonBase(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) { this->screenScript = screenScript; } diff --git a/tabButton.h b/tabButton.h index 5d91331..8a5f9e2 100644 --- a/tabButton.h +++ b/tabButton.h @@ -1,10 +1,10 @@ #ifndef TAB_BUTTON_H #define TAB_BUTTON_H -#include +#include "pfButtonBase.h" namespace battleship{ - class TabButton : public vb01Gui::Button{ + class TabButton : public PfButtonBase{ public: TabButton(vb01::Vector3, vb01::Vector2, std::string, std::string); void onClick(); diff --git a/unitButton.cpp b/unitButton.cpp index 8b0c3f3..ad87bee 100644 --- a/unitButton.cpp +++ b/unitButton.cpp @@ -12,7 +12,7 @@ namespace battleship{ using namespace vb01Gui; using namespace gameBase; - UnitButton::UnitButton(Vector3 pos, Vector2 size, string name, string fontPath, int trigger, string imagePath) : Button(pos, size, name, fontPath, trigger, true, imagePath){ + UnitButton::UnitButton(Vector3 pos, Vector2 size, string name, string fontPath, int trigger, string imagePath) : PfButtonBase(pos, size, name, fontPath, trigger, true, imagePath){ StateManager *stateManager = GameManager::getSingleton()->getStateManager(); ActiveGameState *activeState = (ActiveGameState*)stateManager->getAppStateByType((int)AppStateType::ACTIVE_STATE); diff --git a/unitButton.h b/unitButton.h index 86944ad..799026a 100644 --- a/unitButton.h +++ b/unitButton.h @@ -1,12 +1,12 @@ #ifndef UNIT_BUTTON_H #define UNIT_BUTTON_H -#include +#include "pfButtonBase.h" namespace battleship{ class Unit; - class UnitButton : public vb01Gui::Button{ + class UnitButton : public PfButtonBase{ public: UnitButton(vb01::Vector3, vb01::Vector2, std::string, std::string, int, std::string); protected: