Maintains the editor grid has a correct position to keep the grid aligned with the square and elements on game.
Inheritance: MonoBehaviour
 public static TrackReader AcquireRead(ResourceSync sync, Track track, EditorGrid cells)
 {
     return(new TrackReader(sync.AcquireRead(), track)
     {
         _editorcells = cells
     });
 }
Exemple #2
0
        /// <summary>
        /// Load Level Image and Metadata
        /// </summary>
        /// <param name="editorGrid"></param>
        /// <param name="levelName"></param>
        /// <param name="filePath"></param>
        public void LoadLevel(EditorGrid editorGrid, string levelName, string filePath)
        {
            //File Paths for both the image and metadata
            string gridLoadFilePath     = System.IO.Path.Combine(filePath, levelName + ".png");
            string metadataLoadFilePath = System.IO.Path.Combine(filePath, levelName + ".json");

            //Load image and metadata
            BitmapImage   loadedImage;
            LevelMetadata loadedMetadata;

            //Try to load images and metadata
            try
            {
                loadedImage    = LoadGridImage(gridLoadFilePath);
                loadedMetadata = LoadGridMetadata(metadataLoadFilePath);
            }
            catch (FileNotFoundException)
            {
                //If the we failed to load the files, show an error window and exit of loading function
                new FileImportErrorDialouge().ShowDialog();
                return;
            }

            //Apply loaded level to the level editorGrid and set level title in the info bar
            InsertImageToGrid(editorGrid, loadedImage, loadedMetadata);
        }
Exemple #3
0
        /// <summary>
        /// Saves a editorGrid as an image to a specficified output location
        /// </summary>
        /// <param name="editorGrid">editorGrid to save</param>
        /// <param name="filePath">File path to save image to</param>
        private void SaveGridImage(EditorGrid editorGrid, string filePath)
        {
            //Get the width of the editorGrid
            int dpi    = 96; //One of the standard dpi (72/96) We're not using DPI. It would be for printing/viewing (dots per inch)
            int width  = editorGrid.GridWidth * editorGrid.GridBoxSize;
            int height = editorGrid.GridHeight * editorGrid.GridBoxSize;

            //Renders to a target bitmap
            RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(width, height, dpi, dpi, PixelFormats.Pbgra32);

            renderTargetBitmap.Render(editorGrid.TileGrid);

            //Encodes to a PNG
            PngBitmapEncoder pngImage = new PngBitmapEncoder();

            pngImage.Frames.Add(BitmapFrame.Create(renderTargetBitmap));

            //Writes PNG encoded image to file

            using (System.IO.Stream fileStream = System.IO.File.Create(filePath))
            {
                pngImage.Save(fileStream);
                fileStream.Close();
            }
        }
Exemple #4
0
        private void DrawDefines(AppConfig appConfig, float width)
        {
            definesGridDefinition[0].Width = (int)(width - 90.0f);

            bool definesVisible = false;

            using (new FoldoutScope(564185451, "Defines", out definesVisible, true))
            {
                if (definesVisible == false)
                {
                    return;
                }

                using (new BeginGridScope(definesGrid))
                {
                    for (int i = 0; i < appConfig.Defines.Count; i++)
                    {
                        using (new BeginGridRowScope(definesGrid))
                        {
                            appConfig.Defines[i] = definesGrid.DrawString(appConfig.Defines[i]);
                        }

                        EditorGrid.UpdateList <string>(definesGrid.RowButtonPressed, appConfig.Defines, i);
                    }

                    if (definesGrid.DrawAddButton())
                    {
                        appConfig.Defines.Add(string.Empty);
                    }
                }
            }
        }
