Reworked the gui to use GUECS now so lots of code soon to die.
This commit is contained in:
parent
e78340a0cd
commit
70c2ce7d51
9 changed files with 97 additions and 38 deletions
52
gui.cpp
52
gui.cpp
|
@ -14,7 +14,41 @@
|
|||
|
||||
using std::string, std::vector;
|
||||
|
||||
GUI::GUI(SFMLBackend &backend) : gui(backend) {
|
||||
GUI::GUI(SFMLBackend &backend) : sfml(backend) {
|
||||
using namespace guecs;
|
||||
|
||||
$gui.position(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
$gui.layout(
|
||||
"[*%(200,300)face|_|*%(100,300)stats|*%(200,500)log|_]"
|
||||
"[_|_|_|_|_]"
|
||||
"[_|_|_|_|_]"
|
||||
"[*%(300,200)clock|_|_|_|_]"
|
||||
"[_|_|_|_|_]"
|
||||
"[hp_bar]");
|
||||
|
||||
$gui.world().set_the<Background>({$gui.$parser, ColorValue::DARK_MID});
|
||||
|
||||
for(auto& [name, cell] : $gui.cells()) {
|
||||
auto ent = $gui.entity(name);
|
||||
$gui.set<Rectangle>(ent, {});
|
||||
}
|
||||
|
||||
auto face = $gui.entity("face");
|
||||
$gui.set<Sprite>(face, {"building"});
|
||||
|
||||
auto stats = $gui.entity("stats");
|
||||
$gui.set<Textual>(stats, {L"STATS"});
|
||||
|
||||
auto log = $gui.entity("log");
|
||||
$gui.set<Textual>(log, {L"LOG"});
|
||||
|
||||
auto clock = $gui.entity("clock");
|
||||
$gui.set<Label>(clock, {L"00:00:00", 110});
|
||||
|
||||
auto hp_bar = $gui.entity("hp_bar");
|
||||
$gui.set<Meter>(hp_bar, {});
|
||||
|
||||
$gui.init();
|
||||
}
|
||||
|
||||
void GUI::output(const string msg) {
|
||||
|
@ -23,20 +57,22 @@ void GUI::output(const string msg) {
|
|||
}
|
||||
|
||||
void GUI::main_loop() {
|
||||
gui.handle_events();
|
||||
gui.update_entities();
|
||||
gui.update_log(_lines);
|
||||
$gui.render(sfml.window);
|
||||
// $gui.debug_layout(sfml.window);
|
||||
sfml.handle_events();
|
||||
// sfml.update_entities();
|
||||
sfml.update_log(_lines);
|
||||
}
|
||||
|
||||
void GUI::build_success() {
|
||||
gui.change_face("build_success");
|
||||
sfml.change_face("build_success");
|
||||
sound::stop("building");
|
||||
sound::play("build_success");
|
||||
output("BUILD FINISHED!");
|
||||
}
|
||||
|
||||
void GUI::build_failed(bool play_sound, const string &command) {
|
||||
gui.change_face("build_failed");
|
||||
sfml.change_face("build_failed");
|
||||
sound::stop("building");
|
||||
|
||||
if(play_sound) {
|
||||
|
@ -47,7 +83,7 @@ void GUI::build_failed(bool play_sound, const string &command) {
|
|||
}
|
||||
|
||||
void GUI::you_died() {
|
||||
gui.change_face("you_died");
|
||||
sfml.change_face("you_died");
|
||||
sound::stop("building");
|
||||
sound::play("you_died");
|
||||
output("!!!! YOU DIED! !!!! Learn to code luser.");
|
||||
|
@ -55,7 +91,7 @@ void GUI::you_died() {
|
|||
}
|
||||
|
||||
void GUI::building() {
|
||||
gui.change_face("building");
|
||||
sfml.change_face("building");
|
||||
output("############# START ############");
|
||||
output(">>>> Will it Build?");
|
||||
sound::play("building");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue