Skip to content

Commit

Permalink
Marker Flags - Add placing system & icons (#8951)
Browse files Browse the repository at this point in the history
  • Loading branch information
Timi007 authored Aug 31, 2022
1 parent 4eef2da commit 11984f6
Show file tree
Hide file tree
Showing 23 changed files with 203 additions and 53 deletions.
6 changes: 6 additions & 0 deletions addons/marker_flags/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ class Extended_PostInit_EventHandlers {
init = QUOTE(call COMPILE_SCRIPT(XEH_postInit));
};
};

class Extended_DisplayLoad_EventHandlers {
class RscDisplayMission {
ADDON = QUOTE(_this call COMPILE_SCRIPT(XEH_missionDisplayLoad));
};
};
17 changes: 9 additions & 8 deletions addons/marker_flags/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class CfgVehicles {
displayName = CSTRING(ActionPlace);
condition = QUOTE(_player call FUNC(canPlace));
insertChildren = QUOTE(_this call FUNC(addActions));
icon = QPATHTOF(ui\icons\white_place_icon.paa);
};
};
};
Expand All @@ -18,34 +19,34 @@ class CfgVehicles {
scopeCurator = 2;
author = ECSTRING(common,ACETeam);
displayName = CSTRING(white);
hiddenSelectionsTextures[] = {"#(argb,8,8,3)color(1,1,1,1,co)"};
hiddenSelectionsTextures[] = {"#(argb,8,8,3)color(0.82,0.82,0.82,1,co)"};
};
class GVAR(black): GVAR(white) {
displayName = CSTRING(black);
hiddenSelectionsTextures[] = {"#(argb,8,8,3)color(0,0,0,1,co)"};
hiddenSelectionsTextures[] = {"#(argb,8,8,3)color(0.18,0.18,0.18,1,co)"};
};
class GVAR(red): GVAR(white) {
displayName = CSTRING(red);
hiddenSelectionsTextures[] = {"#(argb,8,8,3)color(1,0,0,1,co)"};
hiddenSelectionsTextures[] = {"#(argb,8,8,3)color(0.647,0.141,0.161,1,co)"};
};
class GVAR(green): GVAR(white) {
displayName = CSTRING(green);
hiddenSelectionsTextures[] = {"#(argb,8,8,3)color(0,1,0,1,co)"};
hiddenSelectionsTextures[] = {"#(argb,8,8,3)color(0.063,0.588,0.063,1,co)"};
};
class GVAR(blue): GVAR(white) {
displayName = CSTRING(blue);
hiddenSelectionsTextures[] = {"#(argb,8,8,3)color(0,0,1,1,co)"};
hiddenSelectionsTextures[] = {"#(argb,8,8,3)color(0.161,0.349,0.58,1,co)"};
};
class GVAR(yellow): GVAR(white) {
displayName = CSTRING(yellow);
hiddenSelectionsTextures[] = {"#(argb,8,8,3)color(1,1,0,1,co)"};
hiddenSelectionsTextures[] = {"#(argb,8,8,3)color(0.776,0.729,0.129,1,co)"};
};
class GVAR(orange): GVAR(white) {
displayName = CSTRING(orange);
hiddenSelectionsTextures[] = {"#(argb,8,8,3)color(1,0.5,0,1,co)"};
hiddenSelectionsTextures[] = {"#(argb,8,8,3)color(0.678,0.349,0.153,1,co)"};
};
class GVAR(purple): GVAR(white) {
displayName = CSTRING(purple);
hiddenSelectionsTextures[] = {"#(argb,8,8,3)color(0.5,0,0.5,1,co)"};
hiddenSelectionsTextures[] = {"#(argb,8,8,3)color(0.373,0.141,0.647,1,co)"};
};
};
24 changes: 16 additions & 8 deletions addons/marker_flags/CfgWeapons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ class CfgWeapons {
class CBA_MiscItem_ItemInfo;

class GVAR(white): ACE_ItemCore {
GVAR(vehicle) = GVAR(white);
GVAR(vehicle) = QGVAR(white);
GVAR(icon) = QPATHTOF(ui\icons\white_place_icon.paa);
author = ECSTRING(common,ACETeam);
scope = 2;
displayName = CSTRING(white);
Expand All @@ -18,37 +19,44 @@ class CfgWeapons {
};

class GVAR(black): GVAR(white) {
GVAR(vehicle) = GVAR(black);
GVAR(vehicle) = QGVAR(black);
GVAR(icon) = QPATHTOF(ui\icons\black_place_icon.paa);
displayName = CSTRING(black);
picture = QPATHTOF(ui\black_ca.paa);
};
class GVAR(red): GVAR(white) {
GVAR(vehicle) = GVAR(red);
GVAR(vehicle) = QGVAR(red);
GVAR(icon) = QPATHTOF(ui\icons\red_place_icon.paa);
displayName = CSTRING(red);
picture = QPATHTOF(ui\red_ca.paa);
};
class GVAR(green): GVAR(white) {
GVAR(vehicle) = GVAR(green);
GVAR(vehicle) = QGVAR(green);
GVAR(icon) = QPATHTOF(ui\icons\green_place_icon.paa);
displayName = CSTRING(green);
picture = QPATHTOF(ui\green_ca.paa);
};
class GVAR(blue): GVAR(white) {
GVAR(vehicle) = GVAR(blue);
GVAR(vehicle) = QGVAR(blue);
GVAR(icon) = QPATHTOF(ui\icons\blue_place_icon.paa);
displayName = CSTRING(blue);
picture = QPATHTOF(ui\blue_ca.paa);
};
class GVAR(yellow): GVAR(white) {
GVAR(vehicle) = GVAR(yellow);
GVAR(vehicle) = QGVAR(yellow);
GVAR(icon) = QPATHTOF(ui\icons\yellow_place_icon.paa);
displayName = CSTRING(yellow);
picture = QPATHTOF(ui\yellow_ca.paa);
};
class GVAR(orange): GVAR(white) {
GVAR(vehicle) = GVAR(orange);
GVAR(vehicle) = QGVAR(orange);
GVAR(icon) = QPATHTOF(ui\icons\orange_place_icon.paa);
displayName = CSTRING(orange);
picture = QPATHTOF(ui\orange_ca.paa);
};
class GVAR(purple): GVAR(white) {
GVAR(vehicle) = GVAR(purple);
GVAR(vehicle) = QGVAR(purple);
GVAR(icon) = QPATHTOF(ui\icons\purple_place_icon.paa);
displayName = CSTRING(purple);
picture = QPATHTOF(ui\purple_ca.paa);
};
Expand Down
1 change: 1 addition & 0 deletions addons/marker_flags/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
PREP(addActions);
PREP(canPlace);
PREP(getFlags);
PREP(handleScrollWheel);
PREP(pickUpFlag);
PREP(placeFlag);
17 changes: 17 additions & 0 deletions addons/marker_flags/XEH_missionDisplayLoad.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "script_component.hpp"

if (!hasInterface) exitWith {};

params ["_display"];

_display displayAddEventHandler ["MouseZChanged", {
params ["", "_scroll"];
[_scroll] call FUNC(handleScrollWheel);
}];

_display displayAddEventHandler ["MouseButtonDown", {
params ["", "_button"];
if (GVAR(isPlacing) isNotEqualTo PLACE_WAITING) exitWith {false};
if (_button isNotEqualTo 1) exitWith {false}; // 1 = Left mouse button
GVAR(isPlacing) = PLACE_CANCEL;
}];
20 changes: 14 additions & 6 deletions addons/marker_flags/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,29 @@

if (!hasInterface) exitWith {};

private _weapons = (call (uiNamespace getVariable [QGVAR(flagItems), {[]}])) apply {configFile >> "CfgWeapons" >> _x};
GVAR(isPlacing) = PLACE_CANCEL;
["ace_interactMenuOpened", {GVAR(isPlacing) = PLACE_CANCEL;}] call CBA_fnc_addEventHandler;

private _cfgWeapons = configFile >> "CfgWeapons";
private _weapons = (call (uiNamespace getVariable [QGVAR(flagItems), {[]}])) apply {_cfgWeapons >> _x};

{
private _name = configName _x;
private _vehicle = getText (_x >> QGVAR(vehicle));
GVAR(flagCache) set [_name, _vehicle];
private _vehicleClass = getText (_x >> QGVAR(vehicle));
private _displayName = getText (_x >> "displayName");
private _icon = getText (_x >> QGVAR(icon));
GVAR(flagCache) set [_name, [_vehicleClass, _displayName, _icon]];

private _action = [
QGVAR(pickup),
LLSTRING(ActionPickUp),
"",
QPATHTOF(ui\icons\white_pickup_icon.paa),
{call FUNC(pickUpFlag)},
{[_player, _target, []] call EFUNC(common,canInteractWith)},
{},
[_name]
[_name],
[0, 0.072, 0.2],
2
] call EFUNC(interact_menu,createAction);
[_vehicle, 0, ["ACE_MainActions"], _action] call EFUNC(interact_menu,addActionToClass);
[_vehicleClass, 0, [], _action] call EFUNC(interact_menu,addActionToClass);
} forEach _weapons;
2 changes: 1 addition & 1 deletion addons/marker_flags/XEH_preStart.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

#include "XEH_PREP.hpp"

private _weapons = (configProperties [configfile >> "CfgWeapons", QUOTE(isClass _x && (isText (_x >> QQGVAR(vehicle)))), true]) apply {configName _x};
private _weapons = (configProperties [configfile >> "CfgWeapons", QUOTE(isClass _x && {isText (_x >> QQGVAR(vehicle))}), true]) apply {configName _x};
uiNamespace setVariable [QGVAR(flagItems), compileFinal str _weapons];
4 changes: 2 additions & 2 deletions addons/marker_flags/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class CfgPatches {
QGVAR(purple)
};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"ace_interact_menu"};
requiredAddons[] = {"ace_common", "ace_interaction", "ace_interact_menu"};
author = ECSTRING(common,ACETeam);
authors[] = {"Brett Mayson"};
authors[] = {"Brett Mayson", "Timi007"};
url = ECSTRING(main,URL);
VERSION_CONFIG;
};
Expand Down
9 changes: 5 additions & 4 deletions addons/marker_flags/functions/fnc_addActions.sqf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "script_component.hpp"
/*
* Author: Brett Mayson
* Author: Brett Mayson, Timi007
* Adds the child actions for placing flags.
*
* Arguments:
Expand All @@ -20,12 +20,13 @@ params ["_unit"];
private _actions = [];

{
private _config = configFile >> "CfgWeapons" >> _x;
(GVAR(flagCache) get _x) params ["_vehicle", "_displayName", "_icon"];

_actions pushBack [
[
_x,
getText (_config >> "displayName"),
getText (_config >> "picture"),
_displayName,
_icon,
{[_this select 0, _this select 2] call FUNC(placeFlag)},
{true},
{},
Expand Down
30 changes: 30 additions & 0 deletions addons/marker_flags/functions/fnc_handleScrollWheel.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "script_component.hpp"
/*
* Author: Timi007
* Handles the marker flag object height.
*
* Arguments:
* 0: Scroll amount <NUMBER>
*
* Return Value:
* Handled <BOOLEAN>
*
* Example:
* [5] call ace_marker_flags_fnc_handleScrollWheel
*
* Public: No
*/

