Exemple #1
0
    def transfer_to_storageholder(self,
                                  amount,
                                  res_id,
                                  transfer_to,
                                  signal_errors=False):
        """Transfers amount of res_id to transfer_to.
		@param transfer_to: worldid or object reference
		@param signal_errors: whether to play an error sound in case the transfer completely failed (no res transferred)
		@return: amount that was actually transferred (NOTE: this is different from the
						 return value of inventory.alter, since here are 2 storages involved)
		"""
        try:
            transfer_to = WorldObject.get_object_by_id(int(transfer_to))
        except TypeError:  # transfer_to not an int, assume already obj
            pass
        # take res from self
        ret = self.get_component(StorageComponent).inventory.alter(
            res_id, -amount)
        # check if we were able to get the planned amount
        ret = amount if amount < abs(ret) else abs(ret)
        # put res to transfer_to
        ret = transfer_to.get_component(StorageComponent).inventory.alter(
            res_id, amount - ret)
        self.get_component(StorageComponent).inventory.alter(
            res_id, ret)  # return resources that did not fit
        actually_transfered = amount - ret
        if signal_errors and actually_transfered == 0:
            AmbientSoundComponent.play_special('error')
        return actually_transfered
 def set_active(self, production=None, active=True):
     super(MineProducer, self).set_active(production, active)
     # check if the user set it to waiting_for_res (which doesn't do anything)
     if active and self._get_current_state(
     ) == PRODUCTION.STATES.waiting_for_res:
         super(MineProducer, self).set_active(production, active=False)
         AmbientSoundComponent.play_special('error')
    def __join_game(self, game=None):
        """Joins a multiplayer game. Displays lobby for that specific game"""
        if game is None:
            game = self.__get_selected_game()
            if game is None:
                return
        if game.get_uuid() == -1:  # -1 signals no game
            AmbientSoundComponent.play_special('error')
            return
        if game.get_version() != NetworkInterface().get_clientversion():
            self.show_popup(
                _("Wrong version"),
                #xgettext:python-format
                _("The game's version differs from your version. "
                  "Every player in a multiplayer game must use the same version. "
                  "This can be fixed by every player updating to the latest version. "
                  "Game version: {game_version} Your version: {own_version}"
                  ).format(game_version=game.get_version(),
                           own_version=NetworkInterface().get_clientversion()))
            return

        # actual join
        if game.password:
            self.__enter_password_dialog(game)

        else:
            self.__actual_join(game)
    def move_entry(self, entry, direction):
        """
		moves an entry up or down
		"""
        position = self.widgets.index(entry)
        if position == len(self.widgets) and direction is 'down' or \
           position == 0 and direction is 'up':
            AmbientSoundComponent.play_special('error')
            return

        if direction is 'up':
            new_pos = position - 1
        elif direction is 'down':
            new_pos = position + 1
        else:
            return

        vbox = self._gui.findChild(name="left_vbox")

        vbox.removeChildren(self.widgets)
        self.widgets.insert(new_pos, self.widgets.pop(position))
        self._route_cmd("move_waypoint", position, direction)
        vbox.addChildren(self.widgets)

        self._gui.adaptLayout()
        self._resource_selection_area_layout_hack_fix()
	def move_entry(self, entry, direction):
		"""
		moves an entry up or down
		"""
		position = self.widgets.index(entry)
		if position == len(self.widgets) and direction is 'down' or \
		   position == 0 and direction is 'up':
			AmbientSoundComponent.play_special('error')
			return

		if direction is 'up':
			new_pos = position - 1
		elif direction is 'down':
			new_pos = position + 1
		else:
			return

		vbox = self._gui.findChild(name="left_vbox")

		vbox.removeChildren(self.widgets)
		self.widgets.insert(new_pos, self.widgets.pop(position))
		self._route_cmd("move_waypoint", position, direction)
		vbox.addChildren(self.widgets)


		self._gui.adaptLayout()
		self._resource_selection_area_layout_hack_fix()
