-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathTemporary Text Bubble.rb
146 lines (129 loc) · 3.97 KB
/
Temporary Text Bubble.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
#===============================================================================
# TheoAllen - Temporary Text Bubble
#-------------------------------------------------------------------------------
# 2018.08.13 - Finished
#===============================================================================
# > Introduction
#-------------------------------------------------------------------------------
# This script pops up a text bubble above a character and goes away after
# certain time has passed. It should not be used for an actual text dialogue
# as it has no wait time. Best to be used as random NPC/Character commentary
#
#===============================================================================
# > How to use
#-------------------------------------------------------------------------------
# Use it in move route script call
# > bubble(text)
# > bubble(text, timeout)
#
# Text is an actual text using ""
# Timeout is frame before it starts fading. Default value is 90 frames
#
# Example :
# > bubble("What was that?")
# > bubble("What was that?", 120)
#
# For splitting into two line, use \n
# Example :
# > bubble("What was that? Sure\n I saw something")
# > bubble("What was that? Sure\n I saw something", 120)
#
#===============================================================================
# > Terms of Use
#-------------------------------------------------------------------------------
# Credit me, TheoAllen. You are free to edit this script by your own. As long
# as you don't claim it's yours. For commercial purpose, don't forget to give me
# a free copy of the game.
#===============================================================================
class Sprite_Bubble < Sprite
Height = 16
Col = Color.new(0,0,0,180)
def initialize(vport, char, text, timeout = 60)
super(vport)
@char = char
self.bitmap = Bitmap.new(23,23)
bitmap.font.size = Height
show_text(text)
@timeout = timeout
update
end
def show_text(text)
@text = text.split(/\n/)
s = @text.collect {|t| self.bitmap.text_size(t).width}.max
bmp = Bitmap.new(s+10,Height*@text.size + 5)
self.bitmap = bmp
bitmap.font.size = Height
draw_background
draw_message
self.ox = width/2
self.oy = height
end
def draw_background
# main body
h = Height*@text.size + 1
bitmap.fill_rect(2,0,width-4,h,Col)
# border left
bitmap.fill_rect(1,1,1,h-2,Col)
bitmap.fill_rect(0,2,1,h-4,Col)
# border right
bitmap.fill_rect(width-1 ,2 ,1 ,h-4,Col)
bitmap.fill_rect(width-2 ,1 ,1 ,h-2,Col)
# pointer
bitmap.fill_rect(width/2-3, h ,7,1,Col)
bitmap.fill_rect(width/2-2, h+1 ,5,1,Col)
bitmap.fill_rect(width/2-1, h+2 ,3,1,Col)
bitmap.fill_rect(width/2, h+3 ,1,1,Col)
end
def draw_message
@text.each_with_index do |t,i|
bitmap.draw_text(5,Height*i,width,20,t)
end
end
def update
super
update_position
@timeout -= 1
if @timeout == 0
if $imported[:Theo_CoreFade] && !fade?
fadeout(30)
else
dispose
end
elsif opacity == 0
dispose
end
end
def update_position
self.x = @char.x
self.y = @char.y - @char.height
end
end
class Game_Character
attr_reader :bubble_text
attr_reader :bubble_timeout
def bubble(text, timeout = 100)
@bubble_text = text
@bubble_timeout = timeout
end
def clear_bubbles
@bubble_text = @bubble_timeout = nil
end
end
class Sprite_Character
alias aed2_text_bubble_update update
def update
aed2_text_bubble_update
if !character.bubble_text.nil? && (!@bubble || @bubble.disposed?)
text = character.bubble_text
time = character.bubble_timeout
character.clear_bubbles
@bubble = Sprite_Bubble.new(viewport,self,text,time)
end
@bubble.update if @bubble && [email protected]?
end
alias aed2_text_bubble_dispose dispose
def dispose
aed2_text_bubble_dispose
@bubble.dispose if @bubble && [email protected]?
end
end