Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ef177fe
wip
gersseba Mar 5, 2014
508130f
Buttons have borders
gersseba Mar 6, 2014
17c6736
wip
gersseba Mar 8, 2014
ccaa5c0
Merge branch 'master' of https://github.com/voxelinc/voxellancer into…
gersseba Mar 16, 2014
6abe92d
update glow
gersseba Mar 16, 2014
de7421f
wip
gersseba Mar 17, 2014
28dd753
Merge branch 'master' of https://github.com/voxelinc/voxellancer into…
gersseba Mar 30, 2014
c483e2b
added assertion and constuctor with callback
gersseba Mar 30, 2014
30cbecb
fix const HUD issue
gersseba Mar 30, 2014
4cb1f33
fix reference from bind
gersseba Mar 30, 2014
2025c05
coding convention
gersseba Mar 31, 2014
b10a8e4
const ref & colors
gersseba Mar 31, 2014
ff88081
Merge branch 'master' of https://github.com/voxelinc/voxellancer into…
gersseba Mar 31, 2014
f9cc792
adapting to changes in hud from mission script pr
gersseba Mar 31, 2014
0ffe45d
more changes to fit recent pr
gersseba Mar 31, 2014
a8d7c0f
wip
gersseba Apr 21, 2014
d9bbe2b
Merge branch 'master' of https://github.com/voxelinc/voxellancer into…
gersseba Apr 21, 2014
e99667f
wip
gersseba Apr 22, 2014
617ff47
Button style
gersseba Apr 24, 2014
db528bd
Merge branch 'intro' of https://github.com/voxelinc/voxellancer into …
gersseba Apr 24, 2014
96328d3
something is not right yet
gersseba May 4, 2014
82f0e35
Merge branch 'master' of https://github.com/voxelinc/voxellancer into…
gersseba May 4, 2014
63b5c80
reset button working
gersseba May 4, 2014
e37bf54
Merge branch 'master' of github.com:voxelinc/voxellancer into button_…
May 18, 2014
2f8f3ba
fixed crash
gersseba May 31, 2014
50527ce
Merge branch 'master' of https://github.com/voxelinc/voxellancer into…
gersseba May 31, 2014
85435b5
Merge branch 'master' of https://github.com/voxelinc/voxellancer into…
gersseba Aug 1, 2014
ec7c65c
fix for problem with master merge
gersseba Aug 1, 2014
287ec9d
removed old code, changed to match code docs
gersseba Aug 11, 2014
3ed3521
button w/out callback possible
gersseba Aug 13, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/display/rendering/starfield.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ namespace glow {
class Buffer;
};


