Пример #1
0
        private void createNewObjectIfNotExists()
        {
            if (tileSetSelectionView.SelectedObject == null)
            {
                int newId = WorldBuilderUtils.CreateObject(placementType, placementMode, tileSetSelectionView);

                if (newId >= 0)
                {
                    switch (placementType)
                    {
                    case PlacementType.BlockPlacement:
                        tileSetSelectionView.SelectedObject = BlockType.lookup[newId];
                        break;

                    case PlacementType.AmbientObjectPlacement:
                        tileSetSelectionView.SelectedObject = AmbientObjectType.lookup[newId];
                        break;

                    case PlacementType.AmbientHitableObjectPlacement:
                        tileSetSelectionView.SelectedObject = AmbientHitableObjectType.lookup[newId];
                        break;
                    }
                }
            }
        }
Пример #2
0
        private void editObject()
        {
            var    selectedElement = manageObjectList.SelectedElement;
            object selectedObject  = null;

            switch (placementType)
            {
            case PlacementType.BlockPlacement:
                selectedObject = ((BlockListItem)selectedElement).BlockType;
                break;

            case PlacementType.AmbientObjectPlacement:
                selectedObject = ((AmbientObjectListItem)selectedElement).AmbientObjectType;
                break;

            case PlacementType.AmbientHitableObjectPlacement:
                selectedObject = ((AmbientHitableObjectListItem)selectedElement).AmbientHitableObjectType;
                break;

            case PlacementType.LivingEntityPlacement:
                selectedObject = ((LivingEntityListItem)selectedElement).LivingEntityType;
                break;
            }

            var dialog = new InputDialog("Edit Object", JToken.FromObject(selectedObject, SerializationUtils.Serializer).ToString(Formatting.Indented));

            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                WorldBuilderUtils.ReplaceTypeFromString(placementType, dialog.ResultText);

                refreshListAndSelectId(((ObjectListItem)selectedElement).GetObject().ID);
            }
        }
Пример #3
0
        private void createNewObject()
        {
            int newId = WorldBuilderUtils.CreateObject(placementType, placementMode, tileSetSelectionView);

            if (newId != -1 && placementMode == PlacementMode.CreateFromTileset)
            {
                refreshListAndSelectId(newId);
            }
        }
Пример #4
0
        private void createNewObjectFromJson()
        {
            int newId = WorldBuilderUtils.CreateObject(placementType, placementMode, tileSetSelectionView, true);

            if (newId != -1)
            {
                refreshListAndSelectId(newId);
            }
        }
Пример #5
0
 private void placeObjectAtPosition()
 {
     if (placementMode == PlacementMode.Manage)
     {
         WorldBuilderUtils.CreateObjectAtMousePosition(((ObjectListItem)manageObjectList.SelectedElement).GetObject());
     }
     else if (placementMode == PlacementMode.CreateFromTileset && tileSetSelectionView.SelectedObject != null)
     {
         WorldBuilderUtils.CreateObjectAtMousePosition(tileSetSelectionView.SelectedObject);
     }
 }
Пример #6
0
        private void createNewFrom()
        {
            var    selectedElement = manageObjectList.SelectedElement;
            object selectedObject  = null;

            switch (placementType)
            {
            case PlacementType.BlockPlacement:
                selectedObject = ((BlockListItem)selectedElement).BlockType;
                break;

            case PlacementType.AmbientObjectPlacement:
                selectedObject = ((AmbientObjectListItem)selectedElement).AmbientObjectType;
                break;

            case PlacementType.AmbientHitableObjectPlacement:
                selectedObject = ((AmbientHitableObjectListItem)selectedElement).AmbientHitableObjectType;
                break;

            case PlacementType.LivingEntityPlacement:
                selectedObject = ((LivingEntityListItem)selectedElement).LivingEntityType;
                break;
            }

            int newId          = WorldBuilderUtils.GenerateNewId(placementType);
            var selectedJToken = JObject.FromObject(selectedObject, SerializationUtils.Serializer);

            selectedJToken["ID"] = newId;

            var dialog = new InputDialog("Create New Object From", selectedJToken.ToString(Formatting.Indented));

            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                WorldBuilderUtils.ReplaceTypeFromString(placementType, dialog.ResultText);

                refreshListAndSelectId(newId);
            }
        }
