Author Topic: DS2.6 help index menu fix  (Read 1828 times)

Offline Sryth

  • Acquaintance
  • *
  • Posts: 13
    • View Profile
DS2.6 help index menu fix
« on: December 20, 2007, 10:44:02 am »
Pretty much a rewrite of the original file, this goes into /cmds/common

replacement for /cmds/common/help.c

Code: [Select]
/*     /cmds/common/help.c
 *     from the Dead Souls Object Library
 *     created by Descartes of Borg 95/10/21
 *     Version: @(#) help.c 1.3@(#)
 *     Last Modified: 96/12/13
 *     HelpMenu functionality revised by Mourdrydd 07/12/13
 */

#include <lib.h>
#include <daemons.h>
#include <message_class.h>

inherit LIB_DAEMON;

varargs void HelpMenu(string index);

mixed cmd(string arg) {
    object who = previous_object();
    int array screen = (who->GetScreen() || ({ 80, 24 }));
    string help = "";
    string tmp = "";

    if( arg == "help") {
        help = HELP_D->GetHelp("help");
        write(help);
        return 1;
    }
    if( !arg || arg == "") {
        if(creatorp(this_player())) help = read_file("/doc/help/creators/creator_general");
        else help = read_file("/doc/help/players/player_general");
        if(!sizeof(help)) help = HELP_D->GetHelp("help");
        write(help);
        return 1;
    }
    if( arg == "index" || HELP_D->GetTopics(arg) ) {
        if( arg == "index" ) {
            HelpMenu();
            return 1;
        }
        HelpMenu(arg);
        return 1;
    }
    if( !(tmp = HELP_D->GetHelp(arg)) ) {
        return HELP_D->GetLastError();
    }
    help = center(mud_name()+" System Help", screen[0]) + tmp;
    if(sizeof(help) < 2000)    help = wrap(help, screen[0]);
    who->eventPage(explode(help, "\n"), "help");
    return 1;
}

static int CanAccess(object who, string index) {
    return HELP_D->CanAccess(who, index);
}

varargs void HelpMenuNav(string ind, string *inds, int pause) {
    if (!ind) ind = "";
    //begin menu nav portion
    if (pause == 1) {
        message("prompt", "\n\nHit <return> to go back to last index.", this_player());
        input_to(function(string str, string index) { HelpMenu(index); }, ind);
    }
    else {
        if (!ind || ind == "") message("prompt", "\n\nEnter an index or 'q' to quit help: ", this_player());
        else message("prompt", "\n\nEnter a topic, 'q' to quit, or <return> for main menu: ", this_player());

        input_to(function(string menuChoice, string index, string *indices) {
              int *scr = this_player()->GetScreen() || ({ 80, 24 });
              string tmp, msg, header = center(mud_name() + " System Help", scr[0]);
              int error = 0, wait = 0, ind_num;

              //begin possible cases
              if (menuChoice == "q") { //exit help by leaving recursion loop
                  message("system", "Exiting help.", this_player());
                  return;
              }
              if (menuChoice == "0") error = 1;
              else if (!menuChoice || menuChoice == "") index = menuChoice = "";
              //entered a numeric index - convert to appropriate topic string
              else if (ind_num = to_int(menuChoice) ) {
                  if ( ind_num < 1 || ind_num > sizeof(indices) ) error = 1;
                  else menuChoice = indices[ind_num-1];
              }
              if (!error) {
                  //if we were in the main index, try to go to a sub-index
                  if (!index || index == "") index = menuChoice;
                  //otherwise get and display help on the topic in this index
                  else {
                      tmp = HELP_D->GetHelpByIndex(index, menuChoice);
                      wait = 1;
                      if ( tmp ) tmp = header + wrap(tmp, scr[0]);
                    else tmp = HELP_D->GetLastError() + "\nThis subject has no defined help entry.";
                      this_player()->eventPage(explode(tmp, "\n"), "help", (: HelpMenuNav :), index, indices, wait);
                  }
              }
              if (error) {
                  message("help", "Invalid index choice.", this_player());
                  message("prompt", "Hit <return>.", this_player());
                  input_to(function(string str, string ind) { HelpMenu(ind); }, index);
              }
              //recurse to appropriate help menu pane, passing along current index
              else if (wait == 0) HelpMenu(index);
          }, ind, inds);
    }
}

varargs void HelpMenu(string index) {
    string tmp;
    string *indices, *bing;
    int *scr = (this_player()->GetScreen() || ({ 80, 24 }));
    int y = 0, i = 0, error = 0;

    //display portion of this routine
    tmp = center(mud_name() + " System Help", scr[0]);
    //get bad cases out of the way first.
    if (!index || index == "") { //main index.  get topics from the help daemon.
        tmp += "Index: %^GREEN%^main index%^RESET%^\n\n";
        indices = filter(HELP_D->GetIndices(), (: CanAccess(this_player(), $1) :));
    }
    else if ( !HELP_D->CanAccess(this_player(), index) ) { index = ""; error = 1; }
    else { //get topic choices
        if (indices = HELP_D->GetTopics(index))
            tmp += "Index: %^GREEN%^" + index + "%^RESET%^\n\n";
        else error = 1;
    }
    if ( !error ) {
        bing = allocate(sizeof(indices));
        foreach(string topic in indices) {
            int z = strlen(topic) + 6;
            if (z > y) y = z;
            bing[i++] = "[%^CYAN%^" + (i+1) + "%^RESET%^] " + topic;
        }
        tmp += format_page(bing, scr[0]/(y+2));
        //menu choices prepared for display, now.
        this_player()->eventPage(explode(tmp, "\n"), "help", (: HelpMenuNav :), index, indices);
    } //end error if
    else {
        message("help", "Invalid index choice.", this_player());
        message("prompt", "Hit <return>.", this_player());
        input_to(function(string str, string ind) { HelpMenu(ind); }, index);
    }
}

Sryth, Implementor
Afterthoughts: Tangledtapestry
Currently in non-public pre-alpha development.

Offline Archaegeo

  • Acquaintance
  • *
  • Posts: 33
    • View Profile
Re: DS2.6 help index menu fix
« Reply #1 on: December 27, 2007, 07:11:34 am »
Nice fix :)