示例#1
0
 /// <summary>
 /// Called by DynamicLabel to recylce its
 /// </summary>
 public void RecycleLabel(DynamicLabel label, bool unlabel)
 {
     if(label.active)
         label.active = false;
     inactiveLabels.Add(label);
     if(label.anchor != null && !unlabel)
     {
         unlabeledAnchors.Add(new LabelRecord(label.anchor, label.offset, label.text));
     }
 }
示例#2
0
        public void TargetShowGameOver(NetworkConnection nc)
        {
            if (IsGameOver)
            {
                return;
            }

            DynamicLabel.CreateLabel(string.Format("{0}", "        GAME OVER :( \n PRESS R TO CONTINUE"), DymicLabelPosition.HORIZONTAL_AND_VERTICAL_CENTERED,
                                     5.0f, 30, true);
            IsGameOver = true;
        }
示例#3
0
 public override void Initialize()
 {
     base.Initialize();
     new PositionLayout(this, 80, 70, HorizontalAlignment.Left, VerticalAlignment.Middle)
     .Create(_backgroundIcon = new Icon(Context, "resource_item_icon_background"));
     new PositionLayout(this, 54, 54, HorizontalAlignment.Left, VerticalAlignment.Middle, new Padding(8))
     .Create(_icon = new Icon(Context, "resource_item_icon"))
     .Right(30, VerticalAlignment.Top, new Padding(20, 20, 5, 5), 120)
     .Create(
         _populationProgressBar =
             new ProgressBar(Context, "population_progress_bar", new UniRectangle(), Color.BlueViolet))
     .Create(_populationLabel = new DynamicLabel(Context, "population_label", new UniRectangle(), () => ""))
     .Right(30, VerticalAlignment.Top, new Padding(20, 20, 5, 5), 120)
     .Create(
         _storageProgressBar =
             new ProgressBar(Context, "storage_progress_bar", new UniRectangle(), Color.BlueViolet))
     .Create(_storageLabel = new DynamicLabel(Context, "storage_label", new UniRectangle(), () => ""));
     _iconTooltip          = Register(new Tooltip(Context, "tooltip", _backgroundIcon, .5f, ""));
     _populationTooltip    = Register(new DynamicTooltip(Context, "tooltip", _populationProgressBar, .5f));
     _storageTooltip       = Register(new DynamicTooltip(Context, "tooltip", _storageProgressBar, .5f));
 }
示例#4
0
        public override void Initialize()
        {
            base.Initialize();
            var basePostion = new PositionLayout(this, 60, 60, HorizontalAlignment.Left, VerticalAlignment.Middle, new Padding(5))
                              .Create(_icon = new Icon(Context, "settlement_item_icon"));

            basePostion.Right(28, VerticalAlignment.Top, new Padding(1))
            .Create(_name = new Label(Context, "settlement_item_name", new UniRectangle(), ""));
            basePostion.Right(28, VerticalAlignment.Bottom, new Padding(4, 0, 0, 8), 78)
            .Create(_population = new DynamicLabel(Context, "settlement_item_population", new UniRectangle(), () => ""));
            new PositionLayout(_population, 25, 25, HorizontalAlignment.Left, VerticalAlignment.Middle)
            .Create(new Icon(Context, "population"));
            _population.Overlay = true;
            basePostion.Right(28, VerticalAlignment.Bottom, new Padding(96, 0, 0, 8), 78)
            .Create(_income = new DynamicLabel(Context, "settlement_item_income", new UniRectangle(), () => ""));
            new PositionLayout(_income, 25, 25, HorizontalAlignment.Left, VerticalAlignment.Middle)
            .Create(new Icon(Context, "income"));
            _income.Overlay    = true;
            _name.Overlay      = true;
            _iconTooltip       = Register(new Tooltip(Context, "tooltip", _icon, .5f, ""));
            _populationTooltip = Register(new Tooltip(Context, "tooltip", _population, 0.5f, ""));
        }
