Save-Point
Auto-Sizing Text Windows - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Material Development (https://www.save-point.org/forum-8.html)
+--- Forum: Scripts Database (https://www.save-point.org/forum-39.html)
+---- Forum: RPGMaker XP (RGSS) Engine (https://www.save-point.org/forum-116.html)
+---- Thread: Auto-Sizing Text Windows (/thread-2758.html)



Auto-Sizing Text Windows - RPG Advocate - 03-02-2008

Auto-Sizing Text Windows
by RPG Advocate
saved from Phylomortis.Com


Introduction
This script adds the ability to show text windows whose dimensions conform to the text inside them. The width of the window is determined by the width of the longest line. The height is determined by the number of lines. To use this script, just add the Window_Autosize class provided after all the other window classes. The way the text box is a bit cumbersome. You initialize the window with an array of lines. The class does the processing from there. Please don't initialize the window with an empty array. This will cause the game to show an error message, as shown in the script. Also, be aware that the initial x and y coordinate of 0 are just dummy values. To use this script effectively, you should either specify explicit x and y coordinates for the window or create an algorithm to determine them, if you need to display the window in a different location depending on the circumstances.


Script
AutoSizing Text Windows



RE: Auto-Sizing Text Windows - xnadvance - 06-02-2011

is this for vx or xp?


RE: Auto-Sizing Text Windows - Charlie Fleed - 06-02-2011

I'm pretty sure this was made for xp.


RE: Auto-Sizing Text Windows - sagam12 - 06-09-2011

nice script but how do you get the x and y coordinates for the window to resize itself? Its just got 0 dummy coordinates, some help please, thanks


RE: Auto-Sizing Text Windows - NightOwl - 06-09-2011

Quote:Also, be aware that the initial x and y coordinate of 0 are just dummy values. To use this script effectively, you should either specify explicit x and y coordinates for the window or create an algorithm to determine them, if you need to display the window in a different location depending on the circumstances.

In a nutshell, the window is defaulted to the top left corner of the screen as (like you said) the x and y position is set to 0,0. Either you can replace the x/y values of 0,0 with values as noted here...
From
Code:
super(0, 0, w, h)
to
Code:
super(20, 40, w, h)

Or better yet, replace them with variables like x and y, and edit the initialization method to match:
Code:
#--------------------------------------------------------------------------
  # * Object Initialization
  #     x     : x-position
  #     y     : y-position
  #     lines : lines
  #--------------------------------------------------------------------------
  def initialize(x,y,lines)
and
Code:
super(x, y, w, h)




RE: Auto-Sizing Text Windows - sagam12 - 06-10-2011

hey thanks for that but it doesnt do anything :S

can you test it for me and see if you can it to work?
and maybe show a screenshot if it does work, thanks xD


RE: Auto-Sizing Text Windows - DerVVulfman - 06-10-2011

Okay... this is the rewrite of the initialize method I mentioned:
Code:
def initialize(x,y,lines)
    @lines = []
    @lines = lines
    @line_width = []
    if @lines.size == 0
      print("Error: Auto-sizing windows must have at least one line")
      exit
    end
    @tester = Window_Base.new(0, 0, 640, 480)
    @tester.contents = Bitmap.new(@tester.width - 32, @tester.height - 32)
    @tester.contents.font.name = "Arial"
    @tester.contents.font.size = 18
    max = 0
    for i in 0..@lines.size - 1
      t = @lines[i]
      @line_width[i] = @tester.contents.text_size(t).width
      if @line_width[i] > max
        max = @line_width[i]
      end
    end
    w = max + 40
    h = @lines.size + 1
    h *= 32
    @tester.dispose
    super(x, y, w, h)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = "Arial"
    self.contents.font.size = 18
    refresh
  end

And this is a map event 'Script Call' I wrote.
Code:
Window_Autosize.new(20,20,
["Here","There"])

Rather than the window showing up at 0,0, it shows up at 20,20 (in pixels). The window resizes to fit the text... two small one-word lines.


RE: Auto-Sizing Text Windows - sagam12 - 06-10-2011

Thanks i got it to work, but the message stays on the screen for a few seconds and then disappears, also it only shows in the top right screen. Its just a script message its not the actual 'show message' text, i need the autosize in the show message window not as a script, or is this script only for script messages?? Your help is much obliged :D


RE: Auto-Sizing Text Windows - DerVVulfman - 06-11-2011

Again, I only set a position of just 20 x 20 in that sample event code. If I wanted it near the bottom left, I coulda used 600 and 400 instead of 20 and 20.
Code:
Window_Autosize.new(600,400,
["Here","There"])
It's all based on a 640x480 pixel area.

The script was written in 2005 and was a basis that people used for their own custom message systems. It could be inserted into a custom message script if one knows what they're doing. By itself, it does make for a nice popup window.

Actually, that was unexpected. Guess I don't have to look for one.

There are other message scripts that have such a function. Personally, I use the UMS (Universal Message System) by ccoa. You can find both RPGMaker XP and RPGMaker VX versions in this forum. You can also check out the Forum Scripts Listings thread (stickied in here) that gives you an index of all the scripts we have... including message scripts.


RE: Auto-Sizing Text Windows - sagam12 - 06-11-2011

thanks for all your help, i managed to use the UMS instead, its alot easier and has more functions.