king-exit/Scripts/_.52.rb
2024-09-06 11:45:39 -05:00

300 lines
10 KiB
Ruby
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#******************************************************************************
#
# テキストウィンドウ
#
# --------------------------------------------------------------------------
# バージョン 1.0.0
# 対 応 RPGツクールVX Ace : RGSS3
# 制 作 者
# 配 布 元 http://cacaosoft.web.fc2.com/
# --------------------------------------------------------------------------
# == 概 要 ==
#
# テキストを表示するウィンドウを追加します。
#
# --------------------------------------------------------------------------
# == 注意事項 ==
#
# ※ このスクリプトの動作には、Custom Menu Base が必要です。
#
#
#******************************************************************************
#==============================================================================
# ◆ 設定項目
#==============================================================================
module CAO::CM::Text
#--------------------------------------------------------------------------
# ◇ ウィンドウの設定
#--------------------------------------------------------------------------
CONFIGURATION = {}
CONFIGURATION[:top] = {
:window => [0, 0, 640, 108, 99],
:text => '\C[16]\L[0,26,520,1]'
}
CONFIGURATION[:bottom] = {
:window => [0, 408, 640, 72, 99],
}
CONFIGURATION[:time] = {
:window => [380, 405, 188, 48],
:frame => 60,
:back => "",
:text => '\C[16]Playtime\X[104]\C[0]\T[%4$3d\'%3$02d]'
}
# CONFIGURATION[:sample] = {
# :window => [112, 88, 320, 240],
# :visible => "$game_switches[3]",
# :open => 48,
# :text => <<'EOS'
#\C[16]\L[296,1,S]\C[0]テストメッセージ\Y[+8]
#\C[16]変数1番 : \C[0]\V[1]
#\C[16]スイッチ3番 : \C[0]\S[3,ON,OFF]
#\C[16]戦闘回数 : \C[0]<% $game_system.battle_count %> \C[16]回\C[0]
#EOS
# }
end
#/////////////////////////////////////////////////////////////////////////////#
# #
# 下記のスクリプトを変更する必要はありません。 #
# #
#/////////////////////////////////////////////////////////////////////////////#
class Window_MenuText < Window_Base
include CAO::CM::Text
#--------------------------------------------------------------------------
# ●
#--------------------------------------------------------------------------
begin
DATA_TEXTS = load_data("Data/cmText.rvdata2")
rescue Errno::ENOENT
DATA_TEXTS = {}
end
#--------------------------------------------------------------------------
# ●
#--------------------------------------------------------------------------
def initialize(ident)
@ident = ident
if params[:back] && !params[:back].empty?
@background_sprite = Sprite.new
@background_sprite.bitmap = Cache.system(params[:back])
end
super(*params[:window][0, 4])
self.z = params[:window][4] || self.z
self.opacity = params[:back] ? 0 : 255
if params[:visible]
self.openness = eval(params[:visible]) ? 255 : 0
end
if params[:slide]
@slide = Slide.new(ident)
self.openness = 255
unless eval(params[:visible])
self.x = @slide.sx
self.y = @slide.sy
end
end
@canvas = CAO::CM::Canvas.new(self)
@frame_count = Graphics.frame_count % Graphics.frame_rate
update_background
refresh
end
#--------------------------------------------------------------------------
# ●
#--------------------------------------------------------------------------
def dispose
super
@background_sprite.dispose if @background_sprite
end
#--------------------------------------------------------------------------
# ●
#--------------------------------------------------------------------------
def update
super
# ウィンドウ開閉
if params[:visible] && !@opening && !@closing
eval(params[:visible]) ? open : close
end
# フレーム更新
if CONFIGURATION[@ident][:frame]
@frame_count += 1
if CONFIGURATION[@ident][:frame] < @frame_count
refresh
@frame_count -= CONFIGURATION[@ident][:frame]
end
end
update_background
end
#--------------------------------------------------------------------------
# ●
#--------------------------------------------------------------------------
def update_background
return unless @background_sprite
@background_sprite.x = self.x
@background_sprite.y = self.y
@background_sprite.z = self.z
@background_sprite.visible = self.openness == 255
end
#--------------------------------------------------------------------------
# ●
#--------------------------------------------------------------------------
def params
return CONFIGURATION[@ident]
end
#--------------------------------------------------------------------------
# ●
#--------------------------------------------------------------------------
def param_text
if CONFIGURATION[@ident][:text]
if CONFIGURATION[@ident][:text].is_a?(Symbol)
return DATA_TEXTS[CONFIGURATION[@ident][:text]] || ""
else
return CONFIGURATION[@ident][:text]
end
else
return DATA_TEXTS[@ident] || ""
end
end
#--------------------------------------------------------------------------
# ●
#--------------------------------------------------------------------------
def open?
return super unless @slide
return self.x == @slide.wx && self.y == @slide.wy
end
#--------------------------------------------------------------------------
# ●
#--------------------------------------------------------------------------
def close?
return super unless @slide
return true if self.x == @slide.ex && self.y == @slide.ey
return true if self.x == @slide.sx && self.y == @slide.sy
return false
end
#--------------------------------------------------------------------------
# ● 開く処理の更新
#--------------------------------------------------------------------------
def update_open
if @slide
self.x += @slide.ox
self.y += @slide.oy
else
self.openness += params[:open] ? 48 : 255
end
@opening = false if open?
end
#--------------------------------------------------------------------------
# ● 閉じる処理の更新
#--------------------------------------------------------------------------
def update_close
if @slide
self.x += @slide.cx
self.y += @slide.cy
if close?
self.x = @slide.sx
self.y = @slide.sy
@closing = false
end
else
self.openness -= params[:open] ? 48 : 255
@closing = false if close?
end
end
#--------------------------------------------------------------------------
# ●
#--------------------------------------------------------------------------
def refresh
self.contents.clear
@canvas.draw_text_ex(0, 0, param_text)
end
end
class Scene_Menu
#--------------------------------------------------------------------------
# ● オプションウィンドウの作成
#--------------------------------------------------------------------------
alias _cao_cm_text_create_option_window create_option_window
def create_option_window
_cao_cm_text_create_option_window
@text_window_set = {}
CAO::CM::Text::CONFIGURATION.each_key do |ident|
@text_window_set[ident] = Window_MenuText.new(ident)
end
end
#--------------------------------------------------------------------------
# ● オプションウィンドウの更新
#--------------------------------------------------------------------------
alias _cao_cm_text_update_option_window update_option_window
def update_option_window
_cao_cm_text_update_option_window
@text_window_set.each_value {|wnd| wnd.update }
end
#--------------------------------------------------------------------------
# ● オプションウィンドウの解放
#--------------------------------------------------------------------------
alias _cao_cm_text_dispose_option_window dispose_option_window
def dispose_option_window
_cao_cm_text_dispose_option_window
@text_window_set.each_value {|wnd| wnd.dispose }
end
#--------------------------------------------------------------------------
# ○
#--------------------------------------------------------------------------
alias _cao_cm_text_check_refresh_window check_refresh_window
def check_refresh_window(command)
_cao_cm_text_check_refresh_window(command)
if command.refresh.include?(:text)
@text_window_set.each_value {|w| w.refresh }
end
end
end
class Window_MenuText::Slide
#--------------------------------------------------------------------------
# ●
#--------------------------------------------------------------------------
attr_reader :wx, :wy, :ox, :oy, :cx, :cy, :sx, :sy, :ex, :ey
#--------------------------------------------------------------------------
# ●
#--------------------------------------------------------------------------
def initialize(ident)
@ox = CAO::CM::Text::CONFIGURATION[ident][:slide][0]
@oy = CAO::CM::Text::CONFIGURATION[ident][:slide][1]
@cx = CAO::CM::Text::CONFIGURATION[ident][:slide][2]
@cy = CAO::CM::Text::CONFIGURATION[ident][:slide][3]
@wx = CAO::CM::Text::CONFIGURATION[ident][:window][0]
@wy = CAO::CM::Text::CONFIGURATION[ident][:window][1]
ww = CAO::CM::Text::CONFIGURATION[ident][:window][2]
wh = CAO::CM::Text::CONFIGURATION[ident][:window][3]
# FIXME: 変化量が大きいとオープンが遅くなる
n = [ step_count(wx, @ox < 0 ? Graphics.width : -ww, -@ox),
step_count(wy, @oy < 0 ? Graphics.height : -wh, -@oy) ].max
@sx = wx - (n * @ox)
@sy = wy - (n * @oy)
n = [ step_count(wx, @cx < 0 ? -ww : Graphics.width, @cx),
step_count(wy, @cy < 0 ? -wh : Graphics.height, @cy) ].max
@ex = wx + (n * @cx)
@ey = wy + (n * @cy)
end
#--------------------------------------------------------------------------
# ●
#--------------------------------------------------------------------------
def step_count(init, limit, step)
count = 0
if step != 0
n = init
loop do
break if step < 0 && limit >= n
break if step > 0 && limit <= n
n += step
count += 1
end
end
return count
end
end