示例#5
0
        /// <summary>
        /// Creates all of the sub-components of the GUI in for the PlayState (buttons, etc.)
        /// </summary>
        public void CreateGUIComponents()
        {
            GUI.RootComponent.ClearChildren();
            GridLayout layout = new GridLayout(GUI, GUI.RootComponent, 11, 11)
            {
                LocalBounds = new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height),
                WidthSizeMode = GUIComponent.SizeMode.Fixed,
                HeightSizeMode = GUIComponent.SizeMode.Fixed
            };

            GUI.RootComponent.AddChild(Master.Debugger.MainPanel);
            layout.AddChild(Master.ToolBar);
            Master.ToolBar.Parent = layout;
            layout.SetComponentPosition(Master.ToolBar, 7, 10, 4, 1);

            GUIComponent companyInfoComponent = new GUIComponent(GUI, layout);

            layout.SetComponentPosition(companyInfoComponent, 0, 0, 4, 2);

            GUIComponent resourceInfoComponent = new ResourceInfoComponent(GUI, layout, Master.Faction);
            layout.SetComponentPosition(resourceInfoComponent, 7, 0, 2, 2);

            GridLayout infoLayout = new GridLayout(GUI, companyInfoComponent, 3, 4);

            CompanyLogoPanel = new ImagePanel(GUI, infoLayout, PlayerCompany.Logo);
            infoLayout.SetComponentPosition(CompanyLogoPanel, 0, 0, 1, 1);

            CompanyNameLabel = new Label(GUI, infoLayout, PlayerCompany.Name, GUI.DefaultFont)
            {
                TextColor = Color.White,
                StrokeColor = new Color(0, 0, 0, 255),
                ToolTip = "Our company Name.",
                Alignment = Drawer2D.Alignment.Top,
            };
            infoLayout.SetComponentPosition(CompanyNameLabel, 1, 0, 1, 1);

            MoneyLabel = new DynamicLabel(GUI, infoLayout, "Money:\n", "", GUI.DefaultFont, "C2", () => Master.Faction.Economy.CurrentMoney)
            {
                TextColor = Color.White,
                StrokeColor = new Color(0, 0, 0, 255),
                ToolTip = "Amount of money in our treasury.",
                Alignment = Drawer2D.Alignment.Top,
            };
            infoLayout.SetComponentPosition(MoneyLabel, 3, 0, 1, 1);

            StockLabel = new DynamicLabel(GUI, infoLayout, "Stock:\n", "", GUI.DefaultFont, "C2", () => Master.Faction.Economy.Company.StockPrice)
            {
                TextColor = Color.White,
                StrokeColor = new Color(0, 0, 0, 255),
                ToolTip = "The price of our company stock.",
                Alignment = Drawer2D.Alignment.Top,
            };
            infoLayout.SetComponentPosition(StockLabel, 5, 0, 1, 1);

            TimeLabel = new Label(GUI, layout, Time.CurrentDate.ToShortDateString() + " " + Time.CurrentDate.ToShortTimeString(), GUI.SmallFont)
            {
                TextColor = Color.White,
                StrokeColor = new Color(0, 0, 0, 255),
                Alignment = Drawer2D.Alignment.Top,
                ToolTip = "Current time and date."
            };
            layout.SetComponentPosition(TimeLabel, 6, 0, 1, 1);

            CurrentLevelLabel = new Label(GUI, infoLayout, "Slice: " + ChunkManager.ChunkData.MaxViewingLevel, GUI.DefaultFont)
            {
                TextColor = Color.White,
                StrokeColor = new Color(0, 0, 0, 255),
                ToolTip = "The maximum height of visible terrain"
            };
            infoLayout.SetComponentPosition(CurrentLevelLabel, 0, 1, 1, 1);

            CurrentLevelUpButton = new Button(GUI, infoLayout, "", GUI.DefaultFont, Button.ButtonMode.ImageButton, GUI.Skin.GetSpecialFrame(GUISkin.Tile.SmallArrowUp))
            {
                ToolTip = "Go up one level of visible terrain",
                KeepAspectRatio = true,
                DontMakeBigger = true,
                DontMakeSmaller = true
            };

            infoLayout.SetComponentPosition(CurrentLevelUpButton, 1, 1, 1, 1);
            CurrentLevelUpButton.OnClicked += CurrentLevelUpButton_OnClicked;

            CurrentLevelDownButton = new Button(GUI, infoLayout, "", GUI.DefaultFont, Button.ButtonMode.ImageButton, GUI.Skin.GetSpecialFrame(GUISkin.Tile.SmallArrowDown))
            {
                ToolTip = "Go down one level of visible terrain",
                KeepAspectRatio = true,
                DontMakeBigger = true,
                DontMakeSmaller = true
            };
            infoLayout.SetComponentPosition(CurrentLevelDownButton, 1, 2, 1, 1);
            CurrentLevelDownButton.OnClicked += CurrentLevelDownButton_OnClicked;

            /*
            LevelSlider = new Slider(GUI, layout, "", ChunkManager.ChunkData.MaxViewingLevel, 0, ChunkManager.ChunkData.ChunkSizeY, Slider.SliderMode.Integer)
            {
                Orient = Slider.Orientation.Vertical,
                ToolTip = "Controls the maximum height of visible terrain",
                DrawLabel = false
            };

            layout.SetComponentPosition(LevelSlider, 0, 1, 1, 6);
            LevelSlider.OnClicked += LevelSlider_OnClicked;
            LevelSlider.InvertValue = true;
            */

            MiniMap = new Minimap(GUI, layout, 192, 192, this, TextureManager.GetTexture(ContentPaths.Terrain.terrain_colormap), TextureManager.GetTexture(ContentPaths.GUI.gui_minimap))
            {
                IsVisible =  true
            };

            layout.SetComponentPosition(MiniMap, 0, 8, 4, 4);
            Rectangle rect = layout.GetRect(new Rectangle(0, 8, 4, 4));
            layout.SetComponentOffset(MiniMap,  new Point(0, rect.Height - 250));

            Button moneyButton = new Button(GUI, layout, "Economy", GUI.SmallFont, Button.ButtonMode.ImageButton, new ImageFrame(TextureManager.GetTexture(ContentPaths.GUI.icons), 32, 2, 1))
            {
                KeepAspectRatio = true,
                ToolTip = "Opens the Economy Menu",
                DontMakeBigger = true,
                DrawFrame = true,
                TextColor = Color.White
            };

            moneyButton.OnClicked += moneyButton_OnClicked;

            Button settingsButton = new Button(GUI, layout, "Settings", GUI.SmallFont, Button.ButtonMode.ImageButton, new ImageFrame(TextureManager.GetTexture(ContentPaths.GUI.icons), 32, 4, 1))
            {
                KeepAspectRatio = true,
                ToolTip = "Opens the Settings Menu",
                DontMakeBigger = true,
                DrawFrame = true,
                TextColor = Color.White
            };

            settingsButton.OnClicked += OpenPauseMenu;

            layout.SetComponentPosition(settingsButton, 10, 0, 1, 1);

            layout.SetComponentPosition(moneyButton, 9, 0, 1, 1);

            InputManager.KeyReleasedCallback -= InputManager_KeyReleasedCallback;
            InputManager.KeyReleasedCallback += InputManager_KeyReleasedCallback;

            AnnouncementViewer = new AnnouncementViewer(GUI, layout, AnnouncementManager);
            layout.SetComponentPosition(AnnouncementViewer, 3, 10, 3, 1);
            layout.UpdateSizes();
        }
        public void ParseWidgets(IContainer ParentWidget, Dictionary <string, object> Data)
        {
            foreach (string name in Data.Keys)
            {
                if (!(Data[name] is JObject))
                {
                    throw new Exception($"Expected an Object, but got {Data[name].GetType().Name} in key '{name}' inside 'widgets'");
                }
                Dictionary <string, object> config = ((JObject)Data[name]).ToObject <Dictionary <string, object> >();
                if (!config.ContainsKey("type"))
                {
                    throw new Exception($"Widget definition must contain a 'type' key in widget '{name}'");
                }
                if (!(config["type"] is string))
                {
                    throw new Exception($"Widget type must be a string.");
                }
                Widget w    = null;
                string type = (string)config["type"];
                switch (type)
                {
                case "container":
                    w = new Container(ParentWidget);
                    break;

                case "label":
                    w = new DynamicLabel(ParentWidget);
                    break;

                case "numeric":
                    w = new NumericBox(ParentWidget);
                    break;

                case "textbox":
                    w = new TextBox(ParentWidget);
                    break;

                case "button":
                    w = new Button(ParentWidget);
                    break;

                case "dropdown":
                    w = new DropdownBox(ParentWidget);
                    break;

                case "checkbox":
                    w = new CheckBox(ParentWidget);
                    break;

                case "radiobox":
                    w = new RadioBox(ParentWidget);
                    break;

                case "switch_picker":
                    w = new GameSwitchBox(ParentWidget);
                    break;

                case "variable_picker":
                    w = new GameVariableBox(ParentWidget);
                    break;

                case "multitextbox":
                    w = new MultilineTextBox(ParentWidget);
                    break;

                case "multilabel":
                    w = new MultilineDynamicLabel(ParentWidget);
                    break;

                default:
                    throw new Exception($"Unknown widget type '{type}' in widget '{name}'");
                }
                if (WidgetLookup.ContainsKey(name))
                {
                    throw new Exception($"Two or more widgets with the same were found: '{name}'");
                }
                WidgetLookup.Add(name, w);
                int                X            = 0;
                int                Y            = 0;
                int                Width        = -1;
                int                Height       = -1;
                string             text         = null;
                int                wvalue       = 0;
                int?               min_value    = null;
                int?               max_value    = null;
                Font               font         = null;
                List <ListItem>    items        = null;
                int                idx          = -1;
                bool               enabled      = true;
                List <ClickAction> clickactions = new List <ClickAction>();
                foreach (string key in config.Keys)
                {
                    if (key == "type")
                    {
                        continue;
                    }
                    object value = config[key];
                    switch (key)
                    {
                    case "x":
                        EnsureType(typeof(long), value, "x");
                        X = Convert.ToInt32(value);
                        break;

                    case "y":
                        EnsureType(typeof(long), value, "y");
                        Y = Convert.ToInt32(value);
                        break;

                    case "width":
                        EnsureType(typeof(long), value, "width");
                        Width = Convert.ToInt32(value);
                        if (Width < 1)
                        {
                            throw new Exception($"Widget width ({Width}) must be greater than 0.");
                        }
                        break;

                    case "height":
                        EnsureType(typeof(long), value, "height");
                        Height = Convert.ToInt32(value);
                        if (Height < 1)
                        {
                            throw new Exception($"Widget height ({Height}) must be greater than 0.");
                        }
                        break;

                    case "font":
                        if (type != "label" && type != "textbox" && type != "button" && type != "dropdown" &&
                            type != "checkbox" && type != "radiobox" && type != "multitextbox" && type != "multilabel")
                        {
                            throw new Exception($"Widget type ({type}) can not contain a 'font' field.");
                        }
                        if (value is string)
                        {
                            if (!Fonts.ContainsKey((string)value))
                            {
                                throw new Exception($"Undefined font name '{(string) value}");
                            }
                            font = Fonts[(string)value];
                        }
                        else if (value is JObject)
                        {
                            font = ParseFont(((JObject)value).ToObject <Dictionary <string, object> >());
                        }
                        else
                        {
                            throw new Exception($"Expected a String or Object, but got {value.GetType().Name} in 'font'");
                        }
                        break;

                    case "value":
                        if (type != "numeric")
                        {
                            throw new Exception($"Widget type ({type}) can not contain a 'value' field.");
                        }
                        EnsureType(typeof(long), value, "value");
                        wvalue = Convert.ToInt32(value);
                        break;

                    case "min_value":
                        if (type != "numeric")
                        {
                            throw new Exception($"Widget type ({type}) can not contain a 'min_value' field.");
                        }
                        EnsureType(typeof(long), value, "min_value");
                        min_value = Convert.ToInt32(value);
                        break;

                    case "max_value":
                        if (type != "numeric")
                        {
                            throw new Exception($"Widget type ({type}) can not contain a 'max_value' field.");
                        }
                        EnsureType(typeof(long), value, "max_value");
                        max_value = Convert.ToInt32(value);
                        break;

                    case "text":
                        if (type != "label" && type != "textbox" && type != "button" && type != "checkbox" &&
                            type != "radiobox" && type != "multitextbox" && type != "multilabel")
                        {
                            throw new Exception($"Widget type ({type}) can not contain a 'text' field.");
                        }
                        EnsureType(typeof(string), value, "text");
                        text = (string)value;
                        break;

                    case "items":
                        if (type != "dropdown")
                        {
                            throw new Exception($"Widget type ({type}) can not contain an 'items' field.");
                        }
                        if (!(value is JArray))
                        {
                            throw new Exception($"Expected an Array, but got {value.GetType().Name} in key 'items'");
                        }
                        List <object> ary = ((JArray)value).ToObject <List <object> >();
                        items = new List <ListItem>();
                        foreach (object o in ary)
                        {
                            EnsureType(typeof(string), o, "items");
                            items.Add(new ListItem((string)o));
                        }
                        break;

                    case "index":
                        if (type != "dropdown")
                        {
                            throw new Exception($"Widget type ({type}) can not contain an 'index' field.");
                        }
                        EnsureType(typeof(long), value, "index");
                        idx = Convert.ToInt32(value);
                        if (idx < 0)
                        {
                            throw new Exception($"Index field must be greater than or equal to 0.");
                        }
                        break;

                    case "enabled":
                        if (type != "label" && type != "dropdown" && type != "switch_picker" && type != "variable_picker" &&
                            type != "checkbox" && type != "radiobox" && type != "textbox" && type != "numeric" &&
                            type != "button" && type != "multilabel")
                        {
                            throw new Exception($"Widget type ({type}) can not contain an 'enabled' field.");
                        }
                        EnsureType(typeof(bool), value, "enabled");
                        enabled = Convert.ToBoolean(value);
                        break;

                    case "widgets":
                        if (!(value is JObject))
                        {
                            throw new Exception($"Expected an Object, but got a {value.GetType().Name} in key 'widgets'");
                        }
                        ParseWidgets(w, ((JObject)value).ToObject <Dictionary <string, object> >());
                        break;

                    case "clicked":
                        if (type != "radiobox" && type != "dropdown")
                        {
                            throw new Exception($"Widget type ({type}) can not contain a 'clicked' field.");
                        }
                        if (!(value is JArray))
                        {
                            throw new Exception($"Expected an Array, but got {value.GetType().Name} in key 'clicked'");
                        }
                        List <object> clickdata = ((JArray)value).ToObject <List <object> >();
                        for (int i = 0; i < clickdata.Count; i++)
                        {
                            object action = clickdata[i];
                            if (!(action is JObject))
                            {
                                throw new Exception($"Expected an Object, but got {action.GetType().Name} in key 'clicked', element {i}");
                            }
                            Dictionary <string, object> actionobject = ((JObject)action).ToObject <Dictionary <string, object> >();
                            if (!actionobject.ContainsKey("action"))
                            {
                                throw new Exception($"Click definition in 'clicked', element {i} must contain an 'action' key.");
                            }
                            string        actiontype      = null;
                            List <object> actionparams    = new List <object>();
                            string        actioncondition = null;
                            foreach (string actionkey in actionobject.Keys)
                            {
                                object actionvalue = actionobject[actionkey];
                                switch (actionkey)
                                {
                                case "action":
                                    EnsureType(typeof(string), actionvalue, "action");
                                    actiontype = (string)actionvalue;
                                    if (actiontype != "enable" && actiontype != "disable" && actiontype != "check" && actiontype != "uncheck" &&
                                        actiontype != "set")
                                    {
                                        throw new Exception($"Unknown action type '{actiontype}'.");
                                    }
                                    break;

                                case "parameter":
                                    if (!(actionvalue is string) && !(actionvalue is JArray))
                                    {
                                        throw new Exception($"Expected a string or Array, but got {actionvalue.GetType().Name} in key 'parameter'.");
                                    }
                                    if (actionvalue is string)
                                    {
                                        actionparams.Add((string)actionvalue);
                                    }
                                    else
                                    {
                                        List <object> paramlist = ((JArray)actionvalue).ToObject <List <object> >();
                                        foreach (object paramvalue in paramlist)
                                        {
                                            actionparams.Add(paramvalue);
                                        }
                                    }
                                    break;

                                case "condition":
                                    EnsureType(typeof(string), actionvalue, "condition");
                                    actioncondition = (string)actionvalue;
                                    break;

                                default:
                                    throw new Exception($"Unknown key '{actionkey}' inside 'clicked' definition");
                                }
                            }
                            clickactions.Add(new ClickAction(actiontype, actionparams, actioncondition));
                        }
                        break;

                    default:
                        throw new Exception($"Unknown key '{key}' inside widget definition");
                    }
                }
                EnabledLookup.Add(name, enabled);
                w.SetPosition(X, Y);
                if (Width != -1 && Height != -1)
                {
                    w.SetSize(Width, Height);
                }
                else if (Width != -1)
                {
                    w.SetWidth(Width);
                }
                else if (Height != -1)
                {
                    w.SetHeight(Height);
                }
                if (type == "label")
                {
                    if (!string.IsNullOrEmpty(text))
                    {
                        ((DynamicLabel)w).SetText(text);
                    }
                    if (font != null)
                    {
                        ((DynamicLabel)w).SetFont(font);
                    }
                    //((DynamicLabel) w).SetParser(this);
                    ((DynamicLabel)w).SetColors(ConditionParser.Colors);
                    ((DynamicLabel)w).SetEnabled(enabled);
                }
                if (type == "multilabel")
                {
                    if (!string.IsNullOrEmpty(text))
                    {
                        ((MultilineDynamicLabel)w).SetText(text);
                    }
                    if (font != null)
                    {
                        ((MultilineDynamicLabel)w).SetFont(font);
                    }
                    //((MultilineDynamicLabel) w).SetParser(this);
                    ((MultilineDynamicLabel)w).SetColors(ConditionParser.Colors);
                    ((MultilineDynamicLabel)w).SetEnabled(enabled);
                }
                if (type == "textbox")
                {
                    if (!string.IsNullOrEmpty(text))
                    {
                        ((TextBox)w).SetInitialText(text);
                    }
                    if (font != null)
                    {
                        ((TextBox)w).TextArea.SetFont(font);
                    }
                    ((TextBox)w).OnTextChanged += Save;
                }
                if (type == "numeric")
                {
                    ((NumericBox)w).SetValue(wvalue);
                    if (min_value != null)
                    {
                        ((NumericBox)w).MinValue = (int)min_value;
                    }
                    if (max_value != null)
                    {
                        ((NumericBox)w).MaxValue = (int)max_value;
                    }
                    ((NumericBox)w).OnValueChanged += Save;
                }
                if (type == "button")
                {
                    if (!string.IsNullOrEmpty(text))
                    {
                        ((Button)w).SetText(text);
                    }
                    if (font != null)
                    {
                        ((Button)w).SetFont(font);
                    }
                }
                if (type == "dropdown")
                {
                    if (items == null && idx != -1 || items != null && idx >= items.Count)
                    {
                        throw new Exception($"Index cannot be greater than or equal to the total item size.");
                    }
                    if (items != null)
                    {
                        ((DropdownBox)w).SetItems(items);
                    }
                    if (idx != -1)
                    {
                        ((DropdownBox)w).SetSelectedIndex(idx);
                    }
                    if (font != null)
                    {
                        ((DropdownBox)w).SetFont(font);
                    }
                    ((DropdownBox)w).OnSelectionChanged += Save;
                    ((DropdownBox)w).OnSelectionChanged += delegate(BaseEventArgs e)
                    {
                        EvaluateAction(clickactions);
                    };
                }
                if (type == "checkbox")
                {
                    if (font != null)
                    {
                        ((CheckBox)w).SetFont(font);
                    }
                    if (!string.IsNullOrEmpty(text))
                    {
                        ((CheckBox)w).SetText(text);
                    }
                }
                if (type == "radiobox")
                {
                    if (font != null)
                    {
                        ((RadioBox)w).SetFont(font);
                    }
                    if (!string.IsNullOrEmpty(text))
                    {
                        ((RadioBox)w).SetText(text);
                    }
                    ((RadioBox)w).OnCheckChanged += delegate(BaseEventArgs e)
                    {
                        if (((RadioBox)w).Checked)
                        {
                            EvaluateAction(clickactions);
                        }
                    };
                }
                if (type == "switch_picker")
                {
                    ((GameSwitchBox)w).OnSwitchChanged += Save;
                }
                if (type == "variable_picker")
                {
                    ((GameVariableBox)w).OnVariableChanged += Save;
                }
                if (type == "multitextbox")
                {
                    if (font != null)
                    {
                        ((MultilineTextBox)w).SetFont(font);
                    }
                    if (!string.IsNullOrEmpty(text))
                    {
                        ((MultilineTextBox)w).SetText(text);
                    }
                }
                SetWidgetEnabled(w, enabled);
            }
        }