1
0
mirror of https://github.com/blupi-games/planetblupi synced 2024-12-30 10:15:36 +01:00

Improve use of gettext

This commit is contained in:
Mathieu Schroeter 2017-02-08 22:50:19 +01:00
parent 8d0c27bfc4
commit ecf73886f6
7 changed files with 277 additions and 248 deletions

View File

@ -3,6 +3,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "gettext.h"
#include "def.h" #include "def.h"
#include "pixmap.h" #include "pixmap.h"
#include "sound.h" #include "sound.h"
@ -43,7 +44,7 @@ CButton::~CButton()
bool CButton::Create(CPixmap *pPixmap, CSound *pSound, bool CButton::Create(CPixmap *pPixmap, CSound *pSound,
POINT pos, int type, bool bMinimizeRedraw, POINT pos, int type, bool bMinimizeRedraw,
int *pMenu, int nbMenu, int *pMenu, int nbMenu,
int *pToolTips, int nbToolTips, const char **pToolTips,
int region, UINT message) int region, UINT message)
{ {
POINT iconDim; POINT iconDim;
@ -69,13 +70,16 @@ bool CButton::Create(CPixmap *pPixmap, CSound *pSound,
m_pos = pos; m_pos = pos;
m_dim = iconDim; m_dim = iconDim;
m_nbMenu = nbMenu; m_nbMenu = nbMenu;
m_nbToolTips = nbToolTips;
m_selMenu = 0; m_selMenu = 0;
m_state = 0; m_state = 0;
m_mouseState = 0; m_mouseState = 0;
m_bMouseDown = false; m_bMouseDown = false;
m_bRedraw = true; m_bRedraw = true;
m_nbToolTips = 0;
while (pToolTips[m_nbToolTips])
++m_nbToolTips;
for ( i=0 ; i<nbMenu ; i++ ) for ( i=0 ; i<nbMenu ; i++ )
{ {
icon = pMenu[i]; icon = pMenu[i];
@ -108,10 +112,7 @@ bool CButton::Create(CPixmap *pPixmap, CSound *pSound,
m_iconMenu[i] = icon; m_iconMenu[i] = icon;
} }
for ( i=0 ; i<nbToolTips ; i++ ) m_toolTips = pToolTips;
{
m_toolTips[i] = pToolTips[i];
}
return true; return true;
} }
@ -293,26 +294,29 @@ bool CButton::MouseOnButton(POINT pos)
// Retourne le tooltips pour un bouton, en fonction // Retourne le tooltips pour un bouton, en fonction
// de la position de la souris. // de la position de la souris.
int CButton::GetToolTips(POINT pos) const char *CButton::GetToolTips(POINT pos)
{ {
int width = m_dim.x; int width = m_dim.x;
int rank; int rank;
if ( m_bHide || !m_bEnable ) return -1; if (m_bHide || !m_bEnable)
return nullptr;
if ( m_nbMenu > 1 && m_bMouseDown ) // sous-menu déroulé ? if ( m_nbMenu > 1 && m_bMouseDown ) // sous-menu déroulé ?
{ {
width += 2+(m_dim.x-1)*m_nbMenu; width += 2+(m_dim.x-1)*m_nbMenu;
} }
if ( pos.x < m_pos.x || if ( pos.x < m_pos.x
pos.x > m_pos.x+width || || pos.x > m_pos.x+width
pos.y < m_pos.y || || pos.y < m_pos.y
pos.y > m_pos.y+m_dim.y ) return -1; || pos.y > m_pos.y+m_dim.y)
return nullptr;
rank = (pos.x-(m_pos.x+2+1))/(m_dim.x-1); rank = (pos.x-(m_pos.x+2+1))/(m_dim.x-1);
if ( rank < 0 ) rank = 0; if ( rank < 0 ) rank = 0;
if ( rank > m_nbToolTips ) return -1; if (rank > m_nbToolTips)
return nullptr;
if ( m_nbMenu > 1 ) if ( m_nbMenu > 1 )
{ {
@ -326,7 +330,7 @@ int CButton::GetToolTips(POINT pos)
} }
} }
return m_toolTips[rank]; return gettext (m_toolTips[rank]);
} }

View File

