Ejemplo n.º 1
0
 public static void OnNameInputEndEdit_Postfix(UIPlanetDetail __instance)
 {
     if (SimulatedWorld.Initialized && !FactoryManager.IsIncomingRequest)
     {
         if (__instance.planet != null && !string.IsNullOrEmpty(__instance.planet.overrideName))
         {
             // Send packet with new planet name
             LocalPlayer.SendPacket(new NameInputPacket(__instance.planet.overrideName, FactoryManager.STAR_NONE, __instance.planet.id, LocalPlayer.PlayerId));
         }
     }
 }
Ejemplo n.º 2
0
 public static void OnNameInputEndEdit_Postfix(UIPlanetDetail __instance)
 {
     if (Multiplayer.IsActive && !Multiplayer.Session.Factories.IsIncomingRequest.Value)
     {
         if (__instance.planet != null && !string.IsNullOrEmpty(__instance.planet.overrideName))
         {
             // Send packet with new planet name
             Multiplayer.Session.Network.SendPacket(new NameInputPacket(__instance.planet.overrideName, NebulaModAPI.STAR_NONE, __instance.planet.id, Multiplayer.Session.LocalPlayer.Id));
         }
     }
 }
Ejemplo n.º 3
0
        public static bool _OnUpdate_Prefix(UIPlanetDetail __instance)
        {
            if (UIRoot.instance.galaxySelect == null || UIRoot.instance.galaxySelect.starmap == null || (Multiplayer.Session != null && !Multiplayer.Session.IsInLobby) || Multiplayer.Session == null)
            {
                return(true);
            }

            if (Time.frameCount % 30 == 0)
            {
                __instance.RefreshDynamicProperties();
            }
            __instance.trslBg.SetActive(true);
            __instance.imgBg.SetActive(true);

            return(false);
        }
Ejemplo n.º 4
0
        public static void UIPlanetDetail_Postfix(UIPlanetDetail __instance)
        {
            // Check if current viewmode is Globe, if not hide objects and return.
            bool active = UIGame.viewMode == EViewMode.Globe;

            foreach (GameObject existingGO in createdObjects)
            {
                existingGO.SetActive(active);
            }
            if (!active)
            {
                return;
            }

            GameObject go = __instance.gameObject;

            /**
             * Structure of gameobjects is (from trial and error and a lot of Debug.Log):
             * planet-detail-ui:
             *  line
             *  res-entry [Contains the UIResAmountEntry component]:
             *   icon [Contains UIButton component, UI.Image]
             *   value-text
             *  res-entry(clone):
             *   icon
             *   value-text
             *
             */

            Transform resGroup = go.transform.Find("res-group");

            foreach (Transform child in resGroup)
            {
                // Create buttons for resources that exist and are selectable, that don't already have buttons.
                if (child.gameObject.name.Contains("res-entry") && child.GetComponent <UIResAmountEntry>().refId != 0 && !buttonCreated[child.GetComponent <UIResAmountEntry>().refId] && child.GetComponent <UIResAmountEntry>().valueString.Trim() != "0")
                {
                    int       tempRefId     = (int)child.GetComponent <UIResAmountEntry>().refId; // ID of resource
                    Transform iconTransform = child.Find("icon");

                    GameObject toggleHighlightButton = GameObject.Instantiate <GameObject>(
                        original: iconTransform.gameObject,
                        position: new Vector3(child.position.x + 1.25f, child.position.y - 0.02f, child.position.z),
                        rotation: Quaternion.identity,
                        parent:   child.parent); // The child object (res-entry) actually moves each time the map is opened for some reason

                    GameObject showNearestVeinButton = GameObject.Instantiate <GameObject>(
                        original: iconTransform.gameObject,
                        position: new Vector3(child.position.x + 1f, child.position.y - 0.02f, child.position.z),
                        rotation: Quaternion.identity,
                        parent:   child.parent);

                    Image highlightImage = toggleHighlightButton.GetComponent <Image>();
                    highlightImage.sprite                  = spriteHighlight;
                    highlightImage.preserveAspect          = true;
                    highlightImage.rectTransform.sizeDelta = new Vector2(28, 14);
                    defaultHighlightButtonColor            = highlightImage.color; // Store the default color so we can switch back later

                    Image showNearestImage = showNearestVeinButton.GetComponent <Image>();
                    showNearestImage.sprite                  = spriteShowNearest;
                    showNearestImage.preserveAspect          = true;
                    showNearestImage.rectTransform.sizeDelta = new Vector2(28, 14);

                    UIButton uiButton1 = toggleHighlightButton.GetComponent <UIButton>();

                    uiButton1.tips.tipTitle = "Highlight";
                    uiButton1.tips.tipText  = "Highlight veins of the type: " + (EVeinType)tempRefId + ".";

                    UIButton uiButton2 = showNearestVeinButton.GetComponent <UIButton>();
                    uiButton2.tips.tipTitle = "Show nearest vein";
                    uiButton2.tips.tipText  = "Move camera to the " + (EVeinType)tempRefId + " nearest the player";

                    uiButton1.onClick += (id) => { ToggleVeinHeighlight(tempRefId, ref toggleHighlightButton); };
                    // uiButton1.onRightClick += (id) => { DebugStuff(tempRefId); };
                    toggleHighlightButton.name = "net-powana-toggle-highlight";

                    uiButton2.onClick         += (id) => { ShowNearestVein(tempRefId, ref showNearestVeinButton); };
                    showNearestVeinButton.name = "net-powana-show-nearest";

                    // todo, turn off highlights when exiting globemap?
                    buttonCreated[tempRefId] = true;

                    createdObjects.Add(toggleHighlightButton);
                    createdObjects.Add(showNearestVeinButton);
                    // Debug.Log("Created buttons for " + (EVeinType)child.GetComponent<UIResAmountEntry>().refId + " Amount: " + child.GetComponent<UIResAmountEntry>().valueString);
                }
            }
        }
