Пример #1
0
        public override void Construct()
        {
            Border    = "border-one";
            Font      = "font10";
            TextColor = new Vector4(0, 0, 0, 1);
            OnShown  += (sender) =>
            {
                Clear();
                ResourceCombos.Clear();
                //Parent.OnClick = null;
                var titleBar = AddChild(new Gui.Widget()
                {
                    AutoLayout  = Gui.AutoLayout.DockTop,
                    MinimumSize = new Point(0, 34),
                });
                int k = 0;
                foreach (var ingredient in Data.RequiredResources)
                {
                    var resource = Library.FindMedianResourceTypeWithTag(ingredient.Type);
                    titleBar.AddChild(new Gui.Widget
                    {
                        MinimumSize         = new Point(32, 32),
                        MaximumSize         = new Point(32, 32),
                        Background          = resource.GuiLayers[0],
                        AutoLayout          = AutoLayout.DockLeft,
                        Text                = ingredient.Count.ToString(),
                        TextHorizontalAlign = HorizontalAlign.Right,
                        TextVerticalAlign   = VerticalAlign.Bottom,
                        Font                = "font10-outline-numsonly",
                        TextColor           = Color.White.ToVector4(),
                        Tooltip             = ingredient.Type.ToString()
                    });
                    if (k < Data.RequiredResources.Count - 1)
                    {
                        titleBar.AddChild(new Gui.Widget
                        {
                            MinimumSize         = new Point(16, 32),
                            MaximumSize         = new Point(16, 32),
                            AutoLayout          = AutoLayout.DockLeft,
                            Text                = "+",
                            TextHorizontalAlign = HorizontalAlign.Center,
                            TextVerticalAlign   = VerticalAlign.Bottom,
                            Font                = "font10"
                        });
                    }
                    else
                    {
                        titleBar.AddChild(new Gui.Widget
                        {
                            MinimumSize         = new Point(16, 32),
                            MaximumSize         = new Point(16, 32),
                            AutoLayout          = AutoLayout.DockLeft,
                            Text                = ">>",
                            TextHorizontalAlign = HorizontalAlign.Center,
                            TextVerticalAlign   = VerticalAlign.Bottom,
                            Font                = "font10"
                        });
                    }
                    k++;
                }

                titleBar.AddChild(new Gui.Widget
                {
                    MinimumSize         = new Point(32, 32),
                    MaximumSize         = new Point(32, 32),
                    Background          = Data.Icon,
                    AutoLayout          = Gui.AutoLayout.DockLeft,
                    Text                = Data.CraftedResultsCount.ToString(),
                    Font                = "font10-outline-numsonly",
                    TextHorizontalAlign = HorizontalAlign.Right,
                    TextVerticalAlign   = VerticalAlign.Bottom,
                    TextColor           = Color.White.ToVector4()
                });
                titleBar.AddChild(new Gui.Widget
                {
                    Text              = " " + Data.Name,
                    Font              = "font16",
                    AutoLayout        = Gui.AutoLayout.DockLeft,
                    TextVerticalAlign = VerticalAlign.Center,
                    MinimumSize       = new Point(0, 34),
                    Padding           = new Margin(0, 0, 16, 0)
                });

                AddChild(new Gui.Widget
                {
                    Text                   = Data.Description + "\n",
                    AutoLayout             = Gui.AutoLayout.DockTop,
                    AutoResizeToTextHeight = true
                });

                var minion = World.PlayerFaction.Minions.FirstOrDefault(m => Data.IsMagical ? m.Stats.IsTaskAllowed(TaskCategory.Research) : m.Stats.IsTaskAllowed(TaskCategory.BuildObject));

                var nearestBuildLocation = World.PlayerFaction.FindNearestItemWithTags(Data.CraftLocation, Vector3.Zero, false, null);
                if (minion == null)
                {
                    AddChild(new Gui.Widget
                    {
                        Text       = String.Format("Needs {0} to {1}!", Data.IsMagical ? "Wizard" : "CraftsDwarf", Data.Verb),
                        TextColor  = new Vector4(1, 0, 0, 1),
                        AutoLayout = Gui.AutoLayout.DockBottom
                    });
                }
                else if (!String.IsNullOrEmpty(Data.CraftLocation) && Data.Type == CraftItem.CraftType.Resource && nearestBuildLocation == null)
                {
                    AddChild(new Gui.Widget
                    {
                        Text       = String.Format("Needs {0} to {1}!", Data.CraftLocation, Data.Verb),
                        TextColor  = new Vector4(1, 0, 0, 1),
                        AutoLayout = Gui.AutoLayout.DockBottom
                    });
                }
                else
                {
                    foreach (var resourceAmount in Data.RequiredResources)
                    {
                        var child = AddChild(new Widget()
                        {
                            AutoLayout  = AutoLayout.DockTop,
                            MinimumSize = new Point(200, 18)
                        });

                        child.AddChild(new Gui.Widget()
                        {
                            Font       = "font8",
                            Text       = String.Format("{0} {1}: ", resourceAmount.Count, resourceAmount.Type),
                            AutoLayout = AutoLayout.DockLeft
                        });
                        child.Layout();

                        var resourceSelector = child.AddChild(new Gui.Widgets.ComboBox
                        {
                            Font        = "font8",
                            Items       = World.ListResourcesWithTag(resourceAmount.Type).Where(r => r.Count >= resourceAmount.Count).Select(r => r.Type).OrderBy(p => p).ToList(),
                            AutoLayout  = AutoLayout.DockLeft,
                            MinimumSize = new Point(200, 18),
                            Tooltip     = String.Format("Type of {0} to use.", resourceAmount.Type)
                        }) as Gui.Widgets.ComboBox;

                        if (AllowWildcard)
                        {
                            resourceSelector.Items.Insert(0, "Any");
                        }

                        if (resourceSelector.Items.Count == 0)
                        {
                            resourceSelector.Items.Add("<Not enough!>");
                        }

                        resourceSelector.SelectedIndex = 0;

                        ResourceCombos.Add(resourceSelector);
                    }


                    if (Data.Type == CraftItem.CraftType.Resource)
                    {
                        var child2 = AddChild(new Widget()
                        {
                            AutoLayout  = AutoLayout.DockTop,
                            MinimumSize = new Point(100, 18)
                        });

                        child2.AddChild(new Gui.Widget()
                        {
                            Font       = "font8",
                            Text       = "Repeat ",
                            AutoLayout = AutoLayout.DockLeft
                        });
                        NumCombo = child2.AddChild(new Gui.Widgets.ComboBox
                        {
                            Font  = "font8",
                            Items = new List <string>()
                            {
                                "1x",
                                "5x",
                                "10x",
                                "100x"
                            },
                            AutoLayout  = AutoLayout.DockLeft,
                            MinimumSize = new Point(64, 18),
                            MaximumSize = new Point(64, 18),
                            Tooltip     = "Craft this many objects."
                        }) as Gui.Widgets.ComboBox;
                        NumCombo.SelectedIndex = 0;
                    }

                    var bottomBar = AddChild(new Widget()
                    {
                        AutoLayout  = AutoLayout.DockTop,
                        MinimumSize = new Point(256, 32)
                    });

                    if (BuildAction != null)
                    {
                        if (Data.Type == CraftItem.CraftType.Object && PlaceAction != null)
                        {
                            var resources = World.ListResources();
                            if (resources.Any(resource => Library.GetResourceType(resource.Key).CraftInfo.CraftItemType == Data.Name))
                            {
                                bottomBar.AddChild(new Button()
                                {
                                    Text    = Library.GetString("place-existing"),
                                    OnClick = (widget, args) =>
                                    {
                                        PlaceAction(this, args);
                                    },
                                    AutoLayout  = AutoLayout.DockLeftCentered,
                                    MinimumSize = new Point(64, 28),
                                    Tooltip     = Library.GetString("place-existing-tooltip", Data.DisplayName)
                                });
                            }
                        }

                        var buildButton = bottomBar.AddChild(new Button()
                        {
                            Text    = Library.GetString("place-new", Data.Verb),
                            Tooltip = Library.GetString("place-new-tooltip", Data.Verb, Data.DisplayName),
                            OnClick = (widget, args) =>
                            {
                                BuildAction(this, args);
                                //sender.Hidden = true;
                                //sender.Invalidate();
                            },
                            AutoLayout  = AutoLayout.DockLeftCentered,
                            MinimumSize = new Point(64, 28),
                        });

                        //Parent.OnClick = (parent, args) => buildButton.OnClick(buildButton, args);
                    }
                }

                Layout();
            };
        }
