Beispiel #1
0
        // TODO: display n to m lines.
        public void UpdatePublic(bool show = true)
        {
            try
            {
                if (FontSize != _panel.GetValueFloat("FontSize"))
                {
                    _panel.SetValueFloat("FontSize", FontSize);
                }
            }
            catch (Exception ex)
            {
                // The game may generate an exception from the GetValueFloat(GetValue) call.
                // We can safely ignore this if it doesn't work, but it may indicate a game issue.
                EconomyScript.Instance.ServerLogger.WriteException(ex, UpdateCrashMessage);
                EconomyScript.Instance.ClientLogger.WriteException(ex, UpdateCrashMessage);
            }

            LastUpdate = DateTime.Now;

            // no need to update if the text has not changed.
            if (_panel.GetPublicText() != _publicString.ToString())
            {
                _panel.WritePublicText(_publicString.ToString());

                if (show)
                {
                    if (ForceRedraw)
                    {
                        _panel.ShowTextureOnScreen();
                    }
                    _panel.ShowPublicTextOnScreen();
                }
            }
        }
Beispiel #2
0
                                  int m(IMyTextPanel a)
                                  {
                                      float b = a.GetValueFloat("FontSize"); if (b == 0.0f)

                                      {
                                          b = 0.01f;
                                      }
                                      return(Convert.ToInt32(Math.Ceiling(17.0f / b)));
                                  }
                private int getMaxLinesFromPanel(IMyTextPanel Panel)
                {
                    float fontSize = Panel.GetValueFloat("FontSize");

                    if (fontSize == 0.0f)
                    {
                        fontSize = 0.01f;
                    }
                    return(Convert.ToInt32(Math.Ceiling(17.0f / fontSize)));
                }
Beispiel #4
0
        // TODO: display n to m lines.
        public void UpdatePublic(bool show = true)
        {
            if (FontSize != _panel.GetValueFloat("FontSize"))
            {
                _panel.SetValueFloat("FontSize", FontSize);
            }
            LastUpdate = DateTime.Now;

            // no need to update if the text has not changed.
            if (_panel.GetPublicText() != _publicString.ToString())
            {
                _panel.WritePublicText(_publicString.ToString());

                if (show)
                {
                    if (ForceRedraw)
                    {
                        _panel.ShowTextureOnScreen();
                    }
                    _panel.ShowPublicTextOnScreen();
                }
            }
        }
