-
Notifications
You must be signed in to change notification settings - Fork 12
/
Anywhere Text on Screen.rb
307 lines (253 loc) · 7.29 KB
/
Anywhere Text on Screen.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
# =============================================================================
# TheoAllen - Anywhere Texts On Screen
# Version: 1.1
# Contact: Discord @ Theo#3034
# =============================================================================
($imported ||= {})[:Theo_AnywhereText] = true
# =============================================================================
# CHANGE LOGS:
# -----------------------------------------------------------------------------
# 2015.01.27 - Added font change
# 2013.08.26 - Finished script
# 2013.08.25 - Started script
# =============================================================================
=begin
----------------------------------------------------------------------------
Introduction :
This script allow you to have many texts written on screen.
----------------------------------------------------------------------------
How to use :
Simply put this script below material but above main
Read the manual
----------------------------------------------------------------------------
Script calls :
Write this following line to script call to add text on your screen
text(key,x,y,text,z,show,width,height,color1,color2)
Paramaters that must be filled:
- key >> Is a hash key. You may fill it with numeric or string. It's used to
delete your on screen text later
- x >> X coordinate from top-left
- y >> Y coordinate from top-left
- text >> Is the text you want to display on screen. It's support escape
characters such as \N[1] in show text message. But, you have to use
double slash to activate. For example \\N[1]
Parameters that can be ommited :
- z >> Z coordinate on screen. The larger number means the closer to
player text will be displayed. If it's ommited, the default value
is 0.
- show >> show duration in frame. If you want to text stay on screen until
you delete it manualy, use -1. The default value is -1
- width >> width of a rectangle that will be used to draw a box
- height >> height of a rectangle that will be used to draw a box
- color1 >> Color of the rectangle. Must be filled by
Color.new(red,green,blue,alpha)
- color2 >> Second Color of the rectangle. The default value is same as
color1
To delete a certain text. Use this script call
del_text(key)
Key is a hash key. Same as above
To clear entire screen, use
clear_texts
##########################
# Additional instruction #
##########################
If you want to change the font, do this script call right before add the text
$game_system.font_name = "Calibri"
text(....)
----------------------------------------------------------------------------
Terms of use :
> Free to edit / Repost of edit
> Link back to original if edited
> Credit me TheoAllen
> Free for non-commercial use / Give me a free copy for commercial use
> Not available for contest with prize such as IGMC
=end
# =============================================================================
# No configuration is avalaible
# Do not touch anything pass this line
# =============================================================================
class Game_Interpreter
def text(key,x,y,text,z = 0,show = -1, width = 0, height = 0,
color1 = Color.new, color2=color1)
return if $game_system.anytexts.include?(key)
txt = TextDTStruct.new(key,x,y,z,width,height,text,show,color1,color2)
$game_system.anytexts[key] = txt
$game_temp.text_to_add = key
Fiber.yield
end
def del_text(key)
return unless $game_system.anytexts.include?(key)
$game_temp.text_to_delete = key
Fiber.yield
end
def clear_texts
$game_system.anytexts.keys.each do |key|
del_text(key)
end
end
end
class Game_Temp
attr_accessor :text_to_delete
attr_accessor :text_to_add
alias theo_anytext_init initialize
def initialize
theo_anytext_init
@text_to_delete = nil
@text_to_add = nil
end
end
class Game_System
attr_writer :font_name
attr_reader :anytexts
alias theo_anytext_init initialize
def initialize
theo_anytext_init
@anytexts = {}
end
def font_name
@font_name ||= Font.default_name
end
end
class TextDTStruct
attr_accessor :key
attr_accessor :x
attr_accessor :y
attr_accessor :z
attr_accessor :width
attr_accessor :height
attr_accessor :text
attr_accessor :show
attr_accessor :color1
attr_accessor :color2
attr_accessor :font_name
def initialize(key, x, y, z, width, height, text, show, color1, color2)
@key = key
@x = x
@y = y
@z = z
@width = width
@height = height
@text = text
@show = show
@color1 = color1
@color2 = color2
@font_name = $game_system.font_name
end
end
class Anywhere_Text < Window_Base
attr_reader :key
def initialize(key,viewport)
pad = standard_padding
super(-pad,-pad,Graphics.width+pad,Graphics.height+pad)
self.viewport = viewport
self.opacity = 0
load_data(key)
draw_contents
end
def load_data(key)
@data = $game_system.anytexts[key]
@key = @key
@text = @data.text
@xpos = @data.x
@ypos = @data.y
@w = @data.width
@h = @data.height
@color1 = @data.color1
@color2 = @data.color2
self.z = @data.z
contents.font.name = @data.font_name
end
def draw_contents
rect = Rect.new(@xpos,@ypos,@w,@h)
contents.gradient_fill_rect(rect,@color1,@color2)
draw_text_ex(@xpos,@ypos,@text)
end
def update
super
update_dispose
end
def update_dispose
@data.show = [@data.show - 1,-1].max
dispose if @data.show == 0
end
end
class Text_Hash
def initialize(viewport = nil)
@viewport = viewport
@data = {}
init_used_text
end
def init_used_text
$game_system.anytexts.keys.each do |key|
add(key)
end
end
def update
update_disposed
update_delete
update_add
update_text
end
def update_disposed
@data.values.each do |text|
next unless text.disposed?
delete(text.key)
end
end
def update_delete
del_key = $game_temp.text_to_delete
unless del_key.nil?
delete(del_key)
$game_temp.text_to_delete = nil
end
end
def update_add
add_key = $game_temp.text_to_add
unless add_key.nil?
add(add_key)
$game_temp.text_to_add = nil
end
end
def update_text
@data.values.each {|text| text.update unless text.disposed?}
end
def delete(key)
text = @data.delete(key)
$game_system.anytexts.delete(key)
return unless text
text.dispose
end
def add(key)
new_text = Anywhere_Text.new(key,@viewport)
@data[key] = new_text
end
def dispose
@data.values.each {|text| text.dispose}
end
end
class Spriteset_Map
alias theo_anytext_crv create_viewports
def create_viewports
theo_anytext_crv
create_anytexts
end
def create_anytexts
@anytexts = Text_Hash.new(@viewport2)
end
alias theo_anytext_update update
def update
theo_anytext_update
update_anytexts
end
def update_anytexts
@anytexts.update
end
alias theo_anytext_dispose dispose
def dispose
theo_anytext_dispose
dispose_anytexts
end
def dispose_anytexts
@anytexts.dispose
end
end