Main Menu
  • Welcome to The RPG Maker Resource Kit.

[RESOLVED] Trouble making a HUD

Started by blazinhandle, November 10, 2007, 07:06:15 AM

0 Members and 1 Guest are viewing this topic.

blazinhandle

Long time no see guys ;D

I'm currently trying to design a HUD that simply displays a variable's stocked number as well as a gradient bar for it.
I'm simply just testing it right now with an event summoning the window with the Script Command $window = Window_Boat_Chase_HUD.new

Here's the simple window script I've been messing around with:
[spoiler]#==============================================================================
# ** Window_Boat_Chase_HUD
#------------------------------------------------------------------------------
#  This window displays the Boat Chase Mini Game HUD.
#==============================================================================
class Window_Boat_Chase_HUD < Window_Base
  def initialize
    super(0, 0, 100, 200)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity=255
    refresh
  end
    #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    #draw_statusmenu(-15, 465)
    self.contents.font.name = "Arial"
    self.contents.font.bold = true
    self.contents.font.size = 20
    draw_boat_chase_skill(15,75)
  end
end
[/spoiler]

Now my problem is that it will not refresh the data. For instance I have an event set it $game_variables[102] to 10. Then I have another adding 5. Yet, the HUD will still only show 10. Also, I'm using Trickster's gradients, anyone know how I might work that using a variable instead of a parameter?

Thanks again guys!

modern algebra

Well, I wouldn't use a call script global variable. Not to say that it is impossible, but it is kind of a strange way to go about it. I would try and integrate the window call into Scene_Map itself. I also think $window is a bad name for a global variable: it is forseeable that some other script would have a global with the same name. If you're married to the idea of having it as a Hybrid type thing, then I would suggest a name like $window_boatchase_garbage, where garbage are just random characters. You have to be careful when naming globals.

However, I will give you advice based on the way it is now. I think a good way to approach this is have an event initialize the window, and then have a parallel process event run to refresh the window when necessary. Now, for how you will go about refreshing, but in any case I suggest you get another variable to store the last value of the main variable inside this variable. Then, you would have the parallel process event look like this:


@>Conditional Branch: Variable[102] != Variable [XXX: Previous Value]
  @>Script: $window_boatchase_garbage.refresh
  @>Control Variables: Variable[XXX: Previous Value] = Variable[102]
  @>
: Branch End
@>Wait: 1 Frame


Basically, what that event does would be to refresh the window any time the value is changed. That is simply because Variable [XXX: Previous Value] retains the value of the variable. When the value of variable [102] is modified in any way, the check will be true and Variable [XXX: Previous Value] would then be set to the new value of the variable and the window would refresh.

If you have any questions, just ask.

blazinhandle

How would you suggest integrating it into Scene_Map?

I tried integrating @boatchase_HUD.window = Boat_Chase_HUD_Window.new if $game_switches[201] == true (using the same check switch technique for dispose). I then created an event that would turn the switch 201 on, however, it wouldn't even show up (perhaps I need to refresh the map?).

I have a feeling I'm making this a lot more complicated then it should be.

modern algebra

Well, it depends where you put that code. If you put it into the main method of Scene_Map, prior to the update phase, then it would not run unless the switch was on before entering the map since it is only checked once at the start. You could try putting this code or something like it into the update method: I'm not sure what the .window thing is, I'll leave it in because I don't know what you're planning.


if $game_switches[201]
  @boatchase_HUD.window = Boat_Chase_HUD_Window.new if @boatchase_HUD.window.nil?
  if @previous_value != $game_variables[102]
    @boatchase_HUD.window.refresh
    @previous_value = $game_variables[102]
  end
else
  @boatchase_HUD.window.dispose if not @boatchase_HUD.window.nil?
  @boatchase_HUD.window = nil
end


You's also need to put this code in below the loop of the main method:


  @boatchase_HUD.window.dispose if not @boatchase_HUD.window.nil?



I am actually not sure if that will work or anything. I would need to see the script you are working with to provide a better solution though.

blazinhandle

