2
* Copyright (C) 2002-4 by the Widelands Development Team
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
#include "event_message_box_option_menu.h"
21
#include "event_message_box.h"
22
#include "event_message_box_option_menu_pic_options.h"
23
#include "ui_window.h"
24
#include "ui_textarea.h"
25
#include "ui_button.h"
26
#include "ui_checkbox.h"
27
#include "ui_editbox.h"
28
#include "ui_multilineeditbox.h"
29
#include "ui_listselect.h"
30
#include "editorinteractive.h"
35
#include "trigger_null.h"
37
Event_Message_Box_Option_Menu::Event_Message_Box_Option_Menu(Editor_Interactive* parent, Event_Message_Box* event) :
38
UIWindow(parent, 0, 0, 430, 400, "Event Option Menu") {
43
UITextarea* tt=new UITextarea(this, 0, 0, "Message Box Event Options", Align_Left);
44
tt->set_pos((get_inner_w()-tt->get_w())/2, 5);
51
m_nr_buttons=m_event->get_nr_buttons();
53
m_picid=m_event->get_pic_id();
54
m_position=m_event->get_pic_position();
55
if(static_cast<int>(m_picid)!=-1)
56
m_clrkey=g_gr->has_clrkey(m_picid);
60
m_buttons[0].name="Continue";
61
m_buttons[1].name="Button 1";
62
m_buttons[2].name="Button 2";
63
m_buttons[3].name="Button 3";
64
m_buttons[0].trigger=m_buttons[1].trigger=m_buttons[2].trigger=m_buttons[3].trigger=-1;
68
new UITextarea(this, spacing, posy, 50, 20, "Name:", Align_CenterLeft);
69
m_name=new UIEdit_Box(this, spacing+60, posy, get_inner_w()/2-60-2*spacing, 20, 0, 0);
70
m_name->set_text(event->get_name());
73
new UITextarea(this, get_inner_w()/2+spacing, posy, 150, 20, "Only run once: ", Align_CenterLeft);
74
m_is_one_time_event=new UICheckbox(this, get_inner_w()-STATEBOX_WIDTH-spacing, posy);
75
m_is_one_time_event->set_state(m_event->is_one_time_event());
80
new UITextarea(this, spacing, posy, 60, 20, "Caption:", Align_CenterLeft);
81
m_caption=new UIEdit_Box(this, spacing+60, posy, get_inner_w()/2-60-2*spacing, 20, 0, 1);
82
m_caption->set_text(m_event->get_caption());
85
new UITextarea(this, get_inner_w()/2+spacing, posy, 150, 20, "Is Modal: ", Align_CenterLeft);
86
m_is_modal=new UICheckbox(this, get_inner_w()-STATEBOX_WIDTH-spacing, posy);
87
m_is_modal->set_state(m_event->get_is_modal());
92
new UITextarea(this, spacing, posy, 50, 20, "Window Title:", Align_CenterLeft);
93
m_window_title=new UIEdit_Box(this, spacing+100, posy, get_inner_w()-100-2*spacing, 20, 0, 2);
94
m_window_title->set_text(m_event->get_window_title());
98
new UITextarea(this, spacing, posy, 50, 20, "Text:", Align_CenterLeft);
100
m_text=new UIMultiline_Editbox(this, spacing, posy, get_inner_w()-2*spacing, 80, event->get_text());
105
new UITextarea(this, spacing, posy, 130, 20, "Number of Buttons: ", Align_CenterLeft);
106
UIButton* b=new UIButton(this, spacing+140, posy, 20, 20, 0, 2);
107
b->set_pic(g_gr->get_picture(PicMod_UI, "pics/scrollbar_down.png", true));
108
b->clickedid.set(this, &Event_Message_Box_Option_Menu::clicked);
109
m_nr_buttons_ta=new UITextarea(this, spacing+160+spacing, posy,15,20,"1", Align_CenterLeft);
110
b=new UIButton(this, spacing+175+spacing, posy, 20, 20, 0, 3);
111
b->set_pic(g_gr->get_picture(PicMod_UI, "pics/scrollbar_up.png", true));
112
b->clickedid.set(this, &Event_Message_Box_Option_Menu::clicked);
116
new UITextarea(this, spacing, posy, 100, 20, "Button Name: ", Align_CenterLeft);
117
m_button_name=new UIEdit_Box(this, spacing+110, posy, 100, 20, 0, 3);
118
m_button_name->changedid.set(this, &Event_Message_Box_Option_Menu::edit_box_edited);
120
// Listbox for buttons
121
m_buttons_ls=new UIListselect(this, get_inner_w()/2+spacing, posy, get_inner_w()/2-2*spacing, 80, Align_Left);
122
m_buttons_ls->selected.set(this, &Event_Message_Box_Option_Menu::ls_selected);
126
new UITextarea(this, spacing, posy, 100, 20, "Select Trigger: ", Align_CenterLeft);
127
b=new UIButton(this, spacing+110, posy, 20, 20, 0, 4);
128
b->set_pic(g_gr->get_picture(PicMod_UI, "pics/scrollbar_down.png", true));
129
b->clickedid.set(this, &Event_Message_Box_Option_Menu::clicked);
130
b=new UIButton(this, spacing+130+spacing, posy, 20, 20, 0, 5);
131
b->set_pic(g_gr->get_picture(PicMod_UI, "pics/scrollbar_up.png", true));
132
b->clickedid.set(this, &Event_Message_Box_Option_Menu::clicked);
136
new UITextarea(this, spacing, posy, 100, 20, "Current: ", Align_CenterLeft);
137
m_current_trigger_ta=new UITextarea(this, spacing+15, posy+15+spacing, get_inner_w()/2, 20, "Keine Trigger gewaehlt!", Align_CenterLeft);
140
// Uses picture checkbox
141
posy=get_inner_h()-60;
142
new UITextarea(this, spacing, posy, 200, 20, "Uses Picture: ", Align_CenterLeft);
143
m_uses_picture=new UICheckbox(this, get_inner_w()/2-STATEBOX_HEIGHT-2*spacing, posy);
144
m_uses_picture->set_state(static_cast<int>(m_event->get_pic_id())!=-1);
145
m_uses_picture->changedto.set(this, &Event_Message_Box_Option_Menu::pic_checkbox_enabled);
147
// Picture options Button
148
b=new UIButton(this, get_inner_w()/2+spacing, posy, 120, 20, 0, 6);
149
b->clickedid.set(this, &Event_Message_Box_Option_Menu::clicked);
150
b->set_title("Picture options");
151
b->set_enabled(m_uses_picture->get_state());
152
m_btn_picture_options=b;
155
posx=(get_inner_w()/2)-60-spacing;
156
posy=get_inner_h()-30;
157
b=new UIButton(this, posx, posy, 60, 20, 0, 1);
159
b->clickedid.set(this, &Event_Message_Box_Option_Menu::clicked);
160
posx=(get_inner_w()/2)+spacing;
161
b=new UIButton(this, posx, posy, 60, 20, 1, 0);
162
b->set_title("Cancel");
163
b->clickedid.set(this, &Event_Message_Box_Option_Menu::clicked);
166
for(i=0; i<m_parent->get_map()->get_number_of_triggers(); i++) {
167
Trigger* trig=m_parent->get_map()->get_trigger(i);
168
if(trig->get_id()==TRIGGER_NULL)
169
m_null_triggers.push_back(i);
172
for(int i=0; i<m_event->get_nr_buttons(); i++) {
173
m_buttons[i].name=m_event->get_button_name(i);
174
for(int j=0; j<((int)m_null_triggers.size()); j++)
175
if(m_parent->get_map()->get_trigger_index(m_event->get_button_trigger(i))==m_null_triggers[j])
176
m_buttons[i].trigger=j;
186
Event_Message_Box_Option_Menu::~Event_Message_Box_Option_Menu(void) {
192
* we're a modal, therefore we can not delete ourself
193
* on close (the caller must do this) instead
194
* we simulate a cancel click
196
bool Event_Message_Box_Option_Menu::handle_mouseclick(uint btn, bool down, int mx, int my) {
197
if(btn == MOUSE_RIGHT && down) {
201
return false; // we're not dragable
205
* a button has been clicked
207
void Event_Message_Box_Option_Menu::clicked(int i) {
211
// Cancel has been clicked
212
if(static_cast<int>(m_picid)!=-1 && m_picid!=m_event->get_pic_id())
213
g_gr->flush_picture(m_picid);
222
m_event->set_is_one_time_event(m_is_one_time_event->get_state());
223
if(m_name->get_text())
224
m_event->set_name(m_name->get_text());
225
if(m_text->get_text().c_str())
226
m_event->set_text(m_text->get_text().c_str());
227
if(m_caption->get_text())
228
m_event->set_caption(m_caption->get_text());
229
if(m_window_title->get_text())
230
m_event->set_window_title(m_window_title->get_text());
231
m_event->set_is_modal(m_is_modal->get_state());
232
m_event->set_nr_buttons(m_nr_buttons);
233
for(int i=0; i<m_nr_buttons; i++) {
234
m_event->set_button_name(i, m_buttons[i].name.c_str());
235
if(m_buttons[i].trigger!=-1) {
236
m_event->set_button_trigger(i, static_cast<Trigger_Null*>(m_parent->get_map()->get_trigger(m_null_triggers[m_buttons[i].trigger])), m_parent->get_map());
238
m_event->set_button_trigger(i, 0, m_parent->get_map());
241
if(m_uses_picture->get_state()) {
242
if(m_picid!=m_event->get_pic_id() && static_cast<int>(m_event->get_pic_id())!=-1) {
243
log("Flushing picture: %i\n", m_event->get_pic_id());
244
g_gr->flush_picture(m_event->get_pic_id());
246
log("Setting pic id to: %i\n", m_picid);
247
m_event->set_pic_id(m_picid);
248
m_event->set_pic_position(m_position);
249
g_gr->use_clrkey(m_event->get_pic_id(), m_clrkey);
251
int picid=m_event->get_pic_id();
252
if(static_cast<int>(picid)!=-1) {
253
log("Flushing picture unten: %i\n", m_event->get_pic_id());
254
g_gr->flush_picture(picid);
256
m_event->set_pic_id(-1);
265
// Number of buttons: down
267
if(m_nr_buttons<1) m_nr_buttons=1;
274
// Number of buttons up
276
if(m_nr_buttons>MAX_BUTTONS) m_nr_buttons=MAX_BUTTONS;
284
m_buttons[m_ls_selected].trigger--;
285
if(m_buttons[m_ls_selected].trigger<-1) m_buttons[m_ls_selected].trigger=m_null_triggers.size()-1;
294
m_buttons[m_ls_selected].trigger++;
295
if(m_buttons[m_ls_selected].trigger>=static_cast<int>(m_null_triggers.size()))
296
m_buttons[m_ls_selected].trigger=-1;
304
Event_Message_Box_Option_Menu_Picture_Options* epo=new Event_Message_Box_Option_Menu_Picture_Options(m_parent,&m_clrkey, &m_picid, &m_position);
314
* update function: update all UI elements
316
void Event_Message_Box_Option_Menu::update(void) {
317
if(m_ls_selected>=m_nr_buttons) m_buttons_ls->select(0);
319
if(!m_null_triggers.size()) {
320
// No triggers, no other buttons
324
m_buttons_ls->clear();
326
for(i=0; i<m_nr_buttons; i++)
327
m_buttons_ls->add_entry(m_buttons[i].name.c_str(), 0);
330
text.append(1,static_cast<uchar>(m_nr_buttons+0x30));
331
m_nr_buttons_ta->set_text(text.c_str());
334
m_button_name->set_text(m_buttons[m_ls_selected].name.c_str());
336
if(m_nr_buttons && m_null_triggers.size()) {
337
if(m_buttons[m_ls_selected].trigger==-1)
338
m_current_trigger_ta->set_text("none");
340
m_current_trigger_ta->set_text(m_parent->get_map()->get_trigger(m_null_triggers[m_buttons[m_ls_selected].trigger])->get_name());
342
m_current_trigger_ta->set_text("---");
343
m_buttons[0].trigger=-1;
348
* Listbox got selected
350
void Event_Message_Box_Option_Menu::ls_selected(int i) {
356
* Button name edit box edited
358
void Event_Message_Box_Option_Menu::edit_box_edited(int i) {
359
m_buttons[m_ls_selected].name=m_button_name->get_text();
364
* The picture checkbox was enabled
366
void Event_Message_Box_Option_Menu::pic_checkbox_enabled(bool t) {
367
m_btn_picture_options->set_enabled(t);