查看: 3979|回复: 11

[讨论] 把窗口存进数组里

[复制链接]
梦石
0
星屑
1433
在线时间
50 小时
注册时间
2020-2-16
回帖
85
发表于 2020-2-27 13:25:24 | 显示全部楼层 |阅读模式

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

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

×
#==============================================================================
# ■ Scene_Menu
#------------------------------------------------------------------------------
#  处理菜单画面的类。
#==============================================================================

class Scene_Menu
  #--------------------------------------------------------------------------
  # ● 初始化对像
  #     menu_index : 命令光标的初期位置
  #--------------------------------------------------------------------------
  def initialize(menu_index = 0)
    @menu_index = menu_index
    @windows = []
  end
  #--------------------------------------------------------------------------
  # ● 主处理
  #--------------------------------------------------------------------------
  def main
    # 生成命令窗口
    s1 = $data_system.words.item
    s2 = $data_system.words.skill
    s3 = $data_system.words.equip
    s4 = "状态"
    s5 = "存档"
    s6 = "结束游戏"
    @windows.push(Window_Command.new(160, [s1, s2, s3, s4, s5, s6]))
    @windows[0].index = @menu_index
    @windows.push(Window_PlayTime.new)
    @windows[1].x = 0
    @windows[1].y = 224
    @windows.push(Window_Steps.new)
    @windows[2].x = 0
    @windows[2].y = 320
    @windows.push(Window_Gold.new)
    @windows[3].x = 0
    @windows[3].y = 416
    @windows.push(Window_MenuStatus.new)
    @windows[4].x = 160
    @windows[4].y = 0
   
    # 同伴人数为 0 的情况下
    if $game_party.actors.size == 0
      # 物品、特技、装备、状态无效化
      @windows[0].disable_item(0)
      @windows[0].disable_item(1)
      @windows[0].disable_item(2)
      @windows[0].disable_item(3)
    end
    # 禁止存档的情况下
    if $game_system.save_disabled
      # 存档无效
      @windows[0].disable_item(4)
    end
   
    # 执行过渡
    Graphics.transition
    # 主循环
    loop do
      # 刷新游戏画面
      Graphics.update
      # 刷新输入信息
      Input.update
      # 刷新画面
      update
      # 如果切换画面就中断循环
      if $scene != self
        break
      end
    end
    # 准备过渡
    Graphics.freeze
    for i in 0...@windows.size
      @windows[i].dispose
    end
    # 释放窗口
  end
  #--------------------------------------------------------------------------
  # ● 刷新画面
  #--------------------------------------------------------------------------
  def update
    for i in 0...@windows.size
      @windows[i].update
    end
    return update_command if @windows[0].active
  end
  def update_command
    # 按下 B 键的情况下
    if Input.trigger?(Input::B)
      # 演奏取消 SE
      $game_system.se_play($data_system.cancel_se)
      # 切换的地图画面
      $scene = Scene_Map.new
      return
    end
   
   
    if Input.trigger?(Input::C)
      # 同伴人数为 0、存档、游戏结束以外的场合
      if $game_party.actors.size == 0 and @windows[0].index < 4
        # 演奏冻结 SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # 命令窗口的光标位置分支
      case @windows[0].index
      when 0  # 物品
        # 演奏确定 SE
        $game_system.se_play($data_system.decision_se)
        # 切换到物品画面
        $scene = Scene_Item.new
      when 1  # 特技
        # 演奏确定 SE
        $game_system.se_play($data_system.decision_se)
        # 激活状态窗口
        @windows[0].active = false
        @windows[4].active = true
        @windows[4].index = 0
      when 2  # 装备
        # 演奏确定 SE
        $game_system.se_play($data_system.decision_se)
        # 激活状态窗口
        @windows[0].active = false
        @windows[4].active = true
        @windows[4].index = 0
      when 3  # 状态
        # 演奏确定 SE
        $game_system.se_play($data_system.decision_se)
        # 激活状态窗口
        @windows[0].active = false
        @windows[4].active = true
        @windows[4].index = 0
      when 4  # 存档
        # 禁止存档的情况下
        if $game_system.save_disabled
          # 演奏冻结 SE
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        # 演奏确定 SE
        $game_system.se_play($data_system.decision_se)
        # 切换到存档画面
        $scene = Scene_Save.new
      when 5  # 游戏结束
        # 演奏确定 SE
        $game_system.se_play($data_system.decision_se)
        # 切换到游戏结束画面
        $scene = Scene_End.new
      end
      return
    end
  end
  
end
流飘零半生,未逢明主。公若是不弃,流愿拜为义父
梦石
0
星屑
34459
在线时间
5096 小时
注册时间
2012-11-19
回帖
4715

