improve tutorial mode

This commit is contained in:
chrys 2017-07-16 16:10:37 +02:00
parent 6173fe8a4d
commit 5d45d806c1
6 changed files with 40 additions and 42 deletions

View File

@ -122,7 +122,7 @@ driver=vcsaDriver
encoding=cp850 encoding=cp850
screenUpdateDelay=0.05 screenUpdateDelay=0.05
suspendingScreen= suspendingScreen=
autodetectSuspendingScreen=True autodetectSuspendingScreen=False
[keyboard] [keyboard]
driver=evdevDriver driver=evdevDriver

View File

@ -1,28 +0,0 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from core import debug
class command():
def __init__(self):
pass
def initialize(self, environment):
self.env = environment
def shutdown(self):
pass
def getDescription(self):
return _('Toggle the Tutorial mode')
def run(self):
text = ''
if self.env['runtime']['helpManager'].isTutorialMode():
text = _('You are leaving the tutorial mode. Press that shortcut again to enter the tutorial mode again.')
else:
text = _('you entered the tutorial mode. In that mode the commands are not executed. but you get a description of what the shortcut does. To leave the tutorial mode, press that shortcut again.')
self.env['runtime']['helpManager'].toggleTutorialMode()
self.env['runtime']['outputManager'].presentText(text, interrupt=True)
def setCallback(self, callback):
pass

View File

