-
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 28 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 |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
#include "camera/camerahead.h" | ||
#include "camera/cameradolly.h" | ||
#include "ui/hud/hud.h" | ||
#include "ui/hud/buttonhudget.h" | ||
#include "display/viewer.h" | ||
|
||
#include "display/rendering/texturerenderer.h" | ||
|
@@ -43,8 +44,10 @@ GamePlay::GamePlay(Game* game) : | |
m_freecamInput(new GamePlayFreecamInput(*this)), | ||
m_freecamActive(false), | ||
m_scene(new GamePlayScene(*this)), | ||
m_scenario(new ScriptedScenario(this, "")), | ||
m_soundManager(new SoundManager()) | ||
{ | ||
World::instance()->player().hud().resetButton()->setCallback((std::function<void(ClickType clickType)>)std::bind(&GamePlay::resetButtonCallback, this, std::placeholders::_1)); | ||
updateView(); | ||
setInitialSubState(m_runningState); | ||
|
||
|
@@ -140,6 +143,8 @@ void GamePlay::loadScenario(int i) { | |
} | ||
|
||
m_scenario->load(); | ||
setResetCallback(); | ||
|
||
} | ||
|
||
void GamePlay::update(float deltaSec) { | ||
|
@@ -170,3 +175,17 @@ void GamePlay::updateView() { | |
World::instance()->player().hud().setView(&m_game->viewer().view()); | ||
} | ||
|
||
void GamePlay::resetButtonCallback(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. It seems unlogical to me to have the code reseting the scenario inside some callback of a click. This should read (I don't care how you make it do that :P ) like: m_scenario->reset(); // or World::instance()->reset(), dunno you know what I mean? |
||
TextureRenderer loadRenderer("data/textures/loading.dds"); | ||
loadRenderer.display("Loading Scenario..."); | ||
|
||
m_soundManager->stopAll(); | ||
m_scenario->clear(); | ||
updateView(); | ||
m_scenario->load(); | ||
setResetCallback(); | ||
} | ||
|
||
void GamePlay::setResetCallback() { | ||
World::instance()->player().hud().resetButton()->setCallback((std::function<void(ClickType clickType)>)std::bind(&GamePlay::resetButtonCallback, this, std::placeholders::_1)); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
#include <memory> | ||
|
||
#include "gamestate/gamestate.h" | ||
#include "ui/clicktype.h" | ||
|
||
|
||
class BaseScenario; | ||
|
@@ -64,5 +65,9 @@ class GamePlay: public GameState { | |
std::unique_ptr<GamePlayFreecamInput> m_freecamInput; | ||
|
||
bool m_freecamActive; | ||
|
||
void resetButtonCallback(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. indentation and stuff 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. o.O it doesn't look like that in my ide |
||
|
||
void setResetCallback(); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#pragma once | ||
|
||
enum class ClickType { | ||
None, | ||
Selection, | ||
Fire | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "buttonhudget.h" | ||
|
||
#include "hud.h" | ||
#include "buttonhudgetvoxels.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++ |
||
ButtonHudget::ButtonHudget(HUD* hud, glm::vec3 direction, const std::function<void(ClickType clickType)>& callback, TextOrientation textOrientation, float scale, std::string content, FontSize fontSize, ButtonStyle buttonStyle) : | ||
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. const ref to glm::vec3 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. ...and to everything else you're passing by value that's not a primitive datatype ;) 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. except for enums right? Compiler will only pass on an int anyway I believe. 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. enums are primitive datatypes, correct ;) |
||
Hudget(hud), | ||
m_buttonVoxels(new ButtonHudgetVoxels(this, direction, textOrientation, scale, content, fontSize, buttonStyle)), | ||
m_callback(callback) | ||
{ | ||
m_buttonVoxels->updateBounds(); | ||
} | ||
|
||
ButtonHudget::~ButtonHudget() = default; | ||
|
||
void ButtonHudget::update(float deltaSec) { | ||
} | ||
|
||
void ButtonHudget::draw() { | ||
m_buttonVoxels->draw(); | ||
} | ||
|
||
bool ButtonHudget::isAt(const Ray& ray) const { | ||
return m_buttonVoxels->isAt(ray); | ||
} | ||
|
||
void ButtonHudget::onClick(ClickType clickType) { | ||
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); | ||
} | ||
|
||
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); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#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, 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; | ||
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); | ||
|
||
void setTextOrientation(TextOrientation textOrientation); | ||
|
||
ButtonStyle buttonStyle(); | ||
void setButtonStyle(ButtonStyle buttonStyle); | ||
|
||
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,72 @@ | ||
#include "buttonhudgetvoxels.h" | ||
|
||
#include "buttonhudget.h" | ||
#include "voxel/voxelcluster.h" | ||
#include "voxel/voxel.h" | ||
#include "voxel/voxelrenderer.h" | ||
#include "hud.h" | ||
|
||
|
||
ButtonHudgetVoxels::ButtonHudgetVoxels(ButtonHudget* buttonHudget, glm::vec3 direction, TextOrientation textOrientation, float scale, std::string content, FontSize fontSize, ButtonStyle buttonStyle) : | ||
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. same here, please use constrefs |
||
TextFieldHudgetVoxels(buttonHudget, direction, textOrientation, scale, content, fontSize), | ||
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_buttonVoxels(new VoxelCluster(scale)), | ||
m_buttonStyle(buttonStyle), | ||
m_hudget(buttonHudget) | ||
{ | ||
setText(content); | ||
} | ||
|
||
ButtonHudgetVoxels::~ButtonHudgetVoxels() = default; | ||
|
||
void ButtonHudgetVoxels::updateBounds() { | ||
if (m_buttonStyle == ButtonStyle::PLAIN) { | ||
return; | ||
} | ||
m_buttonVoxels.reset(new VoxelCluster(m_scale)); | ||
int width = (int)(m_width/m_scale)*m_text.size()+1; | ||
int height = (int)(m_height/m_scale)*2; | ||
for (int i = 0; i < width; i++) { | ||
for (int j = 0; j < height; j++) { | ||
if (i == 0 || j == 0 || i == width - 1 || j == height - 1) { | ||
m_buttonVoxels->addVoxel(new Voxel(glm::ivec3(i, j, 0), 0x0FF00F)); | ||
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 if (m_buttonStyle == ButtonStyle::BORDERED_FILLED) { | ||
m_buttonVoxels->addVoxel(new Voxel(glm::ivec3(i, j, 1), 0x17012D)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void ButtonHudgetVoxels::draw() { | ||
if (m_buttonStyle == ButtonStyle::BORDERED || m_buttonStyle == ButtonStyle::BORDERED_FILLED) { | ||
switch (textOrientation()) { | ||
case TextOrientation::BACKWARDS: | ||
m_buttonVoxels->transform().setPosition(lowerRight()); | ||
m_buttonVoxels->transform().setOrientation(m_hudget->hud()->orientation()); | ||
m_buttonVoxels->transform().rotate(glm::angleAxis(glm::pi<float>(), 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<float>(), glm::vec3(0, 1, 0))); | ||
break; | ||
} | ||
VoxelRenderer::instance()->draw(*m_buttonVoxels); | ||
} | ||
TextFieldHudgetVoxels::draw(); | ||
} | ||
|
||
void ButtonHudgetVoxels::setText(const std::string& text) { | ||
if (m_text.compare(text) == 0) { | ||
return; | ||
} | ||
TextFieldHudgetVoxels::setText(text); | ||
updateBounds(); | ||
} | ||
|
||
ButtonStyle ButtonHudgetVoxels::buttonStyle() { | ||
return m_buttonStyle; | ||
} | ||
|
||
void ButtonHudgetVoxels::setButtonStyle(ButtonStyle buttonStyle) { | ||
m_buttonStyle = buttonStyle; | ||
} |
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.
this line seems to be the same as setResetCallback(). Please use this method then.