private void WindowFunc(int id)
        {
            GUILayout.BeginVertical(GUILayout.Width(550), GUILayout.Height(700));
            sv = GUILayout.BeginScrollView(sv, UnityEngine.GUI.skin.box);
            for (int veinGroupIndex = 1; veinGroupIndex < localPlanet.veinGroups.Length; veinGroupIndex++)
            {
                PlanetData.VeinGroup veinGroup = localPlanet.veinGroups[veinGroupIndex];
                int       veinProduct          = PlanetModelingManager.veinProducts[(int)veinGroup.type];
                ItemProto itemProto            = veinProduct != 0 ? LDB.items.Select(veinProduct) : null;
                Texture2D texture  = null;
                string    veinName = null;
                if (itemProto != null)
                {
                    texture  = itemProto.iconSprite.texture;
                    veinName = itemProto.name.Translate();
                }

                GUILayout.BeginHorizontal();
                GUILayout.Box(texture, VeinIconLayoutOptions);
                GUILayout.Box("Type " + veinGroup.type + "\n" + veinName);

                GUILayout.Label("Count " + veinGroup.count);
                GUILayout.Label("Amount " + veinGroup.amount);

                GUILayout.EndHorizontal();
            }
            GUILayout.EndScrollView();

            UnityEngine.GUI.DragWindow();
        }
        public void UpdatePos()
        {
            float   realRadius    = localPlanet.realRadius;
            Vector3 localPosition = GameCamera.main.transform.localPosition;
            Vector3 forward       = GameCamera.main.transform.forward;

            PlanetData.VeinGroup veinGroup  = localPlanet.veinGroups[veinGroupIndex];
            Vector3 veinGroupWorldPos       = veinGroup.pos.normalized * (realRadius + 2.5f);
            Vector3 cameraVeinGroupDistance = veinGroupWorldPos - localPosition;
            float   magnitude = cameraVeinGroupDistance.magnitude;
            float   num       = Vector3.Dot(forward, cameraVeinGroupDistance);

            if (magnitude < 1f || num < 1f || magnitude > 150)
            {
                Show = false;
                return;
            }

            Vector3 screenPoint = GameCamera.main.WorldToScreenPoint(veinGroupWorldPos);

            // Debug.Log("Screenpoint: " + screenPoint);

            //bool flag = UIRoot.ScreenPointIntoRect(screenPoint, rt, out Vector2 rectPoint);
            //bool flag = DSPExtensions.ScreenPointIntoRectSimple(screenPoint, out Vector2 rectPoint);
            screenPoint.y = Screen.height - screenPoint.y;

            bool flag = true;

            if (Mathf.Abs(screenPoint.x) > Screen.width || Mathf.Abs(screenPoint.y) > Screen.height ||
                screenPoint.x < -100 || screenPoint.y < -100)
            {
                flag = false;
            }

            Show = flag;

            //  Debug.Log("rectPoint: " + rectPoint);
            winRect.x  = Mathf.Round(screenPoint.x);
            winRect.y  = Mathf.Round(screenPoint.y);
            winRect.x += 10;
            winRect.y += 10;

            if (winRect.xMax > Screen.width)
            {
                winRect.x = Screen.width - winRect.width;
            }

            if (winRect.yMax > Screen.height)
            {
                winRect.y = Screen.height - winRect.height - 20;
            }

            winRect.x = Mathf.Max(0, winRect.x);
            winRect.y = Mathf.Max(0, winRect.y);

            winRect.x /= ScaleRatio;
            winRect.y /= ScaleRatio;
        }
            public static PlanetData.VeinGroup New(EVeinType vType, Vector3 worldPos)
            {
                PlanetData.VeinGroup veinGroup = new PlanetData.VeinGroup();
                veinGroup.count  = 0;
                veinGroup.pos    = worldPos;
                veinGroup.type   = vType;
                veinGroup.amount = 0;

                return(veinGroup);
            }
        /*
         * class PlanetDataExt
         * {
         *  public int extraField;
         * }
         * static Dictionary<PlanetData, PlanetDataExt> ExtFields = new Dictionary<PlanetData, PlanetDataExt>();
         */

        public static int AddVeinGroupData(this PlanetData planet, PlanetData.VeinGroup vein)
        {
            //PlanetDataExt ext = ExtFields[planet];
            //ext.extraField = 1;
            int newIndex = planet.veinGroups.Length;

            planet.SetVeinGroupCapacity(planet.veinGroups.Length + 1);
            planet.veinGroups[newIndex] = vein;
            return(newIndex);
        }
        public void UpdateValues()
        {
            PlanetData.VeinGroup veinGroup = _veinGardenerState.localPlanet.veinGroups[_veinGardenerState.veinGroupIndex];
            float currentValue             = veinGroup.amount;
            float maxAmount         = veinGroup.type == EVeinType.Oil ? oilMax : Math.Min(((long)int.MaxValue - 22845704) * oreMultiplier * veinGroup.count, 25000); // maxAmount = 10;
            float currentMultiplier = veinGroup.type == EVeinType.Oil ? VeinData.oilSpeedMultiplier : oreMultiplier;

            currentValue *= currentMultiplier;
            string currentTextValue = veinGroup.type == EVeinType.Oil ? currentValue.ToString("n1") : veinGroup.amount.ToString("n0");

            UIVGGroupEdit.VeinAmountSlider.maxValue = maxAmount;
            UIVGGroupEdit.UpdateData(UIVGGroupEdit.VeinTypeDropdown.value, UIVGGroupEdit.ProductTypeDropdown.value, veinGroup.count, currentValue, currentTextValue);
        }
