Editor command class that toggles an offsets editor UI for the local player's active weapon. It opens the OffsetEditor UI and sets the weapon viewmodel into editor mode, or closes and cleans up the editor and restores mode.
using SWB.Base;
using SWB.Player;
namespace SWB.Editor;
internal class Commands
{
static OffsetEditor offsetEditor;
[ConCmd( "swb_editor_offsets", Help = "Opens the offsets editor" )]
public static void OpenOffsetsEditor()
{
var player = PlayerBase.Local;
var weaponGO = player.Inventory.Active;
var weapon = weaponGO.Components.Get<Weapon>();
if ( offsetEditor is not null )
{
offsetEditor.Delete();
offsetEditor = null;
if ( weapon.ViewModelHandler is not null )
weapon.ViewModelHandler.EditorMode = false;
return;
}
if ( weapon is not null )
{
var screenPanel = player.RootDisplay;
offsetEditor = new OffsetEditor( weapon );
screenPanel.Panel.AddChild( offsetEditor );
if ( weapon.ViewModelHandler is not null )
weapon.ViewModelHandler.EditorMode = true;
}
}
}