/* select the specified recipe and and make sure the window is hidden */ static void select_recipe(int the_recipe) { cur_recipe = the_recipe; use_recipe(cur_recipe); recipes_shown=0; clear_recipe_filter(); hide_window(recipe_win); build_manufacture_list(); }
static void toggle_recipe_window(void) { recipes_shown=!recipes_shown; if (recipes_shown) show_window(recipe_win); else { hide_window(recipe_win); clear_recipe_filter(); } }
static void toggle_recipe_window(void) { if (!recipes_loaded) return; recipes_shown=!recipes_shown; if (recipes_shown) show_window(recipe_win); else { hide_window(recipe_win); clear_recipe_filter(); } }
/* key presses in the window used for a recipe name search string */ static int keypress_recipe_handler(window_info *win, int mx, int my, Uint32 key, Uint32 unikey) { char keychar = tolower(key_to_char(unikey)); last_recipe_key_time = SDL_GetTicks(); if ((keychar == SDLK_RETURN) && (key & ELW_CTRL)) { select_recipe(cur_recipe); return 1; } if ((keychar == '`') || (key & ELW_CTRL) || (key & ELW_ALT)) return 0; if (keychar == SDLK_ESCAPE) { clear_recipe_filter(); return 1; } if (string_input(recipe_name_filter, sizeof(recipe_name_filter), keychar) || (keychar == SDLK_RETURN)) { if (strlen(recipe_name_filter)) { size_t i; for (i=cur_recipe+1; i<cur_recipe+num_recipe_entries; i++) { size_t check = i % num_recipe_entries; if (recipes_store[check].name != NULL && safe_strcasestr(recipes_store[check].name, strlen(recipes_store[check].name), recipe_name_filter, strlen(recipe_name_filter)) != NULL) { /* have matching name so set as the current and make sure visible */ int first_displayed_recipe = vscrollbar_get_pos (win->window_id, recipe_win_scroll_id); int new_pos = first_displayed_recipe; cur_recipe = check; if (cur_recipe < first_displayed_recipe) new_pos = cur_recipe; else if (cur_recipe >= (first_displayed_recipe+num_displayed_recipes)) new_pos = cur_recipe - (num_displayed_recipes - 1); else break; vscrollbar_set_pos(win->window_id, recipe_win_scroll_id, new_pos); break; } } } return 1; } return 0; }
/* draw the recipes - finishing any resize to snap to a reasonable size */ static int recipe_dropdown_draw(window_info *win){ static int resizing = 0; size_t i; int first_displayed_recipe = vscrollbar_get_pos (win->window_id, recipe_win_scroll_id); int relative_cur = cur_recipe - first_displayed_recipe; int help_line = 0; int find_active = 0; /* if resizing wait until we stop */ if (win->resized) resizing = 1; /* once we stop, snap the window size to fit nicely */ else if (resizing) { resizing = 0; num_displayed_recipes = (int)(win->len_y / SLOT_SIZE); if (num_displayed_recipes > num_recipe_entries) num_displayed_recipes = num_recipe_entries; resize_window(win->window_id, recipe_win_width, num_displayed_recipes*SLOT_SIZE); } /* draw all the shown recipes */ for (i=0; i<num_displayed_recipes && i<num_recipe_entries; i++) draw_production_pipe(win,0,SLOT_SIZE*i,i+first_displayed_recipe); /* if shown, the current (highlighted in red) recipe needs drawing again and its name displayed */ if ((relative_cur >= 0) && (relative_cur < num_displayed_recipes)) { draw_production_pipe(win,0,SLOT_SIZE*relative_cur,cur_recipe); if ((cur_recipe < num_recipe_entries) && (recipes_store[cur_recipe].name != NULL)) show_help(recipes_store[cur_recipe].name, win->len_x+5, SLOT_SIZE*relative_cur+(SLOT_SIZE-win->small_font_len_y)/2, win->current_scale); } /* display any name search text */ if (strlen(recipe_name_filter)) { if (SDL_GetTicks() > (last_recipe_key_time+5000)) clear_recipe_filter(); else { static char tmp[30]; safe_snprintf(tmp, sizeof(tmp), "%s[%s]", item_list_find_str, recipe_name_filter); show_help(tmp, 0, win->len_y + 10 + win->small_font_len_y*help_line++, win->current_scale); find_active = 1; } } /* display the name of the recipe with the mouse over, plus general help */ if (mouse_over_recipe != -1) { size_t actual_recipe = mouse_over_recipe + first_displayed_recipe; if ((actual_recipe != cur_recipe) && (actual_recipe < num_recipe_entries) && (recipes_store[actual_recipe].name != NULL)) show_help(recipes_store[actual_recipe].name, win->len_x+5, SLOT_SIZE*mouse_over_recipe+(SLOT_SIZE-win->small_font_len_y)/2, win->current_scale); if (show_help_text) { show_help(cm_help_options_str, 0, win->len_y + 10 + win->small_font_len_y*help_line++, win->current_scale); show_help(recipe_select_str, 0, win->len_y + 10 + win->small_font_len_y*help_line++, win->current_scale); show_help(recipe_load_str, 0, win->len_y + 10 + win->small_font_len_y*help_line++, win->current_scale); show_help(find_active?recipe_during_find_str:recipe_find_str, 0, win->len_y + 10 + win->small_font_len_y*help_line++, win->current_scale); } } mouse_over_recipe = -1; return 1; }