Project1

标题: 关于window窗口的:X键位设置的问题 [打印本页]

作者: jianyulei    时间: 2019-7-18 03:31
标题: 关于window窗口的:X键位设置的问题
本帖最后由 jianyulei 于 2019-7-18 03:34 编辑

请问为何我在@category_window设置:X键位之后,后面的@item_window无论怎么设置:X的键位,游戏中按下A键也只能调用@category_window设置的:X键位?明明:ok和:cancel都很正常啊.
相反,在@item_window里设置:X键位,会让@category_window窗口中按A键也有同样效果.
还有用@item_window.set_handler(:X,     method(:on_item_ok))  将A键设置在道具窗口后,如果我不想关闭窗口,想直接用命令取消该设置的键位让其变成没有设置键位该怎么办?
作者: hyrious    时间: 2019-7-18 08:57
@category_window 和 @item_window 的 active 状态同时只能有一个,active 的那个会响应按键。你遇到这些问题就是因为 active 状态没管理好。

只看你的描述并不能猜到你对默认脚本做了什么修改(而导致了异常),如果需要参考的话可以看中文帮助文档里的这篇小教程
作者: Aephiex    时间: 2019-7-18 16:58
hyrious 发表于 2019-7-18 08:57
@category_window 和 @item_window 的 active 状态同时只能有一个,active 的那个会响应按键。你遇到这些问 ...

嗯嗯!所以可以作出两个各说各话的选择窗口咯!
作者: jianyulei    时间: 2019-7-18 21:49
hyrious 发表于 2019-7-18 08:57
@category_window 和 @item_window 的 active 状态同时只能有一个,active 的那个会响应按键。你遇到这些问 ...

我是修改的原版的道具菜单,想在选择道具那里加上个A键的弹出窗口,参考process_handling里:C的方式增加了:X的按键对应,但发现在@item_window窗口里建立的:X会被@category_window读取,如果是在@category_window建立,同样@item_window也能使用,同时建立则只有@category_window建立的:X生效,完全不知道什么原因.因为同样方法建立的:ok都是正常的
作者: hyrious    时间: 2019-7-19 10:25
体会一下?

RUBY 代码复制下载
  1. class Window_Popup < Window_Selectable
  2.   def initialize
  3.     super 0, 0, 0, 0
  4.     self.openness = 0
  5.   end
  6.  
  7.   def set_text text
  8.     width, height = measure text
  9.     self.width = width + standard_padding * 2
  10.     self.height = height + standard_padding * 2
  11.     create_contents
  12.     draw_text_ex 0, 0, text
  13.   end
  14.  
  15.   def measure text
  16.     width = text.lines.map { |e| (contents.text_size e.chomp).width }.max
  17.     height = text.lines.to_a.size * line_height
  18.     return width, height
  19.   end
  20. end
  21.  
  22. class Window_ItemList < Window_Selectable
  23.   def process_handling
  24.     super
  25.     return unless open? && active && @data[index]
  26.     process_popup if handle?(:popup) && Input.trigger?(:X)
  27.   end
  28.  
  29.   def process_popup
  30.     if handle?(:popup)
  31.       Sound.play_ok
  32.       Input.update
  33.       deactivate
  34.       call_handler(:popup)
  35.     else
  36.       Sound.play_buzzer
  37.     end
  38.   end
  39. end
  40.  
  41. class Scene_Item < Scene_ItemBase
  42.   alias _start_without_popup start
  43.   def start
  44.     _start_without_popup
  45.     create_popup_window
  46.   end
  47.  
  48.   alias _create_item_window_without_popup create_item_window
  49.   def create_item_window
  50.     _create_item_window_without_popup
  51.     @item_window.set_handler(:popup, method(:on_item_popup))
  52.   end
  53.  
  54.   def create_popup_window
  55.     @popup_window = Window_Popup.new
  56.     @popup_window.viewport = @viewport
  57.     @popup_window.set_handler(:ok,     method(:on_popup_ok))
  58.     @popup_window.set_handler(:cancel, method(:on_popup_ok))
  59.   end
  60.  
  61.   def on_item_popup
  62.     rect = @item_window.item_rect @item_window.index
  63.     @popup_window.x = @item_window.x + @item_window.padding + rect.x
  64.     @popup_window.y = @item_window.y + @item_window.padding + rect.y + rect.height
  65.     @popup_window.set_text "You selected #{@item_window.item.name}"
  66.     @popup_window.show.activate.open
  67.   end
  68.  
  69.   def on_popup_ok
  70.     @popup_window.close
  71.     update until @popup_window.close?
  72.     @popup_window.hide.deactivate
  73.     activate_item_window
  74.   end
  75. end





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