diff --git a/src/display/rendering/starfield.h b/src/display/rendering/starfield.h index e60fa978..7eeb4b37 100644 --- a/src/display/rendering/starfield.h +++ b/src/display/rendering/starfield.h @@ -19,7 +19,6 @@ namespace glow { class Buffer; }; - /** * Renders a starfield around the camera. * Old camera positions/orientations are stored in order to stretch the diff --git a/src/gamestate/gameplay/gameplay.cpp b/src/gamestate/gameplay/gameplay.cpp index f21741e9..2cb210b1 100644 --- a/src/gamestate/gameplay/gameplay.cpp +++ b/src/gamestate/gameplay/gameplay.cpp @@ -29,6 +29,7 @@ #include "camera/camerahead.h" #include "camera/cameradolly.h" #include "ui/hud/hud.h" +#include "ui/hud/buttonhudget.h" #include "display/viewer.h" #include "display/rendering/texturerenderer.h" @@ -43,8 +44,10 @@ GamePlay::GamePlay(Game* game) : m_freecamInput(new GamePlayFreecamInput(*this)), m_freecamActive(false), m_scene(new GamePlayScene(*this)), + m_scenario(new ScriptedScenario(this, "")), m_soundManager(new SoundManager()) { + setResetCallback(); updateView(); setInitialSubState(m_runningState); @@ -109,12 +112,9 @@ SoundManager& GamePlay::soundManager() { } void GamePlay::loadScenario(int i) { - TextureRenderer loadRenderer("data/textures/loading.dds"); - loadRenderer.display("Loading Scenario..."); + displayLoadingScreen("Loading Scenario..."); - m_soundManager->stopAll(); - m_scenario->clear(); - updateView(); + clearScenario(); switch (i) { case 0: @@ -140,6 +140,8 @@ void GamePlay::loadScenario(int i) { } m_scenario->load(); + setResetCallback(); + } void GamePlay::update(float deltaSec) { @@ -170,3 +172,29 @@ void GamePlay::updateView() { World::instance()->player().hud().setView(&m_game->viewer().view()); } +void GamePlay::resetScenario() { + displayLoadingScreen("resetting scenario"); + clearScenario(); + + m_scenario->load(); +} + +void GamePlay::clearScenario() { + m_soundManager->stopAll(); + m_scenario->clear(); + updateView(); +} + +void GamePlay::displayLoadingScreen(const std::string& status) { + TextureRenderer loadRenderer("data/textures/loading.dds"); + loadRenderer.display(status); +} + +void GamePlay::resetButtonCallback(ClickType clickType){ + resetScenario(); + setResetCallback(); +} + +void GamePlay::setResetCallback() { + World::instance()->player().hud().resetButton()->setCallback((std::function)std::bind(&GamePlay::resetButtonCallback, this, std::placeholders::_1)); +} diff --git a/src/gamestate/gameplay/gameplay.h b/src/gamestate/gameplay/gameplay.h index e571e640..93d3fbaa 100644 --- a/src/gamestate/gameplay/gameplay.h +++ b/src/gamestate/gameplay/gameplay.h @@ -1,8 +1,10 @@ #pragma once #include +#include #include "gamestate/gamestate.h" +#include "ui/clicktype.h" class BaseScenario; @@ -42,6 +44,8 @@ class GamePlay: public GameState { SoundManager& soundManager(); void loadScenario(int i); + void resetScenario(); + void displayLoadingScreen(const std::string& status); virtual void update(float deltaSec) override; @@ -64,5 +68,11 @@ class GamePlay: public GameState { std::unique_ptr m_freecamInput; bool m_freecamActive; + + void resetButtonCallback(ClickType clickType); + + void clearScenario(); + + void setResetCallback(); }; diff --git a/src/gamestate/gameplay/input/gameplaynormalinput.cpp b/src/gamestate/gameplay/input/gameplaynormalinput.cpp index 004e14c8..e09f684a 100644 --- a/src/gamestate/gameplay/input/gameplaynormalinput.cpp +++ b/src/gamestate/gameplay/input/gameplaynormalinput.cpp @@ -1,8 +1,5 @@ #include "gameplaynormalinput.h" -#ifdef WIN32 -#include -#endif #include #include @@ -103,7 +100,8 @@ GamePlayNormalInput::GamePlayNormalInput(GamePlay& gamePlay) : m_lastfocus = glfwGetWindowAttrib(glfwGetCurrentContext(), GLFW_FOCUSED); retrieveInputValues(); - m_currentTimePressed = 0; + m_currentTimePressedRight = 0; + m_currentTimePressedLeft = 0; } void GamePlayNormalInput::onResizeEvent(const unsigned int width, const unsigned int height) { @@ -143,11 +141,16 @@ void GamePlayNormalInput::onKeyEvent(int key, int scancode, int action, int mods void GamePlayNormalInput::onMouseButtonEvent(int button, int action, int mods) { if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_RELEASE) { - if (m_currentTimePressed > 0 && m_currentTimePressed < m_maxClickTime) { + if (m_currentTimePressedRight > 0 && m_currentTimePressedRight < m_maxClickTime) { World::instance()->player().hud().onClick(ClickType::Selection); - } else { } - m_currentTimePressed = 0; + m_currentTimePressedRight = 0; + } + if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_RELEASE) { + if (m_currentTimePressedLeft > 0 && m_currentTimePressedLeft < m_maxClickTime) { + World::instance()->player().hud().onClick(ClickType::Selection); + } + m_currentTimePressedLeft = 0; } } @@ -239,11 +242,14 @@ void GamePlayNormalInput::processMouseUpdate(float deltaSec) { m_fireUpdate = true; } - if (glfwGetMouseButton(glfwGetCurrentContext(), GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS){ - m_currentTimePressed += deltaSec; + if (glfwGetMouseButton(glfwGetCurrentContext(), GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS) { + m_currentTimePressedRight += deltaSec; + } + if (glfwGetMouseButton(glfwGetCurrentContext(), GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS) { + m_currentTimePressedLeft += deltaSec; } - if (m_mouseControl || glfwGetMouseButton(glfwGetCurrentContext(), GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS && m_maxClickTime < m_currentTimePressed) { + if (m_mouseControl || glfwGetMouseButton(glfwGetCurrentContext(), GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS && m_maxClickTime < m_currentTimePressedRight) { glm::vec3 rot; x = ContextProvider::instance()->resolution().width() / 2 - (int)floor(x); y = ContextProvider::instance()->resolution().height() / 2 - (int)floor(y); diff --git a/src/gamestate/gameplay/input/gameplaynormalinput.h b/src/gamestate/gameplay/input/gameplaynormalinput.h index 9a40862a..c78e0090 100644 --- a/src/gamestate/gameplay/input/gameplaynormalinput.h +++ b/src/gamestate/gameplay/input/gameplaynormalinput.h @@ -57,7 +57,8 @@ class GamePlayNormalInput : public GamePlayInput { void addActionsToVector(); void retrieveInputValues(); - float m_currentTimePressed; + float m_currentTimePressedLeft; + float m_currentTimePressedRight; Property m_deadzoneMouse; Property m_deadzoneGamepad; diff --git a/src/input/inputconfigurator.cpp b/src/input/inputconfigurator.cpp index ef28664b..97b7e04c 100644 --- a/src/input/inputconfigurator.cpp +++ b/src/input/inputconfigurator.cpp @@ -88,8 +88,10 @@ bool InputConfigurator::isConfiguring() { void InputConfigurator::startConfiguration(InputClass inputClass) { if (inputClass == InputClass::Primary) { + World::instance()->player().hud().showMissionInfo("", "Starting configuration for primary input device (keyboard), Please follow the instructions"); glow::info("Starting configuration for primary input device (keyboard), Please follow the instructions"); } else { + World::instance()->player().hud().showMissionInfo("", "Starting configuration for secondary input device (gamepad/Joystick), Please follow the instructions"); glow::info("Starting configuration for secondary input device (gamepad/Joystick), Please follow the instructions"); m_idleValues.resize(m_secondaryInputValues->axisCnt); for(int a = 0; a < m_secondaryInputValues->axisCnt; a++) { diff --git a/src/player.cpp b/src/player.cpp index dabe0c77..2fd758f6 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -7,9 +7,6 @@ #include "factions/factionmatrix.h" -#include "gamestate/game.h" -#include "gamestate/gameplay/gameplay.h" - #include "ui/hud/hud.h" #include "ui/hud/hudget.h" #include "ui/hud/aimhelperhudget.h" diff --git a/src/scenarios/basescenario.h b/src/scenarios/basescenario.h index 584c80ba..b746556c 100644 --- a/src/scenarios/basescenario.h +++ b/src/scenarios/basescenario.h @@ -7,8 +7,8 @@ class BaseScenario { public: BaseScenario(GamePlay* gamePlay); - void load(); - void clear(); + virtual void load(); + virtual void clear(); void reset(); diff --git a/src/scenarios/scriptedscenario.cpp b/src/scenarios/scriptedscenario.cpp index b66b7be4..2a36b723 100644 --- a/src/scenarios/scriptedscenario.cpp +++ b/src/scenarios/scriptedscenario.cpp @@ -35,9 +35,9 @@ ScriptedScenario::ScriptedScenario(GamePlay* gamePlay, const std::string& path): BaseScenario(gamePlay), - m_script(new GamePlayScript(World::instance()->scriptEngine())) + m_script(new GamePlayScript(World::instance()->scriptEngine())), + m_path(path) { - m_script->load(path); } ScriptedScenario::~ScriptedScenario() = default; @@ -54,3 +54,13 @@ void ScriptedScenario::populateWorld() { m_world->scriptEngine().addScript(m_script); } +void ScriptedScenario::load() { + m_script.reset(new GamePlayScript(World::instance()->scriptEngine())); + m_script->load(m_path); + BaseScenario::load(); +} + +void ScriptedScenario::clear() { + m_script.reset(); + BaseScenario::clear(); +} diff --git a/src/scenarios/scriptedscenario.h b/src/scenarios/scriptedscenario.h index ee4c860e..a9f0d6d9 100644 --- a/src/scenarios/scriptedscenario.h +++ b/src/scenarios/scriptedscenario.h @@ -17,10 +17,14 @@ class ScriptedScenario: public BaseScenario { ScriptedScenario(GamePlay* gamePlay, const std::string& path); virtual ~ScriptedScenario(); + virtual void load() override; + virtual void clear() override; protected: std::shared_ptr m_script; virtual void populateWorld() override; + + std::string m_path; }; diff --git a/src/ui/clicktype.h b/src/ui/clicktype.h new file mode 100644 index 00000000..381770be --- /dev/null +++ b/src/ui/clicktype.h @@ -0,0 +1,7 @@ +#pragma once + +enum class ClickType { + None, + Selection, + Fire +}; \ No newline at end of file diff --git a/src/ui/hud/buttonhudget.cpp b/src/ui/hud/buttonhudget.cpp new file mode 100644 index 00000000..2fd0b0e0 --- /dev/null +++ b/src/ui/hud/buttonhudget.cpp @@ -0,0 +1,52 @@ +#include "buttonhudget.h" + +#include "hud.h" +#include "buttonhudgetvoxels.h" + + +ButtonHudget::ButtonHudget(HUD* hud, const glm::vec3 &direction, const std::function& callback, TextOrientation textOrientation, float scale, const std::string& content, FontSize fontSize, ButtonStyle buttonStyle) : + Hudget(hud), + m_buttonVoxels(new ButtonHudgetVoxels(this, direction, textOrientation, scale, content, fontSize, buttonStyle)), + m_callback(callback) +{ + m_buttonVoxels->updateBounds(); +} + +ButtonHudget::~ButtonHudget() = default; + +void ButtonHudget::update(float deltaSec) { +} + +void ButtonHudget::draw() { + m_buttonVoxels->draw(); +} + +bool ButtonHudget::isAt(const Ray& ray) const { + return m_buttonVoxels->isAt(ray); +} + +void ButtonHudget::onClick(ClickType clickType) { + if (m_callback) { + m_callback(clickType); + } +} + +void ButtonHudget::setCallback(const std::function& callback) { + m_callback = callback; +} + +void ButtonHudget::setText(const std::string& content) { + m_buttonVoxels->setText(content); +} + +void ButtonHudget::setTextOrientation(TextOrientation textOrientation) { + m_buttonVoxels->setTextOrientation(textOrientation); +} + +ButtonStyle ButtonHudget::buttonStyle() { + return m_buttonVoxels->buttonStyle(); +} + +void ButtonHudget::setButtonStyle(ButtonStyle buttonStyle) { + m_buttonVoxels->setButtonStyle(buttonStyle); +} \ No newline at end of file diff --git a/src/ui/hud/buttonhudget.h b/src/ui/hud/buttonhudget.h new file mode 100644 index 00000000..2224cf0c --- /dev/null +++ b/src/ui/hud/buttonhudget.h @@ -0,0 +1,40 @@ +#pragma once + +#include +#include +#include + +#include "hudget.h" +#include "ui/voxelfontconstants.h" + + +class ButtonHudgetVoxels; +class TextFieldHudgetVoxels; + +class ButtonHudget : public Hudget { +public: + ButtonHudget(HUD* hud, const glm::vec3& direction, const std::function& callback, TextOrientation textOrientation = TextOrientation::FORWARDS, float scale = 0.5f, const std::string& content = "", FontSize fontSize = FontSize::SIZE5x7, ButtonStyle borderStyle = ButtonStyle::BORDERED); + virtual ~ButtonHudget(); + + virtual void update(float deltaSec) override; + virtual void draw() override; + + virtual bool isAt(const Ray& ray) const override; + + virtual void onClick(ClickType clicktype) override; + + void setText(const std::string& content); + + void setCallback(const std::function& callback); + + void setTextOrientation(TextOrientation textOrientation); + + ButtonStyle buttonStyle(); + void setButtonStyle(ButtonStyle buttonStyle); + +protected: + std::function m_callback; + std::string m_content; + std::unique_ptr m_buttonVoxels; +}; + diff --git a/src/ui/hud/buttonhudgetvoxels.cpp b/src/ui/hud/buttonhudgetvoxels.cpp new file mode 100644 index 00000000..200c11eb --- /dev/null +++ b/src/ui/hud/buttonhudgetvoxels.cpp @@ -0,0 +1,72 @@ +#include "buttonhudgetvoxels.h" + +#include "buttonhudget.h" +#include "voxel/voxelcluster.h" +#include "voxel/voxel.h" +#include "voxel/voxelrenderer.h" +#include "hud.h" + + +ButtonHudgetVoxels::ButtonHudgetVoxels(ButtonHudget* buttonHudget, const glm::vec3& direction, TextOrientation textOrientation, float scale, const std::string& content, FontSize fontSize, ButtonStyle buttonStyle) : + TextFieldHudgetVoxels(buttonHudget, direction, textOrientation, scale, content, fontSize), + m_buttonVoxels(new VoxelCluster(scale)), + m_buttonStyle(buttonStyle), + m_hudget(buttonHudget) +{ + setText(content); +} + +ButtonHudgetVoxels::~ButtonHudgetVoxels() = default; + +void ButtonHudgetVoxels::updateBounds() { + if (m_buttonStyle == ButtonStyle::PLAIN) { + return; + } + m_buttonVoxels.reset(new VoxelCluster(m_scale)); + int width = (int)(m_width/m_scale)*m_text.size()+1; + int height = (int)(m_height/m_scale)*2; + for (int i = 0; i < width; i++) { + for (int j = 0; j < height; j++) { + if (i == 0 || j == 0 || i == width - 1 || j == height - 1) { + m_buttonVoxels->addVoxel(new Voxel(glm::ivec3(i, j, 0), 0x0FF00F)); + } else if (m_buttonStyle == ButtonStyle::BORDERED_FILLED) { + m_buttonVoxels->addVoxel(new Voxel(glm::ivec3(i, j, 1), 0x17012D)); + } + } + } +} + +void ButtonHudgetVoxels::draw() { + if (m_buttonStyle == ButtonStyle::BORDERED || m_buttonStyle == ButtonStyle::BORDERED_FILLED) { + switch (textOrientation()) { + case TextOrientation::FORWARDS: + m_buttonVoxels->transform().setPosition(lowerRight()); + m_buttonVoxels->transform().setOrientation(m_hudget->hud()->orientation()); + m_buttonVoxels->transform().rotate(glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0))); + break; + case TextOrientation::SPHERE_STRAIGHT: + m_buttonVoxels->transform().setPosition(lowerRight()); + m_buttonVoxels->transform().setOrientation(m_hudget->worldOrientation(TextFieldHudgetVoxels::m_direction)); + m_buttonVoxels->transform().rotate(glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0))); + break; + } + VoxelRenderer::instance()->draw(*m_buttonVoxels); + } + TextFieldHudgetVoxels::draw(); +} + +void ButtonHudgetVoxels::setText(const std::string& text) { + if (m_text.compare(text) == 0) { + return; + } + TextFieldHudgetVoxels::setText(text); + updateBounds(); +} + +ButtonStyle ButtonHudgetVoxels::buttonStyle() { + return m_buttonStyle; +} + +void ButtonHudgetVoxels::setButtonStyle(ButtonStyle buttonStyle) { + m_buttonStyle = buttonStyle; +} \ No newline at end of file diff --git a/src/ui/hud/buttonhudgetvoxels.h b/src/ui/hud/buttonhudgetvoxels.h new file mode 100644 index 00000000..ad039209 --- /dev/null +++ b/src/ui/hud/buttonhudgetvoxels.h @@ -0,0 +1,33 @@ +#pragma once + +#include +#include + +#include "textfieldhudgetvoxels.h" + + +class VoxelFont; +class ButtonHudget; +class VoxelCluster; + +class ButtonHudgetVoxels : public TextFieldHudgetVoxels { +public: + ButtonHudgetVoxels(ButtonHudget* textFieldHudget, const glm::vec3& direction, TextOrientation textOrienation = TextOrientation::FORWARDS, float scale = 0.5f, const std::string& content = "", FontSize fontSize = FontSize::SIZE5x7, ButtonStyle buttonStyle = ButtonStyle::BORDERED); + ~ButtonHudgetVoxels(); + + void setText(const std::string& text); + + void updateBounds(); + + virtual void draw() override; + + ButtonStyle buttonStyle(); + void setButtonStyle(ButtonStyle buttonStyle); + +protected: + std::unique_ptr m_buttonVoxels; + Hudget* m_hudget; + + ButtonStyle m_buttonStyle; +}; + diff --git a/src/ui/hud/hud.cpp b/src/ui/hud/hud.cpp index 9bb9fbd3..9eb0f58c 100644 --- a/src/ui/hud/hud.cpp +++ b/src/ui/hud/hud.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -45,6 +46,7 @@ #include "crosshair.h" #include "aimhelperhudget.h" #include "textfieldhudget.h" +#include "buttonhudget.h" @@ -54,6 +56,9 @@ HUD::HUD(Player* player): m_crossHair(new CrossHair(this)), m_aimHelper(new AimHelperHudget(this)), m_scanner(new WorldTreeScanner()), + m_targetName(new TextFieldHudget(this, glm::normalize(glm::vec3(0, -1.1f, -2)), TextOrientation::FORWARDS, 0.025f, "")), + m_speedLabel(new TextFieldHudget(this, glm::normalize(glm::vec3(1.5f, -1.1f, -2)), TextOrientation::FORWARDS, 0.020f, "")), + m_resetButton(new ButtonHudget(this, glm::normalize(glm::vec3(-1.5f, 1.1f, -2)), nullptr, TextOrientation::FORWARDS, 0.01f, "RESET", FontSize::SIZE5x7, ButtonStyle::BORDERED)), m_elements(new HUDElements(*this)), m_drawHud("vfx.drawhud"), m_view(nullptr) @@ -62,6 +67,9 @@ HUD::HUD(Player* player): m_elements->addHudget(m_aimHelper); m_elements->addHudget(m_crossHair); + m_elements->addHudget(m_targetName); + m_elements->addHudget(m_speedLabel); + m_elements->addHudget(m_resetButton); } HUD::~HUD() = default; @@ -277,3 +285,6 @@ void HUD::setView(const View* view) { m_view = view; } +ButtonHudget* HUD::resetButton() { + return m_resetButton; +} diff --git a/src/ui/hud/hud.h b/src/ui/hud/hud.h index b3bfb84b..3b0f668b 100644 --- a/src/ui/hud/hud.h +++ b/src/ui/hud/hud.h @@ -10,13 +10,9 @@ #include "property/property.h" -#include "utils/handle/handle.h" - +#include "ui/clicktype.h" -enum class ClickType { - None, - Selection -}; +#include "utils/handle/handle.h" class Player; class Hudget; @@ -30,6 +26,7 @@ class Viewer; class WorldTreeScanner; class CrossHair; class TextFieldHudget; +class ButtonHudget; class View; class HUD { @@ -76,6 +73,8 @@ class HUD { void showMissionMessage(const std::string& message); void showMessage(const std::string& message); + ButtonHudget* resetButton(); + protected: Player* m_player; @@ -87,6 +86,9 @@ class HUD { float m_fovy; float m_fovx; + TextFieldHudget* m_speedLabel; + TextFieldHudget* m_targetName; + ButtonHudget* m_resetButton; CrossHair* m_crossHair; AimHelperHudget* m_aimHelper; @@ -98,5 +100,6 @@ class HUD { void updateScanner(float deltaSec); void updateFov(); -}; + void openMenu(ClickType clicktype); +}; diff --git a/src/ui/hud/hudelements.cpp b/src/ui/hud/hudelements.cpp index 22ec950f..ad853be1 100644 --- a/src/ui/hud/hudelements.cpp +++ b/src/ui/hud/hudelements.cpp @@ -9,18 +9,19 @@ #include "hudgetanimation.h" #include "hudgethideanimation.h" #include "textfieldhudget.h" +#include "ui/voxelfontconstants.h" HUDElements::HUDElements(HUD& hud): m_hud(hud), - m_targetName(new TextFieldHudget(&m_hud, glm::normalize(glm::vec3(0, -1.1f, -2)), 0.025f, "")), - m_speedLabel(new TextFieldHudget(&m_hud, glm::normalize(glm::vec3(1.5f, -1.1f, -2)), 0.020f, "")), - m_shieldLabel(new TextFieldHudget(&m_hud, glm::normalize(glm::vec3(-1.5f, -1.1f, -2)), 0.020f, "")), - m_missionTitle(new TextFieldHudget(&m_hud, glm::normalize(glm::vec3(0.0f, 1.0f, -2)), 0.020f, "")), + m_targetName(new TextFieldHudget(&m_hud, glm::normalize(glm::vec3(0, -1.1f, -2)), TextOrientation::FORWARDS, 0.025f, "")), + m_speedLabel(new TextFieldHudget(&m_hud, glm::normalize(glm::vec3(1.5f, -1.1f, -2)), TextOrientation::FORWARDS, 0.020f, "")), + m_missionTitle(new TextFieldHudget(&m_hud, glm::normalize(glm::vec3(0.0f, 1.0f, -2)), TextOrientation::FORWARDS, 0.020f, "")), + m_shieldLabel(new TextFieldHudget(&m_hud, glm::normalize(glm::vec3(-1.5f, -1.1f, -2)), TextOrientation::FORWARDS, 0.020f, "")), m_missionTitleHider(new HudgetHideAnimation(*m_missionTitle)), - m_missionCaption(new TextFieldHudget(&m_hud, glm::normalize(glm::vec3(0.0f, 0.8f, -2)), 0.010f, "")), + m_missionCaption(new TextFieldHudget(&m_hud, glm::normalize(glm::vec3(0.0f, 0.8f, -2)), TextOrientation::SPHERE_STRAIGHT, 0.010f, "")), m_missionCaptionHider(new HudgetHideAnimation(*m_missionCaption)), - m_missionMessage(new TextFieldHudget(&m_hud, glm::normalize(glm::vec3(-0.9f, -0.9f, -2)), 0.010f, "")), + m_missionMessage(new TextFieldHudget(&m_hud, glm::normalize(glm::vec3(-0.9f, -0.9f, -2)), TextOrientation::FORWARDS, 0.010f, "")), m_missionMessageHider(new HudgetHideAnimation(*m_missionMessage)) { addHudget(m_targetName); diff --git a/src/ui/hud/hudget.h b/src/ui/hud/hudget.h index e5eea8d9..87d9dc47 100644 --- a/src/ui/hud/hudget.h +++ b/src/ui/hud/hudget.h @@ -4,8 +4,8 @@ #include #include "geometry/ray.h" +#include "ui/clicktype.h" -enum class ClickType; class HUD; diff --git a/src/ui/hud/objecthudget.cpp b/src/ui/hud/objecthudget.cpp index b5561554..d16338c0 100644 --- a/src/ui/hud/objecthudget.cpp +++ b/src/ui/hud/objecthudget.cpp @@ -39,7 +39,7 @@ ObjectHudget::ObjectHudget(HUD* hud): m_objectDelegate(nullptr), m_objectVoxels(new ObjectHudgetVoxels(this)), m_arrowVoxels(new ArrowHudgetVoxels(this)), - m_shieldLabel(new TextFieldHudget(hud, glm::vec3(), 0.010f)) + m_shieldLabel(new TextFieldHudget(hud, glm::vec3(), TextOrientation::FORWARDS, 0.010f)) { m_insideFov = false; } diff --git a/src/ui/hud/textfieldhudget.cpp b/src/ui/hud/textfieldhudget.cpp index d4a05f87..26997ef5 100644 --- a/src/ui/hud/textfieldhudget.cpp +++ b/src/ui/hud/textfieldhudget.cpp @@ -4,10 +4,10 @@ #include "textfieldhudgetvoxels.h" -TextFieldHudget::TextFieldHudget(HUD* hud, const glm::vec3& direction, float scale, const std::string& text, FontSize size) : +TextFieldHudget::TextFieldHudget(HUD* hud, const glm::vec3& direction, TextOrientation textOrientation, float scale, const std::string& text, FontSize size) : Hudget(hud), m_text(text), - m_voxels(new TextFieldHudgetVoxels(this, direction, scale, text, size)) + m_voxels(new TextFieldHudgetVoxels(this, direction, textOrientation, scale, text, size)) { m_direction = direction; } diff --git a/src/ui/hud/textfieldhudget.h b/src/ui/hud/textfieldhudget.h index b42634ae..dba5b341 100644 --- a/src/ui/hud/textfieldhudget.h +++ b/src/ui/hud/textfieldhudget.h @@ -11,7 +11,7 @@ class TextFieldHudgetVoxels; class TextFieldHudget : public Hudget { public: - TextFieldHudget(HUD* hud, const glm::vec3& direction, float scale = 0.5f, const std::string& content = "", FontSize fontSize = FontSize::SIZE5x7); + TextFieldHudget(HUD* hud, const glm::vec3& direction, TextOrientation textOrientation = TextOrientation::FORWARDS, float scale = 0.5f, const std::string& content = "", FontSize fontSize = FontSize::SIZE5x7); virtual ~TextFieldHudget(); void setText(const std::string& content); diff --git a/src/ui/hud/textfieldhudgetvoxels.cpp b/src/ui/hud/textfieldhudgetvoxels.cpp index cc8c2c9e..179d13c1 100644 --- a/src/ui/hud/textfieldhudgetvoxels.cpp +++ b/src/ui/hud/textfieldhudgetvoxels.cpp @@ -12,13 +12,14 @@ #include "utils/geometryhelper.h" -TextFieldHudgetVoxels::TextFieldHudgetVoxels(TextFieldHudget* textFieldHudget, const glm::vec3& direction, float scale, const std::string& text, FontSize fontSize) : - m_textFieldHudget(textFieldHudget), +TextFieldHudgetVoxels::TextFieldHudgetVoxels(Hudget* textFieldHudget, const glm::vec3& direction, TextOrientation textOrientation, float scale, const std::string& text, FontSize fontSize) : + m_hudget(textFieldHudget), m_voxelFont(VoxelFont::instance()), m_text(text), m_direction(direction), m_scale(scale), - m_fontSize(fontSize) + m_fontSize(fontSize), + m_textOrientation(textOrientation) { m_width = m_voxelFont->letterWidth(fontSize) * m_scale; m_height = m_voxelFont->letterWidth(fontSize) * m_scale; @@ -35,23 +36,23 @@ void TextFieldHudgetVoxels::setDirection(const glm::vec3& direction) { } void TextFieldHudgetVoxels::draw() { - m_voxelFont->drawString(m_text, m_textFieldHudget->worldPosition(m_direction), m_textFieldHudget->worldOrientation(m_direction), m_fontSize, m_scale, FontAlign::CENTER); + m_voxelFont->drawString(m_text, worldPosition(), orientation(), m_fontSize, m_scale, FontAlign::CENTER); } const glm::vec3 TextFieldHudgetVoxels::upperLeft() const { - return worldPosition() + worldOrientation() * offsetToCenter(true, true); + return worldPosition() + orientation() * offsetToCenter(true, true); } const glm::vec3 TextFieldHudgetVoxels::lowerLeft() const { - return worldPosition() + worldOrientation() * offsetToCenter(false, true); + return worldPosition() + orientation() * offsetToCenter(false, true); } const glm::vec3 TextFieldHudgetVoxels::upperRight() const { - return worldPosition() + worldOrientation() * offsetToCenter(true, false); + return worldPosition() + orientation() * offsetToCenter(true, false); } const glm::vec3 TextFieldHudgetVoxels::lowerRight() const { - return worldPosition() + worldOrientation() * offsetToCenter(false, false); + return worldPosition() + orientation() * offsetToCenter(false, false); } bool TextFieldHudgetVoxels::isAt(const Ray& ray) const { @@ -71,17 +72,43 @@ float TextFieldHudgetVoxels::scale() { } const glm::vec3 TextFieldHudgetVoxels::offsetToCenter(bool upper, bool left) const { - float horizontalOffset = left ? static_cast(m_text.length()) : 0; - float verticalOffset = upper ? m_height : -m_height; - - return glm::vec3(m_offset + m_width * horizontalOffset - m_width / 2, verticalOffset, 0); + float horizontalOffset, verticalOffset; + if (left) { + horizontalOffset = 0; + } else { + horizontalOffset = (float)m_text.length(); + } + if (upper) { + verticalOffset = m_height; + } else { + verticalOffset = -m_height; + } + + return glm::vec3(m_offset + m_width*horizontalOffset - m_width / 2, verticalOffset, 0); } glm::vec3 TextFieldHudgetVoxels::worldPosition() const { - return m_textFieldHudget->worldPosition(m_direction); + return m_hudget->worldPosition(m_direction); } glm::quat TextFieldHudgetVoxels::worldOrientation() const { - return m_textFieldHudget->worldOrientation(m_direction); + return m_hudget->worldOrientation(m_direction); +} + +TextOrientation TextFieldHudgetVoxels::textOrientation() { + return m_textOrientation; } +glm::quat TextFieldHudgetVoxels::orientation() const { + switch (m_textOrientation) { + case TextOrientation::FORWARDS: + return m_hudget->hud()->orientation(); + case TextOrientation::SPHERE_STRAIGHT: + return worldOrientation(); + } + return glm::quat(); +} + +void TextFieldHudgetVoxels::setTextOrientation(TextOrientation textOrientation) { + m_textOrientation = textOrientation; +} diff --git a/src/ui/hud/textfieldhudgetvoxels.h b/src/ui/hud/textfieldhudgetvoxels.h index e7470b2f..2b4bb388 100644 --- a/src/ui/hud/textfieldhudgetvoxels.h +++ b/src/ui/hud/textfieldhudgetvoxels.h @@ -6,18 +6,17 @@ #include "hudget.h" #include "ui/voxelfontconstants.h" -class TextFieldHudget; +class Hudget; class VoxelFont; -class TextFieldHudgetVoxels{ +class TextFieldHudgetVoxels { public: - TextFieldHudgetVoxels(TextFieldHudget* textFieldHudget, const glm::vec3& direction, float scale = 0.5f, const std::string& text = "", FontSize fontSize = FontSize::SIZE5x7); + TextFieldHudgetVoxels(Hudget* textFieldHudget, const glm::vec3& direction, TextOrientation textOrientation = TextOrientation::FORWARDS, float scale = 0.5f, const std::string& text = "", FontSize fontSize = FontSize::SIZE5x7); void setText(const std::string& text); void setDirection(const glm::vec3& direction); - void update(float deltaSec); - void draw(); + virtual void draw(); virtual bool isAt(const Ray& ray) const; @@ -25,17 +24,25 @@ class TextFieldHudgetVoxels{ float height(); float scale(); + TextOrientation textOrientation(); + void setTextOrientation(TextOrientation textOrientation); protected: - FontSize m_fontSize; - TextFieldHudget* m_textFieldHudget; std::string m_text; - VoxelFont* m_voxelFont; + + Hudget* m_hudget; + glm::vec3 m_direction; + glm::vec3 worldPosition() const; + glm::quat worldOrientation() const; + glm::quat orientation() const; + + FontSize m_fontSize; + VoxelFont* m_voxelFont; + float m_width, m_height, m_scale; float m_offset; - const glm::vec3 offsetToCenter(bool upper, bool left) const; const glm::vec3 upperLeft() const; @@ -43,7 +50,6 @@ class TextFieldHudgetVoxels{ const glm::vec3 upperRight() const; const glm::vec3 lowerRight() const; - glm::vec3 worldPosition() const; - glm::quat worldOrientation() const; + TextOrientation m_textOrientation; }; diff --git a/src/ui/voxelfont.cpp b/src/ui/voxelfont.cpp index dde935b0..83aa5604 100644 --- a/src/ui/voxelfont.cpp +++ b/src/ui/voxelfont.cpp @@ -90,9 +90,9 @@ void VoxelFont::drawString(std::string text, glm::vec3 position, glm::quat orien int VoxelFont::letterWidth(FontSize size) { switch (size) { case FontSize::SIZE3x5: - return 3; - case FontSize::SIZE5x7: return 5; + case FontSize::SIZE5x7: + return 7; default: assert(false); } @@ -117,4 +117,4 @@ VoxelFont* VoxelFont::instance() { } return s_instance; -} +} diff --git a/src/ui/voxelfontconstants.h b/src/ui/voxelfontconstants.h index feb31e32..7262d2fc 100644 --- a/src/ui/voxelfontconstants.h +++ b/src/ui/voxelfontconstants.h @@ -9,4 +9,15 @@ enum class FontAlign { LEFT, CENTER, RIGHT +}; + +enum class TextOrientation { + FORWARDS, // facing straight forward, "normal text" + SPHERE_STRAIGHT // on-helmet effect, facing in look direction from pov +}; + +enum class ButtonStyle { + PLAIN, + BORDERED, + BORDERED_FILLED }; \ No newline at end of file diff --git a/src/world/world.cpp b/src/world/world.cpp index faf44ae2..65c34bf2 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -11,6 +11,9 @@ #include "worldobject/ship.h" #include "worldobject/worldobject.h" +#include "ui/hud/textfieldhudget.h" +#include "ui/hud/hud.h" + #include "display/rendering/skybox.h" #include "scripting/scriptengine.h" @@ -159,5 +162,3 @@ void World::printStatus() { glow::info(" VoxelCount: %;", voxelCount); glow::info(" ParticleCount: %;", particleCount); } - - diff --git a/src/world/world.h b/src/world/world.h index 28f80cc9..e012ab0a 100644 --- a/src/world/world.h +++ b/src/world/world.h @@ -16,6 +16,8 @@ class VoxelParticleEngine; class WorldObject; class WorldLogic; class WorldTree; +class TextFieldHudget; +class HUD; class World { public: @@ -44,7 +46,6 @@ class World { static World* instance(); static void reset(bool showWarning=true); - protected: friend class God;