Advanced Strategic Command
common.h
Go to the documentation of this file.
1 /*
2  This file is part of Advanced Strategic Command; http://www.asc-hq.de
3  Copyright (C) 1994-2010 Martin Bickel
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; see the file COPYING. If not, write to the
17  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  Boston, MA 02111-1307 USA
19 */
20 
21 
22 #ifndef commonH
23 #define commonH
24 
25 #include "../typen.h"
26 
27 #include "../paradialog.h"
28 
29 class GameMap;
30 class ObjectType;
31 class BuildingType;
32 class VehicleType;
33 class TerrainType;
34 
35 extern GameMap* getActiveMap();
36 
37 extern const ObjectType* getObjectType( int id );
38 extern const BuildingType* getBuildingType( int id );
39 extern const VehicleType* getUnitType( int id );
40 extern const TerrainType* getTerrainType( int id );
41 
42 class StringArray {
43  public:
44  vector<ASCString> values;
46  void add( const ASCString& s ) { values.push_back( s ); };
47  ASCString getItem( int n )
48  {
49  return (n> 0 && n <= values.size()) ? values[n-1] : ASCString();
50  }
51  int size() { return values.size(); }; //
52 };
53 
54 class PropertyDialog : public ASC_PG_Dialog {
55  private:
56  PG_PropertyEditor* propertyEditor;
57  bool result;
58 
59  bool ok();
60  bool cancel();
61 
62  map<ASCString,bool> boolValues;
63  map<ASCString,int> intValues;
64  map<ASCString,ASCString> stringValues;
65 
66  void setup();
67 
68  public:
69  PropertyDialog( const ASCString& title );
70  PropertyDialog( const ASCString& title, const PG_Rect& size );
71  void addBool( const ASCString& name, bool defaultValue );
72  void addInteger( const ASCString& name, int defaultValue );
73  void addIntDropdown ( const ASCString& name, const StringArray& names, int defaultValue );
74  void addString( const ASCString& name, const ASCString& defaultValue );
75 
76  std::string getString( const ASCString& name );
77  int getInteger( const ASCString& name );
78  bool getBool( const ASCString& name );
79  bool run();
80 };
81 
82 extern int selectString ( const ASCString& title, const StringArray& entries, int defaultEntry = -1 );
83 
84 extern GameMap* getLoadingMap();
85 
86 extern void setLocalizedEventMessage( GameMap* map, int eventID, const ASCString& message );
87 extern void setLocalizedContainerName( GameMap* map, const MapCoordinate& pos, const std::string& name );
88 
89 extern MapCoordinate getCursorPosition( const GameMap* gamemap );
90 
91 extern void setCursorPosition( const GameMap* gamemap, const MapCoordinate& pos );
92 
93 extern void assertSuccess( const ActionResult& result );
94 
95 #endif
96 
The type of a field.
Definition: terraintype.h:75
void add(const ASCString &s)
Definition: common.h:46
GameMap * getLoadingMap()
Definition: common.cpp:166
GameMap * getActiveMap()
Definition: common.cpp:45
const TerrainType * getTerrainType(int id)
Definition: common.cpp:65
void setLocalizedEventMessage(GameMap *map, int eventID, const ASCString &message)
Definition: common.cpp:172
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
std::string getString(const ASCString &name)
Definition: common.cpp:130
vector< ASCString > values
Definition: common.h:44
void addInteger(const ASCString &name, int defaultValue)
Definition: common.cpp:112
The class describing properties that are common to all vehicles of a certain kind.
Definition: vehicletype.h:177
The class describing properties that are common to all buildings of a certain kind.
Definition: buildingtype.h:35
int getInteger(const ASCString &name)
Definition: common.cpp:135
ASCString getItem(int n)
Definition: common.h:47
void addBool(const ASCString &name, bool defaultValue)
Definition: common.cpp:106
const BuildingType * getBuildingType(int id)
Definition: common.cpp:55
An object that can be placed on fields. Roads, pipelines and ditches are examples of objects...
Definition: objecttype.h:30
Coordinate on the twodimensional map.
Definition: typen.h:202
Adapter class for using Paragui Dialogs in ASC. This class transfers the event control from ASC to Pa...
Definition: paradialog.h:127
void addString(const ASCString &name, const ASCString &defaultValue)
Definition: common.cpp:124
StringArray()
Definition: common.h:45
MapCoordinate getCursorPosition(const GameMap *gamemap)
Definition: common.cpp:203
void addIntDropdown(const ASCString &name, const StringArray &names, int defaultValue)
Definition: common.cpp:118
const VehicleType * getUnitType(int id)
Definition: common.cpp:60
void setCursorPosition(const GameMap *gamemap, const MapCoordinate &pos)
Definition: common.cpp:211
const ObjectType * getObjectType(int id)
Definition: common.cpp:50
int selectString(const ASCString &title, const StringArray &entries, int defaultEntry=-1)
Definition: common.cpp:153
int size()
Definition: common.h:51
bool run()
Definition: common.cpp:145
bool getBool(const ASCString &name)
Definition: common.cpp:140
void assertSuccess(const ActionResult &result)
Definition: common.cpp:218
void setLocalizedContainerName(GameMap *map, const MapCoordinate &pos, const std::string &name)
Definition: common.cpp:182
PropertyDialog(const ASCString &title)
Definition: common.cpp:95
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182