station_gui.h

Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #ifndef STATION_GUI_H
00013 #define STATION_GUI_H
00014 
00015 #include "command_type.h"
00016 #include "station_type.h"
00017 #include "tilearea_type.h"
00018 #include "window_type.h"
00019 #include "cargo_type.h"
00020 #include <set>
00021 
00022 #include "widgets/station_widget.h"
00023 
00025 enum StationCoverageType {
00026   SCT_PASSENGERS_ONLY,     
00027   SCT_NON_PASSENGERS_ONLY, 
00028   SCT_ALL,                 
00029 };
00030 
00031 int DrawStationCoverageAreaText(int left, int right, int top, StationCoverageType sct, int rad, bool supplies);
00032 void CheckRedrawStationCoverage(const Window *w);
00033 
00034 void ShowSelectStationIfNeeded(CommandContainer cmd, TileArea ta);
00035 void ShowSelectWaypointIfNeeded(CommandContainer cmd, TileArea ta);
00036 
00037 enum SortOrder {
00038   SO_DESCENDING,
00039   SO_ASCENDING
00040 };
00041 
00042 class CargoDataEntry;
00043 
00044 enum CargoSortType {
00045   ST_AS_GROUPING,    
00046   ST_COUNT,          
00047   ST_STATION_STRING, 
00048   ST_STATION_ID,     
00049   ST_CARGO_ID,       
00050 };
00051 
00052 class CargoSorter {
00053 public:
00054   CargoSorter(CargoSortType t = ST_STATION_ID, SortOrder o = SO_ASCENDING) : type(t), order(o) {}
00055   CargoSortType GetSortType() {return this->type;}
00056   bool operator()(const CargoDataEntry *cd1, const CargoDataEntry *cd2) const;
00057 
00058 private:
00059   CargoSortType type;
00060   SortOrder order;
00061 
00062   template<class ID>
00063   bool SortId(ID st1, ID st2) const;
00064   bool SortCount(const CargoDataEntry *cd1, const CargoDataEntry *cd2) const;
00065   bool SortStation (StationID st1, StationID st2) const;
00066 };
00067 
00068 typedef std::set<CargoDataEntry *, CargoSorter> CargoDataSet;
00069 
00075 class CargoDataEntry {
00076 public:
00077   CargoDataEntry();
00078   ~CargoDataEntry();
00079 
00085   CargoDataEntry *InsertOrRetrieve(StationID station) {return this->InsertOrRetrieve<StationID>(station);}
00086 
00092   CargoDataEntry *InsertOrRetrieve(CargoID cargo) {return this->InsertOrRetrieve<CargoID>(cargo);}
00093 
00094   void Update(uint count);
00095 
00100   void Remove(StationID station) {CargoDataEntry t(station); this->Remove(&t);}
00101 
00106   void Remove(CargoID cargo) {CargoDataEntry t(cargo); this->Remove(&t);}
00107 
00113   CargoDataEntry *Retrieve(StationID station) const {CargoDataEntry t(station); return this->Retrieve(this->children->find(&t));}
00114 
00120   CargoDataEntry *Retrieve(CargoID cargo) const {CargoDataEntry t(cargo);return this->Retrieve(this->children->find(&t));}
00121 
00122   void Resort(CargoSortType type, SortOrder order);
00123 
00127   StationID GetStation() const {return this->station;}
00128 
00132   CargoID GetCargo() const {return this->cargo;}
00133 
00137   uint GetCount() const {return this->count;}
00138 
00142   CargoDataEntry *GetParent() const {return this->parent;}
00143 
00147   uint GetNumChildren() const {return this->num_children;}
00148 
00152   CargoDataSet::iterator Begin() const {return this->children->begin();}
00153 
00157   CargoDataSet::iterator End() const {return this->children->end();}
00158 
00159   void Clear();
00160 private:
00161 
00162   CargoDataEntry(StationID st, uint c, CargoDataEntry *p);
00163   CargoDataEntry(CargoID car, uint c, CargoDataEntry *p);
00164   CargoDataEntry(StationID st);
00165   CargoDataEntry(CargoID car);
00166 
00167   CargoDataEntry *Retrieve(CargoDataSet::iterator i) const;
00168 
00169   template<class ID>
00170   CargoDataEntry *InsertOrRetrieve(ID s);
00171 
00172   void Remove(CargoDataEntry *comp);
00173   void IncrementSize();
00174 
00175   CargoDataEntry *parent;   
00176   const union {
00177     StationID station;    
00178     CargoID cargo;        
00179   };
00180   uint num_children;        
00181   uint count;               
00182   CargoDataSet *children;   
00183 };
00184 
00185 #endif /* STATION_GUI_H */