The level number is now displayed on the next level screen.
This commit is contained in:
parent
b5c2fc3b5f
commit
bc0912e577
11 changed files with 84 additions and 46 deletions
|
|
@ -31,7 +31,7 @@ namespace scene {
|
|||
|
||||
bool at_mid = config["at_mid"];
|
||||
|
||||
sf::Text text(*$ui.$font, "", 60);
|
||||
sf::Text text(*$gui.$font, "", 60);
|
||||
|
||||
return {name, st, anim, cell, {scale_x, scale_y}, {x, y}, at_mid, flipped, nullptr, text};
|
||||
}
|
||||
|
|
@ -60,12 +60,12 @@ namespace scene {
|
|||
void Engine::init() {
|
||||
dbc::log($F("initialized scene with background {}", $scene.background));
|
||||
|
||||
$ui.position(SCENE_VIEW_X, SCENE_VIEW_Y, SCENE_VIEW_WIDTH, SCENE_VIEW_HEIGHT);
|
||||
$ui.set<guecs::Background>($ui.MAIN, {$ui.$parser, guecs::THEME.TRANSPARENT});
|
||||
auto& background = $ui.get<guecs::Background>($ui.MAIN);
|
||||
$gui.position(SCENE_VIEW_X, SCENE_VIEW_Y, SCENE_VIEW_WIDTH, SCENE_VIEW_HEIGHT);
|
||||
$gui.set<guecs::Background>($gui.MAIN, {$gui.$parser, guecs::THEME.TRANSPARENT});
|
||||
auto& background = $gui.get<guecs::Background>($gui.MAIN);
|
||||
background.set_sprite($scene.background, true);
|
||||
|
||||
$ui.layout($layout);
|
||||
$gui.layout($layout);
|
||||
|
||||
for(auto& actor : $actors) {
|
||||
actor.pos = position_sprite(actor.st, actor.cell,
|
||||
|
|
@ -76,6 +76,17 @@ namespace scene {
|
|||
fixture.pos = position_sprite(fixture.st, fixture.cell,
|
||||
fixture.scale, fixture.at_mid, fixture.pos.x, fixture.pos.y);
|
||||
}
|
||||
|
||||
if($gui.contains("text")) {
|
||||
auto text_id = $gui.entity("text");
|
||||
auto bg_color = guecs::THEME.DARK_DARK;
|
||||
bg_color.a = 100;
|
||||
// BUG: guecs should initialize anything added if it needs it
|
||||
$gui.set<guecs::Rectangle>(text_id, {0, bg_color});
|
||||
$gui.set<guecs::Text>(text_id, {L"", 55});
|
||||
}
|
||||
|
||||
$gui.init();
|
||||
}
|
||||
|
||||
void Engine::apply_effect(const std::string& actor, const std::string& shader) {
|
||||
|
|
@ -94,11 +105,11 @@ namespace scene {
|
|||
}
|
||||
|
||||
bool Engine::mouse(float x, float y, guecs::Modifiers mods) {
|
||||
return $ui.mouse(x, y, mods);
|
||||
return $gui.mouse(x, y, mods);
|
||||
}
|
||||
|
||||
void Engine::render(sf::RenderTexture& view) {
|
||||
$ui.render(view);
|
||||
$gui.render(view);
|
||||
|
||||
for(auto& fixture : $fixtures) {
|
||||
view.draw(*fixture.st.sprite, fixture.effect.get());
|
||||
|
|
@ -110,7 +121,7 @@ namespace scene {
|
|||
}
|
||||
|
||||
$camera.render(view);
|
||||
if(DEBUG) $ui.debug_layout(view);
|
||||
if(DEBUG) $gui.debug_layout(view);
|
||||
|
||||
// BUG: should I do this here or let the caller do it?
|
||||
view.display();
|
||||
|
|
@ -158,7 +169,7 @@ namespace scene {
|
|||
}
|
||||
|
||||
sf::Vector2f Engine::position_sprite(textures::SpriteTexture& st, const std::string& cell_name, sf::Vector2f scale, bool at_mid, float x_diff, float y_diff) {
|
||||
auto& cell = $ui.cell_for(cell_name);
|
||||
auto& cell = $gui.cell_for(cell_name);
|
||||
float x = float(at_mid ? cell.mid_x : cell.x);
|
||||
float y = float(at_mid ? cell.mid_y : cell.y);
|
||||
|
||||
|
|
@ -203,4 +214,11 @@ namespace scene {
|
|||
void Engine::reset(sf::RenderTexture& view) {
|
||||
$camera.reset(view);
|
||||
}
|
||||
|
||||
void Engine::set_text(const std::string& content) {
|
||||
if($gui.contains("text")) {
|
||||
auto el = $gui.get_if<guecs::Text>($gui.entity("text"));
|
||||
el->text->setString(guecs::to_wstring(content));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ namespace scene {
|
|||
|
||||
struct Engine {
|
||||
sf::Clock $clock;
|
||||
guecs::UI $ui;
|
||||
guecs::UI $gui;
|
||||
components::AnimatedScene& $scene;
|
||||
std::string $layout;
|
||||
std::unordered_map<std::string, int> $actor_name_ids;
|
||||
|
|
@ -46,7 +46,7 @@ namespace scene {
|
|||
void attach_text(const std::string& actor, const std::string& text);
|
||||
|
||||
nlohmann::json& buttons() { return $scene.buttons; };
|
||||
lel::Cell& button_cell() { return $ui.cell_for("buttons"); }
|
||||
lel::Cell& button_cell() { return $gui.cell_for("buttons"); }
|
||||
|
||||
Element config_scene_element(nlohmann::json& config, bool duped);
|
||||
|
||||
|
|
@ -60,5 +60,6 @@ namespace scene {
|
|||
void zoom(float mid_x, float mid_y, const std::string& style, float scale);
|
||||
void reset(sf::RenderTexture& view);
|
||||
void set_end_cb(std::function<void()> cb);
|
||||
void set_text(const std::string& content);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -592,8 +592,9 @@ namespace gui {
|
|||
auto config = settings::get("config");
|
||||
size_t levels_to_win = config["game_play"]["levels_to_win"];
|
||||
|
||||
if(level.index <= levels_to_win) {
|
||||
if(level.index < levels_to_win) {
|
||||
show_scene("NEXT_LEVEL");
|
||||
$cur_scene->set_text(fmt::format("ENTERING\nLEVEL\n{}", level.index+2));
|
||||
state(State::NEXT_LEVEL_SCENE);
|
||||
} else {
|
||||
show_scene("WIN");
|
||||
|
|
|
|||
|
|
@ -29,22 +29,26 @@ namespace gui {
|
|||
|
||||
auto& button_cell = $scene.button_cell();
|
||||
|
||||
$ui.position(button_cell.x, button_cell.y, button_cell.w, button_cell.h);
|
||||
$ui.layout(layout);
|
||||
$gui.position(button_cell.x, button_cell.y, button_cell.w, button_cell.h);
|
||||
$gui.layout(layout);
|
||||
|
||||
for(auto& [name, cell] : $ui.cells()) {
|
||||
auto ui_id = $ui.entity(name);
|
||||
$ui.set<guecs::Text>(ui_id, {guecs::to_wstring(name)});
|
||||
$ui.set<guecs::Rectangle>(ui_id, {});
|
||||
$ui.set<guecs::Effect>(ui_id, {});
|
||||
for(auto& [name, cell] : $gui.cells()) {
|
||||
auto ui_id = $gui.entity(name);
|
||||
$gui.set<guecs::Text>(ui_id, {guecs::to_wstring(name)});
|
||||
$gui.set<guecs::Rectangle>(ui_id, {5, guecs::THEME.DARK_MID});
|
||||
$gui.set<guecs::Effect>(ui_id, {});
|
||||
|
||||
if(actions.contains(name)) {
|
||||
auto event_id = actions[name];
|
||||
$ui.set<guecs::Clickable>(ui_id, guecs::make_action(ui_id, event_id));
|
||||
$gui.set<guecs::Clickable>(ui_id, guecs::make_action(ui_id, event_id));
|
||||
}
|
||||
}
|
||||
|
||||
$ui.init();
|
||||
$gui.init();
|
||||
}
|
||||
|
||||
void SceneUI::set_text(const std::string& text) {
|
||||
$scene.set_text(text);
|
||||
}
|
||||
|
||||
void SceneUI::render(sf::RenderTarget &target) {
|
||||
|
|
@ -52,8 +56,8 @@ namespace gui {
|
|||
target.draw($view_sprite);
|
||||
|
||||
if(has_buttons) {
|
||||
$ui.render(target);
|
||||
if(DEBUG) $ui.debug_layout(target);
|
||||
$gui.render(target);
|
||||
if(DEBUG) $gui.debug_layout(target);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -63,7 +67,7 @@ namespace gui {
|
|||
|
||||
bool SceneUI::mouse(float x, float y, guecs::Modifiers mods) {
|
||||
$scene.mouse(x, y, mods);
|
||||
$ui.mouse(x, y, mods);
|
||||
$gui.mouse(x, y, mods);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace gui {
|
|||
AnimatedScene $scene_data{load_scene(name)};
|
||||
scene::Engine $scene{$scene_data};
|
||||
bool has_buttons = false;
|
||||
guecs::UI $ui;
|
||||
guecs::UI $gui;
|
||||
|
||||
AnimatedScene load_scene(const std::string& name);
|
||||
void create_buttons(nlohmann::json& buttons);
|
||||
|
|
@ -22,5 +22,6 @@ namespace gui {
|
|||
void render(sf::RenderTarget &target);
|
||||
void update();
|
||||
bool mouse(float x, float y, guecs::Modifiers mods);
|
||||
void set_text(const std::string& text);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,12 +32,16 @@ namespace gui {
|
|||
for(auto& [name, cell] : $gui.cells()) {
|
||||
auto gui_id = $gui.entity(name);
|
||||
|
||||
$gui.set<Text>(gui_id, {guecs::to_wstring(name)});
|
||||
|
||||
if(name.starts_with("body_")) {
|
||||
auto& cell = $gui.cell_for(name);
|
||||
$body_ui.init(cell.x, cell.y, cell.w, cell.h);
|
||||
} else {
|
||||
// don't show inventory names
|
||||
if(!name.starts_with("inv")) {
|
||||
$gui.set<Text>(gui_id, {guecs::to_wstring(name)});
|
||||
}
|
||||
|
||||
$gui.set<Rectangle>(gui_id, {});
|
||||
$gui.set<Clickable>(gui_id, {
|
||||
guecs::make_action(gui_id, game::Event::INV_SELECT, {gui_id})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue