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

« back to all changes in this revision

Viewing changes to src/editor/ui_menus/event_conquer_area_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 <stdio.h>
 
21
#include "event_conquer_area_option_menu.h"
 
22
#include "event_conquer_area.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 "editorinteractive.h"
 
29
#include "system.h"
 
30
#include "error.h"
 
31
#include "map.h"
 
32
#include "graphic.h"
 
33
 
 
34
Event_Conquer_Area_Option_Menu::Event_Conquer_Area_Option_Menu(Editor_Interactive* parent, Event_Conquer_Area* event) :
 
35
   UIWindow(parent, 0, 0, 180, 280, "Event Option Menu") {
 
36
   m_parent=parent;
 
37
   m_event=event;
 
38
 
 
39
   // Caption
 
40
   UITextarea* tt=new UITextarea(this, 0, 0, "Conquer Area Event Options", Align_Left);
 
41
   tt->set_pos((get_inner_w()-tt->get_w())/2, 5);
 
42
 
 
43
   Coords pt=event->get_coords();
 
44
   m_x=pt.x;
 
45
   m_y=pt.y;
 
46
   m_area=m_event->get_area();
 
47
   m_player=m_event->get_player();
 
48
   const int offsx=5;
 
49
   const int offsy=25;
 
50
   int spacing=5;
 
51
   int posx=offsx;
 
52
   int posy=offsy;
 
53
 
 
54
 
 
55
   // Name editbox
 
56
   new UITextarea(this, spacing, posy, 50, 20, "Name:", Align_CenterLeft);
 
57
   m_name=new UIEdit_Box(this, spacing+60, posy, get_inner_w()-2*spacing-60, 20, 0, 0);
 
58
   m_name->set_text(event->get_name());
 
59
   posy+=20+spacing;
 
60
 
 
61
   // Only run once CB
 
62
   new UITextarea(this, spacing, posy, 150, 20, "Only run once: ", Align_CenterLeft);
 
63
   m_is_one_time_event=new UICheckbox(this, spacing+150, posy);
 
64
   m_is_one_time_event->set_state(m_event->is_one_time_event());
 
65
 
 
66
   posy+=20+spacing;
 
67
   // Set Field Buttons
 
68
   new UITextarea(this, spacing, posy, get_inner_w(), 15, "Current position: ", Align_CenterLeft);
 
69
   posy+=20+spacing;
 
70
   // X
 
71
   UIButton* b=new UIButton(this, spacing+20, posy, 20, 20, 0, 3);
 
72
   b->set_pic(g_gr->get_picture(PicMod_Game, "pics/scrollbar_up.png", true));
 
73
   b->clickedid.set(this, &Event_Conquer_Area_Option_Menu::clicked);
 
74
   b=new UIButton(this, spacing+20, posy+40, 20, 20, 0, 4);
 
75
   b->set_pic(g_gr->get_picture(PicMod_Game, "pics/scrollbar_down.png", true));
 
76
   b->clickedid.set(this, &Event_Conquer_Area_Option_Menu::clicked);
 
77
   b=new UIButton(this, spacing+40, posy, 20, 20, 0, 5);
 
78
   b->set_pic(g_gr->get_picture(PicMod_Game, "pics/scrollbar_up.png", true));
 
79
   b->clickedid.set(this, &Event_Conquer_Area_Option_Menu::clicked);
 
80
   b=new UIButton(this, spacing+40, posy+40, 20, 20, 0, 6);
 
81
   b->set_pic(g_gr->get_picture(PicMod_Game, "pics/scrollbar_down.png", true));
 
82
   b->clickedid.set(this, &Event_Conquer_Area_Option_Menu::clicked);
 
83
   b=new UIButton(this, spacing+60, posy, 20, 20, 0, 7);
 
84
   b->set_pic(g_gr->get_picture(PicMod_Game, "pics/scrollbar_up.png", true));
 
85
   b->clickedid.set(this, &Event_Conquer_Area_Option_Menu::clicked);
 
86
   b=new UIButton(this, spacing+60, posy+40, 20, 20, 0, 8);
 
87
   b->set_pic(g_gr->get_picture(PicMod_Game, "pics/scrollbar_down.png", true));
 
88
   b->clickedid.set(this, &Event_Conquer_Area_Option_Menu::clicked);
 
89
   new UITextarea(this, spacing+20, posy+20, 20, 20, "X: ", Align_CenterLeft);
 
90
   m_x_ta=new UITextarea(this, spacing+40, posy+20, 20, 20, "X: ", Align_CenterLeft);
 
91
 
 
92
   // Y
 
93
   int oldspacing=spacing;
 
94
   spacing=get_inner_w()/2+spacing;
 
95
   b=new UIButton(this, spacing, posy, 20, 20, 0, 9);
 
96
   b->set_pic(g_gr->get_picture(PicMod_Game, "pics/scrollbar_up.png", true));
 
97
   b->clickedid.set(this, &Event_Conquer_Area_Option_Menu::clicked);
 
98
   b=new UIButton(this, spacing, posy+40, 20, 20, 0, 10);
 
99
   b->set_pic(g_gr->get_picture(PicMod_Game, "pics/scrollbar_down.png", true));
 
100
   b->clickedid.set(this, &Event_Conquer_Area_Option_Menu::clicked);
 
101
   b=new UIButton(this, spacing+20, posy, 20, 20, 0, 11);
 
102
   b->set_pic(g_gr->get_picture(PicMod_Game, "pics/scrollbar_up.png", true));
 
103
   b->clickedid.set(this, &Event_Conquer_Area_Option_Menu::clicked);
 
104
   b=new UIButton(this, spacing+20, posy+40, 20, 20, 0, 12);
 
105
   b->set_pic(g_gr->get_picture(PicMod_Game, "pics/scrollbar_down.png", true));
 
106
   b->clickedid.set(this, &Event_Conquer_Area_Option_Menu::clicked);
 
107
   b=new UIButton(this, spacing+40, posy, 20, 20, 0, 13);
 
108
   b->set_pic(g_gr->get_picture(PicMod_Game, "pics/scrollbar_up.png", true));
 
109
   b->clickedid.set(this, &Event_Conquer_Area_Option_Menu::clicked);
 
110
   b=new UIButton(this, spacing+40, posy+40, 20, 20, 0, 14);
 
111
   b->set_pic(g_gr->get_picture(PicMod_Game, "pics/scrollbar_down.png", true));
 
112
   b->clickedid.set(this, &Event_Conquer_Area_Option_Menu::clicked);
 
113
   new UITextarea(this, spacing, posy+20, 20, 20, "Y: ", Align_CenterLeft);
 
114
   m_y_ta=new UITextarea(this, spacing+20, posy+20, 20, 20, "Y: ", Align_CenterLeft);
 
115
   spacing=oldspacing;
 
116
 
 
117
   // Player
 
118
   posy+=60+spacing;
 
119
   new UITextarea(this, spacing, posy, 70, 20, "Player: ", Align_CenterLeft);
 
120
   m_player_ta=new UITextarea(this, spacing+70, posy, 20, 20, "2", Align_Center);
 
121
   b=new UIButton(this, spacing+90, posy, 20, 20, 0, 15);
 
122
   b->set_pic(g_gr->get_picture(PicMod_Game, "pics/scrollbar_up.png", true));
 
123
   b->clickedid.set(this, &Event_Conquer_Area_Option_Menu::clicked);
 
124
   b=new UIButton(this, spacing+110, posy, 20, 20, 0, 16);
 
125
   b->set_pic(g_gr->get_picture(PicMod_Game, "pics/scrollbar_down.png", true));
 
126
   b->clickedid.set(this, &Event_Conquer_Area_Option_Menu::clicked);
 
127
 
 
128
   // Area
 
129
   posy+=20+spacing;
 
130
   new UITextarea(this, spacing, posy+20, 70, 20, "Area: ", Align_CenterLeft);
 
131
   b=new UIButton(this, spacing+70, posy, 20, 20, 0, 17);
 
132
   b->set_pic(g_gr->get_picture(PicMod_Game, "pics/scrollbar_up.png", true));
 
133
   b->clickedid.set(this, &Event_Conquer_Area_Option_Menu::clicked);
 
134
   b=new UIButton(this, spacing+70, posy+40, 20, 20, 0, 18);
 
135
   b->set_pic(g_gr->get_picture(PicMod_Game, "pics/scrollbar_down.png", true));
 
136
   b->clickedid.set(this, &Event_Conquer_Area_Option_Menu::clicked);
 
137
   b=new UIButton(this, spacing+90, posy, 20, 20, 0, 19);
 
138
   b->set_pic(g_gr->get_picture(PicMod_Game, "pics/scrollbar_up.png", true));
 
139
   b->clickedid.set(this, &Event_Conquer_Area_Option_Menu::clicked);
 
140
   b=new UIButton(this, spacing+90, posy+40, 20, 20, 0, 20);
 
141
   b->set_pic(g_gr->get_picture(PicMod_Game, "pics/scrollbar_down.png", true));
 
142
   b->clickedid.set(this, &Event_Conquer_Area_Option_Menu::clicked);
 
143
   b=new UIButton(this, spacing+110, posy, 20, 20, 0, 21);
 
144
   b->set_pic(g_gr->get_picture(PicMod_Game, "pics/scrollbar_up.png", true));
 
145
   b->clickedid.set(this, &Event_Conquer_Area_Option_Menu::clicked);
 
146
   b=new UIButton(this, spacing+110, posy+40, 20, 20, 0, 22);
 
147
   b->set_pic(g_gr->get_picture(PicMod_Game, "pics/scrollbar_down.png", true));
 
148
   b->clickedid.set(this, &Event_Conquer_Area_Option_Menu::clicked);
 
149
   m_area_ta=new UITextarea(this, spacing+90, posy+20, 20, 20, "2", Align_Center);
 
150
 
 
151
 
 
152
   // Ok/Cancel Buttons
 
153
   posx=(get_inner_w()/2)-60-spacing;
 
154
   posy=get_inner_h()-20-spacing;
 
155
   b=new UIButton(this, posx, posy, 60, 20, 0, 1);
 
156
   b->set_title("Ok");
 
157
   b->clickedid.set(this, &Event_Conquer_Area_Option_Menu::clicked);
 
158
   posx=(get_inner_w()/2)+spacing;
 
159
   b=new UIButton(this, posx, posy, 60, 20, 1, 0);
 
160
   b->set_title("Cancel");
 
161
   b->clickedid.set(this, &Event_Conquer_Area_Option_Menu::clicked);
 
162
 
 
163
   center_to_parent();
 
164
   update();
 
165
}
 