Пример #2
0
        private void CreateGraphicsTab()
        {
            var panel = TabPanel.AddTab("GRAPHICS", new Widget
            {
                Border  = "border-thin",
                Padding = new Margin(4, 4, 4, 4)
            });

            var split = panel.AddChild(new Gui.Widgets.Columns
            {
                AutoLayout = AutoLayout.DockFill
            }) as Gui.Widgets.Columns;

            var leftPanel = split.AddChild(new Widget
            {
                Padding = new Margin(2, 2, 2, 2)
            });

            var rightPanel = split.AddChild(new Widget
            {
                Padding = new Margin(2, 2, 2, 2)
            });

            EasyGraphicsSetting = leftPanel.AddChild(LabelAndDockWidget("Easy Settings", new Gui.Widgets.ComboBox
            {
                Items = new String[] { "Lowest", "Low", "Medium", "High", "Highest", "Custom" }.ToList(),
                OnSelectedIndexChanged = OnEasySettingChanged,
                Border = "border-thin"
            })).GetChild(1) as Gui.Widgets.ComboBox;

            Resolution = leftPanel.AddChild(LabelAndDockWidget("Resolution", new Gui.Widgets.ComboBox
            {
                Items = DisplayModes.Select(dm => dm.Key).ToList(),
                OnSelectedIndexChanged = OnItemChanged,
                Border  = "border-thin",
                Tooltip = "Game screen size",
            })).GetChild(1) as Gui.Widgets.ComboBox;

            Fullscreen = leftPanel.AddChild(new CheckBox
            {
                Text = "Fullscreen",
                OnCheckStateChange = OnItemChanged,
                AutoLayout         = AutoLayout.DockTop,
                Tooltip            = "When checked, game will take up the whole screen."
            }) as CheckBox;

            ChunkDrawDistance = leftPanel.AddChild(LabelAndDockWidget("Terrain Draw Distance", new HorizontalFloatSlider
            {
                ScrollArea      = 1000f,
                OnSliderChanged = OnItemChanged,
                Tooltip         = "Higher values allow you to see more terrain. Lower values will make the game run faster."
            })).GetChild(1) as HorizontalFloatSlider;

            /*
             * VertexCullDistance = leftPanel.AddChild(LabelAndDockWidget("Geometry Draw Distance",
             *  new HorizontalFloatSlider
             * {
             *  ScrollArea = 1000f,
             *  OnSliderChanged = OnItemChanged,
             *  Tooltip = "Higher values allow you to see more terrain. Lower values will make the game run faster."
             * })).GetChild(1) as HorizontalFloatSlider;
             */
            /*
             * GenerateDistance = leftPanel.AddChild(LabelAndDockWidget("Generate Distance",
             *  new HorizontalFloatSlider
             *  {
             *      ScrollArea = 1000f,
             *      OnScrollValueChanged = OnItemChanged
             *  })).GetChild(1) as HorizontalFloatSlider;
             */

            Glow = leftPanel.AddChild(new CheckBox
            {
                Text = "Glow",
                OnCheckStateChange = OnItemChanged,
                AutoLayout         = AutoLayout.DockTop,
                Tooltip            = "When checked, bright parts of the screen will have a glow effect. Turn off to make the game run faster."
            }) as CheckBox;

            Antialiasing = rightPanel.AddChild(LabelAndDockWidget("Antialiasing", new Gui.Widgets.ComboBox
            {
                Items = AntialiasingOptions.Select(o => o.Key).ToList(),
                OnSelectedIndexChanged = OnItemChanged,
                Border  = "border-thin",
                Tooltip = "Higher values mean fewer jagged pixels. For best quality use FXAA. Fastest is no antialiasing."
            })).GetChild(1) as Gui.Widgets.ComboBox;

            ReflectTerrain = rightPanel.AddChild(new CheckBox
            {
                Text = "Water Reflects Terrain",
                OnCheckStateChange = OnItemChanged,
                AutoLayout         = AutoLayout.DockTop,
                Tooltip            = "When checked, water will reflect the terrain. Turn off to increase game performance."
            }) as CheckBox;

            ReflectEntities = rightPanel.AddChild(new CheckBox
            {
                Text = "Water Reflects Entities",
                OnCheckStateChange = OnItemChanged,
                AutoLayout         = AutoLayout.DockTop,
                Tooltip            = "When checked, water will reflect entities. Turn off to increase game performance."
            }) as CheckBox;

            AmbientOcclusion = rightPanel.AddChild(new CheckBox
            {
                Text = "Ambient Occlusion",
                OnCheckStateChange = OnItemChanged,
                AutoLayout         = AutoLayout.DockTop,
                Tooltip            = "Enables smooth lighting effects on terrain. Turn off to increase game performance."
            }) as CheckBox;


            CursorLight = rightPanel.AddChild(new CheckBox
            {
                Text = "Cursor Light",
                OnCheckStateChange = OnItemChanged,
                AutoLayout         = AutoLayout.DockTop,
                Tooltip            = "When checked, the cursor casts light. Turn off to increase game performance."
            }) as CheckBox;

            VSync = rightPanel.AddChild(new CheckBox
            {
                Text               = "Vertical Sync",
                Tooltip            = "When checked, the framerate will be fixed to the monitor refresh rate.",
                OnCheckStateChange = OnItemChanged,
                AutoLayout         = AutoLayout.DockTop
            }) as CheckBox;

            EntityLight = rightPanel.AddChild(new CheckBox
            {
                Text = "Dynamic Entity Lighting",
                OnCheckStateChange = OnItemChanged,
                AutoLayout         = AutoLayout.DockTop,
                Tooltip            = "When checked, creatures underground will be in shadow. Turn off to increase game performance."
            }) as CheckBox;

            SelfIllumination = rightPanel.AddChild(new CheckBox
            {
                Text = "Ore Glow",
                OnCheckStateChange = OnItemChanged,
                AutoLayout         = AutoLayout.DockTop,
                Tooltip            = "When checked certain ores will glow underground. Turn off to increase game performance."
            }) as CheckBox;

            ParticlePhysics = leftPanel.AddChild(new CheckBox
            {
                Text = "Particle Physics",
                OnCheckStateChange = OnItemChanged,
                AutoLayout         = AutoLayout.DockTop,
                Tooltip            = "When checked, certain particles will bounce off of terrain. Turn off to increase game performance."
            }) as CheckBox;

            Motes = leftPanel.AddChild(new CheckBox
            {
                Text = "Motes",
                OnCheckStateChange = OnItemChanged,
                AutoLayout         = AutoLayout.DockTop,
                Tooltip            = "When checked, detail grass motes will spawn. Turn off to increase game performance."
            }) as CheckBox;

            //NumMotes = leftPanel.AddChild(LabelAndDockWidget("Max Number of Entities",
            //     new HorizontalFloatSlider
            //     {
            //         ScrollArea = 2048 - 100,
            //         OnSliderChanged = OnItemChanged,
            //         Tooltip = "Controls how many of each type of entity will get drawn to the screen. Higher values mean more detail. Lower values mean better performance."

            //     })).GetChild(1) as HorizontalFloatSlider;

            /*
             * LightMap = leftPanel.AddChild(new CheckBox
             * {
             *  Text = "Light Maps",
             *  OnCheckStateChange = OnItemChanged,
             *  AutoLayout = AutoLayout.DockTop,
             *  Tooltip = "When checked, light maps will be used for pixelated terrain lighting. Turning this off increases performance."
             * }) as CheckBox;
             *
             * DynamicShadows = leftPanel.AddChild(new CheckBox
             * {
             *  Text = "Dynamic Shadows",
             *  OnCheckStateChange = OnItemChanged,
             *  AutoLayout = AutoLayout.DockTop,
             *  Tooltip = "When checked, the sun will cast shadows on terrain and entities. Turning this off increases performance."
             * }) as CheckBox;
             */
        }
