public MapSceneWindow(Rect aStartPos, GUIStyle aStyle, params GUILayoutOption[] aOptions) : base(aStartPos, new GUIContent("Map Scenes"), aStyle, aOptions)
        {
            var _ = GeoController.Instance;

            ButtonContent = new GUIContent()
            {
                image = Resources.Load <Texture2D>("EAdventureData/img/icons/map"),
                text  = "Geo.MapScene.Title".Traslate()
            };

            mapEditor = new MapEditor()
            {
                Components = uAdventureWindowMain.Components,
                Elements   = new List <DataControl> {
                    null
                },
                Repaint       = () => Repaint(),
                PlaceSearcher = { OnRequestRepaint = () => OnRequestRepaint() }
            };

            appearanceWindow = new MapSceneWindowAppearance(aStartPos, new GUIContent(), aStyle, mapEditor, aOptions);

            AddTab(TC.get("Geo.MapScene.AppearanceWindow.Title"), MapSceneWindows.Appearance, appearanceWindow);
            AddTab(TC.get("Geo.MapScene.ReferencesWindow.Title"), MapSceneWindows.References, new MapSceneWindowReferences(aStartPos, new GUIContent(), aStyle, mapEditor, aOptions));
            AddTab(TC.get("Geo.MapScene.DocumentationWindow.Title"), MapSceneWindows.Documentation, new MapSceneWindowDocumentation(aStartPos, new GUIContent(), aStyle, aOptions));
        }
        protected override void OnRectChanged(MapEditor mapEditor, Rect previousScreenRect, Rect newScreenRect)
        {
            base.OnRectChanged(mapEditor, previousScreenRect, newScreenRect);
            var rectBase = new Vector2(Mathf.RoundToInt(newScreenRect.x + 0.5f * newScreenRect.width), Mathf.RoundToInt(newScreenRect.y + newScreenRect.height));

            transformManagerDataControl["Position"] = mapEditor.PixelToLatLon(mapEditor.RelativeToAbsolute(rectBase.ToVector2d()));
        }
 public ChangeGeometryTypeTool(GMLGeometry gmlGeometry, GMLGeometry.GeometryType geometryType, MapEditor mapEditor)
 {
     this.gmlGeometry          = gmlGeometry;
     this.previousPoints       = gmlGeometry.Points.ToArray();
     this.previousGeometryType = gmlGeometry.Type;
     this.newGeometryType      = geometryType;
     this.mapEditor            = mapEditor;
     zoom   = mapEditor.Zoom;
     center = mapEditor.Center;
 }
Ejemplo n.º 4
0
        protected override void OnRectChanged(MapEditor mapEditor, Rect previousScreenRect, Rect newScreenRect)
        {
            base.OnRectChanged(mapEditor, previousScreenRect, newScreenRect);

            var screen      = mapEditor.ScreenRect;
            var newPosition = newScreenRect.Base() - screen.position;
            // We calculate the positioner center in the screen (from 0 to 1)
            var positionerCenter01 = new Vector2(newPosition.x / screen.width, newPosition.y / screen.height);

            // Then we calculate the positioner center pixel in the screen real position
            transformManagerDataControl["Position"] = new Vector2(positionerCenter01.x * gameWidth, positionerCenter01.y * gameHeight);
        }
