/*! * * @file drawMenu.cpp * @author SIMAILA Djalim * @author FABRE Lucas * @date January 2022 * @version 1.0 * @brief menu drawing functions * */ #include #include #include "mingl/shape/rectangle.h" #include "playMode.h" #include "pixelManager.h" #include "utils.h" using namespace nsShape; using namespace nsGraphics; void PixelManager::displayButton(const Position& baseVector,const string& text,nsGraphics::RGBAcolor& color){ window << Rectangle(baseVector, Position(180, 40)+baseVector, KGray); window << Rectangle(baseVector+Position(2,2), Position(178, 38)+baseVector, KBlack); window << nsGui::Text(baseVector+Position(10,22), text, color); } void PixelManager::displayMenu(const Position& pos, Menu& currentMenu){ startFrame(); drawSprite(menuBackground); drawSprite(logo,Position(100,50)); drawText(Position(1150, 700), "version 1.0.0"); size_t margin = 0; size_t cpt = 0; for(string& value : currentMenu.entries ){ displayButton(Position(0,0+margin)+ pos, value, (currentMenu.currentValue == cpt) ? currentMenu.selectedColor : currentMenu.unSelectedColor ); ++cpt; margin += 50; } endFrame(); } PlayMode PixelManager::showInitialMenu(){ vector entries {"single player","multi player (local)","exit"}; Menu initial {entries,0,nsGraphics::KRed,nsGraphics::KWhite}; unsigned xOffset = getScreenHeight() / 2 ; unsigned yOffset = getScreenWidth() / 2 - 90; chrono::milliseconds waitTime = chrono::milliseconds(100); while(window.isOpen()){ displayMenu(Position(yOffset,xOffset),initial); // go down if (window.isPressed({'s', false})){ ++initial.currentValue; if (initial.currentValue > initial.entries.size()-1) initial.currentValue = 0; this_thread::sleep_for(waitTime); } // go up if (window.isPressed({'z', false})){ if (initial.currentValue == 0) initial.currentValue = initial.entries.size()-1; else --initial.currentValue; this_thread::sleep_for(waitTime); }// select option else if (window.isPressed({13, false})){ switch(initial.currentValue){ case 0: return PlayMode::SINGLE; case 1: return PlayMode::TWO_LOCAL; case 2: return PlayMode::EXIT; default: return PlayMode::SINGLE; } } } exit(0); } void PixelManager::askPlayerNameMenu(playerID pID, unsigned score, string& name) { name = string(6, 'A'); size_t currentSelected = 0 ; chrono::milliseconds waitTime = chrono::milliseconds(100); while (window.isOpen()){ startFrame(); drawSprite(menuBackground); drawText(Position(600, 100), "Nom du joueur " + to_string(pID + 1)); drawText(Position(600, 150), "Score : " + to_string(score)); for (size_t i = 0; i < name.size(); ++i){ drawText(Position(600 + 30 * i, 200), string(1, name[i]), (i == currentSelected) ? nsGraphics::KRed : nsGraphics::KWhite); } endFrame(); // go down if (window.isPressed({'s', false})){ ++name[currentSelected]; if (name[currentSelected] > 90) name[currentSelected] = 65; this_thread::sleep_for(waitTime); } // go up if (window.isPressed({'z', false})){ --name[currentSelected]; if (name[currentSelected] < 65) name[currentSelected] = 90; this_thread::sleep_for(waitTime); } // go right if (window.isPressed({'d', false})){ ++currentSelected; if (currentSelected > name.size()-1) currentSelected = 0; this_thread::sleep_for(waitTime); } // go left if (window.isPressed({'q', false})){ if (currentSelected == 0) currentSelected = name.size()-1; else --currentSelected; this_thread::sleep_for(waitTime); } // select option else if (window.isPressed({13, false})) { window.resetKey({13, false}); return; } } exit(0); } bool PixelManager::showDeathMenu() { vector entries {"retry","main menu"}; Menu death {entries,0,nsGraphics::KRed,nsGraphics::KWhite}; unsigned xOffset = getScreenHeight() / 2 ; unsigned yOffset = getScreenWidth() / 2 - 90; chrono::milliseconds waitTime = chrono::milliseconds(100); while(window.isOpen()){ displayMenu(Position(yOffset,xOffset),death); // go down if (window.isPressed({'s', false})){ ++death.currentValue; if (death.currentValue > death.entries.size()-1) death.currentValue = 0; this_thread::sleep_for(waitTime); } // go up if (window.isPressed({'z', false})){ if (death.currentValue == 0) death.currentValue = death.entries.size()-1; else --death.currentValue; this_thread::sleep_for(waitTime); }// select option else if (window.isPressed({13, false})){ switch(death.currentValue){ case 0:{ return true; } case 1:{ window.resetKey({13, false}); return false; } } } } exit(0); }