From 188df84c57a17e9388b6f12f6d208e09debd2169 Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Sun, 18 Jan 2026 09:32:55 -0500 Subject: [PATCH] Remove keyboard shortcuts - always show UI panels and auto-follow Changes: 1. Remove all keyboard shortcuts (B, I, F keys) 2. UI panels always shown (body list, info, simulation info) 3. Selecting a body automatically enables camera follow 4. render_info() now uses GuiWindowBox style matching other UI UI improvements: - render_info() now uses GuiWindowBox for consistent styling - Positioned at bottom-left with smaller window (200x280) - Window close buttons disabled (panels always shown) - Updated help text to reflect new workflow User experience: - Simpler interaction - just select body from list to follow it - All information always visible - Consistent UI styling across all panels --- src/main.cpp | 8 +--- src/renderer.cpp | 117 ++++++++++++++++++++++++----------------------- src/renderer.h | 3 -- 3 files changed, 61 insertions(+), 67 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d3d60f5..90e64d4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,11 +35,9 @@ void run_gui_simulation(SimulationState* sim) { RenderState render_state; setup_camera(&render_state); - + // Initialize UI state render_state.selected_body_index = -1; // No selection initially - render_state.show_body_list = false; - render_state.show_body_info = false; render_state.body_list_scroll = 0; // Initial scroll position render_state.body_list_active = -1; // No active item initially render_state.camera_follow_body = false; // Camera not following initially @@ -55,9 +53,7 @@ void run_gui_simulation(SimulationState* sim) { printf(" Arrow keys: Rotate and zoom camera\n"); printf(" Space: Pause/Resume\n"); printf(" +/-: Speed up/slow down simulation\n"); - printf(" I: Toggle info display\n"); - printf(" B: Toggle body list\n"); - printf(" F: Toggle camera follow on selected body\n"); + printf(" Select body from list to follow it\n"); printf(" ESC: Quit\n\n"); while (!WindowShouldClose()) { diff --git a/src/renderer.cpp b/src/renderer.cpp index a7132c4..96fa5c3 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -32,7 +32,6 @@ void setup_camera(RenderState* render_state) { // Set scaling factors (same scale for distances and sizes) render_state->distance_scale = 1e-9; // Meters to scaled units (1 unit = 1 billion meters) render_state->size_scale = 1e-9; // Same scale for body sizes (minimum size still applies) - render_state->show_info = true; } // Update camera with keyboard/mouse controls @@ -137,26 +136,6 @@ void update_camera(RenderState* render_state, SimulationState* sim) { } } - // Toggle info display with I key - if (IsKeyPressed(KEY_I)) { - render_state->show_info = !render_state->show_info; - } - - // Toggle body list with B key - if (IsKeyPressed(KEY_B)) { - render_state->show_body_list = !render_state->show_body_list; - } - - // Toggle camera follow with F key - if (IsKeyPressed(KEY_F)) { - if (render_state->selected_body_index >= 0) { - render_state->camera_follow_body = !render_state->camera_follow_body; - printf("Camera follow: %s\n", render_state->camera_follow_body ? "enabled" : "disabled"); - } else { - render_state->camera_follow_body = false; - } - } - // Store previous follow state render_state->was_following_body = render_state->camera_follow_body; } @@ -398,12 +377,8 @@ void render_simulation(SimulationState* sim, RenderState* render_state) { EndMode3D(); - // Render 2D info overlay - if (render_state->show_info) { - render_info(sim, "solar_system.txt"); - } - - // Render UI panels + // Render UI panels (always shown) + render_info(sim, "solar_system.txt"); render_body_list_ui(sim, render_state); render_body_info_ui(sim, render_state); @@ -412,40 +387,59 @@ void render_simulation(SimulationState* sim, RenderState* render_state) { // Render simulation information overlay void render_info(SimulationState* sim, const char* config_name) { - DrawText("Orbital Mechanics Simulation", 10, 10, 20, WHITE); + // Panel dimensions + int panel_width = 200; + int panel_height = 280; + int panel_x = 10; + int panel_y = GetScreenHeight() - panel_height - 10; + + Rectangle panel_bounds = { (float)panel_x, (float)panel_y, (float)panel_width, (float)panel_height }; + + // Draw window + if (GuiWindowBox(panel_bounds, "Info")) { + // Window box close button doesn't close this panel + } + + // Prepare info text + char info_text[1024]; + char temp_buffer[256]; + int offset = 0; - char buffer[256]; + snprintf(info_text, sizeof(info_text), "Orbital Mechanics Simulation\n\n"); // Simulation time (in days) double days = sim->time / 86400.0; // seconds to days - snprintf(buffer, sizeof(buffer), "Time: %.2f days", days); - DrawText(buffer, 10, 40, 16, LIGHTGRAY); + snprintf(temp_buffer, sizeof(temp_buffer), "Time: %.2f days\n", days); + strcat(info_text, temp_buffer); // Body count - snprintf(buffer, sizeof(buffer), "Bodies: %d", sim->body_count); - DrawText(buffer, 10, 60, 16, LIGHTGRAY); - - // Config name - snprintf(buffer, sizeof(buffer), "Config: %s", config_name); - DrawText(buffer, 10, 80, 16, LIGHTGRAY); + snprintf(temp_buffer, sizeof(temp_buffer), "Bodies: %d\n", sim->body_count); + strcat(info_text, temp_buffer); // FPS - snprintf(buffer, sizeof(buffer), "FPS: %d", GetFPS()); - DrawText(buffer, 10, 100, 16, LIGHTGRAY); + snprintf(temp_buffer, sizeof(temp_buffer), "FPS: %d\n\n", GetFPS()); + strcat(info_text, temp_buffer); // Controls - DrawText("Controls:", 10, 130, 16, YELLOW); - DrawText(" Arrows: Rotate/Zoom camera", 10, 150, 14, LIGHTGRAY); - DrawText(" Space: Pause/Resume", 10, 170, 14, LIGHTGRAY); - DrawText(" +/-: Speed up/slow down", 10, 190, 14, LIGHTGRAY); - DrawText(" I: Toggle info", 10, 210, 14, LIGHTGRAY); - DrawText(" ESC: Quit", 10, 230, 14, LIGHTGRAY); + strcat(info_text, "Controls:\n"); + strcat(info_text, " Arrows: Rotate/Zoom\n"); + strcat(info_text, " Space: Pause/Resume\n"); + strcat(info_text, " +/-: Speed control\n"); + strcat(info_text, " ESC: Quit\n"); + + // Draw info text (inside window, leave space for title bar) + Rectangle text_bounds = { + (float)panel_x + 8, + (float)panel_y + 25, + (float)panel_width - 16, + (float)panel_height - 29 + }; + + GuiLabel(text_bounds, info_text); } // Render body list UI panel void render_body_list_ui(SimulationState* sim, RenderState* render_state) { - if (!render_state->show_body_list) return; - // Panel dimensions int panel_width = 200; int panel_height = 400; @@ -469,10 +463,8 @@ void render_body_list_ui(SimulationState* sim, RenderState* render_state) { offset += snprintf(body_list_text + offset, buffer_size - offset, "%s", sim->bodies[i].name); } - // Draw window - if (GuiWindowBox(panel_bounds, "Bodies")) { - render_state->show_body_list = false; - } + // Draw window (no close button - panels always shown) + GuiWindowBox(panel_bounds, "Bodies"); // Draw list view (inside window, leave space for title bar) Rectangle list_bounds = { @@ -489,7 +481,9 @@ void render_body_list_ui(SimulationState* sim, RenderState* render_state) { if (render_state->body_list_active >= 0 && render_state->body_list_active < sim->body_count && render_state->body_list_active != previous_active) { render_state->selected_body_index = render_state->body_list_active; - render_state->show_body_info = true; + // Enable camera follow when body is selected + render_state->camera_follow_body = true; + printf("Camera follow enabled for: %s\n", sim->bodies[render_state->selected_body_index].name); } free(body_list_text); @@ -497,8 +491,17 @@ void render_body_list_ui(SimulationState* sim, RenderState* render_state) { // Render body information UI panel void render_body_info_ui(SimulationState* sim, RenderState* render_state) { - if (!render_state->show_body_info || render_state->selected_body_index < 0 || - render_state->selected_body_index >= sim->body_count) return; + if (render_state->selected_body_index < 0 || render_state->selected_body_index >= sim->body_count) { + // No body selected - render empty panel + int panel_width = 250; + int panel_height = 300; + int panel_x = GetScreenWidth() - panel_width - 10; + int panel_y = 10; + + Rectangle panel_bounds = { (float)panel_x, (float)panel_y, (float)panel_width, (float)panel_height }; + GuiWindowBox(panel_bounds, "Info"); + return; + } // Panel dimensions int panel_width = 250; @@ -510,10 +513,8 @@ void render_body_info_ui(SimulationState* sim, RenderState* render_state) { CelestialBody* body = &sim->bodies[render_state->selected_body_index]; - // Draw window - if (GuiWindowBox(panel_bounds, body->name)) { - render_state->show_body_info = false; - } + // Draw window (no close button - panels always shown) + GuiWindowBox(panel_bounds, body->name); // Prepare info text char info_text[1024]; diff --git a/src/renderer.h b/src/renderer.h index 5cc4f9b..0595dbc 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -9,10 +9,7 @@ struct RenderState { Camera3D camera; double distance_scale; // Scale factor for distances double size_scale; // Scale factor for body sizes - bool show_info; // Display simulation info int selected_body_index; // -1 = no selection - bool show_body_list; // Toggle for list panel - bool show_body_info; // Toggle for info panel int body_list_scroll; // Scroll position for body list int body_list_active; // Active item index in body list bool camera_follow_body; // Whether camera follows selected body