Skip to content

Commit

Permalink
Improve Material Selector action bar
Browse files Browse the repository at this point in the history
  • Loading branch information
vanjac committed Nov 11, 2023
1 parent 41a3d57 commit 65aa02b
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 79 deletions.
2 changes: 1 addition & 1 deletion Assets/VoxelEditor/GUI/GUIIconSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static GUIIconSet instance
public Texture entityTag, target, rename, copy, delete, share, bevel, no, pause, restart, editor, playAudio;
public Texture reddit, youTube, undo, import, fill, draw, singleObject, objectType, behavior, newTexture;
public Texture worldImport, newItem, website, donate, pan, orbit, sensor, random, baseLayer, overlayLayer;
public Texture plusOne, minusOne;
public Texture plusOne, minusOne, color;
public Texture indoorLarge, floatingLarge, newWorldLarge, helpLarge, compassLarge;

public Texture[] tagIcons;
Expand Down
8 changes: 8 additions & 0 deletions Assets/VoxelEditor/GUI/GUIUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,12 @@ public static void EndHorizontalClipped()
GUILayout.EndHorizontal();
GUILayout.EndScrollView();
}

public static void ShowDisabled()
{
if (!GUI.enabled)
GUI.color *= new Color(1, 1, 1, 0.5f); // aaaaaaaaa
else
GUI.enabled = false;
}
}
151 changes: 75 additions & 76 deletions Assets/VoxelEditor/GUI/MaterialSelectorGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class MaterialSelectorGUI : GUIPanel
private const int NUM_COLUMNS = 4;
private const int NUM_COLUMNS_ROOT = 6;
private const int TEXTURE_MARGIN = 20;
private const float CATEGORY_BUTTON_HEIGHT = 110;
private const string PREVIEW_SUFFIX = "_preview";
private const string CUSTOM_CATEGORY = "CUSTOM";
private const string WORLD_LIST_CATEGORY = "Import from world...";
Expand All @@ -22,7 +21,8 @@ public class MaterialSelectorGUI : GUIPanel
public Material highlightMaterial = null; // the current selected material
public VoxelArrayEditor voxelArray;

private int tab;
private enum Page { TEXTURE, COLOR };
private Page page = Page.TEXTURE;
private string selectedCategory;
private bool importFromWorld, loadingWorld;
private string importMessage = null;
Expand Down Expand Up @@ -74,61 +74,39 @@ void OnDestroy()

public override void WindowGUI()
{
GUILayout.BeginHorizontal();
TutorialGUI.TutorialHighlight("material type");
tab = GUILayout.SelectionGrid(tab, new string[] { "Texture", "Color" }, 2);
TutorialGUI.ClearHighlight();
if (allowNullMaterial && GUILayout.Button("Clear", GUILayout.ExpandWidth(false)))
MaterialSelected(null);
GUILayout.EndHorizontal();

if (tab == 1)
if (page == Page.COLOR)
{
if (!ColorTab() && colorPicker != null)
{
Destroy(colorPicker);
colorPicker = null;
}
ColorPage();
}
else if (colorPicker != null)
{
Destroy(colorPicker);
colorPicker = null;
}
if (tab == 0)
TextureTab();

if (page == Page.TEXTURE)
TexturePage();
else
{
scrollVelocity = Vector2.zero;
}
}

