123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using CommonLang;
- using CommonUI.Cell.Game;
- namespace CommonUI.Cell
- {
- public class CPJResource : IDisposable
- {
- protected CPJLoader loader;
- protected HashMap<string, CPJAtlas> images = new HashMap<string, CPJAtlas>();
- protected HashMap<string, CSpriteMeta> sprites = new HashMap<string, CSpriteMeta>();
- // -------------------------------------------------------------------------------------
- public CPJResource(CPJLoader loader)
- {
- this.loader = loader;
- foreach (ImagesSet img in loader.ImgTable.Values)
- {
- CPJAtlas atlas = null;
- if (img.IsTiles)
- {
- atlas = new CPJAtlasTiles(img, this);
- }
- else if (img.SplitSize != 0)
- {
- atlas = new CPJAtlasSplitGroup(img, this);
- }
- else
- {
- atlas = new CPJAtlasGroup(img, this);
- }
- images.Add(img.Name, atlas);
- }
- }
- public CPJLoader Loader
- {
- get { return loader; }
- }
- public void Dispose()
- {
- if (images != null)
- {
- foreach (CPJAtlas img in images.Values)
- {
- img.Dispose();
- }
- images = null;
- }
- if (sprites != null)
- {
- sprites.Clear();
- sprites = null;
- }
- if (loader != null)
- {
- loader.Dispose();
- loader = null;
- }
- }
- public CPJAtlas GetAtlas(String key)
- {
- return images.Get(key);
- }
- public ImagesSet GetSetImages(String key)
- {
- return loader.ImgTable.Get(key);
- }
- public CSpriteMeta GetSpriteMeta(String key)
- {
- if (sprites.ContainsKey(key))
- {
- return sprites.Get(key);
- }
- else
- {
- SpriteSet ss = loader.SprTable.Get(key);
- if (ss != null)
- {
- CPJAtlas img = images.Get(ss.ImagesName);
- if (img != null)
- {
- CSpriteMeta ret = new CSpriteMeta(ss, img);
- sprites.Put(key, ret);
- return ret;
- }
- }
- return null;
- }
- }
-
- public void ReleaseTexture()
- {
- if (images != null)
- {
- foreach (CPJAtlas img in images.Values)
- {
- img.ReleaseTexture();
- }
- }
- }
- //-------------------------------------------------------------------------------------
- public static CPJResource CreateResource(string file_name)
- {
- string prefix = file_name.Substring(0, file_name.LastIndexOf('.'));
- if (CommonLang.IO.Resource.ExistData(prefix + ".bin"))
- {
- CPJLoaderBIN loader = new CPJLoaderBIN(prefix + ".bin");
- return new CPJResource(loader);
- }
- else
- {
- CPJLoaderXML loader = new CPJLoaderXML(file_name);
- return new CPJResource(loader);
- }
- }
-
- //-------------------------------------------------------------------------------------
- }
- }
|