Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: shintashi on October 16, 2011, 05:03:47 pm

Title: alternate font size for battle command? [XP]
Post by: shintashi on October 16, 2011, 05:03:47 pm
I've tried messing with the font size for the command window in and out of battle and it's given me nothing but bad mojo. Stuff like

    self.contents.font.size = 24



    self.bitmap.font.size = 24


crashes or gets ignored, and trying to implement
    
if $game_temp.in_battle
#any command whatsoever, even blank space...
end


inside Window_Command was met with a quick and unpleasant "wtf do you think you are doing?" crash.

I can add new commands in battle, but I don't seem to be able to shrink the font size and arrangement. I'd like to keep the window size the same.
Title: Re: alternate font size for battle command? [XP]
Post by: KK20 on October 16, 2011, 05:51:00 pm
You should try clarifying a bit more by what you want fixed. I did this in Window_Command:
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #     color : text color
  #--------------------------------------------------------------------------
  def draw_item(index, color)
    self.contents.font.color = color
    rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.font.size = 18
    self.contents.draw_text(rect, @commands[index])
  end
And that reduced the size of the "Attack, Skills, Items, Defend" commands in battle. It also changes the font size of the title screen window.
Title: Re: alternate font size for battle command? [XP]
Post by: ForeverZer0 on October 16, 2011, 05:53:49 pm
class Window_Command
 
 alias battle_font_refresh refresh
 def refresh
   if $game_temp.in_battle
     self.contents.font.name = 'Calibri'
     self.contents.font.size = 12
   end
   battle_font_refresh
 end
end


The KK20's will try to change the font every time a item is drawn, this way it happens only when the window is refreshed, which is the only way to alias it correctly without the need to over-write a method.
Title: Re: alternate font size for battle command? [XP]
Post by: KK20 on October 16, 2011, 06:05:57 pm
Actually, yeah, the whole '$game_temp.in_battle' throws errors. It's because $game_temp isn't initialized BEFORE the title screen's window pops up. So, to combat this, I added $game_temp = Game_Temp.new in 'Main', right below 'begin'. F0's edit then worked.
Title: Re: alternate font size for battle command? [XP]
Post by: ForeverZer0 on October 16, 2011, 06:27:41 pm
Oops, forgot about window command being used on the title as well.
You can simply check to see if it is defined instead of initializing the class, or simple check the scene instead...

if $scene.is_a?(Scene_Battle)
Title: Re: alternate font size for battle command? [XP]
Post by: shintashi on October 17, 2011, 09:36:43 pm
I'm glad I'm not the only one running into this game temp/opening error, but where does this:

if $scene.is_a?(Scene_Battle)


go? is it a rewrite of


class Window_Command
 
  alias battle_font_refresh refresh
  def refresh
    if $game_temp.in_battle
      self.contents.font.name = 'Calibri'
      self.contents.font.size = 12
    end
    battle_font_refresh
  end
end


and can I stick it the normal command window, or does it belong above main?
Title: Re: alternate font size for battle command? [XP]
Post by: Fantasist on October 17, 2011, 09:52:52 pm
Kind of. Instead of checking for $game_temo, which might or might not be created already, you check for $scene.is_a?, which will work as long as Ruby works. So:

class Window_Command
 
  alias battle_font_refresh refresh
  def refresh
    if $scene.is_a?(Scene_Battle)
      self.contents.font.name = 'Calibri'
      self.contents.font.size = 12
    end
    battle_font_refresh
  end
end


Now that I think about it, changing the font size alone wont give you any extra room. The cursor rect will still be big. Try this instead:


#==============================================================================
# ** Window_BattleCommand
#==============================================================================

class Window_BattleCommand < Window_Selectable
  #--------------------------------------------------------------------------
  # * Start Config
  #--------------------------------------------------------------------------
  FONTNAME = 'Calibri'
  FONTSIZE = 18
  #--------------------------------------------------------------------------
  # * End Config
  #--------------------------------------------------------------------------
  LINEHEIGHT = FONTSIZE + 4
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(width, commands)
    super(0, 0, width, commands.size * LINEHEIGHT + 32)
    @item_max = commands.size
    @commands = commands
    self.contents = Bitmap.new(width - 32, @item_max * LINEHEIGHT)
    self.contents.font.name = FONTNAME
    self.contents.font.size = FONTSIZE
    refresh
    self.index = 0
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    for i in 0...@item_max
      draw_item(i, normal_color)
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #     color : text color
  #--------------------------------------------------------------------------
  def draw_item(index, color)
    self.contents.font.color = color
    rect = Rect.new(4, LINEHEIGHT * index, self.contents.width - 8, LINEHEIGHT)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, @commands[index])
  end
  #--------------------------------------------------------------------------
  # * Get Top Row
  #--------------------------------------------------------------------------
  def top_row
    return self.oy / LINEHEIGHT
  end
  #--------------------------------------------------------------------------
  # * Set Top Row
  #--------------------------------------------------------------------------
  def top_row=(row)
    row = 0 if row < 0
    (row = row_max - 1) if (row > row_max - 1)
    self.oy = row * LINEHEIGHT
  end
  #--------------------------------------------------------------------------
  # * Get Number of Rows Displayable on 1 Page
  #--------------------------------------------------------------------------
  def page_row_max
    return (self.height - 32) / LINEHEIGHT
  end
  #--------------------------------------------------------------------------
  # * Update Cursor Rectangle
  #--------------------------------------------------------------------------
  def update_cursor_rect
    super
    battle_font_cursor_rect
    y = @index / @column_max * LINEHEIGHT - self.oy
    self.cursor_rect.y = y
    self.cursor_rect.height = LINEHEIGHT
  end
  #--------------------------------------------------------------------------
  # * Disable Item
  #     index : item number
  #--------------------------------------------------------------------------
  def disable_item(index)
    draw_item(index, disabled_color)
  end
end

class Scene_Battle
 
  alias battle_font_prep start_phase1
  def start_phase1
    unless @actor_command_window.is_a?(Window_BattleCommand)
      # Make actor command window
      s1 = $data_system.words.attack
      s2 = $data_system.words.skill
      s3 = $data_system.words.guard
      s4 = $data_system.words.item
      @actor_command_window = Window_BattleCommand.new(160, [s1, s2, s3, s4])
      @actor_command_window.y = 160
      @actor_command_window.back_opacity = 160
      @actor_command_window.active = false
      @actor_command_window.visible = false
    end
    battle_font_prep
  end
 
end


Title: Re: alternate font size for battle command? [XP]
Post by: shintashi on October 23, 2011, 01:48:41 pm
I was looking at the test in the shintashi.exe and it sort of hovers - that's easy enough to fix, but I think I'll try playing around with the right fonts for a bit before messing with it further, since I'm only partially done with editing my actor commands (the most complicated is already done but not interfaced with battle equations yet).

 
Title: Re: alternate font size for battle command? [XP]
Post by: Fantasist on October 23, 2011, 11:41:57 pm
Hovers? Didn't get you. Anyway, good luck :)