Allow scrolling document messages

This commit is contained in:
tdixon 2017-08-05 23:12:45 -03:00
parent d1c54f0615
commit d5aa64d29b
2 changed files with 65 additions and 13 deletions

View File

@ -9,14 +9,26 @@ class Doc_Message
def initialize def initialize
@viewport = Viewport.new(0, 0, 640, 480) @viewport = Viewport.new(0, 0, 640, 480)
@sprite_bg = Sprite.new(@viewport) @sprite_bg = Sprite.new(@viewport)
@sprite_scroll_up = Sprite.new(@viewport)
@sprite_scroll_down = Sprite.new(@viewport)
if $game_switches[124] == true if $game_switches[124] == true
@sprite_bg.bitmap = RPG::Cache.picture('lined_paper_red') @sprite_bg.bitmap = RPG::Cache.picture('lined_paper_red')
@sprite_scroll_up.bitmap = RPG::Cache.picture('scroll_up_red')
@sprite_scroll_down.bitmap = RPG::Cache.picture('scroll_down_red')
else else
@sprite_bg.bitmap = RPG::Cache.picture('lined_paper_blue') #Bitmap.new(640, 480) @sprite_bg.bitmap = RPG::Cache.picture('lined_paper_blue') #Bitmap.new(640, 480)
@sprite_scroll_up.bitmap = RPG::Cache.picture('scroll_up_blue')
@sprite_scroll_down.bitmap = RPG::Cache.picture('scroll_down_blue')
end end
@sprite_bg.zoom_x = @sprite_bg.zoom_y = 2 @sprite_bg.zoom_x = @sprite_bg.zoom_y = 2
@sprite_bg.x = 120 @sprite_bg.x = 120
@sprite_bg.y = 24 @sprite_bg.y = 24
@sprite_scroll_up.zoom_x = @sprite_scroll_up.zoom_y = 2
@sprite_scroll_up.x = 524
@sprite_scroll_up.y = 24
@sprite_scroll_down.zoom_x = @sprite_scroll_down.zoom_y = 2
@sprite_scroll_down.x = 524
@sprite_scroll_down.y = 424
#@sprite_bg.bitmap.fill_rect(0, 0, 640, 480, Color.new(0, 0, 0, 128)) #@sprite_bg.bitmap.fill_rect(0, 0, 640, 480, Color.new(0, 0, 0, 128))
@sprite_text = Sprite.new(@viewport) @sprite_text = Sprite.new(@viewport)
@contents = Bitmap.new(200, 216) @contents = Bitmap.new(200, 216)
@ -33,6 +45,11 @@ class Doc_Message
@sprite_bg.opacity = 0 @sprite_bg.opacity = 0
@sprite_text.opacity = 0 @sprite_text.opacity = 0
@sprite_scroll_down.opacity = 0
@sprite_scroll_up.opacity = 0
@y_offset = 0
@scroll_limit = 0
# Animation flags # Animation flags
@fade_in = false @fade_in = false
@ -59,6 +76,7 @@ class Doc_Message
$game_temp.message_proc = nil $game_temp.message_proc = nil
end end
$game_temp.message_doc_text = nil $game_temp.message_doc_text = nil
@y_offset = 0
end end
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
# * Refresh: Load new message text and pre-process it # * Refresh: Load new message text and pre-process it
@ -92,7 +110,8 @@ class Doc_Message
text_raw.gsub!("\\\\", "\\") text_raw.gsub!("\\\\", "\\")
# Now split text into lines by measuring text metrics # Now split text into lines by measuring text metrics
x = y = 0 x = 0
y = 1
maxwidth = @contents.width - HORIZ_MARGIN * 2 maxwidth = @contents.width - HORIZ_MARGIN * 2
spacesize = @contents.text_size(' ') spacesize = @contents.text_size(' ')
for i in text_raw.split(/ /) for i in text_raw.split(/ /)
@ -126,6 +145,11 @@ class Doc_Message
end end
end end
@scroll_limit = 11 - y
if @scroll_limit > 0
@scroll_limit = 0
end
# Prepare renderer # Prepare renderer
@contents.clear @contents.clear
@contents.font.color = Color.new(100, 92, 255, 255) @contents.font.color = Color.new(100, 92, 255, 255)
@ -133,7 +157,7 @@ class Doc_Message
@contents.font.color = Color.new(255, 92, 100, 255) @contents.font.color = Color.new(255, 92, 100, 255)
end end
x = 0 x = 0
y = 0 y = 1
# Get 1 text character in c (loop until unable to get text) # Get 1 text character in c (loop until unable to get text)
while ((c = text.slice!(/./m)) != nil) while ((c = text.slice!(/./m)) != nil)
@ -155,7 +179,7 @@ class Doc_Message
next next
end end
# Draw text # Draw text
@contents.draw_text(HORIZ_MARGIN + x, VERT_MARGIN + (y + 1) * 18 - spacesize.height, 40, 18, c) @contents.draw_text(HORIZ_MARGIN + x, VERT_MARGIN + (y + @y_offset) * 18 - spacesize.height, 40, 18, c)
# Add x to drawn text width # Add x to drawn text width
x += @contents.text_size(c).width x += @contents.text_size(c).width
end end
@ -176,7 +200,6 @@ class Doc_Message
@viewport.visible = false @viewport.visible = false
$game_temp.message_window_showing = false $game_temp.message_window_showing = false
end end
return
end end
# Handle fade-in effect # Handle fade-in effect
@ -189,6 +212,23 @@ class Doc_Message
@fade_in = false @fade_in = false
$game_temp.message_window_showing = true $game_temp.message_window_showing = true
end end
end
# set the scroll indicators to the opacity of the bg,
# or 0 if they cannot scroll further
if @y_offset < 0
@sprite_scroll_up.opacity = @sprite_bg.opacity
else
@sprite_scroll_up.opacity = 0
end
if @y_offset > @scroll_limit
@sprite_scroll_down.opacity = @sprite_bg.opacity
else
@sprite_scroll_down.opacity = 0
end
# don't perform control actions while fading msg box
if @fade_in || @fade_out
return return
end end
@ -197,6 +237,14 @@ class Doc_Message
terminate_message terminate_message
@fade_out = true @fade_out = true
end end
if Input.trigger?(Input::UP) && @y_offset < 0
@y_offset += 1
refresh()
end
if Input.trigger?(Input::DOWN) && @y_offset > @scroll_limit
@y_offset -= 1
refresh()
end
end end
# Message is over and should be hidden or advanced to next # Message is over and should be hidden or advanced to next

View File

@ -11,7 +11,11 @@ class Interpreter
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
def command_101 def command_101
# If other text has been set to message_text # If other text has been set to message_text
if $game_temp.message_text != nil || $game_temp.message_ed_text != nil || $game_temp.message_doc_text != nil || $game_temp.message_desktop_text != nil || $game_temp.message_credits_text != nil if $game_temp.message_text != nil ||
$game_temp.message_ed_text != nil ||
$game_temp.message_doc_text != nil ||
$game_temp.message_desktop_text != nil ||
$game_temp.message_credits_text != nil
# End # End
return false return false
end end