Example #1
0
 private static void ReSelect(SG_Shop_Screen __instance)
 {
     //Log($"attempting to select index {m_selectedIdx}");
     if (m_selectedIdx > -1)
     {
         List <InventoryItemElement> list = GetActiveItems(__instance);
         if (list.Count > 0)
         {
             if (m_selectedIdx > list.Count - 1)
             {
                 m_selectedIdx = list.Count - 1;
             }
             if (m_selectedIdx > -1)
             {
                 //Log($"selecting item at index {m_selectedIdx}");
                 InventoryItemElement item = list[m_selectedIdx];
                 if (item != null)
                 {
                     if (item.gameObject.activeSelf)
                     {
                         item.buttonElement.ForceRadioSetSelection();
                     }
                     __instance.OnItemSelected(item);
                 }
             }
         }
     }
 }
            public static void Prefix(SG_Shop_Screen __instance, StarSystem ___theSystem, ShopDefItem itemDef, Shop shop, //removed ref from shopdefitem?
                                      IMechLabDropTarget targetWidget, bool isSelling = false, bool isBulkAdd = false)
            {
                if (GlobalVars.sim == null)
                {
                    return;
                }
                if (!isSelling)
                {
                    return;
                }
                var curPilots = new List <string> {
                    GlobalVars.sim.Commander.FetchGUID()
                };

                foreach (var p in GlobalVars.sim.PilotRoster)
                {
                    SpecHolder.HolderInstance.AddToMaps(p);
                    curPilots.Add(p.FetchGUID());
                }

                var    sellBonus = 1f;
                string shopOwner;

                if (shop.ThisShopType == Shop.ShopType.BlackMarket)
                {
                    shopOwner = FactionEnumeration.GetAuriganPiratesFactionValue().Name;
                    ModInit.modLog.LogMessage($"System: {___theSystem.Name}. shopOwner: {shopOwner}");
                }
                else
                {
                    shopOwner = sim.CurSystem.Def.OwnerValue.Name;
                    //shopOwner = Traverse.Create(shop).Field("system").GetValue<StarSystem>().Def.OwnerValue.Name;
                    ModInit.modLog.LogMessage($"System: {___theSystem.Name}. shopOwner: {shopOwner}");
                }

                foreach (var pKey in curPilots)
                {
                    if (SpecHolder.HolderInstance.OpForSpecMap.ContainsKey(pKey))
                    {
                        foreach (var spec in SpecHolder.HolderInstance.OpForSpecMap[pKey])
                        {
                            var opSpec =
                                SpecManager.ManagerInstance.OpForSpecList.FirstOrDefault(x => x.OpForSpecID == spec);
                            if (opSpec != null && opSpec.storeBonus.ContainsKey(shopOwner))
                            {
                                sellBonus += opSpec.storeBonus[shopOwner];
                                ModInit.modLog.LogMessage($"Current sell multiplier from specs: {sellBonus}");
                            }
                        }
                    }
                }

                ModInit.modLog.LogMessage($"Total sell multiplier from specs: {sellBonus}");
                ModInit.modLog.LogMessage($"Original sell price: {itemDef.SellCost}");
                var cost = itemDef.SellCost * sellBonus;

                ModInit.modLog.LogMessage($"Final sell price: {cost}");
                itemDef.SellCost = Mathf.RoundToInt(cost);
            }
