Skip to content

Commit

Permalink
new UI for dependency license viewing
Browse files Browse the repository at this point in the history
workaround for #85
closes #85
  • Loading branch information
Sesu8642 committed Nov 25, 2024
1 parent 33ca98e commit c514abf
Show file tree
Hide file tree
Showing 282 changed files with 363 additions and 121 deletions.
3 changes: 3 additions & 0 deletions assets/dependency_licenses/Acknowledgments/Slay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Many thanks to Sean O'Connor for his game Slay which this game is heavily inspired by!

Many thanks to Amit Patel for his guide to hexagonal grids on redblobgames.com!
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
Acknowledgments
===============

Many thanks to Sean O'Connor for his game Slay which this game is heavily inspired by!

Many thanks to Amit Patel for his guide to hexagonal grids on redblobgames.com!


Skin
======

based on Pixthulhu UI Ver. 1

Created by Raymond "Raeleus" Buckley
Expand All @@ -17,7 +6,3 @@ Visit ray3k.wordpress.com for games, tutorials, and much more!git res

Pixthulhu UI can be used under the CC BY license.
http://creativecommons.org/licenses/by/4.0/


Dependencies
============
11 changes: 8 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ configure(subprojects - project(':android')) {
// iterate through all files inside that folder
// convert it to a relative path
// and append it to the file assets.txt
fileTree(assetsFolder).collect { assetsFolder.relativePath(it) }.each {
assetsFile.append(it + "\n")
}

// customization: using a different method that doesn't resolve symlinks
fileTree(assetsFolder).visit { FileVisitDetails visitDetails ->
if (!visitDetails.directory) {
assetsFile.append(visitDetails.relativePath + "\n")
}
}

}
processResources.dependsOn 'generateAssetList'

Expand Down
21 changes: 0 additions & 21 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,6 @@ processResources {
duplicatesStrategy = "exclude"
}

// build license info text file
def license_texts = ''
// read prefix text
license_texts += file('../dependency_licenses/licenses_pre.txt').text
// iterate directories containing the dependency licenses
def base_dir = file("../dependency_licenses")
fileTree(dir: "../dependency_licenses").visit { FileVisitDetails dirDetails ->
if (dirDetails.directory) {
license_texts += "\n" + dirDetails.file.name
license_texts += "\n" + "-".multiply(dirDetails.file.name.length() * 1.2)
fileTree(dir: dirDetails.file.path).visit { FileVisitDetails fileDetails ->
if (!fileDetails.isDirectory()) {
license_texts += "\n\n" + fileDetails.file.name
license_texts += "\n" + fileDetails.file.text
}
}
}
}
// write the result
new File("$resources_dest_path/licenses.txt").text = license_texts

