Skip to content

Commit

Permalink
v0.6.1, integrate HerosMod permissions, HideHotbar, tMod 0.11.5, fix #27
Browse files Browse the repository at this point in the history
  • Loading branch information
JavidPack committed Nov 6, 2019
1 parent e144d30 commit 65cbef6
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 38 deletions.
117 changes: 94 additions & 23 deletions CheatSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,28 @@ internal class CheatSheet : Mod
internal NPCButchererHotbar npcButchererHotbar;
internal EventManagerHotbar eventManagerHotbar;

internal Dictionary<string, bool> herosPermissions = new Dictionary<string, bool>();
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()
{
}
Expand All @@ -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");
}
Expand All @@ -71,6 +93,18 @@ public override void Load()
FieldInfo translationsField = typeof(Mod).GetField("translations", BindingFlags.Instance | BindingFlags.NonPublic);
translations = (Dictionary<string, ModTranslation>)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()
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -190,18 +224,19 @@ 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)
{
herosMod.Call(
// 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
Expand All @@ -212,14 +247,37 @@ private void SetupHEROsModIntegration(Mod herosMod)
(Func<string>)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<ValueTuple<string, string>>() {
(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<bool>)((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;
Expand Down Expand Up @@ -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<CheatSheetClientConfig>().HotbarShownByDefault)
if (!ModContent.GetInstance<CheatSheetClientConfig>().HotbarShownByDefault)
hotbar.Hide();
else
hotbar.Show();
}
catch (Exception e)
{
ErrorLogger.Log(e.ToString());
Logger.Error(e.ToString());
}
}
}
Expand Down Expand Up @@ -319,6 +379,9 @@ public override void ModifyInterfaceLayers(List<GameInterfaceLayer> layers)
if (Main.netMode == 0)
{
SpawnRateMultiplier.HasPermission = true;
foreach (var key in herosPermissions.Keys.ToList()) {
herosPermissions[key] = true;
}
}
CheatSheet.instance.hotbar.ChangedConfiguration();
}
Expand All @@ -329,8 +392,7 @@ public override void ModifyInterfaceLayers(List<GameInterfaceLayer> layers)
"CheatSheet: All Cheat Sheet",
delegate
{
AllItemsMenu menu = (AllItemsMenu)this.GetGlobalItem("AllItemsMenu");
menu.DrawUpdateAll(Main.spriteBatch);
GetGlobalItem<AllItemsMenu>().DrawUpdateAll(Main.spriteBatch);
return true;
},
InterfaceScaleType.UI)
Expand All @@ -340,8 +402,7 @@ public override void ModifyInterfaceLayers(List<GameInterfaceLayer> layers)
"CheatSheet: Paint Tools",
delegate
{
AllItemsMenu menu = (AllItemsMenu)this.GetGlobalItem("AllItemsMenu");
menu.DrawUpdatePaintTools(Main.spriteBatch);
GetGlobalItem<AllItemsMenu>().DrawUpdatePaintTools(Main.spriteBatch);
return true;
},
InterfaceScaleType.Game)
Expand All @@ -355,8 +416,7 @@ public override void ModifyInterfaceLayers(List<GameInterfaceLayer> layers)
"CheatSheet: Extra Accessories",
delegate
{
AllItemsMenu menu = (AllItemsMenu)this.GetGlobalItem("AllItemsMenu");
menu.DrawUpdateExtraAccessories(Main.spriteBatch);
GetGlobalItem<AllItemsMenu>().DrawUpdateExtraAccessories(Main.spriteBatch);
return true;
},
InterfaceScaleType.UI)
Expand Down Expand Up @@ -404,12 +464,23 @@ public void RegisterButton(Texture2D texture, Action buttonClickedAction, Func<s

public override object Call(params object[] args)
{
string message = args[0] as string;
if (message == "AddButton_Test")
{
ErrorLogger.Log("Button Adding...");
RegisterButton(args[1] as Texture2D, args[2] as Action, args[3] as Func<string>);
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<string>);
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;
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
Expand Down
43 changes: 29 additions & 14 deletions Menus/Hotbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ public override void Update()
}
catch (Exception e)
{
ErrorLogger.Log(e.ToString());
CheatSheet.instance.Logger.Error(e.ToString());
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1002,6 +1012,11 @@ public void Show()
//{
// mod.eventManagerHotbar.Show();
//}

Mod herosMod = ModLoader.GetMod("HEROsMod");
if (herosMod != null) {
herosMod.Call("HideHotbar");
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions Menus/SpawnRateMultiplier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions UI/UIView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -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\*
Expand Down

0 comments on commit 65cbef6

Please sign in to comment.