Ejemplo n.º 1
0
        public void FireActions(Gui.Root Gui, Action <Gui.InputEvents, Gui.InputEventArgs> externalHandler)
        {
            if (!GameState.Game.IsActive)
            {
                return;
            }

            var queue = Mapper.GetInputQueue();

            foreach (var @event in queue)
            {
                if (Gui != null)
                {
                    Gui.HandleInput(@event.Message, @event.Args);
                }

                if ([email protected])
                {
                    if (externalHandler != null)
                    {
                        externalHandler(@event.Message, @event.Args);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public override void OnEnter()
        {
            DwarfGame.GumInputMapper.GetInputQueue();

            GuiRoot = new Gui.Root(DwarfGame.GuiSkin);
            GuiRoot.MousePointer = new Gui.MousePointer("mouse", 4, 0);

            var panel = GuiRoot.RootItem.AddChild(new Widget
            {
                AutoLayout = AutoLayout.DockFill,
            });

            panel.AddChild(new Widget
            {
                Text                = "Exit",
                Border              = "border-button",
                AutoLayout          = AutoLayout.FloatBottomRight,
                OnClick             = (sender, args) => GameStateManager.PopState(),
                TextSize            = 2,
                TextHorizontalAlign = HorizontalAlign.Center,
                TextVerticalAlign   = VerticalAlign.Center
            });

            AtlasPanel = panel.AddChild(new GuiDebugPanel
            {
                AutoLayout  = AutoLayout.FloatCenter,
                MinimumSize = new Point((int)(GuiRoot.RenderData.VirtualScreen.Width * 0.9f), (int)(GuiRoot.RenderData.VirtualScreen.Height * 0.9f)),
            });

            GuiRoot.RootItem.Layout();

            IsInitialized = true;

            base.OnEnter();
        }
Ejemplo n.º 3
0
 public WaitState(DwarfGame game, string name, GameStateManager stateManager, WaitThreadRoutine routine)
     : base(game, name, stateManager)
 {
     WaitThread = new Thread(() =>
     {
         System.Threading.Thread.CurrentThread.CurrentCulture   = CultureInfo.InvariantCulture;
         System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
         runRoutine(routine);
     })
     {
         IsBackground = true
     };
     OnFinished = (Boolean, Exception) => { };
     Done       = false;
     GuiRoot    = new Gui.Root(DwarfGame.GuiSkin)
     {
         MousePointer = new MousePointer("mouse", 15.0f, 16, 17, 18, 19, 20, 21, 22, 23)
     };
     GuiRoot.RootItem.AddChild(new Widget()
     {
         Text                = name,
         Font                = "font18-outline",
         AutoLayout          = AutoLayout.DockFill,
         TextColor           = Color.White.ToVector4(),
         TextHorizontalAlign = HorizontalAlign.Center,
         TextVerticalAlign   = VerticalAlign.Center,
         Rect                = GuiRoot.RenderData.VirtualScreen
     });
 }
Ejemplo n.º 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 Gui.Root(DwarfGame.GuiSkin);
            GuiRoot.MousePointer = new Gui.MousePointer("mouse", 4, 0);

            var mainPanel = GuiRoot.RootItem.AddChild(new Gui.Widget
            {
                Rect        = GuiRoot.RenderData.VirtualScreen,
                Padding     = new Margin(4, 4, 4, 4),
                Transparent = true
            });

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

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

            var employeePanel = TabPanel.AddTab("Employees", new Gui.Widgets.EmployeePanel
            {
                Font    = "font10",
                Border  = "border-thin",
                Padding = new Margin(4, 4, 0, 0),
                World   = World,
            });

            var financePanel = TabPanel.AddTab("Finance", new Gui.Widgets.FinancePanel
            {
                Border  = "border-thin",
                Padding = new Margin(4, 4, 0, 0),
                Faction = World.PlayerFaction,
                World   = World
            });

            TabPanel.SelectedTab = 0;

            GuiRoot.RootItem.Layout();

            IsInitialized = true;
            base.OnEnter();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Called when the PlayState is entered from the state manager.
        /// </summary>
        public override void OnEnter()
        {
            // Just toss out any pending input.
            DwarfGame.GumInputMapper.GetInputQueue();

            if (!IsInitialized)
            {
                EnterTime = DateTime.Now;
                DiscoverPlayerTools();

                VoxSelector.Selected  += (voxels, button) => CurrentTool.OnVoxelsSelected(voxels, button);
                VoxSelector.Dragged   += (voxels, button) => CurrentTool.OnVoxelsDragged(voxels, button);
                BodySelector.Selected += (bodies, button) =>
                {
                    CurrentTool.OnBodiesSelected(bodies, button);
                    if (CurrentToolMode == "SelectUnits")
                    {
                        SelectedObjects = bodies;
                    }
                };
                BodySelector.MouseOver += (bodies) => CurrentTool.OnMouseOver(bodies);

                // Ensure game is not paused.
                World.Paused             = false;
                DwarfTime.LastTime.Speed = 1.0f;

                // Setup new gui. Double rendering the mouse?
                Gui = new Gui.Root(DwarfGame.GuiSkin);
                Gui.MousePointer = new Gui.MousePointer("mouse", 4, 0);

                World.UserInterface = this;
                CreateGUIComponents();
                IsInitialized = true;

                SoundManager.PlayMusic("main_theme_day");
                World.Time.Dawn += time =>
                {
                    SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_daytime, 0.15f);
                    SoundManager.PlayMusic("main_theme_day");
                };

                World.Time.NewNight += time =>
                {
                    SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_nighttime, 0.15f);
                    SoundManager.PlayMusic("main_theme_night");
                };

                World.UnpauseThreads();
                AutoSaveTimer = new Timer(GameSettings.Current.AutoSaveTimeMinutes * 60.0f, false, Timer.TimerMode.Real);

                foreach (var contextCommandFactory in AssetManager.EnumerateModHooks(typeof(ContextCommandAttribute), typeof(ContextCommands.ContextCommand), new Type[] { }))
                {
                    ContextCommands.Add(contextCommandFactory.Invoke(null, new Object[] { }) as ContextCommands.ContextCommand);
                }

                World.LogEvent(String.Format("We have arrived at {0}", World.Overworld.Name));
            }

            base.OnEnter();
        }
Ejemplo n.º 6
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 Gui.Root(DwarfGame.GuiSkin);
            GuiRoot.MousePointer = new Gui.MousePointer("mouse", 4, 0);
            var rect = GuiRoot.RenderData.VirtualScreen;

            mainPanel = GuiRoot.RootItem.AddChild(new Gui.Widget
            {
                Rect           = rect,
                MinimumSize    = new Point(3 * GuiRoot.RenderData.VirtualScreen.Width / 4, 3 * GuiRoot.RenderData.VirtualScreen.Height / 4),
                AutoLayout     = AutoLayout.FloatCenter,
                Border         = "border-fancy",
                Padding        = new Margin(4, 4, 4, 4),
                InteriorMargin = new Margin(2, 0, 0, 0),
                TextSize       = 1,
                Font           = "font10"
            });
            Reset();

            IsInitialized = true;

            base.OnEnter();
        }
Ejemplo n.º 7
0
        public void Update(Gui.Root Gui)
        {
            if (!TutorialHidden && TutorialEnabled && !String.IsNullOrEmpty(PendingTutorial) && Gui != null && !Entries[PendingTutorial].Shown)
            {
                if (TutorialVisible && ExistingTutorial != null)
                {
                    ExistingTutorial.Close();
                    ExistingTutorial = null;
                }

                var entry = Entries[PendingTutorial];
                entry.Shown     = true;
                entry.Name      = PendingTutorial;
                TutorialVisible = true;

                var popup = Gui.ConstructWidget(new Gui.Widgets.TutorialPopup
                {
                    Message = entry,
                    OnClose = (sender) =>
                    {
                        TutorialEnabled = !(sender as Gui.Widgets.TutorialPopup).DisableChecked;
                        TutorialVisible = false;
                        Gui.ClearSpecials();
                        if (!String.IsNullOrEmpty(entry.NextTutorial))
                        {
                            ShowTutorial(entry.NextTutorial);
                        }
                    },
                    OnLayout = (sender) =>
                    {
                        sender.Rect.X = Gui.RenderData.VirtualScreen.Width - sender.Rect.Width;
                        sender.Rect.Y = 64;
                    }
                });

                if (entry.Popup)
                {
                    Gui.ShowMinorPopup(popup);
                    popup.PopupDestructionType = PopupDestructionType.Keep;
                }
                else
                {
                    Gui.RootItem.AddChild(popup);
                }
                ExistingTutorial = popup;
                PendingTutorial  = null;

                Gui.SpecialHiliteWidgetName = entry.GuiHilite;
            }

            if ((HighlightWidget != null) && HighlightWidget.IsAnyParentHidden() && TutorialVisible && (ExistingTutorial != null))
            {
                Gui.ClearSpecials();
                ExistingTutorial.Close();
            }
        }
Ejemplo n.º 8
0
        public void FireActions(Gui.Root Gui, Action <Gui.InputEvents, Gui.InputEventArgs> MouseHandler)
        {
            if (!GameState.Game.IsActive)
            {
                return;
            }

            var queue = Mapper.GetInputQueue();

            foreach (var @event in queue)
            {
                if (Gui != null)
                {
                    Gui.HandleInput(@event.Message, @event.Args);
                }

                if ([email protected])
                {
                    if (@event.Message == global::DwarfCorp.Gui.InputEvents.MouseClick ||
                        @event.Message == global::DwarfCorp.Gui.InputEvents.MouseMove ||
                        @event.Message == global::DwarfCorp.Gui.InputEvents.MouseDown ||
                        @event.Message == global::DwarfCorp.Gui.InputEvents.MouseUp ||
                        @event.Message == global::DwarfCorp.Gui.InputEvents.MouseWheel)
                    {
                        if (MouseHandler != null)
                        {
                            MouseHandler(@event.Message, @event.Args);
                        }
                    }
                    else if (@event.Message == global::DwarfCorp.Gui.InputEvents.KeyUp)
                    {
                        GumInputMapper.QueuedInput localevent = @event;
                        foreach (var binding in InputActions.Where((KeyValuePair <string, InputAction> ia) => ia.Value.Keys.Contains((Keys)localevent.Args.KeyValue) && ia.Value.Type == KeyBindingType.Pressed))
                        {
                            if (binding.Value.Handler != null)
                            {
                                binding.Value.Handler();
                            }
                        }
                    }
                }
            }

            // Check 'Held' actions
            var kbState = Keyboard.GetState();

            foreach (var binding in InputActions.Where(ia => ia.Value.Type == KeyBindingType.Held))
            {
                if (binding.Value.Keys.Count(k => kbState.IsKeyDown(k)) > 0 && binding.Value.Handler != null)
                {
                    binding.Value.Handler();
                }
            }
        }
Ejemplo n.º 9
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 Gui.Root(DwarfGame.GuiSkin);
            GuiRoot.MousePointer = new Gui.MousePointer("mouse", 4, 0);

            IsInitialized = true;

            base.OnEnter();
        }
