查看: 2273|回复: 0

[RMVA发布] 「数值输入处理」输入负数

[复制链接]

…あたしは天

梦石
0
星屑
2311
在线时间
4033 小时
注册时间
2010-10-4
回帖
10548

开拓者贵宾

发表于 2014-7-7 09:01:02 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 taroxd 于 2014-10-4 17:38 编辑

  1. #--------------------------------------------------------------------------
  2. # ● 数值输入处理可以输入负数
  3. #--------------------------------------------------------------------------

  4. module Taroxd
  5.   NegativeInput = Object.new
  6. end

  7. class Window_NumberInput < Window_Base
  8.   #--------------------------------------------------------------------------
  9.   # ● 开始输入的处理
  10.   #--------------------------------------------------------------------------
  11.   def start
  12.     @digits_max = $game_message.num_input_digits_max + 1
  13.     num = $game_variables[$game_message.num_input_variable_id]
  14.     max_num = 10**(@digits_max - 1) - 1
  15.     num = [[num, max_num].min, -max_num].max
  16.     @number = sprintf("%+0*d", @digits_max, num)
  17.     @index = 0
  18.     update_placement
  19.     create_contents
  20.     refresh
  21.     open
  22.     activate
  23.   end
  24.   #--------------------------------------------------------------------------
  25.   # ● 处理数字的更改
  26.   #--------------------------------------------------------------------------
  27.   def process_digit_change
  28.     return unless active
  29.     if Input.repeat?(:UP) || Input.repeat?(:DOWN)
  30.       Sound.play_cursor
  31.       if @index == 0
  32.         @number[0] = @number.start_with?('+') ? '-' : '+'
  33.       else
  34.         n = @number[@index].to_i
  35.         @number[@index] = ((n + (Input.repeat?(:UP) ? 1 : -1)) % 10).to_s
  36.       end
  37.       refresh
  38.     end
  39.   end
  40.   #--------------------------------------------------------------------------
  41.   # ● 刷新
  42.   #--------------------------------------------------------------------------
  43.   def refresh
  44.     contents.clear
  45.     change_color(normal_color)
  46.     @digits_max.times do |i|
  47.       rect = item_rect(i)
  48.       rect.x += 1
  49.       draw_text(rect, @number[i], 1)
  50.     end
  51.   end
  52.   #--------------------------------------------------------------------------
  53.   # ● 按下确定键时的处理
  54.   #--------------------------------------------------------------------------
  55.   def process_ok
  56.     Sound.play_ok
  57.     $game_variables[$game_message.num_input_variable_id] = @number.to_i
  58.     deactivate
  59.     close
  60.   end
  61. end
复制代码

评分

参与人数 1星屑 +1 收起 理由
3106345123 + 1 塞糖

查看全部评分

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部