diff --git a/CheatSheet.cs b/CheatSheet.cs index 6150a6d..6bd4777 100644 --- a/CheatSheet.cs +++ b/CheatSheet.cs @@ -42,6 +42,28 @@ internal class CheatSheet : Mod internal NPCButchererHotbar npcButchererHotbar; internal EventManagerHotbar eventManagerHotbar; + internal Dictionary herosPermissions = new Dictionary(); + internal const string ModifySpawnRateMultiplier_Permission = "ModifySpawnRateMultiplier"; + internal const string ModifySpawnRateMultiplier_Display = "Modify Spawn Rate Multiplier"; + internal const string PaintTools_Permission = "PaintTools"; + internal const string PaintTools_Display = "Paint Tools"; + internal const string RecipeBrowser_Permission = "RecipeBrowser"; + internal const string RecipeBrowser_Display = "Recipe Browser"; + internal const string MinionBooster_Permission = "MinionBooster"; + internal const string MinionBooster_Display = "Minion Booster"; + internal const string ClearItemNPCProjectile_Permission = "ClearItemNPCProjectile"; + internal const string ClearItemNPCProjectile_Display = "Clear Item NPC Projectile"; + internal const string ExtraAccessories_Permission = "ExtraAccessories"; + internal const string ExtraAccessories_Display = "Extra Accessories"; + internal const string Vacuum_Permission = "Vacuum"; + internal const string Vacuum_Display = "Vacuum"; + internal const string NPCButcher_Permission = "NPCButcher"; + internal const string NPCButcher_Display = "NPC Butcher"; + internal const string CheatSheetExtensions_Permission = "CheatSheetExtensions"; + internal const string CheatSheetExtensions_Display = "Cheat Sheet Extensions"; + internal const string QuickTeleport_Permission = "QuickTeleport"; + internal const string QuickTeleport_Display = "Quick Teleport"; + public CheatSheet() { } @@ -51,7 +73,7 @@ public CheatSheet() public override void Load() { // Since we are using hooks not in older versions, and since ItemID.Count changed, we need to do this. - if (ModLoader.version < new Version(0, 10, 1, 3)) + if (ModLoader.version < new Version(0, 11, 5)) { throw new Exception("\nThis mod uses functionality only present in the latest tModLoader. Please update tModLoader to use this mod\n\n"); } @@ -71,6 +93,18 @@ public override void Load() FieldInfo translationsField = typeof(Mod).GetField("translations", BindingFlags.Instance | BindingFlags.NonPublic); translations = (Dictionary)translationsField.GetValue(this); //LoadTranslations(); + + // set all to true on load + herosPermissions[PaintTools_Permission] = true; + herosPermissions[ModifySpawnRateMultiplier_Permission] = true; + herosPermissions[RecipeBrowser_Permission] = true; + herosPermissions[MinionBooster_Permission] = true; + herosPermissions[ClearItemNPCProjectile_Permission] = true; + herosPermissions[ExtraAccessories_Permission] = true; + herosPermissions[Vacuum_Permission] = true; + herosPermissions[NPCButcher_Permission] = true; + herosPermissions[CheatSheetExtensions_Permission] = true; + herosPermissions[QuickTeleport_Permission] = true; } public override void Unload() @@ -179,7 +213,7 @@ public override void PostSetupContent() } catch (Exception e) { - ErrorLogger.Log("CheatSheet->HEROsMod PostSetupContent Error: " + e.StackTrace + e.Message); + Logger.Error("CheatSheet->HEROsMod PostSetupContent Error: " + e.StackTrace + e.Message); } } @@ -190,10 +224,11 @@ private void SetupHEROsModIntegration(Mod herosMod) // Special string "AddPermission", // Permission Name - "ModifySpawnRateMultiplier", + ModifySpawnRateMultiplier_Permission, // Permission Display Name - "Modify Spawn Rate Multiplier" + ModifySpawnRateMultiplier_Display ); + // Add Buttons only to non-servers (otherwise the server will crash, since textures aren't loaded on servers) if (!Main.dedServ) { @@ -201,7 +236,7 @@ private void SetupHEROsModIntegration(Mod herosMod) // Special string "AddSimpleButton", // Name of Permission governing the availability of the button/tool - "ModifySpawnRateMultiplier", + ModifySpawnRateMultiplier_Permission, // Texture of the button. 38x38 is recommended for HERO's Mod. Also, a white outline on the icon similar to the other icons will look good. Main.itemTexture[ItemID.WaterCandle], // A method that will be called when the button is clicked @@ -212,14 +247,37 @@ private void SetupHEROsModIntegration(Mod herosMod) (Func)SpawnRateMultiplier.HEROsTooltip ); } + + // Other non-tutorial permissions. + // For simplicity, not doing buttons in Heros, just permissions for most tools. + // Could implement most without sub-menus as buttons if I have time. Right and left click support in Heros desireable. + var permissions = new List>() { + (PaintTools_Permission, PaintTools_Display), + (RecipeBrowser_Permission, RecipeBrowser_Display), + (MinionBooster_Permission,MinionBooster_Display), + (ClearItemNPCProjectile_Permission,ClearItemNPCProjectile_Display), + (ExtraAccessories_Permission,ExtraAccessories_Display), + (Vacuum_Permission,Vacuum_Display), + (NPCButcher_Permission,NPCButcher_Display), + (CheatSheetExtensions_Permission,CheatSheetExtensions_Display), + (QuickTeleport_Permission,QuickTeleport_Display), + }; + foreach (var permission in permissions) { + herosMod.Call("AddPermission", permission.Item1, permission.Item2, (Action)((hasPermission) => HEROsPermissionChanged(permission.Item1, hasPermission))); + } + } + + public void HEROsPermissionChanged(string permission, bool hasPermission) { + herosPermissions[permission] = hasPermission; + // This is called a bunch at once, a little wasteful. + CheatSheet.instance.hotbar.ChangedConfiguration(); } public override void AddRecipeGroups() { if (!Main.dedServ) { - try - { + try { itemBrowser = new ItemBrowser(this); itemBrowser.SetDefaultPosition(new Vector2(80, 300)); itemBrowser.Visible = false; @@ -264,12 +322,14 @@ public override void AddRecipeGroups() hotbar = new Hotbar(this); //hotbar.Position = new Microsoft.Xna.Framework.Vector2(120, 180); hotbar.Visible = true; - if(!GetConfig().HotbarShownByDefault) + if (!ModContent.GetInstance().HotbarShownByDefault) hotbar.Hide(); + else + hotbar.Show(); } catch (Exception e) { - ErrorLogger.Log(e.ToString()); + Logger.Error(e.ToString()); } } } @@ -319,6 +379,9 @@ public override void ModifyInterfaceLayers(List layers) if (Main.netMode == 0) { SpawnRateMultiplier.HasPermission = true; + foreach (var key in herosPermissions.Keys.ToList()) { + herosPermissions[key] = true; + } } CheatSheet.instance.hotbar.ChangedConfiguration(); } @@ -329,8 +392,7 @@ public override void ModifyInterfaceLayers(List layers) "CheatSheet: All Cheat Sheet", delegate { - AllItemsMenu menu = (AllItemsMenu)this.GetGlobalItem("AllItemsMenu"); - menu.DrawUpdateAll(Main.spriteBatch); + GetGlobalItem().DrawUpdateAll(Main.spriteBatch); return true; }, InterfaceScaleType.UI) @@ -340,8 +402,7 @@ public override void ModifyInterfaceLayers(List layers) "CheatSheet: Paint Tools", delegate { - AllItemsMenu menu = (AllItemsMenu)this.GetGlobalItem("AllItemsMenu"); - menu.DrawUpdatePaintTools(Main.spriteBatch); + GetGlobalItem().DrawUpdatePaintTools(Main.spriteBatch); return true; }, InterfaceScaleType.Game) @@ -355,8 +416,7 @@ public override void ModifyInterfaceLayers(List layers) "CheatSheet: Extra Accessories", delegate { - AllItemsMenu menu = (AllItemsMenu)this.GetGlobalItem("AllItemsMenu"); - menu.DrawUpdateExtraAccessories(Main.spriteBatch); + GetGlobalItem().DrawUpdateExtraAccessories(Main.spriteBatch); return true; }, InterfaceScaleType.UI) @@ -404,12 +464,23 @@ public void RegisterButton(Texture2D texture, Action buttonClickedAction, Func); - ErrorLogger.Log("...Button Added"); + try { + string message = args[0] as string; + if (message == "AddButton_Test") + { + Logger.Info("Button Adding..."); + RegisterButton(args[1] as Texture2D, args[2] as Action, args[3] as Func); + Logger.Info("...Button Added"); + } + else if (message == "HideHotbar") { + hotbar.Hide(); + } + else { + Logger.Error("Call Error: Unknown Message: " + message); + } + } + catch (Exception e) { + Logger.Error("Call Error: " + e.StackTrace + e.Message); } return null; } @@ -506,7 +577,7 @@ public override void HandlePacket(BinaryReader reader, int whoAmI) // NPCSlot.HandleFilterRequest(reader.ReadInt32(), reader.ReadInt32(), true); // break; default: - ErrorLogger.Log("CheatSheet: Unknown Message type: " + msgType); + Logger.Warn("Unknown Message type: " + msgType); break; } } @@ -620,7 +691,7 @@ static class CheatSheetUtilities internal static void ReportException(Exception e) { - ErrorLogger.Log("CheatSheet: " + e.Message + e.StackTrace); + CheatSheet.instance.Logger.Error("CheatSheet: " + e.Message + e.StackTrace); try { ReportData data = new ReportData(e); diff --git a/Menus/Hotbar.cs b/Menus/Hotbar.cs index 3d44e71..dbed2f5 100644 --- a/Menus/Hotbar.cs +++ b/Menus/Hotbar.cs @@ -740,7 +740,7 @@ public override void Update() } catch (Exception e) { - ErrorLogger.Log(e.ToString()); + CheatSheet.instance.Logger.Error(e.ToString()); } } @@ -852,19 +852,29 @@ private bool ControlExists(UIView view) public void ChangedConfiguration() { DisableAllWindows(); - bToggleItemBrowser.Visible = ConfigurationLoader.personalConfiguration.ItemBrowser; - bToggleNPCBrowser.Visible = ConfigurationLoader.personalConfiguration.NPCBrowser; - bToggleRecipeBrowser.Visible = ConfigurationLoader.personalConfiguration.RecipeBrowser; - MinionSlotBooster.button.Visible = ConfigurationLoader.personalConfiguration.MinionBooster; - bToggleClearMenu.Visible = ConfigurationLoader.personalConfiguration.ClearMenu; - bTogglePaintTools.Visible = ConfigurationLoader.personalConfiguration.PaintTools; - bToggleExtendedCheat.Visible = ConfigurationLoader.personalConfiguration.ModExtensions; - bCycleExtraAccessorySlots.Visible = ConfigurationLoader.personalConfiguration.ExtraAccessorySlots; - bVacuum.Visible = ConfigurationLoader.personalConfiguration.Vacuum; - bToggleNPCButcherer.Visible = ConfigurationLoader.personalConfiguration.Butcher; - bToggleQuickTeleport.Visible = ConfigurationLoader.personalConfiguration.Waypoints; - LightHack.button.Visible = ConfigurationLoader.personalConfiguration.LightHack; - GodMode.button.Visible = ConfigurationLoader.personalConfiguration.GodMode; + Mod herosMod = ModLoader.GetMod("HEROsMod"); + bool heros = ModLoader.GetMod("HEROsMod") != null; + bool recentHeros = herosMod != null && herosMod.Version >= new Version(0, 2, 2); + bool itemBrowserPermissions = true; + if (Main.netMode == 1 && recentHeros && herosMod.Call("HasPermission", Main.myPlayer, "ItemBrowser") is bool resultA) + itemBrowserPermissions = resultA; + bool SpawnNPCsPermissions = true; + if (Main.netMode == 1 && recentHeros && herosMod.Call("HasPermission", Main.myPlayer, "SpawnNPCs") is bool resultB) + SpawnNPCsPermissions = resultB; + + bToggleItemBrowser.Visible = ConfigurationLoader.personalConfiguration.ItemBrowser && itemBrowserPermissions; + bToggleNPCBrowser.Visible = ConfigurationLoader.personalConfiguration.NPCBrowser && SpawnNPCsPermissions; + bToggleRecipeBrowser.Visible = ConfigurationLoader.personalConfiguration.RecipeBrowser && CheatSheet.instance.herosPermissions[CheatSheet.RecipeBrowser_Permission]; + MinionSlotBooster.button.Visible = ConfigurationLoader.personalConfiguration.MinionBooster && CheatSheet.instance.herosPermissions[CheatSheet.MinionBooster_Permission]; + bToggleClearMenu.Visible = ConfigurationLoader.personalConfiguration.ClearMenu && CheatSheet.instance.herosPermissions[CheatSheet.ClearItemNPCProjectile_Permission]; + bTogglePaintTools.Visible = ConfigurationLoader.personalConfiguration.PaintTools && CheatSheet.instance.herosPermissions[CheatSheet.PaintTools_Permission]; + bToggleExtendedCheat.Visible = ConfigurationLoader.personalConfiguration.ModExtensions && CheatSheet.instance.herosPermissions[CheatSheet.CheatSheetExtensions_Permission]; + bCycleExtraAccessorySlots.Visible = ConfigurationLoader.personalConfiguration.ExtraAccessorySlots && CheatSheet.instance.herosPermissions[CheatSheet.ExtraAccessories_Permission]; + bVacuum.Visible = ConfigurationLoader.personalConfiguration.Vacuum && CheatSheet.instance.herosPermissions[CheatSheet.Vacuum_Permission]; + bToggleNPCButcherer.Visible = ConfigurationLoader.personalConfiguration.Butcher && CheatSheet.instance.herosPermissions[CheatSheet.NPCButcher_Permission]; + bToggleQuickTeleport.Visible = ConfigurationLoader.personalConfiguration.Waypoints && CheatSheet.instance.herosPermissions[CheatSheet.QuickTeleport_Permission]; + LightHack.button.Visible = ConfigurationLoader.personalConfiguration.LightHack && !heros; + GodMode.button.Visible = ConfigurationLoader.personalConfiguration.GodMode && !heros; SpawnRateMultiplier.button.Visible = ConfigurationLoader.personalConfiguration.SpawnRate && SpawnRateMultiplier.HasPermission; //BossDowner.button.Visible = ConfigurationLoader.configuration.BossDowner; //bToggleEventManager.Visible = ConfigurationLoader.configuration.EventManager; @@ -1002,6 +1012,11 @@ public void Show() //{ // mod.eventManagerHotbar.Show(); //} + + Mod herosMod = ModLoader.GetMod("HEROsMod"); + if (herosMod != null) { + herosMod.Call("HideHotbar"); + } } } } diff --git a/Menus/SpawnRateMultiplier.cs b/Menus/SpawnRateMultiplier.cs index 3400a77..f359857 100644 --- a/Menus/SpawnRateMultiplier.cs +++ b/Menus/SpawnRateMultiplier.cs @@ -79,6 +79,8 @@ internal static void RequestSetSpawnRate(int index) // Action taken by sever receiving button internal static void HandleSetSpawnRate(BinaryReader reader, int whoAmI) { + // TODO: Don't just trust UI? Lazy. + int newSetting = reader.ReadInt32(); ChangeSettingLogic(newSetting); diff --git a/UI/UIView.cs b/UI/UIView.cs index 789a2f7..c5974af 100644 --- a/UI/UIView.cs +++ b/UI/UIView.cs @@ -461,6 +461,9 @@ protected virtual Vector2 GetOrigin() protected virtual bool IsMouseInside() { + if (MouseX > Main.screenWidth || MouseX < 0 || MouseY > Main.screenHeight || MouseY < 0) + return false; + Vector2 vector = this.DrawPosition - this.Origin; return (float)UIView.MouseX >= vector.X && (float)UIView.MouseX <= vector.X + this.Width && (float)UIView.MouseY >= vector.Y && (float)UIView.MouseY <= vector.Y + this.Height; } diff --git a/build.txt b/build.txt index cf14ae2..3154ede 100644 --- a/build.txt +++ b/build.txt @@ -1,5 +1,5 @@ author = jopojelly, jofairden, rrryutaro -version = 0.6.0.1 +version = 0.6.1 displayName = Cheat Sheet homepage = http://forums.terraria.org/index.php?threads/cheat-sheet.41407/ buildIgnore = .vs\*, Properties\*, *.csproj, *.user, obj\*, bin\*, *.config, .git\*