Ejemplo n.º 10
0
        public override void OnEnter()
        {
            LogoTexture = AssetManager.GetContentTexture("newgui/gamelogo");

            // Clear the input queue... cause other states aren't using it and it's been filling up.
            DwarfGame.GumInputMapper.GetInputQueue();
            GuiRoot = new Gui.Root(DwarfGame.GuiSkin);
            GuiRoot.MousePointer = new Gui.MousePointer("mouse", 4, 0);
            MakeMenu();
            IsInitialized = true;

            base.OnEnter();
        }
Ejemplo n.º 11
0
        public override void OnEnter()
        {
            TutorialManager          = new Tutorial.TutorialManager();
            IsInitialized            = true;
            DwarfTime.LastTime.Speed = 1.0f;

            IndicatorManager.SetupStandards();

            DwarfGame.GumInputMapper.GetInputQueue();
            GuiRoot = new Gui.Root(DwarfGame.GuiSkin);

            Tip = GuiRoot.RootItem.AddChild(new Gui.Widget
            {
                Font                = "font10",
                TextColor           = new Vector4(1, 1, 1, 1),
                MinimumSize         = new Point(0, 64),
                TextHorizontalAlign = Gui.HorizontalAlign.Center,
                TextVerticalAlign   = Gui.VerticalAlign.Center,
                Text                = "Press any key to jump!",
                AutoLayout          = Gui.AutoLayout.DockBottom,
                Background          = new Gui.TileReference("basic", 0),
                BackgroundColor     = new Vector4(0, 0, 0, 0.5f),
                InteriorMargin      = new Gui.Margin(0, 0, 15, 15)
            });

            LoadTicker = GuiRoot.RootItem.AddChild(new Gui.Widgets.InfoTicker
            {
                Font       = "font8",
                AutoLayout = Gui.AutoLayout.DockFill,
                TextColor  = new Vector4(1, 1, 1, 1)
            }) as Gui.Widgets.InfoTicker;

            GuiRoot.RootItem.Layout();

            if (Settings.GenerateFromScratch)
            {
                Generator = new WorldGenerator(Settings)
                {
                    Seed = MathFunctions.Random.Next()
                };
                Generator.Generate();
            }
            else
            {
                CreateWorld();
            }

            base.OnEnter();
        }
Ejemplo n.º 12
0
        public override void OnEnter()
        {
            LogoTexture = Game.Content.Load <Texture2D>("newgui/gamelogo");

            // Clear the input queue... cause other states aren't using it and it's been filling up.
            DwarfGame.GumInputMapper.GetInputQueue();
            GuiRoot = new Gui.Root(DwarfGame.GumSkin);
            GuiRoot.MousePointer = new Gui.MousePointer("mouse", 4, 0);
            MakeDebugWorldMenu();

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

            base.OnEnter();
        }
Ejemplo n.º 13
0
        public override void OnEnter()
        {
            LogoTexture = Game.Content.Load <Texture2D>("newgui/gamelogo");
            // Clear the input queue... cause other states aren't using it and it's been filling up.
            DwarfGame.GumInputMapper.GetInputQueue();

            GuiRoot = new Gui.Root(DwarfGame.GumSkin);
            GuiRoot.MousePointer = new Gui.MousePointer("mouse", 4, 0);
            MakeMenu();
            IsInitialized = true;

            DwarfTime.LastTime.Speed = 1.0f;
            SoundManager.PlayMusic("menu_music");
            SoundManager.StopAmbience();
            base.OnEnter();
        }
Ejemplo n.º 14
0
        public static Widget CreateCombo <T>(Gui.Root Root, String Name, String Tooltip, T[] Values, Action <T> Setter, Func <T> Getter)
        {
            System.Diagnostics.Debug.Assert(Values.Length == LevelStrings.Length);

            var r = Root.ConstructWidget(new Widget
            {
                AutoLayout  = AutoLayout.DockTop,
                MinimumSize = new Point(0, 30),
                Tooltip     = Tooltip
            });

            r.AddChild(new Widget
            {
                AutoLayout  = AutoLayout.DockLeft,
                MinimumSize = new Point(64, 0),
                Text        = Name
            });

            var combo = r.AddChild(new Gui.Widgets.ComboBox
            {
                AutoLayout             = AutoLayout.DockFill,
                Items                  = new List <String>(LevelStrings),
                OnSelectedIndexChanged = (sender) =>
                {
                    var box = sender as ComboBox;
                    if (box.SelectedIndex >= 0 && box.SelectedIndex < Values.Length)
                    {
                        Setter(Values[box.SelectedIndex]);
                    }
                }
            }) as Gui.Widgets.ComboBox;

            var index = (new List <T>(Values)).IndexOf(Getter());

            if (index == -1)
            {
                combo.SelectedIndex = 2;
            }
            else
            {
                combo.SelectedIndex = index;
            }

            return(r);
        }
