73 lines
2.6 KiB
Ruby
73 lines
2.6 KiB
Ruby
#==============================================================================
|
|||
|
|
# LonaCraft - 10_Icons.rb
|
||
|
|
# What it does:
|
||
|
|
# * Aliases Cache.system so that a request for "Iconset" returns the game's
|
||
|
|
# Graphics/System/Iconset.png with the mod's
|
||
|
|
# Graphics/System/Iconset_LonaCraft.png pasted below it.
|
||
|
|
# * Every integer-icon draw path in the game and RolePlayS goes through
|
||
|
|
# Cache.system("Iconset") (Window_Base#draw_icon 53_Window_Base.rb:623,
|
||
|
|
# item/equip menus, HUD hotkeys, popups), so all of them see the mod icons.
|
||
|
|
# * The merged bitmap is built once and kept (rebuilt only if disposed).
|
||
|
|
#
|
||
|
|
# Index math (53_Window_Base.rb:624): x = index % 16 * 24, y = index / 16 * 24.
|
||
|
|
# The game sheet is pasted at y=0; the mod sheet at y = rows*24 where
|
||
|
|
# rows = game sheet height / 24 rounded up. Mod icon index = rows*16 + cell.
|
||
|
|
# B.0.10.8.26: 1304 px high -> rows 55 -> mod icons start at 880.
|
||
|
|
#==============================================================================
|
||
|
|
module LonaCraft
|
||
|
|
def self.iconset_file
|
||
|
|
resource("Graphics/System/Iconset_LonaCraft.png")
|
||
|
|
end
|
||
|
|
|
||
|
|
# Returns the merged sheet, or nil if it cannot be built (then the game's
|
||
|
|
# own sheet is used and the mod icons draw empty).
|
||
|
|
def self.merged_iconset
|
||
|
|
return @iconset if @iconset && !@iconset.disposed?
|
||
|
|
return nil if @iconset_failed
|
||
|
|
begin
|
||
|
|
base = Cache.system_lonacraft_orig("Iconset")
|
||
|
|
sheet = Bitmap.new(iconset_file)
|
||
|
|
rows = (base.height + ICON_SIZE - 1) / ICON_SIZE
|
||
|
|
width = base.width > sheet.width ? base.width : sheet.width
|
||
|
|
# B.0.10.8.26: 384 x (1320 + 120). Refuse a merge that would make a
|
||
|
|
# giant Bitmap (the game's own sheet is used then, see the rescue).
|
||
|
|
if width > 2048 || rows * ICON_SIZE + sheet.height > 8192
|
||
|
|
sheet.dispose
|
||
|
|
raise "sheet too large (#{width} x #{rows * ICON_SIZE + sheet.height})"
|
||
|
|
end
|
||
|
|
merged = Bitmap.new(width, rows * ICON_SIZE + sheet.height)
|
||
|
|
merged.blt(0, 0, base, base.rect)
|
||
|
|
merged.blt(0, rows * ICON_SIZE, sheet, sheet.rect)
|
||
|
|
sheet.dispose
|
||
|
|
@icon_base = rows * ICON_COLUMNS
|
||
|
|
@iconset = merged
|
||
|
|
rescue => e
|
||
|
|
@iconset_failed = true
|
||
|
|
@iconset = nil
|
||
|
|
p "LonaCraft: iconset merge failed #{e.message}"
|
||
|
|
end
|
||
|
|
@iconset
|
||
|
|
end
|
||
|
|
|
||
|
|
def self.icon_base
|
||
|
|
merged_iconset
|
||
|
|
@icon_base || ICON_BASE_FALLBACK
|
||
|
|
end
|
||
|
|
|
||
|
|
def self.icon_index(cell)
|
||
|
|
icon_base + cell
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
class << Cache
|
||
|
|
unless method_defined?(:system_lonacraft_orig)
|
||
|
|
alias_method :system_lonacraft_orig, :system
|
||
|
|
def system(filename)
|
||
|
|
if filename.to_s.downcase == "iconset"
|
||
|
|
merged = LonaCraft.merged_iconset
|
||
|
|
return merged if merged
|
||
|
|
end
|
||
|
|
system_lonacraft_orig(filename)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|