Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

weatherdialog.cpp

Go to the documentation of this file.
00001 
00002 // C++ Implementation: weatherdialog
00003 //
00004 // Description:
00005 //
00006 //
00007 // Author: Martin Bickel <bickel@asc-hq.org>, (C) 2004
00008 //
00009 // Copyright: See COPYING file that comes with this distribution
00010 //
00011 //
00012 
00013 #include <iostream>
00014 #include <pglistboxitem.h>
00015 
00016 #include "weatherdialog.h"
00017 #include "weatherarea.h"
00018 #include "guidimension.h"
00019 #include "typen.h"
00020 #include "spfst.h"
00021 #include "ascstring.h"
00022 
00023 const int WeatherDialog::xsize = 500;
00024 const int WeatherDialog::ysize = 650;
00025 
00026 
00027 WeatherDialog::WeatherDialog() :  ASC_PG_Dialog(NULL, PG_Rect( 100, 50, xsize, ysize ), "Weather Configuration", SHOW_CLOSE ) {
00028 
00029     //Random Mode
00030     randomMode = new PG_CheckButton(this, PG_Rect( GuiDimension::getLeftIndent(), GuiDimension::getTopOffSet(), xsize/3 , GetTextHeight()*2), "Random Mode");
00031     randomMode->SetSizeByText();
00032     if(actmap->weatherSystem->getEventMode() == RANDOMMODE) {
00033         randomMode->SetPressed();
00034     }
00035 
00036     int seedModeYPos = ScreenToClient(0, randomMode->y).y + GetTextHeight() + GuiDimension::getTopOffSet();
00037     seedMode = new PG_CheckButton(this, PG_Rect( GuiDimension::getLeftIndent(), seedModeYPos, xsize/3 , GetTextHeight()*2), "Seed is Set");
00038     seedMode->SetSizeByText();
00039     if(actmap->weatherSystem->isSeedValueSet()) {
00040         seedMode->SetPressed();
00041     }
00042 
00043      //xPosition for edit Fields
00044     int valueXPos = static_cast<int>(xsize * 0.8);
00045     
00046     int defaultWeatherYPos = seedModeYPos + GetTextHeight()*2;
00047     defaultWeatherLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftOffSet(), defaultWeatherYPos, 10, GetTextHeight() * 2), "Default Weather");
00048     defaultWeatherLabel->SetSizeByText();
00049     weatherTypes = new PG_DropDown(this, PG_Rect(xsize - GuiDimension::getLineEditWidth() *5, defaultWeatherYPos, GuiDimension::getLineEditWidth() *4, GetTextHeight() * 2));
00050 
00051     for(int i = 0; i < cwettertypennum; i++) {
00052         weatherTypes->AddItem(cwettertypen[i]);
00053 
00054     }   
00055 
00056     //Amount of Area Spawns
00057     int areaSpawnsLabelYPos = defaultWeatherYPos + GetTextHeight()*2;
00058     areaSpawnsLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), areaSpawnsLabelYPos, xsize/3 , GetTextHeight()*2),
00059                                    "Amount of Spawns:");
00060     areaSpawnsLabel->SetSizeByText();
00061 
00062     areaSpawnsValue = new PG_LineEdit(this, PG_Rect(valueXPos, areaSpawnsLabelYPos, GuiDimension::getLineEditWidth() , GetTextHeight()*2));
00063     areaSpawnsValue->SetText(ASCString::toString(actmap->weatherSystem->getSpawnsAmount()));
00064 
00065 
00066     //Weather-Update each nth turn
00067     int nthTurnLabelYPos = areaSpawnsLabelYPos + GetTextHeight()*2;
00068     nthTurnLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), nthTurnLabelYPos, xsize/3 , GetTextHeight()*2),
00069                                 "Weather changes each nth Turn:");
00070     nthTurnLabel->SetSizeByText();
00071     nthTurnValue = new PG_LineEdit(this, PG_Rect(valueXPos, nthTurnLabelYPos, GuiDimension::getLineEditWidth() , GetTextHeight()*2));
00072     nthTurnValue->SetText(ASCString::toString(actmap->weatherSystem->getTimeInterval()));
00073 
00074     //Ratio windspeed to passed fields
00075     int windSpeedFieldRatioLabelYPos = nthTurnLabelYPos + GetTextHeight() * 2;
00076     windSpeedFieldRatioLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), windSpeedFieldRatioLabelYPos, xsize/3 , GetTextHeight()*2), "WindSpeed to Fields Ratio:");
00077     windSpeedFieldRatioLabel->SetSizeByText();
00078     windSpeedFieldRatioValue = new PG_LineEdit(this, PG_Rect(valueXPos, windSpeedFieldRatioLabelYPos, GuiDimension::getLineEditWidth() , GetTextHeight()*2));
00079     windSpeedFieldRatioValue->SetText(ASCString::toString(actmap->weatherSystem->getWindspeed2FieldRatio()));
00080 
00081     //LowerSize
00082     int lowerSizeLimitsYPos = windSpeedFieldRatioLabelYPos + GetTextHeight() * 2;
00083     lowerSizeLimitsLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), lowerSizeLimitsYPos, xsize/3 , GetTextHeight()*2), "Lower Area Size rel. to Mapsize:");
00084     lowerSizeLimitsLabel->SetSizeByText();
00085     lowerSizeLimitsValue = new PG_LineEdit(this, PG_Rect(valueXPos ,lowerSizeLimitsYPos, GuiDimension::getLineEditWidth() , GetTextHeight()*2));
00086     lowerSizeLimitsValue->SetText(ASCString::toString(actmap->weatherSystem->getLowerSizeLimit()));
00087 
00088     //UpperSize
00089     int upperSizeLimitsYPos =  lowerSizeLimitsYPos + GetTextHeight() * 2;
00090     upperSizeLimitsLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), upperSizeLimitsYPos, xsize/3 , GetTextHeight()*2), "Upper Area Size rel. to Mapsize:");
00091     upperSizeLimitsLabel->SetSizeByText();
00092     upperSizeLimitsValue = new PG_LineEdit(this, PG_Rect(valueXPos ,upperSizeLimitsYPos, GuiDimension::getLineEditWidth() , GetTextHeight()*2));
00093     upperSizeLimitsValue->SetText(ASCString::toString(actmap->weatherSystem->getUpperSizeLimit()));
00094     
00095     //Lower Duration Limit
00096     int lowerDurationLimitYPos = upperSizeLimitsYPos + GetTextHeight() * 2;
00097     lowerDurationLimitLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), lowerDurationLimitYPos, xsize/3 , GetTextHeight()*2), "Lower Duration Limit:");
00098     lowerDurationLimitLabel->SetSizeByText();
00099     lowerDurationLimitValue = new PG_LineEdit(this, PG_Rect(valueXPos ,lowerDurationLimitYPos, GuiDimension::getLineEditWidth(),
00100     GetTextHeight()*2));
00101     lowerDurationLimitValue->SetText(ASCString::toString(actmap->weatherSystem->getLowerDurationLimit()));
00102      
00103     //Upper Duration Limit
00104     int upperDurationLimitYPos = lowerDurationLimitYPos + GetTextHeight() * 2;
00105     upperDurationLimitLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), upperDurationLimitYPos, xsize/3 , GetTextHeight()*2), "Upper Duration Limit:");
00106     upperDurationLimitLabel->SetSizeByText();
00107     upperDurationLimitValue = new PG_LineEdit(this, PG_Rect(valueXPos ,upperDurationLimitYPos, GuiDimension::getLineEditWidth() , GetTextHeight()*2));
00108     upperDurationLimitValue->SetText(ASCString::toString(actmap->weatherSystem->getUpperDurationLimit()));
00109     //FallOut
00110     int fallOutYPos = upperDurationLimitYPos + GetTextHeight() * 2 + GuiDimension::getTopOffSet();    
00111     fallOutLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), fallOutYPos, xsize/3 , GetTextHeight()*2), "Fallout Chances:");
00112     fallOutLabel->SetSizeByText();
00113 
00114     fallOutButton = new PG_Button(this, PG_Rect(valueXPos, fallOutYPos, (Width()- valueXPos)/2, 30), "Edit", 100);
00115     fallOutButton->sigClick.connect(SigC::slot( *this, &WeatherDialog::editFallOut ));
00116 
00117     //WindSpeed
00118     int windSpeedYPos =  fallOutYPos + GetTextHeight() * 2;
00119     windSpeedLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), windSpeedYPos, xsize/3 , GetTextHeight()*2), "WindSpeed Chances:");
00120     windSpeedLabel->SetSizeByText();
00121 
00122     windSpeedButton = new PG_Button(this, PG_Rect(valueXPos, windSpeedYPos, (Width()- valueXPos)/2, 30), "Edit", 100);
00123     windSpeedButton->sigClick.connect(SigC::slot( *this, &WeatherDialog::editWindSpeed));
00124 
00125     //WindDirection
00126     int windDirYPos =  windSpeedYPos + GetTextHeight() + GuiDimension::getTopOffSet();
00127     windDirectionLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), windDirYPos, xsize/3 , GetTextHeight()*2), "WindDirection Chances:");
00128     windDirectionLabel->SetSizeByText();
00129 
00130     windDirectionButton = new PG_Button(this, PG_Rect(valueXPos, windDirYPos, (Width()- valueXPos)/2, 30), "Edit", 100);
00131     windDirectionButton->sigClick.connect(SigC::slot( *this, &WeatherDialog::editWindDirection));
00132 
00133     //eventAreas
00134     int eventAreasYPos = windDirYPos + GetTextHeight() + GuiDimension::getTopOffSet();
00135     eventAreasLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), eventAreasYPos, xsize/3 , GetTextHeight()*2), "Event driven weather:");
00136     eventAreasLabel->SetSizeByText();
00137     eventAreasButton = new PG_Button(this, PG_Rect(valueXPos, eventAreasYPos, (Width()- valueXPos)/2, 30), "Edit", 100);
00138     eventAreasButton->sigClick.connect(SigC::slot( *this, &WeatherDialog::editEventAreas));
00139 
00140     //eventWindChanges
00141     int eventWindChangesYPos = eventAreasYPos + GetTextHeight() + GuiDimension::getTopOffSet();
00142     eventWindChangesLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), eventWindChangesYPos, xsize/3 , GetTextHeight()*2), "Event driven wind changes:");
00143     eventWindChangesLabel->SetSizeByText();
00144     eventWindChangesButton = new PG_Button(this, PG_Rect(valueXPos, eventWindChangesYPos, (Width()- valueXPos)/2, 30), "Edit", 100);
00145     eventWindChangesButton->sigClick.connect(SigC::slot( *this, &WeatherDialog::editEventWindChanges));
00146 
00147 
00148 
00149     //Ok and Cancel Button
00150     (new PG_Button(this, PG_Rect(30, Height()-40, (Width()-70)/2, 30), "OK", 100))->sigClick.connect(SigC::slot( *this, &WeatherDialog::buttonEvent ));
00151     (new PG_Button(this, PG_Rect(Width()/2+5, Height()-40, (Width()-70)/2, 30), "Cancel", 101))->sigClick.connect(SigC::slot( *this, &WeatherDialog::closeWindow ));
00152 
00153     sigClose.connect( SigC::slot( *this, &WeatherDialog::closeWindow ));
00154 
00155 }
00156 
00157 
00158 WeatherDialog::~WeatherDialog() {}
00159 
00160 void weatherConfigurationDialog() {
00161     WeatherDialog wd;
00162     wd.Show();
00163     wd.RunModal();
00164 }
00165 
00166 
00167 bool WeatherDialog::buttonEvent( PG_Button* button ) {
00168     if(randomMode->GetPressed()) {
00169         actmap->weatherSystem->setEventMode(RANDOMMODE);
00170     } else {
00171         actmap->weatherSystem->setEventMode(EVENTMODE);
00172     }
00173 
00174     if(seedMode->GetPressed()) {
00175         actmap->weatherSystem->setSeedValueGeneration(false);
00176     } else {
00177         actmap->weatherSystem->setSeedValueGeneration(true);
00178     }
00179     actmap->weatherSystem->setDefaultFallout(static_cast<FalloutType>(this->weatherTypes->GetSelectedItemIndex()));
00180     if(!((nthTurnValue->GetText()=="") ||
00181             (windSpeedFieldRatioValue->GetText() == "") ||
00182             (areaSpawnsValue->GetText() == "")||
00183             (lowerSizeLimitsValue->GetText() == "") ||
00184             (upperSizeLimitsValue->GetText() == "")
00185         )) {
00186         actmap->weatherSystem->setTimeInterval(atoi(nthTurnValue->GetText()));
00187         actmap->weatherSystem->setWindSpeed2FieldRatio(atof(windSpeedFieldRatioValue->GetText()));
00188         actmap->weatherSystem->setSpawnAmount(atoi(areaSpawnsValue->GetText()));
00189 
00190         actmap->weatherSystem->setRandomSizeBorders(atof(lowerSizeLimitsValue->GetText()), atof(upperSizeLimitsValue->GetText()) );
00191     }
00192     if(lowerDurationLimitValue->GetText()!=""){
00193       actmap->weatherSystem->setLowerDurationLimit(atoi(lowerDurationLimitValue->GetText()));
00194     }
00195     if(upperDurationLimitValue->GetText()!=""){
00196       actmap->weatherSystem->setUpperDurationLimit(atoi(upperDurationLimitValue->GetText()));
00197     }
00198 
00199     quitModalLoop(1);
00200     return true;
00201 }
00202 
00203 bool WeatherDialog::editFallOut( PG_Button* button ) {
00204     FallOutSettingsDialog fd;
00205     fd.Show();
00206     fd.RunModal();
00207     return true;
00208 }
00209 
00210 bool WeatherDialog::editWindSpeed( PG_Button* button ) {
00211     WindSpeedSettingsDialog wsd;
00212     wsd.Show();
00213     wsd.RunModal();
00214     return true;
00215 }
00216 
00217 bool WeatherDialog::editWindDirection( PG_Button* button ) {
00218     WindDirectionSettingsDialog wdd;
00219     wdd.Show();
00220     wdd.RunModal();
00221     return true;
00222 }
00223 
00224 bool WeatherDialog::editEventAreas(PG_Button* button ) {
00225     EventAreasDialog ead;
00226     ead.Show();
00227     ead.RunModal();
00228     return true;
00229 }
00230 
00231 
00232 bool WeatherDialog::editEventWindChanges(PG_Button* button ) {
00233     EventWindChangesDialog ewcd;
00234     ewcd.Show();
00235     ewcd.RunModal();
00236     return true;
00237 }
00238 //*********************************************************************************************************
00239 const int EventAreasDialog::xSize = 400;
00240 const int EventAreasDialog::ySize = 400;
00241 
00242 EventAreasDialog::EventAreasDialog() : ASC_PG_Dialog(NULL, PG_Rect( 100, 100, xSize, ySize ), "Edit eventdriven Areas", SHOW_CLOSE ) {
00243     int xPos1 = 20;
00244     //EventBox
00245     eventList = new PG_ListBox(this, PG_Rect(xPos1, 20, 350, 200));
00246     eventList->SetMultiSelect (false);
00247     for(int i =0; i< actmap->weatherSystem->getQueuedWeatherAreasSize(); i ++) {
00248         pair<GameTime, WeatherArea*> p = actmap->weatherSystem->getNthWeatherArea(i);
00249         WeatherAreaInformation* wai = new WeatherAreaInformation(p.second, p.first);
00250         currentList.push_back(wai);
00251         new PG_ListBoxItem(eventList, 20, wai->getInformation(), NULL, wai);
00252     }
00253 
00254     //add Button
00255     int yPosButtons = 20 + eventList->Height() + GuiDimension::getTopOffSet();
00256     addButton = new PG_Button(this, PG_Rect(xPos1, yPosButtons, 70, 35), "Add", 90);
00257     addButton->sigClick.connect(SigC::slot( *this, &EventAreasDialog::buttonAdd ));
00258 
00259     //remove Button
00260     removeButton = new PG_Button(this, PG_Rect(Width() - (xPos1 + 70), yPosButtons, 70, 35), "Remove", 90);
00261     removeButton->sigClick.connect(SigC::slot( *this, &EventAreasDialog::buttonRemove ));
00262 
00263     //Ok and Cancel Button
00264     (new PG_Button(this, PG_Rect((Width()- GuiDimension::getButtonWidth())/2, Height()-40, GuiDimension::getButtonWidth() , 30), "OK", 100))->sigClick.connect(SigC::slot( *this, &EventAreasDialog::buttonEvent ));
00265     //(new PG_Button(this, PG_Rect(Width()/2+5, Height()-40, (Width()-70)/2, 30), "Cancel", 101))->sigClick.connect(SigC::slot( *this, &EventAreasDialog::closeWindow ));
00266 
00267     sigClose.connect( SigC::slot( *this, &EventAreasDialog::closeWindow ));
00268 }
00269 
00270 EventAreasDialog::~EventAreasDialog() {}
00271 
00272 bool EventAreasDialog::closeWindow() {
00273     quitModalLoop(2);
00274     return true;
00275 };
00276 
00277 
00278 bool EventAreasDialog::buttonEvent( PG_Button* button ) {
00279     quitModalLoop(2);
00280     return true;
00281 }
00282 
00283 bool EventAreasDialog::buttonAdd( PG_Button* button ) {
00284     AddWeatherAreaDialog awad(this);
00285     awad.Show();
00286     awad.RunModal();
00287     return true;
00288 }
00289 
00290 bool EventAreasDialog::buttonRemove( PG_Button* button ) {
00291     std::vector< PG_ListBoxBaseItem * > items;
00292     eventList->GetSelectedItems(items);
00293     for(int i = 0; i < items.size(); i++) {
00294         PG_ListBoxItem* lbi = dynamic_cast<PG_ListBoxItem*>(items[i]);
00295         WeatherAreaInformation* wai = static_cast<WeatherAreaInformation*>(lbi->GetUserData());
00296         actmap->weatherSystem->removeWeatherArea(wai->getTriggerTime(), wai->getWeatherArea());
00297         delete wai;
00298         delete lbi;
00299     }
00300     return true;
00301 }
00302 
00303 void EventAreasDialog::addNewWeatherAreaInformation(WeatherAreaInformation* wai) {
00304 
00305     currentList.push_back(wai);
00306     new PG_ListBoxItem(eventList, 20, wai->getInformation(), NULL, wai);
00307     actmap->weatherSystem->addWeatherArea(wai->getWeatherArea(), wai->getTriggerTime());
00308 }
00309 
00310 //*********************************************************************************************************
00311 
00312 WindInformation::WindInformation(WindData d, int t): data(d), turn(t) {
00313 }
00314 
00315 WindInformation::~WindInformation() {
00316 }
00317 
00318 int WindInformation::getTurn() const {
00319     return turn;
00320 }
00321 
00322 WindData WindInformation::getWindData() const {
00323     return data;
00324 }
00325 
00326 std::string WindInformation::getInformation() const {
00327     string result = "turn: ";
00328     result.append(ASCString::toString(turn));
00329     result.append(";");
00330     result.append("speed: ");
00331     result.append(ASCString::toString(static_cast<int>(data.speed)));
00332     result.append(";");
00333     result.append("direction: ");
00334     result.append(cdirections[data.direction]);
00335 
00336     return result;
00337 }
00338 
00339 //*********************************************************************************************************
00340 const int EventWindChangesDialog::xSize = 400;
00341 const int EventWindChangesDialog::ySize = 400;
00342 
00343 EventWindChangesDialog::EventWindChangesDialog() : ASC_PG_Dialog(NULL, PG_Rect( 100, 100, xSize, ySize ), "Edit eventdriven WindChange", SHOW_CLOSE ) {
00344     int xPos1 = 20;
00345     //EventBox
00346     eventList = new PG_ListBox(this, PG_Rect(xPos1, 20, 350, 200));
00347     eventList->SetMultiSelect (false);
00348     for(int i =0; i< actmap->weatherSystem->getQueuedWindChangesSize(); i ++) {
00349         pair<int, WindData> p = actmap->weatherSystem->getNthWindChange(i);
00350         WindInformation* wi = new WindInformation(p.second, p.first);
00351         currentList.push_back(wi);
00352         new PG_ListBoxItem(eventList, 20, wi->getInformation(), NULL, wi);
00353     }
00354 
00355     //add Button
00356     int yPosButtons = 20 + eventList->Height() + GuiDimension::getTopOffSet();
00357     addButton = new PG_Button(this, PG_Rect(xPos1, yPosButtons, 50, 35), "Add", 90);
00358     addButton->sigClick.connect(SigC::slot( *this, &EventWindChangesDialog::buttonAdd ));
00359 
00360     //remove Button
00361     removeButton = new PG_Button(this, PG_Rect(Width() - (xPos1 + 50), yPosButtons, 50, 35), "Remove", 90);
00362     removeButton->sigClick.connect(SigC::slot( *this, &EventWindChangesDialog::buttonRemove ));
00363 
00364     //Ok and Cancel Button
00365     (new PG_Button(this, PG_Rect((Width()-GuiDimension::getButtonWidth())/2, Height()-40, GuiDimension::getButtonWidth(), 30), "OK", 100))->sigClick.connect(SigC::slot( *this, &EventWindChangesDialog::buttonEvent ));
00366     //(new PG_Button(this, PG_Rect(Width()/2+5, Height()-40, (Width()-70)/2, 30), "Cancel", 101))->sigClick.connect(SigC::slot( *this, &EventWindChangeDialog::closeWindow ));
00367 
00368     sigClose.connect( SigC::slot( *this, &EventWindChangesDialog::closeWindow ));
00369 }
00370 
00371 EventWindChangesDialog::~EventWindChangesDialog() {}
00372 
00373 bool EventWindChangesDialog::closeWindow() {
00374     quitModalLoop(2);
00375     return true;
00376 };
00377 
00378 
00379 bool EventWindChangesDialog::buttonEvent( PG_Button* button ) {
00380     quitModalLoop(1);
00381     return true;
00382 }
00383 
00384 bool EventWindChangesDialog::buttonAdd( PG_Button* button ) {
00385     AddWindChangeDialog awcd(this);
00386     awcd.Show();
00387     awcd.RunModal();
00388     return true;
00389 }
00390 
00391 bool EventWindChangesDialog::buttonRemove( PG_Button* button ) {
00392     std::vector< PG_ListBoxBaseItem * > items;
00393     eventList->GetSelectedItems(items);
00394     for(int i = 0; i < items.size(); i++) {
00395         PG_ListBoxItem* lbi = dynamic_cast<PG_ListBoxItem*>(items[i]);
00396         WindInformation* wi = static_cast<WindInformation*>(lbi->GetUserData());
00397         actmap->weatherSystem->removeWindChange(wi->getTurn(), wi->getWindData());
00398         delete wi;
00399         delete lbi;
00400     }
00401     return true;
00402 }
00403 
00404 void EventWindChangesDialog::addNewWindInformation(WindInformation* wi) {
00405     currentList.push_back(wi);
00406     new PG_ListBoxItem(eventList, 20, wi->getInformation(), NULL, wi);
00407     actmap->weatherSystem->addGlobalWindChange(wi->getWindData().speed, wi->getWindData().direction, wi->getTurn());
00408 }
00409 
00410 //*********************************************************************************************************
00411 const int AddWindChangeDialog::xSize = 400;
00412 const int AddWindChangeDialog::ySize = 400;
00413 
00414 const string SEPERATOR = ";";
00415 
00416 AddWindChangeDialog::AddWindChangeDialog(EventWindChangesDialog* ewcd):  ASC_PG_Dialog(ewcd, PG_Rect( 0, 0, xSize, ySize ), "Add Weather Area", SHOW_CLOSE ) {
00417     int valueXPos = static_cast<int>(xSize * 0.75);
00418 
00419     turnLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftOffSet(), GuiDimension::getTopOffSet(), 10, GetTextHeight() * 2), "Turn");
00420     turnLabel->SetSizeByText();
00421     turnValue = new PG_LineEdit(this, PG_Rect(valueXPos,  GuiDimension::getTopOffSet(), GuiDimension::getLineEditWidth(), GetTextHeight() * 2));
00422     turnValue->SetValidKeys("1234567890");
00423 
00424 
00425     int speedYPos = GuiDimension::getTopOffSet() + GetTextHeight() * 2;
00426     speedLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftOffSet(), speedYPos, 10, GetTextHeight() * 2), "Speed");
00427     speedLabel->SetSizeByText();
00428     speedValue = new PG_LineEdit(this, PG_Rect(valueXPos, speedYPos, GuiDimension::getLineEditWidth(), GetTextHeight() * 2));
00429     speedValue->SetValidKeys("1234567890");
00430 
00431     int directionYPos = speedYPos + + GetTextHeight() * 2;
00432     directionLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftOffSet(), directionYPos, 10, GetTextHeight() * 2), "Wind Direction");
00433     directionLabel->SetSizeByText();
00434     directionBox = new PG_DropDown(this, PG_Rect(valueXPos - valueXPos/2, directionYPos, GuiDimension::getLineEditWidth() *4, GetTextHeight() * 2));
00435 
00436 
00437     for(int i = 0; i < WeatherSystem::WindDirNum; i++) {
00438         directionBox->AddItem(cdirections[i]);
00439     }
00440 
00441     //Ok and Cancel Button
00442     (new PG_Button(this, PG_Rect(30, Height()-40, (Width()-70)/2, 30), "OK", 100))->sigClick.connect(SigC::slot( *this, &AddWindChangeDialog::buttonEvent ));
00443     (new PG_Button(this, PG_Rect(Width()/2+5, Height()-40, (Width()-70)/2, 30), "Cancel", 101))->sigClick.connect(SigC::slot( *this, &AddWindChangeDialog::closeWindow ));
00444 
00445     sigClose.connect( SigC::slot( *this, &AddWindChangeDialog::closeWindow ));
00446 
00447 }
00448 
00449 AddWindChangeDialog::~AddWindChangeDialog() {}
00450 
00451 bool AddWindChangeDialog::closeWindow() {
00452     quitModalLoop(2);
00453     return true;
00454 }
00455 
00456 bool AddWindChangeDialog::buttonEvent( PG_Button* button ) {
00457     if(!(speedValue->GetText() == "")||
00458             (turnValue->GetText() == "")
00459       ) {
00460         int speed = atoi(speedValue->GetText());
00461         int turn = atoi(turnValue->GetText());
00462         Direction d = static_cast<Direction>(directionBox->GetSelectedItemIndex());
00463         WindData data;
00464         data.speed = speed;
00465         data.direction = d;
00466         WindInformation* wi = new WindInformation(data, turn);
00467         EventWindChangesDialog* ewd = dynamic_cast<EventWindChangesDialog*>(this->GetParent());
00468         ewd->addNewWindInformation(wi);
00469     }
00470     quitModalLoop(1);
00471     return true;
00472 }
00473 
00474 
00475 //*********************************************************************************************************
00476 WeatherAreaInformation::WeatherAreaInformation(WeatherArea* wa, GameTime t, int d, FalloutType f): weatherArea(wa), time(t), duration(d), fallOut(f) {}
00477 WeatherAreaInformation::WeatherAreaInformation(WeatherArea* wa, GameTime t): weatherArea(wa), time(t) {
00478 }
00479 WeatherAreaInformation::~WeatherAreaInformation() {
00480     //No delete of weatherArea is correct
00481 }
00482 
00483 GameTime WeatherAreaInformation::getTriggerTime() const {
00484     return time;
00485 }
00486 int WeatherAreaInformation::getDuration() const {
00487     return duration;
00488 
00489 }
00490 FalloutType WeatherAreaInformation::getFalloutType() const {
00491     return fallOut;
00492 }
00493 
00494 std::string WeatherAreaInformation::getInformation() const {
00495     std::string info = "turn ";
00496     info += ASCString::toString(time.turn());
00497     info.append("; ");
00498     info.append(cwettertypen[weatherArea->getFalloutType()]);
00499     info.append("; ");
00500     info.append("x: ");
00501     info.append(ASCString::toString(weatherArea->getCenterPos().x));
00502     info.append("; ");
00503     info.append("y: ");
00504     info.append(ASCString::toString(weatherArea->getCenterPos().y));
00505 
00506     return info;
00507 }
00508 
00509 //*********************************************************************************************************
00510 
00511 const int AddWeatherAreaDialog::xSize = 400;
00512 const int AddWeatherAreaDialog::ySize = 400;
00513 
00514 
00515 AddWeatherAreaDialog::AddWeatherAreaDialog(EventAreasDialog* ead):  ASC_PG_Dialog(ead, PG_Rect( 0, 0, xSize, ySize ), "Add Weather Area", SHOW_CLOSE ) {
00516     int valueXPos = static_cast<int>(xSize * 0.75);
00517 
00518     turnLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftOffSet(), GuiDimension::getTopOffSet(), 10, GetTextHeight() * 2), "Turn");
00519     turnLabel->SetSizeByText();
00520     turnValue = new PG_LineEdit(this, PG_Rect(valueXPos,  GuiDimension::getTopOffSet(), GuiDimension::getLineEditWidth(), GetTextHeight() * 2));
00521     turnValue->SetValidKeys("1234567890");
00522 
00523     int durationYPos = GuiDimension::getTopOffSet() + GetTextHeight() * 2;
00524     durationLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftOffSet(), durationYPos, 10, GetTextHeight() * 2), "Duration");
00525     durationLabel->SetSizeByText();
00526     durationValue = new PG_LineEdit(this, PG_Rect(valueXPos,  durationYPos, GuiDimension::getLineEditWidth(), GetTextHeight() * 2));
00527     durationValue->SetValidKeys("1234567890");
00528 
00529     int xCoordYPos = durationYPos + + GetTextHeight() * 2;
00530     xCoordLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftOffSet(), xCoordYPos, 10, GetTextHeight() * 2), "xPosition");
00531     xCoordLabel->SetSizeByText();
00532     xCoordValue = new PG_LineEdit(this, PG_Rect(valueXPos,  xCoordYPos, GuiDimension::getLineEditWidth(), GetTextHeight() * 2));
00533     xCoordValue->SetValidKeys("1234567890");
00534 
00535     int yCoordYPos = xCoordYPos + + GetTextHeight() * 2;
00536     yCoordLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftOffSet(), yCoordYPos, 10, GetTextHeight() * 2), "yPosition");
00537     yCoordLabel->SetSizeByText();
00538     yCoordValue = new PG_LineEdit(this, PG_Rect(valueXPos,  yCoordYPos, GuiDimension::getLineEditWidth(), GetTextHeight() * 2));
00539     yCoordValue->SetValidKeys("1234567890");
00540 
00541     int widthYPos = yCoordYPos + + GetTextHeight() * 2;
00542     widthLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftOffSet(), widthYPos, 10, GetTextHeight() * 2), "Width");
00543     widthLabel->SetSizeByText();
00544     widthValue = new PG_LineEdit(this, PG_Rect(valueXPos, widthYPos, GuiDimension::getLineEditWidth(), GetTextHeight() * 2));
00545     widthValue->SetValidKeys("1234567890");
00546 
00547     int heightYPos = widthYPos + + GetTextHeight() * 2;
00548     heightLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftOffSet(), heightYPos, 10, GetTextHeight() * 2), "Height");
00549     heightLabel->SetSizeByText();
00550     heightValue = new PG_LineEdit(this, PG_Rect(valueXPos, heightYPos, GuiDimension::getLineEditWidth(), GetTextHeight() * 2));
00551     heightValue->SetValidKeys("1234567890");
00552 
00553     int heightClustered = heightYPos + GetTextHeight() * 2;
00554     clusteredMode = new PG_CheckButton(this, PG_Rect( GuiDimension::getLeftIndent(), heightClustered, GuiDimension::getLineEditWidth() , GetTextHeight()*2), "Clustered Mode");
00555     clusteredMode->SetSizeByText();
00556     
00557     int wTypesYPos = heightClustered + GetTextHeight() * 2;
00558     wTypesLabel = new PG_Label(this, PG_Rect(GuiDimension::getLeftOffSet(), wTypesYPos, 10, GetTextHeight() * 2), "Weather Type");
00559     wTypesLabel->SetSizeByText();
00560     weatherTypes = new PG_DropDown(this, PG_Rect(valueXPos - valueXPos/2, wTypesYPos, GuiDimension::getLineEditWidth() *4, GetTextHeight() * 2));
00561 
00562 
00563     for(int i = 0; i < cwettertypennum; i++) {
00564         weatherTypes->AddItem(cwettertypen[i]);
00565 
00566     }
00567 
00568     //Ok and Cancel Button
00569     (new PG_Button(this, PG_Rect(30, Height()-40, (Width()-70)/2, 30), "OK", 100))->sigClick.connect(SigC::slot( *this, &AddWeatherAreaDialog::buttonEvent ));
00570     (new PG_Button(this, PG_Rect(Width()/2+5, Height()-40, (Width()-70)/2, 30), "Cancel", 101))->sigClick.connect(SigC::slot( *this, &AddWeatherAreaDialog::closeWindow ));
00571 
00572     sigClose.connect( SigC::slot( *this, &AddWeatherAreaDialog::closeWindow ));
00573 
00574 }
00575 
00576 AddWeatherAreaDialog::~AddWeatherAreaDialog() {}
00577 
00578 bool AddWeatherAreaDialog::closeWindow() {
00579     quitModalLoop(2);
00580     return true;
00581 }
00582 
00583 bool AddWeatherAreaDialog::buttonEvent( PG_Button* button ) {
00584     if(! (xCoordValue->GetText() == "") ||
00585             (yCoordValue->GetText() == "") ||
00586             (widthValue->GetText() == "") ||
00587             (heightValue->GetText() == "") ||
00588             (durationValue->GetText() == "") ||
00589             (turnValue->GetText() == "")
00590       ) {
00591         FalloutType t = static_cast<FalloutType>(weatherTypes->GetSelectedItemIndex());
00592         WeatherArea* newWeatherArea = new WeatherArea(actmap, atoi(xCoordValue->GetText()), atoi(yCoordValue->GetText()),  atoi(widthValue->GetText()), atoi(heightValue->GetText()),
00593         atoi(durationValue->GetText()), t, actmap->weatherSystem->createRandomValue(), clusteredMode->GetPressed());
00594         GameTime time;
00595         time.set(atoi(turnValue->GetText()), 0);
00596         WeatherAreaInformation* wai = new WeatherAreaInformation(newWeatherArea, time);
00597         EventAreasDialog* ead = dynamic_cast<EventAreasDialog*>(this->GetParent());
00598         ead->addNewWeatherAreaInformation(wai);
00599     }
00600     quitModalLoop(2);
00601     return true;
00602 }
00603 
00604 //*********************************************************************************************************
00605 
00606 const int ChanceSettingsDialog::xsize = 400;
00607 const int ChanceSettingsDialog::ysize = 512;
00608 
00609 
00610 ChanceSettingsDialog::ChanceSettingsDialog(std::string title): ASC_PG_Dialog(NULL, PG_Rect( 100, 100, xsize, ysize ), title, SHOW_CLOSE ) {}
00611 
00612 ChanceSettingsDialog::~ChanceSettingsDialog() {}
00613 
00614 void ChanceSettingsDialog::buildUpForm(const vector<string>& labelVec) {
00615     int yPos = 0;
00616     int valueXPos = static_cast<int>(xsize * 0.75);
00617     for(int i = 0; i < labelVec.size(); i++) {
00618         yPos += GetTextHeight()*2;
00619         PG_Label* label = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), yPos, xsize/3 , GetTextHeight()*2), labelVec[i]);
00620         label->SetSizeByText();
00621         labels.push_back(label);
00622         PG_LineEdit* value = new PG_LineEdit(this, PG_Rect(valueXPos , yPos, GuiDimension::getLineEditWidth() , GetTextHeight()*2));
00623         value->SetText(ASCString::toString(getNthChanceValue(i)));
00624         chances.push_back(value);
00625     }
00626     int noteYPos = yPos + GuiDimension::getTopOffSet() + GetTextHeight()*2;
00627     note = new PG_Label(this, PG_Rect(GuiDimension::getLeftIndent(), noteYPos, xsize/3 , GetTextHeight()*2), "The sum of chances must equal 100");
00628     note->SetSizeByText();
00629     //Ok and Cancel Button
00630     (new PG_Button(this, PG_Rect(30, Height()-40, (Width()-70)/2, 30), "OK", 100))->sigClick.connect(SigC::slot( *this, &ChanceSettingsDialog::buttonEvent ));
00631     (new PG_Button(this, PG_Rect(Width()/2+5, Height()-40, (Width()-70)/2, 30), "Cancel", 101))->sigClick.connect(SigC::slot( *this, &ChanceSettingsDialog::closeWindow ));
00632 
00633     sigClose.connect( SigC::slot( *this, &ChanceSettingsDialog::closeWindow ));
00634 
00635 }
00636 
00637 
00638 bool ChanceSettingsDialog::buttonEvent( PG_Button* button ) {
00639 
00640     quitModalLoop(2);
00641     return true;
00642 }
00643 
00644 //*********************************************************************************************************++
00645 FallOutSettingsDialog::FallOutSettingsDialog():ChanceSettingsDialog("Fallout Chances") {
00646     vector<string> labels;
00647     labels.push_back("Dry");
00648     labels.push_back("Light Rain");
00649     labels.push_back("Heavy Rain");
00650     labels.push_back("Light Snowfall");
00651     labels.push_back("Heavy Snowfall");
00652     labels.push_back("Icy");
00653 
00654     buildUpForm(labels);
00655 
00656 }
00657 
00658 FallOutSettingsDialog::~FallOutSettingsDialog() {}
00659 
00660 void FallOutSettingsDialog::setChanceValues(const vector<PG_LineEdit*>& p) {
00661     try {
00662         Percentages c;
00663         for(int i = 0; i < chances.size(); i++) {
00664             c.push_back(atoi(chances[i]->GetText()));
00665         }
00666         actmap->weatherSystem->setLikelihoodFallOut(c);
00667     } catch(IllegalValueException& e) {
00668         cout << e.getMessage() << endl;
00669     }
00670 }
00671 
00672 int FallOutSettingsDialog::getNthChanceValue(int n) {
00673     return actmap->weatherSystem->getFalloutPercentage(n);
00674 }
00675 
00676 bool FallOutSettingsDialog::buttonEvent( PG_Button* button ) {
00677     setChanceValues(chances);
00678     quitModalLoop(2);
00679     return true;
00680 }
00681 
00682 
00683 //****************************************************************************************************************
00684 
00685 WindSpeedSettingsDialog::WindSpeedSettingsDialog():ChanceSettingsDialog("Windspeed Chances") {
00686     vector<string> labels;
00687     int size = WeatherSystem::WINDSPEEDDETAILLEVEL;
00688     int slotSize = maxwindspeed / size;
00689     int value =0;
00690     for (int i = 0; i < size; i++) {
00691         string label = ASCString::toString(value);
00692         label += " - ";
00693         label += ASCString::toString(value + slotSize);
00694         labels.push_back(label);
00695         value+= slotSize;
00696     }
00697     buildUpForm(labels);
00698 }
00699 
00700 
00701 WindSpeedSettingsDialog::~WindSpeedSettingsDialog() {}
00702 
00703 void WindSpeedSettingsDialog::setChanceValues(const vector<PG_LineEdit*>& p) {
00704     try {
00705         Percentages c;
00706         for(int i = 0; i < chances.size(); i++) {
00707             c.push_back(atoi(chances[i]->GetText()));
00708         }
00709         actmap->weatherSystem->setLikelihoodWindSpeed(c);
00710     } catch(IllegalValueException& e) {
00711         cout << e.getMessage() << endl; //If available rewrite to use of MsgBox
00712     }
00713 }
00714 
00715 int WindSpeedSettingsDialog::getNthChanceValue(int n) {
00716     return actmap->weatherSystem->getWindSpeedPercentage(n);
00717 }
00718 
00719 bool WindSpeedSettingsDialog::buttonEvent( PG_Button* button ) {
00720     setChanceValues(chances);
00721     quitModalLoop(2);
00722     return true;
00723 }
00724 
00725 
00726 //*********************************************************************************************************++
00727 WindDirectionSettingsDialog::WindDirectionSettingsDialog():ChanceSettingsDialog("Fallout Chances") {
00728     vector<string> labels;
00729     labels.push_back("North");
00730     labels.push_back("NorthEast");
00731     labels.push_back("East");
00732     labels.push_back("SouthEast");
00733     labels.push_back("South");
00734     labels.push_back("SouthWest");
00735     labels.push_back("West");
00736     labels.push_back("NorthWest");
00737 
00738     buildUpForm(labels);
00739 
00740 }
00741 
00742 WindDirectionSettingsDialog::~WindDirectionSettingsDialog() {}
00743 
00744 void WindDirectionSettingsDialog::setChanceValues(const vector<PG_LineEdit*>& p) {
00745     try {
00746         Percentages c;
00747         for(int i = 0; i < chances.size(); i++) {
00748             c.push_back(atoi(chances[i]->GetText()));
00749         }
00750         actmap->weatherSystem->setLikelihoodWindDirection(c);
00751     } catch(IllegalValueException& e) {
00752         cout << e.getMessage() << endl;
00753     }
00754 }
00755 
00756 int WindDirectionSettingsDialog::getNthChanceValue(int n) {
00757     return actmap->weatherSystem->getWindDirPercentage(n);
00758 }
00759 
00760 bool WindDirectionSettingsDialog::buttonEvent( PG_Button* button ) {
00761     setChanceValues(chances);
00762     quitModalLoop(2);
00763     return true;
00764 }
00765 
00766 
00767 

Generated on Tue Jun 24 01:27:56 2008 for Advanced Strategic Command by  doxygen 1.4.2