// build full changelog
def changelog_dir = "../metadata/en-US/changelogs/"
def changelog = ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import de.sesu8642.feudaltactics.menu.changelog.dagger.ChangelogScreen;
import de.sesu8642.feudaltactics.menu.common.ui.GameScreen;
import de.sesu8642.feudaltactics.menu.crashreporting.ui.CrashReportScreen;
import de.sesu8642.feudaltactics.menu.information.dagger.DependencyLicensesScreen;
import de.sesu8642.feudaltactics.menu.information.ui.DependencyLicensesScreen;
import de.sesu8642.feudaltactics.menu.information.ui.InformationMenuPage1Screen;
import de.sesu8642.feudaltactics.menu.information.ui.InformationMenuPage2Screen;
import de.sesu8642.feudaltactics.menu.mainmenu.ui.MainMenuScreen;
Expand Down Expand Up @@ -68,7 +68,7 @@ public ScreenNavigationController(EventBus eventBus, LocalIngameInputHandler loc
MainMenuScreen mainMenuScreen, @TutorialScreen GameScreen tutorialScreen,
@AboutScreen GameScreen aboutScreen, PreferencesScreen preferencesScreen,
InformationMenuPage1Screen informationMenuScreen, InformationMenuPage2Screen informationMenuScreen2,
@DependencyLicensesScreen GameScreen dependencyLicensesScreen, @ChangelogScreen GameScreen changelogScreen,
DependencyLicensesScreen dependencyLicensesScreen, @ChangelogScreen GameScreen changelogScreen,
CrashReportScreen crashReportScreen, GameControllerEventHandler gameLogicEventHandler,
EventHandler editorEventHandler, IngameRendererEventHandler rendererEventHandler,
IngameScreenEventHandler ingameScreenEventHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public class ExceptionLoggingChangeListener implements EventListener {

private final Runnable listener;

/**
* Constructor.
*
* @param listener runnable to be executed on change
*/
public ExceptionLoggingChangeListener(Runnable listener) {
this.listener = listener;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: GPL-3.0-or-later

package de.sesu8642.feudaltactics.menu.common.ui;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;

/**
* Click listener that causes a proper crash that is logged if an unexpected
* Exception happens.
*/
public class ExceptionLoggingClickListener extends ClickListener {

private final Logger logger = LoggerFactory.getLogger(this.getClass().getName());

private final Runnable listener;

/**
* Constructor.
*
* @param listener runnable to be executed on click
*/
public ExceptionLoggingClickListener(Runnable listener) {
this.listener = listener;
}

@Override
public void clicked(InputEvent event, float x, float y) {
try {
listener.run();
} catch (Exception e) {
logger.error("an unexpected exception happened in a cliock listener", e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ public void dispose() {
activeStage.dispose();
}

/**
* Switches to a new stage. Doesn't set it as the active InputProcessor.
*/
protected void setActiveStage(ResizableResettableStage activeStage) {
this.activeStage = activeStage;
}

public ResizableResettableStage getActiveStage() {
return activeStage;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Slide {
private static final float MAX_RESPONSIVE_IMAGE_WIDTH = Gdx.graphics.getDensity() * 1500F;

private Skin skin;
private Label headlineLabel;
private Table table = new Table();

/**
Expand All @@ -36,7 +37,7 @@ public Slide(Skin skin, String headline) {
// adding the headline is a hack needed because the slide would get a width of 0
// if the the label does not need to wrap (bug?)
Table hackTable = new Table();
Label headlineLabel = new Label(headline, skin.get(SkinConstants.FONT_HEADLINE, LabelStyle.class));
headlineLabel = new Label(headline, skin.get(SkinConstants.FONT_HEADLINE, LabelStyle.class));
hackTable.add(headlineLabel);
table.add(hackTable);
table.row();
Expand Down Expand Up @@ -96,5 +97,12 @@ public Slide addTable(List<List<String>> data) {
public Table getTable() {
return table;
}

/**
* Setter for the headline.
*/
public void setHeadline(String headline) {
headlineLabel.setText(headline);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class SlideStage extends ResizableResettableStage {
private Table currentSlide;
private TextButton backButton;
private TextButton nextButton;
private ScrollPane scrollPane;
private Container<Table> slideContainer = new Container<>();
private Runnable finishedCallback;

Expand Down Expand Up @@ -91,7 +92,7 @@ private void initUi(List<Table> slides) {

Stack slideAreaStack = new Stack(backgroundArea, slideContainer);

ScrollPane scrollPane = new ScrollPane(slideAreaStack, skin);
scrollPane = new ScrollPane(slideAreaStack, skin);
scrollPane.setFadeScrollBars(false);
scrollPane.setOverscroll(false, false);

Expand Down Expand Up @@ -149,6 +150,7 @@ public void reset() {
nextButton.setText(nextButtonText);
currentSlide = slides.get(0);
slideContainer.setActor(currentSlide);
scrollPane.setScrollY(0);
}

@Override
Expand Down Expand Up @@ -178,5 +180,5 @@ public void dispose() {
public void setFinishedCallback(Runnable finishedCallback) {
this.finishedCallback = finishedCallback;
}

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,17 @@

package de.sesu8642.feudaltactics.menu.information.dagger;

import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import javax.inject.Singleton;

import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.google.common.eventbus.EventBus;
import com.google.common.io.Resources;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;

import dagger.Module;
import dagger.Provides;
import de.sesu8642.feudaltactics.events.ScreenTransitionTriggerEvent;
import de.sesu8642.feudaltactics.events.ScreenTransitionTriggerEvent.ScreenTransitionTarget;
import de.sesu8642.feudaltactics.exceptions.InitializationException;
import de.sesu8642.feudaltactics.menu.common.dagger.MenuBackgroundCamera;
import de.sesu8642.feudaltactics.menu.common.dagger.MenuCamera;
import de.sesu8642.feudaltactics.menu.common.dagger.MenuViewport;
import de.sesu8642.feudaltactics.menu.common.ui.GameScreen;
import de.sesu8642.feudaltactics.menu.common.ui.Slide;
import de.sesu8642.feudaltactics.menu.common.ui.SlideStage;

/** Dagger module for the information sub-menu and its items. */
@Module
Expand All @@ -39,33 +26,34 @@ private InformationMenuDaggerModule() {
@Provides
@Singleton
@DependencyLicenses
static String provideDependencyLicensesText() {
try {
URL url = Resources.getResource("licenses.txt");
return Resources.toString(url, StandardCharsets.UTF_8);
} catch (IOException e) {
throw new InitializationException("Dependency licenses cannot be read!", e);
static Map<String, Map<String, String>> provideDependencyLicenses() {
FileHandle assetsFileHandle = Gdx.files.internal("assets.txt");
String assetListText = assetsFileHandle.readString(StandardCharsets.UTF_8.name());
String[] assets = assetListText.split("\n");
// outer map key: dependency name, inner map key: file name, outer map value:
// file contents
Map<String, Map<String, String>> result = new HashMap<>();
for (int i = 0; i < assets.length; i++) {
String assetPath = assets[i];
if (!assetPath.startsWith("dependency_licenses/")) {
continue;
}
String[] pathParts = assetPath.split("/");
String fileName = pathParts[pathParts.length - 1];
StringBuilder dependencyNameBuilder = new StringBuilder();
for (int j = 1; j < pathParts.length - 1; j++) {
if (dependencyNameBuilder.length() > 0) {
dependencyNameBuilder.append(" - ");
}
dependencyNameBuilder.append(pathParts[j]);
}
String dependencyName = dependencyNameBuilder.toString();
FileHandle fileHandle = Gdx.files.internal(assetPath);
String fileContents = fileHandle.readString(StandardCharsets.UTF_8.name());
result.putIfAbsent(dependencyName, new HashMap<>());
result.get(dependencyName).put(fileName, fileContents);
}
}

@Provides
@Singleton
@DependencyLicensesStage
static SlideStage provideDependencyLicensesStage(EventBus eventBus, @MenuViewport Viewport viewport,
@DependencyLicenses String dependencyLicensesText, @MenuBackgroundCamera OrthographicCamera camera,
Skin skin) {
Slide licenseSlide = new Slide(skin, "Dependency Licenses").addLabel(dependencyLicensesText);
return new SlideStage(viewport, Collections.singletonList(licenseSlide),
() -> eventBus.post(new ScreenTransitionTriggerEvent(ScreenTransitionTarget.INFORMATION_MENU_SCREEN_2)),
camera, skin);
}

@Provides
@Singleton
@DependencyLicensesScreen
static GameScreen provideDependencyLicensesScreen(@MenuCamera OrthographicCamera camera,
@MenuViewport Viewport viewport, @DependencyLicensesStage SlideStage dependencyLicensesStage) {
return new GameScreen(camera, viewport, dependencyLicensesStage);
return result;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: GPL-3.0-or-later

package de.sesu8642.feudaltactics.menu.information.ui;

import javax.inject.Inject;
import javax.inject.Singleton;

import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;

import de.sesu8642.feudaltactics.menu.common.ui.Slide;

// this is not created by the DependencyLicensesStage because that could only use static methods as the slide needs to be passed to the super constructor

/** UI for the dependency details. */
@Singleton
public class DependencyDetailsSlide extends Slide {

final Label label;

/**
* Constructor.
*/
@Inject
public DependencyDetailsSlide(Skin skin) {
super(skin, "Dependency Details");
label = new Label("", skin);
label.setWrap(true);
super.getTable().add(label).fill().expand();
}

}
Loading

0 comments on commit c514abf

Please sign in to comment.