限时数值输入
module SL_Settings
module SL_Input_Process
VARIABLE_ID = 10# 控制等待时间的变量,数值为0表示不限时
end
end
class Window_SL_Input_Process < Window_Base
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
def initialize(width = 128, height = 48)
super(0, 0, width, height)
@process = 0.0
@cnt = 0
self.openness = 0
deactivate
end
def process
@process
end
def process=(process)
@process = process
end
#--------------------------------------------------------------------------
# ● 开始输入的处理
#--------------------------------------------------------------------------
def start
create_contents
update_placement
open
activate
@cnt = 0
end
def update_placement
self.x = (Graphics.width - self.width) / 2
end
def refresh
rate = @cnt.to_f / ($game_variables * 60)
color1 = Color.new(0, 255, 0)
color2 = Color.new((rate * 255).to_i, ((1 - rate) * 255).to_i, 0)
_x = self.contents.rect.x
_y = self.contents.rect.y
_w = (self.contents.rect.width * rate).to_i
_h = self.contents.rect.height
self.contents.gradient_fill_rect(_x, _y, _w, _h, color1, color2)
end
def update
super
@cnt += 1 if active
@process += 1 if @cnt % 60 == 0 and active
p @process if @cnt % 60 == 0 and active
refresh if active
end
end
class Window_NumberInput < Window_Base
alias sl_input_process_orig_initialize initialize
def initialize(message_window)
sl_input_process_orig_initialize(message_window)
@sip_window = Window_SL_Input_Process.new
end
alias sl_input_process_orig_update_placement update_placement
def update_placement
sl_input_process_orig_update_placement
return if $game_variables <= 0
if @message_window.y >= Graphics.width / 2
@sip_window.y = self.y - @sip_window.height - 12
else
@sip_window.y = self.y + self.height + 12
end
end
#--------------------------------------------------------------------------
# ● 开始输入的处理(追加定义)
#--------------------------------------------------------------------------
alias sl_input_process_orig_start start
def start
sl_input_process_orig_start
return if $game_variables <= 0
@sip_window.start
end
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
alias sl_input_process_orig_upadte update
def update
sl_input_process_orig_upadte
return if $game_variables <= 0
@sip_window.update
end
#--------------------------------------------------------------------------
# ● “确定”和“取消”的处理(重定义)
#--------------------------------------------------------------------------
def process_handling
return unless active
return process_ok if Input.trigger?(:C)
return process_cancel if Input.trigger?(:B)
return if $game_variables <= 0
if @sip_window.process >= $game_variables
process_ok
end
end
alias sl_input_process_orig_process_ok process_ok
def process_ok
@sip_window.process = 0.0
@sip_window.close
@sip_window.deactivate
sl_input_process_orig_process_ok
end
end
页:
[1]