Compare commits
12 commits
main
...
webSupport
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
217c63a07a | ||
|
|
f0471f35f8 | ||
|
|
f5fef07e0c | ||
|
|
3650878399 | ||
|
|
a3458a2950 | ||
|
|
1f81bb7303 | ||
|
|
8e79abc243 | ||
|
|
d3c313e8a4 | ||
|
|
e933198a85 | ||
|
|
51e73a0f90 | ||
|
|
af7ce57d89 | ||
|
|
d76e12d83e |
7 changed files with 388 additions and 6 deletions
|
|
@ -1,5 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using Server.Network;
|
||||
using Server.Text;
|
||||
using Server.Utilities;
|
||||
|
|
@ -10,6 +12,7 @@ public partial class Gump
|
|||
{
|
||||
private static Serial _nextSerial = (Serial)1;
|
||||
|
||||
public static readonly byte[] WebRender = StringToBuffer("{ webrender }");
|
||||
public static readonly byte[] NoMove = StringToBuffer("{ nomove }");
|
||||
public static readonly byte[] NoClose = StringToBuffer("{ noclose }");
|
||||
public static readonly byte[] NoDispose = StringToBuffer("{ nodispose }");
|
||||
|
|
@ -53,6 +56,8 @@ public partial class Gump
|
|||
|
||||
public bool Closable { get; set; } = true;
|
||||
|
||||
public bool UseWebRender { get; set; } = false;
|
||||
|
||||
public static int GetTypeID(Type type) => type?.FullName?.GetHashCode(StringComparison.Ordinal) ?? -1;
|
||||
|
||||
public void AddPage(int page)
|
||||
|
|
@ -70,6 +75,22 @@ public partial class Gump
|
|||
Add(new GumpBackground(x, y, width, height, gumpID));
|
||||
}
|
||||
|
||||
public void SendData(Mobile m, string responseMethod, object value)
|
||||
{
|
||||
Entries.Clear();
|
||||
|
||||
var jtext = JsonSerializer.Serialize(value, new JsonSerializerOptions() { WriteIndented = true });
|
||||
Add(new GumpBodyUpdate(responseMethod,
|
||||
Convert.ToBase64String(Encoding.UTF8.GetBytes(jtext))));
|
||||
|
||||
m.SendGump(this);
|
||||
}
|
||||
|
||||
public void AddBody(string body)
|
||||
{
|
||||
Add(new GumpBody(Convert.ToBase64String(Encoding.UTF8.GetBytes(body))));
|
||||
}
|
||||
|
||||
public void AddButton(
|
||||
int x, int y, int normalID, int pressedID, int buttonID,
|
||||
GumpButtonType type = GumpButtonType.Reply, int param = 0
|
||||
|
|
|
|||
27
Projects/Server/Gumps/GumpBody.cs
Normal file
27
Projects/Server/Gumps/GumpBody.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
using Server.Collections;
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public class GumpBody : GumpEntry
|
||||
{
|
||||
public static readonly byte[] LayoutName = Gump.StringToBuffer("body");
|
||||
|
||||
public override string Compile(OrderedHashSet<string> strings) => $"{{ body {_body} }}";
|
||||
public GumpBody(string body) =>_body = body;
|
||||
public string _body { get; set; }
|
||||
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
|
||||
{
|
||||
writer.Write((ushort)0x7B20); // "{ "
|
||||
writer.Write(LayoutName);
|
||||
writer.WriteAscii(' ');
|
||||
writer.WriteAscii(_body.ToString());
|
||||
writer.Write((ushort)0x207D); // " }"
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Projects/Server/Gumps/GumpBodyUpdate.cs
Normal file
34
Projects/Server/Gumps/GumpBodyUpdate.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using Server.Collections;
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public class GumpBodyUpdate : GumpEntry
|
||||
{
|
||||
public static readonly byte[] LayoutName = Gump.StringToBuffer("bodyUpdate");
|
||||
|
||||
public override string Compile(OrderedHashSet<string> strings) => $"{{ bodyUpdate {_responseButtonId} {_body} }}";
|
||||
public GumpBodyUpdate(string responseButtonId, string body)
|
||||
{
|
||||
_body = body;
|
||||
_responseButtonId = responseButtonId;
|
||||
}
|
||||
public string _body { get; set; }
|
||||
public string _responseButtonId { get; set; }
|
||||
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
|
||||
{
|
||||
writer.Write((ushort)0x7B20); // "{ "
|
||||
writer.Write(LayoutName);
|
||||
writer.WriteAscii(' ');
|
||||
writer.WriteAscii(_responseButtonId);
|
||||
writer.WriteAscii(' ');
|
||||
writer.WriteAscii(_body);
|
||||
writer.Write((ushort)0x207D); // " }"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -350,6 +350,7 @@ public static class IncomingPlayerPackets
|
|||
continue;
|
||||
}
|
||||
|
||||
var isWebResponse = gump.UseWebRender;
|
||||
var buttonExists = buttonID == 0; // 0 is always 'close'
|
||||
|
||||
if (!buttonExists)
|
||||
|
|
@ -370,7 +371,7 @@ public static class IncomingPlayerPackets
|
|||
}
|
||||
}
|
||||
|
||||
if (!buttonExists)
|
||||
if (!isWebResponse && !buttonExists)
|
||||
{
|
||||
state.LogInfo("Invalid gump response, disconnecting...");
|
||||
var exception = new InvalidGumpResponseException($"Button {buttonID} doesn't exist");
|
||||
|
|
@ -384,7 +385,7 @@ public static class IncomingPlayerPackets
|
|||
|
||||
var switchCount = reader.ReadInt32();
|
||||
|
||||
if (switchCount < 0 || switchCount > gump.m_Switches)
|
||||
if (!isWebResponse && (switchCount < 0 || switchCount > gump.m_Switches))
|
||||
{
|
||||
state.LogInfo("Invalid gump response, disconnecting...");
|
||||
var exception = new InvalidGumpResponseException($"Bad switch count {switchCount}");
|
||||
|
|
@ -405,7 +406,7 @@ public static class IncomingPlayerPackets
|
|||
|
||||
var textCount = reader.ReadInt32();
|
||||
|
||||
if (textCount < 0 || textCount > gump.m_TextEntries)
|
||||
if (!isWebResponse && (textCount < 0 || textCount > gump.m_TextEntries))
|
||||
{
|
||||
state.LogInfo("Invalid gump response, disconnecting...");
|
||||
var exception = new InvalidGumpResponseException($"Bad text entry count {textCount}");
|
||||
|
|
@ -440,7 +441,10 @@ public static class IncomingPlayerPackets
|
|||
textEntries[i] = new TextRelay(entryID, text);
|
||||
}
|
||||
|
||||
state.RemoveGump(gump);
|
||||
if (!isWebResponse)
|
||||
{
|
||||
state.RemoveGump(gump);
|
||||
}
|
||||
|
||||
var prof = GumpProfile.Acquire(gump.GetType());
|
||||
|
||||
|
|
|
|||
|
|
@ -109,6 +109,11 @@ public static class OutgoingGumpPackets
|
|||
|
||||
var layoutWriter = new SpanWriter(_layoutBuffer);
|
||||
|
||||
if (gump.UseWebRender)
|
||||
{
|
||||
layoutWriter.Write(Gump.WebRender);
|
||||
}
|
||||
|
||||
if (!gump.Draggable)
|
||||
{
|
||||
layoutWriter.Write(Gump.NoMove);
|
||||
|
|
|
|||
|
|
@ -86,10 +86,14 @@ namespace Server.Gumps
|
|||
(m_Page + 1) * 10 < searchResults.Length ? 0x7FFF : 0x5EF7
|
||||
);
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
private static void Sciter_OnCommand(CommandEventArgs e)
|
||||
{
|
||||
e.Mobile.SendGump(new SciterTestGump(e.Mobile));
|
||||
}
|
||||
public static void Initialize()
|
||||
{
|
||||
CommandSystem.Register("AddMenu", AccessLevel.GameMaster, AddMenu_OnCommand);
|
||||
CommandSystem.Register("t", AccessLevel.GameMaster, Sciter_OnCommand);
|
||||
}
|
||||
|
||||
[Usage("AddMenu [searchString]")]
|
||||
|
|
|
|||
287
Projects/UOContent/Gumps/SciterTestGump.cs
Normal file
287
Projects/UOContent/Gumps/SciterTestGump.cs
Normal file
|
|
@ -0,0 +1,287 @@
|
|||
using Server.Gumps;
|
||||
using Server.Items;
|
||||
using Server.Network;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public class SciterTestGump : Gump
|
||||
{
|
||||
public class Item
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
public class Shop
|
||||
{
|
||||
public Item[] ShopItems { get; set; } = new Item[]
|
||||
{
|
||||
new Item(){Name="Arrow",Count = 10 },
|
||||
new Item(){Name="Bolt",Count = 10 },
|
||||
new Item(){Name="Gold",Count = 20000 },
|
||||
};
|
||||
}
|
||||
public Shop _shop = new Shop();
|
||||
public SciterTestGump(Mobile user) : base(
|
||||
0,
|
||||
0
|
||||
)
|
||||
{
|
||||
UseWebRender = true;
|
||||
AddBody(body());
|
||||
}
|
||||
|
||||
|
||||
public void TryToAddItem(Mobile m, int index)
|
||||
{
|
||||
if (_shop.ShopItems.Length < index)
|
||||
return;
|
||||
|
||||
var itemName = _shop.ShopItems[index].Name;
|
||||
var itemCount = Convert.ToInt32(_shop.ShopItems[index].Count);
|
||||
|
||||
var type = AssemblyHandler.FindTypeByName(itemName);
|
||||
|
||||
var item = Activator.CreateInstance(type, args: new object[] { itemCount });
|
||||
if (item is Server.Item _item)
|
||||
{
|
||||
m.AddToBackpack(_item);
|
||||
}
|
||||
|
||||
}
|
||||
public override void OnResponse(NetState sender, RelayInfo info)
|
||||
{
|
||||
var from = sender.Mobile;
|
||||
switch (info.ButtonID)
|
||||
{
|
||||
case 0: // close
|
||||
sender.RemoveGump(this);
|
||||
break;
|
||||
case 1:
|
||||
SendData(from, "1", _shop);
|
||||
break;
|
||||
case 2:
|
||||
TryToAddItem(from, Convert.ToInt32(info.TextEntries[0].Text));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
public string body()
|
||||
{
|
||||
return "<html >\r\n" +
|
||||
" \r\n" +
|
||||
" <style>\r\n" +
|
||||
" html{backgroun" +
|
||||
"d-color:black}\r\n" +
|
||||
" h1 { color: wh" +
|
||||
"ite;}\r\n" +
|
||||
" p{color: white" +
|
||||
";}\r\n" +
|
||||
" .btn1 {\r\n" +
|
||||
" backgrou" +
|
||||
"nd-color: yellow;\r" +
|
||||
"\n" +
|
||||
" color: b" +
|
||||
"lack;\r\n" +
|
||||
" text-ali" +
|
||||
"gn: center;\r\n" +
|
||||
" font-siz" +
|
||||
"e: 13px;\r\n" +
|
||||
" }\r\n" +
|
||||
" #close {\r\n" +
|
||||
" position: re" +
|
||||
"lative;\r\n" +
|
||||
" float: right" +
|
||||
";\r\n" +
|
||||
" \r\n" +
|
||||
" }\r\n" +
|
||||
" \r\n" +
|
||||
" .center {\r\n" +
|
||||
" position: re" +
|
||||
"lative;\r\n" +
|
||||
" float: cente" +
|
||||
"r;\r\n" +
|
||||
" } \r\n" +
|
||||
" \r\n" +
|
||||
" .close-btn {\r" +
|
||||
"\n" +
|
||||
" font-size: 6" +
|
||||
"0px;\r\n" +
|
||||
" font-weight:" +
|
||||
" bold;\r\n" +
|
||||
" color: #000;" +
|
||||
"\r\n" +
|
||||
" }\r\n" +
|
||||
" .tsize\r\n" +
|
||||
" {\r\n" +
|
||||
" color: r" +
|
||||
"ed;\r\n" +
|
||||
" font-siz" +
|
||||
"e: 18px;\r\n" +
|
||||
" }\r\n" +
|
||||
" .myButton " +
|
||||
"{\r\n" +
|
||||
" box-shadow" +
|
||||
":inset 0px 34px 0px " +
|
||||
"-15px #b54b3a;\r\n" +
|
||||
" background" +
|
||||
":linear-gradient(to " +
|
||||
"bottom, #a73f2d 5%, " +
|
||||
"#b34332 100%);\r\n" +
|
||||
" background" +
|
||||
"-color:#a73f2d;\r\n" +
|
||||
" border:1px" +
|
||||
" solid #241d13;\r\n" +
|
||||
" display:in" +
|
||||
"line-block;\r\n" +
|
||||
" cursor:poi" +
|
||||
"nter;\r\n" +
|
||||
" color:#fff" +
|
||||
"fff;\r\n" +
|
||||
" font-famil" +
|
||||
"y:Arial;\r\n" +
|
||||
" font-size:" +
|
||||
"15px;\r\n" +
|
||||
" font-weigh" +
|
||||
"t:bold;\r\n" +
|
||||
" padding:9p" +
|
||||
"x 23px;\r\n" +
|
||||
" text-decor" +
|
||||
"ation:none;\r\n" +
|
||||
" text-shado" +
|
||||
"w:0px -1px 0px #7a2a" +
|
||||
"1d;\r\n" +
|
||||
" }\r\n" +
|
||||
" .myButton:ho" +
|
||||
"ver {\r\n" +
|
||||
" background" +
|
||||
":linear-gradient(to " +
|
||||
"bottom, #b34332 5%, " +
|
||||
"#a73f2d 100%);\r\n" +
|
||||
" background" +
|
||||
"-color:#b34332;\r\n" +
|
||||
" }\r\n" +
|
||||
" .myButton:ac" +
|
||||
"tive {\r\n" +
|
||||
" position:r" +
|
||||
"elative;\r\n" +
|
||||
" top:1px;\r" +
|
||||
"\n" +
|
||||
" }\r\n" +
|
||||
" </style>\r\n" +
|
||||
" \r\n\r\n" +
|
||||
"\t<script type=\"mod" +
|
||||
"ule\">\r\n\r\n" +
|
||||
"\t\tdocument.ready =" +
|
||||
" function () {\r\n" +
|
||||
"\t\t}\r\n" +
|
||||
" \r\n" +
|
||||
" document.onmouse" +
|
||||
"leave = function(){" +
|
||||
"\r\n" +
|
||||
" Window.this.xc" +
|
||||
"all(\"GameFocus\");" +
|
||||
"\r\n" +
|
||||
" }\r\n" +
|
||||
"\t</script>\r\n" +
|
||||
" \r\n" +
|
||||
"</head>\r\n" +
|
||||
" <body>\r\n" +
|
||||
" <div id=\"app\" " +
|
||||
">\r\n" +
|
||||
" <a id=\"clos" +
|
||||
"e\" v-on:click=\"Clo" +
|
||||
"se()\" class=\"tsize" +
|
||||
"\">✕</a>\r\n" +
|
||||
" <h1 class=\"" +
|
||||
"center\"> MUO + VueJ" +
|
||||
"s Demo</h1>\r\n" +
|
||||
" <ul>\r\n" +
|
||||
" <li v-for=\"" +
|
||||
"(item, index) in sho" +
|
||||
"pItems\">\r\n" +
|
||||
" <p>{{ item" +
|
||||
".Name }} amount: {{ " +
|
||||
"item.Count }} \r\n" +
|
||||
" <a href=" +
|
||||
"\"#\" class=\"myButt" +
|
||||
"on\" v-on:click=\"Ge" +
|
||||
"t(index)\">OK</a>\r" +
|
||||
"\n" +
|
||||
" </p>\r\n" +
|
||||
" </li>\r\n" +
|
||||
" </ul>\r\n" +
|
||||
" </div>\r\n" +
|
||||
" <script src=\"http" +
|
||||
"s://unpkg.com/vue\">" +
|
||||
"</script>\r\n" +
|
||||
" <!-- <script src=" +
|
||||
"\"js\\vue.js\"></scr" +
|
||||
"ipt> -->\r\n" +
|
||||
" <script>\r\n" +
|
||||
" var app = new " +
|
||||
"Vue({\r\n" +
|
||||
" el: \'#app" +
|
||||
"\',\r\n" +
|
||||
" data: {\r" +
|
||||
"\n" +
|
||||
" shopI" +
|
||||
"tems: []\r\n" +
|
||||
" },\r\n" +
|
||||
" beforeMoun" +
|
||||
"t(){\r\n" +
|
||||
" //set s" +
|
||||
"ize \r\n" +
|
||||
" Window." +
|
||||
"this.move(100,100, 5" +
|
||||
"00, 500, false);\r\n" +
|
||||
" this.ge" +
|
||||
"tItems();\r\n" +
|
||||
" },\r\n" +
|
||||
" methods: {" +
|
||||
"\r\n" +
|
||||
" getItems" +
|
||||
": function () {\r\n" +
|
||||
" Window" +
|
||||
".this.xcall(\"SEND\"" +
|
||||
", 1 ,function (value" +
|
||||
") {\r\n" +
|
||||
" //" +
|
||||
"you can\'t use this " +
|
||||
"now it\'s func\r\n" +
|
||||
" ap" +
|
||||
"p.shopItems = value." +
|
||||
"ShopItems;\r\n" +
|
||||
"\t\t\t });\r" +
|
||||
"\n" +
|
||||
" },\r\n" +
|
||||
" Get: fun" +
|
||||
"ction (index) {\r\n" +
|
||||
" Window" +
|
||||
".this.xcall(\"SEND\"" +
|
||||
", 2, index);\r\n" +
|
||||
" },\r\n" +
|
||||
" Close: f" +
|
||||
"unction () {\r\n" +
|
||||
" docu" +
|
||||
"ment.body.innerHTML " +
|
||||
"= \"\";\r\n" +
|
||||
" Wind" +
|
||||
"ow.this.state = Win" +
|
||||
"dow.WINDOW_HIDDEN;\r" +
|
||||
"\n" +
|
||||
" },\r\n" +
|
||||
" }\r\n" +
|
||||
" });\r\n" +
|
||||
" </script>\r\n" +
|
||||
" </body>\r\n" +
|
||||
"</html>";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue