private void MessageRecieved(ushort arg1, byte[] arg2, ulong arg3, bool arg4)
        {
            Utils.Log("Server Message Recieved!");


            try
            {
                Message RecievedMessage = MyAPIGateway.Utilities.SerializeFromBinary <Message>(arg2);

                if (RecievedMessage == null)
                {
                    return;
                }


                switch (RecievedMessage.Type)
                {
                case MessageType.MarketOffersUpdate:
                    ModCore.MergeNewCollection(RecievedMessage.MarketOffers);
                    break;


                default:
                    Utils.Log($"Unkown message type! Is this mod up to date?");
                    return;
                }
            }
            catch (Exception ex)
            {
                Utils.Log($"Exception occured on server message deserialization! {ex.ToString()}");
                return;
            }
        }
예제 #2
0
        public static void CreateControls(IMyTerminalBlock block, List <IMyTerminalControl> controls)
        {
            if (block as IMyProjector == null || controlsCreated == true)
            {
                return;
            }



            controlsCreated = true;

            var controlList = new List <IMyTerminalControl>();

            MyAPIGateway.TerminalControls.GetControls <IMyProjector>(out controlList);
            controlList[9].Visible  = Block => HideControls(Block);
            controlList[10].Visible = Block => HideControls(Block);
            controlList[11].Visible = Block => HideControls(Block);
            controlList[8].Visible  = Block => HideControls(Block);

            controlList[29].Visible = Block => HideControls(Block);
            controlList[30].Visible = Block => HideControls(Block);
            controlList[31].Visible = Block => HideControls(Block);

            //controlList[28].Visible = Block => HideControls(Block);

            controlList[27].Visible = Block => HideControls(Block);
            controlList[26].Visible = Block => HideControls(Block);



            var SaleList = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlListbox, IMyProjector>("HangerStoreNext");

            SaleList.Title = MyStringId.GetOrCompute("Grids for sale: ");
            SaleList.SupportsMultipleBlocks = false;
            SaleList.VisibleRowsCount       = 12;
            SaleList.Multiselect            = false;


            SaleList.ListContent  = ModCore.GetForSaleGrids;
            SaleList.ItemSelected = ModCore.SetSelectedGrid;
            SaleList.Enabled      = Block => true;
            SaleList.Visible      = Block => ControlVisibility(Block);
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(SaleList);
            controls.Add(SaleList);



            var FilterList = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlCombobox, IMyProjector>("SortType");

            FilterList.Title = MyStringId.GetOrCompute("Sort by:");
            FilterList.SupportsMultipleBlocks = false;
            FilterList.Enabled = Block => true;
            FilterList.Visible = Block => ControlVisibility(Block);
            FilterList.Setter  = ModCore.FilterSet;
            FilterList.Getter  = ModCore.FilterGet;

            FilterList.ComboBoxContent = (list) =>
            {
                list.Add(new MyTerminalControlComboBoxItem()
                {
                    Key = (long)SortType.GridName, Value = MyStringId.GetOrCompute(SortType.GridName.ToString())
                });
                list.Add(new MyTerminalControlComboBoxItem()
                {
                    Key = (long)SortType.Price, Value = MyStringId.GetOrCompute(SortType.Price.ToString())
                });
                list.Add(new MyTerminalControlComboBoxItem()
                {
                    Key = (long)SortType.OwnerName, Value = MyStringId.GetOrCompute(SortType.OwnerName.ToString())
                });
                list.Add(new MyTerminalControlComboBoxItem()
                {
                    Key = (long)SortType.PCU, Value = MyStringId.GetOrCompute(SortType.PCU.ToString())
                });
                list.Add(new MyTerminalControlComboBoxItem()
                {
                    Key = (long)SortType.BlockCount, Value = MyStringId.GetOrCompute(SortType.BlockCount.ToString())
                });
                list.Add(new MyTerminalControlComboBoxItem()
                {
                    Key = (long)SortType.ServerOffers, Value = MyStringId.GetOrCompute(SortType.ServerOffers.ToString())
                });
            };
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(FilterList);
            controls.Add(FilterList);



            var PreviewButton = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyProjector>("PreviewButton");

            PreviewButton.Title   = MyStringId.GetOrCompute("Preview Selected Grid");
            PreviewButton.Tooltip = MyStringId.GetOrCompute("Previews the selected Grid");
            PreviewButton.SupportsMultipleBlocks = false;
            PreviewButton.Action  = Block => ModCore.PreviewSelectedGrid(Block);
            PreviewButton.Enabled = Block => ModCore.PreviewButtonEnabled(block);
            PreviewButton.Visible = Block => ControlVisibility(Block);

            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(PreviewButton);
            controls.Add(PreviewButton);



            var DetailsButton = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyProjector>("Ship Details");

            DetailsButton.Title   = MyStringId.GetOrCompute("Selected Grid Details");
            DetailsButton.Tooltip = MyStringId.GetOrCompute("Provides indepth ship details");
            DetailsButton.SupportsMultipleBlocks = false;
            DetailsButton.Action  = Block => ModCore.ShipDetails(block);
            DetailsButton.Enabled = Block => ModCore.PreviewButtonEnabled(block);
            DetailsButton.Visible = Block => ControlVisibility(Block);

            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(DetailsButton);
            controls.Add(DetailsButton);



            var PurchaseButton = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyProjector>("PurchaseButton");

            PurchaseButton.Title   = MyStringId.GetOrCompute("Purchase Selected Grid");
            PurchaseButton.Tooltip = MyStringId.GetOrCompute("Purchases the selected grid");
            PurchaseButton.SupportsMultipleBlocks = false;
            PurchaseButton.Action  = Block => ModCore.PurchaseSlectedGrid(Block);
            PurchaseButton.Enabled = Block => ModCore.PurchaseButtonVisibility(Block);
            PurchaseButton.Visible = Block => ControlVisibility(Block);
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(PurchaseButton);
            controls.Add(PurchaseButton);
        }
