Advertisement
luistop12

Windowskin opacity

Feb 25th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.89 KB | None | 0 0
  1. #==============================================================================
  2. # ■ Window_Base
  3. #------------------------------------------------------------------------------
  4. #  ゲーム中のすべてのウィンドウのスーパークラスです。
  5. #==============================================================================
  6.  
  7. class Window_Base < Window
  8. #--------------------------------------------------------------------------
  9. # ● 定数
  10. #--------------------------------------------------------------------------
  11. WLH = 24 # 行の高さ基準値 (Window Line Height)
  12. #--------------------------------------------------------------------------
  13. # ● オブジェクト初期化
  14. # x : ウィンドウの X 座標
  15. # y : ウィンドウの Y 座標
  16. # width : ウィンドウの幅
  17. # height : ウィンドウの高さ
  18. #--------------------------------------------------------------------------
  19. def initialize(x, y, width, height)
  20. super()
  21. self.windowskin = Cache.system("Window")
  22. self.x = x
  23. self.y = y
  24. self.width = width
  25. self.height = height
  26. self.z = 100
  27. self.back_opacity = 0
  28. self.openness = 255
  29. create_contents
  30. @opening = false
  31. @closing = false
  32. end
  33. #--------------------------------------------------------------------------
  34. # ● 解放
  35. #--------------------------------------------------------------------------
  36. def dispose
  37. self.contents.dispose
  38. super
  39. end
  40. #--------------------------------------------------------------------------
  41. # ● ウィンドウ内容の作成
  42. #--------------------------------------------------------------------------
  43. def create_contents
  44. self.contents.dispose
  45. self.contents = Bitmap.new(width - 32, height - 32)
  46. end
  47. #--------------------------------------------------------------------------
  48. # ● フレーム更新
  49. #--------------------------------------------------------------------------
  50. def update
  51. super
  52. if @opening
  53. self.openness += 48
  54. @opening = false if self.openness == 255
  55. elsif @closing
  56. self.openness -= 48
  57. @closing = false if self.openness == 0
  58. end
  59. end
  60. #--------------------------------------------------------------------------
  61. # ● ウィンドウを開く
  62. #--------------------------------------------------------------------------
  63. def open
  64. @opening = true if self.openness < 255
  65. @closing = false
  66. end
  67. #--------------------------------------------------------------------------
  68. # ● ウィンドウを閉じる
  69. #--------------------------------------------------------------------------
  70. def close
  71. @closing = true if self.openness > 0
  72. @opening = false
  73. end
  74. #--------------------------------------------------------------------------
  75. # ● 文字色取得
  76. # n : 文字色番号 (0~31)
  77. #--------------------------------------------------------------------------
  78. def text_color(n)
  79. x = 64 + (n % 8) * 8
  80. y = 96 + (n / 8) * 8
  81. return windowskin.get_pixel(x, y)
  82. end
  83. #--------------------------------------------------------------------------
  84. # ● 通常文字色の取得
  85. #--------------------------------------------------------------------------
  86. def normal_color
  87. return text_color(0)
  88. end
  89. #--------------------------------------------------------------------------
  90. # ● システム文字色の取得
  91. #--------------------------------------------------------------------------
  92. def system_color
  93. return text_color(16)
  94. end
  95. #--------------------------------------------------------------------------
  96. # ● ピンチ文字色の取得
  97. #--------------------------------------------------------------------------
  98. def crisis_color
  99. return text_color(17)
  100. end
  101. #--------------------------------------------------------------------------
  102. # ● 戦闘不能文字色の取得
  103. #--------------------------------------------------------------------------
  104. def knockout_color
  105. return text_color(18)
  106. end
  107. #--------------------------------------------------------------------------
  108. # ● ゲージ背景色の取得
  109. #--------------------------------------------------------------------------
  110. def gauge_back_color
  111. return text_color(19)
  112. end
  113. #--------------------------------------------------------------------------
  114. # ● HP ゲージの色 1 の取得
  115. #--------------------------------------------------------------------------
  116. def hp_gauge_color1
  117. return text_color(20)
  118. end
  119. #--------------------------------------------------------------------------
  120. # ● HP ゲージの色 2 の取得
  121. #--------------------------------------------------------------------------
  122. def hp_gauge_color2
  123. return text_color(21)
  124. end
  125. #--------------------------------------------------------------------------
  126. # ● MP ゲージの色 1 の取得
  127. #--------------------------------------------------------------------------
  128. def mp_gauge_color1
  129. return text_color(22)
  130. end
  131. #--------------------------------------------------------------------------
  132. # ● MP ゲージの色 2 の取得
  133. #--------------------------------------------------------------------------
  134. def mp_gauge_color2
  135. return text_color(23)
  136. end
  137. #--------------------------------------------------------------------------
  138. # ● 装備画面のパワーアップ色の取得
  139. #--------------------------------------------------------------------------
  140. def power_up_color
  141. return text_color(24)
  142. end
  143. #--------------------------------------------------------------------------
  144. # ● 装備画面のパワーダウン色の取得
  145. #--------------------------------------------------------------------------
  146. def power_down_color
  147. return text_color(25)
  148. end
  149. #--------------------------------------------------------------------------
  150. # ● アイコンの描画
  151. # icon_index : アイコン番号
  152. # x : 描画先 X 座標
  153. # y : 描画先 Y 座標
  154. # enabled : 有効フラグ。false のとき半透明で描画
  155. #--------------------------------------------------------------------------
  156. def draw_icon(icon_index, x, y, enabled = true)
  157. bitmap = Cache.system("Iconset")
  158. rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  159. self.contents.blt(x, y, bitmap, rect, enabled ? 255 : 128)
  160. end
  161. #--------------------------------------------------------------------------
  162. # ● 顔グラフィックの描画
  163. # face_name : 顔グラフィック ファイル名
  164. # face_index : 顔グラフィック インデックス
  165. # x : 描画先 X 座標
  166. # y : 描画先 Y 座標
  167. # size : 表示サイズ
  168. #--------------------------------------------------------------------------
  169. def draw_face(face_name, face_index, x, y, size = 96)
  170. bitmap = Cache.face(face_name)
  171. rect = Rect.new(0, 0, 0, 0)
  172. rect.x = face_index % 4 * 96 + (96 - size) / 2
  173. rect.y = face_index / 4 * 96 + (96 - size) / 2
  174. rect.width = size
  175. rect.height = size
  176. self.contents.blt(x, y, bitmap, rect)
  177. bitmap.dispose
  178. end
  179. #--------------------------------------------------------------------------
  180. # ● 歩行グラフィックの描画
  181. # character_name : 歩行グラフィック ファイル名
  182. # character_index : 歩行グラフィック インデックス
  183. # x : 描画先 X 座標
  184. # y : 描画先 Y 座標
  185. #--------------------------------------------------------------------------
  186. def draw_character(character_name, character_index, x, y)
  187. return if character_name == nil
  188. bitmap = Cache.character(character_name)
  189. sign = character_name[/^[\!\$]./]
  190. if sign != nil and sign.include?('$')
  191. cw = bitmap.width / 3
  192. ch = bitmap.height / 4
  193. else
  194. cw = bitmap.width / 12
  195. ch = bitmap.height / 8
  196. end
  197. n = character_index
  198. src_rect = Rect.new((n%4*3+1)*cw, (n/4*4)*ch, cw, ch)
  199. self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
  200. end
  201. #--------------------------------------------------------------------------
  202. # ● HP の文字色を取得
  203. # actor : アクター
  204. #--------------------------------------------------------------------------
  205. def hp_color(actor)
  206. return knockout_color if actor.hp == 0
  207. return crisis_color if actor.hp < actor.maxhp / 4
  208. return normal_color
  209. end
  210. #--------------------------------------------------------------------------
  211. # ● MP の文字色を取得
  212. # actor : アクター
  213. #--------------------------------------------------------------------------
  214. def mp_color(actor)
  215. return crisis_color if actor.mp < actor.maxmp / 4
  216. return normal_color
  217. end
  218. #--------------------------------------------------------------------------
  219. # ● アクターの歩行グラフィック描画
  220. # actor : アクター
  221. # x : 描画先 X 座標
  222. # y : 描画先 Y 座標
  223. #--------------------------------------------------------------------------
  224. def draw_actor_graphic(actor, x, y)
  225. draw_character(actor.character_name, actor.character_index, x, y)
  226. end
  227. #--------------------------------------------------------------------------
  228. # ● アクターの顔グラフィック描画
  229. # actor : アクター
  230. # x : 描画先 X 座標
  231. # y : 描画先 Y 座標
  232. # size : 表示サイズ
  233. #--------------------------------------------------------------------------
  234. def draw_actor_face(actor, x, y, size = 96)
  235. draw_face(actor.face_name, actor.face_index, x, y, size)
  236. end
  237. #--------------------------------------------------------------------------
  238. # ● 名前の描画
  239. # actor : アクター
  240. # x : 描画先 X 座標
  241. # y : 描画先 Y 座標
  242. #--------------------------------------------------------------------------
  243. def draw_actor_name(actor, x, y)
  244. self.contents.font.color = hp_color(actor)
  245. self.contents.draw_text(x, y, 108, WLH, actor.name)
  246. end
  247. #--------------------------------------------------------------------------
  248. # ● クラスの描画
  249. # actor : アクター
  250. # x : 描画先 X 座標
  251. # y : 描画先 Y 座標
  252. #--------------------------------------------------------------------------
  253. def draw_actor_class(actor, x, y)
  254. self.contents.font.color = normal_color
  255. self.contents.draw_text(x, y, 108, WLH, actor.class.name)
  256. end
  257. #--------------------------------------------------------------------------
  258. # ● レベルの描画
  259. # actor : アクター
  260. # x : 描画先 X 座標
  261. # y : 描画先 Y 座標
  262. #--------------------------------------------------------------------------
  263. def draw_actor_level(actor, x, y)
  264. self.contents.font.color = system_color
  265. self.contents.draw_text(x, y, 32, WLH, Vocab::level_a)
  266. self.contents.font.color = normal_color
  267. self.contents.draw_text(x + 32, y, 24, WLH, actor.level, 2)
  268. end
  269. #--------------------------------------------------------------------------
  270. # ● ステートの描画
  271. # actor : アクター
  272. # x : 描画先 X 座標
  273. # y : 描画先 Y 座標
  274. # width : 描画先の幅
  275. #--------------------------------------------------------------------------
  276. def draw_actor_state(actor, x, y, width = 96)
  277. count = 0
  278. for state in actor.states
  279. draw_icon(state.icon_index, x + 24 * count, y)
  280. count += 1
  281. break if (24 * count > width - 24)
  282. end
  283. end
  284. #--------------------------------------------------------------------------
  285. # ● HP の描画
  286. # actor : アクター
  287. # x : 描画先 X 座標
  288. # y : 描画先 Y 座標
  289. # width : 幅
  290. #--------------------------------------------------------------------------
  291. def draw_actor_hp(actor, x, y, width = 120)
  292. draw_actor_hp_gauge(actor, x, y, width)
  293. self.contents.font.color = system_color
  294. self.contents.draw_text(x, y, 30, WLH, Vocab::hp_a)
  295. self.contents.font.color = hp_color(actor)
  296. xr = x + width
  297. if width < 120
  298. self.contents.draw_text(xr - 40, y, 40, WLH, actor.hp, 2)
  299. else
  300. self.contents.draw_text(xr - 90, y, 40, WLH, actor.hp, 2)
  301. self.contents.font.color = normal_color
  302. self.contents.draw_text(xr - 50, y, 10, WLH, "/", 2)
  303. self.contents.draw_text(xr - 40, y, 40, WLH, actor.maxhp, 2)
  304. end
  305. end
  306. #--------------------------------------------------------------------------
  307. # ● HP ゲージの描画
  308. # actor : アクター
  309. # x : 描画先 X 座標
  310. # y : 描画先 Y 座標
  311. # width : 幅
  312. #--------------------------------------------------------------------------
  313. def draw_actor_hp_gauge(actor, x, y, width = 120)
  314. gw = width * actor.hp / actor.maxhp
  315. gc1 = hp_gauge_color1
  316. gc2 = hp_gauge_color2
  317. self.contents.fill_rect(x, y + WLH - 8, width, 6, gauge_back_color)
  318. self.contents.gradient_fill_rect(x, y + WLH - 8, gw, 6, gc1, gc2)
  319. end
  320. #--------------------------------------------------------------------------
  321. # ● MP の描画
  322. # actor : アクター
  323. # x : 描画先 X 座標
  324. # y : 描画先 Y 座標
  325. # width : 幅
  326. #--------------------------------------------------------------------------
  327. def draw_actor_mp(actor, x, y, width = 120)
  328. draw_actor_mp_gauge(actor, x, y, width)
  329. self.contents.font.color = system_color
  330. self.contents.draw_text(x, y, 30, WLH, Vocab::mp_a)
  331. self.contents.font.color = mp_color(actor)
  332. xr = x + width
  333. if width < 120
  334. self.contents.draw_text(xr - 40, y, 40, WLH, actor.mp, 2)
  335. else
  336. self.contents.draw_text(xr - 90, y, 40, WLH, actor.mp, 2)
  337. self.contents.font.color = normal_color
  338. self.contents.draw_text(xr - 50, y, 10, WLH, "/", 2)
  339. self.contents.draw_text(xr - 40, y, 40, WLH, actor.maxmp, 2)
  340. end
  341. end
  342. #--------------------------------------------------------------------------
  343. # ● MP ゲージの描画
  344. # actor : アクター
  345. # x : 描画先 X 座標
  346. # y : 描画先 Y 座標
  347. # width : 幅
  348. #--------------------------------------------------------------------------
  349. def draw_actor_mp_gauge(actor, x, y, width = 120)
  350. gw = width * actor.mp / [actor.maxmp, 1].max
  351. gc1 = mp_gauge_color1
  352. gc2 = mp_gauge_color2
  353. self.contents.fill_rect(x, y + WLH - 8, width, 6, gauge_back_color)
  354. self.contents.gradient_fill_rect(x, y + WLH - 8, gw, 6, gc1, gc2)
  355. end
  356. #--------------------------------------------------------------------------
  357. # ● 能力値の描画
  358. # actor : アクター
  359. # x : 描画先 X 座標
  360. # y : 描画先 Y 座標
  361. # type : 能力値の種類 (0~3)
  362. #--------------------------------------------------------------------------
  363. def draw_actor_parameter(actor, x, y, type)
  364. case type
  365. when 0
  366. parameter_name = Vocab::atk
  367. parameter_value = actor.atk
  368. when 1
  369. parameter_name = Vocab::def
  370. parameter_value = actor.def
  371. when 2
  372. parameter_name = Vocab::spi
  373. parameter_value = actor.spi
  374. when 3
  375. parameter_name = Vocab::agi
  376. parameter_value = actor.agi
  377. end
  378. self.contents.font.color = system_color
  379. self.contents.draw_text(x, y, 120, WLH, parameter_name)
  380. self.contents.font.color = normal_color
  381. self.contents.draw_text(x + 120, y, 36, WLH, parameter_value, 2)
  382. end
  383. #--------------------------------------------------------------------------
  384. # ● アイテム名の描画
  385. # item : アイテム (スキル、武器、防具でも可)
  386. # x : 描画先 X 座標
  387. # y : 描画先 Y 座標
  388. # enabled : 有効フラグ。false のとき半透明で描画
  389. #--------------------------------------------------------------------------
  390. def draw_item_name(item, x, y, enabled = true)
  391. if item != nil
  392. draw_icon(item.icon_index, x, y, enabled)
  393. self.contents.font.color = normal_color
  394. self.contents.font.color.alpha = enabled ? 255 : 128
  395. self.contents.draw_text(x + 24, y, 172, WLH, item.name)
  396. end
  397. end
  398. #--------------------------------------------------------------------------
  399. # ● 通貨単位つきの数値描画
  400. # value : 数値 (所持金など)
  401. # x : 描画先 X 座標
  402. # y : 描画先 Y 座標
  403. # width : 幅
  404. #--------------------------------------------------------------------------
  405. def draw_currency_value(value, x, y, width)
  406. cx = contents.text_size(Vocab::gold).width
  407. self.contents.font.color = normal_color
  408. self.contents.draw_text(x, y, width-cx-2, WLH, value, 2)
  409. self.contents.font.color = system_color
  410. self.contents.draw_text(x, y, width, WLH, Vocab::gold, 2)
  411. end
  412. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement