Skip to content

Instantly share code, notes, and snippets.

@AdamKyle
Created November 4, 2012 17:14
Show Gist options
  • Save AdamKyle/4012642 to your computer and use it in GitHub Desktop.
Save AdamKyle/4012642 to your computer and use it in GitHub Desktop.
Super Simple Easy Peasy Gauge Watch System
#==============================================================================
#
# ▼ Vindictive Personalities - Variable Gauge Watch
# -- Last Updated: 2012.10.30
# -- Level: Easy, Medium
# -- Requires: N/A
#
#
# This script requires some set up on your end. While the VP::Config module
# is used to configure the general gauge and the window, the real magic lies
# in how to set up the event to use the script.
#
# The script calls are as such:
#
# $game_gauge.set_var_id(id) --> The variable id to watch the progress.
# $game_gauge.set_rvar_max(max) --> The max number of the variable
# $game_gauge.set_show(true/false) --> Two show or not to show the gauge.
#
# A typical event will look as follows:
#
# if var[id] == max
# do something here.
# else
# $game_gauge.set_var_id(1)
# $game_gauge.set_var_max(10)
# $game_gauge.set_show(tue)
#
# var[id] += 1
# end
#
# This will set up the window, the guage and and then any time the event is
# interacted with and the variable is increased towards its max, the gauge will
# fill up.
#
# The gauge will turn it's self off the second you reach the max value of the
# the variable.
#==============================================================================
#==============================================================================
# ** Module: Vindictive Personalities Config or VP::Config
#------------------------------------------------------------------------------
# This module is responsible for config of the window and the gauge it's
# self.
#==============================================================================
module VP
module Config
# Window Width. The width of the window that holds
# the gauge.
WINDOW_WIDTH = 180
# Window Height. The height of the window that holds
# the gauge.
WINDOW_HEIGHT = 0
# Window Position X. The position of the window that
# holds the gauge.
WINDOW_X = 0
# Window Position Y. The position of the window that
# holds the gauge.
WINDOW_Y = 0
# Guage Position X. The position of the gauge inside
# the window.
GAUGE_X = 0
# Guage Position Y. The position of the gauge inside
# the window.
GAUGE_Y = 0
# Gauge Width. The width of the gauge inside the window.
GAUGE_WIDTH = 160
# Gauge Color One. Color one of the gradiant.
GAUGE_COLOR_ONE = 10
# Gauge Color Two. Color two of the gradiant.
GAUGE_COLOR_TWO = 6
end
end
#==============================================================================
# ** DataManager
#------------------------------------------------------------------------------
# This module manages the database and game objects. Almost all of the
# global variables used by the game are initialized by this module.
#==============================================================================
module DataManager
class << self
alias create_gameobjects_vp_hdsfy45 create_game_objects
end
#--------------------------------------------------------------------------
# * Create Game Objects
#--------------------------------------------------------------------------
def self.create_game_objects
create_gameobjects_vp_hdsfy45
$game_gauge = Game_Gauge.new
end
end
#==============================================================================
# ** Game_Gauge
#------------------------------------------------------------------------------
# This class is responsible for setting the variable id, the variable max
# and weather or not we should show the gauge window.
#==============================================================================
class Game_Gauge
attr_accessor :variable_id
attr_accessor :variable_max
attr_accessor :show
#--------------------------------------------------------------------------
# * Set the variable id
#--------------------------------------------------------------------------
def set_var_id(id)
@variable_id = id
end
#--------------------------------------------------------------------------
# * Set the variable max
#--------------------------------------------------------------------------
def set_var_max(max)
@variable_max = max
end
#--------------------------------------------------------------------------
# * Set the abillity to show or not the gauge.
#--------------------------------------------------------------------------
def set_show(show)
@show = show
end
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
# This class performs the map screen processing.
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
# * Create All Windows
#--------------------------------------------------------------------------
alias create_all_windows_vp_fhhjse5 create_all_windows
def create_all_windows
create_all_windows_vp_fhhjse5
create_gauge
end
#--------------------------------------------------------------------------
# * Create the gauge window
#--------------------------------------------------------------------------
def create_gauge
@gauge = Window_Gauge.new()
end
end
#==============================================================================
# ** Window_Gauge
#------------------------------------------------------------------------------
# Create the gauge window
#==============================================================================
class Window_Gauge < Window_Base
#--------------------------------------------------------------------------
# * Set up the window, height, width and position
#--------------------------------------------------------------------------
def initialize
super(window_position_x, window_position_y, window_width, window_height)
refresh
end
#--------------------------------------------------------------------------
# * Set up the window width
#--------------------------------------------------------------------------
def window_width
if VP::Config::WINDOW_WIDTH == 0
return 180
else
return VP::Config::WINDOW_WIDTH
end
end
#--------------------------------------------------------------------------
# * Set up the window height
#--------------------------------------------------------------------------
def window_height
if VP::Config::WINDOW_HEIGHT == 0
return fitting_height(1)
else
return VP::Config::WINDOW_HEIGHT
end
end
#--------------------------------------------------------------------------
# * Set the X position of the window
#--------------------------------------------------------------------------
def window_position_x
if VP::Config::WINDOW_X == 0
return 0
else
return VP::Config::WINDOW_X
end
end
#--------------------------------------------------------------------------
# * Set the Y position of the window
#--------------------------------------------------------------------------
def window_position_y
if VP::Config::WINDOW_Y == 0
return 0
else
return VP::Config::WINDOW_Y
end
end
#--------------------------------------------------------------------------
# * Refresh the window
#--------------------------------------------------------------------------
def refresh
contents.clear
end
#--------------------------------------------------------------------------
# * Update the window
#--------------------------------------------------------------------------
def update
super
if $game_gauge.show && fill_rate != 1.0
self.visible = true
else
self.visible = false
end
draw_gauge(gauge_position_x, gauge_position_y, gauge_width,
fill_rate, text_color(gauge_color_one),
text_color(gauge_color_two))
end
#--------------------------------------------------------------------------
# * The fill rate of the window
#--------------------------------------------------------------------------
def fill_rate
if $game_gauge.variable_id != nil
value = 1.0/$game_gauge.variable_max
return value * $game_variables[$game_gauge.variable_id]
else
return 0
end
end
#--------------------------------------------------------------------------
# * The width of the gauge
#--------------------------------------------------------------------------
def gauge_width
if VP::Config::GAUGE_WIDTH == 0
return 160
else
return VP::Config::GAUGE_WIDTH
end
end
#--------------------------------------------------------------------------
# * The first gradient color of the gauge
#--------------------------------------------------------------------------
def gauge_color_one
return VP::Config::GAUGE_COLOR_ONE
end
#--------------------------------------------------------------------------
# * The second color of the gauge
#--------------------------------------------------------------------------
def gauge_color_two
return VP::Config::GAUGE_COLOR_TWO
end
#--------------------------------------------------------------------------
# * The X position of the guage inside the window
#--------------------------------------------------------------------------
def gauge_position_x
if VP::Config::GAUGE_X == 0
return 0
else
return VP::Config::GAUGE_X
end
end
#--------------------------------------------------------------------------
# * The Y position of the gauge inside the window
#--------------------------------------------------------------------------
def gauge_position_y
if VP::Config::GAUGE_Y == 0
return -5
else
return VP::Config::GAUGE_Y
end
end
#--------------------------------------------------------------------------
# * Open the window
#--------------------------------------------------------------------------
def open
refresh
super
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment