Exemple #1
0
        public override void Construct()
        {
            Transaction = null;
            Result      = TradeDialogResult.Pending;

            Border = "border-fancy";

            var bottomRow = AddChild(new Widget
            {
                AutoLayout  = AutoLayout.DockBottom,
                MinimumSize = new Point(0, 32)
            });

            TotalDisplay = bottomRow.AddChild(new Widget
            {
                MinimumSize       = new Point(128, 0),
                AutoLayout        = AutoLayout.DockLeft,
                Font              = "font10",
                TextColor         = new Vector4(0, 0, 0, 1),
                TextVerticalAlign = VerticalAlign.Center
            });

            SpaceDisplay = bottomRow.AddChild(new Widget
            {
                MinimumSize       = new Point(128, 0),
                AutoLayout        = AutoLayout.DockLeft,
                Font              = "font10",
                TextColor         = new Vector4(0, 0, 0, 1),
                TextVerticalAlign = VerticalAlign.Center
            });


            bottomRow.AddChild(new Gui.Widgets.Button
            {
                Font       = "font10",
                Border     = "border-button",
                TextColor  = new Vector4(0, 0, 0, 1),
                Text       = "Propose Trade",
                AutoLayout = AutoLayout.DockRight,
                OnClick    = (sender, args) =>
                {
                    if (EnvoyColumns.Valid && PlayerColumns.Valid)
                    {
                        var net         = ComputeNetValue();
                        var envoyOut    = Envoy.ComputeValue(EnvoyColumns.SelectedResources) + EnvoyColumns.TradeMoney;
                        var tradeTarget = envoyOut * 0.25;

                        if (PlayerColumns.SelectedResources.Count == 0 && EnvoyColumns.SelectedResources.Count == 0 &&
                            EnvoyColumns.TradeMoney == 0 && PlayerColumns.TradeMoney == 0)
                        {
                            Result = TradeDialogResult.Cancel;
                            this.Close();
                        }
                        else if (net >= tradeTarget)
                        {
                            Result      = TradeDialogResult.Propose;
                            Transaction = new TradeTransaction
                            {
                                EnvoyEntity  = Envoy,
                                EnvoyItems   = EnvoyColumns.SelectedResources,
                                EnvoyMoney   = EnvoyColumns.TradeMoney,
                                PlayerEntity = Player,
                                PlayerItems  = PlayerColumns.SelectedResources,
                                PlayerMoney  = PlayerColumns.TradeMoney
                            };
                            this.Close();
                        }
                        else
                        {
                            Result = TradeDialogResult.RejectProfit;
                            this.Close();
                        }
                    }
                    else
                    {
                        Root.ShowTooltip(Root.MousePosition, "Trade is invalid");
                    }
                }
            });

            bottomRow.AddChild(new Gui.Widgets.Button
            {
                Font       = "font10",
                Border     = "border-button",
                TextColor  = new Vector4(0, 0, 0, 1),
                Text       = "What will make this work?",
                AutoLayout = AutoLayout.DockRight,
                OnClick    = (sender, args) => EqualizeColumns()
            });

            bottomRow.AddChild(new Gui.Widgets.Button
            {
                Font       = "font10",
                Border     = "border-button",
                TextColor  = new Vector4(0, 0, 0, 1),
                Text       = "Cancel",
                AutoLayout = AutoLayout.DockRight,
                OnLayout   = (sender) => sender.Rect.X -= 16,
                OnClick    = (sender, args) =>
                {
                    Result = TradeDialogResult.Cancel;
                    this.Close();
                }
            });

            var mainPanel = AddChild(new Columns
            {
                AutoLayout = AutoLayout.DockFill
            });

            EnvoyColumns = mainPanel.AddChild(new ResourceColumns
            {
                TradeEntity            = Envoy,
                ValueSourceEntity      = Envoy,
                AutoLayout             = AutoLayout.DockFill,
                LeftHeader             = "Their Items",
                RightHeader            = "They Offer",
                MoneyLabel             = "Their money",
                OnTotalSelectedChanged = (s) => UpdateBottomDisplays()
            }) as ResourceColumns;

            PlayerColumns = mainPanel.AddChild(new ResourceColumns
            {
                TradeEntity            = Player,
                ValueSourceEntity      = Envoy,
                AutoLayout             = AutoLayout.DockFill,
                ReverseColumnOrder     = true,
                LeftHeader             = "Our Items",
                RightHeader            = "We Offer",
                MoneyLabel             = "Our money",
                OnTotalSelectedChanged = (s) => UpdateBottomDisplays()
            }) as ResourceColumns;

            UpdateBottomDisplays();
        }
