diff --git a/Assets/Scripts/Gui/activeGameState.lua b/Assets/Scripts/Gui/activeGameState.lua index 07aa28c..3db570f 100644 --- a/Assets/Scripts/Gui/activeGameState.lua +++ b/Assets/Scripts/Gui/activeGameState.lua @@ -2,6 +2,7 @@ res = graphics.resolution Size = {x = 70, y = 70} sz = 210 s = 40 +minimapSize = {x = 200, y = 200} resTextScale = {x = .5, y = .5} resIconBasePath = 'Icons/Resources/' pointerTex = 'pointer.png' @@ -9,6 +10,14 @@ attackTex = 'attack.png' garrisonTex = 'garrison.png' gui = { + { + guiType = GuiType.BUTTON, + buttonType = ButtonType.MINIMAP, + name = 'minimap', + pos = {x = res.x - minimapSize.x, y = 0, z = 0}, + size = minimapSize, + color = {x = .5, y = .5, z = .5, w = 1} + }, { guiType = GuiType.TEXT, name = 'refineds', diff --git a/Assets/Scripts/Gui/main.lua b/Assets/Scripts/Gui/main.lua index bf9ba09..9075486 100644 --- a/Assets/Scripts/Gui/main.lua +++ b/Assets/Scripts/Gui/main.lua @@ -37,7 +37,8 @@ ButtonType = { PLAYER_TRADE = 33, TRADING_SCREEN = 34, TRADE_OFFER = 35, - RESOURCE_AMMOUNT = 36 + RESOURCE_AMMOUNT = 36, + MINIMAP = 37 } ListboxType = { diff --git a/CMakeLists.txt b/CMakeLists.txt index a6b8bf0..a7a592d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ set(OPTIONS_BUTTONS optionsButton.cpp tabButton.cpp okButton.cpp defaultsButton. 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}) +set(BUTTONS 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) set(GUI tooltip.cpp concreteGuiManager.cpp ${BUTTONS} ${LISTBOXES}) diff --git a/concreteGuiManager.cpp b/concreteGuiManager.cpp index dd7e8c6..cd1c837 100644 --- a/concreteGuiManager.cpp +++ b/concreteGuiManager.cpp @@ -31,6 +31,7 @@ #include "tradingScreenButton.h" #include "offerButton.h" #include "resourceAmmountButton.h" +#include "minimapButton.h" namespace battleship{ using namespace std; @@ -261,6 +262,9 @@ namespace battleship{ case RESOURCE_AMMOUNT: button = new ResourceAmmountButton(pos, size, name, (int)guiTable["ammount"], (int)guiTable["trigger"], imagePath); break; + case MINIMAP: + button = new MinimapButton(pos, size, ""); + break; } int typeArr[2]{(int)GuiElementType::BUTTON, (int)type}; diff --git a/concreteGuiManager.h b/concreteGuiManager.h index bc6c8e4..36b3340 100644 --- a/concreteGuiManager.h +++ b/concreteGuiManager.h @@ -51,7 +51,8 @@ namespace battleship{ PLAYER_TRADE, TRADING_SCREEN, TRADE_OFFER, - RESOURCE_AMMOUNT + RESOURCE_AMMOUNT, + MINIMAP }; enum ListboxType { CONTROLS, diff --git a/minimapButton.cpp b/minimapButton.cpp new file mode 100644 index 0000000..c8a4f1d --- /dev/null +++ b/minimapButton.cpp @@ -0,0 +1,31 @@ +#include "minimapButton.h" +#include "map.h" + +#include + +namespace battleship{ + using namespace vb01; + using namespace std; + + MinimapButton::MinimapButton(Vector3 pos, Vector2 size, string ip) : Button(pos, size, "minimap", "", -1, true, ip){ + content = new Node(); + rectNode->attachChild(content); + } + + MinimapButton::~MinimapButton(){ + } + + void MinimapButton::update(){ + Button::update(); + } + + void MinimapButton::onClick(){ + Vector2 clickPos = getCursorPos(); + float posXRatio = (clickPos.x - pos.x) / size.x; + float posYRatio = (clickPos.y - pos.y) / size.y; + + Camera *cam = Root::getSingleton()->getCamera(); + Vector3 mapSize = Map::getSingleton()->getMapSize(); + cam->setPosition(Vector3(mapSize.x * (-.5 + posXRatio), cam->getPosition().y, mapSize.z * (-.5 + posYRatio))); + } +} diff --git a/minimapButton.h b/minimapButton.h new file mode 100644 index 0000000..1f12ca9 --- /dev/null +++ b/minimapButton.h @@ -0,0 +1,22 @@ +#ifndef MINIMAP_BUTTON_H +#define MINIMAP_BUTTON_H + +#include + +namespace vb01{ + class Node; +} + +namespace battleship{ + class MinimapButton : public vb01Gui::Button{ + public: + MinimapButton(vb01::Vector3, vb01::Vector2, std::string); + ~MinimapButton(); + void onClick(); + void update(); + private: + vb01::Node *content = nullptr; + }; +} + +#endif