Ejemplo n.º 15
0
        public override void OnEnter()
        {
            DwarfGame.GumInputMapper.GetInputQueue();
            World.Tutorial("trade_screen");
            GuiRoot = new Gui.Root(DwarfGame.GuiSkin);
            GuiRoot.MousePointer  = new Gui.MousePointer("mouse", 4, 0);
            GuiRoot.RootItem.Font = "font8";

            TradePanel = GuiRoot.ConstructWidget(new Gui.Widgets.TradePanel
            {
                Rect   = GuiRoot.RenderData.VirtualScreen,
                Envoy  = new Trade.EnvoyTradeEntity(Envoy),
                Player = new Trade.PlayerTradeEntity(PlayerFaction),
            }) as Gui.Widgets.TradePanel;

            TradePanel.Layout();

            GuiRoot.ShowDialog(TradePanel);

            IsInitialized = true;
            base.OnEnter();
        }
Ejemplo n.º 16
0
        public void Update(Gui.Root Gui)
        {
            if (!TutorialEnabled || Gui == null)
            {
                return;
            }

            if (ExistingTutorial != null)
            {
                return;
            }

            if (PendingTutorials.Count > 0)
            {
                var nextTutorial = PendingTutorials.Dequeue();
                if (Entries.ContainsKey(nextTutorial))
                {
                    var entry = Entries[nextTutorial];
                    TutorialVisible  = true;
                    ExistingTutorial = CreateTutorialPopup(entry, Gui);
                }
            }
        }
Ejemplo n.º 17
0
        public void FireKeyboardActionsOnly(Gui.Root Gui)
        {
            if (!GameState.Game.IsActive)
            {
                return;
            }

            var queue = Mapper.GetInputQueue();

            foreach (var @event in queue)
            {
                if (@event.Message == InputEvents.KeyDown || @event.Message == InputEvents.KeyPress || @event.Message == InputEvents.KeyUp)
                {
                    Gui.HandleInput(@event.Message, @event.Args);
                }
                if ([email protected])
                {
                    Mapper.QueueLock.WaitOne();
                    Mapper.Queued.Add(@event);
                    Mapper.QueueLock.ReleaseMutex();
                }
            }
        }
Ejemplo n.º 18
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 Gui.Root(DwarfGame.GumSkin);
            GuiRoot.MousePointer  = new Gui.MousePointer("mouse", 4, 0);
            GuiRoot.RootItem.Font = "font8";

            int w = System.Math.Min(GuiRoot.RenderData.VirtualScreen.Width - 256, 550);
            int h = System.Math.Min(GuiRoot.RenderData.VirtualScreen.Height - 256, 300);
            int x = GuiRoot.RenderData.VirtualScreen.Width / 2 - w / 2;
            int y = System.Math.Max(GuiRoot.RenderData.VirtualScreen.Height / 2 - h / 2, 280);

            int bgx = x - 258;
            int bgy = y - 128;

            DialogueContext.SpeechBubble = GuiRoot.RootItem.AddChild(new Gui.Widget
            {
                Rect      = new Rectangle(bgx + 258, bgy, w + 50, 128),
                Border    = "speech-bubble-reverse",
                Font      = "font16",
                TextColor = Color.Black.ToVector4()
            });

            var bg = GuiRoot.RootItem.AddChild(new Widget()
            {
                Border = "border-dark",
                Rect   = new Rectangle(bgx, bgy, 258, 258)
            });


            DialogueContext.ChoicePanel = GuiRoot.RootItem.AddChild(new Gui.Widget
            {
                Rect       = new Rectangle(x, y, w, h),
                Border     = "border-fancy",
                AutoLayout = AutoLayout.DockFill
            });

            SpeakerAnimation                 = AnimationLibrary.CreateAnimation(DialogueContext.Envoy.OwnerFaction.Race.TalkAnimation);
            SpeakerAnimationPlayer           = new AnimationPlayer(SpeakerAnimation);
            DialogueContext.SpeakerAnimation = SpeakerAnimationPlayer;


            SpeakerWidget = bg.AddChild(new Widget()
            {
                Background  = new TileReference(SpeakerAnimation.SpriteSheet.AssetName, 0),
                AutoLayout  = AutoLayout.DockFill,
                MinimumSize = new Point(256, 256),
                Rect        = new Rectangle(bgx, bgy - 5, 256, 256)
            });

            DialogueContext.Politics = World.Diplomacy.GetPolitics(
                DialogueContext.PlayerFaction, DialogueContext.Envoy.OwnerFaction);
            DialogueContext.World = World;

            if (!DialogueContext.Politics.HasMet)
            {
                DialogueContext.Politics.HasMet = true;

                DialogueContext.Politics.RecentEvents.Add(new Diplomacy.PoliticalEvent()
                {
                    Change      = 0.0f,
                    Description = "we just met",
                    Duration    = new TimeSpan(1, 0, 0, 0),
                    Time        = World.Time.CurrentDate
                });
            }

            DialogueContext.EnvoyName = TextGenerator.GenerateRandom(Datastructures.SelectRandom(DialogueContext.Envoy.OwnerFaction.Race.NameTemplates).ToArray());

            DialogueContext.Transition(DialogueTree.ConversationRoot);

            IsInitialized = true;
            base.OnEnter();
        }
Ejemplo n.º 19
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 Gui.Root(DwarfGame.GuiSkin);
            GuiRoot.MousePointer = new Gui.MousePointer("mouse", 4, 0);
            MakeMenu();

            Progress = GuiRoot.RootItem.AddChild(new Gui.Widgets.ProgressBar
            {
                Rect = new Rectangle(0, 0, GuiRoot.RenderData.VirtualScreen.Width, 32)
            }) as Gui.Widgets.ProgressBar;

            Dictionary <GameMaster.ToolMode, Gui.Widget> ToolbarItems = new Dictionary <GameMaster.ToolMode, Gui.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 Tilesheet = AssetManager.GetContentTexture(ContentPaths.Terrain.terrain_tiles);

            VoxelLibrary.InitializeDefaultLibrary(Game.GraphicsDevice);

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

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

            IsInitialized = true;

            base.OnEnter();
        }
