赞 | 5 |
VIP | 71 |
好人卡 | 22 |
积分 | 6 |
经验 | 32145 |
最后登录 | 2013-8-9 |
在线时间 | 184 小时 |
Lv2.观梦者 天仙
- 梦石
- 0
- 星屑
- 620
- 在线时间
- 184 小时
- 注册时间
- 2008-4-15
- 帖子
- 5023
|
- class Slider_Base < Sprite_Base
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_reader :name # 名称
- attr_reader :max # 最大值
- attr_reader :change # 改变量
- attr_reader :value # 当前值
- attr_accessor :vertical # 当前值
- attr_reader :contents
- WLH = 24
- def initialize(name, x, y, w, h = 10, max = 100, change = 1, value = 0, style = 0)
- viewport = Viewport.new(0, 0, 544, 416)
- super(viewport)
- self.bitmap = Bitmap.new(544, 416)
- self.bitmap.font.color = normal_color
- @contents = @bitmap
- setup(name, x, y, w, h, max, change, value, style)
- end
- #--------------------------------------------------------------------------
- # ● 设置 保存参数
- # name : 名称
- # x : X 坐标
- # y : Y 坐标
- # w : 宽
- # h : 高
- # max : 最大值
- # change : 改变量
- # value : 当前值
- # style : 样式
- #--------------------------------------------------------------------------
- def setup(name, x, y, w, h, max, change, value, style)
- @name = name
- @x = x
- @y = y
- @w = w
- @h = h
- @max = max
- @value = value
- @style = style
- @change = change > 0 ? change : 1
- @scale = true
- @scale_size = 12
- @color1 = Color.new(255, 255, 255, 255)
- @color2 = Color.new(192, 64, 64, 255)
- @name_color = normal_color
- @value_color = normal_color
- draw_slider(value)
- end
- def update
- end
- #--------------------------------------------------------------------------
- # ● slider颜色
- # color : 颜色
- #--------------------------------------------------------------------------
- def color(type, color)
- case type
- when "bar", 1
- @color1 = color
- when "slide", 2
- @color2 = color
- when "name", 3
- @name_color = color
- when "value", 4
- @value_color = color
- end
- draw_slider(@value)
- end
- def color1=(color)
- @color1 = color
- draw_slider(@value)
- end
- def color2=(color)
- @color2 = color
- draw_slider(@value)
- end
- def name_color=(color)
- @name_color = color
- draw_slider(@value)
- end
- def value_color=(color)
- @value_color = color
- draw_slider(@value)
- end
- #--------------------------------------------------------------------------
- # ● 更改当前值
- # value : 当前值
- #--------------------------------------------------------------------------
- def value=(value)
- @value = value
- draw_slider(value)
- end
- def scale=(yes=true)
- @scale=yes
- end
- def scale?
- return @scale
- end
- def scale_size=(size)
- @scale_size = size
- end
- #--------------------------------------------------------------------------
- # ● 绘制名称和当前值
- # value : 当前值
- #--------------------------------------------------------------------------
- def draw_name(x, y)
- # 描绘名称
- self.bitmap.font.color = @name_color
- self.bitmap.draw_text(x, y, @w, 24, @name)
- end
- def draw_value(x, y, value=@value)
- # 描绘当前值
- self.bitmap.font.color = @value_color
- self.bitmap.draw_text(x, y, 64, 24, value.to_s, 2)
- end
- def vertical=(v)
- @vertical = v
- end
- end
- class Slider_H < Slider_Base
- def initialize(name, x, y, w, h = 10, max = 100, change = 1, value = 0, style = 0)
- super(name, x, y, w, h, max, change, value, style)
- @vertical = false
- end
- #--------------------------------------------------------------------------
- # ● 描绘 slider
- # value : 当前值
- #--------------------------------------------------------------------------
- def draw_slider(value)
- case @style
- when 0
- style_0(value)
- when 1
- style_1(value)
- end
- draw_scale(@scale_size) if scale?
- end
- #--------------------------------------------------------------------------
- # ● 样式0
- # value : 当前值
- #--------------------------------------------------------------------------
- def style_0(value)
- slide_x = (@w - @h/2) * value / @max
- # 清理
- self.bitmap.clear
- # 绘制名称和当前值
- self.bitmap.font.size = 20
- draw_name(@x, @y)
- draw_value(@x+@w-64, @y, value)
- # 填充
- self.bitmap.fill_rect(@x, @y+23+@h/2, @w, 2, @color1)
- self.bitmap.fill_rect(@x+slide_x, @y+24, @h/2, @h, @color2)
- end
- #--------------------------------------------------------------------------
- # ● 样式1
- # value : 当前值
- #--------------------------------------------------------------------------
- def style_1(value)
- width = @w * value / @max
- # 清理
- self.bitmap.clear
- self.bitmap.font.size = 20
- # 绘制名称和当前值
- draw_name(@x, @y)
- draw_value(@x+@w-64, @y, value)
- # 填充
- self.bitmap.fill_rect(@x-1, @y+23, @w+2, @h+2, @color1)
- self.bitmap.fill_rect(@x, @y+24, width, @h, @color2)
- end
- #--------------------------------------------------------------------------
- # ● 绘制刻度
- # value : 当前值
- #--------------------------------------------------------------------------
- def draw_scale(size=12)
- self.bitmap.font.color= normal_color
- self.bitmap.font.size = size
-
- s1 = (bitmap.text_size(0).width)/2
- s2 = (bitmap.text_size(@max.to_s).width)/2
-
- self.bitmap.draw_text(@x-s1, @y+@h+32, @w, size, 0)
- self.bitmap.draw_text(@x, @y+@h+32, @w, size, @max/2, 1)
- self.bitmap.draw_text(@x, @y+@h+32, @w+s2, size, @max, 2)
- end
- #--------------------------------------------------------------------------
- # ● 输入刷新
- #--------------------------------------------------------------------------
- def update
- super
- if Input.repeat?(Input::RIGHT)
- if @value < @max - @change
- @value += @change
- else
- @value = @max
- end
- draw_slider(@value)
- end
- if Input.repeat?(Input::LEFT)
- if @value > @change
- @value -= @change
- else
- @value = 0
- end
- draw_slider(@value)
- end
- end
- end
- class Slider_V < Slider_Base
- def initialize(name, x, y, w, h = 10, max = 100, change = 1, value = 0, style = 1)
- super(name, x, y, w, h, max, change, value, style)
- @vertical = true
- end
- #--------------------------------------------------------------------------
- # ● 描绘 slider
- # value : 当前值
- #--------------------------------------------------------------------------
- def draw_slider(value)
- case @style
- when 0
- style_0(value)
- when 1
- style_1(value)
- end
- draw_scale(@scale_size) if scale?
- end
- #--------------------------------------------------------------------------
- # ● 样式0
- # value : 当前值
- #--------------------------------------------------------------------------
- def style_0(value)
- slide_y = (@w - @h/2) * value / @max
- # 清理
- self.bitmap.clear
- # 绘制名称和当前值
- draw_name_v(@x+24, @y, @vertical)
- draw_value(@x-24, @y+@w-WLH, value) # 填充
- # 填充
- self.bitmap.fill_rect(@x+47+@h/2, @y, 2, @w, @color1)
- self.bitmap.fill_rect(@x+49, @y+slide_y, @h, @h/2, @color2)
- end
- #--------------------------------------------------------------------------
- # ● 样式1
- # value : 当前值
- #--------------------------------------------------------------------------
- def style_1(value)
- width = @w * (@max-value) / @max
- # 清理
- self.bitmap.clear
- # 绘制名称和当前值
- draw_name(@x+24, @y, @vertical)
- draw_value(@x-24, @y+@w-WLH, value)#(@x+@w-64, @y, value) # 填充
- self.bitmap.fill_rect(@x+47, @y-1, @h+2, @w+2, @color2)
- self.bitmap.fill_rect(@x+48, @y, @h, width, @color1)
- end
- def draw_name(x, y, v=true)
- v ? draw_name_v(x, y) : super(x, y)
- end
- def draw_name_v(x, y)
- # 描绘名称
- self.bitmap.font.color = @name_color
- self.bitmap.font.size = 20
- t = @name.clone
- cy = y - WLH
- while ((c = t.slice!(/./m)) != nil)
- cy += 3 + WLH - WLH/3
- self.bitmap.draw_text(x, cy, @w, 24, c)
- end
- end
- def draw_scale(size=12)
- self.bitmap.font.color= normal_color
- self.bitmap.font.size = size
-
- s1 = (bitmap.text_size(0).width)/2
- s2 = (bitmap.text_size(@max.to_s).width)/2
-
- self.bitmap.draw_text(@x+50+@h, @y+@w-size/2, @w, size, 0)
- self.bitmap.draw_text(@x+50+@h, @y+(@w-size)/2, @w, size, @max/2)
- self.bitmap.draw_text(@x+50+@h, @y-size/2, @w+s2, size, @max)
- end
- #--------------------------------------------------------------------------
- # ● 输入刷新
- #--------------------------------------------------------------------------
- def update
- super
- if Input.repeat?(Input::UP)
- if @value < @max - @change
- @value += @change
- else
- @value = @max
- end
- draw_slider(@value)
- end
- if Input.repeat?(Input::DOWN)
- if @value > @change
- @value -= @change
- else
- @value = 0
- end
- draw_slider(@value)
- end
- end
- end
- class Sprite_Base < Sprite
- #--------------------------------------------------------------------------
- # ● 獲取文字顏色
- # n : 文字顏色色號(0-31)
- #--------------------------------------------------------------------------
- def text_color(n)
- windowskin = Cache.system("Window")
- x = 64 + (n % 8) * 8
- y = 96 + (n / 8) * 8
- return windowskin.get_pixel(x, y)
- end
- #--------------------------------------------------------------------------
- # ● 獲取一般文字顏色
- #--------------------------------------------------------------------------
- def normal_color
- return text_color(0)
- end
- #--------------------------------------------------------------------------
- # ● 獲取系統文字顏色
- #--------------------------------------------------------------------------
- def system_color
- return text_color(16)
- end
- #--------------------------------------------------------------------------
- # ● 獲取危機文字顏色
- #--------------------------------------------------------------------------
- def crisis_color
- return text_color(17)
- end
- #--------------------------------------------------------------------------
- # ● 獲取戰鬥不能文字顏色
- #--------------------------------------------------------------------------
- def knockout_color
- return text_color(18)
- end
- #--------------------------------------------------------------------------
- # ● 獲取裝備畫面能力值上升顏色
- #--------------------------------------------------------------------------
- def power_up_color
- return text_color(24)
- end
- #--------------------------------------------------------------------------
- # ● 獲取裝備畫面能力值下降顏色
- #--------------------------------------------------------------------------
- def power_down_color
- return text_color(25)
- end
- end
复制代码 |
|