Пример #1
0
 public void Render(Rectangle Where, Gum.Root Gui)
 {
     Gui.DrawQuad(Where, RenderTarget);
 }
Пример #2
0
        protected override void LoadContent()
        {
            var renderData = new Gum.RenderData(
                GraphicsDevice,
                this.Content,
#if GEMXNA
                "Content/xna_draw",
#elif GEMMONO
                "Content/mono_draw",
#endif
                "Content/dwarf_corp_skin/sheets.txt");

            GuiRoot = new Root(new Point(640, 480), renderData);

            GuiRoot.MousePointer    = new MousePointer("mouse", 1.0f, 0);
            GuiRoot.TooltipTextSize = 2;

            var frame = GuiRoot.RootItem.AddChild(new Widget
            {
                Text                = "- DEMO MENU -",
                Border              = "border-one",
                TextSize            = 1,
                TextColor           = new Vector4(1, 0, 0, 1),
                TextHorizontalAlign = HorizontalAlign.Center,
                MinimumSize         = new Point(256, 256),
                AutoLayout          = AutoLayout.FloatCenter,
                InteriorMargin      = new Margin
                {
                    Top = GuiRoot.GetTileSheet("font2").TileHeight * 2
                },
                Padding = new Margin(2, 2, 2, 2),
                Font    = "font2"
            });

            frame.AddChild(new Widget
            {
                Text    = "View Atlas",
                Border  = "border-thin",
                OnClick = (sender, args) =>
                {
                    var dialog = GuiRoot.ConstructWidget(new ShowTextureDialog());
                    GuiRoot.ShowDialog(dialog);
                    GuiRoot.RootItem.Layout();
                },
                TextHorizontalAlign = HorizontalAlign.Center,
                TextVerticalAlign   = VerticalAlign.Center,
                AutoLayout          = AutoLayout.DockTop,
                Font = "font2"
            });

            frame.AddChild(new Widget
            {
                Text    = "View Demo Pane",
                Border  = "border-thin",
                OnClick = (sender, args) =>
                {
                    var dialog = GuiRoot.ConstructWidget(new DemoDialog());
                    GuiRoot.ShowDialog(dialog);
                },
                TextHorizontalAlign = HorizontalAlign.Center,
                TextVerticalAlign   = VerticalAlign.Center,
                AutoLayout          = AutoLayout.DockTop,
                Font = "font2"
            });

            frame.AddChild(new Widget
            {
                Text    = "View Tab Pane",
                Border  = "border-thin",
                OnClick = (sender, args) =>
                {
                    var dialog = GuiRoot.ConstructWidget(new TabDialog());
                    GuiRoot.ShowDialog(dialog);
                },
                TextHorizontalAlign = HorizontalAlign.Center,
                TextVerticalAlign   = VerticalAlign.Center,
                AutoLayout          = AutoLayout.DockTop,
                Font = "font2"
            });

            frame.AddChild(new Widget
            {
                Text    = "View Tilable Border Pane",
                Border  = "border-thin",
                OnClick = (sender, args) =>
                {
                    var dialog = GuiRoot.ConstructWidget(new BorderTilingDialog());
                    GuiRoot.ShowDialog(dialog);
                },
                TextHorizontalAlign = HorizontalAlign.Center,
                TextVerticalAlign   = VerticalAlign.Center,
                AutoLayout          = AutoLayout.DockTop,
                Font = "font2"
            });

            frame.AddChild(new Widget
            {
                Text    = "Toggle Alignment",
                Border  = "border-thin",
                OnClick = (sender, args) =>
                {
                    if (frame.AutoLayout == AutoLayout.FloatTopRight)
                    {
                        frame.AutoLayout = AutoLayout.FloatBottomRight;
                    }
                    else if (frame.AutoLayout == AutoLayout.FloatBottomRight)
                    {
                        frame.AutoLayout = AutoLayout.FloatBottomLeft;
                    }
                    else if (frame.AutoLayout == AutoLayout.FloatBottomLeft)
                    {
                        frame.AutoLayout = AutoLayout.FloatTopLeft;
                    }
                    else if (frame.AutoLayout == AutoLayout.FloatTopLeft)
                    {
                        frame.AutoLayout = AutoLayout.FloatTopRight;
                    }
                    else
                    {
                        frame.AutoLayout = AutoLayout.FloatTopLeft;
                    }
                    GuiRoot.RootItem.Layout();
                },
                TextHorizontalAlign = HorizontalAlign.Center,
                TextVerticalAlign   = VerticalAlign.Center,
                AutoLayout          = AutoLayout.DockTop,
                Font = "font2"
            });

            GuiRoot.RootItem.Layout();
        }