Example #3
0
        public static bool FixGetMechdef(ref ShopDefItem itemDef, Shop shop, bool isBulkAdd, bool isSelling, IMechLabDropTarget targetWidget,
                                         MechLabInventoryWidget_ListView ___inventoryWidget, bool ___isInBuyingState, SimGameState ___simState,
                                         SG_Shop_Screen __instance)
        {
            if (itemDef.Type == ShopItemType.Mech && !___isInBuyingState)
            {
                var dataManager = ___simState.DataManager;

                string guid8 = itemDef.GUID;
                if (dataManager.ChassisDefs.Exists(guid8))
                {
                    ChassisDef chassisDef = dataManager.ChassisDefs.Get(guid8);
                    string     newGUID    = ___simState.GenerateSimGameUID();
                    var        id         = ChassisHandler.GetMDefFromCDef(guid8);
                    MechDef    stockMech  = dataManager.MechDefs.Get(id);
                    MechDef    mechDef3   = new MechDef(chassisDef, newGUID, stockMech);
                    mechDef3.Refresh();
                    if (mechDef3 != null)
                    {
                        InventoryDataObject_ShopFullMech inventoryDataObject_ShopFullMech2 = new InventoryDataObject_ShopFullMech();
                        inventoryDataObject_ShopFullMech2.Init(mechDef3, itemDef, shop, ___simState, dataManager,
                                                               targetWidget, itemDef.Count, isSelling, new UnityAction <InventoryItemElement>(__instance.OnItemSelected));
                        ___inventoryWidget.AddItemToInventory(inventoryDataObject_ShopFullMech2, isBulkAdd);
                        inventoryDataObject_ShopFullMech2.SetItemDraggable(false);
                    }
                }
                return(false);
            }

            return(true);
        }
Example #4
0
 public static void Prefix(SG_Shop_Screen __instance, InventoryItemElement item)
 {
     if (m_needSaveSelected)
     {
         m_selectedIdx = GetActiveItems(__instance).IndexOf(item);
         //Log($"saving index {m_selectedIdx}");
     }
 }
        public static void OnlySortAtEnd(SG_Shop_Screen __instance)
        {
            LogDebug("ShopTabLagFix: OnlySortAtEnd");
            var lv = __instance.inventoryWidget.ListView;

            //These don't actually seem to be needed, but keeping them just in case.
            lv.Sort();
            lv.Refresh();
        }
Example #6
0
        public BuyHelper(SG_Shop_Screen shopScreen, InventoryDataObject_SHOP selectedController, SimGameState simGameState)
        {
            this.shopScreen   = shopScreen;
            this.simGameState = simGameState;
            shopIDO           = selectedController;

            Traverse traverse = Traverse.Create(shopScreen).Field("inventoryWidget");

            inventoryWidget = (MechLabInventoryWidget_ListView)traverse.GetValue();
        }
Example #7
0
 static bool Prefix(SG_Shop_Screen __instance, SG_Stores_StoreImagePanel ___StoreImagePanel, StarSystem ___theSystem)
 {
     try {
         ___StoreImagePanel.FillInData(SG_Shop_Screen.StoreType.FactionStore, ___theSystem.Owner);
         return(false);
     }
     catch (Exception e) {
         PersistentMapClient.Logger.LogError(e);
         return(true);
     }
 }
Example #8
0
 static void Prefix(SG_Shop_Screen __instance, SG_Shop_Screen.StoreType newType, Shop.ShopType ___shopType, StarSystem ___theSystem, SimGameState ___simState)
 {
     try {
         if (newType == SG_Shop_Screen.StoreType.FactionStore && ___simState.IsFactionAlly(___theSystem.Owner, null))
         {
             ___theSystem.FactionShop.RefreshShop();
         }
     }
     catch (Exception e) {
         PersistentMapClient.Logger.LogError(e);
     }
 }
        private static void SetupButtons(SG_Shop_Screen shop_screen)
        {
            try
            {
                Control.LogDebug(DInfo.ShopInterface, "- First Time enter. Start to setup");
                ShopScreen = shop_screen;
                ShopHelper = new ShopScreenHelper(ShopScreen);
                Buttons    = new Dictionary <string, StoreButton>();


                var store_button = ShopHelper.SystemStoreButtonHoldingObject;
                var radio_set    = ShopHelper.SystemStoreButtonHoldingObject.transform.parent.GetComponent <HBSRadioSet>();

                Control.LogDebug(DInfo.ShopInterface, "-- Create buttons");
                foreach (var shop in Control.Shops.OrderBy(i => i.SortOrder))
                {
                    Control.LogDebug(DInfo.ShopInterface, $"--- {shop.Name}");
                    var button = new StoreButton(store_button, shop);
                    Buttons.Add(shop.Name, button);
                }

                Control.LogDebug(DInfo.ShopInterface, "-- Hide original buttons");
                ShopHelper.SystemStoreButtonHoldingObject.SetActive(false);
                ShopHelper.FactionStoreButtonHoldingObject.SetActive(false);
                ShopHelper.BlackMarketStoreButtonHoldingObject.SetActive(false);

                Control.LogDebug(DInfo.ShopInterface, "-- Setup radio set");
                radio_set.ClearRadioButtons();

                foreach (var pair in Buttons)
                {
                    radio_set.AddButtonToRadioSet(pair.Value.Button);
                }

                radio_set.defaultButton = Buttons.Values.First().Button;

                Control.LogDebug(DInfo.ShopInterface, "-- Replace Buy/Sell buttons");

                ShopHelper.BuyTabButton.OnClicked.RemoveAllListeners();
                ShopHelper.SellTabButton.OnClicked.RemoveAllListeners();
                ShopHelper.BuyButton.OnClicked.RemoveAllListeners();

                ShopHelper.BuyTabButton.OnClicked.AddListener(OnBuyTabPress);
                ShopHelper.SellTabButton.OnClicked.AddListener(OnSellTabPress);
                ShopHelper.BuyButton.OnClicked.AddListener(OnBuySellPress);
            }
            catch (Exception e)
            {
                Control.LogError(e);
            }
            Control.LogDebug(DInfo.ShopInterface, "-- done!");
        }
