forked from suppayami/rmvxa-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pop Message.rb
461 lines (417 loc) · 16.3 KB
/
Pop Message.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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
#==============================================================================
#
# ¥ Yami Engine Symphony - Pop Message
# -- Last Updated: 2013.01.29
# -- Level: Easy
# -- Requires: n/a
#
#==============================================================================
$imported = {} if $imported.nil?
$imported["YES-PopMessage"] = true
#==============================================================================
# ¥ Updates
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# 2013.01.29 - Compatible with: YEA - Ace Message System Namebox.
# 2013.01.29 - Fixed a minor crash with Bubble Tag.
# 2013.01.28 - Finished Script.
# 2013.01.25 - Started Script.
#
#==============================================================================
# ¥ Introduction
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script provides bubble messages feature, which makes message window pop
# over player's or event's head.
#
#==============================================================================
# ¥ Instructions
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# To install this script, open up your script editor and copy/paste this script
# to an open slot below ¥ Materials/‘fÞ but above ¥ Main. Remember to save.
#
# -----------------------------------------------------------------------------
# Message Window text Codes - These go inside of your message window.
# -----------------------------------------------------------------------------
# Code: Effect:
# \bm[x] - Pops message on event ID x head.
# Set x to 0 for player pop.
# \cbm - Cancel pops message manually.
# \cbt[name] - Set bubble tag filename to name.
#
#==============================================================================
# ¥ Compatibility
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
# it will run with RPG Maker VX without adjustments.
#
#==============================================================================
#==============================================================================
# ¡ Configuration
#==============================================================================
module YES
module POP_MESSAGE
#===========================================================================
# - Limit Settings -
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# The following below will adjust the limit options for pop message.
#===========================================================================
LIMIT_SETTING = { # Start.
:width => 0, # Set to 0 to disable limitation.
:lines => 4, # Set to 0 to disable limitation.
} # End.
#===========================================================================
# - Effect Settings -
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# The following below will adjust the effect options for pop message.
#===========================================================================
EFFECT_SETTING = { # Start.
:default_face => false,# Use default face draw.
# Effects for non-default face draw.
:face_fade => true, # Makes face to be fading when start message.
:face_move => true, # Makes face to be moving in when start message.
# Bubble tag settings.
:bubble_tag => true, # Enables bubble tag for pop message.
:bubble_name => "BubbleTag", # Put bubble tag image into
# Graphics/System
:bubble_offset_y => -6,
} # End.
end
end
#==============================================================================
# ¥ Editting anything past this point may potentially result in causing
# computer damage, incontinence, explosion of user's head, coma, death, and/or
# halitosis so edit at your own risk.
#==============================================================================
#==============================================================================
# ¡ Window_MessageFace
#==============================================================================
class Window_MessageFace < Window_Base
#--------------------------------------------------------------------------
# initialize
#--------------------------------------------------------------------------
def initialize
super(0, 0, 120, 120)
self.opacity = 0
self.contents_opacity = 0
self.close
@move_x = 0
end
#--------------------------------------------------------------------------
# draw_content_face
#--------------------------------------------------------------------------
def draw_content_face
if $game_message.face_name.empty?
hide_face
else
self.y = - self.height
contents.clear
draw_face($game_message.face_name, $game_message.face_index, 0, 0)
end
end
#--------------------------------------------------------------------------
# fade_time
#--------------------------------------------------------------------------
def fade_time
17
end
#--------------------------------------------------------------------------
# move_time
#--------------------------------------------------------------------------
def move_time
17
end
#--------------------------------------------------------------------------
# move_rate
#--------------------------------------------------------------------------
def move_rate
2
end
#--------------------------------------------------------------------------
# show_face
#--------------------------------------------------------------------------
def show_face
return if $game_message.face_name.empty?
self.open
#---
if (YES::POP_MESSAGE::EFFECT_SETTING[:face_fade] ||
YES::POP_MESSAGE::EFFECT_SETTING[:face_move])
self.openness = 255
end
#---
if YES::POP_MESSAGE::EFFECT_SETTING[:face_fade]
self.contents_opacity = 0
else
self.contents_opacity = 255
end
#---
if YES::POP_MESSAGE::EFFECT_SETTING[:face_move]
@move_x = move_time * move_rate
self.x -= @move_x
end
end
#--------------------------------------------------------------------------
# hide_face
#--------------------------------------------------------------------------
def hide_face
close
end
#--------------------------------------------------------------------------
# update
#--------------------------------------------------------------------------
def update
super
#---
self.contents_opacity += 255.0 / fade_time
#---
if @move_x > 0
rate = [move_rate, @move_x].min
@move_x -= rate
self.x += rate
end
end
end # Window_MessageFace
#==============================================================================
# ¡ Window_Message
#==============================================================================
class Window_Message < Window_Base
#--------------------------------------------------------------------------
# new method: pop_message_initialize
#--------------------------------------------------------------------------
def pop_message_initialize(text)
if text =~ /\\BM\[(\d+)\]/i
setup_pop_message($1.to_i)
end
if text =~ /\\CBM/i
cancel_pop_message
end
if text =~ /\\CBT\[(.*)\]/i
create_bubble_sprite($1)
@bubble_sprite.opacity = 255
end
end
#--------------------------------------------------------------------------
# new method: process_pop_message
#--------------------------------------------------------------------------
def process_pop_message(text)
text.gsub!(/\eCBT\[(.*)\]/i) { "" }
text.gsub!(/\eBM\[(\d+)\]/i) { "" }
text.gsub!(/\eCBM/i) { "" }
text
end
#--------------------------------------------------------------------------
# alias method: convert_escape_characters
#--------------------------------------------------------------------------
alias yes_pm_convert_escape_characters convert_escape_characters
def convert_escape_characters(text)
result = yes_pm_convert_escape_characters(text)
result = process_pop_message(result)
result
end
#--------------------------------------------------------------------------
# new method: setup_pop_message
#--------------------------------------------------------------------------
def setup_pop_message(id)
create_bubble_sprite
adjust_window_size
adjust_window_position(id)
@bubble_sprite.opacity = 255
end
#--------------------------------------------------------------------------
# new method: create_bubble_sprite
#--------------------------------------------------------------------------
def create_bubble_sprite(filename = nil)
return unless YES::POP_MESSAGE::EFFECT_SETTING[:bubble_tag]
filename = YES::POP_MESSAGE::EFFECT_SETTING[:bubble_name] unless filename
bitmap = Cache.system(filename)
@bubble_sprite ||= Sprite.new
@bubble_sprite.z = self.z
@bubble_sprite.opacity = 0
@bubble_sprite.bitmap = bitmap
@bubble_sprite.src_rect.set(0, 0, bitmap.width, bitmap.height / 2)
end
#--------------------------------------------------------------------------
# new method: adjust_window_position
#--------------------------------------------------------------------------
def adjust_window_position(id)
hash = $game_map.events
character = id <= 0 ? $game_player : hash[id]
#---
bitmap = Cache.character(character.character_name)
sign = character.character_name[/^[\!\$]./]
if sign && sign.include?('$')
ch = bitmap.height / 4
else
ch = bitmap.height / 8
end
#---
self.x = character.screen_x - self.width / 2
self.y = character.screen_y - self.height - ch
if @bubble_sprite
@bubble_sprite.x = character.screen_x - @bubble_sprite.width / 2
@bubble_sprite.y = self.y + self.height
@bubble_sprite.y += YES::POP_MESSAGE::EFFECT_SETTING[:bubble_offset_y]
end
#---
end_x = self.x + self.width
self.x = 0 if self.x < 0
self.x = Graphics.width - self.width if end_x > Graphics.width
if self.y < 0
self.y = character.screen_y
if @bubble_sprite
@bubble_sprite.y = self.y - @bubble_sprite.height
@bubble_sprite.y -= YES::POP_MESSAGE::EFFECT_SETTING[:bubble_offset_y]
@bubble_sprite.src_rect.set(0, @bubble_sprite.height,
@bubble_sprite.width, @bubble_sprite.height)
end
end
end
#--------------------------------------------------------------------------
# new method: adjust_window_size
#--------------------------------------------------------------------------
def adjust_window_size
text = convert_escape_characters($game_message.all_text)
#---
width = cal_width_line(text) + standard_padding * 2
width = width + new_line_x
if YES::POP_MESSAGE::LIMIT_SETTING[:width] > 0
width = [YES::POP_MESSAGE::LIMIT_SETTING[:width], width]
end
#---
lines = cal_number_line(text)
if YES::POP_MESSAGE::LIMIT_SETTING[:lines] > 0
lines = [YES::POP_MESSAGE::LIMIT_SETTING[:lines], lines].min
end
if YES::POP_MESSAGE::EFFECT_SETTING[:default_face]
unless $game_message.face_name.empty?
lines = [4, lines].max
end
end
#---
self.width = width
self.height = fitting_height(lines)
create_contents
end
#--------------------------------------------------------------------------
# new method: cal_number_line
#--------------------------------------------------------------------------
def cal_number_line(text)
result = 0
text.each_line { result += 1 }
return result
end
#--------------------------------------------------------------------------
# new method: cal_width_line
#--------------------------------------------------------------------------
def cal_width_line(text)
result = 0
text.each_line { |line|
result = text_size(line).width if result < text_size(line).width
}
return result
end
#--------------------------------------------------------------------------
# new method: cancel_pop_message
#--------------------------------------------------------------------------
def cancel_pop_message
update_placement
reset_size
create_bubble_sprite
end
#--------------------------------------------------------------------------
# new method: reset_size
#--------------------------------------------------------------------------
def reset_size
self.width = window_width
self.height = window_height
update_padding
create_contents
end
#--------------------------------------------------------------------------
# alias method: draw_face
#--------------------------------------------------------------------------
alias yes_pop_message_draw_face draw_face
def draw_face(face_name, face_index, x, y, enabled = true)
return unless YES::POP_MESSAGE::EFFECT_SETTING[:default_face]
yes_pop_message_draw_face(face_name, face_index, x, y, enabled)
end
#--------------------------------------------------------------------------
# alias method: update_placement
#--------------------------------------------------------------------------
alias yes_pop_message_update_placement update_placement
def update_placement
yes_pop_message_update_placement
self.x = 0
end
#--------------------------------------------------------------------------
# alias method: process_all_text
#--------------------------------------------------------------------------
alias yes_pop_message_process_all_text process_all_text
def process_all_text
pop_message_initialize($game_message.all_text)
yes_pop_message_process_all_text
end
#--------------------------------------------------------------------------
# alias method: open_and_wait
#--------------------------------------------------------------------------
alias yes_pop_message_open_and_wait open_and_wait
def open_and_wait
yes_pop_message_open_and_wait
@face_window ||= Window_MessageFace.new
@face_window.draw_content_face
@face_window.x = self.x + 8
@face_window.y += self.y + self.height
@face_window.show_face
end
#--------------------------------------------------------------------------
# alias method: close_and_wait
#--------------------------------------------------------------------------
alias yes_pop_message_close_and_wait close_and_wait
def close_and_wait
@face_window.hide_face
@bubble_sprite.opacity = 0 if @bubble_sprite
yes_pop_message_close_and_wait
cancel_pop_message
end
#--------------------------------------------------------------------------
# alias method: update
#--------------------------------------------------------------------------
alias yes_pop_message_update update
def update
yes_pop_message_update
if @face_window
@face_window.update
@face_window.z = self.z
end
if @bubble_sprite
@bubble_sprite.update
@bubble_sprite.z = self.z
end
end
#--------------------------------------------------------------------------
# overwrite method: adjust_message_window_size
# YEA - Message System Compatible
#--------------------------------------------------------------------------
def adjust_message_window_size
start_name_window
end
end # Window_Message
#==============================================================================
# ¡ Window_NameMessage
#==============================================================================
if $imported["YEA-MessageSystem"]
class Window_NameMessage < Window_Base
#--------------------------------------------------------------------------
# set_x_position
#--------------------------------------------------------------------------
alias yes_pm_set_x_position set_x_position
def set_x_position(x_position)
yes_pm_set_x_position(x_position)
self.x += @message_window.new_line_x if x_position == 1
self.z = @message_window.z
end
end # Window_NameMessage
end
#==============================================================================
#
# ¥ End of File
#
#==============================================================================