aboutsummaryrefslogtreecommitdiff
path: root/game/mainmenu/ButtonSubScene.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'game/mainmenu/ButtonSubScene.cpp')
-rw-r--r--game/mainmenu/ButtonSubScene.cpp96
1 files changed, 73 insertions, 23 deletions
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;
- }
-}