/** Starts all the subscreens of the game */ int engine_windows_init() { window_s w; screen_s* s = &(engine.screen); int main_x = 0; int main_y = 0; if (global.screen_center_horizontally) main_x = engine.screen.width/2 - 80/2; if (global.screen_center_vertically) main_y = engine.screen.height/2 - 24/2; /* main window, wrapper of all others */ w.width = 80; w.height = 24; w.x = main_x; w.y = main_y; w.win = newwin(w.height, w.width, w.y, w.x); if (global.screen_show_outer_border) { if (global.screen_fancy_borders) window_fancy_borders(w.win); else window_normal_borders(w.win); } wnoutrefresh(w.win); s->main = w; /* leftmost */ w.width = 6 * 2 + 2; w.height = s->main.height - 2; /* borders */ w.x = 2; w.y = 1; w.win = derwin(s->main.win, w.height, w.width, w.y, w.x); if (global.screen_fancy_borders) { window_fancy_borders(w.win); /* If the player has no hold, doesnt make sense printing these parts */ if (global.game_can_hold) { /* making the top line between hold and score windows */ mvwaddch(w.win, 5, 0, ACS_LLCORNER|COLOR_PAIR(WHITE_BLACK)); my_mvwhline(w.win, 5, 1, ACS_HLINE|COLOR_PAIR(BLACK_BLACK)|A_BOLD, w.width - 2); mvwaddch(w.win, 5, w.width - 1, ACS_LRCORNER|COLOR_PAIR(BLACK_BLACK)|A_BOLD); /* making the bottom line between hold and score windows */ mvwaddch(w.win, 6, 0, ACS_ULCORNER|COLOR_PAIR(WHITE_BLACK)|A_BOLD); my_mvwhline(w.win, 6, 1, ACS_HLINE|COLOR_PAIR(WHITE_BLACK), w.width - 2); mvwaddch(w.win, 6, w.width - 1, ACS_URCORNER|COLOR_PAIR(WHITE_BLACK)); } } else { window_normal_borders(w.win); wattrset(w.win, engine_get_color(COLOR_BLACK, COLOR_BLACK, true)); mvwhline(w.win, 5, 1, '-', w.width - 2); } wnoutrefresh(w.win); s->leftmost = w; /* middle-left */ w.width = 10 * 2 + 2; w.height = s->main.height - 2; /* borders */ w.x = s->leftmost.x + s->leftmost.width + 1; w.y = 1; w.win = derwin(s->main.win, w.height, w.width, w.y, w.x); if (global.screen_fancy_borders) window_fancy_borders(w.win); else window_normal_borders(w.win); wnoutrefresh(w.win); s->middle_left = w; /* middle-right */ w.width = 4 * 2 + 2; w.height = s->main.height - 2; /* borders */ w.x = s->middle_left.x + s->middle_left.width + 1; w.y = 1; w.win = derwin(s->main.win, w.height, w.width, w.y, w.x); if (global.screen_fancy_borders) { window_fancy_borders(w.win); /* making the top line between 1st next and the rest */ mvwaddch(w.win, 3, 0, ACS_LLCORNER|COLOR_PAIR(WHITE_BLACK)); mvwhline(w.win, 3, 1, ACS_HLINE|COLOR_PAIR(BLACK_BLACK)|A_BOLD, w.width - 2); mvwaddch(w.win, 3, w.width - 1, ACS_LRCORNER|COLOR_PAIR(BLACK_BLACK)|A_BOLD); /* making the bottom line between 1st next and the rest */ mvwaddch(w.win, 4, 0, ACS_ULCORNER|COLOR_PAIR(WHITE_BLACK)|A_BOLD); mvwhline(w.win, 4, 1, ACS_HLINE|COLOR_PAIR(WHITE_BLACK), w.width - 2); mvwaddch(w.win, 4, w.width - 1, ACS_URCORNER|COLOR_PAIR(WHITE_BLACK)); } else { window_normal_borders(w.win); wattrset(w.win, engine_get_color(COLOR_BLACK, COLOR_BLACK, true)); mvwhline(w.win, 3, 1, '-', w.width - 2); } wnoutrefresh(w.win); s->middle_right = w; /* right-most */ w.width = s->main.width - (s->middle_right.x + s->middle_right.width) - 3; w.height = s->main.height - 2; /* borders */ w.x = s->middle_right.x + s->middle_right.width + 1; w.y = 1; w.win = derwin(s->main.win, w.height, w.width, w.y, w.x); if (global.screen_fancy_borders) window_fancy_borders(w.win); else window_normal_borders(w.win); wnoutrefresh(w.win); s->rightmost = w; /* next pieces */ w.width = s->middle_right.width - 2; w.height = s->middle_right.height - 2; w.x = 1; w.y = 1; w.win = derwin(s->middle_right.win, w.height, w.width, w.y, w.x); wnoutrefresh(w.win); s->next_container = w; /* first next piece */ w.width = s->next_container.width; w.height = 2; w.x = 0; w.y = 0; w.win = derwin(s->next_container.win, w.height, w.width, w.y, w.x); wnoutrefresh(w.win); s->next[0] = w; /* the rest */ int i; int y_offset = 2; for (i = 1; i <= global.game_next_no; i++) { /* making all the next pieces 1 line lower */ if (i != 1) y_offset = 0; w.width = s->next_container.width; w.height = 2; w.x = 0; w.y = s->next[i - 1].y + s->next[i - 1].height + 1 + y_offset; w.win = derwin(s->next_container.win, w.height, w.width, w.y, w.x); wnoutrefresh(w.win); s->next[i] = w; } s->board = new_sub_win_from(s->middle_left.win, (s->middle_left.width - 2), (s->middle_left.height - 2), 1, 1); s->info = new_sub_win_from(s->rightmost.win, (s->rightmost.width - 4), (s->rightmost.height - 2), 2, 1); s->leftmost_container = new_sub_win_from(s->leftmost.win, (s->leftmost.width - 2), (s->leftmost.height - 2), 1, 1); s->hold = new_sub_win_from(s->leftmost_container.win, s->leftmost_container.width, 4, 0, 0); s->score = new_sub_win_from(s->leftmost_container.win, s->leftmost_container.width, s->leftmost_container.height - (s->hold.height) - 2, 0, s->hold.y + s->hold.height + 2); /* w.width = s->leftmost_container.width; */ /* w.height = s->leftmost_container.height - (s->hold.height) - 2; */ /* w.x = 0; */ /* w.y = s->hold.y + s->hold.height + 2; */ /* w.win = derwin(s->leftmost_container.win, w.height, w.width, w.y, w.x); */ /* wnoutrefresh(w.win); */ /* s->score = w; */ w = s->info; wattrset(w.win, engine_get_color(COLOR_WHITE, COLOR_BLACK, true)); mvwaddstr(w.win, w.height - 1, 16 , "Loading"); wnoutrefresh(w.win); return 1; }
void shNCursesMenu::accumulateResults () { const int map_end = 64; /* column map ends */ WINDOW *win, *helpwin = NULL; PANEL *panel, *helppanel = NULL; int helplines; free (prepareHelp (&helplines)); /* Two additional lines besides all the choices are the menu title and --End-- or --More-- at the bottom. */ mItemHeight = mini (mHeight - helplines, mChoices.count () + 2); int width = 10; int gap = 0; /* Used to position the menu. */ for (int i = 0; i < mChoices.count (); ++i) { width = maxi (width, strlen (mChoices.get (i)->mText) + 1); } if (!(mFlags & kNoPick)) width += 10; /* Adjust for "( ) x - " prompts. */ /* Main header might be still longer. */ width = maxi (width, strlen (mPrompt) + 2); if (mFlags & kCategorizeObjects) { /* Do not center item lists. */ /* Determine whether window can leave sidebar unobscured. */ if (width <= map_end) { /* Yes! */ width = map_end; } else { /* No, so hide it whole. */ width = mWidth; } } else { width = mini (mWidth, width); if (width > map_end) { /* Would obscure side bar window? */ width = mWidth; /* Then cover it whole. */ } else { /* Place small gap between sidebar and menu if possible. */ gap = mini (10, (map_end - width) / 2); } } win = newwin (mItemHeight, width, 0, maxi (0, map_end - width) - gap); if (!win) { debug.log ("Unable to create window (%d, %d, %d, %d)", mItemHeight, width, 0, maxi (0, map_end - width)); I->p ("Uh oh! Couldn't create window!!"); mDone = 1; return; } keypad (win, TRUE); panel = new_panel (win); if (helplines) { helpwin = newwin (helplines, 80, mHeight - helplines, 0); if (!helpwin) { debug.log ("Unable to create help window (%d, %d, %d, %d)", helplines, 80, mHeight - helplines, 0); I->p ("Uh oh! Couldn't create help window!!"); mDone = 1; return; } helppanel = new_panel (helpwin); showHelp (helpwin); } /* -2 lines to make space for header and --End-- or similar. */ mLast = mini (mOffset + mItemHeight - 2, mChoices.count ()); while (1) { /* Menu loop. */ /* Menu header: */ wattrset (win, A_BOLD); mvwaddnstr (win, 0, 1, mPrompt, width); wclrtoeol (win); wattrset (win, A_NORMAL); int i; for (i = mOffset; i < mLast; ++i) { /* First, clear line. */ wmove (win, 1 + i - mOffset, 0); wclrtoeol (win); /* Then draw. */ char buf[100]; shMenuChoice *item = mChoices.get (i); if (item->mLetter >= 0 and (shMenu::kCategorizeObjects & mFlags) and ((shObject *) item->mValue.mPtr)->isKnownRadioactive ()) { wattrset (win, ColorMap[kGreen]); } if (-2 == item->mLetter) { /* This is a pretty delimiter. */ int len = strlen (item->mText); int j = (width - len) / 2; char *spaces = GetBuf (); for (int i = 0; i < j; ++i) { spaces[i] = ' '; } spaces[j] = '\0'; snprintf (buf, 100, "%s%s%s", spaces, item->mText, spaces); } else if (-1 == item->mLetter) { /* This is a header entry. */ if (kCategorizeObjects & mFlags and mFlags & kMultiPick) { /* Get category header. */ char part[50]; snprintf (part, 50, " %s ", item->mText); char *gap = strstr (part, " "); /* Find gap. */ gap[1] = 0; /* Truncate. */ wattrset (win, A_REVERSE); mvwaddnstr (win, 1 + i - mOffset, 1, part, width); /* Get (toggle all with X) part. */ char *p2 = strstr (item->mText, "(t"); int len = strlen (p2); snprintf (part, len-2, "%s", item->mText); wattrset (win, ColorMap[kBlue]); mvwaddnstr (win, 1 + i - mOffset, width-21, p2, width); /* The toggle key should stand out. */ snprintf (buf, len - 1, "%c", p2[len - 2]); mvwaddch (win, 1 + i - mOffset, width-21+len-2, p2[len - 2] | ColorMap[kWhite]); buf[0] = 0; /* Printing is done. */ } else { wattrset (win, A_REVERSE); snprintf (buf, 100, " %s ", item->mText); } } else if (mFlags & kNoPick) { if (' ' == item->mLetter) { snprintf (buf, 100, "%s", item->mText); } else { snprintf (buf, 100, "%c - %s", item->mLetter, item->mText); } } else { if (' ' == item->mLetter) { snprintf (buf, 100, " %s", item->mText); } else if (mFlags & kShowCount) { if (item->mSelected) { snprintf (buf, 100, "(%d) %c - %s", item->mSelected, item->mLetter, item->mText); } else { snprintf (buf, 100, "( ) %c - %s", item->mLetter, item->mText); } } else { snprintf (buf, 100, "(%c) %c - %s", 0 == item->mSelected ? ' ' : item->mCount == item->mSelected ? 'X' : '#', item->mLetter, item->mText); } } mvwaddnstr (win, 1 + i - mOffset, 1, buf, width); wattrset (win, A_NORMAL); } mvwaddnstr (win, 1 + i - mOffset, 1, bottomLine (i), width); while (1) { if (helplines) { showHelp (helpwin); touchwin (helpwin); } update_panels (); doupdate(); int key = I->getChar (); if (27 == key or 13 == key or ' ' == key) { /* done */ mDone = 1; break; } else if (KEY_BACKSPACE == key) { interpretKey (0, shInterface::kDrop); break; } else if (KEY_HOME == key or KEY_A1 == key) { interpretKey (0, shInterface::kMoveNW); break; } else if (KEY_END == key or KEY_C1 == key) { interpretKey (0, shInterface::kMoveSW); break; } else if (KEY_UP == key) { interpretKey (0, shInterface::kMoveUp); break; } else if (KEY_DOWN == key) { interpretKey (0, shInterface::kMoveDown); break; } else if (KEY_PPAGE == key or KEY_LEFT == key or KEY_A3 == key) { interpretKey (0, shInterface::kMoveNE); break; } else if (KEY_NPAGE == key or KEY_RIGHT == key or KEY_C3 == key) { interpretKey (0, shInterface::kMoveSE); break; } else if ('\t' == key and mHelpFileName) { /* invoke help */ interpretKey (0, shInterface::kHelp); break; } else if (mFlags & kNoPick) { continue; } else { if (interpretKey (key)) break; } if (mDone) break; } if (mDone) break; } /* Clean up. */ hide_panel (panel); del_panel (panel); delwin (win); if (helplines) { hide_panel (helppanel); del_panel (helppanel); delwin (helpwin); } update_panels (); I->drawScreen (); }
void help(int scr) { int v,k; char s[200][100]; strcpy (s[0],"COMMAND LINE"); strcpy (s[1]," -p : play"); strcpy (s[2]," --nocolors : B&W, for dummy terminals (telnet)"); strcpy (s[3]," --autoscr : autodetect the screen's size (BETA)"); strcpy (s[4]," --fakelines : draw lines on terminals without ACS"); strcpy (s[5]," --new_start : start with default configuration"); strcpy (s[6],""); strcpy (s[7],"PLAYER"); strcpy (s[8]," z : previous"); strcpy (s[9]," x : play"); strcpy (s[10]," c : pause"); strcpy (s[11]," v : stop"); strcpy (s[12]," b : next"); strcpy (s[13]," s : Shuffle On/Off"); strcpy (s[14]," <ENTER> : Play "); strcpy (s[15]," <SPACE BAR> : Set As Next "); strcpy (s[16]," <TAB> : Add/Remove to/from filter "); strcpy (s[17]," f : On/Off persistent filter "); strcpy (s[18]," F : Clear filter "); strcpy (s[19]," <LEFT> : Backward"); strcpy (s[20]," <RIGHT> : Forward"); strcpy (s[21]," r : Repreat current song "); strcpy (s[22]," i : ID3v1.1 TAG Editor (for selected song)"); strcpy (s[23]," I : ID3v1.1 TAG Editor (for current song))"); strcpy (s[24]," j or F3 : Jump to file"); strcpy (s[25]," <INSERT> : Volume + "); strcpy (s[26]," <DELETE> : Volume - "); strcpy (s[27]," <HOME> : PCM + "); strcpy (s[28]," <END> : PCM - "); strcpy (s[29]," < : Balance left "); strcpy (s[30]," > : Balance right "); strcpy (s[31]," e : Equalizer"); strcpy (s[32]," ' : Repaint Desktop"); strcpy (s[33]," * : Increase desktop width"); strcpy (s[34]," / : Decrease desktop width"); strcpy (s[35]," + : Increase desktop height"); strcpy (s[36]," - : Decrease desktop height"); strcpy (s[37]," t : Switch clock display mode"); strcpy (s[38]," \\ : Change Password"); strcpy (s[39]," ! : Lock Display"); strcpy (s[40]," = : Switch Status Bar Format"); strcpy (s[41]," h or F1 : Help"); strcpy (s[42]," ? : About and Statistics"); strcpy (s[43]," { : Set Alarm (\"Radio\") On"); strcpy (s[44]," } : Set Alarm (\"Radio\") Off"); strcpy (s[45]," T : Set Sleep mode"); strcpy (s[46]," | : On/Off Shut Down mode"); strcpy (s[47]," o : Settings"); strcpy (s[48]," Q : Quit"); strcpy (s[49],""); strcpy (s[50],"PLAYLIST"); strcpy (s[51]," a : Add File"); strcpy (s[52]," d : Delete File"); strcpy (s[53]," D : Add Directory"); strcpy (s[54]," R : Delete All"); strcpy (s[55]," S : Sort Playlist"); strcpy (s[56]," <UP> : Cursor Up"); strcpy (s[57]," <DOWN> : Cursor Down"); strcpy (s[58]," <PAGE UP> : Page Up"); strcpy (s[59]," <PAGE DOWN> : Page Down"); strcpy (s[60]," 0..9 : Fast Scroll"); strcpy (s[61]," [ : Move Up"); strcpy (s[62]," ' : Move Down"); strcpy (s[63]," l : Locate Current Song"); strcpy (s[64]," L : Autolocate Current Song"); strcpy (s[65]," p : Playlist Options"); strcpy (s[66]," p,n : New Playlist"); strcpy (s[67]," p,l : Load Playlist"); strcpy (s[68]," p,s : Save Playlist"); strcpy (s[69]," p,i : Import Playlist"); strcpy (s[70]," p,e : Export Playlist"); strcpy (s[71]," E : Edit playlist file entry"); strcpy (s[72]," n : Refresh list"); strcpy (s[73]," ; : On/Off save playlist position on exit"); strcpy (s[74],""); strcpy (s[75],"JUMP TO FILE"); strcpy (s[76]," <ENTER> : Play"); strcpy (s[77]," <SPACE BAR> : Set as next"); strcpy (s[78]," <TAB> : Add/Remove to/from filter"); strcpy (s[79]," F : Add/Remove all songs to filter"); strcpy (s[80]," i : ID3 TAG Edditor"); strcpy (s[81]," ESC or q : Close window"); strcpy (s[82],""); strcpy (s[83],"EQUALIZER WINDOW"); strcpy (s[84]," <PAGE UP> : Up ALL"); strcpy (s[85]," <PAGE DOWN> : Down ALL"); strcpy (s[86]," a/z : Up/Down Band #1"); strcpy (s[87]," s/x : Up/Down Band #2"); strcpy (s[88]," d/c : Up/Down Band #3"); strcpy (s[89]," f/v : Up/Down Band #4"); strcpy (s[90]," g/b : Up/Down Band #5"); strcpy (s[91]," h/n : Up/Down Band #6"); strcpy (s[92]," j/m : Up/Down Band #7"); strcpy (s[93]," k/, : Up/Down Band #8"); strcpy (s[94]," l/. : Up/Down Band #9"); strcpy (s[95]," ;// : Up/Down Band #10"); strcpy (s[96]," r : Set all bands to 0 (reset equalizer)"); strcpy (s[97]," L : Load Preset"); strcpy (s[98]," S : Save Preset"); strcpy (s[99]," I : Import Preset(s)"); strcpy (s[100]," D : Delete Preset(s)"); strcpy (s[101]," A : On/Off Automatic Equalizer"); strcpy (s[102],""); strcpy (s[103],"STATISTICS"); strcpy (s[104]," R : Reset current session statistics"); strcpy (s[105],""); strcpy (s[106],"SPECIAL FUNCTIONS"); strcpy (s[107]," P : Save playlist for MP3 CD Player"); strcpy (s[108]," * Save your playlist (p,s). Make a"); strcpy (s[109]," new playlist (p,n).Load Directory (D)"); strcpy (s[110]," from the CD in your playlist."); strcpy (s[111]," * Tested on JazzPIPER MCD650S"); strcpy (s[112],""); strcpy (s[113],"PLAYER MODES"); strcpy (s[114]," Normal : Next song in playlist (don\'t shuffle)"); strcpy (s[115]," Shuffle : Random next song (shuffle)"); strcpy (s[116]," Next Song : Next song is already selected"); strcpy (s[117]," Filter : There are files in the filter"); strcpy (s[118]," P-Filter : The filter is persistent"); strcpy (s[119]," Password : Display is locked with password"); strcpy (s[120]," Radio : Start/Stop music at a specific time"); strcpy (s[121]," Sleep : Shut Down at a specific time"); strcpy (s[122]," Shut Down : Shut Down after current song"); WINDOW *w1; w1=newwin (scr+2,62,7,(nrcols-62)/2); wrefresh (w1); werase (w1); WINDOW *w; w=newwin (scr,60,8,(nrcols-60)/2); wsetcolor (w,12,0); for (int h=0;h<=scr+2;h++) mvwprintw (w,h,0," "); wsetcolor (w,12,0); le_border (w,60,scr); wsetcolor (w,13,1); mvwprintw (w,0,1," Help "); wsetcolor (w,12,0); mvwprintw (w,scr-1,46," ESC - quit "); wrefresh(w); noecho(); timeout (1); k=0; do { wsetcolor (w,12,0); for (int i=0;i<=scr-5;i++) { mvwprintw (w,2+i,2," "); mvwprintw (w,2+i,2,"%s",s[i+k]); } wsetcolor (w,12,0); mvwaddch (w,0,28,ACS_HLINE); mvwaddch (w,scr-1,28,ACS_HLINE); wsetcolor (w,12,1); if (k>0) mvwaddch (w,0,28,ACS_UARROW); if (k<93-(scr-5)) mvwaddch (w,scr-1,28,ACS_DARROW); wrefresh(w); do { messages(); v=getch(); } while (v==ERR); if (v == 27) { v=getch(); if (v==ERR) v='q'; if (v==91) { v=getch(); if (v==65) if (k > 0) k--; if (v==66) if (k < 122-(scr-5)) k++; } } } while (v!='q'); werase (w); reread=1; }
void redraw_attr_dialog(void) { const char *title; int x, y; size_t title_len; int need_ellipsis; werase(change_win); if(file_is_dir) wresize(change_win, 22, 30); else wresize(change_win, 20, 30); mvwaddstr(change_win, 3, 2, "Owner [ ] Read"); if(perms[0]) mvwaddch(change_win, 3, 9, (perms[0] < 0) ? 'X' : '*'); mvwaddstr(change_win, 4, 6, " [ ] Write"); if(perms[1]) mvwaddch(change_win, 4, 9, (perms[1] < 0) ? 'X' : '*'); mvwaddstr(change_win, 5, 6, " [ ] Execute"); if(perms[2]) mvwaddch(change_win, 5, 9, (perms[2] < 0) ? 'X' : '*'); mvwaddstr(change_win, 6, 6, " [ ] SetUID"); if(perms[3]) mvwaddch(change_win, 6, 9, (perms[3] < 0) ? 'X' : '*'); mvwaddstr(change_win, 8, 2, "Group [ ] Read"); if(perms[4]) mvwaddch(change_win, 8, 9, (perms[4] < 0) ? 'X' : '*'); mvwaddstr(change_win, 9, 6, " [ ] Write"); if(perms[5]) mvwaddch(change_win, 9, 9, (perms[5] < 0) ? 'X' : '*'); mvwaddstr(change_win, 10, 6, " [ ] Execute"); if(perms[6]) mvwaddch(change_win, 10, 9, (perms[6] < 0) ? 'X' : '*'); mvwaddstr(change_win, 11, 6, " [ ] SetGID"); if(perms[7]) mvwaddch(change_win, 11, 9, (perms[7] < 0) ? 'X' : '*'); mvwaddstr(change_win, 13, 2, "Other [ ] Read"); if(perms[8]) mvwaddch(change_win, 13, 9, (perms[8] < 0) ? 'X' : '*'); mvwaddstr(change_win, 14, 6, " [ ] Write"); if(perms[9]) mvwaddch(change_win, 14, 9, (perms[9] < 0) ? 'X' : '*'); mvwaddstr(change_win, 15, 6, " [ ] Execute"); if(perms[10]) mvwaddch(change_win, 15, 9, (perms[10] < 0) ? 'X' : '*'); mvwaddstr(change_win, 16, 6, " [ ] Sticky"); if(perms[11]) mvwaddch(change_win, 16, 9, (perms[11] < 0) ? 'X' : '*'); if(file_is_dir) mvwaddstr(change_win, 18, 6, " [ ] Set Recursively"); getmaxyx(stdscr, y, x); mvwin(change_win, (y - (20 + (file_is_dir != 0)*2))/2, (x - 30)/2); box(change_win, 0, 0); x = getmaxx(change_win); title = get_title(); title_len = strlen(title); need_ellipsis = (title_len > (size_t)x - 2); if(need_ellipsis) { x -= 3; title_len = x; } mvwaddnstr(change_win, 0, (getmaxx(change_win) - title_len)/2, title, x - 2); if(need_ellipsis) { waddstr(change_win, "..."); } checked_wmove(change_win, curr, col); curs_set(1); wrefresh(change_win); }
/* * Display text from a file in a dialog box. */ int dialog_textbox(const char *title, const char *tbuf, int initial_height, int initial_width) { int i, x, y, cur_x, cur_y, key = 0; int height, width, boxh, boxw; int passed_end; WINDOW *dialog, *box; begin_reached = 1; end_reached = 0; page_length = 0; hscroll = 0; buf = tbuf; page = buf; /* page is pointer to start of page to be displayed */ do_resize: getmaxyx(stdscr, height, width); if (height < 8 || width < 8) return -ERRDISPLAYTOOSMALL; if (initial_height != 0) height = initial_height; else if (height > 4) height -= 4; else height = 0; if (initial_width != 0) width = initial_width; else if (width > 5) width -= 5; else width = 0; /* center dialog box on screen */ x = (getmaxx(stdscr) - width) / 2; y = (getmaxy(stdscr) - height) / 2; draw_shadow(stdscr, y, x, height, width); dialog = newwin(height, width, y, x); keypad(dialog, TRUE); /* Create window for box region, used for scrolling text */ boxh = height - 4; boxw = width - 2; box = subwin(dialog, boxh, boxw, y + 1, x + 1); wattrset(box, dlg.dialog.atr); wbkgdset(box, dlg.dialog.atr & A_COLOR); keypad(box, TRUE); /* register the new window, along with its borders */ draw_box(dialog, 0, 0, height, width, dlg.dialog.atr, dlg.border.atr); wattrset(dialog, dlg.border.atr); mvwaddch(dialog, height - 3, 0, ACS_LTEE); for (i = 0; i < width - 2; i++) waddch(dialog, ACS_HLINE); wattrset(dialog, dlg.dialog.atr); wbkgdset(dialog, dlg.dialog.atr & A_COLOR); waddch(dialog, ACS_RTEE); print_title(dialog, title, width); print_button(dialog, gettext(" Exit "), height - 2, width / 2 - 4, TRUE); wnoutrefresh(dialog); getyx(dialog, cur_y, cur_x); /* Save cursor position */ /* Print first page of text */ attr_clear(box, boxh, boxw, dlg.dialog.atr); refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); while ((key != KEY_ESC) && (key != '\n')) { key = wgetch(dialog); switch (key) { case 'E': /* Exit */ case 'e': case 'X': case 'x': delwin(box); delwin(dialog); return 0; case 'g': /* First page */ case KEY_HOME: if (!begin_reached) { begin_reached = 1; page = buf; refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); } break; case 'G': /* Last page */ case KEY_END: end_reached = 1; /* point to last char in buf */ page = buf + strlen(buf); back_lines(boxh); refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); break; case 'K': /* Previous line */ case 'k': case KEY_UP: if (!begin_reached) { back_lines(page_length + 1); /* We don't call print_page() here but use * scrolling to ensure faster screen update. * However, 'end_reached' and 'page_length' * should still be updated, and 'page' should * point to start of next page. This is done * by calling get_line() in the following * 'for' loop. */ scrollok(box, TRUE); wscrl(box, -1); /* Scroll box region down one line */ scrollok(box, FALSE); page_length = 0; passed_end = 0; for (i = 0; i < boxh; i++) { if (!i) { /* print first line of page */ print_line(box, 0, boxw); wnoutrefresh(box); } else /* Called to update 'end_reached' and 'page' */ get_line(); if (!passed_end) page_length++; if (end_reached && !passed_end) passed_end = 1; } print_position(dialog); wmove(dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh(dialog); } break; case 'B': /* Previous page */ case 'b': case KEY_PPAGE: if (begin_reached) break; back_lines(page_length + boxh); refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); break; case 'J': /* Next line */ case 'j': case KEY_DOWN: if (!end_reached) { begin_reached = 0; scrollok(box, TRUE); scroll(box); /* Scroll box region up one line */ scrollok(box, FALSE); print_line(box, boxh - 1, boxw); wnoutrefresh(box); print_position(dialog); wmove(dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh(dialog); } break; case KEY_NPAGE: /* Next page */ case ' ': if (end_reached) break; begin_reached = 0; refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); break; case '0': /* Beginning of line */ case 'H': /* Scroll left */ case 'h': case KEY_LEFT: if (hscroll <= 0) break; if (key == '0') hscroll = 0; else hscroll--; /* Reprint current page to scroll horizontally */ back_lines(page_length); refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); break; case 'L': /* Scroll right */ case 'l': case KEY_RIGHT: if (hscroll >= MAX_LEN) break; hscroll++; /* Reprint current page to scroll horizontally */ back_lines(page_length); refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); break; case KEY_ESC: key = on_key_esc(dialog); break; case KEY_RESIZE: back_lines(height); delwin(box); delwin(dialog); on_key_resize(); goto do_resize; } } delwin(box); delwin(dialog); return key; /* ESC pressed */ }
reindeer() { int looper; y_pos = 0; for(x_pos = 70; x_pos > 62; x_pos--) { if(x_pos < 62) { y_pos = 1; } for(looper = 0; looper < 4; looper++) { mvwaddch(dotdeer0, y_pos, x_pos, (chtype)'.'); wrefresh(dotdeer0); wrefresh(w_del_msg); werase(dotdeer0); wrefresh(dotdeer0); wrefresh(w_del_msg); } } y_pos = 2; for(; x_pos > 50; x_pos--) { for(looper = 0; looper < 4; looper++) { if(x_pos < 56) { y_pos = 3; mvwaddch(stardeer0, y_pos, x_pos, (chtype)'*'); wrefresh(stardeer0); wrefresh(w_del_msg); werase(stardeer0); wrefresh(stardeer0); wrefresh(w_del_msg); } else { mvwaddch(dotdeer0, y_pos, x_pos, (chtype)'*'); wrefresh(dotdeer0); wrefresh(w_del_msg); werase(dotdeer0); wrefresh(dotdeer0); wrefresh(w_del_msg); } } } x_pos = 58; for(y_pos = 2; y_pos < 5; y_pos++) { touchwin(lildeer0); wrefresh(lildeer0); wrefresh(w_del_msg); for(looper = 0; looper < 4; looper++) { mvwin(lildeer3, y_pos, x_pos); wrefresh(lildeer3); wrefresh(w_del_msg); mvwin(lildeer2, y_pos, x_pos); wrefresh(lildeer2); wrefresh(w_del_msg); mvwin(lildeer1, y_pos, x_pos); wrefresh(lildeer1); wrefresh(w_del_msg); mvwin(lildeer2, y_pos, x_pos); wrefresh(lildeer2); wrefresh(w_del_msg); mvwin(lildeer3, y_pos, x_pos); wrefresh(lildeer3); wrefresh(w_del_msg); touchwin(lildeer0); wrefresh(lildeer0); wrefresh(w_del_msg); x_pos -= 2; } } x_pos = 35; for(y_pos = 5; y_pos < 10; y_pos++) { touchwin(middeer0); wrefresh(middeer0); wrefresh(w_del_msg); for(looper = 0; looper < 2; looper++) { mvwin(middeer3, y_pos, x_pos); wrefresh(middeer3); wrefresh(w_del_msg); mvwin(middeer2, y_pos, x_pos); wrefresh(middeer2); wrefresh(w_del_msg); mvwin(middeer1, y_pos, x_pos); wrefresh(middeer1); wrefresh(w_del_msg); mvwin(middeer2, y_pos, x_pos); wrefresh(middeer2); wrefresh(w_del_msg); mvwin(middeer3, y_pos, x_pos); wrefresh(middeer3); wrefresh(w_del_msg); touchwin(middeer0); wrefresh(middeer0); wrefresh(w_del_msg); x_pos -= 3; } } usleep(2000); y_pos = 1; for(x_pos = 8; x_pos < 16; x_pos++) { mvwin(bigdeer4, y_pos, x_pos); wrefresh(bigdeer4); wrefresh(w_del_msg); mvwin(bigdeer3, y_pos, x_pos); wrefresh(bigdeer3); wrefresh(w_del_msg); mvwin(bigdeer2, y_pos, x_pos); wrefresh(bigdeer2); wrefresh(w_del_msg); mvwin(bigdeer1, y_pos, x_pos); wrefresh(bigdeer1); wrefresh(w_del_msg); mvwin(bigdeer2, y_pos, x_pos); wrefresh(bigdeer2); wrefresh(w_del_msg); mvwin(bigdeer3, y_pos, x_pos); wrefresh(bigdeer3); wrefresh(w_del_msg); mvwin(bigdeer4, y_pos, x_pos); wrefresh(bigdeer4); wrefresh(w_del_msg); mvwin(bigdeer0, y_pos, x_pos); wrefresh(bigdeer0); wrefresh(w_del_msg); } --x_pos; for(looper = 0; looper < 6; looper++) { mvwin(lookdeer4, y_pos, x_pos); wrefresh(lookdeer4); wrefresh(w_del_msg); mvwin(lookdeer3, y_pos, x_pos); wrefresh(lookdeer3); wrefresh(w_del_msg); mvwin(lookdeer2, y_pos, x_pos); wrefresh(lookdeer2); wrefresh(w_del_msg); mvwin(lookdeer1, y_pos, x_pos); wrefresh(lookdeer1); wrefresh(w_del_msg); mvwin(lookdeer2, y_pos, x_pos); wrefresh(lookdeer2); wrefresh(w_del_msg); mvwin(lookdeer3, y_pos, x_pos); wrefresh(lookdeer3); wrefresh(w_del_msg); mvwin(lookdeer4, y_pos, x_pos); wrefresh(lookdeer4); wrefresh(w_del_msg); } mvwin(lookdeer0, y_pos, x_pos); wrefresh(lookdeer0); wrefresh(w_del_msg); for(; y_pos < 10; y_pos++) { for(looper = 0; looper < 2; looper++) { mvwin(bigdeer4, y_pos, x_pos); wrefresh(bigdeer4); wrefresh(w_del_msg); mvwin(bigdeer3, y_pos, x_pos); wrefresh(bigdeer3); wrefresh(w_del_msg); mvwin(bigdeer2, y_pos, x_pos); wrefresh(bigdeer2); wrefresh(w_del_msg); mvwin(bigdeer1, y_pos, x_pos); wrefresh(bigdeer1); wrefresh(w_del_msg); mvwin(bigdeer2, y_pos, x_pos); wrefresh(bigdeer2); wrefresh(w_del_msg); mvwin(bigdeer3, y_pos, x_pos); wrefresh(bigdeer3); wrefresh(w_del_msg); mvwin(bigdeer4, y_pos, x_pos); wrefresh(bigdeer4); wrefresh(w_del_msg); } mvwin(bigdeer0, y_pos, x_pos); wrefresh(bigdeer0); wrefresh(w_del_msg); } --y_pos; mvwin(lookdeer3, y_pos, x_pos); wrefresh(lookdeer3); wrefresh(w_del_msg); return( 0 ); }
// Pick up items at (posx, posy). void Pickup::pick_up(int posx, int posy, int min) { //min == -1 is Autopickup if (g->m.has_flag("SEALED", posx, posy)) { return; } if (!g->u.can_pickup(min != -1)) { // no message on autopickup (-1) return; } int veh_root_part = 0; int cargo_part = -1; vehicle *veh = g->m.veh_at (posx, posy, veh_root_part); bool from_vehicle = false; if( min != -1 ) { cargo_part = interact_with_vehicle( veh, posx, posy, veh_root_part ); from_vehicle = cargo_part >= 0; if( cargo_part == -2 ) { return; } } if( !from_vehicle ) { bool isEmpty = (g->m.i_at(posx, posy).empty()); // Hide the pickup window if this is a toilet and there's nothing here // but water. if ((!isEmpty) && g->m.furn(posx, posy) == f_toilet) { isEmpty = true; for (size_t i = 0; isEmpty && i < g->m.i_at(posx, posy).size(); i++) { if (g->m.i_at(posx, posy)[i].typeId() != "water") { isEmpty = false; } } } if (isEmpty && (min != -1 || !OPTIONS["AUTO_PICKUP_ADJACENT"] )) { return; } } // which items are we grabbing? std::vector<item> here = (from_vehicle) ? veh->parts[cargo_part].items : g->m.i_at(posx, posy); if (min == -1) { if (g->checkZone("NO_AUTO_PICKUP", posx, posy)) { here.clear(); } // Recursively pick up adjacent items if that option is on. if( OPTIONS["AUTO_PICKUP_ADJACENT"] && g->u.posx == posx && g->u.posy == posy ) { //Autopickup adjacent direction adjacentDir[8] = {NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, NORTHWEST}; for (int i = 0; i < 8; i++) { point apos = direction_XY(adjacentDir[i]); apos.x += posx; apos.y += posy; if( g->m.has_flag( "SEALED", apos.x, apos.y ) ) { continue; } if( g->checkZone( "NO_AUTO_PICKUP", apos.x, apos.y ) ) { continue; } pick_up( apos.x, apos.y, min ); } } } // Not many items, just grab them if ((int)here.size() <= min && min != -1) { g->u.assign_activity( ACT_PICKUP, 0 ); g->u.activity.placement = point( posx, posy ); g->u.activity.values.push_back( from_vehicle ); // Only one item means index is 0. g->u.activity.values.push_back( 0 ); // auto-pickup means pick up all. g->u.activity.values.push_back( 0 ); return; } if(min != -1) { // don't bother if we're just autopickup-ing g->temp_exit_fullscreen(); } bool sideStyle = use_narrow_sidebar(); // Otherwise, we have Autopickup, 2 or more items and should list them, etc. int maxmaxitems = sideStyle ? TERMY : getmaxy(g->w_messages) - 3; int itemsH = std::min(25, TERMY / 2); int pickupBorderRows = 3; // The pickup list may consume the entire terminal, minus space needed for its // header/footer and the item info window. int minleftover = itemsH + pickupBorderRows; if(maxmaxitems > TERMY - minleftover) { maxmaxitems = TERMY - minleftover; } const int minmaxitems = sideStyle ? 6 : 9; std::vector<bool> getitem; getitem.resize(here.size(), false); int maxitems = here.size(); maxitems = (maxitems < minmaxitems ? minmaxitems : (maxitems > maxmaxitems ? maxmaxitems : maxitems )); int pickupH = maxitems + pickupBorderRows; int pickupW = getmaxx(g->w_messages); int pickupY = VIEW_OFFSET_Y; int pickupX = getbegx(g->w_messages); int itemsW = pickupW; int itemsY = sideStyle ? pickupY + pickupH : TERMY - itemsH; int itemsX = pickupX; WINDOW *w_pickup = newwin(pickupH, pickupW, pickupY, pickupX); WINDOW *w_item_info = newwin(itemsH, itemsW, itemsY, itemsX); int ch = ' '; int start = 0, cur_it; int new_weight = g->u.weight_carried(), new_volume = g->u.volume_carried(); bool update = true; mvwprintw(w_pickup, 0, 0, _("PICK UP")); int selected = 0; int last_selected = -1; int itemcount = 0; std::map<int, unsigned int> pickup_count; // Count of how many we'll pick up from each stack if (min == -1) { //Auto Pickup, select matching items if( !select_autopickup_items( here, getitem) ) { // If we didn't find anything, bail out now. return; } } else { if(g->was_fullscreen) { g->draw_ter(); } // Now print the two lists; those on the ground and about to be added to inv // Continue until we hit return or space do { static const std::string pickup_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ:;"; int idx = -1; for (int i = 1; i < pickupH; i++) { mvwprintw(w_pickup, i, 0, " "); } if (ch >= '0' && ch <= '9') { ch = (char)ch - '0'; itemcount *= 10; itemcount += ch; } else if ((ch == '<' || ch == KEY_PPAGE) && start > 0) { start -= maxitems; selected = start; mvwprintw(w_pickup, maxitems + 2, 0, " "); } else if ((ch == '>' || ch == KEY_NPAGE) && start + maxitems < (int)here.size()) { start += maxitems; selected = start; mvwprintw(w_pickup, maxitems + 2, pickupH, " "); } else if ( ch == KEY_UP ) { selected--; if ( selected < 0 ) { selected = here.size() - 1; start = (int)( here.size() / maxitems ) * maxitems; if (start >= (int)here.size()) { start -= maxitems; } } else if ( selected < start ) { start -= maxitems; } } else if ( ch == KEY_DOWN ) { selected++; if ( selected >= (int)here.size() ) { selected = 0; start = 0; } else if ( selected >= start + maxitems ) { start += maxitems; } } else if ( selected >= 0 && ( ( ch == KEY_RIGHT && !getitem[selected]) || ( ch == KEY_LEFT && getitem[selected] ) ) ) { idx = selected; } else if ( ch == '`' ) { std::string ext = string_input_popup( _("Enter 2 letters (case sensitive):"), 3, "", "", "", 2); if(ext.size() == 2) { int p1 = pickup_chars.find(ext.at(0)); int p2 = pickup_chars.find(ext.at(1)); if ( p1 != -1 && p2 != -1 ) { idx = pickup_chars.size() + ( p1 * pickup_chars.size() ) + p2; } } } else { idx = pickup_chars.find(ch); } if( idx >= 0 && idx < (int)here.size()) { if (itemcount != 0 || pickup_count[idx] == 0) { if (itemcount >= here[idx].charges || !here[idx].count_by_charges()) { // Ignore the count if we pickup the whole stack anyway // or something that is not counted by charges (tools) itemcount = 0; } pickup_count[idx] = itemcount; itemcount = 0; } getitem[idx] = ( ch == KEY_RIGHT ? true : ( ch == KEY_LEFT ? false : !getitem[idx] ) ); if ( ch != KEY_RIGHT && ch != KEY_LEFT) { selected = idx; start = (int)( idx / maxitems ) * maxitems; } if (getitem[idx]) { if (pickup_count[idx] != 0 && (int)pickup_count[idx] < here[idx].charges) { item temp = here[idx].clone(); temp.charges = pickup_count[idx]; new_weight += temp.weight(); new_volume += temp.volume(); } else { new_weight += here[idx].weight(); new_volume += here[idx].volume(); } } else if (pickup_count[idx] != 0 && (int)pickup_count[idx] < here[idx].charges) { item temp = here[idx].clone(); temp.charges = pickup_count[idx]; new_weight -= temp.weight(); new_volume -= temp.volume(); pickup_count[idx] = 0; } else { new_weight -= here[idx].weight(); new_volume -= here[idx].volume(); } update = true; } if ( selected != last_selected ) { last_selected = selected; werase(w_item_info); if ( selected >= 0 && selected <= (int)here.size() - 1 ) { std::vector<iteminfo> vThisItem, vDummy; here[selected].info(true, &vThisItem); draw_item_info(w_item_info, "", vThisItem, vDummy, 0, true, true); } draw_border(w_item_info); mvwprintz(w_item_info, 0, 2, c_white, "< %s >", here[selected].display_name().c_str()); wrefresh(w_item_info); } if (ch == ',') { int count = 0; for (size_t i = 0; i < here.size(); i++) { if (getitem[i]) { count++; } else { new_weight += here[i].weight(); new_volume += here[i].volume(); } getitem[i] = true; } if (count == (int)here.size()) { for (size_t i = 0; i < here.size(); i++) { getitem[i] = false; } new_weight = g->u.weight_carried(); new_volume = g->u.volume_carried(); } update = true; } for (cur_it = start; cur_it < start + maxitems; cur_it++) { mvwprintw(w_pickup, 1 + (cur_it % maxitems), 0, " "); if (cur_it < (int)here.size()) { nc_color icolor = here[cur_it].color(&g->u); if (cur_it == selected) { icolor = hilite(icolor); } if (cur_it < (int)pickup_chars.size() ) { mvwputch(w_pickup, 1 + (cur_it % maxitems), 0, icolor, char(pickup_chars[cur_it])); } else { int p = cur_it - pickup_chars.size(); int p1 = p / pickup_chars.size(); int p2 = p % pickup_chars.size(); mvwprintz(w_pickup, 1 + (cur_it % maxitems), 0, icolor, "`%c%c", char(pickup_chars[p1]), char(pickup_chars[p2])); } if (getitem[cur_it]) { if (pickup_count[cur_it] == 0) { wprintz(w_pickup, c_ltblue, " + "); } else { wprintz(w_pickup, c_ltblue, " # "); } } else { wprintw(w_pickup, " - "); } wprintz(w_pickup, icolor, "%s", here[cur_it].display_name().c_str()); } } int pw = pickupW; const char *unmark = _("[left] Unmark"); const char *scroll = _("[up/dn] Scroll"); const char *mark = _("[right] Mark"); mvwprintw(w_pickup, maxitems + 1, 0, unmark); mvwprintw(w_pickup, maxitems + 1, (pw - strlen(scroll)) / 2, scroll); mvwprintw(w_pickup, maxitems + 1, pw - strlen(mark), mark); const char *prev = _("[pgup] Prev"); const char *all = _("[,] All"); const char *next = _("[pgdn] Next"); if (start > 0) { mvwprintw(w_pickup, maxitems + 2, 0, prev); } mvwprintw(w_pickup, maxitems + 2, (pw - strlen(all)) / 2, all); if (cur_it < (int)here.size()) { mvwprintw(w_pickup, maxitems + 2, pw - strlen(next), next); } if (update) { // Update weight & volume information update = false; for (int i = 9; i < pickupW; ++i) { mvwaddch(w_pickup, 0, i, ' '); } mvwprintz(w_pickup, 0, 9, (new_weight >= g->u.weight_capacity() ? c_red : c_white), _("Wgt %.1f"), g->u.convert_weight(new_weight)); wprintz(w_pickup, c_white, "/%.1f", g->u.convert_weight(g->u.weight_capacity())); mvwprintz(w_pickup, 0, 24, (new_volume > g->u.volume_capacity() - 2 ? c_red : c_white), _("Vol %d"), new_volume); wprintz(w_pickup, c_white, "/%d", g->u.volume_capacity() - 2); } wrefresh(w_pickup); ch = (int)getch(); } while (ch != ' ' && ch != '\n' && ch != KEY_ESCAPE); if (ch != '\n') { werase(w_pickup); wrefresh(w_pickup); werase(w_item_info); wrefresh(w_item_info); delwin(w_pickup); delwin(w_item_info); add_msg(_("Never mind.")); g->reenter_fullscreen(); g->refresh_all(); return; } } // At this point we've selected our items, register an activity to pick them up. g->u.assign_activity( ACT_PICKUP, 0 ); g->u.activity.placement = point( posx, posy ); g->u.activity.values.push_back( from_vehicle ); for (size_t i = 0; i < here.size(); i++) { if( getitem[i] ) { g->u.activity.values.push_back( i ); g->u.activity.values.push_back( pickup_count[i] ); } } g->reenter_fullscreen(); werase(w_pickup); wrefresh(w_pickup); werase(w_item_info); wrefresh(w_item_info); delwin(w_pickup); delwin(w_item_info); }
/* * Display a dialog box for inputing a string */ int dialog_inputbox(const char *title, const char *prompt, int height, int width, const char *init) { int i, x, y, box_y, box_x, box_width; int input_x = 0, scroll = 0, key = 0, button = -1; char *instr = dialog_input_result; WINDOW *dialog; if (!init) instr[0] = '\0'; else strcpy(instr, init); do_resize: if (getmaxy(stdscr) <= (height - 2)) return -ERRDISPLAYTOOSMALL; if (getmaxx(stdscr) <= (width - 2)) return -ERRDISPLAYTOOSMALL; /* center dialog box on screen */ x = (COLS - width) / 2; y = (LINES - height) / 2; draw_shadow(stdscr, y, x, height, width); dialog = newwin(height, width, y, x); keypad(dialog, TRUE); draw_box(dialog, 0, 0, height, width, dlg.dialog.atr, dlg.border.atr); (void)wattrset(dialog, dlg.border.atr); mvwaddch(dialog, height - 3, 0, ACS_LTEE); for (i = 0; i < width - 2; i++) waddch(dialog, ACS_HLINE); (void)wattrset(dialog, dlg.dialog.atr); waddch(dialog, ACS_RTEE); print_title(dialog, title, width); (void)wattrset(dialog, dlg.dialog.atr); print_autowrap(dialog, prompt, width - 2, 1, 3); /* Draw the input field box */ box_width = width - 6; getyx(dialog, y, x); box_y = y + 2; box_x = (width - box_width) / 2; draw_box(dialog, y + 1, box_x - 1, 3, box_width + 2, dlg.dialog.atr, dlg.border.atr); print_buttons(dialog, height, width, 0); /* Set up the initial value */ wmove(dialog, box_y, box_x); (void)wattrset(dialog, dlg.inputbox.atr); input_x = strlen(instr); if (input_x >= box_width) { scroll = input_x - box_width + 1; input_x = box_width - 1; for (i = 0; i < box_width - 1; i++) waddch(dialog, instr[scroll + i]); } else { waddstr(dialog, instr); } wmove(dialog, box_y, box_x + input_x); wrefresh(dialog); while (key != KEY_ESC) { key = wgetch(dialog); if (button == -1) { /* Input box selected */ switch (key) { case TAB: case KEY_UP: case KEY_DOWN: break; case KEY_LEFT: continue; case KEY_RIGHT: continue; case KEY_BACKSPACE: case 127: if (input_x || scroll) { (void)wattrset(dialog, dlg.inputbox.atr); if (!input_x) { scroll = scroll < box_width - 1 ? 0 : scroll - (box_width - 1); wmove(dialog, box_y, box_x); for (i = 0; i < box_width; i++) waddch(dialog, instr[scroll + input_x + i] ? instr[scroll + input_x + i] : ' '); input_x = strlen(instr) - scroll; } else input_x--; instr[scroll + input_x] = '\0'; mvwaddch(dialog, box_y, input_x + box_x, ' '); wmove(dialog, box_y, input_x + box_x); wrefresh(dialog); } continue; default: if (key < 0x100 && isprint(key)) { if (scroll + input_x < MAX_LEN) { (void)wattrset(dialog, dlg.inputbox.atr); instr[scroll + input_x] = key; instr[scroll + input_x + 1] = '\0'; if (input_x == box_width - 1) { scroll++; wmove(dialog, box_y, box_x); for (i = 0; i < box_width - 1; i++) waddch(dialog, instr [scroll + i]); } else { wmove(dialog, box_y, input_x++ + box_x); waddch(dialog, key); } wrefresh(dialog); } else flash(); /* Alarm user about overflow */ continue; } } } switch (key) { case 'O': case 'o': delwin(dialog); return 0; case 'H': case 'h': delwin(dialog); return 1; case KEY_UP: case KEY_LEFT: switch (button) { case -1: button = 1; /* Indicates "Help" button is selected */ print_buttons(dialog, height, width, 1); break; case 0: button = -1; /* Indicates input box is selected */ print_buttons(dialog, height, width, 0); wmove(dialog, box_y, box_x + input_x); wrefresh(dialog); break; case 1: button = 0; /* Indicates "OK" button is selected */ print_buttons(dialog, height, width, 0); break; } break; case TAB: case KEY_DOWN: case KEY_RIGHT: switch (button) { case -1: button = 0; /* Indicates "OK" button is selected */ print_buttons(dialog, height, width, 0); break; case 0: button = 1; /* Indicates "Help" button is selected */ print_buttons(dialog, height, width, 1); break; case 1: button = -1; /* Indicates input box is selected */ print_buttons(dialog, height, width, 0); wmove(dialog, box_y, box_x + input_x); wrefresh(dialog); break; } break; case ' ': case '\n': delwin(dialog); return (button == -1 ? 0 : button); case 'X': case 'x': key = KEY_ESC; break; case KEY_ESC: key = on_key_esc(dialog); break; case KEY_RESIZE: delwin(dialog); on_key_resize(); goto do_resize; } } delwin(dialog); return KEY_ESC; /* ESC pressed */ }
void InfoPanel::refresh() { if (srv == NULL) return; if (srv->statedom.empty()) { needrefresh = true; werase(win); mvwprintw(win,0,0,"%s:%s\noffline",srv->gethost(),srv->getport()); NView::refresh(); return; } wattrset(win,getcolorpair(COLOR_WHITE,COLOR_BLACK)); wattron(win, A_REVERSE); mvwprintw(win,0,0," Tasks "); wattroff(win, A_REVERSE); mvwprintw(win,1,0,"all %3d",nalltasks); mvwprintw(win,2,0,"active %3d",nactivetasks); mvwprintw(win,3,0,"run %3d",nruntasks); mvwprintw(win,4,0,"wait %3d",nqueuetasks); mvwprintw(win,5,0,"done %3d",ndonetasks); mvwprintw(win,6,0,"other %3d",nothertasks); wattron(win,A_REVERSE); mvwprintw(win,7,0," Storage "); wattroff(win,A_REVERSE); mvwprintw(win,8,0, "total %8.2fGb",dtotal/(1024*1024*1024)); mvwprintw(win,9,0, "free %8.2fGb",dfree/(1024*1024*1024)); mvwprintw(win,10,0,"allowed %8.2fGb",dallowed/(1024*1024*1024)); mvwprintw(win,11,0,"boinc %8.2fGb",dboinc/(1024*1024*1024)); wattron(win,A_REVERSE); mvwprintw(win,12,0," Statistics "); wattroff(win,A_REVERSE); bool compact = true; //компактный вывод статистики если user=host int line,col; getyx(win,line,col); if ( (!compact)||(abs(usertotal - hosttotal) > 1) ) { mvwprintw(win,line++,0,"user total%10.0f\n",usertotal); mvwprintw(win,line++,0,"host total%10.0f\n",hosttotal); } else mvwprintw(win,line++,0,"total %10.0f\n",usertotal); if ( (!compact)||(abs(useravg - hostavg) > 1) ) { mvwprintw(win,line++,0,"user avg %10.0f\n",useravg); mvwprintw(win,line++,0,"host avg %10.0f\n",hostavg); } else mvwprintw(win,line++,0,"average %10.0f\n",useravg); tm* ltime = localtime(&laststattime); char buf[128]; strftime(buf, sizeof(buf),"%-e %b",ltime); //"%-e %b %-k:%M" mvwprintw(win,line++,0,"%-s %s\n", buf, getdayname(laststattime).c_str()); //дата/время последней статистики //wattrset(win,0); if ( (!compact)||(abs(lastdayuser - lastdayhost) > 1) ) { if ( asciilinedraw == 1) { wmove(win,line++,0); wprintw(win,"+->user %10.0f\n",lastdayuser); wmove(win,line++,0); wprintw(win,"+->host %10.0f\n",lastdayhost); } else { mvwaddch(win,line++,0,ACS_LTEE); waddch(win,ACS_HLINE); wprintw(win,">user %10.0f\n",lastdayuser); mvwaddch(win,line++,0,ACS_LLCORNER); waddch(win,ACS_HLINE); wprintw(win,">host %10.0f\n",lastdayhost); } } else { if( asciilinedraw == 1) { wmove(win,line++,0); wprintw(win,"-->daily %10.0f\n",lastdayhost); } else { mvwaddch(win,line++,0,ACS_LLCORNER); waddch(win,ACS_HLINE); wprintw(win,">daily %10.0f\n",lastdayhost); } } //по проектам mvwprintw(win, line++,0,"\n"); for (int i = 0; i < projects.size(); i++) //цикл по названиям проектов { //расчитываем нужное кол-во строк int needlines = 2; if (!projects[i].sstatus.empty()) needlines++; if ( (!compact)||(abs(projects[i].user - projects[i].host) > 1) ) needlines += 2; else needlines++; if ( (!compact)||(abs(projects[i].userlastday - projects[i].hostlastday) > 1) ) needlines += 2; else needlines++; //проверяем сколько свободных строк осталось в окне if ( ( getheight()-line ) < needlines ) break; //не выводим если осталось мало строк //вывод на экран о проекте wattrset(win,getcolorpair(COLOR_YELLOW,COLOR_BLACK)); mvwprintw(win,line++,0,"%s\n",projects[i].name.c_str()); if (!projects[i].sstatus.empty()) { wattrset(win,getcolorpair(COLOR_RED,COLOR_BLACK)); mvwprintw(win,line++,0,"%s\n",projects[i].sstatus.c_str()); } wattrset(win,getcolorpair(COLOR_WHITE,COLOR_BLACK)); if ( (!compact)||(abs(projects[i].user - projects[i].host) > 1) ) { mvwprintw(win,line++,0,"user total%10.0f\n",projects[i].user); mvwprintw(win,line++,0,"host total%10.0f\n",projects[i].host); } else mvwprintw(win,line++,0,"total %10.0f\n",projects[i].user); ltime = localtime(&projects[i].laststattime); strftime(buf, sizeof(buf),"%-e %b",ltime); //"%-e %b %-k:%M" mvwprintw(win,line++,0,"%-s %s\n",buf, getdayname(projects[i].laststattime).c_str()); if ( (!compact)||(abs(projects[i].userlastday - projects[i].hostlastday) > 1) ) { if (asciilinedraw == 1) { wmove(win,line++,0); wprintw(win,"+->user %10.0f\n",projects[i].userlastday); wmove(win,line++,0); wprintw(win,"+->host %10.0f\n",projects[i].hostlastday); } else { mvwaddch(win,line++,0,ACS_LTEE); waddch(win,ACS_HLINE); wprintw(win,">user %10.0f\n",projects[i].userlastday); mvwaddch(win,line++,0,ACS_LLCORNER); waddch(win,ACS_HLINE); wprintw(win,">host %10.0f\n",projects[i].hostlastday); } } else { if (asciilinedraw == 1) { wmove(win,line++,0); wprintw(win,"-->daily %10.0f\n",projects[i].userlastday); } else { mvwaddch(win,line++,0,ACS_LLCORNER); waddch(win,ACS_HLINE); wprintw(win,">daily %10.0f\n",projects[i].userlastday); } } } if ( line < getheight() ) wclrtobot(win); //чистим нижню часть окна (если не это не последняя строка иначе сотрем символ в правом нижнем) NView::refresh(); }
void drawTree(WINDOW** tv, Group* current, int start_y, int start_x, int highlighted_id) { wmove(*tv, start_y, start_x); wattron(*tv, A_BOLD); if (highlighted_id == current->id) wattron(*tv, COLOR_PAIR(2)); wprintw(*tv, current->name.c_str()); wattron(*tv, COLOR_PAIR(1)); wattroff(*tv, A_BOLD); if (current->id == 2) { wprintw(*tv, " - Data&Ora"); } //wprintw(*tv, " %s%s%s%s%s%s%s", (current->attrs & (1<<7)? "RT ":""), (current->attrs & (1<<6))? "AB ":""), (current->attrs & (1<<5)? "PW ":""), (current->attrs & (1<<4)? "WH ":""), (current->attrs & (1<<3)? "CA ":""), (current->attrs & (1<<2)? "FC ":""), (current->attrs & (1<<1)? "UNK ":"")); //wprintw(*tv, " %s", getAttrs(current).c_str()); start_y += 1; for(auto it = current->children.begin(); it < current->children.end(); it++) { if (it == current->children.begin()) // VLINE + TEE { mvwaddch(*tv, start_y++, start_x, ACS_VLINE); mvwaddch(*tv, start_y, start_x++, ACS_LTEE); mvwaddch(*tv, start_y, start_x++, ACS_HLINE); mvwaddch(*tv, start_y, start_x++, ACS_HLINE); mvwaddch(*tv, start_y, start_x++, ACS_HLINE); drawTree(tv, *it, start_y, start_x+1, highlighted_id); } else if (it == (current->children.end()-1)) // last element, VLINE + LRCORNER { start_x -= 4; start_y += 1; for(unsigned i=0; i < (*(it-1))->total_subgroups; i++) { // 2*VLINE + VLINE + TEE mvwaddch(*tv, start_y++, start_x, ACS_VLINE); mvwaddch(*tv, start_y++, start_x, ACS_VLINE); } mvwaddch(*tv, start_y++, start_x, ACS_VLINE); mvwaddch(*tv, start_y, start_x++, ACS_LLCORNER); mvwaddch(*tv, start_y, start_x++, ACS_HLINE); mvwaddch(*tv, start_y, start_x++, ACS_HLINE); mvwaddch(*tv, start_y, start_x++, ACS_HLINE); drawTree(tv, *it, start_y, start_x+1, highlighted_id); } else { // get the total_subgroup count of the group before in order to know how many VLINEs we need start_x -= 4; start_y += 1; for(unsigned i=0; i < (*(it-1))->total_subgroups; i++) { // 2*VLINE + VLINE + TEE mvwaddch(*tv, start_y++, start_x, ACS_VLINE); mvwaddch(*tv, start_y++, start_x, ACS_VLINE); } mvwaddch(*tv, start_y++, start_x, ACS_VLINE); mvwaddch(*tv, start_y, start_x++, ACS_LTEE); mvwaddch(*tv, start_y, start_x++, ACS_HLINE); mvwaddch(*tv, start_y, start_x++, ACS_HLINE); mvwaddch(*tv, start_y, start_x++, ACS_HLINE); drawTree(tv, *it, start_y, start_x+1, highlighted_id); } } wrefresh(*tv); }
int main() { int max_rows, max_cols; int fake = 7; WINDOW* statusbar = nullptr; WINDOW* treeview = nullptr; WINDOW* commandline = nullptr; pugi::xml_document doc; pugi::xml_parse_result result; struct Group* root; struct Group* current_selection; std::string command = ""; char server_addr[IP_ADDRLEN] = "127.0.0.1"; char buffer[8192]; unsigned short port = 26750; struct sockaddr_in server; struct in_addr addr; socklen_t server_size = sizeof server; int sock; int packlen; initscr(); getmaxyx(stdscr, max_rows, max_cols); if (has_colors() == FALSE) { endwin(); std::cerr << "\nncurses: colors not supported.\n"; return 1; } start_color(); init_pair(1, COLOR_WHITE, COLOR_BLACK); init_pair(2, COLOR_RED, COLOR_BLACK); attron(COLOR_PAIR(1)); //attron(A_BOLD); cbreak(); // we don't need to push [enter] noecho(); // pressed keys are not displayed keypad(stdscr, TRUE); keypad(commandline, TRUE); move(7,1); printw("Sending request to %s:%i...", server_addr, port); std::string packet_1 = "1oeila"; const unsigned packet_1_len = packet_1.length(); if (inet_pton(AF_INET, server_addr, &addr) <= 0) // returns 1 on success { printw("Invalid IP address (inet_pton)."); refresh(); getch(); endwin(); return 1; } memset(&server, 0, sizeof server); server.sin_family = AF_INET; server.sin_port = htons(port); server.sin_addr = addr; sock = socket(AF_INET, SOCK_DGRAM, 0); packlen = sendto(sock, packet_1.c_str(), packet_1_len, 0, (struct sockaddr*)&server, sizeof(server)); if (packlen <= 0) { printw("error"); refresh(); getch(); endwin(); return 1; } printw("done"); move(8,1); printw("Waiting for response..."); refresh(); packlen = recvfrom(sock, buffer, sizeof buffer, 0, (struct sockaddr*)&server, &server_size); if (packlen <= 0) { printw("error"); refresh(); getch(); endwin(); return 1; } printw("done"); move(9,1); printw("Loading tree..."); result = doc.load_buffer(buffer, sizeof buffer); switch (result.status) { case pugi::status_ok: { printw("done"); move(10,1); printw("Rebuilding tree..."); root = populate_tree(doc.first_child().first_child()); // -> TreeStructure -> Root if (root == nullptr) { refresh(); getch(); endwin(); return 1; } else { printw("done"); getch(); } break; } case pugi::status_io_error: case pugi::status_file_not_found: { printw("IO error."); refresh(); getchar(); endwin(); return 1; } case pugi::status_out_of_memory: { printw("out of memory."); refresh(); getchar(); endwin(); return 1; } case pugi::status_internal_error: { printw("internal error while loading."); refresh(); getchar(); endwin(); return 1; } default: { printw("error while parsing."); refresh(); getchar(); endwin(); return 1; } } drawWindows(&statusbar, &treeview, &commandline); drawTree(&treeview, root, 2, 3, 1); mvwprintw(statusbar, 1, max_cols-18, "Total groups: %i", root->total_subgroups+1); wrefresh(statusbar); wmove(commandline, 1, 3); current_selection = root; while (1) { int keypress = getch(); if (keypress == KEY_LEFT) // return to father node { if (current_selection->father != nullptr) // if not root { current_selection = current_selection->father; drawTree(&treeview, root, 2, 3, current_selection->id); } } else if (keypress == KEY_RIGHT) // enter the first child { if (current_selection->total_subgroups) // if has children { current_selection = current_selection->children[0]; drawTree(&treeview, root, 2, 3, current_selection->id); } } else if (keypress == KEY_UP) // navigate through siblings { if (current_selection->id > 1) // if not root { int sibling_index = getIndexById(current_selection->father, current_selection->id) - 1; if (sibling_index >= 0) // check bounds { current_selection = current_selection->father->children[sibling_index]; drawTree(&treeview, root, 2, 3, current_selection->id); } } } else if (keypress == KEY_DOWN) // navigate through siblings { if (current_selection->id > 1) // if not root { int sibling_index = getIndexById(current_selection->father, current_selection->id) + 1; if (sibling_index < current_selection->father->children.size()) // check bounds { current_selection = current_selection->father->children[sibling_index]; drawTree(&treeview, root, 2, 3, current_selection->id); } } } else if ((keypress >= 'A' && keypress <= 'Z') || (keypress >= 'a' && keypress <= 'z') || (keypress >= '0' && keypress <= '9') || keypress == ' ') // command { command += (char)keypress; waddch(commandline, keypress); wrefresh(commandline); } else if (keypress == 127 || keypress == 8) // backspace { int slen = command.length(), c_y, c_x; if (slen > 0) { command.erase(command.end()-1); getyx(commandline, c_y, c_x); mvwaddch(commandline, c_y, c_x-1, ' '); wmove(commandline, c_y, c_x-1); wrefresh(commandline); } } else if (keypress == 10) // enter { if (command == "") { endwin(); delete root; return 1; } std::string buf; std::vector<std::string> tokens; std::stringstream ss(command); // split the command into individual words (delim == ' ') while (ss >> buf) { tokens.push_back(buf); } /*if (tokens[0] == "datetime") { time_t current_time; struct tm* time_info; char timeString[9]; time(¤t_time); time_info = localtime(¤t_time); strftime(timeString, sizeof(timeString), "%H:%M:%S", time_info); mvwprintw(treeview, fake++, 50, ">> server replies: %s", timeString); wrefresh(treeview); } else { endwin(); delete root; return 1; }*/ } else if (keypress == KEY_LEFT) { endwin(); delete root; return 1; } }
/*@ -mustfreeonly -compdestroy @*/ static void display_nav_sol(unsigned char *buf, size_t data_len) { unsigned short gw = 0; unsigned int tow = 0, flags; double epx, epy, epz, evx, evy, evz; unsigned char navmode; struct gps_data_t g; double separation; if (data_len != 52) return; #ifdef S_SPLINT_S assert(navsolwin != NULL); #endif /* S_SPLINT_S */ navmode = (unsigned char)getub(buf, 10); flags = (unsigned int)getub(buf, 11); if ((flags & (UBX_SOL_VALID_WEEK | UBX_SOL_VALID_TIME)) != 0) { tow = (unsigned int)getleu32(buf, 0); gw = (unsigned short)getles16(buf, 8); } epx = (double)(getles32(buf, 12) / 100.0); epy = (double)(getles32(buf, 16) / 100.0); epz = (double)(getles32(buf, 20) / 100.0); evx = (double)(getles32(buf, 28) / 100.0); evy = (double)(getles32(buf, 32) / 100.0); evz = (double)(getles32(buf, 36) / 100.0); ecef_to_wgs84fix(&g.fix, &separation, epx, epy, epz, evx, evy, evz); g.fix.epx = g.fix.epy = (double)(getles32(buf, 24) / 100.0); g.fix.eps = (double)(getles32(buf, 40) / 100.0); g.dop.pdop = (double)(getleu16(buf, 44) / 100.0); g.satellites_used = (int)getub(buf, 47); (void)wmove(navsolwin, 1, 11); (void)wprintw(navsolwin, "%+10.2fm %+10.2fm %+10.2fm", epx, epy, epz); (void)wmove(navsolwin, 2, 11); (void)wprintw(navsolwin, "%+9.2fm/s %+9.2fm/s %+9.2fm/s", evx, evy, evz); (void)wmove(navsolwin, 4, 11); (void)wattrset(navsolwin, A_UNDERLINE); (void)wprintw(navsolwin, "%12.9f %13.9f %8.2fm", g.fix.latitude, g.fix.longitude, g.fix.altitude); (void)mvwaddch(navsolwin, 4, 23, ACS_DEGREE); (void)mvwaddch(navsolwin, 4, 38, ACS_DEGREE); (void)wmove(navsolwin, 5, 11); (void)wprintw(navsolwin, "%6.2fm/s %5.1fo %6.2fm/s", g.fix.speed, g.fix.track, g.fix.climb); (void)mvwaddch(navsolwin, 5, 26, ACS_DEGREE); (void)wattrset(navsolwin, A_NORMAL); (void)wmove(navsolwin, 7, 7); /*@ -compdef @*/ { unsigned int day = tow / 8640000; unsigned int tod = tow % 8640000; unsigned int h = tod / 360000; unsigned int m = tod % 360000; unsigned int s = m % 6000; m = (m - s) / 6000; (void)wattrset(navsolwin, A_UNDERLINE); (void)wprintw(navsolwin, "%u %02u:%02u:%05.2f", day, h, m, (double)s / 100); (void)wattrset(navsolwin, A_NORMAL); } /*@ +compdef @*/ (void)wmove(navsolwin, 8, 11); if ((flags & (UBX_SOL_VALID_WEEK | UBX_SOL_VALID_TIME)) != 0) { (void)wprintw(navsolwin, "%d+%10.3lf", gw, (double)(tow / 1000.0)); (void)wmove(navsolwin, 8, 36); (void)wprintw(navsolwin, "%d", (tow / 86400000)); } /* relies on the fact that epx and epy are set to same value */ (void)wmove(navsolwin, 10, 12); (void)wprintw(navsolwin, "%7.2f", g.fix.epx); (void)wmove(navsolwin, 10, 33); (void)wprintw(navsolwin, "%6.2f", g.fix.epv); (void)wmove(navsolwin, 11, 7); (void)wprintw(navsolwin, "%2d", g.satellites_used); (void)wmove(navsolwin, 11, 15); (void)wprintw(navsolwin, "%5.1f", g.dop.pdop); (void)wmove(navsolwin, 11, 25); (void)wprintw(navsolwin, "0x%02x", navmode); (void)wmove(navsolwin, 11, 36); (void)wprintw(navsolwin, "0x%02x", flags); (void)wnoutrefresh(navsolwin); }
/* * Display a dialog box with two buttons - Yes and No */ int dialog_yesno(const char *title, const char *prompt, int height, int width) { int i, x, y, key = 0, button = 0; WINDOW *dialog; do_resize: if (getmaxy(stdscr) < (height + 4)) return -ERRDISPLAYTOOSMALL; if (getmaxx(stdscr) < (width + 4)) return -ERRDISPLAYTOOSMALL; /* center dialog box on screen */ x = (COLS - width) / 2; y = (LINES - height) / 2; draw_shadow(stdscr, y, x, height, width); dialog = newwin(height, width, y, x); keypad(dialog, TRUE); draw_box(dialog, 0, 0, height, width, dlg.dialog.atr, dlg.border.atr); wattrset(dialog, dlg.border.atr); mvwaddch(dialog, height - 3, 0, ACS_LTEE); for (i = 0; i < width - 2; i++) waddch(dialog, ACS_HLINE); wattrset(dialog, dlg.dialog.atr); waddch(dialog, ACS_RTEE); print_title(dialog, title, width); wattrset(dialog, dlg.dialog.atr); print_autowrap(dialog, prompt, width - 2, 1, 3); print_buttons(dialog, height, width, 0); while (key != KEY_ESC) { key = wgetch(dialog); switch (key) { case 'Y': case 'y': delwin(dialog); return 0; case 'N': case 'n': delwin(dialog); return 1; case TAB: case KEY_LEFT: case KEY_RIGHT: button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button); print_buttons(dialog, height, width, button); wrefresh(dialog); break; case ' ': case '\n': delwin(dialog); return button; case KEY_ESC: key = on_key_esc(dialog); break; case KEY_RESIZE: delwin(dialog); on_key_resize(); goto do_resize; } } delwin(dialog); return key; /* ESC pressed */ }
void engine_draw_next_pieces(game_s* g) { WINDOW* w = NULL; int i, k; for (i = 0; i < global.game_next_no; i++) { piece_s p = g->piece_next[i]; w = engine.screen.next[i].win; werase(w); /* This is a little hack to pretty-print pieces * TODO somehow manage to fix this */ for (k = 0; k < 4; k++) { /* shifting them to the left */ p.block[k].x -= p.x + 1; p.block[k].y -= p.y; p.block[k].y--; if (p.type == PIECE_O) p.block[k].y -= 1; } engine_draw_piece(&p, w); wnoutrefresh(w); } w = engine.screen.middle_right.win; if (global.screen_fancy_borders) { mvwaddch(w, 3, 0, ACS_LLCORNER|COLOR_PAIR(WHITE_BLACK)); mvwhline(w, 3, 1, ACS_HLINE|COLOR_PAIR(BLACK_BLACK)|A_BOLD, 8); mvwaddch(w, 3, 9, ACS_LRCORNER|COLOR_PAIR(BLACK_BLACK)|A_BOLD); } else { wattrset(w, engine_get_color(COLOR_BLACK, COLOR_BLACK, true)); mvwhline(w, 3, 1, '-', 8); } wattrset(w, engine_get_color(COLOR_BLUE, COLOR_BLACK, false)); mvwaddstr(w, 0, 1, "Next"); wnoutrefresh(w); window_s* win = &(engine.screen.middle_right); /* RE-DRAWING BORDERS (damn this sucks) */ if (global.screen_fancy_borders) { window_fancy_borders(win->win); /* making the top line between 1st next and the rest */ mvwaddch(win->win, 3, 0, ACS_LLCORNER|COLOR_PAIR(WHITE_BLACK)); mvwhline(win->win, 3, 1, ACS_HLINE|COLOR_PAIR(BLACK_BLACK)|A_BOLD, win->width - 2); mvwaddch(win->win, 3, win->width - 1, ACS_LRCORNER|COLOR_PAIR(BLACK_BLACK)|A_BOLD); /* making the bottom line between 1st next and the rest */ mvwaddch(win->win, 4, 0, ACS_ULCORNER|COLOR_PAIR(WHITE_BLACK)|A_BOLD); mvwhline(win->win, 4, 1, ACS_HLINE|COLOR_PAIR(WHITE_BLACK), win->width - 2); mvwaddch(win->win, 4, win->width - 1, ACS_URCORNER|COLOR_PAIR(WHITE_BLACK)); } else { window_normal_borders(win->win); wattrset(win->win, engine_get_color(COLOR_BLACK, COLOR_BLACK, true)); mvwhline(win->win, 3, 1, '-', win->width - 2); } }
balls() { overlay(treescrn, treescrn2); mvwaddch(treescrn2, 3, 9, (chtype)'@'); mvwaddch(treescrn2, 3, 15, (chtype)'@'); mvwaddch(treescrn2, 4, 8, (chtype)'@'); mvwaddch(treescrn2, 4, 16, (chtype)'@'); mvwaddch(treescrn2, 5, 7, (chtype)'@'); mvwaddch(treescrn2, 5, 17, (chtype)'@'); mvwaddch(treescrn2, 7, 6, (chtype)'@'); mvwaddch(treescrn2, 7, 18, (chtype)'@'); mvwaddch(treescrn2, 8, 5, (chtype)'@'); mvwaddch(treescrn2, 8, 19, (chtype)'@'); mvwaddch(treescrn2, 10, 4, (chtype)'@'); mvwaddch(treescrn2, 10, 20, (chtype)'@'); mvwaddch(treescrn2, 11, 2, (chtype)'@'); mvwaddch(treescrn2, 11, 22, (chtype)'@'); mvwaddch(treescrn2, 12, 1, (chtype)'@'); mvwaddch(treescrn2, 12, 23, (chtype)'@'); wrefresh(treescrn2); wrefresh(w_del_msg); return( 0 ); }
int item::pick_reload_ammo(player &u, bool interactive) { if (!type->is_gun() && !type->is_tool()) { debugmsg("RELOADING NON-GUN NON-TOOL"); return false; } bool has_m203 = false; for (int i = 0; i < contents.size() && !has_m203; i++) { if (contents[i].type->id == itm_m203) has_m203 = true; } std::vector<int> am; // List of indicies of valid ammo if (type->is_gun()) { if (charges > 0) { itype_id aid = itype_id(curammo->id); for (int i = 0; i < u.inv.size(); i++) { if (u.inv[i].type->id == aid) am.push_back(i); } } else { it_gun* tmp = dynamic_cast<it_gun*>(type); am = u.has_ammo(ammo_type()); if (has_m203) { std::vector<int> grenades = u.has_ammo(AT_40MM); for (int i = 0; i < grenades.size(); i++) am.push_back(grenades[i]); } } } else { it_tool* tmp = dynamic_cast<it_tool*>(type); am = u.has_ammo(ammo_type()); } int index = -1; if (am.size() > 1 && interactive) {// More than one option; list 'em and pick WINDOW* w_ammo = newwin(am.size() + 1, 80, 0, 0); if (charges == 0) { char ch; clear(); it_ammo* ammo_type; mvwprintw(w_ammo, 0, 0, "\ Choose ammo type: Damage Armor Pierce Range Accuracy"); for (int i = 0; i < am.size(); i++) { ammo_type = dynamic_cast<it_ammo*>(u.inv[am[i]].type); mvwaddch(w_ammo, i + 1, 1, i + 'a'); mvwprintw(w_ammo, i + 1, 3, "%s (%d)", u.inv[am[i]].tname().c_str(), u.inv[am[i]].charges); mvwprintw(w_ammo, i + 1, 27, "%d", ammo_type->damage); mvwprintw(w_ammo, i + 1, 38, "%d", ammo_type->pierce); mvwprintw(w_ammo, i + 1, 55, "%d", ammo_type->range); mvwprintw(w_ammo, i + 1, 65, "%d", 100 - ammo_type->accuracy); } refresh(); wrefresh(w_ammo); do ch = getch(); while ((ch < 'a' || ch - 'a' > am.size() - 1) && ch != ' ' && ch != 27); werase(w_ammo); delwin(w_ammo); erase(); if (ch == ' ' || ch == 27) index = -1; else index = am[ch - 'a']; } else {
strng4() { mvwaddch(treescrn2, 9, 17, (chtype)'\''); mvwaddch(treescrn2, 9, 16, (chtype)':'); mvwaddch(treescrn2, 9, 15, (chtype)'.'); mvwaddch(treescrn2, 9, 14, (chtype)','); mvwaddch(treescrn2, 10, 13, (chtype)'\''); mvwaddch(treescrn2, 10, 12, (chtype)':'); mvwaddch(treescrn2, 10, 11, (chtype)'.'); mvwaddch(treescrn2, 10, 10, (chtype)','); mvwaddch(treescrn2, 11, 9, (chtype)'\''); mvwaddch(treescrn2, 11, 8, (chtype)':'); mvwaddch(treescrn2, 11, 7, (chtype)'.'); mvwaddch(treescrn2, 11, 6, (chtype)','); mvwaddch(treescrn2, 12, 5, (chtype)'\''); wrefresh(treescrn2); wrefresh(w_del_msg); return( 0 ); }
/* * chase: * Find the spot for the chaser(er) to move closer to the * chasee(ee). Returns TRUE if we want to keep on chasing later * FALSE if we reach the goal. */ int chase(struct thing *tp, coord *ee, int flee, int *mdead) { register int x, y; register int dist, thisdist, monst_dist = MAXINT; register struct linked_list *weapon; register coord *er = &tp->t_pos, *shoot_dir; register int ch, mch; register int next_player = FALSE; int deadflg; if (mdead != NULL) *mdead = 0; shoot_dir = can_shoot(er, ee); weapon = get_hurl(tp); /* * If the thing is confused, let it move randomly. Invisible * Stalkers are slightly confused all of the time. */ if ((on(*tp, ISHUH) && rnd(10) < 8) || ((on(*tp, ISINVIS) || on(*tp, ISSHADOW)) && rnd(100) < 20) || (on(player, ISINVIS) && off(*tp, CANSEE))) { /* Player is invisible */ /* * get a valid random move */ ch_ret = *rndmove(tp); dist = DISTANCE(ch_ret.y, ch_ret.x, ee->y, ee->x); if (on(*tp, ISHUH) && rnd(20) == 0) /* monster might lose confusion */ turn_off(*tp, ISHUH); /* * check to see if random move takes creature away from player * if it does then turn off ISHELD */ if (dist > 1 && on(*tp, DIDHOLD)) { turn_off(*tp, DIDHOLD); turn_on(*tp, CANHOLD); if (--hold_count <= 0) { hold_count = 0; turn_off(player, ISHELD); } } } /* If we can breathe, we may do so */ else if (on(*tp, CANBREATHE) && (shoot_dir) && (rnd(100) < 67) && (off(player, ISDISGUISE) || (rnd(tp->t_stats.s_lvl) > 6)) && (DISTANCE(er->y, er->x, ee->y, ee->x) < BOLT_LENGTH*BOLT_LENGTH)) { register int chance; register char *breath; /* Will it breathe at random */ if (on(*tp, CANBRANDOM)) { if (rnd(level/20) == 0 && tp->t_index != NUMMONST+1) turn_off(*tp, CANBRANDOM); /* Select type of breath */ chance = rnd(100); if (chance < 11) breath = "acid"; else if (chance < 22) breath = "flame"; else if (chance < 33) breath = "lightning bolt"; else if (chance < 44) breath = "chlorine gas"; else if (chance < 55) breath = "ice"; else if (chance < 66) breath = "nerve gas"; else if (chance < 77) breath = "sleeping gas"; else if (chance < 88) breath = "slow gas"; else breath = "fear gas"; } /* Or can it breathe acid? */ else if (on(*tp, CANBACID)) { if (rnd(level/20) == 0) turn_off(*tp, CANBACID); breath = "acid"; } /* Or can it breathe fire */ else if (on(*tp, CANBFIRE)) { if (rnd(level/20) == 0) turn_off(*tp, CANBFIRE); breath = "flame"; } /* Or can it breathe electricity? */ else if (on(*tp, CANBBOLT)) { if (rnd(level/20) == 0) turn_off(*tp, CANBBOLT); breath = "lightning bolt"; } /* Or can it breathe gas? */ else if (on(*tp, CANBGAS)) { if (rnd(level/20) == 0) turn_off(*tp, CANBGAS); breath = "chlorine gas"; } /* Or can it breathe ice? */ else if (on(*tp, CANBICE)) { if (rnd(level/20) == 0) turn_off(*tp, CANBICE); breath = "ice"; } else if (on(*tp, CANBPGAS)) { if (rnd(level/20) == 0) turn_off(*tp, CANBPGAS); breath = "nerve gas"; } else if (on(*tp, CANBSGAS)) { if (rnd(level/20) == 0) turn_off(*tp, CANBSGAS); breath = "sleeping gas"; } else if (on(*tp, CANBSLGAS)) { if (rnd(level/20) == 0) turn_off(*tp, CANBSLGAS); breath = "slow gas"; } else { if (rnd(level/20) == 0) turn_off(*tp, CANBFGAS); breath = "fear gas"; } /* Now breathe -- returns TRUE if kills itself */ deadflg = shoot_bolt(tp, *er, *shoot_dir, FALSE, tp->t_index, breath, (save(VS_BREATH) ? tp->t_stats.s_hpt/2 : tp->t_stats.s_hpt)); if (deadflg && mdead != NULL) *mdead = 1; ch_ret = *er; dist = DISTANCE(ch_ret.y, ch_ret.x, ee->y, ee->x); if (deadflg) return(TRUE); } /* * If we can shoot or throw something, we might do so * if we are running away, we may decide to shoot anyway if we are far * enough */ else if((off(*tp, ISFLEE) || rnd(DISTANCE(er->y,er->x,ee->y,ee->x)) > 2) && on(*tp, CANSHOOT) && (off(player, ISDISGUISE) || (rnd(tp->t_stats.s_lvl) > 6)) && (shoot_dir) && (weapon)) { missile(shoot_dir->y, shoot_dir->x, weapon, tp); ch_ret = *er; dist = DISTANCE(ch_ret.y, ch_ret.x, ee->y, ee->x); } /* * Otherwise, find the empty spot next to the chaser that is * closest to the chasee. */ else { register int ey, ex; register struct room *rer, *ree; register int dist_to_old = MININT; /* Dist from goal to old position */ /* Get rooms */ rer = roomin(er); ree = roomin(ee); /* * This will eventually hold where we move to get closer * If we can't find an empty spot, we stay where we are. */ dist = flee ? 0 : MAXINT; ch_ret = *er; /* Are we at our goal already? */ if (!flee && ce(ch_ret, *ee)) return(FALSE); ey = er->y + 1; ex = er->x + 1; for (x = er->x - 1; x <= ex; x++) for (y = er->y - 1; y <= ey; y++) { coord tryp; /* Don't try off the board */ if ((x < 0) || (x >= COLS) || (y < 1) || (y >= LINES - 2)) continue; /* Don't try the player if not going after the player */ /* or he's disguised */ if ( ((off(*tp, ISFLEE) && !ce(hero, *ee)) || (on(player, ISDISGUISE) && (rnd(tp->t_stats.s_lvl) < 6))) && x == hero.x && y == hero.y) continue; tryp.x = x; tryp.y = y; /* Is there a monster on this spot closer to our goal? * Don't look in our spot or where we were. */ if (!ce(tryp, *er) && !ce(tryp, tp->t_oldpos) && isalpha(mch = CCHAR( mvwinch(mw, y, x) ))) { register int test_dist; test_dist = DISTANCE(y, x, ee->y, ee->x); if (test_dist <= 25 && /* Let's be fairly close */ test_dist < monst_dist) { /* Could we really move there? */ mvwaddch(mw, y, x, ' '); /* Temporarily blank monst */ if (diag_ok(er, &tryp, tp)) monst_dist = test_dist; mvwaddch(mw, y, x, mch); /* Restore monster */ } } if (!diag_ok(er, &tryp, tp)) continue; ch = CCHAR( mvwinch(cw, y, x) ); /* Screen character */ if (on(*tp, ISFLEE) && (ch == PLAYER)) next_player = TRUE; /* Stepping on player is NOT okay if we are fleeing */ if (step_ok(y, x, NOMONST, tp) && (off(*tp, ISFLEE) || ch != PLAYER)) { /* * If it is a trap, an intelligent monster may not * step on it (unless our hero is on top!) */ if (isatrap(ch)) { if (!(ch == RUSTTRAP) && !(ch == FIRETRAP && on(*tp,NOFIRE)) && rnd(10) < tp->t_stats.s_intel && (y != hero.y || x != hero.x)) continue; } /* * OK -- this place counts */ thisdist = DISTANCE(y, x, ee->y, ee->x); /* Adjust distance if we are being shot at */ if (tp->t_wasshot && tp->t_stats.s_intel > 5 && ce(hero, *ee)) { /* Move out of line of sight */ if (straight_shot(tryp.y, tryp.x, ee->y, ee->x, NULL)) { if (flee) thisdist -= SHOTPENALTY; else thisdist += SHOTPENALTY; } /* But do we want to leave the room? */ else if (rer && rer == ree && ch == DOOR) thisdist += DOORPENALTY; } /* Don't move to the last position if we can help it */ if (ce(tryp, tp->t_oldpos)) dist_to_old = thisdist; else if ((flee && (thisdist > dist)) || (!flee && (thisdist < dist))) { ch_ret = tryp; dist = thisdist; } } } /* If we are running from the player and he is in our way, * go ahead and slug him. */ if (next_player && DISTANCE(er->y, er->x, ee->y, ee->x) < dist && step_ok(tp->t_dest->y, tp->t_dest->x, NOMONST, tp)) { ch_ret = *(tp->t_dest); /* Okay to hit player */ return FALSE; } /* If we can't get closer to the player (if that's our goal) * because other monsters are in the way, just stay put */ if (!flee && ce(hero, *ee) && monst_dist < MAXINT && DISTANCE(er->y, er->x, hero.y, hero.x) < dist) ch_ret = *er; /* Do we want to go back to the last position? */ else if (dist_to_old != MININT && /* It is possible to move back */ ((flee && dist == 0) || /* No other possible moves */ (!flee && dist == MAXINT))) { /* Do we move back or just stay put (default)? */ dist = DISTANCE(er->y, er->x, ee->y, ee->x); /* Current distance */ if (!flee || (flee && (dist_to_old > dist))) ch_ret = tp->t_oldpos; } } /* Make sure we have the real distance now */ dist = DISTANCE(ch_ret.y, ch_ret.x, ee->y, ee->x); /* Mark monsters in a wall */ if (isrock(CCHAR( mvinch(ch_ret.y, ch_ret.x) ))) turn_on(*tp, ISINWALL); else turn_off(*tp, ISINWALL); if (off(*tp, ISFLEE) && ((tp->t_dest != &hero) || off(player, ISINWALL) || on(*tp, CANINWALL))) return (dist != 0); /* May actually hit here from a confused move */ else return(!ce(ch_ret, hero)); }
/* * Display a dialog box with two buttons - Yes and No */ int dialog_yesno (const char *title, const char *prompt, int height, int width) { int i, x, y, key = 0, button = 0; WINDOW *dialog; /* center dialog box on screen */ x = (COLS - width) / 2; y = (LINES - height) / 2; draw_shadow (stdscr, y, x, height, width); dialog = newwin (height, width, y, x); keypad (dialog, TRUE); draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr); wattrset (dialog, border_attr); mvwaddch (dialog, height-3, 0, ACS_LTEE); for (i = 0; i < width - 2; i++) waddch (dialog, ACS_HLINE); wattrset (dialog, dialog_attr); waddch (dialog, ACS_RTEE); if (title != NULL && strlen(title) >= width-2 ) { /* truncate long title -- mec */ char * title2 = malloc(width-2+1); memcpy( title2, title, width-2 ); title2[width-2] = '\0'; title = title2; } if (title != NULL) { wattrset (dialog, title_attr); mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' '); waddstr (dialog, (char *)title); waddch (dialog, ' '); } wattrset (dialog, dialog_attr); print_autowrap (dialog, prompt, width - 2, 1, 3); print_buttons(dialog, height, width, 0); while (key != ESC) { key = wgetch (dialog); switch (key) { case 'Y': case 'y': case 'S': case 's': delwin (dialog); return 0; case 'N': case 'n': delwin (dialog); return 1; case TAB: case KEY_LEFT: case KEY_RIGHT: button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button); print_buttons(dialog, height, width, button); wrefresh (dialog); break; case ' ': case '\n': delwin (dialog); return button; case ESC: break; } } delwin (dialog); return -1; /* ESC pressed */ }
int can_blink(struct thing *tp) { register int y, x, index=9; coord tryp; /* To hold the coordinates for use in diag_ok */ int spots[9], found_one=FALSE; /* First, can the monster even blink? And if so, there is only a 50% * chance that it will do so. And it won't blink if it is running. */ if (off(*tp, CANBLINK) || (on(*tp, ISHELD)) || on(*tp, ISFLEE) || (on(*tp, ISSLOW) && off(*tp, ISHASTE) && !(tp->t_turn)) || (rnd(12) < 6)) return(FALSE); /* Initialize the spots as illegal */ do { spots[--index] = FALSE; } while (index > 0); /* Find a suitable spot next to the player */ for (y=hero.y-1; y<hero.y+2; y++) for (x=hero.x-1; x<hero.x+2; x++, index++) { /* Make sure x coordinate is in range and that we are * not at the player's position */ if (x<0 || x >= COLS || index == 4) continue; /* Is it OK to move there? */ if (!step_ok(y, x, NOMONST, tp)) spots[index] = FALSE; else { /* OK, we can go here. But don't go there if * monster can't get at player from there */ tryp.y = y; tryp.x = x; if (diag_ok(&tryp, &hero, tp)) { spots[index] = TRUE; found_one = TRUE; } } } /* If we found one, go to it */ if (found_one) { /* Find a legal spot */ while (spots[index=rnd(9)] == FALSE) continue; /* Get the coordinates */ y = hero.y + (index/3) - 1; x = hero.x + (index % 3) - 1; /* Move the monster from the old space */ mvwaddch(cw, tp->t_pos.y, tp->t_pos.x, tp->t_oldch); /* Move it to the new space */ tp->t_oldch = CCHAR( mvwinch(cw, y, x) ); if (cansee(y, x) && off(*tp, ISINWALL) && ((off(*tp, ISINVIS) && (off(*tp, ISSHADOW) || rnd(100) < 10)) || on(player, CANSEE)) && off(*tp, CANSURPRISE)) mvwaddch(cw, y, x, tp->t_type); mvwaddch(mw, tp->t_pos.y, tp->t_pos.x, ' '); /* Clear old position */ mvwaddch(mw, y, x, tp->t_type); tp->t_pos.y = y; tp->t_pos.x = x; } return(found_one); }
/* * Display a dialog box with a list of options that can be turned on or off * in the style of radiolist (only one option turned on at a time). */ int dialog_checklist(const char *title, const char *prompt, int height, int width, int list_height, int item_no, const char *const *items) { int i, x, y, box_x, box_y; int key = 0, button = 0, choice = 0, scroll = 0, max_choice, *status; WINDOW *dialog, *list; /* Allocate space for storing item on/off status */ if ((status = malloc(sizeof(int) * item_no)) == NULL) { endwin(); fprintf(stderr, "\nCan't allocate memory in dialog_checklist().\n"); exit(-1); } /* Initializes status */ for (i = 0; i < item_no; i++) { status[i] = !strcasecmp(items[i * 3 + 2], "on"); if ((!choice && status[i]) || !strcasecmp(items[i * 3 + 2], "selected")) choice = i + 1; } if (choice) choice--; max_choice = MIN(list_height, item_no); /* center dialog box on screen */ x = (COLS - width) / 2; y = (LINES - height) / 2; draw_shadow(stdscr, y, x, height, width); dialog = newwin(height, width, y, x); keypad(dialog, TRUE); draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); wattrset(dialog, border_attr); mvwaddch(dialog, height - 3, 0, ACS_LTEE); for (i = 0; i < width - 2; i++) waddch(dialog, ACS_HLINE); wattrset(dialog, dialog_attr); waddch(dialog, ACS_RTEE); print_title(dialog, title, width); wattrset(dialog, dialog_attr); print_autowrap(dialog, prompt, width - 2, 1, 3); list_width = width - 6; box_y = height - list_height - 5; box_x = (width - list_width) / 2 - 1; /* create new window for the list */ list = subwin(dialog, list_height, list_width, y + box_y + 1, x + box_x + 1); keypad(list, TRUE); /* draw a box around the list items */ draw_box(dialog, box_y, box_x, list_height + 2, list_width + 2, menubox_border_attr, menubox_attr); /* Find length of longest item in order to center checklist */ check_x = 0; for (i = 0; i < item_no; i++) check_x = MAX(check_x, +strlen(items[i * 3 + 1]) + 4); check_x = (list_width - check_x) / 2; item_x = check_x + 4; if (choice >= list_height) { scroll = choice - list_height + 1; choice -= scroll; } /* Print the list */ for (i = 0; i < max_choice; i++) { print_item(list, items[(scroll + i) * 3 + 1], status[i + scroll], i, i == choice); } print_arrows(dialog, choice, item_no, scroll, box_y, box_x + check_x + 5, list_height); print_buttons(dialog, height, width, 0); wnoutrefresh(dialog); wnoutrefresh(list); doupdate(); while (key != ESC) { key = wgetch(dialog); for (i = 0; i < max_choice; i++) if (toupper(key) == toupper(items[(scroll + i) * 3 + 1][0])) break; if (i < max_choice || key == KEY_UP || key == KEY_DOWN || key == '+' || key == '-') { if (key == KEY_UP || key == '-') { if (!choice) { if (!scroll) continue; /* Scroll list down */ if (list_height > 1) { /* De-highlight current first item */ print_item(list, items[scroll * 3 + 1], status[scroll], 0, FALSE); scrollok(list, TRUE); wscrl(list, -1); scrollok(list, FALSE); } scroll--; print_item(list, items[scroll * 3 + 1], status[scroll], 0, TRUE); print_arrows(dialog, choice, item_no, scroll, box_y, box_x + check_x + 5, list_height); wnoutrefresh(dialog); wrefresh(list); continue; /* wait for another key press */ } else i = choice - 1; } else if (key == KEY_DOWN || key == '+') { if (choice == max_choice - 1) { if (scroll + choice >= item_no - 1) continue; /* Scroll list up */ if (list_height > 1) { /* De-highlight current last item before scrolling up */ print_item(list, items[(scroll + max_choice - 1) * 3 + 1], status[scroll + max_choice - 1], max_choice - 1, FALSE); scrollok(list, TRUE); wscrl(list, 1); scrollok(list, FALSE); } scroll++; print_item(list, items[(scroll + max_choice - 1) * 3 + 1], status[scroll + max_choice - 1], max_choice - 1, TRUE); print_arrows(dialog, choice, item_no, scroll, box_y, box_x + check_x + 5, list_height); wnoutrefresh(dialog); wrefresh(list); continue; /* wait for another key press */ } else i = choice + 1; } if (i != choice) { /* De-highlight current item */ print_item(list, items[(scroll + choice) * 3 + 1], status[scroll + choice], choice, FALSE); /* Highlight new item */ choice = i; print_item(list, items[(scroll + choice) * 3 + 1], status[scroll + choice], choice, TRUE); wnoutrefresh(dialog); wrefresh(list); } continue; /* wait for another key press */ } switch (key) { case 'H': case 'h': case '?': fprintf(stderr, "%s", items[(scroll + choice) * 3]); delwin(dialog); free(status); return 1; case TAB: case KEY_LEFT: case KEY_RIGHT: button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button); print_buttons(dialog, height, width, button); wrefresh(dialog); break; case 'S': case 's': case ' ': case '\n': if (!button) { if (!status[scroll + choice]) { for (i = 0; i < item_no; i++) status[i] = 0; status[scroll + choice] = 1; for (i = 0; i < max_choice; i++) print_item(list, items[(scroll + i) * 3 + 1], status[scroll + i], i, i == choice); } wnoutrefresh(dialog); wrefresh(list); for (i = 0; i < item_no; i++) if (status[i]) fprintf(stderr, "%s", items[i * 3]); } else fprintf(stderr, "%s", items[(scroll + choice) * 3]); delwin(dialog); free(status); return button; case 'X': case 'x': key = ESC; case ESC: break; } /* Now, update everything... */ doupdate(); } delwin(dialog); free(status); return -1; /* ESC pressed */ }
/* * do_chase: * Make one thing chase another. */ void do_chase(struct thing *th, int flee) { register struct room *rer, *ree, /* room of chaser, room of chasee */ *old_room, /* old room of monster */ *new_room; /* new room of monster */ register int mindist = MAXINT, maxdist = MININT, dist = MININT, i, last_door = -1; /* Door we just came from */ register int stoprun = FALSE, /* TRUE means we are there */ rundoor; /* TRUE means run to a door */ int mdead = 0; register int sch; coord this; /* Temporary destination for chaser */ /* Make sure the monster can move */ if (th->t_no_move != 0) { th->t_no_move--; return; } rer = roomin(&th->t_pos); /* Find room of chaser */ ree = roomin(th->t_dest); /* Find room of chasee */ /* * We don't count doors as inside rooms for this routine */ if (mvwinch(stdscr, th->t_pos.y, th->t_pos.x) == DOOR) rer = NULL; this = *th->t_dest; /* * If we are not in a corridor and not a Xorn, then if we are running * after the player, we run to a door if he is not in the same room. * If we are fleeing, we run to a door if he IS in the same room. * Note: We don't bother with doors in mazes. */ if (levtype != MAZELEV && rer != NULL && off(*th, CANINWALL)) { if (flee) rundoor = (rer == ree); else rundoor = (rer != ree); } else rundoor = FALSE; if (rundoor) { coord exit; /* A particular door */ int exity, exitx; /* Door's coordinates */ if (th->t_doorgoal != -1) { /* Do we already have the goal? */ this = rer->r_exit[th->t_doorgoal]; dist = 0; /* Indicate that we have our door */ } else for (i = 0; i < rer->r_nexits; i++) { /* Loop through doors */ exit = rer->r_exit[i]; exity = exit.y; exitx = exit.x; /* Avoid secret doors */ if (mvwinch(stdscr, exity, exitx) == DOOR) { /* Were we just on this door? */ if (ce(exit, th->t_oldpos)) last_door = i; else { dist = DISTANCE(th->t_dest->y, th->t_dest->x, exity, exitx); /* If fleeing, we want to maximize distance from door to * what we flee, and minimize distance from door to us. */ if (flee) dist -= DISTANCE(th->t_pos.y, th->t_pos.x, exity, exitx); /* Maximize distance if fleeing, otherwise minimize it */ if ((flee && (dist > maxdist)) || (!flee && (dist < mindist))) { th->t_doorgoal = i; /* Use this door */ this = exit; mindist = maxdist = dist; } } } } /* Could we not find a door? */ if (dist == MININT) { /* If we were on a door, go ahead and use it */ if (last_door != -1) { th->t_doorgoal = last_door; this = th->t_oldpos; dist = 0; /* Indicate that we found a door */ } } /* Indicate that we do not want to flee from the door */ if (dist != MININT) flee = FALSE; } else th->t_doorgoal = -1; /* Not going to any door */ /* * this now contains what we want to run to this time * so we run to it. If we hit it we either want to fight it * or stop running */ if (!chase(th, &this, flee, &mdead)) { if (ce(ch_ret, hero)) { /* merchants try to sell something */ if (on(*th, CANSELL)) sell(th); else if (on(*th, ISCHARMED)) {} /* future enhancements */ else if (on(*th, ISFRIENDLY)) {} else attack(th, NULL, FALSE); return; } else if (on(*th, NOMOVE)) stoprun = TRUE; } if (on(*th, ISDEAD)) return; /* Did monster get itself killed? */ if (on(*th, NOMOVE)) return; /* If we have a scavenger, it can pick something up */ if (on(*th, ISSCAVENGE)) { register struct linked_list *item; if ((item = find_obj(ch_ret.y, ch_ret.x)) != NULL) { register int floor = (roomin(&ch_ret) == NULL) ? PASSAGE : FLOOR; detach(lvl_obj, item); mvaddch(ch_ret.y, ch_ret.x, floor); mvwaddch(cw, ch_ret.y, ch_ret.x, floor); attach(th->t_pack, item); } } mvwaddch(cw, th->t_pos.y, th->t_pos.x, th->t_oldch); sch = CCHAR( mvwinch(cw, ch_ret.y, ch_ret.x) ); /* Get old and new room of monster */ old_room=roomin(&th->t_pos); new_room=roomin(&ch_ret); /* If the monster can illuminate rooms, check for a change */ if (on(*th, HASFIRE)) { /* Is monster entering a room? */ if (old_room != new_room && new_room != NULL) { new_room->r_flags |= HASFIRE; new_room->r_fires++; if (cansee(ch_ret.y, ch_ret.x) && new_room->r_fires == 1) light(&hero); } /* Is monster leaving a room? */ if (old_room != new_room && old_room != NULL) { if (--(old_room->r_fires) <= 0) { old_room->r_flags &= ~HASFIRE; if (cansee(th->t_pos.y, th->t_pos.x)) light(&th->t_pos); } } } /* If monster is entering player's room and player can see it, * stop the player's running. */ if (new_room != old_room && new_room != NULL && new_room == ree && cansee(unc(ch_ret)) && (off(*th, ISINVIS) || (off(*th, ISSHADOW) || rnd(10) == 0) || on(player, CANSEE)) && off(*th, CANSURPRISE)) running = FALSE; if (rer != NULL && (rer->r_flags & ISDARK) && !(rer->r_flags & HASFIRE) && sch == FLOOR && DISTANCE(ch_ret.y, ch_ret.x, th->t_pos.y, th->t_pos.x) < see_dist && off(player, ISBLIND)) th->t_oldch = ' '; else th->t_oldch = sch; if (cansee(unc(ch_ret)) && off(*th, ISINWALL) && ((off(*th, ISINVIS) && (off(*th, ISSHADOW) || rnd(100) < 10)) || on(player, CANSEE)) && off(*th, CANSURPRISE)) mvwaddch(cw, ch_ret.y, ch_ret.x, th->t_type); mvwaddch(mw, th->t_pos.y, th->t_pos.x, ' '); mvwaddch(mw, ch_ret.y, ch_ret.x, th->t_type); /* Record monster's last position (if new one is different) */ if (!ce(ch_ret, th->t_pos)) th->t_oldpos = th->t_pos; th->t_pos = ch_ret; /* Mark the monster's new position */ /* If the monster is on a trap, trap it */ sch = CCHAR( mvinch(ch_ret.y, ch_ret.x) ); if (isatrap(sch)) { debug("Monster trapped by %c.", sch); if (cansee(ch_ret.y, ch_ret.x)) th->t_oldch = sch; be_trapped(th, &ch_ret); } /* * And stop running if need be */ if (stoprun && ce(th->t_pos, *(th->t_dest))) turn_off(*th, ISRUN); }
static void cmd_space(key_info_t key_info, keys_info_t *keys_info) { char c; changed = 1; if(perms[permnum] < 0) { c = ' '; perms[permnum] = 0; } else if(curr == 5 || curr == 10 || curr == 15) { int i = curr/5 - 1; if(!perms[permnum]) { c = '*'; perms[permnum] = 1; } else { if(!adv_perms[i]) { c = 'd'; } else { if(origin_perms[permnum] < 0) { c = 'X'; perms[permnum] = -1; } else { c = ' '; perms[permnum] = 0; } } adv_perms[i] = !adv_perms[i]; } } else if(origin_perms[permnum] < 0) { if(perms[permnum] > 0) { c = 'X'; perms[permnum] = -1; } else if(perms[permnum] == 0) { c = '*'; perms[permnum] = 1; } else { c = ' '; perms[permnum] = 0; } } else { c = perms[permnum] ? ' ' : '*'; perms[permnum] = !perms[permnum]; } mvwaddch(change_win, curr, col, c); checked_wmove(change_win, curr, col); wrefresh(change_win); }
// Pick up items at (pos). void Pickup::pick_up( const tripoint &p, int min ) { int cargo_part = -1; const optional_vpart_position vp = g->m.veh_at( p ); vehicle *const veh = veh_pointer_or_null( vp ); bool from_vehicle = false; if( min != -1 ) { veh_interact_results get_items_from = ITEMS_FROM_GROUND; if( veh != nullptr ) { get_items_from = veh->interact_with( p, vp->part_index() ); } switch( get_items_from ) { case DONE: return; case ITEMS_FROM_CARGO: { const cata::optional<vpart_reference> carg = vp.part_with_feature( "CARGO", false ); cargo_part = carg ? carg->part_index() : -1; from_vehicle = cargo_part >= 0; break; } case ITEMS_FROM_GROUND: // Nothing to change, default is to pick from ground anyway. if( g->m.has_flag( "SEALED", p ) ) { return; } break; } } if( !from_vehicle ) { bool isEmpty = ( g->m.i_at( p ).empty() ); // Hide the pickup window if this is a toilet and there's nothing here // but water. if( ( !isEmpty ) && g->m.furn( p ) == f_toilet ) { isEmpty = true; for( const item &maybe_water : g->m.i_at( p ) ) { if( maybe_water.typeId() != "water" ) { isEmpty = false; break; } } } if( isEmpty && ( min != -1 || !get_option<bool>( "AUTO_PICKUP_ADJACENT" ) ) ) { return; } } // which items are we grabbing? std::vector<item> here; if( from_vehicle ) { auto vehitems = veh->get_items( cargo_part ); here.resize( vehitems.size() ); std::copy( vehitems.begin(), vehitems.end(), here.begin() ); } else { auto mapitems = g->m.i_at( p ); here.resize( mapitems.size() ); std::copy( mapitems.begin(), mapitems.end(), here.begin() ); } if( min == -1 ) { // Recursively pick up adjacent items if that option is on. if( get_option<bool>( "AUTO_PICKUP_ADJACENT" ) && g->u.pos() == p ) { //Autopickup adjacent direction adjacentDir[8] = {NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, NORTHWEST}; for( auto &elem : adjacentDir ) { tripoint apos = tripoint( direction_XY( elem ), 0 ); apos += p; pick_up( apos, min ); } } // Bail out if this square cannot be auto-picked-up if( g->check_zone( zone_type_id( "NO_AUTO_PICKUP" ), p ) ) { return; } else if( g->m.has_flag( "SEALED", p ) ) { return; } } // Not many items, just grab them if( static_cast<int>( here.size() ) <= min && min != -1 ) { g->u.assign_activity( activity_id( "ACT_PICKUP" ) ); g->u.activity.placement = p - g->u.pos(); g->u.activity.values.push_back( from_vehicle ); // Only one item means index is 0. g->u.activity.values.push_back( 0 ); // auto-pickup means pick up all. g->u.activity.values.push_back( 0 ); return; } std::vector<std::list<item_idx>> stacked_here; for( size_t i = 0; i < here.size(); i++ ) { item &it = here[i]; bool found_stack = false; for( auto &stack : stacked_here ) { if( stack.begin()->_item.stacks_with( it ) ) { item_idx el = { it, i }; stack.push_back( el ); found_stack = true; break; } } if( !found_stack ) { std::list<item_idx> newstack; newstack.push_back( { it, i } ); stacked_here.push_back( newstack ); } } std::reverse( stacked_here.begin(), stacked_here.end() ); if( min != -1 ) { // don't bother if we're just autopickuping g->temp_exit_fullscreen(); } // Otherwise, we have Autopickup, 2 or more items and should list them, etc. int maxmaxitems = TERMY; int itemsH = std::min( 25, TERMY / 2 ); int pickupBorderRows = 3; // The pickup list may consume the entire terminal, minus space needed for its // header/footer and the item info window. int minleftover = itemsH + pickupBorderRows; if( maxmaxitems > TERMY - minleftover ) { maxmaxitems = TERMY - minleftover; } const int minmaxitems = 9; std::vector<pickup_count> getitem( stacked_here.size() ); int maxitems = stacked_here.size(); maxitems = ( maxitems < minmaxitems ? minmaxitems : ( maxitems > maxmaxitems ? maxmaxitems : maxitems ) ); int itemcount = 0; if( min == -1 ) { //Auto Pickup, select matching items if( !select_autopickup_items( stacked_here, getitem ) ) { // If we didn't find anything, bail out now. return; } } else { int pickupH = maxitems + pickupBorderRows; int pickupW = 44; int itemsW = pickupW; catacurses::window w_pickup = catacurses::newwin( pickupH, pickupW, 0, 0 ); catacurses::window w_item_info = catacurses::newwin( TERMY - pickupH, pickupW, pickupH, 0 ); std::string action; long raw_input_char = ' '; input_context ctxt( "PICKUP" ); ctxt.register_action( "UP" ); ctxt.register_action( "DOWN" ); ctxt.register_action( "RIGHT" ); ctxt.register_action( "LEFT" ); ctxt.register_action( "NEXT_TAB", _( "Next page" ) ); ctxt.register_action( "PREV_TAB", _( "Previous page" ) ); ctxt.register_action( "SCROLL_UP" ); ctxt.register_action( "SCROLL_DOWN" ); ctxt.register_action( "CONFIRM" ); ctxt.register_action( "SELECT_ALL" ); ctxt.register_action( "QUIT", _( "Cancel" ) ); ctxt.register_action( "ANY_INPUT" ); ctxt.register_action( "HELP_KEYBINDINGS" ); ctxt.register_action( "FILTER" ); #if defined(__ANDROID__) ctxt.allow_text_entry = true; // allow user to specify pickup amount #endif int start = 0; int cur_it = 0; bool update = true; mvwprintw( w_pickup, 0, 0, _( "PICK" ) ); int selected = 0; int iScrollPos = 0; std::string filter; std::string new_filter; std::vector<int> matches;//Indexes of items that match the filter bool filter_changed = true; if( g->was_fullscreen ) { g->draw_ter(); } // Now print the two lists; those on the ground and about to be added to inv // Continue until we hit return or space do { const std::string pickup_chars = ctxt.get_available_single_char_hotkeys( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ:;" ); int idx = -1; for( int i = 1; i < pickupH; i++ ) { mvwprintw( w_pickup, i, 0, " " ); } if( action == "ANY_INPUT" && raw_input_char >= '0' && raw_input_char <= '9' ) { int raw_input_char_value = static_cast<char>( raw_input_char ) - '0'; itemcount *= 10; itemcount += raw_input_char_value; if( itemcount < 0 ) { itemcount = 0; } } else if( action == "SCROLL_UP" ) { iScrollPos--; } else if( action == "SCROLL_DOWN" ) { iScrollPos++; } else if( action == "PREV_TAB" ) { if( start > 0 ) { start -= maxitems; } else { start = static_cast<int>( ( matches.size() - 1 ) / maxitems ) * maxitems; } selected = start; mvwprintw( w_pickup, maxitems + 2, 0, " " ); } else if( action == "NEXT_TAB" ) { if( start + maxitems < static_cast<int>( matches.size() ) ) { start += maxitems; } else { start = 0; } iScrollPos = 0; selected = start; mvwprintw( w_pickup, maxitems + 2, pickupH, " " ); } else if( action == "UP" ) { selected--; iScrollPos = 0; if( selected < 0 ) { selected = matches.size() - 1; start = static_cast<int>( matches.size() / maxitems ) * maxitems; if( start >= static_cast<int>( matches.size() ) ) { start -= maxitems; } } else if( selected < start ) { start -= maxitems; } } else if( action == "DOWN" ) { selected++; iScrollPos = 0; if( selected >= static_cast<int>( matches.size() ) ) { selected = 0; start = 0; } else if( selected >= start + maxitems ) { start += maxitems; } } else if( selected >= 0 && selected < static_cast<int>( matches.size() ) && ( ( action == "RIGHT" && !getitem[matches[selected]].pick ) || ( action == "LEFT" && getitem[matches[selected]].pick ) ) ) { idx = selected; } else if( action == "FILTER" ) { new_filter = filter; string_input_popup popup; popup .title( _( "Set filter" ) ) .width( 30 ) .edit( new_filter ); if( !popup.canceled() ) { filter_changed = true; } else { wrefresh( g->w_terrain ); g->draw_panels(); } } else if( action == "ANY_INPUT" && raw_input_char == '`' ) { std::string ext = string_input_popup() .title( _( "Enter 2 letters (case sensitive):" ) ) .width( 3 ) .max_length( 2 ) .query_string(); if( ext.size() == 2 ) { int p1 = pickup_chars.find( ext.at( 0 ) ); int p2 = pickup_chars.find( ext.at( 1 ) ); if( p1 != -1 && p2 != -1 ) { idx = pickup_chars.size() + ( p1 * pickup_chars.size() ) + p2; } } } else if( action == "ANY_INPUT" ) { idx = ( raw_input_char <= 127 ) ? pickup_chars.find( raw_input_char ) : -1; iScrollPos = 0; } if( idx >= 0 && idx < static_cast<int>( matches.size() ) ) { size_t true_idx = matches[idx]; if( itemcount != 0 || getitem[true_idx].count == 0 ) { item &temp = stacked_here[true_idx].begin()->_item; int amount_available = temp.count_by_charges() ? temp.charges : stacked_here[true_idx].size(); if( itemcount >= amount_available ) { itemcount = 0; } getitem[true_idx].count = itemcount; itemcount = 0; } // Note: this might not change the value of getitem[idx] at all! getitem[true_idx].pick = ( action == "RIGHT" ? true : ( action == "LEFT" ? false : !getitem[true_idx].pick ) ); if( action != "RIGHT" && action != "LEFT" ) { selected = idx; start = static_cast<int>( idx / maxitems ) * maxitems; } if( !getitem[true_idx].pick ) { getitem[true_idx].count = 0; } update = true; } if( filter_changed ) { matches.clear(); while( matches.empty() ) { auto filter_func = item_filter_from_string( new_filter ); for( size_t index = 0; index < stacked_here.size(); index++ ) { if( filter_func( stacked_here[index].begin()->_item ) ) { matches.push_back( index ); } } if( matches.empty() ) { popup( _( "Your filter returned no results" ) ); wrefresh( g->w_terrain ); g->draw_panels(); // The filter must have results, or simply be emptied or canceled, // as this screen can't be reached without there being // items available string_input_popup popup; popup .title( _( "Set filter" ) ) .width( 30 ) .edit( new_filter ); if( popup.canceled() ) { new_filter = filter; filter_changed = false; } } } if( filter_changed ) { filter = new_filter; filter_changed = false; selected = 0; start = 0; iScrollPos = 0; } wrefresh( g->w_terrain ); g->draw_panels(); } item &selected_item = stacked_here[matches[selected]].begin()->_item; werase( w_item_info ); if( selected >= 0 && selected <= static_cast<int>( stacked_here.size() ) - 1 ) { std::vector<iteminfo> vThisItem; std::vector<iteminfo> vDummy; selected_item.info( true, vThisItem ); draw_item_info( w_item_info, "", "", vThisItem, vDummy, iScrollPos, true, true ); } draw_custom_border( w_item_info, 0 ); mvwprintw( w_item_info, 0, 2, "< " ); trim_and_print( w_item_info, 0, 4, itemsW - 8, c_white, "%s >", selected_item.display_name() ); wrefresh( w_item_info ); if( action == "SELECT_ALL" ) { int count = 0; for( auto i : matches ) { if( getitem[i].pick ) { count++; } getitem[i].pick = true; } if( count == static_cast<int>( stacked_here.size() ) ) { for( size_t i = 0; i < stacked_here.size(); i++ ) { getitem[i].pick = false; } } update = true; } for( cur_it = start; cur_it < start + maxitems; cur_it++ ) { mvwprintw( w_pickup, 1 + ( cur_it % maxitems ), 0, " " ); if( cur_it < static_cast<int>( matches.size() ) ) { int true_it = matches[cur_it]; item &this_item = stacked_here[ true_it ].begin()->_item; nc_color icolor = this_item.color_in_inventory(); if( cur_it == selected ) { icolor = hilite( c_white ); } if( cur_it < static_cast<int>( pickup_chars.size() ) ) { mvwputch( w_pickup, 1 + ( cur_it % maxitems ), 0, icolor, static_cast<char>( pickup_chars[cur_it] ) ); } else if( cur_it < static_cast<int>( pickup_chars.size() ) + static_cast<int> ( pickup_chars.size() ) * static_cast<int>( pickup_chars.size() ) ) { int p = cur_it - pickup_chars.size(); int p1 = p / pickup_chars.size(); int p2 = p % pickup_chars.size(); mvwprintz( w_pickup, 1 + ( cur_it % maxitems ), 0, icolor, "`%c%c", static_cast<char>( pickup_chars[p1] ), static_cast<char>( pickup_chars[p2] ) ); } else { mvwputch( w_pickup, 1 + ( cur_it % maxitems ), 0, icolor, ' ' ); } if( getitem[true_it].pick ) { if( getitem[true_it].count == 0 ) { wprintz( w_pickup, c_light_blue, " + " ); } else { wprintz( w_pickup, c_light_blue, " # " ); } } else { wprintw( w_pickup, " - " ); } std::string item_name; if( stacked_here[true_it].begin()->_item.ammo_type() == "money" ) { //Count charges // TODO: transition to the item_location system used for the inventory unsigned long charges_total = 0; for( const auto &item : stacked_here[true_it] ) { charges_total += item._item.charges; } //Picking up none or all the cards in a stack if( !getitem[true_it].pick || getitem[true_it].count == 0 ) { item_name = stacked_here[true_it].begin()->_item.display_money( stacked_here[true_it].size(), charges_total ); } else { unsigned long charges = 0; int c = getitem[true_it].count; for( auto it = stacked_here[true_it].begin(); it != stacked_here[true_it].end() && c > 0; ++it, --c ) { charges += it->_item.charges; } item_name = string_format( _( "%s of %s" ), stacked_here[true_it].begin()->_item.display_money( getitem[true_it].count, charges ), format_money( charges_total ) ); } } else { item_name = this_item.display_name( stacked_here[true_it].size() ); } if( stacked_here[true_it].size() > 1 ) { item_name = string_format( "%d %s", stacked_here[true_it].size(), item_name ); } if( get_option<bool>( "ITEM_SYMBOLS" ) ) { item_name = string_format( "%s %s", this_item.symbol(), item_name ); } trim_and_print( w_pickup, 1 + ( cur_it % maxitems ), 6, pickupW - 4, icolor, item_name ); } } mvwprintw( w_pickup, maxitems + 1, 0, _( "[%s] Unmark" ), ctxt.get_desc( "LEFT", 1 ) ); center_print( w_pickup, maxitems + 1, c_light_gray, string_format( _( "[%s] Help" ), ctxt.get_desc( "HELP_KEYBINDINGS", 1 ) ) ); right_print( w_pickup, maxitems + 1, 0, c_light_gray, string_format( _( "[%s] Mark" ), ctxt.get_desc( "RIGHT", 1 ) ) ); mvwprintw( w_pickup, maxitems + 2, 0, _( "[%s] Prev" ), ctxt.get_desc( "PREV_TAB", 1 ) ); center_print( w_pickup, maxitems + 2, c_light_gray, string_format( _( "[%s] All" ), ctxt.get_desc( "SELECT_ALL", 1 ) ) ); right_print( w_pickup, maxitems + 2, 0, c_light_gray, string_format( _( "[%s] Next" ), ctxt.get_desc( "NEXT_TAB", 1 ) ) ); if( update ) { // Update weight & volume information update = false; for( int i = 9; i < pickupW; ++i ) { mvwaddch( w_pickup, 0, i, ' ' ); } units::mass weight_picked_up = 0_gram; units::volume volume_picked_up = 0_ml; for( size_t i = 0; i < getitem.size(); i++ ) { if( getitem[i].pick ) { item temp = stacked_here[i].begin()->_item; if( temp.count_by_charges() && getitem[i].count < temp.charges && getitem[i].count != 0 ) { temp.charges = getitem[i].count; } int num_picked = std::min( stacked_here[i].size(), getitem[i].count == 0 ? stacked_here[i].size() : getitem[i].count ); weight_picked_up += temp.weight() * num_picked; volume_picked_up += temp.volume() * num_picked; } } auto weight_predict = g->u.weight_carried() + weight_picked_up; auto volume_predict = g->u.volume_carried() + volume_picked_up; mvwprintz( w_pickup, 0, 5, weight_predict > g->u.weight_capacity() ? c_red : c_white, _( "Wgt %.1f" ), round_up( convert_weight( weight_predict ), 1 ) ); wprintz( w_pickup, c_white, "/%.1f", round_up( convert_weight( g->u.weight_capacity() ), 1 ) ); std::string fmted_volume_predict = format_volume( volume_predict ); mvwprintz( w_pickup, 0, 18, volume_predict > g->u.volume_capacity() ? c_red : c_white, _( "Vol %s" ), fmted_volume_predict ); std::string fmted_volume_capacity = format_volume( g->u.volume_capacity() ); wprintz( w_pickup, c_white, "/%s", fmted_volume_capacity ); } wrefresh( w_pickup ); action = ctxt.handle_input(); raw_input_char = ctxt.get_raw_input().get_first_input(); } while( action != "QUIT" && action != "CONFIRM" ); bool item_selected = false; // Check if we have selected an item. for( auto selection : getitem ) { if( selection.pick ) { item_selected = true; } } if( action != "CONFIRM" || !item_selected ) { w_pickup = catacurses::window(); w_item_info = catacurses::window(); add_msg( _( "Never mind." ) ); g->reenter_fullscreen(); g->refresh_all(); return; } } // At this point we've selected our items, register an activity to pick them up. g->u.assign_activity( activity_id( "ACT_PICKUP" ) ); g->u.activity.placement = p - g->u.pos(); g->u.activity.values.push_back( from_vehicle ); if( min == -1 ) { // Auto pickup will need to auto resume since there can be several of them on the stack. g->u.activity.auto_resume = true; } std::vector<std::pair<int, int>> pick_values; for( size_t i = 0; i < stacked_here.size(); i++ ) { const auto &selection = getitem[i]; if( !selection.pick ) { continue; } const auto &stack = stacked_here[i]; // Note: items can be both charged and stacked // For robustness, let's assume they can be both in the same stack bool pick_all = selection.count == 0; size_t count = selection.count; for( const item_idx &it : stack ) { if( !pick_all && count == 0 ) { break; } if( it._item.count_by_charges() ) { size_t num_picked = std::min( static_cast<size_t>( it._item.charges ), count ); pick_values.push_back( { static_cast<int>( it.idx ), static_cast<int>( num_picked ) } ); count -= num_picked; } else { size_t num_picked = 1; pick_values.push_back( { static_cast<int>( it.idx ), 0 } ); count -= num_picked; } } } // The pickup activity picks up items last-to-first from its values list, so make sure the // higher indices are at the end. std::sort( pick_values.begin(), pick_values.end() ); for( auto &it : pick_values ) { g->u.activity.values.push_back( it.first ); g->u.activity.values.push_back( it.second ); } g->reenter_fullscreen(); }
int mvaddch(int y, int x, const chtype ch) { return mvwaddch(mainwin,y,x,ch); };
void main() { void done(); int loopy; initscr(); noecho(); nonl(); refresh(); signal(SIGINT,done); signal(SIGTERM,done); #if !defined DOS && !defined OS2 signal(SIGHUP,done); signal(SIGQUIT,done); #endif treescrn = newwin(16,27,3,53); treescrn2 = newwin(16,27,3,53); treescrn3 = newwin(16,27,3,53); treescrn4 = newwin(16,27,3,53); treescrn5 = newwin(16,27,3,53); treescrn6 = newwin(16,27,3,53); treescrn7 = newwin(16,27,3,53); treescrn8 = newwin(16,27,3,53); dotdeer0 = newwin(3,71,0,8); stardeer0 = newwin(4,56,0,8); lildeer0 = newwin(7,53,0,8); lildeer1 = newwin(2,4,0,0); lildeer2 = newwin(2,4,0,0); lildeer3 = newwin(2,4,0,0); middeer0 = newwin(15,42,0,8); middeer1 = newwin(3,7,0,0); middeer2 = newwin(3,7,0,0); middeer3 = newwin(3,7,0,0); bigdeer0 = newwin(10,23,0,0); bigdeer1 = newwin(10,23,0,0); bigdeer2 = newwin(10,23,0,0); bigdeer3 = newwin(10,23,0,0); bigdeer4 = newwin(10,23,0,0); lookdeer0 = newwin(10,25,0,0); lookdeer1 = newwin(10,25,0,0); lookdeer2 = newwin(10,25,0,0); lookdeer3 = newwin(10,25,0,0); lookdeer4 = newwin(10,25,0,0); w_holiday = newwin(1,26,3,27); w_del_msg = newwin(1,12,23,60); mvwaddstr(w_del_msg,0,0,"Hit any key to quit"); mvwaddstr(w_holiday,0,0,"H A P P Y H O L I D A Y S"); /* set up the windows for our various reindeer */ /* lildeer1 */ mvwaddch(lildeer1,0,0,(chtype)'V'); mvwaddch(lildeer1,1,0,(chtype)'@'); mvwaddch(lildeer1,1,1,(chtype)'<'); mvwaddch(lildeer1,1,2,(chtype)'>'); mvwaddch(lildeer1,1,3,(chtype)'~'); /* lildeer2 */ mvwaddch(lildeer2,0,0,(chtype)'V'); mvwaddch(lildeer2,1,0,(chtype)'@'); mvwaddch(lildeer2,1,1,(chtype)'|'); mvwaddch(lildeer2,1,2,(chtype)'|'); mvwaddch(lildeer2,1,3,(chtype)'~'); /* lildeer3 */ mvwaddch(lildeer3,0,0,(chtype)'V'); mvwaddch(lildeer3,1,0,(chtype)'@'); mvwaddch(lildeer3,1,1,(chtype)'>'); mvwaddch(lildeer3,1,2,(chtype)'<'); mvwaddch(lildeer2,1,3,(chtype)'~'); /* middeer1 */ mvwaddch(middeer1,0,2,(chtype)'y'); mvwaddch(middeer1,0,3,(chtype)'y'); mvwaddch(middeer1,1,2,(chtype)'0'); mvwaddch(middeer1,1,3,(chtype)'('); mvwaddch(middeer1,1,4,(chtype)'='); mvwaddch(middeer1,1,5,(chtype)')'); mvwaddch(middeer1,1,6,(chtype)'~'); mvwaddch(middeer1,2,3,(chtype)'\\'); mvwaddch(middeer1,2,4,(chtype)'/'); /* middeer2 */ mvwaddch(middeer2,0,2,(chtype)'y'); mvwaddch(middeer2,0,3,(chtype)'y'); mvwaddch(middeer2,1,2,(chtype)'0'); mvwaddch(middeer2,1,3,(chtype)'('); mvwaddch(middeer2,1,4,(chtype)'='); mvwaddch(middeer2,1,5,(chtype)')'); mvwaddch(middeer2,1,6,(chtype)'~'); mvwaddch(middeer2,2,3,(chtype)'|'); mvwaddch(middeer2,2,5,(chtype)'|'); /* middeer3 */ mvwaddch(middeer3,0,2,(chtype)'y'); mvwaddch(middeer3,0,3,(chtype)'y'); mvwaddch(middeer3,1,2,(chtype)'0'); mvwaddch(middeer3,1,3,(chtype)'('); mvwaddch(middeer3,1,4,(chtype)'='); mvwaddch(middeer3,1,5,(chtype)')'); mvwaddch(middeer3,1,6,(chtype)'~'); mvwaddch(middeer3,2,2,(chtype)'/'); mvwaddch(middeer3,2,6,(chtype)'\\'); /* bigdeer1 */ mvwaddch(bigdeer1,0,17,(chtype)'\\'); mvwaddch(bigdeer1,0,18,(chtype)'/'); mvwaddch(bigdeer1,0,20,(chtype)'\\'); mvwaddch(bigdeer1,0,21,(chtype)'/'); mvwaddch(bigdeer1,1,18,(chtype)'\\'); mvwaddch(bigdeer1,1,20,(chtype)'/'); mvwaddch(bigdeer1,2,19,(chtype)'|'); mvwaddch(bigdeer1,2,20,(chtype)'_'); mvwaddch(bigdeer1,3,18,(chtype)'/'); mvwaddch(bigdeer1,3,19,(chtype)'^'); mvwaddch(bigdeer1,3,20,(chtype)'0'); mvwaddch(bigdeer1,3,21,(chtype)'\\'); mvwaddch(bigdeer1,4,17,(chtype)'/'); mvwaddch(bigdeer1,4,18,(chtype)'/'); mvwaddch(bigdeer1,4,19,(chtype)'\\'); mvwaddch(bigdeer1,4,22,(chtype)'\\'); mvwaddstr(bigdeer1,5,7,"^~~~~~~~~// ~~U"); mvwaddstr(bigdeer1,6,7,"( \\_____( /"); mvwaddstr(bigdeer1,7,8,"( ) /"); mvwaddstr(bigdeer1,8,9,"\\\\ /"); mvwaddstr(bigdeer1,9,11,"\\>/>"); /* bigdeer2 */ mvwaddch(bigdeer2,0,17,(chtype)'\\'); mvwaddch(bigdeer2,0,18,(chtype)'/'); mvwaddch(bigdeer2,0,20,(chtype)'\\'); mvwaddch(bigdeer2,0,21,(chtype)'/'); mvwaddch(bigdeer2,1,18,(chtype)'\\'); mvwaddch(bigdeer2,1,20,(chtype)'/'); mvwaddch(bigdeer2,2,19,(chtype)'|'); mvwaddch(bigdeer2,2,20,(chtype)'_'); mvwaddch(bigdeer2,3,18,(chtype)'/'); mvwaddch(bigdeer2,3,19,(chtype)'^'); mvwaddch(bigdeer2,3,20,(chtype)'0'); mvwaddch(bigdeer2,3,21,(chtype)'\\'); mvwaddch(bigdeer2,4,17,(chtype)'/'); mvwaddch(bigdeer2,4,18,(chtype)'/'); mvwaddch(bigdeer2,4,19,(chtype)'\\'); mvwaddch(bigdeer2,4,22,(chtype)'\\'); mvwaddstr(bigdeer2,5,7,"^~~~~~~~~// ~~U"); mvwaddstr(bigdeer2,6,7,"(( )____( /"); mvwaddstr(bigdeer2,7,7,"( / |"); mvwaddstr(bigdeer2,8,8,"\\/ |"); mvwaddstr(bigdeer2,9,9,"|> |>"); /* bigdeer3 */ mvwaddch(bigdeer3,0,17,(chtype)'\\'); mvwaddch(bigdeer3,0,18,(chtype)'/'); mvwaddch(bigdeer3,0,20,(chtype)'\\'); mvwaddch(bigdeer3,0,21,(chtype)'/'); mvwaddch(bigdeer3,1,18,(chtype)'\\'); mvwaddch(bigdeer3,1,20,(chtype)'/'); mvwaddch(bigdeer3,2,19,(chtype)'|'); mvwaddch(bigdeer3,2,20,(chtype)'_'); mvwaddch(bigdeer3,3,18,(chtype)'/'); mvwaddch(bigdeer3,3,19,(chtype)'^'); mvwaddch(bigdeer3,3,20,(chtype)'0'); mvwaddch(bigdeer3,3,21,(chtype)'\\'); mvwaddch(bigdeer3,4,17,(chtype)'/'); mvwaddch(bigdeer3,4,18,(chtype)'/'); mvwaddch(bigdeer3,4,19,(chtype)'\\'); mvwaddch(bigdeer3,4,22,(chtype)'\\'); mvwaddstr(bigdeer3,5,7,"^~~~~~~~~// ~~U"); mvwaddstr(bigdeer3,6,6,"( ()_____( /"); mvwaddstr(bigdeer3,7,6,"/ / /"); mvwaddstr(bigdeer3,8,5,"|/ \\"); mvwaddstr(bigdeer3,9,5,"/> \\>"); /* bigdeer4 */ mvwaddch(bigdeer4,0,17,(chtype)'\\'); mvwaddch(bigdeer4,0,18,(chtype)'/'); mvwaddch(bigdeer4,0,20,(chtype)'\\'); mvwaddch(bigdeer4,0,21,(chtype)'/'); mvwaddch(bigdeer4,1,18,(chtype)'\\'); mvwaddch(bigdeer4,1,20,(chtype)'/'); mvwaddch(bigdeer4,2,19,(chtype)'|'); mvwaddch(bigdeer4,2,20,(chtype)'_'); mvwaddch(bigdeer4,3,18,(chtype)'/'); mvwaddch(bigdeer4,3,19,(chtype)'^'); mvwaddch(bigdeer4,3,20,(chtype)'0'); mvwaddch(bigdeer4,3,21,(chtype)'\\'); mvwaddch(bigdeer4,4,17,(chtype)'/'); mvwaddch(bigdeer4,4,18,(chtype)'/'); mvwaddch(bigdeer4,4,19,(chtype)'\\'); mvwaddch(bigdeer4,4,22,(chtype)'\\'); mvwaddstr(bigdeer4,5,7,"^~~~~~~~~// ~~U"); mvwaddstr(bigdeer4,6,6,"( )______( /"); mvwaddstr(bigdeer4,7,5,"(/ \\"); mvwaddstr(bigdeer4,8,0,"v___= ----^"); /* lookdeer1 */ mvwaddstr(lookdeer1,0,16,"\\/ \\/"); mvwaddstr(lookdeer1,1,17,"\\Y/ \\Y/"); mvwaddstr(lookdeer1,2,19,"\\=/"); mvwaddstr(lookdeer1,3,17,"^\\o o/^"); mvwaddstr(lookdeer1,4,17,"//( )"); mvwaddstr(lookdeer1,5,7,"^~~~~~~~~// \\O/"); mvwaddstr(lookdeer1,6,7,"( \\_____( /"); mvwaddstr(lookdeer1,7,8,"( ) /"); mvwaddstr(lookdeer1,8,9,"\\\\ /"); mvwaddstr(lookdeer1,9,11,"\\>/>"); /* lookdeer2 */ mvwaddstr(lookdeer2,0,16,"\\/ \\/"); mvwaddstr(lookdeer2,1,17,"\\Y/ \\Y/"); mvwaddstr(lookdeer2,2,19,"\\=/"); mvwaddstr(lookdeer2,3,17,"^\\o o/^"); mvwaddstr(lookdeer2,4,17,"//( )"); mvwaddstr(lookdeer2,5,7,"^~~~~~~~~// \\O/"); mvwaddstr(lookdeer2,6,7,"(( )____( /"); mvwaddstr(lookdeer2,7,7,"( / |"); mvwaddstr(lookdeer2,8,8,"\\/ |"); mvwaddstr(lookdeer2,9,9,"|> |>"); /* lookdeer3 */ mvwaddstr(lookdeer3,0,16,"\\/ \\/"); mvwaddstr(lookdeer3,1,17,"\\Y/ \\Y/"); mvwaddstr(lookdeer3,2,19,"\\=/"); mvwaddstr(lookdeer3,3,17,"^\\o o/^"); mvwaddstr(lookdeer3,4,17,"//( )"); mvwaddstr(lookdeer3,5,7,"^~~~~~~~~// \\O/"); mvwaddstr(lookdeer3,6,6,"( ()_____( /"); mvwaddstr(lookdeer3,7,6,"/ / /"); mvwaddstr(lookdeer3,8,5,"|/ \\"); mvwaddstr(lookdeer3,9,5,"/> \\>"); /* lookdeer4 */ mvwaddstr(lookdeer4,0,16,"\\/ \\/"); mvwaddstr(lookdeer4,1,17,"\\Y/ \\Y/"); mvwaddstr(lookdeer4,2,19,"\\=/"); mvwaddstr(lookdeer4,3,17,"^\\o o/^"); mvwaddstr(lookdeer4,4,17,"//( )"); mvwaddstr(lookdeer4,5,7,"^~~~~~~~~// \\O/"); mvwaddstr(lookdeer4,6,6,"( )______( /"); mvwaddstr(lookdeer4,7,5,"(/ \\"); mvwaddstr(lookdeer4,8,0,"v___= ----^"); /***********************************************/ cbreak(); nodelay(stdscr,TRUE); do { clear(); werase(treescrn); touchwin(treescrn); werase(treescrn2); touchwin(treescrn2); werase(treescrn8); touchwin(treescrn8); refresh(); usleep(1000); boxit(); refresh(); usleep(1000); seas(); refresh(); usleep(1000); greet(); refresh(); usleep(1000); fromwho(); refresh(); usleep(1000); tree(); usleep(1000); balls(); usleep(1000); star(); usleep(1000); strng1(); strng2(); strng3(); strng4(); strng5(); /* set up the windows for our blinking trees */ /* **************************************** */ /* treescrn3 */ overlay(treescrn, treescrn3); /*balls*/ mvwaddch(treescrn3, 4, 18, ' '); mvwaddch(treescrn3, 7, 6, ' '); mvwaddch(treescrn3, 8, 19, ' '); mvwaddch(treescrn3, 11, 22, ' '); /*star*/ mvwaddch(treescrn3, 0, 12, '*'); /*strng1*/ mvwaddch(treescrn3, 3, 11, ' '); /*strng2*/ mvwaddch(treescrn3, 5, 13, ' '); mvwaddch(treescrn3, 6, 10, ' '); /*strng3*/ mvwaddch(treescrn3, 7, 16, ' '); mvwaddch(treescrn3, 7, 14, ' '); /*strng4*/ mvwaddch(treescrn3, 10, 13, ' '); mvwaddch(treescrn3, 10, 10, ' '); mvwaddch(treescrn3, 11, 8, ' '); /*strng5*/ mvwaddch(treescrn3, 11, 18, ' '); mvwaddch(treescrn3, 12, 13, ' '); /* treescrn4 */ overlay(treescrn, treescrn4); /*balls*/ mvwaddch(treescrn4, 3, 9, ' '); mvwaddch(treescrn4, 4, 16, ' '); mvwaddch(treescrn4, 7, 6, ' '); mvwaddch(treescrn4, 8, 19, ' '); mvwaddch(treescrn4, 11, 2, ' '); mvwaddch(treescrn4, 12, 23, ' '); /*star*/ wstandout(treescrn4); mvwaddch(treescrn4, 0, 12, '*'); wstandend(treescrn4); /*strng1*/ mvwaddch(treescrn4, 3, 13, ' '); /*strng2*/ /*strng3*/ mvwaddch(treescrn4, 7, 15, ' '); mvwaddch(treescrn4, 8, 11, ' '); /*strng4*/ mvwaddch(treescrn4, 9, 16, ' '); mvwaddch(treescrn4, 10, 12, ' '); mvwaddch(treescrn4, 11, 8, ' '); /*strng5*/ mvwaddch(treescrn4, 11, 18, ' '); mvwaddch(treescrn4, 12, 14, ' '); /* treescrn5 */ overlay(treescrn, treescrn5); /*balls*/ mvwaddch(treescrn5, 3, 15, ' '); mvwaddch(treescrn5, 10, 20, ' '); mvwaddch(treescrn5, 12, 1, ' '); /*star*/ mvwaddch(treescrn5, 0, 12, '*'); /*strng1*/ mvwaddch(treescrn5, 3, 11, ' '); /*strng2*/ mvwaddch(treescrn5, 5, 12, ' '); /*strng3*/ mvwaddch(treescrn5, 7, 14, ' '); mvwaddch(treescrn5, 8, 10, ' '); /*strng4*/ mvwaddch(treescrn5, 9, 15, ' '); mvwaddch(treescrn5, 10, 11, ' '); mvwaddch(treescrn5, 11, 7, ' '); /*strng5*/ mvwaddch(treescrn5, 11, 17, ' '); mvwaddch(treescrn5, 12, 13, ' '); /* treescrn6 */ overlay(treescrn, treescrn6); /*balls*/ mvwaddch(treescrn6, 6, 7, ' '); mvwaddch(treescrn6, 7, 18, ' '); mvwaddch(treescrn6, 10, 4, ' '); mvwaddch(treescrn6, 11, 23, ' '); /*star*/ wstandout(treescrn6); mvwaddch(treescrn6, 0, 12, '*'); wstandend(treescrn6); /*strng1*/ /*strng2*/ mvwaddch(treescrn6, 5, 11, ' '); /*strng3*/ mvwaddch(treescrn6, 7, 13, ' '); mvwaddch(treescrn6, 8, 9, ' '); /*strng4*/ mvwaddch(treescrn6, 9, 14, ' '); mvwaddch(treescrn6, 10, 10, ' '); mvwaddch(treescrn6, 11, 6, ' '); /*strng5*/ mvwaddch(treescrn6, 11, 16, ' '); mvwaddch(treescrn6, 12, 12, ' '); /* treescrn7 */ overlay(treescrn, treescrn7); /*balls*/ mvwaddch(treescrn7, 3, 15, ' '); mvwaddch(treescrn7, 6, 7, ' '); mvwaddch(treescrn7, 7, 18, ' '); mvwaddch(treescrn7, 10, 4, ' '); mvwaddch(treescrn7, 11, 22, ' '); /*star*/ mvwaddch(treescrn7, 0, 12, '*'); /*strng1*/ mvwaddch(treescrn7, 3, 12, ' '); /*strng2*/ mvwaddch(treescrn7, 5, 13, ' '); mvwaddch(treescrn7, 6, 9, ' '); /*strng3*/ mvwaddch(treescrn7, 7, 15, ' '); mvwaddch(treescrn7, 8, 11, ' '); /*strng4*/ mvwaddch(treescrn7, 9, 16, ' '); mvwaddch(treescrn7, 10, 12, ' '); mvwaddch(treescrn7, 11, 8, ' '); /*strng5*/ mvwaddch(treescrn7, 11, 18, ' '); mvwaddch(treescrn7, 12, 14, ' '); usleep(1000); reindeer(); touchwin(w_holiday); wrefresh(w_holiday); wrefresh(w_del_msg); usleep(1000); for(loopy = 0;loopy < 100;loopy++) { blinkit(); } #ifdef NOLOOP done(); #endif } while(getch() == (ERR)); /* while(!typeahead(stdin));*/ done(); }
void about(int scr) { /* initscr(); WINDOW *w; w=newwin (16,78,7,1); werase(w); setcolor (1,1); mvprintw (7,34,"LinuxEyes"); setcolor (1,1); mvprintw (9,2,"AUTHOR"); mvprintw (13,2,"COPYRIGHT"); mvprintw (17,2,"LOTS OF THANKS TO"); mvprintw (20,2,"BUGS AND SUGGESTIONS"); setcolor (1,0); mvprintw (10,5,"Alexandru Radovici - [email protected]"); mvprintw (11,5," [email protected]"); mvprintw (14,5,"This program is free. You may use it on your own risk. You may distribute"); mvprintw (15,2,"it only integral."); mvprintw (18,5,"Xaudio - http://www.xaudio.com"); mvprintw (21,5,"If you have found bugs or have some suggestions to make please send me an"); mvprintw (22,2,"e-mail. Thank you."); wrefresh (w); */ int v,k; char s[100][100]; strcpy (s[0],"AUTHOR"); strcpy (s[1]," Alexandru Radovici - [email protected]"); strcpy (s[2],""); strcpy (s[3],"VERSION"); strcpy (s[4]," LinuxEyes 0.8, build 0.8.6 (February 8, 2003)"); strcpy (s[5],""); strcpy (s[6],"ROMANIAN SOFTWARE"); strcpy (s[7]," This software was made in Romania!"); strcpy (s[8],""); strcpy (s[9],"WEBSITE"); strcpy (s[10]," http://lug.orizont.net/~linuxeyes"); strcpy (s[11],""); strcpy (s[12],"COPYRIGHT & DISTRIBUTION"); strcpy (s[13]," This software is freeware, you may use it on your"); strcpy (s[14],"own risk. You may distribute it only integral."); strcpy (s[15],""); strcpy (s[16],"MPEG Audio Layer 3"); strcpy (s[17]," Xaudio - http://www.xaudio.com"); strcpy (s[18],""); strcpy (s[19],"BUGS & SUGGESTIONS"); strcpy (s[20]," If you find any bugs or have any suggestion please"); strcpy (s[21],"email me. ([email protected]) Thank you!"); strcpy (s[22],""); strcpy (s[23],"LOTS OF THANKS TO"); strcpy (s[24]," Vera and Iuliu Radovici"); strcpy (s[25]," Ovidiu Stoica - [email protected]"); strcpy (s[26]," Alexandru Armean - [email protected]"); strcpy (s[27]," Valeriu Moldovan - [email protected]"); strcpy (s[28]," Cristian Klein - [email protected]"); strcpy (s[29],""); strcpy (s[30],"CURRENT SESSION STATISTICS"); sprintf (s[31]," Songs Played: %d",(int)n_songs); sprintf (s[32]," Time Played: %d:%.2d:%.2d",(int)n_secs/(60*60),(int)(n_secs/60)%60,(int)n_secs%60); strcpy (s[33],""); strcpy (s[34],"GLOBAL STATISTICS"); sprintf (s[35]," Songs Played: %d",(int)songs); sprintf (s[36]," Time Played: %d:%.2d:%.2d",(int)secs/(60*60),(int)(secs/60)%60,(int)secs%60); WINDOW *w1; w1=newwin (scr+2,62,7,(nrcols-62)/2); wrefresh (w1); werase (w1); WINDOW *w; w=newwin (scr,60,8,(nrcols-60)/2); wsetcolor (w,12,0); for (int h=0;h<=scr+2;h++) mvwprintw (w,h,0," "); wsetcolor (w,12,0); le_border (w,60,scr); wsetcolor (w,13,1); mvwprintw (w,0,1," About LinuxEyes "); wsetcolor (w,12,0); mvwprintw (w,scr-1,46," ESC - quit "); wrefresh(w); noecho(); timeout (1); k=0; do { wsetcolor (w,12,0); for (int i=0;i<=scr-5;i++) { mvwprintw (w,2+i,2," "); mvwprintw (w,2+i,2,"%s",s[i+k]); } wsetcolor (w,12,0); mvwaddch (w,0,28,ACS_HLINE); mvwaddch (w,scr-1,28,ACS_HLINE); wsetcolor (w,12,1); if (k>0) mvwaddch (w,0,28,ACS_UARROW); if (k<35-(scr-5)) mvwaddch (w,scr-1,28,ACS_DARROW); wrefresh(w); do { sprintf (s[31]," Songs Played: %d",(int)n_songs); sprintf (s[32]," Time Played: %d:%.2d:%.2d",(int)n_secs/(60*60),(int)(n_secs/60)%60,(int)n_secs%60); sprintf (s[35]," Songs Played: %d",(int)songs); sprintf (s[36]," Time Played: %d:%.2d:%.2d",(int)secs/(60*60),(int)(secs/60)%60,(int)secs%60); for (int i=0;i<=scr-5;i++) if (((i+k)==30) || ((i+k)==31) || ((i+k)==34) || ((i+k)==35)) { wsetcolor (w,12,0); mvwprintw (w,2+i,2," "); mvwprintw (w,2+i,2,"%s",s[i+k]); wrefresh (w); } messages(); v=getch(); } while (v==ERR); if (v == 27) { v=getch(); if (v==ERR) v='q'; if (v==91) { v=getch(); if (v==65) if (k > 0) k--; if (v==66) if (k < 36-(scr-5)) k++; } } if (v=='R') { n_songs=0; n_secs=0; } } while (v!='q'); werase (w); reread=1; }
tree() { mvwaddch(treescrn, 1, 11, (chtype)'/'); mvwaddch(treescrn, 2, 11, (chtype)'/'); mvwaddch(treescrn, 3, 10, (chtype)'/'); mvwaddch(treescrn, 4, 9, (chtype)'/'); mvwaddch(treescrn, 5, 9, (chtype)'/'); mvwaddch(treescrn, 6, 8, (chtype)'/'); mvwaddch(treescrn, 7, 7, (chtype)'/'); mvwaddch(treescrn, 8, 6, (chtype)'/'); mvwaddch(treescrn, 9, 6, (chtype)'/'); mvwaddch(treescrn, 10, 5, (chtype)'/'); mvwaddch(treescrn, 11, 3, (chtype)'/'); mvwaddch(treescrn, 12, 2, (chtype)'/'); mvwaddch(treescrn, 1, 13, (chtype)'\\'); mvwaddch(treescrn, 2, 13, (chtype)'\\'); mvwaddch(treescrn, 3, 14, (chtype)'\\'); mvwaddch(treescrn, 4, 15, (chtype)'\\'); mvwaddch(treescrn, 5, 15, (chtype)'\\'); mvwaddch(treescrn, 6, 16, (chtype)'\\'); mvwaddch(treescrn, 7, 17, (chtype)'\\'); mvwaddch(treescrn, 8, 18, (chtype)'\\'); mvwaddch(treescrn, 9, 18, (chtype)'\\'); mvwaddch(treescrn, 10, 19, (chtype)'\\'); mvwaddch(treescrn, 11, 21, (chtype)'\\'); mvwaddch(treescrn, 12, 22, (chtype)'\\'); mvwaddch(treescrn, 4, 10, (chtype)'_'); mvwaddch(treescrn, 4, 14, (chtype)'_'); mvwaddch(treescrn, 8, 7, (chtype)'_'); mvwaddch(treescrn, 8, 17, (chtype)'_'); mvwaddstr(treescrn, 13, 0, "//////////// \\\\\\\\\\\\\\\\\\\\\\\\"); mvwaddstr(treescrn, 14, 11, "| |"); mvwaddstr(treescrn, 15, 11, "|_|"); wrefresh(treescrn); wrefresh(w_del_msg); return( 0 ); }
static bool garmin_bin_initialize(void) { /*@-globstate@*/ unsigned int i; #ifndef CONTROLSEND_ENABLE if(serial) { monitor_complain("Direct mode doesn't supported."); return false; } #endif /*@ -onlytrans @*/ miscwin = subwin(devicewin, 1, 80, 1, 0); mid51win = subwin(devicewin, 12, 18, 2, 0); mid114win = subwin(devicewin, GARMIN_CHANNELS + 3, 23, 2, 18); if (miscwin == NULL || mid51win == NULL || mid114win == NULL) return false; (void)syncok(miscwin, true); (void)syncok(mid51win, true); (void)syncok(mid114win, true); /*@ -nullpass @*/ (void)wattrset(miscwin, A_BOLD); display(miscwin, 0, 0, "Time:"); (void)wattrset(miscwin, A_NORMAL); (void)wborder(mid51win, 0, 0, 0, 0, 0, 0, 0, 0), (void)wattrset(mid51win, A_BOLD); display(mid51win, 0, 4, " Position "); display(mid51win, 1, 2, "Fix:"); display(mid51win, 2, 2, "Lat:"); (void)mvwaddch(mid51win, 2, 16, ACS_DEGREE); display(mid51win, 3, 2, "Lon:"); (void)mvwaddch(mid51win, 3, 16, ACS_DEGREE); display(mid51win, 4, 2, "Alt: m"); display(mid51win, 5, 2, "Speed: m/s"); display(mid51win, 6, 2, "Climb: m/s"); display(mid51win, 7, 2, "Leap: sec"); display(mid51win, 8, 2, "epe: m"); display(mid51win, 9, 2, "eph: m"); display(mid51win, 10, 2, "epv: m"); display(mid51win, 11, 3, " ID 51 (0x33) "); (void)wattrset(mid51win, A_NORMAL); (void)wborder(mid114win, 0, 0, 0, 0, 0, 0, 0, 0), (void)wattrset(mid114win, A_BOLD); display(mid114win, 1, 1, "Ch PRN Az El SNR ST"); for (i = 0; i < GARMIN_CHANNELS; i++) { display(mid114win, (int)i + 2, 1, "%2d", i); } display(mid114win, 0, 5, " Satellite "); display(mid114win, 14, 4, " ID 114 (0x72) "); (void)wattrset(mid114win, A_NORMAL); /* initialize the GPS context's time fields */ gpsd_time_init(session.context, time(NULL)); return true; /*@+globstate@*/ }
/** PDCurses (on Windows) doesn't have this function, so I need * to re-implement it. * TODO: implement more features - see 'man mvwhline' */ void my_mvwhline(WINDOW* win, int y, int x, chtype ch, int num) { int i; for (i = 0; i < num; i++) mvwaddch(win, y, (x + i), ch); }