Implement too many changes to list
This commit is contained in:
@@ -16,52 +16,52 @@ namespace KernelPanic.UI
|
||||
{
|
||||
private const int StarterCount = 3;
|
||||
|
||||
private readonly List<VisualElement> cards = new();
|
||||
private readonly List<Label> names = new();
|
||||
private readonly List<Label> languages = new();
|
||||
private readonly List<Label> descriptions = new();
|
||||
private readonly List<VisualElement> _cards = new();
|
||||
private readonly List<Label> _names = new();
|
||||
private readonly List<Label> _languages = new();
|
||||
private readonly List<Label> _descriptions = new();
|
||||
|
||||
private VisualElement root;
|
||||
private VisualElement modal;
|
||||
private VisualElement options;
|
||||
private Label confirmLabel;
|
||||
private Label errorLabel;
|
||||
private DistroDatabase database;
|
||||
private Action<DistroDefinition, IReadOnlyList<DistroDefinition>> onConfirmed;
|
||||
private VisualElement _root;
|
||||
private VisualElement _modal;
|
||||
private VisualElement _options;
|
||||
private Label _confirmLabel;
|
||||
private Label _errorLabel;
|
||||
private DistroDatabase _database;
|
||||
private Action<DistroDefinition, IReadOnlyList<DistroDefinition>> _onConfirmed;
|
||||
|
||||
private IReadOnlyList<DistroDefinition> activeStarters = Array.Empty<DistroDefinition>();
|
||||
private int selectedIndex;
|
||||
private bool active;
|
||||
private bool showingError;
|
||||
private bool confirming;
|
||||
private IVisualElementScheduledItem closeSchedule;
|
||||
private IReadOnlyList<DistroDefinition> _activeStarters = Array.Empty<DistroDefinition>();
|
||||
private int _selectedIndex;
|
||||
private bool _active;
|
||||
private bool _showingError;
|
||||
private bool _confirming;
|
||||
private IVisualElementScheduledItem _closeSchedule;
|
||||
|
||||
public bool IsActive => active;
|
||||
public bool IsActive => _active;
|
||||
|
||||
public void Bind(VisualElement documentRoot, DistroDatabase distroDatabase, Action<DistroDefinition, IReadOnlyList<DistroDefinition>> onStarterConfirmed)
|
||||
{
|
||||
root = documentRoot;
|
||||
database = distroDatabase;
|
||||
onConfirmed = onStarterConfirmed;
|
||||
_root = documentRoot;
|
||||
_database = distroDatabase;
|
||||
_onConfirmed = onStarterConfirmed;
|
||||
|
||||
modal = root.Q<VisualElement>("StarterModal");
|
||||
options = root.Q<VisualElement>("StarterOptions");
|
||||
confirmLabel = root.Q<Label>("StarterConfirmLabel");
|
||||
errorLabel = root.Q<Label>("StarterErrorLabel");
|
||||
_modal = _root.Q<VisualElement>("StarterModal");
|
||||
_options = _root.Q<VisualElement>("StarterOptions");
|
||||
_confirmLabel = _root.Q<Label>("StarterConfirmLabel");
|
||||
_errorLabel = _root.Q<Label>("StarterErrorLabel");
|
||||
|
||||
for (int i = 0; i < StarterCount; i++)
|
||||
{
|
||||
cards.Add(root.Q<VisualElement>($"StarterOption{i}"));
|
||||
names.Add(root.Q<Label>($"StarterName{i}"));
|
||||
languages.Add(root.Q<Label>($"StarterLanguages{i}"));
|
||||
descriptions.Add(root.Q<Label>($"StarterDescription{i}"));
|
||||
_cards.Add(_root.Q<VisualElement>($"StarterOption{i}"));
|
||||
_names.Add(_root.Q<Label>($"StarterName{i}"));
|
||||
_languages.Add(_root.Q<Label>($"StarterLanguages{i}"));
|
||||
_descriptions.Add(_root.Q<Label>($"StarterDescription{i}"));
|
||||
}
|
||||
|
||||
for (int i = 0; i < cards.Count; i++)
|
||||
for (int i = 0; i < _cards.Count; i++)
|
||||
{
|
||||
int index = i;
|
||||
cards[i].RegisterCallback<PointerEnterEvent>(_ => Select(index));
|
||||
cards[i].RegisterCallback<ClickEvent>(_ =>
|
||||
_cards[i].RegisterCallback<PointerEnterEvent>(_ => Select(index));
|
||||
_cards[i].RegisterCallback<ClickEvent>(_ =>
|
||||
{
|
||||
Select(index);
|
||||
ConfirmIntent();
|
||||
@@ -83,31 +83,31 @@ namespace KernelPanic.UI
|
||||
return;
|
||||
}
|
||||
|
||||
activeStarters = starters;
|
||||
active = true;
|
||||
showingError = false;
|
||||
confirming = false;
|
||||
errorLabel.AddToClassList("hidden");
|
||||
options.RemoveFromClassList("hidden");
|
||||
confirmLabel.AddToClassList("hidden");
|
||||
modal.RemoveFromClassList("hidden");
|
||||
_activeStarters = starters;
|
||||
_active = true;
|
||||
_showingError = false;
|
||||
_confirming = false;
|
||||
_errorLabel.AddToClassList("hidden");
|
||||
_options.RemoveFromClassList("hidden");
|
||||
_confirmLabel.AddToClassList("hidden");
|
||||
_modal.RemoveFromClassList("hidden");
|
||||
|
||||
for (int i = 0; i < cards.Count; i++)
|
||||
for (int i = 0; i < _cards.Count; i++)
|
||||
{
|
||||
DistroDefinition unit = starters[i];
|
||||
names[i].text = DistroPresentation.DisplayName(unit);
|
||||
names[i].style.color = new StyleColor(unit.AccentColor);
|
||||
languages[i].text = DistroPresentation.FormatLanguages(unit);
|
||||
descriptions[i].text = unit.Description;
|
||||
_names[i].text = DistroPresentation.DisplayName(unit);
|
||||
_names[i].style.color = new StyleColor(unit.AccentColor);
|
||||
_languages[i].text = DistroPresentation.FormatLanguages(unit);
|
||||
_descriptions[i].text = unit.Description;
|
||||
}
|
||||
|
||||
Select(0);
|
||||
root.Focus();
|
||||
_root.Focus();
|
||||
}
|
||||
|
||||
public void HandleKeyDown(KeyDownEvent evt)
|
||||
{
|
||||
if (showingError)
|
||||
if (_showingError)
|
||||
{
|
||||
if (evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter ||
|
||||
evt.keyCode == KeyCode.Escape || evt.keyCode == KeyCode.Space)
|
||||
@@ -120,13 +120,13 @@ namespace KernelPanic.UI
|
||||
|
||||
if (evt.keyCode == KeyCode.LeftArrow)
|
||||
{
|
||||
Select(selectedIndex - 1);
|
||||
Select(_selectedIndex - 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (evt.keyCode == KeyCode.RightArrow)
|
||||
{
|
||||
Select(selectedIndex + 1);
|
||||
Select(_selectedIndex + 1);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace KernelPanic.UI
|
||||
|
||||
if (evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter)
|
||||
{
|
||||
if (confirming)
|
||||
if (_confirming)
|
||||
{
|
||||
Confirm();
|
||||
return;
|
||||
@@ -149,7 +149,7 @@ namespace KernelPanic.UI
|
||||
return;
|
||||
}
|
||||
|
||||
if (evt.keyCode == KeyCode.Y && confirming)
|
||||
if (evt.keyCode == KeyCode.Y && _confirming)
|
||||
{
|
||||
Confirm();
|
||||
return;
|
||||
@@ -157,32 +157,32 @@ namespace KernelPanic.UI
|
||||
|
||||
if (evt.keyCode == KeyCode.Escape || evt.keyCode == KeyCode.N)
|
||||
{
|
||||
confirming = false;
|
||||
confirmLabel.AddToClassList("hidden");
|
||||
_confirming = false;
|
||||
_confirmLabel.AddToClassList("hidden");
|
||||
}
|
||||
}
|
||||
|
||||
public void PauseSchedules()
|
||||
{
|
||||
closeSchedule?.Pause();
|
||||
_closeSchedule?.Pause();
|
||||
}
|
||||
|
||||
private bool TryGetStarters(out IReadOnlyList<DistroDefinition> starters, out string error)
|
||||
{
|
||||
if (database == null)
|
||||
if (_database == null)
|
||||
{
|
||||
starters = Array.Empty<DistroDefinition>();
|
||||
error = "no DistroDatabase is assigned";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!database.TryValidate(out error))
|
||||
if (!_database.TryValidate(out error))
|
||||
{
|
||||
starters = Array.Empty<DistroDefinition>();
|
||||
return false;
|
||||
}
|
||||
|
||||
IReadOnlyList<DistroDefinition> allDistros = database.AllDistros;
|
||||
IReadOnlyList<DistroDefinition> allDistros = _database.AllDistros;
|
||||
if (allDistros.Count < StarterCount)
|
||||
{
|
||||
starters = Array.Empty<DistroDefinition>();
|
||||
@@ -197,103 +197,103 @@ namespace KernelPanic.UI
|
||||
|
||||
private void ShowConfigError(string error)
|
||||
{
|
||||
active = true;
|
||||
showingError = true;
|
||||
confirming = false;
|
||||
options.AddToClassList("hidden");
|
||||
confirmLabel.AddToClassList("hidden");
|
||||
errorLabel.text = $"starter selection unavailable: {error}. press enter to continue.";
|
||||
errorLabel.RemoveFromClassList("hidden");
|
||||
modal.RemoveFromClassList("hidden");
|
||||
root.Focus();
|
||||
_active = true;
|
||||
_showingError = true;
|
||||
_confirming = false;
|
||||
_options.AddToClassList("hidden");
|
||||
_confirmLabel.AddToClassList("hidden");
|
||||
_errorLabel.text = $"starter selection unavailable: {error}. press enter to continue.";
|
||||
_errorLabel.RemoveFromClassList("hidden");
|
||||
_modal.RemoveFromClassList("hidden");
|
||||
_root.Focus();
|
||||
}
|
||||
|
||||
private void Select(int index)
|
||||
{
|
||||
if (activeStarters.Count == 0)
|
||||
if (_activeStarters.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int slotCount = Mathf.Min(activeStarters.Count, cards.Count);
|
||||
selectedIndex = (index + slotCount) % slotCount;
|
||||
confirming = false;
|
||||
confirmLabel.AddToClassList("hidden");
|
||||
int slotCount = Mathf.Min(_activeStarters.Count, _cards.Count);
|
||||
_selectedIndex = (index + slotCount) % slotCount;
|
||||
_confirming = false;
|
||||
_confirmLabel.AddToClassList("hidden");
|
||||
|
||||
for (int i = 0; i < cards.Count; i++)
|
||||
for (int i = 0; i < _cards.Count; i++)
|
||||
{
|
||||
bool selected = i == selectedIndex;
|
||||
cards[i].EnableInClassList("selected", selected);
|
||||
if (i < activeStarters.Count && selected)
|
||||
bool selected = i == _selectedIndex;
|
||||
_cards[i].EnableInClassList("selected", selected);
|
||||
if (i < _activeStarters.Count && selected)
|
||||
{
|
||||
StyleColor accent = new(activeStarters[i].AccentColor);
|
||||
cards[i].style.borderTopColor = accent;
|
||||
cards[i].style.borderRightColor = accent;
|
||||
cards[i].style.borderBottomColor = accent;
|
||||
cards[i].style.borderLeftColor = accent;
|
||||
StyleColor accent = new(_activeStarters[i].AccentColor);
|
||||
_cards[i].style.borderTopColor = accent;
|
||||
_cards[i].style.borderRightColor = accent;
|
||||
_cards[i].style.borderBottomColor = accent;
|
||||
_cards[i].style.borderLeftColor = accent;
|
||||
}
|
||||
else
|
||||
{
|
||||
cards[i].style.borderTopColor = StyleKeyword.Null;
|
||||
cards[i].style.borderRightColor = StyleKeyword.Null;
|
||||
cards[i].style.borderBottomColor = StyleKeyword.Null;
|
||||
cards[i].style.borderLeftColor = StyleKeyword.Null;
|
||||
_cards[i].style.borderTopColor = StyleKeyword.Null;
|
||||
_cards[i].style.borderRightColor = StyleKeyword.Null;
|
||||
_cards[i].style.borderBottomColor = StyleKeyword.Null;
|
||||
_cards[i].style.borderLeftColor = StyleKeyword.Null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ConfirmIntent()
|
||||
{
|
||||
if (selectedIndex >= activeStarters.Count)
|
||||
if (_selectedIndex >= _activeStarters.Count)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
confirming = true;
|
||||
confirmLabel.text = $"install {DistroPresentation.DisplayName(activeStarters[selectedIndex])}? this cannot be undone [Y/n]";
|
||||
confirmLabel.RemoveFromClassList("hidden");
|
||||
_confirming = true;
|
||||
_confirmLabel.text = $"install {DistroPresentation.DisplayName(_activeStarters[_selectedIndex])}? this cannot be undone [Y/n]";
|
||||
_confirmLabel.RemoveFromClassList("hidden");
|
||||
}
|
||||
|
||||
private void Confirm()
|
||||
{
|
||||
if (selectedIndex >= activeStarters.Count)
|
||||
if (_selectedIndex >= _activeStarters.Count)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DistroDefinition picked = activeStarters[selectedIndex];
|
||||
DistroDefinition picked = _activeStarters[_selectedIndex];
|
||||
List<DistroDefinition> remaining = new();
|
||||
for (int i = 0; i < activeStarters.Count; i++)
|
||||
for (int i = 0; i < _activeStarters.Count; i++)
|
||||
{
|
||||
if (i != selectedIndex)
|
||||
if (i != _selectedIndex)
|
||||
{
|
||||
remaining.Add(activeStarters[i]);
|
||||
remaining.Add(_activeStarters[i]);
|
||||
}
|
||||
}
|
||||
|
||||
onConfirmed?.Invoke(picked, remaining);
|
||||
_onConfirmed?.Invoke(picked, remaining);
|
||||
|
||||
confirmLabel.text = $"installing {picked.Id} (1/1)... done";
|
||||
confirmLabel.RemoveFromClassList("hidden");
|
||||
_confirmLabel.text = $"installing {picked.Id} (1/1)... done";
|
||||
_confirmLabel.RemoveFromClassList("hidden");
|
||||
if (UIPreferences.ReducedMotion)
|
||||
{
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
closeSchedule?.Pause();
|
||||
closeSchedule = root.schedule.Execute(Close).StartingIn(600);
|
||||
_closeSchedule?.Pause();
|
||||
_closeSchedule = _root.schedule.Execute(Close).StartingIn(600);
|
||||
}
|
||||
|
||||
private void Close()
|
||||
{
|
||||
closeSchedule?.Pause();
|
||||
closeSchedule = null;
|
||||
active = false;
|
||||
confirming = false;
|
||||
showingError = false;
|
||||
modal.AddToClassList("hidden");
|
||||
root.Focus();
|
||||
_closeSchedule?.Pause();
|
||||
_closeSchedule = null;
|
||||
_active = false;
|
||||
_confirming = false;
|
||||
_showingError = false;
|
||||
_modal.AddToClassList("hidden");
|
||||
_root.Focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user