private bool ColorTab()
private void ColorPage()
{
if (highlightMaterial == null)
{
GUILayout.Label("No texture selected");
return false;
}
if (CustomTexture.IsCustomTexture(highlightMaterial))
{
GUILayout.Label("Can't change color of custom texture");
return false;
}
GUILayout.BeginHorizontal();
if (ActionBarGUI.ActionBarButton(GUIIconSet.instance.close))
page = Page.TEXTURE;
GUILayout.Label("Adjust color", categoryLabelStyle.Value);
GUILayout.EndHorizontal();

string colorProp = ResourcesDirectory.MaterialColorProperty(highlightMaterial);
if (colorProp == null)
{
GUILayout.Label("Can't change color of this texture");
return false;
}
if (colorPicker == null)
{
whitePoint = Color.white;
showColorStyle = false;
colorStyle = ResourcesDirectory.ColorStyle.PAINT; // ignore white point by default
if (!customTextureBase && ResourcesDirectory.materialInfos.ContainsKey(highlightMaterial.name))
if (!customTextureBase &&
ResourcesDirectory.materialInfos.TryGetValue(highlightMaterial.name, out var info))
{
var info = ResourcesDirectory.materialInfos[highlightMaterial.name];
whitePoint = info.whitePoint;
whitePoint.a = 1.0f;
showColorStyle = info.supportsColorStyles;
Expand Down Expand Up @@ -166,10 +144,9 @@ private bool ColorTab()
colorPicker.CallHandler(); // update white point and call material handler also
}
}
return true;
}

private void TextureTab()
private void TexturePage()
{
if (materials == null)
return;
Expand All @@ -178,53 +155,76 @@ private void TextureTab()
GUILayout.Label("Loading world...");
return;
}
scroll = GUILayout.BeginScrollView(scroll);

if (selectedCategory != "")
GUILayout.BeginHorizontal();

bool wasEnabled = GUI.enabled;
Color baseColor = GUI.color;
if (selectedCategory == "" && !importFromWorld)
GUIUtils.ShowDisabled();
if (ActionBarGUI.ActionBarButton(GUIIconSet.instance.close))
BackButton();
GUI.enabled = wasEnabled;
GUI.color = baseColor;

if (selectedCategory == CUSTOM_CATEGORY)
{
GUILayout.BeginHorizontal();
if (ActionBarGUI.ActionBarButton(GUIIconSet.instance.close))
BackButton();
// prevent from expanding window
GUIUtils.BeginHorizontalClipped(GUILayout.ExpandHeight(false));
if (selectedCategory == CUSTOM_CATEGORY)
if (ActionBarGUI.ActionBarButton(GUIIconSet.instance.newTexture))
ImportTextureFromPhotos();
if (ActionBarGUI.ActionBarButton(GUIIconSet.instance.worldImport))
CategorySelected(WORLD_LIST_CATEGORY);
if (highlightMaterial != null && CustomTexture.IsCustomTexture(highlightMaterial))
{
if (ActionBarGUI.ActionBarButton(GUIIconSet.instance.newTexture))
ImportTextureFromPhotos();
if (ActionBarGUI.ActionBarButton(GUIIconSet.instance.worldImport))
CategorySelected(WORLD_LIST_CATEGORY);
if (highlightMaterial != null && CustomTexture.IsCustomTexture(highlightMaterial))
if (ActionBarGUI.ActionBarButton(GUIIconSet.instance.copy))
DuplicateCustomTexture();
if (ActionBarGUI.ActionBarButton(GUIIconSet.instance.draw))
EditCustomTexture(new CustomTexture(highlightMaterial, isOverlay));
if (ActionBarGUI.ActionBarButton(GUIIconSet.instance.delete))
{
if (ActionBarGUI.ActionBarButton(GUIIconSet.instance.copy))
DuplicateCustomTexture();
if (ActionBarGUI.ActionBarButton(GUIIconSet.instance.draw))
EditCustomTexture(new CustomTexture(highlightMaterial, isOverlay));
if (ActionBarGUI.ActionBarButton(GUIIconSet.instance.delete))
{
var dialog = gameObject.AddComponent<DialogGUI>();
dialog.message = "Are you sure you want to delete this custom texture?";
dialog.yesButtonText = "Yes";
dialog.noButtonText = "No";
dialog.yesButtonHandler = () => DeleteCustomTexture();
}
var dialog = gameObject.AddComponent<DialogGUI>();
dialog.message = "Are you sure you want to delete this custom texture?";
dialog.yesButtonText = "Yes";
dialog.noButtonText = "No";
dialog.yesButtonHandler = () => DeleteCustomTexture();
}
}
GUILayout.Label(selectedCategory, categoryLabelStyle.Value);
GUIUtils.EndHorizontalClipped();
GUILayout.EndHorizontal();
}

