mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Split into functions (for future caching)
This commit is contained in:
parent
d2fdeb5e96
commit
d4225e03d2
@ -18,7 +18,7 @@ GVAR(ParsedTextCached) = [];
|
||||
addMissionEventHandler ["Draw3D", DFUNC(render)];
|
||||
|
||||
//Add Actions to Houses:
|
||||
["interactMenuOpened", {_this call FUNC(addHouseActions)}] call EFUNC(common,addEventHandler);
|
||||
["interactMenuOpened", {_this call FUNC(userActions_addHouseActions)}] call EFUNC(common,addEventHandler);
|
||||
|
||||
// This spawn is probably worth keeping, as pfh don't work natively on the briefing screen and IDK how reliable the hack we implemented for them is.
|
||||
// The thread dies as soon as the mission start, so it's not really compiting for scheduler space.
|
||||
|
@ -4,7 +4,6 @@ ADDON = false;
|
||||
|
||||
PREP(addActionToClass);
|
||||
PREP(addActionToObject);
|
||||
PREP(addHouseActions);
|
||||
PREP(compileMenu);
|
||||
PREP(compileMenuSelfAction);
|
||||
PREP(collectActiveActionTree);
|
||||
@ -26,6 +25,12 @@ PREP(renderSelector);
|
||||
PREP(setupTextColors);
|
||||
PREP(splitPath);
|
||||
|
||||
|
||||
PREP(userActions_addHouseActions);
|
||||
PREP(userActions_getHouseActions);
|
||||
|
||||
|
||||
|
||||
GVAR(keyDown) = false;
|
||||
GVAR(keyDownSelfAction) = false;
|
||||
GVAR(keyDownTime) = 0;
|
||||
|
@ -1,153 +0,0 @@
|
||||
/*
|
||||
* Author: PabstMirror
|
||||
* Scans for nearby "Static" objects (buildings) and adds the UserActions to them.
|
||||
* Called when interact_menu starts rendering (from "interact_keyDown" event)
|
||||
*
|
||||
* Arguments:
|
||||
* Interact Menu Type (0 - world, 1 - self) <NUMBER>
|
||||
*
|
||||
* Return Value:
|
||||
* Nothing
|
||||
*
|
||||
* Example:
|
||||
* [0] call ace_interact_menu_fnc_addHouseActions
|
||||
*
|
||||
* Public: Yes
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
PARAMS_1(_interactionType);
|
||||
|
||||
//Ignore self-interaction menu:
|
||||
if (_interactionType != 0) exitWith {};
|
||||
//Ignore when mounted:
|
||||
if ((vehicle ACE_player) != ACE_player) exitWith {};
|
||||
|
||||
[{
|
||||
private ["_fncStatement", "_player", "_fncCondition", "_variable", "_theHouse", "_statement", "_condition", "_configPath", "_displayName", "_displayNameDefault", "_iconImage", "_position", "_maxDistance", "_helperObject", "_actionOffset", "_memPoint", "_object", "_count", "_helperPos", "_action"];
|
||||
PARAMS_2(_args,_pfID);
|
||||
EXPLODE_4_PVT(_args,_setPosition,_addedHelpers,_housesScaned,_houseBeingScaned);
|
||||
|
||||
if (!EGVAR(interact_menu,keyDown)) then {
|
||||
{deleteVehicle _x;} forEach _addedHelpers;
|
||||
[_pfID] call CBA_fnc_removePerFrameHandler;
|
||||
} else {
|
||||
// Prevent Rare Error when ending mission with interact key down:
|
||||
if (isNull ace_player) exitWith {};
|
||||
|
||||
//If player moved >5 meters from last pos, then rescan
|
||||
if (((getPosASL ace_player) distance _setPosition) < 5) exitWith {};
|
||||
|
||||
// systemChat str _houseBeingScaned;
|
||||
|
||||
if (_houseBeingScaned isEqualTo []) then {
|
||||
_houseWasScaned = false;
|
||||
{
|
||||
_theHouse = _x;
|
||||
if (!(_theHouse in _housesScaned)) exitWith {
|
||||
_houseWasScaned = true;
|
||||
_housesScaned pushBack _x;
|
||||
if ((typeOf _theHouse) != "") then {
|
||||
_configPath = (configFile >> "CfgVehicles" >> (typeOf _theHouse));
|
||||
if (isClass (_configPath >> "UserActions")) then {
|
||||
_args set [3, [_theHouse, 0, []]];
|
||||
};
|
||||
};
|
||||
};
|
||||
// Need to scan fairly far, because houses are big. You can be 25m from center of building but right next to a door.
|
||||
} forEach nearestObjects [ace_player, ["Static"], 30];
|
||||
if (!_houseWasScaned) then {
|
||||
_args set [0, (getPosASL ace_player)];
|
||||
};
|
||||
} else {
|
||||
EXPLODE_3_PVT(_houseBeingScaned,_theHouse,_index,_houseHelpers);
|
||||
_configPath = configFile >> "CfgVehicles" >> (typeOf _theHouse) >> "UserActions";
|
||||
if (_index < ((count _configPath) - 1)) then {
|
||||
_actionPath = _configPath select _index;
|
||||
|
||||
_fncStatement = {
|
||||
PARAMS_3(_target,_player,_variable);
|
||||
EXPLODE_3_PVT(_variable,_theHouse,_statement,_condition);
|
||||
this = _theHouse; //this feels dirty
|
||||
call _statement;
|
||||
};
|
||||
_fncCondition = {
|
||||
PARAMS_3(_target,_player,_variable);
|
||||
EXPLODE_3_PVT(_variable,_theHouse,_statement,_condition);
|
||||
this = _theHouse; //this feels dirty
|
||||
call _condition;
|
||||
};
|
||||
|
||||
_displayName = getText (_actionPath >> "displayName");
|
||||
_displayNameDefault = getText (_actionPath >> "displayNameDefault");
|
||||
_position = getText (_actionPath >> "position");
|
||||
_condition = getText (_actionPath >> "condition");
|
||||
_statement = getText (_actionPath >> "statement");
|
||||
_maxDistance = getNumber (_actionPath >> "radius");
|
||||
|
||||
if (_displayName == "") then {_displayName = (configName _x);};
|
||||
if (_position == "") then {ERROR("Bad Position");};
|
||||
if (_condition == "") then {_condition = "true";};
|
||||
if (_statement == "") then {ERROR("No Statement");};
|
||||
|
||||
_statement = compile _statement;
|
||||
_condition = compile _condition;
|
||||
_maxDistance = _maxDistance + 0.1; //increase range slightly
|
||||
_iconImage = "";
|
||||
|
||||
if (_displayNameDefault != "") then {
|
||||
//something like: "<img image='\A3\Ui_f\data\IGUI\Cfg\Actions\open_door_ca.paa' size='2.5' />";
|
||||
//find the end [.paa']
|
||||
_endIndex = _displayNameDefault find ".paa'";
|
||||
if (_endIndex == -1) exitWith {};
|
||||
_startIndex = _endIndex - 1;
|
||||
_endIndex = _endIndex + 4;
|
||||
//work backwards to find the starting [']
|
||||
while {(_startIndex > 0) && {_iconImage == ""}} do {
|
||||
if ((_displayNameDefault select [_startIndex, 1]) == "'") then {
|
||||
_startIndex = _startIndex + 1;
|
||||
_iconImage = _displayNameDefault select [_startIndex, (_endIndex - _startIndex)];
|
||||
};
|
||||
_startIndex = _startIndex - 1;
|
||||
};
|
||||
};
|
||||
|
||||
//Find a helper object, if one exists on the selection position
|
||||
_helperObject = objNull;
|
||||
_actionOffset = [0,0,0];
|
||||
{
|
||||
EXPLODE_3_PVT(_x,_memPoint,_object,_count);
|
||||
if (_memPoint == _position) exitWith {
|
||||
_helperObject = _object;
|
||||
//make sure actions don't overlap (although they are usualy mutually exclusive)
|
||||
_actionOffset = [0,0,(_count * 0.05)];
|
||||
_x set [2, (_count + 1)];
|
||||
};
|
||||
} forEach _houseHelpers;
|
||||
|
||||
if (isNull _helperObject) then {
|
||||
_helperObject = "Sign_Sphere25cm_F" createVehicleLocal (getpos _theHouse);
|
||||
_houseHelpers pushBack [_position, _helperObject, 1];
|
||||
_helperPos = _theHouse modelToWorld (_theHouse selectionPosition _position);
|
||||
//ASL/ATL bullshit:
|
||||
if (surfaceIsWater _helperPos) then {
|
||||
_helperObject setPosAslw _helperPos;
|
||||
} else {
|
||||
_helperObject setPos _helperPos;
|
||||
};
|
||||
_helperObject hideObject true;
|
||||
_addedHelpers pushBack _helperObject;
|
||||
TRACE_3("Making New Helper %1",_helperObject,_helperPos,_theHouse);
|
||||
};
|
||||
|
||||
_action = [(configName _actionPath), _displayName, _iconImage, _fncStatement, _fncCondition, {}, [_theHouse, _statement, _condition], _actionOffset, _maxDistance] call EFUNC(interact_menu,createAction);
|
||||
[_helperObject, 0, [],_action] call EFUNC(interact_menu,addActionToObject);
|
||||
|
||||
_index = _index + 1;
|
||||
_args set [3, [_theHouse, _index, _houseHelpers]];
|
||||
} else {
|
||||
_args set [3, []];
|
||||
};
|
||||
};
|
||||
};
|
||||
}, 0, [((getPosASL ace_player) vectorAdd [-100,0,0]), [], [], []]] call CBA_fnc_addPerFrameHandler;
|
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Author: PabstMirror
|
||||
* Scans for nearby "Static" objects (buildings) and adds the UserActions to them.
|
||||
* Called when interact_menu starts rendering (from "interact_keyDown" event)
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Interact Menu Type (0 - world, 1 - self) <NUMBER>
|
||||
*
|
||||
* Return Value:
|
||||
* Nothing
|
||||
*
|
||||
* Example:
|
||||
* [0] call ace_interact_menu_fnc_addHouseActions
|
||||
*
|
||||
* Public: Yes
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
PARAMS_1(_interactionType);
|
||||
|
||||
//Ignore self-interaction menu:
|
||||
if (_interactionType != 0) exitWith {};
|
||||
//Ignore when mounted:
|
||||
if ((vehicle ACE_player) != ACE_player) exitWith {};
|
||||
|
||||
systemChat format ["starting %1", diag_tickTime];
|
||||
|
||||
[{
|
||||
private ["_fncStatement", "_player", "_fncCondition", "_variable", "_theHouse", "_statement", "_condition", "_configPath", "_displayName", "_displayNameDefault", "_iconImage", "_position", "_maxDistance", "_helperObject", "_actionOffset", "_memPoint", "_object", "_count", "_helperPos", "_action"];
|
||||
PARAMS_2(_args,_pfID);
|
||||
EXPLODE_4_PVT(_args,_setPosition,_addedHelpers,_housesScaned,_houseBeingScaned);
|
||||
|
||||
if (!EGVAR(interact_menu,keyDown)) then {
|
||||
{deleteVehicle _x;} forEach _addedHelpers;
|
||||
[_pfID] call CBA_fnc_removePerFrameHandler;
|
||||
} else {
|
||||
// Prevent Rare Error when ending mission with interact key down:
|
||||
if (isNull ace_player) exitWith {};
|
||||
|
||||
//If player moved >5 meters from last pos, then rescan
|
||||
if (((getPosASL ace_player) distance _setPosition) < 5) exitWith {};
|
||||
|
||||
//Make the common case fast (looking at a door):
|
||||
if ((!isNull cursorTarget) && {cursorTarget isKindOf "Static"} && {!(cursorTarget in _housesScaned)}) then {
|
||||
_houseBeingScaned = cursorTarget;
|
||||
_housesScaned pushBack _houseBeingScaned;
|
||||
};
|
||||
|
||||
if (isNull _houseBeingScaned) then {
|
||||
_houseWasScaned = false;
|
||||
_nearBuidlings = nearestObjects [ace_player, ["Static"], 30];
|
||||
{
|
||||
_theHouse = _x;
|
||||
if (!(_theHouse in _housesScaned)) exitWith {
|
||||
_houseWasScaned = true;
|
||||
_housesScaned pushBack _x;
|
||||
if ((typeOf _theHouse) != "") then {
|
||||
_configPath = (configFile >> "CfgVehicles" >> (typeOf _theHouse));
|
||||
if (isClass (_configPath >> "UserActions")) then {
|
||||
_args set [3, _theHouse];
|
||||
};
|
||||
};
|
||||
};
|
||||
// Need to scan fairly far, because houses are big. You can be 25m from center of building but right next to a door.
|
||||
} forEach _nearBuidlings;
|
||||
|
||||
//If we finished scanning everything, update position
|
||||
if (!_houseWasScaned) then {
|
||||
systemChat format ["Pos Updated (stable): %1", diag_tickTime];
|
||||
_args set [0, (getPosASL ace_player)];
|
||||
};
|
||||
} else {
|
||||
_actionSet = [(typeOf _houseBeingScaned)] call FUNC(userActions_getHouseActions);
|
||||
EXPLODE_2_PVT(_actionSet,_memPoints,_memPointsActions);
|
||||
|
||||
// systemChat format ["Add Actions for [%1] (%2)", _houseBeingScaned, (count _memPoints)];
|
||||
{
|
||||
_helperObject = "Sign_Sphere25cm_F" createVehicleLocal (getpos _houseBeingScaned);
|
||||
_addedHelpers pushBack _helperObject;
|
||||
|
||||
_helperObject setVariable [QGVAR(building), _houseBeingScaned];
|
||||
|
||||
//ASL/ATL bullshit (note: attachTo doesn't work on buildings)
|
||||
_helperPos = _houseBeingScaned modelToWorld (_houseBeingScaned selectionPosition _x);
|
||||
if (surfaceIsWater _helperPos) then {
|
||||
_helperObject setPosAslw _helperPos;
|
||||
} else {
|
||||
_helperObject setPos _helperPos;
|
||||
};
|
||||
_helperObject hideObject true;
|
||||
TRACE_3("Making New Helper",_helperObject,_x,_houseBeingScaned);
|
||||
{
|
||||
[_helperObject, 0, [], _x] call EFUNC(interact_menu,addActionToObject);
|
||||
} forEach (_memPointsActions select _forEachIndex);
|
||||
|
||||
} forEach _memPoints;
|
||||
|
||||
_args set [3, objNull];
|
||||
};
|
||||
};
|
||||
}, 0, [((getPosASL ace_player) vectorAdd [-100,0,0]), [], [], objNull]] call CBA_fnc_addPerFrameHandler;
|
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Author: PabstMirror
|
||||
* Scans for nearby "Static" objects (buildings) and adds the UserActions to them.
|
||||
* Called when interact_menu starts rendering (from "interact_keyDown" event)
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Building Classname <STRING>
|
||||
*
|
||||
* Return Value:
|
||||
* [[Array of MemPoints], [Array Of Actions]]
|
||||
*
|
||||
* Public: Yes
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
|
||||
PARAMS_1(_typeOfBuilding);
|
||||
|
||||
_memPoints = [];
|
||||
_memPointsActions = [];
|
||||
|
||||
_configPath = configFile >> "CfgVehicles" >> _typeOfBuilding >> "UserActions";
|
||||
|
||||
_fncStatement = {
|
||||
PARAMS_3(_target,_player,_variable);
|
||||
EXPLODE_2_PVT(_variable,_actionStatement,_actionCondition);
|
||||
this = _target getVariable [QGVAR(building), objNull];
|
||||
call _actionStatement;
|
||||
};
|
||||
_fncCondition = {
|
||||
PARAMS_3(_target,_player,_variable);
|
||||
EXPLODE_2_PVT(_variable,_actionStatement,_actionCondition);
|
||||
this = _target getVariable [QGVAR(building), objNull];
|
||||
call _actionCondition;
|
||||
};
|
||||
|
||||
for "_index" from 0 to ((count _configPath) - 1) do {
|
||||
_actionPath = _configPath select _index;
|
||||
|
||||
_actionDisplayName = getText (_actionPath >> "displayName");
|
||||
_actionDisplayNameDefault = getText (_actionPath >> "displayNameDefault");
|
||||
_actionPosition = getText (_actionPath >> "position");
|
||||
_actionCondition = getText (_actionPath >> "condition");
|
||||
_actionStatement = getText (_actionPath >> "statement");
|
||||
_actionMaxDistance = getNumber (_actionPath >> "radius");
|
||||
|
||||
if (_actionDisplayName == "") then {_actionDisplayName = (configName _x);};
|
||||
if (_actionPosition == "") then {ERROR("Bad Position");};
|
||||
if (_actionCondition == "") then {_actionCondition = "true";};
|
||||
if (_actionStatement == "") then {ERROR("No Statement");};
|
||||
|
||||
_actionStatement = compile _actionStatement;
|
||||
_actionCondition = compile _actionCondition;
|
||||
_actionMaxDistance = _actionMaxDistance + 0.5; //increase range slightly
|
||||
_iconImage = "";
|
||||
|
||||
//todo: extension? (~75% of time doing this string shit!)
|
||||
if (_actionDisplayNameDefault != "") then {
|
||||
//something like: "<img image='\A3\Ui_f\data\IGUI\Cfg\Actions\open_door_ca.paa' size='2.5' />";
|
||||
//find the end [.paa']
|
||||
_endIndex = _actionDisplayNameDefault find ".paa'";
|
||||
if (_endIndex == -1) exitWith {};
|
||||
_startIndex = _endIndex - 1;
|
||||
_endIndex = _endIndex + 4;
|
||||
//work backwards to find the starting [']
|
||||
while {(_startIndex > 0) && {_iconImage == ""}} do {
|
||||
if ((_actionDisplayNameDefault select [_startIndex, 1]) == "'") then {
|
||||
_startIndex = _startIndex + 1;
|
||||
_iconImage = _actionDisplayNameDefault select [_startIndex, (_endIndex - _startIndex)];
|
||||
};
|
||||
_startIndex = _startIndex - 1;
|
||||
};
|
||||
};
|
||||
|
||||
_memPointIndex = _memPoints find _actionPosition;
|
||||
_actionOffset = [0,0,0];
|
||||
if (_memPointIndex == -1) then {
|
||||
_memPointIndex = count _memPoints;
|
||||
_memPoints pushBack _actionPosition;
|
||||
_memPointsActions pushBack [];
|
||||
} else {
|
||||
_actionOffset set [2, 0.05 * (count (_memPointsActions select _memPointIndex))];
|
||||
};
|
||||
|
||||
_action = [(configName _actionPath), _actionDisplayName, _iconImage, _fncStatement, _fncCondition, {}, [_actionStatement, _actionCondition], _actionOffset, _actionMaxDistance, [false,false,false,false,true]] call EFUNC(interact_menu,createAction);
|
||||
(_memPointsActions select _memPointIndex) pushBack _action;
|
||||
|
||||
};
|
||||
|
||||
[_memPoints, _memPointsActions]
|
Loading…
Reference in New Issue
Block a user