Exemple #6
0
        private static void ToggleVeinHeighlight(int refId, ref GameObject button)
        {
            // Debug.Log("HeighlightVeins called with refId:" + refId.ToString());
            if (refId < 0 || refId > 15)
            {
                return;
            }

            // This is the group of gameobjects that contain the following components:
            // RectTransform, CanvasRenderer, UI.Image, UIVeinDetail
            Transform[] veinMarks = GameObject.Find("UI Root/Overlay Canvas/In Game/Scene UIs/Vein Marks/").GetComponentsInChildren <Transform>();


            highlightEnabled[refId] = !highlightEnabled[refId];

            // Loop through all nodes on planet (all planets?)
            foreach (Transform veinTip in veinMarks)
            {
                UIVeinDetail uiVeinDetail = veinTip.GetComponent <UIVeinDetail>();
                if (uiVeinDetail == null)
                {
                    continue;
                }

                foreach (UIVeinDetailNode uiVeinDetailNode in uiVeinDetail.allTips)
                {
                    // Check if the node is of the type we selected, todo: Check if it is also on the right planet.
                    if ((uiVeinDetail.inspectPlanet != null) && (uiVeinDetail.inspectPlanet.veinGroups[uiVeinDetailNode.veinGroupIndex].type == (EVeinType)refId))
                    {
                        PlanetData.VeinGroup matchingVein = uiVeinDetail.inspectPlanet.veinGroups[uiVeinDetailNode.veinGroupIndex];

                        Outline ol = uiVeinDetailNode.GetComponent <Outline>();
                        if (ol == null)  // Todo make outline prettier
                        {
                            ol                 = uiVeinDetailNode.gameObject.AddComponent(typeof(Outline)) as Outline;
                            ol.effectColor     = highlightColor;
                            ol.effectDistance  = effectDistance;
                            ol.useGraphicAlpha = true;
                        }
                        ol.enabled = highlightEnabled[refId];
                    }
                }
            }

            Image img = button.GetComponent <Image>();

            img.color = highlightEnabled[refId] ? enabledButtonColor : defaultHighlightButtonColor;
        }
        public void Show()
        {
            PlanetData.VeinGroup veinGroup = _veinGardenerState.localPlanet.veinGroups[_veinGardenerState.veinGroupIndex];
            Debug.Log("Showing vein Group: " + _veinGardenerState.veinGroupIndex);
            //var prodIdList = (from vein in _veinGardenerState.localPlanet.factory.veinPool where vein.groupIndex == _veinGardenerState.veinGroupIndex select vein.productId);
            //Debug.Log("prodIdList: " + prodIdList + " count: " + prodIdList.Count());
            //int prodId = (from vein in _veinGardenerState.localPlanet.factory.veinPool where vein.groupIndex == _veinGardenerState.veinGroupIndex select vein.productId).First();

            int prodId = Gardener.VeinGroup.GetProductType(_veinGardenerState.veinGroupIndex, _veinGardenerState.localPlanet);

            var prodIndex = _veinGardenerState.products.FindIndex(p => p == prodId);

            UIVGGroupEdit.VeinTypeDropdown.value    = (int)veinGroup.type - 1;
            UIVGGroupEdit.ProductTypeDropdown.value = prodIndex;

            UIVGGroupEdit.Show();
        }
        public void UpdatePos()
        {
            if (IsNotValidVGState)
            {
                return;
            }

            float   realRadius    = _veinGardenerState.localPlanet.realRadius;
            Vector3 localPosition = GameCamera.main.transform.localPosition;
            Vector3 forward       = GameCamera.main.transform.forward;

            PlanetData.VeinGroup veinGroup  = _veinGardenerState.localPlanet.veinGroups[_veinGardenerState.veinGroupIndex];
            Vector3 veinGroupWorldPos       = veinGroup.pos.normalized * (realRadius + 2.5f);
            Vector3 cameraVeinGroupDistance = veinGroupWorldPos - localPosition;
            float   magnitude = cameraVeinGroupDistance.magnitude;
            float   num       = Vector3.Dot(forward, cameraVeinGroupDistance);

            if (magnitude < 1f || num < 1f || magnitude > 150)
            {
                Hide();
                return;
            }

            Vector2 rectPoint;
            bool    flag = UIRoot.ScreenPointIntoRect(GameCamera.main.WorldToScreenPoint(veinGroupWorldPos), ContentParent, out rectPoint);

            if (Mathf.Abs(rectPoint.x) > 4000f)
            {
                Hide();
            }
            if (Mathf.Abs(rectPoint.y) > 4000f)
            {
                Hide();
            }

            rectPoint.x += UIVGGroupEdit.ContentTrans.rect.width / 2 + 10;
            rectPoint.y += UIVGGroupEdit.ContentTrans.rect.height / 2 + 10;

            rectPoint.x = Mathf.Round(rectPoint.x);
            rectPoint.y = Mathf.Round(rectPoint.y);

            UIVGGroupEdit.ContentTrans.anchoredPosition = rectPoint;
        }