Пример #7
0
        public override void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            if (SimulationGame.IsWorldBuilderOpen)
            {
                spriteBatch.Draw(backgroundOverlay, Bounds.ToXnaRectangle(), backgroundColor);
                base.Draw(spriteBatch, gameTime);

                if (placementType != PlacementType.NoType && placementType != PlacementType.Inspect && placementType != PlacementType.WorldPartDetails)
                {
                    switch (placementMode)
                    {
                    case PlacementMode.Manage:
                        manageObjectList.Draw(spriteBatch, gameTime);

                        if (manageObjectList.SelectedElement != null)
                        {
                            editBtn.Draw(spriteBatch, gameTime);
                            createNewFromBtn.Draw(spriteBatch, gameTime);
                            removeBtn.Draw(spriteBatch, gameTime);
                        }
                        break;

                    case PlacementMode.ChooseTileset:
                        tilesetSelectionList.Draw(spriteBatch, gameTime);
                        break;

                    case PlacementMode.CreateFromTileset:
                        tileSetSelectionView.Draw(spriteBatch, gameTime);

                        if (tileSetSelectionView.SelectedSpritePosition != null)
                        {
                            createBtn.Draw(spriteBatch, gameTime);
                            createIfNotExistBtn.Draw(spriteBatch, gameTime);
                        }

                        break;
                    }

                    manageBtn.Draw(spriteBatch, gameTime);
                    createFromJsonBtn.Draw(spriteBatch, gameTime);

                    if (placementType != PlacementType.LivingEntityPlacement)
                    {
                        createFromTilesetBtn.Draw(spriteBatch, gameTime);
                    }
                }
                else if (placementType == PlacementType.WorldPartDetails)
                {
                    changePersistencyBtn.Draw(spriteBatch, gameTime);
                    createWorldLinkBtn.Draw(spriteBatch, gameTime);
                    createInteriorBtn.Draw(spriteBatch, gameTime);

                    if (SimulationGame.Player.InteriorID != Interior.Outside)
                    {
                        changeInteriorDimensionsBtn.Draw(spriteBatch, gameTime);
                        removeInteriorBtn.Draw(spriteBatch, gameTime);
                    }

                    worldPartDetailsTextView.Draw(spriteBatch, gameTime);
                }
                else if (placementType == PlacementType.Inspect)
                {
                    if (inspectView.SelectedGameObjects.Count > 0)
                    {
                        editInstanceBtn.Draw(spriteBatch, gameTime);
                        removeInstanceBtn.Draw(spriteBatch, gameTime);
                        showInstanceTypeBtn.Draw(spriteBatch, gameTime);
                        selectedObjectDetailTextView.Draw(spriteBatch, gameTime);
                    }
                    else if (inspectView.SelectedWorldLink != null)
                    {
                        editInstanceBtn.Draw(spriteBatch, gameTime);
                        removeInstanceBtn.Draw(spriteBatch, gameTime);

                        selectedObjectDetailTextView.Draw(spriteBatch, gameTime);
                    }
                }

                if ((placementMode == PlacementMode.Manage && manageObjectList.SelectedElement != null) ||
                    (placementMode == PlacementMode.CreateFromTileset && tileSetSelectionView.SelectedObject != null))
                {
                    placeView.Draw(spriteBatch, gameTime);

                    if (placeView.Bounds.Contains(SimulationGame.MouseState.Position))
                    {
                        if (SimulationGame.KeyboardState.IsKeyDown(Keys.LeftControl) || SimulationGame.KeyboardState.IsKeyDown(Keys.RightControl))
                        {
                            WorldBuilderUtils.DrawPreview(spriteBatch, SimulationGame.MouseState.Position.ToVector2(), (placementMode == PlacementMode.Manage) ? ((ObjectListItem)manageObjectList.SelectedElement).GetObject() : tileSetSelectionView.SelectedObject);
                        }
                        else
                        {
                            var isBlockSelected = false;

                            if (placementMode == PlacementMode.Manage)
                            {
                                if (((ObjectListItem)manageObjectList.SelectedElement) is BlockListItem)
                                {
                                    isBlockSelected = true;
                                }
                            }
                            else if (placementMode == PlacementMode.CreateFromTileset)
                            {
                                if (tileSetSelectionView.SelectedObject is BlockType)
                                {
                                    isBlockSelected = true;
                                }
                            }

                            if (isBlockSelected)
                            {
                                var worldBlockPosition = GeometryUtils.GetBlockFromReal((int)SimulationGame.RealWorldMousePosition.X, (int)SimulationGame.RealWorldMousePosition.Y);

                                WorldBuilderUtils.DrawPreview(spriteBatch, SimulationGame.ConvertWorldPositionToUIPosition(worldBlockPosition.X * WorldGrid.BlockSize.X, worldBlockPosition.Y * WorldGrid.BlockSize.Y), (placementMode == PlacementMode.Manage) ? ((ObjectListItem)manageObjectList.SelectedElement).GetObject() : tileSetSelectionView.SelectedObject);
                            }
                            else
                            {
                                var worldBlockPosition = GeometryUtils.GetChunkPosition((int)SimulationGame.RealWorldMousePosition.X, (int)SimulationGame.RealWorldMousePosition.Y, 16, 16);

                                WorldBuilderUtils.DrawPreview(spriteBatch, SimulationGame.ConvertWorldPositionToUIPosition(worldBlockPosition.X * 16, worldBlockPosition.Y * 16), (placementMode == PlacementMode.Manage) ? ((ObjectListItem)manageObjectList.SelectedElement).GetObject() : tileSetSelectionView.SelectedObject);
                            }
                        }
                    }
                }
                else
                {
                    inspectView.Draw(spriteBatch, gameTime);
                }
            }
        }
