Skip to content

Commit

Permalink
Fix music stop on avatar change
Browse files Browse the repository at this point in the history
  • Loading branch information
poco0317 committed Sep 13, 2018
1 parent 900aaca commit cd2a460
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 43 deletions.
6 changes: 6 additions & 0 deletions Themes/Til Death/BGAnimations/ScreenAvatarSwitch in.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
return Def.ActorFrame{
InitCommand=function(self)
self:visible(false)
SCREENMAN:SystemMessage("Avatar Switcher Activated")
end
}
90 changes: 52 additions & 38 deletions Themes/Til Death/BGAnimations/_switchavatar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ local function input(event)
MESSAGEMAN:Broadcast("AvMouseLeftClick")
end
end
if event.type ~= "InputEventType_Release" then
if event.GameButton == "MenuLeft" then
MESSAGEMAN:Broadcast("AvLeft")
elseif event.GameButton == "MenuRight" then
MESSAGEMAN:Broadcast("AvRight")
elseif event.GameButton == "Back" then
MESSAGEMAN:Broadcast("AvCancel")
elseif event.GameButton == "Start" then
MESSAGEMAN:Broadcast("AvExit")
end
end
return false
end

Expand Down Expand Up @@ -94,51 +105,54 @@ local function avatarSwitch(pn)
self:smooth(0.2)
self:x(0)
end,
CodeMessageCommand=function(self,params)
if params.Name == "AvatarCancel" or params.Name == "AvatarExit" then
self:smooth(0.2)
self:x(-width)
end
AvExitMessageCommand=function(self)
self:smooth(0.2)
self:x(-width)
end,
AvCancelMessageCommand=function(self)
self:smooth(0.2)
self:x(-width)
end
}

t[#t+1] = Def.ActorFrame{
CodeMessageCommand=function(self,params)
AvLeftMessageCommand=function(self)
--grab table/cursor and shift them by 1 to left/right everytime someone presses code for avatarleft/right
local table = SCREENMAN:GetTopScreen():GetChildren().Overlay:GetChildren().AvatarSwitch:GetChildren()["AvatarSwitch"..pn]:GetChildren().AvatarTable
local cursor = SCREENMAN:GetTopScreen():GetChildren().Overlay:GetChildren().AvatarSwitch:GetChildren()["AvatarSwitch"..pn]:GetChildren().AvatarCursor
if params.PlayerNumber == pn then
if params.Name == "AvatarLeft" then
if data[pn]["avatarIndex"] > 1 and data[pn]["cursorIndex"] > 1 then
shift(cursor,-1)
data[pn]["avatarIndex"] = data[pn]["avatarIndex"] - 1
data[pn]["cursorIndex"] = data[pn]["cursorIndex"] - 1
elseif data[pn]["avatarIndex"] > 1 and data[pn]["cursorIndex"] == 1 then
shift(table,1)
data[pn]["avatarIndex"] = data[pn]["avatarIndex"] - 1
end
end
if params.Name == "AvatarRight" then
if data[pn]["avatarIndex"] < #avatars and data[pn]["cursorIndex"] < maxItems then
shift(cursor,1)
data[pn]["avatarIndex"] = data[pn]["avatarIndex"] + 1
data[pn]["cursorIndex"] = data[pn]["cursorIndex"] + 1
elseif data[pn]["avatarIndex"] < #avatars and data[pn]["cursorIndex"] == maxItems then
shift(table,-1)
data[pn]["avatarIndex"] = data[pn]["avatarIndex"] + 1
end
end
local avatarAttributes = SCREENMAN:GetTopScreen():GetChildren().Overlay:GetChildren().AvatarSwitch:GetChildren()["AvatarSwitch"..pn]:GetChildren()
local table = avatarAttributes.AvatarTable
local cursor = avatarAttributes.AvatarCursor
if data[pn]["avatarIndex"] > 1 and data[pn]["cursorIndex"] > 1 then
shift(cursor,-1)
data[pn]["avatarIndex"] = data[pn]["avatarIndex"] - 1
data[pn]["cursorIndex"] = data[pn]["cursorIndex"] - 1
elseif data[pn]["avatarIndex"] > 1 and data[pn]["cursorIndex"] == 1 then
shift(table,1)
data[pn]["avatarIndex"] = data[pn]["avatarIndex"] - 1
end
--rq out of the screen if just canceling.
if params.Name == "AvatarCancel" then
SCREENMAN:GetTopScreen():Cancel()
end,
AvRightMessageCommand=function(self)
--grab table/cursor and shift them by 1 to left/right everytime someone presses code for avatarleft/right
local avatarAttributes = SCREENMAN:GetTopScreen():GetChildren().Overlay:GetChildren().AvatarSwitch:GetChildren()["AvatarSwitch"..pn]:GetChildren()
local table = avatarAttributes.AvatarTable
local cursor = avatarAttributes.AvatarCursor
if data[pn]["avatarIndex"] < #avatars and data[pn]["cursorIndex"] < maxItems then
shift(cursor,1)
data[pn]["avatarIndex"] = data[pn]["avatarIndex"] + 1
data[pn]["cursorIndex"] = data[pn]["cursorIndex"] + 1
elseif data[pn]["avatarIndex"] < #avatars and data[pn]["cursorIndex"] == maxItems then
shift(table,-1)
data[pn]["avatarIndex"] = data[pn]["avatarIndex"] + 1
end
end,

if params.Name == "AvatarExit" then
saveAvatar(params.PlayerNumber)
setAvatarUpdateStatus(pn,true)
SCREENMAN:GetTopScreen():Cancel()
end
--rq out of the screen if just canceling.
AvCancelMessageCommand=function(self)
SCREENMAN:GetTopScreen():Cancel()
end,
AvExitMessageCommand=function(self)
saveAvatar(pn)
setAvatarUpdateStatus(pn,true)
SCREENMAN:GetTopScreen():Cancel()
end
}

Expand Down Expand Up @@ -213,7 +227,7 @@ local function avatarSwitch(pn)
local profileName = GetPlayerOrMachineProfile(PLAYER_1):GetDisplayName()
self:settextf("%s's avatar: %s",profileName,avatars[data[pn]["avatarIndex"]])
end,
CodeMessageCommand=function(self)
AvExitMessageCommand=function(self)
self:queuecommand("Set")
end
}
Expand Down
6 changes: 1 addition & 5 deletions Themes/Til Death/metrics.ini
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,7 @@ Class="ScreenWithMenuElements"
Fallback="ScreenWithMenuElements"
PrevScreen="ScreenSelectMusic"

CodeNames="AvatarLeft,AvatarRight,AvatarCancel,AvatarExit"
CodeAvatarLeft="MenuLeft"
CodeAvatarRight="MenuRight"
CodeAvatarCancel="Back"
CodeAvatarExit="Start"
PlayMusic=false

[ScreenScoreTabOffsetPlot]
Class="ScreenWithMenuElements"
Expand Down

0 comments on commit cd2a460

Please sign in to comment.