fix(core): Adds Gump component functionality (#377)

- [X] Adds gump close packet
- [X] Fixes gump tooltip
- [X] Adds new compile/append functions for the new gump packets
This commit is contained in:
Kamron Batman 2021-01-02 19:08:35 -08:00 committed by GitHub
parent cc91fe2b10
commit 3b413371dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
40 changed files with 1696 additions and 137 deletions

View file

@ -0,0 +1,123 @@
using System.Collections.Generic;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using Server.Collections;
namespace Benchmarks
{
[MemoryDiagnoser]
[SimpleJob(RuntimeMoniker.NetCoreApp50)]
public class BenchmarkOrderedHashSet
{
private List<string> _list;
private OrderedHashSet<string> _ordered;
private HashSet<string> _hashSet;
private const int iterations = 16;
[IterationSetup]
public void IterationSetup()
{
_list = new List<string>();
_ordered = new OrderedHashSet<string>();
_hashSet = new HashSet<string>();
}
[IterationCleanup]
public void IterationCleanup()
{
_list = null;
_ordered = null;
_hashSet = null;
}
[Benchmark]
public int UsingList()
{
for (int i = 0; i < iterations / 2; i++)
{
AddIfNotPresent(_list, i.ToString());
}
for (int i = 0; i < iterations; i++)
{
AddIfNotPresent(_list, i.ToString());
}
for (int i = 0; i < iterations * 2; i++)
{
AddIfNotPresent(_list, i.ToString());
}
for (int i = 0; i < _list.Count; i++)
{
_list[i].ToString();
}
return _list.Count;
}
private static int AddIfNotPresent<T>(List<T> list, T item)
{
var index = list.IndexOf(item);
if (index > -1)
{
return index;
}
list.Add(item);
return list.Count - 1;
}
[Benchmark]
public int UsingOrderedHashSet()
{
for (int i = 0; i < iterations / 2; i++)
{
_ordered.GetOrAdd(i.ToString());
}
for (int i = 0; i < iterations; i++)
{
_ordered.GetOrAdd(i.ToString());
}
for (int i = 0; i < iterations * 2; i++)
{
_ordered.GetOrAdd(i.ToString());
}
foreach (var str in _ordered)
{
str.ToString();
}
return _ordered.Count;
}
[Benchmark]
public int UsingHashSet()
{
for (int i = 0; i < iterations / 2; i++)
{
_hashSet.Add(i.ToString());
}
for (int i = 0; i < iterations; i++)
{
_hashSet.Add(i.ToString());
}
for (int i = 0; i < iterations * 2; i++)
{
_hashSet.Add(i.ToString());
}
foreach (var str in _hashSet)
{
str.ToString();
}
return _hashSet.Count;
}
}
}

View file

@ -10,7 +10,8 @@ namespace Benchmarks
// var featureFlags = BenchmarkRunner.Run<BenchmarkFeatureFlags>();
// var packetConstruction = BenchmarkRunner.Run<BenchmarkPacketConstruction>();
// var broadcast = BenchmarkRunner.Run<BenchmarkPacketBroadcast>();
var stringHelpers = BenchmarkRunner.Run<BenchmarkStringHelpers>();
// var stringHelpers = BenchmarkRunner.Run<BenchmarkStringHelpers>();
var indexList = BenchmarkRunner.Run<BenchmarkOrderedHashSet>();
}
}
}

View file

@ -0,0 +1,24 @@
using System.Linq;
using Server.Collections;
using Xunit;
namespace Server.Tests
{
public class OrderedHashSetTests
{
[Fact]
public void TestOrderedHashSet()
{
var set = new OrderedHashSet<string>(1) { "random string1", "another random string1", "another random string2", "another random string3" };
set.Remove("another random string1");
var list = set.ToList();
string[] arr = { "random string1", "another random string2", "another random string3" };
int i = 0;
foreach (var entry in list)
{
Assert.Equal(entry, arr[i++]);
}
}
}
}

View file

