Add Lua API function SetAmmoTexts (see issue 82)
authorWuzzy <almikes@aol.com>
Mon, 09 May 2016 22:49:31 +0200
changeset 11939 c7ec309cd685
parent 11938 35ec1edd66a2
child 11940 156f1866b8bd
Add Lua API function SetAmmoTexts (see issue #82)
hedgewars/uAmmos.pas
hedgewars/uGearsHedgehog.pas
hedgewars/uScript.pas
hedgewars/uStore.pas
hedgewars/uVariables.pas
hedgewars/uWorld.pas
--- a/hedgewars/uAmmos.pas	Sat Nov 19 21:17:48 2016 +0100
+++ b/hedgewars/uAmmos.pas	Mon May 09 22:49:31 2016 +0200
@@ -397,7 +397,10 @@
 
     with CurWeapon^ do
         begin
-        s:= trammo[Ammoz[AmmoType].NameId];
+        if length(trluaammo[Ammoz[AmmoType].NameId]) > 0 then
+            s:= trluaammo[Ammoz[AmmoType].NameId]
+        else
+            s:= trammo[Ammoz[AmmoType].NameId];
         if (Count <> AMMO_INFINITE) and (not (Hedgehog.Team^.ExtDriven or (Hedgehog.BotLevel > 0))) then
             s:= s + ansistring(' (' + IntToStr(Count) + ')');
         if (Propz and ammoprop_Timerable) <> 0 then
--- a/hedgewars/uGearsHedgehog.pas	Sat Nov 19 21:17:48 2016 +0100
+++ b/hedgewars/uGearsHedgehog.pas	Mon May 09 22:49:31 2016 +0200
@@ -663,6 +663,7 @@
 
 procedure AddPickup(HH: THedgehog; ammo: TAmmoType; cnt, X, Y: LongWord);
 var s: ansistring;
+    name: ansistring;
     vga: PVisualGear;
 begin
     if cnt <> 0 then AddAmmo(HH, ammo, cnt)
@@ -670,10 +671,14 @@
 
     if IsHogLocal(@HH) then
         begin
+        if length(trluaammo[Ammoz[ammo].NameId]) > 0 then
+            name:= trluaammo[Ammoz[ammo].NameId]
+        else
+            name:= trammo[Ammoz[ammo].NameId];
         if cnt <> 0 then
-            s:= trammo[Ammoz[ammo].NameId] + ansistring(' (+' + IntToStr(cnt) + ')')
+            s:= name + ansistring(' (+' + IntToStr(cnt) + ')')
         else
-            s:= trammo[Ammoz[ammo].NameId] + ansistring(' (+' + IntToStr(Ammoz[ammo].NumberInCase) + ')');
+            s:= name + ansistring(' (+' + IntToStr(Ammoz[ammo].NumberInCase) + ')');
         AddCaption(s, HH.Team^.Clan^.Color, capgrpAmmoinfo);
 
         // show ammo icon
--- a/hedgewars/uScript.pas	Sat Nov 19 21:17:48 2016 +0100
+++ b/hedgewars/uScript.pas	Mon May 09 22:49:31 2016 +0200
@@ -550,6 +550,16 @@
     lc_hidemission:= 0;
 end;
 
+function lc_setammotexts(L : Plua_State) : LongInt; Cdecl;
+const
+    call = 'SetAmmoTexts';
+    params = 'ammoType, name, caption, description';
+begin
+    if CheckLuaParamCount(L, 4, call, params) then
+        SetAmmoTexts(TAmmoType(LuaToAmmoTypeOrd(L, 1, call, params)), lua_tostringA(L, 2), lua_tostringA(L, 3), lua_tostringA(L, 4));
+    lc_setammotexts:= 0;
+end;
+
 function lc_enablegameflags(L : Plua_State) : LongInt; Cdecl;
 var i, n : integer;
 begin
@@ -3349,6 +3359,7 @@
 lua_register(luaState, _P'ParseCommand', @lc_parsecommand);
 lua_register(luaState, _P'ShowMission', @lc_showmission);
 lua_register(luaState, _P'HideMission', @lc_hidemission);
+lua_register(luaState, _P'SetAmmoTexts', @lc_setammotexts);
 lua_register(luaState, _P'AddCaption', @lc_addcaption);
 lua_register(luaState, _P'SetAmmo', @lc_setammo);
 lua_register(luaState, _P'SetAmmoDelay', @lc_setammodelay);
--- a/hedgewars/uStore.pas	Sat Nov 19 21:17:48 2016 +0100
+++ b/hedgewars/uStore.pas	Mon May 09 22:49:31 2016 +0200
@@ -938,6 +938,9 @@
 procedure RenderWeaponTooltip(atype: TAmmoType);
 var r: TSDL_Rect;
     i: LongInt;
+    ammoname: ansistring;
+    ammocap: ansistring;
+    ammodesc: ansistring;
     extra: ansistring;
     extracolor: LongInt;
 begin
@@ -978,8 +981,23 @@
     extracolor:= 0;
     end;
 
+if length(trluaammo[Ammoz[atype].NameId]) > 0  then
+    ammoname := trluaammo[Ammoz[atype].NameId]
+else
+    ammoname := trammo[Ammoz[atype].NameId];
+
+if length(trluaammoc[Ammoz[atype].NameId]) > 0 then
+    ammocap := trluaammoc[Ammoz[atype].NameId]
+else
+    ammocap := trammoc[Ammoz[atype].NameId];
+
+if length(trluaammod[Ammoz[atype].NameId]) > 0 then
+    ammodesc := trluaammod[Ammoz[atype].NameId]
+else
+    ammodesc := trammod[Ammoz[atype].NameId];
+
 // render window and return the texture
-WeaponTooltipTex:= RenderHelpWindow(trammo[Ammoz[atype].NameId], trammoc[Ammoz[atype].NameId], trammod[Ammoz[atype].NameId], extra, extracolor, SpritesData[sprAMAmmos].Surface, @r)
+WeaponTooltipTex:= RenderHelpWindow(ammoname, ammocap, ammodesc, extra, extracolor, SpritesData[sprAMAmmos].Surface, @r)
 end;
 
 procedure ShowWeaponTooltip(x, y: LongInt);
--- a/hedgewars/uVariables.pas	Sat Nov 19 21:17:48 2016 +0100
+++ b/hedgewars/uVariables.pas	Mon May 09 22:49:31 2016 +0200
@@ -2471,6 +2471,9 @@
 var trammo:  array[TAmmoStrId] of ansistring;   // name of the weapon
     trammoc: array[TAmmoStrId] of ansistring;   // caption of the weapon
     trammod: array[TAmmoStrId] of ansistring;   // description of the weapon
+    trluaammo: array[TAmmoStrId] of ansistring; // name of the weapon (Lua overwrite)
+    trluaammoc: array[TAmmoStrId] of ansistring; // caption of the weapon (Lua overwrite)
+    trluaammod: array[TAmmoStrId] of ansistring;  // description of the weapon (Lua overwrite)
     trmsg:   array[TMsgStrId]  of ansistring;   // message of the event
     trgoal:  array[TGoalStrId] of ansistring;   // message of the goal
     cTestLua : Boolean;
--- a/hedgewars/uWorld.pas	Sat Nov 19 21:17:48 2016 +0100
+++ b/hedgewars/uWorld.pas	Mon May 09 22:49:31 2016 +0200
@@ -32,6 +32,7 @@
 procedure DrawWorldStereo(Lag: LongInt; RM: TRenderMode);
 procedure ShowMission(caption, subcaption, text: ansistring; icon, time : LongInt);
 procedure HideMission;
+procedure SetAmmoTexts(ammoType: TAmmoType; name: ansistring; caption: ansistring; description: ansistring);
 procedure ShakeCamera(amount: LongInt);
 procedure InitCameraBorders;
 procedure InitTouchInterface;
@@ -1948,6 +1949,16 @@
     missionTimer:= 0;
 end;
 
+procedure SetAmmoTexts(ammoType: TAmmoType; name: ansistring; caption: ansistring; description: ansistring);
+var
+    ammoStrId: TAmmoStrId;
+begin
+    ammoStrId := Ammoz[ammoType].NameId;
+    trluaammo[ammoStrId] := name;
+    trluaammoc[ammoStrId] := caption;
+    trluaammod[ammoStrId] := description;
+end;
+
 procedure ShakeCamera(amount: LongInt);
 begin
 if isCursorVisible then