Add ExtraDamage icon variant for locales with comma as decimal separator
authorWuzzy <Wuzzy@disroot.org>
Mon, 24 Jul 2023 20:02:18 +0200
changeset 15971 cee831693af1
parent 15970 a803428704fd
child 15973 2d9d07ccb8ef
Add ExtraDamage icon variant for locales with comma as decimal separator
QTfrontend/hedgewars.qrc
QTfrontend/hwconsts.h
QTfrontend/ui/widget/selectWeapon.cpp
hedgewars/uRenderUtils.pas
hedgewars/uStore.pas
share/hedgewars/Data/Graphics/AmmoMenu/Ammos_ExtraDamage_comma.png
share/hedgewars/Data/Graphics/AmmoMenu/Ammos_bw_ExtraDamage_comma.png
--- a/QTfrontend/hedgewars.qrc	Wed Jun 28 23:41:38 2023 +0200
+++ b/QTfrontend/hedgewars.qrc	Mon Jul 24 20:02:18 2023 +0200
@@ -1,6 +1,7 @@
 <RCC>
     <qresource prefix="/">
         <file alias="Ammos.png">../share/hedgewars/Data/Graphics/AmmoMenu/Ammos_base.png</file>
+        <file alias="Ammos_ExtraDamage_comma.png">../share/hedgewars/Data/Graphics/AmmoMenu/Ammos_ExtraDamage_comma.png</file>
         <file alias="keys.csv">../share/hedgewars/Data/misc/keys.csv</file>
         <file>res/css/qt.css</file>
         <file>res/css/chat.css</file>
--- a/QTfrontend/hwconsts.h	Wed Jun 28 23:41:38 2023 +0200
+++ b/QTfrontend/hwconsts.h	Mon Jul 24 20:02:18 2023 +0200
@@ -136,3 +136,5 @@
   7, 21, 32, 33, 35, 60\
 }
 
+/* Ammo ID for extra damage */
+#define HW_AMMOTYPE_EXTRADAMAGE 32
--- a/QTfrontend/ui/widget/selectWeapon.cpp	Wed Jun 28 23:41:38 2023 +0200
+++ b/QTfrontend/ui/widget/selectWeapon.cpp	Mon Jul 24 20:02:18 2023 +0200
@@ -38,11 +38,20 @@
 
 QImage getAmmoImage(int num)
 {
-    static QImage ammo(":Ammos.png");
-    int x = num/(ammo.height()/32);
-    int y = (num-((ammo.height()/32)*x))*32;
-    x*=32;
-    return ammo.copy(x, y, 32, 32);
+    // Show ammo image for ammo selection menu
+    if (QLocale().decimalPoint() == "," && num == HW_AMMOTYPE_EXTRADAMAGE) {
+        // Special case: Extra Damage icon showing "1,5" instead of "1.5" if locale
+        // uses comma as decimal separator
+        static QImage extradamage(":Ammos_ExtraDamage_comma.png");
+        return extradamage;
+    } else {
+        // Normal case: Pick icon from Ammos.png
+        static QImage ammo(":Ammos.png");
+        int x = num/(ammo.height()/32);
+        int y = (num-((ammo.height()/32)*x))*32;
+        x*=32;
+        return ammo.copy(x, y, 32, 32);
+    }
 }
 
 SelWeaponItem::SelWeaponItem(bool allowInfinite, int iconNum, int wNum, QImage image, QImage imagegrey, QWidget* parent) :
--- a/hedgewars/uRenderUtils.pas	Wed Jun 28 23:41:38 2023 +0200
+++ b/hedgewars/uRenderUtils.pas	Mon Jul 24 20:02:18 2023 +0200
@@ -29,6 +29,9 @@
 procedure copyToXY(src, dest: PSDL_Surface; destX, destY: LongInt); inline;
 procedure copyToXYFromRect(src, dest: PSDL_Surface; srcX, srcY, srcW, srcH, destX, destY: LongInt);
 
