Skip to content

Commit

Permalink
New chibi editor layout (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
WiIIiam278 authored Feb 3, 2023
1 parent 9e8cbcf commit 1c82cf2
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 37 deletions.
6 changes: 4 additions & 2 deletions src/SerialLoops.Lib/Items/ChibiItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ChibiItem : Item
public Chibi Chibi { get; set; }
public int ChibiIndex { get; set; }
public List<(string Name, ChibiEntry Chibi)> ChibiEntries { get; set; } = new();
public List<IEnumerable<(SKBitmap Frame, int Timing)>> ChibiAnimations { get; set; } = new();
public Dictionary<string, IEnumerable<(SKBitmap Frame, int Timing)>> ChibiAnimations { get; set; } = new();
public (string ScriptName, ScriptCommandInvocation command)[] ScriptUses { get; set; }

public ChibiItem(Chibi chibi, Project project) : base($"CHIBI{chibi.ChibiEntries[0].Animation}", ItemType.Chibi)
Expand All @@ -27,7 +27,7 @@ public ChibiItem(Chibi chibi, Project project) : base($"CHIBI{chibi.ChibiEntries
ChibiIndex = chibiIndices.IndexOf(firstAnimationName[0..3]);
ChibiEntries.AddRange(Chibi.ChibiEntries.Where(c => c.Animation > 0)
.Select(c => (project.Grp.Files.First(f => f.Index == c.Animation).Name[0..^3], c)));
ChibiAnimations.AddRange(ChibiEntries.Select(c => GetChibiAnimation(c.Name, project.Grp)));
ChibiEntries.ForEach(e => ChibiAnimations.Add(e.Name, GetChibiAnimation(e.Name, project.Grp)));
PopulateScriptUses(project.Evt);
}

Expand Down Expand Up @@ -60,4 +60,6 @@ public void PopulateScriptUses(ArchiveFile<EventFile> evt)
ScriptUses = list.ToArray();
}
}


}
2 changes: 1 addition & 1 deletion src/SerialLoops/Editors/BackgroundEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public BackgroundEditor(BackgroundItem item, ILogger log) : base(item, log)
{
}

