| 赞 | 46 |
| VIP | |
| 好人卡 | |
| 积分 | 97 |
| 经验 | |
| 最后登录 | 2026-6-17 |
| 在线时间 | 2775 小时 |
梦石0
星屑9716
在线时间2775 小时
注册时间2008-9-5
回帖3458
   
|
发表于 2017-3-29 15:05:55
|
显示全部楼层
本帖最后由 cinderelmini 于 2017-3-30 14:47 编辑
一个不是很好但是便于理解(大概?)的方式,
首先在代码开头位置设定好每个词条名称以及词条明细说明内容,
(因为哈希表会乱序强行排序有点麻烦于是就用了两个数组了……)
然后监视列表窗口的index刷新右侧窗口就好了……
代码可以直接用,不过最好还是当成思路先理解一下吧……(
【代码在这】- module SNY46
-
- # 这里设定列表选项名称
- UnknowList = ["测试1", "测试2", "测试3", "测试4"]
-
- # 这里设定各个名称的说明明细内容
- # 必须与上面填的选项位置一一对应。
- # 明细可以用正则式控制符,具体参考对话文章说明,不过要加多一个斜杠。
- # 不过这样不能横向居中对齐。
- UnknowTesta = [
- # 明细1
- ["明细行1-1\\V[1]",
- "明细行1-2",
- "明细行1-3", ],
- # 明细2
- ["明细行2-1",
- "明细行2-2",
- "明细行2-3", ],
- # 明细3
- ["明细行3-1",
- "明细行3-2",
- "明细行3-3", ],
- # 明细4
- ["明细行4-1",
- "明细行4-2",
- "明细行4-3", ],
- #...以此格式往下添加
-
- ] # 明细设定结束
-
- end
- class Window_Testa < Window_Base
- #----------------------------------------------------------------------------
- # * 初始化
- #----------------------------------------------------------------------------
- def initialize
- super(160, 0, Graphics.width-160, Graphics.height)
- deactivate
- end
- #----------------------------------------------------------------------------
- # * 更新内容
- #----------------------------------------------------------------------------
- def refresh(command_index = 0)
- contents.clear
- testa_list = SNY46::UnknowTesta[command_index]
- testa_list.each_with_index do |text, i|
- cx = 0
- cy = line_height * i
- draw_text_ex(cx, cy, text)
- end
- end
- end
- class Window_Testleft < Window_Selectable
- # 设定公开变量
- attr_accessor :old_index
- # 初始化
- def initialize
- super(0, 0, window_width, window_height)
- refresh
- self.activate.select(0)
- end
- # 宽度
- def window_width
- return 160
- end
- # 高度
- def window_height
- return fitting_height(visible_line_number)
- end
- # 最大项目数
- def item_max
- return command_list.size
- end
- # 可见行数
- def visible_line_number
- return command_list.size
- end
- # 获取选项列表
- def command_list
- return SNY46::UnknowList
- end
- # 绘制项目
- def draw_item(index)
- rect = item_rect_for_text(index)
- draw_text(rect, command_list[index])
- end
- end
- 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(:cancel, method(:return_scene))
- end
- #--------------------------------------------------------------------------
- # ● 创建内容窗口
- #--------------------------------------------------------------------------
- def create_right_window
- @right_window = Window_Testa.new
- end
- # 更新所有窗口
- def update_all_windows
- super
- update_left_right
- end
- # 更新左右窗口关联
- def update_left_right
- return unless @list_window.old_index != @list_window.index
- @list_window.old_index = @list_window.index
- @right_window.refresh(@list_window.index)
- end
- end
复制代码
简单的几何学分界线
如果是要用变量或者开关之类的做分歧的话,
思路得换一下,也许下边这坨可以用……
把文本设定内容放在Window_Testa内部了,下拉可以看到。
这样的话不能用控制符(因为要居中),
不过事实上现在这样应该更灵活了……
【代码2】
- module SNY46
- # 这里设定列表选项名称
- UnknowList = ["测试1", "测试2", "测试3", "测试4"]
- end
- class Window_Testa < Window_Base
- #----------------------------------------------------------------------------
- # * 初始化
- #----------------------------------------------------------------------------
- def initialize
- super(160, 0, Graphics.width-160, Graphics.height)
- deactivate
- end
- #----------------------------------------------------------------------------
- # * 更新内容
- #----------------------------------------------------------------------------
- def refresh(command_index = 0)
- contents.clear
- testa_list = testa_detal(command_index)
- testa_list.each_with_index do |text, i|
- cx = 0
- cy = line_height * i
- draw_text(cx, cy, contents.width, line_height, text, 1)
- end
- end
- # 设置词条明细内容
- def testa_detal(command_index = 0)
- list = []
- # 这里设定各个名称的说明明细内容
- # 必须与上面填的选项位置一一对应。
- case command_index
- when 0
- # 明细1--------------------------------------
- list.push("明细行1-1")
- # 变量分歧的做法
- case $game_variables[1]
- when 0
- list.push("明细行1-2a")
- when 1
- list.push("明细行1-2b")
- when 2
- list.push("明细行1-2c")
- else
- list.push("明细行1-2d")
- end
- list.push("明细行1-3")
- when 1
- # 明细2--------------------------------------
- list.push("明细行2-1")
- # 开关分歧的做法
- if $game_switches[1]
- list.push("明细行2-2a")
- else
- list.push("明细行2-2b")
- end
- list.push("明细行2-3")
- when 2
- # 明细3--------------------------------------
- list.push("明细行3-1")
- list.push("明细行3-2:" + $game_variables[1].to_s) # 显示变量的做法
- list.push("明细行3-3")
- when 3
- # 明细4--------------------------------------
- list.push("明细行4-1")
- list.push("明细行4-2")
- list.push("明细行4-3")
- #...以此格式往下添加
-
- end # 明细设定结束
- return list
- end
- end
- class Window_Testleft < Window_Selectable
- # 设定公开变量
- attr_accessor :old_index
- # 初始化
- def initialize
- super(0, 0, window_width, window_height)
- refresh
- self.activate.select(0)
- end
- # 宽度
- def window_width
- return 160
- end
- # 高度
- def window_height
- return fitting_height(visible_line_number)
- end
- # 最大项目数
- def item_max
- return command_list.size
- end
- # 可见行数
- def visible_line_number
- return command_list.size
- end
- # 获取选项列表
- def command_list
- return SNY46::UnknowList
- end
- # 绘制项目
- def draw_item(index)
- rect = item_rect_for_text(index)
- draw_text(rect, command_list[index])
- end
- end
- 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(:cancel, method(:return_scene))
- end
- #--------------------------------------------------------------------------
- # ● 创建内容窗口
- #--------------------------------------------------------------------------
- def create_right_window
- @right_window = Window_Testa.new
- end
- # 更新所有窗口
- def update_all_windows
- super
- update_left_right
- end
- # 更新左右窗口关联
- def update_left_right
- return unless @list_window.old_index != @list_window.index
- @list_window.old_index = @list_window.index
- @right_window.refresh(@list_window.index)
- end
- end
复制代码 |
评分
-
查看全部评分
|