Changeset 25966

Timestamp:
Oct 17, 2021, 12:58:51 PM (3 years ago)
Author:
Silier
Message:

There have been quite a bit of number of questions how to change scale of the gui, because this option is hidden from the user.

Use dropdown with values. Implement confirmation box with countdown to revert scale change because buttons can get unable to click.

Differential revision: D3037
Comments by: @vladislavbelov, @Stan, @wraitii, @pieq, @sera
Tested by: @Langbart

Location:
ps/trunk
Files:
5 added
15 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/binaries/data/mods/mod/gui/common/functions_msgbox.js

    r22676 r25966  
    1616}
    1717
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
    1836function openURL(url)
    1937{
  • ps/trunk/binaries/data/mods/mod/gui/msgbox/msgbox.js

    r22676 r25966  
    2525    let captions = data.buttonCaptions || [translate("OK")];
    2626
    27     // Set button captions and visibility
    2827    let mbButton = [];
    29     captions.forEach((caption, i) => {
    30         mbButton[i] = Engine.GetGUIObjectByName("mbButton" + (i + 1));
    31         mbButton[i].caption = caption;
    32         mbButton[i].hidden = false;
    33         mbButton[i].onPress = () => {
    34             Engine.PopGuiPage(i);
    35         };
    36 
    37         // Convention: Cancel is the first button
    38         if (i == 0)
    39             mbCancelHotkey.onPress = mbButton[i].onPress;
    40     });
    41 
    42     // Distribute buttons horizontally
    43     let y1 = "100%-46";
    44     let y2 = "100%-18";
    45     switch (captions.length)
    46     {
    47     case 1:
    48         mbButton[0].size = "18 " + y1 + " 100%-18 " + y2;
    49         break;
    50     case 2:
    51         mbButton[0].size = "18 " + y1 + " 50%-5 " + y2;
    52         mbButton[1].size = "50%+5 " + y1 + " 100%-18 " + y2;
    53         break;
    54     case 3:
    55         mbButton[0].size = "18 " + y1 + " 33%-5 " + y2;
    56         mbButton[1].size = "33%+5 " + y1 + " 66%-5 " + y2;
    57         mbButton[2].size = "66%+5 " + y1 + " 100%-18 " + y2;
    58         break;
    59     }
     28    setButtonCaptionsAndVisibitily(mbButton, captions, mbCancelHotkey, "mbButton");
     29    distributeButtonsHorizontally(mbButton, captions);
    6030}
  • ps/trunk/binaries/data/mods/public/gui/options/options.js

    r24445 r25966  
    147147        }
    148148    },
     149
     150
     151
     152
     153
     154
     155
     156
     157
     158
     159
     160
     161
     162
     163
     164
     165
     166
     167
     168
     169
     170
     171
     172
     173
     174
     175
     176
     177
    149178    "slider":
    150179    {
     
    243272                optionType.sanitizeValue(value, control, option);
    244273
     274
     275
    245276            control.tooltip = option.tooltip + (optionType.tooltip ? "\n" + optionType.tooltip(value, option) : "");
    246277
     278
    247279            Engine.ConfigDB_CreateValue("user", option.config, String(value));
    248280            Engine.ConfigDB_SetChanges("user", true);
     
    250282            g_ChangedKeys.add(option.config);
    251283            fireConfigChangeHandlers(new Set([option.config]));
     284
     285
     286
    252287
    253288            if (option.function)
     
    314349    Engine.ConfigDB_WriteFile("user", "config/user.cfg");
    315350    revertChanges();
     351
     352
     353
     354
     355
     356
     357
     358
     359
     360
     361
     362
    316363}
    317364
  • ps/trunk/binaries/data/mods/public/gui/options/options.json

    r25866 r25966  
    151151                "min": 20,
    152152                "max": 100
     153
     154
     155
     156
     157
     158
     159
     160
     161
     162
     163
     164
     165
     166
     167
     168
     169
     170
    153171            }
    154172        ]
  • ps/trunk/binaries/data/mods/public/gui/options/options.xml

    r23947 r25966  
    3434                    <object name="option_control_number[n]" size="65% 0 100%-8 100%" type="input" style="ModernInput"/>
    3535                    <object name="option_control_dropdown[n]" size="65% 0 100%-8 100%" type="dropdown" style="ModernDropDown" tooltip_style="tooltipInstant"/>
     36
    3637                    <object name="option_control_slider[n]" size="65% 0 100%-8 100%" type="slider" style="ModernSlider"/>
    3738                </object>
  • ps/trunk/source/gui/CGUI.cpp

    r25746 r25966  
    4343#include "ps/Profile.h"
    4444#include "ps/Pyrogenesis.h"
     45
    4546#include "ps/XML/Xeromyces.h"
    4647#include "scriptinterface/ScriptContext.h"
     
    155156        //  constant conversions when operating in a
    156157        //  float-based environment.
    157         m_MousePos = CVector2D((float)ev->ev.motion.x / g_GuiScale, (float)ev->ev.motion.y / g_GuiScale);
     158        m_MousePos = CVector2D((float)ev->ev.motion.x / g_);
    158159
    159160        SGUIMessage msg(GUIM_MOUSE_MOTION);
     
    180181    if (ev->ev.type == SDL_MOUSEBUTTONDOWN || ev->ev.type == SDL_MOUSEBUTTONUP)
    181182    {
    182         m_MousePos = CVector2D((float)ev->ev.button.x / g_GuiScale, (float)ev->ev.button.y / g_GuiScale);
     183        m_MousePos = CVector2D((float)ev->ev.button.x / g_);
    183184    }
    184185
     
    421422CSize2D CGUI::GetWindowSize() const
    422423{
    423     return CSize2D{static_cast<float>(g_xres) / g_GuiScale, static_cast<float>(g_yres) / g_GuiScale};
     424    return CSize2D{static_cast<float>(g_xres) / g_};
    424425}
    425426
  • ps/trunk/source/gui/CGUIText.cpp

    r25645 r25966  
    2727#include "gui/SettingTypes/CGUIString.h"
    2828#include "ps/CStrInternStatic.h"
     29
    2930#include "renderer/Renderer.h"
    3031
     
    3233
    3334extern int g_xres, g_yres;
    34 extern float g_GuiScale;
    3535
    3636// TODO Gee: CRect => CPoint ?
     
    440440        clipping.right = std::floor(clipping.right);
    441441
     442
    442443        glEnable(GL_SCISSOR_TEST);
    443444        glScissor(
    444             std::ceil(clipping.left * g_GuiScale),
    445             std::ceil(g_yres - clipping.bottom * g_GuiScale),
    446             std::floor(clipping.GetWidth() * g_GuiScale),
    447             std::floor(clipping.GetHeight() * g_GuiScale));
     445            std::ceil(clipping.left * cale),
     446            std::ceil(g_yres - clipping.bottom * cale),
     447            std::floor(clipping.GetWidth() * cale),
     448            std::floor(clipping.GetHeight() * cale));
    448449    }
    449450
  • ps/trunk/source/gui/GUIMatrix.cpp

    r22605 r25966  
    1 /* Copyright (C) 2019 Wildfire Games.
     1/* Copyright (C) 20 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
     
    1919
    2020#include "GUIMatrix.h"
    21 
     21#include "ps/VideoMode.h"
    2222#include "maths/Matrix3D.h"
    2323
    2424extern int g_xres, g_yres;
    25 extern float g_GuiScale;
    2625
    2726CMatrix3D GetDefaultGuiMatrix()
    2827{
    29     float xres = g_xres / g_GuiScale;
    30     float yres = g_yres / g_GuiScale;
     28    float xres = g_xres / g_;
     29    float yres = g_yres / g_;
    3130
    3231    CMatrix3D m;
  • ps/trunk/source/gui/ObjectTypes/CInput.cpp

    r25693 r25966  
    3232#include "ps/Globals.h"
    3333#include "ps/Hotkey.h"
     34
    3435#include "renderer/Renderer.h"
    3536
     
    12391240    if (cliparea != CRect())
    12401241    {
     1242
    12411243        glEnable(GL_SCISSOR_TEST);
    12421244        glScissor(
    1243             cliparea.left * g_GuiScale,
    1244             g_yres - cliparea.bottom * g_GuiScale,
    1245             cliparea.GetWidth() * g_GuiScale,
    1246             cliparea.GetHeight() * g_GuiScale);
     1245            cliparea.left * cale,
     1246            g_yres - cliparea.bottom * cale,
     1247            cliparea.GetWidth() * cale,
     1248            cliparea.GetHeight() * cale);
    12471249    }
    12481250
  • ps/trunk/source/ps/CConsole.cpp

    r25648 r25966  
    4646#include "ps/Profile.h"
    4747#include "ps/Pyrogenesis.h"
     48
    4849#include "scriptinterface/ScriptInterface.h"
    4950#include "scriptinterface/JSON.h"
     
    117118    m_fY = 0;
    118119    float height = h * 0.6f;
    119     m_fWidth = w / g_GuiScale;
    120     m_fHeight = height / g_GuiScale;
     120    m_fWidth = w / g_;
     121    m_fHeight = height / g_;
    121122}
    122123
  • ps/trunk/source/ps/GameSetup/Config.cpp

    r25936 r25966  
    3030
    3131int g_xres, g_yres;
    32 float g_GuiScale = 1.0f;
    3332
    3433bool g_Quickstart = false;
     
    4342{
    4443    CFG_GET_VAL("pauseonfocusloss", g_PauseOnFocusLoss);
    45 
    46     CFG_GET_VAL("gui.scale", g_GuiScale);
    4744}
    48 
    4945
    5046static void ProcessCommandLineArgs(const CmdLineArgs& args)
  • ps/trunk/source/ps/GameSetup/Config.h

    r25936 r25966  
    2525
    2626extern int g_xres, g_yres;
    27 extern float g_GuiScale;
    2827
    2928extern bool g_Quickstart;
  • ps/trunk/source/ps/VideoMode.cpp

    r25936 r25966  
    179179        return;
    180180    }
    181     const float scale = g_GuiScale;
     181    const float scale = g_;
    182182    if (scale != 1.0)
    183183    {
     
    223223    CFG_GET_VAL("windowed", windowed);
    224224    m_ConfigFullscreen = !windowed;
     225
     226
    225227
    226228    CFG_GET_VAL("xres", m_ConfigW);
     
    517519}
    518520
     521
     522
     523
     524
     525
     526
     527
     528
     529
     530
     531
     532
    519533bool CVideoMode::SetFullscreen(bool fullscreen)
    520534{
  • ps/trunk/source/ps/VideoMode.h

    r25936 r25966  
    5353
    5454    /**
     55
     56
     57
     58
     59
    5560     * Switch to fullscreen or windowed mode.
    5661     */
     
    9095    int GetDesktopFreq() const;
    9196
     97
     98
    9299    SDL_Window* GetWindow();
    93100
     
    117124    int m_PreferredBPP = 0;
    118125    int m_PreferredFreq = 0;
     126
     127
    119128
    120129    // Config file settings (0 if unspecified)
  • ps/trunk/source/ps/scripting/JSInterface_ConfigDB.cpp

    r25866 r25966  
    2222#include "ps/ConfigDB.h"
    2323#include "ps/CLogger.h"
     24
    2425#include "scriptinterface/FunctionWrapper.h"
    2526#include "scriptinterface/ScriptRequest.h"
     
    194195}
    195196
     197
     198
     199
     200
     201
    196202void RegisterScriptFunctions(const ScriptRequest& rq)
    197203{
     
    208214    ScriptFunction::Register<&Reload>(rq, "ConfigDB_Reload");
    209215    ScriptFunction::Register<&PauseOnFocusLoss>(rq, "PauseOnFocusLoss");
    210 }
    211 }
     216    ScriptFunction::Register<&SetGUIScale>(rq, "SetGUIScale");
     217}
     218}
Note: See TracChangeset for help on using the changeset viewer.