blob: 872528de0cb8c5a549f948da096eaa7a2df06165 (
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
#include "StarErrorScreen.hpp"
#include "StarGuiReader.hpp"
#include "StarRoot.hpp"
#include "StarJsonExtra.hpp"
#include "StarPaneManager.hpp"
#include "StarLabelWidget.hpp"
#include "StarAssets.hpp"
#include "StarGameTypes.hpp"
namespace Star {
ErrorScreen::ErrorScreen() {
m_paneManager = make_shared<PaneManager>();
m_accepted = false;
auto assets = Root::singleton().assets();
m_guiContext = GuiContext::singletonPtr();
m_errorPane = make_shared<Pane>();
GuiReader reader;
reader.registerCallback("btnOk", [this](Widget*) {
m_accepted = true;
});
reader.construct(assets->json("/interface/windowconfig/error.config:paneLayout"), m_errorPane.get());
m_paneManager->displayPane(PaneLayer::Window, m_errorPane, [this](PanePtr) {
m_accepted = true;
});
}
void ErrorScreen::setMessage(String const& errorMessage) {
m_errorPane->fetchChild<LabelWidget>("labelError")->setText(errorMessage);
m_accepted = false;
}
bool ErrorScreen::accepted() {
return m_accepted;
}
void ErrorScreen::render() {
auto assets = Root::singleton().assets();
for (auto backdropImage : assets->json("/interface/windowconfig/title.config:backdropImages").toArray()) {
Vec2F offset = jsonToVec2F(backdropImage.get(0)) * interfaceScale();
String image = backdropImage.getString(1);
float scale = backdropImage.getFloat(2);
Vec2F imageSize = Vec2F(m_guiContext->textureSize(image)) * interfaceScale() * scale;
Vec2F lowerLeft = Vec2F(windowWidth() / 2.0f, windowHeight());
lowerLeft[0] -= imageSize[0] / 2;
lowerLeft[1] -= imageSize[1];
lowerLeft += offset;
RectF screenCoords(lowerLeft, lowerLeft + imageSize);
m_guiContext->drawQuad(image, screenCoords);
}
m_paneManager->render();
renderCursor();
}
bool ErrorScreen::handleInputEvent(InputEvent const& event) {
if (auto mouseMove = event.ptr<MouseMoveEvent>())
m_cursorScreenPos = mouseMove->mousePosition;
return m_paneManager->sendInputEvent(event);
}
void ErrorScreen::update() {
m_paneManager->update();
}
void ErrorScreen::renderCursor() {
m_cursor.update(WorldTimestep);
Vec2I cursorPos = m_cursorScreenPos;
Vec2I cursorSize = m_cursor.size();
Vec2I cursorOffset = m_cursor.offset();
cursorPos[0] -= cursorOffset[0] * interfaceScale();
cursorPos[1] -= (cursorSize[1] - cursorOffset[1]) * interfaceScale();
m_guiContext->drawDrawable(m_cursor.drawable(), Vec2F(cursorPos), interfaceScale());
}
float ErrorScreen::interfaceScale() const {
return m_guiContext->interfaceScale();
}
unsigned ErrorScreen::windowHeight() const {
return m_guiContext->windowHeight();
}
unsigned ErrorScreen::windowWidth() const {
return m_guiContext->windowWidth();
}
}
|