@@ -461,7 +461,7 @@ void Engine::show_multiplayer_diplomacy() {
461461 return ;
462462
463463 Assets &a = *assets.get ();
464- ImDrawList *lst = ImGui::GetWindowDrawList ();
464+ ImDrawList *lst = ImGui::GetWindowDrawList (); // TODO refactor to bkg
465465
466466 const gfx::ImageRef &rbkg = a.at (io::DrsId::img_dialog0);
467467 ImVec2 pos (ImGui::GetWindowPos ());
@@ -543,6 +543,7 @@ void Engine::show_multiplayer_host() {
543543 f.str (" Multiplayer game -" );
544544 f.sl ();
545545
546+ // FIXME make this less ugly
546547 --player_count;
547548 f.scalar (player_count == 1 ? " player" : " players" , player_count, 1 , 1 , MAX_PLAYERS - 1 );
548549 ++player_count;
@@ -555,6 +556,7 @@ void Engine::show_multiplayer_host() {
555556
556557 player_tbl_y = ImGui::GetCursorPosY ();
557558 } else {
559+ // FIXME make this less ugly
558560 --player_count;
559561 f.fmt (" Multiplayer game - %u %s" , player_count, player_count == 1 ? " player" : " players" );
560562 ++player_count;
@@ -631,7 +633,7 @@ void UICache::show_editor_menu() {
631633 ImGui::SetCursorPosY (272 .0f / 768 .0f * vp->WorkSize .y );
632634
633635 if (btn (f, " Create Scenario" , TextHalign::center, e->sfx ))
634- e-> next_menu_state = MenuState::editor_scenario;
636+ next_menu_state = MenuState::editor_scenario;
635637
636638 ImGui::SetCursorPosY (352 .0f / 768 .0f * vp->WorkSize .y );
637639
@@ -644,7 +646,7 @@ void UICache::show_editor_menu() {
644646 ImGui::SetCursorPosY (512 .0f / 768 .0f * vp->WorkSize .y );
645647
646648 if (btn (f, " Cancel" , TextHalign::center, e->sfx ))
647- e-> next_menu_state = MenuState::start;
649+ next_menu_state = MenuState::start;
648650
649651 ImGui::SetCursorPosX (old_x);
650652}
@@ -1007,51 +1009,107 @@ void Engine::open_help() {
10071009 open_url (" https://github.com/FolkertVanVerseveld/aoe" );
10081010}
10091011
1010- void Engine::show_start () {
1011- ZoneScoped;
1012- ImGuiViewport *vp = ImGui::GetMainViewport ();
1013- ImGui::SetNextWindowPos (vp->WorkPos );
1012+ #define ARRAY_SIZE (a ) (sizeof (a) / sizeof (a[0 ])) // NOTE a is compile constant and evaluated twice
10141013
1015- Frame f;
1014+ class MenuButton final {
1015+ public:
1016+ float relY;
1017+ float x0, y0, x1, y1;
1018+ const char *name;
10161019
1017- if (!f.begin (" start" , ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBackground))
1018- return ;
1020+ MenuButton (float y, const char *name)
1021+ : relY(y), name(name)
1022+ , x0(0 ), y0(0 ), x1(0 ), y1(0 ) {}
10191023
1020- ImGui::SetWindowSize (vp->WorkSize );
1024+ void reshape (ImGuiViewport *vp) {
1025+ float w = vp->WorkSize .x , h = vp->WorkSize .y ;
1026+ x0 = 212 / 800 .0f * w;
1027+ x1 = 586 / 800 .0f * w;
1028+ y0 = relY / 768 .0f * h;
1029+ y1 = (relY + 64 .0f ) / 768 .0f * h;
1030+ }
10211031
1022- float old_x = ImGui::GetCursorPosX ();
1032+ bool showDisabled (Frame &f, const char *tooltip, const BackgroundColors &col) const {
1033+ DrawBorder (x0, y0, x1, y1, col);
1034+ ImGui::SetCursorPosY (y0);
1035+ return f.xbtn (name, tooltip, TextHalign::center);
1036+ }
10231037
1024- {
1025- FontGuard fg (fnt.copper );
1038+ bool show (Frame &f, Audio &sfx, const BackgroundColors &col) const {
1039+ ImGui::SetCursorPosY (y0);
1040+ bool b = btn (f, name, TextHalign::center, sfx);
1041+ if (b)
1042+ DrawBorderInv (x0, y0, x1, y1, col);
1043+ else
1044+ DrawBorder (x0, y0, x1, y1, col);
1045+ return b;
1046+ }
1047+ };
1048+
1049+ MenuButton mainMenuButtons[] = {
1050+ {284 , " Single Player" },
1051+ {364 , " Multiplayer" },
1052+ {444 , " Help" },
1053+ {524 , " Scenario Builder" },
1054+ {604 , " Exit" },
1055+ };
1056+
1057+ class MainMenu final {
1058+ public:
1059+ const MenuButton &sp, &mp, &help, &scn, &quit;
1060+
1061+ MainMenu () : sp(mainMenuButtons[0 ]), mp(mainMenuButtons[1 ])
1062+ , help(mainMenuButtons[2 ]), scn(mainMenuButtons[3 ]), quit(mainMenuButtons[4 ]) {}
1063+
1064+ void reshape (ImGuiViewport *vp) {
1065+ for (unsigned i = 0 ; i < ARRAY_SIZE (mainMenuButtons); ++i)
1066+ mainMenuButtons[i].reshape (vp);
1067+ }
1068+ } mainMenu;
1069+
1070+ static void DrawMainMenu (Frame &f, Audio &sfx, Assets &ass)
1071+ {
1072+ MainMenu &mm = mainMenu;
1073+ ImGuiViewport *vp = ImGui::GetMainViewport ();
10261074
1027- ImGui::SetCursorPosY (284 .0f / 768 .0f * vp->WorkSize .y );
1075+ FontGuard fg (fnt.copper );
1076+
1077+ mm.reshape (vp);
1078+
1079+ float y0 = 284 / 768 .0f * vp->WorkSize .y , y1 = 348 / 768 .0f * vp->WorkSize .y ;
1080+ BackgroundColors col = ass.bkg_cols .at (io::DrsId::bkg_main_menu);
1081+
1082+ #define DRAW_BTN (btn ) btn.show(f, sfx, col)
1083+ #define DRAW_DISABLED (btn, tt ) btn.showDisabled(f, tt, col)
10281084
10291085#if 0
1030- if (btn(f, "Single Player", TextHalign::center, sfx ))
1031- next_menu_state = MenuState::singleplayer_menu;
1086+ if (DRAW_BTN(mm.sp ))
1087+ next_menu_state = MenuState::singleplayer_menu;
10321088#else
1033- f. xbtn ( " Single Player " , " Single player mode is not supported yet. Use multiplayer mode with 1 player instead." , TextHalign::center );
1089+ DRAW_DISABLED (mm. sp , " Single player mode is not supported yet. Use multiplayer mode with 1 player instead." );
10341090#endif
10351091
1036- ImGui::SetCursorPosY (364 .0f / 768 .0f * vp->WorkSize .y );
1092+ if (DRAW_BTN (mm.mp )) next_menu_state = MenuState::multiplayer_menu;
1093+ if (DRAW_BTN (mm.help )) eng->open_help ();
1094+ if (DRAW_BTN (mm.scn )) next_menu_state = MenuState::editor_menu;
1095+ if (DRAW_BTN (mm.quit )) throw 0 ;
1096+ }
10371097
1038- if (btn (f, " Multiplayer" , TextHalign::center, sfx))
1039- next_menu_state = MenuState::multiplayer_menu;
1098+ void Engine::show_start () {
1099+ ZoneScoped;
1100+ ImGuiViewport *vp = ImGui::GetMainViewport ();
1101+ ImGui::SetNextWindowPos (vp->WorkPos );
10401102
1041- ImGui::SetCursorPosY (444 .0f / 768 .0f * vp->WorkSize .y );
1042- if (btn (f, " Help" , TextHalign::center, sfx))
1043- open_help ();
1103+ Frame f;
10441104
1045- ImGui::SetCursorPosY (524 .0f / 768 .0f * vp->WorkSize .y );
1105+ if (!f.begin (" start" , ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBackground))
1106+ return ;
10461107
1047- if (btn (f, " Scenario Builder" , TextHalign::center, sfx))
1048- next_menu_state = MenuState::editor_menu;
1108+ ImGui::SetWindowSize (vp->WorkSize );
10491109
1050- ImGui::SetCursorPosY ( 604 . 0f / 768 . 0f * vp-> WorkSize . y );
1110+ float old_x = ImGui::GetCursorPosX ( );
10511111
1052- if (btn (f, " Exit" , TextHalign::center, sfx))
1053- throw 0 ;
1054- }
1112+ DrawMainMenu (f, sfx, *assets.get ());
10551113
10561114 ImGui::SetCursorPosX (old_x);
10571115 ImGui::SetCursorPosY ((710 .0f - 40 .0f ) / 768 .0f * vp->WorkSize .y );
@@ -1076,7 +1134,7 @@ void Engine::show_init() {
10761134 f.str (" Age of Empires game setup" );
10771135
10781136 ImGui::TextWrapped (" %s" , " In this menu, you can change general settings how the game behaves and where the game assets will be loaded from." );
1079- ImGui::TextWrapped (" %s" , " This game is free software. If you have paid for this free software remake, you have been scammed! If you like Age of Empires, please support Microsoft by buying the original game on Steam " );
1137+ ImGui::TextWrapped (" %s" , " This game is free software. If you have paid for this free software remake, you have been fooled! " );
10801138
10811139
10821140 if (!fnt.loaded ()) {
@@ -1329,6 +1387,19 @@ void DrawLine(float x0, float y0, float x1, float y1, SDL_Color col)
13291387 bkg->AddLine (ImVec2 (x0, y0), ImVec2 (x1, y1), IM_COL32 (col.r , col.g , col.b , SDL_ALPHA_OPAQUE), 1 );
13301388}
13311389
1390+ void DrawBorderInv (float x0, float y0, float x1, float y1, const BackgroundColors &bkgcol)
1391+ {
1392+ BackgroundColors bkgcol2;
1393+ bkgcol2.border [0 ] = bkgcol.border [3 ];
1394+ bkgcol2.border [1 ] = bkgcol.border [4 ];
1395+ bkgcol2.border [2 ] = bkgcol.border [5 ];
1396+ bkgcol2.border [3 ] = bkgcol.border [0 ];
1397+ bkgcol2.border [4 ] = bkgcol.border [1 ];
1398+ bkgcol2.border [5 ] = bkgcol.border [2 ];
1399+
1400+ DrawBorder (x0, y0, x1, y1, bkgcol2);
1401+ }
1402+
13321403void DrawBorder (float x0, float y0, float x1, float y1, const BackgroundColors &bkgcol)
13331404{
13341405 DrawLine (x0, y0, x1, y0, bkgcol.border [0 ]);
0 commit comments