diff options
| -rw-r--r-- | src/game.c | 5 | ||||
| -rw-r--r-- | src/player.c | 21 | ||||
| -rw-r--r-- | src/ui.c | 73 | ||||
| -rw-r--r-- | src/ui.h | 6 |
4 files changed, 70 insertions, 35 deletions
@@ -60,8 +60,7 @@ FocusCommand testFloatingWindowCallback(FloatingWindow* window, Game* game) } // Button test. - if (GuiButton((Rectangle){x + 10.0, y + 50.0, 40.0, 20.0}, "A") - && window->hasFocus) + if (GuiButton((Rectangle){x + 10.0, y + 50.0, 40.0, 20.0}, "A")) { puts("hi"); } @@ -255,10 +254,12 @@ void enableGameCursor(Game* game) { game->isCursorEnabled = true; EnableCursor(); + enableWindowManager(&game->wm); } void disableGameCursor(Game* game) { game->isCursorEnabled = false; DisableCursor(); + disableWindowManager(&game->wm); } diff --git a/src/player.c b/src/player.c index a153443..9a08204 100644 --- a/src/player.c +++ b/src/player.c @@ -26,12 +26,11 @@ void updatePlayerHeight(Player* player, Game* game) player->position.y = height; } -void updatePlayerMovement(Player* player, Game* game) +void updatePlayerLookingAround(Player* player, Game* game) { - Camera* camera = &player->camera; - Vector2* cameraAngle = &player->cameraAngle; Settings* settings = &game->settings; - + Vector2* cameraAngle = &player->cameraAngle; + // Get mouse speed. Vector2 mouseSpeed = Vector2Scale(GetMouseDelta(), settings->mouseSpeed); mouseSpeed = Vector2Scale(mouseSpeed, 1.0 / (PI * 2.0)); @@ -41,10 +40,22 @@ void updatePlayerMovement(Player* player, Game* game) cameraAngle->x = Wrap(cameraAngle->x, -PI, PI); cameraAngle->y = Clamp(cameraAngle->y, -PI / 2.5, PI / 2.5); - // Set player direction + // Set player direction. Matrix matrix = MatrixRotateXYZ( (Vector3){-cameraAngle->y, cameraAngle->x, 0.0}); player->direction = (Vector3){matrix.m2, matrix.m6, matrix.m10}; +} + +void updatePlayerMovement(Player* player, Game* game) +{ + Camera* camera = &player->camera; + Vector2* cameraAngle = &player->cameraAngle; + Settings* settings = &game->settings; + + if (!game->isCursorEnabled) + { + updatePlayerLookingAround(player, game); + } // Walking around. player->velocity = Vector3Zero(); @@ -138,8 +138,7 @@ void updateFloatingWindowMinimized(FloatingWindow* window) window->rect.y + closeTitleSizeDeltaHalf, RAYGUI_WINDOW_CLOSEBUTTON_SIZE, RAYGUI_WINDOW_CLOSEBUTTON_SIZE}, - "#120#") - && window->hasFocus) + "#120#")) { window->minimized = false; } @@ -152,7 +151,7 @@ FocusCommand updateFloatingWindowNotMinimized(FloatingWindow* window, window->minimized = GuiWindowBox( (Rectangle){window->rect.x, window->rect.y, window->rect.width, - window->rect.height}, window->title) & window->hasFocus; + window->rect.height}, window->title); // Scissor and draw content within a scroll panel. if (window->callback != NULL) @@ -160,29 +159,17 @@ FocusCommand updateFloatingWindowNotMinimized(FloatingWindow* window, Rectangle scissor; // Handle scrolling. - if (window->hasFocus) - { - GuiScrollPanel( - (Rectangle){ - window->rect.x, window->rect.y + RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT, - window->rect.width, - window->rect.height - RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT}, - NULL, - (Rectangle){ - window->rect.x, window->rect.y, - window->contentSize.x, window->contentSize.y}, - &window->scroll, - &scissor); - } - else - { - scissor = (Rectangle){ - window->rect.x, - window->rect.y + RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT, + GuiScrollPanel( + (Rectangle){ + window->rect.x, window->rect.y + RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT, window->rect.width, - window->rect.height - RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT - }; - } + window->rect.height - RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT}, + NULL, + (Rectangle){ + window->rect.x, window->rect.y, + window->contentSize.x, window->contentSize.y}, + &window->scroll, + &scissor); bool requireScissor = window->rect.width < window->contentSize.x || window->rect.height < window->contentSize.x; @@ -207,10 +194,16 @@ FocusCommand updateFloatingWindowNotMinimized(FloatingWindow* window, return focus; } -FocusCommand updateFloatingWindow(FloatingWindow* window, Game* game) +FocusCommand updateFloatingWindow(FloatingWindow* window, WindowManager* wm, + Game* game) { FocusCommand focus = NO_FOCUS_ACTION; bool isMouseLeftClick = IsMouseButtonPressed(MOUSE_LEFT_BUTTON); + + if (wm->enabled && !window->hasFocus) + { + GuiSetState(STATE_DISABLED); + } // Window movement and resize input and collision check. if (isMouseLeftClick && !window->moving && !window->resizing) @@ -246,22 +239,33 @@ FocusCommand updateFloatingWindow(FloatingWindow* window, Game* game) focus = result == NO_FOCUS_ACTION ? focus : result; } + if (wm->enabled && !window->hasFocus) + { + GuiSetState(STATE_NORMAL); + } + return focus; } void initWindowManager(WindowManager* wm) { memset(wm, 0, sizeof(WindowManager)); + wm->enabled = true; } void updateWindowManager(WindowManager* wm, Game* game) { Vector2 mousePosition = GetMousePosition(); int focusOnto = -1; + + if (!wm->enabled) + { + GuiSetState(STATE_DISABLED); + } for (int index = 0; index < wm->windowCount; ++index) { - FocusCommand focus = updateFloatingWindow(&wm->windows[index], game); + FocusCommand focus = updateFloatingWindow(&wm->windows[index], wm, game); if (focusOnto != -1) { @@ -303,6 +307,11 @@ void updateWindowManager(WindowManager* wm, Game* game) } } + if (!wm->enabled) + { + GuiSetState(STATE_NORMAL); + } + if (focusOnto != -1) { focusOnWindow(wm, focusOnto); @@ -346,3 +355,13 @@ void focusOnWindow(WindowManager* wm, int windowIndex) window.hasFocus = true; wm->windows[wm->windowCount - 1] = window; } + +void enableWindowManager(WindowManager* wm) +{ + wm->enabled = true; +} + +void disableWindowManager(WindowManager* wm) +{ + wm->enabled = false; +} @@ -41,14 +41,18 @@ struct FloatingWindow { typedef struct { FloatingWindow windows[UI_WINDOW_MAX]; int windowCount; + bool enabled; } WindowManager; FloatingWindow createFloatingWindow(const char* title, Rectangle rect); -FocusCommand updateFloatingWindow(FloatingWindow* window, Game* game); +FocusCommand updateFloatingWindow(FloatingWindow* window, WindowManager* wm, + Game* game); void initWindowManager(WindowManager* wm); void updateWindowManager(WindowManager* wm, Game* game); void addWindowToWindowManager(WindowManager* wm, FloatingWindow window); void focusOnWindow(WindowManager* wm, int windowIndex); +void enableWindowManager(WindowManager* wm); +void disableWindowManager(WindowManager* wm); #endif |
