Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- # ***TPS-Addon: TPS Clock***
- #
- # Author: eugene222 (Evgenij)
- # Version: 1.3
- # Date: 01.09.2014
- # Requires: Time and Period System V 1.2 by eugene222
- #===============================================================================
- # Changelog:
- #
- # 04.04.2014 - V. 1.0-alpha1 - script created
- # 05.04.2014 - V. 1.0 - fixed one bug, released the script
- # 09.04.2014 - V. 1.1 - made this compatible with Core 1.1
- # 21.05.2014 - V. 1.2 - added month, days and bg support
- # 01.09.2014 - V. 1.3 - custom position
- #
- #===============================================================================
- # Terms of Use:
- # You can use this script for free and commercial projects as long as you give
- # credits.
- #===============================================================================
- # Beschreibung:
- #
- # Shows a simple hud, this hud is temporary, I will make something better when
- # I have more time
- #
- # If someone have ideas how I could design my HUD, pls send me a message.
- #
- # Scriptcalls:
- # $game_time.show_clock # show HUD
- # $game_time.hide_clock # hide HUD
- #
- #
- #===============================================================================
- module TPS_CLOCK
- #-----------------------------------------------------------------------------
- # :top_left, :top_right, :bottom_left, :bottom_right
- # or you make and array like this: [x, y] if you want to use custom coordinates
- # eg. POS = [0, 120]
- #-----------------------------------------------------------------------------
- POS = :bottom_right
- #-----------------------------------------------------------------------------
- # HUD VISIBLE AT NEW GAME ?
- #-----------------------------------------------------------------------------
- CLOCK_VISIBLE_AT_START = true
- #-----------------------------------------------------------------------------
- # WINDOW OPACITY
- #-----------------------------------------------------------------------------
- WINDOW_OPACITY = 0
- #-----------------------------------------------------------------------------
- # INPUT BUTTON TO SHOW THE HUD
- # - set to false if you dont want to use buttons to controll visibility.
- #-----------------------------------------------------------------------------
- CLOCK_BUTTON = :X
- #-----------------------------------------------------------------------------
- # WHAT SHOULD HAPPEN WHEN YOU PRESS THE BUTTON?
- #
- # :trigger :
- # - SWITCH FROM CLOSED TO OPEN and OPEN TO CLOSED
- # :auto :
- # - THE WINDOW IS VISIBLE FOR SOME TIME AND THEN CLOSES ITSELF
- #-----------------------------------------------------------------------------
- BUTTON_BEHAVIOUR = :trigger
- #-----------------------------------------------------------------------------
- # IF BUTTON_BEHAVIOUR is :auto you can define the time (in frames) the window
- # will be visible on button press.
- #-----------------------------------------------------------------------------
- OPEN_FRAMES = 180
- #-----------------------------------------------------------------------------
- # USE AM PM?
- #-----------------------------------------------------------------------------
- AMPM = true
- #-----------------------------------------------------------------------------
- # TEXT BEHIND TIME (IF AMPM false)
- #-----------------------------------------------------------------------------
- CLOCK_VOCAB = "Uhr"
- #-----------------------------------------------------------------------------
- # USE WEATHER ICON? WHICH DISPLAYS CURRENT WEATHER
- #-----------------------------------------------------------------------------
- USE_WEATHER_ICON = true
- #-----------------------------------------------------------------------------
- # Icon Index for the weathers
- #-----------------------------------------------------------------------------
- WEATHER_ICONS = { :none => 110,:rain => 107, :storm => 109, :snow => 105}
- #-----------------------------------------------------------------------------
- # USE A BACKGROUND PICTURE FOR THE HUD?
- #-----------------------------------------------------------------------------
- USE_BG_GRAPHIC = true
- #-----------------------------------------------------------------------------
- # Name of the background picture, which need to be in Graphics/System
- # muss.
- # - The size need to be 224x72
- #-----------------------------------------------------------------------------
- BG_GRAPHIC = "tps_gui1"
- #-----------------------------------------------------------------------------
- end
- #===============================================================================
- # END OF CONFIG
- #===============================================================================
- $imported ||= {}
- $imported[:e222_tps_clock] = 1.2
- unless $imported[:e222_tps_core]
- msgbox("\"TBS-Addon: Clock\" requires the \"TBS-Core\" script.\n"+
- "The \"TBS-Core\" script must be placed above the addon script.")
- exit
- end
- #===============================================================================
- # Game_Time
- # aliased methods: initialize, refresh_period
- # new methods: show_clock, hide_clock, time_text, time_text_ampm
- # ampm_hour, ampm_text
- #===============================================================================
- class Game_Time
- #-----------------------------------------------------------------------------
- attr_accessor :clock_window_need_refresh
- attr_reader :clock_visible
- #-----------------------------------------------------------------------------
- alias :tps_clock_reinitialize :reinitialize
- #-----------------------------------------------------------------------------
- # Initialize
- #-----------------------------------------------------------------------------
- def reinitialize
- tps_clock_reinitialize
- @clock_window_need_refresh = false if @clock_window_need_refresh.nil?
- @clock_visible = TPS_CLOCK::CLOCK_VISIBLE_AT_START if @clock_visible.nil?
- end
- #-----------------------------------------------------------------------------
- # Next Minute
- #-----------------------------------------------------------------------------
- alias :tps_clock_next_minute_e222 :next_minute
- #-----------------------------------------------------------------------------
- def next_minute
- tps_clock_next_minute_e222
- @clock_window_need_refresh = true
- end
- #-----------------------------------------------------------------------------
- # Next Day
- #-----------------------------------------------------------------------------
- alias :tps_clock_next_day_e222 :next_day
- #-----------------------------------------------------------------------------
- def next_day
- tps_clock_next_day_e222
- @clock_window_need_refresh = true
- end
- #-----------------------------------------------------------------------------
- # Next Month
- #-----------------------------------------------------------------------------
- alias :tps_clock_next_month_e222 :next_month
- #-----------------------------------------------------------------------------
- def next_month
- tps_clock_next_month_e222
- @clock_window_need_refresh = true
- end
- #-----------------------------------------------------------------------------
- # Next Year
- #-----------------------------------------------------------------------------
- alias :tps_clock_next_year_e222 :next_year
- #-----------------------------------------------------------------------------
- def next_year
- tps_clock_next_year_e222
- @clock_window_need_refresh = true
- end
- #-----------------------------------------------------------------------------
- # Time Text without AM/PM
- #-----------------------------------------------------------------------------
- def time_text
- sprintf("%02d:%02d #{TPS_CLOCK::CLOCK_VOCAB}", hour, minute)
- end
- #-----------------------------------------------------------------------------
- # Time Text with AM/PM
- #-----------------------------------------------------------------------------
- def time_text_ampm
- sprintf("%02d:%02d %s", ampm_hour, minute, am_or_pm?)
- end
- #-----------------------------------------------------------------------------
- # AM/PM Hour
- #-----------------------------------------------------------------------------
- def ampm_hour
- h = hour % 12
- h = 12 if h == 0
- h
- end
- #-----------------------------------------------------------------------------
- # AM or PM ?
- #-----------------------------------------------------------------------------
- def am_or_pm?
- hour > 11 ? "PM" : "AM"
- end
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- # Script Call Overides:
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- #-----------------------------------------------------------------------------
- # Resume Time
- #-----------------------------------------------------------------------------
- alias :tps_clock_resume_time_e222 :resume_time
- def resume_time
- tps_clock_resume_time_e222
- @clock_window_need_refresh = true
- end
- #-----------------------------------------------------------------------------
- # Change Year
- #-----------------------------------------------------------------------------
- alias :tps_clock_change_year_e222 :change_year
- def change_year(amount)
- tps_clock_change_year_e222(amount)
- @clock_window_need_refresh = true
- end
- #-----------------------------------------------------------------------------
- # Set Time
- #-----------------------------------------------------------------------------
- alias :tps_clock_set_time_e222 :set_time
- def set_time(time)
- tps_clock_set_time_e222(time)
- @clock_window_need_refresh = true
- end
- #-----------------------------------------------------------------------------
- # Set Day
- #-----------------------------------------------------------------------------
- alias :tps_clock_set_day_e222 :set_day
- def set_day(day)
- tps_clock_set_day_e222(day)
- @clock_window_need_refresh = true
- end
- #-----------------------------------------------------------------------------
- # Set Month
- #-----------------------------------------------------------------------------
- alias :tps_clock_set_month_e222 :set_month
- def set_month(month)
- tps_clock_set_month_e222(month)
- @clock_window_need_refresh = true
- end
- #-----------------------------------------------------------------------------
- # Set Year
- #-----------------------------------------------------------------------------
- alias :tps_clock_set_year_e222 :set_year
- def set_year(year)
- tps_clock_set_year_e222(year)
- @clock_window_need_refresh = true
- end
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- # Clock Window Script Calls:
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- #-----------------------------------------------------------------------------
- # Hide Clock
- #-----------------------------------------------------------------------------
- def hide_clock
- @clock_visible = false
- end
- #-----------------------------------------------------------------------------
- # Show Clock
- #-----------------------------------------------------------------------------
- def show_clock
- @clock_visible = true
- @clock_window_need_refresh = true
- end
- #-----------------------------------------------------------------------------
- end
- #===============================================================================
- # Window_TPSClock
- # new class
- #===============================================================================
- class Window_TPSClock < Window_Base
- #-----------------------------------------------------------------------------
- include TPS_CLOCK
- #-----------------------------------------------------------------------------
- # Initialize
- #-----------------------------------------------------------------------------
- def initialize
- super(*window_pos, window_width, window_height)
- self.opacity = WINDOW_OPACITY
- @open_counter = 0
- self.visible = CLOCK_VISIBLE_AT_START
- self.visible = false if CLOCK_BUTTON && BUTTON_BEHAVIOUR == :auto
- create_bg if USE_BG_GRAPHIC
- refresh
- end
- #-----------------------------------------------------------------------------
- # Window Width
- #-----------------------------------------------------------------------------
- def window_width
- return 224
- end
- #-----------------------------------------------------------------------------
- # Half Contents Width
- #-----------------------------------------------------------------------------
- def hw_contents
- contents.width / 2
- end
- #-----------------------------------------------------------------------------
- # Create Background
- #-----------------------------------------------------------------------------
- def create_bg
- @bg = Sprite.new
- @bg.bitmap = Cache.system(BG_GRAPHIC)
- @bg.visible = CLOCK_VISIBLE_AT_START
- @bg.x = self.x
- @bg.y = self.y
- @bg.z = self.z - 1
- end
- #-----------------------------------------------------------------------------
- # Window Height
- #-----------------------------------------------------------------------------
- def window_height
- return fitting_height(2)
- end
- #-----------------------------------------------------------------------------
- # Window Position
- #-----------------------------------------------------------------------------
- def window_pos
- case POS
- when :top_right
- [Graphics.width - window_width, 0]
- when :bottom_left
- [0, Graphics.height - window_height]
- when :bottom_right
- [Graphics.width - window_width, Graphics.height - window_height]
- when POS
- else
- POS.is_a?(Array) && POS.size == 2 ? POS : [0, 0]
- end
- end
- #-----------------------------------------------------------------------------
- # Time Text
- #-----------------------------------------------------------------------------
- def time_text
- AMPM ? $game_time.time_text_ampm : $game_time.time_text
- end
- #-----------------------------------------------------------------------------
- # Refresh
- #-----------------------------------------------------------------------------
- def refresh
- return unless $game_time.clock_visible
- contents.clear
- draw_text(4, line_height, hw_contents - 28, line_height, dayandnumber_text)
- draw_text(hw_contents - 28, line_height, hw_contents , line_height, time_text, 2)
- draw_text(hw_contents , 0, hw_contents, line_height,current_month_vocab, month_alignment)
- if USE_WEATHER_ICON
- draw_icon(weather_icon, contents.width - 24, line_height) if weather_icon
- end
- end
- #-----------------------------------------------------------------------------
- # Day and Number Text
- #-----------------------------------------------------------------------------
- def dayandnumber_text
- return "#{$game_time.current_day_vocab_short} #{current_day}"
- end
- #-----------------------------------------------------------------------------
- # Current Day
- #-----------------------------------------------------------------------------
- def current_day
- $game_time.current_day.to_s.rjust(2, '0')
- end
- #-----------------------------------------------------------------------------
- # Current Month Text
- #-----------------------------------------------------------------------------
- def current_month_vocab
- $game_time.current_month_vocab
- end
- #-----------------------------------------------------------------------------
- # Current Day Text
- #-----------------------------------------------------------------------------
- def current_day_vocab
- $game_time.current_day_vocab_short
- end
- #-----------------------------------------------------------------------------
- # Weather Icon
- #-----------------------------------------------------------------------------
- def weather_icon
- WEATHER_ICONS[$game_time.current_weather] rescue nil
- end
- def month_alignment
- return (@bg ? 1 : 2)
- end
- #-----------------------------------------------------------------------------
- # Update
- #-----------------------------------------------------------------------------
- def update
- super
- @bg.visible = self.visible unless @bg.nil?
- return unless CLOCK_BUTTON
- change_open if Input.trigger?(CLOCK_BUTTON)
- @bg.visible = open? && self.visible unless @bg.nil?
- @open_counter -= 1 if @open_counter > 0
- close if @open_counter <= 0 && open? && BUTTON_BEHAVIOUR == :auto
- end
- #-----------------------------------------------------------------------------
- # Change Open
- #-----------------------------------------------------------------------------
- def change_open
- case BUTTON_BEHAVIOUR
- when :trigger
- if self.openness > 0
- close
- else
- open
- $game_time.show_clock
- end
- when :auto
- @open_counter = OPEN_FRAMES
- $game_time.show_clock
- open
- else
- return
- end
- end
- #-----------------------------------------------------------------------------
- # Dispose
- #-----------------------------------------------------------------------------
- def dispose
- @bg.bitmap.dispose
- @bg.dispose
- super
- end
- #-----------------------------------------------------------------------------
- end
- #===============================================================================
- # Scene_Map
- # aliased methods: create_all_windows, update
- # new methods: create_clock_window, refresh_tps_clock_window
- #===============================================================================
- class Scene_Map
- #-----------------------------------------------------------------------------
- # * Create All Windows
- #-----------------------------------------------------------------------------
- alias :tps_clock_create_all_windows_e222 :create_all_windows
- #-----------------------------------------------------------------------------
- def create_all_windows
- tps_clock_create_all_windows_e222
- create_clock_window
- end
- #-----------------------------------------------------------------------------
- # * Create Clock Window
- #-----------------------------------------------------------------------------
- def create_clock_window
- @tps_clock_window = Window_TPSClock.new
- end
- #-----------------------------------------------------------------------------
- # * Update
- #-----------------------------------------------------------------------------
- alias :tps_clock_update_e222 :update
- def update
- tps_clock_update_e222
- refresh_tps_clock_window
- @tps_clock_window.visible = $game_time.clock_visible
- end
- #-----------------------------------------------------------------------------
- # Refresh Clock Window
- #-----------------------------------------------------------------------------
- def refresh_tps_clock_window
- return unless $game_time.clock_window_need_refresh
- @tps_clock_window.refresh
- $game_time.clock_window_need_refresh = false
- end
- #-----------------------------------------------------------------------------
- end
- #===============================================================================
- # SCRIPT END
- #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement