From d408be0348d4ba6c066a89d5ac438748b377a03a Mon Sep 17 00:00:00 2001 From: bellyillish Date: Fri, 22 Dec 2023 11:58:14 -0500 Subject: [PATCH] v2.2 --- README.md | 1 - gamedata/scripts/dart_config.script | 70 +++--- gamedata/scripts/dart_core.script | 42 ++-- gamedata/scripts/dart_dxml.script | 233 ++++++++++++------ gamedata/scripts/dart_module.script | 84 ++++--- gamedata/scripts/dart_utils.script | 230 ++++++++--------- .../scripts/modxml_z_dart_ammo_wheel.script | 53 ++-- gamedata/scripts/modxml_z_dart_bhs.script | 94 ++++--- .../modxml_z_dart_companion_list.script | 72 +++--- .../modxml_z_dart_companion_wheel.script | 43 ++-- .../scripts/modxml_z_dart_inventory.script | 14 +- gamedata/scripts/modxml_z_dart_markers.script | 115 +++++---- .../scripts/modxml_z_dart_messages.script | 38 ++- gamedata/scripts/modxml_z_dart_minimap.script | 41 ++- gamedata/scripts/modxml_z_dart_patches.script | 44 ++-- gamedata/scripts/modxml_z_dart_scopes.script | 71 ++++-- .../scripts/modxml_z_dart_status_icons.script | 62 +++-- .../scripts/zzz_dart_companion_list.script | 11 +- gamedata/scripts/zzz_dart_inventory.script | 27 +- gamedata/scripts/zzz_dart_patches.script | 51 ++-- gamedata/scripts/zzz_dart_status_icons.script | 90 ++++--- 21 files changed, 814 insertions(+), 672 deletions(-) diff --git a/README.md b/README.md index 8b45fb6..7e0506e 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,6 @@ DART is customizable via a config file that allows you to move and scale various ## Installation: Install with MO2. Choose "00 Dart Core (Required)" plus any/all fixes during installation. The safest place to install is at the bottom of load order, but in most cases priority won't matter. -- Get v2.0.1 here: https://discord.com/channels/912320241713958912/1169311822139105380/1184663998109597778 - GitHub: https://github.com/bellyillish/dart - Discord: https://discord.com/channels/912320241713958912/1169311822139105380/1169311822139105380 diff --git a/gamedata/scripts/dart_config.script b/gamedata/scripts/dart_config.script index 3f63bd5..4de9013 100644 --- a/gamedata/scripts/dart_config.script +++ b/gamedata/scripts/dart_config.script @@ -1,65 +1,59 @@ -local Dart = Dart_core +local config = dart_core.config -- moves HUD elements [n] pixels closer to the center of the screen -Dart.config.safezone = 0 +config.safezone = 0 -- move an element by {x, y} pixels -- positive values move down and to the right -Dart.config.ammoWheel.offset = {0, 0} -Dart.config.bhs.offset = {8, 0} -Dart.config.companionList.offset = {-12, -96} -Dart.config.companionWheel.offset = {0, 0} -Dart.config.messages.offset = {0, -12} -Dart.config.minimap.offset = {0, 0} -Dart.config.patches.offset = {12, 0} -Dart.config.statusIcons.offset = {-4, -8} +config.ammoWheel.offset = {0, 0} +config.bhs.offset = {8, 0} +config.companionList.offset = {-12, -96} +config.companionWheel.offset = {0, 0} +config.messages.offset = {0, -12} +config.minimap.offset = {0, 0} +config.patches.offset = {12, 0} +config.statusIcons.offset = {-4, -8} -- make an element [n] times its normal size -- results may vary (e.g. text never scales) -Dart.config.ammoWheel.scale = 1 -Dart.config.bhs.scale = 1 -Dart.config.companionList.scale = 1 -Dart.config.companionWheel.scale = 1 -Dart.config.inventory.scale = 1 -- scales icons -Dart.config.minimap.scale = 1 -Dart.config.messages.scale = 1 -Dart.config.patches.scale = 1.25 -- scales patches -Dart.config.statusIcons.scale = 0.75 - - --- scales an element relative to current screen size --- (the element gets smaller as the screen size increases) --- this exists mostly for the companion list which does this anyway --- results will vary depending on the element -Dart.config.ammoWheel.autoscale = false -Dart.config.bhs.autoscale = false -Dart.config.companionList.autoscale = true -Dart.config.companionWheel.autoscale = false -Dart.config.inventory.autoscale = false -Dart.config.messages.autoscale = false -Dart.config.minimap.autoscale = false -Dart.config.patches.autoscale = false -Dart.config.statusIcons.autoscale = false +config.ammoWheel.scale = 1 +config.bhs.scale = 1 +config.companionList.scale = 1 +config.companionWheel.scale = 1 +config.inventory.scale = 1 -- scales icons +config.minimap.scale = 1 +config.messages.scale = 1 +config.patches.scale = 1.25 -- scales patches +config.statusIcons.scale = 1 -- scales the space between inventory icons -- I've seen screwy things like missing icons so use with caution -- I've you have icon issues you can try making this '0' -Dart.config.inventory.padScale = 1 +config.inventory.padScale = 1 + + +-- move the minimap to another part of the screen +-- e.g. {"CENTER", "BOTTOM"} +config.minimap.align = nil -- adjust the transparency of the minimap (0-255) -- nil value will use the value in the XML file -Dart.config.minimap.alpha = nil +config.minimap.alpha = nil -- move the minimap clock by {x, y} pixels -Dart.config.minimap.clockOffset = {0, 0} +config.minimap.clockOffset = {0, 0} -- use cicular ammo wheel (instead of the triangle) -- probably better to turn off if you're using a mod that skins the UI/wheel -Dart.config.ammoWheel.roundWheel = true +config.ammoWheel.roundWheel = true + + +-- controls the spacing between status icons +config.statusIcons.spacing = 2 diff --git a/gamedata/scripts/dart_core.script b/gamedata/scripts/dart_core.script index 914b60e..5b92522 100644 --- a/gamedata/scripts/dart_core.script +++ b/gamedata/scripts/dart_core.script @@ -1,12 +1,11 @@ -- default config config = { - loglimit = 10, + logLimit = 10, safezone = 0, ammoWheel = { anchor = {"CENTER", "CENTER"}, offset = {0, 0}, - autoscale = false, scale = 1, roundWheel = true, }, @@ -14,7 +13,6 @@ config = { bhs = { anchor = {"LEFT", "BOTTOM"}, offset = {8, 0}, - autoscale = false, safezone = true, scale = 1, }, @@ -22,7 +20,6 @@ config = { companionList = { anchor = {"RIGHT", "BOTTOM"}, offset = {-12, 96}, - autoscale = true, safezone = true, scale = 1, }, @@ -30,12 +27,10 @@ config = { companionWheel = { anchor = {"CENTER", "CENTER"}, offset = {0, 0}, - autoscale = false, scale = 1, }, inventory = { - autoscale = false, scale = 1, padScale = 1, }, @@ -45,7 +40,6 @@ config = { messages = { anchor = {"LEFT", "BOTTOM"}, offset = {0, -12}, - autoscale = false, safezone = true, scale = 1, }, @@ -53,9 +47,9 @@ config = { minimap = { anchor = {"RIGHT", "BOTTOM"}, offset = {0, 0}, - autoscale = false, safezone = true, scale = 1, + align = nil, alpha = nil, clockOffset = {0, 0}, }, @@ -63,7 +57,6 @@ config = { patches = { anchor = {"LEFT", "BOTTOM"}, offset = {12, 0}, - autoscale = false, safezone = true, scale = 1.25, }, @@ -73,14 +66,26 @@ config = { statusIcons = { anchor = {"LEFT", "BOTTOM"}, offset = {-4, -8}, - autoscale = false, safezone = true, - scale = 0.75, + scale = 1, + spacing = 2, }, } -- holds state to share data across files -state = {} +state = { + ammoWheel = {}, + bhs = {}, + companionList = {}, + companionWheel = {}, + inventory = {}, + markers = {}, + messages = {}, + minimap = {}, + patches = {}, + scopes = {}, + statusIcons = {}, +} -- consts baseWidth = 1024 @@ -104,7 +109,6 @@ defaultScaleSettings = { align = nil, bounds = screenBounds, offset = {0, 0}, - autoscale = false, safezone = false, scale = 1, } @@ -114,7 +118,6 @@ xmlFileSuffixes = { [""] = ratio16x9, ["16"] = ratio16x9, ["21"] = ratio21x9, - ["32"] = ratio32x9, } -- override aspect ratios for these files @@ -122,8 +125,17 @@ xmlAspectRatios = { ["ui\\ui_hud.xml"] = ratio4x3, } --- replace entire files with files on right + +-- replace files on left with ones on right xmlFileReplacements = { ["ui\\zone_map_21.xml"] = "ui\\zone_map_16.xml", ["ui\\scopes_21.xml"] = "ui\\scopes_16.xml", } + + +-- template for missing left/right scope fillers +scopeFillerTemplate = [[ + + %s + +]] diff --git a/gamedata/scripts/dart_dxml.script b/gamedata/scripts/dart_dxml.script index acd0ac1..42c2a3c 100644 --- a/gamedata/scripts/dart_dxml.script +++ b/gamedata/scripts/dart_dxml.script @@ -1,89 +1,109 @@ -local Dart = Dart_core +local Dart = dart_core local Utils = dart_utils --- split path into basepath and suffix - -- "a\b\c_16.xml" => "a\b\c", "16" +local REPLACEMENT_QUEUE = {} + + +-- split path into filename, alias, ratio +-- "ui\foo_16.xml" => "foo_16.xml", "foo", "16" function splitPath(path) - return path:match("(%w[_%w\\]+%a)_?(%d?%d?)%d*.xml$") + return path:match("ui\\(([_%w]-)_?(%d?%d?)%d*.xml)$") +end + + +-- transfer contents of one XML object to another +function transferXML(FXML, TXML) + TXML.xml_table.kids = FXML.xml_table.kids end --- returns true if path and basepath match -function matchesPath(path, basepath) - local base, suffix = splitPath(path) - return base == basepath, suffix +-- retrieve an entry from REPLACEMENT_QUEUE +function getQueuedReplacement(path) + return REPLACEMENT_QUEUE[path] end --- substitute one XML file for another -function replaceWithFile(DXML, path, dispatch) - local children = {} +-- queue replacement of XML with another file +function requestReplacement(XML, path) + REPLACEMENT_QUEUE[path] = XML + local file = splitPath(path) - -- can't remove element directly - safeIterate(DXML, function(child) - table.insert(children, child) - end) + function load() + CScriptXmlInit():ParseFile(file) + end + + local status = pcall(load) - for _, child in ipairs(children) do - DXML:removeElement(child) + if not status then + REPLACEMENT_QUEUE[path] = nil end - DXML:insertFromXMLFile(path, nil, nil, true) + return status +end + + +-- settle a queued replacement request +function settleReplacement(XML, path) + local TXML = REPLACEMENT_QUEUE[path] - -- re-dispatch "on_xml_read" - if dispatch ~= false then - dxml_core.xmlDispatch(path, DXML) + if not TXML then + return false end + + REPLACEMENT_QUEUE[path] = nil + transferXML(XML, TXML) + + return true end --- detect XML source aspect ratio using filename and special rules -function getXMLAspectRatio(DXML, path) - local _, suffix = splitPath(path) +-- detect source aspect ratio from path and rules +function getXMLAspectRatio(XML, path) + local _, _, ratio = splitPath(path) return Dart.xmlAspectRatios[path] - or Dart.xmlFileSuffixes[suffix] + or Dart.xmlFileSuffixes[ratio] or Dart.ratio16x9 end --- like DXML:isElement() but does not throw -function safeIsElement(DXML, element) - return element and element.el and DXML:isElement(element) +-- like XML:isElement() but does not throw +function safeIsElement(XML, element) + return element and element.el and XML:isElement(element) end --- like DXML:getElementAttr() but sanitizes numeric values -function safeGetAttrs(DXML, element) - return Utils.sanitizeAttrs(DXML:getElementAttr(element)) +-- like XML:getElementAttr() but sanitizes values +function safeGetAttrs(XML, element) + return Utils.validateAttrs(XML:getElementAttr(element) or {}) end --- like DXML:setElementAttr() but you can also pass a callback - -- callback passes current (sanitized) attributes -function safeSetAttrs(DXML, element, attrs) +-- like XML:setElementAttr() but accepts callbacks that pass current attrs +function safeSetAttrs(XML, element, attrs) if type(attrs) == "function" then - attrs = attrs(safeGetAttrs(DXML, element) or {}) + attrs = attrs(safeGetAttrs(XML, element)) end - DXML:setElementAttr(element, attrs) + + XML:setElementAttr(element, attrs) end --- like DXML:iterateChildren() but only passes elements - -- element is optional and defaults to root - -- values returned from callback are collected and returned -function safeIterate(DXML, element, callback) +-- like XML:iterateChildren() but only iterates elements +-- element is optional and defaults to XML:getRoot() +-- return values from callback are collected and returned +function safeIterate(XML, element, callback) if not callback and type(element) == "function" then callback = element - element = DXML:getRoot() + element = XML:getRoot() end local results - DXML:iterateChildren(element, function(child, index) - if not safeIsElement(DXML, child) then + XML:iterateChildren(element, function(child, index) + if not safeIsElement(XML, child) then return end @@ -101,18 +121,18 @@ function safeIterate(DXML, element, callback) end --- find {l, r, t, b} bounds of [n] elements (defaults to children of root) -function getElementBounds(DXML, ...) +-- find {l, r, t, b} bounds of [n] elements (or XML:getRoot().kids) +function getElementBounds(XML, ...) local args = {...} local attrs = {} if #args == 0 then - args = DXML:getRoot().kids + args = XML:getRoot().kids end Utils.ipairscb(args, function(element) - if safeIsElement(DXML, element) then - attrs[#attrs + 1] = safeGetAttrs(DXML, element) + if safeIsElement(XML, element) then + attrs[#attrs + 1] = safeGetAttrs(XML, element) end end) @@ -120,52 +140,123 @@ function getElementBounds(DXML, ...) end --- scale an element to current aspect ratio -function scaleElement(DXML, element, targetRatio, settings) - local attrs = safeGetAttrs(DXML, element) or {} - local scaled = Utils.scaleAttrs(attrs, targetRatio, settings) +-- aspect ratio corrections +function correctElementX(XML, element, targetRatio, settings) + local x = tonumber(safeGetAttrs(XML, element).x) + if x then + safeSetAttrs(XML, element, { + x = Utils.correctX(x, targetRatio, settings) + }) + end +end + + +function correctElementY(XML, element, targetRatio, settings) + local y = tonumber(safeGetAttrs(XML, element).y) + if y then + safeSetAttrs(XML, element, { + y = Utils.correctY(y, targetRatio, settings) + }) + end +end + + +function correctElementW(XML, element, targetRatio, settings) + local width = tonumber(safeGetAttrs(XML, element).width) + if width then + safeSetAttrs(XML, element, { + width = Utils.correctW(width, targetRatio, settings) + }) + end +end + + +function correctElementH(XML, element, targetRatio, settings) + local height = tonumber(safeGetAttrs(XML, element).height) + if height then + safeSetAttrs(XML, element, { + height = Utils.correctH(height, targetRatio, settings) + }) + end +end + + +function correctElementXY(XML, element, targetRatio, settings) + local attrs = safeGetAttrs(XML, element) + safeSetAttrs(XML, element, Utils.correctXY(attrs, targetRatio, settings)) +end + + +function correctElementWH(XML, element, targetRatio, settings) + local attrs = safeGetAttrs(XML, element) + safeSetAttrs(XML, element, Utils.correctWH(attrs, targetRatio, settings)) +end - safeSetAttrs(DXML, element, scaled) - return scaled +function correctElement(XML, element, targetRatio, settings) + local attrs = safeGetAttrs(XML, element) + safeSetAttrs(XML, element, Utils.correctAttrs(attrs, targetRatio, settings)) end --- Extend a DXML object with methods and properties -function extendXMLObject(DXML, path) - local basepath, suffix = splitPath(path) +-- Extend an XML object with methods and properties +function extendXMLObject(XML, path) + local file, alias, ratio = splitPath(path) - if not basepath then - error("Unexpected filename passed to DXML: " .. path) + if not file then + error("Unexpected filename passed to XML: " .. path) end - DXML.isExtended = true - DXML.path = path - DXML.basepath = basepath - DXML.aspectRatio = getXMLAspectRatio(DXML, path) + XML.isExtended = true + XML.path = path + XML.aspectRatio = getXMLAspectRatio(XML, path) - function DXML:safeIsElement(element) + function XML:safeIsElement(element) return safeIsElement(self, element) end - function DXML:safeIterate(element, callback) + function XML:safeIterate(element, callback) return safeIterate(self, element, callback) end - function DXML:safeGetAttrs(element) + function XML:safeGetAttrs(element) return safeGetAttrs(self, element) end - function DXML:safeSetAttrs(element, attrs) + function XML:safeSetAttrs(element, attrs) return safeSetAttrs(self, element, attrs) end - function DXML:scaleElement(element, settings) - return scaleElement(self, element, self.aspectRatio, settings) + function XML:getBounds(...) + return getElementBounds(self, ...) end - function DXML:getElementBounds(...) - return getElementBounds(self, ...) + function XML:correctX(element, settings) + return correctElementX(self, element, self.aspectRatio, settings) + end + + function XML:correctY(element, settings) + return correctElementY(self, element, self.aspectRatio, settings) + end + + function XML:correctW(element, settings) + return correctElementW(self, element, self.aspectRatio, settings) + end + + function XML:correctH(element, settings) + return correctElementH(self, element, self.aspectRatio, settings) + end + + function XML:correctXY(element, settings) + return correctElementXY(self, element, self.aspectRatio, settings) + end + + function XML:correctWH(element, settings) + return correctElementWH(self, element, self.aspectRatio, settings) + end + + function XML:correctElement(element, settings) + return correctElement(self, element, self.aspectRatio, settings) end end diff --git a/gamedata/scripts/dart_module.script b/gamedata/scripts/dart_module.script index 76f1297..4e5aba5 100644 --- a/gamedata/scripts/dart_module.script +++ b/gamedata/scripts/dart_module.script @@ -1,19 +1,19 @@ -local Dart = Dart_core -local Utils = dart_utils -local DartDXML = dart_dxml +local Dart = dart_core +local Utils = dart_utils +local DXML = dart_dxml --- check if a DART module is disabled (placeholder) +-- (placeholder) check if a DART module is disabled function isDisabled(mod) return false end -- create a module logger - -- suppresses repeated logs after [config.loglimit] times -function createLogger(module) - module = (module and module ~= "DART") - and "DART:" .. module +-- suppresses repeated logs after [config.logLimit] times +function createLogger(mod) + mod = (mod and string.upper(mod) ~= "DART") + and "DART:" .. mod or "DART" local calls = {} @@ -25,17 +25,17 @@ function createLogger(module) calls[message] = 0 end - if calls[message] >= Dart.config.loglimit then + if calls[message] >= Dart.config.logLimit then return end calls[message] = calls[message] + 1 - local note = calls[message] == Dart.config.loglimit + local note = calls[message] == Dart.config.logLimit and " (suppressing)" or "" - printf("[%s] %s%s", module, message, note) + printf("[%s] %s%s", mod, message, note) end function clear() @@ -46,20 +46,20 @@ function createLogger(module) end --- create a module DXML cacher -function createCache(module) +-- create a module XML cacher +function createCache(mod) local cache = {} - local function has(filename) - return cache[filename] ~= nil + local function has(path) + return cache[path] ~= nil end - local function set(filename, DXML) - cache[filename] = DXML.xml_table.kids + local function set(path, XML) + cache[path] = XML end - local function apply(filename, DXML) - DXML.xml_table.kids = cache[filename] + local function apply(path, XML) + DXML.transferXML(cache[path], XML) end local function clear() @@ -67,8 +67,8 @@ function createCache(module) end return { - has = has, - set = set, + has = has, + set = set, apply = apply, clear = clear, } @@ -76,50 +76,62 @@ end -- create a module's on_xml_read callback -function createXMLCallback(mod, basepath, ...) +function createXMLCallback(mod, targetAlias, ...) local log = createLogger(mod) local cache = createCache(mod) local fns = {...} - return function(path, DXML) - if not DartDXML.matchesPath(path, basepath) then + return function(path, XML) + local _, alias = DXML.splitPath(path) + + if targetAlias ~= alias then return end local replacement = Dart.xmlFileReplacements[path] if replacement then - log("Replacing %s", path) - return DartDXML.replaceWithFile(DXML, replacement) + log("Replacing %s with %s", path, replacement) + + if DXML.requestReplacement(XML, replacement) then + log("Done with %s", path) + return + else + log("Unable to replace %s with %s", path, replacement) + end end if cache.has(path) then - log("Using cache for %s", path) - return cache.apply(path, DXML) + return cache.apply(path, XML) end - DartDXML.extendXMLObject(DXML, path) + DXML.extendXMLObject(XML, path) - log("Parsing %s (as %s)", path, Utils.getAspectRatioLabel(DXML.aspectRatio)) + local ratioLabel = Utils.getAspectRatioLabel(XML.aspectRatio) local clock = os.clock() for _, fn in ipairs(fns) do - fn(DXML) + fn(XML) end - log("Parsed %s in %.3fs", path, os.clock() - clock) - cache.set(path, DXML) + log("Parsed %s (%s) in %.3fs", path, ratioLabel, os.clock() - clock) + cache.set(path, XML) + + if DXML.getQueuedReplacement(path) then + DXML.settleReplacement(XML, path) + end end end -- create and register a module's on_xml_read callback -function registerModule(mod, basepath, ...) +function registerModule(mod, alias, ...) if isDisabled(mod) then - return createLogger(mod)("Disabled, skipping %s", basepath) + createLogger(mod)("Disabled, skipping %s", alias) + return end RegisterScriptCallback("on_xml_read", - createXMLCallback(mod, basepath, ...) + createXMLCallback(mod, alias, ...) ) end diff --git a/gamedata/scripts/dart_utils.script b/gamedata/scripts/dart_utils.script index 99ddbc3..d360312 100644 --- a/gamedata/scripts/dart_utils.script +++ b/gamedata/scripts/dart_utils.script @@ -1,4 +1,4 @@ -local Dart = Dart_core +local Dart = dart_core function isUsing3DPDA() @@ -6,26 +6,6 @@ function isUsing3DPDA() end -function cosd(degrees) - return math.cos(math.rad(degrees)) -end - - -function sind(degrees) - return math.sin(math.rad(degrees)) -end - - -function abcosd(degrees) - return math.abs(cosd(degrees)) -end - - -function absind(degrees) - return math.abs(sind(degrees)) -end - - function getAspectRatio() return device().width / device().height end @@ -36,7 +16,6 @@ function getAspectRatioVs(otherRatio) end --- get a friendly display label for an aspect ratio function getAspectRatioLabel(aspectRatio) local label = ({ [Dart.ratio4x3] = "4:3", @@ -54,8 +33,8 @@ end -- callback version of ipairs - -- `return [nil]` acts like filter() - -- `return [value]` acts like map() +-- `return nil` acts like filter() +-- `return value` acts like map() function ipairscb(thing, callback) local results @@ -75,8 +54,8 @@ end -- callback version of pairs - -- `return [nil]` acts like filter() - -- `return [key], [value]` maps to new key and value +-- `return nil` acts like filter() +-- `return key, value` maps to new table function pairscb(thing, callback) local results @@ -94,6 +73,7 @@ function pairscb(thing, callback) return results end + -- merge [n] number of indexed tables function imerge(...) local args = {...} @@ -124,22 +104,6 @@ function merge(...) end --- reset and flag invalid numeric attributes -function sanitizeAttrs(attrs) - local toSanitize = {"x", "y", "width", "height"} - local errors = {} - - for _, name in ipairs(toSanitize) do - if attrs[name] and not tonumber(attrs[name]) then - errors[name] = attrs[name] - attrs[name] = nil - end - end - - return attrs, #errors == 0 and nil or errors -end - - -- find {l, r, t, b} bounds of [n] attributes function getBounds(...) local args = {...} @@ -167,39 +131,39 @@ function getBounds(...) end --- combine given scale with autoscale -function addAutoscale(scale) - return (scale or 1) * Dart.baseHeight / device().height +-- reset and flag invalid numeric attributes +-- guards against crashes from invalid XML attributes +function validateAttrs(attrs) + local toSanitize = {"x", "y", "width", "height"} + local errors = {} + + for _, name in ipairs(toSanitize) do + if attrs[name] and not tonumber(attrs[name]) then + errors[name] = attrs[name] + attrs[name] = nil + end + end + + return attrs, #errors == 0 and nil or errors end --- scale {x, y, width, height} to current aspect ratio -function scaleAttrs(attrs, targetRatio, settings) +function correctX(x, targetRatio, settings) settings = merge(Dart.defaultScaleSettings, settings) local ratio = getAspectRatioVs(targetRatio) - local anchor, align, bounds, scale, autoscale, offset, safezone = + local anchor, align, bounds, scale, offset, safezone = settings.anchor, settings.align, settings.bounds, settings.scale, - settings.autoscale, settings.offset, settings.safezone - local x, y, width, height = - tonumber(attrs.x), - tonumber(attrs.y), - tonumber(attrs.width), - tonumber(attrs.height) + x = tonumber(x) - local l, t, r, b = - bounds.l, - bounds.t, - bounds.r, - bounds.b - - local anchor1, anchor2 = anchor[1], anchor[2] + local l, r = bounds.l, bounds.r + local anchor1 = anchor[1] -- move the element if settings.align is specified if x and align and align[1] ~= anchor1 then @@ -216,20 +180,6 @@ function scaleAttrs(attrs, targetRatio, settings) anchor1 = align[1] end - if attrs.y and align and align[2] ~= anchor2 then - if align[2] == "CENTER" then - t = Dart.baseHeight / 2 - (b - t) / 2 - b = Dart.baseHeight / 2 + (b - t) / 2 - y = y + (t - bounds.t) - else - t = Dart.baseHeight - t - b = Dart.baseHeight - b - y = y + (t - bounds.t) - end - - anchor2 = align[2] - end - local xscreen = ({ LEFT = 0, CENTER = Dart.baseWidth / 2, @@ -242,13 +192,7 @@ function scaleAttrs(attrs, targetRatio, settings) RIGHT = xscreen + (r - xscreen) / ratio, })[anchor1] - local yanchor = ({ - TOP = t, - CENTER = (t + b) / 2, - BOTTOM = b, - })[anchor2] - - local xoffset, yoffset = offset[1], offset[2] + local xoffset = offset[1] if safezone then xoffset = xoffset + ({ @@ -258,53 +202,113 @@ function scaleAttrs(attrs, targetRatio, settings) })[anchor1] end - if autoscale then - scale = addAutoscale(scale) - end + x = xscreen + (x - xscreen) / ratio + x = xanchor + (x - xanchor) * scale + x = x + xoffset / ratio / (targetRatio / Dart.ratio4x3) - if x then - x = xscreen + (x - xscreen) / ratio - x = xanchor + (x - xanchor) * scale - x = x + xoffset / ratio / (targetRatio / Dart.ratio4x3) - end + return x +end - if y then - y = yanchor + (y - yanchor) * scale - y = y + yoffset - end - if width then - width = width * scale / ratio - end +function correctY(y, targetRatio, settings) + settings = merge(Dart.defaultScaleSettings, settings) - if height then - height = height * scale + local anchor, align, bounds, scale, offset = + settings.anchor, + settings.align, + settings.bounds, + settings.scale, + settings.offset + + y = tonumber(y) + + local t, b = bounds.t, bounds.b + local anchor2 = anchor[2] + + -- move the element if settings.align is specified + if y and align and align[2] ~= anchor2 then + if align[2] == "CENTER" then + t = Dart.baseHeight / 2 - (b - t) / 2 + b = Dart.baseHeight / 2 + (b - t) / 2 + y = y + (t - bounds.t) + else + t = Dart.baseHeight - t + b = Dart.baseHeight - b + y = y + (t - bounds.t) + end + + anchor2 = align[2] end - return { - x = x, - y = y, - width = width, - height = height, - } + local yanchor = ({ + TOP = t, + CENTER = (t + b) / 2, + BOTTOM = b, + })[anchor2] + + local yoffset = offset[2] + + y = yanchor + (y - yanchor) * scale + y = y + yoffset + + return y end -function scaleX(x, targetRatio, settings) - return scaleAttrs({x = x}, targetRatio, settings).x +function correctW(width, targetRatio, settings) + settings = merge(Dart.defaultScaleSettings, settings) + local ratio = getAspectRatioVs(targetRatio) + + local scale = settings.scale + local width = tonumber(width) + + width = width * scale / ratio + return width end -function scaleY(y, targetRatio, settings) - return scaleAttrs({y = y}, targetRatio, settings).y +function correctH(height, targetRatio, settings) + settings = merge(Dart.defaultScaleSettings, settings) + local ratio = getAspectRatioVs(targetRatio) + + local scale = settings.scale + local height = tonumber(height) + + height = height * scale + return height end -function scaleW(w, targetRatio, settings) - return scaleAttrs({width = w}, targetRatio, settings).width +function correctXY(attrs, targetRatio, settings) + local x, y = tonumber(attrs.x), tonumber(attrs.y) + + if x then + attrs.x = correctX(x, targetRatio, settings) + end + if y then + attrs.y = correctY(y, targetRatio, settings) + end + + return attrs +end + + +function correctWH(attrs, targetRatio, settings) + local width, height = tonumber(attrs.width), tonumber(attrs.height) + + if width then + attrs.width = correctW(width, targetRatio, settings) + end + if height then + attrs.height = correctH(height, targetRatio, settings) + end + + return attrs end -function scaleH(h, targetRatio, settings) - return scaleAttrs({height = h}, targetRatio, settings).height +function correctAttrs(attrs, targetRatio, settings) + attrs = correctXY(attrs, targetRatio, settings) + attrs = correctWH(attrs, targetRatio, settings) + return attrs end diff --git a/gamedata/scripts/modxml_z_dart_ammo_wheel.script b/gamedata/scripts/modxml_z_dart_ammo_wheel.script index 0e013b7..2334a26 100644 --- a/gamedata/scripts/modxml_z_dart_ammo_wheel.script +++ b/gamedata/scripts/modxml_z_dart_ammo_wheel.script @@ -1,78 +1,77 @@ -local Dart = Dart_core +local Dart = dart_core local Utils = dart_utils local Module = dart_module -local mod = "AMMO_WHEEL" +local mod = "ammoWheel" local config = Dart.config.ammoWheel -function parseUIWheelAmmo(DXML) +function parseUIWheelAmmo(XML) local wheel, background, texture, all, alt, extended, result, ammo = - DXML:query("wheel")[1], - DXML:query("wheel > background")[1], - DXML:query("wheel > background > texture")[1], - DXML:query("wheel > all")[1], - DXML:query("wheel > alt")[1], - DXML:query("wheel > extended")[1], - DXML:query("wheel > result")[1], - DXML:query("ammo")[1] + XML:query("wheel")[1], + XML:query("wheel > background")[1], + XML:query("wheel > background > texture")[1], + XML:query("wheel > all")[1], + XML:query("wheel > alt")[1], + XML:query("wheel > extended")[1], + XML:query("wheel > result")[1], + XML:query("ammo")[1] local itemSettings = { - scale = config.scale, - autoscale = config.autoscale, + scale = config.scale, } local wheelSettings = Utils.merge(itemSettings, { - bounds = DXML:getElementBounds(wheel), + bounds = XML:getBounds(wheel), anchor = config.anchor, offset = config.offset, safezone = config.safezone, }) if wheel then - DXML:scaleElement(wheel, wheelSettings) + XML:correctElement(wheel, wheelSettings) end if background then - DXML:scaleElement(background, itemSettings) + XML:correctElement(background, itemSettings) end if extended then - DXML:scaleElement(extended, itemSettings) + XML:correctElement(extended, itemSettings) end if result then - DXML:scaleElement(result, itemSettings) + XML:correctElement(result, itemSettings) end if texture and config.roundWheel - and DXML:getText(texture) == "ui_hud2_wheel_ammo" + and XML:getText(texture) == "ui_hud2_wheel_ammo" then - DXML:setText(texture, "ui_hud2_wheel_companion") + XML:setText(texture, "ui_hud2_wheel_companion") end if all then - DXML:safeIterate(all, function(child) - DXML:scaleElement(child, itemSettings) + XML:safeIterate(all, function(child) + XML:correctElement(child, itemSettings) end) end if alt then - DXML:safeIterate(alt, function(child) - DXML:scaleElement(child, itemSettings) + XML:safeIterate(alt, function(child) + XML:correctElement(child, itemSettings) end) end if ammo then - DXML:safeIterate(ammo, function(child) - DXML:scaleElement(child, itemSettings) + XML:safeIterate(ammo, function(child) + XML:correctElement(child, itemSettings) end) end end function on_xml_read() - Module.registerModule(mod, "ui\\ui_wheel_ammo", parseUIWheelAmmo) + Module.registerModule(mod, "ui_wheel_ammo", parseUIWheelAmmo) end diff --git a/gamedata/scripts/modxml_z_dart_bhs.script b/gamedata/scripts/modxml_z_dart_bhs.script index bcf243d..2c490f4 100644 --- a/gamedata/scripts/modxml_z_dart_bhs.script +++ b/gamedata/scripts/modxml_z_dart_bhs.script @@ -1,115 +1,109 @@ -local Dart = Dart_core +local Dart = dart_core local Module = dart_module -local mod = "BHS" +local mod = "bhs" local config = Dart.config.bhs +local state = Dart.state.bhs function getScaleSettings() return { - bounds = Dart.state.bhsBounds, - anchor = config.anchor, - safezone = config.safezone, - offset = config.offset, - scale = config.scale, - autoscale = config.autoscale, + bounds = state.bounds, + anchor = config.anchor, + safezone = config.safezone, + offset = config.offset, + scale = config.scale, } end -function isBHSElement(DXML, element) - if not DXML:safeIsElement(element) then +function isBHSElement(XML, element) + if not XML:safeIsElement(element) then return false end - local name = DXML:getElementName(element) + local name = XML:getElementName(element) return name:match("^bhs_") or name:match("^body_health_") end -function parseUICustomMsgs(DXML) - local container = DXML:query("body_health_system")[1] - Dart.state.bhsBounds = DXML:getElementBounds(container) +function parseUICustomMsgs(XML) + local container = XML:query("body_health_system")[1] + state.bounds = XML:getBounds(container) - DXML:safeIterate(function(child) - if isBHSElement(DXML, child) then - DXML:scaleElement(child, getScaleSettings()) + XML:safeIterate(function(child) + if isBHSElement(XML, child) then + XML:correctElement(child, getScaleSettings()) end end) end -function parseUIBodyHealth(DXML) - DXML:safeIterate(function(child) - if isBHSElement(DXML, child) then - DXML:scaleElement(child, { - scale = config.scale, - autoscale = config.autoscale, - }) +function parseUIBodyHealth(XML) + XML:safeIterate(function(child) + if isBHSElement(XML, child) then + XML:correctElement(child, {scale = config.scale}) end end) end -function parseMaingame(DXML) - local hudStates = DXML:query("hud_states")[1] +function parseMaingame(XML) + local hudStates = XML:query("hud_states")[1] if not hudStates then return end - local psybar = DXML:query("progress_bar_psy", hudStates)[1] - local progress = DXML:query("progress", psybar)[1] + local psybar = XML:query("progress_bar_psy", hudStates)[1] + local progress = XML:query("progress", psybar)[1] if psybar then -- slight nudge for better alignment - DXML:safeSetAttrs(psybar, function(attrs) + XML:safeSetAttrs(psybar, function(attrs) return {height = attrs.height + 1, width = attrs.width - 1} end) end if progress then - DXML:safeSetAttrs(progress, function(attrs) + XML:safeSetAttrs(progress, function(attrs) return {stretch = 1} end) end - DXML:safeIterate(hudStates, function(child) - DXML:scaleElement(child, getScaleSettings()) + XML:safeIterate(hudStates, function(child) + XML:correctElement(child, getScaleSettings()) end) end -function parseSidHudComponent(DXML) - local sidhud = DXML:query("sidhud")[1] - local radHealth = DXML:query("sidhud > rad_health")[1] - local value = DXML:query("sidhud > rad_health > value")[1] +function parseSidHudComponent(XML) + local sidhud = XML:query("sidhud")[1] + local radHealth = XML:query("sidhud > rad_health")[1] + local value = XML:query("sidhud > rad_health > value")[1] if not (sidhud and radHealth and value) then return end - DXML:scaleElement(sidhud, getScaleSettings()) + XML:correctElement(sidhud, getScaleSettings()) - DXML:scaleElement(radHealth, { - scale = config.scale, - autoscale = config.autoscale, + XML:correctElement(radHealth, { + scale = config.scale, }) - DXML:scaleElement(value, { - scale = config.scale, - autoscale = config.autoscale, + XML:correctElement(value, { + scale = config.scale, }) end function on_xml_read() - Module.registerModule(mod, "ui\\ui_custom_msgs", parseUICustomMsgs) - Module.registerModule(mod, "ui\\ui_body_health", parseUIBodyHealth) - Module.registerModule(mod, "ui\\maingame", parseMaingame) - Module.registerModule(mod, "ui\\ui_sidhud_component", parseSidHudComponent) + Module.registerModule(mod, "ui_custom_msgs", parseUICustomMsgs) + Module.registerModule(mod, "ui_body_health", parseUIBodyHealth) + Module.registerModule(mod, "maingame", parseMaingame) + Module.registerModule(mod, "ui_sidhud_component", parseSidHudComponent) - if not Dart.state.bhsBounds then - CScriptXmlInit():ParseFile("ui_custom_msgs.xml") - end + -- ensure state.bounds is populated first + CScriptXmlInit():ParseFile("ui_custom_msgs.xml") end diff --git a/gamedata/scripts/modxml_z_dart_companion_list.script b/gamedata/scripts/modxml_z_dart_companion_list.script index bfbeaf2..7b69309 100644 --- a/gamedata/scripts/modxml_z_dart_companion_list.script +++ b/gamedata/scripts/modxml_z_dart_companion_list.script @@ -1,33 +1,33 @@ -local Dart = Dart_core +local Dart = dart_core +local Utils = dart_utils local Module = dart_module -local Utils = dart_module -local mod = "COMPANION_LIST" +local mod = "companionList" local config = Dart.config.companionList -- convoluted process per axr_companions -function getBounds(DXML) +function getBounds(XML) local magicCount = 8 local magicPadding = 10 - local list = DXML:query("companion_list")[1] - local health = DXML:query("companion_list > slot > health")[1] - local bg = DXML:query("companion_list > slot > background")[1] + local list = XML:query("companion_list")[1] + local health = XML:query("companion_list > slot > health")[1] + local bg = XML:query("companion_list > slot > background")[1] local xlist, ylist = - DXML:safeGetAttrs(list).x, - DXML:safeGetAttrs(list).y + XML:safeGetAttrs(list).x, + XML:safeGetAttrs(list).y local xhealth, whealth = - DXML:safeGetAttrs(health).x, - DXML:safeGetAttrs(health).width + XML:safeGetAttrs(health).x, + XML:safeGetAttrs(health).width local xbg, wbg, hbg = - DXML:safeGetAttrs(bg).x, - DXML:safeGetAttrs(bg).width, - DXML:safeGetAttrs(bg).height + XML:safeGetAttrs(bg).x, + XML:safeGetAttrs(bg).width, + XML:safeGetAttrs(bg).height return { l = xlist, @@ -38,44 +38,38 @@ function getBounds(DXML) end -function parseUIHud(DXML) - local list = DXML:query("companion_list")[1] - local slot = DXML:query("companion_list > slot")[1] - local healthBg = DXML:query("companion_list > slot > health > background")[1] +function parseUIHud(XML) + local list = XML:query("companion_list")[1] + local slot = XML:query("companion_list > slot")[1] + local healthBg = XML:query("companion_list > slot > health > background")[1] - local bounds = getBounds(DXML) + local bounds = getBounds(XML) + local scale = config.scale -- fixes being partly offscreen in base GAMMA if bounds.r > Dart.baseWidth then - DXML:safeSetAttrs(list, function(attrs) + XML:safeSetAttrs(list, function(attrs) return {x = attrs.x + Dart.baseWidth - bounds.r} end) end - local outerSettings = { - bounds = getBounds(DXML), - offset = config.offset, - anchor = config.anchor, - scale = config.scale, - autoscale = config.autoscale, - safezone = config.safezone - } - - local innerSettings = { - scale = config.scale, - autoscale = config.autoscale - } + XML:correctElement(list, { + bounds = getBounds(XML), + offset = config.offset, + anchor = config.anchor, + scale = config.scale, + safezone = config.safezone + }) - DXML:scaleElement(list, outerSettings) - DXML:scaleElement(slot, innerSettings) - DXML:scaleElement(healthBg, innerSettings) + XML:correctElement(slot, {scale = scale}) + XML:correctElement(healthBg, {scale = scale}) - DXML:safeIterate(slot, function(child) - DXML:scaleElement(child, innerSettings) + XML:safeIterate(slot, function(child) + XML:correctElement(child, {scale = scale}) end) end function on_xml_read() - Module.registerModule(mod, "ui\\ui_hud", parseUIHud) + Module.registerModule(mod, "ui_hud", parseUIHud) end diff --git a/gamedata/scripts/modxml_z_dart_companion_wheel.script b/gamedata/scripts/modxml_z_dart_companion_wheel.script index ec1f431..3ff36c2 100644 --- a/gamedata/scripts/modxml_z_dart_companion_wheel.script +++ b/gamedata/scripts/modxml_z_dart_companion_wheel.script @@ -1,63 +1,62 @@ -local Dart = Dart_core +local Dart = dart_core local Utils = dart_utils local Module = dart_module -local mod = "COMPANION_WHEEL" +local mod = "companionWheel" local config = Dart.config.companionWheel -function parseUIWheelCompanion(DXML) +function parseUIWheelCompanion(XML) local wheel, info, health, weight = - DXML:query("wheel")[1], - DXML:query("info")[1], - DXML:query("info > health")[1], - DXML:query("info > weight")[1] + XML:query("wheel")[1], + XML:query("info")[1], + XML:query("info > health")[1], + XML:query("info > weight")[1] local itemSettings = { - scale = config.scale, - autoscale = config.autoscale, + scale = config.scale, } local wheelSettings = Utils.merge(itemSettings, { - bounds = DXML:getElementBounds(wheel), + bounds = XML:getBounds(wheel), anchor = config.anchor, offset = config.offset, safezone = config.safezone, }) local infoSettings = Utils.merge(wheelSettings, { - bounds = DXML:getElementBounds(info) + bounds = XML:getBounds(info) }) if wheel then - DXML:scaleElement(wheel, wheelSettings) - DXML:safeIterate(wheel, function(child) - DXML:scaleElement(child, itemSettings) + XML:correctElement(wheel, wheelSettings) + XML:safeIterate(wheel, function(child) + XML:correctElement(child, itemSettings) end) end if info then - DXML:scaleElement(info, infoSettings) - DXML:safeIterate(info, function(child) - DXML:scaleElement(child, itemSettings) + XML:correctElement(info, infoSettings) + XML:safeIterate(info, function(child) + XML:correctElement(child, itemSettings) end) end if health then - DXML:safeIterate(health, function(child) - DXML:scaleElement(child, itemSettings) + XML:safeIterate(health, function(child) + XML:correctElement(child, itemSettings) end) end if weight then - DXML:safeIterate(weight, function(child) - DXML:scaleElement(child, itemSettings) + XML:safeIterate(weight, function(child) + XML:correctElement(child, itemSettings) end) end end function on_xml_read() - Module.registerModule(mod, "ui\\ui_wheel_companion", parseUIWheelCompanion) + Module.registerModule(mod, "ui_wheel_companion", parseUIWheelCompanion) end diff --git a/gamedata/scripts/modxml_z_dart_inventory.script b/gamedata/scripts/modxml_z_dart_inventory.script index d9e6357..e64c79e 100644 --- a/gamedata/scripts/modxml_z_dart_inventory.script +++ b/gamedata/scripts/modxml_z_dart_inventory.script @@ -1,16 +1,20 @@ -local Dart = Dart_core +local Dart = dart_core local Module = dart_module -local mod = "INVENTORY" +local mod = "inventory" local config = Dart.config.inventory +local state = Dart.state.inventory -function parseUIInventory(DXML) - Dart.state.inventoryAspectRatio = DXML.aspectRatio +function parseUIInventory(XML) + state.xmlAspectRatio = XML.aspectRatio end function on_xml_read() - Module.registerModule(mod, "ui\\ui_inventory", parseUIInventory) + Module.registerModule(mod, "ui_inventory", parseUIInventory) + + -- make sure XML has been parsed first + CScriptXmlInit():ParseFile("ui_inventory.xml") end diff --git a/gamedata/scripts/modxml_z_dart_markers.script b/gamedata/scripts/modxml_z_dart_markers.script index 2cd07d8..c03e7ec 100644 --- a/gamedata/scripts/modxml_z_dart_markers.script +++ b/gamedata/scripts/modxml_z_dart_markers.script @@ -1,11 +1,11 @@ -local Dart = Dart_core +local Dart = dart_core local Utils = dart_utils local Module = dart_module -local mod = "MARKERS" -local config = Dart.config.markers +local mod = "markers" local log = Module.createLogger(mod) +local config = Dart.config.markers local MARKER_INDEX, TOUCHED = {}, {} @@ -16,21 +16,36 @@ function clearMarkerIndexes() end +-- calculate angle factor +function getAngleFactor(angle) + angle = math.abs(angle) + + while angle >= 180 do + angle = angle - 180 + end + while angle > 90 do + angle = angle - 90 + end + + return angle / 90 +end + + -- potential valid markersa are elements that have valid -- widths and heights and are not textures -function isValidMarker(DXML, element) - if not DXML:safeIsElement(element) then +function isValidMarker(XML, element) + if not XML:safeIsElement(element) then return false end - local name = DXML:getElementName(element) + local name = XML:getElementName(element) if name == "texture" or name:match("^texture_") then return false end - local width = DXML:safeGetAttrs(element).width - local height = DXML:safeGetAttrs(element).height + local width = XML:safeGetAttrs(element).width + local height = XML:safeGetAttrs(element).height return (width and height and width ~= "0" and height ~= "0") end @@ -39,18 +54,18 @@ end -- map_spots is a fairly flat but large file, so markers are pre-collected -- in and indexed for perforamnce, and duplicate markers are removed to -- avoid unexpected behavior -function buildMarkerIndex(DXML) - DXML:safeIterate(function(child) - if not isValidMarker(DXML, child) then +function buildMarkerIndex(XML) + XML:safeIterate(function(child) + if not isValidMarker(XML, child) then return end - local name = DXML:getElementName(child) + local name = XML:getElementName(child) -- remove duplicate markers if MARKER_INDEX[name] then log("Removing duplicate marker %s", name) - DXML:removeElement(MARKER_INDEX[name]) + XML:removeElement(MARKER_INDEX[name]) end MARKER_INDEX[name] = child @@ -61,12 +76,12 @@ end -- transition arrows can be rotated, and {x, y, width, height} is applied -- post-rotation. we have to do some trig to scale width and height, -- but it's not perfect because they're irreversably distorted -function adjustPDAMarker(DXML, element) - local factor = Utils.getAspectRatioVs(DXML.aspectRatio) - local attrs = DXML:getElementAttr(element) - local name = DXML:getElementName(element) +function adjustPDAMarker(XML, element) + local factor = Utils.getAspectRatioVs(XML.aspectRatio) + local name = XML:getElementName(element) + local attrs = XML:safeGetAttrs(element) - local angle = attrs.heading_angle or 0 + local angleFactor = getAngleFactor(attrs.heading_angle or 0) local widthChange = attrs.width local heightChange = attrs.height @@ -74,11 +89,11 @@ function adjustPDAMarker(DXML, element) widthChange = widthChange * (factor - 1) heightChange = heightChange * (factor - 1) - -- factor angle and scale down if not 90 degrees - widthChange = widthChange * (Utils.abcosd(angle) - 0.68 * (angle % 90) / 45) - heightChange = heightChange * (Utils.absind(angle) - 0.68 * (angle % 90) / 45) + -- factor angle + widthChange = widthChange * (1 - angleFactor) + heightChange = heightChange * (angleFactor) - DXML:safeSetAttrs(element, { + XML:safeSetAttrs(element, { width = attrs.width + widthChange, height = attrs.height + heightChange, stretch = 1, @@ -86,11 +101,11 @@ function adjustPDAMarker(DXML, element) -- Extra fudge factor for blinky things if name == "static_border" then - DXML:safeSetAttrs(element, {x = attrs.x + 1}) + XML:safeSetAttrs(element, {x = attrs.x + 1}) end -- this specific animation gets distorted - DXML:removeElementAttr(element, {"xform_anim"}) + XML:removeElementAttr(element, {"xform_anim"}) end @@ -107,31 +122,31 @@ end -- that need to be realigned with their parent. some markers are reused for -- both the level_map and mini_map, in which case a separate copy has to be -- made so they can be altered independently of each other -function parsePDAMarkers(DXML) +function parsePDAMarkers(XML) if not Utils.isUsing3DPDA() then return log("Disabled because the 3D PDA is not being used") end -- saerch for level_map marker definitions Utils.ipairscb({"level_map", "complex_spot"}, function(query) - local definitions = DXML:query(query) + local definitions = XML:query(query) if not definitions then return end Utils.ipairscb(definitions, function(definition) - local miniDefinition = DXML:query("mini_map", definition.parent)[1] + local miniDefinition = XML:query("mini_map", definition.parent)[1] Utils.ipairscb({"spot", "pointer"}, function(attribute) - local name, miniName = DXML:safeGetAttrs(definition)[attribute] + local name, miniName = XML:safeGetAttrs(definition)[attribute] if not name or not MARKER_INDEX[name] then return end if miniDefinition then - miniName = DXML:safeGetAttrs(miniDefinition)[attribute] + miniName = XML:safeGetAttrs(miniDefinition)[attribute] end -- a separate mini_map copy needs to be made @@ -139,14 +154,14 @@ function parsePDAMarkers(DXML) miniName = miniName .. "_mini" if not MARKER_INDEX[miniName] then - MARKER_INDEX[miniName] = DXML:insertElement({ + MARKER_INDEX[miniName] = XML:insertElement({ name = miniName, - attr = DXML:safeGetAttrs(MARKER_INDEX[name]), + attr = XML:safeGetAttrs(MARKER_INDEX[name]), kids = MARKER_INDEX[name].kids }) end - DXML:safeSetAttrs(miniDefinition, {[attribute] = miniName}) + XML:safeSetAttrs(miniDefinition, {[attribute] = miniName}) end -- markers can be referenced multple times, so TOUCHED prevents @@ -154,12 +169,12 @@ function parsePDAMarkers(DXML) -- have children that also need to be resized if not TOUCHED[MARKER_INDEX[name]] - and isValidMarker(DXML, MARKER_INDEX[name]) + and isValidMarker(XML, MARKER_INDEX[name]) then - adjustPDAMarker(DXML, MARKER_INDEX[name]) - DXML:safeIterate(MARKER_INDEX[name], function(child) - if isValidMarker(DXML, child) then - adjustPDAMarker(DXML, child) + adjustPDAMarker(XML, MARKER_INDEX[name]) + XML:safeIterate(MARKER_INDEX[name], function(child) + if isValidMarker(XML, child) then + adjustPDAMarker(XML, child) end end) @@ -171,22 +186,22 @@ function parsePDAMarkers(DXML) end -function adjustMinimapMarker(DXML, element) - DXML:safeIterate(element, function(child) +function adjustMinimapMarker(XML, element) + XML:safeIterate(element, function(child) if - not DXML:safeIsElement(child) - or DXML:getElementName(child) == "texture" - or DXML:getElementName(child):match("^texture_") + not XML:safeIsElement(child) + or XML:getElementName(child) == "texture" + or XML:getElementName(child):match("^texture_") then return end -- only shift (no resize) - DXML:safeSetAttrs(child, function(attrs) - local x = Utils.scaleX(attrs.x, DXML.aspectRatio) + XML:safeSetAttrs(child, function(attrs) + local x = Utils.correctX(attrs.x, XML.aspectRatio) -- Extra fudge factor for blinky things - if DXML:getElementName(child) == "static_border" then + if XML:getElementName(child) == "static_border" then x = x + 1 end @@ -196,8 +211,8 @@ function adjustMinimapMarker(DXML, element) end -function parseMinimapMarkers(DXML) - local definitions = DXML:query("mini_map") +function parseMinimapMarkers(XML) + local definitions = XML:query("mini_map") if not definitions then return @@ -205,7 +220,7 @@ function parseMinimapMarkers(DXML) Utils.ipairscb(definitions, function(definition) Utils.ipairscb({"spot", "pointer"}, function(attribute) - local name = DXML:safeGetAttrs(definition)[attribute] + local name = XML:safeGetAttrs(definition)[attribute] if not name @@ -215,7 +230,7 @@ function parseMinimapMarkers(DXML) return end - adjustMinimapMarker(DXML, MARKER_INDEX[name]) + adjustMinimapMarker(XML, MARKER_INDEX[name]) TOUCHED[MARKER_INDEX[name]] = true end) end) @@ -223,7 +238,7 @@ end function on_xml_read() - Module.registerModule(mod, "ui\\map_spots", + Module.registerModule(mod, "map_spots", buildMarkerIndex, parsePDAMarkers, parseMinimapMarkers, diff --git a/gamedata/scripts/modxml_z_dart_messages.script b/gamedata/scripts/modxml_z_dart_messages.script index a8c2a69..d6de272 100644 --- a/gamedata/scripts/modxml_z_dart_messages.script +++ b/gamedata/scripts/modxml_z_dart_messages.script @@ -1,40 +1,36 @@ -local Dart = Dart_core +local Dart = dart_core local Module = dart_module -local mod = "MESSAGES" +local mod = "messages" local config = Dart.config.messages -function parseMessagesWindow(DXML) - local list1 = DXML:query("sp_log_list")[1] - local list2 = DXML:query("sp_log_list2")[1] +function parseMessagesWindow(XML) + local list1 = XML:query("sp_log_list")[1] + local list2 = XML:query("sp_log_list2")[1] local scaleSettings = { - bounds = DXML:getElementBounds(list1, list2), - offset = config.offset, - anchor = config.anchor, - scale = config.scale, - autoscale = config.autoscale, - safezone = config.safezone + bounds = XML:getBounds(list1, list2), + offset = config.offset, + anchor = config.anchor, + scale = config.scale, + safezone = config.safezone } - DXML:scaleElement(list1, scaleSettings) - DXML:scaleElement(list2, scaleSettings) + XML:correctElement(list1, scaleSettings) + XML:correctElement(list2, scaleSettings) end -function parseMaingamePdaMsg(DXML) - DXML:safeIterate(function(child) - DXML:scaleElement(child, { - scale = config.scale, - autoscale = config.autoscale, - }) +function parseMaingamePdaMsg(XML) + XML:safeIterate(function(child) + XML:correctElement(child, {scale = config.scale}) end) end function on_xml_read() - Module.registerModule(mod, "ui\\messages_window", parseMessagesWindow) - Module.registerModule(mod, "ui\\maingame_pda_msg", parseMaingamePdaMsg) + Module.registerModule(mod, "messages_window", parseMessagesWindow) + Module.registerModule(mod, "maingame_pda_msg", parseMaingamePdaMsg) end diff --git a/gamedata/scripts/modxml_z_dart_minimap.script b/gamedata/scripts/modxml_z_dart_minimap.script index 3075afc..738a238 100644 --- a/gamedata/scripts/modxml_z_dart_minimap.script +++ b/gamedata/scripts/modxml_z_dart_minimap.script @@ -1,28 +1,26 @@ -local Dart = Dart_core +local Dart = dart_core local Utils = dart_utils local Module = dart_module -local mod = "MINIMAP" +local mod = "minimap" local config = Dart.config.minimap --- We can't use DXML:scaleElement() because: +-- We can't use XML:correctElement() because: -- - minimap elements are expressed in dumb units for no reason -- - minimap element widths are aleady adjusted for aspect ratio -function parseZoneMap(DXML) - local compass = DXML:query("minimap > compass")[1] - local frame = DXML:query("minimap > level_frame")[1] - local bg = DXML:query("minimap > background")[1] - local clock = DXML:query("minimap > clock_wnd")[1] +function parseZoneMap(XML) + local compass = XML:query("minimap > compass")[1] + local frame = XML:query("minimap > level_frame")[1] + local bg = XML:query("minimap > background")[1] + local clock = XML:query("minimap > clock_wnd")[1] - local compassAttrs = DXML:safeGetAttrs(compass) - local frameAttrs = DXML:safeGetAttrs(frame) - local bgAttrs = DXML:safeGetAttrs(bg) + local compassAttrs = XML:safeGetAttrs(compass) + local frameAttrs = XML:safeGetAttrs(frame) + local bgAttrs = XML:safeGetAttrs(bg) - local scale = config.autoscale - and Utils.addAutoscale(config.scale) - or config.scale + local scale = config.scale local scaleSettings = Utils.merge(config, { bounds = { @@ -33,31 +31,32 @@ function parseZoneMap(DXML) } }) - DXML:safeSetAttrs(frame, function(attrs) + XML:safeSetAttrs(frame, function(attrs) local dumbUnits = Dart.baseHeight return { - x = Utils.scaleX(attrs.x * dumbUnits, DXML.aspectRatio, scaleSettings) / dumbUnits, - y = Utils.scaleY(attrs.y * dumbUnits, DXML.aspectRatio, scaleSettings) / dumbUnits, + x = Utils.correctX(attrs.x * dumbUnits, XML.aspectRatio, scaleSettings) / dumbUnits, + y = Utils.correctY(attrs.y * dumbUnits, XML.aspectRatio, scaleSettings) / dumbUnits, width = attrs.width * config.scale, height = attrs.height * config.scale, + a = config.alpha, } end) - DXML:safeSetAttrs(compass, function(attrs) + XML:safeSetAttrs(compass, function(attrs) return { width = attrs.width * config.scale, height = attrs.height * config.scale, } end) - DXML:safeSetAttrs(bg, function(attrs) + XML:safeSetAttrs(bg, function(attrs) return { width = attrs.width * config.scale, height = attrs.height * config.scale, } end) - DXML:safeSetAttrs(clock, function(attrs) + XML:safeSetAttrs(clock, function(attrs) local dumbUnits = bgAttrs.height * Dart.baseHeight return { x = (attrs.x * dumbUnits + config.clockOffset[1] / Utils.getAspectRatioVs(Dart.ratio4x3)) / dumbUnits, @@ -68,5 +67,5 @@ end function on_xml_read() - Module.registerModule(mod, "ui\\zone_map", parseZoneMap) + Module.registerModule(mod, "zone_map", parseZoneMap) end diff --git a/gamedata/scripts/modxml_z_dart_patches.script b/gamedata/scripts/modxml_z_dart_patches.script index 79570c3..b1d80f4 100644 --- a/gamedata/scripts/modxml_z_dart_patches.script +++ b/gamedata/scripts/modxml_z_dart_patches.script @@ -1,44 +1,44 @@ -local Dart = Dart_core +local Dart = dart_core local Module = dart_module -local mod = "PATCHES" +local mod = "patches" local config = Dart.config.patches +local state = Dart.state.patches -function parseUIPatches(DXML) - local patch = DXML:query("patch_stalker")[1] - local name1 = DXML:query("name")[1] - local rank1 = DXML:query("rank")[1] - local name2 = DXML:query("name_r")[1] - local rank2 = DXML:query("rank_r")[1] +function parseUIPatches(XML) + local patch = XML:query("patch_stalker")[1] + local name1 = XML:query("name")[1] + local rank1 = XML:query("rank")[1] + local name2 = XML:query("name_r")[1] + local rank2 = XML:query("rank_r")[1] if patch then - Dart.state.patchSize = { - x = DXML:safeGetAttrs(patch).width, - y = DXML:safeGetAttrs(patch).height, + state.patchSize = { + x = XML:safeGetAttrs(patch).width, + y = XML:safeGetAttrs(patch).height, } end - Dart.state.patchAspectRatio = DXML.aspectRatio + state.xmlAspectRatio = XML.aspectRatio local scaleSettings = { - bounds = DXML:getElementBounds(patch, name1, rank1, name2, rank2), - offset = config.offset, - anchor = config.anchor, - scale = config.scale, - autoscale = config.autoscale, - safezone = config.safezone + bounds = XML:getBounds(patch, name1, rank1, name2, rank2), + offset = config.offset, + anchor = config.anchor, + scale = config.scale, + safezone = config.safezone } - DXML:safeIterate(function(child, index) - if DXML:getElementName(child):match("^patch_") then - DXML:scaleElement(child, scaleSettings) + XML:safeIterate(function(child, index) + if XML:getElementName(child):match("^patch_") then + XML:correctElement(child, scaleSettings) end end) end function on_xml_read() - Module.registerModule(mod, "ui\\ui_patches", parseUIPatches) + Module.registerModule(mod, "ui_patches", parseUIPatches) end diff --git a/gamedata/scripts/modxml_z_dart_scopes.script b/gamedata/scripts/modxml_z_dart_scopes.script index 1b93f17..4f624b4 100644 --- a/gamedata/scripts/modxml_z_dart_scopes.script +++ b/gamedata/scripts/modxml_z_dart_scopes.script @@ -1,9 +1,10 @@ -local Dart = Dart_core +local Dart = dart_core local Module = dart_module local Utils = dart_utils -local mod = "SCOPES" +local mod = "scopes" +local log = Module.createLogger(mod) local config = Dart.config.scopes @@ -11,50 +12,78 @@ local config = Dart.config.scopes -- scopes are 1024x768, so we can just scale 1024 to the aspect ratio -- it's actually better than relying on widths in the XML because those -- are sloppy and all over the place -function resizeScope(DXML, scope) - local elements = DXML:query("auto_static", scope) +function resizeScope(XML, scope) + local elements = XML:query("auto_static", scope) + local isBinoculars = XML:getElementName(scope) == "wpn_crosshair_bino" - -- only handle scopes with 3 parts (main, left, right) - if not elements or #elements ~= 3 then + -- fix missing left and right fillers + if #elements == 1 then + local left = string.format(Dart.scopeFillerTemplate, isBinoculars + and "wpn_crosshair_add_lblack" + or "wpn_crosshair_add_l" + ) + + local right = string.format(Dart.scopeFillerTemplate, isBinoculars + and "wpn_crosshair_add_rblack" + or "wpn_crosshair_add_r" + ) + + XML:insertFromXMLString(left, scope) + XML:insertFromXMLString(right, scope) + elements = scope.kids + end + + -- if still not 3 elements then skip + if #elements ~= 3 then return end - local w1 = tonumber(DXML:safeGetAttrs(elements[1]).width) - local w2 = tonumber(DXML:safeGetAttrs(elements[2]).width) - local w3 = tonumber(DXML:safeGetAttrs(elements[3]).width) + local w1 = tonumber(XML:safeGetAttrs(elements[1]).width) + local w2 = tonumber(XML:safeGetAttrs(elements[2]).width) + local w3 = tonumber(XML:safeGetAttrs(elements[3]).width) - -- skip scopes with textures in the wrong order - if w1 < w2 or w1 < w3 then - return + -- make sure main scope texture is first + if w1 < w2 then + w1, w2 = w2, w1 + elements[1], elements[2] = elements[2], elements[1] + end + if w1 < w3 then + w1, w3 = w3, w1 + elements[1], elements[3] = elements[3], elements[1] end - local textureWidth = Utils.scaleW(Dart.baseWidth, Dart.ratio4x3) + -- the binoculars are wider than other scopes + local textureWidth = Utils.correctW(Dart.baseWidth, isBinoculars + and Dart.ratio16x9 + or Dart.ratio4x3 + ) + local fillerWidth = (Dart.baseWidth - textureWidth) / 2 - DXML:safeSetAttrs(elements[1], { + XML:safeSetAttrs(elements[1], { x = fillerWidth, width = textureWidth, }) - DXML:safeSetAttrs(elements[2], { + XML:safeSetAttrs(elements[2], { x = 0, - width = fillerWidth + width = fillerWidth, }) - DXML:safeSetAttrs(elements[3], { + XML:safeSetAttrs(elements[3], { x = fillerWidth + textureWidth, width = fillerWidth, }) end -function parseScopes(DXML) - DXML:safeIterate(function(child) - resizeScope(DXML, child) +function parseScopes(XML) + XML:safeIterate(function(child) + resizeScope(XML, child) end) end function on_xml_read() - Module.registerModule(mod, "ui\\scopes", parseScopes) + Module.registerModule(mod, "scopes", parseScopes) end diff --git a/gamedata/scripts/modxml_z_dart_status_icons.script b/gamedata/scripts/modxml_z_dart_status_icons.script index 8024833..e095963 100644 --- a/gamedata/scripts/modxml_z_dart_status_icons.script +++ b/gamedata/scripts/modxml_z_dart_status_icons.script @@ -1,41 +1,55 @@ -local Dart = Dart_core -local Utils = Dart_utils +local Dart = dart_core local Module = dart_module -local mod = "STATUS_ICONS" +local mod = "statusIcons" local config = Dart.config.statusIcons +local state = Dart.state.statusIcons -function parseUIHud(DXML) - local indicators = DXML:query("indicators")[1] +function parseUIHud(XML) + local indicators = XML:query("indicators")[1] if not indicators then return end - DXML:scaleElement(indicators, { - bounds = DXML:getElementBounds(indicators), - safezone = config.safezone, - anchor = config.anchor, - offset = config.offset, - scale = config.scale, - autoscale = config.autoscale, - }) - - DXML:safeIterate(indicators, function(child) - DXML:scaleElement(child, { - scale = config.scale, - autoscale = config.autoscale, - }) - - -- hack for UI mods that pass ui_hud_16 or ui_hud_21 - DXML:safeSetAttrs(child, function(attrs) - return {width = attrs.width / (DXML.aspectRatio / Dart.ratio4x3)} + state.xmlAspectRatio = XML.aspectRatio + + local scaleSettings = { + bounds = XML:getBounds(indicators), + safezone = config.safezone, + anchor = config.anchor, + offset = config.offset, + scale = config.scale, + } + + XML:correctX(indicators, scaleSettings) + XML:correctY(indicators, scaleSettings) + + -- width is already aspect-ratio corrected, so we just need + -- to account for the custom scale + XML:safeSetAttrs(indicators, function(attrs) + return { + width = attrs.width * config.scale, + height = attrs.height * config.scale, + } + end) + + XML:safeIterate(indicators, function(child) + XML:correctX(child, {scale = config.scale}) + XML:correctY(child, {scale = config.scale}) + + -- width is already aspect-ratio correct here as well + XML:safeSetAttrs(child, function(attrs) + return { + width = attrs.width * config.scale, + height = attrs.height * config.scale, + } end) end) end function on_xml_read() - Module.registerModule(mod, "ui\\ui_hud", parseUIHud) + Module.registerModule(mod, "ui_hud", parseUIHud) end diff --git a/gamedata/scripts/zzz_dart_companion_list.script b/gamedata/scripts/zzz_dart_companion_list.script index 69e310a..3a16162 100644 --- a/gamedata/scripts/zzz_dart_companion_list.script +++ b/gamedata/scripts/zzz_dart_companion_list.script @@ -1,7 +1,7 @@ local Module = dart_module -local mod = "COMPANION_LIST" +local mod = "companionList" local log = Module.createLogger(mod) @@ -12,12 +12,11 @@ else local InitControls = axr_companions.UICompanionList.InitControls - - -- utils_xml.correct_ratio() seems to do more harm than good in general, but - -- here it's also not consistently implemented, making it damn near impossible - -- to do what we need, disabling it makes things so much easier + -- utils_xml.correct_ratio() seems to do more harm than good and is also + -- not consistently implemented, making it damn near impossible to do + -- what we need, disabling it makes things much easier function axr_companions.UICompanionList:InitControls() - local correctRatio = utils_xml.correct_ratio + local correctRatio = utils_xml.correct_ratio utils_xml.correct_ratio = function() end InitControls(self) diff --git a/gamedata/scripts/zzz_dart_inventory.script b/gamedata/scripts/zzz_dart_inventory.script index 16e993c..0507c16 100644 --- a/gamedata/scripts/zzz_dart_inventory.script +++ b/gamedata/scripts/zzz_dart_inventory.script @@ -1,11 +1,12 @@ -local Dart = Dart_core +local Dart = dart_core local Utils = dart_utils local Module = dart_module -local mod = "INVENTORY" +local mod = "inventory" local log = Module.createLogger(mod) local config = Dart.config.inventory +local state = Dart.state.inventory -- only auto-resize these container IDs (just a best guess) @@ -27,23 +28,9 @@ else local InitControls = utils_ui.UICellContainer.InitControls - function utils_ui.UICellContainer:InitControls(owner, prof, ele_base) - -- make sure XML has been parsed first - if not (Dart.state.inventoryAspectRatio) then - CScriptXmlInit():ParseFile("ui_inventory.xml") - end - - local scale, autoscale, padScale = - config.scale, - config.autoscale, - config.padScale - - local xmlAspectRatio = Dart.state.inventoryAspectRatio - - if autoscale then - scale = Utils.addAutoscale(scale) - end + local scale, padScale = config.scale, config.padScale + local xmlAspectRatio = state.xmlAspectRatio local gridSize = self.grid_size * scale local gridLine = self.grid_line * padScale @@ -57,7 +44,7 @@ else -- calculate how many cells can fit in the given width, -- then resize the cells to perfectly fill that space - local width = Utils.scaleW(container:GetWidth(), xmlAspectRatio) + local width = Utils.correctW(container:GetWidth(), xmlAspectRatio) local itemsPerRow = math.floor(width / (gridSize + gridLine)) local cellSize = width / itemsPerRow @@ -66,7 +53,7 @@ else -- grid_size doesn't stretch to aspect ratio but grid_line does self.grid_size = gridSize - self.grid_line = Utils.scaleW(gridLine, xmlAspectRatio) + self.grid_line = Utils.correctW(gridLine, xmlAspectRatio) return InitControls(self, owner, prof, ele_base) end diff --git a/gamedata/scripts/zzz_dart_patches.script b/gamedata/scripts/zzz_dart_patches.script index 2cd788c..14fc228 100644 --- a/gamedata/scripts/zzz_dart_patches.script +++ b/gamedata/scripts/zzz_dart_patches.script @@ -1,33 +1,25 @@ -local Dart = Dart_core +local Dart = dart_core local Utils = dart_utils local Module = dart_module -local mod = "PATCHES" -local log = Module.createLogger(mod) +local mod = "patches" +local log = Module.createLogger(mod) +local config = Dart.config.patches +local state = Dart.state.patches function onFirstUpdate() -- make sure XML has been parsed first - if not (Dart.state.patchAspectRatio) then - CScriptXmlInit():ParseFile("ui_patches.xml") - end + CScriptXmlInit():ParseFile("ui_patches.xml") local xmlAspectRatio, patchSize = - Dart.state.patchAspectRatio, - Dart.state.patchSize - - local scale, autoscale = - Dart.config.patches.scale, - Dart.config.patches.autoscale - - if autoscale then - scale = Utils.addAutoscale(scale) - end + state.xmlAspectRatio, + state.patchSize local scaleSettings = { - offset = Dart.config.patches.offset, - safezone = Dart.config.patches.safezone + offset = config.offset, + safezone = config.safezone } local xo, xp, xn, xr, yo = @@ -37,23 +29,22 @@ function onFirstUpdate() factionid_hud_mcm.xr, factionid_hud_mcm.yo - xp = (xp + patchSize.x / 2) * scale - xn = (xn + patchSize.x / 2) * scale - xr = (xr + patchSize.x / 2) * scale + xp = (xp + patchSize.x / 2) * config.scale + xn = (xn + patchSize.x / 2) * config.scale + xr = (xr + patchSize.x / 2) * config.scale - factionid_hud_mcm.xo = Utils.scaleX(xo, xmlAspectRatio, scaleSettings) - factionid_hud_mcm.yo = Utils.scaleY(yo, xmlAspectRatio, scaleSettings) - factionid_hud_mcm.xp = Utils.scaleX(xp, xmlAspectRatio) - factionid_hud_mcm.xn = Utils.scaleX(xn, xmlAspectRatio) - factionid_hud_mcm.xr = Utils.scaleX(xr, xmlAspectRatio) + factionid_hud_mcm.xo = Utils.correctX(xo, xmlAspectRatio, scaleSettings) + factionid_hud_mcm.yo = Utils.correctY(yo, xmlAspectRatio, scaleSettings) + factionid_hud_mcm.xp = Utils.correctX(xp, xmlAspectRatio) + factionid_hud_mcm.xn = Utils.correctX(xn, xmlAspectRatio) + factionid_hud_mcm.xr = Utils.correctX(xr, xmlAspectRatio) end function on_game_start() if Module.isDisabled(mod) then - log("Disabled, skipping patch MCM values") - else - log("Overriding patch MCM values") - RegisterScriptCallback("actor_on_first_update", onFirstUpdate) + return log("Disabled, skipping UI patch MCM values") end + + RegisterScriptCallback("actor_on_first_update", onFirstUpdate) end diff --git a/gamedata/scripts/zzz_dart_status_icons.script b/gamedata/scripts/zzz_dart_status_icons.script index 48a73b1..4676a07 100644 --- a/gamedata/scripts/zzz_dart_status_icons.script +++ b/gamedata/scripts/zzz_dart_status_icons.script @@ -1,62 +1,72 @@ +local Dart = dart_core local Module = dart_module +local Utils = dart_utils -local mod = "STATUS_ICONS" -local log = Module.createLogger(mod) +local mod = "statusIcons" +local log = Module.createLogger(mod) +local config = Dart.config.statusIcons +local state = Dart.state.statusIcons if Module.isDisabled(mod) then log("Disabled, skipping UIIndicators:InitControls()") else - log("Overriding UIIndicators:InitControls()") + log("Monkey patching UIIndicators:InitControls()") + local InitControls = actor_status.UIIndicators.InitControls - -- strips the ratio and scale adjustments out of the base method and - -- forces it to respect the values defined in the XML - function alticons.actor_status.UIIndicators:InitControls() - self.offset = 2 - self.timeOffset = 15 + -- The base function is filled with hard-coded values that can't easily be + -- changed, and that makes fixing the status icons unnecessarily hard, so we + -- have a mess to clean up and need to get creative to do it + function actor_status.UIIndicators:InitControls() + local getHudXML = utils_xml.get_hud_xml - local xml = utils_xml.get_hud_xml() + -- The base function calls this after setting self.W and before initializing + -- the UI so it's the ideal place to do what we need + function utils_xml.get_hud_xml() + local hudXML = getHudXML() + local ratio = Utils.getAspectRatioVs(state.xmlAspectRatio) - local time_xml = CScriptXmlInit() - time_xml:ParseFile("actor_menu.xml") + local iconWidth = tonumber( + hudXML:ReadAttribute("indicators:static", 0, "width") + ) - self.dialog = xml:InitStatic("indicators", self) - self.dialog:Show(false) + -- force self.W to respect the XML value + if iconWidth then + self.W = iconWidth * alticons.size_adjust / ratio + end - for i = 1, size_table(actor_status.indicators) do - self.slot[i] = { - back_s = xml:InitStatic("indicators:static", self.dialog), - back_f = xml:InitStatic("indicators:flashing", self.dialog), - icon_s = xml:InitStatic("indicators:static", self.dialog), - icon_f = xml:InitStatic("indicators:flashing", self.dialog), - xcvb_time = time_xml:InitTextWnd("quick_slot3_text", self), - } + -- allow a custom spacing value + self.offset = config.spacing * alticons.size_adjust / ratio - for _, el in pairs(self.slot[i]) do - el:SetWndPos(vector2():set( - (el:GetWidth() + self.offset) * (self.mirroed and 1 - i or i - 1), - 0 - )) - end + local InitStatic = hudXML.InitStatic + + -- Intercept the first call to xml:InitStatic(), which should be the call + -- that initializes self.dialog. We need its instance to prevent the base + -- function from "nudging" it with problematic hard-coded values + function hudXML:InitStatic(path, instance) + self.InitStatic = InitStatic - local dialog_pos = self.dialog:GetWndPos() - local icon_pos = self.slot[i].icon_f:GetWndPos() - local icon_width = self.slot[i].icon_f:GetWidth() - local self_height = self.slot[i].xcvb_time:GetHeight() + local dialog = self:InitStatic(path, instance) + local SetWndPos = dialog.SetWndPos - self.slot[i].xcvb_time:SetWndPos(vector2():set( - dialog_pos.x + icon_pos.x, - dialog_pos.y + icon_pos.y - self.timeOffset - )) + -- Disable the first call to dialog:SetWndPos() to prevent the base + -- function from "nudging" {x, y} so that it respects the XML + function dialog:SetWndPos() + self.SetWndPos = SetWndPos + end - self.slot[i].xcvb_time:SetWndSize(vector2():set( - icon_width, - self_height - )) + return dialog + end - self.slot[i].xcvb_time:SetText("") + return hudXML end + + -- call the base function + InitControls(self) + + -- restore original functionality + utils_xml.get_hud_xml = getHudXML end end