Skip to content

Commit dd0fb66

Browse files
add mouse click to avatarswitch
- adds mouse click functionality. currently selects whichever avatar is clicked on, however given the scrolling nature of the selections the correct functionality should be to move the scroller to the avatar clicked on unless that is the already selected avatar, in which case it should set it- same way the music wheel works - clean up some code format and remove code related to player 2
1 parent c3f6aa1 commit dd0fb66

File tree

1 file changed

+63
-85
lines changed

1 file changed

+63
-85
lines changed
Lines changed: 63 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11

2+
local function input(event)
3+
if event.DeviceInput.button == 'DeviceButton_left mouse button' then
4+
if event.type == "InputEventType_Release" then
5+
MESSAGEMAN:Broadcast("AvMouseLeftClick")
6+
end
7+
end
8+
return false
9+
end
210

311
--Parameters.
412
local imgTypes = {".jpg",".png",".gif",".jpeg"}
@@ -22,8 +30,8 @@ local function getInitAvatarIndex(pn)
2230
for i=1,#avatars do
2331
if avatar == avatars[i] then
2432
return i
25-
end;
26-
end;
33+
end
34+
end
2735

2836
return 1
2937
end
@@ -45,14 +53,11 @@ local data ={
4553
cursorIndex = getInitCursorIndex(PLAYER_1),
4654
avatarIndex = getInitAvatarIndex(PLAYER_1),
4755
},
48-
PlayerNumber_P2 = {
49-
cursorIndex = getInitCursorIndex(PLAYER_2),
50-
avatarIndex = getInitAvatarIndex(PLAYER_2),
51-
},
5256
}
5357

5458
local t = Def.ActorFrame{
55-
Name="AvatarSwitch";
59+
Name="AvatarSwitch",
60+
OnCommand=function(self) SCREENMAN:GetTopScreen():AddInputCallback(input) end,
5661
}
5762

5863
--Shifts an actor by "1 index"
@@ -82,33 +87,19 @@ end
8287
-- The main function that contains errything
8388
local function avatarSwitch(pn)
8489
local t = Def.ActorFrame{
85-
Name="AvatarSwitch"..pn;
90+
Name="AvatarSwitch"..pn,
8691
BeginCommand=function(self)
87-
if pn == PLAYER_1 then
88-
self:x(-width);
89-
self:sleep(0.3)
90-
self:smooth(0.2)
91-
self:x(0)
92-
end;
93-
if pn == PLAYER_2 then
94-
self:x(SCREEN_WIDTH)
95-
self:sleep(0.3)
96-
self:smooth(0.2)
97-
self:x(SCREEN_WIDTH-width)
98-
end;
99-
end;
92+
self:x(-width)
93+
self:sleep(0.3)
94+
self:smooth(0.2)
95+
self:x(0)
96+
end,
10097
CodeMessageCommand=function(self,params)
10198
if params.Name == "AvatarCancel" or params.Name == "AvatarExit" then
102-
if pn == PLAYER_1 then
103-
self:smooth(0.2)
104-
self:x(-width)
105-
end
106-
if pn == PLAYER_2 then
107-
self:smooth(0.2)
108-
self:x(SCREEN_WIDTH)
109-
end
110-
end;
111-
end;
99+
self:smooth(0.2)
100+
self:x(-width)
101+
end
102+
end
112103
}
113104

114105
t[#t+1] = Def.ActorFrame{
@@ -125,8 +116,8 @@ local function avatarSwitch(pn)
125116
elseif data[pn]["avatarIndex"] > 1 and data[pn]["cursorIndex"] == 1 then
126117
shift(table,1)
127118
data[pn]["avatarIndex"] = data[pn]["avatarIndex"] - 1
128-
end;
129-
end;
119+
end
120+
end
130121
if params.Name == "AvatarRight" then
131122
if data[pn]["avatarIndex"] < #avatars and data[pn]["cursorIndex"] < maxItems then
132123
shift(cursor,1)
@@ -135,115 +126,102 @@ local function avatarSwitch(pn)
135126
elseif data[pn]["avatarIndex"] < #avatars and data[pn]["cursorIndex"] == maxItems then
136127
shift(table,-1)
137128
data[pn]["avatarIndex"] = data[pn]["avatarIndex"] + 1
138-
end;
139-
end;
140-
end;
129+
end
130+
end
131+
end
141132
--rq out of the screen if just canceling.
142133
if params.Name == "AvatarCancel" then
143134
SCREENMAN:GetTopScreen():Cancel()
144-
end;
145-
--save and exit if exiting. forcefully save both players when 2p as only the changes for the person who pressed exit will be applied.
135+
end
136+
146137
if params.Name == "AvatarExit" then
147-
if GAMESTATE:GetNumPlayersEnabled() == 1 then
148-
saveAvatar(params.PlayerNumber)
149-
setAvatarUpdateStatus(pn,true)
150-
else
151-
saveAvatar(PLAYER_1)
152-
setAvatarUpdateStatus(PLAYER_1,true)
153-
saveAvatar(PLAYER_2)
154-
setAvatarUpdateStatus(PLAYER_2,true)
155-
end;
138+
saveAvatar(params.PlayerNumber)
139+
setAvatarUpdateStatus(pn,true)
156140
SCREENMAN:GetTopScreen():Cancel()
157-
end;
158-
end;
141+
end
142+
end
159143
}
160144

