-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRS_InputExCallObjects.rb
251 lines (217 loc) · 6.47 KB
/
RS_InputExCallObjects.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#================================================================
# The MIT License
# Copyright (c) 2020 biud436
# ---------------------------------------------------------------
# Free for commercial and non commercial use.
#================================================================
#===============================================================================
# Name : RS_InputExCallObjects
# Author : biud436
#-------------------------------------------------------------------------------
# 사용법
#-------------------------------------------------------------------------------
# 이 스크립트는 RS_Input이라는 선행 전체키 스크립트가 있어야 동작합니다.
#
# 이 스크립트는 주로 마우스 커서의 움직임을 관찰하여 마우스 오버, 마우스 클릭, 마우스 아웃
# 이벤트를 발생시킵니다.
#
# 그림 위에 마우스 커서가 있을 때, (마우스 오버시),
# 그림을 마우스로 클릭할 때,
# 그림이 마우스 위에 오버되고 빠져나갈 때, (마우스 아웃 시)
#
# 특정 커먼 이벤트를 발생시킵니다.
#
#-------------------------------------------------------------------------------
# Version Log
#-------------------------------------------------------------------------------
# 2020.01.29 (v1.0.0) - First Release.
# 2021.04.18 (v1.0.1) :
# - 옵션 설정에서 마우스 바깥 이벤트 감지인 OUT_EVENT_EMIT_ONCE를 false로 하면,
# 병렬 처리 이벤트에서 그림의 표시 이벤트가 있을 때
# 마우스 바깥의 좌표를 계속 체크하므로 캐릭터를 조절할 수 없는 문제가 생기게 되므로
# 설정을 true로 변경하였습니다.
# 이외에도 버그가 있는 걸로 보여집니다.
#===============================================================================
$imported = {} if $imported.nil?
$imported["RS_InputExCallObjects"] = true
if !$imported["RS_Input"]
`start https://biud436.blog.me/220289463681`
raise %Q(
전체키 스크립트를 찾을 수 없습니다.
의존성 스크립트를 모두 설치해주시기 바랍니다.
)
end
module RS::Input
module Pictures
# 마우스 오버 시
OVER = {
# 그림 번호 => 커먼 이벤트 ID,
1 => 1
}
# 마우스 클릭 시
CLICK = {
# 그림 번호 => 커먼 이벤트 ID,
1 => 2
}
# 마우스가 오버되고 빠져나갈 때
OUT = {
# 그림 번호 => 커먼 이벤트 ID,
1 => 3,
}
# 마우스 커서의 크기
CURSOR_SIZE = 24
# 스프라이트 마우스 아웃 이벤트를 한 번만 발생시키려면 true,
# 마우스가 바깥에 있어도 계속 발생시키려면 false
OUT_EVENT_EMIT_ONCE = true
# 기본 클래스
BASE_CLASS = Sprite
end
end
#==============================================================================
# ** Sprite
#==============================================================================
class RS::Input::Pictures::BASE_CLASS
attr_reader :mouse_over, :mouse_clicked
alias rs_mb_sprite_initialize initialize
def initialize(viewport=nil)
rs_mb_sprite_initialize(viewport)
@mouse_over = false
@prev_mouse_over = false
@mouse_clicked = false
end
def update_mouse
return if !self.bitmap
return if !self.visible
f = RS::Input::Pictures::CURSOR_SIZE / 2
mx = TouchInput.x + f
my = TouchInput.y + f
cx = self.x
cy = self.y
cw = self.width
ch = self.height
return if cw <= 0 || ch <= 0
if mx.between?(cx, cx + cw) and my.between?(cy, cy + ch)
@mouse_over = true
else
@mouse_over = false
end
if @mouse_over
@mouse_clicked = TouchInput.trigger?(:LEFT)
on_mouse_over
else
if RS::Input::Pictures::OUT_EVENT_EMIT_ONCE
if @prev_mouse_over
on_mouse_out
end
else
on_mouse_out
end
end
if @mouse_clicked
on_mouse_click
end
end
def on_mouse_out
@prev_mouse_over = false
end
def on_mouse_over
@prev_mouse_over = true
end
def on_mouse_click
@mouse_clicked = false
end
alias rs_mb_sprite_update update
def update
rs_mb_sprite_update
update_mouse
end
end
#==============================================================================
# ** Window
#==============================================================================
class Window
alias rs_mb_window_initialize initialize
def initialize(*args)
if args.length == 1
viewport = args[0]
elsif args.length == 4
x, y, width, height = args
end
rs_mb_window_initialize(*args)
@mouse_over = false
@prev_mouse_over = false
@mouse_clicked = false
end
def update_mouse
return if !self.contents
return if !self.visible
f = RS::Input::Pictures::CURSOR_SIZE / 2
mx = TouchInput.x - f
my = TouchInput.y - f
cx = self.x
cy = self.y
cw = self.width
ch = self.height
return if cw <= 0 || ch <= 0
if mx.between?(cx, cx + cw) and my.between?(cy, cy + ch)
@mouse_over = true
else
@mouse_over = false
end
if @mouse_over
@mouse_clicked = TouchInput.trigger?(:LEFT)
on_mouse_over
else
on_mouse_out
end
if @mouse_clicked
on_mouse_click
end
end
def on_mouse_out
@prev_mouse_over = false
end
def on_mouse_over
@prev_mouse_over = true
end
def on_mouse_click
@mouse_clicked = false
end
alias rs_mb_window_update update
def update
rs_mb_window_update
update_mouse
end
end
#==============================================================================
# ** Sprite_Picture
#==============================================================================
class Sprite_Picture
def on_mouse_over
if @picture.name
common_event_id = RS::Input::Pictures::OVER[@picture.number]
if !common_event_id.nil?
$game_temp.reserve_common_event(common_event_id)
end
end
super
end
def on_mouse_out
if @picture.name
common_event_id = RS::Input::Pictures::OUT[@picture.number]
if !common_event_id.nil?
$game_temp.reserve_common_event(common_event_id)
end
end
super
end
def on_mouse_click
if @picture.name
common_event_id = RS::Input::Pictures::CLICK[@picture.number]
if !common_event_id.nil?
$game_temp.reserve_common_event(common_event_id)
end
end
super
end
end