示例#1
0
        /// <summary>
        /// Base Constructor
        /// </summary>
        /// <param name="manager">ScreenManager</param>
        public TabControl(BaseScreenComponent manager)
            : base(manager)
        {
            Pages = new ItemCollection<TabPage>();
            Pages.OnInsert += OnInsert;
            Pages.OnRemove += OnRemove;

            tabControlGrid = new Grid(manager)
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch
            };
            tabControlGrid.Columns.Add(new ColumnDefinition() {ResizeMode = ResizeMode.Parts, Width = 1});
            tabControlGrid.Rows.Add(new RowDefinition() {ResizeMode = ResizeMode.Auto});
            tabControlGrid.Rows.Add(new RowDefinition() {ResizeMode = ResizeMode.Parts, Height =  1});
            Content = tabControlGrid;

            tabListStack = new StackPanel(manager);
            tabListStack.HorizontalAlignment = HorizontalAlignment.Stretch;
            tabListStack.Orientation = Orientation.Horizontal;
            tabListStack.Background = TabListBackground;
            tabControlGrid.AddControl(tabListStack, 0, 0);

            tabPage = new ContentControl(manager);
            tabPage.HorizontalAlignment = HorizontalAlignment.Stretch;
            tabPage.VerticalAlignment = VerticalAlignment.Stretch;
            tabPage.Background = TabPageBackground;
            tabControlGrid.AddControl(tabPage, 0, 1);

            ApplySkin(typeof(TabControl));
        }
        public CreateUniverseScreen(ScreenComponent manager)
            : base(manager)
        {
            Manager = manager;
            settings = manager.Game.Settings;

            Padding = new Border(0, 0, 0, 0);

            Title = Languages.OctoClient.CreateUniverse;

            SetDefaultBackground();

            Panel panel = new Panel(manager);
            panel.VerticalAlignment = VerticalAlignment.Stretch;
            panel.HorizontalAlignment = HorizontalAlignment.Stretch;
            panel.Margin = Border.All(50);
            panel.Background = new BorderBrush(Color.White * 0.5f);
            panel.Padding = Border.All(10);
            Controls.Add(panel);

            Grid grid = new Grid(manager);
            grid.VerticalAlignment = VerticalAlignment.Stretch;
            grid.HorizontalAlignment = HorizontalAlignment.Stretch;
            panel.Controls.Add(grid);

            grid.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Auto });
            grid.Columns.Add(new ColumnDefinition() { Width = 1,ResizeMode = ResizeMode.Parts });

            nameInput = GetTextbox();
            nameInput.TextChanged += (s, e) => {
                createButton.Visible = !string.IsNullOrEmpty(e.NewValue);
            };
            AddLabeledControl(grid, string.Format("{0}: ", Languages.OctoClient.Name), nameInput);

            seedInput = GetTextbox();
            AddLabeledControl(grid, string.Format("{0}: ", Languages.OctoClient.Seed), seedInput);

            createButton = Button.TextButton(manager, Languages.OctoClient.Create);
            createButton.HorizontalAlignment = HorizontalAlignment.Right;
            createButton.VerticalAlignment = VerticalAlignment.Bottom;
            createButton.Visible = false;
            createButton.LeftMouseClick += (s, e) =>
            {
                if (string.IsNullOrEmpty(nameInput.Text))
                    return;

                int? seed = null;
                int textseed;
                if (int.TryParse(seedInput.Text, out textseed))
                    seed = textseed;

                manager.Player.RemovePlayer();
                Guid guid = Manager.Game.Simulation.NewGame(nameInput.Text, seed);
                settings.Set("LastUniverse", guid.ToString());
                manager.Game.Player.InsertPlayer();
                manager.NavigateToScreen(new GameScreen(manager));
            };
            panel.Controls.Add(createButton);
        }
