设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 2417|回复: 0
打印 上一主题 下一主题

[原创发布] [更新:鼠标支持]子选项窗口

[复制链接]

Lv1.梦旅人

梦石
0
星屑
55
在线时间
323 小时
注册时间
2010-8-21
帖子
666
跳转到指定楼层
1
发表于 2011-4-16 14:53:45 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 沙漠点灰 于 2011-5-1 17:42 编辑


1L普通版  2L鼠标版






本脚本更新(呵呵,没有TJ),较上个版本(0.91)更新如下:
1.代码简化,去除Bug
2.支持多选项打开(上个版本只能把一个打开到底)
3.用左右键执行上面(2)的功能[即:左键 退到上个选项层 右键 进入下个选项层]
4.会自动在末尾追加一层"-----------" (占位置)
效果如下,范例照旧稍后放出(http://rpg.blue/thread-175789-1-1.html就是截图..):


代码如下:
  1. #______________________________________________________________________________
  2. # * 此脚本归66RPG - Idiot Script Association(ISA)所有,谢绝任何形式转载。
  3. #______________________________________________________________________________

  4. #==============================================================================
  5. # ■ 子选项 - Sub-option
  6. #------------------------------------------------------------------------------
  7. #   遵守协议:66RPG - Idiot Script Association(ISA)
  8. #   当前版本:0.9.5.0
  9. #------------------------------------------------------------------------------
  10. #   更新日记:沙漠.灰(2011.4.2)
  11. #             - 初始化
  12. #             沙漠.灰(2011.4.16)
  13. #             - 0.95版放出
  14. #==============================================================================

  15. #--------------------------------------------------------------------------
  16. # ● 资料记录
  17. #--------------------------------------------------------------------------

  18. module ISA
  19.    Use["子选项"] = [true, "0.9.5.0"]
  20. end

  21. #==============================================================================
  22. # ■ Window_Folder
  23. #------------------------------------------------------------------------------
  24. #  拥有光标的移动以及滚动功能、子项目的窗口类。
  25. #==============================================================================

  26. class Window_Folder < Window_Base
  27.   #--------------------------------------------------------------------------
  28.   # ● 定义实例变量
  29.   #--------------------------------------------------------------------------
  30.   attr_reader   :index                    # 光标位置
  31.   attr_reader   :c
  32.   #--------------------------------------------------------------------------
  33.   # ● 初始画对像
  34.   #     x      : 窗口的 X 坐标
  35.   #     y      : 窗口的 Y 坐标
  36.   #     width  : 窗口的宽
  37.   #     height : 窗口的高
  38.   #--------------------------------------------------------------------------
  39.   def initialize(x,y,width, height, commands)
  40.     super(x, y, width, height)
  41.     commands += ["-"*(width/11)]
  42.     # 初始化数据
  43.     @move_to        = 0
  44.     @to_refresh     = false
  45.     @commands_size  = 0
  46.     @c              = false
  47.     @index          = [0]
  48.     @spread_command = []
  49.     @disable_item   = []
  50.     commands.size.times{@spread_command.push(1)}
  51.     @true_commands  = commands
  52.     @object_id = 0
  53.     # 生成位图
  54.     self.contents = Bitmap.new(width - 32, @true_commands.self_all_plus * 32-32)
  55.     @v = Viewport.new(16+self.x, 16+self.y, width-32, height-32) ; @v.z = 999
  56.     @new_bitmap = Sprite.new(@v)
  57.     @new_bitmap.bitmap = Bitmap.new(width - 32, @true_commands.self_all_plus * 32-32)
  58.     index = 0 # 描绘顶层项目
  59.     # 描绘父项目
  60.     for unit in @true_commands
  61.       draw_command [index]
  62.       index += 1
  63.     end
  64.   end
  65.   #--------------------------------------------------------------------------
  66.   # ● 项目无效化 index : 项目编号
  67.   #--------------------------------------------------------------------------
  68.   def disable_item(index)
  69.     @disable_item.push(index)
  70.   end
  71.   #--------------------------------------------------------------------------
  72.   # ● 指定项目是否为父项目 index 所在位置
  73.   #--------------------------------------------------------------------------
  74.   def is_folder?(commands,index)
  75.     # 若指定项目为数组且子单元数目大于1就判定为父项目
  76.     if index.size == 1 and commands[index[0]].is_a?(Array)
  77.       return true if commands[index[0]].size > 1
  78.     elsif index.size > 1
  79.       return is_folder?(commands[index[0]],index[1...index.size])
  80.     end
  81.     false
  82.   end
  83.   #--------------------------------------------------------------------------
  84.   # ● 描绘项目名称 index 所在位置  branch 是否分支
  85.   #--------------------------------------------------------------------------
  86.   def draw_command(index,branch=false)
  87.     x, y = check_index_xy(index)
  88.     rect = Rect.new(x+32,y,self.width-32,32)
  89.     self.contents.font.color = disabled_color if @disable_item.include?(index)
  90.     name = get_command(@true_commands,index)
  91.     self.contents.draw_text(rect, name)
  92.     # 为父项目时,描绘指引
  93.     draw_flag(index,branch) if is_folder?(@true_commands,index)
  94.     self.contents.font.color = normal_color
  95.   end
  96.   #--------------------------------------------------------------------------
  97.   # ● 取得项目名称 index 所在位置
  98.   #--------------------------------------------------------------------------
  99.   def get_command(name_array,index)
  100.     return get_command_name(name_array[index[0]]) if index.size == 1
  101.     get_command name_array[index[0]],index[1...index.size]
  102.   end
  103.   #--------------------------------------------------------------------------
  104.   # ● 再次 取得项目名称 index 所在位置
  105.   #--------------------------------------------------------------------------
  106.   def get_command_name(name_array)
  107.     name_array.is_a?(String) ? name_array : name_array[0].is_a?(Array) ?  get_command_name(name_array[0]) : name_array[0]
  108.   end
  109.   #--------------------------------------------------------------------------
  110.   # ● 描绘项目标记 index 所在位置
  111.   #--------------------------------------------------------------------------
  112.   def draw_flag(index,branch=false)
  113.     x, y = check_index_xy index
  114.     src_rect  = Rect.new(x+16,y+10,16,16)
  115.     self.contents.fill_rect(src_rect, Color.new(0,0,0,0))
  116.     dest_rect = branch ? Rect.new(152, 40, 16, 16): Rect.new(168, 24, 16, 16)
  117.     src_bitmap= RPG::Cache.windowskin($game_system.windowskin_name)
  118.     self.contents.stretch_blt(src_rect, src_bitmap, dest_rect)
  119.   end
  120.   #--------------------------------------------------------------------------
  121.   # ● 检查 index 所在坐标
  122.   #--------------------------------------------------------------------------
  123.   def check_index_xy(index)
  124.     # 反复迭代,直到index最后一位
  125.     str = "["
  126.     if index[0] > 0
  127.       for i in 0...index[0]
  128.         str += @spread_command[i].true_to_s + "," rescue str += "1,"
  129.       end
  130.     end
  131.     if @spread_command[index[0]].is_a?(Array) and index.size > 1
  132.       str += check_spread(@spread_command[index[0]],index[1...index.size]) + ","
  133.     end
  134.     [index.size * 32 - 32, eval(str += "]").self_all_plus * 32]
  135.   end
  136.   #--------------------------------------------------------------------------
  137.   # ● 检查展开项目,返回项目数
  138.   #--------------------------------------------------------------------------
  139.   def check_spread(array,index)
  140.     str = "["
  141.     if index[0] > 0
  142.       for i in 0...index[0]
  143.         str += array[i].true_to_s + "," rescue str += "1,"
  144.       end
  145.     end
  146.     if array[index[0]].is_a?(Array) and index.size > 1
  147.       str += check_spread(array[index[0]],index[1...index.size]) + ","
  148.     end
  149.     str += "]"
  150.   end
  151.   #--------------------------------------------------------------------------
  152.   # ● 释放
  153.   #--------------------------------------------------------------------------
  154.   def dispose
  155.     @new_bitmap.bitmap.dispose
  156.     @new_bitmap.dispose
  157.     @v.dispose
  158.     super
  159.   end
  160.   #--------------------------------------------------------------------------
  161.   # ● 设置光标的位置
  162.   #--------------------------------------------------------------------------
  163.   def index=(index)
  164.     @index = index
  165.     update_cursor_rect
  166.   end
  167.   #--------------------------------------------------------------------------
  168.   # ● 检查指定项目大小 index :
  169.   #--------------------------------------------------------------------------
  170.   def check_command_size(index,commands=@true_commands)
  171.     return commands.size if index.size == 1
  172.     check_command_size(index[1...index.size],commands[index[0]])
  173.   end
  174.   #--------------------------------------------------------------------------
  175.   # ● 关闭展开父选项
  176.   #--------------------------------------------------------------------------
  177.   def folder(index,close=true)
  178.     if close
  179.       return if index.size == 1 if closed?(index)
  180.       return folder(index[0...index-1],close) if closed?(index)
  181.       x1, y1 = check_index_xy(index)
  182.       Graphics.freeze
  183.       temp = @spread_command.self_all_plus
  184.       eval("@spread_command#{@index.new_to_s} = 1 ")
  185.       new_height = ((@spread_command.self_all_plus - temp).abs + 1) * 32
  186.       src_rect      = Rect.new(0,0,self.width,self.contents.height)
  187.       dest_rect     = Rect.new(0,y1+new_height,self.width,self.contents.height)
  188.       @new_bitmap.bitmap.stretch_blt(src_rect, self.contents, dest_rect)
  189.       src_rect  = Rect.new(0,y1,self.width,self.contents.height)
  190.       self.contents.fill_rect(src_rect, Color.new(0,0,0,0))
  191.       @new_bitmap.y= y1 + new_height
  192.       @move_to     = -new_height + 32
  193.       @to_refresh  = -1
  194.       draw_command(@index,false)
  195.       Graphics.transition(10)
  196.     else
  197.       return if !is_folder?(@true_commands,index)
  198.       return @index.push(1) if !closed?(index)
  199.       new_height = check_command_size(index+[0]) * 32 - 32
  200.       x1, y1 = check_index_xy(index+[0])
  201.       @new_bitmap.bitmap.clear
  202.       @new_bitmap.y = y1 + 32
  203.       src_rect      = Rect.new(0 ,0    ,self.width,self.contents.height)
  204.       dest_rect     = Rect.new(0,y1+32,self.width,self.contents.height)
  205.       @new_bitmap.bitmap.stretch_blt(src_rect, self.contents, dest_rect)
  206.       src_rect  = Rect.new(0,y1,self.width,self.contents.height)
  207.       self.contents.fill_rect(src_rect, Color.new(0,0,0,0))
  208.       @move_to     = new_height
  209.       @to_refresh  = 1
  210.       draw_command(@index,true)
  211.       size = "1," * check_command_size(@index+[0])
  212.       eval("@spread_command#{@index.new_to_s} = [#{size}] ")
  213.     end
  214.   end
  215.   #--------------------------------------------------------------------------
  216.   # ● 移动项目
  217.   #--------------------------------------------------------------------------
  218.   def move_command
  219.     if @move_to == 0 and @to_refresh != 0
  220.       if @to_refresh == 1
  221.         @to_refresh = 0
  222.         for i in 1...check_command_size(@index+[0])
  223.           draw_command(@index+[i])
  224.         end
  225.         Graphics.freeze
  226.         src_rect  = Rect.new(@new_bitmap.x,@new_bitmap.y,self.width,self.contents.height)
  227.         dest_rect = Rect.new(0,0,self.width,self.contents.height)
  228.         self.contents.stretch_blt(src_rect, @new_bitmap.bitmap, dest_rect)
  229.         @new_bitmap.bitmap.clear
  230.         Graphics.transition(10)
  231.          @index << 1
  232.       else
  233.         @to_refresh = 0
  234.         src_rect  = Rect.new(@new_bitmap.x,@new_bitmap.y,self.width,self.contents.height)
  235.         dest_rect = Rect.new(0,0,self.width,self.contents.height)
  236.         self.contents.stretch_blt(src_rect, @new_bitmap.bitmap, dest_rect)
  237.         @new_bitmap.bitmap.clear
  238.       end
  239.     end
  240.     return if @move_to == 0
  241.     step = @move_to/@move_to.abs * 4
  242.     @move_to -= step
  243.     @new_bitmap.y += step
  244.   end
  245.   #--------------------------------------------------------------------------
  246.   # ● 父选项已关闭? @spread_command
  247.   #--------------------------------------------------------------------------
  248.   def closed?(index,commands=@spread_command)
  249.     return true if !commands[index[0]].is_a?(Array)
  250.     return closed?(index[1...index.size],commands[index[0]]) if index.size > 1
  251.     false
  252.   end
  253.   #--------------------------------------------------------------------------
  254.   # ● 刷新画面
  255.   #--------------------------------------------------------------------------
  256.   def update
  257.     super
  258.     move_command
  259.     return if @to_refresh != 0
  260.     if self.active
  261.       # 方向键下被按下的情况下
  262.       if Input.repeat?(Input::DOWN)
  263.         $game_system.se_play($data_system.cursor_se)
  264.         @index[-1] = (@index[-1]+1)%check_command_size(@index)
  265.         @index[-1] += 1 if @index.size > 1 and @index[-1] == 0
  266.         @index = [0] if @index == [@true_commands.size-1]
  267.       end
  268.       # 方向键上被按下的情况下
  269.       if Input.repeat?(Input::UP)
  270.         $game_system.se_play($data_system.cursor_se)
  271.         @index[-1] -= 1 if @index.size > 1 and @index[-1] == 1
  272.         @index[-1] -= 1 if @index == [0]
  273.         @index[-1] = (@index[-1]-1)%check_command_size(@index)
  274.       end
  275.       # 方向键左被按下的情况下
  276.       if Input.trigger?(Input::LEFT)
  277.         if @index.size == 1
  278.           $game_system.se_play($data_system.buzzer_se)
  279.         else
  280.           @index.pop
  281.           $game_system.se_play($data_system.cancel_se)
  282.         end
  283.       end
  284.       # 方向键右被按下的情况下
  285.       if Input.trigger?(Input::RIGHT)
  286.         if is_folder?(@true_commands,@index)
  287.           $game_system.se_play($data_system.decision_se)
  288.           folder(@index,false)
  289.         end
  290.       end
  291.       # B键被按下的情况下
  292.       if Input.trigger?(Input::B)
  293.         if @index.size == 1
  294.           $game_system.se_play($data_system.buzzer_se)
  295.         else
  296.           @index.pop
  297.           $game_system.se_play($data_system.cancel_se)
  298.           folder(@index)
  299.         end
  300.       end
  301.       # C键被按下的情况下
  302.       if Input.trigger?(Input::C)
  303.         @c = !is_folder?(@true_commands,@index)
  304.         if is_folder?(@true_commands,@index)
  305.           $game_system.se_play($data_system.decision_se)
  306.           folder(@index,false)
  307.         end
  308.       end
  309.     end
  310.     update_cursor_rect
  311.   end
  312.   #--------------------------------------------------------------------------
  313.   # ● 更新光标矩形
  314.   #--------------------------------------------------------------------------
  315.   def update_cursor_rect
  316.     x, y = check_index_xy(@index)
  317.     if y - self.oy >= self.height - 32
  318.       self.oy        += 32
  319.       @new_bitmap.oy += 32
  320.     elsif y - self.oy < 0
  321.       self.oy        -= 32
  322.       @new_bitmap.oy -= 32
  323.     end
  324.     self.cursor_rect.set(x, y-self.oy, [email protected]_to_s.size/3*32, 32)
  325.   end
  326. end
  327. #==============================================================================
  328. # ■ Array
  329. #------------------------------------------------------------------------------
  330. #  数组类  又拿数组开刀...
  331. #==============================================================================

  332. class Array
  333.   #--------------------------------------------------------------------------
  334.   # ● 转换 真 字符串
  335.   #--------------------------------------------------------------------------
  336.   def true_to_s
  337.     string = "["
  338.     for unit in self
  339.       string += unit.is_a?(Array) ? unit.true_to_s + "," : "#{unit},"
  340.     end
  341.     string + "]"
  342.   end
  343.   #--------------------------------------------------------------------------
  344.   # ● 转换 新 字符串
  345.   #--------------------------------------------------------------------------
  346.   def new_to_s
  347.     string = ""
  348.     for unit in self
  349.       string += "[#{unit}]"
  350.     end
  351.     string
  352.   end
  353.   #--------------------------------------------------------------------------
  354.   # ● 全部 自相加
  355.   #--------------------------------------------------------------------------
  356.   def self_all_plus
  357.     var = 0
  358.     self.each {|unit| var +=  unit.is_a?(Array) ? unit.self_all_plus : 1}
  359.     var
  360.   end
  361. end
复制代码


沙漠点灰于2011-5-1 17:50补充以下内容:
鼠标版:
用的鼠标脚本是没有内置dll的那个 Mouse.get_mouse_pos
可以把我的两个范例(http://rpg.blue/thread-174282-1-1.html
http://rpg.blue/thread-175789-1-1.html)替换掉
下面美化脚本(移动光标):
  1. #==============================================================================
  2. # ■ Rect
  3. #------------------------------------------------------------------------------
  4. #  矩形类
  5. #==============================================================================

  6. # 移动帧数,自己改
  7. Cursor_Rect_Move = 10
  8. class Rect
  9.   # 设置
  10.   alias old_set set unless Rect.method_defined? "old_set"
  11.   def set(x,y,w,h,de=false)
  12.     if @target_rect.is_a?(Rect)
  13.       return if @target_rect == Rect.new(x,y,w,h)
  14.     end
  15.     if de
  16.       @cursor_rect_move = Cursor_Rect_Move
  17.       @target_rect = Rect.new(x,y,w,h)
  18.     else
  19.       self.old_set(x,y,w,h)
  20.     end
  21.   end
  22.   # 刷新
  23.   def update
  24.     return unless @target_rect and @cursor_rect_move
  25.     return if @cursor_rect_move <= 0
  26.     x = (@target_rect.x - self.x) / @cursor_rect_move
  27.     y = (@target_rect.y - self.y) / @cursor_rect_move
  28.     w = (@target_rect.width - self.width) / @cursor_rect_move
  29.     h = (@target_rect.height - self.height) / @cursor_rect_move
  30.     @cursor_rect_move -= 1
  31.     self.old_set(x+self.x,y+self.y,w+self.width,h+self.height)
  32.   end
  33. end
  34. #==============================================================================
  35. # ■ Window_Selectable
  36. #------------------------------------------------------------------------------
  37. #  拥有光标的移动以及滚动功能的窗口类。
  38. #==============================================================================

  39. class Window_Selectable < Window_Base
  40.   #--------------------------------------------------------------------------
  41.   # ● 更新光标举行
  42.   #--------------------------------------------------------------------------
  43.   def update_cursor_rect
  44.     # 光标位置不满 0 的情况下
  45.     if @index < 0
  46.       self.cursor_rect.empty
  47.       return
  48.     end
  49.     # 获取当前的行
  50.     row = @index / @column_max
  51.     # 当前行被显示开头行前面的情况下
  52.     if row < self.top_row
  53.       # 从当前行向开头行滚动
  54.       self.top_row = row
  55.     end
  56.     # 当前行被显示末尾行之后的情况下
  57.     if row > self.top_row + (self.page_row_max - 1)
  58.       # 从当前行向末尾滚动
  59.       self.top_row = row - (self.page_row_max - 1)
  60.     end
  61.     # 计算光标的宽
  62.     cursor_width = self.width / @column_max - 32
  63.     # 计算光标坐标
  64.     x = @index % @column_max * (cursor_width + 32)
  65.     y = @index / @column_max * 32 - self.oy
  66.     # 更新国标矩形
  67.     self.cursor_rect.set(x, y, cursor_width, 32,true)
  68.   end
  69. end
  70. #==============================================================================
  71. # ■ Window_Message
  72. #------------------------------------------------------------------------------
  73. #  显示文章的信息窗口。
  74. #==============================================================================

  75. class Window_Message < Window_Selectable
  76.   #--------------------------------------------------------------------------
  77.   # ● 刷新光标矩形
  78.   #--------------------------------------------------------------------------
  79.   def update_cursor_rect
  80.     if @index >= 0
  81.       n = $game_temp.choice_start + @index
  82.       self.cursor_rect.set(8, n * 32, @cursor_width, 32,true)
  83.     else
  84.       self.cursor_rect.empty
  85.     end
  86.   end
  87. end
复制代码
下面是鼠标版:
  1. * 此脚本归66RPG - Idiot Script Association(ISA)所有,谢绝任何形式转载。
  2. #______________________________________________________________________________

  3. #==============================================================================
  4. # ■ 子选项 - Sub-option
  5. #------------------------------------------------------------------------------
  6. #   遵守协议:66RPG - Idiot Script Association(ISA)
  7. #   当前版本:0.9.7.0
  8. #------------------------------------------------------------------------------
  9. #   更新日记:沙漠.灰(2011.4.2)
  10. #             - 初始化
  11. #             沙漠.灰(2011.4.16)
  12. #             - 0.95版放出
  13. #             沙漠.灰(2011.5.1)
  14. #             - 0.97版放出
  15. #=============================================================================

  16. class Window_Folder < Window_Base
  17.   #--------------------------------------------------------------------------
  18.   # ● 定义实例变量
  19.   #--------------------------------------------------------------------------
  20.   attr_reader   :index                    # 光标位置
  21.   attr_reader   :c
  22.   #--------------------------------------------------------------------------
  23.   # ● 初始画对像
  24.   #     x      : 窗口的 X 坐标
  25.   #     y      : 窗口的 Y 坐标
  26.   #     width  : 窗口的宽
  27.   #     height : 窗口的高
  28.   #--------------------------------------------------------------------------
  29.   def initialize(x,y,width, height, commands)
  30.     commands += ["-"*(width/11)]
  31.     super(x, y, width, height)
  32.     # 初始化数据
  33.     @move_to        = 0
  34.     @to_refresh     = false
  35.     @commands_size  = 0
  36.     @c              = false
  37.     @index          = [0]
  38.     @spread_command = []
  39.     @disable_item   = []
  40.     commands.size.times{@spread_command.push(1)}
  41.     @true_commands  = commands
  42.     @object_id = 0
  43.     # 生成位图
  44.     self.contents = Bitmap.new(width - 32, @true_commands.self_all_plus * 32-32)
  45.     @v = Viewport.new(16+self.x, 16+self.y, width-32, height-32) ; @v.z = 999
  46.     @new_bitmap = Sprite.new(@v)
  47.     @new_bitmap.bitmap = Bitmap.new(width - 32, @true_commands.self_all_plus * 32-32)
  48.     index = 0 # 描绘顶层项目
  49.     # 描绘父项目
  50.     for unit in @true_commands
  51.       draw_command [index]
  52.       index += 1
  53.     end
  54.   end
  55.   #--------------------------------------------------------------------------
  56.   # ● 项目无效化 index : 项目编号
  57.   #--------------------------------------------------------------------------
  58.   def disable_item(index)
  59.     @disable_item.push(index)
  60.   end
  61.   #--------------------------------------------------------------------------
  62.   # ● 指定项目是否为父项目 index 所在位置
  63.   #--------------------------------------------------------------------------
  64.   def is_folder?(commands,index)
  65.     # 若指定项目为数组且子单元数目大于1就判定为父项目
  66.     if index.size == 1 and commands[index[0]].is_a?(Array)
  67.       return true if commands[index[0]].size > 1
  68.     elsif index.size > 1
  69.       return is_folder?(commands[index[0]],index[1...index.size])
  70.     end
  71.     false
  72.   end
  73.   #--------------------------------------------------------------------------
  74.   # ● 描绘项目名称 index 所在位置  branch 是否分支
  75.   #--------------------------------------------------------------------------
  76.   def draw_command(index,branch=false)
  77.     x, y = check_index_xy(index)
  78.     rect = Rect.new(x+32,y,self.width-32,32)
  79.     self.contents.font.color = disabled_color if @disable_item.include?(index)
  80.     name = get_command(@true_commands,index)
  81.     self.contents.draw_text(rect, name)
  82.     # 为父项目时,描绘指引
  83.     draw_flag(index,branch) if is_folder?(@true_commands,index)
  84.     self.contents.font.color = normal_color
  85.   end
  86.   #--------------------------------------------------------------------------
  87.   # ● 取得项目名称 index 所在位置
  88.   #--------------------------------------------------------------------------
  89.   def get_command(name_array,index)
  90.     return get_command_name(name_array[index[0]]) if index.size == 1
  91.     get_command name_array[index[0]],index[1...index.size]
  92.   end
  93.   #--------------------------------------------------------------------------
  94.   # ● 再次 取得项目名称 index 所在位置
  95.   #--------------------------------------------------------------------------
  96.   def get_command_name(name_array)
  97.     name_array.is_a?(String) ? name_array : name_array[0].is_a?(Array) ?  get_command_name(name_array[0]) : name_array[0]
  98.   end
  99.   #--------------------------------------------------------------------------
  100.   # ● 描绘项目标记 index 所在位置
  101.   #--------------------------------------------------------------------------
  102.   def draw_flag(index,branch=false)
  103.     x, y = check_index_xy index
  104.     src_rect  = Rect.new(x+16,y+10,16,16)
  105.     self.contents.fill_rect(src_rect, Color.new(0,0,0,0))
  106.     dest_rect = branch ? Rect.new(152, 40, 16, 16): Rect.new(168, 24, 16, 16)
  107.     src_bitmap= RPG::Cache.windowskin($game_system.windowskin_name)
  108.     self.contents.stretch_blt(src_rect, src_bitmap, dest_rect)
  109.   end
  110.   #--------------------------------------------------------------------------
  111.   # ● 检查 index 所在坐标
  112.   #--------------------------------------------------------------------------
  113.   def check_index_xy(index)
  114.     # 反复迭代,直到index最后一位
  115.     str = "["
  116.     if index[0] > 0
  117.       for i in 0...index[0]
  118.         str += @spread_command[i].true_to_s + "," rescue str += "1,"
  119.       end
  120.     end
  121.     if @spread_command[index[0]].is_a?(Array) and index.size > 1
  122.       str += check_spread(@spread_command[index[0]],index[1...index.size]) + ","
  123.     end
  124.     [index.size * 32 - 32, eval(str += "]").self_all_plus * 32]
  125.   end
  126.   #--------------------------------------------------------------------------
  127.   # ● 检查展开项目,返回项目数
  128.   #--------------------------------------------------------------------------
  129.   def check_spread(array,index)
  130.     str = "["
  131.     if index[0] > 0
  132.       for i in 0...index[0]
  133.         str += array[i].true_to_s + "," rescue str += "1,"
  134.       end
  135.     end
  136.     if array[index[0]].is_a?(Array) and index.size > 1
  137.       str += check_spread(array[index[0]],index[1...index.size]) + ","
  138.     end
  139.     str += "]"
  140.   end
  141.   #--------------------------------------------------------------------------
  142.   # ● 释放
  143.   #--------------------------------------------------------------------------
  144.   def dispose
  145.     @new_bitmap.bitmap.dispose
  146.     @new_bitmap.dispose
  147.     @v.dispose
  148.     super
  149.   end
  150.   #--------------------------------------------------------------------------
  151.   # ● 设置光标的位置
  152.   #--------------------------------------------------------------------------
  153.   def index=(index)
  154.     @index = index
  155.     update_cursor_rect
  156.   end
  157.   #--------------------------------------------------------------------------
  158.   # ● 检查指定项目大小 index :
  159.   #--------------------------------------------------------------------------
  160.   def check_command_size(index,commands=@true_commands)
  161.     return commands.size if index.size == 1
  162.     check_command_size(index[1...index.size],commands[index[0]])
  163.   end
  164.   #--------------------------------------------------------------------------
  165.   # ● 关闭\展开父选项
  166.   #--------------------------------------------------------------------------
  167.   def folder(index,close=true)
  168.     if close
  169.       return if index.size == 1 if closed?(index)
  170.       return folder(index[0...index-1],close) if closed?(index)
  171.       x1, y1 = check_index_xy(index)
  172.       Graphics.freeze
  173.       temp = @spread_command.self_all_plus
  174.       eval("@spread_command#{@index.new_to_s} = 1 ")
  175.       new_height = ((@spread_command.self_all_plus - temp).abs + 1) * 32
  176.       src_rect      = Rect.new(0,0,self.width,self.contents.height)
  177.       dest_rect     = Rect.new(0,y1+new_height,self.width,self.contents.height)
  178.       @new_bitmap.bitmap.stretch_blt(src_rect, self.contents, dest_rect)
  179.       src_rect  = Rect.new(0,y1,self.width,self.contents.height)
  180.       self.contents.fill_rect(src_rect, Color.new(0,0,0,0))
  181.       @new_bitmap.y= y1 + new_height
  182.       @move_to     = -new_height + 32
  183.       @to_refresh  = -1
  184.       draw_command(@index,false)
  185.       Graphics.transition(10)
  186.     else
  187.       return if !is_folder?(@true_commands,index)
  188.       return @index.push(1) if !closed?(index)
  189.       new_height = check_command_size(index+[0]) * 32 - 32
  190.       x1, y1 = check_index_xy(index+[0])
  191.       @new_bitmap.bitmap.clear
  192.       @new_bitmap.y = y1 + 32
  193.       src_rect      = Rect.new(0 ,0    ,self.width,self.contents.height)
  194.       dest_rect     = Rect.new(0,y1+32,self.width,self.contents.height)
  195.       @new_bitmap.bitmap.stretch_blt(src_rect, self.contents, dest_rect)
  196.       src_rect  = Rect.new(0,y1,self.width,self.contents.height)
  197.       self.contents.fill_rect(src_rect, Color.new(0,0,0,0))
  198.       @move_to     = new_height
  199.       @to_refresh  = 1
  200.       draw_command(@index,true)
  201.       size = "1," * check_command_size(@index+[0])
  202.       eval("@spread_command#{@index.new_to_s} = [#{size}] ")
  203.     end
  204.   end
  205.   #--------------------------------------------------------------------------
  206.   # ● 移动项目
  207.   #--------------------------------------------------------------------------
  208.   def move_command
  209.     if @move_to == 0 and @to_refresh != 0
  210.       if @to_refresh == 1
  211.         @to_refresh = 0
  212.         for i in 1...check_command_size(@index+[0])
  213.           draw_command(@index+[i])
  214.         end
  215.         Graphics.freeze
  216.         src_rect  = Rect.new(@new_bitmap.x,@new_bitmap.y,self.width,self.contents.height)
  217.         dest_rect = Rect.new(0,0,self.width,self.contents.height)
  218.         self.contents.stretch_blt(src_rect, @new_bitmap.bitmap, dest_rect)
  219.         @new_bitmap.bitmap.clear
  220.         Graphics.transition(10)
  221.          @index << 1
  222.       else
  223.         @to_refresh = 0
  224.         src_rect  = Rect.new(@new_bitmap.x,@new_bitmap.y,self.width,self.contents.height)
  225.         dest_rect = Rect.new(0,0,self.width,self.contents.height)
  226.         self.contents.stretch_blt(src_rect, @new_bitmap.bitmap, dest_rect)
  227.         @new_bitmap.bitmap.clear
  228.       end
  229.     end
  230.     return if @move_to == 0
  231.     step = @move_to/@move_to.abs * 4
  232.     @move_to -= step
  233.     @new_bitmap.y += step
  234.   end
  235.   #--------------------------------------------------------------------------
  236.   # ● 父选项已关闭? @spread_command
  237.   #--------------------------------------------------------------------------
  238.   def closed?(index,commands=@spread_command)
  239.     return true if !commands[index[0]].is_a?(Array)
  240.     return closed?(index[1...index.size],commands[index[0]]) if index.size > 1
  241.     false
  242.   end
  243.   #--------------------------------------------------------------------------
  244.   # ● 刷新画面
  245.   #--------------------------------------------------------------------------
  246.   def update
  247.     super
  248.     move_command
  249.     return if @to_refresh != 0
  250.     if self.active
  251.       # 方向键下被按下的情况下
  252.       if Input.repeat?(Input::DOWN)
  253.         $game_system.se_play($data_system.cursor_se)
  254.         @index[-1] = (@index[-1]+1)%check_command_size(@index)
  255.         @index[-1] += 1 if @index.size > 1 and @index[-1] == 0
  256.         @index = [0] if @index == [@true_commands.size-1]
  257.       end
  258.       # 方向键上被按下的情况下
  259.       if Input.repeat?(Input::UP)
  260.         $game_system.se_play($data_system.cursor_se)
  261.         @index[-1] -= 1 if @index.size > 1 and @index[-1] == 1
  262.         @index[-1] -= 1 if @index == [0]
  263.         @index[-1] = (@index[-1]-1)%check_command_size(@index)
  264.       end
  265.       # 方向键左被按下的情况下
  266.       if Input.trigger?(Input::LEFT)
  267.         if @index.size == 1
  268.           $game_system.se_play($data_system.buzzer_se)
  269.         else
  270.           @index.pop
  271.           $game_system.se_play($data_system.cancel_se)
  272.         end
  273.       end
  274.       # 方向键右被按下的情况下
  275.       if Input.trigger?(Input::RIGHT)
  276.         if is_folder?(@true_commands,@index)
  277.           $game_system.se_play($data_system.decision_se)
  278.           folder(@index,false)
  279.         end
  280.       end
  281.       # B键被按下的情况下
  282.       if Input.trigger?(Input::B)
  283.         if @index.size == 1
  284.           $game_system.se_play($data_system.buzzer_se)
  285.         else
  286.           @index.pop
  287.           $game_system.se_play($data_system.cancel_se)
  288.           folder(@index)
  289.         end
  290.       end
  291.       # C键被按下的情况下
  292.       if Input.trigger?(Input::C)
  293.         @c = !is_folder?(@true_commands,@index)
  294.         if is_folder?(@true_commands,@index)
  295.           $game_system.se_play($data_system.decision_se)
  296.           folder(@index,false)
  297.         end
  298.       end
  299.     end
  300.     update_cursor_rect
  301.   end
  302.   #--------------------------------------------------------------------------
  303.   # ● 更新光标矩形
  304.   #--------------------------------------------------------------------------
  305.   def update_cursor_rect
  306.     return if @move_to != 0
  307.     mouse_x, mouse_y = Mouse.get_mouse_pos
  308.     # y 坐标修正
  309.     mouse_y -= 16
  310.     if mouse_x > self.x and mouse_x < self.x + self.width and
  311.       mouse_y > self.y - 32 and self.y > mouse_y and self.oy > 0
  312.       self.oy        -= 32
  313.       @new_bitmap.oy -= 32
  314.     end
  315.     iindex = @index.dup
  316.     begin
  317.       if mouse_y > self.y and mouse_y < self.y + self.height and
  318.         mouse_x > self.x and mouse_x < self.x + self.width
  319.         pos = ((mouse_y - self.y+self.oy)/32).to_i
  320.         str = @spread_command.true_to_s.pos(pos+1,"1") + "2"
  321.         size = str.unit_size("[")-str.unit_size("]")
  322.         str += "]" * size
  323.         begin
  324.           @index = eval((eval(str)).pos_(2).gsub("]["){","})
  325.         rescue
  326.           @index = eval((eval(str)).pos_(2))
  327.         end
  328.         @index = [@true_commands.size-2] if @index.size == 1 and @index[0] == @true_commands.size-1
  329.       end
  330.     rescue
  331.       # 超过范围
  332.       @index = iindex
  333.     end
  334.     x, y = check_index_xy(@index)
  335.     if y - self.oy >= self.height - 32
  336.       self.oy        += 32
  337.       @new_bitmap.oy += 32
  338.     elsif y - self.oy < 0
  339.       self.oy        -= 32
  340.       @new_bitmap.oy -= 32
  341.     end
  342.     self.cursor_rect.set(x, y-self.oy, [email protected]_to_s.size/3*32, 32, true)
  343.   end
  344. end
  345. #==============================================================================
  346. # ■ Array
  347. #------------------------------------------------------------------------------
  348. #  数组类  又拿数组开刀...
  349. #==============================================================================

  350. class Array
  351.   #--------------------------------------------------------------------------
  352.   # ● 返回目标位置 [[1,1,1,1],1,1,2]
  353.   #--------------------------------------------------------------------------
  354.   def pos_(unit)
  355.     string = ""
  356.     times = 0
  357.     for i in self
  358.       if i.is_a?(Array)
  359.         string += "[#{times}]#{i.pos_(unit)}" if i.true_to_s.include?(unit.to_s)
  360.       else
  361.         string += "[#{times}]" if i == unit
  362.         break if i == unit
  363.       end
  364.       times += 1
  365.     end
  366.     string
  367.   end
  368.   #--------------------------------------------------------------------------
  369.   # ● 转换 真 字符串
  370.   #--------------------------------------------------------------------------
  371.   def true_to_s
  372.     string = "["
  373.     for unit in self
  374.       string += unit.is_a?(Array) ? unit.true_to_s + "," : "#{unit},"
  375.     end
  376.     string + "]"
  377.   end
  378.   #--------------------------------------------------------------------------
  379.   # ● 转换 新 字符串
  380.   #--------------------------------------------------------------------------
  381.   def new_to_s
  382.     string = ""
  383.     for unit in self
  384.       string += "[#{unit}]"
  385.     end
  386.     string
  387.   end
  388.   #--------------------------------------------------------------------------
  389.   # ● 全部 自相加
  390.   #--------------------------------------------------------------------------
  391.   def self_all_plus
  392.     var = 0
  393.     self.each {|unit| var +=  unit.is_a?(Array) ? unit.self_all_plus : 1}
  394.     var
  395.   end
  396. end
  397. #==============================================================================
  398. # ■ String
  399. #------------------------------------------------------------------------------
  400. #  字符类  拿字符开刀了!
  401. #==============================================================================
  402. class String
  403.   def pos(var,str)
  404.     temp = 0
  405.     self.size.times {|i|
  406.     temp += 1 if self[i,1] == str
  407.     return self[0,i] if temp == var}
  408.   end
  409.   def unit_size(unit)
  410.     temp = 0
  411.     self.size.times {|i|
  412.     temp += 1 if self[i,1] == unit}
  413.     return temp
  414.   end
  415. end
复制代码
最后,附赠范例(RM文件浏览,据说可以拿来CG、BGM鉴赏)
>>猛戳>>MetalSagaR游戏主页<<这里<<
欢迎提供您的意见
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-14 05:16

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表