/// <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();
        }
示例#2
0
        void ShowControls()
        {
            var anim = new DoubleAnimation(107, (Duration)TimeSpan.FromSeconds(1));

            anim.EasingFunction = ee;
            anim.Completed     += (s, _) => Expanded = true;
            ControlGrid.BeginAnimation(ContentControl.WidthProperty, anim);
        }
示例#3
0
        private void OpenControlGrid(UIElement sender)
        {
            ControlGrid.Visibility = Visibility.Visible;
            ControlGrid.UpdateLayout();

            var element = sender.TransformToVisual(this).TransformBounds(new Rect(sender.RenderSize));
            var content = ControlGrid.TransformToVisual(this).TransformBounds(new Rect(ControlGrid.RenderSize));

            var maxX = this.RenderSize.Width - content.Width;
            var x    = Convert.ToSingle(Math.Max(0, Math.Min(element.X, maxX)));

            Canvas.SetLeft(ControlGrid, x);
            Canvas.SetTop(ControlGrid, element.Bottom);

            UpdateArrow(element, new Rect(new Point(x, element.Bottom), ControlGrid.RenderSize));
        }
示例#4
0
        private void MainWindow_OnMouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ClickCount >= 2)
            {
                var point = Mouse.GetPosition(this);
                if (Controller.TransformToVisual(this).TransformBounds(new Rect(Controller.RenderSize)).Contains(point))
                {
                    return;
                }
                if (ControlGrid.TransformToVisual(this).TransformBounds(new Rect(ControlGrid.RenderSize)).Contains(point))
                {
                    return;
                }

                CopyToClipBoard();
                this.Close();
            }

            UpdateXY();
        }
        /// <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();
        }