Example #10
0
 static void Postfix(SG_Shop_Screen __instance, StarSystem ___theSystem, SimGameState ___simState, HBSDOTweenStoreTypeToggle ___FactionStoreButton, GameObject ___LowRepFactionOverlay, GameObject ___SystemStoreButtonHoldingObject, GameObject ___FactionStoreButtonHoldingObject)
 {
     try {
         if (___simState.IsFactionAlly(___theSystem.Owner, null))
         {
             ___FactionStoreButton.FillInByFaction(___simState, ___theSystem.Owner);
             ___SystemStoreButtonHoldingObject.SetActive(true);
             ___FactionStoreButtonHoldingObject.SetActive(true);
             ___FactionStoreButton.SetState(ButtonState.Enabled, false);
             ___LowRepFactionOverlay.SetActive(false);
         }
     }
     catch (Exception e) {
         PersistentMapClient.Logger.LogError(e);
     }
 }
        public static void ShowShopInfo(SG_Shop_Screen __instance)
        {
            void show_inventory(Shop shop)
            {
                Control.Logger.LogDebug(
                    $"{shop.ThisShopType}: IsEmpty:{shop.IsEmpty} Count:{shop.ActiveInventory.Count}");
                if (shop.ActiveInventory != null)
                {
                    foreach (var shopDefItem in shop.ActiveInventory)
                    {
                        Control.Logger.LogDebug($"-- : {shopDefItem.ID} {shopDefItem.Type} {shopDefItem.Count}");
                    }
                }
            }

            var system = UnityGameInstance.BattleTechGame.Simulation.CurSystem;

            Control.Logger.LogDebug($"BeginShop for {system.Name}");
            show_inventory(system.SystemShop);
            show_inventory(system.FactionShop);
            show_inventory(system.BlackMarketShop);
        }
Example #12
0
        public static bool BeginShop(SG_Shop_Screen __instance)
        {
            UIControler.InitShopWindow(__instance);

            return(false);
        }
Example #13
0
 public static void Postfix(SG_Shop_Screen __instance)
 {
     ScrollToTop(Traverse.Create(__instance).Field("inventoryWidget").GetValue <MechLabInventoryWidget>());
 }
