pigu_6

VE | Sprite in window

Apr 19th, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.66 KB | None | 0 0
  1. #==============================================================================
  2. # ** Victor Engine - Sprite in Windows
  3. #------------------------------------------------------------------------------
  4. # Author : Victor Sant
  5. #
  6. # Version History:
  7. # v 1.00 - 2012.03.22 > First relase
  8. #------------------------------------------------------------------------------
  9. # This script is an add on for the 'VE - Animated Battle', it's a tool for
  10. # scripters that allows to add a animated sprite of the battler in windows.
  11. # This script alone don't do anything, it needs the scripter to manually
  12. # set the method that adds the animated sprite.
  13. #------------------------------------------------------------------------------
  14. # Compatibility
  15. # Requires the script 'Victor Engine - Basic Module' and
  16. # 'Victor Engine - Animated Battle'
  17. #
  18. # * Alias methods (Default)
  19. # class Window_Base < Window
  20. # def initialize(x, y, width, height)
  21. # def update
  22. # def dispose
  23. #
  24. # class Window_MenuActor < Window_MenuStatus
  25. # def initialize
  26. #
  27. #------------------------------------------------------------------------------
  28. # Instructions:
  29. # To instal the script, open you script editor and paste this script on
  30. # a new section on bellow the Materials section. This script must also
  31. # be bellow all the required scripts.
  32. #
  33. #------------------------------------------------------------------------------
  34. # Additional instructions:
  35. #
  36. # To add the animated sprite, you must add the following method on the window
  37. # script, this isn't recomended for people without any script knowlegde.
  38. # draw_animated_actor(battler, x, y, dir, fade)
  39. # battler : the object with the battler information, it must be a valid
  40. # Game_Actor or Game_Enemy object.
  41. # x : position x of the sprite on the window
  42. # y : position y of the sprite on the window
  43. # dir : string battler face direction: 'left', 'right', 'down' or 'up'
  44. # can be omited or nil, in that case the battler will face left.
  45. # fade : fade effect when the battlers are shown, can be omited
  46. # if true there will be an fade effect when showing the battlers.
  47. #
  48. #==============================================================================
  49.  
  50. #==============================================================================
  51. # ** Victor Engine
  52. #------------------------------------------------------------------------------
  53. # Setting module for the Victor Engine
  54. #==============================================================================
  55.  
  56. module Victor_Engine
  57. #--------------------------------------------------------------------------
  58. # * required
  59. # This method checks for the existance of the basic module and other
  60. # VE scripts required for this script to work, don't edit this
  61. #--------------------------------------------------------------------------
  62. def self.required(name, req, version, type = nil)
  63. if !$imported[:ve_basic_module]
  64. msg = "The script '%s' requires the script\n"
  65. msg += "'VE - Basic Module' v%s or higher above it to work properly\n"
  66. msg += "Go to http://victorscripts.wordpress.com/ to download this script."
  67. msgbox(sprintf(msg, self.script_name(name), version))
  68. exit
  69. else
  70. self.required_script(name, req, version, type)
  71. end
  72. end
  73. #--------------------------------------------------------------------------
  74. # * script_name
  75. # Get the script name base on the imported value
  76. #--------------------------------------------------------------------------
  77. def self.script_name(name, ext = "VE")
  78. name = name.to_s.gsub("_", " ").upcase.split
  79. name.collect! {|char| char == ext ? "#{char} -" : char.capitalize }
  80. name.join(" ")
  81. end
  82. end
  83.  
  84. $imported ||= {}
  85. $imported[:ve_sprite_in_window] = 1.00
  86. Victor_Engine.required(:ve_sprite_in_window, :ve_basic_module, 1.00, :above)
  87. Victor_Engine.required(:ve_sprite_in_window, :ve_animated_battle, 1.00, :above)
  88.  
  89. #==============================================================================
  90. # ** Window_Base
  91. #------------------------------------------------------------------------------
  92. # This is a superclass of all windows in the game.
  93. #==============================================================================
  94.  
  95. class Window_Base < Window
  96. #--------------------------------------------------------------------------
  97. # * Alias method: initialize
  98. #--------------------------------------------------------------------------
  99. alias :initialize_ve_sprite_in_window :initialize
  100. def initialize(x, y, width, height)
  101. initialize_ve_sprite_in_window(x, y, width, height)
  102. @animate_battlers = {}
  103. end
  104. #--------------------------------------------------------------------------
  105. # * Alias method: update
  106. #--------------------------------------------------------------------------
  107. alias :update_ve_sprite_in_window :update
  108. def update
  109. update_ve_sprite_in_window
  110. @animate_battlers.values.each {|sprite| update_sprite(sprite) if sprite }
  111. end
  112. #--------------------------------------------------------------------------
  113. # * Alias method: dispose
  114. #--------------------------------------------------------------------------
  115. alias :dispose_ve_sprite_in_window :dispose
  116. def dispose
  117. dispose_ve_sprite_in_window
  118. @animate_battlers.values.each {|sprite| sprite.dispose if sprite }
  119. end
  120. #--------------------------------------------------------------------------
  121. # * New method: draw_animated_actor
  122. #--------------------------------------------------------------------------
  123. def draw_animated_actor(battler, x, y, dir = 'left', fade = false)
  124. sprite = @animate_battlers[[battler.id, battler.actor?]]
  125. sprite.dispose if sprite && !shared_bimap(sprite)
  126. if !sprite || sprite.bitmap.disposed?
  127. viewport = Viewport.new(0, 0, width - 32, height - 32)
  128. viewport.z = self.z
  129. sprite = Sprite_Animated_Battler.new(viewport, battler, dir, fade)
  130. @animate_battlers[[battler.id, battler.actor?]] = sprite
  131. end
  132. sprite.setup_position(x, y)
  133. update_sprite(sprite)
  134. end
  135. #--------------------------------------------------------------------------
  136. # * New method: update_sprite
  137. #--------------------------------------------------------------------------
  138. def update_sprite(sprite)
  139. sprite.update
  140. sprite.sprite_position(self.ox, self.oy)
  141. sprite.visible = self.visible
  142. sprite.viewport.rect.x = self.x + 16
  143. sprite.viewport.rect.y = self.y + 16
  144. end
  145. #--------------------------------------------------------------------------
  146. # * New method: shared_bimap
  147. #--------------------------------------------------------------------------
  148. def shared_bimap(battler)
  149. list = @animate_battlers.values - [battler]
  150. list.any? {|sprite| battler.bitmap == sprite.bitmap }
  151. end
  152. end
  153.  
  154. #==============================================================================
  155. # ** Window_MenuActor
  156. #------------------------------------------------------------------------------
  157. # This window is for selecting actors that will be the target of item or
  158. # skill use.
  159. #==============================================================================
  160.  
  161. class Window_MenuActor < Window_MenuStatus
  162. #--------------------------------------------------------------------------
  163. # * Alias method: initialize
  164. #--------------------------------------------------------------------------
  165. alias :initialize_ve_sprite_in_window_menuactor :initialize
  166. def initialize
  167. initialize_ve_sprite_in_window_menuactor
  168. refresh
  169. end
  170. end
  171.  
  172. #==============================================================================
  173. # ** Sprite_Animated_Battler
  174. #------------------------------------------------------------------------------
  175. # This sprite is used to display battlers on windows
  176. #==============================================================================
  177.  
  178. class Sprite_Animated_Battler < Sprite_Battler
  179. #--------------------------------------------------------------------------
  180. # * Initialize
  181. #--------------------------------------------------------------------------
  182. def initialize(viewport, battler, dir, fade)
  183. @fade = fade
  184. super(viewport, battler)
  185. @battler.direction = setup_direction(dir)
  186. update
  187. end
  188. #--------------------------------------------------------------------------
  189. # * init_variables
  190. #--------------------------------------------------------------------------
  191. def init_variables
  192. @frame = 0
  193. @sufix = ""
  194. @pose_sufix = ""
  195. @anim_sufix = VE_SPRITE_SUFIX
  196. @pose_count = 0
  197. @frame_width = 0
  198. @frame_height = 0
  199. @pose_value = {}
  200. @icon_list = {}
  201. @throw_list = []
  202. if @fade
  203. start_effect(:appear)
  204. else
  205. self.opacity = 255
  206. @battler_visible = true
  207. end
  208. @battler.clear_poses
  209. setup_positions
  210. end
  211. #--------------------------------------------------------------------------
  212. # * setup_position
  213. #--------------------------------------------------------------------------
  214. def setup_position(x, y)
  215. @x = x + 32
  216. @y = y + 64
  217. end
  218. #--------------------------------------------------------------------------
  219. # * sprite_position
  220. #--------------------------------------------------------------------------
  221. def sprite_position(ox, oy)
  222. self.x = @x + adjust_x - ox
  223. self.y = @y + adjust_y - oy
  224. end
  225. #--------------------------------------------------------------------------
  226. # * update_position
  227. #--------------------------------------------------------------------------
  228. def setup_direction(dir)
  229. case dir.downcase
  230. when 'down' then 2
  231. when 'left' then 4
  232. when 'right' then 6
  233. when 'up' then 8
  234. else 4
  235. end
  236. end
Advertisement
Add Comment
Please, Sign In to add comment