这篇教程C++ utf8_width函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中utf8_width函数的典型用法代码示例。如果您正苦于以下问题:C++ utf8_width函数的具体用法?C++ utf8_width怎么用?C++ utf8_width使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了utf8_width函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: filtered_bionics//.........这里部分代码省略......... case TAB_ACTIVE: msg = _( "No activatable bionics installed." ); break; case TAB_PASSIVE: msg = _( "No passive bionics installed." ); break; } fold_and_print( wBio, list_start_y, 2, WIDTH - 3, c_ltgray, msg ); } else { for( size_t i = scroll_position; i < current_bionic_list->size(); i++ ) { if( list_start_y + static_cast<int>( i ) - scroll_position == HEIGHT - 1 ) { break; } const bool is_highlighted = cursor == static_cast<int>( i ); const nc_color col = get_bionic_text_color( *( *current_bionic_list )[i], is_highlighted ); const std::string desc = string_format( "%c %s", ( *current_bionic_list )[i]->invlet, build_bionic_powerdesc_string( *( *current_bionic_list )[i] ).c_str() ); trim_and_print( wBio, list_start_y + i - scroll_position, 2, WIDTH - 3, col, "%s", desc.c_str() ); // draw bodyparts if( is_highlighted && menu_mode != EXAMINING ) { int max_width = 0; std::vector<std::string>bps; for( int i = 0; i < num_bp; ++i ) { const body_part bp = bp_aBodyPart[i]; const int total = get_total_bionics_slots( bp ); const std::string s = string_format( "%s: %d/%d", body_part_name_as_heading( bp, 1 ).c_str(), total - get_free_bionics_slots( bp ), total ); bps.push_back( s ); max_width = std::max( max_width, utf8_width( s ) ); } const int pos_x = WIDTH - 2 - max_width; const std::string bio_id = ( *current_bionic_list )[i]->id; draw_connectors( wBio, list_start_y + i - scroll_position, utf8_width( desc ) + 3, pos_x - 2, bio_id ); for( int i = 0; i < num_bp; ++i ) { mvwprintz( wBio, i + list_start_y, pos_x, bionic_info( bio_id ).occupied_bodyparts.count( bp_aBodyPart[i] ) > 0 ? c_yellow : c_ltgray, "%s", bps[i].c_str() ); } } } } draw_scrollbar( wBio, cursor, LIST_HEIGHT, current_bionic_list->size(), list_start_y ); } wrefresh( wBio ); draw_bionics_tabs( w_tabs, active.size(), passive.size(), tab_mode ); draw_bionics_titlebar( w_title, this, menu_mode ); if( menu_mode == EXAMINING && !current_bionic_list->empty() ) { draw_description( w_description, *( *current_bionic_list )[cursor] ); } const std::string action = ctxt.handle_input(); const long ch = ctxt.get_raw_input().get_first_input(); bionic *tmp = NULL; bool confirmCheck = false; if( menu_mode == REASSIGNING ) { menu_mode = ACTIVATING; tmp = bionic_by_invlet( ch );
开发者ID:2birdie,项目名称:Cataclysm-DDA,代码行数:67,
示例2: test_patternvoid test_pattern(int iCurrentPage, int iCurrentLine){ std::vector<std::string> vMatchingItems; std::string sItemName = ""; if (vAutoPickupRules[iCurrentPage][iCurrentLine].sRule == "") { return; } //Loop through all itemfactory items //TODO: somehow generate damaged, fitting or container items for (int i = 0; i < standard_itype_ids.size(); i++) { sItemName = item_controller->find_template(standard_itype_ids[i])->name; if (vAutoPickupRules[iCurrentPage][iCurrentLine].bActive && auto_pickup_match(sItemName, vAutoPickupRules[iCurrentPage][iCurrentLine].sRule)) { vMatchingItems.push_back(sItemName); } } const int iOffsetX = 15 + ((TERMX > FULL_SCREEN_WIDTH) ? (TERMX-FULL_SCREEN_WIDTH)/2 : 0); const int iOffsetY = 5 + ((TERMY > FULL_SCREEN_HEIGHT) ? (TERMY-FULL_SCREEN_HEIGHT)/2 : 0); int iStartPos = 0; const int iContentHeight = FULL_SCREEN_HEIGHT - 8; const int iContentWidth = FULL_SCREEN_WIDTH - 30; char ch; std::stringstream sTemp; WINDOW* w_test_rule_border = newwin(iContentHeight + 2, iContentWidth, iOffsetY, iOffsetX); WINDOW* w_test_rule_content = newwin(iContentHeight, iContentWidth - 2, 1 + iOffsetY, 1 + iOffsetX); wborder(w_test_rule_border, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX, LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX); int nmatch = vMatchingItems.size(); std::string buf = string_format(ngettext("%1$d item matches: %2$s", "%1$d items match: %2$s", nmatch), nmatch, vAutoPickupRules[iCurrentPage][iCurrentLine].sRule.c_str()); mvwprintz(w_test_rule_border, 0, iContentWidth/2 - utf8_width(buf.c_str())/2, hilite(c_white), buf.c_str()); mvwprintz(w_test_rule_border, iContentHeight + 1, 1, red_background(c_white), _("Won't display damaged, fits and can/bottle items")); wrefresh(w_test_rule_border); iCurrentLine = 0; do { // Clear the lines for (int i = 0; i < iContentHeight; i++) { for (int j = 0; j < 79; j++) { mvwputch(w_test_rule_content, i, j, c_black, ' '); } } calcStartPos(iStartPos, iCurrentLine, iContentHeight, vMatchingItems.size()); // display auto pickup for (int i = iStartPos; i < vMatchingItems.size(); i++) { if (i >= iStartPos && i < iStartPos + ((iContentHeight > vMatchingItems.size()) ? vMatchingItems.size() : iContentHeight)) { nc_color cLineColor = c_white; sTemp.str(""); sTemp << i + 1; mvwprintz(w_test_rule_content, i - iStartPos, 0, cLineColor, sTemp.str().c_str()); mvwprintz(w_test_rule_content, i - iStartPos, 4, cLineColor, ""); if (iCurrentLine == i) { wprintz(w_test_rule_content, c_yellow, ">> "); } else { wprintz(w_test_rule_content, c_yellow, " "); } wprintz(w_test_rule_content, (iCurrentLine == i) ? hilite(cLineColor) : cLineColor, vMatchingItems[i].c_str()); } } wrefresh(w_test_rule_content); ch = (char)input(); switch(ch) { case 'j': //move down iCurrentLine++; if (iCurrentLine >= vMatchingItems.size()) { iCurrentLine = 0; } break; case 'k': //move up iCurrentLine--; if (iCurrentLine < 0) { iCurrentLine = vMatchingItems.size()-1; } break; } } while(ch == 'j' || ch == 'k'); werase(w_test_rule_border); werase(w_test_rule_content);}
开发者ID:8Z,项目名称:Cataclysm-DDA,代码行数:95,
示例3: string_input_popupstd::string string_input_popup(std::string title, int max_length, std::string input){ std::string ret = input; int titlesize = utf8_width(title.c_str()); int startx = titlesize + 2; int iPopupWidth = (max_length == 0) ? FULL_SCREEN_WIDTH : max_length + titlesize + 4; if (iPopupWidth > FULL_SCREEN_WIDTH) { iPopupWidth = FULL_SCREEN_WIDTH; max_length = FULL_SCREEN_WIDTH - titlesize - 4; } WINDOW *w = newwin(3, iPopupWidth, (TERMY-3)/2, ((TERMX > iPopupWidth) ? (TERMX-iPopupWidth)/2 : 0)); wborder(w, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX, LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX ); std::string underline = ""; for (int i = startx ; i < iPopupWidth-1; i++) underline.push_back('_'); mvwprintz(w, 1, 1, c_ltred, "%s", title.c_str()); mvwprintz(w, 1, startx, c_ltgray, "%s", underline.c_str()); if (input != "") mvwprintz(w, 1, startx, c_magenta, "%s", input.c_str()); int posx = startx + utf8_width(input.c_str()); mvwputch(w, 1, posx, h_ltgray, '_'); do { wrefresh(w); long ch = getch(); if (ch == 27) { // Escape werase(w); wrefresh(w); delwin(w); refresh(); return ""; } else if (ch == '/n') { werase(w); wrefresh(w); delwin(w); refresh(); return ret; } else if (ch == KEY_BACKSPACE || ch == 127) { // Move the cursor back and re-draw it if (ret.size() > 0) { //erease utf8 character TODO: make a function while(ret.size()>0 && ((unsigned char)ret[ret.size()-1])>=128 && ((unsigned char)ret[(int)ret.size()-1])<=191) { ret.erase(ret.size()-1); } ret.erase(ret.size()-1); } } else if(ch==KEY_F(2)) { std::string tmp = get_input_string_from_file(); int tmplen = utf8_width(tmp.c_str()); if(tmplen>0 && (tmplen+utf8_width(ret.c_str())<=max_length||max_length==0)) { ret.append(tmp); } } //experimental unicode input else { std::string tmp = utf32_to_utf8(ch); int tmplen = utf8_width(tmp.c_str()); if(tmplen>0 && (tmplen+utf8_width(ret.c_str())<=max_length||max_length==0)) { ret.append(tmp); } } mvwprintz(w, 1, startx, c_ltgray, "%s", underline.c_str()); mvwprintz(w, 1, startx, c_ltgray, "%s", ret.c_str()); wprintz(w, h_ltgray, "_"); } while (true);}
开发者ID:NickJ1984,项目名称:Cataclysm-DDA,代码行数:76,
示例4: select_from_list_screen/* * This is intended to be a generic tool to select strings from a list * of strings. * * Args lsel -- the items as well as the answer are contained in this list * flags -- There is some inconsistent flags usage. Notice that the * flag SFL_ALLOW_LISTMODE is a flag passed in the flags * argument whereas the flag SFL_NOSELECT is a per item * (that is, per LIST_SEL_S) flag. * title -- passed to conf_scroll_screen * pdesc -- passed to conf_scroll_screen * help -- passed to conf_scroll_screen * helptitle -- passed to conf_scroll_screen * * You have screen width - 4 columns to work with. If you want to overflow to * a second (or third or fourth) line for an item just send another item * in the list but with the SFL_NOSELECT flag set. Only the selectable lines * will be highlighted, which is kind of a crock, but it looked like a lot * of work to fix that. * * Returns 0 on successful choice * -1 if cancelled */intselect_from_list_screen(LIST_SEL_S *lsel, long unsigned int flags, char *title, char *pdesc, HelpType help, char *htitle, LIST_SEL_S *starting_val){ CONF_S *ctmp = NULL, *first_line = NULL; OPT_SCREEN_S screen; int j, lv, ret = -1; LIST_SEL_S *p; char *display; size_t l; ScreenMode listmode = SingleMode; int (*tool)(struct pine *, int, CONF_S **, unsigned); if(!lsel) return(ret); /* find longest value's length */ for(lv = 0, p = lsel; p; p = p->next){ if(!(p->flags & SFL_NOSELECT)){ display = p->display_item ? p->display_item : p->item ? p->item : ""; if(lv < (j = utf8_width(display))) lv = j; } } lv = MIN(lv, ps_global->ttyo->screen_cols - 4); tool = (flags & SFL_CTRLC) ? select_from_list_tool_allow_noselections : select_from_list_tool; /* * Convert the passed in list to conf_scroll lines. */ if(flags & SFL_ALLOW_LISTMODE){ if(flags & SFL_ONLY_LISTMODE) {assert(flags & SFL_STARTIN_LISTMODE);} for(p = lsel; p; p = p->next){ display = p->display_item ? p->display_item : p->item ? p->item : ""; new_confline(&ctmp); if(!first_line && !(p->flags & SFL_NOSELECT)) first_line = ctmp; if(!first_line && !(p->flags & SFL_NOSELECT)) if(!starting_val || (starting_val == p)) first_line = ctmp; /* generous allocation */ l = lv + 4 + strlen(display); ctmp->value = (char *) fs_get((l + 1) * sizeof(char)); utf8_snprintf(ctmp->value, l+1, " %-*.*w", lv, lv, display); ctmp->value[l] = '/0'; ctmp->d.l.lsel = p; ctmp->d.l.listmode = &listmode; if(flags & SFL_ONLY_LISTMODE){ if(flags & SFL_CTRLC) ctmp->keymenu = &sel_from_list_olm_ctrlc; else ctmp->keymenu = &sel_from_list_olm; } else{ if(flags & SFL_CTRLC) ctmp->keymenu = &sel_from_list_sm_ctrlc; else ctmp->keymenu = &sel_from_list_sm; } ctmp->help = help; ctmp->help_title = htitle; ctmp->tool = tool; ctmp->flags = CF_STARTITEM | ((p->flags & SFL_NOSELECT) ? CF_NOSELECT : 0);//.........这里部分代码省略.........
开发者ID:RsrchBoy,项目名称:dpkg-alpine,代码行数:101,
示例5: get_entry_indentsize_t inventory_column::get_entry_width( const inventory_entry &entry ) const { return get_entry_indent( entry ) + utf8_width( get_entry_text( entry ), true );}
开发者ID:Nhatorama,项目名称:Cataclysm-DDA,代码行数:3,
示例6: debugmsg/** * Calculate sizes, populate arrays, initialize window */void uimenu::setup(){ bool w_auto = (w_width == -1 || w_width == -2 ); bool w_autofold = ( w_width == -2); // Space for a line between text and entries. Only needed if there is actually text. const int text_separator_line = text.empty() ? 0 : 1; if ( w_auto ) { w_width = 4; if ( !title.empty() ) { w_width = title.size() + 5; } } bool h_auto = (w_height == -1); if ( h_auto ) { w_height = 4; } if ( desc_enabled && !(w_auto && h_auto) ) { desc_enabled = false; // give up debugmsg( "desc_enabled without w_auto and h_auto (h: %d, w: %d)", static_cast<int>( h_auto ), static_cast<int>( w_auto ) ); } max_entry_len = 0; max_column_len = 0; std::vector<int> autoassign; int pad = pad_left + pad_right + 2; int descwidth_final = 0; // for description width guard for ( size_t i = 0; i < entries.size(); i++ ) { int txtwidth = utf8_width( remove_color_tags(entries[i].txt) ); int ctxtwidth = utf8_width( remove_color_tags(entries[i].ctxt) ); if ( txtwidth > max_entry_len ) { max_entry_len = txtwidth; } if ( ctxtwidth > max_column_len ) { max_column_len = ctxtwidth; } int clen = (ctxtwidth > 0) ? ctxtwidth + 2: 0; if(entries[ i ].enabled) { if( entries[ i ].hotkey > 0 ) { keymap[ entries[ i ].hotkey ] = i; } else if ( entries[ i ].hotkey == -1 && i < 100 ) { autoassign.push_back(i); } if ( entries[ i ].retval == -1 ) { entries[ i ].retval = i; } if ( w_auto && w_width < txtwidth + pad + 4 + clen ) { w_width = txtwidth + pad + 4 + clen; } } else { if ( w_auto && w_width < txtwidth + pad + 4 + clen ) { w_width = txtwidth + pad + 4 + clen; // @todo: or +5 if header } } if ( desc_enabled ) { const int min_width = std::min( TERMX, std::max( w_width, descwidth_final ) ) - 4; const int max_width = TERMX - 4; int descwidth = find_minimum_fold_width( entries[i].desc, desc_lines, min_width, max_width ); descwidth += 4; // 2x border + 2x ' ' pad if ( descwidth_final < descwidth ) { descwidth_final = descwidth; } } if ( entries[ i ].text_color == c_red_red ) { entries[ i ].text_color = text_color; } fentries.push_back( i ); } size_t next_free_hotkey = 0; for( auto it = autoassign.begin(); it != autoassign.end() && next_free_hotkey < hotkeys.size(); ++it ) { while( next_free_hotkey < hotkeys.size() ) { const int setkey = hotkeys[next_free_hotkey]; next_free_hotkey++; if( keymap.count( setkey ) == 0 ) { entries[*it].hotkey = setkey; keymap[setkey] = *it; break; } } } if (desc_enabled) { if (descwidth_final > TERMX) { desc_enabled = false; // give up debugmsg("description would exceed terminal width (%d vs %d available)", descwidth_final, TERMX); } else if (descwidth_final > w_width) { w_width = descwidth_final; } } if(!text.empty() ) { int twidth = utf8_width( remove_color_tags(text) );//.........这里部分代码省略.........
开发者ID:terribleperson,项目名称:Cataclysm-DDA,代码行数:101,
示例7: newwinint minesweeper_game::start_game(){ const int iCenterX = (TERMX > FULL_SCREEN_WIDTH) ? (TERMX - FULL_SCREEN_WIDTH) / 2 : 0; const int iCenterY = (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY - FULL_SCREEN_HEIGHT) / 2 : 0; WINDOW *w_minesweeper_border = newwin(FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, iCenterY, iCenterX); WINDOW_PTR w_minesweeper_borderptr( w_minesweeper_border ); WINDOW *w_minesweeper = newwin(FULL_SCREEN_HEIGHT - 2, FULL_SCREEN_WIDTH - 2, iCenterY + 1, iCenterX + 1); WINDOW_PTR w_minesweeperptr( w_minesweeper ); draw_border(w_minesweeper_border); std::vector<std::string> shortcuts; shortcuts.push_back(_("<n>ew level")); shortcuts.push_back(_("<f>lag")); shortcuts.push_back(_("<q>uit")); int iWidth = 0; for( auto &shortcut : shortcuts ) { if ( iWidth > 0 ) { iWidth += 1; } iWidth += utf8_width(shortcut); } int iPos = FULL_SCREEN_WIDTH - iWidth - 1; for( auto &shortcut : shortcuts ) { shortcut_print(w_minesweeper_border, 0, iPos, c_white, c_ltgreen, shortcut); iPos += utf8_width(shortcut) + 1; } mvwputch(w_minesweeper_border, 0, 2, hilite(c_white), _("Minesweeper")); wrefresh(w_minesweeper_border); input_context ctxt("MINESWEEPER"); ctxt.register_cardinal(); ctxt.register_action("NEW"); ctxt.register_action("FLAG"); ctxt.register_action("CONFIRM"); ctxt.register_action("QUIT"); ctxt.register_action("HELP_KEYBINDINGS"); static const std::array<int, 9> aColors = {{ c_white, c_ltgray, c_cyan, c_blue, c_ltblue, c_green, c_magenta, c_red, c_yellow }}; int iScore = 5; int iPlayerY = 0; int iPlayerX = 0; std::function<void (int, int)> rec_reveal = [&](const int y, const int x) { if ( mLevelReveal[y][x] == unknown || mLevelReveal[y][x] == flag ) { mLevelReveal[y][x] = seen; if ( mLevel[y][x] == 0 ) { const auto circle = closest_tripoints_first( 1, {x, y, 0} ); for( const auto &p : circle ) { if ( p.x >= 0 && p.x < iLevelX && p.y >= 0 && p.y < iLevelY ) { if ( mLevelReveal[p.y][p.x] != seen ) { rec_reveal(p.y, p.x); } } } mvwputch(w_minesweeper, iOffsetY + y, iOffsetX + x, c_black, " "); } else { mvwputch(w_minesweeper, iOffsetY + y, iOffsetX + x, (x == iPlayerX && y == iPlayerY) ? hilite(aColors[mLevel[y][x]]) : aColors[mLevel[y][x]], to_string(mLevel[y][x])); } } }; int iDirY, iDirX; std::string action = "NEW"; do { if (action == "NEW") { new_level(w_minesweeper); iPlayerY = 0; iPlayerX = 0; } wrefresh(w_minesweeper);//.........这里部分代码省略.........
开发者ID:CIB,项目名称:Cataclysm-DDA,代码行数:101,
示例8: newwinint worldfactory::show_worldgen_tab_confirm(WINDOW *win, WORLDPTR world){ const int iTooltipHeight = 1; const int iContentHeight = FULL_SCREEN_HEIGHT - 3 - iTooltipHeight; const int iOffsetX = (TERMX > FULL_SCREEN_WIDTH) ? (TERMX - FULL_SCREEN_WIDTH) / 2 : 0; const int iOffsetY = (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY - FULL_SCREEN_HEIGHT) / 2 : 0; WINDOW *w_confirmation = newwin(iContentHeight, FULL_SCREEN_WIDTH - 2, iTooltipHeight + 2 + iOffsetY, 1 + iOffsetX); unsigned namebar_y = 1; unsigned namebar_x = 3 + utf8_width(_("World Name:")); int line = 1; bool noname = false; input_context ctxt("WORLDGEN_CONFIRM_DIALOG"); // Disabled because it conflicts with the "pick random world name" option, // feel free to enable it and change its keybinding in keybindings.json // ctxt.register_action("HELP_KEYBINDINGS"); ctxt.register_action("QUIT"); ctxt.register_action("ANY_INPUT"); ctxt.register_action("NEXT_TAB"); ctxt.register_action("PREV_TAB"); ctxt.register_action("PICK_RANDOM_WORLDNAME"); std::string worldname = world->world_name; do { mvwprintz(w_confirmation, namebar_y, 2, c_white, _("World Name:")); mvwprintz(w_confirmation, namebar_y, namebar_x, c_ltgray, "______________________________"); fold_and_print(w_confirmation, 3, 2, 76, c_ltgray, _("Press <color_yellow>?</color> to pick a random name for your world.")); fold_and_print(w_confirmation, FULL_SCREEN_HEIGHT / 2 - 2, 2, 76, c_ltgray, _("/Press <color_yellow>></color> when you are satisfied with the world as it is and are ready /to continue, or <color_yellow><</color> to go back and review your world.")); if (!noname) { mvwprintz(w_confirmation, namebar_y, namebar_x, c_ltgray, "%s", worldname.c_str()); if (line == 1) { wprintz(w_confirmation, h_ltgray, "_"); } } if (noname) { mvwprintz(w_confirmation, namebar_y, namebar_x, c_ltgray, "______________________________"); noname = false; } wrefresh(win); wrefresh(w_confirmation); refresh(); const std::string action = ctxt.handle_input(); if (action == "NEXT_TAB") { if (worldname.empty()) { mvwprintz(w_confirmation, namebar_y, namebar_x, h_ltgray, _("______NO NAME ENTERED!!!!_____")); noname = true; wrefresh(w_confirmation); if (!query_yn(_("Are you SURE you're finished? World name will be randomly generated."))) { continue; } else { world->world_name = pick_random_name(); if (!valid_worldname(world->world_name)) { continue; } return 1; } } else if (query_yn(_("Are you SURE you're finished?")) && valid_worldname(worldname)) { world->world_name = worldname; werase(w_confirmation); delwin(w_confirmation); return 1; } else { continue; } } else if (action == "PREV_TAB") { world->world_name = worldname; werase(w_confirmation); delwin(w_confirmation); return -1; } else if (action == "PICK_RANDOM_WORLDNAME") { mvwprintz(w_confirmation, namebar_y, namebar_x, c_ltgray, "______________________________"); world->world_name = worldname = pick_random_name(); } else if (action == "QUIT") { world->world_name = worldname; // cache the current worldname just in case they say No to the exit query return -999; } else if (action == "ANY_INPUT") { const input_event ev = ctxt.get_raw_input(); const long ch = ev.get_first_input(); switch (line) { case 1: { utf8_wrapper wrap(worldname); utf8_wrapper newtext( ev.text ); if( ch == KEY_BACKSPACE ) { if (!wrap.empty()) { wrap.erase(wrap.length() - 1, 1); worldname = wrap.str(); } } else if(ch == KEY_F(2)) { std::string tmp = get_input_string_from_file();//.........这里部分代码省略.........
开发者ID:Krutchen,项目名称:Cataclysm-DDA,代码行数:101,
示例9: question/*---------------------------------------------------------------------- Ask a yes/no question in the status line Args: question -- string to prompt user with dflt -- The default answer to the question (should probably be y or n) on_ctrl_C -- Answer returned on ^C help -- Two line help text flags -- Flags to modify behavior WT_FLUSH_IN - Discard pending input. WT_SEQ_SENSITIVE - Caller is sensitive to sequence number changes caused by unsolicited expunges while we're viewing a message. Result: Messes up the status line, returns y, n, dflt, on_ctrl_C, or SEQ_EXCEPTION ---*/intwant_to(char *question, int dflt, int on_ctrl_C, HelpType help, int flags){ char *free_this = NULL, *free_this2 = NULL, *prompt; int rv, width; size_t len; if(!ps_global->ttyo) return(pre_screen_config_want_to(question, dflt, on_ctrl_C));#ifdef _WINDOWS if (mswin_usedialog ()) { mswin_flush (); switch (mswin_yesno_utf8 (question)) { default: case 0: return (on_ctrl_C); case 1: return ('y'); case 2: return ('n'); } }#endif /*---- One problem with adding the (y/n) here is that shrinking the screen while in radio_buttons() will cause it to get chopped off. It would be better to truncate the question passed in here and leave the full "(y/n) [x] : " on. ----*/ len = strlen(question) + 4; free_this = (char *) fs_get(len); width = utf8_width(question); if(width + 2 < ps_global->ttyo->screen_cols){ snprintf(free_this, len, "%s? ", question); free_this[len-1] = '/0'; prompt = free_this; } else if(width + 1 < ps_global->ttyo->screen_cols){ snprintf(free_this, len, "%s?", question); free_this[len-1] = '/0'; prompt = free_this; } else if(width < ps_global->ttyo->screen_cols){ snprintf(free_this, len, "%s", question); free_this[len-1] = '/0'; prompt = free_this; } else{ free_this2 = (char *) fs_get(len); snprintf(free_this2, len, "%s? ", question); prompt = short_str(free_this2, free_this, len, ps_global->ttyo->screen_cols-1, MidDots); } if(on_ctrl_C == 'n') /* don't ever let cancel == 'n' */ on_ctrl_C = 0; rv = radio_buttons(prompt, (ps_global->ttyo->screen_rows > 4) ? - FOOTER_ROWS(ps_global) : -1, yorn, dflt, on_ctrl_C, help, flags); if(free_this) fs_give((void **) &free_this); if(free_this2) fs_give((void **) &free_this2); return(rv);}
开发者ID:ctubio,项目名称:alpine,代码行数:86,
示例10: utf8_widthvoid string_input_popup::create_window(){ nc_color title_color = c_light_red; nc_color desc_color = c_green; int titlesize = utf8_width( _title ); // Occupied horizontal space if( _max_length <= 0 ) { _max_length = _width; } // 2 for border (top and bottom) and 1 for the input text line. int w_height = 2 + 1; // |"w_width = width + titlesize (this text) + 5": _____ | int w_width = FULL_SCREEN_WIDTH; if( _width <= 0 ) { _width = std::max( 5, FULL_SCREEN_WIDTH - titlesize - 5 ); // Default if unspecified } else { _width = std::min( FULL_SCREEN_WIDTH - 20, _width ); w_width = _width + titlesize + 5; } std::vector<std::string> title_split = { _title }; if( w_width > FULL_SCREEN_WIDTH ) { // Out of horizontal space- wrap the title titlesize = FULL_SCREEN_WIDTH - _width - 5; w_width = FULL_SCREEN_WIDTH; for( int wraplen = w_width - 2; wraplen >= titlesize; wraplen-- ) { title_split = foldstring( _title, wraplen ); if( int( title_split.back().size() ) <= titlesize ) { break; } } w_height += int( title_split.size() ) - 1; } std::vector<std::string> descformatted; if( !_description.empty() ) { const int twidth = std::min( utf8_width( remove_color_tags( _description ) ), w_width - 4 ); descformatted = foldstring( _description, twidth ); w_height += descformatted.size(); } // length of title + border (left) + space _startx = titlesize + 2; // Below the description and below the top border _starty = 1 + descformatted.size(); if( _max_length <= 0 ) { _max_length = 1024; } _endx = w_width - 3; _position = -1; const int w_y = ( TERMY - w_height ) / 2; const int w_x = std::max( ( TERMX - w_width ) / 2, 0 ); w = catacurses::newwin( w_height, w_width, w_y, w_x ); draw_border( w ); for( size_t i = 0; i < descformatted.size(); ++i ) { trim_and_print( w, 1 + i, 1, w_width - 2, desc_color, descformatted[i] ); } for( int i = 0; i < int( title_split.size() ) - 1; i++ ) { mvwprintz( w, _starty++, i + 1, title_color, title_split[i] ); } right_print( w, _starty, w_width - titlesize - 1, title_color, title_split.back() ); _starty = w_height - 2; // The ____ looks better at the bottom right when the title folds}
开发者ID:alapazam,项目名称:Cataclysm-DDA,代码行数:68,
示例11: create_window//.........这里部分代码省略......... if( draw_only ) { return _text; } const std::string action = ctxt->handle_input(); const input_event ev = ctxt->get_raw_input(); ch = ev.type == CATA_INPUT_KEYBOARD ? ev.get_first_input() : 0; if( callbacks[ch] ) { if( callbacks[ch]() ) { continue; } } // This class only registers the ANY_INPUT action by default. If the // client provides their own input_context with registered actions // besides ANY_INPUT, ignore those so that the client may handle them. if( action != "ANY_INPUT" ) { continue; } if( ch == KEY_ESCAPE ) { _text.clear(); _canceled = true; return _text; } else if( ch == '/n' ) { add_to_history( ret.str() ); _text = ret.str(); return _text; } else if( ch == KEY_UP ) { show_history( ret ); redraw = true; } else if( ch == KEY_DOWN || ch == KEY_NPAGE || ch == KEY_PPAGE || ch == KEY_BTAB || ch == 9 ) { /* absolutely nothing */ } else if( ch == KEY_RIGHT ) { if( _position + 1 <= ( int )ret.size() ) { _position++; } redraw = true; } else if( ch == KEY_LEFT ) { if( _position > 0 ) { _position--; } redraw = true; } else if( ch == 0x15 ) { // ctrl-u: delete all the things _position = 0; ret.erase( 0 ); redraw = true; // Move the cursor back and re-draw it } else if( ch == KEY_BACKSPACE ) { // but silently drop input if we're at 0, instead of adding '^' if( _position > 0 && _position <= ( int )ret.size() ) { //TODO: it is safe now since you only input ASCII chars _position--; ret.erase( _position, 1 ); redraw = true; } } else if( ch == KEY_HOME ) { _position = 0; redraw = true; } else if( ch == KEY_END ) { _position = ret.size(); redraw = true; } else if( ch == KEY_DC ) { if( _position < ( int )ret.size() ) { ret.erase( _position, 1 ); redraw = true; } } else if( ch == KEY_F( 2 ) ) { std::string tmp = get_input_string_from_file(); int tmplen = utf8_width( tmp ); if( tmplen > 0 && ( tmplen + utf8_width( ret.c_str() ) <= _max_length || _max_length == 0 ) ) { ret.append( tmp ); } } else if( !ev.text.empty() && _only_digits && !( isdigit( ev.text[0] ) || ev.text[0] == '-' ) ) { // ignore non-digit (and '-' is a digit as well) } else if( _max_length > 0 && ( int )ret.length() >= _max_length ) { // no further input possible, ignore key } else if( !ev.text.empty() ) { const utf8_wrapper t( ev.text ); ret.insert( _position, t ); _position += t.length(); edit.erase( 0 ); ctxt->set_edittext( edit.c_str() ); redraw = true; } else if( ev.edit_refresh ) { const utf8_wrapper t( ev.edit ); edit.erase( 0 ); edit.insert( 0, t ); ctxt->set_edittext( edit.c_str() ); redraw = true; } else if( ev.edit.empty() ) { edit.erase( 0 ); ctxt->set_edittext( edit.c_str() ); redraw = true; } } while( loop == true ); _text = ret.str(); return _text;}
开发者ID:alapazam,项目名称:Cataclysm-DDA,代码行数:101,
示例12: mvwprintz/** * Displays the vehicle's stats at the bottom of the window. */void veh_interact::display_stats (){ bool conf = veh->valid_wheel_config(); const int second_column = 29; const int third_column = 56; std::string speed_units = OPTIONS["USE_METRIC_SPEEDS"].getValue(); float speed_factor = 0.01f; if (OPTIONS["USE_METRIC_SPEEDS"] == "km/h") { speed_factor *= 1.61; } std::string weight_units = OPTIONS["USE_METRIC_WEIGHTS"].getValue(); float weight_factor; if (OPTIONS["USE_METRIC_WEIGHTS"] == "kg") { weight_factor = 1; } else { weight_factor = 2.2f; } mvwprintz(w_stats, 0, 1, c_ltgray, _("Name: ")); mvwprintz(w_stats, 0, 1 + utf8_width(_("Name: ")), c_ltgreen, veh->name.c_str()); fold_and_print(w_stats, 1, 1, second_column, c_ltgray, _("Safe speed: <color_ltgreen>%3d</color> %s"), int(veh->safe_velocity(false) * speed_factor), speed_units.c_str()); fold_and_print(w_stats, 2, 1, second_column, c_ltgray, _("Top speed: <color_ltred>%3d</color> %s"), int(veh->max_velocity(false) * speed_factor), speed_units.c_str()); fold_and_print(w_stats, 3, 1, second_column, c_ltgray, _("Acceleration: <color_ltblue>%3d</color> %s/t"), int(veh->acceleration(false) * speed_factor), speed_units.c_str()); fold_and_print(w_stats, 4, 1, second_column, c_ltgray, _("Mass: <color_ltblue>%5d</color> %s"), int(veh->total_mass() * weight_factor), weight_units.c_str()); if (conf) { fold_and_print(w_stats, 5, second_column, third_column, c_ltgray, _("Wheels: <color_ltgreen>enough</color>")); } else { fold_and_print(w_stats, 5, second_column, third_column, c_ltgray, _("Wheels: <color_ltred>lack</color>")); } fold_and_print(w_stats, 2, second_column, third_column, c_ltgray, _("K dynamics: <color_ltblue>%3d</color>%%"), int(veh->k_dynamics() * 100)); fold_and_print(w_stats, 3, second_column, third_column, c_ltgray, _("K mass: <color_ltblue>%3d</color>%%"), int(veh->k_mass() * 100)); mvwprintz(w_stats, 1, second_column, c_ltgray, _("Fuel usage (safe): ")); int fuel_usage_x = 1 + second_column + utf8_width(_("Fuel usage (safe): ")); ammotype fuel_types[3] = { "gasoline", "battery", "plasma" }; nc_color fuel_colors[3] = { c_ltred, c_yellow, c_ltblue }; bool first = true; for (int i = 0; i < 3; ++i) { int fuel_usage = veh->basic_consumption (fuel_types[i]); if (fuel_usage > 0) { fuel_usage = fuel_usage / 100; if (fuel_usage < 1) { fuel_usage = 1; } if (!first) { mvwprintz(w_stats, 1, fuel_usage_x++, c_ltgray, "/"); } mvwprintz(w_stats, 1, fuel_usage_x++, fuel_colors[i], "%d", fuel_usage); if (fuel_usage > 9) { fuel_usage_x++; } if (fuel_usage > 99) { fuel_usage_x++; } first = false; } } veh->print_fuel_indicator (w_stats, 1, third_column, true, true); // Write the overall damage int column = 1; mvwprintz(w_stats, 5, 1, c_ltgray, _("Status: ")); column += utf8_width(_("Status: ")) + 1; fold_and_print(w_stats, 5, column, third_column, totalDurabilityColor, totalDurabilityText.c_str()); // Write the most damaged part if (mostDamagedPart != -1) { std::string partName; mvwprintz(w_stats, 4, second_column, c_ltgray, _("Most damaged: ")); column = second_column + utf8_width(_("Most damaged: ")) + 1; std::string partID = veh->parts[mostDamagedPart].id; vehicle_part part = veh->parts[mostDamagedPart]; int damagepercent = part.hp / vehicle_part_types[part.id].durability; nc_color damagecolor = getDurabilityColor(damagepercent * 100); partName = vehicle_part_types[partID].name; fold_and_print(w_stats, 4, column, third_column, damagecolor, "%s", partName.c_str()); } wrefresh (w_stats);}
开发者ID:navagator,项目名称:Cataclysm-DDA,代码行数:97,
示例13: strbuf_add_wrapped_text/* * Wrap the text, if necessary. The variable indent is the indent for the * first line, indent2 is the indent for all other lines. * If indent is negative, assume that already -indent columns have been * consumed (and no extra indent is necessary for the first line). */int strbuf_add_wrapped_text(struct strbuf *buf, const char *text, int indent, int indent2, int width){ int w = indent, assume_utf8 = is_utf8(text); const char *bol = text, *space = NULL; if (width <= 0) { strbuf_add_indented_text(buf, text, indent, indent2); return 1; } if (indent < 0) { w = -indent; space = text; } for (;;) { char c; size_t skip; while ((skip = display_mode_esc_sequence_len(text))) text += skip; c = *text; if (!c || isspace(c)) { if (w < width || !space) { const char *start = bol; if (!c && text == start) return w; if (space) start = space; else print_spaces(buf, indent); strbuf_write(buf, start, text - start); if (!c) return w; space = text; if (c == '/t') w |= 0x07; else if (c == '/n') { space++; if (*space == '/n') { strbuf_write(buf, "/n", 1); goto new_line; } else if (!isalnum(*space)) goto new_line; else strbuf_write(buf, " ", 1); } w++; text++; } else {new_line: strbuf_write(buf, "/n", 1); text = bol = space + isspace(*space); space = NULL; w = indent = indent2; } continue; } if (assume_utf8) w += utf8_width(&text, NULL); else { w++; text++; } }}
开发者ID:samv,项目名称:git,代码行数:76,
示例14: newwinint worldfactory::show_worldgen_tab_confirm(WINDOW *win, WORLDPTR world){ const int iTooltipHeight = 1; const int iContentHeight = FULL_SCREEN_HEIGHT - 3 - iTooltipHeight; const int iOffsetX = (TERMX > FULL_SCREEN_WIDTH) ? (TERMX - FULL_SCREEN_WIDTH) / 2 : 0; const int iOffsetY = (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY - FULL_SCREEN_HEIGHT) / 2 : 0; WINDOW *w_confirmation = newwin(iContentHeight, FULL_SCREEN_WIDTH - 2, iTooltipHeight + 2 + iOffsetY, 1 + iOffsetX); unsigned namebar_pos = 3 + utf8_width(_("World Name:")); int line = 1; bool noname = false; long ch; std::string worldname = world->world_name; do { mvwprintz(w_confirmation, 2, 2, c_ltgray, _("World Name:")); mvwprintz(w_confirmation, 2, namebar_pos, c_ltgray, "______________________________"); fold_and_print(w_confirmation, 10, 2, 76, c_ltgray, _("When you are satisfied with the world as it is and are ready to continue, press >")); fold_and_print(w_confirmation, 12, 2, 76, c_ltgray, _("To go back and review your world, press <")); fold_and_print(w_confirmation, 14, 2, 76, c_green, _("To pick a random name for your world, press ?.")); if (!noname) { mvwprintz(w_confirmation, 2, namebar_pos, c_ltgray, "%s", worldname.c_str()); if (line == 1) { wprintz(w_confirmation, h_ltgray, "_"); } } wrefresh(win); wrefresh(w_confirmation); refresh(); ch = input(); if (noname) { mvwprintz(w_confirmation, 2, namebar_pos, c_ltgray, "______________________________"); noname = false; } if (ch == '>') { if (worldname.size() == 0) { mvwprintz(w_confirmation, 2, namebar_pos, h_ltgray, _("______NO NAME ENTERED!!!!_____")); noname = true; wrefresh(w_confirmation); if (!query_yn(_("Are you SURE you're finished? World name will be randomly generated."))) { continue; continue; } else { world->world_name = pick_random_name(); if (!valid_worldname(world->world_name)) { continue; } return 1; } } else if (query_yn(_("Are you SURE you're finished?")) && valid_worldname(worldname)) { world->world_name = worldname; werase(w_confirmation); delwin(w_confirmation); return 1; } else { continue; } } else if (ch == '<') { world->world_name = worldname; werase(w_confirmation); delwin(w_confirmation); return -1; } else if (ch == '?') { mvwprintz(w_confirmation, 2, namebar_pos, c_ltgray, "______________________________"); world->world_name = worldname = pick_random_name(); } else if (ch == KEY_ESCAPE){ world->world_name = worldname; // cache the current worldname just in case they say No to the exit query return -999; } else { switch (line) { case 1: if (ch == KEY_BACKSPACE || ch == 127) { if (worldname.size() > 0) { //erase utf8 character TODO: make a function while(worldname.size() > 0 && ((unsigned char)worldname[worldname.size() - 1]) >= 128 && ((unsigned char)worldname[(int)worldname.size() - 1]) <= 191) { worldname.erase(worldname.size() - 1); } worldname.erase(worldname.size() - 1); mvwprintz(w_confirmation, 2, namebar_pos, c_ltgray, "______________________________ "); mvwprintz(w_confirmation, 2, namebar_pos, c_ltgray, "%s", worldname.c_str()); wprintz(w_confirmation, h_ltgray, "_"); } } else if (is_char_allowed(ch) && utf8_width(worldname.c_str()) < 30) { worldname.push_back(ch); } else if(ch == KEY_F(2)) { std::string tmp = get_input_string_from_file(); int tmplen = utf8_width(tmp.c_str()); if(tmplen > 0 && tmplen + utf8_width(worldname.c_str()) < 30) { worldname.append(tmp);//.........这里部分代码省略.........
开发者ID:NeverGoWest,项目名称:Cataclysm-DDA,代码行数:101,
示例15: construction_menu//.........这里部分代码省略......... } else { mvwprintz(w_con, posy, 31, color_stage, _("Replaces: %s"), termap[current_con->pre_terrain].name.c_str()); } } // display result if (current_con->post_terrain != "") { posy++; if (current_con->post_is_furniture) { mvwprintz(w_con, posy, 31, color_stage, _("Result: %s"), furnmap[current_con->post_terrain].name.c_str()); } else { mvwprintz(w_con, posy, 31, color_stage, _("Result: %s"), termap[current_con->post_terrain].name.c_str()); } } // display time needed posy++; mvwprintz(w_con, posy, 31, color_stage, _("Time: %1d minutes"), current_con->time); // Print tools std::vector<bool> has_tool; posy++; posx = 33; for (int i = 0; i < current_con->tools.size(); i++) { has_tool.push_back(false); mvwprintz(w_con, posy, posx-2, c_white, ">"); for (unsigned j = 0; j < current_con->tools[i].size(); j++) { itype_id tool = current_con->tools[i][j].type; nc_color col = c_red; if (total_inv.has_amount(tool, 1)) { has_tool[i] = true; col = c_green; } int length = utf8_width(item_controller->find_template(tool)->name.c_str()); if (posx + length > FULL_SCREEN_WIDTH-1) { posy++; posx = 33; } mvwprintz(w_con, posy, posx, col, item_controller->find_template(tool)->name.c_str()); posx += length + 1; // + 1 for an empty space if (j < current_con->tools[i].size() - 1) { // "OR" if there's more if (posx > FULL_SCREEN_WIDTH-3) { posy++; posx = 33; } mvwprintz(w_con, posy, posx, c_white, _("OR")); posx += 3; } } posy ++; posx = 33; } // Print components posx = 33; std::vector<bool> has_component; for (int i = 0; i < current_con->components.size(); i++) { has_component.push_back(false); mvwprintz(w_con, posy, posx-2, c_white, ">"); for (unsigned j = 0; j < current_con->components[i].size(); j++) { nc_color col = c_red; component comp = current_con->components[i][j]; if (( item_controller->find_template(comp.type)->is_ammo() && total_inv.has_charges(comp.type, comp.count)) || (!item_controller->find_template(comp.type)->is_ammo() && total_inv.has_amount(comp.type, comp.count))) { has_component[i] = true;
开发者ID:Ferk,项目名称:Cataclysm-DDA,代码行数:67,
示例16: pressed//.........这里部分代码省略......... } button_list[b].ch = -1; /* assumption here is that HelpType is char ** */ help = help_text; ret = mswin_select(utf8prompt, button_list, dflt, on_ctrl_C, help, flags); for(i = 0; i < 25; i++){ if(free_names[i]) fs_give((void **) &free_names[i]); if(free_labels[i]) fs_give((void **) &free_labels[i]); } return (ret); }#endif /* _WINDOWS */ suspend_busy_cue(); flush_ordered_messages(); /* show user previous status msgs */ mark_status_dirty(); /* clear message next display call */ real_line = line > 0 ? line : ps_global->ttyo->screen_rows + line; MoveCursor(real_line, RAD_BUT_COL); CleartoEOLN(); /*---- Find widest label ----*/ max_label = 0; for(i = 0; esc_list && esc_list[i].ch != -1 && i < 11; i++){ if(esc_list[i].ch == -2) /* -2 means to skip this key and leave blank */ continue; if(esc_list[i].name) max_label = MAX(max_label, utf8_width(esc_list[i].name)); } if(ps_global->ttyo->screen_cols - max_label - 1 > 0) maxcol = ps_global->ttyo->screen_cols - max_label - 1; else maxcol = 0; /* * We need to be able to truncate q, so copy it in case it is * a readonly string. */ q = cpystr(utf8prompt); /*---- Init structs for keymenu ----*/ for(i = 0; i < 12; i++) memset((void *)&rb_keys[i], 0, sizeof(struct key)); memset((void *)&rb_keymenu, 0, sizeof(struct key_menu)); rb_keymenu.how_many = 1; rb_keymenu.keys = rb_keys; /*---- Setup key menu ----*/ start = 0; clrbitmap(bitmap); memset(fkey_table, NO_OP_COMMAND, 12 * sizeof(int)); if(flags & RB_RET_HELP && help_text != NO_HELP) panic("RET_HELP and help in radio_buttons!"); /* if shown, always at position 0 */ if(help_text != NO_HELP || flags & RB_RET_HELP){ rb_keymenu.keys[0].name = "?"; rb_keymenu.keys[0].label = N_("Help");
开发者ID:ctubio,项目名称:alpine,代码行数:67,
示例17: mvwprintz/** * Displays the vehicle's stats at the bottom of the window. */void veh_interact::display_stats (){ bool conf = veh->valid_wheel_config(); const int second_column = 29; const int third_column = 56; std::string speed_units = OPTIONS["USE_METRIC_SPEEDS"].getValue(); float speed_factor = 0.01f; if (OPTIONS["USE_METRIC_SPEEDS"] == "km/h") { speed_factor *= 1.61; } std::string weight_units = OPTIONS["USE_METRIC_WEIGHTS"].getValue(); float weight_factor; if (OPTIONS["USE_METRIC_WEIGHTS"] == "kg") { weight_factor = 1; } else { weight_factor = 2.2f; } mvwprintz(w_stats, 0, 1, c_ltgray, _("Name: ")); mvwprintz(w_stats, 0, 1+utf8_width(_("Name: ")), c_ltgreen, veh->name.c_str()); fold_and_print(w_stats, 1, 1, second_column, c_ltgray, _("Safe speed: <color_ltgreen>%3d</color> %s"), int(veh->safe_velocity(false) * speed_factor), speed_units.c_str()); fold_and_print(w_stats, 2, 1, second_column, c_ltgray, _("Top speed: <color_ltred>%3d</color> %s"), int(veh->max_velocity(false) * speed_factor), speed_units.c_str()); fold_and_print(w_stats, 3, 1, second_column, c_ltgray, _("Acceleration: <color_ltblue>%3d</color> %s/t"), int(veh->acceleration(false) * speed_factor), speed_units.c_str()); fold_and_print(w_stats, 4, 1, second_column, c_ltgray, _("Mass: <color_ltblue>%5d</color> %s"), int(veh->total_mass() * weight_factor), weight_units.c_str()); if (conf) { fold_and_print(w_stats, 5, 1, second_column, c_ltgray, _("Wheels: <color_ltgreen>enough</color>")); } else { fold_and_print(w_stats, 5, 1, second_column, c_ltgray, _("Wheels: <color_ltred> lack</color>")); } fold_and_print(w_stats, 2, second_column, third_column, c_ltgray, _("K dynamics: <color_ltblue>%3d</color>%%"), int(veh->k_dynamics() * 100)); fold_and_print(w_stats, 3, second_column, third_column, c_ltgray, _("K mass: <color_ltblue>%3d</color>%%"), int(veh->k_mass() * 100)); mvwprintz(w_stats, 1, second_column, c_ltgray, _("Fuel usage (safe): ")); int fuel_usage_x = 1 + second_column + utf8_width(_("Fuel usage (safe): ")); ammotype fuel_types[3] = { "gasoline", "battery", "plasma" }; nc_color fuel_colors[3] = { c_ltred, c_yellow, c_ltblue }; bool first = true; for (int i = 0; i < 3; ++i) { int fuel_usage = veh->basic_consumption (fuel_types[i]); if (fuel_usage > 0) { fuel_usage = fuel_usage / 100; if (fuel_usage < 1) { fuel_usage = 1; } if (!first) { mvwprintz(w_stats, 1, fuel_usage_x++, c_ltgray, "/"); } mvwprintz(w_stats, 1, fuel_usage_x++, fuel_colors[i], "%d", fuel_usage); if (fuel_usage > 9) { fuel_usage_x++; } if (fuel_usage > 99) { fuel_usage_x++; } first = false; } } veh->print_fuel_indicator (w_stats, 1, third_column, true, true); wrefresh (w_stats);}
开发者ID:nommi,项目名称:Cataclysm-DDA,代码行数:76,
示例18: newwinvoid input_context::display_help(){ inp_mngr.set_timeout(-1); // Shamelessly stolen from help.cpp WINDOW *w_help = newwin(FULL_SCREEN_HEIGHT - 2, FULL_SCREEN_WIDTH - 2, 1 + (int)((TERMY > FULL_SCREEN_HEIGHT) ? (TERMY - FULL_SCREEN_HEIGHT) / 2 : 0), 1 + (int)((TERMX > FULL_SCREEN_WIDTH) ? (TERMX - FULL_SCREEN_WIDTH) / 2 : 0)); // has the user changed something? bool changed = false; // keybindings before the user changed anything. input_manager::t_action_contexts old_action_contexts(inp_mngr.action_contexts); // current status: adding/removing/showing keybindings enum { s_remove, s_add, s_add_global, s_show } status = s_show; // copy of registered_actions, but without the ANY_INPUT and COORDINATE, which should not be shown std::vector<std::string> org_registered_actions(registered_actions); std::vector<std::string>::iterator any_input = std::find(org_registered_actions.begin(), org_registered_actions.end(), ANY_INPUT); if (any_input != org_registered_actions.end()) { org_registered_actions.erase(any_input); } std::vector<std::string>::iterator coordinate = std::find(org_registered_actions.begin(), org_registered_actions.end(), COORDINATE); if (coordinate != org_registered_actions.end()) { org_registered_actions.erase(coordinate); } // colors of the keybindings static const nc_color global_key = c_ltgray; static const nc_color local_key = c_ltgreen; static const nc_color unbound_key = c_ltred; // (vertical) scroll offset size_t scroll_offset = 0; // height of the area usable for display of keybindings, excludes headers & borders const size_t display_height = FULL_SCREEN_HEIGHT - 2 - 2; // -2 for the border // width of the legend const size_t legwidth = FULL_SCREEN_WIDTH - 51 - 2; // keybindings help std::ostringstream legend; legend << "<color_" << string_from_color(unbound_key) << ">" << _("Unbound keys") << "</color>/n"; legend << "<color_" << string_from_color(local_key) << ">" << _("Keybinding active only on this screen") << "</color>/n"; legend << "<color_" << string_from_color(global_key) << ">" << _("Keybinding active globally") << "</color>/n"; legend << _("Press - to remove keybinding/nPress + to add local keybinding/nPress = to add global keybinding/n"); input_context ctxt("HELP_KEYBINDINGS"); ctxt.register_action("UP", _("Scroll up")); ctxt.register_action("DOWN", _("Scroll down")); ctxt.register_action("REMOVE"); ctxt.register_action("ADD_LOCAL"); ctxt.register_action("ADD_GLOBAL"); ctxt.register_action("QUIT"); ctxt.register_action("ANY_INPUT"); if (category != "HELP_KEYBINDINGS") { // avoiding inception! ctxt.register_action("HELP_KEYBINDINGS"); } std::string hotkeys = ctxt.get_available_single_char_hotkeys(display_help_hotkeys); while(true) { werase(w_help); draw_border(w_help); draw_scrollbar(w_help, scroll_offset, display_height, org_registered_actions.size(), 1); mvwprintz(w_help, 0, (FULL_SCREEN_WIDTH - utf8_width(_("Keybindings"))) / 2 - 1, c_ltred, " %s ", _("Keybindings")); fold_and_print(w_help, 1, 51, legwidth, c_white, legend.str()); for (size_t i = 0; i + scroll_offset < org_registered_actions.size() && i < display_height; i++) { const std::string &action_id = org_registered_actions[i + scroll_offset]; bool overwrite_default; const action_attributes &attributes = inp_mngr.get_action_attributes(action_id, category, &overwrite_default); char invlet; if (i < hotkeys.size()) { invlet = hotkeys[i]; } else { invlet = ' '; } if (status == s_add_global && overwrite_default) { // We're trying to add a global, but this action has a local // defined, so gray out the invlet. mvwprintz(w_help, i + 1, 2, c_dkgray, "%c ", invlet); } else if (status == s_add || status == s_add_global) { mvwprintz(w_help, i + 1, 2, c_blue, "%c ", invlet); } else if (status == s_remove) { mvwprintz(w_help, i + 1, 2, c_blue, "%c ", invlet); } else { mvwprintz(w_help, i + 1, 2, c_blue, " "); } nc_color col; if (attributes.input_events.empty()) { col = unbound_key; } else if (overwrite_default) { col = local_key; } else { col = global_key; } mvwprintz(w_help, i + 1, 4, col, "%s: ", get_action_name(action_id).c_str());//.........这里部分代码省略.........
开发者ID:QuantumTangler,项目名称:Cataclysm-DDA,代码行数:101,
示例19: parse_levelint sokoban_game::start_game(){ int iScore = 0; int iMoves = 0; iTotalMoves = 0; int iDirY, iDirX; const int iOffsetX = (TERMX > FULL_SCREEN_WIDTH) ? (TERMX - FULL_SCREEN_WIDTH) / 2 : 0; const int iOffsetY = (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY - FULL_SCREEN_HEIGHT) / 2 : 0; parse_level(); WINDOW *w_sokoban = newwin(FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, iOffsetY, iOffsetX); draw_border(w_sokoban); center_print(w_sokoban, 0, hilite(c_white), _("Sokoban")); std::vector<std::string> shortcuts; shortcuts.push_back(_("<+> next")); // '+': next shortcuts.push_back(_("<-> prev")); // '-': prev shortcuts.push_back(_("<r>eset")); // 'r': reset shortcuts.push_back(_("<q>uit")); // 'q': quit shortcuts.push_back(_("<u>ndo move")); // 'u': undo move int indent = 10; for (size_t i = 0; i < shortcuts.size(); i++) { indent = std::max(indent, utf8_width(shortcuts[i].c_str()) + 1); } indent = std::min(indent, 30); for (size_t i = 0; i < shortcuts.size(); i++) { shortcut_print(w_sokoban, i + 1, FULL_SCREEN_WIDTH - indent, c_white, c_ltgreen, shortcuts[i]); } int input = '.'; int iPlayerY = 0; int iPlayerX = 0; bool bNewLevel = true; bool bMoved = false; do { if (bNewLevel) { bNewLevel = false; iMoves = 0; vUndo.clear(); iPlayerY = mLevelInfo[iCurrentLevel]["PlayerY"]; iPlayerX = mLevelInfo[iCurrentLevel]["PlayerX"]; mLevel = vLevel[iCurrentLevel]; } print_score(w_sokoban, iScore, iMoves); if (check_win()) { //we won yay if (!mAlreadyWon[iCurrentLevel]) { iScore += 500; mAlreadyWon[iCurrentLevel] = true; } input = '+'; } else { draw_level(w_sokoban); wrefresh(w_sokoban); //Check input input = getch(); } bMoved = false; switch (input) { case KEY_UP: /* up */ iDirY = -1; iDirX = 0; bMoved = true; break; case KEY_DOWN: /* down */ iDirY = 1; iDirX = 0; bMoved = true; break; case KEY_LEFT: /* left */ iDirY = 0; iDirX = -1; bMoved = true; break; case KEY_RIGHT: /* right */ iDirY = 0; iDirX = 1; bMoved = true; break; case 'q': return iScore; break; case 'u': { int iPlayerYNew = 0; int iPlayerXNew = 0;//.........这里部分代码省略.........
开发者ID:joshmcgee,项目名称:Cataclysm-DDA,代码行数:101,
示例20: view_update_line_cachestatic LINE_CACHE_REC *view_update_line_cache(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line){ INDENT_FUNC indent_func; LINE_CACHE_REC *rec; LINE_CACHE_SUB_REC *sub; GSList *lines; unsigned char cmd; const unsigned char *ptr, *next_ptr, *last_space_ptr; int xpos, pos, indent_pos, last_space, last_color, color, linecount; int char_len; unichar chr; g_return_val_if_fail(line->text != NULL, NULL); color = ATTR_RESETFG | ATTR_RESETBG; xpos = 0; indent_pos = view->default_indent; last_space = last_color = 0; last_space_ptr = NULL; sub = NULL; indent_func = view->default_indent_func; linecount = 1; lines = NULL; for (ptr = line->text;;) { if (*ptr == '/0') { /* command */ ptr++; cmd = *ptr; ptr++; if (cmd == LINE_CMD_EOL || cmd == LINE_CMD_FORMAT) break; if (cmd == LINE_CMD_CONTINUE) { unsigned char *tmp; memcpy(&tmp, ptr, sizeof(char *)); ptr = tmp; continue; } if (cmd == LINE_CMD_INDENT) { /* set indentation position here - don't do it if we're too close to right border */ if (xpos < view->width-5) indent_pos = xpos; } else if (cmd == LINE_CMD_INDENT_FUNC) { memcpy(&indent_func, ptr, sizeof(INDENT_FUNC)); ptr += sizeof(INDENT_FUNC); if (indent_func == NULL) indent_func = view->default_indent_func; } else update_cmd_color(cmd, &color); continue; } if (!view->utf8) { next_ptr = ptr+1; char_len = 1; } else { char_len = 1; while (ptr[char_len] != '/0' && char_len < 6) char_len++; next_ptr = ptr; chr = get_utf8_char(&next_ptr, char_len); if (chr < 0) char_len = 1; else char_len = utf8_width(chr); next_ptr++; } if (xpos + char_len > view->width && sub != NULL && (last_space <= indent_pos || last_space <= 10) && view->longword_noindent) { /* long word, remove the indentation from this line */ xpos -= sub->indent; sub->indent = 0; } if (xpos + char_len > view->width) { xpos = indent_func == NULL ? indent_pos : indent_func(view, line, -1); sub = g_new0(LINE_CACHE_SUB_REC, 1); if (last_space > indent_pos && last_space > 10) { /* go back to last space */ color = last_color; ptr = last_space_ptr; while (*ptr == ' ') ptr++; } else if (view->longword_noindent) { /* long word, no indentation in next line */ xpos = 0; sub->continues = TRUE; } sub->start = ptr; sub->indent = xpos; sub->indent_func = indent_func; sub->color = color;//.........这里部分代码省略.........
开发者ID:svn2github,项目名称:irssi,代码行数:101,
示例21: rngvoid faction::randomize(){ // Set up values // TODO: Not always in overmap 0,0 mapx = rng(OMAPX / 10, OMAPX - OMAPX / 10); mapy = rng(OMAPY / 10, OMAPY - OMAPY / 10); // Pick an overall goal. goal = faction_goal(rng(1, NUM_FACGOALS - 1)); if (one_in(4)) { goal = FACGOAL_NONE; // Slightly more likely to not have a real goal } good = facgoal_data[goal].good; strength = facgoal_data[goal].strength; sneak = facgoal_data[goal].sneak; crime = facgoal_data[goal].crime; cult = facgoal_data[goal].cult; job1 = faction_job(rng(1, NUM_FACJOBS - 1)); do { job2 = faction_job(rng(0, NUM_FACJOBS - 1)); } while (job2 == job1); good += facjob_data[job1].good + facjob_data[job2].good; strength += facjob_data[job1].strength + facjob_data[job2].strength; sneak += facjob_data[job1].sneak + facjob_data[job2].sneak; crime += facjob_data[job1].crime + facjob_data[job2].crime; cult += facjob_data[job1].cult + facjob_data[job2].cult; int num_values = 0; int tries = 0; values = 0; do { int v = rng(1, NUM_FACVALS - 1); if (!has_value(faction_value(v)) && matches_us(faction_value(v))) { values |= mfb(v); tries = 0; num_values++; good += facval_data[v].good; strength += facval_data[v].strength; sneak += facval_data[v].sneak; crime += facval_data[v].crime; cult += facval_data[v].cult; } else { tries++; } } while((one_in(num_values) || one_in(num_values)) && tries < 15); std::string noun; int sel = 1, best = strength; if (sneak > best) { sel = 2; best = sneak; } if (crime > best) { sel = 3; best = crime; } if (cult > best) { sel = 4; } if (strength <= 0 && sneak <= 0 && crime <= 0 && cult <= 0) { sel = 0; } switch (sel) { case 1: noun = faction_noun_strong[rng(0, 14)]; power = dice(5, 20); size = dice(5, 6); break; case 2: noun = faction_noun_sneak [rng(0, 14)]; power = dice(5, 8); size = dice(5, 8); break; case 3: noun = faction_noun_crime [rng(0, 14)]; power = dice(5, 16); size = dice(5, 8); break; case 4: noun = faction_noun_cult [rng(0, 14)]; power = dice(8, 8); size = dice(4, 6); break; default: noun = faction_noun_none [rng(0, 14)]; power = dice(6, 8); size = dice(6, 6); } if (one_in(4)) { do { name = string_format(_("The %1$s of %2$s"), noun.c_str(), invent_name().c_str()); } while (utf8_width(name.c_str()) > MAX_FAC_NAME_SIZE); } else if (one_in(2)) { do { name = string_format(_("The %1$s %2$s"), invent_adj().c_str(), noun.c_str()); } while (utf8_width(name.c_str()) > MAX_FAC_NAME_SIZE); } else { do { std::string adj;//.........这里部分代码省略.........
开发者ID:3721assistant,项目名称:Cataclysm-DDA,代码行数:101,
示例22: view_line_draw//.........这里部分代码省略......... first = FALSE; else { ypos++; if (--max == 0) break; } if (subline > 0) { /* continuing previous line - indent it */ indent_func = cache->lines[subline-1].indent_func; if (indent_func == NULL) xpos = cache->lines[subline-1].indent; color = cache->lines[subline-1].color; } else { indent_func = NULL; } if (xpos == 0 && indent_func == NULL) need_clrtoeol = TRUE; else { /* line was indented - need to clear the indented area first */ term_set_color(view->window, ATTR_RESET); term_move(view->window, 0, ypos); term_clrtoeol(view->window); if (indent_func != NULL) xpos = indent_func(view, line, ypos); } if (need_move || xpos > 0) term_move(view->window, xpos, ypos); term_set_color(view->window, color); if (subline == cache->count-1) { text_newline = NULL; need_move = FALSE; } else { /* get the beginning of the next subline */ text_newline = cache->lines[subline].start; need_move = !cache->lines[subline].continues; } drawcount++; subline++; } if (*text == '/0') { /* command */ text++; if (*text == LINE_CMD_EOL || *text == LINE_CMD_FORMAT) break; if (*text == LINE_CMD_CONTINUE) { /* jump to next block */ memcpy(&tmp, text+1, sizeof(unsigned char *)); text = tmp; continue; } else if (*text == LINE_CMD_INDENT_FUNC) { text += sizeof(INDENT_FUNC); } else { update_cmd_color(*text, &color); term_set_color(view->window, color); } text++; continue; } end = text; if (view->utf8) { unichar chr = get_utf8_char(&end, 6); char_width = utf8_width(chr); } else { char_width = 1; } xpos += char_width; if (xpos <= term_width) { if (*text >= 32 && (end != text || (*text & 127) >= 32)) { for (; text < end; text++) term_addch(view->window, *text); term_addch(view->window, *text); } else { /* low-ascii */ term_set_color(view->window, ATTR_RESET|ATTR_REVERSE); term_addch(view->window, (*text & 127)+'A'-1); term_set_color(view->window, color); } } text++; } if (need_clrtoeol && xpos < term_width) { term_set_color(view->window, ATTR_RESET); term_clrtoeol(view->window); } return drawcount;}
开发者ID:svn2github,项目名称:irssi,代码行数:101,
示例23: strbuf_add_wrapped_text/* * Wrap the text, if necessary. The variable indent is the indent for the * first line, indent2 is the indent for all other lines. * If indent is negative, assume that already -indent columns have been * consumed (and no extra indent is necessary for the first line). */void strbuf_add_wrapped_text(struct strbuf *buf, const char *text, int indent1, int indent2, int width){ int indent, w, assume_utf8 = 1; const char *bol, *space, *start = text; size_t orig_len = buf->len; if (width <= 0) { strbuf_add_indented_text(buf, text, indent1, indent2); return; }retry: bol = text; w = indent = indent1; space = NULL; if (indent < 0) { w = -indent; space = text; } for (;;) { char c; size_t skip; while ((skip = display_mode_esc_sequence_len(text))) text += skip; c = *text; if (!c || isspace(c)) { if (w <= width || !space) { const char *start = bol; if (!c && text == start) return; if (space) start = space; else strbuf_addchars(buf, ' ', indent); strbuf_add(buf, start, text - start); if (!c) return; space = text; if (c == '/t') w |= 0x07; else if (c == '/n') { space++; if (*space == '/n') { strbuf_addch(buf, '/n'); goto new_line; } else if (!isalnum(*space)) goto new_line; else strbuf_addch(buf, ' '); } w++; text++; } else {new_line: strbuf_addch(buf, '/n'); text = bol = space + isspace(*space); space = NULL; w = indent = indent2; } continue; } if (assume_utf8) { w += utf8_width(&text, NULL); if (!text) { assume_utf8 = 0; text = start; strbuf_setlen(buf, orig_len); goto retry; } } else { w++; text++; } }}
开发者ID:CoerWatt,项目名称:git,代码行数:87,
示例24: optionally_enterintoptionally_enter(char *utf8string, int y_base, int x_base, int utf8string_size, char *utf8prompt, ESCKEY_S *escape_list, HelpType help, int *flags){ UCS *string = NULL, ucs; size_t string_size; UCS *s2; UCS *saved_original = NULL; char *candidate; UCS *kill_buffer = NULL; UCS *k, *kb; int field_pos; /* offset into array dline.vl */ int i, j, return_v, cols, prompt_width, too_thin, real_y_base, km_popped, passwd; char **help_text; long fkey_table[12]; struct key_menu *km; bitmap_t bitmap; COLOR_PAIR *lastc = NULL, *promptc = NULL; struct variable *vars = ps_global->vars; struct display_line dline;#ifdef _WINDOWS int cursor_shown;#endif dprint((5, "=== optionally_enter called ===/n")); dprint((9, "utf8string:/"%s/" y:%d x:%d length: %d append: %d/n", utf8string ? utf8string : "", x_base, y_base, utf8string_size, (flags && *flags & OE_APPEND_CURRENT))); dprint((9, "passwd:%d utf8prompt:/"%s/" label:/"%s/"/n", (flags && *flags & OE_PASSWD_NOAST) ? 10 : (flags && *flags & OE_PASSWD) ? 1 : 0, utf8prompt ? utf8prompt : "", (escape_list && escape_list[0].ch != -1 && escape_list[0].label) ? escape_list[0].label: "")); if(!ps_global->ttyo) return(pre_screen_config_opt_enter(utf8string, utf8string_size, utf8prompt, escape_list, help, flags));#ifdef _WINDOWS if (mswin_usedialog ()) return(win_dialog_opt_enter(utf8string, utf8string_size, utf8prompt, escape_list, help, flags));#endif /* * Utf8string comes in as UTF-8. We'll convert it to a UCS-4 array and operate on * that array, then convert it back before returning. Utf8string_size is the size * of the utf8string array but that doesn't help us much for the array we need to * operate on here. We'll just allocate a big array and then cut it off when * sending it back. * * This should come before the specialized calls above but those aren't * converted to use UCS-4 yet. */ string = utf8_to_ucs4_cpystr(utf8string); dline.vused = ucs4_strlen(string); string_size = (2 * MAX(utf8string_size,dline.vused) + 100); fs_resize((void **) &string, string_size * sizeof(UCS)); suspend_busy_cue(); cols = ps_global->ttyo->screen_cols; prompt_width = utf8_width(utf8prompt); too_thin = 0; km_popped = 0; if(y_base > 0) real_y_base = y_base; else{ real_y_base = y_base + ps_global->ttyo->screen_rows; real_y_base = MAX(real_y_base, 0); } flush_ordered_messages(); mark_status_dirty(); if(flags && *flags & OE_APPEND_CURRENT) /* save a copy in case of cancel */ saved_original = ucs4_cpystr(string); /* * build the function key mapping table, skipping predefined keys... */ memset(fkey_table, NO_OP_COMMAND, 12 * sizeof(long)); for(i = 0, j = 0; escape_list && escape_list[i].ch != -1 && i+j < 12; i++){ if(i+j == OE_HELP_KEY) j++; if(i+j == OE_CANCEL_KEY) j++; if(i+j == OE_ENTER_KEY) j++; fkey_table[i+j] = escape_list[i].ch; } /* assumption that HelpType is char ** *///.........这里部分代码省略.........
开发者ID:ctubio,项目名称:alpine,代码行数:101,
示例25: utf8_width/* * Calculate sizes, populate arrays, initialize window */void uimenu::setup(){ bool w_auto = (w_width == -1 || w_width == -2 ); bool w_autofold = ( w_width == -2); if ( w_auto ) { w_width = 4; if ( !title.empty() ) { w_width = title.size() + 5; } } bool h_auto = (w_height == -1); if ( h_auto ) { w_height = 4; } max_entry_len = 0; std::vector<int> autoassign; int pad = pad_left + pad_right + 2; for ( size_t i = 0; i < entries.size(); i++ ) { int txtwidth = utf8_width(entries[ i ].txt.c_str()); if ( txtwidth > max_entry_len ) { max_entry_len = txtwidth; } if(entries[ i ].enabled) { if( entries[ i ].hotkey > 0 ) { keymap[ entries[ i ].hotkey ] = i; } else if ( entries[ i ].hotkey == -1 && i < 100 ) { autoassign.push_back(i); } if ( entries[ i ].retval == -1 ) { entries[ i ].retval = i; } if ( w_auto && w_width < txtwidth + pad + 4 ) { w_width = txtwidth + pad + 4; } } else { if ( w_auto && w_width < txtwidth + pad + 4 ) { w_width = txtwidth + pad + 4; // todo: or +5 if header } } if ( entries[ i ].text_color == C_UNSET_MASK ) { entries[ i ].text_color = text_color; } fentries.push_back( i ); } static const std::string hotkeys("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); size_t next_free_hotkey = 0; for( auto it = autoassign.begin(); it != autoassign.end() && next_free_hotkey < hotkeys.size(); ++it ) { while( next_free_hotkey < hotkeys.size() ) { const int setkey = hotkeys[next_free_hotkey]; next_free_hotkey++; if( keymap.count( setkey ) == 0 ) { entries[*it].hotkey = setkey; keymap[setkey] = *it; break; } } } if (w_auto && w_width > TERMX) { w_width = TERMX; } if(!text.empty() ) { int twidth = utf8_width(text.c_str()); bool formattxt = true; int realtextwidth = 0; if ( textwidth == -1 ) { if ( w_autofold || !w_auto ) { realtextwidth = w_width - 4; } else { realtextwidth = twidth; if ( twidth + 4 > w_width ) { if ( realtextwidth + 4 > TERMX ) { realtextwidth = TERMX - 4; } textformatted = foldstring(text, realtextwidth); formattxt = false; realtextwidth = 10; for (auto &l : textformatted) { if ( utf8_width(l.c_str()) > realtextwidth ) { realtextwidth = utf8_width(l.c_str()); } } if ( realtextwidth + 4 > w_width ) { w_width = realtextwidth + 4; } } } } else if ( textwidth != -1 ) { realtextwidth = textwidth; } if ( formattxt == true ) { textformatted = foldstring(text, realtextwidth); }//.........这里部分代码省略.........
开发者ID:Caleneledh,项目名称:Cataclysm-DDA,代码行数:101,
示例26: test_patternvoid test_pattern(int iCurrentPage, int iCurrentLine){ std::vector<std::string> vMatchingItems; std::string sItemName = ""; if (vAutoPickupRules[iCurrentPage][iCurrentLine].sRule == "") { return; } //Loop through all itemfactory items //APU now ignores prefixes, bottled items and suffix combinations still not generated for( auto &p : item_controller->get_all_itypes() ) { sItemName = p.second->nname(1); if (vAutoPickupRules[iCurrentPage][iCurrentLine].bActive && auto_pickup_match(sItemName, vAutoPickupRules[iCurrentPage][iCurrentLine].sRule)) { vMatchingItems.push_back(sItemName); } } const int iOffsetX = 15 + ((TERMX > FULL_SCREEN_WIDTH) ? (TERMX - FULL_SCREEN_WIDTH) / 2 : 0); const int iOffsetY = 5 + ((TERMY > FULL_SCREEN_HEIGHT) ? (TERMY - FULL_SCREEN_HEIGHT) / 2 : 0); int iStartPos = 0; const int iContentHeight = FULL_SCREEN_HEIGHT - 8; const int iContentWidth = FULL_SCREEN_WIDTH - 30; std::stringstream sTemp; WINDOW *w_test_rule_border = newwin(iContentHeight + 2, iContentWidth, iOffsetY, iOffsetX); WINDOW_PTR w_test_rule_borderptr( w_test_rule_border ); WINDOW *w_test_rule_content = newwin(iContentHeight, iContentWidth - 2, 1 + iOffsetY, 1 + iOffsetX); WINDOW_PTR w_test_rule_contentptr( w_test_rule_content ); draw_border(w_test_rule_border); int nmatch = vMatchingItems.size(); std::string buf = string_format(ngettext("%1$d item matches: %2$s", "%1$d items match: %2$s", nmatch), nmatch, vAutoPickupRules[iCurrentPage][iCurrentLine].sRule.c_str()); mvwprintz(w_test_rule_border, 0, iContentWidth / 2 - utf8_width(buf.c_str()) / 2, hilite(c_white), "%s", buf.c_str()); mvwprintz(w_test_rule_border, iContentHeight + 1, 1, red_background(c_white), _("Won't display bottled and suffixes=(fits)")); wrefresh(w_test_rule_border); iCurrentLine = 0; input_context ctxt("AUTO_PICKUP_TEST"); ctxt.register_updown(); ctxt.register_action("QUIT"); while(true) { // Clear the lines for (int i = 0; i < iContentHeight; i++) { for (int j = 0; j < 79; j++) { mvwputch(w_test_rule_content, i, j, c_black, ' '); } } calcStartPos(iStartPos, iCurrentLine, iContentHeight, vMatchingItems.size()); // display auto pickup for (int i = iStartPos; i < (int)vMatchingItems.size(); i++) { if (i >= iStartPos && i < iStartPos + ((iContentHeight > (int)vMatchingItems.size()) ? (int)vMatchingItems.size() : iContentHeight)) { nc_color cLineColor = c_white; sTemp.str(""); sTemp << i + 1; mvwprintz(w_test_rule_content, i - iStartPos, 0, cLineColor, "%s", sTemp.str().c_str()); mvwprintz(w_test_rule_content, i - iStartPos, 4, cLineColor, ""); if (iCurrentLine == i) { wprintz(w_test_rule_content, c_yellow, ">> "); } else { wprintz(w_test_rule_content, c_yellow, " "); } wprintz(w_test_rule_content, (iCurrentLine == i) ? hilite(cLineColor) : cLineColor, vMatchingItems[i].c_str()); } } wrefresh(w_test_rule_content); const std::string action = ctxt.handle_input(); if (action == "DOWN") { iCurrentLine++; if (iCurrentLine >= (int)vMatchingItems.size()) { iCurrentLine = 0; } } else if (action == "UP") { iCurrentLine--; if (iCurrentLine < 0) { iCurrentLine = vMatchingItems.size() - 1; } } else { break; }//.........这里部分代码省略.........
开发者ID:Camkitsune,项目名称:Cataclysm-DDA,代码行数:101,
示例27: toolsetvoid game::item_action_menu(){ const auto &gen = item_action_generator::generator(); const action_map &item_actions = gen.get_item_action_map(); // A bit of a hack for now. If more pseudos get implemented, this should be un-hacked std::vector<item *> pseudos; item toolset( "toolset", calendar::turn ); if( u.has_active_bionic( "bio_tools" ) ) { pseudos.push_back( &toolset ); } item_action_map iactions = gen.map_actions_to_items( u, pseudos ); if( iactions.empty() ) { popup( _( "You don't have any items with registered uses" ) ); } uimenu kmenu; kmenu.text = _( "Execute which action?" ); kmenu.return_invalid = true; input_context ctxt( "ITEM_ACTIONS" ); actmenu_cb callback( item_actions ); kmenu.callback = &callback; int num = 0; const auto assigned_action = [&iactions]( const item_action_id & action ) { return iactions.find( action ) != iactions.end(); }; std::vector<std::tuple<item_action_id, std::string, std::string>> menu_items; // Sorts menu items by action. typedef decltype( menu_items )::iterator Iter; const auto sort_menu = [&menu_items]( Iter from, Iter to ) { std::sort( from, to, []( const std::tuple<item_action_id, std::string, std::string> &lhs, const std::tuple<item_action_id, std::string, std::string> &rhs ) { return std::get<1>( lhs ).compare( std::get<1>( rhs ) ) < 0; } ); }; // Add mapped actions to the menu vector. std::transform( iactions.begin(), iactions.end(), std::back_inserter( menu_items ), []( const std::pair<item_action_id, item *> &elem ) { std::stringstream ss; ss << elem.second->display_name(); if( elem.second->ammo_required() ) { ss << " (" << elem.second->ammo_required() << '/' << elem.second->ammo_remaining() << ')'; } const auto method = elem.second->get_use( elem.first ); return std::make_tuple( method->get_type(), method->get_name(), ss.str() ); } ); // Sort mapped actions. sort_menu( menu_items.begin(), menu_items.end() ); // Add unmapped but binded actions to the menu vector. for( const auto &elem : item_actions ) { if( key_bound_to( ctxt, elem.first ) != '/0' && !assigned_action( elem.first ) ) { menu_items.emplace_back( elem.first, gen.get_action_name( elem.first ), "-" ); } } // Sort unmapped actions. auto iter = menu_items.begin(); std::advance( iter, iactions.size() ); sort_menu( iter, menu_items.end() ); // Determine max lengths, to print the menu nicely. std::pair<int, int> max_len; for( const auto &elem : menu_items ) { max_len.first = std::max( max_len.first, utf8_width( std::get<1>( elem ), true ) ); max_len.second = std::max( max_len.second, utf8_width( std::get<2>( elem ), true ) ); } // Fill the menu. for( const auto &elem : menu_items ) { std::stringstream ss; ss << std::get<1>( elem ) << std::string( max_len.first - utf8_width( std::get<1>( elem ), true ), ' ' ) << std::string( 4, ' ' ); ss << std::get<2>( elem ) << std::string( max_len.second - utf8_width( std::get<2>( elem ), true ), ' ' ); const char bind = key_bound_to( ctxt, std::get<0>( elem ) ); const bool enabled = assigned_action( std::get<0>( elem ) ); kmenu.addentry( num, enabled, bind, ss.str() ); num++; } kmenu.query(); if( kmenu.ret < 0 || kmenu.ret >= ( int )iactions.size() ) { return; } draw_ter(); const item_action_id action = std::get<0>( menu_items[kmenu.ret] ); item *it = iactions[action]; if( u.invoke_item( it, action ) ) { u.i_rem( it ); // Need to remove item }//.........这里部分代码省略.........
开发者ID:DaliTimelord,项目名称:Cataclysm-DDA,代码行数:101,
示例28: utf8_widthvoid uimenu::show() { if (!started) { bool w_auto = (w_width == -1 || w_width == -2 ); bool w_autofold = ( w_width == -2); int realtextwidth = 0; if ( w_auto ) { w_width = 4; } bool h_auto = (w_height == -1); if ( h_auto ) { w_height = 4; } std::vector<int> autoassign; autoassign.clear(); int pad = pad_left + pad_right + 2; for ( int i = 0; i < entries.size(); i++ ) { int txtwidth = utf8_width(entries[ i ].txt.c_str()); if(entries[ i ].enabled) { if( entries[ i ].hotkey > 0 ) { keymap[ entries[ i ].hotkey ] = i; } else if ( entries[ i ].hotkey == -1 && i < 100 ) { autoassign.push_back(i); } if ( entries[ i ].retval == -1 ) { entries[ i ].retval = i; } if ( w_auto && w_width < txtwidth + pad + 4 ) { w_width = txtwidth + pad + 4; } } else { if ( w_auto && w_width < txtwidth + pad + 4 ) { w_width = txtwidth + pad + 4; // todo: or +5 if header } } if ( entries[ i ].text_color == C_UNSET_MASK ) { entries[ i ].text_color = text_color; } } if ( autoassign.size() > 0 ) { for ( int a = 0; a < autoassign.size(); a++ ) { int palloc = autoassign[ a ]; int setkey=-1; if ( palloc < 9 ) { setkey = palloc + 49; // 1-9; } else if ( palloc == 9 ) { setkey = palloc + 39; // 0; } else if ( palloc < 36 ) { setkey = palloc + 87; // a-z } else if ( palloc < 61 ) { setkey = palloc + 29; // A-Z } if ( setkey != -1 && keymap.find(setkey) == keymap.end() ) { entries[ palloc ].hotkey = setkey; keymap[ setkey ] = palloc; } } } if (w_auto && w_width > TERMX) { w_width = TERMX; } if(text.size() > 0 ) { int twidth = utf8_width(text.c_str()); bool formattxt=true; if ( textwidth == -1 ) { if ( w_autofold || !w_auto ) { realtextwidth = w_width - 4; } else { realtextwidth = twidth; if ( twidth + 4 > w_width ) { if ( realtextwidth + 4 > TERMX ) { realtextwidth = TERMX - 4; } textformatted = foldstring(text, realtextwidth); formattxt=false; realtextwidth = 10; for ( int l=0; l < textformatted.size(); l++ ) { if ( utf8_width(textformatted[l].c_str()) > realtextwidth ) { realtextwidth = utf8_width(textformatted[l].c_str()); } } if ( realtextwidth + 4 > w_width ) { w_width = realtextwidth + 4; } } } } else if ( textwidth != -1 ) { realtextwidth = textwidth; } if ( formattxt == true ) { textformatted = foldstring(text, realtextwidth); } } if (h_auto) { w_height = 2 + textformatted.size() + entries.size();//.........这里部分代码省略.........
开发者ID:Kalrog,项目名称:Cataclysm-DDA,代码行数:101,
示例29: werasevoid game::print_menu(WINDOW *w_open, int iSel, const int iMenuOffsetX, int iMenuOffsetY, bool bShowDDA){ // Clear Lines werase(w_open); // Define window size int window_width = getmaxx(w_open); int window_height = getmaxy(w_open); // Draw horizontal line for (int i = 1; i < window_width - 1; ++i) { mvwputch(w_open, window_height - 2, i, c_white, LINE_OXOX); } center_print(w_open, window_height - 1, c_red, _("Please report bugs to [email C++ utf8len函数代码示例 C++ utf8_to_unicode函数代码示例
|