mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 11:40:52 +01:00
Compare commits
124 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17164ead34 | ||
|
|
079e099a3b | ||
|
|
1c8ed1c5b2 | ||
|
|
d4cdb7ff3b | ||
|
|
31d301b91f | ||
|
|
07c65474cb | ||
|
|
8c3c8fceea | ||
|
|
ee894d8a8e | ||
|
|
ce169ed15e | ||
|
|
9b215098e4 | ||
|
|
78d01fd25d | ||
|
|
8e8bfbe0cc | ||
|
|
45b0a49ffb | ||
|
|
58638c9109 | ||
|
|
2f2a397ecf | ||
|
|
78c551d854 | ||
|
|
679e07d9ea | ||
|
|
fa5d0235ec | ||
|
|
04d029b9a2 | ||
|
|
6e84821233 | ||
|
|
881cfeb9a9 | ||
|
|
0187e85700 | ||
|
|
dee8a87acd | ||
|
|
d4a7e8f3e0 | ||
|
|
dae6424667 | ||
|
|
3770149cfc | ||
|
|
341c279265 | ||
|
|
37c20723ab | ||
|
|
c3e4a64ad7 | ||
|
|
225446920a | ||
|
|
9b2a50b1a8 | ||
|
|
b4ed513e8c | ||
|
|
c28f2d77c3 | ||
|
|
3e344d00a8 | ||
|
|
c321400347 | ||
|
|
a4ff5d65ec | ||
|
|
97c70124a5 | ||
|
|
cdcc5239ab | ||
|
|
ba2f464249 | ||
|
|
4210f30460 | ||
|
|
9fc95591d9 | ||
|
|
0a59079a4a | ||
|
|
89f168c04d | ||
|
|
f11ac39cd5 | ||
|
|
380de8c4c3 | ||
|
|
539c161ea3 | ||
|
|
b07187459b | ||
|
|
97fb54b6d7 | ||
|
|
fe30d974ca | ||
|
|
884fade25a | ||
|
|
a3ab745121 | ||
|
|
4e0ad23272 | ||
|
|
b9b9cd0711 | ||
|
|
b05b1a7c86 | ||
|
|
4ced901358 | ||
|
|
898d5a3ba5 | ||
|
|
068c05c355 | ||
|
|
cd693875e6 | ||
|
|
e2723a83b3 | ||
|
|
f6ac8fbe1f | ||
|
|
a1e0f18bd6 | ||
|
|
1e7a481911 | ||
|
|
331f14b31a | ||
|
|
88660e1958 | ||
|
|
d9af00c931 | ||
|
|
b8cb037151 | ||
|
|
32d8bd8600 | ||
|
|
f5a1e06f21 | ||
|
|
48a5cb75d6 | ||
|
|
3e6b5a7739 | ||
|
|
9ac0aa4cd6 | ||
|
|
50fb8ca9e5 | ||
|
|
7da89765ac | ||
|
|
ce58c6688f | ||
|
|
2f03640200 | ||
|
|
55fecc95a9 | ||
|
|
8b54ad79cf | ||
|
|
88dec23a03 | ||
|
|
079702347d | ||
|
|
d18bf3d5ac | ||
|
|
ed832748b1 | ||
|
|
6491e51f3d | ||
|
|
58e7fb3a17 | ||
|
|
a9c7926226 | ||
|
|
241dc0b752 | ||
|
|
566948f1c0 | ||
|
|
dbba440f7e | ||
|
|
5b1e9eec27 | ||
|
|
8ef95f0199 | ||
|
|
b71e8f140a | ||
|
|
f8397099de | ||
|
|
5bbf1703ac | ||
|
|
1357e38759 | ||
|
|
655ecbab45 | ||
|
|
a0ef63bd4a | ||
|
|
f34763f11e | ||
|
|
b1f6b4cbe0 | ||
|
|
94708881b3 | ||
|
|
0f6dbac51c | ||
|
|
e67de121ca | ||
|
|
17979db216 | ||
|
|
8d0070b5c3 | ||
|
|
034c392cbe | ||
|
|
160bbc3a72 | ||
|
|
3a4d228e94 | ||
|
|
57f57f9d9f | ||
|
|
0592444252 | ||
|
|
d8499f2e60 | ||
|
|
476b5182f8 | ||
|
|
6c7ab1bd82 | ||
|
|
526ed31b0d | ||
|
|
3ac5552276 | ||
|
|
7a51c22514 | ||
|
|
aa339eb504 | ||
|
|
ffb3800664 | ||
|
|
39eb1a7d75 | ||
|
|
c25ab2fcb1 | ||
|
|
58ea614c1f | ||
|
|
5cbad8b3d9 | ||
|
|
e7e08e5dd6 | ||
|
|
9ac8db37cc | ||
|
|
2d6eebfae2 | ||
|
|
5540d643ef | ||
|
|
76c1d9f97b |
@@ -1,52 +0,0 @@
|
||||
environment:
|
||||
sonarqubekey:
|
||||
secure: h3llq6OeVa94hJ71UOEQSQDq75vFt+doso7iFry0gvt/fFcyeonY9wY+ETOIVITK
|
||||
global:
|
||||
PYTHONUNBUFFERED: True
|
||||
HEADLESS: 1 # For the unit tests.
|
||||
|
||||
version: 0.1.0.{build}
|
||||
pull_requests:
|
||||
do_not_increment_build_number: true
|
||||
|
||||
image: Visual Studio 2019
|
||||
install:
|
||||
- ps: >
|
||||
if (-Not $env:APPVEYOR_PULL_REQUEST_NUMBER -And $env:APPVEYOR_REPO_BRANCH -Eq "master")
|
||||
{
|
||||
cinst msbuild-sonarqube-runner;
|
||||
}
|
||||
|
||||
before_build:
|
||||
- cmd: py -3.5 -m pip install --user requests
|
||||
- cmd: git submodule update --init --recursive
|
||||
- ps: >
|
||||
if (-Not $env:APPVEYOR_PULL_REQUEST_NUMBER -And $env:APPVEYOR_REPO_BRANCH -Eq "master")
|
||||
{
|
||||
SonarScanner.MSBuild.exe begin /k:"ss14" /d:"sonar.host.url=https://sonarcloud.io" /d:"sonar.login=$env:sonarqubekey" /o:"space-wizards" /d:sonar.cs.nunit.reportsPaths="$(Get-Location)\nunitTestResult.xml";
|
||||
}
|
||||
|
||||
platform: x64
|
||||
configuration: Debug
|
||||
|
||||
cache:
|
||||
- packages -> **\*.csproj
|
||||
- Dependencies
|
||||
|
||||
build:
|
||||
project: RobustToolbox.sln
|
||||
parallel: false
|
||||
verbosity: minimal
|
||||
|
||||
build_script:
|
||||
- ps: dotnet build RobustToolbox.sln /p:AppVeyor=yes
|
||||
|
||||
test_script:
|
||||
- ps: dotnet test Robust.UnitTesting/Robust.UnitTesting.csproj
|
||||
|
||||
after_test:
|
||||
- ps: >
|
||||
if (-Not $env:APPVEYOR_PULL_REQUEST_NUMBER -And $env:APPVEYOR_REPO_BRANCH -Eq "master")
|
||||
{
|
||||
SonarScanner.MSBuild.exe end /d:"sonar.login=$env:sonarqubekey";
|
||||
}
|
||||
2
.github/workflows/build-test.yml
vendored
2
.github/workflows/build-test.yml
vendored
@@ -22,7 +22,7 @@ jobs:
|
||||
- name: Setup .NET Core
|
||||
uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: 5.0.100
|
||||
dotnet-version: 6.0.100
|
||||
- name: Install dependencies
|
||||
run: dotnet restore
|
||||
- name: Build
|
||||
|
||||
2
.github/workflows/codeql-analysis.yml
vendored
2
.github/workflows/codeql-analysis.yml
vendored
@@ -42,7 +42,7 @@ jobs:
|
||||
- name: Setup .NET Core
|
||||
uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: 5.0.100
|
||||
dotnet-version: 6.0.100
|
||||
|
||||
- name: Build
|
||||
run: dotnet build
|
||||
|
||||
2
.github/workflows/publish-client.yml
vendored
2
.github/workflows/publish-client.yml
vendored
@@ -23,7 +23,7 @@ jobs:
|
||||
- name: Setup .NET Core
|
||||
uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: 5.0.100
|
||||
dotnet-version: 6.0.100
|
||||
|
||||
- name: Package client
|
||||
run: Tools/package_client_build.py -p windows mac linux
|
||||
|
||||
4
.github/workflows/test-content.yml
vendored
4
.github/workflows/test-content.yml
vendored
@@ -21,7 +21,7 @@ jobs:
|
||||
- name: Setup .NET Core
|
||||
uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: 5.0.100
|
||||
dotnet-version: 6.0.100
|
||||
- name: Disable submodule autoupdate
|
||||
run: touch BuildChecker/DISABLE_SUBMODULE_AUTOUPDATE
|
||||
|
||||
@@ -38,4 +38,4 @@ jobs:
|
||||
- name: Content.Tests
|
||||
run: dotnet test --no-build Content.Tests/Content.Tests.csproj -v n
|
||||
- name: Content.IntegrationTests
|
||||
run: COMPlus_gcServer=1 dotnet test --no-build Content.IntegrationTests/Content.IntegrationTests.csproj -v n
|
||||
run: COMPlus_gcServer=1 dotnet test --no-build Content.IntegrationTests/Content.IntegrationTests.csproj -v n
|
||||
|
||||
Submodule Lidgren.Network/Lidgren.Network updated: 6132604c32...dd285c9246
@@ -3,10 +3,10 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<DefineConstants Condition="'$(TargetFramework)' == 'netstandard2.1' or '$(TargetFramework)' == 'netcoreapp3.1'">$(DefineConstants);HAS_FULL_SPAN</DefineConstants>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
<DefaultItemExcludes>Lidgren.Network/**/*</DefaultItemExcludes>
|
||||
<DefineConstants>$(DefineConstants);USE_RELEASE_STATISTICS</DefineConstants>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<Project>
|
||||
<!-- Engine-specific properties. Content should not use this file. -->
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<LangVersion>9</LangVersion>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<LangVersion>10</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<WarningsAsErrors>nullable</WarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<TargetOS Condition="'$(TargetOS)' == ''">$(ActualOS)</TargetOS>
|
||||
<Python>python3</Python>
|
||||
<Python Condition="'$(ActualOS)' == 'Windows'">py -3</Python>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<EnableClientScripting>True</EnableClientScripting>
|
||||
<!-- Client scripting is disabled on full release builds for security and size reasons. -->
|
||||
<EnableClientScripting Condition="'$(FullRelease)' == 'True'">False</EnableClientScripting>
|
||||
|
||||
@@ -2,29 +2,15 @@ preset raw;
|
||||
|
||||
#include "/Shaders/Internal/shadow_cast_shared.swsl"
|
||||
|
||||
#include "/Shaders/Internal/fov_shared.swsl"
|
||||
|
||||
const highp float g_MinVariance = 0.0;
|
||||
|
||||
varying highp vec2 worldPosition;
|
||||
|
||||
// Center of the FOV, in world coordinates.
|
||||
uniform highp vec2 center;
|
||||
|
||||
void vertex()
|
||||
{
|
||||
highp vec3 transformed = modelMatrix * vec3(VERTEX, 1.0);
|
||||
worldPosition = transformed.xy;
|
||||
transformed = projectionMatrix * viewMatrix * transformed;
|
||||
|
||||
VERTEX = transformed.xy;
|
||||
}
|
||||
|
||||
void fragment()
|
||||
{
|
||||
highp vec2 diff = worldPosition - center;
|
||||
highp float ourDist = length(worldSpaceDiff);
|
||||
|
||||
highp float ourDist = length(diff);
|
||||
|
||||
highp vec2 occlDist = occludeDepth(diff, TEXTURE, 0.25);
|
||||
highp vec2 occlDist = occludeDepth(worldSpaceDiff, TEXTURE, 0.25);
|
||||
|
||||
highp float occlusion = ChebyshevUpperBound(occlDist, ourDist);
|
||||
|
||||
|
||||
@@ -2,21 +2,10 @@ preset raw;
|
||||
|
||||
#include "/Shaders/Internal/shadow_cast_shared.swsl"
|
||||
|
||||
#include "/Shaders/Internal/fov_shared.swsl"
|
||||
|
||||
const highp float g_MinVariance = 0.0;
|
||||
|
||||
// World-space position offset from centre to pixel.
|
||||
varying highp vec2 worldSpaceDiff;
|
||||
|
||||
// Inverted transformation matrix from clip coordinates to difference coordinates.
|
||||
uniform highp mat3 clipToDiff;
|
||||
|
||||
void vertex()
|
||||
{
|
||||
// Convert quad-space (0.0 to 1.0) to clip-space (-1.0 to 1.0)
|
||||
VERTEX = (VERTEX.xy - 0.5) * 2.0;
|
||||
worldSpaceDiff = (clipToDiff * vec3(VERTEX, 1.0)).xy;
|
||||
}
|
||||
|
||||
void fragment()
|
||||
{
|
||||
highp float ourDist = length(worldSpaceDiff);
|
||||
|
||||
16
Resources/Shaders/Internal/fov_shared.swsl
Normal file
16
Resources/Shaders/Internal/fov_shared.swsl
Normal file
@@ -0,0 +1,16 @@
|
||||
// Shared between fov-lighting.swsl and fov.swsl, which both use the Clyde quad,
|
||||
// manually transformed into clip-space to cover the entire viewport
|
||||
|
||||
// World-space position offset from centre to pixel.
|
||||
varying highp vec2 worldSpaceDiff;
|
||||
|
||||
// Inverted transformation matrix from clip coordinates to difference coordinates.
|
||||
uniform highp mat3 clipToDiff;
|
||||
|
||||
void vertex()
|
||||
{
|
||||
// Convert quad-space (0.0 to 1.0) to clip-space (-1.0 to 1.0)
|
||||
VERTEX = (VERTEX.xy - 0.5) * 2.0;
|
||||
worldSpaceDiff = (clipToDiff * vec3(VERTEX, 1.0)).xy;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ void fragment()
|
||||
highp vec2 diff = worldPosition - lightCenter;
|
||||
|
||||
// Totally not hacky PCF on top of VSM.
|
||||
highp float occlusion = createOcclusion(diff);
|
||||
highp float occlusion = lightIndex < 0.0 ? 1.0 : createOcclusion(diff);
|
||||
|
||||
if (occlusion == 0.0)
|
||||
{
|
||||
|
||||
@@ -1,593 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Input;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using Xilium.CefGlue;
|
||||
using static Robust.Client.CEF.CefKeyCodes;
|
||||
using static Robust.Client.CEF.CefKeyCodes.ChromiumKeyboardCode;
|
||||
using static Robust.Client.Input.Keyboard;
|
||||
|
||||
namespace Robust.Client.CEF
|
||||
{
|
||||
// Funny browser control to integrate in UI.
|
||||
public class BrowserControl : Control, IBrowserControl, IRawInputControl
|
||||
{
|
||||
private const int ScrollSpeed = 50;
|
||||
|
||||
[Dependency] private readonly IClyde _clyde = default!;
|
||||
[Dependency] private readonly IInputManager _inputMgr = default!;
|
||||
[Dependency] private readonly CefManager _cef = default!;
|
||||
|
||||
private RobustRequestHandler _requestHandler = new RobustRequestHandler(Logger.GetSawmill("root"));
|
||||
private LiveData? _data;
|
||||
private string _startUrl = "about:blank";
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public string Url
|
||||
{
|
||||
get => _data == null ? _startUrl : _data.Browser.GetMainFrame().Url;
|
||||
set
|
||||
{
|
||||
if (_data == null)
|
||||
_startUrl = value;
|
||||
else
|
||||
_data.Browser.GetMainFrame().LoadUrl(value);
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables] public bool IsLoading => _data?.Browser.IsLoading ?? false;
|
||||
|
||||
private readonly Dictionary<Key, ChromiumKeyboardCode> _keyMap = new()
|
||||
{
|
||||
[Key.A] = VKEY_A,
|
||||
[Key.B] = VKEY_B,
|
||||
[Key.C] = VKEY_C,
|
||||
[Key.D] = VKEY_D,
|
||||
[Key.E] = VKEY_E,
|
||||
[Key.F] = VKEY_F,
|
||||
[Key.G] = VKEY_G,
|
||||
[Key.H] = VKEY_H,
|
||||
[Key.I] = VKEY_I,
|
||||
[Key.J] = VKEY_J,
|
||||
[Key.K] = VKEY_K,
|
||||
[Key.L] = VKEY_L,
|
||||
[Key.M] = VKEY_M,
|
||||
[Key.N] = VKEY_N,
|
||||
[Key.O] = VKEY_O,
|
||||
[Key.P] = VKEY_P,
|
||||
[Key.Q] = VKEY_Q,
|
||||
[Key.R] = VKEY_R,
|
||||
[Key.S] = VKEY_S,
|
||||
[Key.T] = VKEY_T,
|
||||
[Key.U] = VKEY_U,
|
||||
[Key.V] = VKEY_V,
|
||||
[Key.W] = VKEY_W,
|
||||
[Key.X] = VKEY_X,
|
||||
[Key.Y] = VKEY_Y,
|
||||
[Key.Z] = VKEY_Z,
|
||||
[Key.Num0] = VKEY_0,
|
||||
[Key.Num1] = VKEY_1,
|
||||
[Key.Num2] = VKEY_2,
|
||||
[Key.Num3] = VKEY_3,
|
||||
[Key.Num4] = VKEY_4,
|
||||
[Key.Num5] = VKEY_5,
|
||||
[Key.Num6] = VKEY_6,
|
||||
[Key.Num7] = VKEY_7,
|
||||
[Key.Num8] = VKEY_8,
|
||||
[Key.Num9] = VKEY_9,
|
||||
[Key.NumpadNum0] = VKEY_NUMPAD0,
|
||||
[Key.NumpadNum1] = VKEY_NUMPAD1,
|
||||
[Key.NumpadNum2] = VKEY_NUMPAD2,
|
||||
[Key.NumpadNum3] = VKEY_NUMPAD3,
|
||||
[Key.NumpadNum4] = VKEY_NUMPAD4,
|
||||
[Key.NumpadNum5] = VKEY_NUMPAD5,
|
||||
[Key.NumpadNum6] = VKEY_NUMPAD6,
|
||||
[Key.NumpadNum7] = VKEY_NUMPAD7,
|
||||
[Key.NumpadNum8] = VKEY_NUMPAD8,
|
||||
[Key.NumpadNum9] = VKEY_NUMPAD9,
|
||||
[Key.Escape] = VKEY_ESCAPE,
|
||||
[Key.Control] = VKEY_CONTROL,
|
||||
[Key.Shift] = VKEY_SHIFT,
|
||||
[Key.Alt] = VKEY_MENU,
|
||||
[Key.LSystem] = VKEY_LWIN,
|
||||
[Key.RSystem] = VKEY_RWIN,
|
||||
[Key.LBracket] = VKEY_OEM_4,
|
||||
[Key.RBracket] = VKEY_OEM_6,
|
||||
[Key.SemiColon] = VKEY_OEM_1,
|
||||
[Key.Comma] = VKEY_OEM_COMMA,
|
||||
[Key.Period] = VKEY_OEM_PERIOD,
|
||||
[Key.Apostrophe] = VKEY_OEM_7,
|
||||
[Key.Slash] = VKEY_OEM_2,
|
||||
[Key.BackSlash] = VKEY_OEM_5,
|
||||
[Key.Tilde] = VKEY_OEM_3,
|
||||
[Key.Equal] = VKEY_OEM_PLUS,
|
||||
[Key.Space] = VKEY_SPACE,
|
||||
[Key.Return] = VKEY_RETURN,
|
||||
[Key.BackSpace] = VKEY_BACK,
|
||||
[Key.Tab] = VKEY_TAB,
|
||||
[Key.PageUp] = VKEY_PRIOR,
|
||||
[Key.PageDown] = VKEY_NEXT,
|
||||
[Key.End] = VKEY_END,
|
||||
[Key.Home] = VKEY_HOME,
|
||||
[Key.Insert] = VKEY_INSERT,
|
||||
[Key.Delete] = VKEY_DELETE,
|
||||
[Key.Minus] = VKEY_OEM_MINUS,
|
||||
[Key.NumpadAdd] = VKEY_ADD,
|
||||
[Key.NumpadSubtract] = VKEY_SUBTRACT,
|
||||
[Key.NumpadDivide] = VKEY_DIVIDE,
|
||||
[Key.NumpadMultiply] = VKEY_MULTIPLY,
|
||||
[Key.NumpadDecimal] = VKEY_DECIMAL,
|
||||
[Key.Left] = VKEY_LEFT,
|
||||
[Key.Right] = VKEY_RIGHT,
|
||||
[Key.Up] = VKEY_UP,
|
||||
[Key.Down] = VKEY_DOWN,
|
||||
[Key.F1] = VKEY_F1,
|
||||
[Key.F2] = VKEY_F2,
|
||||
[Key.F3] = VKEY_F3,
|
||||
[Key.F4] = VKEY_F4,
|
||||
[Key.F5] = VKEY_F5,
|
||||
[Key.F6] = VKEY_F6,
|
||||
[Key.F7] = VKEY_F7,
|
||||
[Key.F8] = VKEY_F8,
|
||||
[Key.F9] = VKEY_F9,
|
||||
[Key.F10] = VKEY_F10,
|
||||
[Key.F11] = VKEY_F11,
|
||||
[Key.F12] = VKEY_F12,
|
||||
[Key.F13] = VKEY_F13,
|
||||
[Key.F14] = VKEY_F14,
|
||||
[Key.F15] = VKEY_F15,
|
||||
[Key.Pause] = VKEY_PAUSE,
|
||||
};
|
||||
|
||||
public BrowserControl()
|
||||
{
|
||||
CanKeyboardFocus = true;
|
||||
KeyboardFocusOnClick = true;
|
||||
MouseFilter = MouseFilterMode.Stop;
|
||||
|
||||
IoCManager.InjectDependencies(this);
|
||||
}
|
||||
|
||||
protected override void EnteredTree()
|
||||
{
|
||||
base.EnteredTree();
|
||||
|
||||
_cef.CheckInitialized();
|
||||
|
||||
DebugTools.AssertNull(_data);
|
||||
|
||||
// A funny render handler that will allow us to render to the control.
|
||||
var renderer = new ControlRenderHandler(this);
|
||||
|
||||
// A funny web cef client. This can actually be shared by multiple browsers, but I'm not sure how the
|
||||
// rendering would work in that case? TODO CEF: Investigate a way to share the web client?
|
||||
var client = new RobustCefClient(renderer, _requestHandler, new RobustLoadHandler());
|
||||
|
||||
var info = CefWindowInfo.Create();
|
||||
|
||||
// FUNFACT: If you DO NOT set these below and set info.Width/info.Height instead, you get an external window
|
||||
// Good to know, huh? Setup is the same, except you can pass a dummy render handler to the CEF client.
|
||||
info.SetAsWindowless(IntPtr.Zero, false); // TODO CEF: Pass parent handle?
|
||||
info.WindowlessRenderingEnabled = true;
|
||||
|
||||
var settings = new CefBrowserSettings()
|
||||
{
|
||||
WindowlessFrameRate = 60
|
||||
};
|
||||
|
||||
// Create the web browser! And by default, we go to about:blank.
|
||||
var browser = CefBrowserHost.CreateBrowserSync(info, client, settings, _startUrl);
|
||||
|
||||
var texture = _clyde.CreateBlankTexture<Bgra32>(Vector2i.One);
|
||||
|
||||
_data = new LiveData(texture, client, browser, renderer);
|
||||
}
|
||||
|
||||
protected override void ExitedTree()
|
||||
{
|
||||
base.ExitedTree();
|
||||
|
||||
DebugTools.AssertNotNull(_data);
|
||||
|
||||
_data!.Texture.Dispose();
|
||||
_data.Browser.GetHost().CloseBrowser(true);
|
||||
_data = null;
|
||||
}
|
||||
|
||||
protected internal override void MouseMove(GUIMouseMoveEventArgs args)
|
||||
{
|
||||
base.MouseMove(args);
|
||||
|
||||
if (_data == null)
|
||||
return;
|
||||
|
||||
// Logger.Debug();
|
||||
var modifiers = CalcMouseModifiers();
|
||||
var mouseEvent = new CefMouseEvent(
|
||||
(int) args.RelativePosition.X, (int) args.RelativePosition.Y,
|
||||
modifiers);
|
||||
|
||||
_data.Browser.GetHost().SendMouseMoveEvent(mouseEvent, false);
|
||||
}
|
||||
|
||||
protected internal override void MouseExited()
|
||||
{
|
||||
base.MouseExited();
|
||||
|
||||
if (_data == null)
|
||||
return;
|
||||
|
||||
var modifiers = CalcMouseModifiers();
|
||||
|
||||
_data.Browser.GetHost().SendMouseMoveEvent(new CefMouseEvent(0, 0, modifiers), true);
|
||||
}
|
||||
|
||||
protected internal override void MouseWheel(GUIMouseWheelEventArgs args)
|
||||
{
|
||||
base.MouseWheel(args);
|
||||
|
||||
if (_data == null)
|
||||
return;
|
||||
|
||||
var modifiers = CalcMouseModifiers();
|
||||
var mouseEvent = new CefMouseEvent(
|
||||
(int) args.RelativePosition.X, (int) args.RelativePosition.Y,
|
||||
modifiers);
|
||||
|
||||
_data.Browser.GetHost().SendMouseWheelEvent(
|
||||
mouseEvent,
|
||||
(int) args.Delta.X * ScrollSpeed,
|
||||
(int) args.Delta.Y * ScrollSpeed);
|
||||
}
|
||||
|
||||
bool IRawInputControl.RawKeyEvent(in GuiRawKeyEvent guiRawEvent)
|
||||
{
|
||||
if (_data == null)
|
||||
return false;
|
||||
|
||||
var host = _data.Browser.GetHost();
|
||||
|
||||
if (guiRawEvent.Key is Key.MouseLeft or Key.MouseMiddle or Key.MouseRight)
|
||||
{
|
||||
var key = guiRawEvent.Key switch
|
||||
{
|
||||
Key.MouseLeft => CefMouseButtonType.Left,
|
||||
Key.MouseMiddle => CefMouseButtonType.Middle,
|
||||
Key.MouseRight => CefMouseButtonType.Right,
|
||||
_ => default // not possible
|
||||
};
|
||||
|
||||
var mouseEvent = new CefMouseEvent(
|
||||
guiRawEvent.MouseRelative.X, guiRawEvent.MouseRelative.Y,
|
||||
CefEventFlags.None);
|
||||
|
||||
// Logger.Debug($"MOUSE: {guiRawEvent.Action} {guiRawEvent.Key} {guiRawEvent.ScanCode} {key}");
|
||||
|
||||
// TODO: double click support?
|
||||
host.SendMouseClickEvent(mouseEvent, key, guiRawEvent.Action == RawKeyAction.Up, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Handle left/right modifier keys??
|
||||
if (!_keyMap.TryGetValue(guiRawEvent.Key, out var vkKey))
|
||||
vkKey = default;
|
||||
|
||||
// Logger.Debug($"{guiRawEvent.Action} {guiRawEvent.Key} {guiRawEvent.ScanCode} {vkKey}");
|
||||
|
||||
var lParam = 0;
|
||||
lParam |= (guiRawEvent.ScanCode & 0xFF) << 16;
|
||||
if (guiRawEvent.Action != RawKeyAction.Down)
|
||||
lParam |= 1 << 30;
|
||||
|
||||
if (guiRawEvent.Action == RawKeyAction.Up)
|
||||
lParam |= 1 << 31;
|
||||
|
||||
var modifiers = CalcModifiers(guiRawEvent.Key);
|
||||
|
||||
host.SendKeyEvent(new CefKeyEvent
|
||||
{
|
||||
// Repeats are sent as key downs, I guess?
|
||||
EventType = guiRawEvent.Action == RawKeyAction.Up
|
||||
? CefKeyEventType.KeyUp
|
||||
: CefKeyEventType.RawKeyDown,
|
||||
NativeKeyCode = lParam,
|
||||
// NativeKeyCode = guiRawEvent.ScanCode,
|
||||
WindowsKeyCode = (int) vkKey,
|
||||
IsSystemKey = false, // TODO
|
||||
Modifiers = modifiers
|
||||
});
|
||||
|
||||
if (guiRawEvent.Action != RawKeyAction.Up && guiRawEvent.Key == Key.Return)
|
||||
{
|
||||
host.SendKeyEvent(new CefKeyEvent
|
||||
{
|
||||
EventType = CefKeyEventType.Char,
|
||||
WindowsKeyCode = '\r',
|
||||
NativeKeyCode = lParam,
|
||||
Modifiers = modifiers
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private CefEventFlags CalcModifiers(Key key)
|
||||
{
|
||||
CefEventFlags modifiers = default;
|
||||
|
||||
if (_inputMgr.IsKeyDown(Key.Control))
|
||||
modifiers |= CefEventFlags.ControlDown;
|
||||
|
||||
if (_inputMgr.IsKeyDown(Key.Alt))
|
||||
modifiers |= CefEventFlags.AltDown;
|
||||
|
||||
if (_inputMgr.IsKeyDown(Key.Shift))
|
||||
modifiers |= CefEventFlags.ShiftDown;
|
||||
|
||||
if (_inputMgr.IsKeyDown(Key.Shift))
|
||||
modifiers |= CefEventFlags.ShiftDown;
|
||||
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
private CefEventFlags CalcMouseModifiers()
|
||||
{
|
||||
CefEventFlags modifiers = default;
|
||||
|
||||
if (_inputMgr.IsKeyDown(Key.Control))
|
||||
modifiers |= CefEventFlags.ControlDown;
|
||||
|
||||
if (_inputMgr.IsKeyDown(Key.Alt))
|
||||
modifiers |= CefEventFlags.AltDown;
|
||||
|
||||
if (_inputMgr.IsKeyDown(Key.Shift))
|
||||
modifiers |= CefEventFlags.ShiftDown;
|
||||
|
||||
if (_inputMgr.IsKeyDown(Key.Shift))
|
||||
modifiers |= CefEventFlags.ShiftDown;
|
||||
|
||||
if (_inputMgr.IsKeyDown(Key.MouseLeft))
|
||||
modifiers |= CefEventFlags.LeftMouseButton;
|
||||
|
||||
if (_inputMgr.IsKeyDown(Key.MouseMiddle))
|
||||
modifiers |= CefEventFlags.MiddleMouseButton;
|
||||
|
||||
if (_inputMgr.IsKeyDown(Key.MouseRight))
|
||||
modifiers |= CefEventFlags.RightMouseButton;
|
||||
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
protected internal override void TextEntered(GUITextEventArgs args)
|
||||
{
|
||||
base.TextEntered(args);
|
||||
|
||||
if (_data == null)
|
||||
return;
|
||||
|
||||
var host = _data.Browser.GetHost();
|
||||
|
||||
Span<char> buf = stackalloc char[2];
|
||||
var written = args.AsRune.EncodeToUtf16(buf);
|
||||
|
||||
for (var i = 0; i < written; i++)
|
||||
{
|
||||
host.SendKeyEvent(new CefKeyEvent
|
||||
{
|
||||
EventType = CefKeyEventType.Char,
|
||||
WindowsKeyCode = buf[i],
|
||||
Character = buf[i],
|
||||
UnmodifiedCharacter = buf[i]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Resized()
|
||||
{
|
||||
base.Resized();
|
||||
|
||||
if (_data == null)
|
||||
return;
|
||||
|
||||
_data.Browser.GetHost().NotifyMoveOrResizeStarted();
|
||||
_data.Browser.GetHost().WasResized();
|
||||
_data.Texture.Dispose();
|
||||
_data.Texture = _clyde.CreateBlankTexture<Bgra32>((PixelWidth, PixelHeight));
|
||||
}
|
||||
|
||||
protected internal override void Draw(DrawingHandleScreen handle)
|
||||
{
|
||||
base.Draw(handle);
|
||||
|
||||
if (_data == null)
|
||||
return;
|
||||
|
||||
var bufImg = _data.Renderer.Buffer.Buffer;
|
||||
|
||||
_data.Texture.SetSubImage(
|
||||
Vector2i.Zero,
|
||||
bufImg,
|
||||
new UIBox2i(
|
||||
0, 0,
|
||||
Math.Min(PixelWidth, bufImg.Width),
|
||||
Math.Min(PixelHeight, bufImg.Height)));
|
||||
|
||||
handle.DrawTexture(_data.Texture, Vector2.Zero);
|
||||
}
|
||||
|
||||
public void StopLoad()
|
||||
{
|
||||
if (_data == null)
|
||||
throw new InvalidOperationException();
|
||||
|
||||
_data.Browser.StopLoad();
|
||||
}
|
||||
|
||||
public void Reload()
|
||||
{
|
||||
if (_data == null)
|
||||
throw new InvalidOperationException();
|
||||
|
||||
_data.Browser.Reload();
|
||||
}
|
||||
|
||||
public bool GoBack()
|
||||
{
|
||||
if (_data == null)
|
||||
throw new InvalidOperationException();
|
||||
|
||||
if (!_data.Browser.CanGoBack)
|
||||
return false;
|
||||
|
||||
_data.Browser.GoBack();
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool GoForward()
|
||||
{
|
||||
if (_data == null)
|
||||
throw new InvalidOperationException();
|
||||
|
||||
if (!_data.Browser.CanGoForward)
|
||||
return false;
|
||||
|
||||
_data.Browser.GoForward();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void ExecuteJavaScript(string code)
|
||||
{
|
||||
if (_data == null)
|
||||
throw new InvalidOperationException();
|
||||
|
||||
// TODO: this should not run until the browser is done loading seriously does this even work?
|
||||
_data.Browser.GetMainFrame().ExecuteJavaScript(code, string.Empty, 1);
|
||||
}
|
||||
|
||||
public void AddResourceRequestHandler(Action<RequestHandlerContext> handler)
|
||||
{
|
||||
_requestHandler.AddResourceRequestHandler(handler);
|
||||
}
|
||||
|
||||
public void RemoveResourceRequestHandler(Action<RequestHandlerContext> handler)
|
||||
{
|
||||
_requestHandler.RemoveResourceRequestHandler(handler);
|
||||
}
|
||||
|
||||
public void AddBeforeBrowseHandler(Action<BeforeBrowseContext> handler)
|
||||
{
|
||||
_requestHandler.AddBeforeBrowseHandler(handler);
|
||||
}
|
||||
|
||||
public void RemoveBeforeBrowseHandler(Action<BeforeBrowseContext> handler)
|
||||
{
|
||||
_requestHandler.RemoveBeforeBrowseHandler(handler);
|
||||
}
|
||||
|
||||
private sealed class LiveData
|
||||
{
|
||||
public OwnedTexture Texture;
|
||||
public readonly RobustCefClient Client;
|
||||
public readonly CefBrowser Browser;
|
||||
public readonly ControlRenderHandler Renderer;
|
||||
|
||||
public LiveData(
|
||||
OwnedTexture texture,
|
||||
RobustCefClient client,
|
||||
CefBrowser browser,
|
||||
ControlRenderHandler renderer)
|
||||
{
|
||||
Texture = texture;
|
||||
Client = client;
|
||||
Browser = browser;
|
||||
Renderer = renderer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class ControlRenderHandler : CefRenderHandler
|
||||
{
|
||||
public ImageBuffer Buffer { get; }
|
||||
private Control _control;
|
||||
|
||||
internal ControlRenderHandler(Control control)
|
||||
{
|
||||
Buffer = new ImageBuffer(control);
|
||||
_control = control;
|
||||
}
|
||||
|
||||
protected override CefAccessibilityHandler? GetAccessibilityHandler() => null;
|
||||
|
||||
protected override void GetViewRect(CefBrowser browser, out CefRectangle rect)
|
||||
{
|
||||
if (_control.Disposed)
|
||||
{
|
||||
rect = new CefRectangle();
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO CEF: Do we need to pass real screen coords? Cause what we do already works...
|
||||
//var screenCoords = _control.ScreenCoordinates;
|
||||
//rect = new CefRectangle((int) screenCoords.X, (int) screenCoords.Y, (int)Math.Max(_control.Size.X, 1), (int)Math.Max(_control.Size.Y, 1));
|
||||
|
||||
// We do the max between size and 1 because it will LITERALLY CRASH WITHOUT AN ERROR otherwise.
|
||||
rect = new CefRectangle(0, 0, (int) Math.Max(_control.Size.X, 1), (int) Math.Max(_control.Size.Y, 1));
|
||||
}
|
||||
|
||||
protected override bool GetScreenInfo(CefBrowser browser, CefScreenInfo screenInfo)
|
||||
{
|
||||
if (_control.Disposed)
|
||||
return false;
|
||||
|
||||
// TODO CEF: Get actual scale factor?
|
||||
screenInfo.DeviceScaleFactor = 1.0f;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnPopupSize(CefBrowser browser, CefRectangle rect)
|
||||
{
|
||||
if (_control.Disposed)
|
||||
return;
|
||||
}
|
||||
|
||||
protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects,
|
||||
IntPtr buffer, int width, int height)
|
||||
{
|
||||
if (_control.Disposed)
|
||||
return;
|
||||
|
||||
foreach (var dirtyRect in dirtyRects)
|
||||
{
|
||||
Buffer.UpdateBuffer(width, height, buffer, dirtyRect);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnAcceleratedPaint(CefBrowser browser, CefPaintElementType type,
|
||||
CefRectangle[] dirtyRects, IntPtr sharedHandle)
|
||||
{
|
||||
// Unused, but we're forced to implement it so.. NOOP.
|
||||
}
|
||||
|
||||
protected override void OnScrollOffsetChanged(CefBrowser browser, double x, double y)
|
||||
{
|
||||
if (_control.Disposed)
|
||||
return;
|
||||
}
|
||||
|
||||
protected override void OnImeCompositionRangeChanged(CefBrowser browser, CefRange selectedRange,
|
||||
CefRectangle[] characterBounds)
|
||||
{
|
||||
if (_control.Disposed)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
// The library we're using right now. TODO CEF: Do we want to use something else? We will need to ship it ourselves if so.
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace Robust.Client.CEF
|
||||
{
|
||||
// Register this with IoC.
|
||||
// TODO CEF: think if making this inherit CefApp is a good idea...
|
||||
// TODO CEF: A way to handle external window browsers...
|
||||
[UsedImplicitly]
|
||||
public partial class CefManager
|
||||
{
|
||||
private CefApp _app = default!;
|
||||
private bool _initialized = false;
|
||||
|
||||
/// <summary>
|
||||
/// Call this to initialize CEF.
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
DebugTools.Assert(!_initialized);
|
||||
|
||||
string subProcessName;
|
||||
if (OperatingSystem.IsWindows())
|
||||
subProcessName = "Robust.Client.CEF.exe";
|
||||
else if (OperatingSystem.IsLinux())
|
||||
subProcessName = "Robust.Client.CEF";
|
||||
else
|
||||
throw new NotSupportedException("Unsupported platform for CEF!");
|
||||
|
||||
var subProcessPath = PathHelpers.ExecutableRelativeFile(subProcessName);
|
||||
|
||||
var settings = new CefSettings()
|
||||
{
|
||||
WindowlessRenderingEnabled = true, // So we can render to our UI controls.
|
||||
ExternalMessagePump = false, // Unsure, honestly. TODO CEF: Research this?
|
||||
NoSandbox = true, // Not disabling the sandbox crashes CEF.
|
||||
BrowserSubprocessPath = subProcessPath,
|
||||
LocalesDirPath = Path.Combine(PathHelpers.GetExecutableDirectory(), "locales"),
|
||||
ResourcesDirPath = PathHelpers.GetExecutableDirectory(),
|
||||
RemoteDebuggingPort = 9222
|
||||
};
|
||||
|
||||
Logger.Info($"CEF Version: {CefRuntime.ChromeVersion}");
|
||||
|
||||
// --------------------------- README --------------------------------------------------
|
||||
// By the way! You're gonna need the CEF binaries in your client's bin folder.
|
||||
// More specifically, version cef_binary_94.4.1+g4b61a8c+chromium-94.0.4606.54
|
||||
// Windows: https://cef-builds.spotifycdn.com/cef_binary_94.4.1%2Bg4b61a8c%2Bchromium-94.0.4606.54_windows64_minimal.tar.bz2
|
||||
// Linux: https://cef-builds.spotifycdn.com/cef_binary_94.4.1%2Bg4b61a8c%2Bchromium-94.0.4606.54_linux64_minimal.tar.bz2
|
||||
// Here's how to get it to work:
|
||||
// 1. Copy all the contents of "Release" to the bin/Content.Client folder.
|
||||
// 2. Copy all the contents of "Resources" to the bin/Content.Client folder.
|
||||
// -------------------------------------------------------------------------------------
|
||||
|
||||
_app = new RobustCefApp();
|
||||
|
||||
// We pass no main arguments...
|
||||
CefRuntime.Initialize(new CefMainArgs(null), settings, _app, IntPtr.Zero);
|
||||
|
||||
// TODO CEF: After this point, debugging breaks. No, literally. My client crashes but ONLY with the debugger.
|
||||
// I have tried using the DEBUG and RELEASE versions of libcef.so, stripped or non-stripped...
|
||||
// And nothing seemed to work. Odd.
|
||||
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
public void CheckInitialized()
|
||||
{
|
||||
if (!_initialized)
|
||||
throw new InvalidOperationException("CefManager has not been initialized!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Needs to be called regularly for CEF to keep working.
|
||||
/// </summary>
|
||||
public void Update()
|
||||
{
|
||||
DebugTools.Assert(_initialized);
|
||||
|
||||
// Calling this makes CEF do its work, without using its own update loop.
|
||||
CefRuntime.DoMessageLoopWork();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Call before program shutdown.
|
||||
/// </summary>
|
||||
public void Shutdown()
|
||||
{
|
||||
DebugTools.Assert(_initialized);
|
||||
|
||||
CefRuntime.Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Robust.Client.CEF
|
||||
{
|
||||
public interface IBrowserWindow : IBrowserControl, IDisposable
|
||||
{
|
||||
bool Closed { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
using System;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace Robust.Client.CEF
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
// This was supposed to be the main entry for the subprocess program... It doesn't work.
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
// This is a workaround for this to work on UNIX.
|
||||
var argv = args;
|
||||
if (CefRuntime.Platform != CefRuntimePlatform.Windows)
|
||||
{
|
||||
argv = new string[args.Length + 1];
|
||||
Array.Copy(args, 0, argv, 1, args.Length);
|
||||
argv[0] = "-";
|
||||
}
|
||||
|
||||
var mainArgs = new CefMainArgs(argv);
|
||||
|
||||
// This will block executing until the subprocess is shut down.
|
||||
var code = CefRuntime.ExecuteProcess(mainArgs, null, IntPtr.Zero);
|
||||
|
||||
if (code != 0)
|
||||
{
|
||||
System.Console.WriteLine($"CEF Subprocess exited unsuccessfully with exit code {code}! Arguments: {string.Join(' ', argv)}");
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="..\MSBuild\Robust.Properties.targets" />
|
||||
<Import Project="..\MSBuild\Robust.Engine.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<OutputType>WinExe</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="..\MSBuild\Robust.DefineConstants.targets" />
|
||||
<Target Name="RobustAfterBuild" AfterTargets="Build" />
|
||||
<Import Project="..\MSBuild\Robust.Engine.targets" />
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2020.3.0" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\cefglue\CefGlue\CefGlue.csproj" />
|
||||
<ProjectReference Include="..\Robust.Client\Robust.Client.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -13,5 +13,6 @@
|
||||
<Compile Link="XamlX\filename" Include="../XamlX/src/XamlX/**/*.cs" />
|
||||
<Compile Remove="../XamlX/src/XamlX/**/SreTypeSystem.cs" />
|
||||
<Compile Remove="../XamlX/src/XamlX/obj/**" />
|
||||
<Compile Include="..\Robust.Client\UserInterface\ControlPropertyAccess.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Text;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
using Robust.Client.UserInterface;
|
||||
using XamlX.Ast;
|
||||
using XamlX.Emit;
|
||||
using XamlX.IL;
|
||||
@@ -37,9 +38,10 @@ namespace Robust.Client.AutoGenerated
|
||||
|
||||
class NameVisitor : IXamlAstVisitor
|
||||
{
|
||||
private List<(string name, string type)> _names = new List<(string name, string type)>();
|
||||
private readonly List<(string name, string type, AccessLevel access)> _names =
|
||||
new List<(string name, string type, AccessLevel access)>();
|
||||
|
||||
public static List<(string name, string type)> GetNames(IXamlAstNode node)
|
||||
public static List<(string name, string type, AccessLevel access)> GetNames(IXamlAstNode node)
|
||||
{
|
||||
var visitor = new NameVisitor();
|
||||
node.Visit(visitor);
|
||||
@@ -56,27 +58,42 @@ namespace Robust.Client.AutoGenerated
|
||||
{
|
||||
var clrtype = objectNode.Type.GetClrType();
|
||||
var isControl = IsControl(clrtype);
|
||||
//clrtype.Interfaces.Any(i =>
|
||||
//i.IsInterface && i.FullName == "Robust.Client.UserInterface.IControl");
|
||||
|
||||
if (!isControl)
|
||||
return node;
|
||||
|
||||
// Find Name and Access properties
|
||||
XamlAstTextNode nameText = null;
|
||||
XamlAstTextNode accessText = null;
|
||||
foreach (var child in objectNode.Children)
|
||||
{
|
||||
if (child is XamlAstXamlPropertyValueNode propertyValueNode &&
|
||||
propertyValueNode.Property is XamlAstNamePropertyReference namedProperty &&
|
||||
namedProperty.Name == "Name" &&
|
||||
propertyValueNode.Values.Count > 0 &&
|
||||
propertyValueNode.Values[0] is XamlAstTextNode text)
|
||||
{
|
||||
var reg = (text.Text, $@"{clrtype.Namespace}.{clrtype.Name}");
|
||||
if (!_names.Contains(reg))
|
||||
switch (namedProperty.Name)
|
||||
{
|
||||
_names.Add(reg);
|
||||
case "Name":
|
||||
nameText = text;
|
||||
break;
|
||||
case "Access":
|
||||
accessText = text;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nameText == null)
|
||||
return node;
|
||||
|
||||
var reg = (nameText.Text,
|
||||
$@"{clrtype.Namespace}.{clrtype.Name}",
|
||||
accessText != null ? (AccessLevel) Enum.Parse(typeof(AccessLevel), accessText.Text) : AccessLevel.Protected);
|
||||
if (!_names.Contains(reg))
|
||||
{
|
||||
_names.Add(reg);
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
@@ -94,7 +111,8 @@ namespace Robust.Client.AutoGenerated
|
||||
private static string GenerateSourceCode(
|
||||
INamedTypeSymbol classSymbol,
|
||||
string xamlFile,
|
||||
CSharpCompilation comp)
|
||||
CSharpCompilation comp,
|
||||
string fileName)
|
||||
{
|
||||
var className = classSymbol.Name;
|
||||
var nameSpace = classSymbol.ContainingNamespace.ToDisplayString();
|
||||
@@ -118,11 +136,42 @@ namespace Robust.Client.AutoGenerated
|
||||
if (classSymbol.ToString() != rootTypeString && classSymbol.BaseType?.ToString() != rootTypeString)
|
||||
throw new InvalidXamlRootTypeException(rootType, classSymbol, classSymbol.BaseType);
|
||||
|
||||
var fieldAccess = classSymbol.IsSealed ? "private" : "protected";
|
||||
//var names = NameVisitor.GetNames((XamlAstObjectNode)XDocumentXamlParser.Parse(xamlFile).Root);
|
||||
var namedControls = names.Select(info => " " +
|
||||
$"{fieldAccess} global::{info.type} {info.name} => " +
|
||||
$"this.FindControl<global::{info.type}>(\"{info.name}\");");
|
||||
var namedControls = names.Select(info =>
|
||||
{
|
||||
(string name, string type, AccessLevel access) = info;
|
||||
|
||||
string accessStr;
|
||||
switch (access)
|
||||
{
|
||||
case AccessLevel.Public:
|
||||
accessStr = "public";
|
||||
break;
|
||||
case AccessLevel.Protected when classSymbol.IsSealed:
|
||||
case AccessLevel.PrivateProtected when classSymbol.IsSealed:
|
||||
case AccessLevel.Private:
|
||||
accessStr = "private";
|
||||
break;
|
||||
case AccessLevel.Protected:
|
||||
accessStr = "protected";
|
||||
break;
|
||||
case AccessLevel.PrivateProtected:
|
||||
accessStr = "private protected";
|
||||
break;
|
||||
case AccessLevel.Internal:
|
||||
case AccessLevel.ProtectedInternal when classSymbol.IsSealed:
|
||||
accessStr = "internal";
|
||||
break;
|
||||
case AccessLevel.ProtectedInternal:
|
||||
accessStr = "protected internal";
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException($"Invalid access level \"{Enum.GetName(typeof(AccessLevel), access)}\" " +
|
||||
$"for control {name} in file {fileName}.");
|
||||
}
|
||||
|
||||
return $" {accessStr} global::{type} {name} => this.FindControl<global::{type}>(\"{name}\");";
|
||||
});
|
||||
|
||||
return $@"// <auto-generated />
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
@@ -136,7 +185,6 @@ namespace {nameSpace}
|
||||
";
|
||||
}
|
||||
|
||||
|
||||
public void Execute(GeneratorExecutionContext context)
|
||||
{
|
||||
var comp = (CSharpCompilation) context.Compilation;
|
||||
@@ -207,7 +255,7 @@ namespace {nameSpace}
|
||||
|
||||
try
|
||||
{
|
||||
var sourceCode = GenerateSourceCode(typeSymbol, txt, comp);
|
||||
var sourceCode = GenerateSourceCode(typeSymbol, txt, comp, xamlFileName);
|
||||
context.AddSource($"{typeSymbol.Name}.g.cs", SourceText.From(sourceCode, Encoding.UTF8));
|
||||
}
|
||||
catch (InvalidXamlRootTypeException invRootType)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Robust.Client.CEF
|
||||
namespace Robust.Client.WebView
|
||||
{
|
||||
public sealed class BrowserWindowCreateParameters
|
||||
{
|
||||
@@ -1,8 +1,8 @@
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace Robust.Client.CEF
|
||||
namespace Robust.Client.WebView.Cef
|
||||
{
|
||||
public sealed class BeforeBrowseContext
|
||||
internal sealed class CefBeforeBrowseContext : IBeforeBrowseContext
|
||||
{
|
||||
internal readonly CefRequest CefRequest;
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Robust.Client.CEF
|
||||
|
||||
public bool IsCancelled { get; private set; }
|
||||
|
||||
internal BeforeBrowseContext(
|
||||
internal CefBeforeBrowseContext(
|
||||
bool isRedirect,
|
||||
bool userGesture,
|
||||
CefRequest cefRequest)
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Robust.Client.CEF
|
||||
namespace Robust.Client.WebView.Cef
|
||||
{
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
||||
@@ -3,9 +3,9 @@ using System.IO;
|
||||
using System.Net;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace Robust.Client.CEF
|
||||
namespace Robust.Client.WebView.Cef
|
||||
{
|
||||
public sealed class RequestHandlerContext
|
||||
internal sealed class CefRequestHandlerContext : IRequestHandlerContext
|
||||
{
|
||||
internal readonly CefRequest CefRequest;
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Robust.Client.CEF
|
||||
|
||||
internal IRequestResult? Result { get; private set; }
|
||||
|
||||
internal RequestHandlerContext(
|
||||
internal CefRequestHandlerContext(
|
||||
bool isNavigation,
|
||||
bool isDownload,
|
||||
string requestInitiator,
|
||||
@@ -1,22 +1,14 @@
|
||||
using System;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.Utility;
|
||||
using Robust.Shared.Maths;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace Robust.Client.CEF
|
||||
namespace Robust.Client.WebView.Cef
|
||||
{
|
||||
internal sealed class ImageBuffer
|
||||
{
|
||||
private readonly Control _control;
|
||||
|
||||
public ImageBuffer(Control control)
|
||||
{
|
||||
_control = control;
|
||||
}
|
||||
|
||||
public Image<Bgra32> Buffer { get; private set; } = new(1, 1);
|
||||
|
||||
public unsafe void UpdateBuffer(int width, int height, IntPtr buffer, CefRectangle dirtyRect)
|
||||
88
Robust.Client.WebView/Cef/Program.cs
Normal file
88
Robust.Client.WebView/Cef/Program.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace Robust.Client.WebView.Cef
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
// This was supposed to be the main entry for the subprocess program... It doesn't work.
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
// This is a workaround for this to work on UNIX.
|
||||
var argv = args;
|
||||
if (CefRuntime.Platform != CefRuntimePlatform.Windows)
|
||||
{
|
||||
argv = new string[args.Length + 1];
|
||||
Array.Copy(args, 0, argv, 1, args.Length);
|
||||
argv[0] = "-";
|
||||
}
|
||||
/*
|
||||
if (OperatingSystem.IsLinux())
|
||||
{
|
||||
// Chromium tries to load libEGL.so and libGLESv2.so relative to the process executable on Linux.
|
||||
// (Compared to Windows where it is relative to Chromium's *module*)
|
||||
// There is a TODO "is this correct?" in the Chromium code for this.
|
||||
// Great.
|
||||
|
||||
//CopyDllToExecutableDir("libEGL.so");
|
||||
//CopyDllToExecutableDir("libGLESv2.so");
|
||||
|
||||
// System.Threading.Thread.Sleep(200000);
|
||||
}
|
||||
*/
|
||||
var mainArgs = new CefMainArgs(argv);
|
||||
|
||||
// This will block executing until the subprocess is shut down.
|
||||
var code = CefRuntime.ExecuteProcess(mainArgs, null, IntPtr.Zero);
|
||||
|
||||
if (code != 0)
|
||||
{
|
||||
System.Console.WriteLine($"CEF Subprocess exited unsuccessfully with exit code {code}! Arguments: {string.Join(' ', argv)}");
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
/* private static void CopyDllToExecutableDir(string dllName)
|
||||
{
|
||||
var executableDir = PathHelpers.GetExecutableDirectory();
|
||||
var targetPath = Path.Combine(executableDir, dllName);
|
||||
if (File.Exists(targetPath))
|
||||
return;
|
||||
|
||||
// Find source file.
|
||||
string? srcFile = null;
|
||||
foreach (var searchDir in WebViewManagerCef.NativeDllSearchDirectories())
|
||||
{
|
||||
var searchPath = Path.Combine(searchDir, dllName);
|
||||
if (File.Exists(searchPath))
|
||||
{
|
||||
srcFile = searchPath;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (srcFile == null)
|
||||
return;
|
||||
|
||||
for (var i = 0; i < 5; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(targetPath))
|
||||
return;
|
||||
|
||||
File.Copy(srcFile, targetPath);
|
||||
return;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Catching race condition lock errors and stuff I guess.
|
||||
}
|
||||
}
|
||||
} */
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ using System.IO;
|
||||
using System.Net;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace Robust.Client.CEF
|
||||
namespace Robust.Client.WebView.Cef
|
||||
{
|
||||
internal interface IRequestResult
|
||||
{
|
||||
@@ -88,6 +88,13 @@ namespace Robust.Client.CEF
|
||||
protected override void Cancel()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
_stream.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace Robust.Client.CEF
|
||||
namespace Robust.Client.WebView.Cef
|
||||
{
|
||||
internal class RobustCefApp : CefApp
|
||||
{
|
||||
@@ -24,6 +24,13 @@ namespace Robust.Client.CEF
|
||||
{
|
||||
// Disable zygote on Linux.
|
||||
commandLine.AppendSwitch("--no-zygote");
|
||||
|
||||
// Work around https://bitbucket.org/chromiumembedded/cef/issues/3213/ozone-egl-initialization-does-not-have
|
||||
// Desktop GL force makes Chromium not try to load its own ANGLE/Swiftshader so load paths aren't problematic.
|
||||
if (OperatingSystem.IsLinux())
|
||||
commandLine.AppendSwitch("--use-gl", "desktop");
|
||||
|
||||
// commandLine.AppendSwitch("--single-process");
|
||||
|
||||
//commandLine.AppendSwitch("--disable-gpu");
|
||||
//commandLine.AppendSwitch("--disable-gpu-compositing");
|
||||
@@ -1,6 +1,6 @@
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace Robust.Client.CEF
|
||||
namespace Robust.Client.WebView.Cef
|
||||
{
|
||||
// Simple CEF client.
|
||||
internal class RobustCefClient : CefClient
|
||||
@@ -1,6 +1,6 @@
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace Robust.Client.CEF
|
||||
namespace Robust.Client.WebView.Cef
|
||||
{
|
||||
public sealed class RobustLoadHandler : CefLoadHandler
|
||||
{
|
||||
@@ -3,20 +3,20 @@ using System.Collections.Generic;
|
||||
using Robust.Shared.Log;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace Robust.Client.CEF
|
||||
namespace Robust.Client.WebView.Cef
|
||||
{
|
||||
internal sealed class RobustRequestHandler : CefRequestHandler
|
||||
{
|
||||
private readonly ISawmill _sawmill;
|
||||
private readonly List<Action<RequestHandlerContext>> _resourceRequestHandlers = new();
|
||||
private readonly List<Action<BeforeBrowseContext>> _beforeBrowseHandlers = new();
|
||||
private readonly List<Action<IRequestHandlerContext>> _resourceRequestHandlers = new();
|
||||
private readonly List<Action<IBeforeBrowseContext>> _beforeBrowseHandlers = new();
|
||||
|
||||
public RobustRequestHandler(ISawmill sawmill)
|
||||
{
|
||||
_sawmill = sawmill;
|
||||
}
|
||||
|
||||
public void AddResourceRequestHandler(Action<RequestHandlerContext> handler)
|
||||
public void AddResourceRequestHandler(Action<IRequestHandlerContext> handler)
|
||||
{
|
||||
lock (_resourceRequestHandlers)
|
||||
{
|
||||
@@ -24,7 +24,7 @@ namespace Robust.Client.CEF
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveResourceRequestHandler(Action<RequestHandlerContext> handler)
|
||||
public void RemoveResourceRequestHandler(Action<IRequestHandlerContext> handler)
|
||||
{
|
||||
lock (_resourceRequestHandlers)
|
||||
{
|
||||
@@ -32,7 +32,7 @@ namespace Robust.Client.CEF
|
||||
}
|
||||
}
|
||||
|
||||
public void AddBeforeBrowseHandler(Action<BeforeBrowseContext> handler)
|
||||
public void AddBeforeBrowseHandler(Action<IBeforeBrowseContext> handler)
|
||||
{
|
||||
lock (_beforeBrowseHandlers)
|
||||
{
|
||||
@@ -40,7 +40,7 @@ namespace Robust.Client.CEF
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveBeforeBrowseHandler(Action<BeforeBrowseContext> handler)
|
||||
public void RemoveBeforeBrowseHandler(Action<IBeforeBrowseContext> handler)
|
||||
{
|
||||
lock (_beforeBrowseHandlers)
|
||||
{
|
||||
@@ -61,7 +61,7 @@ namespace Robust.Client.CEF
|
||||
{
|
||||
_sawmill.Debug($"HANDLING REQUEST: {request.Url}");
|
||||
|
||||
var context = new RequestHandlerContext(isNavigation, isDownload, requestInitiator, request);
|
||||
var context = new CefRequestHandlerContext(isNavigation, isDownload, requestInitiator, request);
|
||||
|
||||
foreach (var handler in _resourceRequestHandlers)
|
||||
{
|
||||
@@ -85,7 +85,7 @@ namespace Robust.Client.CEF
|
||||
{
|
||||
lock (_beforeBrowseHandlers)
|
||||
{
|
||||
var context = new BeforeBrowseContext(isRedirect, userGesture, request);
|
||||
var context = new CefBeforeBrowseContext(isRedirect, userGesture, request);
|
||||
|
||||
foreach (var handler in _beforeBrowseHandlers)
|
||||
{
|
||||
@@ -6,26 +6,25 @@ using Robust.Shared.Log;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace Robust.Client.CEF
|
||||
namespace Robust.Client.WebView.Cef
|
||||
{
|
||||
public partial class CefManager
|
||||
internal partial class WebViewManagerCef
|
||||
{
|
||||
[Dependency] private readonly IClydeInternal _clyde = default!;
|
||||
|
||||
private readonly List<BrowserWindowImpl> _browserWindows = new();
|
||||
private readonly List<WebViewWindowImpl> _browserWindows = new();
|
||||
|
||||
public IEnumerable<IBrowserWindow> AllBrowserWindows => _browserWindows;
|
||||
public IEnumerable<IWebViewWindow> AllBrowserWindows => _browserWindows;
|
||||
|
||||
public IBrowserWindow CreateBrowserWindow(BrowserWindowCreateParameters createParams)
|
||||
public IWebViewWindow CreateBrowserWindow(BrowserWindowCreateParameters createParams)
|
||||
{
|
||||
var mainHWnd = (_clyde.MainWindow as IClydeWindowInternal)?.WindowsHWnd ?? 0;
|
||||
|
||||
var info = CefWindowInfo.Create();
|
||||
info.Width = createParams.Width;
|
||||
info.Height = createParams.Height;
|
||||
info.Bounds = new CefRectangle(0, 0, createParams.Width, createParams.Height);
|
||||
info.SetAsPopup(mainHWnd, "ss14cef");
|
||||
|
||||
var impl = new BrowserWindowImpl(this);
|
||||
var impl = new WebViewWindowImpl(this);
|
||||
|
||||
var lifeSpanHandler = new WindowLifeSpanHandler(impl);
|
||||
var reqHandler = new RobustRequestHandler(Logger.GetSawmill("root"));
|
||||
@@ -40,13 +39,13 @@ namespace Robust.Client.CEF
|
||||
return impl;
|
||||
}
|
||||
|
||||
private sealed class BrowserWindowImpl : IBrowserWindow
|
||||
private sealed class WebViewWindowImpl : IWebViewWindow
|
||||
{
|
||||
private readonly CefManager _manager;
|
||||
private readonly WebViewManagerCef _manager;
|
||||
internal CefBrowser Browser = default!;
|
||||
internal RobustRequestHandler RequestHandler = default!;
|
||||
|
||||
public Action<RequestHandlerContext>? OnResourceRequest { get; set; }
|
||||
public Action<CefRequestHandlerContext>? OnResourceRequest { get; set; }
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public string Url
|
||||
@@ -73,7 +72,7 @@ namespace Robust.Client.CEF
|
||||
}
|
||||
}
|
||||
|
||||
public BrowserWindowImpl(CefManager manager)
|
||||
public WebViewWindowImpl(WebViewManagerCef manager)
|
||||
{
|
||||
_manager = manager;
|
||||
}
|
||||
@@ -116,12 +115,12 @@ namespace Robust.Client.CEF
|
||||
Browser.GetMainFrame().ExecuteJavaScript(code, string.Empty, 1);
|
||||
}
|
||||
|
||||
public void AddResourceRequestHandler(Action<RequestHandlerContext> handler)
|
||||
public void AddResourceRequestHandler(Action<IRequestHandlerContext> handler)
|
||||
{
|
||||
RequestHandler.AddResourceRequestHandler(handler);
|
||||
}
|
||||
|
||||
public void RemoveResourceRequestHandler(Action<RequestHandlerContext> handler)
|
||||
public void RemoveResourceRequestHandler(Action<IRequestHandlerContext> handler)
|
||||
{
|
||||
RequestHandler.RemoveResourceRequestHandler(handler);
|
||||
}
|
||||
@@ -168,9 +167,9 @@ namespace Robust.Client.CEF
|
||||
|
||||
private sealed class WindowLifeSpanHandler : CefLifeSpanHandler
|
||||
{
|
||||
private readonly BrowserWindowImpl _windowImpl;
|
||||
private readonly WebViewWindowImpl _windowImpl;
|
||||
|
||||
public WindowLifeSpanHandler(BrowserWindowImpl windowImpl)
|
||||
public WindowLifeSpanHandler(WebViewWindowImpl windowImpl)
|
||||
{
|
||||
_windowImpl = windowImpl;
|
||||
}
|
||||
580
Robust.Client.WebView/Cef/WebViewManagerCef.Control.cs
Normal file
580
Robust.Client.WebView/Cef/WebViewManagerCef.Control.cs
Normal file
@@ -0,0 +1,580 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Input;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Utility;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using Xilium.CefGlue;
|
||||
using static Robust.Client.WebView.Cef.CefKeyCodes.ChromiumKeyboardCode;
|
||||
using static Robust.Client.Input.Keyboard;
|
||||
|
||||
namespace Robust.Client.WebView.Cef
|
||||
{
|
||||
internal partial class WebViewManagerCef
|
||||
{
|
||||
public IWebViewControlImpl MakeControlImpl(WebViewControl owner)
|
||||
{
|
||||
var impl = new ControlImpl(owner);
|
||||
_dependencyCollection.InjectDependencies(impl);
|
||||
return impl;
|
||||
}
|
||||
|
||||
private sealed class ControlImpl : IWebViewControlImpl
|
||||
{
|
||||
private static readonly Dictionary<Key, CefKeyCodes.ChromiumKeyboardCode> KeyMap = new()
|
||||
{
|
||||
[Key.A] = VKEY_A,
|
||||
[Key.B] = VKEY_B,
|
||||
[Key.C] = VKEY_C,
|
||||
[Key.D] = VKEY_D,
|
||||
[Key.E] = VKEY_E,
|
||||
[Key.F] = VKEY_F,
|
||||
[Key.G] = VKEY_G,
|
||||
[Key.H] = VKEY_H,
|
||||
[Key.I] = VKEY_I,
|
||||
[Key.J] = VKEY_J,
|
||||
[Key.K] = VKEY_K,
|
||||
[Key.L] = VKEY_L,
|
||||
[Key.M] = VKEY_M,
|
||||
[Key.N] = VKEY_N,
|
||||
[Key.O] = VKEY_O,
|
||||
[Key.P] = VKEY_P,
|
||||
[Key.Q] = VKEY_Q,
|
||||
[Key.R] = VKEY_R,
|
||||
[Key.S] = VKEY_S,
|
||||
[Key.T] = VKEY_T,
|
||||
[Key.U] = VKEY_U,
|
||||
[Key.V] = VKEY_V,
|
||||
[Key.W] = VKEY_W,
|
||||
[Key.X] = VKEY_X,
|
||||
[Key.Y] = VKEY_Y,
|
||||
[Key.Z] = VKEY_Z,
|
||||
[Key.Num0] = VKEY_0,
|
||||
[Key.Num1] = VKEY_1,
|
||||
[Key.Num2] = VKEY_2,
|
||||
[Key.Num3] = VKEY_3,
|
||||
[Key.Num4] = VKEY_4,
|
||||
[Key.Num5] = VKEY_5,
|
||||
[Key.Num6] = VKEY_6,
|
||||
[Key.Num7] = VKEY_7,
|
||||
[Key.Num8] = VKEY_8,
|
||||
[Key.Num9] = VKEY_9,
|
||||
[Key.NumpadNum0] = VKEY_NUMPAD0,
|
||||
[Key.NumpadNum1] = VKEY_NUMPAD1,
|
||||
[Key.NumpadNum2] = VKEY_NUMPAD2,
|
||||
[Key.NumpadNum3] = VKEY_NUMPAD3,
|
||||
[Key.NumpadNum4] = VKEY_NUMPAD4,
|
||||
[Key.NumpadNum5] = VKEY_NUMPAD5,
|
||||
[Key.NumpadNum6] = VKEY_NUMPAD6,
|
||||
[Key.NumpadNum7] = VKEY_NUMPAD7,
|
||||
[Key.NumpadNum8] = VKEY_NUMPAD8,
|
||||
[Key.NumpadNum9] = VKEY_NUMPAD9,
|
||||
[Key.Escape] = VKEY_ESCAPE,
|
||||
[Key.Control] = VKEY_CONTROL,
|
||||
[Key.Shift] = VKEY_SHIFT,
|
||||
[Key.Alt] = VKEY_MENU,
|
||||
[Key.LSystem] = VKEY_LWIN,
|
||||
[Key.RSystem] = VKEY_RWIN,
|
||||
[Key.LBracket] = VKEY_OEM_4,
|
||||
[Key.RBracket] = VKEY_OEM_6,
|
||||
[Key.SemiColon] = VKEY_OEM_1,
|
||||
[Key.Comma] = VKEY_OEM_COMMA,
|
||||
[Key.Period] = VKEY_OEM_PERIOD,
|
||||
[Key.Apostrophe] = VKEY_OEM_7,
|
||||
[Key.Slash] = VKEY_OEM_2,
|
||||
[Key.BackSlash] = VKEY_OEM_5,
|
||||
[Key.Tilde] = VKEY_OEM_3,
|
||||
[Key.Equal] = VKEY_OEM_PLUS,
|
||||
[Key.Space] = VKEY_SPACE,
|
||||
[Key.Return] = VKEY_RETURN,
|
||||
[Key.BackSpace] = VKEY_BACK,
|
||||
[Key.Tab] = VKEY_TAB,
|
||||
[Key.PageUp] = VKEY_PRIOR,
|
||||
[Key.PageDown] = VKEY_NEXT,
|
||||
[Key.End] = VKEY_END,
|
||||
[Key.Home] = VKEY_HOME,
|
||||
[Key.Insert] = VKEY_INSERT,
|
||||
[Key.Delete] = VKEY_DELETE,
|
||||
[Key.Minus] = VKEY_OEM_MINUS,
|
||||
[Key.NumpadAdd] = VKEY_ADD,
|
||||
[Key.NumpadSubtract] = VKEY_SUBTRACT,
|
||||
[Key.NumpadDivide] = VKEY_DIVIDE,
|
||||
[Key.NumpadMultiply] = VKEY_MULTIPLY,
|
||||
[Key.NumpadDecimal] = VKEY_DECIMAL,
|
||||
[Key.Left] = VKEY_LEFT,
|
||||
[Key.Right] = VKEY_RIGHT,
|
||||
[Key.Up] = VKEY_UP,
|
||||
[Key.Down] = VKEY_DOWN,
|
||||
[Key.F1] = VKEY_F1,
|
||||
[Key.F2] = VKEY_F2,
|
||||
[Key.F3] = VKEY_F3,
|
||||
[Key.F4] = VKEY_F4,
|
||||
[Key.F5] = VKEY_F5,
|
||||
[Key.F6] = VKEY_F6,
|
||||
[Key.F7] = VKEY_F7,
|
||||
[Key.F8] = VKEY_F8,
|
||||
[Key.F9] = VKEY_F9,
|
||||
[Key.F10] = VKEY_F10,
|
||||
[Key.F11] = VKEY_F11,
|
||||
[Key.F12] = VKEY_F12,
|
||||
[Key.F13] = VKEY_F13,
|
||||
[Key.F14] = VKEY_F14,
|
||||
[Key.F15] = VKEY_F15,
|
||||
[Key.Pause] = VKEY_PAUSE,
|
||||
};
|
||||
|
||||
[Dependency] private readonly IClyde _clyde = default!;
|
||||
[Dependency] private readonly IInputManager _inputMgr = default!;
|
||||
|
||||
public readonly WebViewControl Owner;
|
||||
|
||||
public ControlImpl(WebViewControl owner)
|
||||
{
|
||||
Owner = owner;
|
||||
}
|
||||
|
||||
private const int ScrollSpeed = 50;
|
||||
|
||||
private readonly RobustRequestHandler _requestHandler = new(Logger.GetSawmill("root"));
|
||||
private LiveData? _data;
|
||||
private string _startUrl = "about:blank";
|
||||
|
||||
public string Url
|
||||
{
|
||||
get => _data == null ? _startUrl : _data.Browser.GetMainFrame().Url;
|
||||
set
|
||||
{
|
||||
if (_data == null)
|
||||
_startUrl = value;
|
||||
else
|
||||
_data.Browser.GetMainFrame().LoadUrl(value);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsLoading => _data?.Browser.IsLoading ?? false;
|
||||
|
||||
public void EnteredTree()
|
||||
{
|
||||
DebugTools.AssertNull(_data);
|
||||
|
||||
// A funny render handler that will allow us to render to the control.
|
||||
var renderer = new ControlRenderHandler(this);
|
||||
|
||||
// A funny web cef client. This can actually be shared by multiple browsers, but I'm not sure how the
|
||||
// rendering would work in that case? TODO CEF: Investigate a way to share the web client?
|
||||
var client = new RobustCefClient(renderer, _requestHandler, new RobustLoadHandler());
|
||||
|
||||
var info = CefWindowInfo.Create();
|
||||
|
||||
// FUNFACT: If you DO NOT set these below and set info.Width/info.Height instead, you get an external window
|
||||
// Good to know, huh? Setup is the same, except you can pass a dummy render handler to the CEF client.
|
||||
info.SetAsWindowless(IntPtr.Zero, false); // TODO CEF: Pass parent handle?
|
||||
info.WindowlessRenderingEnabled = true;
|
||||
|
||||
var settings = new CefBrowserSettings()
|
||||
{
|
||||
WindowlessFrameRate = 60
|
||||
};
|
||||
|
||||
// Create the web browser! And by default, we go to about:blank.
|
||||
var browser = CefBrowserHost.CreateBrowserSync(info, client, settings, _startUrl);
|
||||
|
||||
var texture = _clyde.CreateBlankTexture<Bgra32>(Vector2i.One);
|
||||
|
||||
_data = new LiveData(texture, client, browser, renderer);
|
||||
}
|
||||
|
||||
public void ExitedTree()
|
||||
{
|
||||
DebugTools.AssertNotNull(_data);
|
||||
|
||||
_data!.Texture.Dispose();
|
||||
_data.Browser.GetHost().CloseBrowser(true);
|
||||
_data = null;
|
||||
}
|
||||
|
||||
public void MouseMove(GUIMouseMoveEventArgs args)
|
||||
{
|
||||
if (_data == null)
|
||||
return;
|
||||
|
||||
// Logger.Debug();
|
||||
var modifiers = CalcMouseModifiers();
|
||||
var mouseEvent = new CefMouseEvent(
|
||||
(int)args.RelativePosition.X, (int)args.RelativePosition.Y,
|
||||
modifiers);
|
||||
|
||||
_data.Browser.GetHost().SendMouseMoveEvent(mouseEvent, false);
|
||||
}
|
||||
|
||||
public void MouseExited()
|
||||
{
|
||||
if (_data == null)
|
||||
return;
|
||||
|
||||
var modifiers = CalcMouseModifiers();
|
||||
|
||||
_data.Browser.GetHost().SendMouseMoveEvent(new CefMouseEvent(0, 0, modifiers), true);
|
||||
}
|
||||
|
||||
public void MouseWheel(GUIMouseWheelEventArgs args)
|
||||
{
|
||||
if (_data == null)
|
||||
return;
|
||||
|
||||
var modifiers = CalcMouseModifiers();
|
||||
var mouseEvent = new CefMouseEvent(
|
||||
(int)args.RelativePosition.X, (int)args.RelativePosition.Y,
|
||||
modifiers);
|
||||
|
||||
_data.Browser.GetHost().SendMouseWheelEvent(
|
||||
mouseEvent,
|
||||
(int)args.Delta.X * ScrollSpeed,
|
||||
(int)args.Delta.Y * ScrollSpeed);
|
||||
}
|
||||
|
||||
public bool RawKeyEvent(in GuiRawKeyEvent guiRawEvent)
|
||||
{
|
||||
if (_data == null)
|
||||
return false;
|
||||
|
||||
var host = _data.Browser.GetHost();
|
||||
|
||||
if (guiRawEvent.Key is Key.MouseLeft or Key.MouseMiddle or Key.MouseRight)
|
||||
{
|
||||
var key = guiRawEvent.Key switch
|
||||
{
|
||||
Key.MouseLeft => CefMouseButtonType.Left,
|
||||
Key.MouseMiddle => CefMouseButtonType.Middle,
|
||||
Key.MouseRight => CefMouseButtonType.Right,
|
||||
_ => default // not possible
|
||||
};
|
||||
|
||||
var mouseEvent = new CefMouseEvent(
|
||||
guiRawEvent.MouseRelative.X, guiRawEvent.MouseRelative.Y,
|
||||
CefEventFlags.None);
|
||||
|
||||
// Logger.Debug($"MOUSE: {guiRawEvent.Action} {guiRawEvent.Key} {guiRawEvent.ScanCode} {key}");
|
||||
|
||||
// TODO: double click support?
|
||||
host.SendMouseClickEvent(mouseEvent, key, guiRawEvent.Action == RawKeyAction.Up, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Handle left/right modifier keys??
|
||||
if (!KeyMap.TryGetValue(guiRawEvent.Key, out var vkKey))
|
||||
vkKey = default;
|
||||
|
||||
// Logger.Debug($"{guiRawEvent.Action} {guiRawEvent.Key} {guiRawEvent.ScanCode} {vkKey}");
|
||||
|
||||
var lParam = 0;
|
||||
lParam |= (guiRawEvent.ScanCode & 0xFF) << 16;
|
||||
if (guiRawEvent.Action != RawKeyAction.Down)
|
||||
lParam |= 1 << 30;
|
||||
|
||||
if (guiRawEvent.Action == RawKeyAction.Up)
|
||||
lParam |= 1 << 31;
|
||||
|
||||
var modifiers = CalcModifiers(guiRawEvent.Key);
|
||||
|
||||
host.SendKeyEvent(new CefKeyEvent
|
||||
{
|
||||
// Repeats are sent as key downs, I guess?
|
||||
EventType = guiRawEvent.Action == RawKeyAction.Up
|
||||
? CefKeyEventType.KeyUp
|
||||
: CefKeyEventType.RawKeyDown,
|
||||
NativeKeyCode = lParam,
|
||||
// NativeKeyCode = guiRawEvent.ScanCode,
|
||||
WindowsKeyCode = (int)vkKey,
|
||||
IsSystemKey = false, // TODO
|
||||
Modifiers = modifiers
|
||||
});
|
||||
|
||||
if (guiRawEvent.Action != RawKeyAction.Up && guiRawEvent.Key == Key.Return)
|
||||
{
|
||||
host.SendKeyEvent(new CefKeyEvent
|
||||
{
|
||||
EventType = CefKeyEventType.Char,
|
||||
WindowsKeyCode = '\r',
|
||||
NativeKeyCode = lParam,
|
||||
Modifiers = modifiers
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private CefEventFlags CalcModifiers(Key key)
|
||||
{
|
||||
CefEventFlags modifiers = default;
|
||||
|
||||
if (_inputMgr.IsKeyDown(Key.Control))
|
||||
modifiers |= CefEventFlags.ControlDown;
|
||||
|
||||
if (_inputMgr.IsKeyDown(Key.Alt))
|
||||
modifiers |= CefEventFlags.AltDown;
|
||||
|
||||
if (_inputMgr.IsKeyDown(Key.Shift))
|
||||
modifiers |= CefEventFlags.ShiftDown;
|
||||
|
||||
if (_inputMgr.IsKeyDown(Key.Shift))
|
||||
modifiers |= CefEventFlags.ShiftDown;
|
||||
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
private CefEventFlags CalcMouseModifiers()
|
||||
{
|
||||
CefEventFlags modifiers = default;
|
||||
|
||||
if (_inputMgr.IsKeyDown(Key.Control))
|
||||
modifiers |= CefEventFlags.ControlDown;
|
||||
|
||||
if (_inputMgr.IsKeyDown(Key.Alt))
|
||||
modifiers |= CefEventFlags.AltDown;
|
||||
|
||||
if (_inputMgr.IsKeyDown(Key.Shift))
|
||||
modifiers |= CefEventFlags.ShiftDown;
|
||||
|
||||
if (_inputMgr.IsKeyDown(Key.Shift))
|
||||
modifiers |= CefEventFlags.ShiftDown;
|
||||
|
||||
if (_inputMgr.IsKeyDown(Key.MouseLeft))
|
||||
modifiers |= CefEventFlags.LeftMouseButton;
|
||||
|
||||
if (_inputMgr.IsKeyDown(Key.MouseMiddle))
|
||||
modifiers |= CefEventFlags.MiddleMouseButton;
|
||||
|
||||
if (_inputMgr.IsKeyDown(Key.MouseRight))
|
||||
modifiers |= CefEventFlags.RightMouseButton;
|
||||
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
public void TextEntered(GUITextEventArgs args)
|
||||
{
|
||||
if (_data == null)
|
||||
return;
|
||||
|
||||
var host = _data.Browser.GetHost();
|
||||
|
||||
Span<char> buf = stackalloc char[2];
|
||||
var written = args.AsRune.EncodeToUtf16(buf);
|
||||
|
||||
for (var i = 0; i < written; i++)
|
||||
{
|
||||
host.SendKeyEvent(new CefKeyEvent
|
||||
{
|
||||
EventType = CefKeyEventType.Char,
|
||||
WindowsKeyCode = buf[i],
|
||||
Character = buf[i],
|
||||
UnmodifiedCharacter = buf[i]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void Resized()
|
||||
{
|
||||
if (_data == null)
|
||||
return;
|
||||
|
||||
_data.Browser.GetHost().NotifyMoveOrResizeStarted();
|
||||
_data.Browser.GetHost().WasResized();
|
||||
_data.Texture.Dispose();
|
||||
_data.Texture = _clyde.CreateBlankTexture<Bgra32>((Owner.PixelWidth, Owner.PixelHeight));
|
||||
}
|
||||
|
||||
public void Draw(DrawingHandleScreen handle)
|
||||
{
|
||||
if (_data == null)
|
||||
return;
|
||||
|
||||
var bufImg = _data.Renderer.Buffer.Buffer;
|
||||
|
||||
_data.Texture.SetSubImage(
|
||||
Vector2i.Zero,
|
||||
bufImg,
|
||||
new UIBox2i(
|
||||
0, 0,
|
||||
Math.Min(Owner.PixelWidth, bufImg.Width),
|
||||
Math.Min(Owner.PixelHeight, bufImg.Height)));
|
||||
|
||||
handle.DrawTexture(_data.Texture, Vector2.Zero);
|
||||
}
|
||||
|
||||
public void StopLoad()
|
||||
{
|
||||
if (_data == null)
|
||||
throw new InvalidOperationException();
|
||||
|
||||
_data.Browser.StopLoad();
|
||||
}
|
||||
|
||||
public void Reload()
|
||||
{
|
||||
if (_data == null)
|
||||
throw new InvalidOperationException();
|
||||
|
||||
_data.Browser.Reload();
|
||||
}
|
||||
|
||||
public bool GoBack()
|
||||
{
|
||||
if (_data == null)
|
||||
throw new InvalidOperationException();
|
||||
|
||||
if (!_data.Browser.CanGoBack)
|
||||
return false;
|
||||
|
||||
_data.Browser.GoBack();
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool GoForward()
|
||||
{
|
||||
if (_data == null)
|
||||
throw new InvalidOperationException();
|
||||
|
||||
if (!_data.Browser.CanGoForward)
|
||||
return false;
|
||||
|
||||
_data.Browser.GoForward();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void ExecuteJavaScript(string code)
|
||||
{
|
||||
if (_data == null)
|
||||
throw new InvalidOperationException();
|
||||
|
||||
// TODO: this should not run until the browser is done loading seriously does this even work?
|
||||
_data.Browser.GetMainFrame().ExecuteJavaScript(code, string.Empty, 1);
|
||||
}
|
||||
|
||||
public void AddResourceRequestHandler(Action<IRequestHandlerContext> handler)
|
||||
{
|
||||
_requestHandler.AddResourceRequestHandler(handler);
|
||||
}
|
||||
|
||||
public void RemoveResourceRequestHandler(Action<IRequestHandlerContext> handler)
|
||||
{
|
||||
_requestHandler.RemoveResourceRequestHandler(handler);
|
||||
}
|
||||
|
||||
public void AddBeforeBrowseHandler(Action<IBeforeBrowseContext> handler)
|
||||
{
|
||||
_requestHandler.AddBeforeBrowseHandler(handler);
|
||||
}
|
||||
|
||||
public void RemoveBeforeBrowseHandler(Action<IBeforeBrowseContext> handler)
|
||||
{
|
||||
_requestHandler.RemoveBeforeBrowseHandler(handler);
|
||||
}
|
||||
|
||||
private sealed class LiveData
|
||||
{
|
||||
public OwnedTexture Texture;
|
||||
public readonly RobustCefClient Client;
|
||||
public readonly CefBrowser Browser;
|
||||
public readonly ControlRenderHandler Renderer;
|
||||
|
||||
public LiveData(
|
||||
OwnedTexture texture,
|
||||
RobustCefClient client,
|
||||
CefBrowser browser,
|
||||
ControlRenderHandler renderer)
|
||||
{
|
||||
Texture = texture;
|
||||
Client = client;
|
||||
Browser = browser;
|
||||
Renderer = renderer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class ControlRenderHandler : CefRenderHandler
|
||||
{
|
||||
public ImageBuffer Buffer { get; }
|
||||
private ControlImpl _control;
|
||||
|
||||
internal ControlRenderHandler(ControlImpl control)
|
||||
{
|
||||
Buffer = new ImageBuffer();
|
||||
_control = control;
|
||||
}
|
||||
|
||||
protected override CefAccessibilityHandler? GetAccessibilityHandler() => null;
|
||||
|
||||
protected override void GetViewRect(CefBrowser browser, out CefRectangle rect)
|
||||
{
|
||||
if (_control.Owner.Disposed)
|
||||
{
|
||||
rect = new CefRectangle();
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO CEF: Do we need to pass real screen coords? Cause what we do already works...
|
||||
//var screenCoords = _control.ScreenCoordinates;
|
||||
//rect = new CefRectangle((int) screenCoords.X, (int) screenCoords.Y, (int)Math.Max(_control.Size.X, 1), (int)Math.Max(_control.Size.Y, 1));
|
||||
|
||||
// We do the max between size and 1 because it will LITERALLY CRASH WITHOUT AN ERROR otherwise.
|
||||
rect = new CefRectangle(
|
||||
0, 0,
|
||||
(int)Math.Max(_control.Owner.Size.X, 1), (int)Math.Max(_control.Owner.Size.Y, 1));
|
||||
}
|
||||
|
||||
protected override bool GetScreenInfo(CefBrowser browser, CefScreenInfo screenInfo)
|
||||
{
|
||||
if (_control.Owner.Disposed)
|
||||
return false;
|
||||
|
||||
// TODO CEF: Get actual scale factor?
|
||||
screenInfo.DeviceScaleFactor = 1.0f;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnPopupSize(CefBrowser browser, CefRectangle rect)
|
||||
{
|
||||
if (_control.Owner.Disposed)
|
||||
return;
|
||||
}
|
||||
|
||||
protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects,
|
||||
IntPtr buffer, int width, int height)
|
||||
{
|
||||
if (_control.Owner.Disposed)
|
||||
return;
|
||||
|
||||
foreach (var dirtyRect in dirtyRects)
|
||||
{
|
||||
Buffer.UpdateBuffer(width, height, buffer, dirtyRect);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnAcceleratedPaint(CefBrowser browser, CefPaintElementType type,
|
||||
CefRectangle[] dirtyRects, IntPtr sharedHandle)
|
||||
{
|
||||
// Unused, but we're forced to implement it so.. NOOP.
|
||||
}
|
||||
|
||||
protected override void OnScrollOffsetChanged(CefBrowser browser, double x, double y)
|
||||
{
|
||||
if (_control.Owner.Disposed)
|
||||
return;
|
||||
}
|
||||
|
||||
protected override void OnImeCompositionRangeChanged(CefBrowser browser, CefRange selectedRange,
|
||||
CefRectangle[] characterBounds)
|
||||
{
|
||||
if (_control.Owner.Disposed)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
101
Robust.Client.WebView/Cef/WebViewManagerCef.cs
Normal file
101
Robust.Client.WebView/Cef/WebViewManagerCef.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace Robust.Client.WebView.Cef
|
||||
{
|
||||
internal partial class WebViewManagerCef : IWebViewManagerImpl
|
||||
{
|
||||
private CefApp _app = default!;
|
||||
|
||||
[Dependency] private readonly IDependencyCollection _dependencyCollection = default!;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
IoCManager.Instance!.InjectDependencies(this, oneOff: true);
|
||||
|
||||
string subProcessName;
|
||||
if (OperatingSystem.IsWindows())
|
||||
subProcessName = "Robust.Client.WebView.exe";
|
||||
else if (OperatingSystem.IsLinux())
|
||||
subProcessName = "Robust.Client.WebView";
|
||||
else
|
||||
throw new NotSupportedException("Unsupported platform for CEF!");
|
||||
|
||||
var subProcessPath = PathHelpers.ExecutableRelativeFile(subProcessName);
|
||||
var cefResourcesPath = LocateCefResources();
|
||||
|
||||
// System.Console.WriteLine(AppContext.GetData("NATIVE_DLL_SEARCH_DIRECTORIES"));
|
||||
|
||||
if (cefResourcesPath == null)
|
||||
throw new InvalidOperationException("Unable to locate cef_resources directory!");
|
||||
|
||||
var settings = new CefSettings()
|
||||
{
|
||||
WindowlessRenderingEnabled = true, // So we can render to our UI controls.
|
||||
ExternalMessagePump = false, // Unsure, honestly. TODO CEF: Research this?
|
||||
NoSandbox = true, // Not disabling the sandbox crashes CEF.
|
||||
BrowserSubprocessPath = subProcessPath,
|
||||
LocalesDirPath = Path.Combine(cefResourcesPath, "locales"),
|
||||
ResourcesDirPath = cefResourcesPath,
|
||||
RemoteDebuggingPort = 9222,
|
||||
};
|
||||
|
||||
Logger.Info($"CEF Version: {CefRuntime.ChromeVersion}");
|
||||
|
||||
_app = new RobustCefApp();
|
||||
|
||||
// We pass no main arguments...
|
||||
CefRuntime.Initialize(new CefMainArgs(null), settings, _app, IntPtr.Zero);
|
||||
|
||||
// TODO CEF: After this point, debugging breaks. No, literally. My client crashes but ONLY with the debugger.
|
||||
// I have tried using the DEBUG and RELEASE versions of libcef.so, stripped or non-stripped...
|
||||
// And nothing seemed to work. Odd.
|
||||
}
|
||||
|
||||
private static string? LocateCefResources()
|
||||
{
|
||||
if (ProbeDir(PathHelpers.GetExecutableDirectory(), out var path))
|
||||
return path;
|
||||
|
||||
|
||||
foreach (var searchDir in NativeDllSearchDirectories())
|
||||
{
|
||||
if (ProbeDir(searchDir, out path))
|
||||
return path;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
static bool ProbeDir(string dir, out string path)
|
||||
{
|
||||
path = Path.Combine(dir, "cef_resources");
|
||||
return Directory.Exists(path);
|
||||
}
|
||||
}
|
||||
|
||||
internal static string[] NativeDllSearchDirectories()
|
||||
{
|
||||
var sepChar = OperatingSystem.IsWindows() ? ';' : ':';
|
||||
|
||||
var searchDirectories = ((string)AppContext.GetData("NATIVE_DLL_SEARCH_DIRECTORIES")!)
|
||||
.Split(sepChar, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
return searchDirectories;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
// Calling this makes CEF do its work, without using its own update loop.
|
||||
CefRuntime.DoMessageLoopWork();
|
||||
}
|
||||
|
||||
public void Shutdown()
|
||||
{
|
||||
CefRuntime.Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
127
Robust.Client.WebView/Headless/WebViewManagerHeadless.cs
Normal file
127
Robust.Client.WebView/Headless/WebViewManagerHeadless.cs
Normal file
@@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
|
||||
namespace Robust.Client.WebView.Headless
|
||||
{
|
||||
internal sealed class WebViewManagerHeadless : IWebViewManagerImpl
|
||||
{
|
||||
public IWebViewWindow CreateBrowserWindow(BrowserWindowCreateParameters createParams)
|
||||
{
|
||||
return new WebViewWindowDummy();
|
||||
}
|
||||
|
||||
public IWebViewControlImpl MakeControlImpl(WebViewControl owner)
|
||||
{
|
||||
return new WebViewControlImplDummy();
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
// Nop
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
// Nop
|
||||
}
|
||||
|
||||
public void Shutdown()
|
||||
{
|
||||
// Nop
|
||||
}
|
||||
|
||||
private abstract class DummyBase : IWebViewControl
|
||||
{
|
||||
public string Url { get; set; } = "about:blank";
|
||||
public bool IsLoading => true;
|
||||
|
||||
public void StopLoad()
|
||||
{
|
||||
}
|
||||
|
||||
public void Reload()
|
||||
{
|
||||
}
|
||||
|
||||
public bool GoBack()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool GoForward()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void ExecuteJavaScript(string code)
|
||||
{
|
||||
}
|
||||
|
||||
public void AddResourceRequestHandler(Action<IRequestHandlerContext> handler)
|
||||
{
|
||||
}
|
||||
|
||||
public void RemoveResourceRequestHandler(Action<IRequestHandlerContext> handler)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class WebViewControlImplDummy : DummyBase, IWebViewControlImpl
|
||||
{
|
||||
public void EnteredTree()
|
||||
{
|
||||
}
|
||||
|
||||
public void ExitedTree()
|
||||
{
|
||||
}
|
||||
|
||||
public void MouseMove(GUIMouseMoveEventArgs args)
|
||||
{
|
||||
}
|
||||
|
||||
public void MouseExited()
|
||||
{
|
||||
}
|
||||
|
||||
public void MouseWheel(GUIMouseWheelEventArgs args)
|
||||
{
|
||||
}
|
||||
|
||||
public bool RawKeyEvent(in GuiRawKeyEvent guiRawEvent)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void TextEntered(GUITextEventArgs args)
|
||||
{
|
||||
}
|
||||
|
||||
public void Resized()
|
||||
{
|
||||
}
|
||||
|
||||
public void Draw(DrawingHandleScreen handle)
|
||||
{
|
||||
}
|
||||
|
||||
public void AddBeforeBrowseHandler(Action<IBeforeBrowseContext> handler)
|
||||
{
|
||||
}
|
||||
|
||||
public void RemoveBeforeBrowseHandler(Action<IBeforeBrowseContext> handler)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class WebViewWindowDummy : DummyBase, IWebViewWindow
|
||||
{
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
public bool Closed => false;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Robust.Client.WebView/IBeforeBrowseContext.cs
Normal file
12
Robust.Client.WebView/IBeforeBrowseContext.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace Robust.Client.WebView
|
||||
{
|
||||
public interface IBeforeBrowseContext
|
||||
{
|
||||
string Url { get; }
|
||||
string Method { get; }
|
||||
bool IsRedirect { get; }
|
||||
bool UserGesture { get; }
|
||||
bool IsCancelled { get; }
|
||||
void DoCancel();
|
||||
}
|
||||
}
|
||||
18
Robust.Client.WebView/IRequestHandlerContext.cs
Normal file
18
Robust.Client.WebView/IRequestHandlerContext.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
|
||||
namespace Robust.Client.WebView
|
||||
{
|
||||
public interface IRequestHandlerContext
|
||||
{
|
||||
bool IsNavigation { get; }
|
||||
bool IsDownload { get; }
|
||||
string RequestInitiator { get; }
|
||||
string Url { get; }
|
||||
string Method { get; }
|
||||
bool IsHandled { get; }
|
||||
bool IsCancelled { get; }
|
||||
void DoCancel();
|
||||
void DoRespondStream(Stream stream, string contentType, HttpStatusCode code = HttpStatusCode.OK);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
using System;
|
||||
using Robust.Client.WebView.Cef;
|
||||
|
||||
namespace Robust.Client.CEF
|
||||
namespace Robust.Client.WebView
|
||||
{
|
||||
public interface IBrowserControl
|
||||
public interface IWebViewControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Current URL of the browser. Set to load a new page.
|
||||
@@ -42,7 +43,7 @@ namespace Robust.Client.CEF
|
||||
/// <param name="code">JavaScript code.</param>
|
||||
void ExecuteJavaScript(string code);
|
||||
|
||||
void AddResourceRequestHandler(Action<RequestHandlerContext> handler);
|
||||
void RemoveResourceRequestHandler(Action<RequestHandlerContext> handler);
|
||||
void AddResourceRequestHandler(Action<IRequestHandlerContext> handler);
|
||||
void RemoveResourceRequestHandler(Action<IRequestHandlerContext> handler);
|
||||
}
|
||||
}
|
||||
24
Robust.Client.WebView/IWebViewControlImpl.cs
Normal file
24
Robust.Client.WebView/IWebViewControlImpl.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
|
||||
namespace Robust.Client.WebView
|
||||
{
|
||||
/// <summary>
|
||||
/// Internal swappable implementation of <see cref="WebViewControl"/>.
|
||||
/// </summary>
|
||||
internal interface IWebViewControlImpl : IWebViewControl
|
||||
{
|
||||
void EnteredTree();
|
||||
void ExitedTree();
|
||||
void MouseMove(GUIMouseMoveEventArgs args);
|
||||
void MouseExited();
|
||||
void MouseWheel(GUIMouseWheelEventArgs args);
|
||||
bool RawKeyEvent(in GuiRawKeyEvent guiRawEvent);
|
||||
void TextEntered(GUITextEventArgs args);
|
||||
void Resized();
|
||||
void Draw(DrawingHandleScreen handle);
|
||||
void AddBeforeBrowseHandler(Action<IBeforeBrowseContext> handler);
|
||||
void RemoveBeforeBrowseHandler(Action<IBeforeBrowseContext> handler);
|
||||
}
|
||||
}
|
||||
7
Robust.Client.WebView/IWebViewManager.cs
Normal file
7
Robust.Client.WebView/IWebViewManager.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Robust.Client.WebView
|
||||
{
|
||||
public interface IWebViewManager
|
||||
{
|
||||
IWebViewWindow CreateBrowserWindow(BrowserWindowCreateParameters createParams);
|
||||
}
|
||||
}
|
||||
14
Robust.Client.WebView/IWebViewManagerImpl.cs
Normal file
14
Robust.Client.WebView/IWebViewManagerImpl.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Robust.Client.WebViewHook;
|
||||
|
||||
namespace Robust.Client.WebView
|
||||
{
|
||||
/// <summary>
|
||||
/// Internal implementation of WebViewManager that is switched out by <see cref="IWebViewManagerHook"/>.
|
||||
/// </summary>
|
||||
internal interface IWebViewManagerImpl : IWebViewManagerInternal
|
||||
{
|
||||
void Initialize();
|
||||
void Update();
|
||||
void Shutdown();
|
||||
}
|
||||
}
|
||||
7
Robust.Client.WebView/IWebViewManagerInternal.cs
Normal file
7
Robust.Client.WebView/IWebViewManagerInternal.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Robust.Client.WebView
|
||||
{
|
||||
internal interface IWebViewManagerInternal : IWebViewManager
|
||||
{
|
||||
IWebViewControlImpl MakeControlImpl(WebViewControl owner);
|
||||
}
|
||||
}
|
||||
9
Robust.Client.WebView/IWebViewWindow.cs
Normal file
9
Robust.Client.WebView/IWebViewWindow.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace Robust.Client.WebView
|
||||
{
|
||||
public interface IWebViewWindow : IWebViewControl, IDisposable
|
||||
{
|
||||
bool Closed { get; }
|
||||
}
|
||||
}
|
||||
26
Robust.Client.WebView/Robust.Client.WebView.csproj
Normal file
26
Robust.Client.WebView/Robust.Client.WebView.csproj
Normal file
@@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="..\MSBuild\Robust.Properties.targets" />
|
||||
<Import Project="..\MSBuild\Robust.Engine.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<OutputType>WinExe</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="..\MSBuild\Robust.DefineConstants.targets" />
|
||||
<Target Name="RobustAfterBuild" AfterTargets="Build" />
|
||||
<Import Project="..\MSBuild\Robust.Engine.targets" />
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2020.3.0" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
|
||||
<PackageReference Include="Robust.Natives.Cef" Version="95.7.14" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\cefglue\CefGlue\CefGlue.csproj" />
|
||||
<ProjectReference Include="..\Robust.Client\Robust.Client.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
145
Robust.Client.WebView/WebViewControl.cs
Normal file
145
Robust.Client.WebView/WebViewControl.cs
Normal file
@@ -0,0 +1,145 @@
|
||||
using System;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.WebView.Cef;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Robust.Client.WebView
|
||||
{
|
||||
/// <summary>
|
||||
/// An UI control that presents web content.
|
||||
/// </summary>
|
||||
public sealed class WebViewControl : Control, IWebViewControl, IRawInputControl
|
||||
{
|
||||
[Dependency] private readonly IWebViewManagerInternal _webViewManager = default!;
|
||||
|
||||
private readonly IWebViewControlImpl _controlImpl;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public string Url
|
||||
{
|
||||
get => _controlImpl.Url;
|
||||
set => _controlImpl.Url = value;
|
||||
}
|
||||
|
||||
[ViewVariables] public bool IsLoading => _controlImpl.IsLoading;
|
||||
|
||||
public WebViewControl()
|
||||
{
|
||||
CanKeyboardFocus = true;
|
||||
KeyboardFocusOnClick = true;
|
||||
MouseFilter = MouseFilterMode.Stop;
|
||||
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
_controlImpl = _webViewManager.MakeControlImpl(this);
|
||||
}
|
||||
|
||||
protected override void EnteredTree()
|
||||
{
|
||||
base.EnteredTree();
|
||||
|
||||
_controlImpl.EnteredTree();
|
||||
}
|
||||
|
||||
protected override void ExitedTree()
|
||||
{
|
||||
base.ExitedTree();
|
||||
|
||||
_controlImpl.ExitedTree();
|
||||
}
|
||||
|
||||
protected internal override void MouseMove(GUIMouseMoveEventArgs args)
|
||||
{
|
||||
base.MouseMove(args);
|
||||
|
||||
_controlImpl.MouseMove(args);
|
||||
}
|
||||
|
||||
protected internal override void MouseExited()
|
||||
{
|
||||
base.MouseExited();
|
||||
|
||||
_controlImpl.MouseExited();
|
||||
}
|
||||
|
||||
protected internal override void MouseWheel(GUIMouseWheelEventArgs args)
|
||||
{
|
||||
base.MouseWheel(args);
|
||||
|
||||
_controlImpl.MouseWheel(args);
|
||||
}
|
||||
|
||||
bool IRawInputControl.RawKeyEvent(in GuiRawKeyEvent guiRawEvent)
|
||||
{
|
||||
return _controlImpl.RawKeyEvent(guiRawEvent);
|
||||
}
|
||||
|
||||
protected internal override void TextEntered(GUITextEventArgs args)
|
||||
{
|
||||
base.TextEntered(args);
|
||||
|
||||
_controlImpl.TextEntered(args);
|
||||
}
|
||||
|
||||
protected override void Resized()
|
||||
{
|
||||
base.Resized();
|
||||
|
||||
_controlImpl.Resized();
|
||||
}
|
||||
|
||||
protected internal override void Draw(DrawingHandleScreen handle)
|
||||
{
|
||||
base.Draw(handle);
|
||||
|
||||
_controlImpl.Draw(handle);
|
||||
}
|
||||
|
||||
public void StopLoad()
|
||||
{
|
||||
_controlImpl.StopLoad();
|
||||
}
|
||||
|
||||
public void Reload()
|
||||
{
|
||||
_controlImpl.Reload();
|
||||
}
|
||||
|
||||
public bool GoBack()
|
||||
{
|
||||
return _controlImpl.GoBack();
|
||||
}
|
||||
|
||||
public bool GoForward()
|
||||
{
|
||||
return _controlImpl.GoForward();
|
||||
}
|
||||
|
||||
public void ExecuteJavaScript(string code)
|
||||
{
|
||||
_controlImpl.ExecuteJavaScript(code);
|
||||
}
|
||||
|
||||
public void AddResourceRequestHandler(Action<IRequestHandlerContext> handler)
|
||||
{
|
||||
_controlImpl.AddResourceRequestHandler(handler);
|
||||
}
|
||||
|
||||
public void RemoveResourceRequestHandler(Action<IRequestHandlerContext> handler)
|
||||
{
|
||||
_controlImpl.RemoveResourceRequestHandler(handler);
|
||||
}
|
||||
|
||||
public void AddBeforeBrowseHandler(Action<IBeforeBrowseContext> handler)
|
||||
{
|
||||
_controlImpl.AddBeforeBrowseHandler(handler);
|
||||
}
|
||||
|
||||
public void RemoveBeforeBrowseHandler(Action<IBeforeBrowseContext> handler)
|
||||
{
|
||||
_controlImpl.RemoveBeforeBrowseHandler(handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
59
Robust.Client.WebView/WebViewManager.cs
Normal file
59
Robust.Client.WebView/WebViewManager.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using Robust.Client.WebView;
|
||||
using Robust.Client.WebView.Cef;
|
||||
using Robust.Client.WebView.Headless;
|
||||
using Robust.Client.WebViewHook;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
[assembly: WebViewManagerImpl(typeof(WebViewManager))]
|
||||
|
||||
namespace Robust.Client.WebView
|
||||
{
|
||||
internal sealed class WebViewManager : IWebViewManagerInternal, IWebViewManagerHook
|
||||
{
|
||||
private IWebViewManagerImpl? _impl;
|
||||
|
||||
public void Initialize(GameController.DisplayMode mode)
|
||||
{
|
||||
DebugTools.Assert(_impl == null, "WebViewManager has already been initialized!");
|
||||
|
||||
IoCManager.RegisterInstance<IWebViewManager>(this);
|
||||
IoCManager.RegisterInstance<IWebViewManagerInternal>(this);
|
||||
|
||||
if (mode == GameController.DisplayMode.Headless)
|
||||
_impl = new WebViewManagerHeadless();
|
||||
else
|
||||
_impl = new WebViewManagerCef();
|
||||
|
||||
_impl.Initialize();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
DebugTools.Assert(_impl != null, "WebViewManager has not yet been initialized!");
|
||||
|
||||
_impl!.Update();
|
||||
}
|
||||
|
||||
public void Shutdown()
|
||||
{
|
||||
DebugTools.Assert(_impl != null, "WebViewManager has not yet been initialized!");
|
||||
|
||||
_impl!.Shutdown();
|
||||
}
|
||||
|
||||
public IWebViewWindow CreateBrowserWindow(BrowserWindowCreateParameters createParams)
|
||||
{
|
||||
DebugTools.Assert(_impl != null, "WebViewManager has not yet been initialized!");
|
||||
|
||||
return _impl!.CreateBrowserWindow(createParams);
|
||||
}
|
||||
|
||||
public IWebViewControlImpl MakeControlImpl(WebViewControl owner)
|
||||
{
|
||||
DebugTools.Assert(_impl != null, "WebViewManager has not yet been initialized!");
|
||||
|
||||
return _impl!.MakeControlImpl(owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,7 @@ namespace Robust.Client.Audio.Midi
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IConfigurationManager _cfgMan = default!;
|
||||
|
||||
private SharedBroadphaseSystem _broadPhaseSystem = default!;
|
||||
private SharedPhysicsSystem _broadPhaseSystem = default!;
|
||||
|
||||
[ViewVariables]
|
||||
public bool IsAvailable
|
||||
@@ -88,6 +88,7 @@ namespace Robust.Client.Audio.Midi
|
||||
private float _volume = 0f;
|
||||
private bool _volumeDirty = true;
|
||||
|
||||
// Not reliable until Fluidsynth is initialized!
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float Volume
|
||||
{
|
||||
@@ -134,6 +135,7 @@ namespace Robust.Client.Audio.Midi
|
||||
{
|
||||
if (FluidsynthInitialized || _failedInitialize) return;
|
||||
|
||||
_volume = _cfgMan.GetCVar(CVars.MidiVolume);
|
||||
_cfgMan.OnValueChanged(CVars.MidiVolume, value =>
|
||||
{
|
||||
_volume = value;
|
||||
@@ -175,7 +177,7 @@ namespace Robust.Client.Audio.Midi
|
||||
_midiThread = new Thread(ThreadUpdate);
|
||||
_midiThread.Start();
|
||||
|
||||
_broadPhaseSystem = EntitySystem.Get<SharedBroadphaseSystem>();
|
||||
_broadPhaseSystem = EntitySystem.Get<SharedPhysicsSystem>();
|
||||
FluidsynthInitialized = true;
|
||||
}
|
||||
|
||||
@@ -254,11 +256,12 @@ namespace Robust.Client.Audio.Midi
|
||||
renderer.LoadSoundfont(WindowsSoundfont, true);
|
||||
}
|
||||
|
||||
renderer.Source.SetVolume(Volume);
|
||||
|
||||
lock (_renderers)
|
||||
{
|
||||
_renderers.Add(renderer);
|
||||
}
|
||||
|
||||
return renderer;
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -37,6 +37,11 @@ namespace Robust.Client.Audio.Midi
|
||||
/// </summary>
|
||||
bool LoopMidi { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// This increases all note on velocities to 127.
|
||||
/// </summary>
|
||||
bool VolumeBoost { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The midi program (instrument) the renderer is using.
|
||||
/// </summary>
|
||||
@@ -297,6 +302,9 @@ namespace Robust.Client.Audio.Midi
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool VolumeBoost { get; set; }
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public IEntity? TrackingEntity { get; set; } = null;
|
||||
|
||||
@@ -539,6 +547,8 @@ namespace Robust.Client.Audio.Midi
|
||||
|
||||
// Note On 0x90
|
||||
case 144:
|
||||
if (VolumeBoost)
|
||||
midiEvent.Velocity = 127;
|
||||
_synth.NoteOn(midiEvent.Channel, midiEvent.Key, midiEvent.Velocity);
|
||||
break;
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ namespace Robust.Client
|
||||
[Dependency] private readonly IDiscordRichPresence _discord = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IClientGameStateManager _gameStates = default!;
|
||||
[Dependency] private readonly IDebugDrawingManager _debugDrawMan = default!;
|
||||
|
||||
/// <inheritdoc />
|
||||
public ushort DefaultPort { get; } = 1212;
|
||||
@@ -57,7 +56,6 @@ namespace Robust.Client
|
||||
_configManager.OnValueChanged(CVars.NetTickrate, TickRateChanged, invokeImmediately: true);
|
||||
|
||||
_playMan.Initialize();
|
||||
_debugDrawMan.Initialize();
|
||||
Reset();
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,6 @@ namespace Robust.Client
|
||||
IoCManager.Register<IUserInterfaceManager, UserInterfaceManager>();
|
||||
IoCManager.Register<IUserInterfaceManagerInternal, UserInterfaceManager>();
|
||||
IoCManager.Register<IDebugDrawing, DebugDrawing>();
|
||||
IoCManager.Register<IDebugDrawingManager, DebugDrawingManager>();
|
||||
IoCManager.Register<ILightManager, LightManager>();
|
||||
IoCManager.Register<IDiscordRichPresence, DiscordRichPresence>();
|
||||
IoCManager.Register<IMidiManager, MidiManager>();
|
||||
|
||||
@@ -188,16 +188,16 @@ namespace Robust.Client.Console.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
if (!int.TryParse(args[0], out var id))
|
||||
if (!float.TryParse(args[0], out var duration))
|
||||
{
|
||||
shell.WriteError($"{args[0]} is not a valid integer.");
|
||||
shell.WriteError($"{args[0]} is not a valid float.");
|
||||
return;
|
||||
}
|
||||
|
||||
var mgr = IoCManager.Resolve<IDebugDrawingManager>();
|
||||
var mgr = EntitySystem.Get<DebugRayDrawingSystem>();
|
||||
mgr.DebugDrawRays = !mgr.DebugDrawRays;
|
||||
shell.WriteError("Toggled showing rays to:" + mgr.DebugDrawRays.ToString());
|
||||
mgr.DebugRayLifetime = TimeSpan.FromSeconds((double)int.Parse(args[0], CultureInfo.InvariantCulture));
|
||||
shell.WriteError("Toggled showing rays to:" + mgr.DebugDrawRays);
|
||||
mgr.DebugRayLifetime = TimeSpan.FromSeconds(duration);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace Robust.Client.Console.Commands
|
||||
|
||||
var conGroup = IoCManager.Resolve<IClientConGroupController>();
|
||||
foreach (var command in shell.ConsoleHost.RegisteredCommands.Values
|
||||
.Where(p => p.Command.Contains(filter) && conGroup.CanCommand(p.Command))
|
||||
.Where(p => p.Command.Contains(filter) && (p is not ServerDummyCommand || conGroup.CanCommand(p.Command)))
|
||||
.OrderBy(c => c.Command))
|
||||
{
|
||||
shell.WriteLine(command.Command + ": " + command.Description);
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Robust.Client.Console.Commands
|
||||
{
|
||||
public string Command => "physics";
|
||||
public string Description => $"Shows a debug physics overlay. The arg supplied specifies the overlay.";
|
||||
public string Help => $"{Command} <contactnormals / contactpoints / joints / shapeinfo / shapes>";
|
||||
public string Help => $"{Command} <aabbs / contactnormals / contactpoints / joints / shapeinfo / shapes>";
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length != 1)
|
||||
@@ -21,6 +21,9 @@ namespace Robust.Client.Console.Commands
|
||||
|
||||
switch (args[0])
|
||||
{
|
||||
case "aabbs":
|
||||
system.Flags ^= PhysicsDebugFlags.AABBs;
|
||||
break;
|
||||
case "contactnormals":
|
||||
system.Flags ^= PhysicsDebugFlags.ContactNormals;
|
||||
break;
|
||||
|
||||
127
Robust.Client/Console/Completions.cs
Normal file
127
Robust.Client/Console/Completions.cs
Normal file
@@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Network.Messages;
|
||||
using Robust.Shared.Utility;
|
||||
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
||||
using static Robust.Shared.Network.Messages.MsgScriptCompletionResponse;
|
||||
|
||||
namespace Robust.Client.Console
|
||||
{
|
||||
public class Completions : SS14Window
|
||||
{
|
||||
private HistoryLineEdit _textBar;
|
||||
private ScrollContainer _suggestPanel = new()
|
||||
{
|
||||
HScrollEnabled = false,
|
||||
};
|
||||
|
||||
private BoxContainer _suggestBox = new()
|
||||
{
|
||||
Orientation = LayoutOrientation.Vertical,
|
||||
HorizontalAlignment = HAlignment.Left,
|
||||
};
|
||||
|
||||
public Completions(HistoryLineEdit textBar) : base()
|
||||
{
|
||||
Title = "Suggestions";
|
||||
MouseFilter = MouseFilterMode.Pass;
|
||||
|
||||
_textBar = textBar;
|
||||
_suggestPanel.AddChild(_suggestBox);
|
||||
ContentsContainer.AddChild(_suggestPanel);
|
||||
}
|
||||
|
||||
private bool _firstopen = true;
|
||||
public void OpenAt(Vector2 position, Vector2 size)
|
||||
{
|
||||
if (_firstopen)
|
||||
{
|
||||
SetSize = size;
|
||||
LayoutContainer.SetPosition(this, position);
|
||||
_firstopen = false;
|
||||
}
|
||||
Open();
|
||||
}
|
||||
|
||||
private ImmutableArray<LiteResult> _results;
|
||||
|
||||
public void Update()
|
||||
{
|
||||
_suggestBox.RemoveAllChildren();
|
||||
foreach (var res in _results)
|
||||
{
|
||||
var label = new Entry(res);
|
||||
|
||||
label.OnKeyBindDown += ev =>
|
||||
{
|
||||
if (ev.Function == EngineKeyFunctions.UIClick)
|
||||
_textBar.InsertAtCursor(label.Result.Properties["InsertionText"]);
|
||||
};
|
||||
|
||||
_suggestBox.AddChild(label);
|
||||
}
|
||||
}
|
||||
|
||||
public void TextChanged() => Close();
|
||||
|
||||
public void SetSuggestions(MsgScriptCompletionResponse response)
|
||||
{
|
||||
_results = response.Results;
|
||||
Update();
|
||||
}
|
||||
|
||||
// Label and ghetto button.
|
||||
public class Entry : RichTextLabel
|
||||
{
|
||||
public readonly LiteResult Result;
|
||||
|
||||
public Entry(LiteResult result)
|
||||
{
|
||||
MouseFilter = MouseFilterMode.Stop;
|
||||
Result = result;
|
||||
var compl = new FormattedMessage();
|
||||
var dim = Color.FromHsl((0f, 0f, 0.8f, 1f));
|
||||
|
||||
// warning: ew ahead
|
||||
string basen = "default";
|
||||
if (Result.Tags.Contains("Interface"))
|
||||
basen = "interface name";
|
||||
else if (Result.Tags.Contains("Class"))
|
||||
basen = "class name";
|
||||
else if (Result.Tags.Contains("Struct"))
|
||||
basen = "struct name";
|
||||
else if (Result.Tags.Contains("Keyword"))
|
||||
basen = "keyword";
|
||||
else if (Result.Tags.Contains("Namespace"))
|
||||
basen = "namespace name";
|
||||
else if (Result.Tags.Contains("Method"))
|
||||
basen = "method name";
|
||||
else if (Result.Tags.Contains("Property"))
|
||||
basen = "property name";
|
||||
else if (Result.Tags.Contains("Field"))
|
||||
basen = "field name";
|
||||
|
||||
Color basec = ScriptingColorScheme.ColorScheme[basen];
|
||||
compl.PushColor(basec * dim);
|
||||
compl.AddText(Result.DisplayTextPrefix);
|
||||
compl.PushColor(basec);
|
||||
compl.AddText(Result.DisplayText);
|
||||
compl.PushColor(basec * dim);
|
||||
compl.AddText(Result.DisplayTextSuffix);
|
||||
compl.AddText(" [" + String.Join(", ", Result.Tags) + "]");
|
||||
if (Result.InlineDescription.Length != 0)
|
||||
{
|
||||
compl.PushNewline();
|
||||
compl.AddText(": ");
|
||||
compl.PushColor(Color.LightSlateGray);
|
||||
compl.AddText(Result.InlineDescription);
|
||||
}
|
||||
SetMessage(compl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,16 @@ namespace Robust.Client.Console
|
||||
|
||||
}
|
||||
|
||||
protected override void Complete()
|
||||
{
|
||||
var msg = _client._netManager.CreateNetMessage<MsgScriptCompletion>();
|
||||
msg.ScriptSession = _session;
|
||||
msg.Code = InputBar.Text;
|
||||
msg.Cursor = InputBar.CursorPosition;
|
||||
|
||||
_client._netManager.ClientSendMessage(msg);
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
base.Close();
|
||||
@@ -95,6 +105,12 @@ namespace Robust.Client.Console
|
||||
|
||||
OutputPanel.AddText(">");
|
||||
}
|
||||
|
||||
public void ReceiveCompletionResponse(MsgScriptCompletionResponse response)
|
||||
{
|
||||
Suggestions.SetSuggestions(response);
|
||||
Suggestions.OpenAt((Position.X + Size.X, Position.Y), (Size.X / 2, Size.Y));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ namespace Robust.Client.Console
|
||||
_netManager.RegisterNetMessage<MsgScriptStop>();
|
||||
_netManager.RegisterNetMessage<MsgScriptEval>();
|
||||
_netManager.RegisterNetMessage<MsgScriptStart>();
|
||||
_netManager.RegisterNetMessage<MsgScriptCompletion>();
|
||||
_netManager.RegisterNetMessage<MsgScriptCompletionResponse>(ReceiveScriptCompletionResponse);
|
||||
_netManager.RegisterNetMessage<MsgScriptResponse>(ReceiveScriptResponse);
|
||||
_netManager.RegisterNetMessage<MsgScriptStartAck>(ReceiveScriptStartAckResponse);
|
||||
}
|
||||
@@ -44,6 +46,16 @@ namespace Robust.Client.Console
|
||||
console.ReceiveResponse(message);
|
||||
}
|
||||
|
||||
private void ReceiveScriptCompletionResponse(MsgScriptCompletionResponse message)
|
||||
{
|
||||
if (!_activeConsoles.TryGetValue(message.ScriptSession, out var console))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
console.ReceiveCompletionResponse(message);
|
||||
}
|
||||
|
||||
public bool CanScript => _conGroupController.CanScript();
|
||||
|
||||
public void StartSession()
|
||||
|
||||
@@ -53,6 +53,9 @@ namespace Robust.Client.Console
|
||||
OutputPanel.AddText(">");
|
||||
}
|
||||
|
||||
// No-op for now.
|
||||
protected override void Complete() { }
|
||||
|
||||
protected override async void Run()
|
||||
{
|
||||
var code = InputBar.Text;
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace Robust.Client.Debugging
|
||||
IoCManager.Resolve<IInputManager>(),
|
||||
IoCManager.Resolve<IResourceCache>(),
|
||||
this,
|
||||
Get<SharedBroadphaseSystem>()));
|
||||
Get<SharedPhysicsSystem>()));
|
||||
|
||||
if (value == PhysicsDebugFlags.None)
|
||||
IoCManager.Resolve<IOverlayManager>().RemoveOverlay(typeof(PhysicsDebugOverlay));
|
||||
@@ -161,6 +161,7 @@ namespace Robust.Client.Debugging
|
||||
Shapes = 1 << 2,
|
||||
ShapeInfo = 1 << 3,
|
||||
Joints = 1 << 4,
|
||||
AABBs = 1 << 5,
|
||||
}
|
||||
|
||||
internal sealed class PhysicsDebugOverlay : Overlay
|
||||
@@ -168,8 +169,8 @@ namespace Robust.Client.Debugging
|
||||
private IEntityManager _entityManager = default!;
|
||||
private IEyeManager _eyeManager = default!;
|
||||
private IInputManager _inputManager = default!;
|
||||
private DebugPhysicsSystem _physics = default!;
|
||||
private SharedBroadphaseSystem _broadphaseSystem = default!;
|
||||
private DebugPhysicsSystem _debugPhysicsSystem = default!;
|
||||
private SharedPhysicsSystem _physicsSystem = default!;
|
||||
|
||||
public override OverlaySpace Space => OverlaySpace.WorldSpace | OverlaySpace.ScreenSpace;
|
||||
|
||||
@@ -179,13 +180,13 @@ namespace Robust.Client.Debugging
|
||||
|
||||
private HashSet<Joint> _drawnJoints = new();
|
||||
|
||||
public PhysicsDebugOverlay(IEntityManager entityManager, IEyeManager eyeManager, IInputManager inputManager, IResourceCache cache, DebugPhysicsSystem system, SharedBroadphaseSystem broadphaseSystem)
|
||||
public PhysicsDebugOverlay(IEntityManager entityManager, IEyeManager eyeManager, IInputManager inputManager, IResourceCache cache, DebugPhysicsSystem system, SharedPhysicsSystem physicsSystem)
|
||||
{
|
||||
_entityManager = entityManager;
|
||||
_eyeManager = eyeManager;
|
||||
_inputManager = inputManager;
|
||||
_physics = system;
|
||||
_broadphaseSystem = broadphaseSystem;
|
||||
_debugPhysicsSystem = system;
|
||||
_physicsSystem = physicsSystem;
|
||||
_font = new VectorFont(cache.GetResource<FontResource>("/Fonts/NotoSans/NotoSans-Regular.ttf"), 10);
|
||||
}
|
||||
|
||||
@@ -195,9 +196,9 @@ namespace Robust.Client.Debugging
|
||||
var viewBounds = _eyeManager.GetWorldViewbounds();
|
||||
var mapId = _eyeManager.CurrentMap;
|
||||
|
||||
if ((_physics.Flags & PhysicsDebugFlags.Shapes) != 0 && !viewport.IsEmpty())
|
||||
if ((_debugPhysicsSystem.Flags & PhysicsDebugFlags.Shapes) != 0 && !viewport.IsEmpty())
|
||||
{
|
||||
foreach (var physBody in _broadphaseSystem.GetCollidingEntities(mapId, viewBounds))
|
||||
foreach (var physBody in _physicsSystem.GetCollidingEntities(mapId, viewBounds))
|
||||
{
|
||||
if (physBody.Owner.HasComponent<MapGridComponent>()) continue;
|
||||
|
||||
@@ -236,7 +237,33 @@ namespace Robust.Client.Debugging
|
||||
}
|
||||
}
|
||||
|
||||
if ((_physics.Flags & PhysicsDebugFlags.Joints) != 0x0)
|
||||
if ((_debugPhysicsSystem.Flags & PhysicsDebugFlags.AABBs) != 0 && !viewport.IsEmpty())
|
||||
{
|
||||
foreach (var physBody in _physicsSystem.GetCollidingEntities(mapId, viewBounds))
|
||||
{
|
||||
if (physBody.Owner.HasComponent<MapGridComponent>()) continue;
|
||||
|
||||
var xform = physBody.GetTransform();
|
||||
|
||||
const float AlphaModifier = 0.2f;
|
||||
Box2? aabb = null;
|
||||
|
||||
foreach (var fixture in physBody.Fixtures)
|
||||
{
|
||||
for (var i = 0; i < fixture.Shape.ChildCount; i++)
|
||||
{
|
||||
var shapeBB = fixture.Shape.ComputeAABB(xform, i);
|
||||
aabb = aabb?.Union(shapeBB) ?? shapeBB;
|
||||
}
|
||||
}
|
||||
|
||||
if (aabb == null) continue;
|
||||
|
||||
worldHandle.DrawRect(aabb.Value, Color.Red.WithAlpha(AlphaModifier), false);
|
||||
}
|
||||
}
|
||||
|
||||
if ((_debugPhysicsSystem.Flags & PhysicsDebugFlags.Joints) != 0x0)
|
||||
{
|
||||
_drawnJoints.Clear();
|
||||
|
||||
@@ -255,17 +282,17 @@ namespace Robust.Client.Debugging
|
||||
}
|
||||
}
|
||||
|
||||
if ((_physics.Flags & (PhysicsDebugFlags.ContactPoints | PhysicsDebugFlags.ContactNormals)) != 0)
|
||||
if ((_debugPhysicsSystem.Flags & (PhysicsDebugFlags.ContactPoints | PhysicsDebugFlags.ContactNormals)) != 0)
|
||||
{
|
||||
const float axisScale = 0.3f;
|
||||
|
||||
for (var i = 0; i < _physics.PointCount; ++i)
|
||||
for (var i = 0; i < _debugPhysicsSystem.PointCount; ++i)
|
||||
{
|
||||
var point = _physics.Points[i];
|
||||
var point = _debugPhysicsSystem.Points[i];
|
||||
|
||||
const float radius = 0.1f;
|
||||
|
||||
if ((_physics.Flags & PhysicsDebugFlags.ContactPoints) != 0)
|
||||
if ((_debugPhysicsSystem.Flags & PhysicsDebugFlags.ContactPoints) != 0)
|
||||
{
|
||||
if (point.State == PointState.Add)
|
||||
worldHandle.DrawCircle(point.Position, radius, new Color(255, 77, 243, 255));
|
||||
@@ -273,7 +300,7 @@ namespace Robust.Client.Debugging
|
||||
worldHandle.DrawCircle(point.Position, radius, new Color(255, 77, 77, 255));
|
||||
}
|
||||
|
||||
if ((_physics.Flags & PhysicsDebugFlags.ContactNormals) != 0)
|
||||
if ((_debugPhysicsSystem.Flags & PhysicsDebugFlags.ContactNormals) != 0)
|
||||
{
|
||||
Vector2 p1 = point.Position;
|
||||
Vector2 p2 = p1 + point.Normal * axisScale;
|
||||
@@ -281,7 +308,7 @@ namespace Robust.Client.Debugging
|
||||
}
|
||||
}
|
||||
|
||||
_physics.PointCount = 0;
|
||||
_debugPhysicsSystem.PointCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,12 +317,12 @@ namespace Robust.Client.Debugging
|
||||
var mapId = _eyeManager.CurrentMap;
|
||||
var mousePos = _inputManager.MouseScreenPosition;
|
||||
|
||||
if ((_physics.Flags & PhysicsDebugFlags.ShapeInfo) != 0x0)
|
||||
if ((_debugPhysicsSystem.Flags & PhysicsDebugFlags.ShapeInfo) != 0x0)
|
||||
{
|
||||
var hoverBodies = new List<PhysicsComponent>();
|
||||
var bounds = Box2.UnitCentered.Translated(_eyeManager.ScreenToMap(mousePos.Position).Position);
|
||||
|
||||
foreach (var physBody in _broadphaseSystem.GetCollidingEntities(mapId, bounds))
|
||||
foreach (var physBody in _physicsSystem.GetCollidingEntities(mapId, bounds))
|
||||
{
|
||||
if (physBody.Owner.HasComponent<MapGridComponent>()) continue;
|
||||
hoverBodies.Add(physBody);
|
||||
@@ -327,7 +354,7 @@ namespace Robust.Client.Debugging
|
||||
|
||||
protected internal override void Draw(in OverlayDrawArgs args)
|
||||
{
|
||||
if (_physics.Flags == PhysicsDebugFlags.None) return;
|
||||
if (_debugPhysicsSystem.Flags == PhysicsDebugFlags.None) return;
|
||||
|
||||
switch (args.Space)
|
||||
{
|
||||
|
||||
@@ -2,21 +2,22 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Network.Messages;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Robust.Client.Debugging
|
||||
{
|
||||
internal class DebugDrawingManager : IDebugDrawingManager
|
||||
internal sealed class DebugRayDrawingSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IClientNetManager _net = default!;
|
||||
[Dependency] private readonly IOverlayManager _overlayManager = default!;
|
||||
[Dependency] private readonly IGameTiming _gameTimer = default!;
|
||||
|
||||
private readonly List<RayWithLifetime> raysWithLifeTime = new();
|
||||
private readonly List<RayWithLifetime> _raysWithLifeTime = new();
|
||||
private bool _debugDrawRays;
|
||||
|
||||
private struct RayWithLifetime
|
||||
@@ -52,9 +53,30 @@ namespace Robust.Client.Debugging
|
||||
|
||||
public TimeSpan DebugRayLifetime { get; set; } = TimeSpan.FromSeconds(5);
|
||||
|
||||
public void Initialize()
|
||||
public override void Initialize()
|
||||
{
|
||||
_net.RegisterNetMessage<MsgRay>(HandleDrawRay);
|
||||
base.Initialize();
|
||||
SubscribeNetworkEvent<MsgRay>(HandleDrawRay);
|
||||
// To catch anything that's client-only and not sent by the server.
|
||||
SubscribeLocalEvent<DebugDrawRayMessage>(OnDebugDrawRay);
|
||||
}
|
||||
|
||||
private void OnDebugDrawRay(DebugDrawRayMessage ev)
|
||||
{
|
||||
if (!_debugDrawRays)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var newRayWithLifetime = new RayWithLifetime
|
||||
{
|
||||
DidActuallyHit = ev.Data.Results != null,
|
||||
RayOrigin = ev.Data.Ray.Position,
|
||||
RayHit = ev.Data.Results?.HitPos ?? ev.Data.Ray.Direction * ev.Data.MaxLength + ev.Data.Ray.Position,
|
||||
LifeTime = _gameTimer.RealTime + DebugRayLifetime
|
||||
};
|
||||
|
||||
_raysWithLifeTime.Add(newRayWithLifetime);
|
||||
}
|
||||
|
||||
private void HandleDrawRay(MsgRay msg)
|
||||
@@ -74,15 +96,15 @@ namespace Robust.Client.Debugging
|
||||
LifeTime = _gameTimer.RealTime + DebugRayLifetime
|
||||
};
|
||||
|
||||
raysWithLifeTime.Add(newRayWithLifetime);
|
||||
_raysWithLifeTime.Add(newRayWithLifetime);
|
||||
}
|
||||
|
||||
private sealed class DebugDrawRayOverlay : Overlay
|
||||
{
|
||||
private readonly DebugDrawingManager _owner;
|
||||
private readonly DebugRayDrawingSystem _owner;
|
||||
public override OverlaySpace Space => OverlaySpace.WorldSpace;
|
||||
|
||||
public DebugDrawRayOverlay(DebugDrawingManager owner)
|
||||
public DebugDrawRayOverlay(DebugRayDrawingSystem owner)
|
||||
{
|
||||
_owner = owner;
|
||||
}
|
||||
@@ -90,7 +112,7 @@ namespace Robust.Client.Debugging
|
||||
protected internal override void Draw(in OverlayDrawArgs args)
|
||||
{
|
||||
var handle = args.WorldHandle;
|
||||
foreach (var ray in _owner.raysWithLifeTime)
|
||||
foreach (var ray in _owner._raysWithLifeTime)
|
||||
{
|
||||
handle.DrawLine(
|
||||
ray.RayOrigin,
|
||||
@@ -103,7 +125,7 @@ namespace Robust.Client.Debugging
|
||||
{
|
||||
base.FrameUpdate(args);
|
||||
|
||||
_owner.raysWithLifeTime.RemoveAll(r => r.LifeTime < _owner._gameTimer.RealTime);
|
||||
_owner._raysWithLifeTime.RemoveAll(r => r.LifeTime < _owner._gameTimer.RealTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Robust.Client.Debugging
|
||||
{
|
||||
public interface IDebugDrawingManager
|
||||
{
|
||||
bool DebugDrawRays { get; set; }
|
||||
TimeSpan DebugRayLifetime { get; set; }
|
||||
void Initialize();
|
||||
}
|
||||
}
|
||||
52
Robust.Client/GameController/GameController.RobustModules.cs
Normal file
52
Robust.Client/GameController/GameController.RobustModules.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using Robust.Client.WebViewHook;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Client
|
||||
{
|
||||
internal sealed partial class GameController
|
||||
{
|
||||
private void LoadOptionalRobustModules(GameController.DisplayMode mode)
|
||||
{
|
||||
// In the future, this manifest should be loaded somewhere else and used for more parts of init.
|
||||
// For now, this is fine.
|
||||
var manifest = LoadResourceManifest();
|
||||
|
||||
foreach (var module in manifest.Modules)
|
||||
{
|
||||
switch (module)
|
||||
{
|
||||
case "Robust.Client.WebView":
|
||||
LoadRobustWebView(mode);
|
||||
break;
|
||||
default:
|
||||
Logger.Error($"Unknown Robust module: {module}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadRobustWebView(GameController.DisplayMode mode)
|
||||
{
|
||||
Logger.Debug("Loading Robust.Client.WebView");
|
||||
|
||||
var assembly = LoadRobustModuleAssembly("Robust.Client.WebView");
|
||||
var attribute = assembly.GetCustomAttribute<WebViewManagerImplAttribute>()!;
|
||||
DebugTools.AssertNotNull(attribute);
|
||||
|
||||
var managerType = attribute.ImplementationType;
|
||||
_webViewHook = (IWebViewManagerHook)Activator.CreateInstance(managerType)!;
|
||||
_webViewHook.Initialize(mode);
|
||||
|
||||
Logger.Debug("Done initializing Robust.Client.WebView");
|
||||
}
|
||||
|
||||
private Assembly LoadRobustModuleAssembly(string assemblyName)
|
||||
{
|
||||
// TODO: Launcher distribution and all that stuff.
|
||||
return Assembly.Load(assemblyName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Runtime;
|
||||
@@ -11,12 +10,12 @@ using Robust.Client.GameStates;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Input;
|
||||
using Robust.Client.Placement;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Client.State;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.Utility;
|
||||
using Robust.Client.ViewVariables;
|
||||
using Robust.Client.WebViewHook;
|
||||
using Robust.LoaderApi;
|
||||
using Robust.Shared;
|
||||
using Robust.Shared.Asynchronous;
|
||||
@@ -32,6 +31,7 @@ using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
namespace Robust.Client
|
||||
{
|
||||
@@ -67,6 +67,8 @@ namespace Robust.Client
|
||||
[Dependency] private readonly IMidiManager _midiManager = default!;
|
||||
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
||||
|
||||
private IWebViewManagerHook? _webViewHook;
|
||||
|
||||
private CommandLineArgs? _commandLineArgs;
|
||||
|
||||
// Arguments for loader-load. Not used otherwise.
|
||||
@@ -87,7 +89,7 @@ namespace Robust.Client
|
||||
_clyde.SetWindowTitle(Options.DefaultWindowTitle);
|
||||
|
||||
_taskManager.Initialize();
|
||||
_fontManager.SetFontDpi((uint) _configurationManager.GetCVar(CVars.DisplayFontDpi));
|
||||
_fontManager.SetFontDpi((uint)_configurationManager.GetCVar(CVars.DisplayFontDpi));
|
||||
|
||||
// Disable load context usage on content start.
|
||||
// This prevents Content.Client being loaded twice and things like csi blowing up because of it.
|
||||
@@ -107,6 +109,9 @@ namespace Robust.Client
|
||||
|
||||
IoCManager.Resolve<ISerializationManager>().Initialize();
|
||||
|
||||
// Load optional Robust modules.
|
||||
LoadOptionalRobustModules(displayMode);
|
||||
|
||||
// Call Init in game assemblies.
|
||||
_modLoader.BroadcastRunLevel(ModRunLevel.PreInit);
|
||||
_modLoader.BroadcastRunLevel(ModRunLevel.Init);
|
||||
@@ -196,6 +201,39 @@ namespace Robust.Client
|
||||
return true;
|
||||
}
|
||||
|
||||
private ResourceManifestData LoadResourceManifest()
|
||||
{
|
||||
// Parses /manifest.yml for game-specific settings that cannot be exclusively set up by content code.
|
||||
if (!_resourceCache.TryContentFileRead("/manifest.yml", out var stream))
|
||||
return new ResourceManifestData(Array.Empty<string>());
|
||||
|
||||
var yamlStream = new YamlStream();
|
||||
using (stream)
|
||||
{
|
||||
using var streamReader = new StreamReader(stream, EncodingHelpers.UTF8);
|
||||
yamlStream.Load(streamReader);
|
||||
}
|
||||
|
||||
if (yamlStream.Documents.Count != 1 || yamlStream.Documents[0].RootNode is not YamlMappingNode mapping)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Expected a single YAML document with root mapping for /manifest.yml");
|
||||
}
|
||||
|
||||
var modules = Array.Empty<string>();
|
||||
if (mapping.TryGetNode("modules", out var modulesMap))
|
||||
{
|
||||
var sequence = (YamlSequenceNode)modulesMap;
|
||||
modules = new string[sequence.Children.Count];
|
||||
for (var i = 0; i < modules.Length; i++)
|
||||
{
|
||||
modules[i] = sequence[i].AsString();
|
||||
}
|
||||
}
|
||||
|
||||
return new ResourceManifestData(modules);
|
||||
}
|
||||
|
||||
internal bool StartupSystemSplash(GameControllerOptions options, Func<ILogHandler>? logHandlerFactory)
|
||||
{
|
||||
Options = options;
|
||||
@@ -217,8 +255,10 @@ namespace Robust.Client
|
||||
System.Console.WriteLine($"LogLevel {level} does not exist!");
|
||||
continue;
|
||||
}
|
||||
|
||||
logLevel = result;
|
||||
}
|
||||
|
||||
_logManager.GetSawmill(sawmill).Level = logLevel;
|
||||
}
|
||||
}
|
||||
@@ -259,7 +299,7 @@ namespace Robust.Client
|
||||
|
||||
{
|
||||
// Handle GameControllerOptions implicit CVar overrides.
|
||||
_configurationManager.OverrideConVars(new []
|
||||
_configurationManager.OverrideConVars(new[]
|
||||
{
|
||||
(CVars.DisplayWindowIconSet.Name, options.WindowIconSet.ToString()),
|
||||
(CVars.DisplaySplashLogo.Name, options.SplashLogo.ToString())
|
||||
@@ -271,9 +311,11 @@ namespace Robust.Client
|
||||
_resourceCache.Initialize(Options.LoadConfigAndUserData ? userDataDir : null);
|
||||
|
||||
var mountOptions = _commandLineArgs != null
|
||||
? MountOptions.Merge(_commandLineArgs.MountOptions, Options.MountOptions) : Options.MountOptions;
|
||||
? MountOptions.Merge(_commandLineArgs.MountOptions, Options.MountOptions)
|
||||
: Options.MountOptions;
|
||||
|
||||
ProgramShared.DoMounts(_resourceCache, mountOptions, Options.ContentBuildDirectory, Options.AssemblyDirectory,
|
||||
ProgramShared.DoMounts(_resourceCache, mountOptions, Options.ContentBuildDirectory,
|
||||
Options.AssemblyDirectory,
|
||||
Options.LoadContentResources, _loaderArgs != null && !Options.ResourceMountDisabled, ContentStart);
|
||||
|
||||
if (_loaderArgs != null)
|
||||
@@ -394,6 +436,7 @@ namespace Robust.Client
|
||||
|
||||
private void Update(FrameEventArgs frameEventArgs)
|
||||
{
|
||||
_webViewHook?.Update();
|
||||
_clyde.FrameProcess(frameEventArgs);
|
||||
_modLoader.BroadcastUpdate(ModUpdateLevel.FramePreEngine, frameEventArgs);
|
||||
_stateManager.FrameUpdate(frameEventArgs);
|
||||
@@ -442,7 +485,7 @@ namespace Robust.Client
|
||||
var uh = logManager.GetSawmill("unhandled");
|
||||
AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
|
||||
{
|
||||
var message = ((Exception) args.ExceptionObject).ToString();
|
||||
var message = ((Exception)args.ExceptionObject).ToString();
|
||||
uh.Log(args.IsTerminating ? LogLevel.Fatal : LogLevel.Error, message);
|
||||
};
|
||||
|
||||
@@ -485,11 +528,15 @@ namespace Robust.Client
|
||||
{
|
||||
_modLoader.Shutdown();
|
||||
|
||||
_webViewHook?.Shutdown();
|
||||
|
||||
_networkManager.Shutdown("Client shutting down");
|
||||
_midiManager.Shutdown();
|
||||
IoCManager.Resolve<IEntityLookup>().Shutdown();
|
||||
_entityManager.Shutdown();
|
||||
_clyde.Shutdown();
|
||||
}
|
||||
|
||||
private sealed record ResourceManifestData(string[] Modules);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,9 @@ namespace Robust.Client.GameObjects
|
||||
/// </summary>
|
||||
internal void AnimationComplete(string key)
|
||||
{
|
||||
#pragma warning disable 618
|
||||
AnimationCompleted?.Invoke(key);
|
||||
#pragma warning restore 618
|
||||
}
|
||||
|
||||
[Obsolete("Use AnimationCompletedEvent instead")]
|
||||
|
||||
@@ -27,7 +27,6 @@ namespace Robust.Client.GameObjects
|
||||
private bool _setDrawFovOnInitialize = true;
|
||||
[DataField("zoom")]
|
||||
private Vector2 _setZoomOnInitialize = Vector2.One;
|
||||
private Vector2 _offset = Vector2.Zero;
|
||||
|
||||
public IEye? Eye => _eye;
|
||||
|
||||
@@ -85,14 +84,11 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
public override Vector2 Offset
|
||||
{
|
||||
get => _offset;
|
||||
get => _eye?.Offset ?? default;
|
||||
set
|
||||
{
|
||||
if(_offset.EqualsApprox(value))
|
||||
return;
|
||||
|
||||
_offset = value;
|
||||
UpdateEyePosition();
|
||||
if (_eye != null)
|
||||
_eye.Offset = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +167,7 @@ namespace Robust.Client.GameObjects
|
||||
{
|
||||
if (_eye == null) return;
|
||||
var mapPos = Owner.Transform.MapPosition;
|
||||
_eye.Position = new MapCoordinates(mapPos.Position + _offset, mapPos.MapId);
|
||||
_eye.Position = new MapCoordinates(mapPos.Position, mapPos.MapId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,6 +120,12 @@ namespace Robust.Client.GameObjects
|
||||
set => _visibleNested = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether this pointlight should cast shadows
|
||||
/// </summary>
|
||||
[DataField("castShadows")]
|
||||
public bool CastShadows = true;
|
||||
|
||||
[DataField("nestedvisible")]
|
||||
private bool _visibleNested = true;
|
||||
[DataField("autoRot")]
|
||||
|
||||
@@ -43,15 +43,6 @@ namespace Robust.Client.GameObjects
|
||||
[Animatable]
|
||||
Color Color { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Controls whether we use RSI directions to rotate, or just get angular rotation applied.
|
||||
/// If true, all rotation to this sprite component is negated (that is rotation from say the owner being rotated).
|
||||
/// Rotation transformations on individual layers still apply.
|
||||
/// If false, all layers get locked to south and rotation is a transformation.
|
||||
/// </summary>
|
||||
[Obsolete("Use NoRotation and/or DirectionOverride")]
|
||||
bool Directional { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// All sprite rotation is locked, and will always be drawn upright on
|
||||
/// the screen, regardless of world or view orientation.
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace Robust.Client.GameObjects
|
||||
if (_visible == value) return;
|
||||
_visible = value;
|
||||
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new SpriteUpdateEvent());
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, new SpriteUpdateEvent());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,23 +114,6 @@ namespace Robust.Client.GameObjects
|
||||
set => color = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Controls whether we use RSI directions to rotate, or just get angular rotation applied.
|
||||
/// If true, all rotation to this sprite component is negated (that is rotation from say the owner being rotated).
|
||||
/// Rotation transformations on individual layers still apply.
|
||||
/// If false, all layers get locked to south and rotation is a transformation.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[Obsolete("Use NoRotation and/or DirectionOverride")]
|
||||
public bool Directional
|
||||
{
|
||||
get => _directional;
|
||||
set => _directional = value;
|
||||
}
|
||||
|
||||
[DataField("directional")]
|
||||
private bool _directional = true;
|
||||
|
||||
[ViewVariables]
|
||||
internal RenderingTreeComponent? RenderTree { get; set; } = null;
|
||||
|
||||
@@ -319,7 +302,7 @@ namespace Robust.Client.GameObjects
|
||||
{
|
||||
if (_containerOccluded == value) return;
|
||||
_containerOccluded = value;
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new SpriteUpdateEvent());
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, new SpriteUpdateEvent());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,6 +372,7 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
if (layerDatums.Count != 0)
|
||||
{
|
||||
LayerMap.Clear();
|
||||
LayerDatums = layerDatums;
|
||||
}
|
||||
}
|
||||
@@ -402,7 +386,6 @@ namespace Robust.Client.GameObjects
|
||||
{
|
||||
//deep copying things to avoid entanglement
|
||||
_baseRsi = other._baseRsi;
|
||||
_directional = other._directional;
|
||||
_visible = other._visible;
|
||||
_layerMapShared = other._layerMapShared;
|
||||
color = other.color;
|
||||
@@ -564,7 +547,7 @@ namespace Robust.Client.GameObjects
|
||||
Logger.ErrorS(LogCategory, "Unable to load RSI '{0}'. Trace:\n{1}", rsiPath, Environment.StackTrace);
|
||||
}
|
||||
|
||||
return AddLayer(stateId, res?.RSI);
|
||||
return AddLayer(stateId, res?.RSI, newIndex);
|
||||
}
|
||||
|
||||
public int AddLayerState(string stateId, ResourcePath rsiPath, int? newIndex = null)
|
||||
@@ -1270,6 +1253,12 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
private void RenderInternal(DrawingHandleWorld drawingHandle, Angle eyeRotation, Angle worldRotation, Vector2 worldPosition, Direction? overrideDirection)
|
||||
{
|
||||
// Reduce the angles to fix math shenanigans
|
||||
worldRotation = worldRotation.Reduced();
|
||||
|
||||
if (worldRotation.Theta < 0)
|
||||
worldRotation = new Angle(worldRotation.Theta + Math.Tau);
|
||||
|
||||
var localMatrix = GetLocalMatrix();
|
||||
|
||||
foreach (var layer in Layers)
|
||||
@@ -1280,12 +1269,13 @@ namespace Robust.Client.GameObjects
|
||||
}
|
||||
|
||||
var numDirs = GetLayerDirectionCount(layer);
|
||||
var layerRotation = worldRotation + layer.Rotation;
|
||||
|
||||
CalcModelMatrix(numDirs, eyeRotation, worldRotation, worldPosition, out var modelMatrix);
|
||||
CalcModelMatrix(numDirs, eyeRotation, layerRotation, worldPosition, out var modelMatrix);
|
||||
Matrix3.Multiply(ref localMatrix, ref modelMatrix, out var transformMatrix);
|
||||
drawingHandle.SetTransform(in transformMatrix);
|
||||
|
||||
RenderLayer(drawingHandle, layer, eyeRotation, worldRotation, overrideDirection);
|
||||
RenderLayer(drawingHandle, layer, eyeRotation, layerRotation, overrideDirection);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1321,7 +1311,7 @@ namespace Robust.Client.GameObjects
|
||||
public static Angle CalcRectWorldAngle(Angle worldAngle, int numDirections)
|
||||
{
|
||||
var theta = worldAngle.Theta;
|
||||
var segSize = (MathF.PI * 2) / (numDirections * 2);
|
||||
var segSize = (Math.PI * 2) / (numDirections * 2);
|
||||
var segments = (int)(theta / segSize);
|
||||
var odd = segments % 2;
|
||||
var result = theta - (segments * segSize) - (odd * segSize);
|
||||
@@ -1663,7 +1653,7 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
internal void UpdateBounds()
|
||||
{
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new SpriteUpdateEvent());
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, new SpriteUpdateEvent());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -2061,36 +2051,35 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
public static IEnumerable<IDirectionalTextureProvider> GetPrototypeTextures(EntityPrototype prototype, IResourceCache resourceCache)
|
||||
{
|
||||
return GetPrototypeTextures(prototype, resourceCache, out var _);
|
||||
}
|
||||
|
||||
public static IEnumerable<IDirectionalTextureProvider> GetPrototypeTextures(EntityPrototype prototype, IResourceCache resourceCache, out bool noRot)
|
||||
{
|
||||
var results = new List<IDirectionalTextureProvider>();
|
||||
noRot = false;
|
||||
var icon = IconComponent.GetPrototypeIcon(prototype, resourceCache);
|
||||
if (icon != null)
|
||||
{
|
||||
yield return icon;
|
||||
yield break;
|
||||
results.Add(icon);
|
||||
return results;
|
||||
}
|
||||
|
||||
if (!prototype.Components.TryGetValue("Sprite", out _))
|
||||
{
|
||||
yield return resourceCache.GetFallback<TextureResource>().Texture;
|
||||
yield break;
|
||||
results.Add(resourceCache.GetFallback<TextureResource>().Texture);
|
||||
return results;
|
||||
}
|
||||
|
||||
var dummy = new DummyIconEntity { Prototype = prototype };
|
||||
var spriteComponent = dummy.AddComponent<SpriteComponent>();
|
||||
|
||||
if (prototype.Components.TryGetValue("Appearance", out _))
|
||||
{
|
||||
var appearanceComponent = dummy.AddComponent<AppearanceComponent>();
|
||||
foreach (var layer in appearanceComponent.Visualizers)
|
||||
{
|
||||
layer.InitializeEntity(dummy);
|
||||
layer.OnChangeData(appearanceComponent);
|
||||
}
|
||||
}
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var dummy = entityManager.SpawnEntity(prototype.ID, MapCoordinates.Nullspace).Uid;
|
||||
var spriteComponent = entityManager.EnsureComponent<SpriteComponent>(dummy);
|
||||
|
||||
var anyTexture = false;
|
||||
foreach (var layer in spriteComponent.AllLayers)
|
||||
{
|
||||
if (layer.Texture != null) yield return layer.Texture;
|
||||
if (layer.Texture != null)
|
||||
results.Add(layer.Texture);
|
||||
if (!layer.RsiState.IsValid || !layer.Visible) continue;
|
||||
|
||||
var rsi = layer.Rsi ?? spriteComponent.BaseRSI;
|
||||
@@ -2098,14 +2087,17 @@ namespace Robust.Client.GameObjects
|
||||
!rsi.TryGetState(layer.RsiState, out var state))
|
||||
continue;
|
||||
|
||||
yield return state;
|
||||
results.Add(state);
|
||||
anyTexture = true;
|
||||
}
|
||||
|
||||
dummy.Delete();
|
||||
noRot = spriteComponent.NoRotation;
|
||||
|
||||
entityManager.DeleteEntity(dummy);
|
||||
|
||||
if (!anyTexture)
|
||||
yield return resourceCache.GetFallback<TextureResource>().Texture;
|
||||
results.Add(resourceCache.GetFallback<TextureResource>().Texture);
|
||||
return results;
|
||||
}
|
||||
|
||||
public static IRsiStateLike GetPrototypeIcon(EntityPrototype prototype, IResourceCache resourceCache)
|
||||
@@ -2118,144 +2110,14 @@ namespace Robust.Client.GameObjects
|
||||
return GetFallbackState(resourceCache);
|
||||
}
|
||||
|
||||
var dummy = new DummyIconEntity { Prototype = prototype };
|
||||
var spriteComponent = dummy.AddComponent<SpriteComponent>();
|
||||
dummy.Delete();
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var dummy = entityManager.SpawnEntity(prototype.ID, MapCoordinates.Nullspace).Uid;
|
||||
var spriteComponent = entityManager.EnsureComponent<SpriteComponent>(dummy);
|
||||
var result = spriteComponent.Icon ?? GetFallbackState(resourceCache);
|
||||
entityManager.DeleteEntity(dummy);
|
||||
|
||||
return spriteComponent.Icon ?? GetFallbackState(resourceCache);
|
||||
return result;
|
||||
}
|
||||
|
||||
#region DummyIconEntity
|
||||
private class DummyIconEntity : IEntity
|
||||
{
|
||||
public GameTick LastModifiedTick { get; } = GameTick.Zero;
|
||||
public IEntityManager EntityManager { get; } = null!;
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public EntityUid Uid { get; } = EntityUid.Invalid;
|
||||
EntityLifeStage IEntity.LifeStage { get => _lifeStage; set => _lifeStage = value; }
|
||||
public bool Initialized { get; } = false;
|
||||
public bool Initializing { get; } = false;
|
||||
public bool Deleted { get; } = true;
|
||||
public bool Paused { get; set; }
|
||||
public EntityPrototype? Prototype { get; set; }
|
||||
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public bool IsValid()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public ITransformComponent Transform { get; } = null!;
|
||||
public MetaDataComponent MetaData { get; } = null!;
|
||||
|
||||
private Dictionary<Type, IComponent> _components = new();
|
||||
private EntityLifeStage _lifeStage;
|
||||
|
||||
public T AddComponent<T>() where T : Component, new()
|
||||
{
|
||||
var typeFactory = IoCManager.Resolve<IDynamicTypeFactoryInternal>();
|
||||
var serializationManager = IoCManager.Resolve<ISerializationManager>();
|
||||
var comp = (T)typeFactory.CreateInstanceUnchecked(typeof(T));
|
||||
_components[typeof(T)] = comp;
|
||||
comp.Owner = this;
|
||||
|
||||
if (typeof(ISpriteComponent).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
_components[typeof(ISpriteComponent)] = comp;
|
||||
}
|
||||
|
||||
if (Prototype != null && Prototype.TryGetComponent<T>(comp.Name, out var node))
|
||||
{
|
||||
comp = serializationManager.Copy(node, comp)!;
|
||||
}
|
||||
|
||||
return comp;
|
||||
}
|
||||
|
||||
public void RemoveComponent<T>()
|
||||
{
|
||||
_components.Remove(typeof(T));
|
||||
}
|
||||
|
||||
public bool HasComponent<T>()
|
||||
{
|
||||
return _components.ContainsKey(typeof(T));
|
||||
}
|
||||
|
||||
public bool HasComponent(Type type)
|
||||
{
|
||||
return _components.ContainsKey(type);
|
||||
}
|
||||
|
||||
public T GetComponent<T>()
|
||||
{
|
||||
return (T)_components[typeof(T)];
|
||||
}
|
||||
|
||||
public IComponent GetComponent(Type type)
|
||||
{
|
||||
return null!;
|
||||
}
|
||||
|
||||
public bool TryGetComponent<T>([NotNullWhen(true)] out T? component) where T : class
|
||||
{
|
||||
component = null;
|
||||
if (!_components.TryGetValue(typeof(T), out var value)) return false;
|
||||
component = (T)value;
|
||||
return true;
|
||||
}
|
||||
|
||||
public T? GetComponentOrNull<T>() where T : class
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool TryGetComponent(Type type, [NotNullWhen(true)] out IComponent? component)
|
||||
{
|
||||
component = null;
|
||||
if (!_components.TryGetValue(type, out var value)) return false;
|
||||
component = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
public IComponent? GetComponentOrNull(Type type)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public void QueueDelete()
|
||||
{
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
}
|
||||
|
||||
public IEnumerable<IComponent> GetAllComponents()
|
||||
{
|
||||
return Enumerable.Empty<IComponent>();
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetAllComponents<T>()
|
||||
{
|
||||
return Enumerable.Empty<T>();
|
||||
}
|
||||
|
||||
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
|
||||
public void SendMessage(IComponent? owner, ComponentMessage message)
|
||||
{
|
||||
}
|
||||
|
||||
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
|
||||
public void SendNetworkMessage(IComponent owner, ComponentMessage message, INetChannel? channel = null)
|
||||
{
|
||||
}
|
||||
|
||||
public void Dirty()
|
||||
{
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
internal sealed class SpriteUpdateEvent : EntityEventArgs
|
||||
|
||||
@@ -12,21 +12,20 @@ using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Broadphase;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Client.GameObjects
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class AudioSystem : EntitySystem, IAudioSystem
|
||||
public class AudioSystem : SharedAudioSystem, IAudioSystem
|
||||
{
|
||||
[Dependency] private readonly IResourceCache _resourceCache = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly IClydeAudio _clyde = default!;
|
||||
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly SharedBroadphaseSystem _broadPhaseSystem = default!;
|
||||
[Dependency] private readonly SharedPhysicsSystem _broadPhaseSystem = default!;
|
||||
|
||||
private readonly List<PlayingStream> _playingClydeStreams = new();
|
||||
|
||||
@@ -65,7 +64,7 @@ namespace Robust.Client.GameObjects
|
||||
return;
|
||||
}
|
||||
|
||||
var stream = (PlayingStream?) Play(ev.FileName, ev.Coordinates, ev.AudioParams);
|
||||
var stream = (PlayingStream?) Play(ev.FileName, ev.Coordinates, ev.FallbackCoordinates, ev.AudioParams);
|
||||
if (stream != null)
|
||||
{
|
||||
stream.NetIdentifier = ev.Identifier;
|
||||
@@ -84,8 +83,8 @@ namespace Robust.Client.GameObjects
|
||||
private void PlayAudioEntityHandler(PlayAudioEntityMessage ev)
|
||||
{
|
||||
var stream = EntityManager.TryGetEntity(ev.EntityUid, out var entity) ?
|
||||
(PlayingStream?) Play(ev.FileName, entity, ev.AudioParams)
|
||||
: (PlayingStream?) Play(ev.FileName, ev.Coordinates, ev.AudioParams);
|
||||
(PlayingStream?) Play(ev.FileName, entity, ev.FallbackCoordinates, ev.AudioParams)
|
||||
: (PlayingStream?) Play(ev.FileName, ev.Coordinates, ev.FallbackCoordinates, ev.AudioParams);
|
||||
|
||||
if (stream != null)
|
||||
{
|
||||
@@ -135,6 +134,10 @@ namespace Robust.Client.GameObjects
|
||||
mapPos = stream.TrackingEntity.Transform.MapPosition;
|
||||
}
|
||||
|
||||
// TODO Remove when coordinates can't be NaN
|
||||
if (mapPos == null || !float.IsFinite(mapPos.Value.X) || !float.IsFinite(mapPos.Value.Y))
|
||||
mapPos = stream.TrackingFallbackCoordinates?.ToMap(_entityManager);
|
||||
|
||||
if (mapPos != null)
|
||||
{
|
||||
var pos = mapPos.Value;
|
||||
@@ -212,7 +215,6 @@ namespace Robust.Client.GameObjects
|
||||
{
|
||||
stream.Source.SetVelocity(stream.TrackingEntity.GlobalLinearVelocity());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -277,12 +279,14 @@ namespace Robust.Client.GameObjects
|
||||
/// </summary>
|
||||
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
|
||||
/// <param name="entity">The entity "emitting" the audio.</param>
|
||||
/// <param name="fallbackCoordinates">The map or grid coordinates at which to play the audio when entity is invalid.</param>
|
||||
/// <param name="audioParams"></param>
|
||||
private IPlayingAudioStream? Play(string filename, IEntity entity, AudioParams? audioParams = null)
|
||||
private IPlayingAudioStream? Play(string filename, IEntity entity, EntityCoordinates fallbackCoordinates,
|
||||
AudioParams? audioParams = null)
|
||||
{
|
||||
if (_resourceCache.TryGetResource<AudioResource>(new ResourcePath(filename), out var audio))
|
||||
{
|
||||
return Play(audio, entity, audioParams);
|
||||
return Play(audio, entity, fallbackCoordinates, audioParams);
|
||||
}
|
||||
|
||||
Logger.Error($"Server tried to play audio file {filename} which does not exist.");
|
||||
@@ -294,15 +298,15 @@ namespace Robust.Client.GameObjects
|
||||
/// </summary>
|
||||
/// <param name="stream">The audio stream to play.</param>
|
||||
/// <param name="entity">The entity "emitting" the audio.</param>
|
||||
/// <param name="fallbackCoordinates">The map or grid coordinates at which to play the audio when entity is invalid.</param>
|
||||
/// <param name="audioParams"></param>
|
||||
private IPlayingAudioStream? Play(AudioStream stream, IEntity entity, AudioParams? audioParams = null)
|
||||
private IPlayingAudioStream? Play(AudioStream stream, IEntity entity, EntityCoordinates fallbackCoordinates,
|
||||
AudioParams? audioParams = null)
|
||||
{
|
||||
var source = _clyde.CreateAudioSource(stream);
|
||||
if (!source.SetPosition(entity.Transform.WorldPosition))
|
||||
{
|
||||
source.Dispose();
|
||||
Logger.Warning($"Can't play positional audio \"{stream.Name}\", can't set position.");
|
||||
return null;
|
||||
return Play(stream, fallbackCoordinates, fallbackCoordinates, audioParams);
|
||||
}
|
||||
|
||||
ApplyAudioParams(audioParams, source);
|
||||
@@ -312,6 +316,7 @@ namespace Robust.Client.GameObjects
|
||||
{
|
||||
Source = source,
|
||||
TrackingEntity = entity,
|
||||
TrackingFallbackCoordinates = fallbackCoordinates != EntityCoordinates.Invalid ? fallbackCoordinates : null,
|
||||
Attenuation = audioParams?.Attenuation ?? Attenuation.Default,
|
||||
MaxDistance = audioParams?.MaxDistance ?? float.MaxValue,
|
||||
ReferenceDistance = audioParams?.ReferenceDistance ?? 1f,
|
||||
@@ -327,12 +332,14 @@ namespace Robust.Client.GameObjects
|
||||
/// </summary>
|
||||
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
|
||||
/// <param name="coordinates">The coordinates at which to play the audio.</param>
|
||||
/// <param name="fallbackCoordinates">The map or grid coordinates at which to play the audio when coordinates are invalid.</param>
|
||||
/// <param name="audioParams"></param>
|
||||
private IPlayingAudioStream? Play(string filename, EntityCoordinates coordinates, AudioParams? audioParams = null)
|
||||
private IPlayingAudioStream? Play(string filename, EntityCoordinates coordinates, EntityCoordinates fallbackCoordinates,
|
||||
AudioParams? audioParams = null)
|
||||
{
|
||||
if (_resourceCache.TryGetResource<AudioResource>(new ResourcePath(filename), out var audio))
|
||||
{
|
||||
return Play(audio, coordinates, audioParams);
|
||||
return Play(audio, coordinates, fallbackCoordinates, audioParams);
|
||||
}
|
||||
|
||||
Logger.Error($"Server tried to play audio file {filename} which does not exist.");
|
||||
@@ -344,18 +351,24 @@ namespace Robust.Client.GameObjects
|
||||
/// </summary>
|
||||
/// <param name="stream">The audio stream to play.</param>
|
||||
/// <param name="coordinates">The coordinates at which to play the audio.</param>
|
||||
/// <param name="fallbackCoordinates">The map or grid coordinates at which to play the audio when coordinates are invalid.</param>
|
||||
/// <param name="audioParams"></param>
|
||||
private IPlayingAudioStream? Play(AudioStream stream, EntityCoordinates coordinates,
|
||||
AudioParams? audioParams = null)
|
||||
EntityCoordinates fallbackCoordinates, AudioParams? audioParams = null)
|
||||
{
|
||||
var source = _clyde.CreateAudioSource(stream);
|
||||
if (!source.SetPosition(coordinates.ToMapPos(EntityManager)))
|
||||
if (!source.SetPosition(fallbackCoordinates.Position))
|
||||
{
|
||||
source.Dispose();
|
||||
Logger.Warning($"Can't play positional audio \"{stream.Name}\", can't set position.");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!coordinates.IsValid(_entityManager))
|
||||
{
|
||||
coordinates = fallbackCoordinates;
|
||||
}
|
||||
|
||||
ApplyAudioParams(audioParams, source);
|
||||
|
||||
source.StartPlaying();
|
||||
@@ -363,6 +376,7 @@ namespace Robust.Client.GameObjects
|
||||
{
|
||||
Source = source,
|
||||
TrackingCoordinates = coordinates,
|
||||
TrackingFallbackCoordinates = fallbackCoordinates != EntityCoordinates.Invalid ? fallbackCoordinates : null,
|
||||
Attenuation = audioParams?.Attenuation ?? Attenuation.Default,
|
||||
MaxDistance = audioParams?.MaxDistance ?? float.MaxValue,
|
||||
ReferenceDistance = audioParams?.ReferenceDistance ?? 1f,
|
||||
@@ -395,6 +409,7 @@ namespace Robust.Client.GameObjects
|
||||
public IClydeAudioSource Source = default!;
|
||||
public IEntity TrackingEntity = default!;
|
||||
public EntityCoordinates? TrackingCoordinates;
|
||||
public EntityCoordinates? TrackingFallbackCoordinates;
|
||||
public bool Done;
|
||||
public float Volume;
|
||||
|
||||
@@ -440,19 +455,19 @@ namespace Robust.Client.GameObjects
|
||||
/// <inheritdoc />
|
||||
public IPlayingAudioStream? Play(Filter playerFilter, string filename, IEntity entity, AudioParams? audioParams = null)
|
||||
{
|
||||
return Play(filename, entity, audioParams);
|
||||
return Play(filename, entity, GetFallbackCoordinates(entity.Transform.MapPosition), audioParams);
|
||||
}
|
||||
|
||||
public IPlayingAudioStream? Play(Filter playerFilter, string filename, EntityUid uid, AudioParams? audioParams = null)
|
||||
{
|
||||
return EntityManager.TryGetEntity(uid, out var entity)
|
||||
? Play(filename, entity, audioParams) : null;
|
||||
? Play(filename, entity, GetFallbackCoordinates(entity.Transform.MapPosition), audioParams) : null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IPlayingAudioStream? Play(Filter playerFilter, string filename, EntityCoordinates coordinates, AudioParams? audioParams = null)
|
||||
{
|
||||
return Play(filename, coordinates, audioParams);
|
||||
return Play(filename, coordinates, GetFallbackCoordinates(coordinates.ToMap(_entityManager)), audioParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
#nullable enable
|
||||
|
||||
@@ -20,14 +21,23 @@ namespace Robust.Client.GameObjects
|
||||
[UsedImplicitly]
|
||||
internal class EyeUpdateSystem : EntitySystem
|
||||
{
|
||||
// How fast the camera rotates in radians
|
||||
private const float CameraRotateSpeed = MathF.PI;
|
||||
|
||||
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
|
||||
private bool _isLerping = false;
|
||||
private TransformComponent? _lastParent;
|
||||
private TransformComponent? _lerpTo;
|
||||
private Angle LerpStartRotation;
|
||||
private float _accumulator;
|
||||
|
||||
public bool IsLerping { get => _lerpTo != null; }
|
||||
|
||||
// How fast the camera rotates in radians / s
|
||||
private const float CameraRotateSpeed = MathF.PI;
|
||||
// PER THIS AMOUNT OF TIME MILLISECONDS
|
||||
private const float CameraRotateTimeUnit = 1.2f;
|
||||
// Safety override
|
||||
private const float _lerpTimeMax = CameraRotateTimeUnit + 0.4f;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Initialize()
|
||||
@@ -59,27 +69,6 @@ namespace Robust.Client.GameObjects
|
||||
var currentEye = _eyeManager.CurrentEye;
|
||||
|
||||
// TODO: Content should have its own way of handling this. We should have a default behavior that they can overwrite.
|
||||
/*
|
||||
var inputSystem = EntitySystemManager.GetEntitySystem<InputSystem>();
|
||||
|
||||
var direction = 0;
|
||||
if (inputSystem.CmdStates[EngineKeyFunctions.CameraRotateRight] == BoundKeyState.Down)
|
||||
{
|
||||
direction += 1;
|
||||
}
|
||||
|
||||
if (inputSystem.CmdStates[EngineKeyFunctions.CameraRotateLeft] == BoundKeyState.Down)
|
||||
{
|
||||
direction -= 1;
|
||||
}
|
||||
|
||||
// apply camera rotation
|
||||
if(direction != 0)
|
||||
{
|
||||
currentEye.Rotation += CameraRotateSpeed * frameTime * direction;
|
||||
currentEye.Rotation = currentEye.Rotation.Reduced();
|
||||
}
|
||||
*/
|
||||
|
||||
var playerTransform = _playerManager.LocalPlayer?.ControlledEntity?.Transform;
|
||||
|
||||
@@ -91,13 +80,55 @@ namespace Robust.Client.GameObjects
|
||||
gridEnt.Transform
|
||||
: _mapManager.GetMapEntity(playerTransform.MapID).Transform;
|
||||
|
||||
if (!_isLerping)
|
||||
// Make sure that we don't fire the vomit carousel when we spawn in
|
||||
if (_lastParent is null)
|
||||
_lastParent = parent;
|
||||
|
||||
// Set a default for target rotation
|
||||
var parentRotation = -parent.WorldRotation;
|
||||
// Reuse current rotation when stepping into space
|
||||
if (parent.GridID == GridId.Invalid)
|
||||
parentRotation = currentEye.Rotation;
|
||||
|
||||
// Handle grid change in general
|
||||
if (_lastParent != parent)
|
||||
_lerpTo = parent;
|
||||
|
||||
// And we are up and running!
|
||||
if (_lerpTo is not null)
|
||||
{
|
||||
// TODO: Detect parent change and start lerping
|
||||
var parentRotation = parent.WorldRotation;
|
||||
currentEye.Rotation = -parentRotation;
|
||||
// Handle a case where we have beeing spinning around, but suddenly got off onto a different grid
|
||||
if (parent != _lerpTo) {
|
||||
LerpStartRotation = currentEye.Rotation;
|
||||
_lerpTo = parent;
|
||||
_accumulator = 0f;
|
||||
}
|
||||
|
||||
_accumulator += frameTime;
|
||||
|
||||
var changeNeeded = (float) (LerpStartRotation - parentRotation).Theta;
|
||||
|
||||
var changeLerp = _accumulator / (Math.Abs(changeNeeded % MathF.PI) / CameraRotateSpeed * CameraRotateTimeUnit);
|
||||
|
||||
currentEye.Rotation = Angle.Lerp(LerpStartRotation, parentRotation, changeLerp);
|
||||
|
||||
// Either we have overshot, or we have taken way too long on this, emergency reset time
|
||||
if (changeLerp > 1.0f || _accumulator >= _lerpTimeMax)
|
||||
{
|
||||
_lastParent = parent;
|
||||
_lerpTo = null;
|
||||
_accumulator = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
// We are just fine, or we finished a lerp (and probably overshot)
|
||||
if (_lerpTo is null)
|
||||
{
|
||||
currentEye.Rotation = parentRotation;
|
||||
LerpStartRotation = parentRotation;
|
||||
}
|
||||
|
||||
|
||||
foreach (var eyeComponent in EntityManager.EntityQuery<EyeComponent>(true))
|
||||
{
|
||||
eyeComponent.UpdateEyePosition();
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace Robust.Client.GameObjects
|
||||
AnythingMovedSubHandler(args.Sender.Transform);
|
||||
}
|
||||
|
||||
private void AnythingMovedSubHandler(ITransformComponent sender)
|
||||
private void AnythingMovedSubHandler(TransformComponent sender)
|
||||
{
|
||||
// To avoid doing redundant updates (and we don't need to update a grid's children ever)
|
||||
if (!_checkedChildren.Add(sender.Owner.Uid) ||
|
||||
@@ -125,7 +125,7 @@ namespace Robust.Client.GameObjects
|
||||
if (sender.Owner.TryGetComponent(out PointLightComponent? light))
|
||||
QueueLightUpdate(light);
|
||||
|
||||
foreach (ITransformComponent child in sender.Children)
|
||||
foreach (TransformComponent child in sender.Children)
|
||||
{
|
||||
AnythingMovedSubHandler(child);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace Robust.Client.GameObjects
|
||||
[Dependency] private readonly RenderingTreeSystem _treeSystem = default!;
|
||||
|
||||
private readonly Queue<SpriteComponent> _inertUpdateQueue = new();
|
||||
private HashSet<ISpriteComponent> _manualUpdate = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -38,6 +39,12 @@ namespace Robust.Client.GameObjects
|
||||
sprite.DoUpdateIsInert();
|
||||
}
|
||||
|
||||
foreach (var sprite in _manualUpdate)
|
||||
{
|
||||
if (!sprite.Deleted && !sprite.IsInert)
|
||||
sprite.FrameUpdate(frameTime);
|
||||
}
|
||||
|
||||
var pvsBounds = _eyeManager.GetWorldViewbounds();
|
||||
|
||||
var currentMap = _eyeManager.CurrentMap;
|
||||
@@ -57,10 +64,21 @@ namespace Robust.Client.GameObjects
|
||||
return true;
|
||||
}
|
||||
|
||||
value.FrameUpdate(state);
|
||||
if (!_manualUpdate.Contains(value))
|
||||
value.FrameUpdate(state);
|
||||
return true;
|
||||
}, bounds, true);
|
||||
}
|
||||
|
||||
_manualUpdate.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Force update of the sprite component next frame
|
||||
/// </summary>
|
||||
public void ForceUpdate(ISpriteComponent sprite)
|
||||
{
|
||||
_manualUpdate.Add(sprite);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,8 @@ namespace Robust.Client.GameObjects
|
||||
private void MessageReceived(BoundUIWrapMessage ev)
|
||||
{
|
||||
var uid = ev.Entity;
|
||||
var cmp = EntityManager.GetComponent<ClientUserInterfaceComponent>(uid);
|
||||
if (!EntityManager.TryGetComponent<ClientUserInterfaceComponent>(uid, out var cmp))
|
||||
return;
|
||||
|
||||
var message = ev.Message;
|
||||
// This should probably not happen at this point, but better make extra sure!
|
||||
|
||||
@@ -25,6 +25,9 @@ namespace Robust.Client.Graphics
|
||||
internal set => _coords = value;
|
||||
}
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public Vector2 Offset { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public Angle Rotation
|
||||
@@ -51,6 +54,15 @@ namespace Robust.Client.Graphics
|
||||
|
||||
/// <inheritdoc />
|
||||
public void GetViewMatrix(out Matrix3 viewMatrix, Vector2 renderScale)
|
||||
{
|
||||
var scaleMat = Matrix3.CreateScale(_scale.X * renderScale.X, _scale.Y * renderScale.Y);
|
||||
var rotMat = Matrix3.CreateRotation(_rotation);
|
||||
var transMat = Matrix3.CreateTranslation(-_coords.Position - Offset);
|
||||
|
||||
viewMatrix = transMat * rotMat * scaleMat;
|
||||
}
|
||||
|
||||
public void GetViewMatrixNoOffset(out Matrix3 viewMatrix, Vector2 renderScale)
|
||||
{
|
||||
var scaleMat = Matrix3.CreateScale(_scale.X * renderScale.X, _scale.Y * renderScale.Y);
|
||||
var rotMat = Matrix3.CreateRotation(_rotation);
|
||||
|
||||
@@ -21,6 +21,11 @@ namespace Robust.Client.Graphics
|
||||
/// </summary>
|
||||
MapCoordinates Position { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Translation offset from <see cref="Position"/>. Does not influence the center of FOV.
|
||||
/// </summary>
|
||||
Vector2 Offset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Rotation of the camera around the Z axis.
|
||||
/// </summary>
|
||||
@@ -51,5 +56,7 @@ namespace Robust.Client.Graphics
|
||||
/// <param name="viewMatrixInv">Inverted view matrix for this camera.</param>
|
||||
/// <param name="renderScale"></param>
|
||||
void GetViewMatrixInv(out Matrix3 viewMatrixInv, Vector2 renderScale);
|
||||
|
||||
void GetViewMatrixNoOffset(out Matrix3 viewMatrix, Vector2 renderScale);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using OpenToolkit.Audio.OpenAL;
|
||||
using OpenToolkit.Audio.OpenAL.Extensions.Creative.EFX;
|
||||
using OpenToolkit.Mathematics;
|
||||
using Robust.Client.Audio;
|
||||
using Robust.Shared;
|
||||
using Robust.Shared.Audio;
|
||||
@@ -155,6 +156,14 @@ namespace Robust.Client.Graphics.Clyde
|
||||
var eye = _eyeManager.CurrentEye;
|
||||
var (x, y) = eye.Position.Position;
|
||||
AL.Listener(ALListener3f.Position, x, y, -5);
|
||||
var rot2d = eye.Rotation.ToVec();
|
||||
AL.Listener(ALListenerfv.Orientation, new []{0, 0, -1, rot2d.X, rot2d.Y, 0});
|
||||
|
||||
// Default orientation: at: (0, 0, -1) up: (0, 1, 0)
|
||||
var (rotX, rotY) = eye.Rotation.ToVec();
|
||||
var at = new Vector3(0f, 0f, -1f);
|
||||
var up = new Vector3(rotY, rotX, 0f);
|
||||
AL.Listener(ALListenerfv.Orientation, ref at, ref up);
|
||||
|
||||
// Clear out finalized audio sources.
|
||||
while (_sourceDisposeQueue.TryDequeue(out var handles))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using OpenToolkit.Graphics.OpenGL4;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -49,10 +50,11 @@ namespace Robust.Client.Graphics.Clyde
|
||||
continue;
|
||||
}
|
||||
|
||||
var transform = _entityManager.GetComponent<ITransformComponent>(grid.GridEntityId);
|
||||
var transform = _entityManager.GetComponent<TransformComponent>(grid.GridEntityId);
|
||||
gridProgram.SetUniform(UniIModelMatrix, transform.WorldMatrix);
|
||||
grid.GetMapChunks(worldBounds, out var enumerator);
|
||||
|
||||
foreach (var chunk in grid.GetMapChunks(worldBounds))
|
||||
while (enumerator.MoveNext(out var chunk))
|
||||
{
|
||||
if (_isChunkDirty(grid, chunk))
|
||||
{
|
||||
@@ -85,50 +87,39 @@ namespace Robust.Client.Graphics.Clyde
|
||||
datum = _initChunkBuffers(grid, chunk);
|
||||
}
|
||||
|
||||
var vertexPool = ArrayPool<Vertex2D>.Shared;
|
||||
var indexPool = ArrayPool<ushort>.Shared;
|
||||
Span<ushort> indexBuffer = stackalloc ushort[_indicesPerChunk(chunk)];
|
||||
Span<Vertex2D> vertexBuffer = stackalloc Vertex2D[_verticesPerChunk(chunk)];
|
||||
|
||||
var vertexBuffer = vertexPool.Rent(_verticesPerChunk(chunk));
|
||||
var indexBuffer = indexPool.Rent(_indicesPerChunk(chunk));
|
||||
|
||||
try
|
||||
var i = 0;
|
||||
foreach (var tile in chunk)
|
||||
{
|
||||
var i = 0;
|
||||
foreach (var tile in chunk)
|
||||
var regionMaybe = _tileDefinitionManager.TileAtlasRegion(tile.Tile);
|
||||
if (regionMaybe == null)
|
||||
{
|
||||
var regionMaybe = _tileDefinitionManager.TileAtlasRegion(tile.Tile);
|
||||
if (regionMaybe == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var region = regionMaybe.Value;
|
||||
|
||||
var vIdx = i * 4;
|
||||
vertexBuffer[vIdx + 0] = new Vertex2D(tile.X, tile.Y, region.Left, region.Bottom);
|
||||
vertexBuffer[vIdx + 1] = new Vertex2D(tile.X + 1, tile.Y, region.Right, region.Bottom);
|
||||
vertexBuffer[vIdx + 2] = new Vertex2D(tile.X + 1, tile.Y + 1, region.Right, region.Top);
|
||||
vertexBuffer[vIdx + 3] = new Vertex2D(tile.X, tile.Y + 1, region.Left, region.Top);
|
||||
var nIdx = i * GetQuadBatchIndexCount();
|
||||
var tIdx = (ushort) (i * 4);
|
||||
QuadBatchIndexWrite(indexBuffer, ref nIdx, tIdx);
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
GL.BindVertexArray(datum.VAO);
|
||||
CheckGlError();
|
||||
datum.EBO.Use();
|
||||
datum.VBO.Use();
|
||||
datum.EBO.Reallocate(new Span<ushort>(indexBuffer, 0, i * GetQuadBatchIndexCount()));
|
||||
datum.VBO.Reallocate(new Span<Vertex2D>(vertexBuffer, 0, i * 4));
|
||||
datum.Dirty = false;
|
||||
datum.TileCount = i;
|
||||
}
|
||||
finally
|
||||
{
|
||||
vertexPool.Return(vertexBuffer);
|
||||
indexPool.Return(indexBuffer);
|
||||
var region = regionMaybe.Value;
|
||||
|
||||
var vIdx = i * 4;
|
||||
vertexBuffer[vIdx + 0] = new Vertex2D(tile.X, tile.Y, region.Left, region.Bottom);
|
||||
vertexBuffer[vIdx + 1] = new Vertex2D(tile.X + 1, tile.Y, region.Right, region.Bottom);
|
||||
vertexBuffer[vIdx + 2] = new Vertex2D(tile.X + 1, tile.Y + 1, region.Right, region.Top);
|
||||
vertexBuffer[vIdx + 3] = new Vertex2D(tile.X, tile.Y + 1, region.Left, region.Top);
|
||||
var nIdx = i * GetQuadBatchIndexCount();
|
||||
var tIdx = (ushort) (i * 4);
|
||||
QuadBatchIndexWrite(indexBuffer, ref nIdx, tIdx);
|
||||
i += 1;
|
||||
}
|
||||
|
||||
GL.BindVertexArray(datum.VAO);
|
||||
CheckGlError();
|
||||
datum.EBO.Use();
|
||||
datum.VBO.Use();
|
||||
datum.EBO.Reallocate(indexBuffer[..(i * GetQuadBatchIndexCount())]);
|
||||
datum.VBO.Reallocate(vertexBuffer[..(i * 4)]);
|
||||
datum.Dirty = false;
|
||||
datum.TileCount = i;
|
||||
}
|
||||
|
||||
private MapChunkData _initChunkBuffers(IMapGrid grid, IMapChunk chunk)
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
SwapAllBuffers();
|
||||
}
|
||||
|
||||
private void RenderOverlays(Viewport vp, OverlaySpace space, in Box2 worldBox)
|
||||
private void RenderOverlays(Viewport vp, OverlaySpace space, in Box2 worldBox, in Box2Rotated worldBounds)
|
||||
{
|
||||
using (DebugGroup($"Overlays: {space}"))
|
||||
{
|
||||
@@ -116,8 +116,10 @@ namespace Robust.Client.Graphics.Clyde
|
||||
ClearFramebuffer(default);
|
||||
}
|
||||
|
||||
overlay.ClydeRender(_renderHandle, space, null, vp, new UIBox2i((0, 0), vp.Size), worldBox);
|
||||
overlay.ClydeRender(_renderHandle, space, null, vp, new UIBox2i((0, 0), vp.Size), worldBox, worldBounds);
|
||||
}
|
||||
|
||||
FlushRenderQueue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,8 +132,9 @@ namespace Robust.Client.Graphics.Clyde
|
||||
{
|
||||
var list = GetOverlaysForSpace(space);
|
||||
|
||||
var worldBounds = CalcWorldAABB(vp);
|
||||
var args = new OverlayDrawArgs(space, vpControl, vp, handle, bounds, worldBounds);
|
||||
var worldAABB = CalcWorldAABB(vp);
|
||||
var worldBounds = CalcWorldBounds(vp);
|
||||
var args = new OverlayDrawArgs(space, vpControl, vp, handle, bounds, worldAABB, worldBounds);
|
||||
|
||||
foreach (var overlay in list)
|
||||
{
|
||||
@@ -209,11 +212,12 @@ namespace Robust.Client.Graphics.Clyde
|
||||
return;
|
||||
}
|
||||
|
||||
RenderOverlays(viewport, OverlaySpace.WorldSpaceBelowEntities, worldAABB);
|
||||
RenderOverlays(viewport, OverlaySpace.WorldSpaceBelowEntities, worldAABB, worldBounds);
|
||||
|
||||
var screenSize = viewport.Size;
|
||||
eye.GetViewMatrix(out var eyeMatrix, eye.Scale);
|
||||
|
||||
ProcessSpriteEntities(mapId, worldBounds, _drawingSpriteList);
|
||||
ProcessSpriteEntities(mapId, eyeMatrix, worldBounds, _drawingSpriteList);
|
||||
|
||||
var worldOverlays = new List<Overlay>();
|
||||
|
||||
@@ -261,7 +265,8 @@ namespace Robust.Client.Graphics.Clyde
|
||||
null,
|
||||
viewport,
|
||||
new UIBox2i((0, 0), viewport.Size),
|
||||
worldAABB);
|
||||
worldAABB,
|
||||
worldBounds);
|
||||
overlayIndex = j;
|
||||
continue;
|
||||
}
|
||||
@@ -362,7 +367,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private void ProcessSpriteEntities(MapId map, Box2Rotated worldBounds,
|
||||
private void ProcessSpriteEntities(MapId map, Matrix3 eyeMatrix, Box2Rotated worldBounds,
|
||||
RefList<(SpriteComponent sprite, Matrix3 matrix, Angle worldRot, float yWorldPos)> list)
|
||||
{
|
||||
foreach (var comp in _entitySystemManager.GetEntitySystem<RenderingTreeSystem>().GetRenderTrees(map, worldBounds))
|
||||
@@ -380,10 +385,10 @@ namespace Robust.Client.Graphics.Clyde
|
||||
entry.sprite = value;
|
||||
entry.worldRot = transform.WorldRotation;
|
||||
entry.matrix = transform.WorldMatrix;
|
||||
var worldPos = new Vector2(entry.matrix.R0C2, entry.matrix.R1C2);
|
||||
var eyePos = eyeMatrix.Transform(new Vector2(entry.matrix.R0C2, entry.matrix.R1C2));
|
||||
// Didn't use the bounds from the query as that has to be re-calculated (and is probably more expensive than this).
|
||||
var bounds = value.CalculateBoundingBox(worldPos);
|
||||
entry.yWorldPos = worldPos.Y - bounds.Extents.Y;
|
||||
var bounds = value.CalculateBoundingBox(eyePos);
|
||||
entry.yWorldPos = eyePos.Y - bounds.Extents.Y;
|
||||
return true;
|
||||
|
||||
}, bounds, true);
|
||||
@@ -468,8 +473,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
DrawLightsAndFov(viewport, worldBounds, worldAABB, eye);
|
||||
}
|
||||
|
||||
RenderOverlays(viewport, OverlaySpace.WorldSpaceBelowWorld, worldAABB);
|
||||
FlushRenderQueue();
|
||||
RenderOverlays(viewport, OverlaySpace.WorldSpaceBelowWorld, worldAABB, worldBounds);
|
||||
|
||||
using (DebugGroup("Grids"))
|
||||
{
|
||||
@@ -482,8 +486,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
DrawEntities(viewport, worldBounds, worldAABB, eye);
|
||||
}
|
||||
|
||||
RenderOverlays(viewport, OverlaySpace.WorldSpaceBelowFOV, worldAABB);
|
||||
FlushRenderQueue();
|
||||
RenderOverlays(viewport, OverlaySpace.WorldSpaceBelowFOV, worldAABB, worldBounds);
|
||||
|
||||
if (_lightManager.Enabled && _lightManager.DrawHardFov && eye.DrawFov)
|
||||
{
|
||||
@@ -516,8 +519,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
UIBox2.FromDimensions(Vector2.Zero, viewport.Size), new Color(1, 1, 1, 0.5f));
|
||||
}
|
||||
|
||||
RenderOverlays(viewport, OverlaySpace.WorldSpace, worldAABB);
|
||||
FlushRenderQueue();
|
||||
RenderOverlays(viewport, OverlaySpace.WorldSpace, worldAABB, worldBounds);
|
||||
|
||||
_currentViewport = oldVp;
|
||||
});
|
||||
@@ -529,12 +531,13 @@ namespace Robust.Client.Graphics.Clyde
|
||||
if (eye == null)
|
||||
return default;
|
||||
|
||||
return GetAABB(eye, viewport);
|
||||
// Will be larger than the actual viewport due to rotation.
|
||||
return CalcWorldBounds(viewport).CalcBoundingBox();
|
||||
}
|
||||
|
||||
private static Box2 GetAABB(IEye eye, Viewport viewport)
|
||||
{
|
||||
return Box2.CenteredAround(eye.Position.Position,
|
||||
return Box2.CenteredAround(eye.Position.Position + eye.Offset,
|
||||
viewport.Size / viewport.RenderScale / EyeManager.PixelsPerMeter * eye.Zoom);
|
||||
}
|
||||
|
||||
|
||||
@@ -335,7 +335,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
}
|
||||
|
||||
var (lights, count, expandedBounds) = GetLightsToRender(mapId, worldBounds, worldAABB);
|
||||
eye.GetViewMatrix(out var eyeTransform, eye.Scale);
|
||||
eye.GetViewMatrixNoOffset(out var eyeTransform, eye.Scale);
|
||||
|
||||
UpdateOcclusionGeometry(mapId, expandedBounds, eyeTransform);
|
||||
|
||||
@@ -361,6 +361,8 @@ namespace Robust.Client.Graphics.Clyde
|
||||
{
|
||||
var (light, lightPos, _) = lights[i];
|
||||
|
||||
if (!light.CastShadows) continue;
|
||||
|
||||
DrawOcclusionDepth(lightPos, ShadowMapSize, light.Radius, i);
|
||||
}
|
||||
}
|
||||
@@ -459,7 +461,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
}
|
||||
|
||||
lightShader.SetUniformMaybe("lightCenter", lightPos);
|
||||
lightShader.SetUniformMaybe("lightIndex", (i + 0.5f) / ShadowTexture.Height);
|
||||
lightShader.SetUniformMaybe("lightIndex", component.CastShadows ? (i + 0.5f) / ShadowTexture.Height : -1);
|
||||
|
||||
var offset = new Vector2(component.Radius, component.Radius);
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Text;
|
||||
using System;
|
||||
using System.Text;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
@@ -143,6 +144,61 @@ namespace Robust.Client.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class StackedFont : Font
|
||||
{
|
||||
// _main is the "default" font; the top of the Stack.
|
||||
public readonly Font _main;
|
||||
public readonly Font[] Stack;
|
||||
|
||||
public StackedFont(params Font[] args)
|
||||
{
|
||||
if (args.Length < 1)
|
||||
throw new ArgumentException("At least one font is required");
|
||||
|
||||
Stack = args;
|
||||
_main = args[0];
|
||||
}
|
||||
|
||||
// All metrics methods use the default font (_main).
|
||||
// Technically these could vary between stacked fonts, but that is a case
|
||||
// that really should already be avoided for so many other reasons.
|
||||
public override int GetAscent(float scale) => _main.GetAscent(scale);
|
||||
public override int GetHeight(float scale) => _main.GetHeight(scale);
|
||||
public override int GetDescent(float scale) => _main.GetDescent(scale);
|
||||
public override int GetLineHeight(float scale) => _main.GetLineHeight(scale);
|
||||
|
||||
// DrawChar just proxies to the stack, or invokes _main's fallback.
|
||||
public override float DrawChar(DrawingHandleScreen handle, Rune rune, Vector2 baseline, float scale, Color color, bool fallback=true)
|
||||
{
|
||||
foreach (var f in Stack)
|
||||
{
|
||||
var w = f.DrawChar(handle, rune, baseline, scale, color, fallback: false);
|
||||
if (w != 0f)
|
||||
return w;
|
||||
}
|
||||
|
||||
if (fallback)
|
||||
return _main.DrawChar(handle, rune, baseline, scale, color, fallback: true);
|
||||
|
||||
return 0f;
|
||||
}
|
||||
|
||||
public override CharMetrics? GetCharMetrics(Rune rune, float scale, bool fallback=true)
|
||||
{
|
||||
foreach (var f in Stack)
|
||||
{
|
||||
var m = f.GetCharMetrics(rune, scale, fallback: false);
|
||||
if (m != null)
|
||||
return m;
|
||||
}
|
||||
|
||||
if (!Rune.IsWhiteSpace(rune) && fallback)
|
||||
return _main.GetCharMetrics(rune, scale, fallback: true);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class DummyFont : Font
|
||||
{
|
||||
public override int GetAscent(float scale) => default;
|
||||
|
||||
@@ -84,7 +84,8 @@ namespace Robust.Client.Graphics
|
||||
IViewportControl? vpControl,
|
||||
IClydeViewport vp,
|
||||
in UIBox2i screenBox,
|
||||
in Box2 worldBox)
|
||||
in Box2 worldBox,
|
||||
in Box2Rotated worldBounds)
|
||||
{
|
||||
DrawingHandleBase handle;
|
||||
if (currentSpace == OverlaySpace.ScreenSpace || currentSpace == OverlaySpace.ScreenSpaceBelowWorld)
|
||||
@@ -97,7 +98,7 @@ namespace Robust.Client.Graphics
|
||||
handle = renderHandle.DrawingHandleWorld;
|
||||
}
|
||||
|
||||
var args = new OverlayDrawArgs(currentSpace, vpControl, vp, handle, screenBox, worldBox);
|
||||
var args = new OverlayDrawArgs(currentSpace, vpControl, vp, handle, screenBox, worldBox, worldBounds);
|
||||
|
||||
Draw(args);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,12 @@ namespace Robust.Client.Graphics
|
||||
/// <summary>
|
||||
/// AABB enclosing the area visible in the viewport.
|
||||
/// </summary>
|
||||
public readonly Box2 WorldBounds;
|
||||
public readonly Box2 WorldAABB;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="Box2Rotated"/> of the area visible in the viewport.
|
||||
/// </summary>
|
||||
public readonly Box2Rotated WorldBounds;
|
||||
|
||||
public DrawingHandleScreen ScreenHandle => (DrawingHandleScreen) DrawingHandle;
|
||||
public DrawingHandleWorld WorldHandle => (DrawingHandleWorld) DrawingHandle;
|
||||
@@ -52,13 +57,15 @@ namespace Robust.Client.Graphics
|
||||
IClydeViewport viewport,
|
||||
DrawingHandleBase drawingHandle,
|
||||
in UIBox2i viewportBounds,
|
||||
in Box2 worldBounds)
|
||||
in Box2 worldAabb,
|
||||
in Box2Rotated worldBounds)
|
||||
{
|
||||
Space = space;
|
||||
ViewportControl = viewportControl;
|
||||
Viewport = viewport;
|
||||
DrawingHandle = drawingHandle;
|
||||
ViewportBounds = viewportBounds;
|
||||
WorldAABB = worldAabb;
|
||||
WorldBounds = worldBounds;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,13 +24,14 @@ namespace Robust.Client.Graphics
|
||||
// 2D array for the texture to use for each animation frame at each direction.
|
||||
public readonly Texture[][] Icons;
|
||||
|
||||
internal State(Vector2i size, StateId stateId, DirectionType direction, float[] delays, Texture[][] icons)
|
||||
internal State(Vector2i size, RSI rsi, StateId stateId, DirectionType direction, float[] delays, Texture[][] icons)
|
||||
{
|
||||
DebugTools.Assert(size.X > 0);
|
||||
DebugTools.Assert(size.Y > 0);
|
||||
DebugTools.Assert(stateId.IsValid);
|
||||
|
||||
Size = size;
|
||||
RSI = rsi;
|
||||
StateId = stateId;
|
||||
Directions = direction;
|
||||
Delays = delays;
|
||||
@@ -47,6 +48,11 @@ namespace Robust.Client.Graphics
|
||||
/// </summary>
|
||||
public Vector2i Size { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The source RSI of this state.
|
||||
/// </summary>
|
||||
public RSI RSI { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The identifier for this state inside an RSI.
|
||||
/// </summary>
|
||||
|
||||
@@ -60,6 +60,7 @@ namespace Robust.Client.Input
|
||||
common.AddFunction(EngineKeyFunctions.TextReleaseFocus);
|
||||
common.AddFunction(EngineKeyFunctions.TextScrollToBottom);
|
||||
common.AddFunction(EngineKeyFunctions.TextDelete);
|
||||
common.AddFunction(EngineKeyFunctions.TextTabComplete);
|
||||
|
||||
var editor = contexts.New("editor", common);
|
||||
editor.AddFunction(EngineKeyFunctions.EditorLinePlace);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Robust.Client.Placement
|
||||
@@ -12,6 +13,16 @@ namespace Robust.Client.Placement
|
||||
PlacementMode? CurrentMode { get; set; }
|
||||
PlacementInformation? CurrentPermission { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The direction to spawn the entity in (presently exposed for EntitySpawnWindow UI)
|
||||
/// </summary>
|
||||
Direction Direction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets called when Direction changed (presently for EntitySpawnWindow UI)
|
||||
/// </summary>
|
||||
event EventHandler DirectionChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Gets called when the PlacementManager changed its build/erase mode or when the hijacks changed
|
||||
/// </summary>
|
||||
|
||||
@@ -95,9 +95,21 @@ namespace Robust.Client.Placement
|
||||
private ShaderInstance? _drawingShader { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The texture we use to show from our placement manager to represent the entity to place
|
||||
/// The entity for placement overlay.
|
||||
/// Colour of this gets swapped around in PlacementMode.
|
||||
/// This entity needs to stay in nullspace.
|
||||
/// </summary>
|
||||
public List<IDirectionalTextureProvider>? CurrentTextures { get; set; }
|
||||
public IEntity? CurrentPlacementOverlayEntity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A BAD way to explicitly control the icons used!!!
|
||||
/// Need to fix Content for this
|
||||
/// </summary>
|
||||
public List<IDirectionalTextureProvider>? CurrentTextures {
|
||||
set {
|
||||
PreparePlacementTexList(value, value != null);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Which of the placement orientations we are trying to place with
|
||||
@@ -143,10 +155,21 @@ namespace Robust.Client.Placement
|
||||
set => _colliderAABB = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The directional to spawn the entity in
|
||||
/// </summary>
|
||||
public Direction Direction { get; set; } = Direction.South;
|
||||
private Direction _direction = Direction.South;
|
||||
|
||||
/// <inheritdoc />
|
||||
public Direction Direction
|
||||
{
|
||||
get => _direction;
|
||||
set
|
||||
{
|
||||
_direction = value;
|
||||
DirectionChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler? DirectionChanged;
|
||||
|
||||
private PlacementOverlay _drawOverlay = default!;
|
||||
private bool _isActive;
|
||||
@@ -319,7 +342,7 @@ namespace Robust.Client.Placement
|
||||
{
|
||||
PlacementChanged?.Invoke(this, EventArgs.Empty);
|
||||
Hijack = null;
|
||||
CurrentTextures = null;
|
||||
EnsureNoPlacementOverlayEntity();
|
||||
CurrentPrototype = null;
|
||||
CurrentPermission = null;
|
||||
CurrentMode = null;
|
||||
@@ -351,8 +374,6 @@ namespace Robust.Client.Placement
|
||||
Direction = Direction.North;
|
||||
break;
|
||||
}
|
||||
|
||||
CurrentMode?.SetSprite();
|
||||
}
|
||||
|
||||
public void HandlePlacement()
|
||||
@@ -636,21 +657,64 @@ namespace Robust.Client.Placement
|
||||
BeginPlacing(CurrentPermission);
|
||||
}
|
||||
|
||||
private void EnsureNoPlacementOverlayEntity()
|
||||
{
|
||||
if (CurrentPlacementOverlayEntity != null)
|
||||
{
|
||||
if (!CurrentPlacementOverlayEntity.Deleted)
|
||||
CurrentPlacementOverlayEntity.Delete();
|
||||
CurrentPlacementOverlayEntity = null;
|
||||
}
|
||||
}
|
||||
|
||||
private SpriteComponent SetupPlacementOverlayEntity()
|
||||
{
|
||||
EnsureNoPlacementOverlayEntity();
|
||||
CurrentPlacementOverlayEntity = EntityManager.SpawnEntity(null, MapCoordinates.Nullspace);
|
||||
return CurrentPlacementOverlayEntity.EnsureComponent<SpriteComponent>();
|
||||
}
|
||||
|
||||
private void PreparePlacement(string templateName)
|
||||
{
|
||||
var prototype = _prototypeManager.Index<EntityPrototype>(templateName);
|
||||
|
||||
CurrentTextures = SpriteComponent.GetPrototypeTextures(prototype, ResourceCache).ToList();
|
||||
CurrentPrototype = prototype;
|
||||
|
||||
IsActive = true;
|
||||
|
||||
var lst = SpriteComponent.GetPrototypeTextures(prototype, ResourceCache, out var noRot).ToList();
|
||||
PreparePlacementTexList(lst, noRot);
|
||||
}
|
||||
|
||||
public void PreparePlacementTexList(List<IDirectionalTextureProvider>? texs, bool noRot)
|
||||
{
|
||||
var sc = SetupPlacementOverlayEntity();
|
||||
if (texs != null)
|
||||
{
|
||||
// This one covers most cases (including Construction)
|
||||
foreach (var v in texs)
|
||||
{
|
||||
if (v is RSI.State)
|
||||
{
|
||||
var st = (RSI.State) v;
|
||||
sc.AddLayer(st.StateId, st.RSI);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback
|
||||
sc.AddLayer(v.Default);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sc.AddLayer(new ResourcePath("/Textures/UserInterface/tilebuildoverlay.png"));
|
||||
}
|
||||
sc.NoRotation = noRot;
|
||||
}
|
||||
|
||||
private void PreparePlacementTile()
|
||||
{
|
||||
CurrentTextures = new List<IDirectionalTextureProvider>
|
||||
{ResourceCache
|
||||
.GetResource<TextureResource>(new ResourcePath("/Textures/UserInterface/tilebuildoverlay.png")).Texture};
|
||||
var sc = SetupPlacementOverlayEntity();
|
||||
sc.AddLayer(new ResourcePath("/Textures/UserInterface/tilebuildoverlay.png"));
|
||||
|
||||
IsActive = true;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
@@ -85,14 +86,10 @@ namespace Robust.Client.Placement
|
||||
|
||||
public virtual void Render(DrawingHandleWorld handle)
|
||||
{
|
||||
if (TexturesToDraw == null)
|
||||
{
|
||||
SetSprite();
|
||||
DebugTools.AssertNotNull(TexturesToDraw);
|
||||
}
|
||||
|
||||
if (TexturesToDraw == null || TexturesToDraw.Count == 0)
|
||||
var sce = pManager.CurrentPlacementOverlayEntity;
|
||||
if (sce == null || sce.Deleted)
|
||||
return;
|
||||
var sc = sce.GetComponent<SpriteComponent>();
|
||||
|
||||
IEnumerable<EntityCoordinates> locationcollection;
|
||||
switch (pManager.PlacementType)
|
||||
@@ -111,17 +108,17 @@ namespace Robust.Client.Placement
|
||||
break;
|
||||
}
|
||||
|
||||
var size = TexturesToDraw[0].Size;
|
||||
var dirAng = pManager.Direction.ToAngle();
|
||||
foreach (var coordinate in locationcollection)
|
||||
{
|
||||
if (!coordinate.IsValid(pManager.EntityManager))
|
||||
return; // Just some paranoia just in case
|
||||
var entity = coordinate.GetEntity(pManager.EntityManager);
|
||||
var worldPos = coordinate.ToMapPos(pManager.EntityManager);
|
||||
var pos = worldPos - (size/(float)EyeManager.PixelsPerMeter) / 2f;
|
||||
var color = IsValidPosition(coordinate) ? ValidPlaceColor : InvalidPlaceColor;
|
||||
var worldRot = entity.Transform.WorldRotation + dirAng;
|
||||
|
||||
foreach (var texture in TexturesToDraw)
|
||||
{
|
||||
handle.DrawTexture(texture, pos, color);
|
||||
}
|
||||
sc.Color = IsValidPosition(coordinate) ? ValidPlaceColor : InvalidPlaceColor;
|
||||
sc.Render(handle, pManager.eyeManager.CurrentEye.Rotation, worldRot, worldPos);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,14 +190,6 @@ namespace Robust.Client.Placement
|
||||
return pManager.ResourceCache.TryGetResource(new ResourcePath(@"/Textures/") / key, out sprite);
|
||||
}
|
||||
|
||||
public void SetSprite()
|
||||
{
|
||||
if (pManager.CurrentTextures == null)
|
||||
return;
|
||||
|
||||
TexturesToDraw = pManager.CurrentTextures.Select(o => o.TextureFor(pManager.Direction)).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the player is spawning within a certain range of his character if range is required on this mode
|
||||
/// </summary>
|
||||
@@ -233,7 +222,7 @@ namespace Robust.Client.Placement
|
||||
bounds.Width,
|
||||
bounds.Height);
|
||||
|
||||
return EntitySystem.Get<SharedBroadphaseSystem>().TryCollideRect(collisionBox, mapCoords.MapId);
|
||||
return EntitySystem.Get<SharedPhysicsSystem>().TryCollideRect(collisionBox, mapCoords.MapId);
|
||||
}
|
||||
|
||||
protected Vector2 ScreenToWorld(Vector2 point)
|
||||
|
||||
@@ -24,11 +24,13 @@ namespace Robust.Client.Player
|
||||
public event Action<EntityDetachedEventArgs>? EntityDetached;
|
||||
|
||||
/// <summary>
|
||||
/// Game entity that the local player is controlling. If this is null, the player
|
||||
/// is in free/spectator cam.
|
||||
/// Game entity that the local player is controlling. If this is null, the player is not attached to any
|
||||
/// entity at all.
|
||||
/// </summary>
|
||||
[ViewVariables] public IEntity? ControlledEntity { get; private set; }
|
||||
|
||||
[ViewVariables] public EntityUid? ControlledEntityUid => ControlledEntity?.Uid;
|
||||
|
||||
|
||||
[ViewVariables] public NetUserId UserId { get; set; }
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Robust.UnitTesting")]
|
||||
[assembly: InternalsVisibleTo("Robust.Client.CEF")]
|
||||
[assembly: InternalsVisibleTo("Robust.Client.WebView")]
|
||||
[assembly: InternalsVisibleTo("Robust.Lite")]
|
||||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
|
||||
[assembly: InternalsVisibleTo("Robust.Benchmarks")]
|
||||
|
||||
@@ -125,7 +125,7 @@ namespace Robust.Client.ResourceManagement
|
||||
reg.Indices = foldedIndices;
|
||||
reg.Offsets = callbackOffset;
|
||||
|
||||
var state = new RSI.State(frameSize, stateObject.StateId, stateObject.DirType, foldedDelays,
|
||||
var state = new RSI.State(frameSize, rsi, stateObject.StateId, stateObject.DirType, foldedDelays,
|
||||
textures);
|
||||
rsi.AddState(state);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<PackageReference Include="nfluidsynth" Version="0.3.1" />
|
||||
<PackageReference Include="NVorbis" Version="0.10.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.3" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.4" />
|
||||
<PackageReference Include="OpenToolkit.Graphics" Version="4.0.0-pre9.1" />
|
||||
<PackageReference Include="OpenToolkit.OpenAL" Version="4.0.0-pre9.1" />
|
||||
<PackageReference Include="SpaceWizards.SharpFont" Version="1.0.1" />
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Map;
|
||||
@@ -28,8 +27,8 @@ namespace Robust.Client.UserInterface
|
||||
|
||||
private bool _horizontalExpand;
|
||||
private bool _verticalExpand;
|
||||
private HAlignment _horizontalAlignment;
|
||||
private VAlignment _verticalAlignment;
|
||||
private HAlignment _horizontalAlignment = HAlignment.Stretch;
|
||||
private VAlignment _verticalAlignment = VAlignment.Stretch;
|
||||
private Thickness _margin;
|
||||
private bool _measuring;
|
||||
|
||||
@@ -225,80 +224,6 @@ namespace Robust.Client.UserInterface
|
||||
/// <seealso cref="Rect"/>
|
||||
public UIBox2i PixelRect => UIBox2i.FromDimensions(PixelPosition, PixelSize);
|
||||
|
||||
/// <summary>
|
||||
/// Horizontal size flags for container layout.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
[Obsolete("Use HorizontalAlignment and HorizontalExpand instead.")]
|
||||
public SizeFlags SizeFlagsHorizontal
|
||||
{
|
||||
get
|
||||
{
|
||||
var flags = HorizontalAlignment switch
|
||||
{
|
||||
HAlignment.Stretch => SizeFlags.Fill,
|
||||
HAlignment.Left => SizeFlags.None,
|
||||
HAlignment.Center => SizeFlags.ShrinkCenter,
|
||||
HAlignment.Right => SizeFlags.ShrinkEnd,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
|
||||
if (_horizontalExpand)
|
||||
flags |= SizeFlags.Expand;
|
||||
|
||||
return flags;
|
||||
}
|
||||
set
|
||||
{
|
||||
HorizontalExpand = (value & SizeFlags.Expand) != 0;
|
||||
HorizontalAlignment = (value & ~SizeFlags.Expand) switch
|
||||
{
|
||||
SizeFlags.None => HAlignment.Left,
|
||||
SizeFlags.Fill => HAlignment.Stretch,
|
||||
SizeFlags.ShrinkCenter => HAlignment.Center,
|
||||
SizeFlags.ShrinkEnd => HAlignment.Right,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Vertical size flags for container layout.
|
||||
/// </summary>
|
||||
[Obsolete("Use VerticalAlignment and VerticalExpand instead.")]
|
||||
[ViewVariables]
|
||||
public SizeFlags SizeFlagsVertical
|
||||
{
|
||||
get
|
||||
{
|
||||
var flags = _verticalAlignment switch
|
||||
{
|
||||
VAlignment.Stretch => SizeFlags.Fill,
|
||||
VAlignment.Top => SizeFlags.None,
|
||||
VAlignment.Center => SizeFlags.ShrinkCenter,
|
||||
VAlignment.Bottom => SizeFlags.ShrinkEnd,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
|
||||
if (_verticalExpand)
|
||||
flags |= SizeFlags.Expand;
|
||||
|
||||
return flags;
|
||||
}
|
||||
set
|
||||
{
|
||||
VerticalExpand = (value & SizeFlags.Expand) != 0;
|
||||
VerticalAlignment = (value & ~SizeFlags.Expand) switch
|
||||
{
|
||||
SizeFlags.None => VAlignment.Top,
|
||||
SizeFlags.Fill => VAlignment.Stretch,
|
||||
SizeFlags.ShrinkCenter => VAlignment.Center,
|
||||
SizeFlags.ShrinkEnd => VAlignment.Bottom,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Horizontal alignment mode.
|
||||
/// This determines how the control should be laid out horizontally
|
||||
@@ -788,46 +713,6 @@ namespace Robust.Client.UserInterface
|
||||
Math.Clamp(avail.Y, minH, maxH));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Controls how a control changes size when inside a container.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
[PublicAPI]
|
||||
[Obsolete("Use HAlignment/VAlignment/VerticalExpand/HorizontalExpand instead")]
|
||||
public enum SizeFlags : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// Shrink to the begin of the specified axis.
|
||||
/// </summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Fill as much space as possible in a container, without pushing others.
|
||||
/// </summary>
|
||||
Fill = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Fill as much space as possible in a container, pushing other nodes.
|
||||
/// The ratio of pushing if there's multiple set to expand is dependant on <see cref="SizeFlagsStretchRatio" />
|
||||
/// </summary>
|
||||
Expand = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Combination of <see cref="Fill" /> and <see cref="Expand" />.
|
||||
/// </summary>
|
||||
FillExpand = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Shrink inside a container, aligning to the center.
|
||||
/// </summary>
|
||||
ShrinkCenter = 4,
|
||||
|
||||
/// <summary>
|
||||
/// Shrink inside a container, aligning to the end.
|
||||
/// </summary>
|
||||
ShrinkEnd = 8,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies horizontal alignment modes.
|
||||
/// </summary>
|
||||
|
||||
@@ -40,6 +40,9 @@ namespace Robust.Client.UserInterface
|
||||
[ViewVariables]
|
||||
public string? Name { get; set; }
|
||||
|
||||
// ReSharper disable once ValueParameterNotUsed
|
||||
public AccessLevel? Access { set { } }
|
||||
|
||||
/// <summary>
|
||||
/// If true, this control will always be rendered, even if other UI rendering is disabled.
|
||||
/// </summary>
|
||||
|
||||
12
Robust.Client/UserInterface/ControlPropertyAccess.cs
Normal file
12
Robust.Client/UserInterface/ControlPropertyAccess.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace Robust.Client.UserInterface
|
||||
{
|
||||
public enum AccessLevel
|
||||
{
|
||||
Public,
|
||||
Protected,
|
||||
Internal,
|
||||
ProtectedInternal,
|
||||
Private,
|
||||
PrivateProtected,
|
||||
}
|
||||
}
|
||||
@@ -199,7 +199,7 @@ namespace Robust.Client.UserInterface.Controls
|
||||
{
|
||||
base.KeyBindDown(args);
|
||||
|
||||
if (Disabled || (!_enableAllKeybinds && args.Function != EngineKeyFunctions.UIClick))
|
||||
if (Disabled || args.Function == EngineKeyFunctions.Use || (!_enableAllKeybinds && args.Function != EngineKeyFunctions.UIClick))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -242,7 +242,7 @@ namespace Robust.Client.UserInterface.Controls
|
||||
{
|
||||
base.KeyBindUp(args);
|
||||
|
||||
if (Disabled || (!_enableAllKeybinds && args.Function != EngineKeyFunctions.UIClick))
|
||||
if (Disabled || args.Function == EngineKeyFunctions.Use || (!_enableAllKeybinds && args.Function != EngineKeyFunctions.UIClick))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ namespace Robust.Client.UserInterface.Controls
|
||||
public event Action<LineEditEventArgs>? OnTextEntered;
|
||||
public event Action<LineEditEventArgs>? OnFocusEnter;
|
||||
public event Action<LineEditEventArgs>? OnFocusExit;
|
||||
public event Action<LineEditEventArgs>? OnTabComplete;
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the LineEdit text gets changed by the input text.
|
||||
@@ -523,6 +524,15 @@ namespace Robust.Client.UserInterface.Controls
|
||||
args.Handle();
|
||||
return;
|
||||
}
|
||||
else if (args.Function == EngineKeyFunctions.TextTabComplete)
|
||||
{
|
||||
if (Editable)
|
||||
{
|
||||
OnTabComplete?.Invoke(new LineEditEventArgs(this, _text));
|
||||
}
|
||||
|
||||
args.Handle();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
94
Robust.Client/UserInterface/Controls/SliderIntInput.cs
Normal file
94
Robust.Client/UserInterface/Controls/SliderIntInput.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
|
||||
namespace Robust.Client.UserInterface.Controls
|
||||
{
|
||||
public class SliderIntInput : Control
|
||||
{
|
||||
private Slider _slider;
|
||||
private SpinBox _spinBox;
|
||||
|
||||
private int _value;
|
||||
|
||||
public int MinValue
|
||||
{
|
||||
get => (int) _slider.MinValue;
|
||||
set => _slider.MinValue = value;
|
||||
}
|
||||
|
||||
public int MaxValue
|
||||
{
|
||||
get => (int)_slider.MaxValue;
|
||||
set => _slider.MaxValue = value;
|
||||
}
|
||||
|
||||
public int Value
|
||||
{
|
||||
get => _value;
|
||||
set
|
||||
{
|
||||
if (_value == value)
|
||||
return;
|
||||
_value = value;
|
||||
|
||||
_slider.Value = value;
|
||||
_spinBox.Value = value;
|
||||
|
||||
OnValueChanged?.Invoke(_value);
|
||||
}
|
||||
}
|
||||
|
||||
public float DivisionRatio
|
||||
{
|
||||
get => _slider.SizeFlagsStretchRatio;
|
||||
set => _slider.SizeFlagsStretchRatio = value;
|
||||
}
|
||||
|
||||
public event Action<int>? OnValueChanged;
|
||||
|
||||
public SliderIntInput()
|
||||
{
|
||||
var hBox = new BoxContainer()
|
||||
{
|
||||
HorizontalExpand = true,
|
||||
Orientation = BoxContainer.LayoutOrientation.Horizontal
|
||||
};
|
||||
|
||||
// create slider
|
||||
_slider = new Slider
|
||||
{
|
||||
HorizontalExpand = true
|
||||
};
|
||||
_slider.OnValueChanged += OnSliderValueChanged;
|
||||
hBox.AddChild(_slider);
|
||||
|
||||
// and conected spin box
|
||||
_spinBox = new SpinBox
|
||||
{
|
||||
Value = Value,
|
||||
IsValid = ValidateSpinBox,
|
||||
HorizontalExpand = true,
|
||||
SizeFlagsStretchRatio = 0.3f,
|
||||
Margin = new Shared.Maths.Thickness(8, 0)
|
||||
};
|
||||
_spinBox.ValueChanged += OnSpinBoxChanged;
|
||||
hBox.AddChild(_spinBox);
|
||||
|
||||
AddChild(hBox);
|
||||
}
|
||||
|
||||
private void OnSliderValueChanged(Range slider)
|
||||
{
|
||||
Value = (int) slider.Value;
|
||||
}
|
||||
|
||||
private void OnSpinBoxChanged(object? sender, ValueChangedEventArgs e)
|
||||
{
|
||||
Value = e.Value;
|
||||
}
|
||||
|
||||
private bool ValidateSpinBox(int i)
|
||||
{
|
||||
return i >= MinValue && i <= MaxValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Maths;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -22,15 +22,17 @@ namespace Robust.Client.UserInterface.Controls
|
||||
/// </summary>
|
||||
public Func<int, bool>? IsValid { get; set; }
|
||||
|
||||
private int _value;
|
||||
public int Value
|
||||
{
|
||||
get => int.TryParse(_lineEdit.Text, out int i) ? i : 0;
|
||||
get => _value;
|
||||
set
|
||||
{
|
||||
if (IsValid != null && !IsValid(value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
_value = value;
|
||||
_lineEdit.Text = value.ToString();
|
||||
ValueChanged?.Invoke(this, new ValueChangedEventArgs(value));
|
||||
}
|
||||
@@ -67,6 +69,11 @@ namespace Robust.Client.UserInterface.Controls
|
||||
Value = 0;
|
||||
|
||||
_lineEdit.IsValid = (str) => int.TryParse(str, out var i) && (IsValid == null || IsValid(i));
|
||||
_lineEdit.OnTextChanged += (args) =>
|
||||
{
|
||||
if (int.TryParse(args.Text, out int i))
|
||||
Value = i;
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Robust.Client.UserInterface.Controls
|
||||
{
|
||||
@@ -48,6 +51,7 @@ namespace Robust.Client.UserInterface.Controls
|
||||
return;
|
||||
}
|
||||
|
||||
EntitySystem.Get<SpriteSystem>().ForceUpdate(Sprite);
|
||||
renderHandle.DrawEntity(Sprite.Owner, PixelSize / 2, Scale * UIScale, OverrideDirection);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,22 +130,29 @@ namespace Robust.Client.UserInterface.CustomControls
|
||||
var (left, top) = Position;
|
||||
var (right, bottom) = Position + SetSize;
|
||||
|
||||
if (float.IsNaN(SetSize.X)) {
|
||||
right = Position.X + Size.X;
|
||||
}
|
||||
if (float.IsNaN(SetSize.Y)) {
|
||||
bottom = Position.Y + Size.Y;
|
||||
}
|
||||
|
||||
if ((CurrentDrag & DragMode.Top) == DragMode.Top)
|
||||
{
|
||||
top = Math.Min(args.GlobalPosition.Y - DragOffsetTopLeft.Y, bottom);
|
||||
top = Math.Min(args.GlobalPosition.Y - DragOffsetTopLeft.Y, Math.Min(bottom, bottom - MinSize.Y));
|
||||
}
|
||||
else if ((CurrentDrag & DragMode.Bottom) == DragMode.Bottom)
|
||||
{
|
||||
bottom = Math.Max(args.GlobalPosition.Y + DragOffsetBottomRight.Y, top);
|
||||
bottom = Math.Max(args.GlobalPosition.Y + DragOffsetBottomRight.Y, Math.Max(top, top + MinSize.Y));
|
||||
}
|
||||
|
||||
if ((CurrentDrag & DragMode.Left) == DragMode.Left)
|
||||
{
|
||||
left = Math.Min(args.GlobalPosition.X - DragOffsetTopLeft.X, right);
|
||||
left = Math.Min(args.GlobalPosition.X - DragOffsetTopLeft.X, Math.Min(right, right - MinSize.X));
|
||||
}
|
||||
else if ((CurrentDrag & DragMode.Right) == DragMode.Right)
|
||||
{
|
||||
right = Math.Max(args.GlobalPosition.X + DragOffsetBottomRight.X, left);
|
||||
right = Math.Max(args.GlobalPosition.X + DragOffsetBottomRight.X, Math.Max(left, left + MinSize.X));
|
||||
}
|
||||
|
||||
var rect = new UIBox2(left, top, right, bottom);
|
||||
|
||||
@@ -8,6 +8,6 @@
|
||||
ContentMarginBottomOverride="3" ContentMarginTopOverride="3" />
|
||||
</OutputPanel.StyleBoxOverride>
|
||||
</OutputPanel>
|
||||
<HistoryLineEdit Name="CommandBar" PlaceHolder="{Loc 'console-line-edit-placeholder'}" />
|
||||
<HistoryLineEdit Name="CommandBar" Access="Public" PlaceHolder="{Loc 'console-line-edit-placeholder'}" />
|
||||
</BoxContainer>
|
||||
</Control>
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user