[VXA] I was trying to make a playtime addon...

Otto

Veteran
Veteran
Joined
Apr 24, 2015
Messages
119
Reaction score
70
First Language
Engilsh
Primarily Uses
RM2k3
Howdy!

I was trying to add a small window displaying the total playtime, somewhere into my menu which is run by this script here:

Code:
#==============================================================================
# ** Scene_Menu
#------------------------------------------------------------------------------
#==============================================================================
module RE_MENU
   
  #--------------------------------------------------------------------------
  # ENGLISH
  #--------------------------------------------------------------------------
  # * how to create a recipe
  # * place Reciepe[a] = [b, c, d]
  # * a is a crescent number
  # * b and c are the items that will be combined
  # * d is the end item
  #--------------------------------------------------------------------------
  # PORTUGUES  
  #--------------------------------------------------------------------------
  # * receitas de combinações de itens
  # * coloque Reciepe[a] = [b, c, d] sendo
  # * a o valor crescente da receita de 1 a sla quantos
  # * b e c o valor dos intens da receitas que vam combinar
  # * d o item que será formado apartir dos outrs
  #--------------------------------------------------------------------------
 
  Recipe = {}
  Recipe[1] = [12, 13 , 14]
  Recipe[2] = [1, 1, 2]
  #Recipe[3] = [13, 16, 17]
  #Recipe[4] = [15, 14, 17]
  #Recipe[5] = [12, 12, 18]
  #Recipe[6] = [12, 18, 19]
  #--------------------------------------------------------------------------
  # vocabulary
  #--------------------------------------------------------------------------
  Equip = " "
  Discard = " "
  Combine = "Combine"
  Use = "Use"
  Equip = "EQ: "
  Inventary = "Item"
  Key_itens = "Files"
  Help_desc = " "
  Help_name = " "
  Maps = "Maps"
 
  #--------------------------------------------------------------------------
  # * Combine sond
  #--------------------------------------------------------------------------
  def self.playcombine
      Sound.play_use_item
  end
 
end

#OTTO Create Image for Background!!

  def create_Image_Background
    @sfondo = Sprite.new
    @sfondo.bitmap = Cache.system("Menu_"+$game_variables[10].to_s)
   
    @sfondo.x = 0
    @sfondo.y = 0
    #$sfondo.z =
    @sfondo.opacity = 255
   
  end
 
  def terminate
      super
      dispose_background
   end

   def dispose_background
      @sfondo.bitmap.dispose
      @sfondo.dispose
    end
 
#==============================================================================
# ** Window_Help now turned into Item Name by Otto
#------------------------------------------------------------------------------
#  Esta janela exibe explicação de habilidades e itens e outras informações.
#==============================================================================


class RE_Window_Iname < Window_Base
  #--------------------------------------------------------------------------
  # * Inicialização do objeto
  #     line_number : número de linhas
  #--------------------------------------------------------------------------
  def initialize(line_number = 1)
    super(268, 252, 207, 48) # Graphics.height - 384) OTTO (252)
  end
 
  #--------------------------------------------------------------------------
  # * Configuração de texto
  #     text : texto
  #--------------------------------------------------------------------------
  def set_text(text)
    if text != @text
      @text = text
      refresh
    end
  end
  #--------------------------------------------------------------------------
  # * Limpeza
  #--------------------------------------------------------------------------
  def clear
    set_text(" ")
  end
  #--------------------------------------------------------------------------
  # * Definição de item
  #     item : habilidades, itens, etc.
  #--------------------------------------------------------------------------
  def set_item(item)
    set_text(item ? item.description : " ")
    @item = item
  end
 
  #--------------------------------------------------------------------------
  # * Renovação
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    if @item != nil
      #draw_text(5, 70, 150, 50, RE_MENU::Help_desc)
#~       draw_text(5, -12, 640, 100, @text)
      draw_text(6, -12 , 207, 48, @item.name) #RE_MENU::Help_name + @item.name)
    end
 
  end
end

