Start on tutorial set up
Add third parameter to PS.setMultiFunctionText (bool reflow). If true, automatically reflows text to keep within width limits. (Should we default this to on? That's probably the more common case.)
This commit is contained in:
parent
c8cc203ff5
commit
2be33a0eef
@ -183,4 +183,13 @@
|
|||||||
|
|
||||||
"oolite-primablemanager-completed" = "Equipment configuration is complete.\n\nFirst fast activation (defensive):\n [oolite-primable-a]\n\nSecond fast activation (offensive):\n [oolite-primable-b]";
|
"oolite-primablemanager-completed" = "Equipment configuration is complete.\n\nFirst fast activation (defensive):\n [oolite-primable-a]\n\nSecond fast activation (offensive):\n [oolite-primable-b]";
|
||||||
|
|
||||||
|
|
||||||
|
// tutorial
|
||||||
|
"oolite-tutorial-0-0-title" = "Flight Training Course";
|
||||||
|
"oolite-tutorial-0-0-message" = "Welcome to the Cooperative Flight Training Course, pilot. This course will demonstrate the basic functionality of Cooperative ships to you, in a specially-prepared simulator.\n\nThe course is in multiple sections. While in the simulator, you can use the '[oolite_key_activate_equipment]' key to advance to the next entry in the current lesson, and the '[oolite_key_mode_equipment]' key to go to the next lesson, if you wish to skip sections you have previously completed.\n\nOnce the simulation begins, a panel on your screen will display instructions, which you should follow to progress through the course. If you wish to temporarily hide the panel, press the '[oolite_key_cycle_mfd]' key. You can bring it back with the same key, or it will automatically reappear when there are new instructions.\n\nWhen you are ready, press the Enter key to begin the simulation with the first lesson.";
|
||||||
|
"oolite-tutorial-0-0-choices" = { "1" = "Begin Course"; };
|
||||||
|
|
||||||
|
"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.";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,18 @@ this.startUp = function()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
log(this.name,"Tutorial mode active");
|
log(this.name,"Tutorial mode active");
|
||||||
// define rest of script now
|
// define rest of script now, otherwise it's pointless as it never
|
||||||
|
// gets used in normal play
|
||||||
|
|
||||||
|
this.$tutorialStage = 0;
|
||||||
|
this.$tutorialSubstage = 0;
|
||||||
|
|
||||||
|
/* Number of substages in each stage */
|
||||||
|
this.$tutorialStages = [
|
||||||
|
2, // stage 0: mission screen, post-launch cleanup
|
||||||
|
1, // stage 1: HUD displays
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
// alternative populator
|
// alternative populator
|
||||||
this.ooliteTutorialWillPopulate = function()
|
this.ooliteTutorialWillPopulate = function()
|
||||||
@ -70,18 +81,89 @@ this.startUp = function()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
this.missionScreenOpportunity = function()
|
||||||
|
{
|
||||||
|
if (this.$tutorialStage == 0 && this.$tutorialSubstage == 0)
|
||||||
|
{
|
||||||
|
player.ship.hudHidden = true;
|
||||||
|
mission.runScreen(
|
||||||
|
{
|
||||||
|
titleKey: "oolite-tutorial-0-0-title",
|
||||||
|
messageKey: "oolite-tutorial-0-0-message",
|
||||||
|
choicesKey: "oolite-tutorial-0-0-choices",
|
||||||
|
screenID: "oolite-tutorial-0-0"
|
||||||
|
},function()
|
||||||
|
{
|
||||||
|
player.ship.launch();
|
||||||
|
this._nextItem();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
this.shipLaunchedFromStation = function(station)
|
||||||
|
{
|
||||||
|
if (this.$tutorialStage == 0 && this.$tutorialSubstage == 1)
|
||||||
|
{
|
||||||
|
station.remove();
|
||||||
|
this._nextItem();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// move to the next item in the current tutorial
|
||||||
this._nextItem = function()
|
this._nextItem = function()
|
||||||
{
|
{
|
||||||
// move to the next item in the current tutorial
|
this.$tutorialSubstage++;
|
||||||
|
if (this.$tutorialSubstage >= this.$tutorialStages[this.$tutorialStage])
|
||||||
|
{
|
||||||
|
this._nextSection();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var fn = "__stage"+this.$tutorialStage+"sub"+this.$tutorialSubstage;
|
||||||
|
if (this[fn])
|
||||||
|
{
|
||||||
|
this[fn]();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// move to the next section of the tutorial
|
||||||
this._nextSection = function()
|
this._nextSection = function()
|
||||||
{
|
{
|
||||||
// move to the next section of the current tutorial
|
this.$tutorialStage++;
|
||||||
|
this.$tutorialSubstage = 0;
|
||||||
|
var fn = "__stage"+this.$tutorialStage+"sub"+this.$tutorialSubstage;
|
||||||
|
if (this[fn])
|
||||||
|
{
|
||||||
|
this[fn]();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
this._setInstructions = function(key)
|
||||||
|
{
|
||||||
|
if (player.ship.multiFunctionDisplays == 0)
|
||||||
|
{
|
||||||
|
log(this.name,"Installed HUD does not support multi-function displays - unable to show instructions");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
player.ship.setMultiFunctionText("oolite-tutorial",expandMissionText(key),true);
|
||||||
|
player.ship.setMultiFunctionDisplay(0,"oolite-tutorial");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Tutorial stages */
|
||||||
|
|
||||||
|
// __stage0sub1 not needed
|
||||||
|
|
||||||
|
this.__stage1sub0 = function()
|
||||||
|
{
|
||||||
|
this._setInstructions("oolite-tutorial-1-0");
|
||||||
|
player.ship.hudHidden = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -196,6 +196,7 @@ typedef OOGUITabStop OOGUITabSettings[GUI_MAX_COLUMNS];
|
|||||||
- (void) setKey:(NSString *)str forRow:(OOGUIRow)row;
|
- (void) setKey:(NSString *)str forRow:(OOGUIRow)row;
|
||||||
- (void) setText:(NSString *)str forRow:(OOGUIRow)row;
|
- (void) setText:(NSString *)str forRow:(OOGUIRow)row;
|
||||||
- (void) setText:(NSString *)str forRow:(OOGUIRow)row align:(OOGUIAlignment)alignment;
|
- (void) setText:(NSString *)str forRow:(OOGUIRow)row align:(OOGUIAlignment)alignment;
|
||||||
|
- (NSString *) reflowTextForMFD:(NSString *)input;
|
||||||
- (OOGUIRow) addLongText:(NSString *)str
|
- (OOGUIRow) addLongText:(NSString *)str
|
||||||
startingAtRow:(OOGUIRow)row
|
startingAtRow:(OOGUIRow)row
|
||||||
align:(OOGUIAlignment)alignment;
|
align:(OOGUIAlignment)alignment;
|
||||||
|
@ -645,6 +645,39 @@ static BOOL _refreshStarChart = NO;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (NSString *) reflowTextForMFD:(NSString *)input
|
||||||
|
{
|
||||||
|
NSMutableString *output = [[NSMutableString alloc] initWithCapacity:512];
|
||||||
|
NSArray *lines = [input componentsSeparatedByString:@"\n"];
|
||||||
|
NSSize chSize = pixel_text_size;
|
||||||
|
NSUInteger limit = chSize.width * 15;
|
||||||
|
NSString *line = nil;
|
||||||
|
foreach (line, lines)
|
||||||
|
{
|
||||||
|
NSMutableArray *words = ScanTokensFromString(line);
|
||||||
|
NSMutableString *accum = [NSMutableString stringWithCapacity:64];
|
||||||
|
while ([words count] > 1)
|
||||||
|
{
|
||||||
|
[accum appendString:[words oo_stringAtIndex:0]];
|
||||||
|
[accum appendString:@" "];
|
||||||
|
if (OORectFromString(accum, 0.0f, 0.0f,chSize).size.width + OORectFromString([words oo_stringAtIndex:1], 0.0f, 0.0f,chSize).size.width > limit)
|
||||||
|
{
|
||||||
|
// can't fit next word on this line
|
||||||
|
[output appendString:[accum stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]];
|
||||||
|
[output appendString:@"\n"];
|
||||||
|
[accum setString:@""];
|
||||||
|
}
|
||||||
|
[words removeObjectAtIndex:0];
|
||||||
|
}
|
||||||
|
[output appendString:accum];
|
||||||
|
[output appendString:[words oo_stringAtIndex:0]];
|
||||||
|
[output appendString:@"\n"];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [output autorelease];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void) leaveLastLine
|
- (void) leaveLastLine
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
@ -1191,6 +1191,7 @@ static JSBool PlayerShipSetMultiFunctionText(JSContext *context, uintN argc, jsv
|
|||||||
NSString *key = nil;
|
NSString *key = nil;
|
||||||
NSString *value = nil;
|
NSString *value = nil;
|
||||||
PlayerEntity *player = OOPlayerForScripting();
|
PlayerEntity *player = OOPlayerForScripting();
|
||||||
|
JSBool reflow = NO;
|
||||||
|
|
||||||
if (argc > 0)
|
if (argc > 0)
|
||||||
{
|
{
|
||||||
@ -1205,8 +1206,22 @@ static JSBool PlayerShipSetMultiFunctionText(JSContext *context, uintN argc, jsv
|
|||||||
{
|
{
|
||||||
value = OOStringFromJSValue(context, OOJS_ARGV[1]);
|
value = OOStringFromJSValue(context, OOJS_ARGV[1]);
|
||||||
}
|
}
|
||||||
|
if (argc > 2 && EXPECT_NOT(!JS_ValueToBoolean(context, OOJS_ARGV[2], &reflow)))
|
||||||
|
{
|
||||||
|
OOJSReportBadArguments(context, @"setMultiFunctionText", @"reflow", argc, OOJS_ARGV, nil, @"boolean");
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
[player setMultiFunctionText:value forKey:key];
|
if (!reflow)
|
||||||
|
{
|
||||||
|
[player setMultiFunctionText:value forKey:key];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GuiDisplayGen *gui = [UNIVERSE gui];
|
||||||
|
NSString *formatted = [gui reflowTextForMFD:value];
|
||||||
|
[player setMultiFunctionText:formatted forKey:key];
|
||||||
|
}
|
||||||
|
|
||||||
OOJS_RETURN_VOID;
|
OOJS_RETURN_VOID;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user