示例#3
0
        public ToolbarControl(ScreenComponent screenManager)
            : base(screenManager)
        {
            Player = screenManager.Player;
            toolTextures = new Dictionary<string, Texture2D>();

            buttonBackgroud = new BorderBrush(Color.Black);
            activeBackground = new BorderBrush(Color.Red);

            foreach (var item in DefinitionManager.Instance.GetItemDefinitions())
            {
                Texture2D texture = screenManager.Game.Assets.LoadTexture(item.GetType(), item.Icon);
                toolTextures.Add(item.GetType().FullName, texture);
            }

            Grid grid = new Grid(screenManager)
            {
                Margin = new Border(0, 0, 0, 0),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Bottom
            };
            Controls.Add(grid);

            grid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Auto, Height = 1 });
            grid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Fixed, Height = 50 });

            for (int i = 0; i < OctoAwesome.Player.TOOLCOUNT; i++)
            {
                grid.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Fixed, Width = 50 });
            }

            activeToolLabel = new Label(screenManager);
            activeToolLabel.VerticalAlignment = VerticalAlignment.Top;
            activeToolLabel.HorizontalAlignment = HorizontalAlignment.Center;
            activeToolLabel.Background = new BorderBrush(Color.Black * 0.3f);
            activeToolLabel.TextColor = Color.White;
            grid.AddControl(activeToolLabel, 0, 0, OctoAwesome.Player.TOOLCOUNT);

            for (int i = 0; i < OctoAwesome.Player.TOOLCOUNT; i++)
            {
                buttons[i] = new Button(screenManager)
                {
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    VerticalAlignment = VerticalAlignment.Stretch,
                    Background = buttonBackgroud,
                    HoveredBackground = null,
                    PressedBackground = null,
                };
                buttons[i].Content = images[i] = new Image(screenManager)
                {
                    Width = 42,
                    Height = 42,
                };
                grid.AddControl(buttons[i], i, 1);
            }
        }
