summaryrefslogtreecommitdiffhomepage
path: root/StarsEx/MapView.h
blob: d89ac922a241a8abef41b983c51b0a691647b47b (plain)
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*  Starshatter: The Open Source Project
    Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors
    Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
    Copyright (c) 1997-2006, Destroyer Studios LLC.

    AUTHOR:       John DiCamillo


    OVERVIEW
    ========
    Star Map class
*/

#ifndef MapView_h
#define MapView_h

#include "Types.h"
#include "SimObject.h"
#include "View.h"
#include "UIEventTarget.h"
#include "Bitmap.h"
#include "List.h"
#include "Text.h"

// +--------------------------------------------------------------------+

class ActiveWindow;
class StarSystem;
class Orbital;
class OrbitalRegion;
class Ship;
class Instruction;
class Mission;
class MissionElement;
class Campaign;
class Combatant;
class CombatGroup;
class Menu;
class MenuItem;
class MenuView;
class Font;

const int EID_MAP_CLICK = 1000;

// +--------------------------------------------------------------------+

class MapView : public View,
public UIEventTarget,
public SimObserver
{
public:
    MapView(Window* win);
    virtual ~MapView();

    // Operations:
    virtual void      Refresh();
    virtual void      OnWindowMove();
    virtual void      OnShow();
    virtual void      OnHide();

    virtual void      DrawTitle();
    virtual void      DrawGalaxy();
    virtual void      DrawSystem();
    virtual void      DrawRegion();

    virtual void      DrawGrid();
    virtual void      DrawOrbital(Orbital& orbital, int index);
    virtual void      DrawShip(Ship& ship,           bool current=false, int rep=3);
    virtual void      DrawElem(MissionElement& elem, bool current=false, int rep=3);
    virtual void      DrawNavRoute(OrbitalRegion*      rgn,
    List<Instruction>&  route,
    Color               smarker,
    Ship*               ship=0,
    MissionElement*     elem=0);

    virtual void      DrawCombatantSystem(Combatant* c, Orbital* rgn, int x, int y, int r);
    virtual void      DrawCombatGroupSystem(CombatGroup* g, Orbital* rgn, int x1, int x2, int& y, int a);
    virtual void      DrawCombatGroup(CombatGroup* g, int rep=3);

    virtual int       GetViewMode() const { return view_mode; }
    virtual void      SetViewMode(int mode);
    virtual void      SetSelectionMode(int mode);
    virtual int       GetSelectionMode() const { return seln_mode; }
    virtual void      SetSelection(int index);
    virtual void      SetSelectedShip(Ship* ship);
    virtual void      SetSelectedElem(MissionElement* elem);
    virtual void      SetRegion(OrbitalRegion* rgn);
    virtual void      SetRegionByName(const char* rgn_name);
    virtual void      SelectAt(int x, int y);
    virtual Orbital*  GetSelection();
    virtual Ship*     GetSelectedShip();
    virtual MissionElement* GetSelectedElem();
    virtual int       GetSelectionIndex();
    virtual void      SetShipFilter(DWORD f) { ship_filter = f; }

    // Event Target Interface:
    virtual int       OnMouseMove(int x, int y);
    virtual int       OnLButtonDown(int x, int y);
    virtual int       OnLButtonUp(int x, int y);
    virtual int       OnClick();
    virtual int       OnRButtonDown(int x, int y);
    virtual int       OnRButtonUp(int x, int y);

    virtual bool      IsEnabled()    const;
    virtual bool      IsVisible()    const;
    virtual bool      IsFormActive() const;
    virtual Rect      TargetRect()   const;

    void              ZoomIn();
    void              ZoomOut();

    void              SetGalaxy(List<StarSystem>& systems);
    void              SetSystem(StarSystem* s);
    void              SetMission(Mission* m);
    void              SetShip(Ship* s);
    void              SetCampaign(Campaign* c);

    bool              IsVisible(const Point& loc);

    // accessors:
    virtual void      GetClickLoc(double& x, double& y) { x = click_x; y = click_y; }
    List<StarSystem>& GetGalaxy()       { return system_list; }
    StarSystem*       GetSystem() const { return system; }
    OrbitalRegion*    GetRegion() const;

    virtual bool         Update(SimObject* obj);
    virtual const char*  GetObserverName() const { return "MapWin"; }

    bool              GetEditorMode()            const { return editor;      }
    void              SetEditorMode(bool b)            { editor = b;         }

protected:
    virtual void      BuildMenu();
    virtual void      ClearMenu();
    virtual void      ProcessMenuItem(int action);
    virtual bool      SetCapture();
    virtual bool      ReleaseCapture();

    virtual void      DrawTabbedText(Font* font, const char* text);

    bool              IsClutter(Ship& s);
    bool              IsCrowded(Ship& s);
    bool              IsCrowded(MissionElement& elem);
    void              GetShipLoc(Ship& s, POINT& loc);
    void              GetElemLoc(MissionElement& s, POINT& loc);
    void              SelectShip(Ship* selship);
    void              SelectElem(MissionElement* selelem);
    void              SelectNavpt(Instruction* navpt);
    void              FindShips(bool friendly, bool station, bool starship, bool dropship,
    List<Text>& result);
    void              SetupScroll(Orbital* s);

    double            GetMinRadius(int type);

    Text              title;
    Rect              rect;
    Campaign*         campaign;
    Mission*          mission;
    List<StarSystem>  system_list;
    StarSystem*       system;
    List<Orbital>     stars;
    List<Orbital>     planets;
    List<Orbital>     regions;
    Ship*             ship;
    Bitmap            galaxy_image;
    bool              editor;

    int               current_star;
    int               current_planet;
    int               current_region;
    Ship*             current_ship;
    MissionElement*   current_elem;
    Instruction*      current_navpt;
    int               current_status;

    int               view_mode;
    int               seln_mode;
    bool              captured;
    bool              dragging;
    bool              adding_navpt;
    bool              moving_navpt;
    bool              moving_elem;
    int               scrolling;
    int               mouse_x;
    int               mouse_y;
    DWORD             ship_filter;

    double            zoom;
    double            view_zoom[3];
    double            offset_x;
    double            offset_y;
    double            view_offset_x[3];
    double            view_offset_y[3];
    double            c, r;
    double            scroll_x;
    double            scroll_y;
    double            click_x;
    double            click_y;

    Font*             font;
    Font*             title_font;

    ActiveWindow*     active_window;
    Menu*             active_menu;

    Menu*       map_menu;
    Menu*       map_system_menu;
    Menu*       map_sector_menu;
    Menu*       ship_menu;
    Menu*       nav_menu;
    Menu*       action_menu;
    Menu*       objective_menu;
    Menu*       formation_menu;
    Menu*       speed_menu;
    Menu*       hold_menu;
    Menu*       farcast_menu;

    MenuView*   menu_view;
};

#endif  // MapView_h