Пример #3
0
        private void RebuildGui()
        {
            // Create and initialize GUI framework.
            GuiRoot = new Gum.Root(new Point(640, 480), DwarfGame.GumSkin);
            GuiRoot.MousePointer = new Gum.MousePointer("mouse", 4, 0);

            // CONSTRUCT GUI HERE...
            MainPanel = GuiRoot.RootItem.AddChild(new Gum.Widget
            {
                Rect        = GuiRoot.VirtualScreen,
                Padding     = new Margin(4, 4, 4, 4),
                Transparent = true
            });

            MainPanel.AddChild(new Widget
            {
                Text = "CLOSE",
                TextHorizontalAlign = HorizontalAlign.Center,
                TextVerticalAlign   = VerticalAlign.Center,
                Border  = "border-button",
                OnClick = (sender, args) =>
                {
                    // If changes, prompt before closing.
                    if (HasChanges)
                    {
                        var confirm = new NewGui.Confirm
                        {
                            Text       = "Apply changes?",
                            OkayText   = "YES",
                            CancelText = "NO",
                            OnClose    = (s2) =>
                            {
                                if ((s2 as NewGui.Confirm).DialogResult == NewGui.Confirm.Result.OKAY)
                                {
                                    ApplySettings();
                                }
                                StateManager.PopState();
                            }
                        };
                        GuiRoot.ShowPopup(confirm, false);
                    }
                    else
                    {
                        StateManager.PopState();
                    }
                },
                AutoLayout = AutoLayout.FloatBottomRight
            });

            MainPanel.AddChild(new Widget
            {
                Text = "APPLY",
                TextHorizontalAlign = HorizontalAlign.Center,
                TextVerticalAlign   = VerticalAlign.Center,
                Border  = "border-button",
                OnClick = (sender, args) =>
                {
                    ApplySettings();
                },
                AutoLayout = AutoLayout.FloatBottomRight,
                OnLayout   = s => s.Rect.X -= 128 // Hack to keep it from floating over the other button.
            });

            TabPanel = MainPanel.AddChild(new Gum.Widgets.TabPanel
            {
                AutoLayout       = AutoLayout.DockFill,
                TextSize         = 2,
                SelectedTabColor = new Vector4(1, 0, 0, 1),
                OnLayout         = (sender) => sender.Rect.Height -= 36 // Keep it from overlapping bottom buttons.
            }) as Gum.Widgets.TabPanel;

            CreateGameplayTab();
            CreateAudioTab();
            CreateKeysTab();
            CreateGraphicsTab();

            TabPanel.SelectedTab = 0;

            GuiRoot.RootItem.Layout();

            LoadSettings();
        }
