private void btnFrameRef_Click(object sender, EventArgs e) { int index = lbFrames.SelectedIndex; if (Package.PackageState != AMTUtil.State.READY) { return; } string FileName = (string)Selection_Prompt <string> .ShowDialog("Select a action you want to add as reference", "Action Selection", Package.Animation.Manifest.ActionFileName); if (FileName == null) { return; } //Cannot Have reference conflict string CheckResult = AMTUtil.CheckReference(Package.Animation, Package.Animation.Actions[lbActions.SelectedIndex], AMTUtil.GetActionFromName(Package.Animation, Path.GetFileNameWithoutExtension(FileName))); if (CheckResult != null) { MessageBox.Show("Reference conflict in: " + CheckResult, "Critical Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //lblDebug.Text = FileName; Package.Animation.Actions[lbActions.SelectedIndex].Frames.Add(new AMTFrame()); Package.Animation.Actions[lbActions.SelectedIndex].Frames.Last().Delay = (int)nudDefaultDelay.Value; Package.Animation.Actions[lbActions.SelectedIndex].Frames.Last().ActionRef = Path.GetFileNameWithoutExtension(FileName); Package.Animation.Actions[lbActions.SelectedIndex].Frames.Last().MD5 = null; Package.Animation.Actions[lbActions.SelectedIndex].Frames.Last().Tags.Add("null"); PopulateFrames(); lbFrames.SelectedIndex = lbFrames.Items.Count - 1; }
private void btnOpenExisting_Click(object sender, EventArgs e) { OpenFileDialog OpenFileDialog = new OpenFileDialog(); OpenFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); OpenFileDialog.Filter = AMTConfig.PackageExtension + " files (*" + AMTConfig.PackageExtension + ")|*" + AMTConfig.PackageExtension; OpenFileDialog.FilterIndex = 2; OpenFileDialog.RestoreDirectory = true; if (OpenFileDialog.ShowDialog() == DialogResult.OK) { //Clear UI Before this and Data Package.PackageState = AMTUtil.State.LOADED; ClearElements(); InitData(); //File Loading if (!AMTUtil.OpenPackage(Package, OpenFileDialog.FileName)) { MessageBox.Show("Project Load Error!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Package = new AMTPackage(); Package.PackageState = AMTUtil.State.EMPTY; } else { PopulateResources(); lbAssets.SelectedIndex = 0; PopulateAssetFrames(); lbGifFrames.SelectedIndex = 0; PopulateUI(); } } }
public MainWindow() { InitializeComponent(); Package = new AMTPackage(); bool result = AMTUtil.OpenPackage(Package, AMTUtil.GetAbsPath(Directory.GetCurrentDirectory(), "AMT.apkg")); if (result) { //Set current action Default = new AMTActionPlayer(Package.Animation, AMTUtil.GetDefaultAction(Package.Animation)); CurrentAction = Default; Timer = new DispatcherTimer(); Timer.Interval = TimeSpan.FromMilliseconds(10); Timer.Tick += Timer_Tick; Timer.Start(); this.MouseDoubleClick += MainWindow_MouseDoubleClick; MEAudio.Play(); } else { this.Close(); System.Environment.Exit(0); } this.MouseDown += Window_MouseDown; }
private void btnMoveDown_Click(object sender, EventArgs e) { if (Package.PackageState != AMTUtil.State.READY) { return; } if (lbFrames.SelectedIndex == -1) { MessageBox.Show("You need to select a frame!"); return; } if (lbFrames.SelectedItems.Count > 1) { MessageBox.Show("You cannot move more than one frame."); return; } if (lbFrames.SelectedIndex == lbFrames.Items.Count - 1) { return; } else { //Swap int index = lbFrames.SelectedIndex; AMTUtil.Swap <AMTFrame>(Package.Animation.Actions[lbActions.SelectedIndex].Frames, lbFrames.SelectedIndex, lbFrames.SelectedIndex + 1); PopulateFrames(); lbFrames.SelectedIndex = index + 1; } }
private void btnShowPreview_Click(object sender, EventArgs e) { //When more than one frame, create duplicate action and view action if (Package.PackageState != AMTUtil.State.READY) { return; } if (lbFrames.SelectedIndex == -1) { MessageBox.Show("You need to select a frame!"); return; } if (lbFrames.SelectedItems.Count > 1) { MessageBox.Show("You cannot view more than one frame."); return; } if (Package.Animation.Actions[lbActions.SelectedIndex].Frames[lbFrames.SelectedIndex].ActionRef == null) { AMTResource PreviewResource = AMTUtil.GetResourceFromName(Package, Package.Animation.Actions[lbActions.SelectedIndex].Frames[lbFrames.SelectedIndex].Resource); FramePreview PreviewWindow = new FramePreview(AMTUtil.BytesToImage(PreviewResource.Frames[Package.Animation.Actions[lbActions.SelectedIndex].Frames[lbFrames.SelectedIndex].FrameRef])); PreviewWindow.Show(); } else { ActionPreview PreviewWindow = new ActionPreview(Package, AMTUtil.GetActionFromName(Package.Animation, Package.Animation.Actions[lbActions.SelectedIndex].Frames[lbFrames.SelectedIndex].ActionRef)); PreviewWindow.Show(); } }
private void btnLoadExistingAsset_Click(object sender, EventArgs e) { if (Package.PackageState == AMTUtil.State.EMPTY) { return; } OpenFileDialog OpenFileDialog = new OpenFileDialog(); OpenFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); OpenFileDialog.Filter = "resource files (*" + AMTConfig.ResourcePostExtension + ")|*" + AMTConfig.ResourcePostExtension; OpenFileDialog.FilterIndex = 2; OpenFileDialog.RestoreDirectory = true; if (OpenFileDialog.ShowDialog() == DialogResult.OK) { Package.AddExistingResource(OpenFileDialog.FileName); PopulateResources(); if (Package.PackageState != AMTUtil.State.READY) { if (MessageBox.Show("Do you want to initialize animation using this resource?", "Initialize Animation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { AMTUtil.InitAnimation(Package, Package.CurrentResource.Name); PopulateUI(); } } } Package.SavePackage(); }
private void CMainDisplay_Drop(object sender, DragEventArgs e) { if (MessageBox.Show("Are you sure you want to recycle these files?", "Confirm", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.Cancel) { return; } // When File is dropped on top of widget Main Display if (e.Data.GetDataPresent(DataFormats.FileDrop)) { // Note that you can have more than one file. string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); Timer.Interval = TimeSpan.FromMilliseconds(10); Default = CurrentAction; CurrentAction = new AMTActionPlayer(Package.Animation, AMTUtil.GetActionFromName(Package.Animation, "recycle")); // Assuming you have one file that you care about, pass it off to whatever // handling code you have defined. foreach (string s in files) { Console.WriteLine(s); if (File.GetAttributes(s) == FileAttributes.Directory) { FileSystem.DeleteDirectory(s, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); } else { FileSystem.DeleteFile(s, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); } } } }
private void PopulateFrames() { lbFrames.Items.Clear(); foreach (AMTFrame frame in Package.Animation.Actions[lbActions.SelectedIndex].Frames) { lbFrames.Items.Add(AMTUtil.FrameToString(frame)); } }
public AMTActionPlayer(AMTPackage Pak, AMTAction Act) { this.Package = Pak; this.Action = AMTUtil.ExpandFrame(Pak.Animation, Act); this.CurrentFrame = 0; this.LoopTimes = 0; this.RandomGenerator = new Random(); }
private string ArcPreProcessor(string FilePath) { SevenZipExtractor.SetLibraryPath(@"C:\Program Files (x86)\7-Zip\7z.dll"); var tmp = new SevenZipExtractor(FilePath); tmp.ExtractArchive(WorkingDir); return(AMTUtil.GetAbsPath(WorkingDir, Path.GetFileNameWithoutExtension(FilePath) + AMTConfig.ResourceExtension)); }
private void ArcPostProcessor(string FilePath) { SevenZipExtractor.SetLibraryPath(@"C:\Program Files (x86)\7-Zip\7z.dll"); var tmp = new SevenZipCompressor(); string PostFile = AMTUtil.GetAbsPath(WorkingDir, CurrentResource.Name + AMTConfig.ResourcePostExtension); tmp.CompressFiles(PostFile, FilePath); File.Delete(FilePath); }
private bool SaveCurrentResource() { try { File.WriteAllText(AMTUtil.GetAbsPath(WorkingDir, CurrentResource.Name + AMTConfig.ResourceExtension), JsonConvert.SerializeObject(CurrentResource)); ArcPostProcessor(AMTUtil.GetAbsPath(WorkingDir, CurrentResource.Name + AMTConfig.ResourceExtension)); } catch { return(false); } return(true); }
void Timer_Tick(object sender, EventArgs e) { if (CurrentAction != Default && CurrentAction.GetLoopTime() > 1) { CurrentAction = Default; } AMTFrame f = CurrentAction.GetNextFrameWithRandomness(); Console.WriteLine("Delay: {0}", f.Delay); CMainDisplay.Background = new ImageBrush(AMTUtil.BytesToImageSource(Package.CurrentResource.Frames[f.FrameRef])); //Text(CTopLeft, 10, 100, "Timer Triggered", Color.FromRgb(0, 100, 100)); Timer.Interval = TimeSpan.FromMilliseconds(f.Delay); }
public bool SavePackage() { AMTResource resourceBk = this.CurrentResource; try { this.CurrentResource = null; File.WriteAllText(AMTUtil.GetAbsPath(WorkingDir, "AMT.apkg"), JsonConvert.SerializeObject(this)); } catch { return(false); } this.CurrentResource = resourceBk; return(true); }
public bool SwitchResource(string ResourceName) { if (CurrentResource != null) { if (ResourceName == CurrentResource.Name) { return(true); } } ResourceName = AMTUtil.GetAbsPath(WorkingDir, ResourceName + AMTConfig.ResourceExtension); try { CurrentResource = (AMTResource)JsonConvert.DeserializeObject <AMTResource>(File.ReadAllText(ResourceName)); } catch { return(false); } return(true); }
private void btnNewAsset_Click(object sender, EventArgs e) { if (Package.PackageState == AMTUtil.State.EMPTY) { return; } string PromptValue = InputPrompt.ShowDialog("Name of the resource", "New Resource"); if (PromptValue == null) { return; } if (PromptValue == "") { MessageBox.Show("Input Empty!"); } OpenFileDialog OpenFileDialog = new OpenFileDialog(); OpenFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); OpenFileDialog.Filter = "gif files (*.gif)|*.gif"; OpenFileDialog.FilterIndex = 2; OpenFileDialog.RestoreDirectory = true; if (OpenFileDialog.ShowDialog() == DialogResult.OK) { if (!Package.AddResource(PromptValue, OpenFileDialog.FileName, ResourceType.GIF)) { MessageBox.Show("Resource Load Error!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } PopulateResources(); } if (Package.PackageState != AMTUtil.State.READY) { if (MessageBox.Show("Do you want to initialize animation using this resource?", "Initialize Animation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { AMTUtil.InitAnimation(Package, Package.CurrentResource.Name); PopulateUI(); } } }
private void lbFrames_SelectedIndexChanged(object sender, EventArgs e) { try { if (lbGifFrames.SelectedIndex == -1) { return; } //Make sure frames have been extracted if (Package.CurrentResource.Frames == null || Package.CurrentResource.Frames.Count() == 0) { throw new NoNullAllowedException("Frames have not been extracted"); } //Make sure the selected index is within range if (lbGifFrames.SelectedIndex > Package.CurrentResource.Frames.Count() - 1) { throw new IndexOutOfRangeException("Frame list does not contain index: " + lbGifFrames.SelectedIndex.ToString()); } //Clear the PictureBox ClearPictureBoxImage(); //Load the image from the byte array pbFrame.Image = AMTUtil.BytesToImage(Package.CurrentResource.Frames[lbGifFrames.SelectedIndex]); lblMd5.Text = "MD5: " + AMTUtil.ImageMD5(pbFrame.Image); } catch (Exception ex) { MessageBox.Show( "Error type: " + ex.GetType().ToString() + "\n" + "Message: " + ex.Message, "Error in " + MethodBase.GetCurrentMethod().Name ); } }
void MainWindow_MouseDoubleClick(object sender, MouseButtonEventArgs e) { Timer.Interval = TimeSpan.FromMilliseconds(10); Default = CurrentAction; CurrentAction = new AMTActionPlayer(Package.Animation, AMTUtil.GetActionFromName(Package.Animation, "ribbon")); }
private void btnChangeDelay_Click(object sender, EventArgs e) { if (Package.PackageState != AMTUtil.State.READY) { return; } if (lbFrames.SelectedIndex == -1) { MessageBox.Show("You need to select a frame!"); return; } string PromptValue = InputPrompt.ShowDialog("Input a new time in milliseconds", "Edit time", Package.Animation.Actions[lbActions.SelectedIndex].Frames[lbFrames.SelectedIndex].Delay.ToString()); //User Cancel Action if (PromptValue == null) { return; } if (PromptValue == "") { MessageBox.Show("Input Empty!"); } else { foreach (object o in lbFrames.SelectedItems) { Package.Animation.Actions[lbActions.SelectedIndex].Frames[lbFrames.Items.IndexOf(o)].Delay = Convert.ToInt32(AMTUtil.GetNumbers(PromptValue)); } } PopulateFrames(); }
private void btnRandom_Click(object sender, EventArgs e) { if (Package.PackageState != AMTUtil.State.READY) { return; } if (lbFrames.SelectedIndex == -1) { MessageBox.Show("You need to select a frame!"); return; } string PromptValue = InputPrompt.ShowDialog("Input a new randomness", "Edit Randomness", Package.Animation.Actions[lbActions.SelectedIndex].Frames[lbFrames.SelectedIndex].Randomness.ToString()); //User Cancel Action if (PromptValue == null) { return; } if (PromptValue == "") { MessageBox.Show("Input Empty!"); } else { foreach (object o in lbFrames.SelectedItems) { if (Package.Animation.Actions[lbActions.SelectedIndex].Frames[lbFrames.Items.IndexOf(o)].ActionRef != null) { MessageBox.Show("Action reference frames are not changed.", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { Package.Animation.Actions[lbActions.SelectedIndex].Frames[lbFrames.Items.IndexOf(o)].Randomness = Convert.ToDouble(AMTUtil.GetDouble(PromptValue)); } } } PopulateFrames(); }