查看: 2410|回复: 12

[已经解决] 请教下用脚本做列表窗口的问题

[复制链接]
梦石
0
星屑
2019
在线时间
940 小时
注册时间
2015-10-26
回帖
293

开拓者

发表于 2017-3-29 13:18:25 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 踢腿水上飘 于 2017-3-29 14:22 编辑

意思左边是列表,右边是内容,我模仿了好几个类似模式的脚本写都失败了- -
求个教程啊
我只弄到把窗口画出来这一步……后面就抓瞎了,什么都弄不出来啊,求个教程,怎么弄
效果就是 左边的窗口是词条,右边的窗口是词条的内容
比方左边是是测试1,测试2,测试3,选到测试1  右边就是显示 测试1测试1  这样

请指教下,下面这个是我仿照别人的脚本弄的,结果我仿造别人的脚本  只弄出2个空的窗口,左边有测试1,测试2,测试3,但右边的窗口内容就不会做了……

测试内容
[pre lang="ruby"]    class Window_testa < Window_Selectable
      #----------------------------------------------------------------------------
      # * 初始化
      #----------------------------------------------------------------------------
      def initialize
        super(160, 0, Graphics.width-160, Graphics.height)
        refresh
        activate
      end
      #----------------------------------------------------------------------------
      # * 更新内容
      #----------------------------------------------------------------------------
      def refresh
        draw_text(x, y, Graphics.width, line_height, "测试1测试1", 1)
        draw_text(x, y, Graphics.width, line_height, "测试2测试2", 1)
        draw_text(x, y, Graphics.width, line_height, "测试3测试3", 1)
      end
    end[/pre]


测试列表
[pre lang="ruby"]class Window_testleft < Window_Command
  def initialize
    super(0,0)
  end  
#宽度
    def window_width
    return 160
  end
  #高度
  
    def window_height
    return 240
  end
#指令
    def make_command_list
    add_command("测试1", :aaa)
    add_command("测试2", :bbb)
    add_command("测试3", :ccc)
  end
end[/pre]


创建测试窗口
[pre lang="ruby"]class Testlist < Scene_Base
  #--------------------------------------------------------------------------
  # ● 场景开始
  #--------------------------------------------------------------------------
  def start
    super
    create_list_window
    create_right_window
  end
  #--------------------------------------------------------------------------
  # ● 创建列表
  #--------------------------------------------------------------------------
  def create_list_window
    @list_window = Window_testleft.new
    @list_window.set_handler(:ok,     method(:on_category_ok))
    @list_window.set_handler(:cancel, method(:return_scene))
  end
  #--------------------------------------------------------------------------
  # ● 创建内容窗口
  #--------------------------------------------------------------------------
  def create_right_window
    @right_window = Window_testa.new
  end
  #--------------------------------------------------------------------------
  # ● 选择完成类型
  #--------------------------------------------------------------------------
    def on_category_ok
    @list_window.activate
#    @list_window.select_last
  end
  #--------------------------------------------------------------------------
  # ● 更新
  #--------------------------------------------------------------------------
  def update
    super
    create_right_window
  end
end[/pre]

老鹰

梦石
40
星屑
37812
在线时间
7091 小时
注册时间
2012-5-26
回帖
3297

极短24评委极短23参与极短22参与极短21评委老司机慢点开短篇十吟唱者组别冠军开拓者剧作品鉴家

发表于 2017-3-29 14:07:46 | 显示全部楼层
参考默认的help window以及各个地方的窗口绑定个help window后的操作(如item window)

点评

看了还是抓瞎啊……  发表于 2017-3-29 14:33
回复

使用道具 举报

梦石
0
星屑
9716
在线时间
2775 小时
注册时间
2008-9-5
回帖
3458

开拓者短篇八RM组冠军短篇九导演组亚军白银编剧

发表于 2017-3-29 15:05:55 | 显示全部楼层
本帖最后由 cinderelmini 于 2017-3-30 14:47 编辑