Пример #3
0
        public override void Construct()
        {
            PreviewSelector = AddChild(new Gui.Widgets.ComboBox
            {
                Items = new List <string>(new string[] {
                    "Height",
                    "Biomes",
                    "Temperature",
                    "Rain",
                    "Erosion",
                    "Faults",
                    "Factions"
                }),
                AutoLayout             = Gui.AutoLayout.FloatTopLeft,
                MinimumSize            = new Point(128, 0),
                OnSelectedIndexChanged = (sender) => UpdatePreview = true,
                Font      = "font8",
                TextColor = new Vector4(0, 0, 0, 1)
            }) as Gui.Widgets.ComboBox;

            PreviewSelector.SelectedIndex = 0;

            PreviewPanel = AddChild(new Gui.Widget
            {
                AutoLayout = Gui.AutoLayout.DockFill,
                OnLayout   = (sender) =>
                {
                    sender.Rect = sender.Rect.Interior(0, PreviewSelector.Rect.Height + 2, 0, 0);
                },
                OnClick = (sender, args) =>
                {
                    if (args.MouseButton == 0)
                    {
                        int chunkSize  = 16;
                        var worldSize  = Generator.Settings.ColonySize.ToVector3() * chunkSize / Generator.Settings.WorldScale;
                        var clickPoint = ScreenToWorld(new Vector2(args.X, args.Y));
                        Generator.Settings.WorldGenerationOrigin = Generator.GetOrigin(clickPoint, worldSize);
                    }
                },
                OnMouseMove = (sender, args) =>
                {
                    if (Microsoft.Xna.Framework.Input.Mouse.GetState().RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                    {
                        var delta = new Vector2(args.X, args.Y) - new Vector2(PreviousMousePosition.X,
                                                                              PreviousMousePosition.Y);

                        var keyboard = Microsoft.Xna.Framework.Input.Keyboard.GetState();
                        if (keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift) ||
                            keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.RightShift))
                        {
                            zoom = System.Math.Min((float)System.Math.Max(zoom + delta.Y * 0.001f, 0.1f), 1.5f);
                        }
                        else
                        {
                            phi   += delta.Y * 0.01f;
                            theta -= delta.X * 0.01f;
                            phi    = System.Math.Max(phi, 0.5f);
                            phi    = System.Math.Min(phi, 1.5f);
                        }
                    }
                },
                OnScroll = (sender, args) =>
                {
                    zoom = System.Math.Min((float)System.Math.Max(args.ScrollValue > 0 ? zoom - 0.1f : zoom + 0.1f, 0.1f), 1.5f);
                }
            });
        }