Exemple #5
0
    public void BtnSaveMapInitPanel()
    {
        xl       = Convert.ToInt32(XlDropdown.options[XlDropdown.value].text);
        yl       = Convert.ToInt32(YlDropdown.options[YlDropdown.value].text);
        newLevel = new Level(LevelNameInputField.text, xl, yl, "GamePlay04");
        MapInitPanel.SetActive(false);

        GameObject GridPrefab = Resources.Load("Prefabs/Grid") as GameObject;

        for (int i = 0; i < xl; i++)
        {
            for (int j = 0; j < yl; j++)
            {
                GameObject grid       = Instantiate(GridPrefab);
                EditorGrid editorGrid = grid.AddComponent <EditorGrid>();
                editorGrid.GridID = i * 10 + j;
                grid.transform.SetParent(GridSpawnPoint.transform, false);
                grid.GetComponent <Image>().color = Color.white;
                grid.transform.localPosition      = new Vector3(i * 100, j * 100, 0);
            }
        }

        /*GameObject[] UIElements = GameObject.FindGameObjectsWithTag("UIElement");
         * foreach (GameObject go in UIElements) go.AddComponent<UIDragHandler>();*/
        newLevel.SetPropsCount(Convert.ToInt32(TipsProps.options[TipsProps.value].text),
                               Convert.ToInt32(ResetProps.options[ResetProps.value].text));


        BtnSaveMap.SetActive(true);
    }
 void Start()
 {
     editorGrid = GameObject.FindGameObjectWithTag("EditorGrid").GetComponent <EditorGrid>();
     if (editorGrid)
     {
         oldOffset = editorGrid.offset;
     }
 }
    private void Start()
    {
        g = GetComponent <EditorGrid>();

        level_blocks       = new Dictionary <Vector3Int, Transform>();
        obstacle_blocks    = new Dictionary <Vector3Int, Transform>();
        selectable_objects = new Dictionary <Vector3Int, Transform>();
        // Fill level_blocks
        init_blocks();
    }
Exemple #8
0
    public void OnEnable()
    {
        grid = (EditorGrid)target;
        // Remove first so it doesnt stack
        SceneView.onSceneGUIDelegate -= GridUpdate;
        // Then add delegate
        SceneView.onSceneGUIDelegate += GridUpdate;

        grid.cellSelector = grid.transform.GetChild(0).gameObject;
    }
        private void OnEnable()
        {
            _grid = new EditorGrid(GridBackgroundColor);
            var lColor = GridLineColor;

            _grid.AddLayer(10, 0.2f, lColor);
            _grid.AddLayer(100, 0.4f, lColor);
            _grid.offsetHandler     = () => _dOffset;
            Undo.undoRedoPerformed += OnUndo;
        }
Exemple #10
0
        /// <summary>
        /// Inserts an image in to a specifed grid
        /// </summary>
        /// <param name="editorGrid">Grid to Insert into</param>
        /// <param name="image">Image to insert in to grid</param>
        /// <param name="metadata"> Metadata of Image to insert in to grid</param>
        private void InsertImageToGrid(EditorGrid editorGrid, BitmapImage image, LevelMetadata metadata)
        {
            //Create a new editorGrid with values from our metadata
            int  newGridWidth   = metadata.levelGridWidth;
            int  newGridHeight  = metadata.levelGridHeight;
            int  newGridBoxSize = metadata.levelGridBoxSize;
            Grid newGrid        = editorGrid.CreateGrid(newGridWidth, newGridHeight, newGridBoxSize);

            //Get grid to insert our image in to tiles
            editorGrid.SplitImageInToGrid(image);
        }
Exemple #11
0
 void Start()
 {
     gridAlign         = GetComponent <EditorGrid>();
     gridAlign.enabled = false;
     anim = GetComponent <Animator>();
     tr   = GetComponent <Transform>();
     InvokeRepeating("Move", .5f, repeatRate);
     playerDir = Direction.none;
     lastDirLR = Direction.rightMov;
     lastDirUD = Direction.upMov;
 }
Exemple #12
0
 private void OnEnable()
 {
     halfNode     = nodeSize / 2;
     coin         = (GameObject)AssetDatabase.LoadAssetAtPath("Assets/Prefabs/Coin.prefab", typeof(GameObject));
     style        = (GUISkin)Resources.Load("CustomSkin");
     go           = LoadGamePieces <GameObject>("Resources/GamePieces");
     amountToDrop = new int[go.Length];
     grid         = new EditorGrid();
     ChangeGridSize();
     amountToDrop = new int[go.Length];
 }
Exemple #13
0
        /// <summary>
        /// Creates a new folder for this level and saves editorGrid image and metadata inside it
        /// </summary>
        /// <param name="editorGrid">editorGrid to save</param>
        /// <param name="levelName">Level name to save as</param>
        /// <param name="filePath">File Path to create folder and save at</param>
        public void SaveLevel(EditorGrid editorGrid, string levelName = "untitled_level", string filePath = "")
        {
            //Format file path and save editorGrid image (e.g C:LevelSaves\levelName\levelName.png)
            string gridSaveFilePath = System.IO.Path.Combine(filePath, levelName + ".png");

            SaveGridImage(editorGrid, gridSaveFilePath);

            //Formate file path and save metadata (e.g C:LevelSaves\levelName\levelName.json)
            string metadataLoadFilePath = System.IO.Path.Combine(filePath, levelName + ".json");

            SaveGridMetadata(editorGrid, metadataLoadFilePath, levelName);
        }