Example #14
0
        public static bool Shop_Screen_ReceiveButtonPress_Prefix(SG_Shop_Screen __instance, string button,
                                                                 InventoryDataObject_SHOP ___selectedController, bool ___isInBuyingState, SimGameState ___simState)
        {
            Mod.Log.Debug($"SG_S_S:RBP entered with button:({button})");

            State.Reset();
            if (button != "Capitalism" || ___selectedController == null)
            {
                return(true);
            }
            else
            {
                int cBillValue = ___selectedController.GetCBillValue();
                if (___isInBuyingState)
                {
                    Mod.Log.Debug($"SG_S_S:RBP - processing a purchase.");

                    if (___simState.InMechLabStore() &&
                        (___selectedController.GetItemType() == MechLabDraggableItemType.StorePart ||
                         ___selectedController.GetItemType() == MechLabDraggableItemType.SalvagePart))
                    {
                        // TODO: Can we handle this better than HBS does?
                        return(false);
                    }
                    Shop shop  = ___selectedController.GetShop();
                    int  price = shop.GetPrice(___selectedController.shopDefItem, Shop.PurchaseType.Normal, shop.ThisShopType);
                    if (___selectedController.quantity > 1 || ___selectedController.shopDefItem.IsInfinite)
                    {
                        State.StoreIsBuying = true;

                        if (___selectedController.shopDefItem.IsInfinite)
                        {
                            ___selectedController.quantity = 99;
                        }
                        BuyHelper buyHelper = new BuyHelper(__instance, ___selectedController, ___simState);

                        int maxCanPurchase = (int)Math.Floor(___simState.Funds / (double)price);
                        Mod.Log.Debug($"SG_S_S:RBP - maxCanPurchase:{maxCanPurchase} = funds:{___simState.Funds} / price:{price}.");
                        int popupQuantity = maxCanPurchase < ___selectedController.quantity ? maxCanPurchase : ___selectedController.quantity;
                        Mod.Log.Debug($"SG_S_S:RBP - maxCanPurchase:{maxCanPurchase} controllerQuantity:{___selectedController.quantity} -> popupQuantity:{popupQuantity}.");

                        SG_Stores_MultiPurchasePopup orCreatePopupModule =
                            LazySingletonBehavior <UIManager> .Instance.GetOrCreatePopupModule <SG_Stores_MultiPurchasePopup>(string.Empty);

                        orCreatePopupModule.SetData(___simState, ___selectedController.shopDefItem,
                                                    ___selectedController.GetName(), popupQuantity, price, buyHelper.BuyMultipleItems);
                    }
                    else
                    {
                        GenericPopupBuilder.Create("Confirm?", Strings.T("Purchase for {0}?", SimGameState.GetCBillString(price)))
                        .AddButton("Cancel")
                        .AddButton("Accept", __instance.BuyCurrentSelection)
                        .CancelOnEscape()
                        .AddFader(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill)
                        .Render();
                    }
                }
                else
                {
                    Mod.Log.Debug($"SG_S_S:RBP - processing a sale.");
                    State.StoreIsSelling = true;
                    int num = cBillValue;
                    if (___selectedController.quantity > 1)
                    {
                        SG_Stores_MultiPurchasePopup orCreatePopupModule =
                            LazySingletonBehavior <UIManager> .Instance.GetOrCreatePopupModule <SG_Stores_MultiPurchasePopup>(string.Empty);

                        orCreatePopupModule.SetData(___simState, ___selectedController.shopDefItem,
                                                    ___selectedController.GetName(), ___selectedController.quantity, num, __instance.SoldMultipleItems);
                    }
                    else if (num >= ___simState.Constants.Finances.ShopWarnBeforeSellingPriceMinimum)
                    {
                        GenericPopupBuilder.Create("Confirm?", Strings.T("Sell for {0}?", SimGameState.GetCBillString(num)))
                        .AddButton("Cancel")
                        .AddButton("Accept", __instance.SellCurrentSelection)
                        .CancelOnEscape()
                        .AddFader(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill)
                        .Render();
                    }
                    else
                    {
                        // Sell a single instance
                        __instance.SellCurrentSelection();
                    }
                }
                return(false);
            }
        }
