This commit is contained in:
CortexCore
2023-11-30 00:27:34 +08:00
parent 7712c80804
commit 337840ebb3
30 changed files with 787 additions and 62 deletions

View File

@@ -7,8 +7,8 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace BITKit.Apps;
public partial class GodotBasedApplicationService:EntityComponent, IApplicationService
[CustomType(typeof(IApplicationService))]
public partial class GodotBasedApplicationService:EntityBehaviour, IApplicationService
{
private static readonly System.Net.Http.HttpClient _httpClient = new();
[Export] public string DownloadLatestUrl { get; set; }
@@ -21,20 +21,14 @@ public partial class GodotBasedApplicationService:EntityComponent, IApplicationS
public event Action<string> OnDownloadComplete;
public event Action OnDetectedLatestVersion;
private ILogger<IApplicationService> _logger;
public override void BuildService(IServiceCollection serviceCollection)
{
serviceCollection.AddSingleton<IApplicationService>(this);
}
public override async void OnStart()
{
_logger = Entity.ServiceProvider.GetRequiredService<ILogger<IApplicationService>>();
BIT4Log.Log<IApplicationService>("正在初始化...");
var clientVersion = ProjectSettings.GetSetting("application/config/version").AsString();
_logger.LogInformation($"当前版本:{clientVersion}");
BIT4Log.Log<IApplicationService>($"当前版本:{clientVersion}");
OnClientVersionCheck?.Invoke(clientVersion);
@@ -52,7 +46,7 @@ public partial class GodotBasedApplicationService:EntityComponent, IApplicationS
OnDetectedLatestVersion?.Invoke();
}
_logger.LogInformation($"最新版本:{version}");
BIT4Log.Log<IApplicationService>($"最新版本:{version}");
}
public UniTask<string> DownloadLatestVersionAsync()

View File

@@ -12,7 +12,7 @@ public partial class FreeLookCamera : Node3D,IVirtualCamera
[Export]
private Curve wheelCurve;
[Export(PropertyHint.Range,"0.32,8")]
[Export(PropertyHint.Range,"0.32,64")]
private float distance;
[Export] private float maxDistance;

View File

@@ -84,5 +84,10 @@ public partial class BITAppForGodot : Node
public override void _Process(double delta)
{
DeltaTime =(float) delta;
// var scale = DisplayServer.WindowGetSize().X / 1920f;
// //GetViewport().Scaling3DScale = scale;
//
// //ProjectSettings.SetSetting("display/window/stretch/scale", scale);
}
}

View File

@@ -0,0 +1,67 @@
using Godot;
using System;
using System.Collections.Generic;
using System.Linq;
namespace BITKit.StateMachine
{
public abstract partial class StateMachineNode<T> : Node ,IStateMachine<T> where T : class, IState
{
public bool Enabled { get; set; }
public T CurrentState { get; set; }
public event Action<T, T> OnStateChanged;
public IDictionary<Type, T> StateDictionary { get; } = new Dictionary<Type, T>();
public void Initialize()
{
foreach (var x in StateDictionary)
{
x.Value.Initialize();
}
}
public void UpdateState(float deltaTime)
{
CurrentState?.OnStateUpdate(deltaTime);
}
public void DisposeState()
{
CurrentState?.OnStateExit(CurrentState,null);
CurrentState = null;
}
public void TransitionState<State>() where State : T
{
TransitionState(StateDictionary[typeof(State)]);
}
public void TransitionState(T state)
{
CurrentState?.OnStateExit(CurrentState, state);
var previousState = CurrentState;
CurrentState = state;
state.OnStateEntry(previousState);
OnStateChanged?.Invoke(previousState, CurrentState);
CurrentState = state;
}
public override void _Ready()
{
base._Ready();
foreach (var x in MathNode.GetAllNode(this).OfType<T>())
{
StateDictionary.Add(x.GetType(), x);
}
Initialize();
if (StateDictionary.Count > 0)
TransitionState(StateDictionary.First().Value);
}
public override void _Process(double delta)
{
base._Process(delta);
CurrentState?.OnStateUpdate((float)delta);
}
}
}

View File