public override Panel GetEditorPanel()
public override Container GetEditorPanel()
{
_bg = (BackgroundItem)Description;
return new StackLayout
Expand Down
2 changes: 1 addition & 1 deletion src/SerialLoops/Editors/CharacterSpriteEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public CharacterSpriteEditor(CharacterSpriteItem item, Project project, ILogger
{
}

public override Panel GetEditorPanel()
public override Container GetEditorPanel()
{
_sprite = (CharacterSpriteItem)Description;
_animatedImage = new AnimatedImage(_sprite.GetLipFlapAnimation(_project));
Expand Down
116 changes: 90 additions & 26 deletions src/SerialLoops/Editors/ChibiEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,103 @@
using SerialLoops.Lib.Items;
using SerialLoops.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;

namespace SerialLoops.Editors
{
public class ChibiEditor : Editor
{
private ChibiItem _chibi;
private DropDown _chibiSelection;
private DropDown _animationSelection;
private RadioButtonList _poseSelection;

private AnimatedImage _animatedImage;
private StackLayout _framesStack;

public ChibiEditor(ChibiItem chibi, ILogger log) : base(chibi, log)
{
}

public override Panel GetEditorPanel()
public override Container GetEditorPanel()
{
_chibi = (ChibiItem)Description;

_chibiSelection = new();
_chibiSelection.Items.AddRange(_chibi.ChibiEntries.Select(c => new ListItem() { Text = c.Name, Key = c.Name }));
_chibiSelection.SelectedIndex = 0;
_chibiSelection.SelectedKeyChanged += ChibiSelection_SelectedKeyChanged;
TableRow row = new(GetAnimationEditor(), GetChibiSelector());
row.ScaleHeight = false;

return new TableLayout(row);
}

_animatedImage = new(_chibi.ChibiAnimations[0]);
private Container GetChibiSelector()
{
_animationSelection = new();
_animationSelection.Items.AddRange(_chibi.ChibiEntries
.Select(c => c.Name.Substring(0, c.Name.Length - 3)).Distinct().Select(c => new ListItem() { Text = c, Key = c }));
_animationSelection.SelectedIndex = 0;
_animationSelection.SelectedKeyChanged += ChibiSelection_SelectedKeyChanged;

_poseSelection = new RadioButtonList();
_poseSelection.Items.AddRange(Enum.GetValues(typeof(ChibiPose))
.Cast<ChibiPose>().Select(p => new ListItem() { Text = p.ToString(), Key = p.ToString() }));
_poseSelection.SelectedIndex = 0;
_poseSelection.SelectedKeyChanged += ChibiSelection_SelectedKeyChanged;
_poseSelection.Orientation = Orientation.Vertical;

return new TableLayout
{
Width = 200,
Padding = 10,
Rows =
{
new GroupBox
{
Text = "Animation",
Padding = 10,
Content = _animationSelection
},
new GroupBox
{
Text = "Pose",
Padding = 10,
Content = _poseSelection
}
}
};
}

private Container GetAnimationEditor()
{
_animatedImage = new(_chibi.ChibiAnimations.FirstOrDefault().Value);
_animatedImage.Play();

_framesStack = new() { Orientation = Orientation.Vertical, Spacing = 10 };
_framesStack = new() {
Orientation = Orientation.Horizontal,
Spacing = 15,
MinimumSize = new(300, 100)
};
UpdateFramesStack();

return new StackLayout
{
Orientation = Orientation.Vertical,
Spacing = 10,
Items =
{
_chibiSelection,
new StackLayout
new GroupBox
{
Text = _chibi.Name,
Padding = 10,
Content = _animatedImage
},
new GroupBox
{
Orientation = Orientation.Horizontal,
Spacing = 20,
Items =
Text = "Frames",
Padding = 10,
Content = new Scrollable
{
new GroupBox
{
Text = "Animation",
Content = _animatedImage,
},
new GroupBox
{
Text = "Frames",
Content = _framesStack,
}
Content = _framesStack
}
}
}
Expand All @@ -72,12 +117,31 @@ private void UpdateFramesStack()

private void ChibiSelection_SelectedKeyChanged(object sender, EventArgs e)
{
DropDown chibiDropDown = (DropDown)sender;
AnimatedImage newImage = new(_chibi.ChibiAnimations[chibiDropDown.SelectedIndex]);
string selectedAnimationKey = getSelectedAnimationKey();
if (!_chibi.ChibiAnimations.ContainsKey(selectedAnimationKey))
{
_animatedImage.FramesWithTimings = new() { (new SKGuiImage(new SkiaSharp.SKBitmap(32, 32)), 1) };
} else
{
AnimatedImage newImage = new(_chibi.ChibiAnimations[selectedAnimationKey]);
_animatedImage.FramesWithTimings = newImage.FramesWithTimings;
}
_animatedImage.CurrentFrame = 0;
_animatedImage.FramesWithTimings = newImage.FramesWithTimings;
_animatedImage.UpdateImage();
UpdateFramesStack();
}

private string getSelectedAnimationKey()
{
return $"{_animationSelection.SelectedKey.Trim()}_{_poseSelection.SelectedKey.Trim()}";
}

public enum ChibiPose
{
BL,
BR,
UL,
UR
}
}
}
6 changes: 2 additions & 4 deletions src/SerialLoops/Editors/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ void InitializeComponent()
Text = Description.Name;
Image = EditorTabsPanel.GetItemIcon(Description.Type, _log);
Padding = 10;

Panel panel = GetEditorPanel();
Content = panel;
Content = GetEditorPanel();
}

public abstract Panel GetEditorPanel();
public abstract Container GetEditorPanel();

}
}
2 changes: 1 addition & 1 deletion src/SerialLoops/Editors/MapEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public MapEditor(MapItem map, ILogger log) : base(map, log)
{
}

public override Panel GetEditorPanel()
public override Container GetEditorPanel()
{
_map = (MapItem)Description;
return new StackLayout
Expand Down
2 changes: 1 addition & 1 deletion src/SerialLoops/Editors/PuzzleEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public PuzzleEditor(PuzzleItem item, ILogger log) : base(item, log)
{
}

public override Panel GetEditorPanel()
public override Container GetEditorPanel()
{
_puzzle = (PuzzleItem)Description;
StackLayout mainLayout = new()
Expand Down
2 changes: 1 addition & 1 deletion src/SerialLoops/Editors/ScriptEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public ScriptEditor(ScriptItem item, ILogger log) : base(item, log)
{
}

public override Panel GetEditorPanel()
public override Container GetEditorPanel()
{
_script = (ScriptItem)Description;
return new StackLayout
Expand Down

0 comments on commit 1c82cf2

Please sign in to comment.