#==============================================================================
# ** Window_MenuCommand
#------------------------------------------------------------------------------
#  Esta janela exibe os comandos do menu.
#==============================================================================
class MenuCommand < Window_HorzCommand
  #--------------------------------------------------------------------------
  # * Inicialização da posição do comando de seleção (método da classe)
  #--------------------------------------------------------------------------
  def self.init_command_position
    @@last_command_symbol = nil
  end
  #--------------------------------------------------------------------------
  # * Inicialização do objeto
  #--------------------------------------------------------------------------
  def initialize
    super(268, 72)
  end
  #--------------------------------------------------------------------------
  # * Aquisição da largura da janela
  #--------------------------------------------------------------------------
  def window_width
    return 372
  end
 
  #--------------------------------------------------------------------------
  # * Aquisição da largura da janela
  #--------------------------------------------------------------------------
  def window_height
    48
  end
  #--------------------------------------------------------------------------
  # * Aquisição do número de linhas exibidas
  #--------------------------------------------------------------------------
  def col_max
    return 4
  end
  #def visible_line_number
   # 3
  #end
 
 
  #--------------------------------------------------------------------------
  # * Criação da lista de comandos
  #--------------------------------------------------------------------------
  def make_command_list
    add_main_commands
    add_map_command
    add_game_end_command
  end
  #--------------------------------------------------------------------------
  # * Adição dos comandos principais
  #--------------------------------------------------------------------------
  def add_main_commands
    add_command(RE_MENU::Inventary,   :item,   main_commands_enabled)
    add_command(RE_MENU::Key_itens, :key_item, main_commands_enabled)
  end
 
  #-------------------------------------------------------------------------
  # not sure wtf im doing lol #OTTO
  #-------------------------------------------------------------------------
  def add_map_command
    add_command(RE_MENU::Maps, :maps, main_commands_enabled) #OTTO
  end
  #--------------------------------------
 
  #--------------------------------------------------------------------------
  # * Definição de habilitação dos comandos principais
  #--------------------------------------------------------------------------
  def main_commands_enabled
    $game_party.exists
  end
  #--------------------------------------------------------------------------
  # * Adição do comando de fim do jogo
  #--------------------------------------------------------------------------
  def add_game_end_command
    add_command(Vocab::game_end, :game_end)
  end
  #--------------------------------------------------------------------------
  # * Definição de resultado ao pressionar o botão de confirmação
  #--------------------------------------------------------------------------
  def process_ok
    @@last_command_symbol = current_symbol
    super
  end
  #--------------------------------------------------------------------------
  # * Definição da janela de itens
  #     item_window : janela de itens
  #--------------------------------------------------------------------------
  def item_window=(item_window)
    @item_window = item_window
    @item_window.category = current_symbol
  end
 
end
 
class Window_ItemList < Window_Selectable
  attr_accessor :iname_window  #Thanks TheoAllen
  #--------------------------------------------------------------------------
  # * Inicialização do objeto
  #     x      : coordenada X
  #     y      : coordenada Y
  #     width  : largura
  #     height : altura
  #--------------------------------------------------------------------------
  def initialize(x, y, width, height)
    super(268, 120, 207, 132)
    @category = :none
    @data = []
  end
  #--------------------------------------------------------------------------
  # * Definição de categoria
  #--------------------------------------------------------------------------
  def category=(category)
    return if @category == category
    @category = category
    refresh
    self.oy = 0
  end
  #--------------------------------------------------------------------------
  # * Aquisição do número de colunas
  #--------------------------------------------------------------------------
  def col_max
    return 4
  end
 
  #--------------------------------------------------------------------------
  # * Aquisição do número máximo de itens
  #--------------------------------------------------------------------------
  def item_max
   case @category
    when :item
     8  + $game_variables[14]
    when :key_item
     @data ? @data.size : 1
    else
     @data ? @data.size : 1
   end
  end
 
