~ubuntu-branches/ubuntu/precise/widelands/precise-backports

« back to all changes in this revision

Viewing changes to src/editor/ui_menus/event_message_box_option_menu.cc

  • Committer: Bazaar Package Importer
  • Author(s): Martin Quinson
  • Date: 2005-02-14 10:41:12 UTC
  • Revision ID: james.westby@ubuntu.com-20050214104112-6v08iux9fptxpva9
Tags: upstream-build9
Import upstream version build9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2002-4 by the Widelands Development Team
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 *
 
18
 */
 
19
 
 
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"
 
31
#include "system.h"
 
32
#include "error.h"
 
33
#include "map.h"
 
34
#include "graphic.h"
 
35
#include "trigger_null.h"
 
36
 
 
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") {
 
39
   m_parent=parent;
 
40
   m_event=event;
 
41
 
 
42
   // Caption
 
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);
 
45
 
 
46
   const int offsx=5;
 
47
   const int offsy=25;
 
48
   const int spacing=5;
 
49
   int posx=offsx;
 
50
   int posy=offsy;
 
51
   m_nr_buttons=m_event->get_nr_buttons();
 
52
   m_ls_selected=0;
 
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);
 
57
   else
 
58
      m_clrkey=false;
 
59
 
 
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;
 
65
 
 
66
 
 
67
   // Name editbox
 
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());
 
71
 
 
72
   // Only run once CB
 
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());
 
76
 
 
77
   posy+=20+spacing;
 
78
 
 
79
   // Caption
 
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());
 
83
 
 
84
   // Modal cb
 
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());
 
88
 
 
89
   posy+=20+spacing;
 
90
 
 
91
   // Window Title
 
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());
 
95
 
 
96
   // Text
 
97
   posy+=20+spacing;
 
98
   new UITextarea(this, spacing, posy, 50, 20, "Text:", Align_CenterLeft);
 
99
   posy+=20+spacing;
 
100
   m_text=new UIMultiline_Editbox(this, spacing, posy, get_inner_w()-2*spacing, 80, event->get_text());
 
101
 
 
102
   posy+=80+spacing;
 
103
 
 
104
   // Nur Buttons
 
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);
 
113
 
 
114
   // Button name
 
115
   posy+=20+spacing;
 
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);
 
119
 
 
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);
 
123
 
 
124
   // Select trigger
 
125
   posy+=20+spacing;
 
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);
 
133
 
 
134
   // Current Trigger
 
135
   posy+=20+spacing;
 
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);
 
138
 
 
139
 
 
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);
 
146
 
 
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;
 
153
 
 
154
   // Ok/Cancel Buttons
 
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);
 
158
   b->set_title("Ok");
 
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);
 
164
 
 
165
   int i=0;
 
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);
 
170
   }
 
171
 
 
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;
 
177
   }
 
178
 
 
179
   center_to_parent();
 
180
   update();
 
181
}
 
182
 
 
183
/*
 
184
 * cleanup
 
185
 */
 
186
Event_Message_Box_Option_Menu::~Event_Message_Box_Option_Menu(void) {
 
187
}
 
188
 
 
189
/*
 
190
 * Handle mouseclick
 
191
 *
 
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
 
195
 */
 
196
bool Event_Message_Box_Option_Menu::handle_mouseclick(uint btn, bool down, int mx, int my) {
 
197
   if(btn == MOUSE_RIGHT && down) {
 
198
      clicked(0);
 
199
      return true;
 
200
   } else
 
201
      return false; // we're not dragable
 
202
}
 
203
 
 
204
/*
 
205
 * a button has been clicked
 
206
 */
 
207
void Event_Message_Box_Option_Menu::clicked(int i) {
 
208
   switch(i) {
 
209
      case 0:
 
210
         {
 
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);
 
214
            end_modal(0);
 
215
            return;
 
216
         }
 
217
         break;
 
218
 
 
219
      case 1:
 
220
         {
 
221
            // ok button
 
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());
 
237
               } else {
 
238
                  m_event->set_button_trigger(i, 0, m_parent->get_map());
 
239
               }
 
240
            }
 
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());
 
245
               }
 
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);
 
250
            } else {
 
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);
 
255
               }
 
256
               m_event->set_pic_id(-1);
 
257
            }
 
258
            end_modal(1);
 
259
            return;
 
260
         }
 
261
         break;
 
262
 
 
263
      case 2:
 
264
         {
 
265
            // Number of buttons: down
 
266
            m_nr_buttons--;
 
267
            if(m_nr_buttons<1) m_nr_buttons=1;
 
268
            update();
 
269
         }
 
270
         break;
 
271
 
 
272
      case 3:
 
273
         {
 
274
            // Number of buttons up
 
275
            m_nr_buttons++;
 
276
            if(m_nr_buttons>MAX_BUTTONS) m_nr_buttons=MAX_BUTTONS;
 
277
            update();
 
278
         }
 
279
         break;
 
280
 
 
281
      case 4:
 
282
         {
 
283
            // Trigger sel, down
 
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;
 
286
            update();
 
287
         }
 
288
         break;
 
289
 
 
290
 
 
291
      case 5:
 
292
         {
 
293
            // Trigger sel, up
 
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;
 
297
            update();
 
298
         }
 
299
         break;
 
300
 
 
301
      case 6:
 
302
         {
 
303
            // Picture options
 
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);
 
305
            if(epo->run())
 
306
               update();
 
307
            delete epo;
 
308
         }
 
309
         break;
 
310
   }
 
311
}
 
312
 
 
313
/*
 
314
 * update function: update all UI elements
 
315
 */
 
316
void Event_Message_Box_Option_Menu::update(void) {
 
317
   if(m_ls_selected>=m_nr_buttons) m_buttons_ls->select(0);
 
318
 
 
319
   if(!m_null_triggers.size()) {
 
320
      // No triggers, no other buttons
 
321
      m_nr_buttons=1;
 
322
   }
 
323
 
 
324
   m_buttons_ls->clear();
 
325
   int i;
 
326
   for(i=0; i<m_nr_buttons; i++)
 
327
      m_buttons_ls->add_entry(m_buttons[i].name.c_str(), 0);
 
328
 
 
329
   std::string text;
 
330
   text.append(1,static_cast<uchar>(m_nr_buttons+0x30));
 
331
   m_nr_buttons_ta->set_text(text.c_str());
 
332
 
 
333
 
 
334
   m_button_name->set_text(m_buttons[m_ls_selected].name.c_str());
 
335
 
 
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");
 
339
      else
 
340
         m_current_trigger_ta->set_text(m_parent->get_map()->get_trigger(m_null_triggers[m_buttons[m_ls_selected].trigger])->get_name());
 
341
   } else {
 
342
      m_current_trigger_ta->set_text("---");
 
343
      m_buttons[0].trigger=-1;
 
344
   }
 
345
}
 
346
 
 
347
/*
 
348
 * Listbox got selected
 
349
 */
 
350
void Event_Message_Box_Option_Menu::ls_selected(int i) {
 
351
   m_ls_selected=i;
 
352
   update();
 
353
}
 
354
 
 
355
/*
 
356
 * Button name edit box edited
 
357
 */
 
358
void Event_Message_Box_Option_Menu::edit_box_edited(int i) {
 
359
   m_buttons[m_ls_selected].name=m_button_name->get_text();
 
360
   update();
 
361
}
 
362
 
 
363
/*
 
364
 * The picture checkbox was enabled
 
365
 */
 
366
void Event_Message_Box_Option_Menu::pic_checkbox_enabled(bool t) {
 
367
   m_btn_picture_options->set_enabled(t);
 
368
   update();
 
369
}