Adding support for spacers
authorJohn Hodge <[email protected]>
Sun, 20 Feb 2011 04:01:17 +0000 (12:01 +0800)
committerJohn Hodge <[email protected]>
Sun, 20 Feb 2011 04:01:17 +0000 (12:01 +0800)
src/client/main.c
src/server/itemdb.c

index c5f335b..86b068c 100644 (file)
@@ -441,8 +441,11 @@ int main(int argc, char *argv[])
        {
                // Very basic dispense interface
                for( i = 0; i < giNumItems; i ++ ) {
-                       printf("%2i %s:%i\t%3i %s\n", i, gaItems[i].Type, gaItems[i].ID,
-                               gaItems[i].Price, gaItems[i].Desc);
+                       if( strcmp(gaItems[i].Desc, "-") == 0 )
+                               printf("\n");
+                       else
+                               printf("%2i %s:%i\t%3i %s\n", i, gaItems[i].Type, gaItems[i].ID,
+                                       gaItems[i].Price, gaItems[i].Desc);
                }
                printf(" q Quit\n");
                for(;;)
@@ -602,7 +605,7 @@ int ShowNCursesUI(void)
                                printw("|    ");
                        }
                        
-                       // Check for ... row
+                       // Check for the '...' row
                        // - Oh god, magic numbers!
                        if( i == 0 && itemBase > 0 ) {
                                printw("   ...");
@@ -667,22 +670,38 @@ int ShowNCursesUI(void)
                                        //      itemBase ++;
                                        if( currentItem < giNumItems - 1 )
                                                currentItem ++;
-                                       if( itemBase + itemCount - 1 <= currentItem && itemBase + itemCount < giNumItems )
-                                               itemBase ++;
+                                       else {
+                                               currentItem = 0;
+                                       }
                                        break;
                                case 'A':
                                        //if( itemBase > 0 )
                                        //      itemBase --;
                                        if( currentItem > 0 )
                                                currentItem --;
-                                       if( itemBase + 1 > currentItem && itemBase > 0 )
-                                               itemBase --;
+                                       else {
+                                               currentItem = giNumItems - 1;
+                                       }
                                        break;
                                }
                        }
                        else {
                                
                        }
+                       
+                       if( currentItem < itemBase + 1 && itemBase > 0 )
+                               itemBase = currentItem - 1;
+                       if( currentItem > itemBase + itemCount - 1 && itemBase < itemCount-1 )
+                               itemBase = currentItem - itemCount + 1;
+                       
+                       #if 0
+                       if( itemBase + itemCount - 1 <= currentItem && itemBase + itemCount < giNumItems )
+                       {
+                               itemBase += ;
+                       }
+                       if( itemBase + 1 > currentItem && itemBase > 0 )
+                               itemBase --;
+                       #endif
                }
                else {
                        switch(ch)
@@ -727,6 +746,12 @@ void ShowItemAt(int Row, int Col, int Width, int Index)
                name = gaItems[Index].Desc;
                price = gaItems[Index].Price;
        }
+       
+       // Spacer hack (Desc = "-")
+       if( gaItems[Index].Desc[0] == '-' && gaItems[Index].Desc[1] == '\0' )
+       {
+               return;
+       }
 
        printw("%02i %s", Index, name);
        
index e503123..56de248 100644 (file)
@@ -33,7 +33,8 @@ char  *trim(char *__str);
  int   giNumItems = 0;
 tItem  *gaItems = NULL;
 tHandler       gPseudo_Handler = {Name:"pseudo"};
-tHandler       *gaHandlers[] = {&gPseudo_Handler, &gCoke_Handler, &gSnack_Handler, &gDoor_Handler};
+tHandler       gSpacer_Handler = {Name:"spacer"};
+tHandler       *gaHandlers[] = {&gSpacer_Handler, &gPseudo_Handler, &gCoke_Handler, &gSnack_Handler, &gDoor_Handler};
  int   giNumHandlers = sizeof(gaHandlers)/sizeof(gaHandlers[0]);
 char   *gsItemListFile = DEFAULT_ITEM_FILE;
 #if USE_INOTIFY
@@ -93,7 +94,7 @@ void Load_Itemlist(void)
        regex_t regex;
        regmatch_t      matches[5];
        
-       i = regcomp(&regex, "^-?([a-zA-Z][a-zA-Z0-9]*)\\s+([0-9]+)\\s+([0-9]+)\\s+(.*)", REG_EXTENDED);
+       i = regcomp(&regex, "^-?([a-zA-Z][a-zA-Z]*)\\s+([0-9]+)\\s+([0-9]+)\\s+(.*)", REG_EXTENDED);
        if( i )
        {
                size_t  len = regerror(i, &regex, NULL, 0);

UCC git Repository :: git.ucc.asn.au