Exemple #6
0
	def on_chime(self):
		"""
		Called chime action. Displaying call for help on artists and game design,
		introduces information for SoC applicants (if valid).
		"""
		AmbientSoundComponent.play_special("message")
		self.show_dialog(self.widgets['call_for_support'], {OkButton.DEFAULT_NAME : True})
	def __join_game(self, game=None):
		"""Joins a multiplayer game. Displays lobby for that specific game"""
		if game is None:
			game = self.__get_selected_game()
			if game is None:
				return
		if game.get_uuid() == -1: # -1 signals no game
			AmbientSoundComponent.play_special('error')
			return
		if game.get_version() != NetworkInterface().get_clientversion():
			self.show_popup(_("Wrong version"),
			                   #xgettext:python-format
			                _("The game's version differs from your version. "
			                  "Every player in a multiplayer game must use the same version. "
			                  "This can be fixed by every player updating to the latest version. "
			                  "Game version: {game_version} Your version: {own_version}").format(
			                  game_version=game.get_version(),
			                  own_version=NetworkInterface().get_clientversion()))
			return

		# actual join
		if game.password:
			self.__enter_password_dialog(game)

		else:
			self.__actual_join(game)
Exemple #8
0
    def _add_message(self, message, sound=None):
        """Internal function for adding messages. Do not call directly.
		@param message: _IngameMessage instance
		@param sound: path to soundfile"""
        self.active_messages.insert(0, message)
        if len(self.active_messages) > self.MAX_MESSAGES:
            self.active_messages.remove(
                self.active_messages[self.MAX_MESSAGES])

        if sound:
            horizons.globals.fife.play_sound('speech', sound)
        else:
            # play default msg sound
            AmbientSoundComponent.play_special('message')

        if message.x != 0 and message.y != 0:
            self.session.ingame_gui.minimap.highlight((message.x, message.y))

        self.draw_widget()
        self.show_text(0)
        ExtScheduler().add_new_object(self.hide_text, self,
                                      self.SHOW_NEW_MESSAGE_TEXT)

        self.session.ingame_gui.logbook.display_message_history(
        )  # update message history on new message

        return message.created
Exemple #9
0
	def move_entry(self, entry, direction):
		"""
		moves an entry up or down
		"""
		# Abort (with error sound) if moving this entry is not possible.
		position = self.widgets.index(entry)
		if position == len(self.widgets) and direction == 'down' or \
		   position == 0 and direction == 'up':
			AmbientSoundComponent.play_special('error')
			return

		if direction == 'up':
			new_pos = position - 1
		elif direction == 'down':
			new_pos = position + 1
		else:
			assert False, 'Direction for `move_entry` is neither "up" nor "down".'

		vbox = self._gui.findChild(name="left_vbox")

		vbox.removeChildren(self.widgets)
		self.widgets.insert(new_pos, self.widgets.pop(position))
		self._route_cmd("move_waypoint", position, direction)
		vbox.addChildren(self.widgets)

		self._gui.adaptLayout()
		self._resource_selection_area_layout_hack_fix()
    def move_entry(self, entry, direction):
        """
		moves an entry up or down
		"""
        # Abort (with error sound) if moving this entry is not possible.
        position = self.widgets.index(entry)
        if position == len(self.widgets) and direction == 'down' or \
           position == 0 and direction == 'up':
            AmbientSoundComponent.play_special('error')
            return

        if direction == 'up':
            new_pos = position - 1
        elif direction == 'down':
            new_pos = position + 1
        else:
            assert False, 'Direction for `move_entry` is neither "up" nor "down".'

        vbox = self._gui.findChild(name="left_vbox")

        vbox.removeChildren(self.widgets)
        self.widgets.insert(new_pos, self.widgets.pop(position))
        self._route_cmd("move_waypoint", position, direction)
        vbox.addChildren(self.widgets)

        self._gui.adaptLayout()
        self._resource_selection_area_layout_hack_fix()
	def __call__(self, issuer):
		"""Execute the command
		@param issuer: the issuer of the command
		"""
		if self.position is None:
			AmbientSoundComponent.play_special(self.sound)
		else:
			AmbientSoundComponent.play_special(self.sound, Point(self.position[0], self.position[1]))
