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 ~
 
I haven't tested this, but it should work. I've assumed that your mouse script is a module Mouse, and you locate the position with Mouse.x and Mouse.y. Additionally, this checks for mouse clicks with Mouse.left. The windows might not be in the best places, either. If you're creative, it's easy to figure out which numbers affect the positions of the windows (they're in Window_Message)

Code:
#--------------------------------------------------------------------------
# * Is the mouse within this rect?
#--------------------------------------------------------------------------
def Mouse.in_area?(rect = Rect.new(0, 0, 640, 480))
  return ((Mouse.x - rect.x).between?(0, rect.width) and
          (Mouse.y - rect.y).between?(0, rect.height))
end

class Window_Button
  def initialize(x, y, text)
    width = Bitmap.new(32, 32).text_size(text)
    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.x = x + 8
    @text.y = y + 8
  end
  def update
    super
    # Check for click
    return (self.visible and Mouse.left and in_area?)
  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
  alias_method :meu_window_message_visible=, :visible=
  def initialize
    meu_window_message_initialize
    @save_window = Window_Button.new(self.x + 304, self.y - 24, "Save")
    @save_window.visible = false
    @load_window = Window_Button.new(self.x + 384, self.y - 24, "Load")
    @load_window.visible = false
  end
  def update
    $scene = Scene_Save.new if @save_window.update
    $scene = Scene_Load.new if @load_window.update
    meu_window_message_update
  end
  def dispose
    meu_window_message_dispose
    @save_window.dispose
    @load_window.dispose
  end
  def visible=(value)
    meu_window_message_visible = value
    @save_window = value
    @load_window = value
  end
end
 
Ahh thanks. Will try it and tell you what did I get. ^^

EDIT: Ahh I tried it but it gives me a Syntax Error on line 64. And hmm, I don't think my mouse is a module mouse.
 
Did you put the script below your mouse input?
If yes: What is the constant in your mouse input script that covers the cursor? Just replace "Mouse" with that.
If same: Mouse isn't decalered somewhere and it would be in your mouse input script.
 
Then here , this should work for you:

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.x = x + 8
    @text.y = y + 8
  end
  def update
    super
    # Check for click
    return (self.visible and Mouse.left and in_area?)
  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
  alias_method :meu_window_message_visible=, :visible=
  def initialize
    meu_window_message_initialize
    @save_window = Window_Button.new(self.x + 304, self.y - 24, "Save")
    @save_window.visible = false
    @load_window = Window_Button.new(self.x + 384, self.y - 24, "Load")
    @load_window.visible = false
  end
  def update
    $scene = Scene_Save.new if @save_window.update
    $scene = Scene_Load.new if @load_window.update
    meu_window_message_update
  end
  def dispose
    meu_window_message_dispose
    @save_window.dispose
    @load_window.dispose
  end
  def visible=(value)
    meu_window_message_visible = value
    @save_window = value
    @load_window = value
  end
end
 
Ah. My problem, then. The line that read:
width = Bitmap.new(32, 32).text_size(text)
Should be:
width = Bitmap.new(32, 32).text_size(text).width

I've updated the post with the fixed button. And you don't have to put this in the same script as the mouse system, it would be fine to put it in a new slot.
 
Change the line 'class Window_Button' to 'class Window_Button < Window_Base'. Now THAT was sloppy. I'll change it in my post. And remember what I said about providing the line with the error?
 
Gosh, now I am feeling like giving up.

On line 24 it says: super(x, y, width + 16, height + 16)

I've changed it but now it gives me this error:

71841224fm0.png


On line 272 it says: rx = $mousex - (@real_x / 4 + 16)
 
Now that one, I don't think is my fault. I'm wondering why it never did this before, actually. You should move those lines as such:

Before:
Code:
  def update
   
    rx = $mousex - (@real_x / 4 + 16)
    ry = $mousey - (@real_y / 4 + 16)  
    
    # if an arrow key is pressed, stop path finding
    $move = 0 if Input.dir4 != 0
    
    # move to a specified area on the map, using the mouse
    if $move == 1
        unless moving? or $game_system.map_interpreter.running? or
           @move_route_forcing or $game_temp.message_window_showing or
           (rx.abs <= 16 and ry.abs <= 16)
          rad = -(Math.atan2(ry, rx) / Math::PI * 180)
          case rad
After:
Code:
  def update
   
    # if an arrow key is pressed, stop path finding
    $move = 0 if Input.dir4 != 0
    
    # move to a specified area on the map, using the mouse
    if $move == 1
      rx = $mousex - (@real_x / 4 + 16)
      ry = $mousey - (@real_y / 4 + 16)  
      
        unless moving? or $game_system.map_interpreter.running? or
           @move_route_forcing or $game_temp.message_window_showing or
           (rx.abs <= 16 and ry.abs <= 16)
          rad = -(Math.atan2(ry, rx) / Math::PI * 180)
          case rad
 
I'm going to have to try and test this more thoroughly, it's obvious there's a deeper error lurking here. I'll get back to you when I've got the answers (now that I have your mouse system).

Are there any other scripts you're using?
 

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