40 bool mainMenuLoop =
true;
41 bool startGame =
true;
42 bool showLoadDialog =
false;
52 m_AudioMixer.play(AudioTrigger::MainMenu);
54 m_AudioMixer.play(AudioTrigger::MainMenu,
Coordinate3D{0, 3, 0.5});
60 int logoTexW, logoTexH;
61 SDL_QueryTexture(logoTex,
nullptr,
nullptr, &logoTexW, &logoTexH);
69 ui::SetNextWindowBgAlpha(0);
70 ui::SetNextWindowPos(ImVec2(0.0f, 0.0f));
71 ui::SetNextWindowSize(ui::GetIO().DisplaySize);
74 ui::Begin(
"MainWnd", &open,
75 ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar |
76 ImGuiWindowFlags_NoScrollWithMouse);
88 const ImVec2 logoImgPos(screenWidth / 2 - logoTexW / 2, screenHeight / 4);
89 for (Uint8 opacity = 0; opacity < 255; opacity++)
94 const bool has_event = SDL_PollEvent(&event) != 0;
95 if (has_event && event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_KEYDOWN)
98 ui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
99 ui::SetCursorPos(logoImgPos);
100 float op = opacity / 255.f;
101 ui::Image(logoTex, ImVec2(logoTexW, logoTexH), ImVec2(0, 0), ImVec2(1, 1), ImVec4{op, op, op, op});
114 while (SDL_PollEvent(&event) != 0)
116 ImGui_ImplSDL2_ProcessEvent(&event);
118 if (event.type == SDL_QUIT)
121 mainMenuLoop =
false;
128 switch (loadMenu.
result())
131 showLoadDialog =
false;
136 playAudioMajorSelection();
139 mainMenuLoop =
false;
147 ui::PushFont(buttonFont);
148 ui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
150 ui::SetCursorPos(logoImgPos);
151 ui::Image(logoTex, ImVec2(logoTexW, logoTexH));
153 constexpr ImVec2 buttonSize(200, 40);
154 constexpr
int buttonInterval = 20;
155 ImVec2 buttonPos(screenWidth / 2 - buttonSize.x / 2, screenHeight / 2 - buttonSize.y);
156 ui::SetCursorPos(buttonPos);
157 if (ui::ButtonCt(
"New Game", buttonSize))
160 playAudioMajorSelection();
162 mainMenuLoop =
false;
166 buttonPos.y += buttonSize.y + buttonInterval;
167 ui::SetCursorPos(buttonPos);
168 if (ui::ButtonCt(
"Load Game", buttonSize))
170 showLoadDialog =
true;
173 buttonPos.y += buttonSize.y + buttonInterval;
174 ui::SetCursorPos(buttonPos);
175 if (ui::ButtonCt(
"Quit Game", buttonSize))
178 mainMenuLoop =
false;
181 constexpr
int xOffset = 5, btnSize = 32;
182 ImVec2 leftBottom(xOffset, screenHeight - btnSize - xOffset * 2);
183 ui::SetCursorPos(leftBottom);
184 if (ui::ImageButton(discordTex, ImVec2(btnSize, btnSize)))
189 leftBottom.x += xOffset * 2 + btnSize;
190 ui::SetCursorPos(leftBottom);
191 if (ui::ImageButton(githubTex, ImVec2(btnSize, btnSize)))
202 constexpr ImVec2 fpsTextPos(5, 5);
203 ui::SetCursorPos(fpsTextPos);
204 ui::Text(
"[%.1f FPS]", ui::GetIO().Framerate);
206 ImVec2 textSize = ImGui::CalcTextSize(
VERSION);
207 const ImVec2 versionPos(screenWidth - textSize.x - 10, screenHeight - textSize.y - 10);
208 ui::SetCursorPos(versionPos);