Skip to content

Commit b7c8edb

Browse files
committed
Current
1 parent d54c0f3 commit b7c8edb

File tree

4 files changed

+51
-45
lines changed

4 files changed

+51
-45
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Juce.Core.Repositories;
2+
using Juce.Core.Sequencing;
3+
using Juce.CoreUnity.Ui.Frame;
4+
using Juce.CoreUnity.ViewStack.Context;
5+
using Juce.CoreUnity.ViewStack.Entries;
6+
using System;
7+
8+
namespace Playground.Services.ViewStack.Instructions
9+
{
10+
public class MoveCurrentToForegroundInstruction : InstantInstruction
11+
{
12+
private readonly IUiFrame frame;
13+
private readonly IKeyValueRepository<Type, IViewStackEntry> entriesRepository;
14+
private readonly ISingleRepository<IViewContext> currentContextRepository;
15+
16+
public MoveCurrentToForegroundInstruction(
17+
IUiFrame frame,
18+
IKeyValueRepository<Type, IViewStackEntry> entriesRepository
19+
)
20+
{
21+
this.frame = frame;
22+
this.entriesRepository = entriesRepository;
23+
}
24+
25+
protected override void OnInstantExecute()
26+
{
27+
bool hasCurrentContext = currentContextRepository.TryGet(out IViewContext context);
28+
29+
if (!hasCurrentContext)
30+
{
31+
UnityEngine.Debug.LogError($"Tried to MoveCurrentToForeground " +
32+
$"but it there was not a current view context, at {nameof(MoveCurrentToForegroundInstruction)}");
33+
}
34+
35+
bool found = entriesRepository.TryGet(context.ViewId, out IViewStackEntry entry);
36+
37+
if (!found)
38+
{
39+
UnityEngine.Debug.LogError($"Tried to MoveCurrentToForeground {nameof(IViewStackEntry)} of type {context.ViewId}, " +
40+
$"but it was not registered, at {nameof(MoveCurrentToForegroundInstruction)}");
41+
42+
return;
43+
}
44+
45+
frame.MoveToForeground(entry.Transform);
46+
}
47+
}
48+
}

Runtime/Ui/ViewStack/Instructions/MoveToForegroundInstruction.cs.meta renamed to Runtime/Ui/ViewStack/Instructions/MoveCurrentToForegroundInstruction.cs.meta

File renamed without changes.

Runtime/Ui/ViewStack/Instructions/MoveToForegroundInstruction.cs

Lines changed: 0 additions & 41 deletions
This file was deleted.

Runtime/Ui/ViewStack/Sequences/ViewStackSequenceBuilder.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,13 @@ public IViewStackSequenceBuilder MoveToBackground<T>()
126126
return this;
127127
}
128128

129-
public IViewStackSequenceBuilder MoveToForeground<T>()
129+
public IViewStackSequenceBuilder MoveCurrentToForeground<T>()
130130
{
131131
Type entryId = typeof(T);
132132

133-
instructionsToPlay.Add(new MoveToForegroundInstruction(
133+
instructionsToPlay.Add(new MoveCurrentToForegroundInstruction(
134134
frame,
135-
entriesRepository,
136-
entryId
135+
entriesRepository
137136
));
138137

139138
return this;

0 commit comments

Comments
 (0)