-
Notifications
You must be signed in to change notification settings - Fork 739
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2243 from jonpas/repairHitpointStrings
Improved Repair Hitpoint String Localization
- Loading branch information
Showing
6 changed files
with
162 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Author: Jonpas | ||
* Finds the localized string of the given hitpoint name or uses default text if none found. | ||
* | ||
* 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]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters