查看: 2939|回复: 10

[已经解决] 请问Window类的翻页是怎么实现的?

[复制链接]
梦石
0
星屑
129
在线时间
219 小时
注册时间
2011-1-19
回帖
92
发表于 2016-7-23 16:44:41 | 显示全部楼层 |阅读模式

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

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

×
我想要做一个诗词系统, 先写了一个选诗词的界面,大致的效果是这样的:(选项框应该要把两行字都包进去)
未命名.JPG

我是几乎模仿着Window_Item写的,只不过它里面获取物品信息的部分我是直接用常量来搞的,但是不知道为什么,它的光标不能动。一直在闪烁但是不移动,感觉好像是项目数量的问题,貌似这个选项窗口的选项数量被默认成了1(我的猜测)。

请大神帮忙看一看怎么解决。(下面把源代码贴上。有些比较蠢的地方,多多指教= =)

  1. module Poem
  2.   # 诗词的标题
  3.   POEM_TOPIC = ["登高", "行路难","","","","","","","","","","","","","","","","","","","","11","","","22","22","22","","11","","","22","22","22","","11","","","22","22","22","","11","","","22","22","22"]   
  4.   # 诗词的作者
  5.   POEM_AUTHOR = ["[唐]杜甫", "[唐]李白","","","","","","","","","","","","","","","","","","","","11","","","22"]   
  6.   # 诗词的内容
  7.   POEM_CONTENT = []  
  8.   POEM_CONTENT[0] = "风急天高猿啸哀,渚清沙白鸟飞回。
  9. 无边落木萧萧下,不尽长江滚滚来。
  10. 万里悲秋常作客,百年多病独登台。
  11. 艰难苦恨繁霜鬓,潦倒新停浊酒杯。"
  12.   POEM_CONTENT[1] = "金樽清酒斗十千,玉盘珍羞直万钱。
  13. 停杯投箸不能食,拔剑四顾心茫然。
  14. 欲渡黄河冰塞川,将登太行雪满山。
  15. 闲来垂钓碧溪上,忽复乘舟梦日边。
  16. 行路难!行路难!多歧路,今安在?
  17. 长风破浪会有时,直挂云帆济沧海。"

  18.   # 用于出题的句子
  19.   POEM_TESTSEN1 = ["万里悲秋常作客","长风破浪会有时"]  # 每首诗词用于出题的句子上半句
  20.   POEM_TESTSEN2 = ["百年多病独登台","直挂云帆济沧海"]  # 每首诗词用于出题的句子下半句
  21. end

  22. class Game_Party
  23.   attr_accessor :poem_get   # 诗词的拥有状态
  24.   attr_accessor :poem_use   # 诗词的使用状态
  25.   alias old_initialize initialize
  26.   def initialize
  27.     old_initialize
  28.     @poem_get = []
  29.     @poem_use = []
  30.     num = Poem::POEM_TOPIC.size
  31.     for i in 0...num
  32.       @poem_get.push false
  33.       @poem_use.push false
  34.     end
  35.   end
  36. end


  37. class Window_PoemSel < Window_Selectable
  38.   def initialize
  39.     super(0, 0, 640, 480)
  40.     @column_max = 3
  41.     @poem_max = Poem::POEM_TOPIC.size
  42.     refresh
  43.     self.index = 0
  44.   end
  45.   def refresh
  46.     if self.contents != nil
  47.       self.contents.dispose
  48.       self.contents = nil
  49.     end
  50.     self.contents = Bitmap.new(640 - 32, 480 - 32)
  51.     #@title = []
  52.     #@author = []
  53.     for i in 0...Poem::POEM_TOPIC.size
  54.       if $game_party.poem_get[i] == true
  55.         @title = Poem::POEM_TOPIC[i]
  56.         @author = Poem::POEM_AUTHOR[i]
  57.       end
  58.       if $game_party.poem_get[i] == false
  59.         @title = "???"
  60.         @author = "[?]???"
  61.       end
  62.       draw_poem(i)
  63.     end
  64.   end
  65.   
  66.   def draw_poem(index)
  67.     # 颜色  选中为系统色,拥有但未选中为普通色,未拥有为无效色
  68.     if $game_party.poem_use[index] == true
  69.       self.contents.font.color = system_color
  70.     end
  71.     if $game_party.poem_use[index] == false
  72.       if  $game_party.poem_get[index] == true
  73.         self.contents.font.color = normal_color
  74.       else
  75.         self.contents.font.color = disabled_color
  76.       end
  77.     end
  78.     x = 4 + (index % 3) * 213
  79.     y = (index / 3) * 64
  80.     rect = Rect.new(x, y, self.width / @poem_max - 32, 60)
  81.     self.contents.fill_rect(rect, Color.new(0,0,0,0))
  82.     self.contents.draw_text(x, y, 197, 32, @title,1)
  83.     self.contents.draw_text(x, y+32, 197, 32, @author,1)
  84.   end
  85. end

  86. # 四 选诗词场景
  87. class Scene_PoemSel
  88.   def main
  89.     @poem_window = Window_PoemSel.new
  90.     @poem_window.active = true
  91.     #================================================
  92.     Graphics.transition
  93.     loop do
  94.       Graphics.update
  95.       Input.update
  96.       update
  97.       if $scene != self
  98.         break
  99.       end
  100.     end
  101.     Graphics.freeze
  102.     #================================================
  103.     @poem_window.dispose
  104.   end
  105.   
  106.   def update
  107.     if Input.trigger?(Input::B)
  108.       $scene = Scene_Map.new
  109.     end
  110.     @poem_window.update
  111.    
  112.   end
  113. end
复制代码


请大家看一下,为什么不会动= =谢谢!
本人渣渣一枚,求个合伙人  一起做游戏,有意者联系QQ 980497385
梦石
0
星屑
9557
在线时间
5074 小时
注册时间
2013-6-21
回帖
3459

开拓者贵宾剧作品鉴家

发表于 2016-7-23 17:01:36 | 显示全部楼层
45行改成
  1. @item_max = Poem::POEM_TOPIC.size
复制代码

因为@item_max才是表示最多选项数的内部变量,不要动这个地方。

另外RMXP的翻页只支持默认行高为32的情况,对于行高不是32的情况必须要改动Window_Selectable里面的相关方法。

点评

把你改动的代码发到这里来 我稍后看看。  发表于 2016-7-24 13:51
那个下午做的着急没注意,还有一个小问题,向下翻一行之后光标正常了可是下面不出文字是怎么回事  发表于 2016-7-23 21:48
哦哦哦没事了我弄好了 谢谢RB大神~~  发表于 2016-7-23 17:20
我记得是有个方法叫update_cursor_rect,你在里面找一下。  发表于 2016-7-23 17:20
再按下就会跑到界面之外,请问这个该怎么改?  发表于 2016-7-23 17:17
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部