Parcourir la source

Explicit Cell Support

The Asset Manager now supports using explicit cell mode in an image asset. Cells can be added, removed, edited, and reordered directly in the UI.
Peter Robinson il y a 3 ans
Parent
commit
828f65abe1

+ 1 - 0
editor/AssetAdmin/AssetAdmin.cs

@@ -35,6 +35,7 @@ function AssetAdmin::create(%this)
 	exec("./NewAudioAssetDialog.cs");
 	exec("./DeleteAssetDialog.cs");
 	exec("./ParticleEditor/exec.cs");
+	exec("./ImageEditor/exec.cs");
 
 	%this.guiPage = EditorCore.RegisterEditor("Asset Manager", %this);
 	%this.guiPage.add(%this.buildAssetWindow());

+ 3 - 1
editor/AssetAdmin/AssetInspector.cs

@@ -213,7 +213,7 @@ function AssetInspector::resetInspector(%this)
 function AssetInspector::loadImageAsset(%this, %imageAsset, %assetID)
 {
 	%this.resetInspector();
-	//%this.tabBook.add(%this.imageFrameEditPage);
+	%this.tabBook.add(%this.imageFrameEditPage);
 	%this.tabBook.selectPage(0);
 	%this.titlebar.setText("Image Asset:" SPC %imageAsset.AssetName);
 
@@ -225,6 +225,8 @@ function AssetInspector::loadImageAsset(%this, %imageAsset, %assetID)
 	%this.inspector.addHiddenField("ExplicitMode");
 	%this.inspector.inspect(%imageAsset);
 	%this.inspector.openGroupByIndex(0);
+
+	%this.imageFrameEditPage.inspect(%imageAsset);
 }
 
 function AssetInspector::loadAnimationAsset(%this, %animationAsset, %assetID)

+ 276 - 0
editor/AssetAdmin/ImageEditor/AssetImageFrameEditRow.cs

