Skip to content

Commit

Permalink
Object value (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor-ferenczi authored Oct 19, 2021
1 parent 3f20e06 commit c2a3f9a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.
11 changes: 7 additions & 4 deletions EnhancedUI/Content/ControlPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function renderBlockProperty(parent, propertyState) {
cb = $('<input />')
cb.attr('type', 'checkbox');
cb.attr('id', propertyState.Id);
if (propertyState.BoolValue) {
if (propertyState.Value) {
cb.attr('checked', 'checked');
}
value.append(cb);
Expand All @@ -65,13 +65,16 @@ function renderBlockProperty(parent, propertyState) {
value.append(label);
break;
case "Int64":
value.text(propertyState.Id + ': ' + propertyState.LongValue.toString());
value.text(propertyState.Id + ': ' + propertyState.Value.toString());
break;
case "Single":
value.text(propertyState.Id + ': ' + propertyState.FloatValue.toString());
value.text(propertyState.Id + ': ' + propertyState.Value.toString());
break;
case "Color":
value.text(propertyState.Id + ': ' + propertyState.Value.toString());
break;
default:
value.text(propertyState.Id + ' ' + propertyState.TypeName + ': ' + propertyState.BoolValue.toString() + " | " + propertyState.LongValue.toString() + " | " + propertyState.FloatValue.toString());
value.text(propertyState.Id + ' ' + propertyState.TypeName + ': ' + (propertyState.Value == null ? 'null' : propertyState.Value.toString()));
}

propertyView.append(value);
Expand Down
2 changes: 1 addition & 1 deletion EnhancedUI/Content/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ html {
}

body {
/*overflow: hidden;*/
overflow: hidden;
}

.fullscreen {
Expand Down
41 changes: 17 additions & 24 deletions EnhancedUI/Gui/Terminal/ControlPanel/BlockState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Collections.Generic;
using Sandbox.Game.Entities.Cube;
using Sandbox.ModAPI.Interfaces;
using SharpDX;
using VRageMath;

namespace EnhancedUI.Gui.Terminal.ControlPanel
{
Expand Down Expand Up @@ -53,40 +55,31 @@ public class BlockPropertyState
{
public readonly string Id;
public readonly string TypeName;

public readonly bool BoolValue;
public readonly long LongValue;
public readonly float FloatValue;
// public readonly Color ColorValue;
public object? Value;

public BlockPropertyState(MyTerminalBlock block, ITerminalProperty property)
{
Id = property.Id;
TypeName = property.TypeName;

var asBool = property.AsBool();
if (asBool != null)
switch (property.TypeName)
{
BoolValue = asBool.GetValue(block);
}
case "Boolean":
Value = property.AsBool().GetValue(block);
break;

var asLong = property.As<Int64>();
if (asLong != null)
{
LongValue = asLong.GetValue(block);
}
case "Single":
Value = property.AsFloat().GetValue(block);
break;

var asFloat = property.AsFloat();
if (asFloat != null)
{
FloatValue = asFloat.GetValue(block);
}
case "Int64":
Value = property.As<Int64>().GetValue(block);
break;

// var asColor = property.AsColor();
// if (asColor != null)
// {
// ColorValue = asColor.GetValue(block);
// }
case "Color":
Value = property.As<Color>().GetValue(block).ToString();
break;
}
}
}
}

0 comments on commit c2a3f9a

Please sign in to comment.