Very jank but now I can set different panels as active and test for mouse events in them to enable mouse. This needs a big cleanup and probably some FSM love.

main
Zed A. Shaw 1 week ago
parent f0829bb9ea
commit 941be008f8
  1. 18
      gui.cpp
  2. 1
      gui.hpp
  3. 1
      panel.cpp

@ -84,8 +84,6 @@ void StatusUI::create_render() {
GUI::GUI(DinkyECS::World &world, Map& game_map) :
$game_map(game_map),
$status_ui(world),
$map_view(),
$inventory_ui(),
$lights(game_map.width(), game_map.height()),
$world(world),
$sounds("./assets"),
@ -105,7 +103,6 @@ void GUI::resize_map(int new_size) {
$renderer.resize_grid(new_size, $map_view);
// set canvas to best size
$canvas = Canvas($map_view.width * 2, $map_view.height * 4);
dbc::log("WHY IS RESIZING LIGHTS STILL WORKING?!!!!!!!!!!!!!!!");
}
void GUI::save_world() {
@ -123,6 +120,9 @@ void GUI::create_renderer() {
$status_ui.create_render();
$inventory_ui.create_render();
// don't activate this one
$panels = {&$map_view, &$status_ui};
}
void GUI::handle_world_events() {
@ -209,9 +209,11 @@ bool GUI::handle_ui_events() {
} else if(KB::isKeyPressed(KB::I)) {
// yes, using an if to avoid double grabbing screen
if($show_modal) {
$panels = {&$map_view, &$status_ui};
$show_modal = false;
} else {
pause_screen();
$panels = {&$inventory_ui};
$show_modal = true;
}
} else if(KB::isKeyPressed(KB::P)) {
@ -224,12 +226,16 @@ bool GUI::handle_ui_events() {
} else if(KB::isKeyPressed(KB::Enter)) {
$status_ui.key_press(Event::Return);
}
} else if($renderer.mouse_position($status_ui, pos)) {
} else {
for(Panel *panel : $panels) {
if($renderer.mouse_position(*panel, pos)) {
if(MOUSE::isButtonPressed(MOUSE::Left)) {
$status_ui.mouse_click(Mouse::Button::Left, pos);
panel->mouse_click(Mouse::Button::Left, pos);
event_happened = true;
} else {
$status_ui.mouse_release(Mouse::Button::Left, pos);
panel->mouse_release(Mouse::Button::Left, pos);
}
}
}
}
}

@ -89,6 +89,7 @@ class GUI {
SoundManager $sounds;
SFMLRender $renderer;
UnDumbTSS $paused;
std::vector<Panel*> $panels;
public:
GUI(DinkyECS::World& world, Map& game_map);

@ -36,6 +36,7 @@ const std::wstring& Panel::to_string() {
}
void Panel::mouse_click(ftxui::Mouse::Button btn, Point pos) {
fmt::println("CLICK AT {},{}", pos.x, pos.y);
ftxui::Mouse mev{
.button=btn,
.motion=ftxui::Mouse::Motion::Pressed,

Loading…
Cancel
Save