Ejemplo n.º 20
0
        public override void OnEnter()
        {
            if (ItemSource != null)
            {
                foreach (var path in ItemSource())
                {
                    Items.Add(new ChooserItem {
                        Path = path, Valid = ValidateItem == null ? true : ValidateItem(path)
                    });
                }
            }

            // Clear the input queue... cause other states aren't using it and it's been filling up.
            DwarfGame.GumInputMapper.GetInputQueue();

            GuiRoot = new Gui.Root(DwarfGame.GumSkin);
            GuiRoot.MousePointer            = new Gui.MousePointer("mouse", 4, 0);
            GuiRoot.RootItem.Transparent    = false;
            GuiRoot.RootItem.Background     = new Gui.TileReference("basic", 0);
            GuiRoot.RootItem.InteriorMargin = new Gui.Margin(16, 16, 16, 16);

            // CONSTRUCT GUI HERE...
            BottomBar = GuiRoot.RootItem.AddChild(new Gui.Widget
            {
                AutoLayout          = Gui.AutoLayout.DockBottom,
                MinimumSize         = new Point(0, 60),
                TextHorizontalAlign = Gui.HorizontalAlign.Center,
                Font = "font10"
            });

            if (Items.Count == 0)
            {
                BottomBar.Text = NoItemsText;
            }

            LoadButton = BottomBar.AddChild(new Gui.Widgets.Button
            {
                AutoLayout = Gui.AutoLayout.FloatBottomRight,
                Border     = "border-button",
                Text       = ProceedButtonText,
                OnClick    = (sender, args) =>
                {
                    var selectedItem = Items[PreviewOffset + ItemSelected];
                    if (selectedItem.Valid && OnProceedClicked != null)
                    {
                        OnProceedClicked(selectedItem.Path);
                    }
                }
            });

            NextButton = BottomBar.AddChild(new Gui.Widgets.Button
            {
                AutoLayout = Gui.AutoLayout.FloatTopRight,
                Border     = "border-button",
                Text       = "Next >",
                OnClick    = (sender, args) =>
                {
                    if (PreviewOffset + Grid.ItemsThatFit < Items.Count)
                    {
                        NeedsRefresh   = true;
                        PreviewOffset += Grid.ItemsThatFit;
                    }
                }
            });

            PrevButton = BottomBar.AddChild(new Gui.Widgets.Button
            {
                AutoLayout = Gui.AutoLayout.FloatTopLeft,
                Border     = "border-button",
                Text       = "< Prev",
                OnClick    = (sender, args) =>
                {
                    if (PreviewOffset > 0)
                    {
                        NeedsRefresh   = true;
                        PreviewOffset -= Grid.ItemsThatFit;
                    }
                }
            });

            DeleteButton = BottomBar.AddChild(new Gui.Widgets.Button
            {
                AutoLayout = AutoLayout.FloatBottom,
                Border     = "border-button",
                Text       = "Delete",
                OnClick    = (sender, args) =>
                {
                    var confirm = GuiRoot.ConstructWidget(new Gui.Widgets.Confirm
                    {
                        OkayText   = "Delete",
                        CancelText = "Keep",
                        Text       = "Are you sure you want to delete this?",
                        OnClose    = (s) =>
                        {
                            if ((s as Gui.Widgets.Confirm).DialogResult == Gui.Widgets.Confirm.Result.OKAY)
                            {
                                var selectedItem = Items[PreviewOffset + ItemSelected];
                                Items.Remove(selectedItem);
                                try
                                {
                                    System.IO.Directory.Delete(selectedItem.Path, true);
                                }
                                catch (Exception e)
                                {
                                    GuiRoot.ShowModalPopup(new Gui.Widgets.Confirm()
                                    {
                                        OkayText   = "Ok",
                                        CancelText = "",
                                        Text       = e.Message
                                    });
                                }
                                NeedsRefresh = true;
                            }
                        }
                    });
                    GuiRoot.ShowModalPopup(confirm);
                }
            });

            BottomBar.AddChild(new Gui.Widgets.Button
            {
                AutoLayout = Gui.AutoLayout.FloatBottomLeft,
                Border     = "border-button",
                Text       = "< Back",
                OnClick    = (sender, args) =>
                {
                    StateManager.PopState();
                }
            });

            Grid = GuiRoot.RootItem.AddChild(new Gui.Widgets.GridPanel
            {
                ItemSize            = new Point(128, 128),
                ItemSpacing         = new Point(8, 8),
                AutoLayout          = Gui.AutoLayout.DockFill,
                Border              = "border-one",
                Font                = "font10",
                InteriorMargin      = new Gui.Margin(32, 0, 0, 0),
                TextHorizontalAlign = HorizontalAlign.Center,
                TextVerticalAlign   = VerticalAlign.Top
            }) as Gui.Widgets.GridPanel;

            GuiRoot.RootItem.Layout();

            var gridSpaces = Grid.ItemsThatFit;

            for (var i = 0; i < gridSpaces; ++i)
            {
                var lambda_index = i;
                Grid.AddChild(new Gui.Widget
                {
                    Border = "border-one",
                    Text   = "No Image",
                    TextHorizontalAlign = HorizontalAlign.Center,
                    TextVerticalAlign   = VerticalAlign.Center,
                    OnClick             = (sender, args) =>
                    {
                        ItemSelected = lambda_index;
                        NeedsRefresh = true;
                    }
                });
            }

            GuiRoot.RootItem.Layout();

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

            base.OnEnter();
        }
Ejemplo n.º 21
0
        public override void OnEnter()
        {
            DwarfGame.GumInputMapper.GetInputQueue();

            GuiRoot = new Gui.Root(DwarfGame.GuiSkin);
            GuiRoot.MousePointer = new Gui.MousePointer("mouse", 4, 0);

            var       screen    = GuiRoot.RenderData.VirtualScreen;
            float     scale     = 0.9f;
            float     newWidth  = System.Math.Min(System.Math.Max(screen.Width * scale, 640), screen.Width * scale);
            float     newHeight = System.Math.Min(System.Math.Max(screen.Height * scale, 480), screen.Height * scale);
            Rectangle rect      = new Rectangle((int)(screen.Width / 2 - newWidth / 2), (int)(screen.Height / 2 - newHeight / 2), (int)newWidth, (int)newHeight);

            var main = GuiRoot.RootItem.AddChild(new Gui.Widget
            {
                Rect = rect
            });

            var bottom = main.AddChild(new Widget
            {
                Transparent = true,
                MinimumSize = new Point(0, 32),
                AutoLayout  = AutoLayout.DockBottom,
                Padding     = new Margin(2, 2, 2, 2)
            });

            bottom.AddChild(new Gui.Widgets.Button
            {
                Text = "Close",
                Font = "font16",
                TextHorizontalAlign = HorizontalAlign.Center,
                TextVerticalAlign   = VerticalAlign.Center,
                Border  = "border-button",
                OnClick = (sender, args) =>
                {
                    // If changes, prompt before closing.
                    if (HasChanges)
                    {
                        var confirm = new Popup
                        {
                            Text     = "Dwarf Corp must be restarted for changes to take effect.",
                            OkayText = "Okay",
                            OnClose  = (s2) => StateManager.PopState()
                        };
                        GuiRoot.ShowModalPopup(confirm);
                    }
                    else
                    {
                        StateManager.PopState();
                    }
                },
                AutoLayout = AutoLayout.DockRight
            });

            var tabs = main.AddChild(new Gui.Widgets.TabPanel
            {
                AutoLayout       = AutoLayout.DockFill,
                TextSize         = 1,
                SelectedTabColor = new Vector4(1, 0, 0, 1)
            }) as Gui.Widgets.TabPanel;

            tabs.AddTab("Installed", new InstalledModsWidget
            {
                OwnerState = this
            });

            tabs.AddTab("Search", new SearchWidget
            {
                Owner = this
            });

            GuiRoot.RootItem.Layout();

            IsInitialized = true;

            base.OnEnter();
        }
Ejemplo n.º 22
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.PopState();
                }
            });

            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;
