Advanced Strategic Command
weatherdialog.cpp
Go to the documentation of this file.
1 
2 // C++ Implementation: weatherdialog
3 //
4 // Description:
5 //
6 //
7 // Author: Martin Bickel <bickel@asc-hq.org>, (C) 2004
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12 
13 #include <iostream>
14 #include <pglistboxitem.h>
15 
16 #include "weatherdialog.h"
17 #include "weatherarea.h"
18 #include "guidimension.h"
19 #include "typen.h"
20 #include "spfst.h"
21 #include "ascstring.h"
22 
23 const int WeatherDialog::xsize = 500;
24 const int WeatherDialog::ysize = 650;
25 
26 
27 WeatherDialog::WeatherDialog() : ASC_PG_Dialog(NULL, PG_Rect( 100, 50, xsize, ysize ), "Weather Configuration", SHOW_CLOSE ) {
28 
29  //Random Mode
30  randomMode = new PG_CheckButton(this, PG_Rect( GuiDimension::getLeftIndent(), GuiDimension::getTopOffSet(), xsize/3 , GetTextHeight()*2), "Random Mode");
31  randomMode->SetSizeByText();
32  if(actmap->weatherSystem->getEventMode() == RANDOMMODE) {
33  randomMode->SetPressed();
34  }
35 
36  int seedModeYPos = ScreenToClient(0, randomMode->y).y + GetTextHeight() + GuiDimension::getTopOffSet();
37  seedMode = new PG_CheckButton(this, PG_Rect( GuiDimension::getLeftIndent(), seedModeYPos, xsize/3 , GetTextHeight()*2), "Seed is Set");
38  seedMode->SetSizeByText();
39  if(actmap->weatherSystem->isSeedValueSet()) {
40  seedMode->SetPressed();
41  }
42 
43  //xPosition for edit Fields
44  int valueXPos = static_cast<int>(xsize * 0.8);
45 
46  int defaultWeatherYPos = seedModeYPos + GetTextHeight()*2;
47  defaultWeatherLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftOffSet(), defaultWeatherYPos, 10, GetTextHeight() * 2), "Default Weather");
48  defaultWeatherLabel->SetSizeByText();
49  weatherTypes = new PG_DropDown(this, PG_Rect(xsize - GuiDimension::getLineEditWidth() *5, defaultWeatherYPos, GuiDimension::getLineEditWidth() *4, GetTextHeight() * 2));
50 
51  for(int i = 0; i < cwettertypennum; i++) {
52  weatherTypes->AddItem(cwettertypen[i]);
53 
54  }
55 
56  //Amount of Area Spawns
57  int areaSpawnsLabelYPos = defaultWeatherYPos + GetTextHeight()*2;
58  areaSpawnsLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), areaSpawnsLabelYPos, xsize/3 , GetTextHeight()*2),
59  "Amount of Spawns:");
60  areaSpawnsLabel->SetSizeByText();
61 
62  areaSpawnsValue = new PG_LineEdit(this, PG_Rect(valueXPos, areaSpawnsLabelYPos, GuiDimension::getLineEditWidth() , GetTextHeight()*2));
63  areaSpawnsValue->SetText(ASCString::toString(actmap->weatherSystem->getSpawnsAmount()));
64 
65 
66  //Weather-Update each nth turn
67  int nthTurnLabelYPos = areaSpawnsLabelYPos + GetTextHeight()*2;
68  nthTurnLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), nthTurnLabelYPos, xsize/3 , GetTextHeight()*2),
69  "Weather changes each nth Turn:");
70  nthTurnLabel->SetSizeByText();
71  nthTurnValue = new PG_LineEdit(this, PG_Rect(valueXPos, nthTurnLabelYPos, GuiDimension::getLineEditWidth() , GetTextHeight()*2));
72  nthTurnValue->SetText(ASCString::toString(actmap->weatherSystem->getTimeInterval()));
73 
74  //Ratio windspeed to passed fields
75  int windSpeedFieldRatioLabelYPos = nthTurnLabelYPos + GetTextHeight() * 2;
76  windSpeedFieldRatioLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), windSpeedFieldRatioLabelYPos, xsize/3 , GetTextHeight()*2), "WindSpeed to Fields Ratio:");
77  windSpeedFieldRatioLabel->SetSizeByText();
78  windSpeedFieldRatioValue = new PG_LineEdit(this, PG_Rect(valueXPos, windSpeedFieldRatioLabelYPos, GuiDimension::getLineEditWidth() , GetTextHeight()*2));
79  windSpeedFieldRatioValue->SetText(ASCString::toString(actmap->weatherSystem->getWindspeed2FieldRatio()));
80 
81  //LowerSize
82  int lowerSizeLimitsYPos = windSpeedFieldRatioLabelYPos + GetTextHeight() * 2;
83  lowerSizeLimitsLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), lowerSizeLimitsYPos, xsize/3 , GetTextHeight()*2), "Lower Area Size rel. to Mapsize:");
84  lowerSizeLimitsLabel->SetSizeByText();
85  lowerSizeLimitsValue = new PG_LineEdit(this, PG_Rect(valueXPos ,lowerSizeLimitsYPos, GuiDimension::getLineEditWidth() , GetTextHeight()*2));
86  lowerSizeLimitsValue->SetText(ASCString::toString(actmap->weatherSystem->getLowerSizeLimit()));
87 
88  //UpperSize
89  int upperSizeLimitsYPos = lowerSizeLimitsYPos + GetTextHeight() * 2;
90  upperSizeLimitsLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), upperSizeLimitsYPos, xsize/3 , GetTextHeight()*2), "Upper Area Size rel. to Mapsize:");
91  upperSizeLimitsLabel->SetSizeByText();
92  upperSizeLimitsValue = new PG_LineEdit(this, PG_Rect(valueXPos ,upperSizeLimitsYPos, GuiDimension::getLineEditWidth() , GetTextHeight()*2));
93  upperSizeLimitsValue->SetText(ASCString::toString(actmap->weatherSystem->getUpperSizeLimit()));
94 
95  //Lower Duration Limit
96  int lowerDurationLimitYPos = upperSizeLimitsYPos + GetTextHeight() * 2;
97  lowerDurationLimitLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), lowerDurationLimitYPos, xsize/3 , GetTextHeight()*2), "Lower Duration Limit:");
98  lowerDurationLimitLabel->SetSizeByText();
99  lowerDurationLimitValue = new PG_LineEdit(this, PG_Rect(valueXPos ,lowerDurationLimitYPos, GuiDimension::getLineEditWidth(),
100  GetTextHeight()*2));
101  lowerDurationLimitValue->SetText(ASCString::toString(actmap->weatherSystem->getLowerDurationLimit()));
102 
103  //Upper Duration Limit
104  int upperDurationLimitYPos = lowerDurationLimitYPos + GetTextHeight() * 2;
105  upperDurationLimitLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), upperDurationLimitYPos, xsize/3 , GetTextHeight()*2), "Upper Duration Limit:");
106  upperDurationLimitLabel->SetSizeByText();
107  upperDurationLimitValue = new PG_LineEdit(this, PG_Rect(valueXPos ,upperDurationLimitYPos, GuiDimension::getLineEditWidth() , GetTextHeight()*2));
108  upperDurationLimitValue->SetText(ASCString::toString(actmap->weatherSystem->getUpperDurationLimit()));
109  //FallOut
110  int fallOutYPos = upperDurationLimitYPos + GetTextHeight() * 2 + GuiDimension::getTopOffSet();
111  fallOutLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), fallOutYPos, xsize/3 , GetTextHeight()*2), "Fallout Chances:");
112  fallOutLabel->SetSizeByText();
113 
114  fallOutButton = new PG_Button(this, PG_Rect(valueXPos, fallOutYPos, (Width()- valueXPos)/2, 30), "Edit", 100);
115  fallOutButton->sigClick.connect( sigc::hide(sigc::mem_fun( *this, &WeatherDialog::editFallOut )));
116 
117  //WindSpeed
118  int windSpeedYPos = fallOutYPos + GetTextHeight() * 2;
119  windSpeedLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), windSpeedYPos, xsize/3 , GetTextHeight()*2), "WindSpeed Chances:");
120  windSpeedLabel->SetSizeByText();
121 
122  windSpeedButton = new PG_Button(this, PG_Rect(valueXPos, windSpeedYPos, (Width()- valueXPos)/2, 30), "Edit", 100);
123  windSpeedButton->sigClick.connect( sigc::hide(sigc::mem_fun( *this, &WeatherDialog::editWindSpeed)));
124 
125  //WindDirection
126  int windDirYPos = windSpeedYPos + GetTextHeight() + GuiDimension::getTopOffSet();
127  windDirectionLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), windDirYPos, xsize/3 , GetTextHeight()*2), "WindDirection Chances:");
128  windDirectionLabel->SetSizeByText();
129 
130  windDirectionButton = new PG_Button(this, PG_Rect(valueXPos, windDirYPos, (Width()- valueXPos)/2, 30), "Edit", 100);
131  windDirectionButton->sigClick.connect( sigc::hide(sigc::mem_fun( *this, &WeatherDialog::editWindDirection)));
132 
133  //eventAreas
134  int eventAreasYPos = windDirYPos + GetTextHeight() + GuiDimension::getTopOffSet();
135  eventAreasLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), eventAreasYPos, xsize/3 , GetTextHeight()*2), "Event driven weather:");
136  eventAreasLabel->SetSizeByText();
137  eventAreasButton = new PG_Button(this, PG_Rect(valueXPos, eventAreasYPos, (Width()- valueXPos)/2, 30), "Edit", 100);
138  eventAreasButton->sigClick.connect( sigc::hide(sigc::mem_fun( *this, &WeatherDialog::editEventAreas)));
139 
140  //eventWindChanges
141  int eventWindChangesYPos = eventAreasYPos + GetTextHeight() + GuiDimension::getTopOffSet();
142  eventWindChangesLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), eventWindChangesYPos, xsize/3 , GetTextHeight()*2), "Event driven wind changes:");
143  eventWindChangesLabel->SetSizeByText();
144  eventWindChangesButton = new PG_Button(this, PG_Rect(valueXPos, eventWindChangesYPos, (Width()- valueXPos)/2, 30), "Edit", 100);
145  eventWindChangesButton->sigClick.connect( sigc::hide(sigc::mem_fun( *this, &WeatherDialog::editEventWindChanges)));
146 
147 
148 
149  //Ok and Cancel Button
150  (new PG_Button(this, PG_Rect(30, Height()-40, (Width()-70)/2, 30), "OK", 100))->sigClick.connect( sigc::hide(sigc::mem_fun( *this, &WeatherDialog::buttonEvent )));
151  (new PG_Button(this, PG_Rect(Width()/2+5, Height()-40, (Width()-70)/2, 30), "Cancel", 101))->sigClick.connect( sigc::hide(sigc::mem_fun( *this, &WeatherDialog::closeWindow )));
152 
153  sigClose.connect( sigc::mem_fun( *this, &WeatherDialog::closeWindow ));
154 
155 }
156 
157 
159 
161  WeatherDialog wd;
162  wd.Show();
163  wd.RunModal();
164 }
165 
166 
167 bool WeatherDialog::buttonEvent( PG_Button* button ) {
168  if(randomMode->GetPressed()) {
169  actmap->weatherSystem->setEventMode(RANDOMMODE);
170  } else {
171  actmap->weatherSystem->setEventMode(EVENTMODE);
172  }
173 
174  if(seedMode->GetPressed()) {
175  actmap->weatherSystem->setSeedValueGeneration(false);
176  } else {
177  actmap->weatherSystem->setSeedValueGeneration(true);
178  }
179  actmap->weatherSystem->setDefaultFallout(static_cast<FalloutType>(this->weatherTypes->GetSelectedItemIndex()));
180  if(!((nthTurnValue->GetText()=="") ||
181  (windSpeedFieldRatioValue->GetText() == "") ||
182  (areaSpawnsValue->GetText() == "")||
183  (lowerSizeLimitsValue->GetText() == "") ||
184  (upperSizeLimitsValue->GetText() == "")
185  )) {
186  actmap->weatherSystem->setTimeInterval(atoi(nthTurnValue->GetText()));
187  actmap->weatherSystem->setWindSpeed2FieldRatio(atof(windSpeedFieldRatioValue->GetText()));
188  actmap->weatherSystem->setSpawnAmount(atoi(areaSpawnsValue->GetText()));
189 
190  actmap->weatherSystem->setRandomSizeBorders(atof(lowerSizeLimitsValue->GetText()), atof(upperSizeLimitsValue->GetText()) );
191  }
192  if(lowerDurationLimitValue->GetText()!=""){
193  actmap->weatherSystem->setLowerDurationLimit(atoi(lowerDurationLimitValue->GetText()));
194  }
195  if(upperDurationLimitValue->GetText()!=""){
196  actmap->weatherSystem->setUpperDurationLimit(atoi(upperDurationLimitValue->GetText()));
197  }
198 
199  quitModalLoop(1);
200  return true;
201 }
202 
203 bool WeatherDialog::editFallOut( PG_Button* button ) {
205  fd.Show();
206  fd.RunModal();
207  return true;
208 }
209 
210 bool WeatherDialog::editWindSpeed( PG_Button* button ) {
212  wsd.Show();
213  wsd.RunModal();
214  return true;
215 }
216 
217 bool WeatherDialog::editWindDirection( PG_Button* button ) {
219  wdd.Show();
220  wdd.RunModal();
221  return true;
222 }
223 
224 bool WeatherDialog::editEventAreas(PG_Button* button ) {
225  EventAreasDialog ead;
226  ead.Show();
227  ead.RunModal();
228  return true;
229 }
230 
231 
232 bool WeatherDialog::editEventWindChanges(PG_Button* button ) {
234  ewcd.Show();
235  ewcd.RunModal();
236  return true;
237 }
238 //*********************************************************************************************************
239 const int EventAreasDialog::xSize = 400;
240 const int EventAreasDialog::ySize = 400;
241 
242 EventAreasDialog::EventAreasDialog() : ASC_PG_Dialog(NULL, PG_Rect( 100, 100, xSize, ySize ), "Edit eventdriven Areas", SHOW_CLOSE ) {
243  int xPos1 = 20;
244  //EventBox
245  eventList = new PG_ListBox(this, PG_Rect(xPos1, 20, 350, 200));
246  eventList->SetMultiSelect (false);
247  for(int i =0; i< actmap->weatherSystem->getQueuedWeatherAreasSize(); i ++) {
248  pair<GameTime, WeatherArea*> p = actmap->weatherSystem->getNthWeatherArea(i);
249  WeatherAreaInformation* wai = new WeatherAreaInformation(p.second, p.first);
250  currentList.push_back(wai);
251  new PG_ListBoxItem(eventList, 20, wai->getInformation(), NULL, wai);
252  }
253 
254  //add Button
255  int yPosButtons = 20 + eventList->Height() + GuiDimension::getTopOffSet();
256  addButton = new PG_Button(this, PG_Rect(xPos1, yPosButtons, 70, 35), "Add", 90);
257  addButton->sigClick.connect( sigc::hide(sigc::mem_fun( *this, &EventAreasDialog::buttonAdd )));
258 
259  //remove Button
260  removeButton = new PG_Button(this, PG_Rect(Width() - (xPos1 + 70), yPosButtons, 70, 35), "Remove", 90);
261  removeButton->sigClick.connect( sigc::hide(sigc::mem_fun( *this, &EventAreasDialog::buttonRemove )));
262 
263  //Ok and Cancel Button
264  (new PG_Button(this, PG_Rect((Width()- GuiDimension::getButtonWidth())/2, Height()-40, GuiDimension::getButtonWidth() , 30), "OK", 100))->sigClick.connect( sigc::hide(sigc::mem_fun( *this, &EventAreasDialog::buttonEvent )));
265  //(new PG_Button(this, PG_Rect(Width()/2+5, Height()-40, (Width()-70)/2, 30), "Cancel", 101))->sigClick.connect( sigc::hide(sigc::mem_fun( *this, &EventAreasDialog::closeWindow )));
266 
267  sigClose.connect( sigc::mem_fun( *this, &EventAreasDialog::closeWindow ));
268 }
269 
271 
273  quitModalLoop(2);
274  return true;
275 };
276 
277 
278 bool EventAreasDialog::buttonEvent( PG_Button* button ) {
279  quitModalLoop(2);
280  return true;
281 }
282 
283 bool EventAreasDialog::buttonAdd( PG_Button* button ) {
284  AddWeatherAreaDialog awad(this);
285  awad.Show();
286  awad.RunModal();
287  return true;
288 }
289 
290 bool EventAreasDialog::buttonRemove( PG_Button* button ) {
291  std::vector< PG_ListBoxBaseItem * > items;
292  eventList->GetSelectedItems(items);
293  for(int i = 0; i < items.size(); i++) {
294  PG_ListBoxItem* lbi = dynamic_cast<PG_ListBoxItem*>(items[i]);
295  WeatherAreaInformation* wai = static_cast<WeatherAreaInformation*>(lbi->GetUserData());
296  actmap->weatherSystem->removeWeatherArea(wai->getTriggerTime(), wai->getWeatherArea());
297  delete wai;
298  delete lbi;
299  }
300  return true;
301 }
302 
304 
305  currentList.push_back(wai);
306  new PG_ListBoxItem(eventList, 20, wai->getInformation(), NULL, wai);
307  actmap->weatherSystem->addWeatherArea(wai->getWeatherArea(), wai->getTriggerTime());
308 }
309 
310 //*********************************************************************************************************
311 
312 WindInformation::WindInformation(WindData d, int t): data(d), turn(t) {
313 }
314 
316 }
317 
319  return turn;
320 }
321 
323  return data;
324 }
325 
326 std::string WindInformation::getInformation() const {
327  string result = "turn: ";
328  result.append(ASCString::toString(turn));
329  result.append(";");
330  result.append("speed: ");
331  result.append(ASCString::toString(static_cast<int>(data.speed)));
332  result.append(";");
333  result.append("direction: ");
334  result.append(cdirections[data.direction]);
335 
336  return result;
337 }
338 
339 //*********************************************************************************************************
340 const int EventWindChangesDialog::xSize = 400;
341 const int EventWindChangesDialog::ySize = 400;
342 
343 EventWindChangesDialog::EventWindChangesDialog() : ASC_PG_Dialog(NULL, PG_Rect( 100, 100, xSize, ySize ), "Edit eventdriven WindChange", SHOW_CLOSE ) {
344  int xPos1 = 20;
345  //EventBox
346  eventList = new PG_ListBox(this, PG_Rect(xPos1, 20, 350, 200));
347  eventList->SetMultiSelect (false);
348  for(int i =0; i< actmap->weatherSystem->getQueuedWindChangesSize(); i ++) {
349  pair<int, WindData> p = actmap->weatherSystem->getNthWindChange(i);
350  WindInformation* wi = new WindInformation(p.second, p.first);
351  currentList.push_back(wi);
352  new PG_ListBoxItem(eventList, 20, wi->getInformation(), NULL, wi);
353  }
354 
355  //add Button
356  int yPosButtons = 20 + eventList->Height() + GuiDimension::getTopOffSet();
357  addButton = new PG_Button(this, PG_Rect(xPos1, yPosButtons, 50, 35), "Add", 90);
358  addButton->sigClick.connect( sigc::hide(sigc::mem_fun( *this, &EventWindChangesDialog::buttonAdd )));
359 
360  //remove Button
361  removeButton = new PG_Button(this, PG_Rect(Width() - (xPos1 + 50), yPosButtons, 50, 35), "Remove", 90);
362  removeButton->sigClick.connect( sigc::hide(sigc::mem_fun( *this, &EventWindChangesDialog::buttonRemove )));
363 
364  //Ok and Cancel Button
365  (new PG_Button(this, PG_Rect((Width()-GuiDimension::getButtonWidth())/2, Height()-40, GuiDimension::getButtonWidth(), 30), "OK", 100))->sigClick.connect( sigc::hide(sigc::mem_fun( *this, &EventWindChangesDialog::buttonEvent )));
366  //(new PG_Button(this, PG_Rect(Width()/2+5, Height()-40, (Width()-70)/2, 30), "Cancel", 101))->sigClick.connect( sigc::hide(sigc::mem_fun( *this, &EventWindChangeDialog::closeWindow )));
367 
368  sigClose.connect( sigc::mem_fun( *this, &EventWindChangesDialog::closeWindow ));
369 }
370 
372 
374  quitModalLoop(2);
375  return true;
376 };
377 
378 
379 bool EventWindChangesDialog::buttonEvent( PG_Button* button ) {
380  quitModalLoop(1);
381  return true;
382 }
383 
384 bool EventWindChangesDialog::buttonAdd( PG_Button* button ) {
385  AddWindChangeDialog awcd(this);
386  awcd.Show();
387  awcd.RunModal();
388  return true;
389 }
390 
391 bool EventWindChangesDialog::buttonRemove( PG_Button* button ) {
392  std::vector< PG_ListBoxBaseItem * > items;
393  eventList->GetSelectedItems(items);
394  for(int i = 0; i < items.size(); i++) {
395  PG_ListBoxItem* lbi = dynamic_cast<PG_ListBoxItem*>(items[i]);
396  WindInformation* wi = static_cast<WindInformation*>(lbi->GetUserData());
397  actmap->weatherSystem->removeWindChange(wi->getTurn(), wi->getWindData());
398  delete wi;
399  delete lbi;
400  }
401  return true;
402 }
403 
405  currentList.push_back(wi);
406  new PG_ListBoxItem(eventList, 20, wi->getInformation(), NULL, wi);
407  actmap->weatherSystem->addGlobalWindChange(wi->getWindData().speed, wi->getWindData().direction, wi->getTurn());
408 }
409 
410 //*********************************************************************************************************
411 const int AddWindChangeDialog::xSize = 400;
412 const int AddWindChangeDialog::ySize = 400;
413 
414 const string SEPARATOR = ";";
415 
416 AddWindChangeDialog::AddWindChangeDialog(EventWindChangesDialog* ewcd): ASC_PG_Dialog(ewcd, PG_Rect( 0, 0, xSize, ySize ), "Add Weather Area", SHOW_CLOSE ) {
417  int valueXPos = static_cast<int>(xSize * 0.75);
418 
419  turnLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftOffSet(), GuiDimension::getTopOffSet(), 10, GetTextHeight() * 2), "Turn");
420  turnLabel->SetSizeByText();
421  turnValue = new PG_LineEdit(this, PG_Rect(valueXPos, GuiDimension::getTopOffSet(), GuiDimension::getLineEditWidth(), GetTextHeight() * 2));
422  turnValue->SetValidKeys("1234567890");
423 
424 
425  int speedYPos = GuiDimension::getTopOffSet() + GetTextHeight() * 2;
426  speedLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftOffSet(), speedYPos, 10, GetTextHeight() * 2), "Speed");
427  speedLabel->SetSizeByText();
428  speedValue = new PG_LineEdit(this, PG_Rect(valueXPos, speedYPos, GuiDimension::getLineEditWidth(), GetTextHeight() * 2));
429  speedValue->SetValidKeys("1234567890");
430 
431  int directionYPos = speedYPos + + GetTextHeight() * 2;
432  directionLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftOffSet(), directionYPos, 10, GetTextHeight() * 2), "Wind Direction");
433  directionLabel->SetSizeByText();
434  directionBox = new PG_DropDown(this, PG_Rect(valueXPos - valueXPos/2, directionYPos, GuiDimension::getLineEditWidth() *4, GetTextHeight() * 2));
435 
436 
437  for(int i = 0; i < WeatherSystem::WindDirNum; i++) {
438  directionBox->AddItem(cdirections[i]);
439  }
440 
441  //Ok and Cancel Button
442  (new PG_Button(this, PG_Rect(30, Height()-40, (Width()-70)/2, 30), "OK", 100))->sigClick.connect( sigc::hide(sigc::mem_fun( *this, &AddWindChangeDialog::buttonEvent )));
443  (new PG_Button(this, PG_Rect(Width()/2+5, Height()-40, (Width()-70)/2, 30), "Cancel", 101))->sigClick.connect( sigc::hide(sigc::mem_fun( *this, &AddWindChangeDialog::closeWindow )));
444 
445  sigClose.connect( sigc::mem_fun( *this, &AddWindChangeDialog::closeWindow ));
446 
447 }
448 
450 
451 bool AddWindChangeDialog::closeWindow() {
452  quitModalLoop(2);
453  return true;
454 }
455 
456 bool AddWindChangeDialog::buttonEvent( PG_Button* button ) {
457  if(!(speedValue->GetText() == "")||
458  (turnValue->GetText() == "")
459  ) {
460  int speed = atoi(speedValue->GetText());
461  int turn = atoi(turnValue->GetText());
462  Direction d = static_cast<Direction>(directionBox->GetSelectedItemIndex());
463  WindData data;
464  data.speed = speed;
465  data.direction = d;
466  WindInformation* wi = new WindInformation(data, turn);
467  EventWindChangesDialog* ewd = dynamic_cast<EventWindChangesDialog*>(this->GetParent());
468  ewd->addNewWindInformation(wi);
469  }
470  quitModalLoop(1);
471  return true;
472 }
473 
474 
475 //*********************************************************************************************************
476 WeatherAreaInformation::WeatherAreaInformation(WeatherArea* wa, GameTime t, int d, FalloutType f): weatherArea(wa), time(t), duration(d), fallOut(f) {}
478 }
480  //No delete of weatherArea is correct
481 }
482 
484  return time;
485 }
487  return duration;
488 
489 }
491  return fallOut;
492 }
493 
495  std::string info = "turn ";
496  info += ASCString::toString(time.turn());
497  info.append("; ");
498  info.append(cwettertypen[weatherArea->getFalloutType()]);
499  info.append("; ");
500  info.append("x: ");
501  info.append(ASCString::toString(weatherArea->getCenterPos().x));
502  info.append("; ");
503  info.append("y: ");
504  info.append(ASCString::toString(weatherArea->getCenterPos().y));
505 
506  return info;
507 }
508 
509 //*********************************************************************************************************
510 
511 const int AddWeatherAreaDialog::xSize = 400;
512 const int AddWeatherAreaDialog::ySize = 400;
513 
514 
515 AddWeatherAreaDialog::AddWeatherAreaDialog(EventAreasDialog* ead): ASC_PG_Dialog(ead, PG_Rect( 0, 0, xSize, ySize ), "Add Weather Area", SHOW_CLOSE ) {
516  int valueXPos = static_cast<int>(xSize * 0.75);
517 
518  turnLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftOffSet(), GuiDimension::getTopOffSet(), 10, GetTextHeight() * 2), "Turn");
519  turnLabel->SetSizeByText();
520  turnValue = new PG_LineEdit(this, PG_Rect(valueXPos, GuiDimension::getTopOffSet(), GuiDimension::getLineEditWidth(), GetTextHeight() * 2));
521  turnValue->SetValidKeys("1234567890");
522 
523  int durationYPos = GuiDimension::getTopOffSet() + GetTextHeight() * 2;
524  durationLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftOffSet(), durationYPos, 10, GetTextHeight() * 2), "Duration");
525  durationLabel->SetSizeByText();
526  durationValue = new PG_LineEdit(this, PG_Rect(valueXPos, durationYPos, GuiDimension::getLineEditWidth(), GetTextHeight() * 2));
527  durationValue->SetValidKeys("1234567890");
528 
529  int xCoordYPos = durationYPos + + GetTextHeight() * 2;
530  xCoordLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftOffSet(), xCoordYPos, 10, GetTextHeight() * 2), "xPosition");
531  xCoordLabel->SetSizeByText();
532  xCoordValue = new PG_LineEdit(this, PG_Rect(valueXPos, xCoordYPos, GuiDimension::getLineEditWidth(), GetTextHeight() * 2));
533  xCoordValue->SetValidKeys("1234567890");
534 
535  int yCoordYPos = xCoordYPos + + GetTextHeight() * 2;
536  yCoordLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftOffSet(), yCoordYPos, 10, GetTextHeight() * 2), "yPosition");
537  yCoordLabel->SetSizeByText();
538  yCoordValue = new PG_LineEdit(this, PG_Rect(valueXPos, yCoordYPos, GuiDimension::getLineEditWidth(), GetTextHeight() * 2));
539  yCoordValue->SetValidKeys("1234567890");
540 
541  int widthYPos = yCoordYPos + + GetTextHeight() * 2;
542  widthLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftOffSet(), widthYPos, 10, GetTextHeight() * 2), "Width");
543  widthLabel->SetSizeByText();
544  widthValue = new PG_LineEdit(this, PG_Rect(valueXPos, widthYPos, GuiDimension::getLineEditWidth(), GetTextHeight() * 2));
545  widthValue->SetValidKeys("1234567890");
546 
547  int heightYPos = widthYPos + + GetTextHeight() * 2;
548  heightLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftOffSet(), heightYPos, 10, GetTextHeight() * 2), "Height");
549  heightLabel->SetSizeByText();
550  heightValue = new PG_LineEdit(this, PG_Rect(valueXPos, heightYPos, GuiDimension::getLineEditWidth(), GetTextHeight() * 2));
551  heightValue->SetValidKeys("1234567890");
552 
553  int heightClustered = heightYPos + GetTextHeight() * 2;
554  clusteredMode = new PG_CheckButton(this, PG_Rect( GuiDimension::getLeftIndent(), heightClustered, GuiDimension::getLineEditWidth() , GetTextHeight()*2), "Clustered Mode");
555  clusteredMode->SetSizeByText();
556 
557  int wTypesYPos = heightClustered + GetTextHeight() * 2;
558  wTypesLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftOffSet(), wTypesYPos, 10, GetTextHeight() * 2), "Weather Type");
559  wTypesLabel->SetSizeByText();
560  weatherTypes = new PG_DropDown(this, PG_Rect(valueXPos - valueXPos/2, wTypesYPos, GuiDimension::getLineEditWidth() *4, GetTextHeight() * 2));
561 
562 
563  for(int i = 0; i < cwettertypennum; i++) {
564  weatherTypes->AddItem(cwettertypen[i]);
565 
566  }
567 
568  //Ok and Cancel Button
569  (new PG_Button(this, PG_Rect(30, Height()-40, (Width()-70)/2, 30), "OK", 100))->sigClick.connect( sigc::hide(sigc::mem_fun( *this, &AddWeatherAreaDialog::buttonEvent )));
570  (new PG_Button(this, PG_Rect(Width()/2+5, Height()-40, (Width()-70)/2, 30), "Cancel", 101))->sigClick.connect( sigc::hide(sigc::mem_fun( *this, &AddWeatherAreaDialog::closeWindow )));
571 
572  sigClose.connect( sigc::mem_fun( *this, &AddWeatherAreaDialog::closeWindow ));
573 
574 }
575 
577 
578 bool AddWeatherAreaDialog::closeWindow() {
579  quitModalLoop(2);
580  return true;
581 }
582 
583 bool AddWeatherAreaDialog::buttonEvent( PG_Button* button ) {
584  if(! (xCoordValue->GetText() == "") ||
585  (yCoordValue->GetText() == "") ||
586  (widthValue->GetText() == "") ||
587  (heightValue->GetText() == "") ||
588  (durationValue->GetText() == "") ||
589  (turnValue->GetText() == "")
590  ) {
591  FalloutType t = static_cast<FalloutType>(weatherTypes->GetSelectedItemIndex());
592  WeatherArea* newWeatherArea = new WeatherArea(actmap, atoi(xCoordValue->GetText()), atoi(yCoordValue->GetText()), atoi(widthValue->GetText()), atoi(heightValue->GetText()),
593  atoi(durationValue->GetText()), t, actmap->weatherSystem->createRandomValue(), clusteredMode->GetPressed());
594  GameTime time;
595  time.set(atoi(turnValue->GetText()), 0);
596  WeatherAreaInformation* wai = new WeatherAreaInformation(newWeatherArea, time);
597  EventAreasDialog* ead = dynamic_cast<EventAreasDialog*>(this->GetParent());
599  }
600  quitModalLoop(2);
601  return true;
602 }
603 
604 //*********************************************************************************************************
605 
606 const int ChanceSettingsDialog::xsize = 400;
607 const int ChanceSettingsDialog::ysize = 512;
608 
609 
610 ChanceSettingsDialog::ChanceSettingsDialog(std::string title): ASC_PG_Dialog(NULL, PG_Rect( 100, 100, xsize, ysize ), title, SHOW_CLOSE ) {}
611 
613 
614 void ChanceSettingsDialog::buildUpForm(const vector<string>& labelVec) {
615  int yPos = 0;
616  int valueXPos = static_cast<int>(xsize * 0.75);
617  for(int i = 0; i < labelVec.size(); i++) {
618  yPos += GetTextHeight()*2;
619  PG_Label* label = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), yPos, xsize/3 , GetTextHeight()*2), labelVec[i]);
620  label->SetSizeByText();
621  labels.push_back(label);
622  PG_LineEdit* value = new PG_LineEdit(this, PG_Rect(valueXPos , yPos, GuiDimension::getLineEditWidth() , GetTextHeight()*2));
623  value->SetText(ASCString::toString(getNthChanceValue(i)));
624  chances.push_back(value);
625  }
626  int noteYPos = yPos + GuiDimension::getTopOffSet() + GetTextHeight()*2;
627  note = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), noteYPos, xsize/3 , GetTextHeight()*2), "The sum of chances must equal 100");
628  note->SetSizeByText();
629  //Ok and Cancel Button
630  (new PG_Button(this, PG_Rect(30, Height()-40, (Width()-70)/2, 30), "OK", 100))->sigClick.connect( sigc::hide(sigc::mem_fun( *this, &ChanceSettingsDialog::buttonEvent )));
631  (new PG_Button(this, PG_Rect(Width()/2+5, Height()-40, (Width()-70)/2, 30), "Cancel", 101))->sigClick.connect( sigc::hide(sigc::mem_fun( *this, &ChanceSettingsDialog::closeWindow )));
632 
633  sigClose.connect( sigc::mem_fun( *this, &ChanceSettingsDialog::closeWindow ));
634 
635 }
636 
637 
638 bool ChanceSettingsDialog::buttonEvent( PG_Button* button ) {
639 
640  quitModalLoop(2);
641  return true;
642 }
643 
644 //*********************************************************************************************************++
646  vector<string> labels;
647  labels.push_back("Dry");
648  labels.push_back("Light Rain");
649  labels.push_back("Heavy Rain");
650  labels.push_back("Light Snowfall");
651  labels.push_back("Heavy Snowfall");
652  labels.push_back("Icy");
653 
654  buildUpForm(labels);
655 
656 }
657 
659 
660 void FallOutSettingsDialog::setChanceValues(const vector<PG_LineEdit*>& p) {
661  try {
662  Percentages c;
663  for(int i = 0; i < chances.size(); i++) {
664  c.push_back(atoi(chances[i]->GetText()));
665  }
666  actmap->weatherSystem->setLikelihoodFallOut(c);
667  } catch(IllegalValueException& e) {
668  cout << e.getMessage() << endl;
669  }
670 }
671 
672 int FallOutSettingsDialog::getNthChanceValue(int n) {
673  return actmap->weatherSystem->getFalloutPercentage(n);
674 }
675 
676 bool FallOutSettingsDialog::buttonEvent( PG_Button* button ) {
677  setChanceValues(chances);
678  quitModalLoop(2);
679  return true;
680 }
681 
682 
683 //****************************************************************************************************************
684 
686  vector<string> labels;
688  int slotSize = maxwindspeed / size;
689  int value =0;
690  for (int i = 0; i < size; i++) {
691  string label = ASCString::toString(value);
692  label += " - ";
693  label += ASCString::toString(value + slotSize);
694  labels.push_back(label);
695  value+= slotSize;
696  }
697  buildUpForm(labels);
698 }
699 
700 
702 
703 void WindSpeedSettingsDialog::setChanceValues(const vector<PG_LineEdit*>& p) {
704  try {
705  Percentages c;
706  for(int i = 0; i < chances.size(); i++) {
707  c.push_back(atoi(chances[i]->GetText()));
708  }
709  actmap->weatherSystem->setLikelihoodWindSpeed(c);
710  } catch(IllegalValueException& e) {
711  cout << e.getMessage() << endl; //If available rewrite to use of MsgBox
712  }
713 }
714 
715 int WindSpeedSettingsDialog::getNthChanceValue(int n) {
716  return actmap->weatherSystem->getWindSpeedPercentage(n);
717 }
718 
719 bool WindSpeedSettingsDialog::buttonEvent( PG_Button* button ) {
720  setChanceValues(chances);
721  quitModalLoop(2);
722  return true;
723 }
724 
725 
726 //*********************************************************************************************************++
728  vector<string> labels;
729  labels.push_back("North");
730  labels.push_back("NorthEast");
731  labels.push_back("East");
732  labels.push_back("SouthEast");
733  labels.push_back("South");
734  labels.push_back("SouthWest");
735  labels.push_back("West");
736  labels.push_back("NorthWest");
737 
738  buildUpForm(labels);
739 
740 }
741 
743 
744 void WindDirectionSettingsDialog::setChanceValues(const vector<PG_LineEdit*>& p) {
745  try {
746  Percentages c;
747  for(int i = 0; i < chances.size(); i++) {
748  c.push_back(atoi(chances[i]->GetText()));
749  }
750  actmap->weatherSystem->setLikelihoodWindDirection(c);
751  } catch(IllegalValueException& e) {
752  cout << e.getMessage() << endl;
753  }
754 }
755 
756 int WindDirectionSettingsDialog::getNthChanceValue(int n) {
757  return actmap->weatherSystem->getWindDirPercentage(n);
758 }
759 
760 bool WindDirectionSettingsDialog::buttonEvent( PG_Button* button ) {
761  setChanceValues(chances);
762  quitModalLoop(2);
763  return true;
764 }
765 
766 
767 
the time in ASC, measured in turns and moves
Definition: typen.h:178
vector< PG_Label * > labels
Definition: weatherdialog.h:47
map accessing and usage routines used by ASC and the mapeditor
WeatherArea * getWeatherArea()
const string SEPARATOR
virtual ~ChanceSettingsDialog()
double atof(const std::string &s)
Definition: misc.cpp:157
AddWindChangeDialog(EventWindChangesDialog *ead)
FalloutType getFalloutType() const
const char * cwettertypen[cwettertypennum]
the names of the different weather
Definition: typen.cpp:78
int turn() const
Definition: typen.h:181
static const int WindDirNum
Definition: weatherarea.h:285
WeatherAreaInformation(WeatherArea *wa, GameTime time, int duration, FalloutType fallOut)
MapCoordinate getCenterPos() const
Definition: weatherarea.h:183
static int getButtonWidth()
virtual bool closeWindow()
Definition: weatherdialog.h:33
Direction direction
Definition: weatherarea.h:105
virtual ~WeatherDialog()
WindData getWindData() const
FalloutType
Definition: weatherarea.h:94
ChanceSettingsDialog(std::string title)
static ASCString toString(int i)
converts the parameter to a String
Definition: ascstring.cpp:193
bool quitModalLoop(int value)
Definition: paradialog.cpp:545
Adapter class for using Paragui Dialogs in ASC. This class transfers the event control from ASC to Pa...
Definition: paradialog.h:127
void addNewWindInformation(WindInformation *wi)
vector< int > Percentages
Definition: weatherarea.h:121
void addNewWeatherAreaInformation(WeatherAreaInformation *wai)
unsigned int speed
Definition: weatherarea.h:104
int getTurn() const
vector< PG_LineEdit * > chances
Definition: weatherdialog.h:46
const ASCString & getMessage(void) const
Definition: errors.h:42
static const int xsize
Definition: weatherdialog.h:49
WindInformation(WindData data, int turn)
static int getLeftIndent()
static int getLineEditWidth()
FalloutType getFalloutType() const
GameTime getTriggerTime() const
int atoi(const std::string &s)
Definition: misc.cpp:152
void weatherConfigurationDialog()
AddWeatherAreaDialog(EventAreasDialog *ead)
virtual void buildUpForm(const vector< string > &labelVec)
std::string getInformation() const
Direction
Definition: weatherarea.h:84
GameMap * actmap
Definition: spfst.cpp:64
static int getTopOffSet()
const char * cdirections[WeatherSystem::WindDirNum]
Definition: weatherarea.cpp:20
const int cwettertypennum
The number of different weather.
Definition: typen.h:61
std::string getInformation() const
static const int WINDSPEEDDETAILLEVEL
Definition: weatherarea.h:286
const int maxwindspeed
Wind with its maximum strength of 255 is moving this distance per turn.
Definition: typen.h:501
static const int ysize
Definition: weatherdialog.h:50
static int getLeftOffSet()
void set(int turn, int move)
Definition: typen.h:183