public void OnCreated(ILoading loading)
 {
     Loading = loading;
     if (Enabled && Loading.loadingComplete)
     {
         SubstituteTextureManager.RegenerateCache();
     }
 }
 public void OnEnabled()
 {
     HarmonyHelper.DoOnHarmonyReady(() => Patcher.PatchAll());
     Enabled = true;
     if (Loading != null && Loading.loadingComplete)
     {
         SubstituteTextureManager.RegenerateCache();
     }
 }
 public void OnDisabled()
 {
     if (HarmonyHelper.IsHarmonyInstalled)
     {
         Patcher.UnpatchAll();
     }
     Enabled = false;
     if (Loading != null && Loading.loadingComplete)
     {
         SubstituteTextureManager.RegenerateCache();
     }
 }
        public static void ApplySurfaceMapAReplacement(Texture2D surfaceMapA, bool updateMipmaps, TerrainPatch patch)
        {
            surfaceMapA.Apply(updateMipmaps);
            if (Settings.TempDisable || Settings.EraseClipping)
            {
                return;
            }

            var replacedSurfaceMapA = SubstituteTextureManager.GetOrCreateSubstituteTexture(patch);

            replacedSurfaceMapA.Apply(updateMipmaps);
        }
        public static void OnSettingsUI(UIHelperBase helper)
        {
#if DEBUG
            Debug.Log("Make settings was called");
#endif
            helper.AddCheckbox("overwrite terrain appearance", EraseClipping, (isChecked) => { EraseClipping.value = isChecked; SubstituteTextureManager.RegenerateCache(); });
            var modeDropdown = helper.AddDropdown("operating mode", Enum.GetNames(typeof(Modes)), Mode.value, (value) => { Mode.value = value; SubstituteTextureManager.RegenerateCache(); }) as UIDropDown;
            void OnStrengthChanged(int strength, bool apply)
            {
                strengthSlider.value = strength;
                strengthNumber.text  = strength.ToString();
                if (apply && strength != Strength.value)
                {
                    Strength.value = strength;
                    if ((Modes)Mode.value != Modes.Erase)
                    {
                        SubstituteTextureManager.RegenerateCache();
                    }
                }
            }

            var mainPanel     = modeDropdown.parent.parent as UIScrollablePanel;
            var strengthPanel = mainPanel.AddUIComponent <UIPanel>();
            strengthPanel.autoLayout = true;
            strengthPanel.autoFitChildrenHorizontally = true;
            strengthPanel.autoFitChildrenVertically   = true;
            strengthPanel.autoLayoutDirection         = LayoutDirection.Vertical;
            var strengthLabel = strengthPanel.AddUIComponent <UILabel>();
            strengthLabel.text      = "strength";
            strengthLabel.textScale = 1.125f;
            var strengthRow = strengthPanel.AddUIComponent <UIPanel>();
            strengthRow.autoLayout = true;
            strengthRow.autoFitChildrenHorizontally = true;
            strengthRow.autoFitChildrenVertically   = true;
            strengthRow.autoLayoutDirection         = LayoutDirection.Horizontal;
            strengthRow.autoLayoutPadding           = new RectOffset(0, 8, 0, 0);
            strengthSlider = createSlider(helper, 0, MaxStrength, 1, Strength, (value) => { OnStrengthChanged(Mathf.RoundToInt(value), false); });
            strengthRow.AttachUIComponent(strengthSlider.gameObject);
            strengthNumber = createTextField(helper, Strength.value.ToString(), (_) => { }, (value) => { OnStrengthChanged(Util.LenientStringToInt(value, 0, MaxStrength, Strength.value), true); });
            strengthRow.AttachUIComponent(strengthNumber.gameObject);
            strengthNumber.numericalOnly    = true;
            strengthNumber.allowFloats      = false;
            strengthNumber.allowNegative    = false;
            strengthNumber.maxLength        = 4;
            strengthNumber.width           /= 3;
            strengthSlider.height           = strengthNumber.height;
            strengthSlider.eventMouseUp    += (_, __) => OnStrengthChanged(Mathf.RoundToInt(strengthSlider.value), true);
            strengthSlider.eventMouseLeave += (_, __) => OnStrengthChanged(Mathf.RoundToInt(strengthSlider.value), true);
            strengthSlider.eventLeaveFocus += (_, __) => OnStrengthChanged(Mathf.RoundToInt(strengthSlider.value), true);
            strengthSlider.eventLostFocus  += (_, __) => OnStrengthChanged(Mathf.RoundToInt(strengthSlider.value), true);
            helper.AddCheckbox("temporarily disable the mod (for quick comparison)", TempDisable, (isChecked) => { TempDisable = isChecked; SubstituteTextureManager.RegenerateCache(); });
        }
Esempio n. 6
0
        // maybe replace this with a transpiler that duplicates everything that is done to m_surfaceMapA?
        static void Postfix(TerrainPatch __instance)
        {
            if (Settings.TempDisable || Settings.EraseClipping.value)
            {
                return;
            }
#if DEBUG
            Debug.Log("resizing patch (" + __instance.m_x + "|" + __instance.m_z + ")");
#endif
            Texture2D original    = __instance.m_surfaceMapA;
            Texture2D replacement = SubstituteTextureManager.GetOrCreateSubstituteTexture(__instance);

            replacement.Resize(original.width, original.height, original.format, false);
            replacement.wrapMode   = original.wrapMode;
            replacement.filterMode = original.filterMode;
        }
        public static void SetSurfaceMapAPixelReplacement(Texture2D surfaceMapA, int x, int y, Color color, TerrainPatch patch)
        {
            if (Settings.TempDisable)
            {
                surfaceMapA.SetPixel(x, y, color);
                return;
            }
            var newcolor = ChangeColor(color);

            if (Settings.EraseClipping)
            {
                surfaceMapA.SetPixel(x, y, newcolor);
            }
            else
            {
                var replacedSurfaceMapA = SubstituteTextureManager.GetOrCreateSubstituteTexture(patch);
                replacedSurfaceMapA.SetPixel(x, y, newcolor);
                surfaceMapA.SetPixel(x, y, color);
            }
        }