Start introducing the HUD in the tutorial

New features: player.ship.{show,hide}HUDSelector(selector) to selectively disable HUD entries.
with_dial entry for legends to tie legends to the visibility of particular HUD selectors.
This commit is contained in:
cim 2013-12-04 22:57:39 +00:00
parent 067dd3a222
commit 7e83f253a6
8 changed files with 230 additions and 9 deletions

View File

@ -1012,8 +1012,7 @@
"oolite-start-option-1" = " Start New Commander ";
"oolite-start-option-2" = " Load Commander ";
"oolite-start-option-3" = " View Ship Library ";
// "oolite-start-option-4" = " Manage Expansion Packs "; // not yet implemented
"oolite-start-option-4" = " <coming soon> ";
"oolite-start-option-4" = " Manage Expansion Packs "; // not yet implemented
"oolite-start-option-5" = " Exit Game ";
"oolite-newgame-title" = "Start New Commander";

View File

@ -233,6 +233,7 @@
y_origin = -1;
height = 20;
width = 10;
with_dial = "drawForwardShieldBar:";
},
{ text = "AFT";
x = -262;
@ -240,6 +241,7 @@
y_origin = -1;
height = 20;
width = 10;
with_dial = "drawAftShieldBar:";
},
{
text = "FUEL";
@ -248,6 +250,7 @@
y_origin = -1;
height = 14;
width = 9;
with_dial = "drawFuelBar:";
},
{
text = "CT";
@ -256,6 +259,7 @@
y_origin = -1;
height = 14;
width = 9;
with_dial = "drawCabinTempBar:";
},
{
text = "LT";
@ -264,6 +268,7 @@
y_origin = -1;
height = 14;
width = 9;
with_dial = "drawWeaponTempBar:";
},
{
text = "ALT";
@ -272,6 +277,7 @@
y_origin = -1;
height = 14;
width = 9;
with_dial = "drawAltitudeBar:";
},
{
text = "MISS";
@ -280,6 +286,7 @@
y_origin = -1;
height = 16;
width = 10;
with_dial = "drawMissileDisplay:";
},
{ // RHS
text = "SPD";
@ -288,6 +295,7 @@
y_origin = -1;
height = 20;
width = 10;
with_dial = "drawSpeedBar:";
},
{
text = "ROLL";
@ -296,6 +304,7 @@
y_origin = -1;
height = 12;
width = 9;
with_dial = "drawRollBar:";
},
//{ // yaw bar legend, disabled by default
// // uncomment as required to enable
@ -304,6 +313,7 @@
// y = -138;
// height = 12;
// width = 9;
// with_dial = "drawYawBar:";
//},
{
text = "PITCH";
@ -312,6 +322,7 @@
y_origin = -1;
height = 12;
width = 9;
with_dial = "drawPitchBar:";
}
);
multi_function_displays = (

View File

@ -191,5 +191,16 @@
"oolite-tutorial-1-0" = "Lesson 1: the HUD\nThis lesson introduces the HUD components in turn.\n\nYou will need to press '[oolite_key_activate_equipment]' to go to the next component - do this now.\n\nRemember, you can also press '[oolite_key_mode_equipment]' to skip to the next lesson.";
"oolite-tutorial-1-1" = "Energy banks: 1/3\nThe energy bank gauge shows the stored energy in your ship's capacitors, which are used to power various high-energy systems.\nThey are continually recharged from your ship's power plant, but intensive activity will drain them faster than they can be charged.";
"oolite-tutorial-1-2" = "Energy banks: 2/3\nA crucial system powered by the banks is the emergency hull shield. This will protect your ship and most of its systems from high-energy impact. If your energy banks are too empty to power this shield, this may be fatal.";
"oolite-tutorial-1-3" = "Energy banks: 3/3\nIf your energy banks are low, the gauge will change colour to alert you. Watch how long it takes to recharge from nearly empty, and avoid placing too much strain on the banks.";
"oolite-tutorial-1-4" = "Primary Shields: 1/3\nTo protect your ship further from high energy impacts it is fitted with two shield generators. A pre-charged shield is much more reliable than the emergency hull shield.\nOne generator protects your forward arc...\n";
"oolite-tutorial-1-5" = "Primary Shields: 2/3\n...while the other protects your aft.\nThe charge levels are independent, so try to take impacts on the stronger shield.";
"oolite-tutorial-1-6" = "Primary Shields: 3/3\nThe shields will slowly recharge from the energy banks if they are drained, and the bars will change colour to highlight a drained state. As with the energy banks, a full recharge will take some time.";
}