@ -1,74 +0,0 @@
/*************************************************************************
* ModernUO *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: ArraySet.cs *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
using System;
using System.Collections;
using System.Collections.Generic;
namespace Server.Collections
{
public class ArraySet<T> : IList<T>
{
private readonly List<T> m_List = new();
public T this[int index]
{
get => m_List[index];
set => m_List[index] = value;
}
public int Count => m_List.Count;
public bool IsReadOnly => false;
public void Clear() => m_List.Clear();
public bool Contains(T item) => m_List.Contains(item);
public void CopyTo(T[] array, int arrayIndex) => m_List.CopyTo(array, arrayIndex);
public IEnumerator<T> GetEnumerator() => m_List.GetEnumerator();
public int IndexOf(T item) => m_List.IndexOf(item);
public void Insert(int index, T item) => throw new NotImplementedException();
public bool Remove(T item) => throw new NotImplementedException();
public void RemoveAt(int index) => throw new NotImplementedException();
void ICollection<T>.Add(T item) => m_List.Add(item);
IEnumerator IEnumerable.GetEnumerator() => m_List.GetEnumerator();
public int Add(T item)
{
var indexOf = m_List.IndexOf(item);
if (indexOf >= 0)
{
return indexOf;
}
m_List.Add(item);
return m_List.Count - 1;
}
public void CopyTo(T[] array) => m_List.CopyTo(array);
public void CopyTo(int index, T[] array, int arrayIndex, int count) =>
m_List.CopyTo(index, array, arrayIndex, count);
}
}

View file

@ -0,0 +1,102 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics;
namespace Microsoft.Collections.Extensions
{
internal static class HashHelpers
{
// must never be written to
internal static readonly int[] SizeOneIntArray = new int[1];
// This is the maximum prime smaller than Array.MaxArrayLength
public const int MaxPrimeArrayLength = 0x7FEFFFFD;
public const int HashPrime = 101;
// Table of prime numbers to use as hash table sizes.
// A typical resize algorithm would pick the smallest prime number in this array
// that is larger than twice the previous capacity.
// Suppose our Hashtable currently has capacity x and enough elements are added
// such that a resize needs to occur. Resizing first computes 2x then finds the
// first prime in the table greater than 2x, i.e. if primes are ordered
// p_1, p_2, ..., p_i, ..., it finds p_n such that p_n-1 < 2x < p_n.
// Doubling is important for preserving the asymptotic complexity of the
// hashtable operations such as add. Having a prime guarantees that double
// hashing does not lead to infinite loops. IE, your hash function will be
// h1(key) + i*h2(key), 0 <= i < size. h2 and the size must be relatively prime.
// We prefer the low computation costs of higher prime numbers over the increased
// memory allocation of a fixed prime number i.e. when right sizing a HashSet.
public static readonly int[] primes = {
3, 7, 11, 17, 23, 29, 37, 47, 59, 71, 89, 107, 131, 163, 197, 239, 293, 353, 431, 521, 631, 761, 919,
1103, 1327, 1597, 1931, 2333, 2801, 3371, 4049, 4861, 5839, 7013, 8419, 10103, 12143, 14591,
17519, 21023, 25229, 30293, 36353, 43627, 52361, 62851, 75431, 90523, 108631, 130363, 156437,
187751, 225307, 270371, 324449, 389357, 467237, 560689, 672827, 807403, 968897, 1162687, 1395263,
1674319, 2009191, 2411033, 2893249, 3471899, 4166287, 4999559, 5999471, 7199369 };
public static bool IsPrime(int candidate)
{
if ((candidate & 1) != 0)
{
int limit = (int)Math.Sqrt(candidate);
for (int divisor = 3; divisor <= limit; divisor += 2)
{
if (candidate % divisor == 0)
{
return false;
}
}
return true;
}
return candidate == 2;
}
public static int GetPrime(int min)
{
if (min < 0)
{
throw new ArgumentException("Hashtable's capacity overflowed and went negative. Check load factor, capacity and the current size of the table.");
}
for (int i = 0; i < primes.Length; i++)
{
int prime = primes[i];
if (prime >= min)
{
return prime;
}
}
//outside of our predefined table.
//compute the hard way.
for (int i = min | 1; i < int.MaxValue; i += 2)
{
if (IsPrime(i) && (i - 1) % HashPrime != 0)
{
return i;
}
}
return min;
}
// Returns size of hashtable to grow to.
public static int ExpandPrime(int oldSize)
{
int newSize = 2 * oldSize;
// Allow the hashtables to grow to maximum possible size (~2G elements) before encountering capacity overflow.
// Note that this check works even when _items.Length overflowed thanks to the (uint) cast
if ((uint)newSize > MaxPrimeArrayLength && MaxPrimeArrayLength > oldSize)
{
Debug.Assert(MaxPrimeArrayLength == GetPrime(MaxPrimeArrayLength), "Invalid MaxPrimeArrayLength");
return MaxPrimeArrayLength;
}
return GetPrime(newSize);
}
}
}

View file

@ -0,0 +1,144 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2021 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: OrderedHashSet.ValueCollection.cs *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
namespace Server.Collections
{
public partial class OrderedHashSet<TValue>
{
[DebuggerDisplay("Count = {Count}")]
public sealed class ValueCollection : IList<TValue>, IReadOnlyList<TValue>
{
private readonly OrderedHashSet<TValue> _orderedHashSet;
private const string NotSupported_ValueCollectionSet =
"Mutating a key collection derived from a hash set is not allowed.";
public int Count => _orderedHashSet.Count;
public TValue this[int index] => ((IList<TValue>)_orderedHashSet)[index];
TValue IList<TValue>.this[int index]
{
get => this[index];
set => throw new NotSupportedException(NotSupported_ValueCollectionSet);
}
bool ICollection<TValue>.IsReadOnly => true;
internal ValueCollection(OrderedHashSet<TValue> OrderedHashSet) =>
_orderedHashSet = OrderedHashSet;
public Enumerator GetEnumerator() => new Enumerator(_orderedHashSet);
IEnumerator<TValue> IEnumerable<TValue>.GetEnumerator() => GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
int IList<TValue>.IndexOf(TValue item) => _orderedHashSet.IndexOf(item);
void IList<TValue>.Insert(int index, TValue item) => throw new NotSupportedException(NotSupported_ValueCollectionSet);
void IList<TValue>.RemoveAt(int index) => throw new NotSupportedException(NotSupported_ValueCollectionSet);
void ICollection<TValue>.Add(TValue item) => throw new NotSupportedException(NotSupported_ValueCollectionSet);
void ICollection<TValue>.Clear() => throw new NotSupportedException(NotSupported_ValueCollectionSet);
bool ICollection<TValue>.Contains(TValue item) => _orderedHashSet.Contains(item);
void ICollection<TValue>.CopyTo(TValue[] array, int arrayIndex)
{
if (array == null)
{
throw new ArgumentNullException(nameof(array));
}
if ((uint)arrayIndex > (uint)array.Length)
{
throw new ArgumentOutOfRangeException(nameof(arrayIndex), ArgumentOutOfRange_NeedNonNegNum);
}
int count = Count;
if (array.Length - arrayIndex < count)
{
throw new ArgumentException(Arg_ArrayPlusOffTooSmall);
}
Entry[] entries = _orderedHashSet._entries;
for (int i = 0; i < count; ++i)
{
array[i + arrayIndex] = entries[i].Value;
}
}
bool ICollection<TValue>.Remove(TValue item) => throw new NotSupportedException(NotSupported_ValueCollectionSet);
public struct Enumerator : IEnumerator<TValue>
{
private readonly OrderedHashSet<TValue> _orderedHashSet;
private readonly int _version;
private int _index;
private TValue _current;
public TValue Current => _current;
object IEnumerator.Current => _current;
internal Enumerator(OrderedHashSet<TValue> OrderedHashSet)
{
_orderedHashSet = OrderedHashSet;
_version = OrderedHashSet._version;
_index = 0;
_current = default;
}
public void Dispose()
{
}
public bool MoveNext()
{
if (_version != _orderedHashSet._version)
{
throw new InvalidOperationException(InvalidOperation_EnumFailedVersion);
}
if (_index < _orderedHashSet.Count)
{
_current = _orderedHashSet._entries[_index].Value;
++_index;
return true;
}
_current = default;
return false;
}
void IEnumerator.Reset()
{
if (_version != _orderedHashSet._version)
{
throw new InvalidOperationException(InvalidOperation_EnumFailedVersion);
}
_index = 0;
_current = default;
}
}
}
}
}

View file

@ -0,0 +1,661 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2021 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: OrderedHashSet.cs *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
using System;
using System.Buffers;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using Microsoft.Collections.Extensions;
namespace Server.Collections
{
[DebuggerDisplay("Count = {Count}")]
public partial class OrderedHashSet<TValue> : IList<TValue>, IReadOnlyList<TValue>, ISet<TValue>, IReadOnlySet<TValue>
{
private struct Entry
{
public uint HashCode;
public TValue Value;
public int Next; // the index of the next item in the same bucket, -1 if last
}
private const string ArgumentOutOfRange_Index =
"Index was out of range. Must be non-negative and less than the size of the collection.";
private const string ArgumentOutOfRange_NeedNonNegNum =
"Non-negative number required.";
private const string Argument_InvalidOffLen =
"Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.";
private const string Argument_AddingDuplicate = "An item with the same value has already been added. Value: {0}";
private const string Arg_ArrayPlusOffTooSmall =
"Destination array is not long enough to copy all the items in the collection. Check array index and length.";
private const string InvalidOperation_ConcurrentOperationsNotSupported =
"Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.";
private const string InvalidOperation_EnumFailedVersion =
"Collection was modified; enumeration operation may not execute.";
private static readonly Entry[] InitialEntries = new Entry[1];
private int[] _buckets = HashHelpers.SizeOneIntArray;
private Entry[] _entries = InitialEntries;
private int _count;
private int _version;
private readonly IEqualityComparer<TValue> _comparer;
private ValueCollection _values;
public int Count => _count;
public IEqualityComparer<TValue> Comparer => _comparer ?? EqualityComparer<TValue>.Default;
public ValueCollection Values => _values ??= new ValueCollection(this);
public OrderedHashSet()
: this(0)
{
}
public OrderedHashSet(IEqualityComparer<TValue> comparer)
: this(0, comparer)
{
}
public OrderedHashSet(int capacity, IEqualityComparer<TValue> comparer = null)
{
if (capacity < 0)
{
throw new ArgumentOutOfRangeException(nameof(capacity));
}
if (capacity > 0)
{
int newSize = HashHelpers.GetPrime(capacity);
_buckets = new int[newSize];
_entries = new Entry[newSize];
}
if (comparer != EqualityComparer<TValue>.Default)
{
_comparer = comparer;
}
}
public OrderedHashSet(IEnumerable<TValue> collection, IEqualityComparer<TValue> comparer = null)
: this((collection as ICollection<TValue>)?.Count ?? 0, comparer)
{
if (collection == null)
{
throw new ArgumentNullException(nameof(collection));
}
foreach (TValue value in collection)
{
Add(value);
}
}
public void ExceptWith(IEnumerable<TValue> other)
{
throw new NotImplementedException();
}
public void IntersectWith(IEnumerable<TValue> other)
{
throw new NotImplementedException();
}
public bool Contains(TValue item) => TryGetValue(item, out var value) && EqualityComparer<TValue>.Default.Equals(value);
// TODO: Implement IReadOnlySet and ISet
bool IReadOnlySet<TValue>.IsProperSubsetOf(IEnumerable<TValue> other) => throw new NotImplementedException();
bool IReadOnlySet<TValue>.IsProperSupersetOf(IEnumerable<TValue> other) => throw new NotImplementedException();
bool IReadOnlySet<TValue>.IsSubsetOf(IEnumerable<TValue> other) => throw new NotImplementedException();
bool IReadOnlySet<TValue>.IsSupersetOf(IEnumerable<TValue> other) => throw new NotImplementedException();
bool IReadOnlySet<TValue>.Overlaps(IEnumerable<TValue> other) => throw new NotImplementedException();
bool IReadOnlySet<TValue>.SetEquals(IEnumerable<TValue> other) => throw new NotImplementedException();
bool ISet<TValue>.IsProperSubsetOf(IEnumerable<TValue> other) => throw new NotImplementedException();
bool ISet<TValue>.IsProperSupersetOf(IEnumerable<TValue> other) => throw new NotImplementedException();
bool ISet<TValue>.IsSubsetOf(IEnumerable<TValue> other) => throw new NotImplementedException();
bool ISet<TValue>.IsSupersetOf(IEnumerable<TValue> other) => throw new NotImplementedException();
bool ISet<TValue>.Overlaps(IEnumerable<TValue> other) => throw new NotImplementedException();
bool ISet<TValue>.SetEquals(IEnumerable<TValue> other) => throw new NotImplementedException();
public void SymmetricExceptWith(IEnumerable<TValue> other) => throw new NotImplementedException();
public void UnionWith(IEnumerable<TValue> other) => throw new NotImplementedException();
public void Clear()
{
if (_count > 0)
{
Array.Clear(_buckets, 0, _buckets.Length);
Array.Clear(_entries, 0, _count);
_count = 0;
++_version;
}
}
public int EnsureCapacity(int capacity)
{
if (capacity < 0)
{
throw new ArgumentOutOfRangeException(nameof(capacity));
}
if (_entries.Length >= capacity)
{
return _entries.Length;
}
int newSize = HashHelpers.GetPrime(capacity);
Resize(newSize);
++_version;
return newSize;
}
public Enumerator GetEnumerator() => new(this);
void ICollection<TValue>.Add(TValue item) => TryAdd(item);
public bool Add(TValue item) => TryAdd(item);
public int GetOrAdd(TValue value) => TryInsert(null, value);
public int IndexOf(TValue value) => IndexOf(value, out _);
public void Insert(int index, TValue value)
{
if ((uint)index > (uint)Count)
{
throw new ArgumentOutOfRangeException(nameof(index), ArgumentOutOfRange_Index);
}
TryInsert(index, value);
}
public void Move(int fromIndex, int toIndex)
{
if ((uint)fromIndex >= (uint)Count)
{
throw new ArgumentOutOfRangeException(nameof(fromIndex), ArgumentOutOfRange_Index);
}
if ((uint)toIndex >= (uint)Count)
{
throw new ArgumentOutOfRangeException(nameof(toIndex), ArgumentOutOfRange_Index);
}
if (fromIndex == toIndex)
{
return;
}
Entry[] entries = _entries;
Entry temp = entries[fromIndex];
RemoveEntryFromBucket(fromIndex);
int direction = fromIndex < toIndex ? 1 : -1;
for (int i = fromIndex; i != toIndex; i += direction)
{
entries[i] = entries[i + direction];
UpdateBucketIndex(i + direction, -direction);
}
AddEntryToBucket(ref temp, toIndex, _buckets);
entries[toIndex] = temp;
++_version;
}
public void MoveRange(int fromIndex, int toIndex, int count)
{
if (count == 1)
{
Move(fromIndex, toIndex);
return;
}
if ((uint)fromIndex >= (uint)Count)
{
throw new ArgumentOutOfRangeException(nameof(fromIndex), ArgumentOutOfRange_Index);
}
if ((uint)toIndex >= (uint)Count)
{
throw new ArgumentOutOfRangeException(nameof(toIndex), ArgumentOutOfRange_Index);
}
if (count < 0)
{
throw new ArgumentOutOfRangeException(nameof(count), ArgumentOutOfRange_NeedNonNegNum);
}
if (fromIndex + count > Count)
{
throw new ArgumentException(Argument_InvalidOffLen);
}
if (toIndex + count > Count)
{
throw new ArgumentException(Argument_InvalidOffLen);
}
if (fromIndex == toIndex || count == 0)
{
return;
}
Entry[] entries = _entries;
Entry[] entriesToMove = ArrayPool<Entry>.Shared.Rent(count);
for (int i = 0; i < count; ++i)
{
entriesToMove[i] = entries[fromIndex + i];
RemoveEntryFromBucket(fromIndex + i);
}
// Move entries in between
int direction = 1;
int amount = count;
int start = fromIndex;
int end = toIndex;
if (fromIndex > toIndex)
{
direction = -1;
amount = -count;
start = fromIndex + count - 1;
end = toIndex + count - 1;
}
for (int i = start; i != end; i += direction)
{
entries[i] = entries[i + amount];
UpdateBucketIndex(i + amount, -amount);
}
int[] buckets = _buckets;
// Copy entries to destination
for (int i = 0; i < count; ++i)
{
Entry temp = entriesToMove[i];
AddEntryToBucket(ref temp, toIndex + i, buckets);
entries[toIndex + i] = temp;
}
++_version;
ArrayPool<Entry>.Shared.Return(entriesToMove);
}
public bool Remove(TValue value)
{
int index = IndexOf(value);
if (index >= 0)
{
RemoveAt(index);
return true;
}
return false;
}
public void RemoveAt(int index)
{
int count = Count;
if ((uint)index >= (uint)count)
{
throw new ArgumentOutOfRangeException(nameof(index), ArgumentOutOfRange_Index);
}
// Remove the entry from the bucket
RemoveEntryFromBucket(index);
// Decrement the indices > index
Entry[] entries = _entries;
for (int i = index + 1; i < count; ++i)
{
entries[i - 1] = entries[i];
UpdateBucketIndex(i, incrementAmount: -1);
}
--_count;
entries[_count] = default;
++_version;
}
public void TrimExcess() => TrimExcess(Count);
public void TrimExcess(int capacity)
{
if (capacity < Count)
{
throw new ArgumentOutOfRangeException(nameof(capacity));
}
int newSize = HashHelpers.GetPrime(capacity);
if (newSize < _entries.Length)
{
Resize(newSize);
++_version;
}
}
public bool TryAdd(TValue value) => TryInsert(null, value) != _count - 1;
public bool TryGetValue(TValue value, out TValue actualValue)
{
int index = IndexOf(value);
if (index >= 0)
{
actualValue = _entries[index].Value;
return true;
}
actualValue = default;
return false;
}
public TValue this[int index]
{
get
{
if ((uint)index >= (uint)Count)
{
throw new ArgumentOutOfRangeException(nameof(index), ArgumentOutOfRange_Index);
}
return _entries[index].Value;
}
set
{
if ((uint)index >= (uint)Count)
{
throw new ArgumentOutOfRangeException(nameof(index), ArgumentOutOfRange_Index);
}
TValue v = value;
int foundIndex = IndexOf(v, out uint hashCode);
if (foundIndex < 0)
{
RemoveEntryFromBucket(index);
Entry entry = new Entry { HashCode = hashCode, Value = value };
AddEntryToBucket(ref entry, index, _buckets);
_entries[index] = entry;
++_version;
}
else if (foundIndex == index)
{
ref Entry entry = ref _entries[index];
entry.Value = value;
}
else
{
throw new ArgumentException(string.Format(Argument_AddingDuplicate, v.ToString()));
}
}
}
public bool IsReadOnly => false;
IEnumerator<TValue> IEnumerable<TValue>.GetEnumerator() => GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
public void CopyTo(TValue[] array, int arrayIndex)
{
if (array == null)
{
throw new ArgumentNullException(nameof(array));
}
if ((uint)arrayIndex > (uint)array.Length)
{
throw new ArgumentOutOfRangeException(nameof(arrayIndex), ArgumentOutOfRange_NeedNonNegNum);
}
int count = Count;
if (array.Length - arrayIndex < count)
{
throw new ArgumentException(Arg_ArrayPlusOffTooSmall);
}
Entry[] entries = _entries;
for (int i = 0; i < count; ++i)
{
Entry entry = entries[i];
array[i + arrayIndex] = entry.Value;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private Entry[] Resize(int newSize)
{
int[] newBuckets = new int[newSize];
Entry[] newEntries = new Entry[newSize];
int count = Count;
Array.Copy(_entries, newEntries, count);
for (int i = 0; i < count; ++i)
{
AddEntryToBucket(ref newEntries[i], i, newBuckets);
}
_buckets = newBuckets;
_entries = newEntries;
return newEntries;
}
private int IndexOf(TValue value, out uint hashCode)
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
IEqualityComparer<TValue> comparer = _comparer;
hashCode = (uint)(comparer?.GetHashCode(value) ?? value.GetHashCode());
int index = _buckets[(int)(hashCode % (uint)_buckets.Length)] - 1;
if (index >= 0)
{
comparer ??= EqualityComparer<TValue>.Default;
Entry[] entries = _entries;
int collisionCount = 0;
do
{
Entry entry = entries[index];
if (entry.HashCode == hashCode && comparer.Equals(entry.Value, value))
{
break;
}
index = entry.Next;
if (collisionCount >= entries.Length)
{
// The chain of entries forms a loop; which means a concurrent update has happened.
// Break out of the loop and throw, rather than looping forever.
throw new InvalidOperationException(InvalidOperation_ConcurrentOperationsNotSupported);
}
++collisionCount;
} while (index >= 0);
}
return index;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private int TryInsert(int? index, TValue value)
{
int i = IndexOf(value, out uint hashCode);
return i >= 0 ? i : AddInternal(index, value, hashCode);
}
private int AddInternal(int? index, TValue value, uint hashCode)
{
Entry[] entries = _entries;
// Check if resize is needed
int count = Count;
if (entries.Length == count || entries.Length == 1)
{
entries = Resize(HashHelpers.ExpandPrime(entries.Length));
}
// Increment indices >= index;
int actualIndex = index ?? count;
for (int i = count - 1; i >= actualIndex; --i)
{
entries[i + 1] = entries[i];
UpdateBucketIndex(i, incrementAmount: 1);
}
ref Entry entry = ref entries[actualIndex];
entry.HashCode = hashCode;
entry.Value = value;
AddEntryToBucket(ref entry, actualIndex, _buckets);
++_count;
++_version;
return actualIndex;
}
// Returns the index of the next entry in the bucket
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void AddEntryToBucket(ref Entry entry, int entryIndex, int[] buckets)
{
ref int b = ref buckets[(int)(entry.HashCode % (uint)buckets.Length)];
entry.Next = b - 1;
b = entryIndex + 1;
}
private void RemoveEntryFromBucket(int entryIndex)
{
Entry[] entries = _entries;
Entry entry = entries[entryIndex];
ref int b = ref _buckets[(int)(entry.HashCode % (uint)_buckets.Length)];
// Bucket was pointing to removed entry. Update it to point to the next in the chain
if (b == entryIndex + 1)
{
b = entry.Next + 1;
}
else
{
// Start at the entry the bucket points to, and walk the chain until we find the entry with the index we want to remove, then fix the chain
int i = b - 1;
int collisionCount = 0;
while (true)
{
ref Entry e = ref entries[i];
if (e.Next == entryIndex)
{
e.Next = entry.Next;
return;
}
i = e.Next;
if (collisionCount >= entries.Length)
{
// The chain of entries forms a loop; which means a concurrent update has happened.
// Break out of the loop and throw, rather than looping forever.
throw new InvalidOperationException(InvalidOperation_ConcurrentOperationsNotSupported);
}
++collisionCount;
}
}
}
private void UpdateBucketIndex(int entryIndex, int incrementAmount)
{
Entry[] entries = _entries;
Entry entry = entries[entryIndex];
ref int b = ref _buckets[(int)(entry.HashCode % (uint)_buckets.Length)];
// Bucket was pointing to entry. Increment the index by incrementAmount.
if (b == entryIndex + 1)
{
b += incrementAmount;
}
else
{
// Start at the entry the bucket points to, and walk the chain until we find the entry with the index we want to increment.
int i = b - 1;
int collisionCount = 0;
while (true)
{
ref Entry e = ref entries[i];
if (e.Next == entryIndex)
{
e.Next += incrementAmount;
return;
}
i = e.Next;
if (collisionCount >= entries.Length)
{
// The chain of entries forms a loop; which means a concurrent update has happened.
// Break out of the loop and throw, rather than looping forever.
throw new InvalidOperationException(InvalidOperation_ConcurrentOperationsNotSupported);
}
++collisionCount;
}
}
}
public struct Enumerator : IEnumerator<TValue>
{
private readonly OrderedHashSet<TValue> _OrderedHashSet;
private readonly int _version;
private int _index;
private TValue _current;
public TValue Current => _current;
object IEnumerator.Current => _current;
internal Enumerator(OrderedHashSet<TValue> OrderedHashSet)
{
_OrderedHashSet = OrderedHashSet;
_version = OrderedHashSet._version;
_index = 0;
_current = default;
}
public void Dispose()
{
}
public bool MoveNext()
{
if (_version != _OrderedHashSet._version)
{
throw new InvalidOperationException(InvalidOperation_EnumFailedVersion);
}
if (_index < _OrderedHashSet.Count)
{
Entry entry = _OrderedHashSet._entries[_index];
_current = entry.Value;
++_index;
return true;
}
_current = default;
return false;
}
void IEnumerator.Reset()
{
if (_version != _OrderedHashSet._version)
{
throw new InvalidOperationException(InvalidOperation_EnumFailedVersion);
}
_index = 0;
_current = default;
}
}
}
}

View file

@ -1,3 +1,5 @@
using System.Buffers;
using Server.Collections;
using Server.Network;
namespace Server.Gumps
@ -24,6 +26,8 @@ namespace Server.Gumps
public override string Compile(NetState ns) => $"{{ checkertrans {X} {Y} {Width} {Height} }}";
public override string Compile(OrderedHashSet<string> strings) => $"{{ checkertrans {X} {Y} {Width} {Height} }}";
public override void AppendTo(NetState ns, IGumpWriter disp)
{
disp.AppendLayout(m_LayoutName);
@ -32,5 +36,19 @@ namespace Server.Gumps
disp.AppendLayout(Width);
disp.AppendLayout(Height);
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(m_LayoutName);
writer.WriteAscii(X.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Y.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Width.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Height.ToString());
writer.Write((ushort)0x207D); // " }"
}
}
}

View file

@ -1,3 +1,5 @@
using System.Buffers;
using Server.Collections;
using Server.Network;
namespace Server.Gumps
@ -27,6 +29,8 @@ namespace Server.Gumps
public override string Compile(NetState ns) => $"{{ resizepic {X} {Y} {GumpID} {Width} {Height} }}";
public override string Compile(OrderedHashSet<string> strings) => $"{{ resizepic {X} {Y} {GumpID} {Width} {Height} }}";
public override void AppendTo(NetState ns, IGumpWriter disp)
{
disp.AppendLayout(m_LayoutName);
@ -36,5 +40,21 @@ namespace Server.Gumps
disp.AppendLayout(Width);
disp.AppendLayout(Height);
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(m_LayoutName);
writer.WriteAscii(X.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Y.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(GumpID.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Width.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Height.ToString());
writer.Write((ushort)0x207D); // " }"
}
}
}

View file

@ -1,3 +1,5 @@
using System.Buffers;
using Server.Collections;
using Server.Network;
namespace Server.Gumps
@ -43,6 +45,9 @@ namespace Server.Gumps
public override string Compile(NetState ns) =>
$"{{ button {X} {Y} {NormalID} {PressedID} {(int)Type} {Param} {ButtonID} }}";
public override string Compile(OrderedHashSet<string> strings) =>
$"{{ button {X} {Y} {NormalID} {PressedID} {(int)Type} {Param} {ButtonID} }}";
public override void AppendTo(NetState ns, IGumpWriter disp)
{
disp.AppendLayout(m_LayoutName);
@ -54,5 +59,25 @@ namespace Server.Gumps
disp.AppendLayout(Param);
disp.AppendLayout(ButtonID);
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(m_LayoutName);
writer.WriteAscii(X.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Y.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(NormalID.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(PressedID.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(((int)Type).ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Param.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(ButtonID.ToString());
writer.Write((ushort)0x207D); // " }"
}
}
}

View file

@ -1,3 +1,5 @@
using System.Buffers;
using Server.Collections;
using Server.Network;
namespace Server.Gumps
@ -31,6 +33,9 @@ namespace Server.Gumps
public override string Compile(NetState ns) =>
$"{{ checkbox {X} {Y} {InactiveID} {ActiveID} {(InitialState ? 1 : 0)} {SwitchID} }}";
public override string Compile(OrderedHashSet<string> strings) =>
$"{{ checkbox {X} {Y} {InactiveID} {ActiveID} {(InitialState ? 1 : 0)} {SwitchID} }}";
public override void AppendTo(NetState ns, IGumpWriter disp)
{
disp.AppendLayout(m_LayoutName);
@ -43,5 +48,25 @@ namespace Server.Gumps
disp.Switches++;
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(m_LayoutName);
writer.WriteAscii(X.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Y.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(InactiveID.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(ActiveID.ToString());
writer.Write((byte)0x20); // ' '
writer.Write((byte)(InitialState ? 0x31 : 0x30)); // 1 or 0
writer.Write((byte)0x20); // ' '
writer.WriteAscii(SwitchID.ToString());
writer.Write((ushort)0x207D); // " }"
switches++;
}
}
}

View file

@ -13,6 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
using System.Buffers;
using Server.Collections;
using Server.Network;
namespace Server.Gumps
@ -21,10 +23,16 @@ namespace Server.Gumps
{
private static readonly byte[] m_LayoutName = Gump.StringToBuffer("echandleinput");
public override string Compile(NetState ns) => "{ echandleinput }";
public override string Compile(OrderedHashSet<string> strings) => "{ echandleinput }";
public override void AppendTo(NetState ns, IGumpWriter disp)
{
disp.AppendLayout(m_LayoutName);
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.WriteAscii("{ echandleinput }");
}
}
}

View file

@ -1,3 +1,5 @@
using System.Buffers;
using Server.Collections;
using Server.Network;
namespace Server.Gumps
@ -23,6 +25,11 @@ namespace Server.Gumps
}
public abstract string Compile(NetState ns);
public abstract string Compile(OrderedHashSet<string> strings);
public abstract void AppendTo(NetState ns, IGumpWriter disp);
// TODO: Replace OrderedHashSet with InsertOnlyHashSet, a copy of HashSet that is ReadOnly compatible, but includes
// a public AddIfNotPresent function that returns the index of the element
public abstract void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches);
}
}

View file

@ -1,3 +1,5 @@
using System.Buffers;
using Server.Collections;
using Server.Network;
namespace Server.Gumps
@ -11,11 +13,20 @@ namespace Server.Gumps
public int Group { get; set; }
public override string Compile(NetState ns) => $"{{ group {Group} }}";
public override string Compile(OrderedHashSet<string> strings) => $"{{ group {Group} }}";
public override void AppendTo(NetState ns, IGumpWriter disp)
{
disp.AppendLayout(m_LayoutName);
disp.AppendLayout(Group);
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(m_LayoutName);
writer.WriteAscii(Group.ToString());
writer.Write((ushort)0x207D); // " }"
}
}
}

View file

@ -1,3 +1,5 @@
using System.Buffers;
using Server.Collections;
using Server.Network;
namespace Server.Gumps
@ -34,6 +36,9 @@ namespace Server.Gumps
public override string Compile(NetState ns) =>
$"{{ htmlgump {X} {Y} {Width} {Height} {Parent.Intern(Text)} {(Background ? 1 : 0)} {(Scrollbar ? 1 : 0)} }}";
public override string Compile(OrderedHashSet<string> strings) =>
$"{{ htmlgump {X} {Y} {Width} {Height} {strings.GetOrAdd(Text)} {(Background ? 1 : 0)} {(Scrollbar ? 1 : 0)} }}";
public override void AppendTo(NetState ns, IGumpWriter disp)
{
disp.AppendLayout(m_LayoutName);
@ -45,5 +50,25 @@ namespace Server.Gumps
disp.AppendLayout(Background);
disp.AppendLayout(Scrollbar);
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(m_LayoutName);
writer.WriteAscii(X.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Y.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Width.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Height.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(strings.GetOrAdd(Text).ToString());
writer.Write((byte)0x20); // ' '
writer.Write((byte)(Background ? 0x31 : 0x30)); // 1 or 0
writer.Write((byte)0x20); // ' '
writer.Write((byte)(Scrollbar ? 0x31 : 0x30)); // 1 or 0
writer.Write((ushort)0x207D); // " }"
}
}
}

View file

@ -1,3 +1,5 @@
using System.Buffers;
using Server.Collections;
using Server.Network;
namespace Server.Gumps
@ -88,9 +90,19 @@ namespace Server.Gumps
public GumpHtmlLocalizedType Type { get; set; }
public override string Compile(NetState ns)
{
return Type switch
public override string Compile(NetState ns) =>
Type switch
{
GumpHtmlLocalizedType.Plain =>
$"{{ xmfhtmlgump {X} {Y} {Width} {Height} {Number} {(Background ? 1 : 0)} {(Scrollbar ? 1 : 0)} }}",
GumpHtmlLocalizedType.Color =>
$"{{ xmfhtmlgumpcolor {X} {Y} {Width} {Height} {Number} {(Background ? 1 : 0)} {(Scrollbar ? 1 : 0)} {Color} }}",
_ =>
$"{{ xmfhtmltok {X} {Y} {Width} {Height} {(Background ? 1 : 0)} {(Scrollbar ? 1 : 0)} {Color} {Number} @{Args}@ }}"
};
public override string Compile(OrderedHashSet<string> strings) =>
Type switch
{
GumpHtmlLocalizedType.Plain =>
$"{{ xmfhtmlgump {X} {Y} {Width} {Height} {Number} {(Background ? 1 : 0)} {(Scrollbar ? 1 : 0)} }}",
@ -99,7 +111,6 @@ namespace Server.Gumps
_ =>
$"{{ xmfhtmltok {X} {Y} {Width} {Height} {(Background ? 1 : 0)} {(Scrollbar ? 1 : 0)} {Color} {Number} @{Args}@ }}"
};
}
public override void AppendTo(NetState ns, IGumpWriter disp)
{
@ -154,5 +165,81 @@ namespace Server.Gumps
}
}
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
switch (Type)
{
case GumpHtmlLocalizedType.Plain:
{
writer.Write(m_LayoutNamePlain);
writer.WriteAscii(X.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Y.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Width.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Height.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Number.ToString());
writer.Write((byte)0x20); // ' '
writer.Write((byte)(Background ? 0x31 : 0x30)); // 1 or 0
writer.Write((byte)0x20); // ' '
writer.Write((byte)(Scrollbar ? 0x31 : 0x30)); // 1 or 0
break;
}
case GumpHtmlLocalizedType.Color:
{
writer.Write(m_LayoutNameColor);
writer.WriteAscii(X.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Y.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Width.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Height.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Number.ToString());
writer.Write((byte)0x20); // ' '
writer.Write((byte)(Background ? 0x31 : 0x30)); // 1 or 0
writer.Write((byte)0x20); // ' '
writer.Write((byte)(Scrollbar ? 0x31 : 0x30)); // 1 or 0
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Color.ToString());
break;
}
case GumpHtmlLocalizedType.Args:
{
writer.Write(m_LayoutNameArgs);
writer.WriteAscii(X.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Y.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Width.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Height.ToString());
writer.Write((byte)0x20); // ' '
writer.Write((byte)(Background ? 0x31 : 0x30)); // 1 or 0
writer.Write((byte)0x20); // ' '
writer.Write((byte)(Scrollbar ? 0x31 : 0x30)); // 1 or 0
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Color.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Number.ToString());
writer.Write((byte)0x20); // ' '
writer.Write((byte)0x40); // '@'
writer.WriteAscii(Args ?? "");
writer.Write((byte)0x40); // '@'
break;
}
}
writer.Write((ushort)0x207D); // " }"
}
}
}

View file

@ -1,3 +1,5 @@
using System.Buffers;
using Server.Collections;
using Server.Network;
namespace Server.Gumps
@ -6,13 +8,15 @@ namespace Server.Gumps
{
private static readonly byte[] m_LayoutName = Gump.StringToBuffer("gumppic");
private static readonly byte[] m_HueEquals = Gump.StringToBuffer(" hue=");
private static readonly byte[] m_ClassEquals = Gump.StringToBuffer(" class=");
public GumpImage(int x, int y, int gumpID, int hue = 0)
public GumpImage(int x, int y, int gumpID, int hue = 0, string cls = null)
{
X = x;
Y = y;
GumpID = gumpID;
Hue = hue;
Class = cls;
}
public int X { get; set; }
@ -23,8 +27,13 @@ namespace Server.Gumps
public int Hue { get; set; }
public string Class { get; set; }
public override string Compile(NetState ns) =>
Hue == 0 ? $"{{ gumppic {X} {Y} {GumpID} }}" : $"{{ gumppic {X} {Y} {GumpID} hue={Hue} }}";
$"{{ gumppic {X} {Y} {GumpID}{(Hue == 0 ? "" : $"hue={Hue}")}{(string.IsNullOrEmpty(Class) ? "" : $"class={Class}")} }}";
public override string Compile(OrderedHashSet<string> strings) =>
$"{{ gumppic {X} {Y} {GumpID}{(Hue == 0 ? "" : $"hue={Hue}")}{(string.IsNullOrEmpty(Class) ? "" : $"class={Class}")} }}";
public override void AppendTo(NetState ns, IGumpWriter disp)
{
@ -38,6 +47,40 @@ namespace Server.Gumps
disp.AppendLayout(m_HueEquals);
disp.AppendLayoutNS(Hue);
}
if (!string.IsNullOrEmpty(Class))
{
disp.AppendLayout(m_ClassEquals);
disp.AppendLayoutNS(Class);
}
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(m_LayoutName);
writer.WriteAscii(X.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Y.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(GumpID.ToString());
writer.Write((byte)0x20); // ' '
if (Hue != 0)
{
writer.Write(m_HueEquals);
writer.WriteAscii(Hue.ToString());
writer.Write((byte)0x20); // ' '
}
if (!string.IsNullOrWhiteSpace(Class))
{
writer.Write(m_ClassEquals);
writer.WriteAscii(Class);
writer.Write((byte)0x20); // ' '
}
writer.Write((byte)0x7D); // '}'
}
}
}

View file

@ -1,3 +1,5 @@
using System.Buffers;
using Server.Collections;
using Server.Network;
namespace Server.Gumps
@ -7,9 +9,8 @@ namespace Server.Gumps
private static readonly byte[] m_LayoutName = Gump.StringToBuffer("buttontileart");
private static readonly byte[] m_LayoutTooltip = Gump.StringToBuffer(" }{ tooltip");
private GumpButtonType m_Type;
// Note, on OSI, The tooltip supports ONLY clilocs as far as I can figure out, and the tooltip ONLY works after the buttonTileArt (as far as I can tell from testing)
// Note, on OSI, the tooltip supports ONLY clilocs as far as I can figure out,
// and the tooltip ONLY works after the buttonTileArt (as far as I can tell from testing)
public GumpImageTileButton(
int x, int y, int normalID, int pressedID, int buttonID, GumpButtonType type, int param,
@ -21,7 +22,7 @@ namespace Server.Gumps
NormalID = normalID;
PressedID = pressedID;
ButtonID = buttonID;
m_Type = type;
Type = type;
Param = param;
ItemID = itemID;
@ -42,19 +43,7 @@ namespace Server.Gumps
public int ButtonID { get; set; }
public GumpButtonType Type
{
get => m_Type;
set
{
if (m_Type != value)
{
m_Type = value;
var parent = Parent;
}
}
}
public GumpButtonType Type { get; set; }
public int Param { get; set; }
@ -68,17 +57,15 @@ namespace Server.Gumps
public int LocalizedTooltip { get; set; }
public override string Compile(NetState ns)
{
if (LocalizedTooltip > 0)
{
return
$"{{ buttontileart {X} {Y} {NormalID} {PressedID} {(int)m_Type} {Param} {ButtonID} {ItemID} {Hue} {Width} {Height} }}{{ tooltip {LocalizedTooltip} }}";
}
public override string Compile(NetState ns) =>
LocalizedTooltip > 0 ?
$"{{ buttontileart {X} {Y} {NormalID} {PressedID} {(int)Type} {Param} {ButtonID} {ItemID} {Hue} {Width} {Height} }}{{ tooltip {LocalizedTooltip} }}" :
$"{{ buttontileart {X} {Y} {NormalID} {PressedID} {(int)Type} {Param} {ButtonID} {ItemID} {Hue} {Width} {Height} }}";
return
$"{{ buttontileart {X} {Y} {NormalID} {PressedID} {(int)m_Type} {Param} {ButtonID} {ItemID} {Hue} {Width} {Height} }}";
}
public override string Compile(OrderedHashSet<string> strings) =>
LocalizedTooltip > 0 ?
$"{{ buttontileart {X} {Y} {NormalID} {PressedID} {(int)Type} {Param} {ButtonID} {ItemID} {Hue} {Width} {Height} }}{{ tooltip {LocalizedTooltip} }}" :
$"{{ buttontileart {X} {Y} {NormalID} {PressedID} {(int)Type} {Param} {ButtonID} {ItemID} {Hue} {Width} {Height} }}";
public override void AppendTo(NetState ns, IGumpWriter disp)
{
@ -87,7 +74,7 @@ namespace Server.Gumps
disp.AppendLayout(Y);
disp.AppendLayout(NormalID);
disp.AppendLayout(PressedID);
disp.AppendLayout((int)m_Type);
disp.AppendLayout((int)Type);
disp.AppendLayout(Param);
disp.AppendLayout(ButtonID);
@ -102,5 +89,42 @@ namespace Server.Gumps
disp.AppendLayout(LocalizedTooltip);
}
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(m_LayoutName);
writer.WriteAscii(X.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Y.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(NormalID.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(PressedID.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(((int)Type).ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Param.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(ButtonID.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(ItemID.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Hue.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Width.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Height.ToString());
writer.Write((byte)0x20); // ' '
if (LocalizedTooltip > 0)
{
writer.Write(m_LayoutTooltip);
writer.WriteAscii(LocalizedTooltip.ToString());
writer.Write((byte)0x20); // ' '
}
writer.Write((byte)0x7D); // " }"
}
}
}

View file

@ -1,3 +1,5 @@
using System.Buffers;
using Server.Collections;
using Server.Network;
namespace Server.Gumps
@ -26,6 +28,7 @@ namespace Server.Gumps
public int GumpID { get; set; }
public override string Compile(NetState ns) => $"{{ gumppictiled {X} {Y} {Width} {Height} {GumpID} }}";
public override string Compile(OrderedHashSet<string> strings) => $"{{ gumppictiled {X} {Y} {Width} {Height} {GumpID} }}";
public override void AppendTo(NetState ns, IGumpWriter disp)
{
@ -36,5 +39,21 @@ namespace Server.Gumps
disp.AppendLayout(Height);
disp.AppendLayout(GumpID);
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(m_LayoutName);
writer.WriteAscii(X.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Y.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Width.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Height.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(GumpID.ToString());
writer.Write((ushort)0x207D); // " }"
}
}
}

View file

@ -1,3 +1,5 @@
using System.Buffers;
using Server.Collections;
using Server.Network;
namespace Server.Gumps
@ -26,6 +28,9 @@ namespace Server.Gumps
public override string Compile(NetState ns) =>
Hue == 0 ? $"{{ tilepic {X} {Y} {ItemID} }}" : $"{{ tilepichue {X} {Y} {ItemID} {Hue} }}";
public override string Compile(OrderedHashSet<string> strings) =>
Hue == 0 ? $"{{ tilepic {X} {Y} {ItemID} }}" : $"{{ tilepichue {X} {Y} {ItemID} {Hue} }}";
public override void AppendTo(NetState ns, IGumpWriter disp)
{
disp.AppendLayout(Hue == 0 ? m_LayoutName : m_LayoutNameHue);
@ -38,5 +43,23 @@ namespace Server.Gumps
disp.AppendLayout(Hue);
}
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write(Hue == 0 ? m_LayoutName : m_LayoutNameHue);
writer.WriteAscii(X.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Y.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(ItemID.ToString());
if (Hue != 0)
{
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Hue.ToString());
}
writer.Write((ushort)0x207D); // " }"
}
}
}

View file

@ -1,3 +1,5 @@
using System.Buffers;
using Server.Collections;
using Server.Network;
namespace Server.Gumps
@ -11,11 +13,20 @@ namespace Server.Gumps
public uint Serial { get; set; }
public override string Compile(NetState ns) => $"{{ itemproperty {Serial} }}";
public override string Compile(OrderedHashSet<string> strings) => $"{{ itemproperty {Serial} }}";
public override void AppendTo(NetState ns, IGumpWriter disp)
{
disp.AppendLayout(m_LayoutName);
disp.AppendLayout(Serial);
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(m_LayoutName);
writer.WriteAscii(Serial.ToString());
writer.Write((ushort)0x207D); // " }"
}
}
}

View file

@ -1,3 +1,5 @@
using System.Buffers;
using Server.Collections;
using Server.Network;
namespace Server.Gumps
@ -23,6 +25,7 @@ namespace Server.Gumps
public string Text { get; set; }
public override string Compile(NetState ns) => $"{{ text {X} {Y} {Hue} {Parent.Intern(Text)} }}";
public override string Compile(OrderedHashSet<string> strings) => $"{{ text {X} {Y} {Hue} {strings.GetOrAdd(Text)} }}";
public override void AppendTo(NetState ns, IGumpWriter disp)
{
@ -32,5 +35,19 @@ namespace Server.Gumps
disp.AppendLayout(Hue);
disp.AppendLayout(Parent.Intern(Text));
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(m_LayoutName);
writer.WriteAscii(X.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Y.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Hue.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(strings.GetOrAdd(Text).ToString());
writer.Write((ushort)0x207D); // " }"
}
}
}

View file

@ -1,3 +1,5 @@
using System.Buffers;
using Server.Collections;
using Server.Network;
namespace Server.Gumps
@ -31,6 +33,9 @@ namespace Server.Gumps
public override string Compile(NetState ns) =>
$"{{ croppedtext {X} {Y} {Width} {Height} {Hue} {Parent.Intern(Text)} }}";
public override string Compile(OrderedHashSet<string> strings) =>
$"{{ croppedtext {X} {Y} {Width} {Height} {Hue} {strings.GetOrAdd(Text)} }}";
public override void AppendTo(NetState ns, IGumpWriter disp)
{
disp.AppendLayout(m_LayoutName);
@ -41,5 +46,23 @@ namespace Server.Gumps
disp.AppendLayout(Hue);
disp.AppendLayout(Parent.Intern(Text));
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(m_LayoutName);
writer.WriteAscii(X.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Y.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Width.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Height.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Hue.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(strings.GetOrAdd(Text).ToString());
writer.Write((ushort)0x207D); // " }"
}
}
}

View file

@ -13,6 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
using System.Buffers;
using Server.Collections;
using Server.Network;
namespace Server.Gumps
@ -26,11 +28,20 @@ namespace Server.Gumps
public int GumpID { get; set; }
public override string Compile(NetState ns) => $"{{ mastergump {GumpID} }}";
public override string Compile(OrderedHashSet<string> strings) => $"{{ mastergump {GumpID} }}";
public override void AppendTo(NetState ns, IGumpWriter disp)
{
disp.AppendLayout(m_LayoutName);
disp.AppendLayout(GumpID);
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(m_LayoutName);
writer.WriteAscii(GumpID.ToString());
writer.Write((ushort)0x207D); // " }"
}
}
}

View file

@ -1,3 +1,5 @@
using System.Buffers;
using Server.Collections;
using Server.Network;
namespace Server.Gumps
@ -11,11 +13,20 @@ namespace Server.Gumps
public int Page { get; set; }
public override string Compile(NetState ns) => $"{{ page {Page} }}";
public override string Compile(OrderedHashSet<string> strings) => $"{{ page {Page} }}";
public override void AppendTo(NetState ns, IGumpWriter disp)
{
disp.AppendLayout(m_LayoutName);
disp.AppendLayout(Page);
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(m_LayoutName);
writer.WriteAscii(Page.ToString());
writer.Write((ushort)0x207D); // " }"
}
}
}

View file

@ -1,3 +1,5 @@
using System.Buffers;
using Server.Collections;
using Server.Network;
namespace Server.Gumps
@ -31,6 +33,9 @@ namespace Server.Gumps
public override string Compile(NetState ns) =>
$"{{ radio {X} {Y} {InactiveID} {ActiveID} {(InitialState ? 1 : 0)} {SwitchID} }}";
public override string Compile(OrderedHashSet<string> strings) =>
$"{{ radio {X} {Y} {InactiveID} {ActiveID} {(InitialState ? 1 : 0)} {SwitchID} }}";
public override void AppendTo(NetState ns, IGumpWriter disp)
{
disp.AppendLayout(m_LayoutName);
@ -43,5 +48,25 @@ namespace Server.Gumps
disp.Switches++;
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(m_LayoutName);
writer.WriteAscii(X.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Y.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(InactiveID.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(ActiveID.ToString());
writer.Write((byte)0x20); // ' '
writer.Write((byte)(InitialState ? 0x31 : 0x30)); // 1 or 0
writer.Write((byte)0x20); // ' '
writer.WriteAscii(SwitchID.ToString());
writer.Write((ushort)0x207D); // " }"
switches++;
}
}
}

View file

@ -13,6 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
using System.Buffers;
using Server.Collections;
using Server.Network;
namespace Server.Gumps
@ -47,6 +49,8 @@ namespace Server.Gumps
public int SY { get; set; }
public override string Compile(NetState ns) => $"{{ picinpic {X} {Y} {GumpID} {Width} {Height} {SX} {SY} }}";
public override string Compile(OrderedHashSet<string> strings) =>
$"{{ picinpic {X} {Y} {GumpID} {Width} {Height} {SX} {SY} }}";
public override void AppendTo(NetState ns, IGumpWriter disp)
{
@ -59,5 +63,25 @@ namespace Server.Gumps
disp.AppendLayout(SX);
disp.AppendLayout(SY);
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(m_LayoutName);
writer.WriteAscii(X.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Y.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(GumpID.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Width.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Height.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(SX.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(SY.ToString());
writer.Write((ushort)0x207D); // " }"
}
}
}

View file

@ -1,3 +1,5 @@
using System.Buffers;
using Server.Collections;
using Server.Network;
namespace Server.Gumps
@ -34,6 +36,9 @@ namespace Server.Gumps
public override string Compile(NetState ns) =>
$"{{ textentry {X} {Y} {Width} {Height} {Hue} {EntryID} {Parent.Intern(InitialText)} }}";
public override string Compile(OrderedHashSet<string> strings) =>
$"{{ textentry {X} {Y} {Width} {Height} {Hue} {EntryID} {strings.GetOrAdd(InitialText)} }}";
public override void AppendTo(NetState ns, IGumpWriter disp)
{
disp.AppendLayout(m_LayoutName);
@ -47,5 +52,27 @@ namespace Server.Gumps
disp.TextEntries++;
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(m_LayoutName);
writer.WriteAscii(X.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Y.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Width.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Height.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Hue.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(EntryID.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(strings.GetOrAdd(InitialText).ToString());
writer.Write((ushort)0x207D); // " }"
entries++;
}
}
}

View file

@ -1,3 +1,5 @@
using System.Buffers;
using Server.Collections;
using Server.Network;
namespace Server.Gumps
@ -39,6 +41,9 @@ namespace Server.Gumps
public override string Compile(NetState ns) =>
$"{{ textentrylimited {X} {Y} {Width} {Height} {Hue} {EntryID} {Parent.Intern(InitialText)} {Size} }}";
public override string Compile(OrderedHashSet<string> strings) =>
$"{{ textentrylimited {X} {Y} {Width} {Height} {Hue} {EntryID} {strings.GetOrAdd(InitialText)} {Size} }}";
public override void AppendTo(NetState ns, IGumpWriter disp)
{
disp.AppendLayout(m_LayoutName);
@ -53,5 +58,29 @@ namespace Server.Gumps
disp.TextEntries++;
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(m_LayoutName);
writer.WriteAscii(X.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Y.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Width.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Height.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Hue.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(EntryID.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(strings.GetOrAdd(InitialText).ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Size.ToString());
writer.Write((ushort)0x207D); // " }"
entries++;
}
}
}

View file

@ -13,6 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
using System.Buffers;
using Server.Collections;
using Server.Network;
namespace Server.Gumps
@ -31,13 +33,37 @@ namespace Server.Gumps
public string Args { get; set; }
public override string Compile(NetState ns) => $"{{ tooltip {Number} @{Args}@ }}";
public override string Compile(NetState ns) =>
string.IsNullOrEmpty(Args) ? $"{{ tooltip {Number} }}" : $"{{ tooltip {Number} @{Args}@ }}";
public override string Compile(OrderedHashSet<string> strings) =>
string.IsNullOrEmpty(Args) ? $"{{ tooltip {Number} }}" : $"{{ tooltip {Number} @{Args}@ }}";
public override void AppendTo(NetState ns, IGumpWriter disp)
{
disp.AppendLayout(m_LayoutName);
disp.AppendLayout(Number);
disp.AppendLayout(Args);
if (!string.IsNullOrEmpty(Args))
{
disp.AppendLayout(Args);
}
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(m_LayoutName);
writer.WriteAscii(Number.ToString());
if (!string.IsNullOrEmpty(Args))
{
writer.Write((byte)0x20); // ' '
writer.Write((byte)0x40); // '@'
writer.WriteAscii(Args);
writer.Write((byte)0x40); // '@'
}
writer.Write((ushort)0x207D); // " }"
}
}
}

View file

@ -8454,8 +8454,7 @@ namespace Server
if (gump != null)
{
// TODO: Recycle CloseGump
m_NetState.Send(new CloseGump(gump.TypeID, 0));
m_NetState.SendCloseGump(gump.TypeID, 0);
m_NetState.RemoveGump(gump);
gump.OnServerClose(m_NetState);
}
@ -8478,7 +8477,7 @@ namespace Server
foreach (var gump in gumps)
{
ns.Send(new CloseGump(gump.TypeID, 0));
ns.SendCloseGump(gump.TypeID, 0);
gump.OnServerClose(ns);
}

View file

@ -44,6 +44,7 @@ namespace Server.Network
void AppendLayout(uint val);
void AppendLayoutNS(int val);
void AppendLayout(string text);
void AppendLayoutNS(string text);
void AppendLayout(byte[] buffer);
void WriteStrings(List<string> strings);
void Flush();
@ -110,6 +111,11 @@ namespace Server.Network
m_Layout.Write(m_Buffer, 1, bytes);
}
public void AppendLayoutNS(string text)
{
m_Layout.WriteAsciiFixed(text, text.Length);
}
public void AppendLayout(string text)
{
AppendLayout(m_BeginTextSeparator);
@ -248,6 +254,13 @@ namespace Server.Network
m_LayoutLength += bytes;
}
public void AppendLayoutNS(string text)
{
var length = text.Length;
Stream.WriteAsciiFixed(text, length);
m_LayoutLength += length;
}
public void AppendLayout(string text)
{
AppendLayout(m_BeginTextSeparator);

View file

@ -0,0 +1,40 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: OutgoingGumpPackets.cs *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
using System.Buffers;
namespace Server.Network
{
public static class OutgoingGumpPackets
{
public static void SendCloseGump(this NetState ns, int typeId, int buttonId)
{
if (ns == null || !ns.GetSendBuffer(out var buffer))
{
return;
}
var writer = new CircularBufferWriter(buffer);
writer.Write((byte)0xBF); // Packet ID
writer.Write((ushort)13);
writer.Write((short)0x04);
writer.Write(typeId);
writer.Write(buttonId);
ns.Send(ref buffer, writer.Position);
}
}
}

View file

@ -98,8 +98,6 @@ namespace Server
var newBuffer = GC.AllocateUninitializedArray<byte>(size);
_buffer.AsSpan(0, Math.Min(size, _buffer.Length)).CopyTo(newBuffer);
_buffer = newBuffer;
// Array.Resize(ref _buffer, size);
}
public virtual void Flush()

View file

@ -39,14 +39,14 @@ namespace Server
AddPage(1);
Add(new InternalEntry(61, 71, 108, GetHueFor(0))); // Humility
Add(new InternalEntry(123, 46, 112, GetHueFor(4))); // Valor
Add(new InternalEntry(187, 70, 107, GetHueFor(5))); // Honor
Add(new InternalEntry(35, 135, 110, GetHueFor(1))); // Sacrifice
Add(new InternalEntry(211, 133, 105, GetHueFor(2))); // Compassion
Add(new InternalEntry(61, 195, 111, GetHueFor(3))); // Spiritulaity
Add(new InternalEntry(186, 195, 109, GetHueFor(6))); // Justice
Add(new InternalEntry(121, 221, 106, GetHueFor(7))); // Honesty
Add(new VirtueGumpItem(61, 71, 108, GetHueFor(0))); // Humility
Add(new VirtueGumpItem(123, 46, 112, GetHueFor(4))); // Valor
Add(new VirtueGumpItem(187, 70, 107, GetHueFor(5))); // Honor
Add(new VirtueGumpItem(35, 135, 110, GetHueFor(1))); // Sacrifice
Add(new VirtueGumpItem(211, 133, 105, GetHueFor(2))); // Compassion
Add(new VirtueGumpItem(61, 195, 111, GetHueFor(3))); // Spiritulaity
Add(new VirtueGumpItem(186, 195, 109, GetHueFor(6))); // Justice
Add(new VirtueGumpItem(121, 221, 106, GetHueFor(7))); // Honesty
if (m_Beholder == m_Beheld)
{
@ -171,22 +171,11 @@ namespace Server
}
}
private class InternalEntry : GumpImage
private class VirtueGumpItem : GumpImage
{
private static readonly byte[] m_Class = StringToBuffer(" class=VirtueGumpItem");
public InternalEntry(int x, int y, int gumpID, int hue) : base(x, y, gumpID, hue)
public VirtueGumpItem(int x, int y, int gumpID, int hue) : base(x, y, gumpID, hue, "VirtueGumpItem")
{
}
public override string Compile(NetState ns) => $"{{ gumppic {X} {Y} {GumpID} hue={Hue} class=VirtueGumpItem }}";
public override void AppendTo(NetState ns, IGumpWriter disp)
{
base.AppendTo(ns, disp);
disp.AppendLayout(m_Class);
}
}
}
}