Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ § SES - Time: Clock (v1.3) by Solistra [License: CC BY-SA 3.0]
- # ║ <RMVX Ace>
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Change Log
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ v1.3 (January 4th, 2013) - Compatibility fix to work with Dynamic Time v1.3.
- # ║ v1.2 (December 4th, 2012) - Added the tag <time no_clock> to maps. This tag
- # ║ allows the developer to create maps that suppress the on-map clock. You
- # ║ can also now create multiple clocks.
- # ║ v1.1 (December 2nd, 2012) - Added the ability for players to toggle whether
- # ║ or not the clock is visible and added relevant configuration options. Also
- # ║ added the ability to use a different clock in Scene_Menu with its own
- # ║ relevant settings, and rearranged some of the code for compatibility.
- # ║ v1.0 (December 1st, 2012) - Initial Release
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Summary
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ This script is a simple extension to the SES Dynamic Time script that adds
- # ║ a user-defined clock to the map which can keep track of the current time
- # ║ and date.
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Required Scripts
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ The SES Dynamic Time script (version 1.3 or higher) is required in order to
- # ║ use this script.
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Known Incompatibilities
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ See the SES Dynamic Time script for known incompatibilities.
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Installation
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ Place this script below the SES Dynamic Time script, above any other custom
- # ║ scripts, and above Main.
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Configuration
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ This clock is very flexible (like the base script is), so there is, once
- # ║ again, a fair amount of configuration to do.
- # ║
- # ║ First, you will have to define which units of time you want to use in the
- # ║ text for your clock. The order that you define these units in is important,
- # ║ as the order is used when you set up the actual text below. (The order you
- # ║ have the units in indexes them from 0, not 1.)
- # ║
- # ║ Once you have the units you wish to use defined, you may optionally name
- # ║ any of the values from these units. To do this, you will have to modify
- # ║ the NAMES hash. The key of the hash should be the symbol corresponding to
- # ║ the unit of time you wish to have named values for, and the value of the
- # ║ key should be an array. For each element in the array, that numeric value
- # ║ for the specified unit of time will be replaced by the element. For example,
- # ║ let's define some day names (assuming we set up the base script to use 7
- # ║ days for each week):
- # ║
- # ║ NAMES = {
- # ║ :day => ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
- # ║ :month => ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
- # ║ "Sep", "Oct", "Nov", "Dec"]
- # ║ }
- # ║
- # ║ If $game_time.day is equal to 3, this will show "Wed" in the clock instead.
- # ║ As an added example, you can also see that you can use this for months. If
- # ║ you're using a meridian, you could name the values "AM" and "PM", as well.
- # ║ This is a VERY flexible option, so get creative with it.
- # ║
- # ║ If you're using hours in your clock, you can add the symbol corresponding
- # ║ to the unit you are using for hours in the FORMAT_HOUR array to have its
- # ║ values formatted as a standard clock instead of military time. This will
- # ║ format 0 as 12, and will appropriately create "PM" times for values that
- # ║ are greater than 12 (so 16 would become 4 for display purposes).
- # ║
- # ║ Below this, you will define the actual text used in your clock. This string
- # ║ requires some special explanation: it uses placeholders that can affect
- # ║ the formatting of the unit they represent. Here, you'll make use of the
- # ║ order of the units that you defined in the UNITS array.
- # ║
- # ║ There are three different placeholders for different formatting styles that
- # ║ you can use: <#>, (#), and {#} (Replace # with the index of the unit you
- # ║ want to use in the UNITS array). The <#> placeholder has no formatting;
- # ║ it simply inserts the value of the unit # represents. The (#) placeholder,
- # ║ on the other hand, offsets the value with spaces (so if the value of # is
- # ║ 9 and the maximum for this unit is 60, it will display as " 9"). Likewise,
- # ║ the {#} placeholder prefixes the unit with leading zeroes (so a 9 for the
- # ║ unit above would display as "09").
- # ║
- # ║ For example, let's create a clock that has the format HH:MM [AM|PM] M/D/Y:
- # ║
- # ║ UNITS = [:minute, :hour, :meridian, :day, :month, :year]
- # ║ NAMES = { :meridian => ["AM", "PM"] }
- # ║ TEXT = "(1):{0} <2> (4)/{3}/<5>"
- # ║
- # ║ Given all of that configuration, we could end up with a clock that looks
- # ║ like this: " 7:08 PM 2/04/458".
- # ║
- # ║ Now that you've defined the clock text how you want it to appear, you will
- # ║ want to set up the properties of the clock window itself. In comparison
- # ║ to the above, this is extremely easy: it's just a four-element array to
- # ║ set the X position, Y position, width, and height of the window in pixels.
- # ║ For example, let's create a 250-pixel-wide clock in the upper-right:
- # ║
- # ║ WINDOW_PROPERTIES = [Graphics.width - 250, 0, 250, 48]
- # ║
- # ║ Play with those values all that you want to get the clock placed just where
- # ║ you like it; just note that there MUST be four elements to this array, and
- # ║ all four MUST be integers.
- # ║
- # ║ Below this is the most advanced portion of this script: constructors. You
- # ║ may have noticed that time can be split in interesting ways with the base
- # ║ Dynamic Time script -- but this has the potential to have hours that only
- # ║ go up to 6, or a maximum of 30 minutes instead of 60. Without constructors,
- # ║ you would be forced to recreate the structure of your time scheme in order
- # ║ to accurately show those hours or minutes in a way that makes sense for a
- # ║ standard clock (otherwise you'd end up going from 5:29 PM to 0:00 PM next).
- # ║
- # ║ This is where constructors come in. A constructor is basically a snippet of
- # ║ Ruby code that will replace the actual value of a unit of time for DISPLAY
- # ║ PURPOSES ONLY. The setup for this should look familiar by now: it's a hash
- # ║ with the unit of time to use the constructor for as the key, and a Proc to
- # ║ use as the constructor for this unit (note: a Proc is basically a block of
- # ║ Ruby code).
- # ║
- # ║ At this point, if you don't know basic Ruby syntax or how to use Ruby, you
- # ║ might do well not to play around with constructors until you learn more
- # ║ about the language. Having said that, here's an example of how to build
- # ║ some constructors for some common problems -- for the example, we have time
- # ║ split as 30 minutes per hour, 6 hours per time of day, 4 times of day per
- # ║ day, 7 days per week, 4 weeks per month, and 12 months per year:
- # ║
- # ║ CONSTRUCTORS = {
- # ║ :minute => Proc.new{$game_system.time.minute * 2}, # So 30 becomes 60.
- # ║ :hour => Proc.new do
- # ║ t = $game_system.time
- # ║ t.hour + t.time_of_day * t.hour_max # Make an hour in military time.
- # ║ end,
- # ║ :day => Proc.new do
- # ║ t = $game_system.time
- # ║ t.day + t.week * t.day_max # Builds an accurate day count.
- # ║ end,
- # ║ :month => Proc.new{$game_system.time.month + 1}, # So 0 is 1.
- # ║ }
- # ║
- # ║ With these constructors in place, we can now use these irregular units of
- # ║ time in our clock and have them show up like a standard clock or calendar
- # ║ would show them.
- # ║
- # ║ If you do not understand that example or how it works, you can try playing
- # ║ with the constructors if you know basic Ruby, or feel free to ignore the
- # ║ constructors completely.
- # ║
- # ║ For anyone who wishes to use constructors, note that the constructor's code
- # ║ replaces the value of the unit of time BEFORE any other formatting is done
- # ║ on the unit for display purposes. This is an EXTREMELY flexible option, and
- # ║ is only limited by your imagination and knowledge of Ruby.
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Script Calls
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ With version 1.2 of this script, you can now add multiple clocks to your
- # ║ game relatively easily.
- # ║
- # ║ To do this, you will need to push an array of arguments to send to your
- # ║ clocks into $game_system.clocks. Each clock takes the following arguments:
- # ║ the units of time this clock uses, a hash of names for these units, an array
- # ║ of units to be formatted as standard hours, the text to use for your clock
- # ║ on the map, text to use for the clock in the menu, an array of the
- # ║ properties used for the window on the map (x, y, width, height), an array
- # ║ of the properties used for the window in the menu (x, y, width, height), and
- # ║ a hash of any contructors you wish to use.
- # ║
- # ║ $game_system.clocks.push([...arguments...])
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Tags
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ● Map
- # ║ <time no_clock>
- # ║ Suppresses showing the clock on this map only.
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § Aliased Methods
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ● Game_System
- # ║ initialize
- # ║ ● Scene_Map
- # ║ create_all_windows
- # ║ ● Scene_Menu
- # ║ start
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ § New Methods
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ● Game_Map
- # ║ no_clock?
- # ║ ● Scene_Map
- # ║ create_clock_windows
- # ║ ● Scene_Menu
- # ║ create_clock_windows
- # ║
- #═╬═════════════════════════════════════════════════════════════════════════════
- # ║ ▼ module SES::Time::Clock
- #═╩═════════════════════════════════════════════════════════════════════════════
- module SES module Time module Clock
- class << self; attr_accessor :visible end
- #═╦═══════════════════════════════════════════════════════════════════════════
- # ║ α BEGIN CONFIGURATION
- #═╩═══════════════════════════════════════════════════════════════════════════
- # Determines whether the clock is visible by default or not. (Note: this
- # affects all clocks.)
- @visible = true
- # The input key used to toggle the visibility of the clock. You may set this
- # to nil if you do not want the player to be able to toggle the clock. (This
- # setting is persistent across all clocks as well.)
- TOGGLE_VISIBILITY = :L
- # Set whether or not you wish to have the clock available in the menu.
- CLOCK_IN_MENU = true
- # Define which units of game time you will use in your clock's text here.
- # Note: the order that you put your units in here is important, as the order
- # is referenced in the TEXT constant below.
- # [index 0, index 1, index 2, ...]
- UNITS = [:day, :hour, :minute, :time_of_day]
- # Name any units of time that you want to have alternate names for here.
- # (Check the Configuration section in the header of this script for more
- # information.)
- NAMES = {
- # [unit symbol] => ["Name 1", "Name 2", ...]
- :time_of_day => ["AM", "AM", "PM", "PM"]
- }
- # Configure any units you wish to offset as standard (not military) hours.
- FORMAT_HOUR = [:hour]
- # Define the text used by the clock. (Check the Configuration section in the
- # header of this script for more information.)
- TEXT = "(1):{2} <3>"
- MENU_TEXT = "Day <0>\n(1):{2} <3>"
- # Set the x, y, width, and height properties for the clock window here.
- # All are measured in pixels. (Note: this array MUST have four elements!)
- MAP_ARGS = [Graphics.width - 120, Graphics.height - 48, 120, 48]
- MENU_ARGS = [0, Graphics.height - 120, 160, 72]
- # Build any custom constructors that you wish to use here. This is relatively
- # advanced, and does require at least minimal knowledge of Ruby.
- CONSTRUCTORS = {
- :hour => Proc.new do
- t = $game_system.time; t.hour + t.time_of_day * t.hour_max
- end,
- }
- #═╦═══════════════════════════════════════════════════════════════════════════
- # ║ Ω END CONFIGURATION
- #─╫───────────────────────────────────────────────────────────────────────────
- # ║ ▼ class Window
- #═╩═══════════════════════════════════════════════════════════════════════════
- class Window < Window_Base
- def initialize(units = UNITS, names = NAMES, hour_format = FORMAT_HOUR,
- text = TEXT, menu_text = MENU_TEXT, map_args = MAP_ARGS, menu_args =
- MENU_ARGS, constructors = CONSTRUCTORS)
- # Begin the actual initialization here.
- @units, @names, @hour_format = units, names, hour_format
- @text, @menu_text = text, menu_text
- @constructors = constructors
- super(*(SceneManager.scene.is_a?(Scene_Map) ? map_args : menu_args))
- if SceneManager.scene.is_a?(Scene_Menu) then self.openness = 255
- else self.openness = Clock.visible ? 255 : 0 end
- initialize_tags
- refresh
- end
- def update
- super
- refresh if $game_system.time.update_conditions_met? && self.open?
- toggle_visibility if Input.trigger?(TOGGLE_VISIBILITY)
- end
- def toggle_visibility
- return if SceneManager.scene.is_a?(Scene_Menu)
- if self.open? then self.close
- else self.open && refresh end
- Clock.visible = !Clock.visible
- end
- def refresh
- contents.clear
- draw_text_ex(4, 0, parse_clock_text)
- end
- def initialize_tags
- @tags = {
- # Simple "just return it" tag.
- '\<#\>' => Proc.new{|var| var},
- # The whitespace offset tag.
- '\(#\)' => Proc.new do |var, index|
- max = $game_system.time.send("#{@units[index]}_max").to_s.length
- if max - var.length > 0
- var.length == max ? var : (" " * (max - var.length)) << var
- else var end
- end,
- # Decimal prefix tag.
- '\{#\}' => Proc.new do |var, index|
- max = $game_system.time.send("#{@units[index]}_max").to_s.length
- if max - var.length > 0
- var.length == max ? var : ("0" * (max - var.length)) << var
- else var end
- end
- }
- end
- def parse_clock_text
- text = (SceneManager.scene.is_a?(Scene_Map) ? @text : @menu_text).clone
- time = $game_system.time
- @units.each_with_index do |u, i|
- v = @names[u] ? @names[u][time.send(u)] : time.send(@units[i])
- v = format_variable(v, @units[i])
- text = parse_text(text, i, v)
- end
- return text
- end
- def parse_text(text, i, v)
- @tags.each do |tag, code|
- text.gsub!(Regexp.new(tag.sub("#", i.to_s)), code.call(v.to_s, i))
- end
- return text
- end
- def format_variable(var, unit)
- var = @constructors[unit].call if @constructors.include?(unit)
- return format_hour(var) if @hour_format.include?(unit)
- var
- end
- def format_hour(var)
- if var == 0 then 12
- elsif var > 12 then var - 12
- else var end
- end
- end
- #═╦═══════════════════════════════════════════════════════════════════════════
- # ║ ▲ class Window
- #═╩═══════════════════════════════════════════════════════════════════════════
- end end end
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▲ module SES::Time::Clock
- #═╩═════════════════════════════════════════════════════════════════════════════
- ($imported ||= {})["SES - Time: Clock"] = 1.3
- if $imported["SES - Time"].nil? || $imported["SES - Time"] < 1.3
- raise("SES Clock requires SES Time v1.3 or greater.")
- end
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▼ class Game_System
- #═╩═════════════════════════════════════════════════════════════════════════════
- class Game_System
- attr_accessor :clocks
- alias :ses_time_clock_sys_init :initialize
- def initialize(*args, &block)
- ses_time_clock_sys_init(*args, &block)
- @clocks = []
- @clocks.push([])
- end
- end
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▲ class Game_System
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ▼ class Game_Map
- #═╩═════════════════════════════════════════════════════════════════════════════
- class Game_Map
- def no_clock?(map = @map)
- (map.note =~ /\<time no\_clock\>/ ? true : false) unless map.nil?
- end
- end
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▲ class Game_Map
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ▼ class Scene_Map
- #═╩═════════════════════════════════════════════════════════════════════════════
- class Scene_Map < Scene_Base
- alias :ses_time_clock_map_caw :create_all_windows
- def create_all_windows(*args, &block)
- ses_time_clock_map_caw(*args, &block)
- create_clock_windows unless $game_map.no_clock?
- end
- def create_clock_windows
- $game_system.clocks.each_with_index do |args, i|
- instance_variable_set("@clock_#{i}", SES::Time::Clock::Window.new(*args))
- end
- end
- end
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▲ class Scene_Map
- #─╫─────────────────────────────────────────────────────────────────────────────
- # ║ ▼ class Scene_Menu
- #═╩═════════════════════════════════════════════════════════════════════════════
- if SES::Time::Clock::CLOCK_IN_MENU
- class Scene_Menu < Scene_MenuBase
- alias :ses_time_clock_menu_start :start
- def start(*args, &block)
- ses_time_clock_menu_start(*args, &block)
- create_clock_windows
- end
- def create_clock_windows
- $game_system.clocks.each_with_index do |a, i|
- instance_variable_set("@clock_#{i}", SES::Time::Clock::Window.new(*a))
- end
- end
- end
- end
- #═╦═════════════════════════════════════════════════════════════════════════════
- # ║ ▲ class Scene_Menu
- #═╩═════════════════════════════════════════════════════════════════════════════
Advertisement
Add Comment
Please, Sign In to add comment