QuasiXi

[GTBS] Place Window v2.5

Jan 31st, 2014
620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.80 KB | None | 0 0
  1. #===============================================================================
  2. #  GTBS Placement Window v2.5.2
  3. #
  4. # This Script was made for GTBS 2.4.  It is a plug-n-play
  5. # Paste this anywhere below [GTBS] Window_Base
  6. # Feel free to use/edit
  7. # Credits would be nice, but you do not need to.
  8. #
  9. # Edit the values in module Quasi to your liking.
  10. # Don't edit anything else unless you know what you are doing.
  11. #
  12. # To use a picture instead of windowskin for the Place Window
  13. # Make a file in Graphics/Pictures/GTBS/ named "TBS_Place"
  14. #
  15. # Uses battlers instead of characters.
  16. # Uses Animated battlers settings if sprite name has the _ANIM suffix
  17. # Animated battlers might be buggy, didn't test all the different types
  18. # only tested Minkoff and GTBS
  19. # Not sure how Minkoff mini battle actually works, so it may be scripted incorrect
  20. #
  21. # Animated Character referenced off Galv
  22. #
  23. # By Quasi (http://quasixi.wordpress.com/)
  24. # 1/31/14
  25. #
  26. # Edited:
  27. # Fixed a small buy with L,R
  28. # 2/7/14
  29. #
  30. # Added hide for background picture
  31. # Didn't notice I forgot it
  32. # 2/8/14
  33. #===============================================================================
  34.  
  35. module Quasi
  36.   PLACEOFFSET_Y = 70
  37.   PLACEWIN_X = 0
  38.   PLACEWIN_Y = Graphics.height - 170
  39.   PLACEWIN_Z = 2
  40.   PLACEWIN_HEIGHT = 100
  41.   PLACEWIN_WIDTH = Graphics.width
  42.   PLACEWIN_COL = 5 #Max Number of actors to display
  43.   WINPLACE_SPACING = 40 #Spacing Between Actors
  44.  
  45.   # Set this to true if you want to use minkoff battlers ( needs to end in _MINI )
  46.   # Keep this as false if your not using it or it'll cut the chara incorrect.
  47.   PLACEMINKOFF = false
  48.   # Set the pose you want to use
  49.   # Only works for animated battlers!
  50.   # If you don't know what poses they're are look at [GTBS] Animation Config
  51.   # line 113, for minkoff line 175
  52.   PLACEPOSE = 2
  53. end
  54.  
  55.  
  56. #===============================================================================
  57. # Changes to [GTBS] Scene_Battle
  58. # Adds window + hides
  59. #===============================================================================
  60. class Scene_Battle_TBS
  61.   Win_Place = 'place'
  62.   alias quasi_create_windows create_windows
  63.  
  64.   def create_windows
  65.     quasi_create_windows
  66.     create_place_window
  67.   end
  68.  
  69.   def create_place_window
  70.     @windows[Win_Place] = Windows_Place_GTBS.new
  71.   end
  72.  
  73.   def finish_prep
  74.     @windows[Win_Help].hide
  75.     @windows[Win_Place].hide
  76.     if @ATB_Active
  77.       setup_start_atb
  78.     else
  79.       choose_team_start
  80.     end
  81.   end
  82.  
  83. #===============================================================================
  84. # Changes to [GTBS] Place_Actors
  85. # Updates Place Window
  86. # Flipped R and L
  87. #===============================================================================
  88.  
  89.   alias quasi_start_actor_place start_actor_place
  90.   alias quasi_place_update place_update
  91.  
  92.   def set_place_finish?
  93.     @windows[Win_Confirm].ask(Command_Confirm::Place)
  94.     @windows[Win_Place].visible = false
  95.   end
  96.  
  97.   def start_actor_place
  98.     quasi_start_actor_place
  99.     @windows[Win_Place].visible = true
  100.     @windows[Win_Place].update($game_party.all_members[@index], @index)
  101.   end
  102.  
  103.   #--------------------------------------------------------------------------
  104.   # * Place Init - This method is the "initial" update to be processed during the
  105.   #    character placement phase
  106.   # L and R, switched to go correctly with window
  107.   # A (SHIFT) added to remove a battler
  108.   #--------------------------------------------------------------------------  
  109.   def place_init
  110.     actor = $game_party.all_members[@index]
  111.     if Input.trigger?(Input::B)
  112.       if tactics_actors.size == 0#Cannot exit setup if no actors placed
  113.         Sound.play_buzzer
  114.       else
  115.         Sound.play_cancel
  116.         set_place_finish?
  117.       end
  118.     elsif Input.trigger?(Input::A)
  119.       if @cursor.in_range?
  120.         if @temp_placed = occupied_by?   #if occupied
  121.           @temp_placed.hide
  122.           @temp_placed.tbs_battler = false
  123.           @temp_placed.clear_tbs_pos
  124.           dispose_character(@temp_placed)
  125.           clear_r_sprites
  126.           @temp_placed = nil
  127.           Sound.play_decision
  128.         end
  129.       end
  130.     elsif Input.trigger?(Input::C)
  131.       #valid in range?
  132.       if @cursor.in_range?
  133.         if temp_placed = occupied_by?   #if occupied
  134.           @cursor.target_positions = [@cursor.pos]
  135.           @cursor.target_area[0] = 1
  136.           @temp_placed = temp_placed
  137.           Sound.play_decision
  138.         else
  139.           if actor.hidden?
  140.             if actor.death_state?
  141.               Sound.play_buzzer
  142.               return
  143.             else
  144.               Sound.play_decision
  145.               actor.gtbs_entrance(@cursor.x, @cursor.y)
  146.               create_character(@spriteset.viewport1, actor)
  147.               next_actor_to_place
  148.               @cursor.moveto_next
  149.               if tactics_actors.size == $game_party.placable?
  150.                 set_place_finish?
  151.               end
  152.             end
  153.           #not allowed to place an actor that was forced by a map place
  154.           elsif !@place_loc.include?(actor.pos)
  155.             Sound.play_buzzer
  156.             return
  157.           else #if actor already placed, move to location
  158.             Sound.play_decision
  159.             actor.moveto(@cursor.x, @cursor.y)
  160.             actor.update
  161.           end
  162.  
  163.         end
  164.       else #valid not in range
  165.         Sound.play_buzzer
  166.       end
  167.      
  168.     #next actor
  169.     elsif Input.trigger?(Input::R)
  170.       Sound.play_cursor
  171.       next_actor_to_place
  172.     #previous actor
  173.     elsif Input.trigger?(Input::L)
  174.       Sound.play_cursor
  175.       previous_actor_to_place
  176.     end
  177.   end
  178.  
  179.   def place_update
  180.     quasi_place_update
  181.     @windows[Win_Help].visible = true if @windows[Win_Help].visible != true
  182.     @windows[Win_Place].visible = true if @windows[Win_Confirm].visible == false
  183.     @windows[Win_Place].update($game_party.all_members[@index], @index)
  184.   end
  185. end
  186.  
  187. #===============================================================================
  188. # Windows_Place_GTBS
  189. # By Quasi
  190. #===============================================================================
  191. class Windows_Place_GTBS < TBS_Window_Base
  192.   #----------------------------------------------------------------------------
  193.   # * Object Intialization
  194.   #    actor = Game_Actor/Game_Enemy/nil
  195.   #----------------------------------------------------------------------------
  196.   def initialize(actor = nil)
  197.     super(Quasi::PLACEWIN_X, Quasi::PLACEWIN_Y, Quasi::PLACEWIN_WIDTH, Quasi::PLACEWIN_HEIGHT)
  198.     @actor = nil
  199.     @index = 0
  200.     @animtime = 0
  201.     @step = -1
  202.     @afix = 1
  203.     @key = ""
  204.     @col = Quasi::PLACEWIN_COL
  205.     @y = Quasi::PLACEOFFSET_Y
  206.     @tsteps = 2
  207.     self.z = Quasi::PLACEWIN_Z
  208.     create_back
  209.     create_contents
  210.     refresh
  211.   end
  212.  
  213.   def create_back
  214.     if FileTest.exist?('Graphics/Pictures/GTBS/Window_Place.png')
  215.       @back = Sprite.new
  216.       @back.bitmap = Cache.picture('GTBS/Window_Place.png')
  217.       @back.z = 0
  218.       self.opacity = 0
  219.     else
  220.       self.opacity = GTBS::CONTROL_OPACITY
  221.     end
  222.   end
  223.   #----------------------------------------------------------------------------
  224.   # Update Method
  225.   #----------------------------------------------------------------------------
  226.   def update(actor = nil, index = nil)
  227.     super()
  228.     if @actor != actor
  229.       @actor = actor
  230.       refresh
  231.     end
  232.     if @index != index
  233.       @index = index
  234.       refresh
  235.     end
  236.    
  237.     return unless self.visible
  238.     @animtime += 1
  239.     if @animtime == 10
  240.       @animtime = 0
  241.       @step += 1
  242.       if @step >= @tsteps
  243.         @step = -1
  244.       end
  245.       refresh
  246.     end
  247.   end
  248.  
  249.   #----------------------------------------------------------------------------
  250.   # Refresh Method
  251.   #----------------------------------------------------------------------------
  252.   def refresh
  253.     if @actor == nil
  254.       hide
  255.       return
  256.     end
  257.     draw_actor_info
  258.     self.visible = true
  259.   end
  260.  
  261.   def draw_character(character_name, character_index, battler_hue, x, y, enabled = true)  
  262.     return unless character_name
  263.     anim = character_name.include?(GTBS::DETERMINE_ANIM_KEY)
  264.     suffix = ""
  265.     if Quasi::PLACEMINKOFF == true
  266.       if File.exist?('Graphics/Battlers/'+character_name+'_MINI.png')
  267.         suffix = "_MINI"
  268.       end
  269.     end
  270.     bitmap = Cache.battler(character_name+suffix, battler_hue)
  271.     n = character_index
  272.     step = 0
  273.     step = @step if enabled
  274.    
  275.     if anim and !Quasi::PLACEMINKOFF
  276.       cf = GTBS::DEFAULT_POSE_FRAMES
  277.       cs = GTBS::DEFAULT_POSE_STANCES
  278.       cp = (Quasi::PLACEPOSE - 1) * 4
  279.      
  280.       cw = bitmap.width / cf
  281.       ch = bitmap.height / (cs * 4)
  282.       cx = (cp%4*cf+1+step)*cw
  283.       cy = (cp/4*4)*ch
  284.      
  285.       ts = cf - 1
  286.     elsif anim and Quasi::PLACEMINKOFF
  287.      
  288.       cf = GTBS::MINKOFF_HOLDER_POSE_FRAMES
  289.       cs = GTBS::MINKOFF_HOLDER_POSE_STANCES
  290.       cp = (Quasi::PLACEPOSE - 1)
  291.      
  292.       cw = bitmap.width / cf
  293.       ch = bitmap.height / cs
  294.       cx = (1+step)*cw
  295.       cy = cp*ch
  296.       ts = cf - 1
  297.     else
  298.       sign = character_name[/^[\!\$]./]
  299.       if sign && sign.include?('$')
  300.         cw = bitmap.width / 3
  301.         ch = bitmap.height / 4
  302.       else
  303.         cw = bitmap.width / 12
  304.         ch = bitmap.height / 8
  305.       end
  306.       cx = (n%4*3+1+step)*cw
  307.       cy = (n/4*4)*ch
  308.       ts = 2
  309.     end
  310.     if enabled == true
  311.       @tsteps = ts
  312.     end
  313.     ocx = cw/2
  314.    
  315.     src_rect = Rect.new(cx, cy, cw, ch)
  316.     ret_rect = Rect.new(x - ocx, y - ch, cw, ch)
  317.     contents.stretch_blt(ret_rect, bitmap, src_rect)
  318.   end
  319.  
  320.   def draw_actor_info
  321.     clear_info
  322.     draw_text(0, 50, 180, line_height, " < Prev")
  323.     draw_text(Graphics.width - 100, 50, 180, line_height, "Next > ")
  324.    
  325.     party_members = $game_party.all_members
  326.     if @col > party_members.size
  327.       @col = party_members.size
  328.     end
  329.    
  330.     @odd = (@col + 1) % 2
  331.     @ofix = (@col / 2) - @odd
  332.     @afix = party_members.size - (@col - @ofix)
  333.    
  334.     @fix = @col
  335.     @fix %= 2
  336.    
  337.     @pindex = @index + @afix
  338.     for i in 0...@col
  339.       @pindex += 1
  340.       @pindex %= party_members.size
  341.      
  342.       @a = party_members[@pindex]
  343.      
  344.       spacing = i * Quasi::WINPLACE_SPACING
  345.       x = ( Graphics.width / 2 ) - (((@col - @fix) * 40) / 2)
  346.       x -= 16
  347.       if @index != @pindex
  348.         @ani = false
  349.       else
  350.         @ani = true
  351.       end
  352.       if @a != nil
  353.         draw_character(@a.character_name, @a.character_index, @a.battler_hue,x + spacing + 2, @y, @ani)
  354.       end
  355.     end
  356.   end
  357.  
  358.   def clear_info
  359.     self.contents.clear
  360.     contents.clear
  361.   end
  362.  
  363.   #-----------------------------------------------------------
  364.   # This change checks for a background image and if exist set its visiblity
  365.   #-----------------------------------------------------------
  366.   def visible=(bool)
  367.     if @back
  368.       @back.visible = bool
  369.     end
  370.     super(bool)
  371.   end
  372. end
Advertisement
Add Comment
Please, Sign In to add comment