Пример #8
0
        public void LoadContent()
        {
            tilesets = WorldBuilderUtils.GetTileSets(SimulationGame.ContentManager.RootDirectory + "\\Tiles");

            Bounds = new Rect(SimulationGame.Resolution.Width * 2 / 3, 0, SimulationGame.Resolution.Width / 3, SimulationGame.Resolution.Height);
            tilesetSelectionArea = new Rect(Bounds.X, Bounds.Y + 120, Bounds.Width - 10, Bounds.Height);

            backgroundOverlay = new Texture2D(SimulationGame.Graphics.GraphicsDevice, 1, 1);
            backgroundOverlay.SetData(new Color[] { Color.White });

            placeView = new BaseUI()
            {
                Bounds = new Rect(0, 0, SimulationGame.Resolution.Width * 2 / 3, SimulationGame.Resolution.Height)
            };
            placeView.OnKeyPress(Keys.Escape, () =>
            {
                if (placementMode == PlacementMode.CreateFromTileset)
                {
                    tileSetSelectionView.Deselect();
                }
            });
            placeView.OnClick(placeObjectAtPosition);

            selectedObjectDetailTextView = new TextView(tilesetSelectionArea, "");
            worldPartDetailsTextView     = new TextView(tilesetSelectionArea, "");

            inspectView = new InspectView(new Rect(0, 0, SimulationGame.Resolution.Width * 2 / 3, SimulationGame.Resolution.Height));
            inspectView.OnSelect(handleInspectGameObjectSelection, handleInspectBlockSelection, handleInspectWorldLinkSelection);

            tileSetSelectionView = new TileSetSelectionView(tilesetSelectionArea);
            tilesetSelectionList = new ScrollableList(tilesetSelectionArea);
            tilesetSelectionList.OnSelect((UIElement selectedElement) =>
            {
                placementMode = PlacementMode.CreateFromTileset;
                tileSetSelectionView.SetTileSet(((Button)selectedElement).Text);
            });

            manageObjectList = new ScrollableList(tilesetSelectionArea);

            foreach (var tileset in tilesets)
            {
                var button = new Button(tileset, Point.Zero);

                button.ShowBorder = false;

                tilesetSelectionList.AddElement(button);
            }

            // Block Type Button
            blockTypeBtn = new Button("Blocks", new Point(Bounds.X, Bounds.Y + 10));
            blockTypeBtn.OnClick(() => {
                placementType = PlacementType.BlockPlacement;
                handleManageBtnClick();
            });

            // Ambient Object Type Button
            ambientObjectTypeBtn = new Button("Ambient Objects", new Point(blockTypeBtn.Bounds.Right + 10, Bounds.Y + 10));
            ambientObjectTypeBtn.OnClick(() => {
                placementType = PlacementType.AmbientObjectPlacement;
                handleManageBtnClick();
            });

            // Ambient Hitable Object Type Button
            ambientHitableObjectTypeBtn = new Button("Hitable Objects", new Point(ambientObjectTypeBtn.Bounds.Right + 10, Bounds.Y + 10));
            ambientHitableObjectTypeBtn.OnClick(() => {
                placementType = PlacementType.AmbientHitableObjectPlacement;
                handleManageBtnClick();
            });

            // Ambient Hitable Object Type Button
            livingEntityTypeBtn = new Button("Living Entities", new Point(ambientHitableObjectTypeBtn.Bounds.Right + 10, Bounds.Y + 10));
            livingEntityTypeBtn.OnClick(() => {
                placementType = PlacementType.LivingEntityPlacement;
                handleManageBtnClick();
            });

            // World Part Details Button
            worldPartBtn = new Button("World Details", new Point(livingEntityTypeBtn.Bounds.Right + 10, Bounds.Y + 10));
            worldPartBtn.OnClick(() => {
                placementType = PlacementType.WorldPartDetails;
                placementMode = PlacementMode.NoPlacement;
            });

            // Manage Button
            manageBtn = new Button("Manage", new Point(Bounds.X, blockTypeBtn.Bounds.Bottom + 10));
            manageBtn.OnClick(handleManageBtnClick);

            // Create From Json
            createFromJsonBtn = new Button("Create From Json", new Point(manageBtn.Bounds.Right + 10, blockTypeBtn.Bounds.Bottom + 10));
            createFromJsonBtn.OnClick(createNewObjectFromJson);

            // Create From Tileset
            createFromTilesetBtn = new Button("Create From Tileset", new Point(createFromJsonBtn.Bounds.Right + 10, blockTypeBtn.Bounds.Bottom + 10));
            createFromTilesetBtn.OnClick(() => placementMode = PlacementMode.ChooseTileset);

            // Edit Btn
            editBtn = new Button("Edit", new Point(Bounds.X, manageBtn.Bounds.Bottom + 10));
            editBtn.OnClick(editObject);

            // Create New From Btn
            createNewFromBtn = new Button("Create New From", new Point(editBtn.Bounds.Right + 10, manageBtn.Bounds.Bottom + 10));
            createNewFromBtn.OnClick(createNewFrom);

            // Remove Btn
            removeBtn = new Button("Remove", new Point(createNewFromBtn.Bounds.Right + 10, manageBtn.Bounds.Bottom + 10));
            removeBtn.OnClick(removeObject);

            // Create If not exist Btn
            createIfNotExistBtn = new Button("Create If Not Exist", new Point(Bounds.X, manageBtn.Bounds.Bottom + 10));
            createIfNotExistBtn.OnClick(createNewObjectIfNotExists);

            // Create Btn
            createBtn = new Button("Create New", new Point(createIfNotExistBtn.Bounds.Right + 10, manageBtn.Bounds.Bottom + 10));
            createBtn.OnClick(createNewObject);

            // Edit Instance Btn
            editInstanceBtn = new Button("Edit", new Point(Bounds.X, manageBtn.Bounds.Bottom + 10));
            editInstanceBtn.OnClick(handleEditInstanceBtnClick);

            // Remove Instance Btn
            removeInstanceBtn = new Button("Remove", new Point(editInstanceBtn.Bounds.Right + 10, manageBtn.Bounds.Bottom + 10));
            removeInstanceBtn.OnClick(handleRemoveInstanceBtnClick);

            // Show Instance Type Btn
            showInstanceTypeBtn = new Button("Show Type", new Point(removeInstanceBtn.Bounds.Right + 10, manageBtn.Bounds.Bottom + 10));
            showInstanceTypeBtn.OnClick(handleShowInstanceTypeBtnClick);

            // Change Persistency Btn
            changePersistencyBtn = new Button("Change Persistency", new Point(Bounds.X, worldPartBtn.Bounds.Bottom + 10));
            changePersistencyBtn.OnClick(handleChangePersistencyBtn);

            // Create WorldLink Btn
            createWorldLinkBtn = new Button("Create Worldlink", new Point(changePersistencyBtn.Bounds.Right + 10, worldPartBtn.Bounds.Bottom + 10));
            createWorldLinkBtn.OnClick(handleCreateWorldLinkBtn);

            // Create Interior Btn
            createInteriorBtn = new Button("Create Interior", new Point(createWorldLinkBtn.Bounds.Right + 10, worldPartBtn.Bounds.Bottom + 10));
            createInteriorBtn.OnClick(handleCreateInteriorBtn);

            // Change Interior Dimensions Btn
            changeInteriorDimensionsBtn = new Button("Change Dimensions", new Point(Bounds.X, manageBtn.Bounds.Bottom + 10));
            changeInteriorDimensionsBtn.OnClick(hanleChangeInteriorDimensionsBtn);

            // Delete Interior Btn
            removeInteriorBtn = new Button("Remove Interior", new Point(changeInteriorDimensionsBtn.Bounds.Right + 10, manageBtn.Bounds.Bottom + 10));
            removeInteriorBtn.OnClick(handleRemoveInteriorBtn);

            OnKeyPress(Keys.Delete, handleRemoveInstanceBtnClick);
            OnRightClick(() =>
            {
                if (placementMode == PlacementMode.CreateFromTileset)
                {
                    placementMode = PlacementMode.ChooseTileset;
                }
            });
            OnKeyPress(Keys.Back, () => {
                if (placementMode == PlacementMode.CreateFromTileset)
                {
                    placementMode = PlacementMode.ChooseTileset;
                }
            });

            AddElement(blockTypeBtn);
            AddElement(ambientObjectTypeBtn);
            AddElement(ambientHitableObjectTypeBtn);
            AddElement(livingEntityTypeBtn);
            AddElement(worldPartBtn);
        }