Exemple #9
0
 // Token: 0x06000FCA RID: 4042 RVA: 0x000B8BA0 File Offset: 0x000B6FA0
 public override void _OnUpdate()
 {
     if (this.inspectPlanet == null)
     {
         base._Close();
         return;
     }
     PlanetData.VeinGroup veinGroup = this.inspectPlanet.veinGroups[this.veinGroupIndex];
     if (veinGroup.count == 0)
     {
         base._Close();
         return;
     }
     if (this.counter % 3 == 0 && this.showingAmount != veinGroup.amount)
     {
         this.showingAmount = veinGroup.amount;
         if (veinGroup.type != EVeinType.Oil)
         {
             this.infoText.text = string.Concat(new string[]
             {
                 veinGroup.count.ToString(),
                 "空格个".Translate(),
                 this.veinProto.name,
                 "储量".Translate(),
                 veinGroup.amount.ToString("#,##0")
             });
         }
         else
         {
             this.infoText.text = string.Concat(new string[]
             {
                 veinGroup.count.ToString(),
                 "空格个".Translate(),
                 this.veinProto.name,
                 "产量".Translate(),
                 ((float)veinGroup.amount * VeinData.oilSpeedMultiplier).ToString("0.00"),
                 "/s"
             });
         }
     }
     this.counter++;
 }