开拓者

发表于 2020-2-27 14:36:55 | 显示全部楼层
@windows = {}
@windows[:command] = Window_Command.new()
@windows[:status] = Window_MenuStatus.new()
@windows[:command].x = xx
@windows[:command].y = yy
xp vx va mv  va mz 各类型脚本/插件定制
回复

使用道具 举报

梦石
0
星屑
1433
在线时间
50 小时
注册时间
2020-2-16
回帖
85
 楼主| 发表于 2020-2-28 11:00:17 | 显示全部楼层
芯☆淡茹水 发表于 2020-2-27 14:36
@windows = {}
@windows[:command] = Window_Command.new()
@windows[:status] = Window_MenuStatus.new()

谢谢指点,
流飘零半生,未逢明主。公若是不弃,流愿拜为义父
回复

使用道具 举报

梦石
0
星屑
635
在线时间
244 小时
注册时间
2010-9-9
回帖
421
发表于 2020-2-28 11:23:23 | 显示全部楼层
本帖最后由 EngShun 于 2020-2-28 11:31 编辑

为什么大家都不用插入代码? _(:з」∠)_
这里来玩点不太黑的黑科技
  1. class StdObj < Hash
  2.   def method_missing(method, *args, &block)
  3.     if block
  4.         self.define_singleton_method method, &block
  5.     elsif(method.to_s[/([^\=]+)\=$/])
  6.         self[$1.to_sym] = args[0]
  7.     else
  8.         return self[method]
  9.     end
  10.   end
  11. end
  12. # ============== 我是华丽分割线 ==============
  13. @windows = StdClass.new

  14. @windows.command = Window_Command.new
  15. @windows.status = Window_MenuStatus.new

  16. @windows.dispose do
  17.   self.values.each {|w|w.dispose}
  18. end
复制代码

丢进数组其实不是很必要,毕竟效率低了 _(:з」∠)_

点评

@guoxiaomi 我不太记得xp的ruby版本了,反正那个定义函数的函数也不是那么重要就是了 \_(:з」∠)_  发表于 2020-2-29 00:02
xp里没有define_singleton_method,所以第4行会触发method_missing无限递归hhh  发表于 2020-2-28 17:03
回复

使用道具 举报

梦石
1
星屑
24088
在线时间
3339 小时
注册时间
2011-7-8
回帖
3862

开拓者

发表于 2020-2-28 17:02:41 | 显示全部楼层
@command_window和@window.command真的有什么区别吗,不过如果是数组的话,可能到后面很容易忘掉每个窗口都是啥了。

评分

参与人数 1赞 +1 收起 理由
EngShun + 1 我很赞同

查看全部评分

熟悉rgss和ruby,xp区版主~
正在填坑:《膜拜组传奇》讲述膜拜组和学霸们的故事。
已上steam:与TXBD合作的Reformers《变革者》
* 战斗调用公共事件 *
* RGSOS 网络脚本 *
回复

使用道具 举报

梦石
0
星屑
1433
在线时间
50 小时
注册时间
2020-2-16
回帖
85
 楼主| 发表于 2020-2-29 09:54:22 | 显示全部楼层
guoxiaomi 发表于 2020-2-28 17:02
@command_window和@window.command真的有什么区别吗,不过如果是数组的话,可能到后面很容易忘掉每个窗口都 ...

数数,编号1号2号。其实我在这里的意思就是这是我突发奇想的一东东,虽然会说实际意义不大,但愿留在这里会给不经意路过的人一个灵感
流飘零半生,未逢明主。公若是不弃,流愿拜为义父
回复

使用道具 举报

梦石
0
星屑
1433
在线时间
50 小时
注册时间
2020-2-16
回帖
85
 楼主| 发表于 2020-2-29 09:55:19 | 显示全部楼层
EngShun 发表于 2020-2-28 11:23
为什么大家都不用插入代码? _(:з」∠)_
这里来玩点不太黑的黑科技

请教一下 def method_missing(method, *args, &block)  的 * 和 & 什么意思
流飘零半生,未逢明主。公若是不弃,流愿拜为义父
回复

使用道具 举报

遠航の猫咪

梦石
3
星屑
26947
在线时间
2423 小时
注册时间
2005-10-15
回帖
987

开拓者

发表于 2020-2-29 13:35:47 | 显示全部楼层
看了一下我的SEP Core里关于XP的Scene_Base的实现,是这样的