Exemple #12
0
	def __call__(self, issuer):
		"""Execute the command
		@param issuer: the issuer of the command
		"""
		if self.position is None:
			AmbientSoundComponent.play_special(self.sound)
		else:
			AmbientSoundComponent.play_special(self.sound, Point(self.position[0], self.position[1]))
Exemple #13
0
	def speed_down(self):
		if self.speed_is_paused():
			AmbientSoundComponent.play_special('error')
			return
		if self.timer.ticks_per_second in GAME_SPEED.TICK_RATES:
			i = GAME_SPEED.TICK_RATES.index(self.timer.ticks_per_second)
			if i > 0:
				self.speed_set(GAME_SPEED.TICK_RATES[i - 1])
		else:
			self.speed_set(GAME_SPEED.TICK_RATES[0])
Exemple #14
0
 def speed_down(self):
     if self.speed_is_paused():
         AmbientSoundComponent.play_special('error')
         return
     if self.timer.ticks_per_second in GAME_SPEED.TICK_RATES:
         i = GAME_SPEED.TICK_RATES.index(self.timer.ticks_per_second)
         if i > 0:
             self.speed_set(GAME_SPEED.TICK_RATES[i - 1])
     else:
         self.speed_set(GAME_SPEED.TICK_RATES[0])
Exemple #15
0
 def speed_up(self):
     if self.speed_is_paused():
         AmbientSoundComponent.play_special("error")
         return
     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 _scroll(self, direction):
		"""Scroll back or forth one message.
		@param direction: -1 or 1"""
		if not self._parameters:
			return
		new_cur = self._cur_entry + direction
		if new_cur < 0 or new_cur >= len(self._parameters):
			return # invalid scroll
		self._cur_entry = new_cur
		AmbientSoundComponent.play_special('flippage')
		self._redraw_captainslog()
Exemple #17
0
    def _scroll(self, direction):
        """Scroll back or forth one message.
		@param direction: -1 or 1"""
        if not self._parameters:
            return
        new_cur = self._cur_entry + direction
        if new_cur < 0 or new_cur >= len(self._parameters):
            return  # invalid scroll
        self._cur_entry = new_cur
        AmbientSoundComponent.play_special('flippage')
        self._redraw_captainslog()
Exemple #18
0
	def _make_configuration_default(self, reset=False):
		"""Saves current resources as default via game settings"""
		if reset:
			config = [] # meaning invalid
		else:
			config = json.dumps(self._get_current_resources())
		horizons.globals.fife.set_uh_setting("ResourceOverviewBarConfiguration", config)
		horizons.globals.fife.save_settings()
		self._update_default_configuration()
		AmbientSoundComponent.play_special("success")
		if reset: # in the other case, it's already set
			self.redraw()
Exemple #19
0
	def _update_settlement(self):
		city_name_label = self._child_finder('city_name')
		if self._settlement.owner.is_local_player: # allow name changes
			# Update settlement on the resource overview to make sure it
			# is setup correctly for the coming calculations
			self._ingame_gui.resource_overview.set_inventory_instance(self._settlement)
			cb = Callback(self._ingame_gui.show_change_name_dialog, self._settlement)
			helptext = _("Click to change the name of your settlement")
			city_name_label.enable_cursor_change_on_hover()
		else: # no name changes
			cb = lambda: AmbientSoundComponent.play_special('error')
			helptext = u""
			city_name_label.disable_cursor_change_on_hover()

		self._widget.mapEvents({
			'city_name': cb
		})
		city_name_label.helptext = helptext

		foundlabel = self._child_finder('owner_emblem')
		foundlabel.image = 'content/gui/images/tabwidget/emblems/emblem_%s.png' % (self._settlement.owner.color.name)
		foundlabel.helptext = self._settlement.owner.name

		foundlabel = self._child_finder('city_name')
		foundlabel.text = self._settlement.get_component(SettlementNameComponent).name
		foundlabel.resizeToContent()

		foundlabel = self._child_finder('city_inhabitants')
		foundlabel.text = u' {amount:>4d}'.format(amount=self._settlement.inhabitants)
		foundlabel.resizeToContent()

		self._update_position()
