-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathNotification Window (ENG).rb
239 lines (208 loc) · 7.29 KB
/
Notification Window (ENG).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
#==============================================================================
# TheoAllen - Notification Window
# Version : 1.0
# Language : English
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Contact :
#------------------------------------------------------------------------------
# *> http://www.rpgmakervxace.net
# *> http://www.theolized.com
#==============================================================================
($imported ||= {})[:Theo_NotifWindow] = true
#==============================================================================
# Change Logs:
# -----------------------------------------------------------------------------
# 2015.02.09 - Translated to english + import the basic module
# 2013.09.22 - Finished
#==============================================================================
=begin
==================
|| Introduction ||
------------------
This script give you an alternative to display a notification instead of
showed up using show text. Notification will be displayed on the top-left
corner with typing effect
======================
|| How to use ||
----------------------
Put this script below material but above main
To show notification, use this script call
add_notif("Your notification text")
===================
|| Terms of use ||
-------------------
Credit me, TheoAllen. You are free to edit this script by your own. As long
as you don't claim it yours. For commercial purpose, don't forget to give me
a free copy of the game.
=end
#==============================================================================
# Configurations
#==============================================================================
module Theo
module Notif
#=============================================#
# Timing (where 60 frame equal as 1 second) ~ #
#=============================================#
StartFadein = 15 # Frame required to show the notification window
DelayTime = 120 # Time wait before the next notification
EndFadeout = 15 # Frame required to hide the notification
#=============================================#
# Window color in (red, green, blue, alpha) ~ #
#=============================================#
ColorStart = Color.new(0,0,0,180) # From left
ColorEnd = Color.new(0,0,0,50) # To right
#=============================================#
# Position (smaller value means get on top) ~ #
#=============================================#
XPosition = -6
end
end
#==============================================================================
# Do not touch pass this line
#==============================================================================
#------------------------------------------------------------------------------
# Importing fuction from basic module because people hate to include scripter's
# basic module :v
#------------------------------------------------------------------------------
module THEO
module FADE
# Default duration of fading
DEFAULT_DURATION = 60
# -------------------------------------------------------------------------
# *) Init core fade instance variables
# -------------------------------------------------------------------------
def init_fade_members
@obj = nil
@target_opacity = -1
@fade_speed = 0.0
@pseudo_opacity = 0
end
# -------------------------------------------------------------------------
# *) Set object
# -------------------------------------------------------------------------
def setfade_obj(obj)
@obj = obj
@pseudo_opacity = @obj.opacity
end
# -------------------------------------------------------------------------
# *) Fade function
# -------------------------------------------------------------------------
def fade(opacity, duration = DEFAULT_DURATION)
@target_opacity = opacity
make_fade_speed(duration)
end
# -------------------------------------------------------------------------
# *) Determine fade speed
# -------------------------------------------------------------------------
def make_fade_speed(duration)
@fade_speed = (@target_opacity - @obj.opacity)/duration.to_f
@pseudo_opacity = @obj.opacity.to_f
end
# -------------------------------------------------------------------------
# *) Fadeout function
# -------------------------------------------------------------------------
def fadeout(duration = DEFAULT_DURATION)
fade(0, duration)
end
# -------------------------------------------------------------------------
# *) Fadein function
# -------------------------------------------------------------------------
def fadein(duration = DEFAULT_DURATION)
fade(255, duration)
end
# -------------------------------------------------------------------------
# *) Update fade
# -------------------------------------------------------------------------
def update_fade
if fade?
@pseudo_opacity += @fade_speed
@obj.opacity = @pseudo_opacity
else
@target_opacity = -1
end
end
# -------------------------------------------------------------------------
# *) Is performing fade?
# -------------------------------------------------------------------------
def fade?
return false if @target_opacity == -1
@target_opacity != @pseudo_opacity.round
end
end
end
#------------------------------------------------------------------------------
# End of import
#------------------------------------------------------------------------------
class Game_Interpreter
def add_notif(text)
$game_temp.stack_notif << text
end
end
class Game_Temp
attr_reader :stack_notif
alias theo_typenotif_init initialize
def initialize
theo_typenotif_init
@stack_notif ||= []
end
end
class Window_TypingNotif < Window_Base
class Opacity_Fade
attr_accessor :opacity
include THEO::FADE
def initialize
@opacity = 0
init_fade_members
setfade_obj(self)
end
end
Color1 = Theo::Notif::ColorStart
Color2 = Theo::Notif::ColorEnd
def initialize
super(-12,Theo::Notif::XPosition,Graphics.width+24,fitting_height(1))
@ref = Opacity_Fade.new
refresh
self.contents_opacity = @ref.opacity
self.opacity = 0
end
def refresh
contents.clear
contents.gradient_fill_rect(contents.rect, Color1, Color2)
end
def update
super
@ref.update_fade
self.contents_opacity = @ref.opacity
if @fiber.nil? && !$game_temp.stack_notif.empty?
@fiber = Fiber.new { update_notif_fiber }
elsif @fiber
@fiber.resume
end
end
def update_notif_fiber
refresh
@ref.fadein(Theo::Notif::StartFadein)
Fiber.yield while @ref.fade?
loop do
notif = $game_temp.stack_notif.shift
refresh
draw_text_ex(4 + 12,0,notif)
Theo::Notif::DelayTime.times { Fiber.yield }
break if $game_temp.stack_notif.empty?
end
@ref.fadeout(Theo::Notif::EndFadeout)
Fiber.yield while @ref.fade?
@fiber = nil
end
def process_character(*args)
super(*args)
Fiber.yield
end
end
class Scene_Map
alias theo_typenotif_start start
def start
theo_typenotif_start
@notif_text = Window_TypingNotif.new
end
end