Advertisement
Guest User

Window_Base Saerostherogue

a guest
Jul 29th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.93 KB | None | 0 0
  1. #==============================================================================
  2. # ■ Window_Base
  3. #------------------------------------------------------------------------------
  4. #  ゲーム中の全てのウィンドウのスーパークラスです。
  5. #==============================================================================
  6.  
  7. class Window_Base < Window
  8. #--------------------------------------------------------------------------
  9. # ● オブジェクト初期化
  10. #--------------------------------------------------------------------------
  11. def initialize(x, y, width, height)
  12. super
  13. self.windowskin = Cache.system("Window")
  14. update_padding
  15. update_tone
  16. create_contents
  17. @opening = @closing = false
  18. end
  19. #--------------------------------------------------------------------------
  20. # ● 解放
  21. #--------------------------------------------------------------------------
  22. def dispose
  23. contents.dispose unless disposed?
  24. super
  25. end
  26. #--------------------------------------------------------------------------
  27. # ● 行の高さを取得
  28. #--------------------------------------------------------------------------
  29. def line_height
  30. return 24
  31. end
  32. #--------------------------------------------------------------------------
  33. # ● 標準パディングサイズの取得
  34. #--------------------------------------------------------------------------
  35. def standard_padding
  36. return 12
  37. end
  38. #--------------------------------------------------------------------------
  39. # ● パディングの更新
  40. #--------------------------------------------------------------------------
  41. def update_padding
  42. self.padding = standard_padding
  43. end
  44. #--------------------------------------------------------------------------
  45. # ● ウィンドウ内容の幅を計算
  46. #--------------------------------------------------------------------------
  47. def contents_width
  48. width - standard_padding * 2
  49. end
  50. #--------------------------------------------------------------------------
  51. # ● ウィンドウ内容の高さを計算
  52. #--------------------------------------------------------------------------
  53. def contents_height
  54. height - standard_padding * 2
  55. end
  56. #--------------------------------------------------------------------------
  57. # ● 指定行数に適合するウィンドウの高さを計算
  58. #--------------------------------------------------------------------------
  59. def fitting_height(line_number)
  60. line_number * line_height + standard_padding * 2
  61. end
  62. #--------------------------------------------------------------------------
  63. # ● 色調の更新
  64. #--------------------------------------------------------------------------
  65. def update_tone
  66. self.tone.set($game_system.window_tone)
  67. end
  68. #--------------------------------------------------------------------------
  69. # ● ウィンドウ内容の作成
  70. #--------------------------------------------------------------------------
  71. def create_contents
  72. contents.dispose
  73. if contents_width > 0 && contents_height > 0
  74. self.contents = Bitmap.new(contents_width, contents_height)
  75. else
  76. self.contents = Bitmap.new(1, 1)
  77. end
  78. end
  79. #--------------------------------------------------------------------------
  80. # ● フレーム更新
  81. #--------------------------------------------------------------------------
  82. def update
  83. super
  84. update_tone
  85. update_open if @opening
  86. update_close if @closing
  87. end
  88. #--------------------------------------------------------------------------
  89. # ● 開く処理の更新
  90. #--------------------------------------------------------------------------
  91. def update_open
  92. self.openness += 48
  93. @opening = false if open?
  94. end
  95. #--------------------------------------------------------------------------
  96. # ● 閉じる処理の更新
  97. #--------------------------------------------------------------------------
  98. def update_close
  99. self.openness -= 48
  100. @closing = false if close?
  101. end
  102. #--------------------------------------------------------------------------
  103. # ● ウィンドウを開く
  104. #--------------------------------------------------------------------------
  105. def open
  106. @opening = true unless open?
  107. @closing = false
  108. self
  109. end
  110. #--------------------------------------------------------------------------
  111. # ● ウィンドウを閉じる
  112. #--------------------------------------------------------------------------
  113. def close
  114. @closing = true unless close?
  115. @opening = false
  116. self
  117. end
  118. #--------------------------------------------------------------------------
  119. # ● ウィンドウの表示
  120. #--------------------------------------------------------------------------
  121. def show
  122. self.visible = true
  123. self
  124. end
  125. #--------------------------------------------------------------------------
  126. # ● ウィンドウの非表示
  127. #--------------------------------------------------------------------------
  128. def hide
  129. self.visible = false
  130. self
  131. end
  132. #--------------------------------------------------------------------------
  133. # ● ウィンドウのアクティブ化
  134. #--------------------------------------------------------------------------
  135. def activate
  136. self.active = true
  137. self
  138. end
  139. #--------------------------------------------------------------------------
  140. # ● ウィンドウの非アクティブ化
  141. #--------------------------------------------------------------------------
  142. def deactivate
  143. self.active = false
  144. self
  145. end
  146. #--------------------------------------------------------------------------
  147. # ● 文字色取得
  148. # n : 文字色番号(0..31)
  149. #--------------------------------------------------------------------------
  150. def text_color(n)
  151. windowskin.get_pixel(64 + (n % 8) * 8, 96 + (n / 8) * 8)
  152. end
  153. #--------------------------------------------------------------------------
  154. # ● 各種文字色の取得
  155. #--------------------------------------------------------------------------
  156. def normal_color; text_color(0); end; # 通常
  157. def system_color; text_color(16); end; # システム
  158. def crisis_color; text_color(17); end; # ピンチ
  159. def knockout_color; text_color(18); end; # 戦闘不能
  160. def gauge_back_color; text_color(19); end; # ゲージ背景
  161. def hp_gauge_color1; text_color(20); end; # HP ゲージ 1
  162. def hp_gauge_color2; text_color(21); end; # HP ゲージ 2
  163. def mp_gauge_color1; text_color(22); end; # MP ゲージ 1
  164. def mp_gauge_color2; text_color(23); end; # MP ゲージ 2
  165. def mp_cost_color; text_color(23); end; # 消費 TP
  166. def power_up_color; text_color(24); end; # 装備 パワーアップ
  167. def power_down_color; text_color(25); end; # 装備 パワーダウン
  168. def tp_gauge_color1; text_color(28); end; # TP ゲージ 1
  169. def tp_gauge_color2; text_color(29); end; # TP ゲージ 2
  170. def tp_cost_color; text_color(29); end; # 消費 TP
  171. #--------------------------------------------------------------------------
  172. # ● 保留項目の背景色を取得
  173. #--------------------------------------------------------------------------
  174. def pending_color
  175. windowskin.get_pixel(80, 80)
  176. end
  177. #--------------------------------------------------------------------------
  178. # ● 半透明描画用のアルファ値を取得
  179. #--------------------------------------------------------------------------
  180. def translucent_alpha
  181. return 160
  182. end
  183. #--------------------------------------------------------------------------
  184. # ● テキスト描画色の変更
  185. # enabled : 有効フラグ。false のとき半透明で描画
  186. #--------------------------------------------------------------------------
  187. def change_color(color, enabled = true)
  188. contents.font.color.set(color)
  189. contents.font.color.alpha = translucent_alpha unless enabled
  190. end
  191. #--------------------------------------------------------------------------
  192. # ● テキストの描画
  193. # args : Bitmap#draw_text と同じ
  194. #--------------------------------------------------------------------------
  195. def draw_text(*args)
  196. contents.draw_text(*args)
  197. end
  198. #--------------------------------------------------------------------------
  199. # ● テキストサイズの取得
  200. #--------------------------------------------------------------------------
  201. def text_size(str)
  202. contents.text_size(str)
  203. end
  204. #--------------------------------------------------------------------------
  205. # ● 制御文字つきテキストの描画
  206. #--------------------------------------------------------------------------
  207. def draw_text_ex(x, y, text)
  208. reset_font_settings
  209. text = convert_escape_characters(text)
  210. pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
  211. process_character(text.slice!(0, 1), text, pos) until text.empty?
  212. end
  213. #--------------------------------------------------------------------------
  214. # ● フォント設定のリセット
  215. #--------------------------------------------------------------------------
  216. def reset_font_settings
  217. change_color(normal_color)
  218. contents.font.size = Font.default_size
  219. contents.font.bold = false
  220. contents.font.italic = false
  221. end
  222. #--------------------------------------------------------------------------
  223. # Pruebas
  224. #--------------------------------------------------------------------------
  225. def custom_convert(x_case, y_case = 0, z_case = 0)
  226. text = ""
  227. case x_case
  228. when 1 # Introduce \X[1] en la descripción de algo para mostrar el valor de n
  229. n = 50 + $game_actors[1].level
  230. text = n.to_i
  231. when 2 # \X[2] muestra un valor u otro según el requisito que se cumpla
  232. n = 6 if $game_actors[1].level <= 6
  233. n = $game_actors[1].level if $game_actors[1].level > 6
  234. text = n.to_i
  235. when 3 # Sanación relámpago
  236. n = $game_actors[1].mat * 3
  237. text = n.to_i
  238. end
  239. return text
  240. end
  241. #--------------------------------------------------------------------------
  242. # Pruebas
  243. #--------------------------------------------------------------------------
  244. def convert_escape_characters(text)
  245. result = text.to_s.clone
  246. result.gsub!(/\\X\[(\d+)\]/i) {
  247. custom_convert($1.to_i) }
  248. result.gsub!(/\\X\[(\d+):(\d+)\]/i) {
  249. custom_convert($1.to_i, $2.to_i) }
  250. result.gsub!(/\\X\[(\d+):(\d+):(\d+)\]/i) {
  251. custom_convert($1.to_i, $2.to_i, $3.to_i) }
  252. result.gsub!(/\\/) { "\e" }
  253. result.gsub!(/\e\e/) { "\\" }
  254. result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i] }
  255. result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i] }
  256. result.gsub!(/\eN\[(\d+)\]/i) { actor_name($1.to_i) }
  257. result.gsub!(/\eP\[(\d+)\]/i) { party_member_name($1.to_i) }
  258. result.gsub!(/\eG/i) { Vocab::currency_unit }
  259. result
  260. end
  261. #--------------------------------------------------------------------------
  262. # ● アクター n 番の名前を取得
  263. #--------------------------------------------------------------------------
  264. def actor_name(n)
  265. actor = n >= 1 ? $game_actors[n] : nil
  266. actor ? actor.name : ""
  267. end
  268. #--------------------------------------------------------------------------
  269. # ● パーティメンバー n 番の名前を取得
  270. #--------------------------------------------------------------------------
  271. def party_member_name(n)
  272. actor = n >= 1 ? $game_party.members[n - 1] : nil
  273. actor ? actor.name : ""
  274. end
  275. #--------------------------------------------------------------------------
  276. # ● 文字の処理
  277. # c : 文字
  278. # text : 描画処理中の文字列バッファ(必要なら破壊的に変更)
  279. # pos : 描画位置 {:x, :y, :new_x, :height}
  280. #--------------------------------------------------------------------------
  281. def process_character(c, text, pos)
  282. case c
  283. when "\n" # 改行
  284. process_new_line(text, pos)
  285. when "\f" # 改ページ
  286. process_new_page(text, pos)
  287. when "\e" # 制御文字
  288. process_escape_character(obtain_escape_code(text), text, pos)
  289. else # 普通の文字
  290. process_normal_character(c, pos)
  291. end
  292. end
  293. #--------------------------------------------------------------------------
  294. # ● 通常文字の処理
  295. #--------------------------------------------------------------------------
  296. def process_normal_character(c, pos)
  297. text_width = text_size(c).width
  298. draw_text(pos[:x], pos[:y], text_width * 2, pos[:height], c)
  299. pos[:x] += text_width
  300. end
  301. #--------------------------------------------------------------------------
  302. # ● 改行文字の処理
  303. #--------------------------------------------------------------------------
  304. def process_new_line(text, pos)
  305. pos[:x] = pos[:new_x]
  306. pos[:y] += pos[:height]
  307. pos[:height] = calc_line_height(text)
  308. end
  309. #--------------------------------------------------------------------------
  310. # ● 改ページ文字の処理
  311. #--------------------------------------------------------------------------
  312. def process_new_page(text, pos)
  313. end
  314. #--------------------------------------------------------------------------
  315. # ● 制御文字の本体を破壊的に取得
  316. #--------------------------------------------------------------------------
  317. def obtain_escape_code(text)
  318. text.slice!(/^[\$\.\|\^!><\{\}\\]|^[A-Z]+/i)
  319. end
  320. #--------------------------------------------------------------------------
  321. # ● 制御文字の引数を破壊的に取得
  322. #--------------------------------------------------------------------------
  323. def obtain_escape_param(text)
  324. text.slice!(/^\[\d+\]/)[/\d+/].to_i rescue 0
  325. end
  326. #--------------------------------------------------------------------------
  327. # ● 制御文字の処理
  328. # code : 制御文字の本体部分(「\C[1]」なら「C」)
  329. #--------------------------------------------------------------------------
  330. def process_escape_character(code, text, pos)
  331. case code.upcase
  332. when 'C'
  333. change_color(text_color(obtain_escape_param(text)))
  334. when 'I'
  335. process_draw_icon(obtain_escape_param(text), pos)
  336. when '{'
  337. make_font_bigger
  338. when '}'
  339. make_font_smaller
  340. end
  341. end
  342. #--------------------------------------------------------------------------
  343. # ● 制御文字によるアイコン描画の処理
  344. #--------------------------------------------------------------------------
  345. def process_draw_icon(icon_index, pos)
  346. draw_icon(icon_index, pos[:x], pos[:y])
  347. pos[:x] += 24
  348. end
  349. #--------------------------------------------------------------------------
  350. # ● フォントを大きくする
  351. #--------------------------------------------------------------------------
  352. def make_font_bigger
  353. contents.font.size += 8 if contents.font.size <= 64
  354. end
  355. #--------------------------------------------------------------------------
  356. # ● フォントを小さくする
  357. #--------------------------------------------------------------------------
  358. def make_font_smaller
  359. contents.font.size -= 8 if contents.font.size >= 16
  360. end
  361. #--------------------------------------------------------------------------
  362. # ● 行の高さを計算
  363. # restore_font_size : 計算後にフォントサイズを元に戻す
  364. #--------------------------------------------------------------------------
  365. def calc_line_height(text, restore_font_size = true)
  366. result = [line_height, contents.font.size].max
  367. last_font_size = contents.font.size
  368. text.slice(/^.*$/).scan(/\e[\{\}]/).each do |esc|
  369. make_font_bigger if esc == "\e{"
  370. make_font_smaller if esc == "\e}"
  371. result = [result, contents.font.size].max
  372. end
  373. contents.font.size = last_font_size if restore_font_size
  374. result
  375. end
  376. #--------------------------------------------------------------------------
  377. # ● ゲージの描画
  378. # rate : 割合(1.0 で満タン)
  379. # color1 : グラデーション 左端
  380. # color2 : グラデーション 右端
  381. #--------------------------------------------------------------------------
  382. def draw_gauge(x, y, width, rate, color1, color2)
  383. fill_w = (width * rate).to_i
  384. gauge_y = y + line_height - 8
  385. contents.fill_rect(x, gauge_y, width, 6, gauge_back_color)
  386. contents.gradient_fill_rect(x, gauge_y, fill_w, 6, color1, color2)
  387. end
  388. #--------------------------------------------------------------------------
  389. # ● アイコンの描画
  390. # enabled : 有効フラグ。false のとき半透明で描画
  391. #--------------------------------------------------------------------------
  392. def draw_icon(icon_index, x, y, enabled = true)
  393. bitmap = Cache.system("Iconset")
  394. rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  395. contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
  396. end
  397. #--------------------------------------------------------------------------
  398. # ● 顔グラフィックの描画
  399. # enabled : 有効フラグ。false のとき半透明で描画
  400. #--------------------------------------------------------------------------
  401. def draw_face(face_name, face_index, x, y, enabled = true)
  402. bitmap = Cache.face(face_name)
  403. rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96, 96, 96)
  404. contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
  405. bitmap.dispose
  406. end
  407. #--------------------------------------------------------------------------
  408. # ● 歩行グラフィックの描画
  409. #--------------------------------------------------------------------------
  410. def draw_character(character_name, character_index, x, y)
  411. return unless character_name
  412. bitmap = Cache.character(character_name)
  413. sign = character_name[/^[\!\$]./]
  414. if sign && sign.include?('$')
  415. cw = bitmap.width / 3
  416. ch = bitmap.height / 4
  417. else
  418. cw = bitmap.width / 12
  419. ch = bitmap.height / 8
  420. end
  421. n = character_index
  422. src_rect = Rect.new((n%4*3+1)*cw, (n/4*4)*ch, cw, ch)
  423. contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
  424. end
  425. #--------------------------------------------------------------------------
  426. # ● HP の文字色を取得
  427. #--------------------------------------------------------------------------
  428. def hp_color(actor)
  429. return knockout_color if actor.hp == 0
  430. return crisis_color if actor.hp < actor.mhp / 4
  431. return normal_color
  432. end
  433. #--------------------------------------------------------------------------
  434. # ● MP の文字色を取得
  435. #--------------------------------------------------------------------------
  436. def mp_color(actor)
  437. return crisis_color if actor.mp < actor.mmp / 4
  438. return normal_color
  439. end
  440. #--------------------------------------------------------------------------
  441. # ● TP の文字色を取得
  442. #--------------------------------------------------------------------------
  443. def tp_color(actor)
  444. return normal_color
  445. end
  446. #--------------------------------------------------------------------------
  447. # ● アクターの歩行グラフィック描画
  448. #--------------------------------------------------------------------------
  449. def draw_actor_graphic(actor, x, y)
  450. draw_character(actor.character_name, actor.character_index, x, y)
  451. end
  452. #--------------------------------------------------------------------------
  453. # ● アクターの顔グラフィック描画
  454. #--------------------------------------------------------------------------
  455. def draw_actor_face(actor, x, y, enabled = true)
  456. draw_face(actor.face_name, actor.face_index, x, y, enabled)
  457. end
  458. #--------------------------------------------------------------------------
  459. # ● 名前の描画
  460. #--------------------------------------------------------------------------
  461. def draw_actor_name(actor, x, y, width = 112)
  462. change_color(hp_color(actor))
  463. draw_text(x, y, width, line_height, actor.name)
  464. end
  465. #--------------------------------------------------------------------------
  466. # ● 職業の描画
  467. #--------------------------------------------------------------------------
  468. def draw_actor_class(actor, x, y, width = 112)
  469. change_color(normal_color)
  470. draw_text(x, y, width, line_height, actor.class.name)
  471. end
  472. #--------------------------------------------------------------------------
  473. # ● 二つ名の描画
  474. #--------------------------------------------------------------------------
  475. def draw_actor_nickname(actor, x, y, width = 180)
  476. change_color(normal_color)
  477. draw_text(x, y, width, line_height, actor.nickname)
  478. end
  479. #--------------------------------------------------------------------------
  480. # ● レベルの描画
  481. #--------------------------------------------------------------------------
  482. def draw_actor_level(actor, x, y)
  483. change_color(system_color)
  484. draw_text(x, y, 32, line_height, Vocab::level_a)
  485. change_color(normal_color)
  486. draw_text(x + 32, y, 24, line_height, actor.level, 2)
  487. end
  488. #--------------------------------------------------------------------------
  489. # ● ステートおよび強化/弱体のアイコンを描画
  490. #--------------------------------------------------------------------------
  491. def draw_actor_icons(actor, x, y, width = 96)
  492. icons = (actor.state_icons + actor.buff_icons)[0, width / 24]
  493. icons.each_with_index {|n, i| draw_icon(n, x + 24 * i, y) }
  494. end
  495. #--------------------------------------------------------------------------
  496. # ● 現在値/最大値を分数形式で描画
  497. # current : 現在値
  498. # max : 最大値
  499. # color1 : 現在値の色
  500. # color2 : 最大値の色
  501. #--------------------------------------------------------------------------
  502. def draw_current_and_max_values(x, y, width, current, max, color1, color2)
  503. change_color(color1)
  504. xr = x + width
  505. if width < 96
  506. draw_text(xr - 40, y, 42, line_height, current, 2)
  507. else
  508. draw_text(xr - 92, y, 42, line_height, current, 2)
  509. change_color(color2)
  510. draw_text(xr - 52, y, 12, line_height, "/", 2)
  511. draw_text(xr - 42, y, 42, line_height, max, 2)
  512. end
  513. end
  514. #--------------------------------------------------------------------------
  515. # ● HP の描画
  516. #--------------------------------------------------------------------------
  517. def draw_actor_hp(actor, x, y, width = 124)
  518. draw_gauge(x, y, width, actor.hp_rate, hp_gauge_color1, hp_gauge_color2)
  519. change_color(system_color)
  520. draw_text(x, y, 30, line_height, Vocab::hp_a)
  521. draw_current_and_max_values(x, y, width, actor.hp, actor.mhp,
  522. hp_color(actor), normal_color)
  523. end
  524. #--------------------------------------------------------------------------
  525. # ● MP の描画
  526. #--------------------------------------------------------------------------
  527. def draw_actor_mp(actor, x, y, width = 124)
  528. draw_gauge(x, y, width, actor.mp_rate, mp_gauge_color1, mp_gauge_color2)
  529. change_color(system_color)
  530. draw_text(x, y, 30, line_height, Vocab::mp_a)
  531. draw_current_and_max_values(x, y, width, actor.mp, actor.mmp,
  532. mp_color(actor), normal_color)
  533. end
  534. #--------------------------------------------------------------------------
  535. # ● TP の描画
  536. #--------------------------------------------------------------------------
  537. def draw_actor_tp(actor, x, y, width = 124)
  538. draw_gauge(x, y, width, actor.tp_rate, tp_gauge_color1, tp_gauge_color2)
  539. change_color(system_color)
  540. draw_text(x, y, 30, line_height, Vocab::tp_a)
  541. change_color(tp_color(actor))
  542. draw_text(x + width - 42, y, 42, line_height, actor.tp.to_i, 2)
  543. end
  544. #--------------------------------------------------------------------------
  545. # ● シンプルなステータスの描画
  546. #--------------------------------------------------------------------------
  547. def draw_actor_simple_status(actor, x, y)
  548. draw_actor_name(actor, x, y)
  549. draw_actor_level(actor, x, y + line_height * 1)
  550. draw_actor_icons(actor, x, y + line_height * 2)
  551. draw_actor_class(actor, x + 120, y)
  552. draw_actor_hp(actor, x + 120, y + line_height * 1)
  553. draw_actor_mp(actor, x + 120, y + line_height * 2)
  554. end
  555. #--------------------------------------------------------------------------
  556. # ● 能力値の描画
  557. #--------------------------------------------------------------------------
  558. def draw_actor_param(actor, x, y, param_id)
  559. change_color(system_color)
  560. draw_text(x, y, 120, line_height, Vocab::param(param_id))
  561. change_color(normal_color)
  562. draw_text(x + 120, y, 36, line_height, actor.param(param_id), 2)
  563. end
  564. #--------------------------------------------------------------------------
  565. # ● アイテム名の描画
  566. # enabled : 有効フラグ。false のとき半透明で描画
  567. #--------------------------------------------------------------------------
  568. def draw_item_name(item, x, y, enabled = true, width = 172)
  569. return unless item
  570. draw_icon(item.icon_index, x, y, enabled)
  571. change_color(normal_color, enabled)
  572. draw_text(x + 24, y, width, line_height, item.name)
  573. end
  574. #--------------------------------------------------------------------------
  575. # ● 通貨単位つき数値(所持金など)の描画
  576. #--------------------------------------------------------------------------
  577. def draw_currency_value(value, unit, x, y, width)
  578. cx = text_size(unit).width
  579. change_color(normal_color)
  580. draw_text(x, y, width - cx - 2, line_height, value, 2)
  581. change_color(system_color)
  582. draw_text(x, y, width, line_height, unit, 2)
  583. end
  584. #--------------------------------------------------------------------------
  585. # ● 能力値変化の描画色取得
  586. #--------------------------------------------------------------------------
  587. def param_change_color(change)
  588. return power_up_color if change > 0
  589. return power_down_color if change < 0
  590. return normal_color
  591. end
  592. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement