Project1

标题: RMVA-图片选项(更新支持鼠标) [打印本页]

作者: 北极七月熊    时间: 2013-4-20 14:35
标题: RMVA-图片选项(更新支持鼠标)
本帖最后由 北极七月熊 于 2013-4-29 15:11 编辑

千辛万苦终于做出想要的效果了……,虽然目前还没办法支持鼠标{:2_264:}
这是仿照一个前辈用XP写的一种方法,虽然换到用VA写各种出错泪奔~
使用的方法比较简单,只要按照VA默认的在窗口添加指令的原方法add_command,多填写上参数就可以了。
新增了四个参数:
usepic - 是否使用图片,如果使用图片,则填写true,反正false,
usepic的参数默认false,即不存在图片时使用VA默认的文字指令。
pic- 默认显示图片,默认nil
over_pic - 当正在选择时的图片,即光标移动上去的图片,默认nil
overd - 是否已经选择,无需填写
例如:add_command("新游戏", :new_game, true, nil, true, "图片1.png", "图片2.png")
------------------------------------------------------------------------------------------------

今天研究了一下Sion所提供的鼠标脚鼠标脚本,发现还是挺好兼容的。{:2_287:}
只要在
class Window_Selectable
def set_cursor
里的select(new_index) if new_index < item_max && new_index != @index
改成:

       if new_index < item_max && new_index != @index
          move_overd_pic?(@index)

          contents.clear#新的修正
          draw_all_items
          select(new_index)
      end
就按钮可以支持鼠标了{:2_249:}

------------------------
一个BUG,请先自行修正:
在33行:
    #重置指令的参数overd为false
    move_overd_pic?(last_index)
    contents.clear#新增修正
    draw_all_items
    end


------------------------------------------------------------------------------------------------

范例下载:
http://pan.baidu.com/share/link?shareid=411995&uk=975966104

随便弄了一张图片{:2_263:}

