diff --git a/binaries/data/mods/public/gui/reference/structree/Sections/Trainer/TrainerSection.js b/binaries/data/mods/public/gui/reference/structree/Sections/Trainer/TrainerSection.js index f532ff0eff..30766212a1 100644 --- a/binaries/data/mods/public/gui/reference/structree/Sections/Trainer/TrainerSection.js +++ b/binaries/data/mods/public/gui/reference/structree/Sections/Trainer/TrainerSection.js @@ -59,6 +59,11 @@ class TrainerSection for (let handler of this.widthChangedHandlers) handler(this.width, !this.TrainerSection.hidden); } + + isVisible() + { + return !this.TrainerSection.hidden; + } } TrainerSection.prototype.Caption = diff --git a/binaries/data/mods/public/gui/reference/structree/Sections/Tree/TreeSection.js b/binaries/data/mods/public/gui/reference/structree/Sections/Tree/TreeSection.js index a9ede02230..1ede107cea 100644 --- a/binaries/data/mods/public/gui/reference/structree/Sections/Tree/TreeSection.js +++ b/binaries/data/mods/public/gui/reference/structree/Sections/Tree/TreeSection.js @@ -10,6 +10,9 @@ class TreeSection this.PhaseIdents = new PhaseIdentManager(this.page); this.rightMargin = this.TreeSection.size.right; + this.vMargin = this.TreeSection.size.top + -this.TreeSection.size.bottom; + this.width = 0; + this.height = 0; this.structureBoxes = []; for (let boxIdx in this.Structures.children) @@ -34,6 +37,9 @@ class TreeSection // Position phase idents this.PhaseIdents.draw(phaseList, civCode, runningWidths, this.Structures.size.left); + + this.width = this.Structures.size.left + Math.max(...runningWidths) + EntityBox.prototype.HMargin; + this.height = this.constructor.getPositionOffset(phaseList.length, this.page.TemplateParser); } drawPhaseIcon(phaseIcon, phaseIndex, civCode) diff --git a/binaries/data/mods/public/gui/reference/structree/StructreePage.js b/binaries/data/mods/public/gui/reference/structree/StructreePage.js index b41d6bbe14..d5b18984e4 100644 --- a/binaries/data/mods/public/gui/reference/structree/StructreePage.js +++ b/binaries/data/mods/public/gui/reference/structree/StructreePage.js @@ -12,6 +12,8 @@ class StructreePage extends ReferencePage this.structureBoxes = []; this.trainerBoxes = []; + this.StructreePage = Engine.GetGUIObjectByName("structreePage"); + this.Background = Engine.GetGUIObjectByName("background"); this.CivEmblem = Engine.GetGUIObjectByName("civEmblem"); this.CivName = Engine.GetGUIObjectByName("civName"); this.CivHistory = Engine.GetGUIObjectByName("civHistory"); @@ -30,6 +32,9 @@ class StructreePage extends ReferencePage let civInfoButton = new CivInfoButton(this); let closeButton = new CloseButton(this); Engine.SetGlobalHotkey("structree", "Press", this.closePage.bind(this)); + + this.StructreePage.onWindowResized = this.updatePageWidth.bind(this); + this.width = 0; } closePage() @@ -48,6 +53,31 @@ class StructreePage extends ReferencePage let templateLists = this.TemplateLister.getTemplateLists(this.activeCiv); this.TreeSection.draw(templateLists.structures, this.activeCiv); this.TrainerSection.draw(templateLists.units, this.activeCiv); + + this.width = this.TreeSection.width + -this.TreeSection.rightMargin; + if (this.TrainerSection.isVisible()) + this.width += this.TrainerSection.width + this.SectionGap; + this.updatePageWidth(); + this.updatePageHeight(); + } + + updatePageHeight() + { + let y = (this.TreeSection.height + this.TreeSection.vMargin) / 2; + let pageSize = this.StructreePage.size; + pageSize.top = -y; + pageSize.bottom = y; + this.StructreePage.size = pageSize; + } + + updatePageWidth() + { + let screenSize = this.Background.getComputedSize(); + let pageSize = this.StructreePage.size; + let x = Math.min(this.width, screenSize.right - this.BorderMargin * 2) / 2; + pageSize.left = -x; + pageSize.right = x; + this.StructreePage.size = pageSize; } } @@ -56,3 +86,7 @@ StructreePage.prototype.CloseButtonTooltip = // Gap between the `TreeSection` and `TrainerSection` gui objects (when the latter is visible) StructreePage.prototype.SectionGap = 12; + +// Margin around the edge of the structree on lower resolutions, +// preventing the UI from being clipped by the edges of the screen. +StructreePage.prototype.BorderMargin = 16; diff --git a/binaries/data/mods/public/gui/reference/structree/structree.xml b/binaries/data/mods/public/gui/reference/structree/structree.xml index b27799efcd..4c5301d4c2 100644 --- a/binaries/data/mods/public/gui/reference/structree/structree.xml +++ b/binaries/data/mods/public/gui/reference/structree/structree.xml @@ -13,9 +13,9 @@