KModTimer ACE

KModTimer ACE
Version 1.0.0

by Kyonides Arkanthes
​

Introduction

This is a simple scriptlet that provides some extra features for your timer sprite like custom font name and size and even a colored background. The last feature can be deactivated as well.

The embedded comments include a list of all the newly available script calls.

The Script

Ruby:
# * KModTimer ACE * #
#   Scripter : Kyonides Arkanthes
#   v1.0.0 - 2023-05-02

# * Script Calls * #

# - Reset Timer's Setup
# $game_timer.reset

# - Change Timer's X Alignment - Positions: :left, :center or :right
# $game_timer.pos_x = X-Alignment

# $game_timer.font_name = "Font Name"
# $game_timer.font_size = Number
# $game_timer.set_font("Font Name", Number)

# - Change the Font Color
# $game_timer.font_color(Red, Green, Blue)
# $game_timer.font_color(Red, Green, Blue, Alpha)

# - Change the Background Color
# $game_timer.bg_color(Red, Green, Blue)
# $game_timer.bg_color(Red, Green, Blue, Alpha)

# - Toggle Background Color - Boolean: true or false
# $game_timer.use_bg = Boolean

module KModTimer
  # Initial Values
  FONT_NAME = "Arial"
  FONT_SIZE = 32
  # Color Ranges (0..255) [Red, Green, Blue, Alpha]
  FONT_COLOR = [255, 255, 255, 255]
  BG_COLOR   = [0, 0, 0, 80]
  USE_BG_COLOR = true
  # Choose the Position: :left, :center or :right
  POSITION_X = :left
# * End of Setup Section * #
  extend self
  attr_accessor :refresh
end

class Sprite_Timer
  def create_bitmap
    self.bitmap = Bitmap.new(96, 48)
    bg_setup
    font_setup
  end

  def bg_setup
    @bg_color = Color.new(*$game_timer.bg_color)
  end

  def font_setup
    font = self.bitmap.font
    font.name = $game_timer.font_name
    font.size = $game_timer.font_size
    font.color.set(*$game_timer.font_color)
  end

  def redraw_backdrop
    bm = self.bitmap
    $game_timer.use_bg ? bm.fill_rect(bm.rect, @bg_color) : bm.clear
  end
  
  def redraw
    if KModTimer.refresh
      KModTimer.refresh = nil
      bg_setup
      font_setup
    end
    redraw_backdrop
    bitmap.draw_text(bitmap.rect, timer_text, 1)
  end

  def update_x
    case $game_timer.pos_x
    when :left
      self.x = 0
    when :center
      self.x = (Graphics.width - self.bitmap.width) / 2
    when :right
      self.x = Graphics.width - self.bitmap.width
    end
  end

  def update_position
    update_x
    self.y = 0
    self.z = 200
  end
end

class Game_Timer
  include KModTimer
  alias :kyon_mod_timer_gm_sys_init :initialize
  def initialize
    kyon_mod_timer_gm_sys_init
    reset
  end

  def reset
    @font_name = FONT_NAME.dup
    @font_size = FONT_SIZE
    @font_color = FONT_COLOR.dup
    @bg_color = BG_COLOR.dup
    @use_bg = USE_BG_COLOR
    @pos_x = POSITION_X
  end

  def set_font(new_name, new_size)
    KModTimer.refresh = true
    @font_name = new_name
    @font_size = new_size
  end

  def font_name=(new_name)
    KModTimer.refresh = true
    @font_name = new_name
  end

  def font_size=(new_size)
    KModTimer.refresh = true
    @font_size = new_size
  end

  def font_color(red, green, blue, alpha=255)
    KModTimer.refresh = true
    @font_color = [red, green, blue, alpha]
  end

  def bg_color(red, green, blue, alpha=255)
    KModTimer.refresh = true
    @bg_color = [red, green, blue, alpha]
  end

  def use_bg=(bool)
    KModTimer.refresh = true
    @use_bg = bool
  end
  attr_reader :font_name, :font_size, :font_color, :bg_color,  :use_bg
  attr_accessor :pos_x
end

Terms & Conditions

Feel free to use it.
Optionally, you could include my nickname in your game credits.
That's it.
New Features Are Available!​

From now on, all of the RGSS based engines allow you to change the timer's settings during gameplay! 😮

The script calls for RMXP and RMVX are identical. 😉

VX Ace's calls are totally different because of the existence of the Game_Timer class. He, he.

Original thread: https://forums.rpgmakerweb.com/threads/kmodtimer-ace.157106/