RUBY 代码复制
  1. #encoding:utf-8
  2. #==============================================================================
  3. # ■ 图片选项(修改Window_Selectable 和 Window_Command)by 只有金刚心
  4. #  (不支持鼠标)
  5. #------------------------------------------------------------------------------
  6. # 使用方法:按照VA默认的在窗口添加指令的原方法add_command,多填写上参数就可以了。
  7. # 新增参数:
  8. # usepic - 是否使用图片,如果使用图片,则填写true,反正false
  9. # usepic的参数默认false,即不存在图片时使用VA默认的文字指令
  10. # pic- 默认显示图片,默认nil
  11. # over_pic - 当正在选择时的图片,即光标移动上去的图片,默认nil
  12. # overd - 是否已经选择,无需填写
  13. # 例如:add_command("新游戏", :new_game, true, nil, true, "图片1.png", "图片2.png")
  14. #==============================================================================
  15.  
  16. class Window_Selectable < Window_Base
  17.   #--------------------------------------------------------------------------
  18.   # ● 处理光标的移动
  19.   #--------------------------------------------------------------------------
  20.   def process_cursor_move
  21.     return unless cursor_movable?
  22.     last_index = @index
  23.     cursor_down (Input.trigger?(:DOWN))  if Input.repeat?(:DOWN)
  24.     cursor_up   (Input.trigger?(:UP))    if Input.repeat?(:UP)
  25.     cursor_right(Input.trigger?(:RIGHT)) if Input.repeat?(:RIGHT)
  26.     cursor_left (Input.trigger?(:LEFT))  if Input.repeat?(:LEFT)
  27.     cursor_pagedown   if !handle?(:pagedown) && Input.trigger?(:R)
  28.     cursor_pageup     if !handle?(:pageup)   && Input.trigger?(:L)
  29.  
  30.     #★★当光标移动时重新绘制指令★★
  31.     if @index != last_index
  32.     Sound.play_cursor
  33.     #重置指令的参数overd为false
  34.     move_overd_pic?(last_index)
  35.     draw_all_items
  36.     end
  37.  
  38.   end
  39.  
  40.   #--------------------------------------------------------------------------
  41.   # ● 更新光标
  42.   #--------------------------------------------------------------------------
  43.   def update_cursor
  44.     if @cursor_all
  45.       cursor_rect.set(0, 0, contents.width, row_max * item_height)
  46.       self.top_row = 0
  47.     elsif @index < 0
  48.       cursor_rect.empty
  49.     else
  50.  
  51.       #★★更新图片指令★★
  52.       if pic_or_text(@index) == true
  53.         cursor_rect.empty
  54.         overd_pic?(@index)
  55.         redraw_item(@index)
  56.       #保留原来的光标
  57.       else
  58.       ensure_cursor_visible
  59.       cursor_rect.set(item_rect(@index))
  60.       end
  61.  
  62.     end
  63.   end
  64.  
  65.   #★★图片指令函数★★  
  66.   def pic_or_text(index)
  67.   end
  68.   def overd_pic(index)
  69.   end
  70.  
  71. end  
  72.  
  73. class Window_Command < Window_Selectable
  74.  
  75.   #★★添加指令★★
  76.   #(保留原指令:name-指令名称,symbol-对应的符号,enabled-有效状态的标志,ext-任意的扩展数据)
  77.   #(新增参数usepic-是否使用图片,pic-默认显示图片,over_pic-当正在选择时的图片,overd-是否已经选择)
  78.   def add_command(name, symbol, enabled = true, ext = nil, usepic = false, pic = nil, over_pic = nil,overd = false)
  79.     @list.push({:name=>name, :symbol=>symbol, :enabled=>enabled, :ext=>ext,:usepic=>usepic, :pic=>pic, :over_pic=>over_pic, :overd=>overd})
  80.   end
  81.  
  82.   #★★绘制图片指令★★
  83.   def draw_item(index)
  84.     #绘制图片指令
  85.     if @list[index][:usepic] == true && @list[index][:pic] != nil
  86.       if @list[index][:over_pic] != nil  && @list[index][:overd] == true
  87.         @bitmap = Cache.picture(@list[index][:over_pic])
  88.       else
  89.         @bitmap = Cache.picture(@list[index][:pic])
  90.       end
  91.     rect = Rect.new(0, 0, @bitmap.width, @bitmap.height)
  92.     #图片指令的坐标参照文字指令
  93.     contents.blt(index % col_max * (item_width + spacing), index / col_max * item_height, @bitmap, rect)
  94.     @bitmap.dispose
  95.     #保留原来的文字指令
  96.     else
  97.     change_color(normal_color, command_enabled?(index))
  98.     draw_text(item_rect_for_text(index), command_name(index), alignment)
  99.     end  
  100.   end
  101.  
  102.   #★★判断使用图片还是文字★★
  103.   def current_usepic?
  104.     current_data ? current_data[:usepic] : false
  105.   end
  106.  
  107.   def pic_or_text(index)
  108.     return current_usepic?
  109.   end
  110.  
  111.   #★★判断光标是否移动到图片上★★
  112.   def move_overd_pic?(index)
  113.     @list[index][:overd] = false
  114.   end
  115.  
  116.   def overd_pic?(index)
  117.     @list[index][:overd] = true
  118.   end
  119.  
  120. end




作者: 4lnlove    时间: 2013-4-20 19:30
我可是希望大大能想出把邊框去掉的方法{:2_258:}
作者: 北极七月熊    时间: 2013-4-20 23:52
4lnlove 发表于 2013-4-20 19:30
我可是希望大大能想出把邊框去掉的方法

#--------------------------------------------------------------------------
  # ● 生成指令窗口
  #--------------------------------------------------------------------------
  def create_command_window
    @command_window = Window_TitleCommand.new
    @command_window.opacity = 0
    @command_window.set_handler(:new_game, method(:command_new_game))
    @command_window.set_handler(:continue, method(:command_continue))
    @command_window.set_handler(:shutdown, method(:command_shutdown))
  end

在生成指令窗口时加上这样一句的可以了。
作者: 千葉玖濑    时间: 2013-4-21 21:11
说实话用图片响应就可以了呢……

作者: raymondyrf    时间: 2013-4-22 00:55
和鼠标操作脚本兼容到一起的时候,鼠标移动到图片时可以进行操作没错,但是移开到图片之外还是可以点击,请问怎么解决?
作者: 北极七月熊    时间: 2013-4-22 12:12
本帖最后由 北极七月熊 于 2013-4-22 12:19 编辑
raymondyrf 发表于 2013-4-22 00:55
和鼠标操作脚本兼容到一起的时候,鼠标移动到图片时可以进行操作没错,但是移开到图片之外还是可以点击,请 ...

呃……因为我本意是想在选项里加入图片,这个是command,用在菜单之类的地方

而不是要作为按钮button,如果你想要点击图片才有响应的,可以去试试图片响应....

我现在也想再写一个在事件里调用的图片按钮的脚本……{:2_264:}
其实我拿标题界面来测试是不对的,当时只是为了方便,其实这个脚本用在菜单那种的比较合适{:2_263:}




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1