Пример #4
0
        public override void Construct()
        {
            Border    = "border-fancy";
            Font      = "font8";
            TextColor = new Vector4(0, 0, 0, 1);
            OnShown  += (sender) =>
            {
                Clear();
                ResourceCombos.Clear();
                //Parent.OnClick = null;

                var builder = new StringBuilder();
                builder.AppendLine("-" + Data.Name + "-");
                builder.AppendLine(Data.Description);
                builder.AppendLine("Required:");

                AddChild(new Gui.Widget
                {
                    Text       = builder.ToString(),
                    AutoLayout = Gui.AutoLayout.DockTop
                });

                var nearestBuildLocation = World.PlayerFaction.FindNearestItemWithTags(Data.CraftLocation, Vector3.Zero, false);

                if (!String.IsNullOrEmpty(Data.CraftLocation) && nearestBuildLocation == null)
                {
                    AddChild(new Gui.Widget
                    {
                        Text       = String.Format("Needs {0} to {1}!", Data.CraftLocation, Data.Verb),
                        TextColor  = new Vector4(1, 0, 0, 1),
                        AutoLayout = Gui.AutoLayout.DockBottom
                    });
                }
                else
                {
                    foreach (var resourceAmount in Data.RequiredResources)
                    {
                        var child = AddChild(new Widget()
                        {
                            AutoLayout  = AutoLayout.DockTop,
                            MinimumSize = new Point(200, 18)
                        });

                        child.AddChild(new Gui.Widget()
                        {
                            Font       = "font8",
                            Text       = String.Format("{0} {1}: ", resourceAmount.NumResources, resourceAmount.ResourceType),
                            AutoLayout = AutoLayout.DockLeft
                        });
                        child.Layout();

                        var resourceSelector = child.AddChild(new Gui.Widgets.ComboBox
                        {
                            Font        = "font8",
                            Items       = Master.Faction.ListResourcesWithTag(resourceAmount.ResourceType).Where(r => r.NumResources >= resourceAmount.NumResources).Select(r => r.ResourceType.ToString()).OrderBy(p => p).ToList(),
                            AutoLayout  = AutoLayout.DockLeft,
                            MinimumSize = new Point(200, 18)
                        }) as Gui.Widgets.ComboBox;

                        if (resourceSelector.Items.Count == 0)
                        {
                            resourceSelector.Items.Add("<Not enough!>");
                        }

                        resourceSelector.SelectedIndex = 0;

                        ResourceCombos.Add(resourceSelector);
                    }


                    if (Data.Type == CraftItem.CraftType.Resource)
                    {
                        var child2 = AddChild(new Widget()
                        {
                            AutoLayout  = AutoLayout.DockTop,
                            MinimumSize = new Point(100, 18)
                        });

                        child2.AddChild(new Gui.Widget()
                        {
                            Font       = "font8",
                            Text       = "Repeat ",
                            AutoLayout = AutoLayout.DockLeft
                        });
                        NumCombo = child2.AddChild(new Gui.Widgets.ComboBox
                        {
                            Font  = "font8",
                            Items = new List <string>()
                            {
                                "1x",
                                "5x",
                                "10x",
                                "100x"
                            },
                            AutoLayout  = AutoLayout.DockLeft,
                            MinimumSize = new Point(64, 18),
                            MaximumSize = new Point(64, 18)
                        }) as Gui.Widgets.ComboBox;
                        NumCombo.SelectedIndex = 0;
                    }

                    if (BuildAction != null)
                    {
                        var buildButton = AddChild(new Button()
                        {
                            Text    = "Craft",
                            OnClick = (widget, args) =>
                            {
                                BuildAction(widget, args);
                                //sender.Hidden = true;
                                //sender.Invalidate();
                            },
                            AutoLayout  = AutoLayout.DockTop,
                            MinimumSize = new Point(64, 24),
                            MaximumSize = new Point(64, 24)
                        });

                        //Parent.OnClick = (parent, args) => buildButton.OnClick(buildButton, args);
                    }
                }

                Layout();
            };
        }