Oolite
Loading...
Searching...
No Matches
HeadUpDisplay.h
Go to the documentation of this file.
1/*
2
3HeadUpDisplay.h
4
5Class handling the player ship’s heads-up display, and 2D drawing functions.
6
7Oolite
8Copyright (C) 2004-2013 Giles C Williams and contributors
9
10This program is free software; you can redistribute it and/or
11modify it under the terms of the GNU General Public License
12as published by the Free Software Foundation; either version 2
13of the License, or (at your option) any later version.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23MA 02110-1301, USA.
24
25*/
26
27#import "OOFoundation.h"
28#import "OOOpenGL.h"
29
30#import "MyOpenGLView.h"
31#import "OOMaths.h"
32#import "OOTypes.h"
33#import "ShipEntity.h"
34
35@class OOCrosshairs, OOColor;
36
37@protocol OOHUDBeaconIcon;
38
39#define SCANNER_CENTRE_X 0
40#define SCANNER_CENTRE_Y -180
41#define SCANNER_SCALE 256
42#define SCANNER_WIDTH 288
43#define SCANNER_HEIGHT 72
44
45#define SCANNER_MAX_ZOOM 5.0
46#define SCANNER_ZOOM_LEVELS 5
47#define ZOOM_INDICATOR_CENTRE_X 108
48#define ZOOM_INDICATOR_CENTRE_Y -216
49#define ZOOM_INDICATOR_WIDTH 11.0f
50#define ZOOM_INDICATOR_HEIGHT 14.0f
51#define ZOOM_LEVELS_IMAGE @"zoom.png"
52
53#define COMPASS_IMAGE @"compass.png"
54#define COMPASS_CENTRE_X 132
55#define COMPASS_CENTRE_Y -216
56#define COMPASS_SIZE 56
57#define COMPASS_HALF_SIZE 28
58#define COMPASS_REDDOT_IMAGE @"reddot.png"
59#define COMPASS_GREENDOT_IMAGE @"greendot.png"
60#define COMPASS_DOT_SIZE 16
61#define COMPASS_HALF_DOT_SIZE 8
62
63#define AEGIS_IMAGE @"aegis.png"
64#define AEGIS_CENTRE_X -132
65#define AEGIS_CENTRE_Y -216
66#define AEGIS_WIDTH 24
67#define AEGIS_HEIGHT 24
68
69#define SPEED_BAR_CENTRE_X 200
70#define SPEED_BAR_CENTRE_Y -145
71#define SPEED_BAR_WIDTH 80
72#define SPEED_BAR_HEIGHT 8
73#define SPEED_BAR_DRAW_SURROUND YES
74
75#define ROLL_BAR_CENTRE_X 200
76#define ROLL_BAR_CENTRE_Y -160
77#define ROLL_BAR_WIDTH 80
78#define ROLL_BAR_HEIGHT 8
79#define ROLL_BAR_DRAW_SURROUND YES
80
81#define PITCH_BAR_CENTRE_X 200
82#define PITCH_BAR_CENTRE_Y -170
83#define PITCH_BAR_WIDTH 80
84#define PITCH_BAR_HEIGHT 8
85#define PITCH_BAR_DRAW_SURROUND YES
86
87#define ENERGY_GAUGE_CENTRE_X 200
88#define ENERGY_GAUGE_CENTRE_Y -205
89#define ENERGY_GAUGE_WIDTH 80
90#define ENERGY_GAUGE_HEIGHT 48
91#define ENERGY_GAUGE_DRAW_SURROUND YES
92
93#define FORWARD_SHIELD_BAR_CENTRE_X -200
94#define FORWARD_SHIELD_BAR_CENTRE_Y -146
95#define FORWARD_SHIELD_BAR_WIDTH 80
96#define FORWARD_SHIELD_BAR_HEIGHT 8
97#define FORWARD_SHIELD_BAR_DRAW_SURROUND YES
98
99#define AFT_SHIELD_BAR_CENTRE_X -200
100#define AFT_SHIELD_BAR_CENTRE_Y -162
101#define AFT_SHIELD_BAR_WIDTH 80
102#define AFT_SHIELD_BAR_HEIGHT 8
103#define AFT_SHIELD_BAR_DRAW_SURROUND YES
104
105#define FUEL_BAR_CENTRE_X -200
106#define FUEL_BAR_CENTRE_Y -179
107#define FUEL_BAR_WIDTH 80
108#define FUEL_BAR_HEIGHT 8
109
110#define WITCHDEST_CENTRE_X -200
111#define WITCHDEST_CENTRE_Y -179
112#define WITCHDEST_WIDTH 80
113#define WITCHDEST_HEIGHT 8
114
115#define CABIN_TEMP_BAR_CENTRE_X -200
116#define CABIN_TEMP_BAR_CENTRE_Y -189
117#define CABIN_TEMP_BAR_WIDTH 80
118#define CABIN_TEMP_BAR_HEIGHT 8
119
120#define WEAPON_TEMP_BAR_CENTRE_X -200
121#define WEAPON_TEMP_BAR_CENTRE_Y -199
122#define WEAPON_TEMP_BAR_WIDTH 80
123#define WEAPON_TEMP_BAR_HEIGHT 8
124
125#define ALTITUDE_BAR_CENTRE_X -200
126#define ALTITUDE_BAR_CENTRE_Y -209
127#define ALTITUDE_BAR_WIDTH 80
128#define ALTITUDE_BAR_HEIGHT 8
129
130#define MISSILES_DISPLAY_X -228
131#define MISSILES_DISPLAY_Y -224
132#define MISSILES_DISPLAY_SPACING 16
133#define MISSILE_ICON_WIDTH 12
134#define MISSILE_ICON_HEIGHT MISSILE_ICON_WIDTH
135
136#define PRIMED_DISPLAY_X -144
137#define PRIMED_DISPLAY_Y -256
138#define PRIMED_DISPLAY_WIDTH 12
139#define PRIMED_DISPLAY_HEIGHT 12
140
141#define ASCTARGET_DISPLAY_X 64
142#define ASCTARGET_DISPLAY_Y -234
143#define ASCTARGET_DISPLAY_WIDTH 10
144#define ASCTARGET_DISPLAY_HEIGHT 10
145
146#define CLOCK_DISPLAY_X -44
147#define CLOCK_DISPLAY_Y -234
148#define CLOCK_DISPLAY_WIDTH 12
149#define CLOCK_DISPLAY_HEIGHT 12
150
151#define WEAPONSOFFLINETEXT_DISPLAY_X -175
152#define WEAPONSOFFLINETEXT_DISPLAY_Y 2
153#define WEAPONSOFFLINETEXT_WIDTH 8
154#define WEAPONSOFFLINETEXT_HEIGHT 8
155
156#define FPSINFO_DISPLAY_X -300
157#define FPSINFO_DISPLAY_Y 220
158#define FPSINFO_DISPLAY_WIDTH 12
159#define FPSINFO_DISPLAY_HEIGHT 12
160
161#define STATUS_LIGHT_CENTRE_X -108
162#define STATUS_LIGHT_CENTRE_Y -216
163#define STATUS_LIGHT_WIDTH 8
164#define STATUS_LIGHT_HEIGHT 8
165
166#define HIT_INDICATOR_CENTRE_X 200
167#define HIT_INDICATOR_CENTRE_Y 0
168
169#define SCOOPSTATUS_CENTRE_X -132
170#define SCOOPSTATUS_CENTRE_Y -152
171#define SCOOPSTATUS_WIDTH 16.0
172#define SCOOPSTATUS_HEIGHT 16.0
173
174#define MFD_TEXT_WIDTH 10
175#define MFD_TEXT_HEIGHT 10
176
177#define DIALS_KEY @"dials"
178#define LEGENDS_KEY @"legends"
179#define MFDS_KEY @"multi_function_displays"
180#define X_KEY @"x"
181#define Y_KEY @"y"
182#define X_ORIGIN_KEY @"x_origin"
183#define Y_ORIGIN_KEY @"y_origin"
184#define SPACING_KEY @"spacing"
185#define ALPHA_KEY @"alpha"
186#define SELECTOR_KEY @"selector"
187#define IMAGE_KEY @"image"
188#define WIDTH_KEY @"width"
189#define HEIGHT_KEY @"height"
190#define SPRITE_KEY @"sprite"
191#define DRAW_SURROUND_KEY @"draw_surround"
192#define EQUIPMENT_REQUIRED_KEY @"equipment_required"
193#define ALERT_CONDITIONS_KEY @"alert_conditions"
194#define VIEWSCREEN_KEY @"viewscreen_only"
195#define DIAL_REQUIRED_KEY @"with_dial"
196#define LABELLED_KEY @"labelled"
197#define TEXT_KEY @"text"
198#define RGB_COLOR_KEY @"rgb_color"
199#define COLOR_KEY @"color"
200#define COLOR_KEY_LOW @"color_low"
201#define COLOR_KEY_MEDIUM @"color_medium"
202#define COLOR_KEY_HIGH @"color_high"
203#define COLOR_KEY_CRITICAL @"color_critical"
204#define COLOR_KEY_SURROUND @"color_surround"
205#define N_BARS_KEY @"n_bars"
206#define CUSTOM_DIAL_KEY @"data_source"
207
208#define ROWS_KEY @"rows"
209#define COLUMNS_KEY @"columns"
210#define ROW_HEIGHT_KEY @"row_height"
211#define ROW_START_KEY @"row_start"
212#define TITLE_KEY @"title"
213#define BACKGROUND_RGBA_KEY @"background_rgba"
214#define OVERALL_ALPHA_KEY @"overall_alpha"
215#define NONLINEAR_SCANNER @"nonlinear_scanner"
216
217#define Z1 [(MyOpenGLView*)[[player universe] gameView] display_z]
218
219#define ONE_EIGHTH 0.125
220
221#define MAX_ACCURACY_RANGE 7000 // 7.000km
222#define ACCURACY_PROBABILITY_DECREASE_FACTOR 0.000035f // for every 1000km decrease by 3.5% the chance of high accuracy
223#define MIN_PROBABILITY_ACCURACY 0.35f // floor value for probability of high accuracy is 35%
224
225enum {
229};
230
232
233@interface HeadUpDisplay : NSObject {
234@private
235 NSMutableArray* legendArray;
236 NSMutableArray* dialArray;
237 NSMutableArray* mfdArray;
238
239 // zoom level
241
242 // where to draw it
243 GLfloat z1;
244 GLfloat lineWidth;
245
246 NSString* hudName;
247 NSString* deferredHudName; // Usually it will be nil. If not nil, then it means that we have a deferred HUD waiting to be drawn This may happen
248 // for example when a script handler attempts to switch HUD while it is being rendered. - Nikos 20110628
250
251 GLfloat overallAlpha;
252
253 BOOL reticleTargetSensitive; // TO DO: Move this into the propertiesReticleTargetSensitive structure (Getafix - 2010/08/21)
254 NSMutableDictionary* propertiesReticleTargetSensitive;
255
257
259
260 BOOL allowBigGui;
261
263
264 NSMutableSet* _hiddenSelectors;
265
266 // Crosshairs
271 NSDictionary* _crosshairOverrides;
275 NSString* crosshairDefinition;
277
278 NSMutableArray* _reticleColors;
279
280 // essentially scanner without gridlines
282
283 // Nonlinear scanner
286}
287
288- (id)initWithDictionary:(NSDictionary*)hudinfo;
289- (id)initWithDictionary:(NSDictionary*)hudinfo inFile:(NSString*)hudFileName;
290
291- (void)resetGuis:(NSDictionary*)info;
292
293- (NSString*)hudName;
294- (void)setHudName:(NSString*)newHudName;
295
296- (GLfloat)scannerZoom;
297- (void)setScannerZoom:(GLfloat)value;
298
299- (GLfloat)overallAlpha;
300- (void)setOverallAlpha:(GLfloat)newAlphaValue;
301
303- (void)setReticleTargetSensitive:(BOOL)newReticleTargetSensitiveValue;
304- (NSMutableDictionary*)propertiesReticleTargetSensitive;
305
306- (BOOL)isHidden;
307- (void)setHidden:(BOOL)newValue;
308
310
311- (BOOL)hasHidden:(NSString*)selectorName;
312- (void)setHiddenSelector:(NSString*)selectorName hidden:(BOOL)hide;
314
315- (BOOL)isCompassActive;
316- (void)setCompassActive:(BOOL)newValue;
317
318- (BOOL)isUpdating;
319- (void)setDeferredHudName:(NSString*)newDeferredHudName;
320- (NSString*)deferredHudName;
322- (BOOL)setCrosshairDefinition:(NSString*)newDefinition;
323
324- (void)addLegend:(NSDictionary*)info;
325- (void)addDial:(NSDictionary*)info;
326- (void)addMFD:(NSDictionary*)info;
327
328- (NSUInteger)mfdCount;
329
330- (void)renderHUD;
331
333
334- (void)setLineWidth:(GLfloat)value;
335- (GLfloat)lineWidth;
336
337- (BOOL)minimalisticScanner;
338- (void)setMinimalisticScanner:(BOOL)newValue;
339
340+ (Vector)nonlinearScannerScale:(Vector)V Zoom:(GLfloat)zoom Scale:(double)scale;
341- (BOOL)nonlinearScanner;
342- (void)setNonlinearScanner:(BOOL)newValue;
343
344- (BOOL)scannerUltraZoom;
345- (void)setScannerUltraZoom:(BOOL)newValue;
346
347- (OOColor*)reticleColorForIndex:(NSUInteger)idx;
348- (BOOL)setReticleColorForIndex:(NSUInteger)idx toColor:(OOColor*)newColor;
349
350@end
351
352@interface NSString (OODisplayEncoding)
353
354// Return a C string in the 8-bit encoding used for display.
355- (const char*)cStringUsingOoliteEncoding;
356
357// Return a C string in the 8-bit encoding used for display, with substitutions performed.
359
360@end
361
362/*
363 Protocol for things that can be used as HUD compass items. Really ought
364 to grow into a general protocol for HUD elements.
365*/
366@protocol OOHUDBeaconIcon <NSObject>
367
368- (void)oo_drawHUDBeaconIconAt:(NSPoint)where size:(NSSize)size alpha:(GLfloat)alpha z:(GLfloat)z;
369
370@end
371
372@interface NSString (OOHUDBeaconIcon) <OOHUDBeaconIcon>
373@end
374
375void OODrawString(NSString* text, GLfloat x, GLfloat y, GLfloat z, NSSize siz);
376void OODrawStringAligned(NSString* text, GLfloat x, GLfloat y, GLfloat z, NSSize siz, BOOL rightAlign);
377
378/* OODrawString(Aligned) handles all the string drawing, but because
379 * it does texture application and GL_QUADS beginning once per string
380 * it's quite slow.
381 *
382 * Where efficiency is needed, call OOStartDrawingStrings(), then
383 * OODrawStringQuadsAligned for each bit of text, then
384 * OOStopDrawingStrings().
385 *
386 * Trying to draw anything else between OOStartDrawingStrings() and
387 * OOStopDrawingStrings() will have messy results. You can safely call
388 * Stop, draw the other thing you want, then call Start again - it's
389 * just a little inefficient. Similarly calling
390 * OODrawStringQuadsAligned() without calling OOStartDrawingStrings()
391 * won't work very well.
392 *
393 * - CIM
394 */
396void OODrawStringQuadsAligned(NSString* text, GLfloat x, GLfloat y, GLfloat z, NSSize siz, BOOL rightAlign);
398
399void OODrawHilightedString(NSString* text, GLfloat x, GLfloat y, GLfloat z, NSSize siz);
400void OODrawPlanetInfo(int gov, int eco, int tec, GLfloat x, GLfloat y, GLfloat z, NSSize siz);
401void OODrawHilightedPlanetInfo(int gov, int eco, int tec, GLfloat x, GLfloat y, GLfloat z, NSSize siz);
402NSRect OORectFromString(NSString* text, GLfloat x, GLfloat y, NSSize siz);
403CGFloat OOStringWidthInEm(NSString* text);
404
void OODrawStringAligned(NSString *text, GLfloat x, GLfloat y, GLfloat z, NSSize siz, BOOL rightAlign)
void OODrawHilightedString(NSString *text, GLfloat x, GLfloat y, GLfloat z, NSSize siz)
void OOHUDResetTextEngine(void)
void OODrawStringQuadsAligned(NSString *text, GLfloat x, GLfloat y, GLfloat z, NSSize siz, BOOL rightAlign)
void OOStartDrawingStrings(void)
NSRect OORectFromString(NSString *text, GLfloat x, GLfloat y, NSSize siz)
CGFloat OOStringWidthInEm(NSString *text)
@ OO_RETICLE_COLOR_TARGET
@ OO_RETICLE_COLOR_WORMHOLE
@ OO_RETICLE_COLOR_TARGET_SENSITIVE
void OODrawHilightedPlanetInfo(int gov, int eco, int tec, GLfloat x, GLfloat y, GLfloat z, NSSize siz)
void OODrawString(NSString *text, GLfloat x, GLfloat y, GLfloat z, NSSize siz)
void OODrawPlanetInfo(int gov, int eco, int tec, GLfloat x, GLfloat y, GLfloat z, NSSize siz)
void OOStopDrawingStrings(void)
float y
float x
OOEquipmentType * OOWeaponType
Definition ShipEntity.h:164
const char * cStringUsingOoliteEncoding()
const char * cStringUsingOoliteEncodingAndRemapping()
OOCrosshairs * _crosshairs
NSMutableArray * _reticleColors
GLfloat scanner_zoom
NSString * hudName
NSString * deferredHudName
GLfloat _crosshairScale
NSString * crosshairDefinition
OOColor * _crosshairColor
OOWeaponType _lastWeaponType
NSMutableSet * _hiddenSelectors
GLfloat _lastOverallAlpha
void refreshLastTransmitter()
NSUInteger mfdCount()
BOOL cloakIndicatorOnStatusLight
NSMutableArray * mfdArray
NSDictionary * _crosshairOverrides
GLfloat scannerZoom()
GLfloat _crosshairWidth
NSMutableArray * dialArray
GLfloat overallAlpha
BOOL minimalistic_scanner
void clearHiddenSelectors()
NSMutableDictionary * propertiesReticleTargetSensitive
BOOL reticleTargetSensitive
NSMutableArray * legendArray