#~   def item_max
#~    #8 + $game_variables[14]
#~     @data ? @data.size : 1 #Max Inventory Slot? Can I use variable? #OTTO
#~   end
  #--------------------------------------------------------------------------
  # * Aquisição do espaçamento entre os itens
  #--------------------------------------------------------------------------
  def spacing
    return 4
  end
 
  #--------------------------------------------------------------------------
  # * Aquisição de altura do item
  #--------------------------------------------------------------------------
  def item_height
    36
  end
  #--------------------------------------------------------------------------
  # * Aquisição das informações do item
  #--------------------------------------------------------------------------
  def item
    @data && index >= 0 ? @data[index] : nil
  end
  #--------------------------------------------------------------------------
  # * Definição de habilitação de seleção
  #--------------------------------------------------------------------------
  def current_item_enabled?
    enable?(@data[index])
  end
  #--------------------------------------------------------------------------
  # * Inclusão do item na lista
  #     item : item
  #--------------------------------------------------------------------------
  def include?(item)
    case @category
    when :item
      item.is_a?(RPG::Item) && !item.key_item? #or item.is_a?(RPG::Weapon)
    when :key_item
      item.is_a?(RPG::Item) && item.key_item?
    else
      false
    end
  end
  #--------------------------------------------------------------------------
  # * Definição de itens disponíveis para uso
  #--------------------------------------------------------------------------
  def usable?(item)
    if item.is_a?(RPG::Weapon)
      return true
    else
      return $game_party.usable?(item)
    end
    return false
 
  end
  #--------------------------------------------------------------------------
  # * Definição de habilitação do item
  #     item : item
  #--------------------------------------------------------------------------
  def enable?(item)
    #$game_party.usable?(item)
    return true
  end
  #--------------------------------------------------------------------------
  # * Criação da lista de itens
  #--------------------------------------------------------------------------
  def make_item_list
    @data = $game_party.all_items.select {|item| include?(item) }
    @data.push(nil) if include?(nil)
  end
  #--------------------------------------------------------------------------
  # * Retorno à seleção anterior
  #--------------------------------------------------------------------------
 
  def select_last
    select(@data.index($game_party.last_item.object) || 0)
  end
  #--------------------------------------------------------------------------
  # * desenhar o item
  #--------------------------------------------------------------------------
 
  def draw_item_name(item, x, y, enabled = true, width = 80)
    return unless item
    draw_icon(item.icon_index, x + 10, y + 6, enabled)
    change_color(normal_color, enabled)
#~     draw_text(x + 5, y + 50, width, line_height, item.name)
  end
  #--------------------------------------------------------------------------
  # * Desenho de um item
  #     index : índice do item
  #--------------------------------------------------------------------------
  def draw_item(index)
    item = @data[index]
 
    if item
      rect = item_rect(index)
      rect.width -= 4
      draw_item_name(item, rect.x , rect.y, true)
      rect.y -= 20
      draw_item_number(rect, item)
    end
  end
 
  #--------------------------------------------------------------------------
  # * Desenho do número de itens possuido
  #     rect : retângulo
  #     item : item
  #--------------------------------------------------------------------------
  def draw_item_number(rect, item)
    draw_text(rect, sprintf(" %2d", $game_party.item_number(item)), 2) #unless it has some tag in the notes??
  end
  #--------------------------------------------------------------------------
  # * Atualização da janela de ajuda  #<--- Thanks Theo Allen for help editing
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_item(item)
    @help_window.refresh
    return unless @iname_window
    @iname_window.set_item(item)
    @iname_window.refresh
  end
 
  #--------------------------------------------------------------------------
  # * Update Item Name #OTTO
  #--------------------------------------------------------------------------
#~   def update_iname
#~     @iname_window.set_item(item)
#~     @iname_window.refresh
#~   end
 
  #--------------------------------------------------------------------------
  # * Renovação
  #--------------------------------------------------------------------------
  def refresh
    make_item_list
    create_contents
    draw_all_items
    update_help
#~     update_iname
  end

end
 
