A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/AlmasB/FXGL/commit/0d50a6397 below:

added showChoiceBox, closes #1094 · AlmasB/FXGL@0d50a63 · GitHub

File tree Expand file treeCollapse file tree 6 files changed

+72

-0

lines changed

Filter options

Expand file treeCollapse file tree 6 files changed

+72

-0

lines changed Original file line number Diff line number Diff line change

@@ -37,6 +37,11 @@ protected void initUI() {

37 37 38 38

dialogs.put("Error", () -> getDialogService().showErrorBox("This is a scary error box!", () -> {}));

39 39 40 +

dialogs.put("Choice with 1", () -> getDialogService().showChoiceBox("Choose wisely!", answer -> System.out.println("Chosen: " + answer), "Hello"));

41 +

dialogs.put("Choice with 2", () -> getDialogService().showChoiceBox("Choose wisely!", answer -> System.out.println("Chosen: " + answer), "Hello", "World"));

42 +

dialogs.put("Choice with 3", () -> getDialogService().showChoiceBox("Choose wisely!", answer -> System.out.println("Chosen: " + answer), "Hello", "World", "FXGL"));

43 +

dialogs.put("Choice with 4", () -> getDialogService().showChoiceBox("Choose wisely!", answer -> System.out.println("Chosen: " + answer), "Hello", "World", "FXGL", "JavaFX"));

44 + 40 45

dialogs.put("Confirmation", () -> getDialogService().showConfirmationBox("This is a confirmation box. Agree?", answer -> System.out.println("You pressed yes? " + answer)));

41 46 42 47

dialogs.put("Input", () -> getDialogService().showInputBox("This is an input box. You can type stuff...", answer -> System.out.println("You typed: "+ answer)));

Original file line number Diff line number Diff line change

@@ -26,6 +26,8 @@ public abstract class DialogFactoryService extends EngineService {

26 26 27 27

public abstract Pane confirmationDialog(String message, Consumer<Boolean> callback);

28 28 29 +

public abstract <T> Pane choiceDialog(String message, Consumer<T> resultCallback, T firstOption, T... options);

30 + 29 31

public abstract Pane inputDialog(String message, Consumer<String> callback);

30 32 31 33

public abstract Pane inputDialog(String message, Predicate<String> filter, Consumer<String> callback);

Original file line number Diff line number Diff line change

@@ -47,6 +47,18 @@ public abstract class DialogService extends EngineService {

47 47

*/

48 48

public abstract void showConfirmationBox(String message, Consumer<Boolean> resultCallback);

49 49 50 +

/**

51 +

* Shows a blocking message box with given choices.

52 +

* The callback is invoked with the user answer as parameter.

53 +

*

54 +

* @param message message to show

55 +

* @param resultCallback the function to be called

56 +

* @param firstOption the first option

57 +

* @param options any other options

58 +

* @param <T> type of options

59 +

*/

60 +

public abstract <T> void showChoiceBox(String message, Consumer<T> resultCallback, T firstOption, T... options);

61 + 50 62

/**

51 63

* Shows a blocking (stops game execution, method returns normally) message box with OK button and input field. The callback

52 64

* is invoked with the field text as parameter.

Original file line number Diff line number Diff line change

@@ -11,6 +11,7 @@ import com.almasb.fxgl.localization.LocalizationService

11 11

import javafx.beans.binding.StringBinding

12 12

import javafx.beans.property.ReadOnlyDoubleProperty

13 13

import javafx.beans.value.ChangeListener

14 +

import javafx.collections.FXCollections

14 15

import javafx.geometry.Insets

15 16

import javafx.geometry.Pos

16 17

import javafx.scene.Node

@@ -89,6 +90,46 @@ class FXGLDialogFactoryServiceProvider : DialogFactoryService() {

89 90

return wrap(vbox)

90 91

}

91 92 93 +

override fun <T : Any> choiceDialog(message: String, resultCallback: Consumer<T>, firstOption: T, vararg options: T): Pane {

94 +

val text = createMessage(message)

95 + 96 +

val choices = options.toMutableList()

97 +

choices.add(0, firstOption)

98 + 99 +

val hbox = HBox()

100 + 101 +

if (choices.size > 3) {

102 + 103 +

val choiceBox = uiFactory.newChoiceBox(FXCollections.observableArrayList(choices))

104 +

choiceBox.selectionModel.selectFirst()

105 + 106 +

val btn = uiFactory.newButton("Select")

107 +

btn.setOnAction {

108 +

resultCallback.accept(choiceBox.value)

109 +

}

110 + 111 +

hbox.children += choiceBox

112 +

hbox.children += btn

113 + 114 +

} else {

115 +

choices.forEach { option ->

116 +

val btn = uiFactory.newButton(option.toString())

117 +

btn.setOnAction {

118 +

resultCallback.accept(option)

119 +

}

120 + 121 +

hbox.children += btn

122 +

}

123 +

}

124 + 125 +

hbox.alignment = Pos.CENTER

126 + 127 +

val vbox = VBox(50.0, text, hbox)

128 +

vbox.setAlignment(Pos.CENTER)

129 + 130 +

return wrap(vbox)

131 +

}

132 + 92 133

override fun inputDialog(message: String, callback: Consumer<String>): Pane {

93 134

return inputDialog(message, Predicate { true }, callback)

94 135

}

Original file line number Diff line number Diff line change

@@ -133,6 +133,15 @@ class FXGLDialogService : DialogService() {

133 133

show("Confirm", dialog)

134 134

}

135 135 136 +

override fun <T : Any> showChoiceBox(message: String, callback: Consumer<T>, firstOption: T, vararg options: T) {

137 +

val dialog = dialogFactory.choiceDialog(message, { result ->

138 +

close()

139 +

callback.accept(result)

140 +

}, firstOption, *options)

141 + 142 +

show("Choice", dialog)

143 +

}

144 + 136 145

override fun showInputBox(message: String, resultCallback: Consumer<String>) {

137 146

showInputBox(message, Predicate { true }, resultCallback)

138 147

}

Original file line number Diff line number Diff line change

@@ -28,6 +28,9 @@ object MockDialogService : DialogService() {

28 28

override fun showConfirmationBox(message: String?, resultCallback: Consumer<Boolean>?) {

29 29

}

30 30 31 +

override fun <T : Any?> showChoiceBox(message: String?, resultCallback: Consumer<T>?, firstOption: T, vararg options: T) {

32 +

}

33 + 31 34

override fun showInputBoxWithCancel(message: String?, filter: Predicate<String>?, resultCallback: Consumer<String>?) {

32 35

}

33 36

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4