@@ -0,0 +1,276 @@
+
+function AssetImageFrameEditRow::onAdd(%this)
+{
+	%this.errorColor = "255 0 0 255";
+	%this.indexBox = new GuiControl()
+	{
+		HorizSizing="width";
+		VertSizing="height";
+		Position="0 0";
+		Extent="20 40";
+		Align = center;
+		vAlign = middle;
+		Text = %this.CellIndex;
+		FontSizeAdjust = 1.4;
+		FontColor = %this.errorColor;
+	};
+	ThemeManager.setProfile(%this.indexBox, "codeProfile");
+	%this.add(%this.indexBox);
+
+	%this.nameBox = new GuiTextEditCtrl()
+	{
+		HorizSizing="width";
+		VertSizing="height";
+		Position="20 3";
+		Extent="200 32";
+		Text = %this.CellName;
+		AltCommand = %this.getID() @ ".CellNameChange();";
+		FontColor = %this.errorColor;
+		InputMode = "AlphaNumeric";
+	};
+	ThemeManager.setProfile(%this.nameBox, "textEditProfile");
+	%this.add(%this.nameBox);
+
+	%this.offsetXBox = new GuiTextEditCtrl()
+	{
+		HorizSizing="width";
+		VertSizing="height";
+		Position="224 3";
+		Extent="80 32";
+		Align = right;
+		Text = getWord(%this.CellOffset, 0);
+		AltCommand = %this.getID() @ ".CellOffsetXChange();";
+		FontColor = %this.errorColor;
+		InputMode = "Number";
+	};
+	ThemeManager.setProfile(%this.offsetXBox, "textEditProfile");
+	%this.add(%this.offsetXBox);
+
+	%this.offsetYBox = new GuiTextEditCtrl()
+	{
+		HorizSizing="width";
+		VertSizing="height";
+		Position="308 3";
+		Extent="80 32";
+		Align = right;
+		Text = getWord(%this.CellOffset, 1);
+		AltCommand = %this.getID() @ ".CellOffsetYChange();";
+		FontColor = %this.errorColor;
+		InputMode = "Number";
+	};
+	ThemeManager.setProfile(%this.offsetYBox, "textEditProfile");
+	%this.add(%this.offsetYBox);
+
+	%this.widthBox = new GuiTextEditCtrl()
+	{
+		HorizSizing="width";
+		VertSizing="height";
+		Position="392 3";
+		Extent="80 32";
+		Align = right;
+		Text = %this.CellWidth;
+		AltCommand = %this.getID() @ ".CellWidthChange();";
+		FontColor = %this.errorColor;
+		InputMode = "Number";
+	};
+	ThemeManager.setProfile(%this.widthBox, "textEditProfile");
+	%this.add(%this.widthBox);
+
+	%this.heightBox = new GuiTextEditCtrl()
+	{
+		HorizSizing="width";
+		VertSizing="height";
+		Position="476 3";
+		Extent="80 32";
+		Align = right;
+		Text = %this.CellHeight;
+		AltCommand = %this.getID() @ ".CellHeightChange();";
+		FontColor = %this.errorColor;
+		InputMode = "Number";
+	};
+	ThemeManager.setProfile(%this.heightBox, "textEditProfile");
+	%this.add(%this.heightBox);
+
+	%this.buttonBar = new GuiChainCtrl()
+	{
+		Class = "EditorButtonBar";
+		Position = "564 5";
+		Extent = "0 24";
+		ChildSpacing = 4;
+		IsVertical = false;
+		Tool = %this;
+	};
+	ThemeManager.setProfile(%this.buttonBar, "emptyProfile");
+	%this.add(%this.buttonBar);
+	%this.buttonBar.addButton("MoveCellUp", 2, "Move Cell Up", "getMoveCellUpEnabled");
+	%this.buttonBar.addButton("MoveCellDown", 6, "Move Cell Down", "getMoveCellDownEnabled");
+	%this.buttonBar.addButton("RemoveCell", 23, "Remove Cell", "getRemoveCellEnabled");
+}
+
+function AssetImageFrameEditRow::CellNameChange(%this)
+{
+	%name = %this.nameBox.getText();
+	%name = stripChars(%name, " ");
+	%this.nameBox.setText(%name);
+	if(%name !$= %this.CellName)
+	{
+		if(%name $= "")
+		{
+			%this.setNameError(true);
+		}
+		else
+		{
+			%this.setNameError(false);
+			%this.postEvent("CellNameChange", %this SPC %name);
+		}
+	}
+}
+
+function AssetImageFrameEditRow::CellOffsetXChange(%this)
+{
+	%x = %this.offsetXBox.getText();
+	%x = stripChars(%x, " ");
+	if(%x $= "")
+	{
+		%x = 0;
+	}
+	%x = mClamp(%x, 0, %this.ImageWidth - 1);
+	%this.offsetXBox.setText(%x);
+
+	if(%x !$= getWord(%this.CellOffset, 0))
+	{
+		%width = %this.CellWidth;
+		if((%x + %width) > %this.ImageWidth)
+		{
+			%width = %this.ImageWidth - %x;
+			%this.widthBox.setText(%width);
+		}
+		%this.postEvent("CellSizeChange", %this SPC %x SPC getWord(%this.CellOffset, 1) SPC %width SPC %this.CellHeight);
+	}
+}
+
+function AssetImageFrameEditRow::CellOffsetYChange(%this)
+{
+	%y = %this.offsetYBox.getText();
+	%y = stripChars(%y, " ");
+	if(%y $= "")
+	{
+		%y = 0;
+	}
+	%y = mClamp(%y, 0, %this.ImageHeight - 1);
+	%this.offsetYBox.setText(%y);
+
+	if(%y !$= getWord(%this.CellOffset, 1))
+	{
+		%height = %this.CellHeight;
+		if((%y + %height) > %this.ImageHeight)
+		{
+			%height = %this.ImageHeight - %y;
+			%this.heightBox.setText(%height);
+		}
+		%this.postEvent("CellSizeChange", %this SPC getWord(%this.CellOffset, 0) SPC %y SPC %this.CellWidth SPC %height);
+	}
+}
+
+function AssetImageFrameEditRow::CellWidthChange(%this)
+{
+	%width = %this.widthBox.getText();
+	%width = stripChars(%width, " ");
+	if(%width $= "")
+	{
+		%width = 1;
+	}
+	%width = mClamp(%width, 1, %this.ImageWidth);
+	%this.widthBox.setText(%width);
+
+	if(%width !$= %this.CellWidth)
+	{
+		%x = getWord(%this.CellOffset, 0);
+		if((%x + %width) > %this.ImageWidth)
+		{
+			%x = %this.ImageWidth - %width;
+			%this.offsetXBox.setText(%x);
+		}
+		%this.postEvent("CellSizeChange", %this SPC %x SPC getWord(%this.CellOffset, 1) SPC %width SPC %this.CellHeight);
+	}
+}
+
+function AssetImageFrameEditRow::CellHeightChange(%this)
+{
+	%height = %this.heightBox.getText();
+	%height = stripChars(%height, " ");
+	if(%height $= "")
+	{
+		%height = 1;
+	}
+	%height = mClamp(%height, 1, %this.ImageHeight);
+	%this.heightBox.setText(%height);
+
+	if(%height !$= %this.CellHeight)
+	{
+		%y = getWord(%this.CellOffset, 1);
+		if((%y + %height) > %this.ImageHeight)
+		{
+			%y = %this.ImageHeight - %height;
+			%this.offsetYBox.setText(%y);
+		}
+		%this.postEvent("CellSizeChange", %this SPC getWord(%this.CellOffset, 0) SPC %y SPC %this.CellWidth SPC %height);
+	}
+}
+
+function AssetImageFrameEditRow::setNameError(%this, %hasError)
+{
+	%this.nameBox.overrideFontColor = %hasError;
+	%this.indexBox.overrideFontColor = %hasError;
+}
+
+function AssetImageFrameEditRow::getMoveCellUpEnabled(%this)
+{
+	return %this.CellIndex != 0;
+}
+
+function AssetImageFrameEditRow::getMoveCellDownEnabled(%this)
+{
+	return %this.CellIndex < (%this.CellCount - 1);
+}
+
+function AssetImageFrameEditRow::getRemoveCellEnabled(%this)
+{
+	return %this.CellCount > 1;
+}
+
+function AssetImageFrameEditRow::updateCellCount(%this, %newCount)
+{
+	%this.CellCount = %newCount;
+	%this.buttonBar.refreshEnabled();
+}
+
+function AssetImageFrameEditRow::MoveCellUp(%this)
+{
+	%this.postEvent("swapCells", (%this.CellIndex - 1) SPC %this.CellIndex);
+}
+
+function AssetImageFrameEditRow::MoveCellDown(%this)
+{
+	%this.postEvent("swapCells", %this.CellIndex SPC (%this.CellIndex + 1));
+}
+
+function AssetImageFrameEditRow::RemoveCell(%this)
+{
+	%this.postEvent("removeCell", %this.CellIndex);
+}
+
+function AssetImageFrameEditRow::refresh(%this)
+{
+	%this.indexBox.setText(%this.CellIndex);
+	%this.nameBox.setText(%this.CellName);
+	%this.offsetXBox.setText(getWord(%this.CellOffset, 0));
+	%this.offsetYBox.setText(getWord(%this.CellOffset, 1));
+	%this.widthBox.setText(%this.CellWidth);
+	%this.heightBox.setText(%this.CellHeight);
+}
+
+function AssetImageFrameEditRow::onRemove(%this)
+{
+	%this.deleteObjects();
+}