Ejemplo n.º 5
0
        private static bool OnPlanetDataSet(ref UIPlanetDetail __instance,
                                            ref UIResAmountEntry ___tipEntry,
                                            ref Text ___nameText,
                                            ref Text ___typeText,
                                            ref Text ___orbitRadiusValueText,
                                            ref Text ___orbitRadiusValueTextEx,
                                            ref Text ___orbitPeriodValueText,
                                            ref Text ___rotationPeriodValueText,
                                            ref Text ___inclinationValueText,
                                            ref Text ___obliquityValueText,
                                            ref Sprite ___unknownResIcon,
                                            ref Sprite ___sprite6,
                                            ref Sprite ___sprite8,
                                            ref Sprite ___sprite9)
        {
            var getEntry = Traverse.Create(__instance).Method("GetEntry");

            getEntry.GetValue <UIResAmountEntry>();
            for (var index = 0; index < __instance.entries.Count; ++index)
            {
                var entry = __instance.entries[index];
                entry.SetEmpty();
                __instance.pool.Add(entry);
            }

            __instance.entries.Clear();
            ___tipEntry = null;
            if (__instance.planet == null)
            {
                return(false);
            }
            var _observed = GameMain.history.universeObserveLevel >=
                            (__instance.planet != GameMain.localPlanet ? 2 : 1);

            ___nameText.text = __instance.planet.displayName;
            var empty = string.Empty;

            ___typeText.text = string.Format("{0} {1}", __instance.planet.typeString,
                                             "<color=\"#FD965EC0\">" + __instance.planet.singularityString + "</color>");
            ___orbitRadiusValueText.text   = __instance.planet.orbitRadius.ToString("0.00#") + " AU";
            ___orbitRadiusValueTextEx.text = __instance.planet.name;
            ___orbitPeriodValueText.text   =
                __instance.planet.orbitalPeriod.ToString("#,##0") + "空格秒".Translate();
            ___rotationPeriodValueText.text =
                __instance.planet.rotationPeriod.ToString("#,##0") + "空格秒".Translate();
            var num1 = Mathf.Abs(__instance.planet.orbitInclination);
            var num2 = (int)num1;
            var num3 = (int)((num1 - (double)num2) * 60.0);

            if (__instance.planet.orbitInclination < 0.0)
            {
                num2 = -num2;
            }
            var num4 = Mathf.Abs(__instance.planet.obliquity);
            var num5 = (int)num4;
            var num6 = (int)((num4 - (double)num5) * 60.0);

            if (__instance.planet.obliquity < 0.0)
            {
                num5 = -num5;
            }
            ___inclinationValueText.text = string.Format("{0}° {1}′", num2, num3);
            ___obliquityValueText.text   = string.Format("{0}° {1}′", num5, num6);
            var num7 = 0;

            if (__instance.planet.type != EPlanetType.Gas)
            {
                for (var index = 0; index < 6; ++index)
                {
                    var id        = index + 1;
                    var veinProto = LDB.veins.Select(id);
                    var itemProto = LDB.items.Select(veinProto.MiningItem);
                    if (veinProto != null && itemProto != null)
                    {
                        var entry = getEntry.GetValue <UIResAmountEntry>();
                        ;
                        __instance.entries.Add(entry);
                        entry.SetInfo(num7, itemProto.name, veinProto.iconSprite, veinProto.description, false, false,
                                      "                ");
                        entry.refId = id;
                        ++num7;
                    }
                }

                var    waterItemId = __instance.planet.waterItemId;
                Sprite icon        = null;
                var    str         = "无".Translate();
                if (waterItemId < 0)
                {
                    str = waterItemId != -1 ? "未知".Translate() : "熔岩".Translate();
                }
                var itemProto1 = LDB.items.Select(waterItemId);
                if (itemProto1 != null)
                {
                    icon = itemProto1.iconSprite;
                    str  = itemProto1.name;
                }

                var entry1 = getEntry.GetValue <UIResAmountEntry>();
                ;
                __instance.entries.Add(entry1);
                entry1.SetInfo(num7, "海洋类型".Translate(), icon,
                               itemProto1 == null ? string.Empty : itemProto1.description, false,
                               itemProto1 != null && waterItemId != 1000, string.Empty);
                entry1.valueString = str;
                var index1 = num7 + 1;
                var entry2 = getEntry.GetValue <UIResAmountEntry>();
                ;
                __instance.entries.Add(entry2);
                entry2.SetInfo(index1, "适建区域".Translate(), ___sprite6, string.Empty, false, false, "      %");
                if (__instance.planet.landPercentDirty)
                {
                    PlanetAlgorithm.CalcLandPercent(__instance.planet);
                    __instance.planet.landPercentDirty = false;
                }

                StringBuilderUtility.WritePositiveFloat(entry2.sb, 0, 5, __instance.planet.landPercent * 100f, 1);
                entry2.DisplayStringBuilder();
                var index2 = index1 + 1;
                var entry3 = getEntry.GetValue <UIResAmountEntry>();
                ;
                __instance.entries.Add(entry3);
                entry3.SetInfo(index2, "风能利用率".Translate(), ___sprite8, string.Empty, false,
                               __instance.planet.windStrength > 1.49899995326996, "    %");
                StringBuilderUtility.WriteUInt(entry3.sb, 0, 3,
                                               (uint)(__instance.planet.windStrength * 100.0 + 0.499900013208389));
                entry3.DisplayStringBuilder();
                var index3 = index2 + 1;
                var entry4 = getEntry.GetValue <UIResAmountEntry>();
                ;
                __instance.entries.Add(entry4);
                entry4.SetInfo(index3, "光能利用率".Translate(), ___sprite9, string.Empty, false,
                               __instance.planet.luminosity > 1.49899995326996, "    %");
                StringBuilderUtility.WriteUInt(entry4.sb, 0, 3,
                                               (uint)(__instance.planet.luminosity * 100.0 + 0.499900013208389));
                entry4.DisplayStringBuilder();
                num7 = index3 + 1;
                for (var index4 = 7; index4 < 15; ++index4)
                {
                    var id         = index4;
                    var veinProto  = LDB.veins.Select(id);
                    var itemProto2 = LDB.items.Select(veinProto.MiningItem);
                    if (veinProto != null && itemProto2 != null && __instance.planet.veinAmounts[id] > 0L)
                    {
                        var entry5 = getEntry.GetValue <UIResAmountEntry>();
                        ;
                        __instance.entries.Add(entry5);
                        entry5.SetInfo(num7, itemProto2.name, veinProto.iconSprite, veinProto.description, true, false,
                                       index4 != 7 ? "                " : "         /s");
                        entry5.refId = id;
                        ++num7;
                    }
                }

                if (!_observed)
                {
                    var entry5 = getEntry.GetValue <UIResAmountEntry>();
                    ;
                    __instance.entries.Add(entry5);
                    entry5.SetInfo(num7, string.Empty, null, string.Empty, false, false, string.Empty);
                    ___tipEntry = entry5;
                    ++num7;
                }
            }
            else
            {
                for (var index = 0; index < __instance.planet.gasItems.Length; ++index)
                {
                    var itemProto = LDB.items.Select(__instance.planet.gasItems[index]);
                    if (itemProto != null)
                    {
                        var entry = getEntry.GetValue <UIResAmountEntry>();
                        ;
                        __instance.entries.Add(entry);
                        if (_observed)
                        {
                            entry.SetInfo(num7, "可采集".Translate() + itemProto.name, itemProto.iconSprite,
                                          "环绕行星手动采集".Translate(), false, false, "        /s");
                            StringBuilderUtility.WritePositiveFloat(entry.sb, 0, 7, __instance.planet.gasSpeeds[index]);
                            entry.DisplayStringBuilder();
                        }
                        else
                        {
                            entry.SetInfo(num7, "未知".Translate(), ___unknownResIcon, "环绕行星手动采集".Translate(),
                                          false, false, "        /s");
                            entry.valueString = "未知".Translate();
                        }

                        entry.SetObserved(_observed);
                        ++num7;
                    }
                }
            }

            __instance.SetResCount(num7);
            __instance.RefreshDynamicProperties();
            return(false);
        }
Ejemplo n.º 6
0
 public static void UIPlanetDetail___OnOpen_Prefix(UIPlanetDetail __instance)
 {
 }