forked from firleju/maszyna
-
Notifications
You must be signed in to change notification settings - Fork 2
/
driveruilayer.cpp
198 lines (163 loc) · 6.17 KB
/
driveruilayer.cpp
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#include "stdafx.h"
#include "driveruilayer.h"
#include "Globals.h"
#include "application.h"
#include "translation.h"
#include "simulation.h"
#include "Train.h"
#include "AnimModel.h"
#include "renderer.h"
driver_ui::driver_ui() {
clear_panels();
// bind the panels with ui object. maybe not the best place for this but, eh
push_back( &m_aidpanel );
push_back( &m_scenariopanel );
push_back( &m_timetablepanel );
push_back( &m_debugpanel );
push_back( &m_transcriptspanel );
m_aidpanel.title = locale::strings[ locale::string::driver_aid_header ];
m_scenariopanel.title = locale::strings[ locale::string::driver_scenario_header ];
m_scenariopanel.size_min = { 435, 85 };
m_scenariopanel.size_max = { Global.iWindowWidth * 0.95, Global.iWindowHeight * 0.95 };
m_timetablepanel.title = locale::strings[ locale::string::driver_timetable_header ];
m_timetablepanel.size_min = { 435, 70 };
m_timetablepanel.size_max = { 435, Global.iWindowHeight * 0.95 };
m_transcriptspanel.title = locale::strings[ locale::string::driver_transcripts_header ];
m_transcriptspanel.size_min = { 435, 85 };
m_transcriptspanel.size_max = { Global.iWindowWidth * 0.95, Global.iWindowHeight * 0.95 };
}
// potentially processes provided input key. returns: true if key was processed, false otherwise
bool
driver_ui::on_key_( int const Key, int const Scancode, int const Action, int const Mods ) {
if( m_paused ) {
// if the pause is on block input except for the pause key which we let the owner deal with
return ( Key != Application.key_binding( user_command::pausetoggle ) );
}
switch( Key ) {
case GLFW_KEY_F1:
case GLFW_KEY_F2:
case GLFW_KEY_F3:
case GLFW_KEY_F10:
case GLFW_KEY_F12: { // ui mode selectors
if( ( true == Global.ctrlState )
|| ( true == Global.shiftState ) ) {
// only react to keys without modifiers
return false;
}
if( Action != GLFW_PRESS ) { return true; } // recognized, but ignored
}
default: { // everything else
break;
}
}
switch (Key) {
case GLFW_KEY_F1: {
// basic consist info
auto state = (
( m_aidpanel.is_open == false ) ? 0 :
( m_aidpanel.is_expanded == false ) ? 1 :
2 );
state = clamp_circular( ++state, 3 );
m_aidpanel.is_open = ( state > 0 );
m_aidpanel.is_expanded = ( state > 1 );
return true;
}
case GLFW_KEY_F2: {
// timetable
auto state = (
( m_timetablepanel.is_open == false ) ? 0 :
( m_timetablepanel.is_expanded == false ) ? 1 :
2 );
state = clamp_circular( ++state, 3 );
m_timetablepanel.is_open = ( state > 0 );
m_timetablepanel.is_expanded = ( state > 1 );
return true;
}
case GLFW_KEY_F3: {
// debug panel
m_scenariopanel.is_open = !m_scenariopanel.is_open;
return true;
}
case GLFW_KEY_F12: {
// debug panel
m_debugpanel.is_open = !m_debugpanel.is_open;
return true;
}
default: {
break;
}
}
return false;
}
// potentially processes provided mouse movement. returns: true if the input was processed, false otherwise
bool
driver_ui::on_cursor_pos_( double const Horizontal, double const Vertical ) {
// intercept mouse movement when the pause window is on
return m_paused;
}
// potentially processes provided mouse button. returns: true if the input was processed, false otherwise
bool
driver_ui::on_mouse_button_( int const Button, int const Action, int const Mods ) {
// intercept mouse movement when the pause window is on
return m_paused;
}
// updates state of UI elements
void
driver_ui::update() {
auto const pausemask { 1 | 2 };
auto ispaused { ( false == DebugModeFlag ) && ( ( Global.iPause & pausemask ) != 0 ) };
if( ( ispaused != m_paused )
&& ( false == Global.ControlPicking ) ) {
set_cursor( ispaused );
}
m_paused = ispaused;
ui_layer::update();
}
void
driver_ui::set_cursor( bool const Visible ) {
if( Visible ) {
Application.set_cursor( GLFW_CURSOR_NORMAL );
Application.set_cursor_pos( Global.iWindowWidth / 2, Global.iWindowHeight / 2 );
}
else {
Application.set_cursor( GLFW_CURSOR_DISABLED );
Application.set_cursor_pos( 0, 0 );
}
}
// render() subclass details
void
driver_ui::render_() {
if( m_paused ) {
// pause/quit modal
auto const popupheader { locale::strings[ locale::string::driver_pause_header ].c_str() };
ImGui::OpenPopup( popupheader );
if( ImGui::BeginPopupModal( popupheader, nullptr, ImGuiWindowFlags_AlwaysAutoResize ) ) {
auto const popupwidth{ locale::strings[ locale::string::driver_pause_header ].size() * 7 };
if( ImGui::Button( locale::strings[ locale::string::driver_pause_resume ].c_str(), ImVec2( popupwidth, 0 ) ) ) {
ImGui::CloseCurrentPopup();
command_relay commandrelay;
commandrelay.post(user_command::pausetoggle, 0.0, 0.0, GLFW_PRESS, 0);
}
if( ImGui::Button( locale::strings[ locale::string::driver_pause_quit ].c_str(), ImVec2( popupwidth, 0 ) ) ) {
ImGui::CloseCurrentPopup();
// NOTE: server shuts down entire network, client or standalone instance only shuts down self
if( Application.is_server() ) {
command_relay commandrelay;
commandrelay.post( user_command::quitsimulation, 0.0, 0.0, GLFW_PRESS, 0 );
}
else {
Application.queue_quit();
}
}
ImGui::EndPopup();
}
}
}