Advanced Strategic Command
unitguidedialog.cpp
Go to the documentation of this file.
1 #include <sigc++/sigc++.h>
2 #include <sstream>
3 
4 #include "unitguidedialog.h"
5 
6 #include "../typen.h"
7 #include "../terraintype.h"
8 #include "../vehicletype.h"
9 #include "../spfst.h"
10 #include "../spfst-legacy.h"
11 #include "../gameoptions.h"
12 #include "../iconrepository.h"
13 #include "../unitset.h"
14 #include <iostream>
15 #include <boost/algorithm/string/trim.hpp>
16 
25 class DataTab : public PG_Widget
26 {
27  public:
29 
30  DataTab( PG_Widget* parent, const PG_Rect& pos, bool showDescription );
31  ~DataTab();
32  void setPage( Page page );
33  void setUnit( VehicleType* type );
34  void setTab0( DataTab* tab0 );
35  void setCompare( bool compare );
36  void setData();
37  void HideAllLocal();
38 
39 
40  private:
41  Page currentPage;
42  VehicleType* currentUnit;
43 
44  PG_Rect parentPos;
45  DataTab* tabCompare;
46  bool compareData;
47  bool showDescriptionOnly;
48 
49  //std::vector< PG_Widget* > children;
50  PG_Widget *movementTab, *weapons1Tab, *weapons2Tab, *productionTab, *transportTab, *generalTab, *terrainAccessTab1, *terrainAccessTab2;
51  PG_Label *nameGeneral, *iconGeneral;//, *categoryIcon;
52  PG_Label *id, *category, *armor, *view, *jamming, *maxWind, *tankEnery, *tankMat, *tankFuel, *fuelConsuption, *maxSpeed, *weight, *autoRepairRate, *productionCostEnergy, *productionCostMaterial, *productionCostFuel;
53 
54  PG_Label **movementIcons, *jumpRange, *jumpCost;
55  PG_Label **weaponNames, **weaponPunch, **weaponRange, **weaponRechargeCost;
56  PG_Label **terrainAccessLabel;
57 };
58 
59 DataTab::DataTab( PG_Widget* parent, const PG_Rect& pos, bool showDescription ) : PG_Widget( parent, pos )
60 {
61  currentPage = general;
62  currentUnit = NULL;
63  parentPos = pos;
64  compareData = false;
65  tabCompare = NULL;
66  showDescriptionOnly = showDescription;
67 
68  int xPos = 10;
69  int yPos = 10;
70  int width = parentPos.Width() - 20;
71  int height = parentPos.Height() - 20;
72  int lineHeight = 12;
73  int labelHeight = 12;
74  //int heightLevelWidth = 20;
75  int fontSize = 10;
76 
77  iconGeneral = new PG_Label( this, PG_Rect( xPos, yPos, 48, 48 ) );
78  yPos += 55;
79  nameGeneral = new PG_Label( this, PG_Rect( xPos, yPos, width, labelHeight ) );
80  yPos += lineHeight;
81 
82  movementTab = new PG_Widget( this, PG_Rect( xPos, yPos, width, height ) );
83  weapons1Tab = new PG_Widget( this, PG_Rect( xPos, yPos, width, height ) );
84  weapons2Tab = new PG_Widget( this, PG_Rect( xPos, yPos, width, height ) );
85  productionTab = new PG_Widget( this, PG_Rect( xPos, yPos, width, height ) );
86  transportTab = new PG_Widget( this, PG_Rect( xPos, yPos, width, height ) );
87  generalTab = new PG_Widget( this, PG_Rect( xPos, yPos, width, height ) );
88  terrainAccessTab1 = new PG_Widget( this, PG_Rect( xPos, yPos, width, height ) );
89  terrainAccessTab2 = new PG_Widget( this, PG_Rect( xPos, yPos, width, height ) );
90 
91  HideAllLocal();
92  generalTab->Show();
93 
94 
95  xPos = 0;
96  yPos = 0;
97 
98  id = new PG_Label( generalTab, PG_Rect( xPos, yPos, width, labelHeight ) );
99  yPos += lineHeight;
100  //categoryIcon = new PG_Label( generalTab, PG_Rect( xPos, yPos, 20, 20 ) );
101  category = new PG_Label ( generalTab, PG_Rect( xPos/* + 30*/, yPos, width - 30, labelHeight ) );
102  yPos += lineHeight;
103  armor = new PG_Label( generalTab, PG_Rect( xPos, yPos, width, labelHeight ) );
104  yPos += lineHeight;
105  view = new PG_Label( generalTab, PG_Rect( xPos, yPos, width, labelHeight ) );
106  yPos += lineHeight;
107  jamming = new PG_Label( generalTab, PG_Rect( xPos, yPos, width, labelHeight ) );
108  yPos += lineHeight;
109  maxWind = new PG_Label( generalTab, PG_Rect( xPos, yPos, width, labelHeight ) );
110  yPos += lineHeight;
111  tankEnery = new PG_Label( generalTab, PG_Rect( xPos, yPos, width, labelHeight ) );
112  yPos += lineHeight;
113  tankMat = new PG_Label( generalTab, PG_Rect( xPos, yPos, width, labelHeight ) );
114  yPos += lineHeight;
115  tankFuel = new PG_Label( generalTab, PG_Rect( xPos, yPos, width, labelHeight ) );
116  yPos += lineHeight;
117  fuelConsuption = new PG_Label( generalTab, PG_Rect( xPos, yPos, width, labelHeight ) );
118  yPos += lineHeight;
119  maxSpeed = new PG_Label( generalTab, PG_Rect( xPos, yPos, width, labelHeight ) );
120  yPos += lineHeight;
121  weight = new PG_Label( generalTab, PG_Rect( xPos, yPos, width, labelHeight ) );
122  yPos += lineHeight;
123  autoRepairRate = new PG_Label( generalTab, PG_Rect( xPos, yPos, width, labelHeight ) );
124  yPos += lineHeight;
125  productionCostEnergy = new PG_Label( generalTab, PG_Rect( xPos, yPos, width, labelHeight ) );
126  yPos += lineHeight;
127  productionCostMaterial = new PG_Label( generalTab, PG_Rect( xPos, yPos, width, labelHeight ) );
128  yPos += lineHeight;
129  productionCostFuel = new PG_Label( generalTab, PG_Rect( xPos, yPos, width, labelHeight ) );
130  yPos += lineHeight;
131 
132  xPos = 0;
133  yPos = 0;
134 
135  movementIcons = new PG_Label*[ choehenstufennum ];
136 
137  for( int i=0; i<choehenstufennum; i++ )
138  {
139  movementIcons[ i ] = new PG_Label( movementTab, PG_Rect( xPos, yPos, width, labelHeight ) );
140  yPos += lineHeight;
141  }
142  jumpRange = new PG_Label( movementTab, PG_Rect( xPos, yPos, width, labelHeight ) );
143  yPos += lineHeight;
144  jumpCost = new PG_Label( movementTab, PG_Rect( xPos, yPos, width, labelHeight ) );
145  yPos += lineHeight;
146 
147  xPos = 0;
148  yPos = 0;
149 
150  weaponNames = new PG_Label*[ 16 ];
151  weaponPunch = new PG_Label*[ 16 ];
152  weaponRange = new PG_Label*[ 16 ];
153  weaponRechargeCost = new PG_Label*[ 16 ];
154  for( int i=0; i<8; i++ )
155  {
156  weaponNames[ i ] = new PG_Label( weapons1Tab, PG_Rect( xPos, yPos, width, labelHeight ) );
157  yPos += lineHeight;
158  weaponPunch[ i ] = new PG_Label( weapons1Tab, PG_Rect( xPos, yPos, width, labelHeight ) );
159  yPos += lineHeight;
160  weaponRange[ i ] = new PG_Label( weapons1Tab, PG_Rect( xPos, yPos, width, labelHeight ) );
161  yPos += lineHeight;
162  weaponRechargeCost[ i ] = new PG_Label( weapons1Tab, PG_Rect( xPos, yPos, width, labelHeight ) );
163  yPos += lineHeight;
164  }
165 
166  xPos = 0;
167  yPos = 0;
168 
169  for( int i=8; i<16; i++ )
170  {
171  weaponNames[ i ] = new PG_Label( weapons2Tab, PG_Rect( xPos, yPos, width, labelHeight ) );
172  yPos += lineHeight;
173  weaponPunch[ i ] = new PG_Label( weapons2Tab, PG_Rect( xPos, yPos, width, labelHeight ) );
174  yPos += lineHeight;
175  weaponRange[ i ] = new PG_Label( weapons2Tab, PG_Rect( xPos, yPos, width, labelHeight ) );
176  yPos += lineHeight;
177  weaponRechargeCost[ i ] = new PG_Label( weapons2Tab, PG_Rect( xPos, yPos, width, labelHeight ) );
178  yPos += lineHeight;
179  }
180 
181  xPos = 0;
182  yPos = 0;
183 
184  terrainAccessLabel = new PG_Label*[ terrainPropertyNum ];
185  for( int i=0; i<30; i++ )
186  {
187  terrainAccessLabel[ i ] = new PG_Label( terrainAccessTab1, PG_Rect( xPos, yPos, width, labelHeight ) );
188  yPos += lineHeight;
189  }
190 
191  xPos = 0;
192  yPos = 0;
193 
194  for( int i=30; i<terrainPropertyNum; i++ )
195  {
196  terrainAccessLabel[ i ] = new PG_Label( terrainAccessTab2, PG_Rect( xPos, yPos, width, labelHeight ) );
197  yPos += lineHeight;
198  }
199 
200  xPos = 0;
201  yPos = 0;
202 
203  SetFontSize( fontSize, true );
204 }
205 
207 {
208  delete movementIcons;
209 }
210 
212 {
213  tabCompare = tab0;
214 }
215 
216 void DataTab::setCompare( bool compare )
217 {
218  compareData = compare;
219  setData();
220 }
221 
223 {
224  movementTab->Hide();
225  weapons1Tab->Hide();
226  weapons2Tab->Hide();
227  productionTab->Hide();
228  transportTab->Hide();
229  terrainAccessTab1->Hide();
230  terrainAccessTab2->Hide();
231  generalTab->Hide();
232 }
233 
234 void DataTab::setPage( Page page )
235 {
236  currentPage = page;
237  HideAllLocal();
238  switch( page )
239  {
240  case movement:
241  movementTab->Show();
242  break;
243  case weapons1:
244  weapons1Tab->Show();
245  break;
246  case weapons2:
247  weapons2Tab->Show();
248  break;
249  case production:
250  productionTab->Show();
251  break;
252  case transport:
253  transportTab->Show();
254  break;
255  case terrainAccess1:
256  terrainAccessTab1->Show();
257  break;
258  case terrainAccess2:
259  terrainAccessTab2->Show();
260  break;
261  default:
262  generalTab->Show();
263  break;
264  }
265 }
266 
268 {
269  currentUnit = type;
270  setData();
271 }
272 
274 {
275 
276 
277  if( currentUnit == NULL && ! showDescriptionOnly )
278  return;
279 
280  VehicleType* compareType = NULL;
281  if( compareData && tabCompare != NULL )
282  {
283  compareType = tabCompare->currentUnit;
284  }
285 
286  char buffer[ 500 ];
287  std::string value = "";
288 
289  if( showDescriptionOnly )
290  {
291  iconGeneral->SetText( "Icon" );
292  nameGeneral->SetText( "Name" );
293  id->SetText( "ID" );
294  category->SetText( "Category" );
295  armor->SetText( "Armor" );
296  view->SetText( "View" );
297  jamming->SetText( "Jamming" );
298  maxWind->SetText( "Max Wind Resistance" );
299  tankEnery->SetText( "Tank Energy ASC|BI" );
300  tankMat->SetText( "Tank Material ASC|BI" );
301  tankFuel->SetText( "Tank Fuel ASC|BI" );
302  fuelConsuption->SetText( "Fuel Consumption" );
303  maxSpeed->SetText( "Max Speed" );
304  weight->SetText( "Weight" );
305  autoRepairRate->SetText( "Auto Repair Rate" );
306  productionCostEnergy->SetText( "Production Cost Energy" );
307  productionCostMaterial->SetText( "Production Cost Material" );
308  productionCostFuel->SetText( "Production Cost Fuel" );
309 
310  for( int i=0; i<choehenstufennum; i++ )
311  {
312  std::string iconName = "height-a";
313  char buffer[ 5 ];
314  itoa( i, buffer, 10 );
315  iconName += buffer;
316  iconName += ".png";
317  movementIcons[ i ]->SetIcon( IconRepository::getIcon( iconName ).getBaseSurface() );
318  }
319 
320  for( int i=0; i<16; i++ )
321  {
322  value = "Weapon ";
323  itoa( i, buffer, 10 );
324  value += buffer;
325  value += " Name";
326  weaponNames[ i ]->SetText( value );
327  weaponPunch[ i ]->SetText( "Punch" );
328  weaponRange[ i ]->SetText( "Range" );
329  weaponRechargeCost[ i ]->SetText( "Laser Recharge" );
330  }
331 
332  for( int i=0; i<terrainPropertyNum; i++ )
333  {
334  terrainAccessLabel[ i ]->SetText( terrainProperty[ i ] );
335  }
336 
337  jumpRange->SetText( "Jump Range" );
338  jumpCost->SetText( "Jump Cost" );
339 
340  }else
341  {
342  iconGeneral->SetIcon( currentUnit->getImage().getBaseSurface() );
343  nameGeneral->SetText( currentUnit->getName() );
344  itoa( currentUnit->getID(), buffer, 10 );
345  id->SetText( buffer );
346  //categoryIcon->SetIcon( IconRepository::getIcon( moveMaliTypeIcons[ currentUnit->movemalustyp ] ).getBaseSurface() );
347  category->SetText( cmovemalitypes[ currentUnit->movemalustyp ] );
348 
349  {
350  int armor = currentUnit->armor;
351  if( compareType != NULL )
352  {
353  armor = armor - compareType->armor;
354  }
355  itoa( armor, buffer, 10 );
356  this->armor->SetText( buffer );
357  }
358 
359  {
360  int view = currentUnit->view;
361  if( compareType != NULL )
362  {
363  view = view - compareType->view;
364  }
365  itoa( view, buffer, 10 );
366  this->view->SetText( buffer );
367  }
368 
369  {
370  int jamming = currentUnit->jamming;
371  if( compareType != NULL )
372  {
373  jamming = jamming - compareType->jamming;
374  }
375  itoa( jamming, buffer, 10 );
376  this->jamming->SetText( buffer );
377  }
378 
379  {
380  int maxwindspeedonwater = currentUnit->maxwindspeedonwater;
381  if( compareType != NULL )
382  {
383  maxwindspeedonwater = maxwindspeedonwater - compareType->maxwindspeedonwater;
384  }
385  itoa( maxwindspeedonwater, buffer, 10 );
386  this->maxWind->SetText( buffer );
387  }
388 
389  {
390  Resources biTank = currentUnit->getStorageCapacity( 1 );
391  Resources ascTank = currentUnit->getStorageCapacity( 0 );
392  value = "";
393 
394  int tank = ascTank.resource( 0 );
395  if( compareType != NULL )
396  {
397  tank = tank - compareType->getStorageCapacity( 0 ).resource( 0 );
398  }
399  itoa( tank, buffer, 10 );
400 
401  value += buffer;
402  value += " | ";
403 
404  tank = biTank.resource( 0 );
405  if( compareType != NULL )
406  {
407  tank = tank - compareType->getStorageCapacity( 1 ).resource( 0 );
408  }
409  itoa( tank, buffer, 10 );
410 
411  value += buffer;
412  this->tankEnery->SetText( value );
413 
414  value = "";
415  tank = ascTank.resource( 1 );
416  if( compareType != NULL )
417  {
418  tank = tank - compareType->getStorageCapacity( 0 ).resource( 1 );
419  }
420  itoa( tank, buffer, 10 );
421 
422  value += buffer;
423  value += " | ";
424 
425  tank = biTank.resource( 1 );
426  if( compareType != NULL )
427  {
428  tank = tank - compareType->getStorageCapacity( 1 ).resource( 1 );
429  }
430  itoa( tank, buffer, 10 );
431 
432  value += buffer;
433  this->tankMat->SetText( value );
434 
435 
436  value = "";
437  tank = ascTank.resource( 2 );
438  if( compareType != NULL )
439  {
440  tank = tank - compareType->getStorageCapacity( 0 ).resource( 2 );
441  }
442  itoa( tank, buffer, 10 );
443 
444  value += buffer;
445  value += " | ";
446 
447  tank = biTank.resource( 2 );
448  if( compareType != NULL )
449  {
450  tank = tank - compareType->getStorageCapacity( 1 ).resource( 2 );
451  }
452  itoa( tank, buffer, 10 );
453 
454  value += buffer;
455  this->tankFuel->SetText( value );
456  }
457 
458  {
459  int fuelConsumption = currentUnit->fuelConsumption;
460  if( compareType != NULL )
461  {
462  fuelConsumption = fuelConsumption - compareType->fuelConsumption;
463  }
464  itoa( fuelConsumption, buffer, 10 );
465  this->fuelConsuption->SetText( buffer );
466  }
467 
468  {
469  int movement = currentUnit->maxSpeed();
470  if( compareType != NULL )
471  {
472  movement = movement - compareType->maxSpeed();
473  }
474  itoa( movement, buffer, 10 );
475  this->maxSpeed->SetText( buffer );
476  }
477 
478  {
479  int weight = currentUnit->weight;
480  if( compareType != NULL )
481  {
482  weight = weight - compareType->weight;
483  }
484  itoa( weight, buffer, 10 );
485  this->weight->SetText( buffer );
486  }
487 
488  {
489  int autorepairrate = currentUnit->autorepairrate;
490  if( compareType != NULL )
491  {
492  autorepairrate = autorepairrate - compareType->autorepairrate;
493  }
494  itoa( autorepairrate, buffer, 10 );
495  this->autoRepairRate->SetText( buffer );
496  }
497 
498 
499  {
500  int tank = currentUnit->calcProductionCost().resource( 0 );
501  if( compareType != NULL )
502  {
503  tank = tank - compareType->calcProductionCost().resource( 0 );
504  }
505  itoa( tank, buffer, 10 );
506 
507  this->productionCostEnergy->SetText( buffer );
508  }
509 
510  {
511  int tank = currentUnit->calcProductionCost().resource( 1 );
512  if( compareType != NULL )
513  {
514  tank = tank - compareType->calcProductionCost().resource( 1 );
515  }
516  itoa( tank, buffer, 10 );
517 
518  this->productionCostMaterial->SetText( buffer );
519  }
520 
521  {
522  int tank = currentUnit->calcProductionCost().resource( 2 );
523  if( compareType != NULL )
524  {
525  tank = tank - compareType->calcProductionCost().resource( 2 );
526  }
527  itoa( tank, buffer, 10 );
528 
529  this->productionCostFuel->SetText( buffer );
530  }
531 
532  for( int i=0; i<choehenstufennum; i++ )
533  {
534  int movement = currentUnit->movement[ i ];
535  if( compareType != NULL )
536  {
537  movement = movement - compareType->movement[ i ];
538  }
539  itoa( movement, buffer, 10 );
540  value = buffer;
541  if( currentUnit->jumpDrive.height & (1<<i) )
542  value += " Jump";
543  movementIcons[ i ]->SetText( value );
544  }
545 
546  {
547  int maxDistance = currentUnit->jumpDrive.maxDistance;
548  if( compareType != NULL )
549  {
550  maxDistance = maxDistance - compareType->jumpDrive.maxDistance;
551  }
552  maxDistance /= 10;
553  itoa( maxDistance, buffer, 10 );
554  this->jumpRange->SetText( buffer );
555  }
556 
557  for( int i=0; i<16; i++ )
558  {
559  weaponNames[ i ]->SetText( "N/A" );
560  weaponPunch[ i ]->SetText( "0-0" );
561  weaponRange[ i ]->SetText( "0-0" );
562  weaponRechargeCost[ i ]->SetText( "0x 0|0|0" );
563  }
564 
565  for( int i=0; i<currentUnit->weapons.count; i++ )
566  {
567  weaponNames[ i ]->SetText( currentUnit->weapons.weapon[ i ].name );
568 
569  value = "";
570  int maxPunch = currentUnit->weapons.weapon[ i ].maxstrength;
571  if( compareType != NULL )
572  {
573  maxPunch = maxPunch - compareType->weapons.weapon[ i ].maxstrength;
574  }
575  itoa( maxPunch, buffer, 10 );
576  value = buffer;
577  value += "-";
578  int minPunch = currentUnit->weapons.weapon[ i ].minstrength;
579  if( compareType != NULL )
580  {
581  minPunch = minPunch - compareType->weapons.weapon[ i ].minstrength;
582  }
583  itoa( minPunch, buffer, 10 );
584  value += buffer;
585  weaponPunch[ i ]->SetText( value );
586 
587  value = "";
588  int minRange = currentUnit->weapons.weapon[ i ].mindistance;
589  if( compareType != NULL )
590  {
591  minRange = minRange - compareType->weapons.weapon[ i ].mindistance;
592  }
593  minRange /= 10;
594  itoa( minRange, buffer, 10 );
595  value = buffer;
596  value += "-";
597  int maxRange = currentUnit->weapons.weapon[ i ].maxdistance;
598  if( compareType != NULL )
599  {
600  maxRange = maxRange - compareType->weapons.weapon[ i ].maxdistance;
601  }
602  maxRange /= 10;
603  itoa( maxRange, buffer, 10 );
604  value += buffer;
605  weaponRange[ i ]->SetText( value );
606 
607  value = "";
608  int rechargeRate = currentUnit->weapons.weapon[ i ].laserRechargeRate;
609  if( compareType != NULL )
610  {
611  rechargeRate = rechargeRate - compareType->weapons.weapon[ i ].laserRechargeRate;
612  }
613  itoa( rechargeRate, buffer, 10 );
614  value = buffer;
615  value += "x ";
616  int costEnergy = currentUnit->weapons.weapon[ i ].laserRechargeCost.resource( 0 );
617  if( compareType != NULL )
618  {
619  costEnergy = costEnergy - compareType->weapons.weapon[ i ].laserRechargeCost.resource( 0 );
620  }
621  itoa( costEnergy, buffer, 10 );
622  value += buffer;
623  value += "|";
624  int costMaterial = currentUnit->weapons.weapon[ i ].laserRechargeCost.resource( 1 );
625  if( compareType != NULL )
626  {
627  costMaterial = costMaterial - compareType->weapons.weapon[ i ].laserRechargeCost.resource( 1 );
628  }
629  itoa( costMaterial, buffer, 10 );
630  value += buffer;
631  value += "|";
632  int costFuel = currentUnit->weapons.weapon[ i ].laserRechargeCost.resource( 2 );
633  if( compareType != NULL )
634  {
635  costFuel = costFuel - compareType->weapons.weapon[ i ].laserRechargeCost.resource( 2 );
636  }
637  itoa( costFuel, buffer, 10 );
638  value += buffer;
639  weaponRechargeCost[ i ]->SetText( value );
640  }
641 
642  for( int i=0; i<terrainPropertyNum; i++ )
643  {
644  if( currentUnit->terrainaccess.terrainkill[ i ] )
645  {
646  terrainAccessLabel[ i ]->SetText( "kill" );
647  }else if( currentUnit->terrainaccess.terrainnot[ i ] )
648  {
649  terrainAccessLabel[ i ]->SetText( "not accessible" );
650  }else if( currentUnit->terrainaccess.terrainreq[ i ] )
651  {
652  terrainAccessLabel[ i ]->SetText( "required" );
653  }else if( currentUnit->terrainaccess.terrain[ i ] )
654  {
655  terrainAccessLabel[ i ]->SetText( "yes" );
656  }else
657  {
658  terrainAccessLabel[ i ]->SetText( "" );
659  }
660 
661  // narf!
662  if( currentUnit->jumpDrive.height != 0 )
663  {
664  if( currentUnit->jumpDrive.targetterrain.terrainreq[ i ] )
665  {
666  value = terrainAccessLabel[ i ]->GetText();
667  value += " JumpReq";
668  terrainAccessLabel[ i ]->SetText( value );
669  }else if( currentUnit->jumpDrive.targetterrain.terrain[ i ] )
670  {
671  value = terrainAccessLabel[ i ]->GetText();
672  value += " Jump";
673  terrainAccessLabel[ i ]->SetText( value );
674  }
675  }
676  }
677 
678  {
679  value = "";
680  int cost = currentUnit->jumpDrive.consumption.resource( 0 );
681  if( compareType != NULL )
682  {
683  cost = cost - compareType->jumpDrive.consumption.resource( 0 );
684  }
685  itoa( cost, buffer, 10 );
686  value += buffer;
687  value += "|";
688 
689  cost = currentUnit->jumpDrive.consumption.resource( 1 );
690  if( compareType != NULL )
691  {
692  cost = cost - compareType->jumpDrive.consumption.resource( 1 );
693  }
694  itoa( cost, buffer, 10 );
695  value += buffer;
696  value += "|";
697 
698  cost = currentUnit->jumpDrive.consumption.resource( 2 );
699  if( compareType != NULL )
700  {
701  cost = cost - compareType->jumpDrive.consumption.resource( 2 );
702  }
703  itoa( cost, buffer, 10 );
704  value += buffer;
705 
706  jumpCost->SetText( value );
707  }
708  }
709 
710 
711 }
712 
713 
714 
715 class UnitGuideWidget : public PG_Widget
716 {
717  private:
718  DropDownSelector* mainCategory;
719  DropDownSelector* subCategory;
720 
721  DropDownSelector* unitSet;
722  DropDownSelector* displayTab;
723  DropDownSelector* unit;
724  DropDownSelector* page;
725 
726  PG_Button* display;
727  PG_CheckButton* showDifference;
728 
729  PG_Label* mainCategoryLabel;
730  PG_Label* subCategoryLabel;
731  PG_Label* unitSetLabel;
732  PG_Label* displayTabLabel;
733  PG_Label* unitLabel;
734  PG_Label* showDifferenceLabel;
735 
736  PG_ScrollArea* content;
737 
738  DataTab* descriptionTab;
739  //--------------------------
740  struct TSubCategory{
741  int category;
742  std::string name;
743  };
744  typedef std::vector< TSubCategory > TSubCategories;
745 
746  struct TMainCategory{
747  std::string name;
748  TSubCategories subCategories;
749  };
750  typedef std::vector< TMainCategory > TMainCategories;
751 
752  TMainCategories mainCategories;
753  //--------------------------
754 
755  void loadCategories();
756 
757  void selectUnits();
758 
759  // signal connectors
760  void mainCategoryChanged( int i );
761  void subCategoryChanged( int i );
762  void unitSetChanged( int i );
763  void pageChanged( int i );
764  bool displayUnit();
765  bool showDifferenceTrigger( bool pressed );
766  //---------------------------
767  typedef std::vector< VehicleType* > TVehicleTypes;
768  TVehicleTypes selectedUnits;
769 
770  typedef std::vector< DataTab* > TDataTabs;
771  TDataTabs dataTabs;
772 
773  public:
774  UnitGuideWidget( PG_Widget* parent, const PG_Rect& pos, int tabs );
775 };
776 
777 
778 
779 UnitGuideWidget::UnitGuideWidget( PG_Widget* parent, const PG_Rect& pos, int tabs ) : PG_Widget( parent, pos )
780 {
781  loadCategories();
782 
783  int xPos = 20;
784  int yPos = 20;
785 
786  mainCategoryLabel = new PG_Label ( this, PG_Rect( xPos, yPos, 100, 20 ), "Main Category" );
787  xPos += 120;
788 
789  mainCategory = new DropDownSelector( this, PG_Rect( xPos, yPos, 200, 20 ) );
790  for( int i=0; i<mainCategories.size(); i++ )
791  {
792  mainCategory->AddItem( mainCategories[ i ].name );
793  }
794  mainCategory->selectionSignal.connect( sigc::mem_fun( *this, &UnitGuideWidget::mainCategoryChanged ) );
795  xPos += 220;
796 
797  unitSetLabel = new PG_Label ( this, PG_Rect( xPos, yPos, 100, 20 ), "Unit Set" );
798  xPos += 120;
799 
800  unitSet = new DropDownSelector( this, PG_Rect( xPos, yPos, 200, 20 ) );
801  unitSet->AddItem( "All Sets" );
802  for( int i=0; i<unitSets.size(); i++ )
803  {
804  unitSet->AddItem( unitSets[ i ]->name );
805  }
806  unitSet->selectionSignal.connect( sigc::mem_fun( *this, &UnitGuideWidget::unitSetChanged ) );
807  xPos = 20;
808  yPos += 25;
809 
810 
811  subCategoryLabel = new PG_Label ( this, PG_Rect( xPos, yPos, 100, 20 ), "Sub Category" );
812  xPos += 120;
813 
814  subCategory = new DropDownSelector( this, PG_Rect( xPos, yPos, 200, 20 ) );
815  subCategory->selectionSignal.connect( sigc::mem_fun( *this, &UnitGuideWidget::subCategoryChanged ) );
816  xPos += 220;
817 
818  unitLabel = new PG_Label ( this, PG_Rect( xPos, yPos, 100, 20 ), "Unit" );
819  xPos += 120;
820 
821  unit = new DropDownSelector( this, PG_Rect( xPos, yPos, 200, 20 ) );
822  xPos = 20;
823  yPos += 25;
824 
825  displayTabLabel = new PG_Label ( this, PG_Rect( xPos, yPos, 100, 20 ), "Display on tab" );
826  xPos += 120;
827 
828  displayTab = new DropDownSelector( this, PG_Rect( xPos, yPos, 50, 20 ) );
829  for( int i=0; i<tabs; i++ )
830  {
831  std::stringstream nameStream;
832  nameStream << i;
833  displayTab->AddItem( nameStream.str() );
834  }
835  xPos += 70;
836 
837  showDifferenceLabel = new PG_Label ( this, PG_Rect( xPos, yPos, 100, 20 ), "show difference" );
838  xPos += 120;
839 
840  showDifference = new PG_CheckButton( this, PG_Rect( xPos, yPos, 20, 20 ) );
841  showDifference->sigClick.connect( sigc::mem_fun( *this, &UnitGuideWidget::showDifferenceTrigger ));
842  xPos += 40;
843 
844  display = new PG_Button( this, PG_Rect( xPos, yPos, 100, 20 ), "display" );
845  display->sigClick.connect( sigc::hide( sigc::mem_fun( *this, &UnitGuideWidget::displayUnit )));
846  xPos += 120;
847 
848  page = new DropDownSelector( this, PG_Rect( xPos, yPos, 200, 20 ) );
849  page->AddItem( "General" );
850  page->AddItem( "Weapons 1" );
851  page->AddItem( "Weapons 2" );
852  page->AddItem( "Movement" );
853  page->AddItem( "Transport" );
854  page->AddItem( "TerrainAccess 1" );
855  page->AddItem( "TerrainAccess 2" );
856  page->AddItem( "Production" );
857  page->selectionSignal.connect( sigc::mem_fun( *this, &UnitGuideWidget::pageChanged ) );
858 
859  xPos = 0;
860  yPos += 25;
861  /*
862  content = new PG_ScrollArea( this, PG_Rect( xPos, yPos, pos.Width(), pos.Height() - yPos - 10 ) );
863  content->ScrollTo( 0, 0 );
864  */
865  descriptionTab = new DataTab( this, PG_Rect( xPos, yPos, 200, pos.Height() - yPos - 10 ), true );
866  descriptionTab->setData();
867 
868  xPos += 200;
869  for( int i=0; i<tabs; i++ )
870  {
871  DataTab* dataTab = new DataTab( this, PG_Rect( xPos, yPos, 150, pos.Height() - yPos - 10 ), false );
872  dataTabs.push_back( dataTab );
873  xPos += 150;
874  }
875  for( int i=1; i<tabs; i++ )
876  {
877  dataTabs[ i ]->setTab0( dataTabs[ 0 ] );
878  }
879  mainCategory->SelectFirstItem();
880  unitSet->SelectFirstItem();
881 
882 }
883 
884 bool UnitGuideWidget::showDifferenceTrigger( bool pressed )
885 {
886  //Hide();
887  for( int i=1; i<dataTabs.size(); i++ )
888  {
889  dataTabs[ i ]->setCompare( pressed );
890  }
891  //Show();
892  return true;
893 }
894 
895 void UnitGuideWidget::pageChanged( int i )
896 {
897  //Hide();
898  switch( i )
899  {
900  case 0:
901  for( int tab=0; tab<dataTabs.size(); tab++ )
902  dataTabs[ tab ]->setPage( DataTab::general );
903  descriptionTab->setPage( DataTab::general );
904  break;
905  case 1:
906  for( int tab=0; tab<dataTabs.size(); tab++ )
907  dataTabs[ tab ]->setPage( DataTab::weapons1 );
908  descriptionTab->setPage( DataTab::weapons1 );
909  break;
910  case 2:
911  for( int tab=0; tab<dataTabs.size(); tab++ )
912  dataTabs[ tab ]->setPage( DataTab::weapons2 );
913  descriptionTab->setPage( DataTab::weapons2 );
914  break;
915  case 3:
916  for( int tab=0; tab<dataTabs.size(); tab++ )
917  dataTabs[ tab ]->setPage( DataTab::movement );
918  descriptionTab->setPage( DataTab::movement );
919  break;
920  case 4:
921  for( int tab=0; tab<dataTabs.size(); tab++ )
922  dataTabs[ tab ]->setPage( DataTab::transport );
923  descriptionTab->setPage( DataTab::transport );
924  break;
925  case 5:
926  for( int tab=0; tab<dataTabs.size(); tab++ )
927  dataTabs[ tab ]->setPage( DataTab::terrainAccess1 );
928  descriptionTab->setPage( DataTab::terrainAccess1 );
929  break;
930  case 6:
931  for( int tab=0; tab<dataTabs.size(); tab++ )
932  dataTabs[ tab ]->setPage( DataTab::terrainAccess2 );
933  descriptionTab->setPage( DataTab::terrainAccess2 );
934  break;
935  case 7:
936  for( int tab=0; tab<dataTabs.size(); tab++ )
937  dataTabs[ tab ]->setPage( DataTab::production );
938  descriptionTab->setPage( DataTab::production );
939  break;
940  default:
941  for( int tab=0; tab<dataTabs.size(); tab++ )
942  dataTabs[ tab ]->setPage( DataTab::general );
943  descriptionTab->setPage( DataTab::general );
944  break;
945  }
946  //Show();
947 }
948 
949 bool UnitGuideWidget::displayUnit()
950 {
951 // Hide();
952  dataTabs[ displayTab->GetSelectedItemIndex() ]->setUnit( selectedUnits[ unit->GetSelectedItemIndex() ] );
953 
954  if( showDifference->GetPressed() && displayTab->GetSelectedItemIndex() == 0 )
955  {
956  for( int i=1; i<dataTabs.size(); i++ )
957  dataTabs[ i ]->setData();
958  }
959 
960 // Show();
961  return true;
962 }
963 
964 void UnitGuideWidget::selectUnits()
965 {
966  selectedUnits.clear();
967  int allUnits = actmap->getVehicleTypeNum();
968  int filter = mainCategories[ mainCategory->GetSelectedItemIndex() ].subCategories[ subCategory->GetSelectedItemIndex() ].category;
969 
970  SingleUnitSet* selectedUnitSet = NULL;
971  if( unitSet->GetSelectedItemIndex() > 0 )
972  selectedUnitSet = unitSets[ unitSet->GetSelectedItemIndex() - 1 ];
973 
974 
975  for( int i=0; i<allUnits; i++ )
976  {
978 
979  if( selectedUnitSet != NULL )
980  {
981  if( ! selectedUnitSet->isMember( type->id, SingleUnitSet::unit ) )
982  continue;
983  }
984 
985  for( int j=0; j<type->guideSortHelp.size(); j++ )
986  {
987  if( type->guideSortHelp[ j ] == filter )
988  {
989  // yay!
990  selectedUnits.push_back( type );
991 
992  break;
993  }
994  }
995  }
996 
997  unit->DeleteAll();
998  for( int i=0; i<selectedUnits.size(); i++ )
999  {
1000  unit->AddItem( selectedUnits[ i ]->getName() );
1001  }
1002  unit->SelectFirstItem();
1003 }
1004 
1005 void UnitGuideWidget::mainCategoryChanged( int i )
1006 {
1007  subCategory->DeleteAll();
1008 
1009  TSubCategories subCategories = mainCategories[ i ].subCategories;
1010  for( int j=0; j<subCategories.size(); j++ )
1011  {
1012  subCategory->AddItem( subCategories[ j ].name );
1013  }
1014  subCategory->SelectFirstItem();
1015 }
1016 
1017 void UnitGuideWidget::subCategoryChanged( int i )
1018 {
1019  selectUnits();
1020 }
1021 
1022 void UnitGuideWidget::unitSetChanged( int i )
1023 {
1024  selectUnits();
1025 }
1026 
1027 
1028 void UnitGuideWidget::loadCategories()
1029 {
1030  ASCString lineBuffer;
1031  tnfilestream file( "guidesorthelp.properties", tnstream::reading );
1032 
1033  TMainCategory mainCategory;
1034  while( file.readTextString( lineBuffer ) )
1035  {
1036  std::string line = lineBuffer;
1037  boost::algorithm::trim( line );
1038 
1039  if( line.size() == 0 )
1040  continue;
1041 
1042  if( line[ 0 ] == '[' )
1043  {
1044  if( mainCategory.subCategories.size() > 0 )
1045  {
1046  mainCategories.push_back( mainCategory );
1047  }
1048  mainCategory.name = line.substr( 1, line.length() - 2 );
1049  mainCategory.subCategories.clear();
1050  }else
1051  {
1052  if( line.find( "=" ) > 0 )
1053  {
1054  std::string key = line.substr( 0, line.find( "=" ) );
1055  line = line.substr( line.find( "=" ) + 1 );
1056  boost::algorithm::trim( key );
1057  boost::algorithm::trim( line );
1058  TSubCategory subCat;
1059  subCat.name = line;
1060  subCat.category = atoi( key );
1061  mainCategory.subCategories.push_back( subCat );
1062  }
1063  }
1064 
1065  }
1066  if( mainCategory.subCategories.size() > 0 )
1067  {
1068  mainCategories.push_back( mainCategory );
1069  }
1070  /*
1071  TSubCategory subCategory;
1072  subCategory.name = "Heavy Trooper";
1073  subCategory.category = 203;
1074 
1075  TSubCategories infantry;
1076  infantry.push_back( subCategory );
1077 
1078  subCategory.name = "jumps";
1079  subCategory.category = 505;
1080  infantry.push_back( subCategory );
1081 
1082  TMainCategory mainCategory;
1083  mainCategory.name = "Infantry";
1084  mainCategory.subCategories = infantry;
1085 
1086  mainCategories.push_back( mainCategory );
1087 
1088  TSubCategories tanks;
1089  subCategory.name = "A-Sat Multi";
1090  subCategory.category = 232;
1091  tanks.push_back( subCategory );
1092 
1093  mainCategory.name = "Sats";
1094  mainCategory.subCategories = tanks;
1095 
1096  mainCategories.push_back( mainCategory );
1097  */
1098 }
1099 
1101 {
1102  private:
1103  UnitGuideWidget *w;
1104  public:
1105  UnitGuideWindow( PG_Widget* parent, const PG_Rect& pos, int tabs );
1106  ~UnitGuideWindow();
1107 };
1108 
1109 UnitGuideWindow::UnitGuideWindow( PG_Widget* parent, const PG_Rect& pos, int tabs ) : ASC_PG_Dialog( parent, pos, "UnitGuide" )
1110 {
1111  w = new UnitGuideWidget( this, PG_Rect( 0, 0, pos.Width(), pos.Height() ), tabs );
1112 }
1113 
1115 {
1116  delete w;
1117 }
1118 
1119 void unitGuideWindow( int tabs )
1120 {
1121  try {
1122  UnitGuideWindow w( NULL, PG_Rect( 50, 50, 760, 600 ), tabs );
1123  w.Show();
1124  w.RunModal();
1125  } catch ( tfileerror err ) {
1126  errorMessage("error loading file " + err.getFileName() );
1127  }
1128 }
struct VehicleType::JumpDrive jumpDrive
int getVehicleTypeNum()
Definition: gamemap.cpp:1856
vector< int > guideSortHelp
Definition: vehicletype.h:279
DataTab(PG_Widget *parent, const PG_Rect &pos, bool showDescription)
const ASCString & getFileName() const
Definition: simplestream.h:80
const int choehenstufennum
The number of levels of height.
Definition: typen.h:67
bool isMember(int id, Type type)
Definition: unitset.cpp:36
UnitWeapon weapons
The weapons.
Definition: vehicletype.h:248
const char * cmovemalitypes[cmovemalitypenum]
the names of the different MoveMalusTypes
Definition: typen.cpp:43
const Surface & getImage() const
Definition: vehicletype.h:325
void HideAllLocal()
Resources laserRechargeCost
the resources that recharging the laser for a single shot requires
Definition: vehicletype.h:143
SingleWeapon weapon[16]
Definition: vehicletype.h:170
ASCString getName() const
sigc::signal< void, int > selectionSignal
TerrainAccess targetterrain
Definition: vehicletype.h:314
SDL_Surface * getBaseSurface()
Definition: surface.h:116
void setTab0(DataTab *tab0)
UnitGuideWindow(PG_Widget *parent, const PG_Rect &pos, int tabs)
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
const int terrainPropertyNum
the number of bits that specify the terrain of a field
Definition: terraintype.h:28
vector< int > movement
the distance a unit can travel each round. One value for each of the 8 levels of height ...
Definition: vehicletype.h:203
int view
the visibility range
The class describing properties that are common to all vehicles of a certain kind.
Definition: vehicletype.h:177
int mindistance
the minimal distance the weapon can shoot
Definition: vehicletype.h:114
int minstrength
strength of the weapon when fired over the maximum distance
Definition: vehicletype.h:123
TerrainBits terrainreq
ALL these bits must be set in the terrain.
Definition: terraintype.h:50
Resources calcProductionCost()
void setData()
Adapter class for using Paragui Dialogs in ASC. This class transfers the event control from ASC to Pa...
Definition: paradialog.h:127
int movemalustyp
The category of the unit. Original used only to distinguish only between different movement costs for...
Definition: vehicletype.h:206
void setPage(Page page)
int jamming
the radar jamming power
int height
bitmapped: on these levels of height the jump drive can be activated
Definition: vehicletype.h:310
TerrainBits terrainnot
if one of these bits is set, the field will NOT be accessible
Definition: terraintype.h:53
int maxdistance
the maximum distance the weapon can shoot
Definition: vehicletype.h:111
VehicleType * getvehicletype_bypos(int pos)
Definition: gamemap.cpp:1831
UnitGuideWidget(PG_Widget *parent, const PG_Rect &pos, int tabs)
int autorepairrate
the damage this unit can repair itself automatically each turn.
Definition: vehicletype.h:251
void errorMessage(const ASCString &string)
todo: beschreibung und infotext in eigenem fenster heightchange production transport waffen detailinf...
int weight
the weight of the unit, without fuel or other cargo
Definition: vehicletype.h:218
TerrainBits terrainkill
if a terrain is not accessible AND one of these bits is matched, the unit will be destroyed ...
Definition: terraintype.h:56
Resources getStorageCapacity(int mode) const
returns the Storage capacity of the unit
char * itoa(int a, char *b, int c)
Definition: misc.cpp:179
int atoi(const std::string &s)
Definition: misc.cpp:152
TerrainBits terrain
at least one of these bits must match on of the terrain
Definition: terraintype.h:47
int fuelConsumption
the fuel consumption to move a single field
Definition: vehicletype.h:200
int & resource(int type)
Definition: typen.h:105
ASCString name
Definition: vehicletype.h:149
static Surface & getIcon(const ASCString &name)
int maxwindspeedonwater
the maximum speed of the wind that the unit can survive when on open water without sinking ...
Definition: vehicletype.h:209
void AddItem(const std::string &text, void *userdata=NULL, Uint16 height=0)
const char * terrainProperty[terrainPropertyNum+1]
Definition: terraintype.cpp:30
GameMap * actmap
Definition: spfst.cpp:64
UnitSets unitSets
Definition: unitset.cpp:211
int maxstrength
strength of the weapon when fired over the minimal distance
Definition: vehicletype.h:120
Resources are basically the currency of ASC.
Definition: typen.h:97
int maxSpeed() const
TerrainAccess terrainaccess
the terrain this unit can move to
Definition: vehicletype.h:221
void setUnit(VehicleType *type)
void setCompare(bool compare)
void unitGuideWindow(int tabs)
void line(int x1, int y1, int x2, int y2, Uint8 actcol)
draws a simple line on the screen. Not very fast...
Definition: basegfx.cpp:181
int laserRechargeRate
the number of shots that the laser is recharged each turn
Definition: vehicletype.h:140