From 88e774c30d045a89910f47efbac1a8e4fdd6eaa7 Mon Sep 17 00:00:00 2001 From: Seb <65898127+Seb105@users.noreply.github.com> Date: Tue, 12 Oct 2021 18:53:35 +0100 Subject: [PATCH] Interaction - Rename group self-interact (#8346) * 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 Co-authored-by: PabstMirror --- addons/interaction/CfgVehicles.hpp | 7 ++ addons/interaction/XEH_PREP.hpp | 3 + addons/interaction/config.cpp | 1 + .../functions/fnc_canRenameGroup.sqf | 20 ++++++ .../interaction/functions/fnc_renameGroup.sqf | 39 +++++++++++ .../functions/fnc_renameGroupUI.sqf | 36 ++++++++++ addons/interaction/groupRename_GUI.hpp | 66 +++++++++++++++++++ addons/interaction/initSettings.sqf | 8 +++ addons/interaction/stringtable.xml | 15 +++++ 9 files changed, 195 insertions(+) create mode 100644 addons/interaction/functions/fnc_canRenameGroup.sqf create mode 100644 addons/interaction/functions/fnc_renameGroup.sqf create mode 100644 addons/interaction/functions/fnc_renameGroupUI.sqf create mode 100644 addons/interaction/groupRename_GUI.hpp diff --git a/addons/interaction/CfgVehicles.hpp b/addons/interaction/CfgVehicles.hpp index cbf2d39f67..95a00e2465 100644 --- a/addons/interaction/CfgVehicles.hpp +++ b/addons/interaction/CfgVehicles.hpp @@ -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 { diff --git a/addons/interaction/XEH_PREP.hpp b/addons/interaction/XEH_PREP.hpp index 8eada17e3d..2d32f3115e 100644 --- a/addons/interaction/XEH_PREP.hpp +++ b/addons/interaction/XEH_PREP.hpp @@ -32,6 +32,9 @@ PREP(canPardon); PREP(pardon); PREP(canPullOutBody); PREP(pullOutBody); +PREP(canRenameGroup); +PREP(renameGroupUI); +PREP(renameGroup); // Weapon Attachments PREP(getWeaponAttachmentsActions); diff --git a/addons/interaction/config.cpp b/addons/interaction/config.cpp index 77c2b408af..93711a57ce 100644 --- a/addons/interaction/config.cpp +++ b/addons/interaction/config.cpp @@ -19,3 +19,4 @@ class CfgPatches { #include "RscTitles.hpp" #include "ACE_Settings.hpp" #include "ACE_ZeusActions.hpp" +#include "groupRename_GUI.hpp" diff --git a/addons/interaction/functions/fnc_canRenameGroup.sqf b/addons/interaction/functions/fnc_canRenameGroup.sqf new file mode 100644 index 0000000000..bc6d423435 --- /dev/null +++ b/addons/interaction/functions/fnc_canRenameGroup.sqf @@ -0,0 +1,20 @@ +#include "script_component.hpp" +/* + * Author: Seb + * Checks if the unit is allowed to rename its group. + * + * Arguments: + * 0: Unit + * + * Return Value: + * Is this unit allowed to rename its group? + * + * Example: + * player call ace_interaction_fnc_canRenameGroup + * + * Public: No + */ + +params [["_unit", objNull, [objNull]]]; + +GVAR(enableGroupRenaming) && {_unit == leader _unit} diff --git a/addons/interaction/functions/fnc_renameGroup.sqf b/addons/interaction/functions/fnc_renameGroup.sqf new file mode 100644 index 0000000000..100e02e0b8 --- /dev/null +++ b/addons/interaction/functions/fnc_renameGroup.sqf @@ -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 + * 1: The new name of the group + * + * Return Value: + * Whether the group was succesfully renamed + * + * 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 diff --git a/addons/interaction/functions/fnc_renameGroupUI.sqf b/addons/interaction/functions/fnc_renameGroupUI.sqf new file mode 100644 index 0000000000..d67aff3322 --- /dev/null +++ b/addons/interaction/functions/fnc_renameGroupUI.sqf @@ -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 + * + * 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; diff --git a/addons/interaction/groupRename_GUI.hpp b/addons/interaction/groupRename_GUI.hpp new file mode 100644 index 0000000000..a0b332b505 --- /dev/null +++ b/addons/interaction/groupRename_GUI.hpp @@ -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); + }; + }; +}; diff --git a/addons/interaction/initSettings.sqf b/addons/interaction/initSettings.sqf index 0500cd5c43..684207d252 100644 --- a/addons/interaction/initSettings.sqf +++ b/addons/interaction/initSettings.sqf @@ -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; diff --git a/addons/interaction/stringtable.xml b/addons/interaction/stringtable.xml index 7cbb67e9a6..24fd5a694d 100644 --- a/addons/interaction/stringtable.xml +++ b/addons/interaction/stringtable.xml @@ -323,6 +323,15 @@ 成為隊長 Lider ol + + Rename Group + + + This group name is already in use. + + + NEW GROUP NAME: + DANCE! TANZEN! @@ -1227,5 +1236,11 @@ Cette option permet de fixer/retirer des accessoires d'arme à partir du menu d'interaction personnel. Włącza akcje przyczepienia/odczepienia dodatków dla obecnej broni + + Allow group rename + + + Allows a group leader to rename their group if the name is not already taken. +