Auto-Sizing Text Windows
#1
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
Reply }
#2
is this for vx or xp?

Reply }
#3
I'm pretty sure this was made for xp.
[Image: facebook_icon.png] [Image: youtube_128x128-120x120.png] [Image: deviant.png] [Image: save-point.png]
Reply }
#4
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
Reply }
#5
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)

DerVVulfman's 'regular Joe' account for testing and permissions use.
Who watches the Watchmen?
Reply }
#6
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
Reply }
#7
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.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)

[Image: QrnbKlx.jpg]
[Image: sGz1ErF.png]    [Image: liM4ikn.png]    [Image: fdzKgZA.png]    [Image: sj0H81z.png]
[Image: QL7oRau.png]    [Image: uSqjY09.png]    [Image: GAA3qE9.png]    [Image: 2Hmnx1G.png]    [Image: BwtNdKw.png%5B]
  Above are clickable links
Reply }
#8
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
Reply }
#9
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.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)

[Image: QrnbKlx.jpg]
[Image: sGz1ErF.png]    [Image: liM4ikn.png]    [Image: fdzKgZA.png]    [Image: sj0H81z.png]
[Image: QL7oRau.png]    [Image: uSqjY09.png]    [Image: GAA3qE9.png]    [Image: 2Hmnx1G.png]    [Image: BwtNdKw.png%5B]
  Above are clickable links
Reply }
#10
thanks for all your help, i managed to use the UMS instead, its alot easier and has more functions.
Reply }


Possibly Related Threads…
Thread Author Replies Views Last Post
   Text Scroll Script - Enhanced DerVVulfman 23 34,265 02-18-2021, 04:16 AM
Last Post: DerVVulfman
   Message Text from Files DerVVulfman 0 5,279 04-13-2016, 03:25 AM
Last Post: DerVVulfman
   Text Extraction Generator DerVVulfman 5 12,940 10-13-2014, 09:32 PM
Last Post: Narzew
   Text to RGSS DerVVulfman 10 25,598 05-04-2013, 04:34 AM
Last Post: DerVVulfman
   Auto Equip Optimizer for Guillaume777's MultiSlots DerVVulfman 1 6,965 06-20-2012, 03:26 PM
Last Post: buddysievers
   Damage Text Revamp 2.1 PK8 3 12,817 04-08-2012, 06:47 PM
Last Post: PK8
   Auto Populate Maps, Version 0.5 Charlie Fleed 14 27,002 03-17-2012, 03:04 PM
Last Post: LilyKnight
   Popup Windows deValdr 5 10,761 06-02-2011, 09:38 AM
Last Post: deValdr
   Another Scrolling Text Script kyonides 1 6,469 04-12-2010, 01:36 AM
Last Post: Shiroiyuki
   [Unsupported] Auto Tone PK8 0 5,326 12-07-2008, 03:06 PM
Last Post: PK8



Users browsing this thread: 1 Guest(s)