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.

Save/Load Buttons on WindowSkin Script Request

Hi all,

Long time no see. It's been a long while since I have came here last time. I have been busy and all but I am hopefully back now. (Love the new layout, btw. The smilies are cute. ^^)

So I have been looking for CG online and came through Seinarukana : The spirit of the eternity sword HCG. It was pretty nice and I loved it very much. So I decided to make a freeware (I can't make it commercial anyway) visual novel out of it, giving credits to Xuse of course.

So I want a little (Not sure if it's simple) script for this visual novel. I am not sure whether it's really simple or not but I'd really appreciate if someone would it for me.

Basically, I'd like if there were a save and a load button on the windowskin. I use a simple mouse system so I want a save and a load button on the windowskin to be clicked on. Below a screenshot to explain:

examplejl3.png


Hopefully, I am detailed enough. If you need anymore details, please tell me and I'll put it for you right away.

Thank you very much ~
 
This should work better:

Code:
module Mouse
  def self.x
    return Input.pos[0]
  end
  def self.y
    return Input.pos[1]
  end
  def self.left
    return Input.mouse_press?(0)
  end
  #--------------------------------------------------------------------------
  # * Is the mouse within this rect?
  #--------------------------------------------------------------------------
  def self.in_area?(rect = Rect.new(0, 0, 640, 480))
    return ((self.x - rect.x).between?(0, rect.width) and
            (self.y - rect.y).between?(0, rect.height))
  end
end

class Window_Button < Window_Base
  def initialize(x, y, text)
    width = Bitmap.new(32, 32).text_size(text).width
    height = 32
    super(x, y, width + 16, height + 16)
    self.opacity = 160
    @text = Sprite.new
    @text.bitmap = Bitmap.new(width, height)
    @text.bitmap.draw_text(0, 0, width, height, text)
    @text.visible = false
  end
  def update
    @text.visible = self.visible
    @text.x = x + 8
    @text.y = y + 8
    @text.z = z + 8
    super
    # Check for click
    return (self.visible and Mouse.left and in_area?)
  end
  def dispose
    super
    @text.dispose
  end
  #--------------------------------------------------------------------------
  # Check if the mouse cursor is in the given area of the window
  #  in_area?(in_contents)
  #  in_area?(rect)
  #  in_area?(rect, in_contents)
  #  in_area?(x, y, width, height)
  #  in_area?(x, y, width, height, in_contents)
  #--------------------------------------------------------------------------
  def in_area?(*args)
    in_contents = false
    in_contents = args.pop if (args.size == 1 and !args[0].is_a?(Rect)) or
                              args.size == 2 or args.size == 5
    case args.size
    when 0
      rect = Rect.new(0, 0, self.width, self.height)
    when 1
      rect = args[0].dup if args[0].is_a?(Rect)
    when 4
      rect = Rect.new(*args)
    else
      raise ArgumentError.new
    end
    if in_contents # Searching within the window's contents
      rect.x += self.margin - self.ox
      rect.y += self.margin - self.oy
      rect.width = [rect.width, self.width - rect.x - self.margin].min
      rect.height = [rect.height, self.height - rect.y - self.margin].min
    else
      rect.width = [rect.width, self.width - rect.x].min
      rect.height = [rect.height, self.height - rect.y].min
    end
    rect.x += self.x
    rect.y += self.y
    return Mouse.in_area?(rect)
  end
end

class Window_Message
  alias_method :meu_window_message_initialize, :initialize
  alias_method :meu_window_message_update, :update
  alias_method :meu_window_message_dispose, :dispose
  def initialize
    meu_window_message_initialize
    @save_window = Window_Button.new(self.x + 304, self.y - 24, "Save")
    @save_window.visible = false
    @save_window.z = self.z
    @load_window = Window_Button.new(self.x + 384, self.y - 24, "Load")
    @load_window.visible = false
    @load_window.z = self.z
    self.z -= 1
  end
  def update
    @save_window.visible = self.visible
    @load_window.visible = self.visible
    $game_temp.save_calling = true if @save_window.update
    $scene = Scene_Load.new(Scene_Map) if @load_window.update
    meu_window_message_update
  end
  def dispose
    meu_window_message_dispose
    @save_window.dispose
    @load_window.dispose
  end
end

class Scene_Load
  alias_method :meu_scene_load_initialize, :initialize
  def initialize(final = Scene_Title)
    @final = final
    meu_scene_load_initialize
  end
  #--------------------------------------------------------------------------
  # * Cancel Processing
  #--------------------------------------------------------------------------
  def on_cancel
    # Play cancel SE
    $game_system.se_play($data_system.cancel_se)
    # Switch to title screen
    $scene = @final.new
  end
end

However, the game crashes when you press escape from the load menu. This is because it creates a new Scene_Map, but $game_temp.message_window_showing is still true. I'll fix this later, I have to get off my computer before it runs out of juice. It will involve my special baby, the layering scene class (I feel like I'm injecting it everywhere, but it's so useful for situations like this!)
 

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