Icon Bar

Icon Bar
Version: 1.0

Introduction

This is a really simple script I wrote for my game and I thought that it might be useful for some other people. Basically, it makes a bar out of two different icons, an empty and a full one. It splits the icons into halves and makes a bar out of them (think the Zelda life bar with full, half, and empty hearts).

Screenshots

http://farm3.static.flickr.com/2032/197 ... d27440.jpg[/IMG]

I probably should have chosen better icons, but it should be visible. See that the top one has three and a half lighter diamonds, the second has three, and the other two have none.

Demo

Okay, I just made a small demo, and changed the instructions to (hopefully) make them easier to understand. Until the demo's accepted to the DLM, I'll attach it to this post.

Script

Script Spoiler
#==============================================================================
# ** Window_Base
#------------------------------------------------------------------------------
#  This class is for all in-game windows.
#==============================================================================

class Window_Base
`#--------------------------------------------------------------------------
  # * Draw icon bar
  #     x      : draw spot x-coordinate
  #     y      : draw spot y-coordinate
  #     value  : number of half-icons to draw filled
  #     max    : number of half-icons to draw total
  #     filled : name of icon used as filled
  #     empty  : name of icon used as empty   
  #-----------------------------------------------------------------------
  def draw_icon_bar(x, y, value, max, filled = 'Filled', empty = 'Empty')
    filled_icon = RPG::Cache.icon(filled)
    empty_icon = RPG::Cache.icon(empty)
    for i in 0...value
      icon_x = (i / 2) * 32 + ((i % 2) * 12) + x
      if i % 2 == 1
        rectangle = Rect.new(12, 0, 12, 24)
      else
        rectangle = Rect.new(0, 0, 12, 24)
      end
      self.contents.blt(icon_x, y + 4, filled_icon, rectangle, 255)
    end
    for i in value...max
      icon_x = (i / 2) * 32 + ((i % 2) * 12) + x
      if i % 2 == 1
        rectangle = Rect.new(12, 0, 12, 24)
      else
        rectangle = Rect.new(0, 0, 12, 24)
      end
      self.contents.blt(icon_x, y + 4, empty_icon, rectangle, 255)
    end
  end
end
Expand to see the code.


Instructions

Copy and paste above main. To call it just use "draw_icon_bar(x, y, value, max, filled icon (optional), empty icon (optional)". Just make sure that you either name icons when you call it or that you have icons called "Filled" and "Empty", and remember that "value" and "max" are the number of half icons, so if you want 2 1/2 out of 5, use 5 and 10.

Compatibility

Unless you have another def in Window_Base called "draw_icon_bar," you shouldn't have problems. Just make sure that when you call it, the window has "self.contents" defined.

Author's Notes

If anyone has good icons for this script, it would be nice if you'd post them for other people to use. I'm afraid I'm a horrible artist, and the icons in the demo aren't mine (I actually can't remember where I got them ':|).

Terms and Conditions

Credit's really not needed. It took me all of five minutes. :D
I think a demo or somethink is nice,
because i (i think some others else) dont know how to
use this script. With the itemnaming e.g.

A Demo I think helps. I would use your script if i know how to :D

(Sry for my bad english, i?m german)
greez zeroStar
Thanks for taking up my request.

The girl in the demo causes a weird bug.
Itll open up your explanation screen, then not let you go back to map.
If you press Esc, you can open the menu, with your screen still lingering.

Weird, but attractive.
dude there is mager glitch in this press the menu button in the window and the icons stay on the menu
@Ninjitsu & Yoshine
I know. The demo isn't supposed to do anything other than show you how to put the bar in a window of your own design.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=31967