File: menumanager.cpp

package info (click to toggle)
qonk 0.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 2,076 kB
  • ctags: 2,026
  • sloc: cpp: 14,978; sh: 3,464; makefile: 200
file content (147 lines) | stat: -rw-r--r-- 3,839 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "menumanager.h"

#include "ui/menusystem.h"
#include "ui/menu.h"
#include "ui/menuaction.h"

#include "controloptions.h"
#include "gameoptions.h"
#include "videooptions.h"

#include "input.h"
#include "main.h"
#include "sdl_driver.h"

MenuManager::MenuManager(Main &newMain)
  : main(newMain)
{
  menuSystem = new MenuSystem(main.getSDLDriver().getSDLInput());

  controlOptions = new ControlOptions(main);
  videoOptions = new VideoOptions();
  gameOptions = new GameOptions();

  Menu *m = new Menu(Menu::NONE, "qonk");
  m->addLink("singleplayer", Menu::SINGLEPLAYER);
  m->addLink("multiplayer", Menu::MULTIPLAYER);
  m->addLink("options", Menu::OPTIONS);
  m->addAction("quit", new QuitAction(main));
  menuSystem->addMenu(Menu::MAIN, m);

  m = new Menu(Menu::MAIN, "singleplayer");
  m->addAction("planets", gameOptions->getPlanetsAction());
  m->addAction("enemies", gameOptions->getPlayersAction());
  m->addAction("show enemies", gameOptions->getEnemyVisibilityAction());
  m->addAction("start game", gameOptions->getStartSinglePlayerGameAction(main));
  m->addBackLink();
  menuSystem->addMenu(Menu::SINGLEPLAYER, m);

  m = new Menu(Menu::MAIN, "multiplayer");
  m->addLink("this is not", Menu::NONE);
  m->addLink("yet implemented.", Menu::NONE);
  m->addBackLink();
  menuSystem->addMenu(Menu::MULTIPLAYER, m);

  m = new Menu(Menu::MAIN, "options");
  m->addLink("audio", Menu::AUDIO_OPTIONS);
  m->addLink("video", Menu::VIDEO_OPTIONS);
  m->addLink("controls", Menu::CONTROL_OPTIONS);
  m->addBackLink();
  menuSystem->addMenu(Menu::OPTIONS, m);

  m = new Menu(Menu::OPTIONS, "audio");
  m->addLink("this is not", Menu::NONE);
  m->addLink("yet implemented.", Menu::NONE);
  m->addBackLink();
  menuSystem->addMenu(Menu::AUDIO_OPTIONS, m);

  m = new Menu(Menu::OPTIONS, "video");
  m->addAction("screen size:", videoOptions->getScreenSizeAction());
  m->addAction("toggle fullscreen", videoOptions->getToggleFullscreenAction());
  m->addAction("apply", videoOptions->getApplyVideoOptionsAction(main));
  m->addBackLink();
  menuSystem->addMenu(Menu::VIDEO_OPTIONS, m);

  m = new Menu(Menu::OPTIONS, "controls", 10);
  m->addAction("select all", controlOptions->getControlAction(GA_SELECT_ALL));
  m->addAction("show enemies", controlOptions->getControlAction(GA_TOGGLE_ENEMY_VISIBILITY));
  m->addAction("selection", controlOptions->getControlAction(GA_SELECTION));
  m->addAction("cursor up", controlOptions->getControlAction(GA_CURSOR_UP));
  m->addAction("cursor down", controlOptions->getControlAction(GA_CURSOR_DOWN));
  m->addAction("cursor left", controlOptions->getControlAction(GA_CURSOR_LEFT));
  m->addAction("cursor right", controlOptions->getControlAction(GA_CURSOR_RIGHT));
  m->addAction("select nearest", controlOptions->getControlAction(GA_SELECT_NEAREST_PLANET));
  m->addAction("move to nearest", controlOptions->getControlAction(GA_MOVE_TO_NEAREST_PLANET));
  m->addAction("single ship mode", controlOptions->getControlAction(GA_SET_FLEET_STRENGTH_SINGLE));
  m->addBackLink();
  menuSystem->addMenu(Menu::CONTROL_OPTIONS, m);

  menuSystem->resize();

  menuSystem->enter();
}

MenuManager::~MenuManager()
{
  delete menuSystem;

  delete gameOptions;
  delete videoOptions;
}

void
MenuManager::showSinglePlayerMenu()
{
  menuSystem->enter(Menu::SINGLEPLAYER);
}

void
MenuManager::show()
{
  menuSystem->enter();
}

void
MenuManager::hide()
{
  menuSystem->enter(Menu::NONE);
}

bool
MenuManager::isVisible() const
{
  return menuSystem->isVisible();
}

void
MenuManager::resize()
{
  menuSystem->resize();
}

void
MenuManager::render()
{
  menuSystem->render();
}

bool
MenuManager::update()
{
  return menuSystem->update();
}

void
MenuManager::senseFinished(bool b)
{
  if (b)
    menuSystem->invoke();
  else
    menuSystem->cancel();
}

void
QuitAction::invoke()
{
  main.quit();
}