source: opengl-game/gui/game-screen.cpp

feature/imgui-sdl
Last change on this file was d8cf709, checked in by Dmitry Portnoy <dportnoy@…>, 4 years ago

Change UIEvent to also include the original event from the UI library the game gui is currently using, such as SDL or GLFW.

  • Property mode set to 100644
File size: 2.1 KB
Line 
1#include "game-screen.hpp"
2
3#include <iostream>
4
5#include <SDL2/SDL_ttf.h>
6
7#include "../vulkan-game.hpp"
8
9#include "button.hpp"
10#include "panel.hpp"
11#include "ui-value.hpp"
12
13using namespace std;
14
15// TODO: Figure out a good way to return errors instead of just printing them
16// Probably throw an exception in the constructor
17// Make sure to cleanup anythign that was initialized correctly before the error
18// since throwing an exception in the constructor means the destructor won't get called
19
20GameScreen::GameScreen(SDL_Renderer& renderer, VulkanGame& gameInfo) :
21 Screen(renderer, gameInfo) {
22 Panel *statsPanel = new Panel(10, 50, 95, 46, 0x161616FF, this->renderer);
23
24 statsPanel->addUIElement(new UIValue(0, 0, "Score: ", this->gameInfo.score,
25 this->gameInfo.proggyFont, 0xFFFFFFFF, this->renderer));
26 statsPanel->addUIElement(new UIValue(14, 19, "FPS: ", this->gameInfo.fps,
27 this->gameInfo.proggyFont, 0xFFFFFFFF, this->renderer));
28
29 // TODO: Add the button to the panel it's in, not directly to the window
30 addUIElement(statsPanel);
31 addUIElement(new Panel(540, 10, 250, 35, 0x161616FF, this->renderer));
32 addUIElement(new Panel(590, 60, 200, 200, 0x161616FF, this->renderer));
33 addUIElement(new Button("Main Menu", 708, 17, 8, 0x222299FF, 0xFFFFFFFF, this->gameInfo,
34 this->renderer, mainMenu_onMouseClick, nullptr, nullptr));
35}
36
37GameScreen::~GameScreen() {
38}
39
40void GameScreen::createRenderCommands(VkCommandBuffer& commandBuffer, uint32_t currentImage) {
41 gameInfo.modelPipeline.createRenderCommands(commandBuffer, currentImage);
42 gameInfo.shipPipeline.createRenderCommands(commandBuffer, currentImage);
43 gameInfo.asteroidPipeline.createRenderCommands(commandBuffer, currentImage);
44 gameInfo.laserPipeline.createRenderCommands(commandBuffer, currentImage);
45 gameInfo.explosionPipeline.createRenderCommands(commandBuffer, currentImage);
46
47 // Always render this pipeline last
48 gameInfo.overlayPipeline.createRenderCommands(commandBuffer, currentImage);
49}
50
51void GameScreen::handleEvent(GameEvent& e) {
52 Screen::handleEvent(e);
53}
54
55void mainMenu_onMouseClick(VulkanGame& gameInfo) {
56 gameInfo.goToScreen(gameInfo.screens[SCREEN_MAIN]);
57}
Note: See TracBrowser for help on using the repository browser.