Пример #4
0
        public override void OnEnter()
        {
            // Clear the input queue... cause other states aren't using it and it's been filling up.
            DwarfGame.GumInputMapper.GetInputQueue();

            GuiRoot = new Gum.Root(new Point(640, 480), DwarfGame.GumSkin);
            GuiRoot.MousePointer = new Gum.MousePointer("mouse", 4, 0);

            // CONSTRUCT GUI HERE...
            var mainPanel = GuiRoot.RootItem.AddChild(new Gum.Widget
            {
                Rect           = GuiRoot.VirtualScreen,
                Border         = "border-fancy",
                Text           = "Create a Company",
                Padding        = new Margin(4, 4, 4, 4),
                InteriorMargin = new Margin(24, 0, 0, 0),
                TextSize       = 2
            });

            mainPanel.AddChild(new Gum.Widgets.Button
            {
                Text = "CREATE!",
                TextHorizontalAlign = HorizontalAlign.Center,
                TextVerticalAlign   = VerticalAlign.Center,
                Border  = "border-button",
                OnClick = (sender, args) =>
                {
                    // Grab string values from widgets!
                    CompanyInformation.Name  = NameField.Text;
                    CompanyInformation.Motto = MottoField.Text;

                    // Why are they stored as statics on this class???
                    StateManager.PushState(new NewGameChooseWorldState(Game, Game.StateManager));
                },
                AutoLayout = AutoLayout.FloatBottomRight
            });

            mainPanel.AddChild(new Gum.Widgets.Button
            {
                Text = "BACK",
                TextHorizontalAlign = HorizontalAlign.Center,
                TextVerticalAlign   = VerticalAlign.Center,
                Border  = "border-button",
                OnClick = (sender, args) =>
                {
                    StateManager.PopState();
                },
                AutoLayout = AutoLayout.FloatBottomRight,
                OnLayout   = s => s.Rect.X -= 128 // Hack to keep it from floating over the other button.
            });

            #region Name
            var nameRow = mainPanel.AddChild(new Widget
            {
                MinimumSize = new Point(0, 24),
                AutoLayout  = AutoLayout.DockTop,
                Padding     = new Margin(0, 0, 2, 2)
            });

            nameRow.AddChild(new Gum.Widget
            {
                MinimumSize         = new Point(64, 0),
                Text                = "Name",
                AutoLayout          = AutoLayout.DockLeft,
                TextHorizontalAlign = HorizontalAlign.Right,
                TextVerticalAlign   = VerticalAlign.Center
            });

            nameRow.AddChild(new Gum.Widgets.Button
            {
                Text       = "Randomize",
                AutoLayout = AutoLayout.DockRight,
                Border     = "border-button",
                OnClick    = (sender, args) =>
                {
                    var templates  = TextGenerator.GetAtoms(ContentPaths.Text.Templates.company_exploration);
                    NameField.Text = TextGenerator.GenerateRandom(Datastructures.SelectRandom(templates).ToArray());
                    // Todo: Doesn't automatically invalidate when text changed??
                    NameField.Invalidate();
                }
            });

            NameField = nameRow.AddChild(new EditableTextField
            {
                Text       = CompanyInformation.Name,
                AutoLayout = AutoLayout.DockFill
            }) as EditableTextField;
            #endregion


            #region Motto
            var mottoRow = mainPanel.AddChild(new Widget
            {
                MinimumSize = new Point(0, 24),
                AutoLayout  = AutoLayout.DockTop,
                Padding     = new Margin(0, 0, 2, 2)
            });

            mottoRow.AddChild(new Widget
            {
                MinimumSize         = new Point(64, 0),
                Text                = "Motto",
                AutoLayout          = AutoLayout.DockLeft,
                TextHorizontalAlign = HorizontalAlign.Right,
                TextVerticalAlign   = VerticalAlign.Center
            });

            mottoRow.AddChild(new Widget
            {
                Text       = "Randomize",
                AutoLayout = AutoLayout.DockRight,
                Border     = "border-button",
                OnClick    = (sender, args) =>
                {
                    var templates   = TextGenerator.GetAtoms(ContentPaths.Text.Templates.mottos);
                    MottoField.Text = TextGenerator.GenerateRandom(Datastructures.SelectRandom(templates).ToArray());
                    // Todo: Doesn't automatically invalidate when text changed??
                    MottoField.Invalidate();
                }
            });

            MottoField = mottoRow.AddChild(new EditableTextField
            {
                Text       = CompanyInformation.Motto,
                AutoLayout = AutoLayout.DockFill
            }) as EditableTextField;
            #endregion

            #region Logo

            var logoRow = mainPanel.AddChild(new Widget
            {
                MinimumSize = new Point(0, 64),
                AutoLayout  = AutoLayout.DockTop,
                Padding     = new Margin(0, 0, 2, 2)
            });

            CompanyLogoDisplay = logoRow.AddChild(new NewGui.CompanyLogo
            {
                AutoLayout         = AutoLayout.DockLeft,
                MinimumSize        = new Point(64, 64),
                MaximumSize        = new Point(64, 64),
                CompanyInformation = CompanyInformation
            }) as NewGui.CompanyLogo;

            logoRow.AddChild(new Widget
            {
                Text       = "BG:",
                AutoLayout = AutoLayout.DockLeft
            });

            logoRow.AddChild(new Widget
            {
                Background  = CompanyInformation.LogoBackground,
                MinimumSize = new Point(32, 32),
                MaximumSize = new Point(32, 32),
                AutoLayout  = AutoLayout.DockLeft,
                OnClick     = (sender, args) =>
                {
                    var source  = GuiRoot.GetTileSheet("company-logo-background") as Gum.TileSheet;
                    var chooser = new NewGui.GridChooser
                    {
                        ItemSource = Enumerable.Range(0, source.Columns * source.Rows)
                                     .Select(i => new Widget {
                            Background = new TileReference("company-logo-background", i)
                        }),
                        OnClose = (s2) =>
                        {
                            var gc = s2 as NewGui.GridChooser;
                            if (gc.DialogResult == NewGui.GridChooser.Result.OKAY &&
                                gc.SelectedItem != null)
                            {
                                sender.Background = gc.SelectedItem.Background;
                                sender.Invalidate();
                                CompanyInformation.LogoBackground = gc.SelectedItem.Background;
                                CompanyLogoDisplay.Invalidate();
                            }
                        },
                        PopupDestructionType = PopupDestructionType.DestroyOnOffClick
                    };
                    GuiRoot.ShowPopup(chooser);
                }
            });

            logoRow.AddChild(new Widget
            {
                Background      = new TileReference("basic", 1),
                BackgroundColor = CompanyInformation.LogoBackgroundColor,
                MinimumSize     = new Point(32, 32),
                MaximumSize     = new Point(32, 32),
                AutoLayout      = AutoLayout.DockLeft,
                OnClick         = (sender, args) =>
                {
                    var chooser = new NewGui.GridChooser
                    {
                        ItemSize    = new Point(16, 16),
                        ItemSpacing = new Point(4, 4),
                        ItemSource  = EnumerateDefaultColors()
                                      .Select(c => new Widget
                        {
                            Background      = new TileReference("basic", 1),
                            BackgroundColor = new Vector4(c.ToVector3(), 1),
                        }),
                        OnClose = (s2) =>
                        {
                            var gc = s2 as NewGui.GridChooser;
                            if (gc.DialogResult == NewGui.GridChooser.Result.OKAY &&
                                gc.SelectedItem != null)
                            {
                                sender.BackgroundColor = gc.SelectedItem.BackgroundColor;
                                sender.Invalidate();
                                CompanyInformation.LogoBackgroundColor = gc.SelectedItem.BackgroundColor;
                                CompanyLogoDisplay.Invalidate();
                            }
                        },
                        PopupDestructionType = PopupDestructionType.DestroyOnOffClick
                    };
                    GuiRoot.ShowPopup(chooser);
                }
            });

            logoRow.AddChild(new Widget
            {
                Text       = "FG:",
                AutoLayout = AutoLayout.DockLeft
            });

            logoRow.AddChild(new Widget
            {
                Background  = CompanyInformation.LogoSymbol,
                MinimumSize = new Point(32, 32),
                MaximumSize = new Point(32, 32),
                AutoLayout  = AutoLayout.DockLeft,
                OnClick     = (sender, args) =>
                {
                    var source  = GuiRoot.GetTileSheet("company-logo-symbol") as Gum.TileSheet;
                    var chooser = new NewGui.GridChooser
                    {
                        ItemSource = Enumerable.Range(0, source.Columns * source.Rows)
                                     .Select(i => new Widget
                        {
                            Background = new TileReference("company-logo-symbol", i)
                        }),
                        OnClose = (s2) =>
                        {
                            var gc = s2 as NewGui.GridChooser;
                            if (gc.DialogResult == NewGui.GridChooser.Result.OKAY &&
                                gc.SelectedItem != null)
                            {
                                sender.Background = gc.SelectedItem.Background;
                                sender.Invalidate();
                                CompanyInformation.LogoSymbol = gc.SelectedItem.Background;
                                CompanyLogoDisplay.Invalidate();
                            }
                        },
                        PopupDestructionType = PopupDestructionType.DestroyOnOffClick
                    };
                    GuiRoot.ShowPopup(chooser);
                }
            });

            logoRow.AddChild(new Widget
            {
                Background      = new TileReference("basic", 1),
                BackgroundColor = CompanyInformation.LogoSymbolColor,
                MinimumSize     = new Point(32, 32),
                MaximumSize     = new Point(32, 32),
                AutoLayout      = AutoLayout.DockLeft,
                OnClick         = (sender, args) =>
                {
                    var chooser = new NewGui.GridChooser
                    {
                        ItemSize    = new Point(16, 16),
                        ItemSpacing = new Point(4, 4),
                        ItemSource  = EnumerateDefaultColors()
                                      .Select(c => new Widget
                        {
                            Background      = new TileReference("basic", 1),
                            BackgroundColor = new Vector4(c.ToVector3(), 1),
                        }),
                        OnClose = (s2) =>
                        {
                            var gc = s2 as NewGui.GridChooser;
                            if (gc.DialogResult == NewGui.GridChooser.Result.OKAY &&
                                gc.SelectedItem != null)
                            {
                                sender.BackgroundColor = gc.SelectedItem.BackgroundColor;
                                sender.Invalidate();
                                CompanyInformation.LogoSymbolColor = gc.SelectedItem.BackgroundColor;
                                CompanyLogoDisplay.Invalidate();
                            }
                        },
                        PopupDestructionType = PopupDestructionType.DestroyOnOffClick
                    };
                    GuiRoot.ShowPopup(chooser);
                }
            });


            #endregion

            GuiRoot.RootItem.Layout();

            // Must be true or Render will not be called.
            IsInitialized = true;

            base.OnEnter();
        }