View File

@ -53,8 +53,8 @@ this.startUp = function()
/* Number of substages in each stage */
this.$tutorialStages = [
2, // stage 0: mission screen, post-launch cleanup
1, // stage 1: HUD displays
10, // stage 1: HUD displays
1 // stage 2: ...
]
// alternative populator
@ -155,6 +155,61 @@ this.startUp = function()
}
}
this.$HUDSelectors = ["drawEnergyGauge:","drawForwardShieldBar:","drawAftShieldBar:","drawSpeedBar:","drawRollBar:","drawPitchBar:","drawYellowSurround:","drawFuelBar:","drawCabinTempBar:","drawWeaponTempBar:","drawAltitudeBar:","drawMissileDisplay:","drawStatusLight:","drawClock:","drawCompass:","drawScanner:","drawScannerZoomIndicator:"];
this.$HUDHighlighter = null;
this.$HUDHighlighterSelector = null;
this.$HUDHighlighterCycles = 10;
this._showHUDItem = function(selector)
{
player.ship.showHUDSelector(selector);
if (this.$HUDHighlighterSelector)
{
player.ship.showHUDSelector(this.$HUDHighlighterSelector);
}
this.$HUDHighlighterSelector = selector;
if (this.$HUDHighlighter)
{
this.$HUDHighlighter.stop();
}
this.$HUDHighlighterCycles = 10;
this.$HUDHighlighter = new Timer
(this,
function()
{
if (this.$HUDHighlighterCycles == 0)
{
this.$HUDHighlighter.stop();
}
else if (this.$HUDHighlighterCycles % 2 == 0)
{
player.ship.hideHUDSelector(this.$HUDHighlighterSelector);
}
else
{
player.ship.showHUDSelector(this.$HUDHighlighterSelector);
}
--this.$HUDHighlighterCycles;
},0.5,0.5);
}
this._resetHUDItems = function()
{
for (var i=0; i<this.$HUDSelectors.length; i++)
{
player.ship.showHUDSelector(this.$HUDSelectors[i]);
}
}
this._hideHUDItems = function()
{
for (var i=0; i<this.$HUDSelectors.length; i++)
{
player.ship.hideHUDSelector(this.$HUDSelectors[i]);
}
}
/* Tutorial stages */
// __stage0sub1 not needed
@ -162,8 +217,51 @@ this.startUp = function()
this.__stage1sub0 = function()
{
this._setInstructions("oolite-tutorial-1-0");
this._hideHUDItems();
player.ship.hudHidden = false;
}
this.__stage1sub1 = function()
{
this._setInstructions("oolite-tutorial-1-1");
this._showHUDItem("drawEnergyGauge:");
}
this.__stage1sub2 = function()
{
this._setInstructions("oolite-tutorial-1-2");
}
this.__stage1sub3 = function()
{
this._setInstructions("oolite-tutorial-1-3");
player.ship.energy = 1;
}
this.__stage1sub4 = function()
{
this._setInstructions("oolite-tutorial-1-4");
this._showHUDItem("drawForwardShieldBar:");
}
this.__stage1sub5 = function()
{
this._setInstructions("oolite-tutorial-1-5");
this._showHUDItem("drawAftShieldBar:");
}
this.__stage1sub6 = function()
{
this._setInstructions("oolite-tutorial-1-6");
player.ship.energy = 256;
player.ship.forwardShield = 0;
player.ship.aftShield = 0;
}
this.__stage2sub0 = function()
{
this._resetHUDItems();
}
}

View File

@ -8144,11 +8144,13 @@ static NSString *last_outfitting_key=nil;
++row;
#if 0
// not yet implemented
text = DESC(@"oolite-start-option-4");
[gui setText:text forRow:row align:GUI_ALIGN_CENTER];
[gui setColor:[OOColor yellowColor] forRow:row];
[gui setKey:[NSString stringWithFormat:@"Start:%d", row] forRow:row];
#endif
++row;

View File

