aboutsummaryrefslogtreecommitdiff
path: root/game/mainmenu
diff options
context:
space:
mode:
authorJAROWMR <jarorutjes07@gmail.com>2024-12-29 15:05:21 +0100
committerJAROWMR <jarorutjes07@gmail.com>2024-12-29 15:05:21 +0100
commitb758b2b20da8e3ab002dacc663237e1681ae973c (patch)
tree60c41aa58570eaebbc589b07ff13f045fe46a93a /game/mainmenu
parente007e8f467349eeddaf503e31897d4135ba6fed4 (diff)
back button
Diffstat (limited to 'game/mainmenu')
-rw-r--r--game/mainmenu/ButtonSetMainMenuScript.cpp19
-rw-r--r--game/mainmenu/ButtonSetMainMenuScript.h14
-rw-r--r--game/mainmenu/ButtonSubScene.cpp96
-rw-r--r--game/mainmenu/ButtonSubScene.h26
-rw-r--r--game/mainmenu/IButtonScript.cpp13
-rw-r--r--game/mainmenu/MainMenuConfig.h4
-rw-r--r--game/mainmenu/MainMenuScene.cpp13
-rw-r--r--game/mainmenu/ShopMenuScene.cpp11
8 files changed, 163 insertions, 33 deletions
diff --git a/game/mainmenu/ButtonSetMainMenuScript.cpp b/game/mainmenu/ButtonSetMainMenuScript.cpp
new file mode 100644
index 0000000..808d8a2
--- /dev/null
+++ b/game/mainmenu/ButtonSetMainMenuScript.cpp
@@ -0,0 +1,19 @@
+#include "ButtonSetMainMenuScript.h"
+#include "MainMenuConfig.h"
+#include "iostream"
+
+using namespace crepe;
+using namespace std;
+
+void ButtonSetMainMenuScript::init(){
+ cout << "script init" << endl;
+ IButtonScript::init();
+ this->subscribe<ButtonPressEvent>([this](const ButtonPressEvent& e) { return this->on_button_press(e); });
+}
+
+bool ButtonSetMainMenuScript::on_button_press(const ButtonPressEvent& e){
+ this->set_next_scene(MainMenuConfig::MAINMENU_SCENE);
+ cout << "Start triggered:" << e.metadata.game_object_id << std::endl;
+ return false;
+}
+
diff --git a/game/mainmenu/ButtonSetMainMenuScript.h b/game/mainmenu/ButtonSetMainMenuScript.h
new file mode 100644
index 0000000..44c21aa
--- /dev/null
+++ b/game/mainmenu/ButtonSetMainMenuScript.h
@@ -0,0 +1,14 @@
+#pragma once
+
+#include "IButtonScript.h"
+#include <crepe/api/Script.h>
+
+class ButtonSetMainMenuScript : public IButtonScript {
+public:
+ void init() override;
+ bool on_button_press(const crepe::ButtonPressEvent& e);
+private:
+ float velocity = 20;
+protected:
+ bool transition = false;
+};
diff --git a/game/mainmenu/ButtonSubScene.cpp b/game/mainmenu/ButtonSubScene.cpp
index b4abe21..7562128 100644
--- a/game/mainmenu/ButtonSubScene.cpp
+++ b/game/mainmenu/ButtonSubScene.cpp
@@ -1,6 +1,8 @@
#include "ButtonSubScene.h"
+#include "ButtonSetMainMenuScript.h"
#include "ButtonSetShopScript.h"
#include "ButtonTransitionPreviewScript.h"
+#include "IButtonScript.h"
#include "MainMenuConfig.h"
#include <crepe/api/BehaviorScript.h>
@@ -13,11 +15,64 @@ using namespace crepe;
using namespace std;
void ButtonSubScene::create(Scene & scn,const Data & data){
- GameObject button_object = scn.new_object("button","",data.position,0,1);
- this->large_btn_overlay(button_object);
- this->btn_text_middle(button_object,data.text,data.text_offset,data.text_size);
- this->set_script(button_object,data.script);
+ GameObject button_object = scn.new_object("button","",data.position,0,data.scale);
+ this->set_button_overlay(button_object,data);
+ this->btn_text(button_object,data);
+ this->set_script(button_object,data);
+ this->set_icon(button_object,data);
}
+
+void ButtonSubScene::btn_text(crepe::GameObject & button_object,const Data & data){
+
+ crepe::vec2 size = {data.text_width,(data.text_width/data.text.size())*2};
+
+ button_object.add_component<Text>(size,data.text_offset+MainMenuConfig::FONTOFFSET, MainMenuConfig::FONT, Text::Data{
+ .text_color = Color::WHITE,
+ }, data.text);
+}
+
+void ButtonSubScene::set_script(crepe::GameObject & button_object,const Data & data){
+ switch (data.script_type) {
+ case ScriptSelect::PREVIEW:
+ button_object.add_component<BehaviorScript>().set_script<ButtonTransitionPreviewScript>();
+ break;
+ case ScriptSelect::SHOP:
+ button_object.add_component<BehaviorScript>().set_script<ButtonSetShopScript>();
+ break;
+ case ScriptSelect::MAINMENU:
+ button_object.add_component<BehaviorScript>().set_script<ButtonSetMainMenuScript>();
+ break;
+ case ScriptSelect::NONE:
+ button_object.add_component<BehaviorScript>().set_script<IButtonScript>();
+ break;
+ }
+}
+
+void ButtonSubScene::set_icon(crepe::GameObject & button_object,const Data & data){
+ switch (data.icon_type) {
+ case IconSelect::SHOP:
+ button_object.add_component<Sprite>(Asset("asset/ui/buttonCoinsSmall.png"),Sprite::Data{
+ .sorting_in_layer = MainMenuConfig::STARTING_SORTING_IN_LAYER+3,
+ .size = MainMenuConfig::ICON_SIZE,
+ .position_offset = data.icon_offset,
+ });
+ break;
+ case IconSelect::NONE:
+ break;
+ }
+}
+
+void ButtonSubScene::set_button_overlay(crepe::GameObject & button_object,const Data & data){
+ switch (data.button_type) {
+ case ButtonSelect::LARGE:
+ this->large_btn_overlay(button_object);
+ break;
+ case ButtonSelect::SMALL:
+ this->small_btn_overlay(button_object);
+ break;
+ }
+}
+
void ButtonSubScene::large_btn_overlay(crepe::GameObject & button_object){
button_object.add_component<Sprite>(Asset("asset/ui/buttonBacking.png"),Sprite::Data{
.sorting_in_layer = MainMenuConfig::STARTING_SORTING_IN_LAYER+1,
@@ -27,6 +82,20 @@ void ButtonSubScene::large_btn_overlay(crepe::GameObject & button_object){
this->btn_color_side(button_object,SIDE_PANEL_OFFSET);
}
+void ButtonSubScene::small_btn_overlay(crepe::GameObject & button_object){
+ button_object.add_component<Sprite>(Asset("asset/ui/backbuttonright.png"),Sprite::Data{
+ .sorting_in_layer = MainMenuConfig::STARTING_SORTING_IN_LAYER+1,
+ .size = MainMenuConfig::SMALL_OVERLAY_SIZE_RIGHT,
+ .position_offset = {20,0},
+ });
+ button_object.add_component<Sprite>(Asset("asset/ui/backbuttonleft.png"),Sprite::Data{
+ .sorting_in_layer = MainMenuConfig::STARTING_SORTING_IN_LAYER+1,
+ .size = MainMenuConfig::SMALL_OVERLAY_SIZE_LEFT,
+ .position_offset = {-80,0},
+ });
+ button_object.add_component<Button>(vec2{MainMenuConfig::SMALL_OVERLAY_SIZE_LEFT.x+MainMenuConfig::SMALL_OVERLAY_SIZE_RIGHT.x,MainMenuConfig::SMALL_OVERLAY_SIZE_LEFT.y},vec2{0,0});
+}
+
void ButtonSubScene::btn_color_side(crepe::GameObject & button_object,const vec2 & offset){
button_object.add_component<Sprite>(Asset("asset/ui/buttonSmallBlue.png"),Sprite::Data{
.sorting_in_layer = MainMenuConfig::STARTING_SORTING_IN_LAYER+2,
@@ -40,22 +109,3 @@ void ButtonSubScene::btn_color_side(crepe::GameObject & button_object,const vec2
.position_offset = {-offset.x,offset.y},
});
}
-
-//fc-match arial
-void ButtonSubScene::btn_text_middle(crepe::GameObject & button_object,const std::string & text,const crepe::vec2 & text_offset,const crepe::vec2 & text_size){
- button_object.add_component<Text>(text_size,text_offset+MainMenuConfig::FONTOFFSET, MainMenuConfig::FONT, Text::Data{
- .text_color = Color::WHITE,
- }, text);
-}
-
-void ButtonSubScene::set_script(crepe::GameObject & button_object,ScriptSelect script){
- switch (script) {
- case ScriptSelect::PREVIEW:
- button_object.add_component<BehaviorScript>().set_script<ButtonTransitionPreviewScript>();
- break;
- case ScriptSelect::SHOP:
- button_object.add_component<BehaviorScript>().set_script<ButtonSetShopScript>();
- case ScriptSelect::NONE:
- break;
- }
-}
diff --git a/game/mainmenu/ButtonSubScene.h b/game/mainmenu/ButtonSubScene.h
index 9905a8b..6f183ed 100644
--- a/game/mainmenu/ButtonSubScene.h
+++ b/game/mainmenu/ButtonSubScene.h
@@ -13,23 +13,41 @@ public:
enum class ScriptSelect {
PREVIEW,
SHOP,
+ MAINMENU,
NONE,
};
+ //icon enum
+ enum class IconSelect {
+ SHOP,
+ NONE,
+ };
+ //icon enum
+ enum class ButtonSelect {
+ SMALL,
+ LARGE,
+ };
//data struct
struct Data{
const std::string & text = "NODATA";
const crepe::vec2 & text_offset = {0,0};
- const crepe::vec2 & text_size = {200,200};
+ const float text_width = 200;
+ const crepe::vec2 & icon_offset = {0,0};
+ const IconSelect icon_type = IconSelect::NONE;
const crepe::vec2 & position = {0,0};
- const ScriptSelect script = ScriptSelect::NONE;
+ const ScriptSelect script_type = ScriptSelect::NONE;
+ const ButtonSelect button_type = ButtonSelect::LARGE;
+ const float scale = 1;
};
public:
void create(crepe::Scene & scn,const Data & data);
private:
void large_btn_overlay(crepe::GameObject & button_object);
+ void small_btn_overlay(crepe::GameObject & button_object);
void btn_color_side(crepe::GameObject & button_object,const crepe::vec2 & offset);
- void btn_text_middle(crepe::GameObject & button_object,const std::string & text,const crepe::vec2 & text_offset,const crepe::vec2 & text_size);
- void set_script(crepe::GameObject & button_object,ScriptSelect script);
+ void btn_text(crepe::GameObject & button_object,const Data & data);
+ void set_script(crepe::GameObject & button_object,const Data & data);
+ void set_icon(crepe::GameObject & button_object,const Data & data);
+ void set_button_overlay(crepe::GameObject & button_object,const Data & data);
private:
static constexpr crepe::vec2 SIDE_PANEL_OFFSET = {113,0};
};
diff --git a/game/mainmenu/IButtonScript.cpp b/game/mainmenu/IButtonScript.cpp
index 6cd42fb..ab907c4 100644
--- a/game/mainmenu/IButtonScript.cpp
+++ b/game/mainmenu/IButtonScript.cpp
@@ -1,6 +1,8 @@
#include "IButtonScript.h"
+#include "api/Sprite.h"
#include "iostream"
#include "system/InputSystem.h"
+#include "types.h"
using namespace crepe;
using namespace std;
@@ -10,12 +12,21 @@ void IButtonScript::init(){
this->subscribe<ButtonEnterEvent>([this](const ButtonEnterEvent& e) { return this->on_button_enter(e); });
}
bool IButtonScript::on_button_exit(const ButtonExitEvent& e){
+ RefVector<Sprite> sprites = this->get_components<Sprite>();
+ for(Sprite & sprite : sprites)
+ {
+ sprite.data.color = Color{255,255,255,255};
+ }
cout << "button triggered:" << e.metadata.game_object_id << std::endl;
return false;
}
bool IButtonScript::on_button_enter(const ButtonEnterEvent& e){
-
+ RefVector<Sprite> sprites = this->get_components<Sprite>();
+ for(Sprite & sprite : sprites)
+ {
+ sprite.data.color = Color{200,200,200,255};
+ }
cout << "button Enter:" << e.metadata.game_object_id << std::endl;
return false;
}
diff --git a/game/mainmenu/MainMenuConfig.h b/game/mainmenu/MainMenuConfig.h
index fd7e922..9dbb838 100644
--- a/game/mainmenu/MainMenuConfig.h
+++ b/game/mainmenu/MainMenuConfig.h
@@ -16,6 +16,7 @@ struct MainMenuConfig {
static constexpr const char* START_SCENE = "scene1";
static constexpr const char* PREVIEW_SCENE = "scene1";
static constexpr const char* SHOP_SCENE = "shopmenu";
+ static constexpr const char* MAINMENU_SCENE = "mainmenu";
//Moving to new scene (Start and Preview)
static constexpr float SLOW_DOWN = 200;
static constexpr float END = 300;
@@ -25,6 +26,9 @@ struct MainMenuConfig {
static constexpr const char* FONT = "Jetpackia";
static constexpr crepe::vec2 FONTOFFSET = {0,0};
static constexpr crepe::vec2 LARGE_OVERLAY_SIZE = {250,100};
+ static constexpr crepe::vec2 SMALL_OVERLAY_SIZE_RIGHT = {150,100};
+ static constexpr crepe::vec2 SMALL_OVERLAY_SIZE_LEFT = {50,100};
static constexpr crepe::vec2 SIDE_PANEL_SIZE = {50,150};
+ static constexpr crepe::vec2 ICON_SIZE = {50,50};
};
diff --git a/game/mainmenu/MainMenuScene.cpp b/game/mainmenu/MainMenuScene.cpp
index 80c945b..e514ee5 100644
--- a/game/mainmenu/MainMenuScene.cpp
+++ b/game/mainmenu/MainMenuScene.cpp
@@ -34,19 +34,22 @@ void MainMenuScene::load_scene(){
//Preview btn
button.create(*this,ButtonSubScene::Data{
.text = "PREVIEW",
- .text_size = vec2{200,80},
+ .text_width = 200,
.position = pos,
- .script = ButtonSubScene::ScriptSelect::PREVIEW,
+ .script_type = ButtonSubScene::ScriptSelect::PREVIEW,
});
- //Shop btn
pos.y += MainMenuConfig::MENU_BUTTON_SPACING + MainMenuConfig::LARGE_OVERLAY_SIZE.y;
button.create(*this,ButtonSubScene::Data{
.text = "SHOP",
- .text_size = vec2{200,80},
+ .text_offset = {-20,0},
+ .text_width = 115,
+ .icon_offset = {60,0},
+ .icon_type = ButtonSubScene::IconSelect::SHOP,
.position = pos,
- .script = ButtonSubScene::ScriptSelect::SHOP,
+ .script_type = ButtonSubScene::ScriptSelect::SHOP,
});
+
//Start of map
StartSubScene start;
diff --git a/game/mainmenu/ShopMenuScene.cpp b/game/mainmenu/ShopMenuScene.cpp
index b18ae47..be2039f 100644
--- a/game/mainmenu/ShopMenuScene.cpp
+++ b/game/mainmenu/ShopMenuScene.cpp
@@ -1,5 +1,6 @@
#include "ShopMenuScene.h"
+#include "ButtonSubScene.h"
#include "api/Camera.h"
#include "MainMenuConfig.h"
#include "api/Sprite.h"
@@ -24,6 +25,16 @@ void ShopMenuScene::load_scene(){
.size = {1100,860},
.position_offset {0},
});
+
+ ButtonSubScene button;
+ button.create(*this,ButtonSubScene::Data{
+ .text = "BACK",
+ .text_width = 115,
+ .position = {-400,-350},
+ .script_type = ButtonSubScene::ScriptSelect::MAINMENU,
+ .button_type = ButtonSubScene::ButtonSelect::SMALL,
+ .scale = 0.8
+ });
}
string ShopMenuScene::get_name() const { return "shopmenu"; }