+function GetSurfaceFrameCoordinateX(Surface: PSDL_Surface; Frame, frameWidth, frameHeight: LongInt): LongInt;
+function GetSurfaceFrameCoordinateY(Surface: PSDL_Surface; Frame, frameHeight: LongInt): LongInt;
+
 procedure DrawSprite2Surf(sprite: TSprite; dest: PSDL_Surface; x,y: LongInt); inline;
 procedure DrawSpriteFrame2Surf(sprite: TSprite; dest: PSDL_Surface; x,y: LongInt; frame: LongInt);
 procedure DrawLine2Surf(dest: PSDL_Surface; x0,y0,x1,y1:LongInt; r,g,b: byte);
@@ -78,6 +81,24 @@
     WriteInRoundRect:= WriteInRoundRect(Surface, X, Y, Color, Font, s, 0);
 end;*)
 
+function GetSurfaceFrameCoordinateX(Surface: PSDL_Surface; Frame, frameWidth, frameHeight: LongInt): LongInt;
+var nx, ny: LongInt;
+begin
+   nx:= Surface^.w div frameWidth; // number of horizontal frames
+   if nx = 0 then nx:= 1; // one frame is minimum
+   ny:= Surface^.h div frameHeight; // number of vertical frames
+   if ny = 0 then ny:= 1;
+   GetSurfaceFrameCoordinateX:= (Frame div ny) * frameWidth;
+end;
+
+function GetSurfaceFrameCoordinateY(Surface: PSDL_Surface; Frame, frameHeight: LongInt): LongInt;
+var ny: LongInt;
+begin
+   ny:= Surface^.h div frameHeight; // number of vertical frames
+   if ny = 0 then ny:= 1; // one frame is minimum
+   GetSurfaceFrameCoordinateY:= (Frame mod ny) * frameHeight;
+end;
+
 function IsTooDarkToRead(TextColor: LongWord): boolean; inline;
 var clr: TSDL_Color;
 begin
--- a/hedgewars/uStore.pas	Wed Jun 28 23:41:38 2023 +0200
+++ b/hedgewars/uStore.pas	Mon Jul 24 20:02:18 2023 +0200
@@ -474,12 +474,30 @@
                         end;
                 if (ii in [sprAMAmmos, sprAMAmmosBW]) then
                     begin
+                    // Optionally add ammos overlay from HWP file
                     tmpoverlay := LoadDataImage(Path, copy(FileName, 1, length(FileName)-5), (imflags and (not ifCritical)));
                     if tmpoverlay <> nil then
                         begin
                         copyToXY(tmpoverlay, tmpsurf, 0, 0);
                         SDL_FreeSurface(tmpoverlay)
-                        end
+                        end;
+
+                    // Replace ExtraDamage icon with a variant showing "1,5" instead of "1.5"
+                    // if the current locale uses a comma as a decimal separator.
+                    if lDecimalSeparator = ',' then
+                        begin
+                        if ii = sprAMAmmos then
+                            tmpoverlay:= LoadDataImage(ptAmmoMenu, 'Ammos_ExtraDamage_comma', ifNone)
+                        else
+                            tmpoverlay:= LoadDataImage(ptAmmoMenu, 'Ammos_bw_ExtraDamage_comma', ifNone);
+                        if tmpoverlay <> nil then
+                            begin
+                            copyToXY(tmpoverlay, tmpsurf,
+                               GetSurfaceFrameCoordinateX(tmpsurf, ord(amExtraDamage)-1, SpritesData[ii].Width, SpritesData[ii].Height),
+                               GetSurfaceFrameCoordinateY(tmpsurf, ord(amExtraDamage)-1, SpritesData[ii].Height));
+                            SDL_FreeSurface(tmpoverlay);
+                            end;
+                        end;
                     end;
                 if (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR]) then
                     begin
Binary file share/hedgewars/Data/Graphics/AmmoMenu/Ammos_ExtraDamage_comma.png has changed
Binary file share/hedgewars/Data/Graphics/AmmoMenu/Ammos_bw_ExtraDamage_comma.png has changed