Esempio n. 1
0
        public void RefreshSlotElement(MechLabItemSlotElement instance, MechLabPanel panel)
        {
            var weights = instance.ComponentRef?.Def?.GetComponent <Weights>();

            if (weights == null)
            {
                return;
            }

            var mechDef = panel.activeMechDef;

            if (mechDef == null)
            {
                return;
            }

            var tonnageSaved = CalculateWeightSavings(mechDef, weights);

            tonnageSaved -= CalculateEngineTonnageChanges(mechDef, weights);
            var adapter = new MechLabItemSlotElementAdapter(instance);

            if (!Mathf.Approximately(tonnageSaved, 0))
            {
                var sign = tonnageSaved > 0 ? "- " : "";
                adapter.bonusTextA.text = $"{sign}{tonnageSaved} ton";
            }
            else if (adapter.bonusTextA.text.EndsWith("ton"))
            {
                adapter.bonusTextA.text = instance.ComponentRef.Def.BonusValueA;
            }
        }
Esempio n. 2
0
        public void RefreshSlotElement(MechLabItemSlotElement instance, MechLabPanel panel = null)
        {
            var engineRef = instance.ComponentRef.GetEngineCoreRef();

            if (engineRef == null)
            {
                return;
            }

            var adapter = new MechLabItemSlotElementAdapter(instance);

            adapter.bonusTextA.text = engineRef.BonusValueA;
            adapter.bonusTextB.text = engineRef.BonusValueB;
        }
            internal void Show(DynamicSlots dynamicSlots)
            {
                var def  = dynamicSlots.Def;
                var @ref = new MechComponentRef(def.Description.Id, null, def.ComponentType, ChassisLocations.None)
                {
                    DataManager = def.DataManager
                };

                @ref.RefreshComponentDef();
                element.SetData(@ref, ChassisLocations.None, def.DataManager, null);
                var adapter = new MechLabItemSlotElementAdapter(element);

                if (dynamicSlots.NameText != null)
                {
                    adapter.nameText.text = dynamicSlots.NameText;
                }

                if (dynamicSlots.BonusAText == "")
                {
                    adapter.bonusTextA.gameObject.SetActive(false);
                }
                else if (dynamicSlots.BonusAText != null)
                {
                    adapter.bonusTextA.text = dynamicSlots.BonusAText;
                    adapter.bonusTextA.gameObject.SetActive(true);
                }

                if (dynamicSlots.BonusBText == "")
                {
                    adapter.bonusTextB.gameObject.SetActive(false);
                }
                else if (dynamicSlots.BonusBText != null)
                {
                    adapter.bonusTextB.text = dynamicSlots.BonusBText;
                    adapter.bonusTextB.gameObject.SetActive(true);
                }

                if (dynamicSlots.BackgroundColor != null)
                {
                    adapter.backgroundColor.SetUIColor(dynamicSlots.BackgroundColor.Value);
                }

                adapter.icon.gameObject.SetActive(dynamicSlots.ShowIcon);

                layout.SetActive(true);
                element.SetDraggable(false);
            }
        public void ModifySlotElement(MechLabItemSlotElement instance, MechLabPanel panel)
        {
            var weightSavings = instance.ComponentRef?.Def?.GetComponent <WeightSavings>();

            if (weightSavings == null)
            {
                return;
            }

            var mechDef = panel.activeMechDef;

            if (mechDef == null)
            {
                return;
            }

            var tonnageSaved = CalculateWeightSavings(weightSavings, mechDef);
            var adapter      = new MechLabItemSlotElementAdapter(instance);

            if (StringUtils.IsNullOrWhiteSpace(adapter.bonusTextA.text))
            {
                if (tonnageSaved > 0.1)
                {
                    adapter.bonusTextA.text = $"- {tonnageSaved} ton";
                }
            }

            if (StringUtils.IsNullOrWhiteSpace(adapter.bonusTextB.text))
            {
                if (weightSavings.RequiredSlots > 0)
                {
                    adapter.bonusTextB.text = $"req. {weightSavings.RequiredSlots} slots";
                }
            }

            adapter.bonusTextA.text = $"- {tonnageSaved} ton";
            adapter.bonusTextB.text = $"req. {weightSavings.RequiredSlots} slots";
        }