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.
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"
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") {
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);
43
Coords pt=event->get_coords();
46
m_area=m_event->get_area();
47
m_player=m_event->get_player();
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());
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());
68
new UITextarea(this, spacing, posy, get_inner_w(), 15, "Current position: ", Align_CenterLeft);
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);
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);
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);
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);
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);
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);
170
Event_Conquer_Area_Option_Menu::~Event_Conquer_Area_Option_Menu(void) {
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
180
bool Event_Conquer_Area_Option_Menu::handle_mouseclick(uint btn, bool down, int mx, int my) {
181
if(btn == MOUSE_RIGHT && down) {
185
return false; // we're not dragable
190
* a button has been clicked
192
void Event_Conquer_Area_Option_Menu::clicked(int i) {
196
// Cancel has been clicked
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);
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;
229
case 15: m_player++; break;
230
case 16: m_player--; break;
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;
243
* update function: update all UI elements
245
void Event_Conquer_Area_Option_Menu::update(void) {
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;
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();
254
if(m_area<1) m_area=1;
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);
262
sprintf(buf, "%i", m_player);
263
m_player_ta->set_text(buf);
265
sprintf(buf, "%i", m_area);
266
m_area_ta->set_text(buf);