nsnake
Classic snake game for the terminal
Loading...
Searching...
No Matches
LayoutMainMenu.cpp
1#include <Interface/LayoutMainMenu.hpp>
2#include <Interface/Colors.hpp>
3#include <Interface/Ncurses.hpp>
4#include <Config/Globals.hpp>
5#include <Misc/Utils.hpp>
6#include <Flow/GameStateMainMenu.hpp>
7#include <Interface/Animation/AnimationSnakes.hpp>
8
9#include <iostream>
10
11LayoutMainMenu::LayoutMainMenu(int width, int height, GameStateMainMenu* state):
12 Layout(width, height),
13 state(state),
14 logo(NULL),
15 menu(NULL),
16 animationwin(NULL),
17 animation(NULL)
18{
19 this->windowsInit();
20}
21LayoutMainMenu::~LayoutMainMenu()
22{
23 this->windowsExit();
24}
25void LayoutMainMenu::windowsInit()
26{
27 Layout::windowsInit();
28
29 // LOGO
30 this->logo = new Window(this->main,
31 0,
32 0,
33 56,
34 7);
35
36 // MENU
37 this->menu = new Window(this->main,
38 55,
39 0,
40 24,
41 WINDOW_FILL);
42 this->menu->setTitle("Main Menu");
43
44 if (Globals::Screen::show_borders)
45 {
46 this->menu->borders(Globals::Screen::fancy_borders ?
47 Window::BORDER_FANCY :
48 Window::BORDER_REGULAR);
49 }
50 this->menu->refresh();
51
52 // ANIMATION
53 this->animationwin = new Window(this->main,
54 0,
55 this->logo->getH(),
56 this->logo->getW(),
57 this->main->getH() - this->logo->getH() - 1);
58
59 this->animation = new AnimationSnakes(this->animationwin);
60 this->animation->load();
61}
62void LayoutMainMenu::windowsExit()
63{
64 SAFE_DELETE(this->menu);
65 SAFE_DELETE(this->logo);
66 SAFE_DELETE(this->animationwin);
67 SAFE_DELETE(this->animation);
68
69 Layout::windowsExit();
70}
72{
73 this->animation->update();
74
75 this->main->clear();
76
77 this->animation->draw();
78
79 this->logo->clear();
80 this->logo->print(Utils::String::split(" __ _ _______ __ _ _______ ___ _ _______\n"
81 "| | | || || | | || _ || | | || |\n"
82 "| |_| || _____|| |_| || |_| || |_| || ___|\n"
83 "| || |_____ | || || _|| |___ \n"
84 "| _ ||_____ || _ || || |_ | ___|\n"
85 "| | | | _____| || | | || _ || _ || |___ \n"
86 "|_| |__||_______||_| |__||__| |__||___| |_||_______|", '\n'),
87 0,
88 0,
89 Colors::pair(COLOR_GREEN, COLOR_DEFAULT, true));
90
91 this->logo->refresh();
92
93 // Yay!
94 this->menu->clear();
95
96 menu->draw(this->menu);
97
98 this->menu->refresh();
99
100 this->main->refresh();
101
102 // NCURSES NEEDS THIS
103 refresh();
104}
105
Rules and behavior of the Fire animation.
virtual void draw()=0
Shows Animation on the screen.
virtual void update()=0
Updates Animation's internal state.
virtual void load()=0
Loads all internal things.
void draw(Menu *menu)
Shows the Main Menu screen, along with drawing menu.
Animation * animation
Cure thing at the main menu.
Interface for how the things are shown on the screen.
Definition Layout.hpp:16
Window * main
Layout's main Window, where all the others are inside.
Definition Layout.hpp:33
List of selectable items.
Definition Menu.hpp:29
void draw(Window *window)
Draws the whole Menu on #window.
Definition Menu.cpp:95
A segment of the terminal screen (2D char matrix).
Definition Window.hpp:17
void setTitle(std::string title, WindowTitlePosition position=Window::TOP_LEFT)
Sets a text that will appear at the top of the Window.
Definition Window.cpp:214
void print(std::string str, int x, int y, ColorPair pair=0)
Shows text #str at x y on the window with color #pair.
Definition Window.cpp:94