Commit 2026bcad authored by hex's avatar hex

优化超先行卡下载,增加场地图自动下载,调整文字大小立绘大小

parent e814b21e
......@@ -1520,7 +1520,7 @@ MonoBehaviour:
mTrueTypeFont: {fileID: 12800000, guid: f775853fdfd14bb47934543e95c3bae3, type: 3}
mFont: {fileID: 0}
mText:
mFontSize: 20
mFontSize: 30
mFontStyle: 0
mAlignment: 1
mEncoding: 1
......@@ -2059,7 +2059,7 @@ MonoBehaviour:
mTrueTypeFont: {fileID: 12800000, guid: f775853fdfd14bb47934543e95c3bae3, type: 3}
mFont: {fileID: 0}
mText:
mFontSize: 20
mFontSize: 25
mFontStyle: 0
mAlignment: 0
mEncoding: 1
......
......@@ -155,9 +155,6 @@ public class Menu : WindowServantSP
#endif
}
/// <summary>
/// 当用户点击下载超先行卡按钮时触发
/// </summary>
void onClickDownloadSuperPre()
{
if (isDownloadingSuperPre)
......@@ -169,40 +166,62 @@ public class Menu : WindowServantSP
Program.I().StartCoroutine(DownloadAndApplySuperPrePackCoroutine());
}
/// <summary>
/// [修改] 这是包装器协程,负责错误捕获和状态管理。
/// </summary>
private IEnumerator DownloadAndApplySuperPrePackCoroutine()
{
isDownloadingSuperPre = true;
// 定义常量和路径
var workerEnumerator = DownloadAndApplySuperPrePack_Worker();
while (true)
{
object current = null;
try
{
if (!workerEnumerator.MoveNext())
{
break; // 工作完成,跳出循环
}
current = workerEnumerator.Current;
}
catch (Exception e)
{
Program.PrintToChat($"处理更新时发生严重错误: {e.Message}");
UnityEngine.Debug.LogError($"[SuperPreUpdate] Error: {e.ToString()}");
break; // 发生错误,跳出循环
}
yield return current;
}
isDownloadingSuperPre = false;
}
private IEnumerator DownloadAndApplySuperPrePack_Worker()
{
// --- 1. 定义常量和路径 ---
const string downloadUrl = "https://cdntx.moecube.com/ygopro-super-pre/archive/ygopro-super-pre.ypk";
string downloadsDir = "downloads";
string expansionsDir = "expansions";
string ypkFileName = "ygopro-super-pre.ypk";
string zipFileName = "ygopro-super-pre.zip";
string ypkFilePath = Path.Combine(expansionsDir, ypkFileName);
string zipFilePath = Path.Combine(expansionsDir, zipFileName);
string ypkFilePathInDownloads = Path.Combine(downloadsDir, ypkFileName);
// 1. 确保 expansions 目录存在
if (!Directory.Exists(expansionsDir))
{
Directory.CreateDirectory(expansionsDir);
}
// --- 2. 确保目录存在 ---
// (同步操作,如果失败会直接抛出 IO 异常)
if (!Directory.Exists(downloadsDir)) Directory.CreateDirectory(downloadsDir);
if (!Directory.Exists(expansionsDir)) Directory.CreateDirectory(expansionsDir);
Program.PrintToChat("开始检查超先行卡更新...");
Program.PrintToChat("开始检查超先行卡更新...\n请注意超先行卡更新会清空原来的 expansions 文件夹");
// 2. 使用 DownloadFileWithHeadCheck 下载文件
// --- 3. 下载文件 ---
bool downloadCompleted = false;
bool newVersionDownloaded = false;
int lastReportedProgress = -10;
int lastReportedProgress = 0; // 用于控制进度报告的频率
yield return Program.I().StartCoroutine(UnityFileDownloader.DownloadFileWithHeadCheck(
// 使用一个临时变量来接收 StartCoroutine 的结果,因为我们需要 yield 它
var downloadCoroutine = UnityFileDownloader.DownloadFileWithHeadCheck(
downloadUrl,
ypkFilePath,
(success) =>
{
downloadCompleted = success;
},
ypkFilePathInDownloads,
(success) => { downloadCompleted = success; },
(progress) =>
{
if (!newVersionDownloaded)
......@@ -214,53 +233,59 @@ public class Menu : WindowServantSP
if (currentProgress >= lastReportedProgress + 10)
{
Program.PrintToChat($"下载进度: {currentProgress}%");
lastReportedProgress = currentProgress; // 更新已报告的进度
lastReportedProgress = currentProgress;
}
}
));
);
yield return Program.I().StartCoroutine(downloadCoroutine);
// 3. 处理下载结果
// --- 4. 处理下载结果 ---
if (!downloadCompleted)
{
Program.PrintToChat("超先行卡更新失败,请检查网络连接或稍后再试。");
isDownloadingSuperPre = false;
yield break; // 提前退出协程
throw new Exception("文件下载失败,请检查网络或稍后再试。");
}
// --- 5. 应用更新 ---
if (newVersionDownloaded)
{
Program.PrintToChat("下载完成,开始解压。");
yield return null;
try
{
// 我们将 .ypk 文件复制为 .zip 来进行解压,而不是重命名它。
File.Copy(ypkFilePath, zipFilePath, true); // `true` 表示如果目标文件已存在则覆盖
// 解压 .zip 文件
byte[] zipData = File.ReadAllBytes(zipFilePath);
Program.I().ExtractZipFile(zipData, expansionsDir);
Program.PrintToChat("解压完成!");
// 清理临时的 .zip 文件并提示用户
File.Delete(zipFilePath);
Program.PrintToChat("超先行卡包已成功应用,请【重启游戏】以使改动完全生效。");
}
catch (Exception e)
{
Program.PrintToChat($"应用更新时发生错误: {e.Message}");
// 如果zip文件还存在,尝试删除
if (File.Exists(zipFilePath))
{
File.Delete(zipFilePath);
}
}
Program.PrintToChat("下载完成,开始应用更新...");
yield return null;
Program.PrintToChat("正在清理旧文件...");
// 同步操作,如果失败会抛出异常
ClearDirectory(expansionsDir);
yield return null;
Program.PrintToChat("正在解压新文件...");
byte[] ypkData = File.ReadAllBytes(ypkFilePathInDownloads);
// 同步操作,如果失败会抛出异常
Program.I().ExtractZipFile(ypkData, expansionsDir);
Program.PrintToChat("更新成功!请【重启游戏】以使改动完全生效。");
}
else
{
Program.PrintToChat("文件已是最新版本,无需下载。");
Program.PrintToChat("您的超先行卡包已是最新版本,无需更新。");
}
}
isDownloadingSuperPre = false;
/// <summary>
/// [辅助方法] 安全地清空一个目录下的所有文件和子目录。
/// </summary>
private void ClearDirectory(string dirPath)
{
if (!Directory.Exists(dirPath)) return;
DirectoryInfo di = new DirectoryInfo(dirPath);
foreach (FileInfo file in di.GetFiles())
{
file.Delete();
}
foreach (DirectoryInfo dir in di.GetDirectories())
{
dir.Delete(true);
}
}
public static void deleteShell()
......
......@@ -2453,8 +2453,8 @@ public class gameCard : OCGobject
.GetComponent<YGO1superShower>();
shower.card.mainTexture = tex;
shower.closeup.mainTexture = texc;
shower.closeup.height = 360;
shower.closeup.width = (int)(360 * shower.closeup.mainTexture.width / shower.closeup.mainTexture.height);
shower.closeup.height = 400;
shower.closeup.width = (int)(400 * shower.closeup.mainTexture.width / shower.closeup.mainTexture.height);
Ocgcore.LRCgo = shower.gameObject;
destroy(shower.gameObject, 0.7f, false, true);
}
......@@ -2516,8 +2516,8 @@ public class gameCard : OCGobject
.GetComponent<YGO1superShower>();
shower.card.mainTexture = tex;
shower.closeup.mainTexture = texc;
shower.closeup.height = 360;
shower.closeup.width = (int)(360 * shower.closeup.mainTexture.width / shower.closeup.mainTexture.height);
shower.closeup.height = 400;
shower.closeup.width = (int)(400 * shower.closeup.mainTexture.width / shower.closeup.mainTexture.height);
Ocgcore.LRCgo = shower.gameObject;
destroy(shower.gameObject, 2f, false, true);
}
......
......@@ -376,7 +376,7 @@ public class GameTextureManager
switch (pic.type)
{
case GameTextureType.card_picture:
case GameTextureType.field_picture:
case GameTextureType.field_picture:
// 卡图和场地直接使用,无需额外处理
texture = tempTexture;
// 因为我们直接用了tempTexture,所以不要销毁它
......@@ -469,59 +469,110 @@ public class GameTextureManager
return new RectInt(x, y, width, height);
}
// private static Texture2D ProcessFeatureTexture(PictureResource pic, Texture2D source)
// {
// RectInt cropRect = GetCardArtRect(pic, source.width, source.height);
// if (cropRect.width <= 0 || cropRect.height <= 0) return null;
// Color32[] pixels = source.GetPixels32();
// int sourceWidth = source.width;
// int newWidth = cropRect.width;
// int newHeight = cropRect.height;
// Color32[] newPixels = new Color32[newWidth * newHeight];
// // 复制裁剪区域的像素
// for (int row = 0; row < newHeight; row++)
// {
// for (int col = 0; col < newWidth; col++)
// {
// int sourceIndex = (cropRect.y + row) * sourceWidth + (cropRect.x + col);
// int destIndex = row * newWidth + col;
// newPixels[destIndex] = pixels[sourceIndex];
// }
// }
// // 应用边缘淡出效果
// float fadeMargin = 40f;
// for (int y = 0; y < newHeight; y++)
// {
// for (int x = 0; x < newWidth; x++)
// {
// float alpha = 1.0f;
// // 计算到四条边的距离
// float distToLeft = x;
// float distToRight = newWidth - 1 - x;
// float distToTop = newHeight - 1 - y;
// float distToBottom = y;
// if (distToLeft < fadeMargin) alpha = Mathf.Min(alpha, distToLeft / fadeMargin);
// if (distToRight < fadeMargin) alpha = Mathf.Min(alpha, distToRight / fadeMargin);
// if (distToTop < fadeMargin) alpha = Mathf.Min(alpha, distToTop / fadeMargin);
// if (distToBottom < fadeMargin) alpha = Mathf.Min(alpha, distToBottom / fadeMargin);
// int index = y * newWidth + x;
// newPixels[index].a = (byte)(newPixels[index].a * alpha * 0.7f); // 乘以0.7f以匹配原效果
// }
// }
// // 创建最终纹理
// Texture2D finalTexture = new Texture2D(newWidth, newHeight, TextureFormat.RGBA32, false);
// finalTexture.SetPixels32(newPixels);
// finalTexture.Apply();
// // 计算k值(基于alpha不为0的最后一行)
// CalculateKValue(pic, newPixels, newWidth, newHeight);
// return finalTexture;
// }
// PictureResource pic 参数可能不再需要,但为了保持调用方代码不变,我们暂时保留它。
private static Texture2D ProcessFeatureTexture(PictureResource pic, Texture2D source)
{
RectInt cropRect = GetCardArtRect(pic, source.width, source.height);
if (cropRect.width <= 0 || cropRect.height <= 0) return null;
// 如果源纹理为空,直接返回
if (source == null) return null;
Color32[] pixels = source.GetPixels32();
int sourceWidth = source.width;
// 1. 不再调用 GetCardArtRect,直接使用源纹理的完整尺寸
int width = source.width;
int height = source.height;
int newWidth = cropRect.width;
int newHeight = cropRect.height;
Color32[] newPixels = new Color32[newWidth * newHeight];
// 2. 获取源纹理的完整像素数组
Color32[] pixels = source.GetPixels32();
// 复制裁剪区域的像素
for (int row = 0; row < newHeight; row++)
{
for (int col = 0; col < newWidth; col++)
{
int sourceIndex = (cropRect.y + row) * sourceWidth + (cropRect.x + col);
int destIndex = row * newWidth + col;
newPixels[destIndex] = pixels[sourceIndex];
}
}
// 3. 不再需要像素拷贝循环,因为我们要在整个纹理上操作
// 应用边缘淡出效果
// 4. 应用边缘淡出效果 (这段逻辑几乎不变,只是作用于整个 'pixels' 数组)
float fadeMargin = 40f;
for (int y = 0; y < newHeight; y++)
for (int y = 0; y < height; y++)
{
for (int x = 0; x < newWidth; x++)
for (int x = 0; x < width; x++)
{
float alpha = 1.0f;
// 计算到四条边的距离
float distToLeft = x;
float distToRight = newWidth - 1 - x;
float distToTop = newHeight - 1 - y;
float distToRight = width - 1 - x;
float distToTop = height - 1 - y; // Y坐标在像素数组中是从上到下的
float distToBottom = y;
// 根据距离计算Alpha衰减
if (distToLeft < fadeMargin) alpha = Mathf.Min(alpha, distToLeft / fadeMargin);
if (distToRight < fadeMargin) alpha = Mathf.Min(alpha, distToRight / fadeMargin);
if (distToTop < fadeMargin) alpha = Mathf.Min(alpha, distToTop / fadeMargin);
if (distToBottom < fadeMargin) alpha = Mathf.Min(alpha, distToBottom / fadeMargin);
int index = y * newWidth + x;
newPixels[index].a = (byte)(newPixels[index].a * alpha * 0.7f); // 乘以0.7f以匹配原效果
int index = y * width + x;
// 将计算出的透明度与原有的透明度相乘
pixels[index].a = (byte)(pixels[index].a * alpha * 0.7f); // 乘以0.7f以匹配原效果
}
}
// 创建最终纹理
Texture2D finalTexture = new Texture2D(newWidth, newHeight, TextureFormat.RGBA32, false);
finalTexture.SetPixels32(newPixels);
// 5. 创建一个与源纹理尺寸相同的新纹理
Texture2D finalTexture = new Texture2D(width, height, TextureFormat.RGBA32, false);
finalTexture.SetPixels32(pixels); // 将修改后的完整像素数组应用上去
finalTexture.Apply();
// 计算k值(基于alpha不为0的最后一行)
CalculateKValue(pic, newPixels, newWidth, newHeight);
// 6. k值计算仍然有效,因为它现在会基于整个处理后的图像进行计算
CalculateKValue(pic, pixels, width, height);
return finalTexture;
}
......
......@@ -4966,7 +4966,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 137080}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -7.89496, y: 0, z: -10.794931}
m_LocalPosition: {x: 0, y: 0, z: -20}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
......
......@@ -19,7 +19,7 @@ MonoBehaviour:
width: 1512
height: 916
m_ShowMode: 4
m_Title: Project
m_Title: Hierarchy
m_RootView: {fileID: 2}
m_MinSize: {x: 875, y: 300}
m_MaxSize: {x: 10000, y: 10000}
......@@ -119,7 +119,7 @@ MonoBehaviour:
m_MinSize: {x: 300, y: 200}
m_MaxSize: {x: 24288, y: 16192}
vertical: 0
controlID: 90
controlID: 53
--- !u!114 &6
MonoBehaviour:
m_ObjectHideFlags: 52
......@@ -144,7 +144,7 @@ MonoBehaviour:
m_MinSize: {x: 200, y: 200}
m_MaxSize: {x: 16192, y: 16192}
vertical: 1
controlID: 91
controlID: 54
--- !u!114 &7
MonoBehaviour:
m_ObjectHideFlags: 52
......@@ -165,11 +165,11 @@ MonoBehaviour:
x: 0
y: 0
width: 1147
height: 444
height: 391
m_MinSize: {x: 200, y: 100}
m_MaxSize: {x: 16192, y: 8096}
vertical: 0
controlID: 92
controlID: 17
--- !u!114 &8
MonoBehaviour:
m_ObjectHideFlags: 52
......@@ -188,9 +188,9 @@ MonoBehaviour:
x: 0
y: 0
width: 282.5
height: 444
m_MinSize: {x: 200, y: 200}
m_MaxSize: {x: 4000, y: 4000}
height: 391
m_MinSize: {x: 201, y: 221}
m_MaxSize: {x: 4001, y: 4021}
m_ActualView: {fileID: 13}
m_Panes:
- {fileID: 13}
......@@ -214,9 +214,9 @@ MonoBehaviour:
x: 282.5
y: 0
width: 864.5
height: 444
m_MinSize: {x: 200, y: 200}
m_MaxSize: {x: 4000, y: 4000}
height: 391
m_MinSize: {x: 202, y: 221}
m_MaxSize: {x: 4002, y: 4021}
m_ActualView: {fileID: 14}
m_Panes:
- {fileID: 12}
......@@ -239,9 +239,9 @@ MonoBehaviour:
m_Position:
serializedVersion: 2
x: 0
y: 444
y: 391
width: 1147
height: 422
height: 475
m_MinSize: {x: 231, y: 271}
m_MaxSize: {x: 10001, y: 10021}
m_ActualView: {fileID: 15}
......@@ -300,7 +300,7 @@ MonoBehaviour:
x: 282.5
y: 96
width: 862.5
height: 423
height: 370
m_ViewDataDictionary: {fileID: 0}
m_OverlayCanvas:
m_LastAppliedPresetName: Default
......@@ -558,9 +558,9 @@ MonoBehaviour:
m_PlayAudio: 0
m_AudioPlay: 0
m_Position:
m_Target: {x: 0.82517153, y: -0.41986775, z: -0.013034212}
m_Target: {x: -0.9613698, y: 0.29541966, z: -0.011044071}
speed: 2
m_Value: {x: 0.82517153, y: -0.41986775, z: -0.013034212}
m_Value: {x: 74.80919, y: 7.592579, z: -0.95798886}
m_RenderMode: 0
m_CameraMode:
drawMode: 0
......@@ -611,9 +611,9 @@ MonoBehaviour:
speed: 2
m_Value: {x: 0, y: 0, z: 0, w: 1}
m_Size:
m_Target: 1.5899264
m_Target: 1.3784163
speed: 2
m_Value: 1.5899264
m_Value: 308.5191
m_Ortho:
m_Target: 1
speed: 2
......@@ -662,7 +662,7 @@ MonoBehaviour:
x: 0
y: 96
width: 281.5
height: 423
height: 370
m_ViewDataDictionary: {fileID: 0}
m_OverlayCanvas:
m_LastAppliedPresetName: Default
......@@ -673,21 +673,21 @@ MonoBehaviour:
scrollPos: {x: 0, y: 0}
m_SelectedIDs:
m_LastClickedID: 0
m_ExpandedIDs: 10b4fcff3eb4fcff18cbfcff1abafdff2abafdff4ebafdff52bafdff42e7fdff40e9fdff88eafdff8eeafdffd0ecfdfffa9cfefffe9cfeffeec9feff92cbffffb6cbffffbacbffffaaf8ffff06fbffff
m_ExpandedIDs: 2c87dfff7e87dfff548bdfff0468e2ffa87ee2ffba7ee2ffde7ee2ff3c80e2ff8e80e2ff5a84e2ff4685eaff7485eaff4e9ceaffdcf7ecffb60eedff2446effffe5cefff7474f2ffe274f2ffe674f2ffb2a1f2ffd6a1f2ff804cf4ffee4cf4fff24cf4ffe279f4ff460df5ffb40df5ffb80df5ffa83af5ff3c2bf6ffaa2bf6ffae2bf6ffc441f6ff7a58f6ff8c58f6ff9e58f6ffce5bf6ffd25bf6ff2c5ff6ff4c5ff6ff9a5ff6ff9e5ff6ff9c60f6ffe002f7fff202f7ff0003f7ff0c03f7ff1a03f7ff4e03f7ff5203f7ff6819f7ff4230f7fff09cf8fff49cf8ffe4c9f8ffb669f9ff246af9ff286af9ff0697f9ff1897f9ff1637faff1a37faff0a64fafffa2bfbfffe2bfbffee58fbff8af7fbff9cf7fbffaaf7fbffb6f7fbffc4f7fbfff8f7fbfffcf7fbffc824fcffec24fcff96e9fcffb0e9fcffe4e9fcffe8e9fcffa216fdffb416fdffc616fdffd816fdffcce5fdfff0e5fdfff4e5fdffe412feff0a95ffff0e95fffffec1ffff06fbffff
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name: Input Highlight
m_OriginalName: Input Highlight
m_Name:
m_OriginalName:
m_EditFieldRect:
serializedVersion: 2
x: 0
y: 0
width: 0
height: 0
m_UserData: -205446
m_UserData: 0
m_IsWaitingForDelay: 0
m_IsRenaming: 0
m_OriginalEventType: 0
m_OriginalEventType: 11
m_IsRenamingFilename: 0
m_ClientGUIView: {fileID: 8}
m_SearchString:
......@@ -721,7 +721,7 @@ MonoBehaviour:
x: 282.5
y: 96
width: 862.5
height: 423
height: 370
m_ViewDataDictionary: {fileID: 0}
m_OverlayCanvas:
m_LastAppliedPresetName: Default
......@@ -754,7 +754,7 @@ MonoBehaviour:
scale: 24
fitToScreenEnabled: 0
rotationDegree: 270
highlightSafeAreaEnabled: 0
highlightSafeAreaEnabled: 1
friendlyName: Apple iPhone 13 Pro Max
networkReachability: 1
systemLanguage: 10
......@@ -780,16 +780,16 @@ MonoBehaviour:
m_Pos:
serializedVersion: 2
x: 0
y: 540
y: 487
width: 1146
height: 401
height: 454
m_ViewDataDictionary: {fileID: 0}
m_OverlayCanvas:
m_LastAppliedPresetName: Default
m_SaveData: []
m_OverlaysVisible: 1
m_SearchFilter:
m_NameFilter: search
m_NameFilter: trans_men
m_ClassNames: []
m_AssetLabels: []
m_AssetBundleNames: []
......@@ -801,7 +801,7 @@ MonoBehaviour:
m_Folders:
- Assets/ArtSystem/gameInfo
m_Globs: []
m_OriginalText: search
m_OriginalText: trans_men
m_FilterByTypeIntersection: 0
m_ViewMode: 1
m_StartGridSize: 64
......@@ -813,9 +813,9 @@ MonoBehaviour:
m_IsLocked: 0
m_FolderTreeState:
scrollPos: {x: 0, y: 179}
m_SelectedIDs: caaf0000
m_LastClickedID: 45002
m_ExpandedIDs: 00000000b2ae0000b4ae0000b6ae0000b8ae0000baae0000bcae0000beae0000c6ae000000ca9a3bffffff7f
m_SelectedIDs: daae0000
m_LastClickedID: 44762
m_ExpandedIDs: 0000000078ae00007aae00007cae00007eae000080ae000082ae000084ae00008cae000000ca9a3bffffff7f
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
......@@ -843,7 +843,7 @@ MonoBehaviour:
scrollPos: {x: 0, y: 0}
m_SelectedIDs:
m_LastClickedID: 0
m_ExpandedIDs: 00000000b2ae0000b4ae0000b6ae0000b8ae0000baae0000bcae0000beae0000
m_ExpandedIDs: 0000000078ae00007aae00007cae00007eae000080ae000082ae000084ae0000
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
......@@ -921,9 +921,9 @@ MonoBehaviour:
m_Pos:
serializedVersion: 2
x: 0
y: 540
y: 487
width: 1146
height: 401
height: 454
m_ViewDataDictionary: {fileID: 0}
m_OverlayCanvas:
m_LastAppliedPresetName: Default
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment