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

Final gettext convert (no more LoadString)

This commit is contained in:
Mathieu Schroeter 2017-02-09 18:28:00 +01:00
parent 4785cd25a8
commit 67831eab7c
8 changed files with 59 additions and 36 deletions

View File

@ -1,6 +1,8 @@
// DecBlupi.cpp // DecBlupi.cpp
// //
#include <unordered_map>
#include "gettext.h"
#include "DEF.H" #include "DEF.H"
#include "DECOR.H" #include "DECOR.H"
#include "ACTION.H" #include "ACTION.H"
@ -1041,46 +1043,61 @@ void CDecor::ListRemove(int rank)
// Retourne -1 si aucune répétiton n'est possible. // Retourne -1 si aucune répétiton n'est possible.
int CDecor::ListSearch(int rank, int button, POINT cel, int CDecor::ListSearch(int rank, int button, POINT cel,
int &textForButton) const char *&textForButton)
{ {
int i, j, param, nb; int i, j, param, nb;
static const char *errors[] = {
/* 0 */ translate ("1: Grow tomatoes\n2: Eat"),
/* 1 */ translate ("1: Make a bunch\n2: Transform"),
/* 2 */ translate ("1: Take\n2: Transform"),
/* 3 */ translate ("1: Extract iron\n2: Make a bomb"),
/* 4 */ translate ("1: Extract iron\n2: Make a Jeep"),
/* 5 */ translate ("1: Extract iron\n2: Make an armour"),
/* 6 */ translate ("1: Cut down a tree \n2: Make a palisade"),
/* 7 */ translate ("1: Take\n2: Build palisade"),
/* 8 */ translate ("1: Cut down a tree \n2: Build a bridge"),
/* 9 */ translate ("1: Take\n2: Build a bridge"),
/* 10 */ translate ("1: Cut down a tree \n2: Make a boat"),
/* 11 */ translate ("1: Take\n2: Make a boat"),
};
static int table_series[] = static int table_series[] =
{ {
TX_REPEAT_CULTIVE, 0, // errors
2, BUTTON_CULTIVE, BUTTON_MANGE, 2, BUTTON_CULTIVE, BUTTON_MANGE,
TX_REPEAT_FLEUR, 1, // errors
4, BUTTON_FLEUR, BUTTON_CARRY, BUTTON_LABO, BUTTON_DEPOSE, 4, BUTTON_FLEUR, BUTTON_CARRY, BUTTON_LABO, BUTTON_DEPOSE,
TX_REPEAT_FLEURQ, 2, // errors
3, BUTTON_CARRY, BUTTON_LABO, BUTTON_DEPOSE, 3, BUTTON_CARRY, BUTTON_LABO, BUTTON_DEPOSE,
TX_REPEAT_FABMINE, 3, // errors
3, BUTTON_EXTRAIT, BUTTON_FABMINE, BUTTON_DEPOSE, 3, BUTTON_EXTRAIT, BUTTON_FABMINE, BUTTON_DEPOSE,
TX_REPEAT_FABJEEP, 4, // errors
3, BUTTON_EXTRAIT, BUTTON_FABJEEP, BUTTON_DJEEP, 3, BUTTON_EXTRAIT, BUTTON_FABJEEP, BUTTON_DJEEP,
TX_REPEAT_FABARMURE, 5, // errors
3, BUTTON_EXTRAIT, BUTTON_FABARMURE, BUTTON_DARMURE, 3, BUTTON_EXTRAIT, BUTTON_FABARMURE, BUTTON_DARMURE,
TX_REPEAT_PALIS, 6, // errors
4, BUTTON_ABAT, BUTTON_CARRY, BUTTON_DEPOSE, BUTTON_PALIS, 4, BUTTON_ABAT, BUTTON_CARRY, BUTTON_DEPOSE, BUTTON_PALIS,
TX_REPEAT_PALISQ, 7, // errors
3, BUTTON_CARRY, BUTTON_DEPOSE, BUTTON_PALIS, 3, BUTTON_CARRY, BUTTON_DEPOSE, BUTTON_PALIS,
TX_REPEAT_PONT, 8, // errors
4, BUTTON_ABAT, BUTTON_CARRY, BUTTON_DEPOSE, BUTTON_PONT, 4, BUTTON_ABAT, BUTTON_CARRY, BUTTON_DEPOSE, BUTTON_PONT,
TX_REPEAT_PONTQ, 9, // errors
3, BUTTON_CARRY, BUTTON_DEPOSE, BUTTON_PONT, 3, BUTTON_CARRY, BUTTON_DEPOSE, BUTTON_PONT,
TX_REPEAT_BATEAU, 10, // errors
4, BUTTON_ABAT, BUTTON_CARRY, BUTTON_DEPOSE, BUTTON_BATEAU, 4, BUTTON_ABAT, BUTTON_CARRY, BUTTON_DEPOSE, BUTTON_BATEAU,
TX_REPEAT_BATEAUQ, 11, // errors
3, BUTTON_CARRY, BUTTON_DEPOSE, BUTTON_BATEAU, 3, BUTTON_CARRY, BUTTON_DEPOSE, BUTTON_BATEAU,
-1, -1,
@ -1107,7 +1124,7 @@ int CDecor::ListSearch(int rank, int button, POINT cel,
goto next; goto next;
} }
} }
textForButton = table_series[i]; textForButton = gettext (errors[table_series[i]]);
return nb-1; return nb-1;
} }
@ -4533,14 +4550,16 @@ bool CDecor::IsWorkBlupi(int rank)
// pour le blupi sélectionné. // pour le blupi sélectionné.
void CDecor::BlupiGetButtons(POINT pos, int &nb, void CDecor::BlupiGetButtons(POINT pos, int &nb,
int *pButtons, int *pErrors, int &perso) int *pButtons, int *pErrors,
std::unordered_map<int, const char *> &texts, int &perso)
{ {
int* pB = pButtons; int* pB = pButtons;
int* pE = pErrors; int* pE = pErrors;
POINT cel, cel2; POINT cel, cel2;
int i, rank, button, error, channel, icon, textForButton; int i, rank, button, error, channel, icon;
bool bBuild = false; bool bBuild = false;
bool bPut; bool bPut;
const char *textForButton;
static int table_buttons[] = static int table_buttons[] =
{ {
@ -4713,7 +4732,8 @@ void CDecor::BlupiGetButtons(POINT pos, int &nb,
m_blupi[m_rankBlupiHili].repeatLevelHope = rank; m_blupi[m_rankBlupiHili].repeatLevelHope = rank;
pButtons[nb] = BUTTON_REPEAT; pButtons[nb] = BUTTON_REPEAT;
pErrors[nb] = textForButton; pErrors[nb] = 500;
texts[nb] = textForButton;
nb ++; nb ++;
return; return;
} }

View File

@ -2,6 +2,7 @@
#pragma once #pragma once
#include <unordered_map>
#include "DEF.H" #include "DEF.H"
#include "SOUND.H" #include "SOUND.H"
#include "PIXMAP.H" #include "PIXMAP.H"
@ -254,7 +255,7 @@ public:
int ListGetParam(int rank, int button, POINT cel); int ListGetParam(int rank, int button, POINT cel);
bool ListPut(int rank, int button, POINT cel, POINT cMem); bool ListPut(int rank, int button, POINT cel, POINT cMem);
void ListRemove(int rank); void ListRemove(int rank);
int ListSearch(int rank, int button, POINT cel, int &textForButton); int ListSearch(int rank, int button, POINT cel, const char *&textForButton);
bool RepeatAdjust(int rank, int button, POINT &cel, POINT &cMem, bool RepeatAdjust(int rank, int button, POINT &cel, POINT &cMem,
int param, int list); int param, int list);
void GoalStart(int rank, int action, POINT cel); void GoalStart(int rank, int action, POINT cel);
@ -294,7 +295,8 @@ public:
bool IsBlupiHere(POINT cel, int direct, bool bSkipInMove); bool IsBlupiHere(POINT cel, int direct, bool bSkipInMove);
void GetLevelJauge(int *pLevels, int *pTypes); void GetLevelJauge(int *pLevels, int *pTypes);
bool IsWorkBlupi(int rank); bool IsWorkBlupi(int rank);
void BlupiGetButtons(POINT pos, int &nb, int *pButtons, int *pErrors, int &perso); void BlupiGetButtons(POINT pos, int &nb, int *pButtons, int *pErrors,
std::unordered_map<int, const char *> &texts, int &perso);
void TerminatedInit(); void TerminatedInit();
int IsTerminated(); int IsTerminated();
Term* GetTerminated(); Term* GetTerminated();

View File

@ -1926,8 +1926,9 @@ bool CEvent::DrawButtons()
{ {
m_pDecor->BlupiGetButtons(m_menuPos, m_menuNb, m_pDecor->BlupiGetButtons(m_menuPos, m_menuNb,
m_menuButtons, m_menuErrors, m_menuButtons, m_menuErrors,
m_menuTexts,
m_menuPerso); m_menuPerso);
m_menu.Update(m_menuNb, m_menuButtons, m_menuErrors); m_menu.Update(m_menuNb, m_menuButtons, m_menuErrors, m_menuTexts);
button = m_menu.GetSel(); button = m_menu.GetSel();
m_pDecor->CelHiliButton(m_menuCel, button); m_pDecor->CelHiliButton(m_menuCel, button);
@ -3469,7 +3470,7 @@ bool CEvent::PlayUp(POINT pos, Uint16 mod)
else else
{ {
m_pDecor->BlupiGetButtons(pos, m_menuNb, m_menuButtons, m_pDecor->BlupiGetButtons(pos, m_menuNb, m_menuButtons,
m_menuErrors, m_menuPerso); m_menuErrors, m_menuTexts, m_menuPerso);
if ( m_menuNb == 0 ) if ( m_menuNb == 0 )
{ {
m_pDecor->BlupiSound(-1, table_sound_boing[Random(0,2)], pos); m_pDecor->BlupiSound(-1, table_sound_boing[Random(0,2)], pos);
@ -3480,7 +3481,7 @@ bool CEvent::PlayUp(POINT pos, Uint16 mod)
m_menuPos = pos; m_menuPos = pos;
m_menu.Create(m_pPixmap, m_pSound, m_menu.Create(m_pPixmap, m_pSound,
pos, m_menuNb, m_menuButtons, m_menuErrors, pos, m_menuNb, m_menuButtons, m_menuErrors,
m_menuPerso); m_menuTexts, m_menuPerso);
m_bMenu = true; m_bMenu = true;
m_pDecor->HideTooltips(true); // plus de tooltips pour décor m_pDecor->HideTooltips(true); // plus de tooltips pour décor
} }

View File

@ -3,6 +3,7 @@
#pragma once #pragma once
#include <vector> #include <vector>
#include <unordered_map>
#include "jauge.h" #include "jauge.h"
#include "menu.h" #include "menu.h"
#include "button.h" #include "button.h"
@ -176,6 +177,7 @@ protected:
int m_menuNb; int m_menuNb;
int m_menuButtons[MAXBUTTON]; int m_menuButtons[MAXBUTTON];
int m_menuErrors[MAXBUTTON]; int m_menuErrors[MAXBUTTON];
std::unordered_map<int, const char *> m_menuTexts;
int m_menuPerso; int m_menuPerso;
POINT m_menuCel; POINT m_menuCel;
POINT m_oldMousePos; POINT m_oldMousePos;

View File

@ -142,6 +142,7 @@ CMenu::~CMenu()
bool CMenu::Create(CPixmap *pPixmap, CSound *pSound, bool CMenu::Create(CPixmap *pPixmap, CSound *pSound,
POINT pos, int nb, int *pButtons, int *pErrors, POINT pos, int nb, int *pButtons, int *pErrors,
std::unordered_map<int, const char *> &texts,
int perso) int perso)
{ {
pos.x -= DIMBUTTONX/2; pos.x -= DIMBUTTONX/2;
@ -153,7 +154,7 @@ bool CMenu::Create(CPixmap *pPixmap, CSound *pSound,
m_pos = pos; m_pos = pos;
m_perso = perso; m_perso = perso;
Update(nb, pButtons, pErrors); Update(nb, pButtons, pErrors, texts);
if ( m_pos.x < POSDRAWX ) m_pos.x = POSDRAWX; if ( m_pos.x < POSDRAWX ) m_pos.x = POSDRAWX;
if ( m_pos.y < POSDRAWY ) m_pos.y = POSDRAWY; if ( m_pos.y < POSDRAWY ) m_pos.y = POSDRAWY;
@ -176,7 +177,8 @@ bool CMenu::Create(CPixmap *pPixmap, CSound *pSound,
// Met à jour le menu. // Met à jour le menu.
void CMenu::Update(int nb, int *pButtons, int *pErrors) void CMenu::Update(int nb, int *pButtons, int *pErrors,
std::unordered_map<int, const char *> &texts)
{ {
int i; int i;
@ -195,6 +197,7 @@ void CMenu::Update(int nb, int *pButtons, int *pErrors)
m_buttons[i] = pButtons[i]; m_buttons[i] = pButtons[i];
m_errors[i] = pErrors[i]; m_errors[i] = pErrors[i];
} }
m_texts = texts;
} }
// Détruit le menu. // Détruit le menu.
@ -270,7 +273,7 @@ void CMenu::Draw()
if ( m_errors[i] >= 100 ) // no ressource au lieu erreur ? if ( m_errors[i] >= 100 ) // no ressource au lieu erreur ?
{ {
LoadString(m_errors[i], text, 50); snprintf (text, sizeof (text), m_texts[i]);
pText = strchr(text, '\n'); pText = strchr(text, '\n');
if ( pText != nullptr ) *pText = 0; if ( pText != nullptr ) *pText = 0;
} }
@ -309,7 +312,7 @@ void CMenu::Draw()
{ {
if ( m_errors[i] >= 100 ) // no ressource au lieu erreur ? if ( m_errors[i] >= 100 ) // no ressource au lieu erreur ?
{ {
LoadString(m_errors[i], text, 50); snprintf (text, sizeof (text), m_texts[i]);
pText = strchr(text, '\n'); pText = strchr(text, '\n');
if ( pText != nullptr ) strcpy(text, pText+1); if ( pText != nullptr ) strcpy(text, pText+1);
} }

6
menu.h
View File

@ -2,6 +2,7 @@
#pragma once #pragma once
#include <unordered_map>
#include "def.h" #include "def.h"
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -14,8 +15,10 @@ public:
bool Create(CPixmap *pPixmap, CSound *pSound, bool Create(CPixmap *pPixmap, CSound *pSound,
POINT pos, int nb, int *pButtons, int *pErrors, POINT pos, int nb, int *pButtons, int *pErrors,
std::unordered_map<int, const char *> &texts,
int perso); int perso);
void Update(int nb, int *pButtons, int *pErrors); void Update(int nb, int *pButtons, int *pErrors,
std::unordered_map<int, const char *> &texts);
void Delete(); void Delete();
void Draw(); void Draw();
int GetSel(); int GetSel();
@ -43,6 +46,7 @@ protected:
int m_perso; int m_perso;
int m_buttons[MAXBUTTON]; int m_buttons[MAXBUTTON];
int m_errors[MAXBUTTON]; int m_errors[MAXBUTTON];
std::unordered_map<int, const char *> m_texts;
UINT m_messages[MAXBUTTON]; UINT m_messages[MAXBUTTON];
int m_selRank; int m_selRank;
}; };

View File

@ -31,14 +31,6 @@ void OutputDebug(char *pMessage)
#endif #endif
} }
// Charge un texte dans une ressource.
void LoadString(UINT nID, char *pBuffer, int lgBuffer)
{
LoadString(g_hInstance, nID, pBuffer, lgBuffer);
}
// Conversion de la position de la souris. // Conversion de la position de la souris.
POINT ConvLongToPos(LPARAM lParam) POINT ConvLongToPos(LPARAM lParam)

1
misc.h
View File

@ -7,7 +7,6 @@
extern void InitHInstance(HINSTANCE hInstance); extern void InitHInstance(HINSTANCE hInstance);
extern void OutputDebug(char *pMessage); extern void OutputDebug(char *pMessage);
extern void LoadString(UINT nID, char *pBuffer, int lgBuffer);
extern POINT ConvLongToPos(LPARAM lParam); extern POINT ConvLongToPos(LPARAM lParam);