Strategy Bar system

Started by shintashi, October 18, 2011, 02:31:02 am

Previous topic - Next topic

shintashi

October 20, 2011, 08:52:43 pm #20 Last Edit: October 20, 2011, 09:06:05 pm by shintashi
Quote from: Fantasist on October 20, 2011, 07:31:28 pm
^ You need to call refresh method every time there is a change in the displayed values. But I;m sure KK20 can take care of it :D
One more thing. It might just be me, but dummy windows don't feel like a good idea...


I had a thing called @window_st.refresh (st for strategy text) but as i thought about it today I realized since KK20's version doesn't update until i press enter, there's no way to know if the global variable was the problem, and i also realized i could have used the global in a much cleaner way.

you are right about dummy windows, it's just the only thing I could think of once i realized the layer of the text is always the same as the window.

layer 100ish = background dummy window
layer 110ish = strategy bar stuff
layer 120ish = text dummy window

it kinda sucks that i need two windows to get the layering right.


edit: tested it by going through a full round of combat, and the confirmed modifiers show up. For now, I'm going to try positioning the terms in the right place, and then I can worry about how to get them to update "live". 

Fantasist

October 20, 2011, 09:41:10 pm #21 Last Edit: October 20, 2011, 09:42:52 pm by Fantasist
Here's a demo with my corrections. I mainly cleaned up the code and reorganized a few things:
http://www.sendspace.com/file/5pmrvw

Look for changes in the scripts in the editor so you can incorporate them into your project.
Legend:
+ <script_name>: New script, just copy the entire script slot and add it to your project
* <script_name>: Made changes to the original. To find the change, go to the slot, hit CTRL+F and type "# MOD". You'll see what's changed. Simply make those changes to your project.
Though, the changes I've made were already made in your project, I think. Pay attention to "+ Game_Actor" and replicate those changes into your project.

Changes I've made from the original:
- redefined and reorganized the update phases.
- removed the "make_strategy_result" method. It's now taken care of by the "end_strategy" method.
- renamed the sprite variables to be more descriptive.
- instead of calling the refresh method each time an arrow is moved, I've simply changed the arrow sprites' .x values and _rotate sprites' .angle values.
- Some other stuff I might not remember.


For displaying the +/- 1-10 values on the black rectangle, you could draw directly on the sprite instead of creating a new window for that. Bitmap objects have a method to draw text on them. Even in windows, what you always see is "self.contents.draw_text(x, y, width, height, text, align)", but self.contents is a Bitmap (in the window's initialize method, you'll see "self.contents = Bitmap.new(width, height)" ). So even the black sprite has a bitmap, right? (@sprite.bitmap = RPG::Cache.picture("black_rectangle")) You just need to use draw_text on that bitmap: "@sprite.bitmap.draw_text(x, y, width, height, text, align)". But beware, when you clear the bitmap before drawing text, there will be a transparent bg. self.contents is cleared before drawing text because it's transparent to begin with. But when drawing to your black rextangle, instead f clearing the area, you replace the area from the original graphic using Bitmap's "blt" method (read up on it in the RMXP help file). Following me so far?

For cleaning up the status window, you could simply clear the contents of Window_BattleStatus and redraw them. Basically, wherever you've changed the @status_window to Window_BlankStatus, simply do this: "@status_window.contents.clear". When you want to restore the original: "@status_window.refresh". This way, you can completely skip making a new window.
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




shintashi

Well i got a lot of the kinks out of the system, and i got text to display on top of the strategies, and to also change when the arrow keys are moved. The stats also stay in position when moving to the next character, but reset when canceling (although one might be able to lock some in place by going all the way back and forward.. that part is a bit weird).

Spoiler: ShowHide




The descriptive words for each category change depending on your settings, and change colors when near extremes. For this part of the project, I had to add new colors to my Window_Base. I also reversed the order of C and B buttons in KK20's code.

New colors: (nothing special, but irritating)


