def activate(self): # Don't use 'register_ui_event_handler' as we want the action pad to be disabled/frozen when paused pf.register_event_handler(pf.EVENT_UNIT_SELECTION_CHANGED, ActionPadVC.__on_selection_changed, self) pf.register_event_handler(pf.SDL_KEYDOWN, ActionPadVC.__on_keydown, self) self.__view.show()
def __on_load(self, event): assert self.fc is None self.fc = fc.FileChooser("Load") self.fc.show() self.deactivate() pf.register_event_handler(EVENT_FILE_CHOOSER_OKAY, MenuVC.__on_load_confirm, self) pf.register_event_handler(EVENT_FILE_CHOOSER_CANCEL, MenuVC.__on_load_cancel, self)
def on_save_as(self, event): assert self.fc is None self.fc = ui.FileChooser() self.fc.show() self.deactivate() pf.register_event_handler(EVENT_FILE_CHOOSER_OKAY, MenuVC.on_save_as_confirm, self) pf.register_event_handler(EVENT_FILE_CHOOSER_CANCEL, MenuVC.on_save_as_cancel, self)
def activate(self): pf.register_event_handler(EVENT_DIPLO_FAC_SELECTION_CHANGED, DiplomacyVC.__on_fac_sel_changed, self) pf.register_event_handler(EVENT_DIPLO_FAC_REMOVED, DiplomacyVC.__on_fac_removed, self) pf.register_event_handler(EVENT_DIPLO_FAC_CHANGED, DiplomacyVC.__on_fac_changed, self) pf.register_event_handler(EVENT_DIPLO_FAC_NEW, DiplomacyVC.__on_fac_new, self) pf.register_event_handler(pf.EVENT_NEW_GAME, DiplomacyVC.__on_new_game, self)
def activate(self): pf.register_event_handler(EVENT_SELECTED_TILE_CHANGED, TerrainTabVC.__on_selected_tile_changed, self) pf.register_event_handler(EVENT_SDL_MOUSEBUTTONDOWN, TerrainTabVC.__on_mouse_pressed, self) pf.register_event_handler(EVENT_SDL_MOUSEBUTTONUP, TerrainTabVC.__on_mouse_released, self) pf.register_event_handler(EVENT_TERRAIN_BRUSH_SIZE_CHANGED, TerrainTabVC.__on_brush_size_changed, self)
war_on = True for unit in red_army_units: atk_pos = (-100, 0) unit.attack(atk_pos) for unit in blue_army_units: atk_pos = (+100, 0) unit.attack(atk_pos) def toggle_pause(user, event): if event[0] == pf.SDL_SCANCODE_P: ss = pf.get_simstate() if ss == pf.G_RUNNING: pf.set_simstate(pf.G_PAUSED_UI_RUNNING) else: pf.set_simstate(pf.G_RUNNING) setup_scene() setup_armies() fixup_anim_combatable() perf_stats_win = psw.PerfStatsWindow() perf_stats_win.show() pf.register_event_handler(pf.SDL_KEYDOWN, start_war, None) pf.register_ui_event_handler(pf.SDL_KEYDOWN, toggle_pause, None)
def activate(self): pf.register_event_handler(EVENT_MENU_NEW, MenuVC.__on_new, self) pf.register_event_handler(EVENT_MENU_LOAD, MenuVC.__on_load, self) pf.register_event_handler(EVENT_MENU_SAVE, MenuVC.__on_save, self) pf.register_event_handler(EVENT_MENU_SAVE_AS, MenuVC.__on_save_as, self) pf.register_event_handler(EVENT_MENU_EXIT, MenuVC.__on_exit, self) pf.register_event_handler(EVENT_MENU_CANCEL, MenuVC.__on_cancel, self) pf.register_event_handler(EVENT_OLD_GAME_TEARDOWN_BEGIN, MenuVC.__on_old_game_teardown_begin, self) pf.register_event_handler(EVENT_OLD_GAME_TEARDOWN_END, MenuVC.__on_old_game_teardown_end, self)
def activate(self): pf.register_event_handler(EVENT_MENU_NEW, MenuVC.__on_new, self) pf.register_event_handler(EVENT_MENU_LOAD, MenuVC.__on_load, self) pf.register_event_handler(EVENT_MENU_SAVE, MenuVC.__on_save, self) pf.register_event_handler(EVENT_MENU_SAVE_AS, MenuVC.__on_save_as, self) pf.register_event_handler(EVENT_MENU_EXIT, MenuVC.__on_exit, self) pf.register_event_handler(EVENT_MENU_CANCEL, MenuVC.__on_cancel, self) pf.register_event_handler(EVENT_MENU_SETTINGS_SHOW, MenuVC.__on_settings_show, self) pf.register_event_handler(common.constants.EVENT_SETTINGS_HIDE, MenuVC.__on_settings_hide, self) pf.register_event_handler(EVENT_MENU_PERF_SHOW, MenuVC.__on_perf_show, self) pf.register_event_handler(EVENT_MENU_SESSION_SHOW, MenuVC.__on_session_show, self) pf.register_event_handler(EVENT_OLD_GAME_TEARDOWN_BEGIN, MenuVC.__on_old_game_teardown_begin, self) pf.register_event_handler(EVENT_OLD_GAME_TEARDOWN_END, MenuVC.__on_old_game_teardown_end, self) pf.register_ui_event_handler( common.constants.EVENT_SESSION_SAVE_REQUESTED, MenuVC.__on_session_save, self) pf.register_ui_event_handler( common.constants.EVENT_SESSION_LOAD_REQUESTED, MenuVC.__on_session_load, self)
active_cam_idx = 0 def toggle_camera(user, event): mode_for_idx = [1, 0] if event[0] == SDL_SCANCODE_C: global active_cam_idx active_cam_idx = (active_cam_idx + 1) % 2 pf.activate_camera(active_cam_idx, mode_for_idx[active_cam_idx]) def toggle_sinbad(user, event): if event[0] == SDL_SCANCODE_V: sinbad.notify(EVENT_SINBAD_TOGGLE_ANIM, None) pf.register_event_handler(EVENT_SDL_KEYDOWN, toggle_camera, None) pf.register_event_handler(EVENT_SDL_KEYDOWN, toggle_sinbad, None) ############################################################ # Setup UI # ############################################################ demo_win = ui.DemoWindow() demo_win.show() perf_win = ui.PerfStatsWindow() perf_win.show()
blue_army_units.remove(self) except: pass am.AnimCombatable._AnimCombatable__on_death = __on_death am.AnimCombatable._AnimCombatable__on_death_anim_finish = __on_death_anim_finish def toggle_war(user, event): if event[0] != pf.SDL_SCANCODE_W: return global war_on if war_on: pf.set_diplomacy_state(0, 1, pf.DIPLOMACY_STATE_PEACE) war_on = False else: pf.set_diplomacy_state(0, 1, pf.DIPLOMACY_STATE_WAR) war_on = True setup_scene() setup_armies() fixup_anim_combatable() perf_stats_win = psw.PerfStatsWindow() perf_stats_win.show() pf.register_event_handler(pf.SDL_KEYDOWN, toggle_war, None)
def activate(self): pf.register_event_handler(pf.SDL_MOUSEMOTION, ObjectsVC.__on_mousemove, self) pf.register_event_handler(pf.SDL_MOUSEBUTTONDOWN, ObjectsVC.__on_click, self) pf.register_event_handler(pf.SDL_MOUSEBUTTONUP, ObjectsVC.__on_release, self) pf.register_event_handler(pf.SDL_MOUSEWHEEL, ObjectsVC.__on_mousewheel, self) pf.register_event_handler(pf.EVENT_NEW_GAME, ObjectsVC.__on_new_game, self) pf.register_event_handler(EVENT_OBJECT_SELECTION_CHANGED, ObjectsVC.__on_selected_object_changed, self) pf.register_event_handler(EVENT_MOUSE_ENTERED_MAP, ObjectsVC.__on_mouse_enter_map, self) pf.register_event_handler(EVENT_MOUSE_EXITED_MAP, ObjectsVC.__on_mouse_exit_map, self) pf.register_event_handler(EVENT_OBJECTS_TAB_MODE_CHANGED, ObjectsVC.__on_mode_changed, self) pf.register_event_handler(EVENT_OBJECT_SELECTED_UNIT_PICKED, ObjectsVC.__on_selected_unit_picked, self) pf.register_event_handler(EVENT_OBJECT_DELETE_SELECTION, ObjectsVC.__on_delete_selection, self) pf.register_event_handler(EVENT_OLD_GAME_TEARDOWN_BEGIN, ObjectsVC.__on_old_game_teardown_begin, self) self.__set_selection_for_mode() self.current_object = self.__object_at_index( self.view.selected_object_idx)
pf.set_faction_controllable(0, False) pf.set_faction_controllable(2, False) pf.set_faction_controllable(3, False) ############################################################ # Setup global events # ############################################################ active_cam_idx = 0 def toggle_camera(user, event): mode_for_idx = [pf.CAM_MODE_RTS, pf.CAM_MODE_FPS] if event[0] == pf.SDL_SCANCODE_C: global active_cam_idx active_cam_idx = (active_cam_idx + 1) % 2 pf.activate_camera(active_cam_idx, mode_for_idx[active_cam_idx]) pf.register_event_handler(pf.SDL_KEYDOWN, toggle_camera, None) ############################################################ # Setup UI # ############################################################ demo_vc = dvc.DemoVC(dw.DemoWindow()) demo_vc.activate() action_pad_vc = apvc.ActionPadVC(apw.ActionPadWindow()) action_pad_vc.activate()
def activate(self): pf.register_event_handler(pf.SDL_MOUSEMOTION, ObjectsVC.__on_mousemove, self) pf.register_event_handler(pf.SDL_MOUSEBUTTONDOWN, ObjectsVC.__on_click, self) pf.register_event_handler(pf.SDL_MOUSEBUTTONUP, ObjectsVC.__on_release, self) pf.register_event_handler(pf.SDL_MOUSEWHEEL, ObjectsVC.__on_mousewheel, self) pf.register_event_handler(pf.EVENT_NEW_GAME, ObjectsVC.__on_new_game, self) pf.register_event_handler(EVENT_OBJECT_SELECTION_CHANGED, ObjectsVC.__on_selected_object_changed, self) pf.register_event_handler(EVENT_MOUSE_ENTERED_MAP, ObjectsVC.__on_mouse_enter_map, self) pf.register_event_handler(EVENT_MOUSE_EXITED_MAP, ObjectsVC.__on_mouse_exit_map, self) pf.register_event_handler(EVENT_OBJECTS_TAB_MODE_CHANGED, ObjectsVC.__on_mode_changed, self) pf.register_event_handler(EVENT_OBJECT_SELECTED_UNIT_PICKED, ObjectsVC.__on_selected_unit_picked, self) pf.register_event_handler(EVENT_OBJECT_DELETE_SELECTION, ObjectsVC.__on_delete_selection, self) pf.register_event_handler(EVENT_OLD_GAME_TEARDOWN_BEGIN, ObjectsVC.__on_old_game_teardown_begin, self) self.__set_selection_for_mode() if self.view.mode == self.view.OBJECTS_MODE_PLACE: self.current_object = self.__object_at_index( self.view.selected_object_idx) else: self.current_object = None # Handle the case where we deleted some factions so our view's index is now stale factions_list = pf.get_factions_list() if self.view.selected_faction_idx >= len(factions_list): self.view.selected_faction_idx = len(factions_list) - 1
def install(): global mouse_over_map mouse_over_map = not pf.mouse_over_ui() and not pf.mouse_over_minimap() pf.register_event_handler(pf.SDL_MOUSEMOTION, __on_mousemove, None)
def activate(self): pf.register_event_handler(EVENT_SETTINGS_APPLY, GameSettingsVC.__on_settings_apply, self) pf.register_event_handler(EVENT_SETTINGS_HB_MODE_CHANGED, GameSettingsVC.__on_hb_mode_changed, self)
and attr not in dir(object) and not isinstance(getattr(cls, attr), types.BuiltinMethodType)] if len(methods) > 0: print indented_border(2, char='*') print 2*tab + "METHODS" print indented_border(2, char='*') for method in methods: print 2*tab + "[{0}]".format(method.__name__) print "{0}".format(wrap_text(method.__doc__, 80, 2 * TAB_WIDTH)) print print star_border print "BUILT-IN CONSTANTS" print star_border print for const in [attr for attr in dir(pf) if (isinstance(getattr(pf, attr), types.IntType) or isinstance(getattr(pf, attr), types.LongType) or isinstance(getattr(pf, attr), types.FloatType) or isinstance(getattr(pf, attr), types.StringType) or isinstance(getattr(pf, attr), types.UnicodeType)) and not attr.startswith('__')]: print(tab + "{0} {1}".format(const, getattr(pf, const))) def on_tick(user, event): pf.global_event(pf.SDL_QUIT, None) pf.register_event_handler(pf.EVENT_UPDATE_START, on_tick, None)
def activate(self): pf.register_event_handler(EVENT_CONTROLLED_FACTION_CHANGED, DemoVC.__on_controlled_faction_chagned, self) pf.register_event_handler(EVENT_SETTINGS_SHOW, DemoVC.__on_settings_show, self) pf.register_event_handler(EVENT_PERF_SHOW, DemoVC.__on_perf_show, self) pf.register_event_handler(common.constants.EVENT_SETTINGS_HIDE, DemoVC.__on_settings_hide, self) self.__view.show()
# import pf import math import traceback ############################################################ # Debugging setup # ############################################################ def on_task_exc(user, event): traceback.print_exception(event[1], event[2], event[3]) pf.register_event_handler(pf.EVENT_SCRIPT_TASK_EXCEPTION, on_task_exc, None) ############################################################ # Global configs # ############################################################ pf.load_map("assets/maps", "plain.pfmap") pf.set_ambient_light_color((1.0, 1.0, 1.0)) pf.set_emit_light_color((1.0, 1.0, 1.0)) pf.set_emit_light_pos((1664.0, 1024.0, 384.0)) pf.disable_fog_of_war() pf.set_minimap_size(0) pf.disable_unit_selection() ############################################################ # Camera setup #
def activate(self): pf.register_event_handler(EVENT_MENU_NEW, MenuVC.on_new, self) pf.register_event_handler(EVENT_MENU_LOAD, MenuVC.on_load, self) pf.register_event_handler(EVENT_MENU_SAVE, MenuVC.on_save, self) pf.register_event_handler(EVENT_MENU_SAVE_AS, MenuVC.on_save_as, self) pf.register_event_handler(EVENT_MENU_EXIT, MenuVC.on_exit, self) pf.register_event_handler(EVENT_MENU_CANCEL, MenuVC.on_cancel, self)
def activate(self): pf.register_event_handler(pf.EVENT_UNIT_SELECTION_CHANGED, ActionPadVC.__on_selection_changed, self) pf.register_event_handler(pf.SDL_KEYDOWN, ActionPadVC.__on_keydown, self) self.__view.show()
def activate(self): pf.register_event_handler(EVENT_TOP_TAB_SELECTION_CHANGED, TabBarVC.__on_tab_changed, self) self.children[self.active_idx].activate()
def activate(self): pf.register_event_handler(EVENT_SETTINGS_APPLY, VideoSettingsVC.__on_settings_apply, self) pf.register_event_handler(EVENT_RES_SETTING_CHANGED, VideoSettingsVC.__on_resolution_changed, self) pf.register_event_handler(EVENT_WINMODE_SETTING_CHANGED, VideoSettingsVC.__on_winmode_changed, self) pf.register_event_handler(EVENT_AR_SETTING_CHANGED, VideoSettingsVC.__on_aspect_ratio_changed, self) pf.register_event_handler(EVENT_WIN_TOP_SETTING_CHANGED, VideoSettingsVC.__on_win_ontop_changed, self) pf.register_event_handler(EVENT_VSYNC_SETTING_CHANGED, VideoSettingsVC.__on_vsync_changed, self) pf.register_event_handler(EVENT_SHADOWS_SETTING_CHANGED, VideoSettingsVC.__on_vsync_changed, self)