diff --git a/EZAction/EZ-Action-Icon-v1.ico b/EZAction/EZ-Action-Icon-v1.ico new file mode 100644 index 0000000..5560a74 Binary files /dev/null and b/EZAction/EZ-Action-Icon-v1.ico differ diff --git a/EZAction/EZAction.csproj b/EZAction/EZAction.csproj index bb0ee66..e0a1ad9 100644 --- a/EZAction/EZAction.csproj +++ b/EZAction/EZAction.csproj @@ -14,6 +14,7 @@ 4 true true + false publish\ true Disk @@ -25,8 +26,7 @@ false true 0 - 1.0.0.%2a - false + 0.3.0.%2a false true @@ -49,6 +49,9 @@ prompt 4 + + EZ-Action-Icon-v1.ico + @@ -133,5 +136,8 @@ false + + + \ No newline at end of file diff --git a/EZAction/MainWindow.xaml b/EZAction/MainWindow.xaml index 357281b..c5646eb 100644 --- a/EZAction/MainWindow.xaml +++ b/EZAction/MainWindow.xaml @@ -16,7 +16,7 @@ - + + - + diff --git a/EZAction/MainWindow.xaml.cs b/EZAction/MainWindow.xaml.cs index ea65611..1694dbc 100644 --- a/EZAction/MainWindow.xaml.cs +++ b/EZAction/MainWindow.xaml.cs @@ -12,11 +12,14 @@ using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; +using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +//using System.Windows.Threading; using System.Text.Json; using System.Text.Json.Serialization; +//using System.Timers; using Microsoft.Win32; namespace TestAppWPF @@ -36,12 +39,48 @@ public partial class MainWindow : Window string windowTitle_Base = "Easy Action for ArmA 3"; string openedFile = ""; + + // Animation objects + DoubleAnimation fadeOutAnim = new DoubleAnimation(); + Storyboard animPlay; + + /*---------------------------------*/ + /* Constants for the utility label */ + /*---------------------------------*/ + const string labelEmpty = ""; + const string editingMode = "Editing mode active"; + + const string actionCreated = "Action created"; + const string actionEdited = "Action edited"; + const string actionDeleted = "Action deleted"; + + const string validationError = "Action incomplete"; + const string noActionExists = "No actions exist"; + const string noActionSelected = "No action was selected"; + + const string copiedToClipboard = "Copied to clipboard"; + const string actionsWritten = "Actions written to file"; + const string writeAborted = "Action write aborted"; + const string noActionsToWrite = "No actions to write"; + const string errorWrite = "Error during writing"; + + + /*---------------------------------*/ + /* Constants for the save button */ + /*---------------------------------*/ + const string defaultSave = "Save Action"; + const string createAction = "Create Action"; + const string editAction = "Edit Action"; + + + public MainWindow() { //Set up basic settings if (Properties.Settings.Default.defaultSavePath == "") { - Properties.Settings.Default.defaultSavePath = String.Concat(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "\\EZ-Action"); + //MessageBox.Show("Welcome to EZ-Action!" + "\n" + "Please select a working directory. All files generated by this program will be saved there." + "\n" + "You will be able to change this selection later."); + Properties.Settings.Default.defaultSavePath = String.Concat(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)); Properties.Settings.Default.Save(); } if (Properties.Settings.Default.profileDir == "") { @@ -50,25 +89,44 @@ public MainWindow() } InitializeComponent(); + + // Always stays the same, so set as early as possible + fadeOutAnim.From = 1.0; + fadeOutAnim.To = 0.0; + fadeOutAnim.FillBehavior = FillBehavior.Stop; + + Utility_Label.Text = labelEmpty; } private void DelEvent_Button_Click(object sender, RoutedEventArgs e) { object selectedItem = eventList.SelectedItem; + if (eventList.Items.Count == 0) + { + SetUtilityLabel(noActionExists, true); + return; + } if (selectedItem != null) { aceEvent.eventList.RemoveAt(eventList.Items.IndexOf(selectedItem)); eventList.Items.Remove(selectedItem); + + SetUtilityLabel(actionDeleted, true); + } + else + { + SetUtilityLabel(noActionSelected, true); } } private void RegEvent_Button_Click(object sender, RoutedEventArgs e) { // Action Validation - if (validateAction()) + if (ValidateAction()) { + SetUtilityLabel(validationError); return; } @@ -87,6 +145,8 @@ private void RegEvent_Button_Click(object sender, RoutedEventArgs e) targetText.Text = targetCache; targetCache = ""; + SetUtilityLabel(actionEdited, true); + DeactiveEditingMode(); } // When adding, can just straight add and create object @@ -95,13 +155,16 @@ private void RegEvent_Button_Click(object sender, RoutedEventArgs e) aceEvent newEvent = new aceEvent(id, functionText.Text, actionText.Text, progressCheck.IsChecked, intDuration, targetText.Text, classCheck.IsChecked, eventLabelText.Text); aceEvent.eventList.Add(newEvent); + + SetUtilityLabel(actionCreated, true); } + + // Reset all the UI element functionText.Text = ""; classCheck.IsChecked = false; actionText.Text = ""; - //conditionText.Text = ""; eventLabelText.Text = ""; progressCheck.IsChecked = true; @@ -111,15 +174,15 @@ private void RegEvent_Button_Click(object sender, RoutedEventArgs e) private void EventList_MouseDoubleClick(object sender, RoutedEventArgs e) { - ActivateEditingMode(); try { - Editing_Label.Visibility = Visibility.Visible; object selectedItem = eventList.SelectedItem; int index = eventList.Items.IndexOf(selectedItem); aceEvent editAction = aceEvent.eventList[index]; + ActivateEditingMode(); + //Disable the event list so only one thing can be edited at the same time eventList.IsEnabled = false; @@ -139,7 +202,7 @@ private void EventList_MouseDoubleClick(object sender, RoutedEventArgs e) // Catch OutOfRangeExceptions when the user clicks a non-existing item catch (System.ArgumentOutOfRangeException exception) { editing = false; - Editing_Label.Visibility = Visibility.Hidden; + DeactiveEditingMode(); return; } } @@ -147,9 +210,15 @@ private void EventList_MouseDoubleClick(object sender, RoutedEventArgs e) private void ActivateEditingMode() { editing = true; - Editing_Label.Visibility = Visibility.Visible; + //Editing_Label.Visibility = Visibility.Visible; + //Utility_Label.Text = editingMode; + + SetUtilityLabel(editingMode); + + RegEvent_Button.Content = editAction; eventList.IsEnabled = false; + DelEvent_Button.IsEnabled = false; Generate_Button.IsEnabled = false; Clipboard_Button.IsEnabled = false; } @@ -157,14 +226,20 @@ private void ActivateEditingMode() private void DeactiveEditingMode() { editing = false; - Editing_Label.Visibility = Visibility.Hidden; + //Editing_Label.Visibility = Visibility.Hidden; + //Utility_Label.Text = labelEmpty; + + //SetUtilityLabel(labelEmpty); + + RegEvent_Button.Content = createAction; eventList.IsEnabled = true; + DelEvent_Button.IsEnabled = true; Generate_Button.IsEnabled = true; Clipboard_Button.IsEnabled = true; } - private bool validateAction() + private bool ValidateAction() { bool validationFail = false; @@ -188,27 +263,32 @@ private bool validateAction() functionText.Background = Brushes.Transparent; } - if (actionText.Text == "") + if (eventLabelText.Text == "") { validationFail = true; - actionText.Background = Brushes.Salmon; + eventLabelText.Background = Brushes.Salmon; } else { - actionText.Background = Brushes.Transparent; + eventLabelText.Background = Brushes.Transparent; } - if (eventLabelText.Text == "") + + // + // Progress dependant + // + + if (progressCheck.IsChecked == true && actionText.Text == "") { validationFail = true; - eventLabelText.Background = Brushes.Salmon; + actionText.Background = Brushes.Salmon; } else { - eventLabelText.Background = Brushes.Transparent; + actionText.Background = Brushes.Transparent; } - if (durationText.Text == "") + if (progressCheck.IsChecked == true && durationText.Text == "") { validationFail = true; durationText.Background = Brushes.Salmon; @@ -231,7 +311,28 @@ private void Generate_Button_Click(object sender, RoutedEventArgs e) //int varBuild = variableContent.BuildSQF(); int evtBuild = aceEvent.BuildSQF(); - new errorPrint(evtBuild); + //new errorPrint(evtBuild); + + //if (evtBuild == 0) + //{ + // Utility_Label.Text = actionsWritten; + //} + + switch (evtBuild) + { + case 0: + SetUtilityLabel(actionsWritten, true); + break; + case 1: + SetUtilityLabel(writeAborted, true); + break; + case 2: + SetUtilityLabel(noActionsToWrite, true); + break; + case 3: + SetUtilityLabel(errorWrite, true); + break; + } } private void ArmaDir_Button_Click(object sender, RoutedEventArgs e) @@ -257,8 +358,26 @@ private void OpenVarPage_Button_Click(object sender, RoutedEventArgs e) private void Clipboard_Button_Click(object sender, RoutedEventArgs e) { - aceEvent.BuildToClipboard(); - MessageBox.Show("Text copied to clipboard!"); + int result; + result = aceEvent.BuildToClipboard(); + + //if (result == 0) + //{ + // Utility_Label.Text = copiedToClipboard; + //} + + switch (result) + { + case 0: + SetUtilityLabel(copiedToClipboard, true); + break; + case 1: + SetUtilityLabel(noActionsToWrite, true); + break; + case 2: + SetUtilityLabel(errorWrite, true); + break; + } } private void NumberValidationTextBox(object sender, TextCompositionEventArgs e) @@ -277,6 +396,8 @@ private void ResetWindow() this.Title = windowTitle_Base; openedFile = ""; + Utility_Label.Text = labelEmpty; + editing = false; fileOpen = false; @@ -307,7 +428,7 @@ private void OpenFile_Button_Click(object sender, RoutedEventArgs e) int index = 0; - + OpenFileDialog file = new OpenFileDialog { @@ -327,31 +448,31 @@ private void OpenFile_Button_Click(object sender, RoutedEventArgs e) StreamReader readingFile = new StreamReader(file.FileName); string line; - bool first = true; + bool first = true; while ((line = readingFile.ReadLine()) != null) { ran = true; if (first) - { + { metadata data = JsonSerializer.Deserialize(line); - if (!data.validateSelf()) + if (!data.ValidateSelf()) { //metaImported = true; MessageBox.Show("The metadata couldn't be loaded!"); } //else //{ - + //} - + first = false; } else { aceEvent deserializedEvent = JsonSerializer.Deserialize(line); - + if (deserializedEvent.ValidateSelf()) { //actionImported = true; @@ -435,6 +556,49 @@ private void SaveAs() } } + private void SetUtilityLabel(string labelToSet, bool fadeOut = false, int fadeOffset = 1600, int fadeTime = 150) + { + // If animPlay is still active and hasn't been removed, do so + if (animPlay != null) + { + animPlay.Stop(Utility_Label); + //animPlay.Remove(Utility_Label); + + Utility_Label.Opacity = (double)1.0; + + Utility_Label.Visibility = Visibility.Visible; + } + + Utility_Label.Text = labelToSet; + Utility_Label.Visibility = Visibility.Visible; + + Utility_Label.Opacity = (double)1.0; + + if (fadeOut) + { + animPlay = new Storyboard(); + + Utility_Label.Opacity = (double)1.0; + + fadeOutAnim.BeginTime = TimeSpan.FromMilliseconds(fadeOffset); + fadeOutAnim.Duration = new Duration(TimeSpan.FromMilliseconds((double)fadeTime)); + + animPlay.Children.Add(fadeOutAnim); + //Storyboard.SetTarget(fadeOutAnim, Utility_Label); + Storyboard.SetTargetProperty(fadeOutAnim, new PropertyPath(TextBlock.OpacityProperty)); + + animPlay.Completed += CompletedHandler; + animPlay.Begin(Utility_Label, HandoffBehavior.SnapshotAndReplace, true); + } + } + + private void CompletedHandler(object sender, EventArgs e) + { + animPlay.Stop(Utility_Label); + //Utility_Label.Visibility = Visibility.Hidden; + Utility_Label.Opacity = 0.0; + } + private string SetNewTitle(string file) { return String.Concat(windowTitle_Base, ": ", file); diff --git a/EZAction/Properties/AssemblyInfo.cs b/EZAction/Properties/AssemblyInfo.cs index b7820b0..2556739 100644 --- a/EZAction/Properties/AssemblyInfo.cs +++ b/EZAction/Properties/AssemblyInfo.cs @@ -7,12 +7,12 @@ // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("TestAppWPF")] -[assembly: AssemblyDescription("")] +[assembly: AssemblyTitle("EZAction")] +[assembly: AssemblyDescription("A program to quickly generate the skeleton code for ArmA 3 ACE Interactions")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("TestAppWPF")] -[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyProduct("EZAction")] +[assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -51,5 +51,6 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("0.3.0.0")] +[assembly: AssemblyFileVersion("0.3.0.0")] +[assembly: NeutralResourcesLanguage("")] diff --git a/EZAction/aceEvent.cs b/EZAction/aceEvent.cs index c7299a8..9f88b88 100644 --- a/EZAction/aceEvent.cs +++ b/EZAction/aceEvent.cs @@ -7,7 +7,6 @@ using System.Threading.Tasks; using System.IO; using System.Windows; -//using System.Windows.Forms; using MessageBox = System.Windows.MessageBox; using Microsoft.Win32; @@ -136,7 +135,7 @@ public static int BuildSQF() if (eventList.Count <= 0) { - MessageBox.Show("No actions to declare. Skipping step."); + //MessageBox.Show("No actions to declare. Skipping step."); return 2; } @@ -157,7 +156,7 @@ public static int BuildSQF() } else { - return 3; + return 1; } string targets = DeclareTargets(); @@ -175,10 +174,16 @@ public static int BuildSQF() return 0; } - public static void BuildToClipboard() + public static int BuildToClipboard() { StringBuilder buildBuddy = new StringBuilder(); + if (eventList.Count <= 0) + { + //MessageBox.Show("No actions to declare. Skipping step."); + return 1; + } + string targets = DeclareTargets(); string functions = BuildFunctions(); string actions = CreateActions(); @@ -189,7 +194,16 @@ public static void BuildToClipboard() buildBuddy.Append(actions); buildBuddy.Append(adds); - System.Windows.Clipboard.SetText(buildBuddy.ToString()); + try + { + System.Windows.Clipboard.SetText(buildBuddy.ToString()); + } + catch(Exception e) + { + return 2; + } + + return 0; } // Standard for only base and one thing to add @@ -255,7 +269,7 @@ private static string DeclareTargets() foreach (aceEvent element in eventList) { int index = eventList.IndexOf(element) + 1; - string objectNum = String.Concat("_target", index); + string objectNum = String.Concat("_", element.functionName, "Target"); concat = ConcatWithNewLine(concat, new[] { objectNum, " = ", element.targetEntity, ";" }); } @@ -269,12 +283,13 @@ private static string DeclareTargets() private static string BuildFunctions() { - string concat; + // Initialize cause else C# cries + string concat = ""; foreach (aceEvent element in eventList) { - concat = ConcatWithNewLine("_", new[] { element.functionName, " = {" }); + concat = ConcatWithNewLine(concat, new[] { "_", element.functionName, " = {" }); if (element.progressBar) { @@ -294,11 +309,9 @@ private static string BuildFunctions() concat = ConcatWithNewLine(concat, "};"); concat = ConcatNewLine(concat); concat = ConcatNewLine(concat); - - return concat; } - return "shit"; + return concat; } @@ -335,7 +348,7 @@ private static string AddActions() foreach (aceEvent element in eventList) { int index = eventList.IndexOf(element) + 1; - string objectNum = String.Concat("_target", index); + string objectNum = String.Concat("_", element.functionName, "Target"); if (element.classCheck == true) @@ -367,7 +380,7 @@ public DateTime LastSave public metadata() { } - public bool validateSelf() + public bool ValidateSelf() { if (lastSave.ToString() == "01.01.0001 00:00:00") { @@ -384,58 +397,58 @@ public string ExportMetadata() { - class variableContent { - public static List variableList = new List(); - - private string name; - private string value; - - public variableContent(string varName, string varVal) { - name = varName; - value = varVal; - } - - public static int BuildSQF() - { - if (variableList.Count <= 0) { - MessageBox.Show("No variables to declare. Skipping step."); - return 2; - } - - SaveFileDialog saveDialog = new SaveFileDialog - { - Filter = "ArmA 3 Scripting Files (*.sqf)|*.sqf", - FileName = "output_variables.sqf", - InitialDirectory = Properties.Settings.Default.defaultSavePath - }; - - if (saveDialog.ShowDialog() == true) - { - //Cleanup file before writing - File.Delete(saveDialog.FileName); - - foreach (variableContent element in variableList) - { - string line; - //If it's only numbers OR bool values, treat as such - if (Regex.IsMatch(element.value, "^[0-9]*$") || element.value == "true" || element.value == "false") - { - line = String.Concat(element.name, " = ", element.value, "; publicVariable \"", element.name, "\";"); - } - //Else treat as foreign - else - { - line = String.Concat(element.name, " = \"", element.value, "\"; publicVariable \"", element.name, "\";"); - } - } - return 0; - } - else { - return 1; - } - } + //class variableContent { + // public static List variableList = new List(); + + // private string name; + // private string value; + + // public variableContent(string varName, string varVal) { + // name = varName; + // value = varVal; + // } + + // public static int BuildSQF() + // { + // if (variableList.Count <= 0) { + // MessageBox.Show("No variables to declare. Skipping step."); + // return 2; + // } + + // SaveFileDialog saveDialog = new SaveFileDialog + // { + // Filter = "ArmA 3 Scripting Files (*.sqf)|*.sqf", + // FileName = "output_variables.sqf", + // InitialDirectory = Properties.Settings.Default.defaultSavePath + // }; + + // if (saveDialog.ShowDialog() == true) + // { + // //Cleanup file before writing + // File.Delete(saveDialog.FileName); + + // foreach (variableContent element in variableList) + // { + // string line; + // //If it's only numbers OR bool values, treat as such + // if (Regex.IsMatch(element.value, "^[0-9]*$") || element.value == "true" || element.value == "false") + // { + // line = String.Concat(element.name, " = ", element.value, "; publicVariable \"", element.name, "\";"); + // } + // //Else treat as foreign + // else + // { + // line = String.Concat(element.name, " = \"", element.value, "\"; publicVariable \"", element.name, "\";"); + // } + // } + // return 0; + // } + // else { + // return 1; + // } + // } - } + //} class errorPrint {