예제 #3
0
        public static void CreateControls(IMyTerminalBlock block, List <IMyTerminalControl> controls)
        {
            if (block as IMyProjector == null || controlsCreated == true)
            {
                return;
            }

            controlsCreated = true;

            var controlList = new List <IMyTerminalControl>();

            MyAPIGateway.TerminalControls.GetControls <IMyProjector>(out controlList);
            controlList[9].Visible  = Block => HideControls(Block);
            controlList[10].Visible = Block => HideControls(Block);
            controlList[11].Visible = Block => HideControls(Block);
            controlList[8].Visible  = Block => HideControls(Block);

            controlList[29].Visible = Block => HideControls(Block);
            controlList[30].Visible = Block => HideControls(Block);
            controlList[31].Visible = Block => HideControls(Block);

            //controlList[28].Visible = Block => HideControls(Block);

            controlList[27].Visible = Block => HideControls(Block);
            controlList[26].Visible = Block => HideControls(Block);



            var SaleList = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlListbox, IMyProjector>("HangerStoreNext");

            SaleList.Title = MyStringId.GetOrCompute("出售中的网格: ");
            SaleList.SupportsMultipleBlocks = false;
            SaleList.VisibleRowsCount       = 12;
            SaleList.Multiselect            = false;

            SaleList.ListContent  = ModCore.GetForSaleGrids;
            SaleList.ItemSelected = ModCore.SetSelectedGrid;
            SaleList.Enabled      = Block => true;
            SaleList.Visible      = Block => ControlVisibility(Block);
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(SaleList);
            controls.Add(SaleList);


            var PreviewButton = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyProjector>("PreviewButton");

            PreviewButton.Title   = MyStringId.GetOrCompute("预览所选网格");
            PreviewButton.Tooltip = MyStringId.GetOrCompute("预览所选网格");
            PreviewButton.SupportsMultipleBlocks = false;
            PreviewButton.Action  = Block => ModCore.PreviewSelectedGrid(Block);
            PreviewButton.Enabled = Block => ModCore.PreviewButtonVisibility(block);
            PreviewButton.Visible = Block => ControlVisibility(Block);

            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(PreviewButton);
            controls.Add(PreviewButton);



            var DetailsButton = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyProjector>("Ship Details");

            DetailsButton.Title   = MyStringId.GetOrCompute("所选网格详情");
            DetailsButton.Tooltip = MyStringId.GetOrCompute("深入提供飞船详情");
            DetailsButton.SupportsMultipleBlocks = false;
            DetailsButton.Action  = Block => ModCore.ShipDetails(block);
            DetailsButton.Enabled = Block => ModCore.PreviewButtonVisibility(block);
            DetailsButton.Visible = Block => ControlVisibility(Block);

            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(DetailsButton);
            controls.Add(DetailsButton);



            var PurchaseButton = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlButton, IMyProjector>("PurchaseButton");

            PurchaseButton.Title   = MyStringId.GetOrCompute("购买所选网格");
            PurchaseButton.Tooltip = MyStringId.GetOrCompute("购买所选网格");
            PurchaseButton.SupportsMultipleBlocks = false;

            PurchaseButton.Action = Block => ModCore.PurchaseSlectedGrid(Block);

            PurchaseButton.Enabled = Block => ModCore.PurchaseButtonVisibility(Block);
            PurchaseButton.Visible = Block => ControlVisibility(Block);
            MyAPIGateway.TerminalControls.AddControl <IMyProjector>(PurchaseButton);
            controls.Add(PurchaseButton);
        }