class Comand_itens < Window_Command
  #--------------------------------------------------------------------------
  # * Inicialização do objeto
  #--------------------------------------------------------------------------
  def initialize
    super(284, 296)
    self.windowskin = Cache.system("Window_C")
    refresh
  end
 
  #--------------------------------------------------------------------------
  # * Aquisição da largura da janela
  #--------------------------------------------------------------------------
  def window_width
    return 100
  end
  def window_height
    return 76
  end
  def activeCombine=(active)
    @activecombine = active
  end
  def usename=(name)
    @usename = name
  end
  def activeCombine
    return @activecombine
  end
  def usename
    return @usename
  end
  def important=(value)
    @important = value
  end
  def important
    return @important
  end
  def isuse=(value)
    @isuse = value
  end
  def isuse
    return @isuse
  end
  #--------------------------------------------------------------------------
  # * Criação da lista de comandos
  #--------------------------------------------------------------------------
  def make_command_list
    add_command(usename,   :usar,   isuse)
    add_command(RE_MENU::Combine,  :combine,  activeCombine)
#~     add_command(RE_MENU::Discard,  :discart,  important)
  end
end
class Scene_Menu < Scene_MenuBase
  #--------------------------------------------------------------------------
  # * Inicialização do processo
  #--------------------------------------------------------------------------
  def start
    super
    create_Help_window
    create_command_window
    create_item_window
    create_Iname_window
    create_status_window
    create_command_itens
    create_Equip_window
    create_Image_Background
    @iscombine = false
    @actor = $game_party.members[0]
  end
 
  #--------------------------------------------------------------------------
  # * Criação da janela de comando
  #--------------------------------------------------------------------------
  def create_command_window
    @command_window = MenuCommand.new
    @command_window.set_handler(:item,      method(:command_item))
    @command_window.set_handler(:key_item,      method(:command_item))
    @command_window.set_handler(:game_end,  method(:command_game_end))
    @command_window.set_handler(:cancel,    method(:return_scene))
  end
 
  #--------------------------------------------------------------------------
  # * Criação da janela de itens
  #--------------------------------------------------------------------------
  def create_item_window
    wy = @command_window.y + @command_window.height + 100
    wh = Graphics.height - wy
    @item_window = Window_ItemList.new(344, wy, 200, wh)
    @item_window.help_window = @help_window
    @item_window.set_handler(:ok,     method(:on_item_ok))
    @item_window.set_handler(:cancel, method(:on_item_cancel))
    @command_window.item_window = @item_window
    @command_window.item_window = @item_window
  end
  #--------------------------------------------------------------------------
  # * Criação da janela de comando dos intems
  #--------------------------------------------------------------------------
  def create_command_itens
    @command_item = Comand_itens.new
    @command_item.set_handler(:usar,      method(:use_item))
    @command_item.set_handler(:combine,      method(:combine_item))
    @command_item.set_handler(:discart,  method(:discart_item))
    @command_item.set_handler(:cancel,    method(:return_itens))
    @command_item.visible = false
    @command_item.active = false
  end
 
  #--------------------------------------------------------------------------
  # * Criação das janelas #Position for Status and Equip #OTTO
  #--------------------------------------------------------------------------
  def create_status_window
    @Status_window = Window_Base.new(475,120,165,84)
    @Status_window.contents.clear
    #@Status_window.draw_actor_face(@actor, 1, 10)
    @Status_window.change_color(@Status_window.normal_color)
    @Status_window.draw_text(1, -10 , 120, 48, @actor.name)
    @Status_window.draw_actor_hp(@actor, 0, 40, 120)
  end
 
  def create_Help_window
    @help_window = Window_Help.new() #RE_Window_Help.new()
  end
 
  def create_Iname_window #OTTO
    @ihelp_window = RE_Window_Iname.new()
    @item_window.iname_window = @ihelp_window
  end
 
  def create_Equip_window
    @Equip_window = Window_Base.new(475,183,165,48)
    @Equip_window.contents.clear
    if @actor.equips[0] != nil
      @Equip_window.draw_icon(@actor.equips[0].icon_index, 36, 0, true)
      @Equip_window.draw_text(0, -12 , 120, 48, RE_MENU::Equip)
      #INSERT CURRENT / REMAINING AMMO HERE # OTTO
      #@Equip_window.draw_text(10, 40 , 150, 50, @actor.equips[0].name)
    else
      @Equip_window.draw_text(0, -12 , 120, 48, RE_MENU::Equip)
    end
 
 
  end
  def use_item
    if @item.is_a?(RPG::Weapon)
      @actor.change_equip(0,@item)
      Sound.play_equip
    else
      Sound.play_use_item
      @actor.use_item(@item)
      use_item_to_actors
   
    end
    return_itens
    refresh
    check_common_event
  end
  def use_item_to_actors
    $game_party.members.each do |target|
      @item.repeats.times { target.item_apply(@actor, @item) }
    end
  end
  def check_common_event
    if $game_temp.common_event_reserved?
      @sfondo.bitmap.dispose
      @sfondo.dispose
      SceneManager.goto(Scene_Map)
      @iscombine = false
    end
  end
  def combine_item
    if @iscombine == false
      @iscombine = true
      @combineitem = @item
    else
      recipe = RE_MENU::Recipe
      if @combineitem.id == @item.template_id
        if $game_party.item_number(@item) <= 1
          @combineitem = nil
        end
      end
      if @combineitem != nil
        for x in 1..recipe.size
        recipe1 = recipe[x]
     
          if recipe1[0] == @combineitem.template_id and recipe1[1] == @item.template_id
            @iscombine = false
            combineitens(x)
            break
          elsif recipe1[1] == @combineitem.template_id and recipe1[0] == @item.template_id
            @iscombine = false
            combineitens(x)
            break
          end
        end
      end
      if @iscombine == true
        Sound.play_buzzer
          @iscombine = false
      end
   
    end
    refresh
    return_itens
 
 
  end
  def combineitens(x)
    RE_MENU::playcombine
    $game_party.gain_item(@item, -1, true)
    $game_party.gain_item(@combineitem, -1, true)
    for y in 0..$data_items.size
        novoitem = $data_items[y] if y == RE_MENU::Recipe[x][2]
    end
    $game_party.gain_item(novoitem, 1)
  end
  def discart_item
    $game_party.gain_item(@item, -1, true)
    return_itens
  end
  def return_itens
    @command_item.visible = false
    @command_item.active = false
    @item_window.active = true
    @item_window.refresh
  end
  #--------------------------------------------------------------------------
  # * Item [Confirmação] #thanks to A-Moonless-Night
  #--------------------------------------------------------------------------
   #THIS BYPASSES THE SECOND USE/COMBINE WINDOW AND JUMPS DIRECTLY TO RECIPE CHECK