示例#4
0
        public InventoryControl(ScreenComponent manager, int columns = COLUMNS)
            : base(manager)
        {
            ScrollContainer scroll = new ScrollContainer(manager)
            {
                Margin = new Border(0, 0, 0, 0),
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
            };
            Controls.Add(scroll);

            Grid grid = new Grid(manager)
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
            };
            for (int i = 0; i < columns; i++)
                grid.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Parts, Width = 1 });
            int rows = (int)System.Math.Ceiling((float)manager.Game.Player.ActorHost.Player.Inventory.Count / columns);
            for (int i = 0; i < rows; i++)
                grid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Fixed, Height = 50 });

            int column = 0;
            int row = 0;
            foreach (var item in manager.Game.Player.ActorHost.Player.Inventory)
            {
                Texture2D texture = manager.Game.Assets.LoadTexture(item.Definition.GetType(), item.Definition.Icon);

                var image = new Image(manager) { Texture = texture, Width = 42, Height = 42, VerticalAlignment = VerticalAlignment.Center };
                image.MouseEnter += (s, e) => { HoveredSlot = item; };
                image.MouseLeave += (s, e) => { HoveredSlot = null; };
                image.StartDrag += (e) =>
                {
                    e.Handled = true;
                    e.Icon = texture;
                    e.Content = item;
                    e.Sender = image;
                };
                var label = new Label(manager) { Text = item.Amount.ToString(), HorizontalAlignment = HorizontalAlignment.Right, VerticalTextAlignment = VerticalAlignment.Bottom, Background = new BorderBrush(Color.White) };
                grid.AddControl(image, column, row);
                grid.AddControl(label, column, row);

                column++;
                if (column >= columns)
                {
                    row++;
                    column = 0;
                }
            }

            scroll.Content = grid;
        }
        public ResourcePacksOptionControl(ScreenComponent manager)
            : base(manager)
        {
            Grid grid = new Grid(manager)
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                Margin = Border.All(15),
            };
            Controls.Add(grid);

            grid.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Parts, Width = 1 });
            grid.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Fixed, Width = 100 });
            grid.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Parts, Width = 1 });
            grid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Parts, Height = 1 });
            grid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Auto, Height = 1 });
            grid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Auto, Height = 1 });

            StackPanel buttons = new StackPanel(manager)
            {
                VerticalAlignment = VerticalAlignment.Stretch,
            };
            grid.AddControl(buttons, 1, 0);

            #region Manipulationsbuttons

            addButton = Button.TextButton(manager, "Add");
            addButton.HorizontalAlignment = HorizontalAlignment.Stretch;
            addButton.Visible = false;
            buttons.Controls.Add(addButton);

            removeButton = Button.TextButton(manager, "Remove");
            removeButton.HorizontalAlignment = HorizontalAlignment.Stretch;
            removeButton.Visible = false;
            buttons.Controls.Add(removeButton);

            moveUpButton = Button.TextButton(manager, "Up");
            moveUpButton.HorizontalAlignment = HorizontalAlignment.Stretch;
            moveUpButton.Visible = false;
            buttons.Controls.Add(moveUpButton);

            moveDownButton = Button.TextButton(manager, "Down");
            moveDownButton.HorizontalAlignment = HorizontalAlignment.Stretch;
            moveDownButton.Visible = false;
            buttons.Controls.Add(moveDownButton);

            #endregion

            applyButton = Button.TextButton(manager, "Apply");
            applyButton.HorizontalAlignment = HorizontalAlignment.Right;
            applyButton.VerticalAlignment = VerticalAlignment.Bottom;
            grid.AddControl(applyButton, 0, 2, 3);

            infoLabel = new Label(ScreenManager)
            {
                HorizontalTextAlignment = HorizontalAlignment.Left,
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Top,
                WordWrap = true,
            };
            grid.AddControl(infoLabel, 0, 1, 3);

            #region Listen

            loadedPacksList = new Listbox<ResourcePack>(manager)
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                SelectedItemBrush = new BorderBrush(Color.SaddleBrown * 0.7f),
                TemplateGenerator = ListTemplateGenerator,
            };

            grid.AddControl(loadedPacksList, 0, 0);

            activePacksList = new Listbox<ResourcePack>(manager)
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                SelectedItemBrush = new BorderBrush(Color.SaddleBrown * 0.7f),
                TemplateGenerator = ListTemplateGenerator,
            };

            grid.AddControl(activePacksList, 2, 0);

            #endregion

            #region Info Grid

            //Grid infoGrid = new Grid(ScreenManager)
            //{
            //    HorizontalAlignment = HorizontalAlignment.Stretch,
            //};

            //infoGrid.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Auto, Width = 1 });
            //infoGrid.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Parts, Width = 1 });
            //infoGrid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Auto, Height = 1 });
            //infoGrid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Auto, Height = 1 });
            //infoGrid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Auto, Height = 1 });

            //Label nameLabel = new Label(ScreenManager)
            //{
            //    Text = "Name:",
            //};
            //infoGrid.AddControl(nameLabel, 0, 0);

            //Label authorLabel = new Label(ScreenManager)
            //{
            //    Text = "Author:",
            //};
            //infoGrid.AddControl(authorLabel, 0, 1);

            //Label descriptionLabel = new Label(ScreenManager)
            //{
            //    Text = "Description:",
            //};
            //infoGrid.AddControl(descriptionLabel, 0, 2);

            //grid.AddControl(infoGrid, 0, 1, 3);

            #endregion

            loadedPacksList.SelectedItemChanged += loadedList_SelectedItemChanged;
            activePacksList.SelectedItemChanged += activeList_SelectedItemChanged;

            addButton.LeftMouseClick += (s, e) =>
            {
                ResourcePack pack = loadedPacksList.SelectedItem;
                loadedPacksList.Items.Remove(pack);
                activePacksList.Items.Add(pack);
                activePacksList.SelectedItem = pack;
            };

            removeButton.LeftMouseClick += (s, e) =>
            {
                ResourcePack pack = activePacksList.SelectedItem;
                activePacksList.Items.Remove(pack);
                loadedPacksList.Items.Add(pack);
                loadedPacksList.SelectedItem = pack;
            };

            moveUpButton.LeftMouseClick += (s, e) =>
            {
                ResourcePack pack = activePacksList.SelectedItem;
                if (pack == null)
                    return;

                int index = activePacksList.Items.IndexOf(pack);
                if (index > 0)
                {
                    activePacksList.Items.Remove(pack);
                    activePacksList.Items.Insert(index - 1, pack);
                    activePacksList.SelectedItem = pack;
                }
            };

            moveDownButton.LeftMouseClick += (s, e) =>
            {
                ResourcePack pack = activePacksList.SelectedItem;
                if (pack == null) return;

                int index = activePacksList.Items.IndexOf(pack);
                if (index < activePacksList.Items.Count - 1)
                {
                    activePacksList.Items.Remove(pack);
                    activePacksList.Items.Insert(index + 1, pack);
                    activePacksList.SelectedItem = pack;
                }
            };

            applyButton.LeftMouseClick += (s, e) =>
            {
                manager.Game.Assets.ApplyResourcePacks(activePacksList.Items);
                Program.Restart();
            };

            // Daten laden

            AssetComponent assets = manager.Game.Assets;
            foreach (var item in assets.LoadedResourcePacks)
                loadedPacksList.Items.Add(item);

            foreach (var item in manager.Game.Assets.ActiveResourcePacks)
            {
                activePacksList.Items.Add(item);
                if (loadedPacksList.Items.Contains(item))
                    loadedPacksList.Items.Remove(item);
            }
        }
 private void AddLabeledControl(Grid grid, String name, Control c)
 {
     grid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Auto });
     grid.AddControl(new Label(Manager) { Text = name }, 0, grid.Rows.Count -1);
     grid.AddControl(c, 1, grid.Rows.Count - 1);
     grid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Fixed, Height = 10 });
 }
