Ticket #4321: maxSize.patch

File maxSize.patch, 8.8 KB (added by s0600204, 7 years ago)

Proposed patch

  • binaries/data/mods/mod/gui/common/modern/styles.xml

    diff --git a/binaries/data/mods/mod/gui/common/modern/styles.xml b/binaries/data/mods/mod/gui/common/modern/styles.xml
    index cfa4b6b..8ff04c9 100644
    a b  
    1313        ghost="false"
    1414        hidden="false"
    1515        size="0 0 100% 100%"
     16        size_max="0 0 100% 100%"
    1617        z="0"
    1718        font="sans-14"
    1819        buffer_zone="5"
  • binaries/data/mods/mod/gui/gui.rnc

    diff --git a/binaries/data/mods/mod/gui/gui.rnc b/binaries/data/mods/mod/gui/gui.rnc
    index 034078d..c2fb8d6 100644
    a b base_settings =  
    4343  attribute ghost { bool }?&
    4444  attribute hidden { bool }?&
    4545  attribute size { clientarea }?&
     46  attribute size_max { clientarea }?&
    4647  attribute z { xsd:decimal }?
    4748# Defaults are not put in here, because it ruins the concept of styles.
    4849ex_settings =
  • binaries/data/mods/mod/gui/gui.rng

    diff --git a/binaries/data/mods/mod/gui/gui.rng b/binaries/data/mods/mod/gui/gui.rng
    index fde243b..af8bca7 100644
    a b  
    160160        </attribute>
    161161      </optional>
    162162      <optional>
     163        <attribute name="size_max">
     164          <ref name="clientarea"/>
     165        </attribute>
     166      </optional>
     167      <optional>
    163168        <attribute name="z">
    164169          <data type="decimal"/>
    165170        </attribute>
  • binaries/data/mods/public/gui/common/styles.xml

    diff --git a/binaries/data/mods/public/gui/common/styles.xml b/binaries/data/mods/public/gui/common/styles.xml
    index ed3a9a0..ce1a9ff 100644
    a b  
    1515        ghost="false"
    1616        hidden="false"
    1717        size="0 0 100% 100%"
     18        size_max="0 0 100% 100%"
    1819        z="0"
    1920
    2021        font="sans-14"
  • binaries/data/mods/public/gui/structree/draw.js

    diff --git a/binaries/data/mods/public/gui/structree/draw.js b/binaries/data/mods/public/gui/structree/draw.js
    index 9b94943..4527f64 100644
    a b  
    11var g_DrawLimits = {}; // GUI limits. Populated by predraw()
     2var g_ContentWidth = 0;
    23
    34var g_TooltipFunctions = [
    45    getEntityNamesFormatted,
    function draw()  
    4041    Engine.GetGUIObjectByName("civHistory").caption = g_CivData[g_SelectedCiv].History;
    4142
    4243    let i = 0;
     44    g_ContentWidth = 0;
    4345    for (let pha of phaseList)
    4446    {
    4547        let prodBarWidth = 0;
    function draw()  
    139141            hideRemaining("phase["+i+"]_struct["+s+"]_row[", r, "]");
    140142            ++s;
    141143            prodBarWidth += eleWidth + defMargin;
     144            g_ContentWidth = Math.max(y, g_ContentWidth);
    142145        }
    143146        hideRemaining("phase["+i+"]_struct[", s, "]");
    144147        let offset = getPositionOffset(i);
    function draw()  
    148151        {
    149152            let prodBar = Engine.GetGUIObjectByName("phase["+i+"]_bar["+(j-1)+"]");
    150153            let prodBarSize = prodBar.size;
    151             prodBarSize.right = leftMargin + prodBarWidth;
     154            prodBarSize.right = leftMargin + prodBarWidth + defMargin * 2;
    152155            prodBar.size = prodBarSize;
    153156        }
    154157
    function draw()  
    213216
    214217    let size = Engine.GetGUIObjectByName("display_tree").size;
    215218    size.right = t > 0 ? -124 : -4;
     219    g_ContentWidth += t > 0 ? 28 + defWidth : 4
    216220    Engine.GetGUIObjectByName("display_tree").size = size;
    217221
    218222    Engine.GetGUIObjectByName("display_trainers").hidden = t == 0;
     223
     224    g_ContentWidth += 96;
     225    updatePageMaxWidth();
     226}
     227
     228function updatePageMaxWidth()
     229{
     230    let page_maxsize = Engine.GetGUIObjectByName("structree_page").size_max;
     231    let x = g_ContentWidth / 2;
     232    page_maxsize.left = -x;
     233    page_maxsize.right = x;
     234    Engine.GetGUIObjectByName("structree_page").size_max = page_maxsize;
    219235}
    220236
    221237function drawProdIcon(pha, s, r, p, prod)
    function predraw()  
    275291    let phaseList = g_ParsedData.phaseList;
    276292    let initIconSize = Engine.GetGUIObjectByName("phase[0]_struct[0]_row[0]_prod[0]").size;
    277293
     294    let page_maxsize = Engine.GetGUIObjectByName("structree_page").size_max;
     295    page_maxsize.rleft = 50;
     296    page_maxsize.rright = 50;
     297    Engine.GetGUIObjectByName("structree_page").size_max = page_maxsize;
     298
    278299    let phaseCount = phaseList.length;
    279300    let i = 0;
    280301    for (let pha of phaseList)
    function predraw()  
    353374    hideRemaining("phase[", i, "]");
    354375    hideRemaining("phase[", i, "]_bar");
    355376
     377    let page_size = Engine.GetGUIObjectByName("structree_page").size;
     378    let offset = getPositionOffset(i) + 196;
     379    page_size.top = -offset / 2;
     380    page_size.bottom = offset / 2;
     381    Engine.GetGUIObjectByName("structree_page").size = page_size;
     382
    356383    let t = 0;
    357384    let ele = Engine.GetGUIObjectByName("trainer["+t+"]");
    358385    g_DrawLimits.trainer = {
  • binaries/data/mods/public/gui/structree/structree.xml

    diff --git a/binaries/data/mods/public/gui/structree/structree.xml b/binaries/data/mods/public/gui/structree/structree.xml
    index dbe6e24..912a387 100644
    a b  
    1313    <!-- Add a translucent black background to fade out the menu page -->
    1414    <object type="image" z="0" sprite="BackgroundTranslucent"/>
    1515
    16     <object type="image" style="ModernDialog" size="16 24 100%-16 100%-24">
     16    <object type="image" style="ModernDialog" size="16 50%-360 100%-16 50%+360" name="structree_page">
    1717        <object style="TitleText" type="text" size="50%-128 -18 50%+128 14">
    1818            <translatableAttribute id="caption">Structure Tree</translatableAttribute>
    1919        </object>
  • source/gui/CTooltip.cpp

    diff --git a/source/gui/CTooltip.cpp b/source/gui/CTooltip.cpp
    index f44dbe6..aed3cf7 100644
    a b CTooltip::CTooltip()  
    4949    GUI<int>::SetSetting(this, "delay", 500);
    5050    GUI<EVAlign>::SetSetting(this, "anchor", EVAlign_Bottom);
    5151    GUI<EAlign>::SetSetting(this, "text_align", EAlign_Left);
     52    GUI<CClientArea>::SetSetting(this, "size_max", CClientArea("0 0 100% 100%"));
    5253
    5354    // Set up a blank piece of text, to be replaced with a more
    5455    // interesting message later
  • source/gui/GUIbase.cpp

    diff --git a/source/gui/GUIbase.cpp b/source/gui/GUIbase.cpp
    index 1f5b247..1f5bd11 100644
    a b CRect CClientArea::GetClientArea(const CRect& parent) const  
    5252    return client;
    5353}
    5454
     55
     56CRect CClientArea::GetClientArea(const CRect& parent, const CClientArea& maxLimit) const
     57{
     58    CRect limit = maxLimit.GetClientArea(parent);
     59    CRect client = this->GetClientArea(parent);
     60
     61    // If no limit imposed, then we don't need to restrict
     62    if (parent == limit)
     63        return client;
     64
     65    client.left = std::max(client.left, limit.left);
     66    client.top = std::max(client.top, limit.top);
     67    client.right = std::min(client.right, limit.right);
     68    client.bottom = std::min(client.bottom, limit.bottom);
     69
     70    return client;
     71}
     72
    5573bool CClientArea::SetClientArea(const CStr& Value)
    5674{
    5775    /* ClientAreas contain a left, top, right, and bottom
  • source/gui/GUIbase.h

    diff --git a/source/gui/GUIbase.h b/source/gui/GUIbase.h
    index f71c733..56c1c55 100644
    a b public:  
    177177     * Get client area rectangle when the parent is given
    178178     */
    179179    CRect GetClientArea(const CRect& parent) const;
     180    CRect GetClientArea(const CRect& parent, const CClientArea& maxLimit) const;
    180181
    181182    /**
    182183     * The ClientArea can be set from a string looking like:
  • source/gui/GUIutil.cpp

    diff --git a/source/gui/GUIutil.cpp b/source/gui/GUIutil.cpp
    index 2c0f63f..752a678 100644
    a b PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, const T& V  
    390390    //
    391391
    392392    // If setting was "size", we need to re-cache itself and all children
    393     if (Setting == "size")
     393    if (Setting == "size" || Setting == "size_max")
    394394    {
    395395        RecurseObject(0, pObject, &IGUIObject::UpdateCachedSize);
    396396    }
  • source/gui/IGUIObject.cpp

    diff --git a/source/gui/IGUIObject.cpp b/source/gui/IGUIObject.cpp
    index e0efbf8..12b8135 100644
    a b IGUIObject::IGUIObject()  
    3434    AddSetting(GUIST_bool,          "enabled");
    3535    AddSetting(GUIST_bool,          "hidden");
    3636    AddSetting(GUIST_CClientArea,   "size");
     37    AddSetting(GUIST_CClientArea,   "size_max");
    3738    AddSetting(GUIST_CStr,          "style");
    3839    AddSetting(GUIST_CStr,          "hotkey");
    3940    AddSetting(GUIST_float,         "z");
    void IGUIObject::UpdateCachedSize()  
    307308    CClientArea ca;
    308309    GUI<CClientArea>::GetSetting(this, "size", ca);
    309310
     311    CClientArea ca_max;
     312    GUI<CClientArea>::GetSetting(this, "size_max", ca_max);
     313
    310314    // If absolute="false" and the object has got a parent,
    311315    //  use its cached size instead of the screen. Notice
    312316    //  it must have just been cached for it to work.
    313317    if (absolute == false && m_pParent && !IsRootObject())
    314         m_CachedActualSize = ca.GetClientArea(m_pParent->m_CachedActualSize);
     318        m_CachedActualSize = ca.GetClientArea(m_pParent->m_CachedActualSize, ca_max);
    315319    else
    316         m_CachedActualSize = ca.GetClientArea(CRect(0.f, 0.f, g_xres * g_GuiScale, g_yres * g_GuiScale));
     320        m_CachedActualSize = ca.GetClientArea(CRect(0.f, 0.f, g_xres * g_GuiScale, g_yres * g_GuiScale), ca_max);
    317321
    318322    // In a few cases, GUI objects have to resize to fill the screen
    319323    // but maintain a constant aspect ratio.