File: StateMessageBox.cpp

package info (click to toggle)
xmoto 0.5.11%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 80,908 kB
  • sloc: cpp: 96,757; ansic: 22,196; sh: 4,940; makefile: 1,073; yacc: 289; sed: 16
file content (152 lines) | stat: -rw-r--r-- 4,430 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
/*=============================================================================
XMOTO

This file is part of XMOTO.

XMOTO 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.

XMOTO 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 XMOTO; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
=============================================================================*/

#include "StateMessageBox.h"
#include "../Game.h"
#include "../drawlib/DrawLib.h"
#include "../GameText.h"

void StateMessageBox::initStateMessageBox(StateMessageBoxReceiver* i_receiver,
					  const std::string& i_text,
					  int i_buttons,
					  bool i_input,
					  const std::string& i_inputText,
					  bool i_query,
					  bool i_verticallyLarge) {
    m_receiver      = i_receiver;
    m_clickedButton = UI_MSGBOX_NOTHING;
    m_name          = "StateMessageBox";
    m_msgbox        = NULL;

    m_text            = i_text;
    m_buttons         = i_buttons;
    m_input           = i_input;
    m_inputText       = i_inputText;
    m_query           = i_query;
    m_verticallyLarge = i_verticallyLarge;
}

StateMessageBox::StateMessageBox(StateMessageBoxReceiver* i_receiver,
				 const std::string& i_text,
				 int i_buttons,
				 bool i_input,
				 const std::string& i_inputText,
				 bool i_query,
				 bool drawStateBehind,
				 bool updateStatesBehind,
				 bool i_verticallyLarge):
  StateMenu(drawStateBehind,
	    updateStatesBehind)
{
  initStateMessageBox(i_receiver, i_text, i_buttons, i_input, i_inputText, i_query, i_verticallyLarge);
}

StateMessageBox::StateMessageBox(StateMessageBoxReceiver* i_receiver,
		  std::vector<std::string>& completionList,
  		  const std::string& i_text,
  		  int i_buttons,
  		  bool i_input,
  		  const std::string& i_inputText,
  		  bool i_query,
  		  bool drawStateBehind,
  		  bool updateStatesBehind,
  		  bool i_verticallyLarge) :
  		StateMenu(drawStateBehind,
  			    updateStatesBehind) {
 initStateMessageBox(i_receiver, i_text, i_buttons, i_input, i_inputText, i_query, i_verticallyLarge);
 m_completionList = completionList;
}

StateMessageBox::~StateMessageBox()
{
}

void StateMessageBox::makeActiveButton(UIMsgBoxButton i_button) {
  if(m_msgbox != NULL) {
    m_msgbox->makeActiveButton(i_button);
  } else {
    throw Exception("Active buttons can be set only once the state is entered");
  }
}

void StateMessageBox::enter() {
  createGUI();
  StateMenu::enter();
}

void StateMessageBox::leave()
{
  if(m_receiver != NULL) {
    m_receiver->sendFromMessageBox(getMsgBxId(), m_clickedButton, m_msgbox->getTextInput());
  } else {
    sendFromMessageBox(getMsgBxId(), m_clickedButton, m_msgbox->getTextInput());
  }

  delete m_GUI;
}

void StateMessageBox::checkEvents() {
  UIMsgBoxButton Button = m_msgbox->getClicked();

  if(Button == UI_MSGBOX_NOTHING)
    return;

  m_clickedButton = Button;

  m_requestForEnd = true;
}

void StateMessageBox::xmKey(InputEventType i_type, const XMKey& i_xmkey) {
  StateMenu::xmKey(i_type, i_xmkey);
}

void StateMessageBox::createGUI() {
  DrawLib* drawlib = GameApp::instance()->getDrawLib();

  m_GUI = new UIRoot(&m_screen);
  m_GUI->setFont(drawlib->getFontSmall()); 
  m_GUI->setPosition(0, 0,
		     m_screen.getDispWidth(),
		     m_screen.getDispHeight());

  m_msgbox = m_GUI->msgBox(m_text, (UIMsgBoxButton)(m_buttons), m_help, m_custom1, m_custom2, m_input, false, m_verticallyLarge);
  if(m_input) {
    m_msgbox->setTextInputFont(drawlib->getFontMedium());
    m_msgbox->setTextInput(m_inputText);
  }
  m_msgbox->addCompletionWord(m_completionList);
}

std::string StateMessageBox::getMsgBxId() const {
  return m_msgbxid;
}

void StateMessageBox::setMsgBxId(const std::string& i_id) {
  m_msgbxid = i_id;
}

void StateMessageBox::setCustom(const std::string& i_custom1, const std::string& i_custom2) {
  m_custom1 = i_custom1;
  m_custom2 = i_custom2;
}

void StateMessageBox::setHelp(const std::string& i_help) {
  m_help = i_help;
}