Exemple #20
0
    def update_settlement(self):
        city_name_label = self.cityinfo.child_finder('city_name')
        if self.settlement.owner.is_local_player:  # allow name changes
            # Update settlement on the resource overview to make sure it
            # is setup correctly for the coming calculations
            self.resource_overview.set_inventory_instance(self.settlement)
            cb = Callback(self.show_change_name_dialog, self.settlement)
            helptext = _("Click to change the name of your settlement")
            city_name_label.enable_cursor_change_on_hover()
        else:  # no name changes
            cb = lambda: AmbientSoundComponent.play_special('error')
            helptext = u""
            city_name_label.disable_cursor_change_on_hover()
        self.cityinfo.mapEvents({'city_name': cb})
        city_name_label.helptext = helptext

        foundlabel = self.cityinfo.child_finder('owner_emblem')
        foundlabel.image = 'content/gui/images/tabwidget/emblems/emblem_%s.png' % (
            self.settlement.owner.color.name)
        foundlabel.helptext = self.settlement.owner.name

        foundlabel = self.cityinfo.child_finder('city_name')
        foundlabel.text = self.settlement.get_component(
            SettlementNameComponent).name
        foundlabel.resizeToContent()

        foundlabel = self.cityinfo.child_finder('city_inhabitants')
        foundlabel.text = u' {amount:>4d}'.format(
            amount=self.settlement.inhabitants)
        foundlabel.resizeToContent()

        self._update_cityinfo_position()
 def mousePressed(self, evt):
     if evt.getButton() == fife.MouseEvent.LEFT:
         obj = self._get_object(evt)
         if obj and self._is_buildable(obj.id):
             self.session.set_cursor('building', Entities.buildings[obj.id])
         elif obj:  # object that is not buildable
             AmbientSoundComponent.play_special('error')
             self.on_escape()
         else:
             self.on_escape()
         evt.consume()
     elif evt.getButton() == fife.MouseEvent.RIGHT:
         self.on_escape()
         evt.consume()
     else:
         super(PipetteTool, self).mouseClicked(evt)
	def mousePressed(self, evt):
		if evt.getButton() == fife.MouseEvent.LEFT:
			obj = self._get_object(evt)
			if obj and self._is_buildable(obj.id):
				self.session.ingame_gui.set_cursor('building', Entities.buildings[obj.id])
			elif obj: # object that is not buildable
				AmbientSoundComponent.play_special('error')
				self.on_escape()
			else:
				self.on_escape()
			evt.consume()
		elif evt.getButton() == fife.MouseEvent.RIGHT:
			self.on_escape()
			evt.consume()
		else:
			super(PipetteTool, self).mouseClicked(evt)