#--------------------------------------------------------------------------
  # * Get Blue Text Color
  #--------------------------------------------------------------------------
  def blue_color
      return Color.new(0, 0, 255, 255)
  end
  #--------------------------------------------------------------------------
  # * Get Green Text Color
  #--------------------------------------------------------------------------
  def green_color
      return Color.new(0, 255, 0, 255)
  end
  #--------------------------------------------------------------------------
  # * Get Red Text Color
  #--------------------------------------------------------------------------
  def red_color
     return Color.new(255, 0, 0, 255)
  end
  #--------------------------------------------------------------------------
  # * Get Yellow Text Color
  #--------------------------------------------------------------------------
  def yellow_color
    return Color.new(255, 255, 0, 255)
  end
  #--------------------------------------------------------------------------
  # * Get Magenta Text Color
  #--------------------------------------------------------------------------
  def magenta_color
      return Color.new(255, 0, 255, 255)
  end
  #--------------------------------------------------------------------------
  # * Get Orange Text Color
  #--------------------------------------------------------------------------
  def orange_color
     return Color.new(255, 128, 0, 255)
  end
  #--------------------------------------------------------------------------
  # * Get Purple Text Color
  #--------------------------------------------------------------------------
  def purple_color
      return Color.new(128, 55, 255, 255)
  end




Window_ST:
Spoiler: ShowHide


#==============================================================================
# ** Window_ST
#------------------------------------------------------------------------------
#  This window displays Window Strategy Text in the Strategy Bars.
#==============================================================================

class Window_ST < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(240, 320, 400, 160)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 0
    @actor = $active_actor
    refresh
  end
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  def dispose
    super
  end
  #--------------------------------------------------------------------------
  # * Refresh *Revised*
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    a_name = @actor.name
    a_spd = @actor.spd
    a_uke = @actor.uke
    a_agg = @actor.agg
#    p $active_actor.name

      self.contents.font.color = normal_color
      self.contents.font.size = 11
   
     # initive/patience bar (timing)
    if a_spd > 7
      self.contents.font.color = blue_color
      self.contents.draw_text(124, 94, 80, 11, "Sage", 1)
    end 
    if a_spd > 2 && a_spd < 8
      self.contents.font.color = normal_color
      self.contents.draw_text(124, 94, 80, 11, "Reserved", 1)
    end
    if a_spd > -3 && a_spd < 3
      self.contents.font.color = normal_color
      self.contents.draw_text(124, 94, 80, 11, "Calm", 1)
    end
    if a_spd > -8 && a_spd < -2
      self.contents.font.color = normal_color
      self.contents.draw_text(124, 94, 80, 11, "Impulsive", 1)
    end
    if a_spd < -7
      self.contents.font.color = yellow_color
      self.contents.draw_text(124, 94, 80, 11, "Kensai", 1)
    end
   
    # uke/seme bar (fight/flight)
    if a_uke > 7
      self.contents.font.color = green_color
      self.contents.draw_text(124, 106, 80, 11, "Tank", 1)
    end
   if a_uke > 2 && a_uke < 8
     self.contents.font.color = normal_color
      self.contents.draw_text(124, 106, 80, 11, "Masochist", 1)
    end
    if a_uke > -3 && a_uke < 3
      self.contents.font.color = normal_color
      self.contents.draw_text(124, 106, 80, 11, "Balanced", 1)
    end
   if a_uke > -8 && a_uke < -2
     self.contents.font.color = normal_color
      self.contents.draw_text(124, 106, 80, 11, "Sadist", 1)
    end
   if a_uke < -7
      self.contents.font.color = purple_color
      self.contents.draw_text(124, 106, 80, 11, "Dominatrix", 1)
    end     
   
    #brutality/finesse bar (self control)
    if a_agg > 7
      self.contents.font.color = orange_color
      self.contents.draw_text(124, 118, 80, 11, "Sublime", 1)
    end 
    if a_agg > 2 && a_agg < 8
      self.contents.font.color = normal_color
      self.contents.draw_text(124, 118, 80, 11, "Graceful", 1)
    end 
    if a_agg > -3 && a_agg < 3
      self.contents.font.color = normal_color
      self.contents.draw_text(124, 118, 80, 11, "Moderate", 1)
    end 
    if a_agg > -8 && a_agg < -2
      self.contents.font.color = normal_color
      self.contents.draw_text(124, 118, 80, 11, "Rage", 1)
    end 
    if a_agg < -7
      self.contents.font.color = red_color
      self.contents.draw_text(124, 118, 80, 11, "Berserk", 1)
    end 
   
    # numerical values of strategy bars
          self.contents.font.color = normal_color
    if a_spd < 1
      self.contents.draw_text(0, 94, 80, 11, a_spd.to_s, 1)
    else
      self.contents.draw_text(0, 94, 80, 11, "+" + a_spd.to_s, 1)
    end
    if a_uke < 1
      self.contents.draw_text(0, 106, 80, 11, a_uke.to_s, 1)
    else
      self.contents.draw_text(0, 106, 80, 11, "+" + a_uke.to_s, 1)
    end
    if a_agg < 1
      self.contents.draw_text(0, 118, 80, 11, a_agg.to_s, 1)
    else
      self.contents.draw_text(0, 118, 80, 11, "+" + a_agg.to_s, 1)
    end
  # active actor's name display
    self.contents.font.name = "Arial Black"
      self.contents.font.size = 18
    self.contents.draw_text(260, 86, 80, 32, a_name.to_s, 1)
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
  end