@ -2,6 +2,8 @@
#pragma once #pragma once
#include <vector>
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
class CButton class CButton
@ -13,7 +15,7 @@ public:
bool Create(CPixmap *pPixmap, CSound *pSound, bool Create(CPixmap *pPixmap, CSound *pSound,
POINT pos, int type, bool bMinimizeRedraw, POINT pos, int type, bool bMinimizeRedraw,
int *pMenu, int nbMenu, int *pMenu, int nbMenu,
int *pTooltips, int nbToolTips, const char **pToolTips,
int region, UINT message); int region, UINT message);
void Draw(); void Draw();
void Redraw(); void Redraw();
@ -32,7 +34,7 @@ public:
bool TreatEvent(const SDL_Event &event); bool TreatEvent(const SDL_Event &event);
bool MouseOnButton(POINT pos); bool MouseOnButton(POINT pos);
int GetToolTips(POINT pos); const char *GetToolTips(POINT pos);
protected: protected:
@ -54,7 +56,7 @@ protected:
int m_state; // 0=relâché, 1=pressé, +2=survollé int m_state; // 0=relâché, 1=pressé, +2=survollé
int m_mouseState; // 0=relâché, 1=pressé, +2=survollé int m_mouseState; // 0=relâché, 1=pressé, +2=survollé
int m_iconMenu[20]; // icônes du sous-menu int m_iconMenu[20]; // icônes du sous-menu
int m_toolTips[20]; // info-bulles const char **m_toolTips; // info-bulles
int m_nbMenu; // nb de case du sous-menu int m_nbMenu; // nb de case du sous-menu
int m_nbToolTips; // nb d'info-bulles int m_nbToolTips; // nb d'info-bulles
int m_selMenu; // sous-menu sélectionné int m_selMenu; // sous-menu sélectionné

View File

