Skip to content

Commit 789d635

Browse files
Android editor: Update game menu bar to match desktop editor
1 parent 16bb065 commit 789d635

14 files changed

Lines changed: 276 additions & 107 deletions

File tree

platform/android/editor/game_menu_utils_jni.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,24 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_editor_utils_GameMenuUtils_set
9090
#endif
9191
}
9292

93+
JNIEXPORT void JNICALL Java_org_godotengine_godot_editor_utils_GameMenuUtils_setSelectionAvoidLocked(JNIEnv *env, jclass clazz, jboolean enabled) {
94+
#ifdef TOOLS_ENABLED
95+
GameViewPlugin *game_view_plugin = _get_game_view_plugin();
96+
if (game_view_plugin != nullptr && game_view_plugin->get_debugger().is_valid()) {
97+
game_view_plugin->get_debugger()->set_selection_avoid_locked(enabled);
98+
}
99+
#endif
100+
}
101+
102+
JNIEXPORT void JNICALL Java_org_godotengine_godot_editor_utils_GameMenuUtils_setSelectionPreferGroup(JNIEnv *env, jclass clazz, jboolean enabled) {
103+
#ifdef TOOLS_ENABLED
104+
GameViewPlugin *game_view_plugin = _get_game_view_plugin();
105+
if (game_view_plugin != nullptr && game_view_plugin->get_debugger().is_valid()) {
106+
game_view_plugin->get_debugger()->set_selection_prefer_group(enabled);
107+
}
108+
#endif
109+
}
110+
93111
JNIEXPORT void JNICALL Java_org_godotengine_godot_editor_utils_GameMenuUtils_setCameraOverride(JNIEnv *env, jclass clazz, jboolean enabled) {
94112
#ifdef TOOLS_ENABLED
95113
GameViewPlugin *game_view_plugin = _get_game_view_plugin();

platform/android/editor/game_menu_utils_jni.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_editor_utils_GameMenuUtils_nex
3838
JNIEXPORT void JNICALL Java_org_godotengine_godot_editor_utils_GameMenuUtils_setNodeType(JNIEnv *env, jclass clazz, jint type);
3939
JNIEXPORT void JNICALL Java_org_godotengine_godot_editor_utils_GameMenuUtils_setSelectMode(JNIEnv *env, jclass clazz, jint mode);
4040
JNIEXPORT void JNICALL Java_org_godotengine_godot_editor_utils_GameMenuUtils_setSelectionVisible(JNIEnv *env, jclass clazz, jboolean visible);
41+
JNIEXPORT void JNICALL Java_org_godotengine_godot_editor_utils_GameMenuUtils_setSelectionAvoidLocked(JNIEnv *env, jclass clazz, jboolean enabled);
42+
JNIEXPORT void JNICALL Java_org_godotengine_godot_editor_utils_GameMenuUtils_setSelectionPreferGroup(JNIEnv *env, jclass clazz, jboolean enabled);
4143
JNIEXPORT void JNICALL Java_org_godotengine_godot_editor_utils_GameMenuUtils_setCameraOverride(JNIEnv *env, jclass clazz, jboolean enabled);
4244
JNIEXPORT void JNICALL Java_org_godotengine_godot_editor_utils_GameMenuUtils_setCameraManipulateMode(JNIEnv *env, jclass clazz, jint mode);
4345
JNIEXPORT void JNICALL Java_org_godotengine_godot_editor_utils_GameMenuUtils_resetCamera2DPosition(JNIEnv *env, jclass clazz);

platform/android/java/editor/src/main/java/org/godotengine/editor/BaseGodotEditor.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ abstract class BaseGodotEditor : GodotActivity(), GameMenuFragment.GameMenuListe
147147
internal const val GAME_MENU_ACTION_SET_NODE_TYPE = "setNodeType"
148148
internal const val GAME_MENU_ACTION_SET_SELECT_MODE = "setSelectMode"
149149
internal const val GAME_MENU_ACTION_SET_SELECTION_VISIBLE = "setSelectionVisible"
150+
internal const val GAME_MENU_ACTION_SET_SELECTION_AVOID_LOCKED = "setSelectionAvoidLocked"
151+
internal const val GAME_MENU_ACTION_SET_SELECTION_PREFER_GROUP = "setSelectionPreferGroup"
150152
internal const val GAME_MENU_ACTION_SET_CAMERA_OVERRIDE = "setCameraOverride"
151153
internal const val GAME_MENU_ACTION_SET_CAMERA_MANIPULATE_MODE = "setCameraManipulateMode"
152154
internal const val GAME_MENU_ACTION_RESET_CAMERA_2D_POSITION = "resetCamera2DPosition"
@@ -980,6 +982,14 @@ abstract class BaseGodotEditor : GodotActivity(), GameMenuFragment.GameMenuListe
980982
val enabled = actionData.getBoolean(KEY_GAME_MENU_ACTION_PARAM1)
981983
toggleSelectionVisibility(enabled)
982984
}
985+
GAME_MENU_ACTION_SET_SELECTION_AVOID_LOCKED -> {
986+
val enabled = actionData.getBoolean(KEY_GAME_MENU_ACTION_PARAM1)
987+
toggleSelectionAvoidLocked(enabled)
988+
}
989+
GAME_MENU_ACTION_SET_SELECTION_PREFER_GROUP -> {
990+
val enabled = actionData.getBoolean(KEY_GAME_MENU_ACTION_PARAM1)
991+
toggleSelectionPreferGroup(enabled)
992+
}
983993
GAME_MENU_ACTION_SET_CAMERA_OVERRIDE -> {
984994
val enabled = actionData.getBoolean(KEY_GAME_MENU_ACTION_PARAM1)
985995
overrideCamera(enabled)
@@ -1040,6 +1050,20 @@ abstract class BaseGodotEditor : GodotActivity(), GameMenuFragment.GameMenuListe
10401050
}
10411051
}
10421052

