1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23
24 #include "ultima/nuvie/core/nuvie_defs.h"
25
26 #include "ultima/nuvie/gui/gui.h"
27 #include "ultima/nuvie/gui/gui_button.h"
28 #include "ultima/nuvie/gui/gui_text.h"
29
30 #include "ultima/nuvie/gui/gui_dialog.h"
31 #include "ultima/nuvie/gui/gui_yes_no_dialog.h"
32 #include "ultima/nuvie/keybinding/keys.h"
33
34 namespace Ultima {
35 namespace Nuvie {
36
GUI_YesNoDialog(GUI * gui,int x,int y,int w,int h,const char * msg,CallBack * yesCallback,CallBack * noCallback)37 GUI_YesNoDialog::GUI_YesNoDialog(GUI *gui, int x, int y, int w, int h, const char *msg,
38 CallBack *yesCallback, CallBack *noCallback) :
39 GUI_Dialog(x, y, w, h, 244, 216, 131, GUI_DIALOG_MOVABLE) {
40 GUI_Widget *widget;
41 b_index_num = -1;
42
43 yes_callback_object = yesCallback;
44 no_callback_object = noCallback;
45
46 yes_button = new GUI_Button(this, 100, 50, 40, 18, "Yes", gui->get_font(), BUTTON_TEXTALIGN_CENTER, 0, this, 0);
47 AddWidget(yes_button);
48 button_index[0] = yes_button;
49
50 no_button = new GUI_Button(this, 30, 50, 40, 18, "No", gui->get_font(), BUTTON_TEXTALIGN_CENTER, 0, this, 0);
51 AddWidget(no_button);
52 button_index[1] = no_button;
53
54 widget = (GUI_Widget *) new GUI_Text(10, 25, 0, 0, 0, msg, gui->get_font());
55 AddWidget(widget);
56 }
57
58
~GUI_YesNoDialog()59 GUI_YesNoDialog::~GUI_YesNoDialog() {
60 }
61
KeyDown(const Common::KeyState & key)62 GUI_status GUI_YesNoDialog::KeyDown(const Common::KeyState &key) {
63 if (key.keycode == Common::KEYCODE_y)
64 return (GUI_status)yes_callback_object->callback(YESNODIALOG_CB_YES, nullptr);
65
66 KeyBinder *keybinder = Game::get_game()->get_keybinder();
67 ActionType a = keybinder->get_ActionType(key);
68
69 switch (keybinder->GetActionKeyType(a)) {
70 case EAST_KEY:
71 case WEST_KEY:
72 if (b_index_num != -1)
73 button_index[b_index_num]->set_highlighted(false);
74
75 if (b_index_num == 0)
76 b_index_num = 1;
77 else
78 b_index_num = 0;
79 button_index[b_index_num]->set_highlighted(true);
80 return GUI_YUM;
81 case DO_ACTION_KEY:
82 if (b_index_num != -1)
83 return button_index[b_index_num]->Activate_button();
84 break;
85 default:
86 break;
87 }
88
89 return (GUI_status)no_callback_object->callback(YESNODIALOG_CB_NO, nullptr, this);
90 }
91
callback(uint16 msg,GUI_CallBack * caller,void * data)92 GUI_status GUI_YesNoDialog::callback(uint16 msg, GUI_CallBack *caller, void *data) {
93 if (caller == yes_button)
94 return (GUI_status)yes_callback_object->callback(YESNODIALOG_CB_YES, nullptr);
95
96 if (caller == no_button)
97 return (GUI_status)no_callback_object->callback(YESNODIALOG_CB_NO, nullptr, this);
98
99 return GUI_PASS;
100 }
101
102 } // End of namespace Nuvie
103 } // End of namespace Ultima
104