1
2
|
#//////////////////////////////////////////Textbox/////////////////////////////////////////////// #__________________________________________________
class Interpreter def set_text(character, text, distance=-1) #@parameter character: -1 --> player, 0 ---> this event, 1 ---> event with that ID #@parameter distance: < 0 --> always visible, >= 0 --> visible when distance # between character and player is not more than distance character = get_character(character) character.text = text if text != character.text character.distance = distance end end #========================== class Game_Character attr_accessor :text attr_accessor :distance alias init initialize def initialize init @text = "" @window_text = nil @old_text = "" @distance = 0 end #----------- alias npc_text_update update def update npc_text_update if @text != @old_text @window_text.dispose if @window_text != nil if @text == nil or @text == "" @window_text = nil @old_text = "" else @window_text = NPC_Window.new(@text) @window_text.visible = false @old_text = @text end end if @window_text != nil if @distance < 0 @window_text.set_visible( ! @transparent) else if ($game_player.x >= @x-@distance) and ($game_player.x <= @x+@distance) and ($game_player.y >= @y-@distance) and ($game_player.y <= @y+@distance) @window_text.set_visible( ! @transparent) else @window_text.set_visible(false) end end @window_text.update @window_text.x = screen_x - @window_text.width/2 @window_text.y = screen_y - 40 - 50 end end end #==================== class NPC_Window < Window_Base def initialize(text) dummy_bitmap = Bitmap.new(32,32) dummy_bitmap.font.name = $defaultfonttype dummy_bitmap.font.size = 14 text_size = dummy_bitmap.text_size(text).width super(0, 0, text_size+32, 30) self.contents = nil self.back_opacity = 140 @air_text = Air_Text.new(self.x, self.y, self.width, self.height, text) end #----------- def refresh @air_text.refresh super end #----------- def update @air_text.update @air_text.x = self.x-16 @air_text.y = self.y-16 super end #----------- def dispose @air_text.dispose super end #----------- def set_visible(visible) self.visible = visible @air_text.visible = visible end end #=========== class Air_Text < Window_Base def initialize(x, y, width, height, designate_text) super(x-48, y-48, width+32, height+32) self.contents = Bitmap.new(self.width - 32, self.height - 32) self.opacity = 0 self.back_opacity = 0 w = self.contents.width h = self.contents.height self.contents.font.name = $defaultfonttype self.contents.font.size = 14 self.contents.draw_text(0, 0, w, h, designate_text, 1) end #-------------------- def dispose self.contents.clear super end end |