diff --git a/headers/pixelManager.h b/headers/pixelManager.h index 5394ccd..4f5d988 100644 --- a/headers/pixelManager.h +++ b/headers/pixelManager.h @@ -183,6 +183,8 @@ public: PlayMode showInitialMenu(); PlayMode showDeathMenu(); + string nameMenu(playerID pID); + unsigned getScreenHeight() const; unsigned getScreenWidth() const; @@ -205,7 +207,7 @@ public: * @param[] * @fn */ - void askPlayerNameMenu(playerID pID, string& name) const; + void askPlayerNameMenu(playerID pID, string& name); // y will be negative sometimes, so not unsigned diff --git a/src/drawEntity.cpp b/src/drawEntity.cpp index 4760d33..063a7de 100644 --- a/src/drawEntity.cpp +++ b/src/drawEntity.cpp @@ -69,9 +69,9 @@ void PixelManager::drawPlayer(unsigned x, unsigned width, const nsGraphics::RGBA window << Triangle(Position(15+width+x,720-PLAYER_HEIGHT/2), Position(15+width*2+x,720-PLAYER_HEIGHT/2), Position(15+width+x,720-PLAYER_HEIGHT*0.9), color); } -void PixelManager::askPlayerNameMenu(playerID pID, string& name) const { +void PixelManager::askPlayerNameMenu(playerID pID, string& name) { cout << "ask for player " << (pID+1) << endl; - name = "Thomas"; + name = nameMenu(pID); } void PixelManager::drawMissile(const Position& baseVector, unsigned width, const nsGraphics::RGBAcolor& color) const { @@ -140,7 +140,7 @@ void PixelManager::drawGodFace(int y, bool angry) const { } void PixelManager::displayText(const Position& pos, const string& text,const nsGraphics::RGBAcolor& color) const { - window << Text(pos, text, color); + window << Text(pos, text, color, GlutFont::GlutFonts::BITMAP_TIMES_ROMAN_24); } void PixelManager::drawFPS(unsigned fps) const { diff --git a/src/drawMenu.cpp b/src/drawMenu.cpp index 19d64f8..3f0064c 100644 --- a/src/drawMenu.cpp +++ b/src/drawMenu.cpp @@ -30,6 +30,7 @@ void PixelManager::displayMenu(const Position& pos, Menu& currentMenu){ startFrame(); drawMenuBackground(); drawSprite(logo,Position(100,50)); + displayText(Position(1150,700), "version 1.0.0"); size_t margin = 0; size_t cpt = 0; for(string& value : currentMenu.entries ){ @@ -47,7 +48,7 @@ PlayMode PixelManager::showInitialMenu(){ const unsigned yOffset = getScreenWidth() / 2 - 90; chrono::milliseconds waitTime = chrono::milliseconds(100); while(true){ - displayMenu(Position(yOffset,xOffset),initial); + displayMenu(Position(yOffset,xOffset),initial); // go down if (window.isPressed({'s', false})){ ++initial.currentValue; @@ -75,6 +76,50 @@ PlayMode PixelManager::showInitialMenu(){ } } +string PixelManager::nameMenu(playerID pID){ + string name (6,'A'); + size_t currentSelected = 0 ; + chrono::milliseconds waitTime = chrono::milliseconds(100); + while (true){ + startFrame(); + drawMenuBackground(); + displayText(Position(600,100),"Nom du joueur "+ string(1,pID)); + for (size_t i = 0; i < name.size(); ++i){ + displayText(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})) + { + this_thread::sleep_for(waitTime); + return name; + } + } +} PlayMode PixelManager::showDeathMenu() { vector entries {"main menu","exit"};