• 0
gekigengar

Act Editor Replace Color for all layers

Question

I need help for this Act Editor.

Hello, I want to be able to tint the entire mob layer color without having to go frame by frame.

Currently, CTRL-SHIFT-W (Replace color script) does just that, but only for that 1 single frame.

I wanted to replace color for the entire frame in the sprite for a quick mob tinting. (For all animation, and all frames).

Any help?

Share this post


Link to post
Share on other sites

10 answers to this question

Recommended Posts

  • 1

Copy and paste this file to Scripts > Open scripts folder (name it "SetColor.cs"):

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using ErrorManager;
using GRF.FileFormats.ActFormat;
using GRF.FileFormats.SprFormat;
using GRF.FileFormats.PalFormat;
using GRF.Image;
using GRF.Image.Decoders;
using GRF.Graphics;
using GrfToWpfBridge;
using TokeiLibrary;
using TokeiLibrary.WPF;
using Action = GRF.FileFormats.ActFormat.Action;
using Frame = GRF.FileFormats.ActFormat.Frame;
using Point = System.Windows.Point;

namespace Scripts {
    public class Script : IActScript {
		public object DisplayName {
			get { return "Change all layer color"; }
		}
		
		public string Group {
			get { return "Scripts"; }
		}
		
		public string InputGesture {
			get { return null; }
		}
		
		public string Image {
			get { return null; }
		}
		
		public void Execute(Act act, int selectedActionIndex, int selectedFrameIndex, int[] selectedLayerIndexes) {
			if (act == null) return;
			
			var frame = act[selectedActionIndex, selectedFrameIndex];
			
			GrfColor startColor;
			
			if (frame.Layers.Count == 0) {
				startColor = GrfColor.White;
			}
			else {
				startColor = act[selectedActionIndex, selectedFrameIndex, 0].Color;
			}
			
			ColorPicker.PickerDialog picker = new ColorPicker.PickerDialog(startColor.ToColor(), ColorPicker.Core.ColorMode.Hue);
			picker.Owner = WpfUtilities.TopWindow;
			picker.ShowDialog();
			
			if (picker.DialogResult) {
				try {
					act.Commands.Begin();
					GrfColor newColor = picker.PickerControl.SelectedColor.ToGrfColor();
					act.Commands.SetColor(newColor);
				}
				catch (Exception err) {
					act.Commands.CancelEdit();
					ErrorHandler.HandleException(err, ErrorLevel.Warning);
				}
				finally {
					act.Commands.End();
					act.InvalidateVisual();
				}
			}
		}
		
		public bool CanExecute(Act act, int selectedActionIndex, int selectedFrameIndex, int[] selectedLayerIndexes) {
			return act != null;
		}
	}
}

Then you can use Scripts > Change all layer color. I really should update Act Editor @@...

Edited by Tokei
  • Upvote 2

Share this post


Link to post
Share on other sites
  • 1
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using ErrorManager;
using GRF.FileFormats.ActFormat;
using GRF.FileFormats.SprFormat;
using GRF.FileFormats.PalFormat;
using GRF.Image;
using GRF.Image.Decoders;
using GRF.Graphics;
using GrfToWpfBridge;
using TokeiLibrary;
using TokeiLibrary.WPF;
using Action = GRF.FileFormats.ActFormat.Action;
using Frame = GRF.FileFormats.ActFormat.Frame;
using Point = System.Windows.Point;

namespace Scripts {
    public class Script : IActScript {
		public object DisplayName {
			get { return "MyCustomScript"; }
		}
		
		public string Group {
			get { return "Scripts"; }
		}
		
		public string InputGesture {
			get { return null; }
		}
		
		public string Image {
			get { return null; }
		}
		
		public void Execute(Act act, int selectedActionIndex, int selectedFrameIndex, int[] selectedLayerIndexes) {
			if (act == null) return;
			
			try {
				act.Commands.Begin();
				act.Commands.Backup(_ => {
					act.SetColor("#99F80909");
				}, "MyCustomScript", true);
			}
			catch (Exception err) {
				act.Commands.CancelEdit();
				ErrorHandler.HandleException(err, ErrorLevel.Warning);
			}
			finally {
				act.Commands.End();
				act.InvalidateVisual();
				act.InvalidateSpriteVisual();
			}
		}
		
		public bool CanExecute(Act act, int selectedActionIndex, int selectedFrameIndex, int[] selectedLayerIndexes) {
			return act != null;
		}
	}
}

use Scripts, line 49 is act.SetColor("#99F80909"); Change it any way.

  • Upvote 2

Share this post


Link to post
Share on other sites
  • 0
