int mix_handler(Uint8 quantity, const char* empty_error_str) { Uint8 str[32]; int items_no=0; int i; int cannot_manu = 1; if(manufacture_win < 0) build_manufacture_list(); for(i=MIX_SLOT_OFFSET;i<MIX_SLOT_OFFSET+NUM_MIX_SLOTS;i++) if(manufacture_list[i].quantity > 0) { cannot_manu = 0; break; } if (cannot_manu) { set_shown_string(c_red2, empty_error_str); return 1; } str[0]=MANUFACTURE_THIS; for(i=MIX_SLOT_OFFSET;i<MIX_SLOT_OFFSET+NUM_MIX_SLOTS;i++){ if(manufacture_list[i].quantity > 0){ str[items_no*3+2]=manufacture_list[i].pos; *((Uint16 *)(str+items_no*3+2+1))=SDL_SwapLE16(manufacture_list[i].quantity); items_no++; } } str[1]=items_no; if(items_no){ //don't send an empty string save_last_mix(); str[items_no*3+2]= quantity; my_tcp_send(my_socket,str,items_no*3+3); } 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; }
int click_manufacture_handler(window_info *win, int mx, int my, Uint32 flags) { int pos; static int last_slot=-1; 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, 12, 3, 0, 0, 33, 33); 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_slot=-1; for(j=36;j<36+6;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[pos].quantity -= quantitytomove; copy_recipe(); return 1; } for(j=36;j<36+6;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[pos].quantity -= quantitytomove; copy_recipe(); return 1; } } } else if (pos>=0) last_slot=-1; //see if we clicked on any item from the "production pipe" pos=get_mouse_pos_in_grid(mx, my, 6, 1, 5, manufacture_menu_y_len-37, 33, 33); if (pos >= 0 && manufacture_list[36+pos].quantity > 0) { if(action_mode==ACTION_LOOK || (flags&ELW_RIGHT_MOUSE)){ str[0]=LOOK_AT_INVENTORY_ITEM; str[1]=manufacture_list[36+pos].pos; my_tcp_send(my_socket,str,2); return 1; } else { int j; last_slot=pos; for(j=0;j<36;j++) if(manufacture_list[j].quantity && manufacture_list[j].pos==manufacture_list[36+pos].pos){ //found item in ingredients slot, move from "production pipe" back to this slot if (flags & ELW_WHEEL_DOWN) { if (manufacture_list[36+pos].quantity < quantitytomove) quantitytomove = -manufacture_list[36+pos].quantity; else quantitytomove*=-1; } else if (manufacture_list[36+pos].quantity < quantitytomove) quantitytomove = manufacture_list[36+pos].quantity; manufacture_list[j].quantity += quantitytomove; manufacture_list[j].pos=manufacture_list[36+pos].pos; manufacture_list[j].image_id=manufacture_list[36+pos].image_id; manufacture_list[36+pos].quantity -= quantitytomove; copy_recipe(); return 1; } for(j=0;j<36;j++) if(!manufacture_list[j].quantity){ //found item in ingredients slot, move from "production pipe" back to this slot if (manufacture_list[36+pos].quantity < quantitytomove) quantitytomove = manufacture_list[36+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[36+pos].pos; manufacture_list[j].image_id=manufacture_list[36+pos].image_id; manufacture_list[36+pos].quantity -= quantitytomove; copy_recipe(); return 1; } } } else if (pos>=0) { //click on an empty slot //handle the mouse wheel if (pos!=last_slot && ((flags&ELW_WHEEL_UP)||(flags&ELW_WHEEL_DOWN))) { //simulate a click on the dropdown last_slot=-1; recipe_dropdown_click_handler(win,0,0,flags); use_recipe(cur_recipe); build_manufacture_list(); return 0; } } else last_slot=-1; //see if we clicked on the recipe handler recipe_controls_click_handler(mx,my,flags); // clear the message area if double-clicked if ((my > manufacture_menu_y_len-85) && my < (manufacture_menu_y_len-37)) { static Uint32 last_click = 0; if (safe_button_click(&last_click)) { set_shown_string(0,""); 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; }