Skip to content

Commit

Permalink
Input code from Z with fixes to the input focus (#15)
Browse files Browse the repository at this point in the history
- Merged Z's input code which is based on the WinHook library
- Fixed input focus based on Terminal tab selection
- Allowed to have two separate browsers in Inventory and Control Panel
  • Loading branch information
viktor-ferenczi authored Oct 25, 2021
1 parent c2a3f9a commit 97b9ea9
Show file tree
Hide file tree
Showing 25 changed files with 603 additions and 290 deletions.
6 changes: 0 additions & 6 deletions EnhancedUI/Content/ControlPanel.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@
<body>

<div class="fullscreen">

<h1 class="show">CONTROL PANEL</h1>

<p>Browser size: <span id="window-size"></span> pixels</p>

<div id="blocks"></div>

</div>

</body>
Expand Down
83 changes: 78 additions & 5 deletions EnhancedUI/Content/ControlPanel.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var blockStates = null;

// Invoked from C#
// noinspection JSUnusedGlobalSymbols
async function stateUpdated() {
const blockViews = $('#blocks');
blockViews.empty();
Expand Down Expand Up @@ -48,40 +50,111 @@ function renderBlockProperty(parent, propertyState) {
let propertyView= $('<div />');
propertyView.addClass('property');

let cb, label;
let value = $('<div />');
value.addClass('value');
switch(propertyState.TypeName) {
case "Boolean":
cb = $('<input />')
cb.attr('type', 'checkbox');
cb.attr('id', propertyState.Id);
cb.attr('type', 'checkbox');
if (propertyState.Value) {
cb.attr('checked', 'checked');
}
value.append(cb);

label = $('<label />');
label.attr('for', propertyState.Id);
label.text(propertyState.Id);
value.append(label);

break;

case "Int64":
value.text(propertyState.Id + ': ' + propertyState.Value.toString());
label = $('<label />');
label.attr('for', propertyState.Id);
label.text(propertyState.Id);
value.append(label);

cb = $('<input />')
cb.attr('id', propertyState.Id);
cb.attr('type', 'number');
cb.attr('value', propertyState.Value == null ? '0' : propertyState.Value.toString());
cb.attr('maxlength', '20');
cb.attr('size', '20');
value.append(cb);

break;

case "Single":
value.text(propertyState.Id + ': ' + propertyState.Value.toString());
label = $('<label />');
label.attr('for', propertyState.Id);
label.text(propertyState.Id);
value.append(label);

cb = $('<input />')
cb.attr('id', propertyState.Id);
cb.attr('type', 'number');
cb.attr('value', propertyState.Value == null ? '0.0' : propertyState.Value.toString());
cb.attr('maxlength', '20');
cb.attr('size', '20');
value.append(cb);

break;

case "StringBuilder":
label = $('<label />');
label.attr('for', propertyState.Id);
label.text(propertyState.Id);
value.append(label);

cb = $('<input />')
cb.attr('id', propertyState.Id);
cb.attr('value', propertyState.Value == null ? '' : propertyState.Value.toString());
cb.attr('maxlength', '65535');
cb.attr('size', '100');
value.append(cb);

break;

case "Color":
value.text(propertyState.Id + ': ' + propertyState.Value.toString());
// See https://bitbucket.org/chromiumembedded/cef/issues/899

label = $('<label />');
label.attr('for', propertyState.Id);
label.text(propertyState.Id);
value.append(label);

cb = $('<input />')
cb.attr('id', propertyState.Id);
cb.attr('type', 'color');
cb.attr('value', propertyState.Value == null ? '#ffffff' : propertyState.Value.toString());
value.append(cb);

break;

default:
value.text(propertyState.Id + ' ' + propertyState.TypeName + ': ' + (propertyState.Value == null ? 'null' : propertyState.Value.toString()));
label = $('<label />');
label.attr('for', propertyState.Id);
label.text(propertyState.Id + '[' + propertyState.TypeName + '] ');
value.append(label);

cb = $('<input />')
cb.attr('readonly', 'readonly');
cb.attr('id', propertyState.Id);
cb.attr('value', propertyState.Value == null ? '' : propertyState.Value.toString());
value.append(cb);

break;
}

propertyView.append(value);

parent.append(propertyView);
}

// Invoked from C#
// noinspection JSUnusedGlobalSymbols
async function blockStateUpdated(entityId) {
// let blockState = await state.GetBlockState(entityId);
// let blockView = $('#block-' + entityId);
Expand Down
2 changes: 1 addition & 1 deletion EnhancedUI/Content/Inventory.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<h1 class="show">INVENTORY</h1>

<p>Browser size: <span id="window-size"></span> pixels</p>
<p><input value="Test" /></p>

</div>

Expand Down
7 changes: 7 additions & 0 deletions EnhancedUI/Content/Inventory.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
// Invoked from C#
// noinspection JSUnusedGlobalSymbols
async function stateUpdated() {
}

// Invoked from C#
// noinspection JSUnusedGlobalSymbols
async function blockStateUpdated(entityId) {
}
13 changes: 10 additions & 3 deletions EnhancedUI/Content/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ html {
background: transparent url("checkerboard.png");
font-family: SpaceEngineers, serif;
color: lightcyan;
font-size: 1.5vw;
line-height: 1.6vw;
}

body {
overflow: hidden;
overflow-x: hidden;
}

.fullscreen {
Expand All @@ -28,8 +30,13 @@ body {
display: none;
}

label {
padding-left: 0.5ch;
label,
input[type="checkbox"] {
margin-right: 0.5ch;
}

label:hover {
text-decoration: underline;
}

.block {
Expand Down
5 changes: 3 additions & 2 deletions EnhancedUI/Content/common.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
$(document).ready(async function () {
// For debugging only
// $("#window-size").text(`${window.innerWidth}x${window.innerHeight}`);

await CefSharp.BindObjectAsync("state");
state.NotifyBound();

$("#window-size").text(`${window.innerWidth}x${window.innerHeight}`);
});
8 changes: 4 additions & 4 deletions EnhancedUI/EnhancedUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<Nullable>enable</Nullable>
<OutputPath>bin\</OutputPath>
<PlatformTarget>x64</PlatformTarget>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>full</DebugType>
Expand All @@ -14,10 +15,6 @@
</PropertyGroup>

<ItemGroup>
<Reference Include="EmptyKeys.UserInterface, Version=3.2.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>$(SolutionDir)GameBinaries\EmptyKeys.UserInterface.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Sandbox.Common, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(SolutionDir)GameBinaries\Sandbox.Common.dll</HintPath>
Expand Down Expand Up @@ -58,6 +55,7 @@
<Private>False</Private>
</Reference>
<Reference Include="System.Web" />
<Reference Include="System.Windows.Forms" />
<Reference Include="VRage, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(SolutionDir)GameBinaries\VRage.dll</HintPath>
Expand Down Expand Up @@ -122,6 +120,8 @@
<PackageReference Include="CefSharp.Common" Version="93.1.140" />
<PackageReference Include="CefSharp.OffScreen" Version="93.1.140" />
<PackageReference Include="Lib.Harmony" Version="2.1.1" />
<PackageReference Include="WinHook" Version="0.1.1" />
<PackageReference Include="Winook" Version="1.3.2" />
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
Expand Down
3 changes: 3 additions & 0 deletions EnhancedUI/Gui/Chromium.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Runtime.InteropServices;
using CefSharp;
using CefSharp.OffScreen;
using VRage.Utils;
using VRageMath;

namespace EnhancedUI.Gui
Expand All @@ -25,6 +26,8 @@ public Chromium(Vector2I size, object state)
LifeSpanHandler = new LifespanHandler()
};

Browser.MenuHandler = new CustomMenuHandler();

Browser.Paint += BrowserOnPaint;
Browser.BrowserInitialized += BrowserOnBrowserInitialized;

Expand Down
Loading

0 comments on commit 97b9ea9

Please sign in to comment.