本文整理汇总了Python中horizons.gui.modules.PlayerDataSelection.get_player_color方法的典型用法代码示例。如果您正苦于以下问题:Python PlayerDataSelection.get_player_color方法的具体用法?Python PlayerDataSelection.get_player_color怎么用?Python PlayerDataSelection.get_player_color使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类horizons.gui.modules.PlayerDataSelection
的用法示例。
在下文中一共展示了PlayerDataSelection.get_player_color方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SingleplayerMenu
# 需要导入模块: from horizons.gui.modules import PlayerDataSelection [as 别名]
# 或者: from horizons.gui.modules.PlayerDataSelection import get_player_color [as 别名]
class SingleplayerMenu(Window):
def __init__(self, windows):
super(SingleplayerMenu, self).__init__(windows)
self._mode = None
self._gui = load_uh_widget('singleplayermenu.xml')
self._gui.mapEvents({
'cancel' : self._windows.close,
'okay' : self.act,
'scenario' : Callback(self._select_mode, 'scenario'),
'random' : Callback(self._select_mode, 'random'),
'free_maps': Callback(self._select_mode, 'free_maps')
})
self._playerdata = PlayerDataSelection()
self._aidata = AIDataSelection()
self._gui.findChild(name="playerdataselectioncontainer").addChild(self._playerdata.get_widget())
self._gui.findChild(name="aidataselectioncontainer").addChild(self._aidata.get_widget())
def hide(self):
# Save the player-data on hide so that other menus gets updated data
self._playerdata.save_settings()
self._gui.hide()
def show(self):
self._playerdata.update_data()
self._gui.findChild(name='scenario').marked = True
self._select_mode('scenario')
def on_return(self):
self.act()
def _select_mode(self, mode):
self._gui.hide()
modes = {
'random': RandomMapWidget,
'free_maps': FreeMapsWidget,
'scenario': ScenarioMapWidget,
}
# remove old widget
if self._mode:
self._mode.end()
self._gui.findChild(name="right_side_box").removeChild(self._mode.get_widget())
self._mode = modes[mode](self._windows, self, self._aidata)
self._mode.show()
self._gui.findChild(name="right_side_box").addChild(self._mode.get_widget())
self._gui.show()
def act(self):
"""Start the game. Called when OK button is pressed."""
player_color = self._playerdata.get_player_color()
player_name = self._playerdata.get_player_name()
if not player_name:
self._windows.open_popup(_("Invalid player name"), _("You entered an invalid playername."))
return
horizons.globals.fife.set_uh_setting("Nickname", player_name)
self._windows.close()
self._mode.act(player_name, player_color)
示例2: SingleplayerMenu
# 需要导入模块: from horizons.gui.modules import PlayerDataSelection [as 别名]
# 或者: from horizons.gui.modules.PlayerDataSelection import get_player_color [as 别名]
class SingleplayerMenu(object):
def __init__(self, mainmenu):
self._mainmenu = mainmenu
self._mode = None
self._gui = load_uh_widget('singleplayermenu.xml')
self._gui.mapEvents({
'cancel' : self.cancel,
'okay' : self.act,
'scenario' : Callback(self._select_mode, 'scenario'),
'random' : Callback(self._select_mode, 'random'),
'free_maps': Callback(self._select_mode, 'free_maps')
})
self._playerdata = PlayerDataSelection()
self._aidata = AIDataSelection()
self._gui.findChild(name="playerdataselectioncontainer").addChild(self._playerdata.get_widget())
self._gui.findChild(name="aidataselectioncontainer").addChild(self._aidata.get_widget())
def hide(self):
self._gui.hide()
def cancel(self):
self._mainmenu.show_main()
def show(self):
self._mainmenu.hide()
self._mainmenu.current = self
self._mainmenu.on_escape = self.cancel
self._gui.findChild(name='scenario').marked = True
self._select_mode('scenario')
def _select_mode(self, mode):
self._gui.hide()
modes = {
'random': RandomMapWidget,
'free_maps': FreeMapsWidget,
'scenario': ScenarioMapWidget,
}
# remove old widget
if self._mode:
self._mode.end()
self._gui.findChild(name="right_side_box").removeChild(self._mode.get_widget())
self._mode = modes[mode](self._mainmenu, self, self._aidata)
self._mode.show()
self._gui.findChild(name="right_side_box").addChild(self._mode.get_widget())
self._gui.show()
def act(self):
"""Start the game. Called when OK button is pressed."""
player_color = self._playerdata.get_player_color()
player_name = self._playerdata.get_player_name()
if not player_name:
self._mainmenu.show_popup(_("Invalid player name"), _("You entered an invalid playername."))
return
horizons.globals.fife.set_uh_setting("Nickname", player_name)
self._mode.act(player_name, player_color)
示例3: MultiplayerMenu
# 需要导入模块: from horizons.gui.modules import PlayerDataSelection [as 别名]
# 或者: from horizons.gui.modules.PlayerDataSelection import get_player_color [as 别名]
class MultiplayerMenu(Window):
def __init__(self, mainmenu, windows):
super(MultiplayerMenu, self).__init__(windows)
self._mainmenu = mainmenu
def hide(self):
self._gui.hide()
def show(self):
if not self._check_connection():
return
self._gui = load_uh_widget('multiplayermenu.xml')
self._gui.mapEvents({
'cancel' : self._windows.close,
'join' : self._join_game,
'create' : self._create_game,
'refresh': Callback(self._refresh, play_sound=True)
})
self._gui.findChild(name='gamelist').capture(self._update_game_details)
self._playerdata = PlayerDataSelection()
self._gui.findChild(name="playerdataselectioncontainer").addChild(self._playerdata.get_widget())
refresh_worked = self._refresh()
if not refresh_worked:
self._windows.close()
return
# FIXME workaround for multiple callback registrations
# this happens because subscription is done when the window is showed, unsubscription
# only when it is closed. if new windows appear and disappear, show is called multiple
# times. the error handler is used throughout the entire mp menu, that's why we can't
# unsubscribe in hide. need to find a better solution.
NetworkInterface().discard("error", self._on_error)
NetworkInterface().subscribe("error", self._on_error)
self._gui.show()
# TODO Remove once loading a game is implemented again
self._gui.findChild(name='load').parent.hide()
def close(self):
# when the connection to the master server fails, the window will be closed before
# anything has been setup
if not hasattr(self, '_gui'):
return
self.hide()
NetworkInterface().unsubscribe("error", self._on_error)
# the window is also closed when a game starts, don't disconnect in that case
if NetworkInterface().is_connected and not NetworkInterface().is_joined:
NetworkInterface().disconnect()
NetworkInterface().change_name(self._playerdata.get_player_name())
NetworkInterface().change_color(self._playerdata.get_player_color().id)
def on_return(self):
self._join_game()
def _check_connection(self):
"""
Check if all dependencies for multiplayer games are met and we can connect to
the master server. If any dependency is not met, the window is closed.
"""
# It is important to close this window before showing the error popup.
# Otherwise closing the popup will trigger `show` again, a new attempt
# to connect is made, which ends up in an endless loop.
if enet is None:
self._windows.close()
headline = _("Unable to find pyenet")
descr = _('The multiplayer feature requires the library "pyenet", '
"which could not be found on your system.")
advice = _("Linux users: Try to install pyenet through your package manager.")
self._windows.show_error_popup(headline, descr, advice)
return False
if NetworkInterface() is None:
try:
NetworkInterface.create_instance()
except RuntimeError as e:
self._windows.close()
headline = _("Failed to initialize networking.")
descr = _("Network features could not be initialized with the current configuration.")
advice = _("Check the settings you specified in the network section.")
self._windows.show_error_popup(headline, descr, advice, unicode(e))
return False
if not NetworkInterface().is_connected:
try:
NetworkInterface().connect()
except Exception as err:
self._windows.close()
headline = _("Fatal Network Error")
descr = _("Could not connect to master server.")
advice = _("Please check your Internet connection. If it is fine, "
#.........这里部分代码省略.........
示例4: MultiplayerMenu
# 需要导入模块: from horizons.gui.modules import PlayerDataSelection [as 别名]
# 或者: from horizons.gui.modules.PlayerDataSelection import get_player_color [as 别名]
class MultiplayerMenu(object):
def __init__(self, mainmenu):
self._mainmenu = mainmenu
def hide(self):
self._gui.hide()
def show(self):
if not self._check_connection():
return
self._mainmenu.hide()
self._mainmenu.current = self
self._mainmenu.on_escape = self.close
self._gui = load_uh_widget('multiplayermenu.xml')
self._gui.mapEvents({
'cancel' : self.close,
'join' : self._join_game,
'create' : self._create_game,
'refresh': Callback(self._refresh, play_sound=True)
})
self._gui.findChild(name='gamelist').capture(self._update_game_details)
self._gui.findChild(name='showonlyownversion').capture(self._refresh)
self._playerdata = PlayerDataSelection()
self._gui.findChild(name="playerdataselectioncontainer").addChild(self._playerdata.get_widget())
refresh_worked = self._refresh()
if not refresh_worked:
self.cancel()
return
NetworkInterface().subscribe("game_prepare", self._prepare_game)
NetworkInterface().subscribe("game_starts", self._start_game)
NetworkInterface().subscribe("error", self._on_error)
self._gui.show()
# TODO Remove once loading a game is implemented again
self._gui.findChild(name='load').parent.hide()
def close(self):
self.hide()
NetworkInterface().unsubscribe("game_prepare", self._prepare_game)
NetworkInterface().unsubscribe("game_starts", self._start_game)
NetworkInterface().unsubscribe("error", self._on_error)
if NetworkInterface().is_connected:
NetworkInterface().disconnect()
NetworkInterface().change_name(self._playerdata.get_player_name())
NetworkInterface().change_color(self._playerdata.get_player_color().id)
self._mainmenu.show_main()
def _check_connection(self):
"""
Check if all dependencies for multiplayer games are met and we can connect to
the master server.
"""
if enet is None:
headline = _(u"Unable to find pyenet")
descr = _(u'The multiplayer feature requires the library "pyenet", '
u"which could not be found on your system.")
advice = _(u"Linux users: Try to install pyenet through your package manager.")
self._mainmenu.show_error_popup(headline, descr, advice)
return False
if NetworkInterface() is None:
try:
NetworkInterface.create_instance()
except RuntimeError as e:
headline = _(u"Failed to initialize networking.")
descr = _("Network features could not be initialized with the current configuration.")
advice = _("Check the settings you specified in the network section.")
self._mainmenu.show_error_popup(headline, descr, advice, unicode(e))
return False
if not NetworkInterface().is_connected:
try:
NetworkInterface().connect()
except Exception as err:
headline = _(u"Fatal Network Error")
descr = _(u"Could not connect to master server.")
advice = _(u"Please check your Internet connection. If it is fine, "
u"it means our master server is temporarily down.")
self._mainmenu.show_error_popup(headline, descr, advice, unicode(err))
return False
if NetworkInterface().is_joined:
if not NetworkInterface().leavegame():
return False
return True
def _on_error(self, exception, fatal=True):
"""Error callback"""
if fatal and self._mainmenu.session is not None:
#.........这里部分代码省略.........