Giter Club home page Giter Club logo

gdx-dialogs's Introduction

gdx-dialogs

libGDX extension providing cross-platform support for native dialogs

Alt text

Updates & News

Follow me to receive release updates about this and my other projects (Promise: No BS posts)

https://twitter.com/TomGrillGames and https://www.facebook.com/tomgrillgames

I will also stream sometimes when developing at https://www.twitch.tv/tomgrill and write a blog article from time to time at http://tomgrill.de

Version

Current stable: 1.3.0 (Snapshot versions are no longer provided)

##Supported Platforms Android, iOS, iOS-MOE, Desktop (kinda) Desktop show Java UI Dialogs which usually dont fit very well in desktop game. I added Desktop support mainly to make testing while developing easier.

##Requirements libGDX 1.9.3+, Android API 9+, ios 6+, ios-moe 9+

##Currently available dialog types

  1. ButtonDialog: shows a dialog with 1-3 buttons for the user to click.
  2. ProgressDialog: Shows dialog with a progress wheel. Not cancelable by the user.
  3. TextPrompt: On screen display with text input.

Installation

Core

Add this to your build.gradle core dependencies

compile "de.tomgrill.gdxdialogs:gdx-dialogs-core:1.3.0"

Android

Add this to your build.gradle android dependencies

compile "de.tomgrill.gdxdialogs:gdx-dialogs-android:1.3.0"

Copy the /gdx-dialogs-android/res folder from this project to your android project. Keep the directory structure.

You can edit the /gdx-dialogs-android/res/values-v11/styles.xml if you want use another theme like Holo.Light

If your project already has styles.xml file make sure you merge what you need from both files.

iOS

Add this to your robovm.xml

<forceLinkClasses>
    ....
    <pattern>de.tomgrill.gdxdialogs.ios.IOSGDXDialogs</pattern>
</forceLinkClasses>

Add this to your build.gradle ios dependencies

compile "de.tomgrill.gdxdialogs:gdx-dialogs-ios:1.3.0"

iOS-MOE

Add this to your build.gradle ios-moe dependencies

compile "de.tomgrill.gdxdialogs:gdx-dialogs-ios-moe:1.3.0"

Desktop

Add this to your build.gradle desktop dependencies

compile "de.tomgrill.gdxdialogs:gdx-dialogs-desktop:1.3.0"

HTML(GWT)

Add this to your build.gradle html dependencies

compile "de.tomgrill.gdxdialogs:gdx-dialogs-html:1.3.0"
compile "de.tomgrill.gdxdialogs:gdx-dialogs-core:1.3.0:sources"
compile "de.tomgrill.gdxdialogs:gdx-dialogs-html:1.3.0:sources"

Add this to your GdxDefinition.gwt.xml

<inherits name='de.tomgrill.gdxdialogs.html.gdx_dialogs_html' />
<inherits name="de.tomgrill.gdxdialogs.core.gdx_dialogs_core" />

Usage

View the gdx-dialogs sample app https://github.com/TomGrill/gdx-dialogs-app

Enable

GDXDialogs dialogs = GDXDialogsSystem.install();

ButtonDialog

GDXButtonDialog bDialog = dialogs.newDialog(GDXButtonDialog.class);
bDialog.setTitle("Buy a item");
bDialog.setMessage("Do you want to buy the mozarella?");

bDialog.setClickListener(new ButtonClickListener() {

	@Override
	public void click(int button) {
		// handle button click here
	}
});

bDialog.addButton("No");
bDialog.addButton("Never");
bDialog.addButton("Yes, nomnom!");

bDialog.build().show();

ProgressDialog

GDXProgressDialog progressDialog = dialogs.newDialog(GDXProgressDialog.class);

progressDialog.setTitle("Download");
progressDialog.setMessage("Loading new level from server...");

progressDialog.build().show();

TextPrompt

GDXTextPrompt textPrompt = dialogs.newDialog(GDXTextPrompt.class);

textPrompt.setTitle("Your name");
textPrompt.setMessage("Please tell me your name.");

textPrompt.setCancelButtonLabel("Cancel");
textPrompt.setConfirmButtonLabel("Save name");

textPrompt.setTextPromptListener(new TextPromptListener() {

	@Override
	public void confirm(String text) {
	  // do something with the user input
	}

	@Override
	public void cancel() {
	  // handle input cancel
	}
});

textPrompt.build().show();

Open GL Context

Sometimes you want to call a method within one of your listeners which requires OpenGL context from the libgdx main thread. Since all dialogs run in their own thread (without OpenGL context) you have to make sure your method runs in the main thread by wrapping as postRunnable:

dialog.setClickListener(new ButtonClickListener() {
    @Override
    public void click(int button) {
        Gdx.app.postRunnable(new Runnable() {
            @Override
            public void run() {
                // call the a method which requires OpenGL context.
            }
        });
    }
});

Create your own dialogs.

