void playsingle_controller::init_gui(){ LOG_NG << "Initializing GUI... " << (SDL_GetTicks() - ticks()) << "\n"; play_controller::init_gui(); // Scroll to the starting position of the first team. If there is a // human team, use that team; otherwise use team 1. If the map defines // a starting position for the selected team, scroll to that tile. Note // this often does not matter since many scenario start with messages, // which will usually scroll to the speaker. Also note that the map // does not necessarily define the starting positions. While usually // best to use the map, the scenarion may explicitly set the positions, // overriding those found in the map (if any). { int scroll_team = gamestate().first_human_team_ + 1; if (scroll_team == 0) { scroll_team = 1; } map_location loc(gamestate().board_.map().starting_position(scroll_team)); if ((loc.x >= 0) && (loc.y >= 0)) { gui_->scroll_to_tile(loc, game_display::WARP); } } update_locker lock_display(gui_->video(), is_skipping_replay()); gui_->draw(); get_hotkey_command_executor()->set_button_state(); events::raise_draw_event(); }
void playsingle_controller::init_gui(){ LOG_NG << "Initializing GUI... " << (SDL_GetTicks() - ticks()) << "\n"; play_controller::init_gui(); if(gamestate().first_human_team_ != -1) { gui_->scroll_to_tile(gamestate().board_.map().starting_position(gamestate().first_human_team_ + 1), game_display::WARP); } gui_->scroll_to_tile(gamestate().board_.map().starting_position(1), game_display::WARP); update_locker lock_display(gui_->video(), is_skipping_replay()); gui_->draw(); get_hotkey_command_executor()->set_button_state(); events::raise_draw_event(); }
void controller_base::execute_action(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu) { hotkey::command_executor * cmd_exec = get_hotkey_command_executor(); if (!cmd_exec) { return; } std::vector<std::string> items; BOOST_FOREACH(const std::string& item, items_arg) { const hotkey::hotkey_command& command = hotkey::get_hotkey_command(item); if(cmd_exec->can_execute_command(command)) items.push_back(item); } if(items.empty()) return; cmd_exec->execute_action(items, xloc, yloc, context_menu, get_display()); }
void controller_base::show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu, display& disp) { hotkey::command_executor * cmd_exec = get_hotkey_command_executor(); if (!cmd_exec) { return; } std::vector<std::string> items = items_arg; std::vector<std::string>::iterator i = items.begin(); while(i != items.end()) { const hotkey::hotkey_command& command = hotkey::get_hotkey_command(*i); if(!cmd_exec->can_execute_command(command) || (context_menu && !in_context_menu(command.id))) { i = items.erase(i); continue; } ++i; } if(items.empty()) return; cmd_exec->show_menu(items, xloc, yloc, context_menu, disp); }
void controller_base::handle_event(const SDL_Event& event) { if(gui::in_dialog()) { return; } static const hotkey::hotkey_command& quit_hotkey = hotkey::hotkey_command::get_command_by_command(hotkey::HOTKEY_QUIT_GAME); switch(event.type) { case SDL_KEYDOWN: // Detect key press events, unless there something that has keyboard focus // in which case the key press events should go only to it. if(have_keyboard_focus()) { if(event.key.keysym.sym == SDLK_ESCAPE) { hotkey::execute_command(get_display(), quit_hotkey, get_hotkey_command_executor()); break; } process_keydown_event(event); hotkey::key_event(get_display(), event, get_hotkey_command_executor()); } else { process_focus_keydown_event(event); break; } // intentionally fall-through case SDL_KEYUP: process_keyup_event(event); break; case SDL_JOYBUTTONDOWN: process_keydown_event(event); hotkey::jbutton_event(get_display(), event, get_hotkey_command_executor()); break; case SDL_JOYHATMOTION: process_keydown_event(event); hotkey::jhat_event(get_display(), event, get_hotkey_command_executor()); break; case SDL_MOUSEMOTION: // Ignore old mouse motion events in the event queue SDL_Event new_event; if(SDL_PeepEvents(&new_event,1,SDL_GETEVENT, SDL_EVENTMASK(SDL_MOUSEMOTION)) > 0) { while(SDL_PeepEvents(&new_event,1,SDL_GETEVENT, SDL_EVENTMASK(SDL_MOUSEMOTION)) > 0) {}; get_mouse_handler_base().mouse_motion_event(new_event.motion, is_browsing()); } else { get_mouse_handler_base().mouse_motion_event(event.motion, is_browsing()); } break; case SDL_MOUSEBUTTONDOWN: process_keydown_event(event); get_mouse_handler_base().mouse_press(event.button, is_browsing()); if (get_mouse_handler_base().get_show_menu()){ show_menu(get_display().get_theme().context_menu()->items(),event.button.x,event.button.y,true, get_display()); } hotkey::mbutton_event(get_display(), event, get_hotkey_command_executor()); break; case SDL_MOUSEBUTTONUP: get_mouse_handler_base().mouse_press(event.button, is_browsing()); if (get_mouse_handler_base().get_show_menu()){ show_menu(get_display().get_theme().context_menu()->items(),event.button.x,event.button.y,true, get_display()); } break; #if !SDL_VERSION_ATLEAST(2, 0, 0) case SDL_ACTIVEEVENT: if (event.active.state == SDL_APPMOUSEFOCUS && event.active.gain == 0) { if (get_mouse_handler_base().is_dragging()) { //simulate mouse button up when the app has lost mouse focus //this should be a general fix for the issue when the mouse //is dragged out of the game window and then the button is released int x, y; Uint8 mouse_flags = SDL_GetMouseState(&x, &y); if ((mouse_flags & SDL_BUTTON_LEFT) == 0) { get_mouse_handler_base().mouse_press(event.button, is_browsing()); } } } break; #endif #if SDL_VERSION_ATLEAST(2,0,0) case SDL_MOUSEWHEEL: get_mouse_handler_base().mouse_wheel(event.wheel.x, event.wheel.y, is_browsing()); break; #endif default: break; } }
void playsingle_controller::end_turn_enable(bool enable) { gui_->enable_menu("endturn", enable); get_hotkey_command_executor()->set_button_state(); }