def on_item_ok
    @item = @item_window.item
    if @item != nil
      if @iscombine && @item.is_a?(RPG::Item) && !@item.key_item?
        combine_item
      else
        if @item.is_a?(RPG::Weapon)
          @command_item.activeCombine = false
          @command_item.usename = RE_MENU::Equip
        else
          @command_item.activeCombine = true
          @command_item.usename = RE_MENU::Use
        end
        if @item.is_a?(RPG::Item) and @item.key_item?
          @command_item.important = false
        else
          @command_item.important = true
        end
        if @item_window.usable?(@item)
          @command_item.isuse = true
        else
          @command_item.isuse = false
        end
        @command_item.refresh
        @command_item.visible = true
        @command_item.active = true
      end
    else
      Sound.play_buzzer
      @item_window.active = true
    end
    @help_window.set_item(@item)
  end
 
#~   def on_item_ok
#~     @item = @item_window.item
#~     if @item != nil
#~       if @item.is_a?(RPG::Weapon)
#~         @command_item.activeCombine = false
#~         @command_item.usename = RE_MENU::Equip
#~       else
#~         @command_item.activeCombine = true
#~         @command_item.usename = RE_MENU::Use
#~       end
#~       if @item.is_a?(RPG::Item) and @item.key_item?
#~         @command_item.important = false
#~       else
#~         @command_item.important = true
#~       end
#~       if @item_window.usable?(@item)
#~         @command_item.isuse = true
#~       else
#~         @command_item.isuse = false
#~       end
#~    
#~       @command_item.refresh
#~       @command_item.visible = true
#~       @command_item.active = true
#~     else
#~       Sound.play_buzzer
#~       @item_window.active = true
#~     end
#~     @help_window.set_item(@item)
#~   end
  #--------------------------------------------------------------------------
  # * Item [Cancelamento]
  #--------------------------------------------------------------------------
  def on_item_cancel
    @item_window.unselect
    @command_window.activate
    @iscombine = false
  end
 
  #--------------------------------------------------------------------------
  # * Comando [Item]
  #--------------------------------------------------------------------------
  def command_item
    @command_window.item_window = @item_window
    @item_window.activate
    @item_window.select_last
 
  end
  #--------------------------------------------------------------------------
  # Trying to add a Maps command #OTTO
  #--------------------------------------------------------------------------
  def command_maps
    SceneManager.call(Scene_Maps)
  end
  #--------------------------------------------------------------------------
  # * Comando [Fim do Jogo]
  #--------------------------------------------------------------------------
  def command_game_end
    SceneManager.call(Scene_Options)
  end
  #--------------------------------------------------------------------------
  # * Comandos individuais [Cancelamento]
  #--------------------------------------------------------------------------
  def on_personal_cancel
    @status_window.unselect
    @command_window.activate
  end
 
  def refresh
    @actor = $game_party.members[0]
    @item_window.refresh
    @Equip_window.contents.clear
    if @actor.equips[0] != nil
      @Equip_window.draw_icon(@actor.equips[0].icon_index, 36, 0, true)
      @Equip_window.draw_text(0, -12 , 120, 48, RE_MENU::Equip)
