#==============================================================================
# Advanced Item Menu
#------------------------------------------------------------------------------
# Script by BlueScope, draw_wrap_text method by Trickster
#==============================================================================
class Bitmap
#--------------------------------------------------------------------------
def draw_wrap_text(x,y,width, height, text)
array = text.split
for i in array
word = i + ' '
word_width = text_size(word).width
if x + word_width > width
y += height
x = 0
end
self.draw_text(x, y, word_width, height, word)
x += word_width
end
end
#--------------------------------------------------------------------------
end
class Window_ItemCategory < Window_Selectable
#--------------------------------------------------------------------------
def initialize
super(0, 0, 640, 96)
self.contents = Bitmap.new(width - 32, height - 32)
@commands = ["Weapons", "Armor", "Medicine", "Scrolls", "Food", "Materials", "Collectables", "Other Items"]
@item_max = 8
@column_max = 4
refresh
self.index = 0
end
#--------------------------------------------------------------------------
def refresh
self.contents.clear
for i in 0...@item_max
draw_item(i)
end
end
#--------------------------------------------------------------------------
def draw_item(index)
x = 4 + index % 4 * 160
y = index / 4 * 32
rect = Rect.new(x, y, 128 - 10, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, @commands[index], 1)
end
#--------------------------------------------------------------------------
def update_cursor_rect
x = index % 4 * 160
y = index / 4 * 32
self.cursor_rect.set(x, y, 128, 32)
end
#--------------------------------------------------------------------------
end
class Window_Item < Window_Selectable
#--------------------------------------------------------------------------
def initialize(tag_id)
super(0, 96, 320, 382)
@column_max = 1
@tag_id = tag_id
refresh
self.index = 0
self.active = false
if $game_temp.in_battle
self.y = 64
self.height = 256
self.back_opacity = 160
end
end
#--------------------------------------------------------------------------
def item
return @data[self.index]
end
#--------------------------------------------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
for i in 1...$data_items.size
if $game_party.item_number(i) > 0 and $data_items[i].element_set.include?(@tag_id)
@data.push($data_items[i])
end
end
unless $game_temp.in_battle
for i in 1...$data_weapons.size
if $game_party.weapon_number(i) > 0 and @tag_id == 1
@data.push($data_weapons[i])
end
end
for i in 1...$data_armors.size
if $game_party.armor_number(i) > 0 and @tag_id == 2
@data.push($data_armors[i])
end
end
end
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
for i in 0...@item_max
draw_item(i)
end
end
end
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
case item
when RPG::Item
number = $game_party.item_number(item.id)
when RPG::Weapon
number = $game_party.weapon_number(item.id)
when RPG::Armor
number = $game_party.armor_number(item.id)
end
if item.is_a?(RPG::Item) and
$game_party.item_can_use?(item.id)
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
x = 4 + index % 1 * (288 + 32)
y = index / 1 * 32
rect = Rect.new(x, y, self.width / @column_max - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
bitmap = RPG::Cache.icon(item.icon_name)
opacity = self.contents.font.color == normal_color ? 255 : 128
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
self.contents.draw_text(x + 228, y, 16, 32, ":", 1)
self.contents.draw_text(x + 244, y, 36, 32, number.to_s, 2)
end
#--------------------------------------------------------------------------
def update_help
@help_window.set_text(self.item == nil ? "" : self.item.description)
end
#--------------------------------------------------------------------------
end
class Window_ItemDescription < Window_Base
#--------------------------------------------------------------------------
def initialize
super(320, 96, 320, 382)
self.z = 1
self.contents = Bitmap.new(width - 32, height - 32)
end
#--------------------------------------------------------------------------
def refresh(item)
self.contents.clear
if item != nil
@itemname = item
filename = "Data/ItemDescriptions.txt"
if FileTest.exist?(filename)
file = File.open(filename)
content = file.readlines
end
for line in 0..content.size
if content[line].include?("*" + @itemname)
@description = content[line+1]
break
else
return
end
end
self.contents.draw_text(0, 0, self.width-40, 32, @itemname, 1)
self.contents.fill_rect(0, 48, self.width-40, 1, normal_color)
self.contents.draw_wrap_text(0, 64, self.width-40, 32, @description.to_s)
end
end
#--------------------------------------------------------------------------
end
class Window_Target < Window_Selectable
#--------------------------------------------------------------------------
def initialize
super(320, 96, 320, 382)
self.contents = Bitmap.new(width - 32, height - 32)
self.z += 10
@item_max = $game_party.actors.size
refresh
end
#--------------------------------------------------------------------------
def refresh
self.contents.clear
for i in 0...$game_party.actors.size
x = 4
y = 1 + i * 70
actor = $game_party.actors[i]
draw_actor_name(actor, x, y)
draw_actor_state(actor, x + 144, y)
draw_actor_hp(actor, x, y + 32)
draw_actor_sp(actor, x + 144, y + 32)
end
end
#--------------------------------------------------------------------------
def update_cursor_rect
if @index <= -2
self.cursor_rect.set(0, 1 + (@index + 10) * 70, self.width - 32, 64)
elsif @index == -1
self.cursor_rect.set(0, 0, self.width - 32, 1 + @item_max * 70 - 20)
else
self.cursor_rect.set(0, 1 + @index * 70, self.width - 32, 64)
end
end
#--------------------------------------------------------------------------
end
class Scene_ItemAdvanced
#--------------------------------------------------------------------------
def main
@category_window = Window_ItemCategory.new
@description_window = Window_ItemDescription.new
@target_window = Window_Target.new
@target_window.visible = false
@target_window.active = false
@dummy_window = Window_Base.new(0, 96, 320, 382)
@dummy_window.z = 1
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@category_window.dispose
if @item_window != nil
@item_window.dispose
end
@description_window.dispose
@target_window.dispose
@dummy_window.dispose
end
#--------------------------------------------------------------------------
def update
@category_window.update
if @item_window != nil
@item_window.update
end
@target_window.update
if @category_window.active
update_category
return
end
if @item_window.active
update_item
return
end
if @target_window.active
update_target
return
end
end
#--------------------------------------------------------------------------
def update_category
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Menu.new(0)
return
end
if Input.trigger?(Input::C)
@category_window.active = false
@item_window = Window_Item.new(@category_window.index + 1)
@item_window.active = true
@item = @item_window.item
@description_window.refresh(@item.name)
end
end
#--------------------------------------------------------------------------
def update_item
if Input.trigger?(Input::UP) or Input.trigger?(Input::DOWN)
@item = @item_window.item
@description_window.refresh(@item.name)
end
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@item_window.active = false
@item_window.visible = false
@category_window.active = true
@description_window.contents.clear
return
end
if Input.trigger?(Input::C)
@item = @item_window.item
unless @item.is_a?(RPG::Item)
$game_system.se_play($data_system.buzzer_se)
return
end
unless $game_party.item_can_use?(@item.id)
$game_system.se_play($data_system.buzzer_se)
return
end
$game_system.se_play($data_system.decision_se)
if @item.scope >= 3
@item_window.active = false
@target_window.visible = true
@target_window.active = true
if @item.scope == 4 || @item.scope == 6
@target_window.index = -1
else
@target_window.index = 0
end
else
if @item.common_event_id > 0
$game_temp.common_event_id = @item.common_event_id
$game_system.se_play(@item.menu_se)
if @item.consumable
$game_party.lose_item(@item.id, 1)
@item_window.draw_item(@item_window.index)
end
$scene = Scene_Map.new
return
end
end
return
end
end
#--------------------------------------------------------------------------
def update_target
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
unless $game_party.item_can_use?(@item.id)
@item_window.refresh
end
@item_window.active = true
@target_window.visible = false
@target_window.active = false
return
end
if Input.trigger?(Input::C)
if $game_party.item_number(@item.id) == 0
$game_system.se_play($data_system.buzzer_se)
return
end
if @target_window.index == -1
used = false
for i in $game_party.actors
used |= i.item_effect(@item)
end
end
if @target_window.index >= 0
target = $game_party.actors[@target_window.index]
used = target.item_effect(@item)
end
if used
$game_system.se_play(@item.menu_se)
if @item.consumable
$game_party.lose_item(@item.id, 1)
@item_window.draw_item(@item_window.index)
end
@target_window.refresh
if $game_party.all_dead?
$scene = Scene_Gameover.new
return
end
if @item.common_event_id > 0
$game_temp.common_event_id = @item.common_event_id
$scene = Scene_Map.new
return
end
end
unless used
$game_system.se_play($data_system.buzzer_se)
end
return
end
end
#--------------------------------------------------------------------------
end