fix offset mask logic
This commit is contained in:
164
Class1.cs
164
Class1.cs
@@ -12,11 +12,13 @@ namespace StrategicMapPlus
|
||||
[BepInPlugin("com.mod.strategicmapplus", "Strategic Map Plus", "28.0.0")]
|
||||
public class StrategicMapMod : BaseUnityPlugin
|
||||
{
|
||||
public static bool GlobalShowToggle = false;
|
||||
private float timer = 0f;
|
||||
private float interval = 0.5f;
|
||||
private bool texturesLoaded = false;
|
||||
|
||||
public static Dictionary<string, Sprite> SpriteCache = new Dictionary<string, Sprite>();
|
||||
public static Dictionary<string, Texture2D> RawTextureCache = new Dictionary<string, Texture2D>();
|
||||
private HashSet<string> reportedMissingKeys = new HashSet<string>();
|
||||
|
||||
void Awake()
|
||||
@@ -26,6 +28,12 @@ namespace StrategicMapPlus
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Toggle con Ctrl + V
|
||||
if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) && Input.GetKeyDown(KeyCode.V))
|
||||
{
|
||||
GlobalShowToggle = !GlobalShowToggle;
|
||||
}
|
||||
|
||||
if (!texturesLoaded && Time.time > 3f) LoadTextures();
|
||||
|
||||
timer += Time.deltaTime;
|
||||
@@ -58,6 +66,8 @@ namespace StrategicMapPlus
|
||||
if (textureLookup.ContainsKey(texName))
|
||||
{
|
||||
Texture2D tex = textureLookup[texName];
|
||||
RawTextureCache[logicKey] = tex; // Guardamos la original para Debug
|
||||
|
||||
Textures.IconOffset offset = null;
|
||||
if (Textures.IconsOffsets.ContainsKey(logicKey)) offset = Textures.IconsOffsets[logicKey];
|
||||
|
||||
@@ -166,7 +176,8 @@ namespace StrategicMapPlus
|
||||
|
||||
if (SpriteCache.ContainsKey(generatedKey))
|
||||
{
|
||||
visualizer.ShowIcon(SpriteCache[generatedKey]);
|
||||
Texture2D raw = RawTextureCache.ContainsKey(generatedKey) ? RawTextureCache[generatedKey] : null;
|
||||
visualizer.ShowIcon(SpriteCache[generatedKey], raw);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -203,39 +214,75 @@ namespace StrategicMapPlus
|
||||
Texture2D newTexture = new Texture2D(originalTexture.width, originalTexture.height);
|
||||
newTexture.ReadPixels(new Rect(0, 0, tmp.width, tmp.height), 0, 0);
|
||||
|
||||
// 5. MODIFICAR LOS PÍXELES (Aquí ocurre la magia)
|
||||
Color[] pixels = newTexture.GetPixels();
|
||||
// 5. MODIFICAR LOS PÍXELES (Lógica de Re-muestreo / Resampling)
|
||||
// En lugar de mover la máscara, dejamos la máscara fija en el centro y movemos la textura (Source).
|
||||
// Esto permite hacer CLAMP (repetir bordes) para evitar cortes rectos.
|
||||
|
||||
Color[] sourcePixels = newTexture.GetPixels(); // Píxeles originales (Source)
|
||||
Color[] finalPixels = new Color[sourcePixels.Length]; // Píxeles destino (Destination)
|
||||
|
||||
float width = newTexture.width;
|
||||
float height = newTexture.height;
|
||||
Vector2 center = new Vector2(width / 2f, height / 2f);
|
||||
float radius = (Mathf.Min(width, height) / 2f); // Radio máximo
|
||||
|
||||
// Configuración por defecto
|
||||
float maskRadius = (Mathf.Min(width, height) / 2f);
|
||||
float shiftX = 0f;
|
||||
float shiftY = 0f;
|
||||
|
||||
if (offset != null)
|
||||
{
|
||||
center += new Vector2(offset.x, offset.y);
|
||||
if (offset.size > 0) radius = offset.size / 2f;
|
||||
}
|
||||
// Size: Escala de la máscara (1.0 = toca bordes)
|
||||
if (offset.size > 0) maskRadius *= offset.size;
|
||||
|
||||
for (int i = 0; i < pixels.Length; i++)
|
||||
// Offset: Desplazamiento del CONTENIDO (UV Shift)
|
||||
// Si Offset X > 0 (positivo), queremos ver lo que hay a la derecha,
|
||||
// por tanto "desplazamos la textura hacia la izquierda" (sumamos al índice de lectura).
|
||||
shiftX = offset.x * width;
|
||||
shiftY = offset.y * height;
|
||||
} else
|
||||
{
|
||||
// --- Opción A: Máscara Redonda (Matemática) ---
|
||||
int x = i % newTexture.width;
|
||||
int y = i / newTexture.width;
|
||||
float dist = Vector2.Distance(new Vector2(x, y), center);
|
||||
// Default
|
||||
offset = new Textures.IconOffset(0.07f, 0, 0.9f);
|
||||
|
||||
if (dist > radius)
|
||||
{
|
||||
pixels[i] = Color.clear; // Hacemos transparente lo que esté fuera del círculo
|
||||
}
|
||||
|
||||
// --- Opción B: Quitar el negro (Si prefieres por color) ---
|
||||
// if (pixels[i].r < 0.1f && pixels[i].g < 0.1f && pixels[i].b < 0.1f)
|
||||
// {
|
||||
// pixels[i] = Color.clear;
|
||||
// }
|
||||
if (offset.size > 0) maskRadius *= offset.size;
|
||||
shiftX = offset.x * width;
|
||||
shiftY = offset.y * height;
|
||||
}
|
||||
|
||||
newTexture.SetPixels(pixels);
|
||||
int w = (int)width;
|
||||
int h = (int)height;
|
||||
|
||||
for (int i = 0; i < finalPixels.Length; i++)
|
||||
{
|
||||
int x = i % w;
|
||||
int y = i / w;
|
||||
|
||||
// 1. MÁSCARA (Siempre centrada en el output)
|
||||
float dist = Vector2.Distance(new Vector2(x, y), center);
|
||||
if (dist > maskRadius)
|
||||
{
|
||||
finalPixels[i] = Color.clear;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 2. MUESTREO (Sampling) con Offset
|
||||
// Calculamos qué píxel de la textura original corresponde a esta posición (x,y)
|
||||
int srcX = (int)(x + shiftX);
|
||||
int srcY = (int)(y + shiftY);
|
||||
|
||||
// 3. CLAMP (Repetir bordes)
|
||||
// Si nos salimos de la textura, repetimos el último píxel válido.
|
||||
// Esto evita el "corte recto" transparente (siempre que el borde tenga color).
|
||||
srcX = Mathf.Clamp(srcX, 0, w - 1);
|
||||
srcY = Mathf.Clamp(srcY, 0, h - 1);
|
||||
|
||||
// Leemos del array original
|
||||
int srcIndex = srcY * w + srcX;
|
||||
finalPixels[i] = sourcePixels[srcIndex];
|
||||
}
|
||||
|
||||
newTexture.SetPixels(finalPixels);
|
||||
newTexture.Apply();
|
||||
|
||||
// 6. Limpieza
|
||||
@@ -255,15 +302,71 @@ namespace StrategicMapPlus
|
||||
private bool isInitialized = false;
|
||||
private bool hasContent = false;
|
||||
|
||||
// --- ZONA DEBUG EN INSPECTOR ---
|
||||
public bool DebugMode = false;
|
||||
public float DebugOffsetX = 0f;
|
||||
public float DebugOffsetY = 0f;
|
||||
public float DebugSize = 1f;
|
||||
|
||||
private Texture2D _rawTexture; // La textura original sin recortar
|
||||
private Texture2D _generatedDebugTex; // Para limpiar memoria
|
||||
private Sprite _defaultSprite; // Sprite original para restaurar
|
||||
private float _lastX, _lastY, _lastSize;
|
||||
private bool _lastDebugMode;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!isInitialized || displayObj == null) return;
|
||||
|
||||
bool shouldShow = hasContent && Input.GetKey(KeyCode.V);
|
||||
// Lógica de visualización (V o Ctrl+V)
|
||||
bool shouldShow = hasContent && (StrategicMapMod.GlobalShowToggle || Input.GetKey(KeyCode.V));
|
||||
if (displayObj.activeSelf != shouldShow)
|
||||
{
|
||||
displayObj.SetActive(shouldShow);
|
||||
}
|
||||
|
||||
// Lógica de DEBUG en tiempo real
|
||||
if (_rawTexture != null)
|
||||
{
|
||||
// Si activamos el modo debug, forzamos actualización
|
||||
if (DebugMode && !_lastDebugMode)
|
||||
{
|
||||
_lastDebugMode = true;
|
||||
UpdateDebugTexture();
|
||||
}
|
||||
else if (!DebugMode && _lastDebugMode)
|
||||
{
|
||||
_lastDebugMode = false;
|
||||
// AL SALIR DEL DEBUG: Restaurar el sprite original
|
||||
if (iconImage != null && _defaultSprite != null) iconImage.sprite = _defaultSprite;
|
||||
}
|
||||
|
||||
if (DebugMode)
|
||||
{
|
||||
if (_lastX != DebugOffsetX || _lastY != DebugOffsetY || _lastSize != DebugSize)
|
||||
{
|
||||
UpdateDebugTexture();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateDebugTexture()
|
||||
{
|
||||
_lastX = DebugOffsetX;
|
||||
_lastY = DebugOffsetY;
|
||||
_lastSize = DebugSize;
|
||||
|
||||
if (_generatedDebugTex != null) Destroy(_generatedDebugTex);
|
||||
|
||||
var debugOffset = new Textures.IconOffset(DebugOffsetX, DebugOffsetY, DebugSize);
|
||||
_generatedDebugTex = StrategicMapMod.MakeTextureTransparent(_rawTexture, debugOffset);
|
||||
|
||||
if (_generatedDebugTex != null)
|
||||
{
|
||||
Sprite debugSprite = Sprite.Create(_generatedDebugTex, new Rect(0, 0, _generatedDebugTex.width, _generatedDebugTex.height), new Vector2(0.5f, 0.5f));
|
||||
if (iconImage != null) iconImage.sprite = debugSprite;
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
@@ -325,17 +428,26 @@ namespace StrategicMapPlus
|
||||
if (displayObj != null && displayObj.activeSelf) displayObj.SetActive(false);
|
||||
}
|
||||
|
||||
public void ShowIcon(Sprite s)
|
||||
public void ShowIcon(Sprite s, Texture2D raw = null)
|
||||
{
|
||||
if (!isInitialized) Initialize();
|
||||
if (!isInitialized) return;
|
||||
|
||||
// Guardamos la referencia raw para el debug
|
||||
_rawTexture = raw;
|
||||
_defaultSprite = s; // Guardamos el sprite base
|
||||
|
||||
// Aseguramos orden de dibujado (Encima de todo)
|
||||
displayObj.transform.SetAsLastSibling();
|
||||
|
||||
if (s != null)
|
||||
{
|
||||
iconImage.sprite = s;
|
||||
// Solo sobreescribimos visualmente si NO estamos en modo debug
|
||||
if (!DebugMode)
|
||||
{
|
||||
iconImage.sprite = s;
|
||||
}
|
||||
|
||||
iconImage.enabled = true;
|
||||
if (debugText != null) debugText.text = "";
|
||||
hasContent = true;
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace StrategicMapPlus
|
||||
};
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
static public Dictionary<string, IconOffset> IconsOffsets = new Dictionary<string, IconOffset>() { };
|
||||
static public Dictionary<string, IconOffset> IconsOffsets = new Dictionary<string, IconOffset>() {};
|
||||
|
||||
public class IconOffset
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("StrategicView-Plus")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9153fd763e579199d54cab0a432ff9090b4c64e9")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+7e598d765a951b2ed1dffae0db08efa1368fa39a")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("StrategicView-Plus")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("StrategicView-Plus")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@@ -1 +1 @@
|
||||
32d9cb21f9105a306e788f865867ce1cabf7e1239b4f80ba170e98b961bae87f
|
||||
90f7195f387189c7972462dcdf91a73885ae72597aaaeff424f4540350fd7c06
|
||||
|
||||
@@ -11,20 +11,21 @@ D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\Unity.TextMeshPro.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\UnityEngine.CoreModule.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\UnityEngine.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\UnityEngine.InputLegacyModule.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\UnityEngine.InputModule.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\UnityEngine.UI.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\UnityEngine.UIModule.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\Utils.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\Mono.Cecil.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\MonoMod.Utils.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\MonoMod.RuntimeDetour.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\Google.Protobuf.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\UnityEngine.UnityWebRequestModule.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\UnityEngine.UIModule.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\UnityEngine.GameCenterModule.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\Zxcvbn.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\Facepunch.Steamworks.Win64.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\UnityEngine.UnityWebRequestTextureModule.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\UnityEngine.AnimationModule.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\UnityEngine.InputLegacyModule.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\UnityEngine.TextRenderingModule.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\UnityEngine.JSONSerializeModule.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\UnityEngine.IMGUIModule.dll
|
||||
@@ -96,7 +97,6 @@ D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\UnityEngine.WindModule.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\UnityEngine.XRModule.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\UnityEngine.ARModule.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\UnityEngine.InputModule.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\InAppPurchasing-Claims.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\prefs.dll
|
||||
D:\Downloads\Unity Modding\StrategicMap-Plus\StrategicView-Plus\bin\Debug\net472\Unity.Timeline.dll
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user