#~       @Equip_window.draw_text(10, 40 , 150, 50, @actor.equips[0].name)
    else
      @Equip_window.draw_text(0, -12 , 120, 48, RE_MENU::Equip)
    end
    @Status_window.contents.clear
#~     @Status_window.draw_actor_face(@actor, 1, 10)
    @Status_window.change_color(@Status_window.normal_color)
    @Status_window.draw_text(1, -10 , 120, 48, @actor.name)
    @Status_window.draw_actor_hp(@actor, 0, 40, 120)
   
  end
end
the script already has tons of modification made by me (with some big time help by fellow users).
Rather than keeping modifying that script risking to mess everything up, I followed the advice from my script godess ( :p ) A-Moonless-Night and went on to create an "indipendent" addon that goes right under the menu script.

Here's what I wrote so fare:

Code:
#--------------------------------------------------------------------------
# * THIS ADDS A WINDOW WITH PLAYTIME IN THE RE MENU;
#   THIS IS BASED OFF THE EDIT I MADE IN DARK SAGA RESURRECTION
#   AND INCLUDES FIX BY JeanBis *.
#----------------------------------------------------------------------------------

module RE_MENU
 
 class RE_Window_Time
 
  def create_time_window
     @time_window.x = 320
     @time_window.y = 240
   @time_window.width = 165
     @time_window.height = 55
  end
 
  def refresh
   @time_window.contents.clear
   @total_sec = Graphics.frame_count / Graphics.frame_rate
        hour = @total_sec / 60 / 60
        min = @total_sec / 60 % 60
        sec = @total_sec % 60
        playtime = sprintf("%02d : %02d : %02d", hour, min, sec)
   @time_window.draw_icon(32, 0, 64) #(X, Y, ID)
   @time_window.draw_text(32, 0, @time_window.width, 32, playtime)
  end

  def update
    super
    if Graphics.frame_count / Graphics.frame_rate != @total_sec
        refresh
    end
  end
 
 end

end
I basically started from a editing I did in an old project I was working on about a year ago, where I changed the gold window into a playtime window, like this:



now in that project all I really had to do was adding those lines into the script, since the gold window was already bult in, I didn't have to worry about actually making the window appear, which instead I have to do here.