Exemple #14
0
        private void OnEnable()
        {
            if (definesGrid == null)
            {
                definesGridDefinition = new EditorGridDefinition();
                definesGridDefinition.AddColumn("Define", 200);
                definesGridDefinition.RowButtons = GridButton.All;
                definesGridDefinition.DrawHeader = false;

                definesGrid = new EditorGrid(definesGridDefinition);
            }
        }
Exemple #15
0
        public void TestGizmo()
        {
            XNAGame game = new XNAGame();

            EditorGizmoTranslation translationGizmo = new EditorGizmoTranslation();
            EditorGrid             grid             = new EditorGrid();

            translationGizmo.Position = new Vector3(0, 0, 0);
            translationGizmo.Enabled  = true;

            grid.Size          = new Vector2(100, 100);
            grid.Interval      = 1;
            grid.MajorInterval = 10;


            bool toggle = false;

            game.InitializeEvent += delegate
            {
                translationGizmo.Load(game);
            };
            game.DrawEvent += delegate
            {
                game.GraphicsDevice.RenderState.CullMode = CullMode.CullClockwiseFace;

                translationGizmo.Render(game);
                grid.Render(game);
            };
            game.UpdateEvent += delegate
            {
                translationGizmo.Update(game);

                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.LeftAlt))
                {
                    toggle = !toggle;
                }
                if (toggle)
                {
                    game.Mouse.CursorEnabled     = true;
                    game.IsMouseVisible          = true;
                    game.SpectaterCamera.Enabled = false;
                }
                else
                {
                    game.Mouse.CursorEnabled     = false;
                    game.IsMouseVisible          = false;
                    game.SpectaterCamera.Enabled = true;
                }
            };

            game.Run();
        }
Exemple #16
0
        public override void Draw()
        {
            Handles.color = previewColor;
            Vector3 rotStartDir = settingExternal ? Vector3.right : Vector3.down;

            Handles.BeginGUI();
            foreach (Vector2Int position in manipPositions)
            {
                Vector2 screenPos = EditorGrid.GetInstance().GridToScreenPos(position);
                Handles.DrawSolidArc(new Vector3(screenPos.x, screenPos.y), Vector3.forward, rotStartDir, 180f, EditorGrid.GetInstance().scale *EditorGrid.LINK_SIZE);
            }
            Handles.EndGUI();
        }
Exemple #17
0
 public override void Draw()
 {
     //draw tile previews
     base.Draw();
     foreach (Vector2Int position in manipPositions)
     {
         Vector2 screenPos = EditorGrid.GetInstance().GridToScreenPos(position);
         Rect    r         = new Rect(screenPos, EditorGrid.GetInstance().GetScaledTileSize())
         {
             center = screenPos
         };
         GUI.color = previewColor;
         GUI.Box(r, "");
     }
 }
Exemple #18
0
 public static TrackWriter AcquireWrite(
     ResourceSync sync,
     Track track,
     SimulationRenderer renderer,
     UndoManager undo,
     Timeline timeline,
     EditorGrid cells)
 {
     return(new TrackWriter(sync.AcquireWrite(), track)
     {
         _undo = undo,
         _renderer = renderer,
         _timeline = timeline,
         _editorcells = cells
     });
 }
        private static void Check(params string[] rows)
        {
            var editorGrid = EditorGrid.FromStrings(rows);
            var solverGrid = editorGrid.CreateSolverGrid();

            solverGrid.Refine();

            Assert.AreEqual(editorGrid.Squares.Size, solverGrid.Squares.Size);

            foreach (var position in solverGrid.Squares.AllPositions)
            {
                var expected = editorGrid.Squares[position];
                var actual   = solverGrid.Squares[position];

                Assert.AreEqual(expected, actual, "Unequal squares at {0}", position);
            }
        }
