summaryrefslogtreecommitdiffstats
path: root/Client/GUI/GUI_Menu_Upgrade.sqf
blob: 1ceb51eefdf654748bc630c19b143f07eb332f1b (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
disableSerialization;

_display = _this select 0;
displayUpgrade = "";

MenuAction = -1;
mouseX = -1;
mouseY = -1;

_requiredFunds = 0;
_requiredSupply = 0;

_tooltip = _display DisplayCtrl 18998;
_tooltip_text = _display DisplayCtrl 18999;

_controls = [];
_u = 18001;
_curIDC = _display DisplayCtrl _u;
while {!isNull _curIDC} do {_controls = _controls + [_curIDC];_u = _u + 1;_curIDC = _display DisplayCtrl _u};

_level = 0;
_val = 0;
_time = 0;
_name = '';
_tooltip_text_content = '';
_canUpgrade = false;
_dependent = false;
_isUpgrading = false;
_lastTimerUpdate = -5;
_upgr = 'WFBE_UPGRADELABELS' Call GetNamespace;
_upgrlev = 'WFBE_UPGRADELEVELS' Call GetNamespace;
_upgrdep = 'WFBE_UPGRADEDEPENDENCIES' Call GetNamespace;
_upgrcond = 'WFBE_UPGRADECONDITION' Call GetNamespace;
_upgrdesc = 'WFBE_UPGRADEDESCRIPTION' Call GetNamespace; //---added MrNiceGuy


while {alive player && dialog} do {
	if (Side player != sideJoined) exitWith {closeDialog 0};
	if !(dialog) exitWith {};
	
	_upgrades = (sideJoinedText) Call GetSideUpgrades;
	
	if (time - _lastTimerUpdate > 1) then {_lastTimerUpdate = time;_isUpgrading = Call Compile Format ["WFBE_%1_Upgrading",sideJoinedText]};
	
	_u = 0;
	{
		_level = _upgrades select _u;
		_maxLevel = _upgrlev select _u;
		_dependencie = _upgrdep select _u;
		_condition = _upgrcond select _u;
		if (_level == _maxLevel) then {_x ctrlSetTextColor [0, 1, 0, 1]};
		if (!_condition) then {_x ctrlSetTextColor [1, 0, 0, 1]};
		if (count _dependencie > 0 && _level != _maxLevel && _condition) then {
			if (_upgrades select (_dependencie select 0) < (_dependencie select 1)) then {
				_x ctrlSetTextColor [1, 0, 0, 1];
			} else {
				if (_level != _maxLevel) then {
					_x ctrlSetTextColor [0.75,0.75,0.75,1];
				};
			};
		};
		_u = _u + 1;
	} forEach _controls;
	
	//--- Tooltips.
	if (displayUpgrade != "") then {
		
		switch (displayUpgrade) do {
			case "infantry": {_val = 0};
			case "light": {_val = 1};
			case "heavy": {_val = 2};
			case "air": {_val = 3};
			case "parachutist": {_val = 4};
			case "uav": {_val = 5};
			case "supply": {_val = 6};
			case "ambuSpawn": {_val = 7};
			case "airlift": {_val = 8};
			case "flares": {_val = 9};
			case "artillery": {_val = 10};
			case "icbm": {_val = 11};
			case "fasttravel": {_val = 12};
			case "gear": {_val = 13};
			case "ammo": {_val = 14};
			case "easa": {_val = 15};
			case "paradrop": {_val = 16};
			case "shells": {_val = 17};
		};

		ctrlSetFocus (_controls select _val);
		
		_dependencie = _upgrdep select _val;
		_condition = _upgrcond select _val;
		_maxLevel = _upgrlev select _val;
		_name = _upgr select _val;
		_level = _upgrades select _val;
		_desc = _upgrdesc select _val; //---added MrNiceGuy

		
		_enabled = true;
		if (!_condition) then {_enabled = false};
		if (count _dependencie > 0 && _enabled) then {
			if (_upgrades select (_dependencie select 0) < (_dependencie select 1)) then {
				_dependent = true;
			} else {_dependent = false};
		} else {_dependent = false};
		
		_bpath = if (_level == _maxLevel) then {_level} else {_level + 1};
		_time = (Format["WFBE_UPGRADETIMESLEVEL%1",_bpath] Call GetNamespace) select _val;
		_needed = (Format["WFBE_UPGRADEPRICESLEVEL%1",_bpath] Call GetNamespace) select _val;
		_requiredSupply = _needed select 0;
		_requiredFunds = _needed select 1;

		_currentSupply = (sideJoined) Call GetSideSupply;
		_currentFunds = Call GetPlayerfunds;
		
		_colorSupply = "'#ff9900'";
		_colorFunds = "'#ff9900'";
		_hasFunds = true;
		if !(paramMoneyOnly) then {if (_currentSupply < _requiredSupply) then {_colorSupply = "'#ff0033'";_hasFunds = false}};
		if (_currentFunds < _requiredFunds) then {_colorFunds = "'#ff0033'";_hasFunds = false};
		
		if (!_isUpgrading && _level < _maxLevel && !_dependent && _enabled && _hasFunds) then {_canUpgrade = true} else {_canUpgrade = false};
		
		_tooltip_w = 0.30;
		_tooltip_h = 0.50;
		_tooltip_x = if ((1 - mouseX) < _tooltip_w) then {mouseX - _tooltip_w - 0.02} else {mouseX + 0.02};
		_tooltip_y = if (mouseY > 0.5) then {mouseY - _tooltip_h - 0.02} else {mouseY + 0.02};
		
		if (_level != _maxLevel) then {
			_supplyCd = if !(paramMoneyOnly) then {Format ["<t size='0.8' color='#bfbfbf' font='Zeppelin33'>%1</t><br />",Format [localize 'STR_WF_UPGRADE_Cost',"<t color=" + _colorSupply + ">" + str(_requiredSupply) + '</t>' + '/' + "<t color='#ff9900'>" + str(_currentSupply) + '</t> S']]} else {""};
			_tooltip_text_content = parsetext (
				Format ["<t size='1.2' color='#338dcc' shadow='0'>%1:</t><br />",_name] +
				Format ["<t size='0.8' color='#bfbfbf' font='Zeppelin33'>%1</t><br /><br />",Format [localize 'STR_WF_UPGRADE_Level',"<t color='#ff9900'>" + str(_level) + '</t>' + "/<t color='#ff9900'>" + str(_maxLevel) + '</t>']] +
				_supplyCd +
				Format ["<t size='0.8' color='#bfbfbf' font='Zeppelin33'>%1</t><br />",Format [localize 'STR_WF_UPGRADE_Cost',"<t color=" + _colorFunds + ">" + str(_requiredFunds) + '</t>' + '/' + "<t color='#ff9900'>" + str(_currentFunds) + '</t> $']] +
				Format ["<t size='0.8' color='#bfbfbf' font='Zeppelin33'>%1</t><br /><br />",Format [localize 'STR_WF_UPGRADE_Duration',"<t color='#ff9900'>" + str(_time) + ' </t>' + localize 'STR_WF_Seconds']] +
				Format ["<t size='0.8' color='#ff9900' shadow='0'>%1</t><br />",localize 'STR_WF_UPGRADE_Description'] + /* added MrNiceGuy */
				Format ["<t size='0.8' color='#338dcc' shadow='2'>%1</t><br />",_desc] /* added MrNiceGuy */
			);

			if (_isUpgrading) then {
				//_tooltip_h = 0.12;
				_tooltip_text_content = parsetext (
					Format ["<t size='1.2' color='#338dcc' shadow='0'>%1:</t><br />",_name] +
					Format ["<t size='0.8' color='#bfbfbf' font='Zeppelin33'>%1</t><br /><br />",Format [localize 'STR_WF_UPGRADE_Level',"<t color='#ff9900'>" + str(_level) + '</t>' + "/<t color='#ff9900'>" + str(_maxLevel) + '</t>']] + /* added MrNiceGuy */
					Format ["<t size='0.8' color='#ff9900' font='Zeppelin33'>%1</t><br /><br />",localize 'STR_WF_UPGRADE_AlreadyRunning']+
					Format ["<t size='0.8' color='#ff9900' shadow='0'>%1</t><br />",localize 'STR_WF_UPGRADE_Description'] + /* added MrNiceGuy */
					Format ["<t size='0.8' color='#338dcc' shadow='0'>%1</t><br />",_desc] /* added MrNiceGuy */
				);
			};
			if (!_enabled) then {
				//_tooltip_h = 0.12; /* added MrNiceGuy */
				_tooltip_text_content = parsetext (
					Format ["<t size='1.2' color='#338dcc' shadow='0'>%1:</t><br />",_name] +
					Format ["<t size='0.8' color='#ff0033' font='Zeppelin33'>%1</t><br /><br />",localize 'STR_WF_UPGRADE_Condition'] +
					Format ["<t size='0.8' color='#ff9900' shadow='0'>%1</t><br />",localize 'STR_WF_UPGRADE_Description'] + /* added MrNiceGuy */
					Format ["<t size='0.8' color='#338dcc' shadow='0'>%1</t><br />",_desc] /* added MrNiceGuy */
				);			
			};
			if (_dependent && !_isUpgrading && _enabled) then {
				_tooltip_text_content = parsetext (
					Format ["<t size='1.2' color='#338dcc' shadow='0'>%1:</t><br />",_name] +
					Format ["<t size='0.8' color='#bfbfbf' font='Zeppelin33'>%1</t><br /><br />",Format [localize 'STR_WF_UPGRADE_Level',"<t color='#ff9900'>" + str(_level) + '</t>' + "/<t color='#ff9900'>" + str(_maxLevel) + '</t>']] + /* added MrNiceGuy */
					Format ["<t size='0.8' color='#ff9900' font='Zeppelin33'>%1</t><br /><br />",Format[localize 'STR_WF_UPGRADE_Dependent',_upgr select (_dependencie select 0),_dependencie select 1]] +
					Format ["<t size='0.8' color='#ff9900' shadow='0'>%1</t><br />",localize 'STR_WF_UPGRADE_Description'] + /* added MrNiceGuy */
					Format ["<t size='0.8' color='#338dcc' shadow='0'>%1</t><br />",_desc] /* added MrNiceGuy */
				);			
			};
		} else {
			//_tooltip_h = 0.12;
			_tooltip_text_content = parsetext (
				Format ["<t size='1.2' color='#338dcc' shadow='0'>%1:</t><br />",_name] +
				Format ["<t size='0.8' color='#bfbfbf' font='Zeppelin33'>%1</t><br /><br />",Format [localize 'STR_WF_UPGRADE_Level',"<t color='#ff9900'>" + str(_level) + '</t>' + "/<t color='#ff9900'>" + str(_maxLevel) + '</t>']] + /* added MrNiceGuy */
				Format ["<t size='0.8' color='#00ff33' font='Zeppelin33'>%1</t><br /><br />",localize 'STR_WF_UPGRADE_Maximum'] +
				Format ["<t size='0.8' color='#ff9900' shadow='0'>%1</t><br />",localize 'STR_WF_UPGRADE_Description'] + /* added MrNiceGuy */
				Format ["<t size='0.8' color='#338dcc' shadow='0'>%1</t><br />",_desc] /* added MrNiceGuy */

			);
		};
		
		if ((ctrlPosition _tooltip select 0) == 0 || true) then {_tooltip ctrlSetPosition [_tooltip_x,_tooltip_y,_tooltip_w,_tooltip_h]};
		_tooltip ctrlCommit 0;
		
		_tooltip_text ctrlSetStructuredText _tooltip_text_content;
		if ((ctrlPosition _tooltip_text select 0) == 0 || true) then {_tooltip_text ctrlSetPosition [_tooltip_x,_tooltip_y,_tooltip_w,_tooltip_h]};
		_tooltip_text ctrlCommit 0;
		
	} else {
		if ((ctrlPosition _tooltip select 0) != 0) then {_tooltip ctrlSetPosition [0,0,0,0];_tooltip ctrlCommit 0};
		if ((ctrlPosition _tooltip_text select 0) != 0) then {_tooltip_text ctrlSetPosition [0,0,0,0];_tooltip_text ctrlCommit 0};
	};
	
	_commander = false;
	if (!isNull(commanderTeam)) then {
		if (commanderTeam == group player) then {_commander = true};
	};
	
	if (MenuAction == 1 && _canUpgrade && _commander) then {
		MenuAction = -1;
		-(_requiredFunds) Call ChangePlayerFunds;
		if !(paramMoneyOnly) then {[sideJoined, -_requiredSupply] Call ChangeSideSupply};
		
		WFBE_RequestUpgrade = ['SRVFNCREQUESTUPGRADE',[_time,_level,_val,_name,sideJoined]];
		publicVariable 'WFBE_RequestUpgrade';
		if (isHostedServer) then {['SRVFNCREQUESTUPGRADE',[_time,_level,_val,_name,sideJoined]] Spawn HandleSPVF};
		
		Call Compile Format ["WFBE_%1_Upgrading = true;",sideJoinedText];
		_isUpgrading = true;
		hint Format [localize "STR_WF_INFO_Upgrade_Start",_name];
	} else {MenuAction = -1};
	
	_txt = if (_isUpgrading) then {localize "STR_WF_UPGRADE_RunningInfo" + "..."} else {""};
	ctrlSetText[18802,_txt];
	
	sleep 0.05;
	
	//--- Back Button.
	if (MenuAction == 2) exitWith { //---added-MrNiceGuy
		MenuAction = -1;
		closeDialog 0;
		createDialog "WF_Menu";
	};
};