diff --git a/source/code/MenuSystem.cc b/source/code/MenuSystem.cc index 2bed47f..2787732 100644 --- a/source/code/MenuSystem.cc +++ b/source/code/MenuSystem.cc @@ -165,7 +165,7 @@ Menu::Menu(SDL_Surface **screen) this->screen = *screen; buttons = vector(10); isSubmenu = true; - exit.setLabel("Back"); + exit.setLabel( _("Back") ); } Menu::Menu(SDL_Surface **screen,bool submenu) @@ -174,9 +174,9 @@ Menu::Menu(SDL_Surface **screen,bool submenu) buttons = vector(0); isSubmenu = submenu; if(isSubmenu) - exit.setLabel("Back"); + exit.setLabel( _("Back") ); else - exit.setLabel("Exit"); + exit.setLabel( _("Exit") ); } Menu::Menu(SDL_Surface** screen, string title, bool submenu) { @@ -185,9 +185,9 @@ Menu::Menu(SDL_Surface** screen, string title, bool submenu) { isSubmenu = submenu; this->title = title; if(isSubmenu) - exit.setLabel("Back"); + exit.setLabel(_("Back") ); else - exit.setLabel("Exit"); + exit.setLabel(_("Exit") ); } void Menu::run() diff --git a/source/code/NetworkThing.hpp b/source/code/NetworkThing.hpp index 0aa53d8..0dc1574 100644 --- a/source/code/NetworkThing.hpp +++ b/source/code/NetworkThing.hpp @@ -134,6 +134,7 @@ public: server = enet_host_create (& address /* the address to bind the server host to */, 1 /* allow up to 1 clients and/or outgoing connections */, + 4 /* allow 4 channels to be used */, 0 /* assume any amount of incoming bandwidth */, 0 /* assume any amount of outgoing bandwidth */); if (server == NULL) @@ -163,6 +164,7 @@ public: ntDisconnect(); client = enet_host_create (NULL /* create a client host */, 1 /* only allow 1 outgoing connection */, + 4 /* allow 4 channels to be used */, 0 /* Unlimited downstream bandwidth */, 0 /* Unlimted upstream bandwidth */); @@ -173,7 +175,7 @@ public: else { /* Initiate the connection, allocating the four channels 0 and 1 and 2 and 3. */ - peer = enet_host_connect (client, & address, 4); + peer = enet_host_connect (client, & address, 4,0); if (peer == NULL) { diff --git a/source/code/common.h b/source/code/common.h index e879a8e..0a2e2eb 100644 --- a/source/code/common.h +++ b/source/code/common.h @@ -45,12 +45,17 @@ Copyright (C) 2008 Poul Sander #include #include #include +#include +#include #ifdef WIN32 #include "windows.h" #include "shlobj.h" #endif +#define _(String) gettext (String) + using namespace std; +using boost::format; struct commonTime{ unsigned int days; @@ -63,6 +68,7 @@ string itoa(int num) __attribute__((const)); string getPathToSaveFiles() __attribute__((pure)); + /** * str2int parses a string and returns an int with the value of the string. * if the string is not an int then 0 is returned instead of throing an error diff --git a/source/code/main.cpp b/source/code/main.cpp index d7fd026..64bada2 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp @@ -74,7 +74,13 @@ Copyright (C) 2008 Poul Sander #define SHAREDIR "." #endif +#ifndef LOCALEDIR +#define LOCALEDIR SHAREDIR"/locale" +#endif +#ifndef PACKAGE +#define PACKAGE "blockattack_roftb" +#endif //enet things #if NETWORK @@ -646,10 +652,10 @@ static int InitImages() nf_standard_small_font.setDest(screen); NFont_OpenFont(&nf_scoreboard_font,"fonts/PenguinAttack.ttf",20,nf_button_color); nf_scoreboard_font.setDest(boardBackBack); - nf_scoreboard_font.draw(370,148,"Score:"); - nf_scoreboard_font.draw(370,197,"Time:"); - nf_scoreboard_font.draw(370,246,"Chain:"); - nf_scoreboard_font.draw(370,295,"Speed:"); + nf_scoreboard_font.draw(370,148,_("Score:") ); + nf_scoreboard_font.draw(370,197,_("Time:") ); + nf_scoreboard_font.draw(370,246,_("Chain:") ); + nf_scoreboard_font.draw(370,295,_("Speed:") ); //Loads the sound if sound present @@ -1922,8 +1928,8 @@ void DrawHighscores(int x, int y, bool endless) { MakeBackground(xsize,ysize); DrawIMG(background,screen,0,0); - if (endless) nf_standard_blue_font.draw(x+100,y+100,"Endless:"); - else nf_standard_blue_font.draw(x+100,y+100,"Time Trial:"); + if (endless) nf_standard_blue_font.draw(x+100,y+100,_("Endless:") ); + else nf_standard_blue_font.draw(x+100,y+100,_("Time Trial:") ); for (int i =0;i<10;i++) { char playerScore[32]; @@ -1955,9 +1961,9 @@ void DrawStats() DrawIMG(background,screen,0,0); int y = 5; const int y_spacing = 30; - NFont_Write(screen, 10,y,"Stats"); + NFont_Write(screen, 10,y,_("Stats") ); y+=y_spacing*2; - NFont_Write(screen, 10,y,"Chains"); + NFont_Write(screen, 10,y,_("Chains") ); for(int i=2;i<13;i++) { y+=y_spacing; @@ -1966,43 +1972,43 @@ void DrawStats() NFont_Write(screen, 300,y,numberAsString.c_str()); } y+=y_spacing*2; - NFont_Write(screen, 10,y,"Lines Pushed: "); + NFont_Write(screen, 10,y,_("Lines Pushed: ") ); string numberAsString = itoa(Stats::getInstance()->getNumberOf("linesPushed")); NFont_Write(screen, 300,y,numberAsString.c_str()); y+=y_spacing; - NFont_Write(screen, 10,y,"Puzzles solved: "); + NFont_Write(screen, 10,y, _("Puzzles solved: ") ); numberAsString = itoa(Stats::getInstance()->getNumberOf("puzzlesSolved")); NFont_Write(screen, 300,y,numberAsString.c_str()); y+=y_spacing*2; - NFont_Write(screen, 10,y,"Run time: "); + NFont_Write(screen, 10,y, _("Run time: ") ); commonTime ct = TimeHandler::peekTime("totalTime",TimeHandler::ms2ct(SDL_GetTicks())); y+=y_spacing; - NFont_Write(screen, 10,y,((string)("Days: "+itoa(ct.days))).c_str()); + NFont_Write(screen, 10,y,((string)( _("Days: ")+itoa(ct.days))).c_str()); y+=y_spacing; - NFont_Write(screen, 10,y,((string)("Hours: "+itoa(ct.hours))).c_str()); + NFont_Write(screen, 10,y,((string)( _("Hours: ")+itoa(ct.hours))).c_str()); y+=y_spacing; - NFont_Write(screen, 10,y,((string)("Minutes: "+itoa(ct.minutes))).c_str()); + NFont_Write(screen, 10,y,((string)( _("Minutes: ")+itoa(ct.minutes))).c_str()); y+=y_spacing; - NFont_Write(screen, 10,y,((string)("Seconds: "+itoa(ct.seconds))).c_str()); + NFont_Write(screen, 10,y,((string)( _("Seconds: ")+itoa(ct.seconds))).c_str()); y-=y_spacing*4; //Four rows back const int x_offset3 = xsize/3+10; //Ofset for three rows - NFont_Write(screen, x_offset3,y,"Play time: "); + NFont_Write(screen, x_offset3,y, _("Play time: ") ); ct = TimeHandler::getTime("playTime"); y+=y_spacing; - NFont_Write(screen, x_offset3,y,((string)("Days: "+itoa(ct.days))).c_str()); + NFont_Write(screen, x_offset3,y,((string)( _("Days: ")+itoa(ct.days))).c_str()); y+=y_spacing; - NFont_Write(screen, x_offset3,y,((string)("Hours: "+itoa(ct.hours))).c_str()); + NFont_Write(screen, x_offset3,y,((string)( _("Hours: ")+itoa(ct.hours))).c_str()); y+=y_spacing; - NFont_Write(screen, x_offset3,y,((string)("Minutes: "+itoa(ct.minutes))).c_str()); + NFont_Write(screen, x_offset3,y,((string)( _("Minutes: ")+itoa(ct.minutes))).c_str()); y+=y_spacing; - NFont_Write(screen, x_offset3,y,((string)("Seconds: "+itoa(ct.seconds))).c_str()); + NFont_Write(screen, x_offset3,y,((string)( _("Seconds: ")+itoa(ct.seconds))).c_str()); const int x_offset = xsize/2+10; y = 5+y_spacing*2; - NFont_Write(screen, x_offset,y,"VS CPU (win/loss)"); + NFont_Write(screen, x_offset,y, _("VS CPU (win/loss)") ); for(int i=0;i<7;i++) { y += y_spacing; @@ -2050,7 +2056,7 @@ void OpenScoresDisplay() DrawIMG(bNext,screen,nextX,nextY); //Draw page number - string pageXofY = ((string)"Page ")+itoa(page+1)+((string)" of ")+itoa(numberOfPages); + string pageXofY = (format(_("Page %1% of %2%") )%(page+1)%numberOfPages).str(); NFont_Write(screen, xsize/2-nf_standard_blue_font.getWidth( pageXofY.c_str())/2,ysize-60,pageXofY.c_str()); SDL_Delay(10); @@ -2535,10 +2541,10 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl *theGame, BlockGameSdl *th strHolder = itoa(theGame->GetScore()+theGame->GetHandicap()); NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+100,strHolder.c_str()); if (theGame->GetAIenabled()) - NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,"CPU"); + NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,_("AI") ); else if (editorMode) - NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,"Playing field"); + NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,_("Playing field") ); else if (!singlePuzzle) NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,player1name); @@ -2634,21 +2640,21 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl *theGame, BlockGameSdl *th //Write the keys that are in use int y = theGame2->GetTopY()+400; - NFont_Write(screen, theGame2->GetTopX()+7,y,"Movement keys:" ); + NFont_Write(screen, theGame2->GetTopX()+7,y,_("Movement keys:") ); NFont_Write(screen, theGame2->GetTopX()+7,y+40,(getKeyName(keySettings[0].left)+", "+getKeyName(keySettings[0].right)+"," ).c_str() ); NFont_Write(screen, theGame2->GetTopX()+7,y+76,(getKeyName(keySettings[0].up)+", "+getKeyName(keySettings[0].down)).c_str() ); - NFont_Write(screen, theGame2->GetTopX()+7,y+120,("Switch: "+getKeyName(keySettings[0].change) ).c_str() ); + NFont_Write(screen, theGame2->GetTopX()+7,y+120,( _("Switch: ")+getKeyName(keySettings[0].change) ).c_str() ); if(theGame->isPuzzleMode()) - NFont_Write(screen, theGame2->GetTopX()+7,y+160,("Restart: "+getKeyName(keySettings[0].push) ).c_str() ); + NFont_Write(screen, theGame2->GetTopX()+7,y+160,( _("Restart: ")+getKeyName(keySettings[0].push) ).c_str() ); else - NFont_Write(screen, theGame2->GetTopX()+7,y+160,("Push line: "+getKeyName(keySettings[0].push) ).c_str() ); + NFont_Write(screen, theGame2->GetTopX()+7,y+160,( _("Push line: ")+getKeyName(keySettings[0].push) ).c_str() ); } else DrawIMG(theGame2->sBoard,screen,theGame2->GetTopX(),theGame2->GetTopY()); strHolder = itoa(theGame2->GetScore()+theGame2->GetHandicap()); NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+100,strHolder.c_str()); if (theGame2->GetAIenabled()) - NFont_Write(screen, theGame2->GetTopX()+10,theGame2->GetTopY()-34,"CPU"); + NFont_Write(screen, theGame2->GetTopX()+10,theGame2->GetTopY()-34,_("AI") ); else NFont_Write(screen, theGame2->GetTopX()+10,theGame2->GetTopY()-34,theGame2->name); if (theGame2->isTimeTrial()) @@ -2784,7 +2790,7 @@ int PuzzleLevelSelect() DrawIMG(background, screen, 0, 0); DrawIMG(iCheckBoxArea,screen,xplace,yplace); - NFont_Write(screen, xplace+12,yplace+2,"Select Puzzle"); + NFont_Write(screen, xplace+12,yplace+2,_("Select Puzzle") ); //Now drow the fields you click in (and a V if clicked): for (int i = 0; i < nrOfPuzzles;i++) { @@ -2911,7 +2917,7 @@ int StageLevelSelect() //nowTime=SDL_GetTicks(); DrawIMG(background, screen, 0, 0); DrawIMG(iCheckBoxArea,screen,xplace,yplace); - NFont_Write(screen, xplace+12,yplace+2,"Stage Clear Level Select"); + NFont_Write(screen, xplace+12,yplace+2, _("Stage Clear Level Select") ); for (int i = 0; i < nrOfStageLevels;i++) { DrawIMG(iLevelCheckBox,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50); @@ -2969,20 +2975,20 @@ int StageLevelSelect() if ((10+j*500) - scoreString = "Best score: "+itoa(stageScores[overLevel]); + scoreString = _("Best score: ")+itoa(stageScores[overLevel]); if(stageTimes[overLevel]>0) - timeString = "Time used: "+itoa(stageTimes[overLevel]/1000/60)+" : "+itoa2((stageTimes[overLevel]/1000)%60); + timeString = _("Time used: ")+itoa(stageTimes[overLevel]/1000/60)+" : "+itoa2((stageTimes[overLevel]/1000)%60); NFont_Write(screen, 200,200,scoreString.c_str()); NFont_Write(screen, 200,250,timeString.c_str()); overLevel; } - string totalString = "Total score: " +itoa(totalScore) + " in " + itoa(totalTime/1000/60) + " : " + itoa2((totalTime/1000)%60); + string totalString = (format("Total score: %1% in %2%:%3%")%totalScore%(totalTime/1000/60)%((totalTime/1000)%60)).str(); //"Total score: " +itoa(totalScore) + " in " + itoa(totalTime/1000/60) + " : " + itoa2((totalTime/1000)%60); NFont_Write(screen, 200,600,totalString.c_str()); //DrawIMG(mouse,screen,mousex,mousey); @@ -3006,13 +3012,13 @@ int startSingleVs() MakeBackground(xsize,ysize); DrawIMG(changeButtonsBack,background,xplace,yplace); - NFont_Write(background, xplace+10,yplace+10,"1 : Very Easy"); - NFont_Write(background, xplace+10,yplace+40,"2 : Easy"); - NFont_Write(background, xplace+10,yplace+70,"3 : Below Normal"); - NFont_Write(background, xplace+10,yplace+100,"4 : Normal"); - NFont_Write(background, xplace+10,yplace+130,"5 : Above Normal"); - NFont_Write(background, xplace+10,yplace+160,"6 : Hard"); - NFont_Write(background, xplace+10,yplace+190,"7 : Hardest"); + NFont_Write(background, xplace+10,yplace+10,_("1 : Very Easy") ); + NFont_Write(background, xplace+10,yplace+40,_("2 : Easy") ); + NFont_Write(background, xplace+10,yplace+70,_("3 : Below Normal") ); + NFont_Write(background, xplace+10,yplace+100,_("4 : Normal") ); + NFont_Write(background, xplace+10,yplace+130,_("5 : Above Normal") ); + NFont_Write(background, xplace+10,yplace+160,_("6 : Hard") ); + NFont_Write(background, xplace+10,yplace+190,_("7 : Hardest") ); DrawIMG(background, screen, 0, 0); SDL_Flip(screen); do @@ -3090,7 +3096,7 @@ void startVsMenu() //int nowTime=SDL_GetTicks(); MakeBackground(xsize,ysize); - NFont_Write(background, 360,650,"Press ESC to accept"); + NFont_Write(background, 360,650, _("Press ESC to accept") ); DrawIMG(bBack,background,xsize/2-120/2,600); do { @@ -3369,6 +3375,9 @@ int main(int argc, char *argv[]) bFullscreen = false; //Set default Config variables: Config::getInstance()->setDefault("themename","default"); + setlocale (LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); if (argc > 1) { int argumentNr = 1; @@ -3385,13 +3394,13 @@ int main(int argc, char *argv[]) char selectTheme[] = "-theme"; if (!(strncmp(argv[argumentNr],helpString,6))) { - cout << "Block Attack Help" << endl << "--help Display this message" << - endl << "-priority Starts game in high priority" << endl << - "-forceredraw Redraw the whole screen every frame, prevents garbage" << endl << - "-forcepartdraw Only draw what is changed, sometimes cause garbage" << endl << - "-nosound No sound will be played at all, and sound hardware will not be loaded (use this if game crashes because of sound)" << endl << - "-theme Changes to the theme on startup" << endl << - "-editor Starts the build-in editor (not yet integrated)" << endl; + cout << "Block Attack Help" << endl << "--help " << _("Displays this message") << + endl << "-priority " << _("Starts game in high priority") << endl << + "-forceredraw " << _("Redraw the whole screen every frame, prevents garbage") << endl << + "-forcepartdraw " << _("Only draw what is changed, sometimes cause garbage") << endl << + "-nosound " << _("No sound will be played at all, and sound hardware will not be loaded (use this if game crashes because of sound)") << endl << + "-theme <" << _("THEMENAME") << "> " << _("Changes to the theme on startup") << endl << + "-editor " << _("Starts the build-in editor (not yet integrated)") << endl; #ifdef WIN32 system("Pause"); #endif @@ -3789,8 +3798,9 @@ int main(int argc, char *argv[]) //int hours, mins, secs, commonTime ct = TimeHandler::ms2ct(SDL_GetTicks()); - cout << "Block Attack - Rise of the Blocks ran for: " << ct.hours << " hours " << ct.minutes << " mins and " << ct.seconds << " secs" << endl; - + //cout << "Block Attack - Rise of the Blocks ran for: " << ct.hours << " hours " << ct.minutes << " mins and " << ct.seconds << " secs" << endl; + cout << boost::format("Block Attack - Rise of the Blocks ran for: %1% hours %2% mins and %3% secs") % ct.hours % ct.minutes % ct.seconds << endl; + ct = TimeHandler::addTime("totalTime",ct); cout << "Total run time is now: " << ct.days << " days " << ct.hours << " hours " << ct.minutes << " mins and " << ct.seconds << " secs" << endl; diff --git a/source/code/menudef.cpp b/source/code/menudef.cpp index a675c74..2c2846a 100644 --- a/source/code/menudef.cpp +++ b/source/code/menudef.cpp @@ -25,6 +25,7 @@ Copyright (C) 2011 Poul Sander #include #include "menu/MenuItem.hpp" #include "MenuSystem.h" +#include "common.h" using namespace std; @@ -122,12 +123,12 @@ void buttonActionMusic(Button* b) { void buttonActionSound(Button* b) { SoundEnabled = !SoundEnabled; - b->setLabel(SoundEnabled? "Music: On" : "Music: Off"); + b->setLabel(SoundEnabled? _("Sound: On") : _("Sound: Off") ); } void buttonActionFullscreen(Button* b) { bFullscreen = !bFullscreen; - b->setLabel(bFullscreen? "Fullscreen: On" : "Fullscreen: Off"); + b->setLabel(bFullscreen? _("Fullscreen: On") : _("Fullscreen: Off") ); ResetFullscreen(); } @@ -146,13 +147,13 @@ void buttonActionHighscores(Button *b) { } static void ChangeKeysMenu(long playernumber) { - Menu km(&screen,"Change key bindings",true); - Button_changekey bLeft(&keySettings[playernumber].left,"Left"); - Button_changekey bRight(&keySettings[playernumber].right,"Right"); - Button_changekey bUp(&keySettings[playernumber].up,"Up"); - Button_changekey bDown(&keySettings[playernumber].down,"Down"); - Button_changekey bPush(&keySettings[playernumber].push,"Push"); - Button_changekey bSwitch(&keySettings[playernumber].change,"Change"); + Menu km(&screen,_("Change key bindings"),true); + Button_changekey bLeft(&keySettings[playernumber].left,_("Left") ); + Button_changekey bRight(&keySettings[playernumber].right,_("Right") ); + Button_changekey bUp(&keySettings[playernumber].up,_("Up") ); + Button_changekey bDown(&keySettings[playernumber].down,_("Down") ); + Button_changekey bPush(&keySettings[playernumber].push,_("Push") ); + Button_changekey bSwitch(&keySettings[playernumber].change,_("Change") ); km.addButton(&bLeft); km.addButton(&bRight); km.addButton(&bUp); @@ -171,23 +172,23 @@ static void ChangeKeysMenu2(Button *b) { } void ConfigureMenu(Button *b) { - Menu cm(&screen,"Configuration",true); + Menu cm(&screen,_("Configuration"),true); Button bMusic,bSound,buttonFullscreen,bPlayer1Name,bPlayer2Name; Button bPlayer1Keys, bPlayer2Keys; - bMusic.setLabel(MusicEnabled? "Music: On" : "Music: Off"); + bMusic.setLabel(MusicEnabled? _("Music: On") : _("Music: Off") ); bMusic.setAction(buttonActionMusic); - bSound.setLabel(SoundEnabled? "Music: On" : "Music: Off"); + bSound.setLabel(SoundEnabled? _("Music: On") : _("Music: Off") ); bSound.setAction(buttonActionSound); - buttonFullscreen.setLabel(bFullscreen? "Fullscreen: On" : "Fullscreen: Off"); + buttonFullscreen.setLabel(bFullscreen? _("Fullscreen: On") : _("Fullscreen: Off") ); buttonFullscreen.setAction(buttonActionFullscreen); bPlayer1Name.setAction(buttonActionPlayer1Name); - bPlayer1Name.setLabel("Change player 1's name"); + bPlayer1Name.setLabel(_("Change player 1's name") ); bPlayer2Name.setAction(buttonActionPlayer2Name); - bPlayer2Name.setLabel("Change player 2's name"); + bPlayer2Name.setLabel(_("Change player 2's name") ); bPlayer1Keys.setAction(ChangeKeysMenu1); - bPlayer1Keys.setLabel("Change player 1's keys"); + bPlayer1Keys.setLabel(_("Change player 1's keys") ); bPlayer2Keys.setAction(ChangeKeysMenu2); - bPlayer2Keys.setLabel("Change player 2's keys"); + bPlayer2Keys.setLabel(_("Change player 2's keys") ); cm.addButton(&bMusic); cm.addButton(&bSound); cm.addButton(&buttonFullscreen); @@ -201,19 +202,19 @@ void ConfigureMenu(Button *b) { void MainMenu() { InitMenues(); - Menu m(&screen,"Block Attack - Rise of the blocks",false); + Menu m(&screen,_("Block Attack - Rise of the blocks"),false); Button bHi,bTimetrial1, bPuzzle, bVs1, bConfigure,bHighscore; - bHi.setLabel("Single player - endless"); + bHi.setLabel(_("Single player - endless") ); bHi.setAction(runSinglePlayerEndless); - bTimetrial1.setLabel("Single player - time trial"); + bTimetrial1.setLabel(_("Single player - time trial") ); bTimetrial1.setAction(runSinglePlayerTimeTrial); - bPuzzle.setLabel("Single player - puzzle mode"); + bPuzzle.setLabel(_("Single player - puzzle mode") ); bPuzzle.setAction(runSinglePlayerPuzzle); - bVs1.setLabel("Single player - vs"); + bVs1.setLabel(_("Single player - vs") ); bVs1.setAction(runSinglePlayerVs); - bConfigure.setLabel("Configure"); + bConfigure.setLabel(_("Configure") ); bConfigure.setAction(ConfigureMenu); - bHighscore.setLabel("Highscores"); + bHighscore.setLabel(_("Highscores") ); bHighscore.setAction(buttonActionHighscores); m.addButton(&bHi); m.addButton(&bTimetrial1);