16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 13:59:19 +02:00
This commit is contained in:
2026-01-03 23:23:52 +01:00
parent 8cee745af5
commit d3dbcb3fca
2 changed files with 1184 additions and 1003 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -18,7 +18,8 @@ http://mozilla.org/MPL/2.0/.
#include "AnimModel.h"
#include "renderer.h"
driver_ui::driver_ui() {
driver_ui::driver_ui()
{
clear_panels();
// bind the panels with ui object. maybe not the best place for this but, eh
@@ -52,19 +53,22 @@ driver_ui::driver_ui() {
m_transcriptspanel.size_min = {435, 85};
m_transcriptspanel.size_max = {Global.fb_size.x * 0.95, Global.fb_size.y * 0.95};
if (Global.gui_defaultwindows) {
if (Global.gui_defaultwindows)
{
m_aidpanel.is_open = true;
m_scenariopanel.is_open = true;
}
if (Global.gui_trainingdefault) {
if (Global.gui_trainingdefault)
{
m_mappanel.is_open = true;
m_trainingcardpanel.is_open = true;
m_vehiclelist.is_open = true;
}
}
void driver_ui::render_menu_contents() {
void driver_ui::render_menu_contents()
{
ui_layer::render_menu_contents();
if (ImGui::BeginMenu(STR_C("Mode windows")))
@@ -93,46 +97,53 @@ void driver_ui::showDebugUI()
}
// potentially processes provided input key. returns: true if key was processed, false otherwise
bool
driver_ui::on_key( int const Key, int const Action ) {
bool driver_ui::on_key(int const Key, int const Action)
{
if (ui_layer::on_key(Key, Action))
return true;
switch( Key ) {
switch (Key)
{
case GLFW_KEY_TAB:
case GLFW_KEY_F1:
case GLFW_KEY_F2:
case GLFW_KEY_F3:
case GLFW_KEY_F10:
case GLFW_KEY_F12: { // ui mode selectors
case GLFW_KEY_F12:
{ // ui mode selectors
if( ( true == Global.ctrlState )) {
if ((true == Global.ctrlState) || (true == Global.shiftState))
{
// only react to keys without modifiers
return false;
}
if( Action != GLFW_PRESS ) { return true; } // recognized, but ignored
if (Action != GLFW_PRESS)
{
return true;
} // recognized, but ignored
}
default: { // everything else
default:
{ // everything else
break;
}
}
switch (Key) {
switch (Key)
{
case GLFW_KEY_TAB: {
case GLFW_KEY_TAB:
{
m_mappanel.is_open = !m_mappanel.is_open;
return true;
}
case GLFW_KEY_F1: {
case GLFW_KEY_F1:
{
// basic consist info
auto state = (
( m_aidpanel.is_open == false ) ? 0 :
( m_aidpanel.is_expanded == false ) ? 1 :
2 );
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);
@@ -141,12 +152,10 @@ driver_ui::on_key( int const Key, int const Action ) {
return true;
}
case GLFW_KEY_F2: {
case GLFW_KEY_F2:
{
// timetable
auto state = (
( m_timetablepanel.is_open == false ) ? 0 :
( m_timetablepanel.is_expanded == false ) ? 1 :
2 );
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);
@@ -155,13 +164,15 @@ driver_ui::on_key( int const Key, int const Action ) {
return true;
}
case GLFW_KEY_F3: {
case GLFW_KEY_F3:
{
// debug panel
m_scenariopanel.is_open = !m_scenariopanel.is_open;
return true;
}
case GLFW_KEY_F12 : {
case GLFW_KEY_F12:
{
// debug panel
if (Global.shiftState)
{
@@ -170,7 +181,8 @@ driver_ui::on_key( int const Key, int const Action ) {
}
}
default: {
default:
{
break;
}
}
@@ -179,27 +191,27 @@ driver_ui::on_key( int const Key, int const Action ) {
}
// 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 ) {
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 ) {
bool driver_ui::on_mouse_button(int const Button, int const Action)
{
// intercept mouse movement when the pause window is on
return m_paused;
}
// updates state of UI elements
void
driver_ui::update() {
void driver_ui::update()
{
auto const pausemask{1 | 2};
auto ispaused{(false == DebugModeFlag) && ((Global.iPause & pausemask) != 0)};
if( ( ispaused != m_paused )
&& ( false == Global.ControlPicking ) ) {
if ((ispaused != m_paused) && (false == Global.ControlPicking))
{
set_cursor(ispaused);
}
m_paused = ispaused;
@@ -207,50 +219,58 @@ driver_ui::update() {
ui_layer::update();
}
void
driver_ui::set_cursor( bool const Visible ) {
void driver_ui::set_cursor(bool const Visible)
{
if( Visible ) {
if (Visible)
{
Application.set_cursor(GLFW_CURSOR_NORMAL);
Application.set_cursor_pos(Global.window_size.x / 2, Global.window_size.y / 2);
}
else {
else
{
Application.set_cursor(GLFW_CURSOR_DISABLED);
Application.set_cursor_pos(0, 0);
}
}
// render() subclass details
void
driver_ui::render_() {
void driver_ui::render_()
{
const std::string *rec_name = m_trainingcardpanel.is_recording();
if (rec_name && m_cameraviewpanel.set_state(true)) {
if (rec_name && m_cameraviewpanel.set_state(true))
{
m_cameraviewpanel.rec_name = *rec_name;
m_cameraviewpanel.is_open = true;
} else if (!rec_name)
}
else if (!rec_name)
m_cameraviewpanel.set_state(false);
// pause/quit modal
auto const popupheader{STR_C("Simulation Paused")};
ImGui::SetNextWindowSize(ImVec2(-1, -1));
if( ImGui::BeginPopupModal( popupheader, nullptr, 0 ) ) {
if( ( ImGui::Button( STR_C("Resume"), ImVec2( 150, 0 ) ) )
|| ( ImGui::IsKeyReleased( ImGui::GetKeyIndex( ImGuiKey_Escape ) ) ) )
if (ImGui::BeginPopupModal(popupheader, nullptr, 0))
{
if ((ImGui::Button(STR_C("Resume"), ImVec2(150, 0))) || (ImGui::IsKeyReleased(ImGui::GetKeyIndex(ImGuiKey_Escape))))
{
m_relay.post(user_command::pausetoggle, 0.0, 0.0, GLFW_RELEASE, 0);
}
if( ImGui::Button( STR_C("Quit"), ImVec2( 150, 0 ) ) ) {
if (ImGui::Button(STR_C("Quit"), ImVec2(150, 0)))
{
Application.queue_quit(false);
}
if (!m_paused)
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
} else if (m_paused) {
}
else if (m_paused)
{
ImGui::OpenPopup(popupheader);
}
if (Global.desync != 0.0f) {
if (Global.desync != 0.0f)
{
ImGui::SetNextWindowSize(ImVec2(-1, -1));
if (ImGui::Begin("network", nullptr, ImGuiWindowFlags_NoCollapse))
ImGui::Text("desync: %0.2f", Global.desync);