-
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 10 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, 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::registerCallback(std::function<void(ClickType clickType)> 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. setCallback should suffice as name, I think |
||
m_callback = callback; | ||
} | ||
|
||
void ButtonHudget::setContent(std::string content) { | ||
m_buttonVoxels->setContent(content); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <functional> | ||
|
||
#include "hudget.h" | ||
#include "ui/voxelfontconstants.h" | ||
|
||
class ButtonHudgetVoxels; | ||
class TextFieldHudgetVoxels; | ||
|
||
class ButtonHudget : public Hudget{ | ||
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. Another space after Hudget, please |
||
public: | ||
ButtonHudget(HUD* hud, glm::vec3 direction, 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 setContent(std::string content); | ||
|
||
void registerCallback(std::function<void(ClickType clickType)> 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. I think mrzzzrm already mentioned that these should be const references instead of values. |
||
|
||
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) | ||
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. indent |
||
{ | ||
setContent(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 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::setContent(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. constref ;) |
||
if (m_content.compare(content) == 0) { | ||
return; | ||
} | ||
TextFieldHudgetVoxels::setContent(content); | ||
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(); | ||
|
||
void setContent(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. I think we should build up our ui in best ui-api-tradition (i.e. Qt). Therefor setText deems me to be the better name 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. As it turns out you already made that change to the texthudgets (along some other changes) in mission scripting... It's not like there is much use arguing about that now |
||
|
||
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 <glm/glm.hpp> | ||
#include <glm/gtx/quaternion.hpp> | ||
|
@@ -35,6 +36,7 @@ | |
#include "display/view.h" | ||
#include "camera/camerahead.h" | ||
#include "textfieldhudget.h" | ||
#include "buttonhudget.h" | ||
#include "physics/physics.h" | ||
|
||
|
||
|
@@ -48,6 +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)), (std::function<void(ClickType clickType)>)std::bind(&HUD::openMenu, this, std::placeholders::_1), 0.01f, "MENU")), | ||
m_target(nullptr), | ||
m_drawHud("vfx.drawhud") | ||
{ | ||
|
@@ -56,6 +59,7 @@ HUD::HUD(Player* player): | |
m_hudgets.push_back(m_aimHelper.get()); | ||
m_hudgets.push_back(m_targetName.get()); | ||
m_hudgets.push_back(m_speedLabel.get()); | ||
m_hudgets.push_back(m_menuButton.get()); | ||
} | ||
|
||
HUD::~HUD() = default; | ||
|
@@ -241,6 +245,10 @@ float HUD::fovx() const { | |
return m_fovx; | ||
} | ||
|
||
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 |
||
|
||
void HUD::setViewer(Viewer& viewer) { | ||
m_viewer = &viewer; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,26 +12,28 @@ | |
|
||
#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), | ||
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. indent |
||
m_voxelFont(VoxelFont::instance()), | ||
m_content(content), | ||
m_direction(direction), | ||
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() { | ||
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 { | ||
|
@@ -67,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; | ||
|
@@ -81,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); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,12 +11,13 @@ 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, 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(); | ||
|
||
void setContent(std::string content); | ||
virtual void setContent(std::string content); | ||
|
||
void update(float deltaSec); | ||
void draw(); | ||
|
||
virtual void draw(); | ||
|
||
virtual bool isAt(const Ray& ray) const; | ||
|
||
|
@@ -25,16 +26,16 @@ 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; | ||
|
||
Hudget* m_hudget; | ||
glm::vec3 worldPosition() const; | ||
glm::quat worldOrientation() const; | ||
|
||
FontSize m_fontSize; | ||
TextFieldHudget* m_textFieldHudget; | ||
std::string m_content; | ||
VoxelFont* m_voxelFont; | ||
glm::vec3 m_direction; | ||
|
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++