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