Ejemplo n.º 1
0
 private void UpdateValues()
 {
     hasHudLcd = false;
     if (thisLcd.GetPublicTitle().ToLower().Contains(matchstring))
     {
         hasHudLcd = true;
         ParseAndUpdateConfig(thisLcd.GetPublicTitle());
     }
     else if (thisLcd.CustomData.ToLower().Contains(matchstring))
     {
         hasHudLcd = true;
         ParseAndUpdateConfig(thisLcd.CustomData);
     }
 }
        private void WritePanelAll(IMyTextPanel panel)
        {
            string panelText = "";

            panelText += panel.GetPublicTitle() + '\n';
            for (int i = 0; i < itemCounts.Count; i++)
            {
                var itemValue = itemCounts.ElementAt(i);
                panelText += String.Format("{0} : {1}\n", itemValue.Key, itemValue.Value);
            }
            panel.WritePublicText(panelText);
        }
Ejemplo n.º 3
0
        private bool updatePanel(IMyTextPanel TextPanel)
        {
            List <BfGps>  Waypoints = getGpsWaypoints(TextPanel);
            StringBuilder Text      = new StringBuilder();

            if (TextPanel.GetPublicTitle().Trim().Length > 0)
            {
                Text.AppendLine(TextPanel.GetPublicTitle());
            }
            for (int i = 0; i < Waypoints.Count; i++)
            {
                BfGps Gps = Waypoints[i];
                if (Gps != null)
                {
                    double distance = Math.Round(Vector3D.Distance(PbPos, Gps.vector), 2);
                    Text.AppendLine(Gps.name + ": " + distance.ToString("### ### ### ###.00") + " m");
                }
            }

            return(displayOnPrivateText(TextPanel, Text) || displayOnPublicText(TextPanel, Text));
        }
Ejemplo n.º 4
0
        private void getRadarValues()
        {
            var privatetitle = panel.CustomData;
            var publictitle  = panel.GetPublicTitle();

            try
            {
                HoloSetting PlayerAdjust;
                privateradarid = parseSettingsString(privatetitle, out PlayerAdjust);
                PrivateAdjust  = PlayerAdjust;
                publicradarid  = parseSettingsString(publictitle, out PlayerAdjust);
                PublicAdjust   = PlayerAdjust;
            }
            catch
            {
                //do nothing.
            }
        }
        /// <summary>
        /// Sets the text on an inventory panel using it's custom data
        /// Custom data is assumed to be single lines of item names
        /// </summary>
        private void WritePanelFromCustomData(IMyTextPanel panel)
        {
            string panelText = "";

            panelText += panel.GetPublicTitle() + '\n';
            var lines = panel.CustomData.Split('\n');

            for (int l = 0; l < lines.Length; l++)
            {
                string line  = lines[l];
                string quota = "";
                if (itemQuotas.ContainsKey(line))
                {
                    quota += "/" + itemQuotas[line];
                }
                if (itemCounts.ContainsKey(line))
                {
                    panelText += itemCounts[line] + '\n';
                }
            }
            panel.WritePublicText(panelText);
        }
