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.

Window_Speaker (custom class) assistance needed

Hey, everyone...it's been a while since I've posted anything here. I'm working on a mini-script for my game that shows the speaker's name whenever a text message pops up (the speaker's name is defined in a simple script call). I can get the name to display fine, but my problems with it are two-fold:
  1. I haven't figured out the proper way to make the window's size customizable based on the length of the speaker's name (rather than the length of the message box) without having an arrow display on the right side, and
  2. I want to make sure that the Window_Speaker window doesn't blink every time a new page in the text is posted...only when the name of the speaker changes.
Below are samplings of the code I'm using right now. What do I need to do to solve my problems?
Code:
class Window_Speaker < Window_Base
  def initialize
    super(80, 256, 480, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.z = 9999
    refresh
  end
  
  # displays the name of the speaker in a window slightly above the message box
  def refresh
    self.contents.clear
    self.contents.font.color = text_color(6)
    text = $game_temp.speaker_name
    if text != ''
      self.contents.draw_text(4, 0, self.width - 40, 32, text)
    else
      self.width = 0
    end
  end
end
Code:
class Game_Temp
  attr_accessor :speaker_name # Does the speaker have a name?
  
  alias message_display_tweaks_init initialize
  def initialize
    @speaker_name = ''
    message_display_tweaks_init
  end
end

class Window_Message < Window_Selectable
  alias message_display_tweaks_term terminate_message
  def terminate_message
    if @speaker_window != nil
      @speaker_window.dispose
      @speaker_window = nil
    end
    message_display_tweaks_term
  end
  
  alias message_display_tweaks_ref refresh
  def refresh
    if @speaker_window == nil
      @speaker_window = Window_Speaker.new
    end
    @speaker_window.opacity = self.opacity
    @speaker_window.back_opacity = self.back_opacity
    message_display_tweaks_ref
  end
end
 
You could checxk out the Universial Message system by ccoa and the Advanced message system by Dubealex. THey both have some sort of feature. Trace their code, you could learn from it.
 

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