source: opengl-game/gui/game-screen.cpp@ 699e83a

feature/imgui-sdl
Last change on this file since 699e83a was 699e83a, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 5 years ago

Add a GameScreen class to render the main gameplay

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