@ -187,6 +187,7 @@ MA 02110-1301, USA.
#define DRAW_SURROUND_KEY @"draw_surround"
#define EQUIPMENT_REQUIRED_KEY @"equipment_required"
#define ALERT_CONDITIONS_KEY @"alert_conditions"
#define DIAL_REQUIRED_KEY @"with_dial"
#define LABELLED_KEY @"labelled"
#define TEXT_KEY @"text"
#define RGB_COLOR_KEY @"rgb_color"
@ -248,6 +249,8 @@ MA 02110-1301, USA.
BOOL hudHidden;
int last_transmitter;
NSMutableSet *_hiddenSelectors;
// Crosshairs
OOCrosshairs *_crosshairs;
@ -283,6 +286,11 @@ MA 02110-1301, USA.
- (BOOL) isHidden;
- (void) setHidden:(BOOL)newValue;
- (BOOL) hasHidden:(NSString *)selectorName;
- (void) setHiddenSelector:(NSString *)selectorName hidden:(BOOL)hide;
- (void) clearHiddenSelectors;
- (BOOL) isCompassActive;
- (void) setCompassActive:(BOOL)newValue;

View File

@ -58,7 +58,7 @@ MA 02110-1301, USA.
#define WIDGET_INFO 0
#define WIDGET_CACHE 1
#define WIDGET_SELECTOR 2
#define WIDGET_SELECTOR_NAME 3
/* Convenience macros to make set-colour-or-default quicker. 'info' must be the NSDictionary and 'alpha' must be the overall alpha or these won't work */
#define DO_SET_COLOR(t,d) SetGLColourFromInfo(info,t,d,alpha)
@ -262,6 +262,8 @@ OOINLINE void GLColorWithOverallAlpha(const GLfloat *color, GLfloat alpha)
hudHidden = NO;
_hiddenSelectors = [[NSMutableSet alloc] initWithCapacity:16];
hudUpdating = NO;
overallAlpha = [hudinfo oo_floatForKey:@"overall_alpha" defaultValue:DEFAULT_OVERALL_ALPHA];
@ -308,7 +310,8 @@ OOINLINE void GLColorWithOverallAlpha(const GLfloat *color, GLfloat alpha)
DESTROY(propertiesReticleTargetSensitive);
DESTROY(_crosshairOverrides);
DESTROY(crosshairDefinition);
DESTROY(_hiddenSelectors);
[super dealloc];
}
@ -523,6 +526,35 @@ OOINLINE void GLColorWithOverallAlpha(const GLfloat *color, GLfloat alpha)
}
- (BOOL) hasHidden:(NSString *)selectorName
{
if (selectorName == nil)
{
return NO;
}
return [_hiddenSelectors containsObject:selectorName];
}
- (void) setHiddenSelector:(NSString *)selectorName hidden:(BOOL)hide
{
if (hide)
{
[_hiddenSelectors addObject:selectorName];
}
else
{
[_hiddenSelectors removeObject:selectorName];
}
}
- (void) clearHiddenSelectors
{
[_hiddenSelectors removeAllObjects];
}
- (BOOL) isCompassActive
{
return _compassActive;
@ -638,9 +670,9 @@ OOINLINE void GLColorWithOverallAlpha(const GLfloat *color, GLfloat alpha)
// valid dial, now prefetch data
struct CachedInfo cache;
prefetchData(info, &cache);
// add WIDGET_INFO, WIDGET_CACHE, WIDGET_SELECTOR to array
// add WIDGET_INFO, WIDGET_CACHE, WIDGET_SELECTOR, WIDGET_SELECTOR_NAME to array
[dialArray addObject:[NSArray arrayWithObjects:info, [NSValue valueWithBytes:&cache objCType:@encode(struct CachedInfo)],
[NSValue valueWithPointer:selector], nil]];
[NSValue valueWithPointer:selector], selectorString, nil]];
}
@ -902,6 +934,12 @@ OOINLINE void GLColorWithOverallAlpha(const GLfloat *color, GLfloat alpha)
}
}
// check association with hidden dials
if ([self hasHidden:[info oo_stringForKey:DIAL_REQUIRED_KEY defaultValue:nil]])
{
return;
}
OOTextureSprite *legendSprite = nil;
NSString *legendText = nil;
float x, y;
@ -962,6 +1000,11 @@ OOINLINE void GLColorWithOverallAlpha(const GLfloat *color, GLfloat alpha)
}
}
if (EXPECT_NOT([self hasHidden:[sCurrentDrawItem objectAtIndex:WIDGET_SELECTOR_NAME]]))
{
return;
}
// use the selector value stored during init.
[self performSelector:[(NSValue *)[sCurrentDrawItem objectAtIndex:WIDGET_SELECTOR] pointerValue] withObject:info];
OOCheckOpenGLErrors(@"HeadUpDisplay after drawHUDItem %@", info);

