Star favourite sceneries in the list

A right click stars or unstars the scenery under it; the starred ones are
gathered in a group on top and marked where they belong. They are kept in
favorites.txt beside the settings, not in eu07.ini.
This commit is contained in:
maj00r
2026-10-04 14:23:16 +02:00
parent be34d48033
commit e0901ae0ab
13 changed files with 223 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
@@ -71,8 +72,9 @@ public partial class Scenarios : UserControl
bool includeArchival = archivalSwitch.IsChecked != true;
bool expandGroups = AppServices.Current.Settings.AutoExpandSceneryTree;
var favorites = AppServices.Current.Favorites;
var nodes = new SceneryTreeBuilder(AppServices.Current.SceneryTexts)
.Build(Sceneries, includeArchival, App.Loc.CurrentLangCode);
.Build(Sceneries, includeArchival, App.Loc.CurrentLangCode, favorites.Contains, App.Loc["Favorites"]);
foreach (var node in nodes)
sceneryList.Items.Add(ToTreeItem(node, expandGroups));
@@ -93,6 +95,42 @@ public partial class Scenarios : UserControl
return item;
}
private Scenery? SelectedScenery =>
sceneryList.SelectedItem is TreeViewItem { Tag: int index } && index < Sceneries.Count
? Sceneries[index]
: null;
// A right click picks the scenery under it, so the menu speaks of that one.
private void SceneryList_OnContextRequested(object? sender, ContextRequestedEventArgs e)
{
var hit = e.Source as Control;
while (hit is not null and not TreeViewItem)
hit = hit.Parent as Control;
if (hit is TreeViewItem { Tag: int } item)
sceneryList.SelectedItem = item;
}
private void SceneryMenu_OnOpening(object? sender, CancelEventArgs e)
{
var scenery = SelectedScenery;
favoriteMenuItem.IsEnabled = scenery is not null;
favoriteMenuItem.Header = App.Loc[scenery is not null && AppServices.Current.Favorites.Contains(scenery)
? "FavoriteRemove"
: "FavoriteAdd"];
}
private void ToggleFavorite_OnClick(object? sender, RoutedEventArgs e)
{
if (SelectedScenery is not { } scenery)
return;
AppServices.Current.Favorites.Toggle(scenery);
BuildSceneryTree();
AppServices.Current.Settings.LastScenery = Path.GetFileNameWithoutExtension(scenery.Path);
RestoreLastScenery();
}
private void RestoreLastScenery()
{
string last = AppServices.Current.Settings.LastScenery;