mirror of
https://github.com/kwsch/pkNX.git
synced 2026-04-24 23:06:56 -05:00
Improve main editor buttons (#259)
* Don't add spaces for abbreviations * Sort editor buttons alphabetically
This commit is contained in:
parent
905977383b
commit
6cff58fbf7
|
|
@ -2,6 +2,7 @@
|
|||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using pkNX.Sprites;
|
||||
|
|
@ -160,7 +161,7 @@ private void OpenFolder(string path)
|
|||
private void LoadROM(EditorBase editor)
|
||||
{
|
||||
Editor = editor;
|
||||
var ctrl = Editor.GetControls(120, 35);
|
||||
var ctrl = Editor.GetControls(120, 35).OrderBy(x => x.Text);
|
||||
FLP_Controls.Controls.Clear();
|
||||
foreach (var c in ctrl)
|
||||
FLP_Controls.Controls.Add(c);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,43 @@ public abstract class EditorBase
|
|||
|
||||
public void Initialize() => ROM.Initialize();
|
||||
|
||||
private static string GetEditorName(string name)
|
||||
{
|
||||
var newName = name.Replace('_', ' ').ToCharArray();
|
||||
var builder = new StringBuilder();
|
||||
|
||||
// Force first char to upper
|
||||
newName[0] = char.ToUpper(newName[0]);
|
||||
|
||||
for (int i = 0; i < newName.Length; ++i)
|
||||
{
|
||||
char c = newName[i];
|
||||
builder.Append(c);
|
||||
|
||||
// Check the next char
|
||||
if (i + 1 >= newName.Length)
|
||||
continue;
|
||||
char nextC = newName[i + 1];
|
||||
|
||||
// If current is space, replace next with upper char
|
||||
if (c == ' ')
|
||||
{
|
||||
newName[i + 1] = char.ToUpper(nextC);
|
||||
}
|
||||
// If current is lower and next is upper, add a space in between
|
||||
else if (char.IsLower(c) && char.IsUpper(nextC))
|
||||
{
|
||||
builder.Append(' ');
|
||||
}
|
||||
// If previous is upper, current is upper and next is lower, add a space in between
|
||||
else if (i + 2 < newName.Length && char.IsUpper(c) && char.IsUpper(nextC) && char.IsLower(newName[i + 2]))
|
||||
{
|
||||
builder.Append(' ');
|
||||
}
|
||||
}
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
public IEnumerable<Button> GetControls(int width, int height)
|
||||
{
|
||||
var type = GetType();
|
||||
|
|
@ -30,18 +67,6 @@ public IEnumerable<Button> GetControls(int width, int height)
|
|||
if (!m.Name.StartsWith(prefix))
|
||||
continue;
|
||||
|
||||
static string GetEditorName(string name)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
foreach (char c in name.Replace("_", ""))
|
||||
{
|
||||
if (char.IsUpper(c) && builder.Length > 0)
|
||||
builder.Append(' ');
|
||||
builder.Append(c);
|
||||
}
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
var name = m.Name[prefix.Length..];
|
||||
var b = new Button
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user