From ef177feeaedc471f29a86a807a835db3904e6101 Mon Sep 17 00:00:00 2001 From: gersseba Date: Wed, 5 Mar 2014 21:38:30 +0100 Subject: [PATCH 01/21] wip --- src/ui/hud/buttonhudget.cpp | 42 ++++++++++++++++++++++++++++++ src/ui/hud/buttonhudget.h | 30 +++++++++++++++++++++ src/ui/hud/buttonhudgetvoxels.cpp | 0 src/ui/hud/buttonhudgetvoxels.h | 27 +++++++++++++++++++ src/ui/hud/textfieldhudgetvoxels.h | 14 +++++----- 5 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 src/ui/hud/buttonhudget.cpp create mode 100644 src/ui/hud/buttonhudget.h create mode 100644 src/ui/hud/buttonhudgetvoxels.cpp create mode 100644 src/ui/hud/buttonhudgetvoxels.h diff --git a/src/ui/hud/buttonhudget.cpp b/src/ui/hud/buttonhudget.cpp new file mode 100644 index 00000000..f77a9a72 --- /dev/null +++ b/src/ui/hud/buttonhudget.cpp @@ -0,0 +1,42 @@ +#include "textfieldhudget.h" + +#include "hud.h" +#include "textfieldhudgetvoxels.h" + + +TextFieldHudget::TextFieldHudget(HUD* hud, std::string content, glm::vec3 direction) : +Hudget(hud), +m_content(content), +m_voxels(new TextFieldHudgetVoxels(this, content, direction, 0.04f)) { + m_direction = direction; +} + +TextFieldHudget::TextFieldHudget(HUD* hud, std::string content, glm::vec3 direction, float scale) : +Hudget(hud), +m_content(content), +m_voxels(new TextFieldHudgetVoxels(this, content, direction, scale)) { + m_direction = direction; +} + +TextFieldHudget::~TextFieldHudget() = default; + +void TextFieldHudget::update(float deltaSec) { +} + +void TextFieldHudget::draw() { + m_voxels->draw(); +} + +void TextFieldHudget::setContent(std::string content) { + m_content = content; + m_voxels->setContent(content); +} + + +bool TextFieldHudget::isAt(const Ray& ray) const { + return m_voxels->isAt(ray); +} + +void TextFieldHudget::onClick(ClickType clickType) { + // Nothing to do here +} \ 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..6b72808e --- /dev/null +++ b/src/ui/hud/buttonhudget.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include + +#include "hudget.h" + +class TextFieldHudgetVoxels; + + +class TextFieldHudget : public Hudget { +public: + TextFieldHudget(HUD* hud, std::string content, glm::vec3 direction); + TextFieldHudget(HUD* hud, std::string content, glm::vec3 direction, float scale); + virtual ~TextFieldHudget(); + + void setContent(std::string content); + + virtual void update(float deltaSec) override; + virtual void draw() override; + + virtual bool isAt(const Ray& ray) const override; + + virtual void onClick(ClickType clickType) override; + +protected: + std::string m_content; + std::unique_ptr m_voxels; +}; + diff --git a/src/ui/hud/buttonhudgetvoxels.cpp b/src/ui/hud/buttonhudgetvoxels.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/ui/hud/buttonhudgetvoxels.h b/src/ui/hud/buttonhudgetvoxels.h new file mode 100644 index 00000000..5952a7cf --- /dev/null +++ b/src/ui/hud/buttonhudgetvoxels.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include + +#include "textfieldhudgetvoxels.h" +#include "hudget.h" + +class VoxelFont; +class ButtonHudget; + +class ButtonHudgetVoxels : public TextFieldHudgetVoxels { +public: + ButtonHudgetVoxels(ButtonHudget* textFieldHudget); + ButtonHudgetVoxels(ButtonHudget* textFieldHudget, std::string content, glm::vec3 direction, float scale); + + void setContent(std::string content); + + void update(float deltaSec); + ; + + virtual bool isAt(const Ray& ray) const override; + + +protected: +}; + diff --git a/src/ui/hud/textfieldhudgetvoxels.h b/src/ui/hud/textfieldhudgetvoxels.h index 155368bd..e2598969 100644 --- a/src/ui/hud/textfieldhudgetvoxels.h +++ b/src/ui/hud/textfieldhudgetvoxels.h @@ -15,14 +15,10 @@ class TextFieldHudgetVoxels{ void setContent(std::string content); - void update(float deltaSec); - void draw(); + virtual void update(float deltaSec); + virtual void draw(); virtual bool isAt(const Ray& ray) const; - const glm::vec3 upperLeft() const; - const glm::vec3 lowerLeft() const; - const glm::vec3 upperRight() const; - const glm::vec3 lowerRight() const; float width(); float height(); @@ -30,6 +26,12 @@ class TextFieldHudgetVoxels{ protected: + + const glm::vec3 upperLeft() const; + const glm::vec3 lowerLeft() const; + const glm::vec3 upperRight() const; + const glm::vec3 lowerRight() const; + TextFieldHudget* m_textFieldHudget; std::string m_content; VoxelFont* m_voxelFont; From 508130fecdec140495c180c23a57e05b3f2c94a0 Mon Sep 17 00:00:00 2001 From: gersseba Date: Fri, 7 Mar 2014 00:39:12 +0100 Subject: [PATCH 02/21] Buttons have borders --- src/ui/hud/buttonhudget.cpp | 42 ++++++++++----------- src/ui/hud/buttonhudget.h | 23 +++++++----- src/ui/hud/buttonhudgetvoxels.cpp | 56 ++++++++++++++++++++++++++++ src/ui/hud/buttonhudgetvoxels.h | 14 +++++-- src/ui/hud/hud.cpp | 8 +++- src/ui/hud/hud.h | 5 ++- src/ui/hud/textfieldhudgetvoxels.cpp | 14 +++---- src/ui/hud/textfieldhudgetvoxels.h | 6 +-- 8 files changed, 120 insertions(+), 48 deletions(-) diff --git a/src/ui/hud/buttonhudget.cpp b/src/ui/hud/buttonhudget.cpp index f77a9a72..f25dcf0b 100644 --- a/src/ui/hud/buttonhudget.cpp +++ b/src/ui/hud/buttonhudget.cpp @@ -1,42 +1,40 @@ -#include "textfieldhudget.h" +#include "buttonhudget.h" #include "hud.h" -#include "textfieldhudgetvoxels.h" +#include "buttonhudgetvoxels.h" -TextFieldHudget::TextFieldHudget(HUD* hud, std::string content, glm::vec3 direction) : -Hudget(hud), -m_content(content), -m_voxels(new TextFieldHudgetVoxels(this, content, direction, 0.04f)) { - m_direction = direction; +ButtonHudget::ButtonHudget(HUD* hud, std::string content, glm::vec3 direction) : +TextFieldHudget(hud,content,direction), +m_voxels(new ButtonHudgetVoxels(this, content, direction, 0.04f)) { } -TextFieldHudget::TextFieldHudget(HUD* hud, std::string content, glm::vec3 direction, float scale) : -Hudget(hud), -m_content(content), -m_voxels(new TextFieldHudgetVoxels(this, content, direction, scale)) { - m_direction = direction; +ButtonHudget::ButtonHudget(HUD* hud, std::string content, glm::vec3 direction, float scale) : +TextFieldHudget(hud, content, direction, scale), +m_voxels(new ButtonHudgetVoxels(this, content, direction, scale)) { } -TextFieldHudget::~TextFieldHudget() = default; +ButtonHudget::~ButtonHudget() = default; -void TextFieldHudget::update(float deltaSec) { +void ButtonHudget::update(float deltaSec) { } -void TextFieldHudget::draw() { +void ButtonHudget::draw() { m_voxels->draw(); } -void TextFieldHudget::setContent(std::string content) { - m_content = content; - m_voxels->setContent(content); +bool ButtonHudget::isAt(const Ray& ray) const { + return m_voxels->isAt(ray); } +void ButtonHudget::onClick(ClickType clickType) { + callback(clickType); +} -bool TextFieldHudget::isAt(const Ray& ray) const { - return m_voxels->isAt(ray); +void ButtonHudget::registerCallback(void(*callbackFunction)(ClickType clickType)) { + callback = callbackFunction; } -void TextFieldHudget::onClick(ClickType clickType) { - // Nothing to do here +void ButtonHudget::setContent(std::string content) { + m_voxels->setContent(content); } \ No newline at end of file diff --git a/src/ui/hud/buttonhudget.h b/src/ui/hud/buttonhudget.h index 6b72808e..d1bcfb63 100644 --- a/src/ui/hud/buttonhudget.h +++ b/src/ui/hud/buttonhudget.h @@ -4,27 +4,30 @@ #include #include "hudget.h" +#include "textfieldhudget.h" -class TextFieldHudgetVoxels; +class ButtonHudgetVoxels; - -class TextFieldHudget : public Hudget { +class ButtonHudget : public TextFieldHudget { public: - TextFieldHudget(HUD* hud, std::string content, glm::vec3 direction); - TextFieldHudget(HUD* hud, std::string content, glm::vec3 direction, float scale); - virtual ~TextFieldHudget(); - - void setContent(std::string content); + ButtonHudget(HUD* hud, std::string content, glm::vec3 direction); + ButtonHudget(HUD* hud, std::string content, glm::vec3 direction, float scale); + 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; + virtual void onClick(ClickType clicktype) override; + + virtual void setContent(std::string content); + + void registerCallback(void(*callbackFunction)(ClickType clickType)); protected: + void(*callback)(ClickType clicktype); std::string m_content; - std::unique_ptr m_voxels; + std::unique_ptr m_voxels; }; diff --git a/src/ui/hud/buttonhudgetvoxels.cpp b/src/ui/hud/buttonhudgetvoxels.cpp index e69de29b..410721c7 100644 --- a/src/ui/hud/buttonhudgetvoxels.cpp +++ b/src/ui/hud/buttonhudgetvoxels.cpp @@ -0,0 +1,56 @@ +#include "buttonhudgetvoxels.h" + +#include "buttonhudget.h" +#include "voxel/voxelcluster.h" +#include "voxel/voxel.h" +#include "voxel/voxelrenderer.h" + + +ButtonHudgetVoxels::ButtonHudgetVoxels(ButtonHudget* buttonHudget, std::string content, glm::vec3 direction, float scale) : +TextFieldHudgetVoxels(buttonHudget, content, direction, scale), +m_horizontalBounds(new VoxelCluster(scale)), +m_verticalBounds(new VoxelCluster(scale)) +{ + setContent(content); +} + +ButtonHudgetVoxels::~ButtonHudgetVoxels() = default; + +void ButtonHudgetVoxels::updateBounds() { + delete m_horizontalBounds; + m_horizontalBounds = (new VoxelCluster(m_scale)); + delete m_verticalBounds; + m_verticalBounds = (new VoxelCluster(m_scale)); + int width = (int)(m_width/m_scale)*m_content.size(); + int height = (int)(m_height/m_scale)*2; + for (int i = 0; i < width; i++) { + m_horizontalBounds->addVoxel(new Voxel(glm::ivec3(i, 0, 0), 0x0FF00F)); + } + for (int i = 0; i < height; i++) { + m_verticalBounds->addVoxel(new Voxel(glm::ivec3(0, i, 0), 0x0FF00F)); + } +} + +void ButtonHudgetVoxels::draw() { + TextFieldHudgetVoxels::draw(); + m_horizontalBounds->transform().setPosition(upperLeft()); + m_horizontalBounds->transform().setOrientation(m_hudget->worldOrientation(m_direction)); + VoxelRenderer::instance()->draw(*m_horizontalBounds); + m_horizontalBounds->transform().setPosition(lowerLeft()); + m_horizontalBounds->transform().setOrientation(m_hudget->worldOrientation(m_direction)); + VoxelRenderer::instance()->draw(*m_horizontalBounds); + m_verticalBounds->transform().setPosition(lowerLeft()); + m_verticalBounds->transform().setOrientation(m_hudget->worldOrientation(m_direction)); + VoxelRenderer::instance()->draw(*m_verticalBounds); + m_verticalBounds->transform().setPosition(lowerRight()); + m_verticalBounds->transform().setOrientation(m_hudget->worldOrientation(m_direction)); + VoxelRenderer::instance()->draw(*m_verticalBounds); +} + +void ButtonHudgetVoxels::setContent(std::string content) { + if (m_content.compare(content) == 0) { + return; + } + TextFieldHudgetVoxels::setContent(content); + updateBounds(); +} \ No newline at end of file diff --git a/src/ui/hud/buttonhudgetvoxels.h b/src/ui/hud/buttonhudgetvoxels.h index 5952a7cf..99403759 100644 --- a/src/ui/hud/buttonhudgetvoxels.h +++ b/src/ui/hud/buttonhudgetvoxels.h @@ -4,24 +4,30 @@ #include #include "textfieldhudgetvoxels.h" -#include "hudget.h" class VoxelFont; class ButtonHudget; +class VoxelCluster; class ButtonHudgetVoxels : public TextFieldHudgetVoxels { public: ButtonHudgetVoxels(ButtonHudget* textFieldHudget); ButtonHudgetVoxels(ButtonHudget* textFieldHudget, std::string content, glm::vec3 direction, float scale); + ~ButtonHudgetVoxels(); void setContent(std::string content); - void update(float deltaSec); - ; + //void update(float deltaSec); - virtual bool isAt(const Ray& ray) const override; + void updateBounds(); + virtual void draw() override; + + //virtual bool isAt(const Ray& ray) const override; protected: + VoxelCluster* m_horizontalBounds; + VoxelCluster* m_verticalBounds; + }; diff --git a/src/ui/hud/hud.cpp b/src/ui/hud/hud.cpp index 5d110453..f64209ba 100644 --- a/src/ui/hud/hud.cpp +++ b/src/ui/hud/hud.cpp @@ -35,6 +35,7 @@ #include "display/view.h" #include "camera/camerahead.h" #include "textfieldhudget.h" +#include "buttonhudget.h" #include "physics/physics.h" @@ -46,7 +47,7 @@ HUD::HUD(Player* player, Viewer* viewer): 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, -2)))), + m_targetName(new ButtonHudget(this, "", glm::normalize(glm::vec3(0, -1, -2)))), m_speedLabel(new TextFieldHudget(this, "", glm::normalize(glm::vec3(1, -1, -2)), 0.03f)), m_target(nullptr) { @@ -55,6 +56,7 @@ HUD::HUD(Player* player, Viewer* viewer): m_hudgets.push_back(m_aimHelper.get()); m_hudgets.push_back(m_targetName.get()); m_hudgets.push_back(m_speedLabel.get()); + //m_targetName->registerCallback(&callback); } HUD::~HUD() = default; @@ -232,3 +234,7 @@ float HUD::fovy() const { float HUD::fovx() const { return m_fovx; } + +void HUD::callback(ClickType clicktype) { + printf("callback"); +} diff --git a/src/ui/hud/hud.h b/src/ui/hud/hud.h index 36487f84..131842ee 100644 --- a/src/ui/hud/hud.h +++ b/src/ui/hud/hud.h @@ -26,6 +26,7 @@ class Viewer; class WorldTreeScanner; class CrossHair; class TextFieldHudget; +class ButtonHudget; class HUD { public: @@ -79,7 +80,7 @@ class HUD { std::unique_ptr m_crossHair; std::unique_ptr m_scanner; std::unique_ptr m_speedLabel; - std::unique_ptr m_targetName; + std::unique_ptr m_targetName; std::list m_hudgets; @@ -87,5 +88,7 @@ class HUD { void updateScanner(float deltaSec); void updateFov(); + + void callback(ClickType clicktype); }; diff --git a/src/ui/hud/textfieldhudgetvoxels.cpp b/src/ui/hud/textfieldhudgetvoxels.cpp index db95d0d9..dfd47742 100644 --- a/src/ui/hud/textfieldhudgetvoxels.cpp +++ b/src/ui/hud/textfieldhudgetvoxels.cpp @@ -13,14 +13,14 @@ #include "utils/geometryhelper.h" TextFieldHudgetVoxels::TextFieldHudgetVoxels(TextFieldHudget* textFieldHudget) : -m_textFieldHudget(textFieldHudget), +m_hudget(textFieldHudget), m_voxelFont(new VoxelFont()) { } TextFieldHudgetVoxels::TextFieldHudgetVoxels(TextFieldHudget* textFieldHudget, std::string content, glm::vec3 direction, float scale) : -m_textFieldHudget(textFieldHudget), +m_hudget(textFieldHudget), m_voxelFont(new VoxelFont()), m_content(content), m_direction(direction), @@ -38,21 +38,21 @@ void TextFieldHudgetVoxels::setContent(std::string content) { void TextFieldHudgetVoxels::draw() { std::vector letters; - m_voxelFont->drawString(m_content, m_textFieldHudget->worldPosition(m_direction), m_textFieldHudget->worldOrientation(m_direction), FontSize::s5x7, m_scale, FontAlign::aCenter); + m_voxelFont->drawString(m_content, m_hudget->worldPosition(m_direction), m_hudget->worldOrientation(m_direction), FontSize::s5x7, m_scale, FontAlign::aCenter); } const glm::vec3 TextFieldHudgetVoxels::upperLeft() const { - return m_textFieldHudget->worldPosition(m_direction) + m_textFieldHudget->worldOrientation(m_direction) * glm::vec3(m_offset + m_width * 0 - m_width / 2, m_height, 0); + return m_hudget->worldPosition(m_direction) + m_hudget->worldOrientation(m_direction) * glm::vec3(m_offset + m_width * 0 - m_width / 2, m_height, 0); } const glm::vec3 TextFieldHudgetVoxels::lowerLeft() const { - return m_textFieldHudget->worldPosition(m_direction) + m_textFieldHudget->worldOrientation(m_direction) * glm::vec3(m_offset + m_width * 0 - m_width / 2, -m_height, 0); + return m_hudget->worldPosition(m_direction) + m_hudget->worldOrientation(m_direction) * glm::vec3(m_offset + m_width * 0 - m_width / 2, -m_height, 0); } const glm::vec3 TextFieldHudgetVoxels::upperRight() const { - return m_textFieldHudget->worldPosition(m_direction) + m_textFieldHudget->worldOrientation(m_direction) * glm::vec3(m_offset + m_width * m_content.length() - m_width / 2, m_height, 0); + return m_hudget->worldPosition(m_direction) + m_hudget->worldOrientation(m_direction) * glm::vec3(m_offset + m_width * m_content.length() - m_width / 2, m_height, 0); } const glm::vec3 TextFieldHudgetVoxels::lowerRight() const { - return m_textFieldHudget->worldPosition(m_direction) + m_textFieldHudget->worldOrientation(m_direction) * glm::vec3(m_offset + m_width * m_content.length() - m_width / 2, -m_height, 0); + return m_hudget->worldPosition(m_direction) + m_hudget->worldOrientation(m_direction) * glm::vec3(m_offset + m_width * m_content.length() - m_width / 2, -m_height, 0); } bool TextFieldHudgetVoxels::isAt(const Ray& ray) const { diff --git a/src/ui/hud/textfieldhudgetvoxels.h b/src/ui/hud/textfieldhudgetvoxels.h index e2598969..77579057 100644 --- a/src/ui/hud/textfieldhudgetvoxels.h +++ b/src/ui/hud/textfieldhudgetvoxels.h @@ -13,9 +13,9 @@ class TextFieldHudgetVoxels{ TextFieldHudgetVoxels(TextFieldHudget* textFieldHudget); TextFieldHudgetVoxels(TextFieldHudget* textFieldHudget, std::string content, glm::vec3 direction, float scale); - void setContent(std::string content); + virtual void setContent(std::string content); - virtual void update(float deltaSec); + //virtual void update(float deltaSec); virtual void draw(); virtual bool isAt(const Ray& ray) const; @@ -32,7 +32,7 @@ class TextFieldHudgetVoxels{ const glm::vec3 upperRight() const; const glm::vec3 lowerRight() const; - TextFieldHudget* m_textFieldHudget; + TextFieldHudget* m_hudget; std::string m_content; VoxelFont* m_voxelFont; glm::vec3 m_direction; From 17c67365a80287327c34a0260c28469a52fd6394 Mon Sep 17 00:00:00 2001 From: gersseba Date: Sat, 8 Mar 2014 21:17:43 +0100 Subject: [PATCH 03/21] wip --- src/ui/hud/buttonhudget.cpp | 9 +++---- src/ui/hud/buttonhudget.h | 6 +++-- src/ui/hud/buttonhudgetvoxels.cpp | 39 ++++++++++++------------------- src/ui/hud/buttonhudgetvoxels.h | 3 +-- src/ui/hud/callback.cpp | 0 src/ui/hud/callback.h | 11 +++++++++ src/ui/hud/hud.cpp | 4 ++-- src/ui/hud/hud.h | 6 ++++- 8 files changed, 43 insertions(+), 35 deletions(-) create mode 100644 src/ui/hud/callback.cpp create mode 100644 src/ui/hud/callback.h diff --git a/src/ui/hud/buttonhudget.cpp b/src/ui/hud/buttonhudget.cpp index f25dcf0b..1f559a6d 100644 --- a/src/ui/hud/buttonhudget.cpp +++ b/src/ui/hud/buttonhudget.cpp @@ -2,7 +2,7 @@ #include "hud.h" #include "buttonhudgetvoxels.h" - +#include "callback.h" ButtonHudget::ButtonHudget(HUD* hud, std::string content, glm::vec3 direction) : TextFieldHudget(hud,content,direction), @@ -28,11 +28,12 @@ bool ButtonHudget::isAt(const Ray& ray) const { } void ButtonHudget::onClick(ClickType clickType) { - callback(clickType); + (m_hud->*callback)(clickType); } -void ButtonHudget::registerCallback(void(*callbackFunction)(ClickType clickType)) { - callback = callbackFunction; +void ButtonHudget::registerCallback(void(HUD::*callbackFunction)(ClickType clickType)) { + (m_hud->*callbackFunction)(ClickType::Selection); + //callback = callbackFunction; } void ButtonHudget::setContent(std::string content) { diff --git a/src/ui/hud/buttonhudget.h b/src/ui/hud/buttonhudget.h index d1bcfb63..661600a9 100644 --- a/src/ui/hud/buttonhudget.h +++ b/src/ui/hud/buttonhudget.h @@ -7,6 +7,7 @@ #include "textfieldhudget.h" class ButtonHudgetVoxels; +class Callback; class ButtonHudget : public TextFieldHudget { public: @@ -23,11 +24,12 @@ class ButtonHudget : public TextFieldHudget { virtual void setContent(std::string content); - void registerCallback(void(*callbackFunction)(ClickType clickType)); + void registerCallback(void(HUD::*callbackFunction)(ClickType clickType)); protected: - void(*callback)(ClickType clicktype); + void(HUD::*callback)(ClickType clicktype); std::string m_content; std::unique_ptr m_voxels; + std::unique_ptr m_callback; }; diff --git a/src/ui/hud/buttonhudgetvoxels.cpp b/src/ui/hud/buttonhudgetvoxels.cpp index 410721c7..c3824b34 100644 --- a/src/ui/hud/buttonhudgetvoxels.cpp +++ b/src/ui/hud/buttonhudgetvoxels.cpp @@ -8,8 +8,7 @@ ButtonHudgetVoxels::ButtonHudgetVoxels(ButtonHudget* buttonHudget, std::string content, glm::vec3 direction, float scale) : TextFieldHudgetVoxels(buttonHudget, content, direction, scale), -m_horizontalBounds(new VoxelCluster(scale)), -m_verticalBounds(new VoxelCluster(scale)) +m_buttonVoxels(new VoxelCluster(scale)) { setContent(content); } @@ -17,34 +16,26 @@ m_verticalBounds(new VoxelCluster(scale)) ButtonHudgetVoxels::~ButtonHudgetVoxels() = default; void ButtonHudgetVoxels::updateBounds() { - delete m_horizontalBounds; - m_horizontalBounds = (new VoxelCluster(m_scale)); - delete m_verticalBounds; - m_verticalBounds = (new VoxelCluster(m_scale)); - int width = (int)(m_width/m_scale)*m_content.size(); - int height = (int)(m_height/m_scale)*2; + delete m_buttonVoxels; + m_buttonVoxels = (new VoxelCluster(m_scale)); + int width = (int)(m_width/m_scale)*m_content.size()+1; + int height = (int)(m_height/m_scale)*2+1; for (int i = 0; i < width; i++) { - m_horizontalBounds->addVoxel(new Voxel(glm::ivec3(i, 0, 0), 0x0FF00F)); - } - for (int i = 0; i < height; i++) { - m_verticalBounds->addVoxel(new Voxel(glm::ivec3(0, i, 0), 0x0FF00F)); + 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 { + // draw only bounds + } + } } } void ButtonHudgetVoxels::draw() { + m_buttonVoxels->transform().setPosition(lowerLeft()); + m_buttonVoxels->transform().setOrientation(m_hudget->worldOrientation(m_direction)); + VoxelRenderer::instance()->draw(*m_buttonVoxels); TextFieldHudgetVoxels::draw(); - m_horizontalBounds->transform().setPosition(upperLeft()); - m_horizontalBounds->transform().setOrientation(m_hudget->worldOrientation(m_direction)); - VoxelRenderer::instance()->draw(*m_horizontalBounds); - m_horizontalBounds->transform().setPosition(lowerLeft()); - m_horizontalBounds->transform().setOrientation(m_hudget->worldOrientation(m_direction)); - VoxelRenderer::instance()->draw(*m_horizontalBounds); - m_verticalBounds->transform().setPosition(lowerLeft()); - m_verticalBounds->transform().setOrientation(m_hudget->worldOrientation(m_direction)); - VoxelRenderer::instance()->draw(*m_verticalBounds); - m_verticalBounds->transform().setPosition(lowerRight()); - m_verticalBounds->transform().setOrientation(m_hudget->worldOrientation(m_direction)); - VoxelRenderer::instance()->draw(*m_verticalBounds); } void ButtonHudgetVoxels::setContent(std::string content) { diff --git a/src/ui/hud/buttonhudgetvoxels.h b/src/ui/hud/buttonhudgetvoxels.h index 99403759..e1cda368 100644 --- a/src/ui/hud/buttonhudgetvoxels.h +++ b/src/ui/hud/buttonhudgetvoxels.h @@ -26,8 +26,7 @@ class ButtonHudgetVoxels : public TextFieldHudgetVoxels { //virtual bool isAt(const Ray& ray) const override; protected: - VoxelCluster* m_horizontalBounds; - VoxelCluster* m_verticalBounds; + VoxelCluster* m_buttonVoxels; }; diff --git a/src/ui/hud/callback.cpp b/src/ui/hud/callback.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/ui/hud/callback.h b/src/ui/hud/callback.h new file mode 100644 index 00000000..5380dd09 --- /dev/null +++ b/src/ui/hud/callback.h @@ -0,0 +1,11 @@ + +enum ClickType; + +class Callback { +public: + Callback(); + + virtual void onClickCallback(ClickType clickType); + virtual void onMouseOverCallback(); + +}; \ No newline at end of file diff --git a/src/ui/hud/hud.cpp b/src/ui/hud/hud.cpp index f64209ba..140f0ebf 100644 --- a/src/ui/hud/hud.cpp +++ b/src/ui/hud/hud.cpp @@ -56,7 +56,7 @@ HUD::HUD(Player* player, Viewer* viewer): m_hudgets.push_back(m_aimHelper.get()); m_hudgets.push_back(m_targetName.get()); m_hudgets.push_back(m_speedLabel.get()); - //m_targetName->registerCallback(&callback); + m_targetName->registerCallback(&HUD::helloFunction); } HUD::~HUD() = default; @@ -235,6 +235,6 @@ float HUD::fovx() const { return m_fovx; } -void HUD::callback(ClickType clicktype) { +void HUD::helloFunction(ClickType clicktype) { printf("callback"); } diff --git a/src/ui/hud/hud.h b/src/ui/hud/hud.h index 131842ee..0c6f90b2 100644 --- a/src/ui/hud/hud.h +++ b/src/ui/hud/hud.h @@ -10,6 +10,7 @@ #include "property/property.h" #include "worldobject/handle/handle.h" +#include "callback.h" enum class ClickType { None, @@ -89,6 +90,9 @@ class HUD { void updateScanner(float deltaSec); void updateFov(); - void callback(ClickType clicktype); + void helloFunction(ClickType clicktype); }; +class HUDCallback : public Callback { + virtual void onClickCallback(ClickType clickType) override; +}; From 6abe92d9cc4f4e08d5ba46e1317f950d63eb1fc6 Mon Sep 17 00:00:00 2001 From: gersseba Date: Sun, 16 Mar 2014 13:19:07 +0100 Subject: [PATCH 04/21] update glow --- lib/glow | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/glow b/lib/glow index 6efb0d44..2f13db1b 160000 --- a/lib/glow +++ b/lib/glow @@ -1 +1 @@ -Subproject commit 6efb0d449271979e75c40a458070e4aa54b6c1de +Subproject commit 2f13db1bbeb5aef9c2326c16983a9460da1ca5cc From de7421f8d1754b3d581db35b558d72ea23011ca4 Mon Sep 17 00:00:00 2001 From: gersseba Date: Mon, 17 Mar 2014 23:10:30 +0100 Subject: [PATCH 05/21] wip --- src/ui/hud/buttonhudget.cpp | 22 ++++++++--------- src/ui/hud/buttonhudget.h | 16 ++++++------ src/ui/hud/buttonhudgetvoxels.cpp | 24 ++++++++++-------- src/ui/hud/buttonhudgetvoxels.h | 12 +++------ src/ui/hud/callback.cpp | 0 src/ui/hud/callback.h | 11 --------- src/ui/hud/hud.cpp | 10 +++++--- src/ui/hud/hud.h | 8 ++---- src/ui/hud/textfieldhudgetvoxels.cpp | 37 ++++++++-------------------- src/ui/hud/textfieldhudgetvoxels.h | 15 +++++------ src/ui/voxelfont.cpp | 4 +-- src/world/world.cpp | 18 +++++++++++++- src/world/world.h | 9 +++++++ 13 files changed, 92 insertions(+), 94 deletions(-) delete mode 100644 src/ui/hud/callback.cpp delete mode 100644 src/ui/hud/callback.h diff --git a/src/ui/hud/buttonhudget.cpp b/src/ui/hud/buttonhudget.cpp index b01edec3..23aeba22 100644 --- a/src/ui/hud/buttonhudget.cpp +++ b/src/ui/hud/buttonhudget.cpp @@ -2,11 +2,12 @@ #include "hud.h" #include "buttonhudgetvoxels.h" -#include "callback.h" -ButtonHudget::ButtonHudget(HUD* hud, glm::vec3 direction, float scale = 0.5f, std::string content = "", FontSize fontSize = FontSize::SIZE5x7) : -TextFieldHudget(hud, direction,scale,content,fontSize), -m_voxels(new ButtonHudgetVoxels(this, content, direction, scale)) { +ButtonHudget::ButtonHudget(HUD* hud, glm::vec3 direction, float scale, std::string content, FontSize fontSize, bool bounds) : +Hudget(hud), +m_buttonVoxels(new ButtonHudgetVoxels(this, direction, scale, content, fontSize, bounds)) +{ + m_buttonVoxels->updateBounds(); } ButtonHudget::~ButtonHudget() = default; @@ -15,22 +16,21 @@ void ButtonHudget::update(float deltaSec) { } void ButtonHudget::draw() { - m_voxels->draw(); + m_buttonVoxels->draw(); } bool ButtonHudget::isAt(const Ray& ray) const { - return m_voxels->isAt(ray); + return m_buttonVoxels->isAt(ray); } void ButtonHudget::onClick(ClickType clickType) { - (m_hud->*callback)(clickType); + m_callback(clickType); } -void ButtonHudget::registerCallback(void(HUD::*callbackFunction)(ClickType clickType)) { - (m_hud->*callbackFunction)(ClickType::Selection); - //callback = callbackFunction; +void ButtonHudget::registerCallback(std::function& callback) { + m_callback = callback; } void ButtonHudget::setContent(std::string content) { - m_voxels->setContent(content); + m_buttonVoxels->setContent(content); } \ No newline at end of file diff --git a/src/ui/hud/buttonhudget.h b/src/ui/hud/buttonhudget.h index d31c5196..de255faa 100644 --- a/src/ui/hud/buttonhudget.h +++ b/src/ui/hud/buttonhudget.h @@ -2,16 +2,17 @@ #include #include +#include #include "hudget.h" -#include "textfieldhudget.h" +#include "ui/voxelfontconstants.h" class ButtonHudgetVoxels; -class Callback; +class TextFieldHudgetVoxels; -class ButtonHudget : public TextFieldHudget { +class ButtonHudget : public Hudget{ public: - ButtonHudget(HUD* hud, glm::vec3 direction, float scale = 0.5f, std::string content = "", FontSize fontSize = FontSize::SIZE5x7); + ButtonHudget(HUD* hud, glm::vec3 direction, float scale = 0.5f, std::string content = "", FontSize fontSize = FontSize::SIZE5x7, bool bounds = true); virtual ~ButtonHudget(); virtual void update(float deltaSec) override; @@ -23,12 +24,11 @@ class ButtonHudget : public TextFieldHudget { virtual void setContent(std::string content); - void registerCallback(void(HUD::*callbackFunction)(ClickType clickType)); + void registerCallback(std::function& callback); protected: - void(HUD::*callback)(ClickType clicktype); + std::function m_callback; std::string m_content; - std::unique_ptr m_voxels; - std::unique_ptr m_callback; + std::unique_ptr m_buttonVoxels; }; diff --git a/src/ui/hud/buttonhudgetvoxels.cpp b/src/ui/hud/buttonhudgetvoxels.cpp index c3824b34..1ecb30bd 100644 --- a/src/ui/hud/buttonhudgetvoxels.cpp +++ b/src/ui/hud/buttonhudgetvoxels.cpp @@ -6,9 +6,11 @@ #include "voxel/voxelrenderer.h" -ButtonHudgetVoxels::ButtonHudgetVoxels(ButtonHudget* buttonHudget, std::string content, glm::vec3 direction, float scale) : -TextFieldHudgetVoxels(buttonHudget, content, direction, scale), -m_buttonVoxels(new VoxelCluster(scale)) +ButtonHudgetVoxels::ButtonHudgetVoxels(ButtonHudget* buttonHudget, glm::vec3 direction, float scale, std::string content, FontSize fontSize, bool bounds) : +TextFieldHudgetVoxels(buttonHudget, direction, scale, content, fontSize), +m_buttonVoxels(new VoxelCluster(scale)), +m_bounds(bounds), +m_hudget(buttonHudget) { setContent(content); } @@ -16,25 +18,27 @@ m_buttonVoxels(new VoxelCluster(scale)) ButtonHudgetVoxels::~ButtonHudgetVoxels() = default; void ButtonHudgetVoxels::updateBounds() { - delete m_buttonVoxels; - m_buttonVoxels = (new VoxelCluster(m_scale)); + m_buttonVoxels.reset(new VoxelCluster(m_scale)); int width = (int)(m_width/m_scale)*m_content.size()+1; - int height = (int)(m_height/m_scale)*2+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 { - // draw only bounds + m_buttonVoxels->addVoxel(new Voxel(glm::ivec3(i, j, 1), 0x17012D)); } } } } void ButtonHudgetVoxels::draw() { - m_buttonVoxels->transform().setPosition(lowerLeft()); - m_buttonVoxels->transform().setOrientation(m_hudget->worldOrientation(m_direction)); - VoxelRenderer::instance()->draw(*m_buttonVoxels); + if (m_bounds) { + 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))); + VoxelRenderer::instance()->draw(*m_buttonVoxels); + } TextFieldHudgetVoxels::draw(); } diff --git a/src/ui/hud/buttonhudgetvoxels.h b/src/ui/hud/buttonhudgetvoxels.h index e1cda368..11d44947 100644 --- a/src/ui/hud/buttonhudgetvoxels.h +++ b/src/ui/hud/buttonhudgetvoxels.h @@ -11,22 +11,18 @@ class VoxelCluster; class ButtonHudgetVoxels : public TextFieldHudgetVoxels { public: - ButtonHudgetVoxels(ButtonHudget* textFieldHudget); - ButtonHudgetVoxels(ButtonHudget* textFieldHudget, std::string content, glm::vec3 direction, float scale); + ButtonHudgetVoxels(ButtonHudget* textFieldHudget, glm::vec3 direction, float scale = 0.5f, std::string content = "", FontSize fontSize = FontSize::SIZE5x7, bool bounds = true); ~ButtonHudgetVoxels(); void setContent(std::string content); - //void update(float deltaSec); - void updateBounds(); virtual void draw() override; - //virtual bool isAt(const Ray& ray) const override; - protected: - VoxelCluster* m_buttonVoxels; - + std::unique_ptr m_buttonVoxels; + bool m_bounds; + Hudget* m_hudget; }; diff --git a/src/ui/hud/callback.cpp b/src/ui/hud/callback.cpp deleted file mode 100644 index e69de29b..00000000 diff --git a/src/ui/hud/callback.h b/src/ui/hud/callback.h deleted file mode 100644 index 0543486c..00000000 --- a/src/ui/hud/callback.h +++ /dev/null @@ -1,11 +0,0 @@ - -#include "ui/clicktype.h" - -class Callback { -public: - Callback(); - - virtual void onClickCallback(ClickType clickType); - virtual void onMouseOverCallback(); - -}; \ No newline at end of file diff --git a/src/ui/hud/hud.cpp b/src/ui/hud/hud.cpp index 25a59e45..957bccda 100644 --- a/src/ui/hud/hud.cpp +++ b/src/ui/hud/hud.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -47,8 +48,9 @@ HUD::HUD(Player* player, Viewer* viewer): m_crossHair(new CrossHair(this)), m_aimHelper(new AimHelperHudget(this)), m_scanner(new WorldTreeScanner()), - m_targetName(new ButtonHudget(this, glm::normalize(glm::vec3(0, -1.1f, -2)), 0.025f, "")), + m_targetName(new TextFieldHudget(this, glm::normalize(glm::vec3(0, -1.1f, -2)), 0.025f, "")), m_speedLabel(new TextFieldHudget(this, glm::normalize(glm::vec3(1.5f, -1.1f, -2)), 0.020f, "")), + m_menuButton(new ButtonHudget(this, glm::normalize(glm::vec3(-1.5f, 1.1f, -2)), 0.01f, "MENU")), m_target(nullptr) { m_scanner->setScanRadius(1050.0f); @@ -56,7 +58,9 @@ HUD::HUD(Player* player, Viewer* viewer): m_hudgets.push_back(m_aimHelper.get()); m_hudgets.push_back(m_targetName.get()); m_hudgets.push_back(m_speedLabel.get()); - m_targetName->registerCallback(&HUD::helloFunction); + m_hudgets.push_back(m_menuButton.get()); + std::function callbackFunction = std::bind(&HUD::helloFunction, this, std::placeholders::_1); + m_menuButton->registerCallback(callbackFunction); } HUD::~HUD() = default; @@ -238,5 +242,5 @@ float HUD::fovx() const { } void HUD::helloFunction(ClickType clicktype) { - printf("callback"); + World::instance()->showText("new Text", this); } diff --git a/src/ui/hud/hud.h b/src/ui/hud/hud.h index 41925496..d64b5d4b 100644 --- a/src/ui/hud/hud.h +++ b/src/ui/hud/hud.h @@ -10,7 +10,6 @@ #include "property/property.h" #include "worldobject/handle/handle.h" -#include "callback.h" #include "ui/clicktype.h" class Player; @@ -76,7 +75,8 @@ class HUD { std::unique_ptr m_crossHair; std::unique_ptr m_scanner; std::unique_ptr m_speedLabel; - std::unique_ptr m_targetName; + std::unique_ptr m_targetName; + std::unique_ptr m_menuButton; std::list m_hudgets; @@ -87,7 +87,3 @@ class HUD { void helloFunction(ClickType clicktype); }; - -class HUDCallback : public Callback { - virtual void onClickCallback(ClickType clickType) override; -}; diff --git a/src/ui/hud/textfieldhudgetvoxels.cpp b/src/ui/hud/textfieldhudgetvoxels.cpp index 0c0376e1..aecd914b 100644 --- a/src/ui/hud/textfieldhudgetvoxels.cpp +++ b/src/ui/hud/textfieldhudgetvoxels.cpp @@ -12,8 +12,8 @@ #include "utils/geometryhelper.h" -TextFieldHudgetVoxels::TextFieldHudgetVoxels(TextFieldHudget* textFieldHudget, glm::vec3 direction, float scale, std::string content, FontSize fontSize) : -m_textFieldHudget(textFieldHudget), +TextFieldHudgetVoxels::TextFieldHudgetVoxels(Hudget* textFieldHudget, glm::vec3 direction, float scale, std::string content, FontSize fontSize) : +m_hudget(textFieldHudget), m_voxelFont(VoxelFont::instance()), m_content(content), m_direction(direction), @@ -21,35 +21,19 @@ m_scale(scale), m_fontSize(fontSize) { m_width = m_voxelFont->letterWidth(fontSize) * m_scale; - m_height = m_voxelFont->letterWidth(fontSize) * m_scale; + m_height = m_voxelFont->letterHeight(fontSize) * m_scale; m_offset = -1.f * ((m_content.length() - 1) / 2.0f) * m_width; } +TextFieldHudgetVoxels::~TextFieldHudgetVoxels() = default; + void TextFieldHudgetVoxels::setContent(std::string content) { m_content = content; m_offset = -1.f * ((m_content.length() - 1) / 2.0f) * m_width; } void TextFieldHudgetVoxels::draw() { -<<<<<<< HEAD - std::vector letters; - m_voxelFont->drawString(m_content, m_hudget->worldPosition(m_direction), m_hudget->worldOrientation(m_direction), FontSize::s5x7, m_scale, FontAlign::aCenter); -} - -const glm::vec3 TextFieldHudgetVoxels::upperLeft() const { - return m_hudget->worldPosition(m_direction) + m_hudget->worldOrientation(m_direction) * glm::vec3(m_offset + m_width * 0 - m_width / 2, m_height, 0); -} - -const glm::vec3 TextFieldHudgetVoxels::lowerLeft() const { - return m_hudget->worldPosition(m_direction) + m_hudget->worldOrientation(m_direction) * glm::vec3(m_offset + m_width * 0 - m_width / 2, -m_height, 0); -} -const glm::vec3 TextFieldHudgetVoxels::upperRight() const { - return m_hudget->worldPosition(m_direction) + m_hudget->worldOrientation(m_direction) * glm::vec3(m_offset + m_width * m_content.length() - m_width / 2, m_height, 0); -} -const glm::vec3 TextFieldHudgetVoxels::lowerRight() const { - return m_hudget->worldPosition(m_direction) + m_hudget->worldOrientation(m_direction) * glm::vec3(m_offset + m_width * m_content.length() - m_width / 2, -m_height, 0); -======= - m_voxelFont->drawString(m_content, m_textFieldHudget->worldPosition(m_direction), m_textFieldHudget->worldOrientation(m_direction), m_fontSize, m_scale, FontAlign::CENTER); + m_voxelFont->drawString(m_content, worldPosition(), worldOrientation(), m_fontSize, m_scale, FontAlign::CENTER); } const glm::vec3 TextFieldHudgetVoxels::upperLeft() const { @@ -64,7 +48,6 @@ const glm::vec3 TextFieldHudgetVoxels::upperRight() const { } const glm::vec3 TextFieldHudgetVoxels::lowerRight() const { return worldPosition() + worldOrientation() * offsetToCenter(false, false); ->>>>>>> b23ef0a00b4532a08ff62d7ce822c1de3ac81bf6 } bool TextFieldHudgetVoxels::isAt(const Ray& ray) const { @@ -86,9 +69,9 @@ float TextFieldHudgetVoxels::scale() { const glm::vec3 TextFieldHudgetVoxels::offsetToCenter(bool upper, bool left) const { float horizontalOffset, verticalOffset; if (left) { - horizontalOffset = (float)m_content.length(); - } else { horizontalOffset = 0; + } else { + horizontalOffset = (float)m_content.length(); } if (upper) { verticalOffset = m_height; @@ -100,9 +83,9 @@ const glm::vec3 TextFieldHudgetVoxels::offsetToCenter(bool upper, bool left) con } 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); } \ No newline at end of file diff --git a/src/ui/hud/textfieldhudgetvoxels.h b/src/ui/hud/textfieldhudgetvoxels.h index c5d8ce05..22899295 100644 --- a/src/ui/hud/textfieldhudgetvoxels.h +++ b/src/ui/hud/textfieldhudgetvoxels.h @@ -11,11 +11,12 @@ class VoxelFont; class TextFieldHudgetVoxels{ public: - TextFieldHudgetVoxels(TextFieldHudget* textFieldHudget, glm::vec3 direction, float scale = 0.5f, std::string content = "", FontSize fontSize = FontSize::SIZE5x7); + TextFieldHudgetVoxels(Hudget* textFieldHudget, glm::vec3 direction, float scale = 0.5f, std::string content = "", FontSize fontSize = FontSize::SIZE5x7); + ~TextFieldHudgetVoxels(); virtual void setContent(std::string content); - //virtual void update(float deltaSec); + virtual void draw(); virtual bool isAt(const Ray& ray) const; @@ -25,12 +26,12 @@ class TextFieldHudgetVoxels{ float scale(); protected: - const glm::vec3 upperLeft() const; - const glm::vec3 lowerLeft() const; - const glm::vec3 upperRight() const; - const glm::vec3 lowerRight() const; + virtual const glm::vec3 upperLeft() const; + virtual const glm::vec3 lowerLeft() const; + virtual const glm::vec3 upperRight() const; + virtual const glm::vec3 lowerRight() const; - TextFieldHudget* m_hudget; + Hudget* m_hudget; glm::vec3 worldPosition() const; glm::quat worldOrientation() const; diff --git a/src/ui/voxelfont.cpp b/src/ui/voxelfont.cpp index e556a95d..0c0143ad 100644 --- a/src/ui/voxelfont.cpp +++ b/src/ui/voxelfont.cpp @@ -91,9 +91,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); } diff --git a/src/world/world.cpp b/src/world/world.cpp index 5f6b06d6..5eb2f63e 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -9,6 +9,9 @@ #include "worldobject/ship.h" #include "worldobject/worldobject.h" +#include "ui/hud/textfieldhudget.h" +#include "ui/hud/hud.h" + #include "skybox.h" #include "worldlogic.h" @@ -24,8 +27,11 @@ World::World(): m_god(new God(*this)), m_particleEngine(new VoxelParticleEngine()), m_factionMatrix(new FactionMatrix()), - m_deltaSec(0.0f) + m_deltaSec(0.0f), + m_textHudget(new TextFieldHudget(nullptr, glm::normalize(glm::vec3(0,0.05f,-1)),0.03f)) { + m_textLifeTime = 0.0f; + m_textTimer = 0.0f; } World::~World() { @@ -73,6 +79,11 @@ void World::update(float deltaSecs) { for (WorldObject *worldObject : m_worldObjects) { worldObject->update(deltaSecs); } + + if (m_textTimer < m_textLifeTime) { + m_textTimer += deltaSecs; + m_textHudget->draw(); + } } float World::deltaSec() const { @@ -113,3 +124,8 @@ void World::removeWorldObject(WorldObject* worldObject) { } } +void World::showText(std::string text, HUD* hud, float lifeTime) { + m_textHudget.reset(new TextFieldHudget(hud, glm::normalize(glm::vec3(0, 0.05f, -1)), 0.03f, text)); + m_textLifeTime = lifeTime; + m_textTimer = 0; +} \ No newline at end of file diff --git a/src/world/world.h b/src/world/world.h index 2df88028..8f92c702 100644 --- a/src/world/world.h +++ b/src/world/world.h @@ -12,6 +12,8 @@ class VoxelParticleEngine; class WorldObject; class WorldLogic; class WorldTree; +class TextFieldHudget; +class HUD; class World { public: @@ -35,6 +37,8 @@ class World { static World *instance(); static void reset(); + void showText(std::string text, HUD* hud, float lifeTime = 2.0f); + protected: friend class God; @@ -55,6 +59,11 @@ class World { std::unique_ptr m_particleEngine; std::unique_ptr m_factionMatrix; + std::unique_ptr m_textHudget; + float m_textLifeTime; + float m_textTimer; + + std::unordered_set m_worldObjects; std::unordered_set m_ships; From c483e2bcbf5e5a1939c66142e6524d2307d88b2d Mon Sep 17 00:00:00 2001 From: gersseba Date: Sun, 30 Mar 2014 21:52:54 +0200 Subject: [PATCH 06/21] added assertion and constuctor with callback --- src/ui/hud/buttonhudget.cpp | 6 ++++-- src/ui/hud/buttonhudget.h | 2 +- src/ui/hud/hud.cpp | 9 +++------ src/ui/hud/hud.h | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/ui/hud/buttonhudget.cpp b/src/ui/hud/buttonhudget.cpp index 23aeba22..8c1c4a90 100644 --- a/src/ui/hud/buttonhudget.cpp +++ b/src/ui/hud/buttonhudget.cpp @@ -3,9 +3,10 @@ #include "hud.h" #include "buttonhudgetvoxels.h" -ButtonHudget::ButtonHudget(HUD* hud, glm::vec3 direction, float scale, std::string content, FontSize fontSize, bool bounds) : +ButtonHudget::ButtonHudget(HUD* hud, glm::vec3 direction, std::function& callback, float scale, std::string content, FontSize fontSize, bool bounds) : Hudget(hud), -m_buttonVoxels(new ButtonHudgetVoxels(this, direction, scale, content, fontSize, bounds)) +m_buttonVoxels(new ButtonHudgetVoxels(this, direction, scale, content, fontSize, bounds)), +m_callback(callback) { m_buttonVoxels->updateBounds(); } @@ -24,6 +25,7 @@ bool ButtonHudget::isAt(const Ray& ray) const { } void ButtonHudget::onClick(ClickType clickType) { + assert(m_callback); m_callback(clickType); } diff --git a/src/ui/hud/buttonhudget.h b/src/ui/hud/buttonhudget.h index de255faa..a049607c 100644 --- a/src/ui/hud/buttonhudget.h +++ b/src/ui/hud/buttonhudget.h @@ -12,7 +12,7 @@ class TextFieldHudgetVoxels; class ButtonHudget : public Hudget{ public: - ButtonHudget(HUD* hud, glm::vec3 direction, float scale = 0.5f, std::string content = "", FontSize fontSize = FontSize::SIZE5x7, bool bounds = true); + ButtonHudget(HUD* hud, glm::vec3 direction, std::function& callback, float scale = 0.5f, std::string content = "", FontSize fontSize = FontSize::SIZE5x7, bool bounds = true); virtual ~ButtonHudget(); virtual void update(float deltaSec) override; diff --git a/src/ui/hud/hud.cpp b/src/ui/hud/hud.cpp index 2e2df04c..fbd4085c 100644 --- a/src/ui/hud/hud.cpp +++ b/src/ui/hud/hud.cpp @@ -50,8 +50,7 @@ HUD::HUD(Player* player): m_scanner(new WorldTreeScanner()), m_targetName(new TextFieldHudget(this, glm::normalize(glm::vec3(0, -1.1f, -2)), 0.025f, "")), m_speedLabel(new TextFieldHudget(this, glm::normalize(glm::vec3(1.5f, -1.1f, -2)), 0.020f, "")), - m_menuButton(new ButtonHudget(this, glm::normalize(glm::vec3(-1.5f, 1.1f, -2)), 0.01f, "MENU")), - m_target(nullptr) + m_menuButton(new ButtonHudget(this, glm::normalize(glm::vec3(-1.5f, 1.1f, -2)), (std::function)std::bind(&HUD::openMenu, this, std::placeholders::_1), 0.01f, "MENU")), m_target(nullptr), m_drawHud("vfx.drawhud") { @@ -61,8 +60,6 @@ HUD::HUD(Player* player): m_hudgets.push_back(m_targetName.get()); m_hudgets.push_back(m_speedLabel.get()); m_hudgets.push_back(m_menuButton.get()); - std::function callbackFunction = std::bind(&HUD::helloFunction, this, std::placeholders::_1); - m_menuButton->registerCallback(callbackFunction); } HUD::~HUD() = default; @@ -248,8 +245,8 @@ float HUD::fovx() const { return m_fovx; } -void HUD::helloFunction(ClickType clicktype) { - World::instance()->showText("new Text", this); +void HUD::openMenu(ClickType clicktype) { + glow::debug("Not yet implemented"); } void HUD::setViewer(Viewer& viewer) { diff --git a/src/ui/hud/hud.h b/src/ui/hud/hud.h index 6d8341e4..5dc2b6a8 100644 --- a/src/ui/hud/hud.h +++ b/src/ui/hud/hud.h @@ -89,5 +89,5 @@ class HUD { void updateScanner(float deltaSec); void updateFov(); - void helloFunction(ClickType clicktype); + void openMenu(ClickType clicktype); }; From 30cbecb1f347adffcb78c5436fe2c6623c0635ac Mon Sep 17 00:00:00 2001 From: gersseba Date: Sun, 30 Mar 2014 22:19:57 +0200 Subject: [PATCH 07/21] fix const HUD issue --- src/ui/hud/buttonhudget.cpp | 2 +- src/ui/hud/buttonhudget.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui/hud/buttonhudget.cpp b/src/ui/hud/buttonhudget.cpp index 8c1c4a90..7940e381 100644 --- a/src/ui/hud/buttonhudget.cpp +++ b/src/ui/hud/buttonhudget.cpp @@ -3,7 +3,7 @@ #include "hud.h" #include "buttonhudgetvoxels.h" -ButtonHudget::ButtonHudget(HUD* hud, glm::vec3 direction, std::function& callback, float scale, std::string content, FontSize fontSize, bool bounds) : +ButtonHudget::ButtonHudget(const HUD* hud, glm::vec3 direction, std::function& callback, float scale, std::string content, FontSize fontSize, bool bounds) : Hudget(hud), m_buttonVoxels(new ButtonHudgetVoxels(this, direction, scale, content, fontSize, bounds)), m_callback(callback) diff --git a/src/ui/hud/buttonhudget.h b/src/ui/hud/buttonhudget.h index a049607c..7914f058 100644 --- a/src/ui/hud/buttonhudget.h +++ b/src/ui/hud/buttonhudget.h @@ -12,7 +12,7 @@ class TextFieldHudgetVoxels; class ButtonHudget : public Hudget{ public: - ButtonHudget(HUD* hud, glm::vec3 direction, std::function& callback, float scale = 0.5f, std::string content = "", FontSize fontSize = FontSize::SIZE5x7, bool bounds = true); + ButtonHudget(const HUD* hud, glm::vec3 direction, std::function& callback, float scale = 0.5f, std::string content = "", FontSize fontSize = FontSize::SIZE5x7, bool bounds = true); virtual ~ButtonHudget(); virtual void update(float deltaSec) override; From 4cb1f332ec0522cb3958dfc8e2fbafe364b92020 Mon Sep 17 00:00:00 2001 From: gersseba Date: Sun, 30 Mar 2014 23:11:47 +0200 Subject: [PATCH 08/21] fix reference from bind --- src/ui/hud/buttonhudget.cpp | 4 ++-- src/ui/hud/buttonhudget.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ui/hud/buttonhudget.cpp b/src/ui/hud/buttonhudget.cpp index 7940e381..47abc753 100644 --- a/src/ui/hud/buttonhudget.cpp +++ b/src/ui/hud/buttonhudget.cpp @@ -3,7 +3,7 @@ #include "hud.h" #include "buttonhudgetvoxels.h" -ButtonHudget::ButtonHudget(const HUD* hud, glm::vec3 direction, std::function& callback, float scale, std::string content, FontSize fontSize, bool bounds) : +ButtonHudget::ButtonHudget(HUD* hud, glm::vec3 direction, std::function callback, float scale, std::string content, FontSize fontSize, bool bounds) : Hudget(hud), m_buttonVoxels(new ButtonHudgetVoxels(this, direction, scale, content, fontSize, bounds)), m_callback(callback) @@ -29,7 +29,7 @@ void ButtonHudget::onClick(ClickType clickType) { m_callback(clickType); } -void ButtonHudget::registerCallback(std::function& callback) { +void ButtonHudget::registerCallback(std::function callback) { m_callback = callback; } diff --git a/src/ui/hud/buttonhudget.h b/src/ui/hud/buttonhudget.h index 7914f058..8c5c82a6 100644 --- a/src/ui/hud/buttonhudget.h +++ b/src/ui/hud/buttonhudget.h @@ -12,7 +12,7 @@ class TextFieldHudgetVoxels; class ButtonHudget : public Hudget{ public: - ButtonHudget(const HUD* hud, glm::vec3 direction, std::function& callback, float scale = 0.5f, std::string content = "", FontSize fontSize = FontSize::SIZE5x7, bool bounds = true); + ButtonHudget(HUD* hud, glm::vec3 direction, std::function callback, float scale = 0.5f, std::string content = "", FontSize fontSize = FontSize::SIZE5x7, bool bounds = true); virtual ~ButtonHudget(); virtual void update(float deltaSec) override; @@ -24,7 +24,7 @@ class ButtonHudget : public Hudget{ virtual void setContent(std::string content); - void registerCallback(std::function& callback); + void registerCallback(std::function callback); protected: std::function m_callback; From 2025c05f6ca60a64e1ee2d9ca6121f638dd0235e Mon Sep 17 00:00:00 2001 From: Sebastian Gerstenberg Date: Mon, 31 Mar 2014 17:32:02 +0200 Subject: [PATCH 09/21] coding convention --- src/ui/hud/buttonhudget.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ui/hud/buttonhudget.h b/src/ui/hud/buttonhudget.h index 8c5c82a6..0733dde3 100644 --- a/src/ui/hud/buttonhudget.h +++ b/src/ui/hud/buttonhudget.h @@ -7,10 +7,11 @@ #include "hudget.h" #include "ui/voxelfontconstants.h" + class ButtonHudgetVoxels; class TextFieldHudgetVoxels; -class ButtonHudget : public Hudget{ +class ButtonHudget : public Hudget { public: ButtonHudget(HUD* hud, glm::vec3 direction, std::function callback, float scale = 0.5f, std::string content = "", FontSize fontSize = FontSize::SIZE5x7, bool bounds = true); virtual ~ButtonHudget(); From b10a8e4964e651f9a8dc687e815521b823b78322 Mon Sep 17 00:00:00 2001 From: gersseba Date: Mon, 31 Mar 2014 22:05:48 +0200 Subject: [PATCH 10/21] const ref & colors --- src/ui/hud/buttonhudget.cpp | 10 +++++----- src/ui/hud/buttonhudget.h | 4 ++-- src/ui/hud/buttonhudgetvoxels.cpp | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/ui/hud/buttonhudget.cpp b/src/ui/hud/buttonhudget.cpp index 47abc753..4ee7444f 100644 --- a/src/ui/hud/buttonhudget.cpp +++ b/src/ui/hud/buttonhudget.cpp @@ -3,10 +3,10 @@ #include "hud.h" #include "buttonhudgetvoxels.h" -ButtonHudget::ButtonHudget(HUD* hud, glm::vec3 direction, std::function callback, float scale, std::string content, FontSize fontSize, bool bounds) : -Hudget(hud), -m_buttonVoxels(new ButtonHudgetVoxels(this, direction, scale, content, fontSize, bounds)), -m_callback(callback) +ButtonHudget::ButtonHudget(HUD* hud, glm::vec3 direction, const std::function& callback, float scale, std::string content, FontSize fontSize, bool bounds) : + Hudget(hud), + m_buttonVoxels(new ButtonHudgetVoxels(this, direction, scale, content, fontSize, bounds)), + m_callback(callback) { m_buttonVoxels->updateBounds(); } @@ -29,7 +29,7 @@ void ButtonHudget::onClick(ClickType clickType) { m_callback(clickType); } -void ButtonHudget::registerCallback(std::function callback) { +void ButtonHudget::registerCallback(const std::function& callback) { m_callback = callback; } diff --git a/src/ui/hud/buttonhudget.h b/src/ui/hud/buttonhudget.h index 0733dde3..bcfdde15 100644 --- a/src/ui/hud/buttonhudget.h +++ b/src/ui/hud/buttonhudget.h @@ -13,7 +13,7 @@ class TextFieldHudgetVoxels; class ButtonHudget : public Hudget { public: - ButtonHudget(HUD* hud, glm::vec3 direction, std::function callback, float scale = 0.5f, std::string content = "", FontSize fontSize = FontSize::SIZE5x7, bool bounds = true); + ButtonHudget(HUD* hud, glm::vec3 direction, const std::function& callback, float scale = 0.5f, std::string content = "", FontSize fontSize = FontSize::SIZE5x7, bool bounds = true); virtual ~ButtonHudget(); virtual void update(float deltaSec) override; @@ -25,7 +25,7 @@ class ButtonHudget : public Hudget { virtual void setContent(std::string content); - void registerCallback(std::function callback); + void registerCallback(const std::function& callback); protected: std::function m_callback; diff --git a/src/ui/hud/buttonhudgetvoxels.cpp b/src/ui/hud/buttonhudgetvoxels.cpp index 1ecb30bd..31da7038 100644 --- a/src/ui/hud/buttonhudgetvoxels.cpp +++ b/src/ui/hud/buttonhudgetvoxels.cpp @@ -7,10 +7,10 @@ ButtonHudgetVoxels::ButtonHudgetVoxels(ButtonHudget* buttonHudget, glm::vec3 direction, float scale, std::string content, FontSize fontSize, bool bounds) : -TextFieldHudgetVoxels(buttonHudget, direction, scale, content, fontSize), -m_buttonVoxels(new VoxelCluster(scale)), -m_bounds(bounds), -m_hudget(buttonHudget) + TextFieldHudgetVoxels(buttonHudget, direction, scale, content, fontSize), + m_buttonVoxels(new VoxelCluster(scale)), + m_bounds(bounds), + m_hudget(buttonHudget) { setContent(content); } From f9cc792a5507acd79d8d63f074f07c4fdcb2f935 Mon Sep 17 00:00:00 2001 From: gersseba Date: Tue, 1 Apr 2014 00:02:02 +0200 Subject: [PATCH 11/21] adapting to changes in hud from mission script pr --- src/ui/hud/buttonhudget.cpp | 2 +- src/ui/hud/buttonhudgetvoxels.cpp | 10 +++++----- src/ui/hud/buttonhudgetvoxels.h | 2 +- src/ui/hud/hud.cpp | 6 +++--- src/ui/hud/hud.h | 9 +++------ src/ui/hud/textfieldhudgetvoxels.cpp | 27 ++++++++++++++++++++------- src/ui/hud/textfieldhudgetvoxels.h | 8 ++++---- src/world/world.cpp | 6 ------ 8 files changed, 37 insertions(+), 33 deletions(-) diff --git a/src/ui/hud/buttonhudget.cpp b/src/ui/hud/buttonhudget.cpp index 4ee7444f..e5353443 100644 --- a/src/ui/hud/buttonhudget.cpp +++ b/src/ui/hud/buttonhudget.cpp @@ -34,5 +34,5 @@ void ButtonHudget::registerCallback(const std::functionsetContent(content); + m_buttonVoxels->setText(content); } \ No newline at end of file diff --git a/src/ui/hud/buttonhudgetvoxels.cpp b/src/ui/hud/buttonhudgetvoxels.cpp index 31da7038..87949e86 100644 --- a/src/ui/hud/buttonhudgetvoxels.cpp +++ b/src/ui/hud/buttonhudgetvoxels.cpp @@ -12,14 +12,14 @@ ButtonHudgetVoxels::ButtonHudgetVoxels(ButtonHudget* buttonHudget, glm::vec3 dir m_bounds(bounds), m_hudget(buttonHudget) { - setContent(content); + setText(content); } ButtonHudgetVoxels::~ButtonHudgetVoxels() = default; void ButtonHudgetVoxels::updateBounds() { m_buttonVoxels.reset(new VoxelCluster(m_scale)); - int width = (int)(m_width/m_scale)*m_content.size()+1; + 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++) { @@ -42,10 +42,10 @@ void ButtonHudgetVoxels::draw() { TextFieldHudgetVoxels::draw(); } -void ButtonHudgetVoxels::setContent(std::string content) { - if (m_content.compare(content) == 0) { +void ButtonHudgetVoxels::setText(const std::string& text) { + if (m_text.compare(text) == 0) { return; } - TextFieldHudgetVoxels::setContent(content); + TextFieldHudgetVoxels::setText(text); updateBounds(); } \ No newline at end of file diff --git a/src/ui/hud/buttonhudgetvoxels.h b/src/ui/hud/buttonhudgetvoxels.h index 11d44947..cc36f368 100644 --- a/src/ui/hud/buttonhudgetvoxels.h +++ b/src/ui/hud/buttonhudgetvoxels.h @@ -14,7 +14,7 @@ class ButtonHudgetVoxels : public TextFieldHudgetVoxels { ButtonHudgetVoxels(ButtonHudget* textFieldHudget, glm::vec3 direction, float scale = 0.5f, std::string content = "", FontSize fontSize = FontSize::SIZE5x7, bool bounds = true); ~ButtonHudgetVoxels(); - void setContent(std::string content); + virtual void setText(const std::string& text); void updateBounds(); diff --git a/src/ui/hud/hud.cpp b/src/ui/hud/hud.cpp index d900fe09..3891fea8 100644 --- a/src/ui/hud/hud.cpp +++ b/src/ui/hud/hud.cpp @@ -65,12 +65,12 @@ HUD::HUD(Player* player): m_view(nullptr) { m_scanner->setScanRadius(1050.0f); - m_hudgets.push_back(m_targetName.get()); - m_hudgets.push_back(m_speedLabel.get()); - m_hudgets.push_back(m_menuButton.get()); m_elements->addHudget(m_aimHelper); m_elements->addHudget(m_crossHair); + m_elements->addHudget(m_targetName); + m_elements->addHudget(m_speedLabel); + m_elements->addHudget(m_menuButton); } HUD::~HUD() = default; diff --git a/src/ui/hud/hud.h b/src/ui/hud/hud.h index 7597dd43..1422b88f 100644 --- a/src/ui/hud/hud.h +++ b/src/ui/hud/hud.h @@ -84,12 +84,9 @@ class HUD { float m_fovy; float m_fovx; - std::unique_ptr m_aimHelper; - std::unique_ptr m_crossHair; - std::unique_ptr m_scanner; - std::unique_ptr m_speedLabel; - std::unique_ptr m_targetName; - std::unique_ptr m_menuButton; + TextFieldHudget* m_speedLabel; + TextFieldHudget* m_targetName; + ButtonHudget* m_menuButton; CrossHair* m_crossHair; AimHelperHudget* m_aimHelper; diff --git a/src/ui/hud/textfieldhudgetvoxels.cpp b/src/ui/hud/textfieldhudgetvoxels.cpp index 39468603..e833ce08 100644 --- a/src/ui/hud/textfieldhudgetvoxels.cpp +++ b/src/ui/hud/textfieldhudgetvoxels.cpp @@ -12,8 +12,8 @@ #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, float scale, const std::string& text, FontSize fontSize) : + m_hudget(textFieldHudget), m_voxelFont(VoxelFont::instance()), m_text(text), m_direction(direction), @@ -31,7 +31,7 @@ void TextFieldHudgetVoxels::setText(const std::string& text) { } void TextFieldHudgetVoxels::draw() { - m_voxelFont->drawString(m_content, worldPosition(), worldOrientation(), m_fontSize, m_scale, FontAlign::CENTER); + m_voxelFont->drawString(m_text, worldPosition(), worldOrientation(), m_fontSize, m_scale, FontAlign::CENTER); } const glm::vec3 TextFieldHudgetVoxels::upperLeft() const { @@ -67,10 +67,23 @@ 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); + //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); } glm::vec3 TextFieldHudgetVoxels::worldPosition() const { diff --git a/src/ui/hud/textfieldhudgetvoxels.h b/src/ui/hud/textfieldhudgetvoxels.h index bcdb696c..8932c4b1 100644 --- a/src/ui/hud/textfieldhudgetvoxels.h +++ b/src/ui/hud/textfieldhudgetvoxels.h @@ -6,15 +6,14 @@ #include "hudget.h" #include "ui/voxelfontconstants.h" -class TextFieldHudget; +class Hudget; class VoxelFont; class TextFieldHudgetVoxels{ public: - TextFieldHudgetVoxels(TextFieldHudget* textFieldHudget, const glm::vec3& direction, float scale = 0.5f, const std::string& text = "", FontSize fontSize = FontSize::SIZE5x7); - - void setText(const std::string& text); + TextFieldHudgetVoxels(Hudget* textFieldHudget, const glm::vec3& direction, float scale = 0.5f, const std::string& text = "", FontSize fontSize = FontSize::SIZE5x7); + virtual void setText(const std::string& text); virtual void draw(); @@ -25,6 +24,7 @@ class TextFieldHudgetVoxels{ float scale(); protected: + std::string m_text; Hudget* m_hudget; diff --git a/src/world/world.cpp b/src/world/world.cpp index ecae543f..da3abb41 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -169,9 +169,3 @@ void World::printStatus() { glow::info(" VoxelCount: %;", voxelCount); glow::info(" ParticleCount: %;", particleCount); } - -void World::showText(std::string text, HUD* hud, float lifeTime) { - //m_textHudget.reset(new TextFieldHudget(hud, glm::normalize(glm::vec3(0, 0.05f, -1)), 0.03f, text)); - m_textLifeTime = lifeTime; - m_textTimer = 0; -} From 0ffe45dd5c6977f6b96e1aca16d4ef529370b813 Mon Sep 17 00:00:00 2001 From: gersseba Date: Tue, 1 Apr 2014 00:05:00 +0200 Subject: [PATCH 12/21] more changes to fit recent pr --- src/ui/hud/buttonhudget.cpp | 4 ++-- src/ui/hud/buttonhudget.h | 4 ++-- src/ui/hud/textfieldhudgetvoxels.cpp | 4 ---- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/ui/hud/buttonhudget.cpp b/src/ui/hud/buttonhudget.cpp index e5353443..99ae2536 100644 --- a/src/ui/hud/buttonhudget.cpp +++ b/src/ui/hud/buttonhudget.cpp @@ -29,10 +29,10 @@ void ButtonHudget::onClick(ClickType clickType) { m_callback(clickType); } -void ButtonHudget::registerCallback(const std::function& callback) { +void ButtonHudget::setCallback(const std::function& callback) { m_callback = callback; } -void ButtonHudget::setContent(std::string content) { +void ButtonHudget::setText(const std::string& content) { m_buttonVoxels->setText(content); } \ No newline at end of file diff --git a/src/ui/hud/buttonhudget.h b/src/ui/hud/buttonhudget.h index bcfdde15..5d61a41d 100644 --- a/src/ui/hud/buttonhudget.h +++ b/src/ui/hud/buttonhudget.h @@ -23,9 +23,9 @@ class ButtonHudget : public Hudget { virtual void onClick(ClickType clicktype) override; - virtual void setContent(std::string content); + virtual void setText(const std::string& content); - void registerCallback(const std::function& callback); + void setCallback(const std::function& callback); protected: std::function m_callback; diff --git a/src/ui/hud/textfieldhudgetvoxels.cpp b/src/ui/hud/textfieldhudgetvoxels.cpp index e833ce08..4cd3aae6 100644 --- a/src/ui/hud/textfieldhudgetvoxels.cpp +++ b/src/ui/hud/textfieldhudgetvoxels.cpp @@ -80,10 +80,6 @@ const glm::vec3 TextFieldHudgetVoxels::offsetToCenter(bool upper, bool left) con } return glm::vec3(m_offset + m_width*horizontalOffset - m_width / 2, verticalOffset, 0); - //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); } glm::vec3 TextFieldHudgetVoxels::worldPosition() const { From a8d7c0fb0ef30fee08f3df65745d9b533ac5db5b Mon Sep 17 00:00:00 2001 From: gersseba Date: Mon, 21 Apr 2014 15:08:14 +0200 Subject: [PATCH 13/21] wip --- .../gameplay/running/gameplayrunninginput.cpp | 17 +++++++++++------ .../gameplay/running/gameplayrunninginput.h | 3 ++- src/ui/clicktype.h | 3 ++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/gamestate/gameplay/running/gameplayrunninginput.cpp b/src/gamestate/gameplay/running/gameplayrunninginput.cpp index 4c5e59e0..7ff0671a 100644 --- a/src/gamestate/gameplay/running/gameplayrunninginput.cpp +++ b/src/gamestate/gameplay/running/gameplayrunninginput.cpp @@ -98,7 +98,8 @@ GamePlayRunningInput::GamePlayRunningInput(): // glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); retrieveInputValues(); - m_currentTimePressed = 0; + m_currentTimePressedRight = 0; + m_currentTimePressedLeft = 0; } void GamePlayRunningInput::resizeEvent(const unsigned int width, const unsigned int height) { @@ -139,12 +140,16 @@ void GamePlayRunningInput::keyCallback(int key, int scancode, int action, int mo void GamePlayRunningInput::mouseButtonCallback(int button, int action, int mods) { if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_RELEASE) { - if (m_currentTimePressed > 0 && m_currentTimePressed < prop_maxClickTime) { + if (m_currentTimePressedRight > 0 && m_currentTimePressedRight < prop_maxClickTime) { + World::instance()->player().hud().onClick(ClickType::Selection); + } + m_currentTimePressedRight = 0; + } + if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_RELEASE) { + if (m_currentTimePressedLeft > 0 && m_currentTimePressedLeft < prop_maxClickTime) { World::instance()->player().hud().onClick(ClickType::Selection); - } else { - } - m_currentTimePressed = 0; + m_currentTimePressedRight = 0; } } @@ -241,7 +246,7 @@ void GamePlayRunningInput::processMouseUpdate(float deltaSec) { } if (glfwGetMouseButton(glfwGetCurrentContext(), GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS){ - m_currentTimePressed += deltaSec; + m_currentTimePressedRight += deltaSec; } if (m_mouseControl || glfwGetMouseButton(glfwGetCurrentContext(), GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS && prop_maxClickTime < m_currentTimePressed) { diff --git a/src/gamestate/gameplay/running/gameplayrunninginput.h b/src/gamestate/gameplay/running/gameplayrunninginput.h index 2180ab34..1305ab01 100644 --- a/src/gamestate/gameplay/running/gameplayrunninginput.h +++ b/src/gamestate/gameplay/running/gameplayrunninginput.h @@ -58,7 +58,8 @@ class GamePlayRunningInput { void setupJoystickControls(); void retrieveInputValues(); - float m_currentTimePressed; + float m_currentTimePressedLeft; + float m_currentTimePressedRight; Property prop_deadzoneMouse; Property prop_deadzoneGamepad; diff --git a/src/ui/clicktype.h b/src/ui/clicktype.h index dee2f634..381770be 100644 --- a/src/ui/clicktype.h +++ b/src/ui/clicktype.h @@ -2,5 +2,6 @@ enum class ClickType { None, - Selection + Selection, + Fire }; \ No newline at end of file From e99667fd488c653390d68492b714b9497675b14a Mon Sep 17 00:00:00 2001 From: gersseba Date: Tue, 22 Apr 2014 07:50:42 +0200 Subject: [PATCH 14/21] wip --- .../gameplay/input/gameplaynormalinput.cpp | 23 +++++++++++++------ src/player.cpp | 3 --- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/gamestate/gameplay/input/gameplaynormalinput.cpp b/src/gamestate/gameplay/input/gameplaynormalinput.cpp index f2f7bc66..3a9836cb 100644 --- a/src/gamestate/gameplay/input/gameplaynormalinput.cpp +++ b/src/gamestate/gameplay/input/gameplaynormalinput.cpp @@ -97,7 +97,8 @@ GamePlayNormalInput::GamePlayNormalInput() : m_lastfocus = glfwGetWindowAttrib(glfwGetCurrentContext(), GLFW_FOCUSED); retrieveInputValues(); - m_currentTimePressed = 0; + m_currentTimePressedRight = 0; + m_currentTimePressedLeft = 0; } void GamePlayNormalInput::resizeEvent(const unsigned int width, const unsigned int height) { @@ -135,11 +136,16 @@ void GamePlayNormalInput::keyCallback(int key, int scancode, int action, int mod void GamePlayNormalInput::mouseButtonCallback(int button, int action, int mods) { if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_RELEASE) { - if (m_currentTimePressed > 0 && m_currentTimePressed < prop_maxClickTime) { + if (m_currentTimePressedRight > 0 && m_currentTimePressedRight < prop_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 < prop_maxClickTime) { + World::instance()->player().hud().onClick(ClickType::Selection); + } + m_currentTimePressedLeft = 0; } } @@ -231,11 +237,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 && prop_maxClickTime < m_currentTimePressed) { + if (m_mouseControl || glfwGetMouseButton(glfwGetCurrentContext(), GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS && prop_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/player.cpp b/src/player.cpp index 9a24fb05..f21727ad 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" From 617ff4754b45c6633eb9138c63692bd185d85c4b Mon Sep 17 00:00:00 2001 From: gersseba Date: Thu, 24 Apr 2014 16:26:50 +0200 Subject: [PATCH 15/21] Button style --- src/gamestate/gameplay/gameplay.cpp | 5 ++++ src/gamestate/gameplay/gameplay.h | 3 +++ src/input/inputconfigurator.cpp | 2 ++ src/ui/hud/buttonhudget.cpp | 16 ++++++++++-- src/ui/hud/buttonhudget.h | 7 +++++- src/ui/hud/buttonhudgetvoxels.cpp | 37 ++++++++++++++++++++++------ src/ui/hud/buttonhudgetvoxels.h | 8 ++++-- src/ui/hud/hud.cpp | 11 ++++++--- src/ui/hud/hud.h | 4 ++- src/ui/hud/hudelements.cpp | 11 +++++---- src/ui/hud/textfieldhudget.cpp | 4 +-- src/ui/hud/textfieldhudget.h | 2 +- src/ui/hud/textfieldhudgetvoxels.cpp | 36 +++++++++++++++++++++------ src/ui/hud/textfieldhudgetvoxels.h | 8 +++++- src/ui/voxelfontconstants.h | 11 +++++++++ test/perftest/testperformance.cpp | 2 +- 16 files changed, 132 insertions(+), 35 deletions(-) diff --git a/src/gamestate/gameplay/gameplay.cpp b/src/gamestate/gameplay/gameplay.cpp index 7c90f2a5..2cb19841 100644 --- a/src/gamestate/gameplay/gameplay.cpp +++ b/src/gamestate/gameplay/gameplay.cpp @@ -28,6 +28,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" @@ -45,6 +46,7 @@ GamePlay::GamePlay(Game* game) : m_soundManager(new SoundManager()), m_scenario(new ScriptedScenario(this, "data/scripts/scenarios/demo.lua")) { + World::instance()->player().hud().resetButton()->setCallback((std::function)std::bind(&GamePlay::resetButtonCallback, this, std::placeholders::_1)); updateView(); setInitialSubState(m_runningState); @@ -167,3 +169,6 @@ void GamePlay::updateView() { World::instance()->player().hud().setView(&m_game->viewer().view()); } +void GamePlay::resetButtonCallback(ClickType clickType){ + m_scenario->reset(); +} \ No newline at end of file diff --git a/src/gamestate/gameplay/gameplay.h b/src/gamestate/gameplay/gameplay.h index a4cb7428..5ba40709 100644 --- a/src/gamestate/gameplay/gameplay.h +++ b/src/gamestate/gameplay/gameplay.h @@ -3,6 +3,7 @@ #include #include "gamestate/gamestate.h" +#include "ui/clicktype.h" class BaseScenario; @@ -59,5 +60,7 @@ class GamePlay: public GameState { std::unique_ptr m_normalInput; std::unique_ptr m_freecamInput; bool m_freecamActive; + + void resetButtonCallback(ClickType clickType); }; diff --git a/src/input/inputconfigurator.cpp b/src/input/inputconfigurator.cpp index 6d7ce436..68cb566c 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/ui/hud/buttonhudget.cpp b/src/ui/hud/buttonhudget.cpp index 99ae2536..d0c4ab65 100644 --- a/src/ui/hud/buttonhudget.cpp +++ b/src/ui/hud/buttonhudget.cpp @@ -3,9 +3,9 @@ #include "hud.h" #include "buttonhudgetvoxels.h" -ButtonHudget::ButtonHudget(HUD* hud, glm::vec3 direction, const std::function& callback, float scale, std::string content, FontSize fontSize, bool bounds) : +ButtonHudget::ButtonHudget(HUD* hud, glm::vec3 direction, const std::function& callback, TextOrientation textOrientation, float scale, std::string content, FontSize fontSize, ButtonStyle buttonStyle) : Hudget(hud), - m_buttonVoxels(new ButtonHudgetVoxels(this, direction, scale, content, fontSize, bounds)), + m_buttonVoxels(new ButtonHudgetVoxels(this, direction, textOrientation, scale, content, fontSize, buttonStyle)), m_callback(callback) { m_buttonVoxels->updateBounds(); @@ -35,4 +35,16 @@ void ButtonHudget::setCallback(const std::function& c 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 index 5d61a41d..2c131d17 100644 --- a/src/ui/hud/buttonhudget.h +++ b/src/ui/hud/buttonhudget.h @@ -13,7 +13,7 @@ class TextFieldHudgetVoxels; class ButtonHudget : public Hudget { public: - ButtonHudget(HUD* hud, glm::vec3 direction, const std::function& callback, float scale = 0.5f, std::string content = "", FontSize fontSize = FontSize::SIZE5x7, bool bounds = true); + ButtonHudget(HUD* hud, glm::vec3 direction, const std::function& callback, TextOrientation textOrientation = TextOrientation::BACKWARDS, float scale = 0.5f, std::string content = "", FontSize fontSize = FontSize::SIZE5x7, ButtonStyle borderStyle = ButtonStyle::BORDERED); virtual ~ButtonHudget(); virtual void update(float deltaSec) override; @@ -27,6 +27,11 @@ class ButtonHudget : public Hudget { 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; diff --git a/src/ui/hud/buttonhudgetvoxels.cpp b/src/ui/hud/buttonhudgetvoxels.cpp index 87949e86..a824c779 100644 --- a/src/ui/hud/buttonhudgetvoxels.cpp +++ b/src/ui/hud/buttonhudgetvoxels.cpp @@ -4,12 +4,13 @@ #include "voxel/voxelcluster.h" #include "voxel/voxel.h" #include "voxel/voxelrenderer.h" +#include "hud.h" -ButtonHudgetVoxels::ButtonHudgetVoxels(ButtonHudget* buttonHudget, glm::vec3 direction, float scale, std::string content, FontSize fontSize, bool bounds) : - TextFieldHudgetVoxels(buttonHudget, direction, scale, content, fontSize), +ButtonHudgetVoxels::ButtonHudgetVoxels(ButtonHudget* buttonHudget, glm::vec3 direction, TextOrientation textOrientation, float scale, std::string content, FontSize fontSize, ButtonStyle buttonStyle) : +TextFieldHudgetVoxels(buttonHudget, direction, textOrientation, scale, content, fontSize), m_buttonVoxels(new VoxelCluster(scale)), - m_bounds(bounds), + m_buttonStyle(buttonStyle), m_hudget(buttonHudget) { setText(content); @@ -18,6 +19,9 @@ ButtonHudgetVoxels::ButtonHudgetVoxels(ButtonHudget* buttonHudget, glm::vec3 dir 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; @@ -25,7 +29,7 @@ void ButtonHudgetVoxels::updateBounds() { 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 { + } else if (m_buttonStyle == ButtonStyle::BORDERED_FILLED) { m_buttonVoxels->addVoxel(new Voxel(glm::ivec3(i, j, 1), 0x17012D)); } } @@ -33,10 +37,19 @@ void ButtonHudgetVoxels::updateBounds() { } void ButtonHudgetVoxels::draw() { - if (m_bounds) { - 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))); + if (m_buttonStyle == ButtonStyle::BORDERED || m_buttonStyle == ButtonStyle::BORDERED_FILLED) { + switch (textOrientation()) { + case TextOrientation::BACKWARDS: + 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(); @@ -48,4 +61,12 @@ void ButtonHudgetVoxels::setText(const std::string& text) { } 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 index cc36f368..f096a88d 100644 --- a/src/ui/hud/buttonhudgetvoxels.h +++ b/src/ui/hud/buttonhudgetvoxels.h @@ -11,7 +11,7 @@ class VoxelCluster; class ButtonHudgetVoxels : public TextFieldHudgetVoxels { public: - ButtonHudgetVoxels(ButtonHudget* textFieldHudget, glm::vec3 direction, float scale = 0.5f, std::string content = "", FontSize fontSize = FontSize::SIZE5x7, bool bounds = true); + ButtonHudgetVoxels(ButtonHudget* textFieldHudget, glm::vec3 direction, TextOrientation textOrienation = TextOrientation::BACKWARDS, float scale = 0.5f, std::string content = "", FontSize fontSize = FontSize::SIZE5x7, ButtonStyle buttonStyle = ButtonStyle::BORDERED); ~ButtonHudgetVoxels(); virtual void setText(const std::string& text); @@ -20,9 +20,13 @@ class ButtonHudgetVoxels : public TextFieldHudgetVoxels { virtual void draw() override; + ButtonStyle buttonStyle(); + void setButtonStyle(ButtonStyle buttonStyle); + protected: std::unique_ptr m_buttonVoxels; - bool m_bounds; Hudget* m_hudget; + + ButtonStyle m_buttonStyle; }; diff --git a/src/ui/hud/hud.cpp b/src/ui/hud/hud.cpp index 5098493a..674724d8 100644 --- a/src/ui/hud/hud.cpp +++ b/src/ui/hud/hud.cpp @@ -56,9 +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)), 0.025f, "")), - m_speedLabel(new TextFieldHudget(this, glm::normalize(glm::vec3(1.5f, -1.1f, -2)), 0.020f, "")), - m_menuButton(new ButtonHudget(this, glm::normalize(glm::vec3(-1.5f, 1.1f, -2)), (std::function)std::bind(&HUD::openMenu, this, std::placeholders::_1), 0.01f, "MENU")), + m_targetName(new TextFieldHudget(this, glm::normalize(glm::vec3(0, -1.1f, -2)), TextOrientation::BACKWARDS, 0.025f, "")), + m_speedLabel(new TextFieldHudget(this, glm::normalize(glm::vec3(1.5f, -1.1f, -2)), TextOrientation::BACKWARDS, 0.020f, "")), + m_resetButton(new ButtonHudget(this, glm::normalize(glm::vec3(-1.5f, 1.1f, -2)), (std::function)std::bind(&HUD::openMenu, this, std::placeholders::_1), TextOrientation::BACKWARDS, 0.01f, "RESET",FontSize::SIZE5x7,ButtonStyle::BORDERED)), m_elements(new HUDElements(*this)), m_target(nullptr), m_drawHud("vfx.drawhud"), @@ -70,7 +70,7 @@ HUD::HUD(Player* player): m_elements->addHudget(m_crossHair); m_elements->addHudget(m_targetName); m_elements->addHudget(m_speedLabel); - m_elements->addHudget(m_menuButton); + m_elements->addHudget(m_resetButton); } HUD::~HUD() = default; @@ -288,3 +288,6 @@ void HUD::openMenu(ClickType clicktype) { glow::debug("Not yet implemented"); } +ButtonHudget* HUD::resetButton() { + return m_resetButton; +} \ No newline at end of file diff --git a/src/ui/hud/hud.h b/src/ui/hud/hud.h index 1422b88f..097fa915 100644 --- a/src/ui/hud/hud.h +++ b/src/ui/hud/hud.h @@ -73,6 +73,8 @@ class HUD { void showMissionMessage(const std::string& message); void showMessage(const std::string& message); + ButtonHudget* resetButton(); + protected: Player* m_player; @@ -86,7 +88,7 @@ class HUD { TextFieldHudget* m_speedLabel; TextFieldHudget* m_targetName; - ButtonHudget* m_menuButton; + ButtonHudget* m_resetButton; CrossHair* m_crossHair; AimHelperHudget* m_aimHelper; diff --git a/src/ui/hud/hudelements.cpp b/src/ui/hud/hudelements.cpp index 9f90cbb1..5aea6495 100644 --- a/src/ui/hud/hudelements.cpp +++ b/src/ui/hud/hudelements.cpp @@ -7,17 +7,18 @@ #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_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::BACKWARDS, 0.025f, "")), + m_speedLabel(new TextFieldHudget(&m_hud, glm::normalize(glm::vec3(1.5f, -1.1f, -2)), TextOrientation::BACKWARDS, 0.020f, "")), + m_missionTitle(new TextFieldHudget(&m_hud, glm::normalize(glm::vec3(0.0f, 1.0f, -2)), TextOrientation::BACKWARDS, 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::BACKWARDS, 0.010f, "")), m_missionMessageHider(new HudgetHideAnimation(*m_missionMessage)) { addHudget(m_targetName); diff --git a/src/ui/hud/textfieldhudget.cpp b/src/ui/hud/textfieldhudget.cpp index b0bf9d6b..4624ba2f 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 c75a3c14..b12626e5 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::BACKWARDS, 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 4cd3aae6..c83498b3 100644 --- a/src/ui/hud/textfieldhudgetvoxels.cpp +++ b/src/ui/hud/textfieldhudgetvoxels.cpp @@ -12,13 +12,14 @@ #include "utils/geometryhelper.h" -TextFieldHudgetVoxels::TextFieldHudgetVoxels(Hudget* textFieldHudget, const glm::vec3& direction, float scale, const std::string& text, FontSize fontSize) : +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; @@ -31,23 +32,27 @@ void TextFieldHudgetVoxels::setText(const std::string& text) { } void TextFieldHudgetVoxels::draw() { - m_voxelFont->drawString(m_text, worldPosition(), worldOrientation(), m_fontSize, m_scale, FontAlign::CENTER); + if (m_textOrientation == TextOrientation::BACKWARDS) { + m_voxelFont->drawString(m_text, worldPosition(), orientation(), m_fontSize, m_scale, FontAlign::CENTER); + } else if (m_textOrientation == TextOrientation::SPHERE_STRAIGHT) { + 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 { @@ -90,3 +95,20 @@ glm::quat TextFieldHudgetVoxels::worldOrientation() const { return m_hudget->worldOrientation(m_direction); } +TextOrientation TextFieldHudgetVoxels::textOrientation() { + return m_textOrientation; +} + +glm::quat TextFieldHudgetVoxels::orientation() const { + switch (m_textOrientation) { + case TextOrientation::BACKWARDS: + return m_hudget->hud()->orientation(); + case TextOrientation::SPHERE_STRAIGHT: + return worldOrientation(); + } + return glm::quat(); +} + +void TextFieldHudgetVoxels::setTextOrientation(TextOrientation textOrientation) { + m_textOrientation = textOrientation; +} \ No newline at end of file diff --git a/src/ui/hud/textfieldhudgetvoxels.h b/src/ui/hud/textfieldhudgetvoxels.h index 8932c4b1..2040002e 100644 --- a/src/ui/hud/textfieldhudgetvoxels.h +++ b/src/ui/hud/textfieldhudgetvoxels.h @@ -11,7 +11,7 @@ class VoxelFont; class TextFieldHudgetVoxels{ public: - TextFieldHudgetVoxels(Hudget* 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::BACKWARDS, float scale = 0.5f, const std::string& text = "", FontSize fontSize = FontSize::SIZE5x7); virtual void setText(const std::string& text); @@ -23,6 +23,9 @@ class TextFieldHudgetVoxels{ float height(); float scale(); + TextOrientation textOrientation(); + void setTextOrientation(TextOrientation textOrientation); + protected: std::string m_text; @@ -31,6 +34,7 @@ class TextFieldHudgetVoxels{ glm::vec3 m_direction; glm::vec3 worldPosition() const; glm::quat worldOrientation() const; + glm::quat orientation() const; FontSize m_fontSize; VoxelFont* m_voxelFont; @@ -44,5 +48,7 @@ class TextFieldHudgetVoxels{ const glm::vec3 lowerLeft() const; const glm::vec3 upperRight() const; const glm::vec3 lowerRight() const; + + TextOrientation m_textOrientation; }; diff --git a/src/ui/voxelfontconstants.h b/src/ui/voxelfontconstants.h index feb31e32..c4e7eb3c 100644 --- a/src/ui/voxelfontconstants.h +++ b/src/ui/voxelfontconstants.h @@ -9,4 +9,15 @@ enum class FontAlign { LEFT, CENTER, RIGHT +}; + +enum class TextOrientation { + BACKWARDS, + SPHERE_STRAIGHT +}; + +enum class ButtonStyle { + PLAIN, + BORDERED, + BORDERED_FILLED }; \ No newline at end of file diff --git a/test/perftest/testperformance.cpp b/test/perftest/testperformance.cpp index 416e6c6e..32c07618 100644 --- a/test/perftest/testperformance.cpp +++ b/test/perftest/testperformance.cpp @@ -80,7 +80,7 @@ go_bandit([](){ before_each([&]() { World::reset(); world = World::instance(); - world->setPlayer(*new Player()); +// world->setPlayer(*new Player()); }); after_each([&]() { From 96328d351d31ea860cae03c22564e891989ce070 Mon Sep 17 00:00:00 2001 From: gersseba Date: Sun, 4 May 2014 20:40:13 +0200 Subject: [PATCH 16/21] something is not right yet --- src/gamestate/gameplay/gameplay.cpp | 14 +++++++++++++- src/gamestate/intro/intro.cpp | 2 +- src/scenarios/basescenario.h | 4 ++-- src/scenarios/scriptedscenario.cpp | 10 ++++++++-- src/scenarios/scriptedscenario.h | 3 +++ src/ui/voxelfont.cpp | 2 +- 6 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/gamestate/gameplay/gameplay.cpp b/src/gamestate/gameplay/gameplay.cpp index 2cb19841..3917f5ce 100644 --- a/src/gamestate/gameplay/gameplay.cpp +++ b/src/gamestate/gameplay/gameplay.cpp @@ -120,6 +120,8 @@ void GamePlay::loadScenario(int i) { } m_scenario->load(); + World::instance()->player().hud().resetButton()->setCallback((std::function)std::bind(&GamePlay::resetButtonCallback, this, std::placeholders::_1)); + } void GamePlay::keyCallback(int key, int scancode, int action, int mods) { @@ -170,5 +172,15 @@ void GamePlay::updateView() { } void GamePlay::resetButtonCallback(ClickType clickType){ - m_scenario->reset(); + printf("gameplay callback"); + TextureRenderer loadRenderer("data/textures/loading.dds"); + loadRenderer.display("Loading Scenario..."); + + m_soundManager->stopAll(); + m_scenario->clear(); + updateView(); + //m_scenario.reset(new ScriptedScenario(this, "data/scripts/scenarios/demo.lua")); + m_scenario->load(); + World::instance()->player().hud().resetButton()->setCallback((std::function)std::bind(&GamePlay::resetButtonCallback, this, std::placeholders::_1)); + } \ No newline at end of file diff --git a/src/gamestate/intro/intro.cpp b/src/gamestate/intro/intro.cpp index aa174ac3..d34451d2 100644 --- a/src/gamestate/intro/intro.cpp +++ b/src/gamestate/intro/intro.cpp @@ -50,7 +50,7 @@ void Intro::update(float deltaSec) { m_letterCountdown += deltaSec; while (m_letterCountdown > 0.0f && m_currentLine < INTRO_LINES.size()) { - m_letterCountdown -= 0.05; + m_letterCountdown -= 0.05f; if (m_currentLetter >= INTRO_LINES[m_currentLine].size()) { m_currentLine++; 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..97f947a0 100644 --- a/src/scenarios/scriptedscenario.cpp +++ b/src/scenarios/scriptedscenario.cpp @@ -35,9 +35,10 @@ 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); + //m_script->load(path); } ScriptedScenario::~ScriptedScenario() = default; @@ -54,3 +55,8 @@ 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(); +} diff --git a/src/scenarios/scriptedscenario.h b/src/scenarios/scriptedscenario.h index ee4c860e..5bdaad54 100644 --- a/src/scenarios/scriptedscenario.h +++ b/src/scenarios/scriptedscenario.h @@ -17,10 +17,13 @@ class ScriptedScenario: public BaseScenario { ScriptedScenario(GamePlay* gamePlay, const std::string& path); virtual ~ScriptedScenario(); + void load() override; protected: std::shared_ptr m_script; virtual void populateWorld() override; + + std::string m_path; }; diff --git a/src/ui/voxelfont.cpp b/src/ui/voxelfont.cpp index e500f8e2..83aa5604 100644 --- a/src/ui/voxelfont.cpp +++ b/src/ui/voxelfont.cpp @@ -117,4 +117,4 @@ VoxelFont* VoxelFont::instance() { } return s_instance; -} +} From 63b5c80b6a918bf4f7e3902418bd067ec0ec8818 Mon Sep 17 00:00:00 2001 From: gersseba Date: Sun, 4 May 2014 22:05:31 +0200 Subject: [PATCH 17/21] reset button working --- src/gamestate/gameplay/gameplay.cpp | 9 +++++---- src/gamestate/gameplay/gameplay.h | 2 ++ src/gamestate/gameplay/input/gameplaynormalinput.cpp | 6 +++--- src/scenarios/scriptedscenario.cpp | 6 +++++- src/scenarios/scriptedscenario.h | 3 ++- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/gamestate/gameplay/gameplay.cpp b/src/gamestate/gameplay/gameplay.cpp index 3917f5ce..8b786232 100644 --- a/src/gamestate/gameplay/gameplay.cpp +++ b/src/gamestate/gameplay/gameplay.cpp @@ -120,7 +120,7 @@ void GamePlay::loadScenario(int i) { } m_scenario->load(); - World::instance()->player().hud().resetButton()->setCallback((std::function)std::bind(&GamePlay::resetButtonCallback, this, std::placeholders::_1)); + setResetCallback(); } @@ -172,15 +172,16 @@ void GamePlay::updateView() { } void GamePlay::resetButtonCallback(ClickType clickType){ - printf("gameplay callback"); TextureRenderer loadRenderer("data/textures/loading.dds"); loadRenderer.display("Loading Scenario..."); m_soundManager->stopAll(); m_scenario->clear(); updateView(); - //m_scenario.reset(new ScriptedScenario(this, "data/scripts/scenarios/demo.lua")); m_scenario->load(); - World::instance()->player().hud().resetButton()->setCallback((std::function)std::bind(&GamePlay::resetButtonCallback, this, std::placeholders::_1)); + setResetCallback(); +} +void GamePlay::setResetCallback() { + World::instance()->player().hud().resetButton()->setCallback((std::function)std::bind(&GamePlay::resetButtonCallback, this, std::placeholders::_1)); } \ No newline at end of file diff --git a/src/gamestate/gameplay/gameplay.h b/src/gamestate/gameplay/gameplay.h index 8c2cfb9e..541434dc 100644 --- a/src/gamestate/gameplay/gameplay.h +++ b/src/gamestate/gameplay/gameplay.h @@ -64,5 +64,7 @@ class GamePlay: public GameState { bool m_freecamActive; void resetButtonCallback(ClickType clickType); + + void setResetCallback(); }; diff --git a/src/gamestate/gameplay/input/gameplaynormalinput.cpp b/src/gamestate/gameplay/input/gameplaynormalinput.cpp index cf2a79bd..bd6e5a9e 100644 --- a/src/gamestate/gameplay/input/gameplaynormalinput.cpp +++ b/src/gamestate/gameplay/input/gameplaynormalinput.cpp @@ -136,13 +136,13 @@ void GamePlayNormalInput::keyCallback(int key, int scancode, int action, int mod void GamePlayNormalInput::mouseButtonCallback(int button, int action, int mods) { if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_RELEASE) { - if (m_currentTimePressedRight > 0 && m_currentTimePressedRight < prop_maxClickTime) { + if (m_currentTimePressedRight > 0 && m_currentTimePressedRight < m_maxClickTime) { World::instance()->player().hud().onClick(ClickType::Selection); } m_currentTimePressedRight = 0; } if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_RELEASE) { - if (m_currentTimePressedLeft > 0 && m_currentTimePressedLeft < prop_maxClickTime) { + if (m_currentTimePressedLeft > 0 && m_currentTimePressedLeft < m_maxClickTime) { World::instance()->player().hud().onClick(ClickType::Selection); } m_currentTimePressedLeft = 0; @@ -244,7 +244,7 @@ void GamePlayNormalInput::processMouseUpdate(float deltaSec) { m_currentTimePressedLeft += deltaSec; } - if (m_mouseControl || glfwGetMouseButton(glfwGetCurrentContext(), GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS && prop_maxClickTime < m_currentTimePressedRight) { + 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/scenarios/scriptedscenario.cpp b/src/scenarios/scriptedscenario.cpp index 97f947a0..6f14ac38 100644 --- a/src/scenarios/scriptedscenario.cpp +++ b/src/scenarios/scriptedscenario.cpp @@ -38,7 +38,6 @@ ScriptedScenario::ScriptedScenario(GamePlay* gamePlay, const std::string& path): m_script(new GamePlayScript(World::instance()->scriptEngine())), m_path(path) { - //m_script->load(path); } ScriptedScenario::~ScriptedScenario() = default; @@ -60,3 +59,8 @@ void ScriptedScenario::load() { m_script->load(m_path); BaseScenario::load(); } + +void ScriptedScenario::clear() { + m_script->~GamePlayScript(); + BaseScenario::clear(); +} diff --git a/src/scenarios/scriptedscenario.h b/src/scenarios/scriptedscenario.h index 5bdaad54..a9f0d6d9 100644 --- a/src/scenarios/scriptedscenario.h +++ b/src/scenarios/scriptedscenario.h @@ -17,7 +17,8 @@ class ScriptedScenario: public BaseScenario { ScriptedScenario(GamePlay* gamePlay, const std::string& path); virtual ~ScriptedScenario(); - void load() override; + virtual void load() override; + virtual void clear() override; protected: std::shared_ptr m_script; From 2f8f3baeab56e6ea7fe48a05bbeb425d6aafbfa1 Mon Sep 17 00:00:00 2001 From: gersseba Date: Sat, 31 May 2014 10:45:11 +0200 Subject: [PATCH 18/21] fixed crash --- src/scenarios/scriptedscenario.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scenarios/scriptedscenario.cpp b/src/scenarios/scriptedscenario.cpp index 6f14ac38..2a36b723 100644 --- a/src/scenarios/scriptedscenario.cpp +++ b/src/scenarios/scriptedscenario.cpp @@ -61,6 +61,6 @@ void ScriptedScenario::load() { } void ScriptedScenario::clear() { - m_script->~GamePlayScript(); + m_script.reset(); BaseScenario::clear(); } From ec7c65c120b8b124c217199f406d82b4dd3175fd Mon Sep 17 00:00:00 2001 From: gersseba Date: Fri, 1 Aug 2014 16:41:44 +0200 Subject: [PATCH 19/21] fix for problem with master merge --- src/gamestate/gameplay/gameplay.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gamestate/gameplay/gameplay.cpp b/src/gamestate/gameplay/gameplay.cpp index 660205ac..65d9e6c4 100644 --- a/src/gamestate/gameplay/gameplay.cpp +++ b/src/gamestate/gameplay/gameplay.cpp @@ -44,6 +44,7 @@ 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()) { World::instance()->player().hud().resetButton()->setCallback((std::function)std::bind(&GamePlay::resetButtonCallback, this, std::placeholders::_1)); From 287ec9de9ea1a289f7881a101fc7384c2fc5f51d Mon Sep 17 00:00:00 2001 From: gersseba Date: Mon, 11 Aug 2014 19:53:10 +0200 Subject: [PATCH 20/21] removed old code, changed to match code docs --- src/gamestate/gameplay/gameplay.cpp | 29 ++++++++++++++++++---------- src/gamestate/gameplay/gameplay.h | 7 ++++++- src/ui/hud/buttonhudget.cpp | 3 ++- src/ui/hud/buttonhudget.h | 4 ++-- src/ui/hud/buttonhudgetvoxels.cpp | 6 +++--- src/ui/hud/buttonhudgetvoxels.h | 5 +++-- src/ui/hud/hud.cpp | 10 +++------- src/ui/hud/hud.h | 2 +- src/ui/hud/hudelements.cpp | 10 +++++----- src/ui/hud/objecthudget.cpp | 2 +- src/ui/hud/textfieldhudget.h | 2 +- src/ui/hud/textfieldhudgetvoxels.cpp | 6 +----- src/ui/hud/textfieldhudgetvoxels.h | 4 ++-- src/ui/voxelfontconstants.h | 4 ++-- src/world/world.cpp | 7 ------- src/world/world.h | 5 ----- 16 files changed, 51 insertions(+), 55 deletions(-) diff --git a/src/gamestate/gameplay/gameplay.cpp b/src/gamestate/gameplay/gameplay.cpp index 65d9e6c4..2cb210b1 100644 --- a/src/gamestate/gameplay/gameplay.cpp +++ b/src/gamestate/gameplay/gameplay.cpp @@ -47,7 +47,7 @@ GamePlay::GamePlay(Game* game) : m_scenario(new ScriptedScenario(this, "")), m_soundManager(new SoundManager()) { - World::instance()->player().hud().resetButton()->setCallback((std::function)std::bind(&GamePlay::resetButtonCallback, this, std::placeholders::_1)); + setResetCallback(); updateView(); setInitialSubState(m_runningState); @@ -112,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: @@ -175,14 +172,26 @@ void GamePlay::updateView() { World::instance()->player().hud().setView(&m_game->viewer().view()); } -void GamePlay::resetButtonCallback(ClickType clickType){ - TextureRenderer loadRenderer("data/textures/loading.dds"); - loadRenderer.display("Loading Scenario..."); +void GamePlay::resetScenario() { + displayLoadingScreen("resetting scenario"); + clearScenario(); + m_scenario->load(); +} + +void GamePlay::clearScenario() { m_soundManager->stopAll(); m_scenario->clear(); updateView(); - m_scenario->load(); +} + +void GamePlay::displayLoadingScreen(const std::string& status) { + TextureRenderer loadRenderer("data/textures/loading.dds"); + loadRenderer.display(status); +} + +void GamePlay::resetButtonCallback(ClickType clickType){ + resetScenario(); setResetCallback(); } diff --git a/src/gamestate/gameplay/gameplay.h b/src/gamestate/gameplay/gameplay.h index 8a567378..93d3fbaa 100644 --- a/src/gamestate/gameplay/gameplay.h +++ b/src/gamestate/gameplay/gameplay.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "gamestate/gamestate.h" #include "ui/clicktype.h" @@ -43,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; @@ -66,7 +69,9 @@ class GamePlay: public GameState { bool m_freecamActive; - void resetButtonCallback(ClickType clickType); + void resetButtonCallback(ClickType clickType); + + void clearScenario(); void setResetCallback(); }; diff --git a/src/ui/hud/buttonhudget.cpp b/src/ui/hud/buttonhudget.cpp index d0c4ab65..8e8e39a7 100644 --- a/src/ui/hud/buttonhudget.cpp +++ b/src/ui/hud/buttonhudget.cpp @@ -3,7 +3,8 @@ #include "hud.h" #include "buttonhudgetvoxels.h" -ButtonHudget::ButtonHudget(HUD* hud, glm::vec3 direction, const std::function& callback, TextOrientation textOrientation, float scale, std::string content, FontSize fontSize, ButtonStyle buttonStyle) : + +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) diff --git a/src/ui/hud/buttonhudget.h b/src/ui/hud/buttonhudget.h index 2c131d17..2224cf0c 100644 --- a/src/ui/hud/buttonhudget.h +++ b/src/ui/hud/buttonhudget.h @@ -13,7 +13,7 @@ class TextFieldHudgetVoxels; class ButtonHudget : public Hudget { public: - ButtonHudget(HUD* hud, glm::vec3 direction, const std::function& callback, TextOrientation textOrientation = TextOrientation::BACKWARDS, float scale = 0.5f, std::string content = "", FontSize fontSize = FontSize::SIZE5x7, ButtonStyle borderStyle = ButtonStyle::BORDERED); + 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; @@ -23,7 +23,7 @@ class ButtonHudget : public Hudget { virtual void onClick(ClickType clicktype) override; - virtual void setText(const std::string& content); + void setText(const std::string& content); void setCallback(const std::function& callback); diff --git a/src/ui/hud/buttonhudgetvoxels.cpp b/src/ui/hud/buttonhudgetvoxels.cpp index a824c779..200c11eb 100644 --- a/src/ui/hud/buttonhudgetvoxels.cpp +++ b/src/ui/hud/buttonhudgetvoxels.cpp @@ -7,8 +7,8 @@ #include "hud.h" -ButtonHudgetVoxels::ButtonHudgetVoxels(ButtonHudget* buttonHudget, glm::vec3 direction, TextOrientation textOrientation, float scale, std::string content, FontSize fontSize, ButtonStyle buttonStyle) : -TextFieldHudgetVoxels(buttonHudget, direction, textOrientation, scale, content, fontSize), +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) @@ -39,7 +39,7 @@ void ButtonHudgetVoxels::updateBounds() { void ButtonHudgetVoxels::draw() { if (m_buttonStyle == ButtonStyle::BORDERED || m_buttonStyle == ButtonStyle::BORDERED_FILLED) { switch (textOrientation()) { - case TextOrientation::BACKWARDS: + 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))); diff --git a/src/ui/hud/buttonhudgetvoxels.h b/src/ui/hud/buttonhudgetvoxels.h index f096a88d..ad039209 100644 --- a/src/ui/hud/buttonhudgetvoxels.h +++ b/src/ui/hud/buttonhudgetvoxels.h @@ -5,16 +5,17 @@ #include "textfieldhudgetvoxels.h" + class VoxelFont; class ButtonHudget; class VoxelCluster; class ButtonHudgetVoxels : public TextFieldHudgetVoxels { public: - ButtonHudgetVoxels(ButtonHudget* textFieldHudget, glm::vec3 direction, TextOrientation textOrienation = TextOrientation::BACKWARDS, float scale = 0.5f, std::string content = "", FontSize fontSize = FontSize::SIZE5x7, ButtonStyle buttonStyle = ButtonStyle::BORDERED); + 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(); - virtual void setText(const std::string& text); + void setText(const std::string& text); void updateBounds(); diff --git a/src/ui/hud/hud.cpp b/src/ui/hud/hud.cpp index 8b0ba9f0..9eb0f58c 100644 --- a/src/ui/hud/hud.cpp +++ b/src/ui/hud/hud.cpp @@ -56,9 +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::BACKWARDS, 0.025f, "")), - m_speedLabel(new TextFieldHudget(this, glm::normalize(glm::vec3(1.5f, -1.1f, -2)), TextOrientation::BACKWARDS, 0.020f, "")), - m_resetButton(new ButtonHudget(this, glm::normalize(glm::vec3(-1.5f, 1.1f, -2)), (std::function)std::bind(&HUD::openMenu, this, std::placeholders::_1), TextOrientation::BACKWARDS, 0.01f, "RESET",FontSize::SIZE5x7,ButtonStyle::BORDERED)), + 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) @@ -285,10 +285,6 @@ void HUD::setView(const View* view) { m_view = view; } -void HUD::openMenu(ClickType clicktype) { - glow::debug("Not yet implemented"); -} - ButtonHudget* HUD::resetButton() { return m_resetButton; } diff --git a/src/ui/hud/hud.h b/src/ui/hud/hud.h index 097fa915..3b0f668b 100644 --- a/src/ui/hud/hud.h +++ b/src/ui/hud/hud.h @@ -73,7 +73,7 @@ class HUD { void showMissionMessage(const std::string& message); void showMessage(const std::string& message); - ButtonHudget* resetButton(); + ButtonHudget* resetButton(); protected: diff --git a/src/ui/hud/hudelements.cpp b/src/ui/hud/hudelements.cpp index 71a953bc..ad853be1 100644 --- a/src/ui/hud/hudelements.cpp +++ b/src/ui/hud/hudelements.cpp @@ -14,14 +14,14 @@ HUDElements::HUDElements(HUD& hud): m_hud(hud), - m_targetName(new TextFieldHudget(&m_hud, glm::normalize(glm::vec3(0, -1.1f, -2)), TextOrientation::BACKWARDS, 0.025f, "")), - m_speedLabel(new TextFieldHudget(&m_hud, glm::normalize(glm::vec3(1.5f, -1.1f, -2)), TextOrientation::BACKWARDS, 0.020f, "")), - m_missionTitle(new TextFieldHudget(&m_hud, glm::normalize(glm::vec3(0.0f, 1.0f, -2)), TextOrientation::BACKWARDS, 0.020f, "")), - m_shieldLabel(new TextFieldHudget(&m_hud, glm::normalize(glm::vec3(-1.5f, -1.1f, -2)), TextOrientation::BACKWARDS, 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)), 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)), TextOrientation::BACKWARDS, 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/objecthudget.cpp b/src/ui/hud/objecthudget.cpp index 2218ff1b..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(), TextOrientation::BACKWARDS, 0.010f)) + m_shieldLabel(new TextFieldHudget(hud, glm::vec3(), TextOrientation::FORWARDS, 0.010f)) { m_insideFov = false; } diff --git a/src/ui/hud/textfieldhudget.h b/src/ui/hud/textfieldhudget.h index 8108de09..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, TextOrientation textOrientation = TextOrientation::BACKWARDS, 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 f74c5537..179d13c1 100644 --- a/src/ui/hud/textfieldhudgetvoxels.cpp +++ b/src/ui/hud/textfieldhudgetvoxels.cpp @@ -36,11 +36,7 @@ void TextFieldHudgetVoxels::setDirection(const glm::vec3& direction) { } void TextFieldHudgetVoxels::draw() { - if (m_textOrientation == TextOrientation::BACKWARDS) { m_voxelFont->drawString(m_text, worldPosition(), orientation(), m_fontSize, m_scale, FontAlign::CENTER); - } else if (m_textOrientation == TextOrientation::SPHERE_STRAIGHT) { - m_voxelFont->drawString(m_text, worldPosition(), orientation(), m_fontSize, m_scale, FontAlign::CENTER); - } } const glm::vec3 TextFieldHudgetVoxels::upperLeft() const { @@ -105,7 +101,7 @@ TextOrientation TextFieldHudgetVoxels::textOrientation() { glm::quat TextFieldHudgetVoxels::orientation() const { switch (m_textOrientation) { - case TextOrientation::BACKWARDS: + case TextOrientation::FORWARDS: return m_hudget->hud()->orientation(); case TextOrientation::SPHERE_STRAIGHT: return worldOrientation(); diff --git a/src/ui/hud/textfieldhudgetvoxels.h b/src/ui/hud/textfieldhudgetvoxels.h index baeae16a..2b4bb388 100644 --- a/src/ui/hud/textfieldhudgetvoxels.h +++ b/src/ui/hud/textfieldhudgetvoxels.h @@ -9,9 +9,9 @@ class Hudget; class VoxelFont; -class TextFieldHudgetVoxels{ +class TextFieldHudgetVoxels { public: - TextFieldHudgetVoxels(Hudget* textFieldHudget, const glm::vec3& direction, TextOrientation textOrientation = TextOrientation::BACKWARDS, 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); diff --git a/src/ui/voxelfontconstants.h b/src/ui/voxelfontconstants.h index c4e7eb3c..7262d2fc 100644 --- a/src/ui/voxelfontconstants.h +++ b/src/ui/voxelfontconstants.h @@ -12,8 +12,8 @@ enum class FontAlign { }; enum class TextOrientation { - BACKWARDS, - SPHERE_STRAIGHT + FORWARDS, // facing straight forward, "normal text" + SPHERE_STRAIGHT // on-helmet effect, facing in look direction from pov }; enum class ButtonStyle { diff --git a/src/world/world.cpp b/src/world/world.cpp index 4c948f6e..65c34bf2 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -37,8 +37,6 @@ World::World(): m_eventPoller(new EventPoller()), m_missionSystem(new MissionSystem()) { - m_textLifeTime = 0.0f; - m_textTimer = 0.0f; } World::~World() { @@ -106,11 +104,6 @@ void World::update(float deltaSecs) { for (WorldObject *worldObject : m_worldObjects) { worldObject->update(deltaSecs); } - - if (m_textTimer < m_textLifeTime) { - m_textTimer += deltaSecs; - m_textHudget->draw(); - } } float World::deltaSec() const { diff --git a/src/world/world.h b/src/world/world.h index 02276c5c..e012ab0a 100644 --- a/src/world/world.h +++ b/src/world/world.h @@ -69,11 +69,6 @@ class World { std::unique_ptr m_eventPoller; std::unique_ptr m_missionSystem; - std::unique_ptr m_textHudget; - float m_textLifeTime; - float m_textTimer; - - std::unordered_set m_worldObjects; std::unordered_set m_ships; }; From 3ed3521cf8f878e04bd30adb1a9d28ab739da63d Mon Sep 17 00:00:00 2001 From: gersseba Date: Wed, 13 Aug 2014 15:34:36 +0200 Subject: [PATCH 21/21] button w/out callback possible --- src/ui/hud/buttonhudget.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ui/hud/buttonhudget.cpp b/src/ui/hud/buttonhudget.cpp index 8e8e39a7..2fd0b0e0 100644 --- a/src/ui/hud/buttonhudget.cpp +++ b/src/ui/hud/buttonhudget.cpp @@ -26,8 +26,9 @@ bool ButtonHudget::isAt(const Ray& ray) const { } void ButtonHudget::onClick(ClickType clickType) { - assert(m_callback); - m_callback(clickType); + if (m_callback) { + m_callback(clickType); + } } void ButtonHudget::setCallback(const std::function& callback) {