RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[RESOLVED] Trouble making a HUD

0 Members and 1 Guest are viewing this topic.

***
Rep:
Level 88
Menu & Battle System Guru
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
Code: [Select]
$window = Window_Boat_Chase_HUD.new


Here's the simple window script I've been messing around with:
Spoiler for:
Code: [Select]
#==============================================================================
# ** 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

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!
« Last Edit: November 11, 2007, 10:30:30 PM by Zeriab »

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
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:

Code: [Select]
@>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.

***
Rep:
Level 88
Menu & Battle System Guru
How would you suggest integrating it into Scene_Map?

I tried integrating
Code: [Select]
@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.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
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.

Code: [Select]
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:

Code: [Select]
  @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.

***
Rep:
Level 88
Menu & Battle System Guru
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:
Code: [Select]
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

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
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?


***
Rep:
Level 88
Menu & Battle System Guru
Yeah the .window (emphasis on the dot, lol) was meant to be _window.

This is what worked:

In the Update Section:
Code: [Select]
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:
Code: [Select]
@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.
« Last Edit: November 10, 2007, 09:29:25 PM by blazinhandle »

*
Full Metal Mod - He will pillage your women!
Rep:
Level 93
The RGSS Dude
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 -
Code: [Select]
draw_gradient(x,y,width,height,value)

this would be what you do -
Code: [Select]
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."

***
Rep:
Level 88
Menu & Battle System Guru
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 for:
Code: [Select]
#--------------------------------------------------------------------------
# * 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

*
Full Metal Mod - He will pillage your women!
Rep:
Level 93
The RGSS Dude
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) -

Code: [Select]
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
Code: [Select]
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."

***
Rep:
Level 88
Menu & Battle System Guru
Awesome, I just had to adjust a few things and it worked. Here's what I did (just in case you're wondering):
Spoiler for:
Code: [Select]
  #--------------------------------------------------------------------------
  # * 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



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