示例#1
0
 protected override void SetUpIcons()
 {
     if (Application.isPlaying)
     {
         if (this._requiredIngredients != null)
         {
             float   num           = 1f / (Screen.width / 70f);
             Vector3 localPosition = new Vector3(0.5f - num * (float)(this._requiredIngredients.Count / 2), 0.06f, 0f);
             for (int i = 0; i < this._requiredIngredients.Count; i++)
             {
                 BuildIngredients          buildIngredients = this._requiredIngredients[i];
                 HudGui.BuildingIngredient icons            = this.GetIcons(buildIngredients._itemID);
                 icons._icon.transform.parent        = null;
                 icons._text.transform.parent        = null;
                 icons._icon.transform.localPosition = localPosition;
                 localPosition.z += 1f;
                 icons._text.transform.localPosition = localPosition;
                 localPosition.z -= 1f;
                 localPosition.x += num;
             }
         }
         else
         {
             Destroy(base.gameObject);
         }
     }
 }
示例#2
0
 private void CheckText()
 {
     if (Application.isPlaying)
     {
         for (int i = 0; i < this._requiredIngredients.Count; i++)
         {
             Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[i];
             ReceipeIngredient         receipeIngredient       = this._presentIngredients[i];
             HudGui.BuildingIngredient icons = this.GetIcons(buildIngredients._itemID);
             if (buildIngredients != null && receipeIngredient != null && receipeIngredient._amount != buildIngredients._amount)
             {
                 if (!icons._iconGo.activeSelf || !icons._label.gameObject.activeSelf)
                 {
                     icons._iconGo.SetActive(true);
                     icons._label.gameObject.SetActive(true);
                     Scene.HudGui.BuildingIngredientsGrid.repositionNow = true;
                     if (!Scene.HudGui.BuildingIngredientsFollow.gameObject.activeSelf)
                     {
                         Scene.HudGui.BuildingIngredientsFollow.gameObject.SetActive(true);
                     }
                 }
                 Craft_Structure.BuildIngredients.TextOptions textDisplayMode = buildIngredients._textDisplayMode;
                 if (textDisplayMode != Craft_Structure.BuildIngredients.TextOptions.PresentOverTotal)
                 {
                     if (textDisplayMode != Craft_Structure.BuildIngredients.TextOptions.Present)
                     {
                         if (textDisplayMode == Craft_Structure.BuildIngredients.TextOptions.Total)
                         {
                             icons._label.text = buildIngredients._amount.ToString();
                         }
                     }
                     else
                     {
                         icons._label.text = receipeIngredient._amount.ToString();
                     }
                 }
                 else if (icons.DisplayedPresent != receipeIngredient._amount || icons.DisplayedNeeded != buildIngredients._amount)
                 {
                     icons.DisplayedPresent = receipeIngredient._amount;
                     icons.DisplayedNeeded  = buildIngredients._amount;
                     icons._label.text      = receipeIngredient._amount + "/" + buildIngredients._amount;
                 }
             }
             else if (icons._iconGo.activeSelf || icons._label.gameObject.activeSelf)
             {
                 icons._iconGo.SetActive(false);
                 icons._label.gameObject.SetActive(false);
             }
         }
     }
 }