params ["_scrollAmount"];

if (GVAR(isPlacing) isNotEqualTo PLACE_WAITING) exitWith {
false
};

// Move object height 5cm per scroll
GVAR(objectHeight) = GVAR(objectHeight) + (_scrollAmount * 0.05);

// Clamp height between MIN_HEIGHT and MAX_HEIGHT
GVAR(objectHeight) = MIN_HEIGHT max (GVAR(objectHeight) min MAX_HEIGHT);

true
15 changes: 10 additions & 5 deletions addons/marker_flags/functions/fnc_pickUpFlag.sqf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "script_component.hpp"
/*
* Author: Brett Mayson
* Author: Brett Mayson, Timi007
* Places a flag in front of the unit.
*
* Arguments:
Expand All @@ -12,17 +12,22 @@
* Nothing
*
* Example:
* [_flag,player,"x"] call ace_marker_flags_fnc_pickupFlag
* [_flag, player, ["ace_marker_flags_white"]] call ace_marker_flags_fnc_pickupFlag
*
* Public: No
*/

params [["_flag", objNull, [objNull]], ["_unit", objNull, [objNull]], ["_args", [""], [[]]]];
private _itemName = _args # 0;
_args params ["_item"];
TRACE_3("pickupFlag",_unit,_flag,_itemName);