Exemple #10
0
            static bool ShouldAbortSanityChecks(UIVeinDetailNode __instance, out PlanetData.VeinGroup veinGroup, out ItemProto itemProto)
            {
                veinGroup = default(PlanetData.VeinGroup);
                itemProto = null;

                if (__instance.inspectPlanet == null)
                {
                    return(true);
                }
                veinGroup = __instance.inspectPlanet.veinGroups[__instance.veinGroupIndex];
                if (veinGroup.count == 0 || veinGroup.type != EVeinType.Oil)
                {
                    return(true);
                }

                var prodId = (from vein in __instance.inspectPlanet.factory.veinPool where vein.groupIndex == __instance.veinGroupIndex select vein.productId).First();

                itemProto = LDB.items.Select(prodId);

                return(false);
            }
        public void Init()
        {
            var inGameWindows = GameObject.Find("UI Root/Overlay Canvas/In Game/Windows");

            //Debug.Log(inGameWindows);
            ContentParent        = inGameWindows.GetComponent <RectTransform>();
            GUIGOVeinGroupModify = VeinPlanter.Instantiate(bundleAssets.LoadAsset <GameObject>("Assets/UI/VeinGardener/UIVeinGardenerGroupEdit.prefab"));
            AttachGameObject(GUIGOVeinGroupModify, inGameWindows.transform);


            UIVGGroupEdit = GUIGOVeinGroupModify.GetComponent <UIVeinGardenerGroupEdit>();
            if (!UIVGGroupEdit.IsInit)
            {
                UIVGGroupEdit.Init();
            }

            UIVGGroupEdit.Hide();
            //GUIGOVeinGroupModify.SetActive(true);

            Debug.Log("Registering callbacks for VG.GroupEdit");

            UIVGGroupEdit.UIOnVeinTypeChanged = newValue => {
                if (IsNotValidVGState)
                {
                    return;
                }
                EVeinType            newType   = (EVeinType)newValue + 1;
                PlanetData.VeinGroup veinGroup = _veinGardenerState.localPlanet.veinGroups[_veinGardenerState.veinGroupIndex];
                if (veinGroup.type == newType)
                {
                    return;
                }
                Gardener.VeinGroup.ChangeType(_veinGardenerState.veinGroupIndex, newType, _veinGardenerState.localPlanet);
                int extingProductId = Gardener.VeinGroup.GetProductType(_veinGardenerState.veinGroupIndex, _veinGardenerState.localPlanet);
                UIVGGroupEdit.ProductTypeDropdown.value = _veinGardenerState.products.FindIndex(p => p == extingProductId);
            };

            UIVGGroupEdit.UIOnProductTypeChanged = newValue => {
                if (IsNotValidVGState)
                {
                    return;
                }
                PlanetData.VeinGroup veinGroup = _veinGardenerState.localPlanet.veinGroups[_veinGardenerState.veinGroupIndex];
                int newProductId    = _veinGardenerState.products[newValue];
                int extingProductId = Gardener.VeinGroup.GetProductType(_veinGardenerState.veinGroupIndex, _veinGardenerState.localPlanet);
                if (newProductId == extingProductId)
                {
                    return;
                }

                Debug.Log("Changing product type for vein: " + _veinGardenerState.veinGroupIndex + "(" + veinGroup.type + ") to " + _veinGardenerState.products[newValue]);
                Gardener.VeinGroup.ChangeType(_veinGardenerState.veinGroupIndex, veinGroup.type, _veinGardenerState.localPlanet, productId: newProductId);
            };



            UIVGGroupEdit.UIOnVeinAmountSliderValueChanged = newValue => {
                Debug.Log("VG.GroupEdit : VeinAmountSliderValueChanged : " + newValue);
                Gardener.VeinGroup.UpdateVeinAmount(_veinGardenerState.veinGroupIndex, (long)(newValue / _veinGardenerState.oreMultiplier), _veinGardenerState.localPlanet);

                PlanetData.VeinGroup veinGroup = _veinGardenerState.localPlanet.veinGroups[_veinGardenerState.veinGroupIndex];
                if (veinGroup.type == EVeinType.Oil)
                {
                    Gardener.VeinGroup.UpdateVeinAmount(_veinGardenerState.veinGroupIndex, (long)(newValue / VeinData.oilSpeedMultiplier), _veinGardenerState.localPlanet);
                }
                else
                {
                    Gardener.VeinGroup.UpdateVeinAmount(_veinGardenerState.veinGroupIndex, (long)(newValue / oreMultiplier), _veinGardenerState.localPlanet);
                }
            };

            //UnityEngine.UI.Dropdown VeinTypeDropdown = GetNamedComponentInChildren<UnityEngine.UI.Dropdown>(GUIGOVeinGroupModify, "VeinTypeDropdown");
            //UnityEngine.UI.Dropdown ProductTypeDropdown = GetNamedComponentInChildren<UnityEngine.UI.Dropdown>(GUIGOVeinGroupModify, "ProductTypeDropdown");
            //UnityEngine.UI.Dropdown ModeVeinTypeDropdown = GetNamedComponentInChildren<UnityEngine.UI.Dropdown>(GUIGOModeSelect, "VeinTypeDropdown");


            Debug.Log("Populating UIVGGroupEdit.VeinTypeDropdown");
            UIVGGroupEdit.VeinTypeDropdown.ClearOptions();

            foreach (EVeinType tabType in Enum.GetValues(typeof(EVeinType)))
            {
                if (tabType == EVeinType.Max || tabType == EVeinType.None)
                {
                    continue;
                }
                int       veinProduct = PlanetModelingManager.veinProducts[(int)tabType];
                ItemProto itemProto   = veinProduct != 0 ? LDB.items.Select(veinProduct) : null;
                if (itemProto != null)
                {
                    UIVGGroupEdit.VeinTypeDropdown.options.Add(new UnityEngine.UI.Dropdown.OptionData()
                    {
                        image = itemProto.iconSprite, text = itemProto.name.Translate()
                    });
                }
            }

            Debug.Log("Populating Group Edit Products");
            UIVGGroupEdit.ProductTypeDropdown.ClearOptions();

            foreach (int prodId in _veinGardenerState.products)
            {
                ItemProto itemProto = prodId != 0 ? LDB.items.Select(prodId) : null;
                if (itemProto != null)
                {
                    UIVGGroupEdit.ProductTypeDropdown.options.Add(new UnityEngine.UI.Dropdown.OptionData()
                    {
                        image = itemProto.iconSprite, text = itemProto.name.Translate()
                    });
                }
            }
            UIVGGroupEdit.ContentTrans = GUIGOVeinGroupModify.GetComponent <RectTransform>();
        }
            public static bool GetClosestIndex(Ray ray, PlanetData localPlanet, out int closestVeinGroupIndex, out int closestVeinIndex, out float closestVeinDistance, out float closestVeinDistance2D)
            {
                float realRadius = localPlanet.realRadius;

                closestVeinGroupIndex = -1;
                closestVeinIndex      = -1;
                closestVeinDistance   = -1;
                closestVeinDistance2D = -1;
                float   closestVeinGroupDistance = 100f;
                Vector3 vector = Vector3.zero;

                if (Phys.RayCastSphere(ray.origin, ray.direction, 600f, Vector3.zero, realRadius + 1f, out var rch))
                {
                    Dictionary <int, float> distMap = new Dictionary <int, float>();

                    // First pass check for vein Group. Uses veinGroups (cheaper)
                    for (int i = 0; i < localPlanet.veinGroups.Length; i++)
                    {
                        PlanetData.VeinGroup veinGroup = localPlanet.veinGroups[i];
                        if (veinGroup.type == EVeinType.None)
                        {
                            continue;
                        }

                        float currentveinGroupDistance = Vector3.Distance(rch.point, veinGroup.pos * realRadius);
                        //Debug.Log("Comp: veinGroup: " + veinGroup.ToString() + " index: " + i + " Pos: " + veinGroup.pos.ToString() + " dist: " + currentveinGroupDistance);
                        distMap[i] = currentveinGroupDistance;
                        if (currentveinGroupDistance < closestVeinGroupDistance)
                        {
                            closestVeinGroupDistance = currentveinGroupDistance;
                            closestVeinGroupIndex    = i;
                            vector = veinGroup.pos * (realRadius + 2.5f);
                        }
                    }

                    // Second Pass. Looks up distance to specific vein nodes.
                    var limitedCandidates = distMap.OrderBy(key => key.Value).Take(Math.Min(distMap.Count(), 5));

                    //var veinCandidates = from vg in limitedCandidates select from vp in localPlanet.factory.veinPool where vp;
                    closestVeinDistance   = closestVeinGroupDistance;
                    closestVeinDistance2D = closestVeinGroupDistance;
                    foreach (var candkv in limitedCandidates)
                    {
                        //Debug.Log("Cand: VeinGroup Idx=" + candkv.Key + "\t Dist: " + candkv.Value);

                        for (int i = 1; i < localPlanet.factory.veinCursor; i++)
                        {
                            var vein = localPlanet.factory.veinPool[i];
                            if (vein.id != i || vein.groupIndex != candkv.Key)
                            {
                                continue;
                            }

                            float veinDistance = Vector3.Distance(rch.point, vein.pos);
                            if (veinDistance < closestVeinDistance)
                            {
                                closestVeinDistance   = veinDistance;
                                closestVeinGroupIndex = candkv.Key;
                                closestVeinIndex      = vein.id;
                            }

                            float veinDistance2D = Vector2.Distance(rch.point, vein.pos);
                            if (veinDistance2D < closestVeinDistance2D)
                            {
                                closestVeinDistance2D = veinDistance2D;
                                closestVeinGroupIndex = candkv.Key;
                                closestVeinIndex      = vein.id;
                            }
                        }
                    }
                    //Debug.Log("Closest: VgIdx=" + closestVeinGroupIndex + " Vein Idx=" + closestVeinIndex + "\t Dist: " + closestVeinDistance + ", Dist2D: " + closestVeinDistance2D);



                    // Cheat for now
                    //Assert.Equals(closestVeinGroupIndex, limitedCandidates.First().Key);
                    //closestVeinGroupIndex = candidates.First().Key;
                }

                // Check if there are any vein colliders inside a radius 5f sphere.
                if (closestVeinGroupIndex >= 0)
                {
                    /*
                     * if (!Phys.RayCastSphere(ray.origin, ray.direction, 600f, vector, 5f, out rch))
                     * {
                     *  Debug.Log("Resetting to -1! ");
                     *  closestVeinGroupIndex = -1;
                     *  closestVeinIndex = -1;
                     *  return false;
                     * }
                     */
                    if (closestVeinDistance2D < 5)
                    {
                        return(true);
                    }
                    else
                    {
                        //Debug.Log("Resetting to -1! Distance is above: 5");
                        closestVeinGroupIndex = -1;
                        closestVeinIndex      = -1;
                        closestVeinDistance2D = -1;
                        return(false);
                    }
                }
                return(false);
            }