Ejemplo n.º 6
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////
        /*                                                                       INITIALIZATION                                                                           */
        //////////////////////////////////////////////////////////////////////////////////////////////////////////



        void GetBlocks()
        {
            List <IMyTerminalBlock> _blocks = new List <IMyTerminalBlock>();

            GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(_blocks);
            for (int i = 0; i < _blocks.Count; i++)
            {
                if (_blocks[i].CustomName.Contains(platformID))
                {
                    ///////////////////////// CHECK FOR HACKED BLOCKs
                    if (IsBeingHacked(_blocks[i]))
                    {
                        Debug("->" + _blocks[i].CustomName + " is being hacked!");

                        hackDetected = true;
                    }
                    ///////////////////////// CHECK FOR DAMAGED BLOCKs
                    if (IsBeingAttacked(_blocks[i]))
                    {
                        Debug("->" + _blocks[i].CustomName + " is damaged!");
                        attackDetected = true;
                    }
                    /////////////////////// GETTING GRAV GENs //////////////////////
                    if (_blocks[i].CustomName.Contains(gravID) && _blocks[i].CustomName.Contains(securityID))
                    {
                        gravs.Add((IMyGravityGenerator)_blocks[i]);
                    }
                    /////////////////////// GETTING AIRVENTS //////////////////////
                    if (_blocks[i].CustomName.Contains(airVentID))
                    {
                        IMyAirVent _vent = (IMyAirVent)_blocks[i];
                        airvents.Add(_vent);
                    }
                    ////////////////// GETTING ALERT SPEAKERS ////////////////////
                    if (_blocks[i].CustomName.Contains(speakerID) && _blocks[i].CustomName.Contains(securityID))
                    {
                        alerts.Add((IMySoundBlock)_blocks[i]);
                    }
                    /////////////////// GETTING INTERIOR LIGHTS ////////////////////
                    if (_blocks[i].CustomName.Contains(lightID) && _blocks[i].CustomName.Contains(securityID))
                    {
                        lights.Add((IMyInteriorLight)_blocks[i]);
                    }
                    /////////////////////// GETTING DOORS //////////////////////////
                    if (_blocks[i].CustomName.Contains(doorID))
                    {
                        doors.Add((IMyDoor)_blocks[i]);
                        if (_blocks[i].CustomName.Contains(securityID))
                        {
                            securityDoors.Add((IMyDoor)_blocks[i]);
                        }
                    }
                    ///////////////////// GETTING TEXT PANELS /////////////////////
                    if (_blocks[i].CustomName.Contains(panelID))
                    {
                        IMyTextPanel _panel = (IMyTextPanel)_blocks[i];
                        if (_panel.GetPublicTitle().Contains(debugID))
                        {
                            //debugger.Add(_panel);
                            //debugEnabled = true;
                        }
                        else
                        {
                            if (!_panel.CustomName.Contains(configID) && _panel.GetPublicTitle() == infoID)
                            {
                                _panel.ShowPublicTextOnScreen();
                                _panel.SetValue("FontSize", 0.8f);
                                panels.Add(_panel);
                            }
                        }
                    }

                    ////////////////////// GETTING PROGRAMS //////////////////////
                    if (_blocks[i].CustomName.Contains(programID))
                    {
                        IMyProgrammableBlock _program = (IMyProgrammableBlock)_blocks[i];
                        if (!_program.CustomName.Contains(coreID))
                        {
                            programs.Add(_program);
                        }
                    }
                    ///////////////////// GETTING TIMERBLOCKS ////////////////////
                    if (_blocks[i].CustomName.Contains(timerID) && _blocks[i].CustomName.Contains(securityID))
                    {
                        timers.Add((IMyTimerBlock)_blocks[i]);
                    }
                    /////////////////// GETTING GATLING TURRETS /////////////////
                    if (_blocks[i].CustomName.Contains(gatlingID))
                    {
                        gatlings.Add((IMyLargeGatlingTurret)_blocks[i]);
                    }
                    if (_blocks[i].CustomName.Contains(missileID))
                    {
                        missiles.Add((IMyLargeMissileTurret)_blocks[i]);
                    }
                    if (_blocks[i].CustomName.Contains(turretID))
                    {
                        turrets.Add((IMyLargeInteriorTurret)_blocks[i]);
                    }
                }
            }
            booted = true;
        }
Ejemplo n.º 7
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();
        }
Ejemplo n.º 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 showTest = 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("*", StringComparison.InvariantCultureIgnoreCase))
                    showAll = true;
                if (!showAll)
                {
                    if (str.Equals("test", StringComparison.InvariantCultureIgnoreCase))
                        showTest = 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);

            if (showTest)
            {
                Test(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;

            // This might be a costly operation to run.
            var markets = MarketManager.FindMarketsFromLocation(textPanel.WorldMatrix.Translation);
            if (markets.Count == 0)
            {
                writer.AddPublicCenterLine(TextPanelWriter.LcdLineWidth / 2f, "« Economy »");
                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.AddPublicText("« Market List");
                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);
                    writer.AddPublicRightText(buyColumn, kvp.Key.BuyPrice.ToString("0.00"));
                    writer.AddPublicRightText(sellColumn, kvp.Key.SellPrice.ToString("0.00"));
                    writer.AddPublicLine();
                }
            }

            writer.UpdatePublic();
        }
Ejemplo n.º 9
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();
        }
