-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModelSelectionWindow.xaml.cs
More file actions
116 lines (103 loc) · 3.7 KB
/
ModelSelectionWindow.xaml.cs
File metadata and controls
116 lines (103 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace Sm64DecompLevelViewer
{
public class ModelItem
{
public string Name { get; set; }
public bool IsSupported { get; set; }
public string Color => IsSupported ? "#4EC9B0" : "#F44747";
}
public partial class ModelSelectionWindow : Window
{
private List<string> _allModels = new List<string>();
private List<string> _supportedModels;
public string? SelectedModel { get; private set; }
public ModelSelectionWindow(string projectRoot, List<string> supportedModels)
{
InitializeComponent();
_supportedModels = supportedModels;
LoadModels(projectRoot);
FilterModels("");
}
private void LoadModels(string projectRoot)
{
try
{
// Common locations for model_ids.h
var paths = new[]
{
Path.Combine(projectRoot, "include", "model_ids.h"),
Path.Combine(projectRoot, "howtomake", "include", "model_ids.h"),
Path.Combine(projectRoot, "leveleditor", "include", "model_ids.h")
};
foreach (var path in paths)
{
if (File.Exists(path))
{
var content = File.ReadAllText(path);
var matches = Regex.Matches(content, @"#define\s+(MODEL_[A-Z0-9_]+)");
foreach (Match m in matches)
{
string model = m.Groups[1].Value;
if (!_allModels.Contains(model))
_allModels.Add(model);
}
}
}
if (_allModels.Count == 0)
{
// Fallback defaults if no file found
_allModels.Add("MODEL_NONE");
_allModels.Add("MODEL_MARIO");
_allModels.Add("MODEL_GOOMBA");
_allModels.Add("MODEL_BOBOMB");
}
_allModels.Sort();
}
catch (Exception ex)
{
MessageBox.Show($"Error loading model IDs: {ex.Message}");
}
}
private void FilterModels(string search)
{
var filtered = string.IsNullOrWhiteSpace(search)
? _allModels
: _allModels.Where(m => m.Contains(search, StringComparison.OrdinalIgnoreCase));
ModelListBox.ItemsSource = filtered.Select(m => new ModelItem
{
Name = m,
IsSupported = _supportedModels.Contains(m, StringComparer.OrdinalIgnoreCase)
}).ToList();
}
private void SearchTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
FilterModels(SearchTextBox.Text);
}
private void SelectButton_Click(object sender, RoutedEventArgs e)
{
if (ModelListBox.SelectedItem is ModelItem item)
{
SelectedModel = item.Name;
DialogResult = true;
Close();
}
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
Close();
}
private void ModelListBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
SelectButton_Click(sender, e);
}
}
}