Added help/del to the state-help system, made some appearance tweaks on the examples.

This commit is contained in:
Griatch 2009-05-02 08:55:12 +00:00
parent fd050f75ca
commit 5bc1db70ed
2 changed files with 35 additions and 13 deletions

View file

@ -53,8 +53,8 @@ def cmd_entermenu(command):
# and clear_state(), the latter returns the player to
# the normal mode of gameplay.
source_object.set_state(STATENAME)
#display the menu.
print_menu(source_object)
#show the menu.
source_object.execute_cmd('menu')
#
# Commands only available while in the 'menu' state. Note that
@ -64,23 +64,24 @@ def cmd_entermenu(command):
def menu_cmd_option1(command):
"""
option1
This selects the first option.
This command, obviously, selects the first option.
"""
source_object = command.source_object
print_menu(source_object, 1)
def menu_cmd_option2(command):
"""
option2
This selects the second option. Duh.
<<TOPIC:About>>
This is an extra topic to test the auto_help functionality.
This command selects the second option. Duh.
"""
source_object = command.source_object
print_menu(source_object, 2)
def menu_cmd_clear(command):
def menu_cmd_menu(command):
"""
clear
Clears the options.
menu
Clears the options and redraws the menu.
<<TOPIC:autohelp>>
This is an extra topic to test the auto-help functionality. The state-help
system supports nested ('related') topics just like the normal help index does.
"""
source_object = command.source_object
print_menu(source_object)
@ -100,11 +101,9 @@ def print_menu(source_obj,choice=None):
else:
ch = " %soption1\n option2" % ('%cn%cy')
s ="%sMenu---------\n%s\n %shelp - get help" % ('%ch%cr',ch,'%cn%cy')
s ="%sMenu: \n%s\n %shelp" % ('%ch%cr',ch,'%cn%cy')
source_obj.emit_to(s)
#Add the 'entry' command to the normal command table
GLOBAL_CMD_TABLE.add_command("entermenu", cmd_entermenu)
@ -114,4 +113,4 @@ GLOBAL_CMD_TABLE.add_command("entermenu", cmd_entermenu)
#while in the menu.
GLOBAL_STATE_TABLE.add_command(STATENAME, "option1", menu_cmd_option1,auto_help=True)
GLOBAL_STATE_TABLE.add_command(STATENAME, "option2", menu_cmd_option2,auto_help=True)
GLOBAL_STATE_TABLE.add_command(STATENAME, "clear", menu_cmd_clear,auto_help=True)
GLOBAL_STATE_TABLE.add_command(STATENAME, "menu", menu_cmd_menu,auto_help=True)

View file

@ -146,6 +146,16 @@ class StateHelpIndex(object):
else:
self.help_index[state][command] = (staff_only, text)
def del_state_help(self, state, topic):
"""Manually delete an help topic from state help system. Note that this is
only going to last until the next @reload unless you also turn off auto_help
for the relevant topic."""
if self.help_index.has_key(state) and self.help_index[state].has_key(topic):
del self.help_index[state][topic]
return True
else:
return False
def get_state_help(self,caller, state, command):
"get help for a particular command within a state"
if self.help_index.has_key(state) and self.help_index[state].has_key(command):
@ -204,6 +214,8 @@ def cmd_state_help(command):
source_object = command.source_object
state = source_object.get_state()
args = command.command_argument
switches = command.command_switches
help_index = GLOBAL_STATE_TABLE.help_index
if not args:
@ -219,6 +231,17 @@ def cmd_state_help(command):
return
else:
args = args.strip()
if 'del' in switches:
if not source_object.is_staff():
source_object.emit_to("Only staff can delete help topics.")
return
if help_index.del_state_help(state,args):
source_object.emit_to("Topic %s deleted." % args)
else:
source_object.emit_to("Topic %s not found." % args)
return
help = help_index.get_state_help(source_object, state, args)
if help:
source_object.emit_to("%s" % help)