summary refs log tree commit diff stats
path: root/tools/mapedit/src/object.h
blob: a87fa9675daef4fd9379407f9862ee8661288a7d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#ifndef OBJECT_H
#define OBJECT_H

#include <wx/wxprec.h>

#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif

#include <string>
#include <map>

class World;

class MapObjectLoadException: public std::exception
{
  public:
    MapObjectLoadException(std::string stuff) : stuff(stuff) {}
    
    virtual const char* what() const throw()
    {
      return ("An error occured loading map objects: " + stuff).c_str();
    }
    
  private:
    std::string stuff;
};

class MapObject {
  public:
    MapObject(std::string id);
    
    static const std::map<std::string, MapObject>& getAllObjects();
    
    struct Input {
      enum class Type {
        Slider,
        Choice
      };
      
      std::string name;
      Type type;
      int minvalue;
      int maxvalue;
      std::map<int, std::string> choices;
    };
    
    std::string getID() const;
    std::string getName() const;
    wxBitmap getSprite() const;
    int getWidth() const;
    int getHeight() const;
    const std::map<std::string, Input>& getInputs() const;
    const Input& getInput(std::string id) const;
    
    bool operator==(const MapObject& other) const;
    bool operator!=(const MapObject& other) const;
    
  private:
    const std::string id;
    std::string name;
    wxBitmap sprite;
    int width;
    int height;
    std::map<std::string, Input> inputs;
};

class MapObjectEntry {
  public:
    MapObjectEntry(
      const MapObject& object,
      int posx,
      int posy,
      size_t index);
    
    struct Item {
      MapObject::Input::Type type;
      int intvalue;
    };
    
    const MapObject& getObject() const;
    std::pair<int, int> getPosition() const;
    Item& getItem(std::string str);
    const std::map<std::string, Item>& getItems() const;
    size_t getIndex() const;
    
    void setPosition(int x, int y);
    void addItem(std::string id, Item& item);
    
    bool operator==(const MapObjectEntry& other) const;
    bool operator!=(const MapObjectEntry& other) const;
  
  private:
    const MapObject& object;
    std::pair<int, int> position;
    std::map<std::string, Item> items; 
    size_t index;
};

class VariableChoiceValidator : public wxValidator {
  public:
    VariableChoiceValidator(World& world, MapObjectEntry::Item& item);
    wxObject* Clone() const;
    bool TransferFromWindow();
    bool TransferToWindow();
    bool Validate(wxWindow* parent);
    
  private:
    World& world;
    MapObjectEntry::Item& item;
};

class SliderItemValidator : public wxValidator {
  public:
    SliderItemValidator(World& world, MapObjectEntry::Item& item);
    wxObject* Clone() const;
    bool TransferFromWindow();
    bool TransferToWindow();
    bool Validate(wxWindow* parent);
    
  private:
    World& world;
    MapObjectEntry::Item& item;
};

#endif