Skip to content

Commit

Permalink
Remade Help Windows (had nsnakes helps, oops)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdantas committed Mar 21, 2014
1 parent 13aa712 commit cb4eeea
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 93 deletions.
4 changes: 1 addition & 3 deletions src/Game/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,20 @@ void Game::handleInput()
// Toggling Pause and Help window
if (this->isPaused)
{
this->isPaused = false;
this->showHelp = false;
this->timer.unpause();
this->timerPiece.unpause();
}
else
{
this->isPaused = true;
this->showHelp = true;
this->timer.pause();
this->timerPiece.pause();
}
}

// Other keys are not used when paused.
if (this->isPaused)
if (this->isPaused || this->showHelp)
{
this->pauseMenu->handleInput();
return;
Expand Down
6 changes: 3 additions & 3 deletions src/Game/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ Profile::Profile(std::string name):

// Theme

settings.theme.text = Colors::pair(COLOR_WHITE, COLOR_DEFAULT);
settings.theme.hilite_text = Colors::pair(COLOR_BLUE, COLOR_DEFAULT);
settings.theme.textbox = Colors::pair(COLOR_WHITE, COLOR_RED);
settings.theme.text = 0;
settings.theme.hilite_text = Colors::pair(COLOR_CYAN, COLOR_DEFAULT);
settings.theme.textbox = (settings.theme.hilite_text | A_REVERSE);

settings.theme.piece_has_colors = true;
settings.theme.ghost_has_colors = true;
Expand Down
62 changes: 18 additions & 44 deletions src/Interface/LayoutGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ LayoutGame::LayoutGame(Game* game, int width, int height):
middle_left(nullptr),
board(nullptr),
middle_right(nullptr),
rightmost(nullptr)
rightmost(nullptr),
helpWindows(nullptr)
{
this->windowsInit();
}
Expand Down Expand Up @@ -177,20 +178,7 @@ void LayoutGame::windowsInit()
}
this->pause->setTitle("Paused");

// Le help window.
this->help = new Window(this->main,
this->main->getW() / 4,
this->main->getH() / 4,
this->main->getW() / 2,
this->main->getH() / 2);
if (Globals::Profiles::current->settings.screen.show_borders)
{
this->help->borders(Globals::Profiles::current->settings.screen.fancy_borders ?
Window::BORDER_FANCY :
Window::BORDER_REGULAR);
}
this->help->setTitle("Help");

