public void AddCharacterOption(int charID, string CharName) //Add option to character list with name CharName { float gapHeight = 45; //height of buttons in list + gap between ScrollArea.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, ScrollArea.rect.height + gapHeight); //Add this height to the scroll area GameObject newOption = Instantiate(Template, Template.transform.parent); //Create new button newOption.SetActive(true); RectTransform NORectTrans = newOption.GetComponent <RectTransform>(); Vector3 newPos = NORectTrans.anchoredPosition; newPos.y -= contentList.Count * gapHeight; //Move down to latest point NORectTrans.anchoredPosition = newPos; ContentInstance inst = newOption.GetComponent <ContentInstance>(); //Character Data inst.ID = charID; inst.CharacterName = CharName; //Set the name //inst.ReloadFile(); //Load any Data from file Button newButton = newOption.GetComponent <Button>(); ColorBlock C = newButton.colors; if (contentList.Count % 2 == 0) { C.normalColor = evenColor; } else { C.normalColor = oddColor; } newButton.colors = C; //Set color depending if even or odd in list contentList.Add(inst); //Add to instant list }
/// <summary> /// Deserialize the <see cref="ContentInstance.Content"/> of a <see cref="ContentInstance"/>. /// </summary> /// <typeparam name="T">The Type of the ContentInstance's Content</typeparam> /// <param name="this">The ContentInstance</param> /// <returns>The content of the ContentInstance</returns> public static T?GetContent <T>(this ContentInstance @this) where T : class { var json = @this.Content as JToken; return(json?.ToObject <T>(Connection.Serializer)); }
public override void Load() { ContentInstance.Register(new UIHelper()); blackPixel = GetTexture("Assets/BlackPixel"); slenderLogo = GetTexture("Assets/Slender"); chad = GetTexture("Assets/THE_CHAD"); storedLogo = Main.logoTexture; storedLogo2 = Main.logo2Texture; Main.logoTexture = GetTexture("Assets/Invisible"); Main.logo2Texture = GetTexture("Assets/Invisible"); MenuHelper.msgOfTheDay = ChooseRandomMessage(rand); rand = Main.rand.Next(0, 20); tick = Main.soundMenuTick; open = Main.soundMenuOpen; close = Main.soundMenuClose; Main.soundMenuTick = GetSound("Sounds/Custom/Other/Nothingness"); Main.soundMenuOpen = GetSound("Sounds/Custom/Other/Nothingness"); Main.soundMenuClose = GetSound("Sounds/Custom/Other/Nothingness"); Mod spooky = ModLoader.GetMod("SpookyTerraria"); Main.versionNumber = $"Terraria {Main.versionNumber}\n{spooky.Name} v{spooky.Version}"; Sprint = RegisterHotKey("Sprint", "LeftShift"); Hooks.On_AddMenuButtons += Hooks_On_AddMenuButtons; Hooks.On_ModLoaderMenus += Hooks_On_ModLoaderMenus;; if (!Main.dedServ) { On.Terraria.Lang.GetRandomGameTitle += Lang_GetRandomGameTitle; Main.chTitle = true; } // MaxMenuItems = 16 On.Terraria.Main.DrawInterface_30_Hotbar += Main_DrawInterface_30_Hotbar; On.Terraria.Main.DrawPlayers += Main_DrawPlayers; On.Terraria.Main.DrawBG += Main_DrawBG; On.Terraria.Main.DrawMenu += Main_DrawMenu; On.Terraria.Main.DrawInterface_35_YouDied += nothing => { }; On.Terraria.Main.Draw += Main_Draw; On.Terraria.IngameOptions.DrawLeftSide += IngameOptions_DrawLeftSide; On.Terraria.IngameOptions.Draw += IngameOptions_Draw; // IL.Terraria.Main.DrawMenu += MoveOptionUI; // Shader initialization if (!Main.dedServ) { // Shaders Ref <Effect> Darkness = new Ref <Effect>(GetEffect("Effects/Darkness")); Filters.Scene["Darkness"] = new Filter(new ScreenShaderData(Darkness, "Darkness"), EffectPriority.VeryHigh); // Skies Filters.Scene["SpookyTerraria:BlackSky"] = new Filter(new ScreenShaderData("FilterTower").UseColor(0.0f, 0.0f, 0.0f).UseOpacity(0f), EffectPriority.Medium); SkyManager.Instance["SpookyTerraria:BlackSky"] = new BlackSky(); } /*ContentInstance.Register(new AmbienceHelper()); * ModContent.GetInstance<AmbienceHelper>().InitializeSoundInstances();*/ }
void ForceCancelPassword() { ContentManager.active.AddMessage("Error when checking for password"); password_inst = null; passwordCheckFunction = ""; passwordCheckID = -1; }
int passwordCheckID = -1; //who you're checking for //Load Save When password is true void PasswordLoadSave(int CharID) { if (password_inst.ID == CharID) { if (passwordCheckFunction == "save") { password_inst.Save(true); password_inst = null; passwordCheckFunction = ""; passwordCheckID = -1; } else if (passwordCheckFunction == "load") { password_inst.Load(true); password_inst = null; passwordCheckFunction = ""; passwordCheckID = -1; } else { ForceCancelPassword(); } } else { ForceCancelPassword(); } }
void ILoadable.Load(Mod mod) { ContentInstance.Register(this); vanillaPlayerTextures = PlayerTextures; vanillaPlayerHairTextures = PlayerHairTextures; vanillaPlayerHairAltTextures = PlayerHairAltTextures; }
public static void Init() { ContentInstance.Register(new SoundChanges()); var mod = ModContent.GetInstance <TerrariaAmbience>(); var changes = Instance; var loader = Ambience.Instance; #region SFX Changes changes.runSFX_Cashe = Main.soundRun; changes.drip_Cashe = Main.soundDrip; changes.liquid_Cashe = Main.soundLiquid; changes.liquidInstance_Cashe = Main.soundInstanceLiquid; changes.dripInstance_Cashe = Main.soundInstanceDrip; changes.splashCashe = Main.soundSplash; changes.zombieCashe = Main.soundZombie; // loader.splashCashe = Main.soundSplash; // Now change the sound (Main.soundX = y) // NOTE: drip.Len = 3 (0, 1 ,2) (3 different variants) // NOTE: liquid.Len = 2 (0, 1) (0 == Water | 1 == Lava) if (!Main.dedServ) { Main.soundRun = mod.GetSound("Sounds/Custom/nothingness"); Main.soundDrip[0] = Ambience.Drip1; Main.soundDrip[1] = Ambience.Drip2; Main.soundDrip[2] = Ambience.Drip3; Main.soundLiquid[0] = Ambience.WaterStream; Main.soundLiquid[1] = Ambience.LavaStream; Main.soundInstanceDrip[0] = Ambience.Drip1Instance; Main.soundInstanceDrip[1] = Ambience.Drip2Instance; Main.soundInstanceDrip[2] = Ambience.Drip3Instance; Main.soundInstanceLiquid[0] = Ambience.WaterStreamInstance; Main.soundInstanceLiquid[1] = Ambience.LavaStreamInstance; Main.soundZombie[0] = mod.GetSound($"{Ambience.AmbientPath}/npcs/zombie1"); Main.soundZombie[1] = mod.GetSound($"{Ambience.AmbientPath}/npcs/zombie2"); Main.soundZombie[2] = mod.GetSound($"{Ambience.AmbientPath}/npcs/zombie3"); } #endregion }
public void Import(LdstrFile file, IMod mod, CultureInfo culture) { ContentInstance.Register(Utils.GetModByName(mod.Name)); var module = mod.Code.ManifestModule; var entryDict = file.LdstrEntries; foreach (var entryPair in entryDict) { var method = module.FindMethod(entryPair.Key); if (method == null) { continue; } var e = entryPair.Value; if (!HaveTranslation(e)) { continue; } var modification = new ILContext.Manipulator(il => { foreach (var instruction in il.Instrs) { var ins = e.Instructions.FirstOrDefault(i => instruction.MatchLdstr(i.Origin)); if (ins == null || string.IsNullOrEmpty(ins.Translation)) { continue; } instruction.Operand = ins.Translation; foreach (var label in il.Labels) { if (label.Target.MatchLdstr(ins.Origin)) { label.Target = instruction; } } } }); if (!modifications.ContainsKey(method)) { HookEndpointManager.Modify(method, modification); modifications.Add(method, modification); } } }
void callDataReceived(int LoadID, string data) //Called when json data is received { if (!isLocalPlayer) { return; } GameObject[] contents = GameObject.FindGameObjectsWithTag("ContentInstance"); foreach (GameObject obj in contents) { ContentInstance inst = obj.GetComponent <ContentInstance>(); if (inst.isLookingFor(LoadID)) { inst.OnClientRecieveData(LoadID, data); //Sends the json data to instances } } }
//////////////// private ILoadable LoadLoadableSingleton(Type loadableClassType) { MethodInfo method = typeof(ModContent).GetMethod("GetInstance"); MethodInfo genericMethod = method.MakeGenericMethod(loadableClassType); object rawInstance = genericMethod?.Invoke(null, new object[] { }); if (rawInstance != null) { return((ILoadable)rawInstance); } var loadable = (ILoadable)Activator.CreateInstance(loadableClassType, ReflectionHelpers.MostAccess); ContentInstance.Register(loadable); return(loadable); }
// Constructor that defines type of object. public ParsingObject(string passedName, List <string> passedContent) { Name = passedName; content = passedContent; if (content.Count > 1) { ObjType = ObjectType.Collection; } else if (ContentInstance.Contains('{')) { ObjType = ObjectType.ComplexObject; } else { ObjType = ObjectType.Primitive; } }
//Call a check for a password public void CheckForPassword(int CharacterID, ContentInstance instance, string checkFunction) { passwordCheckFunction = checkFunction; password_inst = instance; if (passwordCheckFunction == "save") { Networking_Host.active.CmdRequiresSavePassword(Name, CharacterID); } else if (passwordCheckFunction == "load") { Networking_Host.active.CmdRequiresLoadPassword(Name, CharacterID); } else { ForceCancelPassword(); } }
public void SetAsActive(ContentInstance I) //Set the active character { if (I != null) { ColorBlock C; if (activeInstant != null) //Reset old one { C = activeInstant.GetComponent <Button>().colors; C.normalColor = PreColor; activeInstant.GetComponent <Button>().colors = C; } activeInstant = I; //Set here C = activeInstant.GetComponent <Button>().colors; PreColor = C.normalColor; //Store old colors C.normalColor = CurrentColor; //Selection Color activeInstant.GetComponent <Button>().colors = C; } }
//take all the childs and transforms it into a list (prefab, pos, rot). Childs are destroyed public void ContentToList() { content = new List <ContentInstance>(); Dictionary <string, GameObject> foundPrefabs = new Dictionary <string, GameObject>(); string regex = "(\\(Clone\\)| \\(\\d+\\))"; //regex to match for (Clone) or (1) string[] where2look = { "Assets/Prefabs/Collectibles", "Assets/Prefabs/Enemies", "Assets/Prefabs/Special" }; for (int i = transform.childCount - 1; i >= 0; i--) { Transform child = transform.GetChild(i); string realName = Regex.Replace(child.name, regex, ""); GameObject prefab; if (foundPrefabs.ContainsKey(realName)) { prefab = foundPrefabs[realName]; } else { string[] matches = AssetDatabase.FindAssets(realName, where2look); if (matches.Length == 0) { Debug.LogError("Prefab of: " + realName + " not found! Maybe folder isn't included in search"); continue; } prefab = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(matches[0]), typeof(GameObject)) as GameObject; foundPrefabs.Add(realName, prefab); } ContentInstance contentInstance = new ContentInstance(); contentInstance.prefab = prefab; contentInstance.position = child.localPosition; contentInstance.rotation = child.localRotation; content.Add(contentInstance); DestroyImmediate(child.gameObject); } }
public ContentInstances GetInstances(ContentParameter parameters) { ContentInstances instances = new ContentInstances(); foreach (string fileName in base.m_PluginAssemblies) { Assembly contentAssembly = Assembly.LoadFrom(fileName); foreach (Type assemblyType in contentAssembly.GetTypes()) { Type typeInterface = assemblyType.GetInterface("IContent", true); if (assemblyType.IsPublic && !assemblyType.IsAbstract && typeInterface != null) { ContentInstance newContent = new ContentInstance(); newContent.Instance = Activator.CreateInstance(assemblyType) as IContent; try { newContent.Instance.Initialize(parameters); instances.Add(newContent); } catch (Exception ex) { //TODO: Log a message here since the instance couldn't be made } newContent = null; } typeInterface = null; } contentAssembly = null; } return(instances); }
public override void Load() { ContentInstance.Register(new Ambience()); string path = Path.Combine(ModLoader.ModPath, "Cache//ta_secretconfig.txt"); string replacePath = Path.Combine(ModLoader.ModPath, "TASoundReplace"); if (!Directory.Exists(replacePath)) { Directory.CreateDirectory(replacePath); } File.WriteAllText(Path.Combine(replacePath, "README.txt"), "If you are replacing sounds, please read the index/key below for the sounds you might want to replace." + "\nThese replacements will ONLY work if you put it in here word-for-word.\n" + "\nforest_morning\nforest_day\nforest_evening\nforest_night\ndesert_crickets\nsnowfall_day\nsnowfall_night\njungle_day\njungle_night\ncorruption_roars" + "\ncrimson_rumbles\nug_drip\nhell_rumble\nbeach_waves\nbreeze\nrain_new\n\nPlease, do note that these files must be in the WAVE format (.wav)!"); if (File.Exists(path) && File.ReadAllLines(path)[0] != null) { string[] lines = File.ReadAllLines(path); Ambience.TAAmbient = float.Parse(lines[0]); } else { Ambience.TAAmbient = 100f; } if (File.Exists(path) && File.ReadAllLines(path)[1] != null) { string[] lines = File.ReadAllLines(path); Ambience.fStepsVol = float.Parse(lines[1]); } else { Ambience.fStepsVol = 100f; } Ambience.Initialize(); On.Terraria.Main.DoUpdate += Main_DoUpdate; MethodDetours.DetourAll(); Ambience.PlayAllAmbience(); var aLoader = Ambience.Instance; aLoader.dayCricketsVolume = 0f; aLoader.nightCricketsVolume = 0f; aLoader.eveningCricketsVolume = 0f; aLoader.desertCricketsVolume = 0f; aLoader.crackleVolume = 0f; aLoader.ugAmbienceVolume = 0f; aLoader.crimsonRumblesVolume = 0f; aLoader.snowDayVolume = 0f; aLoader.snowNightVolume = 0f; aLoader.corruptionRoarsVolume = 0f; aLoader.dayJungleVolume = 0f; aLoader.nightJungleVolume = 0f; aLoader.beachWavesVolume = 0f; aLoader.hellRumbleVolume = 0f; aLoader.rainVolume = 0f; aLoader.morningCricketsVolume = 0f; aLoader.breezeVolume = 0f; }
protected override void Register() { RaceLoader.AddRace(this); ContentInstance.Register(this); }