Пример #5
0
        public override void OnEnter()
        {
            // Clear the input queue... cause other states aren't using it and it's been filling up.
            DwarfGame.GumInputMapper.GetInputQueue();

            GuiRoot = new Gum.Root(new Point(640, 480), DwarfGame.GumSkin);
            GuiRoot.MousePointer = new Gum.MousePointer("mouse", 4, 0);
            MakeMenu();

            Dictionary <GameMaster.ToolMode, Gum.Widget> ToolbarItems = new Dictionary <GameMaster.ToolMode, Gum.Widget>();

            //ToolbarItems[GameMaster.ToolMode.SelectUnits] = CreateIcon(5, GameMaster.ToolMode.SelectUnits);
            //    ToolbarItems[GameMaster.ToolMode.Dig] = CreateIcon(0, GameMaster.ToolMode.Dig);
            //    ToolbarItems[GameMaster.ToolMode.Build] = CreateIcon(2, GameMaster.ToolMode.Build);
            //    ToolbarItems[GameMaster.ToolMode.Cook] = CreateIcon(3, GameMaster.ToolMode.Cook);
            //    ToolbarItems[GameMaster.ToolMode.Farm] = CreateIcon(5, GameMaster.ToolMode.Farm);
            //    ToolbarItems[GameMaster.ToolMode.Magic] = CreateIcon(6, GameMaster.ToolMode.Magic);
            //    ToolbarItems[GameMaster.ToolMode.Gather] = CreateIcon(6, GameMaster.ToolMode.Gather);
            //    ToolbarItems[GameMaster.ToolMode.Chop] = CreateIcon(1, GameMaster.ToolMode.Chop);
            //    ToolbarItems[GameMaster.ToolMode.Guard] = CreateIcon(4, GameMaster.ToolMode.Guard);
            //    ToolbarItems[GameMaster.ToolMode.Attack] = CreateIcon(3, GameMaster.ToolMode.Attack);

            var roomIcons = GuiRoot.GetTileSheet("rooms") as Gum.TileSheet;

            RoomLibrary.InitializeStatics();
            var Tilesheet = TextureManager.GetTexture(ContentPaths.Terrain.terrain_tiles);

            VoxelLibrary.InitializeDefaultLibrary(Game.GraphicsDevice, Tilesheet);


            var bottomRightTray = GuiRoot.RootItem.AddChild(new NewGui.ToolTray.Tray
            {
                IsRootTray = true,
                Corners    = Gum.Scale9Corners.Left | Gum.Scale9Corners.Top,
                AutoLayout = Gum.AutoLayout.FloatBottom,
                ItemSource = new Gum.Widget[]
                {
                    new NewGui.ToolTray.Icon
                    {
                        Icon             = new TileReference("tool-icons", 5),
                        KeepChildVisible = true,
                        ExpansionChild   = new NewGui.ToolTray.Tray
                        {
                            ItemSource = RoomLibrary.GetRoomTypes().Select(name => RoomLibrary.GetData(name))
                                         .Select(data => new NewGui.ToolTray.Icon
                            {
                                Icon           = data.NewIcon,
                                ExpansionChild = new NewGui.BuildRoomInfo
                                {
                                    Data = data,
                                    Rect = new Rectangle(0, 0, 256, 128)
                                },
                                OnClick = (sender, args) =>
                                {
                                    (sender as NewGui.FramedIcon).Enabled = false;
                                }
                            })
                        }
                    },
                    new NewGui.ToolTray.Icon
                    {
                        Icon             = new TileReference("tool-icons", 6),
                        KeepChildVisible = true,
                        ExpansionChild   = new NewGui.ToolTray.Tray
                        {
                            ItemSource = VoxelLibrary.GetTypes().Where(voxel => voxel.IsBuildable)
                                         .Select(data => new NewGui.ToolTray.Icon
                            {
                                Icon           = new TileReference("rooms", 0),
                                ExpansionChild = new NewGui.BuildWallInfo
                                {
                                    Data = data,
                                    Rect = new Rectangle(0, 0, 256, 128)
                                }
                            })
                        }
                    }
                }
            });

            bottomRightTray.Hidden = false;
            GuiRoot.RootItem.Layout();

            IsInitialized = true;

            base.OnEnter();
        }