this->helpWindows = new WindowGameHelp();
}
void LayoutGame::windowsExit()
{
Expand All @@ -202,7 +190,7 @@ void LayoutGame::windowsExit()
SAFE_DELETE(this->middle_right);
SAFE_DELETE(this->rightmost);
SAFE_DELETE(this->pause);
SAFE_DELETE(this->help);
SAFE_DELETE(this->helpWindows);

for (unsigned int i = 0; i < this->next.size(); i++)
SAFE_DELETE(this->next[i]);
Expand All @@ -220,35 +208,21 @@ void LayoutGame::draw(Menu* menu)
return;

// Will only show the requested windows then exit.
if (this->game->isPaused)

if (this->game->isPaused && this->game->showPauseMenu)
{
if (this->game->showPauseMenu)
{
this->pause->clear();
menu->draw(this->pause);
this->pause->refresh();
}
else if (this->game->showHelp)
{
this->help->clear();
this->help->print("Game keys",
this->help->getW()/2 - 9/2, // center
1,
Globals::Profiles::current->settings.theme.hilite_text);

this->help->print_multiline("Arrow keys Move piece\n"
"Space bar Drop piece\n"
"z Rotate counterclockwise\n"
"x Rotate clockwise\n"
"c Hold piece\n"
"q Quit\n"
"p Pause/Unpause\n"
"h Show help",
1,
3,
Globals::Profiles::current->settings.theme.text);
this->help->refresh();
}
this->pause->clear();
menu->draw(this->pause);
this->pause->refresh();

refresh();
return;
}

if (this->game->showHelp)
{
this->helpWindows->run();
this->game->showHelp = false;

// NCURSES NEEDS THIS
refresh();
Expand Down
5 changes: 3 additions & 2 deletions src/Interface/LayoutGame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <Interface/Layout.hpp>
#include <Interface/Menu/Menu.hpp>
#include <Interface/WindowGameHelp.hpp>
#include <Game/Game.hpp>

#include <vector>
Expand Down Expand Up @@ -58,8 +59,8 @@ class LayoutGame: public Layout
/// Contains the pause menu.
Window* pause;

/// Contains the help screen.
Window* help;
private:
WindowGameHelp* helpWindows;
};

#endif //LAYOUTGAMEMODESURVIVAL_H_DEFINED
Expand Down
95 changes: 54 additions & 41 deletions src/Interface/WindowGameHelp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

WindowGameHelp::WindowGameHelp()
{
int width = 40;
int height = 15;
int width = 50;
int height = 20;

int windowx = Layout::screenWidth/2 - width/2;
int windowy = Layout::screenHeight/2 - height/2;
Expand Down Expand Up @@ -68,62 +68,75 @@ void WindowGameHelp::run()
// Help Window
if (activatedIndex == 0)
{
this->windows[0]->print_multiline("nSnake is the classical snake game\n"
"on the terminal.\n",
0, 0,
this->windows[0]->print_multiline("yetris: customizable Tetris(tm) clone\n"
" for the terminal.\n",
1, 1,
Globals::Profiles::current->settings.theme.text);

this->windows[0]->print_multiline("Controls:\n",
0, 3, Globals::Profiles::current->settings.theme.hilite_text);

this->windows[0]->print_multiline(" Move up\n"
" Move down\n"
" Move left\n"
" Move right\n"
" Pause game\n"
" Quit anytime\n"
" Show help\n",
10, 3,
1, 4, Globals::Profiles::current->settings.theme.hilite_text);

this->windows[0]->print_multiline(" Move Left\n"
" Move Right\n"
" Soft Drop\n"
" Hard Drop\n"
" Hold Piece\n"
" Rotate Clockwise\n"
" Rotate Counterclockwise\n"
" Show Help\n"
" Pause\n"
" Quit Anytime\n",
11, 4,
Globals::Profiles::current->settings.theme.hilite_text);

this->windows[0]->print_multiline(InputManager::keyToString(InputManager::getBind("up")) + "\n" +
InputManager::keyToString(InputManager::getBind("down")) + "\n" +
InputManager::keyToString(InputManager::getBind("left")) + "\n" +
this->windows[0]->print_multiline(InputManager::keyToString(InputManager::getBind("left")) + "\n" +
InputManager::keyToString(InputManager::getBind("right")) + "\n" +
InputManager::keyToString(InputManager::getBind("down")) + "\n" +
InputManager::keyToString(InputManager::getBind("drop")) + "\n" +
InputManager::keyToString(InputManager::getBind("hold")) + "\n" +
InputManager::keyToString(InputManager::getBind("rotate_clockwise")) + "\n" +
InputManager::keyToString(InputManager::getBind("rotate_counterclockwise")) + "\n" +
InputManager::keyToString(InputManager::getBind("help")) + "\n" +
InputManager::keyToString(InputManager::getBind("pause")) + "\n" +
InputManager::keyToString(InputManager::getBind("quit")) + "\n" +
InputManager::keyToString(InputManager::getBind("help")) + "\n",
24, 3,
InputManager::keyToString(InputManager::getBind("quit")) + "\n",
37, 4,
Globals::Profiles::current->settings.theme.text);

this->windows[0]->print_multiline(" Settings and scores are stored at:\n"
" ~/.local/share/nsnake/",
0, 11,
this->windows[0]->print_multiline("Your settings and scores are stored at:\n",
1, 16,
Globals::Profiles::current->settings.theme.text);

this->windows[0]->print_multiline("~/.local/share/yetris/" + Globals::Profiles::current->name,
0, 17,
Globals::Profiles::current->settings.theme.hilite_text);
}
//
// Credits
else if (activatedIndex == 1)
{
this->windows[1]->print_multiline(" _ __ _ __ _ ____ \n"
"| |\\ | ( (` | |\\ | / /\\ | |_/ | |_ \n"
"|_| \\| _)_) |_| \\| /_/--\\ |_| \\ |_|__ \n",
this->windows[1]->print_multiline(" ### ### ####### ####### ###### ####### #####\n"
" ### ### #### ### ### ### ### ### ###\n"
" ##### ###### ### ### ### ### ###\n"
" ### #### ### ###### ### ###\n"
" ### #### ### ### ### ### ### ###\n"
" ### ####### ### ### ### ####### #####\n",
0, 0, Colors::pair(COLOR_BLUE, COLOR_DEFAULT, true));

this->windows[1]->print_multiline(" v" VERSION " (built " DATE ")\n",
0, 3, Colors::pair(COLOR_GREEN, COLOR_DEFAULT, true));

this->windows[1]->print_multiline(
"\n"
"nSnake was made by Alexandre Dantas,\n"
"contact him at <[email protected]>\n"
"\n"
"Thanks for playing this game :)\n"
"\n"
"http://nsnake.alexdantas.net/\n"
"https://github.com/alexdantas/nsnake/",
1, 5, Globals::Profiles::current->settings.theme.text);

this->windows[1]->print_multiline(" v" VERSION " (built " DATE ")\n",
24, 6, Colors::pair(COLOR_GREEN, COLOR_DEFAULT, true));

this->windows[1]->print_multiline("yetris was created by Alexandre Dantas,\n"
"contact him at <[email protected]>\n"
"\n"
"Thanks for playing this game :)\n"
"\n"
"Homepage: http://nsnake.alexdantas.net/\n"
"\n"
"Source code and other contributors:\n"
"https://github.com/alexdantas/yetris/\n"
"\n"
"Support free software! http://www.gnu.org/",
1, 7, Globals::Profiles::current->settings.theme.text);
}

this->windows[activatedIndex]->refresh();
Expand Down

0 comments on commit cb4eeea

Please sign in to comment.