- Timestamp:
- Aug 16, 2019, 7:58:34 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Web/Handlers/ItemIconHandler.cs
r351 r354 53 53 54 54 public bool LoadIcons () { 55 55 56 lock (icons) { 56 57 if (loaded) { … … 59 60 60 61 MicroStopwatch microStopwatch = new MicroStopwatch (); 61 62 GameObject atlasObj = GameObject.Find ("/NGUI Root (2D)/ItemIconAtlas");63 if (atlasObj == null) {64 Log.Error ("Web:IconHandler: Atlas object not found");65 loaded = true;66 return false;67 }68 69 DynamicUIAtlas atlas = atlasObj.GetComponent<DynamicUIAtlas> ();70 if (atlas == null) {71 Log.Error ("Web:IconHandler: Atlas component not found");72 loaded = true;73 return false;74 }75 76 string textureResourceName = atlas.PrebakedAtlas;77 List<UISpriteData> sprites;78 int elementWidth, elementHeight;79 Texture2D atlasTex;80 81 if (!DynamicUIAtlasTools.ReadPrebakedAtlasDescriptor (textureResourceName, out sprites,82 out elementWidth, out elementHeight)) {83 SdtdConsole.Instance.Output ("Web:IconHandler: Could not read dynamic atlas descriptor");84 return false;85 }86 87 if (!DynamicUIAtlasTools.ReadPrebakedAtlasTexture (textureResourceName, out atlasTex)) {88 SdtdConsole.Instance.Output ("Web:IconHandler: Could not read dynamic atlas texture");89 return false;90 }91 62 92 63 // Get list of used tints for all items … … 107 78 } 108 79 109 // Load icons from vanilla 110 foreach (UISpriteData data in sprites) { 111 string name = data.name; 112 Texture2D tex = new Texture2D (data.width, data.height, TextureFormat.ARGB32, false); 113 tex.SetPixels (atlasTex.GetPixels (data.x, atlasTex.height - data.height - data.y, data.width, 114 data.height)); 115 116 AddIcon (name, tex, tintedIcons); 117 118 Object.Destroy (tex); 80 try { 81 loadIconsFromFolder (Utils.GetGameDir ("Data/ItemIcons"), tintedIcons); 82 } catch (Exception e) { 83 Log.Error ("Failed loading icons from base game"); 84 Log.Exception (e); 119 85 } 120 121 Resources.UnloadAsset (atlasTex);122 86 123 87 // Load icons from mods … … 125 89 try { 126 90 string modIconsPath = mod.Path + "/ItemIcons"; 127 if (Directory.Exists (modIconsPath)) { 128 foreach (string file in Directory.GetFiles (modIconsPath)) { 129 try { 130 if (file.EndsWith (".png", StringComparison.OrdinalIgnoreCase)) { 131 string name = Path.GetFileNameWithoutExtension (file); 132 Texture2D tex = new Texture2D (1, 1, TextureFormat.ARGB32, false); 133 if (tex.LoadImage (File.ReadAllBytes (file))) { 134 if (tex.width == elementWidth && tex.height == elementHeight) { 135 AddIcon (name, tex, tintedIcons); 136 } 137 138 Object.Destroy (tex); 139 } 140 } 141 } catch (Exception e) { 142 Log.Exception (e); 143 } 144 } 145 } 91 loadIconsFromFolder (modIconsPath, tintedIcons); 146 92 } catch (Exception e) { 93 Log.Error ("Failed loading icons from mod " + mod.ModInfo.Name.Value); 147 94 Log.Exception (e); 148 95 } … … 153 100 154 101 return true; 102 } 103 } 104 105 private void loadIconsFromFolder (string _path, Dictionary<string, List<Color>> _tintedIcons) { 106 if (Directory.Exists (_path)) { 107 foreach (string file in Directory.GetFiles (_path)) { 108 try { 109 if (file.EndsWith (".png", StringComparison.OrdinalIgnoreCase)) { 110 string name = Path.GetFileNameWithoutExtension (file); 111 Texture2D tex = new Texture2D (1, 1, TextureFormat.ARGB32, false); 112 if (tex.LoadImage (File.ReadAllBytes (file))) { 113 AddIcon (name, tex, _tintedIcons); 114 115 Object.Destroy (tex); 116 } 117 } 118 } catch (Exception e) { 119 Log.Exception (e); 120 } 121 } 155 122 } 156 123 }
Note:
See TracChangeset
for help on using the changeset viewer.