Files

81 lines
3.8 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using UnityEngine;
using TMPro;
// НАСТРОЙКИ: звук, вибрация, уведомления, графика, частота кадров, сохранение, сброс, о игре.
public class SettingsPanel : BasePanel
{
// Ползунки не должны пересоздаваться посреди перетаскивания
protected override bool RebuildOnChange { get { return false; } }
static readonly string[] QualityNames = { "Низкое", "Среднее", "Высокое" };
protected override void Build(RectTransform root)
{
var d = GP.Data;
var list = ScrollList(root);
// --- Звук ---
var sound = UIKit.Card(list);
ProfilePanel.Header(sound, "Звук");
SliderRow(sound, "Музыка", d.musicVolume, v => { d.musicVolume = v; GP.ApplySettings(); GP.SaveSoon(); });
SliderRow(sound, "Звуки", d.soundVolume, v => { d.soundVolume = v; GP.ApplySettings(); GP.SaveSoon(); });
// --- Общие ---
var general = UIKit.Card(list);
ProfilePanel.Header(general, "Общие");
SwitchRow(general, "Вибрация", d.vibration, v => { d.vibration = v; GP.SaveSoon(); if (v) GP.Vibrate(); });
SwitchRow(general, "Уведомления", d.notifications, v => { d.notifications = v; GP.SaveSoon(); });
// --- Графика ---
var gfx = UIKit.Card(list);
ProfilePanel.Header(gfx, "Графика");
UIKit.Text(gfx, "Качество", 28, UIKit.Theme.TextDim);
UIKit.Tabs(gfx, QualityNames, d.quality, i =>
{
d.quality = i; GP.ApplySettings(); GP.SaveSoon(); RequestRebuild();
});
SwitchRow(gfx, "60 кадров/сек (больше расход батареи)", d.fps60, v => { d.fps60 = v; GP.ApplySettings(); GP.SaveSoon(); });
// --- Игра ---
var game = UIKit.Card(list);
ProfilePanel.Header(game, "Игра");
UIKit.Button(game, "Сохранить игру сейчас", UIKit.Theme.Blue, () =>
{
if (SaveManager.Instance != null) SaveManager.Instance.SaveGame();
GP.Save();
UIKit.Toast("Игра сохранена");
}, -1, 90);
UIKit.Button(game, "Сбросить весь прогресс", UIKit.Theme.Red, () =>
UIKit.Confirm("Сбросить прогресс?",
"Удалятся все здания, ресурсы, войска, герой и задания. Отменить это нельзя.",
"Сбросить", () => { GP.ResetAll(); if (UIPanelManager.Instance != null) UIPanelManager.Instance.CloseAll(); }),
-1, 90);
// --- О игре ---
var about = UIKit.Card(list);
ProfilePanel.Header(about, "О игре");
ProfilePanel.KV(about, "Версия", Application.version);
ProfilePanel.KV(about, "ID игрока", d.playerId);
UIKit.Text(about, "MVP1 • команда 4bit", 24, UIKit.Theme.TextDim, TextAlignmentOptions.Center);
}
static void SliderRow(Transform parent, string label, float value, System.Action<float> onChange)
{
var r = UIKit.Row(parent, 70, 20);
var t = UIKit.Text(r, label, 28);
UIKit.Size(t, 200);
var pct = UIKit.Text(r, Mathf.RoundToInt(value * 100) + "%", 26, UIKit.Theme.TextDim, TextAlignmentOptions.Right);
UIKit.Slider(r, value, v => { pct.text = Mathf.RoundToInt(v * 100) + "%"; onChange(v); });
pct.transform.SetAsLastSibling();
UIKit.Size(pct, 90);
}
static void SwitchRow(Transform parent, string label, bool value, System.Action<bool> onChange)
{
var r = UIKit.Row(parent, 76, 20);
var t = UIKit.Text(r, label, 28);
UIKit.Size(t, -1, -1, 1);
UIKit.Switch(r, value, onChange);
}
}