summaryrefslogtreecommitdiff
path: root/ui/gameMainWindow.cpp
blob: b6e0075ab7ed3f97d01364b2e48c05c5781e6570 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "gameMainWindow.h"
#include "editNetwork.h"
#include "gameMainSelector.h"
#include "gfx/camera_controller.h"
#include "manualCameraController.h"
#include "maths.h"
#include "modeHelper.hpp"
#include "toolbar.h"
#include "window.h"
#include <GL/glew.h>
#include <SDL2/SDL.h>
#include <collection.hpp>
#include <game/gamestate.h>
#include <game/network/rail.h>
#include <game/worldobject.h> // IWYU pragma: keep
#include <gfx/renderable.h>
#include <glm/glm.hpp>
#include <memory>
#include <utility>

class GameMainToolbar : Mode<decltype(GameMainSelector::target)>, public Toolbar {
public:
	explicit GameMainToolbar(GameMainSelector * gms_) :
		Mode<decltype(GameMainSelector::target)> {gms_->target}, Toolbar {
																		 {"ui/icon/network.png",
																				 toggle<EditNetworkOf<RailLinks>>()},
																 }
	{
	}
};

GameMainWindow::GameMainWindow(size_t w, size_t h) :
	Window {w, h, "I Like Trains", SDL_WINDOW_OPENGL}, SceneRenderer {size}, camera {{-1250.0F, -1250.0F, 35.0F}, quarter_pi, rdiv(w, h),
																  0.1F, 10000.0F}
{
	uiComponents.create<ManualCameraController>(glm::vec2 {-1150, -1150});
	auto gms = uiComponents.create<GameMainSelector>(&camera, glm::vec2 {w, h});
	uiComponents.create<GameMainToolbar>(gms.get());
}

void
GameMainWindow::tick(TickDuration)
{
	uiComponents.apply<CameraController>(&CameraController::updateCamera, &camera);
	shader.setView(camera.GetViewProjection());
}

void
GameMainWindow::render() const
{
	SceneRenderer::render([this] {
		gameState->world.apply<Renderable>(&Renderable::render, shader);
		uiComponents.apply<WorldOverlay>(&WorldOverlay::render, shader);
	});
	Window::render();
}