Example #15
0
            static bool Prefix(
                string button,
                SG_Shop_Screen __instance)
            {
                shopScreen = __instance;
                var selectedController          = Traverse.Create(shopScreen).Field("selectedController").GetValue <InventoryDataObject_BASE>();
                var selectedControllerIsPresent = selectedController != null;
                var isBuySellButton             = button == "Capitalism";

                if (!isBuySellButton || !selectedControllerIsPresent)
                {
                    Logger.Debug($"buysellbutton: {isBuySellButton}\nselectedController: {selectedControllerIsPresent}");
                    ResetVariables();
                    return(true);
                }
                var simGameState = Traverse.Create(shopScreen).Field("simState").GetValue <SimGameState>();
                var isTraveling  = simGameState.TravelState != SimGameTravelStatus.IN_SYSTEM;

                if (isTraveling)
                {
                    Logger.Debug("traveling, so block buy/sell");
                    ResetVariables();
                    return(false);
                }
                var shiftHeld        = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
                var ctrlHeld         = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);
                var ctrlAndShiftHeld = shiftHeld && ctrlHeld;

                Logger.Debug($"shift held: {shiftHeld}\nctrl held: {ctrlHeld}\nctrlshift held: {ctrlAndShiftHeld}");
                var isInBuyingState       = Traverse.Create(shopScreen).Field("isInBuyingState").GetValue <bool>();
                var activeModifierAmounts = new List <int>
                {
                    ModSettings.CtrlAndShiftKeyCombinationModifierActive&& ctrlAndShiftHeld?ModSettings.CtrlAndShiftKeyCombinationAmount : 0,
                    ModSettings.CtrlKeyModifierActive&& ctrlHeld ? ModSettings.CtrlKeyAmount                                             : 0,
                    ModSettings.ShiftKeyModifierActive&& shiftHeld ? ModSettings.ShiftKeyAmount                                          : 0,
                    1 // no modifier keys
                };
                var maxModifierAmount = activeModifierAmounts.Max();
                // selectedController.RefreshInfo();
                var shopDefItem = selectedController.shopDefItem;
                var quantity    = shopDefItem.IsInfinite ? BigNumberForApproxInfinity : selectedController.quantity;

                Logger.Debug($"raw count: {selectedController.quantity}");
                Logger.Debug($"count: {quantity}");
                var numberToTrade = new List <int> {
                    maxModifierAmount, quantity
                }.Min();

                Logger.Debug($"how many? {numberToTrade}");
                numToBuyOrSell = numberToTrade;


                var minimumThreshold = simGameState.Constants.Finances.ShopWarnBeforeSellingPriceMinimum;

                activeModifierAmounts.ForEach(delegate(int amount) { Logger.Debug($"{amount}"); });
                Logger.Debug($"max: {numToBuyOrSell}");
                Logger.Debug($"threshold: {minimumThreshold}");

                if (isInBuyingState)
                {
                    var cbillValue = simGameState.CurSystem.Shop.GetPrice(shopDefItem, Shop.PurchaseType.Normal);
                    var cbillTotal = cbillValue * numToBuyOrSell;
                    Logger.Debug($"item value: {cbillValue}");
                    Logger.Debug($"item total: {cbillTotal}");
                    if (cbillTotal > minimumThreshold && ModSettings.WarnWhenBuyingAbovePriceMinimum)
                    {
                        GenericPopupBuilder.
                        Create("Confirm?", $"Purchase {numToBuyOrSell} for {SimGameState.GetCBillString(cbillTotal)}?").
                        AddButton("Cancel", null, true, (PlayerAction)null).
                        AddButton("Accept", (Action)BuyCurrent, true, (PlayerAction)null).
                        CancelOnEscape().
                        AddFader(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill, 0.0f, true).
                        Render();
                    }
                    else
                    {
                        BuyCurrent();
                    }
                    return(false);
                }
                else
                {
                    var cbillValue = selectedController.GetCBillValue();
                    var cbillTotal = cbillValue * numToBuyOrSell;
                    Logger.Debug($"item value: {cbillValue}");
                    Logger.Debug($"item total: {cbillTotal}");
                    if (cbillTotal > minimumThreshold && ModSettings.WarnWhenSellingAbovePriceMinimum)
                    {
                        GenericPopupBuilder.
                        Create("Confirm?", $"Sell {numToBuyOrSell} for {SimGameState.GetCBillString(cbillTotal)}?").
                        AddButton("Cancel", (Action)null, true, (PlayerAction)null).
                        AddButton("Accept", (Action)SellCurrent, true, (PlayerAction)null).
                        CancelOnEscape().
                        AddFader(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill, 0.0f, true).
                        Render();
                    }
                    else
                    {
                        SellCurrent();
                    }
                    return(false);
                }
            }
