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.

Cursor Script fix

I'm currently using this cursor script, by Selwyn. It works fine, except that it doesn't show up during Scene_load and Scene_Save, thus making it impossible to see which file your saving into. If someone can look into it and see what the problem is, I'd be very grateful.

Code:
#==============================================================================
# â–  Cursor Script
#------------------------------------------------------------------------------
#  Script to display a cursor instead of a highlight box
#   by Selwyn
#   selwyn@rmxp.ch
#==============================================================================

#==============================================================================
# â–  Cursor_Sprite
#==============================================================================

class Sprite_Cursor < Sprite
  #--------------------------------------------------------------------------
  # ● instances
  #--------------------------------------------------------------------------
  attr_accessor :true_x
  attr_accessor :true_y
  #--------------------------------------------------------------------------
  # ● initialize
  #--------------------------------------------------------------------------
  def initialize(x = 0, y = 0)
    super()
    self.x = @true_x = x
    self.y = @true_y = y
    self.z = 10000
    self.bitmap = RPG::Cache.windowskin("cursor2") rescue Bitmap.new(32, 32)
  end
  #--------------------------------------------------------------------------
  # ● update
  #--------------------------------------------------------------------------
  def update
    super
    
    if self.y < @true_y
      n = (@true_y - self.y) / 3
      n = 1 if n == 0
      self.y += n
    elsif self.y > @true_y
      n = (self.y - @true_y) / 3
      n = 1 if n == 0
      self.y -= n
    end

    if self.x < @true_x
      n = (@true_x - self.x) / 3
      n = 1 if n == 0
      self.x += n
    elsif self.x > @true_x
      n = (self.x - @true_x) / 3
      n = 1 if n == 0
      self.x -= n
    end
  end
end

#==============================================================================
# â–  Window_Selectable
#==============================================================================

class Window_Selectable < Window_Base
  #--------------------------------------------------------------------------
  # ● instances
  #--------------------------------------------------------------------------
  attr_reader   :index
  attr_reader   :help_window
  attr_accessor :cursor
  alias update_cursor_moves update
  #--------------------------------------------------------------------------
  # ● initialize
  #--------------------------------------------------------------------------
  def initialize(x, y, width, height)
    super(x, y, width, height)
    @item_max = 1
    @column_max = 1
    @index = -1
    @cursor = Sprite_Cursor.new(x, y)
    update_cursor
  end
  #--------------------------------------------------------------------------
  # ● x=
  #--------------------------------------------------------------------------
  def x=(x)
    super
    @cursor.x = x if !@cursor.nil?
  end
  #--------------------------------------------------------------------------
  # ● y=
  #--------------------------------------------------------------------------
  def y=(y)
    super
    @cursor.y = y if !@cursor.nil?
  end
  #--------------------------------------------------------------------------
  # ● visible=
  #--------------------------------------------------------------------------
  def visible=(visible)
    super
    if !@cursor.nil? and visible == false
      @cursor.visible = false
    end
  end
  #--------------------------------------------------------------------------
  # ● dispose
  #--------------------------------------------------------------------------
  def dispose
    @cursor.dispose
    super
  end
  #--------------------------------------------------------------------------
  # ● update_cursor_rect
  #--------------------------------------------------------------------------
  def update_cursor_rect
    if @index < 0
      self.cursor_rect.empty
      return
    end
    row = @index / @column_max
    if row < self.top_row
      self.top_row = row
    end
    if row > self.top_row + (self.page_row_max - 1)
      self.top_row = row - (self.page_row_max - 1)
    end
    cursor_width = self.width / @column_max - 32
    x = @index % @column_max * (cursor_width + 32)
    y = @index / @column_max * 32 - self.oy
    self.cursor_rect.set(x, y, cursor_width, 32)
  end
  #--------------------------------------------------------------------------
  # ● update_cursor
  #--------------------------------------------------------------------------
  def update_cursor
    @cursor.true_x = self.cursor_rect.x + self.x - 8
    @cursor.true_y = self.cursor_rect.y + self.y + 16
    @cursor.update
    @cursor.visible = (self.visible and self.index >= 0)
  end
  #--------------------------------------------------------------------------
  # ● update
  #--------------------------------------------------------------------------
  def update
    update_cursor_moves
    update_cursor
  end
end

Thank you
 

Anonymous

Guest

First add this to the initialize method of Window_SaveFile:

Code:
    @cursor = Sprite.new
    @cursor.bitmap = RPG::Cache.picture("cursor")
    @cursor.z = 10000
    @cursor.x = x
    @cursor.y = y + 24
    @cursor.visible = false

Before the refresh method call (I'd just put it at the top, right after the call to super).

Add this dispose method:

Code:
  def dispose
    super
    @cursor.dispose
  end

Replace the method selected= with this:

Code:
  def selected=(selected)
    @selected = selected
    update_cursor
  end

And add this method:

Code:
  def update_cursor
    if @selected
      @cursor.visible = true
    else
      @cursor.visible = false
    end
  end
 

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