Skip to content

Commit

Permalink
Merge pull request #2243 from jonpas/repairHitpointStrings
Browse files Browse the repository at this point in the history
Improved Repair Hitpoint String Localization
  • Loading branch information
thojkooi committed Aug 26, 2015
2 parents f7679b4 + 6a6c500 commit 3db981a
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 113 deletions.
1 change: 1 addition & 0 deletions addons/repair/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ PREP(doRepair);
PREP(doRepairTrack);
PREP(doReplaceTrack);
PREP(doReplaceWheel);
PREP(getHitPointString);
PREP(getPostRepairDamage);
PREP(getWheelHitPointsWithSelections);
PREP(hasItems);
Expand Down
22 changes: 12 additions & 10 deletions addons/repair/functions/fnc_addRepairActions.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ if (_type in _initializedClasses) exitWith {};
([_vehicle] call FUNC(getWheelHitPointsWithSelections)) params ["_wheelHitPoints", "_wheelHitPointSelections"];


private ["_hitPointsAddedNames", "_hitPointsAddedStrings", "_hitPointsAddedAmount"];
_hitPointsAddedNames = [];
_hitPointsAddedStrings = [];
_hitPointsAddedAmount = [];

// add repair events to this vehicle class
{
if (_x in _wheelHitPoints) then {
Expand All @@ -50,7 +55,7 @@ if (_type in _initializedClasses) exitWith {};

// remove wheel action
_name = format ["Remove_%1", _x];
_text = localize "STR_ACE_Repair_RemoveWheel";
_text = localize LSTRING(RemoveWheel);

_condition = {[_this select 1, _this select 0, _this select 2 select 0, "RemoveWheel"] call DFUNC(canRepair)};
_statement = {[_this select 1, _this select 0, _this select 2 select 0, "RemoveWheel"] call DFUNC(repair)};
Expand Down Expand Up @@ -97,18 +102,15 @@ if (_type in _initializedClasses) exitWith {};
if (isText (configFile >> "CfgVehicles" >> _type >> "HitPoints" >> _x >> "depends")) exitWith {};

// add misc repair action

private ["_name", "_text", "_icon", "_selection", "_customSelectionsConfig", "_currentHitpoint", "_condition", "_statement"];
private ["_name", "_icon", "_selection", "_condition", "_statement"];

_name = format ["Repair_%1", _x];

_text = format ["STR_ACE_Repair_%1", _x];

if (isLocalized _text) then {
_text = format [localize LSTRING(RepairHitpoint), localize _text];
} else {
_text = format [localize LSTRING(RepairHitpoint), _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";

Expand Down
12 changes: 6 additions & 6 deletions addons/repair/functions/fnc_doRepair.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ if (isArray _hitpointGroupConfig) then {

// display text message if enabled
if (GVAR(DisplayTextOnRepair)) then {
_text = format ["STR_ACE_Repair_%1", _hitPoint];
private ["_textLocalized", "_textDefault"];

if (isLocalized _text) then {
_text = format [localize ([LSTRING(RepairedHitPointFully), LSTRING(RepairedHitPointPartially)] select (_hitPointDamage > 0)), localize _text];
} else {
_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 changes: 89 additions & 0 deletions addons/repair/functions/fnc_getHitPointString.sqf
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]]
10 changes: 3 additions & 7 deletions addons/repair/functions/fnc_repair.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,10 @@ _repairTime = if (isNumber (_config >> "repairingTime")) then {
0;
};

private ["_text", "_processText"];
private ["_processText"];
// Find localized string
_processText = getText (_config >> "displayNameProgress");
_text = format ["STR_ACE_Repair_%1", _hitPoint];
if (isLocalized _text) then {
_text = format [_processText, localize _text];
} else {
_text = _processText;
};
([_hitPoint, _processText, _processText] call FUNC(getHitPointString)) params ["_text"];

// Start repair
[
Expand Down
141 changes: 51 additions & 90 deletions addons/repair/stringtable.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<!-- Edited with tabler - 2014-12-21 -->
<Project name="ACE">
<Package name="repair">
Expand Down Expand Up @@ -118,18 +118,6 @@
<English>Who can perform a full repair on a vehicle?</English>
<Polish>Kto może przeprowadzić pełną naprawę pojazdu?</Polish>
</Key>
<Key ID="STR_ACE_Repair_RepairHitpoint">
<English>Repair %1</English>
<German>Reparieren %1</German>
<Spanish>Reparación %1</Spanish>
<French>Réparer %1</French>
<Polish>Napraw %1</Polish>
<Czech>Opravit %1</Czech>
<Portuguese>Reparar %1</Portuguese>
<Italian>Ripara %1</Italian>
<Hungarian>Szerelés %1</Hungarian>
<Russian>Ремонт %1</Russian>
</Key>
<Key ID="STR_ACE_Repair_Repair">
<English>Repair &gt;&gt;</English>
<German>Reparieren &gt;&gt;</German>
Expand Down Expand Up @@ -242,6 +230,15 @@
<Hungarian>Motor</Hungarian>
<Russian>Двигатель</Russian>
</Key>
<Key ID="STR_ACE_Repair_HitHStabilizerL1">
<English>Left Horizontal Stabilizer</English>
</Key>
<Key ID="STR_ACE_Repair_HitHStabilizerR1">
<English>Right Horizontal Stabilizer</English>
</Key>
<Key ID="STR_ACE_Repair_HitVStabilizer1">
<English>Vertical Stabilizer</English>
</Key>
<Key ID="STR_ACE_Repair_HitFuel">
<English>Fuel Tank</English>
<German>Tank</German>
Expand All @@ -254,15 +251,36 @@
<Hungarian>Üzemanyagtank</Hungarian>
<Russian>Топливный бак</Russian>
</Key>
<Key ID="STR_ACE_Repair_HitTransmission">
<English>Transmission</English>
</Key>
<Key ID="STR_ACE_Repair_HitGear">
<English>Gear</English>
</Key>
<Key ID="STR_ACE_Repair_HitStarter">
<English>Starter</English>
</Key>
<Key ID="STR_ACE_Repair_HitTail">
<English>Tail</English>
</Key>
<Key ID="STR_ACE_Repair_HitPilotTube">
<English>Pilot Tube</English>
</Key>
<Key ID="STR_ACE_Repair_HitStaticPort">
<English>Static Port</English>
</Key>
<Key ID="STR_ACE_Repair_HitAmmo">
<English>Ammo</English>
</Key>
<Key ID="STR_ACE_Repair_HitTurret">
<English>Main Turret</English>
<English>Turret</English>
<German>Turm</German>
<Spanish>Torreta príncipal</Spanish>
<Spanish>Torreta</Spanish>
<French>Tourelle</French>
<Polish>Wieżyczka</Polish>
<Czech>Hlavní Věž</Czech>
<Portuguese>Torre principal</Portuguese>
<Italian>Torretta principale</Italian>
<Czech>Věž</Czech>
<Portuguese>Torre</Portuguese>
<Italian>Torretta</Italian>
<Hungarian>Lövegtorony</Hungarian>
<Russian>Башню</Russian>
</Key>
Expand All @@ -278,6 +296,9 @@
<Hungarian>Ágyú</Hungarian>
<Russian>Пушку</Russian>
</Key>
<Key ID="STR_ACE_Repair_HitMissiles">
<English>Missiles</English>
</Key>
<Key ID="STR_ACE_Repair_HitLTrack">
<English>Left Track</English>
<German>Linke Kette</German>
Expand Down Expand Up @@ -463,77 +484,17 @@
<Hungarian>Bal szélvédő</Hungarian>
<Russian>Стекло (слава)</Russian>
</Key>
<Key ID="STR_ACE_Repair_HitGlass1">
<English>Glass 1</English>
<German>Scheibe 1</German>
<Spanish>Ventana 1</Spanish>
<French>Vitre 1</French>
<Polish>Szyba 1</Polish>
<Czech>Sklo 1</Czech>
<Portuguese>Vidro 1</Portuguese>
<Italian>Vetro 1</Italian>
<Hungarian>Üveg 1</Hungarian>
<Russian>Стекло 1</Russian>
</Key>
<Key ID="STR_ACE_Repair_HitGlass2">
<English>Glass 2</English>
<German>Scheibe 2</German>
<Spanish>Ventana 2</Spanish>
<French>Vitre 2</French>
<Polish>Szyba 2</Polish>
<Czech>Sklo 2</Czech>
<Portuguese>Vidro 2</Portuguese>
<Italian>Vetro 2</Italian>
<Hungarian>Üveg 2</Hungarian>
<Russian>Стекло 2</Russian>
</Key>
<Key ID="STR_ACE_Repair_HitGlass3">
<English>Glass 3</English>
<German>Scheibe 3</German>
<Spanish>Ventana 3</Spanish>
<French>Vitre 3</French>
<Polish>Szyba 3</Polish>
<Czech>Sklo 3</Czech>
<Portuguese>Vidro 3</Portuguese>
<Italian>Vetro 3</Italian>
<Hungarian>Üveg 3</Hungarian>
<Russian>Стекло 3</Russian>
</Key>
<Key ID="STR_ACE_Repair_HitGlass4">
<English>Glass 4</English>
<German>Scheibe 4</German>
<Spanish>Ventana 4</Spanish>
<French>Vitre 4</French>
<Polish>Szyba 4</Polish>
<Czech>Sklo 4</Czech>
<Portuguese>Vidro 4</Portuguese>
<Italian>Vetro 4</Italian>
<Hungarian>Üveg 4</Hungarian>
<Russian>Стекло 4</Russian>
</Key>
<Key ID="STR_ACE_Repair_HitGlass5">
<English>Glass 5</English>
<German>Scheibe 5</German>
<Spanish>Ventana 5</Spanish>
<French>Vitre 5</French>
<Polish>Szyba 5</Polish>
<Czech>Sklo 5</Czech>
<Portuguese>Vidro 5</Portuguese>
<Italian>Vetro 5</Italian>
<Hungarian>Üveg 5</Hungarian>
<Russian>Стекло 5</Russian>
</Key>
<Key ID="STR_ACE_Repair_HitGlass6">
<English>Glass 6</English>
<German>Scheibe 6</German>
<Spanish>Ventana 6</Spanish>
<French>Vitre 6</French>
<Polish>Szyba 6</Polish>
<Czech>Sklo 6</Czech>
<Portuguese>Vidro 6</Portuguese>
<Italian>Vetro 6</Italian>
<Hungarian>Üveg 6</Hungarian>
<Russian>Стекло 6</Russian>
<Key ID="STR_ACE_Repair_HitGlass">
<English>Glass</English>
<German>Scheibe</German>
<Spanish>Ventana</Spanish>
<French>Vitre</French>
<Polish>Szyba</Polish>
<Czech>Sklo</Czech>
<Portuguese>Vidro</Portuguese>
<Italian>Vetro</Italian>
<Hungarian>Üveg</Hungarian>
<Russian>Стекло</Russian>
</Key>
<Key ID="STR_ACE_Repair_moduleName">
<English>Repair Settings</English>
Expand Down Expand Up @@ -696,4 +657,4 @@
<Polish>Przydziel klasę budynku naprawczego do jednego lub kilku budynków.</Polish>
</Key>
</Package>
</Project>
</Project>

0 comments on commit 3db981a

Please sign in to comment.