Ejemplo n.º 23
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 Gui.Root(DwarfGame.GuiSkin);
            GuiRoot.MousePointer = new Gui.MousePointer("mouse", 4, 0);

            Rectangle rect = GuiRoot.RenderData.VirtualScreen;

            rect.Inflate(-rect.Width / 3, -rect.Height / 3);
            var mainPanel = GuiRoot.RootItem.AddChild(new Gui.Widget
            {
                Rect           = rect,
                MinimumSize    = new Point(512, 256),
                AutoLayout     = AutoLayout.FloatCenter,
                Border         = "border-fancy",
                Padding        = new Margin(4, 4, 4, 4),
                InteriorMargin = new Margin(2, 0, 0, 0),
                TextSize       = 1,
                Font           = "font10"
            });

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

            #region Name

            mainPanel.AddChild(new Widget()
            {
                Text       = "Create a Company",
                Font       = "font16",
                AutoLayout = AutoLayout.DockTop,
            });

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

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

            nameRow.AddChild(new Gui.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());
                }
            });

            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 Button
            {
                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 Gui.Widgets.CompanyLogo
            {
                AutoLayout         = AutoLayout.DockLeft,
                MinimumSize        = new Point(64, 64),
                MaximumSize        = new Point(64, 64),
                CompanyInformation = CompanyInformation
            }) as Gui.Widgets.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 Gui.TileSheet;
                    var chooser = new Gui.Widgets.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 Gui.Widgets.GridChooser;
                            if (gc.DialogResult == Gui.Widgets.GridChooser.Result.OKAY &&
                                gc.SelectedItem != null)
                            {
                                sender.Background = gc.SelectedItem.Background;
                                sender.Invalidate();
                                CompanyInformation.LogoBackground = gc.SelectedItem.Background;
                                CompanyLogoDisplay.Invalidate();
                            }
                        },
                        PopupDestructionType = PopupDestructionType.DestroyOnOffClick
                    };
                    GuiRoot.ShowModalPopup(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 Gui.Widgets.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 Gui.Widgets.GridChooser;
                            if (gc.DialogResult == Gui.Widgets.GridChooser.Result.OKAY &&
                                gc.SelectedItem != null)
                            {
                                sender.BackgroundColor = gc.SelectedItem.BackgroundColor;
                                sender.Invalidate();
                                CompanyInformation.LogoBackgroundColor = gc.SelectedItem.BackgroundColor;
                                CompanyLogoDisplay.Invalidate();
                            }
                        },
                        PopupDestructionType = PopupDestructionType.DestroyOnOffClick
                    };
                    GuiRoot.ShowModalPopup(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 Gui.TileSheet;
                    var chooser = new Gui.Widgets.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 Gui.Widgets.GridChooser;
                            if (gc.DialogResult == Gui.Widgets.GridChooser.Result.OKAY &&
                                gc.SelectedItem != null)
                            {
                                sender.Background = gc.SelectedItem.Background;
                                sender.Invalidate();
                                CompanyInformation.LogoSymbol = gc.SelectedItem.Background;
                                CompanyLogoDisplay.Invalidate();
                            }
                        },
                        PopupDestructionType = PopupDestructionType.DestroyOnOffClick
                    };
                    GuiRoot.ShowModalPopup(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 Gui.Widgets.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 Gui.Widgets.GridChooser;
                            if (gc.DialogResult == Gui.Widgets.GridChooser.Result.OKAY &&
                                gc.SelectedItem != null)
                            {
                                sender.BackgroundColor = gc.SelectedItem.BackgroundColor;
                                sender.Invalidate();
                                CompanyInformation.LogoSymbolColor = gc.SelectedItem.BackgroundColor;
                                CompanyLogoDisplay.Invalidate();
                            }
                        },
                        PopupDestructionType = PopupDestructionType.DestroyOnOffClick
                    };
                    GuiRoot.ShowModalPopup(chooser);
                }
            });


            #endregion

            GuiRoot.RootItem.Layout();

            IsInitialized = true;

            base.OnEnter();
        }
Ejemplo n.º 24
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 Gui.Root(DwarfGame.GumSkin);
            GuiRoot.MousePointer = new Gui.MousePointer("mouse", 4, 0);

            var mainPanel = GuiRoot.RootItem.AddChild(new Gui.Widget
            {
                Rect        = GuiRoot.RenderData.VirtualScreen,
                Padding     = new Margin(4, 4, 4, 4),
                Transparent = true
            });

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

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

            var employeePanel = TabPanel.AddTab("Employees", new Gui.Widgets.EmployeePanel
            {
                Border  = "border-thin",
                Padding = new Margin(4, 4, 0, 0),
                Faction = World.PlayerFaction,
            });

            //var financePanel = tabPanel.AddTab("Finance", new Gui.Widgets.FinancePanel
            //{
            //    Border = "border-thin",
            //    Padding = new Margin(4, 4, 0, 0),
            //    Economy = World.PlayerEconomy
            //});

            TabPanel.AddTab("Available Goals", new Gui.Widgets.GoalPanel
            {
                GoalSource = World.GoalManager.EnumerateGoals().Where(g =>
                                                                      g.State == Goals.GoalState.Available),
                World   = World,
                OnShown = (sender) => World.GoalManager.ResetNewAvailableGoals()
            });

            TabPanel.AddTab("Active Goals", new Gui.Widgets.GoalPanel
            {
                GoalSource = World.GoalManager.EnumerateGoals().Where(g =>
                                                                      g.State == Goals.GoalState.Active && g.GoalType != Goals.GoalTypes.Achievement)
            });

            TabPanel.AddTab("Completed Goals", new Gui.Widgets.GoalPanel
            {
                GoalSource = World.GoalManager.EnumerateGoals().Where(g =>
                                                                      g.State == Goals.GoalState.Complete),
                OnShown = (sender) => World.GoalManager.ResetNewCompletedGoals()
            });

            TabPanel.GetTabButton(1).DrawIndicator = true;
            TabPanel.GetTabButton(3).DrawIndicator = true;

            TabPanel.SelectedTab = 0;

            GuiRoot.RootItem.Layout();

            IsInitialized = true;
            base.OnEnter();
        }
Ejemplo n.º 25
0
 public void Render(Rectangle Where, Gui.Root Gui)
 {
     Gui.DrawQuad(Where, RenderTarget);
 }
Ejemplo n.º 26
0
        public override void OnEnter()
        {
            if (ItemSource != null)
            {
                foreach (var path in ItemSource())
                {
                    var meta = path.GetFiles("meta.txt");

                    Items.Add(new ChooserItem
                    {
                        Name  = GetItemName(path.FullName),
                        Path  = path.FullName,
                        Valid = ValidateItem == null ? "" : ValidateItem(path.FullName),
                        Age   = meta.Length > 0 ? DateTime.Now - meta[0].LastWriteTime : DateTime.Now - path.LastWriteTime
                    });
                }
            }

            foreach (var item in Items)
            {
                item.Screenshot = ScreenshotSource(item.Path);
            }

            DwarfGame.GumInputMapper.GetInputQueue();

            GuiRoot = new Gui.Root(DwarfGame.GuiSkin);
            GuiRoot.MousePointer            = new Gui.MousePointer("mouse", 4, 0);
            GuiRoot.RootItem.Transparent    = false;
            GuiRoot.RootItem.InteriorMargin = new Gui.Margin(16, 16, 32, 32);

            BottomBar = GuiRoot.RootItem.AddChild(new Gui.Widget
            {
                AutoLayout          = Gui.AutoLayout.DockBottom,
                MinimumSize         = new Point(0, 60),
                TextHorizontalAlign = Gui.HorizontalAlign.Center,
                TextVerticalAlign   = Gui.VerticalAlign.Center,
                Background          = new Gui.TileReference("basic", 0),
                Font           = "font10",
                InteriorMargin = new Gui.Margin(10, 10, 10, 10)
            });

            if (Items.Count == 0)
            {
                BottomBar.Text = NoItemsText;
            }


            BottomBar.AddChild(new Gui.Widgets.Button
            {
                AutoLayout = Gui.AutoLayout.FloatBottomLeft,
                Border     = "border-button",
                Text       = "< Back",
                Tooltip    = "Back to the main screen",
                OnClick    = (sender, args) =>
                {
                    GameStateManager.PopState();
                }
            });

            Grid = GuiRoot.RootItem.AddChild(new Gui.Widgets.WidgetListView
            {
                AutoLayout                  = Gui.AutoLayout.DockFill,
                Border                      = "border-one",
                Font                        = "font10",
                InteriorMargin              = new Gui.Margin(32, 0, 0, 0),
                TextHorizontalAlign         = HorizontalAlign.Center,
                TextVerticalAlign           = VerticalAlign.Top,
                SelectedItemBackgroundColor = Color.LightBlue.ToVector4(),
                SelectedItemForegroundColor = Color.Black.ToVector4()
            }) as Gui.Widgets.WidgetListView;

            GuiRoot.RootItem.Layout();

            GuiRoot.RootItem.Layout();

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

            base.OnEnter();
        }