if (isNull _flag) exitWith {};

[_unit, "PutDown"] call EFUNC(common,doGesture);
deleteVehicle _flag;
[_unit, _itemName] call EFUNC(common,addToInventory);

[{
params ["_flag", "_unit", "_item"];

[_unit, _item] call EFUNC(common,addToInventory);
deleteVehicle _flag;
}, [_flag, _unit, _item], 0.7] call CBA_fnc_waitAndExecute;
73 changes: 60 additions & 13 deletions addons/marker_flags/functions/fnc_placeFlag.sqf
Original file line number Diff line number Diff line change
@@ -1,27 +1,74 @@
#include "script_component.hpp"
/*
* Author: Brett Mayson
* Places a flag in front of the unit.
* Author: Timi007
* Starts the placing process of the marker flag for the player.
* Flags can be placed with the special marker flag items.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Flag <STRING>
* 0: Player <OBJECT>
* 1: Flag item <STRING>
*
* Return Value:
* Flag <OBJECT>
* Nothing
*
* Example:
* [player, "ace_marker_flags_white"] call ace_marker_flags_fnc_placeFlag
*
* Public: No
*/

params [["_unit", objNull, [objNull]], ["_flag", QGVAR(white), [""]]];
params [["_player", objNull, [objNull]], ["_item", QGVAR(white), [""]]];
TRACE_2("Placing flag", _player, _item);