Ejemplo n.º 5
0
            public override void OnDrawingGizmos()
            {
                var gameplayArea = Target as GameplayAreaDataControl;

                if (!gameplayArea.UsesGameplayArea)
                {
                    return;
                }

                var viewRect         = MapEditor.Current.ScreenRect.ToPoints();
                var gameplayAreaRect = MapEditor.Current.ToRelative(MapEditor.Current.LatLonToPixels(gameplayArea.BoundingBox.ToPoints())).ToRectD().ToRect().ToPoints();

                var points = new Vector2[]
                {
                    // TopLeft
                    viewRect[0],
                    gameplayAreaRect[0],
                    // TopCenter
                    new Vector2(gameplayAreaRect[0].x, viewRect[0].y),
                    gameplayAreaRect[1],
                    // TopRight
                    new Vector2(gameplayAreaRect[1].x, viewRect[0].y),
                    new Vector2(viewRect[1].x, gameplayAreaRect[1].y),
                    // MiddleRight
                    gameplayAreaRect[1],
                    new Vector2(viewRect[1].x, gameplayAreaRect[2].y),
                    // BottomRight
                    gameplayAreaRect[2],
                    viewRect[2],
                    // BottomCenter
                    gameplayAreaRect[3],
                    new Vector2(gameplayAreaRect[2].x, viewRect[2].y),
                    // BottomLeft
                    new Vector2(viewRect[3].x, gameplayAreaRect[3].y),
                    new Vector2(gameplayAreaRect[3].x, viewRect[3].y),
                    // MiddleLeft
                    new Vector2(viewRect[0].x, gameplayAreaRect[0].y),
                    gameplayAreaRect[3]
                };

                for (int i = 0; i < points.Length; i += 2)
                {
                    var rect = new Rect(points[i], points[i + 1] - points[i]);
                    if (rect.width > 0 || rect.height > 0)
                    {
                        Handles.BeginGUI();
                        Handles.color = MapEditor.GetColor(new Color(0, 0, 0, 0.5f));
                        Handles.DrawAAConvexPolygon(rect.ToPoints3());
                        Handles.EndGUI();
                    }
                }
            }
Ejemplo n.º 6
0
        public override Vector2 ToScreenPoint(MapEditor mapEditor, Vector2 point)
        {
            var angle = this.degree * Mathf.Deg2Rad;

            var centerMeters = GM.LatLonToMeters(mapEditor.Center.x, mapEditor.Center.y);
            var metersPos    = centerMeters + new Vector2d(distance * Mathd.Sin(angle), distance * Mathd.Cos(angle));
            var pixelsPos    = GM.MetersToPixels(metersPos, mapEditor.Zoom);
            var basePixel    = mapEditor.PixelToRelative(pixelsPos).ToVector2();

            var pixelScale = GM.MetersToPixels(GM.PixelsToMeters(new Vector2d(scale, scale), 19), mapEditor.Zoom);

            return(basePixel + new Vector2((float)(point.x * pixelScale.x), (float)(point.y * pixelScale.y)));
        }
        public override Vector2 FromScreenPoint(MapEditor mapEditor, Vector2 point)
        {
            var pixelScaleAt = GM.GetPixelsPerMeter(position.x, 19) / GM.GetPixelsPerMeter(0, 19);
            // First we get the scale of the pixels based on the current zoom
            var pixelScale = GM.MetersToPixels(GM.PixelsToMeters(new Vector2d(scale, scale), 19), mapEditor.Zoom) * pixelScaleAt;
            // Then we calculate the center
            var center = mapEditor.PixelToRelative(GM.MetersToPixels(GM.LatLonToMeters(position.x, position.y), mapEditor.Zoom)).ToVector2();

            // We make the point relative to center
            point -= center;
            // And finally we unscale the relative point
            return(new Vector2(point.x / (float)pixelScale.x, point.y / (float)pixelScale.y));
        }
        public override Vector2 ToScreenPoint(MapEditor mapEditor, Vector2 point)
        {
            // Scale of 1 means 1 pixel is 1 map pixel in scale 19
            // Scale of 2 means 1 pixel is 0.5 map pixel in scale 18
            // and so on...

            var pixelScaleAt = GM.GetPixelsPerMeter(position.x, 19) / GM.GetPixelsPerMeter(0, 19);
            var pixelScale   = GM.MetersToPixels(GM.PixelsToMeters(new Vector2d(scale, scale), 19), mapEditor.Zoom) * pixelScaleAt;

            var center = mapEditor.PixelToRelative(GM.MetersToPixels(GM.LatLonToMeters(position.x, position.y), mapEditor.Zoom)).ToVector2();

            return(center + new Vector2((float)(point.x * pixelScale.x), (float)(point.y * pixelScale.y)));
        }