示例#7
0
        public InventoryScreen(ScreenComponent manager)
            : base(manager)
        {
            assets = manager.Game.Assets;

            foreach (var item in DefinitionManager.Instance.GetItemDefinitions())
            {
                Texture2D texture = manager.Game.Assets.LoadTexture(item.GetType(), item.Icon);
                toolTextures.Add(item.GetType().FullName, texture);
            }

            player = manager.Player;
            IsOverlay = true;
            Background = new BorderBrush(Color.Black * 0.5f);

            backgroundBrush = new BorderBrush(Color.Black);
            hoverBrush = new BorderBrush(Color.Brown);

            Texture2D panelBackground = assets.LoadTexture(typeof(ScreenComponent), "panel");

            Grid grid = new Grid(manager)
            {
                Width = 800,
                Height = 500,
            };

            grid.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Fixed, Width = 600 });
            grid.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Fixed, Width = 200 });
            grid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Parts, Height = 1 });
            grid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Fixed, Height = 100 });

            Controls.Add(grid);

            inventory = new InventoryControl(manager)
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                Background = NineTileBrush.FromSingleTexture(panelBackground, 30, 30),
                Padding = Border.All(20),
            };

            grid.AddControl(inventory, 0, 0);

            StackPanel infoPanel = new StackPanel(manager)
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                Background = NineTileBrush.FromSingleTexture(panelBackground, 30, 30),
                Padding = Border.All(20),
                Margin = Border.All(10, 0, 0, 0),
            };

            nameLabel = new Label(manager);
            infoPanel.Controls.Add(nameLabel);
            massLabel = new Label(manager);
            infoPanel.Controls.Add(massLabel);
            volumeLabel = new Label(manager);
            infoPanel.Controls.Add(volumeLabel);
            grid.AddControl(infoPanel, 1, 0);

            Grid toolbar = new Grid(manager)
            {
                Margin = Border.All(0, 10, 0, 0),
                Height = 100,
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                Background = NineTileBrush.FromSingleTexture(panelBackground, 30, 30),
            };

            toolbar.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Parts, Width = 1 });
            for (int i = 0; i < Player.TOOLCOUNT; i++)
                toolbar.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Fixed, Width = 50 });
            toolbar.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Parts, Width = 1 });
            toolbar.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Parts, Height = 1 });

            images = new Image[Player.TOOLCOUNT];
            for (int i = 0; i < Player.TOOLCOUNT; i++)
            {
                Image image = images[i] = new Image(manager)
                {
                    Width = 42,
                    Height = 42,
                    Background = backgroundBrush,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    Tag = i,
                    Padding = Border.All(2),
                };

                image.StartDrag += (e) =>
                {
                    InventorySlot slot = player.ActorHost.Player.Tools[(int)image.Tag];
                    if (slot != null)
                    {
                        e.Handled = true;
                        e.Icon = toolTextures[slot.Definition.GetType().FullName];
                        e.Content = slot;
                        e.Sender = toolbar;
                    }
                };

                image.DropEnter += (e) => { image.Background = hoverBrush; };
                image.DropLeave += (e) => { image.Background = backgroundBrush; };
                image.EndDrop += (e) =>
                {
                    e.Handled = true;

                    if (e.Sender is Grid) // && ShiftPressed
                    {
                        // Swap
                        int targetIndex = (int)image.Tag;
                        InventorySlot targetSlot = player.ActorHost.Player.Tools[targetIndex];
                        int sourceIndex = -1;
                        InventorySlot sourceSlot = e.Content as InventorySlot;

                        for (int j = 0; j < player.ActorHost.Player.Tools.Length; j++)
                        {
                            if (player.ActorHost.Player.Tools[j] == sourceSlot)
                            {
                                sourceIndex = j;
                                break;
                            }
                        }

                        SetTool(sourceSlot, targetIndex);
                        SetTool(targetSlot, sourceIndex);
                    }
                    else
                    {
                        // Inventory Drop
                        InventorySlot slot = e.Content as InventorySlot;
                        SetTool(slot, (int)image.Tag);
                    }
                };

                toolbar.AddControl(image, i + 1, 0);
            }

            grid.AddControl(toolbar, 0, 1, 2);
            Title = Languages.OctoClient.Inventory;
        }
