Skip to content

Commit 660fa7b

Browse files
committed
feature: make FocusManager as Injectable service and inject it in Nui.
fix: Fix DI Loading NUI as transient service instead singleton
1 parent 008d74c commit 660fa7b

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

engine/src/main/java/org/destinationsol/CoreService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import org.terasology.gestalt.di.ServiceRegistry;
2222
import org.terasology.gestalt.di.scanners.StandardScanner;
2323
import org.terasology.gestalt.entitysystem.component.management.ComponentManager;
24+
import org.terasology.nui.FocusManager;
25+
import org.terasology.nui.FocusManagerImpl;
2426
import org.terasology.nui.reflection.WidgetLibrary;
2527
import org.terasology.reflection.copy.CopyStrategyLibrary;
2628
import org.terasology.reflection.reflect.ReflectFactory;
@@ -50,15 +52,17 @@ public CoreService(SolApplication application) {
5052
this.with(MenuLayout.class).lifetime(Lifetime.Singleton);
5153

5254
this.with(NUIManager.class).lifetime(Lifetime.Singleton);
55+
this.with(FocusManager.class).lifetime(Lifetime.Singleton).use(FocusManagerImpl.class);
5356
this.with(MenuBackgroundManager.class).lifetime(Lifetime.Singleton);
5457

5558
this.with(ReflectFactory.class).lifetime(Lifetime.Singleton).use(ReflectionReflectFactory.class);
5659
this.with(CopyStrategyLibrary.class).lifetime(Lifetime.Singleton);
5760

5861
this.with(WidgetLibrary.class).lifetime(Lifetime.Singleton);
5962
this.with(SolInputManager.class).lifetime(Lifetime.Singleton);
63+
6064
this.registerScanner(new StandardScanner("org.destinationsol.assets"));
61-
this.registerScanner(new StandardScanner("org.destinationsol.ui.nui"));
65+
this.registerScanner(new StandardScanner("org.destinationsol.ui.nui.screens"));
6266

6367
// TODO seems this is should be GameService before game
6468
this.with(Console.class).lifetime(Lifetime.Singleton).use(ConsoleImpl.class);

engine/src/main/java/org/destinationsol/assets/ui/UISkinFormat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class UISkinFormat extends AbstractAssetFileFormat<UISkinData> {
4646

4747
private static final Logger logger = LoggerFactory.getLogger(UISkinFormat.class);
4848
private Gson gson;
49-
private ClassLibrary<UIWidget> widgetClassLibrary;
49+
private static ClassLibrary<UIWidget> widgetClassLibrary;
5050

5151
@Inject
5252
public UISkinFormat(WidgetLibrary widgetClassLibrary) {

engine/src/main/java/org/destinationsol/ui/nui/NUIManager.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,16 @@ public class NUIManager {
138138
* @param options used to initialise the UI scale with its previously-saved value
139139
*/
140140
@Inject
141-
public NUIManager(SolApplication solApplication, Context context, CommonDrawer commonDrawer, GameOptions options, UiDrawer uiDrawer) {
141+
public NUIManager(SolApplication solApplication,
142+
Context context,
143+
CommonDrawer commonDrawer,
144+
GameOptions options,
145+
UiDrawer uiDrawer,
146+
FocusManager focusManager) {
142147
NUIInputProcessor.CONSUME_INPUT = false;
143148
this.context = context;
144149
this.uiDrawer = uiDrawer;
150+
this.focusManager = focusManager;
145151

146152
// TODO: Re-enable tabbing when it works
147153
TabbingManager.tabForwardInput = Keyboard.Key.NONE;
@@ -152,7 +158,6 @@ public NUIManager(SolApplication solApplication, Context context, CommonDrawer c
152158
keyboard = new LibGDXKeyboardDevice();
153159
canvasRenderer = new LibGDXCanvasRenderer(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(),
154160
commonDrawer.getSpriteBatch(), new ShapeRenderer(), false, true);
155-
focusManager = new FocusManagerImpl();
156161
whiteTexture = Assets.getDSTexture(WHITE_TEXTURE_URN).getUiTexture();
157162
skin = Assets.getSkin(DEFAULT_SKIN_URN);
158163

@@ -313,10 +318,6 @@ public NUIScreenLayer createScreen(String uri) {
313318
if (rootWidget instanceof NUIScreenLayer) {
314319
NUIScreenLayer screen = (NUIScreenLayer) rootWidget;
315320
if (!alreadyLoaded) {
316-
// Populate all @In annotated fields in the screen class with values from the context.
317-
InjectionHelper.inject(screen, context);
318-
screen.setFocusManager(focusManager);
319-
screen.setNuiManager(this);
320321
screen.initialise();
321322
}
322323
return screen;

engine/src/main/java/org/destinationsol/ui/nui/NUIScreenLayer.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.terasology.nui.UIWidget;
2727
import org.terasology.nui.events.NUIKeyEvent;
2828

29+
import javax.inject.Inject;
2930
import java.util.Arrays;
3031
import java.util.Collections;
3132
import java.util.Iterator;
@@ -177,7 +178,8 @@ protected boolean escapeCloses() {
177178
* Primary usage is in {@link NUIManager#pushScreen}
178179
* @param focusManager the focus manager to use.
179180
*/
180-
void setFocusManager(FocusManager focusManager) {
181+
@Inject
182+
public void setFocusManager(FocusManager focusManager) {
181183
this.focusManager = focusManager;
182184
}
183185

@@ -193,7 +195,8 @@ protected FocusManager getFocusManager() {
193195
* Sets the game's NUI Manager.
194196
* @param nuiManager the game's NUI Manager
195197
*/
196-
void setNuiManager(NUIManager nuiManager) {
198+
@Inject
199+
public void setNuiManager(NUIManager nuiManager) {
197200
this.nuiManager = nuiManager;
198201
}
199202

0 commit comments

Comments
 (0)