Skip to content

Commit

Permalink
Interaction - Rename group self-interact (#8346)
Browse files Browse the repository at this point in the history
* Group renaming self interact

* UI base

* Custom UI solution (looks terrible)

* Improve GUI, optimise functions

* Add exitWith return value to fnc_renameGroup

* tabs to spaces

* Small tweaks

* newlines

pre-empting newline gestapo

* input prompt caps

* Implement suggestions

* Remove already inherited value

* Per-side group name handling

* Add same group case sensitive changes.

* Suggestions

- Use ace_common_fnc_displayTextStructured
- Formatting
- Phrasing of strings

* replace spawn with CBA_fnc_execNextFrame

* Update addons/interaction/initSettings.sqf

Co-authored-by: PabstMirror <[email protected]>

Co-authored-by: PabstMirror <[email protected]>
  • Loading branch information
Seb105 and PabstMirror authored Oct 12, 2021
1 parent 3d93155 commit 88e774c
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 0 deletions.
7 changes: 7 additions & 0 deletions addons/interaction/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,13 @@ class CfgVehicles {
showDisabled = 1;
icon = QPATHTOF(UI\team\team_management_ca.paa);
};
class ACE_RenameGroup {
displayName = CSTRING(RenameGroup);
condition = QUOTE(_player call FUNC(canRenameGroup));
exceptions[] = {"isNotSwimming", "isNotInside", "isNotSitting", "isNotOnLadder", "isNotRefueling"};
statement = QUOTE(_player call FUNC(renameGroupUI));
showDisabled =1;
};
};