[pre lang="ruby"]#==============================================================================
# ■ Scene_Base
#------------------------------------------------------------------------------
#   游戏中全部场景的公用模块。
#==============================================================================
module Scene_Base
  include SailCat::Core_Config
  #--------------------------------------------------------------------------
  # ● 主处理
  #--------------------------------------------------------------------------
  def main
    return unless need_create?
    SceneManager.start
    create
    post_create
    Graphics.transition unless @custom_transition
    update_scene until $scene != self
    Graphics.freeze
    pre_terminate
    terminate
  end
  #--------------------------------------------------------------------------
  # ● 建立预判
  #--------------------------------------------------------------------------
  def need_create?
    true
  end
  #--------------------------------------------------------------------------
  # ● 建立场景
  #--------------------------------------------------------------------------
  def create
    execute_method_set([:prepare_data, :create_spriteset,
      :create_all_sprites, :create_all_windows])
  end
  #--------------------------------------------------------------------------
  # ● 设置场景
  #--------------------------------------------------------------------------
  def post_create;      execute_method_set("post_create");        end
  #--------------------------------------------------------------------------
  # ● 更新场景
  #--------------------------------------------------------------------------
  def update_scene
    Graphics.update
    Input.update
    update
  end
  #--------------------------------------------------------------------------
  # ● 终止场景
  #--------------------------------------------------------------------------
  def pre_terminate;    execute_method_set("pre_terminate");      end
  #--------------------------------------------------------------------------
  # ● 结束场景
  #--------------------------------------------------------------------------
  def terminate
    dispose_spriteset
    dispose_all_sprites
    dispose_all_windows
    after_effect
  end
  #--------------------------------------------------------------------------
  # ● 更新窗口
  #--------------------------------------------------------------------------
  def update_all_windows
    ivar = instance_variables.map {|i| instance_variable_get(i)}.flatten
    ivar.each {|i| i.update if i.is_a?(Window) and not i.disposed?}
  end
  #--------------------------------------------------------------------------
  # ● 释放精灵组
  #--------------------------------------------------------------------------
  def dispose_spriteset
    ivar = instance_variables.map {|i| instance_variable_get(i)}.flatten
    ivar.each {|i| i.dispose if i.is_a?(Spriteset)}
  end
  #--------------------------------------------------------------------------
  # ● 释放精灵
  #--------------------------------------------------------------------------
  def dispose_all_sprites
    ivar = instance_variables.map {|i| instance_variable_get(i)}.flatten
    ivar.each do |i|
      if i.is_a?(Sprite) and not i.disposed?
        i.bitmap.dispose unless i.bitmap.disposed?
        i.dispose
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● 释放窗口
  #--------------------------------------------------------------------------
  def dispose_all_windows
    ivar = instance_variables.map {|i| instance_variable_get(i)}.flatten
    ivar.each {|i| i.dispose if i.is_a?(Window) and not i.disposed?}
  end
  #--------------------------------------------------------------------------
  # ● 结束效果
  #--------------------------------------------------------------------------
  def after_effect
  end
end[/pre]
SailCat (小猫子·要开心一点) 共上站 24 次,发表过 11 篇文章 上 次 在: [2006年01月28日11:41:18 星期六] 从 [162.105.120.91] 到本站一游。
回复

使用道具 举报

梦石
0
星屑
1433
在线时间
50 小时
注册时间
2020-2-16
回帖
85
 楼主| 发表于 2020-2-29 14:17:05 | 显示全部楼层
SailCat 发表于 2020-2-29 13:35
看了一下我的SEP Core里关于XP的Scene_Base的实现,是这样的

#========================================= ...

请教一下execute_method_set([:prepare_data, :create_spriteset,:create_all_sprites, :create_all_windows])
这个 execute_method_se t是方法,括号里面是实参,:prepare_data这个是什么
流飘零半生,未逢明主。公若是不弃,流愿拜为义父
回复

使用道具 举报

梦石
0
星屑
635
在线时间
244 小时
注册时间
2010-9-9
回帖
421
发表于 2020-2-29 16:56:05 | 显示全部楼层
轩辕合流 发表于 2020-2-29 09:55
请教一下 def method_missing(method, *args, &block)  的 * 和 & 什么意思


* 在参数内代表把后续的所有参数都放进一个数组,所以这里的 *args 代表了把 method 之后的所有参数都当成名为args的参数
运行一下下面的脚本你就会知道差别了
  1. def test1(*args)
  2.   p args
  3. end
  4. def test2(a, *b)
  5.   p a
  6.   p b
  7. end

  8. test1 1, 2, 3
  9. test2 1, 2, 3
复制代码

这里温馨提醒一下学脚本最有效的方法还是直接写了运行看看

而&block就比较不好解释了,所以我懒得解释 _(:з」∠)_
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部