module Nova
module Encyclopedia
module SCROLLING_TEXT_SETTINGS
#Author: GGZiron
#Terms: Free to use and redistribute, only not to claim is yours.
#Credits: not needed.
# ========================================================
# Settings for the add on
# ========================================================
ALL_WINDOWS_CAN_BE_ACTIVATED = false
#If true, all windows, even those that have fitting text,
#will allow to be activated.
AUTO_DETECT_IF_SHOULD_BE_ACTIVATED = true
#when true, code automatically detects if topic should
#be able to be selected or no
#If both settings above are false, you
#need to add can_scroll in the topic.
#:can_scroll => true,
#example topic with such aproach
=begin
"Oracles" => {
:switch_id => 0,
:category => :extra,
:info => "The leaders of each nation's Basilicom\nwho serves the CPUs. There are different\nconditions for each nation to become an\nOracle. Planeptune's Oracle, Histoire, is\nan artificial being created by an Ancient\nCPU; she also has the role of recording\nPlaneptune's history.",
:image? => true,
:folder => 'Graphics/Encyclopedia/Topics/',
:image_name => 'Oracles',
:icon? => true,
:icon_index => 230,
:can_scroll => true, #The new entry goes here!!
},
=end
TEXT_SCROLLING_SPEED = 8
#How fast to scroll
MAX_FITTING_ROWS = 8
#Used for the auto detection feature. If more than 8 rows, enables
#topic to be selected.
LIMIT_SCROLL = 8
#Determines how down player can scroll.
#Bigger the number, more restricted is the scroll.
#Real formula multiplies that number to the line_height, and the result
#is substracted from the content.height(the bottom of the content bitmap),
#do determine if reached far enough in the scroll.
#Leave it default if it works.
# ========================================================
# End of settings
# ========================================================
end
end
end
class GGZ_SCROLLING_TEXT < Window_Selectable
include Nova::Encyclopedia
include Nova::Encyclopedia::SCROLLING_TEXT_SETTINGS
attr_accessor :back_box
alias_method :oy_ggz124=, :oy=
def initialize(x, y, width, height)
super(x, y, width, height)
set_contents
self.windowskin = Cache.system(Info_Main[:windowskin])
back_sprite
end
def set_contents
self.contents.font.name = Info_Main[:font_name]
self.contents.font.size = Info_Main[:font_size]
self.contents.font.color = Info_Main[:font_color]
self.contents.font.outline = Info_Main[:font_outline]
end
def back_sprite
if Info_Main[:image?]
self.opacity = 0
@back_box = Sprite.new
@back_box.visible = false
@back_box.z = self.z - 1
path = Info_Main[:folder]
name = Info_Main[:name]
@back_box.bitmap = Bitmap.new(path + name)
@back_box.ox = Info_Main[:img_ox]
@back_box.oy = Info_Main[:img_oy]
@back_box.x = self.x
@back_box.y = self.y
end
end
def display_info(text)
self.oy = 0
lines = text.count("\n") + 1
self.contents.dispose
self.contents = Bitmap.new(contents_width, fitting_height(lines) - line_height)
set_contents
draw_text_ex(0, 0, text)
end
#▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
# ● Dispose
#▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
def dispose
super
@back_box.bitmap.dispose; @back_box.dispose
end
def process_cursor_move
return unless self.active
scroll_down if Input.repeat?(:DOWN)
scroll_up if Input.repeat?(:UP)
#Sound.play_cursor if @index != last_index
end
def reset_font_settings; end
def row_height
[line_height, contents.font.size].max
end
def oy=(int)
self.oy_ggz124 = int
if oy > contents.height - row_height * LIMIT_SCROLL
self.oy_ggz124 = contents.height - row_height * LIMIT_SCROLL
end
self.oy_ggz124 = 0 if oy < 0
end
def scroll_down
self.oy += TEXT_SCROLLING_SPEED
end
def scroll_up
self.oy -= TEXT_SCROLLING_SPEED
end
end
class Encyclopedia < Scene_Base
include Nova::Encyclopedia::SCROLLING_TEXT_SETTINGS
alias_method :exec_all_windows_old124, :exec_all_windows
alias_method :method_information_old124, :method_information
def exec_all_windows
exec_all_windows_old124
@pedia_info.dispose
px = @pedia_topics.width; py = Graphics.height * 0.3
pw = Graphics.width - px; ph = (Graphics.height - py) - @pedia_help.height
@pedia_info = GGZ_SCROLLING_TEXT.new(px, py, pw, ph)
@pedia_info.set_handler(:cancel, method(:activate_topic_window))
@pedia_topics.set_handler(:ok, method(:activate_text_window))
end
#Method Overwrite
def method_information
return if @pedia_topics.data[@pedia_topics.index].nil?
condition = @text_index != @pedia_topics.data[@pedia_topics.index][:info]
can_scroll = @pedia_topics.data[@pedia_topics.index][:can_scroll] || false
method_information_old124
if condition
return @pedia_topics.ok_enabled = true if ALL_WINDOWS_CAN_BE_ACTIVATED
if AUTO_DETECT_IF_SHOULD_BE_ACTIVATED
lines = @text_index.count("\n")
return lines > MAX_FITTING_ROWS ?
@pedia_topics.ok_enabled = true :
@pedia_topics.ok_enabled = false
end
@pedia_topics.ok_enabled = can_scroll
end
end
def activate_text_window
@pedia_topics.deactivate
@pedia_info.activate
end
def activate_topic_window
@pedia_topics.activate
@pedia_info.deactivate
end
end
class Pedia_Topics < Window_Selectable
alias_method :initialize_old124, :initialize
attr_writer :ok_enabled
def initialize(tx, ty, tw, th)
initialize_old124(tx, ty, tw, th)
@ok_enabled = false
end
def ok_enabled?
return @ok_enabled
end
end