Advanced Strategic Command
resourceplacementdialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  paradialog.cpp - description
3  -------------------
4  begin : Thu Feb 21 2002
5  copyright : (C) 2002 by Martin Bickel
6  email : bickel@asc-hq.org
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 
19 
20 #include <iostream>
21 #include "resourceplacement.h"
22 // #include "notificationdialog.h"
24 #include "spfst.h"
25 #include "spfst-legacy.h"
26 
27 
28 const int ResourcePlacementDialog::xsize = 400;
29 const int ResourcePlacementDialog::ysize = 612;
30 const int ResourcePlacementDialog::xOffSet = xsize/10;
31 const int ResourcePlacementDialog::yOffSet = ysize/20;
32 const int ResourcePlacementDialog::leftIndent = xsize/50;;
33 
34 
36  ASC_PG_Dialog(NULL, PG_Rect( 100,100, xsize, ysize ), "Place Resources", SHOW_CLOSE ),
37  fuelRoughness(1), materialRoughness(1), maxFuelOffSet(100), maxMaterialOffSet(100),
38  fuelRoughnessWidget(NULL), materialRoughnessWidget(NULL), fuelOffsetWidget(NULL), materialOffsetWidget(NULL), d(0)
39 {
40  int xFuelWidgetPos = leftIndent;
41  int yFuelWidgetPos = ysize/10;
42  int hFuelWidget = GetTextHeight() + 10;
43  placeFuelWidget = new PG_CheckButton(this, PG_Rect(xFuelWidgetPos, yFuelWidgetPos, xsize/3 , GetTextHeight()*2), "Fuel");
44  placeFuelWidget->SetSizeByText();
45 
46 
47 
48  int xMaterialWidgetPos = xFuelWidgetPos;
49  int yMaterialWidgetPos = yFuelWidgetPos + hFuelWidget;
50  placeMaterialWidget = new PG_CheckButton(this, PG_Rect(xMaterialWidgetPos, yMaterialWidgetPos, xsize/3, GetTextHeight()*2), "Material");
51  placeMaterialWidget->SetSizeByText();
52 
53  int xFuelRoughnessLabelPos = 0;
54  if(placeFuelWidget->Width() > placeMaterialWidget->Width()) {
55  xFuelRoughnessLabelPos = xFuelWidgetPos + placeFuelWidget->Width() + xOffSet;
56  } else {
57  xFuelRoughnessLabelPos = xFuelWidgetPos + placeMaterialWidget->Width() + xOffSet;
58  }
59  fuelRoughnessLabel = new PG_Label(this, PG_Rect(xFuelRoughnessLabelPos, yFuelWidgetPos , 40, hFuelWidget), "Fuel Roughness: ");
60  fuelRoughnessLabel->SetSizeByText();
61 
62  materialRoughnessLabel = new PG_Label(this, PG_Rect(xFuelRoughnessLabelPos, yMaterialWidgetPos , 40, hFuelWidget), "Material Roughness: ");
63  materialRoughnessLabel->SetSizeByText();
64 
65  int xFuelRoughnessWidgetPos = 0;
66  if(fuelRoughnessLabel->Width() > materialRoughnessLabel->Width()) {
67  xFuelRoughnessWidgetPos = xFuelRoughnessLabelPos + fuelRoughnessLabel->Width();
68  } else {
69  xFuelRoughnessWidgetPos = xFuelRoughnessLabelPos + materialRoughnessLabel->Width();
70  }
71  fuelRoughnessWidget = new PG_LineEdit ( this, PG_Rect(xFuelRoughnessWidgetPos, yFuelWidgetPos, xsize - ( xFuelRoughnessLabelPos + fuelRoughnessLabel->Width() + xOffSet), hFuelWidget));
72  fuelRoughnessWidget->SetValidKeys("1234567890.");
73  fuelRoughnessWidget->SetText("1.0");
74 
75 
76 
77  materialRoughnessWidget = new PG_LineEdit ( this, PG_Rect(xFuelRoughnessWidgetPos, yMaterialWidgetPos, xsize - ( xFuelRoughnessLabelPos + fuelRoughnessLabel->Width() + xOffSet), hFuelWidget));
78  materialRoughnessWidget->SetValidKeys("1234567890.");
79  materialRoughnessWidget->SetText("1.0");
80 
81 
82 
83  int yFuelOffSetLabelPos = yMaterialWidgetPos + hFuelWidget + yOffSet;
84  fuelOffSetLabel = new PG_Label(this, PG_Rect(xFuelWidgetPos, yFuelOffSetLabelPos, 40, hFuelWidget), "Fuel Offset: ");
85  fuelOffSetLabel->SetSizeByText();
86 
87  int xFuelOffSetValue = xFuelWidgetPos + fuelOffSetLabel->Width();
88  fuelOffSetValue = new PG_LineEdit(this, PG_Rect(xFuelOffSetValue, yFuelOffSetLabelPos, 40, hFuelWidget));
90  fuelOffSetValue->SetValidKeys("1234567890");
91  fuelOffSetValue->SetEditable(false);
92 
93  int yFuelOffSetSliderPos = int(yFuelOffSetLabelPos + hFuelWidget * 1.5);
94  fuelOffSetSlider = new PG_Slider(this, PG_Rect(xFuelWidgetPos, yFuelOffSetSliderPos, xsize - (xFuelWidgetPos + leftIndent) , hFuelWidget), PG_ScrollBar::HORIZONTAL);
96  fuelOffSetSlider->SetPosition(atoi(fuelOffSetValue->GetText()));
97  fuelOffSetSlider->sigSlide.connect(sigc::mem_fun(*this, &ResourcePlacementDialog::scrollTrackEventFuel));
98 
99 
100  //MaterialOffSet
101  int yMaterialOffSetLabelPos = yFuelOffSetSliderPos + hFuelWidget;
102  materialOffSetLabel = new PG_Label(this, PG_Rect(xFuelWidgetPos, yMaterialOffSetLabelPos, 40, hFuelWidget), "Material Offset: ");
103  materialOffSetLabel->SetSizeByText();
104 
105  int xMaterialOffSetValue = xFuelWidgetPos + materialOffSetLabel->Width();
106  materialOffSetValue = new PG_LineEdit(this, PG_Rect(xMaterialOffSetValue, yMaterialOffSetLabelPos, 40, hFuelWidget));
108  materialOffSetValue->SetValidKeys("1234567890");
109  materialOffSetValue->SetEditable(false);
110 
111  int yMaterialOffSetSliderPos = int(yMaterialOffSetLabelPos + hFuelWidget * 1.5);
112  materialOffSetSlider = new PG_Slider(this, PG_Rect(xFuelWidgetPos, yMaterialOffSetSliderPos, xsize - (xFuelWidgetPos + leftIndent) , hFuelWidget), PG_ScrollBar::HORIZONTAL);
114  materialOffSetSlider->SetPosition(atoi(materialOffSetValue->GetText()));
115  materialOffSetSlider->sigSlide.connect(sigc::mem_fun(*this, &ResourcePlacementDialog::scrollTrackEventMaterial));
116 
117  //FuelFreeRatio
118  int yFuelFreeRatioLabelPos = yMaterialOffSetSliderPos + hFuelWidget + yOffSet;
119  fuelFreeRatioLabel = new PG_Label(this, PG_Rect(xFuelWidgetPos, yFuelFreeRatioLabelPos, 40, hFuelWidget), "Fuel Free Fields Ratio: ");
120  fuelFreeRatioLabel->SetSizeByText();
121 
122  int xFuelFreeRatioValue = xFuelWidgetPos + fuelFreeRatioLabel->Width();
123  fuelFreeRatioValue = new PG_LineEdit(this, PG_Rect(xFuelFreeRatioValue, yFuelFreeRatioLabelPos, 40, hFuelWidget));
125  fuelFreeRatioValue->SetValidKeys("1234567890");
126  fuelFreeRatioValue->SetEditable(false);
127 
128  int yFuelFreeRatioSliderPos = int(yFuelFreeRatioLabelPos + hFuelWidget * 1.5);
129  fuelFreeRatioSlider = new PG_Slider(this, PG_Rect(xFuelWidgetPos, yFuelFreeRatioSliderPos, xsize - (xFuelWidgetPos + leftIndent) , hFuelWidget), PG_ScrollBar::HORIZONTAL);
130  fuelFreeRatioSlider->SetRange(0, 100);
131  fuelFreeRatioSlider->SetPosition(atoi(fuelFreeRatioValue->GetText()));
132  fuelFreeRatioSlider->sigSlide.connect(sigc::mem_fun(*this, &ResourcePlacementDialog::scrollTrackEventFuelFreeRatio));
133 
134  //MaterialFreeRatio
135  int yMaterialFreeRatioLabelPos = yFuelFreeRatioSliderPos + hFuelWidget ;
136  materialFreeRatioLabel = new PG_Label(this, PG_Rect(xFuelWidgetPos, yMaterialFreeRatioLabelPos, 40, hFuelWidget), "Material Free Fields Ratio: ");
137  materialFreeRatioLabel->SetSizeByText();
138 
139  int xMaterialFreeRatioValue = xFuelWidgetPos + materialFreeRatioLabel->Width();
140  materialFreeRatioValue = new PG_LineEdit(this, PG_Rect(xMaterialFreeRatioValue, yMaterialFreeRatioLabelPos, 40, hFuelWidget));
142  materialFreeRatioValue->SetValidKeys("1234567890");
143  materialFreeRatioValue->SetEditable(false);
144 
145  int yMaterialFreeRatioSliderPos = int(yMaterialFreeRatioLabelPos + hFuelWidget * 1.5);
146  materialFreeRatioSlider = new PG_Slider(this, PG_Rect(xFuelWidgetPos, yMaterialFreeRatioSliderPos, xsize - (xFuelWidgetPos + leftIndent) , hFuelWidget), PG_ScrollBar::HORIZONTAL);
147  materialFreeRatioSlider->SetRange(0, 100);
148  materialFreeRatioSlider->SetPosition(atoi(materialFreeRatioValue->GetText()));
150 
151  //Buttons OK and Cancel
152 
153  (new PG_Button(this, PG_Rect(30, Height()-40, (Width()-70)/2, 30), "OK", 100))->sigClick.connect( sigc::mem_fun( *this, &ResourcePlacementDialog::buttonEvent ));
154  (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, &ResourcePlacementDialog::closeWindow )));
155 
156  sigClose.connect( sigc::mem_fun( *this, &ResourcePlacementDialog::closeWindow ));
157 }
158 
159 
160 
161 bool ResourcePlacementDialog::buttonEvent( PG_Button* button ) {
162  if((atof(fuelRoughnessWidget->GetText())<=0) || (atof(fuelRoughnessWidget->GetText())>=4) ||
163  (atof(materialRoughnessWidget->GetText())<=0) || (atof(materialRoughnessWidget->GetText())>=4)) {
164  d = new PG_MessageBox(this, PG_Rect(0,0, Width()/2, int(Height()* 0.75)), "Error Report", "Condition 0.0 < roughness < 4.0 not met", PG_Rect(Width()/4 - 25, int(Height()*0.75) - 30, 50, 30), "OK");
165  d->Show();
166 
167  return true;
168  } else {
169  quitModalLoop(1);
170  ResourcePlacement rp (*actmap , atof(fuelRoughnessWidget->GetText()), atof(materialRoughnessWidget->GetText()), atoi(fuelOffSetValue->GetText()), atoi(materialOffSetValue->GetText()), 0, atoi(materialFreeRatioValue->GetText()));
171 
172  if((placeFuelWidget->GetPressed()) && (placeMaterialWidget->GetPressed())) {
173  rp.placeResources();
174  } else if(placeFuelWidget->GetPressed()) {
175  rp.placeFuelResources();
176  } else if(placeMaterialWidget->GetPressed()) {
178  }
179  return true;
180  }
181 }
182 
183 
184 
186  materialOffSetValue->SetText( ASCString::toString( (int) data));
187  return true;
188 }
189 
191  fuelOffSetValue->SetText( ASCString::toString( (int) data ));
192  return true;
193 }
194 
195 
197  materialFreeRatioValue->SetText( ASCString::toString((int)data));
198  return true;
199 }
200 
201 
203  fuelFreeRatioValue->SetText(ASCString::toString((int)data));
204  return true;
205 }
206 
208  quitModalLoop(1);
209  return true;
210 }
211 
214  rpd.Show();
215  rpd.RunModal();
216 }
217 
218 
219 
220 
void placeResources()
Fills the map with all resources.
static const int MAXFUELVALUE
bool scrollTrackEventFuelFreeRatio(long data)
map accessing and usage routines used by ASC and the mapeditor
double atof(const std::string &s)
Definition: misc.cpp:157
static const int MAXMATERIALVALUE
bool buttonErrorOkEvent(PG_Button *button)
static const int MINMATERIALVALUE
PG_CheckButton * placeMaterialWidget
void placeFuelResources()
Fills the map only with fuel resources.
static ASCString toString(int i)
converts the parameter to a String
Definition: ascstring.cpp:193
void resourcePlacementDialog()
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 placeMaterialResources()
Fills the map only with material resources.
bool scrollTrackEventMaterialFreeRatio(long data)
int atoi(const std::string &s)
Definition: misc.cpp:152
static const int MINFUELVALUE
Fills a map with resources using the diamond-square algorithm.
GameMap * actmap
Definition: spfst.cpp:64
bool buttonEvent(PG_Button *button)