@ -181,7 +181,7 @@ class commandManager():
return return
if self.commandExists(command, section): if self.commandExists(command, section):
try: try:
if self.env['runtime']['helpManager'].isTutorialMode(): if self.env['runtime']['helpManager'].isTutorialMode() and section != 'help':
self.env['runtime']['debug'].writeDebugOut("Tutorial for command:" + section + "." + command ,debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut("Tutorial for command:" + section + "." + command ,debug.debugLevel.INFO)
description = self.getCommandDescription(command, section) description = self.getCommandDescription(command, section)
self.env['runtime']['outputManager'].presentText(description, interrupt=True) self.env['runtime']['outputManager'].presentText(description, interrupt=True)

View File

@ -54,9 +54,9 @@ class fenrirManager():
startTime = time.time() startTime = time.time()
if eventReceived: if eventReceived:
self.prepareCommand() self.prepareCommand()
if not self.environment['runtime']['screenManager'].isSuspendingScreen(): #if not self.environment['runtime']['screenManager'].isSuspendingScreen():
if self.environment['runtime']['helpManager'].handleTutorialMode(): # if self.environment['runtime']['helpManager'].handleTutorialMode():
self.wasCommand = True # self.wasCommand = True
if not (self.wasCommand or self.environment['runtime']['helpManager'].isTutorialMode()) or self.environment['runtime']['screenManager'].isSuspendingScreen(): if not (self.wasCommand or self.environment['runtime']['helpManager'].isTutorialMode()) or self.environment['runtime']['screenManager'].isSuspendingScreen():
self.environment['runtime']['inputManager'].writeEventBuffer() self.environment['runtime']['inputManager'].writeEventBuffer()
if self.environment['runtime']['inputManager'].noKeyPressed(): if self.environment['runtime']['inputManager'].noKeyPressed():
@ -70,7 +70,7 @@ class fenrirManager():
self.environment['input']['keyForeward'] -=1 self.environment['input']['keyForeward'] -=1
#self.environment['runtime']['screenManager'].update('onInput') #self.environment['runtime']['screenManager'].update('onInput')
self.environment['runtime']['commandManager'].executeDefaultTrigger('onInput') self.environment['runtime']['commandManager'].executeDefaultTrigger('onInput')
self.handleCommands() self.handleCommands()
def handleScreenChange(self): def handleScreenChange(self):
self.environment['runtime']['screenManager'].update('onScreenChange') self.environment['runtime']['screenManager'].update('onScreenChange')
''' '''
@ -116,19 +116,21 @@ class fenrirManager():
if self.environment['input']['keyForeward'] > 0: if self.environment['input']['keyForeward'] > 0:
return return
shortcut = self.environment['runtime']['inputManager'].getCurrShortcut() shortcut = self.environment['runtime']['inputManager'].getCurrShortcut()
command = self.environment['runtime']['inputManager'].getCommandForShortcut(shortcut) command = self.environment['runtime']['inputManager'].getCommandForShortcut(shortcut)
if len(self.environment['input']['prevDeepestInput']) <= len(self.environment['input']['currInput']): if len(self.environment['input']['prevDeepestInput']) >= len(self.environment['input']['currInput']):
self.wasCommand = command != '' or self.environment['runtime']['inputManager'].isFenrirKeyPressed() or self.environment['runtime']['inputManager'].isScriptKeyPressed() self.wasCommand = command != '' or self.environment['runtime']['inputManager'].isFenrirKeyPressed() or self.environment['runtime']['inputManager'].isScriptKeyPressed()
if command == '': if command == '':
return return
self.environment['runtime']['commandManager'].queueCommand(command) self.environment['runtime']['commandManager'].queueCommand(command)
def handleCommands(self): def handleCommands(self):
if not self.environment['runtime']['commandManager'].isCommandQueued(): if not self.environment['runtime']['commandManager'].isCommandQueued():
return return
if len(self.environment['input']['prevDeepestInput']) > len(self.environment['input']['currInput']):
return
if self.environment['runtime']['helpManager'].isTutorialMode():
self.environment['runtime']['commandManager'].executeCommand( self.environment['commandInfo']['currCommand'], 'help')
self.environment['runtime']['commandManager'].executeCommand( self.environment['commandInfo']['currCommand'], 'commands') self.environment['runtime']['commandManager'].executeCommand( self.environment['commandInfo']['currCommand'], 'commands')
def shutdownRequest(self): def shutdownRequest(self):
self.environment['runtime']['eventManager'].stopMainEventLoop() self.environment['runtime']['eventManager'].stopMainEventLoop()

View File

@ -14,13 +14,26 @@ class helpManager():
def initialize(self, environment): def initialize(self, environment):
self.env = environment self.env = environment
self.createHelpDict() self.createHelpDict()
def shutdown(self): def shutdown(self):
pass pass
def toggleTutorialMode(self): def toggleTutorialMode(self):
self.setTutorialMode(not self.env['general']['tutorialMode']) self.setTutorialMode(not self.env['general']['tutorialMode'])
def setTutorialMode(self, newTutorialMode): def setTutorialMode(self, newTutorialMode):
self.env['general']['tutorialMode'] = newTutorialMode self.env['general']['tutorialMode'] = newTutorialMode
if newTutorialMode:
self.createHelpDict()
self.env['bindings'][str([1, ['KEY_ESC']])] = 'TOGGLE_TUTORIAL_MODE'
self.env['bindings'][str([1, ['KEY_UP']])] = 'PREV_HELP'
self.env['bindings'][str([1, ['KEY_DOWN']])] = 'NEXT_HELP'
self.env['bindings'][str([1, ['KEY_SPACE']])] = 'CURR_HELP'
else:
try:
del(self.env['bindings'][str([1, ['KEY_ESC']])])
del(self.env['bindings'][str([1, ['KEY_UP']])])
del(self.env['bindings'][str([1, ['KEY_DOWN']])])
del(self.env['bindings'][str([1, ['KEY_SPACE']])])
except:
pass
def isTutorialMode(self): def isTutorialMode(self):
return self.env['general']['tutorialMode'] return self.env['general']['tutorialMode']
def getCommandHelpText(self, command, section = 'commands'): def getCommandHelpText(self, command, section = 'commands'):
@ -28,11 +41,17 @@ class helpManager():
commandName = commandName.split('__-__')[0] commandName = commandName.split('__-__')[0]
commandName = commandName.replace('_',' ') commandName = commandName.replace('_',' ')
commandName = commandName.replace('_',' ') commandName = commandName.replace('_',' ')
commandDescription = self.env['runtime']['commandManager'].getCommandDescription( command, section = 'commands') if command == 'TOGGLE_TUTORIAL_MODE':
commandDescription = _('toggles the tutorial mode')
else:
commandDescription = self.env['runtime']['commandManager'].getCommandDescription( command, section = 'commands')
if commandDescription == '': if commandDescription == '':
commandDescription = 'no Description available' commandDescription = 'no Description available'
commandShortcut = self.env['runtime']['commandManager'].getShortcutForCommand( command) commandShortcut = self.env['runtime']['commandManager'].getShortcutForCommand( command)
commandShortcut = commandShortcut.replace('KEY_',' ') commandShortcut = commandShortcut.replace('KEY_',' ')
commandShortcut = commandShortcut.replace('[','')
commandShortcut = commandShortcut.replace(']','')
commandShortcut = commandShortcut.replace("'",'')
if commandShortcut == '': if commandShortcut == '':
commandShortcut = 'unbound' commandShortcut = 'unbound'
helptext = commandName + ', Shortcut ' + commandShortcut + ', Description ' + commandDescription helptext = commandName + ', Shortcut ' + commandShortcut + ', Description ' + commandDescription
@ -43,6 +62,8 @@ class helpManager():
self.helpDict[len(self.helpDict)] = self.getCommandHelpText(command, section) self.helpDict[len(self.helpDict)] = self.getCommandHelpText(command, section)
if len(self.helpDict) > 0: if len(self.helpDict) > 0:
self.tutorialListIndex = 0 self.tutorialListIndex = 0
else:
self.tutorialListIndex = None
def getHelpForCurrentIndex(self): def getHelpForCurrentIndex(self):
if self.tutorialListIndex == None: if self.tutorialListIndex == None:
return '' return ''
@ -60,6 +81,7 @@ class helpManager():
if self.tutorialListIndex < 0: if self.tutorialListIndex < 0:
self.tutorialListIndex = len(self.helpDict) - 1 self.tutorialListIndex = len(self.helpDict) - 1
def handleTutorialMode(self): def handleTutorialMode(self):
return
if self.env['runtime']['inputManager'].noKeyPressed(): if self.env['runtime']['inputManager'].noKeyPressed():
return return
if self.env['input']['currInput'] in [['KEY_F1', 'KEY_FENRIR']]: if self.env['input']['currInput'] in [['KEY_F1', 'KEY_FENRIR']]:

View File

@ -70,8 +70,10 @@ class settingsManager():
self.env['runtime']['debug'].writeDebugOut("invalid shortcut (missing KEY_FENRIR): "+ str(shortcut) + ' command:' +commandName ,debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut("invalid shortcut (missing KEY_FENRIR): "+ str(shortcut) + ' command:' +commandName ,debug.debugLevel.ERROR)
continue continue
self.env['runtime']['debug'].writeDebugOut("Shortcut: "+ str(shortcut) + ' command:' +commandName ,debug.debugLevel.INFO, onAnyLevel=True) self.env['runtime']['debug'].writeDebugOut("Shortcut: "+ str(shortcut) + ' command:' +commandName ,debug.debugLevel.INFO, onAnyLevel=True)
self.env['bindings'][str(shortcut)] = commandName self.env['bindings'][str(shortcut)] = commandName
kbConfig.close() kbConfig.close()
# fix bindings
self.env['bindings'][str([1, ['KEY_F1', 'KEY_FENRIR']])] = 'TOGGLE_TUTORIAL_MODE'
def loadSoundIcons(self, soundIconPath): def loadSoundIcons(self, soundIconPath):
siConfig = open(soundIconPath + '/soundicons.conf',"r") siConfig = open(soundIconPath + '/soundicons.conf',"r")