_unit removeItem _flag;
_flag = GVAR(flagCache) get _flag; // convert to vehicle type
private _pos = _unit modelToWorld [0, 1, 0];
private _flag = _flag createVehicle _pos;
_flag setPos _pos;
[QGVAR(placed), [_unit, _flag]] call CBA_fnc_localEvent;
[_unit, "PutDown"] call EFUNC(common,doGesture);
(GVAR(flagCache) get _item) params ["_vehicleClass"];

private _flag = _vehicleClass createVehicle [0, 0, 0];

TRACE_1("Created flag", _flag);

// Set flag start height
GVAR(objectHeight) = MAX_HEIGHT;

GVAR(isPlacing) = PLACE_WAITING;

// Add info dialog for the player which show the controls
[LLSTRING(ActionPlace), LLSTRING(ActionCancel), LLSTRING(ActionAdjustHeight)] call EFUNC(interaction,showMouseHint);

private _mouseClickID = [_player, "DefaultAction", {
GVAR(isPlacing) isEqualTo PLACE_WAITING
}, {
GVAR(isPlacing) = PLACE_APPROVE
}] call EFUNC(common,addActionEventHandler);

[{
params ["_args", "_handle"];
_args params ["_player", "_item", "_flag", "_mouseClickID"];

if (isNull _flag || {!([_player, _flag] call EFUNC(common,canInteractWith))}) then {
GVAR(isPlacing) = PLACE_CANCEL;
};

if (GVAR(isPlacing) isNotEqualTo PLACE_WAITING) exitWith {
[_handle] call CBA_fnc_removePerFrameHandler;
call EFUNC(interaction,hideMouseHint);
[_player, "DefaultAction", _mouseClickID] call EFUNC(common,removeActionEventHandler);

if (GVAR(isPlacing) isEqualTo PLACE_APPROVE) then {
// End position of the flag
GVAR(isPlacing) = PLACE_CANCEL;
[_player, "PutDown"] call EFUNC(common,doGesture);
_player removeItem _item;
[QGVAR(placed), [_player, _flag, _item]] call CBA_fnc_localEvent;
} else {
// Action is canceled
deleteVehicle _flag;
};
};

private _pos = (eyePos _player) vectorAdd ((getCameraViewDirection _player) vectorMultiply FLAG_PLACING_DISTANCE);
// Adjust height of flag with the scroll wheel
_pos set [2, ((getPosWorld _player) select 2) + GVAR(objectHeight)];

_flag setPosWorld _pos;
_flag setDir (getDir _player - 90);
}, 0, [_player, _item, _flag, _mouseClickID]] call CBA_fnc_addPerFrameHandler;
9 changes: 9 additions & 0 deletions addons/marker_flags/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@
#endif

#include "\z\ace\addons\main\script_macros.hpp"

#define PLACE_WAITING -1
#define PLACE_CANCEL 0
#define PLACE_APPROVE 1

#define MIN_HEIGHT -0.3
#define MAX_HEIGHT 0.4

#define FLAG_PLACING_DISTANCE 2
Loading

0 comments on commit 11984f6

Please sign in to comment.