X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=src%2Fclient%2Fmenu.c;h=b5202d38afe2fb8d8126ac76f688ad5f2e8f9aa0;hb=f14393c85d4c66f34e6d92f8894e170163da1e37;hp=ce3309fc8201c3010494f768fcd1c586a8877a42;hpb=0b5755205d388b5704c040c21285c0b7ab58825e;p=tpg%2Fopendispense2.git diff --git a/src/client/menu.c b/src/client/menu.c index ce3309f..b5202d3 100644 --- a/src/client/menu.c +++ b/src/client/menu.c @@ -14,6 +14,11 @@ #include // getuid #include "common.h" +// === CONSTANTS === +#define COLOURPAIR_DEFAULT 0 +#define COLOURPAIR_CANTBUY 1 +#define COLOURPAIR_SELECTED 2 + // === PROTOTYPES === int ShowItemAt(int Row, int Col, int Width, int Index, int bHilighted); void PrintAlign(int Row, int Col, int Width, const char *Left, char Pad1, const char *Mid, char Pad2, const char *Right, ...); @@ -85,6 +90,11 @@ int ShowNCursesUI(void) // Enter curses mode initscr(); + start_color(); + use_default_colors(); + init_pair(COLOURPAIR_DEFAULT, -1, -1); // Not avaliable + init_pair(COLOURPAIR_CANTBUY, COLOR_BLACK, -1); // Not avaliable + init_pair(COLOURPAIR_SELECTED, COLOR_GREEN, -1); // Selected cbreak(); noecho(); // Get max index @@ -174,7 +184,7 @@ int ShowNCursesUI(void) PrintAlign(yBase+height-1, xBase+1, width-2, username, ' ', balance_str, ' ', gsUserFlags); PrintAlign(yBase+height, xBase+1, width-2, - "q: Quit", ' ', "Arrow: Select", ' ', "Enter: Drop"); + "q: Quit", ' ', "Arrows: Select", ' ', "Enter: Buy"); // Get input @@ -209,7 +219,6 @@ int ShowNCursesUI(void) case 'j': _ItemDown(); break; case 'k': _ItemUp(); break; case 'l': break; - case 0x1b: // Escape case 'q': ret = -1; // -1: Return with no dispense break; @@ -242,6 +251,10 @@ int ShowNCursesUI(void) return ret; } +#define COKE_LABEL "Coke Machine" +#define NCOKESLOTS 7 // slots 0 -- 6 +#define EPS_LABEL "Electronic Payment System" + /** * \brief Show item \a Index at (\a Col, \a Row) * \return Dispense index of item @@ -256,7 +269,6 @@ int ShowItemAt(int Row, int Col, int Width, int Index, int bHilighted) switch(giUIMode) { // Standard UI - // - This assumes that case UI_MODE_STANDARD: // Bounds check // Index = -1, request limit @@ -266,25 +278,25 @@ int ShowItemAt(int Row, int Col, int Width, int Index, int bHilighted) if( Index == 0 ) { price = 0; - name = "Coke Machine"; + name = COKE_LABEL; Index = -1; // -1 indicates a label break; } Index --; // Drinks 0 - 6 - if( Index <= 6 ) + if( Index < NCOKESLOTS ) { name = gaItems[Index].Desc; price = gaItems[Index].Price; status = gaItems[Index].Status; break; } - Index -= 7; + Index -= NCOKESLOTS; // EPS label if( Index == 0 ) { price = 0; - name = "Electronic Payment System"; + name = EPS_LABEL; Index = -1; // -1 indicates a label break; } @@ -294,6 +306,9 @@ int ShowItemAt(int Row, int Col, int Width, int Index, int bHilighted) price = gaItems[Index].Price; status = gaItems[Index].Status; break; + case UI_MODE_BASIC: + case UI_MODE_DRINKSONLY: + case UI_MODE_ALL: default: return -1; } @@ -311,17 +326,29 @@ int ShowItemAt(int Row, int Col, int Width, int Index, int bHilighted) switch( status ) { case 0: - if( bHilighted ) + if( bHilighted ) { + color_set( COLOURPAIR_SELECTED, NULL ); printw("-> "); - else + } + else if( price > giUserBalance ) { + attrset(A_BOLD); + color_set( COLOURPAIR_CANTBUY, NULL ); printw(" "); + } + else { + color_set( 0, NULL ); + printw(" "); + } break; case 1: + attrset(A_BOLD); + color_set( COLOURPAIR_CANTBUY, NULL ); printw("SLD "); break; default: case -1: + color_set( COLOURPAIR_CANTBUY, NULL ); printw("ERR "); break; } @@ -329,6 +356,8 @@ int ShowItemAt(int Row, int Col, int Width, int Index, int bHilighted) printw("%-*.*s", nameWidth, nameWidth, name); printw(" %4i", price); + color_set(0, NULL); + attrset(A_NORMAL); } else { @@ -337,8 +366,8 @@ int ShowItemAt(int Row, int Col, int Width, int Index, int bHilighted) } // If the item isn't availiable for sale, return -1 (so it's skipped) - if( status || (price > giUserBalance && gbDisallowSelectWithoutBalance) ) - Index = -1; + if( status > 0 || (price > giUserBalance && gbDisallowSelectWithoutBalance) ) + Index = -2; return Index; }