Compare commits
101 Commits
in-develop
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b3e29a3262 | ||
|
|
429e5bc90b | ||
|
|
8146be16ed | ||
|
|
afb4844084 | ||
|
|
ed3cb902e4 | ||
|
|
3c385e27b0 | ||
|
|
783cfd22e1 | ||
|
|
16a5b1ce2f | ||
|
|
6bfa8868bf | ||
|
|
748f72352f | ||
|
|
a302f0d24d | ||
|
|
3d9914c927 | ||
|
|
3af182b986 | ||
|
|
58269e917a | ||
|
|
172b26ed51 | ||
|
|
78aef47bc0 | ||
|
|
ea8de7881f | ||
|
|
e6fa522f39 | ||
|
|
6d7a8e4c50 | ||
|
|
c6c1c110f7 | ||
|
|
046a59e915 | ||
|
|
501b411e34 | ||
|
|
95c4a2fc8e | ||
|
|
ce02fc2b88 | ||
|
|
f525fc7ffc | ||
|
|
1bf3f00322 | ||
|
|
525adfdd04 | ||
|
|
fcdd4a8fc1 | ||
|
|
acc9972c80 | ||
|
|
5097e371f3 | ||
|
|
98755b6bed | ||
|
|
0d771088e1 | ||
|
|
43c577ef17 | ||
|
|
017673452b | ||
|
|
b8488c7289 | ||
|
|
cfde1f8d7f | ||
|
|
9144cb453e | ||
|
|
20a7fd7a3e | ||
|
|
33255d5ee6 | ||
|
|
ada778fe71 | ||
|
|
ab7494616b | ||
|
|
08bfb97399 | ||
|
|
062fe2e8bc | ||
|
|
b903e9b3c4 | ||
|
|
a40d30fec7 | ||
|
|
98bff669e9 | ||
|
|
c2d320ea97 | ||
|
|
9ee6bf3067 | ||
|
|
2198b8a8d9 | ||
|
|
7e3f13491d | ||
|
|
d28fd90b84 | ||
|
|
b8336ce3d2 | ||
|
|
b5ac747f77 | ||
|
|
369df7a0d1 | ||
|
|
06464945bd | ||
|
|
1bab3e12a5 | ||
|
|
a50c1a8d0d | ||
|
|
f780309572 | ||
|
|
2362333d46 | ||
|
|
0ab0cd75ba | ||
|
|
043b789da1 | ||
|
|
d7d6a49b98 | ||
|
|
39fa2edb3a | ||
|
|
e7d606f08e | ||
|
|
db6231c6d0 | ||
|
|
cd2f3c312e | ||
|
|
2eeca4e418 | ||
|
|
4daa379011 | ||
|
|
ba4173f029 | ||
|
|
af0db24b0a | ||
|
|
732abedba5 | ||
|
|
fe6b050702 | ||
|
|
b3feab7cb3 | ||
|
|
87a5b301c7 | ||
|
|
8fc7f606f9 | ||
|
|
fae5b8bcda | ||
|
|
ac6de04e68 | ||
|
|
d9a93f24fb | ||
|
|
754c8fea2e | ||
|
|
82f8d00625 | ||
|
|
56a1afe1cd | ||
|
|
796c3a2bc6 | ||
|
|
dd192692bd | ||
|
|
5a200a8a70 | ||
|
|
83130806a8 | ||
|
|
a5513bf87b | ||
|
|
547ea55300 | ||
|
|
3471ae54a5 | ||
|
|
c020269f6e | ||
|
|
f037412e9a | ||
|
|
5e1d53e96b | ||
|
|
8ac76dd17f | ||
|
|
efca808e1c | ||
|
|
dd230ad515 | ||
|
|
1dd345a290 | ||
|
|
e48df5df15 | ||
|
|
ef550f353d | ||
|
|
a6bd2495ab | ||
|
|
477afa142b | ||
|
|
d5735be2db | ||
|
|
f37928307c |
80
.github/workflows/checks.yaml
vendored
@@ -1,42 +1,42 @@
|
||||
name: Checks
|
||||
#name: Checks
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'main'
|
||||
pull_request:
|
||||
branches:
|
||||
- 'main'
|
||||
#on:
|
||||
# push:
|
||||
# branches:
|
||||
# - 'main'
|
||||
# pull_request:
|
||||
# branches:
|
||||
# - 'main'
|
||||
#
|
||||
#jobs:
|
||||
# formatting-check:
|
||||
# name: Follow Google Formatting Guidelines
|
||||
# runs-on: ubuntu-latest
|
||||
# steps:
|
||||
# - uses: actions/checkout@v5
|
||||
# with:
|
||||
# fetch-depth: 0 # Fix for incremental formatting
|
||||
# - uses: actions/setup-java@v5
|
||||
# with:
|
||||
# java-version: '25'
|
||||
# distribution: 'temurin'
|
||||
# cache: maven
|
||||
# - name: Run Format Check
|
||||
# run: mvn spotless:check
|
||||
|
||||
jobs:
|
||||
formatting-check:
|
||||
name: Follow Google Formatting Guidelines
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 0 # Fix for incremental formatting
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
java-version: '25'
|
||||
distribution: 'temurin'
|
||||
cache: maven
|
||||
- name: Run Format Check
|
||||
run: mvn spotless:check
|
||||
|
||||
tests:
|
||||
name: Unittests
|
||||
runs-on: ${{ matrix.os }}
|
||||
needs: formatting-check
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest] #windows-latest, macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
java-version: '25'
|
||||
distribution: 'temurin'
|
||||
cache: maven
|
||||
- name: Run Unittests
|
||||
run: mvn -B test
|
||||
# tests:
|
||||
# name: Unittests
|
||||
# runs-on: ${{ matrix.os }}
|
||||
# needs: formatting-check
|
||||
# strategy:
|
||||
# matrix:
|
||||
# os: [ubuntu-latest] #windows-latest, macos-latest
|
||||
# steps:
|
||||
# - uses: actions/checkout@v5
|
||||
# - uses: actions/setup-java@v5
|
||||
# with:
|
||||
# java-version: '25'
|
||||
# distribution: 'temurin'
|
||||
# cache: maven
|
||||
# - name: Run Unittests
|
||||
# run: mvn -B test
|
||||
|
||||
10
.gitignore
vendored
@@ -47,6 +47,9 @@ shelf/
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
misc.xml
|
||||
uiDesigner.xml
|
||||
|
||||
|
||||
##############################
|
||||
## Eclipse
|
||||
@@ -75,6 +78,8 @@ dist/
|
||||
nbdist/
|
||||
nbactions.xml
|
||||
nb-configuration.xml
|
||||
misc.xml
|
||||
compiler.xml
|
||||
|
||||
##############################
|
||||
## Visual Studio Code
|
||||
@@ -102,3 +107,8 @@ newgamesver-release-V1.jar
|
||||
server.properties
|
||||
gameserver.log.*
|
||||
gameserver.log
|
||||
|
||||
##############################
|
||||
## JPackage
|
||||
##############################
|
||||
jpackage-input
|
||||
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
@@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
||||
22
.idea/compiler.xml
generated
@@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="pism_framework" />
|
||||
<module name="pism_game" />
|
||||
<module name="pism_app" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
<component name="JavacSettings">
|
||||
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
|
||||
<module name="pism_app" options="" />
|
||||
<module name="pism_framework" options="" />
|
||||
<module name="pism_game" options="" />
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
3
.idea/dictionaries/project.xml
generated
@@ -5,14 +5,17 @@
|
||||
<w>clid</w>
|
||||
<w>dcompile</w>
|
||||
<w>errorprone</w>
|
||||
<w>español</w>
|
||||
<w>flushnl</w>
|
||||
<w>gaaf</w>
|
||||
<w>gamelist</w>
|
||||
<w>pism</w>
|
||||
<w>playerlist</w>
|
||||
<w>tictactoe</w>
|
||||
<w>toop</w>
|
||||
<w>vmoptions</w>
|
||||
<w>xplugin</w>
|
||||
<w>yourturn</w>
|
||||
</words>
|
||||
</dictionary>
|
||||
</component>
|
||||
4
.idea/encodings.xml
generated
@@ -1,12 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$APPLICATION_HOME_DIR$/bin/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$APPLICATION_HOME_DIR$/bin/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/app/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/app/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/framework/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/framework/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/game/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/game/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/processors/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/processors/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
|
||||
3
.idea/inspectionProfiles/Project_Default.xml
generated
@@ -2,7 +2,8 @@
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="AutoCloseableResource" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="METHOD_MATCHER_CONFIG" value="java.util.Formatter,format,java.io.Writer,append,com.google.common.base.Preconditions,checkNotNull,org.hibernate.Session,close,java.io.PrintWriter,printf,java.io.PrintStream,printf,java.lang.foreign.Arena,ofAuto,java.lang.foreign.Arena,global,org.toop.framework.audio.AudioPlayer,play" />
|
||||
<option name="METHOD_MATCHER_CONFIG" value="java.util.Formatter,format,java.io.Writer,append,com.google.common.base.Preconditions,checkNotNull,org.hibernate.Session,close,java.io.PrintWriter,printf,java.io.PrintStream,printf,java.lang.foreign.Arena,ofAuto,java.lang.foreign.Arena,global,org.toop.framework.audio.AudioPlayer,play,java.util.Map,remove,java.util.concurrent.Executors,newSingleThreadScheduledExecutor|newFixedThreadPool|newSingleThreadExecutor" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="WriteOnlyObject" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
</profile>
|
||||
</component>
|
||||
19
.idea/misc.xml
generated
@@ -1,19 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<list size="1">
|
||||
<item index="0" class="java.lang.String" itemvalue="com.google.common.eventbus.Subscribe" />
|
||||
</list>
|
||||
</component>
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" default="true" project-jdk-name="openjdk-25" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
15
.idea/resourceBundles.xml
generated
@@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ResourceBundleManager">
|
||||
<custom-resource-bundle>
|
||||
<file value="file://$PROJECT_DIR$/app/src/main/resources/assets/localization/Localization.properties" />
|
||||
<file value="file://$PROJECT_DIR$/app/src/main/resources/assets/localization/Localization_de.properties" />
|
||||
<file value="file://$PROJECT_DIR$/app/src/main/resources/assets/localization/Localization_es.properties" />
|
||||
<file value="file://$PROJECT_DIR$/app/src/main/resources/assets/localization/Localization_fr.properties" />
|
||||
<file value="file://$PROJECT_DIR$/app/src/main/resources/assets/localization/Localization_it.properties" />
|
||||
<file value="file://$PROJECT_DIR$/app/src/main/resources/assets/localization/Localization_nl.properties" />
|
||||
<file value="file://$PROJECT_DIR$/app/src/main/resources/assets/localization/Localization_zh.properties" />
|
||||
<base-name>localization</base-name>
|
||||
</custom-resource-bundle>
|
||||
</component>
|
||||
</project>
|
||||
104
app/pom.xml
@@ -1,15 +1,20 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.toop</groupId>
|
||||
<artifactId>pism_app</artifactId>
|
||||
<parent>
|
||||
<groupId>org.toop</groupId>
|
||||
<artifactId>pism</artifactId>
|
||||
<version>0.1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>app</artifactId>
|
||||
<version>0.1</version>
|
||||
|
||||
<properties>
|
||||
<main-class>org.toop.Main</main-class>
|
||||
<maven.compiler.source>25</maven.compiler.source>
|
||||
<maven.compiler.target>25</maven.compiler.target>
|
||||
|
||||
<maven.compiler.release>25</maven.compiler.release>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
@@ -19,25 +24,41 @@
|
||||
<artifactId>spotless-maven-plugin</artifactId>
|
||||
<version>2.46.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.toop</groupId>
|
||||
<artifactId>pism_framework</artifactId>
|
||||
<version>0.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.toop</groupId>
|
||||
<artifactId>pism_game</artifactId>
|
||||
<version>0.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.10.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-controls</artifactId>
|
||||
<version>25</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.errorprone</groupId>
|
||||
<artifactId>error_prone_core</artifactId>
|
||||
<version>2.42.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.errorprone</groupId>
|
||||
<artifactId>error_prone_annotations</artifactId>
|
||||
<version>2.42.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.toop</groupId>
|
||||
<artifactId>framework</artifactId>
|
||||
<version>0.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.toop</groupId>
|
||||
<artifactId>game</artifactId>
|
||||
<version>0.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -68,6 +89,7 @@
|
||||
<mainClass>org.toop.Main</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
<finalName>pism</finalName>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
@@ -107,6 +129,56 @@
|
||||
</java>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.14.1</version>
|
||||
<configuration>
|
||||
<showWarnings>true</showWarnings>
|
||||
<fork>true</fork>
|
||||
<executable>${java.home}/bin/javac</executable>
|
||||
<source>25</source>
|
||||
<target>25</target>
|
||||
<release>25</release>
|
||||
<encoding>UTF-8</encoding>
|
||||
<compilerArgs>
|
||||
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
|
||||
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
|
||||
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
|
||||
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
|
||||
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
|
||||
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
|
||||
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
|
||||
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
|
||||
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
|
||||
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
|
||||
<arg>
|
||||
-Xplugin:ErrorProne \
|
||||
</arg>
|
||||
<!-- TODO-->
|
||||
<!-- -Xep:RestrictedApi:ERROR \-->
|
||||
<!-- -XepOpt:RestrictedApi:annotation=org.toop.annotations.TestsOnly \-->
|
||||
<!-- -XepOpt:RestrictedApi:allowlistRegex=(?s).*/src/test/java/.*|.*test\.java \-->
|
||||
<!-- -XepOpt:RestrictedApi:message=This API is marked @TestsOnly and shouldn't be normally used.-->
|
||||
<arg>-XDcompilePolicy=simple</arg>
|
||||
<arg>--should-stop=ifError=FLOW</arg>
|
||||
</compilerArgs>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>com.google.errorprone</groupId>
|
||||
<artifactId>error_prone_core</artifactId>
|
||||
<version>2.42.0</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.errorprone</groupId>
|
||||
<artifactId>error_prone_core</artifactId>
|
||||
<version>2.42.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -1,21 +1,9 @@
|
||||
package org.toop;
|
||||
|
||||
import org.toop.app.App;
|
||||
import org.toop.framework.asset.ResourceLoader;
|
||||
import org.toop.framework.asset.ResourceManager;
|
||||
import org.toop.framework.audio.SoundManager;
|
||||
import org.toop.framework.networking.NetworkingClientManager;
|
||||
import org.toop.framework.networking.NetworkingInitializationException;
|
||||
|
||||
public final class Main {
|
||||
public static void main(String[] args) {
|
||||
initSystems();
|
||||
App.run(args);
|
||||
}
|
||||
|
||||
private static void initSystems() throws NetworkingInitializationException {
|
||||
ResourceManager.loadAssets(new ResourceLoader("app/src/main/resources/assets"));
|
||||
new Thread(NetworkingClientManager::new).start();
|
||||
new Thread(SoundManager::new).start();
|
||||
}
|
||||
static void main(String[] args) {
|
||||
App.run(args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,114 +1,276 @@
|
||||
package org.toop.app;
|
||||
|
||||
import org.toop.app.menu.MainMenu;
|
||||
import org.toop.app.menu.Menu;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.KeyCodeCombination;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.stage.Stage;
|
||||
import org.toop.framework.asset.ResourceManager;
|
||||
import org.toop.framework.asset.resources.CssAsset;
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.WidgetContainer;
|
||||
import org.toop.app.widget.complex.LoadingWidget;
|
||||
import org.toop.app.widget.display.SongDisplay;
|
||||
import org.toop.app.widget.popup.EscapePopup;
|
||||
import org.toop.app.widget.popup.QuitPopup;
|
||||
import org.toop.app.widget.view.MainView;
|
||||
import org.toop.framework.audio.*;
|
||||
import org.toop.framework.audio.events.AudioEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.framework.eventbus.GlobalEventBus;
|
||||
import org.toop.framework.networking.connection.NetworkingClientEventListener;
|
||||
import org.toop.framework.networking.connection.NetworkingClientManager;
|
||||
import org.toop.framework.resource.ResourceLoader;
|
||||
import org.toop.framework.resource.ResourceManager;
|
||||
import org.toop.framework.resource.events.AssetLoaderEvents;
|
||||
import org.toop.framework.resource.resources.CssAsset;
|
||||
import org.toop.framework.resource.resources.MusicAsset;
|
||||
import org.toop.framework.resource.resources.SoundEffectAsset;
|
||||
import org.toop.local.AppContext;
|
||||
import org.toop.local.AppSettings;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public final class App extends Application {
|
||||
private static Stage stage;
|
||||
private static StackPane root;
|
||||
private static Scene scene;
|
||||
|
||||
private static int width;
|
||||
private static int height;
|
||||
|
||||
private static boolean isQuitting;
|
||||
|
||||
private static class QuitMenu extends Menu {
|
||||
public QuitMenu() {
|
||||
final Region background = createBackground("quit_background");
|
||||
|
||||
final Text sure = createText("Are you sure?");
|
||||
|
||||
final Button yes = createButton("Yes", () -> { stage.close(); });
|
||||
final Button no = createButton("No", () -> { pop(); isQuitting = false; });
|
||||
|
||||
final HBox buttons = new HBox(50, yes, no);
|
||||
buttons.setAlignment(Pos.CENTER);
|
||||
|
||||
final VBox box = new VBox(35, sure, buttons);
|
||||
box.getStyleClass().add("quit_box");
|
||||
box.setAlignment(Pos.CENTER);
|
||||
box.setMaxWidth(350);
|
||||
box.setMaxHeight(200);
|
||||
|
||||
pane = new StackPane(background, box);
|
||||
pane.getStylesheets().add(ResourceManager.get(CssAsset.class, "quit.css").getUrl());
|
||||
|
||||
}
|
||||
}
|
||||
private static int height;
|
||||
private static int width;
|
||||
|
||||
public static void run(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws Exception {
|
||||
final StackPane root = new StackPane(new MainMenu().getPane());
|
||||
public void start(Stage stage) {
|
||||
// Start loading localization
|
||||
ResourceManager.loadAssets(new ResourceLoader("app/src/main/resources/localization"));
|
||||
ResourceManager.loadAssets(new ResourceLoader("app/src/main/resources/style"));
|
||||
|
||||
final StackPane root = WidgetContainer.setup();
|
||||
final Scene scene = new Scene(root);
|
||||
scene.getStylesheets().add(((CssAsset) ResourceManager.get("app.css")).getUrl());
|
||||
|
||||
stage.setTitle("pism");
|
||||
stage.setMinWidth(1080);
|
||||
stage.setMinHeight(720);
|
||||
stage.setOpacity(0.0);
|
||||
|
||||
stage.setTitle(AppContext.getString("app-title"));
|
||||
stage.titleProperty().bind(AppContext.bindToKey("app-title"));
|
||||
|
||||
stage.setWidth(0);
|
||||
stage.setHeight(0);
|
||||
|
||||
scene.getRoot();
|
||||
|
||||
stage.setMinWidth(1200);
|
||||
stage.setMinHeight(800);
|
||||
stage.setOnCloseRequest(event -> {
|
||||
event.consume();
|
||||
|
||||
if (!isQuitting) {
|
||||
quitPopup();
|
||||
}
|
||||
quit();
|
||||
});
|
||||
|
||||
stage.setScene(scene);
|
||||
stage.setResizable(false);
|
||||
|
||||
stage.show();
|
||||
stage.setResizable(true);
|
||||
|
||||
App.stage = stage;
|
||||
App.root = root;
|
||||
App.scene = scene;
|
||||
|
||||
App.width = (int)stage.getWidth();
|
||||
App.height = (int)stage.getHeight();
|
||||
|
||||
new EventFlow().addPostEvent(new AudioEvents.StartBackgroundMusic()).asyncPostEvent();
|
||||
new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(0.1)).asyncPostEvent();
|
||||
AppSettings.applySettings();
|
||||
|
||||
App.isQuitting = false;
|
||||
setKeybinds(root);
|
||||
|
||||
LoadingWidget loading = new LoadingWidget(Primitive.text(
|
||||
"Loading...", false), 0, 0, Integer.MAX_VALUE, false, false // Just set a high default
|
||||
);
|
||||
|
||||
WidgetContainer.setCurrentView(loading);
|
||||
|
||||
setOnLoadingSuccess(loading);
|
||||
|
||||
EventFlow loadingFlow = new EventFlow();
|
||||
|
||||
final boolean[] hasRun = {false};
|
||||
loadingFlow
|
||||
.listen(AssetLoaderEvents.LoadingProgressUpdate.class, e -> {
|
||||
if (!hasRun[0]) {
|
||||
hasRun[0] = true;
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
Platform.runLater(() -> stage.setOpacity(1.0));
|
||||
}
|
||||
|
||||
Platform.runLater(() -> {
|
||||
loading.setMaxAmount(e.isLoadingAmount());
|
||||
try {
|
||||
loading.setAmount(e.hasLoadedAmount());
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
if (e.hasLoadedAmount() >= e.isLoadingAmount()-1) {
|
||||
Platform.runLater(loading::triggerSuccess);
|
||||
loadingFlow.unsubscribe("init_loading");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}, false, "init_loading");
|
||||
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
try {
|
||||
executor.submit(
|
||||
() -> ResourceManager.loadAssets(new ResourceLoader("app/src/main/resources/assets")
|
||||
));
|
||||
} finally {
|
||||
executor.shutdown();
|
||||
}
|
||||
|
||||
stage.show();
|
||||
}
|
||||
|
||||
private void setKeybinds(StackPane root) {
|
||||
root.addEventHandler(KeyEvent.KEY_PRESSED,event -> {
|
||||
if (event.getCode() == KeyCode.ESCAPE) {
|
||||
escapePopup();
|
||||
}
|
||||
});
|
||||
stage.setFullScreenExitKeyCombination(
|
||||
new KeyCodeCombination(
|
||||
KeyCode.F11
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static void quitPopup() {
|
||||
isQuitting = true;
|
||||
push(new QuitMenu());
|
||||
public void escapePopup() {
|
||||
|
||||
if ( WidgetContainer.getCurrentView() == null
|
||||
|| WidgetContainer.getCurrentView() instanceof MainView) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Objects.requireNonNull(
|
||||
WidgetContainer.find(widget -> widget instanceof QuitPopup || widget instanceof EscapePopup)
|
||||
).isEmpty()) {
|
||||
WidgetContainer.removeFirst(QuitPopup.class);
|
||||
WidgetContainer.removeFirst(EscapePopup.class);
|
||||
return;
|
||||
}
|
||||
|
||||
EscapePopup escPopup = new EscapePopup();
|
||||
escPopup.show(Pos.CENTER);
|
||||
}
|
||||
|
||||
public static void activate(Menu menu) {
|
||||
pop();
|
||||
push(menu);
|
||||
private void setOnLoadingSuccess(LoadingWidget loading) {
|
||||
loading.setOnSuccess(() -> {
|
||||
|
||||
try {
|
||||
initSystems();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
AppSettings.applyMusicVolumeSettings();
|
||||
new EventFlow().addPostEvent(new AudioEvents.StartBackgroundMusic()).postEvent();
|
||||
loading.hide();
|
||||
WidgetContainer.add(Pos.CENTER, new MainView());
|
||||
WidgetContainer.add(Pos.BOTTOM_RIGHT, new SongDisplay());
|
||||
stage.setOnCloseRequest(event -> {
|
||||
event.consume();
|
||||
|
||||
if (WidgetContainer.getAllWidgets().stream().anyMatch(e -> e instanceof QuitPopup)) return;
|
||||
|
||||
QuitPopup a = new QuitPopup();
|
||||
a.show(Pos.CENTER);
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public static void push(Menu menu) {
|
||||
root.getChildren().addLast(menu.getPane());
|
||||
private void initSystems() throws InterruptedException { // TODO Move to better place
|
||||
|
||||
final int THREAD_COUNT = 2;
|
||||
CountDownLatch latch = new CountDownLatch(THREAD_COUNT);
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
ExecutorService threads = Executors.newFixedThreadPool(THREAD_COUNT);
|
||||
|
||||
try {
|
||||
|
||||
threads.submit(() -> {
|
||||
new NetworkingClientEventListener(
|
||||
GlobalEventBus.get(),
|
||||
new NetworkingClientManager(GlobalEventBus.get()));
|
||||
|
||||
latch.countDown();
|
||||
});
|
||||
|
||||
threads.submit(() -> {
|
||||
MusicManager<MusicAsset> musicManager =
|
||||
new MusicManager<>(
|
||||
GlobalEventBus.get(),
|
||||
ResourceManager.getAllOfTypeAndRemoveWrapper(MusicAsset.class),
|
||||
true
|
||||
);
|
||||
|
||||
SoundEffectManager<SoundEffectAsset> soundEffectManager =
|
||||
new SoundEffectManager<>(ResourceManager.getAllOfType(SoundEffectAsset.class));
|
||||
|
||||
AudioVolumeManager audioVolumeManager = new AudioVolumeManager()
|
||||
.registerManager(VolumeControl.MASTERVOLUME, musicManager)
|
||||
.registerManager(VolumeControl.MASTERVOLUME, soundEffectManager)
|
||||
.registerManager(VolumeControl.FX, soundEffectManager)
|
||||
.registerManager(VolumeControl.MUSIC, musicManager);
|
||||
|
||||
new AudioEventListener<>(
|
||||
GlobalEventBus.get(),
|
||||
musicManager,
|
||||
soundEffectManager,
|
||||
audioVolumeManager
|
||||
).initListeners("medium-button-click.wav");
|
||||
|
||||
latch.countDown();
|
||||
});
|
||||
|
||||
} finally {
|
||||
latch.await();
|
||||
threads.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
public static void quit() {
|
||||
stage.close();
|
||||
System.exit(0); // TODO: This is like dropping a nuke
|
||||
}
|
||||
|
||||
public static void pop() {
|
||||
root.getChildren().removeLast();
|
||||
public static void setFullscreen(boolean fullscreen) {
|
||||
stage.setFullScreen(fullscreen);
|
||||
|
||||
width = (int)stage.getWidth();
|
||||
height = (int)stage.getHeight();
|
||||
}
|
||||
|
||||
public static int getWidth() { return width; }
|
||||
public static int getHeight() { return height; }
|
||||
public static void setStyle(String theme, String layoutSize) {
|
||||
scene.getStylesheets().clear();
|
||||
|
||||
scene.getStylesheets().add(ResourceManager.<CssAsset>get("general.css").getUrl());
|
||||
scene.getStylesheets().add(ResourceManager.<CssAsset>get(theme + ".css").getUrl());
|
||||
scene.getStylesheets().add(ResourceManager.<CssAsset>get(layoutSize + ".css").getUrl());
|
||||
}
|
||||
|
||||
public static int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public static int getHeight() {
|
||||
return height;
|
||||
}
|
||||
}
|
||||
54
app/src/main/java/org/toop/app/GameInformation.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package org.toop.app;
|
||||
|
||||
public class GameInformation {
|
||||
public enum Type {
|
||||
TICTACTOE(2, 5),
|
||||
REVERSI(2, 10);
|
||||
|
||||
private final int playerCount;
|
||||
private final int maxDepth;
|
||||
|
||||
Type(int playerCount, int maxDepth) {
|
||||
this.playerCount = playerCount;
|
||||
this.maxDepth = maxDepth;
|
||||
}
|
||||
|
||||
public int getPlayerCount() {
|
||||
return playerCount;
|
||||
}
|
||||
|
||||
public int getMaxDepth() {
|
||||
return maxDepth;
|
||||
}
|
||||
|
||||
public String getTypeToString() {
|
||||
String name = this.name();
|
||||
return switch (name) {
|
||||
case "TICTACTOE" -> "TicTacToe";
|
||||
case "REVERSI" -> "Reversi";
|
||||
case "CONNECT4" -> "Connect4";
|
||||
case "BATTLESHIP" -> "Battleship";
|
||||
default -> name;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class Player {
|
||||
public String name = "";
|
||||
public boolean isHuman = true;
|
||||
public int computerDifficulty = 1;
|
||||
public int computerThinkTime = 1;
|
||||
}
|
||||
|
||||
public final Type type;
|
||||
public final Player[] players;
|
||||
|
||||
public GameInformation(Type type) {
|
||||
this.type = type;
|
||||
players = new Player[type.getPlayerCount()];
|
||||
|
||||
for (int i = 0; i < players.length; i++) {
|
||||
players[i] = new Player();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package org.toop.app;
|
||||
|
||||
public enum GameType {
|
||||
TICTACTOE, REVERSI;
|
||||
|
||||
public static String toName(GameType type) {
|
||||
return switch (type) {
|
||||
case TICTACTOE -> "Tic Tac Toe";
|
||||
case REVERSI -> "Reversi";
|
||||
};
|
||||
}
|
||||
|
||||
public static GameType toType(String name) {
|
||||
return switch (name) {
|
||||
case "Tic Tac Toe" -> TICTACTOE;
|
||||
case "Reversi" -> REVERSI;
|
||||
|
||||
default -> TICTACTOE;
|
||||
};
|
||||
}
|
||||
}
|
||||
376
app/src/main/java/org/toop/app/Server.java
Normal file
@@ -0,0 +1,376 @@
|
||||
package org.toop.app;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Pos;
|
||||
import org.toop.app.gameControllers.*;
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.WidgetContainer;
|
||||
import org.toop.app.widget.complex.LoadingWidget;
|
||||
import org.toop.app.widget.popup.ChallengePopup;
|
||||
import org.toop.app.widget.popup.ErrorPopup;
|
||||
import org.toop.app.widget.popup.SendChallengePopup;
|
||||
import org.toop.app.widget.view.ServerView;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.framework.game.players.ArtificialPlayer;
|
||||
import org.toop.framework.game.players.OnlinePlayer;
|
||||
import org.toop.framework.gameFramework.controller.GameController;
|
||||
import org.toop.framework.eventbus.GlobalEventBus;
|
||||
import org.toop.framework.gameFramework.model.player.Player;
|
||||
import org.toop.framework.networking.connection.clients.TournamentNetworkingClient;
|
||||
import org.toop.framework.networking.connection.events.NetworkEvents;
|
||||
import org.toop.framework.networking.connection.types.NetworkingConnector;
|
||||
import org.toop.framework.networking.server.gateway.NettyGatewayServer;
|
||||
import org.toop.game.players.ai.mcts.MCTSAI3;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public final class Server {
|
||||
private NettyGatewayServer nettyGatewayServer;
|
||||
|
||||
private String user = "";
|
||||
private long clientId = -1;
|
||||
|
||||
private final List<String> onlinePlayers = new CopyOnWriteArrayList<>();
|
||||
private final List<String> gameList = new CopyOnWriteArrayList<>();
|
||||
|
||||
private ServerView primary;
|
||||
private boolean isPolling = true;
|
||||
|
||||
private GameController gameController;
|
||||
|
||||
private final AtomicBoolean isSingleGame = new AtomicBoolean(false);
|
||||
|
||||
private ScheduledExecutorService scheduler;
|
||||
|
||||
private EventFlow connectFlow;
|
||||
|
||||
public static GameInformation.Type gameToType(String game) {
|
||||
if (game.equalsIgnoreCase("tic-tac-toe")) {
|
||||
return GameInformation.Type.TICTACTOE;
|
||||
} else if (game.equalsIgnoreCase("reversi")) {
|
||||
return GameInformation.Type.REVERSI;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Server(String ip, String port, String user) {
|
||||
this(ip, port, user, null);
|
||||
}
|
||||
|
||||
// Server has to deal with ALL network related listen events. This "server" can then interact with the manager to make stuff happen.
|
||||
// This prevents data races where events get sent to the game manager but the manager isn't ready yet.
|
||||
public Server(String ip, String port, String user, NettyGatewayServer nettyGatewayServer) {
|
||||
if (ip.split("\\.").length < 4) {
|
||||
new ErrorPopup("\"" + ip + "\" " + AppContext.getString("is-not-a-valid-ip-address"));
|
||||
return;
|
||||
}
|
||||
|
||||
int parsedPort;
|
||||
|
||||
try {
|
||||
parsedPort = Integer.parseInt(port);
|
||||
} catch (NumberFormatException _) {
|
||||
new ErrorPopup("\"" + port + "\" " + AppContext.getString("is-not-a-valid-port"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (user.isEmpty() || user.matches("^[0-9].*")) {
|
||||
new ErrorPopup(AppContext.getString("invalid-username"));
|
||||
return;
|
||||
}
|
||||
|
||||
this.nettyGatewayServer = nettyGatewayServer;
|
||||
|
||||
final int reconnectAttempts = 10;
|
||||
|
||||
LoadingWidget loading = new LoadingWidget(
|
||||
Primitive.text("connecting"), 0, 0, reconnectAttempts, true, true
|
||||
);
|
||||
|
||||
WidgetContainer.getCurrentView().transitionNextCustom(loading, "disconnect", this::disconnect);
|
||||
|
||||
var a = new EventFlow()
|
||||
.addPostEvent(NetworkEvents.StartClient.class,
|
||||
new TournamentNetworkingClient(GlobalEventBus.get()),
|
||||
new NetworkingConnector(ip, parsedPort, reconnectAttempts, 1, TimeUnit.SECONDS)
|
||||
);
|
||||
|
||||
loading.setOnFailure(() -> {
|
||||
if (WidgetContainer.getCurrentView() == loading) WidgetContainer.getCurrentView().transitionPrevious();
|
||||
a.unsubscribeAll();
|
||||
WidgetContainer.add(
|
||||
Pos.CENTER,
|
||||
new ErrorPopup(AppContext.getString("connecting-failed") + " " + ip + ":" + port)
|
||||
);
|
||||
});
|
||||
|
||||
a.onResponse(NetworkEvents.CreatedIdForClient.class, e -> clientId = e.clientId(), true);
|
||||
|
||||
a.onResponse(NetworkEvents.StartClientResponse.class, e -> {
|
||||
if (!e.successful()) {
|
||||
return;
|
||||
}
|
||||
|
||||
primary = new ServerView(user, this::sendChallenge, user, clientId);
|
||||
|
||||
WidgetContainer.getCurrentView().transitionNextCustom(primary, "disconnect", this::disconnect);
|
||||
|
||||
a.unsubscribe("connecting");
|
||||
a.unsubscribe("startclient");
|
||||
|
||||
this.user = user;
|
||||
|
||||
new EventFlow().addPostEvent(new NetworkEvents.SendLogin(clientId, user)).postEvent();
|
||||
|
||||
startPopulateScheduler();
|
||||
populateGameList();
|
||||
|
||||
primary.removeViewFromPreviousChain(loading);
|
||||
|
||||
}, false, "startclient")
|
||||
.listen(
|
||||
NetworkEvents.ConnectTry.class,
|
||||
e -> {
|
||||
if (clientId != e.clientId()) return;
|
||||
Platform.runLater(
|
||||
() -> {
|
||||
try {
|
||||
loading.setAmount(e.amount());
|
||||
if (e.amount() >= loading.getMaxAmount()) {
|
||||
loading.triggerFailure();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
false, "connecting"
|
||||
)
|
||||
.postEvent();
|
||||
|
||||
a.listen(NetworkEvents.ChallengeResponse.class, this::handleReceivedChallenge, false, "challenge")
|
||||
.listen(NetworkEvents.GameMatchResponse.class, this::handleMatchResponse, false, "match-response")
|
||||
.listen(NetworkEvents.GameResultResponse.class, this::handleGameResult, false, "game-result")
|
||||
.listen(NetworkEvents.GameMoveResponse.class, this::handleReceivedMove, false, "game-move")
|
||||
.listen(NetworkEvents.YourTurnResponse.class, this::handleYourTurn, false, "your-turn")
|
||||
.listen(NetworkEvents.ClosedConnection.class, this::closedConnection, false, "closed-connection")
|
||||
.listen(NetworkEvents.TournamentResultResponse.class, this::handleTournamentResult, false, "tournament-result");
|
||||
|
||||
connectFlow = a;
|
||||
}
|
||||
|
||||
private void sendChallenge(String opponent) {
|
||||
if (!isPolling) return;
|
||||
|
||||
var a = new SendChallengePopup(this, opponent, (playerInformation, gameType) -> {
|
||||
new EventFlow().addPostEvent(new NetworkEvents.SendChallenge(clientId, opponent, gameType)).postEvent();
|
||||
isSingleGame.set(true);
|
||||
});
|
||||
|
||||
a.show(Pos.CENTER);
|
||||
}
|
||||
|
||||
private void handleMatchResponse(NetworkEvents.GameMatchResponse response) {
|
||||
// TODO: Redo all of this mess
|
||||
if (gameController != null) {
|
||||
gameController.stop();
|
||||
}
|
||||
|
||||
gameController = null;
|
||||
|
||||
// if (!isPolling) return;
|
||||
|
||||
String gameType = extractQuotedValue(response.gameType());
|
||||
if (response.clientId() == clientId) {
|
||||
isPolling = false;
|
||||
onlinePlayers.clear();
|
||||
|
||||
final GameInformation.Type type = gameToType(gameType);
|
||||
if (type == null) {
|
||||
new ErrorPopup("Unsupported game type: " + gameType);
|
||||
return;
|
||||
}
|
||||
|
||||
final String startingPlayer = response.playerToMove();
|
||||
final int userStartingTurn = startingPlayer.equalsIgnoreCase(user) ? 0 : 1;
|
||||
final int opponentStartingTurn = 1 - userStartingTurn;
|
||||
|
||||
final GameInformation information = new GameInformation(type);
|
||||
information.players[userStartingTurn].name = user;
|
||||
information.players[opponentStartingTurn].name = response.opponent();
|
||||
|
||||
Player[] players = new Player[2];
|
||||
|
||||
players[userStartingTurn] = new ArtificialPlayer(new MCTSAI3(1000, 8), user);
|
||||
players[opponentStartingTurn] = new OnlinePlayer(response.opponent());
|
||||
|
||||
switch (type) {
|
||||
case TICTACTOE -> gameController = new TicTacToeBitController(players);
|
||||
case REVERSI -> gameController = new ReversiBitController(players);
|
||||
default -> new ErrorPopup("Unsupported game type.");
|
||||
|
||||
}
|
||||
|
||||
if (gameController != null) {
|
||||
primary.reEnableButton(); // Re enable subscribe button
|
||||
gameController.start();
|
||||
isPolling = true; // Fixes server getting stuck
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleYourTurn(NetworkEvents.YourTurnResponse response) {
|
||||
if (gameController == null) {
|
||||
return;
|
||||
}
|
||||
gameController.onYourTurn(response);
|
||||
|
||||
}
|
||||
|
||||
private void handleGameResult(NetworkEvents.GameResultResponse response) {
|
||||
if (gameController == null) {
|
||||
return;
|
||||
}
|
||||
gameController.gameFinished(response);
|
||||
}
|
||||
|
||||
private void handleTournamentResult(NetworkEvents.TournamentResultResponse response) {
|
||||
IO.println(response.gameType());
|
||||
IO.println(Arrays.toString(response.names()));
|
||||
IO.println(Arrays.toString(response.scoreTypes()));
|
||||
IO.println(Arrays.toString(response.scores().toArray()));
|
||||
}
|
||||
|
||||
private void handleReceivedMove(NetworkEvents.GameMoveResponse response) {
|
||||
if (gameController == null) {
|
||||
return;
|
||||
}
|
||||
gameController.onMoveReceived(response);
|
||||
}
|
||||
|
||||
private void handleReceivedChallenge(NetworkEvents.ChallengeResponse response) {
|
||||
if (!isPolling) return;
|
||||
|
||||
String challengerName = extractQuotedValue(response.challengerName());
|
||||
String gameType = extractQuotedValue(response.gameType());
|
||||
final String finalGameType = gameType;
|
||||
var a = new ChallengePopup(challengerName, gameType, (playerInformation) -> {
|
||||
final long challengeId = Long.parseLong(response.challengeId().replaceAll("\\D", ""));
|
||||
new EventFlow().addPostEvent(new NetworkEvents.SendAcceptChallenge(clientId, challengeId)).postEvent();
|
||||
isSingleGame.set(true);
|
||||
});
|
||||
|
||||
a.show(Pos.CENTER);
|
||||
}
|
||||
|
||||
private void sendMessage(String message) {
|
||||
new EventFlow().addPostEvent(new NetworkEvents.SendMessage(clientId, message)).postEvent();
|
||||
}
|
||||
|
||||
private void disconnect() {
|
||||
new EventFlow().addPostEvent(new NetworkEvents.CloseClient(clientId)).postEvent();
|
||||
isPolling = false;
|
||||
stopScheduler();
|
||||
connectFlow.unsubscribeAll();
|
||||
|
||||
if (nettyGatewayServer != null) {
|
||||
nettyGatewayServer.stop();
|
||||
}
|
||||
|
||||
WidgetContainer.getCurrentView().transitionPrevious();
|
||||
}
|
||||
|
||||
private void closedConnection(NetworkEvents.ClosedConnection e) {
|
||||
new EventFlow().addPostEvent(new NetworkEvents.CloseClient(clientId)).postEvent();
|
||||
isPolling = false;
|
||||
stopScheduler();
|
||||
connectFlow.unsubscribeAll();
|
||||
|
||||
if (nettyGatewayServer != null) {
|
||||
nettyGatewayServer.stop();
|
||||
}
|
||||
|
||||
WidgetContainer.getCurrentView().transitionPrevious();
|
||||
WidgetContainer.add(Pos.CENTER, new ErrorPopup("Server closed connection."));
|
||||
}
|
||||
|
||||
private void forfeitGame() {
|
||||
new EventFlow().addPostEvent(new NetworkEvents.SendForfeit(clientId)).postEvent();
|
||||
}
|
||||
|
||||
private void exitGame() {
|
||||
forfeitGame();
|
||||
startPopulateScheduler();
|
||||
}
|
||||
|
||||
private void gameOver(){
|
||||
startPopulateScheduler();
|
||||
}
|
||||
|
||||
private void startPopulateScheduler() {
|
||||
isPolling = true;
|
||||
isSingleGame.set(false);
|
||||
stopScheduler();
|
||||
|
||||
new EventFlow()
|
||||
.listen(NetworkEvents.PlayerlistResponse.class, e -> {
|
||||
if (e.clientId() == clientId) {
|
||||
onlinePlayers.clear();
|
||||
onlinePlayers.addAll(List.of(e.playerlist()));
|
||||
onlinePlayers.removeIf(name -> name.equalsIgnoreCase(user));
|
||||
primary.update(onlinePlayers);
|
||||
}
|
||||
}, false);
|
||||
|
||||
scheduler = Executors.newSingleThreadScheduledExecutor();
|
||||
scheduler.scheduleAtFixedRate(() -> {
|
||||
if (isPolling) {
|
||||
new EventFlow().addPostEvent(new NetworkEvents.SendGetPlayerlist(clientId)).postEvent();
|
||||
} else {
|
||||
stopScheduler();
|
||||
}
|
||||
}, 0, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
private void stopScheduler() {
|
||||
if (scheduler != null && !scheduler.isShutdown()) {
|
||||
scheduler.shutdownNow();
|
||||
}
|
||||
}
|
||||
|
||||
private void gamesListFromServerHandler(NetworkEvents.GamelistResponse event) {
|
||||
gameList.clear();
|
||||
var gl = new java.util.ArrayList<>(List.of(event.gamelist()));
|
||||
gl.sort(String::compareTo);
|
||||
gameList.addAll(gl);
|
||||
primary.updateGameList(gl);
|
||||
}
|
||||
|
||||
public void populateGameList() {
|
||||
new EventFlow().addPostEvent(new NetworkEvents.SendGetGamelist(clientId))
|
||||
.listen(NetworkEvents.GamelistResponse.class, this::gamesListFromServerHandler, true)
|
||||
.postEvent();
|
||||
}
|
||||
|
||||
public List<String> getGameList() {
|
||||
return gameList;
|
||||
}
|
||||
|
||||
private String extractQuotedValue(String s) {
|
||||
int first = s.indexOf('"');
|
||||
int last = s.lastIndexOf('"');
|
||||
if (first >= 0 && last > first) {
|
||||
return s.substring(first + 1, last);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
245
app/src/main/java/org/toop/app/canvas/BitGameCanvas.java
Normal file
@@ -0,0 +1,245 @@
|
||||
package org.toop.app.canvas;
|
||||
|
||||
import javafx.animation.KeyFrame;
|
||||
import javafx.animation.Timeline;
|
||||
import javafx.scene.canvas.Canvas;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.input.MouseButton;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.util.Duration;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.framework.gameFramework.model.game.TurnBasedGame;
|
||||
import org.toop.framework.gameFramework.view.GUIEvents;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public abstract class BitGameCanvas implements GameCanvas {
|
||||
protected record Cell(float x, float y, float width, float height) {
|
||||
public boolean isInside(double x, double y) {
|
||||
return x >= this.x && x <= this.x + width &&
|
||||
y >= this.y && y <= this.y + height;
|
||||
}
|
||||
}
|
||||
|
||||
protected final Canvas canvas;
|
||||
protected final GraphicsContext graphics;
|
||||
|
||||
protected final Color color;
|
||||
protected final Color backgroundColor;
|
||||
|
||||
protected final int width;
|
||||
protected final int height;
|
||||
|
||||
protected final int rowSize;
|
||||
protected final int columnSize;
|
||||
|
||||
protected final int gapSize;
|
||||
protected final boolean edges;
|
||||
|
||||
protected final Cell[] cells;
|
||||
|
||||
private Consumer<Long> onCellCLicked;
|
||||
|
||||
public void setOnCellClicked(Consumer<Long> onClick) {
|
||||
this.onCellCLicked = onClick;
|
||||
}
|
||||
|
||||
protected BitGameCanvas(Color color, Color backgroundColor, int width, int height, int rowSize, int columnSize, int gapSize, boolean edges) {
|
||||
canvas = new Canvas(width, height);
|
||||
graphics = canvas.getGraphicsContext2D();
|
||||
|
||||
this.onCellCLicked = (c) -> new EventFlow().addPostEvent(GUIEvents.PlayerAttemptedMove.class, c).postEvent();
|
||||
|
||||
this.color = color;
|
||||
this.backgroundColor = backgroundColor;
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
this.rowSize = rowSize;
|
||||
this.columnSize = columnSize;
|
||||
|
||||
this.gapSize = gapSize;
|
||||
this.edges = edges;
|
||||
|
||||
cells = new Cell[rowSize * columnSize];
|
||||
|
||||
final float cellWidth = ((float) width - gapSize * rowSize - gapSize) / rowSize;
|
||||
final float cellHeight = ((float) height - gapSize * columnSize - gapSize) / columnSize;
|
||||
|
||||
for (int y = 0; y < columnSize; y++) {
|
||||
final float startY = y * cellHeight + y * gapSize + gapSize;
|
||||
|
||||
for (int x = 0; x < rowSize; x++) {
|
||||
final float startX = x * cellWidth + x * gapSize + gapSize;
|
||||
cells[x + y * rowSize] = new Cell(startX, startY, cellWidth, cellHeight);
|
||||
}
|
||||
}
|
||||
|
||||
canvas.setOnMouseClicked(event -> {
|
||||
|
||||
if (event.getButton() != MouseButton.PRIMARY) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int column = (int) ((event.getX() / this.width) * rowSize);
|
||||
final int row = (int) ((event.getY() / this.height) * columnSize);
|
||||
|
||||
final Cell cell = cells[column + row * rowSize];
|
||||
|
||||
if (cell.isInside(event.getX(), event.getY())) {
|
||||
event.consume();
|
||||
this.onCellCLicked.accept(1L << (column + row * rowSize));
|
||||
}
|
||||
});
|
||||
|
||||
render();
|
||||
}
|
||||
|
||||
public void loopOverBoard(long bb, Consumer<Integer> onCell){
|
||||
while (bb != 0) {
|
||||
int idx = Long.numberOfTrailingZeros(bb); // index of least-significant 1-bit
|
||||
onCell.accept(idx);
|
||||
|
||||
bb &= bb - 1; // clear LSB 1-bit
|
||||
}
|
||||
}
|
||||
|
||||
private void render() {
|
||||
graphics.setFill(backgroundColor);
|
||||
graphics.fillRect(0, 0, width, height);
|
||||
|
||||
graphics.setFill(color);
|
||||
|
||||
for (int x = 0; x < rowSize - 1; x++) {
|
||||
final float start = cells[x].x + cells[x].width;
|
||||
graphics.fillRect(start, gapSize, gapSize, height - gapSize * 2);
|
||||
}
|
||||
|
||||
for (int y = 0; y < columnSize - 1; y++) {
|
||||
final float start = cells[y * rowSize].y + cells[y * rowSize].height;
|
||||
graphics.fillRect(gapSize, start, width - gapSize * 2, gapSize);
|
||||
}
|
||||
|
||||
if (edges) {
|
||||
graphics.fillRect(0, 0, width, gapSize);
|
||||
graphics.fillRect(0, 0, gapSize, height);
|
||||
|
||||
graphics.fillRect(width - gapSize, 0, gapSize, height);
|
||||
graphics.fillRect(0, height - gapSize, width, gapSize);
|
||||
}
|
||||
}
|
||||
|
||||
public void fill(Color color, int cell) {
|
||||
final float x = cells[cell].x();
|
||||
final float y = cells[cell].y();
|
||||
|
||||
final float width = cells[cell].width();
|
||||
final float height = cells[cell].height();
|
||||
|
||||
graphics.setFill(color);
|
||||
graphics.fillRect(x, y, width, height);
|
||||
}
|
||||
|
||||
public void clear(int cell) {
|
||||
final float x = cells[cell].x();
|
||||
final float y = cells[cell].y();
|
||||
|
||||
final float width = cells[cell].width();
|
||||
final float height = cells[cell].height();
|
||||
|
||||
graphics.clearRect(x, y, width, height);
|
||||
|
||||
graphics.setFill(backgroundColor);
|
||||
graphics.fillRect(x, y, width, height);
|
||||
}
|
||||
|
||||
public void clearAll() {
|
||||
for (int i = 0; i < cells.length; i++) {
|
||||
clear(i);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawPlayerMove(int player, int move) {
|
||||
final float x = cells[move].x() + gapSize;
|
||||
final float y = cells[move].y() + gapSize;
|
||||
|
||||
final float width = cells[move].width() - gapSize * 2;
|
||||
final float height = cells[move].height() - gapSize * 2;
|
||||
|
||||
graphics.setFill(color);
|
||||
graphics.setFont(Font.font("Arial", 40)); // TODO different font and size
|
||||
graphics.fillText(String.valueOf(player), x + width, y + height);
|
||||
}
|
||||
|
||||
public void drawDot(Color color, int cell) {
|
||||
final float x = cells[cell].x() + gapSize;
|
||||
final float y = cells[cell].y() + gapSize;
|
||||
|
||||
final float width = cells[cell].width() - gapSize * 2;
|
||||
final float height = cells[cell].height() - gapSize * 2;
|
||||
|
||||
graphics.setFill(color);
|
||||
graphics.fillOval(x, y, width, height);
|
||||
}
|
||||
|
||||
public void drawInnerDot(Color color, int cell, boolean slightlyBigger) {
|
||||
final float x = cells[cell].x() + gapSize;
|
||||
final float y = cells[cell].y() + gapSize;
|
||||
|
||||
float multiplier = slightlyBigger?1.4f:1.5f;
|
||||
|
||||
final float width = (cells[cell].width() - gapSize * 2)/multiplier;
|
||||
final float height = (cells[cell].height() - gapSize * 2)/multiplier;
|
||||
|
||||
float offset = slightlyBigger?5f:4f;
|
||||
|
||||
graphics.setFill(color);
|
||||
graphics.fillOval(x + width/offset, y + height/offset, width, height);
|
||||
}
|
||||
|
||||
private void drawDotScaled(Color color, int cell, double scale) {
|
||||
final float cx = cells[cell].x() + gapSize;
|
||||
final float cy = cells[cell].y() + gapSize;
|
||||
|
||||
final float fullWidth = cells[cell].width() - gapSize * 2;
|
||||
final float height = cells[cell].height() - gapSize * 2;
|
||||
|
||||
final float scaledWidth = (float)(fullWidth * scale);
|
||||
final float offsetX = (fullWidth - scaledWidth) / 2;
|
||||
|
||||
graphics.setFill(color);
|
||||
graphics.fillOval(cx + offsetX, cy, scaledWidth, height);
|
||||
}
|
||||
|
||||
public Timeline flipDot(Color fromColor, Color toColor, int cell) {
|
||||
final int steps = 60;
|
||||
final long duration = 250;
|
||||
final double interval = duration / (double) steps;
|
||||
|
||||
final Timeline timeline = new Timeline();
|
||||
|
||||
for (int i = 0; i <= steps; i++) {
|
||||
final double t = i / (double) steps;
|
||||
final KeyFrame keyFrame = new KeyFrame(Duration.millis(i * interval),
|
||||
_ -> {
|
||||
clear(cell);
|
||||
|
||||
final double scale = t <= 0.5 ? 1 - 2 * t : 2 * t - 1;
|
||||
final Color currentColor = t < 0.5 ? fromColor : toColor;
|
||||
|
||||
drawDotScaled(currentColor, cell, scale);
|
||||
}
|
||||
);
|
||||
|
||||
timeline.getKeyFrames().add(keyFrame);
|
||||
}
|
||||
|
||||
return timeline;
|
||||
}
|
||||
|
||||
public Canvas getCanvas() {
|
||||
return canvas;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.toop.app.canvas;
|
||||
|
||||
import org.toop.framework.gameFramework.model.game.TurnBasedGame;
|
||||
|
||||
public interface DrawPlayerHover {
|
||||
void drawPlayerHover(int player, int move, TurnBasedGame game);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package org.toop.app.canvas;
|
||||
|
||||
public interface DrawPlayerMove {
|
||||
void drawPlayerMove(int player, int move);
|
||||
}
|
||||
9
app/src/main/java/org/toop/app/canvas/GameCanvas.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package org.toop.app.canvas;
|
||||
|
||||
import javafx.scene.canvas.Canvas;
|
||||
import org.toop.framework.gameFramework.model.game.TurnBasedGame;
|
||||
|
||||
public interface GameCanvas {
|
||||
Canvas getCanvas();
|
||||
void redraw(TurnBasedGame gameCopy);
|
||||
}
|
||||
68
app/src/main/java/org/toop/app/canvas/ReversiBitCanvas.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package org.toop.app.canvas;
|
||||
|
||||
import javafx.scene.paint.Color;
|
||||
import org.toop.app.App;
|
||||
import org.toop.framework.game.games.reversi.BitboardReversi;
|
||||
import org.toop.framework.game.players.LocalPlayer;
|
||||
import org.toop.framework.gameFramework.model.game.TurnBasedGame;
|
||||
|
||||
public class ReversiBitCanvas extends BitGameCanvas {
|
||||
private TurnBasedGame gameCopy;
|
||||
private int previousCell;
|
||||
public ReversiBitCanvas() {
|
||||
super(Color.GRAY, new Color(0f, 0.4f, 0.2f, 1f), (App.getHeight() / 4) * 3, (App.getHeight() / 4) * 3, 8, 8, 5, true);
|
||||
canvas.setOnMouseMoved(event -> {
|
||||
double mouseX = event.getX();
|
||||
double mouseY = event.getY();
|
||||
int cellId = -1;
|
||||
|
||||
BitGameCanvas.Cell hovered = null;
|
||||
for (BitGameCanvas.Cell cell : cells) {
|
||||
if (cell.isInside(mouseX, mouseY)) {
|
||||
hovered = cell;
|
||||
cellId = turnCoordsIntoCellId(mouseX, mouseY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hovered != null) {
|
||||
checkHoverDots(hovered, cellId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private int turnCoordsIntoCellId(double x, double y) {
|
||||
final int column = (int) ((x / this.width) * rowSize);
|
||||
final int row = (int) ((y / this.height) * columnSize);
|
||||
return column + row * rowSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void redraw(TurnBasedGame gameCopy) {
|
||||
this.gameCopy = gameCopy;
|
||||
clearAll();
|
||||
long[] board = gameCopy.getBoard();
|
||||
loopOverBoard(board[0], (i) -> drawDot(Color.WHITE, i));
|
||||
loopOverBoard(board[1], (i) -> drawDot(Color.BLACK, i));
|
||||
}
|
||||
|
||||
public void drawLegalDots(TurnBasedGame gameCopy){
|
||||
long legal = gameCopy.getLegalMoves();
|
||||
loopOverBoard(legal, (i) -> drawInnerDot(gameCopy.getCurrentTurn()==0?new Color(1f,1f,1f,0.65f) :new Color(0f,0f,0f,0.65f), i,false));
|
||||
}
|
||||
|
||||
private void checkHoverDots(BitGameCanvas.Cell hovered, int cellId){
|
||||
if (previousCell == cellId){
|
||||
return;
|
||||
}
|
||||
long backflips = ((BitboardReversi)gameCopy).getFlips(1L << previousCell);
|
||||
loopOverBoard(backflips, (i) -> drawInnerDot(gameCopy.getCurrentTurn()==1?Color.WHITE:Color.BLACK, i,true));
|
||||
previousCell = cellId;
|
||||
if (gameCopy.getPlayer(gameCopy.getCurrentTurn()) instanceof LocalPlayer) {
|
||||
long legal = gameCopy.getLegalMoves();
|
||||
if ((legal & (1L << cellId)) != 0) {
|
||||
long flips = ((BitboardReversi) gameCopy).getFlips(1L << cellId);
|
||||
loopOverBoard(flips, (i) -> drawInnerDot(gameCopy.getCurrentTurn() == 0 ? Color.WHITE : Color.BLACK, i, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package org.toop.app.canvas;
|
||||
|
||||
import javafx.scene.paint.Color;
|
||||
import org.toop.app.App;
|
||||
import org.toop.framework.gameFramework.model.game.TurnBasedGame;
|
||||
|
||||
public class TicTacToeBitCanvas extends BitGameCanvas{
|
||||
public TicTacToeBitCanvas() {
|
||||
super(
|
||||
Color.GRAY,
|
||||
Color.TRANSPARENT,
|
||||
(App.getHeight() / 4) * 3,
|
||||
(App.getHeight() / 4) * 3,
|
||||
3,
|
||||
3,
|
||||
30,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void redraw(TurnBasedGame gameCopy) {
|
||||
clearAll();
|
||||
drawMoves(gameCopy.getBoard());
|
||||
}
|
||||
|
||||
private void drawMoves(long[] gameBoard){
|
||||
loopOverBoard(gameBoard[0], (i) -> drawX(Color.RED, i));
|
||||
loopOverBoard(gameBoard[1], (i) -> drawO(Color.BLUE, i));
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void drawX(Color color, int cell) {
|
||||
graphics.setStroke(color);
|
||||
graphics.setLineWidth(gapSize);
|
||||
|
||||
final float x = cells[cell].x() + gapSize;
|
||||
final float y = cells[cell].y() + gapSize;
|
||||
|
||||
final float width = cells[cell].width() - gapSize * 2;
|
||||
final float height = cells[cell].height() - gapSize * 2;
|
||||
|
||||
graphics.strokeLine(x, y, x + width, y + height);
|
||||
graphics.strokeLine(x + width, y, x, y + height);
|
||||
}
|
||||
|
||||
public void drawO(Color color, int cell) {
|
||||
graphics.setStroke(color);
|
||||
graphics.setLineWidth(gapSize);
|
||||
|
||||
final float x = cells[cell].x() + gapSize;
|
||||
final float y = cells[cell].y() + gapSize;
|
||||
|
||||
final float width = cells[cell].width() - gapSize * 2;
|
||||
final float height = cells[cell].height() - gapSize * 2;
|
||||
|
||||
graphics.strokeOval(x, y, width, height);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
package org.toop.app.gameControllers;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Pos;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.toop.app.canvas.GameCanvas;
|
||||
import org.toop.app.canvas.ReversiBitCanvas;
|
||||
import org.toop.app.widget.WidgetContainer;
|
||||
import org.toop.app.widget.view.GameView;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.framework.eventbus.GlobalEventBus;
|
||||
import org.toop.framework.game.games.reversi.BitboardReversi;
|
||||
import org.toop.framework.gameFramework.controller.GameController;
|
||||
import org.toop.framework.gameFramework.model.game.threadBehaviour.SupportsOnlinePlay;
|
||||
import org.toop.framework.gameFramework.model.game.TurnBasedGame;
|
||||
import org.toop.framework.gameFramework.model.game.threadBehaviour.ThreadBehaviour;
|
||||
import org.toop.framework.gameFramework.model.player.Player;
|
||||
import org.toop.framework.gameFramework.view.GUIEvents;
|
||||
import org.toop.framework.networking.connection.events.NetworkEvents;
|
||||
import org.toop.framework.game.players.LocalPlayer;
|
||||
|
||||
public class GenericGameController implements GameController {
|
||||
protected final EventFlow eventFlow = new EventFlow();
|
||||
|
||||
// Logger for logging
|
||||
protected final Logger logger = LogManager.getLogger(this.getClass());
|
||||
|
||||
// Reference to gameView view
|
||||
protected final GameView gameView;
|
||||
|
||||
// Reference to game canvas
|
||||
protected final GameCanvas canvas;
|
||||
|
||||
protected final TurnBasedGame game; // Reference to game instance
|
||||
private final ThreadBehaviour gameThreadBehaviour;
|
||||
|
||||
// TODO: Change gameType to automatically happen with either dependency injection or something else.
|
||||
public GenericGameController(GameCanvas canvas, TurnBasedGame game, ThreadBehaviour gameThreadBehaviour, String gameType) {
|
||||
logger.info("Creating: {}", this.getClass());
|
||||
|
||||
this.canvas = canvas;
|
||||
this.game = game;
|
||||
this.gameThreadBehaviour = gameThreadBehaviour;
|
||||
|
||||
// Tell thread how to send moves
|
||||
this.gameThreadBehaviour.setOnSendMove(
|
||||
(id, m) -> GlobalEventBus.get().post(new NetworkEvents.SendMove(id, (short)translateMove(m)))
|
||||
);
|
||||
|
||||
// Tell thread how to update UI
|
||||
this.gameThreadBehaviour.setOnUpdateUI(() -> Platform.runLater(this::updateUI));
|
||||
|
||||
// Change scene to game view
|
||||
gameView = new GameView(null, null, null, gameType);
|
||||
gameView.add(Pos.CENTER, canvas.getCanvas());
|
||||
WidgetContainer.getCurrentView().transitionNext(gameView, true);
|
||||
|
||||
// Listen to updates
|
||||
logger.info("Game controller started listening");
|
||||
eventFlow
|
||||
.listen(GUIEvents.GameEnded.class, this::onGameFinish, false)
|
||||
.listen(GUIEvents.PlayerAttemptedMove.class, event -> {
|
||||
logger.info("User attempting move {}", event.move());
|
||||
logger.info("Current player's turn {}", getCurrentPlayer().getName());
|
||||
logger.info("First player {}", game.getPlayer(0).getName());
|
||||
logger.info("Username {}", getCurrentPlayer().getName());
|
||||
logger.info("User is class {}, {}", getCurrentPlayer().getClass(), getCurrentPlayer() instanceof LocalPlayer);
|
||||
if (getCurrentPlayer() instanceof LocalPlayer lp) {
|
||||
try {
|
||||
lp.setLastMove(event.move());
|
||||
} catch (Exception e) {
|
||||
IO.println(e);
|
||||
}
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void start(){
|
||||
logger.info("Starting GameManager");
|
||||
updateUI();
|
||||
gameThreadBehaviour.start();
|
||||
logger.info("GameManager started");
|
||||
}
|
||||
|
||||
public void stop(){
|
||||
logger.info("Stopping GameManager");
|
||||
removeListeners();
|
||||
gameThreadBehaviour.stop();
|
||||
logger.info("GameManager stopped");
|
||||
}
|
||||
|
||||
public Player getCurrentPlayer(){
|
||||
return game.getPlayer(getCurrentPlayerIndex());
|
||||
}
|
||||
|
||||
public int getCurrentPlayerIndex(){
|
||||
return game.getCurrentTurn();
|
||||
}
|
||||
|
||||
protected long translateMove(int move){
|
||||
return 1L << move;
|
||||
}
|
||||
|
||||
protected int translateMove(long move){
|
||||
return Long.numberOfTrailingZeros(move);
|
||||
}
|
||||
|
||||
private void removeListeners(){
|
||||
eventFlow.unsubscribeAll();
|
||||
}
|
||||
|
||||
private void onGameFinish(GUIEvents.GameEnded event){
|
||||
logger.info("OnlineTurnBasedGame Finished");
|
||||
String name = event.winner() == -1 ? null : getPlayer(event.winner()).getName();
|
||||
gameView.gameOver(event.winOrTie(), name);
|
||||
stop();
|
||||
}
|
||||
|
||||
public Player getPlayer(int player){
|
||||
if (player < 0 || player > game.getPlayerCount()-1){ // TODO: Make game turn player count
|
||||
logger.error("Invalid player index");
|
||||
throw new IllegalArgumentException("player out of range");
|
||||
}
|
||||
return game.getPlayer(player);
|
||||
}
|
||||
|
||||
private boolean isOnline(){
|
||||
return this.gameThreadBehaviour instanceof SupportsOnlinePlay;
|
||||
}
|
||||
|
||||
public void onYourTurn(NetworkEvents.YourTurnResponse event){
|
||||
if (isOnline()){
|
||||
((SupportsOnlinePlay) this.gameThreadBehaviour).onYourTurn(event.clientId());
|
||||
}
|
||||
}
|
||||
|
||||
public void onMoveReceived(NetworkEvents.GameMoveResponse event){
|
||||
if (isOnline()){
|
||||
((SupportsOnlinePlay) this.gameThreadBehaviour).onMoveReceived(
|
||||
translateMove(Integer.parseInt(event.move())));
|
||||
}
|
||||
}
|
||||
|
||||
public void gameFinished(NetworkEvents.GameResultResponse event){
|
||||
if (isOnline()){
|
||||
((SupportsOnlinePlay) this.gameThreadBehaviour).gameFinished(event.condition());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMove(long clientId, long move) {
|
||||
new EventFlow().addPostEvent(NetworkEvents.SendMove.class, clientId, (short) Long.numberOfTrailingZeros(move)).asyncPostEvent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUI() {
|
||||
TurnBasedGame gameCopy = game.deepCopy();
|
||||
canvas.redraw(gameCopy);
|
||||
String gameType = game.getClass().getSimpleName().replace("Bitboard","");
|
||||
gameView.nextPlayer(true, getCurrentPlayer().getName(), game.getPlayer(1-getCurrentPlayerIndex()).getName(),gameType);
|
||||
if (gameType.equals("Reversi")) {
|
||||
BitboardReversi reversiGame = (BitboardReversi) game;
|
||||
BitboardReversi.Score reversiScore = reversiGame.getScore();
|
||||
gameView.setPlayer1Score(reversiScore.black());
|
||||
gameView.setPlayer2Score(reversiScore.white());
|
||||
if (getCurrentPlayer() instanceof LocalPlayer) {
|
||||
((ReversiBitCanvas)canvas).drawLegalDots(gameCopy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.toop.app.gameControllers;
|
||||
|
||||
import org.toop.app.canvas.ReversiBitCanvas;
|
||||
import org.toop.framework.gameFramework.model.game.threadBehaviour.ThreadBehaviour;
|
||||
import org.toop.framework.gameFramework.model.player.Player;
|
||||
import org.toop.framework.game.gameThreads.LocalThreadBehaviour;
|
||||
import org.toop.framework.game.gameThreads.OnlineThreadBehaviour;
|
||||
import org.toop.framework.game.games.reversi.BitboardReversi;
|
||||
import org.toop.framework.game.players.OnlinePlayer;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ReversiBitController extends GenericGameController {
|
||||
|
||||
private BitboardReversi game;
|
||||
|
||||
public ReversiBitController(Player[] players) {
|
||||
BitboardReversi game = new BitboardReversi();
|
||||
game.init(players);
|
||||
ThreadBehaviour thread = Arrays.stream(players).anyMatch(e -> e instanceof OnlinePlayer) ?
|
||||
new OnlineThreadBehaviour(game) : new LocalThreadBehaviour(game);
|
||||
|
||||
super(new ReversiBitCanvas(), game, thread, "Reversi");
|
||||
}
|
||||
|
||||
public BitboardReversi.Score getScore() {
|
||||
return game.getScore();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.toop.app.gameControllers;
|
||||
|
||||
import org.toop.app.canvas.TicTacToeBitCanvas;
|
||||
import org.toop.framework.gameFramework.model.game.threadBehaviour.ThreadBehaviour;
|
||||
import org.toop.framework.gameFramework.model.player.Player;
|
||||
import org.toop.framework.game.gameThreads.LocalThreadBehaviour;
|
||||
import org.toop.framework.game.gameThreads.OnlineThreadBehaviour;
|
||||
import org.toop.framework.game.games.tictactoe.BitboardTicTacToe;
|
||||
import org.toop.framework.game.players.OnlinePlayer;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class TicTacToeBitController extends GenericGameController {
|
||||
public TicTacToeBitController(Player[] players) {
|
||||
BitboardTicTacToe game = new BitboardTicTacToe();
|
||||
game.init(players);
|
||||
|
||||
ThreadBehaviour thread = Arrays.stream(players).anyMatch(e -> e instanceof OnlinePlayer) ?
|
||||
new OnlineThreadBehaviour(game) : new LocalThreadBehaviour(game);
|
||||
|
||||
super(new TicTacToeBitCanvas(), game, thread, "TicTacToe");
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package org.toop.app.menu;
|
||||
|
||||
import org.toop.framework.asset.ResourceManager;
|
||||
import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public final class CreditsMenu extends Menu {
|
||||
private Locale currentLocale = AppContext.getLocale();
|
||||
private LocalizationAsset loc = ResourceManager.get("localization.properties");
|
||||
public CreditsMenu() {
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package org.toop.app.menu;
|
||||
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import org.toop.app.GameType;
|
||||
|
||||
public class GameSelectMenu extends Menu {
|
||||
public GameSelectMenu(GameType type) {
|
||||
final Region background = createBackground();
|
||||
|
||||
final ComboBox<String> selectedGame = new ComboBox<>();
|
||||
selectedGame.getItems().add(GameType.toName(GameType.TICTACTOE));
|
||||
selectedGame.getItems().add(GameType.toName(GameType.REVERSI));
|
||||
selectedGame.setValue(GameType.toName(type));
|
||||
|
||||
final ComboBox<String> selectedMode = new ComboBox<>();
|
||||
selectedMode.getItems().add("Local");
|
||||
selectedMode.getItems().add("Online");
|
||||
selectedMode.setValue("Local");
|
||||
|
||||
final HBox selectedContainer = new HBox(10, selectedGame, selectedMode);
|
||||
|
||||
final TextField serverIpField = new TextField();
|
||||
serverIpField.setPromptText("Enter here your server ip address");
|
||||
|
||||
VBox box = new VBox(selectedContainer, serverIpField);
|
||||
pane = new StackPane(background, box);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package org.toop.app.menu;
|
||||
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.GameType;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.layout.*;
|
||||
import org.toop.app.menu.game.TicTacToeMenu;
|
||||
import org.toop.game.tictactoe.TicTacToe;
|
||||
|
||||
public final class MainMenu extends Menu {
|
||||
public MainMenu() {
|
||||
final Region background = createBackground();
|
||||
|
||||
final Button tictactoe = createButton("Tic Tac Toe", () -> { App.activate(new TicTacToeMenu(new TicTacToe("player 1", true, "player 2", true))); });
|
||||
final Button reversi = createButton("Reversi", () -> { App.activate(new GameSelectMenu(GameType.REVERSI)); });
|
||||
|
||||
final VBox gamesBox = new VBox(10, tictactoe, reversi);
|
||||
gamesBox.setAlignment(Pos.TOP_LEFT);
|
||||
gamesBox.setPickOnBounds(false);
|
||||
gamesBox.setTranslateY(50);
|
||||
gamesBox.setTranslateX(25);
|
||||
|
||||
final Button credits = createButton("Credits", () -> { App.push(new CreditsMenu()); });
|
||||
final Button options = createButton("Options", () -> { App.push(new OptionsMenu()); });
|
||||
final Button quit = createButton("Quit", () -> { App.quitPopup(); });
|
||||
|
||||
final VBox controlBox = new VBox(10, credits, options, quit);
|
||||
controlBox.setAlignment(Pos.BOTTOM_LEFT);
|
||||
controlBox.setPickOnBounds(false);
|
||||
controlBox.setTranslateY(-50);
|
||||
controlBox.setTranslateX(25);
|
||||
|
||||
pane = new StackPane(background, gamesBox, controlBox);
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package org.toop.app.menu;
|
||||
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.text.Text;
|
||||
|
||||
public abstract class Menu {
|
||||
protected Pane pane;
|
||||
public Pane getPane() { return pane; }
|
||||
|
||||
public Region createBackground(String css) {
|
||||
final Region background = new Region();
|
||||
background.setPrefSize(Double.MAX_VALUE, Double.MAX_VALUE);
|
||||
background.getStyleClass().add(css);
|
||||
|
||||
return background;
|
||||
}
|
||||
|
||||
public Region createBackground() {
|
||||
return createBackground("background");
|
||||
}
|
||||
|
||||
public Text createText(String css, String x) {
|
||||
final Text text = new Text(x);
|
||||
text.getStyleClass().add(css);
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
public Text createText(String x) {
|
||||
return createText("text", x);
|
||||
}
|
||||
|
||||
public Button createButton(String css, String x, Runnable runnable) {
|
||||
final Button button = new Button(x);
|
||||
button.setOnAction(_ -> runnable.run());
|
||||
button.getStyleClass().add(css);
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
public Button createButton(String x, Runnable runnable) {
|
||||
return createButton("button", x, runnable);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package org.toop.app.menu;
|
||||
|
||||
import org.toop.framework.asset.ResourceManager;
|
||||
import org.toop.framework.asset.resources.LocalizationAsset;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public final class OptionsMenu extends Menu {
|
||||
private Locale currentLocale = AppContext.getLocale();
|
||||
private LocalizationAsset loc = ResourceManager.get("localization.properties");
|
||||
public OptionsMenu() {
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
package org.toop.app.menu.game;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.canvas.Canvas;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Text;
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.menu.MainMenu;
|
||||
import org.toop.app.menu.Menu;
|
||||
|
||||
public abstract class GameMenu extends Menu {
|
||||
protected final class Cell {
|
||||
public float x;
|
||||
public float y;
|
||||
|
||||
public float width;
|
||||
public float height;
|
||||
|
||||
public Cell(float x, float y, float width, float height) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public boolean check(float x, float y) {
|
||||
return x >= this.x && y >= this.y && x <= this.x + width && y <= this.y + height;
|
||||
}
|
||||
}
|
||||
|
||||
protected final int size;
|
||||
|
||||
protected final Canvas canvas;
|
||||
protected final GraphicsContext graphics;
|
||||
|
||||
protected final int rows;
|
||||
protected final int columns;
|
||||
|
||||
protected final int gapSize;
|
||||
|
||||
protected final Cell[] cells;
|
||||
|
||||
protected GameMenu(int rows, int columns, int gapSize) {
|
||||
final int size = Math.min(App.getWidth(), App.getHeight()) / 5 * 4;
|
||||
|
||||
final Canvas canvas = new Canvas(size, size);
|
||||
|
||||
final GraphicsContext graphics = canvas.getGraphicsContext2D();
|
||||
|
||||
this.size = size;
|
||||
|
||||
this.canvas = canvas;
|
||||
this.graphics = graphics;
|
||||
|
||||
this.rows = rows;
|
||||
this.columns = columns;
|
||||
|
||||
this.gapSize = gapSize;
|
||||
|
||||
cells = new Cell[rows * columns];
|
||||
|
||||
final float cellWidth = ((float)size - (rows - 1) * gapSize) / rows;
|
||||
final float cellHeight = ((float)size - (columns - 1) * gapSize) / rows;
|
||||
|
||||
for (int y = 0; y < columns; y++) {
|
||||
final float startY = y * cellHeight + y * gapSize;
|
||||
|
||||
for (int x = 0; x < rows; x++) {
|
||||
final float startX = x * cellWidth + x * gapSize;
|
||||
cells[y * rows + x] = new Cell(startX, startY, cellWidth, cellHeight);
|
||||
}
|
||||
}
|
||||
|
||||
final Region background = createBackground();
|
||||
|
||||
final Text player1 = createText("player_1", "Player 1");
|
||||
final Text player2 = createText("player_2", "Player 2");
|
||||
|
||||
final HBox playersContainer = new HBox(100, player1, player2);
|
||||
playersContainer.setAlignment(Pos.TOP_CENTER);
|
||||
playersContainer.setPickOnBounds(false);
|
||||
playersContainer.setTranslateY(50);
|
||||
|
||||
final Button hint = createButton("Hint", () -> {});
|
||||
final Button back = createButton("Back", () -> { App.activate(new MainMenu()); });
|
||||
|
||||
final VBox controlContainer = new VBox(hint, back);
|
||||
StackPane.setAlignment(controlContainer, Pos.BOTTOM_LEFT);
|
||||
controlContainer.setPickOnBounds(false);
|
||||
|
||||
pane = new StackPane(background, canvas, playersContainer, controlContainer);
|
||||
}
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
package org.toop.app.menu.game;
|
||||
|
||||
import javafx.scene.paint.Color;
|
||||
import org.toop.game.Game;
|
||||
import org.toop.game.Player;
|
||||
import org.toop.game.tictactoe.TicTacToe;
|
||||
import org.toop.game.tictactoe.TicTacToeAI;
|
||||
|
||||
import javax.management.RuntimeErrorException;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
public final class TicTacToeMenu extends GameMenu {
|
||||
private final TicTacToe game;
|
||||
private final TicTacToeAI ai;
|
||||
|
||||
// private final ExecutorService executor = Executors.newFixedThreadPool(1);
|
||||
private final BlockingQueue<Game.Move> moveQueue = new LinkedBlockingQueue<>();
|
||||
|
||||
public TicTacToeMenu(TicTacToe game) {
|
||||
super(3, 3, 10);
|
||||
|
||||
graphics.setFill(Color.CYAN);
|
||||
|
||||
for (int x = 1; x < rows; x++) {
|
||||
graphics.fillRect(cells[x].x - gapSize, 0, gapSize, size);
|
||||
}
|
||||
|
||||
for (int y = 1; y < columns; y++) {
|
||||
graphics.fillRect(0, cells[y * rows].y - gapSize, size, gapSize);
|
||||
}
|
||||
|
||||
this.game = game;
|
||||
ai = new TicTacToeAI();
|
||||
|
||||
canvas.setOnMouseClicked(event -> {
|
||||
for (int i = 0; i < cells.length; i++) {
|
||||
if (cells[i].check((float) event.getX(), (float) event.getY())) {
|
||||
final Game.Move move = new Game.Move(i, game.getCurrentPlayer().values()[0]);
|
||||
play(move);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
new Thread(this::gameThread).start();
|
||||
}
|
||||
|
||||
private void play(Game.Move move) {
|
||||
final Game.Move[] legalMoves = game.getLegalMoves();
|
||||
|
||||
boolean isLegal = false;
|
||||
|
||||
for (final Game.Move legalMove : legalMoves) {
|
||||
if (legalMove.position() == move.position() && legalMove.value() == move.value()) {
|
||||
isLegal = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isLegal) {
|
||||
return;
|
||||
}
|
||||
|
||||
try { moveQueue.put(move); }
|
||||
catch (InterruptedException _) {}
|
||||
}
|
||||
|
||||
private void placeX(int cell) {
|
||||
graphics.setStroke(Color.ORANGERED);
|
||||
graphics.setLineWidth(gapSize);
|
||||
|
||||
final float x = cells[cell].x + gapSize;
|
||||
final float y = cells[cell].y + gapSize;
|
||||
|
||||
final float width = cells[cell].width - gapSize * 2;
|
||||
final float height = cells[cell].height - gapSize * 2;
|
||||
|
||||
graphics.strokeLine(x, y, x + width, y + height);
|
||||
graphics.strokeLine(x + width, y, x, y + height);
|
||||
}
|
||||
|
||||
private void placeO(int cell) {
|
||||
graphics.setStroke(Color.DEEPSKYBLUE);
|
||||
graphics.setLineWidth(gapSize);
|
||||
|
||||
final float x = cells[cell].x + gapSize;
|
||||
final float y = cells[cell].y + gapSize;
|
||||
|
||||
final float width = cells[cell].width - gapSize * 2;
|
||||
final float height = cells[cell].height - gapSize * 2;
|
||||
|
||||
graphics.strokeOval(x, y, width, height);
|
||||
}
|
||||
|
||||
private void gameThread() {
|
||||
boolean running = true;
|
||||
|
||||
while(running) {
|
||||
final Player currentPlayer = game.getCurrentPlayer();
|
||||
|
||||
try {
|
||||
Game.Move move;
|
||||
|
||||
if (!currentPlayer.isAI()) {
|
||||
try { move = moveQueue.take(); }
|
||||
catch (InterruptedException _) { return; }
|
||||
} else {
|
||||
move = ai.findBestMove(game, 9);
|
||||
}
|
||||
|
||||
assert move != null;
|
||||
final Game.State state = game.play(move);
|
||||
|
||||
if (move.value() == 'X') {
|
||||
placeX(move.position());
|
||||
} else {
|
||||
placeO(move.position());
|
||||
}
|
||||
|
||||
switch (state) {
|
||||
case NORMAL: break;
|
||||
|
||||
case DRAW:
|
||||
case LOSE:
|
||||
case WIN:
|
||||
running = false;
|
||||
break;
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
209
app/src/main/java/org/toop/app/widget/Primitive.java
Normal file
@@ -0,0 +1,209 @@
|
||||
package org.toop.app.widget;
|
||||
|
||||
import javafx.scene.image.ImageView;
|
||||
import org.toop.framework.audio.events.AudioEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.framework.resource.resources.ImageAsset;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.control.Separator;
|
||||
import javafx.scene.control.Slider;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.util.StringConverter;
|
||||
|
||||
public final class Primitive {
|
||||
public static Text header(String key, boolean localize) {
|
||||
var header = new Text();
|
||||
header.getStyleClass().add("header");
|
||||
|
||||
if (!key.isEmpty()) {
|
||||
if (localize) header.setText(AppContext.getString(key)); else header.setText(key);
|
||||
header.textProperty().bind(AppContext.bindToKey(key, localize));
|
||||
}
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
public static Text header(String key) {
|
||||
return header(key, true);
|
||||
}
|
||||
|
||||
public static Text text(String key, boolean localize) {
|
||||
var text = new Text();
|
||||
text.getStyleClass().add("text");
|
||||
|
||||
if (!key.isEmpty()) {
|
||||
if (localize) text.setText(AppContext.getString(key)); else text.setText(key);
|
||||
text.textProperty().bind(AppContext.bindToKey(key, localize));
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
public static Text text(String key) {
|
||||
return text(key, true);
|
||||
}
|
||||
|
||||
public static ImageView image(ImageAsset imageAsset) {
|
||||
ImageView imageView = new ImageView(imageAsset.getImage());
|
||||
imageView.getStyleClass().add("image");
|
||||
imageView.setPreserveRatio(true);
|
||||
imageView.setFitWidth(400);
|
||||
imageView.setFitHeight(400);
|
||||
return imageView;
|
||||
}
|
||||
|
||||
public static Button button(String key, Runnable onAction, boolean localize, boolean disableOnClick) {
|
||||
var button = new Button();
|
||||
button.getStyleClass().add("button");
|
||||
|
||||
if (!key.isEmpty()) {
|
||||
if (localize) button.setText(AppContext.getString(key)); else button.setText(key);
|
||||
button.textProperty().bind(AppContext.bindToKey(key, localize));
|
||||
}
|
||||
|
||||
if (onAction != null) {
|
||||
button.setOnAction(_ -> {
|
||||
if (disableOnClick) button.setDisable(true);
|
||||
onAction.run();
|
||||
playButtonSound();
|
||||
});
|
||||
}
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
public static Button button(String key, Runnable onAction, boolean disableOnClick) {
|
||||
return button(key, onAction, true, disableOnClick);
|
||||
}
|
||||
|
||||
public static TextField input(String promptKey, String text, Consumer<String> onValueChanged, boolean localize) {
|
||||
var input = new TextField();
|
||||
input.getStyleClass().add("input");
|
||||
|
||||
if (!promptKey.isEmpty()) {
|
||||
if (localize) input.setPromptText(AppContext.getString(promptKey)); else input.setPromptText(promptKey);
|
||||
input.promptTextProperty().bind(AppContext.bindToKey(promptKey, localize));
|
||||
}
|
||||
|
||||
input.setText(text);
|
||||
|
||||
if (onValueChanged != null) {
|
||||
input.textProperty().addListener((_, _, newValue) ->
|
||||
onValueChanged.accept(newValue));
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
public static TextField input(String promptKey, String text, Consumer<String> onValueChanged) {
|
||||
return input(promptKey, text, onValueChanged, true);
|
||||
}
|
||||
|
||||
public static Slider slider(int min, int max, int value, Consumer<Integer> onValueChanged) {
|
||||
var slider = new Slider();
|
||||
slider.getStyleClass().add("slider");
|
||||
|
||||
slider.setMin(min);
|
||||
slider.setMax(max);
|
||||
slider.setValue(value);
|
||||
|
||||
if (onValueChanged != null) {
|
||||
slider.valueProperty().addListener((_, _, newValue) -> {
|
||||
onValueChanged.accept(newValue.intValue());
|
||||
});
|
||||
}
|
||||
|
||||
slider.setOnMouseReleased(event -> {
|
||||
playButtonSound();
|
||||
});
|
||||
|
||||
return slider;
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <T> ComboBox<T> choice(StringConverter<T> converter, T value, Consumer<T> onValueChanged, T... items) {
|
||||
var choice = new ComboBox<T>();
|
||||
choice.getStyleClass().add("choice");
|
||||
|
||||
if (converter != null) {
|
||||
choice.setConverter(converter);
|
||||
}
|
||||
|
||||
if (value != null) {
|
||||
choice.setValue(value);
|
||||
}
|
||||
|
||||
if (onValueChanged != null) {
|
||||
choice.valueProperty().addListener((_, _, newValue) -> {
|
||||
onValueChanged.accept(newValue);
|
||||
playButtonSound();
|
||||
});
|
||||
}
|
||||
|
||||
choice.setItems(FXCollections.observableArrayList(items));
|
||||
|
||||
return choice;
|
||||
}
|
||||
|
||||
public static ScrollPane scroll(Node content) {
|
||||
var scroll = new ScrollPane();
|
||||
scroll.getStyleClass().add("scroll");
|
||||
scroll.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
|
||||
scroll.setFitToWidth(true);
|
||||
|
||||
scroll.setContent(content);
|
||||
|
||||
return scroll;
|
||||
}
|
||||
|
||||
public static Separator separator() {
|
||||
var separator = new Separator();
|
||||
separator.getStyleClass().add("separator");
|
||||
|
||||
return separator;
|
||||
}
|
||||
|
||||
public static HBox hbox(Node... nodes) {
|
||||
var hbox = new HBox();
|
||||
hbox.getStyleClass().add("container");
|
||||
hbox.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
|
||||
|
||||
for (var node : nodes) {
|
||||
if (node != null) {
|
||||
hbox.getChildren().add(node);
|
||||
}
|
||||
}
|
||||
|
||||
return hbox;
|
||||
}
|
||||
|
||||
public static VBox vbox(Node... nodes) {
|
||||
var vbox = new VBox();
|
||||
vbox.getStyleClass().add("container");
|
||||
vbox.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
|
||||
|
||||
for (var node : nodes) {
|
||||
if (node != null) {
|
||||
vbox.getChildren().add(node);
|
||||
}
|
||||
}
|
||||
|
||||
return vbox;
|
||||
}
|
||||
|
||||
private static void playButtonSound() {
|
||||
new EventFlow().addPostEvent(new AudioEvents.ClickButton()).postEvent();
|
||||
}
|
||||
}
|
||||
5
app/src/main/java/org/toop/app/widget/Updatable.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package org.toop.app.widget;
|
||||
|
||||
public interface Updatable {
|
||||
void update();
|
||||
}
|
||||
29
app/src/main/java/org/toop/app/widget/Widget.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package org.toop.app.widget;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Node;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public interface Widget {
|
||||
Logger logger = LogManager.getLogger(Widget.class);
|
||||
|
||||
Node getNode();
|
||||
|
||||
default void show(Pos position) {
|
||||
logger.debug("Showing Widget: {} at position: {}", this.getNode(), position.toString());
|
||||
WidgetContainer.add(position, this);
|
||||
}
|
||||
|
||||
default void hide() {
|
||||
logger.debug("Hiding Widget: {}", this.getNode());
|
||||
WidgetContainer.remove(this);
|
||||
}
|
||||
|
||||
default void replace(Pos position, Widget widget) {
|
||||
logger.debug("Replacing Widget: {}, with widget: {}, to position: {}",
|
||||
this.getNode(), widget.getNode(), position.toString());
|
||||
widget.show(position);
|
||||
hide();
|
||||
}
|
||||
}
|
||||
148
app/src/main/java/org/toop/app/widget/WidgetContainer.java
Normal file
@@ -0,0 +1,148 @@
|
||||
package org.toop.app.widget;
|
||||
|
||||
import javafx.scene.Node;
|
||||
import org.toop.app.widget.complex.PopupWidget;
|
||||
import org.toop.app.widget.complex.ViewWidget;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.layout.StackPane;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public final class WidgetContainer {
|
||||
private static StackPane root;
|
||||
private static ViewWidget currentView;
|
||||
|
||||
public static synchronized StackPane setup() {
|
||||
if (root != null) {
|
||||
return root;
|
||||
}
|
||||
|
||||
root = new StackPane();
|
||||
root.getStyleClass().add("bg-view");
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
public static void add(Pos position, Widget widget) {
|
||||
if (root == null || widget == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Platform.runLater(() -> {
|
||||
if (root.getChildren().contains(widget.getNode())) {
|
||||
return;
|
||||
}
|
||||
|
||||
StackPane.setAlignment(widget.getNode(), position);
|
||||
|
||||
if (widget instanceof ViewWidget view) {
|
||||
root.getChildren().addFirst(view.getNode());
|
||||
currentView = view;
|
||||
} else if (widget instanceof PopupWidget popup) {
|
||||
currentView.add(Pos.CENTER, (Widget) popup);
|
||||
} else {
|
||||
root.getChildren().add(widget.getNode());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void remove(Widget widget) {
|
||||
if (root == null || widget == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Platform.runLater(() -> {
|
||||
if (widget instanceof PopupWidget popup) {
|
||||
currentView.remove((Widget) popup);
|
||||
} else {
|
||||
root.getChildren().remove(widget.getNode());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void remove(Class<? extends Widget> widgetClass) {
|
||||
if (root == null || currentView == null) return;
|
||||
|
||||
Platform.runLater(() ->
|
||||
currentView.getChildren().removeIf(widget -> widget.getClass().isAssignableFrom(widgetClass))
|
||||
);
|
||||
}
|
||||
|
||||
public static void removeFirst(Class<? extends Widget> widgetClass) {
|
||||
if (root == null || currentView == null) return;
|
||||
|
||||
Platform.runLater(() -> {
|
||||
for (Node widget : currentView.getChildren()) {
|
||||
if (widgetClass.isAssignableFrom(widget.getClass())) {
|
||||
currentView.getChildren().remove(widget);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static List<Widget> find(Class<? extends Widget> widgetClass) {
|
||||
if (root == null || currentView == null) return null;
|
||||
|
||||
return getAllWidgets()
|
||||
.stream()
|
||||
.filter(widget -> widget.getClass().isAssignableFrom(widgetClass))
|
||||
.toList();
|
||||
}
|
||||
|
||||
public static List<Widget> find(Predicate<Widget> predicate) {
|
||||
if (root == null || currentView == null) return null;
|
||||
|
||||
return getAllWidgets()
|
||||
.stream()
|
||||
.filter(predicate)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public static Widget findFirst(Class<? extends Widget> widgetClass) {
|
||||
if (root == null || currentView == null) return null;
|
||||
|
||||
return getAllWidgets()
|
||||
.stream()
|
||||
.filter(widget -> widget.getClass().isAssignableFrom(widgetClass))
|
||||
.findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public static ViewWidget getCurrentView() {
|
||||
return currentView;
|
||||
}
|
||||
|
||||
public static void setCurrentView(ViewWidget view) {
|
||||
if (root == null || view == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Platform.runLater(() -> {
|
||||
root.getChildren().clear();
|
||||
root.getChildren().add(view.getNode());
|
||||
currentView = view;
|
||||
});
|
||||
}
|
||||
|
||||
public static List<Widget> getAllWidgets() {
|
||||
final List<Widget> children = new ArrayList<>();
|
||||
|
||||
for (var child : root.getChildren()) {
|
||||
if (child instanceof Widget widget) {
|
||||
children.add(widget);
|
||||
}
|
||||
}
|
||||
|
||||
for (var child : currentView.getNode().getChildren()) {
|
||||
if (child instanceof Widget widget) {
|
||||
children.add(widget);
|
||||
}
|
||||
}
|
||||
|
||||
return children;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package org.toop.app.widget.complex;
|
||||
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.Widget;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Text;
|
||||
|
||||
public class ConfirmWidget implements Widget {
|
||||
private final HBox buttonsContainer;
|
||||
private final Text messageText;
|
||||
private final VBox container;
|
||||
|
||||
public ConfirmWidget(String confirm) {
|
||||
buttonsContainer = Primitive.hbox();
|
||||
messageText = Primitive.text("");
|
||||
container = Primitive.vbox(Primitive.header(confirm), messageText, Primitive.separator(), buttonsContainer);
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
messageText.setText(message);
|
||||
}
|
||||
|
||||
public void addButton(String key, Runnable onClick) {
|
||||
Platform.runLater(() -> {
|
||||
var button = Primitive.button(key, onClick, false);
|
||||
buttonsContainer.getChildren().add(button);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node getNode() {
|
||||
return container;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.toop.app.widget.complex;
|
||||
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.Widget;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.util.StringConverter;
|
||||
|
||||
public class LabeledChoiceWidget<T> implements Widget {
|
||||
private final ComboBox<T> comboBox;
|
||||
private final VBox container;
|
||||
|
||||
@SafeVarargs
|
||||
public LabeledChoiceWidget(
|
||||
String key,
|
||||
StringConverter<T> converter,
|
||||
T initialValue,
|
||||
Consumer<T> onValueChanged,
|
||||
T... items
|
||||
) {
|
||||
var label = Primitive.text(key);
|
||||
comboBox = Primitive.choice(converter, initialValue, onValueChanged, items);
|
||||
container = Primitive.vbox(label, comboBox);
|
||||
}
|
||||
|
||||
public T getValue() {
|
||||
return comboBox.getValue();
|
||||
}
|
||||
|
||||
public void setValue(T value) {
|
||||
comboBox.setValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node getNode() {
|
||||
return container;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.toop.app.widget.complex;
|
||||
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.Widget;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.VBox;
|
||||
|
||||
public class LabeledInputWidget implements Widget {
|
||||
private final TextField input;
|
||||
private final VBox container;
|
||||
|
||||
public LabeledInputWidget(String key, String promptKey, String initialText, Consumer<String> onValueChanged) {
|
||||
var label = Primitive.text(key);
|
||||
input = Primitive.input(promptKey, initialText, onValueChanged);
|
||||
container = Primitive.vbox(label, input);
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return input.getText();
|
||||
}
|
||||
|
||||
public void setValue(String text) {
|
||||
input.setText(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node getNode() {
|
||||
return container;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.toop.app.widget.complex;
|
||||
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.Widget;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Slider;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Text;
|
||||
|
||||
public class LabeledSliderWidget implements Widget {
|
||||
private final Slider slider;
|
||||
private final Text labelValue;
|
||||
private final VBox container;
|
||||
|
||||
public LabeledSliderWidget(String key, int min, int max, int value, Consumer<Integer> onValueChanged) {
|
||||
var label = Primitive.text(key);
|
||||
|
||||
labelValue = new Text(String.valueOf(value));
|
||||
labelValue.getStyleClass().add("text");
|
||||
|
||||
slider = Primitive.slider(min, max, value, newValue -> {
|
||||
labelValue.setText(String.valueOf(newValue));
|
||||
|
||||
if (onValueChanged != null) {
|
||||
onValueChanged.accept(newValue);
|
||||
}
|
||||
});
|
||||
|
||||
var sliderRow = Primitive.hbox(slider, labelValue);
|
||||
container = Primitive.vbox(label, sliderRow);
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return (int)slider.getValue();
|
||||
}
|
||||
|
||||
public void setValue(int newValue) {
|
||||
slider.setValue(newValue);
|
||||
labelValue.setText(String.valueOf(newValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node getNode() {
|
||||
return container;
|
||||
}
|
||||
}
|
||||
162
app/src/main/java/org/toop/app/widget/complex/LoadingWidget.java
Normal file
@@ -0,0 +1,162 @@
|
||||
package org.toop.app.widget.complex;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.ProgressBar;
|
||||
import javafx.scene.control.ProgressIndicator;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Text;
|
||||
import org.toop.app.widget.Primitive;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class LoadingWidget extends ViewWidget implements Update { // TODO make of widget type
|
||||
private final Text loadingText; // TODO Make changeable
|
||||
private final ProgressIndicator progressBar;
|
||||
private final AtomicBoolean successTriggered = new AtomicBoolean(false);
|
||||
private final AtomicBoolean failureTriggered = new AtomicBoolean(false);
|
||||
|
||||
private Runnable success = () -> {};
|
||||
private Runnable failure = () -> {};
|
||||
private int maxAmount;
|
||||
private int minAmount;
|
||||
private int amount;
|
||||
private Callable<Boolean> successTrigger = () -> (amount >= maxAmount);
|
||||
private Callable<Boolean> failureTrigger = () -> (amount < minAmount);
|
||||
private float percentage = 0.0f;
|
||||
|
||||
private boolean isInfinite = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* Widget that shows a loading bar.
|
||||
*
|
||||
* @param loadingText Text above the loading bar.
|
||||
* @param minAmount The minimum amount.
|
||||
* @param startAmount The starting amount.
|
||||
* @param maxAmount The max amount.
|
||||
*/
|
||||
public LoadingWidget(Text loadingText, int minAmount, int startAmount, int maxAmount, boolean infinite, boolean circle) {
|
||||
isInfinite = infinite;
|
||||
|
||||
this.maxAmount = maxAmount;
|
||||
this.minAmount = minAmount;
|
||||
amount = startAmount;
|
||||
|
||||
this.loadingText = loadingText;
|
||||
progressBar = circle ? new ProgressIndicator() : new ProgressBar();
|
||||
|
||||
VBox box = Primitive.vbox(this.loadingText, progressBar);
|
||||
progressBar.getStyleClass().add("loading-progress-bar");
|
||||
add(Pos.CENTER, box);
|
||||
}
|
||||
|
||||
public void setMaxAmount(int maxAmount) {
|
||||
this.maxAmount = maxAmount;
|
||||
}
|
||||
|
||||
public void setAmount(int amount) throws Exception {
|
||||
this.amount = amount;
|
||||
update();
|
||||
}
|
||||
|
||||
public int getMaxAmount() {
|
||||
return maxAmount;
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public float getPercentage() {
|
||||
return percentage;
|
||||
}
|
||||
|
||||
public boolean isTriggered() {
|
||||
return (failureTriggered.get() || successTriggered.get());
|
||||
}
|
||||
|
||||
public ProgressIndicator getProgressBar() {
|
||||
return progressBar;
|
||||
}
|
||||
|
||||
/**
|
||||
* What to do when success is triggered.
|
||||
* @param onSuccess The lambda that gets run on success.
|
||||
*/
|
||||
public void setOnSuccess(Runnable onSuccess) {
|
||||
success = onSuccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* What to do when failure is triggered.
|
||||
* @param onFailure The lambda that gets run on failure.
|
||||
*/
|
||||
public void setOnFailure(Runnable onFailure) {
|
||||
failure = onFailure;
|
||||
}
|
||||
|
||||
/**
|
||||
* The trigger to activate onSuccess.
|
||||
* @param trigger The lambda that triggers onSuccess.
|
||||
*/
|
||||
public void setSuccessTrigger(Callable<Boolean> trigger) {
|
||||
successTrigger = trigger;
|
||||
}
|
||||
|
||||
/**
|
||||
* The trigger to activate onFailure.
|
||||
* @param trigger The lambda that triggers onFailure.
|
||||
*/
|
||||
public void setFailureTrigger(Callable<Boolean> trigger) {
|
||||
failureTrigger = trigger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forcefully trigger success.
|
||||
*/
|
||||
public void triggerSuccess() {
|
||||
if (successTriggered.compareAndSet(false, true)) {
|
||||
Platform.runLater(() -> {
|
||||
if (success != null) success.run();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forcefully trigger failure.
|
||||
*/
|
||||
public void triggerFailure() {
|
||||
if (failureTriggered.compareAndSet(false, true)) {
|
||||
Platform.runLater(() -> {
|
||||
if (failure != null) failure.run();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() throws Exception { // TODO Better exception
|
||||
if (successTriggered.get() || failureTriggered.get()) { // If already triggered, throw exception.
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
if (successTrigger.call()) {
|
||||
triggerSuccess();
|
||||
this.remove((Node) this);
|
||||
return;
|
||||
} else if (failureTrigger.call()) {
|
||||
triggerFailure();
|
||||
this.remove((Node) this);
|
||||
return;
|
||||
}
|
||||
|
||||
if (maxAmount != 0) {
|
||||
percentage = (float) amount / maxAmount;
|
||||
}
|
||||
if (!isInfinite) {
|
||||
progressBar.setProgress(percentage);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package org.toop.app.widget.complex;
|
||||
|
||||
import org.toop.app.GameInformation;
|
||||
import org.toop.app.widget.Primitive;
|
||||
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Text;
|
||||
|
||||
public class PlayerInfoWidget {
|
||||
private final GameInformation.Player information;
|
||||
private final VBox container;
|
||||
private Text playerName;
|
||||
private boolean hasSet;
|
||||
|
||||
public PlayerInfoWidget(GameInformation.Player information) {
|
||||
this.information = information;
|
||||
container = Primitive.vbox(
|
||||
buildToggle().getNode(),
|
||||
buildContent()
|
||||
);
|
||||
this.playerName = null;
|
||||
}
|
||||
|
||||
private ToggleWidget buildToggle() {
|
||||
return new ToggleWidget(
|
||||
"computer", "player",
|
||||
information.isHuman,
|
||||
isHuman -> {
|
||||
information.isHuman = isHuman;
|
||||
container.getChildren().setAll(
|
||||
buildToggle().getNode(),
|
||||
buildContent()
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private Node buildContent() {
|
||||
|
||||
if (information.isHuman) {
|
||||
var spacer = Primitive.vbox(
|
||||
makeAIButton(0, 0, "zwartepiet"),
|
||||
makeAIButton(0, 0, "sinterklaas"),
|
||||
makeAIButton(0, 0, "santa")
|
||||
); //todo make a better solution
|
||||
spacer.setVisible(false);
|
||||
var nameInput = new LabeledInputWidget(
|
||||
"name",
|
||||
"enter-your-name",
|
||||
information.name,
|
||||
newName -> information.name = newName
|
||||
);
|
||||
|
||||
return Primitive.vbox(spacer,nameInput.getNode());
|
||||
} else {
|
||||
var AIBox = Primitive.vbox(
|
||||
makeAIButton(0, 1, "zwartepiet"),
|
||||
makeAIButton(2, 1, "sinterklaas"),
|
||||
makeAIButton(9, 1, "santa")
|
||||
);
|
||||
|
||||
this.playerName = Primitive.text("");
|
||||
playerName.setText(information.name);
|
||||
|
||||
var nameDisplay = Primitive.vbox(
|
||||
Primitive.text("name"),
|
||||
playerName
|
||||
);
|
||||
|
||||
if (!hasSet) {
|
||||
doDefault();
|
||||
hasSet = true;
|
||||
}
|
||||
|
||||
return Primitive.vbox(
|
||||
AIBox,
|
||||
nameDisplay
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Node getNode() {
|
||||
return container;
|
||||
}
|
||||
|
||||
private Node makeAIButton(int depth, int thinktime, String name) {
|
||||
return Primitive.button(name, () -> {
|
||||
information.name = getName(name);
|
||||
information.computerDifficulty = depth;
|
||||
information.computerThinkTime = thinktime;
|
||||
this.playerName.setText(getName(name));
|
||||
}, false);
|
||||
}
|
||||
|
||||
private String getName(String name) {
|
||||
return switch (name) {
|
||||
case "sinterklaas" -> "Sint. R. Klaas";
|
||||
case "zwartepiet" -> "Zwarte Piet";
|
||||
case "santa" -> "Santa";
|
||||
default -> "Default";
|
||||
};
|
||||
}
|
||||
|
||||
private void doDefault() {
|
||||
information.name = getName("zwartepiet");
|
||||
information.computerDifficulty = 0;
|
||||
information.computerThinkTime = 1;
|
||||
this.playerName.setText(getName("zwartepiet"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.toop.app.widget.complex;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Button;
|
||||
|
||||
public abstract class PopupWidget extends StackWidget {
|
||||
private final Button popButton;
|
||||
|
||||
public PopupWidget() {
|
||||
super("bg-popup");
|
||||
|
||||
popButton = new Button("X");
|
||||
popButton.setOnAction(_ -> hide());
|
||||
|
||||
add(Pos.TOP_RIGHT, popButton);
|
||||
}
|
||||
|
||||
protected void setOnPop(Runnable onPop) {
|
||||
popButton.setOnAction(_ -> onPop.run());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.toop.app.widget.complex;
|
||||
|
||||
import org.toop.app.widget.Widget;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.layout.StackPane;
|
||||
|
||||
public abstract class StackWidget extends StackPane implements Widget {
|
||||
public StackWidget(String cssClass) {
|
||||
this.getStyleClass().add(cssClass);
|
||||
}
|
||||
|
||||
public void add(Pos position, Node node) {
|
||||
Platform.runLater(() -> {
|
||||
if (this.getChildren().contains(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
StackPane.setAlignment(node, position);
|
||||
this.getChildren().add(node);
|
||||
});
|
||||
}
|
||||
|
||||
public void add(Pos position, Widget widget) {
|
||||
add(position, widget.getNode());
|
||||
}
|
||||
|
||||
public void remove(Node node) {
|
||||
Platform.runLater(() -> {
|
||||
this.getChildren().remove(node);
|
||||
});
|
||||
}
|
||||
|
||||
public void remove(Widget widget) {
|
||||
remove(widget.getNode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackPane getNode() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package org.toop.app.widget.complex;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TableWidget<DATATYPE> extends PopupWidget {
|
||||
private ObservableList<DATATYPE> serverList = FXCollections.observableArrayList();
|
||||
private TableView<DATATYPE> table = new TableView<>();
|
||||
|
||||
|
||||
public TableWidget(String... columns) {
|
||||
var cols = new ArrayList<TableColumn<DATATYPE, String>>();
|
||||
|
||||
for (String column : columns) {
|
||||
TableColumn<DATATYPE, String> col = new TableColumn<>(column.toUpperCase());
|
||||
col.setCellValueFactory(new PropertyValueFactory<>(column));
|
||||
cols.add(col);
|
||||
}
|
||||
|
||||
table.getColumns().addAll(cols);
|
||||
update();
|
||||
onColumnClicked();
|
||||
|
||||
add(Pos.CENTER, table);
|
||||
}
|
||||
|
||||
public void add(DATATYPE serverFound) {
|
||||
serverList.add(serverFound);
|
||||
update();
|
||||
}
|
||||
|
||||
public void add(List<DATATYPE> serverFound) {
|
||||
serverList.addAll(serverFound);
|
||||
}
|
||||
|
||||
public void remove(DATATYPE serverFound) {
|
||||
serverList.remove(serverFound);
|
||||
update();
|
||||
}
|
||||
|
||||
public void onColumnClicked() {
|
||||
table.setOnMouseClicked(event -> {
|
||||
DATATYPE selected = table.getSelectionModel().getSelectedItem();
|
||||
if (selected == null) return;
|
||||
IO.println(selected.toString());
|
||||
});
|
||||
}
|
||||
|
||||
private void update() {
|
||||
table.setItems(serverList);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package org.toop.app.widget.complex;
|
||||
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.Widget;
|
||||
import org.toop.framework.audio.events.AudioEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.layout.VBox;
|
||||
|
||||
public class ToggleWidget implements Widget {
|
||||
private final Button button;
|
||||
private final VBox container;
|
||||
|
||||
private final String onKey;
|
||||
private final String offKey;
|
||||
|
||||
private boolean state;
|
||||
|
||||
public ToggleWidget(String onKey, String offKey, boolean initialState, Consumer<Boolean> onToggle) {
|
||||
this.onKey = onKey;
|
||||
this.offKey = offKey;
|
||||
this.state = initialState;
|
||||
|
||||
button = new Button(AppContext.getString(getCurrentKey()));
|
||||
button.setOnAction(_ -> {
|
||||
state = !state;
|
||||
updateText();
|
||||
if (onToggle != null) {
|
||||
onToggle.accept(state);
|
||||
new EventFlow().addPostEvent(new AudioEvents.ClickButton()).postEvent(); // TODO FIX PRIMITIVES
|
||||
}
|
||||
});
|
||||
|
||||
container = Primitive.vbox(button);
|
||||
}
|
||||
|
||||
private String getCurrentKey() {
|
||||
return state? offKey : onKey;
|
||||
}
|
||||
|
||||
private void updateText() {
|
||||
button.setText(AppContext.getString(getCurrentKey()));
|
||||
}
|
||||
|
||||
public boolean getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(boolean newState) {
|
||||
if (state != newState) {
|
||||
state = newState;
|
||||
updateText();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node getNode() {
|
||||
return container;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package org.toop.app.widget.complex;
|
||||
|
||||
public interface Update {
|
||||
void update() throws Exception;
|
||||
}
|
||||
104
app/src/main/java/org/toop/app/widget/complex/ViewWidget.java
Normal file
@@ -0,0 +1,104 @@
|
||||
package org.toop.app.widget.complex;
|
||||
|
||||
import org.toop.app.widget.Primitive;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
|
||||
public abstract class ViewWidget extends StackWidget {
|
||||
private ViewWidget previous = null;
|
||||
|
||||
public ViewWidget() {
|
||||
super("bg-primary");
|
||||
}
|
||||
|
||||
public void transition(ViewWidget view) {
|
||||
view.previous = this;
|
||||
replace(Pos.CENTER, view);
|
||||
}
|
||||
|
||||
public void transitionNext(ViewWidget view) {
|
||||
transitionNext(view, false);
|
||||
}
|
||||
|
||||
public void transitionNext(ViewWidget view, boolean aware) {
|
||||
if (aware && this.getClass().equals(view.getClass())) {
|
||||
view.previous = this.previous;
|
||||
}
|
||||
else{
|
||||
view.previous = this;
|
||||
}
|
||||
|
||||
replace(Pos.CENTER, view);
|
||||
|
||||
var backButton = Primitive.button("back", () -> {
|
||||
view.transitionPrevious();
|
||||
}, false);
|
||||
|
||||
view.add(Pos.BOTTOM_LEFT, Primitive.vbox(backButton));
|
||||
}
|
||||
|
||||
public void transitionNextCustom(ViewWidget view, String key, Runnable runnable) {
|
||||
view.previous = this;
|
||||
|
||||
replace(Pos.CENTER, view);
|
||||
|
||||
var customButton = Primitive.button(key, () -> {
|
||||
runnable.run();
|
||||
view.transitionPrevious();
|
||||
}, false);
|
||||
|
||||
view.add(Pos.BOTTOM_LEFT, Primitive.vbox(customButton));
|
||||
}
|
||||
|
||||
public void transitionPrevious() {
|
||||
if (previous == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
replace(Pos.CENTER, previous);
|
||||
previous = null;
|
||||
}
|
||||
|
||||
public void removeIndexFromPreviousChain(int index) {
|
||||
ViewWidget view = this;
|
||||
|
||||
while (index > 0 && view != null) {
|
||||
index--;
|
||||
|
||||
if (index == 0) {
|
||||
if (view.previous != null && view.previous.previous != null) {
|
||||
view.previous = view.previous.previous;
|
||||
}
|
||||
}
|
||||
|
||||
view = view.previous;
|
||||
}
|
||||
}
|
||||
|
||||
public void removeViewFromPreviousChain(ViewWidget view) {
|
||||
ViewWidget prev = previous;
|
||||
int index = 0;
|
||||
|
||||
while (prev != null) {
|
||||
index++;
|
||||
|
||||
if (prev == view) {
|
||||
removeIndexFromPreviousChain(index);
|
||||
break;
|
||||
}
|
||||
|
||||
prev = prev.previous;
|
||||
}
|
||||
}
|
||||
|
||||
public void reload(ViewWidget view) {
|
||||
view.previous = previous;
|
||||
replace(Pos.CENTER, view);
|
||||
|
||||
var backButton = Primitive.button("back", () -> {
|
||||
view.transitionPrevious();
|
||||
}, false);
|
||||
|
||||
view.add(Pos.BOTTOM_LEFT, Primitive.vbox(backButton));
|
||||
}
|
||||
}
|
||||
117
app/src/main/java/org/toop/app/widget/display/SongDisplay.java
Normal file
@@ -0,0 +1,117 @@
|
||||
package org.toop.app.widget.display;
|
||||
|
||||
import org.toop.app.widget.Widget;
|
||||
import org.toop.framework.audio.events.AudioEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.framework.eventbus.GlobalEventBus;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ProgressBar;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Text;
|
||||
|
||||
public class SongDisplay extends VBox implements Widget {
|
||||
private final Text songTitle;
|
||||
private final ProgressBar progressBar;
|
||||
private final Text progressText;
|
||||
|
||||
public SongDisplay() {
|
||||
new EventFlow()
|
||||
.listen(AudioEvents.PlayingMusic.class, this::updateTheSong, false);
|
||||
|
||||
setAlignment(Pos.CENTER);
|
||||
setMaxHeight(Region.USE_PREF_SIZE);
|
||||
getStyleClass().add("song-display");
|
||||
|
||||
// TODO ADD GOOD SONG TITLES WITH ARTISTS DISPLAYED
|
||||
songTitle = new Text("song playing");
|
||||
songTitle.getStyleClass().add("song-title");
|
||||
|
||||
progressBar = new ProgressBar(0);
|
||||
progressBar.getStyleClass().add("loading-progress-bar");
|
||||
|
||||
progressText = new Text("0:00/0:00");
|
||||
progressText.getStyleClass().add("progress-text");
|
||||
|
||||
// TODO ADD BETTER CSS FOR THE SKIPBUTTON WHERE ITS AT A NICER POSITION
|
||||
|
||||
Button skipButton = new Button(">>");
|
||||
Button pauseButton = new Button("⏸");
|
||||
Button previousButton = new Button("<<");
|
||||
|
||||
skipButton.getStyleClass().setAll("skip-button");
|
||||
pauseButton.getStyleClass().setAll("pause-button");
|
||||
previousButton.getStyleClass().setAll("previous-button");
|
||||
|
||||
skipButton.setOnAction( event -> {
|
||||
GlobalEventBus.get().post(new AudioEvents.SkipMusic());
|
||||
});
|
||||
|
||||
pauseButton.setOnAction(event -> {
|
||||
GlobalEventBus.get().post(new AudioEvents.PauseMusic());
|
||||
if (pauseButton.getText().equals("⏸")) {
|
||||
pauseButton.setText("▶");
|
||||
}
|
||||
else if (pauseButton.getText().equals("▶")) {
|
||||
pauseButton.setText("⏸");
|
||||
}
|
||||
});
|
||||
|
||||
previousButton.setOnAction( event -> {
|
||||
GlobalEventBus.get().post(new AudioEvents.PreviousMusic());
|
||||
});
|
||||
|
||||
HBox control = new HBox(10, previousButton, pauseButton, skipButton);
|
||||
control.setAlignment(Pos.CENTER);
|
||||
control.getStyleClass().add("controls");
|
||||
|
||||
getChildren().addAll(songTitle, progressBar, progressText, control);
|
||||
}
|
||||
|
||||
private void updateTheSong(AudioEvents.PlayingMusic event) {
|
||||
Platform.runLater(() -> {
|
||||
String text = event.name();
|
||||
text = text.substring(0, text.length() - 4);
|
||||
songTitle.setText(text);
|
||||
double currentPos = event.currentPosition();
|
||||
double duration = event.duration();
|
||||
if (currentPos / duration > 0.05) {
|
||||
double progress = currentPos / duration;
|
||||
progressBar.setProgress(progress);
|
||||
}
|
||||
else if (currentPos / duration < 0.05) {
|
||||
progressBar.setProgress(0.05);
|
||||
}
|
||||
progressText.setText(getTimeString(event.currentPosition(), event.duration()));
|
||||
});
|
||||
}
|
||||
|
||||
private String getTimeString(long position, long duration) {
|
||||
long positionMinutes = position / 60;
|
||||
long durationMinutes = duration / 60;
|
||||
long positionSeconds = position % 60;
|
||||
long durationSeconds = duration % 60;
|
||||
String positionSecondsStr = String.valueOf(positionSeconds);
|
||||
String durationSecondsStr = String.valueOf(durationSeconds);
|
||||
|
||||
if (positionSeconds < 10) {
|
||||
positionSecondsStr = "0" + positionSeconds;
|
||||
}
|
||||
if (durationSeconds < 10) {
|
||||
durationSecondsStr = "0" + durationSeconds;
|
||||
}
|
||||
|
||||
String time = positionMinutes + ":" + positionSecondsStr + " / " + durationMinutes + ":" + durationSecondsStr;
|
||||
return time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node getNode() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package org.toop.app.widget.popup;
|
||||
|
||||
import org.toop.app.GameInformation;
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.complex.PlayerInfoWidget;
|
||||
import org.toop.app.widget.complex.PopupWidget;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
public final class ChallengePopup extends PopupWidget {
|
||||
private final GameInformation.Player playerInformation;
|
||||
private final String challenger;
|
||||
private final String game;
|
||||
private final Consumer<GameInformation.Player> onAccept;
|
||||
|
||||
public ChallengePopup(String challenger, String game, Consumer<GameInformation.Player> onAccept) {
|
||||
this.challenger = challenger;
|
||||
this.game = game;
|
||||
this.onAccept = onAccept;
|
||||
|
||||
this.playerInformation = new GameInformation.Player();
|
||||
|
||||
setupLayout();
|
||||
}
|
||||
|
||||
private void setupLayout() {
|
||||
var challengeText = Primitive.text("you-were-challenged-by");
|
||||
|
||||
var challengerHeader = Primitive.header(challenger, false);
|
||||
|
||||
var toAGameOfText = Primitive.text("to-a-game-of");
|
||||
var gameHeader = Primitive.header(game, false);
|
||||
|
||||
var acceptButton = Primitive.button("accept", () -> {
|
||||
onAccept.accept(playerInformation);
|
||||
this.hide();
|
||||
}, false);
|
||||
var denyButton = Primitive.button("deny", () -> hide(), false);
|
||||
|
||||
var leftSection = Primitive.vbox(
|
||||
challengeText,
|
||||
challengerHeader,
|
||||
toAGameOfText,
|
||||
gameHeader,
|
||||
Primitive.separator(),
|
||||
Primitive.hbox(
|
||||
acceptButton,
|
||||
denyButton
|
||||
)
|
||||
);
|
||||
|
||||
var playerInfoWidget = new PlayerInfoWidget(playerInformation);
|
||||
|
||||
add(Pos.CENTER,
|
||||
Primitive.hbox(
|
||||
leftSection,
|
||||
playerInfoWidget.getNode()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
16
app/src/main/java/org/toop/app/widget/popup/ErrorPopup.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package org.toop.app.widget.popup;
|
||||
|
||||
import org.toop.app.widget.complex.ConfirmWidget;
|
||||
import org.toop.app.widget.complex.PopupWidget;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
|
||||
public class ErrorPopup extends PopupWidget {
|
||||
public ErrorPopup(String error) {
|
||||
var confirmWidget = new ConfirmWidget("error");
|
||||
confirmWidget.setMessage(error);
|
||||
confirmWidget.addButton("ok", this::hide);
|
||||
|
||||
add(Pos.CENTER, confirmWidget);
|
||||
}
|
||||
}
|
||||
48
app/src/main/java/org/toop/app/widget/popup/EscapePopup.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package org.toop.app.widget.popup;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Node;
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.Widget;
|
||||
import org.toop.app.widget.WidgetContainer;
|
||||
import org.toop.app.widget.complex.PopupWidget;
|
||||
import org.toop.app.widget.complex.ViewWidget;
|
||||
import org.toop.app.widget.view.GameView;
|
||||
import org.toop.app.widget.view.OptionsView;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class EscapePopup extends PopupWidget {
|
||||
public EscapePopup() {
|
||||
ViewWidget currentView = WidgetContainer.getCurrentView();
|
||||
ArrayList<Node> nodes = new ArrayList<>();
|
||||
|
||||
nodes.add(Primitive.button("Continue", this::hide, false, false)); // TODO, localize
|
||||
|
||||
if (!(currentView.getClass().isAssignableFrom(OptionsView.class))) {
|
||||
var opt = Primitive.button("options", () -> {
|
||||
hide();
|
||||
WidgetContainer.getCurrentView().transitionNext(new OptionsView());
|
||||
}, false);
|
||||
nodes.add(opt);
|
||||
}
|
||||
|
||||
if (currentView.getClass().isAssignableFrom(GameView.class)) {
|
||||
Widget tut = AppContext.currentTutorial();
|
||||
if (tut != null) {
|
||||
nodes.add(Primitive.button("tutorialstring", () -> {
|
||||
WidgetContainer.getCurrentView().add(Pos.CENTER, tut);
|
||||
}, false));
|
||||
}
|
||||
}
|
||||
|
||||
nodes.add(Primitive.button("quit", () -> {
|
||||
hide();
|
||||
WidgetContainer.add(Pos.CENTER, new QuitPopup());
|
||||
}, false));
|
||||
|
||||
add(Pos.CENTER, Primitive.vbox(nodes.toArray(new Node[0])));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.toop.app.widget.popup;
|
||||
|
||||
import org.toop.app.widget.complex.ConfirmWidget;
|
||||
import org.toop.app.widget.complex.PopupWidget;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import org.toop.framework.game.games.reversi.BitboardReversi;
|
||||
|
||||
public final class GameOverPopup extends PopupWidget {
|
||||
public GameOverPopup(boolean winOrTie, String winner) {
|
||||
var confirmWidget = new ConfirmWidget("game-over");
|
||||
|
||||
if (winOrTie) {
|
||||
confirmWidget.setMessage(winner + " won the game!");
|
||||
}
|
||||
else{
|
||||
confirmWidget.setMessage("It was a tie!");
|
||||
}
|
||||
confirmWidget.addButton("ok", this::hide);
|
||||
|
||||
add(Pos.CENTER, confirmWidget);
|
||||
}
|
||||
}
|
||||
27
app/src/main/java/org/toop/app/widget/popup/QuitPopup.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package org.toop.app.widget.popup;
|
||||
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.widget.complex.ConfirmWidget;
|
||||
import org.toop.app.widget.complex.PopupWidget;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
|
||||
public class QuitPopup extends PopupWidget {
|
||||
public QuitPopup() {
|
||||
var confirmWidget = new ConfirmWidget("are-you-sure");
|
||||
|
||||
confirmWidget.addButton("yes", () -> {
|
||||
App.quit();
|
||||
});
|
||||
|
||||
confirmWidget.addButton("no", () -> {
|
||||
hide();
|
||||
});
|
||||
|
||||
add(Pos.CENTER, confirmWidget);
|
||||
|
||||
setOnPop(() -> {
|
||||
hide();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package org.toop.app.widget.popup;
|
||||
|
||||
import org.toop.app.GameInformation;
|
||||
import org.toop.app.Server;
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.complex.LabeledChoiceWidget;
|
||||
import org.toop.app.widget.complex.PlayerInfoWidget;
|
||||
import org.toop.app.widget.complex.PopupWidget;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.util.StringConverter;
|
||||
|
||||
public final class SendChallengePopup extends PopupWidget {
|
||||
private final Server server;
|
||||
private final String opponent;
|
||||
private final BiConsumer<GameInformation.Player, String> onSend;
|
||||
|
||||
private final GameInformation.Player playerInformation;
|
||||
|
||||
public SendChallengePopup(Server server, String opponent, BiConsumer<GameInformation.Player, String> onSend) {
|
||||
this.server = server;
|
||||
this.opponent = opponent;
|
||||
this.onSend = onSend;
|
||||
|
||||
this.playerInformation = new GameInformation.Player();
|
||||
|
||||
setupLayout();
|
||||
}
|
||||
|
||||
private void setupLayout() {
|
||||
// --- Left side: challenge text and buttons ---
|
||||
var challengeText = Primitive.text("challenge");
|
||||
|
||||
var opponentHeader = Primitive.header(opponent, false);
|
||||
|
||||
var gameText = Primitive.text("to-a-game-of");
|
||||
|
||||
var games = server.getGameList();
|
||||
var gameChoice = new LabeledChoiceWidget<>(
|
||||
"game",
|
||||
new StringConverter<>() {
|
||||
@Override
|
||||
public String toString(String game) {
|
||||
return AppContext.getString(game);
|
||||
}
|
||||
@Override
|
||||
public String fromString(String s) { return null; }
|
||||
},
|
||||
games.getFirst(),
|
||||
newGame -> {
|
||||
playerInformation.computerDifficulty = Math.min(
|
||||
playerInformation.computerDifficulty,
|
||||
Server.gameToType(newGame).getMaxDepth()
|
||||
);
|
||||
},
|
||||
games.toArray(new String[0])
|
||||
);
|
||||
|
||||
var sendButton = Primitive.button(
|
||||
"send",
|
||||
() -> { onSend.accept(playerInformation, gameChoice.getValue()); this.hide(); }
|
||||
, false);
|
||||
|
||||
var cancelButton = Primitive.button("cancel", () -> hide(), false);
|
||||
|
||||
var leftSection = Primitive.vbox(
|
||||
challengeText,
|
||||
opponentHeader,
|
||||
gameText,
|
||||
gameChoice.getNode(),
|
||||
Primitive.separator(),
|
||||
Primitive.hbox(
|
||||
sendButton,
|
||||
cancelButton
|
||||
)
|
||||
);
|
||||
|
||||
var playerInfoWidget = new PlayerInfoWidget(playerInformation);
|
||||
|
||||
add(Pos.CENTER,
|
||||
Primitive.hbox(
|
||||
leftSection,
|
||||
playerInfoWidget.getNode()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package org.toop.app.widget.tutorial;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.text.Text;
|
||||
import org.apache.maven.surefire.shared.lang3.tuple.ImmutablePair;
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.Updatable;
|
||||
import org.toop.app.widget.complex.PopupWidget;
|
||||
|
||||
import org.toop.framework.resource.resources.ImageAsset;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A widget base for all the tutorial widgets.
|
||||
*
|
||||
* <p>Usage example:
|
||||
*
|
||||
* <pre>{@code
|
||||
* public class Connect4TutorialWidget extends BaseTutorialWidget {
|
||||
* public Connect4TutorialWidget(Runnable nextScreen) {
|
||||
* super(List.of(
|
||||
* new ImmutablePair<>("connect4.1", ResourceManager.get("connect41.png")),
|
||||
* new ImmutablePair<>("connect4.2", ResourceManager.get("connect42.png"))
|
||||
* ), nextScreen);
|
||||
* }
|
||||
* }</pre>
|
||||
*/
|
||||
public class BaseTutorialWidget extends PopupWidget implements Updatable {
|
||||
|
||||
private final Text tutorialText;
|
||||
private final ImageView imagery;
|
||||
private final Button previousButton;
|
||||
private final Button nextButton;
|
||||
private final List<ImmutablePair<String, ImageAsset>> pages;
|
||||
private final Runnable nextScreen;
|
||||
|
||||
private int pageIndex = 0;
|
||||
|
||||
public BaseTutorialWidget(List<ImmutablePair<String, ImageAsset>> pages, Runnable nextScreen) {
|
||||
this.tutorialText = Primitive.text(pages.getFirst().getKey());
|
||||
this.imagery = Primitive.image(pages.getFirst().getValue());
|
||||
|
||||
this.pages = pages;
|
||||
this.nextScreen = nextScreen;
|
||||
|
||||
previousButton = Primitive.button("goback", () -> { update(false); this.hide(); }, false);
|
||||
nextButton = Primitive.button(">", () -> update(true), false);
|
||||
|
||||
var w = Primitive.hbox(
|
||||
previousButton,
|
||||
nextButton
|
||||
);
|
||||
|
||||
var x = Primitive.vbox(imagery, tutorialText);
|
||||
|
||||
add(Pos.CENTER, Primitive.vbox(x, w));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
update(true);
|
||||
}
|
||||
|
||||
// TODO Refactor if statements to make code easier to read.
|
||||
public void update(boolean next) {
|
||||
pageIndex = next ? pageIndex + 1 : pageIndex - 1;
|
||||
|
||||
if (pageIndex >= pages.size()) {
|
||||
pageIndex--;
|
||||
return;
|
||||
} else if (pageIndex < 0) {
|
||||
pageIndex++;
|
||||
return;
|
||||
}
|
||||
|
||||
if (pageIndex == pages.size()-1) {
|
||||
nextButton.textProperty().unbind();
|
||||
nextButton.setText(AppContext.getString("startgame"));
|
||||
nextButton.setOnAction((_) -> {
|
||||
this.hide();
|
||||
nextScreen.run();
|
||||
});
|
||||
} else {
|
||||
nextButton.textProperty().unbind();
|
||||
nextButton.setText(AppContext.getString(">"));
|
||||
nextButton.setOnAction((_) -> this.update(true));
|
||||
}
|
||||
|
||||
if (pageIndex == 0) {
|
||||
previousButton.textProperty().unbind();
|
||||
previousButton.setText(AppContext.getString("goback"));
|
||||
previousButton.setOnAction((_) -> this.hide());
|
||||
} else {
|
||||
previousButton.textProperty().unbind();
|
||||
previousButton.setText(AppContext.getString("<"));
|
||||
previousButton.setOnAction((_) -> this.update(false));
|
||||
}
|
||||
|
||||
var currentPage = pages.get(pageIndex);
|
||||
|
||||
var text = currentPage.getKey();
|
||||
var image = currentPage.getValue();
|
||||
|
||||
tutorialText.textProperty().unbind();
|
||||
tutorialText.setText(AppContext.getString(text));
|
||||
imagery.setImage(Primitive.image(image).getImage());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.toop.app.widget.tutorial;
|
||||
|
||||
import org.apache.maven.surefire.shared.lang3.tuple.ImmutablePair;
|
||||
import org.toop.framework.resource.ResourceManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Connect4TutorialWidget extends BaseTutorialWidget {
|
||||
public Connect4TutorialWidget(Runnable nextScreen) {
|
||||
super(List.of(
|
||||
new ImmutablePair<>("connect4.1", ResourceManager.get("connect41.png")),
|
||||
new ImmutablePair<>("connect4.2", ResourceManager.get("connect42.png"))
|
||||
), nextScreen);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.toop.app.widget.tutorial;
|
||||
|
||||
import org.apache.maven.surefire.shared.lang3.tuple.ImmutablePair;
|
||||
import org.toop.framework.resource.ResourceManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ReversiTutorialWidget extends BaseTutorialWidget {
|
||||
public ReversiTutorialWidget(Runnable nextScreen) {
|
||||
super(List.of(
|
||||
new ImmutablePair<>("reversi1", ResourceManager.get("reversi1.png")),
|
||||
new ImmutablePair<>("reversi2", ResourceManager.get("reversi2.png")),
|
||||
new ImmutablePair<>("reversi3", ResourceManager.get("cat.jpg")),
|
||||
new ImmutablePair<>("reversi4", ResourceManager.get("cat.jpg"))
|
||||
), nextScreen);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.toop.app.widget.tutorial;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.WidgetContainer;
|
||||
import org.toop.app.widget.complex.PopupWidget;
|
||||
import org.toop.local.AppSettings;
|
||||
|
||||
public class ShowEnableTutorialWidget extends PopupWidget {
|
||||
|
||||
public ShowEnableTutorialWidget(Runnable tutorial, Runnable nextScreen, Runnable appSettingsSetter) {
|
||||
var a = Primitive.hbox(
|
||||
Primitive.button("ok", () -> { appSettingsSetter.run(); tutorial.run(); this.hide(); }, false),
|
||||
Primitive.button("no", () -> { appSettingsSetter.run(); nextScreen.run(); this.hide(); }, false),
|
||||
Primitive.button("never", () -> { AppSettings.getSettings().setTutorialFlag(false); nextScreen.run(); this.hide(); }, false)
|
||||
);
|
||||
|
||||
var txt = Primitive.text("tutorial");
|
||||
add(Pos.CENTER, Primitive.vbox(txt, a));
|
||||
WidgetContainer.add(Pos.CENTER, this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.toop.app.widget.tutorial;
|
||||
|
||||
import org.apache.maven.surefire.shared.lang3.tuple.ImmutablePair;
|
||||
import org.toop.framework.resource.ResourceManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TicTacToeTutorialWidget extends BaseTutorialWidget {
|
||||
public TicTacToeTutorialWidget(Runnable nextScreen) {
|
||||
super(List.of(
|
||||
new ImmutablePair<>("tictactoe1", ResourceManager.get("tictactoe1.png")),
|
||||
new ImmutablePair<>("tictactoe2", ResourceManager.get("tictactoe2.png"))
|
||||
), nextScreen);
|
||||
}
|
||||
|
||||
}
|
||||
81
app/src/main/java/org/toop/app/widget/view/CreditsView.java
Normal file
@@ -0,0 +1,81 @@
|
||||
package org.toop.app.widget.view;
|
||||
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.complex.ViewWidget;
|
||||
|
||||
import javafx.animation.KeyFrame;
|
||||
import javafx.animation.KeyValue;
|
||||
import javafx.animation.Timeline;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.util.Duration;
|
||||
|
||||
public class CreditsView extends ViewWidget {
|
||||
public CreditsView() {
|
||||
var scrumMasterCredit = newCredit("scrum-master", "Stef");
|
||||
var productOwnerCredit = newCredit("product-owner", "Omar");
|
||||
var mergeCommanderCredit = newCredit("merge-commander", "Bas");
|
||||
var localizationCredit = newCredit("localization", "Ticho");
|
||||
var aiCredit = newCredit("ai", "Michiel");
|
||||
var developersCredit = newCredit("developers", "Michiel, Bas, Stef, Omar, Ticho");
|
||||
var moralSupportCredit = newCredit("moral-support", "Wesley");
|
||||
var openglCredit = newCredit("opengl", "Omar");
|
||||
|
||||
var topSpacer = new Region();
|
||||
topSpacer.setPrefHeight(App.getHeight());
|
||||
|
||||
var bottomSpacer = new Region();
|
||||
bottomSpacer.setPrefHeight(App.getHeight());
|
||||
|
||||
var creditsContainer = Primitive.vbox(
|
||||
topSpacer,
|
||||
|
||||
scrumMasterCredit,
|
||||
productOwnerCredit,
|
||||
mergeCommanderCredit,
|
||||
localizationCredit,
|
||||
aiCredit,
|
||||
developersCredit,
|
||||
moralSupportCredit,
|
||||
openglCredit,
|
||||
|
||||
bottomSpacer
|
||||
);
|
||||
|
||||
var creditsScroll = Primitive.scroll(creditsContainer);
|
||||
|
||||
creditsScroll.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
|
||||
creditsScroll.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
|
||||
|
||||
add(Pos.CENTER, creditsScroll);
|
||||
|
||||
animate(creditsScroll, 15);
|
||||
}
|
||||
|
||||
private HBox newCredit(String key, String other) {
|
||||
var credit = new Text(": " + other);
|
||||
credit.getStyleClass().add("header");
|
||||
|
||||
var creditBox = Primitive.hbox(
|
||||
Primitive.header(key),
|
||||
credit
|
||||
);
|
||||
|
||||
creditBox.setPrefHeight(App.getHeight() / 3.0);
|
||||
return creditBox;
|
||||
}
|
||||
|
||||
private void animate(ScrollPane scroll, int length) {
|
||||
final Timeline timeline = new Timeline(
|
||||
new KeyFrame(Duration.seconds(0), new KeyValue(scroll.vvalueProperty(), 0.0)),
|
||||
new KeyFrame(Duration.seconds(length), new KeyValue(scroll.vvalueProperty(), 1.0))
|
||||
);
|
||||
|
||||
timeline.setCycleCount(Timeline.INDEFINITE);
|
||||
timeline.play();
|
||||
}
|
||||
}
|
||||
195
app/src/main/java/org/toop/app/widget/view/GameView.java
Normal file
@@ -0,0 +1,195 @@
|
||||
package org.toop.app.widget.view;
|
||||
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Circle;
|
||||
import javafx.scene.text.Font;
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.complex.ViewWidget;
|
||||
import org.toop.app.widget.popup.GameOverPopup;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.text.Text;
|
||||
import org.toop.app.widget.tutorial.Connect4TutorialWidget;
|
||||
import org.toop.app.widget.tutorial.ReversiTutorialWidget;
|
||||
import org.toop.app.widget.tutorial.TicTacToeTutorialWidget;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
public final class GameView extends ViewWidget {
|
||||
private final Text playerHeader;
|
||||
private final Text turnHeader;
|
||||
private final Text player1Header;
|
||||
private final Text player2Header;
|
||||
private Circle player1Icon;
|
||||
private Circle player2Icon;
|
||||
private final Text player1Score;
|
||||
private final Text player2Score;
|
||||
private final Button forfeitButton;
|
||||
private final Button exitButton;
|
||||
private final TextField chatInput;
|
||||
private final Text keyThingy;
|
||||
private boolean hasSet = false;
|
||||
|
||||
public GameView(Runnable onForfeit, Runnable onExit, Consumer<String> onMessage, String gameType) {
|
||||
playerHeader = Primitive.header("");
|
||||
turnHeader = Primitive.header("");
|
||||
keyThingy = Primitive.text("turnof");
|
||||
player1Header = Primitive.header("");
|
||||
player2Header = Primitive.header("");
|
||||
player1Icon = new Circle();
|
||||
player2Icon = new Circle();
|
||||
player1Score = Primitive.header("");
|
||||
player2Score = Primitive.header("");
|
||||
|
||||
if (onForfeit != null) {
|
||||
forfeitButton = Primitive.button("forfeit", () -> onForfeit.run(), false);
|
||||
} else {
|
||||
forfeitButton = null;
|
||||
}
|
||||
|
||||
exitButton = Primitive.button("exit", () -> {
|
||||
onExit.run();
|
||||
transitionPrevious();
|
||||
}, false);
|
||||
|
||||
if (onMessage != null) {
|
||||
chatInput = Primitive.input("enter-your-message", "", null);
|
||||
chatInput.setOnAction(_ -> {
|
||||
onMessage.accept(chatInput.getText());
|
||||
chatInput.clear();
|
||||
});
|
||||
} else {
|
||||
chatInput = null;
|
||||
}
|
||||
|
||||
switch (gameType) {
|
||||
case "TicTacToe":
|
||||
AppContext.setCurrentTutorial(new TicTacToeTutorialWidget(() -> {}));
|
||||
break;
|
||||
case "Reversi":
|
||||
AppContext.setCurrentTutorial(new ReversiTutorialWidget(() -> {}));
|
||||
break;
|
||||
case "Connect4":
|
||||
AppContext.setCurrentTutorial(new Connect4TutorialWidget(() -> {}));
|
||||
break;
|
||||
}
|
||||
|
||||
setupLayout();
|
||||
}
|
||||
|
||||
private void setupLayout() {
|
||||
var turnInfo = Primitive.vbox(
|
||||
turnHeader
|
||||
);
|
||||
|
||||
add(Pos.TOP_CENTER, turnInfo);
|
||||
|
||||
var buttons = Primitive.vbox(
|
||||
forfeitButton,
|
||||
exitButton
|
||||
);
|
||||
|
||||
add(Pos.BOTTOM_LEFT, buttons);
|
||||
|
||||
if (chatInput != null) {
|
||||
add(Pos.BOTTOM_RIGHT, Primitive.vbox(chatInput));
|
||||
}
|
||||
}
|
||||
|
||||
public void nextPlayer(boolean isMe, String currentPlayer, String nextPlayer, String GameType) {
|
||||
Platform.runLater(() -> {
|
||||
if (!(hasSet)) {
|
||||
playerHeader.setText(currentPlayer + " vs. " + nextPlayer);
|
||||
hasSet = true;
|
||||
setPlayerHeaders(isMe, currentPlayer, nextPlayer, GameType);
|
||||
}
|
||||
//TODO idk if theres any way to check this? only EN uses 's and the rest doesnt. if theres a better way to do this pls let me know
|
||||
if (AppContext.getLocale().toLanguageTag().equals("en")) {
|
||||
turnHeader.setText(currentPlayer + keyThingy.getText());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void gameOver(boolean iWon, String winner) {
|
||||
new GameOverPopup(iWon, winner).show(Pos.CENTER);
|
||||
}
|
||||
|
||||
private void setPlayerHeaders(boolean isMe, String currentPlayer, String nextPlayer, String GameType) {
|
||||
if (Objects.equals(GameType, "TicTacToe")) {
|
||||
if (isMe) {
|
||||
player1Header.setText("X: " + currentPlayer);
|
||||
player2Header.setText("O: " + nextPlayer);
|
||||
}
|
||||
else {
|
||||
player1Header.setText("X: " + nextPlayer);
|
||||
player2Header.setText("O: " + currentPlayer);
|
||||
}
|
||||
setPlayerInfoTTT();
|
||||
}
|
||||
else if (Objects.equals(GameType, "Reversi")) {
|
||||
if (isMe) {
|
||||
player1Header.setText(currentPlayer);
|
||||
player2Header.setText(nextPlayer);
|
||||
}
|
||||
else {
|
||||
player1Header.setText(nextPlayer);
|
||||
player2Header.setText(currentPlayer);
|
||||
}
|
||||
setPlayerInfoReversi();
|
||||
}
|
||||
}
|
||||
|
||||
private void setPlayerInfoTTT() {
|
||||
var playerInfo = Primitive.vbox(
|
||||
playerHeader,
|
||||
Primitive.separator(),
|
||||
player1Header,
|
||||
player2Header
|
||||
);
|
||||
|
||||
add(Pos.TOP_RIGHT, playerInfo);
|
||||
}
|
||||
|
||||
private void setPlayerInfoReversi() {
|
||||
var player1box = Primitive.hbox(
|
||||
player1Icon,
|
||||
player1Header,
|
||||
player1Score
|
||||
);
|
||||
|
||||
player1box.getStyleClass().add("hboxspacing");
|
||||
|
||||
var player2box = Primitive.hbox(
|
||||
player2Icon,
|
||||
player2Header,
|
||||
player2Score
|
||||
);
|
||||
|
||||
player2box.getStyleClass().add("hboxspacing");
|
||||
|
||||
var playerInfo = Primitive.vbox(
|
||||
playerHeader,
|
||||
Primitive.separator(),
|
||||
player1box,
|
||||
player2box
|
||||
);
|
||||
|
||||
player1Icon.setRadius(player1Header.fontProperty().map(Font::getSize).getValue());
|
||||
player2Icon.setRadius(player2Header.fontProperty().map(Font::getSize).getValue());
|
||||
player1Icon.setFill(Color.WHITE);
|
||||
player2Icon.setFill(Color.BLACK);
|
||||
add(Pos.TOP_RIGHT, playerInfo);
|
||||
}
|
||||
|
||||
public void setPlayer1Score(int score) {
|
||||
player1Score.setText("(" + Integer.toString(score) + ")");
|
||||
}
|
||||
|
||||
public void setPlayer2Score(int score) {
|
||||
player2Score.setText("(" + Integer.toString(score) + ")");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
package org.toop.app.widget.view;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import org.toop.app.GameInformation;
|
||||
import org.toop.app.gameControllers.ReversiBitController;
|
||||
import org.toop.app.gameControllers.TicTacToeBitController;
|
||||
import org.toop.framework.game.players.LocalPlayer;
|
||||
import org.toop.framework.gameFramework.controller.GameController;
|
||||
import org.toop.framework.gameFramework.model.player.Player;
|
||||
import org.toop.framework.game.players.ArtificialPlayer;
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.complex.PlayerInfoWidget;
|
||||
import org.toop.app.widget.complex.ViewWidget;
|
||||
import org.toop.app.widget.popup.ErrorPopup;
|
||||
import org.toop.app.widget.tutorial.*;
|
||||
import org.toop.game.players.ai.MiniMaxAI;
|
||||
import org.toop.game.players.ai.mcts.MCTSAI1;
|
||||
import org.toop.game.players.ai.mcts.MCTSAI3;
|
||||
import org.toop.game.players.ai.mcts.MCTSAI4;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import org.toop.local.AppSettings;
|
||||
|
||||
public class LocalMultiplayerView extends ViewWidget {
|
||||
private final GameInformation information;
|
||||
|
||||
private GameController gameController;
|
||||
|
||||
public LocalMultiplayerView(GameInformation.Type type) {
|
||||
this(new GameInformation(type));
|
||||
}
|
||||
|
||||
public LocalMultiplayerView(GameInformation information) {
|
||||
this.information = information;
|
||||
var playButton = Primitive.button("play", () -> {
|
||||
if (gameController != null) {
|
||||
gameController.stop();
|
||||
}
|
||||
for (var player : information.players) {
|
||||
if (player.isHuman && player.name.isEmpty()) {
|
||||
new ErrorPopup(AppContext.getString("please-enter-your-name")).show(Pos.CENTER);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Fix this temporary ass way of setting the players
|
||||
Player[] players = new Player[2];
|
||||
|
||||
switch (information.type) {
|
||||
case TICTACTOE:
|
||||
if (information.players[0].isHuman) {
|
||||
players[0] = new LocalPlayer(information.players[0].name);
|
||||
} else {
|
||||
players[0] = new ArtificialPlayer(new MCTSAI1(100), "MCTS AI");
|
||||
}
|
||||
if (information.players[1].isHuman) {
|
||||
players[1] = new LocalPlayer(information.players[1].name);
|
||||
} else {
|
||||
players[1] = new ArtificialPlayer(new MiniMaxAI(9), "MiniMax AI");
|
||||
}
|
||||
if (AppSettings.getSettings().getTutorialFlag() && AppSettings.getSettings().getFirstTTT()) {
|
||||
new ShowEnableTutorialWidget(
|
||||
() -> new TicTacToeTutorialWidget(() -> {
|
||||
gameController = new TicTacToeBitController(players);
|
||||
gameController.start();
|
||||
}),
|
||||
() -> Platform.runLater(() -> {
|
||||
gameController = new TicTacToeBitController(players);
|
||||
gameController.start();
|
||||
}),
|
||||
() -> AppSettings.getSettings().setFirstTTT(false)
|
||||
);
|
||||
} else {
|
||||
gameController = new TicTacToeBitController(players);
|
||||
gameController.start();
|
||||
}
|
||||
break;
|
||||
case REVERSI:
|
||||
if (information.players[0].isHuman) {
|
||||
players[0] = new LocalPlayer(information.players[0].name);
|
||||
} else {
|
||||
// players[0] = new ArtificialPlayer(new RandomAI(), "Random AI");
|
||||
players[0] = new ArtificialPlayer(new MCTSAI1(100), "MCTS V1 AI");
|
||||
}
|
||||
if (information.players[1].isHuman) {
|
||||
players[1] = new LocalPlayer(information.players[1].name);
|
||||
} else {
|
||||
players[1] = new ArtificialPlayer(new MCTSAI4(100, 8), "MCTS V4 AI");
|
||||
}
|
||||
if (AppSettings.getSettings().getTutorialFlag() && AppSettings.getSettings().getFirstReversi()) {
|
||||
new ShowEnableTutorialWidget(
|
||||
() -> new ReversiTutorialWidget(() -> {
|
||||
gameController = new ReversiBitController(players);
|
||||
gameController.start();
|
||||
}),
|
||||
() -> Platform.runLater(() -> {
|
||||
gameController = new ReversiBitController(players);
|
||||
gameController.start();
|
||||
}),
|
||||
() -> AppSettings.getSettings().setFirstReversi(false)
|
||||
);
|
||||
} else {
|
||||
gameController = new ReversiBitController(players);
|
||||
gameController.start();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}, false);
|
||||
|
||||
var playerSection = setupPlayerSections();
|
||||
|
||||
add(Pos.CENTER, Primitive.vbox(
|
||||
playerSection,
|
||||
Primitive.separator(),
|
||||
playButton
|
||||
));
|
||||
}
|
||||
|
||||
private ScrollPane setupPlayerSections() {
|
||||
int playerCount = information.type.getPlayerCount();
|
||||
VBox[] playerBoxes = new VBox[playerCount];
|
||||
|
||||
for (int i = 0; i < playerCount; i++) {
|
||||
var player = information.players[i];
|
||||
|
||||
var playerHeader = Primitive.header("");
|
||||
playerHeader.setText("player" + " #" + (i + 1));
|
||||
|
||||
var playerWidget = new PlayerInfoWidget(player);
|
||||
|
||||
playerBoxes[i] = Primitive.vbox(
|
||||
playerHeader,
|
||||
Primitive.separator(),
|
||||
playerWidget.getNode()
|
||||
);
|
||||
}
|
||||
|
||||
return Primitive.scroll(Primitive.hbox(
|
||||
playerBoxes
|
||||
));
|
||||
}
|
||||
}
|
||||
24
app/src/main/java/org/toop/app/widget/view/LocalView.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package org.toop.app.widget.view;
|
||||
|
||||
import org.toop.app.GameInformation;
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.complex.ViewWidget;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
|
||||
public class LocalView extends ViewWidget {
|
||||
public LocalView() {
|
||||
var ticTacToeButton = Primitive.button("tic-tac-toe", () -> {
|
||||
transitionNext(new LocalMultiplayerView(GameInformation.Type.TICTACTOE));
|
||||
}, false);
|
||||
|
||||
var reversiButton = Primitive.button("reversi", () -> {
|
||||
transitionNext(new LocalMultiplayerView(GameInformation.Type.REVERSI));
|
||||
}, false);
|
||||
|
||||
add(Pos.CENTER, Primitive.vbox(
|
||||
ticTacToeButton,
|
||||
reversiButton
|
||||
));
|
||||
}
|
||||
}
|
||||
39
app/src/main/java/org/toop/app/widget/view/MainView.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package org.toop.app.widget.view;
|
||||
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.complex.ViewWidget;
|
||||
import javafx.geometry.Pos;
|
||||
import org.toop.app.widget.popup.QuitPopup;
|
||||
|
||||
public class MainView extends ViewWidget {
|
||||
public MainView() {
|
||||
var localButton = Primitive.button("local", () -> {
|
||||
transitionNext(new LocalView());
|
||||
}, false);
|
||||
|
||||
var onlineButton = Primitive.button("online", () -> {
|
||||
transitionNext(new OnlineView());
|
||||
}, false);
|
||||
|
||||
var creditsButton = Primitive.button("credits", () -> {
|
||||
transitionNext(new CreditsView());
|
||||
}, false);
|
||||
|
||||
var optionsButton = Primitive.button("options", () -> {
|
||||
transitionNext(new OptionsView());
|
||||
}, false);
|
||||
|
||||
var quitButton = Primitive.button("quit", () -> {
|
||||
var a = new QuitPopup();
|
||||
a.show(Pos.CENTER);
|
||||
}, false);
|
||||
|
||||
add(Pos.CENTER, Primitive.vbox(
|
||||
localButton,
|
||||
onlineButton,
|
||||
creditsButton,
|
||||
optionsButton,
|
||||
quitButton
|
||||
));
|
||||
}
|
||||
}
|
||||
72
app/src/main/java/org/toop/app/widget/view/OnlineView.java
Normal file
@@ -0,0 +1,72 @@
|
||||
package org.toop.app.widget.view;
|
||||
|
||||
import org.toop.app.Server;
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.complex.LabeledInputWidget;
|
||||
import org.toop.app.widget.complex.ViewWidget;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import org.toop.framework.game.games.reversi.BitboardReversi;
|
||||
import org.toop.framework.game.games.tictactoe.BitboardTicTacToe;
|
||||
import org.toop.framework.gameFramework.model.game.TurnBasedGame;
|
||||
import org.toop.framework.networking.server.gateway.NettyGatewayServer;
|
||||
import org.toop.framework.networking.server.stores.TurnBasedGameTypeStore;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class OnlineView extends ViewWidget {
|
||||
public OnlineView() {
|
||||
var serverInformationHeader = Primitive.header("server-information");
|
||||
|
||||
var serverIPInput = new LabeledInputWidget("ip-address", "enter-the-server-ip", "", _ -> {});
|
||||
var serverPortInput = new LabeledInputWidget("port", "enter-the-server-port", "", _ -> {});
|
||||
var playerNameInput = new LabeledInputWidget("player-name", "enter-your-name", "", _ -> {});
|
||||
|
||||
var connectButton = Primitive.button("connect", () -> {
|
||||
new Server(
|
||||
serverIPInput.getValue(),
|
||||
serverPortInput.getValue(),
|
||||
playerNameInput.getValue()
|
||||
);
|
||||
}, false);
|
||||
|
||||
var localHostButton = Primitive.button("host!", () -> {
|
||||
|
||||
var tps = new TurnBasedGameTypeStore();
|
||||
tps.register("tic-tac-toe", BitboardTicTacToe::new);
|
||||
tps.register("reversi", BitboardReversi::new);
|
||||
|
||||
var a = new NettyGatewayServer(6666, tps, Duration.ofSeconds(10));
|
||||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
a.start();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}).start();
|
||||
|
||||
new Server(
|
||||
"127.0.0.1",
|
||||
"6666",
|
||||
"host",
|
||||
a
|
||||
);
|
||||
}, false, false);
|
||||
|
||||
add(Pos.CENTER, Primitive.vbox(
|
||||
serverInformationHeader,
|
||||
Primitive.separator(),
|
||||
|
||||
serverIPInput.getNode(),
|
||||
serverPortInput.getNode(),
|
||||
playerNameInput.getNode(),
|
||||
Primitive.separator(),
|
||||
|
||||
connectButton,
|
||||
Primitive.separator(),
|
||||
localHostButton
|
||||
));
|
||||
}
|
||||
}
|
||||
161
app/src/main/java/org/toop/app/widget/view/OptionsView.java
Normal file
@@ -0,0 +1,161 @@
|
||||
package org.toop.app.widget.view;
|
||||
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.complex.LabeledChoiceWidget;
|
||||
import org.toop.app.widget.complex.LabeledSliderWidget;
|
||||
import org.toop.app.widget.complex.ViewWidget;
|
||||
import org.toop.app.widget.complex.ToggleWidget;
|
||||
import org.toop.framework.audio.VolumeControl;
|
||||
import org.toop.framework.audio.events.AudioEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.local.AppContext;
|
||||
import org.toop.local.AppSettings;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.util.StringConverter;
|
||||
|
||||
public class OptionsView extends ViewWidget {
|
||||
public OptionsView() {
|
||||
add(Pos.CENTER, Primitive.hbox(
|
||||
generalSection(),
|
||||
volumeSection(),
|
||||
styleSection()
|
||||
));
|
||||
}
|
||||
|
||||
private VBox generalSection() {
|
||||
var languageWidget = new LabeledChoiceWidget<>(
|
||||
"language",
|
||||
new StringConverter<>() {
|
||||
@Override
|
||||
public String toString(Locale locale) {
|
||||
return AppContext.getString(locale.getDisplayName().toLowerCase());
|
||||
}
|
||||
@Override
|
||||
public Locale fromString(String s) { return null; }
|
||||
},
|
||||
AppContext.getLocale(),
|
||||
newLocale -> {
|
||||
AppSettings.getSettings().setLocale(newLocale.toString());
|
||||
AppContext.setLocale(newLocale);
|
||||
reload(new OptionsView());
|
||||
},
|
||||
AppContext.getLocalization().getAvailableLocales().toArray(new Locale[0])
|
||||
);
|
||||
|
||||
var fullscreenToggle = new ToggleWidget(
|
||||
"fullscreen", "windowed",
|
||||
AppSettings.getSettings().getFullscreen(),
|
||||
fullscreen -> {
|
||||
AppSettings.getSettings().setFullscreen(fullscreen);
|
||||
App.setFullscreen(fullscreen);
|
||||
}
|
||||
);
|
||||
|
||||
return Primitive.vbox(
|
||||
Primitive.header("general"),
|
||||
Primitive.separator(),
|
||||
|
||||
languageWidget.getNode(),
|
||||
fullscreenToggle.getNode()
|
||||
);
|
||||
}
|
||||
|
||||
private VBox volumeSection() {
|
||||
var masterVolumeWidget = new LabeledSliderWidget(
|
||||
"master-volume",
|
||||
0, 100,
|
||||
AppSettings.getSettings().getVolume(),
|
||||
val -> {
|
||||
AppSettings.getSettings().setVolume(val);
|
||||
new EventFlow()
|
||||
.addPostEvent(new AudioEvents.ChangeVolume(val, VolumeControl.MASTERVOLUME))
|
||||
.postEvent();
|
||||
}
|
||||
);
|
||||
|
||||
var effectsVolumeWidget = new LabeledSliderWidget(
|
||||
"effects-volume",
|
||||
0, 100,
|
||||
AppSettings.getSettings().getFxVolume(),
|
||||
val -> {
|
||||
AppSettings.getSettings().setFxVolume(val);
|
||||
new EventFlow()
|
||||
.addPostEvent(new AudioEvents.ChangeVolume(val, VolumeControl.FX))
|
||||
.postEvent();
|
||||
}
|
||||
);
|
||||
|
||||
var musicVolumeWidget = new LabeledSliderWidget(
|
||||
"music-volume",
|
||||
0, 100,
|
||||
AppSettings.getSettings().getMusicVolume(),
|
||||
val -> {
|
||||
AppSettings.getSettings().setMusicVolume(val);
|
||||
new EventFlow()
|
||||
.addPostEvent(new AudioEvents.ChangeVolume(val, VolumeControl.MUSIC))
|
||||
.postEvent();
|
||||
}
|
||||
);
|
||||
|
||||
return Primitive.vbox(
|
||||
Primitive.header("volume"),
|
||||
Primitive.separator(),
|
||||
|
||||
masterVolumeWidget.getNode(),
|
||||
effectsVolumeWidget.getNode(),
|
||||
musicVolumeWidget.getNode()
|
||||
);
|
||||
}
|
||||
|
||||
private VBox styleSection() {
|
||||
var themeWidget = new LabeledChoiceWidget<>(
|
||||
"theme",
|
||||
new StringConverter<>() {
|
||||
@Override
|
||||
public String toString(String theme) {
|
||||
return AppContext.getString(theme);
|
||||
}
|
||||
@Override
|
||||
public String fromString(String s) { return null; }
|
||||
},
|
||||
AppSettings.getSettings().getTheme(),
|
||||
newTheme -> {
|
||||
AppSettings.getSettings().setTheme(newTheme);
|
||||
App.setStyle(newTheme, AppSettings.getSettings().getLayoutSize());
|
||||
},
|
||||
"dark", "light", "high-contrast"
|
||||
);
|
||||
|
||||
var layoutWidget = new LabeledChoiceWidget<>(
|
||||
"layout-size",
|
||||
new StringConverter<>() {
|
||||
@Override
|
||||
public String toString(String layout) {
|
||||
return AppContext.getString(layout);
|
||||
}
|
||||
@Override
|
||||
public String fromString(String s) { return null; }
|
||||
},
|
||||
AppSettings.getSettings().getLayoutSize(),
|
||||
newLayout -> {
|
||||
AppSettings.getSettings().setLayoutSize(newLayout);
|
||||
App.setStyle(AppSettings.getSettings().getTheme(), newLayout);
|
||||
},
|
||||
"small", "medium", "large"
|
||||
);
|
||||
|
||||
|
||||
return Primitive.vbox(
|
||||
Primitive.header("style"),
|
||||
Primitive.separator(),
|
||||
|
||||
themeWidget.getNode(),
|
||||
layoutWidget.getNode()
|
||||
);
|
||||
}
|
||||
}
|
||||
115
app/src/main/java/org/toop/app/widget/view/ServerView.java
Normal file
@@ -0,0 +1,115 @@
|
||||
package org.toop.app.widget.view;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.css.converter.StringConverter;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.complex.ViewWidget;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ListView;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.framework.eventbus.GlobalEventBus;
|
||||
import org.toop.framework.networking.connection.events.NetworkEvents;
|
||||
|
||||
public final class ServerView extends ViewWidget {
|
||||
private final String user;
|
||||
private final Consumer<String> onPlayerClicked;
|
||||
private final long clientId;
|
||||
|
||||
private final ComboBox<String> gameListSub;
|
||||
private final ComboBox<String> gameListTour;
|
||||
private final ListView<Button> listView;
|
||||
private Button subscribeButton;
|
||||
|
||||
public ServerView(String user, Consumer<String> onPlayerClicked, String userName, long clientId) {
|
||||
this.user = user;
|
||||
this.onPlayerClicked = onPlayerClicked;
|
||||
this.clientId = clientId;
|
||||
|
||||
this.gameListSub = new ComboBox<>();
|
||||
this.gameListTour = new ComboBox<>();
|
||||
this.listView = new ListView<>();
|
||||
|
||||
setupLayout(userName);
|
||||
}
|
||||
|
||||
private void setupLayout(String userName) {
|
||||
var playerHeader = Primitive.header(user, false);
|
||||
|
||||
if (userName.equals("host")) { // TODO is fragile
|
||||
var tournamentButton = Primitive.hbox(
|
||||
gameListTour,
|
||||
Primitive.button(
|
||||
"tournament",
|
||||
() -> GlobalEventBus.get().post(new NetworkEvents.SendCommand(clientId, "tournament", "start", gameListTour.getValue())),
|
||||
false,
|
||||
false
|
||||
)
|
||||
);
|
||||
|
||||
add(Pos.BOTTOM_CENTER, tournamentButton);
|
||||
} else {
|
||||
subscribeButton = Primitive.button(
|
||||
"subscribe",
|
||||
() -> new EventFlow().addPostEvent(new NetworkEvents.SendSubscribe(clientId, gameListSub.getValue())).postEvent(),
|
||||
false,
|
||||
true
|
||||
); // TODO localize
|
||||
|
||||
var subscribe = Primitive.hbox(gameListSub, subscribeButton);
|
||||
|
||||
var playerListSection = Primitive.vbox(
|
||||
playerHeader,
|
||||
Primitive.separator(),
|
||||
subscribe,
|
||||
listView
|
||||
);
|
||||
|
||||
add(Pos.CENTER, playerListSection);
|
||||
|
||||
var disconnectButton = Primitive.button(
|
||||
"disconnect",
|
||||
this::transitionPrevious,
|
||||
false
|
||||
);
|
||||
|
||||
add(Pos.BOTTOM_LEFT, Primitive.vbox(disconnectButton));
|
||||
}
|
||||
}
|
||||
|
||||
public void update(List<String> players) {
|
||||
Platform.runLater(() -> {
|
||||
listView.getItems().clear();
|
||||
|
||||
for (String player : players) {
|
||||
var playerButton = Primitive.button(player, () -> onPlayerClicked.accept(player), false, false);
|
||||
listView.getItems().add(playerButton);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void updateGameList(List<String> games) {
|
||||
Platform.runLater(() -> {
|
||||
gameListSub.getItems().clear();
|
||||
gameListSub.setItems(FXCollections.observableArrayList(games));
|
||||
gameListSub.getSelectionModel().select(0);
|
||||
|
||||
gameListTour.getItems().clear();
|
||||
gameListTour.setItems(FXCollections.observableArrayList(games));
|
||||
gameListTour.getSelectionModel().select(0);
|
||||
});
|
||||
}
|
||||
|
||||
public void reEnableButton() {
|
||||
subscribeButton.setDisable(false);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,86 @@
|
||||
package org.toop.local;
|
||||
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.toop.app.widget.tutorial.BaseTutorialWidget;
|
||||
import org.toop.framework.resource.ResourceManager;
|
||||
import org.toop.framework.resource.resources.LocalizationAsset;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class AppContext {
|
||||
private static Locale currentLocale = Locale.getDefault();
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.binding.StringBinding;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
|
||||
public static void setCurrentLocale(Locale locale) {
|
||||
currentLocale = locale;
|
||||
public class AppContext {
|
||||
private static final Logger logger = LogManager.getLogger(AppContext.class);
|
||||
|
||||
private static final LocalizationAsset localization = ResourceManager.get("localization");
|
||||
private static Locale locale = Locale.forLanguageTag("en");
|
||||
|
||||
private static final ObjectProperty<Locale> localeProperty = new SimpleObjectProperty<>(locale);
|
||||
private static BaseTutorialWidget tutorialWidget;
|
||||
|
||||
public static LocalizationAsset getLocalization() {
|
||||
return localization;
|
||||
}
|
||||
|
||||
public static void setLocale(Locale locale) {
|
||||
AppContext.locale = locale;
|
||||
localeProperty.set(locale);
|
||||
}
|
||||
|
||||
public static Locale getLocale() {
|
||||
return currentLocale;
|
||||
return locale;
|
||||
}
|
||||
|
||||
public static String getString(String key) {
|
||||
assert localization != null;
|
||||
|
||||
// TODO: Gebruik ResourceBundle.getBundle() zodat de fallback automatisch gaat.
|
||||
// Hiervoor zou de assetManager aangepast moeten worden.
|
||||
|
||||
try{ // Main return
|
||||
return localization.getString(key, locale);
|
||||
}
|
||||
catch (MissingResourceException e) {
|
||||
logger.error("Missing resource key: {}, in bundle: {}. ", key, locale, e);
|
||||
}
|
||||
|
||||
try{ // Fallback return
|
||||
return localization.getString(key, localization.getFallback());
|
||||
}
|
||||
catch (MissingResourceException e) {
|
||||
logger.error("Missing resource key: {}, in default bundle!", key, e);
|
||||
}
|
||||
// Default return
|
||||
return "MISSING RESOURCE";
|
||||
}
|
||||
|
||||
public static StringBinding bindToKey(String key, boolean localize) {
|
||||
if (localize) return Bindings.createStringBinding(
|
||||
() -> localization.getString(key, locale),
|
||||
localeProperty
|
||||
);
|
||||
|
||||
return Bindings.createStringBinding(
|
||||
() -> key
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public static StringBinding bindToKey(String key) {
|
||||
return bindToKey(key, true);
|
||||
}
|
||||
|
||||
public static void setCurrentTutorial(BaseTutorialWidget tutorial) {
|
||||
AppContext.tutorialWidget = tutorial;
|
||||
}
|
||||
|
||||
public static BaseTutorialWidget currentTutorial() {
|
||||
return AppContext.tutorialWidget;
|
||||
}
|
||||
}
|
||||
114
app/src/main/java/org/toop/local/AppSettings.java
Normal file
@@ -0,0 +1,114 @@
|
||||
package org.toop.local;
|
||||
|
||||
import org.toop.app.App;
|
||||
import org.toop.framework.audio.VolumeControl;
|
||||
import org.toop.framework.audio.events.AudioEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.framework.resource.ResourceManager;
|
||||
import org.toop.framework.resource.ResourceMeta;
|
||||
import org.toop.framework.resource.resources.SettingsAsset;
|
||||
import org.toop.framework.settings.Settings;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Locale;
|
||||
|
||||
public class AppSettings {
|
||||
private static SettingsAsset settingsAsset;
|
||||
|
||||
public static void applySettings() {
|
||||
settingsAsset = getPath();
|
||||
if (!settingsAsset.isLoaded()) {
|
||||
settingsAsset.load();
|
||||
}
|
||||
|
||||
checkSettings();
|
||||
|
||||
Settings settingsData = settingsAsset.getContent();
|
||||
|
||||
AppContext.setLocale(Locale.of(settingsData.locale));
|
||||
App.setFullscreen(settingsData.fullScreen);
|
||||
|
||||
App.setStyle(settingsAsset.getTheme(), settingsAsset.getLayoutSize());
|
||||
}
|
||||
|
||||
public static void applyMusicVolumeSettings() {
|
||||
Settings settingsData = settingsAsset.getContent();
|
||||
|
||||
new EventFlow()
|
||||
.addPostEvent(new AudioEvents.ChangeVolume(settingsData.volume, VolumeControl.MASTERVOLUME))
|
||||
.postEvent();
|
||||
new EventFlow()
|
||||
.addPostEvent(new AudioEvents.ChangeVolume(settingsData.fxVolume, VolumeControl.FX))
|
||||
.postEvent();
|
||||
new EventFlow()
|
||||
.addPostEvent(new AudioEvents.ChangeVolume(settingsData.musicVolume, VolumeControl.MUSIC))
|
||||
.postEvent();
|
||||
}
|
||||
|
||||
public static SettingsAsset getPath() {
|
||||
if (settingsAsset == null) {
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
String basePath;
|
||||
|
||||
if (os.contains("win")) {
|
||||
basePath = System.getenv("APPDATA");
|
||||
if (basePath == null) {
|
||||
basePath = System.getProperty("user.home");
|
||||
}
|
||||
} else if (os.contains("mac")) {
|
||||
basePath = System.getProperty("user.home") + "/Library/Application Support";
|
||||
} else {
|
||||
basePath = System.getProperty("user.home") + "/.config";
|
||||
}
|
||||
|
||||
File settingsFile =
|
||||
new File(basePath + File.separator + "ISY1" + File.separator + "settings.json");
|
||||
// this.settingsAsset = new SettingsAsset(settingsFile);
|
||||
ResourceManager.addAsset(new ResourceMeta<>("settings.json", new SettingsAsset(settingsFile)));
|
||||
}
|
||||
return ResourceManager.get("settings.json");
|
||||
}
|
||||
|
||||
public static SettingsAsset getSettings() {
|
||||
return settingsAsset;
|
||||
}
|
||||
|
||||
public static void checkSettings() {
|
||||
Settings s = settingsAsset.getContent();
|
||||
boolean changed = false;
|
||||
|
||||
if (s.showTutorials == null) {
|
||||
settingsAsset.setTutorialFlag(true);
|
||||
changed = true;
|
||||
}
|
||||
if (s.firstReversi == null) {
|
||||
settingsAsset.setFirstReversi(true);
|
||||
changed = true;
|
||||
}
|
||||
if (s.firstTTT == null) {
|
||||
settingsAsset.setFirstTTT(true);
|
||||
changed = true;
|
||||
}
|
||||
if (s.firstConnect4 == null) {
|
||||
settingsAsset.setFirstConnect4(true);
|
||||
changed = true;
|
||||
}
|
||||
if (changed) {
|
||||
getSettings().save();
|
||||
}
|
||||
}
|
||||
|
||||
public static void doDefaultSettings() {
|
||||
settingsAsset.setFirstConnect4(true);
|
||||
settingsAsset.setFirstTTT(true);
|
||||
settingsAsset.setFirstReversi(true);
|
||||
settingsAsset.setLocale("en");
|
||||
settingsAsset.setTheme("dark");
|
||||
settingsAsset.setFullscreen(false);
|
||||
settingsAsset.setVolume(100);
|
||||
settingsAsset.setFxVolume(20);
|
||||
settingsAsset.setMusicVolume(15);
|
||||
settingsAsset.setTutorialFlag(true);
|
||||
settingsAsset.setLayoutSize("medium");
|
||||
}
|
||||
}
|
||||
BIN
app/src/main/resources/assets/audio/fx/harsh-button-click.wav
Normal file
BIN
app/src/main/resources/assets/audio/fx/medium-button-click.wav
Normal file
BIN
app/src/main/resources/assets/audio/fx/soft-button-click.wav
Normal file
BIN
app/src/main/resources/assets/audio/music/bignic - Gladius.mp3
Normal file
|
Before Width: | Height: | Size: 357 KiB |
BIN
app/src/main/resources/assets/images/cat.jpg
Normal file
|
After Width: | Height: | Size: 596 KiB |
BIN
app/src/main/resources/assets/images/connect41.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
app/src/main/resources/assets/images/connect42.png
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
app/src/main/resources/assets/images/reversi1.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
app/src/main/resources/assets/images/reversi2.png
Normal file
|
After Width: | Height: | Size: 33 KiB |
BIN
app/src/main/resources/assets/images/tictactoe1.png
Normal file
|
After Width: | Height: | Size: 9.7 KiB |
BIN
app/src/main/resources/assets/images/tictactoe2.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
@@ -1,17 +0,0 @@
|
||||
# Window title
|
||||
windowTitle=ISY Games Selector
|
||||
|
||||
# Main Menu buttons
|
||||
mainMenuSelectTicTacToe=Tic Tac Toe
|
||||
mainMenuSelectReversi=Reversi
|
||||
mainMenuSelectSudoku=Sudoku
|
||||
mainMenuSelectBattleship=Battleship
|
||||
mainMenuSelectOther=Other
|
||||
mainMenuSelectCredits=Credits
|
||||
mainMenuSelectOptions=Options
|
||||
mainMenuSelectQuit=Quit
|
||||
|
||||
# Quit Menu text and buttons
|
||||
quitMenuTextSure=Are you sure?
|
||||
quitMenuButtonYes=Yes
|
||||
quitMenuButtonNo=No
|
||||
@@ -1,17 +0,0 @@
|
||||
# Window title
|
||||
windowTitle=ISY Spiele-Auswahl
|
||||
|
||||
# Main Menu buttons
|
||||
mainMenuSelectTicTacToe=Tic Tac Toe
|
||||
mainMenuSelectReversi=Reversi
|
||||
mainMenuSelectSudoku=Sudoku
|
||||
mainMenuSelectBattleship=Flottenman\u00F6ver
|
||||
mainMenuSelectOther=Andere
|
||||
mainMenuSelectCredits=Credits
|
||||
mainMenuSelectOptions=Optionen
|
||||
mainMenuSelectQuit=Beenden
|
||||
|
||||
# Quit Menu text and buttons
|
||||
quitMenuTextSure=Bist du sicher?
|
||||
quitMenuButtonYes=Ja
|
||||
quitMenuButtonNo=Nein
|
||||
@@ -1,17 +0,0 @@
|
||||
# Window title
|
||||
windowTitle=Selector de juegos ISY
|
||||
|
||||
# Main Menu buttons
|
||||
mainMenuSelectTicTacToe=Tres en raya
|
||||
mainMenuSelectReversi=Reversi
|
||||
mainMenuSelectSudoku=Sudoku
|
||||
mainMenuSelectBattleship=Batalla naval
|
||||
mainMenuSelectOther=Otros
|
||||
mainMenuSelectCredits=Cr\u00E9ditos
|
||||
mainMenuSelectOptions=Opciones
|
||||
mainMenuSelectQuit=Salir
|
||||
|
||||
# Quit Menu text and buttons
|
||||
quitMenuTextSure=\u00BFEst\u00E1s seguro?
|
||||
quitMenuButtonYes=S\u00ED
|
||||
quitMenuButtonNo=No
|
||||
@@ -1,17 +0,0 @@
|
||||
# Window title
|
||||
windowTitle=S\u00E9lecteur de jeux ISY
|
||||
|
||||
# Main Menu buttons
|
||||
mainMenuSelectTicTacToe=Morpion
|
||||
mainMenuSelectReversi=Reversi
|
||||
mainMenuSelectSudoku=Sudoku
|
||||
mainMenuSelectBattleship=Bataille navale
|
||||
mainMenuSelectOther=Autres
|
||||
mainMenuSelectCredits=Cr\u00E9dits
|
||||
mainMenuSelectOptions=Options
|
||||
mainMenuSelectQuit=Quitter
|
||||
|
||||
# Quit Menu text and buttons
|
||||
quitMenuTextSure=\u00CAtes-vous s\u00FBr?
|
||||
quitMenuButtonYes=Oui
|
||||
quitMenuButtonNo=Non
|
||||
@@ -1,17 +0,0 @@
|
||||
# Window title
|
||||
windowTitle=Selettore giochi ISY
|
||||
|
||||
# Main Menu buttons
|
||||
mainMenuSelectTicTacToe=Tris
|
||||
mainMenuSelectReversi=Reversi
|
||||
mainMenuSelectSudoku=Sudoku
|
||||
mainMenuSelectBattleship=Battaglia navale
|
||||
mainMenuSelectOther=Altro
|
||||
mainMenuSelectCredits=Crediti
|
||||
mainMenuSelectOptions=Opzioni
|
||||
mainMenuSelectQuit=Esci
|
||||
|
||||
# Quit Menu text and buttons
|
||||
quitMenuTextSure=Sei sicuro?
|
||||
quitMenuButtonYes=S\u00EC
|
||||
quitMenuButtonNo=No
|
||||
@@ -1,17 +0,0 @@
|
||||
# Window title
|
||||
windowTitle=ISY Spellen Kiezer
|
||||
|
||||
# Main Menu buttons
|
||||
mainMenuSelectTicTacToe=Boter Kaas En Eieren
|
||||
mainMenuSelectReversi=Reversi
|
||||
mainMenuSelectSudoku=Sudoku
|
||||
mainMenuSelectBattleship=Zeeslag
|
||||
mainMenuSelectOther=Anders
|
||||
mainMenuSelectCredits=Credits
|
||||
mainMenuSelectOptions=Opties
|
||||
mainMenuSelectQuit=Afsluiten
|
||||
|
||||
# Quit Menu text and buttons
|
||||
quitMenuTextSure=Weet je het zeker?
|
||||
quitMenuButtonYes=Ja
|
||||
quitMenuButtonNo=Nee
|
||||
@@ -1,30 +0,0 @@
|
||||
# suppress inspection "LossyEncoding" for whole file
|
||||
# Window title
|
||||
windowTitle=ISY \u6E38\u620F\u9009\u62E9\u5668
|
||||
# ?????
|
||||
|
||||
# Main Menu buttons
|
||||
mainMenuSelectTicTacToe=\u4E95\u5B57\u68CB
|
||||
# ???
|
||||
mainMenuSelectReversi=\u9ED1\u767D\u68CB
|
||||
# ???
|
||||
mainMenuSelectSudoku=\u6570\u72EC
|
||||
# ??
|
||||
mainMenuSelectBattleship=\u6D77\u6218\u68CB
|
||||
# ???
|
||||
mainMenuSelectOther=\u5176\u4ED6
|
||||
# ??
|
||||
mainMenuSelectCredits=\u5236\u4F5C\u4EBA\u5458
|
||||
# ????
|
||||
mainMenuSelectOptions=\u9009\u9879
|
||||
# ??
|
||||
mainMenuSelectQuit=\u9000\u51FA
|
||||
# ??
|
||||
|
||||
# Quit Menu text and buttons
|
||||
quitMenuTextSure=\u4F60\u786E\u5B9A\u5417\uFF1F
|
||||
# ?????
|
||||
quitMenuButtonYes=\u662F
|
||||
# ?
|
||||
quitMenuButtonNo=\u5426
|
||||
# ?
|
||||
@@ -1,37 +0,0 @@
|
||||
.background {
|
||||
-fx-background-color: linear-gradient(to bottom right, #21a7b2, #8f32b9);
|
||||
}
|
||||
|
||||
.text {
|
||||
-fx-fill: white;
|
||||
|
||||
-fx-font-family: "Segoe UI", sans-serif;
|
||||
-fx-font-weight: bold;
|
||||
-fx-font-size: 24px;
|
||||
}
|
||||
|
||||
.button, .text-field, .combo-box, .combo-box-popup .list-cell {
|
||||
-fx-padding: 10 20;
|
||||
|
||||
-fx-background-color: transparent;
|
||||
-fx-border-color: transparent;
|
||||
}
|
||||
|
||||
.combo-box-popup .list-view {
|
||||
-fx-background-color: #1d1d1d;
|
||||
}
|
||||
|
||||
.text-field {
|
||||
-fx-text-fill: white;
|
||||
}
|
||||
|
||||
.button:hover, .text-field:hover, .combo-box:hover, .combo-box-popup .list-cell:hover {
|
||||
-fx-cursor: hand;
|
||||
|
||||
-fx-effect: dropshadow(gaussian, #00ffff7f, 10, 0.5, 0, 0);
|
||||
-fx-border-color: white;
|
||||
}
|
||||
|
||||
.text-field:focused, .combo-box:focused {
|
||||
-fx-border-color: white;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
.quit_background {
|
||||
-fx-background-color: rgba(0, 0, 0, 0.6);
|
||||
}
|
||||
|
||||
.quit_box {
|
||||
-fx-background-color: rgba(30, 30, 30, 0.5);
|
||||
-fx-background-radius: 15;
|
||||
}
|
||||
106
app/src/main/resources/localization/localization_ar.properties
Normal file
@@ -0,0 +1,106 @@
|
||||
accept=\u0642\u0628\u0648\u0644
|
||||
ai=\u0627\u0644\u0630\u0643\u0627\u0621 \u0627\u0644\u0635\u0646\u0627\u0639\u064a
|
||||
app-title=\u0645\u062e\u062a\u0627\u0631 \u0627\u0644\u0643\u0627\u0645 \u0627\u0644\u0645\u062e\u062a\u0627\u0631
|
||||
are-you-sure=\u0647\u0644 \u0623\u0646\u062a \u0645\u062a\u0623\u0643\u062f?
|
||||
back=\u0627\u0644\u0631\u062c\u0648\u0639
|
||||
cancel=\u0625\u0644\u063a\u0627\u0621
|
||||
challenge=\u062a\u062d\u062f\u064a
|
||||
connect4=Connect 4
|
||||
computer-difficulty=\u0635\u0639\u0648\u0628 \u0627\u0644\u0643\u0645\u0628\u064a\u0648\u062a\u0631
|
||||
computer-think-time=\u0648\u0642\u062a \u062a\u0641\u0643\u064a\u0631 \u0627\u0644\u0643\u0645\u0628\u064a\u0648\u062a\u0631
|
||||
computer=\u0643\u0645\u0628\u064a\u0648\u062a\u0631
|
||||
connect=\u0627\u062a\u0635\u0627\u0644
|
||||
credits=\u0627\u0644\u0645\u0633\u0627\u0647\u0645\u0629
|
||||
dark=\u0638\u0644\u0627\u0645
|
||||
deny=\u0631\u0641\u0636
|
||||
developers=\u0627\u0644\u0645\u0637\u0648\u0631\u0648\u0646
|
||||
disconnect=\u0641\u0635\u0644 \u0627\u0644\u0627\u062a\u0635\u0627\u0644
|
||||
effects-volume=\u0635\u0648\u062a \u0627\u0644\u062a\u0623\u062b\u064a\u0631\u0627\u062a
|
||||
enter-the-server-ip=\u0623\u062f\u062e\u0644 \u0639\u0646\u0648\u0627\u0646 \u0627\u0644\u0633\u064a\u0631\u0641\u0631
|
||||
enter-the-server-port=\u0623\u062f\u062e\u0644 \u0645\u0646\u0641\u0630 \u0627\u0644\u0633\u064a\u0631\u0641\u0631
|
||||
enter-your-name=\u0623\u062f\u062e\u0644 \u0627\u0633\u0645\u0643
|
||||
error=\u062e\u0637\u0623
|
||||
exit=\u062e\u0631\u0648\u062c
|
||||
forfeit=\u0627\u0633\u062a\u0643\u0644\u0627\u0644
|
||||
fullscreen=\u0643\u0627\u0645\u0644 \u0627\u0644\u0634\u0627\u0634\u0629
|
||||
game-over=\u0627\u0646\u062a\u0647\u062a \u0627\u0644\u0644\u0639\u0628\u0629
|
||||
general=\u0639\u0627\u0645
|
||||
high-contrast=\u062A\u0628\u0627\u0646\u064A\u0629 \u0639\u0627\u0644\u064A
|
||||
invalid-username=\u0627\u0633\u0645 \u063a\u064a\u0631 \u0635\u062d\u064a\u062d
|
||||
ip-address=\u0639\u0646\u0648\u0627\u0646 IP
|
||||
is-not-a-valid-ip-address=\u0644\u064a\u0633 \u0639\u0646\u0648\u0627\u0646 IP \u0635\u062d\u064a\u062d
|
||||
is-not-a-valid-port=\u0644\u064a\u0633 \u0645\u0646\u0641\u0630 \u0635\u062d\u064a\u062d
|
||||
language=\u0644\u063a\u0629
|
||||
large=\u0633\u064a\u0631
|
||||
layout-size=\u062d\u062c\u0645 \u0627\u0644\u062a\u0635\u0645\u064a\u0645
|
||||
light=\u0636\u0624\u0621
|
||||
local=\u0645\u062d\u0644\u064a
|
||||
localization=\u062a\u0639\u0631\u064a\u0628 \u0627\u0644\u0644\u063a\u0629
|
||||
master-volume=\u0635\u0648\u062a \u0627\u0644\u0645\u0633\u062a\u0648\u0649
|
||||
medium=\u0645\u062a\u0648\u0633\u0637
|
||||
merge-commander=Merge Commander
|
||||
moral-support=\u062f\u0639\u0645 \u0623\u0639\u0635\u0627\u0628\u064a
|
||||
music-volume=\u0635\u0648\u062a \u0627\u0644\u0645\u0648\u0633\u064a\u0642\u0649
|
||||
name=\u0627\u0633\u0645
|
||||
never=\u0644\u0627\u060c \u0644\u0627 \u0623\u0631\u064A\u062F \u0623\u0646 \u0623\u0631\u0649 \u0623\u064A \u062F\u0631\u0648\u0633 \u0639\u0644\u0649 \u0627\u0644\u0625\u0637\u0644\u0627\u0642.
|
||||
no=\u0644\u0627
|
||||
ok=\u0645\u0648\u0627\u0641\u0642
|
||||
online=\u0645\u062a\u0635\u0644
|
||||
opengl=OpenGL
|
||||
options=\u062e\u064a\u0627\u0631\u0627\u062a
|
||||
play=\u0644\u0639\u0628
|
||||
player-name=\u0627\u0633\u0645 \u0627\u0644\u0644\u0627\u0639\u0628
|
||||
player=\u0644\u0627\u0639\u0628
|
||||
please-enter-your-name=\u064a\u0631\u062c\u0649 \u0623\u062f\u062e\u0644 \u0627\u0633\u0645\u0643
|
||||
port=\u0645\u0646\u0641\u0630
|
||||
product-owner=\u0635\u0627\u062d\u0628 \u0627\u0644\u0645\u0646\u062a\u062c
|
||||
quit=\u062e\u0631\u0648\u062c
|
||||
reversi=\u0631\u064a\u0641\u0631\u0633\u064a
|
||||
scrum-master=Scrum Master
|
||||
send=\u0625\u0631\u0633\u0627\u0644
|
||||
server-information=\u0645\u0639\u0644\u0648\u0645\u0627\u062a \u0627\u0644\u0633\u064a\u0631\u0641\u0631
|
||||
small=\u0635\u063a\u064a\u0631
|
||||
style=\u0623\u0633\u0644\u0648\u0628
|
||||
the-game-ended-in-a-draw=\u0627\u0646\u062a\u0647\u062a \u0627\u0644\u0644\u0639\u0628\u0629 \u0628\u062a\u0639\u0627\u062f\u0644
|
||||
theme=\u0645\u0648\u0636\u0648\u0639
|
||||
tic-tac-toe=\u062a\u064a\u0643 \u062a\u0627\u0643 \u062a\u0648
|
||||
tictactoe1 =\u0645\u0631\u062d\u0628\u064b\u0627 \u0628\u0643 \u0641\u064a \u0644\u0639\u0628\u0629 \u0625\u0643\u0633-\u0623\u0648! \u064a\u0645\u0643\u0646\u0643 \u0627\u0644\u0642\u064a\u0627\u0645 \u0628\u062d\u0631\u0643\u062a\u0643 \u0628\u0627\u0644\u0646\u0642\u0631 \u0639\u0644\u0649 \u0623\u064a \u0645\u0646 \u0627\u0644\u0645\u0631\u0628\u0639\u0627\u062a \u0627\u0644\u062a\u0633\u0639\u0629 \u0639\u0644\u0649 \u0627\u0644\u0644\u0648\u062d\u0629. \u0627\u0644\u0645\u062b\u0627\u0644 \u0623\u0639\u0644\u0627\u0647:
|
||||
tictactoe2 =\u064a\u0641\u0648\u0632 \u0627\u0644\u0644\u0627\u0639\u0628 \u0639\u0646\u062f\u0645\u0627 \u064a\u062d\u0635\u0644 \u0639\u0644\u0649 \u062b\u0644\u0627\u062b \u0642\u0637\u0639 \u0645\u062a\u062a\u0627\u0644\u064a\u0629 ? \u0623\u0641\u0642\u064a\u064b\u0627 \u0623\u0648 \u0639\u0645\u0648\u062f\u064a\u064b\u0627 \u0623\u0648 \u0642\u0637\u0631\u064a\u064b\u0627. \u0641\u064a \u0627\u0644\u0645\u062b\u0627\u0644 \u0623\u0639\u0644\u0627\u0647\u060c \u064a\u0641\u0648\u0632 \u0627\u0644\u0644\u0627\u0639\u0628 \u0628\u0635\u0641 \u0642\u0637\u0631\u064a \u0645\u0646 \u062b\u0644\u0627\u062b \u0642\u0637\u0639
|
||||
to-a-game-of=\u0625\u0644\u0649 \u0644\u0639\u0628\u0629 \u0645\u0646
|
||||
tutorial=\u0647\u0644 \u062a\u0631\u064a\u062f \u0645\u0634\u0627\u0647\u062f\u0629 \u062f\u0644\u064a\u0644 \u0644\u0647\u0630\u0627 \u0627\u0644\u0644\u0639\u0628\u0629\u061f
|
||||
volume=\u0635\u0648\u062a
|
||||
windowed=\u0641\u064a \u0646\u0641\u0630\u0629
|
||||
yes=\u0646\u0639\u0645
|
||||
you-lost-against=\u0623\u0646\u062a \u062e\u0633\u0631\u062a \u0636\u062f
|
||||
you-were-challenged-by=\u062a\u062d\u062f\u064a\u062a \u0645\u0646
|
||||
you-win=\u0623\u0646\u062a \u062a\u0641\u0648\u0632
|
||||
>=>
|
||||
<=<
|
||||
connect4.1=\u0645\u0631\u062d\u0628\u0627 \u0628\u0643 \u0641\u064a \u0644\u0639\u0628\u0629 Connect 4! \u064a\u0645\u0643\u0646\u0643 \u062a\u0633\u0645\u064a\u0629 \u0627\u0644\u0644\u0639\u0628 \u0645\u0646 \u0637\u0631\u0641 \u0645\u0646 \u0627\u0644\u0639\u0645\u0648\u062f\u0627\u062a. \u0633\u064a\u062a\u0645 \u0648\u0636\u0639 \u0627\u0644\u0644\u062d\u0629 \u0627\u0644\u0623\u0642\u0644 \u0641\u064a \u062a\u0644\u0643 \u0627\u0644\u0639\u0645\u0648\u062f\u0629 \u0627\u0644\u0645\u0644\u0623\u0629 \u0627\u0644\u062a\u064a \u0644\u064a\u0633\u062a\u0645\u0644\u0623 \u0627\u0644\u0645\u0644\u0623\u0629.
|
||||
connect4.2=\u064a\u0645\u0643\u0646\u0643 \u0627\u0644\u0641\u0648\u0632 \u0628\u0647\u0632\u0645 \u0623\u0631\u062c\u0639 \u0645\u0646 \u0627\u0644\u0642\u0637\u0639 \u0627\u0644\u0641\u064a \u0627\u0644\u0623\u0641\u0642 \u0623\u0648 \u0627\u0644\u0645\u064a\u0646 \u0623\u0648 \u0623\u0641\u0642 \u0639\u0644\u0649 \u0627\u0644\u0645\u0644\u0623\u0629!
|
||||
reversi1=\u0645\u0631\u062d\u0628\u0627 \u0628\u0643 \u0641\u064a \u0644\u0639\u0628\u0629 Reversi! \u064a\u0645\u0643\u0646\u0643 \u0627\u0644\u0644\u0639\u0628 \u0628\u0627\u0644\u0646\u0642\u0631 \u0639\u0644\u0649 \u0623\u064a \u0646\u0642\u0637\u0629 \u0645\u0634\u0631\u0641\u0629.
|
||||
reversi2=\u0639\u0646\u062f\u0645\u0627 \u062a\u0646\u0642\u0631 \u0639\u0644\u0649 \u0646\u0642\u0637\u0629 \u0633\u064a\u062a\u063a\u064a\u0631 \u062c\u0645\u064a\u0639 \u0627\u0644\u0644\u0648\u0639\u0627\u0628 \u0628\u064a\u0646 \u0645\u0643\u0627\u0646 \u062a\u0636\u0639 \u0627\u0644\u0646\u0642\u0637\u0629 \u0648\u0646\u0642\u0637\u0629 \u0627\u0644\u0644\u0648\u0639 \u0627\u0644\u062a\u0627\u0644\u064a \u0627\u0644\u0645\u0648\u062c\u0648\u062f.
|
||||
reversi3=\u0645\u0631\u062a\u0643 \u0642\u062f \u064a\u062a\u063a\u0627\u0637 \u0625\u0630\u0627 \u0644\u0645 \u064a\u0643\u0646 \u0647\u0646\u0627\u0643 \u062d\u0631\u0643 \u0642\u0627\u0646\u0648\u0646\u064a.
|
||||
reversi4=\u0627\u0644\u0644\u0627\u0639\u0628 \u0627\u0644\u0630\u064a \u064a\u0641\u0648\u0632 \u0641\u064a \u0646\u0647\u0627\u064a\u0629 \u0627\u0644\u0644\u0639\u0628 \u0647\u0648 \u0627\u0644\u0630\u064a \u064a\u0643\u0648\u0646 \u0644\u062f\u064a\u0647 \u0627\u0644\u0623\u0643\u062b\u0631 \u0645\u0646 \u0627\u0644\u0644\u0648\u0639\u0627\u0628 \u0639\u0644\u0649 \u0627\u0644\u0644\u0648\u062d\u0629.
|
||||
tutorialstring=\u0627\u0644\u062f\u0631\u0633 \u0627\u0644\u062a\u0648\u0636\u064a\u062d\u064a
|
||||
startgame=\u0627\u0628\u062f\u0623 \u0627\u0644\u0644\u0639\u0628\u0629!
|
||||
goback=\u0627\u0631\u062c\u0639
|
||||
turnof=\u062F\u0648\u0631\u0647
|
||||
zwartepiet=\u0633\u0647\u0644: Zwarte Piet
|
||||
sinterklaas=\u0645\u062a\u0648\u0633\u0637: Sint R. Klaas
|
||||
santa=\u0635\u0639\u0628: Santa
|
||||
|
||||
|
||||
arabic=\u0627\u0644\u0639\u0631\u0628\u064a\u0629
|
||||
chinese=\u4e2d\u6587 (\u0627\u0644\u0635\u064a\u0646\u064a\u0629)
|
||||
dutch=Nederlands (\u0627\u0644\u0647\u0648\u0644\u0646\u062f\u064a\u0629)
|
||||
english=English (\u0627\u0644\u0625\u0646\u062c\u0644\u064a\u0632\u064a\u0629)
|
||||
french=Fran\u00e7ais (\u0627\u0644\u0641\u0631\u0646\u0633\u064a\u0629)
|
||||
georgian=\u10e5\u10d0\u10e0\u10d4\u10e1\u10d8 (\u0627\u0644\u062c\u0648\u0631\u062c\u064a\u0629)
|
||||
german=Deutsch (\u0627\u0644\u0623\u0644\u0645\u0627\u0646\u064a\u0629)
|
||||
hindi=\u0939\u093f\u0928\u094d\u0926\u0940 (\u0627\u0644\u0647\u0646\u062f\u064a\u0629)
|
||||
italian=Italiano (\u0627\u0644\u0625\u064a\u0637\u0627\u0644\u064a\u0629)
|
||||
japanese=\u65e5\u672c\u8a9e (\u0627\u0644\u064a\u0627\u0628\u0627\u0646\u064a\u0629)
|
||||
korean=\ud55c\uad6d\uc5b4 (\u0627\u0644\u0643\u0648\u0631\u064a\u0629)
|
||||
russian=\u0420\u0443\u0441\u0441\u043a\u0438\u0439 (\u0627\u0644\u0631\u0648\u0633\u064a\u0629)
|
||||
spanish=Espa\u00f1ol (\u0627\u0644\u0625\u0633\u0628\u0627\u0646\u064a\u0629)
|
||||