Add WebRender
fix fir
This commit is contained in:
parent
990d151ef3
commit
d76e12d83e
8 changed files with 395 additions and 8 deletions
|
|
@ -14,6 +14,11 @@ namespace Server.Tests.Network
|
|||
IGumpWriter disp = new DisplayGumpFast(g);
|
||||
// IGumpWriter disp = new DisplayGumpPacked(g);
|
||||
|
||||
if (g.UseWebRender)
|
||||
{
|
||||
disp.AppendLayout(Gump.WebRender);
|
||||
}
|
||||
|
||||
if (!g.Draggable)
|
||||
{
|
||||
disp.AppendLayout(Gump.NoMove);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using Server.Network;
|
||||
using Server.Text;
|
||||
|
||||
|
|
@ -8,7 +10,7 @@ namespace Server.Gumps
|
|||
public 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 }");
|
||||
|
|
@ -52,6 +54,8 @@ namespace Server.Gumps
|
|||
|
||||
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)
|
||||
|
|
@ -68,7 +72,21 @@ namespace Server.Gumps
|
|||
{
|
||||
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); // " }"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -349,7 +349,7 @@ namespace Server.Network
|
|||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var isWebResponse = gump.UseWebRender;
|
||||
var buttonExists = buttonID == 0; // 0 is always 'close'
|
||||
|
||||
if (!buttonExists)
|
||||
|
|
@ -370,7 +370,7 @@ namespace Server.Network
|
|||
}
|
||||
}
|
||||
|
||||
if (!buttonExists)
|
||||
if (!isWebResponse && !buttonExists)
|
||||
{
|
||||
state.LogInfo("Invalid gump response, disconnecting...");
|
||||
var exception = new InvalidGumpResponseException($"Button {buttonID} doesn't exist");
|
||||
|
|
@ -384,7 +384,7 @@ namespace Server.Network
|
|||
|
||||
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 +405,7 @@ namespace Server.Network
|
|||
|
||||
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 +440,8 @@ namespace Server.Network
|
|||
textEntries[i] = new TextRelay(entryID, text);
|
||||
}
|
||||
|
||||
state.RemoveGump(gump);
|
||||
if (!isWebResponse)
|
||||
state.RemoveGump(gump);
|
||||
|
||||
var prof = GumpProfile.Acquire(gump.GetType());
|
||||
|
||||
|
|
|
|||
|
|
@ -108,6 +108,12 @@ namespace Server.Network
|
|||
|
||||
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]"), Description(
|
||||
|
|
|
|||
292
Projects/UOContent/Gumps/SciterTestGump.cs
Normal file
292
Projects/UOContent/Gumps/SciterTestGump.cs
Normal file
|
|
@ -0,0 +1,292 @@
|
|||
using Server.Gumps;
|
||||
using Server.Network;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public class SciterTestGump : Gump
|
||||
{
|
||||
public class Shop
|
||||
{
|
||||
public string[] ShopItems { get; set; } = new string[] { "item1", "item2" };
|
||||
}
|
||||
|
||||
public SciterTestGump(Mobile user) : base(
|
||||
0,
|
||||
0
|
||||
)
|
||||
{
|
||||
UseWebRender = true;
|
||||
AddBody(Body());
|
||||
}
|
||||
|
||||
public override void OnResponse(NetState sender, RelayInfo info)
|
||||
{
|
||||
var from = sender.Mobile;
|
||||
switch (info.ButtonID)
|
||||
{
|
||||
case 0: // close
|
||||
sender.RemoveGump(this);
|
||||
break;
|
||||
case 1: // hide
|
||||
from.Hidden = true;
|
||||
break;
|
||||
case 2: // unhide
|
||||
from.Hidden = false;
|
||||
break;
|
||||
case 3: // sendDataToCLeint
|
||||
SendData(from, "ShowSend", new Shop());
|
||||
break;
|
||||
case 4: // showData
|
||||
var builder = new StringBuilder();
|
||||
for (int i = 0; i < info.TextEntries.Length; i++)
|
||||
{
|
||||
var test = info.TextEntries[i].Text;
|
||||
builder.Append("argument ");
|
||||
builder.Append(i.ToString());
|
||||
builder.Append(" = ");
|
||||
builder.Append(test);
|
||||
builder.Append(" ");
|
||||
}
|
||||
|
||||
from.SendAsciiMessage(builder.ToString());
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
public string Body()
|
||||
{
|
||||
return "<html>\r\n" +
|
||||
" <head>\r\n" +
|
||||
" <title>Test<" +
|
||||
"/title>\r\n" +
|
||||
" <style>\r\n" +
|
||||
" [onmousele" +
|
||||
"ave] { aspect: \"Emu" +
|
||||
".onmouseleave\"; }\r" +
|
||||
"\n" +
|
||||
" html {\r" +
|
||||
"\n" +
|
||||
" over" +
|
||||
"flow: hidden;\r\n" +
|
||||
" \r\n" +
|
||||
" }\r\n" +
|
||||
" \r\n" +
|
||||
" .btn {\r\n" +
|
||||
" border: 2px solid " +
|
||||
"black;\r\n" +
|
||||
" border-radius: 5px" +
|
||||
";\r\n" +
|
||||
" background-color: " +
|
||||
"white;\r\n" +
|
||||
" color: black;\r\n" +
|
||||
" padding: 14px 28px" +
|
||||
";\r\n" +
|
||||
" font-size: 16px;\r" +
|
||||
"\n" +
|
||||
" cursor: pointer;\r" +
|
||||
"\n" +
|
||||
"} \r\n" +
|
||||
".success {\r\n" +
|
||||
" border-color: #04A" +
|
||||
"A6D;\r\n" +
|
||||
" color: green;\r\n" +
|
||||
"}\r\n\r\n" +
|
||||
".success:hover {\r\n" +
|
||||
" background-color: " +
|
||||
"#04AA6D;\r\n" +
|
||||
" color: white;\r\n" +
|
||||
"}\r\n\r\n" +
|
||||
"/* Blue */\r\n" +
|
||||
".info {\r\n" +
|
||||
" border-color: #219" +
|
||||
"6F3;\r\n" +
|
||||
" color: dodgerblue" +
|
||||
"\r\n" +
|
||||
"}\r\n\r\n" +
|
||||
".info:hover {\r\n" +
|
||||
" background: #2196F" +
|
||||
"3;\r\n" +
|
||||
" color: white;\r\n" +
|
||||
"}\r\n\r\n" +
|
||||
"/* Orange */\r\n" +
|
||||
".warning {\r\n" +
|
||||
" border-color: #ff9" +
|
||||
"800;\r\n" +
|
||||
" color: orange;\r\n" +
|
||||
"}\r\n\r\n" +
|
||||
".warning:hover {\r\n" +
|
||||
" background: #ff980" +
|
||||
"0;\r\n" +
|
||||
" color: white;\r\n" +
|
||||
"}\r\n\r\n" +
|
||||
"/* Red */\r\n" +
|
||||
".danger {\r\n" +
|
||||
" border-color: #f44" +
|
||||
"336;\r\n" +
|
||||
" color: red\r\n" +
|
||||
"}\r\n\r\n" +
|
||||
".danger:hover {\r\n" +
|
||||
" background: #f4433" +
|
||||
"6;\r\n" +
|
||||
" color: white;\r\n" +
|
||||
"}\r\n\r\n" +
|
||||
"/* Gray */\r\n" +
|
||||
".default {\r\n" +
|
||||
" border-color: #e7e" +
|
||||
"7e7;\r\n" +
|
||||
" color: black;\r\n" +
|
||||
"}\r\n\r\n" +
|
||||
".default:hover {\r\n" +
|
||||
" background: #e7e7e" +
|
||||
"7;\r\n" +
|
||||
"}\r\n\r\n" +
|
||||
" </style>\r\n" +
|
||||
" <script type=\"t" +
|
||||
"ext/tiscript\">\r\n" +
|
||||
"\r\n" +
|
||||
" namespace Em" +
|
||||
"u {\r\n" +
|
||||
" function o" +
|
||||
"nmouseleave() {\r\n" +
|
||||
" this.o" +
|
||||
"n(\"mouseleave\", fu" +
|
||||
"nction(evt) {\r\n" +
|
||||
" \r\n" +
|
||||
" });\r" +
|
||||
"\n" +
|
||||
" }\r\n" +
|
||||
" }\r\n\r\n" +
|
||||
" function sel" +
|
||||
"f.ready() {\r\n" +
|
||||
" view.move(" +
|
||||
"400px,100px,500,300)" +
|
||||
";\r\n" +
|
||||
" view.windo" +
|
||||
"wTopmost = false;\r" +
|
||||
"\n" +
|
||||
" //focus on" +
|
||||
" form \r\n" +
|
||||
" //this.tim" +
|
||||
"er(20ms, function() " +
|
||||
"{ view.focusable(#fi" +
|
||||
"rst).state.focus = t" +
|
||||
"rue; });\r\n" +
|
||||
" }\r\n\r\n" +
|
||||
" self.on(\"ke" +
|
||||
"ydown\", function(ev" +
|
||||
"t) {\r\n" +
|
||||
" if(evt.ke" +
|
||||
"yCode == 27)\r\n" +
|
||||
" {\r\n" +
|
||||
" close(" +
|
||||
");\r\n" +
|
||||
" }\r\n" +
|
||||
" });\r\n\r\n" +
|
||||
" function Sho" +
|
||||
"wSend(data)\r\n" +
|
||||
" {\r\n" +
|
||||
" var input " +
|
||||
"= $(#test);\r\n" +
|
||||
" if(element" +
|
||||
")return; \r\n" +
|
||||
" input.clea" +
|
||||
"r();\r\n\r\n" +
|
||||
" for (var i" +
|
||||
" = 0; i < data.ShopI" +
|
||||
"tems.length; i++) {" +
|
||||
"\r\n" +
|
||||
" input.ap" +
|
||||
"pend(data.ShopItems[" +
|
||||
"i]+\' ,\');\r\n" +
|
||||
" }\r\n" +
|
||||
" }\r\n\r\n" +
|
||||
" function clo" +
|
||||
"se()\r\n" +
|
||||
" {\r\n" +
|
||||
" view.Host_" +
|
||||
"SEND(0);\r\n" +
|
||||
" view.windo" +
|
||||
"wState = View.WINDOW" +
|
||||
"_HIDDEN;\r\n" +
|
||||
" view.move(" +
|
||||
"0px,0px,0,0);\r\n" +
|
||||
" }\r\n" +
|
||||
" \r\n\r\n\r\n" +
|
||||
" event click " +
|
||||
"$(button#load) {\r\n" +
|
||||
" view.Hos" +
|
||||
"t_SEND(3);\r\n" +
|
||||
" }\r\n\r\n" +
|
||||
" event click " +
|
||||
"$(button#send) {\r\n" +
|
||||
" view.Hos" +
|
||||
"t_SEND(4,\"arg0\",\"" +
|
||||
"arg1\",\"arg2\",\"ar" +
|
||||
"g3\",\"arg4\",\"arg5" +
|
||||
"\",\"arg6\",\"arg7\"" +
|
||||
",\"arg8\",\"arg9\");" +
|
||||
"\r\n" +
|
||||
" }\r\n\r\n" +
|
||||
" event click " +
|
||||
"$(button#hide) {\r\n" +
|
||||
" view.Hos" +
|
||||
"t_SEND(1,\"HELLO WOR" +
|
||||
"LD YEAH\");\r\n" +
|
||||
" }\r\n\r\n" +
|
||||
" event click " +
|
||||
"$(button#unhide) {\r" +
|
||||
"\n" +
|
||||
" view.Hos" +
|
||||
"t_SEND(2);\r\n" +
|
||||
" }\r\n\r\n" +
|
||||
" event click " +
|
||||
"$(button#close) {\r" +
|
||||
"\n" +
|
||||
" close();\r" +
|
||||
"\n" +
|
||||
" }\r\n" +
|
||||
" \r\n\r\n" +
|
||||
" </script>\r\n" +
|
||||
" \r\n" +
|
||||
" </head>\r\n" +
|
||||
" <body onmouselea" +
|
||||
"ve>\r\n" +
|
||||
" <button#load" +
|
||||
" class=\"btn warning" +
|
||||
"\" onmouseenter onmo" +
|
||||
"useleave>getDataFrom" +
|
||||
"Server</button>\r\n" +
|
||||
" <button#send" +
|
||||
" class=\"btn warning" +
|
||||
"\" onmouseenter onmo" +
|
||||
"useleave>sendDataToS" +
|
||||
"erver</button>\r\n" +
|
||||
" <button#hide" +
|
||||
" class=\"btn warning" +
|
||||
"\" onmouseenter onmo" +
|
||||
"useleave>hide</butto" +
|
||||
"n>\r\n" +
|
||||
" <button#unhi" +
|
||||
"de class=\"btn info" +
|
||||
"\">unhide</button>\r" +
|
||||
"\n" +
|
||||
" <button#clos" +
|
||||
"e class=\"btn danger" +
|
||||
"\">Close</button>\r" +
|
||||
"\n" +
|
||||
" <textarea id" +
|
||||
"=\"test\" name=\"com" +
|
||||
"ment\"></textarea></" +
|
||||
"p>\r\n" +
|
||||
" </body>\r\n" +
|
||||
"</html>";
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue