TheoAllen

TSBS Battlecam Backup

Oct 7th, 2014
446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 28.62 KB | None | 0 0
  1. #==============================================================================
  2. # TSBS Addon - Battle Camera
  3. # Version : 1.0.1
  4. # Language : English
  5. # Requires : Theolized SBS version 1.4
  6. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7. # Contact :
  8. #------------------------------------------------------------------------------
  9. # *> http://www.rpgmakerid.com
  10. # *> http://www.rpgmakervxace.net
  11. # *> http://theolized.blogspot.com
  12. #==============================================================================
  13. ($imported ||= {})[:TSBS_Camera] = true
  14. #==============================================================================
  15. # Change Logs:
  16. # -----------------------------------------------------------------------------
  17. # 2014.10.05 - Added sprite rewriter for later compatibility patch
  18. #            - Compatibility patch with YES Damage Popup
  19. # 2014.09.25 - Finished final version 1.0
  20. # 2014.08.28 - Finished initial version 0.8
  21. #==============================================================================
  22. %Q{
  23.  
  24.   ===================
  25.   || Introduction ||
  26.   -------------------
  27.   This script adds battle camera effect where you could move the camera focus
  28.   or even zoom the battle screen.
  29.  
  30.   =================
  31.   || How to use ||
  32.   -----------------
  33.   Put this script below TSBS implementation part.
  34.   To call the camera effect, select one of these command format.
  35.  
  36.   1st Format --> [:camera, scope, [x, y], dur, zoom, (method)],
  37.   2nd Format --> [:camera, "Camera Key"],
  38.  
  39.   Note if you use the first format :
  40.   > Scope   : Scope position where camera should focus. There're 5 avalaible
  41.              options can be used. They're
  42.               [0: Target] [1: Self] [2: All Enemies] [3: All Allies]
  43.               [4: Everyone] [5: Screen]
  44.              
  45.   > [x, y]  : Relative position from the scope
  46.   > dur     : Camera move duration in frame
  47.   > zoom    : Camera zoom value. Should filled by float. e.g, 1.0 or 1.5
  48.   > method  : Movement method. Choose between :linear, :smooth
  49.  
  50.   Example :
  51.   [:camera, 0, [0, 0], 56, 1.15],
  52.   [:camera, 0, [0, 0], 56, 1.15, :smooth],
  53.  
  54.   Note if you use the second format :
  55.   "Camera Key" is similar as action key. It stored in CAM_PRESETUP in
  56.   configuration part below.
  57.  
  58.   To reset the position of camera, call this command
  59.   Format --> [:cam_reset, dur, (method)],
  60.  
  61.   ===================
  62.   || Terms of use ||
  63.   -------------------
  64.   Credit me, TheoAllen. You are free to edit this script by your own. As long
  65.   as you don't claim it yours. For commercial purpose, don't forget to give me
  66.   a free copy of the game.
  67.  
  68.   =====================
  69.   || Special Thanks ||
  70.   ---------------------
  71.   - Galenmereth / Tor Damian Design for easing movement algorithm
  72.   - Journey Battle System / Tankentai VXA as inspiration
  73.   - Anyone who requested this feature
  74.  
  75. }
  76. #==============================================================================
  77. # Editable region
  78. #==============================================================================
  79. module TSBS # <-- Do not touch
  80.  #============================================================================
  81.   DEFAULT_CAM_METHOD = :smooth
  82.  #----------------------------------------------------------------------------
  83.  # Default camera movement method. There're two avalaible movement methods.
  84.  # Choose between them
  85.  # > :linear
  86.  # > :smooth
  87.  #
  88.  # For constant movement, choose :linear
  89.  # For smoother movement, choose :smooth
  90.  #============================================================================
  91.  # Camera pre setup. Made for easier call
  92.  #----------------------------------------------------------------------------
  93.   CAM_PRESETUP = {
  94. # "Camera Key"  => [scope,[x, y], dur, zoom, (method)]
  95.   "Everyone"    => [4    ,[0, 0],  56,  1.0],
  96.   "Screen"      => [5    ,[0, 0],  56,  1.0],
  97.  
  98.   "Target"      => [0, [100, -50], 75, 1.00],
  99.   "Actor"       => [1, [100, -50], 55, 1.00],
  100.  
  101.   "Actors"      => [3, [-100, 0], 55, 1.00],
  102.   "Actors2"     => [5, [50, 20], 55, 1.00],
  103.   "Enemies"     => [2, [100, 0], 55, 1.00],
  104.   "Enemies2"    => [5, [-50, 20], 55, 1.00],
  105.  
  106.   } # <-- don't touch
  107.  #============================================================================
  108.  # Camera focus change when selecting certain command
  109.  # Set all to nil if you don't want to use these
  110.  #----------------------------------------------------------------------------
  111.   CAMERA_ACTOR_COMMAND  = "Actors2"   # When selecting actor command
  112.   CAMERA_ENEMY_SELECT   = "Enemies2"  # When selecting enemy
  113.   CAMERA_TURN_START     = "Screen"    # When turn start
  114.  #============================================================================
  115.  # Some bugfixes
  116.  #----------------------------------------------------------------------------
  117.   CAMERA_YEA_POPUP_FIX  = true  # If you using YEA/YES Damage Popup
  118.   CAMERA_ANIMATION_ZOOM = true  # Is animation also need to be scalled?
  119.  #============================================================================
  120.  # Camera command call. Used to call camera function like [:camera, ...]
  121.  #----------------------------------------------------------------------------
  122.   CAMERA_MOVE     = :camera
  123.   CAMERA_RESET    = :cam_reset
  124.  #=============================================================================
  125. end # <-- Do not touch
  126. #==============================================================================
  127. # * End of editable region
  128. #------------------------------------------------------------------------------
  129. # Below this line may dangerous to enter. There're many monster inside. Do not
  130. # enter unless you're pretty confident or have sufficient skills.
  131. #==============================================================================
  132. if $imported[:TSBS] # Compatibility flag
  133. #==============================================================================
  134. module TSBS
  135. #==============================================================================
  136. # ** TSBS::Camera
  137. #------------------------------------------------------------------------------
  138. #  This class handles camera metadata
  139. #==============================================================================
  140.   class Camera
  141.     attr_accessor :zoom
  142.     attr_accessor :x
  143.     attr_accessor :y
  144.     #--------------------------------------------------------------------------
  145.     # * Initialize
  146.     #--------------------------------------------------------------------------
  147.     def initialize
  148.       reset_camera
  149.       clear_movement_flag
  150.     end
  151.     #--------------------------------------------------------------------------
  152.     # * Reset camera metadata
  153.     #--------------------------------------------------------------------------
  154.     def reset_camera
  155.       @zoom = 1.0
  156.       @x = 0.0
  157.       @y = 0.0
  158.       @shake_v = 0.0
  159.       @shake_h = 0.0
  160.       @shake_count_v = 0.0
  161.       @shake_count_h = 0.0
  162.     end
  163.     #--------------------------------------------------------------------------
  164.     # * Clear movement flag
  165.     #--------------------------------------------------------------------------
  166.     def clear_movement_flag
  167.       @fiber = nil
  168.       @total_dur = 0
  169.       @duration = 0
  170.       @ori_x = 0.0
  171.       @ori_y = 0.0
  172.       @ori_zoom = 0.0
  173.       @target_x = 0.0
  174.       @target_y = 0.0
  175.       @target_zoom = 0.0
  176.     end
  177.     #--------------------------------------------------------------------------
  178.     # * Interpret camera key
  179.     #--------------------------------------------------------------------------
  180.     def interpret_camera(key)
  181.       return if key.nil?
  182.       camera = CAM_PRESETUP[key]
  183.       if camera.nil?
  184.         ErrorSound.play
  185.         text = "Camera error on : #{@used_sequence}\n" +
  186.         "Uninitialized camera constant \"#{@acts[1]}\""
  187.         msgbox text
  188.         exit
  189.       end
  190.       case camera[0]
  191.       when 2 # All Enemies
  192.         battlers = $game_troop.alive_members
  193.       when 3 # All Allies
  194.         battlers = $game_party.alive_members
  195.       when 4 # Everyone
  196.         battlers = $game_troop.alive_members + $game_party.alive_members
  197.       else # Screen
  198.         battlers = nil
  199.       end
  200.       unless camera[1].is_a?(Array)
  201.         ErrorSound.play
  202.         msgbox "Camera error on : #{@used_sequence}\n" +
  203.         "Second parameter should be array"
  204.         exit
  205.       end
  206.       point_x = camera[1][0]
  207.       point_y = camera[1][1]
  208.       dur = camera[2]
  209.       zoom = camera[3]
  210.       method = camera[4] || DEFAULT_CAM_METHOD
  211.       unless respond_to?(method)
  212.         ErrorSound.play
  213.         msgbox "Camera error on : #{@used_sequence}\nWrong method name"
  214.         exit
  215.       end
  216.       move_camera(battlers, point_x, point_y, dur, zoom, method)
  217.     end
  218.     #--------------------------------------------------------------------------
  219.     # * Move camera
  220.     #--------------------------------------------------------------------------
  221.     def move_camera(battlers, x, y, dur, zoom, method)
  222.       clear_movement_flag
  223.       @duration = dur
  224.       if battlers
  225.         size = battlers.size
  226.         point_x = battlers.inject(0) {|r, battler| r + battler.rel_x}.to_f/size
  227.         point_y = battlers.inject(0) {|r, battler| r + battler.rel_y}.to_f/size
  228.       else
  229.         point_x = 0
  230.         point_y = 0
  231.       end
  232.       @ori_x = @x
  233.       @ori_y = @y
  234.       @ori_zoom = @zoom
  235.       @target_x = (point_x + x).to_f
  236.       @target_y = (point_y + y).to_f
  237.       @target_zoom = zoom
  238.       @fiber = Fiber.new { update_camera(method) }
  239.     end
  240.     #--------------------------------------------------------------------------
  241.     # * The distance position of X axis
  242.     #--------------------------------------------------------------------------
  243.     def dist_x(x)
  244.       dist = Graphics.width/2 - x
  245.       return (@x * @zoom) + (dist * (@zoom - 1.0)) + @shake_h
  246.     end
  247.     #--------------------------------------------------------------------------
  248.     # * The distance position of Y axis
  249.     #--------------------------------------------------------------------------
  250.     def dist_y(y)
  251.       dist = Graphics.height/2 - y
  252.       return (@y * @zoom) + (dist * (@zoom - 1.0)) + @shake_v
  253.     end
  254.     #--------------------------------------------------------------------------
  255.     # * Update. Called once per frame
  256.     #--------------------------------------------------------------------------
  257.     def update
  258.       @fiber.resume if @fiber
  259.       return unless $imported[:TSBS_BattleCosmetic]
  260.       horz = backdrop_settings[:shake_h]
  261.       vert = backdrop_settings[:shake_v]
  262.       @shake_count_h = (@shake_count_h + horz[0]) % 360
  263.       @shake_count_v = (@shake_count_v + vert[0]) % 360
  264.       @shake_h = Math.cos(Math.radian(@shake_count_h)) * vert[1]
  265.       @shake_v = Math.cos(Math.radian(@shake_count_v)) * vert[1]
  266.     end
  267.     #--------------------------------------------------------------------------
  268.     # * Camera is moving?
  269.     #--------------------------------------------------------------------------
  270.     def moving?
  271.       !@fiber.nil?
  272.     end
  273.     #--------------------------------------------------------------------------
  274.     # * Update camera movement
  275.     #--------------------------------------------------------------------------
  276.     def update_camera(method_name)
  277.       @duration.times do |t|
  278.         @x = send(method_name, t, @ori_x, @target_x - @ori_x, @duration).round
  279.         @y = send(method_name, t, @ori_y, @target_y - @ori_y, @duration).round
  280.         @zoom = send(method_name, t, @ori_zoom, @target_zoom - @ori_zoom,
  281.           @duration)
  282.         Fiber.yield
  283.       end
  284.       @x = @target_x
  285.       @y = @target_y
  286.       @zoom = @target_zoom
  287.       clear_movement_flag
  288.     end
  289.     # -------------------------------------------------------------------------
  290.     # * Easing movement method : Linear
  291.     # -------------------------------------------------------------------------
  292.     def linear(time, start, change, total_time)
  293.       return change * time / total_time + start
  294.     end
  295.     # -------------------------------------------------------------------------
  296.     # * Easing movement method : Smooth
  297.     # -------------------------------------------------------------------------
  298.     def smooth(time, start, change, total_time)
  299.       time /= total_time.to_f
  300.       time -= 1
  301.       return change*(time*time*time + 1) + start
  302.     end
  303.   end
  304. #==============================================================================
  305. # ** Screen_Point
  306. #------------------------------------------------------------------------------
  307. #  This class created to supports camera reposition
  308. #==============================================================================
  309.   class Screen_Point
  310.     alias tsbs_cam_screen_x screen_x
  311.     alias tsbs_cam_screen_y screen_y
  312.     def screen_x
  313.       tsbs_cam_screen_x - $tsbs_camera.dist_x(self.x)
  314.     end
  315.    
  316.     def screen_y
  317.       tsbs_cam_screen_y - $tsbs_camera.dist_y(self.y)
  318.     end
  319.   end
  320. end
  321.  
  322. #==============================================================================
  323. # ** TSBS Sprite Rewriter
  324. #------------------------------------------------------------------------------
  325. #  Rewriter module for sprite to change how X,Y are handled in sprite in order
  326. # to work with battle camera. To use this module, include this module to any
  327. # sprite subclass and initialize the Screen_Point at initialize method. Don't
  328. # forget to make alias for tsbs_x= and tsbs_y=
  329. #
  330. #  Use this module to provide more compatibility patches among various scripts
  331. # See the examples at the end of this script
  332. #==============================================================================
  333.  
  334. def point_rewrite
  335.   alias_method "tsbs_x=", "x="
  336.   alias_method "tsbs_y=", "y="
  337. end
  338.  
  339. module TSBS_SpriteRewriter
  340.   #----------------------------------------------------------------------------
  341.   # * X=
  342.   #----------------------------------------------------------------------------
  343.   def x=(x)
  344.     return if disposed?
  345.     @screen_point.x = x
  346.     self.tsbs_x = @screen_point.screen_x
  347.   end
  348.   #----------------------------------------------------------------------------
  349.   # * Y=
  350.   #----------------------------------------------------------------------------
  351.   def y=(y)
  352.     return if disposed?
  353.     @screen_point.y = y
  354.     self.tsbs_y = @screen_point.screen_y
  355.   end
  356.   #----------------------------------------------------------------------------
  357.   # * Overwrite method : Basic X,Y
  358.   #----------------------------------------------------------------------------
  359.   def x; @screen_point.x; end
  360.   def y; @screen_point.y; end
  361. end
  362.  
  363. #==============================================================================
  364. # ** DataManager
  365. #------------------------------------------------------------------------------
  366. #  This module manages the database and game objects. Almost all of the
  367. # global variables used by the game are initialized by this module.
  368. #==============================================================================
  369.  
  370. class << DataManager
  371.   # --------------------------------------------------------------------------
  372.   # Alias method : Create game objects
  373.   # --------------------------------------------------------------------------  
  374.   alias tsbs_cam_create_obj create_game_objects
  375.   def create_game_objects
  376.     tsbs_cam_create_obj
  377.     $tsbs_camera = TSBS::Camera.new
  378.   end
  379.  
  380. end
  381.  
  382. #==============================================================================
  383. # ** Game_Backdrop
  384. #------------------------------------------------------------------------------
  385. #  This class handles battleback metadata to simulate battleback replacement.
  386. # Instance of this class included within the Game_Temp class
  387. #==============================================================================
  388.  
  389. class Game_Backdrop
  390.  
  391.   alias tsbs_cam_zoom_1 zoom_1
  392.   alias tsbs_cam_zoom_2 zoom_2
  393.  
  394.   def zoom_1
  395.     tsbs_cam_zoom_1 * $tsbs_camera.zoom
  396.   end
  397.  
  398.   def zoom_2
  399.     tsbs_cam_zoom_2 * $tsbs_camera.zoom
  400.   end
  401.  
  402. end
  403.  
  404. #==============================================================================
  405. # ** Game_Battler
  406. #------------------------------------------------------------------------------
  407. #  A battler class with methods for sprites and actions added. This class
  408. # is used as a super class of the Game_Actor class and Game_Enemy class.
  409. #==============================================================================
  410.  
  411. class Game_Battler
  412.   # --------------------------------------------------------------------------
  413.   # Alias method : Custom sequence handler
  414.   # --------------------------------------------------------------------------
  415.   alias tsbs_cam_custom_sequence custom_sequence_handler
  416.   def custom_sequence_handler
  417.     tsbs_cam_custom_sequence
  418.     case @acts[0]
  419.     when CAMERA_MOVE;   setup_camera_move
  420.     when CAMERA_RESET;  setup_camera_reset
  421.     end
  422.   end
  423.   # --------------------------------------------------------------------------
  424.   # New method : Setup camera move
  425.   # --------------------------------------------------------------------------
  426.   def setup_camera_move
  427.     if @acts[1].is_a?(String)
  428.       camera = CAM_PRESETUP[@acts[1]]
  429.       if camera.nil?
  430.         ErrorSound.play
  431.         text = "Camera error on : #{@used_sequence}\n" +
  432.         "Uninitialized camera constant \"#{@acts[1]}\""
  433.         msgbox text
  434.         exit
  435.       end
  436.       @acts = [@acts[0]] + camera
  437.     end
  438.     return TSBS.error(@acts[0], 4, @used_sequence) if @acts.size < 5
  439.     case @acts[1]
  440.     when 0 # Current target
  441.       battlers = target_array
  442.     when 1 # Self
  443.       battlers = [self]
  444.     when 2 # All Enemies
  445.       battlers = opponents_unit.alive_members
  446.     when 3 # All Allies
  447.       battlers = friends_unit.alive_members
  448.     when 4 # Everyone
  449.       battlers = opponents_unit.alive_members + friends_unit.alive_members
  450.     else # Screen
  451.       battlers = nil
  452.     end
  453.     unless @acts[2].is_a?(Array)
  454.       ErrorSound.play
  455.       msgbox "Camera error on : #{@used_sequence}\n" +
  456.       "Second parameter should be array"
  457.       exit
  458.     end
  459.     point_x = @acts[2][0]
  460.     point_y = @acts[2][1]
  461.     dur = @acts[3]
  462.     zoom = @acts[4]
  463.     method = @acts[5] || DEFAULT_CAM_METHOD
  464.     unless $tsbs_camera.respond_to?(method)
  465.       ErrorSound.play
  466.       msgbox "Camera error on : #{@used_sequence}\nWrong method name"
  467.       exit
  468.     end
  469.     $tsbs_camera.move_camera(battlers, point_x, point_y, dur, zoom, method)
  470.   end
  471.   # --------------------------------------------------------------------------
  472.   # New method : Setup camera reset
  473.   # --------------------------------------------------------------------------
  474.   def setup_camera_reset
  475.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  476.     $tsbs_camera.move_camera(nil, 0, 0, @acts[1], 1.0, @acts[2] ||
  477.       DEFAULT_CAM_METHOD)
  478.   end
  479.    
  480. end
  481.  
  482. #==============================================================================
  483. # ** Game_Actor
  484. #------------------------------------------------------------------------------
  485. #  This class handles actors. It is used within the Game_Actors class
  486. # ($game_actors) and is also referenced from the Game_Party class ($game_party)
  487. #==============================================================================
  488.  
  489. class Game_Actor
  490.   alias tsbs_cam_screen_x screen_x
  491.   alias tsbs_cam_screen_y screen_y
  492.   # --------------------------------------------------------------------------
  493.   # Alias method : Screen X
  494.   # --------------------------------------------------------------------------
  495.   def screen_x
  496.     tsbs_cam_screen_x - $tsbs_camera.dist_x(self.x)
  497.   end
  498.   # --------------------------------------------------------------------------
  499.   # Alias method : Screen Y
  500.   # --------------------------------------------------------------------------
  501.   def screen_y
  502.     tsbs_cam_screen_y - $tsbs_camera.dist_y(self.y)
  503.   end
  504.  
  505. end
  506.  
  507. #==============================================================================
  508. # ** Game_Enemy
  509. #------------------------------------------------------------------------------
  510. #  This class handles enemies. It used within the Game_Troop class
  511. # ($game_troop).
  512. #==============================================================================
  513.  
  514. class Game_Enemy
  515.   alias tsbs_cam_screen_x screen_x
  516.   alias tsbs_cam_screen_y screen_y
  517.   # --------------------------------------------------------------------------
  518.   # Alias method : Screen X
  519.   # --------------------------------------------------------------------------
  520.   def screen_x
  521.     tsbs_cam_screen_x - $tsbs_camera.dist_x(self.x)
  522.   end
  523.   # --------------------------------------------------------------------------
  524.   # Alias method : Screen Y
  525.   # --------------------------------------------------------------------------
  526.   def screen_y
  527.     tsbs_cam_screen_y - $tsbs_camera.dist_y(self.y)
  528.   end
  529.  
  530. end
  531.  
  532. #==============================================================================
  533. # ** Sprite_BattlerIcon
  534. #------------------------------------------------------------------------------
  535. #  This sprite is used to display battler's Icon. It observes icon key from
  536. # Game_Battler class and automatically changes sprite display when triggered.
  537. #==============================================================================
  538.  
  539. class Sprite_BattlerIcon
  540.   # --------------------------------------------------------------------------
  541.   # Alias method : Update
  542.   # --------------------------------------------------------------------------
  543.   alias tsbs_cam_update update
  544.   def update
  545.     tsbs_cam_update
  546.     self.zoom_x = self.zoom_y = $tsbs_camera.zoom
  547.   end
  548.  
  549. end
  550.  
  551. #==============================================================================
  552. # ** Sprite_Battler
  553. #------------------------------------------------------------------------------
  554. #  This sprite is used to display battlers. It observes an instance of the
  555. # Game_Battler class and automatically changes sprite states.
  556. #==============================================================================
  557.  
  558. class Sprite_Battler
  559.   # --------------------------------------------------------------------------
  560.   # Alias method : Update
  561.   # --------------------------------------------------------------------------
  562.   alias tsbs_cam_update_pos update_position
  563.   def update_position
  564.     self.zoom_x = self.zoom_y = $tsbs_camera.zoom
  565.     tsbs_cam_update_pos
  566.   end
  567.  
  568. end
  569.  
  570. #==============================================================================
  571. # ** Scene_Battle
  572. #------------------------------------------------------------------------------
  573. #  This class performs battle screen processing.
  574. #==============================================================================
  575.  
  576. class Scene_Battle
  577.   # --------------------------------------------------------------------------
  578.   # Alias method : Update basic
  579.   # --------------------------------------------------------------------------
  580.   alias tsbs_cam_update_basic update_basic
  581.   def update_basic
  582.     tsbs_cam_update_basic
  583.     $tsbs_camera.update
  584.   end
  585.  
  586.   alias tsbs_cam_start_actor_cmd start_actor_command_selection
  587.   def start_actor_command_selection
  588.     tsbs_cam_start_actor_cmd
  589.     $tsbs_camera.interpret_camera(TSBS::CAMERA_ACTOR_COMMAND)
  590.   end
  591.  
  592.   alias tsbs_cam_enemy_select select_enemy_selection
  593.   def select_enemy_selection
  594.     tsbs_cam_enemy_select
  595.     $tsbs_camera.interpret_camera(TSBS::CAMERA_ENEMY_SELECT)
  596.   end
  597.  
  598.   alias tsbs_cam_on_enemy_cancel on_enemy_cancel
  599.   def on_enemy_cancel
  600.     tsbs_cam_on_enemy_cancel
  601.     $tsbs_camera.interpret_camera(TSBS::CAMERA_ACTOR_COMMAND)
  602.   end
  603.  
  604.   alias tsbs_cam_turn_start turn_start
  605.   def turn_start
  606.     tsbs_cam_turn_start
  607.     $tsbs_camera.interpret_camera(TSBS::CAMERA_TURN_START)
  608.     update_basic while $tsbs_camera.moving?
  609.   end
  610.  
  611.   alias tsbs_cam_terminate terminate
  612.   def terminate
  613.     tsbs_cam_terminate
  614.     $tsbs_camera.reset_camera
  615.   end
  616.  
  617. end
  618.  
  619. #==============================================================================#
  620. #                 BELOW THIS LINE ARE COMPATIBILITY PATCHES!                   #
  621. #==============================================================================#
  622.  
  623. #==============================================================================
  624. # ** YEA Battle Engine Popup fix
  625. #------------------------------------------------------------------------------
  626. #  Just glitch fix for YEA damage popup for anyone who bothered. Overwrite
  627. # some methods from YEA Battle Engine
  628. #==============================================================================
  629.  
  630. if $imported["YEA-BattleEngine"] && TSBS::CAMERA_YEA_POPUP_FIX
  631. #==============================================================================
  632. if !$imported["YES-BattlePopup"]
  633. class Sprite_Battler
  634.   def create_new_popup(value, rules, flags)
  635.     return if @battler == nil
  636.     return if flags & @popup_flags != []
  637.     array = YEA::BATTLE::POPUP_RULES[rules]
  638.     for popup in @popups
  639.       popup.screen_point.y -= 24
  640.     end
  641.     return unless SceneManager.scene.is_a?(Scene_Battle)
  642.     return if SceneManager.scene.spriteset.nil?
  643.     view = SceneManager.scene.spriteset.viewportPopups
  644.     new_popup = Sprite_Popup.new(view, @battler, value, rules, flags)
  645.     @popups.push(new_popup)
  646.     @popup_flags.push("weakness") if flags.include?("weakness")
  647.     @popup_flags.push("resistant") if flags.include?("resistant")
  648.     @popup_flags.push("immune") if flags.include?("immune")
  649.     @popup_flags.push("absorbed") if flags.include?("absorbed")
  650.   end
  651. end # Sprite Battler
  652.  
  653. class Sprite_Popup < Sprite_Base
  654.   #----------------------------------------------------------------------------
  655.   # * Alias method : Basic x= y=
  656.   #----------------------------------------------------------------------------
  657.   point_rewrite
  658.   include TSBS_SpriteRewriter
  659.   #--------------------------------------------------------------------------
  660.   # initialize
  661.   #--------------------------------------------------------------------------
  662.   alias tsbs_cam_init initialize
  663.   def initialize(viewport, battler, value, rules, flags)
  664.     @screen_point = TSBS::Screen_Point.new
  665.     tsbs_cam_init(viewport, battler, value, rules, flags)
  666.   end
  667.  
  668.   def create_popup_bitmap
  669.     rules_array = YEA::BATTLE::POPUP_RULES[@rules]
  670.     bw = Graphics.width
  671.     bw += 48 if @flags.include?("state")
  672.     bh = Font.default_size * 3
  673.     bitmap = Bitmap.new(bw, bh)
  674.     bitmap.font.name = rules_array[8]
  675.     size = @flags.include?("critical") ? rules_array[2] * 1.2 : rules_array[2]
  676.     bitmap.font.size = size
  677.     bitmap.font.bold = rules_array[3]
  678.     bitmap.font.italic = rules_array[4]
  679.     if flags.include?("critical")
  680.       crit = YEA::BATTLE::POPUP_RULES["CRITICAL"]
  681.       bitmap.font.out_color.set(crit[5], crit[6], crit[7], 255)
  682.     else
  683.       bitmap.font.out_color.set(0, 0, 0, 255)
  684.     end
  685.     dx = 0; dy = 0; dw = 0
  686.     dx += 24 if @flags.include?("state")
  687.     dw += 24 if @flags.include?("state")
  688.     if @flags.include?("state") || @flags.include?("buff")
  689.       c_width = bitmap.text_size(@value).width
  690.       icon_bitmap = $game_temp.iconset
  691.       icon_index = flag_state_icon
  692.       rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  693.       bitmap.blt(dx+(bw-c_width)/2-36, (bh - 24)/2, icon_bitmap, rect, 255)
  694.     end
  695.     bitmap.font.color.set(rules_array[5], rules_array[6], rules_array[7])
  696.     bitmap.draw_text(dx, dy, bw-dw, bh, @value, 1)
  697.     self.bitmap = bitmap
  698.     self.x = @battler.x # Rewriting this
  699.     self.x += rand(4) - rand(4) if @battler.sprite.popups.size >= 1
  700.     self.x -= SceneManager.scene.spriteset.viewport1.ox
  701.     self.y = @battler.x - @battler.sprite.oy/2 # Rewriting this
  702.     self.y -= @battler.sprite.oy/2 if @battler.actor?
  703.     self.y -= SceneManager.scene.spriteset.viewport1.oy
  704.     self.y += YEA::BATTLE::POPUP_SETTINGS[:offset]
  705.     self.ox = bw/2; self.oy = bh/2
  706.     self.zoom_x = self.zoom_y = rules_array[0]
  707.     if @flags.include?("no zoom")
  708.       self.zoom_x = self.zoom_y = rules_array[1]
  709.     end
  710.     @target_zoom = rules_array[1]
  711.     @zoom_direction = (self.zoom_x > @target_zoom) ? "down" : "up"
  712.     self.z = 500
  713.   end
  714.  
  715.  
  716. end # Sprite_Popup
  717.  
  718. end # !$imported["YES-BattlePopup"]
  719.  
  720. end # $imported["YEA-BattleEngine"] && TSBS::CAMERA_YEA_POPUP_FIX
  721. #==============================================================================  
  722. if $imported["YES-BattlePopup"]
  723.  
  724. class Sprite_PopupLuna < Sprite
  725.   point_rewrite
  726.   include TSBS_SpriteRewriter
  727.  
  728.   alias tsbs_init_luna initialize
  729.   def initialize(*args)
  730.     @screen_point = TSBS::Screen_Point.new
  731.     tsbs_init_luna(*args)
  732.   end
  733.   #----------------------------
  734.   # Overwrite start popup
  735.   #----------------------------
  736.   def start_popup
  737.     self.bitmap = create_bitmap
  738.     self.x = @battler.x
  739.     self.y = @battler.y
  740.     self.ox = self.bitmap.width / 2
  741.     self.oy = self.bitmap.height
  742.     self.z = @battler.screen_z + 350
  743.   end
  744.  
  745. end
  746.  
  747. #==============================================================================
  748. end # $imported["YES-BattlePopup"]
  749.  
  750. end # $imported[:TSBS]
Advertisement
Add Comment
Please, Sign In to add comment