I am currently working on making a CMS for my game but i kinda hit a wall in one respect. I would like to display my skills on several 'pages', by this i mean that i want to show the first 6 skills in the window, then when right is pressed it will draw the next 6 items, i just need to know how to make the left/right page switching work....
EDIT:
after a bit of fiddleing i figured it out: i added a parameter to the initialize method and used global variables to keep track of what page i was on, then added conditions to whether left or right was pushed that change the page variable and dispose of the menu and re-initialize it with the new page #.
here's the old code:
[spoiler]class Test_Menu_9 < Window_Selectable
def initialize(actor)
super(0, 0, 450, 235)
@actor = actor
@item_max = 6
refresh
self.index = 0
end
def skill
return @data[self.index]
end
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
for i in 0...@actor.skills.size
skill = $data_skills[@actor.skills[i]]
if skill != nil
# if @actor.skill_can_use?(skill.id)
@data.push(skill)
# end
end
@column_max = ((@data.size - 1) / 6) +1
end
# If the number of items is not 0, it draws up bit map, drawing all item
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
self.contents.font.name = $fontface
self.contents.font.size = $fontsize
for i in 0...@item_max
draw_item(i)
end
end
end
def draw_item(index)
skill = @data[index]
x = 0
y = index * 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(skill.icon_name)
self.contents.blt(x, y, bitmap, Rect.new(0, 0, 24, 24), 255)
self.contents.draw_text(x + 30, y, 204, 32, skill.name, 0)
self.contents.draw_text(x + 200, y, 48, 32, skill.sp_cost.to_s, 2)
end
end
class Test_Scene_2
#BLOCK 1
def main
@window_1=Test_Menu_7.new
@window_8=Test_Menu_8.new
@window_8.x=190
@window_3=Test_Menu_11.new($Character_Id_I_Am_Working_With)
@window_3.y=80
@window_9=Test_Menu_9b.new($game_party.actors[$Character_Id_I_Am_Working_With])
@window_9.x=190
@window_9.y=55
@window_10=Test_Menu_10.new
@window_10.x=190
@window_10.y=290
@window_6=Test_Menu_6.new
@window_6.x=190
@window_6.y=395
#BLOCK 2
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
#BLOCK 3
Graphics.freeze
@window_1.dispose
@window_8.dispose
@window_3.dispose
@window_9.dispose
@window_10.dispose
@window_6.dispose
end
#BLOCK 4
def update
@window_9.update
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
end
end
end[/spoiler]
and the new code:
[spoiler]class Test_Menu_9b < Window_Selectable
def initialize(actor, thepage)
super(0, 0, 450, 235)
@actor = actor
$my_current_page = thepage
$my_current_page_start = thepage * 6
$my_current_page_end = $my_current_page_start + 5
@item_max = 6
refresh
self.index = 0
end
def skill
return @data[self.index]
end
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
for i in $my_current_page_start..$my_current_page_end
if i<@actor.skills.size
skill = $data_skills[@actor.skills[i]]
if skill != nil
# if @actor.skill_can_use?(skill.id)
@data.push(skill)
$my_number_pages = ((@actor.skills.size - 1) / 6)
# end
end
end
end
# If the number of items is not 0, it draws up bit map, drawing all item
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
self.contents.font.name = $fontface
self.contents.font.size = $fontsize
for i in 0...@item_max
draw_item(i)
end
end
end
def draw_item(index)
skill = @data[index]
x = 0
y = index * 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(skill.icon_name)
self.contents.blt(x, y, bitmap, Rect.new(0, 0, 24, 24), 255)
self.contents.draw_text(x + 30, y, 204, 32, skill.name, 0)
self.contents.draw_text(x + 200, y, 48, 32, skill.sp_cost.to_s, 2)
end
end
class Test_Scene_2
#BLOCK 1
def main
@window_1=Test_Menu_7.new
@window_8=Test_Menu_8.new
@window_8.x=190
@window_3=Test_Menu_11.new($Character_Id_I_Am_Working_With)
@window_3.y=80
@window_9=Test_Menu_9b.new($game_party.actors[$Character_Id_I_Am_Working_With], 0)
@window_9.x=190
@window_9.y=55
@window_10=Test_Menu_10.new
@window_10.x=190
@window_10.y=290
@window_6=Test_Menu_6.new
@window_6.x=190
@window_6.y=395
#BLOCK 2
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
#BLOCK 3
Graphics.freeze
@window_1.dispose
@window_8.dispose
@window_3.dispose
@window_9.dispose
@window_10.dispose
@window_6.dispose
end
#BLOCK 4
def update
@window_9.update
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
end
if Input.trigger?(Input::LEFT)
if $my_current_page > 0
@window_9.dispose
$my_current_page = $my_current_page - 1
@window_9=Test_Menu_9b.new($game_party.actors[$Character_Id_I_Am_Working_With], $my_current_page)
@window_9.x=190
@window_9.y=55
end
end
if Input.trigger?(Input::RIGHT)
if $my_current_page < $my_number_pages
@window_9.dispose
$my_current_page = $my_current_page + 1
@window_9=Test_Menu_9b.new($game_party.actors[$Character_Id_I_Am_Working_With], $my_current_page)
@window_9.x=190
@window_9.y=55
end
end
end
end[/spoiler]
i do realize it might be hard to see what i'm saying because i'm not good at explaining....so please tell me if you don't understand! I've attached the demo of what it does.