In case you require are certain dialog (F.e. DatePicker, ProgressBar, ....) which is not supported by gdx-dialogs yet you can write your own dialog.

  1. Create a interface like this (in core project): GDXButtonDialog
  2. Create the implementation for Android like this (in android project): AndroidGDXButtonDialog
  3. Create the implementation for Desktop like this (in desktop project): DesktopGDXButtonDialog
  4. Create the implementation for iOS like this (in ios project): IOSGDXButtonDialog
  5. Create a fallback implementation with empty methods (in core project): FallbackGDXButtonDialog

If your dialog is written register it like this:

if(Gdx.app.getType() == ApplicationType.Android) {
	dialogs.registerDialog("package.for.your.dialog.interface.GDXButtonDialog", "package.for.your.dialog.os.specific.implementation.AndroidGDXButtonDialog");
}

else if(Gdx.app.getType() == ApplicationType.Desktop) {
	dialogs.registerDialog("package.for.your.dialog.interface.GDXButtonDialog", "package.for.your.dialog.os.specific.implementation.DesktopGDXButtonDialog");
}

else if(Gdx.app.getType() == ApplicationType.iOS) {
	dialogs.registerDialog("package.for.your.dialog.interface.GDXButtonDialog", "package.for.your.dialog.os.specific.implementation.IOSGDXButtonDialog");
}

else {
	dialogs.registerDialog("package.for.your.dialog.interface.GDXButtonDialog", "package.for.your.dialog.os.specific.implementation.FallbackGDXButtonDialog");
}

Use your own dialog:

dialogs.newDialog(GDXButtonDialog.class); // Use your dialog interface here

Note: Every platform specific implementation must have constructor even if it is empty. Android implementations must have a contructor accepting Activity parameter.

Increase your karma points :) Share your dialog with us, add it to this repository and make a Pull Request.

##Release History

Release history for major milestones (available via Maven):

  • Version 1.3.0: Bugfix: Submodules had dependency on SNAPSHOT versions
  • Version 1.2.5: Bugfix: DesktopTextPrompt;
  • Version 1.2.4: Bugfix: DesktopTextPrompt;
  • Version 1.2.3: Bugfix: DesktopTextPrompt not showing default value;
  • Version 1.2.2: TextPrompt can now be used as a password field. Use setInputType(...);
  • Version 1.2.1: TextPrompt dialogs have new setMaxLength() method.
  • Version 1.2.0: gwt/html support
  • Version 1.1.0: ios-moe support, ios support, Android proguard setup now out of the box
  • Version 1.0.0: no changes, just released 0.2.0 as first stable build
  • Version 0.2.0: API Changes. You can create own dialogs now.
  • Version 0.1.0: Initial Release

##Reporting Issues

Something not working quite as expected? Do you need a feature that has not been implemented yet? Check the issue tracker and add a new one if your problem is not already listed. Please try to provide a detailed description of your problem, including the steps to reproduce it.

##Contributing

Awesome! If you would like to contribute with a new feature or a bugfix, fork this repo and submit a pull request.

##License

The gdx-dialogs project is licensed under the Apache 2 License, meaning you can use it free of charge, without strings attached in commercial and non-commercial projects. We love to get (non-mandatory) credit in case you release a game or app using gdx-dialogs!

gdx-dialogs's People

Contributors

fxzjshm avatar kromzem avatar mustii82 avatar piotr-j avatar samuelhnrq avatar tobloef avatar tomgrill avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gdx-dialogs's Issues

GWT support?

Could you please add JavaScript dialogs in project 'html'?

ProGuard rules needed for Android

It seems that ProGuard obfuscation by default will break gdx-dialogs, due to the reflection used in GDXDialogsSystem.

See the libGDX forums: http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=22698. Note that this isn't my thread, and I don't have details beyond what the OP mentions. In particular, I haven't tested the fix that I suggest there, and I'm not even sure it's syntactically valid.

It would be good to mention this in the setup instructions in the README, or even supply a ProGuard config that will automatically be pulled in (if such a thing is possible).

Input Dialog not work

Exception in thread "Thread-2" java.lang.NullPointerException
at javax.swing.plaf.basic.BasicOptionPaneUI.addButtonComponents(BasicOptionPaneUI.java:673)
at javax.swing.plaf.basic.BasicOptionPaneUI.createButtonArea(BasicOptionPaneUI.java:630)
at com.apple.laf.AquaOptionPaneUI.createButtonArea(AquaOptionPaneUI.java:53)
at javax.swing.plaf.basic.BasicOptionPaneUI.installComponents(BasicOptionPaneUI.java:178)
at javax.swing.plaf.basic.BasicOptionPaneUI.installUI(BasicOptionPaneUI.java:141)
at javax.swing.JComponent.setUI(JComponent.java:666)
at javax.swing.JOptionPane.setUI(JOptionPane.java:1860)
at javax.swing.JOptionPane.updateUI(JOptionPane.java:1882)
at javax.swing.JOptionPane.(JOptionPane.java:1845)
at javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:857)
at de.tomgrill.gdxdialogs.desktop.dialogs.DesktopGDXTextPrompt$1.run(DesktopGDXTextPrompt.java:76)
at java.lang.Thread.run(Thread.java:745)