示例#8
0
        public LoadScreen(ScreenComponent manager)
            : base(manager)
        {
            Manager = manager;

            Padding = new Border(0, 0, 0, 0);

            Title = Languages.OctoClient.SelectUniverse;

            SetDefaultBackground();

            //Main Panel
            mainStack = new Grid(manager);
            mainStack.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Parts, Width = 3 });
            mainStack.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Parts, Width = 1 });
            mainStack.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Parts, Height = 1 });
            mainStack.Margin = Border.All(50);
            mainStack.HorizontalAlignment = HorizontalAlignment.Stretch;
            mainStack.VerticalAlignment = VerticalAlignment.Stretch;

            Controls.Add(mainStack);

            //Level Stack
            levelList = new Listbox<IUniverse>(manager);
            levelList.Background = new BorderBrush(Color.White * 0.5f);
            levelList.VerticalAlignment = VerticalAlignment.Stretch;
            levelList.HorizontalAlignment = HorizontalAlignment.Stretch;
            levelList.Margin = Border.All(10);
            levelList.SelectedItemBrush = new BorderBrush(Color.SaddleBrown * 0.7f);
            levelList.TemplateGenerator += (x) =>
            {
                return new Label(manager)
                {
                    Text = string.Format("{0} ({1})", x.Name, x.Seed),
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    Padding = Border.All(10),
                };
            };
            mainStack.AddControl(levelList, 0, 0);

            //Sidebar
            Panel sidebar = new Panel(manager);
            sidebar.Padding = Border.All(20);
            sidebar.VerticalAlignment = VerticalAlignment.Stretch;
            sidebar.HorizontalAlignment = HorizontalAlignment.Stretch;
            sidebar.Background = new BorderBrush(Color.White * 0.5f);
            sidebar.Margin = Border.All(10);
            mainStack.AddControl(sidebar, 1, 0);

            //Universe Info
            Label l = new Label(manager);
            l.Text = " Placeholder ";
            l.VerticalAlignment = VerticalAlignment.Top;
            l.HorizontalAlignment = HorizontalAlignment.Left;
            sidebar.Controls.Add(l);

            //Buttons
            StackPanel buttonStack = new StackPanel(manager);
            buttonStack.VerticalAlignment = VerticalAlignment.Bottom;
            buttonStack.HorizontalAlignment = HorizontalAlignment.Stretch;
            sidebar.Controls.Add(buttonStack);

            //renameButton = getButton("Rename");
            //buttonStack.Controls.Add(renameButton);

            deleteButton = GetButton(Languages.OctoClient.Delete);
            buttonStack.Controls.Add(deleteButton);
            deleteButton.LeftMouseClick += (s, e) =>
            {
                if (levelList.SelectedItem == null)
                {
                    MessageScreen msg = new MessageScreen(manager, Languages.OctoClient.Error, Languages.OctoClient.SelectUniverseFirst);
                    manager.NavigateToScreen(msg);

                    return;
                }

                // Sicherstellen, dass universe nicht geladen ist
                if (ResourceManager.Instance.CurrentUniverse != null &&
                    ResourceManager.Instance.CurrentUniverse.Id == levelList.SelectedItem.Id)
                    return;

                ResourceManager.Instance.DeleteUniverse(levelList.SelectedItem.Id);
                levelList.Items.Remove(levelList.SelectedItem);
                levelList.SelectedItem = null;
                levelList.InvalidateDimensions();
                SettingsManager.Set("LastUniverse", "");
            };

            createButton = GetButton(Languages.OctoClient.Create);
            createButton.LeftMouseClick += (s, e) => manager.NavigateToScreen(new CreateUniverseScreen(manager));
            buttonStack.Controls.Add(createButton);

            playButton = GetButton(Languages.OctoClient.Play);
            playButton.LeftMouseClick += (s, e) =>
            {
                if (levelList.SelectedItem == null)
                {
                    MessageScreen msg = new MessageScreen(manager, Languages.OctoClient.Error, Languages.OctoClient.SelectUniverseFirst);
                    manager.NavigateToScreen(msg);

                    return;
                }

                Play();
            };
            buttonStack.Controls.Add(playButton);

            foreach (var universe in ResourceManager.Instance.ListUniverses())
                levelList.Items.Add(universe);

            // Erstes Element auswählen, oder falls vorhanden das letzte gespielte Universum
            if (levelList.Items.Count >= 1)
                levelList.SelectedItem = levelList.Items[0];

            if (SettingsManager.KeyExists("LastUniverse") && SettingsManager.Get("LastUniverse") != null
                && SettingsManager.Get("LastUniverse") != "")
            {
                levelList.SelectedItem = levelList.Items.First(u => u.Id == Guid.Parse(SettingsManager.Get("LastUniverse")));
            }
        }