Exemple #23
0
	def update_settlement(self):
		cityinfo = self.widgets['city_info']
		city_name_label = cityinfo.findChild(name="city_name")
		if self.settlement.owner.is_local_player: # allow name changes
			cb = Callback(self.show_change_name_dialog, self.settlement)
			helptext = _("Click to change the name of your settlement")
			city_name_label.enable_cursor_change_on_hover()
		else: # no name changes
			cb = lambda : AmbientSoundComponent.play_special('error')
			helptext = u""
			city_name_label.disable_cursor_change_on_hover()
		cityinfo.mapEvents({
			'city_name': cb
		})
		city_name_label.helptext = helptext

		foundlabel = cityinfo.child_finder('owner_emblem')
		foundlabel.image = 'content/gui/images/tabwidget/emblems/emblem_%s.png' % (self.settlement.owner.color.name)
		foundlabel.helptext = self.settlement.owner.name

		foundlabel = cityinfo.child_finder('city_name')
		foundlabel.text = self.settlement.get_component(SettlementNameComponent).name
		foundlabel.resizeToContent()

		foundlabel = cityinfo.child_finder('city_inhabitants')
		foundlabel.text = u' %s' % (self.settlement.inhabitants)
		foundlabel.resizeToContent()

		cityinfo.adaptLayout()
	def append_warehouse(self, warehouse):
		"""Add a warehouse to the list on the left side.
		@param warehouse: Set to add a specific one, else the selected one gets added.
		"""
		if len(self.widgets) >= self.MAX_ENTRIES:
			# reached max entries the gui can hold
			AmbientSoundComponent.play_special('error')
			return

		self._route_cmd("append", warehouse.worldid)
		self.add_gui_entry(warehouse)
		if self.resource_menu_shown:
			self.hide_resource_menu()

		self._check_no_entries_label()

		self._gui.adaptLayout()
	def __refresh(self, play_sound=False):
		"""Refresh list of games.
		Only possible in multiplayer main menu state.
		@param play_sound: whether to play the refresh sound
		@return bool, whether refresh worked"""
		if play_sound:
			AmbientSoundComponent.play_special('refresh')
		only_this_version_allowed = self.current.findChild(name='showonlyownversion').marked
		self.games = NetworkInterface().get_active_games(only_this_version_allowed)
		if self.games is None:
			return False

		gamelist = [self._display_game_name(g) for g in self.games]
		self.current.distributeInitialData({'gamelist': gamelist})
		self.current.distributeData({'gamelist': 0}) # select first map
		self.__update_game_details()
		return True
	def _join_game(self):
		"""Joins a multiplayer game. Displays lobby for that specific game"""
		try:
			index = self._gui.collectData('gamelist')
			game = self._games[index]
		except IndexError:
			return

		if game.uuid == -1: # -1 signals no game
			AmbientSoundComponent.play_special('error')
			return

		if game.version != NetworkInterface().get_clientversion():
			self._windows.show_popup(_("Wrong version"),
			                          #xgettext:python-format
			                          _("The game's version differs from your version. "
			                            "Every player in a multiplayer game must use the same version. "
			                            "This can be fixed by every player updating to the latest version. "
			                            "Game version: {game_version} Your version: {own_version}").format(
			                            game_version=game.version,
			                            own_version=NetworkInterface().get_clientversion()))
			return

		NetworkInterface().change_name(self._playerdata.get_player_name())
		NetworkInterface().change_color(self._playerdata.get_player_color().id)

		password = ""
		if game.password:
			# Repeatedly ask the player for the password
			success = False
			while not success:
				password = self._request_game_password(game)
				if password is None:
					break
				password = hashlib.sha1(password).hexdigest()
				success = NetworkInterface().joingame(game.uuid, password)

			if not success:
				return
		else:
			if not NetworkInterface().joingame(game.uuid, password):
				return

		window = GameLobby(self._windows)
		self._windows.show(window)
    def _refresh(self, play_sound=False):
        """Refresh list of games.

		@param play_sound: whether to play the refresh sound
		@return bool, whether refresh worked
		"""
        if play_sound:
            AmbientSoundComponent.play_special('refresh')

        self._games = NetworkInterface().get_active_games()
        if self._games is None:
            return False

        gamelist = [self._display_game_name(g) for g in self._games]
        self._gui.distributeInitialData({'gamelist': gamelist})
        self._gui.distributeData({'gamelist': 0})
        self._update_game_details()
        return True
	def _refresh(self, play_sound=False):
		"""Refresh list of games.

		@param play_sound: whether to play the refresh sound
		@return bool, whether refresh worked
		"""
		if play_sound:
			AmbientSoundComponent.play_special('refresh')

		self._games = NetworkInterface().get_active_games()
		if self._games is None:
			return False

		gamelist = [self._display_game_name(g) for g in self._games]
		self._gui.distributeInitialData({'gamelist': gamelist})
		self._gui.distributeData({'gamelist': 0})
		self._update_game_details()
		return True
    def __refresh(self, play_sound=False):
        """Refresh list of games.
		Only possible in multiplayer main menu state.
		@param play_sound: whether to play the refresh sound
		@return bool, whether refresh worked"""
        if play_sound:
            AmbientSoundComponent.play_special('refresh')
        only_this_version_allowed = self.current.findChild(
            name='showonlyownversion').marked
        self.games = NetworkInterface().get_active_games(
            only_this_version_allowed)
        if self.games is None:
            return False

        gamelist = [self._display_game_name(g) for g in self.games]
        self.current.distributeInitialData({'gamelist': gamelist})
        self.current.distributeData({'gamelist': 0})  # select first map
        self.__update_game_details()
        return True
    def _join_game(self):
        """Joins a multiplayer game. Displays lobby for that specific game"""
        try:
            index = self._gui.collectData('gamelist')
            game = self._games[index]
        except IndexError:
            return

        if game.uuid == -1:  # -1 signals no game
            AmbientSoundComponent.play_special('error')
            return

        if game.version != NetworkInterface().get_clientversion():
            self._windows.open_popup(
                T("Wrong version"),
                T("The game's version differs from your version. "
                  "Every player in a multiplayer game must use the same version. "
                  "This can be fixed by every player updating to the latest version. "
                  "Game version: {game_version} Your version: {own_version}").
                format(game_version=game.version,
                       own_version=NetworkInterface().get_clientversion()))
            return

        NetworkInterface().change_name(self._playerdata.get_player_name())
        NetworkInterface().change_color(self._playerdata.get_player_color().id)

        if game.password:
            # ask the player for the password
            popup = PasswordInput(self._windows)
            password = self._windows.open(popup)
            if password is None:
                return
            password = hashlib.sha1(
                password.encode(encoding='utf-8')).hexdigest()
            success = NetworkInterface().joingame(game.uuid, password)
            if not success:
                return
        elif not NetworkInterface().joingame(game.uuid, ''):
            return

        window = GameLobby(self._windows)
        self._windows.open(window)
	def _add_message(self, message, sound=None):
		"""Internal function for adding messages. Do not call directly.
		@param message: Message instance
		@param sound: path to soundfile"""
		self.active_messages.insert(0, message)
		if len(self.active_messages) > self.MAX_MESSAGES:
			self.active_messages.remove(self.active_messages[self.MAX_MESSAGES])

		if sound:
			horizons.main.fife.play_sound('speech', sound)
		else:
			# play default msg sound
			AmbientSoundComponent.play_special('message')

		if message.x is not None and message.y is not None:
			self.session.ingame_gui.minimap.highlight( (message.x, message.y) )

		self.draw_widget()
		self.show_text(0)
		ExtScheduler().add_new_object(self.hide_text, self, self.SHOW_NEW_MESSAGE_TEXT)