Ejemplo n.º 27
0
        public override void OnEnter()
        {
            DwarfGame.GumInputMapper.GetInputQueue();


            GuiRoot = new Gui.Root(DwarfGame.GuiSkin);
            GuiRoot.MousePointer = new Gui.MousePointer("mouse", 4, 0);

            var panel = GuiRoot.RootItem.AddChild(new Widget
            {
                AutoLayout  = AutoLayout.FloatCenter,
                MinimumSize = new Point((int)(GuiRoot.RenderData.VirtualScreen.Width * 0.75f), (int)(GuiRoot.RenderData.VirtualScreen.Height * 0.75f)),
                Border      = "border-fancy"
            });

            panel.AddChild(new Widget
            {
                Text       = "Exit Designer",
                Border     = "border-button",
                AutoLayout = AutoLayout.FloatBottomRight,
                OnClick    = (sender, args) => StateManager.PopState()
            });

            SpriteFrame = panel.AddChild(new DwarfCorp.Gui.Widgets.EmployeePortrait
            {
                MinimumSize = new Point(48 * 6, 40 * 6),
                MaximumSize = new Point(48 * 6, 40 * 6),
                AutoLayout  = AutoLayout.DockLeft
            }) as DwarfCorp.Gui.Widgets.EmployeePortrait;

            SpriteFrame.Sprite = new LayeredSprites.LayerStack();
            foreach (Animation animation in AnimationLibrary.LoadNewLayeredAnimationFormat(ContentPaths.dwarf_animations))
            {
                var proxyAnim = SpriteFrame.Sprite.ProxyAnimation(animation);
                proxyAnim.Loops = true;
                Animations.Add(proxyAnim);
            }

            SpriteFrame.AnimationPlayer = new AnimationPlayer();
            SpriteFrame.AnimationPlayer.ChangeAnimation(Animations[0], AnimationPlayer.ChangeAnimationOptions.ResetAndPlay);

            AddSelector(panel, "body");
            AddSelector(panel, "face");
            AddSelector(panel, "nose");
            AddSelector(panel, "beard");
            AddSelector(panel, "hair");
            AddSelector(panel, "tool");
            AddSelector(panel, "hat");
            AddSelector(panel, "minecart");

            var anim = panel.AddChild(new Widget
            {
                MinimumSize = new Point(0, 32),
                AutoLayout  = AutoLayout.DockTop,
                Padding     = new Margin(2, 2, 2, 2)
            });

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

            var animCombo = anim.AddChild(new Gui.Widgets.ComboBox
            {
                Items                  = Animations.Select(a => a.Name).ToList(),
                Border                 = "border-thin",
                AutoLayout             = AutoLayout.DockTop,
                OnSelectedIndexChanged = (sender) => SpriteFrame.AnimationPlayer.ChangeAnimation(Animations.First(a => a.Name == (sender as Gui.Widgets.ComboBox).SelectedItem),
                                                                                                 AnimationPlayer.ChangeAnimationOptions.ResetAndPlay),
                ItemsVisibleInPopup = 12,
            }) as Gui.Widgets.ComboBox;

            animCombo.SelectedIndex = animCombo.Items.IndexOf("WalkingFORWARD");

            GuiRoot.RootItem.Layout();

            IsInitialized = true;

            base.OnEnter();
        }
Ejemplo n.º 28
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 Gui.Root(DwarfGame.GumSkin);
            GuiRoot.MousePointer = new MousePointer("mouse", 15.0f, 16, 17, 18, 19, 20, 21, 22, 23);

            var 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 Gui.Margin(4, 4, 4, 4),
                InteriorMargin = new Gui.Margin(24, 0, 0, 0),
            });

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

            rightPanel.AddChild(new Gui.Widget
            {
                Text               = "Regenerate",
                Border             = "border-button",
                ChangeColorOnHover = true,
                TextColor          = new Vector4(0, 0, 0, 1),
                Font               = "font16",
                AutoLayout         = Gui.AutoLayout.DockTop,
                OnClick            = (sender, args) => { Settings = new WorldGenerationSettings();  RestartGeneration(); }
            });

            rightPanel.AddChild(new Gui.Widget
            {
                Text               = "Save World",
                Border             = "border-button",
                ChangeColorOnHover = true,
                TextColor          = new Vector4(0, 0, 0, 1),
                Font               = "font16",
                AutoLayout         = Gui.AutoLayout.DockTop,
                OnClick            = (sender, args) =>
                {
                    if (Generator.CurrentState != WorldGenerator.GenerationState.Finished)
                    {
                        GuiRoot.ShowTooltip(GuiRoot.MousePosition, "Generator is not finished.");
                    }
                    else
                    {
                        System.IO.DirectoryInfo worldDirectory = System.IO.Directory.CreateDirectory(DwarfGame.GetWorldDirectory() + ProgramData.DirChar + Settings.Name);
                        NewOverworldFile file = new NewOverworldFile(Game.GraphicsDevice, Overworld.Map, Settings.Name, Settings.SeaLevel);
                        file.WriteFile(worldDirectory.FullName);
                        file.SaveScreenshot(worldDirectory.FullName + ProgramData.DirChar + "screenshot.png");
                        GuiRoot.ShowModalPopup(GuiRoot.ConstructWidget(new Gui.Widgets.Popup
                        {
                            Text = "File saved."
                        }));
                    }
                }
            });

            rightPanel.AddChild(new Gui.Widget
            {
                Text               = "Advanced",
                Border             = "border-button",
                ChangeColorOnHover = true,
                TextColor          = new Vector4(0, 0, 0, 1),
                Font               = "font16",
                AutoLayout         = Gui.AutoLayout.DockTop,
                OnClick            = (sender, args) =>
                {
                    var advancedSettingsEditor = GuiRoot.ConstructWidget(new Gui.Widgets.WorldGenerationSettingsDialog
                    {
                        Settings = Settings,
                        OnClose  = (s) => RestartGeneration()
                    });

                    GuiRoot.ShowModalPopup(advancedSettingsEditor);
                }
            });

            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) =>
                {
                    Generator.Abort();
                    StateManager.PopState();
                }
            });

            StartButton = rightPanel.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) =>
                {
                    if (Generator.CurrentState != WorldGenerator.GenerationState.Finished)
                    {
                        GuiRoot.ShowTooltip(GuiRoot.MousePosition, "World generation is not finished.");
                    }
                    else
                    {
                        Overworld.Name        = Settings.Name;
                        Settings.ExistingFile = null;
                        Settings.WorldOrigin  = Settings.WorldGenerationOrigin;
                        if (Settings.Natives == null || Settings.Natives.Count == 0)
                        {
                            Settings.Natives = Generator.NativeCivilizations;
                        }

                        StateManager.ClearState();
                        StateManager.PushState(new LoadState(Game, StateManager, Settings));
                    }
                }
            });

            rightPanel.AddChild(new Gui.Widget
            {
                Text       = "Colony size",
                AutoLayout = Gui.AutoLayout.DockTop,
                Font       = "font8",
                TextColor  = new Vector4(0, 0, 0, 1)
            });

            var colonySizeCombo = rightPanel.AddChild(new Gui.Widgets.ComboBox
            {
                AutoLayout             = Gui.AutoLayout.DockTop,
                Items                  = new List <string>(new string[] { "Small", "Medium", "Large" }),
                Font                   = "font8",
                TextColor              = new Vector4(0, 0, 0, 1),
                OnSelectedIndexChanged = (sender) =>
                {
                    switch ((sender as Gui.Widgets.ComboBox).SelectedItem)
                    {
                    case "Small": Settings.ColonySize = new Point3(4, 1, 4); break;

                    case "Medium": Settings.ColonySize = new Point3(8, 1, 8); break;

                    case "Large": Settings.ColonySize = new Point3(10, 1, 10); break;
                    }

                    var worldSize = Settings.ColonySize.ToVector3() * VoxelConstants.ChunkSizeX / Settings.WorldScale;

                    float w = worldSize.X / 2;
                    float h = worldSize.Z / 2;

                    float clickX = System.Math.Max(System.Math.Min(Settings.WorldGenerationOrigin.X, Settings.Width - w), w);
                    float clickY = System.Math.Max(System.Math.Min(Settings.WorldGenerationOrigin.Y, Settings.Height - h), h);

                    Settings.WorldGenerationOrigin = new Vector2((int)(clickX), (int)(clickY));
                }
            }) as Gui.Widgets.ComboBox;

            rightPanel.AddChild(new Gui.Widget
            {
                Text       = "Difficulty",
                AutoLayout = Gui.AutoLayout.DockTop,
                Font       = "font8",
                TextColor  = new Vector4(0, 0, 0, 1)
            });

            var difficultySelectorCombo = rightPanel.AddChild(new Gui.Widgets.ComboBox
            {
                AutoLayout             = Gui.AutoLayout.DockTop,
                Items                  = Embarkment.EmbarkmentLibrary.Select(e => e.Key).ToList(),
                TextColor              = new Vector4(0, 0, 0, 1),
                Font                   = "font8",
                OnSelectedIndexChanged = (sender) =>
                {
                    Settings.InitalEmbarkment = Embarkment.EmbarkmentLibrary[(sender as Gui.Widgets.ComboBox).SelectedItem];
                }
            }) as Gui.Widgets.ComboBox;

            ZoomedPreview = rightPanel.AddChild(new Gui.Widget
            {
                AutoLayout = Gui.AutoLayout.DockBottom,
                OnLayout   = (sender) =>
                {
                    var space = System.Math.Min(
                        difficultySelectorCombo.Rect.Width, StartButton.Rect.Top - difficultySelectorCombo.Rect.Bottom - 4);
                    sender.Rect.Height = space;
                    sender.Rect.Width  = space;
                    sender.Rect.Y      = difficultySelectorCombo.Rect.Bottom + 2;
                    sender.Rect.X      = difficultySelectorCombo.Rect.X +
                                         ((difficultySelectorCombo.Rect.Width - space) / 2);
                }
            });


            StatsLabel = rightPanel.AddChild(new Gui.Widget()
            {
                AutoLayout          = Gui.AutoLayout.DockBottom,
                Font                = "font8",
                TextColor           = new Vector4(1, 1, 1, 1),
                Background          = new TileReference("sbasic", 0),
                BackgroundColor     = new Vector4(0.0f, 0.0f, 0.0f, 0.2f),
                TextHorizontalAlign = HorizontalAlign.Left,
                MinimumSize         = new Point(128, 64),
                WrapText            = true,
                Padding             = new Margin(10, 10, 10, 0)
            });

            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;

            Preview = mainPanel.AddChild(new WorldGeneratorPreview(Game.GraphicsDevice)
            {
                Border     = "border-thin",
                AutoLayout = Gui.AutoLayout.DockFill
            }) as WorldGeneratorPreview;

            GuiRoot.RootItem.Layout();
            Preview.PreviewPanel.OnClick += (widget, args) =>
            {
                StatsLabel.Text = Generator.GetSpawnStats();

                StatsLabel.Invalidate();
            };

            difficultySelectorCombo.SelectedIndex = difficultySelectorCombo.Items.IndexOf("Normal");
            colonySizeCombo.SelectedIndex         = colonySizeCombo.Items.IndexOf("Medium");

            IsInitialized = true;

            if (AutoGenerate)
            {
                RestartGeneration();
            }
            else // Setup a dummy generator for now.
            {
                Generator = new WorldGenerator(Settings);
                Generator.LoadDummy(
                    new Color[Overworld.Map.GetLength(0) * Overworld.Map.GetLength(1)],
                    Game.GraphicsDevice);
                Preview.SetGenerator(Generator);
            }

            base.OnEnter();
        }