class ACE_Equipment {
Expand Down
3 changes: 3 additions & 0 deletions addons/interaction/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ PREP(canPardon);
PREP(pardon);
PREP(canPullOutBody);
PREP(pullOutBody);
PREP(canRenameGroup);
PREP(renameGroupUI);
PREP(renameGroup);

// Weapon Attachments
PREP(getWeaponAttachmentsActions);
Expand Down
1 change: 1 addition & 0 deletions addons/interaction/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ class CfgPatches {
#include "RscTitles.hpp"
#include "ACE_Settings.hpp"
#include "ACE_ZeusActions.hpp"
#include "groupRename_GUI.hpp"
20 changes: 20 additions & 0 deletions addons/interaction/functions/fnc_canRenameGroup.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "script_component.hpp"
/*
* Author: Seb
* Checks if the unit is allowed to rename its group.
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* Is this unit allowed to rename its group? <BOOL>
*
* Example:
* player call ace_interaction_fnc_canRenameGroup
*
* Public: No
*/

params [["_unit", objNull, [objNull]]];

GVAR(enableGroupRenaming) && {_unit == leader _unit}
39 changes: 39 additions & 0 deletions addons/interaction/functions/fnc_renameGroup.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "script_component.hpp"
/*
* Author: Seb
* Renames a group to a given string (groupID), whilst checking that it is not an invalid name.
*
* Arguments:
* 0: The group to be renamed <GROUP>
* 1: The new name of the group <STRING>
*
* Return Value:
* Whether the group was succesfully renamed <BOOL>
*
* Example:
* [group player, "leet squad"] call ace_interaction_fnc_renameGroup
*
* Public: No
*/

params [
["_group", grpNull, [grpNull]],
["_newName", "", [""]]
];
if (_newName isEqualTo (groupID _group)) exitWith {true};

private _lowerName = toLower _newName; // Case insensitive name search
private _nameAlreadyTaken = allGroups findIf {
side _x isEqualTo side _group
&& {_lowerName isEqualTo toLower (groupID _x)}
&& {_group != _x}
} != -1;


if (_nameAlreadyTaken) then {
[LLSTRING(RenameGroupAlreadyExists)] call EFUNC(common,displayTextStructured);
} else {
_group setGroupIdGlobal [_newName];
};

!_nameAlreadyTaken
36 changes: 36 additions & 0 deletions addons/interaction/functions/fnc_renameGroupUI.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "script_component.hpp"
/*
* Author: Seb
* Shows a UI to allow a unit to change its group ID.
*
* Arguments:
* 0: The unit renaming their group <OBJECT>
*
* Return Value:
* None
*
* Example:
* player call ace_interaction_fnc_renameGroupUI
*
* Public: No
*/

// delay a frame so we don't overlap with interaction-menu as it closes
[{
params [["_unit", objNull, [objNull]]];

private _display = findDisplay 46 createDisplay QGVAR(groupNameDisplay);
private _textCtrl = _display displayCtrl 451;
_textCtrl ctrlSetText (groupID group _unit);
_display setVariable [QGVAR(renamedGroup), group _unit];
_display displayAddEventHandler ["Unload", {
params ["_display", "_exitCode"];

if !(_exitCode isEqualTo 1) exitWith {};

private _group = _display getVariable QGVAR(renamedGroup);
private _textCtrl = _display displayCtrl 451;
private _newName = ctrlText _textCtrl;
[_group, _newName] call FUNC(renameGroup);
}];
}, _this] call CBA_fnc_execNextFrame;
66 changes: 66 additions & 0 deletions addons/interaction/groupRename_GUI.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#define FONT_H (((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) * 1)
#define FONT_W (FONT_H / pixelH * pixelW)
#define GAP_W (pixelW * 2)
#define GAP_H (pixelH * 2)
#define ELEMENT_HEIGHT FONT_H + FONT_W
#define TOTAL_W FONT_W * 25
#define TOTAL_H FONT_H * 3 + GAP_H

class ctrlStatic;
class ctrlButton;
class ctrlEdit;
class ctrlStaticTitle;

class GVAR(groupNameDisplay) {
idd = -1;
enableSimulation = 1;

class ControlsBackground {
class Title: ctrlStaticTitle {
x = QUOTE(safeZoneX + (safeZoneW / 2) - TOTAL_W/2);
y = QUOTE(safeZoneY + (safeZoneH / 2) - (FONT_H * 1.2) - GAP_H);
w = QUOTE(TOTAL_W);
h = QUOTE(FONT_H * 1.2);
sizeEx = QUOTE(FONT_H * 1.2);
text = CSTRING(renameGroupInput);
};
class Background: ctrlStatic {
colorBackground[] = {0, 0, 0, 0.8};
x = QUOTE(safeZoneX + (safeZoneW / 2) - TOTAL_W/2);
y = QUOTE(safeZoneY + (safeZoneH / 2));
w = QUOTE(TOTAL_W);
h = QUOTE(ELEMENT_HEIGHT);
};
};

class controls {
class Input: ctrlEdit {
idc = 451;
x = QUOTE(safeZoneX + (safeZoneW / 2) - TOTAL_W/2 + FONT_W/2);
y = QUOTE(safeZoneY + (safeZoneH / 2) + FONT_W/2);
w = QUOTE(TOTAL_W - FONT_W);
h = QUOTE(ELEMENT_HEIGHT - FONT_W);
sizeEx = QUOTE(FONT_H);
};

class OkButton: ctrlButton {
idc = 1;
x = QUOTE(safeZoneX + (safeZoneW / 2) + TOTAL_W/2 - FONT_W * 15);
y = QUOTE(safeZoneY + (safeZoneH / 2) + ELEMENT_HEIGHT + GAP_H);
w = QUOTE(FONT_W * 15);
h = QUOTE(ELEMENT_HEIGHT - FONT_W);
sizeEx = QUOTE(FONT_H);
text = CSTRING(RenameGroup);
};

class CancelButton: ctrlButton {
idc = 2;
x = QUOTE(safeZoneX + (safeZoneW / 2) - TOTAL_W/2);
y = QUOTE(safeZoneY + (safeZoneH / 2) + ELEMENT_HEIGHT + GAP_H);
w = QUOTE(FONT_W * 6);
h = QUOTE(ELEMENT_HEIGHT - FONT_W);
sizeEx = QUOTE(FONT_H);
text = CSTRING(CancelSelection);
};
};
};
8 changes: 8 additions & 0 deletions addons/interaction/initSettings.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,11 @@
format ["ACE %1", LLSTRING(DisplayName)],
true
] call CBA_fnc_addSetting;

[
QGVAR(enableGroupRenaming), "CHECKBOX",
[LSTRING(EnableRenameGroup_DisplayName), LSTRING(EnableRenameGroup_Description)],
format ["ACE %1", LLSTRING(DisplayName)],
true,
true
] call CBA_fnc_addSetting;
15 changes: 15 additions & 0 deletions addons/interaction/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,15 @@
<Chinese>成為隊長</Chinese>
<Turkish>Lider ol</Turkish>
</Key>
<Key ID="STR_ACE_Interaction_RenameGroup">
<English>Rename Group</English>
</Key>
<Key ID="STR_ACE_Interaction_RenameGroupAlreadyExists">
<English>This group name is already in use.</English>
</Key>
<Key ID="STR_ACE_Interaction_RenameGroupInput">
<English>NEW GROUP NAME:</English>
</Key>
<Key ID="STR_ACE_Interaction_Dance">
<English>DANCE!</English>
<German>TANZEN!</German>
Expand Down Expand Up @@ -1227,5 +1236,11 @@
<French>Cette option permet de fixer/retirer des accessoires d'arme à partir du menu d'interaction personnel.</French>
<Polish>Włącza akcje przyczepienia/odczepienia dodatków dla obecnej broni</Polish>
</Key>
<Key ID="STR_ACE_Interaction_enableRenameGroup_DisplayName">
<English>Allow group rename</English>
</Key>
<Key ID="STR_ACE_Interaction_enableRenameGroup_Description">
<English>Allows a group leader to rename their group if the name is not already taken.</English>
</Key>
</Package>
</Project>

0 comments on commit 88e774c

Please sign in to comment.