From 1f33d46c9e15e5309d67a409d3c5cacd2c9d4daf Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 20 Feb 2011 12:01:17 +0800 Subject: [PATCH] Adding support for spacers --- src/client/main.c | 39 ++++++++++++++++++++++++++++++++------- src/server/itemdb.c | 5 +++-- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/client/main.c b/src/client/main.c index c5f335b..86b068c 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -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); diff --git a/src/server/itemdb.c b/src/server/itemdb.c index e503123..56de248 100644 --- a/src/server/itemdb.c +++ b/src/server/itemdb.c @@ -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(®ex, "^-?([a-zA-Z][a-zA-Z0-9]*)\\s+([0-9]+)\\s+([0-9]+)\\s+(.*)", REG_EXTENDED); + i = regcomp(®ex, "^-?([a-zA-Z][a-zA-Z]*)\\s+([0-9]+)\\s+([0-9]+)\\s+(.*)", REG_EXTENDED); if( i ) { size_t len = regerror(i, ®ex, NULL, 0); -- 2.20.1