示例#9
0
        public LoadScreen(ScreenComponent manager)
            : base(manager)
        {
            Manager = manager;

            Padding = new Border(0, 0, 0, 0);

            SetDefaultBackground();

            //Main Panel
            mainStack = new Grid(manager);
            mainStack.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Parts, Width = 3 });
            mainStack.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Parts, Width = 1 });
            mainStack.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Parts, Height = 1 });
            mainStack.Margin = Border.All(50);
            mainStack.HorizontalAlignment = HorizontalAlignment.Stretch;
            mainStack.VerticalAlignment = VerticalAlignment.Stretch;

            Controls.Add(mainStack);

            //Level Stack
            Listbox<IUniverse> levelList = new Listbox<IUniverse>(manager);
            levelList.Background = new BorderBrush(Color.White * 0.5f);
            levelList.VerticalAlignment = VerticalAlignment.Stretch;
            levelList.HorizontalAlignment = HorizontalAlignment.Stretch;
            levelList.Margin = Border.All(10);
            levelList.TemplateGenerator += (x) =>
            {
                return new Label(manager)
                {
                    Text = string.Format("{0} ({1})", x.Name, x.Seed),
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    Padding = Border.All(10),
                };
            };
            levelList.SelectedItemChanged += (s, e) =>
            {
                playButton.Enabled = e.NewItem != null;
                deleteButton.Enabled = e.NewItem != null;
            };
            mainStack.AddControl(levelList, 0, 0);

            //Sidebar
            Panel sidebar = new Panel(manager);
            sidebar.Padding = Border.All(20);
            sidebar.VerticalAlignment = VerticalAlignment.Stretch;
            sidebar.HorizontalAlignment = HorizontalAlignment.Stretch;
            sidebar.Background = new BorderBrush(Color.White * 0.5f);
            sidebar.Margin = Border.All(10);
            mainStack.AddControl(sidebar, 1, 0);

            //Universe Info
            Label l = new Label(manager);
            l.Text = " Placeholder ";
            l.VerticalAlignment = VerticalAlignment.Top;
            l.HorizontalAlignment = HorizontalAlignment.Left;
            sidebar.Controls.Add(l);

            //Buttons
            StackPanel buttonStack = new StackPanel(manager);
            buttonStack.VerticalAlignment = VerticalAlignment.Bottom;
            buttonStack.HorizontalAlignment = HorizontalAlignment.Stretch;
            sidebar.Controls.Add(buttonStack);

            //renameButton = getButton("Rename");
            //buttonStack.Controls.Add(renameButton);

            deleteButton = getButton("Delete");
            buttonStack.Controls.Add(deleteButton);
            deleteButton.LeftMouseClick += (s, e) =>
            {
                if (levelList.SelectedItem == null)
                    return;

                // Sicherstellen, dass universe nicht geladen ist
                if (ResourceManager.Instance.CurrentUniverse != null &&
                    ResourceManager.Instance.CurrentUniverse.Id == levelList.SelectedItem.Id)
                    return;

                ResourceManager.Instance.DeleteUniverse(levelList.SelectedItem.Id);
                levelList.Items.Remove(levelList.SelectedItem);
                levelList.SelectedItem = null;
                levelList.InvalidateDimensions();
            };

            createButton = getButton("Create");
            createButton.LeftMouseClick += (s, e) => manager.NavigateToScreen(new CreateUniverseScreen(manager));
            buttonStack.Controls.Add(createButton);

            playButton = getButton("Play");
            playButton.LeftMouseClick += (s, e) =>
            {
                if (levelList.SelectedItem == null)
                    return;

                manager.Player.RemovePlayer();
                manager.Game.Simulation.LoadGame(levelList.SelectedItem.Id);
                manager.Game.Player.InsertPlayer();
                manager.NavigateToScreen(new GameScreen(manager));
            };
            buttonStack.Controls.Add(playButton);

            foreach (var universe in ResourceManager.Instance.ListUniverses())
                levelList.Items.Add(universe);
        }