-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRS_CustomWindow.rb
144 lines (142 loc) · 4.83 KB
/
RS_CustomWindow.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
#================================================================
# The MIT License
# Copyright (c) 2020 biud436
# ---------------------------------------------------------------
# Free for commercial and non commercial use.
#================================================================
#===============================================================================
# Name : Custom Window (Ruby) - RPG Maker VX Ace
# Author : biud436
# Date : 2017.03.21
# Introduction : This script allows you to create the custom window in the map
# Usage :
# In the event editor, you can use the script command, then use this method.
# ------------------------------------------------------------------------------
# create_custom_window(x, y, width, height, text, auto_dispose)
# ------------------------------------------------------------------------------
# x : x is the same as x-position of the custom window
# y : y is the same as x-position of the custom window
# width : width is the same as a maximum width of the custom window
# height : height is the same as a maximum height of the custom window
# text : text is you can write the string as you want to indicate into the
# screen, can use the text code.
# auto_dispose : auto_dispose is you can set whether the window automatically
# ends up when pressing a decision key.
# ------------------------------------------------------------------------------
# remove_custom_window(uid)
# ------------------------------------------------------------------------------
# If you want to remove already created custom window, you can try this.
# Notice that there is one important parameter.
# uid - when calling 'create_custom_window' method, it returns the variable
# named 'uid'. So getting variable 'uid' there is two ways :
# - the way that uses the method called 'create_custom_window'
# - the way that uses a global variable called '$game_map.uid'
#===============================================================================
# The update Logs
#===============================================================================
# 2017.03.25 (v1.0.1) - Fixed an issue that didn't remove existing window.
# 2017.03.26 (v1.0.2) - Added the remove function for all custom windows
$imported = {} if $imported.nil?
$imported["RS_CustomWindow"] = true
class Window_CustomText < Window_Base
def initialize(*args)
super(*args[0..3])
@rect = args[0..3]
@texts = args[4] || ''
@auto_dispose = args[5] || false
refresh
end
def auto_dispose?
return @auto_dispose
end
def refresh
draw_text_ex(0, 0, @texts)
end
end
class Game_Map
attr_accessor :custom_windows
attr_accessor :uid
alias xxxx_initialize initialize
def initialize
xxxx_initialize
@custom_windows = {}
@uid = 0
end
end
class Game_Interpreter
def create_custom_window(*args)
SceneManager.scene.create_custom_window(*args)
end
def remove_custom_window(uid)
SceneManager.scene.remove_custom_window(uid)
end
def remove_all_custom_windows
SceneManager.scene.remove_all_custom_windows
end
end
class Scene_Map < Scene_Base
alias xxxx_start start
def start
xxxx_start
@custom_windows = {}
@custom_window_dirty = false
@disposing_windows = []
restore_custom_windows
end
alias xxxx_update update
def update
xxxx_update
if not @custom_window_dirty
@custom_windows.keys.each do |key|
if @custom_windows[key].is_a?(Window_Base)
@custom_windows[key].update
@disposing_windows.push(->(){
if @custom_windows[key].auto_dispose? && Input.trigger?(:C)
@custom_windows.delete(key)
$game_map.custom_windows.delete(key)
end
})
end
end
@disposing_windows.each {|i| i.call if i.is_a?(Proc)}
@disposing_windows.clear
end
end
alias xxxx_terminate terminate
def terminate
xxxx_terminate
remove_all_custom_windows
end
def restore_custom_windows
return unless $game_map.custom_windows.is_a?(Hash)
$game_map.custom_windows.values.each do |args|
create_custom_window(*args)
end
end
def create_custom_window(*args)
uid = ($game_map.uid += 1)
$game_map.custom_windows[uid] = args
new_window = Window_CustomText.new(*args)
@custom_windows[uid] = new_window
@custom_window_dirty = false
uid
end
def remove_custom_window(uid)
return false unless @disposing_windows.is_a?(Array)
return false unless @custom_windows.is_a?(Hash)
if @custom_windows[uid].is_a?(Window_Base)
@custom_windows[uid].visible = false
@custom_windows.delete(uid)
$game_map.custom_windows.delete(uid)
end
end
def remove_all_custom_windows
@custom_window_dirty = true
if @custom_windows.is_a?(Hash)
@custom_windows.values.each do |window|
window.visible = false
window.dispose if window.is_a?(Window_Base)
end
end
end
end