Skip to content

Commit be2c54b

Browse files
Refac
1 parent 66009c6 commit be2c54b

File tree

14 files changed

+107
-92
lines changed

14 files changed

+107
-92
lines changed

pacman-app-arcade-mspacman/src/main/java/de/amr/pacmanfx/arcade/ms_pacman/ArcadeMsPacMan_UIConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public Image bonusValueImage(byte symbol) {
214214
@Override
215215
public MsPacManBody createLivesCounterShape3D() {
216216
return ui.theAssets().theModel3DRepository().createMsPacManBody(
217-
ui.theUserPrefs().getFloat("3d.lives_counter.shape_size"),
217+
ui.theUIPrefs().getFloat("3d.lives_counter.shape_size"),
218218
getAssetNS("pac.color.head"),
219219
getAssetNS("pac.color.eyes"),
220220
getAssetNS("pac.color.palate"),
@@ -230,7 +230,7 @@ public MsPacMan3D createPac3D(AnimationRegistry animationRegistry, Pac pac) {
230230
ui.theAssets().theModel3DRepository(),
231231
animationRegistry,
232232
pac,
233-
ui.theUserPrefs().getFloat("3d.pac.size"),
233+
ui.theUIPrefs().getFloat("3d.pac.size"),
234234
getAssetNS("pac.color.head"),
235235
getAssetNS("pac.color.eyes"),
236236
getAssetNS("pac.color.palate"),

pacman-app-arcade-pacman/src/main/java/de/amr/pacmanfx/arcade/pacman/ArcadePacMan_UIConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public Image bonusValueImage(byte symbol) {
204204
@Override
205205
public PacBody createLivesCounterShape3D() {
206206
return ui.theAssets().theModel3DRepository().createPacBody(
207-
ui.theUserPrefs().getFloat("3d.lives_counter.shape_size"),
207+
ui.theUIPrefs().getFloat("3d.lives_counter.shape_size"),
208208
getAssetNS("pac.color.head"),
209209
getAssetNS("pac.color.eyes"),
210210
getAssetNS("pac.color.palate")
@@ -216,7 +216,7 @@ public PacMan3D createPac3D(AnimationRegistry animationRegistry, Pac pac) {
216216
var pac3D = new PacMan3D(ui.theAssets().theModel3DRepository(),
217217
animationRegistry,
218218
pac,
219-
ui.theUserPrefs().getFloat("3d.pac.size"),
219+
ui.theUIPrefs().getFloat("3d.pac.size"),
220220
getAssetNS("pac.color.head"),
221221
getAssetNS("pac.color.eyes"),
222222
getAssetNS("pac.color.palate"));

pacman-app-arcade-pacmanxxl/src/main/java/de/amr/pacmanfx/arcade/pacman_xxl/PacManXXL_MsPacMan_UIConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public Image bonusValueImage(byte symbol) {
212212
@Override
213213
public MsPacManBody createLivesCounterShape3D() {
214214
return ui.theAssets().theModel3DRepository().createMsPacManBody(
215-
ui.theUserPrefs().getFloat("3d.lives_counter.shape_size"),
215+
ui.theUIPrefs().getFloat("3d.lives_counter.shape_size"),
216216
getAssetNS("pac.color.head"),
217217
getAssetNS("pac.color.eyes"),
218218
getAssetNS("pac.color.palate"),
@@ -228,7 +228,7 @@ public MsPacMan3D createPac3D(AnimationRegistry animationRegistry, Pac pac) {
228228
ui.theAssets().theModel3DRepository(),
229229
animationRegistry,
230230
pac,
231-
ui.theUserPrefs().getFloat("3d.pac.size"),
231+
ui.theUIPrefs().getFloat("3d.pac.size"),
232232
getAssetNS("pac.color.head"),
233233
getAssetNS("pac.color.eyes"),
234234
getAssetNS("pac.color.palate"),

pacman-app-arcade-pacmanxxl/src/main/java/de/amr/pacmanfx/arcade/pacman_xxl/PacManXXL_PacMan_UIConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public ArcadePacMan_PacAnimationMap createPacAnimations(Pac pac) {
200200
@Override
201201
public PacBody createLivesCounterShape3D() {
202202
return ui.theAssets().theModel3DRepository().createPacBody(
203-
ui.theUserPrefs().getFloat("3d.lives_counter.shape_size"),
203+
ui.theUIPrefs().getFloat("3d.lives_counter.shape_size"),
204204
getAssetNS("pac.color.head"),
205205
getAssetNS("pac.color.eyes"),
206206
getAssetNS("pac.color.palate")
@@ -213,7 +213,7 @@ public PacBase3D createPac3D(AnimationRegistry animationRegistry, Pac pac) {
213213
ui.theAssets().theModel3DRepository(),
214214
animationRegistry,
215215
pac,
216-
ui.theUserPrefs().getFloat("3d.pac.size"),
216+
ui.theUIPrefs().getFloat("3d.pac.size"),
217217
getAssetNS("pac.color.head"),
218218
getAssetNS("pac.color.eyes"),
219219
getAssetNS("pac.color.palate")

pacman-app-tengen-mspacman/src/main/java/de/amr/pacmanfx/tengen/ms_pacman/TengenMsPacMan_UIConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ public TengenMsPacMan_PacAnimationMap createPacAnimations(Pac pac) {
356356
@Override
357357
public MsPacManBody createLivesCounterShape3D() {
358358
return ui.theAssets().theModel3DRepository().createMsPacManBody(
359-
ui.theUserPrefs().getFloat("3d.lives_counter.shape_size"),
359+
ui.theUIPrefs().getFloat("3d.lives_counter.shape_size"),
360360
getAssetNS("pac.color.head"),
361361
getAssetNS("pac.color.eyes"),
362362
getAssetNS("pac.color.palate"),
@@ -372,7 +372,7 @@ public MsPacMan3D createPac3D(AnimationRegistry animationRegistry, Pac pac) {
372372
ui.theAssets().theModel3DRepository(),
373373
animationRegistry,
374374
pac,
375-
ui.theUserPrefs().getFloat("3d.pac.size"),
375+
ui.theUIPrefs().getFloat("3d.pac.size"),
376376
getAssetNS("pac.color.head"),
377377
getAssetNS("pac.color.eyes"),
378378
getAssetNS("pac.color.palate"),

pacman-ui/src/main/java/de/amr/pacmanfx/ui/UserUIPreferences.java renamed to pacman-ui-lib/src/main/java/de/amr/pacmanfx/uilib/assets/UIPreferences.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Copyright (c) 2021-2025 Armin Reichert (MIT License)
33
See file LICENSE in repository root directory for details.
44
*/
5-
package de.amr.pacmanfx.ui;
5+
package de.amr.pacmanfx.uilib.assets;
66

77
import javafx.scene.paint.Color;
88
import javafx.scene.text.Font;
@@ -15,13 +15,18 @@
1515

1616
import static de.amr.pacmanfx.uilib.Ufx.formatColorHex;
1717

18-
public class UserUIPreferences {
18+
public class UIPreferences {
1919

2020
private final Map<String, Object> defaultValueMap = new HashMap<>();
2121
private final Preferences prefs;
2222

23-
public UserUIPreferences(Class<?> _class) {
24-
prefs = Preferences.userNodeForPackage(_class);
23+
public UIPreferences(Class<?> javaClass) {
24+
prefs = Preferences.userNodeForPackage(javaClass);
25+
if (!isBackingStoreAccessible()) {
26+
Logger.error("User preferences could not be accessed, using default values!");
27+
} else {
28+
addMissingValues();
29+
}
2530
}
2631

2732
public boolean isBackingStoreAccessible() {

pacman-ui-lib/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// module is open to allow access to non-class resources
22
open module de.amr.pacmanfx.uilib {
3+
requires java.prefs;
34
requires javafx.graphics;
45
requires javafx.controls;
56
requires javafx.media;

pacman-ui/src/main/java/de/amr/pacmanfx/ui/GameUI.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import de.amr.pacmanfx.ui.layout.StartPagesView;
1616
import de.amr.pacmanfx.ui.sound.SoundManager;
1717
import de.amr.pacmanfx.uilib.GameClock;
18+
import de.amr.pacmanfx.uilib.assets.UIPreferences;
1819
import javafx.beans.property.BooleanProperty;
1920
import javafx.beans.property.DoubleProperty;
2021
import javafx.beans.property.IntegerProperty;
@@ -107,7 +108,7 @@ public interface GameUI {
107108
Keyboard theKeyboard();
108109
SoundManager theSound();
109110
Stage theStage();
110-
UserUIPreferences theUserPrefs();
111+
UIPreferences theUIPrefs();
111112

112113
void restart();
113114
void selectGameVariant(String variant);
@@ -162,8 +163,8 @@ default void runActionOrElse(GameAction optAction, Runnable defaultCode) {
162163
* @return CustomMenuItem representing a context menu title item
163164
*/
164165
default MenuItem createContextMenuTitle(String titleKey) {
165-
Font font = theUserPrefs().getFont("context_menu.title.font");
166-
Color fillColor = theUserPrefs().getColor("context_menu.title.fill");
166+
Font font = theUIPrefs().getFont("context_menu.title.font");
167+
Color fillColor = theUIPrefs().getColor("context_menu.title.fill");
167168
var text = new Text(theAssets().text(titleKey));
168169
text.setFont(font);
169170
text.setFill(fillColor);
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Copyright (c) 2021-2025 Armin Reichert (MIT License)
3+
See file LICENSE in repository root directory for details.
4+
*/
5+
package de.amr.pacmanfx.ui;
6+
7+
import de.amr.pacmanfx.uilib.assets.UIPreferences;
8+
import javafx.scene.paint.Color;
9+
import javafx.scene.text.Font;
10+
import javafx.scene.text.FontWeight;
11+
12+
import static de.amr.pacmanfx.Globals.TS;
13+
14+
public class PacManGames_Preferences extends UIPreferences {
15+
16+
public PacManGames_Preferences() {
17+
super(PacManGames_Preferences.class);
18+
19+
storeDefaultValue("3d.bonus.symbol.width", 8.0f);
20+
storeDefaultValue("3d.bonus.points.width", 1.8f * 8.0f);
21+
storeDefaultValue("3d.energizer.radius", 3.5f);
22+
storeDefaultValue("3d.energizer.scaling.min", 0.2f);
23+
storeDefaultValue("3d.energizer.scaling.max", 1.0f);
24+
storeDefaultValue("3d.floor.padding", 5.0f);
25+
storeDefaultValue("3d.floor.thickness", 0.5f);
26+
storeDefaultValue("3d.ghost.size", 15.5f);
27+
storeDefaultValue("3d.house.base_height", 12.0f);
28+
storeDefaultValue("3d.house.opacity", 0.4f);
29+
storeDefaultValue("3d.house.sensitivity", 1.5f * TS);
30+
storeDefaultValue("3d.house.wall_thickness", 2.5f);
31+
storeDefaultValue("3d.level_counter.symbol_size", 10.0f);
32+
storeDefaultValue("3d.level_counter.elevation", 6f);
33+
storeDefaultValue("3d.lives_counter.capacity", 5);
34+
storeDefaultColor("3d.lives_counter.pillar_color", Color.grayRgb(120));
35+
storeDefaultColor("3d.lives_counter.plate_color", Color.grayRgb(180));
36+
storeDefaultValue("3d.lives_counter.shape_size", 12.0f);
37+
storeDefaultValue("3d.obstacle.base_height", 4.0f);
38+
storeDefaultValue("3d.obstacle.corner_radius", 4.0f);
39+
storeDefaultValue("3d.obstacle.opacity", 1.0f);
40+
storeDefaultValue("3d.obstacle.wall_thickness", 2.25f);
41+
storeDefaultValue("3d.pac.size", 16.0f);
42+
storeDefaultValue("3d.pellet.radius", 1.0f);
43+
44+
// "Kornblumenblau, sind die Augen der Frauen beim Weine. Hicks!"
45+
storeDefaultColor("context_menu.title.fill", Color.CORNFLOWERBLUE);
46+
storeDefaultFont("context_menu.title.font", Font.font("Dialog", FontWeight.BLACK, 14.0f));
47+
48+
storeDefaultColor("debug_text.fill", Color.YELLOW);
49+
storeDefaultFont("debug_text.font", Font.font("Sans", FontWeight.BOLD, 16.0f));
50+
51+
storeDefaultValue("scene2d.max_scaling", 5.0f);
52+
}
53+
}

pacman-ui/src/main/java/de/amr/pacmanfx/ui/PacManGames_UI_Impl.java

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import de.amr.pacmanfx.ui.layout.*;
1717
import de.amr.pacmanfx.ui.sound.SoundManager;
1818
import de.amr.pacmanfx.uilib.GameClock;
19+
import de.amr.pacmanfx.uilib.assets.UIPreferences;
1920
import javafx.application.Platform;
2021
import javafx.beans.binding.Bindings;
2122
import javafx.beans.property.*;
@@ -25,16 +26,13 @@
2526
import javafx.scene.image.Image;
2627
import javafx.scene.paint.Color;
2728
import javafx.scene.shape.DrawMode;
28-
import javafx.scene.text.Font;
29-
import javafx.scene.text.FontWeight;
3029
import javafx.stage.Stage;
3130
import org.tinylog.Logger;
3231

3332
import java.util.HashMap;
3433
import java.util.Map;
3534
import java.util.Optional;
3635

37-
import static de.amr.pacmanfx.Globals.TS;
3836
import static de.amr.pacmanfx.ui.PacManGames_GameActions.*;
3937
import static java.util.Objects.requireNonNull;
4038

@@ -76,7 +74,7 @@ public class PacManGames_UI_Impl implements GameUI {
7674
private final GameContext theGameContext;
7775
private final Keyboard theKeyboard;
7876
private final Joypad theJoypad;
79-
private final UserUIPreferences thePrefs;
77+
private final UIPreferences theUIPrefs;
8078
private final Stage theStage;
8179

8280
private final ActionBindingManager globalActionBindings = new DefaultActionBindingManager();
@@ -101,10 +99,9 @@ public PacManGames_UI_Impl(GameContext gameContext, Stage stage, double width, d
10199

102100
// Game UI
103101
theAssets = new PacManGames_Assets();
104-
thePrefs = new UserUIPreferences(PacManGames_UI_Impl.class);
102+
theUIPrefs = new PacManGames_Preferences();
105103
theStage = stage;
106104

107-
initPreferences();
108105
initGlobalActionBindings();
109106

110107
mainScene = new MainScene(this, width, height);
@@ -122,8 +119,8 @@ public PacManGames_UI_Impl(GameContext gameContext, Stage stage, double width, d
122119
theGameClock.setPausableAction(this::doSimulationStepAndUpdateGameScene);
123120
theGameClock.setPermanentAction(this::drawCurrentView);
124121

125-
property3DWallHeight.set(thePrefs.getFloat("3d.obstacle.base_height"));
126-
property3DWallOpacity.set(thePrefs.getFloat("3d.obstacle.opacity"));
122+
property3DWallHeight.set(theUIPrefs.getFloat("3d.obstacle.base_height"));
123+
property3DWallOpacity.set(theUIPrefs.getFloat("3d.obstacle.opacity"));
127124
}
128125

129126
private void configureStage(Stage stage) {
@@ -155,48 +152,6 @@ private void initGlobalActionBindings() {
155152
globalActionBindings.updateKeyboard(theKeyboard);
156153
}
157154

158-
private void initPreferences() {
159-
thePrefs.storeDefaultValue("3d.bonus.symbol.width", 8.0f);
160-
thePrefs.storeDefaultValue("3d.bonus.points.width", 1.8f * 8.0f);
161-
thePrefs.storeDefaultValue("3d.energizer.radius", 3.5f);
162-
thePrefs.storeDefaultValue("3d.energizer.scaling.min", 0.2f);
163-
thePrefs.storeDefaultValue("3d.energizer.scaling.max", 1.0f);
164-
thePrefs.storeDefaultValue("3d.floor.padding", 5.0f);
165-
thePrefs.storeDefaultValue("3d.floor.thickness", 0.5f);
166-
thePrefs.storeDefaultValue("3d.ghost.size", 15.5f);
167-
thePrefs.storeDefaultValue("3d.house.base_height", 12.0f);
168-
thePrefs.storeDefaultValue("3d.house.opacity", 0.4f);
169-
thePrefs.storeDefaultValue("3d.house.sensitivity", 1.5f * TS);
170-
thePrefs.storeDefaultValue("3d.house.wall_thickness", 2.5f);
171-
thePrefs.storeDefaultValue("3d.level_counter.symbol_size", 10.0f);
172-
thePrefs.storeDefaultValue("3d.level_counter.elevation", 6f);
173-
thePrefs.storeDefaultValue("3d.lives_counter.capacity", 5);
174-
thePrefs.storeDefaultColor("3d.lives_counter.pillar_color", Color.grayRgb(120));
175-
thePrefs.storeDefaultColor("3d.lives_counter.plate_color", Color.grayRgb(180));
176-
thePrefs.storeDefaultValue("3d.lives_counter.shape_size", 12.0f);
177-
thePrefs.storeDefaultValue("3d.obstacle.base_height", 4.0f);
178-
thePrefs.storeDefaultValue("3d.obstacle.corner_radius", 4.0f);
179-
thePrefs.storeDefaultValue("3d.obstacle.opacity", 1.0f);
180-
thePrefs.storeDefaultValue("3d.obstacle.wall_thickness", 2.25f);
181-
thePrefs.storeDefaultValue("3d.pac.size", 16.0f);
182-
thePrefs.storeDefaultValue("3d.pellet.radius", 1.0f);
183-
184-
// "Kornblumenblau, sind die Augen der Frauen beim Weine. Hicks!"
185-
thePrefs.storeDefaultColor("context_menu.title.fill", Color.CORNFLOWERBLUE);
186-
thePrefs.storeDefaultFont("context_menu.title.font", Font.font("Dialog", FontWeight.BLACK, 14.0f));
187-
188-
thePrefs.storeDefaultColor("debug_text.fill", Color.YELLOW);
189-
thePrefs.storeDefaultFont("debug_text.font", Font.font("Sans", FontWeight.BOLD, 16.0f));
190-
191-
thePrefs.storeDefaultValue("scene2d.max_scaling", 5.0f);
192-
193-
if (!thePrefs.isBackingStoreAccessible()) {
194-
Logger.error("User preferences could not be accessed, using default values!");
195-
} else {
196-
thePrefs.addMissingValues();
197-
}
198-
}
199-
200155
private void selectView(PacManGames_View view) {
201156
requireNonNull(view);
202157
final PacManGames_View oldView = mainScene.currentView();
@@ -317,7 +272,7 @@ public boolean isCurrentGameSceneID(String id) {
317272
@Override public Stage theStage() { return theStage; }
318273

319274
@Override
320-
public UserUIPreferences theUserPrefs() { return thePrefs; }
275+
public UIPreferences theUIPrefs() { return theUIPrefs; }
321276

322277
@Override
323278
public void restart() {

0 commit comments

Comments
 (0)