+/**
+ */
+int ShowNCursesUI(void)
+{
+ int ch;
+ int i, times;
+ int xBase, yBase;
+ const int displayMinWidth = 34;
+ const int displayMinItems = 8;
+ char *titleString = "Dispense";
+ int titleStringLen = strlen(titleString);
+ int itemCount = displayMinItems;
+ int itemBase = 0;
+
+ int height = itemCount + 3;
+ int width = displayMinWidth;
+
+ // Enter curses mode
+ initscr();
+ raw(); noecho();
+
+ xBase = COLS/2 - width/2;
+ yBase = LINES/2 - height/2;
+
+ for( ;; )
+ {
+ // Header
+ move( yBase, xBase );
+ addch('/');
+ times = width/2 - titleStringLen/2 - 2;
+ while(times --) addch('-');
+ addch(' ');
+ addstr(titleString);
+ addch(' ');
+ times = width/2 - titleStringLen/2 - 2;
+ while(times --) addch('-');
+ addch('\\');
+
+ // Items
+ for( i = 0; i < itemCount; i ++ )
+ {
+ int _x, _y;
+ move( yBase + 1 + i, xBase );
+ addch('|');
+ addch(' ');
+
+ // Check for ... row
+ if( i == 0 && itemBase > 0 ) {
+ printw(" ...");
+ times = width - 1 - 8;
+ while(times--) addch(' ');
+ }
+ else if( i == itemCount - 1 && itemBase < giNumItems - itemCount ) {
+ printw(" ...");
+ times = width - 1 - 8;
+ while(times--) addch(' ');
+ }
+ // Show an item
+ else {
+ if( itemBase + i < 0 || itemBase + i >= giNumItems ) {
+ printw("%02i %i OOR", itemBase + i, i);
+ continue ;
+ }
+ printw("%02i %s", itemBase + i, gaItems[itemBase + i].Desc);
+
+ getyx(stdscr, _y, _x);
+ times = width - 6 - (_x - xBase); // TODO: Better handling for large prices
+ while(times--) addch(' ');
+ printw("%4i ", gaItems[itemBase + i].Price);
+ }
+
+ // Scrollbar (if needed)
+ if( giNumItems > itemCount ) {
+ if( i == 0 ) {
+ addch('A');
+ }
+ else if( i == itemCount - 1 ) {
+ addch('V');
+ }
+ else {
+ int percentage = itemBase * 100 / (giNumItems-itemCount);
+ if( i-1 == percentage*(itemCount-3)/100 ) {
+ addch('#');
+ }
+ else {
+ addch('|');
+ }
+ }
+ }
+ else {
+ addch('|');
+ }
+ }
+
+ // Footer
+ move( yBase + 1 + itemCount, xBase );
+ addch('\\');
+ times = width/2 - titleStringLen/2 - 2;
+ while(times --) addch('-');
+ addch(' ');
+ addstr(titleString);
+ addch(' ');
+ times = width/2 - titleStringLen/2 - 2;
+ while(times --) addch('-');
+ addch('/');
+
+ move( yBase + 1 + itemCount + 1, xBase );
+ {
+ int count = itemCount-2;
+ int ofs = itemBase;
+ if( itemBase == 0 ) count ++;
+ else ofs ++;
+ if( itemBase == giNumItems-itemCount) {
+ count ++;
+ ofs ++;
+ }
+ printw("%i - %i / %i items", itemBase, itemBase+count, giNumItems);
+ }
+
+ ch = getch();
+
+ if( ch == '\x1B' ) {
+ ch = getch();
+ if( ch == '[' ) {
+ ch = getch();
+
+ switch(ch)
+ {
+ case 'B':
+ if( itemBase < giNumItems - (itemCount) )
+ itemBase ++;
+ break;
+ case 'A':
+ if( itemBase > 0 )
+ itemBase --;
+ break;
+ }
+ }
+ else {
+
+ }
+ }
+ else {
+ break;
+ }
+
+ }
+
+
+ // Leave
+ endwin();
+ return -1;
+}
+