Code:
#==============================================================================
# ** Window_Item
#------------------------------------------------------------------------------
# This window displays items in possession on the item screens.
#==============================================================================
class Window_Item < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 60, 320, 420)
@column_max = 1
refresh
self.index = 0
end
#--------------------------------------------------------------------------
# * Get Item
#--------------------------------------------------------------------------
def item
return @data[self.index]
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
# Add item
for i in 1...$data_items.size
if $game_party.item_number(i) > 0
@data.push($data_items[i])
end
end
# Also add weapons and items if outside of battle
unless $game_temp.in_battle
for i in 1...$data_weapons.size
if $game_party.weapon_number(i) > 0
@data.push($data_weapons[i])
end
end
for i in 1...$data_armors.size
if $game_party.armor_number(i) > 0
@data.push($data_armors[i])
end
end
end
# If item count is not 0, make a bit map and draw all items
@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
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
#--------------------------------------------------------------------------
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 % 2 * (0 + 0)
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 + 240, y, 16, 32, ":", 1)
self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
end
#--------------------------------------------------------------------------
# * Help Text Update
#--------------------------------------------------------------------------
def update_help
@help_window.set_text(self.item == nil ? "" : self.item.description)
end
end
#==============================================================================
# ** Window_Item
#------------------------------------------------------------------------------
# This window displays items in possession on the battle screens.
#==============================================================================
class Window_ItemBattle < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 320, 640, 160)
@column_max = 2
refresh
self.index = 0
# If in battle, move window to center of screen
# and make it semi-transparent
if $game_temp.in_battle
self.y = 320
self.height = 160
self.back_opacity = 255
end
end
#--------------------------------------------------------------------------
# * Get Item
#--------------------------------------------------------------------------
def item
return @data[self.index]
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
# Add item
for i in 1...$data_items.size
if $game_party.item_number(i) > 0
@data.push($data_items[i])
end
end
# Also add weapons and items if outside of battle
unless $game_temp.in_battle
for i in 1...$data_weapons.size
if $game_party.weapon_number(i) > 0
@data.push($data_weapons[i])
end
end
for i in 1...$data_armors.size
if $game_party.armor_number(i) > 0
@data.push($data_armors[i])
end
end
end
# If item count is not 0, make a bit map and draw all items
@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
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
#--------------------------------------------------------------------------
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 % 2 * (288 + 32)
y = index / 2 * 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 + 240, y, 16, 32, ":", 1)
self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
end
#--------------------------------------------------------------------------
# * Help Text Update
#--------------------------------------------------------------------------
def update_help
@help_window.set_text(self.item == nil ? "" : self.item.description)
end
end
#==============================================================================
# ? Window_ItemDescription
#------------------------------------------------------------------------------
# ?This window is shown in a menu for an item description
#==============================================================================
class Window_ItemD < Window_Base
#--------------------------------------------------------------------------
# ? Initialize the window
#--------------------------------------------------------------------------
def initialize
super(0, 0, 640, 60)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = "Verdana"
self.contents.font.size = 22
end
#--------------------------------------------------------------------------
# ? Set the text and alignment of the text in the window
# text : Text to set in the help window
# align : alignment of the text
# 0-Left-Justify
# 1-Center
# 2-Right-Justify
#--------------------------------------------------------------------------
def set_text(text, align = 0)
if text != @text or align != @align
self.contents.clear
self.contents.font.color = normal_color
self.contents.draw_text(4, 0, self.width - 40, 32, text, align)
@text = text
@align = align
@actor = nil
end
self.visible = true
end
#--------------------------------------------------------------------------
# ? Draw an actor's name and status in the help window.
# actor : Actor whose name and status will be shown in the help window
#--------------------------------------------------------------------------
def set_actor(actor)
if actor != @actor
self.contents.clear
draw_actor_name(actor, 4, 0)
draw_actor_state(actor, 140, 0)
draw_actor_hp(actor, 284, 0)
draw_actor_sp(actor, 460, 0)
@actor = actor
@text = nil
self.visible = true
end
end
#--------------------------------------------------------------------------
# ? Draw the name of an enemy and its status
# enemy : Enemy to use
#--------------------------------------------------------------------------
def set_enemy(enemy)
text = enemy.name
state_text = make_battler_state_text(enemy, 112, false)
if state_text != ""
text += " " + state_text
end
set_text(text, 1)
end
end
#==============================================================================
# ? Window_Target
#------------------------------------------------------------------------------
# ?This window is shown when the player selects an item that requires
# a target in the item menus within the main menu. This window
# isn't shown in battle. It is just a picture
#==============================================================================
class Window_TargetMenuFalse < Window_Base
#--------------------------------------------------------------------------
# ? Initialize the Target window
#--------------------------------------------------------------------------
def initialize
super(320, 60, 320, 420)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = "Verdana"
self.contents.font.size = 22
self.z += 10
@item_max = $game_party.actors.size
refresh
end
#--------------------------------------------------------------------------
# ? Draw the Target window
#--------------------------------------------------------------------------
def refresh
self.contents.clear
for i in 0...$game_party.actors.size
x = 60
y = i * 105
actor = $game_party.actors[i]
draw_actor_graphic(actor, x - 30, y + 70)
draw_actor_name(actor, x, y)
draw_actor_state(actor, x + 120, y)
draw_actor_hp(actor, x, y + 24)
draw_actor_sp(actor, x + 60, y + 44)
end
end
end
#==============================================================================
# ? Window_Target
#------------------------------------------------------------------------------
# ?This window is shown when the player selects an item that requires
# a target in the item menus within the main menu. This window
# isn't shown in battle. This actually shows the targets
#==============================================================================
class Window_TargetMenu < Window_Selectable
#--------------------------------------------------------------------------
# ? Initialize the Target window
#--------------------------------------------------------------------------
def initialize
super(320, 60, 320, 420)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = "Verdana"
self.contents.font.size = 22
self.z += 10
@item_max = $game_party.actors.size
refresh
end
#--------------------------------------------------------------------------
# ? Draw the Target window
#--------------------------------------------------------------------------
def refresh
self.contents.clear
for i in 0...$game_party.actors.size
x = 4
y = i * 105
actor = $game_party.actors[i]
end
end
#--------------------------------------------------------------------------
# ? Update the position of the cursor rectangle
#--------------------------------------------------------------------------
def update_cursor_rect
if @index <= -2
self.cursor_rect.set(0, (@index + 10) * 105, self.width - 32, 80)
elsif @index == -1
self.cursor_rect.set(0, 0, self.width - 32, @item_max * 105 - 20)
else
self.cursor_rect.set(0, @index * 105, self.width - 32, 80)
end
end
end