加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 taroxd 于 2014-10-4 17:38 编辑
#-------------------------------------------------------------------------- # ● 数值输入处理可以输入负数 #-------------------------------------------------------------------------- module Taroxd NegativeInput = Object.new end class Window_NumberInput < Window_Base #-------------------------------------------------------------------------- # ● 开始输入的处理 #-------------------------------------------------------------------------- def start @digits_max = $game_message.num_input_digits_max + 1 num = $game_variables[$game_message.num_input_variable_id] max_num = 10**(@digits_max - 1) - 1 num = [[num, max_num].min, -max_num].max @number = sprintf("%+0*d", @digits_max, num) @index = 0 update_placement create_contents refresh open activate end #-------------------------------------------------------------------------- # ● 处理数字的更改 #-------------------------------------------------------------------------- def process_digit_change return unless active if Input.repeat?(:UP) || Input.repeat?(:DOWN) Sound.play_cursor if @index == 0 @number[0] = @number.start_with?('+') ? '-' : '+' else n = @number[@index].to_i @number[@index] = ((n + (Input.repeat?(:UP) ? 1 : -1)) % 10).to_s end refresh end end #-------------------------------------------------------------------------- # ● 刷新 #-------------------------------------------------------------------------- def refresh contents.clear change_color(normal_color) @digits_max.times do |i| rect = item_rect(i) rect.x += 1 draw_text(rect, @number[i], 1) end end #-------------------------------------------------------------------------- # ● 按下确定键时的处理 #-------------------------------------------------------------------------- def process_ok Sound.play_ok $game_variables[$game_message.num_input_variable_id] = @number.to_i deactivate close end end
#--------------------------------------------------------------------------
# ● 数值输入处理可以输入负数
#--------------------------------------------------------------------------
module Taroxd
NegativeInput = Object.new
end
class Window_NumberInput < Window_Base
#--------------------------------------------------------------------------
# ● 开始输入的处理
#--------------------------------------------------------------------------
def start
@digits_max = $game_message.num_input_digits_max + 1
num = $game_variables[$game_message.num_input_variable_id]
max_num = 10**(@digits_max - 1) - 1
num = [[num, max_num].min, -max_num].max
@number = sprintf("%+0*d", @digits_max, num)
@index = 0
update_placement
create_contents
refresh
open
activate
end
#--------------------------------------------------------------------------
# ● 处理数字的更改
#--------------------------------------------------------------------------
def process_digit_change
return unless active
if Input.repeat?(:UP) || Input.repeat?(:DOWN)
Sound.play_cursor
if @index == 0
@number[0] = @number.start_with?('+') ? '-' : '+'
else
n = @number[@index].to_i
@number[@index] = ((n + (Input.repeat?(:UP) ? 1 : -1)) % 10).to_s
end
refresh
end
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
contents.clear
change_color(normal_color)
@digits_max.times do |i|
rect = item_rect(i)
rect.x += 1
draw_text(rect, @number[i], 1)
end
end
#--------------------------------------------------------------------------
# ● 按下确定键时的处理
#--------------------------------------------------------------------------
def process_ok
Sound.play_ok
$game_variables[$game_message.num_input_variable_id] = @number.to_i
deactivate
close
end
end
|