Beispiel #5
0
        private static void ProcessLcdBlock(IMyTextPanel textPanel)
        {
            //counter++;

            var checkArray = (textPanel.GetPublicTitle() + " " + textPanel.GetPrivateTitle()).Split(new Char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var showAll = false;
            bool showOre = false;
            bool showIngot = false;
            bool showComponent = false;
            bool showAmmo = false;
            bool showTools = false;
            bool showGasses = false;
            bool showStock = false;
            bool showPrices = true;
            bool showTest1 = false;
            bool showTest2 = false;
            StartFrom startFrom = StartFrom.None; //if # is specified eg #20  then run the start line logic
            int startLine = 0; //this is where our start line placeholder sits
            int pageNo = 1;

            // removed Linq, to reduce the looping through the array. This should only have to do one loop through all items in the array.
            foreach (var str in checkArray)
            {
                if (str.Equals("stock", StringComparison.InvariantCultureIgnoreCase))
                    showStock = true;
                if (str.Contains("#"))
                {
                    string[] lineNo = str.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                    if (lineNo.Length != 0 && int.TryParse(lineNo[0], out startLine))
                    {
                        //this only runs if they put a number in
                        startFrom = StartFrom.Line;
                    }
                }
                if (str.StartsWith("P", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (int.TryParse(str.Substring(1), out pageNo))
                        startFrom = StartFrom.Page;
                }
                if (str.Equals("*", StringComparison.InvariantCultureIgnoreCase))
                    showAll = true;
                if (!showAll)
                {
                    if (str.Equals("test1", StringComparison.InvariantCultureIgnoreCase))
                        showTest1 = true;
                    else if (str.Equals("test2", StringComparison.InvariantCultureIgnoreCase))
                        showTest2 = true;
                    else if (str.StartsWith("ore", StringComparison.InvariantCultureIgnoreCase))
                        showOre = true;
                    else if (str.StartsWith("ingot", StringComparison.InvariantCultureIgnoreCase))
                        showIngot = true;
                    else if (str.StartsWith("component", StringComparison.InvariantCultureIgnoreCase))
                        showComponent = true;
                    else if (str.StartsWith("ammo", StringComparison.InvariantCultureIgnoreCase))
                        showAmmo = true;
                    else if (str.StartsWith("tool", StringComparison.InvariantCultureIgnoreCase))
                        showTools = true;
                    else if (str.StartsWith("gas", StringComparison.InvariantCultureIgnoreCase))
                        showGasses = true;
                }
            }

            bool showHelp = !showAll && !showOre && !showIngot && !showComponent && !showAmmo && !showTools && !showGasses;

            var writer = TextPanelWriter.Create(textPanel);

            // Use the update interval on the LCD Panel to determine how often the display is updated.
            // It can only go as fast as the timer calling this code is.
            var interval = Math.Max(1f, textPanel.GetValueFloat("ChangeIntervalSlider"));
            if (writer.LastUpdate > DateTime.Now.AddSeconds(-interval))
                return;

            showPrices = !showStock || writer.IsWide;

            if (showTest1)
            {
                Test1(writer);
                writer.UpdatePublic();
                return;
            }
            if (showTest2)
            {
                Test2(writer);
                writer.UpdatePublic();
                return;
            }

            if (showHelp)
            {
                writer.AddPublicLine("Please add a tag to the private or public title.");
                writer.AddPublicLine("ie., * ingot ore component ammo tools.");
                writer.UpdatePublic();
                return;
            }

            var buyColumn = TextPanelWriter.LcdLineWidth - 180;
            var sellColumn = TextPanelWriter.LcdLineWidth - 0;
            var stockColumn = TextPanelWriter.LcdLineWidth - 0;

            if (showPrices && showStock)
            {
                buyColumn = TextPanelWriter.LcdLineWidth - 280;
                sellColumn = TextPanelWriter.LcdLineWidth - 180;
                stockColumn = TextPanelWriter.LcdLineWidth - 0;
            }

            // This might be a costly operation to run.
            var markets = MarketManager.FindMarketsFromLocation(textPanel.WorldMatrix.Translation);
            if (markets.Count == 0)
            {
                writer.AddPublicCenterLine(TextPanelWriter.LcdLineWidth / 2f, "« {0} »", EconomyScript.Instance.ServerConfig.TradeNetworkName);
                writer.AddPublicCenterLine(TextPanelWriter.LcdLineWidth / 2f, "« No market in range »");
            }
            else
            {
                // TODO: not sure if we should display all markets, the cheapest market item, or the closet market.
                // LOGIC summary: it needs to show the cheapest in stock(in range) sell(to player) price, and the highest (in range) has funds buy(from player) price
                // but this logic depends on the buy/sell commands defaulting to the same buy/sell rules as above.
                // where buy /sell commands run out of funds or supply in a given market and need to pull from the next market
                //it will either have to stop at each price change and notify the player, and/or prompt to keep transacting at each new price, or blindly keep buying until the
                //order is filled, the market runs out of stock, or the money runs out. Blindly is probably not optimal unless we are using stockmarket logic (buy orders/offers)
                //so the prompt option is the safer
                var market = markets.FirstOrDefault();

                // Build a list of the items, so we can get the name so we can the sort the items by name.
                var list = new Dictionary<MarketItemStruct, string>();

                writer.AddPublicCenterLine(TextPanelWriter.LcdLineWidth / 2f, market.DisplayName);

                if (startFrom == StartFrom.Page)
                {
                    // convert the page to lines required.
                    if (pageNo < 1)
                        pageNo = 1;
                    startLine = ((writer.DisplayLines - 2) * (pageNo - 1));
                    startFrom = StartFrom.Line;
                }

                string fromLine = " (From item #" + startLine + ".)";
                writer.AddPublicText("« Market List");
                if (startLine >= 1)
                    writer.AddPublicText(fromLine);
                else
                    startLine = 1; // needed for truncating end line.

                if (showPrices && showStock)
                {
                    writer.AddPublicRightText(buyColumn, "Buy");
                    writer.AddPublicRightText(sellColumn, "Sell");
                    writer.AddPublicRightLine(stockColumn, "Stock »");
                }
                else if (showStock)
                    writer.AddPublicRightLine(stockColumn, "Stock »");
                else if (showPrices)
                {
                    writer.AddPublicRightText(buyColumn, "Buy");
                    writer.AddPublicRightLine(sellColumn, "Sell »");
                }

                foreach (var marketItem in market.MarketItems)
                {
                    if (marketItem.IsBlacklisted)
                        continue;

                    MyObjectBuilderType result;
                    if (MyObjectBuilderType.TryParse(marketItem.TypeId, out result))
                    {
                        var id = new MyDefinitionId(result, marketItem.SubtypeName);
                        var content = Support.ProducedType(id);

                        //if (((Type)id.TypeId).IsSubclassOf(typeof(MyObjectBuilder_GasContainerObject))) // TODO: Not valid call yet.

                        // Cannot check the Type of the item, without having to use MyObjectBuilderSerializer.CreateNewObject().

                        if (showAll ||
                            (showOre && content is MyObjectBuilder_Ore) ||
                            (showIngot && content is MyObjectBuilder_Ingot) ||
                            (showComponent && content is MyObjectBuilder_Component) ||
                            (showAmmo && content is MyObjectBuilder_AmmoMagazine) ||
                            (showTools && content is MyObjectBuilder_PhysicalGunObject) || // guns, welders, hand drills, grinders.
                            (showGasses && content is MyObjectBuilder_GasContainerObject) || // aka gas bottle.
                            (showGasses && content is MyObjectBuilder_GasProperties))  // Type check here allows mods that inherit from the same type to also appear in the lists.
                        {
                            MyDefinitionBase definition;
                            if (MyDefinitionManager.Static.TryGetDefinition(id, out definition))
                                list.Add(marketItem, definition == null ? marketItem.TypeId + "/" + marketItem.SubtypeName : definition.GetDisplayName());
                        }
                    }
                }
                int line = 0;
                foreach (var kvp in list.OrderBy(k => k.Value))
                {
                    line++;
                    if (startFrom == StartFrom.Line && line < startLine) //if we have a start line specified skip all lines up to that
                        continue;
                    if (startFrom == StartFrom.Line && line - startLine >= writer.WholeDisplayLines - 2)  // counts 2 lines of headers.
                        break; // truncate the display and don't display the text on the bottom edge of the display.
                    writer.AddPublicLeftTrim(buyColumn - 120, kvp.Value);

                    decimal showBuy = kvp.Key.BuyPrice;
                    decimal showSell = kvp.Key.SellPrice;
                    if ((EconomyScript.Instance.ServerConfig.PriceScaling) && (market.MarketId == EconomyConsts.NpcMerchantId))  {
                        showBuy = EconDataManager.PriceAdjust(kvp.Key.BuyPrice, kvp.Key.Quantity, PricingBias.Buy);
                        showSell = EconDataManager.PriceAdjust(kvp.Key.SellPrice, kvp.Key.Quantity, PricingBias.Sell); }

                    if (showPrices && showStock)
                    {
                        writer.AddPublicRightText(buyColumn, showBuy.ToString("0.000", EconomyScript.ServerCulture));
                        writer.AddPublicRightText(sellColumn, showSell.ToString("0.000", EconomyScript.ServerCulture));

                        // TODO: components and tools should be displayed as whole numbers. Will be hard to align with other values.
                        writer.AddPublicRightText(stockColumn, kvp.Key.Quantity.ToString("0.0000", EconomyScript.ServerCulture)); // TODO: recheck number of decimal places.
                    }
                    else if (showStock) //does this ever actually run? seems to already be in the above?
                    {
                        // TODO: components and tools should be displayed as whole numbers. Will be hard to align with other values.

                        writer.AddPublicRightText(stockColumn, kvp.Key.Quantity.ToString("0.0000", EconomyScript.ServerCulture)); // TODO: recheck number of decimal places.
                    }
                    else if (showPrices)
                    {
                        writer.AddPublicRightText(buyColumn, showBuy.ToString("0.000", EconomyScript.ServerCulture));
                        writer.AddPublicRightText(sellColumn, showSell.ToString("0.000", EconomyScript.ServerCulture));
                    }
                    writer.AddPublicLine();
                }
            }

            writer.UpdatePublic();
        }
Beispiel #6
0
        public static void ProcessLcdBlock(IMyTextPanel textPanel)
        {
            //counter++;

            var writer = TextPanelWriter.Create(textPanel);

            // Use the update interval on the LCD Panel to determine how often the display is updated.
            // It can only go as fast as the timer calling this code is.
            float interval;

            try
            {
                interval = Math.Max((float)EconomyScript.Instance.ServerConfig.MinimumLcdDisplayInterval, textPanel.GetValueFloat("ChangeIntervalSlider"));
            }
            catch (Exception ex)
            {
                // The game may generate an exception from the GetValueFloat(GetValue) call.
                EconomyScript.Instance.ServerLogger.WriteException(ex, UpdateCrashMessage);
                EconomyScript.Instance.ClientLogger.WriteException(ex, UpdateCrashMessage);
                // We can't safely ignore this one if it doesn't work, because this can affect the display timing.
                return;
            }
            if (writer.LastUpdate > DateTime.Now.AddSeconds(-interval))
            {
                return;
            }

            var       checkArray    = textPanel.GetPublicTitle().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var       showAll       = false;
            bool      showOre       = false;
            bool      showIngot     = false;
            bool      showComponent = false;
            bool      showAmmo      = false;
            bool      showTools     = false;
            bool      showGasses    = false;
            bool      showStock     = false;
            bool      showPrices    = true;
            bool      showTest1     = false;
            bool      showTest2     = false;
            StartFrom startFrom     = StartFrom.None; //if # is specified eg #20  then run the start line logic
            int       startLine     = 0;              //this is where our start line placeholder sits
            int       pageNo        = 1;

            // removed Linq, to reduce the looping through the array. This should only have to do one loop through all items in the array.
            foreach (var str in checkArray)
            {
                if (str.Equals("stock", StringComparison.InvariantCultureIgnoreCase))
                {
                    showStock = true;
                }
                if (str.Contains("#"))
                {
                    string[] lineNo = str.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                    if (lineNo.Length != 0 && int.TryParse(lineNo[0], out startLine))
                    {
                        //this only runs if they put a number in
                        startFrom = StartFrom.Line;
                    }
                }
                if (str.StartsWith("P", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (int.TryParse(str.Substring(1), out pageNo))
                    {
                        startFrom = StartFrom.Page;
                    }
                }
                if (str.Equals("*", StringComparison.InvariantCultureIgnoreCase))
                {
                    showAll = true;
                }
                if (!showAll)
                {
                    if (str.Equals("test1", StringComparison.InvariantCultureIgnoreCase))
                    {
                        showTest1 = true;
                    }
                    else if (str.Equals("test2", StringComparison.InvariantCultureIgnoreCase))
                    {
                        showTest2 = true;
                    }
                    else if (str.StartsWith("ore", StringComparison.InvariantCultureIgnoreCase))
                    {
                        showOre = true;
                    }
                    else if (str.StartsWith("ingot", StringComparison.InvariantCultureIgnoreCase))
                    {
                        showIngot = true;
                    }
                    else if (str.StartsWith("component", StringComparison.InvariantCultureIgnoreCase))
                    {
                        showComponent = true;
                    }
                    else if (str.StartsWith("ammo", StringComparison.InvariantCultureIgnoreCase))
                    {
                        showAmmo = true;
                    }
                    else if (str.StartsWith("tool", StringComparison.InvariantCultureIgnoreCase))
                    {
                        showTools = true;
                    }
                    else if (str.StartsWith("gas", StringComparison.InvariantCultureIgnoreCase))
                    {
                        showGasses = true;
                    }
                }
            }

            bool showHelp = !showAll && !showOre && !showIngot && !showComponent && !showAmmo && !showTools && !showGasses;



            showPrices = !showStock || writer.IsWide;

            if (showTest1)
            {
                Test1(writer);
                writer.UpdatePublic();
                return;
            }
            if (showTest2)
            {
                Test2(writer);
                writer.UpdatePublic();
                return;
            }

            if (showHelp)
            {
                writer.AddPublicLine("Please add a tag to the private or public title.");
                writer.AddPublicLine("ie., * ingot ore component ammo tools.");
                writer.UpdatePublic();
                return;
            }

            var buyColumn   = TextPanelWriter.LcdLineWidth - 180;
            var sellColumn  = TextPanelWriter.LcdLineWidth - 0;
            var stockColumn = TextPanelWriter.LcdLineWidth - 0;

            if (showPrices && showStock)
            {
                buyColumn   = TextPanelWriter.LcdLineWidth - 280;
                sellColumn  = TextPanelWriter.LcdLineWidth - 180;
                stockColumn = TextPanelWriter.LcdLineWidth - 0;
            }

            // This might be a costly operation to run.
            var markets = MarketManager.FindMarketsFromLocation(textPanel.WorldMatrix.Translation);

            if (markets.Count == 0)
            {
                writer.AddPublicCenterLine(TextPanelWriter.LcdLineWidth / 2f, "« {0} »", EconomyScript.Instance.ServerConfig.TradeNetworkName);
                writer.AddPublicCenterLine(TextPanelWriter.LcdLineWidth / 2f, "« No market in range »");
            }
            else
            {
                // TODO: not sure if we should display all markets, the cheapest market item, or the closet market.
                // LOGIC summary: it needs to show the cheapest in stock(in range) sell(to player) price, and the highest (in range) has funds buy(from player) price
                // but this logic depends on the buy/sell commands defaulting to the same buy/sell rules as above.
                // where buy /sell commands run out of funds or supply in a given market and need to pull from the next market
                //it will either have to stop at each price change and notify the player, and/or prompt to keep transacting at each new price, or blindly keep buying until the
                //order is filled, the market runs out of stock, or the money runs out. Blindly is probably not optimal unless we are using stockmarket logic (buy orders/offers)
                //so the prompt option is the safer
                var market = markets.FirstOrDefault();

                // Build a list of the items, so we can get the name so we can the sort the items by name.
                var list = new Dictionary <MarketItemStruct, string>();

                writer.AddPublicCenterLine(TextPanelWriter.LcdLineWidth / 2f, market.DisplayName);

                if (startFrom == StartFrom.Page)
                {
                    // convert the page to lines required.
                    if (pageNo < 1)
                    {
                        pageNo = 1;
                    }
                    startLine = ((writer.DisplayLines - 2) * (pageNo - 1));
                    startFrom = StartFrom.Line;
                }

                string fromLine = " (From item #" + startLine + ".)";
                writer.AddPublicText("« Market List");
                if (startLine >= 1)
                {
                    writer.AddPublicText(fromLine);
                }
                else
                {
                    startLine = 1; // needed for truncating end line.
                }
                if (showPrices && showStock)
                {
                    writer.AddPublicRightText(buyColumn, "Buy");
                    writer.AddPublicRightText(sellColumn, "Sell");
                    writer.AddPublicRightLine(stockColumn, "Stock »");
                }
                else if (showStock)
                {
                    writer.AddPublicRightLine(stockColumn, "Stock »");
                }
                else if (showPrices)
                {
                    writer.AddPublicRightText(buyColumn, "Buy");
                    writer.AddPublicRightLine(sellColumn, "Sell »");
                }

                foreach (var marketItem in market.MarketItems)
                {
                    if (marketItem.IsBlacklisted)
                    {
                        continue;
                    }

                    MyObjectBuilderType result;
                    if (MyObjectBuilderType.TryParse(marketItem.TypeId, out result))
                    {
                        var id      = new MyDefinitionId(result, marketItem.SubtypeName);
                        var content = Support.ProducedType(id);

                        //if (((Type)id.TypeId).IsSubclassOf(typeof(MyObjectBuilder_GasContainerObject))) // TODO: Not valid call yet.

                        // Cannot check the Type of the item, without having to use MyObjectBuilderSerializer.CreateNewObject().

                        if (showAll ||
                            (showOre && content is MyObjectBuilder_Ore) ||
                            (showIngot && content is MyObjectBuilder_Ingot) ||
                            (showComponent && content is MyObjectBuilder_Component) ||
                            (showAmmo && content is MyObjectBuilder_AmmoMagazine) ||
                            (showTools && content is MyObjectBuilder_PhysicalGunObject) ||   // guns, welders, hand drills, grinders.
                            (showGasses && content is MyObjectBuilder_GasContainerObject) || // aka gas bottle.
                            (showGasses && content is MyObjectBuilder_GasProperties))        // Type check here allows mods that inherit from the same type to also appear in the lists.
                        {
                            MyDefinitionBase definition;
                            if (MyDefinitionManager.Static.TryGetDefinition(id, out definition))
                            {
                                list.Add(marketItem, definition == null ? marketItem.TypeId + "/" + marketItem.SubtypeName : definition.GetDisplayName());
                            }
                        }
                    }
                }
                int line = 0;
                foreach (var kvp in list.OrderBy(k => k.Value))
                {
                    line++;
                    if (startFrom == StartFrom.Line && line < startLine) //if we have a start line specified skip all lines up to that
                    {
                        continue;
                    }
                    if (startFrom == StartFrom.Line && line - startLine >= writer.WholeDisplayLines - 2) // counts 2 lines of headers.
                    {
                        break;                                                                           // truncate the display and don't display the text on the bottom edge of the display.
                    }
                    writer.AddPublicLeftTrim(buyColumn - 120, kvp.Value);

                    decimal showBuy  = kvp.Key.BuyPrice;
                    decimal showSell = kvp.Key.SellPrice;
                    if ((EconomyScript.Instance.ServerConfig.PriceScaling) && (market.MarketId == EconomyConsts.NpcMerchantId))
                    {
                        showBuy  = EconDataManager.PriceAdjust(kvp.Key.BuyPrice, kvp.Key.Quantity, PricingBias.Buy);
                        showSell = EconDataManager.PriceAdjust(kvp.Key.SellPrice, kvp.Key.Quantity, PricingBias.Sell);
                    }

                    if (showPrices && showStock)
                    {
                        writer.AddPublicRightText(buyColumn, showBuy.ToString("\t0.000", EconomyScript.ServerCulture));
                        writer.AddPublicRightText(sellColumn, showSell.ToString("\t0.000", EconomyScript.ServerCulture));

                        // TODO: components and tools should be displayed as whole numbers. Will be hard to align with other values.
                        writer.AddPublicRightText(stockColumn, kvp.Key.Quantity.ToString("\t0.0000", EconomyScript.ServerCulture)); // TODO: recheck number of decimal places.
                    }
                    else if (showStock)                                                                                             //does this ever actually run? seems to already be in the above?
                    {
                        // TODO: components and tools should be displayed as whole numbers. Will be hard to align with other values.

                        writer.AddPublicRightText(stockColumn, kvp.Key.Quantity.ToString("\t0.0000", EconomyScript.ServerCulture)); // TODO: recheck number of decimal places.
                    }
                    else if (showPrices)
                    {
                        writer.AddPublicRightText(buyColumn, showBuy.ToString("\t0.000", EconomyScript.ServerCulture));
                        writer.AddPublicRightText(sellColumn, showSell.ToString("\t0.000", EconomyScript.ServerCulture));
                    }
                    writer.AddPublicLine();
                }
            }

            writer.UpdatePublic();
        }
Beispiel #7
0
        private static void ProcessLcdBlock(IMyTextPanel textPanel)
        {
            //counter++;

            var  checkArray      = (textPanel.GetPublicTitle() + " " + textPanel.GetPrivateTitle()).Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            bool showLeaderboard = false;

            //bool showConfig = false;


            // removed Linq, to reduce the looping through the array. This should only have to do one loop through all items in the array.
            foreach (var str in checkArray)
            {
                if (str.Equals("Leaderboard", StringComparison.InvariantCultureIgnoreCase))
                {
                    showLeaderboard = true;
                }
                //else if (str.StartsWith("Config", StringComparison.InvariantCultureIgnoreCase))
                //	showConfig = true;
            }

            bool showHelp = !showLeaderboard;

            var writer = TextPanelWriter.Create(textPanel);

            // Use the update interval on the LCD Panel to determine how often the display is updated.
            // It can only go as fast as the timer calling this code is.
            var interval = Math.Max(1f, textPanel.GetValueFloat("ChangeIntervalSlider"));

            if (writer.LastUpdate > DateTime.Now.AddSeconds(-interval))
            {
                return;
            }

            if (showHelp)
            {
                writer.AddPublicLine("Please add a tag to the private or public title.");
                writer.AddPublicLine("ie., * Leaderboard");
                writer.UpdatePublic();
                return;
            }
            if (showLeaderboard)
            {
                writer.AddPublicCenterLine(TextPanelWriter.LcdLineWidth / 2f, "Conquest Faction Leaderboard");


                if (writer.IsWide)
                {
                    var NameColumn          = TextPanelWriter.LcdLineWidth - 550;
                    var VictoryPointsColumn = TextPanelWriter.LcdLineWidth - 240;
                    var PlanetBasesColumn   = TextPanelWriter.LcdLineWidth - 160;
                    var MoonBasesColumn     = TextPanelWriter.LcdLineWidth - 80;
                    var AsteroidBasesColumn = TextPanelWriter.LcdLineWidth;
                    writer.AddPublicText("Tag");
                    writer.AddPublicText("  Name");
                    writer.AddPublicRightText(VictoryPointsColumn, "Points");
                    if (ConquestScript.Instance.Config.PlanetPoints > 0)
                    {
                        writer.AddPublicRightText(PlanetBasesColumn, "Planet");
                    }
                    if (ConquestScript.Instance.Config.MoonPoints > 0)
                    {
                        writer.AddPublicRightText(MoonBasesColumn, "Moon");
                    }
                    if (ConquestScript.Instance.Config.AsteroidPoints > 0)
                    {
                        writer.AddPublicRightText(AsteroidBasesColumn, "Asteroid");
                    }
                    writer.AddPublicLine();
                    foreach (ConquestFaction Faction in ConquestScript.Instance.Data.ConquestFactions)
                    {
                        if (Faction.VictoryPoints > 0)
                        {
                            writer.AddPublicLeftTrim(NameColumn - 50, Faction.FactionTag);
                            if (Faction.FactionName.Length > 40)
                            {
                                writer.AddPublicText("    " + Faction.FactionName.Substring(0, 40) + "...");
                            }
                            else
                            {
                                writer.AddPublicText("    " + Faction.FactionName);
                            }
                            writer.AddPublicRightText(VictoryPointsColumn, Faction.VictoryPoints.ToString());
                            if (ConquestScript.Instance.Config.PlanetPoints > 0)
                            {
                                writer.AddPublicRightText(PlanetBasesColumn, Faction.PlanetBases.ToString());
                            }
                            if (ConquestScript.Instance.Config.MoonPoints > 0)
                            {
                                writer.AddPublicRightText(MoonBasesColumn, Faction.MoonBases.ToString());
                            }
                            if (ConquestScript.Instance.Config.AsteroidPoints > 0)
                            {
                                writer.AddPublicRightText(AsteroidBasesColumn, Faction.AsteroidBases.ToString());
                            }

                            writer.AddPublicLine();
                        }
                    }
                }
                else
                {
                    var NameColumn          = TextPanelWriter.LcdLineWidth - 300;
                    var VictoryPointsColumn = TextPanelWriter.LcdLineWidth;
                    writer.AddPublicText("Tag");
                    writer.AddPublicText("  Name");
                    writer.AddPublicRightLine(VictoryPointsColumn, "Points");
                    foreach (ConquestFaction Faction in ConquestScript.Instance.Data.ConquestFactions)
                    {
                        if (Faction.VictoryPoints > 0)
                        {
                            writer.AddPublicLeftTrim(NameColumn - 25, Faction.FactionTag);
                            if (Faction.FactionName.Length > 40)
                            {
                                writer.AddPublicText("    " + Faction.FactionName.Substring(0, 30) + "...");
                            }
                            else
                            {
                                writer.AddPublicText("    " + Faction.FactionName);
                            }
                            writer.AddPublicRightText(VictoryPointsColumn, Faction.VictoryPoints.ToString());
                            writer.AddPublicLine();
                        }
                    }
                }
            }
            writer.UpdatePublic();
        }
Beispiel #8
0
        private static void ProcessLcdBlock(IMyTextPanel textPanel)
        {
            //counter++;

            var  checkArray    = (textPanel.GetPublicTitle() + " " + textPanel.GetPrivateTitle()).Split(new Char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var  showAll       = false;
            bool showOre       = false;
            bool showIngot     = false;
            bool showComponent = false;
            bool showAmmo      = false;
            bool showTools     = false;
            bool showStock     = false;
            bool showPrices    = true;
            bool showTest1     = false;
            bool showTest2     = false;

            // removed Linq, to reduce the looping through the array. This should only have to do one loop through all items in the array.
            foreach (var str in checkArray)
            {
                if (str.Equals("stock", StringComparison.InvariantCultureIgnoreCase))
                {
                    showStock = true;
                }
                if (str.Equals("*", StringComparison.InvariantCultureIgnoreCase))
                {
                    showAll = true;
                }
                if (!showAll)
                {
                    if (str.Equals("test1", StringComparison.InvariantCultureIgnoreCase))
                    {
                        showTest1 = true;
                    }
                    if (str.Equals("test2", StringComparison.InvariantCultureIgnoreCase))
                    {
                        showTest2 = true;
                    }
                    if (str.Equals("ore", StringComparison.InvariantCultureIgnoreCase))
                    {
                        showOre = true;
                    }
                    if (str.Equals("ingot", StringComparison.InvariantCultureIgnoreCase))
                    {
                        showIngot = true;
                    }
                    if (str.Equals("component", StringComparison.InvariantCultureIgnoreCase))
                    {
                        showComponent = true;
                    }
                    if (str.Equals("ammo", StringComparison.InvariantCultureIgnoreCase))
                    {
                        showAmmo = true;
                    }
                    if (str.Equals("tools", StringComparison.InvariantCultureIgnoreCase))
                    {
                        showTools = true;
                    }
                }
            }

            bool showHelp = !showAll && !showOre && !showIngot && !showComponent && !showAmmo && !showTools;

            var writer = TextPanelWriter.Create(textPanel);

            // Use the update interval on the LCD Panel to determine how often the display is updated.
            // It can only go as fast as the timer calling this code is.
            var interval = Math.Max(1f, textPanel.GetValueFloat("ChangeIntervalSlider"));

            if (writer.LastUpdate > DateTime.Now.AddSeconds(-interval))
            {
                return;
            }

            showPrices = !showStock || writer.IsWide;

            if (showTest1)
            {
                Test1(writer);
                writer.UpdatePublic();
                return;
            }
            if (showTest2)
            {
                Test2(writer);
                writer.UpdatePublic();
                return;
            }

            if (showHelp)
            {
                writer.AddPublicLine("Please add a tag to the private or public title.");
                writer.AddPublicLine("ie., * ingot ore component ammo tools.");
                writer.UpdatePublic();
                return;
            }

            var buyColumn   = TextPanelWriter.LcdLineWidth - 180;
            var sellColumn  = TextPanelWriter.LcdLineWidth - 0;
            var stockColumn = TextPanelWriter.LcdLineWidth - 0;

            if (showPrices && showStock)
            {
                buyColumn   = TextPanelWriter.LcdLineWidth - 280;
                sellColumn  = TextPanelWriter.LcdLineWidth - 180;
                stockColumn = TextPanelWriter.LcdLineWidth - 0;
            }

            // This might be a costly operation to run.
            var markets = MarketManager.FindMarketsFromLocation(textPanel.WorldMatrix.Translation);

            if (markets.Count == 0)
            {
                writer.AddPublicCenterLine(TextPanelWriter.LcdLineWidth / 2f, "« {0} »", EconomyScript.Instance.Config.TradeNetworkName);
                writer.AddPublicCenterLine(TextPanelWriter.LcdLineWidth / 2f, "« No market in range »");
            }
            else
            {
                // TODO: not sure if we should display all markets, the cheapest market item, or the closet market.
                var market = markets.FirstOrDefault();

                // Build a list of the items, so we can get the name so we can the sort the items by name.
                var list = new Dictionary <MarketItemStruct, string>();

                writer.AddPublicCenterLine(TextPanelWriter.LcdLineWidth / 2f, market.DisplayName);

                writer.AddPublicText("« Market List");

                if (showPrices && showStock)
                {
                    writer.AddPublicRightText(buyColumn, "Buy");
                    writer.AddPublicRightText(sellColumn, "Sell");
                    writer.AddPublicRightLine(stockColumn, "Stock »");
                }
                else if (showStock)
                {
                    writer.AddPublicRightLine(stockColumn, "Stock »");
                }
                else if (showPrices)
                {
                    writer.AddPublicRightText(buyColumn, "Buy");
                    writer.AddPublicRightLine(sellColumn, "Sell »");
                }

                foreach (var marketItem in market.MarketItems)
                {
                    if (marketItem.IsBlacklisted)
                    {
                        continue;
                    }

                    MyObjectBuilderType result;
                    if (MyObjectBuilderType.TryParse(marketItem.TypeId, out result))
                    {
                        var id      = new MyDefinitionId(result, marketItem.SubtypeName);
                        var content = Support.ProducedType(id);

                        // Cannot check the Type of the item, without having to use MyObjectBuilderSerializer.CreateNewObject().

                        if (showAll ||
                            (showOre && content is MyObjectBuilder_Ore) ||
                            (showIngot && content is MyObjectBuilder_Ingot) ||
                            (showComponent && content is MyObjectBuilder_Component) ||
                            (showAmmo && content is MyObjectBuilder_AmmoMagazine) ||
                            (showTools && content is MyObjectBuilder_PhysicalGunObject) ||
                            (showTools && content is MyObjectBuilder_GasContainerObject))  // Type check here allows mods that inherit from the same type to also appear in the lists.
                        {
                            MyPhysicalItemDefinition definition = null;
                            if (MyDefinitionManager.Static.TryGetPhysicalItemDefinition(id, out definition))
                            {
                                list.Add(marketItem, definition == null ? marketItem.TypeId + "/" + marketItem.SubtypeName : definition.GetDisplayName());
                            }
                        }
                    }
                }

                foreach (var kvp in list.OrderBy(k => k.Value))
                {
                    writer.AddPublicLeftTrim(buyColumn - 120, kvp.Value);
                    if (showPrices && showStock)
                    {
                        writer.AddPublicRightText(buyColumn, kvp.Key.BuyPrice.ToString("0.00", EconomyScript.ServerCulture));
                        writer.AddPublicRightText(sellColumn, kvp.Key.SellPrice.ToString("0.00", EconomyScript.ServerCulture));

                        // TODO: components and tools should be displayed as whole numbers. Will be hard to align with other values.
                        writer.AddPublicRightText(stockColumn, kvp.Key.Quantity.ToString("0.000000", EconomyScript.ServerCulture)); // TODO: recheck number of decimal places.
                    }
                    else if (showStock)
                    {
                        // TODO: components and tools should be displayed as whole numbers. Will be hard to align with other values.

                        writer.AddPublicRightText(stockColumn, kvp.Key.Quantity.ToString("0.000000", EconomyScript.ServerCulture)); // TODO: recheck number of decimal places.
                    }
                    else if (showPrices)
                    {
                        writer.AddPublicRightText(buyColumn, kvp.Key.BuyPrice.ToString("0.00", EconomyScript.ServerCulture));
                        writer.AddPublicRightText(sellColumn, kvp.Key.SellPrice.ToString("0.00", EconomyScript.ServerCulture));
                    }
                    writer.AddPublicLine();
                }
            }

            writer.UpdatePublic();
        }