Exemple #13
0
        public void HandleClick()
        {
            Vector3 worldPos;
            // RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTrans, Input.mousePosition, uicam, out var localPoint);
            Ray ray = GameCamera.main.ScreenPointToRay(Input.mousePosition);

            if (!VFInput.onGUI && Input.GetMouseButtonDown(0))
            {
                // Debug.Log("Clicking screen pos: " + Input.mousePosition.ToString() + " Ray: " + ray.ToString());

                _veinGardenerState.localPlanet = GameMain.localPlanet;
                if (_veinGardenerState.localPlanet == null)
                {
                    return;
                }

                if (Physics.Raycast(ray, out var hitInfo, 1000f, 15873, QueryTriggerInteraction.Ignore))
                {
                    worldPos = hitInfo.point;
                    // Debug.Log("Clicked on world pos: " + worldPos.ToString());

                    Gardener.VeinGroup.GetClosestIndex(ray, _veinGardenerState.localPlanet, out int closestVeinGroupIndex, out int closestVeinIndex, out float closestVeinDistance, out float closestVeinDistance2D);

                    switch (_veinGardenerState.modMode)
                    {
                    case eVeinModificationMode.AddVeinGroup:
                        //if (closestVeinGroupIndex < 0)
                    {
                        var veinGroup = Gardener.VeinGroup.New(_veinGardenerState.newVeinGroupType, worldPos.normalized);
                        closestVeinGroupIndex             = _veinGardenerState.localPlanet.AddVeinGroupData(veinGroup);
                        _veinGardenerState.veinGroupIndex = closestVeinGroupIndex;
                        Debug.Log("Adding new veinGroup: " + veinGroup.type.ToString() + " index: " + closestVeinGroupIndex + " Pos: " + veinGroup.pos * _veinGardenerState.localPlanet.radius);
                    }
                        Gardener.Vein.Add(_veinGardenerState.localPlanet, worldPos, closestVeinGroupIndex);
                        break;

                    case eVeinModificationMode.ExtendVein:
                        if (closestVeinDistance2D > 40)
                        {
                            Debug.Log("Not Extending veinGroup.index: " + _veinGardenerState.veinGroupIndex + ". Distance from vein group too large: " + closestVeinDistance2D);
                        }
                        Gardener.Vein.Add(_veinGardenerState.localPlanet, worldPos, _veinGardenerState.veinGroupIndex);
                        break;

                    case eVeinModificationMode.ModifyVeinGroup:
                        if (closestVeinGroupIndex >= 0)
                        {
                            PlanetData.VeinGroup veinGroup = _veinGardenerState.localPlanet.veinGroups[closestVeinGroupIndex];
                            Debug.Log("Clicked on veinGroup: " + veinGroup.ToString() + " index: " + closestVeinGroupIndex + " Type: " + veinGroup.type);
                            Debug.Log("VeinGroup: " + veinGroup.pos.ToString() + " index: " + (veinGroup.pos * (_veinGardenerState.localPlanet.realRadius + 2.5f)));

                            dialog = new UIVeinGroupDialog()
                            {
                                localPlanet    = _veinGardenerState.localPlanet,
                                veinGroupIndex = closestVeinGroupIndex,
                                Show           = true
                            };
                            _veinGardenerState.veinGroupIndex = closestVeinGroupIndex;
                            VeinPlanter.instance.veinGroupModifyPresenter.Show();
                        }
                        else
                        {
                            VeinPlanter.instance.veinGroupModifyPresenter.Hide();
                        }
                        break;

                    case eVeinModificationMode.RemoveVein:
                        if (closestVeinGroupIndex >= 0 && closestVeinIndex >= 0 && closestVeinDistance2D < 1)
                        {
                            Debug.Log("Removing vein: " + closestVeinIndex + " in group: " + closestVeinGroupIndex);
                            Gardener.Vein.Remove(_veinGardenerState.localPlanet, closestVeinIndex, closestVeinGroupIndex);
                            Gardener.VeinGroup.UpdatePosFromChildren(closestVeinGroupIndex);
                        }
                        break;


                    case eVeinModificationMode.TerrainLower:
                        //TerrainLower(worldPos);
                        break;

                    case eVeinModificationMode.Deactivated:
                    default:
                        break;
                    }
                }
            }
        }
