Add 'mood' option for displayMessage
This commit is contained in:
parent
cfa3579631
commit
6d11774493
@ -14,6 +14,10 @@ local CHAT_MODE_SUBTITLE = "Subtitle"
|
||||
local CHAT_MODE_SCROLLING = "Scrolling"
|
||||
local last_chat_time = 0
|
||||
local USE_ALPHA_ROWS_FOR_CHAT = True
|
||||
local MOOD_NEUTRAL = 0
|
||||
local MOOD_BAD = 1
|
||||
local MOOD_GOOD = 2
|
||||
|
||||
|
||||
local chat_log = {}
|
||||
|
||||
@ -35,14 +39,15 @@ end
|
||||
|
||||
local secondary_osd = ""
|
||||
local last_secondary_osd_time = nil
|
||||
local secondary_osd_mood = MOOD_NEUTRAL
|
||||
|
||||
function set_secondary_osd(osd_message)
|
||||
function set_secondary_osd(osd_message, mood)
|
||||
secondary_osd = osd_message
|
||||
last_secondary_osd_time = mp.get_time()
|
||||
secondary_osd_mood = mood
|
||||
end
|
||||
|
||||
|
||||
function add_chat(chat_message)
|
||||
function add_chat(chat_message, mood)
|
||||
last_chat_time = mp.get_time()
|
||||
local entry = #chat_log+1
|
||||
for i = 1, #chat_log do
|
||||
@ -75,7 +80,15 @@ function chat_update()
|
||||
local xpos = opts['chatLeftMargin']
|
||||
local ypos = opts['chatTopMargin']+(0*opts['chatOutputFontSize'])
|
||||
local messageString = '('..secondary_osd..')'
|
||||
messageString = '{\\1c&H0000FF}'..messageString
|
||||
local messageColour
|
||||
if secondary_osd_mood == MOOD_NEUTRAL then
|
||||
messageColour = "{\\1c&HFFFFFF}"
|
||||
elseif secondary_osd_mood == MOOD_BAD then
|
||||
messageColour = "{\\1c&H0000FF}"
|
||||
elseif secondary_osd_mood == MOOD_GOOD then
|
||||
messageColour = "{\\1c&H00FF00}"
|
||||
end
|
||||
messageString = messageColour..messageString
|
||||
chat_ass = format_chatroom(xpos,ypos,messageString)
|
||||
end
|
||||
end
|
||||
@ -159,12 +172,28 @@ mp.register_script_message('chat', function(e)
|
||||
add_chat(e)
|
||||
end)
|
||||
|
||||
mp.register_script_message('primary-osd', function(e)
|
||||
add_chat(e)
|
||||
mp.register_script_message('primary-osd-neutral', function(e)
|
||||
add_chat(e,MOOD_NEUTRAL)
|
||||
end)
|
||||
|
||||
mp.register_script_message('secondary-osd', function(e)
|
||||
set_secondary_osd(e)
|
||||
mp.register_script_message('primary-osd-bad', function(e)
|
||||
add_chat(e,MOOD_BAD)
|
||||
end)
|
||||
|
||||
mp.register_script_message('primary-osd-good', function(e)
|
||||
add_chat(e,MOOD_GOOD)
|
||||
end)
|
||||
|
||||
mp.register_script_message('secondary-osd-neutral', function(e)
|
||||
set_secondary_osd(e,MOOD_NEUTRAL)
|
||||
end)
|
||||
|
||||
mp.register_script_message('secondary-osd-bad', function(e)
|
||||
set_secondary_osd(e,MOOD_BAD)
|
||||
end)
|
||||
|
||||
mp.register_script_message('secondary-osd-good', function(e)
|
||||
set_secondary_osd(e,MOOD_GOOD)
|
||||
end)
|
||||
|
||||
mp.register_script_message('set_syncplayintf_options', function(e)
|
||||
|
||||
@ -790,7 +790,7 @@ class SyncplayClient(object):
|
||||
allReadyMessage = getMessage("all-users-ready").format(self.userlist.readyUserCount())
|
||||
autoplayingMessage = getMessage("autoplaying-notification").format(int(self.autoplayTimeLeft))
|
||||
countdownMessage = u"{}{}{}".format(allReadyMessage,self._player.osdMessageSeparator, autoplayingMessage)
|
||||
self.ui.showOSDMessage(countdownMessage, 1, secondaryOSD=True)
|
||||
self.ui.showOSDMessage(countdownMessage, 1, secondaryOSD=True, mood=constants.MESSAGE_GOODNEWS)
|
||||
if self.autoplayTimeLeft <= 0:
|
||||
self.setPaused(False)
|
||||
self.stopAutoplayCountdown()
|
||||
@ -939,7 +939,7 @@ class SyncplayClient(object):
|
||||
|
||||
def _checkIfYouReAloneInTheRoom(self, OSDOnly):
|
||||
if self._userlist.areYouAloneInRoom():
|
||||
self._ui.showOSDMessage(getMessage("alone-in-the-room"), constants.WARNING_OSD_MESSAGES_LOOP_INTERVAL, secondaryOSD=True)
|
||||
self._ui.showOSDMessage(getMessage("alone-in-the-room"), constants.WARNING_OSD_MESSAGES_LOOP_INTERVAL, secondaryOSD=True, mood=constants.MESSAGE_BADNEWS)
|
||||
if not OSDOnly:
|
||||
self._ui.showMessage(getMessage("alone-in-the-room"), True)
|
||||
if constants.SHOW_OSD_WARNINGS and not self._warnings["alone-in-the-room"]['timer'].running:
|
||||
@ -969,8 +969,10 @@ class SyncplayClient(object):
|
||||
if not self._client._player or self._client.autoplayTimerIsRunning():
|
||||
return
|
||||
osdMessage = None
|
||||
messageMood = constants.MESSAGE_GOODNEWS
|
||||
fileDifferencesForRoom = self._userlist.getFileDifferencesForRoom()
|
||||
if not self._userlist.areAllFilesInRoomSame() and fileDifferencesForRoom is not None:
|
||||
messageMood = constants.MESSAGE_BADNEWS
|
||||
fileDifferencesMessage = getMessage("room-file-differences").format(fileDifferencesForRoom)
|
||||
if self._userlist.currentUser.canControl() and self._userlist.isReadinessSupported():
|
||||
if self._userlist.areAllUsersInRoomReady():
|
||||
@ -985,9 +987,10 @@ class SyncplayClient(object):
|
||||
if self._userlist.areAllUsersInRoomReady():
|
||||
osdMessage = getMessage("all-users-ready").format(self._userlist.readyUserCount())
|
||||
else:
|
||||
messageMood = constants.MESSAGE_BADNEWS
|
||||
osdMessage = getMessage("not-all-ready").format(self._userlist.usersInRoomNotReady())
|
||||
if osdMessage:
|
||||
self._ui.showOSDMessage(osdMessage, constants.WARNING_OSD_MESSAGES_LOOP_INTERVAL, secondaryOSD=True)
|
||||
self._ui.showOSDMessage(osdMessage, constants.WARNING_OSD_MESSAGES_LOOP_INTERVAL, secondaryOSD=True, mood=messageMood)
|
||||
|
||||
def __displayMessageOnOSD(self, warningName, warningFunction):
|
||||
if constants.OSD_WARNING_MESSAGE_DURATION > self._warnings[warningName]["displayedFor"]:
|
||||
@ -1388,8 +1391,8 @@ class UiManager(object):
|
||||
self.showOSDMessage(messageString, duration=constants.OSD_DURATION)
|
||||
self.__ui.showMessage(messageString)
|
||||
|
||||
def showMessage(self, message, noPlayer=False, noTimestamp=False, secondaryOSD=False):
|
||||
if not noPlayer: self.showOSDMessage(message, duration=constants.OSD_DURATION, secondaryOSD=secondaryOSD)
|
||||
def showMessage(self, message, noPlayer=False, noTimestamp=False, secondaryOSD=False,mood=constants.MESSAGE_NEUTRAL):
|
||||
if not noPlayer: self.showOSDMessage(message, duration=constants.OSD_DURATION, secondaryOSD=secondaryOSD, mood=mood)
|
||||
self.__ui.showMessage(message, noTimestamp)
|
||||
|
||||
def updateAutoPlayState(self, newState):
|
||||
@ -1398,7 +1401,7 @@ class UiManager(object):
|
||||
def showUserList(self, currentUser, rooms):
|
||||
self.__ui.showUserList(currentUser, rooms)
|
||||
|
||||
def showOSDMessage(self, message, duration=constants.OSD_DURATION, secondaryOSD=False):
|
||||
def showOSDMessage(self, message, duration=constants.OSD_DURATION, secondaryOSD=False, mood=constants.MESSAGE_NEUTRAL):
|
||||
autoplayConditionsMet = self._client.autoplayConditionsMet()
|
||||
if secondaryOSD and not constants.SHOW_OSD_WARNINGS and not self._client.autoplayTimerIsRunning():
|
||||
return
|
||||
@ -1419,7 +1422,7 @@ class UiManager(object):
|
||||
self.lastPrimaryOSDEndTime = time.time() + constants.OSD_DURATION
|
||||
if self.lastSecondaryOSDEndTime and time.time() < self.lastSecondaryOSDEndTime:
|
||||
message = u"{}{}{}".format(self.lastSecondaryOSDMessage, self._client._player.osdMessageSeparator, message)
|
||||
self._client._player.displayMessage(message, int(duration * 1000), secondaryOSD)
|
||||
self._client._player.displayMessage(message, int(duration * 1000), secondaryOSD, mood)
|
||||
|
||||
def setControllerStatus(self, username, isController):
|
||||
self.__ui.setControllerStatus(username, isController)
|
||||
|
||||
@ -216,6 +216,11 @@ FILEITEM_SWITCH_FILE_SWITCH = 1
|
||||
FILEITEM_SWITCH_STREAM_SWITCH = 2
|
||||
PLAYLISTITEM_CURRENTLYPLAYING_ROLE = 3
|
||||
|
||||
MESSAGE_NEUTRAL = 0
|
||||
MESSAGE_BADNEWS = 1
|
||||
MESSAGE_GOODNEWS = 2
|
||||
MOOD_LIST = ["neutral","bad","good"]
|
||||
|
||||
SYNCPLAY_UPDATE_URL = u"http://syncplay.pl/checkforupdate?{}" # Params
|
||||
SYNCPLAY_DOWNLOAD_URL = "http://syncplay.pl/download/"
|
||||
SYNCPLAY_PUBLIC_SERVER_LIST_URL = u"http://syncplay.pl/listpublicservers?{}" # Params
|
||||
|
||||
@ -12,7 +12,7 @@ class BasePlayer(object):
|
||||
'''
|
||||
Display given message on player's OSD or similar means
|
||||
'''
|
||||
def displayMessage(self, message, duration = (constants.OSD_DURATION*1000)):
|
||||
def displayMessage(self, message, duration = (constants.OSD_DURATION*1000), secondaryOSD=False, mood=constants.MESSAGE_NEUTRAL):
|
||||
raise NotImplementedError()
|
||||
|
||||
'''
|
||||
|
||||
@ -396,7 +396,7 @@ class MPCHCAPIPlayer(BasePlayer):
|
||||
def openFile(self, filePath, resetPosition=False):
|
||||
self._mpcApi.openFile(filePath)
|
||||
|
||||
def displayMessage(self, message, duration = (constants.OSD_DURATION*1000), secondaryOSD=False):
|
||||
def displayMessage(self, message, duration = (constants.OSD_DURATION*1000), secondaryOSD=False, mood=constants.MESSAGE_NEUTRAL):
|
||||
self._mpcApi.sendOsd(message, constants.MPC_OSD_POSITION, duration)
|
||||
|
||||
@retry(MpcHcApi.PlayerNotReadyException, constants.MPC_MAX_RETRIES, constants.MPC_RETRY_WAIT_TIME, 1)
|
||||
|
||||
@ -89,16 +89,18 @@ class MplayerPlayer(BasePlayer):
|
||||
def _getProperty(self, property_):
|
||||
self._listener.sendLine("get_property {}".format(property_))
|
||||
|
||||
def displayMessage(self, message, duration=(constants.OSD_DURATION * 1000), secondaryOSD=False):
|
||||
def displayMessage(self, message, duration=(constants.OSD_DURATION * 1000), secondaryOSD=False, mood=constants.MESSAGE_NEUTRAL):
|
||||
moodString = constants.MOOD_LIST[mood]
|
||||
|
||||
if not secondaryOSD and self._client.chatIsEnabled(): # TODO: Add check to ensure it is in 'chatroom' mode
|
||||
max_message_length = 3+constants.MAX_USERNAME_LENGTH+constants.MAX_CHAT_MESSAGE_LENGTH
|
||||
messageStrings = utils.splitText(message,max_message_length)
|
||||
for messageString in messageStrings:
|
||||
self._listener.sendLine(u'script-message-to syncplayintf primary-osd "{}"'.format(messageString))
|
||||
self._listener.sendLine(u'script-message-to syncplayintf primary-osd-{} "{}"'.format(moodString,messageString))
|
||||
return
|
||||
if secondaryOSD:
|
||||
messageString = self._sanitizeText(message.replace("\\n", "<NEWLINE>")).replace("<NEWLINE>", "\\n")
|
||||
self._listener.sendLine(u'script-message-to syncplayintf secondary-osd "{}"'.format(messageString))
|
||||
self._listener.sendLine(u'script-message-to syncplayintf secondary-osd-{} "{}"'.format(moodString,messageString))
|
||||
message = self._sanitizeText(message.replace("\\n","<NEWLINE>")).replace("<NEWLINE>","\\n")
|
||||
#self._listener.sendLine(u'{} "{!s}" {} {}'.format(self.OSD_QUERY, message, duration, constants.MPLAYER_OSD_LEVEL).encode('utf-8'))
|
||||
|
||||
|
||||
@ -116,7 +116,7 @@ class VlcPlayer(BasePlayer):
|
||||
else:
|
||||
return self._position
|
||||
|
||||
def displayMessage(self, message, duration=constants.OSD_DURATION * 1000, secondaryOSD=False):
|
||||
def displayMessage(self, message, duration=constants.OSD_DURATION * 1000, secondaryOSD=False, mood=constants.MESSAGE_NEUTRAL):
|
||||
duration /= 1000
|
||||
if secondaryOSD == False:
|
||||
self._listener.sendLine('display-osd: {}, {}, {}'.format('top-right', duration, message.encode('utf8')))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user