-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Button hudget #546
base: master
Are you sure you want to change the base?
Button hudget #546
Changes from 15 commits
ef177fe
508130f
17c6736
ccaa5c0
6abe92d
de7421f
28dd753
c483e2b
30cbecb
4cb1f33
2025c05
b10a8e4
ff88081
f9cc792
0ffe45d
a8d7c0f
d9bbe2b
e99667f
617ff47
db528bd
96328d3
82f0e35
63b5c80
e37bf54
2f8f3ba
50527ce
85435b5
ec7c65c
287ec9d
3ed3521
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#pragma once | ||
|
||
enum class ClickType { | ||
None, | ||
Selection | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "buttonhudget.h" | ||
|
||
#include "hud.h" | ||
#include "buttonhudgetvoxels.h" | ||
|
||
ButtonHudget::ButtonHudget(HUD* hud, glm::vec3 direction, const std::function<void(ClickType clickType)>& 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(); | ||
} | ||
|
||
ButtonHudget::~ButtonHudget() = default; | ||
|
||
void ButtonHudget::update(float deltaSec) { | ||
} | ||
|
||
void ButtonHudget::draw() { | ||
m_buttonVoxels->draw(); | ||
} | ||
|
||
bool ButtonHudget::isAt(const Ray& ray) const { | ||
return m_buttonVoxels->isAt(ray); | ||
} | ||
|
||
void ButtonHudget::onClick(ClickType clickType) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rather like if(m_callback) mmh? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we allow setting nullptrs as callbacks? if you want no action on click you should rather use a dummy callback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In any case it should be possible to not set a callback at all - I know of no GUI-API that requires you to react in some way if some button is pressed. |
||
assert(m_callback); | ||
m_callback(clickType); | ||
} | ||
|
||
void ButtonHudget::setCallback(const std::function<void(ClickType clickType)>& callback) { | ||
m_callback = callback; | ||
} | ||
|
||
void ButtonHudget::setText(const std::string& content) { | ||
m_buttonVoxels->setText(content); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <functional> | ||
|
||
#include "hudget.h" | ||
#include "ui/voxelfontconstants.h" | ||
|
||
|
||
class ButtonHudgetVoxels; | ||
class TextFieldHudgetVoxels; | ||
|
||
class ButtonHudget : public Hudget { | ||
public: | ||
ButtonHudget(HUD* hud, glm::vec3 direction, const std::function<void(ClickType clickType)>& callback, float scale = 0.5f, std::string content = "", FontSize fontSize = FontSize::SIZE5x7, bool bounds = true); | ||
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 setText(const std::string& content); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any reason why this is virtual? if none, please remove |
||
|
||
void setCallback(const std::function<void(ClickType clickType)>& callback); | ||
|
||
protected: | ||
std::function<void(ClickType clickType)> m_callback; | ||
std::string m_content; | ||
std::unique_ptr<ButtonHudgetVoxels> m_buttonVoxels; | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "buttonhudgetvoxels.h" | ||
|
||
#include "buttonhudget.h" | ||
#include "voxel/voxelcluster.h" | ||
#include "voxel/voxel.h" | ||
#include "voxel/voxelrenderer.h" | ||
|
||
|
||
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) | ||
{ | ||
setText(content); | ||
} | ||
|
||
ButtonHudgetVoxels::~ButtonHudgetVoxels() = default; | ||
|
||
void ButtonHudgetVoxels::updateBounds() { | ||
m_buttonVoxels.reset(new VoxelCluster(m_scale)); | ||
int width = (int)(m_width/m_scale)*m_text.size()+1; | ||
int height = (int)(m_height/m_scale)*2; | ||
for (int i = 0; i < width; i++) { | ||
for (int j = 0; j < height; j++) { | ||
if (i == 0 || j == 0 || i == width - 1 || j == height - 1) { | ||
m_buttonVoxels->addVoxel(new Voxel(glm::ivec3(i, j, 0), 0x0FF00F)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume these are border and content colors? please make them constants There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or even better: configurable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will declare them at the beginning of the method (as it is done in all other hudgets). I created a #554 which addresses the issue of a configurable color theme. |
||
} else { | ||
m_buttonVoxels->addVoxel(new Voxel(glm::ivec3(i, j, 1), 0x17012D)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
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<float>(), glm::vec3(0, 1, 0))); | ||
VoxelRenderer::instance()->draw(*m_buttonVoxels); | ||
} | ||
TextFieldHudgetVoxels::draw(); | ||
} | ||
|
||
void ButtonHudgetVoxels::setText(const std::string& text) { | ||
if (m_text.compare(text) == 0) { | ||
return; | ||
} | ||
TextFieldHudgetVoxels::setText(text); | ||
updateBounds(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "textfieldhudgetvoxels.h" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nl++ |
||
class VoxelFont; | ||
class ButtonHudget; | ||
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(); | ||
|
||
virtual void setText(const std::string& text); | ||
|
||
void updateBounds(); | ||
|
||
virtual void draw() override; | ||
|
||
protected: | ||
std::unique_ptr<VoxelCluster> m_buttonVoxels; | ||
bool m_bounds; | ||
Hudget* m_hudget; | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
#include <algorithm> | ||
#include <cmath> | ||
#include <functional> | ||
#include <string> | ||
|
||
#include <glm/glm.hpp> | ||
|
@@ -45,6 +46,7 @@ | |
#include "crosshair.h" | ||
#include "aimhelperhudget.h" | ||
#include "textfieldhudget.h" | ||
#include "buttonhudget.h" | ||
|
||
|
||
|
||
|
@@ -54,6 +56,9 @@ HUD::HUD(Player* player): | |
m_crossHair(new CrossHair(this)), | ||
m_aimHelper(new AimHelperHudget(this)), | ||
m_scanner(new WorldTreeScanner()), | ||
m_targetName(new TextFieldHudget(this, glm::normalize(glm::vec3(0, -1.1f, -2)), 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<void(ClickType clickType)>)std::bind(&HUD::openMenu, this, std::placeholders::_1), 0.01f, "MENU")), | ||
m_elements(new HUDElements(*this)), | ||
m_target(nullptr), | ||
m_drawHud("vfx.drawhud"), | ||
|
@@ -63,6 +68,9 @@ HUD::HUD(Player* player): | |
|
||
m_elements->addHudget(m_aimHelper); | ||
m_elements->addHudget(m_crossHair); | ||
m_elements->addHudget(m_targetName); | ||
m_elements->addHudget(m_speedLabel); | ||
m_elements->addHudget(m_menuButton); | ||
} | ||
|
||
HUD::~HUD() = default; | ||
|
@@ -258,4 +266,7 @@ void HUD::setView(const View* view) { | |
m_view = view; | ||
} | ||
|
||
void HUD::openMenu(ClickType clicktype) { | ||
glow::debug("Not yet implemented"); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when should a callback with clicktype none be fired? Also, when I click I don't get debug output atm |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,43 +6,43 @@ | |
#include "hudget.h" | ||
#include "ui/voxelfontconstants.h" | ||
|
||
class TextFieldHudget; | ||
class Hudget; | ||
class VoxelFont; | ||
|
||
class TextFieldHudgetVoxels{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whitespace before { |
||
public: | ||
TextFieldHudgetVoxels(TextFieldHudget* textFieldHudget, const glm::vec3& direction, float scale = 0.5f, const std::string& text = "", FontSize fontSize = FontSize::SIZE5x7); | ||
TextFieldHudgetVoxels(Hudget* textFieldHudget, const glm::vec3& direction, float scale = 0.5f, const std::string& text = "", FontSize fontSize = FontSize::SIZE5x7); | ||
|
||
void setText(const std::string& text); | ||
virtual void setText(const std::string& text); | ||
|
||
void update(float deltaSec); | ||
void draw(); | ||
virtual void draw(); | ||
|
||
virtual bool isAt(const Ray& ray) const; | ||
|
||
float width(); | ||
float height(); | ||
float scale(); | ||
|
||
|
||
protected: | ||
FontSize m_fontSize; | ||
TextFieldHudget* m_textFieldHudget; | ||
std::string m_text; | ||
VoxelFont* m_voxelFont; | ||
|
||
Hudget* m_hudget; | ||
|
||
glm::vec3 m_direction; | ||
glm::vec3 worldPosition() const; | ||
glm::quat worldOrientation() const; | ||
|
||
FontSize m_fontSize; | ||
VoxelFont* m_voxelFont; | ||
|
||
float m_width, m_height, m_scale; | ||
float m_offset; | ||
|
||
|
||
const glm::vec3 offsetToCenter(bool upper, bool left) const; | ||
|
||
const glm::vec3 upperLeft() const; | ||
const glm::vec3 lowerLeft() const; | ||
const glm::vec3 upperRight() const; | ||
const glm::vec3 lowerRight() const; | ||
|
||
glm::vec3 worldPosition() const; | ||
glm::quat worldOrientation() const; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nl++