Exemple #32
0
	def append_warehouse(self, warehouse):
		"""Add a warehouse to the list on the left side.
		@param warehouse: Set to add a specific one, else the selected one gets added.
		"""
		if not self.session.world.diplomacy.can_trade(self.session.world.player, warehouse.owner):
			self.session.ingame_gui.message_widget.add_custom(T("You are not allowed to trade with this player"))
			return

		if len(self.widgets) >= self.MAX_ENTRIES:
			# reached max entries the gui can hold
			AmbientSoundComponent.play_special('error')
			return

		self._route_cmd("append", warehouse.worldid)
		self.add_gui_entry(warehouse)
		if self.resource_menu_shown:
			self.hide_resource_menu()

		self._check_no_entries_label()

		self._gui.adaptLayout()
	def append_warehouse(self, warehouse):
		"""Add a warehouse to the list on the left side.
		@param warehouse: Set to add a specific one, else the selected one gets added.
		"""
		if not self.session.world.diplomacy.can_trade(self.session.world.player, warehouse.owner):
			self.session.ingame_gui.message_widget.add_custom(T("You are not allowed to trade with this player"))
			return

		if len(self.widgets) >= self.MAX_ENTRIES:
			# reached max entries the gui can hold
			AmbientSoundComponent.play_special('error')
			return

		self._route_cmd("append", warehouse.worldid)
		self.add_gui_entry(warehouse)
		if self.resource_menu_shown:
			self.hide_resource_menu()

		self._check_no_entries_label()

		self._gui.adaptLayout()
	def _join_game(self):
		"""Joins a multiplayer game. Displays lobby for that specific game"""
		try:
			index = self._gui.collectData('gamelist')
			game = self._games[index]
		except IndexError:
			return

		if game.uuid == -1: # -1 signals no game
			AmbientSoundComponent.play_special('error')
			return

		if game.version != NetworkInterface().get_clientversion():
			self._windows.open_popup(T("Wrong version"),
			                          T("The game's version differs from your version. "
			                            "Every player in a multiplayer game must use the same version. "
			                            "This can be fixed by every player updating to the latest version. "
			                            "Game version: {game_version} Your version: {own_version}").format(
			                            game_version=game.version,
			                            own_version=NetworkInterface().get_clientversion()))
			return

		NetworkInterface().change_name(self._playerdata.get_player_name())
		NetworkInterface().change_color(self._playerdata.get_player_color().id)

		if game.password:
			# ask the player for the password
			popup = PasswordInput(self._windows)
			password = self._windows.open(popup)
			if password is None:
				return
			password = hashlib.sha1(password.encode(encoding='utf-8')).hexdigest()
			success = NetworkInterface().joingame(game.uuid, password)
			if not success:
				return
		elif not NetworkInterface().joingame(game.uuid, ''):
			return

		window = GameLobby(self._windows)
		self._windows.open(window)
	def transfer_to_storageholder(self, amount, res_id, transfer_to, signal_errors=False):
		"""Transfers amount of res_id to transfer_to.
		@param transfer_to: worldid or object reference
		@param signal_errors: whether to play an error sound in case the transfer completely failed (no res transferred)
		@return: amount that was actually transferred (NOTE: this is different from the
						 return value of inventory.alter, since here are 2 storages involved)
		"""
		try:
			transfer_to = WorldObject.get_object_by_id(int(transfer_to))
		except TypeError: # transfer_to not an int, assume already obj
			pass
		# take res from self
		ret = self.get_component(StorageComponent).inventory.alter(res_id, -amount)
		# check if we were able to get the planned amount
		ret = amount if amount < abs(ret) else abs(ret)
		# put res to transfer_to
		ret = transfer_to.get_component(StorageComponent).inventory.alter(res_id, amount - ret)
		self.get_component(StorageComponent).inventory.alter(res_id, ret) # return resources that did not fit
		actually_transfered = amount - ret
		if signal_errors and actually_transfered == 0:
			AmbientSoundComponent.play_special('error')
		return actually_transfered
	def __refresh(self, play_sound=False):
		"""Refresh list of games.
		Only possible in multiplayer main menu state.
		@param play_sound: whether to play the refresh sound
		@return bool, whether refresh worked"""
		if play_sound:
			AmbientSoundComponent.play_special('refresh')
		self.games = NetworkInterface().get_active_games(self.current.findChild(name='showonlyownversion').marked)
		if self.games is None:
			return False

		self.current.distributeInitialData(
		  {'gamelist' : map(lambda x: u"{gamename}: {name} ({players}, {limit}){version}".format(
		                        name=x.get_map_name(),
		                        gamename=x.get_name(),
		                        players=x.get_player_count(),
		                        limit=x.get_player_limit(),
		                        version=u" " + _("Version differs!") if x.get_version() != NetworkInterface().get_clientversion() else u""),
		                    self.games)})
		self.current.distributeData({'gamelist' : 0}) # select first map
		self.__update_game_details()
		return True
	def __join_game(self, game = None):
		"""Joins a multiplayer game. Displays lobby for that specific game"""
		if game == None:
			game = self.__get_selected_game()
		if game.load is not None and SavegameAccessor.get_hash(SavegameManager.get_multiplayersave_map(game.mapname)) != game.load:
			self.show_popup(_("Error"), self.current.findChild(name="save_missing_help_button").btn_text, size=1)
			return
		if game.get_uuid() == -1: # -1 signals no game
			AmbientSoundComponent.play_special('error')
			return
		if game.get_version() != NetworkInterface().get_clientversion():
			self.show_popup(_("Wrong version"),
			                   #xgettext:python-format
			                _("The game's version differs from your version. Every player in a multiplayer game must use the same version. This can be fixed by every player updating to the latest version. Game version: {game_version} Your version: {own_version}").format(
			                  game_version=game.get_version(),
			                  own_version=NetworkInterface().get_clientversion()))
			return
		# actual join
		join_worked = NetworkInterface().joingame(game.get_uuid())
		if not join_worked:
			return
		self.__apply_new_nickname()
		self.__show_gamelobby()
    def _add_message(self, message, sound=None):
        """Internal function for adding messages. Do not call directly.
		@param message: _IngameMessage instance
		@param sound: path to soundfile"""
        self.active_messages.insert(0, message)
        if len(self.active_messages) > self.MAX_MESSAGES:
            self.active_messages.remove(self.active_messages[self.MAX_MESSAGES])

        if sound:
            horizons.globals.fife.play_sound("speech", sound)
        else:
            # play default msg sound
            AmbientSoundComponent.play_special("message")

        if message.x is not None and message.y is not None:
            self.session.ingame_gui.minimap.highlight((message.x, message.y))

        self.draw_widget()
        self.show_text(0)
        ExtScheduler().add_new_object(self.hide_text, self, self.SHOW_NEW_MESSAGE_TEXT)

        self.session.ingame_gui.logbook.display_message_history()  # update message history on new message

        return message.created
