/// <summary> /// Loads the sprites used in secondary panels in TNH /// </summary> private void LoadPanelSprites(SetupStage stage) { IFileHandle file = Source.Resources.GetFile("mag_dupe_background.png"); Sprite result = TNHTweakerUtils.LoadSprite(file); MagazinePanel.background = result; file = Source.Resources.GetFile("ammo_purchase_background.png"); result = TNHTweakerUtils.LoadSprite(file); AmmoPurchasePanel.background = result; file = Source.Resources.GetFile("full_auto_background.png"); result = TNHTweakerUtils.LoadSprite(file); FullAutoPanel.background = result; file = Source.Resources.GetFile("fire_rate_background.png"); result = TNHTweakerUtils.LoadSprite(file); FireRatePanel.background = result; file = Source.Resources.GetFile("minus_icon.png"); result = TNHTweakerUtils.LoadSprite(file); FireRatePanel.minusSprite = result; file = Source.Resources.GetFile("plus_icon.png"); result = TNHTweakerUtils.LoadSprite(file); FireRatePanel.plusSprite = result; }
public void LoadAsset(SetupStage stage, Mod mod, IHandle handle) { if (handle is not IDirectoryHandle dir) { throw new ArgumentException("Could not load character! Character should point to a folder holding the character.json and thumb.png"); } try { CustomCharacter character = null; Sprite thumbnail = null; foreach (IFileHandle file in dir.GetFiles()) { if (file.Path.EndsWith("character.json")) { string charString = stage.ImmediateReaders.Get <string>()(file); JsonSerializerSettings settings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; character = JsonConvert.DeserializeObject <CustomCharacter>(charString, settings); } else if (file.Path.EndsWith("thumb.png")) { thumbnail = TNHTweakerUtils.LoadSprite(file); } } if (character == null) { TNHTweakerLogger.LogError("TNHTweaker -- Failed to load custom character! No character.json file found"); return; } else if (thumbnail == null) { TNHTweakerLogger.LogError("TNHTweaker -- Failed to load custom character! No thumb.png file found"); return; } //Now we want to load the icons for each pool foreach (IFileHandle iconFile in dir.GetFiles()) { foreach (EquipmentPool pool in character.EquipmentPools) { if (iconFile.Path.EndsWith(pool.IconName)) { pool.GetPoolEntry().TableDef.Icon = TNHTweakerUtils.LoadSprite(iconFile); } } } TNHTweakerLogger.Log("TNHTweaker -- Character loaded successfuly : " + character.DisplayName, TNHTweakerLogger.LogType.File); LoadedTemplateManager.AddCharacterTemplate(character, thumbnail); } catch (Exception e) { TNHTweakerLogger.LogError("Failed to load setup assets for character! Caused Error: " + e.ToString()); } }