Code:
#-----------------------------------------------------------------
# Menu Item
# by Slipknot
#-----------------------------------------------------------------
class Menu_Item
#-----------------------------------------------------------------
def main
@what = ItemCommand.new
@what.z = 100
@help_window = Window_Help.new
@help_window.visible = false
@none = NoneWin.new
@target_window = Window_Target.new
visact(@target_window,false)
@itemw = SoloItem.new
@itemw.help_window = @help_window
@weparm = WeaponArmor.new
@weparm.help_window = @help_window
visact(@weparm,false)
visact(@itemw,false)
@wins = [@what,@help_window,@none,@target_window,@itemw,@weparm]
Graphics.transition
loop do
Graphics.update
Input.update; update
if $scene != self; break; end
end
Graphics.freeze
for i in @wins; i.dispose; end
end
#-----------------------------------------------------------------
def update
for i in @wins; i.update; end
if @itemw.active == false or @weparm.active == false
@none.visible = true; @help_window.visible = false
else; @none.visible = false; @help_window.visible = true; end
if @what.active; update_what; return
else; @help_window.visible = true; end
if @itemw.active; update_item; return; end
if @weparm.active; update_weparm; return; end
if @target_window.active; update_target; return; end
end
#-----------------------------------------------------------------
def update_what
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)
case @what.index
when 0; visact(@what,false); visact(@itemw,true)
when 1; visact(@what,false); visact(@weparm,true)
when 2
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Menu.new(0)
end
return
end
end
#-----------------------------------------------------------------
def update_item
if Input.trigger?(Input::B)
visact(@what,true); visact(@itemw,false); return
end
if Input.trigger?(Input::C)
@item = @itemw.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
@itemw.active = false
@target_window.x = (@itemw.index + 1) % 2 * 304
@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)
@itemw.draw_item(@itemw.index)
end
$scene = Scene_Map.new; return
end
end; return
end
end
#-----------------------------------------------------------------
def update_weparm
if Input.trigger?(Input::B)
visact(@what,true)
visact(@weparm,false)
return
end
if Input.trigger?(Input::C)
$game_system.se_play($data_system.buzzer_se)
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
@itemw.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)
@itemw.draw_item(@itemw.index)
end
@target_window.refresh
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
#-----------------------------------------------------------------
def visact(w,tf)
w.active = tf; w.visible = tf
end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
class SoloItem < Window_Selectable
#-----------------------------------------------------------------
def initialize
super(0,64,640,416)
@column_max = 2
refresh
self.index = 0
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
@data.push($data_items[i])
end
end
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
self.contents.font.name = $defaultfonttype
self.contents.font.size = $defaultfontsize
for i in 0...@item_max
draw_item(i)
end
end
end
#-----------------------------------------------------------------
def draw_item(index)
item = @data[index]
number = $game_party.item_number(item.id)
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
#-----------------------------------------------------------------
def update_help
@help_window.set_text(self.item == nil ? "" : self.item.description)
end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
class WeaponArmor < Window_Selectable
#-----------------------------------------------------------------
def initialize
super(0, 64, 640, 416)
@column_max = 2
refresh
self.index = 0
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_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
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
self.contents.font.name = $defaultfonttype
self.contents.font.size = $defaultfontsize
for i in 0...@item_max; draw_item(i); end
end
end
#-----------------------------------------------------------------
def draw_item(index)
item = @data[index]
number = $game_party.weapon_number(item.id)
self.contents.font.color = disabled_color
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
#-----------------------------------------------------------------
def update_help
@help_window.set_text(self.item == nil ? "" : self.item.description)
end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
class NoneWin < Window_Base
#-----------------------------------------------------------------
def initialize; super(0,64,640,416); end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
class ItemCommand < Window_Selectable
#-----------------------------------------------------------------
def initialize
super(0,0,640,64)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $defaultfonttype
self.contents.font.size = $defaultfontsize
@item_max = 3; @column_max = 3
@commands = ["Items","Weapons and Armors","Leave"]
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 * 212
self.contents.draw_text(x,0,200,32,@commands[index])
end
#-----------------------------------------------------------------
end