Skip to content

Commit

Permalink
Update PluginOptionTab for DrawData removal
Browse files Browse the repository at this point in the history
PluginOptionTab:
	Removed ButtonData
	Added ButtonRect, ButtonPosition, ButtonOffset
	Added TrySetButtonOffset(Point)
	Draws tab button using ButtonPosition and ButtonRect's Size values
PathfinderOptionsMenu relies on tab button offset drawing
  • Loading branch information
Spartan322 committed May 2, 2022
1 parent 187829b commit 7bc7c62
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
2 changes: 2 additions & 0 deletions PathfinderAPI/Options/OptionsManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Pathfinder.GUI;
using BepInEx.Configuration;
using HarmonyLib;
using Hacknet;

namespace Pathfinder.Options;

Expand Down
13 changes: 5 additions & 8 deletions PathfinderAPI/Options/PathfinderOptionsMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,13 @@ internal static bool Draw(ref OptionsMenu __instance, GameTime gameTime)
#pragma warning disable 618
var tabs = OptionsManager.Tabs;
#pragma warning restore 618

int tabX = 10;
int tabX = 10, tabY = 70;

foreach (var tab in OptionsManager.PluginTabs)
{
if(tab.ButtonData.X == null)
{
tab.ButtonData.Set(tabX);
tabX += 10 + tab.ButtonData.Width.GetValueOrDefault();
}
if(tab.TrySetButtonOffset(new Point(tabX, tabY)))
tabX += 10 + tab.ButtonRect.Width;
tab.OnDraw(gameTime);
}

Expand All @@ -91,7 +88,7 @@ internal static bool Draw(ref OptionsMenu __instance, GameTime gameTime)
CurrentTabId = tab.Name;
var active = CurrentTabId == tab.Name;
// Display tab button
if (Button.doButton(tab.ButtonID, tabX, 70, 128, 20, tab.Name, active ? Color.Green : Color.Gray))
if (Button.doButton(tab.ButtonID, tabX, tabY, 128, 20, tab.Name, active ? Color.Green : Color.Gray))
{
CurrentTabId = tab.Name;
break;
Expand Down
20 changes: 14 additions & 6 deletions PathfinderAPI/Options/PluginOptionTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,22 @@ public class PluginOptionTab : IReadOnlyDictionary<string, IPluginOption>
public SpriteBatch Batch { get; internal set; }
public int HacknetGuiId { get; }
public bool IsLoaded { get; internal set; }
public PluginOptionDrawData ButtonData { get; set; } = new PluginOptionDrawData
public Rectangle ButtonRect { get; set; } = new Rectangle
{
X = 0,
Y = 70,
Y = 0,
Width = 128,
Height = 20
};

public Point ButtonPosition => ButtonRect.Location + ButtonOffset;
public Point ButtonOffset { get; protected set; }
public virtual bool TrySetButtonOffset(Point offset)
{
ButtonOffset = offset;
return ButtonOffset == offset;
}

public PluginOptionTab(string tabName, string tabId = null)
{
TabName = tabName;
Expand Down Expand Up @@ -101,10 +109,10 @@ public virtual void OnDraw(GameTime gameTime)
var active = PathfinderOptionsMenu.CurrentTabId == Id;
// Display tab button
if (Button.doButton(HacknetGuiId,
ButtonData.X.GetValueOrDefault(),
ButtonData.Y.GetValueOrDefault(),
ButtonData.Width.GetValueOrDefault(),
ButtonData.Height.GetValueOrDefault(),
ButtonPosition.X,
ButtonPosition.Y,
ButtonRect.Width,
ButtonRect.Height,
TabName,
active ? Color.Green : Color.Gray))
{
Expand Down

0 comments on commit 7bc7c62

Please sign in to comment.