コード例 #1
0
ファイル: NewOptionsState.cs プロジェクト: Solsund/dwarfcorp
 public NewOptionsState(DwarfGame Game, GameStateManager StateManager) :
     base(Game, "NewOptionsState", StateManager)
 {
 }
コード例 #2
0
ファイル: MainMenuState.cs プロジェクト: johan74/dwarfcorp
 public MainMenuState(DwarfGame game, GameStateManager stateManager) :
     base(game, "MainMenuState", stateManager)
 {
 }
コード例 #3
0
        public override void OnEnter()
        {
            if (SuppressEnter)
            {
                SuppressEnter = false;
                return;
            }

            DwarfGame.GumInputMapper.GetInputQueue();

            #region Setup GUI
            GuiRoot = new Gui.Root(DwarfGame.GuiSkin);
            GuiRoot.MousePointer = new MousePointer("mouse", 15.0f, 16, 17, 18, 19, 20, 21, 22, 23);

            MainPanel = GuiRoot.RootItem.AddChild(new Gui.Widget
            {
                Rect           = GuiRoot.RenderData.VirtualScreen,
                Border         = "border-fancy",
                Text           = Settings.Name,
                Font           = "font16",
                TextColor      = new Vector4(0, 0, 0, 1),
                Padding        = new Margin(4, 4, 4, 4),
                InteriorMargin = new Margin(24, 0, 0, 0)
            });

            var rightPanel = MainPanel.AddChild(new Widget
            {
                MinimumSize = new Point(256, 0),
                Padding     = new Margin(2, 2, 2, 2),
                AutoLayout  = AutoLayout.DockRight
            });

            rightPanel.AddChild(new Gui.Widget
            {
                Text               = "Back",
                Border             = "border-button",
                ChangeColorOnHover = true,
                TextColor          = new Vector4(0, 0, 0, 1),
                Font               = "font16",
                AutoLayout         = Gui.AutoLayout.DockTop,
                OnClick            = (sender, args) =>
                {
                    GameStateManager.ClearState();
                    GameStateManager.PushState(new MainMenuState(Game));
                }
            });

            rightPanel.AddChild(new Widget
            {
                Text               = "Factions",
                Border             = "border-button",
                ChangeColorOnHover = true,
                TextColor          = new Vector4(0, 0, 0, 1),
                Font               = "font16",
                AutoLayout         = AutoLayout.DockTop,
                OnClick            = (sender, args) =>
                {
                    SuppressEnter = true;
                    GameStateManager.PushState(new FactionViewState(GameState.Game, Settings));
                }
            });

            switch (PanelState)
            {
            case PanelStates.Generate:
                RightPanel = rightPanel.AddChild(new GenerationPanel(Game, Settings)
                {
                    RestartGeneration = () => RestartGeneration(),
                    GetGenerator      = () => Generator,
                    OnVerified        = () =>
                    {
                        SwitchToLaunchPanel();
                    },
                    AutoLayout = Gui.AutoLayout.DockFill,
                });
                break;

            case PanelStates.Launch:
                RightPanel = rightPanel.AddChild(new LaunchPanel(Game, Generator, Settings, this)
                {
                    AutoLayout = AutoLayout.DockFill,
                });

                break;
            }

            GenerationProgress = MainPanel.AddChild(new Gui.Widgets.ProgressBar
            {
                AutoLayout          = Gui.AutoLayout.DockBottom,
                TextHorizontalAlign = Gui.HorizontalAlign.Center,
                TextVerticalAlign   = Gui.VerticalAlign.Center,
                Font      = "font10",
                TextColor = new Vector4(1, 1, 1, 1)
            }) as Gui.Widgets.ProgressBar;

            PoliticsToggle = MainPanel.AddChild(new Gui.Widgets.CheckBox
            {
                Text     = "Show Political Boundaries",
                Hidden   = true,
                OnLayout = (sender) =>
                {
                    sender.Rect = GenerationProgress.Rect;
                },
                OnCheckStateChange = (sender) =>
                {
                    Preview.ShowPolitics = (sender as Gui.Widgets.CheckBox).CheckState;
                }
            }) as Gui.Widgets.CheckBox;

            Preview = MainPanel.AddChild(new WorldGeneratorPreview(Game.GraphicsDevice)
            {
                Border     = "border-thin",
                AutoLayout = Gui.AutoLayout.DockFill,
                Overworld  = Settings,
                Hidden     = true,
                OnLayout   = (sender) =>
                {
                    //sender.Rect = new Rectangle(sender.Rect.X, sender.Rect.Y, sender.Rect.Width, GenerationProgress.Rect.Bottom - sender.Rect.Y);
                },
                OnCellSelectionMade = () =>
                {
                    if (RightPanel is LaunchPanel launch)
                    {
                        launch.UpdateCellInfo();
                    }
                }
            }) as WorldGeneratorPreview;
コード例 #4
0
        public void Reset()
        {
            mainPanel.Clear();
            Rectangle rect = GuiRoot.RenderData.VirtualScreen;

            mainPanel.AddChild(new Gui.Widgets.Button
            {
                Text = "< Back",
                TextHorizontalAlign = HorizontalAlign.Center,
                TextVerticalAlign   = VerticalAlign.Center,
                Border  = "border-button",
                Font    = "font16",
                OnClick = (sender, args) =>
                {
                    GameStateManager.PopState();
                },
                AutoLayout = AutoLayout.FloatBottomLeft,
            });
            var interior = mainPanel.GetDrawableInterior();

            var widgetList = mainPanel.AddChild(new WidgetListView()
            {
                Font                  = "font10",
                AutoLayout            = AutoLayout.DockLeft,
                ItemHeight            = 32,
                MinimumSize           = new Point(interior.Width / 2, interior.Height - 128),
                MaximumSize           = new Point(interior.Width / 2, interior.Height - 128),
                ChangeColorOnHover    = true,
                ChangeColorOnSelected = true
            }) as WidgetListView;

            var detailsPanel = mainPanel.AddChild(new Widget()
            {
                AutoLayout  = AutoLayout.DockLeft,
                MinimumSize = new Point(interior.Width / 2, interior.Height - 128)
            });



            var icon = detailsPanel.AddChild(new TutorialIcon()
            {
                MinimumSize = new Point(256, 128),
                MaximumSize = new Point(256, 128),
                AutoLayout  = AutoLayout.DockTop
            }) as TutorialIcon;


            var title = detailsPanel.AddChild(new Widget()
            {
                Font              = "font16",
                AutoLayout        = AutoLayout.DockTop,
                MinimumSize       = new Point(256, 32),
                TextVerticalAlign = VerticalAlign.Center
            });

            var details = detailsPanel.AddChild(new Widget()
            {
                Font        = "font10",
                AutoLayout  = AutoLayout.DockTop,
                MinimumSize = new Point(256, 256)
            });


            foreach (var tutorial in World.TutorialManager.EnumerateTutorials())
            {
                widgetList.AddItem(new Widget()
                {
                    Background = new TileReference("basic", 0),
                    Text       = tutorial.Value.Title,
                    OnClick    = (sender, args) =>
                    {
                        details.Text     = tutorial.Value.Text;
                        title.Text       = tutorial.Value.Title;
                        var asset        = "newgui\\tutorials\\" + tutorial.Key;
                        icon.ImageSource = AssetManager.DoesTextureExist(asset) ? asset : null;

                        if (icon.ImageSource == null && tutorial.Value.Icon != null)
                        {
                            icon.Background  = null;// tutorial.Value.Icon;
                            icon.MinimumSize = new Point(128, 128);
                            icon.MaximumSize = new Point(128, 128);
                        }
                        else
                        {
                            icon.MinimumSize = new Point(256, 128);
                            icon.MaximumSize = new Point(256, 128);
                            icon.Background  = null;
                        }

                        icon.Invalidate();
                        icon.Parent.Layout();
                    },
                    TextVerticalAlign = VerticalAlign.Center,
                });
            }

            mainPanel.Layout();
        }
コード例 #5
0
 public PaginatedChooserState(DwarfGame Game, GameStateManager StateManager) :
     base(Game, "GuiStateTemplate", StateManager)
 {
 }
コード例 #6
0
 public GuiDebugState(DwarfGame game, GameStateManager stateManager) :
     base(game, "GuiDebugState", stateManager)
 {
 }
コード例 #7
0
ファイル: LaunchPanel.cs プロジェクト: sodomon2/dwarfcorp
        public override void Construct()
        {
            Padding = new Margin(2, 2, 0, 0);

            StartButton = AddChild(new Gui.Widget
            {
                Text               = "Start Game",
                Border             = "border-button",
                ChangeColorOnHover = true,
                TextColor          = new Vector4(0, 0, 0, 1),
                Font               = "font16",
                AutoLayout         = Gui.AutoLayout.DockBottom,
                OnClick            = (sender, args) =>
                {
                    var saveName = DwarfGame.GetWorldDirectory() + Path.DirectorySeparatorChar + Settings.Name + Path.DirectorySeparatorChar + String.Format("{0}-{1}", (int)Settings.InstanceSettings.Origin.X, (int)Settings.InstanceSettings.Origin.Y);
                    var saveGame = SaveGame.LoadMetaFromDirectory(saveName);
                    if (saveGame != null)
                    {
                        DwarfGame.LogSentryBreadcrumb("WorldGenerator", "User is loading a saved game.");
                        Settings.InstanceSettings.LoadType = LoadType.LoadFromFile;

                        GameStateManager.ClearState();
                        GameStateManager.PushState(new LoadState(Game, Settings, LoadTypes.UseExistingOverworld));
                    }
                    else
                    {
                        DwarfGame.LogSentryBreadcrumb("WorldGenerator", string.Format("User is starting a game with a {0} x {1} world.", Settings.Width, Settings.Height));
                        Settings.InstanceSettings.LoadType = LoadType.CreateNew;

                        var message = "";
                        var valid   = InstanceSettings.ValidateEmbarkment(Settings, out message);
                        if (valid == InstanceSettings.ValidationResult.Pass)
                        {
                            LaunchNewGame();
                        }
                        else if (valid == InstanceSettings.ValidationResult.Query)
                        {
                            var popup = new Gui.Widgets.Confirm()
                            {
                                Text    = message,
                                OnClose = (_sender) =>
                                {
                                    if ((_sender as Gui.Widgets.Confirm).DialogResult == Gui.Widgets.Confirm.Result.OKAY)
                                    {
                                        LaunchNewGame();
                                    }
                                }
                            };
                            Root.ShowModalPopup(popup);
                        }
                        else if (valid == InstanceSettings.ValidationResult.Reject)
                        {
                            var popup = new Gui.Widgets.Confirm()
                            {
                                Text       = message,
                                CancelText = ""
                            };
                            Root.ShowModalPopup(popup);
                        }
                    }
                }
            });

            CellInfo = AddChild(new Widget
            {
                AutoLayout = AutoLayout.DockFill,
                TextColor  = new Vector4(0, 0, 0, 1),
                Font       = "font10"
            });

            ZoomedPreview = AddChild(new Gui.Widget
            {
                AutoLayout = Gui.AutoLayout.DockBottom,
                OnLayout   = (sender) =>
                {
                    sender.Rect.Height = StartButton.Rect.Width;
                    sender.Rect.Width  = StartButton.Rect.Width;
                    sender.Rect.Y      = StartButton.Rect.Top - StartButton.Rect.Width - 2;
                    sender.Rect.X      = StartButton.Rect.X;
                }
            });

            UpdateCellInfo();
            this.Layout();

            base.Construct();
        }
コード例 #8
0
        public void Reset()
        {
            mainPanel.Clear();
            Rectangle rect = GuiRoot.RenderData.VirtualScreen;

            mainPanel.AddChild(new Gui.Widgets.Button
            {
                Text = "< Back",
                TextHorizontalAlign = HorizontalAlign.Center,
                TextVerticalAlign   = VerticalAlign.Center,
                Border  = "border-button",
                Font    = "font16",
                OnClick = (sender, args) =>
                {
                    GameStateManager.PopState();
                },
                AutoLayout = AutoLayout.FloatBottomLeft,
            });


            var widgetList = mainPanel.AddChild(new WidgetListView()
            {
                AutoLayout = AutoLayout.DockTop,
                SelectedItemForegroundColor = Color.Black.ToVector4(),
                SelectedItemBackgroundColor = new Vector4(0, 0, 0, 0),
                ItemBackgroundColor2        = new Vector4(0, 0, 0, 0.1f),
                ItemBackgroundColor1        = new Vector4(0, 0, 0, 0),
                ItemHeight  = 64,
                MinimumSize = new Point(0, 3 * GuiRoot.RenderData.VirtualScreen.Height / 4)
            }) as WidgetListView;

            var factions = Overworld.Natives.Where(f => f.InteractiveFaction && Library.GetRace(f.Race).HasValue(out var race) && race.IsIntelligent);

            foreach (var faction in factions)
            {
                var diplomacy = Overworld.GetPolitics(faction, Overworld.Natives.FirstOrDefault(n => n.Name == "Player"));
                var details   = diplomacy.GetEvents().Select(e => string.Format("{0} ({1})", TextGenerator.ToSentenceCase(e.Description), e.Change > 0 ? "+" + e.Change.ToString() : e.Change.ToString()));

                var entry = widgetList.AddItem(new Widget()
                {
                    Background = new TileReference("basic", 0),
                });
                StringBuilder sb = new StringBuilder();
                foreach (var detail in details)
                {
                    sb.AppendLine(detail);
                }
                entry.Tooltip = "Recent events:\n" + sb.ToString();
                if (sb.ToString() == "")
                {
                    entry.Tooltip = "No recent events.";
                }
                var titlebar = entry.AddChild(new Widget()
                {
                    InteriorMargin = new Margin(5, 5, 5, 5),
                    MinimumSize    = new Point(512, 36),
                    AutoLayout     = AutoLayout.DockTop,
                });
                titlebar.AddChild(new Widget()
                {
                    Background  = new TileReference("map-icons", Library.GetRace(faction.Race).HasValue(out var race) ? race.Icon : 0),
                    MaximumSize = new Point(32, 32),
                    MinimumSize = new Point(32, 32),
                    AutoLayout  = AutoLayout.DockLeft,
                });
コード例 #9
0
 public TutorialViewState(DwarfGame game, GameStateManager stateManager, WorldManager world) :
     base(game, "TutorialViewState", stateManager)
 {
     World = world;
 }
コード例 #10
0
ファイル: IntroState.cs プロジェクト: svifylabs/dwarfcorp
 public IntroState(DwarfGame game, GameStateManager stateManager) :
     base(game, "IntroState", stateManager)
 {
     ResourceLibrary library = new ResourceLibrary();
 }
コード例 #11
0
 public NewGameCreateDebugWorldState(DwarfGame game, GameStateManager stateManager) :
     base(game, "MainMenuState", stateManager)
 {
 }
コード例 #12
0
 public GuiStateTemplate(DwarfGame Game, GameStateManager StateManager) :
     base(Game, "GuiStateTemplate", StateManager)
 {
 }
コード例 #13
0
        public override void Update(DwarfTime gameTime)
        {
            if (DoneLoading)
            {
                // Todo: Decouple gui/input from world.
                // Copy important bits to PlayState - This is a hack; decouple world from gui and input instead.
                PlayState.Input = Input;
                GameStateManager.PopState(false);
                GameStateManager.PushState(new PlayState(Game, World));

                World.OnSetLoadingMessage = null;
            }
            else
            {
                if (LoadType == LoadTypes.GenerateOverworld)
                {
                    if (Generator.CurrentState == OverworldGenerator.GenerationState.Finished && World == null)
                    {
                        CreateWorld();
                    }
                    else
                    {
                        if (!LoadTicker.HasMesssage(Generator.LoadingMessage))
                        {
                            LoadTicker.AddMessage(Generator.LoadingMessage);
                        }
                    }
                }

                foreach (var item in DwarfGame.GumInputMapper.GetInputQueue())
                {
                    GuiRoot.HandleInput(item.Message, item.Args);
                    if (item.Message == Gui.InputEvents.KeyPress)
                    {
                        Runner.Jump();
                    }
                }

                GuiRoot.Update(gameTime.ToRealTime());
                Runner.Update(gameTime);

                if (World != null && World.LoadStatus == WorldManager.LoadingStatus.Failure && !DisplayException)
                {
                    DisplayException = true;
                    string exceptionText = World.LoadingException == null
                        ? "Unknown exception."
                        : World.LoadingException.ToString();
                    GuiRoot.MouseVisible        = true;
                    GuiRoot.MousePointer        = new Gui.MousePointer("mouse", 4, 0);
                    DwarfTime.LastTime.IsPaused = false;
                    DwarfTime.LastTime.Speed    = 1.0f;
                    World = null;
                    DwarfGame.LogSentryBreadcrumb("Loading", "Loading failed.", SharpRaven.Data.BreadcrumbLevel.Error);
                    GuiRoot.ShowModalPopup(new Gui.Widgets.Confirm()
                    {
                        CancelText = "",
                        Text       = "Oh no! Loading failed :( This crash has been automatically reported to the developers: " + exceptionText,
                        OnClick    = (s, a) =>
                        {
                            DwarfGame.LogSentryBreadcrumb("Loading", "Loading failed. Player going back to start.");
                            GameStateManager.ClearState();
                        },
                        OnClose = (s) =>
                        {
                            DwarfGame.LogSentryBreadcrumb("Loading", "Loading failed. Player going back to start.");
                            GameStateManager.ClearState();
                        },
                        Rect = GuiRoot.RenderData.VirtualScreen
                    });
                }
            }

            base.Update(gameTime);
        }
コード例 #14
0
        // Does not actually set these.
        //public static NamedImageFrame CompanyLogo { get; set; }
        //public static Color CompanyColor { get; set; }

        public CompanyMakerState(DwarfGame game, GameStateManager stateManager) :
            base(game, "CompanyMakerState", stateManager)
        {
            CompanyInformation = new CompanyInformation();
        }
コード例 #15
0
        public LoadSaveGameState(DwarfGame Game, GameStateManager StateManager) :
            base(Game, StateManager)
        {
            this.ProceedButtonText = "Load";
            this.NoItemsText       = "No saves found.";

            this.ItemSource = () =>
            {
                System.IO.DirectoryInfo savedirectory = System.IO.Directory.CreateDirectory(DwarfGame.GetSaveDirectory());
                var dirs = savedirectory.EnumerateDirectories().ToList();
                dirs.Sort((a, b) => b.LastWriteTime.CompareTo(a.LastWriteTime));
                return(dirs.ToList());
            };

            this.ScreenshotSource = (path) =>
            {
                var screenshots = System.IO.Directory.GetFiles(path, "*.png");
                if (screenshots.Length == 0)
                {
                    return(null);
                }
                else
                {
                    return(AssetManager.LoadUnbuiltTextureFromAbsolutePath(screenshots[0]));
                }
            };

            this.OnProceedClicked = (path) =>
            {
                StateManager.ClearState();
                StateManager.PushState(new LoadState(Game, Game.StateManager,
                                                     new WorldGenerationSettings
                {
                    ExistingFile = path,
                    Name         = path
                }));
            };

            this.ValidateItem = (path) =>
            {
                try
                {
                    var saveGame = SaveGame.CreateFromDirectory(path);
                    if (!Program.CompatibleVersions.Contains(saveGame.Metadata.Version))
                    {
                        return(String.Format("Incompatible version {0}", saveGame.Metadata.Version));
                    }
                    var overworld = saveGame.Metadata.OverworldFile;
                    if (!System.IO.Directory.Exists(DwarfGame.GetWorldDirectory() + Program.DirChar + overworld))
                    {
                        return(String.Format("Overworld \"{0}\" does not exist.", overworld));
                    }
                    return("");
                }
                catch (Exception e)
                {
                    return(String.Format("Error while loading {0}", e.Message));
                }
            };

            this.GetItemName = (path) =>
            {
                try
                {
                    var saveGame = SaveGame.CreateFromDirectory(path);
                    return(saveGame.Metadata.OverworldFile);
                }
                catch (Exception)
                {
                    return("?");
                }
            };

            this.InvalidItemText = "This save was created with a different version of DwarfCorp and cannot be loaded.";
        }
コード例 #16
0
ファイル: IntroState.cs プロジェクト: johan74/dwarfcorp
 public IntroState(DwarfGame game, GameStateManager stateManager) :
     base(game, "IntroState", stateManager)
 {
 }
コード例 #17
0
ファイル: NewEconomyState.cs プロジェクト: johan74/dwarfcorp
 public NewEconomyState(DwarfGame Game, GameStateManager StateManager, WorldManager World) :
     base(Game, "GuiStateTemplate", StateManager)
 {
     this.World = World;
 }