Skip to content

Commit

Permalink
fix: Fixes edge cases with on off items (#1832)
Browse files Browse the repository at this point in the history
### Summary
- Generalizes the On/Off toggle items concept
- Updates the OnOffGump so it is static
- Standardizes OnOff items so they can be used by staff


### Notes
Decided to not fix #1417 because it is not clear that the clilocs or errors are for that purpose. Can't test this on OSI anyways.
  • Loading branch information
kamronbatman committed Jun 11, 2024
1 parent f756cce commit 19f65dc
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 146 deletions.
1 change: 0 additions & 1 deletion Projects/Application/Application.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Diagnostics;
using System.Reflection;
using System.Threading;

namespace Server;

Expand Down
2 changes: 0 additions & 2 deletions Projects/Server.Tests/Fixtures/ServerFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Diagnostics;
using System.Reflection;
using System.Threading;

namespace Server.Tests;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Buffers;
using System.Collections.Generic;
using System.IO.Compression;
using System.Text;
using Server.Compression;
using Server.Gumps;
Expand Down
2 changes: 0 additions & 2 deletions Projects/Server/Events/EventSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
*************************************************************************/

using System;
using System.Collections.Generic;
using Server.Network;

namespace Server;

Expand Down
1 change: 0 additions & 1 deletion Projects/Server/Items/VirtualCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/

using System.Drawing;
using ModernUO.Serialization;
using Server.Gumps;
using Server.Network;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Buffers;
using System.IO;
using System.IO.Compression;
using Server.Compression;

namespace Server.Network
Expand Down
75 changes: 75 additions & 0 deletions Projects/UOContent/Items/Misc/GumpToggleItems.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using Server.Gumps;
using Server.Network;

namespace Server.Items;

public interface IGumpToggleItem
{
public bool IsLockedDown { get; }
public bool TurnedOn { get; set; }
}

public sealed class TurnOnGump : TurnOnOffGump<TurnOnGump>
{
public TurnOnGump(IGumpToggleItem item) : base(item)
{
}

protected override void BuildLayout(ref StaticGumpBuilder builder)
{
base.BuildLayout(ref builder);

builder.AddHtmlLocalized(45, 20, 300, 35, 1011034); // Activate this item
}
}

public sealed class TurnOffGump : TurnOnOffGump<TurnOffGump>
{
public TurnOffGump(IGumpToggleItem item) : base(item)
{
}

protected override void BuildLayout(ref StaticGumpBuilder builder)
{
base.BuildLayout(ref builder);

builder.AddHtmlLocalized(45, 20, 300, 35, 1011035); // Deactivate this item
}
}

public abstract class TurnOnOffGump<T> : StaticGump<T> where T : TurnOnOffGump<T>
{
protected readonly IGumpToggleItem _item;

public TurnOnOffGump(IGumpToggleItem item) : base(150, 200) => _item = item;

protected override void BuildLayout(ref StaticGumpBuilder builder)
{
builder.AddBackground(0, 0, 300, 150, 0xA28);

builder.AddButton(40, 53, 0xFA5, 0xFA7, 1);
builder.AddHtmlLocalized(80, 55, 65, 35, 1011036); // OKAY

builder.AddButton(150, 53, 0xFA5, 0xFA7, 0);
builder.AddHtmlLocalized(190, 55, 100, 35, 1011012); // CANCEL
}

public override void OnResponse(NetState sender, in RelayInfo info)
{
var from = sender.Mobile;

if (info.ButtonID != 1)
{
from.SendLocalizedMessage(502694); // Cancelled action.
return;
}

var newValue = !_item.TurnedOn;
_item.TurnedOn = newValue;

if (newValue && !_item.IsLockedDown)
{
from.SendLocalizedMessage(502693); // Remember, this only works when locked down.
}
}
}
51 changes: 8 additions & 43 deletions Projects/UOContent/Items/Misc/WindChimes.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using ModernUO.Serialization;
using Server.Gumps;
using Server.Multis;
using Server.Network;

namespace Server.Items;

[SerializationGenerator(0, false)]
public abstract partial class BaseWindChimes : Item
public abstract partial class BaseWindChimes : Item, IGumpToggleItem
{
[InvalidateProperties]
[SerializableField(0)]
Expand Down Expand Up @@ -46,55 +44,22 @@ public override void GetProperties(IPropertyList list)
}
}

public bool IsOwner(Mobile mob) => BaseHouse.FindHouseAt(this)?.IsOwner(mob) == true;
public bool HasAccess(Mobile mob) => mob.AccessLevel >= AccessLevel.GameMaster ||
BaseHouse.FindHouseAt(this)?.IsOwner(mob) == true;

public override void OnDoubleClick(Mobile from)
{
if (IsOwner(from))
{
from.SendGump(new OnOffGump(this));
}
else
if (!HasAccess(from))
{
from.SendLocalizedMessage(502691); // You must be the owner to use this.
}
}

private class OnOffGump : Gump
{
private readonly BaseWindChimes m_Chimes;

public OnOffGump(BaseWindChimes chimes) : base(150, 200)
else if (TurnedOn)
{
m_Chimes = chimes;

AddBackground(0, 0, 300, 150, 0xA28);
AddHtmlLocalized(45, 20, 300, 35, chimes.TurnedOn ? 1011035 : 1011034); // [De]Activate this item
AddButton(40, 53, 0xFA5, 0xFA7, 1);
AddHtmlLocalized(80, 55, 65, 35, 1011036); // OKAY
AddButton(150, 53, 0xFA5, 0xFA7, 0);
AddHtmlLocalized(190, 55, 100, 35, 1011012); // CANCEL
from.SendGump(new TurnOffGump(this));
}

public override void OnResponse(NetState sender, in RelayInfo info)
else
{
var from = sender.Mobile;

if (info.ButtonID == 1)
{
var newValue = !m_Chimes.TurnedOn;

m_Chimes.TurnedOn = newValue;

if (newValue && !m_Chimes.IsLockedDown)
{
from.SendLocalizedMessage(502693); // Remember, this only works when locked down.
}
}
else
{
from.SendLocalizedMessage(502694); // Cancelled action.
}
from.SendGump(new TurnOnGump(this));
}
}
}
Expand Down

0 comments on commit 19f65dc

Please sign in to comment.