Exemple #14
0
        private void HandleClick()
        {
            Vector3 worldPos;
            // RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTrans, Input.mousePosition, uicam, out var localPoint);
            Ray ray = GameCamera.main.ScreenPointToRay(Input.mousePosition);

            if (Input.GetMouseButtonDown(0))
            {
                // Debug.Log("Clicking screen pos: " + Input.mousePosition.ToString() + " Ray: " + ray.ToString());

                PlanetData localPlanet = GameMain.localPlanet;
                if (localPlanet == null)
                {
                    return;
                }

                if (Physics.Raycast(ray, out var hitInfo, 1000f, 15873, QueryTriggerInteraction.Ignore))
                {
                    worldPos = hitInfo.point;
                    // Debug.Log("Clicked on world pos: " + worldPos.ToString());

                    Gardener.VeinGroup.GetClosestIndex(ray, localPlanet, out int closestVeinGroupIndex, out int closestVeinIndex, out float closestVeinDistance, out float closestVeinDistance2D);

                    switch (modMode)
                    {
                    case eVeinModificationMode.AddVein:
                        if (closestVeinGroupIndex < 0)
                        {
                            var veinGroup = Gardener.VeinGroup.New(EVeinType.Iron, worldPos.normalized);
                            closestVeinGroupIndex = localPlanet.AddVeinGroupData(veinGroup);
                            Debug.Log("Adding new veinGroup: " + veinGroup.type.ToString() + " index: " + closestVeinGroupIndex + " Pos: " + veinGroup.pos * localPlanet.radius);
                        }
                        Gardener.Vein.Add(localPlanet, worldPos, closestVeinGroupIndex);
                        break;

                    case eVeinModificationMode.ModifyVeinGroup:
                        if (closestVeinGroupIndex >= 0)
                        {
                            PlanetData.VeinGroup veinGroup = localPlanet.veinGroups[closestVeinGroupIndex];
                            Debug.Log("Clicked on veinGroup: " + veinGroup.ToString() + " index: " + closestVeinGroupIndex + " Type: " + veinGroup.type);
                            Debug.Log("VeinGroup: " + veinGroup.pos.ToString() + " index: " + (veinGroup.pos * (localPlanet.realRadius + 2.5f)));

                            dialog = new UIVeinGroupDialog()
                            {
                                localPlanet    = localPlanet,
                                veinGroupIndex = closestVeinGroupIndex,
                                Show           = true
                            };
                        }
                        else
                        {
                            dialog = null;
                        }
                        break;

                    case eVeinModificationMode.RemoveVein:
                        if (closestVeinGroupIndex >= 0 && closestVeinIndex >= 0 && closestVeinDistance2D < 1)
                        {
                            Debug.Log("Removing vein: " + closestVeinIndex + " in group: " + closestVeinGroupIndex);
                            Gardener.Vein.Remove(localPlanet, closestVeinIndex, closestVeinGroupIndex);
                            Gardener.VeinGroup.UpdatePosFromChildren(closestVeinGroupIndex);
                        }
                        break;

                    case eVeinModificationMode.Deactivated:
                    default:
                        break;
                    }
                }
            }
        }
