From 67831eab7cae3eaf48308573e4ee52e797b95e52 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Thu, 9 Feb 2017 18:28:00 +0100 Subject: [PATCH] Final gettext convert (no more LoadString) --- decblupi.cpp | 54 +++++++++++++++++++++++++++++++++++----------------- decor.h | 6 ++++-- event.cpp | 7 ++++--- event.h | 2 ++ menu.cpp | 11 +++++++---- menu.h | 6 +++++- misc.cpp | 8 -------- misc.h | 1 - 8 files changed, 59 insertions(+), 36 deletions(-) diff --git a/decblupi.cpp b/decblupi.cpp index cb54034..9ebe0c2 100644 --- a/decblupi.cpp +++ b/decblupi.cpp @@ -1,6 +1,8 @@ // DecBlupi.cpp // +#include +#include "gettext.h" #include "DEF.H" #include "DECOR.H" #include "ACTION.H" @@ -1041,46 +1043,61 @@ void CDecor::ListRemove(int rank) // Retourne -1 si aucune répétiton n'est possible. int CDecor::ListSearch(int rank, int button, POINT cel, - int &textForButton) + const char *&textForButton) { 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[] = { - TX_REPEAT_CULTIVE, + 0, // errors 2, BUTTON_CULTIVE, BUTTON_MANGE, - TX_REPEAT_FLEUR, + 1, // errors 4, BUTTON_FLEUR, BUTTON_CARRY, BUTTON_LABO, BUTTON_DEPOSE, - TX_REPEAT_FLEURQ, + 2, // errors 3, BUTTON_CARRY, BUTTON_LABO, BUTTON_DEPOSE, - TX_REPEAT_FABMINE, + 3, // errors 3, BUTTON_EXTRAIT, BUTTON_FABMINE, BUTTON_DEPOSE, - TX_REPEAT_FABJEEP, + 4, // errors 3, BUTTON_EXTRAIT, BUTTON_FABJEEP, BUTTON_DJEEP, - TX_REPEAT_FABARMURE, + 5, // errors 3, BUTTON_EXTRAIT, BUTTON_FABARMURE, BUTTON_DARMURE, - TX_REPEAT_PALIS, + 6, // errors 4, BUTTON_ABAT, BUTTON_CARRY, BUTTON_DEPOSE, BUTTON_PALIS, - TX_REPEAT_PALISQ, + 7, // errors 3, BUTTON_CARRY, BUTTON_DEPOSE, BUTTON_PALIS, - TX_REPEAT_PONT, + 8, // errors 4, BUTTON_ABAT, BUTTON_CARRY, BUTTON_DEPOSE, BUTTON_PONT, - TX_REPEAT_PONTQ, + 9, // errors 3, BUTTON_CARRY, BUTTON_DEPOSE, BUTTON_PONT, - TX_REPEAT_BATEAU, + 10, // errors 4, BUTTON_ABAT, BUTTON_CARRY, BUTTON_DEPOSE, BUTTON_BATEAU, - TX_REPEAT_BATEAUQ, + 11, // errors 3, BUTTON_CARRY, BUTTON_DEPOSE, BUTTON_BATEAU, -1, @@ -1107,7 +1124,7 @@ int CDecor::ListSearch(int rank, int button, POINT cel, goto next; } } - textForButton = table_series[i]; + textForButton = gettext (errors[table_series[i]]); return nb-1; } @@ -4533,14 +4550,16 @@ bool CDecor::IsWorkBlupi(int rank) // pour le blupi sélectionné. void CDecor::BlupiGetButtons(POINT pos, int &nb, - int *pButtons, int *pErrors, int &perso) + int *pButtons, int *pErrors, + std::unordered_map &texts, int &perso) { int* pB = pButtons; int* pE = pErrors; POINT cel, cel2; - int i, rank, button, error, channel, icon, textForButton; + int i, rank, button, error, channel, icon; bool bBuild = false; bool bPut; + const char *textForButton; static int table_buttons[] = { @@ -4713,7 +4732,8 @@ void CDecor::BlupiGetButtons(POINT pos, int &nb, m_blupi[m_rankBlupiHili].repeatLevelHope = rank; pButtons[nb] = BUTTON_REPEAT; - pErrors[nb] = textForButton; + pErrors[nb] = 500; + texts[nb] = textForButton; nb ++; return; } diff --git a/decor.h b/decor.h index 8c874d1..9bf7ce1 100644 --- a/decor.h +++ b/decor.h @@ -2,6 +2,7 @@ #pragma once +#include #include "DEF.H" #include "SOUND.H" #include "PIXMAP.H" @@ -254,7 +255,7 @@ public: int ListGetParam(int rank, int button, POINT cel); bool ListPut(int rank, int button, POINT cel, POINT cMem); 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, int param, int list); void GoalStart(int rank, int action, POINT cel); @@ -294,7 +295,8 @@ public: bool IsBlupiHere(POINT cel, int direct, bool bSkipInMove); void GetLevelJauge(int *pLevels, int *pTypes); 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 &texts, int &perso); void TerminatedInit(); int IsTerminated(); Term* GetTerminated(); diff --git a/event.cpp b/event.cpp index 9de6af7..ec7818c 100644 --- a/event.cpp +++ b/event.cpp @@ -1926,8 +1926,9 @@ bool CEvent::DrawButtons() { m_pDecor->BlupiGetButtons(m_menuPos, m_menuNb, m_menuButtons, m_menuErrors, + m_menuTexts, 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(); m_pDecor->CelHiliButton(m_menuCel, button); @@ -3469,7 +3470,7 @@ bool CEvent::PlayUp(POINT pos, Uint16 mod) else { m_pDecor->BlupiGetButtons(pos, m_menuNb, m_menuButtons, - m_menuErrors, m_menuPerso); + m_menuErrors, m_menuTexts, m_menuPerso); if ( m_menuNb == 0 ) { 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_menu.Create(m_pPixmap, m_pSound, pos, m_menuNb, m_menuButtons, m_menuErrors, - m_menuPerso); + m_menuTexts, m_menuPerso); m_bMenu = true; m_pDecor->HideTooltips(true); // plus de tooltips pour décor } diff --git a/event.h b/event.h index 561362a..3713056 100644 --- a/event.h +++ b/event.h @@ -3,6 +3,7 @@ #pragma once #include +#include #include "jauge.h" #include "menu.h" #include "button.h" @@ -176,6 +177,7 @@ protected: int m_menuNb; int m_menuButtons[MAXBUTTON]; int m_menuErrors[MAXBUTTON]; + std::unordered_map m_menuTexts; int m_menuPerso; POINT m_menuCel; POINT m_oldMousePos; diff --git a/menu.cpp b/menu.cpp index 989aec9..286d58c 100644 --- a/menu.cpp +++ b/menu.cpp @@ -142,6 +142,7 @@ CMenu::~CMenu() bool CMenu::Create(CPixmap *pPixmap, CSound *pSound, POINT pos, int nb, int *pButtons, int *pErrors, + std::unordered_map &texts, int perso) { pos.x -= DIMBUTTONX/2; @@ -153,7 +154,7 @@ bool CMenu::Create(CPixmap *pPixmap, CSound *pSound, m_pos = pos; m_perso = perso; - Update(nb, pButtons, pErrors); + Update(nb, pButtons, pErrors, texts); if ( m_pos.x < POSDRAWX ) m_pos.x = POSDRAWX; if ( m_pos.y < POSDRAWY ) m_pos.y = POSDRAWY; @@ -176,7 +177,8 @@ bool CMenu::Create(CPixmap *pPixmap, CSound *pSound, // 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 &texts) { int i; @@ -195,6 +197,7 @@ void CMenu::Update(int nb, int *pButtons, int *pErrors) m_buttons[i] = pButtons[i]; m_errors[i] = pErrors[i]; } + m_texts = texts; } // Détruit le menu. @@ -270,7 +273,7 @@ void CMenu::Draw() 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'); if ( pText != nullptr ) *pText = 0; } @@ -309,7 +312,7 @@ void CMenu::Draw() { 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'); if ( pText != nullptr ) strcpy(text, pText+1); } diff --git a/menu.h b/menu.h index 46c3149..d0d1c26 100644 --- a/menu.h +++ b/menu.h @@ -2,6 +2,7 @@ #pragma once +#include #include "def.h" ///////////////////////////////////////////////////////////////////////////// @@ -14,8 +15,10 @@ public: bool Create(CPixmap *pPixmap, CSound *pSound, POINT pos, int nb, int *pButtons, int *pErrors, + std::unordered_map &texts, int perso); - void Update(int nb, int *pButtons, int *pErrors); + void Update(int nb, int *pButtons, int *pErrors, + std::unordered_map &texts); void Delete(); void Draw(); int GetSel(); @@ -43,6 +46,7 @@ protected: int m_perso; int m_buttons[MAXBUTTON]; int m_errors[MAXBUTTON]; + std::unordered_map m_texts; UINT m_messages[MAXBUTTON]; int m_selRank; }; diff --git a/misc.cpp b/misc.cpp index 6fd967d..b664704 100644 --- a/misc.cpp +++ b/misc.cpp @@ -31,14 +31,6 @@ void OutputDebug(char *pMessage) #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. POINT ConvLongToPos(LPARAM lParam) diff --git a/misc.h b/misc.h index fe0ec83..139e6d8 100644 --- a/misc.h +++ b/misc.h @@ -7,7 +7,6 @@ extern void InitHInstance(HINSTANCE hInstance); extern void OutputDebug(char *pMessage); -extern void LoadString(UINT nID, char *pBuffer, int lgBuffer); extern POINT ConvLongToPos(LPARAM lParam);