Now the good news is, the game didn't explode :D
Bad news, timer is nowhere to be seen :(

I'm pretty sure I'm missing some instructions to actually tell the main script what to do with this timer (assuming that even works in the first place LOL)
Can anyone help?
 

A-Moonless-Night

WINTER IS COMING
Veteran
Joined
Mar 17, 2012
Messages
634
Reaction score
416
First Language
English
Primarily Uses
RMVXA
You haven't actually created a window; all you've really done is make an instance variable called @time_window. Have a look at the other default windows and see how they're set up—a good window to mimic for what you're planning would be Window_Help. To start with, RE_Window_Time will need to inherit from a window class, such as Window_Base, which you would do by writing:
Code:
class RE_Window_Time < Window_Base
Code:
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(line_number = 2)
    super(0, 0, Graphics.width, fitting_height(line_number))
  end
When you call Window_Help, you only need to specify how many lines need to fit, and then it works it out from there. x and y are both always 0, meaning the window is drawn at the top-left of the screen. The width is always Graphics.width, which means it fills the width of the screen. The height is calculated using a method from Window_Base called fitting_height, which figures out how tall the window needs to be to fit x number of lines.
Code:
  #--------------------------------------------------------------------------
  # * Set Text
  #--------------------------------------------------------------------------
  def set_text(text)
    if text != @text
      @text = text
      refresh
    end
  end
Basically, this checks if the instance variable @text is equal to the argument 'text' (which you write in when you call the set_text method), and if not, set @text to 'text'.
Code:
  def clear
    set_text("")
  end
Sets the text to be blank.
Code:
  def set_item(item)
    set_text(item ? item.description : "")
  end
This is where the help window draws item descriptions. If item exists, draw the item description, or else set the text to be blank.
Code:
  def refresh
    contents.clear
    draw_text_ex(4, 0, @text)
  end
This clears the contents and draws them again. As you can see above, this is called in set_text(text), which means it'll occur every time @text does not equal 'text'.

You won't need an instance variable called @time_window in the RE_Window_Time class; instead, you'll use this in Scene_Menu when you draw the window:
Code:
class Scene_Menu < Scene_MenuBase
  alias otto_menu_scenemenu_start start
  def start
    otto_menu_scenemenu_start
    create_time_window
  end
 
  def create_time_window
    @time_window = RE_Window_Time.new(320, 240, 165, 55)
  end
end
As you can see, I set the x, y, width and height when I create the time window in the menu scene. In order for this to work, your initialize method in RE_Window_Time should look something like this:

Code:
class RE_Window_Time < Window_Base
  def initialize(x, y, width, height)
    super(x, y, width, height)
  end
end
Lastly, your RE_Window_Time class shouldn't be nested inside module RE_MENU.

Hope this helps.
 

Otto

Veteran
Veteran
Joined
Apr 24, 2015
Messages
119
Reaction score
70
First Language
Engilsh
Primarily Uses
RM2k3
Thanks, that was helpful indeed :D

upload_2018-8-17_12-16-6.png

Icon and position are still to be determined, and I'm going to have to modify the background image to show a darker section under the timer (just like the options and the help window - In fact, the whole menu graphic is placeholder) but what's important is that it works, thanks again to my script godess :p

here's the final script for future reference:

Code:
#--------------------------------------------------------------------------
# * THIS ADDS A WINDOW WITH PLAYTIME IN THE RE MENU;
#   THIS IS BASED OFF THE EDIT I MADE IN DARK SAGA RESURRECTION (Ghost Rider Production)
#   AND INCLUDES FIX BY JeanBis. *
#  
# *  ALSO big thank you to A-Moonless-Night *.
#
#  This addon is made specifically for the RE Menu (which, at this day, I don't
#  know the original author) and it's unlikely it will work with other custom
#  menus, but you'll never know right?
#  Anyway, screw this completely unprofessional disclaimer text and do what
#  you want with this script, just credit A-Moonless-Night aka AMoonlessNight,
#  OTTO aka GhostRider aka GhostRiderProduction and JeanBis if you happen to
#  use it.
#
#--------------------------------------------------------------------------


class RE_Window_Time < Window_Base
 def initialize(x, y, width, height)
  super(x, y, width, height)
 end
end
 

class Scene_Menu < Scene_MenuBase
  alias otto_menu_scenemenu_start start
  def start
    otto_menu_scenemenu_start
    create_time_window
  end
 
  def create_time_window
    @time_window = RE_Window_Time.new(472, 422, 165, 55)
  end
 
  def refresh
   @time_window.contents.clear
   @total_sec = Graphics.frame_count / Graphics.frame_rate
        hour = @total_sec / 60 / 60
        min = @total_sec / 60 % 60
        sec = @total_sec % 60
        playtime = sprintf("%02d : %02d : %02d", hour, min, sec)
   @time_window.draw_icon(64, 0, 2) #(X, Y, ID?)
   @time_window.draw_text(32, 0, @time_window.width, 32, playtime)
  end
 
  def update
   super
   if Graphics.frame_count / Graphics.frame_rate != @total_sec
        refresh
   end
  end
 
end

#--------------------------------------------------------------------------
# That's all Folks!
#--------------------------------------------------------------------------
:D
 

A-Moonless-Night

WINTER IS COMING
Veteran
Joined
Mar 17, 2012
Messages
634
Reaction score
416
First Language
English
Primarily Uses
RMVXA
I would actually put refresh and update in the RE_Window_Time class (in which case, you would just remove @time_window from the start of those method calls), but otherwise, looks good.
 

Otto

Veteran
Veteran
Joined
Apr 24, 2015
Messages
119
Reaction score
70
First Language
Engilsh
Primarily Uses
RM2k3
Oh, kinda like this?

Code:
class RE_Window_Time < Window_Base
 def initialize(x, y, width, height)
  super(x, y, width, height)
 end

def refresh
   @contents.clear
   @total_sec = Graphics.frame_count / Graphics.frame_rate
       hour = @total_sec / 60 / 60
       min = @total_sec / 60 % 60
       sec = @total_sec % 60
       playtime = sprintf("%02d : %02d : %02d", hour, min, sec)
   @draw_icon(64, 0, 2) #(X, Y, ID?)
   @draw_text(32, 0, @time_window.width, 32, playtime)
 end

  def update
   super
   if Graphics.frame_count / Graphics.frame_rate != @total_sec
       refresh
   end
  end

end

class Scene_Menu < Scene_MenuBase
  alias otto_menu_scenemenu_start start
  def start
   otto_menu_scenemenu_start
   create_time_window
  end

  def create_time_window
   @time_window = RE_Window_Time.new(472, 422, 165, 55)
  end

 end
 

A-Moonless-Night

WINTER IS COMING
Veteran
Joined
Mar 17, 2012
Messages
634
Reaction score
416
First Language
English
Primarily Uses
RMVXA
Almost. Try this:
Code:
class RE_Window_Time < Window_Base
 def initialize(x, y, width, height)
  super(x, y, width, height)
 end

def refresh
   contents.clear
   @total_sec = Graphics.frame_count / Graphics.frame_rate
       hour = @total_sec / 60 / 60
       min = @total_sec / 60 % 60
       sec = @total_sec % 60
       playtime = sprintf("%02d : %02d : %02d", hour, min, sec)
   draw_icon(64, 0, 2) # draw_icon takes (icon ID, x, y)
   draw_text(32, 0, contents_width, line_height, playtime)
 end

  def update
   super
   refresh if Graphics.frame_count / Graphics.frame_rate != @total_sec
  end

end
The code for Scene_Menu should be fine.
 

Otto

Veteran
Veteran
Joined
Apr 24, 2015
Messages
119
Reaction score
70
First Language
Engilsh
Primarily Uses
RM2k3
Thanks, your version looks a lot more Pro :)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

The most rewarding part of making custom body character parts is absolutely not making the masks work. Somebody please put me out of my misery.
Any commercial devs here ever mess with Gamejolt? Been contemplating making my games available there but don't know if it's worth the effort or not.
Social distancing taught me of how much of not a loner I am. Dammit, I miss seeing my friends...
Happy 4th of July all. Anybody have plans? Mine here is staying home away from the virus. Still a nice 3 day weekend.
The project I am working on is going great at the moment. I'm hoping everyone is having as successful a time as I am. :)

Forum statistics

Threads
99,258
Messages
963,580
Members
130,850
Latest member
MarcusCryo
Top