Exemple #15
0
 // Token: 0x06000FCB RID: 4043 RVA: 0x000B8D1C File Offset: 0x000B711C
 public void Refresh()
 {
     if (this.inspectPlanet == null)
     {
         return;
     }
     PlanetData.VeinGroup veinGroup = this.inspectPlanet.veinGroups[this.veinGroupIndex];
     if (veinGroup.count == 0)
     {
         base._Close();
         return;
     }
     this.veinProto = LDB.veins.Select((int)veinGroup.type);
     if (this.veinProto != null)
     {
         this.veinIcon.sprite = this.veinProto.iconSprite;
         this.showingAmount   = veinGroup.amount;
         if (veinGroup.type != EVeinType.Oil)
         {
             this.infoText.text = string.Concat(new string[]
             {
                 veinGroup.count.ToString(),
                 "空格个".Translate(),
                 this.veinProto.name,
                 "储量".Translate(),
                 veinGroup.amount.ToString("#,##0")
             });
         }
         else
         {
             this.infoText.text = string.Concat(new string[]
             {
                 veinGroup.count.ToString(),
                 "空格个".Translate(),
                 this.veinProto.name,
                 "产量".Translate(),
                 ((float)veinGroup.amount * VeinData.oilSpeedMultiplier).ToString("0.00"),
                 "/s"
             });
         }
     }
     else
     {
         this.veinIcon.sprite = null;
         this.showingAmount   = veinGroup.amount;
         if (veinGroup.type != EVeinType.Oil)
         {
             this.infoText.text = string.Concat(new string[]
             {
                 veinGroup.count.ToString(),
                 "空格个".Translate(),
                 " ? ",
                 "储量".Translate(),
                 veinGroup.amount.ToString("#,##0")
             });
         }
         else
         {
             this.infoText.text = string.Concat(new string[]
             {
                 veinGroup.count.ToString(),
                 "空格个".Translate(),
                 " ? ",
                 "产量".Translate(),
                 ((float)veinGroup.amount * VeinData.oilSpeedMultiplier).ToString("0.00"),
                 "/s"
             });
         }
     }
 }