赞 | 0 |
VIP | 37 |
好人卡 | 0 |
积分 | 1 |
经验 | 48662 |
最后登录 | 2012-11-14 |
在线时间 | 3 小时 |
Lv1.梦旅人 SB們大家好<
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 3 小时
- 注册时间
- 2008-1-7
- 帖子
- 457
|
- #==============================================================================
- # ■ Window_Command2
- #------------------------------------------------------------------------------
- # 横向选择行窗口。
- #==============================================================================
- class Window_Command2 < Window_Selectable
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_reader :commands # 命令
- #--------------------------------------------------------------------------
- # ● 初始化对象
- # width : 窗口的宽
- # commands : 命令字符串序列
- # column_max : 行数 (2 行以上时选择)
- # row_max : 列数 (0:列数加起来)
- # spacing : 选项横向排列时间隔空白宽度
- #--------------------------------------------------------------------------
- def initialize(width, commands, row_max, spacing = 32)
- super(0, 0, width , row_max * WLH + 32 , spacing)
- @commands = commands
- @item_max = commands.size
- @column_max = 1
- @row_max = row_max
- @t = @item_max % page_row_max == 0 ? 0 : 1
- create_contents
- refresh
- self.index = 0
- end
- #--------------------------------------------------------------------------
- # ● 刷新
- #--------------------------------------------------------------------------
- def refresh
- self.contents.clear
- for i in 0...@item_max
- draw_item(i)
- end
- end
-
-
- #--------------------------------------------------------------------------
- # ● 窗口内容生成
- #--------------------------------------------------------------------------
- def create_contents
- self.contents.dispose
- @t = 0 if @t.nil?
- self.contents = Bitmap.new([width - 32 , (@item_max / page_row_max + @t) * width - 32].max , height - 32)
- end
- #--------------------------------------------------------------------------
- # ● 设置光标的位置
- # index : 新的光标位置
- #--------------------------------------------------------------------------
- def index=(index)
- @index = index
- update_cursor
- call_update_help
- end
- #--------------------------------------------------------------------------
- # ● 获取行数
- #--------------------------------------------------------------------------
- def row_max
- return (@item_max + @column_max - 1) / @column_max
- end
- #--------------------------------------------------------------------------
- # ● 获取开头行
- #--------------------------------------------------------------------------
- def top_row
- return self.oy / WLH
- end
- #--------------------------------------------------------------------------
- # ● 设置开头行
- # row : 显示开头的行
- #--------------------------------------------------------------------------
- def top_row=(row)
- #~ row = 0 if row < 0
- self.ox = row / page_row_max * width
- end
- #--------------------------------------------------------------------------
- # ● 获取 1 页可以显示的行数
- #--------------------------------------------------------------------------
- def page_row_max
- return (self.height - 32) / WLH
- end
- #--------------------------------------------------------------------------
- # ● 获取 1 页可以显示的项目数
- #--------------------------------------------------------------------------
- def page_item_max
- return page_row_max * @column_max
- end
- #--------------------------------------------------------------------------
- # ● 获取末尾行
- #--------------------------------------------------------------------------
- def bottom_row
- return top_row + page_row_max - 1
- end
- #--------------------------------------------------------------------------
- # ● 设置末尾行
- # row : 显示末尾的行
- #--------------------------------------------------------------------------
- def bottom_row=(row)
- self.top_row = row - (page_row_max - 1)
- end
- #--------------------------------------------------------------------------
- # ● 获取项目描画矩形
- # index : 项目编号
- #--------------------------------------------------------------------------
- def item_rect(index)
- rect = Rect.new(0, 0, 0, 0)
- rect.width = (contents.width + @spacing) / (@item_max / page_row_max + @t) - @spacing - 16
- rect.height = WLH
- rect.x = index / page_row_max * width
- rect.y = index % page_row_max * WLH
- return rect
- end
- #--------------------------------------------------------------------------
- # ● 帮助窗口的设置
- # help_window : 新的帮助窗口
- #--------------------------------------------------------------------------
- def help_window=(help_window)
- @help_window = help_window
- call_update_help
- end
- #--------------------------------------------------------------------------
- # ● 光标移动可能判定
- #--------------------------------------------------------------------------
- def cursor_movable?
- return false if (not visible or not active)
- return false if (index < 0 or index > @item_max or @item_max == 0)
- return false if (@opening or @closing)
- return true
- end
- #--------------------------------------------------------------------------
- # ● 光标下移动
- # wrap : 滚动移动许可
- #--------------------------------------------------------------------------
- def cursor_down(wrap = false)
- if wrap
- if @index % page_row_max == page_row_max - 1
- @index = @index / page_row_max
- elsif @index == @item_max - 1
- @index = @index / page_row_max * page_row_max
- else
- @index = @index + 1
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 光标上移动
- # wrap : 滚动移动许可
- #--------------------------------------------------------------------------
- def cursor_up(wrap = false)
- if wrap
- if @index % page_row_max == 0
- if @index / page_row_max != @item_max / page_row_max
- @index = page_row_max - 1
- else
- @index = @item_max - 1
- end
- else
- @index = @index - 1
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 光标右移动
- # wrap : 滚动移动许可
- #--------------------------------------------------------------------------
- def cursor_right(wrap = false)
- if wrap
- cursor_pagedown
- end
- end
- #--------------------------------------------------------------------------
- # ● 光标左移动
- # wrap : 滚动移动许可
- #--------------------------------------------------------------------------
- def cursor_left(wrap = false)
- if wrap
- cursor_pageup
- end
- end
- #--------------------------------------------------------------------------
- # ● 光标移动到1页后
- #--------------------------------------------------------------------------
- def cursor_pagedown
- if @t == 0
- if @index / page_row_max < @item_max / page_row_max - 1
- @index = @index + page_row_max > @item_max - 1? (@index / page_row_max + 1) * page_row_max : @index + page_row_max
- self.top_row += @index
- end
- else
- if @index / page_row_max < @item_max / page_row_max
- @index = @index + page_row_max > @item_max - 1? (@index / page_row_max + 1) * page_row_max : @index + page_row_max
- self.top_row += @index
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 光标移动到1页前
- #--------------------------------------------------------------------------
- def cursor_pageup
- if @index >= page_row_max
- @index -= page_row_max
- self.top_row += @index
- end
- end
- #--------------------------------------------------------------------------
- # ● 更新光标矩形
- #--------------------------------------------------------------------------
- def update_cursor
- if @index < 0 # 光标位置不满 0 的情况下
- self.cursor_rect.empty # 光标无效
- else # 光标位 0 以上的情况下
- row = @index / @column_max # 获取当前的行
- rect = item_rect(@index) # 获取选择项的矩形
- rect.y -= self.oy # 矩形滚动的位置加起来
- rect.x = 0
- self.cursor_rect = rect # 更新光标矩形
- end
- end
-
- #--------------------------------------------------------------------------
- # ● 描绘项目
- # index : 项目编号
- # enabled : 有效标记录。是false 的时候半透明绘画
- #--------------------------------------------------------------------------
- def draw_item(index, enabled = true)
- rect = item_rect(index)
- rect.x += 4
- rect.width -= 8
- self.contents.clear_rect(rect)
- self.contents.font.color = normal_color
- self.contents.font.color.alpha = enabled ? 255 : 128
- self.contents.draw_text(rect, @commands[index])
- end
- end
复制代码
横向选择菜单
@command_window = Window_Command2.new(174, [s1,s2] ,1)
参数分别是 宽度,命令数组,每页的行数
写得仓促 很多无意义东西没有删掉
若有bug我会尽快修正.
|
|