1
1
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
2
10
3
11
-- Parameters.
4
12
local imgTypes = {" .jpg" ," .png" ," .gif" ," .jpeg" }
@@ -22,8 +30,8 @@ local function getInitAvatarIndex(pn)
22
30
for i = 1 ,# avatars do
23
31
if avatar == avatars [i ] then
24
32
return i
25
- end ;
26
- end ;
33
+ end
34
+ end
27
35
28
36
return 1
29
37
end
@@ -45,14 +53,11 @@ local data ={
45
53
cursorIndex = getInitCursorIndex (PLAYER_1 ),
46
54
avatarIndex = getInitAvatarIndex (PLAYER_1 ),
47
55
},
48
- PlayerNumber_P2 = {
49
- cursorIndex = getInitCursorIndex (PLAYER_2 ),
50
- avatarIndex = getInitAvatarIndex (PLAYER_2 ),
51
- },
52
56
}
53
57
54
58
local t = Def .ActorFrame {
55
- Name = " AvatarSwitch" ;
59
+ Name = " AvatarSwitch" ,
60
+ OnCommand = function (self ) SCREENMAN :GetTopScreen ():AddInputCallback (input ) end ,
56
61
}
57
62
58
63
-- Shifts an actor by "1 index"
82
87
-- The main function that contains errything
83
88
local function avatarSwitch (pn )
84
89
local t = Def .ActorFrame {
85
- Name = " AvatarSwitch" .. pn ;
90
+ Name = " AvatarSwitch" .. pn ,
86
91
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 ,
100
97
CodeMessageCommand = function (self ,params )
101
98
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
112
103
}
113
104
114
105
t [# t + 1 ] = Def .ActorFrame {
@@ -125,8 +116,8 @@ local function avatarSwitch(pn)
125
116
elseif data [pn ][" avatarIndex" ] > 1 and data [pn ][" cursorIndex" ] == 1 then
126
117
shift (table ,1 )
127
118
data [pn ][" avatarIndex" ] = data [pn ][" avatarIndex" ] - 1
128
- end ;
129
- end ;
119
+ end
120
+ end
130
121
if params .Name == " AvatarRight" then
131
122
if data [pn ][" avatarIndex" ] < # avatars and data [pn ][" cursorIndex" ] < maxItems then
132
123
shift (cursor ,1 )
@@ -135,115 +126,102 @@ local function avatarSwitch(pn)
135
126
elseif data [pn ][" avatarIndex" ] < # avatars and data [pn ][" cursorIndex" ] == maxItems then
136
127
shift (table ,- 1 )
137
128
data [pn ][" avatarIndex" ] = data [pn ][" avatarIndex" ] + 1
138
- end ;
139
- end ;
140
- end ;
129
+ end
130
+ end
131
+ end
141
132
-- rq out of the screen if just canceling.
142
133
if params .Name == " AvatarCancel" then
143
134
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
+
146
137
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 )
156
140
SCREENMAN :GetTopScreen ():Cancel ()
157
- end ;
158
- end ;
141
+ end
142
+ end
159
143
}
160
144
161
145
-- Background Quad
162
146
t [# t + 1 ] = Def .Quad {
163
147
InitCommand = function (self )
164
148
self :xy (frameX ,frameY ):zoomto (width ,height ):halign (0 ):valign (1 ):diffuse (color (" #00000066" ))
165
- end ;
149
+ end
166
150
}
167
151
168
152
-- MASKING SCKS
169
153
t [# t + 1 ] = Def .Quad {
170
154
InitCommand = function (self )
171
155
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 ,
179
157
}
180
158
181
159
-- Cursor
182
160
t [# t + 1 ] = Def .Quad {
183
- Name = " AvatarCursor" ;
161
+ Name = " AvatarCursor" ,
184
162
InitCommand = function (self )
185
163
self :xy (frameX - 2 + border ,frameY + 2 - border ):zoomto (itemHeight + 4 ,itemWidth + 4 ):halign (0 ):valign (1 ):diffuse (color (" #FFFFFF" ))
186
- end ;
164
+ end ,
187
165
BeginCommand = function (self )
188
166
shift (self ,(data [pn ][" cursorIndex" ]- 1 ))
189
- end ;
167
+ end
190
168
}
191
169
192
170
-- List of avatars
193
171
local avatarTable = Def .ActorFrame {
194
- Name = " AvatarTable" ;
172
+ Name = " AvatarTable" ,
195
173
BeginCommand = function (self )
196
174
shift (self ,- (data [pn ][" avatarIndex" ]- 1 ))
197
175
shift (self ,(data [pn ][" cursorIndex" ]- 1 ))
198
- end ;
176
+ end
199
177
}
200
178
t [# t + 1 ] = avatarTable
201
179
for k ,v in pairs (avatars ) do
202
180
avatarTable [# avatarTable + 1 ] = Def .Sprite {
181
+ Name = # avatarTable ,
203
182
InitCommand = function (self )
204
183
self :visible (true ):halign (0 ):valign (1 ):xy (frameX + border + ((border + itemWidth )* (k - 1 )),frameY - border ):ztest (true )
205
- end ;
184
+ end ,
206
185
BeginCommand = function (self )
207
186
self :queuecommand (" ModifyAvatar" )
208
- end ;
187
+ end ,
209
188
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 ))
212
191
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
216
203
217
204
-- Text
218
205
t [# t + 1 ] = LoadFont (" Common Normal" ) .. {
219
206
InitCommand = function (self )
220
207
self :xy (frameX ,frameY - height ):halign (0 ):valign (1 ):zoom (0.35 )
221
- end ;
208
+ end ,
222
209
BeginCommand = function (self )
223
210
self :queuecommand (" Set" )
224
- end ;
211
+ end ,
225
212
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 ,
235
216
CodeMessageCommand = function (self )
236
217
self :queuecommand (" Set" )
237
- end ;
238
- };
218
+ end
219
+ }
239
220
return t
240
221
end
241
222
242
223
if GAMESTATE :IsHumanPlayer (PLAYER_1 ) then
243
224
t [# t + 1 ] = avatarSwitch (PLAYER_1 )
244
225
end
245
- if GAMESTATE :IsHumanPlayer (PLAYER_2 ) then
246
- t [# t + 1 ] = avatarSwitch (PLAYER_2 )
247
- end
248
226
249
227
return t
0 commit comments