mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Consolidated into 1 function
This commit is contained in:
parent
7f175bad5f
commit
9718883599
@ -15,6 +15,7 @@ PREP(doRepair);
|
||||
PREP(doRepairTrack);
|
||||
PREP(doReplaceTrack);
|
||||
PREP(doReplaceWheel);
|
||||
PREP(getHitPointString);
|
||||
PREP(getPostRepairDamage);
|
||||
PREP(getWheelHitPointsWithSelections);
|
||||
PREP(hasItems);
|
||||
|
@ -88,60 +88,15 @@ _hitPointsAddedAmount = [];
|
||||
|
||||
// add misc repair action
|
||||
|
||||
private ["_name", "_text", "_icon", "_selection", "_condition", "_statement", "_toFind", "_hitPointFoundIndex", "_combinedString"];
|
||||
private ["_name", "_icon", "_selection", "_condition", "_statement"];
|
||||
|
||||
_name = format ["Repair_%1", _x];
|
||||
|
||||
|
||||
// Prepare first part of the string from stringtable
|
||||
_text = LSTRING(Hit);
|
||||
|
||||
// Remove "Hit" from hitpoint name if one exists
|
||||
_toFind = if (_x find "Hit" == 0) then {
|
||||
[_x, 3] call CBA_fnc_substr
|
||||
} else {
|
||||
_x
|
||||
};
|
||||
|
||||
// Loop through always shorter part of the hitpoint name to find the string from stringtable or use an already found one
|
||||
for "_i" from 0 to (count _x) do {
|
||||
// Loop through already added hitpoints and save index
|
||||
_hitPointFoundIndex = -1;
|
||||
{
|
||||
if (_x == _toFind) exitWith {
|
||||
_hitPointFoundIndex = _forEachIndex;
|
||||
};
|
||||
} forEach _hitPointsAddedNames;
|
||||
|
||||
// Use already added hitpoint if one found above and numerize
|
||||
if (_hitPointFoundIndex != -1) exitWith {
|
||||
_text = localize (_hitPointsAddedStrings select _hitPointFoundIndex) + " " + str(_hitPointsAddedAmount select _hitPointFoundIndex);
|
||||
_hitPointsAddedAmount set [_hitPointFoundIndex, (_hitPointsAddedAmount select _hitPointFoundIndex) + 1]; // Set amount
|
||||
TRACE_2("Same hitpoint found",_toFind,_hitPointsAddedNames);
|
||||
};
|
||||
|
||||
// Localize if localization found and save all variables for possible hitpoints of same type
|
||||
_combinedString = _text + _toFind;
|
||||
if (isLocalized _combinedString) exitWith {
|
||||
// Add hitpoint to the list
|
||||
_hitPointsAddedNames pushBack _toFind;
|
||||
_hitPointsAddedStrings pushBack _combinedString;
|
||||
_hitPointsAddedAmount pushBack 2;
|
||||
|
||||
// Localize text
|
||||
_text = localize _combinedString;
|
||||
TRACE_1("Hitpoint localized",_toFind);
|
||||
};
|
||||
|
||||
// Cut off one character
|
||||
_toFind = [_toFind, 0, count _toFind - 1] call CBA_fnc_substr;
|
||||
};
|
||||
|
||||
// Display part name directly if no string is found in stringtable
|
||||
if (_text == LSTRING(Hit)) then {
|
||||
_text = _x;
|
||||
};
|
||||
|
||||
// Find localized string and track those added for numerization
|
||||
([_x, "%1", _x, [_hitPointsAddedNames, _hitPointsAddedStrings, _hitPointsAddedAmount]] call FUNC(getHitPointString)) params ["_text", "_trackArray"];
|
||||
_hitPointsAddedNames = _trackArray select 0;
|
||||
_hitPointsAddedStrings = _trackArray select 1;
|
||||
_hitPointsAddedAmount = _trackArray select 2;
|
||||
|
||||
_icon = "A3\ui_f\data\igui\cfg\actions\repair_ca.paa";
|
||||
_selection = "";
|
||||
|
@ -33,34 +33,12 @@ _hitPointDamage = _hitPointDamage max ([_unit] call FUNC(getPostRepairDamage));
|
||||
|
||||
// display text message if enabled
|
||||
if (GVAR(DisplayTextOnRepair)) then {
|
||||
private ["_text", "_toFind", "_combinedString"];
|
||||
private ["_textLocalized", "_textDefault"];
|
||||
|
||||
// Prepare first part of the string from stringtable
|
||||
_text = LSTRING(Hit);
|
||||
|
||||
// Remove "Hit" from hitpoint name if one exists
|
||||
_toFind = if (_x find "Hit" == 0) then {
|
||||
[_x, 3] call CBA_fnc_substr
|
||||
} else {
|
||||
_x
|
||||
};
|
||||
|
||||
// Loop through always shorter part of the hitpoint name to find the string from stringtable
|
||||
for "_i" from 0 to (count _x) do {
|
||||
// Localize if localization found
|
||||
_combinedString = _text + _toFind;
|
||||
if (isLocalized _combinedString) exitWith {
|
||||
_text = format [localize ([LSTRING(RepairedHitPointFully), LSTRING(RepairedHitPointPartially)] select (_hitPointDamage > 0)), localize _combinedString];
|
||||
};
|
||||
|
||||
// Cut off one character
|
||||
_toFind = [_toFind, 0, count _toFind - 1] call CBA_fnc_substr;
|
||||
};
|
||||
|
||||
// Don't display part name if no string is found in stringtable
|
||||
if (_text == LSTRING(Hit)) then {
|
||||
_text = localize ([LSTRING(RepairedFully), LSTRING(RepairedPartially)] select (_hitPointDamage > 0));
|
||||
};
|
||||
// Find localized string
|
||||
_textLocalized = localize ([LSTRING(RepairedHitPointFully), LSTRING(RepairedHitPointPartially)] select (_hitPointDamage > 0));
|
||||
_textDefault = localize ([LSTRING(RepairedFully), LSTRING(RepairedPartially)] select (_hitPointDamage > 0));
|
||||
([_hitPoint, _textLocalized, _textDefault] call FUNC(getHitPointString)) params ["_text"];
|
||||
|
||||
// Display text
|
||||
[_text] call EFUNC(common,displayTextStructured);
|
||||
|
89
addons/repair/functions/fnc_getHitPointString.sqf
Normal file
89
addons/repair/functions/fnc_getHitPointString.sqf
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Author: Jonpas
|
||||
* Finds the localized string of the given hitpoint name.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Hitpoint <STRING>
|
||||
* 1: Localized Text <STRING>
|
||||
* 2: Default Text <STRING>
|
||||
* 3: Track Added Hitpoints <BOOL> (default: false)
|
||||
*
|
||||
* Return Value:
|
||||
* 0: Text
|
||||
* 1: Added Hitpoint (default: [])
|
||||
*
|
||||
* Example:
|
||||
* [unit, vehicle, "hitpoint"] call ace_repair_fnc_getHitPointString
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_track", "_trackNames", "_trackStrings", "_trackAmount", "_text", "_toFind", "_trackIndex", "_combinedString"];
|
||||
params ["_hitPoint", "_textLocalized", "_textDefault", ["_trackArray", []]];
|
||||
|
||||
_track = if (count _trackArray > 0) then {true} else {false};
|
||||
_trackNames = [];
|
||||
_trackStrings = [];
|
||||
_trackAmount = [];
|
||||
|
||||
if (_track) then {
|
||||
_trackNames = _trackArray select 0;
|
||||
_trackStrings = _trackArray select 1;
|
||||
_trackAmount = _trackArray select 2;
|
||||
};
|
||||
|
||||
// Prepare first part of the string from stringtable
|
||||
_text = LSTRING(Hit);
|
||||
|
||||
// Remove "Hit" from hitpoint name if one exists
|
||||
_toFind = if (_hitPoint find "Hit" == 0) then {
|
||||
[_hitPoint, 3] call CBA_fnc_substr
|
||||
} else {
|
||||
_hitPoint
|
||||
};
|
||||
|
||||
// Loop through always shorter part of the hitpoint name to find the string from stringtable
|
||||
for "_i" from 0 to (count _hitPoint) do {
|
||||
if (_track) then {
|
||||
// Loop through already added hitpoints and save index
|
||||
_trackIndex = -1;
|
||||
{
|
||||
if (_x == _toFind) exitWith {
|
||||
_trackIndex = _forEachIndex;
|
||||
};
|
||||
} forEach _trackNames;
|
||||
|
||||
// Use already added hitpoint if one found above and numerize
|
||||
if (_trackIndex != -1) exitWith {
|
||||
_text = localize (_trackStrings select _trackIndex) + " " + str(_trackAmount select _trackIndex);
|
||||
_trackAmount set [_trackIndex, (_trackAmount select _trackIndex) + 1]; // Set amount
|
||||
TRACE_2("Same hitpoint found",_toFind,_trackNames);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
// Localize if localization found
|
||||
_combinedString = _text + _toFind;
|
||||
if (isLocalized _combinedString) exitWith {
|
||||
_text = format [_textLocalized, localize _combinedString];
|
||||
TRACE_1("Hitpoint localized",_toFind);
|
||||
|
||||
if (_track) then {
|
||||
// Add hitpoint to the list
|
||||
_trackNames pushBack _toFind;
|
||||
_trackStrings pushBack _combinedString;
|
||||
_trackAmount pushBack 2;
|
||||
};
|
||||
};
|
||||
|
||||
// Cut off one character
|
||||
_toFind = [_toFind, 0, count _toFind - 1] call CBA_fnc_substr;
|
||||
};
|
||||
|
||||
// Don't display part name if no string is found in stringtable
|
||||
if (_text == LSTRING(Hit)) then {
|
||||
_text = _textDefault;
|
||||
};
|
||||
|
||||
[_text, [_trackNames, _trackStrings, _trackAmount]]
|
@ -164,36 +164,10 @@ _repairTime = if (isNumber (_config >> "repairingTime")) then {
|
||||
0;
|
||||
};
|
||||
|
||||
private ["_processText", "_text", "_toFind", "_combinedString"];
|
||||
private ["_processText"];
|
||||
// Find localized string
|
||||
_processText = getText (_config >> "displayNameProgress");
|
||||
|
||||
// Prepare first part of the string from stringtable
|
||||
_text = LSTRING(Hit);
|
||||
|
||||
// Remove "Hit" from hitpoint name if one exists
|
||||
_toFind = if (_x find "Hit" == 0) then {
|
||||
[_x, 3] call CBA_fnc_substr
|
||||
} else {
|
||||
_x
|
||||
};
|
||||
|
||||
// Loop through always shorter part of the hitpoint name to find the string from stringtable
|
||||
for "_i" from 0 to (count _x) do {
|
||||
// Localize if localization found
|
||||
_combinedString = _text + _toFind;
|
||||
if (isLocalized _combinedString) exitWith {
|
||||
_text = format [_processText, localize _combinedString];
|
||||
};
|
||||
|
||||
// Cut off one character
|
||||
_toFind = [_toFind, 0, count _toFind - 1] call CBA_fnc_substr;
|
||||
};
|
||||
|
||||
// Don't display part name if no string is found in stringtable
|
||||
if (_text == LSTRING(Hit)) then {
|
||||
_text = _processText;
|
||||
};
|
||||
|
||||
([_hitPoint, _processText, _processText] call FUNC(getHitPointString)) params ["_text"];
|
||||
|
||||
// Start repair
|
||||
[
|
||||
|
Loading…
Reference in New Issue
Block a user