/**
* Renders a starfield around the camera.
* Old camera positions/orientations are stored in order to stretch the
Expand Down
38 changes: 33 additions & 5 deletions src/gamestate/gameplay/gameplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -43,8 +44,10 @@ GamePlay::GamePlay(Game* game) :
m_freecamInput(new GamePlayFreecamInput(*this)),
m_freecamActive(false),
m_scene(new GamePlayScene(*this)),
m_scenario(new ScriptedScenario(this, "")),
m_soundManager(new SoundManager())
{
setResetCallback();
updateView();
setInitialSubState(m_runningState);

Expand Down Expand Up @@ -109,12 +112,9 @@ SoundManager& GamePlay::soundManager() {
}

void GamePlay::loadScenario(int i) {
TextureRenderer loadRenderer("data/textures/loading.dds");
loadRenderer.display("Loading Scenario...");
displayLoadingScreen("Loading Scenario...");

m_soundManager->stopAll();
m_scenario->clear();
updateView();
clearScenario();

switch (i) {
case 0:
Expand All @@ -140,6 +140,8 @@ void GamePlay::loadScenario(int i) {
}

m_scenario->load();
setResetCallback();

}

void GamePlay::update(float deltaSec) {
Expand Down Expand Up @@ -170,3 +172,29 @@ void GamePlay::updateView() {
World::instance()->player().hud().setView(&m_game->viewer().view());
}

void GamePlay::resetScenario() {
displayLoadingScreen("resetting scenario");
clearScenario();

m_scenario->load();
}

void GamePlay::clearScenario() {
m_soundManager->stopAll();
m_scenario->clear();
updateView();
}

void GamePlay::displayLoadingScreen(const std::string& status) {
TextureRenderer loadRenderer("data/textures/loading.dds");
loadRenderer.display(status);
}

void GamePlay::resetButtonCallback(ClickType clickType){
resetScenario();
setResetCallback();
}

void GamePlay::setResetCallback() {
World::instance()->player().hud().resetButton()->setCallback((std::function<void(ClickType clickType)>)std::bind(&GamePlay::resetButtonCallback, this, std::placeholders::_1));
}
10 changes: 10 additions & 0 deletions src/gamestate/gameplay/gameplay.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#pragma once

#include <memory>
#include <string>

#include "gamestate/gamestate.h"
#include "ui/clicktype.h"


class BaseScenario;
Expand Down Expand Up @@ -42,6 +44,8 @@ class GamePlay: public GameState {
SoundManager& soundManager();

void loadScenario(int i);
void resetScenario();
void displayLoadingScreen(const std::string& status);

virtual void update(float deltaSec) override;

Expand All @@ -64,5 +68,11 @@ class GamePlay: public GameState {
std::unique_ptr<GamePlayFreecamInput> m_freecamInput;

bool m_freecamActive;

void resetButtonCallback(ClickType clickType);

void clearScenario();

void setResetCallback();
};

26 changes: 16 additions & 10 deletions src/gamestate/gameplay/input/gameplaynormalinput.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#include "gameplaynormalinput.h"

#ifdef WIN32
#include <windows.h>
#endif
#include <GL/glew.h>
#include <GLFW/glfw3.h>

Expand Down Expand Up @@ -103,7 +100,8 @@ GamePlayNormalInput::GamePlayNormalInput(GamePlay& gamePlay) :
m_lastfocus = glfwGetWindowAttrib(glfwGetCurrentContext(), GLFW_FOCUSED);

retrieveInputValues();
m_currentTimePressed = 0;
m_currentTimePressedRight = 0;
m_currentTimePressedLeft = 0;
}

void GamePlayNormalInput::onResizeEvent(const unsigned int width, const unsigned int height) {
Expand Down Expand Up @@ -143,11 +141,16 @@ void GamePlayNormalInput::onKeyEvent(int key, int scancode, int action, int mods

void GamePlayNormalInput::onMouseButtonEvent(int button, int action, int mods) {
if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_RELEASE) {
if (m_currentTimePressed > 0 && m_currentTimePressed < m_maxClickTime) {
if (m_currentTimePressedRight > 0 && m_currentTimePressedRight < m_maxClickTime) {
World::instance()->player().hud().onClick(ClickType::Selection);
} else {
}
m_currentTimePressed = 0;
m_currentTimePressedRight = 0;
}
if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_RELEASE) {
if (m_currentTimePressedLeft > 0 && m_currentTimePressedLeft < m_maxClickTime) {
World::instance()->player().hud().onClick(ClickType::Selection);
}
m_currentTimePressedLeft = 0;
}
}

Expand Down Expand Up @@ -239,11 +242,14 @@ void GamePlayNormalInput::processMouseUpdate(float deltaSec) {
m_fireUpdate = true;
}

if (glfwGetMouseButton(glfwGetCurrentContext(), GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS){
m_currentTimePressed += deltaSec;
if (glfwGetMouseButton(glfwGetCurrentContext(), GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS) {
m_currentTimePressedRight += deltaSec;
}
if (glfwGetMouseButton(glfwGetCurrentContext(), GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS) {
m_currentTimePressedLeft += deltaSec;
}

if (m_mouseControl || glfwGetMouseButton(glfwGetCurrentContext(), GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS && m_maxClickTime < m_currentTimePressed) {
if (m_mouseControl || glfwGetMouseButton(glfwGetCurrentContext(), GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS && m_maxClickTime < m_currentTimePressedRight) {
glm::vec3 rot;
x = ContextProvider::instance()->resolution().width() / 2 - (int)floor(x);
y = ContextProvider::instance()->resolution().height() / 2 - (int)floor(y);
Expand Down
3 changes: 2 additions & 1 deletion src/gamestate/gameplay/input/gameplaynormalinput.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class GamePlayNormalInput : public GamePlayInput {
void addActionsToVector();
void retrieveInputValues();

float m_currentTimePressed;
float m_currentTimePressedLeft;
float m_currentTimePressedRight;

Property<float> m_deadzoneMouse;
Property<float> m_deadzoneGamepad;
Expand Down
2 changes: 2 additions & 0 deletions src/input/inputconfigurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
3 changes: 0 additions & 3 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/scenarios/basescenario.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class BaseScenario {
public:
BaseScenario(GamePlay* gamePlay);

void load();
void clear();
virtual void load();
virtual void clear();
void reset();


Expand Down
14 changes: 12 additions & 2 deletions src/scenarios/scriptedscenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@

ScriptedScenario::ScriptedScenario(GamePlay* gamePlay, const std::string& path):
BaseScenario(gamePlay),
m_script(new GamePlayScript(World::instance()->scriptEngine()))
m_script(new GamePlayScript(World::instance()->scriptEngine())),
m_path(path)
{
m_script->load(path);
}

ScriptedScenario::~ScriptedScenario() = default;
Expand All @@ -54,3 +54,13 @@ void ScriptedScenario::populateWorld() {
m_world->scriptEngine().addScript(m_script);
}

void ScriptedScenario::load() {
m_script.reset(new GamePlayScript(World::instance()->scriptEngine()));
m_script->load(m_path);
BaseScenario::load();
}

void ScriptedScenario::clear() {
m_script.reset();
BaseScenario::clear();
}
4 changes: 4 additions & 0 deletions src/scenarios/scriptedscenario.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ class ScriptedScenario: public BaseScenario {
ScriptedScenario(GamePlay* gamePlay, const std::string& path);
virtual ~ScriptedScenario();

virtual void load() override;
virtual void clear() override;

protected:
std::shared_ptr<GamePlayScript> m_script;

virtual void populateWorld() override;

std::string m_path;
};

7 changes: 7 additions & 0 deletions src/ui/clicktype.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

enum class ClickType {
None,
Selection,
Fire
};
52 changes: 52 additions & 0 deletions src/ui/hud/buttonhudget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "buttonhudget.h"

#include "hud.h"
#include "buttonhudgetvoxels.h"

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nl++


ButtonHudget::ButtonHudget(HUD* hud, const glm::vec3 &direction, const std::function<void(ClickType clickType)>& callback, TextOrientation textOrientation, float scale, const std::string& content, FontSize fontSize, ButtonStyle buttonStyle) :
Hudget(hud),
m_buttonVoxels(new ButtonHudgetVoxels(this, direction, textOrientation, scale, content, fontSize, buttonStyle)),
m_callback(callback)
{
m_buttonVoxels->updateBounds();
}

ButtonHudget::~ButtonHudget() = default;

void ButtonHudget::update(float deltaSec) {
}

void ButtonHudget::draw() {
m_buttonVoxels->draw();
}

bool ButtonHudget::isAt(const Ray& ray) const {
return m_buttonVoxels->isAt(ray);
}

void ButtonHudget::onClick(ClickType clickType) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather like

if(m_callback)
m_callback(clickType)

mmh?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link

Choose a reason for hiding this comment

The 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.

if (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);
}
40 changes: 40 additions & 0 deletions src/ui/hud/buttonhudget.h
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, const glm::vec3& direction, const std::function<void(ClickType clickType)>& callback, TextOrientation textOrientation = TextOrientation::FORWARDS, float scale = 0.5f, const std::string& content = "", FontSize fontSize = FontSize::SIZE5x7, ButtonStyle borderStyle = ButtonStyle::BORDERED);
virtual ~ButtonHudget();

virtual void update(float deltaSec) override;
virtual void draw() override;

virtual bool isAt(const Ray& ray) const override;

virtual void onClick(ClickType clicktype) override;

void setText(const std::string& content);

void setCallback(const std::function<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;
};

Loading