diff options
author | nathansmithsmith <thenathansmithsmith@gmail.com> | 2023-12-22 16:59:47 -0700 |
---|---|---|
committer | nathansmithsmith <thenathansmithsmith@gmail.com> | 2023-12-22 16:59:47 -0700 |
commit | 5b7e4668d549237e02dfe0580918c48b6d3b5c2d (patch) | |
tree | bc31e830e86c27d77bdb2955942f03d176bedca4 /src | |
parent | 797381def454d1556f82a81e6452c7b8ee6d1bad (diff) |
Reset button
Diffstat (limited to 'src')
-rw-r--r-- | src/screens/infoScreen.c | 64 | ||||
-rw-r--r-- | src/screens/infoScreen.h | 7 |
2 files changed, 56 insertions, 15 deletions
diff --git a/src/screens/infoScreen.c b/src/screens/infoScreen.c index 58a19ed..ca968d2 100644 --- a/src/screens/infoScreen.c +++ b/src/screens/infoScreen.c @@ -52,7 +52,11 @@ const EntityUserInfo infoScreenEntityInfo[INFO_SCREEN_ENTITY_COUNT] = { void initInfoScreen(Game * game) { InfoScreen * infoScreen = &game->infoScreen; + // Buttons. infoScreen->goBackButton = (Rectangle){0.0, 25.0, 100.0, 50.0}; + infoScreen->backButton = (Rectangle){0.0, 85.0, 100.0, 50.0}; + infoScreen->nextButton = (Rectangle){100.0, 85.0, 100.0, 50.0}; + infoScreen->resetButton = (Rectangle){0.0, 145.0, 100.0, 50.0}; // Camera. infoScreen->camera = (Camera3D){ @@ -65,12 +69,13 @@ void initInfoScreen(Game * game) { infoScreen->currentEntity = 0; - infoScreen->rotation = QuaternionIdentity(); infoScreen->resetMouse = true; - // Set distances. - for (int i = 0; i < ENTITY_USER_INFO_MSG_MAX; ++i) + // Set distances and roations. + for (int i = 0; i < ENTITY_USER_INFO_MSG_MAX; ++i) { infoScreen->distances[i] = infoScreenEntityInfo[i].cameraDistance; + infoScreen->rotations[i] = QuaternionIdentity(); + } resizeInfoScreen(game, infoScreen); } @@ -106,8 +111,8 @@ void updateInfoScreenCameraControls(Game * game, InfoScreen * infoScreen) { // Apply rotation. Quaternion rotationSpeed = QuaternionFromAxisAngle(angle.axis, angle.angle * t); - infoScreen->rotation = QuaternionMultiply(infoScreen->rotation, rotationSpeed); - infoScreen->rotation = QuaternionNormalize(infoScreen->rotation); + infoScreen->rotations[currentEntity] = QuaternionMultiply(infoScreen->rotations[currentEntity], rotationSpeed); + infoScreen->rotations[currentEntity] = QuaternionNormalize(infoScreen->rotations[currentEntity]); } void updateInfoScreenCamera(Game * game, InfoScreen * infoScreen) { @@ -117,13 +122,43 @@ void updateInfoScreenCamera(Game * game, InfoScreen * infoScreen) { camera->position = (Vector3){0.0, 0.0, infoScreen->distances[currentEntity]}; } +void infoScreenBack(InfoScreen * infoScreen) { + --infoScreen->currentEntity; + infoScreen->currentEntity = Clamp(infoScreen->currentEntity, 0, INFO_SCREEN_ENTITY_COUNT - 1); +} + +void infoScreenNext(InfoScreen * infoScreen) { + ++infoScreen->currentEntity; + infoScreen->currentEntity = Clamp(infoScreen->currentEntity, 0, INFO_SCREEN_ENTITY_COUNT - 1); +} + +void infoScreenResetEntity(InfoScreen * infoScreen) { + int currentEntity = infoScreen->currentEntity; + + infoScreen->resetMouse = true; + infoScreen->rotations[currentEntity] = QuaternionIdentity(); + infoScreen->distances[currentEntity] = infoScreenEntityInfo[currentEntity].cameraDistance; +} + void drawInfoScreenUI(Game * game, InfoScreen * infoScreen) { int currentEntity = infoScreen->currentEntity; - // Back button. - if (GuiButton(infoScreen->goBackButton, "Back")) + // Back to main menu button. + if (GuiButton(infoScreen->goBackButton, "Main menu")) game->screenId = SCREEN_MAIN_MENU; + // Back button. + if (GuiButton(infoScreen->backButton, "Back")) + infoScreenBack(infoScreen); + + // Next button. + if (GuiButton(infoScreen->nextButton, "Next")) + infoScreenNext(infoScreen); + + // Reset button. + if (GuiButton(infoScreen->resetButton, "Reest")) + infoScreenResetEntity(infoScreen); + // Draw ship name. EntityType type = infoScreenEntityInfo[currentEntity].type; const char * name = entityTypeInfo[type].name; @@ -156,11 +191,8 @@ void updateInfoScreen(Game * game) { ClearBackground(BLACK); // Reset. - if (IsKeyPressed(KEY_R)) { - infoScreen->resetMouse = true; - infoScreen->rotation = QuaternionIdentity(); - infoScreen->distances[currentEntity] = infoScreenEntityInfo[currentEntity].cameraDistance; - } + if (IsKeyPressed(KEY_R)) + infoScreenResetEntity(infoScreen); // Change distance. infoScreen->distances[currentEntity] += GetMouseWheelMove(); @@ -180,6 +212,12 @@ void updateInfoScreen(Game * game) { drawInfoScreenUI(game, infoScreen); } + // Arrows. + if (IsKeyPressed(KEY_LEFT)) + infoScreenBack(infoScreen); + else if (IsKeyPressed(KEY_RIGHT)) + infoScreenNext(infoScreen); + EntityUserInfo info = infoScreenEntityInfo[currentEntity]; // Update camera. @@ -188,7 +226,7 @@ void updateInfoScreen(Game * game) { // Draw shit. BeginMode3D(infoScreen->camera); - game->assets.models[info.assetId].transform = QuaternionToMatrix(infoScreen->rotation); + game->assets.models[info.assetId].transform = QuaternionToMatrix(infoScreen->rotations[currentEntity]); DrawModelWires(game->assets.models[info.assetId], Vector3Zero(), 1.0, GREEN); EndMode3D(); diff --git a/src/screens/infoScreen.h b/src/screens/infoScreen.h index 0c2f93d..a84180c 100644 --- a/src/screens/infoScreen.h +++ b/src/screens/infoScreen.h @@ -21,7 +21,10 @@ typedef struct EntityUserInfo { extern const EntityUserInfo infoScreenEntityInfo[INFO_SCREEN_ENTITY_COUNT]; typedef struct InfoScreen { - Rectangle goBackButton; + Rectangle goBackButton; // Go to main menu. + Rectangle backButton; + Rectangle nextButton; + Rectangle resetButton; Camera3D camera; float distances[ENTITY_USER_INFO_MSG_MAX]; @@ -29,7 +32,7 @@ typedef struct InfoScreen { int currentEntity; Vector2 lastMouse; - Quaternion rotation; + Quaternion rotations[ENTITY_USER_INFO_MSG_MAX]; bool resetMouse; } InfoScreen; |