166
 
 
167
/*
 
168
 * cleanup
 
169
 */
 
170
Event_Conquer_Area_Option_Menu::~Event_Conquer_Area_Option_Menu(void) {
 
171
}
 
172
 
 
173
/*
 
174
 * Handle mouseclick
 
175
 *
 
176
 * we're a modal, therefore we can not delete ourself
 
177
 * on close (the caller must do this) instead
 
178
 * we simulate a cancel click
 
179
 */
 
180
bool Event_Conquer_Area_Option_Menu::handle_mouseclick(uint btn, bool down, int mx, int my) {
 
181
   if(btn == MOUSE_RIGHT && down) {
 
182
      clicked(0);
 
183
      return true;
 
184
   } else
 
185
      return false; // we're not dragable
 
186
 
 
187
}
 
188
 
 
189
/*
 
190
 * a button has been clicked
 
191
 */
 
192
void Event_Conquer_Area_Option_Menu::clicked(int i) {
 
193
   switch(i) {
 
194
      case 0:
 
195
         {
 
196
            // Cancel has been clicked
 
197
            end_modal(0);
 
198
            return;
 
199
         }
 
200
         break;
 
201
 
 
202
      case 1:
 
203
         {
 
204
            // ok button
 
205
            m_event->set_is_one_time_event(m_is_one_time_event->get_state());
 
206
            if(m_name->get_text())
 
207
               m_event->set_name(m_name->get_text());
 
208
            m_event->set_coords(Coords(m_x,m_y));
 
209
            m_event->set_player(m_player);
 
210
            m_event->set_area(m_area);
 
211
            end_modal(1);
 
212
            return;
 
213
         }
 
214
         break;
 
215
 
 
216
      case 3: m_x+=100; break;
 
217
      case 4: m_x-=100; break;
 
218
      case 5: m_x+=10; break;
 
219
      case 6: m_x-=10; break;
 
220
      case 7: m_x+=1; break;
 
221
      case 8: m_x-=1; break;
 
222
      case 9: m_y+=100; break;
 
223
      case 10: m_y-=100; break;
 
224
      case 11: m_y+=10; break;
 
225
      case 12: m_y-=10; break;
 
226
      case 13: m_y+=1; break;
 
227
      case 14: m_y-=1; break;
 
228
 
 
229
      case 15: m_player++; break;
 
230
      case 16: m_player--; break;
 
231
 
 
232
      case 17: m_area+=100; break;
 
233
      case 18: m_area-=100; break;
 
234
      case 19: m_area+=10; break;
 
235
      case 20: m_area-=10; break;
 
236
      case 21: m_area+=1; break;
 
237
      case 22: m_area-=1; break;
 
238
   }
 
239
   update();
 
240
}
 