161145
--Background Quad
162146
t[#t+1] = Def.Quad{
163147
InitCommand=function(self)
164148
self:xy(frameX,frameY):zoomto(width,height):halign(0):valign(1):diffuse(color("#00000066"))
165-
end;
149+
end
166150
}
167151

168152
--MASKING SCKS
169153
t[#t+1] = Def.Quad{
170154
InitCommand=function(self)
171155
self:xy(width,0):zoomto(SCREEN_WIDTH-width,SCREEN_HEIGHT):halign(0):valign(0):zwrite(true):clearzbuffer(true):blend('BlendMode_NoEffect')
172-
end;
173-
BeginCommand=function(self)
174-
if pn == PLAYER_2 then
175-
self:x(0)
176-
self:halign(1)
177-
end;
178-
end;
156+
end,
179157
}
180158

181159
--Cursor
182160
t[#t+1] = Def.Quad{
183-
Name="AvatarCursor";
161+
Name="AvatarCursor",
184162
InitCommand=function(self)
185163
self:xy(frameX-2+border,frameY+2-border):zoomto(itemHeight+4,itemWidth+4):halign(0):valign(1):diffuse(color("#FFFFFF"))
186-
end;
164+
end,
187165
BeginCommand=function(self)
188166
shift(self,(data[pn]["cursorIndex"]-1))
189-
end;
167+
end
190168
}
191169

192170
--List of avatars
193171
local avatarTable = Def.ActorFrame{
194-
Name="AvatarTable";
172+
Name="AvatarTable",
195173
BeginCommand=function(self)
196174
shift(self,-(data[pn]["avatarIndex"]-1))
197175
shift(self,(data[pn]["cursorIndex"]-1))
198-
end;
176+
end
199177
}
200178
t[#t+1] = avatarTable
201179
for k,v in pairs(avatars) do
202180
avatarTable[#avatarTable+1] = Def.Sprite {
181+
Name = #avatarTable,
203182
InitCommand=function(self)
204183
self:visible(true):halign(0):valign(1):xy(frameX+border+((border+itemWidth)*(k-1)),frameY-border):ztest(true)
205-
end;
184+
end,
206185
BeginCommand=function(self)
207186
self:queuecommand("ModifyAvatar")
208-
end;
187+
end,
209188
ModifyAvatarCommand=function(self)
210-
self:finishtweening();
211-
self:LoadBackground(THEME:GetPathG("","Player avatar/"..v));
189+
self:finishtweening()
190+
self:LoadBackground(THEME:GetPathG("","Player avatar/"..v))
212191
self:zoomto(itemWidth,itemHeight)
213-
end;
214-
};
215-
end;
192+
end,
193+
AvMouseLeftClickMessageCommand=function(self) -- theoretically this should move the scroller unless to the target, unless the target is already selected in which case this should executre, but, that's work -mina
194+
if isOver(self) then
195+
data[pn]["avatarIndex"] = tonumber(self:GetName()) + 1
196+
saveAvatar(pn)
197+
setAvatarUpdateStatus(pn,true)
198+
SCREENMAN:GetTopScreen():Cancel()
199+
end
200+
end,
201+
}
202+
end
216203

217204
--Text
218205
t[#t+1] = LoadFont("Common Normal") .. {
219206
InitCommand=function(self)
220207
self:xy(frameX,frameY-height):halign(0):valign(1):zoom(0.35)
221-
end;
208+
end,
222209
BeginCommand=function(self)
223210
self:queuecommand("Set")
224-
end;
211+
end,
225212
SetCommand=function(self,params)
226-
local profileName = profile:GetDisplayName()
227-
--self:settextf("Player 1 avatar: ci%d ai%d",cursorIndex,avatarIndex)
228-
if pn == PLAYER_1 then
229-
self:settextf("%s's avatar: %s",profileName,avatars[data[pn]["avatarIndex"]])
230-
end;
231-
if pn == PLAYER_2 then
232-
self:settextf("%s's avatar: %s",profileName,avatars[data[pn]["avatarIndex"]])
233-
end;
234-
end;
213+
local profileName = GetPlayerOrMachineProfile(PLAYER_1):GetDisplayName()
214+
self:settextf("%s's avatar: %s",profileName,avatars[data[pn]["avatarIndex"]])
215+
end,
235216
CodeMessageCommand=function(self)
236217
self:queuecommand("Set")
237-
end;
238-
};
218+
end
219+
}
239220
return t
240221
end
241222

242223
if GAMESTATE:IsHumanPlayer(PLAYER_1) then
243224
t[#t+1] = avatarSwitch(PLAYER_1)
244225
end
245-
if GAMESTATE:IsHumanPlayer(PLAYER_2) then
246-
t[#t+1] = avatarSwitch(PLAYER_2)
247-
end
248226

249227
return t

0 commit comments

Comments
 (0)