/// <summary> /// Draws the no map image controls. /// </summary> private void DrawNoMapImage() { GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GUILayout.FlexibleSpace(); GUILayout.BeginVertical(GUILayout.ExpandHeight(true)); GUILayout.FlexibleSpace(); ControlGrid.DrawGenericGrid( (data, index, style, options) => { if (GUILayout.Button(data[index], style, options)) { switch (index) { case 0: Map2DService.Instance.StartNewMap(); break; } } return(null); }, this.noMapButtonContent, this.noMapButtonContent.Length, GUI.skin.button, GUILayout.Width(128), GUILayout.Height(128)); GUILayout.FlexibleSpace(); GUILayout.EndVertical(); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); }
/// <summary> /// Draws the editor tool bar. /// </summary> private void DrawToolBar() { GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); var values = new IEditorTool <IMapEditor> [this.tools.Count]; var i = 0; foreach (var editorTool in this.tools) { values[i++] = editorTool; } var settings = SettingsManager.Instance; var size = settings.GetSetting(GlobalConstants.Map2DDrawingModeButtonSizeKey, 64.0f); var buttonsPerRow = settings.GetSetting(GlobalConstants.Map2DDrawModeButtonsPerRowKey, 20); ControlGrid.DrawGenericGrid( (toolArray, index, style, options) => { var tool = toolArray[index]; if (tool.DrawTool()) { return(tool); } var result = GUILayout.Toggle(this.drawingToolIndex == tool.Uid, tool.ButtonContent, style, options); // detect a tool change if (result && this.drawingToolIndex != tool.Uid) { // if there is a current tool shut it down if (this.currentTool != null) { this.currentTool.Shutdown(); } // store reference to the old tool var oldTool = this.currentTool; // save index to tool this.drawingToolIndex = tool.Uid; // set current tool this.currentTool = tool; this.currentTool.Startup(this); // save tool UID as the last tool used settings.SetValue(GlobalConstants.Map2DLastEditorDrawingToolUidKey, this.currentTool.Uid.ToString()); // notify service so code hooks can receive notifications Map2DService.Instance.OnEditorDrawingToolSelected(oldTool, tool); } // return same tool reference return(tool); }, values, buttonsPerRow, GUI.skin.button, GUILayout.Height(size), GUILayout.Width(size)); GUILayout.EndHorizontal(); }
/// <summary> /// Initializes a new instance of the <see cref="Map2DTileSelection"/> class. /// </summary> public Map2DTileSelection() { // setup controls and variables this.materialControls = new GenericMaterialCreationControl(); this.mainPreview = new TileSelectionControl(); this.materialControls.ShowFreeform = false; this.materialControls.ShowColor = false; this.materialControls.ShowShader = false; this.mainPreview.MultipleTileSelection = false; this.mainPreview.ShowHoverRectangle = false; // hook into the before spacing drawn event to allow us to customize the look this.materialControls.BeforeSpacingDrawn = () => GUILayout.BeginVertical(); // hook into the after spacing drawn event to allow us to customize the look this.materialControls.AfterSpacingDrawn = () => { GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false)); var items = new bool[4]; items[this.mainPreview.Zoom - 1] = true; ControlGrid.DrawGenericGrid( (data, index, style, options) => { var result = GUILayout.Toggle(data[index], (index + 1).ToString(CultureInfo.InvariantCulture), style, options); if (result != data[index]) { this.mainPreview.Zoom = index + 1; } return(result); }, items, items.Length, GUI.skin.button); GUILayout.EndHorizontal(); GUILayout.EndVertical(); }; // hook into the tile selection event on the main preview control this.mainPreview.TileSelection += this.MainPreviewTileSelection; // hook into the main preview texture changed so we can generate a generic image for the selected texture this.mainPreview.TextureChanged += this.MainPreviewTextureChanged; // Hook into the texture changed event and update the texture and selected texture id's this.materialControls.TextureChanged += (s, e) => { this.mainPreview.TextureAsset = this.materialControls.TextureAsset; }; // ensure preview texture size is updated this.materialControls.TileSizeChanged += (s, e) => { this.mainPreview.TileHeight = this.materialControls.TileHeight; this.mainPreview.TileWidth = this.materialControls.TileWidth; }; // hook into events to sync control properties this.materialControls.StartSpacingChanged += (s, e) => { this.mainPreview.StartSpacing = this.materialControls.StartSpacing; }; this.materialControls.SpacingChanged += (s, e) => { this.mainPreview.Spacing = this.materialControls.Spacing; }; this.materialControls.FreeformChanged += (s, e) => { this.mainPreview.FreeForm = this.materialControls.FreeForm; }; // sync control properties this.mainPreview.Refresh += (s, e) => this.Repaint(); this.mainPreview.StartSpacing = this.materialControls.StartSpacing; this.mainPreview.Spacing = this.materialControls.Spacing; this.mainPreview.FreeForm = this.materialControls.FreeForm; }
/// <summary> /// Draws the list of layers. /// </summary> private void DrawLayerList() { var service = Map2DService.Instance; if (service.ActiveMapIndex < 0) { return; } var map = service.GetActiveMap(); if (map.Layers == null) { return; } var layers = new Map2DLayerModel[map.Layers.Count]; map.Layers.CopyTo(layers, 0); this.scrollValue = GUILayout.BeginScrollView(this.scrollValue, false, false); GUILayout.BeginVertical(); ControlGrid.DrawGenericGrid( (data, index, style, options) => { //GUILayout.BeginHorizontal(GUI.skin.box, GUILayout.Height(64), GUILayout.ExpandWidth(true)); //GUILayout.BeginVertical(GUILayout.ExpandWidth(true)); var layerModel = data[index]; var nameText = layerModel.Name; nameText = nameText ?? string.Empty; if (index == map.ActiveLayer) { GUI.SetNextControlName("txtLayerName" + index); layerModel.Name = GUILayout.TextField(nameText, GUILayout.MinWidth(32)); } else { if (GUILayout.Button(nameText, GUILayout.MinWidth(32))) { map.ActiveLayer = index; GUI.FocusControl("txtLayerName" + index); service.OnRepaintMap(); } } //GUILayout.BeginHorizontal(); //GUILayout.EndHorizontal(); //GUILayout.EndVertical(); //GUILayout.FlexibleSpace(); //var texture = layerModel.Texture; //if (texture != null) //{ // if (GUILayout.Button(string.Empty, GUI.skin.label, GUILayout.MaxWidth(64), GUILayout.Height(64))) // { // Debug.Log("here"); // } // GUI.DrawTexture(GUILayoutUtility.GetLastRect(), texture, ScaleMode.ScaleToFit, false); //} //GUILayout.EndHorizontal(); return(layerModel); }, layers, 1, null); GUILayout.EndVertical(); GUILayout.FlexibleSpace(); GUILayout.EndScrollView(); }