Commit ab7b6822 authored by mercury233's avatar mercury233

update picture loading

parent a0c8e33c
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text.RegularExpressions;
using UnityEngine; using UnityEngine;
using YGOSharp.OCGWrapper.Enums; using YGOSharp.OCGWrapper.Enums;
...@@ -424,38 +425,35 @@ public class GameField : OCGobject ...@@ -424,38 +425,35 @@ public class GameField : OCGobject
fieldCode[player] = code; fieldCode[player] = code;
if (code > 0) if (code > 0)
{ {
Texture2D tex; Texture2D tex = null;
if (File.Exists("picture/field/" + code.ToString() + ".png")) bool found = false;
foreach (ZipFile zip in GameZipManager.Zips)
{ {
tex = UIHelper.getTexture2D("picture/field/" + code.ToString() + ".png"); if (zip.Name.ToLower().EndsWith("script.zip"))
} continue;
else if (File.Exists("picture/field/" + code.ToString() + ".jpg")) foreach (string file in zip.EntryFileNames)
{
tex = UIHelper.getTexture2D("picture/field/" + code.ToString() + ".jpg");
}
else
{
tex = null;
bool found = false;
foreach (ZipFile zip in GameZipManager.Zips)
{ {
foreach (string file in zip.EntryFileNames) if (Regex.IsMatch(file.ToLower(), "field/" + code.ToString() + "\\.(jpg|png)$"))
{ {
string file1 = file.ToLower(); MemoryStream ms = new MemoryStream();
if (file1.EndsWith(code.ToString() + ".jpg") && file1.Contains("field")) ZipEntry e = zip[file];
{ e.Extract(ms);
MemoryStream ms = new MemoryStream(); tex = new Texture2D(1024, 600);
ZipEntry e = zip[file]; tex.LoadImage(ms.ToArray());
e.Extract(ms); found = true;
tex = new Texture2D(1024, 600);
tex.LoadImage(ms.ToArray());
found = true;
break;
}
}
if (found)
break; break;
}
} }
if (found)
break;
}
if (tex == null)
{
tex = UIHelper.getTexture2D("picture/field/" + code.ToString() + ".png");
}
if (tex == null)
{
tex = UIHelper.getTexture2D("picture/field/" + code.ToString() + ".jpg");
} }
if (tex != null) if (tex != null)
{ {
......
...@@ -287,7 +287,7 @@ public class Program : MonoBehaviour ...@@ -287,7 +287,7 @@ public class Program : MonoBehaviour
}); });
go(300, () => go(300, () =>
{ {
InterString.initialize("config/translation.conf"); InterString.initialize("config/translation.conf");
GameTextureManager.initialize(); GameTextureManager.initialize();
Config.initialize("config/config.conf"); Config.initialize("config/config.conf");
...@@ -324,6 +324,8 @@ public class Program : MonoBehaviour ...@@ -324,6 +324,8 @@ public class Program : MonoBehaviour
foreach (ZipFile zip in GameZipManager.Zips) foreach (ZipFile zip in GameZipManager.Zips)
{ {
if (zip.Name.ToLower().EndsWith("script.zip"))
continue;
foreach (string file in zip.EntryFileNames) foreach (string file in zip.EntryFileNames)
{ {
if (file.ToLower().EndsWith(".conf")) if (file.ToLower().EndsWith(".conf"))
......
...@@ -8,6 +8,7 @@ using UnityEngine; ...@@ -8,6 +8,7 @@ using UnityEngine;
using YGOSharp.OCGWrapper.Enums; using YGOSharp.OCGWrapper.Enums;
using Ionic.Zip; using Ionic.Zip;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
public enum GameTextureType public enum GameTextureType
{ {
...@@ -47,6 +48,32 @@ public class GameTextureManager ...@@ -47,6 +48,32 @@ public class GameTextureManager
} }
} }
} }
init(bitmap);
}
public BitmapHelper(MemoryStream stream)
{
Bitmap bitmap;
try
{
bitmap = (Bitmap)Image.FromStream(stream);
}
catch (Exception)
{
bitmap = new Bitmap(10, 10);
for (int i = 0; i < 10; i++)
{
for (int w = 0; w < 10; w++)
{
bitmap.SetPixel(i, w, System.Drawing.Color.White);
}
}
}
init(bitmap);
}
private void init(Bitmap bitmap)
{
var bmpData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); var bmpData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
IntPtr ptr = bmpData.Scan0; IntPtr ptr = bmpData.Scan0;
int bytes = Math.Abs(bmpData.Stride) * bitmap.Height; int bytes = Math.Abs(bmpData.Stride) * bitmap.Height;
...@@ -67,6 +94,7 @@ public class GameTextureManager ...@@ -67,6 +94,7 @@ public class GameTextureManager
bitmap.UnlockBits(bmpData); bitmap.UnlockBits(bmpData);
bitmap.Dispose(); bitmap.Dispose();
} }
public System.Drawing.Color GetPixel(int a, int b) public System.Drawing.Color GetPixel(int a, int b)
{ {
return colors[a, b]; return colors[a, b];
...@@ -269,12 +297,94 @@ public class GameTextureManager ...@@ -269,12 +297,94 @@ public class GameTextureManager
} }
} }
private static BitmapHelper getCloseup(PictureResource pic)
{
BitmapHelper bitmap = null;
bool found = false;
string code = pic.code.ToString();
foreach (ZipFile zip in GameZipManager.Zips)
{
if (zip.Name.ToLower().EndsWith("script.zip"))
continue;
foreach (string file in zip.EntryFileNames)
{
if (Regex.IsMatch(file.ToLower(), "closeup/" + code + "\\.png$"))
{
MemoryStream ms = new MemoryStream();
ZipEntry e = zip[file];
e.Extract(ms);
bitmap = new BitmapHelper(ms);
found = true;
break;
}
}
if (found)
break;
}
if (!found)
{
string path = "picture/closeup/" + code + ".png";
if (File.Exists(path))
{
bitmap = new BitmapHelper(path);
}
}
return bitmap;
}
private static byte[] getPicture(PictureResource pic, out bool EightEdition)
{
EightEdition = false;
string code = pic.code.ToString();
foreach (ZipFile zip in GameZipManager.Zips)
{
if (zip.Name.ToLower().EndsWith("script.zip"))
continue;
foreach (string file in zip.EntryFileNames)
{
if (Regex.IsMatch(file.ToLower(), "pics/"+code+ "\\.(jpg|png)$"))
{
MemoryStream ms = new MemoryStream();
ZipEntry e = zip[file];
e.Extract(ms);
return ms.ToArray();
}
}
}
string path = "picture/card/" + code + ".png";
if (!File.Exists(path))
{
path = "picture/card/" + code + ".jpg";
}
if (!File.Exists(path))
{
EightEdition = true;
path = "picture/cardIn8thEdition/" + code + ".png";
}
if (!File.Exists(path))
{
EightEdition = true;
path = "picture/cardIn8thEdition/" + code + ".jpg";
}
if (File.Exists(path))
{
using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read))
{
file.Seek(0, SeekOrigin.Begin);
var data = new byte[file.Length];
file.Read(data, 0, (int)file.Length);
return data;
}
}
return new byte[0];
}
private static void ProcessingCardFeature(PictureResource pic) private static void ProcessingCardFeature(PictureResource pic)
{ {
if (File.Exists("picture/closeup/" + pic.code.ToString() + ".png")) bool EightEdition = false;
BitmapHelper bitmap = getCloseup(pic);
if (bitmap != null)
{ {
string path = "picture/closeup/" + pic.code.ToString() + ".png";
BitmapHelper bitmap = new BitmapHelper(path);
int left; int left;
int right; int right;
int up; int up;
...@@ -311,18 +421,8 @@ public class GameTextureManager ...@@ -311,18 +421,8 @@ public class GameTextureManager
} }
else else
{ {
string path = "picture/card/" + pic.code.ToString() + ".png"; var data = getPicture(pic, out EightEdition);
if (!File.Exists(path)) if (data.Length == 0)
{
path = "picture/card/" + pic.code.ToString() + ".jpg";
}
bool Iam8 = false;
if (!File.Exists(path))
{
Iam8 = true;
path = "picture/cardIn8thEdition/" + pic.code.ToString() + ".jpg";
}
if (!File.Exists(path))
{ {
pic.hashed_data = new float[10, 10, 4]; pic.hashed_data = new float[10, 10, 4];
for (int w = 0; w < 10; w++) for (int w = 0; w < 10; w++)
...@@ -342,7 +442,9 @@ public class GameTextureManager ...@@ -342,7 +442,9 @@ public class GameTextureManager
} }
else else
{ {
pic.hashed_data = getCuttedPic(path, pic.pCard,Iam8); MemoryStream stream = new MemoryStream(data);
bitmap = new BitmapHelper(stream);
pic.hashed_data = getCuttedPic(bitmap, pic.pCard, EightEdition);
int width = pic.hashed_data.GetLength(0); int width = pic.hashed_data.GetLength(0);
int height = pic.hashed_data.GetLength(1); int height = pic.hashed_data.GetLength(1);
int size = (int)(height * 0.8); int size = (int)(height * 0.8);
...@@ -440,9 +542,8 @@ public class GameTextureManager ...@@ -440,9 +542,8 @@ public class GameTextureManager
} }
} }
private static float[,,] getCuttedPic(string path,bool pCard,bool EightEdition) private static float[,,] getCuttedPic(BitmapHelper bitmap, bool pCard, bool EightEdition)
{ {
BitmapHelper bitmap = new BitmapHelper(path);
int left = 0, top = 0, right = bitmap.colors.GetLength(0), buttom = bitmap.colors.GetLength(1); int left = 0, top = 0, right = bitmap.colors.GetLength(0), buttom = bitmap.colors.GetLength(1);
//right is width and buttom is height now //right is width and buttom is height now
if (EightEdition) if (EightEdition)
...@@ -569,36 +670,24 @@ public class GameTextureManager ...@@ -569,36 +670,24 @@ public class GameTextureManager
private static void ProcessingVerticleDrawing(PictureResource pic) private static void ProcessingVerticleDrawing(PictureResource pic)
{ {
string path = "picture/closeup/" + pic.code.ToString() + ".png"; var bitmap = getCloseup(pic);
if (!File.Exists(path)) if (bitmap == null)
{ {
path = "picture/card/" + pic.code.ToString() + ".png"; bool EightEdition;
if (!File.Exists(path)) var data = getPicture(pic, out EightEdition);
{ if (data.Length == 0)
path = "picture/card/" + pic.code.ToString() + ".jpg";
}
bool Iam8 = false;
if (!File.Exists(path))
{
Iam8 = true;
path = "picture/cardIn8thEdition/" + pic.code.ToString() + ".jpg";
}
if (!File.Exists(path))
{
path = "texture/duel/unknown.jpg";
}
if (!File.Exists(path))
{ {
return; return;
} }
pic.hashed_data = getCuttedPic(path, pic.pCard,Iam8); MemoryStream stream = new MemoryStream(data);
bitmap = new BitmapHelper(stream);
pic.hashed_data = getCuttedPic(bitmap, pic.pCard, EightEdition);
softVtype(pic, 0.5f); softVtype(pic, 0.5f);
pic.k = 1; pic.k = 1;
//pic.autoMade = true; //pic.autoMade = true;
} }
else else
{ {
BitmapHelper bitmap = new BitmapHelper(path);
int left; int left;
int right; int right;
int up; int up;
...@@ -709,66 +798,26 @@ public class GameTextureManager ...@@ -709,66 +798,26 @@ public class GameTextureManager
private static void ProcessingCardPicture(PictureResource pic) private static void ProcessingCardPicture(PictureResource pic)
{ {
string path = "picture/card/" + pic.code.ToString() + ".png"; bool EightEdition;
if (!File.Exists(path)) var data = getPicture(pic, out EightEdition);
if (data.Length > 0)
{ {
path = "picture/card/" + pic.code.ToString() + ".jpg"; pic.data = data;
} if (!loadedList.ContainsKey(hashPic(pic.code, pic.type)))
if (!File.Exists(path))
{
path = "picture/cardIn8thEdition/" + pic.code.ToString() + ".jpg";
}
if (!File.Exists(path))
{
bool found = false;
foreach (ZipFile zip in GameZipManager.Zips)
{
foreach (string file in zip.EntryFileNames)
{
string file1 = file.ToLower();
if (file1.EndsWith(pic.code.ToString() + ".jpg") && !file1.Contains("field"))
{
MemoryStream ms = new MemoryStream();
ZipEntry e = zip[file];
e.Extract(ms);
pic.data = ms.ToArray();
if (!loadedList.ContainsKey(hashPic(pic.code, pic.type)))
{
loadedList.Add(hashPic(pic.code, pic.type), pic);
}
found = true;
break;
}
}
if (found)
break;
}
if (!found)
{ {
if (pic.code > 0) loadedList.Add(hashPic(pic.code, pic.type), pic);
{
pic.u_data = unknown;
}
else
{
pic.u_data = myBack;
}
if (!loadedList.ContainsKey(hashPic(pic.code, pic.type)))
{
loadedList.Add(hashPic(pic.code, pic.type), pic);
}
} }
} }
else else
{ {
byte[] data; if (pic.code > 0)
using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read))
{ {
file.Seek(0, SeekOrigin.Begin); pic.u_data = unknown;
data = new byte[file.Length]; }
file.Read(data, 0, (int)file.Length); else
{
pic.u_data = myBack;
} }
pic.data = data;
if (!loadedList.ContainsKey(hashPic(pic.code, pic.type))) if (!loadedList.ContainsKey(hashPic(pic.code, pic.type)))
{ {
loadedList.Add(hashPic(pic.code, pic.type), pic); loadedList.Add(hashPic(pic.code, pic.type), pic);
......
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