+- Save-Point (https://www.save-point.org)
+-- Forum: Archives (https://www.save-point.org/forum-105.html)
+--- Forum: Creation Asylum Archives (https://www.save-point.org/forum-90.html)
+---- Forum: Scripts & Code Snippets (https://www.save-point.org/forum-92.html)
+----- Forum: RPG Maker XP Code (https://www.save-point.org/forum-93.html)
+----- Thread: Vertical or Horizontal Menu with or without Icons (/thread-6803.html)
Vertical or Horizontal Menu with or without Icons - Tsunokiette - 12-11-2005
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.
Replace Window_Command with this script-
* Window_Command
Code:
#=========================================================
# * VH_Window_Command
#---------------------------------------------------------
# Make Horizontal or Vertical Menus with or without icons
#---------------------------------------------------------
# Version 3
# 12.15.05
#---------------------------------------------------------
# Tsunokiette
# * Give Credit *
#=========================================================
#*********************************
# Window_Command Begins
#_________________________________
# Sub-Class of (Window_Selectable)
#*********************************
class VH_Window_Command < Window_Selectable
#------------------------------------------------------------------------
# Initialization
#________________________________________________________________________
# type = what kind of menu you want (set to 'vertical' or 'horizontal')
# commands = text commands
# icons = icons to go with commands (leave empty if you don't want icons)
#------------------------------------------------------------------------
def initialize(type = 'vertical', commands = [], icons = nil)
case type
when 'vertical'
super(0, 0, 182, commands.size * 32 + 32)
when 'horizontal'
super(0, 0, 640, 64)
end
unless icons.nil?
@icons = []
for i in 0...icons.size
@icons[i] = RPG::Cache.icon(icons[i])
end
end
@item_max = commands.size
@column_max = commands.size unless type != 'horizontal'
@commands = commands
@type = type
self.contents = Bitmap.new(width - 32, height - 32)
font_properties
refresh
self.index = 0
end
#------------------------
# Set the Font Properties
#------------------------
def font_properties
self.contents.font.name = 'Times New Roman'
self.contents.font.size = 22
end
#------------------------------
# Refresh the Window's Contents
#------------------------------
def refresh
self.contents.clear
case @type
when 'vertical'
if @icons.nil?
for i in 0...@item_max
draw_v(i, normal_color)
end
else
for i in 0...@item_max
draw_v_icon(i, normal_color)
end
end
when 'horizontal'
if @icons.nil?
for i in 0...@item_max
draw_h(i, normal_color)
end
else
for i in 0...@item_max
draw_h_icon(i, normal_color)
end
end
end
end
#------------------------------------
# Draw Contents Vertically With Icons
#____________________________________
# Index = Command Location
# Color = Text Color
#------------------------------------
def draw_v_icon(index, color)
self.contents.font.color = color
x = 24
y = 32 * index
w = self.contents.width - 24
h = 32
ix = 0
iy = ((32 * index) + 4)
rect = Rect.new(x, y, w, h)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, @commands[index], 1)
@icon_sprite[index] = Sprite.new
@icon_sprite[index].bitmap = @icons[index]
@icon_sprite[index].x = ix
@icon_sprite[index].y = iy
end
#---------------------------------------
# Draw Contents Vertically Without Icons
#_______________________________________
# Index = Command Location
# Color = Text Color
#---------------------------------------
def draw_v(index, color)
self.contents.font.color = color
x = 0
y = 32 * index
w = self.contents.width
h = 32
rect = Rect.new(x,y,w,h)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, @commands[index], 1)
end
#--------------------------------------
# Draw Contents Horizontally With Icons
#______________________________________
# Index = Command Location
# Color = Text Color
#--------------------------------------
def draw_h_icon(index, color)
self.contents.font.color = color
x = (((640 / @commands.size) * @index) + 24)
y = 0
w = ((640 / @commands.size) - 24)
h = 32
ix = ((640 / @commands.size) * @index)
iy = 4
rect = Rect.new(x,y,w,h)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, @commands[index], 1)
@icon_sprite[index] = Sprite.new
@icon_sprite[index].bitmap = @icons[index]
@icon_sprite[index].x = ix
@icon_sprite[index].y = iy
end
#-----------------------------------------
# Draw contents Horizontally Without Icons
#_________________________________________
# Index = Command Location
# Color = Text Color
#-----------------------------------------
def draw_h(index, color)
self.contents.font.color = color
x = ((640 / @commands.size) * @index)
y = 0
w = 640 / @commands.size
h = 32
rect = Rect.new(x,y,w,h)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, @commands[index], 1)
end
def disable_item(index)
case @type
when 'vertical'
if @icons.nil?
draw_v(index, disabled_color)
else
draw_v_icon(index, disabled_color)
end
when 'horizontal'
if @icons.nil?
draw_h(index, disabled_color)
else
draw_h_icon(index, disabled_color)
end
end
end
#--------------
# Update Cursor
#--------------
def update_cursor_rect
unless @index >= 0
self.cursor_rect.empty unless @index >= 0
return
end
case @type
when 'vertical'
x = 0
y = @index * 32
w = self.contents.width
h = 32
self.cursor_rect.set(x, y, w, h)
when 'horizontal'
x = ((640 / @commands.size) * @index)
y = 0
w = 640 / @commands.size
h = 32
self.cursor_rect.set(x,y,w,h)
end
end
#--------------
# Alias Dispose
#--------------
alias :tsuno_UpdatedWindowCommand_VHWindowCommand_dispose :dispose
def dispose
unless @icons.nil?
for i in 0...@icons.size
@icon_sprite[i].dispose
end
end
tsuno_UpdatedWindowCommand_VHWindowCommand_dispose
end