Ejemplo n.º 9
0
        public override Vector2 ToScreenPoint(MapEditor mapEditor, Vector2 point)
        {
            var screen      = mapEditor.ScreenRect;
            var heightRatio = screen.height / gameHeight;
            // First we scale relative to the (0,0) and revert the y
            var scaled = new Vector2((point.x * scale) * heightRatio, (point.y * scale) * heightRatio);
            // Sidely, we calculate the positioner center in the screen (from 0 to 1)
            var positionerCenter01 = new Vector2(position.x / gameWidth, position.y / gameHeight);
            // Then we calculate the positioner center pixel in the screen real position
            var positionerCenterPixel = screen.position + new Vector2(positionerCenter01.x * screen.width, positionerCenter01.y * screen.height);

            // And we combine the relative position to the center position
            return(scaled + positionerCenterPixel);
        }
Ejemplo n.º 10
0
        public override Vector2 FromScreenPoint(MapEditor mapEditor, Vector2 point)
        {
            var screen      = mapEditor.ScreenRect;
            var heightRatio = gameHeight / screen.height;
            // We calculate the positioner center in the screen (from 0 to 1)
            var positionerCenter01 = new Vector2(position.x / gameWidth, position.y / gameHeight);
            // Then we calculate the positioner center pixel in the screen real position
            var positionerCenterPixel = screen.position + new Vector2(positionerCenter01.x * screen.width, positionerCenter01.y * screen.height);
            // Then we get the local position
            var localPos = point - positionerCenterPixel;

            // And we return the unscaled version with the Y reverted
            return(new Vector2((localPos.x * heightRatio) / scale, (localPos.y * heightRatio) / scale));
        }
        public override void OnDrawingGizmosSelected(MapEditor mapEditor, Vector2[] points)
        {
            base.OnDrawingGizmosSelected(mapEditor, points);

            var center = points.Select(p => ToScreenPoint(mapEditor, p)).Center();

            Handles.BeginGUI();

            var influencePixels = mapEditor.MetersToPixelsAt(position, interactionRange);

            Handles.color = Color.black;
            Handles.DrawWireArc(center, Vector3.back, Vector2.up, 360, influencePixels);
            Handles.EndGUI();
        }
Ejemplo n.º 12
0
        protected override void OnRectChanged(MapEditor mapEditor, Rect previousScreenRect, Rect newScreenRect)
        {
            base.OnRectChanged(mapEditor, previousScreenRect, newScreenRect);

            var newPos       = newScreenRect.Base().ToVector2d();
            var metersPos    = GM.PixelsToMeters(mapEditor.RelativeToAbsolute(newPos), mapEditor.Zoom);
            var centerMeters = GM.LatLonToMeters(mapEditor.Center.x, mapEditor.Center.y);

            var metersVector = metersPos - centerMeters;

            float angle = Vector3.Angle(new Vector3(0.0f, 1.0f, 0.0f), new Vector3((float)metersVector.normalized.x, (float)metersVector.normalized.y, 0.0f));

            if (metersVector.x < 0.0f)
            {
                angle = 360.0f - angle;
            }

            transformManagerDataControl["Distance"] = (float)metersVector.magnitude;
            transformManagerDataControl["Degree"]   = angle;
        }
        private static void Center(MapEditor mapEditor, MapElementDataControl mapElement)
        {
            var extElementReference = mapElement as ExtElementRefDataControl;
            var geoElementReference = mapElement as GeoElementRefDataControl;

            if (extElementReference != null)
            {
                var sprite = ScenesWindowElementReference.ReferenceComponent.GetSprite(extElementReference);
                if (!sprite)
                {
                    mapEditor.Center = (Vector2d)extElementReference.TransformManager["Position"];
                }
                else
                {
                    var texture = sprite.texture;
                    var rect    = new RectD(new Vector2d(-0.5f * texture.width, -texture.height),
                                            new Vector2d(texture.width, texture.height));

                    var previousTransformManager = mapEditor.PositionManager;
                    mapEditor.PositionManager = extElementReference.TransformManager.GUIMapPositionManager;
                    var relativeRect = mapEditor.ToRelative(rect.ToPoints()).ToRectD();
                    mapEditor.PositionManager = previousTransformManager;
                    var boundingBox = relativeRect.ToPoints()
                                      .Select(p => mapEditor.PixelToLatLon(mapEditor.RelativeToAbsolute(p)))
                                      .ToArray()
                                      .ToRectD();

                    mapEditor.ZoomToBoundingBox(boundingBox);
                    mapEditor.Center = boundingBox.Center;
                }
            }
            else if (geoElementReference != null)
            {
                var geoElement = geoElementReference.ReferencedDataControl as GeoElementDataControl;
                var geometry   = geoElement.GMLGeometries[geoElement.SelectedGeometry];
                mapEditor.ZoomToBoundingBox(geometry.BoundingBox);
                mapEditor.Center = geometry.BoundingBox.Center;
            }
        }