示例#3
0
 private void AllOff(bool destroy = false)
 {
     try
     {
         if (Scene.HudGui)
         {
             Scene.HudGui.AddBuildingIngredientIcon.SetActive(false);
             Scene.HudGui.DestroyIcon.SetActive(false);
             Scene.HudGui.ToggleVariationIcon.SetActive(false);
             Scene.HudGui.CantPlaceIcon.SetActive(false);
             if (Scene.HudGui.BuildingIngredientsFollow.gameObject.activeSelf)
             {
                 Scene.HudGui.BuildingIngredientsFollow.gameObject.SetActive(false);
             }
         }
         if (Application.isPlaying)
         {
             for (int i = 0; i < this._requiredIngredients.Count; i++)
             {
                 Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[i];
                 HudGui.BuildingIngredient        icons            = this.GetIcons(buildIngredients._itemID);
                 if (icons._iconGo.activeSelf || icons._label.gameObject.activeSelf)
                 {
                     icons._iconGo.SetActive(false);
                     icons._label.gameObject.SetActive(false);
                 }
             }
         }
         if (LocalPlayer.Inventory)
         {
             LocalPlayer.Inventory.DontShowDrop = false;
         }
     }
     catch
     {
     }
 }
        protected override void Update()
        {
            if (!_initialized)
            {
                return;
            }
            CheckText();
            CheckNeeded();
            Scene.HudGui.DestroyIcon.gameObject.SetActive(true);
            if (_swapTo)
            {
                if (!Scene.HudGui.ToggleVariationIcon.activeSelf)
                {
                    Scene.HudGui.ToggleVariationIcon.SetActive(true);
                }
                if (TheForest.Utils.Input.GetButtonDown("Rotate"))
                {
                    SwapToNextGhost();
                    return;
                }
            }
            if (TheForest.Utils.Input.GetButtonAfterDelay("Craft", 0.25f))
            {
                CancelBlueprint();
                return;
            }
            if (_lockBuild || (CustomLockCheck != null && CustomLockCheck()))
            {
                int num = 0;
                for (int i = 0; i < _requiredIngredients.Count; i++)
                {
                    num += _requiredIngredients[i]._amount - _presentIngredients[i]._amount;
                }
                if (num == 1)
                {
                    AllOff();
                    Scene.HudGui.CantPlaceIcon.SetActive(true);
                    return;
                }
            }
            Scene.HudGui.CantPlaceIcon.SetActive(false);
            bool flag = false;

            for (int j = 0; j < _requiredIngredients.Count; j++)
            {
                HudGui.BuildingIngredient icons = GetIcons(_requiredIngredients[j]._itemID);
                if (_requiredIngredients[j]._amount != _presentIngredients[j]._amount)
                {
                    BuildIngredients  buildIngredients  = _requiredIngredients[j];
                    ReceipeIngredient receipeIngredient = _presentIngredients[j];
                    if (buildIngredients._amount > receipeIngredient._amount)
                    {
                        if (!LocalPlayer.Inventory.Owns(_requiredIngredients[j]._itemID) && !Cheats.Creative)
                        {
                            icons.SetMissingIngredientColor();
                        }
                        else
                        {
                            icons.SetAvailableIngredientColor();
                            if (_nextAddItem < Time.time && !flag)
                            {
                                flag = true;
                                if (!Scene.HudGui.AddBuildingIngredientIcon.activeSelf)
                                {
                                    Scene.HudGui.AddBuildingIngredientIcon.SetActive(true);
                                }
                                Scene.HudGui.AddBuildingIngredientIcon.transform.localPosition = icons._iconGo.transform.localPosition + new Vector3(0f, -50f, 0f);
                                Scene.HudGui.AddBuildingIngredientIcon.transform.rotation      = icons._iconGo.transform.rotation;
                                if (TheForest.Utils.Input.GetButtonDown("Build"))
                                {
                                    _nextAddItem = Time.time + 0.25f;
                                    AddIngredient(j);
                                    break;
                                }
                                if (TheForest.Utils.Input.GetButton("Build") && (_nextAddItem < Time.time))
                                {
                                    _nextAddItem = Time.time + 0.05f;
                                    AddIngredient(j);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            if (!flag && Scene.HudGui.AddBuildingIngredientIcon.activeSelf)
            {
                Scene.HudGui.AddBuildingIngredientIcon.SetActive(false);
            }
            if (Vector3.Dot(LocalPlayer.Transform.forward, _uiFollowTarget.forward) < 0.75f || LocalPlayer.Transform.InverseTransformPoint(_uiFollowTarget.position).z < 0f)
            {
                SetUpIcons();
            }
        }
示例#5
0
 private void SetUpIcons()
 {
     if (Application.isPlaying)
     {
         if (this._requiredIngredients != null)
         {
             if (!this._uiFollowTarget)
             {
                 this._uiFollowTarget        = new GameObject("UiFollowTarget").transform;
                 this._uiFollowTarget.parent = base.transform;
             }
             if (this._bounds.size.sqrMagnitude == 0f)
             {
                 this._bounds.center = base.transform.position;
                 this._requiredIngredients.ForEach(delegate(Craft_Structure.BuildIngredients ri)
                 {
                     ri._subIngredients.ForEach(delegate(Craft_Structure.BuildIngredients.SubIngredient si)
                     {
                         si._renderers.ForEach(delegate(GameObject go)
                         {
                             if (go.activeSelf)
                             {
                                 Renderer component = go.GetComponent <Renderer>();
                                 if (component)
                                 {
                                     this._bounds.Encapsulate(component.bounds.center);
                                 }
                                 else if (go.transform.childCount > 0)
                                 {
                                     Transform child = go.transform.GetChild(0);
                                     component       = child.GetComponent <Renderer>();
                                     if (component)
                                     {
                                         this._bounds.Encapsulate(component.bounds.center);
                                     }
                                     else
                                     {
                                         this._bounds.Encapsulate(child.position);
                                     }
                                 }
                             }
                             this._bounds.Encapsulate(go.transform.position);
                         });
                     });
                 });
             }
             Vector3 position = LocalPlayer.MainCamTr.position;
             position.y = this._bounds.center.y;
             Vector3 forward = this._bounds.center + this.TriggerOffset - LocalPlayer.MainCamTr.position;
             float   num     = forward.magnitude * 0.9f;
             Vector3 vector  = LocalPlayer.MainCamTr.position + forward.normalized * Mathf.Clamp(10f, 1f, num);
             vector.y = Mathf.Lerp(vector.y, LocalPlayer.MainCamTr.position.y, 0.5f);
             this._uiFollowTarget.position = vector;
             if (!this._bounds.Contains(position))
             {
                 Ray   ray = new Ray(LocalPlayer.MainCamTr.position, (this._uiFollowTarget.position - LocalPlayer.MainCamTr.position).normalized);
                 float a;
                 if (this._bounds.IntersectRay(ray, out a))
                 {
                     Vector3 point = ray.GetPoint(Mathf.Clamp(10f, 1f, Mathf.Min(a, num)));
                     if (Vector3.Dot(LocalPlayer.Transform.forward, point - LocalPlayer.MainCamTr.position) > 0.35f)
                     {
                         this._uiFollowTarget.position = point;
                     }
                 }
                 forward = this._uiFollowTarget.position - LocalPlayer.MainCamTr.position;
             }
             else if (Vector3.Dot(LocalPlayer.Transform.forward, vector - LocalPlayer.MainCamTr.position) < 0.1f)
             {
                 this._uiFollowTarget.position = LocalPlayer.MainCamTr.position + LocalPlayer.MainCamTr.forward * Mathf.Clamp(10f, 1f, num);
                 forward = this._uiFollowTarget.position - LocalPlayer.MainCamTr.position;
             }
             this._uiFollowTarget.rotation = Quaternion.LookRotation(forward);
             Scene.HudGui.BuildingIngredientsFollow._target = this._uiFollowTarget;
             for (int i = this._requiredIngredients.Count - 1; i >= 0; i--)
             {
                 Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[i];
                 HudGui.BuildingIngredient        icons            = this.GetIcons(buildIngredients._itemID);
                 icons._iconGo.transform.SetAsFirstSibling();
             }
             Scene.HudGui.BuildingIngredientsGrid.Reposition();
         }
         else
         {
             UnityEngine.Object.Destroy(base.gameObject);
         }
     }
 }
示例#6
0
 private void Update()
 {
     if (this._initialized)
     {
         this.CheckText();
         this.CheckNeeded();
         Scene.HudGui.DestroyIcon.gameObject.SetActive(true);
         if (this._swapTo)
         {
             if (!Scene.HudGui.ToggleVariationIcon.activeSelf)
             {
                 Scene.HudGui.ToggleVariationIcon.SetActive(true);
             }
             if (TheForest.Utils.Input.GetButtonDown("Rotate"))
             {
                 this.SwapToNextGhost();
                 return;
             }
         }
         if (TheForest.Utils.Input.GetButtonAfterDelay("Craft", 0.5f, false))
         {
             this.CancelBlueprint();
             return;
         }
         if (this._lockBuild || (this.CustomLockCheck != null && this.CustomLockCheck()))
         {
             int num = 0;
             for (int i = 0; i < this._requiredIngredients.Count; i++)
             {
                 num += this._requiredIngredients[i]._amount - this._presentIngredients[i]._amount;
             }
             if (num == 1)
             {
                 this.AllOff(false);
                 Scene.HudGui.CantPlaceIcon.SetActive(true);
                 return;
             }
         }
         Scene.HudGui.CantPlaceIcon.SetActive(false);
         bool flag = false;
         for (int j = 0; j < this._requiredIngredients.Count; j++)
         {
             HudGui.BuildingIngredient icons = this.GetIcons(this._requiredIngredients[j]._itemID);
             if (this._requiredIngredients[j]._amount != this._presentIngredients[j]._amount)
             {
                 Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[j];
                 ReceipeIngredient receipeIngredient = this._presentIngredients[j];
                 if (buildIngredients._amount > receipeIngredient._amount)
                 {
                     if (!LocalPlayer.Inventory.Owns(this._requiredIngredients[j]._itemID, true) && !Cheats.Creative)
                     {
                         icons.SetMissingIngredientColor();
                     }
                     else
                     {
                         icons.SetAvailableIngredientColor();
                         if (this._nextAddItem < Time.time && !flag)
                         {
                             flag = true;
                             if (!Scene.HudGui.AddBuildingIngredientIcon.activeSelf)
                             {
                                 Scene.HudGui.AddBuildingIngredientIcon.SetActive(true);
                             }
                             Scene.HudGui.AddBuildingIngredientIcon.transform.localPosition = icons._iconGo.transform.localPosition + new Vector3(0f, -50f, 0f);
                             Scene.HudGui.AddBuildingIngredientIcon.transform.rotation      = icons._iconGo.transform.rotation;
                             if (this.GetBuildInputDown() || (Cheats.Creative && TheForest.Utils.Input.GetButton("Build")))
                             {
                                 if (Cheats.Creative)
                                 {
                                     this._nextAddItem = Time.time + 0.065f;
                                 }
                                 this.AddIngredient(j);
                                 break;
                             }
                         }
                     }
                 }
             }
         }
         if (!flag && Scene.HudGui.AddBuildingIngredientIcon.activeSelf)
         {
             Scene.HudGui.AddBuildingIngredientIcon.SetActive(false);
         }
         if (Vector3.Dot(LocalPlayer.Transform.forward, this._uiFollowTarget.forward) < 0.75f || LocalPlayer.Transform.InverseTransformPoint(this._uiFollowTarget.position).z < 0f)
         {
             this.SetUpIcons();
         }
         else if (SteamClientDSConfig.isDedicatedClient)
         {
             bool  flag2 = LocalPlayer.Transform.InverseTransformPoint(this._uiFollowTarget.position).z >= 0f;
             float num2  = Vector3.Dot(LocalPlayer.Transform.forward, this._uiFollowTarget.forward);
             bool  flag3 = num2 > 0.35f && num2 < 0.8f;
             if (flag2 && flag3)
             {
                 this.SetUpIcons();
             }
         }
     }
 }