diff options
author | JAROWMR <jarorutjes07@gmail.com> | 2025-01-08 14:40:37 +0100 |
---|---|---|
committer | JAROWMR <jarorutjes07@gmail.com> | 2025-01-08 14:40:37 +0100 |
commit | 3b6081d03300d353434fd4f6e91237fc8f1a4390 (patch) | |
tree | 4c7b75f641e36de0c8aea933ea2cbdb213c35f0b /game | |
parent | aa8bf26452157f81f72b6d6759e461ff2ca24568 (diff) |
added credit window
Diffstat (limited to 'game')
-rw-r--r-- | game/CMakeLists.txt | 3 | ||||
-rw-r--r-- | game/menus/ButtonShowCreditsSubScript.cpp | 20 | ||||
-rw-r--r-- | game/menus/ButtonShowCreditsSubScript.h | 14 | ||||
-rw-r--r-- | game/menus/ButtonSubScene.cpp | 10 | ||||
-rw-r--r-- | game/menus/ButtonSubScene.h | 2 | ||||
-rw-r--r-- | game/menus/mainmenu/CreditsSubScene.cpp | 13 | ||||
-rw-r--r-- | game/menus/mainmenu/CreditsSubScript.cpp | 14 | ||||
-rw-r--r-- | game/menus/mainmenu/CreditsSubScript.h | 6 | ||||
-rw-r--r-- | game/menus/mainmenu/MainMenuScene.cpp | 6 |
9 files changed, 79 insertions, 9 deletions
diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 1f9b8cf..f81850d 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -37,11 +37,14 @@ add_executable(main menus/ButtonNextMainMenuSubScript.cpp menus/FloatingWindowSubScene.cpp menus/IFloatingWindowScript.cpp + menus/ButtonShowCreditsSubScript.cpp menus/shop/ShopMenuScene.cpp menus/mainmenu/ButtonTransitionPreviewSubScript.cpp menus/mainmenu/ITransitionScript.cpp menus/mainmenu/MainMenuScene.cpp menus/mainmenu/TransitionStartSubScript.cpp + menus/mainmenu/CreditsSubScene.cpp + menus/mainmenu/CreditsSubScript.cpp menus/endgame/EndGameSubScene.cpp menus/endgame/EndGameSubScript.cpp coins/CoinSubScene.cpp diff --git a/game/menus/ButtonShowCreditsSubScript.cpp b/game/menus/ButtonShowCreditsSubScript.cpp new file mode 100644 index 0000000..ec0e980 --- /dev/null +++ b/game/menus/ButtonShowCreditsSubScript.cpp @@ -0,0 +1,20 @@ +#include "ButtonShowCreditsSubScript.h" +#include "MenusConfig.h" +#include "mainmenu/CreditsSubScript.h" +#include <crepe/api/AudioSource.h> +#include <crepe/types.h> + +using namespace crepe; +using namespace std; + +void ButtonShowCreditsSubScript::init() { + IButtonScript::init(); + this->subscribe<ButtonPressEvent>([this](const ButtonPressEvent & e) { + return this->on_button_press(e); + }); +} + +bool ButtonShowCreditsSubScript::on_button_press(const ButtonPressEvent & e) { + this->trigger_event<ShowCreditsEvent>(); + return false; +} diff --git a/game/menus/ButtonShowCreditsSubScript.h b/game/menus/ButtonShowCreditsSubScript.h new file mode 100644 index 0000000..3c73c44 --- /dev/null +++ b/game/menus/ButtonShowCreditsSubScript.h @@ -0,0 +1,14 @@ +#pragma once + +#include "IButtonScript.h" + +#include <crepe/api/Script.h> + +class ButtonShowCreditsSubScript : public IButtonScript { +public: + void init() override; + bool on_button_press(const crepe::ButtonPressEvent & e); + +protected: + bool transition = false; +}; diff --git a/game/menus/ButtonSubScene.cpp b/game/menus/ButtonSubScene.cpp index 2fb4c38..d657be9 100644 --- a/game/menus/ButtonSubScene.cpp +++ b/game/menus/ButtonSubScene.cpp @@ -3,12 +3,14 @@ #include "ButtonReplaySubScript.h" #include "ButtonSetMainMenuSubScript.h" #include "ButtonSetShopSubScript.h" +#include "ButtonShowCreditsSubScript.h" #include "IButtonScript.h" #include "MenusConfig.h" #include "mainmenu/ButtonTransitionPreviewSubScript.h" #include "../Config.h" +#include "mainmenu/CreditsSubScript.h" #include <crepe/api/BehaviorScript.h> #include <crepe/api/Button.h> @@ -63,6 +65,14 @@ void ButtonSubScene::set_script(crepe::GameObject & button_object, const Data & button_object.add_component<BehaviorScript>() .set_script<ButtonReplaySubScript>(); break; + case ScriptSelect::CREDITS_BACK: + button_object.add_component<BehaviorScript>() + .set_script<CreditsSubScript>(data.tag); + break; + case ScriptSelect::CREDITS_SHOW: + button_object.add_component<BehaviorScript>() + .set_script<ButtonShowCreditsSubScript>(); + break; case ScriptSelect::NONE: button_object.add_component<BehaviorScript>().set_script<IButtonScript>(); break; diff --git a/game/menus/ButtonSubScene.h b/game/menus/ButtonSubScene.h index ba6d1f7..74f9464 100644 --- a/game/menus/ButtonSubScene.h +++ b/game/menus/ButtonSubScene.h @@ -17,6 +17,8 @@ public: MAINMENU, NEXT, REPLAY, + CREDITS_SHOW, + CREDITS_BACK, NONE, }; //icon enum diff --git a/game/menus/mainmenu/CreditsSubScene.cpp b/game/menus/mainmenu/CreditsSubScene.cpp index 9a49257..df4616e 100644 --- a/game/menus/mainmenu/CreditsSubScene.cpp +++ b/game/menus/mainmenu/CreditsSubScene.cpp @@ -1,7 +1,6 @@ #include "CreditsSubScene.h" #include "CreditsSubScript.h" -#include "EndGameSubScript.h" #include "../../Config.h" #include "../ButtonSubScene.h" @@ -19,7 +18,7 @@ using namespace std; void CreditsSubScene::create(Scene & scn) { - const std::string TAG = "end_game_tag"; + const std::string TAG = "credits_tag"; GameObject script = scn.new_object("script"); script.add_component<BehaviorScript>().set_script<CreditsSubScript>(TAG); @@ -30,7 +29,7 @@ void CreditsSubScene::create(Scene & scn) { FloatingWindowSubScene::Data { .group_tag = TAG, .width = 500, - .offset = {0, -50}, + .offset = {150, -50}, .width_middle_offset = -2, } ); @@ -45,7 +44,7 @@ void CreditsSubScene::create(Scene & scn) { .world_space = false, .text_color = Color::WHITE, }, - vec2 {0, -207} + FONTOFFSET, TITEL_STRING + vec2 {150, -207} + FONTOFFSET, TITEL_STRING ); // Buttons @@ -56,9 +55,9 @@ void CreditsSubScene::create(Scene & scn) { ButtonSubScene::Data { .text = "Back", .text_width = 150, - .position = {-button_position.x, button_position.y}, - //.script_type = ButtonSubScene::ScriptSelect::REPLAY, - //.button_type = ButtonSubScene::ButtonSelect::BACK, + .position = {-button_position.x+150, button_position.y}, + .script_type = ButtonSubScene::ScriptSelect::CREDITS_BACK, + .button_type = ButtonSubScene::ButtonSelect::BACK, .scale = 0.6, .worldspace = false, .tag = TAG, diff --git a/game/menus/mainmenu/CreditsSubScript.cpp b/game/menus/mainmenu/CreditsSubScript.cpp index 5326594..ce74ba4 100644 --- a/game/menus/mainmenu/CreditsSubScript.cpp +++ b/game/menus/mainmenu/CreditsSubScript.cpp @@ -13,9 +13,18 @@ using namespace crepe; + CreditsSubScript::CreditsSubScript(const std::string & tag) { this->tag = tag; } void CreditsSubScript::init() { + IButtonScript::init(); + this->subscribe<ButtonPressEvent>([this](const ButtonPressEvent & e) { + return this->on_button_press(e); + }); + this->subscribe<ShowCreditsEvent>([this](const ShowCreditsEvent & e) { + this->enable_all(); + return false; + }); this->disable_all(); } @@ -44,3 +53,8 @@ bool CreditsSubScript::enable_all() { } return false; } + +bool CreditsSubScript::on_button_press(const ButtonPressEvent & e) { + return this->disable_all(); +} + diff --git a/game/menus/mainmenu/CreditsSubScript.h b/game/menus/mainmenu/CreditsSubScript.h index 08e1f91..e411202 100644 --- a/game/menus/mainmenu/CreditsSubScript.h +++ b/game/menus/mainmenu/CreditsSubScript.h @@ -1,14 +1,18 @@ #pragma once #include "../IFloatingWindowScript.h" +#include "../IButtonScript.h" #include <crepe/api/Event.h> #include <crepe/api/Script.h> -class CreditsSubScript : public IFloatingWindowScript { +struct ShowCreditsEvent : public crepe::Event {}; + +class CreditsSubScript : public IFloatingWindowScript, public IButtonScript { public: CreditsSubScript(const std::string & tag); void init() override; bool disable_all(); bool enable_all(); + bool on_button_press(const crepe::ButtonPressEvent & e); }; diff --git a/game/menus/mainmenu/MainMenuScene.cpp b/game/menus/mainmenu/MainMenuScene.cpp index 743fe43..fba90ac 100644 --- a/game/menus/mainmenu/MainMenuScene.cpp +++ b/game/menus/mainmenu/MainMenuScene.cpp @@ -1,5 +1,6 @@ #include "MainMenuScene.h" +#include "CreditsSubScene.h" #include "MainMenuConfig.h" #include "TransitionStartSubScript.h" @@ -81,7 +82,7 @@ void MainMenuScene::load_scene() { .text_offset = {0, 0}, .text_width = 200, .position = pos_btn, - //.script_type = ButtonSubScene::ScriptSelect::SHOP, + .script_type = ButtonSubScene::ScriptSelect::CREDITS_SHOW, } ); @@ -123,6 +124,9 @@ void MainMenuScene::load_scene() { .tag = MENU_INFO_TAG, } ); + + CreditsSubScene creditscene; + creditscene.create(*this); } string MainMenuScene::get_name() const { return MAINMENU_SCENE; } |