241
 
 
242
/*
 
243
 * update function: update all UI elements
 
244
 */
 
245
void Event_Conquer_Area_Option_Menu::update(void) {
 
246
   if(m_x<0) m_x=0;
 
247
   if(m_y<0) m_y=0;
 
248
   if(m_x>=((int)m_parent->get_map()->get_width())) m_x=m_parent->get_map()->get_width()-1;
 
249
   if(m_y>=((int)m_parent->get_map()->get_height())) m_y=m_parent->get_map()->get_height()-1;
 
250
 
 
251
   if(m_player<=0) m_player=1;
 
252
   if(m_player>m_parent->get_map()->get_nrplayers()) m_player=m_parent->get_map()->get_nrplayers();
 
253
 
 
254
   if(m_area<1) m_area=1;
 
255
 
 
256
   char buf[200];
 
257
   sprintf(buf, "%i", m_x);
 
258
   m_x_ta->set_text(buf);
 
259
   sprintf(buf, "%i", m_y);
 
260
   m_y_ta->set_text(buf);
 
261
 
 
262
   sprintf(buf, "%i", m_player);
 
263
   m_player_ta->set_text(buf);
 
264
 
 
265
   sprintf(buf, "%i", m_area);
 
266
   m_area_ta->set_text(buf);
 
267
}