This repository has been archived on 2026-05-18. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
rpgskeleton/Scripts/RPG/Window_SkillList.rb

123 lines
4.6 KiB
Ruby
Raw Permalink Normal View History

2014-04-23 21:59:50 -07:00
# -*- coding: utf-8 -*-
#==============================================================================
# ** Window_SkillList
#------------------------------------------------------------------------------
# This window is for displaying a list of available skills on the skill window.
#==============================================================================
class Window_SkillList < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(x, y, width, height)
super
@actor = nil
@stype_id = 0
@data = []
end
#--------------------------------------------------------------------------
# * Set Actor
#--------------------------------------------------------------------------
def actor=(actor)
return if @actor == actor
@actor = actor
refresh
self.oy = 0
end
#--------------------------------------------------------------------------
# * Set Skill Type ID
#--------------------------------------------------------------------------
def stype_id=(stype_id)
return if @stype_id == stype_id
@stype_id = stype_id
refresh
self.oy = 0
end
#--------------------------------------------------------------------------
# * Get Digit Count
#--------------------------------------------------------------------------
def col_max
return 2
end
#--------------------------------------------------------------------------
# * Get Number of Items
#--------------------------------------------------------------------------
def item_max
@data ? @data.size : 1
end
#--------------------------------------------------------------------------
# * Get Skill
#--------------------------------------------------------------------------
def item
@data && index >= 0 ? @data[index] : nil
end
#--------------------------------------------------------------------------
# * Get Activation State of Selection Item
#--------------------------------------------------------------------------
def current_item_enabled?
enable?(@data[index])
end
#--------------------------------------------------------------------------
# * Include in Skill List?
#--------------------------------------------------------------------------
def include?(item)
item && item.stype_id == @stype_id
end
#--------------------------------------------------------------------------
# * Display Skill in Active State?
#--------------------------------------------------------------------------
def enable?(item)
@actor && @actor.usable?(item)
end
#--------------------------------------------------------------------------
# * Create Skill List
#--------------------------------------------------------------------------
def make_item_list
@data = @actor ? @actor.skills.select {|skill| include?(skill) } : []
end
#--------------------------------------------------------------------------
# * Restore Previous Selection Position
#--------------------------------------------------------------------------
def select_last
select(@data.index(@actor.last_skill.object) || 0)
end
#--------------------------------------------------------------------------
# * Draw Item
#--------------------------------------------------------------------------
def draw_item(index)
skill = @data[index]
if skill
rect = item_rect(index)
rect.width -= 4
draw_item_name(skill, rect.x, rect.y, enable?(skill))
draw_skill_cost(rect, skill)
end
end
#--------------------------------------------------------------------------
# * Draw Skill Use Cost
#--------------------------------------------------------------------------
def draw_skill_cost(rect, skill)
if @actor.skill_tp_cost(skill) > 0
change_color(tp_cost_color, enable?(skill))
draw_text(rect, @actor.skill_tp_cost(skill), 2)
elsif @actor.skill_mp_cost(skill) > 0
change_color(mp_cost_color, enable?(skill))
draw_text(rect, @actor.skill_mp_cost(skill), 2)
end
end
#--------------------------------------------------------------------------
# * Update Help Text
#--------------------------------------------------------------------------
def update_help
@help_window.set_item(item)
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
make_item_list
create_contents
draw_all_items
end
end