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

Project1

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

GPRA_Window_Message 07.04.04 改

 关闭 [复制链接]

Lv1.梦旅人

劒剋

梦石
0
星屑
50
在线时间
27 小时
注册时间
2007-12-16
帖子
1304
跳转到指定楼层
1
发表于 2007-12-31 07:32:58 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
  1. #==============================================================================
  2. # ◎ GPRA_Window_Message
  3. #------------------------------------------------------------------------------
  4. # ◎ 显示文章的信息窗口加强。
  5. #------------------------------------------------------------------------------
  6. # 制作者:绿梨子红苹果
  7. # 个人主页:vbgm.9126.com
  8. # E-Mail:[email protected]
  9. # QQ:42378361
  10. #==============================================================================
  11. class Window_Message < Window_Selectable
  12. #--------------------------------------------------------------------------
  13. # ● 初始化状态
  14. #--------------------------------------------------------------------------
  15. MODE = 51
  16. AUTOCLOSE = 52
  17. TYPEMODE = 53
  18. def initialize
  19. super(80, 304, 480, 160)
  20. self.contents = Bitmap.new(width - 32, height - 32)
  21. self.visible = false
  22. self.z = 9998
  23. @fade_in = false
  24. @fade_out = false
  25. @contents_showing = false
  26. @cursor_width = 0
  27. @op = 255 # 不透明度
  28. @head_bmp = nil # 装载头像用
  29. @head_file = nil # 头像文件名
  30. @text = nil # 记录所处理文字
  31. @skip = false # 记录是否跳过此次对话
  32. @auto_close = -1 # 默认不打开自动关闭
  33. @type_mode=-1 # 打字模式
  34. @delay=-1 # 等待n帧标志
  35. @finish=false # 记录文字处理是否结束
  36. @ts = TextStream.new # 创建一个新的TXT读取流
  37. @is_read_txt =false # 默认不是在读取txt文件
  38. self.active = false
  39. self.index = -1
  40. end
  41. #--------------------------------------------------------------------------
  42. # ● 释放
  43. #--------------------------------------------------------------------------
  44. def dispose
  45. terminate_message
  46. $game_temp.message_window_showing = false
  47. if @input_number_window != nil
  48. @input_number_window.dispose
  49. end
  50. super
  51. end
  52. #--------------------------------------------------------------------------
  53. # ● 处理信息结束
  54. #--------------------------------------------------------------------------
  55. def terminate_message
  56. self.active = false
  57. self.pause = false
  58. self.index = -1
  59. self.contents.clear
  60. # 清除显示中标志
  61. @contents_showing = false
  62. # 呼叫信息调用
  63. if $game_temp.message_proc != nil
  64. $game_temp.message_proc.call
  65. end
  66. # 清除文章、选择项、输入数值的相关变量
  67. $game_temp.message_text = nil
  68. $game_temp.message_proc = nil
  69. $game_temp.choice_start = 99
  70. $game_temp.choice_max = 0
  71. $game_temp.choice_cancel_type = 0
  72. $game_temp.choice_proc = nil
  73. $game_temp.num_input_start = 99
  74. $game_temp.num_input_variable_id = 0
  75. $game_temp.num_input_digits_max = 0
  76. # 开放金钱窗口
  77. if @gold_window != nil
  78. @gold_window.dispose
  79. @gold_window = nil
  80. end
  81. end
  82. #--------------------------------------------------------------------------
  83. # ● 刷新
  84. #--------------------------------------------------------------------------
  85. def refresh
  86. # 清空原先内容
  87. self.contents.clear
  88. # 恢复一般字色
  89. self.contents.font.color = normal_color
  90. # 恢复字体大小
  91. self.contents.font.size = 20
  92. # 绘制文字位置初始化
  93. @x = @y = 0
  94. # 字体高度记录
  95. @height = 32
  96. # 文字不透明度设定为255
  97. @op = 255
  98. # 头像默认显示在右边
  99. @right = true
  100. # 头像默认显示一般表情
  101. @face = nil
  102. # 默认显示角色姓名
  103. @name = nil
  104. # 默认不跳过此次对话
  105. @skip = false
  106. # 从变量读取自动关闭设置
  107. @auto_close = $game_variables[AUTOCLOSE]
  108. # 从变量读取打字模式设置
  109. @type_mode=$game_variables[TYPEMODE]
  110. # 默认不等待
  111. @delay=-1
  112. # 设定文字没有处理结束
  113. @finish=false
  114. # 光标宽度初始化为零
  115. @cursor_width = 0
  116. # 到选择项的下一行字
  117. if $game_temp.choice_start == 0
  118. @x = 16
  119. end
  120. # 有等待显示的文字的情况下
  121. # (注:因为一旦文字非空就处理,所以可以设定 $game_temp.message_text 达到显示文章的效果)
  122. if $game_temp.message_text != nil
  123. # @text 功能改进
  124. if @text==nil or @text==""
  125. @text = $game_temp.message_text.dup
  126. else
  127. @text = @text + $game_temp.message_text
  128. end
  129. # 最先必须要将 "\\\\" 变换为 "\000"
  130. @text.gsub!(/\\\\/) { "\000" }
  131. # 在TXT模式还没有打开的时候
  132. if !@is_read_txt
  133. # TXT读取模式打开
  134. if @text.slice!(/\\[Tt][Xx][Tt]\[(\w+)\]\[(\w+)\]/)!=nil
  135. # 打开文件,成功打开后再进入后面部分
  136. if @ts.open($1,$2)
  137. # 根据显示模式确定需要打开行数
  138. case $game_variables[MODE]
  139. when 0 # 正常模式
  140. @text = @ts.get_text(4)
  141. when 1 # 图书模式
  142. @text = @ts.get_text(12)
  143. when 2 # 全屏模式
  144. @text = @ts.get_text(15)
  145. end
  146. # 如果包含[END]
  147. if @text.gsub!(/\[END\]/){""}!=nil
  148. #退出TXT读取模式
  149. @is_read_txt=false
  150. else
  151. #否则设置正在读取标志
  152. @is_read_txt=true
  153. end
  154. end
  155. else
  156. if @text.slice!(/\\[Tt][Xx][Tt]\[(\w+)\]/)!=nil
  157. # 打开文件,成功打开后再进入后面部分
  158. if @ts.open($1,"")
  159. # 根据显示模式确定需要打开行数
  160. case $game_variables[MODE]
  161. when 0 # 正常模式
  162. @text = @ts.get_text(4)
  163. when 1 # 图书模式
  164. @text = @ts.get_text(12)
  165. when 2 # 全屏模式
  166. @text = @ts.get_text(15)
  167. end
  168. # 如果包含[END]
  169. if @text.gsub!(/\[END\]/){""}!=nil
  170. #退出TXT读取模式
  171. @is_read_txt=false
  172. else
  173. #否则设置正在读取标志
  174. @is_read_txt=true
  175. end
  176. end
  177. end
  178. end
  179. end
  180. # 如果取得的字符含"\\~"时
  181. if @text.slice!(/\\~/)!=nil
  182. # 跳过此次对话
  183. terminate_message
  184. # 设置跳过此次对话标志
  185. @skip = true
  186. # 直接返回等待连接后面部分
  187. return
  188. end
  189. # 限制文字处理(注:这里是默认功能。)
  190. begin
  191. last_text = @text.clone
  192. @text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  193. end until @text == last_text
  194. @text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  195. $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  196. end
  197. #(注:后面将单个字符循环判断,所以这里将控制符全部换成单个字符)
  198. # 为了方便将 "\\C" 变为 "\001"
  199. @text.gsub!(/\\[Cc]\[([0-9#a-zA-Z]+)\]/) { "\001[#{$1}]" }
  200. # "\\G" 变为 "\002"
  201. @text.gsub!(/\\[Gg]/) { "\002" }
  202. # ========================增强功能========================
  203. # "\\/" 删除行尾换行符号
  204. @text.gsub!(/\\\/\n/) {""}
  205. # 去掉不在行尾的"\\/"符号,防止出错
  206. @text.gsub!(/\\\//) {""}
  207. # "\\I" 物品图标+名称显示
  208. @text.gsub!(/\\[Ii]\[([0-9]+)\]/) { "\003[#{$1}]"+$data_items[$1.to_i].name }
  209. # "\\K" 技能图标+名称显示
  210. @text.gsub!(/\\[Kk]\[([0-9]+)\]/) { "\004[#{$1}]"+$data_skills[$1.to_i].name }
  211. # "\\W" 武器图标+名称显示
  212. @text.gsub!(/\\[Ww]\[([0-9]+)\]/) { "\005[#{$1}]"+$data_weapons[$1.to_i].name }
  213. # "\\A" 防具图标+名称显示
  214. @text.gsub!(/\\[Dd]\[([0-9]+)\]/) { "\006[#{$1}]"+$data_armors[$1.to_i].name }
  215. # 注:大量显示图片将是游戏的速度大大减慢
  216. # "\\I1" 物品图标显示
  217. @text.gsub!(/\\[Ii]1\[([0-9]+)\]/) { "\003[#{$1}]" }
  218. # "\\K1" 技能图标显示
  219. @text.gsub!(/\\[Kk]1\[([0-9]+)\]/) { "\004[#{$1}]" }
  220. # "\\W1" 武器图标显示
  221. @text.gsub!(/\\[Ww]1\[([0-9]+)\]/) { "\005[#{$1}]" }
  222. # "\\A1" 防具图标显示
  223. @text.gsub!(/\\[Dd]1\[([0-9]+)\]/) { "\006[#{$1}]" }
  224. # "\\I2" 物品名称显示
  225. @text.gsub!(/\\[Ii]2\[([0-9]+)\]/) { $data_items[$1.to_i].name }
  226. # "\\K2" 技能名称显示
  227. @text.gsub!(/\\[Kk]2\[([0-9]+)\]/) { $data_skills[$1.to_i].name }
  228. # "\\W2" 武器名称显示
  229. @text.gsub!(/\\[Ww]2\[([0-9]+)\]/) { $data_weapons[$1.to_i].name }
  230. # "\\A2" 防具名称显示
  231. @text.gsub!(/\\[Dd]2\[([0-9]+)\]/) { $data_armors[$1.to_i].name }
  232. # "\\S" 字体大小(只修改第一个"\\S")
  233. # 这里首先删掉能找到的第一个"\\S"
  234. if @text.slice!(/\\[Ss]\[([0-9]+)\]/)!=nil
  235. # 当找了"\\S"时满足上述条件,就设置文字大小
  236. self.set_font_size($1.to_i)
  237. end
  238. # "\\O" 文字透明度(使用注意同上,模拟声音变小……)
  239. if @text.slice!(/\\[Oo]\[([0-9]+)\]/)!=nil
  240. self.set_font_op($1.to_i)
  241. end
  242. # "\\=" 停顿固定帧(延时)
  243. @text.gsub!(/\\=\[([0-9]+)\]/) { "\024[#{$1}]" }
  244. # "\\." 停顿3帧
  245. @text.gsub!(/\\\./) { "\024[3]" }
  246. # "\\_" 停顿1秒(30帧)
  247. @text.gsub!(/\\_/) { "\024[30]" }
  248. # "\\L" 指定头像左边显示
  249. if @text.slice!(/\\[Ll]/)!=nil
  250. # 设定头像居右标志为假
  251. @right=false
  252. # 顺便要设置@x=104,文字在右边显示
  253. @x=104
  254. end
  255. # "\\X" 指定不要显示姓名,带参数就是指定显示姓名(可内部使用"\\N[]")
  256. # 首先是寻找有没有带参数的"\\X"
  257. if @text.slice!(/\\[Xx]\[(\w+)\]/)!=nil
  258. # 找到的话将参数赋予@name
  259. @name=$1
  260. # 没有找到的话
  261. else
  262. # 再去寻找有没有不带参数的"\\X"
  263. if @text.slice!(/\\[Xx]/)!=nil
  264. # 找到的话就将姓名变成"???"
  265. @name="???"
  266. end
  267. end
  268. # "\\F" 指定表情(Face 用来指定表情啦)
  269. # 这里"\w"表示匹配字母+数字还有下划线,同样支持中文
  270. if @text.slice!(/\\[Ff]\[(\w+)\]/)!=nil
  271. # 找到的话就设定表情
  272. @face=$1
  273. end
  274. # "\\H" 显示头像(不明白大家为什么都喜欢用 Face 表示头像……)
  275. # 这里我将把显示头像放到字串的最前面,因为头像应该先显示出来
  276. if @text.slice!(/\\[Hh]\[([0-9]+)\]/)!=nil
  277. # 找到的话就提到字符串最前面
  278. @text="\030[#{$1}]"+@text
  279. end
  280. # ================ 分析部分结束,下面是显示部分 ================
  281. # 在此调用过程完成,因为在update部分也会有相同代码
  282. self.refresh_
  283. end
  284. # 选择项的情况
  285. if $game_temp.choice_max > 0
  286. @item_max = $game_temp.choice_max
  287. self.active = true
  288. self.index = 0
  289. end
  290. # 输入数值的情况
  291. if $game_temp.num_input_variable_id > 0
  292. digits_max = $game_temp.num_input_digits_max
  293. number = $game_variables[$game_temp.num_input_variable_id]
  294. @input_number_window = Window_InputNumber.new(digits_max)
  295. @input_number_window.number = number
  296. @input_number_window.x = self.x + 8
  297. @input_number_window.y = self.y + $game_temp.num_input_start * 32
  298. end
  299. end
  300. #--------------------------------------------------------------------------
  301. # ● 设置窗口位置与不透明度
  302. #--------------------------------------------------------------------------
  303. def reset_window
  304. # 判断现在的显示模式
  305. case $game_variables[MODE]
  306. when 0 # 普通模式
  307. self.width=480
  308. self.height=160
  309. self.contents.font.size = 22
  310. self.contents = Bitmap.new(width - 32, height - 32)
  311. self.x = 80
  312. if $game_temp.in_battle
  313. self.y = 16
  314. else
  315. case $game_system.message_position
  316. when 0 # 上
  317. self.y = 16
  318. when 1 # 中
  319. self.y = 160
  320. when 2 # 下
  321. self.y = 304
  322. end
  323. end
  324. when 1 # 图书模式
  325. self.width=532
  326. self.height=416
  327. self.contents.font.size = 22
  328. self.contents = Bitmap.new(width - 32, height - 32)
  329. self.x = 54
  330. self.y = 32
  331. when 2 # 全屏模式
  332. self.width=672
  333. self.height=512
  334. self.contents.font.size = 22
  335. self.contents = Bitmap.new(width - 32, height - 32)
  336. self.x = -16
  337. self.y = -16
  338. when 3 # 系统消息
  339. self.width = 400
  340. self.height = 60
  341. self.contents.font.size = 22
  342. self.contents = Bitmap.new(width - 32, height - 32)
  343. self.x = 120
  344. self.y = 200
  345. when 4 # 字幕
  346. self.width = 480
  347. self.height = 100
  348. self.contents.font.size = 16
  349. self.contents = Bitmap.new(width - 32, height - 32)
  350. self.x = 80
  351. self.y = 370
  352. when 5 # 对话框(头像专用,本游戏没用)
  353. self.width=480
  354. self.height=160
  355. self.contents.font.size = 22
  356. self.contents = Bitmap.new(width - 32, height - 32)
  357. self.x = 160
  358. self.y = 304
  359. end
  360. if $game_system.message_frame == 0
  361. self.opacity = 255
  362. else
  363. self.opacity = 0
  364. end
  365. self.back_opacity = 192
  366. end
  367. #--------------------------------------------------------------------------
  368. # ● 刷新画面
  369. #--------------------------------------------------------------------------
  370. def update
  371. super
  372. # 渐变的情况下
  373. if @fade_in
  374. # 脚本在这里设定透明度
  375. self.contents_opacity += @op/8
  376. if @input_number_window != nil
  377. @input_number_window.contents_opacity += 32
  378. end
  379. if self.contents_opacity >= @op
  380. @fade_in = false
  381. end
  382. return
  383. end
  384. # 输入数值的情况下
  385. if @input_number_window != nil
  386. @input_number_window.update
  387. # 确定
  388. if Input.trigger?(Input::C)
  389. $game_system.se_play($data_system.decision_se)
  390. $game_variables[$game_temp.num_input_variable_id] =
  391. @input_number_window.number
  392. $game_map.need_refresh = true
  393. # 释放输入数值窗口
  394. @input_number_window.dispose
  395. @input_number_window = nil
  396. terminate_message
  397. end
  398. return
  399. end
  400. # 显示信息中的情况下
  401. if @contents_showing
  402. # 刷新文本
  403. self.refresh_
  404. # 如果不是在显示选择项中就显示暂停标志
  405. if $game_temp.choice_max == 0
  406. self.pause = true
  407. end
  408. # 取消
  409. if Input.trigger?(Input::B)
  410. if $game_temp.choice_max > 0 and $game_temp.choice_cancel_type > 0
  411. $game_system.se_play($data_system.cancel_se)
  412. $game_temp.choice_proc.call($game_temp.choice_cancel_type - 1)
  413. terminate_message
  414. end
  415. end
  416. # @auto_close自减计数
  417. @auto_close-=1
  418. # 确定或者自动关闭
  419. if Input.trigger?(Input::C) or @auto_close==0 # @auto_close为0自动关闭,所以一开始为负数或0就不会自动关闭
  420. # 文字还没有处理完的时候
  421. if !@finish
  422. # 删除所有停顿效果
  423. @text.gsub!(/\024\[([0-9]+)\]/) { "" }
  424. # 删除当前延迟效果
  425. @delay = 0
  426. # 关闭打字效果
  427. @type_mode=-1
  428. # 一次处理完所有的字
  429. self.refresh_
  430. else
  431. # 有选择项的情况
  432. if $game_temp.choice_max > 0
  433. $game_system.se_play($data_system.decision_se)
  434. $game_temp.choice_proc.call(self.index)
  435. end
  436. # 清空文字
  437. terminate_message
  438. # 在读取TXT的模式下,需要继续打开文字
  439. if @is_read_txt
  440. # 根据显示模式确定需要打开行数
  441. case $game_variables[MODE]
  442. when 0 # 正常模式
  443. $game_temp.message_text = @ts.get_text(4)
  444. when 1 # 图书模式
  445. $game_temp.message_text = @ts.get_text(12)
  446. when 2 # 全屏模式
  447. $game_temp.message_text = @ts.get_text(15)
  448. end
  449. # 如果包含[END]则退出TXT读取模式
  450. if $game_temp.message_text.gsub!(/\[END\]/){""}!=nil
  451. @is_read_txt=false
  452. end
  453. end
  454. end
  455. end
  456. return
  457. end
  458. # 在渐变以外的状态下有等待显示的信息与选择项的场合
  459. if @fade_out == false and !($game_temp.message_text == nil or $game_temp.message_text == "")
  460. @contents_showing = true
  461. $game_temp.message_window_showing = true
  462. reset_window
  463. refresh
  464. Graphics.frame_reset
  465. # 当不跳过对话时才进行淡入操作
  466. if !@skip
  467. self.visible = true
  468. self.contents_opacity = 0
  469. if @input_number_window != nil
  470. @input_number_window.contents_opacity = 0
  471. end
  472. @fade_in = true
  473. end
  474. return
  475. end
  476. # 没有可以显示的信息、但是窗口为可见的情况下
  477. if self.visible
  478. @fade_out = true
  479. self.opacity -= 48
  480. if self.opacity == 0
  481. self.visible = false
  482. @fade_out = false
  483. $game_temp.message_window_showing = false
  484. end
  485. return
  486. end
  487. end
  488. #--------------------------------------------------------------------------
  489. # ● 刷新光标矩形
  490. #--------------------------------------------------------------------------
  491. def update_cursor_rect
  492. if @index >= 0
  493. n = $game_temp.choice_start + @index
  494. self.cursor_rect.set(8, n * 32, @cursor_width, 32)
  495. else
  496. self.cursor_rect.empty
  497. end
  498. end
  499. #--------------------------------------------------------------------------
  500. # ● 设定字体大小
  501. #--------------------------------------------------------------------------
  502. def set_font_size(size=20)
  503. # 最大字96号,再大就超过文字栏了,而且Ruby本来有限制……
  504. if size>96
  505. size=96
  506. end
  507. # 设定字的大小
  508. self.contents.font.size = size
  509. # 如果字太大了就要加高每行文字高度。
  510. if size > 28
  511. @height=size+4
  512. else
  513. @height=32
  514. end
  515. end
  516. #--------------------------------------------------------------------------
  517. # ● 设定文字透明
  518. #--------------------------------------------------------------------------
  519. def set_font_op(op=255)
  520. # 限制透明度为0-255
  521. if op>255
  522. op=255
  523. elsif op<0
  524. op=0
  525. end
  526. # 这里设定文字透明是没有用的,设定透明在update过程开始
  527. @op = op
  528. end
  529. #--------------------------------------------------------------------------
  530. # ● 显示文字/头像过程
  531. #--------------------------------------------------------------------------
  532. def refresh_
  533. # 处理已经结束的情况下直接return
  534. if @finish
  535. return
  536. end
  537. # 延时处理
  538. @delay-=1
  539. if @delay<=0
  540. # 每次处理i个标志,这里i就设置为@type_mode了
  541. i=@type_mode
  542. # c 获取 1 个字 (如果不能取得文字就循环)
  543. while ((c = @text.slice!(/./m)) != nil)
  544. # ======================== 默认功能 ========================
  545. # \\ 的情况下
  546. if c == "\000"
  547. # 还原为本来的文字
  548. c = "\\"
  549. end
  550. # \C[n] 的情况下
  551. if c == "\001"
  552. # 取得字色编码
  553. @text.sub!(/\[([0-9#a-zA-Z]+)\]/, "")
  554. # 如果是设定RGB颜色
  555. if $1[0,1]=="#"
  556. # 先拷贝一下文字
  557. c=$1.dup
  558. # 分3段分别取出R,G,B颜色
  559. c.sub!(/#([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})/, "")
  560. # 设定文字颜色
  561. self.contents.font.color = Color.new($1.to_i(16), $2.to_i(16), $3.to_i(16),@op)
  562. next
  563. else
  564. # 记录到变量 color
  565. color = $1.to_i
  566. # 字色0~7是有效的
  567. if color >= 0 and color <= 7
  568. # 设置文字颜色
  569. self.contents.font.color = text_color(color)
  570. end
  571. end
  572. # 进行下次循环
  573. next
  574. end
  575. # 显示金钱窗口,这个……不用说了吧……
  576. if c == "\002"
  577. if @gold_window == nil
  578. @gold_window = Window_Gold.new
  579. @gold_window.x = 560 - @gold_window.width
  580. if $game_temp.in_battle
  581. @gold_window.y = 192
  582. else
  583. @gold_window.y = self.y >= 128 ? 32 : 384
  584. end
  585. @gold_window.opacity = self.opacity
  586. @gold_window.back_opacity = self.back_opacity
  587. end
  588. next
  589. end
  590. # 另起一行文字的情况下
  591. if c == "\n"
  592. # 刷新选择项及光标的高
  593. if @y >= $game_temp.choice_start
  594. @cursor_width = [@cursor_width, @x>440 ? 448 : @x+8].max
  595. end
  596. # y 加 1
  597. @y += 1
  598. # 因为字体大小会变化,这里添加判断语句,超出就不显示了
  599. if @y>=self.contents.height/@height
  600. # 删除@text剩余的所有内容
  601. @text=nil
  602. # 然后返回
  603. break
  604. end
  605. # 因为头像的缘故,这里需要改写
  606. if @right
  607. # 头像右边显示的时候是0
  608. @x=0
  609. else
  610. # 头像靠左显示时@x要留出绘制头像空间
  611. @x=104
  612. end
  613. # 移动到选择项的下一行
  614. if @y >= $game_temp.choice_start
  615. @x=16
  616. end
  617. # 下面的文字
  618. next
  619. end
  620. # ======================== 加强功能 ========================
  621. # 显示物品图标
  622. if c == "\003"
  623. # 取得物品ID
  624. @text.sub!(/\[([0-9]+)\]/, "")
  625. # 这里的 RPG::Cache 是高速缓存,不明白的看看帮助文档吧……
  626. icon = RPG::Cache.icon($data_items[$1.to_i].icon_name)
  627. # 绘制这个图标
  628. self.contents.blt(@x+4,@y*@height+(@height-24)/2,icon,Rect.new(0, 0, 24, 24))
  629. # 将x值增加24
  630. @x+=24
  631. # 执行下一次循环
  632. next
  633. end
  634. # 显示技能图标(因为类似物品图标显示,所以省略注释)
  635. if c == "\004"
  636. @text.sub!(/\[([0-9]+)\]/, "")
  637. icon = RPG::Cache.icon($data_skills[$1.to_i].icon_name)
  638. self.contents.blt(@x+4,@y*@height+(@height-24)/2,icon,Rect.new(0, 0, 24, 24))
  639. @x+=24
  640. next
  641. end
  642. # 显示武器图标(因为类似物品图标显示,所以省略注释)
  643. if c == "\005"
  644. @text.sub!(/\[([0-9]+)\]/, "")
  645. icon = RPG::Cache.icon($data_weapons[$1.to_i].icon_name)
  646. self.contents.blt(@x+4,@y*@height+(@height-24)/2,icon,Rect.new(0, 0, 24, 24))
  647. @x+=24
  648. next
  649. end
  650. # 显示防具图标(因为类似物品图标显示,所以省略注释)
  651. if c == "\006"
  652. @text.sub!(/\[([0-9]+)\]/, "")
  653. icon = RPG::Cache.icon($data_armors[$1.to_i].icon_name)
  654. self.contents.blt(@x+4,@y*@height+(@height-24)/2,icon,Rect.new(0, 0, 24, 24))
  655. @x+=24
  656. next
  657. end
  658. # 等待n帧
  659. if c == "\024"
  660. # 取得参数(需要等待多少帧)
  661. @text.sub!(/\[([0-9]+)\]/, "")
  662. # 设定@delay标志
  663. @delay = $1.to_i
  664. # 退出此次循环
  665. break
  666. end
  667. # 显示头像
  668. if c == "\030"
  669. #暂时记录文字大小,用于显示完头像恢复
  670. size=self.contents.font.size
  671. # 设定为正常的20号字
  672. self.contents.font.size=20
  673. # 设定系统字色,为写名字做准备的
  674. self.contents.font.color = system_color
  675. # 取得"[]"内的字符并从原字串中删除这一部分
  676. @text.sub!(/\[([0-9]+)\]/, "")
  677. # 记录到head变量
  678. head=$1
  679. # 判断头像和原来的是不是一样的
  680. if @face == nil
  681. # 不一样
  682. if @head_file != head
  683. # 改变成现在的头像文件名
  684. @head_file = head
  685. # 不一样的话再重新载入头像
  686. @head_bmp=RPG::Cache.character("head/gpra_"+@head_file, 0)
  687. end
  688. else
  689. # 当表情不是空的时候需要考虑表情的
  690. if @head_file != head + "_" + @face
  691. # 改变成现在的头像文件名
  692. @head_file = head + "_" + @face
  693. # 不一样的话再重新载入头像
  694. @head_bmp=RPG::Cache.character("head/gpra_"+@head_file, 0)
  695. end
  696. end
  697. # 显示头像,分左右两种情况
  698. if @right
  699. # 绘制头像图片
  700. self.contents.blt(348,0,@head_bmp,Rect.new(0,0,100,100))
  701. # 显示角色姓名
  702. if @name==nil
  703. # 取得角色姓名到变量 c
  704. c = $game_actors[head.to_i].name
  705. # 描绘角色的姓名
  706. self.contents.draw_text(348,104,100,24,c,1)
  707. else
  708. # 取得"???"到变量 c,当然这个"???"可以改为其他的默认值
  709. c = @name
  710. # 描绘角色的姓名
  711. self.contents.draw_text(348,104,100,24,c,1)
  712. end
  713. else
  714. # 绘制头像图片
  715. self.contents.blt(0,0,@head_bmp,Rect.new(0,0,100,100))
  716. # 显示角色姓名
  717. if @name==nil
  718. # 取得角色姓名到变量 c
  719. c = $game_actors[head.to_i].name
  720. # 描绘角色的姓名
  721. self.contents.draw_text(0,104,100,24,c,1)
  722. else
  723. # 取得"???"到变量 c,当然这个"???"可以改为其他的默认值
  724. c = @name
  725. # 描绘角色的姓名
  726. self.contents.draw_text(0,104,100,24,c,1)
  727. end
  728. end
  729. # 恢复默认字色
  730. self.contents.font.color = normal_color
  731. # 恢复字体大小
  732. self.contents.font.size=size
  733. # 进行下一次循环
  734. next
  735. end
  736. # ======================== 以上加强部分 ========================
  737. # 描绘文字
  738. self.contents.draw_text(4+@x,@height*@y, @height, @height, c)
  739. # x 为描绘文字宽度进行自增运算,计算下一个文字起始位置
  740. @x += self.contents.text_size(c).width
  741. # 操作了@type_mode个字符后就退出循环了,@type_mode为负则操作一次完成
  742. i-=1
  743. if i==0
  744. break
  745. end
  746. end
  747. end
  748. # 如果@text处理结束了,就设置结束标志
  749. if @text==nil or @text==""
  750. @finish=true
  751. end
  752. end
  753. end
复制代码
Shining...

Lv1.梦旅人

劒剋

梦石
0
星屑
50
在线时间
27 小时
注册时间
2007-12-16
帖子
1304
2
 楼主| 发表于 2007-12-31 07:32:58 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
  1. #==============================================================================
  2. # ◎ GPRA_Window_Message
  3. #------------------------------------------------------------------------------
  4. # ◎ 显示文章的信息窗口加强。
  5. #------------------------------------------------------------------------------
  6. # 制作者:绿梨子红苹果
  7. # 个人主页:vbgm.9126.com
  8. # E-Mail:[email protected]
  9. # QQ:42378361
  10. #==============================================================================
  11. class Window_Message < Window_Selectable
  12. #--------------------------------------------------------------------------
  13. # ● 初始化状态
  14. #--------------------------------------------------------------------------
  15. MODE = 51
  16. AUTOCLOSE = 52
  17. TYPEMODE = 53
  18. def initialize
  19. super(80, 304, 480, 160)
  20. self.contents = Bitmap.new(width - 32, height - 32)
  21. self.visible = false
  22. self.z = 9998
  23. @fade_in = false
  24. @fade_out = false
  25. @contents_showing = false
  26. @cursor_width = 0
  27. @op = 255 # 不透明度
  28. @head_bmp = nil # 装载头像用
  29. @head_file = nil # 头像文件名
  30. @text = nil # 记录所处理文字
  31. @skip = false # 记录是否跳过此次对话
  32. @auto_close = -1 # 默认不打开自动关闭
  33. @type_mode=-1 # 打字模式
  34. @delay=-1 # 等待n帧标志
  35. @finish=false # 记录文字处理是否结束
  36. @ts = TextStream.new # 创建一个新的TXT读取流
  37. @is_read_txt =false # 默认不是在读取txt文件
  38. self.active = false
  39. self.index = -1
  40. end
  41. #--------------------------------------------------------------------------
  42. # ● 释放
  43. #--------------------------------------------------------------------------
  44. def dispose
  45. terminate_message
  46. $game_temp.message_window_showing = false
  47. if @input_number_window != nil
  48. @input_number_window.dispose
  49. end
  50. super
  51. end
  52. #--------------------------------------------------------------------------
  53. # ● 处理信息结束
  54. #--------------------------------------------------------------------------
  55. def terminate_message
  56. self.active = false
  57. self.pause = false
  58. self.index = -1
  59. self.contents.clear
  60. # 清除显示中标志
  61. @contents_showing = false
  62. # 呼叫信息调用
  63. if $game_temp.message_proc != nil
  64. $game_temp.message_proc.call
  65. end
  66. # 清除文章、选择项、输入数值的相关变量
  67. $game_temp.message_text = nil
  68. $game_temp.message_proc = nil
  69. $game_temp.choice_start = 99
  70. $game_temp.choice_max = 0
  71. $game_temp.choice_cancel_type = 0
  72. $game_temp.choice_proc = nil
  73. $game_temp.num_input_start = 99
  74. $game_temp.num_input_variable_id = 0
  75. $game_temp.num_input_digits_max = 0
  76. # 开放金钱窗口
  77. if @gold_window != nil
  78. @gold_window.dispose
  79. @gold_window = nil
  80. end
  81. end
  82. #--------------------------------------------------------------------------
  83. # ● 刷新
  84. #--------------------------------------------------------------------------
  85. def refresh
  86. # 清空原先内容
  87. self.contents.clear
  88. # 恢复一般字色
  89. self.contents.font.color = normal_color
  90. # 恢复字体大小
  91. self.contents.font.size = 20
  92. # 绘制文字位置初始化
  93. @x = @y = 0
  94. # 字体高度记录
  95. @height = 32
  96. # 文字不透明度设定为255
  97. @op = 255
  98. # 头像默认显示在右边
  99. @right = true
  100. # 头像默认显示一般表情
  101. @face = nil
  102. # 默认显示角色姓名
  103. @name = nil
  104. # 默认不跳过此次对话
  105. @skip = false
  106. # 从变量读取自动关闭设置
  107. @auto_close = $game_variables[AUTOCLOSE]
  108. # 从变量读取打字模式设置
  109. @type_mode=$game_variables[TYPEMODE]
  110. # 默认不等待
  111. @delay=-1
  112. # 设定文字没有处理结束
  113. @finish=false
  114. # 光标宽度初始化为零
  115. @cursor_width = 0
  116. # 到选择项的下一行字
  117. if $game_temp.choice_start == 0
  118. @x = 16
  119. end
  120. # 有等待显示的文字的情况下
  121. # (注:因为一旦文字非空就处理,所以可以设定 $game_temp.message_text 达到显示文章的效果)
  122. if $game_temp.message_text != nil
  123. # @text 功能改进
  124. if @text==nil or @text==""
  125. @text = $game_temp.message_text.dup
  126. else
  127. @text = @text + $game_temp.message_text
  128. end
  129. # 最先必须要将 "\\\\" 变换为 "\000"
  130. @text.gsub!(/\\\\/) { "\000" }
  131. # 在TXT模式还没有打开的时候
  132. if !@is_read_txt
  133. # TXT读取模式打开
  134. if @text.slice!(/\\[Tt][Xx][Tt]\[(\w+)\]\[(\w+)\]/)!=nil
  135. # 打开文件,成功打开后再进入后面部分
  136. if @ts.open($1,$2)
  137. # 根据显示模式确定需要打开行数
  138. case $game_variables[MODE]
  139. when 0 # 正常模式
  140. @text = @ts.get_text(4)
  141. when 1 # 图书模式
  142. @text = @ts.get_text(12)
  143. when 2 # 全屏模式
  144. @text = @ts.get_text(15)
  145. end
  146. # 如果包含[END]
  147. if @text.gsub!(/\[END\]/){""}!=nil
  148. #退出TXT读取模式
  149. @is_read_txt=false
  150. else
  151. #否则设置正在读取标志
  152. @is_read_txt=true
  153. end
  154. end
  155. else
  156. if @text.slice!(/\\[Tt][Xx][Tt]\[(\w+)\]/)!=nil
  157. # 打开文件,成功打开后再进入后面部分
  158. if @ts.open($1,"")
  159. # 根据显示模式确定需要打开行数
  160. case $game_variables[MODE]
  161. when 0 # 正常模式
  162. @text = @ts.get_text(4)
  163. when 1 # 图书模式
  164. @text = @ts.get_text(12)
  165. when 2 # 全屏模式
  166. @text = @ts.get_text(15)
  167. end
  168. # 如果包含[END]
  169. if @text.gsub!(/\[END\]/){""}!=nil
  170. #退出TXT读取模式
  171. @is_read_txt=false
  172. else
  173. #否则设置正在读取标志
  174. @is_read_txt=true
  175. end
  176. end
  177. end
  178. end
  179. end
  180. # 如果取得的字符含"\\~"时
  181. if @text.slice!(/\\~/)!=nil
  182. # 跳过此次对话
  183. terminate_message
  184. # 设置跳过此次对话标志
  185. @skip = true
  186. # 直接返回等待连接后面部分
  187. return
  188. end
  189. # 限制文字处理(注:这里是默认功能。)
  190. begin
  191. last_text = @text.clone
  192. @text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  193. end until @text == last_text
  194. @text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  195. $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  196. end
  197. #(注:后面将单个字符循环判断,所以这里将控制符全部换成单个字符)
  198. # 为了方便将 "\\C" 变为 "\001"
  199. @text.gsub!(/\\[Cc]\[([0-9#a-zA-Z]+)\]/) { "\001[#{$1}]" }
  200. # "\\G" 变为 "\002"
  201. @text.gsub!(/\\[Gg]/) { "\002" }
  202. # ========================增强功能========================
  203. # "\\/" 删除行尾换行符号
  204. @text.gsub!(/\\\/\n/) {""}
  205. # 去掉不在行尾的"\\/"符号,防止出错
  206. @text.gsub!(/\\\//) {""}
  207. # "\\I" 物品图标+名称显示
  208. @text.gsub!(/\\[Ii]\[([0-9]+)\]/) { "\003[#{$1}]"+$data_items[$1.to_i].name }
  209. # "\\K" 技能图标+名称显示
  210. @text.gsub!(/\\[Kk]\[([0-9]+)\]/) { "\004[#{$1}]"+$data_skills[$1.to_i].name }
  211. # "\\W" 武器图标+名称显示
  212. @text.gsub!(/\\[Ww]\[([0-9]+)\]/) { "\005[#{$1}]"+$data_weapons[$1.to_i].name }
  213. # "\\A" 防具图标+名称显示
  214. @text.gsub!(/\\[Dd]\[([0-9]+)\]/) { "\006[#{$1}]"+$data_armors[$1.to_i].name }
  215. # 注:大量显示图片将是游戏的速度大大减慢
  216. # "\\I1" 物品图标显示
  217. @text.gsub!(/\\[Ii]1\[([0-9]+)\]/) { "\003[#{$1}]" }
  218. # "\\K1" 技能图标显示
  219. @text.gsub!(/\\[Kk]1\[([0-9]+)\]/) { "\004[#{$1}]" }
  220. # "\\W1" 武器图标显示
  221. @text.gsub!(/\\[Ww]1\[([0-9]+)\]/) { "\005[#{$1}]" }
  222. # "\\A1" 防具图标显示
  223. @text.gsub!(/\\[Dd]1\[([0-9]+)\]/) { "\006[#{$1}]" }
  224. # "\\I2" 物品名称显示
  225. @text.gsub!(/\\[Ii]2\[([0-9]+)\]/) { $data_items[$1.to_i].name }
  226. # "\\K2" 技能名称显示
  227. @text.gsub!(/\\[Kk]2\[([0-9]+)\]/) { $data_skills[$1.to_i].name }
  228. # "\\W2" 武器名称显示
  229. @text.gsub!(/\\[Ww]2\[([0-9]+)\]/) { $data_weapons[$1.to_i].name }
  230. # "\\A2" 防具名称显示
  231. @text.gsub!(/\\[Dd]2\[([0-9]+)\]/) { $data_armors[$1.to_i].name }
  232. # "\\S" 字体大小(只修改第一个"\\S")
  233. # 这里首先删掉能找到的第一个"\\S"
  234. if @text.slice!(/\\[Ss]\[([0-9]+)\]/)!=nil
  235. # 当找了"\\S"时满足上述条件,就设置文字大小
  236. self.set_font_size($1.to_i)
  237. end
  238. # "\\O" 文字透明度(使用注意同上,模拟声音变小……)
  239. if @text.slice!(/\\[Oo]\[([0-9]+)\]/)!=nil
  240. self.set_font_op($1.to_i)
  241. end
  242. # "\\=" 停顿固定帧(延时)
  243. @text.gsub!(/\\=\[([0-9]+)\]/) { "\024[#{$1}]" }
  244. # "\\." 停顿3帧
  245. @text.gsub!(/\\\./) { "\024[3]" }
  246. # "\\_" 停顿1秒(30帧)
  247. @text.gsub!(/\\_/) { "\024[30]" }
  248. # "\\L" 指定头像左边显示
  249. if @text.slice!(/\\[Ll]/)!=nil
  250. # 设定头像居右标志为假
  251. @right=false
  252. # 顺便要设置@x=104,文字在右边显示
  253. @x=104
  254. end
  255. # "\\X" 指定不要显示姓名,带参数就是指定显示姓名(可内部使用"\\N[]")
  256. # 首先是寻找有没有带参数的"\\X"
  257. if @text.slice!(/\\[Xx]\[(\w+)\]/)!=nil
  258. # 找到的话将参数赋予@name
  259. @name=$1
  260. # 没有找到的话
  261. else
  262. # 再去寻找有没有不带参数的"\\X"
  263. if @text.slice!(/\\[Xx]/)!=nil
  264. # 找到的话就将姓名变成"???"
  265. @name="???"
  266. end
  267. end
  268. # "\\F" 指定表情(Face 用来指定表情啦)
  269. # 这里"\w"表示匹配字母+数字还有下划线,同样支持中文
  270. if @text.slice!(/\\[Ff]\[(\w+)\]/)!=nil
  271. # 找到的话就设定表情
  272. @face=$1
  273. end
  274. # "\\H" 显示头像(不明白大家为什么都喜欢用 Face 表示头像……)
  275. # 这里我将把显示头像放到字串的最前面,因为头像应该先显示出来
  276. if @text.slice!(/\\[Hh]\[([0-9]+)\]/)!=nil
  277. # 找到的话就提到字符串最前面
  278. @text="\030[#{$1}]"+@text
  279. end
  280. # ================ 分析部分结束,下面是显示部分 ================
  281. # 在此调用过程完成,因为在update部分也会有相同代码
  282. self.refresh_
  283. end
  284. # 选择项的情况
  285. if $game_temp.choice_max > 0
  286. @item_max = $game_temp.choice_max
  287. self.active = true
  288. self.index = 0
  289. end
  290. # 输入数值的情况
  291. if $game_temp.num_input_variable_id > 0
  292. digits_max = $game_temp.num_input_digits_max
  293. number = $game_variables[$game_temp.num_input_variable_id]
  294. @input_number_window = Window_InputNumber.new(digits_max)
  295. @input_number_window.number = number
  296. @input_number_window.x = self.x + 8
  297. @input_number_window.y = self.y + $game_temp.num_input_start * 32
  298. end
  299. end
  300. #--------------------------------------------------------------------------
  301. # ● 设置窗口位置与不透明度
  302. #--------------------------------------------------------------------------
  303. def reset_window
  304. # 判断现在的显示模式
  305. case $game_variables[MODE]
  306. when 0 # 普通模式
  307. self.width=480
  308. self.height=160
  309. self.contents.font.size = 22
  310. self.contents = Bitmap.new(width - 32, height - 32)
  311. self.x = 80
  312. if $game_temp.in_battle
  313. self.y = 16
  314. else
  315. case $game_system.message_position
  316. when 0 # 上
  317. self.y = 16
  318. when 1 # 中
  319. self.y = 160
  320. when 2 # 下
  321. self.y = 304
  322. end
  323. end
  324. when 1 # 图书模式
  325. self.width=532
  326. self.height=416
  327. self.contents.font.size = 22
  328. self.contents = Bitmap.new(width - 32, height - 32)
  329. self.x = 54
  330. self.y = 32
  331. when 2 # 全屏模式
  332. self.width=672
  333. self.height=512
  334. self.contents.font.size = 22
  335. self.contents = Bitmap.new(width - 32, height - 32)
  336. self.x = -16
  337. self.y = -16
  338. when 3 # 系统消息
  339. self.width = 400
  340. self.height = 60
  341. self.contents.font.size = 22
  342. self.contents = Bitmap.new(width - 32, height - 32)
  343. self.x = 120
  344. self.y = 200
  345. when 4 # 字幕
  346. self.width = 480
  347. self.height = 100
  348. self.contents.font.size = 16
  349. self.contents = Bitmap.new(width - 32, height - 32)
  350. self.x = 80
  351. self.y = 370
  352. when 5 # 对话框(头像专用,本游戏没用)
  353. self.width=480
  354. self.height=160
  355. self.contents.font.size = 22
  356. self.contents = Bitmap.new(width - 32, height - 32)
  357. self.x = 160
  358. self.y = 304
  359. end
  360. if $game_system.message_frame == 0
  361. self.opacity = 255
  362. else
  363. self.opacity = 0
  364. end
  365. self.back_opacity = 192
  366. end
  367. #--------------------------------------------------------------------------
  368. # ● 刷新画面
  369. #--------------------------------------------------------------------------
  370. def update
  371. super
  372. # 渐变的情况下
  373. if @fade_in
  374. # 脚本在这里设定透明度
  375. self.contents_opacity += @op/8
  376. if @input_number_window != nil
  377. @input_number_window.contents_opacity += 32
  378. end
  379. if self.contents_opacity >= @op
  380. @fade_in = false
  381. end
  382. return
  383. end
  384. # 输入数值的情况下
  385. if @input_number_window != nil
  386. @input_number_window.update
  387. # 确定
  388. if Input.trigger?(Input::C)
  389. $game_system.se_play($data_system.decision_se)
  390. $game_variables[$game_temp.num_input_variable_id] =
  391. @input_number_window.number
  392. $game_map.need_refresh = true
  393. # 释放输入数值窗口
  394. @input_number_window.dispose
  395. @input_number_window = nil
  396. terminate_message
  397. end
  398. return
  399. end
  400. # 显示信息中的情况下
  401. if @contents_showing
  402. # 刷新文本
  403. self.refresh_
  404. # 如果不是在显示选择项中就显示暂停标志
  405. if $game_temp.choice_max == 0
  406. self.pause = true
  407. end
  408. # 取消
  409. if Input.trigger?(Input::B)
  410. if $game_temp.choice_max > 0 and $game_temp.choice_cancel_type > 0
  411. $game_system.se_play($data_system.cancel_se)
  412. $game_temp.choice_proc.call($game_temp.choice_cancel_type - 1)
  413. terminate_message
  414. end
  415. end
  416. # @auto_close自减计数
  417. @auto_close-=1
  418. # 确定或者自动关闭
  419. if Input.trigger?(Input::C) or @auto_close==0 # @auto_close为0自动关闭,所以一开始为负数或0就不会自动关闭
  420. # 文字还没有处理完的时候
  421. if !@finish
  422. # 删除所有停顿效果
  423. @text.gsub!(/\024\[([0-9]+)\]/) { "" }
  424. # 删除当前延迟效果
  425. @delay = 0
  426. # 关闭打字效果
  427. @type_mode=-1
  428. # 一次处理完所有的字
  429. self.refresh_
  430. else
  431. # 有选择项的情况
  432. if $game_temp.choice_max > 0
  433. $game_system.se_play($data_system.decision_se)
  434. $game_temp.choice_proc.call(self.index)
  435. end
  436. # 清空文字
  437. terminate_message
  438. # 在读取TXT的模式下,需要继续打开文字
  439. if @is_read_txt
  440. # 根据显示模式确定需要打开行数
  441. case $game_variables[MODE]
  442. when 0 # 正常模式
  443. $game_temp.message_text = @ts.get_text(4)
  444. when 1 # 图书模式
  445. $game_temp.message_text = @ts.get_text(12)
  446. when 2 # 全屏模式
  447. $game_temp.message_text = @ts.get_text(15)
  448. end
  449. # 如果包含[END]则退出TXT读取模式
  450. if $game_temp.message_text.gsub!(/\[END\]/){""}!=nil
  451. @is_read_txt=false
  452. end
  453. end
  454. end
  455. end
  456. return
  457. end
  458. # 在渐变以外的状态下有等待显示的信息与选择项的场合
  459. if @fade_out == false and !($game_temp.message_text == nil or $game_temp.message_text == "")
  460. @contents_showing = true
  461. $game_temp.message_window_showing = true
  462. reset_window
  463. refresh
  464. Graphics.frame_reset
  465. # 当不跳过对话时才进行淡入操作
  466. if !@skip
  467. self.visible = true
  468. self.contents_opacity = 0
  469. if @input_number_window != nil
  470. @input_number_window.contents_opacity = 0
  471. end
  472. @fade_in = true
  473. end
  474. return
  475. end
  476. # 没有可以显示的信息、但是窗口为可见的情况下
  477. if self.visible
  478. @fade_out = true
  479. self.opacity -= 48
  480. if self.opacity == 0
  481. self.visible = false
  482. @fade_out = false
  483. $game_temp.message_window_showing = false
  484. end
  485. return
  486. end
  487. end
  488. #--------------------------------------------------------------------------
  489. # ● 刷新光标矩形
  490. #--------------------------------------------------------------------------
  491. def update_cursor_rect
  492. if @index >= 0
  493. n = $game_temp.choice_start + @index
  494. self.cursor_rect.set(8, n * 32, @cursor_width, 32)
  495. else
  496. self.cursor_rect.empty
  497. end
  498. end
  499. #--------------------------------------------------------------------------
  500. # ● 设定字体大小
  501. #--------------------------------------------------------------------------
  502. def set_font_size(size=20)
  503. # 最大字96号,再大就超过文字栏了,而且Ruby本来有限制……
  504. if size>96
  505. size=96
  506. end
  507. # 设定字的大小
  508. self.contents.font.size = size
  509. # 如果字太大了就要加高每行文字高度。
  510. if size > 28
  511. @height=size+4
  512. else
  513. @height=32
  514. end
  515. end
  516. #--------------------------------------------------------------------------
  517. # ● 设定文字透明
  518. #--------------------------------------------------------------------------
  519. def set_font_op(op=255)
  520. # 限制透明度为0-255
  521. if op>255
  522. op=255
  523. elsif op<0
  524. op=0
  525. end
  526. # 这里设定文字透明是没有用的,设定透明在update过程开始
  527. @op = op
  528. end
  529. #--------------------------------------------------------------------------
  530. # ● 显示文字/头像过程
  531. #--------------------------------------------------------------------------
  532. def refresh_
  533. # 处理已经结束的情况下直接return
  534. if @finish
  535. return
  536. end
  537. # 延时处理
  538. @delay-=1
  539. if @delay<=0
  540. # 每次处理i个标志,这里i就设置为@type_mode了
  541. i=@type_mode
  542. # c 获取 1 个字 (如果不能取得文字就循环)
  543. while ((c = @text.slice!(/./m)) != nil)
  544. # ======================== 默认功能 ========================
  545. # \\ 的情况下
  546. if c == "\000"
  547. # 还原为本来的文字
  548. c = "\\"
  549. end
  550. # \C[n] 的情况下
  551. if c == "\001"
  552. # 取得字色编码
  553. @text.sub!(/\[([0-9#a-zA-Z]+)\]/, "")
  554. # 如果是设定RGB颜色
  555. if $1[0,1]=="#"
  556. # 先拷贝一下文字
  557. c=$1.dup
  558. # 分3段分别取出R,G,B颜色
  559. c.sub!(/#([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})/, "")
  560. # 设定文字颜色
  561. self.contents.font.color = Color.new($1.to_i(16), $2.to_i(16), $3.to_i(16),@op)
  562. next
  563. else
  564. # 记录到变量 color
  565. color = $1.to_i
  566. # 字色0~7是有效的
  567. if color >= 0 and color <= 7
  568. # 设置文字颜色
  569. self.contents.font.color = text_color(color)
  570. end
  571. end
  572. # 进行下次循环
  573. next
  574. end
  575. # 显示金钱窗口,这个……不用说了吧……
  576. if c == "\002"
  577. if @gold_window == nil
  578. @gold_window = Window_Gold.new
  579. @gold_window.x = 560 - @gold_window.width
  580. if $game_temp.in_battle
  581. @gold_window.y = 192
  582. else
  583. @gold_window.y = self.y >= 128 ? 32 : 384
  584. end
  585. @gold_window.opacity = self.opacity
  586. @gold_window.back_opacity = self.back_opacity
  587. end
  588. next
  589. end
  590. # 另起一行文字的情况下
  591. if c == "\n"
  592. # 刷新选择项及光标的高
  593. if @y >= $game_temp.choice_start
  594. @cursor_width = [@cursor_width, @x>440 ? 448 : @x+8].max
  595. end
  596. # y 加 1
  597. @y += 1
  598. # 因为字体大小会变化,这里添加判断语句,超出就不显示了
  599. if @y>=self.contents.height/@height
  600. # 删除@text剩余的所有内容
  601. @text=nil
  602. # 然后返回
  603. break
  604. end
  605. # 因为头像的缘故,这里需要改写
  606. if @right
  607. # 头像右边显示的时候是0
  608. @x=0
  609. else
  610. # 头像靠左显示时@x要留出绘制头像空间
  611. @x=104
  612. end
  613. # 移动到选择项的下一行
  614. if @y >= $game_temp.choice_start
  615. @x=16
  616. end
  617. # 下面的文字
  618. next
  619. end
  620. # ======================== 加强功能 ========================
  621. # 显示物品图标
  622. if c == "\003"
  623. # 取得物品ID
  624. @text.sub!(/\[([0-9]+)\]/, "")
  625. # 这里的 RPG::Cache 是高速缓存,不明白的看看帮助文档吧……
  626. icon = RPG::Cache.icon($data_items[$1.to_i].icon_name)
  627. # 绘制这个图标
  628. self.contents.blt(@x+4,@y*@height+(@height-24)/2,icon,Rect.new(0, 0, 24, 24))
  629. # 将x值增加24
  630. @x+=24
  631. # 执行下一次循环
  632. next
  633. end
  634. # 显示技能图标(因为类似物品图标显示,所以省略注释)
  635. if c == "\004"
  636. @text.sub!(/\[([0-9]+)\]/, "")
  637. icon = RPG::Cache.icon($data_skills[$1.to_i].icon_name)
  638. self.contents.blt(@x+4,@y*@height+(@height-24)/2,icon,Rect.new(0, 0, 24, 24))
  639. @x+=24
  640. next
  641. end
  642. # 显示武器图标(因为类似物品图标显示,所以省略注释)
  643. if c == "\005"
  644. @text.sub!(/\[([0-9]+)\]/, "")
  645. icon = RPG::Cache.icon($data_weapons[$1.to_i].icon_name)
  646. self.contents.blt(@x+4,@y*@height+(@height-24)/2,icon,Rect.new(0, 0, 24, 24))
  647. @x+=24
  648. next
  649. end
  650. # 显示防具图标(因为类似物品图标显示,所以省略注释)
  651. if c == "\006"
  652. @text.sub!(/\[([0-9]+)\]/, "")
  653. icon = RPG::Cache.icon($data_armors[$1.to_i].icon_name)
  654. self.contents.blt(@x+4,@y*@height+(@height-24)/2,icon,Rect.new(0, 0, 24, 24))
  655. @x+=24
  656. next
  657. end
  658. # 等待n帧
  659. if c == "\024"
  660. # 取得参数(需要等待多少帧)
  661. @text.sub!(/\[([0-9]+)\]/, "")
  662. # 设定@delay标志
  663. @delay = $1.to_i
  664. # 退出此次循环
  665. break
  666. end
  667. # 显示头像
  668. if c == "\030"
  669. #暂时记录文字大小,用于显示完头像恢复
  670. size=self.contents.font.size
  671. # 设定为正常的20号字
  672. self.contents.font.size=20
  673. # 设定系统字色,为写名字做准备的
  674. self.contents.font.color = system_color
  675. # 取得"[]"内的字符并从原字串中删除这一部分
  676. @text.sub!(/\[([0-9]+)\]/, "")
  677. # 记录到head变量
  678. head=$1
  679. # 判断头像和原来的是不是一样的
  680. if @face == nil
  681. # 不一样
  682. if @head_file != head
  683. # 改变成现在的头像文件名
  684. @head_file = head
  685. # 不一样的话再重新载入头像
  686. @head_bmp=RPG::Cache.character("head/gpra_"+@head_file, 0)
  687. end
  688. else
  689. # 当表情不是空的时候需要考虑表情的
  690. if @head_file != head + "_" + @face
  691. # 改变成现在的头像文件名
  692. @head_file = head + "_" + @face
  693. # 不一样的话再重新载入头像
  694. @head_bmp=RPG::Cache.character("head/gpra_"+@head_file, 0)
  695. end
  696. end
  697. # 显示头像,分左右两种情况
  698. if @right
  699. # 绘制头像图片
  700. self.contents.blt(348,0,@head_bmp,Rect.new(0,0,100,100))
  701. # 显示角色姓名
  702. if @name==nil
  703. # 取得角色姓名到变量 c
  704. c = $game_actors[head.to_i].name
  705. # 描绘角色的姓名
  706. self.contents.draw_text(348,104,100,24,c,1)
  707. else
  708. # 取得"???"到变量 c,当然这个"???"可以改为其他的默认值
  709. c = @name
  710. # 描绘角色的姓名
  711. self.contents.draw_text(348,104,100,24,c,1)
  712. end
  713. else
  714. # 绘制头像图片
  715. self.contents.blt(0,0,@head_bmp,Rect.new(0,0,100,100))
  716. # 显示角色姓名
  717. if @name==nil
  718. # 取得角色姓名到变量 c
  719. c = $game_actors[head.to_i].name
  720. # 描绘角色的姓名
  721. self.contents.draw_text(0,104,100,24,c,1)
  722. else
  723. # 取得"???"到变量 c,当然这个"???"可以改为其他的默认值
  724. c = @name
  725. # 描绘角色的姓名
  726. self.contents.draw_text(0,104,100,24,c,1)
  727. end
  728. end
  729. # 恢复默认字色
  730. self.contents.font.color = normal_color
  731. # 恢复字体大小
  732. self.contents.font.size=size
  733. # 进行下一次循环
  734. next
  735. end
  736. # ======================== 以上加强部分 ========================
  737. # 描绘文字
  738. self.contents.draw_text(4+@x,@height*@y, @height, @height, c)
  739. # x 为描绘文字宽度进行自增运算,计算下一个文字起始位置
  740. @x += self.contents.text_size(c).width
  741. # 操作了@type_mode个字符后就退出循环了,@type_mode为负则操作一次完成
  742. i-=1
  743. if i==0
  744. break
  745. end
  746. end
  747. end
  748. # 如果@text处理结束了,就设置结束标志
  749. if @text==nil or @text==""
  750. @finish=true
  751. end
  752. end
  753. end
复制代码
Shining...
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

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

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

GMT+8, 2026-7-27 01:50

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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