diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index 492b5f6c4..04593aefe 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -568,10 +568,20 @@ + + + + + + + LuaWindowView.xaml + + + @@ -935,6 +945,10 @@ MSBuild:Compile Designer + + Designer + MSBuild:Compile + MSBuild:Compile Designer diff --git a/Artemis/Artemis/InjectionModules/BaseModules.cs b/Artemis/Artemis/InjectionModules/BaseModules.cs index 7018eef22..3cf6d05be 100644 --- a/Artemis/Artemis/InjectionModules/BaseModules.cs +++ b/Artemis/Artemis/InjectionModules/BaseModules.cs @@ -6,6 +6,7 @@ using Artemis.Profiles.Layers.Abstract; using Artemis.Profiles.Layers.Interfaces; using Artemis.Profiles.Layers.Types.Audio.AudioCapturing; using Artemis.Profiles.Lua; +using Artemis.Profiles.Lua.Modules.Gui; using Artemis.Services; using Artemis.Utilities.DataReaders; using Artemis.Utilities.GameState; @@ -116,6 +117,8 @@ namespace Artemis.InjectionModules .InheritedFrom() .BindAllBaseClasses()); + Bind().ToSelf(); + #endregion } } diff --git a/Artemis/Artemis/Models/ProfileEditorModel.cs b/Artemis/Artemis/Models/ProfileEditorModel.cs index cb9af3a15..093393770 100644 --- a/Artemis/Artemis/Models/ProfileEditorModel.cs +++ b/Artemis/Artemis/Models/ProfileEditorModel.cs @@ -50,7 +50,7 @@ namespace Artemis.Models new ConstructorArgument("dataModel", dataModel), new ConstructorArgument("layer", layer) }; - _windowService.ShowDialog("Artemis | Edit layer", args); + _windowService.ShowDialog("Artemis | Edit layer", null, args); // If the layer was a folder, but isn't anymore, assign it's children to it's parent. if (layer.LayerType is FolderType || !layer.Children.Any()) diff --git a/Artemis/Artemis/Profiles/Lua/Modules/Gui/LuaButton.cs b/Artemis/Artemis/Profiles/Lua/Modules/Gui/LuaButton.cs new file mode 100644 index 000000000..8cbbbcb92 --- /dev/null +++ b/Artemis/Artemis/Profiles/Lua/Modules/Gui/LuaButton.cs @@ -0,0 +1,49 @@ +using System; +using System.Windows; +using System.Windows.Controls; +using Artemis.Managers; +using MoonSharp.Interpreter; +using MoonSharp.Interpreter.Interop; + +namespace Artemis.Profiles.Lua.Modules.Gui +{ + [MoonSharpUserData] + public class LuaButton + { + private readonly LuaManager _luaManager; + + public LuaButton(LuaManager luaManager, string text, double x, double y, double? width, double? height) + { + _luaManager = luaManager; + + Button = new Button {Content = text}; + if (width != null) + Button.Width = width.Value; + if (height != null) + Button.Height = height.Value; + + Button.Click += ButtonOnClick; + } + + [MoonSharpVisible(false)] + public Button Button { get; } + + public string Text + { + get => Button.Dispatcher.Invoke(() => (string) Button.Content); + set => Button.Dispatcher.Invoke(() => Button.Content = value); + } + + private void ButtonOnClick(object sender, RoutedEventArgs routedEventArgs) + { + _luaManager.EventsModule.LuaInvoke(_luaManager.ProfileModel, () => OnClick(this)); + } + + public event EventHandler Click; + + protected virtual void OnClick(LuaButton button) + { + Click?.Invoke(button, null); + } + } +} diff --git a/Artemis/Artemis/Profiles/Lua/Modules/Gui/LuaCheckBox.cs b/Artemis/Artemis/Profiles/Lua/Modules/Gui/LuaCheckBox.cs new file mode 100644 index 000000000..825fe0ca1 --- /dev/null +++ b/Artemis/Artemis/Profiles/Lua/Modules/Gui/LuaCheckBox.cs @@ -0,0 +1,55 @@ +using System; +using System.Windows; +using System.Windows.Controls; +using Artemis.Managers; +using MoonSharp.Interpreter; +using MoonSharp.Interpreter.Interop; + +namespace Artemis.Profiles.Lua.Modules.Gui +{ + [MoonSharpUserData] + public class LuaCheckBox + { + private readonly LuaManager _luaManager; + + public LuaCheckBox(LuaManager luaManager, string text, bool isChecked, double x, double y, double? width, double? height) + { + _luaManager = luaManager; + + CheckBox = new CheckBox {Content = text, IsChecked = isChecked}; + if (width != null) + CheckBox.Width = width.Value; + if (height != null) + CheckBox.Height = height.Value; + + CheckBox.Click += CheckBoxOnClick; + } + + [MoonSharpVisible(false)] + public CheckBox CheckBox { get; } + + public string Text + { + get => CheckBox.Dispatcher.Invoke(() => (string) CheckBox.Content); + set => CheckBox.Dispatcher.Invoke(() => CheckBox.Content = value); + } + + public bool IsChecked + { + get => CheckBox.Dispatcher.Invoke(() => CheckBox.IsChecked != null && (bool) CheckBox.IsChecked); + set => CheckBox.Dispatcher.Invoke(() => CheckBox.IsChecked = value); + } + + private void CheckBoxOnClick(object sender, RoutedEventArgs routedEventArgs) + { + _luaManager.EventsModule.LuaInvoke(_luaManager.ProfileModel, () => OnClick(this)); + } + + public event EventHandler Click; + + protected virtual void OnClick(LuaCheckBox checkBox) + { + Click?.Invoke(checkBox, null); + } + } +} diff --git a/Artemis/Artemis/Profiles/Lua/Modules/Gui/LuaComboBox.cs b/Artemis/Artemis/Profiles/Lua/Modules/Gui/LuaComboBox.cs new file mode 100644 index 000000000..bb67d84eb --- /dev/null +++ b/Artemis/Artemis/Profiles/Lua/Modules/Gui/LuaComboBox.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Windows.Controls; +using Artemis.Managers; +using MoonSharp.Interpreter; +using MoonSharp.Interpreter.Interop; + +namespace Artemis.Profiles.Lua.Modules.Gui +{ + [MoonSharpUserData] + public class LuaComboBox + { + private readonly LuaManager _luaManager; + + public LuaComboBox(LuaManager luaManager, string value, List values, double x, double y, double? width, double? height) + { + _luaManager = luaManager; + + ComboBox = new ComboBox {ItemsSource = new ObservableCollection(values), SelectedItem = value}; + if (width != null) + ComboBox.Width = (double) width; + if (height != null) + ComboBox.Height = (double) height; + + ComboBox.SelectionChanged += ComboBoxOnSelectionChanged; + } + + [MoonSharpVisible(false)] + public ComboBox ComboBox { get; } + + public string Value + { + get => ComboBox.Dispatcher.Invoke(() => (string) ComboBox.SelectedItem); + set => ComboBox.Dispatcher.Invoke(() => ComboBox.SelectedItem = value); + } + + public void SetValues(string[] values) + { + var collection = (ObservableCollection) ComboBox.ItemsSource; + collection.Clear(); + foreach (var value in values) + collection.Add(value); + } + + public void AddValue(string value) + { + ((ObservableCollection) ComboBox.ItemsSource).Add(value); + } + + public void RemoveValue(string value) + { + var collection = (ObservableCollection) ComboBox.ItemsSource; + if (collection.Contains(value)) + collection.Remove(value); + } + + private void ComboBoxOnSelectionChanged(object sender, SelectionChangedEventArgs selectionChangedEventArgs) + { + _luaManager.EventsModule.LuaInvoke(_luaManager.ProfileModel, () => OnSelectionChanged(this)); + } + + public event EventHandler SelectionChanged; + + protected virtual void OnSelectionChanged(LuaComboBox comboBox) + { + SelectionChanged?.Invoke(comboBox, null); + } + } +} diff --git a/Artemis/Artemis/Profiles/Lua/Modules/Gui/LuaLabel.cs b/Artemis/Artemis/Profiles/Lua/Modules/Gui/LuaLabel.cs new file mode 100644 index 000000000..fa10a4cc2 --- /dev/null +++ b/Artemis/Artemis/Profiles/Lua/Modules/Gui/LuaLabel.cs @@ -0,0 +1,30 @@ +using System.Windows; +using System.Windows.Controls; +using MoonSharp.Interpreter; +using MoonSharp.Interpreter.Interop; + +namespace Artemis.Profiles.Lua.Modules.Gui +{ + [MoonSharpUserData] + public class LuaLabel + { + public LuaLabel(string text, double x, double y, double fontSize = 12, int fontWeight = 400) + { + Label = new Label + { + Content = text, + FontSize = fontSize, + FontWeight = FontWeight.FromOpenTypeWeight(fontWeight) + }; + } + + [MoonSharpVisible(false)] + public Label Label { get; } + + public string Text + { + get => Label.Dispatcher.Invoke(() => (string) Label.Content); + set => Label.Dispatcher.Invoke(() => Label.Content = value); + } + } +} diff --git a/Artemis/Artemis/Profiles/Lua/Modules/Gui/LuaTextBox.cs b/Artemis/Artemis/Profiles/Lua/Modules/Gui/LuaTextBox.cs new file mode 100644 index 000000000..13376adf8 --- /dev/null +++ b/Artemis/Artemis/Profiles/Lua/Modules/Gui/LuaTextBox.cs @@ -0,0 +1,48 @@ +using System; +using System.Windows.Controls; +using Artemis.Managers; +using MoonSharp.Interpreter; +using MoonSharp.Interpreter.Interop; + +namespace Artemis.Profiles.Lua.Modules.Gui +{ + [MoonSharpUserData] + public class LuaTextBox + { + private readonly LuaManager _luaManager; + + public LuaTextBox(LuaManager luaManager, string text, double x, double y, double? width, double? height) + { + _luaManager = luaManager; + + TextBox = new TextBox {Text = text}; + if (width != null) + TextBox.Width = width.Value; + if (height != null) + TextBox.Height = height.Value; + + TextBox.TextChanged += TextBoxOnTextChanged; + } + + [MoonSharpVisible(false)] + public TextBox TextBox { get; } + + public string Text + { + get => TextBox.Dispatcher.Invoke(() => TextBox.Text); + set => TextBox.Dispatcher.Invoke(() => TextBox.Text = value); + } + + private void TextBoxOnTextChanged(object sender, TextChangedEventArgs textChangedEventArgs) + { + _luaManager.EventsModule.LuaInvoke(_luaManager.ProfileModel, () => OnTextChanged(this)); + } + + public event EventHandler TextChanged; + + protected virtual void OnTextChanged(LuaTextBox button) + { + TextChanged?.Invoke(button, null); + } + } +} diff --git a/Artemis/Artemis/Profiles/Lua/Modules/Gui/LuaWindowView.xaml b/Artemis/Artemis/Profiles/Lua/Modules/Gui/LuaWindowView.xaml new file mode 100644 index 000000000..849d91643 --- /dev/null +++ b/Artemis/Artemis/Profiles/Lua/Modules/Gui/LuaWindowView.xaml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Lua/Modules/Gui/LuaWindowView.xaml.cs b/Artemis/Artemis/Profiles/Lua/Modules/Gui/LuaWindowView.xaml.cs new file mode 100644 index 000000000..c10b953ac --- /dev/null +++ b/Artemis/Artemis/Profiles/Lua/Modules/Gui/LuaWindowView.xaml.cs @@ -0,0 +1,15 @@ +using MahApps.Metro.Controls; + +namespace Artemis.Profiles.Lua.Modules.Gui +{ + /// + /// Interaction logic for LuaWindowView.xaml + /// + public partial class LuaWindowView : MetroWindow + { + public LuaWindowView() + { + InitializeComponent(); + } + } +} diff --git a/Artemis/Artemis/Profiles/Lua/Modules/Gui/LuaWindowViewModel.cs b/Artemis/Artemis/Profiles/Lua/Modules/Gui/LuaWindowViewModel.cs new file mode 100644 index 000000000..5c927cdb1 --- /dev/null +++ b/Artemis/Artemis/Profiles/Lua/Modules/Gui/LuaWindowViewModel.cs @@ -0,0 +1,93 @@ +using System.Collections.Generic; +using System.Windows; +using System.Windows.Controls; +using Artemis.Managers; +using Caliburn.Micro; +using MoonSharp.Interpreter; + +namespace Artemis.Profiles.Lua.Modules.Gui +{ + [MoonSharpUserData] + public class LuaWindowViewModel : Screen + { + private readonly LuaManager _luaManager; + + public LuaWindowViewModel(LuaManager luaManager) + { + _luaManager = luaManager; + + Canvas = new Canvas(); + Content = new List {Canvas}; + } + + public Canvas Canvas { get; set; } + public List Content { get; set; } + + public LuaLabel CreateLabel(string text, double x, double y, double fontSize = 12, int fontWeight = 400) + { + LuaLabel element = null; + Execute.OnUIThread(() => + { + element = new LuaLabel(text, x, y, fontSize, fontWeight); + AddControl(element.Label, x, y); + }); + + return element; + } + + public LuaButton CreateButton(string text, double x, double y, double? width, double? height) + { + LuaButton element = null; + Execute.OnUIThread(() => + { + element = new LuaButton(_luaManager, text, x, y, width, height); + AddControl(element.Button, x, y); + }); + + return element; + } + + public LuaTextBox CreateTextBox(string text, double x, double y, double? width, double? height) + { + LuaTextBox element = null; + Execute.OnUIThread(() => + { + element = new LuaTextBox(_luaManager, text, x, y, width, height); + AddControl(element.TextBox, x, y); + }); + + return element; + } + + public LuaComboBox CreateComboBox(string value, List values, double x, double y, double? width, double? height) + { + LuaComboBox element = null; + Execute.OnUIThread(() => + { + element = new LuaComboBox(_luaManager, value, values, x, y, width, height); + AddControl(element.ComboBox, x, y); + }); + + return element; + } + + public LuaCheckBox CreateCheckBox(string text, bool isChecked, double x, double y, double? width, double? height) + { + LuaCheckBox element = null; + Execute.OnUIThread(() => + { + element = new LuaCheckBox(_luaManager, text, isChecked, x, y, width, height); + AddControl(element.CheckBox, x, y); + }); + + return element; + } + + private void AddControl(UIElement uiElement, double x, double y) + { + Canvas.Children.Add(uiElement); + Canvas.SetLeft(uiElement, x); + Canvas.SetTop(uiElement, y); + } + } +} diff --git a/Artemis/Artemis/Profiles/Lua/Modules/LuaEventsModule.cs b/Artemis/Artemis/Profiles/Lua/Modules/LuaEventsModule.cs index 02abc90dd..41ceb2176 100644 --- a/Artemis/Artemis/Profiles/Lua/Modules/LuaEventsModule.cs +++ b/Artemis/Artemis/Profiles/Lua/Modules/LuaEventsModule.cs @@ -73,7 +73,7 @@ namespace Artemis.Profiles.Lua.Modules } } - private void LuaInvoke(ProfileModel profileModel, Action action) + public void LuaInvoke(ProfileModel profileModel, Action action) { lock (InvokeLock) { diff --git a/Artemis/Artemis/Profiles/Lua/Modules/LuaGuiModule.cs b/Artemis/Artemis/Profiles/Lua/Modules/LuaGuiModule.cs new file mode 100644 index 000000000..64b0a411a --- /dev/null +++ b/Artemis/Artemis/Profiles/Lua/Modules/LuaGuiModule.cs @@ -0,0 +1,50 @@ +using System.Collections.Generic; +using System.Dynamic; +using System.Linq; +using Artemis.Managers; +using Artemis.Profiles.Lua.Modules.Gui; +using Artemis.Services; +using Caliburn.Micro; +using MoonSharp.Interpreter; +using Ninject.Parameters; + +namespace Artemis.Profiles.Lua.Modules +{ + [MoonSharpUserData] + public class LuaGuiModule : LuaModule + { + private readonly WindowService _windowService; + private readonly List _windows; + + public LuaGuiModule(LuaManager luaManager, WindowService windowService) : base(luaManager) + { + _windowService = windowService; + _windows = new List(); + } + + public override string ModuleName => "Gui"; + + public LuaWindowViewModel CreateWindow(string title, double width, double height) + { + lock (_windows) + { + dynamic settings = new ExpandoObject(); + settings.Width = width; + settings.Height = height; + IParameter[] args = + { + new ConstructorArgument("luaManager", LuaManager) + }; + + Execute.OnUIThread(() => _windows.Add(_windowService.ShowWindow("Artemis | " + title, settings, args))); + return _windows.Last(); + } + } + + public override void Dispose() + { + foreach (var window in _windows) + window.TryClose(); + } + } +} diff --git a/Artemis/Artemis/Properties/AssemblyInfo.cs b/Artemis/Artemis/Properties/AssemblyInfo.cs index 9b302b36d..50ed559cc 100644 --- a/Artemis/Artemis/Properties/AssemblyInfo.cs +++ b/Artemis/Artemis/Properties/AssemblyInfo.cs @@ -53,7 +53,7 @@ using System.Windows; // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.9.0.1")] -[assembly: AssemblyFileVersion("1.9.0.1")] +[assembly: AssemblyVersion("1.9.0.2")] +[assembly: AssemblyFileVersion("1.9.0.2")] [assembly: InternalsVisibleTo("Artemis.Explorables")] diff --git a/Artemis/Artemis/Services/WindowService.cs b/Artemis/Artemis/Services/WindowService.cs index 4b419a1f7..60f195676 100644 --- a/Artemis/Artemis/Services/WindowService.cs +++ b/Artemis/Artemis/Services/WindowService.cs @@ -1,39 +1,41 @@ -using System.Dynamic; -using Caliburn.Micro; -using Ninject; -using Ninject.Parameters; - -namespace Artemis.Services -{ - public class WindowService - { - private readonly IKernel _kernel; - - public WindowService(IKernel kernel) - { - _kernel = kernel; - } - - public T ShowWindow(string windowName, params IParameter[] param) where T : class - { - var windowManager = new WindowManager(); +using System.Dynamic; +using Caliburn.Micro; +using Ninject; +using Ninject.Parameters; + +namespace Artemis.Services +{ + public class WindowService + { + private readonly IKernel _kernel; + + public WindowService(IKernel kernel) + { + _kernel = kernel; + } + + public T ShowWindow(string windowName, dynamic settings = null, params IParameter[] param) where T : class + { + var windowManager = new WindowManager(); var viewModel = _kernel.Get(param); - dynamic settings = new ExpandoObject(); - settings.Title = windowName; - windowManager.ShowWindow(viewModel, null, settings); - return viewModel; - } - - public T ShowDialog(string dialogName, params IParameter[] param) where T : class - { - var windowManager = new WindowManager(); - var viewModel = _kernel.Get(param); - - dynamic settings = new ExpandoObject(); - settings.Title = dialogName; - windowManager.ShowDialog(viewModel, null, settings); - return viewModel; - } - } + if (settings == null) + settings = new ExpandoObject(); + settings.Title = windowName; + windowManager.ShowWindow(viewModel, null, settings); + return viewModel; + } + + public T ShowDialog(string dialogName, dynamic settings = null, params IParameter[] param) where T : class + { + var windowManager = new WindowManager(); + var viewModel = _kernel.Get(param); + + if (settings == null) + settings = new ExpandoObject(); + settings.Title = dialogName; + windowManager.ShowDialog(viewModel, null, settings); + return viewModel; + } + } } \ No newline at end of file diff --git a/Artemis/Artemis/Styles/ColorBox.xaml b/Artemis/Artemis/Styles/ColorBox.xaml index 6c8f49fea..7431a2993 100644 --- a/Artemis/Artemis/Styles/ColorBox.xaml +++ b/Artemis/Artemis/Styles/ColorBox.xaml @@ -210,7 +210,7 @@ ItemsSource="{Binding AvailableBrushTypes, RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Center"> - +