static int recipe_controls_click_handler(int mx, int my, Uint32 flags){ int wpx=SLOT_SIZE*NUM_MIX_SLOTS+2; int wpy=manufacture_menu_y_len-37; int lpx=18; int lpy=SLOT_SIZE; if (mx>wpx&&mx<wpx+lpx&&my>wpy+lpy-10&&my<wpy+lpy){ //arrow if (flags & ELW_WHEEL_UP) { cur_recipe=(cur_recipe-1+num_recipe_entries)%num_recipe_entries; use_recipe(cur_recipe); } else if (flags & ELW_WHEEL_DOWN) { cur_recipe=(cur_recipe+1)%num_recipe_entries; use_recipe(cur_recipe); } else { //normal click toggle_recipe_window(); } build_manufacture_list(); do_click_sound(); } else if (mx>wpx+3&&mx<wpx+lpx-3&&my>wpy&&my<wpy+15){ //+ button copy_recipe_from_manu_list(recipes_store[cur_recipe].items); clear_recipe_name(cur_recipe); build_manufacture_list(); do_click_sound(); // save recipes to disk to avoid loss on disconnects/crashes save_recipes(); } return 0; }
//CLICK HANDLERS int recipe_dropdown_click_handler(window_info *win, int mx, int my, Uint32 flags){ static int last_clicked=0; static int last_recipe=0; if (flags & ELW_WHEEL_UP) { cur_recipe=(cur_recipe-1+SHOW_MAX_RECIPE)%SHOW_MAX_RECIPE; } else if (flags & ELW_WHEEL_DOWN) { cur_recipe=(cur_recipe+1)%SHOW_MAX_RECIPE; } else { //normal click select_window(recipe_win); cur_recipe=my/(33+1); if ( ((SDL_GetTicks() - last_clicked) < 400)&& last_recipe==cur_recipe){ //double click on the same recipe to select it and close the dropdown use_recipe(cur_recipe); recipes_shown=0; hide_window(recipe_win); } last_clicked = SDL_GetTicks(); } build_manufacture_list(); last_recipe = cur_recipe; do_click_sound(); return 1; }
// Control the hud timer by various mouse clicks: // Shift+click changed mode Countdown / Stopwatch // For Countdown, mouse wheel up/down decrease/increase start time. // Defaul step 5, +ctrl 1, +alt 30 // Left-click start/stop timer // Mouse wheel click - reset timer. // int Hud_Timer::mouse_click(Uint32 flags) { // change countdown start if (flags & (ELW_WHEEL_DOWN|ELW_WHEEL_UP)) { int step = 5; if (!mode_coundown) return 1; if (flags & ELW_CTRL) step = 1; else if (flags & ELW_ALT) step = 30; if ((flags & ELW_WHEEL_UP)!=0) step *= -1; set_start(start_value + step); } // control mode else if (flags & ELW_SHIFT) { toggle_mode(); do_window_close_sound(); } else { // reset if (flags & ELW_MID_MOUSE) reset(); // start / stop else if (flags & ELW_LEFT_MOUSE) toggle_running(); do_click_sound(); } return 1; }
static int click_session_handler(window_info *win, int mx, int my, Uint32 flags) { if (flags & (ELW_WHEEL_UP|ELW_WHEEL_DOWN)) return 0; last_mouse_click_y = my; do_click_sound(); return 1; }
int recipe_controls_click_handler(int mx, int my, Uint32 flags){ int i; int wpx=33*6+2; int wpy=manufacture_menu_y_len-37; int lpx=18; int lpy=33; if (mx>wpx&&mx<wpx+lpx&&my>wpy+lpy-10&&my<wpy+lpy){ //arrow if (flags & ELW_WHEEL_UP) { cur_recipe=(cur_recipe-1+SHOW_MAX_RECIPE)%SHOW_MAX_RECIPE; use_recipe(cur_recipe); } else if (flags & ELW_WHEEL_DOWN) { cur_recipe=(cur_recipe+1)%SHOW_MAX_RECIPE; use_recipe(cur_recipe); } else { //normal click recipes_shown=!recipes_shown; } build_manufacture_list(); if (recipes_shown) show_window(recipe_win); else hide_window(recipe_win); do_click_sound(); } else if (mx>wpx+3&&mx<wpx+lpx-3&&my>wpy&&my<wpy+15){ //+ button //copy the recipe for(i=36;i<36+6;i++) recipes[cur_recipe][i-36]=manufacture_list[i]; clear_recipe_name(cur_recipe); build_manufacture_list(); do_click_sound(); // save recipes to disk to avoid loss on disconnects/crashes save_recipes(); } return 0; }
static int recipe_controls_click_handler(window_info *win, int mx, int my, Uint32 flags){ int wpx=pipeline_x + SLOT_SIZE*NUM_MIX_SLOTS; int wpy=manufacture_menu_y_len-recipe_y_offset; int lpx=PIPE_CONTROL_X; int lpy=SLOT_SIZE; if (!recipes_loaded) return 0; if (mx>wpx && mx<wpx+lpx && my>wpy+lpy-control_elem_size*2 && my<wpy+lpy){ //arrow if (flags & ELW_WHEEL_UP) { cur_recipe=(cur_recipe-1+num_recipe_entries)%num_recipe_entries; use_recipe(cur_recipe); } else if (flags & ELW_WHEEL_DOWN) { cur_recipe=(cur_recipe+1)%num_recipe_entries; use_recipe(cur_recipe); } else { //normal click toggle_recipe_window(); } build_manufacture_list(); do_click_sound(); } else if (mx>wpx+win->small_font_len_x/2 && mx<wpx+lpx-win->small_font_len_x/2 && my>wpy && my<wpy+win->small_font_len_y){ //+ button copy_recipe_from_manu_list(recipes_store[cur_recipe].items); clear_recipe_name(cur_recipe); build_manufacture_list(); do_click_sound(); // save recipes to disk to avoid loss on disconnects/crashes save_recipes(); } return 0; }
int click_knowledge_handler(window_info *win, int mx, int my, Uint32 flags) { int x,y,idx; Uint8 str[3]; x= mx; y= my; if(x > win->len_x-win->box_size) return 0; if(y > booklist_y_len) return 0; if(flags&ELW_WHEEL_UP) { vscrollbar_scroll_up(win->window_id, knowledge_scroll_id); return 1; } else if(flags&ELW_WHEEL_DOWN) { vscrollbar_scroll_down(win->window_id, knowledge_scroll_id); return 1; } else { selected_book = -1; x = (x < (win->len_x-win->box_size)/2) ?0 :1; y/=booklist_y_step; idx = x + 2 *(y + vscrollbar_get_pos (win->window_id, knowledge_scroll_id)); if(idx < knowledge_count) { str[0] = GET_KNOWLEDGE_INFO; *(Uint16 *)(str+1) = SDL_SwapLE16((short)idx); my_tcp_send(my_socket,str,3); raw_knowledge_string[0] = '\0'; // Check if we display the book image and label knowledge_book_id = idx; if (knowledge_list[idx].present && knowledge_list[idx].has_book) { widget_unset_flags (win->window_id, knowledge_book_image_id, WIDGET_DISABLED); widget_unset_flags (win->window_id, knowledge_book_label_id, WIDGET_DISABLED); } else { widget_set_flags(win->window_id, knowledge_book_image_id, WIDGET_DISABLED); widget_set_flags(win->window_id, knowledge_book_label_id, WIDGET_DISABLED); } selected_book = idx; } do_click_sound(); } return 1; }
/* act on scroll wheel in the main window or clicking a URL */ static int click_url_handler(window_info *win, int mx, int my, Uint32 flags) { static size_t cm_id = CM_INIT_VALUE; if (flags & ELW_WHEEL_UP) vscrollbar_scroll_up(url_win, url_scroll_id); else if (flags & ELW_WHEEL_DOWN) vscrollbar_scroll_down(url_win, url_scroll_id); else if (have_url_count && url_win_hover_url != NULL) { if (flags & ELW_CTRL) { delete_current_url(url_win_hover_url); do_window_close_sound(); } else if (flags & ELW_RIGHT_MOUSE) { cm_url = url_win_hover_url; /* create first time needed */ if (!cm_valid(cm_id)) { cm_id = cm_create(cm_url_menu_str, context_url_handler); cm_set_pre_show_handler(cm_id, context_url_pre_show_handler); } cm_show_direct(cm_id, -1, -1); } else { /* open the URL but block double clicks */ Uint32 currentclicktime = SDL_GetTicks(); if (currentclicktime < url_win_clicktime) url_win_clicktime = 0; /* just in case we're running for 49 days :) */ if ((currentclicktime - url_win_clicktime > 1000) || (url_win_clicked_url != url_win_hover_url)) { do_click_sound(); open_current_url(url_win_hover_url); } } } url_win_top_line = vscrollbar_get_pos(url_win, url_scroll_id); return 0; }
// Look though the category for the selected item, pick it up if found. // static void select_item(int image_id, Uint16 item_id) { int i; int found_at = -1; for (i=0; i<no_storage; i++) { if ((item_id != unset_item_uid) && (storage_items[i].id != unset_item_uid) && (storage_items[i].quantity > 0)) { if (storage_items[i].id == item_id) { found_at = i; break; } } else if ((storage_items[i].image_id == image_id) && (storage_items[i].quantity > 0)) { found_at = i; break; } } if (found_at < 0) { do_alert1_sound(); item_lists_reset_pickup_fail_time(); } else { active_storage_item=storage_items[found_at].pos; if (!view_only_storage) { storage_item_dragged=found_at; do_drag_item_sound(); } else { do_click_sound(); } } }
//CLICK HANDLERS static int recipe_dropdown_click_handler(window_info *win, int mx, int my, Uint32 flags){ static int last_clicked=0; static int last_recipe=0; int first_displayed_recipe = vscrollbar_get_pos (win->window_id, recipe_win_scroll_id); int rel_curr; if (flags & ELW_WHEEL_UP) { cur_recipe=(cur_recipe-1+num_recipe_entries)%num_recipe_entries; rel_curr = cur_recipe - first_displayed_recipe; if ((rel_curr < 0) || (rel_curr >= num_displayed_recipes)) vscrollbar_set_pos(win->window_id, recipe_win_scroll_id, cur_recipe); } else if (flags & ELW_WHEEL_DOWN) { cur_recipe=(cur_recipe+1)%num_recipe_entries; rel_curr = cur_recipe - first_displayed_recipe; if ((rel_curr < 0) || (rel_curr >= num_displayed_recipes)) { first_displayed_recipe = cur_recipe; if (cur_recipe > 0) first_displayed_recipe -= num_displayed_recipes - 1; vscrollbar_set_pos(win->window_id, recipe_win_scroll_id, first_displayed_recipe); } } else { //normal click select_window(recipe_win); cur_recipe=first_displayed_recipe + my/(SLOT_SIZE+1); //double click on the same recipe to select it and close the dropdown if ( ((SDL_GetTicks() - last_clicked) < 400)&& last_recipe==cur_recipe) select_recipe(cur_recipe); last_clicked = SDL_GetTicks(); do_click_sound(); } last_recipe = cur_recipe; return 1; }
static int click_misc_handler(window_info *win, int mx, int my, Uint32 flags) { int clockheight = 0; int in_stats_bar = 0; // handle scrolling the stats bars if not all displayed if (show_stats_in_hud && (my >= 0) && (my < num_disp_stat*side_stats_bar_height)) { in_stats_bar = 1; if ((first_disp_stat > 0) && ((flags & ELW_WHEEL_UP) || ((flags & ELW_LEFT_MOUSE) && (flags & ELW_CTRL)))) { first_disp_stat--; return 1; } else if ((first_disp_stat + num_disp_stat < NUM_WATCH_STAT-1) && ((flags & ELW_WHEEL_DOWN) || ((flags & ELW_RIGHT_MOUSE) && (flags & ELW_CTRL)))) { first_disp_stat++; return 1; } } if (mouse_is_over_timer(win, mx, my)) return mouse_click_timer(flags); // only handle mouse button clicks, not scroll wheels moves if ( (flags & ELW_MOUSE_BUTTON) == 0) return 0; // reserve CTRL clicks for scrolling if (flags & ELW_CTRL) return 0; //check to see if we clicked on the clock if(view_digital_clock>0){ clockheight += digital_clock_height; } if(view_analog_clock>0){ clockheight += analog_clock_size; } if(my > (win->len_y - compass_size - clockheight) && my < (win->len_y - compass_size)) { unsigned char protocol_name; do_click_sound(); protocol_name= GET_TIME; my_tcp_send(my_socket,&protocol_name,1); return 1; } /* show research if click on the knowledge bar */ if (mouse_is_over_knowedge_bar(win, mx, my)) { do_click_sound(); send_input_text_line("#research", 9); return 1; } //check to see if we clicked on the compass if(my > (win->len_y - compass_size) && my < win->len_y) { unsigned char protocol_name; do_click_sound(); protocol_name= LOCATE_ME; if (flags & ELW_SHIFT) { copy_next_LOCATE_ME = 2; } my_tcp_send(my_socket,&protocol_name,1); return 1; } //check to see if we clicked on the stats if (in_stats_bar) { handle_stats_selection(first_disp_stat + (my / side_stats_bar_height) + 1, flags); return 1; } return 0; }
// Handle mouse clicks in the window // int List_Window::click(window_info *win, int mx, int my, Uint32 flags) { if (my < 0) // don't respond here to title bar being clicked return 0; if (flags & ELW_LEFT_MOUSE) clicked = true; if (!Vars::lists()->valid_active_list()) return 1; // hide and clear any quantity input widow Vars::quantity_input()->close(); size_t last_selected = selected_item_number; size_t num_items = Vars::lists()->get_list().get_num_items(); bool was_dragging = ((storage_item_dragged != -1) || (item_dragged != -1)); size_t over_item_number = Vars::win()->get_item_number(mx, my); // If dragging item and ctrl+left-click on window, add item to list if ((flags & ELW_LEFT_MOUSE) && (flags & ELW_CTRL) && was_dragging) { if (storage_item_dragged != -1) Vars::lists()->add_item(over_item_number, storage_items[storage_item_dragged].image_id, storage_items[storage_item_dragged].id, item_quantity); else if (item_dragged != -1) Vars::lists()->add_item(over_item_number, item_list[item_dragged].image_id, item_list[item_dragged].id, item_quantity); return 1; } // ctrl+right-click on a selected item opens the edit menu if ((flags & ELW_RIGHT_MOUSE) && (flags & ELW_CTRL) && (over_item_number<num_items)) { cm_show_direct(Vars::win()->get_grid_cm(), win->window_id, -1); storage_item_dragged = item_dragged = -1; return 1; } restore_inventory_quantity(); // wheel mouse up/down scrolls if ((flags & ELW_WHEEL_UP ) || (flags & ELW_WHEEL_DOWN )) { // change the active list if (my<get_grid_size()*num_grid_rows) { if (flags & ELW_WHEEL_UP) Vars::lists()->change_active(-1); else if (flags & ELW_WHEEL_DOWN) Vars::lists()->change_active(1); make_active_visable(); } // scroll the names else { if (flags&ELW_WHEEL_UP) vscrollbar_scroll_up(win->window_id, names_scroll_id); else if(flags&ELW_WHEEL_DOWN) vscrollbar_scroll_down(win->window_id, names_scroll_id); } return 1; } // see if we can use the item quantity or take items from storage if ((flags & ELW_RIGHT_MOUSE) || (flags & ELW_LEFT_MOUSE)) { if ((over_item_number!=last_selected) && (over_item_number < num_items)) { selected_item_number = over_item_number; last_quantity_selected = quantities.selected; quantities.selected = ITEM_EDIT_QUANT; item_quantity = quantities.quantity[ITEM_EDIT_QUANT].val = Vars::lists()->get_list().get_quantity(selected_item_number); if (flags & ELW_RIGHT_MOUSE) do_click_sound(); if (flags & ELW_LEFT_MOUSE) { // randomly close the window if (!(SDL_GetTicks() & 63)) { hide_window(Vars::win()->get_id()); set_shown_string(c_red2, item_list_magic_str); return 0; } storage_item_dragged = item_dragged = -1; int image_id = Vars::lists()->get_list().get_image_id(selected_item_number); Uint16 item_id = Vars::lists()->get_list().get_item_id(selected_item_number); int cat_id = Vars::cat_maps()->get_cat(image_id, item_id); if (cat_id != -1) pickup_storage_item(image_id, item_id, cat_id); else { do_alert1_sound(); il_pickup_fail_time = SDL_GetTicks(); static bool first_fail = true; if (first_fail) { first_fail = false; LOG_TO_CONSOLE(c_red1, item_list_learn_cat_str); } } } } else storage_item_dragged = item_dragged = -1; } return 1; }
int click_storage_handler(window_info * win, int mx, int my, Uint32 flags) { if(flags&ELW_WHEEL_UP) { if(mx>10 && mx<130) { vscrollbar_scroll_up(storage_win, STORAGE_SCROLLBAR_CATEGORIES); } else if(mx>150 && mx<352){ vscrollbar_scroll_up(storage_win, STORAGE_SCROLLBAR_ITEMS); } } else if(flags&ELW_WHEEL_DOWN) { if(mx>10 && mx<130) { vscrollbar_scroll_down(storage_win, STORAGE_SCROLLBAR_CATEGORIES); } else if(mx>150 && mx<352){ vscrollbar_scroll_down(storage_win, STORAGE_SCROLLBAR_ITEMS); } } else if ( (flags & ELW_MOUSE_BUTTON) == 0) { return 0; } else { if(my>10 && my<202){ if(mx>10 && mx<130){ int cat=-1; cat=(my-20)/13 + vscrollbar_get_pos(storage_win, STORAGE_SCROLLBAR_CATEGORIES); move_to_category(cat); do_click_sound(); } else if(mx>150 && mx<352){ if(view_only_storage && item_dragged!=-1 && left_click){ drop_fail_time = SDL_GetTicks(); do_alert1_sound(); } else if(!view_only_storage && item_dragged!=-1 && left_click){ Uint8 str[6]; str[0]=DEPOSITE_ITEM; str[1]=item_list[item_dragged].pos; *((Uint32*)(str+2))=SDL_SwapLE32(item_quantity); my_tcp_send(my_socket, str, 6); do_drop_item_sound(); if(item_list[item_dragged].quantity<=item_quantity) item_dragged=-1;//Stop dragging this item... } else if(right_click || (view_only_storage && left_click)){ storage_item_dragged=-1; item_dragged=-1; if(cur_item_over!=-1) { Uint8 str[3]; str[0]=LOOK_AT_STORAGE_ITEM; *((Uint16*)(str+1))=SDL_SwapLE16(storage_items[cur_item_over].pos); my_tcp_send(my_socket, str, 3); active_storage_item=storage_items[cur_item_over].pos; do_click_sound(); } } else if(!view_only_storage && cur_item_over!=-1){ storage_item_dragged=cur_item_over; active_storage_item=storage_items[cur_item_over].pos; do_drag_item_sound(); } } } } return 1; }
// Draw the item list window // int List_Window::draw(window_info *win) { Vars::lists()->check_and_timed_save(false); // if resizing wait until we stop if (win->resized) resizing = true; // once we stop, snap the window size to fix nicely else if (resizing) { calc_num_show_names(win->len_y); resizing = false; resize_window (win->window_id, get_size_x(), get_size_y()); } // check if we need to change the number of grid rows shown int new_num_grid_rows = min_grid_rows(); if (Vars::lists()->valid_active_list()) new_num_grid_rows = std::max(static_cast<size_t>(new_num_grid_rows), (Vars::lists()->get_list().get_num_items() +5) / 6); if (num_grid_rows != new_num_grid_rows) { num_grid_rows = new_num_grid_rows; resized_name_panel(win); } glEnable(GL_TEXTURE_2D); // draw the images if (Vars::lists()->valid_active_list()) { glColor3f(1.0f,1.0f,1.0f); for(size_t i=0; i<Vars::lists()->get_list().get_num_items() && i<static_cast<size_t>(6*num_grid_rows); i++) { int x_start, y_start; x_start = get_grid_size() * (i%6) + 1; y_start = get_grid_size() * (i/6); draw_item(Vars::lists()->get_list().get_image_id(i), x_start, y_start, get_grid_size()); } } size_t help_lines_shown = 0; // Display any name search text if (strlen(filter)) { if (SDL_GetTicks() > (last_key_time+5000)) { filter[0] = '\0'; last_key_time = 0; } else { std::string tmp = std::string(item_list_find_str) + std::string("[") + std::string(filter) + std::string("]"); show_help(tmp.c_str(), 0, static_cast<int>(0.5 + win->len_y + 10 + SMALL_FONT_Y_LEN * help_lines_shown++)); } } // draw mouse over window help text if (show_help_text) { if (!resizing) for (size_t i=0; i<help_str.size(); ++i) show_help(help_str[i], 0, static_cast<int>(0.5 + win->len_y + 10 + SMALL_FONT_Y_LEN * help_lines_shown++)); help_str.clear(); } glDisable(GL_TEXTURE_2D); // draw the item grid glColor3f(0.77f,0.57f,0.39f); rendergrid(6, num_grid_rows, 0, 0, get_grid_size(), get_grid_size()); // if an object is selected, draw a green grid around it if (Vars::lists()->valid_active_list() && (quantities.selected == ITEM_EDIT_QUANT) && (selected_item_number < Vars::lists()->get_list().get_num_items())) { int x_start = selected_item_number%6 * get_grid_size(); int y_start = static_cast<int>(selected_item_number/6) * get_grid_size(); if ((SDL_GetTicks() - il_pickup_fail_time) < 250) glColor3f(0.8f,0.2f,0.2f); else glColor3f(0.0f, 1.0f, 0.3f); rendergrid(1, 1, x_start, y_start, get_grid_size(), get_grid_size()); rendergrid(1, 1, x_start-1, y_start-1, get_grid_size()+2, get_grid_size()+2); } glEnable(GL_TEXTURE_2D); // draw the quantities over everything else so they always show if (Vars::lists()->valid_active_list()) { glColor3f(1.0f,1.0f,1.0f); char str[80]; for(size_t i=0; i<Vars::lists()->get_list().get_num_items() && i<static_cast<size_t>(6*num_grid_rows); i++) { int x_start, y_start, y_end; x_start = get_grid_size() * (i%6) + 1; y_start = get_grid_size() * (i/6); y_end = y_start + get_grid_size() - 1; safe_snprintf(str, sizeof(str), "%i", Vars::lists()->get_list().get_quantity(i)); draw_string_small_shadowed(x_start, (i&1)?(y_end-15):(y_end-27), (unsigned char*)str, 1,1.0f,1.0f,1.0f, 0.0f, 0.0f, 0.0f); } } // Drawn the new list button (+) with highlight when mouse over if (mouse_over_add_button) glColor3f(0.99f,0.77f,0.55f); else glColor3f(0.77f,0.57f,0.39f); draw_string_zoomed(add_button_x, add_button_y, (unsigned const char*)"+", 1, 2.0); // draw the item list names glColor3f(1.0f,1.0f,1.0f); int pos_y = get_grid_size()*num_grid_rows + get_list_gap(); int num_shown = 0; const int top_entry = vscrollbar_get_pos (win_id, names_scroll_id); const std::vector<List> lists = Vars::lists()->get_lists(); const int hl_width = static_cast<int>(win->len_x-ELW_BOX_SIZE-3); const int hl_height = static_cast<int>(names_list_height + get_list_gap()); const size_t disp_chars = static_cast<size_t>((win->len_x-ELW_BOX_SIZE-2*get_list_gap()) / SMALL_FONT_X_LEN); for (size_t i = top_entry; i<lists.size() && num_shown<num_show_names_list; ++i) { if (i==Vars::lists()->get_active()) draw_highlight(1, static_cast<int>(pos_y-get_list_gap()/2), hl_width, hl_height, 1); else if (i==name_under_mouse) draw_highlight(1, static_cast<int>(pos_y-get_list_gap()/2), hl_width, hl_height, 0); glColor3f(1.0f,1.0f,1.0f); if (lists[i].get_name().size() > disp_chars) { std::string todisp = lists[i].get_name().substr(0,disp_chars); draw_string_small(get_list_gap(), pos_y, reinterpret_cast<const unsigned char*>(todisp.c_str()), 1); if (i==name_under_mouse) show_help(lists[i].get_name().c_str(), 0, static_cast<int>(0.5 + win->len_y + 10 + SMALL_FONT_Y_LEN * help_lines_shown)); } else draw_string_small(get_list_gap(), pos_y, reinterpret_cast<const unsigned char*>(lists[i].get_name().c_str()), 1); pos_y += static_cast<int>(names_list_height + get_list_gap()); num_shown++; } if (clicked && (name_under_mouse < lists.size())) { do_click_sound(); Vars::lists()->set_active(name_under_mouse); } if (clicked && mouse_over_add_button) { do_click_sound(); new_or_rename_list(true); } name_under_mouse = static_cast<size_t>(-1); mouse_over_add_button = clicked = false; #ifdef OPENGL_TRACE CHECK_GL_ERRORS(); #endif //OPENGL_TRACE return 1; }
static int click_manufacture_handler(window_info *win, int mx, int my, Uint32 flags) { int pos; Uint8 str[100]; int quantitytomove=1; if ((flags & ELW_CTRL) || (flags & ELW_SHIFT) || (flags & ELW_ALT)) quantitytomove = 10; /* if the eye cursor is active and we right click, change to standard walk */ if(action_mode==ACTION_LOOK && (flags&ELW_RIGHT_MOUSE)) action_mode = ACTION_WALK; //see if we clicked on any item in the main category pos=get_mouse_pos_in_grid(mx, my, GRID_COLS, GRID_ROWS, 0, 0, SLOT_SIZE, SLOT_SIZE); if (pos >= 0 && manufacture_list[pos].quantity > 0) { if(action_mode==ACTION_LOOK || (flags&ELW_RIGHT_MOUSE)) { str[0]=LOOK_AT_INVENTORY_ITEM; str[1]=manufacture_list[pos].pos; my_tcp_send(my_socket,str,2); return 1; } else { int j; last_changed_slot=-1; for(j=MIX_SLOT_OFFSET;j<MIX_SLOT_OFFSET+NUM_MIX_SLOTS;j++) if(manufacture_list[j].pos==manufacture_list[pos].pos && manufacture_list[j].quantity > 0){ //found an empty space in the "production pipe" if (flags & ELW_WHEEL_UP) { if (manufacture_list[j].quantity < quantitytomove) quantitytomove = -manufacture_list[j].quantity; else quantitytomove*=-1; } else if (manufacture_list[pos].quantity < quantitytomove) quantitytomove = manufacture_list[pos].quantity; manufacture_list[j].quantity += quantitytomove; manufacture_list[j].pos=manufacture_list[pos].pos; manufacture_list[j].image_id=manufacture_list[pos].image_id; manufacture_list[j].id=manufacture_list[pos].id; manufacture_list[pos].quantity -= quantitytomove; copy_recipe_from_manu_list(manu_recipe.items); do_click_sound(); return 1; } for(j=MIX_SLOT_OFFSET;j<MIX_SLOT_OFFSET+NUM_MIX_SLOTS;j++) if(manufacture_list[j].quantity <= 0){ //found an empty space in the "production pipe" if (flags & ELW_WHEEL_UP) return 1; //quantity already 0 in production pipeline if (manufacture_list[pos].quantity < quantitytomove) quantitytomove = manufacture_list[pos].quantity; manufacture_list[j].quantity += quantitytomove; manufacture_list[j].pos=manufacture_list[pos].pos; manufacture_list[j].image_id=manufacture_list[pos].image_id; manufacture_list[j].id=manufacture_list[pos].id; manufacture_list[pos].quantity -= quantitytomove; copy_recipe_from_manu_list(manu_recipe.items); do_click_sound(); return 1; } } } else if (pos>=0) last_changed_slot=-1; //see if we clicked on any item from the "production pipe" pos=get_mouse_pos_in_grid(mx, my, NUM_MIX_SLOTS, 1, pipeline_x, manufacture_menu_y_len-recipe_y_offset, SLOT_SIZE, SLOT_SIZE); if (pos >= 0 && manufacture_list[MIX_SLOT_OFFSET+pos].quantity > 0) { if(action_mode==ACTION_LOOK || (flags&ELW_RIGHT_MOUSE)){ str[0]=LOOK_AT_INVENTORY_ITEM; str[1]=manufacture_list[MIX_SLOT_OFFSET+pos].pos; my_tcp_send(my_socket,str,2); return 1; } else { int j; last_changed_slot=pos; for(j=0;j<MIX_SLOT_OFFSET;j++) if(manufacture_list[j].quantity && manufacture_list[j].pos==manufacture_list[MIX_SLOT_OFFSET+pos].pos){ //found item in ingredients slot, move from "production pipe" back to this slot if (flags & ELW_WHEEL_DOWN) { if (manufacture_list[MIX_SLOT_OFFSET+pos].quantity < quantitytomove) quantitytomove = -manufacture_list[MIX_SLOT_OFFSET+pos].quantity; else quantitytomove*=-1; } else if (manufacture_list[MIX_SLOT_OFFSET+pos].quantity < quantitytomove) quantitytomove = manufacture_list[MIX_SLOT_OFFSET+pos].quantity; manufacture_list[j].quantity += quantitytomove; manufacture_list[j].pos=manufacture_list[MIX_SLOT_OFFSET+pos].pos; manufacture_list[j].image_id=manufacture_list[MIX_SLOT_OFFSET+pos].image_id; manufacture_list[j].id=manufacture_list[MIX_SLOT_OFFSET+pos].id; manufacture_list[MIX_SLOT_OFFSET+pos].quantity -= quantitytomove; copy_recipe_from_manu_list(manu_recipe.items); do_click_sound(); return 1; } for(j=0;j<MIX_SLOT_OFFSET;j++) if(!manufacture_list[j].quantity){ //found item in ingredients slot, move from "production pipe" back to this slot if (manufacture_list[MIX_SLOT_OFFSET+pos].quantity < quantitytomove) quantitytomove = manufacture_list[MIX_SLOT_OFFSET+pos].quantity; //handles mouse wheel if (flags & ELW_WHEEL_DOWN) return 1; //No more items to put in production pipe manufacture_list[j].quantity += quantitytomove; manufacture_list[j].pos=manufacture_list[MIX_SLOT_OFFSET+pos].pos; manufacture_list[j].image_id=manufacture_list[MIX_SLOT_OFFSET+pos].image_id; manufacture_list[j].id=manufacture_list[MIX_SLOT_OFFSET+pos].id; manufacture_list[MIX_SLOT_OFFSET+pos].quantity -= quantitytomove; copy_recipe_from_manu_list(manu_recipe.items); do_click_sound(); return 1; } } } else if (pos>=0) { //click on an empty slot //handle the mouse wheel if (recipes_loaded && (pos!=last_changed_slot)) { if (((flags&ELW_WHEEL_UP)||(flags&ELW_WHEEL_DOWN)) && recipe_win >= 0 && recipe_win < windows_list.num_windows) { //simulate a click on the dropdown last_changed_slot=-1; recipe_dropdown_click_handler(&windows_list.window[recipe_win],0,0,flags); use_recipe(cur_recipe); build_manufacture_list(); } else { toggle_recipe_window(); } do_click_sound(); return 0; } } else last_changed_slot=-1; //see if we clicked on the recipe handler recipe_controls_click_handler(win,mx,my,flags); // clear the message area if double-clicked if ((my > manufacture_menu_y_len-text_y_offset) && my < (manufacture_menu_y_len-recipe_y_offset)) { static Uint32 last_click = 0; if (safe_button_click(&last_click)) { set_shown_string(0,""); return 1; } } return 0; }
// Display the main window. All the players achievemnt icons and the controls. // Handle the mouse over events for the icons and the controls. // int Achievements_Window::display_handler(window_info *win) { Achievements_System *as = Achievements_System::get_instance(); int icon_per = (256 / as->get_size()); int icon_per_texture = icon_per * icon_per; bool another_page = false; glEnable(GL_TEXTURE_2D); glColor3f(1.0f,1.0f,1.0f); for (size_t i=first; i<their_achievements.size(); ++i) { size_t shown_num = i-first; if ((static_cast<int>(shown_num)/as->get_per_row()) >= physical_rows) { another_page = true; break; } int texture = -1; const Achievement * achievement = as->achievement(their_achievements[i]); if (achievement) texture = as->texture(achievement->get_id() / icon_per_texture); if (texture >= 0) { int cur_item = achievement->get_id() % icon_per_texture; float u_start = 1.0f/static_cast<float>(icon_per) * (cur_item % icon_per); float u_end = u_start + static_cast<float>(as->get_size())/256; float v_start = 1.0f/static_cast<float>(icon_per) * (cur_item / icon_per); float v_end = v_start + static_cast<float>(as->get_size()) / 256; int start_x = as->get_border() + as->get_display() * (shown_num % as->get_per_row()); int start_y = as->get_border() + as->get_display() * (shown_num / as->get_per_row()); bind_texture(texture); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.05f); glBegin(GL_QUADS); draw_2d_thing( u_start, v_start, u_end, v_end, start_x, start_y, start_x+as->get_display(), start_y+as->get_display() ); glEnd(); glDisable(GL_ALPHA_TEST); } else { int pos_x = as->get_border() + (shown_num % as->get_per_row()) * as->get_display() + (as->get_display() - win->default_font_len_x) / 2; int pos_y = as->get_border() + (shown_num / as->get_per_row()) * as->get_display() + (as->get_display() - win->default_font_len_y) / 2; draw_string_zoomed(pos_x+gx_adjust, pos_y+gy_adjust, (const unsigned char *)"?", 1, win->current_scale); } } size_t now_over = Achievement::npos; if ((cm_window_shown() == CM_INIT_VALUE) && (win_mouse_x > as->get_border()) && (win_mouse_y > as->get_border())) { int row = (win_mouse_y - as->get_border()) / as->get_display(); int col = (win_mouse_x - as->get_border()) / as->get_display(); if ((row >= 0) && (row < physical_rows) && (col >= 0) && (col < as->get_per_row())) { size_t current_index = first + row * as->get_per_row() + col; if (current_index < their_achievements.size()) now_over = their_achievements[current_index]; } } if (now_over != last_over) { if (last_over != Achievement::npos) hide_window(child_win_id); last_over = now_over; if (last_over != Achievement::npos) open_child(); } int prev_start = gx_adjust + as->get_border(); int prev_end = prev_start + as->get_font_x() * as->get_prev().size(); int next_start = prev_end + 2 * as->get_border(); int next_end = next_start + as->get_font_x() * as->get_next().size(); int close_start = gx_adjust + win->len_x - (as->get_border() + as->get_font_x() * as->get_close().size()); int close_end = gx_adjust + win->len_x - as->get_border(); bool over_controls = (win_mouse_y > (win->len_y - (as->get_font_y() + as->get_border()))); bool over_close = (over_controls && (win_mouse_x > close_start) && (win_mouse_x < close_end)); bool over_prev = (over_controls && (win_mouse_x > prev_start) && (win_mouse_x < prev_end)); bool over_next = (over_controls && (win_mouse_x > next_start) && (win_mouse_x < next_end)); float active_colour[3] = { 1.0f, 1.0f, 1.0f }; float inactive_colour[3] = { 0.5f, 0.5f, 0.5f }; float mouse_over_colour[3] = { 1.0f, 0.5f, 0.0f }; glColor3fv((first) ?((over_prev) ?mouse_over_colour :active_colour) :inactive_colour); draw_string_small_zoomed(prev_start, gy_adjust + win->len_y - (as->get_font_y() + as->get_border()), reinterpret_cast<const unsigned char *>(as->get_prev().c_str()), 1, as->get_current_scale()); glColor3fv((another_page) ?((over_next) ?mouse_over_colour :active_colour) :inactive_colour); draw_string_small_zoomed(next_start, gy_adjust + win->len_y - (as->get_font_y() + as->get_border()), reinterpret_cast<const unsigned char *>(as->get_next().c_str()), 1, as->get_current_scale()); glColor3fv((over_close) ?mouse_over_colour :active_colour); draw_string_small_zoomed(close_start, gy_adjust + win->len_y - (as->get_font_y() + as->get_border()), reinterpret_cast<const unsigned char *>(as->get_close().c_str()), 1, as->get_current_scale()); if (over_close && ctrl_clicked) as->hide_all(); if (over_close && clicked) hide_window(main_win_id); else if (over_prev && first && clicked) first -= physical_rows * as->get_per_row(); else if (over_next && another_page && clicked) first += physical_rows * as->get_per_row(); if (clicked && (over_prev || over_next)) do_click_sound(); if ((ctrl_clicked || clicked) && over_close) do_window_close_sound(); if (over_controls && show_help_text) { if (over_close) show_help(as->get_close_help(), 0, win->len_y + as->get_y_win_offset(), win->current_scale); else if (over_prev) show_help((first)?as->get_prev_help() :as->get_no_prev_help(), 0, win->len_y + as->get_y_win_offset(), win->current_scale); else if (over_next) show_help((another_page)?as->get_next_help() :as->get_no_next_help(), 0, win->len_y + as->get_y_win_offset(), win->current_scale); } win_mouse_x = win_mouse_y = -1; ctrl_clicked = clicked = false; return 1; }
void handle_stats_selection(int stat, Uint32 flags) { window_info *win = NULL; int proposed_max_disp_stats = 0; int i; if (stats_bar_win < 0 || stats_bar_win >= windows_list.num_windows) return; win = &windows_list.window[stats_bar_win]; proposed_max_disp_stats = calc_max_disp_stats(calc_stats_bar_len(win, get_num_statsbar_exp()+1)); if (((flags & ELW_ALT) || (flags & ELW_SHIFT)) && (max_disp_stats > 1)) { for (i=0;i<proposed_max_disp_stats;i++) { // if already selected, unselect and remove bar, closing any gap if (watch_this_stats[i]==stat) { statsinfo[stat-1].is_selected=0; if (i<proposed_max_disp_stats-1) memmove(&(watch_this_stats[i]), &(watch_this_stats[i+1]), (proposed_max_disp_stats-i-1) * sizeof(int)); watch_this_stats[proposed_max_disp_stats-1] = 0; break; } // if the bar is not in use, set it to the new stat if (watch_this_stats[i]==0) { watch_this_stats[i]=stat; statsinfo[stat-1].is_selected=1; break; } } } else { // if not already selected, select the stat and replace the first bar if (statsinfo[stat-1].is_selected==0) { statsinfo[watch_this_stats[0]-1].is_selected=0; watch_this_stats[0] = stat; statsinfo[stat-1].is_selected=1; } // else unselect the stat and remove the bar, closing any gap else { statsinfo[stat-1].is_selected=0; for (i=0;i<max_disp_stats;i++) { if (watch_this_stats[i] == stat) { if (i<max_disp_stats-1) memmove(&(watch_this_stats[i]), &(watch_this_stats[i+1]), (max_disp_stats-i-1) * sizeof(int)); watch_this_stats[max_disp_stats-1] = 0; } } } } // default to overall if no valid first skill is set if(watch_this_stats[0]<1 || watch_this_stats[0]>=NUM_WATCH_STAT) { watch_this_stats[0]=NUM_WATCH_STAT-1; statsinfo[watch_this_stats[0]-1].is_selected=1; } init_stats_display(); do_click_sound(); }