@ -45,7 +45,7 @@ static Statistic table_statistic[] =
0,0, // 0,0, //
76, 76,
false, false,
gettext ("Sick Blupi"), translate ("Sick Blupi"),
0, 0, 0, 0,
}, },
{ // STATBLUPIf = 1 { // STATBLUPIf = 1
@ -54,7 +54,7 @@ static Statistic table_statistic[] =
0,0, // 0,0, //
13, 13,
false, false,
gettext ("Tired Blupi"), translate ("Tired Blupi"),
0, 0, 0, 0,
}, },
{ // STATBLUPI = 2 { // STATBLUPI = 2
@ -63,7 +63,7 @@ static Statistic table_statistic[] =
0,0, // 0,0, //
14, 14,
false, false,
gettext ("Blupi"), translate ("Blupi"),
0, 0, 0, 0,
}, },
{ // STATDISCIPLE = 3 { // STATDISCIPLE = 3
@ -72,7 +72,7 @@ static Statistic table_statistic[] =
0,0, // 0,0, //
85, 85,
false, false,
gettext ("Helper robot"), translate ("Helper robot"),
0, 0, 0, 0,
}, },
{ // 4 { // 4
@ -81,7 +81,7 @@ static Statistic table_statistic[] =
117,117, // bateau 117,117, // bateau
58, 58,
false, false,
gettext ("Boat"), translate ("Boat"),
0, 0, 0, 0,
}, },
{ // 5 { // 5
@ -90,7 +90,7 @@ static Statistic table_statistic[] =
118,118, // jeep 118,118, // jeep
65, 65,
false, false,
gettext ("Jeep"), translate ("Jeep"),
0, 0, 0, 0,
}, },
{ // 6 { // 6
@ -99,7 +99,7 @@ static Statistic table_statistic[] =
16,16, // armure 16,16, // armure
106, 106,
false, false,
gettext ("Armour"), translate ("Armour"),
0, 0, 0, 0,
}, },
{ // 7 { // 7
@ -108,7 +108,7 @@ static Statistic table_statistic[] =
93,93, // pičge 93,93, // pičge
70, 70,
false, false,
gettext ("Sticky trap"), translate ("Sticky trap"),
0, 0, 0, 0,
}, },
{ // 8 { // 8
@ -117,7 +117,7 @@ static Statistic table_statistic[] =
92,92, // poison 92,92, // poison
71, 71,
false, false,
gettext ("Poison"), translate ("Poison"),
0, 0, 0, 0,
}, },
{ // 9 { // 9
@ -126,7 +126,7 @@ static Statistic table_statistic[] =
85,85, // dynamite 85,85, // dynamite
57, 57,
false, false,
gettext ("Dynamite"), translate ("Dynamite"),
0, 0, 0, 0,
}, },
{ // 10 { // 10
@ -135,7 +135,7 @@ static Statistic table_statistic[] =
125,125, // mine 125,125, // mine
63, 63,
false, false,
gettext ("Time bomb"), translate ("Time bomb"),
0, 0, 0, 0,
}, },
{ // 11 { // 11
@ -144,7 +144,7 @@ static Statistic table_statistic[] =
60,60, // tomate 60,60, // tomate
28, 28,
false, false,
gettext ("Tomatoes"), translate ("Tomatoes"),
0, 0, 0, 0,
}, },
{ // 12 { // 12
@ -153,7 +153,7 @@ static Statistic table_statistic[] =
80,80, // bouteille 80,80, // bouteille
34, 34,
false, false,
gettext ("Medical potion"), translate ("Medical potion"),
0, 0, 0, 0,
}, },
{ // 13 { // 13
@ -162,7 +162,7 @@ static Statistic table_statistic[] =
36,36, // planches 36,36, // planches
22, 22,
false, false,
gettext ("Planks"), translate ("Planks"),
0, 0, 0, 0,
}, },
{ // 14 { // 14
@ -171,7 +171,7 @@ static Statistic table_statistic[] =
44,44, // pierres 44,44, // pierres
27, 27,
false, false,
gettext ("Stones"), translate ("Stones"),
0, 0, 0, 0,
}, },
{ // 15 { // 15
@ -180,7 +180,7 @@ static Statistic table_statistic[] =
124,124, // drapeau 124,124, // drapeau
64, 64,
true, true,
gettext ("Flag"), translate ("Flag"),
0, 0, 0, 0,
}, },
{ // 16 { // 16
@ -189,7 +189,7 @@ static Statistic table_statistic[] =
123,123, // fer 123,123, // fer
62, 62,
false, false,
gettext ("Iron"), translate ("Iron"),
0, 0, 0, 0,
}, },
{ // 17 { // 17
@ -198,7 +198,7 @@ static Statistic table_statistic[] =
82,82, // fleurs1 82,82, // fleurs1
72, 72,
false, false,
pgettext ("Flower|1|", "Flowers"), ptranslate ("Flower|1|", "Flowers"),
0, 0, 0, 0,
}, },
{ // 18 { // 18
@ -207,7 +207,7 @@ static Statistic table_statistic[] =
84,84, // fleurs2 84,84, // fleurs2
73, 73,
false, false,
pgettext ("Flower|2|", "Flowers"), ptranslate ("Flower|2|", "Flowers"),
0, 0, 0, 0,
}, },
{ // 19 { // 19
@ -216,7 +216,7 @@ static Statistic table_statistic[] =
95,95, // fleurs3 95,95, // fleurs3
74, 74,
false, false,
pgettext ("Flower|3|", "Flowers"), ptranslate ("Flower|3|", "Flowers"),
0, 0, 0, 0,
}, },
{ // 20 { // 20
@ -225,7 +225,7 @@ static Statistic table_statistic[] =
61,61, // cabane 61,61, // cabane
19, 19,
true, true,
gettext ("Garden shed"), translate ("Garden shed"),
0, 0, 0, 0,
}, },
{ // 21 { // 21
@ -234,7 +234,7 @@ static Statistic table_statistic[] =
-52,-56, // couveuse -52,-56, // couveuse
25, 25,
false, false,
gettext ("Incubator"), translate ("Incubator"),
0, 0, 0, 0,
}, },
{ // 22 { // 22
@ -243,7 +243,7 @@ static Statistic table_statistic[] =
-80,-84, // téléporteur -80,-84, // téléporteur
101, 101,
false, false,
gettext ("Teleporter"), translate ("Teleporter"),
0, 0, 0, 0,
}, },
{ // 23 { // 23
@ -252,7 +252,7 @@ static Statistic table_statistic[] =
28,29, // laboratoire 28,29, // laboratoire
35, 35,
true, true,
gettext ("Laboratory"), translate ("Laboratory"),
0, 0, 0, 0,
}, },
{ // 24 { // 24
@ -261,7 +261,7 @@ static Statistic table_statistic[] =
121,122, // mine de fer 121,122, // mine de fer
61, 61,
true, true,
gettext ("Mine"), translate ("Mine"),
0, 0, 0, 0,
}, },
{ // 25 { // 25
@ -270,7 +270,7 @@ static Statistic table_statistic[] =
119,120, // usine 119,120, // usine
59, 59,
true, true,
gettext ("Workshop"), translate ("Workshop"),
0, 0, 0, 0,
}, },
{ // 26 { // 26
@ -279,7 +279,7 @@ static Statistic table_statistic[] =
27,27, // tour 27,27, // tour
33, 33,
true, true,
gettext ("Protection tower"), translate ("Protection tower"),
0, 0, 0, 0,
}, },
{ // STATFEU = 27 { // STATFEU = 27
@ -288,7 +288,7 @@ static Statistic table_statistic[] =
0,0, // 0,0, //
37, 37,
true, true,
gettext ("Fire"), translate ("Fire"),
0, 0, 0, 0,
}, },
{ // STATROBOT = 28 { // STATROBOT = 28
@ -297,7 +297,7 @@ static Statistic table_statistic[] =
0,0, // 0,0, //
56, 56,
false, false,
gettext ("Master robot"), translate ("Master robot"),
0, 0, 0, 0,
}, },
{ // STATTRACKS = 29 { // STATTRACKS = 29
@ -306,7 +306,7 @@ static Statistic table_statistic[] =
0,0, // 0,0, //
17, 17,
false, false,
gettext ("Bulldozer"), translate ("Bulldozer"),
0, 0, 0, 0,
}, },
{ // STATBOMBE = 30 { // STATBOMBE = 30
@ -315,7 +315,7 @@ static Statistic table_statistic[] =
0,0, // 0,0, //
38, 38,
false, false,
gettext ("Bouncing bomb"), translate ("Bouncing bomb"),
0, 0, 0, 0,
}, },
{ // STATARAIGNEE = 31 { // STATARAIGNEE = 31
@ -324,7 +324,7 @@ static Statistic table_statistic[] =
0,0, // 0,0, //
15, 15,
false, false,
gettext ("Spider"), translate ("Spider"),
0, 0, 0, 0,
}, },
{ // STATVIRUS = 32 { // STATVIRUS = 32
@ -333,7 +333,7 @@ static Statistic table_statistic[] =
0,0, // 0,0, //
16, 16,
false, false,
gettext ("Virus"), translate ("Virus"),
0, 0, 0, 0,
}, },
{ // STATELECTRO = 33 { // STATELECTRO = 33
@ -342,7 +342,7 @@ static Statistic table_statistic[] =
0,0, // 0,0, //
75, 75,
false, false,
gettext ("Electrocutor"), translate ("Electrocutor"),
0, 0, 0, 0,
}, },
@ -732,7 +732,7 @@ void CDecor::StatisticDraw()
if ( rank == m_statHili ) // statistique survolée ? if ( rank == m_statHili ) // statistique survolée ?
{ {
m_pPixmap->DrawIconDemi(-1, CHBLUPI, ICON_HILI_STAT, pos); m_pPixmap->DrawIconDemi(-1, CHBLUPI, ICON_HILI_STAT, pos);
textRes = pStatistic->text; textRes = gettext (pStatistic->text);
} }
if ( pStatistic->nb > 0 ) if ( pStatistic->nb > 0 )

407
event.cpp

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,7 @@
#pragma once #pragma once
#include <vector>
#include "jauge.h" #include "jauge.h"
#include "menu.h" #include "menu.h"
#include "button.h" #include "button.h"
@ -16,7 +17,7 @@ typedef struct
int type; int type;
int iconMenu[20]; int iconMenu[20];
int x, y; int x, y;
int toolTips[20]; const char *toolTips[16];
} }
Button; Button;

View File

@ -4,3 +4,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <libintl.h> #include <libintl.h>
#include "gettext/gettext.h" #include "gettext/gettext.h"
#define translate(msgid) msgid
#define ptranslate(msgctx, msgid) msgctx GETTEXT_CONTEXT_GLUE msgid

View File

@ -146,6 +146,7 @@ xcopy /Y ffmpeg-3.2.2-win32-shared\bin\*.dll $(SolutionDir)\$(Configuration)\</C
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
@ -172,6 +173,7 @@ xcopy /Y ffmpeg-3.2.2-win32-shared\bin\*.dll $(SolutionDir)\$(Configuration)\</C
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>