Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  2. #_/    ◆ RPGVXAXE- KMS_GenericGauge ◆ VX Ace ◆
  3. #_/    ◇ Last update : 2012/08/05 (TOMY@Kamesoft) ◇
  4. #_/----------------------------------------------------------------------------
  5. #_/  汎用的なゲージ描画機能を提供します。
  6. #_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  7.  
  8. #==============================================================================
  9. # ★ 設定項目 - BEGIN Setting ★
  10. #==============================================================================
  11.  
  12. module KMS_GenericGauge
  13.   # Bản Thiết Lập
  14.   #  "Graphics/System" Nơi bỏ file
  15.   HP_IMAGE  = "GaugeHP"   # HP
  16.   MP_IMAGE  = "GaugeMP"   # MP
  17.   TP_IMAGE  = "GaugeTP"   # TP
  18.   EXP_IMAGE = "GaugeEXP"  # EXP
  19.  
  20.   # ◆ ゲージ位置補正 [x, y]
  21.   HP_OFFSET  = [-23, -2]  # HP
  22.   MP_OFFSET  = [-23, -2]  # MP
  23.   TP_OFFSET  = [-23, -2]  # TP
  24.   EXP_OFFSET = [-23, -2]  # EXP
  25.  
  26.   # ◆ ゲージ長補正
  27.   HP_LENGTH  = -4  # HP
  28.   MP_LENGTH  = -4  # MP
  29.   TP_LENGTH  = -4  # TP
  30.   EXP_LENGTH = -4  # EXP
  31.  
  32.   # ◆ ゲージの傾き角度
  33.   #  -89 ~ 89 で指定。
  34.   HP_SLOPE  = 30  # HP
  35.   MP_SLOPE  = 30  # MP
  36.   TP_SLOPE  = 30  # TP
  37.   EXP_SLOPE = 30  # EXPe
  38. end
  39.  
  40. #==============================================================================
  41. # ☆ 設定ここまで - END Setting ☆
  42. #==============================================================================
  43.  
  44. $kms_imported = {} if $kms_imported == nil
  45. $kms_imported["GenericGauge"] = true
  46.  
  47. # *****************************************************************************
  48.  
  49. #==============================================================================
  50. # ■ Bitmap
  51. #==============================================================================
  52.  
  53. class Bitmap
  54.   #--------------------------------------------------------------------------
  55.   # ○ 平行四辺形転送
  56.   #--------------------------------------------------------------------------
  57.   def skew_blt(x, y, src_bitmap, src_rect, slope, opacity = 255)
  58.     slope = [[slope, -90].max, 90].min
  59.     sh    = src_rect.height
  60.     off  = sh / Math.tan(Math::PI * (90 - slope.abs) / 180.0)
  61.     if slope >= 0
  62.       dx   = x + off.round
  63.       diff = -off / sh
  64.     else
  65.       dx   = x
  66.       diff = off / sh
  67.     end
  68.     rect = Rect.new(src_rect.x, src_rect.y, src_rect.width, 1)
  69.  
  70.     sh.times { |i|
  71.       blt(dx + (diff * i).round, y + i, src_bitmap, rect, opacity)
  72.       rect.y += 1
  73.     }
  74.   end
  75. end unless $kms_imported["BitmapExtension"]  # ビットマップ拡張未導入時のみ
  76.  
  77. #==============================================================================
  78. # ■ Game_Actor
  79. #==============================================================================
  80.  
  81. class Game_Actor < Game_Battler
  82.   #--------------------------------------------------------------------------
  83.   # ○ 現在のレベルから次のレベルまでの全必要経験値取得
  84.   #--------------------------------------------------------------------------
  85.   def next_level_exp_full
  86.     return next_level_exp - current_level_exp
  87.   end
  88.   #--------------------------------------------------------------------------
  89.   # ○ 次のレベルまでの残り経験値取得
  90.   #--------------------------------------------------------------------------
  91.   def next_level_exp_rest
  92.     return next_level_exp - exp
  93.   end
  94.   #--------------------------------------------------------------------------
  95.   # ○ 次のレベルまでの経験値取得率取得
  96.   #--------------------------------------------------------------------------
  97.   def exp_rate
  98.     diff = [next_level_exp_full, 1].max
  99.     rest = [next_level_exp_rest, 1].max
  100.     return (diff - rest) * 1.0 / diff
  101.   end
  102. end
  103.  
  104. #==============================================================================
  105. # ■ Window_Base
  106. #==============================================================================
  107.  
  108. class Window_Base < Window
  109.   #--------------------------------------------------------------------------
  110.   # ○ 定数
  111.   #--------------------------------------------------------------------------
  112.   # ゲージ転送元座標 [x, y]
  113.   GAUGE_SRC_POS = {
  114.     :normal   => [ 0, 24],
  115.     :decrease => [ 0, 48],
  116.     :increase => [72, 48],
  117.   }
  118.   #--------------------------------------------------------------------------
  119.   # ○ クラス変数
  120.   #--------------------------------------------------------------------------
  121.   @@__gauge_buf = Bitmap.new(320, 24)
  122.   #--------------------------------------------------------------------------
  123.   # ● オブジェクト初期化
  124.   #     x       : ウィンドウの X 座標
  125.   #     y       : ウィンドウの Y 座標
  126.   #     width   : ウィンドウの幅
  127.   #     height  : ウィンドウの高さ
  128.   #--------------------------------------------------------------------------
  129.   alias initialize_KMS_GenericGauge initialize
  130.   def initialize(x, y, width, height)
  131.     initialize_KMS_GenericGauge(x, y, width, height)
  132.  
  133.     @@__gauge_buf = Bitmap.new(320, 24) if @@__gauge_buf.disposed?
  134.   end
  135.   #--------------------------------------------------------------------------
  136.   # ○ ゲージ描画
  137.   #     file       : ゲージ画像ファイル名
  138.   #     x, y       : 描画先 X, Y 座標
  139.   #     width      : 幅
  140.   #     ratio      : 割合
  141.   #     offset     : 座標調整 [x, y]
  142.   #     len_offset : 長さ調整
  143.   #     slope      : 傾き
  144.   #     gauge_type : ゲージタイプ
  145.   #--------------------------------------------------------------------------
  146.   def draw_generic_gauge(file, x, y, width, ratio, offset, len_offset, slope,
  147.                          gauge_type = :normal)
  148.     img    = Cache.system(file)
  149.     x     += offset[0]
  150.     y     += offset[1]
  151.     width += len_offset
  152.     draw_generic_gauge_base(img, x, y, width, slope)
  153.     gw = (width * ratio).to_i
  154.     draw_generic_gauge_bar(img, x, y, width, gw, slope, GAUGE_SRC_POS[gauge_type])
  155.   end
  156.   #--------------------------------------------------------------------------
  157.   # ○ ゲージベース描画
  158.   #     img   : ゲージ画像
  159.   #     x, y  : 描画先 X, Y 座標
  160.   #     width : 幅
  161.   #     slope : 傾き
  162.   #--------------------------------------------------------------------------
  163.   def draw_generic_gauge_base(img, x, y, width, slope)
  164.     rect = Rect.new(0, 0, 24, 24)
  165.     if slope != 0
  166.       contents.skew_blt(x, y, img, rect, slope)
  167.       rect.x = 96
  168.       contents.skew_blt(x + width + 24, y, img, rect, slope)
  169.  
  170.       rect.x     = 24
  171.       rect.width = 72
  172.       dest_rect = Rect.new(0, 0, width, 24)
  173.       @@__gauge_buf.clear
  174.       @@__gauge_buf.stretch_blt(dest_rect, img, rect)
  175.       contents.skew_blt(x + 24, y, @@__gauge_buf, dest_rect, slope)
  176.     else
  177.       contents.blt(x, y, img, rect)
  178.       rect.x = 96
  179.       contents.blt(x + width + 24, y, img, rect)
  180.       rect.x     = 24
  181.       rect.width = 72
  182.       dest_rect = Rect.new(x + 24, y, width, 24)
  183.       contents.stretch_blt(dest_rect, img, rect)
  184.     end
  185.   end
  186.   #--------------------------------------------------------------------------
  187.   # ○ ゲージ内部描画
  188.   #     img     : ゲージ画像
  189.   #     x, y    : 描画先 X, Y 座標
  190.   #     width   : 全体幅
  191.   #     gw      : 内部幅
  192.   #     slope   : 傾き
  193.   #     src_pos : 転送元座標 [x, y]
  194.   #     start   : 開始位置
  195.   #--------------------------------------------------------------------------
  196.   def draw_generic_gauge_bar(img, x, y, width, gw, slope, src_pos, start = 0)
  197.     rect = Rect.new(src_pos[0], src_pos[1], 72, 24)
  198.     dest_rect = Rect.new(0, 0, width, 24)
  199.     @@__gauge_buf.clear
  200.     @@__gauge_buf.stretch_blt(dest_rect, img, rect)
  201.     dest_rect.x     = start
  202.     dest_rect.width = gw
  203.     x += start
  204.     if slope != 0
  205.       contents.skew_blt(x + 24, y, @@__gauge_buf, dest_rect, slope)
  206.     else
  207.       contents.blt(x + 24, y, @@__gauge_buf, dest_rect)
  208.     end
  209.   end
  210.   #--------------------------------------------------------------------------
  211.   # ● HP の描画
  212.   #--------------------------------------------------------------------------
  213.   def draw_actor_hp(actor, x, y, width = 124)
  214.     draw_actor_hp_gauge(actor, x, y, width)
  215.     change_color(system_color)
  216.     draw_text(x, y, 30, line_height, Vocab::hp_a)
  217.     draw_current_and_max_values(x, y, width, actor.hp, actor.mhp,
  218.       hp_color(actor), normal_color)
  219.   end
  220.   #--------------------------------------------------------------------------
  221.   # ● MP の描画
  222.   #--------------------------------------------------------------------------
  223.   def draw_actor_mp(actor, x, y, width = 124)
  224.     draw_actor_mp_gauge(actor, x, y, width)
  225.     change_color(system_color)
  226.     draw_text(x, y, 30, line_height, Vocab::mp_a)
  227.     draw_current_and_max_values(x, y, width, actor.mp, actor.mmp,
  228.       mp_color(actor), normal_color)
  229.   end
  230.   #--------------------------------------------------------------------------
  231.   # ● TP の描画
  232.   #--------------------------------------------------------------------------
  233.   def draw_actor_tp(actor, x, y, width = 124)
  234.     draw_actor_tp_gauge(actor, x, y, width)
  235.     change_color(system_color)
  236.     draw_text(x, y, 30, line_height, Vocab::tp_a)
  237.     change_color(tp_color(actor))
  238.     draw_text(x + width - 42, y, 42, line_height, actor.tp.to_i, 2)
  239.   end
  240.   #--------------------------------------------------------------------------
  241.   # ○ HP ゲージの描画
  242.   #     actor : アクター
  243.   #     x, y  : 描画先 X, Y 座標
  244.   #     width : 幅
  245.   #--------------------------------------------------------------------------
  246.   def draw_actor_hp_gauge(actor, x, y, width = 120)
  247.     draw_generic_gauge(KMS_GenericGauge::HP_IMAGE,
  248.       x, y, width, actor.hp_rate,
  249.       KMS_GenericGauge::HP_OFFSET,
  250.       KMS_GenericGauge::HP_LENGTH,
  251.       KMS_GenericGauge::HP_SLOPE
  252.     )
  253.   end
  254.   #--------------------------------------------------------------------------
  255.   # ○ MP ゲージの描画
  256.   #     actor : アクター
  257.   #     x, y  : 描画先 X, Y 座標
  258.   #     width : 幅
  259.   #--------------------------------------------------------------------------
  260.   def draw_actor_mp_gauge(actor, x, y, width = 120)
  261.     draw_generic_gauge(KMS_GenericGauge::MP_IMAGE,
  262.       x, y, width, actor.mp_rate,
  263.       KMS_GenericGauge::MP_OFFSET,
  264.       KMS_GenericGauge::MP_LENGTH,
  265.       KMS_GenericGauge::MP_SLOPE
  266.     )
  267.   end
  268.   #--------------------------------------------------------------------------
  269.   # ○ TP ゲージの描画
  270.   #     actor : アクター
  271.   #     x, y  : 描画先 X, Y 座標
  272.   #     width : 幅
  273.   #--------------------------------------------------------------------------
  274.   def draw_actor_tp_gauge(actor, x, y, width = 120)
  275.     draw_generic_gauge(KMS_GenericGauge::TP_IMAGE,
  276.       x, y, width, actor.tp_rate,
  277.       KMS_GenericGauge::TP_OFFSET,
  278.       KMS_GenericGauge::TP_LENGTH,
  279.       KMS_GenericGauge::TP_SLOPE
  280.     )
  281.   end
  282.   #--------------------------------------------------------------------------
  283.   # ○ Exp の描画
  284.   #     actor : アクター
  285.   #     x, y  : 描画先 X, Y 座標
  286.   #     width : 幅
  287.   #--------------------------------------------------------------------------
  288.   def draw_actor_exp(actor, x, y, width = 180)
  289.     str = actor.max_level? ? "-------" : actor.exp
  290.     change_color(normal_color)
  291.     draw_text(x, y, width, line_height, str, 2)
  292.   end
  293.   #--------------------------------------------------------------------------
  294.   # ○ NextExp の描画
  295.   #     actor : アクター
  296.   #     x, y  : 描画先 X, Y 座標
  297.   #     width : 幅
  298.   #--------------------------------------------------------------------------
  299.   def draw_actor_next_exp(actor, x, y, width = 180)
  300.     draw_actor_exp_gauge(actor, x, y, width)
  301.  
  302.     str = actor.max_level? ? "-------" : actor.next_level_exp_rest
  303.     change_color(normal_color)
  304.     draw_text(x, y, width, line_height, str, 2)
  305.   end
  306.   #--------------------------------------------------------------------------
  307.   # ○ Exp ゲージの描画
  308.   #     actor : アクター
  309.   #     x, y  : 描画先 X, Y 座標
  310.   #     width : 幅
  311.   #--------------------------------------------------------------------------
  312.   def draw_actor_exp_gauge(actor, x, y, width = 180)
  313.     draw_generic_gauge(KMS_GenericGauge::EXP_IMAGE,
  314.       x, y, width, actor.exp_rate,
  315.       KMS_GenericGauge::EXP_OFFSET,
  316.       KMS_GenericGauge::EXP_LENGTH,
  317.       KMS_GenericGauge::EXP_SLOPE
  318.     )
  319.   end
  320. end
  321.  
  322. #==============================================================================
  323. # ■ Window_Status
  324. #==============================================================================
  325.  
  326. class Window_Status < Window_Selectable
  327.   #--------------------------------------------------------------------------
  328.   # ● 経験値情報の描画
  329.   #--------------------------------------------------------------------------
  330.   def draw_exp_info(x, y)
  331.     s_next = sprintf(Vocab::ExpNext, Vocab::level)
  332.     change_color(system_color)
  333.     draw_text(x, y + line_height * 0, 180, line_height, Vocab::ExpTotal)
  334.     draw_text(x, y + line_height * 2, 180, line_height, s_next)
  335.     change_color(normal_color)
  336.     draw_actor_exp(     @actor, x, y + line_height * 1)
  337.     draw_actor_next_exp(@actor, x, y + line_height * 3)
  338.   end
  339. end