Example #16
0
 private static void ResetVariables()
 {
     numToBuyOrSell = 0;
     shopScreen     = null; // clear ref for GC
 }
Example #17
0
 public static void Prefix(SG_Shop_Screen __instance)
 {
     m_needSaveSelected = false;
 }
        internal static void InitShopWindow(SG_Shop_Screen shop_screen)
        {
            Control.LogDebug(DInfo.ShopInterface, "Enter Shop Screen");
            if (shop_screen != ShopScreen)
            {
                SetupButtons(shop_screen);
            }

            StoreButton active = null;

            Control.LogDebug(DInfo.ShopInterface, "- SetupButtons");
            foreach (var button in Buttons.Values)
            {
                try
                {
                    var shop = button.Shop;
                    Control.LogDebug(DInfo.ShopInterface, $"-- [{shop.Name}]");
                    Control.LogDebug(DInfo.ShopInterface, $"--- Exists:{shop.Exists} CanUse:{shop.CanUse}");

                    if (shop.Exists)
                    {
                        button.ButtonHolder.SetActive(true);

                        if (shop is ISpriteIcon spr_icon)
                        {
                            Control.LogDebug(DInfo.ShopInterface, $"--- sprite image - set");
                            button.Button.SetImageAndText(spr_icon.Sprite, shop.TabText);
                            Control.LogDebug(DInfo.ShopInterface, $"--- set icon color to  r{shop.IconColor.r:0.00} g{shop.IconColor.g:0.00} b{shop.IconColor.b:0.00}");
                            button.Icon.color = shop.IconColor;
                        }
                        else if (shop is ITextIcon txt_icon)
                        {
                            var id = txt_icon.SpriteID;
                            Control.LogDebug(DInfo.ShopInterface, $"--- txt image - {id} - request");
                            Control.State.Sim.RequestItem <Sprite>(
                                id,
                                (sprite) =>
                            {
                                Control.LogDebug(DInfo.ShopInterface, $"--- button image {id} received ");
                                button.Button.SetImageAndText(sprite, shop.TabText);
                                Control.LogDebug(DInfo.ShopInterface, $"--- set icon color to  r{shop.IconColor.r:0.00} g{shop.IconColor.g:0.00} b{shop.IconColor.b:0.00}");
                                button.Icon.color = shop.IconColor;
                                Control.LogDebug(DInfo.ShopInterface, $"--- set");
                            },
                                BattleTechResourceType.Sprite
                                );
                        }

                        if (shop.CanUse)
                        {
                            button.Button.SetState(ButtonState.Enabled);
                            button.Overlay.SetActive(false);
                            if (active == null)
                            {
                                active = button;
                            }
                        }
                        else
                        {
                            button.Button.SetState(ButtonState.Disabled);
                            button.Overlay.SetActive(true);
                        }
                    }
                    else
                    {
                        button.ButtonHolder.SetActive(false);
                    }
                }
                catch (Exception e)
                {
                    Control.LogError(e);
                }
            }
            if (active != null)
            {
                active.Button.ForceRadioSetSelection();
                ActiveShop = active.Shop;
                ShopScreen.StartCoroutine(SwitchAtEndOfFrame());
            }
        }
Example #19
0
 public static List <InventoryItemElement> GetActiveItems(SG_Shop_Screen __instance)
 {
     return(Traverse.Create(__instance).Field("inventoryWidget").Field("localInventory").GetValue <List <InventoryItemElement> >().FindAll(i => i.isActiveAndEnabled));
 }
Example #20
0
 public static void Postfix(SG_Shop_Screen __instance)
 {
     ReSelect(__instance);
     m_needSaveSelected = true;
 }