+ 246 - 0
editor/AssetAdmin/ImageEditor/AssetImageFrameEditTool.cs

@@ -0,0 +1,246 @@
+
+function AssetImageFrameEditTool::onAdd(%this)
+{
+	%this.explicitModeCheckbox = new GuiCheckboxCtrl()
+	{
+		HorizSizing="right";
+		VertSizing="bottom";
+		Position="10 3";
+		Extent= "285 30";
+		Text = "Use Explicit Frame Mode";
+		TextExtent = "280 30";
+		command = %this.getID() @ ".toggleExplicitMode();";
+	};
+	ThemeManager.setProfile(%this.explicitModeCheckbox, "checkboxProfile");
+	%this.add(%this.explicitModeCheckbox);
+
+	%this.toolScroll = new GuiScrollCtrl()
+	{
+		HorizSizing="width";
+		VertSizing="height";
+		Position="0 40";
+		Extent= getWord(%this.extent, 0) SPC (getWord(%this.extent, 1) - 40);
+		hScrollBar="dynamic";
+		vScrollBar="dynamic";
+		constantThumbHeight="0";
+		showArrowButtons="1";
+		scrollBarThickness="14";
+	};
+	ThemeManager.setProfile(%this.toolScroll, "scrollingPanelProfile");
+	ThemeManager.setProfile(%this.toolScroll, "scrollingPanelThumbProfile", "ThumbProfile");
+	ThemeManager.setProfile(%this.toolScroll, "scrollingPanelTrackProfile", "TrackProfile");
+	ThemeManager.setProfile(%this.toolScroll, "scrollingPanelArrowProfile", "ArrowProfile");
+	%this.add(%this.toolScroll);
+
+	%this.rowChain = new GuiChainCtrl()
+	{
+		HorizSizing="right";
+		VertSizing="bottom";
+		Position="0 0";
+		Extent= "662" SPC getWord(%this.toolScroll.extent, 1);
+		IsVertical="1";
+		ChildSpacing="2";
+	};
+	ThemeManager.setProfile(%this.rowChain, "emptyProfile");
+	%this.toolScroll.add(%this.rowChain);
+
+	%this.addNewCellButton = new GuiButtonCtrl()
+	{
+		HorizSizing="left";
+		VertSizing="bottom";
+		Position="580 5";
+		Extent= "110 26";
+		Text = "Add Cell";
+		command = %this.getID() @ ".addNewCell();";
+	};
+	ThemeManager.setProfile(%this.addNewCellButton, "buttonProfile");
+	%this.add(%this.addNewCellButton);
+}
+
+function AssetImageFrameEditTool::inspect(%this, %asset)
+{
+	%this.asset = %asset;
+	%this.explicitModeCheckbox.setStateOn(%asset.ExplicitMode);
+
+	%this.rowChain.deleteObjects();
+	%this.addHeaderRow();
+
+	%this.toggleExplicitMode();
+}
+
+function AssetImageFrameEditTool::createRows(%this)
+{
+	%cellCount = %this.asset.getExplicitCellCount();
+	for(%i = 0; %i < %cellCount; %i++)
+	{
+		%name = %this.asset.getExplicitCellName(%i);
+		%width = %this.asset.getExplicitCellWidth(%i);
+		%height = %this.asset.getExplicitCellHeight(%i);
+		%offset = %this.asset.getExplicitCellOffset(%i);
+
+		%this.addImageFrameRow(%name, %offset, %width, %height, %i);
+	}
+}
+
+function AssetImageFrameEditTool::toggleExplicitMode(%this)
+{
+	%explicitModeOn = %this.explicitModeCheckbox.getStateOn();
+	%this.toolScroll.setVisible(%explicitModeOn);
+	%this.addNewCellButton.setVisible(%explicitModeOn);
+	%this.asset.setExplicitMode(%explicitModeOn);
+
+	if(%explicitModeOn && %this.asset.getExplicitCellCount() == 0)
+	{
+		%this.addNewCell();
+	}
+	else if(%explicitModeOn)
+	{
+		%this.createRows();
+	}
+	else
+	{
+		%this.rowChain.deleteObjects();
+		%this.addHeaderRow();
+	}
+}
+
+function AssetImageFrameEditTool::addHeaderRow(%this)
+{
+	%row = new GuiControl()
+	{
+		Class = "AssetImageFrameHeaderRow";
+		HorizSizing="right";
+		VertSizing="bottom";
+		Position="0 0";
+		Extent="560 22";
+	};
+	ThemeManager.setProfile(%row, "emptyProfile");
+	%this.rowChain.add(%row);
+}
+
+function AssetImageFrameEditTool::addImageFrameRow(%this, %name, %offset, %width, %height, %index)
+{
+	%row = new GuiControl()
+	{
+		Class = "AssetImageFrameEditRow";
+		HorizSizing="right";
+		VertSizing="bottom";
+		Position="0 0";
+		Extent="662 40";
+		CellName = %name;
+		CellOffset = %offset;
+		CellWidth = %width;
+		CellHeight = %height;
+		CellIndex = %index;
+		ImageWidth = %this.asset.getImageWidth();
+		ImageHeight = %this.asset.getImageHeight();
+		CellCount = %this.asset.getExplicitCellCount();
+	};
+	ThemeManager.setProfile(%row, "emptyProfile");
+	%this.rowChain.add(%row);
+	%this.startListening(%row);
+}
+
+function AssetImageFrameEditTool::addNewCell(%this)
+{
+	%index = %this.asset.getExplicitCellCount();
+	%name = "Frame" @ %index;
+	%x = 0;
+	%y = 0;
+	%width = %this.asset.getImageWidth();
+	%height = %this.asset.getImageHeight();
+
+	%this.rowChain.callOnChildrenNoRecurse("updateCellCount", %index + 1);
+
+	%this.asset.addExplicitCell(%x, %y, %width, %height, %name);
+	%this.addImageFrameRow(%name, %x SPC %y, %width, %height, %index);
+}
+
+function AssetImageFrameEditTool::onCellNameChange(%this, %data)
+{
+	%row = getWord(%data, 0);
+	%name = getWord(%data, 1);
+
+	if(%this.asset.getExplicitCellIndex(%name) != -1)
+	{
+		%row.setNameError(true);
+	}
+	else
+	{
+		%this.asset.setExplicitCell(%row.CellIndex, getWord(%row.CellOffset, 0), getWord(%row.CellOffset, 1), %row.CellWidth, %row.CellHeight, %name);
+		%row.CellName = %name;
+	}
+}
+
+function AssetImageFrameEditTool::onCellSizeChange(%this, %data)
+{
+	%row = getWord(%data, 0);
+	%x = getWord(%data, 1);
+	%y = getWord(%data, 2);
+	%width = getWord(%data, 3);
+	%height = getWord(%data, 4);
+
+	%this.asset.setExplicitCell(%row.CellIndex, %x, %y, %width, %height, %row.CellName);
+	%row.CellOffset = %x SPC %y;
+	%row.CellWidth = %width;
+	%row.CellHeight = %height;
+}
+
+function AssetImageFrameEditTool::onSwapCells(%this, %data)
+{
+	%index1 = getWord(%data, 0);
+	%index2 = getWord(%data, 1);
+
+	%name1 = %this.asset.getExplicitCellName(%index1);
+	%width1 = %this.asset.getExplicitCellWidth(%index1);
+	%height1 = %this.asset.getExplicitCellHeight(%index1);
+	%offset1 = %this.asset.getExplicitCellOffset(%index1);
+
+	%name2 = %this.asset.getExplicitCellName(%index2);
+	%width2 = %this.asset.getExplicitCellWidth(%index2);
+	%height2 = %this.asset.getExplicitCellHeight(%index2);
+	%offset2 = %this.asset.getExplicitCellOffset(%index2);
+
+	%this.asset.setExplicitCell(%index1, getWord(%offset2, 0), getWord(%offset2, 1), %width2, %height2, %name2);
+	%this.asset.setExplicitCell(%index2, getWord(%offset1, 0), getWord(%offset1, 1), %width1, %height1, %name1);
+
+	%row1 = %this.rowChain.getObject(%index1 + 1);
+	%row2 = %this.rowChain.getObject(%index2 + 1);
+
+	%row1.CellOffset = %offset2;
+	%row1.CellWidth = %width2;
+	%row1.CellHeight = %height2;
+	%row1.CellName = %name2;
+
+	%row2.CellOffset = %offset1;
+	%row2.CellWidth = %width1;
+	%row2.CellHeight = %height1;
+	%row2.CellName = %name1;
+
+	%row1.refresh();
+	%row2.refresh();
+}
+
+function AssetImageFrameEditTool::onRemoveCell(%this, %index)
+{
+	%this.schedule(50, "onRemoveCell2", %index);
+}
+
+function AssetImageFrameEditTool::onRemoveCell2(%this, %index)
+{
+	%this.asset.removeExplicitCell(%index);
+	%row = %this.rowChain.getObject(%index + 1);
+	%row.delete();
+
+	%count = %this.asset.getExplicitCellCount();
+	for(%i = 0; %i < %this.rowChain.getCount(); %i++)
+	{
+		%row = %this.rowChain.getObject(%i);
+		if(%row.isMethod("refresh"))
+		{
+			%row.CellIndex = (%i - 1);
+			%row.updateCellCount(%count);
+			%row.refresh();
+		}
+	}
+}

