Skip to content

Commit

Permalink
Fix buymenu (#264)
Browse files Browse the repository at this point in the history
* wip fix buy menu - control all buttons on any change

* fix exploit possibility in buy menu

* fix category count not cached

* add 3d icons to ACE spectator
  • Loading branch information
nomisum authored Jul 11, 2020
1 parent b695ba4 commit a2179d6
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 103 deletions.
78 changes: 38 additions & 40 deletions BC_buymenu/functions/fn_changeValue.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ private _ctrlSingleCount = _parentControl getVariable ["ctrlSingleCount", contro
private _data = _parentControl getVariable ["data", []];

private _baseConfigName = _parentControl getVariable ["baseConfigName", "none"];
private _categoryName = _parentControl getVariable ["categoryName", "none"];
private _categoryName = _parentControl getVariable ["categoryConfigName", "none"];


private _catPlusMinusButtons = _ctrlChosenInThisCat getVariable ["catPlusMinusButtons", []];
private _catButtons = _ctrlChosenInThisCat getVariable ["catButtons", []];

// diag_log format ["_data in changeValue %1", _data];

Expand All @@ -64,61 +64,59 @@ private _enableDisableButtons = {
_ctrlSingleCount ctrlSetBackgroundColor [0,0,0,0.8];
_ctrlSingleCount ctrlSetStructuredText parseText ("<t size='0.7' align='center' shadow='0' color='#999999'>" + ("max " + str _stock) + "</t>");

// disable all buttons of cat if necessary and exit
if (_catValue >= _valueMaxInThisCat) exitWith {
{
_x params ["_btnPlus", "_btnMinus"];
private _catMaxed = _catValue >= _valueMaxInThisCat;

{
_x params ["_ctrlItemCount", "_btnPlus", "_btnMinus"];

// initially enable all, then look for conditions
_btnMinus ctrlEnable true;
_btnPlus ctrlEnable true;

// actual values for items of cat
private _itemValue = _ctrlItemCount getVariable ["value", 0];
private _minItemValue = _ctrlItemCount getVariable ["minValue", 0];
private _maxItemValue = _ctrlItemCount getVariable ["maxValue", 0];

if (_catMaxed) then {
_btnPlus ctrlEnable false;
};

// max item value
if (_itemValue == _maxItemValue) then {
_btnPlus ctrlEnable false;
_btnMinus ctrlEnable true;
} forEach _catPlusMinusButtons;
_ctrlSingleCount ctrlSetBackgroundColor [0.4,0.66,0.4,1];
_ctrlSingleCount ctrlSetStructuredText parseText ("<t size='0.7' align='center' shadow='0' color='#000000'>" + ("max " + str _stock) + "</t>");
};

// just do disable again on individual basis when max item value is reached
if (_itemValue >= _stock) then {
_btnPlus ctrlEnable false;
_ctrlSingleCount ctrlSetBackgroundColor [0.4,0.66,0.4,1];
_ctrlSingleCount ctrlSetStructuredText parseText ("<t size='0.7' align='center' shadow='0' color='#000000'>" + ("max " + str _stock) + "</t>");
};

_ctrlChosenInThisCat ctrlSetStructuredText parseText (
_catFormatting + str _catValue + "/" + str _maxValue + "</t>"
);
_ctrlChosenInThisCat ctrlCommit 0;
// minitemvalue is zero (or above if vehicle bought in previous session)
if (_itemValue <= _minItemValue) then {
_btnMinus ctrlEnable false;
} else {
_btnMinus ctrlEnable true;
};
true
};

// enable all, if cat max is not reached
{
_x params ["_btnPlus", "_btnMinus"];
_btnPlus ctrlEnable true;
} forEach _catPlusMinusButtons;

// just do disable again on individual basis when max item value is reached
if (_itemValue == _maxItemValue || _itemValue >= _stock) exitWith {
_btnPlus ctrlEnable false;
_ctrlSingleCount ctrlSetBackgroundColor [0.4,0.66,0.4,1];
_ctrlSingleCount ctrlSetStructuredText parseText ("<t size='0.7' align='center' shadow='0' color='#000000'>" + ("max " + str _stock) + "</t>");
false
};

if (_itemValue <= _minItemValue) exitWith {
_btnMinus ctrlEnable false;
false
};

_btnMinus ctrlEnable true;
_btnPlus ctrlEnable true;
false
} forEach _catButtons;

_catMaxed
};

// needs to be before enabledisablebuttons
_ctrlChosenInThisCat setVariable ["value", _catValue];
_parentControl setVariable ["value", _itemValue];

private _catMaxed = [_itemValue, _maxItemValue, _catValue, _stock, _btnPlus, _btnMinus] call _enableDisableButtons;

if (_catMaxed) then {
_catFormatting = _catFormattingMaxed
};

_ctrlChosenInThisCat setVariable ["value", _catValue];
_parentControl setVariable ["value", _itemValue];

[_baseConfigName, _categoryName, _catValue] call BC_buymenu_fnc_saveCatGlobalCache;

// set cargo and crew count
Expand Down
10 changes: 6 additions & 4 deletions BC_buymenu/functions/fn_createGUI.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ for "_i" from 0 to (count _categoriesExtracted - 1) do {
_ctrlItemCount setVariable ["connectedButtons", [_btnPlus, _btnMinus]];

// parent cat control stores plus and minus buttons to disable/enable
private _plusMinusButtons = _ctrlChosenInThisCat getVariable ["catPlusMinusButtons", []];
_plusMinusButtons pushBack [_btnPlus, _btnMinus];
_ctrlChosenInThisCat setVariable ["catPlusMinusButtons", _plusMinusButtons];
private _plusMinusButtons = _ctrlChosenInThisCat getVariable ["catButtons", []];
_plusMinusButtons pushBack [_ctrlItemCount, _btnPlus, _btnMinus];
_ctrlChosenInThisCat setVariable ["catButtons", _plusMinusButtons];
_ctrlChosenInThisCat ctrlCommit 0;

};
Expand Down Expand Up @@ -462,7 +462,9 @@ if (player getVariable ["BC_potentToBuy", false]) then {
_rowHeight * 37.25 - (ctrlTextHeight _buttonText)/2 + safezoneY,
_screenWidth - _columnWidth * 2,
ctrlTextHeight _buttonText
]; _buttonText ctrlCommit 0;
];
_buttonText ctrlEnable false;
_buttonText ctrlCommit 0;
};