Ejemplo n.º 10
0
        private SortedDictionary <int, List <IMyTextPanel> > SortPanelsWithName(string name, List <IMyTextPanel> panels)
        {
            SortedDictionary <int, List <IMyTextPanel> > sortedDict = new SortedDictionary <int, List <IMyTextPanel> >();

            for (int i = 0; i < panels.Count; i++)
            {
                IMyTextPanel panel = panels[i];

                if (!panel.IsFunctional || !panel.IsWorking)
                {
                    continue;
                }

                string[] nameParts  = panel.CustomName.Trim().Split(' ');
                string[] titleParts = panel.GetPublicTitle().Trim().Split(' ');
                DebugString.AppendLine(string.Format("Title Parts: {0}", string.Join(", ", titleParts)));

                string indexPart = "";

                int ind;
                int test;

                if (nameParts.Length >= 2 && nameParts[0].Equals(name.Split(' ')[0]))
                {
                    // workaround for stupid people that cant follow instructions properly
                    if (nameParts[1].Length < 2)
                    {
                        if (nameParts.Length >= 3 && nameParts[1].Equals("#") && int.TryParse(nameParts[2], out test))
                        {
                            indexPart = nameParts[2];
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        indexPart = nameParts[1].Substring(1);
                    }

                    if (nameParts[1].StartsWith("#") && int.TryParse(indexPart, out ind) && ind >= 0)
                    {
                        if (!sortedDict.ContainsKey(ind))
                        {
                            sortedDict.Add(ind, new List <IMyTextPanel>());
                            DebugString.AppendLine(string.Format("New list at index: {0}", ind));
                        }
                        sortedDict[ind].Add(panel);
                        DebugString.AppendLine(string.Format("Add panel at index: {0}", ind));
                    }
                }
                else if (titleParts.Length >= 2 && titleParts[0].Equals(name.Split(' ')[0]))
                {
                    // workaround for stupid people that cant follow instructions properly
                    if (titleParts[1].Length < 2)
                    {
                        if (titleParts.Length >= 3 && titleParts[1].Equals("#") && int.TryParse(titleParts[2], out test))
                        {
                            indexPart = titleParts[2];
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        indexPart = titleParts[1].Substring(1);
                    }

                    if (titleParts[1].StartsWith("#") && int.TryParse(indexPart, out ind) && ind >= 0)
                    {
                        if (!sortedDict.ContainsKey(ind))
                        {
                            sortedDict.Add(ind, new List <IMyTextPanel>());
                            DebugString.AppendLine(string.Format("New list at index: {0}", ind));
                        }
                        sortedDict[ind].Add(panel);
                        DebugString.AppendLine(string.Format("Add panel at index: {0}", ind));
                    }
                }
            }
            return(sortedDict);
        }
Ejemplo n.º 11
0
        private void EvaluateBlockInvPanels(List <IMyTextPanel> blockInvPanels)
        {
            BlockInvPanels   = new Dictionary <IMyTerminalBlock, List <List <IMyTextPanel> > >();
            BlockInvContents = new Dictionary <IMyTerminalBlock, List <string> >();

            for (int i = 0; i < blockInvPanels.Count; i++)
            {
                IMyTextPanel     panel = blockInvPanels[i];
                IMyTerminalBlock block;

                if (!panel.CustomName.StartsWith(BlockInvPanelsPrefix) && !panel.GetPublicTitle().StartsWith(BlockInvPanelsPrefix))
                {
                    continue;
                }

                int startIndexName = panel.CustomName.IndexOf('"') + 1;
                int lastIndexName  = panel.CustomName.LastIndexOf('"');

                int startIndexTitle = panel.GetPublicTitle().IndexOf('"') + 1;
                int lastIndexTitle  = panel.GetPublicTitle().LastIndexOf('"');

                if (panel.CustomName.StartsWith(BlockInvPanelsPrefix) && startIndexName >= 0 && lastIndexName > 0 && startIndexName < lastIndexName)
                {
                    int length = lastIndexName - startIndexName;

                    string blockname = panel.CustomName.Substring(startIndexName, length);

                    panel.WriteText(string.Format("Cannot find {0} or.\n\r", blockname));
                    panel.WriteText(string.Format("{0} does not have an inventory.", blockname), true);

                    if (GetBlockWithExactName(blockname, out block) && block.HasInventory)
                    {
                        if (!BlockInvPanels.ContainsKey(block))
                        {
                            BlockInvPanels.Add(block, new List <List <IMyTextPanel> >());
                            BlockInvPanels[block].Add(new List <IMyTextPanel>());
                            BlockInvContents.Add(block, EvaluateInvOwner(block));
                        }

                        BlockInvPanels[block][0].Add(panel);
                    }
                }
                else if (panel.GetPublicTitle().StartsWith(BlockInvPanelsPrefix) && startIndexTitle >= 0 && lastIndexTitle > 0 && startIndexTitle < lastIndexTitle)
                {
                    int length = lastIndexTitle - startIndexTitle;

                    string blockname = panel.GetPublicTitle().Substring(startIndexTitle, length);

                    panel.WriteText(string.Format("Cannot find {0} or.\n\r", blockname));
                    panel.WriteText(string.Format("{0} does not have an inventory.", blockname), true);

                    if (GetBlockWithExactName(blockname, out block) && block.HasInventory)
                    {
                        if (!BlockInvPanels.ContainsKey(block))
                        {
                            BlockInvPanels.Add(block, new List <List <IMyTextPanel> >());
                            BlockInvPanels[block].Add(new List <IMyTextPanel>());
                            BlockInvContents.Add(block, EvaluateInvOwner(block));
                        }

                        BlockInvPanels[block][0].Add(panel);
                    }
                }
                else if (TryGetBlockWithInvBehind(panel, out block))
                {
                    if (!BlockInvPanels.ContainsKey(block))
                    {
                        BlockInvPanels.Add(block, new List <List <IMyTextPanel> >());
                        BlockInvPanels[block].Add(new List <IMyTextPanel>());
                        BlockInvContents.Add(block, EvaluateInvOwner(block));
                    }

                    BlockInvPanels[block][0].Add(panel);
                }
                else
                {
                    panel.WriteText(CannotFindInvMessage);
                }
            }

            //sort them
            List <IMyTerminalBlock> keys = new List <IMyTerminalBlock>(BlockInvPanels.Keys);

            for (int i = 0; i < keys.Count; i++)
            {
                var key   = keys[i];
                var value = BlockInvPanels[key][0];

                SortedDictionary <int, List <IMyTextPanel> > sortedDict = new SortedDictionary <int, List <IMyTextPanel> >();

                for (int j = 0; j < value.Count; j++)
                {
                    IMyTextPanel panel = value[j];

                    if (!panel.IsFunctional || !panel.IsWorking)
                    {
                        continue;
                    }

                    string[] nameParts  = panel.CustomName.Trim().Split(' ');
                    string[] titleParts = panel.GetPublicTitle().Trim().Split(' ');

                    string indexPart = "";

                    int index;
                    int test;

                    if (nameParts.Length >= 2 && panel.CustomName.StartsWith(BlockInvPanelsPrefix))
                    {
                        // workaround for stupid people that cant follow instructions properly
                        if (nameParts[1].Length < 2)
                        {
                            if (nameParts.Length >= 3 && nameParts[1].Equals("#") && int.TryParse(nameParts[2], out test))
                            {
                                indexPart = nameParts[2];
                            }
                            else
                            {
                                continue;
                            }
                        }
                        else
                        {
                            indexPart = nameParts[1].Substring(1);
                        }

                        if (nameParts[1].StartsWith("#") && int.TryParse(indexPart, out index) && index >= 0)
                        {
                            if (!sortedDict.ContainsKey(index))
                            {
                                sortedDict.Add(index, new List <IMyTextPanel>());
                                DebugString.AppendLine(string.Format("[Name]BIP New list at index: {0}", index));
                            }
                            sortedDict[index].Add(panel);
                            DebugString.AppendLine(string.Format("[Name]BIP Add panel at index: {0}", index));
                        }
                    }
                    else if (titleParts.Length >= 2 && panel.GetPublicTitle().StartsWith(BlockInvPanelsPrefix))
                    {
                        DebugString.AppendLine(string.Format("[Title]BIP trying to add panel {0}", panel.CustomName));
                        // workaround for stupid people that cant follow instructions properly
                        if (titleParts[1].Length < 2)
                        {
                            if (titleParts.Length >= 3 && titleParts[1].Equals("#") && int.TryParse(titleParts[2], out test))
                            {
                                indexPart = titleParts[2];
                            }
                            else
                            {
                                continue;
                            }
                        }
                        else
                        {
                            indexPart = titleParts[1].Substring(1);
                        }

                        if (titleParts[1].StartsWith("#") && int.TryParse(indexPart, out index) && index >= 0)
                        {
                            if (!sortedDict.ContainsKey(index))
                            {
                                sortedDict.Add(index, new List <IMyTextPanel>());
                                DebugString.AppendLine(string.Format("[Title]BIP New list at index: {0}", index));
                            }
                            sortedDict[index].Add(panel);
                            DebugString.AppendLine(string.Format("[Title]BIP Add panel at index: {0}", index));
                        }
                    }
                }

                BlockInvPanels[key] = new List <List <IMyTextPanel> >(sortedDict.Values);
            }
        }
Ejemplo n.º 12
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();
        }
Ejemplo n.º 13
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();
        }