end







Strategy:
Spoiler: ShowHide


#==============================================================================
# ** Scene Battle Strategy
#------------------------------------------------------------------------------
#  This class performs battle strategy screen processing.
#==============================================================================

class Scene_Battle
  #--------------------------------------------------------------------------
  # * Start Strategy (make sure @battler is_an_actor? = true)
  #--------------------------------------------------------------------------
  def start_strategy
    #load background window overlay with actor's name
    #load arrow key readers
    #@actor_command_window.visible = false
    @actor_command_window.active = false
    @triangle_step = 1
    @spd = @active_battler.spd
    @uke = @active_battler.uke
    @agg = @active_battler.agg
    @b_spd = @active_battler.spd
    @b_uke = @active_battler.uke
    @b_agg = @active_battler.agg
    @status_window.dispose
    @status_window = Window_BlankStatus.new
    $active_actor = $game_party.actors[@actor_index]
    @window_st = Window_ST.new
    @window_st.z = 200
  end

  #--------------------------------------------------------------------------
  # * Make Triangle (circle, triangle lid)
  #--------------------------------------------------------------------------
  def make_triangle
    y_mod = 25
    # triangle background
      @sprite8 = Sprite.new
    @sprite8.z, @sprite8.x, @sprite8.y = 115, 477, 280 + y_mod
    @sprite8.angle = 0 #keep 0
    @sprite8.bitmap = RPG::Cache.picture ("tri_circle")
    #Create x_, y_, and z_rotate
    make_rotate
    #tri_cover
      @sprite12 = Sprite.new
    @sprite12.z, @sprite12.x, @sprite12.y = 119, 497, 290 + y_mod
    @sprite12.angle = 0 #keep 0
    @sprite12.bitmap = RPG::Cache.picture ("tri_cover")

  end
  #--------------------------------------------------------------------------
  # * Make Triangle (x_rotate, y_rotate, z_rotate)
  #--------------------------------------------------------------------------
  def make_rotate
    y_mod = 25
  # x_rotate
      @sprite9 = Sprite.new
    @sprite9.z, @sprite9.x, @sprite9.y = 116, 555, 306 + y_mod
    @sprite9.angle = 0 + (@spd * 3)
    @sprite9.ox = 6
    @sprite9.oy = 6
    @sprite9.bitmap = RPG::Cache.picture ("x_rotate")
    # y_rotate
      @sprite10 = Sprite.new
    @sprite10.z, @sprite10.x, @sprite10.y = 117, 503 +6, 381 + y_mod
    @sprite10.angle = 0 + (@uke * 3)
    @sprite10.ox = 6
    @sprite10.oy = 47
    @sprite10.bitmap = RPG::Cache.picture ("y_rotate")
    #z_rotate
      @sprite11 = Sprite.new
    @sprite11.z, @sprite11.x, @sprite11.y = 118, 525 +69, 383 + y_mod
    @sprite11.angle = 0 + (@agg * 3)
    @sprite11.ox = 69
    @sprite11.oy = 52
    @sprite11.bitmap = RPG::Cache.picture ("z_rotate")
  end
  #--------------------------------------------------------------------------
  # * Make Bars (initiative, semeru, brutality)
  #--------------------------------------------------------------------------
  def make_bars

    # @active_battler.name
    abs = 8 * @spd
    abu = 8 * @uke
    aba = 8 * @agg
   
    y_mod = 25
    # initiative <=> patience (impulsive/intercept)
      @sprite1 = Sprite.new
    @sprite1.z, @sprite1.x, @sprite1.y = 120, 260, 274 + y_mod
    @sprite1.angle = 0
    @sprite1.bitmap = RPG::Cache.picture ("yellow_blue")
    # semeru <=> ukeru (forceful/receiving)
      @sprite2 = Sprite.new
    @sprite2.z, @sprite2.x, @sprite2.y = 121, 261, 348 + y_mod
    @sprite2.angle = 0
    @sprite2.bitmap = RPG::Cache.picture ("indigo_green")
    # brutality <=> finesse (bloody/accurate)   
      @sprite3 = Sprite.new
    @sprite3.z, @sprite3.x, @sprite3.y = 122, 260, 376 + y_mod
    @sprite3.angle = 0
    @sprite3.bitmap = RPG::Cache.picture ("red_orange")
    #black rectangle status display /was y 402
            @sprite7 = Sprite.new
    @sprite7.z, @sprite7.x, @sprite7.y = 125, 260, 400 + y_mod
    @sprite7.angle = 0
    @sprite7.bitmap = RPG::Cache.picture ("black_rectangle")
    # create arrow graphics
    make_arrows
    #you need to stick the +/- 1-10 + text. over black_rectangle
    #   may need a Window_BlackText to make it happen.
  end
  #--------------------------------------------------------------------------
  # * Make Arrows (arrowR, arrowG, arrowB)
  #--------------------------------------------------------------------------
  def make_arrows
    abs = 8 * @spd
    abu = 8 * @uke
    aba = 8 * @agg
    y_mod = 25
  #arrowB
          @sprite4 = Sprite.new
    @sprite4.z, @sprite4.x, @sprite4.y = 123, 346 + abs, 334 + y_mod
    @sprite4.angle = 0
    @sprite4.bitmap = RPG::Cache.picture ("arrowB")
    #arrowG
          @sprite5 = Sprite.new
    @sprite5.z, @sprite5.x, @sprite5.y = 123, 346 + abu, 362 + y_mod
    @sprite5.angle = 0
    @sprite5.bitmap = RPG::Cache.picture ("arrowG")
    #arrowR
          @sprite6 = Sprite.new
    @sprite6.z, @sprite6.x, @sprite6.y = 124, 346 + aba, 391 + y_mod
    @sprite6.angle = 0
    @sprite6.bitmap = RPG::Cache.picture ("arrowR")   
  end
  #--------------------------------------------------------------------------
  # * Frame Update (triangle lines and bar arrows move when updated)
  #--------------------------------------------------------------------------