// prevent from expanding window
GUIUtils.BeginHorizontalClipped(GUILayout.ExpandHeight(false));
GUILayout.Label(selectedCategory, categoryLabelStyle.Value);
GUIUtils.EndHorizontalClipped();

wasEnabled = GUI.enabled;
baseColor = GUI.color;
if (highlightMaterial == null || CustomTexture.IsCustomTexture(highlightMaterial)
|| ResourcesDirectory.MaterialColorProperty(highlightMaterial) == null)
{
GUIUtils.ShowDisabled();
}
if (ActionBarGUI.ActionBarButton(GUIIconSet.instance.color))
page = Page.COLOR;
GUI.enabled = wasEnabled;
GUI.color = baseColor;

if (allowNullMaterial && selectedCategory == "")
{
if (highlightMaterial != null && ActionBarGUI.ActionBarButton(GUIIconSet.instance.no))
MaterialSelected(null);
else if (highlightMaterial == null)
ActionBarGUI.HighlightedActionBarButton(GUIIconSet.instance.no);
}

GUILayout.EndHorizontal();

scroll = GUILayout.BeginScrollView(scroll);
if (importFromWorld && (importMessage != null))
GUILayout.Label(importMessage);

Rect rowRect = new Rect();
int materialColumns = categories.Length > 0 ? NUM_COLUMNS_ROOT : NUM_COLUMNS;
string highlightName = "", previewName = "";
if (highlightMaterial != null)
{
highlightName = highlightMaterial.name;
previewName = highlightName + PREVIEW_SUFFIX;
}
string highlightName = highlightMaterial?.name;
string previewName = (highlightName != null) ? (highlightName + PREVIEW_SUFFIX) : null;
for (int i = 0; i < materials.Count; i++)
{
if (i % materialColumns == 0)
Expand All @@ -237,8 +237,7 @@ private void TextureTab()
buttonRect.width - TEXTURE_MARGIN * 2, buttonRect.height - TEXTURE_MARGIN * 2);
Material material = materials[i];
bool selected;
if (material != null && (material.name == highlightName
|| material.name == previewName))
if (material?.name == highlightName || material?.name == previewName)
// highlight the button
selected = !GUI.Toggle(buttonRect, true, "", GUI.skin.button);
else
Expand Down
Binary file added Assets/VoxelEditor/GUI/icons/palette.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
121 changes: 121 additions & 0 deletions Assets/VoxelEditor/GUI/icons/palette.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Assets/VoxelEditor/TutorialPages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public static class Tutorials
() => new TutorialPaintPage(
"You can use the Paint panel to paint the selected faces with <i>materials</i> and <i>overlays</i>."),
() => new TutorialPaintPage(
"Choose any of the categories to browse for a texture. Then switch to the Color tab to change its color.",
highlight: "material type"),
"Choose any of the categories to browse for a texture. Then tap the Color button to change its color."),
() => new TutorialPaintPage(
"A paint is composed of two parts: an opaque material and a transparent overlay. "
+ "Use the tabs to switch between the two parts.",
Expand Down
1 change: 1 addition & 0 deletions Assets/VoxelEditor/editScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,7 @@ MonoBehaviour:
overlayLayer: {fileID: 2800000, guid: 7e0e6bcbebe5b1e4a80e0f5576bc30ed, type: 3}
plusOne: {fileID: 2800000, guid: 34b8c574bafcc7541bf8778c7f29e0fd, type: 3}
minusOne: {fileID: 2800000, guid: ab5c3d88d3e155741b402fef1ee52c72, type: 3}
color: {fileID: 2800000, guid: efd72c913ac0be549af477e59955aae8, type: 3}
indoorLarge: {fileID: 0}
floatingLarge: {fileID: 0}
newWorldLarge: {fileID: 0}
Expand Down

0 comments on commit 65aa02b

Please sign in to comment.