设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1623|回复: 3
打印 上一主题 下一主题

[已经解决] 命令窗口选择项太多,怎么让这些项目在窗口全部显示?

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
33 小时
注册时间
2011-9-17
帖子
24
跳转到指定楼层
1
发表于 2014-8-15 12:08:49 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

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

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

x
这个脚本是呼出两个简单的窗口,左边是命令窗口,如果命令窗口的项目个数很多,超过了窗体高度,怎么让这些项目文字压缩在窗口之内?




RUBY 代码复制
  1. class Window_mp_Command < Window_Selectable
  2.   def initialize(width, commands)
  3.     super(0, 0, width, 480)
  4.     @item_max = 15
  5.     @commands = commands
  6.     self.contents = Bitmap.new(width - 32, @item_max * 32)
  7.     refresh
  8.     self.index = 0
  9.   end
  10.  
  11.   def refresh
  12.     self.contents.clear
  13.     for i in 0...@item_max
  14.       draw_item(i, normal_color)
  15.     end
  16.   end
  17.  
  18.   def draw_item(index, color)
  19.     self.contents.font.color = color
  20.     rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
  21.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  22.     self.contents.draw_text(rect, @commands[index].to_s)
  23.   end
  24.  
  25.   def disable_item(index)
  26.     draw_item(index, disabled_color)
  27.   end
  28.   def able_item(index)
  29.     draw_item(index, normal_color)
  30.   end
  31. end
  32.  
  33. class Window_st < Window_Base
  34.   def initialize(actor)
  35.     super(0, 0, 460, 480)
  36.     self.contents = Bitmap.new(width - 32, height - 32)
  37.     @actor = actor
  38.   end  
  39. end
  40.  
  41. class Scene_st
  42.  
  43.   def initialize(actor_index = 0 , menu_index = 0)
  44.     @actor_index = actor_index
  45.     @menu_index = menu_index
  46.   end
  47.   #--------------------------------------------------------------------------
  48.   # ● 主处理
  49.   #--------------------------------------------------------------------------
  50.   def main
  51.     s1 = "项目1"
  52.     s2 = "项目2"
  53.     s3 = "项目3"
  54.     s4 = "项目4"
  55.     s5 = "项目5"
  56.     s6 = "项目6"
  57.     s7 = "项目7"
  58.     s8 = "项目8"
  59.     s9 = "项目9"
  60.     s10 = "项目10"
  61.     s11 = "项目11"
  62.     s12 = "项目12"
  63.     s13 = "项目13"
  64.     s14 = "项目14"
  65.     s15 = "项目15"
  66.     @command_window = Window_mp_Command.new(180, [s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15])
  67.     @command_window.index = @menu_index
  68.     @command_window.x = 0
  69.     @st_window = Window_st.new(@actor)
  70.     @st_window.x = 180
  71.     @st_window.y = 0
  72.     Graphics.transition
  73.     # 主循环
  74.     loop do# 刷新游戏画面      
  75.       Graphics.update     
  76.       Input.update # 刷新输入信息      
  77.       update# 刷新画面   
  78.       if $scene != self # 如果切换画面就中断循环
  79.         break
  80.       end
  81.     end
  82.     # 准备过渡
  83.     Graphics.freeze# 释放窗口   
  84.     @command_window.dispose
  85.     @st_window.dispose
  86.     # 释放背景
  87.     end
  88.   #--------------------------------------------------------------------------
  89.   # ● 刷新画面
  90.   #--------------------------------------------------------------------------
  91.   def update
  92.     # 刷新窗口
  93.     @command_window.update
  94.     if Input.trigger?(Input::B)
  95.       $game_system.se_play($data_system.cancel_se)
  96.       @command_window.index = 14
  97.       return
  98.     end
  99.   end
  100. end

评分

参与人数 1星屑 +35 收起 理由
︶ㄣ牛排ぶ + 35 手动认可奖励

查看全部评分

Lv1.梦旅人

梦石
0
星屑
76
在线时间
1379 小时
注册时间
2012-7-5
帖子
1698

开拓者

2
发表于 2014-8-15 12:44:50 | 只看该作者
解决方案1 字变小
self.contents.font.size = 12

点评

仅仅变小是不行地,还要注意行距的问题,draw_text(x,y,width,height,"")你懂的  发表于 2014-8-15 13:12

  -fk: -azogi:
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
33 小时
注册时间
2011-9-17
帖子
24
3
 楼主| 发表于 2014-8-15 13:28:09 | 只看该作者
只把字改小了没用啊,行距应该怎么改?
回复 支持 反对

使用道具 举报

Lv4.逐梦者 (版主)

梦石
0
星屑
9532
在线时间
5073 小时
注册时间
2013-6-21
帖子
3580

开拓者贵宾剧作品鉴家

4
发表于 2014-8-15 13:46:13 | 只看该作者
首先,因为你这个行距行高都发生了变化,而默认的Window_Selectable行高定死为32,所以先要改动Window_Selectable
参考我在这个帖子的回复:
https://rpg.blue/thread-369336-1-3.html
覆盖一下Window_Selectable,这个是WIndow_Selectable的加强版,可以自定义行高,不会发生光标或者排版错乱的问题。
然后我们就可以改自己的脚本了。
首先你的Window_mp_Command的initialize有个super(0,0,width,480)对不,现在改成
  1. super(0,0,width,480,24)
复制代码
最后那个24是行高。不写的话默认是32.
然后就是draw_item方法了,修改成这样:
  1. def draw_item(index, color)
  2.   self.contents.font.size = 18 # 改成18号字,可以调节
  3.   self.contents.font.color = color
  4.   rect = Rect.new(4, 24 * index, self.contents.width - 8, 24) # 行高是24,为了达到比较好的视觉效果,行高建议设置为:字号*4/3
  5.   self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  6.   self.contents.draw_text(rect, @commands[index].to_s)
  7. end
复制代码
这回应该没问题了。

评分

参与人数 2星屑 +212 收起 理由
︶ㄣ牛排ぶ + 200 认可答案
kuerlulu + 12 尽职的版主

查看全部评分

回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-9-21 20:42

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表