Ejemplo n.º 14
0
        public GeoElementWindow(Rect aStartPos, GUIStyle aStyle, params GUILayoutOption[] aOptions) : base(aStartPos, new GUIContent("Geo.GeoElement.Title".Traslate()), aStyle, aOptions)
        {
            ButtonContent = new GUIContent
            {
                image = Resources.Load <Texture2D>("EAdventureData/img/icons/poi"),
                text  = "Geo.GeoElement.Title".Traslate()
            };

            mapEditor = new MapEditor()
            {
                Components = EditorWindowBase.Components,
                Elements   = new List <DataControl> {
                    null
                },
                Repaint       = () => Repaint(),
                PlaceSearcher = { OnRequestRepaint = () => OnRequestRepaint() }
            };

            geometryComponent = new GeoElementWindowGeometry(aStartPos, new GUIContent(), aStyle, mapEditor, aOptions);

            AddTab(TC.get("Geo.GeoElement.GeometryWindow.Title"), GeoElementWindows.Geometry, geometryComponent);
            AddTab(TC.get("Geo.GeoElement.DescriptionWindow.Title"), GeoElementWindows.Description, new GeoElementWindowDescription(aStartPos, new GUIContent(), aStyle, aOptions));
            AddTab(TC.get("Geo.GeoElement.ActionsWindow.Title"), GeoElementWindows.Actions, new GeoElementWindowActions(aStartPos, new GUIContent(), aStyle, aOptions));
        }
Ejemplo n.º 15
0
            public override void OnDrawingGizmosSelected()
            {
                var gameplayArea = Target as GameplayAreaDataControl;

                if (!gameplayArea.UsesGameplayArea)
                {
                    return;
                }

                var gameplayAreaRect = MapEditor.Current.ToRelative(MapEditor.Current.LatLonToPixels(gameplayArea.BoundingBox.ToPoints()))
                                       .ToRectD().ToRect();


                var handleRectID = GUIUtility.GetControlID(GetHashCode(), FocusType.Passive);

                EditorGUI.BeginChangeCheck();
                Handles.BeginGUI();
                var newRect = HandleUtil.HandleRect(handleRectID, gameplayAreaRect, 10, (_, __, ___) => { },
                                                    (p, hover, active) => HandleUtil.DrawSquare(p, 10, MapEditor.GetColor(Color.yellow),
                                                                                                hover ? MapEditor.GetColor(Color.red) : MapEditor.GetColor(Color.black)));

                Handles.EndGUI();
                if (EditorGUI.EndChangeCheck())
                {
                    var latLonRect = MapEditor.Current
                                     .PixelsToLatLon(MapEditor.Current.FromRelative(newRect.ToRectD().ToPoints())).ToRectD();
                    gameplayArea.BoundingBox = latLonRect;
                }
            }
        /* ----------------------------------
         * GUI ELEMENTS
         * -----------------------------------*/

        public MapWindow(Rect rect, GUIContent content, GUIStyle style, MapEditor componentBasedEditor, params GUILayoutOption[] options) : base(rect, content, style, componentBasedEditor, options)
        {
        }
