#include #include #include "global.h" #ifdef SFX #include "special_effects.h" #endif #ifdef EYE_CANDY #include "eye_candy_wrapper.h" #endif int map_root_win = -1; int showing_continent = 0; int mouse_over_minimap = 0; int reload_tab_map = 0; #define MARK_FILTER_MAX_LEN 40 int mark_filter_active = 0; char mark_filter_text[MARK_FILTER_MAX_LEN] = ""; int click_map_handler (window_info *win, int mx, int my, Uint32 flags) { Uint32 ctrl_on = flags & ELW_CTRL; Uint32 left_click = flags & ELW_LEFT_MOUSE; Uint32 right_click = flags & ELW_RIGHT_MOUSE; float scale = (float) (win->len_x-hud_x) / 300.0f; if (left_click && mx > 0 && mx < 50*scale && my > 0 && my < 55*scale) { showing_continent = !showing_continent; } else if (!showing_continent) { if (left_click) { pf_move_to_mouse_position (); } else if (right_click) { if (!ctrl_on) put_mark_on_map_on_mouse_position (); else delete_mark_on_map_on_mouse_position (); } } return 1; } int display_map_handler (window_info * win) { // are we actively drawing things? if (SDL_GetAppState () & SDL_APPACTIVE) { draw_hud_interface (); Leave2DMode (); if(reload_tab_map && map_root_win >= 0 && windows_list.window[map_root_win].displayed){ //need to reload the BMP switch_from_game_map(); switch_to_game_map(); } draw_game_map (!showing_continent, mouse_over_minimap); Enter2DMode (); CHECK_GL_ERRORS (); reload_tab_map = 0; } #ifdef SFX if(special_effects){ display_special_effects(0); } #endif //SFX // remember the time stamp to improve FPS quality when switching modes next_fps_time=cur_time+1000; last_count=0; #ifdef EYE_CANDY ec_idle(); #endif //EYE_CANDY #ifdef NEW_LIGHTING light_idle(); #endif // NEW_LIGHTING draw_delay = 20; return 1; } int mouseover_map_handler (window_info *win, int mx, int my) { float scale = (float) (win->len_x-hud_x) / 300.0f; if (mx > 0 && mx < 50*scale && my > 0 && my < 55*scale) { mouse_over_minimap = 1; } else { mouse_over_minimap = 0; } return mouse_over_minimap; } int keypress_map_handler (window_info *win, int mx, int my, Uint32 key, Uint32 unikey) { Uint8 ch = key_to_char (unikey); if (ch == SDLK_RETURN && adding_mark && input_text_line.len > 0) { int i; // if text wrapping just keep the text until the wrap. for (i = 0; i < input_text_line.len; i++) { if (input_text_line.data[i] == '\n') { input_text_line.data[i] = '\0'; break; } } marks[max_mark].x = mark_x; marks[max_mark].y = mark_y; memset ( marks[max_mark].text, 0, sizeof (marks[max_mark].text) ); my_strncp ( marks[max_mark].text, input_text_line.data, sizeof (marks[max_mark].text) ); max_mark++; save_markings (); adding_mark = 0; clear_input_line (); } // does the user want to cancel a mapmark? else if (ch == SDLK_ESCAPE && adding_mark) { adding_mark = 0; clear_input_line (); } // enable, disable or reset the mark filter else if ((key == K_MARKFILTER) || (mark_filter_active && (ch == SDLK_ESCAPE))) { if (!mark_filter_active || (ch == SDLK_ESCAPE)) mark_filter_active ^= 1; memset(mark_filter_text, 0, sizeof(char)*MARK_FILTER_MAX_LEN); } // now try the keypress handler for all root windows else if ( keypress_root_common (key, unikey) ) { return 1; } else if (key == K_MAP) { switch_from_game_map (); hide_window (map_root_win); show_window (game_root_win); // Undo stupid quickbar hack if ( !get_show_window (quickbar_win) ) show_window (quickbar_win); } else if (mark_filter_active && !adding_mark) { size_t filt_len = strlen(mark_filter_text); #ifndef OSX if (ch == SDLK_BACKSPACE && filt_len > 0) #else if (((ch == SDLK_BACKSPACE) || (ch == 127)) && filt_len > 0) #endif { mark_filter_text[filt_len-1] = '\0'; } else if (IS_PRINT(ch) && (filt_len < (size_t)(MARK_FILTER_MAX_LEN-1))) { mark_filter_text[filt_len] = ch; mark_filter_text[filt_len+1] = '\0'; } } else { reset_tab_completer(); if (ch == '`' || key == K_CONSOLE) { switch_from_game_map (); hide_window (map_root_win); show_window (console_root_win); } else if ( !text_input_handler (key, unikey) ) { // nothing we can handle return 0; } } // we handled it, return 1 to let the window manager know return 1; } int show_map_handler (window_info *win) { hide_window(book_win); hide_window(paper_win); hide_window(color_race_win); hide_window(tab_bar_win); widget_move_win(input_widget->window_id, input_widget->id, map_root_win); widget_resize (input_widget->window_id, input_widget->id, win->len_x-HUD_MARGIN_X, input_widget->len_y); widget_move (input_widget->window_id, input_widget->id, 0, win->len_y-input_widget->len_y-HUD_MARGIN_Y); widget_set_flags(input_widget->window_id, input_widget->id, INPUT_DEFAULT_FLAGS|WIDGET_INVISIBLE); return 1; } int hide_map_handler (window_info * win) { widget_unset_flag(input_widget->window_id, input_widget->id, WIDGET_INVISIBLE); return 1; } void create_map_root_window (int width, int height) { if (map_root_win < 0) { map_root_win = create_window ("Map", -1, -1, 0, 0, width, height, ELW_TITLE_NONE|ELW_SHOW_LAST); set_window_handler (map_root_win, ELW_HANDLER_DISPLAY, &display_map_handler); set_window_handler (map_root_win, ELW_HANDLER_KEYPRESS, &keypress_map_handler); set_window_handler (map_root_win, ELW_HANDLER_CLICK, &click_map_handler); set_window_handler (map_root_win, ELW_HANDLER_MOUSEOVER, &mouseover_map_handler); set_window_handler (map_root_win, ELW_HANDLER_SHOW, &show_map_handler); set_window_handler (map_root_win, ELW_HANDLER_HIDE, &hide_map_handler); } }