Ejemplo n.º 29
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 Gui.Root(DwarfGame.GuiSkin);
            GuiRoot.MousePointer = new MousePointer("mouse", 15.0f, 16, 17, 18, 19, 20, 21, 22, 23);

            var 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 Gui.Margin(4, 4, 4, 4),
                InteriorMargin = new Gui.Margin(24, 0, 0, 0),
            });

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

            rightPanel.AddChild(new Gui.Widget
            {
                Text               = "Regenerate",
                Border             = "border-button",
                ChangeColorOnHover = true,
                TextColor          = new Vector4(0, 0, 0, 1),
                Font               = "font16",
                AutoLayout         = Gui.AutoLayout.DockTop,
                OnClick            = (sender, args) => { Settings = new WorldGenerationSettings();  RestartGeneration(); }
            });

            rightPanel.AddChild(new Gui.Widget
            {
                Text               = "Save World",
                Border             = "border-button",
                ChangeColorOnHover = true,
                TextColor          = new Vector4(0, 0, 0, 1),
                Font               = "font16",
                AutoLayout         = Gui.AutoLayout.DockTop,
                OnClick            = (sender, args) =>
                {
                    if (Generator.CurrentState != WorldGenerator.GenerationState.Finished)
                    {
                        GuiRoot.ShowTooltip(GuiRoot.MousePosition, "Generator is not finished.");
                    }
                    else
                    {
                        System.IO.DirectoryInfo worldDirectory = System.IO.Directory.CreateDirectory(DwarfGame.GetWorldDirectory() + System.IO.Path.DirectorySeparatorChar + Settings.Name);
                        NewOverworldFile file = new NewOverworldFile(Game.GraphicsDevice, Overworld.Map, Settings.Name, Settings.SeaLevel);
                        file.WriteFile(worldDirectory.FullName);
                        file.SaveScreenshot(worldDirectory.FullName + System.IO.Path.DirectorySeparatorChar + "screenshot.png");
                        GuiRoot.ShowModalPopup(GuiRoot.ConstructWidget(new Gui.Widgets.Popup
                        {
                            Text = "File saved."
                        }));
                    }
                }
            });

            rightPanel.AddChild(new Gui.Widget
            {
                Text               = "Advanced",
                Border             = "border-button",
                ChangeColorOnHover = true,
                TextColor          = new Vector4(0, 0, 0, 1),
                Font               = "font16",
                AutoLayout         = Gui.AutoLayout.DockTop,
                OnClick            = (sender, args) =>
                {
                    var advancedSettingsEditor = GuiRoot.ConstructWidget(new Gui.Widgets.WorldGenerationSettingsDialog
                    {
                        Settings = Settings,
                        OnClose  = (s) =>
                        {
                            if ((s as Gui.Widgets.WorldGenerationSettingsDialog).Result == Gui.Widgets.WorldGenerationSettingsDialog.DialogResult.Okay)
                            {
                                RestartGeneration();
                            }
                        }
                    });

                    GuiRoot.ShowModalPopup(advancedSettingsEditor);
                }
            });

            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) =>
                {
                    Generator.Abort();
                    StateManager.PopState();
                }
            });

            StartButton = rightPanel.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) =>
                {
                    if (Generator.CurrentState != WorldGenerator.GenerationState.Finished)
                    {
                        GuiRoot.ShowTooltip(GuiRoot.MousePosition, "World generation is not finished.");
                    }
                    else
                    {
                        Overworld.Name        = Settings.Name;
                        Settings.ExistingFile = null;
                        Settings.WorldOrigin  = Settings.WorldGenerationOrigin;
                        Settings.SpawnRect    = Generator.GetSpawnRectangle();
                        if (Settings.Natives == null || Settings.Natives.Count == 0)
                        {
                            Settings.Natives = Generator.NativeCivilizations;
                        }
                        //Settings.StartUnderground = StartUnderground.CheckState;
                        //Settings.RevealSurface = RevealSurface.CheckState;

                        foreach (var faction in Settings.Natives)
                        {
                            Vector2 center            = new Vector2(faction.Center.X, faction.Center.Y);
                            Vector2 spawn             = new Vector2(Generator.GetSpawnRectangle().Center.X, Generator.GetSpawnRectangle().Center.Y);
                            faction.DistanceToCapital = (center - spawn).Length();
                            faction.ClaimsColony      = false;
                        }

                        foreach (var faction in Generator.GetFactionsInSpawn())
                        {
                            faction.ClaimsColony = true;
                        }

                        StateManager.ClearState();
                        StateManager.PushState(new LoadState(Game, StateManager, Settings));
                    }
                }
            });

            rightPanel.AddChild(new Gui.Widget
            {
                Text       = "Territory size",
                AutoLayout = Gui.AutoLayout.DockTop,
                Font       = "font8",
                TextColor  = new Vector4(0, 0, 0, 1),
            });

            var colonySizeCombo = rightPanel.AddChild(new Gui.Widgets.ComboBox
            {
                AutoLayout             = Gui.AutoLayout.DockTop,
                Items                  = new List <string>(new string[] { "Small", "Medium", "Large" }),
                Font                   = "font8",
                TextColor              = new Vector4(0, 0, 0, 1),
                OnSelectedIndexChanged = (sender) =>
                {
                    switch ((sender as Gui.Widgets.ComboBox).SelectedItem)
                    {
                    case "Small": Settings.ColonySize = new Point3(4, 1, 4); break;

                    case "Medium": Settings.ColonySize = new Point3(8, 1, 8); break;

                    case "Large": Settings.ColonySize = new Point3(10, 1, 10); break;
                    }

                    var worldSize = Settings.ColonySize.ToVector3() * VoxelConstants.ChunkSizeX / Settings.WorldScale;

                    float w = worldSize.X;
                    float h = worldSize.Z;

                    float clickX = System.Math.Max(System.Math.Min(Settings.WorldGenerationOrigin.X, Settings.Width - w), 0);
                    float clickY = System.Math.Max(System.Math.Min(Settings.WorldGenerationOrigin.Y, Settings.Height - h), 0);

                    Settings.WorldGenerationOrigin = new Vector2((int)(clickX), (int)(clickY));
                }
            }) as Gui.Widgets.ComboBox;

            rightPanel.AddChild(new Gui.Widget
            {
                Text       = "Difficulty",
                AutoLayout = Gui.AutoLayout.DockTop,
                Font       = "font8",
                TextColor  = new Vector4(0, 0, 0, 1)
            });

            var difficultySelectorCombo = rightPanel.AddChild(new Gui.Widgets.ComboBox
            {
                AutoLayout             = Gui.AutoLayout.DockTop,
                Items                  = EmbarkmentLibrary.Embarkments.Select(e => e.Key).ToList(),
                TextColor              = new Vector4(0, 0, 0, 1),
                Font                   = "font8",
                OnSelectedIndexChanged = (sender) =>
                {
                    Settings.InitalEmbarkment = EmbarkmentLibrary.Embarkments[(sender as Gui.Widgets.ComboBox).SelectedItem];
                }
            }) as Gui.Widgets.ComboBox;

            /*
             * StartUnderground = rightPanel.AddChild(new Gui.Widgets.CheckBox
             * {
             *  AutoLayout = Gui.AutoLayout.DockTop,
             *  Font = "font8",
             *  Text = "@world-generation-start-underground"
             * }) as Gui.Widgets.CheckBox;
             *
             * RevealSurface = rightPanel.AddChild(new Gui.Widgets.CheckBox
             * {
             *  AutoLayout = Gui.AutoLayout.DockTop,
             *  Font = "font8",
             *  Text = "@world-generation-reveal-surface",
             *  CheckState = true
             * }) as Gui.Widgets.CheckBox;
             */

            rightPanel.AddChild(new Gui.Widget
            {
                Text       = "Cave Layers",
                AutoLayout = Gui.AutoLayout.DockTop,
                Font       = "font8",
                TextColor  = new Vector4(0, 0, 0, 1),
            });

            var layerSetting = rightPanel.AddChild(new Gui.Widgets.ComboBox
            {
                AutoLayout             = AutoLayout.DockTop,
                Items                  = new List <string>(new string[] { "Barely any", "Few", "Normal", "Lots", "Way too many" }),
                Font                   = "font8",
                TextColor              = new Vector4(0, 0, 0, 1),
                OnSelectedIndexChanged = (sender) =>
                {
                    switch ((sender as Gui.Widgets.ComboBox).SelectedItem)
                    {
                    case "Barely any": Settings.NumCaveLayers = 2; break;

                    case "Few": Settings.NumCaveLayers = 3; break;

                    case "Normal": Settings.NumCaveLayers = 4; break;

                    case "Lots": Settings.NumCaveLayers = 6; break;

                    case "Way too many": Settings.NumCaveLayers = 9; break;
                    }
                }
            }) as Gui.Widgets.ComboBox;

            ZoomedPreview = rightPanel.AddChild(new Gui.Widget
            {
                AutoLayout = Gui.AutoLayout.DockBottom,
                OnLayout   = (sender) =>
                {
                    var space = System.Math.Min(
                        layerSetting.Rect.Width, StartButton.Rect.Top - layerSetting.Rect.Bottom - 4);
                    sender.Rect.Height = space;
                    sender.Rect.Width  = space;
                    sender.Rect.Y      = layerSetting.Rect.Bottom + 2;
                    sender.Rect.X      = layerSetting.Rect.X +
                                         ((layerSetting.Rect.Width - space) / 2);
                }
            });

            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;

            Preview = mainPanel.AddChild(new WorldGeneratorPreview(Game.GraphicsDevice)
            {
                Border     = "border-thin",
                AutoLayout = Gui.AutoLayout.DockFill
            }) as WorldGeneratorPreview;

            GuiRoot.RootItem.Layout();

            difficultySelectorCombo.SelectedIndex = difficultySelectorCombo.Items.IndexOf("Normal");
            colonySizeCombo.SelectedIndex         = colonySizeCombo.Items.IndexOf("Medium");
            layerSetting.SelectedIndex            = layerSetting.Items.IndexOf("Normal");

            IsInitialized = true;

            if (AutoGenerate)
            {
                RestartGeneration();
            }
            else // Setup a dummy generator for now.
            {
                Generator = new WorldGenerator(Settings);
                Generator.LoadDummy(
                    new Color[Overworld.Map.GetLength(0) * Overworld.Map.GetLength(1)],
                    Game.GraphicsDevice);
                Preview.SetGenerator(Generator);
            }

            base.OnEnter();
        }