@@ -0,0 +1,24 @@
using Godot;
using System;
namespace BITKit.StateMachine;
public partial class StateNode : Node, IState
{
public virtual bool Enabled { get; set; }
public virtual void Initialize()
{
}
public virtual void OnStateEntry(IState old)
{
}
public virtual void OnStateUpdate(float deltaTime)
{
}
public virtual void OnStateExit(IState old, IState newState)
{
}
}

View File

@@ -5,18 +5,16 @@ using Microsoft.Extensions.DependencyInjection;
namespace BITKit;
public partial class UXApplicationService : EntityComponent
public partial class UXApplicationService : EntityBehaviour
{
[Export] private Label currentVersionLabel;
[Export] private Label latestVersionLabel;
[Export] private Button downloadLatestButton;
[Inject]
private IApplicationService _service;
public override void OnAwake()
{
_service = Entity.ServiceProvider.GetRequiredService<IApplicationService>();
downloadLatestButton.Hide();
downloadLatestButton.Pressed += () =>

View File

@@ -1,5 +1,6 @@
using Godot;
using System;
using Cysharp.Threading.Tasks;
namespace BITKit.UX;
@@ -17,17 +18,39 @@ public partial class UXPanel : Control, IUXPanel
public bool AllowInput => allowInput;
private string _index;
public bool IsEntered { get; set; }
public virtual void Entry()
{
Show();
//OnEntry();
}
public UniTask EntryAsync()
{
return UniTask.CompletedTask;
}
public void Entered()
{
}
public virtual void Exit()
{
Hide();
//OnExit();
}
public UniTask ExitAsync()
{
return UniTask.CompletedTask;
}
public void Exited()
{
}
public event Action OnEntry;
public event Action OnExit;
@@ -55,4 +78,9 @@ public partial class UXPanel : Control, IUXPanel
UXService.UnRegister(this);
IsValid = false;
}
public void OnUpdate(float deltaTime)
{
throw new NotImplementedException();
}
}

View File

@@ -13,6 +13,6 @@ public partial class UXProfiler : Node
if (fpsLabel is not null)
fpsLabel.Text = $"FPS: {Engine.GetFramesPerSecond()}";
if (resolutionLabel is not null)
resolutionLabel.Text = $"Resolution: {windowSize.X}x{windowSize.Y}";
resolutionLabel.Text = $"{windowSize.X}x{windowSize.Y}";
}
}

View File

@@ -0,0 +1,36 @@
using Godot;
using System;
namespace BITKit.UX.Settings;
public partial class UXSettings : Node
{
[Export] private Slider uiScaleSlider;
[Export] private Slider renderResolutionSlider;
[Export] private CheckBox fullScreenCheckBox;
public override void _Ready()
{
base._Ready();
uiScaleSlider.ValueChanged += SetUIScale;
renderResolutionSlider.ValueChanged += SetRenderResolution;
fullScreenCheckBox.Toggled += SetFullScreen;
}
private void SetFullScreen(bool toggledon)
{
DisplayServer.WindowSetMode(toggledon ? DisplayServer.WindowMode.Fullscreen:DisplayServer.WindowMode.Minimized);
BIT4Log.Log<UXSettings>($"设置全屏为{toggledon}");
}
public void SetUIScale(double scale)
{
//GetViewport().Scaling3DScale =(float) scale;
BIT4Log.Log<UXSettings>($"设置UI缩放比例为{scale}");
}
public void SetRenderResolution(double scale)
{
GetViewport().Scaling3DScale = (float)scale;
BIT4Log.Log<UXSettings>($"设置渲染分辨率比例为{scale}");
}
}

View File

@@ -18,6 +18,8 @@ public partial class HttpGet : Node,IActivable
public bool Enabled { get; set; } = true;
[Signal]
public delegate void OnGetEventHandler(string httpContext);
[Signal]
public delegate void OnExceptionEventHandler(string exception);
/// <summary>
/// 请求数据的间隔
/// </summary>
@@ -73,6 +75,10 @@ public partial class HttpGet : Node,IActivable
catch (OperationCanceledException)
{
}
catch (Exception e)
{
EmitSignal(nameof(OnException), e.Message);
}
allowNextRequest = true;
}