UI/Puzzle/CombinationLockUI.razor
@using Sandbox;
@using Sandbox.UI;
@using static CombinationLockInteractor;
@namespace Opium
@inherits PanelComponent
<root>
<LockPanelInspector LockType="@(lockType)" StartingCombination="@(Combo)" CombinationLockInteractor="@(ComboLockObject)" CombinationLockUI="@this"></LockPanelInspector>
<div class="stoplooking">
<label>[</label>
<InputHint @Action="Flashlight" />
<label>] Close</label>
<div class="spacer" />
<label>[</label>
<InputHint @Action="left" />
<label>] Move Left</label>
<div class="spacer" />
<label>[</label>
<InputHint @Action="right" />
<label>] Move Right</label>
<div class="spacer" />
<label>[</label>
<InputHint @Action="Forward" />
<label>] Move Up</label>
<div class="spacer" />
<label>[</label>
<InputHint @Action="backward" />
<label>] Move Down</label>
<div class="spacer" />
<label>[</label>
<InputHint @Action="use" />
<label>] Submit</label>
</div>
</root>
@code
{
private CombinationLockInteractor ComboLockObject { get; set; }
LockType lockType = LockType.PadlockA;
string Combo = "1234";
public bool Solved = false;
public void StartInteract(CombinationLockInteractor obj, LockType type, string combo )
{
ComboLockObject = obj;
var player = GameObject.Components.Get<Opium.PlayerController>(FindMode.EverythingInSelfAndAncestors);
player.LockMovement = true;
player.LockCameraMovement = true;
lockType = obj.Type;
Combo = combo;
}
public void StopInteract()
{
var player = GameObject.Components.Get<Opium.PlayerController>(FindMode.EverythingInSelfAndAncestors);
player.LockMovement = false;
player.LockCameraMovement = false;
ComboLockObject.StopInteract();
}
protected override void OnUpdate()
{
HandleCombinationLockInput();
}
private void HandleCombinationLockInput()
{
if (Input.Pressed("flashlight"))
StopInteract();
else if (Input.Pressed("use"))
Submit();
}
public void Submit()
{
if (Solved)
{
ComboLockObject.CorrectCombination();
StopInteract();
}
}
/// <summary>
/// the hash determines if the system should be rebuilt. If it changes, it will be rebuilt
/// </summary>
protected override int BuildHash() => System.HashCode.Combine(Time.Delta );
}