Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Using Icons in place of text in battle command window

Status
Not open for further replies.
How do I insert icons in place of the text. I went to Scene_Battle 1 and inserted this by s1.
x = 4
y = index * 32
rect = Rect.new(x, y, self.width - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
bitmap = RPG::Cache.icon("insert icon name here")

That didn't work.
 
Thanks, seph.

All right, I figured out how to replace the text with icons and ran into a new problem. First, here are the scripts that I'm using:

Code:
#==============================================================================
# ** Window_Command
#------------------------------------------------------------------------------
#  This window deals with general command choices.
#==============================================================================
class Window_Command < Window_Selectable
  attr_accessor :disabled
  #--------------------------------------------------------------------------
  # * Object Initialization
  #  width : window width
  #  commands : command text string array
  #--------------------------------------------------------------------------
  def initialize(width,a,type=nil,align = nil,b = nil,color = nil,icons = nil)
 if type.nil?
   @type = 0
 elsif !type.nil?
   @type = type
 end
 # Compute window height from command quantity
 case @type
 when 0
   super(0, 0, width, a.size * 32 + 32)
   @item_max = a.size
   self.contents = Bitmap.new(width - 32, @item_max * 32)
 when 1
   super(0, 0,width,80)
   @item_max = a.size
   @column_max = a.size
   self.contents = Bitmap.new(width - 32,height - 32)
 end
 @commands_a = a
 @disabled = []
 @cursor_status = true
 for i in 0..@item_max
   @disabled[i] = false
 end
 if align.nil?
   @alignment = 0
 elsif !align.nil?
   @alignment = align
 end
 if b.nil?
   @commands_b = []
   for i in 0..@commands_a.size
  @commands_b[i] = @commands_a[i]
   end
 else !b.nil?
   @commands_b = b
 end  
 if color.nil?
   @selected_color = normal_color
 elsif !color.nil?
   @selected_color = color
 end
 if icons.nil?
   @icon_status = false
 elsif !icons.nil?
   @icons = icons
   @icon_status = true
 end
 refresh
 self.index = 0
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
 self.contents.clear
 if @icon_status == true
   case @type
   when 0
  for i in 0..(@icons.size - 1)
    y = ((i * 32) + ((i + 1) * 4))
    draw_icon(@icons[i],4,y)
  end
   when 1
  command_width = (self.contents.width / @item_max)
  for i in 0..(@icons.size - 1)
    x = ((i * command_width) + ((i + 1) * 4))
    y = ((self.contents.height - 24) / 2)
    draw_icon(@icons[i],x,y)
  end
   end
 end
 for i in 0...@item_max
   if self.index == i
  draw_item(i, @selected_color,1,@alignment)
   elsif @disabled[i] == true
  draw_item(i, disabled_color,0,@alignment)
   elsif @index != i
  draw_item(i, normal_color,0,@alignment)
   end
 end
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #  index : item number
  #  color : text color
  #--------------------------------------------------------------------------
  def draw_item(index, color,type,alignment)
 case @type
 when 0
   if @icon_status == true
  x = 8 + 24
   elsif @icon_status == false
  x = 4
   end
   rect = Rect.new(x, 32 * index, self.contents.width - 36, 32)
   self.contents.font.color = color
   self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
   case type
   when 0
  self.contents.draw_text(rect, @commands_a[index],alignment)
   when 1
  self.contents.draw_text(rect, @commands_b[index],alignment)
   end
 when 1
   y = ((self.contents.height - 32) / 2)
   if @icon_status == true
  command_width = ((self.contents.width / @column_max) - 24 - 8)
  x = ((index * command_width) + ((index + 1) * (24 + 8)))
  rect = Rect.new(x,y,command_width - 24 - 8,32)
   elsif @icon_status == false
  command_width = ((self.contents.width / @column_max) - 4)
  x = ((index * command_width) + (index * 4))
  rect = Rect.new(x,y,command_width - 4,32)
   end
   self.contents.font.color = color
   self.contents.fill_rect(rect,Color.new(0,0,0,0))
   case type
   when 0
  self.contents.draw_text(rect,@commands_a[index],alignment)
   when 1
  self.contents.draw_text(rect,@commands_b[index],alignment)
   end
 end
  end
  #--------------------------------------------------------------------------
  # * Disable Item
  #  index : item number
  #--------------------------------------------------------------------------
  def disable_item(index)
 @disabled[index] = true
  end
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------
  def update
 refresh
 super
  end
  #--------------------------------------------------------------------------
  # * Disable Cursor
  #--------------------------------------------------------------------------
  def disable_cursor
 @cursor_status = false
  end
  #--------------------------------------------------------------------------
  # * Update Cursor
  #--------------------------------------------------------------------------
  def update_cursor_rect
 if @cursor_status == false
   self.cursor_rect.empty
   return
 end
 if @type == 0
   super
 else
   command_width = (self.contents.width / @item_max)
   x = @index * command_width
   y = ((self.contents.height - 24) / 2)#32
   self.cursor_rect.set(x, y, command_width, 24)#32
 end
  end
  #--------------------------------------------------------------------------
  # * Draw Icon
  #--------------------------------------------------------------------------
  def draw_icon(name,x,y)
 if name == ''
   return
 else
   bitmap = RPG::Cache.icon(name)
   w = 24
   h = 24
   src_rect = Rect.new(0, 0, w, h)
   self.contents.blt(x, y , bitmap, src_rect)
 end
  end
end
Code:
class Window_Base < Window  
  #--------------------------------------------------------------------------
  # * Draw Slant Bar(by SephirothSpawn)
  #--------------------------------------------------------------------------
  def draw_slant_bar(x, y, min, max, width = 152, height = 6,
      bar_color = Color.new(150, 0, 0, 255), end_color = Color.new(255, 255, 60, 255))
    # Draw Border
    for i in 0..height
      self.contents.fill_rect(x + i, y + height - i, width + 1, 1, Color.new(0 , 0, 0, 0))
    end
    # Draw Background
    for i in 1..(height - 1)
      r = 100 * (height - i) / height + 0 * i / height
      g = 100 * (height - i) / height + 0 * i / height
      b = 100 * (height - i) / height + 0 * i / height
      a = 255 * (height - i) / height + 255 * i / height
      self.contents.fill_rect(x + i, y + height - i, width, 1, Color.new(r, b, g, a))
    end
    # Draws Bar
    for i in 1..( (min / max.to_f) * width - 1)
      for j in 1..(height - 1)
        r = bar_color.red * (width - i) / width + end_color.red * i / width
        g = bar_color.green * (width - i) / width + end_color.green * i / width
        b = bar_color.blue * (width - i) / width + end_color.blue * i / width
        a = bar_color.alpha * (width - i) / width + end_color.alpha * i / width
        self.contents.fill_rect(x + i + j, y + height - j, 1, 1, Color.new(r, g, b, a))
      end
    end
  end
end


class Window_EnemyHP < Window_Base
  
  def initialize
    super(0, 0, 640, 480)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 0
    refresh
  end
  
  def refresh
    self.contents.clear
    for i in 0...$game_troop.enemies.size
      @enemy = $game_troop.enemies[i]
      @percent = (@enemy.hp * 100) / @enemy.maxhp
      unless @enemy.hp == 0
      draw_slant_bar(@enemy.screen_x - 55, @enemy.screen_y - 10, @enemy.hp, @enemy.maxhp, width = 75, height = 3, bar_color = Color.new(140, 0, 0, 255), end_color = Color.new(220, 0, 0, 255))
    end
  end
end  
end
 
class Scene_Battle
  
  alias raz_update update
  alias raz_update_phase5 update_phase5
  alias raz_update_phase4_step1 update_phase4_step1
  alias raz_update_phase4_step5 update_phase4_step5
  
  def main
    # Initialize each kind of temporary battle data
    $game_temp.in_battle = true
    $game_temp.battle_turn = 0
    $game_temp.battle_event_flags.clear
    $game_temp.battle_abort = false
    $game_temp.battle_main_phase = false
    $game_temp.battleback_name = $game_map.battleback_name
    $game_temp.forcing_battler = nil
    # Initialize battle event interpreter
    $game_system.battle_interpreter.setup(nil, 0)
    # Prepare troop
    @troop_id = $game_temp.battle_troop_id
    $game_troop.setup(@troop_id)
    # Make actor command window
    s1 = ""
    s2 = ""
    s3 = ""
    s4 = ""
    @actor_command_window = Window_Command.new(174, [s1, s2, s3, s4], 1, 2, nil, nil, ['attack', 'skill', 'defend', 'item'])#**
    @actor_command_window.y = 0
    @actor_command_window.opacity = 0
    @actor_command_window.back_opacity = 0
    @actor_command_window.active = false
    @actor_command_window.visible = false
    # Make other windows
    @party_command_window = Window_PartyCommand.new
    @help_window = Window_Help.new
    @help_window.back_opacity = 160
    @help_window.visible = false
    @status_window = Window_BattleStatus.new
    @message_window = Window_Message.new
    # Make sprite set
    @spriteset = Spriteset_Battle.new
    @enemy_window = Window_EnemyHP.new
    @enemy_window.z = 95

    # Initialize wait count
    @wait_count = 0
    # Execute transition
    if $data_system.battle_transition == ""
      Graphics.transition(20)
    else
      Graphics.transition(40, "Graphics/Transitions/" +
        $data_system.battle_transition)
    end
    # Start pre-battle phase
    start_phase1
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Refresh map
    $game_map.refresh
    # Prepare for transition
    Graphics.freeze
    # Dispose of windows
    @actor_command_window.dispose
    @party_command_window.dispose
    @help_window.dispose
    @status_window.dispose
    @message_window.dispose
    @enemy_window.dispose
    if @skill_window != nil
      @skill_window.dispose
    end
    if @item_window != nil
      @item_window.dispose
    end
    if @result_window != nil
      @result_window.dispose
    end
    # Dispose of sprite set
    @spriteset.dispose
    # If switching to title screen
    if $scene.is_a?(Scene_Title)
      # Fade out screen
      Graphics.transition
      Graphics.freeze
    end
    # If switching from battle test to any screen other than game over screen
    if $BTEST and not $scene.is_a?(Scene_Gameover)
      $scene = nil
    end
  end
  
  def update
    @enemy_window.update
    raz_update
  end

  def update_phase5
    # If wait count is larger than 0
    if @phase5_wait_count > 0
      # Decrease wait count
      @phase5_wait_count -= 1
      # If wait count reaches 0
      if @phase5_wait_count == 0
        @enemy_window.visible = false
        # Show result window
        @result_window.visible = true
        # Clear main phase flag
        $game_temp.battle_main_phase = false
        # Refresh status window
        @status_window.refresh
        @enemy_window.refresh
      end
      return
    end
   raz_update_phase5
 end

def update_phase4_step1
  raz_update_phase4_step1
  @enemy_window.refresh
end

  def update_phase4_step5
    # Hide help window
    @help_window.visible = false
    # Refresh status window
    @status_window.refresh
    @enemy_window.refresh
    raz_update_phase4_step5 
  end
end
Code:
#==============================================================================
# ++ 矢印型セレクトカーソル ver. 1.12 ++
#  Script by パラ犬
#  http://2d6.parasite.jp/
#------------------------------------------------------------------------------
# コマンド選択時のカーソルを任意の画像にします。
#==============================================================================

module PARA_LEFT_CURSOR
  
  # カーソル画像ファイル名(「Graphics/Windowskin」フォルダ内)
  FILE_NAME = "cursor"

  # 表示タイプ( 0:矢印のみ 1:矢印+四角カーソル )
  TYPE = 0

end

# ↑ 設定項目ここまで
#------------------------------------------------------------------------------

#==============================================================================
# â–  Window_Base
#==============================================================================

class Window_Base
  #--------------------------------------------------------------------------
  # ● カーソルの矩形更新
  #--------------------------------------------------------------------------
  alias cursor_rect_para_lcr cursor_rect
  def cursor_rect=(rect)
    if PARA_LEFT_CURSOR::TYPE == 1
      super(rect)
    end
    empty = Rect.new(0,0,0,0)
    if rect != empty and self.visible != false and @index != -1
      if @cursor == nil or @cursor.disposed?
        # スプライトを作成
        @cursor = Sprite.new
        @cursor.bitmap = RPG::Cache.windowskin(PARA_LEFT_CURSOR::FILE_NAME)
      end
      # カーソルスプライトの位置を移動
      @cursor.x = self.x + rect.x
      cy = (rect.height-24) / 2
      @cursor.y = self.y + cy + rect.y + 12
      @cursor.z = self.z + 2
    elsif @cursor != nil
      @cursor.dispose
    end
  end
  #--------------------------------------------------------------------------
  # ● 解放
  #--------------------------------------------------------------------------
  alias dispose_para_cur dispose
  def dispose
    super
    if @cursor != nil
      @cursor.dispose
    end
  end
  #--------------------------------------------------------------------------
  # ● self.visible
  #--------------------------------------------------------------------------
  def visible=(bool)
    super
    # ウインドウが不可視の時はカーソルを消去
    if @cursor != nil and bool == false
      @cursor.dispose
    end
  end
  #--------------------------------------------------------------------------
  # ● self.x
  #--------------------------------------------------------------------------
  def x=(x)
    super
    if @index != nil
      # カーソルの矩形を更新
      update_cursor_rect
    end
  end
  #--------------------------------------------------------------------------
  # ● self.y
  #--------------------------------------------------------------------------
  def y=(y)
    super
    if @index != nil
      # カーソルの矩形を更新
      update_cursor_rect
    end
  end
end

Here's the problem. Take a look at the position of the white hand cursor in both screens.

http://i145.photobucket.com/albums/r228 ... eicon1.png[/IMG]

http://i145.photobucket.com/albums/r228 ... eicon2.png[/IMG]

You'll notice that the cursor gets progressively farther away from the icon it's supposed to be next to as it goes across the list of commands. I did find that if I extend the width of the window, it sort of evens itself out, but then the icons are spread out too far from each other.

The second thing I would like is to have the icons centered over the player's head like so:

http://i145.photobucket.com/albums/r228 ... ofhead.png[/IMG]

If you are willing to help me, I can send you an unencrypted file. I have other scripts that might be interfering. Thanks for taking the time to read this.
 
Here is a demo with all the scripts that I am using.

demo link removed - outdated

If you are going to help me, please identify the parts of the scripts that you modified within the actual scripts. Thanks.
 
I'm now using Selwyn's cursor script which can be found here.

http://www.rmxp.org/forums/showthread.php?t=738

I still would like to know how to make the cursor closer to the icon it's supposed to be next to. I'm assuming it has something to do with the distance between the icons.

Also, I'm not sure what I'm supposed to change to move the actor command window above the head. There's a line of code that says: @actor_command_window.y = 0 and when I changed the 0, nothing happened. I even added @actor_command_window.x = 0 and messed around with the numbers and still, nothing happened. I'm pretty sure I need to change the x and y coordinates but I don't see those coordinates in the command windows script. Well, there is one, but I believe that would change the coordinates for all the command windows, which I don't want to change. I only want to change the xy coordinates in the actor command window in the battle scene. Also, I'm making the changes via Raziel's enemy bar script instead of in battle_scene 1.
 
Okay, it's been a while and I have been able to figure out most of what I needed except for one thing. I still would like for the actor command window to be centered above the player.

Here is what my battle screen currently looks like.
http://i145.photobucket.com/albums/r228 ... rigina.jpg[/IMG]

Here is what I would like for it to look like. Created in Graphics Gale.
http://i145.photobucket.com/albums/r228 ... hicons.png[/IMG]

I have been modifying the command window in two places. The first script is Tsunokiette's Advanced Command Windows which actually replaces my default command window. I edited all the parts under the "when 1" statements.
Code:
#==============================================================================
# ** Window_Command
#------------------------------------------------------------------------------
#  This window deals with general command choices.
#==============================================================================
class Window_Command < Window_Selectable
  attr_accessor :disabled
  #--------------------------------------------------------------------------
  # * Object Initialization
  #  width : window width
  #  commands : command text string array
  #--------------------------------------------------------------------------
  def initialize(width,a,type=nil,align = nil,b = nil,color = nil,icons = nil)
 if type.nil?
   @type = 0
 elsif !type.nil?
   @type = type
 end
 # Compute window height from command quantity
 case @type
 when 0
   super(0, 0, width, a.size * 32 + 32)
   @item_max = a.size
   self.contents = Bitmap.new(width - 32, @item_max * 32)
 when 1
   super(0, 0,width,80)
   @item_max = a.size
   @column_max = a.size
   self.contents = Bitmap.new(width - 32,height - 32)
 end
 @commands_a = a
 @disabled = []
 @cursor_status = true
 for i in 0..@item_max
   @disabled[i] = false
 end
 if align.nil?
   @alignment = 0
 elsif !align.nil?
   @alignment = align
 end
 if b.nil?
   @commands_b = []
   for i in 0..@commands_a.size
  @commands_b[i] = @commands_a[i]
   end
 else !b.nil?
   @commands_b = b
 end  
 if color.nil?
   @selected_color = normal_color
 elsif !color.nil?
   @selected_color = color
 end
 if icons.nil?
   @icon_status = false
 elsif !icons.nil?
   @icons = icons
   @icon_status = true
 end
 refresh
 self.index = 0
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
 self.contents.clear
 if @icon_status == true
   case @type
   when 0
  for i in 0..(@icons.size - 1)
    y = ((i * 32) + ((i + 1) * 4))
    draw_icon(@icons[i],4,y)
  end
   when 1
  command_width = (self.contents.width / @item_max)
  for i in 0..(@icons.size - 1)
    x = ((i * command_width) + ((i + 1) * 1))#used to be 4
    y = ((self.contents.height - 24) / 2)
    draw_icon(@icons[i],x,y)
  end
   end
 end
 for i in 0...@item_max
   if self.index == i
  draw_item(i, @selected_color,1,@alignment)
   elsif @disabled[i] == true
  draw_item(i, disabled_color,0,@alignment)
   elsif @index != i
  draw_item(i, normal_color,0,@alignment)
   end
 end
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #  index : item number
  #  color : text color
  #--------------------------------------------------------------------------
  def draw_item(index, color,type,alignment)
 case @type
 when 0
   if @icon_status == true
  x = 8 + 24
   elsif @icon_status == false
  x = 4
   end
   rect = Rect.new(x, 32 * index, self.contents.width - 36, 32)
   self.contents.font.color = color
   self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
   case type
   when 0
  self.contents.draw_text(rect, @commands_a[index],alignment)
   when 1
  self.contents.draw_text(rect, @commands_b[index],alignment)
   end
 when 1
   y = ((self.contents.height - 32) / 2)
   if @icon_status == true
  command_width = ((self.contents.width / @column_max) - 24 - 8)
  x = ((index * command_width) + ((index + 1) * (24 + 8)))
  rect = Rect.new(x,y,command_width - 24 - 8,32)
   elsif @icon_status == false
  command_width = ((self.contents.width / @column_max) - 4)
  x = ((index * command_width) + (index * 4))
  rect = Rect.new(x,y,command_width - 4,32)
   end
   self.contents.font.color = color
   self.contents.fill_rect(rect,Color.new(0,0,0,0))
   case type
   when 0
  self.contents.draw_text(rect,@commands_a[index],alignment)
   when 1
  self.contents.draw_text(rect,@commands_b[index],alignment)
   end
 end
  end
  #--------------------------------------------------------------------------
  # * Disable Item
  #  index : item number
  #--------------------------------------------------------------------------
  def disable_item(index)
 @disabled[index] = true
  end
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------
  def update
 refresh
 super
  end
  #--------------------------------------------------------------------------
  # * Disable Cursor
  #--------------------------------------------------------------------------
  def disable_cursor
 @cursor_status = false
  end
  #--------------------------------------------------------------------------
  # * Update Cursor
  #--------------------------------------------------------------------------
  def update_cursor_rect
 if @cursor_status == false
   self.cursor_rect.empty
   return
 end
 if @type == 0
   super
 else
   command_width = (self.contents.width / @item_max)
   x = @index * command_width
   y = ((self.contents.height - 24) / 2)#32
   self.cursor_rect.set(x, y, command_width, 24)#32
 end
  end
  #--------------------------------------------------------------------------
  # * Draw Icon
  #--------------------------------------------------------------------------
  def draw_icon(name,x,y)
 if name == ''
   return
 else
   bitmap = RPG::Cache.icon(name)
   w = 24
   h = 24
   src_rect = Rect.new(0, 0, w, h)
   self.contents.blt(x, y , bitmap, src_rect)
 end
  end
end

The second script is Raziel's enemy bars with slant bars by SephirothSpawn.
Code:
    # Make actor command window
    s1 = ""
    s2 = ""
    s3 = ""
    s4 = ""
    @actor_command_window = Window_Command.new(132, [s1, s2, s3, s4], 1, 1, nil, nil, ['attack', 'skill', 'defend', 'item'])#**
    @actor_command_window.y = 0
    @actor_command_window.opacity = 0
    @actor_command_window.back_opacity = 0
    @actor_command_window.active = false
    @actor_command_window.visible = false
 
You should be able to use this (Sorry I was no help before).


Code:
class Scene_Battle
  alias_method :seph_aligncommand_scnbtl_p3scw, :phase3_setup_command_window
  def phase3_setup_command_window
    seph_aligncommand_scnbtl_p3scw
    @actor_command_window.x = @active_battler.screen_x - @actor_command_window.width / 2
    @actor_command_window.y = @active_battler.screen_y - 128
  end
end

You should be able to just tink with that 128 value, until it is above the sprite with the right distance. Let me know if you need anyhelp.
 
Status
Not open for further replies.

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top