Make SetAmmoTexts update ammo menu weapon name, too
authorWuzzy <almikes@aol.com>
Tue, 10 May 2016 01:33:23 +0200
changeset 11945 156f1866b8bd
parent 11944 c7ec309cd685
child 11946 7ece39a537bd
Make SetAmmoTexts update ammo menu weapon name, too Lua API warning: SetAmmoTexts can not be called in onGameInit
hedgewars/uWorld.pas
--- a/hedgewars/uWorld.pas	Mon May 09 22:49:31 2016 +0200
+++ b/hedgewars/uWorld.pas	Tue May 10 01:33:23 2016 +0200
@@ -61,6 +61,7 @@
     , uCursor
     , uCommands
     , uTeams
+    , uDebug
 {$IFDEF USE_VIDEO_RECORDING}
     , uVideoRec
 {$ENDIF}
@@ -1952,9 +1953,26 @@
 procedure SetAmmoTexts(ammoType: TAmmoType; name: ansistring; caption: ansistring; description: ansistring);
 var
     ammoStrId: TAmmoStrId;
+    ammoStr: ansistring;
+    tmpsurf: PSDL_Surface;
 begin
     ammoStrId := Ammoz[ammoType].NameId;
+
     trluaammo[ammoStrId] := name;
+    if length(trluaammo[ammoStrId]) > 0 then
+        ammoStr:= trluaammo[ammoStrId]
+    else
+        ammoStr:= trammo[ammoStrId];
+
+    if checkFails(length(ammoStr) > 0,'No default text/translation found for ammo type #' + intToStr(ord(ammoType)) + '!',true) then exit;
+        
+    tmpsurf:= TTF_RenderUTF8_Blended(Fontz[CheckCJKFont(ammoStr,fnt16)].Handle, PChar(ammoStr), cWhiteColorChannels);
+    if checkFails(tmpsurf <> nil,'Name-texture creation for ammo type #' + intToStr(ord(ammoType)) + ' failed!',true) then exit;
+    tmpsurf:= doSurfaceConversion(tmpsurf);
+    FreeAndNilTexture(Ammoz[ammoType].NameTex);
+    Ammoz[ammoType].NameTex:= Surface2Tex(tmpsurf, false);
+    SDL_FreeSurface(tmpsurf);
+
     trluaammoc[ammoStrId] := caption;
     trluaammod[ammoStrId] := description;
 end;