I'm working on a script that includes a new Window_Selectable. I can get it to activate and get a cursor to show up in it, but I can't figure out how to actually populate the list of selectable items. I tried copying a couple other scripts, but to no avail.
Can anyone help me understand which commands will populate this list and where they should go?
Thanks!
(Ace) Adding items to Window_Selectable
● ARCHIVED · READ-ONLY
-
-
You can see the Window_ItemList is a good example, that window using Window_Selectable as it's parent class :
#==============================================================================# ** Window_ItemList#------------------------------------------------------------------------------# This window displays a list of party items on the item screen.#==============================================================================class Window_ItemList < Window_Selectable #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize(x, y, width, height) super @category = :none @data = [] end #-------------------------------------------------------------------------- # * Set Category #-------------------------------------------------------------------------- def category=(category) return if @category == category @category = category 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 Item #-------------------------------------------------------------------------- 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 Item List? #-------------------------------------------------------------------------- def include?(item) case @category when :item item.is_a?(RPG::Item) && !item.key_item? when :weapon item.is_a?(RPG::Weapon) when :armor item.is_a?(RPG::Armor) when :key_item item.is_a?(RPG::Item) && item.key_item? else false end end #-------------------------------------------------------------------------- # * Display in Enabled State? #-------------------------------------------------------------------------- def enable?(item) $game_party.usable?(item) end #-------------------------------------------------------------------------- # * Create Item List #-------------------------------------------------------------------------- def make_item_list @data = $game_party.all_items.select {|item| include?(item) } @data.push(nil) if include?(nil) end #-------------------------------------------------------------------------- # * Restore Previous Selection Position #-------------------------------------------------------------------------- def select_last select(@data.index($game_party.last_item.object) || 0) end #-------------------------------------------------------------------------- # * Draw Item # This is the method that used to add item in the list. # But then draw_item itself is called by method draw_all_items # so it draws all item that should be drawn in this window. #-------------------------------------------------------------------------- def draw_item(index) item = @data[index] if item rect = item_rect(index) rect.width -= 4 draw_item_name(item, rect.x, rect.y, enable?(item)) draw_item_number(rect, item) end end #-------------------------------------------------------------------------- # * Draw Number of Items #-------------------------------------------------------------------------- def draw_item_number(rect, item) draw_text(rect, sprintf(":%2d", $game_party.item_number(item)), 2) end #-------------------------------------------------------------------------- # * Update Help Text #-------------------------------------------------------------------------- def update_help @help_window.set_item(item) end #-------------------------------------------------------------------------- # * Refresh #-------------------------------------------------------------------------- def refresh make_item_list create_contents draw_all_items endendSpoiler
Check the draw_item method, take your tme to study it. That will helps :) -
Thanks, that was helpful. However, I don't seem to be adding the correct type of information to the data variable. I tried just adding a string and that failed (nothing shows up in my list). What are the requirements there?
-
Did you set the position of the text correctly? The text placement in the window and the width of text container(you know the third argument of draw_text method) must fit for your string. Then when I mean text placement, it is the x and y position, and for Window_Selectable that usually draw many list of item it should(must) dynamic,I mean for listing items, the y coordinate position must changed for every items so it draws downward. I'm not sure why it's not appear.
But still, I if you can post your code here, then it will be easier for me to point your way. To be honest adding an item list like that is more easy in Window_Command which simply added via add_command that you call from make_command_list, but yeah you need to learn it too and the handler method will needed fo each item(or I must say command list). -
Sure, thanks for any help on figuring out how to get something to show up in the list.
My followup question is going to be about how to tie the selected item to text in the help window.
Spoilerclass Window_MyList < Window_Selectable
def col_max
3
end
#--------------------------------------------------------------------------
# initialize
#--------------------------------------------------------------------------
def initialize(dx, dy)
dw = Graphics.width# - (Graphics.width * 2 / 5)
dh = Graphics.height - dy
super(dx, dy, dw, dh)
@actor = nil
@command_window = nil
@status_window
@data = []
refresh
end
#--------------------------------------------------------------------------
# actor=
#--------------------------------------------------------------------------
def actor=(actor)
return if @actor == actor
@actor = actor
@last_item = nil
refresh
self.oy = 0
end
#--------------------------------------------------------------------------
# command_window=
#--------------------------------------------------------------------------
def command_window=(command_window)
@command_window = command_window
end
#--------------------------------------------------------------------------
# status_window=
#--------------------------------------------------------------------------
def status_window=(status_window)
@status_window = status_window
end
#--------------------------------------------------------------------------
# refresh
#--------------------------------------------------------------------------
def refresh
make_item_list
create_contents
draw_all_items
end
#--------------------------------------------------------------------------
# make_item_list
#--------------------------------------------------------------------------
def make_item_list
@data = []
@data.push("List Item 1")
@data.push("List Item 2")
end
#--------------------------------------------------------------------------
# draw_item
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
if item
rect = item_rect(index)
rect.width -= 4
draw_item_name(item, rect.x, rect.y, enable?(item))
draw_item_number(rect, item)
end
end
end -
Window_Command is for lists of menu commands, not for displaying usable items. If you just want to display a different set of items, I'd recommend making a subclass of Window_ItemList and modifying the make_item_list, include?, draw_item and update_help methods.
Also in your code above you're adding items to @data as strings, then in draw_item calling draw_item_name / draw_item_number to draw them. If you want to display strings, you should be using draw_text. Window_ItemList uses draw_item_name because its @data elements are RPG::Items.