Exemple #39
0
	def _on_gui_action(self, msg):
		AmbientSoundComponent.play_special('click')
Exemple #40
0
	def set_active(self, production=None, active=True):
		super(MineProducer, self).set_active(production, active)
		# check if the user set it to waiting_for_res (which doesn't do anything)
		if active and self._get_current_state() == PRODUCTION.STATES.waiting_for_res:
			super(MineProducer, self).set_active(production, active=False)
			AmbientSoundComponent.play_special('error')
 def _on_gui_hover_action(self, msg):
     """Make a sound when the mouse hovers over a button"""
     AmbientSoundComponent.play_special('refresh', position=None, gain=1)
 def _on_gui_cancel_action(self, msg):
     """Make a sound when a cancelButton is clicked"""
     AmbientSoundComponent.play_special('success', gain=10)
 def _on_gui_click_action(self, msg):
     """Make a sound when a button is clicked"""
     AmbientSoundComponent.play_special('click', gain=10)
	def _on_gui_cancel_action(self, msg):
		"""Make a sound when a cancelButton is clicked"""
		AmbientSoundComponent.play_special('success', gain=10)
Exemple #45
0
	def _on_gui_action(self, msg):
		AmbientSoundComponent.play_special('click')
	def _on_gui_click_action(self, msg):
		"""Make a sound when a button is clicked"""
		AmbientSoundComponent.play_special('click', gain=10)
	def _on_gui_hover_action(self, msg):
		"""Make a sound when the mouse hovers over a button"""
		AmbientSoundComponent.play_special('refresh', position=None, gain=1)