Commit ddc0ccae authored by Michael Ochmann's avatar Michael Ochmann
Browse files

menu state is now fully working

parent 9b26fd3a
[
{
"type" : "box",
"id" : "credits",
"background" : "00000000",
"x" : 0,
"y" : 0,
"height" : 100,
"width" : 100,
"childs" : [
{
"type" : "textured",
"id" : "creditsBackdrop",
"background" : "ui/backdrop/Komp 1_00001.png",
"frametime" : 0.07,
"x" : 0,
"y" : 0,
"height" : 100,
"width" : "auto",
"childs" : []
},
{
"type" : "box",
"id" : "scroll",
"background" : "00000000",
"x" : 0,
"y" : 0,
"height" : 100,
"width" : 100,
"childs" : []
}
]
}
]
\ No newline at end of file
[
{
"title" : "Gameplay",
"members" : [
"Elias Broschin",
"Jeremias Boos"
]
},
{
"title" : "Gameplay",
"members" : [
"Elias Broschin",
"Jeremias Boos"
]
},
{
"title" : "Gameplay",
"members" : [
"Elias Broschin",
"Jeremias Boos"
]
},
{
"title" : "Gameplay",
"members" : [
"Elias Broschin",
"Jeremias Boos"
]
},
{
"title" : "Gameplay",
"members" : [
"Elias Broschin",
"Jeremias Boos"
]
}
]
\ No newline at end of file
[
{
"type" : "box",
"id" : "menu",
"background" : "00000000",
"x" : 0,
"y" : 0,
"height" : 100,
"width" : 100,
"childs" : [
{
"type" : "animation",
"id" : "menBackdrop",
"frames" : [
"ui/backdrop/Komp 1_00000.png",
"ui/backdrop/Komp 1_00001.png",
"ui/backdrop/Komp 1_00002.png",
"ui/backdrop/Komp 1_00003.png",
"ui/backdrop/Komp 1_00004.png",
"ui/backdrop/Komp 1_00005.png",
"ui/backdrop/Komp 1_00006.png",
"ui/backdrop/Komp 1_00007.png",
"ui/backdrop/Komp 1_00008.png",
"ui/backdrop/Komp 1_00009.png",
"ui/backdrop/Komp 1_00010.png",
"ui/backdrop/Komp 1_00011.png",
"ui/backdrop/Komp 1_00012.png",
"ui/backdrop/Komp 1_00013.png",
"ui/backdrop/Komp 1_00014.png",
"ui/backdrop/Komp 1_00015.png",
"ui/backdrop/Komp 1_00016.png",
"ui/backdrop/Komp 1_00017.png",
"ui/backdrop/Komp 1_00018.png",
"ui/backdrop/Komp 1_00019.png",
"ui/backdrop/Komp 1_00020.png",
"ui/backdrop/Komp 1_00021.png",
"ui/backdrop/Komp 1_00022.png",
"ui/backdrop/Komp 1_00023.png",
"ui/backdrop/Komp 1_00024.png",
"ui/backdrop/Komp 1_00025.png",
"ui/backdrop/Komp 1_00026.png",
"ui/backdrop/Komp 1_00027.png",
"ui/backdrop/Komp 1_00028.png",
"ui/backdrop/Komp 1_00029.png"
],
"frametime" : 0.07,
{
"type" : "box",
"id" : "menu",
"background" : "00000000",
"x" : 0,
"y" : 0,
"height" : 100,
"width" : "auto",
"width" : 100,
"childs" : [
{
"type" : "text",
"id" : "title",
"font" : "FreebooterUpdated",
"fontsize" : 70,
"text" : "DETH BUFF ARR",
"color" : "000000FF",
"x" : 1,
"y" : 6,
"height" : 100,
"width" : 100,
"childs" : []
}
{
"type" : "animation",
"id" : "menBackdrop",
"frames" : [
"ui/backdrop/Komp 1_00000.png",
"ui/backdrop/Komp 1_00001.png",
"ui/backdrop/Komp 1_00002.png"
//,
//"ui/backdrop/Komp 1_00003.png",
//"ui/backdrop/Komp 1_00004.png",
//"ui/backdrop/Komp 1_00005.png",
//"ui/backdrop/Komp 1_00006.png",
//"ui/backdrop/Komp 1_00007.png",
//"ui/backdrop/Komp 1_00008.png",
//"ui/backdrop/Komp 1_00009.png",
//"ui/backdrop/Komp 1_00010.png",
//"ui/backdrop/Komp 1_00011.png",
//"ui/backdrop/Komp 1_00012.png",
//"ui/backdrop/Komp 1_00013.png",
//"ui/backdrop/Komp 1_00014.png",
//"ui/backdrop/Komp 1_00015.png",
//"ui/backdrop/Komp 1_00016.png",
//"ui/backdrop/Komp 1_00017.png",
//"ui/backdrop/Komp 1_00018.png",
//"ui/backdrop/Komp 1_00019.png",
//"ui/backdrop/Komp 1_00020.png",
//"ui/backdrop/Komp 1_00021.png",
//"ui/backdrop/Komp 1_00022.png",
//"ui/backdrop/Komp 1_00023.png",
//"ui/backdrop/Komp 1_00024.png",
//"ui/backdrop/Komp 1_00025.png",
//"ui/backdrop/Komp 1_00026.png",
//"ui/backdrop/Komp 1_00027.png",
//"ui/backdrop/Komp 1_00028.png",
//"ui/backdrop/Komp 1_00029.png"
],
"frametime" : 0.07,
"x" : 0,
"y" : 0,
"height" : 100,
"width" : "auto",
"childs" : [
{
"type" : "text",
"id" : "title",
"font" : "FreebooterUpdated",
"fontsize" : 80,
"text" : "DETH BUFF ARR",
"color" : "000000FF",
"x" : 2,
"y" : 6,
"height" : 100,
"width" : 100,
"childs" : []
},
{
"type" : "box",
"id" : "startGameButton",
"background": "00000000",
"x" : 5,
"y" : 40,
"height" : 8,
"width" : 20,
"childs" : [
{
"type" : "text",
"id" : "startGame",
"font" : "FreebooterUpdated",
"fontsize" : 80,
"text" : "Start Game",
"color" : "000000FF",
"x" : 0,
"y" : 20,
"height" : 100,
"width" : 100,
"childs" : []
}
]
},
{
"type" : "box",
"id" : "creditsButton",
"background": "00000000",
"x" : 5,
"y" : 50,
"height" : 8,
"width" : 20,
"childs" : [
{
"type" : "text",
"id" : "credits",
"font" : "FreebooterUpdated",
"fontsize" : 80,
"text" : "Credits",
"color" : "000000FF",
"x" : 0,
"y" : 20,
"height" : 100,
"width" : 100,
"childs" : []
}
]
},
{
"type" : "box",
"id" : "quitButton",
"background": "00000000",
"x" : 5,
"y" : 60,
"height" : 8,
"width" : 20,
"childs" : [
{
"type" : "text",
"id" : "quit",
"font" : "FreebooterUpdated",
"fontsize" : 80,
"text" : "Quit",
"color" : "000000FF",
"x" : 0,
"y" : 20,
"height" : 100,
"width" : 100,
"childs" : []
}
]
}
]
}
]
}
]
}
}
]
\ No newline at end of file
#ifndef GDW_SS15_CPP_CREDITS_STATE_HPP
#define GDW_SS15_CPP_CREDITS_STATE_HPP
#include <game_state_machine/game_state.h>
namespace gdw {
class credits_state : public game_state {
public:
credits_state(engine& engine);
~credits_state();
void update(float dt);
void on_enter();
void on_exit();
};
} //Namespace gdw
#endif //GDW_SS15_CPP_CREDITS_STATE_HPP
......@@ -21,9 +21,9 @@ namespace gdw{
CENTER,
};*/
using on_hover_function = void(*)(float x, float y);
using on_pressed_function = void(*)(float x, float y);
using on_released_function = void(*)(float x, float y);
using on_hover_function = std::function<void(float , float )>;
using on_pressed_function = std::function<void(float , float)>;
using on_released_function = std::function<void(float , float )>;
class ui_widget{
private:
......@@ -139,18 +139,18 @@ namespace gdw{
}
void add_on_hover(on_hover_function fun){
on_hover_functions_.push_back(fun);
on_hover_functions_.emplace_back(fun);
}
void add_on_pressed(on_pressed_function fun){
on_pressed_functions_.push_back(fun);
on_pressed_functions_.emplace_back(fun);
}
void add_on_released(on_released_function fun){
on_released_functions_.push_back(fun);
on_released_functions_.emplace_back(fun);
}
void remove_on_hover(on_hover_function fun){
/*void remove_on_hover(on_hover_function fun){
auto found = std::find(on_hover_functions_.begin(),on_hover_functions_.end(),fun);
if(found == on_hover_functions_.end())
return;
......@@ -162,15 +162,15 @@ namespace gdw{
auto found = std::find(on_pressed_functions_.begin(),on_pressed_functions_.end(),fun);
if(found == on_pressed_functions_.end())
return;
on_pressed_functions_.push_back(fun);
on_pressed_functions_.erase(found);
}
void remove_on_released(on_released_function fun){
auto found = std::find(on_released_functions_.begin(),on_released_functions_.end(),fun);
if(found == on_released_functions_.end())
return;
on_released_functions_.push_back(fun);
}
on_released_functions_.erase(found);
}*/
};
}
#endif //GDW_SS15_CPP_UI_WIDGET_HPP
......@@ -7,7 +7,6 @@
namespace gdw {
namespace fsi {
static std::vector<std::string> explode(const std::string &str, char delimiter) {
std::vector<std::string> tokens;
std::stringstream inStream(str);
......@@ -35,6 +34,8 @@ namespace gdw {
return glm::vec4(r/255.0f, g/255.0f, b/255.0f, a/255.0f);
}
const glm::vec4 color = fsi::hexToVec4("005196");
static std::string secondsToTimestamp(float secondsFloat, bool millis = false) {
int hours = (int)floor(secondsFloat / 60 / 60);
int minutes = (int)floor(secondsFloat / 60) % 60;
......
lodepng @ eb16d900
Subproject commit eb16d900b2e82c01ba9d81b376e7fd7419edd15b
#include <game_state_machine/credits_state.hpp>
#include <util/id.hpp>
#include <util/logger.hpp>
#include <core/engine.hpp>
#include <ecs/entity_manager.hpp>
#include <glm/glm.hpp>
#include <glm/gtx/quaternion.hpp>
#include <ecs/entity.hpp>
#include <input/input.hpp>
#include <game_state_machine/game_state_machine.h>
#include <game_state_machine/game_state.h>
#include <game_state_machine/play_state.h>
#include <ui/ui_system.hpp>
#include <ui/UIManager.hpp>
#include <ui/text_widget.hpp>
#include <util/fsi.hpp>
#include <util/jsoncpp.hpp>
#include <game_state_machine/game_state_machine.h>
#include <game_state_machine/menu_state.h>
namespace gdw {
credits_state::credits_state(engine &engine):game_state(engine) {
id_ = type_id<credits_state>();
this->uiManager = make_unique<gdw::UIManager>(this->engine_, "ui/credits.json");
auto file = this->engine_.asset_manager().load("ui/creditsText.json");
if (!file) {
log(log_level::error) << "Could not load UI file 'creditsText'" << std::endl;
}
Json::Value dom;
Json::Reader reader;
if (!reader.parse(&(*file->content().begin()), &(*file->content().end()), dom))
log << "error loading jsonz" << std::endl;
text_widget* screen = (text_widget*) this->uiManager->getElementById("scroll");
this->engine_.ui_system().loadFont("font/FreebooterUpdated.ttf");
int top = 1;
float oldY = 0;
for (auto &widget : dom) {
text_widget* test = (text_widget*) screen->add_widget<text_widget>(25/100.f,top*5/100.f + oldY,100/100.f,100/100.f,"FreebooterUpdated",
widget["title"].asString(),
80, fsi::hexToVec4("000000FF"),
NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE
);
oldY += top*5/100.f;
int top2 = 1;
for (Json::Value::iterator it = widget["members"].begin(); it != widget["members"].end(); ++it) {
screen->add_widget<text_widget>(25/100.f,
(test->y() + test->height() + oldY + top2 * 2)/100.f,
100/100.f,100/100.f,"FreebooterUpdated",
(*it).asString(),
50, fsi::hexToVec4("000000FF"),
NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE
);
oldY +=top2 * 2;
top2++;
}
top++;
}
}
credits_state::~credits_state() {}
void credits_state::on_enter() {
this->uiManager->render(true);
}
void credits_state::update(float dt) {
if (this->engine_.input().isPressed(inputMapping::state_switch))
this->engine_.game_state_machine().change_state<menu_state>();
//this->uiManager->getElementById("scroll")->y(this->uiManager->getElementById("scroll")->y() - 0.001);
}
void credits_state::on_exit() {
this->uiManager->render(false);
}
} //namespace gdw
......@@ -4,12 +4,14 @@
#include <util/make_unique.hpp>
#include <game_state_machine/play_state.h>
#include <game_state_machine/menu_state.h>
#include <game_state_machine/credits_state.hpp>
namespace gdw {
game_state_machine::game_state_machine(engine& engine):engine_(engine), current_state_(nullptr) {
game_states_[type_id<play_state>()] = make_unique<play_state>(engine);
game_states_[type_id<menu_state>()] = make_unique<menu_state>(engine);
game_states_[type_id<credits_state>()] = make_unique<credits_state>(engine);
//default state
//current_state_ = game_states_[type_id<play_state>()].get();
......
......@@ -9,12 +9,45 @@
#include <game_state_machine/game_state_machine.h>
#include <game_state_machine/play_state.h>
#include <ui/UIManager.hpp>
#include <ui/text_widget.hpp>
#include <util/fsi.hpp>
#include <game_state_machine/credits_state.hpp>
namespace gdw {
menu_state::menu_state(engine &engine):game_state(engine) {
id_ = type_id<menu_state>();
this->uiManager = make_unique<gdw::UIManager>(this->engine_, "ui/menu.json");
/**
* Dont look at this code, it just ugly highlights the menu items
*/
text_widget* button = (text_widget*) this->uiManager->getElementById("startGame");
button->add_on_hover([button](float x, float y) {
button->color(fsi::hexToVec4("ffc514ff"));
});
text_widget* button2 = (text_widget*) this->uiManager->getElementById("credits");
button2->add_on_hover([button2](float x, float y) {
button2->color(fsi::hexToVec4("ffc514ff"));
});
text_widget* button3 = (text_widget*) this->uiManager->getElementById("quit");
button3->add_on_hover([button3](float x, float y) {
button3->color(fsi::hexToVec4("ffc514ff"));
});
/**
* Click action for menu buttons
*/
button->add_on_released([this](float x, float y) {
this->engine_.game_state_machine().change_state<play_state>();
});
button2->add_on_released([this](float x, float y) {
this->engine_.game_state_machine().change_state<credits_state>();
});
button3->add_on_released([this](float x, float y) {
this->engine_.quit();
});
}
menu_state::~menu_state() {}
......@@ -24,6 +57,15 @@ void menu_state::on_enter() {
}
void menu_state::update(float dt) {
/**
* Dont look at this code, it just ugly highlights the menu items
*/
text_widget* button1 = (text_widget*) this->uiManager->getElementById("startGame");
button1->color(fsi::hexToVec4("000000FF"));
text_widget* button2 = (text_widget*) this->uiManager->getElementById("credits");
button2->color(fsi::hexToVec4("000000FF"));
text_widget* button3 = (text_widget*) this->uiManager->getElementById("quit");
button3->color(fsi::hexToVec4("000000FF"));
if (this->engine_.input().isPressed(inputMapping::state_switch))
this->engine_.game_state_machine().change_state<play_state>();
}
......
......@@ -419,6 +419,6 @@ namespace gdw {
engine_.game_play_system().gamemanager().add_points(1);
items_to_create.emplace_back(item_spawn_pos);
}
}aaa
}
} //Namespace gdw
......@@ -31,7 +31,7 @@ namespace gdw {
Json::Value dom;
Json::Reader reader;
if (!reader.parse(&(*file->content().begin()), &(*file->content().end()), dom))
log << "error loading json" << std::endl;
log << "error parsing json '" << filename << "'" << std::endl;
for (auto &widget : dom) {
this->widgets[widget["id"].asString()] = this->createWidget((gdw::ui_widget*) &this->engine.ui_system(), widget);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment