mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2025-02-18 13:58:28 +00:00
font size can be configured in options
This commit is contained in:
parent
4895134fd2
commit
d42489b7e6
3 changed files with 49 additions and 6 deletions
Assets/Scripts
|
@ -26,7 +26,12 @@ namespace SanAndreasUnity.Behaviours
|
|||
|
||||
bool m_isFirstOnGUI = true;
|
||||
|
||||
bool m_shouldChangeFontSize = false;
|
||||
int m_imguiFontSize = 0;
|
||||
public int ImguiFontSize { get => m_imguiFontSize; set { m_imguiFontSize = value; m_shouldChangeFontSize = true; } }
|
||||
|
||||
[SerializeField] int m_defaultFontSizeOnMobile = 16;
|
||||
|
||||
[SerializeField] float m_scrollbarSizeMultiplierOnMobile = 2f;
|
||||
|
||||
// note: UIManager's OnGUI() should execute before other OnGUI()s, because other scripts may try to create their own
|
||||
|
@ -45,6 +50,12 @@ namespace SanAndreasUnity.Behaviours
|
|||
this.UseTouchInput = true;
|
||||
}
|
||||
|
||||
// set default font size on mobile platforms
|
||||
if (Application.isMobilePlatform)
|
||||
{
|
||||
this.ImguiFontSize = m_defaultFontSizeOnMobile;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
|
@ -53,10 +64,15 @@ namespace SanAndreasUnity.Behaviours
|
|||
if (m_isFirstOnGUI)
|
||||
{
|
||||
m_isFirstOnGUI = false;
|
||||
|
||||
this.SetupGui();
|
||||
}
|
||||
|
||||
if (m_shouldChangeFontSize)
|
||||
{
|
||||
m_shouldChangeFontSize = false;
|
||||
SetStylesFontSize(m_imguiFontSize);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SetupGui()
|
||||
|
@ -83,9 +99,6 @@ namespace SanAndreasUnity.Behaviours
|
|||
style.fixedWidth *= m_scrollbarSizeMultiplierOnMobile;
|
||||
}
|
||||
|
||||
// set font size for styles
|
||||
SetStylesFontSize(m_defaultFontSizeOnMobile);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -97,7 +110,7 @@ namespace SanAndreasUnity.Behaviours
|
|||
var styles = new GUIStyle[]{skin.button, skin.label, skin.textArea, skin.textField, skin.toggle, skin.window, skin.box};
|
||||
foreach (var style in styles)
|
||||
{
|
||||
//Debug.LogFormat("style: {0}, font size: {1}", style.name, style.fontSize);
|
||||
Debug.LogFormat("style: {0}, font size: {1}", style.name, style.fontSize);
|
||||
style.fontSize = newFontSize;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,6 +50,12 @@ namespace SanAndreasUnity.Settings {
|
|||
setValue = (value) => { UIManager.Instance.UseTouchInput = value; },
|
||||
persistType = OptionsWindow.InputPersistType.OnStart
|
||||
};
|
||||
OptionsWindow.IntInput m_imguiFontSize = new OptionsWindow.IntInput ("Imgui font size", 0, 25) {
|
||||
//isAvailable = () => UIManager.Instance != null,
|
||||
getValue = () => UIManager.Instance.ImguiFontSize,
|
||||
setValue = (value) => { UIManager.Instance.ImguiFontSize = value; },
|
||||
persistType = OptionsWindow.InputPersistType.OnStart,
|
||||
};
|
||||
|
||||
OptionsWindow.FloatInput m_pedSyncRate = new OptionsWindow.FloatInput ("Ped sync rate", 1, 60) {
|
||||
isAvailable = () => PedManager.Instance != null,
|
||||
|
@ -132,7 +138,7 @@ namespace SanAndreasUnity.Settings {
|
|||
void Awake ()
|
||||
{
|
||||
var inputs = new OptionsWindow.Input[] { m_timeScaleInput, m_gravityInput, m_displayHealthBarsInput, m_displayMinimapInput,
|
||||
m_runInBackgroundInput, m_drawLineFromGunInput, m_enableCamera, m_useTouchInput,
|
||||
m_runInBackgroundInput, m_drawLineFromGunInput, m_enableCamera, m_useTouchInput, m_imguiFontSize,
|
||||
m_pausePlayerSpawning, m_playerSpawnInterval,
|
||||
m_pedSyncRate,
|
||||
m_vehicleSyncRate, m_syncVehicleTransformUsingSyncVars, m_syncVehiclesLinearVelocity,
|
||||
|
|
|
@ -91,6 +91,30 @@ namespace SanAndreasUnity.UI {
|
|||
|
||||
}
|
||||
|
||||
public class IntInput : Input<int>
|
||||
{
|
||||
public int minValue;
|
||||
public int maxValue;
|
||||
|
||||
public IntInput () { }
|
||||
|
||||
public IntInput (string description, int minValue, int maxValue) : base (description)
|
||||
{
|
||||
this.minValue = minValue;
|
||||
this.maxValue = maxValue;
|
||||
}
|
||||
|
||||
public override int Display (int currentValue)
|
||||
{
|
||||
return Mathf.RoundToInt( OptionsWindow.FloatSlider (currentValue, this.minValue, this.maxValue, this.description) );
|
||||
}
|
||||
|
||||
public override int Load (string str)
|
||||
{
|
||||
return int.Parse (str, System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
|
||||
public class FloatInput : Input<float>
|
||||
{
|
||||
public float minValue;
|
||||
|
|
Loading…
Add table
Reference in a new issue