Exemple #2
0
        public override void Construct()
        {
            Transaction = null;
            Result      = TradeDialogResult.Pending;

            Border = "border-fancy";

            Balance = AddChild(new Balance()
            {
                AutoLayout  = AutoLayout.DockBottom,
                MinimumSize = new Point(32 * 3, 64),
            }) as Balance;
            var bottomRow = AddChild(new Widget
            {
                AutoLayout  = AutoLayout.DockBottom,
                MinimumSize = new Point(0, 32)
            });


            bottomRow.AddChild(new Gui.Widgets.Button
            {
                Font       = "font10",
                Border     = "border-button",
                TextColor  = new Vector4(0, 0, 0, 1),
                Text       = "Propose Trade",
                AutoLayout = AutoLayout.DockRight,
                OnClick    = (sender, args) =>
                {
                    if (EnvoyColumns.Valid && PlayerColumns.Valid)
                    {
                        var net         = ComputeNetValue();
                        var envoyOut    = Envoy.ComputeValue(EnvoyColumns.SelectedResources) + EnvoyColumns.TradeMoney;
                        var tradeTarget = 1.0m;

                        if (PlayerColumns.SelectedResources.Count == 0 && EnvoyColumns.SelectedResources.Count == 0 &&
                            EnvoyColumns.TradeMoney == 0 && PlayerColumns.TradeMoney == 0)
                        {
                            Root.ShowTooltip(Root.MousePosition, "You've selected nothing to trade.");
                        }
                        else if (net >= tradeTarget)
                        {
                            Result      = TradeDialogResult.Propose;
                            Transaction = new TradeTransaction
                            {
                                EnvoyEntity  = Envoy,
                                EnvoyItems   = EnvoyColumns.SelectedResources,
                                EnvoyMoney   = EnvoyColumns.TradeMoney,
                                PlayerEntity = Player,
                                PlayerItems  = PlayerColumns.SelectedResources,
                                PlayerMoney  = PlayerColumns.TradeMoney
                            };
                            Root.SafeCall(OnPlayerAction, this);
                        }
                        else
                        {
                            Result = TradeDialogResult.RejectProfit;
                            Root.SafeCall(OnPlayerAction, this);
                        }
                    }
                    else
                    {
                        Root.ShowTooltip(Root.MousePosition, "Trade is invalid");
                    }
                }
            });

            var autoButton = bottomRow.AddChild(new Gui.Widgets.Button
            {
                Font       = "font10",
                Border     = "border-button",
                TextColor  = new Vector4(0, 0, 0, 1),
                Text       = "Make this work",
                Tooltip    = "What will make this work?",
                AutoLayout = AutoLayout.DockRight,
                OnUpdate   = (sender, gameTime) =>
                {
                    DwarfBux net, tradeTarget;
                    CalculateTradeAmount(out net, out tradeTarget);
                    (sender as Gui.Widgets.Button).Enabled = net < tradeTarget;
                    sender.Invalidate();
                },
                OnClick = (sender, args) =>
                {
                    if ((sender as Gui.Widgets.Button).Enabled)
                    {
                        EqualizeColumns();
                    }
                }
            });

            Root.RegisterForUpdate(autoButton);

            bottomRow.AddChild(new Gui.Widgets.Button
            {
                Font       = "font10",
                Border     = "border-button",
                TextColor  = new Vector4(0, 0, 0, 1),
                Text       = "Clear",
                Tooltip    = "Clear trade",
                AutoLayout = AutoLayout.DockRight,
                OnClick    = (sender, args) =>
                {
                    EnvoyColumns.Reconstruct(Envoy.Resources, new List <ResourceAmount>(), (int)Envoy.Money);
                    PlayerColumns.Reconstruct(Player.Resources, new List <ResourceAmount>(), (int)Player.Money);
                    UpdateBottomDisplays();
                    Layout();
                }
            });

            bottomRow.AddChild(new Gui.Widgets.Button
            {
                Font       = "font10",
                Border     = "border-button",
                TextColor  = new Vector4(0, 0, 0, 1),
                Text       = "Stop",
                Tooltip    = "Stop trading.",
                AutoLayout = AutoLayout.DockRight,
                //OnLayout = (sender) => sender.Rect.X -= 16,
                OnClick = (sender, args) =>
                {
                    Result = TradeDialogResult.Cancel;
                    Root.SafeCall(OnPlayerAction, this);
                    //this.Close();
                }
            });


            TotalDisplay = Balance.AddChild(new Widget
            {
                MinimumSize         = new Point(128, 64),
                AutoLayout          = AutoLayout.DockBottom,
                Font                = "font10",
                TextColor           = new Vector4(0, 0, 0, 1),
                TextVerticalAlign   = VerticalAlign.Bottom,
                TextHorizontalAlign = HorizontalAlign.Center
            });

            SpaceDisplay = bottomRow.AddChild(new Widget
            {
                //MinimumSize = new Point(128, 0),
                AutoLayout        = AutoLayout.DockFill,
                Font              = "font10",
                TextColor         = new Vector4(0, 0, 0, 1),
                TextVerticalAlign = VerticalAlign.Center,
                MaximumSize       = new Point(256, 32),
                Tag = "trade_stocks"
            });

            var mainPanel = AddChild(new Columns
            {
                AutoLayout = AutoLayout.DockFill
            });


            PlayerColumns = mainPanel.AddChild(new ResourceColumns
            {
                TradeEntity            = Player,
                ValueSourceEntity      = Envoy,
                AutoLayout             = AutoLayout.DockFill,
                ReverseColumnOrder     = true,
                LeftHeader             = "Our Items",
                RightHeader            = "We Offer",
                MoneyLabel             = "Our money",
                OnTotalSelectedChanged = (s) => UpdateBottomDisplays(),
                Tag = "trade_money"
            }) as ResourceColumns;

            EnvoyColumns = mainPanel.AddChild(new ResourceColumns
            {
                TradeEntity            = Envoy,
                ValueSourceEntity      = Envoy,
                AutoLayout             = AutoLayout.DockFill,
                LeftHeader             = "Their Items",
                RightHeader            = "They Offer",
                MoneyLabel             = "Their money",
                OnTotalSelectedChanged = (s) => UpdateBottomDisplays()
            }) as ResourceColumns;

            UpdateBottomDisplays();
        }
