Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
Quasar

Menu Search Feature

Recommended Posts

I've added a console command (and corresponding item on the menus) which allows you to enter a term and then search for occurances of it within the other menus. The next result is returned each time until all matches have been exhausted. The search then gets reset so you can start over if you wish.

I pasted the code just to make this post longer and to piss off people who hate code ^_^ I figured some of you like Joel might be interested to see what was involved in adding such a potentially useful feature.

CONSOLE_COMMAND(mn_search, 0)
{
   int i = 0;
   menu_t *curMenu;
   boolean pastLast;

   // if lastMatch is set, set pastLast to false so that we'll seek
   // forward until we pass the last item that was matched
   pastLast = !lastMatch;

   if(!mn_searchstr || !mn_searchstr[0])
   {
      MN_ErrorMsg("invalid search string");
      return;
   }

   M_Strlwr(mn_searchstr);

   // run through every menu in the search list...
   while((curMenu = mn_search_menus[i++]))
   {
      menu_t *curPage = curMenu;

      // run through every page of the menu
      while(curPage)
      {
         int j = 0;
         menuitem_t *item; 

         // run through items
         while((item = &(curPage->menuitems[j++])))
         {
            char *desc;

            if(item->type == it_end)
               break;

            if(!item->description)
               continue;

            // keep seeking until we pass the last item found
            if(item == lastMatch)
            {
               pastLast = true;
               continue;
            }            
            if(!pastLast)
               continue;

            desc = M_Strlwr(strdup(item->description));

            // found a match
            if(strstr(desc, mn_searchstr))
            {
               // go to it
               lastMatch = item;
               MN_StartMenu(curPage);
               MN_ErrorMsg("found: %s", desc);
               if(!is_a_gap(item))
                  curPage->selected = j - 1;
               free(desc);
               return;
            }
            free(desc);
         }

         curPage = curPage->nextpage;
      }
   }

   if(lastMatch) // if doing a valid search, reset it now
   {
      lastMatch = NULL;
      MN_ErrorMsg("reached end of search");
   }
   else
      MN_ErrorMsg("no match found for '%s'", mn_searchstr);
}

Share this post


Link to post
Quasar said:

I pasted the code just to make this post longer and to piss off people who hate code ^_^



haha! Nice :)

Share this post


Link to post

you know you need to redesign your menus when:

1) You need a search function to find stuff in them.

Share this post


Link to post

The menus have already BEEN redesigned; in fact they are now 99.9% finished. The search function is there for two reasons:

1) I NEVER want to hear "I can't find so-and-so in the menus" again in my life, no matter what.

2) To ease the transition now that many things have been moved around to more logical places.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×