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.

Multi-line text windows (with bonus Dispose method question!)

I'm extending the Window_Command class to show a list of topics the player can browse through - you select a command and it pulls up a new window with detailed information on what that command does. However, I've got a few problems with it...

http://i192.photobucket.com/albums/z164 ... 2_4942.jpg[/IMG]

The text doesn't align properly, or parse newline characters the way I want it to. These two are probably related, since my strings are pretty long with newline characters every 42 characters (or less). Text should be in the top-right corner, and there should be a newline before every number. Also, note that the super-cool selection box is overlapping onto my new window.

Also,

http://i192.photobucket.com/albums/z164 ... 2_4947.jpg[/IMG]

The window doesn't go away when it should!

Here's a look at my script. It takes the command index in, and looks up the appropriate text in an array. For debugging purposes, I've just set @display to default text that showcases my problems. I'm sure that I've made a host of stupid mistakes, partially because I'm still trying to figure out scoping in Ruby and partially because all of the code I've put together is hacked from existing game code and what relevant tutorials I've found floating around these forums.

PHP:
class Repository_Topics < Window_Base
def initialize(i)
		height = 448 #max number of lines * 32
		@display = "1blah blah blah blah \n 2blah blah blah\n 3blah"
		super(160,0, 42*8, 448)
		self.contents = Bitmap.new(42*8 - 32, 448 - 32)
		refresh
end
	def refresh
		self.contents.clear
		self.contents.font.color = normal_color
		self.contents.font.size = 20
		self.contents.draw_text(0, 0, 42*8, 448, @display)
    if Input.trigger?(Input::B)
			$game_system.se_play($data_system.cancel_se)
      self.dispose
    end
	end
	
end
 
Diedrupo;259036 said:
Have you tried adding an input trigger for the C button? That's usually the one used for actions, B is used for canceling.
This wasn't the answer, but it led me to the problem, so thanks! :)
The issue was basically this: In the command window I had this function to call the new window:

PHP:
	def update
	# If B button was pressed
	    if Input.trigger?(Input::B) 
	      # Play cancel SE #on this planet
	      $game_system.se_play($data_system.cancel_se)
	      # Switch to map screen
	      $scene = Scene_Map.new
	      return
	    end
		if Input.trigger?(Input::C)
      # Choose a topic, create a new window to show data on that topic. 
      $game_system.se_play($data_system.decision_se)
      # Creates a new window that will draw the text of the topic selected
      @detailWindow = Repository_Topics.new(@command_window.index)
    end
		if Input.trigger?(Input::B)
			$game_system.se_play($data_system.cancel_se)
			@detailWindow.dispose
		end
  end

And like a complete dope, I didn't realize that I had two different if trigger?(B) statements. So I moved the second one up to the first, threw in some more conditional branching, and ended up with this correct code:

PHP:
if Input.trigger?(Input::B) 
	      # Play cancel SE 
        if @detailWindow == nil || @detailWindow.disposed?
          $game_system.se_play($data_system.cancel_se)
          # Switch to map screen 
          $scene = Scene_Map.new
        else
          $game_system.se_play($data_system.cancel_se)
          @detailWindow.dispose
        end
	      return
	    end

Now I just need to figure out why the newline character isn't working like I think it should! Who wants to put money on me using the frontslash as opposed to the backslash :(
 

ccoa

Member

The bitmap class doesn't handle newline characters. You'll need to draw the other lines 32 pixels farther down for each. Or else write a script that wraps the text when you reach the end of the window (that's actually not too hard).

Here's an example of the later solution:

Code:
    words = @item.description.split(" ")
    x = 0
    y = 0
    for word in words
      length = self.contents.text_size(word).width + 8
      if (x + length) >= self.contents.width
        x = 0
        y += 16
      end
      self.contents.draw_text(x, y, length, 32, word)
      x += length
    end
 
ccoa;259075 said:
The bitmap class doesn't handle newline characters. You'll need to draw the other lines 32 pixels farther down for each. Or else write a script that wraps the text when you reach the end of the window (that's actually not too hard).

It's wonderful little idiosyncrasies like this that make scripting such a joy :)

Thank you very much for the help, the script worked perfectly! Now the only problem is that weird transparent box overlap from the command menu spilling over onto the text box.

Or I could just move the text box over a couple of pixels, duh :-O
 

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