Window_HorizCommand Addendum An RMXP SDK Patch
Version: 1.0
Introduction
The Window_HorizCommand class from the RMXP SDK (v 2.4) did allow one to make a horizontal command window. However, it forced all the command options to appear simultaneously within the same window. No option was off-screen or invisible and the window did not allow for left-to-right scrolling.
This addendum permits you to create horizontal command windows WITH THE Window_HorizCommand class while showing only a limited number of options whilst you can scroll left-right to uncover them.
Script
The Script
Code:
#==============================================================================
# ** Window_HorizCommand Addendum
# Based on the 'Window_HorizCommand" from thr RMXP SDK
#------------------------------------------------------------------------------
# by DerVVulfman
# version 1.0
# 06-15-2020 (mm/dd/yyyy)
# RGSS / RPGMaker XP
#==============================================================================
#
# The Window_HorizCommand class from the RMXP SDK (v 2.4) did allow one to
# make a horizontal command window. However, it forced all the command
# options to appear simultaneously within the same window. No option was
# off-screen or invisible and the window did not allow for left-to-right
# scrolling.
#
# This addendum permits you to create horizontal command windows WITH THE
# Window_HorizCommand class while showing only a limited number of options
# whilst you can scroll left-right to uncover them.
#
# To use, ensure the 'adaption' value is made true after creating your
# horizontal window, otherwise, the options within this script will not be
# used.
#
# EX: @score_window = Window_Score.new
# @score_window.adaption = true
#
# NOTE: Cursor command options have not been altered in any way. The
# ability to change the Index position and the use of the Arrow
# keys were untouched.
#
#==============================================================================
#==============================================================================
# ** Window_HorizCommand
#------------------------------------------------------------------------------
# This window deals with general command choices. (Horizontal)
#==============================================================================
class Window_HorizCommand < Window_Selectable
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :adaption # Adation usage flag
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias win_horizcommand_addendum_initialize initialize
alias win_horizcommand_addendum_update_cursor_rect update_cursor_rect
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(width, commands, c_spacing = (width - 32) / commands.size)
# New Option added for switch control
@adaption = false
# Perform the original call
win_horizcommand_addendum_initialize(width, commands, c_spacing)
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
# Exit if adaption is off
return if @adaption != true
# Update help text (update_help is defined by the subclasses)
if self.active and @help_window != nil
update_help
end
# Update cursor rectangle
update_cursor_rect
end
#--------------------------------------------------------------------------
# * Get Top Row
#--------------------------------------------------------------------------
def left_item
# Divide x-coordinate of window contents transfer origin by 1 row
# width of c_spacing
return self.ox / @c_spacing
end
#--------------------------------------------------------------------------
# * Set Top Row
# row : row shown on top
#--------------------------------------------------------------------------
def left_item=(item)
# If item is less than 0, change it to 0
item = 0 if item < 0
# If item exceeds item_left_max - 1, change it to item_left_max - 1
item = item_left_max - 1 if item > item_left_max - 1
# Multiply 1 item width by c_spacing for z-coordinate of window contents
# transfer origin
self.ox = item * @c_spacing
end
#--------------------------------------------------------------------------
# * Get Row Count
#--------------------------------------------------------------------------
def item_left_max
# Compute items
return @item_max +1
end
#--------------------------------------------------------------------------
# * Get Number of Rows Displayable on 1 Page
#--------------------------------------------------------------------------
def page_left_max
# Subtract a frame width of c_spacing from the window width, and divide
# it by 1 item width of c_spacing
if ((self.width - 32) / @c_spacing) == 0
return 1
elsif ((self.width - 32) / @c_spacing) % 2 == 0
return ((self.width - 32) / @c_spacing)
end
return ((self.width - 32) / @c_spacing) + 1
end
#--------------------------------------------------------------------------
# * Cursor Rectangle Update
#--------------------------------------------------------------------------
def update_cursor_rect
# Run the original version if adaption is off
if @adaption != true
win_horizcommand_addendum_update_cursor_rect
return
end
# If cursor position is less than 0
return self.cursor_rect.empty if @index < 0
# Get current horizontal item
item = @index
# If current item is before leftmost item
if item < self.left_item
# Scroll so that current row becomes top row
self.left_item = item
end
# If current row is more to back than back row
if item > self.left_item + (self.page_left_max - 1)
# Scroll so that current row becomes back row
self.left_item = item - (self.page_left_max - 1)
end
# Calculate cursor coordinates
cursor_x = (@index * @c_spacing) - self.ox
# Update cursor rectangle
self.cursor_rect.set(cursor_x, 0, @c_spacing, 32)
end
end
Author's Puzzlement
I wonder why they never considered that the horizontal bar would scroll like this???
Compatibility
Designed solely for the Window_HorizCommand class from the RMXP SDK (v 2.4)
Terms of Use
Free and clear, even for commercial project. Due credit is all that is required.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)