1053+
override fun toggleSelectionAvoidLocked(enabled: Boolean) {
1054+
gameMenuState.putBoolean(GAME_MENU_ACTION_SET_SELECTION_AVOID_LOCKED, enabled)
1055+
godot?.runOnRenderThread {
1056+
GameMenuUtils.setSelectionAvoidLocked(enabled)
1057+
}
1058+
}
1059+
1060+
override fun toggleSelectionPreferGroup(enabled: Boolean) {
1061+
gameMenuState.putBoolean(GAME_MENU_ACTION_SET_SELECTION_PREFER_GROUP, enabled)
1062+
godot?.runOnRenderThread {
1063+
GameMenuUtils.setSelectionPreferGroup(enabled)
1064+
}
1065+
}
1066+
10431067
override fun overrideCamera(enabled: Boolean) {
10441068
gameMenuState.putBoolean(GAME_MENU_ACTION_SET_CAMERA_OVERRIDE, enabled)
10451069
godot?.runOnRenderThread {

platform/android/java/editor/src/main/java/org/godotengine/editor/GodotGame.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,22 @@ open class GodotGame : BaseGodotGame() {
130130
editorMessageDispatcher.dispatchGameMenuAction(EDITOR_MAIN_INFO, actionBundle)
131131
}
132132

133+
override fun toggleSelectionAvoidLocked(enabled: Boolean) {
134+
val actionBundle = Bundle().apply {
135+
putString(KEY_GAME_MENU_ACTION, GAME_MENU_ACTION_SET_SELECTION_AVOID_LOCKED)
136+
putBoolean(KEY_GAME_MENU_ACTION_PARAM1, enabled)
137+
}
138+
editorMessageDispatcher.dispatchGameMenuAction(EDITOR_MAIN_INFO, actionBundle)
139+
}
140+
141+
override fun toggleSelectionPreferGroup(enabled: Boolean) {
142+
val actionBundle = Bundle().apply {
143+
putString(KEY_GAME_MENU_ACTION, GAME_MENU_ACTION_SET_SELECTION_PREFER_GROUP)
144+
putBoolean(KEY_GAME_MENU_ACTION_PARAM1, enabled)
145+
}
146+
editorMessageDispatcher.dispatchGameMenuAction(EDITOR_MAIN_INFO, actionBundle)
147+
}
148+
133149
override fun overrideCamera(enabled: Boolean) {
134150
val actionBundle = Bundle().apply {
135151
putString(KEY_GAME_MENU_ACTION, GAME_MENU_ACTION_SET_CAMERA_OVERRIDE)

platform/android/java/editor/src/main/java/org/godotengine/editor/embed/GameMenuFragment.kt

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import android.view.MotionEvent
4040
import android.view.View
4141
import android.view.ViewGroup
4242
import android.widget.Button
43+
import android.widget.ImageButton
4344
import android.widget.PopupMenu
4445
import android.widget.RadioButton
4546
import androidx.core.content.edit
@@ -98,6 +99,8 @@ class GameMenuFragment : Fragment(), PopupMenu.OnMenuItemClickListener {
9899
fun suspendGame(suspended: Boolean)
99100
fun dispatchNextFrame()
100101
fun toggleSelectionVisibility(enabled: Boolean)
102+
fun toggleSelectionAvoidLocked(enabled: Boolean)
103+
fun toggleSelectionPreferGroup(enabled: Boolean)
101104
fun overrideCamera(enabled: Boolean)
102105
fun selectRuntimeNode(nodeType: NodeType)
103106
fun selectRuntimeNodeSelectMode(selectMode: SelectMode)
@@ -142,9 +145,6 @@ class GameMenuFragment : Fragment(), PopupMenu.OnMenuItemClickListener {
142145
private val setTimeScaleButton: Button? by lazy {
143146
view?.findViewById<Button>(R.id.game_menu_set_time_scale_button)
144147
}
145-
private val resetTimeScaleButton: View? by lazy {
146-
view?.findViewById(R.id.game_menu_reset_time_scale_button)
147-
}
148148
private val unselectNodesButton: RadioButton? by lazy {
149149
view?.findViewById(R.id.game_menu_unselect_nodes_button)
150150
}
@@ -154,15 +154,15 @@ class GameMenuFragment : Fragment(), PopupMenu.OnMenuItemClickListener {
154154
private val select3DNodesButton: RadioButton? by lazy {
155155
view?.findViewById(R.id.game_menu_select_3d_nodes_button)
156156
}
157-
private val guiVisibilityButton: View? by lazy {
158-
view?.findViewById(R.id.game_menu_gui_visibility_button)
159-
}
160157
private val toolSelectButton: RadioButton? by lazy {
161158
view?.findViewById(R.id.game_menu_tool_select_button)
162159
}
163160
private val listSelectButton: RadioButton? by lazy {
164161
view?.findViewById(R.id.game_menu_list_select_button)
165162
}
163+
private val selectDropdownButton: ImageButton? by lazy {
164+
view?.findViewById(R.id.game_menu_select_dropdown_button)
165+
}
166166
private val audioMuteButton: View? by lazy {
167167
view?.findViewById(R.id.game_menu_audio_mute_button)
168168
}
@@ -192,6 +192,30 @@ class GameMenuFragment : Fragment(), PopupMenu.OnMenuItemClickListener {
192192
}
193193
}
194194

195+
private val selectDropdownMenu: PopupMenu by lazy {
196+
PopupMenu(context, selectDropdownButton).apply {
197+
inflate(R.menu.select_dropdown_menu)
198+
menu.setGroupDividerEnabled(true)
199+
setOnMenuItemClickListener { item: MenuItem ->
200+
when (item.itemId) {
201+
R.id.menu_show_selection_visibility -> {
202+
item.isChecked = !item.isChecked
203+
menuListener?.toggleSelectionVisibility(item.isChecked)
204+
}
205+
R.id.menu_dont_select_locked_nodes -> {
206+
item.isChecked = !item.isChecked
207+
menuListener?.toggleSelectionAvoidLocked(item.isChecked)
208+
}
209+
R.id.menu_select_group_over_children -> {
210+
item.isChecked = !item.isChecked
211+
menuListener?.toggleSelectionPreferGroup(item.isChecked)
212+
}
213+
}
214+
true
215+
}
216+
}
217+
}
218+
195219
private val timeScaleMenu: PopupMenu by lazy {
196220
PopupMenu(context, setTimeScaleButton).apply {
197221
inflate(R.menu.time_scale_options)
@@ -335,13 +359,6 @@ class GameMenuFragment : Fragment(), PopupMenu.OnMenuItemClickListener {
335359
}
336360
}
337361

338-
resetTimeScaleButton?.apply {
339-
setOnClickListener {
340-
menuListener?.resetTimeScale()
341-
setTimeScaleButton?.text = "1.0x"
342-
}
343-
}
344-
345362
unselectNodesButton?.apply{
346363
setOnCheckedChangeListener { buttonView, isChecked ->
347364
if (isChecked) {
@@ -363,13 +380,6 @@ class GameMenuFragment : Fragment(), PopupMenu.OnMenuItemClickListener {
363380
}
364381
}
365382
}
366-
guiVisibilityButton?.apply{
367-
setOnClickListener {
368-
val isActivated = !it.isActivated
369-
menuListener?.toggleSelectionVisibility(!isActivated)
370-
it.isActivated = isActivated
371-
}
372-
}
373383

374384
toolSelectButton?.apply{
375385
setOnCheckedChangeListener { buttonView, isChecked ->
@@ -385,6 +395,9 @@ class GameMenuFragment : Fragment(), PopupMenu.OnMenuItemClickListener {
385395
}
386396
}
387397
}
398+
selectDropdownButton?.setOnClickListener {
399+
selectDropdownMenu.show()
400+
}
388401
audioMuteButton?.apply{
389402
setOnClickListener {
390403
val isActivated = !it.isActivated
@@ -418,12 +431,16 @@ class GameMenuFragment : Fragment(), PopupMenu.OnMenuItemClickListener {
418431
select2DNodesButton?.isChecked = nodeType == GameMenuListener.NodeType.TYPE_2D
419432
select3DNodesButton?.isChecked = nodeType == GameMenuListener.NodeType.TYPE_3D
420433

421-
guiVisibilityButton?.isActivated = !gameMenuState.getBoolean(BaseGodotEditor.GAME_MENU_ACTION_SET_SELECTION_VISIBLE, true)
422-
423434
val selectMode = gameMenuState.getSerializable(BaseGodotEditor.GAME_MENU_ACTION_SET_SELECT_MODE) as GameMenuListener.SelectMode? ?: GameMenuListener.SelectMode.SINGLE
424435
toolSelectButton?.isChecked = selectMode == GameMenuListener.SelectMode.SINGLE
425436
listSelectButton?.isChecked = selectMode == GameMenuListener.SelectMode.LIST
426437

438+
selectDropdownMenu.menu.apply {
439+
findItem(R.id.menu_show_selection_visibility)?.isChecked = gameMenuState.getBoolean(BaseGodotEditor.GAME_MENU_ACTION_SET_SELECTION_VISIBLE, true)
440+
findItem(R.id.menu_dont_select_locked_nodes)?.isChecked = gameMenuState.getBoolean(BaseGodotEditor.GAME_MENU_ACTION_SET_SELECTION_AVOID_LOCKED, false)
441+
findItem(R.id.menu_select_group_over_children)?.isChecked = gameMenuState.getBoolean(BaseGodotEditor.GAME_MENU_ACTION_SET_SELECTION_PREFER_GROUP, false)
442+
}
443+
427444
audioMuteButton?.isActivated = gameMenuState.getBoolean(BaseGodotEditor.GAME_MENU_ACTION_SET_DEBUG_MUTE_AUDIO, false)
428445

429446
popupMenu.menu.apply {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:state_checked="true" android:color="#FFFFFF" />
4+
<item android:color="#808080" />
5+
</selector>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="16dp"
3+
android:height="16dp"
4+
android:tint="@color/game_menu_icons_color_state"
5+
android:viewportWidth="24"
6+
android:viewportHeight="24">
7+
8+
<path
9+
android:fillColor="@android:color/white"
10+
android:pathData="M16.59,8.59L12,13.17 7.41,8.59 6,10l6,6 6,-6z" />
11+
12+
</vector>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:shape="rectangle">
4+
5+
<solid android:color="#1C1C1C" />
6+
<corners android:radius="8dp" />
7+
8+
</shape>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:state_checked="true">
4+
<shape>
5+
<solid android:color="#333333" />
6+
<corners android:radius="6dp" />
7+
</shape>
8+
</item>
9+
10+
<item>
11+
<shape>
12+
<solid android:color="@android:color/transparent" />
13+
</shape>
14+
</item>
15+
</selector>

platform/android/java/editor/src/main/res/drawable/game_menu_selected_bg.xml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
<shape xmlns:android="http://schemas.android.com/apk/res/android"
33
android:shape="rectangle">
44

5-
<solid android:color="#3333b5e5" />
6-
<corners android:radius="5dp" />
7-
<stroke
8-
android:width="1dp"
9-
android:color="@android:color/holo_blue_dark" />
5+
<solid android:color="#333333" />
6+
<corners android:radius="6dp" />
107
</shape>

0 commit comments

Comments
 (0)