-
Notifications
You must be signed in to change notification settings - Fork 12
/
VX Style Choice.rb
185 lines (154 loc) · 4.71 KB
/
VX Style Choice.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
# =============================================================================
# TheoAllen - VX Style Choices
# Version : 1.1
# Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
# (English Documentation)
# =============================================================================
($imported ||= {})[:Theo_VXStyleChoices] = true
# =============================================================================
# Change Logs :
# -----------------------------------------------------------------------------
# 2013.11.14 - Compatibility patch with my choice help
# - Bugfix. Face graphic erased when clearing message box
# 2013.10.14 - Bugfix. Choice isn't displayed if it isn't followed by texts
# 2013.10.12 - Finished script
# =============================================================================
=begin
Introduction :
This script allow you to display choices as VX has
How to use :
Put this script below material but above main
Use these script calls to activate VX style choice
vx_choice(true) << to activate
vx_choice(false) << to deacitave
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
# =============================================================================
# No configuration. Just dont edit below this line
# =============================================================================
class Game_Interpreter
def vx_choice(bool)
$game_message.vx_choice = bool
end
end
class Game_Message
attr_accessor :vx_choice
alias theo_vxchoice_init initialize
def initialize
theo_vxchoice_init
@vx_choice = true
end
end
class Window_Message < Window_Base
alias theo_vxchoice_init initialize
def initialize
theo_vxchoice_init
init_vxchoice_member
end
def init_vxchoice_member
@need_clear = false
@choice_index = 0
@choice_y = 0
end
alias theo_vxchoice_input input_choice
def input_choice
return start_vx_choice if $game_message.vx_choice
return theo_vxchoice_input
end
alias theo_vxchoice_new_page new_page
def new_page(text, pos)
theo_vxchoice_new_page(text, pos)
@need_clear = ($game_message.texts.size + $game_message.choices.size) >
visible_line_number
end
alias theo_vxchoice_new_line process_new_line
def process_new_line(text, pos)
theo_vxchoice_new_line(text, pos)
@choice_y = pos[:y]
end
def start_vx_choice
open_and_wait unless open?
if @need_clear
input_need_clear
end
@choice_index = 0
ypos = 0
$game_message.choices.each do |choice|
draw_text_ex(new_line_x + padding_x, @choice_y + ypos, choice)
ypos += line_height
end
update_vx_choice(@choice_y)
end
def padding_x
return 16
end
def input_need_clear
input_pause
contents.clear
draw_face($game_message.face_name, $game_message.face_index, 0, 0)
@choice_y = 0
@need_clear = false
end
def update_vx_choice(ypos)
rect_width = contents.width - new_line_x - rface
cursor_rect.set(new_line_x, ypos, rect_width, line_height)
if choice_help?
@choice_help.open
update_choice_help
end
wait(10)
until Input.trigger?(:C) || (Input.trigger?(:B) && cancel_enabled?)
update_choice_cursor
Fiber.yield
end
cursor_rect.empty
execute_choice
Input.update
end
def rface
($imported[:Theo_RightSideFace] && !$game_message.face_name.empty? &&
$game_message.rface) ? 100 : 0
end
def cancel_enabled?
$game_message.choice_cancel_type > 0
end
def update_choice_cursor
cursor_rect.y = @choice_y + @choice_index * line_height
change_choice_index(1) if Input.repeat?(:DOWN)
change_choice_index(-1) if Input.repeat?(:UP)
end
def change_choice_index(amount)
Sound.play_cursor
@choice_index += amount
wrap_index
update_choice_help if choice_help?
end
def wrap_index
@choice_index = 0 if @choice_index > $game_message.choices.size - 1
@choice_index = $game_message.choices.size - 1 if @choice_index < 0
end
def execute_choice
call_ok_handler if Input.trigger?(:C)
call_cancel_handler if Input.trigger?(:B)
if choice_help?
@choice_help.close
end
end
def choice_help?
$imported[:Theo_ChoiceHelp]
end
def update_choice_help
@choice_help.set_text($game_message.choice_helps[@choice_index])
end
def call_ok_handler
Sound.play_ok
$game_message.choice_proc.call(@choice_index)
end
def call_cancel_handler
Sound.play_cancel
$game_message.choice_proc.call($game_message.choice_cancel_type - 1)
end
end