예제 #1
0
 void ShowOutline()
 {
     for (int x = 0; x < outlines.GetLength(0); x++)
     {
         for (int y = 0; y < outlines.GetLength(1); y++)
         {
             if (outlineTiles[x, y])
             {
                 TileOutline o  = outlines[x, y];
                 int         xx = x - 1;
                 int         yy = y;
                 o.w.SetActive(x > 0 && !outlineTiles[xx, yy]);
                 xx = x + 1;
                 yy = y;
                 o.e.SetActive(x < outlines.GetLength(0) - 1 && !outlineTiles[xx, yy]);
                 xx = x;
                 yy = y - 1;
                 o.s.SetActive(y > 0 && !outlineTiles[xx, yy]);
                 xx = x;
                 yy = y + 1;
                 o.n.SetActive(y < outlines.GetLength(1) - 1 && !outlineTiles[xx, yy]);
             }
             else
             {
                 TileOutline o = outlines[x, y];
                 o.n.SetActive(false);
                 o.e.SetActive(false);
                 o.w.SetActive(false);
                 o.s.SetActive(false);
             }
         }
     }
 }
예제 #2
0
        protected override void OnInit()
        {
            base.OnInit();

            // Enable camera control
            CameraController.AllowUserRotate = true;
            CameraController.AllowUserInvert = true;
            CameraController.AllowUserZoom   = true;
            CameraController.AllowUserPan    = true;

            // Load grid
            m_grid    = new Grid(Level);
            m_outline = new TileOutline(Level);

            // Setup preview
            m_previewEntity = new TilePreview();
            Level.Entities.Add(m_previewEntity);

            // Setup change queue
            m_pendingChanges = new List <TilePreview>();

            // Add GUI elements
            Game.Screen.Elements.Add(m_menuButton);
            Game.Screen.Elements.Add(m_saveButton);
            Game.Screen.Elements.Add(m_testButton);

            m_titleText.Options[0] = MouseButton.Left.GetPrompt() + " " + TranslateTitle(Level.Info.Title);
            Game.Screen.Elements.Add(m_titleText);
            Game.Screen.Elements.Add(m_statusText);
            Game.Screen.Elements.Add(m_tileSelect);

            if (!Game.User.Progress.UsedLevelEditor)
            {
                // Do first time tutorial
                var dialog = DialogBox.CreateQueryBox(
                    Game.Screen,
                    Game.Language.Translate("menus.editor.title"),
                    Game.Language.Translate("menus.editor.first_time_prompt"),
                    new string[] {
                    Game.Language.Translate("menus.yes"),
                    Game.Language.Translate("menus.no"),
                },
                    false
                    );
                dialog.OnClosed += delegate(object sender, DialogBoxClosedEventArgs args)
                {
                    if (args.Result == 0)
                    {
                        // YES
                        ShowGuide();
                    }
                };
                ShowDialog(dialog);

                // Supress it in future
                Game.User.Progress.UsedLevelEditor = true;
                Game.User.Progress.Save();
            }
        }
예제 #3
0
        private bool GetPotentialPlacement(out TileCoordinates o_position, out Tile o_tile, out FlatDirection o_direction, TileOutline previewOutline)
        {
            if (Dialog == null &&
                !m_menuButton.TestMouse() &&
                !m_testButton.TestMouse() &&
                !m_saveButton.TestMouse() &&
                m_titleText.TestMouse() < 0 &&
                !m_tileSelect.TestMouse())
            {
                var ray = BuildRay(Game.Screen.MousePosition, 100.0f);

                // Raycast against level
                TileCoordinates levelHitCoords;
                Direction       levelHitSide;
                float           levelHitDistance;
                bool            levelHit = Level.RaycastTiles(ray, out levelHitCoords, out levelHitSide, out levelHitDistance);

                // Raycast against grid
                TileCoordinates gridHitCoords;
                Direction       gridHitSide;
                float           gridHitDistance;
                bool            gridHit = m_grid.Raycast(ray, out gridHitCoords, out gridHitSide, out gridHitDistance);

                // Determine the closest hit result (if any)
                TileCoordinates hitCoords;
                Direction       hitSide;
                bool            hit = false;
                if (gridHit && !levelHit)
                {
                    hitCoords = gridHitCoords;
                    hitSide   = gridHitSide;
                    hit       = true;
                }
                else if (levelHit)
                {
                    hitCoords = levelHitCoords;
                    hitSide   = levelHitSide;
                    hit       = true;
                }
                else
                {
                    hitCoords = default(TileCoordinates);
                    hitSide   = default(Direction);
                    hit       = false;
                }

                // Determine where to place or delete
                if (hit)
                {
                    var baseCoords = Level.Tiles[hitCoords].GetBase(Level, hitCoords);
                    if (Game.Keyboard.Keys[Key.LeftShift].Held || Game.Keyboard.Keys[Key.RightShift].Held)
                    {
                        // Deleting tile
                        o_tile      = Tiles.Air;
                        o_direction = FlatDirection.North;
                        o_position  = baseCoords;
                        if (previewOutline != null)
                        {
                            previewOutline.Visible  = levelHit;
                            previewOutline.Position = baseCoords;
                            previewOutline.Height   = Level.Tiles[baseCoords].Height;
                            previewOutline.Red      = true;
                        }
                    }
                    else if (levelHit && Game.Keyboard.Keys[Key.LeftCtrl].Held || Game.Keyboard.Keys[Key.RightCtrl].Held)
                    {
                        // Replacing tile
                        o_tile      = m_tileSelect.SelectedTile;
                        o_direction = m_tileSelect.SelectedTileDirection;
                        o_position  = baseCoords;
                        if (previewOutline != null)
                        {
                            previewOutline.Visible = false;
                        }
                    }
                    else
                    {
                        // Adding tile
                        o_tile      = m_tileSelect.SelectedTile;
                        o_direction = m_tileSelect.SelectedTileDirection;
                        if (hitSide == Direction.Down)
                        {
                            o_position = hitCoords.Move(hitSide, o_tile.Height);
                        }
                        else
                        {
                            o_position = hitCoords.Move(hitSide);
                        }
                        if (previewOutline != null)
                        {
                            previewOutline.Visible  = levelHit;
                            previewOutline.Position = baseCoords;
                            previewOutline.Height   = Level.Tiles[baseCoords].Height;
                            previewOutline.Red      = false;
                        }
                    }
                    return(true);
                }
            }

            o_position  = default(TileCoordinates);
            o_direction = default(FlatDirection);
            o_tile      = default(Tile);
            if (previewOutline != null)
            {
                previewOutline.Visible = false;
            }
            return(false);
        }