class RPG::BaseItem
#--------------------------------------------------------------------------
# ○ アイテム分類のキャッシュ生成 (非戦闘時)
#--------------------------------------------------------------------------
def create_categorize_item_cache
if @__item_category == nil || !KGC::CategorizeItem::ENABLE_AUTO_CATEGORIZE
@__item_category = []
else
@__item_category.compact!
end
self.note.each_line { |line|
if line =~ KGC::CategorizeItem::Regexp::BaseItem::CATEGORY
# カテゴリ
c = KGC::CategorizeItem::CATEGORY_IDENTIFIER.index($1)
@__item_category << c if c != nil
end
}
if @__item_category.empty?
@__item_category << KGC::CategorizeItem::ITEM_DEFAULT_CATEGORY_INDEX
elsif KGC::CategorizeItem::NOT_ALLOW_DUPLICATE
# 最後に指定したカテゴリに配置
@__item_category = [@__item_category.pop]
end
end
#--------------------------------------------------------------------------
# ○ アイテム分類のキャッシュ生成 (戦闘時)
#--------------------------------------------------------------------------
def create_categorize_item_battle_cache
if @__item_category_battle == nil ||
!KGC::CategorizeItem::ENABLE_AUTO_CATEGORIZE
@__item_category_battle = []
else
@__item_category_battle.compact!
end
self.note.each_line { |line|
if line =~ KGC::CategorizeItem::Regexp::BaseItem::CATEGORY
# カテゴリ
c = KGC::CategorizeItem::CATEGORY_IDENTIFIER_BATTLE.index($1)
@__item_category_battle << c if c != nil
end
}
if @__item_category_battle.empty?
@__item_category_battle <<
KGC::CategorizeItem::ITEM_DEFAULT_CATEGORY_INDEX_BATTLE
elsif KGC::CategorizeItem::NOT_ALLOW_DUPLICATE
# 最後に指定したカテゴリに配置
@__item_category_battle = [@__item_category_battle.pop]
end
end
#--------------------------------------------------------------------------
# ○ アイテムのカテゴリ (非戦闘時)
#--------------------------------------------------------------------------
def item_category
create_categorize_item_cache if @__item_category == nil
return @__item_category
end
#--------------------------------------------------------------------------
# ○ アイテムのカテゴリ (戦闘時)
#--------------------------------------------------------------------------
def item_category_battle
create_categorize_item_battle_cache if @__item_category_battle == nil
return @__item_category_battle
end
end
class RPG::UsableItem < RPG::BaseItem
#--------------------------------------------------------------------------
# ○ アイテム分類のキャッシュ生成 (非戦闘時)
#--------------------------------------------------------------------------
def create_categorize_item_cache
@__item_category = []
if self.price == 0
@__item_category << KGC::CategorizeItem::RESERVED_CATEGORY_INDEX["貴重品"]
end
super
end
#--------------------------------------------------------------------------
# ○ アイテム分類のキャッシュ生成 (戦闘時)
#--------------------------------------------------------------------------
def create_categorize_item_battle_cache
@__item_category_battle = []
if self.price == 0
@__item_category_battle <<
KGC::CategorizeItem::RESERVED_CATEGORY_INDEX_BATTLE["貴重品"]
end
super
end
end
class RPG::Armor < RPG::BaseItem
#--------------------------------------------------------------------------
# ○ 定数
#--------------------------------------------------------------------------
CATEGORIZE_TYPE = ["盾", "头部防具", "身体防具", "装饰品"]
#--------------------------------------------------------------------------
# ○ アイテム分類のキャッシュ生成 (非戦闘時)
#--------------------------------------------------------------------------
def create_categorize_item_cache
@__item_category = []
@__item_category << KGC::CategorizeItem::RESERVED_CATEGORY_INDEX["防具"]
type = CATEGORIZE_TYPE[self.kind]
if type != nil
@__item_category << KGC::CategorizeItem::RESERVED_CATEGORY_INDEX[type]
end
super
end
#--------------------------------------------------------------------------
# ○ アイテム分類のキャッシュ生成 (戦闘時)
#--------------------------------------------------------------------------
def create_categorize_item_battle_cache
@__item_category_battle = []
@__item_category_battle <<
KGC::CategorizeItem::RESERVED_CATEGORY_INDEX_BATTLE["防具"]
type = CATEGORIZE_TYPE[self.kind]
if type != nil
@__item_category_battle <<
KGC::CategorizeItem::RESERVED_CATEGORY_INDEX_BATTLE[type]
end
super
end
end
class Window_Item < Window_Selectable
#--------------------------------------------------------------------------
# ● 公開インスタンス変数
#--------------------------------------------------------------------------
attr_reader :category # カテゴリ
#--------------------------------------------------------------------------
# ● オブジェクト初期化
# x : ウィンドウの X 座標
# y : ウィンドウの Y 座標
# width : ウィンドウの幅
# height : ウィンドウの高さ
#--------------------------------------------------------------------------
alias initialize_KGC_CategorizeItem initialize
def initialize(x, y, width, height)
@category = 0
initialize_KGC_CategorizeItem(x, y, width, height)
end
#--------------------------------------------------------------------------
# ○ カテゴリ設定
#--------------------------------------------------------------------------
def category=(value)
@category = value
refresh
end
#--------------------------------------------------------------------------
# ● アイテムをリストに含めるかどうか
# item : アイテム
#--------------------------------------------------------------------------
alias include_KGC_CategorizeItem? include?
def include?(item)
return false if item == nil
# 「全種」なら無条件で含める
if $game_temp.in_battle
return true unless KGC::CategorizeItem::ENABLE_IN_BATTLE
reserved_index = KGC::CategorizeItem::RESERVED_CATEGORY_INDEX_BATTLE
else
return true unless KGC::CategorizeItem::ENABLE_NOT_IN_BATTLE
reserved_index = KGC::CategorizeItem::RESERVED_CATEGORY_INDEX
end
return true if @category == reserved_index["全部"]
result = include_KGC_CategorizeItem?(item)
unless result
# 使用可能なら追加候補とする
if $imported["UsableEquipment"] && $game_party.item_can_use?(item)
result = true
end
end
# カテゴリ一致判定
item_category = ($game_temp.in_battle ?
item.item_category_battle : item.item_category)
result &= item_category.include?(@category)
# 「全種」なら含める
return true if @category == reserved_index["全部"]
if $game_temp.item_window_category == nil
show_category_window
else
# 指定カテゴリを表示
category = $game_temp.item_window_category
if category.is_a?(String)
category = KGC::CategorizeItem::CATEGORY_IDENTIFIER.index(category)
end
@category_window.openness = 0
hide_category_window
@category_window.index = category
@item_window.category = category
@item_window.call_update_help
end
end
#--------------------------------------------------------------------------
# ● 終了処理
#--------------------------------------------------------------------------
alias terminate_KGC_CategorizeItem terminate
def terminate
terminate_KGC_CategorizeItem
@category_window.dispose
$game_temp.item_window_category = nil
end
#--------------------------------------------------------------------------
# ● フレーム更新
#--------------------------------------------------------------------------
alias update_KGC_CategorizeItem update
def update
@category_window.update
update_KGC_CategorizeItem
if @category_window.active
update_category_selection
end
end
#--------------------------------------------------------------------------
# ○ カテゴリ選択の更新
#--------------------------------------------------------------------------
def update_category_selection
unless @category_activated
@category_activated = true
show_category_window
return
end
# 選択カテゴリー変更
if @last_category_index != @category_window.index
@item_window.category = @category_window.index
@item_window.refresh
@last_category_index = @category_window.index
end
if Input.trigger?(Input::B)
Sound.play_cancel
return_scene
elsif Input.trigger?(Input::C)
Sound.play_decision
hide_category_window
end
end
#--------------------------------------------------------------------------
# ● アイテム選択の更新
#--------------------------------------------------------------------------
alias update_item_selection_KGC_CategorizeItem update_item_selection
def update_item_selection
if Input.trigger?(Input::B)
Sound.play_cancel
if $game_temp.item_category_disabled
return_scene
else
show_category_window
end
return
end
update_item_selection_KGC_CategorizeItem
end
#--------------------------------------------------------------------------
# ○ カテゴリウィンドウの表示
#--------------------------------------------------------------------------
def show_category_window
@category_window.open
@category_window.active = true
@item_window.active = false
end
#--------------------------------------------------------------------------
# ○ カテゴリウィンドウの非表示
#--------------------------------------------------------------------------
def hide_category_window
@category_activated = false
@category_window.close
@category_window.active = false
@item_window.active = true
# アイテムウィンドウのインデックスを調整
if @item_window.index >= @item_window.item_max
@item_window.index = [@item_window.item_max - 1, 0].max
end
end
end
end # <-- if KGC::CategorizeItem::ENABLE_NOT_IN_BATTLE
if $game_temp.item_window_category == nil
@item_window.active = false
# 記憶していたカテゴリを復元
if KGC::CategorizeItem::REMEMBER_INDEX_IN_BATTLE
@category_window.index = @active_battler.last_item_category
@item_window.category = @category_window.index
end
else
# 指定カテゴリを表示
category = $game_temp.item_window_category
if category.is_a?(String)
category =
KGC::CategorizeItem::CATEGORY_IDENTIFIER_BATTLE.index(category)
end
hide_item_category_window
@category_window.openness = 0
@category_window.index = category
@item_window.category = category
@item_window.refresh
@item_window.call_update_help
end
end
#--------------------------------------------------------------------------
# ● アイテム選択の終了
#--------------------------------------------------------------------------
alias end_item_selection_KGC_CategorizeItem end_item_selection
def end_item_selection
if @category_window != nil
@category_window.dispose
@category_window = nil
end
$game_temp.item_window_category = nil
end_item_selection_KGC_CategorizeItem
end
#--------------------------------------------------------------------------
# ● アイテム選択の更新
#--------------------------------------------------------------------------
alias update_item_selection_KGC_CategorizeItem update_item_selection
def update_item_selection
@category_window.update
if @category_window.active
update_item_category_selection
return
elsif Input.trigger?(Input::B)
Sound.play_cancel
if $game_temp.item_category_disabled
end_item_selection
else
show_item_category_window
end
return
end
update_item_selection_KGC_CategorizeItem
end
#--------------------------------------------------------------------------
# ● アイテムの決定
#--------------------------------------------------------------------------
alias determine_item_KGC_CategorizeItem determine_item
def determine_item
# 選択したカテゴリを記憶
if KGC::CategorizeItem::REMEMBER_INDEX_IN_BATTLE && @category_window != nil
@active_battler.last_item_category = @category_window.index
end
determine_item_KGC_CategorizeItem
end
#--------------------------------------------------------------------------
# ○ アイテムのカテゴリ選択の更新
#--------------------------------------------------------------------------
def update_item_category_selection
@help_window.update
# 選択カテゴリー変更
if @last_category_index != @category_window.index
@item_window.category = @category_window.index
@item_window.refresh
@last_category_index = @category_window.index
end
if Input.trigger?(Input::B)
Sound.play_cancel
end_item_selection
elsif Input.trigger?(Input::C)
Sound.play_decision
hide_item_category_window
end
end
#--------------------------------------------------------------------------
# ○ アイテムカテゴリウィンドウの表示
#--------------------------------------------------------------------------
def show_item_category_window
@category_window.open
@category_window.active = true
@item_window.active = false
end
#--------------------------------------------------------------------------
# ○ アイテムカテゴリウィンドウの非表示
#--------------------------------------------------------------------------
def hide_item_category_window
@category_activated = false
@category_window.close
@category_window.active = false
@item_window.active = true
# アイテムウィンドウのインデックスを調整
if @item_window.index >= @item_window.item_max
@item_window.index = [@item_window.item_max - 1, 0].max
end
end
end
end # <-- if KGC::CategorizeItem::ENABLE_IN_BATTLE作者: ranceking 时间: 2012-11-26 09:52
没有大触可以为我解答么?作者: 咕噜 时间: 2012-11-28 22:51 本帖最后由 delv25 于 2012-11-28 22:53 编辑