From 7337573255223253520231fe40ebb6e61164ebfa Mon Sep 17 00:00:00 2001 From: Filip Maciejewski Date: Sun, 9 Sep 2018 15:16:27 +0200 Subject: [PATCH 1/2] Fix invisible build display close button --- .../modules/02_build/ui/KPLIB_buildDisplay.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Missionframework/modules/02_build/ui/KPLIB_buildDisplay.hpp b/Missionframework/modules/02_build/ui/KPLIB_buildDisplay.hpp index 6e6bbefaa..ab870da95 100644 --- a/Missionframework/modules/02_build/ui/KPLIB_buildDisplay.hpp +++ b/Missionframework/modules/02_build/ui/KPLIB_buildDisplay.hpp @@ -34,11 +34,6 @@ class KPLIB_build { class Controls { - class KPLIB_DialogCross: KP_DialogCrossC { - action = "call KPLIB_fnc_build_camClose;"; - x = safeZoneX + safeZoneW * (KP_X_VAL_C + KP_WIDTH_BUILD - 0.02); - }; - class KPLIB_ModeUnits: KP_ActivePicture { text = "\a3\Ui_F_Curator\Data\Displays\RscDisplayCurator\modeUnits_ca.paa"; idc = KPLIB_IDC_BUILD_TAB_INFANTRY; @@ -117,5 +112,10 @@ class KPLIB_build { onButtonClick = "['build', _this] call KPLIB_fnc_build_displayScript"; }; + class KPLIB_DialogCross: KP_DialogCrossC { + action = "call KPLIB_fnc_build_camClose;"; + x = safeZoneX + safeZoneW * (KP_X_VAL_C + KP_WIDTH_BUILD - 0.02); + }; + }; }; From 824aba04760894edd3a364023588214c30a7b659 Mon Sep 17 00:00:00 2001 From: Filip Maciejewski Date: Sun, 9 Sep 2018 22:07:59 +0200 Subject: [PATCH 2/2] Refactor build camera --- .../02_build/fnc/fn_build_camAreaLimiter.sqf | 53 ++++++ .../02_build/fnc/fn_build_camClose.sqf | 27 --- ...ild_camOpen.sqf => fn_build_camCreate.sqf} | 20 +-- .../fnc/fn_build_camera_ticker_start.sqf | 56 ------ .../fnc/fn_build_camera_ticker_stop.sqf | 24 --- .../02_build/fnc/fn_build_displayLoad.sqf | 107 ++++++++++++ .../fnc/fn_build_displayPlaceObject.sqf | 44 +++++ .../02_build/fnc/fn_build_displayScript.sqf | 160 ------------------ .../02_build/fnc/fn_build_displaySetMode.sqf | 54 ++++++ .../02_build/fnc/fn_build_displayTabClick.sqf | 44 +++++ .../02_build/fnc/fn_build_displayUnload.sqf | 22 +++ .../modules/02_build/fnc/fn_build_fobArea.sqf | 60 ------- .../02_build/fnc/fn_build_handleMouse.sqf | 62 +++++++ .../02_build/fnc/fn_build_initModule.sqf | 4 +- .../02_build/fnc/fn_build_markArea.sqf | 44 +++++ .../fnc/fn_build_setupPlayerActions.sqf | 29 +--- .../modules/02_build/fnc/fn_build_start.sqf | 58 +++++++ .../modules/02_build/fnc/fn_build_stop.sqf | 28 +++ .../modules/02_build/functions.hpp | 32 +++- .../02_build/ui/KPLIB_buildDisplay.hpp | 19 ++- 20 files changed, 575 insertions(+), 372 deletions(-) create mode 100644 Missionframework/modules/02_build/fnc/fn_build_camAreaLimiter.sqf delete mode 100644 Missionframework/modules/02_build/fnc/fn_build_camClose.sqf rename Missionframework/modules/02_build/fnc/{fn_build_camOpen.sqf => fn_build_camCreate.sqf} (71%) delete mode 100644 Missionframework/modules/02_build/fnc/fn_build_camera_ticker_start.sqf delete mode 100644 Missionframework/modules/02_build/fnc/fn_build_camera_ticker_stop.sqf create mode 100644 Missionframework/modules/02_build/fnc/fn_build_displayLoad.sqf create mode 100644 Missionframework/modules/02_build/fnc/fn_build_displayPlaceObject.sqf delete mode 100644 Missionframework/modules/02_build/fnc/fn_build_displayScript.sqf create mode 100644 Missionframework/modules/02_build/fnc/fn_build_displaySetMode.sqf create mode 100644 Missionframework/modules/02_build/fnc/fn_build_displayTabClick.sqf create mode 100644 Missionframework/modules/02_build/fnc/fn_build_displayUnload.sqf delete mode 100644 Missionframework/modules/02_build/fnc/fn_build_fobArea.sqf create mode 100644 Missionframework/modules/02_build/fnc/fn_build_handleMouse.sqf create mode 100644 Missionframework/modules/02_build/fnc/fn_build_markArea.sqf create mode 100644 Missionframework/modules/02_build/fnc/fn_build_start.sqf create mode 100644 Missionframework/modules/02_build/fnc/fn_build_stop.sqf diff --git a/Missionframework/modules/02_build/fnc/fn_build_camAreaLimiter.sqf b/Missionframework/modules/02_build/fnc/fn_build_camAreaLimiter.sqf new file mode 100644 index 000000000..0ec8e4bf6 --- /dev/null +++ b/Missionframework/modules/02_build/fnc/fn_build_camAreaLimiter.sqf @@ -0,0 +1,53 @@ +/* + KPLIB_fnc_build_camera_ticker_start + + File: fn_build_camera_ticker_start.sqf + Author: KP Liberation Dev Team - https://github.com/KillahPotatoes + Date: 2018-07-01 + Last Update: 2018-09-09 + License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html + + Description: + Build camera per frame ticker, limits camera area + + Parameter(s): + NONE + + Returns: + NUMBER - PFH Handle +*/ +params [ + ["_position", nil, [[]]], + ["_radius", nil, [0]], + ["_camera", nil, [objNull]] +]; + +private _handle = [{ + params ["_args", "_handle"]; + _args params ["_position", "_radius","_camera"]; + + if(_camera isEqualTo objNull) exitWith { + systemChat "Camera does not exist, stopping area limiter."; + _handle call CBA_fnc_removePerFrameHandler; + }; + + private _currentCamPos = (getPos _camera); + + // Check if camera is in FOB area + private _inArea = _currentCamPos inArea [_position, _radius + 5, _radius + 5, 0, false]; + // If not force it back + if (!_inArea) then { + // Get the direction towards the center + private _dir = _currentCamPos getDir _position; + // The more outside the area the faster the camera will be pulled back in + private _step = ((_currentCamPos distance2D _position) - _radius - 5) / 10; + // Get new position + private _newPos = (_camera getPos [_step, _dir]); + _newPos set [2, _currentCamPos select 2]; // use old Z + // Move camera back towards the center + _camera setPos _newPos; + }; + +}, 0, [_position, _radius, _camera]] call CBA_fnc_addPerFrameHandler; + +_handle diff --git a/Missionframework/modules/02_build/fnc/fn_build_camClose.sqf b/Missionframework/modules/02_build/fnc/fn_build_camClose.sqf deleted file mode 100644 index b6b7036e0..000000000 --- a/Missionframework/modules/02_build/fnc/fn_build_camClose.sqf +++ /dev/null @@ -1,27 +0,0 @@ -/* - KPLIB_fnc_build_camClose - - File: fn_build_camClose.sqf - Author: KP Liberation Dev Team - https://github.com/KillahPotatoes - Date: 2018-07-01 - Last Update: 2018-08-05 - License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html - - Description: - Opens the build camera and creates build overlay - - Parameter(s): - NONE - - Returns: - BOOL -*/ - -// Close camera -camDestroy (missionNamespace getVariable ["KPLIB_build_camera", objNull]); -// Close overlay display -(uiNamespace getVariable ["KPLIB_build_display", displayNull]) closeDisplay 1; -// Stop PFH -[] call KPLIB_fnc_build_camera_ticker_stop; - -true diff --git a/Missionframework/modules/02_build/fnc/fn_build_camOpen.sqf b/Missionframework/modules/02_build/fnc/fn_build_camCreate.sqf similarity index 71% rename from Missionframework/modules/02_build/fnc/fn_build_camOpen.sqf rename to Missionframework/modules/02_build/fnc/fn_build_camCreate.sqf index daa4cec15..d7f277463 100644 --- a/Missionframework/modules/02_build/fnc/fn_build_camOpen.sqf +++ b/Missionframework/modules/02_build/fnc/fn_build_camCreate.sqf @@ -8,20 +8,21 @@ License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html Description: - Opens the build camera and creates build overlay + Creates the build camera Parameter(s): NONE Returns: - BOOL + OBJECT - Building camera */ +params [ + ["_position", nil, [[]]], + ["_radius", nil, [0]] +]; private _camera = "CamCurator" camCreate (eyePos player); -// Animate player -player playactionnow "gear"; - _camera cameraEffect ["internal", "back"]; _camera camCommand "maxPitch 89"; _camera camCommand "minPitch -89"; @@ -35,11 +36,6 @@ _camera camCommand format ["speedMax %1", 1.5]; // Enable display of GUI in camera cameraEffectEnableHUD true; -[] call KPLIB_fnc_build_camera_ticker_start; - -KPLIB_build_camera = _camera; - -private _display = (findDisplay 46) createDisplay "KPLIB_build"; -uiNamespace setVariable ["KPLIB_build_display", _display]; +[_position, _radius, _camera] call KPLIB_fnc_build_camAreaLimiter; -true +_camera diff --git a/Missionframework/modules/02_build/fnc/fn_build_camera_ticker_start.sqf b/Missionframework/modules/02_build/fnc/fn_build_camera_ticker_start.sqf deleted file mode 100644 index 10f12fd1c..000000000 --- a/Missionframework/modules/02_build/fnc/fn_build_camera_ticker_start.sqf +++ /dev/null @@ -1,56 +0,0 @@ -/* - KPLIB_fnc_build_camera_ticker_start - - File: fn_build_camera_ticker_start.sqf - Author: KP Liberation Dev Team - https://github.com/KillahPotatoes - Date: 2018-07-01 - Last Update: 2018-08-06 - License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html - - Description: - Build camera per frame ticker - - Parameter(s): - NONE - - Returns: - BOOL -*/ - -KPLIB_cam_arrow = "Sign_Arrow_Large_Blue_F" createVehicle [0,0,0]; - -// Wait for camera and create PFH -[{!isNull KPLIB_build_camera}, { - - private _fob = player getVariable "KPLIB_fob"; - private _camera = missionNamespace getVariable ["KPLIB_build_camera", objNull]; - - KPLIB_build_ticker = [{ - (_this select 0 ) params ["_fobPos", "_camera"]; - - private _currentCamPos = (getPos _camera); - - // Check if camera is in FOB area - private _inArea = _currentCamPos inArea [_fobPos, KPLIB_range_fob + 5, KPLIB_range_fob + 5, 0, false]; - // If not force it back - if (!_inArea) then { - // Get the direction towards the center of FOB - private _dir = _currentCamPos getDir _fobPos; - // The more outside the area the faster the camera will be pulled back in - private _step = ((_currentCamPos distance2D _fobPos) - KPLIB_range_fob - 5) / 10; - // Get new position - private _newPos = (_camera getPos [_step, _dir]); - _newPos set [2, _currentCamPos select 2]; // use old Z - // Move camera back towards the center - _camera setPos _newPos; - }; - - // Update "cursor" position - private _pos = screenToWorld [0.5, 0.5]; - KPLIB_cam_arrow setPosASL (AGLToASL _pos); - - }, 0, [getMarkerPos _fob, _camera]] call CBA_fnc_addPerFrameHandler; - -}] call CBA_fnc_waitUntilAndExecute; - -true diff --git a/Missionframework/modules/02_build/fnc/fn_build_camera_ticker_stop.sqf b/Missionframework/modules/02_build/fnc/fn_build_camera_ticker_stop.sqf deleted file mode 100644 index 4f7ad3589..000000000 --- a/Missionframework/modules/02_build/fnc/fn_build_camera_ticker_stop.sqf +++ /dev/null @@ -1,24 +0,0 @@ -/* - KPLIB_fnc_build_camera_ticker_stop - - File: fn_build_camera_ticker_stop.sqf - Author: KP Liberation Dev Team - https://github.com/KillahPotatoes - Date: 2018-07-01 - Last Update: 2018-08-06 - License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html - - Description: - Stops build camera per frame ticker - - Parameter(s): - NONE - - Returns: - BOOL -*/ - -(missionNamespace getVariable ["KPLIB_build_ticker", -1]) call CBA_fnc_removePerFrameHandler; - -deleteVehicle (missionNamespace getVariable ["KPLIB_cam_arrow", objNull]); - -true diff --git a/Missionframework/modules/02_build/fnc/fn_build_displayLoad.sqf b/Missionframework/modules/02_build/fnc/fn_build_displayLoad.sqf new file mode 100644 index 000000000..852dd8284 --- /dev/null +++ b/Missionframework/modules/02_build/fnc/fn_build_displayLoad.sqf @@ -0,0 +1,107 @@ +#include "..\ui\defines.hpp" +/* + KPLIB_fnc_build_displayLoad + + File: fn_build_displayLoad.sqf + Author: KP Liberation Dev Team - https://github.com/KillahPotatoes + Date: 2018-09-09 + Last Update: 2018-09-09 + License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html + + Description: + Handle build display load + + Parameter(s): + 0: DISPLAY - Build display + + Returns: + NOTHING +*/ +params [["_display", nil, [displayNull]]]; + +systemChat "onLoad"; + +// Add ESC Handler +_display displayAddEventHandler ["keyDown", { + params ["_display","_dik","_shift","_ctrl","_alt"]; + if (_dik == 1) exitWith { + // [] call KPLIB_fnc_build_stop; + // Open debug ESC menu (for debugging) + [] spawn { + private _interruptDisplay = (findDisplay 46) createDisplay "RscDisplayInterrupt"; + waitUntil {_interruptDisplay isEqualTo displayNull}; + (findDisplay 46) createDisplay "KPLIB_build"; + }; + true + }; + private _logic = KPLIB_buildLogic; + _logic setVariable ["shiftKey", _shift]; + _logic setVariable ["ctrlKey", _ctrl]; + + systemChat format["keyDown, ctrl: %1, shift: %2", [_ctrl, _shift]]; +}]; + +_display displayAddEventHandler ["keyUp", { + params ["_display","_dik","_shift","_ctrl","_alt"]; + + private _logic = KPLIB_buildLogic; + _logic setVariable ["shiftKey", _shift]; + _logic setVariable ["ctrlKey", _ctrl]; + + systemChat format["keyUp, ctrl: %1, shift: %2", [_ctrl, _shift]]; +}]; + +// Add Item selection handler +private _itemsList = _display displayCtrl KPLIB_IDC_BUILD_ITEM_LIST; +_itemsList ctrlAddEventHandler ["LBSelChanged", { + params ["_control", "_selectedIndex"]; + + private _logic = KPLIB_buildLogic; + private _mode = _logic getVariable "buildMode"; + + if(_selectedIndex == -1) exitWith { + _logic setVariable ["buildItem", []]; + }; + + private _buildList = KPLIB_preset_buildLists select _mode; + private _selectedItem = _buildList select _selectedIndex; + + systemChat format["buildItem: %1", _selectedItem]; + _logic setVariable ["buildItem", _selectedItem]; +}]; + +// Add build confirmation handler +private _confirmButton = _display displayCtrl KPLIB_IDC_BUILD_CONFIRM; +_confirmButton ctrlAddEventHandler ["buttonClick", { + private _logic = KPLIB_buildLogic; + + // TODO implement build queue handling (resource check etc.) + systemChat "buildConfirm: Resource check not implemented yet!"; + { + private _dirAndUp = [vectorDir _x, vectorUp _x]; + private _pos = getPos _x; + private _class = typeOf _x; + + private _obj = [_class, _pos, 0, true] remoteExecCall ["KPLIB_fnc_common_spawnVehicle", 2]; + _obj setVectorDirAndUp _dirAndUp; + + } forEach (_logic getVariable "buildQueue"); +}]; + +// Add tab change handler +{ + _ctrl = _display displayCtrl _x; + _ctrl ctrlAddEventHandler ["buttonClick", { + _this call KPLIB_fnc_build_displayTabClick; + }]; +} forEach KPLIB_BUILD_TABS_IDCS_ARRAY; + +// Hide vignette, show hud +private _vignette = _display displayCtrl 1202; +_vignette ctrlShow false; +showHUD true; + +private _logic = KPLIB_buildLogic; +_logic setVariable ["display", _display]; +(_logic getVariable ["buildMode", 0]) call KPLIB_fnc_build_displaySetMode; +setMousePosition (_logic getVariable "mousePos"); diff --git a/Missionframework/modules/02_build/fnc/fn_build_displayPlaceObject.sqf b/Missionframework/modules/02_build/fnc/fn_build_displayPlaceObject.sqf new file mode 100644 index 000000000..f2bfb95a6 --- /dev/null +++ b/Missionframework/modules/02_build/fnc/fn_build_displayPlaceObject.sqf @@ -0,0 +1,44 @@ +/* + KPLIB_fnc_build_displayPlaceObject + + File: fn_build_displayPlaceObject.sqf + Author: KP Liberation Dev Team - https://github.com/KillahPotatoes + Date: 2018-09-09 + Last Update: 2018-09-09 + License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html + + Description: + Places object into build queue + + Parameter(s): + 0: STRING - Classname of object to place + 1: NUMBER - Supply price of placed object + 2: NUMBER - Ammo price of placed object + 3: NUMBER - Fuel price of placed object + + Returns: + NOTHING +*/ +params [ + ["_className", "", [""]], + ["_priceSupplies", nil, [0]], + ["_priceAmmo", nil, [0]], + ["_priceFuel", nil, [0]] +]; + +systemChat format["placeObject: %1", _this]; + +if !(_className isEqualTo "") then { + private _logic = KPLIB_buildLogic; + private _pos = screenToWorld (_logic getVariable "mousePos"); + + private _obj = _className createVehicleLocal _pos; + _obj enableSimulation false; + + (_logic getVariable "buildQueue") pushBack _obj; + + if !(_logic getVariable "ctrlKey") then { + _logic setVariable ["buildItem", []]; + } + +}; diff --git a/Missionframework/modules/02_build/fnc/fn_build_displayScript.sqf b/Missionframework/modules/02_build/fnc/fn_build_displayScript.sqf deleted file mode 100644 index 2cf16c551..000000000 --- a/Missionframework/modules/02_build/fnc/fn_build_displayScript.sqf +++ /dev/null @@ -1,160 +0,0 @@ -#include "..\ui\defines.hpp" -/* - KPLIB_fnc_build_displayScript - - File: fn_build_displayScript.sqf - Author: KP Liberation Dev Team - https://github.com/KillahPotatoes - Date: 2018-07-01 - Last Update: 2018-08-05 - License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html - - Description: - This function handles whole build display logic - - Parameter(s): - 0: STRING - Action identifier, used to detect what action is required be handled by script - 1: ARRAY - Additional parameters of action - - Returns: - NOTHING -*/ - -params [ - ["_mode", nil, [""]], - ["_parameters", nil, [[]]] -]; - -switch _mode do { - case "onLoad": { - diag_log "onload"; - _parameters params [["_display", nil, [displayNull]]]; - - private _vignette = _display displayCtrl 1202; - _vignette ctrlShow false; - - showHUD true; - - // ESC closes whole camera - _display displayAddEventHandler ["keyDown", { - if (_this select 1 == 1) then { - call KPLIB_fnc_build_camClose; - }; - }]; - - // Handle item selection - private _itemsList = _display displayCtrl KPLIB_IDC_BUILD_ITEM_LIST; - _itemsList ctrlAddEventHandler ["LBSelChanged", { - params ["_control", "_selectedIndex"]; - - private _display = uiNamespace getVariable "KPLIB_build_display"; - private _mode = _display getVariable "KPLIB_buildMode"; - - if(_selectedIndex == -1) exitWith { - _display setVariable ["KPLIB_buildItem", nil]; - }; - - private _buildList = KPLIB_preset_buildLists select _mode; - private _selectedItem = _buildList select _selectedIndex; - - _display setVariable ["KPLIB_buildItem", _selectedItem]; - }]; - - // Handle build confirmation - private _confirmButton = _display displayCtrl KPLIB_IDC_BUILD_CONFIRM; - _confirmButton ctrlAddEventHandler ["buttonClick", { - private _display = uiNamespace getVariable "KPLIB_build_display"; - private _buildItem = _display getVariable ["KPLIB_buildItem", nil]; - - if(!isNil "_buildItem") then { - [_buildItem select 0, getPosATL KPLIB_cam_arrow] call KPLIB_fnc_common_spawnVehicle; - }; - }]; - - // Add tab change handler - { - _ctrl = _display displayCtrl _x; - _ctrl ctrlAddEventHandler ["buttonClick", { - ["tabChanged", _this] call KPLIB_fnc_build_displayScript - }]; - } forEach KPLIB_BUILD_TABS_IDCS_ARRAY; - - // Initialize with infantry tab selected - ["tabChanged", [_display displayCtrl KPLIB_IDC_BUILD_TAB_INFANTRY]] call KPLIB_fnc_build_displayScript; - - // Create FOB range indicators - ["init", player getVariable ["KPLIB_fob", ""]] call KPLIB_fnc_build_fobArea; - }; - - case "onUnload": { - [] call KPLIB_fnc_build_camClose; - // Remove fob range indicators - ["remove"] call KPLIB_fnc_build_fobArea; - }; - - case "tabChanged": { - _parameters params [["_selectedControl", nil, [controlNull]]]; - - private _display = ctrlParent _selectedControl; - - _selectedMode = 0; - { - _ctrl = _display displayctrl _x; - _ctrl ctrlsettextcolor [1,1,1,0.5]; - _color = [1,1,1,0.5]; - // Selected tab will be scaled up and highlighted - if (_ctrl == _selectedControl) then { - _color = [1,1,1,1]; - _selectedMode = _foreachindex; - }; - _ctrl ctrlSetTextColor _color; - } foreach KPLIB_BUILD_TABS_IDCS_ARRAY; - - // If clicked mode is different than current mode fire change event - if(_display getVariable ["KPLIB_buildMode", -1] != _selectedMode) then { - _display setVariable ["KPLIB_buildMode", _selectedMode]; - ["modeChanged", [_display, _selectedMode]] call KPLIB_fnc_build_displayScript; - }; - }; - - case "modeChanged": { - _parameters params [ - ["_display", nil, [displayNull]], - ["_selectedMode", 0, [0]] - ]; - // CfgVehicles config for shorter access - private _cfg = configFile >> "CfgVehicles"; - private _listElements = KPLIB_preset_buildLists select _selectedMode; - - private _listBox = _display displayCtrl KPLIB_IDC_BUILD_ITEM_LIST; - _listBox lbSetCurSel -1; // Unselect current row as it sticks between clearing - lnbClear _listBox; - { - // All but squad build mode - if (_selectedMode != 7) then { - _x params ["_className", "_priceSupp", "_priceAmmo", "_priceFuel"]; - private _name = getText (_cfg >> _className >> "displayName"); - - _listBox lnbAddRow [_name, str _priceSupp, str _priceAmmo, str _priceFuel]; - - _icon = getText ( _cfg >> _className >> "icon"); - if(isText (configFile >> "CfgVehicleIcons" >> _icon)) then { - _icon = (getText (configFile >> "CfgVehicleIcons" >> _icon)); - }; - _listBox lnbSetPicture [[((lnbSize _listBox) select 0) - 1, 0], _icon]; - - } else { - // TODO handle squad build mode - systemChat "Not implemented yet!"; - }; - - } foreach _listElements; - }; - - case "buildConfirm": { - - }; - - default { - diag_log format ["[KP LIBERATION] Inorrect mode passed to build display script: %1", _this]; - }; -} diff --git a/Missionframework/modules/02_build/fnc/fn_build_displaySetMode.sqf b/Missionframework/modules/02_build/fnc/fn_build_displaySetMode.sqf new file mode 100644 index 000000000..1ef09d214 --- /dev/null +++ b/Missionframework/modules/02_build/fnc/fn_build_displaySetMode.sqf @@ -0,0 +1,54 @@ +#include "..\ui\defines.hpp" +/* + KPLIB_fnc_build_displaySetMode + + File: fn_build_displaySetMode.sqf + Author: KP Liberation Dev Team - https://github.com/KillahPotatoes + Date: 2018-09-09 + Last Update: 2018-09-09 + License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html + + Description: + Sets display build mode + + Parameter(s): + 0: NUMBER - Build mode index + + Returns: + NOTHING +*/ +params [["_mode", 0, [0]]]; + +systemChat format["Set mode: %1", _mode]; + +private _logic = KPLIB_buildLogic; + +// CfgVehicles config for shorter access +private _cfg = configFile >> "CfgVehicles"; +private _listElements = KPLIB_preset_buildLists select _mode; + +private _listBox = (_logic getVariable "display") displayCtrl KPLIB_IDC_BUILD_ITEM_LIST; +_listBox lbSetCurSel -1; // Unselect current row as it sticks between clearing +lnbClear _listBox; +{ + // All but squad build mode + if (_mode != 7) then { + _x params ["_className", "_priceSupp", "_priceAmmo", "_priceFuel"]; + private _name = getText (_cfg >> _className >> "displayName"); + + _listBox lnbAddRow [_name, str _priceSupp, str _priceAmmo, str _priceFuel]; + + _icon = getText ( _cfg >> _className >> "icon"); + if(isText (configFile >> "CfgVehicleIcons" >> _icon)) then { + _icon = (getText (configFile >> "CfgVehicleIcons" >> _icon)); + }; + _listBox lnbSetPicture [[((lnbSize _listBox) select 0) - 1, 0], _icon]; + + } else { + // TODO handle squad build mode + if (true) exitWith { + systemChat "Not implemented yet!"; + }; + }; + +} foreach _listElements; diff --git a/Missionframework/modules/02_build/fnc/fn_build_displayTabClick.sqf b/Missionframework/modules/02_build/fnc/fn_build_displayTabClick.sqf new file mode 100644 index 000000000..1b9462ca7 --- /dev/null +++ b/Missionframework/modules/02_build/fnc/fn_build_displayTabClick.sqf @@ -0,0 +1,44 @@ +#include "..\ui\defines.hpp" +/* + KPLIB_fnc_build_displayTabClick + + File: fn_build_displayTabClick.sqf + Author: KP Liberation Dev Team - https://github.com/KillahPotatoes + Date: 2018-09-09 + Last Update: 2018-09-09 + License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html + + Description: + Handle tab control click + + Parameter(s): + 0: CONTROL - Clicked tab control + + Returns: + NOTHING +*/ +params [["_tabCtrl", nil, [controlNull]]]; + +systemChat format["Tab click: %1", _tabCtrl]; + +private _logic = KPLIB_buildLogic; +private _display = ctrlParent _tabCtrl; + +_selectedMode = 0; +{ + private _ctrl = _display displayCtrl _x; + _ctrl ctrlSetTextColor [1,1,1,0.5]; + _color = [1,1,1,0.5]; + // Selected tab will be scaled up and highlighted + if (_ctrl isEqualTo _tabCtrl) then { + _color = [1,1,1,1]; + _selectedMode = _foreachindex; + }; + _ctrl ctrlSetTextColor _color; +} foreach KPLIB_BUILD_TABS_IDCS_ARRAY; + +// If clicked mode is different than current mode fire change event +if(_logic getVariable ["buildMode", -1] != _selectedMode) then { + _logic setVariable ["buildMode", _selectedMode]; + (_logic getVariable "buildMode") call KPLIB_fnc_build_displaySetMode; +}; diff --git a/Missionframework/modules/02_build/fnc/fn_build_displayUnload.sqf b/Missionframework/modules/02_build/fnc/fn_build_displayUnload.sqf new file mode 100644 index 000000000..abb4e976e --- /dev/null +++ b/Missionframework/modules/02_build/fnc/fn_build_displayUnload.sqf @@ -0,0 +1,22 @@ +#include "..\ui\defines.hpp" +/* + KPLIB_fnc_build_displayUnload + + File: fn_build_displayUnload.sqf + Author: KP Liberation Dev Team - https://github.com/KillahPotatoes + Date: 2018-09-09 + Last Update: 2018-09-09 + License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html + + Description: + Handle build display unload + + Parameter(s): + 0: DISPLAY - Build display + + Returns: + NOTHING +*/ +params [["_display", nil, [displayNull]]]; + +systemChat "onUnload"; diff --git a/Missionframework/modules/02_build/fnc/fn_build_fobArea.sqf b/Missionframework/modules/02_build/fnc/fn_build_fobArea.sqf deleted file mode 100644 index 7d433f5f8..000000000 --- a/Missionframework/modules/02_build/fnc/fn_build_fobArea.sqf +++ /dev/null @@ -1,60 +0,0 @@ -/* - KPLIB_fnc_build_fobArea - - File: fn_build_fobArea.sqf - Author: KP Liberation Dev Team - https://github.com/KillahPotatoes - Date: 2018-08-05 - Last Update: 2018-08-05 - License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html - - Description: - Creates or removes sphere indicator at FOB area - - Parameter(s): - 0: STRING - Action identifier, used to detect what action should be taken, ("init"/"remove") - 1: STRING - FOB marker name - - Returns: - NOTHING -*/ - -params [ - ["_mode", "init", [""]], - ["_fob", nil, [""]] -]; - -private _indicatorClass = "Sign_Sphere100cm_F"; - -switch toLower _mode do { - case "init": { - - // Get spheres global array - private _spheres = missionNamespace getVariable ["KPLIB_fob_indicatorSpheres", []]; - // Remove old spheres - if !(_spheres isEqualTo []) then { ["remove"] call KPLIB_fnc_build_fobArea }; - - // Get positions - private _indicatorsPositions = [getMarkerPos _fob] call KPLIB_fnc_common_getCirclePositions; - - // Create spheres - { - private _pos = _x; - - private _sphere = _indicatorClass createVehicleLocal [0, 0, 0]; - _sphere setPos [_pos select 0, _pos select 1, _pos select 2]; - - _spheres pushBack _sphere; - - } forEach _indicatorsPositions; - - KPLIB_fob_indicatorSpheres = _spheres; - }; - - case "remove": { - // Remove all spheres - { - deleteVehicle _x; - } forEach (missionNamespace getVariable ["KPLIB_fob_indicatorSpheres", []]); - KPLIB_fob_indicatorSpheres = []; - }; -}; diff --git a/Missionframework/modules/02_build/fnc/fn_build_handleMouse.sqf b/Missionframework/modules/02_build/fnc/fn_build_handleMouse.sqf new file mode 100644 index 000000000..43a98e0d0 --- /dev/null +++ b/Missionframework/modules/02_build/fnc/fn_build_handleMouse.sqf @@ -0,0 +1,62 @@ +#include "..\ui\defines.hpp" +/* + KPLIB_fnc_build_handleMouse + + File: fn_build_handleMouse.sqf + Author: KP Liberation Dev Team - https://github.com/KillahPotatoes + Date: 2018-09-09 + Last Update: 2018-09-09 + License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html + + Description: + Handle build display mouse movement events + + Parameter(s): + 0: STRING - Mouse move event + 1: ARRAY - Additional event arguments + + Returns: + NOTHING +*/ +params [ + ["_mode", nil, [""]], + ["_args", nil, [[]]] +]; + +private _logic = KPLIB_buildLogic; + +switch toLower _mode do { + case "onmousebuttondown": { + _args params ["_ctrl","_button"]; + + _logic setVariable [["mouseLeft", "mouseRight"] select _button, true]; + + systemChat format ["mouseDown: %1", _logic getVariable (["mouseLeft", "mouseRight"] select _button)]; + + // Place object if lmb + if (_button == 0) then { + (_logic getVariable "buildItem") call KPLIB_fnc_build_displayPlaceObject; + }; + }; + + case "onmousebuttonup": { + _args params ["_ctrl","_button"]; + + _logic setVariable [["mouseLeft", "mouseRight"] select _button, false]; + + systemChat format ["mouseUp: %1", _logic getVariable (["mouseLeft", "mouseRight"] select _button)]; + }; + case "onmousezchanged": { + _args params ["_ctrl","_zChange"]; + systemChat format ["zChange: %1", _zChange]; + + if (true) exitWith {true}; + }; + + case "onmousemoving": { + _args params ["_ctrl","_x","_y"]; + + _logic setVariable ["mousePos", [_x, _y]]; + }; + +} diff --git a/Missionframework/modules/02_build/fnc/fn_build_initModule.sqf b/Missionframework/modules/02_build/fnc/fn_build_initModule.sqf index af7c6696c..cab1c8610 100644 --- a/Missionframework/modules/02_build/fnc/fn_build_initModule.sqf +++ b/Missionframework/modules/02_build/fnc/fn_build_initModule.sqf @@ -19,9 +19,9 @@ if (isServer) then {diag_log format ["[KP LIBERATION] [%1] [BUILD] Module initializing...", diag_tickTime];}; -call compile preprocessFileLineNumbers "modules\02_build\globals.sqf"; +[] call compile preprocessFileLineNumbers "modules\02_build\globals.sqf"; -call KPLIB_fnc_build_setupPlayerActions; +[] call KPLIB_fnc_build_setupPlayerActions; if (isServer) then {diag_log format ["[KP LIBERATION] [%1] [BUILD] Module initialized", diag_tickTime];}; diff --git a/Missionframework/modules/02_build/fnc/fn_build_markArea.sqf b/Missionframework/modules/02_build/fnc/fn_build_markArea.sqf new file mode 100644 index 000000000..185f8abff --- /dev/null +++ b/Missionframework/modules/02_build/fnc/fn_build_markArea.sqf @@ -0,0 +1,44 @@ +/* + KPLIB_fnc_build_markArea + + File: fn_build_markArea.sqf + Author: KP Liberation Dev Team - https://github.com/KillahPotatoes + Date: 2018-08-05 + Last Update: 2018-09-09 + License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html + + Description: + Creates sphere indicators around given area (LOCALLY) + + Parameter(s): + 0: ARRAY - Center position of area to mark + 1: STRING - Radius to mark around the center position + + Returns: + ARRAY - Array with created spheres +*/ +params [ + ["_position", nil, [[]]], + ["_radius", nil, [0]] +]; + +private _indicatorClass = "Sign_Sphere100cm_F"; + +// Create spheres array +private _spheres = []; + +// Get positions +private _indicatorsPositions = [_position] call KPLIB_fnc_common_getCirclePositions; + +// Create spheres +{ + private _pos = _x select [0, 3]; + + private _sphere = _indicatorClass createVehicleLocal [0, 0, 0]; + _sphere setPos _pos; + + _spheres pushBack _sphere; + +} forEach _indicatorsPositions; + +_spheres diff --git a/Missionframework/modules/02_build/fnc/fn_build_setupPlayerActions.sqf b/Missionframework/modules/02_build/fnc/fn_build_setupPlayerActions.sqf index 390b5a8f9..4cae7eddd 100644 --- a/Missionframework/modules/02_build/fnc/fn_build_setupPlayerActions.sqf +++ b/Missionframework/modules/02_build/fnc/fn_build_setupPlayerActions.sqf @@ -19,27 +19,14 @@ // Actions avalible LOCALLY to player if(hasInterface) then { - ["KPLIB_player_fob", { - params ["_player", "_fob"]; - - private _buildActionId = _player getVariable ["KPLIB_actionId_build", nil]; - - // Remove redeploy action if player had one avalible - if (_fob isEqualTo "" || _fob isEqualTo "KPLIB_eden_startbase_marker") then { - if (!isNil "_buildActionId") then { - _player removeAction _buildActionId; - _player setVariable ["KPLIB_actionId_build", nil]; - }; - } else { - // If entered fob and had no action - if (isNil "_buildActionId") then { - // Add action to player - _buildActionId = _player addAction [localize "STR_ACTION_FOB_BUILD", {[] spawn KPLIB_fnc_build_camOpen}, nil, -802, false, true, "", "vehicle player == player", 10]; - // Save action id so it can we removed when out of FOB - _player setVariable ["KPLIB_actionId_build", _buildActionId]; - }; - }; - }] call CBA_fnc_addEventHandler + // Build action + private _buildCondition = 'vehicle player == player && !(player getVariable ["KPLIB_fob", ""] in ["", "KPLIB_eden_startbase_marker"])'; + private _buildAction = { + private _pos = getMarkerPos (player getVariable "KPLIB_fob"); + [_pos, KPLIB_range_fob] call KPLIB_fnc_build_start; + }; + _buildActionId = player addAction [localize "STR_ACTION_FOB_BUILD", _buildAction, nil, -802, false, true, "", _buildCondition, 10]; + player setVariable ["KPLIB_actionId_build", _buildActionId]; }; true diff --git a/Missionframework/modules/02_build/fnc/fn_build_start.sqf b/Missionframework/modules/02_build/fnc/fn_build_start.sqf new file mode 100644 index 000000000..abd3bff9a --- /dev/null +++ b/Missionframework/modules/02_build/fnc/fn_build_start.sqf @@ -0,0 +1,58 @@ + + +/* + KPLIB_fnc_build_start + + File: fn_build_start.sqf + Author: KP Liberation Dev Team - https://github.com/KillahPotatoes + Date: 2018-09-09 + Last Update: 2018-09-09 + License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html + + Description: + Starts KP Liberation building mode + + Parameter(s): + 0: ARRAY - Center position of build area + 1: NUMBER - Allowed build radius + + Returns: + LOCATION - Building logic object +*/ +params [ + ["_center", nil, [[]]], + ["_radius", nil, [0]] +]; + +// Animate player +player playactionnow "gear"; + +private _logic = [] call CBA_fnc_createNamespace; +KPLIB_buildLogic = _logic; + +// Initialize all variables used by logic +{ + _logic setVariable _x; +} forEach [ + // General + ["buildMode", nil], + ["buildItem", []], + ["buildQueue", []], + ["center", _center], + ["radius", _radius], + ["cursorPos", []], + ["areaIndicators", [_center, _radius] call KPLIB_fnc_build_markArea], + ["camera", [_center, _radius] call KPLIB_fnc_build_camCreate], + ["display", displayNull], + // Keys + ["altKey", false], + ["ctrlKey", false], + ["shiftKey", false], + ["leftMouse", false], + ["rightMouse", false], + ["mousePos", [0.5, 0.5]] +]; + +(findDisplay 46) createDisplay "KPLIB_build"; + +_logic diff --git a/Missionframework/modules/02_build/fnc/fn_build_stop.sqf b/Missionframework/modules/02_build/fnc/fn_build_stop.sqf new file mode 100644 index 000000000..9b1a7d762 --- /dev/null +++ b/Missionframework/modules/02_build/fnc/fn_build_stop.sqf @@ -0,0 +1,28 @@ +/* + KPLIB_fnc_build_stop + + File: fn_build_stop.sqf + Author: KP Liberation Dev Team - https://github.com/KillahPotatoes + Date: 2018-09-09 + Last Update: 2018-09-09 + License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html + + Description: + Stops KP Liberation building mode + + Parameter(s): + NONE + + Returns: + NOTHING +*/ + +private _logic = missionNamespace getVariable ["KPLIB_buildLogic", nil]; + +if !(isNil "_logic") then { + camDestroy (_logic getVariable ["camera", objNull]); + (_logic getVariable ["display", displayNull]) closeDisplay 0; + {deleteVehicle _X} forEach (_logic getVariable ["spheres", []]); + {deleteVehicle _X} forEach (_logic getVariable ["buildQueue", []]); + _logic call CBA_fnc_deleteNamespace; +}; diff --git a/Missionframework/modules/02_build/functions.hpp b/Missionframework/modules/02_build/functions.hpp index 8ef3b460b..d09d25165 100644 --- a/Missionframework/modules/02_build/functions.hpp +++ b/Missionframework/modules/02_build/functions.hpp @@ -14,24 +14,42 @@ class build { file = "modules\02_build\fnc"; - // Close build camera - class build_camClose {}; + // PFH limiting camera flying area + class build_camAreaLimiter {}; // Open build menu - class build_camOpen {}; + class build_camCreate {}; - class build_camera_ticker_start {}; + // Display initialization + class build_displayLoad {}; - class build_camera_ticker_stop {}; + // Place object in build queue + class build_displayPlaceObject {}; - class build_fobArea {}; + // Set display build mode (tab) + class build_displaySetMode {}; - class build_displayScript {}; + // Handle tab click + class build_displayTabClick {}; + + // Display load handler + class build_displayUnload {}; + + // Mouse movement and click handler + class build_handleMouse {}; // Module initialization class build_initModule { postInit = 1; }; + // Marks given area with circle created out of spheres + class build_markArea {}; + class build_setupPlayerActions {}; + + // Start building logic + class build_start {}; + + class build_stop {}; }; diff --git a/Missionframework/modules/02_build/ui/KPLIB_buildDisplay.hpp b/Missionframework/modules/02_build/ui/KPLIB_buildDisplay.hpp index ab870da95..81236e6ec 100644 --- a/Missionframework/modules/02_build/ui/KPLIB_buildDisplay.hpp +++ b/Missionframework/modules/02_build/ui/KPLIB_buildDisplay.hpp @@ -16,11 +16,24 @@ class KPLIB_build { idd = -1; movingEnable = 0; - onLoad = "['onLoad', _this] call KPLIB_fnc_build_displayScript"; - onUnload = "['onUnload', _this] call KPLIB_fnc_build_displayScript"; + onLoad = "call KPLIB_fnc_build_displayLoad"; + onUnload = "call KPLIB_fnc_build_displayUnload"; class controlsBackground { + class MouseHandler: RscControlsGroupNoScrollbars { + idc = 101; + x = safeZoneX; + y = safeZoneY; + w = safeZoneW; + h = safeZoneH; + onMouseButtonDown = "['onMouseButtonDown', _this] call KPLIB_fnc_build_handleMouse"; + onMouseButtonUp = "['onMouseButtonUp', _this] call KPLIB_fnc_build_handleMouse"; + onMouseZChanged = "['onMouseZChanged', _this] call KPLIB_fnc_build_handleMouse"; + onMouseMoving = "['onMouseMoving', _this] call KPLIB_fnc_build_handleMouse"; + onMouseHolding = "['onMouseHolding', _this] call KPLIB_fnc_build_handleMouse"; + }; + class KPLIB_DialogTitle: KP_DialogTitleC { text = "$STR_BUILD"; w = KP_GETWPLAIN(KP_WIDTH_BUILD,1); @@ -113,7 +126,7 @@ class KPLIB_build { }; class KPLIB_DialogCross: KP_DialogCrossC { - action = "call KPLIB_fnc_build_camClose;"; + action = "call KPLIB_fnc_build_stop"; x = safeZoneX + safeZoneW * (KP_X_VAL_C + KP_WIDTH_BUILD - 0.02); };