Exemple #3
0
        public override void Construct()
        {
            Transaction = null;
            Result      = MarketDialogResult.Pending;

            Border = "border-fancy";

            var bottomRow = AddChild(new Widget
            {
                AutoLayout  = AutoLayout.DockBottom,
                MinimumSize = new Point(0, 32)
            });

            bottomRow.AddChild(new Gui.Widgets.Button
            {
                Font       = "font10",
                Border     = "border-button",
                TextColor  = new Vector4(0, 0, 0, 1),
                Text       = "Propose Trade",
                AutoLayout = AutoLayout.DockRight,
                OnClick    = (sender, args) =>
                {
                    if (PlayerColumns.Valid)
                    {
                        if (PlayerColumns.SelectedResources.Count == 0)
                        {
                            Root.ShowModalMessage("You've selected nothing to trade.");
                        }
                        else
                        {
                            Result      = MarketDialogResult.Propose;
                            Transaction = new MarketTransaction
                            {
                                PlayerEntity = Player,
                                PlayerItems  = PlayerColumns.SelectedResources,
                                PlayerMoney  = ComputeNetValue()
                            };

                            Root.SafeCall(OnPlayerAction, this);
                        }
                    }
                    else
                    {
                        Root.ShowTooltip(Root.MousePosition, "Trade is invalid");
                    }
                }
            });

            bottomRow.AddChild(new Gui.Widgets.Button
            {
                Font       = "font10",
                Border     = "border-button",
                TextColor  = new Vector4(0, 0, 0, 1),
                Text       = "Clear",
                Tooltip    = "Clear trade",
                AutoLayout = AutoLayout.DockRight,
                OnClick    = (sender, args) =>
                {
                    PlayerColumns.Reconstruct(Player.Resources, new List <ResourceAmount>(), (int)Player.Money);
                    UpdateBottomDisplays();
                    Layout();
                }
            });

            bottomRow.AddChild(new Gui.Widgets.Button
            {
                Font       = "font10",
                Border     = "border-button",
                TextColor  = new Vector4(0, 0, 0, 1),
                Text       = "Stop",
                Tooltip    = "Stop trading.",
                AutoLayout = AutoLayout.DockRight,
                //OnLayout = (sender) => sender.Rect.X -= 16,
                OnClick = (sender, args) =>
                {
                    Result = MarketDialogResult.Cancel;
                    Root.SafeCall(OnPlayerAction, this);
                    //this.Close();
                }
            });

            TotalDisplay = bottomRow.AddChild(new Widget
            {
                MinimumSize         = new Point(256, 64),
                AutoLayout          = AutoLayout.DockFill,
                Font                = "font10",
                TextColor           = new Vector4(0, 0, 0, 1),
                TextVerticalAlign   = VerticalAlign.Bottom,
                TextHorizontalAlign = HorizontalAlign.Left,
                Text                = "Total Profit: $0"
            });

            var mainPanel = AddChild(new Columns
            {
                AutoLayout = AutoLayout.DockFill
            });

            PlayerColumns = mainPanel.AddChild(new ResourceColumns
            {
                TradeEntity            = Player,
                ValueSourceEntity      = Player,
                AutoLayout             = AutoLayout.DockFill,
                ReverseColumnOrder     = true,
                LeftHeader             = "Our Items",
                RightHeader            = "We Offer",
                MoneyLabel             = "Our money",
                OnTotalSelectedChanged = (s) => UpdateBottomDisplays(),
                Tag            = "trade_money",
                ShowMoneyField = false
            }) as ResourceColumns;

            UpdateBottomDisplays();
        }