예제 #4
0
        private static void MessageHandler(byte[] bytes)
        {
            try
            {
                Debug.Write("Message Recieved!");

                Message RecievedMessage = MyAPIGateway.Utilities.SerializeFromBinary <Message>(bytes);
                //MyLog.Default.WriteLineAndConsole("Recieved Message from server: "+ RecievedMessage.Type.ToString());

                if (RecievedMessage.Type == MessageType.RequestAllItems)
                {
                    //ModCore.MarketGrids.Clear();

                    ModCore.MarketGrids = RecievedMessage.MarketBoxItmes;


                    //Do we need to update GUI?

                    //ModCore.UpdateGUI(ModCore.m_block);
                }
                else if (RecievedMessage.Type == MessageType.AddOne)
                {
                    ModCore.MarketGrids.Add(RecievedMessage.MarketBoxItmes[0]);
                }
                else if (RecievedMessage.Type == MessageType.RemoveOne)
                {
                    //MyLog.Default.WriteLineAndConsole("MessageType: RemoveOne");
                    MarketList list = ModCore.MarketGrids.First(x => x.Name == RecievedMessage.MarketBoxItmes[0].Name);

                    for (int i = 0; i < ModCore.MarketGrids.Count; i++)
                    {
                        if (ModCore.MarketGrids[i].Name == RecievedMessage.MarketBoxItmes[0].Name)
                        {
                            ModCore.MarketGrids.RemoveAt(i);
                            ModCore.RemovedMarketGrids = RecievedMessage.MarketBoxItmes[0];
                            MyLog.Default.WriteLineAndConsole("MessageType: RemovedOne " + ModCore.RemovedMarketGrids.Name);
                            break;
                        }
                    }

                    try
                    {
                        ModCore.m_block.RefreshCustomInfo();
                        ModCore.UpdateGUI(ModCore.m_block);
                    }
                    catch
                    {
                        //Experiement to see if this
                    }

                    //Remove frome list
                }
                else
                {
                    //Do nothing...
                }

                //Update GUI
                //ModCore.UpdateGUI();



                //MyLog.Default.WriteLineAndConsole("Message Recieved");


                //Array.Copy(bytes, 1, data, 0, data.Length);
            }
            catch (Exception ex)
            {
                //MyLog.Default.WriteLineAndConsole($"WTF is this shit " + ex);
            }
        }