本文整理匯總了Python中horizons.gui.mousetools.SelectionTool.apply_select方法的典型用法代碼示例。如果您正苦於以下問題:Python SelectionTool.apply_select方法的具體用法?Python SelectionTool.apply_select怎麽用?Python SelectionTool.apply_select使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類horizons.gui.mousetools.SelectionTool
的用法示例。
在下文中一共展示了SelectionTool.apply_select方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Session
# 需要導入模塊: from horizons.gui.mousetools import SelectionTool [as 別名]
# 或者: from horizons.gui.mousetools.SelectionTool import apply_select [as 別名]
#.........這裏部分代碼省略.........
try:
# load how often the game has been saved (used to know the difference between
# a loaded and a new game)
self.savecounter = SavegameManager.get_metadata(savegame)['savecounter']
except KeyError:
self.savecounter = 0
self.world = World(self) # Load horizons.world module (check horizons/world/__init__.py)
self.world._init(savegame_db)
self.view.load(savegame_db) # load view
if not self.is_game_loaded():
# NOTE: this must be sorted before iteration, cause there is no defined order for
# iterating a dict, and it must happen in the same order for mp games.
for i in sorted(players):
self.world.setup_player(i['id'], i['name'], i['color'], i['local'])
center = self.world.init_new_world()
self.view.center(center[0], center[1])
else:
# try to load scenario data
self.scenario_eventhandler.load(savegame_db)
self.manager.load(savegame_db) # load the manager (there might me old scheduled ticks).
self.ingame_gui.load(savegame_db) # load the old gui positions and stuff
for instance_id in savegame_db("SELECT id FROM selected WHERE `group` IS NULL"): # Set old selected instance
obj = WorldObject.get_object_by_id(instance_id[0])
self.selected_instances.add(obj)
obj.select()
for group in xrange(len(self.selection_groups)): # load user defined unit groups
for instance_id in savegame_db("SELECT id FROM selected WHERE `group` = ?", group):
self.selection_groups[group].add(WorldObject.get_object_by_id(instance_id[0]))
# cursor has to be inited last, else player interacts with a not inited world with it.
self.cursor = SelectionTool(self)
self.cursor.apply_select() # Set cursor correctly, menus might need to be opened.
assert hasattr(self.world, "player"), 'Error: there is no human player'
"""
TUTORIAL:
From here on you should digg into the classes that are loaded above, especially the world class.
(horizons/world/__init__.py). It's where the magic happens and all buildings and units are loaded.
"""
def speed_set(self, ticks):
"""Set game speed to ticks ticks per second"""
raise NotImplementedError
def display_speed(self):
text = u''
tps = self.timer.ticks_per_second
if tps == 0: # pause
text = u'0x'
elif tps == GAME_SPEED.TICKS_PER_SECOND: # normal speed, 1x
pass # display nothing
else:
text = unicode(tps/GAME_SPEED.TICKS_PER_SECOND) + u'x' # 2x, 4x, ...
self.ingame_gui.display_game_speed(text)
def speed_up(self):
if self.timer.ticks_per_second in GAME_SPEED.TICK_RATES:
i = GAME_SPEED.TICK_RATES.index(self.timer.ticks_per_second)
if i + 1 < len(GAME_SPEED.TICK_RATES):
self.speed_set(GAME_SPEED.TICK_RATES[i + 1])
else:
self.speed_set(GAME_SPEED.TICK_RATES[0])
def speed_down(self):
示例2: Session
# 需要導入模塊: from horizons.gui.mousetools import SelectionTool [as 別名]
# 或者: from horizons.gui.mousetools.SelectionTool import apply_select [as 別名]
#.........這裏部分代碼省略.........
self.world = World(self) # Load horizons.world module (check horizons/world/__init__.py)
self.world._init(savegame_db, force_player_id, disasters_enabled=disasters_enabled)
self.view.load(savegame_db) # load view
if not self.is_game_loaded():
# NOTE: this must be sorted before iteration, cause there is no defined order for
# iterating a dict, and it must happen in the same order for mp games.
for i in sorted(players, lambda p1, p2: cmp(p1['id'], p2['id'])):
self.world.setup_player(i['id'], i['name'], i['color'], i['clientid'] if is_multiplayer else None, i['local'], i['ai'], i['difficulty'])
self.world.set_forced_player(force_player_id)
center = self.world.init_new_world(trader_enabled, pirate_enabled, natural_resource_multiplier)
self.view.center(center[0], center[1])
else:
# try to load scenario data
self.scenario_eventhandler.load(savegame_db)
self.manager.load(savegame_db) # load the manager (there might me old scheduled ticks).
self.world.init_fish_indexer() # now the fish should exist
if self.is_game_loaded():
LastActivePlayerSettlementManager().load(savegame_db) # before ingamegui
self.ingame_gui.load(savegame_db) # load the old gui positions and stuff
for instance_id in savegame_db("SELECT id FROM selected WHERE `group` IS NULL"): # Set old selected instance
obj = WorldObject.get_object_by_id(instance_id[0])
self.selected_instances.add(obj)
obj.get_component(SelectableComponent).select()
for group in xrange(len(self.selection_groups)): # load user defined unit groups
for instance_id in savegame_db("SELECT id FROM selected WHERE `group` = ?", group):
self.selection_groups[group].add(WorldObject.get_object_by_id(instance_id[0]))
# cursor has to be inited last, else player interacts with a not inited world with it.
self.current_cursor = 'default'
self.cursor = SelectionTool(self)
# Set cursor correctly, menus might need to be opened.
# Open menus later; they may need unit data not yet inited
self.cursor.apply_select()
Scheduler().before_ticking()
savegame_db.close()
assert hasattr(self.world, "player"), 'Error: there is no human player'
"""
TUTORIAL:
That's it. After that, we call start() to activate the timer, and we're live.
From here on you should dig into the classes that are loaded above, especially the world class
(horizons/world/__init__.py). It's where the magic happens and all buildings and units are loaded.
"""
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:
"""
示例3: Session
# 需要導入模塊: from horizons.gui.mousetools import SelectionTool [as 別名]
# 或者: from horizons.gui.mousetools.SelectionTool import apply_select [as 別名]
#.........這裏部分代碼省略.........
self.random.setstate( rng_state_tuple )
self.world = World(self) # Load horizons.world module (check horizons/world/__init__.py)
self.world._init(savegame_db, force_player_id, disasters_enabled=disasters_enabled)
self.view.load(savegame_db) # load view
if not self.is_game_loaded():
# NOTE: this must be sorted before iteration, cause there is no defined order for
# iterating a dict, and it must happen in the same order for mp games.
for i in sorted(players, lambda p1, p2: cmp(p1['id'], p2['id'])):
self.world.setup_player(i['id'], i['name'], i['color'], i['local'], i['ai'], i['difficulty'])
self.world.set_forced_player(force_player_id)
center = self.world.init_new_world(trader_enabled, pirate_enabled, natural_resource_multiplier)
self.view.center(center[0], center[1])
else:
# try to load scenario data
self.scenario_eventhandler.load(savegame_db)
self.manager.load(savegame_db) # load the manager (there might me old scheduled ticks).
self.world.init_fish_indexer() # now the fish should exist
self.ingame_gui.load(savegame_db) # load the old gui positions and stuff
for instance_id in savegame_db("SELECT id FROM selected WHERE `group` IS NULL"): # Set old selected instance
obj = WorldObject.get_object_by_id(instance_id[0])
self.selected_instances.add(obj)
obj.get_component(SelectableComponent).select()
for group in xrange(len(self.selection_groups)): # load user defined unit groups
for instance_id in savegame_db("SELECT id FROM selected WHERE `group` = ?", group):
self.selection_groups[group].add(WorldObject.get_object_by_id(instance_id[0]))
# cursor has to be inited last, else player interacts with a not inited world with it.
self.current_cursor = 'default'
self.cursor = SelectionTool(self)
# Set cursor correctly, menus might need to be opened.
# Open menus later, they may need unit data not yet inited
self.cursor.apply_select()
Scheduler().before_ticking()
savegame_db.close()
assert hasattr(self.world, "player"), 'Error: there is no human player'
"""
TUTORIAL:
That's it. After that, we call start() to activate the timer, and we're on live.
From here on you should digg into the classes that are loaded above, especially the world class.
(horizons/world/__init__.py). It's where the magic happens and all buildings and units are loaded.
"""
def speed_set(self, ticks, suggestion=False):
"""Set game speed to ticks ticks per second"""
raise NotImplementedError
def display_speed(self):
text = u''
up_icon = self.ingame_gui.widgets['minimap'].findChild(name='speedUp')
down_icon = self.ingame_gui.widgets['minimap'].findChild(name='speedDown')
tps = self.timer.ticks_per_second
if tps == 0: # pause
text = u'0x'
up_icon.set_inactive()
down_icon.set_inactive()
else:
if tps != GAME_SPEED.TICKS_PER_SECOND:
text = unicode("%1gx" % (tps * 1.0/GAME_SPEED.TICKS_PER_SECOND))
#%1g: displays 0.5x, but 2x instead of 2.0x
index = GAME_SPEED.TICK_RATES.index(tps)
if index + 1 >= len(GAME_SPEED.TICK_RATES):
up_icon.set_inactive()