+ 67 - 0
editor/AssetAdmin/ImageEditor/AssetImageFrameHeaderRow.cs

@@ -0,0 +1,67 @@
+
+function AssetImageFrameHeaderRow::onAdd(%this)
+{
+	%this.nameBox = new GuiControl()
+	{
+		HorizSizing="width";
+		VertSizing="height";
+		Position="20 0";
+		Extent="200 25";
+		Text = "Cell Name";
+		vAlign = "Bottom";
+	};
+	ThemeManager.setProfile(%this.nameBox, "LabelProfile");
+	%this.add(%this.nameBox);
+
+	%this.offsetXBox = new GuiControl()
+	{
+		HorizSizing="width";
+		VertSizing="height";
+		Position="224 0";
+		Extent="80 25";
+		Text = "X";
+		Align = "Center";
+		vAlign = "Bottom";
+	};
+	ThemeManager.setProfile(%this.offsetXBox, "LabelProfile");
+	%this.add(%this.offsetXBox);
+
+	%this.offsetYBox = new GuiControl()
+	{
+		HorizSizing="width";
+		VertSizing="height";
+		Position="308 0";
+		Extent="80 25";
+		Text = "Y";
+		Align = "Center";
+		vAlign = "Bottom";
+	};
+	ThemeManager.setProfile(%this.offsetYBox, "LabelProfile");
+	%this.add(%this.offsetYBox);
+
+	%this.widthBox = new GuiControl()
+	{
+		HorizSizing="width";
+		VertSizing="height";
+		Position="392 0";
+		Extent="80 25";
+		Text = "Width";
+		Align = "Center";
+		vAlign = "Bottom";
+	};
+	ThemeManager.setProfile(%this.widthBox, "LabelProfile");
+	%this.add(%this.widthBox);
+
+	%this.heightBox = new GuiControl()
+	{
+		HorizSizing="width";
+		VertSizing="height";
+		Position="476 0";
+		Extent="80 25";
+		Text = "Height";
+		Align = "Center";
+		vAlign = "Bottom";
+	};
+	ThemeManager.setProfile(%this.heightBox, "LabelProfile");
+	%this.add(%this.heightBox);
+}

+ 3 - 0
editor/AssetAdmin/ImageEditor/exec.cs

@@ -0,0 +1,3 @@
+exec("./AssetImageFrameEditTool.cs");
+exec("./AssetImageFrameEditRow.cs");
+exec("./AssetImageFrameHeaderRow.cs");

+ 5 - 0
editor/EditorCore/EditorButtonBar.cs

@@ -36,3 +36,8 @@ function EditorButtonBar::refreshEnabled(%this)
 		}
 	}
 }
+
+function EditorButtonBar::onRemove(%this)
+{
+	%this.deleteObjects();
+}

+ 8 - 0
editor/EditorCore/EditorIconButton.cs

@@ -72,3 +72,11 @@ function EditorIconButton::onThemeChange(%this, %theme)
 		%this.icon.setImageColor(ThemeManager.activeTheme.iconButtonProfile.fontColorNA);
 	}
 }
+
+function EditorIconButton::onRemove(%this)
+{
+	if(isObject(%this.icon))
+	{
+		%this.icon.delete();
+	}
+}