Ejemplo n.º 30
0
        private void RebuildGui()
        {
            BuildingGUI = true;

            // Create and initialize GUI framework.
            GuiRoot = new Gui.Root(DwarfGame.GumSkin);
            GuiRoot.MousePointer = new Gui.MousePointer("mouse", 4, 0);
            var       screen    = GuiRoot.RenderData.VirtualScreen;
            float     scale     = 0.75f;
            float     newWidth  = System.Math.Min(System.Math.Max(screen.Width * scale, 640), screen.Width * scale);
            float     newHeight = System.Math.Min(System.Math.Max(screen.Height * scale, 480), screen.Height * scale);
            Rectangle rect      = new Rectangle((int)(screen.Width / 2 - newWidth / 2), (int)(screen.Height / 2 - newHeight / 2), (int)newWidth, (int)newHeight);

            // CONSTRUCT GUI HERE...
            MainPanel = GuiRoot.RootItem.AddChild(new Gui.Widget
            {
                Rect        = rect,
                Padding     = new Margin(4, 4, 4, 4),
                Transparent = true,
                MinimumSize = new Point(640, 480),
                Font        = "font10"
            });

            MainPanel.AddChild(new Gui.Widgets.Button
            {
                Text = "Close",
                Font = "font16",
                TextHorizontalAlign = HorizontalAlign.Center,
                TextVerticalAlign   = VerticalAlign.Center,
                Border  = "border-button",
                OnClick = (sender, args) =>
                {
                    // If changes, prompt before closing.
                    if (HasChanges)
                    {
                        var confirm = new Gui.Widgets.Confirm
                        {
                            Text       = "Apply changes?",
                            OkayText   = "Yes",
                            CancelText = "No",
                            OnClose    = (s2) =>
                            {
                                if ((s2 as Gui.Widgets.Confirm).DialogResult == Gui.Widgets.Confirm.Result.OKAY)
                                {
                                    ConfirmSettings();
                                }
                                if (OnClosed != null)
                                {
                                    OnClosed();
                                }
                                StateManager.PopState();
                            }
                        };
                        GuiRoot.ShowModalPopup(confirm);
                    }
                    else
                    {
                        if (OnClosed != null)
                        {
                            OnClosed();
                        }
                        StateManager.PopState();
                    }
                },
                AutoLayout = AutoLayout.FloatBottomRight
            });

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

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

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

            TabPanel.SelectedTab = 0;

            GuiRoot.RootItem.Layout();

            LoadSettings();

            BuildingGUI = false;
        }