コード例 #1
0
        static void Postfix(Pilot ___pilot, GameObject ___cantBuyMRBOverlay, HBSTooltip ___cantBuyToolTip,
                            LocalizableText ___costText, UIColorRefTracker ___costTextColor)
        {
            if (ModState.SimGameState == null)
            {
                return;                                // Only patch if we're in SimGame
            }
            Mod.Log.Debug?.Write($"Refreshing availability for pilot: {___pilot.Name}");

            // TODO: This may need to be improved, as it's used inside a loop. Maybe write to company stats?
            CrewDetails details = ModState.GetCrewDetails(___pilot.pilotDef);

            Mod.Log.Debug?.Write($"  -- pilot requires: {details.Size} berths");

            int usedBerths      = CrewHelper.UsedBerths(ModState.SimGameState.PilotRoster);
            int availableBerths = ModState.SimGameState.GetMaxMechWarriors() - usedBerths;

            Mod.Log.Debug?.Write($"AvailableBerths: {availableBerths} = max: {ModState.SimGameState.GetMaxMechWarriors()} - used: {usedBerths}");

            // Check berths limitations
            if (details.Size > availableBerths)
            {
                Mod.Log.Info?.Write($"Pilot {___pilot.Name} cannot be hired, not enough berths (needs {details.Size})");

                ___cantBuyMRBOverlay.SetActive(true);

                HBSTooltipStateData tooltipStateData = new HBSTooltipStateData();
                tooltipStateData.SetContextString($"DM.BaseDescriptionDefs[{ModConsts.Tooltip_NotEnoughBerths}]");
                ___cantBuyToolTip.SetDefaultStateData(tooltipStateData);
            }

            // Check type limitations
            if (!CrewHelper.CanHireMoreCrewOfType(details))
            {
                Mod.Log.Info?.Write($"Pilot {___pilot.Name} cannot be hired, too many of type already employed.");

                ___cantBuyMRBOverlay.SetActive(true);

                HBSTooltipStateData tooltipStateData = new HBSTooltipStateData();
                tooltipStateData.SetContextString($"DM.BaseDescriptionDefs[{ModConsts.Tooltip_TooManyOfType}]");
                ___cantBuyToolTip.SetDefaultStateData(tooltipStateData);
            }
            else
            {
                Mod.Log.Debug?.Write($"Pilot {___pilot.Name} can be hired, no limiations on max.");
            }

            // Set the prices
            //int purchaseCostAfterReputationModifier = ModState.SimGameState.CurSystem.GetPurchaseCostAfterReputationModifier(
            //    ModState.SimGameState.GetMechWarriorHiringCost(___pilot.pilotDef)
            //    );
            // TODO: Apply system cost multiplier
            // Hiring cost is influenced by:
            //  - current morale rating
            //  - any faction alignment for units
            //  - any reputation modifiers

            ___costText.SetText(SimGameState.GetCBillString(details.HiringBonus));

            UIColor costColor = UIColor.Red;

            if (details.HiringBonus <= ModState.SimGameState.Funds)
            {
                costColor = UIColor.White;
            }
            ___costTextColor.SetUIColor(costColor);
        }
コード例 #2
0
        private static void TabPressed(TabInfo settingsTab)
        {
            Control.LogDebug($"PRESSED [{settingsTab.Caption}]");
            foreach (var buttonInfo in buttons)
            {
                buttonInfo.go.SetActive(false);
            }

            current_tab = settingsTab;

            if (settingsTab?.Buttons == null || settingsTab.Buttons.Length == 0)
            {
                return;
            }

            for (int i = 0; i < 14 && i < settingsTab.Buttons.Length; i++)
            {
                Control.LogDebug($"- button {i}");

                var bdef   = settingsTab.Buttons[i];
                var button = buttons[i];
                if (!string.IsNullOrEmpty(bdef.Text))
                {
                    Control.LogDebug($"-- set text");
                    button.text.text = bdef.Text;
                    button.text.RefreshText();
                    button.go_text.SetActive(true);
                }
                else
                {
                    button.go_text.SetActive(false);
                }


                if (!string.IsNullOrEmpty(bdef.Icon))
                {
                    Control.LogDebug($"-- set icon");
                    button.icon.vectorGraphics = icon_cache.GetAsset(bdef.Icon);
                    button.go_icon.SetActive(true);
                    if (button.icon.vectorGraphics == null)
                    {
                        Control.LogError($"Icon {bdef.Icon} not found, replacing with ???");
                        button.text.text = "???";
                        button.text.RefreshText();
                        button.go_text.SetActive(true);
                    }
                }
                else
                {
                    button.go_icon.SetActive(false);
                }

                if (!string.IsNullOrEmpty(bdef.Tag))
                {
                    Control.LogDebug($"- set tag");
                    button.tag.text = bdef.Tag;
                    button.tag.RefreshText();
                    button.go_tag.SetActive(true);
                }
                else
                {
                    button.go_tag.SetActive(false);
                }

                if (!string.IsNullOrEmpty(bdef.Tooltip))
                {
                    var state = new HBSTooltipStateData();
                    state.SetString(bdef.Tooltip);

                    button.tooltip.SetDefaultStateData(state);
                }
                else
                {
                    var state = new HBSTooltipStateData();
                    state.SetDisabled();
                    button.tooltip.SetDefaultStateData(state);
                }

                button.go.SetActive(!bdef.Debug || Control.Settings.ShowDebugButtons);
            }
            inv_helper.filterRadioSet.Value.Reset();
            FilterPressed(0);
        }