I get always this Error on 1.2.3 when I want to show a TextInput Dialog on Desktop

Android SDK Problem

Error:Execution failed for task ':android:processDebugManifest'.

Manifest merger failed : uses-sdk:minSdkVersion 9 cannot be smaller than version 15 declared in library [de.tomgrill.gdxdialogs:gdx-dialogs-android:1.1.0] .../android/build/intermediates/exploded-aar/de.tomgrill.gdxdialogs/gdx-dialogs-android/1.1.0/AndroidManifest.xml
Suggestion: use tools:overrideLibrary="de.tomgrill.gdxdialogs.android" to force usage

Why does the Library on the new version need at least SDK 15?

DesktopGDXTextPrompt bug

There's a small bug in the text prompt for desktop. When you close the dialog it is registered as confirmed. This happens because CLOSED_OPTION is not considered as the return value of showOptionDialog(). Here's a simplified version of the current code:

int response = JOptionPane.showOptionDialog(...);
if (response == 1) {
    listener.cancel();
} else {
    listener.confirm(...);
}
// CLOSED_OPTION is not considered

According to the javadoc of showOptionDialog():

@return an integer indicating the option chosen by the user,
or CLOSED_OPTION if the user closed the dialog

So fixing it would be as easy as adding an else if branch.

Exception android.view.WindowManager$BadTokenException: Unable to add window -- token

Some of my Users get this Exceptions randomly:

Exception android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@1b77d4b9 is not valid; is your activity running?
android.view.ViewRootImpl.setView (ViewRootImpl.java:574)
android.view.WindowManagerGlobal.addView (WindowManagerGlobal.java:282)
android.view.WindowManagerImpl.addView (WindowManagerImpl.java:85)
android.app.Dialog.show (Dialog.java:298)
de.tomgrill.gdxdialogs.android.dialogs.AndroidGDXButtonDialog$1.run (AndroidGDXButtonDialog.java:70)
android.os.Handler.handleCallback (Handler.java:739)
android.os.Handler.dispatchMessage (Handler.java:95)
android.os.Looper.loop (Looper.java:135)
android.app.ActivityThread.main (ActivityThread.java:5910)
java.lang.reflect.Method.invoke (Method.java)
java.lang.reflect.Method.invoke (Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1405)

ANR on Android

Broadcast of Intent { act=android.intent.action.SCREEN_OFF flg=0x50000010 launchParam=MultiScreenLaunchParams { mDisplayId=0 mBaseDisplayId=0 mFlags=0 } (has extras) }

at java.lang.Thread.sleep! (Native method) - sleeping on <0x0439898d> (a java.lang.Object) at java.lang.Thread.sleep (Thread.java:371) - locked <0x0439898d> (a java.lang.Object) at java.lang.Thread.sleep (Thread.java:313) at de.tomgrill.gdxdialogs.android.dialogs.AndroidGDXButtonDialog.build (AndroidGDXButtonDialog.java:172) at cfh.k (myesjxbmv.java:16525) at cfh.a (myesjxbmv.java:37155) at cfr.b (ucveuxxeo.java:132) at do.onDrawFrame (AndroidGraphics.java:5383)

Many of my users get this ANR

1.1 Problems

I get in logical this error on the most time i exit a dialog: exit Monitoring
after that every thing freeze

with 1.0 it works fine...

How to implement a Textfield only dialog which activates the textinput onShow?

Hi there Tom!

There's a game called Hearthstone. They have some textfields in there and they work like this:

When user clicks the textfield it doesn't open any dialog and it opens the white field with keyboard visible below:

image

I can open this field with your Dialogs too, but only when I click on a textfield in a TextPromptDialog.

Is there any way that you could help me implementing the 'instant' textfield only dialog like on the screen?

I mean - a dialog which is not a dialog, but an EditText which just prompts this white area.

I would be grateful!

No OpenGL context found in the current thread. On setScreen();

If I call setScreen(); in a dialog o'clock function I get this error:

Exception in thread "Thread-1" java.lang.RuntimeException: No OpenGL context found in the current thread.
at org.lwjgl.opengl.GLContext.getCapabilities(GLContext.java:124)
at org.lwjgl.opengl.GL20.glCreateShader(GL20.java:219)
at com.badlogic.gdx.backends.lwjgl.LwjglGL20.glCreateShader(LwjglGL20.java:201)
at com.badlogic.gdx.graphics.glutils.ShaderProgram.loadShader(ShaderProgram.java:207)
at com.badlogic.gdx.graphics.glutils.ShaderProgram.compileShaders(ShaderProgram.java:186)
at com.badlogic.gdx.graphics.glutils.ShaderProgram.(ShaderProgram.java:169)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.createDefaultShader(SpriteBatch.java:156)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.(SpriteBatch.java:120)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.(SpriteBatch.java:73)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.