#probably an index loop starting with a case = 1, ++ with up/down
 
  def update_triangle
    case @triangle_step
    when 1     
      update_triangle_step1
    when 2
      update_triangle_step2
    when 3
      update_triangle_step3
    end
  end


  #--------------------------------------------------------------------------
  # * Arrows Verticle: UP & DOWN
  #--------------------------------------------------------------------------
  def arrows_verticle
   
      if Input.repeat?(Input::UP) and @triangle_step > 1
        $game_system.se_play($data_system.cursor_se)
        @triangle_step -= 1
      end
 
      if Input.repeat?(Input::DOWN) and @triangle_step < 3
        $game_system.se_play($data_system.cursor_se)
        @triangle_step += 1
      end
 
      #Confirm Choices and Exit
      if Input.trigger?(Input::C)
        $game_system.se_play($data_system.decision_se)
        make_strategy_result(false)
        phase3_next_actor
      end
      if Input.trigger?(Input::B)
        $game_system.se_play($data_system.cancel_se)
        make_strategy_result
      end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (Strategy Option 1)
  #--------------------------------------------------------------------------
  def update_triangle_step1
    @sprite1.tone = Tone.new(55, 0, 55, 0)
    @sprite2.tone = Tone.new(0, 0, 0, 0)
    if Input.repeat?(Input::LEFT) and @spd > -10
      $game_system.se_play($data_system.cursor_se)
       @spd -= 1
      refresh
    end

    if Input.repeat?(Input::RIGHT) and @spd < 10
      $game_system.se_play($data_system.cursor_se)
      @spd += 1
      refresh
    end
   
    #changes @active_battler.spd with left/right
    arrows_verticle

  end
  #--------------------------------------------------------------------------
  # * Frame Update (Strategy Option 2)
  #--------------------------------------------------------------------------
  def update_triangle_step2
    @sprite1.tone = Tone.new(0, 0, 0, 0)
    @sprite2.tone = Tone.new(100, 0, 100, 0)
    @sprite3.tone = Tone.new(0, 0, 0, 0)
    if Input.repeat?(Input::LEFT) and @uke > -10
      $game_system.se_play($data_system.cursor_se)
      @uke -= 1
      refresh
    end

   if Input.repeat?(Input::RIGHT) and @uke < 10
     $game_system.se_play($data_system.cursor_se)
     @uke += 1
     refresh
   end

    #changes @active_battler.uke with left/right
    arrows_verticle
   
  end
  #--------------------------------------------------------------------------
  # * Frame Update (Strategy Option 3)
  #--------------------------------------------------------------------------
  def update_triangle_step3
    @sprite2.tone = Tone.new(0, 0, 0, 0)
    @sprite3.tone = Tone.new(125, 0, 125, 0)
    if Input.repeat?(Input::LEFT) and @agg > -10
      $game_system.se_play($data_system.cursor_se)
      @agg -= 1
      refresh
    end

    if Input.repeat?(Input::RIGHT) and @agg < 10
      $game_system.se_play($data_system.cursor_se)
      @agg += 1
      refresh
    end
   
    #changes @active_battler.agg with left/right
    arrows_verticle
   
  end
  #--------------------------------------------------------------------------
  # * Refresh - may cause interference: alt: "strategy_refresh"
  #--------------------------------------------------------------------------
  def refresh # may crash
    #clear old sprites
