# HG changeset patch # User Wuzzy # Date 1690221738 -7200 # Node ID cee831693af1ecd9acb5a5201543f8ad703df4ae # Parent a803428704fde7d15121ed91b69fa8896e07afba Add ExtraDamage icon variant for locales with comma as decimal separator diff -r a803428704fd -r cee831693af1 QTfrontend/hedgewars.qrc --- 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 @@ ../share/hedgewars/Data/Graphics/AmmoMenu/Ammos_base.png + ../share/hedgewars/Data/Graphics/AmmoMenu/Ammos_ExtraDamage_comma.png ../share/hedgewars/Data/misc/keys.csv res/css/qt.css res/css/chat.css diff -r a803428704fd -r cee831693af1 QTfrontend/hwconsts.h --- 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 diff -r a803428704fd -r cee831693af1 QTfrontend/ui/widget/selectWeapon.cpp --- 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) : diff -r a803428704fd -r cee831693af1 hedgewars/uRenderUtils.pas --- 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 diff -r a803428704fd -r cee831693af1 hedgewars/uStore.pas --- 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 diff -r a803428704fd -r cee831693af1 share/hedgewars/Data/Graphics/AmmoMenu/Ammos_ExtraDamage_comma.png Binary file share/hedgewars/Data/Graphics/AmmoMenu/Ammos_ExtraDamage_comma.png has changed diff -r a803428704fd -r cee831693af1 share/hedgewars/Data/Graphics/AmmoMenu/Ammos_bw_ExtraDamage_comma.png Binary file share/hedgewars/Data/Graphics/AmmoMenu/Ammos_bw_ExtraDamage_comma.png has changed