本帖最后由 MCCF 于 2020-4-13 08:56 编辑
明白你的意思了。首先你要看Scene_Item的处理:
#--------------------------------------------------------------------------
# ● 生成分类窗口
#--------------------------------------------------------------------------
def create_category_window
@category_window = Window_ItemCategory.new
@category_window .viewport = @viewport
@category_window .help_window = @help_window
@category_window .y = @help_window .height
@category_window .set_handler ( :ok , method( :on_category_ok ) )
@category_window .set_handler ( :cancel , method( :return_scene ) )
end
#--------------------------------------------------------------------------
# ● 生成物品窗口
#--------------------------------------------------------------------------
def create_item_window
wy = @category_window .y + @category_window .height
wh = Graphics.height - wy
@item_window = Window_ItemList.new ( 0 , wy, Graphics.width , wh)
@item_window .viewport = @viewport
@item_window .help_window = @help_window
@item_window .set_handler ( :ok , method( :on_item_ok ) )
@item_window .set_handler ( :cancel , method( :on_item_cancel ) )
@category_window .item_window = @item_window
end
#--------------------------------------------------------------------------
# ● 生成分类窗口
#--------------------------------------------------------------------------
def create_category_window
@category_window = Window_ItemCategory.new
@category_window .viewport = @viewport
@category_window .help_window = @help_window
@category_window .y = @help_window .height
@category_window .set_handler ( :ok , method( :on_category_ok ) )
@category_window .set_handler ( :cancel , method( :return_scene ) )
end
#--------------------------------------------------------------------------
# ● 生成物品窗口
#--------------------------------------------------------------------------
def create_item_window
wy = @category_window .y + @category_window .height
wh = Graphics.height - wy
@item_window = Window_ItemList.new ( 0 , wy, Graphics.width , wh)
@item_window .viewport = @viewport
@item_window .help_window = @help_window
@item_window .set_handler ( :ok , method( :on_item_ok ) )
@item_window .set_handler ( :cancel , method( :on_item_cancel ) )
@category_window .item_window = @item_window
end
会看到帮助窗口(在父类定义)被传递给了分类窗口和物品窗口;
物品窗口被传递给了分类窗口。
于是分类窗口改变时就会调用物品窗口的方法让其refresh(刷新)。如Window_ItemCategory内:
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
def update
super
@item_window .category = current_symbol if @item_window
end
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
def update
super
@item_window .category = current_symbol if @item_window
end
在Window_ItemList内对应有:
#--------------------------------------------------------------------------
# ● 设置分类
#--------------------------------------------------------------------------
def category=( category)
return if @category == category
@category = category
refresh
self .oy = 0
end
#--------------------------------------------------------------------------
# ● 设置分类
#--------------------------------------------------------------------------
def category=( category)
return if @category == category
@category = category
refresh
self .oy = 0
end