Skip to content

Commit

Permalink
The LEAVE GUILD button is now a part of the popup, it is no longer di…
Browse files Browse the repository at this point in the history
…splayed next to the EXIT button.
  • Loading branch information
Berzeger committed Feb 5, 2024
1 parent 0e98c46 commit e600beb
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 11 deletions.
5 changes: 3 additions & 2 deletions LeaveGuild.dfmod.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ModTitle": "Leave Guild",
"ModVersion": "1.0.3",
"ModVersion": "1.0.4",
"ModAuthor": "Berzeger",
"DFUnity_Version": "1.0.0",
"ModDescription": "A simple mod that lets you leave guilds. Simply talk to a guild member and you'll find the new option there.",
Expand All @@ -10,6 +10,7 @@
"Assets/Game/Mods/LeaveGuild/Scripts/LeaveGuild.cs",
"Assets/Game/Mods/LeaveGuild/Scripts/LeaveGuildServicePopupWindow.cs",
"Assets/Game/Mods/LeaveGuild/Scripts/LeaveGuildSaveData.cs",
"Assets/Game/Mods/LeaveGuild/modsettings.json"
"Assets/Game/Mods/LeaveGuild/modsettings.json",
"Assets/Game/Mods/LeaveGuild/Textures/BLANKMENU_4.png"
]
}
80 changes: 71 additions & 9 deletions Scripts/LeaveGuildServicePopupWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@
using static Berzeger.LeaveGuildSaveData;
using System;
using System.Reflection;
using DaggerfallWorkshop.Utility.AssetInjection;
using DaggerfallWorkshop.Game.Guilds;

namespace Berzeger
{
public class LeaveGuildServicePopupWindow : DaggerfallGuildServicePopupWindow
{
protected Button leaveButton = new Button();
protected Rect leaveButtonRect = new Rect(5, 33, 35, 15);
protected Rect leaveButtonRect = new Rect(5f, 33f, 120f, 7f);
protected new Rect talkButtonRect = new Rect(5f, 15f, 120f, 7f);
protected new Rect exitButtonRect = new Rect(44f, 42f, 43f, 15f);
private new const string baseTextureName = "BLANKMENU_4";

public LeaveGuildServicePopupWindow(IUserInterfaceManager uiManager, StaticNPC npc, FactionFile.GuildGroups guildGroup, int buildingFactionId)
: base(uiManager, npc, guildGroup, buildingFactionId)
Expand All @@ -32,22 +37,79 @@ protected override void Setup()
{
ResolveQuestOfferLocationsModCompatibility();

// Leave Guild button
TextureReplacement.TryImportTexture(baseTextureName, true, out Texture2D tex);
baseTexture = tex;

// Create interface panel
mainPanel.HorizontalAlignment = HorizontalAlignment.Center;
mainPanel.VerticalAlignment = VerticalAlignment.Middle;
mainPanel.BackgroundTexture = baseTexture;
mainPanel.Position = new Vector2(0, 50);
mainPanel.Size = new Vector2(130, 60);

// Is a member of the guild group (i.e. a temple, a knight order etc.)
bool isGeneralMember = guildManager.GetGuild(guildGroup).IsMember();

// The game generally considers the player a member of a guild if they're a member of any guild belonging to the faction.
// We need to query specifically the one single faction.
bool isSpecificMember = guild.IsMember();

// Join Guild button
joinButton = DaggerfallUI.AddButton(joinButtonRect, mainPanel);
joinButton.Hotkey = DaggerfallShortcut.GetBinding(DaggerfallShortcut.Buttons.GuildsJoin);
joinButton.Label.Text = "JOIN GUILD";
joinButton.Label.TextColor = !isGeneralMember ? DaggerfallUI.DaggerfallDefaultTextColor : DaggerfallUI.DaggerfallDisabledTextColor;
joinButton.Label.HorizontalAlignment = HorizontalAlignment.Center;
joinButton.Label.Position = new Vector2(0, 1);
joinButton.Label.ShadowPosition = Vector2.zero;
if (!isGeneralMember)
{
joinButton.OnMouseClick += JoinButton_OnMouseClick;
}

// Leave Guild button
leaveButton = DaggerfallUI.AddButton(leaveButtonRect, mainPanel);
leaveButton.Label.Text = "LEAVE GUILD";
leaveButton.Label.TextColor = isSpecificMember? DaggerfallUI.DaggerfallDefaultTextColor : DaggerfallUI.DaggerfallDisabledTextColor;
leaveButton.Label.HorizontalAlignment = HorizontalAlignment.Center;
leaveButton.Label.Position = new Vector2(0, 1);
leaveButton.Label.ShadowPosition = Vector2.zero;
leaveButton.Hotkey = DaggerfallShortcut.GetBinding(DaggerfallShortcut.Buttons.GuildsJoin);
// Assign the handler only if the button is enabled
if (isSpecificMember)
{
leaveButton = DaggerfallUI.AddButton(leaveButtonRect, mainPanel);
leaveButton.OnMouseClick += LeaveButton_OnMouseClick;
leaveButton.Label.Text = "LEAVE GUILD";
leaveButton.Label.TextColor = DaggerfallUI.DaggerfallDefaultTextColor;

// we can also reuse the join hotkey - these two buttons are never shown together
leaveButton.Hotkey = DaggerfallShortcut.GetBinding(DaggerfallShortcut.Buttons.GuildsJoin);
}

base.Setup();
// Talk button
talkButton = DaggerfallUI.AddButton(talkButtonRect, mainPanel);
talkButton.OnMouseClick += TalkButton_OnMouseClick;
talkButton.Hotkey = DaggerfallShortcut.GetBinding(DaggerfallShortcut.Buttons.GuildsTalk);
talkButton.OnKeyboardEvent += TalkButton_OnKeyboardEvent;
talkButton.Label.TextColor = DaggerfallUI.DaggerfallDefaultTextColor;
talkButton.Label.Text = "TALK";
talkButton.Label.HorizontalAlignment = HorizontalAlignment.Center;
talkButton.Label.Position = new Vector2(0, 1);
talkButton.Label.ShadowPosition = Vector2.zero;

// Service button
serviceLabel.Position = new Vector2(0, 1);
serviceLabel.ShadowPosition = Vector2.zero;
serviceLabel.HorizontalAlignment = HorizontalAlignment.Center;
serviceLabel.Text = Services.GetServiceLabelText(service).ToUpper();
serviceButton = DaggerfallUI.AddButton(serviceButtonRect, mainPanel);
serviceButton.Components.Add(serviceLabel);
serviceButton.OnMouseClick += ServiceButton_OnMouseClick;
serviceButton.Hotkey = DaggerfallShortcut.GetBinding(Services.GetServiceShortcutButton(service));
serviceButton.OnKeyboardEvent += ServiceButton_OnKeyboardEvent;

// Exit button
exitButton = DaggerfallUI.AddButton(exitButtonRect, mainPanel);
exitButton.OnMouseClick += ExitButton_OnMouseClick;
exitButton.Hotkey = DaggerfallShortcut.GetBinding(DaggerfallShortcut.Buttons.GuildsExit);
exitButton.OnKeyboardEvent += ExitButton_OnKeyboardEvent;

NativePanel.Components.Add(mainPanel);
}

protected virtual void LeaveButton_OnMouseClick(BaseScreenComponent sender, Vector2 position)
Expand Down
8 changes: 8 additions & 0 deletions Textures.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Textures/BLANKMENU_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
104 changes: 104 additions & 0 deletions Textures/BLANKMENU_4.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e600beb

Please sign in to comment.