SiliconHero
Member
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:
- 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
- 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.
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