一个不是很好但是便于理解(大概?)的方式,
首先在代码开头位置设定好每个词条名称以及词条明细说明内容,
(因为哈希表会乱序强行排序有点麻烦于是就用了两个数组了……)
然后监视列表窗口的index刷新右侧窗口就好了……
代码可以直接用,不过最好还是当成思路先理解一下吧……(
【代码在这】
  1. module SNY46
  2.   
  3.   # 这里设定列表选项名称
  4.   UnknowList = ["测试1", "测试2", "测试3", "测试4"]
  5.   
  6.   # 这里设定各个名称的说明明细内容
  7.   # 必须与上面填的选项位置一一对应。
  8.   # 明细可以用正则式控制符,具体参考对话文章说明,不过要加多一个斜杠。
  9.   # 不过这样不能横向居中对齐。
  10.   UnknowTesta = [
  11.   # 明细1
  12.   ["明细行1-1\\V[1]",
  13.   "明细行1-2",
  14.   "明细行1-3", ],
  15.   # 明细2
  16.   ["明细行2-1",
  17.   "明细行2-2",
  18.   "明细行2-3", ],
  19.   # 明细3
  20.   ["明细行3-1",
  21.   "明细行3-2",
  22.   "明细行3-3", ],
  23.   # 明细4
  24.   ["明细行4-1",
  25.   "明细行4-2",
  26.   "明细行4-3", ],
  27.   #...以此格式往下添加
  28.   
  29.   ] # 明细设定结束
  30.   
  31. end

  32. class Window_Testa < Window_Base
  33.   #----------------------------------------------------------------------------
  34.   # * 初始化
  35.   #----------------------------------------------------------------------------
  36.   def initialize
  37.     super(160, 0, Graphics.width-160, Graphics.height)
  38.     deactivate
  39.   end
  40.   #----------------------------------------------------------------------------
  41.   # * 更新内容
  42.   #----------------------------------------------------------------------------
  43.   def refresh(command_index = 0)
  44.     contents.clear
  45.     testa_list = SNY46::UnknowTesta[command_index]
  46.     testa_list.each_with_index do |text, i|
  47.       cx = 0
  48.       cy = line_height * i
  49.       draw_text_ex(cx, cy, text)
  50.     end
  51.   end
  52. end



  53. class Window_Testleft < Window_Selectable
  54.   # 设定公开变量
  55.   attr_accessor :old_index
  56.   # 初始化
  57.   def initialize
  58.     super(0, 0, window_width, window_height)
  59.     refresh
  60.     self.activate.select(0)
  61.   end  
  62.   # 宽度
  63.   def window_width
  64.     return 160
  65.   end
  66.   # 高度
  67.   def window_height
  68.     return fitting_height(visible_line_number)
  69.   end
  70.   # 最大项目数
  71.   def item_max
  72.     return command_list.size
  73.   end
  74.   # 可见行数
  75.   def visible_line_number
  76.     return command_list.size
  77.   end
  78.   # 获取选项列表
  79.   def command_list
  80.     return SNY46::UnknowList
  81.   end
  82.   # 绘制项目
  83.   def draw_item(index)
  84.     rect = item_rect_for_text(index)
  85.     draw_text(rect, command_list[index])
  86.   end
  87. end





  88. class Testlist < Scene_Base
  89.   #--------------------------------------------------------------------------
  90.   # ● 场景开始
  91.   #--------------------------------------------------------------------------
  92.   def start
  93.     super
  94.     create_list_window
  95.     create_right_window
  96.   end
  97.   #--------------------------------------------------------------------------
  98.   # ● 创建列表
  99.   #--------------------------------------------------------------------------
  100.   def create_list_window
  101.     @list_window = Window_Testleft.new
  102.     @list_window.set_handler(:cancel, method(:return_scene))
  103.   end
  104.   #--------------------------------------------------------------------------
  105.   # ● 创建内容窗口
  106.   #--------------------------------------------------------------------------
  107.   def create_right_window
  108.     @right_window = Window_Testa.new
  109.   end
  110.   # 更新所有窗口
  111.   def update_all_windows
  112.     super
  113.     update_left_right
  114.   end
  115.   # 更新左右窗口关联
  116.   def update_left_right
  117.     return unless @list_window.old_index != @list_window.index
  118.     @list_window.old_index = @list_window.index
  119.     @right_window.refresh(@list_window.index)
  120.   end
  121. end
复制代码



简单的几何学分界线

如果是要用变量或者开关之类的做分歧的话,
思路得换一下,也许下边这坨可以用……

把文本设定内容放在Window_Testa内部了,下拉可以看到。
这样的话不能用控制符(因为要居中),
不过事实上现在这样应该更灵活了……

【代码2】

  1. module SNY46
  2.   # 这里设定列表选项名称
  3.   UnknowList = ["测试1", "测试2", "测试3", "测试4"]
  4. end

  5. class Window_Testa < Window_Base
  6.   #----------------------------------------------------------------------------
  7.   # * 初始化
  8.   #----------------------------------------------------------------------------
  9.   def initialize
  10.     super(160, 0, Graphics.width-160, Graphics.height)
  11.     deactivate
  12.   end
  13.   #----------------------------------------------------------------------------
  14.   # * 更新内容
  15.   #----------------------------------------------------------------------------
  16.   def refresh(command_index = 0)
  17.     contents.clear
  18.     testa_list = testa_detal(command_index)
  19.     testa_list.each_with_index do |text, i|
  20.       cx = 0
  21.       cy = line_height * i
  22.       draw_text(cx, cy, contents.width, line_height, text, 1)
  23.     end
  24.   end
  25.   # 设置词条明细内容
  26.   def testa_detal(command_index = 0)
  27.     list = []
  28.     # 这里设定各个名称的说明明细内容
  29.     # 必须与上面填的选项位置一一对应。
  30.     case command_index
  31.     when 0
  32.       # 明细1--------------------------------------
  33.       list.push("明细行1-1")
  34.       # 变量分歧的做法
  35.       case $game_variables[1]
  36.       when 0
  37.         list.push("明细行1-2a")
  38.       when 1
  39.         list.push("明细行1-2b")
  40.       when 2
  41.         list.push("明细行1-2c")
  42.       else
  43.         list.push("明细行1-2d")
  44.       end
  45.       list.push("明细行1-3")
  46.     when 1
  47.       # 明细2--------------------------------------
  48.       list.push("明细行2-1")
  49.       # 开关分歧的做法
  50.       if $game_switches[1]
  51.         list.push("明细行2-2a")
  52.       else
  53.         list.push("明细行2-2b")
  54.       end
  55.       list.push("明细行2-3")
  56.     when 2
  57.       # 明细3--------------------------------------
  58.       list.push("明细行3-1")
  59.       list.push("明细行3-2:" + $game_variables[1].to_s) # 显示变量的做法
  60.       list.push("明细行3-3")
  61.     when 3
  62.       # 明细4--------------------------------------
  63.       list.push("明细行4-1")
  64.       list.push("明细行4-2")
  65.       list.push("明细行4-3")
  66.     #...以此格式往下添加
  67.   
  68.     end # 明细设定结束
  69.     return list
  70.   end
  71. end



  72. class Window_Testleft < Window_Selectable
  73.   # 设定公开变量
  74.   attr_accessor :old_index
  75.   # 初始化
  76.   def initialize
  77.     super(0, 0, window_width, window_height)
  78.     refresh
  79.     self.activate.select(0)
  80.   end  
  81.   # 宽度
  82.   def window_width
  83.     return 160
  84.   end
  85.   # 高度
  86.   def window_height
  87.     return fitting_height(visible_line_number)
  88.   end
  89.   # 最大项目数
  90.   def item_max
  91.     return command_list.size
  92.   end
  93.   # 可见行数
  94.   def visible_line_number
  95.     return command_list.size
  96.   end
  97.   # 获取选项列表
  98.   def command_list
  99.     return SNY46::UnknowList
  100.   end
  101.   # 绘制项目
  102.   def draw_item(index)
  103.     rect = item_rect_for_text(index)
  104.     draw_text(rect, command_list[index])
  105.   end
  106. end





  107. class Testlist < Scene_Base
  108.   #--------------------------------------------------------------------------
  109.   # ● 场景开始
  110.   #--------------------------------------------------------------------------
  111.   def start
  112.     super
  113.     create_list_window
  114.     create_right_window
  115.   end
  116.   #--------------------------------------------------------------------------
  117.   # ● 创建列表
  118.   #--------------------------------------------------------------------------
  119.   def create_list_window
  120.     @list_window = Window_Testleft.new
  121.     @list_window.set_handler(:cancel, method(:return_scene))
  122.   end
  123.   #--------------------------------------------------------------------------
  124.   # ● 创建内容窗口
  125.   #--------------------------------------------------------------------------
  126.   def create_right_window
  127.     @right_window = Window_Testa.new
  128.   end
  129.   # 更新所有窗口
  130.   def update_all_windows
  131.     super
  132.     update_left_right
  133.   end
  134.   # 更新左右窗口关联
  135.   def update_left_right
  136.     return unless @list_window.old_index != @list_window.index
  137.     @list_window.old_index = @list_window.index
  138.     @right_window.refresh(@list_window.index)
  139.   end
  140. end
复制代码

点评

你把那个 < Scene_Base改成 < Scene_MenuBase就好了  发表于 2017-3-30 16:29
啊,现在这样好多了,对了,我的其他界面背景都是透明的,但这个背景是黑色的,这个在哪里设置?  发表于 2017-3-30 16:02
弄了个版本2…………也许能满足需求?  发表于 2017-3-30 14:47
并且改了以后就没法居中对齐了,在text后面加上,1就报错,也没办法一行打2个内容一个靠左一个靠右对齐,总之内容很不灵活,不过还是多谢你了  发表于 2017-3-30 00:02
嗯,改过后的确可以显示变量了,不过还是没有达到我的目的,我希望在内容那里可以使用条件分歧,比方if $game_variables[1]>=1 xx else xx这样的。  发表于 2017-3-29 23:59

评分

参与人数 2星屑 +1 梦石 +1 收起 理由
RaidenInfinity + 1 认可答案
踢腿水上飘 + 1 塞糖

查看全部评分

回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部