赞 | 12 |
VIP | 107 |
好人卡 | 6 |
积分 | 4 |
经验 | 31122 |
最后登录 | 2024-6-29 |
在线时间 | 1606 小时 |
Lv2.观梦者 傻♂逼
- 梦石
- 0
- 星屑
- 374
- 在线时间
- 1606 小时
- 注册时间
- 2007-3-13
- 帖子
- 6562
|
这个效果?
- class Bitmap1 < Bitmap
- def draw_text(x, y, w, h, s)
- @cb = Bitmap.new("Graphics/system/src.png") if @cb == nil
- blt(x,y,@cb,Rect.new(s.to_i*32,0,[[w,32].min,0].max,[[h,32].min,0].max))
- end
- end
- #==============================================================================
- # ■ Window_NumberInput
- #------------------------------------------------------------------------------
- # 信息窗口内部使用、输入数值的窗口。
- #==============================================================================
- class Window_NumberInput < Window_Base
- #--------------------------------------------------------------------------
- # ● 生成窗口内容
- #--------------------------------------------------------------------------
- def create_contents
- self.contents.dispose
- self.contents = Bitmap1.new(width - 32, height - 32)
- end
- #--------------------------------------------------------------------------
- # ● 初始化对像
- # digits_max : 位数
- #--------------------------------------------------------------------------
- def initialize
- super(0, 0, 544, 64)
- @number = []
- @digits_max = 6
- @index = 0
- self.opacity = 0
- self.active = false
- self.z += 9999
- refresh
- update_cursor
- end
- #--------------------------------------------------------------------------
- # ● 取得数值
- #--------------------------------------------------------------------------
- def number
- return @number.to_s.to_i
- end
- #--------------------------------------------------------------------------
- # ● 设置数值
- # number : 新的数值
- #--------------------------------------------------------------------------
- def number=(number)
- number = number.to_s.scan(/./)
- @number = number
- for i in 0...@digits_max
- @number[i] = 0 if @number[i].to_s == ""
- end
- @index = 0
- refresh
- end
- #--------------------------------------------------------------------------
- # ● 获取位数
- #--------------------------------------------------------------------------
- def digits_max
- return @digits_max
- end
- #--------------------------------------------------------------------------
- # ● 设置位数
- # digits_max : 新位数
- #--------------------------------------------------------------------------
- def digits_max=(digits_max)
- @digits_max = digits_max
- for i in 0...digits_max
- @number[i] = 0 if @number[i].to_s == ""
- end
- refresh
- end
- #--------------------------------------------------------------------------
- # ● 光标右移
- # wrap : 允许循环
- #--------------------------------------------------------------------------
- def cursor_right(wrap)
- if @index < @digits_max - 1 or wrap
- @index = (@index + 1) % @digits_max
- end
- end
- #--------------------------------------------------------------------------
- # ● 光标左移
- # wrap : 允许循环
- #--------------------------------------------------------------------------
- def cursor_left(wrap)
- if @index > 0 or wrap
- @index = (@index + @digits_max - 1) % @digits_max
- end
- end
- #--------------------------------------------------------------------------
- # ● 更新画面
- #--------------------------------------------------------------------------
- def update
- super
- if self.active
- if Input.repeat?(Input::UP) or Input.repeat?(Input::DOWN)
- Sound.play_cursor
- n = @number[@index]
- if Input.repeat?(Input::UP)
- n = (n.to_i)+1
- n = 0 if n > 9
- end
- if Input.repeat?(Input::DOWN)
- n = (n.to_i) -1
- n = 9 if n < 0
- end
- c = @number[@index]
- @number[@index] = n
- ch_no(@index,c,n)
- refresh
- end
- last_index = @index
- if Input.repeat?(Input::RIGHT)
- cursor_right(Input.trigger?(Input::RIGHT))
- end
- if Input.repeat?(Input::LEFT)
- cursor_left(Input.trigger?(Input::LEFT))
- end
- if @index != last_index
- Sound.play_cursor
- end
- update_cursor
- end
- end
- #--------------------------------------------------------------------------
- # ● 刷新
- #--------------------------------------------------------------------------
- def refresh
- self.contents.clear
- self.contents.font.color = normal_color
- x = 0
- y = 0
- for i in @number
- self.contents.draw_text(24+x,y,32,64,i.to_s)
- x += 32
- end
- end
- def base_update
- last_index = @index
- if self.active
- if Input.repeat?(Input::RIGHT)
- cursor_right(Input.trigger?(Input::RIGHT))
- end
- if Input.repeat?(Input::LEFT)
- cursor_left(Input.trigger?(Input::LEFT))
- end
- if @index != last_index
- Sound.play_cursor
- end
- update_cursor
- end
-
- Graphics.update
- end
- #--------------------------------------------------------------------------
- # ● 刷新光标
- #--------------------------------------------------------------------------
- def update_cursor
- self.cursor_rect.set(24 + @index * 32, 0, 32, 32)
- end
- def ch_no(i,s,n)
- for ii in 1..40
- self.contents.clear_rect(24+i*32, 0, 32, 32)
- self.contents.draw_text(24+i*32,0-ii,32,32,s)
- self.contents.draw_text(24+i*32,41-ii,32,32,n)
- base_update
- end
- end
- end
复制代码 |
|