本文整理汇总了Python中horizons.messaging.SpeedChanged类的典型用法代码示例。如果您正苦于以下问题:Python SpeedChanged类的具体用法?Python SpeedChanged怎么用?Python SpeedChanged使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SpeedChanged类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: speed_set
def speed_set(self, ticks, suggestion=False):
"""Set game speed to ticks ticks per second"""
old = self.timer.ticks_per_second
self.timer.ticks_per_second = ticks
self.view.map.setTimeMultiplier(float(ticks) / float(GAME_SPEED.TICKS_PER_SECOND))
if old == 0 and self.timer.tick_next_time is None: # back from paused state
if self.paused_time_missing is None:
# happens if e.g. a dialog pauses the game during startup on hotkeypress
self.timer.tick_next_time = time.time()
else:
self.timer.tick_next_time = time.time() + (self.paused_time_missing / ticks)
elif ticks == 0 or self.timer.tick_next_time is None:
# go into paused state or very early speed change (before any tick)
if self.timer.tick_next_time is not None:
self.paused_time_missing = (self.timer.tick_next_time - time.time()) * old
else:
self.paused_time_missing = None
self.timer.tick_next_time = None
else:
"""
Under odd circumstances (anti-freeze protection just activated, game speed
decremented multiple times within this frame) this can delay the next tick
by minutes. Since the positive effects of the code aren't really observeable,
this code is commented out and possibly will be removed.
# correct the time until the next tick starts
time_to_next_tick = self.timer.tick_next_time - time.time()
if time_to_next_tick > 0: # only do this if we aren't late
self.timer.tick_next_time += (time_to_next_tick * old / ticks)
"""
SpeedChanged.broadcast(self, old, ticks)
示例2: end
def end(self):
# unsubscribe early, to avoid messages coming in while we're shutting down
SpeedChanged.unsubscribe(self._on_speed_changed)
NewDisaster.unsubscribe(self._on_new_disaster)
NewSettlement.unsubscribe(self._on_new_settlement)
PlayerLevelUpgrade.unsubscribe(self._on_player_level_upgrade)
MineEmpty.unsubscribe(self._on_mine_empty)
ZoomChanged.unsubscribe(self._update_zoom)
GuiAction.unsubscribe(self._on_gui_click_action)
GuiHover.unsubscribe(self._on_gui_hover_action)
GuiCancelAction.unsubscribe(self._on_gui_cancel_action)
self.mainhud.mapEvents({
'zoomIn' : None,
'zoomOut' : None,
'rotateRight' : None,
'rotateLeft': None,
'destroy_tool' : None,
'build' : None,
'diplomacyButton' : None,
'gameMenuButton' : None
})
self.mainhud.hide()
self.mainhud = None
self.windows.close_all()
self.message_widget = None
self.minimap = None
self.resource_overview.end()
self.resource_overview = None
self.keylistener = None
self.cityinfo.end()
self.cityinfo = None
self.hide_menu()
if self.cursor:
self.cursor.remove()
self.cursor.end()
self.cursor = None
LastActivePlayerSettlementManager().remove()
LastActivePlayerSettlementManager.destroy_instance()
self.production_finished_icon_manager.end()
self.production_finished_icon_manager = None
self.status_icon_manager.end()
self.status_icon_manager = None
super(IngameGui, self).end()
示例3: end
def end(self):
self.mainhud.mapEvents({
'zoomIn' : None,
'zoomOut' : None,
'rotateRight' : None,
'rotateLeft': None,
'destroy_tool' : None,
'build' : None,
'diplomacyButton' : None,
'gameMenuButton' : None
})
self.message_widget = None
self.minimap = None
self.resource_overview.end()
self.resource_overview = None
self.keylistener = None
self.cityinfo.end()
self.cityinfo = None
self.hide_menu()
SettlerUpdate.unsubscribe(self._on_settler_level_change)
SpeedChanged.unsubscribe(self._on_speed_changed)
self.session.view.remove_change_listener(self._update_zoom)
if self.cursor:
self.cursor.remove()
self.cursor.end()
self.cursor = None
LastActivePlayerSettlementManager().remove()
LastActivePlayerSettlementManager.destroy_instance()
self.production_finished_icon_manager.end()
self.production_finished_icon_manager = None
self.status_icon_manager.end()
self.status_icon_manager = None
super(IngameGui, self).end()
示例4: __init__
def __init__(self, session):
super(IngameGui, self).__init__()
self.session = session
assert isinstance(self.session, horizons.session.Session)
self.settlement = None
self._old_menu = None
self.cursor = None
self.coordinates_tooltip = None
self.keylistener = IngameKeyListener(self.session)
self.cityinfo = CityInfo(self)
LastActivePlayerSettlementManager.create_instance(self.session)
self.message_widget = MessageWidget(self.session)
# Windows
self.windows = WindowManager()
self.show_popup = self.windows.show_popup
self.show_error_popup = self.windows.show_error_popup
self.logbook = LogBook(self.session, self.windows)
self.players_overview = PlayersOverview(self.session)
self.players_settlements = PlayersSettlements(self.session)
self.players_ships = PlayersShips(self.session)
self.chat_dialog = ChatDialog(self.windows, self.session)
self.change_name_dialog = ChangeNameDialog(self.windows, self.session)
self.pausemenu = PauseMenu(self.session, self, self.windows, in_editor_mode=False)
self.help_dialog = HelpDialog(self.windows, session=self.session)
# Icon manager
self.status_icon_manager = StatusIconManager(
renderer=self.session.view.renderer['GenericRenderer'],
layer=self.session.view.layers[LAYERS.OBJECTS]
)
self.production_finished_icon_manager = ProductionFinishedIconManager(
renderer=self.session.view.renderer['GenericRenderer'],
layer=self.session.view.layers[LAYERS.OBJECTS]
)
# 'minimap' is the guichan gui around the actual minimap, which is saved
# in self.minimap
self.mainhud = load_uh_widget('minimap.xml')
self.mainhud.position_technique = "right:top"
icon = self.mainhud.findChild(name="minimap")
self.minimap = Minimap(icon,
targetrenderer=horizons.globals.fife.targetrenderer,
imagemanager=horizons.globals.fife.imagemanager,
session=self.session,
view=self.session.view)
def speed_up():
SpeedUpCommand().execute(self.session)
def speed_down():
SpeedDownCommand().execute(self.session)
self.mainhud.mapEvents({
'zoomIn' : self.session.view.zoom_in,
'zoomOut' : self.session.view.zoom_out,
'rotateRight' : Callback.ChainedCallbacks(self.session.view.rotate_right, self.minimap.rotate_right),
'rotateLeft' : Callback.ChainedCallbacks(self.session.view.rotate_left, self.minimap.rotate_left),
'speedUp' : speed_up,
'speedDown' : speed_down,
'destroy_tool' : self.toggle_destroy_tool,
'build' : self.show_build_menu,
'diplomacyButton' : self.show_diplomacy_menu,
'gameMenuButton' : self.toggle_pause,
'logbook' : lambda: self.windows.toggle(self.logbook)
})
self.mainhud.show()
hotkey_replacements = {
'rotateRight': 'ROTATE_RIGHT',
'rotateLeft': 'ROTATE_LEFT',
'speedUp': 'SPEED_UP',
'speedDown': 'SPEED_DOWN',
'destroy_tool': 'DESTROY_TOOL',
'build': 'BUILD_TOOL',
'gameMenuButton': 'ESCAPE',
'logbook': 'LOGBOOK',
}
for (widgetname, action) in hotkey_replacements.iteritems():
widget = self.mainhud.findChild(name=widgetname)
keys = horizons.globals.fife.get_keys_for_action(action)
# No `.upper()` here: "Pause" looks better than "PAUSE".
keyname = HOTKEYS.DISPLAY_KEY.get(keys[0], keys[0].capitalize())
widget.helptext = widget.helptext.format(key=keyname)
self.resource_overview = ResourceOverviewBar(self.session)
# Register for messages
SpeedChanged.subscribe(self._on_speed_changed)
NewDisaster.subscribe(self._on_new_disaster)
NewSettlement.subscribe(self._on_new_settlement)
PlayerLevelUpgrade.subscribe(self._on_player_level_upgrade)
MineEmpty.subscribe(self._on_mine_empty)
#.........这里部分代码省略.........
示例5: __init__
def __init__(self, session, gui):
super(IngameGui, self).__init__()
self.session = session
assert isinstance(self.session, horizons.session.Session)
self.main_gui = gui
self.settlement = None
self._old_menu = None
self.cursor = None
self.coordinates_tooltip = None
self.keylistener = IngameKeyListener(self.session)
self.cityinfo = CityInfo(self)
LastActivePlayerSettlementManager.create_instance(self.session)
self.message_widget = MessageWidget(self.session)
# Windows
self.windows = WindowManager()
self.logbook = LogBook(self.session, self.windows)
self.players_overview = PlayersOverview(self.session)
self.players_settlements = PlayersSettlements(self.session)
self.players_ships = PlayersShips(self.session)
self.chat_dialog = ChatDialog(self.windows, self.session)
self.change_name_dialog = ChangeNameDialog(self.windows, self.session)
self.pausemenu = PauseMenu(self.session, self, self.windows, in_editor_mode=False)
self.help_dialog = HelpDialog(self.windows, session=self.session)
# Icon manager
self.status_icon_manager = StatusIconManager(
renderer=self.session.view.renderer['GenericRenderer'],
layer=self.session.view.layers[LAYERS.OBJECTS]
)
self.production_finished_icon_manager = ProductionFinishedIconManager(
renderer=self.session.view.renderer['GenericRenderer'],
layer=self.session.view.layers[LAYERS.OBJECTS]
)
# 'minimap' is the guichan gui around the actual minimap, which is saved
# in self.minimap
self.mainhud = load_uh_widget('minimap.xml')
self.mainhud.position_technique = "right+0:top+0"
icon = self.mainhud.findChild(name="minimap")
self.minimap = Minimap(icon,
targetrenderer=horizons.globals.fife.targetrenderer,
imagemanager=horizons.globals.fife.imagemanager,
session=self.session,
view=self.session.view)
def speed_up():
SpeedUpCommand().execute(self.session)
def speed_down():
SpeedDownCommand().execute(self.session)
self.mainhud.mapEvents({
'zoomIn' : self.session.view.zoom_in,
'zoomOut' : self.session.view.zoom_out,
'rotateRight' : Callback.ChainedCallbacks(self.session.view.rotate_right, self.minimap.rotate_right),
'rotateLeft' : Callback.ChainedCallbacks(self.session.view.rotate_left, self.minimap.rotate_left),
'speedUp' : speed_up,
'speedDown' : speed_down,
'destroy_tool' : self.toggle_destroy_tool,
'build' : self.show_build_menu,
'diplomacyButton' : self.show_diplomacy_menu,
'gameMenuButton' : self.toggle_pause,
'logbook' : lambda: self.windows.toggle(self.logbook)
})
self.mainhud.show()
self.resource_overview = ResourceOverviewBar(self.session)
# Register for messages
SpeedChanged.subscribe(self._on_speed_changed)
NewDisaster.subscribe(self._on_new_disaster)
NewSettlement.subscribe(self._on_new_settlement)
PlayerLevelUpgrade.subscribe(self._on_player_level_upgrade)
MineEmpty.subscribe(self._on_mine_empty)
self.session.view.add_change_listener(self._update_zoom)
self._display_speed(self.session.timer.ticks_per_second)