Skip to content

Commit

Permalink
Add support for waypoint type conditions and priority (#722)
Browse files Browse the repository at this point in the history
  • Loading branch information
mharis001 authored Mar 25, 2023
1 parent 31c2d4a commit 5f949ab
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 26 deletions.
1 change: 1 addition & 0 deletions addons/attributes/CfgWaypointTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class ZEN_WaypointTypes {
displayName = ECSTRING(ai,Fastrope);
type = "SCRIPTED";
script = QPATHTOEF(ai,functions\fnc_waypointFastrope.sqf);
condition = QUOTE(isClass (configFile >> 'CfgPatches' >> 'ace_fastroping'));
};
class SearchBuilding {
displayName = ECSTRING(ai,SearchBuilding);
Expand Down
23 changes: 20 additions & 3 deletions addons/attributes/functions/fnc_compileWaypoints.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@
* Public: No
*/

uiNamespace setVariable [QGVAR(waypointTypes), configProperties [configFile >> "ZEN_WaypointTypes", "isClass _x"] apply {
[toUpper getText (_x >> "displayName"), getText (_x >> "tooltip"), getText (_x >> "type"), getText (_x >> "script")]
}];
private _waypointTypes = configProperties [configFile >> "ZEN_WaypointTypes", "isClass _x"] apply {
private _condition = compile getText (_x >> "condition");

if (_condition isEqualTo {}) then {
_condition = {true};
};

[
getText (_x >> "displayName"),
getText (_x >> "tooltip"),
getText (_x >> "type"),
getText (_x >> "script"),
_condition,
getNumber (_x >> "priority")
]
};

[_waypointTypes, 5, false] call CBA_fnc_sortNestedArray;

uiNamespace setVariable [QGVAR(waypointTypes), _waypointTypes];
27 changes: 22 additions & 5 deletions addons/attributes/functions/fnc_gui_waypoint.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,35 @@ if (!isNull waypointAttachedVehicle _entity) exitWith {
_ctrlBackground ctrlSetText localize "str_a3_rscattributewaypointtype_type";
};

private _ctrlToolbox = _controlsGroup controlsGroupCtrl IDC_ATTRIBUTE_TOOLBOX;
// Get active waypoint types and create toolbox with appropriate number of rows
private _waypointTypes = uiNamespace getVariable QGVAR(waypointTypes) select {
_entity call (_x select 4)
};

private _rows = ceil (count _waypointTypes / 3);
parsingNamespace setVariable [QEGVAR(common,rows), _rows];
parsingNamespace setVariable [QEGVAR(common,columns), 3];

private _ctrlToolbox = _display ctrlCreate [QEGVAR(common,RscToolbox), IDC_ATTRIBUTE_TOOLBOX, _controlsGroup];
_ctrlToolbox ctrlSetBackgroundColor [0, 0, 0, 0];
_ctrlToolbox ctrlSetPosition [0, POS_H(1), POS_W(26), POS_H(_rows)];
_ctrlToolbox ctrlCommit 0;

private _ctrlBackground = _controlsGroup controlsGroupCtrl IDC_ATTRIBUTE_BACKGROUND;
_ctrlBackground ctrlSetPositionH POS_H(_rows);
_ctrlBackground ctrlCommit 0;

_controlsGroup ctrlSetPositionH POS_H(_rows + 1);
_controlsGroup ctrlCommit 0;

// Determine the waypoint type from the given entity
private _waypointType = waypointType _entity;
private _waypointType = waypointType _entity;
private _waypointScript = waypointScript _entity;
private _waypointTypes = uiNamespace getVariable QGVAR(waypointTypes);

{
_x params ["_name", "_tooltip", "_type", "_script"];

private _index = _ctrlToolbox lbAdd _name;
private _index = _ctrlToolbox lbAdd toUpper _name;
_ctrlToolbox lbSetTooltip [_index, _tooltip];
_ctrlToolbox setVariable [str _index, [_type, _script]];

Expand All @@ -49,7 +67,6 @@ _ctrlToolbox ctrlAddEventHandler ["ToolBoxSelChanged", {
params ["_ctrlToolbox", "_index"];

private _value = _ctrlToolbox getVariable str _index;

private _controlsGroup = ctrlParentControlsGroup _ctrlToolbox;
_controlsGroup setVariable [QGVAR(value), _value];
}];
15 changes: 1 addition & 14 deletions addons/attributes/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,8 @@ class GVAR(toolbox): GVAR(base) {
};
};

#define WAYPOINT_ROWS (ceil (count (uiNamespace getVariable QGVAR(waypointTypes)) / 3))

class GVAR(waypoint): GVAR(base) {
function = QFUNC(gui_waypoint);
h = POS_H(WAYPOINT_ROWS + 1);
class controls: controls {
class Label: Label {
w = POS_W(26);
Expand All @@ -146,18 +143,8 @@ class GVAR(waypoint): GVAR(base) {
x = 0;
y = POS_H(1);
w = POS_W(26);
h = POS_H(WAYPOINT_ROWS);
};
class Toolbox: ctrlToolbox {
idc = IDC_ATTRIBUTE_TOOLBOX;
x = 0;
y = POS_H(1);
w = POS_W(26);
h = POS_H(WAYPOINT_ROWS);
colorBackground[] = {0, 0, 0, 0};
rows = WAYPOINT_ROWS;
columns = 3;
};
// Toolbox created through script based on available waypoints
};
};

Expand Down
10 changes: 6 additions & 4 deletions docs/frameworks/custom_waypoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ Waypoints are added as subclasses to the `ZEN_WaypointTypes` root config class.

Name | Type | Description
---- | ---- | -----------
`displayName` | STRING | Displayed name of the waypoint
`tooltip` | STRING | Tooltip displayed when hovered
`type` | STRING | Waypoint type, [reference](https://community.bistudio.com/wiki/Waypoint_types)
`script` | STRING | Path to waypoint script file, used when type is "SCRIPTED"
`displayName` | STRING | Displayed name of the waypoint.
`tooltip` | STRING | Tooltip displayed when hovered.
`type` | STRING | Waypoint type, [reference](https://community.bistudio.com/wiki/Waypoint_types).
`script` | STRING | Path to waypoint script file, used when type is "SCRIPTED".
`condition` | STRING | Condition to show the waypoint type.
`priority` | NUMBER | Waypoint sorting priority.

### Example

Expand Down

0 comments on commit 5f949ab

Please sign in to comment.