diff --git a/CHANGELOG.md b/CHANGELOG.md index 00470a0..64ee907 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.5.0] + +### Added + +- Default button + +### Changed + +- Monospaced fonts now respects custom character properties +- Keeping changes at runtime + +--- + ## [1.4.0] ### Added @@ -119,6 +132,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Initial version +[1.5.0]: https://github.com/kleber-swf/unity-bitmap-font-creator/releases/tag/1.5.0 [1.4.0]: https://github.com/kleber-swf/unity-bitmap-font-creator/releases/tag/1.4.0 [1.3.0]: https://github.com/kleber-swf/unity-bitmap-font-creator/releases/tag/1.3.0 [1.2.1]: https://github.com/kleber-swf/unity-bitmap-font-creator/releases/tag/1.2.1 diff --git a/Documentation/screenshot-01.png b/Documentation/screenshot-01.png index 1ad65dd..7969d94 100644 Binary files a/Documentation/screenshot-01.png and b/Documentation/screenshot-01.png differ diff --git a/Editor/Resources/RuntimeData.asset b/Editor/Resources/RuntimeData.asset new file mode 100644 index 0000000..659e750 --- /dev/null +++ b/Editor/Resources/RuntimeData.asset @@ -0,0 +1,14 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c4647d479c338325f9328893d838e266, type: 3} + m_Name: RuntimeData + m_EditorClassIdentifier: diff --git a/Editor/Resources/RuntimeData.asset.meta b/Editor/Resources/RuntimeData.asset.meta new file mode 100644 index 0000000..27f9e89 --- /dev/null +++ b/Editor/Resources/RuntimeData.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3342bbdaf7f3d987980bb6d5ee3dd118 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Scripts/BitmapFontCreator.cs b/Editor/Scripts/BitmapFontCreator.cs index 89d8e70..b441f52 100644 --- a/Editor/Scripts/BitmapFontCreator.cs +++ b/Editor/Scripts/BitmapFontCreator.cs @@ -85,24 +85,14 @@ private static Material CreateMaterial(string baseName, Texture2D texture) private static Font CreateFontAsset(string baseName, Material material, ExecutionData data, out string error) { - error = null; - var map = new Dictionary(); - for (var i = 0; i < data.CustomCharacterProps.Count; i++) - { - var e = data.CustomCharacterProps[i]; - if (string.IsNullOrEmpty(e.Character)) - { - error = $"Character for Custom Character Properties at position {i + 1} is empty"; - return null; - } - map.Add(e.Character[0], e); - } + var custom = GetCustomPropsAsMap(data.CustomCharacterProps, out error); + if (!string.IsNullOrEmpty(error)) return null; var metrics = new FontMetrics(); var font = new Font(baseName) { material = material, - characterInfo = CreateCharacters(data, map, data.Descent, ref metrics), + characterInfo = CreateCharacters(data, custom, data.Descent, ref metrics), }; var so = new SerializedObject(font); @@ -115,8 +105,27 @@ private static Font CreateFontAsset(string baseName, Material material, Executio return font; } - private static CharacterInfo[] CreateCharacters(ExecutionData data, Dictionary map, - float descent, ref FontMetrics metrics) + private static Dictionary GetCustomPropsAsMap(List props, out string error) + { + error = null; + var map = new Dictionary(); + + for (var i = 0; i < props.Count; i++) + { + var e = props[i]; + if (string.IsNullOrEmpty(e.Character)) + { + error = $"Character for Custom Character Properties at position {i + 1} is empty"; + return null; + } + map.Add(e.Character[0], e); + } + + return map; + } + + private static CharacterInfo[] CreateCharacters(ExecutionData data, Dictionary custom, + float descent, ref FontMetrics metrics) { var texSize = new Vector2Int(data.Texture.width, data.Texture.height); var cellSize = new Vector2Int(Mathf.FloorToInt(texSize.x / data.Cols), Mathf.FloorToInt(texSize.y / data.Rows)); @@ -164,14 +173,14 @@ ref gi gi.uvBottom = cellUVSize.x * (col + 1) - ((cellSize.x - gi.xMax) * ratio.x); gi.uvRight = cellUVSize.y * (data.Rows - row - 1) + ((cellSize.y - gi.yMax) * ratio.y); - var info = CreateCharacterInfo(ch, gi, map); + var info = CreateCharacterInfo(ch, gi, custom); characters.Add(info); if (!data.CaseInsentive) continue; var ch2 = char.ToUpper(ch); - if (ch2 != ch) characters.Add(CreateCharacterInfo(ch2, gi, map)); + if (ch2 != ch) characters.Add(CreateCharacterInfo(ch2, gi, custom)); ch2 = char.ToLower(ch2); - if (ch2 != ch) characters.Add(CreateCharacterInfo(ch2, gi, map)); + if (ch2 != ch) characters.Add(CreateCharacterInfo(ch2, gi, custom)); #if BITMAP_FONT_CREATOR_DEV static string _(float x) => $"{x}"; @@ -183,12 +192,12 @@ ref gi characters.Add(CreateSpaceCharacter(advanceMin)); if (data.Monospaced) - SetFontAsMonospaced(characters, advanceMax); + SetFontAsMonospaced(characters, advanceMax, custom); return characters.ToArray(); } - private static CharacterInfo CreateCharacterInfo(char ch, GlyphInfo g, Dictionary map) + private static CharacterInfo CreateCharacterInfo(char ch, GlyphInfo g, Dictionary custom) { var info = new CharacterInfo { @@ -203,7 +212,7 @@ private static CharacterInfo CreateCharacterInfo(char ch, GlyphInfo g, Dictionar advance = g.advance, }; - if (map.TryGetValue(ch, out var props)) + if (custom.TryGetValue(ch, out var props)) { info.minX += props.Padding.x; info.maxX += props.Padding.x; @@ -256,10 +265,11 @@ private static CharacterInfo CreateSpaceCharacter(int advance) }; } - private static void SetFontAsMonospaced(List characters, int advMax) + private static void SetFontAsMonospaced(List characters, int advMax, Dictionary custom) { for (var i = 0; i < characters.Count; i++) { + if (custom.ContainsKey((char)characters[i].index)) continue; var c = characters[i]; var x = c.minX + Mathf.RoundToInt((advMax - c.advance) * 0.5f); c.minX += x; diff --git a/Editor/Scripts/Model/BitmapFontCreatorModel.cs b/Editor/Scripts/Model/BitmapFontCreatorModel.cs index 625a626..1d35ca3 100644 --- a/Editor/Scripts/Model/BitmapFontCreatorModel.cs +++ b/Editor/Scripts/Model/BitmapFontCreatorModel.cs @@ -4,32 +4,8 @@ namespace dev.klebersilva.tools.bitmapfontcreator { - internal enum Orientation - { - Horizontal, - Vertical, - } - - [Serializable] - internal class CharacterProps - { - public string Character = ""; - public Vector2Int Padding = Vector2Int.zero; - public int Spacing = 0; - - public CharacterProps Clone() - { - return new CharacterProps - { - Character = Character, - Padding = Padding, - Spacing = Spacing, - }; - } - } - [Serializable] - internal class BitmapFontCreatorData : ISerializationCallbackReceiver + internal class BitmapFontCreatorModel : ISerializationCallbackReceiver { private const string IgnoreCharacter = "\n"; @@ -63,7 +39,7 @@ public string Characters public string ValidCharacters { get; protected set; } = string.Empty; public int ValidCharactersCount { get; protected set; } = 0; - public virtual void CopyTo(BitmapFontCreatorData dest) + public virtual void CopyTo(BitmapFontCreatorModel dest) { if (dest == null) return; @@ -74,10 +50,10 @@ public virtual void CopyTo(BitmapFontCreatorData dest) dest.AlphaThreshold = AlphaThreshold; dest.LineSpacing = LineSpacing; dest.AutoLineSpacing = AutoLineSpacing; - dest.Monospaced = Monospaced; - dest.CaseInsentive = CaseInsentive; dest.FontSize = FontSize; dest.AutoFontSize = AutoFontSize; + dest.Monospaced = Monospaced; + dest.CaseInsentive = CaseInsentive; dest.Ascent = Ascent; dest.Descent = Descent; dest.DefaultCharacterSpacing = DefaultCharacterSpacing; @@ -91,7 +67,6 @@ public virtual void CopyTo(BitmapFontCreatorData dest) UpdateChacters(); } - // TODO this should be called automatically when the field Characters changes private void UpdateChacters() { ValidCharacters = _characters.Replace(IgnoreCharacter, string.Empty); @@ -100,23 +75,23 @@ private void UpdateChacters() public void OnBeforeSerialize() { } public void OnAfterDeserialize() { UpdateChacters(); } - } - - internal class ExecutionData : BitmapFontCreatorData - { - [NonSerialized] public Texture2D Texture; - public static ExecutionData Default => new() + public static BitmapFontCreatorModel Default => new() { - Texture = null, Characters = string.Empty, Orientation = Orientation.Horizontal, Cols = 1, Rows = 1, AlphaThreshold = 0f, - DefaultCharacterSpacing = 10, - Monospaced = false, LineSpacing = 0f, + AutoLineSpacing = true, + FontSize = 0f, + AutoFontSize = true, + Monospaced = false, + CaseInsentive = false, + Ascent = 0f, + Descent = 0f, + DefaultCharacterSpacing = 0, CustomCharacterProps = new List(), ValidCharacters = string.Empty, ValidCharactersCount = 0 diff --git a/Editor/Scripts/Model/CharacterProps.cs b/Editor/Scripts/Model/CharacterProps.cs new file mode 100644 index 0000000..3470291 --- /dev/null +++ b/Editor/Scripts/Model/CharacterProps.cs @@ -0,0 +1,23 @@ +using System; +using UnityEngine; + +namespace dev.klebersilva.tools.bitmapfontcreator +{ + [Serializable] + internal class CharacterProps + { + public string Character = ""; + public Vector2Int Padding = Vector2Int.zero; + public int Spacing = 0; + + public CharacterProps Clone() + { + return new CharacterProps + { + Character = Character, + Padding = Padding, + Spacing = Spacing, + }; + } + } +} diff --git a/Editor/Scripts/Model/CharacterProps.cs.meta b/Editor/Scripts/Model/CharacterProps.cs.meta new file mode 100644 index 0000000..bdd57c7 --- /dev/null +++ b/Editor/Scripts/Model/CharacterProps.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fff4f5fb74dce3b39a0a829a2aab67f3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Scripts/Model/ExecutionData.cs b/Editor/Scripts/Model/ExecutionData.cs new file mode 100644 index 0000000..d1d90ad --- /dev/null +++ b/Editor/Scripts/Model/ExecutionData.cs @@ -0,0 +1,21 @@ +using System; +using UnityEngine; + +namespace dev.klebersilva.tools.bitmapfontcreator +{ + [Serializable] + internal class ExecutionData : BitmapFontCreatorModel + { + public Texture2D Texture; + + public static new ExecutionData Default + { + get + { + var data = new ExecutionData { Texture = null }; + BitmapFontCreatorModel.Default.CopyTo(data); + return data; + } + } + } +} diff --git a/Editor/Scripts/Model/ExecutionData.cs.meta b/Editor/Scripts/Model/ExecutionData.cs.meta new file mode 100644 index 0000000..07018a6 --- /dev/null +++ b/Editor/Scripts/Model/ExecutionData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0de823dd61571ed518a847279c9d04a7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Scripts/Model/Orientation.cs b/Editor/Scripts/Model/Orientation.cs new file mode 100644 index 0000000..ae3905f --- /dev/null +++ b/Editor/Scripts/Model/Orientation.cs @@ -0,0 +1,8 @@ +namespace dev.klebersilva.tools.bitmapfontcreator +{ + internal enum Orientation + { + Horizontal, + Vertical, + } +} diff --git a/Editor/Scripts/Model/Orientation.cs.meta b/Editor/Scripts/Model/Orientation.cs.meta new file mode 100644 index 0000000..d685ef7 --- /dev/null +++ b/Editor/Scripts/Model/Orientation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a628876da94dd93aab529a6f59dd8b40 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Scripts/Model/PrefsModel.cs b/Editor/Scripts/Model/PrefsModel.cs index 1c09f18..252f00b 100644 --- a/Editor/Scripts/Model/PrefsModel.cs +++ b/Editor/Scripts/Model/PrefsModel.cs @@ -29,4 +29,4 @@ public static void Save(PrefsModel model) EditorPrefs.SetString(EditorPrefsKey, content); } } -} \ No newline at end of file +} diff --git a/Editor/Scripts/Model/RuntimeData.cs b/Editor/Scripts/Model/RuntimeData.cs new file mode 100644 index 0000000..a2fd299 --- /dev/null +++ b/Editor/Scripts/Model/RuntimeData.cs @@ -0,0 +1,18 @@ +using UnityEngine; + +namespace dev.klebersilva.tools.bitmapfontcreator +{ + // [CreateAssetMenu(fileName = "RuntimeData", menuName = "RuntimeData", order = 0)] + internal class RuntimeData : ScriptableObject + { + private const string DataPath = "RuntimeData"; + public ExecutionData Data; + + public static RuntimeData Load() + { + var data = Resources.Load(DataPath); + data.Data ??= ExecutionData.Default; + return data; + } + } +} diff --git a/Editor/Scripts/Model/RuntimeData.cs.meta b/Editor/Scripts/Model/RuntimeData.cs.meta new file mode 100644 index 0000000..f27abc2 --- /dev/null +++ b/Editor/Scripts/Model/RuntimeData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c4647d479c338325f9328893d838e266 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Scripts/Model/Settings/Profile.cs b/Editor/Scripts/Model/Settings/Profile.cs index 76eaf74..b539b1e 100644 --- a/Editor/Scripts/Model/Settings/Profile.cs +++ b/Editor/Scripts/Model/Settings/Profile.cs @@ -3,12 +3,12 @@ namespace dev.klebersilva.tools.bitmapfontcreator { [Serializable] - internal class Profile : BitmapFontCreatorData + internal class Profile : BitmapFontCreatorModel { public string Name; public Profile() { } - public Profile(string name, BitmapFontCreatorData src) + public Profile(string name, BitmapFontCreatorModel src) { Name = name; src?.CopyTo(this); diff --git a/Editor/Scripts/UI/BitmapFontCreatorEditor.cs b/Editor/Scripts/UI/BitmapFontCreatorEditor.cs index 0d82440..71dbc68 100644 --- a/Editor/Scripts/UI/BitmapFontCreatorEditor.cs +++ b/Editor/Scripts/UI/BitmapFontCreatorEditor.cs @@ -3,11 +3,11 @@ namespace dev.klebersilva.tools.bitmapfontcreator { - public class BitmapFontCreatorEditor : EditorWindow + public partial class BitmapFontCreatorEditor : EditorWindow { public const string MenuItemPath = "Window/Text/Bitmap Font Creator"; - private readonly ExecutionData _data = ExecutionData.Default; + private ExecutionData _data; private CharacterPropsList _customCharPropsList; private ProfilesView _profilesView; private PrefsView _prefsView; @@ -16,10 +16,11 @@ public class BitmapFontCreatorEditor : EditorWindow private Vector2 _charactersScrollPos = Vector2.zero; private Vector2 _mainScrollPos = Vector2.zero; - private int _selectedCharacterSetIndex = 0; private string _error = string.Empty; private bool _showPreview = false; - + private bool _textureGroupFoldout = true; + private bool _fontGroupFoldout = true; + private bool _charGroupFoldout = true; private Vector2Int _guessRowsColsCache; [MenuItem(MenuItemPath)] @@ -39,38 +40,33 @@ public static void ShowWindow() private void Setup() { + _data = RuntimeData.Load().Data; _settings = Settings.Load(); _prefs = PrefsModel.Load(); - _settings.Profiles.Selected?.CopyTo(_data); - _customCharPropsList = new CharacterPropsList(_data.CustomCharacterProps); - _profilesView = new ProfilesView(_data, _settings.Profiles, _prefs); - _prefsView = new PrefsView(_prefs); - } + if (!Application.isPlaying) + _settings.Profiles.Selected?.CopyTo(_data); - private bool _textureGroupFoldout = true; - private bool _fontGroupFoldout = true; - private bool _charGroupFoldout = true; + SetupBottomMenu(_data, _settings.Profiles, _prefs); + } private void OnGUI() { -#if BITMAP_FONT_CREATOR_DEV if (_customCharPropsList == null) Setup(); -#endif EditorGUIUtility.labelWidth = 120; _mainScrollPos = GUILayout.BeginScrollView(_mainScrollPos, false, false, GUIStyle.none, GUI.skin.verticalScrollbar, GUILayout.ExpandHeight(true)); GUILayout.BeginVertical(); - _textureGroupFoldout = EditorGUILayout.BeginFoldoutHeaderGroup(_textureGroupFoldout, UI.TextureGroupTitle, Styles.GroupTitle); + _textureGroupFoldout = EditorGUILayout.BeginFoldoutHeaderGroup(_textureGroupFoldout, UIContent.TextureGroupTitle, Styles.GroupTitle); if (_textureGroupFoldout) DrawTextureGroup(); EditorGUILayout.EndFoldoutHeaderGroup(); - _fontGroupFoldout = EditorGUILayout.BeginFoldoutHeaderGroup(_fontGroupFoldout, UI.FontGroupTitle, Styles.GroupTitle); + _fontGroupFoldout = EditorGUILayout.BeginFoldoutHeaderGroup(_fontGroupFoldout, UIContent.FontGroupTitle, Styles.GroupTitle); if (_fontGroupFoldout) DrawFontInfoGroup(); EditorGUILayout.EndFoldoutHeaderGroup(); - _charGroupFoldout = EditorGUILayout.BeginFoldoutHeaderGroup(_charGroupFoldout, UI.CharactersGroupTitle, Styles.GroupTitle); + _charGroupFoldout = EditorGUILayout.BeginFoldoutHeaderGroup(_charGroupFoldout, UIContent.CharactersGroupTitle, Styles.GroupTitle); if (_charGroupFoldout) DrawCharacterGroup(); EditorGUILayout.EndFoldoutHeaderGroup(); @@ -86,161 +82,18 @@ private void OnGUI() if (_showPreview) TexturePreviewPopup.Open(_data, _prefs); } - #region Texture Group - - private void DrawTextureGroup() - { - EditorGUILayout.BeginVertical(Styles.Group); - - DrawTextureField(); - _data.Cols = UIUtils.IntFieldMin(UI.Cols, _data.Cols, 1); - _data.Rows = UIUtils.IntFieldMin(UI.Rows, _data.Rows, 1); - - GUILayout.BeginHorizontal(); - GUILayout.FlexibleSpace(); - if (GUILayout.Button(UI.GuessRowsAndColsButton, Styles.MiniButton)) GuessRowsAndCols(); - _showPreview = DrawPreviewButton(); - GUILayout.EndHorizontal(); - - EditorGUILayout.Space(); - _data.Orientation = (Orientation)EditorGUILayout.EnumPopup(UI.Orientation, _data.Orientation); - _data.AlphaThreshold = EditorGUILayout.Slider(UI.AlphaThreshold, _data.AlphaThreshold, 0f, 1f); - - EditorGUILayout.EndVertical(); - } - - private void DrawTextureField() - { - EditorGUI.BeginChangeCheck(); - _data.Texture = EditorGUILayout.ObjectField(UI.TextureLabel, _data.Texture, typeof(Texture2D), false) as Texture2D; - if (EditorGUI.EndChangeCheck()) _guessRowsColsCache = Vector2Int.zero; - } - - private bool DrawPreviewButton() - { - GUI.enabled = _data.Texture != null && _data.Rows > 0 && _data.Cols > 0; - var value = GUILayout.Button(UI.PreviewButton, Styles.MiniButton); - GUI.enabled = true; - return value; - } - - #endregion - - #region Font Group - - private void DrawFontInfoGroup() - { - EditorGUILayout.BeginVertical(Styles.Group); - - _data.FontSize = UIUtils.FloatFieldWithAuto(UI.FontSize, _data.FontSize, UI.AutoFontSize, ref _data.AutoFontSize); - _data.LineSpacing = UIUtils.FloatFieldWithAuto(UI.LineSpacing, _data.LineSpacing, UI.AutoLineSpacing, ref _data.AutoLineSpacing); - _data.Ascent = UIUtils.FloatFieldMin(UI.Ascent, _data.Ascent, 0f); - _data.Descent = UIUtils.FloatFieldMin(UI.Descent, _data.Descent, 0f); - _data.Monospaced = EditorGUILayout.Toggle(UI.Monospaced, _data.Monospaced); - - EditorGUILayout.EndVertical(); - } - - #endregion - - #region Character Group - - private void DrawCharacterGroup() - { - EditorGUILayout.BeginVertical(Styles.Group); - - _data.CaseInsentive = EditorGUILayout.Toggle(UI.CaseInsentive, _data.CaseInsentive); - _data.DefaultCharacterSpacing = EditorGUILayout.IntField(UI.DefaultCharacterSpacing, _data.DefaultCharacterSpacing); - - DrawCharacterSetDropDown(); - - EditorGUILayout.Space(); - DrawCharactersField(); - - EditorGUILayout.Space(); - GUILayout.Label(UI.CustomCharacterProperties, Styles.HeaderLabel); - _customCharPropsList.DoLayoutList(); - - EditorGUILayout.EndVertical(); - } - - private void DrawCharacterSetDropDown() - { - _selectedCharacterSetIndex = EditorGUILayout.Popup(UI.CharacterSet, _selectedCharacterSetIndex, CharacterSets.Names); - if (!GUI.changed) return; - if (_selectedCharacterSetIndex == 0) return; - _data.Characters = CharacterSets.Characters[_selectedCharacterSetIndex]; - } - - private void DrawCharactersField() - { - GUILayout.BeginHorizontal(); - GUILayout.Label(UI.Characters, Styles.HeaderLabel); - GUILayout.FlexibleSpace(); - GUILayout.Label(_data.ValidCharactersCount.ToString(), _data.ValidCharactersCount == _data.Cols * _data.Rows ? Styles.CounterLabelRight : Styles.CounterLabelWrong); - GUILayout.EndHorizontal(); - - _charactersScrollPos = GUILayout.BeginScrollView(_charactersScrollPos, false, false, GUIStyle.none, GUI.skin.verticalScrollbar, GUILayout.Height(100)); - - EditorGUI.BeginChangeCheck(); - _data.Characters = GUILayout.TextArea(_data.Characters, Styles.CharactersField); - if (EditorGUI.EndChangeCheck()) - _selectedCharacterSetIndex = 0; - - GUILayout.EndScrollView(); - } - - #endregion - private void DrawCreateFontButton() { GUI.color = Color.cyan; - if (UIUtils.CenteredButton(UI.CreateButton, Styles.CreateButton)) + if (UIUtils.CenteredButton(UIContent.CreateButton, Styles.CreateButton)) BitmapFontCreator.TryCreateFont(_data, _prefsView.Model.WarnOnReplaceFont, out _error); GUI.color = Color.white; } - private void DrawBottomMenu() - { - GUILayout.BeginHorizontal(Styles.BottomMenu); - _profilesView.Draw(); - if (GUILayout.Button(UI.RollbackButton, Styles.RollbackButton)) - RollbackSettings(); - GUILayout.FlexibleSpace(); - _prefsView.Draw(); - GUILayout.EndHorizontal(); - } - - #region Actions - private void ShowCurrentError() { Debug.LogError(_error); _error = null; } - - private void RollbackSettings() - { - var profile = (BitmapFontCreatorData)_settings.Profiles.Selected ?? ExecutionData.Default; - profile.CopyTo(_data); - } - - private void GuessRowsAndCols() - { - if (_data.Texture == null) - { - Debug.LogWarning("Texture cannot be null"); - return; - } - - _guessRowsColsCache = _guessRowsColsCache.x == 0 || _guessRowsColsCache.y == 0 - ? BitmapFontCreator.GuessRowsAndCols(_data.Texture) - : _guessRowsColsCache; - - _data.Cols = _guessRowsColsCache.y; - _data.Rows = _guessRowsColsCache.x; - } - - #endregion } } diff --git a/Editor/Scripts/UI/Components.meta b/Editor/Scripts/UI/Components.meta new file mode 100644 index 0000000..9e93687 --- /dev/null +++ b/Editor/Scripts/UI/Components.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5105333bf89adb262897b873d14ef122 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Scripts/UI/CharacterPropsList.cs b/Editor/Scripts/UI/Components/CharacterPropsList.cs similarity index 91% rename from Editor/Scripts/UI/CharacterPropsList.cs rename to Editor/Scripts/UI/Components/CharacterPropsList.cs index a2b8b0d..71f0c7c 100644 --- a/Editor/Scripts/UI/CharacterPropsList.cs +++ b/Editor/Scripts/UI/Components/CharacterPropsList.cs @@ -24,15 +24,15 @@ private void ListDrawHeader(Rect rect) var w = rect.width - padding; rect.width = widths[0] * w; - GUI.Label(rect, UI.CustomCharacter); + GUI.Label(rect, UIContent.CustomCharacter); rect.x += rect.width + spacing; rect.width = widths[1] * w; - GUI.Label(rect, UI.CustomSpacing); + GUI.Label(rect, UIContent.CustomSpacing); rect.x += rect.width + spacing; rect.width = widths[2] * w; - GUI.Label(rect, UI.CustomPadding); + GUI.Label(rect, UIContent.CustomPadding); } private void ListDrawElement(Rect rect, int index, bool isActive, bool isFocused) diff --git a/Editor/Scripts/UI/CharacterPropsList.cs.meta b/Editor/Scripts/UI/Components/CharacterPropsList.cs.meta similarity index 100% rename from Editor/Scripts/UI/CharacterPropsList.cs.meta rename to Editor/Scripts/UI/Components/CharacterPropsList.cs.meta diff --git a/Editor/Scripts/UI/PrefsView.cs b/Editor/Scripts/UI/Components/PrefsView.cs similarity index 68% rename from Editor/Scripts/UI/PrefsView.cs rename to Editor/Scripts/UI/Components/PrefsView.cs index 533516a..c62390e 100644 --- a/Editor/Scripts/UI/PrefsView.cs +++ b/Editor/Scripts/UI/Components/PrefsView.cs @@ -13,7 +13,7 @@ internal class PrefsView public void Draw() { - if (GUILayout.Button(UI.PreferencesButton, Styles.PreferencesButton)) PopupWindow.Show(_buttonRect, new PrefsPopup(_model)); + if (GUILayout.Button(UIContent.PreferencesButton, Styles.PreferencesButton)) PopupWindow.Show(_buttonRect, new PrefsPopup(_model)); if (Event.current.type == EventType.Repaint) _buttonRect = GUILayoutUtility.GetLastRect(); } } @@ -36,18 +36,18 @@ internal class PrefsPopup : PopupWindowContent public override void OnGUI(Rect rect) { rect.height = _headerHeight; - GUI.Label(rect, UI.PreferencesLabel, Styles.SectionLabel); + GUI.Label(rect, UIContent.PreferencesLabel, Styles.SectionLabel); rect.x += _padding.left; rect.y += _padding.top + rect.height; rect.height = EditorGUIUtility.singleLineHeight; - _model.WarnOnReplaceFont = EditorGUI.ToggleLeft(rect, UI.WarnOnReplaceFont, _model.WarnOnReplaceFont); + _model.WarnOnReplaceFont = EditorGUI.ToggleLeft(rect, UIContent.WarnOnReplaceFont, _model.WarnOnReplaceFont); rect.y += rect.height; - _model.WarnOnReplaceSettings = EditorGUI.ToggleLeft(rect, UI.WarnOnReplaceSettings, _model.WarnOnReplaceSettings); + _model.WarnOnReplaceSettings = EditorGUI.ToggleLeft(rect, UIContent.WarnOnReplaceSettings, _model.WarnOnReplaceSettings); rect.y += rect.height; - _model.WarnOnReplaceProfile = EditorGUI.ToggleLeft(rect, UI.WarnOnReplaceProfile, _model.WarnOnReplaceProfile); + _model.WarnOnReplaceProfile = EditorGUI.ToggleLeft(rect, UIContent.WarnOnReplaceProfile, _model.WarnOnReplaceProfile); } public override void OnClose() diff --git a/Editor/Scripts/UI/PrefsView.cs.meta b/Editor/Scripts/UI/Components/PrefsView.cs.meta similarity index 100% rename from Editor/Scripts/UI/PrefsView.cs.meta rename to Editor/Scripts/UI/Components/PrefsView.cs.meta diff --git a/Editor/Scripts/UI/ProfilesView.cs b/Editor/Scripts/UI/Components/ProfilesView.cs similarity index 95% rename from Editor/Scripts/UI/ProfilesView.cs rename to Editor/Scripts/UI/Components/ProfilesView.cs index a33a5aa..001fbca 100644 --- a/Editor/Scripts/UI/ProfilesView.cs +++ b/Editor/Scripts/UI/Components/ProfilesView.cs @@ -10,14 +10,14 @@ internal class ProfilesView private const string SaveProfileOption = "Save Profile"; private const string DeleteProfileOption = "Delete Profile"; - private readonly BitmapFontCreatorData _editorData; + private readonly BitmapFontCreatorModel _editorData; private readonly ProfileList _profiles; private readonly PrefsModel _prefs; private string[] _options; private int _optionIndex = 0; - public ProfilesView(BitmapFontCreatorData editorData, ProfileList profiles, PrefsModel prefs) + public ProfilesView(BitmapFontCreatorModel editorData, ProfileList profiles, PrefsModel prefs) { _editorData = editorData; _profiles = profiles; diff --git a/Editor/Scripts/UI/ProfilesView.cs.meta b/Editor/Scripts/UI/Components/ProfilesView.cs.meta similarity index 100% rename from Editor/Scripts/UI/ProfilesView.cs.meta rename to Editor/Scripts/UI/Components/ProfilesView.cs.meta diff --git a/Editor/Scripts/UI/TexturePreviewPopup.cs b/Editor/Scripts/UI/Components/TexturePreviewPopup.cs similarity index 88% rename from Editor/Scripts/UI/TexturePreviewPopup.cs rename to Editor/Scripts/UI/Components/TexturePreviewPopup.cs index ff2bc22..aa74a15 100644 --- a/Editor/Scripts/UI/TexturePreviewPopup.cs +++ b/Editor/Scripts/UI/Components/TexturePreviewPopup.cs @@ -32,7 +32,7 @@ private void DoOpen(ExecutionData data, PrefsModel prefs) private void OnGUI() { if (_data.Texture != null && _data.Rows > 0 && _data.Cols > 0) DrawContent(); - else GUILayout.Label(UI.NoContent, Styles.CenterLabel); + else GUILayout.Label(UIContent.NoContent, Styles.CenterLabel); } private void DrawContent() @@ -47,18 +47,18 @@ private void DrawTopBar() GUILayout.FlexibleSpace(); _prefs.GridColor = EditorGUILayout.ColorField(GUIContent.none, _prefs.GridColor, false, true, false, GUILayout.Width(24)); - GUILayout.Label(UI.GridColorLabel, Styles.ToolbarLabel); + GUILayout.Label(UIContent.GridColorLabel, Styles.ToolbarLabel); _prefs.HeightColor = EditorGUILayout.ColorField(GUIContent.none, _prefs.HeightColor, false, true, false, GUILayout.Width(24)); - GUILayout.Label(UI.HeightColorLabel, Styles.ToolbarLabel); + GUILayout.Label(UIContent.HeightColorLabel, Styles.ToolbarLabel); _prefs.BaselineColor = EditorGUILayout.ColorField(GUIContent.none, _prefs.BaselineColor, false, true, false, GUILayout.Width(24)); - GUILayout.Label(UI.BaselineColorLabel, Styles.ToolbarLabel); + GUILayout.Label(UIContent.BaselineColorLabel, Styles.ToolbarLabel); GUILayout.Space(10); var selection = GUILayout.Toggle( _prefs.TextureBackground == 0, - _prefs.TextureBackground == 0 ? UI.DarkTextureIcon : UI.LightTextureIcon, + _prefs.TextureBackground == 0 ? UIContent.DarkTextureIcon : UIContent.LightTextureIcon, Styles.BackgroundTextureIcon); _prefs.TextureBackground = selection ? 0 : 1; @@ -86,7 +86,7 @@ private void DrawTexture(float y) _scrollPos = GUI.BeginScrollView(scrollRect, _scrollPos, scrollContentRect); GUI.DrawTextureWithTexCoords(textureRect, - _prefs.TextureBackground == 0 ? UI.GridDarkTexture : UI.GridLightTexture, + _prefs.TextureBackground == 0 ? Styles.GridDarkTexture : Styles.GridLightTexture, new Rect(0, 0, textureRect.width / _gridTexSize, textureRect.height / _gridTexSize), true); GUI.DrawTexture(textureRect, _data.Texture, ScaleMode.ScaleToFit, true); DrawGrid(textureRect, _data.Ascent, _data.Descent, ratio); diff --git a/Editor/Scripts/UI/TexturePreviewPopup.cs.meta b/Editor/Scripts/UI/Components/TexturePreviewPopup.cs.meta similarity index 100% rename from Editor/Scripts/UI/TexturePreviewPopup.cs.meta rename to Editor/Scripts/UI/Components/TexturePreviewPopup.cs.meta diff --git a/Editor/Scripts/UI/Partials.meta b/Editor/Scripts/UI/Partials.meta new file mode 100644 index 0000000..6ea09da --- /dev/null +++ b/Editor/Scripts/UI/Partials.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 680edeb885049c665b5ea32db5f91b41 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Scripts/UI/Partials/BottomMenu.cs b/Editor/Scripts/UI/Partials/BottomMenu.cs new file mode 100644 index 0000000..f1ca40e --- /dev/null +++ b/Editor/Scripts/UI/Partials/BottomMenu.cs @@ -0,0 +1,43 @@ +using UnityEngine; + +namespace dev.klebersilva.tools.bitmapfontcreator +{ + public partial class BitmapFontCreatorEditor + { + + private void SetupBottomMenu(ExecutionData data, ProfileList profiles, PrefsModel prefs) + { + _customCharPropsList = new CharacterPropsList(data.CustomCharacterProps); + _profilesView = new ProfilesView(data, profiles, prefs); + _prefsView = new PrefsView(prefs); + } + + private void DrawBottomMenu() + { + GUILayout.BeginHorizontal(Styles.BottomMenu); + _profilesView.Draw(); + + if (GUILayout.Button(UIContent.RollbackButton, Styles.ToolbarButton)) + RollbackSettings(); + + if (GUILayout.Button(UIContent.DefaultButton, Styles.ToolbarButton)) + ClearSettings(); + + GUILayout.FlexibleSpace(); + + _prefsView.Draw(); + GUILayout.EndHorizontal(); + } + + private void RollbackSettings() + { + var profile = (BitmapFontCreatorModel)_settings.Profiles.Selected ?? ExecutionData.Default; + profile.CopyTo(_data); + } + + private void ClearSettings() + { + ExecutionData.Default.CopyTo(_data); + } + } +} diff --git a/Editor/Scripts/UI/Partials/BottomMenu.cs.meta b/Editor/Scripts/UI/Partials/BottomMenu.cs.meta new file mode 100644 index 0000000..91aded0 --- /dev/null +++ b/Editor/Scripts/UI/Partials/BottomMenu.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f41e54ab020804775ae80514c2b64fc1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Scripts/UI/Partials/CharacterGroup.cs b/Editor/Scripts/UI/Partials/CharacterGroup.cs new file mode 100644 index 0000000..d0aa4c2 --- /dev/null +++ b/Editor/Scripts/UI/Partials/CharacterGroup.cs @@ -0,0 +1,55 @@ +using UnityEditor; +using UnityEngine; + +namespace dev.klebersilva.tools.bitmapfontcreator +{ + public partial class BitmapFontCreatorEditor + { + private int _selectedCharacterSetIndex = 0; + + private void DrawCharacterGroup() + { + EditorGUILayout.BeginVertical(Styles.Group); + + _data.CaseInsentive = EditorGUILayout.Toggle(UIContent.CaseInsentive, _data.CaseInsentive); + _data.DefaultCharacterSpacing = EditorGUILayout.IntField(UIContent.DefaultCharacterSpacing, _data.DefaultCharacterSpacing); + + DrawCharacterSetDropDown(); + + EditorGUILayout.Space(); + DrawCharactersField(); + + EditorGUILayout.Space(); + GUILayout.Label(UIContent.CustomCharacterProperties, Styles.HeaderLabel); + _customCharPropsList.DoLayoutList(); + + EditorGUILayout.EndVertical(); + } + + private void DrawCharacterSetDropDown() + { + _selectedCharacterSetIndex = EditorGUILayout.Popup(UIContent.CharacterSet, _selectedCharacterSetIndex, CharacterSets.Names); + if (!GUI.changed) return; + if (_selectedCharacterSetIndex == 0) return; + _data.Characters = CharacterSets.Characters[_selectedCharacterSetIndex]; + } + + private void DrawCharactersField() + { + GUILayout.BeginHorizontal(); + GUILayout.Label(UIContent.Characters, Styles.HeaderLabel); + GUILayout.FlexibleSpace(); + GUILayout.Label(_data.ValidCharactersCount.ToString(), _data.ValidCharactersCount == _data.Cols * _data.Rows ? Styles.CounterLabelRight : Styles.CounterLabelWrong); + GUILayout.EndHorizontal(); + + _charactersScrollPos = GUILayout.BeginScrollView(_charactersScrollPos, false, false, GUIStyle.none, GUI.skin.verticalScrollbar, GUILayout.Height(100)); + + EditorGUI.BeginChangeCheck(); + _data.Characters = GUILayout.TextArea(_data.Characters, Styles.CharactersField); + if (EditorGUI.EndChangeCheck()) + _selectedCharacterSetIndex = 0; + + GUILayout.EndScrollView(); + } + } +} \ No newline at end of file diff --git a/Editor/Scripts/UI/Partials/CharacterGroup.cs.meta b/Editor/Scripts/UI/Partials/CharacterGroup.cs.meta new file mode 100644 index 0000000..5319101 --- /dev/null +++ b/Editor/Scripts/UI/Partials/CharacterGroup.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 21faaa340b3f1e53ab28edc48d115804 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Scripts/UI/Partials/FontGroup.cs b/Editor/Scripts/UI/Partials/FontGroup.cs new file mode 100644 index 0000000..5004082 --- /dev/null +++ b/Editor/Scripts/UI/Partials/FontGroup.cs @@ -0,0 +1,20 @@ +using UnityEditor; + +namespace dev.klebersilva.tools.bitmapfontcreator +{ + public partial class BitmapFontCreatorEditor + { + private void DrawFontInfoGroup() + { + EditorGUILayout.BeginVertical(Styles.Group); + + _data.FontSize = UIUtils.FloatFieldWithAuto(UIContent.FontSize, _data.FontSize, UIContent.AutoFontSize, ref _data.AutoFontSize); + _data.LineSpacing = UIUtils.FloatFieldWithAuto(UIContent.LineSpacing, _data.LineSpacing, UIContent.AutoLineSpacing, ref _data.AutoLineSpacing); + _data.Ascent = UIUtils.FloatFieldMin(UIContent.Ascent, _data.Ascent, 0f); + _data.Descent = UIUtils.FloatFieldMin(UIContent.Descent, _data.Descent, 0f); + _data.Monospaced = EditorGUILayout.Toggle(UIContent.Monospaced, _data.Monospaced); + + EditorGUILayout.EndVertical(); + } + } +} diff --git a/Editor/Scripts/UI/Partials/FontGroup.cs.meta b/Editor/Scripts/UI/Partials/FontGroup.cs.meta new file mode 100644 index 0000000..8a3b935 --- /dev/null +++ b/Editor/Scripts/UI/Partials/FontGroup.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0454552e63788fa49bcde8853cbc553a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Scripts/UI/Partials/TextureGroup.cs b/Editor/Scripts/UI/Partials/TextureGroup.cs new file mode 100644 index 0000000..624c6a5 --- /dev/null +++ b/Editor/Scripts/UI/Partials/TextureGroup.cs @@ -0,0 +1,60 @@ +using UnityEditor; +using UnityEngine; + +namespace dev.klebersilva.tools.bitmapfontcreator +{ + public partial class BitmapFontCreatorEditor + { + private void DrawTextureGroup() + { + EditorGUILayout.BeginVertical(Styles.Group); + + DrawTextureField(); + _data.Cols = UIUtils.IntFieldMin(UIContent.Cols, _data.Cols, 1); + _data.Rows = UIUtils.IntFieldMin(UIContent.Rows, _data.Rows, 1); + + GUILayout.BeginHorizontal(); + GUILayout.FlexibleSpace(); + if (GUILayout.Button(UIContent.GuessRowsAndColsButton, Styles.MiniButton)) GuessRowsAndCols(); + _showPreview = DrawPreviewButton(); + GUILayout.EndHorizontal(); + + EditorGUILayout.Space(); + _data.Orientation = (Orientation)EditorGUILayout.EnumPopup(UIContent.Orientation, _data.Orientation); + _data.AlphaThreshold = EditorGUILayout.Slider(UIContent.AlphaThreshold, _data.AlphaThreshold, 0f, 1f); + + EditorGUILayout.EndVertical(); + } + + private void DrawTextureField() + { + EditorGUI.BeginChangeCheck(); + _data.Texture = EditorGUILayout.ObjectField(UIContent.TextureLabel, _data.Texture, typeof(Texture2D), false) as Texture2D; + if (EditorGUI.EndChangeCheck()) _guessRowsColsCache = Vector2Int.zero; + } + + private bool DrawPreviewButton() + { + GUI.enabled = _data.Texture != null && _data.Rows > 0 && _data.Cols > 0; + var value = GUILayout.Button(UIContent.PreviewButton, Styles.MiniButton); + GUI.enabled = true; + return value; + } + + private void GuessRowsAndCols() + { + if (_data.Texture == null) + { + Debug.LogWarning("Texture cannot be null"); + return; + } + + _guessRowsColsCache = _guessRowsColsCache.x == 0 || _guessRowsColsCache.y == 0 + ? BitmapFontCreator.GuessRowsAndCols(_data.Texture) + : _guessRowsColsCache; + + _data.Cols = _guessRowsColsCache.y; + _data.Rows = _guessRowsColsCache.x; + } + } +} diff --git a/Editor/Scripts/UI/Partials/TextureGroup.cs.meta b/Editor/Scripts/UI/Partials/TextureGroup.cs.meta new file mode 100644 index 0000000..c806e23 --- /dev/null +++ b/Editor/Scripts/UI/Partials/TextureGroup.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b94acb0f451fb5cd7a2bb49d255a8914 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Scripts/SettingsEditor.cs b/Editor/Scripts/UI/SettingsEditor.cs similarity index 100% rename from Editor/Scripts/SettingsEditor.cs rename to Editor/Scripts/UI/SettingsEditor.cs diff --git a/Editor/Scripts/SettingsEditor.cs.meta b/Editor/Scripts/UI/SettingsEditor.cs.meta similarity index 100% rename from Editor/Scripts/SettingsEditor.cs.meta rename to Editor/Scripts/UI/SettingsEditor.cs.meta diff --git a/Editor/Scripts/UI/UIModel.cs b/Editor/Scripts/UI/UIModel.cs deleted file mode 100644 index 3790a35..0000000 --- a/Editor/Scripts/UI/UIModel.cs +++ /dev/null @@ -1,228 +0,0 @@ -using UnityEditor; -using UnityEngine; - -namespace dev.klebersilva.tools.bitmapfontcreator -{ - internal static class CharacterSets - { - public static readonly string[] Names = new[] { - "Custom", - "ASCII", - "ASCII Lowercase", - "ASCII Uppercase", - "Numbers", - }; - public static readonly string[] Characters = new[] { - null, - "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", - "!\"#$%&'()*+,-./0123456789:;<=>?@[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", - "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`{|}~", - "0123456789.,-+", - }; - } - - internal static class UI - { - public static readonly Font MonospacedFont = Resources.Load("Fonts/monospaced"); - public static readonly Texture2D GridDarkTexture = Resources.Load("Textures/grid-dark"); - public static readonly Texture2D GridLightTexture = Resources.Load("Textures/grid-light"); - - public static readonly GUIContent TextureGroupTitle = new("Texture Properties"); - public static readonly GUIContent FontGroupTitle = new("Font Properties"); - public static readonly GUIContent CharactersGroupTitle = new("Characters"); - - public static readonly GUIContent TextureLabel = new("Texture", "Texture used for the font"); - public static readonly GUIContent Orientation = new("Orientation", "Order to look up for characters in the texture"); - public static readonly GUIContent Cols = new("Cols", "Number of columns in the texture"); - public static readonly GUIContent Rows = new("Rows", "Number of rows in the texture"); - public static readonly GUIContent GuessRowsAndColsButton = new("Guess", "Guess the number of rows and columns of the texture based on transparency gaps"); - public static readonly GUIContent PreviewButton = new("Preview", "Preview the texture with current rows and cols"); - public static readonly GUIContent AlphaThreshold = new("Alpha Threshold", "Alpha threshold to identify characters bounds"); - public static readonly GUIContent Monospaced = new("Monospaced", "Whether the result font should be monospaced"); - public static readonly GUIContent CaseInsentive = new("Case Insentive", "Whether the characters for lowercase and uppercase are the same"); - public static readonly GUIContent Ascent = new("Ascent", "Font ascent. It's the part of the glyphs that should be above the baseline"); - public static readonly GUIContent Descent = new("Descent", "Font descent. It's the part of the glyphs that should be below the baseline"); - public static readonly GUIContent FontSize = new("Font Size", "Base font size in pixels"); - public static readonly GUIContent AutoFontSize = new("Auto", "Automatically calculate the font size based on ascent property or cell size"); - public static readonly GUIContent LineSpacing = new("Line Spacing", "Vertical spacing between lines"); - public static readonly GUIContent AutoLineSpacing = new("Auto", "Automatically calculate the line spacing based on cell height"); - public static readonly GUIContent CharacterSet = new("Character Set", "Predefined character set to use"); - public static readonly GUIContent Characters = new("Characters", "Characters used in the font in order they appear in the texture. Use the space character to represent blank spaces in the texture"); - public static readonly GUIContent DefaultCharacterSpacing = new("Character Spacing", "Default spacing between characters"); - public static readonly GUIContent CustomCharacterProperties = new("Custom Character Properties", "Custom properties for each characters, if any"); - public static readonly GUIContent CustomCharacter = new("Char", "Character to apply the properties"); - public static readonly GUIContent CustomSpacing = new("Spacing", "Horizontal spacing after the character (advance). Ignored if font is monospaced"); - public static readonly GUIContent CustomPadding = new("Padding", "Custom horizontal and vertical padding to add before the character"); - - public static readonly GUIContent CreateButton = new("Create", "Create font files"); - - public static readonly GUIContent RollbackButton = new("Rollback", "Rollback settings to the selected profile or default"); - public static readonly GUIContent PreferencesButton = new(string.Empty, "Preferences"); - public static readonly GUIContent PreferencesLabel = new("Preferences"); - public static readonly GUIContent WarnOnReplaceFont = new("Warn before replacing font files", "Warn before replacing an existing font. This will replace the old font keeping the references"); - public static readonly GUIContent WarnOnReplaceSettings = new("Warn before replacing settings", "Warn before replacing settings when selecting a profile"); - public static readonly GUIContent WarnOnReplaceProfile = new("Warn before replacing profile", "Warn before replacing an existing profile"); - - public static readonly GUIContent NoContent = new("Invalid texture", "There is no texture selected or the number of rows or columns are set to zero"); - public static readonly GUIContent GridColorLabel = new("Grid", "Color for the grid lines showing rows and columns"); - public static readonly GUIContent HeightColorLabel = new("Height", "Color for de glyph hight line (ascent + descent)"); - public static readonly GUIContent BaselineColorLabel = new("Baseline", "Color for the baseline (descent)"); - - public static readonly GUIContent DarkTextureIcon = new() { image = GridDarkTexture, }; - public static readonly GUIContent LightTextureIcon = new() { image = GridLightTexture }; - } - - internal static class Styles - { - public static readonly float AutoToggleWidth = 50f; - - public static readonly GUIStyle GroupTitle = new(EditorStyles.foldoutHeader) - { - margin = new(0, 0, 2, 2), - padding = new(18, 5, 10, 10), - }; - - public static readonly GUIStyle Group = new("hostview") - { - margin = new(), - padding = new(18, 5, 5, 20), - }; - - public static readonly GUIStyle HeaderLabel = new(EditorStyles.label) - { - margin = new(EditorStyles.label.margin.left, EditorStyles.label.margin.right, 5, 5), - }; - - public static readonly GUIStyle SectionLabel = new("ContentToolbar") - { - padding = new(5, 5, 5, 5), - fixedHeight = 25, - }; - - public static readonly GUIStyle CounterLabelRight = new(EditorStyles.label) - { - stretchHeight = true, - alignment = TextAnchor.LowerCenter, - fontStyle = FontStyle.Italic, - normal = new() - { - background = new GUIStyle("WinBtnMaxMac").normal.background, - textColor = EditorStyles.label.normal.textColor, - }, - imagePosition = ImagePosition.ImageLeft, - contentOffset = new Vector2(-17, 0), - }; - - public static readonly GUIStyle CounterLabelWrong = new(EditorStyles.label) - { - stretchHeight = true, - stretchWidth = true, - alignment = TextAnchor.LowerCenter, - fontStyle = FontStyle.Italic, - normal = new() - { - background = new GUIStyle("WinBtnCloseMac").normal.background, - textColor = EditorStyles.label.normal.textColor, - }, - imagePosition = ImagePosition.ImageLeft, - contentOffset = new Vector2(-17, 0), - }; - - - public static readonly GUIStyle CharactersField = new(EditorStyles.textArea) - { - font = UI.MonospacedFont, - stretchHeight = true, - normal = new() { textColor = Color.white }, - }; - - public static readonly GUIStyle CustomCharacterField = new(EditorStyles.textField) - { - font = UI.MonospacedFont, - }; - - public static readonly GUIStyle CreateButton = new(GUI.skin.button) - { - padding = new(20, 20, 7, 8), - margin = new(10, 10, 20, 20), - fixedHeight = 32, - }; - - public static readonly GUIStyle BottomMenu = new("DD Background") - { - padding = new(1, 1, 1, 1), - margin = new(), - }; - - public static readonly GUIStyle ProfilesButton = new("ToolbarPopupLeft"); - public static readonly GUIStyle RollbackButton = new("TE toolbarbutton") { padding = new(10, 6, 0, 0), }; - public static readonly GUIStyle PreferencesButton = new("PaneOptions") { margin = new(0, 0, 3, 0), }; - - public static readonly GUIStyle CenterLabel = new(GUI.skin.label) - { - stretchWidth = true, - stretchHeight = true, - alignment = TextAnchor.MiddleCenter, - }; - - public static readonly GUIStyle Toolbar = new("TimeAreaToolbar") { fixedHeight = 24, }; - public static readonly GUIStyle MiniButton = new(EditorStyles.miniButton) { fixedWidth = 66, }; - - public static readonly GUIStyle ToolbarLabel = new(EditorStyles.label) - { - margin = new(0, 20, 0, 0), - padding = new(0, 3, 0, 0), - alignment = TextAnchor.MiddleLeft, - stretchHeight = true, - }; - - public static readonly GUIStyle BackgroundTextureIcon = new("HelpBox") - { - padding = new(2, 2, 2, 2), - imagePosition = ImagePosition.ImageOnly, - fixedWidth = 20, - fixedHeight = 20, - }; - } - - internal static class UIUtils - { - public static float FloatFieldMin(GUIContent label, float value, float min) - { - EditorGUI.BeginChangeCheck(); - value = EditorGUILayout.FloatField(label, value); - if (EditorGUI.EndChangeCheck() && value < min) value = min; - return value; - } - - public static int IntFieldMin(GUIContent label, int value, int min) - { - EditorGUI.BeginChangeCheck(); - value = EditorGUILayout.IntField(label, value); - if (EditorGUI.EndChangeCheck() && value < min) value = min; - return value; - } - - public static float FloatFieldWithAuto(GUIContent label, float value, GUIContent autoLabel, ref bool auto) - { - GUILayout.BeginHorizontal(); - GUI.enabled = !auto; - value = EditorGUILayout.FloatField(label, value); - GUI.enabled = true; - - auto = EditorGUILayout.ToggleLeft(autoLabel, auto, GUILayout.Width(Styles.AutoToggleWidth)); - GUILayout.EndHorizontal(); - return value; - } - - public static bool CenteredButton(GUIContent label, GUIStyle style = null) - { - GUILayout.BeginHorizontal(); - GUILayout.FlexibleSpace(); - var value = GUILayout.Button(label, style ?? GUI.skin.button); - GUILayout.FlexibleSpace(); - GUILayout.EndHorizontal(); - return value; - } - } -} diff --git a/Editor/Scripts/UI/Util/CharacterSets.cs b/Editor/Scripts/UI/Util/CharacterSets.cs new file mode 100644 index 0000000..70f6003 --- /dev/null +++ b/Editor/Scripts/UI/Util/CharacterSets.cs @@ -0,0 +1,20 @@ +namespace dev.klebersilva.tools.bitmapfontcreator +{ + internal static class CharacterSets + { + public static readonly string[] Names = new[] { + "Custom", + "ASCII", + "ASCII Lowercase", + "ASCII Uppercase", + "Numbers", + }; + public static readonly string[] Characters = new[] { + null, + "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", + "!\"#$%&'()*+,-./0123456789:;<=>?@[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", + "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`{|}~", + "0123456789.,-+", + }; + } +} diff --git a/Editor/Scripts/UI/Util/CharacterSets.cs.meta b/Editor/Scripts/UI/Util/CharacterSets.cs.meta new file mode 100644 index 0000000..b1b05ef --- /dev/null +++ b/Editor/Scripts/UI/Util/CharacterSets.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c059c797f705253e48b6e5afa8958cd4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Scripts/UI/Util/Styles.cs b/Editor/Scripts/UI/Util/Styles.cs new file mode 100644 index 0000000..7871c90 --- /dev/null +++ b/Editor/Scripts/UI/Util/Styles.cs @@ -0,0 +1,122 @@ +using UnityEditor; +using UnityEngine; + +namespace dev.klebersilva.tools.bitmapfontcreator +{ + internal static class Styles + { + public static readonly float AutoToggleWidth = 50f; + + public static readonly Font MonospacedFont = Resources.Load("Fonts/monospaced"); + public static readonly Texture2D GridDarkTexture = Resources.Load("Textures/grid-dark"); + public static readonly Texture2D GridLightTexture = Resources.Load("Textures/grid-light"); + + public static readonly GUIStyle GroupTitle = new(EditorStyles.foldoutHeader) + { + margin = new(0, 0, 2, 2), + padding = new(18, 5, 10, 10), + }; + + public static readonly GUIStyle Group = new("hostview") + { + margin = new(), + padding = new(18, 5, 5, 20), + }; + + public static readonly GUIStyle HeaderLabel = new(EditorStyles.label) + { + margin = new(EditorStyles.label.margin.left, EditorStyles.label.margin.right, 5, 5), + }; + + public static readonly GUIStyle SectionLabel = new("ContentToolbar") + { + padding = new(5, 5, 5, 5), + fixedHeight = 25, + }; + + public static readonly GUIStyle CounterLabelRight = new(EditorStyles.label) + { + stretchHeight = true, + alignment = TextAnchor.LowerCenter, + fontStyle = FontStyle.Italic, + normal = new() + { + background = new GUIStyle("WinBtnMaxMac").normal.background, + textColor = EditorStyles.label.normal.textColor, + }, + imagePosition = ImagePosition.ImageLeft, + contentOffset = new Vector2(-17, 0), + }; + + public static readonly GUIStyle CounterLabelWrong = new(EditorStyles.label) + { + stretchHeight = true, + stretchWidth = true, + alignment = TextAnchor.LowerCenter, + fontStyle = FontStyle.Italic, + normal = new() + { + background = new GUIStyle("WinBtnCloseMac").normal.background, + textColor = EditorStyles.label.normal.textColor, + }, + imagePosition = ImagePosition.ImageLeft, + contentOffset = new Vector2(-17, 0), + }; + + + public static readonly GUIStyle CharactersField = new(EditorStyles.textArea) + { + font = MonospacedFont, + stretchHeight = true, + normal = new() { textColor = Color.white }, + }; + + public static readonly GUIStyle CustomCharacterField = new(EditorStyles.textField) + { + font = MonospacedFont, + }; + + public static readonly GUIStyle CreateButton = new(GUI.skin.button) + { + padding = new(20, 20, 7, 8), + margin = new(10, 10, 20, 20), + fixedHeight = 32, + }; + + public static readonly GUIStyle BottomMenu = new("DD Background") + { + padding = new(1, 1, 1, 1), + margin = new(), + }; + + public static readonly GUIStyle ProfilesButton = new("ToolbarPopupLeft"); + public static readonly GUIStyle ToolbarButton = new("TE toolbarbutton") { padding = new(10, 6, 0, 0), }; + public static readonly GUIStyle PreferencesButton = new("PaneOptions") { margin = new(0, 0, 3, 0), }; + + public static readonly GUIStyle CenterLabel = new(GUI.skin.label) + { + stretchWidth = true, + stretchHeight = true, + alignment = TextAnchor.MiddleCenter, + }; + + public static readonly GUIStyle Toolbar = new("TimeAreaToolbar") { fixedHeight = 24, }; + public static readonly GUIStyle MiniButton = new(EditorStyles.miniButton) { fixedWidth = 66, }; + + public static readonly GUIStyle ToolbarLabel = new(EditorStyles.label) + { + margin = new(0, 20, 0, 0), + padding = new(0, 3, 0, 0), + alignment = TextAnchor.MiddleLeft, + stretchHeight = true, + }; + + public static readonly GUIStyle BackgroundTextureIcon = new("HelpBox") + { + padding = new(2, 2, 2, 2), + imagePosition = ImagePosition.ImageOnly, + fixedWidth = 20, + fixedHeight = 20, + }; + } +} diff --git a/Editor/Scripts/UI/UIModel.cs.meta b/Editor/Scripts/UI/Util/Styles.cs.meta similarity index 100% rename from Editor/Scripts/UI/UIModel.cs.meta rename to Editor/Scripts/UI/Util/Styles.cs.meta diff --git a/Editor/Scripts/UI/Util/UIContent.cs b/Editor/Scripts/UI/Util/UIContent.cs new file mode 100644 index 0000000..42eb1cd --- /dev/null +++ b/Editor/Scripts/UI/Util/UIContent.cs @@ -0,0 +1,52 @@ +using UnityEngine; + +namespace dev.klebersilva.tools.bitmapfontcreator +{ + internal static class UIContent + { + public static readonly GUIContent TextureGroupTitle = new("Texture Properties"); + public static readonly GUIContent FontGroupTitle = new("Font Properties"); + public static readonly GUIContent CharactersGroupTitle = new("Characters"); + + public static readonly GUIContent TextureLabel = new("Texture", "Texture used for the font"); + public static readonly GUIContent Orientation = new("Orientation", "Order to look up for characters in the texture"); + public static readonly GUIContent Cols = new("Cols", "Number of columns in the texture"); + public static readonly GUIContent Rows = new("Rows", "Number of rows in the texture"); + public static readonly GUIContent GuessRowsAndColsButton = new("Guess", "Guess the number of rows and columns of the texture based on transparency gaps"); + public static readonly GUIContent PreviewButton = new("Preview", "Preview the texture with current rows and cols"); + public static readonly GUIContent AlphaThreshold = new("Alpha Threshold", "Alpha threshold to identify characters bounds"); + public static readonly GUIContent Monospaced = new("Monospaced", "Whether the result font should be monospaced"); + public static readonly GUIContent CaseInsentive = new("Case Insentive", "Whether the characters for lowercase and uppercase are the same"); + public static readonly GUIContent Ascent = new("Ascent", "Font ascent. It's the part of the glyphs that should be above the baseline"); + public static readonly GUIContent Descent = new("Descent", "Font descent. It's the part of the glyphs that should be below the baseline"); + public static readonly GUIContent FontSize = new("Font Size", "Base font size in pixels"); + public static readonly GUIContent AutoFontSize = new("Auto", "Automatically calculate the font size based on ascent property or cell size"); + public static readonly GUIContent LineSpacing = new("Line Spacing", "Vertical spacing between lines"); + public static readonly GUIContent AutoLineSpacing = new("Auto", "Automatically calculate the line spacing based on cell height"); + public static readonly GUIContent CharacterSet = new("Character Set", "Predefined character set to use"); + public static readonly GUIContent Characters = new("Characters", "Characters used in the font in order they appear in the texture. Use the space character to represent blank spaces in the texture"); + public static readonly GUIContent DefaultCharacterSpacing = new("Character Spacing", "Default spacing between characters"); + public static readonly GUIContent CustomCharacterProperties = new("Custom Character Properties", "Custom properties for each characters, if any"); + public static readonly GUIContent CustomCharacter = new("Char", "Character to apply the properties"); + public static readonly GUIContent CustomSpacing = new("Spacing", "Horizontal spacing after the character (advance). Ignored if font is monospaced"); + public static readonly GUIContent CustomPadding = new("Padding", "Custom horizontal and vertical padding to add before the character"); + + public static readonly GUIContent CreateButton = new("Create", "Create font files"); + + public static readonly GUIContent RollbackButton = new("Rollback", "Rollback settings to the selected profile or default"); + public static readonly GUIContent DefaultButton = new("Default", "Reset settings to their default values"); + public static readonly GUIContent PreferencesButton = new(string.Empty, "Preferences"); + public static readonly GUIContent PreferencesLabel = new("Preferences"); + public static readonly GUIContent WarnOnReplaceFont = new("Warn before replacing font files", "Warn before replacing an existing font. This will replace the old font keeping the references"); + public static readonly GUIContent WarnOnReplaceSettings = new("Warn before replacing settings", "Warn before replacing settings when selecting a profile"); + public static readonly GUIContent WarnOnReplaceProfile = new("Warn before replacing profile", "Warn before replacing an existing profile"); + + public static readonly GUIContent NoContent = new("Invalid texture", "There is no texture selected or the number of rows or columns are set to zero"); + public static readonly GUIContent GridColorLabel = new("Grid", "Color for the grid lines showing rows and columns"); + public static readonly GUIContent HeightColorLabel = new("Height", "Color for de glyph hight line (ascent + descent)"); + public static readonly GUIContent BaselineColorLabel = new("Baseline", "Color for the baseline (descent)"); + + public static readonly GUIContent DarkTextureIcon = new() { image = Styles.GridDarkTexture, }; + public static readonly GUIContent LightTextureIcon = new() { image = Styles.GridLightTexture }; + } +} diff --git a/Editor/Scripts/UI/Util/UIContent.cs.meta b/Editor/Scripts/UI/Util/UIContent.cs.meta new file mode 100644 index 0000000..ba0581d --- /dev/null +++ b/Editor/Scripts/UI/Util/UIContent.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2f606d52c280f78c4babe4ec24c3a224 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Scripts/UI/Util/UIUtils.cs b/Editor/Scripts/UI/Util/UIUtils.cs new file mode 100644 index 0000000..307cb65 --- /dev/null +++ b/Editor/Scripts/UI/Util/UIUtils.cs @@ -0,0 +1,46 @@ +using UnityEditor; +using UnityEngine; + +namespace dev.klebersilva.tools.bitmapfontcreator +{ + internal static class UIUtils + { + public static float FloatFieldMin(GUIContent label, float value, float min) + { + EditorGUI.BeginChangeCheck(); + value = EditorGUILayout.FloatField(label, value); + if (EditorGUI.EndChangeCheck() && value < min) value = min; + return value; + } + + public static int IntFieldMin(GUIContent label, int value, int min) + { + EditorGUI.BeginChangeCheck(); + value = EditorGUILayout.IntField(label, value); + if (EditorGUI.EndChangeCheck() && value < min) value = min; + return value; + } + + public static float FloatFieldWithAuto(GUIContent label, float value, GUIContent autoLabel, ref bool auto) + { + GUILayout.BeginHorizontal(); + GUI.enabled = !auto; + value = EditorGUILayout.FloatField(label, value); + GUI.enabled = true; + + auto = EditorGUILayout.ToggleLeft(autoLabel, auto, GUILayout.Width(Styles.AutoToggleWidth)); + GUILayout.EndHorizontal(); + return value; + } + + public static bool CenteredButton(GUIContent label, GUIStyle style = null) + { + GUILayout.BeginHorizontal(); + GUILayout.FlexibleSpace(); + var value = GUILayout.Button(label, style ?? GUI.skin.button); + GUILayout.FlexibleSpace(); + GUILayout.EndHorizontal(); + return value; + } + } +} diff --git a/Editor/Scripts/UI/Util/UIUtils.cs.meta b/Editor/Scripts/UI/Util/UIUtils.cs.meta new file mode 100644 index 0000000..cb51989 --- /dev/null +++ b/Editor/Scripts/UI/Util/UIUtils.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6be9bccbcce4f2890a7bc3901f06df50 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/README.md b/README.md index b4c70cf..3b46ddc 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ Preferences are accessed by clicking on the three dots at the bottom right corne - **Guess (Rows and Cols)**: Guess the number of rows and columns of the texture based on transparency gaps. - **Create**: Creates the font using the given settings. - **Rollback**: Rollback settings to the selected profile or default if none is selected. +- **Default**: Reset settings to their default values. ## Profiles diff --git a/package.json b/package.json index 08ca2ec..1b3c691 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "dev.klebersilva.tools.bitmapfontcreator", - "version": "1.4.0", - "description": "A simple tool to create bitmap fonts from a texture sprite sheet to be used with Text component.", + "version": "1.5.0", + "description": "Create bitmap fonts from sprite sheets in Unity.", "displayName": "Bitmap Font Creator", "unity": "2018.3", "author": {