The script is in the first post (it's a spoiler to spare room). My premise is just to display the variable and have a gradient to support it.

The draw_boat_chase_skill is just a Window_Base adjustment that holds both the text "Skill" and the variable:
def draw_boat_chase_skill(x, y, width = 100)
    # Draw "Skill" text string
    self.contents.font.name = "Arial"
    self.contents.font.bold = true
    self.contents.font.size = 14
    self.contents.font.color = normal_color
    self.contents.draw_text(x+3, y+3, 72, 32, "Skill")
    # Draw Skill
    self.contents.font.color = $game_variables[102].to_s == 0 ? knockout_color :
      $game_variables[102].to_s <= $game_variables[102].to_s * 4 ? crisis_color : normal_color
    self.contents.draw_text(x-70, y, 90, 32, $game_variables[102].to_s, 2)
  end

modern algebra

I meant the @boatchase_HUD.window part. It made me assume that there is a class represented by the variable @boatchase_HUD which has an instance variable @window.

In any case, did what I post work?


blazinhandle

#6
Yeah the .window (emphasis on the dot, lol) was meant to be _window.

This is what worked:

In the Update Section:
if $game_switches[201] == true
      @boatchase_HUD_window = Window_Boat_Chase_HUD.new if @boatchase_HUD_window.nil?
      if @previous_value != $game_variables[102]
        @boatchase_HUD_window.refresh
        @previous_value = $game_variables[102]
      end
    else
      @boatchase_HUD_window.dispose if not @boatchase_HUD_window.nil?
      @boatchase_HUD_window = nil
    end


In the Main ofcourse:
@boatchase_HUD_window.dispose if not @boatchase_HUD_window.nil?

Any ideas on how to shape a gradient bar for a variable though?
I've been trying with Trickster's system, but am having some troubles.

Tsunokiette

The most important thing to figure out is how high this boat chasing skill can go. After that it's smooth sailing.

assuming this is the bar format -
draw_gradient(x,y,width,height,value)

this would be what you do -
value = (variable * 1.0) / max_the_variable_can_be
draw_gradient(x,y,width,height,value)
"The wonderful thing about Tiggers
Is Tiggers are wonderful things
Their tops are made out of rubber
Their bottoms are made out of springs

They're bouncy, trouncy, flouncy, pouncy
Fun, fun, fun, fun, fun!
But the most wonderful thing about Tiggers
Is I'm the only one, I'm the only one."

blazinhandle

Say I wanted the max to be 15 and the minimum to be -15.

I'm using Trickster's Gradient Bar script and figure I can just plug in the variable for HP, but am not quite sure how to: [spoiler]#--------------------------------------------------------------------------
# * Load Gradient from RPG::Cache
#--------------------------------------------------------------------------
module RPG
  module Cache
    def self.gradient(filename, hue = 0)
      self.load_bitmap("Graphics/Gradients/", filename, hue)
    end
  end
end
 
class Window_Base < Window
  #--------------------------------------------------------------------------
  # * Constants Bar Types and Hues for parameters and parameter names
  #--------------------------------------------------------------------------
  HP_BAR = "014-Reds01"
  SP_BAR = "013-Blues01"
  BATTLESP_BAR = "032-Blues02"
  EXP_BAR = "023-Dusk01"
  ATK_BAR = "020-Metallic01"
  PDEF_BAR = "020-Metallic01"
  MDEF_BAR = "020-Metallic01"
  STR_BAR = "020-Metallic01"
  DEX_BAR = "020-Metallic01"
  AGI_BAR = "020-Metallic01"
  INT_BAR = "020-Metallic01"
  HUES = [150,180,60,30,270,350,320,170]
  STATS = ["atk","pdef","mdef","str","dex","agi","int"]
  # leave this alone if you don't know what you are doing
  OUTLINE = 1
  BORDER = 1
  #--------------------------------------------------------------------------
  # * Draw Gradient Bar
  #--------------------------------------------------------------------------
  def draw_gradient_bar(x, y, min, max, file, width = nil, height = nil, hue = 0, back = "Back", back2 = "Back2")
    bar = RPG::Cache.gradient(file, hue)
    back = RPG::Cache.gradient(back)
    back2 = RPG::Cache.gradient(back2)
    cx = BORDER
    cy = BORDER
    dx = OUTLINE
    dy = OUTLINE
    zoom_x = width != nil ? width : back.width
    zoom_y = height != nil ? height : back.height
    percent = min / max.to_f if max != 0
    percent = 0 if max == 0
    back_dest_rect = Rect.new(x,y,zoom_x,zoom_y)
    back2_dest_rect = Rect.new(x+dx,y+dy,zoom_x -dx*2,zoom_y-dy*2)
    bar_dest_rect = Rect.new(x+cx,y+cy,zoom_x * percent-cx*2,zoom_y-cy*2)
    back_source_rect = Rect.new(0,0,back.width,back.height)
    back2_source_rect = Rect.new(0,0,back2.width,back2.height)
    bar_source_rect = Rect.new(0,0,bar.width* percent,bar.height)
    self.contents.stretch_blt(back_dest_rect, back, back_source_rect)
    self.contents.stretch_blt(back2_dest_rect, back2, back2_source_rect)
    self.contents.stretch_blt(bar_dest_rect, bar, bar_source_rect)
  end    #--------------------------------------------------------------------------
  # * Draw HP
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #     width : draw spot width
  #--------------------------------------------------------------------------
  alias trick_draw_actor_hp draw_actor_hp
  def draw_actor_hp(actor, x, y, width = 144)
    # Calculate if there is draw space for MaxHP
    if width - 32 >= 108
      hp_x = x + width - 108
      flag = true
    elsif width - 32 >= 48
      hp_x = x + width - 48
      flag = false
    end
    width = hp_x - x
    width += $game_temp.in_battle ? 50 : 100
    percent = actor.hp / actor.maxhp.to_f
    hue = 120 * percent
    # Draw HP
    draw_gradient_bar(x, y + 16, actor.hp, actor.maxhp, HP_BAR, width, 8, hue)
    trick_draw_actor_hp(actor, x, y, width)
  end
[/spoiler]

Tsunokiette

Okay, this is what you do.

Keep doing the text in the hud the same way. For the gradient bar you want to cheat and make the min 0 and the max 30.

Now, don't freak out. This won't change any of your data.

It's just instead of doing this (hp being the variable for the data) -

percent = (variable * 1.0) / hp_max
hue = 120 * percent
def draw_gradient_bar(x, y, variable, 15, file, width, height, hue, back, back2)


you would do
percent = ((variable *1.0) + 15) / hp_max
hue = 120 * percent
def draw_gradient_bar(x, y, variable + 15, 30, file, width, height, hue, back, back2)


Now, I'm not entirely sure about format, but you should get the idea.
"The wonderful thing about Tiggers
Is Tiggers are wonderful things
Their tops are made out of rubber
Their bottoms are made out of springs

They're bouncy, trouncy, flouncy, pouncy
Fun, fun, fun, fun, fun!
But the most wonderful thing about Tiggers
Is I'm the only one, I'm the only one."

blazinhandle

Awesome, I just had to adjust a few things and it worked. Here's what I did (just in case you're wondering):
[spoiler]  #--------------------------------------------------------------------------
  # * Draw "Skill" Vertical Gradient Bar -15 - +15
  #--------------------------------------------------------------------------
  def draw_skill_vertical_gradient_bar(x, y, min, max, file, width = nil, height = nil, hue = 0, back = "Back", back2 = "Back2")
    bar = RPG::Cache.gradient(file, hue)
    back = RPG::Cache.gradient(back)
    back2 = RPG::Cache.gradient(back2)
    cx = BORDER
    cy = BORDER
    dx = OUTLINE
    dy = OUTLINE
    zoom_x = width != nil ? width : back.width
    zoom_y = height != nil ? height : back.height
    percent = (($game_variables[102]*1.0) +15) / max.to_f if max != 0
    percent = 0 if max == 0
    bar_y = (zoom_y - zoom_y * percent).ceil
    source_y = bar.height - bar.height * percent
    back_dest_rect = Rect.new(x,y,zoom_x,zoom_y)
    back2_dest_rect = Rect.new(x+dx,y+dy,zoom_x -dx*2,zoom_y-dy*2)
    bar_dest_rect = Rect.new(x+cx,y+bar_y+cy,zoom_x-cx*2,(zoom_y * percent).to_i-cy*2)
    back_source_rect = Rect.new(0,0,back.width,back.height)
    back2_source_rect = Rect.new(0,0,back2.width,back2.height)
    bar_source_rect = Rect.new(0,source_y,bar.width,bar.height * percent)
    self.contents.stretch_blt(back_dest_rect, back, back_source_rect)
    self.contents.stretch_blt(back2_dest_rect, back2, back2_source_rect)
    self.contents.stretch_blt(bar_dest_rect, bar, bar_source_rect)
  end    #--------------------------------------------------------------------------
  # * Draw "Skill"
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #     width : draw spot width
  #--------------------------------------------------------------------------
  alias trick_draw_boatchase_skill draw_boatchase_skill
  def draw_boatchase_skill(x, y, width = 144)
    percent = ($game_variables[102]+15) / 30
    hue = 120*percent
    # Draw SP
    draw_skill_vertical_gradient_bar(x, y-50, $game_variables[102]+15, 30, BATTLESP_BAR, 13, height, hue)
    trick_draw_boatchase_skill(x, y, height)
  end
[/spoiler]



Thanks a lot Modern and Tsuno! I really appreciate it!