Exemple #20
0
        /// <summary>
        /// Saves metadata relating to the level saved
        /// </summary>
        /// <param name="editorGrid">editorGrid to save metadata about</param>
        /// <param name="filePath">File path to save metadata to</param>
        /// /// <param name="levelName">Level Name to save</param>
        private void SaveGridMetadata(EditorGrid editorGrid, string filePath, string levelName)
        {
            //Create a metadata object, for data storage
            LevelMetadata levelMetadata = new LevelMetadata
            {
                levelName        = levelName,
                levelSaved       = DateTime.Now,
                levelGridWidth   = editorGrid.GridHeight,
                levelGridHeight  = editorGrid.GridHeight,
                levelGridBoxSize = editorGrid.GridBoxSize
            };

            //Serialize as JSON
            string jsonMetadata = JsonConvert.SerializeObject(levelMetadata, Formatting.Indented);

            //Save File
            File.WriteAllText(filePath, jsonMetadata);
        }
 void Update()
 {
     if (!editorGrid && !(editorGrid = GameObject.FindGameObjectWithTag("EditorGrid").GetComponent <EditorGrid>()))
     {
         Debug.LogWarning("No GameObject with tag `EditorGrid`");
         return;
     }
     if (oldOffset != editorGrid.offset)
     {
         Vector3    cur_offset = editorGrid.offset;
         Vector3Int temp_cell  = editorGrid.LocalToCell(transform.localPosition, oldOffset);
         transform.localPosition = editorGrid.CellToLocal(temp_cell, cur_offset);
         oldOffset            = editorGrid.offset;
         transform.hasChanged = false;
     }
     else if (transform.hasChanged)
     {
         transform.localPosition = editorGrid.GetCellSnappedPosition(transform.localPosition);
         transform.hasChanged    = false;
     }
 }
    // Start is called before the first frame update
    // =========================================================================
    void Start()
    {
        // Connections
        g  = GameObject.FindGameObjectWithTag("EditorGrid").GetComponent <EditorGrid>();
        lc = g.gameObject.GetComponent <LevelController>();

        // Prefab loading
        target_prefab = Resources.Load <Target>("Prefabs/Target");

        // Camera Controller
        cc = Camera.main.GetComponent <CameraController>();
        // Level Raycasting

        // Targets
        hovering_target = GetComponentInChildren <Target>();
        if (!hovering_target)
        {
            hovering_target = Instantiate <Target>(target_prefab, this.transform);
            hovering_target.gameObject.SetActive(false);
        }
        cur_targets    = new Dictionary <Vector3Int, Target>();
        cur_targets_2d = new Dictionary <Vector2Int, Target>();
    }
        public void Run()
        {
            EditorGrid grid;

            grid               = new EditorGrid();
            grid.Size          = new Vector2(100, 100);
            grid.Interval      = 1;
            grid.MajorInterval = 10;

            bool mouseEnabled = false;

            scrollIndex = 0;

            game.UpdateEvent += delegate
            {
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.M))
                {
                    placeTool.Enabled     = false;
                    moveTool.Enabled      = true;
                    snapLearnTool.Enabled = false;
                }
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.L))
                {
                    placeTool.Enabled     = false;
                    moveTool.Enabled      = false;
                    snapLearnTool.Enabled = true;
                }
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.P))
                {
                    placeTool.Enabled     = !placeTool.Enabled;
                    moveTool.Enabled      = false;
                    snapLearnTool.Enabled = false;
                }
                if (placeTool.Enabled)
                {
                    updatePlaceType(game, placeTool);
                }
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.LeftAlt))
                {
                    mouseEnabled = !mouseEnabled;
                }
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.C))
                {
                    createNewWorldObjectType(builder);
                }
                if (game.Keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftControl) && game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.S))
                {
                    save();
                }
                if (game.Keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftControl) && game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.L))
                {
                    load();
                }
                if (mouseEnabled)
                {
                    game.Mouse.CursorEnabled     = true;
                    game.IsMouseVisible          = true;
                    game.SpectaterCamera.Enabled = false;
                }
                else
                {
                    game.Mouse.CursorEnabled     = false;
                    game.IsMouseVisible          = false;
                    game.SpectaterCamera.Enabled = true;
                }
            };

            game.DrawEvent += delegate
            {
                grid.Render(game);
            };

            game.Run();
        }
