File: pause_menu.cpp

package info (click to toggle)
warmux 1%3A11.04.1%2Brepack2-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid
  • size: 126,388 kB
  • sloc: cpp: 186,040; xml: 8,909; sh: 3,358; makefile: 1,052; ansic: 713
file content (168 lines) | stat: -rw-r--r-- 4,307 bytes parent folder | download | duplicates (4)
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/******************************************************************************
 *  Warmux is a convivial mass murder game.
 *  Copyright (C) 2001-2011 Warmux Team.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 ******************************************************************************
 * Pause Menu
 *****************************************************************************/

#include "menu/pause_menu.h"
//-----------------------------------------------------------------------------
#include <sstream>
#include <iostream>
#include <algorithm>  //std::transform
#include "game/config.h"
#include "graphic/font.h"
#include "graphic/video.h"
#include "gui/grid_box.h"
#include "gui/big/button_pic.h"
#include "include/app.h"
#include "menu/options_menu.h"
#include "menu/help_menu.h"
#include "tool/resource_manager.h"
#include "tool/xml_document.h"
//-----------------------------------------------------------------------------

PauseMenu::PauseMenu(bool& _exit_game)
  : Menu("interface/quit_screen", vNo)
  , exit_game(_exit_game)
  , sub_menu(NULL)
{
  Point2i size(100, 100);

  Box* box = new GridBox(2, 2, 5, true);

  bt_continue_play = new ButtonPic(_("Back to battle"),
                                   "menu/ico_back_to_battle", size);
  box->AddWidget(bt_continue_play);

  bt_options_menu = new ButtonPic(_("Options menu"),
                                  "menu/ico_options_menu", size);
  box->AddWidget(bt_options_menu);

  bt_help_menu = new ButtonPic(_("Help"), "menu/ico_help", size);
  box->AddWidget(bt_help_menu);

  bt_main_menu = new ButtonPic(_("Quit game"), "menu/ico_quit_battle", size);
  box->AddWidget(bt_main_menu);

  widgets.AddWidget(box);
  widgets.Pack();
  box->SetPosition((GetMainWindow().GetSize() - box->GetSize())/2);
  widgets.Pack();
}

PauseMenu::~PauseMenu()
{
}

void PauseMenu::BackToMainMenu()
{
  exit_game = true;
  close_menu = true;
}

void PauseMenu::BackToGame()
{
  exit_game = false;
  close_menu = true;
}

void PauseMenu::RunOptionsMenu()
{
  sub_menu = new OptionMenu();
  sub_menu->Run();
  sub_menu = NULL;
  close_menu = true;
}

void PauseMenu::RunHelpMenu()
{
  sub_menu = new HelpMenu();
  sub_menu->Run();
  sub_menu = NULL;
  close_menu = true;
}

bool PauseMenu::signal_ok()
{
  bool r = false;

  Widget * w = widgets.GetCurrentKeyboardSelectedWidget();
  if (w == bt_main_menu) {
    BackToMainMenu();
  } else if (w == bt_continue_play) {
    BackToGame();
  } else if (w == bt_options_menu) {
    RunOptionsMenu();
  } else if (w == bt_help_menu) {
    RunHelpMenu();
  }

  return r;
}

bool PauseMenu::signal_cancel()
{
  return false;
}


void PauseMenu::Draw(const Point2i& /*mousePosition*/)
{
}

void PauseMenu::OnClick(const Point2i &mousePosition, int button)
{
  widgets.Click(mousePosition, button);
}

void PauseMenu::OnClickUp(const Point2i &mousePosition, int button)
{
  widgets.ClickUp(mousePosition, button);

  if (Mouse::IS_CLICK_BUTTON(button)) {
    if (bt_main_menu->Contains(mousePosition)) {
      BackToMainMenu();
    } else if (bt_continue_play->Contains(mousePosition)) {
      BackToGame();
    } else if (bt_options_menu->Contains(mousePosition)) {
      RunOptionsMenu();
    } else if (bt_help_menu->Contains(mousePosition)) {
      RunHelpMenu();
    }
  }
}

void PauseMenu::RedrawMenu()
{
  if (sub_menu) {
    sub_menu->RedrawMenu();
  } else {
    Menu::RedrawMenu();
  }
}

void PauseMenu::DisplayError(const std::string &msg)
{
  if (sub_menu) {
    sub_menu->DisplayError(msg);
  } else {
    DisplayError(msg);
  }
}
  
//-----------------------------------------------------------------------------