Example #1
0
    def add(self,
            string_id,
            point=None,
            msg_type=None,
            message_dict=None,
            play_sound=True,
            check_duplicate=False):
        """Adds a message to the MessageWidget.
		@param point: point where the action took place. Clicks on the message will then focus that spot.
		@param id: message id string, needed to retrieve the message text from the content database.
		@param msg_type: message type; determines what happens on click
		@param message_dict: dict with strings to replace in the message, e.g. {'player': 'Arthus'}
		@param play_sound: whether to play the default message speech for string_id
		@param check_duplicate: check for pseudo-duplicates (similar messages recently nearby)
		"""
        if check_duplicate:
            if string_id in self._last_message:
                when, where = self._last_message[string_id]
                if when > Scheduler().cur_tick - Scheduler().get_ticks(self.__class__._DUPLICATE_TIME_THRESHOLD) and \
                   where.distance(point) < self.__class__._DUPLICATE_SPACE_THRESHOLD:
                    # there has been a message nearby recently, abort
                    return
            self._last_message[string_id] = (Scheduler().cur_tick, point)

        sound = get_speech_file(string_id) if play_sound else None
        return self._add_message(_IngameMessage(point=point,
                                                id=string_id,
                                                msg_type=msg_type,
                                                created=next(self.msgcount),
                                                message_dict=message_dict),
                                 sound=sound)
	def add(self, string_id, x=None, y=None, msg_type=None, message_dict=None, sound_file=True, check_duplicate=False):
		"""Adds a message to the MessageWidget.
		@param x, y: int coordinates where the action took place. Clicks on the message will then focus that spot.
		@param id: message id string, needed to retrieve the message text from the content database.
		@param type: message type; determines what happens on click
		@param message_dict: dict with strings to replace in the message, e.g. {'player': 'Arthus'}
		@param sound_file: if True: play default message speech for string_id
		                   if False: do not play sound
		                   if sound file path: play this sound file
		@param check_duplicate: check for pseudo-duplicates (similar messages recently nearby)
		"""
		if check_duplicate:
			if string_id in self._last_message:
				when, where = self._last_message[string_id]
				if when > Scheduler().cur_tick - Scheduler().get_ticks(self.__class__._DUPLICATE_TIME_THRESHOLD) and \
				   where.distance( (x, y) ) < self.__class__._DUPLICATE_SPACE_THRESHOLD:
					# there has been a message nearby recently, abort
					return
			self._last_message[string_id] = (Scheduler().cur_tick, Point(x, y))

		sound = {
							True: get_speech_file(string_id),
							False: None
							}.get(sound_file, sound_file)
		return self._add_message(Message(x, y, string_id, msg_type=msg_type, created=self.msgcount.next(), message_dict=message_dict), sound)
    def add(self, string_id, point=None, msg_type=None, message_dict=None, play_sound=True, check_duplicate=False):
        """Adds a message to the MessageWidget.
		@param point: point where the action took place. Clicks on the message will then focus that spot.
		@param id: message id string, needed to retrieve the message text from the content database.
		@param msg_type: message type; determines what happens on click
		@param message_dict: dict with strings to replace in the message, e.g. {'player': 'Arthus'}
		@param play_sound: whether to play the default message speech for string_id
		@param check_duplicate: check for pseudo-duplicates (similar messages recently nearby)
		"""
        if check_duplicate:
            if string_id in self._last_message:
                when, where = self._last_message[string_id]
                if (
                    when > Scheduler().cur_tick - Scheduler().get_ticks(self.__class__._DUPLICATE_TIME_THRESHOLD)
                    and where.distance(point) < self.__class__._DUPLICATE_SPACE_THRESHOLD
                ):
                    # there has been a message nearby recently, abort
                    return
            self._last_message[string_id] = (Scheduler().cur_tick, point)

        sound = get_speech_file(string_id) if play_sound else None
        return self._add_message(
            _IngameMessage(
                point=point, id=string_id, msg_type=msg_type, created=self.msgcount.next(), message_dict=message_dict
            ),
            sound=sound,
        )
    def add(self, x, y, string_id, message_dict=None, sound_file=True):
        """Adds a message to the MessageWidget.
		@param x, y: int coordinates where the action took place.
		@param id: message id string, needed to retrieve the message from the database.
		@param message_dict: template dict with the neccassary values. ( e.g.: {'player': 'Arthus'}
		@params sound_file if not set play default message speech for string_id
						if set for False do not play sound
						if set sound file path play this sound, for example some event sound
		"""
        sound = {True: get_speech_file(string_id), False: None}.get(sound_file, sound_file)
        self._add_message(Message(x, y, string_id, self.current_tick, message_dict=message_dict), sound)