2019-07-03 09:44:53 +02:00
|
|
|
using System;
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
using Godot;
|
2021-09-12 20:21:15 +02:00
|
|
|
using Godot.NativeInterop;
|
2019-07-03 09:44:53 +02:00
|
|
|
|
|
|
|
namespace GodotTools.Internals
|
|
|
|
{
|
|
|
|
public class EditorProgress : IDisposable
|
|
|
|
{
|
|
|
|
public string Task { get; }
|
|
|
|
|
|
|
|
public EditorProgress(string task, string label, int amount, bool canCancel = false)
|
|
|
|
{
|
|
|
|
Task = task;
|
2021-09-12 20:21:15 +02:00
|
|
|
using godot_string taskIn = Marshaling.mono_string_to_godot(task);
|
|
|
|
using godot_string labelIn = Marshaling.mono_string_to_godot(label);
|
2021-09-12 20:23:05 +02:00
|
|
|
Internal.godot_icall_EditorProgress_Create(taskIn, labelIn, amount, canCancel);
|
2019-07-03 09:44:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
~EditorProgress()
|
|
|
|
{
|
|
|
|
// Should never rely on the GC to dispose EditorProgress.
|
|
|
|
// It should be disposed immediately when the task finishes.
|
|
|
|
GD.PushError("EditorProgress disposed by the Garbage Collector");
|
|
|
|
Dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
2021-09-12 20:21:15 +02:00
|
|
|
using godot_string taskIn = Marshaling.mono_string_to_godot(Task);
|
2021-09-12 20:23:05 +02:00
|
|
|
Internal.godot_icall_EditorProgress_Dispose(taskIn);
|
2019-07-03 09:44:53 +02:00
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Step(string state, int step = -1, bool forceRefresh = true)
|
|
|
|
{
|
2021-09-12 20:21:15 +02:00
|
|
|
using godot_string taskIn = Marshaling.mono_string_to_godot(Task);
|
|
|
|
using godot_string stateIn = Marshaling.mono_string_to_godot(state);
|
2021-09-12 20:23:05 +02:00
|
|
|
Internal.godot_icall_EditorProgress_Step(taskIn, stateIn, step, forceRefresh);
|
2019-07-03 09:44:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool TryStep(string state, int step = -1, bool forceRefresh = true)
|
|
|
|
{
|
2021-09-12 20:21:15 +02:00
|
|
|
using godot_string taskIn = Marshaling.mono_string_to_godot(Task);
|
|
|
|
using godot_string stateIn = Marshaling.mono_string_to_godot(state);
|
2021-09-12 20:23:05 +02:00
|
|
|
return Internal.godot_icall_EditorProgress_Step(taskIn, stateIn, step, forceRefresh);
|
2019-07-03 09:44:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|