aboutsummaryrefslogtreecommitdiff
path: root/game/menus/shop/ShopLoadScript.cpp
blob: a9f9bfe156bab82d34f8367cdb56e26566730699 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "ShopLoadScript.h"
#include <crepe/ValueBroker.h>
#include "api/Button.h"
#include "api/Sprite.h"
#include "Shopconfig.h"
#include "api/Text.h"
#include "manager/SaveManager.h"

using namespace crepe;
using namespace std;

void ShopLoadScript::init() {
	this->update();
	this->subscribe<ShopUpdate>([this](const ShopUpdate e) {
		return this->update();
	});
}

bool ShopLoadScript::update(){
	SaveManager & save = this->get_save_manager();
	ValueBroker<int> buy_bullet = save.get<int>(BUY_BULLET_SAVE,0);
	ValueBroker<int> buy_bubble = save.get<int>(BUY_BUBBLE_SAVE,0);


	if(buy_bullet.get()){
		auto sprites = this->get_components_by_tag<Sprite>(BUY_BULLET);
		for(auto sprite : sprites){
			sprite.get().active = false;
		}
		auto buttons = this->get_components_by_tag<Button>(BUY_BULLET);
		for(auto btn : buttons){
			btn.get().active = false;
		}
		auto texts = this->get_components_by_tag<Text>(BUY_BULLET);
		for(auto txt : texts){
			txt.get().active = false;
		}
		auto sprites1 = this->get_components_by_tag<Sprite>(SELECT_BULLET);
		for(auto sprite : sprites1){
			sprite.get().active = true;
		}
		auto buttons1 = this->get_components_by_tag<Button>(SELECT_BULLET);
		for(auto btn : buttons1){
			btn.get().active = true;
		}
		auto texts1 = this->get_components_by_tag<Text>(SELECT_BULLET);
		for(auto txt : texts1){
			txt.get().active = true;
		}
	}
	else {
		auto sprites = this->get_components_by_tag<Sprite>(SELECT_BULLET);
		for(auto sprite : sprites){
			sprite.get().active = false;
		}
		auto buttons = this->get_components_by_tag<Button>(SELECT_BULLET);
		for(auto btn : buttons){
			btn.get().active = false;
		}
		auto texts = this->get_components_by_tag<Text>(SELECT_BULLET);
		for(auto txt : texts){
			txt.get().active = false;
		}
		auto sprites1 = this->get_components_by_tag<Sprite>(BUY_BULLET);
		for(auto sprite : sprites1){
			sprite.get().active = true;
		}
		auto buttons1 = this->get_components_by_tag<Button>(BUY_BULLET);
		for(auto btn : buttons1){
			btn.get().active = true;
		}
		auto texts1 = this->get_components_by_tag<Text>(BUY_BULLET);
		for(auto txt : texts1){
			txt.get().active = true;
		}
	}

	if(buy_bubble.get()){
		auto sprites = this->get_components_by_tag<Sprite>(BUY_BUBBLE);
		for(auto sprite : sprites){
			sprite.get().active = false;
		}
		auto buttons = this->get_components_by_tag<Button>(BUY_BUBBLE);
		for(auto btn : buttons){
			btn.get().active = false;
		}
		auto texts = this->get_components_by_tag<Text>(BUY_BUBBLE);
		for(auto txt : texts){
			txt.get().active = false;
		}
		auto sprites1 = this->get_components_by_tag<Sprite>(SELECT_BUBBLE);
		for(auto sprite : sprites1){
			sprite.get().active = true;
		}
		auto buttons1 = this->get_components_by_tag<Button>(SELECT_BUBBLE);
		for(auto btn : buttons1){
			btn.get().active = true;
		}
		auto texts1 = this->get_components_by_tag<Text>(SELECT_BUBBLE);
		for(auto txt : texts1){
			txt.get().active = true;
		}
	}
	else {
		auto sprites = this->get_components_by_tag<Sprite>(SELECT_BUBBLE);
		for(auto sprite : sprites){
			sprite.get().active = false;
		}
		auto buttons = this->get_components_by_tag<Button>(SELECT_BUBBLE);
		for(auto btn : buttons){
			btn.get().active = false;
		}
		auto texts = this->get_components_by_tag<Text>(SELECT_BUBBLE);
		for(auto txt : texts){
			txt.get().active = false;
		}
		auto sprites1 = this->get_components_by_tag<Sprite>(BUY_BUBBLE);
		for(auto sprite : sprites1){
			sprite.get().active = true;
		}
		auto buttons1 = this->get_components_by_tag<Button>(BUY_BUBBLE);
		for(auto btn : buttons1){
			btn.get().active = true;
		}
		auto texts1 = this->get_components_by_tag<Text>(BUY_BUBBLE);
		for(auto txt : texts1){
			txt.get().active = true;
		}
	}
	return false;
}