Exemple #24
0
        public override bool HandleEvent(Event e)
        {
            switch (e.type)
            {
            case EventType.MouseDown:
                settingExternal = (IsPrimaryControl(e) || IsSecondaryControl(e)) && e.control;
                goto case EventType.MouseDrag;

            case EventType.MouseDrag:
                if (IsPrimaryControl(e) || IsSecondaryControl(e))
                {
                    Vector2Int position = EditorGrid.GetInstance().ScreenToGridPos(e.mousePosition);
                    if (FeatureEditorWindow.GetInstance().Feature.HasLinkAt(position))
                    {
                        manipPositions.Add(position);
                        if (settingExternal)
                        {
                            previewColor = Color.yellow;
                        }
                        else if (IsPrimaryControl(e))
                        {
                            previewColor = Color.green;
                        }
                        else if (IsSecondaryControl(e))
                        {
                            previewColor = Color.red;
                        }
                        return(true);
                    }
                }
                break;

            case EventType.MouseUp:
                if (IsPrimaryControl(e) || IsSecondaryControl(e))
                {
                    FeatureAsset feature = FeatureEditorWindow.GetInstance().Feature;
                    string       description;
                    UnityAction  action;

                    bool targetState = IsPrimaryControl(e) ? true : IsSecondaryControl(e) ? false : false;
                    if (settingExternal)
                    {
                        description = targetState ? "Set connection(s) to external" : "Set connections(s) to internal";
                        action      = () => {
                            foreach (Vector2Int position in manipPositions)
                            {
                                if (feature.TryGetLink(position, out Link link))
                                {
                                    link.external = targetState;
                                }
                            }
                        };
                    }
                    else
                    {
                        description = targetState ? "Set connection(s) to open" : "Set connections(s) to closed";
                        action      = () => {
                            foreach (Vector2Int position in manipPositions)
                            {
                                if (feature.TryGetLink(position, out Link link))
                                {
                                    link.open = targetState;
                                }
                            }
                        };
                    }

                    ChangeAsset(feature, description, action);

                    e.Use();
                    manipPositions.Clear();
                    return(true);
                }
                break;
            }
            return(false);
        }
