The gui can now pop open a modal based on clicking a button but I need to manage focus next.

main
Zed A. Shaw 6 days ago
parent 34c84343db
commit 64855f3c90
  1. 92
      ansi_parser.cpp
  2. 4
      ansi_parser.rl
  3. 24
      gui.cpp
  4. 2
      gui.hpp
  5. 1
      render.cpp
  6. 2
      status.txt

@ -10,7 +10,7 @@
using namespace fmt;
#line 107 "ansi_parser.rl"
#line 110 "ansi_parser.rl"
@ -24,15 +24,16 @@ static const char _foo_actions[] = {
};
static const char _foo_key_offsets[] = {
0, 0, 1, 2, 8, 9, 11, 12,
15, 16, 17, 18, 20, 23, 25, 28,
30, 33, 34, 37, 38, 39, 40, 41,
42
0, 0, 1, 2, 10, 11, 13, 16,
19, 20, 23, 24, 25, 26, 28, 31,
33, 36, 38, 41, 42, 45, 46, 47,
48, 49, 50
};
static const int _foo_trans_keys[] = {
27, 91, 50, 51, 52, 55, 48, 54,
109, 55, 109, 109, 56, 57, 109, 59,
27, 91, 49, 50, 51, 52, 55, 57,
48, 54, 109, 48, 109, 34, 48, 55,
50, 55, 109, 109, 56, 57, 109, 59,
50, 59, 48, 57, 59, 48, 57, 48,
57, 59, 48, 57, 48, 57, 109, 48,
57, 109, 56, 57, 109, 59, 50, 109,
@ -40,63 +41,65 @@ static const int _foo_trans_keys[] = {
};
static const char _foo_single_lengths[] = {
0, 1, 1, 4, 1, 2, 1, 3,
1, 1, 1, 0, 1, 0, 1, 0,
1, 1, 3, 1, 1, 1, 1, 1,
1
0, 1, 1, 6, 1, 2, 3, 3,
1, 3, 1, 1, 1, 0, 1, 0,
1, 0, 1, 1, 3, 1, 1, 1,
1, 1, 1
};
static const char _foo_range_lengths[] = {
0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 1, 1, 1, 1, 1,
1, 0, 0, 0, 0, 0, 0, 0,
0
0, 0, 0, 0, 0, 1, 1, 1,
1, 1, 1, 0, 0, 0, 0, 0,
0, 0, 0
};
static const char _foo_index_offsets[] = {
0, 0, 2, 4, 10, 12, 15, 17,
21, 23, 25, 27, 29, 32, 34, 37,
39, 42, 44, 48, 50, 52, 54, 56,
58
0, 0, 2, 4, 12, 14, 17, 21,
25, 27, 31, 33, 35, 37, 39, 42,
44, 47, 49, 52, 54, 58, 60, 62,
64, 66, 68
};
static const char _foo_trans_targs[] = {
2, 1, 3, 0, 5, 7, 18, 22,
4, 0, 24, 0, 6, 24, 0, 24,
0, 8, 17, 24, 0, 9, 0, 10,
0, 11, 0, 12, 0, 13, 12, 0,
14, 0, 15, 14, 0, 16, 0, 24,
16, 0, 24, 0, 19, 21, 24, 0,
20, 0, 10, 0, 24, 0, 24, 0,
2, 1, 2, 1, 0
2, 1, 3, 0, 5, 7, 9, 20,
24, 6, 4, 0, 26, 0, 6, 26,
0, 4, 4, 4, 0, 4, 8, 26,
0, 26, 0, 10, 19, 26, 0, 11,
0, 12, 0, 13, 0, 14, 0, 15,
14, 0, 16, 0, 17, 16, 0, 18,
0, 26, 18, 0, 26, 0, 21, 23,
26, 0, 22, 0, 12, 0, 26, 0,
26, 0, 2, 1, 2, 1, 0
};
static const char _foo_trans_actions[] = {
0, 7, 0, 0, 19, 19, 19, 19,
19, 0, 0, 0, 0, 17, 0, 15,
0, 0, 0, 0, 0, 0, 0, 3,
0, 0, 0, 1, 0, 23, 0, 0,
1, 0, 26, 0, 0, 1, 0, 32,
0, 0, 9, 0, 0, 0, 0, 0,
0, 0, 5, 0, 11, 0, 13, 0,
0, 7, 21, 29, 0
19, 19, 19, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 17,
0, 15, 0, 0, 0, 0, 0, 0,
0, 3, 0, 0, 0, 1, 0, 23,
0, 0, 1, 0, 26, 0, 0, 1,
0, 32, 0, 0, 9, 0, 0, 0,
0, 0, 0, 0, 5, 0, 11, 0,
13, 0, 0, 7, 21, 29, 0
};
static const char _foo_eof_actions[] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
21
0, 0, 21
};
static const int foo_start = 23;
static const int foo_first_final = 23;
static const int foo_start = 25;
static const int foo_first_final = 25;
static const int foo_error = 0;
static const int foo_en_main = 23;
static const int foo_en_main = 25;
#line 110 "ansi_parser.rl"
#line 113 "ansi_parser.rl"
#include <ftxui/screen/terminal.hpp>
@ -122,14 +125,14 @@ bool ANSIParser::parse(std::wstring_view codes, ColorCB color_cb, WriteCB write_
sf::Color &target = color;
#line 117 "ansi_parser.cpp"
#line 120 "ansi_parser.cpp"
{
cs = foo_start;
}
#line 135 "ansi_parser.rl"
#line 138 "ansi_parser.rl"
#line 120 "ansi_parser.cpp"
#line 123 "ansi_parser.cpp"
{
int _klen;
unsigned int _trans;
@ -307,7 +310,7 @@ _match:
#line 75 "ansi_parser.rl"
{}
break;
#line 281 "ansi_parser.cpp"
#line 284 "ansi_parser.cpp"
}
}
@ -327,7 +330,7 @@ _again:
#line 75 "ansi_parser.rl"
{}
break;
#line 299 "ansi_parser.cpp"
#line 302 "ansi_parser.cpp"
}
}
}
@ -335,12 +338,13 @@ _again:
_out: {}
}
#line 136 "ansi_parser.rl"
#line 139 "ansi_parser.rl"
bool good = p - pe == 0;
if(!good) {
println("FAIL AT {}", p - pe);
p -= 10;
// dear cthuhlu, save me from the pain that is wstring
for(int i = 0; i < 100; i++) {
print("{}", char(p[i]));

@ -96,7 +96,10 @@ using namespace fmt;
"5" |
"6" |
"7" %invert |
"22" |
"27" %reset_invert |
"9" ["0"-"7"] |
"10" ["0"-"7"] |
(fg|bg) (color24b num %red ";" num %blue ";" num %green ) %color_out
) "m" %end
);
@ -138,6 +141,7 @@ bool ANSIParser::parse(std::wstring_view codes, ColorCB color_cb, WriteCB write_
if(!good) {
println("FAIL AT {}", p - pe);
p -= 10;
// dear cthuhlu, save me from the pain that is wstring
for(int i = 0; i < 100; i++) {
print("{}", char(p[i]));

@ -34,6 +34,7 @@ GUI::GUI(DinkyECS::World &world, Map& game_map) :
$log({{"Welcome to the game!"}}),
$status_ui(SCREEN_X, SCREEN_Y, 0, 0),
$map_view(0, 0, GAME_MAP_POS, 0, false),
$modal_test(SCREEN_X/2, SCREEN_Y/4, 800, 200, false),
$view_port{0,0},
$world(world),
$sounds("./assets"),
@ -70,7 +71,24 @@ void GUI::create_renderer() {
return canvas($canvas);
}));
auto test_button = Button("TEST", [&]{ println("pressed"); });
auto modal_buttons = Container::Horizontal({
Button("OK", [&]{ println("OK pressed"); }),
Button("CANCEL", [&]{ println("CANCEL pressed"); }),
});
$modal_test.set_renderer(Renderer([&, modal_buttons] {
return hbox({
hflow(
vbox(
text("Hello!"),
modal_buttons->Render()
))}) | border;
}));
auto test_button = Container::Horizontal({
Button("Open Test Modal", [&]{ $show_modal = true; }),
Button("Close It", [&]{ $show_modal = false; }),
});
auto status_rend = Renderer(test_button, [&, test_button, player]{
const auto& player_combat = $world.get<Combat>(player.entity);
@ -214,6 +232,10 @@ void GUI::render_scene() {
$renderer.draw_text($status_ui);
$renderer.draw_grid($map_view);
if($show_modal) {
$renderer.draw_text($modal_test);
}
$renderer.display();
}

@ -43,6 +43,8 @@ class GUI {
ActionLog $log;
Panel $status_ui;
Panel $map_view;
Panel $modal_test;
bool $show_modal = false;
Point $view_port;
Component $test_button;
DinkyECS::World& $world;

@ -39,6 +39,7 @@ SFMLRender::SFMLRender() :
{
// force true color, but maybe I want to support different color sets
$font.loadFromFile("./assets/text.otf");
$font.setSmooth(false);
$ui_text.setFont($font);
$ui_text.setPosition(0,0);
$ui_text.setCharacterSize(UI_FONT_SIZE);

@ -5,6 +5,8 @@ TODAY'S GOAL:
TODO:
* panels and everything except renderer should use character coodinates
* panels should know if they're text vs. grid rendered
* panels need a background and border setting
* Can std::any be defaulted to a noop in the events?
* Save file isn't saving gold.
* Inventory needs to be better, but need some kinds of "weapons" or other loot to get and not just gold.

Loading…
Cancel
Save