#    @sprite1.dispose
#    @sprite2.dispose
#    @sprite3.dispose
    @sprite4.dispose
    @sprite5.dispose
    @sprite6.dispose
#    @sprite7.dispose
#    @sprite8.dispose
    @sprite9.dispose
    @sprite10.dispose
    @sprite11.dispose
#    @sprite12.dispose
    #Refresh Window Strategy Text
      @active_battler.spd = @spd
      @active_battler.uke = @uke
      @active_battler.agg = @agg
    @window_st.refresh
#    make_bars
#    make_triangle
    make_arrows
    make_rotate
  end
  #--------------------------------------------------------------------------
  # * Make Strategy Results (Game Battler: attr accessor(s) for @actor)
  #--------------------------------------------------------------------------
  def make_strategy_result(save_changes=true)
    if save_changes
      @active_battler.spd = @b_spd
      @active_battler.uke = @b_uke
      @active_battler.agg = @b_agg
    end
    #lock values in place
    # deactivate triangle_update through "@triangle_step"
    @triangle_step = nil
    #dispose of these windows and bitmaps
    @sprite1.dispose
    @sprite2.dispose
    @sprite3.dispose
    @sprite4.dispose
    @sprite5.dispose
    @sprite6.dispose
    @sprite7.dispose
    @sprite8.dispose
    @sprite9.dispose
    @sprite10.dispose
    @sprite11.dispose
    @sprite12.dispose
    # Go to command input for next actor
    @actor_command_window.active = true
    @status_window.dispose
    @window_st.dispose
    @status_window = Window_BattleStatus.new
    phase3_prior_actor if save_changes
  end
end