/** ******************************************************************************* @file /gui/contexts/FinalStatistic.cpp @brief Obrazovka FinalStatistic @author Pavel @version 0.1 ******************************************************************************/ // #include "gui/contexts/FinalStatistic.h" #include "gui/common/ActiveObjects_ext.h" #include "gui/common/Sounds.h" #include "gui/common/BasicFonts.h" #include "gui/common/Defs.h" #include "gui/common/colors.h" #include "gui/GUI.h" // #include "world/world_messages.h" // #include "common/rm/rminit.h" #include "common/compatibility.h" #include "common/Log.h" #include namespace gui{ using namespace World; /*****************************************************************************/ TGuiEndGame::TGuiEndGame(World::ENDGAME_REASON r, World::TPlayerContainer * p, int w){ reason = r; players = p; winner = w; } #define BORDER 10 #define BUTTON_WIDTH 150 #define BUTTON_HEIGHT 40 #define STATISTIC_WIDTH 600 #define STATISTIC_HEIGHT 500 #define STATISTIC_X ((SCREEN_WIDTH-STATISTIC_WIDTH)/2) #define STATISTIC_Y ((SCREEN_HEIGHT-STATISTIC_HEIGHT)/2) #define DESCRIPTION_WIDTH ((STATISTIC_WIDTH-BORDER)/2-BORDER) #define IMAGE_WIDTH DESCRIPTION_WIDTH #define IMAGE_HEIGHT ((int)(0.735f*IMAGE_WIDTH)) #define TABLE_Y (BORDER + IMAGE_HEIGHT + BORDER) #define TABLE_HEIGHT (STATISTIC_HEIGHT - 4*BORDER - IMAGE_HEIGHT - BUTTON_HEIGHT) #define TABLE_ROW_HEIGHT 20 #define TABLE_ROW_Y 40 #define TABLE_FIRST_COL_WIDTH 170 /*****************************************************************************/ TStatisticWindow::TStatisticWindow(TContextPrimaryParameter cpp, TGuiEndGame* eg) : TWindow(AO_UNMOVABLE, STATISTIC_X, STATISTIC_Y, STATISTIC_WIDTH, STATISTIC_HEIGHT) { rm::TRM_txt_i *rmtxti = (rm::TRM_txt_i *)KSendGlobalMessage(MSG_GET_RM_TXT_I, MOD_GUI, MOD_RM, NULL); wchar_t wtemp[LABEL_MAX_LENGTH]; setBgImage(RASTER_PANEL); //panely gimage = new TGroupBar(AO_NORMAL, BORDER, BORDER, IMAGE_WIDTH, IMAGE_HEIGHT); Add(gimage); gdescription = new TGroupBar(AO_NORMAL, (STATISTIC_WIDTH-BORDER)/2+BORDER, BORDER, DESCRIPTION_WIDTH, IMAGE_HEIGHT); Add(gdescription); gtable = new TGroupBar(AO_NORMAL, BORDER, TABLE_Y, STATISTIC_WIDTH-2*BORDER, TABLE_HEIGHT); Add(gtable); //obrazek int wpraster = 0; if(cpp == context_endgame && eg->reason>=ER_VICTORY_DESTROY) wpraster = RASTER_VICTORY; else wpraster = RASTER_DEFEAT; // TWallpaper* wp = new TWallpaper(wpraster, BORDER+1, BORDER+1, IMAGE_WIDTH-2, IMAGE_HEIGHT-2); Add(wp); //popis TMultiLabel* mldesc = new TMultiLabel(AO_NORMAL, BORDER, BORDER, DESCRIPTION_WIDTH-2*BORDER, IMAGE_HEIGHT-2*BORDER); if(cpp == context_defeated) mldesc->setText(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_YOU_WERE_DEFEATED)); else if(cpp == context_endgame && eg->reason == ER_CANCEL) mldesc->setText(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_GAME_WAS_CANCELED)); else if(cpp == context_endgame && eg->reason == ER_SHUTDOWN) mldesc->setText(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_SERVER_WAS_CLOSED)); else if(cpp == context_endgame && eg->reason == ER_VICTORY_DESTROY) mldesc->setText(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_WINNER_WON)); else if(cpp == context_endgame && eg->reason == ER_VICTORY_CONQUER) mldesc->setText(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_CITIES_CONQUERED)); else if(cpp == context_endgame && eg->reason == ER_VICTORY_TIMEOUT) mldesc->setText(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_AFTER_TIME_GAME_ENDS)); else if(cpp == context_endgame && eg->reason == ER_DRAW) mldesc->setText(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_DRAW_GAME)); gdescription->Add(mldesc); //tabulka gtable->Add(new TLabel(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_MENKILLED), 2*BORDER, TABLE_ROW_Y)); gtable->Add(new TLabel(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_MENLOST), 2*BORDER, TABLE_ROW_Y+TABLE_ROW_HEIGHT)); gtable->Add(new TLabel(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_UNITTRAINED), 2*BORDER, TABLE_ROW_Y+2*TABLE_ROW_HEIGHT)); gtable->Add(new TLabel(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_BUILDINGDESTROIED), 2*BORDER, TABLE_ROW_Y+3*TABLE_ROW_HEIGHT)); gtable->Add(new TLabel(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_BUILDINGLOST), 2*BORDER, TABLE_ROW_Y+4*TABLE_ROW_HEIGHT)); gtable->Add(new TLabel(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_BUILDINGBUILT), 2*BORDER, TABLE_ROW_Y+5*TABLE_ROW_HEIGHT)); gtable->Add(new TLabel(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_BUILDINANNEXED), 2*BORDER, TABLE_ROW_Y+6*TABLE_ROW_HEIGHT)); gtable->Add(new TLabel(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_MONEYEARNED), 2*BORDER, TABLE_ROW_Y+7*TABLE_ROW_HEIGHT)); // rm::TSymbolData* ss = TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 36); int players = (int)eg->players->size(); int col_width = (STATISTIC_WIDTH-4*BORDER-TABLE_FIRST_COL_WIDTH)/players; int ord = 0; // for(World::TPlayerContainer::iterator it = eg->players->begin(); it != eg->players->end(); it++) { int id = (*it).first; PLAYER* pl = &((*it).second->data()); int col_x = BORDER+TABLE_FIRST_COL_WIDTH+col_width*ord; TIcon* cr = new TIcon(ss, col_x + col_width/2 - ss->width/2, BORDER); cr->setColor( ColorPlayer[id][0]/255.f, ColorPlayer[id][1]/255.f, ColorPlayer[id][2]/255.f); gtable->Add(cr); // int j=0; snwprintf(wtemp, LABEL_MAX_LENGTH, L"%d", pl->statistics.units_killed); gtable->Add(new TLabel(wtemp, col_x, TABLE_ROW_Y+(j++)*TABLE_ROW_HEIGHT, col_width, TABLE_ROW_HEIGHT, 1)); snwprintf(wtemp, LABEL_MAX_LENGTH, L"%d", pl->statistics.units_lost); gtable->Add(new TLabel(wtemp, col_x, TABLE_ROW_Y+(j++)*TABLE_ROW_HEIGHT, col_width, TABLE_ROW_HEIGHT, 1)); snwprintf(wtemp, LABEL_MAX_LENGTH, L"%d", pl->statistics.units_created); gtable->Add(new TLabel(wtemp, col_x, TABLE_ROW_Y+(j++)*TABLE_ROW_HEIGHT, col_width, TABLE_ROW_HEIGHT, 1)); snwprintf(wtemp, LABEL_MAX_LENGTH, L"%d", pl->statistics.buildings_destroyed); gtable->Add(new TLabel(wtemp, col_x, TABLE_ROW_Y+(j++)*TABLE_ROW_HEIGHT, col_width, TABLE_ROW_HEIGHT, 1)); snwprintf(wtemp, LABEL_MAX_LENGTH, L"%d", pl->statistics.buildings_lost); gtable->Add(new TLabel(wtemp, col_x, TABLE_ROW_Y+(j++)*TABLE_ROW_HEIGHT, col_width, TABLE_ROW_HEIGHT, 1)); snwprintf(wtemp, LABEL_MAX_LENGTH, L"%d", pl->statistics.buildings_built); gtable->Add(new TLabel(wtemp, col_x, TABLE_ROW_Y+(j++)*TABLE_ROW_HEIGHT, col_width, TABLE_ROW_HEIGHT, 1)); snwprintf(wtemp, LABEL_MAX_LENGTH, L"%d", pl->statistics.buildings_captured); gtable->Add(new TLabel(wtemp, col_x, TABLE_ROW_Y+(j++)*TABLE_ROW_HEIGHT, col_width, TABLE_ROW_HEIGHT, 1)); snwprintf(wtemp, LABEL_MAX_LENGTH, L"%d", pl->statistics.money_gained); gtable->Add(new TLabel(wtemp, col_x, TABLE_ROW_Y+(j++)*TABLE_ROW_HEIGHT, col_width, TABLE_ROW_HEIGHT, 1)); //zatim nepouzito /* snwprintf(wtemp, L"%d", pl->statistics.towns_captured); gtable->Add(new TLabel(wtemp, col_x, TABLE_ROW_Y+(j++)*TABLE_ROW_HEIGHT, col_width, TABLE_ROW_HEIGHT, 1)); snwprintf(wtemp, L"%d", pl->statistics.towns_lost); gtable->Add(new TLabel(wtemp, col_x, TABLE_ROW_Y+(j++)*TABLE_ROW_HEIGHT, col_width, TABLE_ROW_HEIGHT, 1)); snwprintf(wtemp, L"%d", pl->statistics.kingdoms_captured); gtable->Add(new TLabel(wtemp, col_x, TABLE_ROW_Y+(j++)*TABLE_ROW_HEIGHT, col_width, TABLE_ROW_HEIGHT, 1)); snwprintf(wtemp, L"%d", pl->statistics.kingdoms_lost); gtable->Add(new TLabel(wtemp, col_x, TABLE_ROW_Y+(j++)*TABLE_ROW_HEIGHT, col_width, TABLE_ROW_HEIGHT, 1)); */ ord++; } // butony bmenu = new TSoundedTextButton(AO_NORMAL, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_MAINMENU), // (STATISTIC_WIDTH)/2-BORDER-BUTTON_WIDTH-BORDER-BUTTON_WIDTH/2, STATISTIC_HEIGHT-BORDER-BUTTON_HEIGHT, (STATISTIC_WIDTH-BUTTON_WIDTH)/2, STATISTIC_HEIGHT-BORDER-BUTTON_HEIGHT, BUTTON_WIDTH, BUTTON_HEIGHT, SAMPLE_CLICK); Add(bmenu); bmenu->setShortcutKey(SDLK_RETURN); //zatim nepouzito /* bnext = new TSoundedTextButton(AO_NORMAL, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_ANOTHERBATTLE), (STATISTIC_WIDTH)/2-BUTTON_WIDTH/2, STATISTIC_HEIGHT-BORDER-BUTTON_HEIGHT, BUTTON_WIDTH, BUTTON_HEIGHT, SAMPLE_CLICK); Add(bnext); brepeat = new TSoundedTextButton(AO_NORMAL, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_REPLAY), (STATISTIC_WIDTH)/2+BORDER+BORDER+BUTTON_WIDTH/2, STATISTIC_HEIGHT-BORDER-BUTTON_HEIGHT, BUTTON_WIDTH, BUTTON_HEIGHT, SAMPLE_CLICK); Add(brepeat); */ delete rmtxti; } /*****************************************************************************/ TFinalStatistic::TFinalStatistic(TContextParameter contextparameter) { //gui prvky statisticwindow = NULL; gamedisconnectedwindow = NULL; } TFinalStatistic::~TFinalStatistic() { // vypusti a odalokuje vsechny aktivni prvky v sobe (rekursivne) DelNFreeAll(); } TContext* TFinalStatistic::createContext(...){ TFinalStatistic* n = new TFinalStatistic(TContextParameter()); strcpy(n->szName,"FINALSTATISTIC"); return n; } void TFinalStatistic::activateContext(TContextParameter contextparameter) { // kdyz je kurzor na kraji obrazovky tak se nezmeni jeho obrazek na sipku TaoKernel::aoKernel->cursor->scrolling = false; // mozna se casem zmeni glClearColor(0, 0, 0, 1); if( contextparameter.iPrimary == context_disconnected ) { if (TSoundInterface::si) TSoundInterface::si->fadeoutMusic(5000); //wokno gamedisconnectedwindow = new TErrorWindow(TEXT_CONNECTIONLOST, ewtNotice, true); Add(gamedisconnectedwindow); } else if( contextparameter.iPrimary == context_endgame ) { // prehrej final theme (az bude najaka) if (TSoundInterface::si) TSoundInterface::si->playMusic(MUSIC_FINAL_THEME); //wokno statisticwindow = new TStatisticWindow(context_endgame, (TGuiEndGame*)contextparameter.iSecondary); Add(statisticwindow); } else if( contextparameter.iPrimary == context_defeated ) { if (TSoundInterface::si) TSoundInterface::si->fadeoutMusic(5000); //wokno statisticwindow = new TStatisticWindow(context_defeated, (TGuiEndGame*)contextparameter.iSecondary); Add(statisticwindow); } //smaz alokovany end game delete (TGuiEndGame*)contextparameter.iSecondary; } void TFinalStatistic::deactivateContext() { DelNFreeAll(); statisticwindow = NULL; gamedisconnectedwindow = NULL; } void TFinalStatistic::drawContext(){ TFrame::drawObject(); } int TFinalStatistic::workInput(INPUT *input) { int ret = TContext::workInput(input); // okno se statistikami if (statisticwindow) { if CLICKED(statisticwindow->bmenu) { TGUI::gui_inst->screen->selectContext("MAINMENU", TContextParameter(context_mainmenu, 0) ); KSendGlobalMsg(MSG_NET_STOP, ANNONYMOUS, MOD_NET, NULL); } //TODO: ostatni buttony } // okno disconnected if (gamedisconnectedwindow) { if CLICKED(gamedisconnectedwindow->bok) { TGUI::gui_inst->screen->selectContext("MAINMENU", TContextParameter(context_mainmenu, 0) ); KSendGlobalMsg(MSG_NET_STOP, ANNONYMOUS, MOD_NET, NULL); } } return ret; } }//namespace