Expand Down
9 changes: 8 additions & 1 deletion BC_objectives/functions/common/fn_init.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ if (isServer) then {
};

if (hasInterface) then {
call BC_objectives_fnc_endConditionListener;
[{
!isNil "TRANSMISSION_COMPLETE" &&
!isNil "BLUFOR_CAPTURED" &&
!isNil "BLUFOR_ELIMINATED" &&
!isNil "OPFOR_ELIMINATED"
},{
call BC_objectives_fnc_endConditionListener;
}, []] call CBA_fnc_waitUntilAndExecute;
};


Expand Down
1 change: 1 addition & 0 deletions BC_setup/cfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class BC_setup {
class initialSpawnClient;
class isOnWater;
class openSpawnDialog;
class spectatorDraw3D;
class streamingSpectator;
class teleportPlayer;
class TFARsettings { preInit = 1; };
Expand Down
40 changes: 40 additions & 0 deletions BC_setup/functions/client/fn_spectatorDraw3D.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
params ["_canHearSpectators"];

// as we dont have any events we force spectator false here in a cheap local loop
[{
params ["_args", "_handle"];
_args params ["_canHearSpectators"];

if (!_canHearSpectators) then {
player setVariable ["TFAR_forceSpectator", false];
};

if (!visibleMap) then {

private _truck = missionNamespace getVariable ["GRAD_tracking_radioVehObj", objNull];
private _terminal = missionNamespace getVariable ["GRAD_tracking_terminalObj", objNull];
private _colorTruck = [1,1,1,1];
private _colorTerminal = [1,1,1,1];

if ([_truck] call GRAD_tracking_fnc_radioVehIsSending) then {
_colorTruck = [1,0.2,0.2,1];
};

if (call GRAD_tracking_fnc_terminalIsSending) then {
_colorTerminal = [0.2,0.2,1,1];
};

private _ticksRatio = GRAD_TICKS_DONE / GRAD_TICKS_NEEDED;
private _string_2 = " | Done: " + str GRAD_INTERVALS_DONE + "/" + str GRAD_INTERVALS_NEEDED;
private _string = " " + (str (round(_ticksRatio * 100))) + " " + localize "str_GRAD_transmissionTime_2" + _string_2;



drawIcon3D [getText (configFile >> "CfgVehicles" >> (typeOf _truck) >> "icon"), _colorTruck, getPos _truck, 1, 1, 0, _string, 2, 0.03, "RobotoCondensed"];

if (GRAD_TERMINAL) then {
private _strength = (str GRAD_TERMINAL_DISTANCE + " % strength");
drawIcon3D [getText (configFile >> "CfgVehicles" >> (typeOf _terminal) >> "icon"), _colorTerminal, [0,0,0], 1, 1, 0, _strength, 2, 0.03, "RobotoCondensed"];
};
};
}, 0, [_canHearSpectators]] call CBA_fnc_addPerFrameHandler;
56 changes: 1 addition & 55 deletions BC_setup/functions/client/fn_streamingSpectator.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -29,61 +29,7 @@ if (hasInterface) then {
};

// as we dont have any events we force spectator false here in a cheap local loop
[{
player setVariable ["TFAR_forceSpectator", false];

if (["HasCustomIcon",["truckIcon"]] call BIS_fnc_EGSpectator) then {
["RemoveCustomIcon",["truckIcon"]] call BIS_fnc_EGSpectator;
};

if (["HasCustomIcon",["terminalIcon"]] call BIS_fnc_EGSpectator) then {
["RemoveCustomIcon",["terminalIcon"]] call BIS_fnc_EGSpectator;
};

private _truck = missionNamespace getVariable ["GRAD_tracking_radioVehObj", objNull];
private _terminal = missionNamespace getVariable ["GRAD_tracking_terminalObj", objNull];
private _colorTruck = [1,1,1,1];
private _colorTerminal = [1,1,1,1];

if ([_truck] call GRAD_tracking_fnc_radioVehIsSending) then {
_colorTruck = [1,0.2,0.2,1];
};

if (call GRAD_tracking_fnc_terminalIsSending) then {
_colorTerminal = [0.2,0.2,1,1];
};

private _ticksRatio = GRAD_TICKS_DONE / GRAD_TICKS_NEEDED;
private _string_2 = " | Done: " + str GRAD_INTERVALS_DONE + "/" + str GRAD_INTERVALS_NEEDED;
private _string = " " + (str (round(_ticksRatio * 100))) + " " + localize "str_GRAD_transmissionTime_2" + _string_2;


[
"AddCustomIcon",
[
"truckIcon",
_truck,
[getText (configFile >> "CfgVehicles" >> (typeOf _truck) >> "icon"), _colorTruck, getPos _truck, 1, 1, 0, _string, 2, 0.03, "RobotoCondensed"],
[false, [1,1,1,0.5]],
{true}
]
] call BIS_fnc_EGSpectator;

if (!isNull _terminal) then {
private _strength = (str GRAD_TERMINAL_DISTANCE + " % strength");
[
"AddCustomIcon",
[
"terminalIcon",
_terminal,
[getText (configFile >> "CfgVehicles" >> (typeOf _terminal) >> "icon"), _colorTerminal, [0,0,0], 1, 1, 0, _strength, 2, 0.03, "RobotoCondensed"],
[false, [1,1,1,0.5]],
{true}
]
] call BIS_fnc_EGSpectator;
};

}, 1, []] call CBA_fnc_addPerFrameHandler;
[false] call BC_setup_fnc_spectatorDraw3D;
};
};

Expand Down
6 changes: 3 additions & 3 deletions mission.sqm
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class EditorData
class Camera
{
pos[]={1654.0718,27.026608,5580.4976};
dir[]={0.46733555,-0.22718981,0.85453922};
up[]={0.10908268,0.97380704,0.19946253};
aside[]={0.87746614,-5.3457916e-007,-0.47987655};
dir[]={0.63615161,-0.37405545,0.67501712};
up[]={0.25662869,0.92734838,0.27230805};
aside[]={0.72782856,-1.7648563e-007,-0.68592554};
};
};
binarizationWanted=0;
Expand Down
1 change: 1 addition & 0 deletions onPlayerKilled.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ if (!(_killer isEqualTo player)) then {
};

[true] call ace_spectator_fnc_setSpectator;
[true] call BC_setup_fnc_spectatorDraw3D;

0 comments on commit a2179d6

Please sign in to comment.