Ejemplo n.º 17
0
        public GeoElementWindowGeometry(Rect aStartPos, GUIContent aContent, GUIStyle aStyle, MapEditor mapEditor, params GUILayoutOption[] aOptions)
            : base(aStartPos, aContent, aStyle, mapEditor, aOptions)
        {
            PreviewTitle = "Item.Preview".Traslate();

            conditionsTex   = Resources.Load <Texture2D>("EAdventureData/img/icons/conditions-24x24");
            noConditionsTex = Resources.Load <Texture2D>("EAdventureData/img/icons/no-conditions-24x24");

            typeNames = Enum.GetNames(typeof(GMLGeometry.GeometryType)).Select(n => TC.get("Geo.GeoElement.Geometry.Type." + n + ".Name")).ToArray();

            AbstractEditorComponent.RegisterComponent(this);

            geometriesList = new DataControlList
            {
                Columns = new List <ColumnList.Column>
                {
                    new ColumnList.Column
                    {
                        Text = "Name"
                    },
                    new ColumnList.Column
                    {
                        Text = "Type"
                    },
                    new ColumnList.Column
                    {
                        Text = "Conditions"
                    }
                },
                drawCell = (rect, row, column, active, focused) =>
                {
                    var geometry = this.geometriesList.list[row] as GMLGeometryDataControl;
                    switch (column)
                    {
                    case 0:
                    {
                        if (active)
                        {
                            var indexRect = new Rect(rect.position, new Vector2(30, rect.height));
                            var nameRect  = new Rect(rect.position + Vector2.right * 30, new Vector2(rect.width - 30, rect.height));
                            EditorGUI.BeginChangeCheck();
                            GUI.Label(indexRect, (row + 1) + ":");
                            var newName = GUI.TextField(nameRect, geometry.Name);
                            if (EditorGUI.EndChangeCheck())
                            {
                                geometry.Name = newName;
                            }
                        }
                        else
                        {
                            GUI.Label(rect, (row + 1) + ":" + geometry.Name);
                        }
                    }
                    break;

                    case 1:
                    {
                        GUI.Label(rect, TC.get("Geo.GeoElement.Geometry.Type." + geometry.Type + ".Name"));
                    }
                    break;

                    case 2:
                        if (GUI.Button(rect,
                                       geometry.Conditions.getBlocksCount() > 0 ? conditionsTex : noConditionsTex))
                        {
                            this.geometriesList.index = row;
                            var window = ScriptableObject.CreateInstance <ConditionEditorWindow>();
                            window.Init(geometry.Conditions);
                        }
                        break;
                    }
                },
                onSelectCallback = list =>
                {
                    if (list.index > -1)
                    {
                        workingGeoElement.SelectedGeometry = list.index;
                        Center(workingGeoElement.GMLGeometries[workingGeoElement.SelectedGeometry]);
                    }
                },
                onRemoveCallback = list =>
                {
                    if (workingGeoElement.SelectedGeometry > -1)
                    {
                        workingGeoElement.SelectedGeometry = Mathf.Max(0, workingGeoElement.SelectedGeometry - 1);
                        Center(workingGeoElement.GMLGeometries[workingGeoElement.SelectedGeometry]);
                        list.index = workingGeoElement.SelectedGeometry;
                    }
                }
            };
        }
        public MapSceneWindowReferences(Rect rect, GUIContent content, GUIStyle style, MapEditor componentBasedEditor, params GUILayoutOption[] options)
            : base(rect, content, style, componentBasedEditor, options)
        {
            conditionsTex   = Resources.Load <Texture2D>("EAdventureData/img/icons/conditions-24x24");
            noConditionsTex = Resources.Load <Texture2D>("EAdventureData/img/icons/no-conditions-24x24");
            centerTex       = Resources.Load <Texture2D>("EAdventureData/img/icons/center-24x24");

            icons = new Dictionary <Type, Texture2D>()
            {
                { typeof(GeoElementDataControl), Resources.Load <Texture2D>("EAdventureData/img/icons/poi") },
                { typeof(PlayerDataControl), Resources.Load <Texture2D>("EAdventureData/img/icons/player-old") },
                { typeof(ItemDataControl), Resources.Load <Texture2D>("EAdventureData/img/icons/item") },
                { typeof(AtrezzoDataControl), Resources.Load <Texture2D>("EAdventureData/img/icons/atrezzo-1") },
                { typeof(NPCDataControl), Resources.Load <Texture2D>("EAdventureData/img/icons/npc") }
            };

            new MapReferenceComponent(rect, null, style, null);

            mapElements = new DataControlList
            {
                Columns = new List <ColumnList.Column>
                {
                    new ColumnList.Column
                    {
                        Text = TC.get("ElementList.Title")
                    },
                    new ColumnList.Column
                    {
                        Text        = TC.get("Geo.MapScene.ReferenceList.Column.Center"),
                        SizeOptions = new [] { GUILayout.Width(24f) },
                    },
                    new ColumnList.Column()
                    {
                        Text = TC.get("Conditions.Title")
                    }
                },
                drawCell = (cellRect, row, column, active, focused) =>
                {
                    var mapElement = mapElements.list[row] as MapElementDataControl;
                    switch (column)
                    {
                    case 0:
                        var iconSpace = new Rect(cellRect);
                        var nameSpace = new Rect(cellRect);
                        iconSpace.size      = new Vector2(16, nameSpace.size.y);
                        nameSpace.position += new Vector2(16, 0);
                        nameSpace.size     += new Vector2(-16, 0);

                        Texture2D icon = null;
                        var       type = mapElement.ReferencedDataControl.GetType();
                        if (icons.ContainsKey(type))
                        {
                            icon = icons[type];
                        }
                        if (icon != null)
                        {
                            GUI.Label(iconSpace, icons[type]);
                        }
                        GUI.Label(icon != null ? nameSpace : cellRect, mapElement.ReferencedId);
                        break;

                    case 1:
                        var elementReference = mapElement as ExtElementRefDataControl;

                        if ((elementReference == null || elementReference.TransformManager.PositionManagerName == "WorldPositioned") &&
                            GUI.Button(cellRect, centerTex))
                        {
                            Center(componentBasedEditor, mapElement);
                        }
                        break;

                    case 2:
                        if (GUI.Button(cellRect,
                                       mapElement.Conditions.getBlocksCount() > 0 ? conditionsTex : noConditionsTex))
                        {
                            this.mapElements.index = row;
                            var window = ScriptableObject.CreateInstance <ConditionEditorWindow>();
                            window.Init(mapElement.Conditions);
                        }
                        break;
                    }
                }
            };
            mapElements.onSelectCallback += list =>
            {
                componentBasedEditor.SelectedElement = (DataControl)(mapElements.index == -1 ? null : mapElements.list[mapElements.index]);
            };

            componentBasedEditor.onSelectElement += elem =>
            {
                mapElements.index = mapElements.list.IndexOf(elem);
            };
        }
Ejemplo n.º 19
0
        public MapSceneWindowAppearance(Rect rect, GUIContent content, GUIStyle style, MapEditor componentBasedEditor, params GUILayoutOption[] options)
            : base(rect, content, style, componentBasedEditor, options)
        {
            renderStyles = Enum.GetNames(typeof(RenderStyle))
                           .Select(e => TC.get("Geo.MapScene.Appearance.RenderStyle." + e)).ToArray();
            cameraTypes = Enum.GetNames(typeof(CameraType))
                          .Select(e => TC.get("Geo.MapScene.Appearance.CameraType." + e)).ToArray();
            tileMetaNames = TileProvider.Instance.PublicMetas.Select(m => TC.get(m.Name)).ToArray();

            new GameplayAreaComponent(rect, content, style, options);

            disabledTypes = new Dictionary <Type, bool>
            {
                { typeof(GeoElementRefDataControl), false },
                { typeof(ExtElementRefDataControl), false }
            };
        }