5 hours ago, Kinx said:
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using ErrorManager;
using GRF.FileFormats.ActFormat;
using GRF.FileFormats.SprFormat;
using GRF.FileFormats.PalFormat;
using GRF.Image;
using GRF.Image.Decoders;
using GRF.Graphics;
using GrfToWpfBridge;
using TokeiLibrary;
using TokeiLibrary.WPF;
using Action = GRF.FileFormats.ActFormat.Action;
using Frame = GRF.FileFormats.ActFormat.Frame;
using Point = System.Windows.Point;

namespace Scripts {
    public class Script : IActScript {
		public object DisplayName {
			get { return "MyCustomScript"; }
		}
		
		public string Group {
			get { return "Scripts"; }
		}
		
		public string InputGesture {
			get { return null; }
		}
		
		public string Image {
			get { return null; }
		}
		
		public void Execute(Act act, int selectedActionIndex, int selectedFrameIndex, int[] selectedLayerIndexes) {
			if (act == null) return;
			
			try {
				act.Commands.Begin();
				act.Commands.Backup(_ => {
					act.SetColor("#99F80909");
				}, "MyCustomScript", true);
			}
			catch (Exception err) {
				act.Commands.CancelEdit();
				ErrorHandler.HandleException(err, ErrorLevel.Warning);
			}
			finally {
				act.Commands.End();
				act.InvalidateVisual();
				act.InvalidateSpriteVisual();
			}
		}
		
		public bool CanExecute(Act act, int selectedActionIndex, int selectedFrameIndex, int[] selectedLayerIndexes) {
			return act != null;
		}
	}
}

use Scripts, line 49 is act.SetColor("#99F80909"); Change it any way.

Thank you so much!

It works brilliantly!

Saves a ton of time tinting sprites :wub:

Any way I can use the color picker for this though? Instead of defining the color string in the script itself.

Share this post


Link to post
Share on other sites
  • 0
10 hours ago, Tokei said:

Copy and paste this file to Scripts > Open scripts folder (name it "SetColor.cs"):

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using ErrorManager;
using GRF.FileFormats.ActFormat;
using GRF.FileFormats.SprFormat;
using GRF.FileFormats.PalFormat;
using GRF.Image;
using GRF.Image.Decoders;
using GRF.Graphics;
using GrfToWpfBridge;
using TokeiLibrary;
using TokeiLibrary.WPF;
using Action = GRF.FileFormats.ActFormat.Action;
using Frame = GRF.FileFormats.ActFormat.Frame;
using Point = System.Windows.Point;

namespace Scripts {
    public class Script : IActScript {
		public object DisplayName {
			get { return "Change all layer color"; }
		}
		
		public string Group {
			get { return "Scripts"; }
		}
		
		public string InputGesture {
			get { return null; }
		}
		
		public string Image {
			get { return null; }
		}
		
		public void Execute(Act act, int selectedActionIndex, int selectedFrameIndex, int[] selectedLayerIndexes) {
			if (act == null) return;
			
			var frame = act[selectedActionIndex, selectedFrameIndex];
			
			GrfColor startColor;
			
			if (frame.Layers.Count == 0) {
				startColor = GrfColor.White;
			}
			else {
				startColor = act[selectedActionIndex, selectedFrameIndex, 0].Color;
			}
			
			ColorPicker.PickerDialog picker = new ColorPicker.PickerDialog(startColor.ToColor(), ColorPicker.Core.ColorMode.Hue);
			picker.Owner = WpfUtilities.TopWindow;
			picker.ShowDialog();
			
			if (picker.DialogResult) {
				try {
					act.Commands.Begin();
					GrfColor newColor = picker.PickerControl.SelectedColor.ToGrfColor();
					act.Commands.SetColor(newColor);
				}
				catch (Exception err) {
					act.Commands.CancelEdit();
					ErrorHandler.HandleException(err, ErrorLevel.Warning);
				}
				finally {
					act.Commands.End();
					act.InvalidateVisual();
				}
			}
		}
		
		public bool CanExecute(Act act, int selectedActionIndex, int selectedFrameIndex, int[] selectedLayerIndexes) {
			return act != null;
		}
	}
}

Then you can use Scripts > Change all layer color. I really should update Act Editor @@...

Thanks a lot Tokei!

For both the answer and for developing Act Editor!

Oh, meanwhile, if you are planning to update it..

There are a lot of bugs in the Palette Editor.

Sometimes selecting a gradient palette, and pasting ARGB color does not update the palette. (Unless I first move the color picker around)

And the Undo tends to revert to the wrong colors.

I also have a suggestion for the ability to assign which area of the sprite will use which part of the palette.

