Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cargo - Add ability to add custom name to cargo objects #8023

Merged
merged 20 commits into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ havena <silveredenis@gmail.com>
Hawkins
Head <brobergsebastian@gmail.com>
Hybrid V
JasperRab <jasper@jasperrab.eu>
john681611 <john681611@hotmail.com>
JoramD
Karneck <dschultz26@hotmail.com>
Expand Down
16 changes: 0 additions & 16 deletions addons/arsenal/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,6 @@
<Czech>[Shift+Klik pro uložení jako standardního vybavení pro misi]</Czech>
<Turkish>[Shift+Click varsayılan kıyafetlere kaydet]</Turkish>
</Key>
<Key ID="STR_ACE_Arsenal_buttonRenameText">
<English>Rename</English>
<Spanish>Renombrar</Spanish>
<French>Renommer</French>
<German>Umbenennen</German>
<Polish>Zmień nazwę</Polish>
<Japanese>改名</Japanese>
<Italian>Rinomina</Italian>
<Korean>이름바꾸기</Korean>
<Chinese>重新命名</Chinese>
<Chinesesimp>重新命名</Chinesesimp>
<Russian>Переименовать</Russian>
<Portuguese>Renomear</Portuguese>
<Czech>Přejmenovat</Czech>
<Turkish>Yeniden adlandır</Turkish>
</Key>
<Key ID="STR_ACE_Arsenal_buttonRenameTooltip">
<English>Rename the selected loadout</English>
<Spanish>Renombrar el equipamiento seleccionado</Spanish>
Expand Down
4 changes: 2 additions & 2 deletions addons/arsenal/ui/RscAttributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1005,8 +1005,8 @@ class GVAR(loadoutsDisplay) {
class buttonRename: buttonSave {
idc = IDC_buttonRename;
x = QUOTE(32.5 * GRID_W);
text= CSTRING(buttonRenameText);
tooltip= CSTRING(buttonRenameTooltip);
text = ECSTRING(common,rename);
tooltip = CSTRING(buttonRenameTooltip);
onButtonClick = QUOTE([ARR_2(ctrlParent (_this select 0), _this select 0)] call FUNC(buttonLoadoutsRename));
};
class buttonLoad: buttonSave {
Expand Down
12 changes: 12 additions & 0 deletions addons/cargo/CfgEden.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ class Cfg3DEN {
class AttributeCategories {
class ace_attributes {
class Attributes {
class GVAR(customName) {
displayName = CSTRING(customName_edenName);
tooltip = CSTRING(customName_edenDesc);
property = QGVAR(customName);
control = "Edit";

expression = QUOTE(_this setVariable [ARR_3(QQGVAR(customName), _value, true)];);
defaultValue = "''";

condition = "objectHasInventoryCargo - objectVehicle";
typeName = "STRING";
};
class GVAR(space) {
displayName = CSTRING(space_edenName);
tooltip = CSTRING(space_edenDesc);
Expand Down
2 changes: 2 additions & 0 deletions addons/cargo/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ PREP(addCargoVehiclesActions);
PREP(canLoadItemIn);
PREP(canUnloadItem);
PREP(getCargoSpaceLeft);
PREP(getNameItem);
PREP(getSizeItem);
PREP(handleDeleted);
PREP(handleDestroyed);
Expand All @@ -13,6 +14,7 @@ PREP(moduleSettings);
PREP(onMenuOpen);
PREP(paradropItem);
PREP(removeCargoItem);
PREP(renameObject);
PREP(setSize);
PREP(setSpace);
PREP(startLoadIn);
Expand Down
72 changes: 45 additions & 27 deletions addons/cargo/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

// Show hint as feedback
private _hint = [LSTRING(LoadingFailed), LSTRING(LoadedItem)] select _loaded;
private _itemName = getText (configOf _item >> "displayName");
private _itemName = [_item, true] call FUNC(getNameItem);
private _vehicleName = getText (configOf _vehicle >> "displayName");

[[_hint, _itemName, _vehicleName], 3.0] call EFUNC(common,displayTextStructured);
Expand All @@ -38,11 +38,9 @@

private _unloaded = [_item, _vehicle, _unloader] call FUNC(unloadItem); //returns true if sucessful

private _itemClass = if (_item isEqualType "") then {_item} else {typeOf _item};

// Show hint as feedback
private _hint = [LSTRING(UnloadingFailed), LSTRING(UnloadedItem)] select _unloaded;
private _itemName = getText (configFile >> "CfgVehicles" >> _itemClass >> "displayName");
private _itemName = [_item, true] call FUNC(getNameItem);
private _vehicleName = getText (configOf _vehicle >> "displayName");

[[_hint, _itemName, _vehicleName], 3.0] call EFUNC(common,displayTextStructured);
Expand Down Expand Up @@ -89,28 +87,45 @@ GVAR(vehicleAction) = [
}
] call EFUNC(interact_menu,createAction);

GVAR(objectAction) = [
QGVAR(load), localize LSTRING(loadObject), "a3\ui_f\data\IGUI\Cfg\Actions\loadVehicle_ca.paa",
{
params ["_target", "_player"];
[_player, _target] call FUNC(startLoadIn);
},
{
//IGNORE_PRIVATE_WARNING ["_target", "_player"];
GVAR(enable) &&
{(_target getVariable [QGVAR(canLoad), getNumber (configOf _target >> QGVAR(canLoad))]) in [true, 1]} &&
{locked _target < 2} &&
{alive _target} &&
{[_player, _target, ["isNotSwimming"]] call EFUNC(common,canInteractWith)} &&
{((nearestObjects [_target, GVAR(cargoHolderTypes), (MAX_LOAD_DISTANCE + 10)]) findIf {
private _hasCargoConfig = 1 == getNumber (configOf _x >> QGVAR(hasCargo));
private _hasCargoPublic = _x getVariable [QGVAR(hasCargo), false];
(_hasCargoConfig || {_hasCargoPublic}) && {_x != _target} && {alive _x} && {locked _x < 2} &&
{([_target, _x] call EFUNC(interaction,getInteractionDistance)) < MAX_LOAD_DISTANCE}
}) > -1}
},
LINKFUNC(addCargoVehiclesActions)
] call EFUNC(interact_menu,createAction);
GVAR(objectActions) = [
[QGVAR(renameObject), LELSTRING(common,rename), "", //TODO: add icon, maybe a pencil couldn't find it before.
{
GVAR(interactionVehicle) = _target;
createDialog QGVAR(renameMenu);
},
{
//IGNORE_PRIVATE_WARNING ["_target", "_player"];
GVAR(enable) &&
{GVAR(enableRename)} &&
{(_target getVariable [QGVAR(canLoad), getNumber (configOf _target >> QGVAR(canLoad))]) in [true, 1]} &&
{alive _target} &&
{[_player, _target, ["isNotSwimming"]] call EFUNC(common,canInteractWith)} &&
{!((typeOf _target) in ["ACE_Wheel", "ACE_Track"])} && // Exclude Wheel and Track
{!(_target iskindOf "Land_CanisterFuel_F")} // Exclude Fuel Canisters
}
] call EFUNC(interact_menu,createAction),
[QGVAR(load), localize LSTRING(loadObject), "a3\ui_f\data\IGUI\Cfg\Actions\loadVehicle_ca.paa",
{
params ["_target", "_player"];
[_player, _target] call FUNC(startLoadIn);
},
{
//IGNORE_PRIVATE_WARNING ["_target", "_player"];
GVAR(enable) &&
{(_target getVariable [QGVAR(canLoad), getNumber (configOf _target >> QGVAR(canLoad))]) in [true, 1]} &&
{locked _target < 2} &&
{alive _target} &&
{[_player, _target, ["isNotSwimming"]] call EFUNC(common,canInteractWith)} &&
{((nearestObjects [_target, GVAR(cargoHolderTypes), (MAX_LOAD_DISTANCE + 10)]) findIf {
private _hasCargoConfig = 1 == getNumber (configOf _x >> QGVAR(hasCargo));
private _hasCargoPublic = _x getVariable [QGVAR(hasCargo), false];
(_hasCargoConfig || {_hasCargoPublic}) && {_x != _target} && {alive _x} && {locked _x < 2} &&
{([_target, _x] call EFUNC(interaction,getInteractionDistance)) < MAX_LOAD_DISTANCE}
}) > -1}
},
LINKFUNC(addCargoVehiclesActions)
] call EFUNC(interact_menu,createAction)
];

// find all remaining configured classes and init them, see XEH_preStart.sqf
private _vehicleClassesAddAction = call (uiNamespace getVariable [QGVAR(initializedVehicleClasses), {[]}]);
Expand All @@ -121,7 +136,10 @@ GVAR(initializedVehicleClasses) append _vehicleClassesAddAction;

private _objectClassesAddAction = call (uiNamespace getVariable [QGVAR(initializedItemClasses), {[]}]);
{
[_x, 0, ["ACE_MainActions"], GVAR(objectAction)] call EFUNC(interact_menu,addActionToClass);
private _objectClass = _x;
{
[_objectClass, 0, ["ACE_MainActions"], _x] call EFUNC(interact_menu,addActionToClass);
} forEach GVAR(objectActions);
} forEach _objectClassesAddAction;
GVAR(initializedItemClasses) append _objectClassesAddAction;

Expand Down
1 change: 1 addition & 0 deletions addons/cargo/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ class CfgPatches {
#include "CfgEventHandlers.hpp"
#include "CfgVehicles.hpp"
#include "menu.hpp"
#include "renameMenu.hpp"
32 changes: 32 additions & 0 deletions addons/cargo/functions/fnc_getNameItem.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "script_component.hpp"
/*
* Author: JasperRab
* Gets the name of the item, and alternatively the custom name if requested and available.
*
* Arguments:
* 0: Target <OBJECT>
* 1: Add custom name part <BOOL> (default: false)
*
* Return Value:
* Item Name <STRING>
*
* Example:
* [crate_7] call ace_cargo_fnc_getNameItem
*
* Public: Yes
*/

params ["_object", ["_addCustomPart", false]];

private _class = if (_object isEqualType "") then {_object} else {typeOf _object};
private _displayName = getText (configFile >> "CfgVehicles" >> _class >> "displayName");

if (_addCustomPart && {!(_object isEqualType "")}) then {
private _customPart = _object getVariable [QGVAR(customName), ""];

if (_customPart isNotEqualTo "") then {
_displayName = _displayName + " [" + _customPart + "]";
};
};

_displayName
6 changes: 4 additions & 2 deletions addons/cargo/functions/fnc_initObject.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ if (_object getVariable [QGVAR(initObject),false]) exitWith {};
if (_canLoadConfig) then {
GVAR(initializedItemClasses) pushBack _type;
TRACE_1("Adding load cargo action to class", _type);
[_type, 0, ["ACE_MainActions"], GVAR(objectAction)] call EFUNC(interact_menu,addActionToClass);
[_type, 0, ["ACE_MainActions"], GVAR(objectActions) select 0] call EFUNC(interact_menu,addActionToClass);
[_type, 0, ["ACE_MainActions"], GVAR(objectActions) select 1] call EFUNC(interact_menu,addActionToClass);
PabstMirror marked this conversation as resolved.
Show resolved Hide resolved
} else {
_object setVariable [QGVAR(initObject),true];
TRACE_1("Adding load cargo action to object", _object);
[_object, 0, ["ACE_MainActions"], GVAR(objectAction)] call EFUNC(interact_menu,addActionToObject);
[_object, 0, ["ACE_MainActions"], GVAR(objectActions) select 0] call EFUNC(interact_menu,addActionToClass);
[_object, 0, ["ACE_MainActions"], GVAR(objectActions) select 1] call EFUNC(interact_menu,addActionToClass);
};
2 changes: 1 addition & 1 deletion addons/cargo/functions/fnc_onMenuOpen.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ if (GVAR(interactionParadrop)) then {
lbClear _ctrl;
{
private _class = if (_x isEqualType "") then {_x} else {typeOf _x};
private _displayName = getText (configfile >> "CfgVehicles" >> _class >> "displayName");
private _displayName = [_x, true] call FUNC(getNameItem);
if (GVAR(interactionParadrop)) then {
_ctrl lbAdd format ["%1 (%2s)", _displayName, GVAR(paradropTimeCoefficent) * ([_class] call FUNC(getSizeItem))];
} else {
Expand Down
2 changes: 1 addition & 1 deletion addons/cargo/functions/fnc_paradropItem.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ if (_showHint) then {
[
[
LSTRING(UnloadedItem),
getText (configOf _object >> "displayName"),
[_itemObject, true] call FUNC(getNameItem),
getText (configOf _vehicle >> "displayName")
],
3
Expand Down
27 changes: 27 additions & 0 deletions addons/cargo/functions/fnc_renameObject.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "script_component.hpp"
/*
* Author: JasperRab
* Renames object.
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* [] call ace_cargo_fnc_renameObject
*
* Public: Yes
*/

private _display = uiNamespace getVariable QGVAR(menuDisplay);
if (isNil "_display") exitWith {};

private _ctrlEditText = ctrlText 100;
if (_ctrlEditText isEqualTo "") then { // custom name has been removed
[LSTRING(clearedCustomName), 3] call EFUNC(common,displayTextStructured);
} else {
[[LSTRING(renamedObject), _ctrlEditText], 3] call EFUNC(common,displayTextStructured);
};
GVAR(interactionVehicle) setVariable [QGVAR(customName), _ctrlEditText, true];
PabstMirror marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 3 additions & 4 deletions addons/cargo/functions/fnc_startLoadIn.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ if ([_object, _vehicle] call FUNC(canLoadItemIn)) then {
GVAR(loadTimeCoefficient) * _size,
[_object, _vehicle],
{
TRACE_1("load finish",_this);
TRACE_1("load finish",_this);
[objNull, _this select 0 select 0, true] call EFUNC(common,claim);
["ace_loadCargo", _this select 0] call CBA_fnc_localEvent;
},
{
TRACE_1("load fail",_this);
[objNull, _this select 0 select 0, true] call EFUNC(common,claim)
[objNull, _this select 0 select 0, true] call EFUNC(common,claim);
},
localize LSTRING(LoadingItem),
{
Expand All @@ -60,8 +60,7 @@ if ([_object, _vehicle] call FUNC(canLoadItemIn)) then {
] call EFUNC(common,progressBar);
_return = true;
} else {
private _displayName = getText (configOf _object >> "displayName");

private _displayName = [_object, true] call FUNC(getNameItem);
[[LSTRING(LoadingFailed), _displayName], 3] call EFUNC(common,displayTextStructured);
};

Expand Down
5 changes: 2 additions & 3 deletions addons/cargo/functions/fnc_startUnload.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ if ([_item, GVAR(interactionVehicle), ACE_player] call FUNC(canUnloadItem)) then
localize LSTRING(UnloadingItem),
{
(_this select 0) params ["_item", "_target", "_player"];

(alive _target)
&& {locked _target < 2}
&& {([_player, _target] call EFUNC(interaction,getInteractionDistance)) < MAX_LOAD_DISTANCE}
Expand All @@ -86,8 +86,7 @@ if ([_item, GVAR(interactionVehicle), ACE_player] call FUNC(canUnloadItem)) then
["isNotSwimming"]
] call EFUNC(common,progressBar);
} else {
private _itemClass = if (_item isEqualType "") then {_item} else {typeOf _item};
private _displayName = getText (configFile >> "CfgVehicles" >> _itemClass >> "displayName");
private _displayName = [_item, true] call FUNC(getNameItem);

[[LSTRING(UnloadingFailed), _displayName], 3] call EFUNC(common,displayTextStructured);
};
9 changes: 9 additions & 0 deletions addons/cargo/initSettings.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@
false,
{[QGVAR(openAfterUnload), _this, true] call EFUNC(common,cbaSettings_settingChanged)}
] call CBA_fnc_addSetting;

[
QGVAR(enableRename), "CHECKBOX",
[LSTRING(ModuleSettings_enableRename), LSTRING(ModuleSettings_enableRename_Description)],
[LELSTRING(OptionsMenu,CategoryLogistics), LLSTRING(openMenu)],
true,
false,
{[QGVAR(enableRename), _this, true] call EFUNC(common,cbaSettings_settingChanged)}
] call CBA_fnc_addSetting;
Loading