void GUI::getEndStats() { int nrOfStats = 8; this->nrOfBoxes = nrOfStats; this->textBoxes = new Text[this->nrOfBoxes]; char temp[255]; string Stats[8]; Stats[0] = "Level: " + getCurrentLevel(); Stats[1] = "Difficulty: "; Stats[1].append( convertWstrToStr( this->difficultyList[currentDifficulty] ) ); Stats[2] = "Resources: "; Stats[2].append( itoa(Statistics::Getinstance()->totalRes, temp, 10) ); Stats[3] = "Supplys: "; Stats[3].append (itoa(Statistics::Getinstance()->totalSupply, temp, 10) ); int totalTime = (int)Statistics::Getinstance()->totalTime; string time = "Time: "; int min = totalTime/60; int sek = totalTime%60; if(min != 0) { time.append( itoa(min, temp, 10) ); time.append(" min "); } time.append ( itoa(sek, temp, 10) ); time.append(" sek"); Stats[4] = time; Stats[5] = "Buildings built: "; Stats[5].append( itoa(Statistics::Getinstance()->totalNrOfBuildings, temp, 10) ); Stats[6] = "Enemies killed: "; Stats[6].append( itoa(Statistics::Getinstance()->totalEnemiesKilled, temp, 10) ); Stats[7] = "Nr of Upgrades: "; Stats[7].append( itoa(Statistics::Getinstance()->totalNrOfUpgrades, temp, 10) ); for(int i = 0; i < nrOfStats; i++) { wStats[i] = convertStrToWstr(Stats[i]); } this->textBoxes[0] = createTextBox(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(0.75f*SCREEN_HEIGHT)), (wchar_t*)wStats[0].c_str(), 18, 0xffffffff); this->textBoxes[1] = createTextBox(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(0.85f*SCREEN_HEIGHT)), (wchar_t*)wStats[1].c_str(), 18, 0xffffffff); this->textBoxes[2] = createTextBox(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(0.95f*SCREEN_HEIGHT)), (wchar_t*)wStats[2].c_str(), 18, 0xffffffff); this->textBoxes[3] = createTextBox(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(1.05f*SCREEN_HEIGHT)), (wchar_t*)wStats[3].c_str(), 18, 0xffffffff); this->textBoxes[4] = createTextBox(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(1.15f*SCREEN_HEIGHT)), (wchar_t*)wStats[4].c_str(), 18, 0xffffffff); this->textBoxes[5] = createTextBox(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(1.25f*SCREEN_HEIGHT)), (wchar_t*)wStats[5].c_str(), 18, 0xffffffff); this->textBoxes[6] = createTextBox(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(1.35f*SCREEN_HEIGHT)), (wchar_t*)wStats[6].c_str(), 18, 0xffffffff); this->textBoxes[7] = createTextBox(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(1.45f*SCREEN_HEIGHT)), (wchar_t*)wStats[7].c_str(), 18, 0xffffffff); }
// adds input text box to window void addTextBox(Interface *gui, GtkWidget *parentVbox) { // generates vertical box that holds items GtkWidget *vbox; vbox = gtk_vbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(parentVbox), vbox, FALSE, FALSE, 0); //generates input box frame GtkWidget *frame; frame = gtk_frame_new ("Write word"); gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); //create input box createTextBox(gui, frame); }
ChatBox createChatBox(int x, int y) { ChatBox box; int i; box.rect.x = x; box.rect.y = y; box.rect.h = DY * (NB_MSG); box.rect.w = CHAT_W; box.callback = NULL; box.update = false; for(i=0;i<NB_MSG;i++) { strcpy(box.text[i],""); // on met des espaces pour que les surface associƩ aient une taille box.messages[i] = createText(box.text[i],box.rect.x,box.rect.y + DY * i,10); } box.input = createTextBox("",box.rect.x,box.rect.y + DY * NB_MSG,10,20,15,false); return box; }
void GUI::createBtns(int state) { wchar_t* level = (wchar_t*)levelList[currentLevel].c_str(); wchar_t* difficulty = (wchar_t*)difficultyList[currentDifficulty].c_str(); if(state == STATE_MENU) { this->nrOfBtns = 3; this->menuBtns = new Button[nrOfBtns]; this->menuBtns[0] = createBtn(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(0.7f*SCREEN_HEIGHT)), STARTGAME); this->menuBtns[1] = createBtn(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(0.9f*SCREEN_HEIGHT)), SETTINGS); this->menuBtns[2] = createBtn(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(1.1f*SCREEN_HEIGHT)), QUIT); } else if(state == STATE_SETTINGS) { this->nrOfBtns = 2; this->menuBtns = new Button[nrOfBtns]; this->menuBtns[0] = createBtn(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(0.7f*SCREEN_HEIGHT)), MUTE); this->menuBtns[1] = createBtn(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(1.5f*SCREEN_HEIGHT)), BACK); } else if(state == STATE_PAUSED) { this->nrOfBtns = 3; this->menuBtns = new Button[nrOfBtns]; this->menuBtns[0] = createBtn(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(0.7f*SCREEN_HEIGHT)), PAUSED_CONTINUE); this->menuBtns[1] = createBtn(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(0.9f*SCREEN_HEIGHT)), SETTINGS); this->menuBtns[2] = createBtn(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(1.1f*SCREEN_HEIGHT)), MAIN_MENU); for(int i = 0; i < this->nrOfBtns; i++) { setLeftAligned(this->menuBtns[i].text); } } else if(state == STATE_NEWGAME) { int time = Statistics::Getinstance()->readScoreFromFile("highscore.txt", convertWstrToStr(level)+".txt"); char temp[255]; string score = itoa(time, temp, 10); if(score == "0") { score = "No score set yet."; } else { string best = "Best time: "; int min = time/60; int sek = time%60; if(min != 0) { best.append( itoa(min, temp, 10) ); best.append(" min "); } best.append ( itoa(sek, temp, 10) ); best.append(" sek"); score = best; } bestTime = convertStrToWstr(score); this->nrOfBoxes = 3; this->textBoxes = new Text[nrOfBoxes]; this->textBoxes[0] = createTextBox(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(0.7f*SCREEN_HEIGHT)), level, 36, 0xffa8a8a8); this->textBoxes[1] = createTextBox(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(0.9f*SCREEN_HEIGHT)), difficulty, 36, 0xffa8a8a8); this->textBoxes[2] = createTextBox(D3DXVECTOR2(0.5f*(0.4f*SCREEN_WIDTH),0.5f*(1.1f*SCREEN_HEIGHT)), (wchar_t*)bestTime.c_str(), 24, 0xffa8a8a8); this->nrOfBtns = 6; this->menuBtns = new Button[nrOfBtns]; this->menuBtns[0] = createBtn(D3DXVECTOR2(textBoxes[0].pos.x - 80, textBoxes[0].pos.y), LAST); this->menuBtns[1] = createBtn(D3DXVECTOR2(textBoxes[0].pos.x + 80, textBoxes[0].pos.y), NEXT); this->menuBtns[2] = createBtn(D3DXVECTOR2(textBoxes[1].pos.x - 80, textBoxes[1].pos.y), LAST); this->menuBtns[3] = createBtn(D3DXVECTOR2(textBoxes[1].pos.x + 80, textBoxes[1].pos.y), NEXT); this->menuBtns[4] = createBtn(D3DXVECTOR2(0.4f*(0.5*SCREEN_WIDTH),0.5f*(1.45f*SCREEN_HEIGHT)), STARTGAME); this->menuBtns[5] = createBtn(D3DXVECTOR2(0.4f*(0.5*SCREEN_WIDTH),0.5f*(1.6f*SCREEN_HEIGHT)), BACK); } else if(state == STATE_LOADING) { this->nrOfBoxes = 1; this->textBoxes = new Text[nrOfBoxes]; this->textBoxes[0] = createTextBox(D3DXVECTOR2(0.5f*(1*SCREEN_WIDTH),0.5f*(1*SCREEN_HEIGHT)), L"LOADING", 150, 0xffa8a8a8); } else if(state == STATE_WIN) { getEndStats(); this->nrOfBoxes+=1; Text* temp = new Text[this->nrOfBoxes]; for(int i = 0; i < this->nrOfBoxes-1; i++) { temp[i] = this->textBoxes[i]; } delete []this->textBoxes; this->textBoxes = NULL; this->textBoxes = temp; for(int i = 0; i < 8; i++) { setLeftAligned(this->textBoxes[i]); } this->textBoxes[8] = createTextBox(D3DXVECTOR2(0.5f*(1*SCREEN_WIDTH),0.5f*(0.55f*SCREEN_HEIGHT)), L"You Won!", 62, 0xffa8a8a8); this->nrOfBtns =2; this->menuBtns = new Button[nrOfBtns]; this->menuBtns[0] = createBtn(D3DXVECTOR2(0.5f*(0.8f*SCREEN_WIDTH),0.5f*(1.6f*SCREEN_HEIGHT)), MAIN_MENU); this->menuBtns[1] = createBtn(D3DXVECTOR2(0.5f*(1.2f*SCREEN_WIDTH),0.5f*(1.6f*SCREEN_HEIGHT)), RETRY); Statistics::Getinstance()->writeScoreToFile( "highscore.txt" ); } else if(state == STATE_LOSE) { getEndStats(); this->nrOfBoxes+=1; Text* temp = new Text[this->nrOfBoxes]; for(int i = 0; i < this->nrOfBoxes-1; i++) { temp[i] = this->textBoxes[i]; } delete []this->textBoxes; this->textBoxes = NULL; this->textBoxes = temp; for(int i = 0; i < 8; i++) { setLeftAligned(this->textBoxes[i]); } this->textBoxes[8] = createTextBox(D3DXVECTOR2(0.5f*(1*SCREEN_WIDTH),0.5f*(0.55f*SCREEN_HEIGHT)), L"You Lost", 62, 0xffa8a8a8); this->nrOfBtns = 2; this->menuBtns = new Button[nrOfBtns]; this->menuBtns[0] = createBtn(D3DXVECTOR2(0.5f*(0.8f*SCREEN_WIDTH),0.5f*(1.6f*SCREEN_HEIGHT)), MAIN_MENU); this->menuBtns[1] = createBtn(D3DXVECTOR2(0.5f*(1.2f*SCREEN_WIDTH),0.5f*(1.6f*SCREEN_HEIGHT)), RETRY); } }
void GUI::setInGameText(int resource, int supply, int nrOfBuildings, int goal, int selectedStructure) { string name; string purpose; int cost; string typeOfCost; if(selectedStructure == BUILDABLE_MAINBUILDING) { name = "Headquarter"; purpose = "Base"; cost = 0; currentBuilding = TEXTURE_MAINBUILDING; typeOfCost = "Cost: "; } else if(selectedStructure == BUILDABLE_SUPPLY) { name = "Supply"; purpose = "Give supply"; cost = COST_SUPPLY; currentBuilding = TEXTURE_SUPPLY; typeOfCost = "Resource: "; } else if(selectedStructure == BUILDABLE_TOWER) { name = "Tower"; purpose = "Offensive structure"; cost = COST_TOWER; currentBuilding = TEXTURE_TOWER; typeOfCost = "Supply: "; } else if(selectedStructure == BUILDABLE_UPGRADE_OFFENSE) { name = "Offensive"; purpose = "Upgrade"; cost = COST_UPGRADE; currentBuilding = TEXTURE_ATK; typeOfCost = "Resource: "; } else if(selectedStructure == BUILDABLE_UPGRADE_DEFENSE) { name = "Defensive"; purpose = "Upgrade"; cost = COST_UPGRADE; currentBuilding = TEXTURE_DEF; typeOfCost = "Resource: "; } else if(selectedStructure == BUILDABLE_UPGRADE_RES) { name = "Resources"; purpose = "Increase res/kill"; cost = COST_UPGRADE; currentBuilding = TEXTURE_MONEY; typeOfCost = "Resource: "; } if(first) { this->nrOfBoxes = 16; this->textBoxes = new Text[this->nrOfBoxes]; first = false; } char temp[255]; string Stats[8]; Stats[0] = itoa(resource, temp, 10); Stats[1] = itoa(supply, temp, 10); Stats[2] = itoa((int)Statistics::Getinstance()->totalTime, temp, 10); Stats[3] = "Built: "; Stats[3].append( itoa(nrOfBuildings, temp, 10) ); Stats[4] = "Goal: "; Stats[4].append( itoa(goal, temp, 10) ); Stats[5] = name; Stats[6] = purpose; Stats[7] = typeOfCost; Stats[7].append( itoa(cost, temp, 10) ); for(int i = 0; i < 8; i++) { wStats[i] = convertStrToWstr(Stats[i]); } this->textBoxes[0] = createTextBox(D3DXVECTOR2(0.5f*(1*SCREEN_WIDTH),0.5f*(1.7f*SCREEN_HEIGHT)), (wchar_t*)wStats[0].c_str(), 18, 0xffffffff); this->textBoxes[1] = createTextBox(D3DXVECTOR2(0.5f*(1*SCREEN_WIDTH),0.5f*(1.875f*SCREEN_HEIGHT)), (wchar_t*)wStats[1].c_str(), 18, 0xffffffff); this->textBoxes[2] = createTextBox(D3DXVECTOR2(0.5f*(1.3f*SCREEN_WIDTH),0.5f*(1.7f*SCREEN_HEIGHT)), (wchar_t*)wStats[2].c_str(), 18, 0xffffffff); this->textBoxes[3] = createTextBox(D3DXVECTOR2(0.5f*(1.65f*SCREEN_WIDTH),0.5f*(1.7f*SCREEN_HEIGHT)), (wchar_t*)wStats[3].c_str(), 18, 0xffffffff); this->textBoxes[4] = createTextBox(D3DXVECTOR2(0.5f*(1.85f*SCREEN_WIDTH),0.5f*(1.7f*SCREEN_HEIGHT)), (wchar_t*)wStats[4].c_str(), 18, 0xffffffff); this->textBoxes[5] = createTextBox(D3DXVECTOR2(0.5f*(0.5f*SCREEN_WIDTH),0.5f*(1.7f*SCREEN_HEIGHT)), (wchar_t*)wStats[5].c_str(), 18, 0xffffffff); this->textBoxes[6] = createTextBox(D3DXVECTOR2(0.5f*(0.51f*SCREEN_WIDTH),0.5f*(1.8f*SCREEN_HEIGHT)), (wchar_t*)wStats[6].c_str(), 14, 0xffffffff); this->textBoxes[7] = createTextBox(D3DXVECTOR2(0.5f*(0.5f*SCREEN_WIDTH),0.5f*(1.9f*SCREEN_HEIGHT)), (wchar_t*)wStats[7].c_str(), 14, 0xffffffff); this->textBoxes[8] = createTextBox(D3DXVECTOR2(0.5f*(0.8f*SCREEN_WIDTH),0.5f*(1.7f*SCREEN_HEIGHT)), L"Resource:", 18, 0xffffffff); this->textBoxes[9] = createTextBox(D3DXVECTOR2(0.5f*(0.775f*SCREEN_WIDTH),0.5f*(1.875f*SCREEN_HEIGHT)), L"Supply:", 18, 0xffffffff); this->textBoxes[10] = createTextBox(D3DXVECTOR2(0.5f*(1.2f*SCREEN_WIDTH),0.5f*(1.7f*SCREEN_HEIGHT)), L"Time:", 18, 0xffffffff); this->textBoxes[11] = createTextBox(D3DXVECTOR2(0.5f*(1.24f*SCREEN_WIDTH),0.5f*(1.84f*SCREEN_HEIGHT)), L"1", 20, 0xffffffff); this->textBoxes[12] = createTextBox(D3DXVECTOR2(0.5f*(1.42f*SCREEN_WIDTH),0.5f*(1.84f*SCREEN_HEIGHT)), L"2", 20, 0xffffffff); this->textBoxes[13] = createTextBox(D3DXVECTOR2(0.5f*(1.6f*SCREEN_WIDTH),0.5f*(1.84f*SCREEN_HEIGHT)), L"3", 20, 0xffffffff); this->textBoxes[14] = createTextBox(D3DXVECTOR2(0.5f*(1.775f*SCREEN_WIDTH),0.5f*(1.84f*SCREEN_HEIGHT)), L"4", 20, 0xffffffff); this->textBoxes[15] = createTextBox(D3DXVECTOR2(0.5f*(1.95f*SCREEN_WIDTH),0.5f*(1.84f*SCREEN_HEIGHT)), L"5", 20, 0xffffffff); this->panels[0].textureID = currentBuilding; }