-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectAddWindow.xaml.cs
More file actions
115 lines (99 loc) · 4.12 KB
/
ObjectAddWindow.xaml.cs
File metadata and controls
115 lines (99 loc) · 4.12 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
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using Sm64DecompLevelViewer.Models;
namespace Sm64DecompLevelViewer
{
public partial class ObjectAddWindow : Window
{
public LevelObject? NewObject { get; private set; }
private string _projectRoot;
private int _initialX, _initialY, _initialZ;
private List<string> _supportedModels;
public ObjectAddWindow(string projectRoot, List<string> behaviors, List<string> macroPresets, List<string> specialPresets, List<string> supportedModels, int x = 0, int y = 0, int z = 0)
{
InitializeComponent();
_projectRoot = projectRoot;
_supportedModels = supportedModels;
_initialX = x;
_initialY = y;
_initialZ = z;
BehaviorListBox.ItemsSource = behaviors;
MacroListBox.ItemsSource = macroPresets;
SpecialListBox.ItemsSource = specialPresets;
// Default values
NormalModelTextBox.Text = "MODEL_NONE";
ValidateModel(NormalModelTextBox.Text);
}
private void NormalModelTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
ValidateModel(NormalModelTextBox.Text);
}
private void ValidateModel(string modelName)
{
if (UnsupportedModelWarning == null || BuildRequiredWarning == null) return;
// Handle missing actors folder state
if (_supportedModels.Contains("MISSING_ACTORS_FOLDER"))
{
BuildRequiredWarning.Visibility = Visibility.Visible;
UnsupportedModelWarning.Visibility = Visibility.Collapsed;
return;
}
BuildRequiredWarning.Visibility = Visibility.Collapsed;
if (string.IsNullOrWhiteSpace(modelName) || modelName == "MODEL_NONE")
{
UnsupportedModelWarning.Visibility = Visibility.Collapsed;
return;
}
bool isSupported = _supportedModels.Contains(modelName, StringComparer.OrdinalIgnoreCase);
UnsupportedModelWarning.Visibility = isSupported ? Visibility.Collapsed : Visibility.Visible;
}
private void SelectModelButton_Click(object sender, RoutedEventArgs e)
{
var dialog = new ModelSelectionWindow(_projectRoot, _supportedModels);
dialog.Owner = this;
if (dialog.ShowDialog() == true)
{
NormalModelTextBox.Text = dialog.SelectedModel ?? "MODEL_NONE";
}
}
private void AddButton_Click(object sender, RoutedEventArgs e)
{
var selectedTab = ((TabItem)MainTabControl.SelectedItem).Header.ToString();
NewObject = new LevelObject
{
X = _initialX, Y = _initialY, Z = _initialZ,
RX = 0, RY = 0, RZ = 0,
Params = 0,
IsNew = true
};
if (selectedTab == "Normal")
{
NewObject.ModelName = NormalModelTextBox.Text;
NewObject.Behavior = BehaviorListBox.SelectedItem?.ToString() ?? "bhvStaticObject";
NewObject.SourceType = ObjectSourceType.Normal;
}
else if (selectedTab == "Macro")
{
NewObject.ModelName = MacroListBox.SelectedItem?.ToString() ?? "macro_goomba_triplet_formation";
NewObject.Behavior = "(Macro Preset)";
NewObject.SourceType = ObjectSourceType.Macro;
}
else if (selectedTab == "Special")
{
NewObject.ModelName = SpecialListBox.SelectedItem?.ToString() ?? "special_empty_room_0";
NewObject.Behavior = "(Special Object)";
NewObject.SourceType = ObjectSourceType.Special;
}
DialogResult = true;
Close();
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
Close();
}
}
}