Exemple #25
0
        public void TestAddDeleteMeshToFromWorld()
        {
            XNAGame game = new XNAGame();

            OBJParser.ObjImporter importer = new OBJParser.ObjImporter();
            var c = new OBJToRAMMeshConverter(new RAMTextureFactory());

            importer.AddMaterialFileStream("WallInnerCorner.mtl", new FileStream(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallInnerCorner.mtl", FileMode.Open));
            importer.ImportObjFile(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallInnerCorner.obj");
            var meshWallInnerCorner = c.CreateMesh(importer);

            importer.AddMaterialFileStream("WallStraight.mtl", new FileStream(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallStraight.mtl", FileMode.Open));
            importer.ImportObjFile(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallStraight.obj");
            var meshWallStraight = c.CreateMesh(importer);

            importer.AddMaterialFileStream("WallOuterCorner.mtl", new FileStream(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallOuterCorner.mtl", FileMode.Open));
            importer.ImportObjFile(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallOuterCorner.obj");
            var meshWallOuterCorner = c.CreateMesh(importer);

            var texturePool           = new TexturePool();
            var meshpartPool          = new MeshPartPool();
            var vertexDeclarationPool = new VertexDeclarationPool();

            var renderer = new SimpleMeshRenderer(texturePool, meshpartPool, vertexDeclarationPool);

            vertexDeclarationPool.SetVertexElements <TangentVertex>(TangentVertex.VertexElements);

            World world = new World();
            TileSnapInformationBuilder builder = new TileSnapInformationBuilder();

            WorldObjectPlaceTool placeTool = new WorldObjectPlaceTool(game, world, renderer, builder, new SimpleMeshFactory(), new SimpleTileFaceTypeFactory());
            WorldObjectType      type1     = new WorldObjectType(meshWallInnerCorner, Guid.NewGuid(), builder);
            WorldObjectType      type2     = new WorldObjectType(meshWallStraight, Guid.NewGuid(), builder);
            WorldObjectType      type3     = new WorldObjectType(meshWallOuterCorner, Guid.NewGuid(), builder);

            var tileDataInnerCorner = new TileData(Guid.NewGuid());
            var tileDataStraight    = new TileData(Guid.NewGuid());
            var tileDataOuterCorner = new TileData(Guid.NewGuid());

            tileDataInnerCorner.Dimensions = type1.BoundingBox.Max - type1.BoundingBox.Min;
            tileDataStraight.Dimensions    = type2.BoundingBox.Max - type2.BoundingBox.Min;
            tileDataOuterCorner.Dimensions = type1.BoundingBox.Max - type1.BoundingBox.Min;

            var faceSnapType1 = new TileFaceType(Guid.NewGuid())
            {
                Name = "type1"
            };

            //var faceSnapType2 = new TileFaceType() { Name = "type2" };

            tileDataInnerCorner.SetFaceType(TileFace.Front, faceSnapType1);
            tileDataInnerCorner.SetLocalWinding(TileFace.Front, true);

            tileDataInnerCorner.SetFaceType(TileFace.Left, faceSnapType1);
            tileDataInnerCorner.SetLocalWinding(TileFace.Left, true);

            tileDataStraight.SetFaceType(TileFace.Back, faceSnapType1);
            tileDataStraight.SetLocalWinding(TileFace.Back, false);

            tileDataStraight.SetFaceType(TileFace.Front, faceSnapType1);
            tileDataStraight.SetLocalWinding(TileFace.Front, true);

            tileDataOuterCorner.SetFaceType(TileFace.Front, faceSnapType1);
            tileDataOuterCorner.SetLocalWinding(TileFace.Front, true);

            tileDataOuterCorner.SetFaceType(TileFace.Right, faceSnapType1);
            tileDataOuterCorner.SetLocalWinding(TileFace.Right, true);


            type1.TileData = tileDataInnerCorner;
            type2.TileData = tileDataStraight;
            type3.TileData = tileDataOuterCorner;


            type1.SnapInformation = builder.CreateFromTile(tileDataInnerCorner);
            type2.SnapInformation = builder.CreateFromTile(tileDataStraight);
            type3.SnapInformation = builder.CreateFromTile(tileDataOuterCorner);

            List <WorldObjectType> typeList = new List <WorldObjectType>();

            typeList.Add(type1);
            typeList.Add(type2);
            typeList.Add(type3);

            WorldObjectMoveTool moveTool = new WorldObjectMoveTool(game, world, builder, renderer);

            game.AddXNAObject(moveTool);
            game.AddXNAObject(placeTool);

            game.IsFixedTimeStep = false;
            game.DrawFps         = true;
            game.AddXNAObject(texturePool);
            game.AddXNAObject(meshpartPool);
            game.AddXNAObject(vertexDeclarationPool);
            game.AddXNAObject(renderer);

            EditorGrid grid;

            grid               = new EditorGrid();
            grid.Size          = new Vector2(100, 100);
            grid.Interval      = 1;
            grid.MajorInterval = 10;

            bool mouseEnabled = false;

            game.UpdateEvent += delegate
            {
                if (placeTool.Enabled)
                {
                    moveTool.Enabled = false;

                    if (placeTool.ObjectsPlacedSinceEnabled() == 1)
                    {
                        placeTool.Enabled = false;
                    }
                }
                else
                {
                    moveTool.Enabled = true;
                }

                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.NumPad1))
                {
                    placeTool.PlaceType = typeList[0];
                    placeTool.Enabled   = true;
                }
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.NumPad2))
                {
                    placeTool.PlaceType = typeList[1];
                    placeTool.Enabled   = true;
                }
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.NumPad3))
                {
                    placeTool.PlaceType = typeList[2];
                    placeTool.Enabled   = true;
                }

                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.LeftAlt))
                {
                    mouseEnabled = !mouseEnabled;
                }
                if (mouseEnabled)
                {
                    game.Mouse.CursorEnabled     = true;
                    game.IsMouseVisible          = true;
                    game.SpectaterCamera.Enabled = false;
                }
                else
                {
                    game.Mouse.CursorEnabled     = false;
                    game.IsMouseVisible          = false;
                    game.SpectaterCamera.Enabled = true;
                    //activeWorldObject = null;
                }
            };
            game.DrawEvent += delegate
            {
                grid.Render(game);
            };

            game.Run();
        }
Exemple #26
0
        internal static SolverGrid CreateSolverGrid(params string[] rows)
        {
            var editorGrid = EditorGrid.FromStrings(rows);

            return(editorGrid.CreateSolverGrid());
        }
Exemple #27
0
        protected static IPuzzleEditor CreatePuzzleEditor(params string[] rows)
        {
            var editorGrid = EditorGrid.FromStrings(rows);

            return(new PuzzleEditor(editorGrid));
        }
Exemple #28
0
        public void TestLearnSnap()
        {
            XNAGame game = new XNAGame();

            OBJParser.ObjImporter importer = new OBJParser.ObjImporter();
            var c = new OBJToRAMMeshConverter(new RAMTextureFactory());

            importer.AddMaterialFileStream("WallInnerCorner.mtl", new FileStream(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallInnerCorner.mtl", FileMode.Open));
            importer.ImportObjFile(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallInnerCorner.obj");
            var meshWallInnerCorner = c.CreateMesh(importer);

            importer.AddMaterialFileStream("WallStraight.mtl", new FileStream(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallStraight.mtl", FileMode.Open));
            importer.ImportObjFile(TWDir.GameData.CreateSubdirectory("Core\\TileEngine") + "/TileSet001/WallStraight.obj");
            var meshWallStraight = c.CreateMesh(importer);

            var texturePool           = new TexturePool();
            var meshpartPool          = new MeshPartPool();
            var vertexDeclarationPool = new VertexDeclarationPool();

            var renderer = new SimpleMeshRenderer(texturePool, meshpartPool, vertexDeclarationPool);

            vertexDeclarationPool.SetVertexElements <TangentVertex>(TangentVertex.VertexElements);

            World world = new World();
            TileSnapInformationBuilder builder = new TileSnapInformationBuilder();

            WorldObjectType type1 = new WorldObjectType(meshWallInnerCorner, Guid.NewGuid(), builder);
            WorldObjectType type2 = new WorldObjectType(meshWallStraight, Guid.NewGuid(), builder);

            var tileDataInnerCorner = new TileData(Guid.NewGuid());
            var tileDataStraight    = new TileData(Guid.NewGuid());

            tileDataInnerCorner.Dimensions = type1.BoundingBox.Max - type1.BoundingBox.Min;
            tileDataStraight.Dimensions    = type2.BoundingBox.Max - type2.BoundingBox.Min;


            type1.TileData = tileDataInnerCorner;
            type2.TileData = tileDataStraight;


            var TileInnerCorner = world.CreateNewWorldObject(game, type1, renderer);

            TileInnerCorner.Position = new Vector3(-7, 0, 0);
            var TileStraight = world.CreateNewWorldObject(game, type2, renderer);

            TileStraight.Position = new Vector3(7, 0, 0);

            game.IsFixedTimeStep = false;
            game.DrawFps         = true;
            game.AddXNAObject(texturePool);
            game.AddXNAObject(meshpartPool);
            game.AddXNAObject(vertexDeclarationPool);
            game.AddXNAObject(renderer);

            EditorGrid grid;

            grid               = new EditorGrid();
            grid.Size          = new Vector2(100, 100);
            grid.Interval      = 1;
            grid.MajorInterval = 10;

            var snapLearnTool = new SnapLearnTool(world, renderer, builder);

            game.AddXNAObject(snapLearnTool);

            bool mouseEnabled = false;

            var WallCornerBB = type1.TileData.GetBoundingBox();

            game.UpdateEvent += delegate
            {
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.LeftAlt))
                {
                    mouseEnabled = !mouseEnabled;
                }
                if (mouseEnabled)
                {
                    game.Mouse.CursorEnabled     = true;
                    game.IsMouseVisible          = true;
                    game.SpectaterCamera.Enabled = false;
                }
                else
                {
                    game.Mouse.CursorEnabled     = false;
                    game.IsMouseVisible          = false;
                    game.SpectaterCamera.Enabled = true;
                    //activeWorldObject = null;
                }
            };
            game.DrawEvent += delegate
            {
                grid.Render(game);
                game.LineManager3D.WorldMatrix = TileInnerCorner.WorldMatrix;
                //game.LineManager3D.AddBox(WallCornerBB, Color.White);
            };

            game.Run();
        }
Exemple #29
0
        public void TestLearnPlace()
        {
            XNAGame game = new XNAGame();

            var texturePool           = new TexturePool();
            var meshpartPool          = new MeshPartPool();
            var vertexDeclarationPool = new VertexDeclarationPool();

            vertexDeclarationPool.SetVertexElements <TangentVertex>(TangentVertex.VertexElements);
            var renderer = new SimpleMeshRenderer(texturePool, meshpartPool, vertexDeclarationPool);

            game.IsFixedTimeStep = false;
            game.DrawFps         = true;
            game.AddXNAObject(texturePool);
            game.AddXNAObject(meshpartPool);
            game.AddXNAObject(vertexDeclarationPool);
            game.AddXNAObject(renderer);

            EditorGrid grid;

            grid               = new EditorGrid();
            grid.Size          = new Vector2(100, 100);
            grid.Interval      = 1;
            grid.MajorInterval = 10;

            World world   = new World();
            var   builder = new TileSnapInformationBuilder();

            //var TileInnerCorner = factory.CreateNewWorldObject(game, wallInnerCornerType, renderer);
            //TileInnerCorner.Position = new Vector3(-7, 0, 0);
            //var TileStraight = factory.CreateNewWorldObject(game, wallStraightType, renderer);
            //TileStraight.Position = new Vector3(7, 0, 0);

            var placeTool     = new WorldObjectPlaceTool(game, world, renderer, builder, new SimpleMeshFactory(), new SimpleTileFaceTypeFactory());
            var moveTool      = new WorldObjectMoveTool(game, world, builder, renderer);
            var snapLearnTool = new SnapLearnTool(world, renderer, builder);

            game.AddXNAObject(placeTool);
            game.AddXNAObject(moveTool);
            game.AddXNAObject(snapLearnTool);


            setupWorldObjectTypes(game, renderer, builder);



            bool mouseEnabled = false;

            game.UpdateEvent += delegate
            {
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.M))
                {
                    placeTool.Enabled     = false;
                    moveTool.Enabled      = true;
                    snapLearnTool.Enabled = false;
                }
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.L))
                {
                    placeTool.Enabled     = false;
                    moveTool.Enabled      = false;
                    snapLearnTool.Enabled = true;
                }


                if (placeTool.Enabled)
                {
                    moveTool.Enabled      = false;
                    snapLearnTool.Enabled = false;

                    if (placeTool.ObjectsPlacedSinceEnabled() == 1)
                    {
                        placeTool.Enabled = false;
                    }
                }


                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.NumPad1))
                {
                    placeTool.PlaceType = typeList[0];
                    placeTool.Enabled   = true;
                }
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.NumPad2))
                {
                    placeTool.PlaceType = typeList[1];
                    placeTool.Enabled   = true;
                }

                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.LeftAlt))
                {
                    mouseEnabled = !mouseEnabled;
                }
                if (mouseEnabled)
                {
                    game.Mouse.CursorEnabled     = true;
                    game.IsMouseVisible          = true;
                    game.SpectaterCamera.Enabled = false;
                }
                else
                {
                    game.Mouse.CursorEnabled     = false;
                    game.IsMouseVisible          = false;
                    game.SpectaterCamera.Enabled = true;
                    //activeWorldObject = null;
                }
            };

            game.DrawEvent += delegate
            {
                grid.Render(game);
            };

            game.Run();
        }