View File

@ -72,7 +72,8 @@ static JSBool PlayerShipBeginHyperspaceCountdown(JSContext *context, uintN argc,
static JSBool PlayerShipCancelHyperspaceCountdown(JSContext *context, uintN argc, jsval *vp);
static JSBool PlayerShipSetMultiFunctionDisplay(JSContext *context, uintN argc, jsval *vp);
static JSBool PlayerShipSetMultiFunctionText(JSContext *context, uintN argc, jsval *vp);
static JSBool PlayerShipHideHUDSelector(JSContext *context, uintN argc, jsval *vp);
static JSBool PlayerShipShowHUDSelector(JSContext *context, uintN argc, jsval *vp);
static BOOL ValidateContracts(JSContext *context, uintN argc, jsval *vp, BOOL isCargo, OOSystemID *start, OOSystemID *destination, double *eta, double *fee, double *premium, NSString *functionName, unsigned *risk);
@ -203,6 +204,7 @@ static JSFunctionSpec sPlayerShipMethods[] =
{ "cancelHyperspaceCountdown", PlayerShipCancelHyperspaceCountdown, 0 },
{ "disengageAutopilot", PlayerShipDisengageAutopilot, 0 },
{ "engageAutopilotToStation", PlayerShipEngageAutopilotToStation, 1 },
{ "hideHUDSelector", PlayerShipHideHUDSelector, 1 },
{ "launch", PlayerShipLaunch, 0 },
{ "removeAllCargo", PlayerShipRemoveAllCargo, 0 },
{ "removeContract", PlayerShipRemoveContract, 2 },
@ -212,6 +214,7 @@ static JSFunctionSpec sPlayerShipMethods[] =
{ "setCustomView", PlayerShipSetCustomView, 2 },
{ "setMultiFunctionDisplay", PlayerShipSetMultiFunctionDisplay, 1 },
{ "setMultiFunctionText", PlayerShipSetMultiFunctionText, 1 },
{ "showHUDSelector", PlayerShipShowHUDSelector, 1 },
{ "takeInternalDamage", PlayerShipTakeInternalDamage, 0 },
{ "useSpecialCargo", PlayerShipUseSpecialCargo, 1 },
{ 0 }
@ -1229,6 +1232,52 @@ static JSBool PlayerShipSetMultiFunctionText(JSContext *context, uintN argc, jsv
}
static JSBool PlayerShipHideHUDSelector(JSContext *context, uintN argc, jsval *vp)
{
OOJS_NATIVE_ENTER(context)
NSString *key = nil;
PlayerEntity *player = OOPlayerForScripting();
if (argc > 0)
{
key = OOStringFromJSValue(context, OOJS_ARGV[0]);
}
if (key == nil)
{
OOJSReportBadArguments(context, @"PlayerShip", @"hideHUDSelector", MIN(argc, 1U), OOJS_ARGV, nil, @"string (selector)");
return NO;
}
[[player hud] setHiddenSelector:key hidden:YES];
OOJS_RETURN_VOID;
OOJS_NATIVE_EXIT
}
static JSBool PlayerShipShowHUDSelector(JSContext *context, uintN argc, jsval *vp)
{
OOJS_NATIVE_ENTER(context)
NSString *key = nil;
PlayerEntity *player = OOPlayerForScripting();
if (argc > 0)
{
key = OOStringFromJSValue(context, OOJS_ARGV[0]);
}
if (key == nil)
{
OOJSReportBadArguments(context, @"PlayerShip", @"hideHUDSelector", MIN(argc, 1U), OOJS_ARGV, nil, @"string (selector)");
return NO;
}
[[player hud] setHiddenSelector:key hidden:NO];
OOJS_RETURN_VOID;
OOJS_NATIVE_EXIT
}