(Sometimes I need a quick fix to those pesky nose color palettes!)

This might not be the place to report bugs, but I am not sure where to report.

Other than that, thanks a lot :D

------------------------------------------------------

EDIT: Edited the script, added the ability to preview the color in editor following the examples from other scripts.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using ErrorManager;
using GRF.FileFormats.ActFormat;
using GRF.FileFormats.SprFormat;
using GRF.FileFormats.PalFormat;
using GRF.Image;
using GRF.Image.Decoders;
using GRF.Graphics;
using GrfToWpfBridge;
using TokeiLibrary;
using TokeiLibrary.WPF;
using Action = GRF.FileFormats.ActFormat.Action;
using Frame = GRF.FileFormats.ActFormat.Frame;
using Point = System.Windows.Point;

namespace Scripts {
    public class Script : IActScript {
		public object DisplayName {
			get { return "Fill Color"; }
		}
		
		public string Group {
			get { return "Scripts"; }
		}
		
		public string InputGesture {
			get { return "Ctrl-Shift-N"; }
		}
		
		public string Image {
			get { return "pal.png"; }
		}
		
		public void Execute(Act act, int selectedActionIndex, int selectedFrameIndex, int[] selectedLayerIndexes) {
			if (act == null) return;
			
			var frame = act[selectedActionIndex, selectedFrameIndex];
			
			GrfColor startColor;
			
			if (frame.Layers.Count == 0) {
				startColor = GrfColor.White;
			}
			else {
				startColor = act[selectedActionIndex, selectedFrameIndex, 0].Color;
			}
			
			ColorPicker.PickerDialog picker = new ColorPicker.PickerDialog(startColor.ToColor(), ColorPicker.Core.ColorMode.Hue);
			picker.Owner = WpfUtilities.TopWindow;
			
			picker.PickerControl.PreviewColorChanged += (s, color) => _previewUpdate(act, color.ToGrfColor());
			picker.PickerControl.ColorChanged += (s, color) => _previewUpdate(act, color.ToGrfColor());
				
			picker.ShowDialog();
			
			act.Commands.SetColor(startColor);
			
			if (picker.DialogResult) {
				try {
					act.Commands.Begin();
					GrfColor newColor = picker.PickerControl.SelectedColor.ToGrfColor();
					act.Commands.SetColor(newColor);
				}
				catch (Exception err) {
					act.Commands.CancelEdit();
					ErrorHandler.HandleException(err, ErrorLevel.Warning);
				}
				finally {
					act.Commands.End();
					act.InvalidateVisual();
				}
			}
		}
		
		public bool CanExecute(Act act, int selectedActionIndex, int selectedFrameIndex, int[] selectedLayerIndexes) {
			return act != null;
		}
		
		private void _previewUpdate(Act act, GrfColor color) {
			act.Commands.SetColor(color);
			
			act.InvalidateVisual();
		}
	}
}

I hope I am doing this right, just sharing for people who is looking for the same script :D

Edited by gekigengar

Share this post


Link to post
Share on other sites
  • 0

@Tokei Sorry for reviving this old thread, but there is a similar problem to this.

 

Moving a sprite moves the sprites X Y coordinates in a single frame only... Is there a option/script to move it in all frames at once?

In my case, it's a falcon that should be placed higher.

 

Thank you in advance.

Edited by Chuu

Share this post


Link to post
Share on other sites
  • 0

Have you tried holding down alt + moving the image? I reallyyy need to remake that software.

Share this post


Link to post
Share on other sites
  • 0

Yes I've tried it after your reply, but sadly it doesn't change the effect. Still just one frame is touched.

I think your software is fine, there are just some scripts missing that target all frames at once.

Frame 0:  Moved Y by +100

JI7Ucro.png

 

Frame 1:

4CGlIPB.png

Share this post


Link to post
Share on other sites
  • 0

@Tokeiburu

Is there a script out yet to move everything at once? X_X

Share this post


Link to post
Share on other sites
  • 0
On 1/16/2018 at 6:49 AM, Chuu said:

@Tokeiburu

Is there a script out yet to move everything at once? X_X

Well, I've updated the version to 1.1.0, the Alt-Move should now work. Bunch of other changes as well, looks like I forgot to push the updates for this software (I got pretty busy!).

Although I'll just mention that this was always possible via scripting:

Script > Script Runner... > 

act[selectedActionIndex].Translate(0, -100);

or

// Translates by 100 up for the whole act file
act.Translate(0, -100);

 

Edited by Tokei
  • Like 1

Share this post


Link to post
Share on other sites
  • 0

Thank you so much, it does work flawless. So many people appreciate your hard work, keep it up!

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now