Mithran

Untitled

Jan 15th, 2014
618
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 KB | None | 0 0
  1. # add xparams to equip status window
  2. # example script by Mithran at forums.rpgmakerweb.com
  3. # Terms of Use: use as you see fit (learn, edit, repost, commercial allowed)
  4. module Vocab
  5. XPARAM = # xparam terms
  6. ["HIT", # 0 HIT HIT rate
  7. "EVA", # 1 EVA EVAsion rate
  8. "CRI",# 2 CRI CRItical rate
  9. "CEV", # 3 CEV Critical EVasion rate
  10. "MEV", # 4 MEV Magic EVasion rate
  11. "MRF",# 5 MRF Magic ReFlection rate
  12. "CNT", # 6 CNT CouNTer attack rate
  13. "HRG",# 7 HRG Hp ReGeneration rate
  14. "MRG", # 8 MRG Mp ReGeneration rate
  15. "TRG",# 9 TRG Tp ReGeneration rate
  16. ]
  17. def self.xparam(param_id)
  18. XPARAM[param_id]
  19. end
  20. end
  21.  
  22. class Window_EquipStatus
  23. XPARAM_DISPLAY_MULT = true # if true, multiply xparam as %
  24. FONT_SIZE = 21 # font point size of this window
  25. SKIP_XPARAMS = [7, 8] # skip drawing these xparams
  26. alias initialize_setfont initialize
  27. # making a copy of the origina method so it can be used in the redefinition
  28. def initialize(*args)
  29. initialize_setfont(*args) # calling original method
  30. if FONT_SIZE
  31. contents.font.size = FONT_SIZE # setting custom font size
  32. refresh # redrawing window
  33. end
  34. end
  35.  
  36. alias refresh_drawxparam refresh
  37. def refresh
  38. refresh_drawxparam
  39. off = 0
  40. 10.times {|i| # 10 times, one for each number of xparams
  41. if SKIP_XPARAMS.include?(i) # if this xparam is to be omitted
  42. off += 1 # increase offset variable so there are no gaps in drawing
  43. next # skip drawing and move onto the next one
  44. end
  45. draw_item_ex(0, line_height * (7 + i - off), i) # draw item calls all other draw methods
  46. }
  47. end
  48.  
  49. def draw_item_ex(x, y, param_id)
  50. # calls all seperate draw methods, see below
  51. # this method basically passes the origin of where each item should be drawn
  52. draw_xparam_name(x + 4, y, param_id)
  53. draw_current_xparam(x + 94, y, param_id) if @actor
  54. draw_right_arrow(x + 126, y)
  55. draw_new_xparam(x + 150, y, param_id) if @temp_actor
  56. end
  57.  
  58. def draw_xparam_name(x, y, param_id) # draw the parameter name
  59. change_color(system_color)
  60. draw_text(x, y, 80, line_height, Vocab.xparam(param_id))
  61. end
  62.  
  63. def draw_current_xparam(x, y, param_id) # draw current value of xparam
  64. change_color(normal_color)
  65. text = !XPARAM_DISPLAY_MULT ? sprintf("%0.2f", @actor.xparam(param_id)) : "#{(@actor.xparam(param_id) * 100).to_i}%"
  66. draw_text(x, y, 32, line_height, text, 2)
  67. end
  68.  
  69. def draw_new_xparam(x, y, param_id)
  70. new_value = @temp_actor.xparam(param_id)
  71. change_color(param_change_color(new_value - @actor.xparam(param_id)))
  72. text = !XPARAM_DISPLAY_MULT ? sprintf("%0.2f", new_value) : "#{(new_value * 100).to_i}%"
  73. # above line - get text to be drawn. if using display mult, multiply value
  74. # by 100 and add a percent sign instead of displaying the decimal
  75. # if not, display two decimal values with a leading zero
  76. draw_text(x, y, 32, line_height, text, 2)
  77. end
  78.  
  79. def window_height
  80. 344 # default of Graphics.height minus the help window's height
  81. # calculating this dynamically would require redefining a few other methods
  82. end
  83.  
  84. def line_height
  85. return FONT_SIZE if FONT_SIZE # if font size is set, use it for line height
  86. super # if not set, use the default value
  87. end
  88.  
  89. end
  90.  
  91. class Scene_Equip
  92.  
  93. def create_item_window
  94. # redefining this and using math to put the item window in the correct place
  95. wx = @status_window.width
  96. wy = @slot_window.y + @slot_window.height
  97. ww = Graphics.width - @status_window.width
  98. wh = Graphics.height - wy
  99. @item_window = Window_EquipItemCompact.new(wx, wy, ww, wh)
  100. @item_window.viewport = @viewport
  101. @item_window.help_window = @help_window
  102. @item_window.status_window = @status_window
  103. @item_window.actor = @actor
  104. @item_window.set_handler(:ok, method(:on_item_ok))
  105. @item_window.set_handler(:cancel, method(:on_item_cancel))
  106. @slot_window.item_window = @item_window
  107. end
  108. end
  109.  
  110. class Window_EquipItemCompact < Window_EquipItem
  111. # compact version of the equip item window with one column
  112. def col_max
  113. 1
  114. end
  115. end
Advertisement
Add Comment
Please, Sign In to add comment