Exemple #30
0
        public override bool HandleEvent(Event e)
        {
            if (tileEditorPanel.HandleEvent(e))
            {
                return(true);
            }

            switch (e.type)
            {
            case EventType.MouseDown:
                if (IsPrimaryControl(e))
                {
                    //start selection box
                    selectionRect.position = e.mousePosition;
                    e.Use();
                    selectionMode = SELECT_MODE_SELECT;
                    return(true);
                }
                else if (IsSecondaryControl(e))
                {
                    //start selection box
                    selectionRect.position = e.mousePosition;
                    e.Use();
                    selectionMode = SELECT_MODE_DESELECT;
                    return(true);
                }
                break;

            case EventType.MouseDrag:
                if (IsPrimaryControl(e) || IsSecondaryControl(e))
                {
                    //update selection box
                    selectionRect.max = e.mousePosition;
                    e.Use();
                    return(true);
                }
                break;

            case EventType.MouseUp:
                if (IsPrimaryControl(e) || IsSecondaryControl(e))
                {
                    //select all tiles within selection box
                    string       description;
                    UnityAction  action;
                    Vector2Int[] positions = EditorGrid.GetInstance().RectToGridPositions(selectionRect, true);
                    FeatureAsset feature   = FeatureEditorWindow.GetInstance().Feature;
                    if (selectionMode == SELECT_MODE_SELECT)
                    {
                        description = "Select section(s)";
                        action      = () => {
                            if (!e.shift)
                            {
                                //not additive
                                feature.DeselectAllSections();
                            }
                            foreach (Vector2Int gp in positions)
                            {
                                //additive
                                feature.SelectSection(gp);
                            }
                        };
                    }
                    else if (selectionMode == SELECT_MODE_DESELECT)
                    {
                        description = "Deselect section(s)";
                        action      = () => {
                            if (!e.shift)
                            {
                                //not additive
                                feature.DeselectAllSections();
                            }
                            else
                            {
                                //additive
                                foreach (Vector2Int gp in positions)
                                {
                                    feature.DeselectSection(gp);
                                }
                            }
                        };
                    }
                    else
                    {
                        description = "ERROR";
                        action      = null;
                    }

                    ChangeAsset(feature, description, action);

                    selectionRect = new Rect();
                    selectionMode = SELECT_MODE_NONE;
                    e.Use();
                    return(true);
                }
                break;
            }
            return(false);
        }