Merge pull request #17730 from RandomShaper/radio-buttons-in-menus
Radio buttons in menus
This commit is contained in:
commit
187b14ae24
14 changed files with 182 additions and 64 deletions
|
|
@ -626,8 +626,8 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
|
|||
theme->set_color("font_color_disabled", "PopupMenu", font_color_disabled);
|
||||
theme->set_icon("checked", "PopupMenu", theme->get_icon("GuiChecked", "EditorIcons"));
|
||||
theme->set_icon("unchecked", "PopupMenu", theme->get_icon("GuiUnchecked", "EditorIcons"));
|
||||
theme->set_icon("radio_checked", "PopupMenu", theme->get_icon("GuiChecked", "EditorIcons"));
|
||||
theme->set_icon("radio_unchecked", "PopupMenu", theme->get_icon("GuiUnchecked", "EditorIcons"));
|
||||
theme->set_icon("radio_checked", "PopupMenu", theme->get_icon("GuiRadioChecked", "EditorIcons"));
|
||||
theme->set_icon("radio_unchecked", "PopupMenu", theme->get_icon("GuiRadioUnchecked", "EditorIcons"));
|
||||
theme->set_icon("submenu", "PopupMenu", theme->get_icon("ArrowRight", "EditorIcons"));
|
||||
theme->set_icon("visibility_hidden", "PopupMenu", theme->get_icon("GuiVisibilityHidden", "EditorIcons"));
|
||||
theme->set_icon("visibility_visible", "PopupMenu", theme->get_icon("GuiVisibilityVisible", "EditorIcons"));
|
||||
|
|
|
|||
|
|
@ -1679,10 +1679,10 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor, AnimationPlay
|
|||
onion_skinning->get_popup()->add_separator();
|
||||
onion_skinning->get_popup()->add_item(TTR("Depth"), -1);
|
||||
onion_skinning->get_popup()->set_item_disabled(onion_skinning->get_popup()->get_item_count() - 1, true);
|
||||
onion_skinning->get_popup()->add_check_item(TTR("1 step"), ONION_SKINNING_1_STEP);
|
||||
onion_skinning->get_popup()->add_radio_check_item(TTR("1 step"), ONION_SKINNING_1_STEP);
|
||||
onion_skinning->get_popup()->set_item_checked(onion_skinning->get_popup()->get_item_count() - 1, true);
|
||||
onion_skinning->get_popup()->add_check_item(TTR("2 steps"), ONION_SKINNING_2_STEPS);
|
||||
onion_skinning->get_popup()->add_check_item(TTR("3 steps"), ONION_SKINNING_3_STEPS);
|
||||
onion_skinning->get_popup()->add_radio_check_item(TTR("2 steps"), ONION_SKINNING_2_STEPS);
|
||||
onion_skinning->get_popup()->add_radio_check_item(TTR("3 steps"), ONION_SKINNING_3_STEPS);
|
||||
onion_skinning->get_popup()->add_separator();
|
||||
onion_skinning->get_popup()->add_check_item(TTR("Differences Only"), ONION_SKINNING_DIFFERENCES_ONLY);
|
||||
onion_skinning->get_popup()->add_check_item(TTR("Force White Modulate"), ONION_SKINNING_FORCE_WHITE_MODULATE);
|
||||
|
|
|
|||
|
|
@ -42,9 +42,18 @@ bool ItemListPlugin::_set(const StringName &p_name, const Variant &p_value) {
|
|||
set_item_text(idx, p_value);
|
||||
else if (what == "icon")
|
||||
set_item_icon(idx, p_value);
|
||||
else if (what == "checkable")
|
||||
set_item_checkable(idx, p_value);
|
||||
else if (what == "checked")
|
||||
else if (what == "checkable") {
|
||||
// This keeps compatibility to/from versions where this property was a boolean, before radio buttons
|
||||
switch ((int)p_value) {
|
||||
case 0:
|
||||
case 1:
|
||||
set_item_checkable(idx, p_value);
|
||||
break;
|
||||
case 2:
|
||||
set_item_radio_checkable(idx, true);
|
||||
break;
|
||||
}
|
||||
} else if (what == "checked")
|
||||
set_item_checked(idx, p_value);
|
||||
else if (what == "id")
|
||||
set_item_id(idx, p_value);
|
||||
|
|
@ -68,9 +77,14 @@ bool ItemListPlugin::_get(const StringName &p_name, Variant &r_ret) const {
|
|||
r_ret = get_item_text(idx);
|
||||
else if (what == "icon")
|
||||
r_ret = get_item_icon(idx);
|
||||
else if (what == "checkable")
|
||||
r_ret = is_item_checkable(idx);
|
||||
else if (what == "checked")
|
||||
else if (what == "checkable") {
|
||||
// This keeps compatibility to/from versions where this property was a boolean, before radio buttons
|
||||
if (!is_item_checkable(idx)) {
|
||||
r_ret = 0;
|
||||
} else {
|
||||
r_ret = is_item_radio_checkable(idx) ? 2 : 1;
|
||||
}
|
||||
} else if (what == "checked")
|
||||
r_ret = is_item_checked(idx);
|
||||
else if (what == "id")
|
||||
r_ret = get_item_id(idx);
|
||||
|
|
@ -95,7 +109,7 @@ void ItemListPlugin::_get_property_list(List<PropertyInfo> *p_list) const {
|
|||
int flags = get_flags();
|
||||
|
||||
if (flags & FLAG_CHECKABLE) {
|
||||
p_list->push_back(PropertyInfo(Variant::BOOL, base + "checkable"));
|
||||
p_list->push_back(PropertyInfo(Variant::BOOL, base + "checkable", PROPERTY_HINT_ENUM, "No,As checkbox,As radio button"));
|
||||
p_list->push_back(PropertyInfo(Variant::BOOL, base + "checked"));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,9 @@ public:
|
|||
virtual Ref<Texture> get_item_icon(int p_idx) const { return Ref<Texture>(); };
|
||||
|
||||
virtual void set_item_checkable(int p_idx, bool p_check) {}
|
||||
virtual void set_item_radio_checkable(int p_idx, bool p_check) {}
|
||||
virtual bool is_item_checkable(int p_idx) const { return false; };
|
||||
virtual bool is_item_radio_checkable(int p_idx) const { return false; };
|
||||
|
||||
virtual void set_item_checked(int p_idx, bool p_checked) {}
|
||||
virtual bool is_item_checked(int p_idx) const { return false; };
|
||||
|
|
@ -145,7 +147,9 @@ public:
|
|||
virtual Ref<Texture> get_item_icon(int p_idx) const { return pp->get_item_icon(p_idx); }
|
||||
|
||||
virtual void set_item_checkable(int p_idx, bool p_check) { pp->set_item_as_checkable(p_idx, p_check); }
|
||||
virtual void set_item_radio_checkable(int p_idx, bool p_check) { pp->set_item_as_radio_checkable(p_idx, p_check); }
|
||||
virtual bool is_item_checkable(int p_idx) const { return pp->is_item_checkable(p_idx); }
|
||||
virtual bool is_item_radio_checkable(int p_idx) const { return pp->is_item_radio_checkable(p_idx); }
|
||||
|
||||
virtual void set_item_checked(int p_idx, bool p_checked) { pp->set_item_checked(p_idx, p_checked); }
|
||||
virtual bool is_item_checked(int p_idx) const { return pp->is_item_checked(p_idx); }
|
||||
|
|
|
|||
|
|
@ -3351,14 +3351,14 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed
|
|||
view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/front_view"), VIEW_FRONT);
|
||||
view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/rear_view"), VIEW_REAR);
|
||||
view_menu->get_popup()->add_separator();
|
||||
view_menu->get_popup()->add_check_item(TTR("Perspective") + " (" + ED_GET_SHORTCUT("spatial_editor/switch_perspective_orthogonal")->get_as_text() + ")", VIEW_PERSPECTIVE);
|
||||
view_menu->get_popup()->add_check_item(TTR("Orthogonal") + " (" + ED_GET_SHORTCUT("spatial_editor/switch_perspective_orthogonal")->get_as_text() + ")", VIEW_ORTHOGONAL);
|
||||
view_menu->get_popup()->add_radio_check_item(TTR("Perspective") + " (" + ED_GET_SHORTCUT("spatial_editor/switch_perspective_orthogonal")->get_as_text() + ")", VIEW_PERSPECTIVE);
|
||||
view_menu->get_popup()->add_radio_check_item(TTR("Orthogonal") + " (" + ED_GET_SHORTCUT("spatial_editor/switch_perspective_orthogonal")->get_as_text() + ")", VIEW_ORTHOGONAL);
|
||||
view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_PERSPECTIVE), true);
|
||||
view_menu->get_popup()->add_separator();
|
||||
view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_normal", TTR("Display Normal")), VIEW_DISPLAY_NORMAL);
|
||||
view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_wireframe", TTR("Display Wireframe")), VIEW_DISPLAY_WIREFRAME);
|
||||
view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_overdraw", TTR("Display Overdraw")), VIEW_DISPLAY_OVERDRAW);
|
||||
view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_unshaded", TTR("Display Unshaded")), VIEW_DISPLAY_SHADELESS);
|
||||
view_menu->get_popup()->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_normal", TTR("Display Normal")), VIEW_DISPLAY_NORMAL);
|
||||
view_menu->get_popup()->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_wireframe", TTR("Display Wireframe")), VIEW_DISPLAY_WIREFRAME);
|
||||
view_menu->get_popup()->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_overdraw", TTR("Display Overdraw")), VIEW_DISPLAY_OVERDRAW);
|
||||
view_menu->get_popup()->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_unshaded", TTR("Display Unshaded")), VIEW_DISPLAY_SHADELESS);
|
||||
view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL), true);
|
||||
view_menu->get_popup()->add_separator();
|
||||
view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_environment", TTR("View Environment")), VIEW_ENVIRONMENT);
|
||||
|
|
@ -5109,12 +5109,12 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) {
|
|||
accept = memnew(AcceptDialog);
|
||||
editor->get_gui_base()->add_child(accept);
|
||||
|
||||
p->add_check_shortcut(ED_SHORTCUT("spatial_editor/1_viewport", TTR("1 Viewport"), KEY_MASK_CMD + KEY_1), MENU_VIEW_USE_1_VIEWPORT);
|
||||
p->add_check_shortcut(ED_SHORTCUT("spatial_editor/2_viewports", TTR("2 Viewports"), KEY_MASK_CMD + KEY_2), MENU_VIEW_USE_2_VIEWPORTS);
|
||||
p->add_check_shortcut(ED_SHORTCUT("spatial_editor/2_viewports_alt", TTR("2 Viewports (Alt)"), KEY_MASK_ALT + KEY_MASK_CMD + KEY_2), MENU_VIEW_USE_2_VIEWPORTS_ALT);
|
||||
p->add_check_shortcut(ED_SHORTCUT("spatial_editor/3_viewports", TTR("3 Viewports"), KEY_MASK_CMD + KEY_3), MENU_VIEW_USE_3_VIEWPORTS);
|
||||
p->add_check_shortcut(ED_SHORTCUT("spatial_editor/3_viewports_alt", TTR("3 Viewports (Alt)"), KEY_MASK_ALT + KEY_MASK_CMD + KEY_3), MENU_VIEW_USE_3_VIEWPORTS_ALT);
|
||||
p->add_check_shortcut(ED_SHORTCUT("spatial_editor/4_viewports", TTR("4 Viewports"), KEY_MASK_CMD + KEY_4), MENU_VIEW_USE_4_VIEWPORTS);
|
||||
p->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/1_viewport", TTR("1 Viewport"), KEY_MASK_CMD + KEY_1), MENU_VIEW_USE_1_VIEWPORT);
|
||||
p->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/2_viewports", TTR("2 Viewports"), KEY_MASK_CMD + KEY_2), MENU_VIEW_USE_2_VIEWPORTS);
|
||||
p->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/2_viewports_alt", TTR("2 Viewports (Alt)"), KEY_MASK_ALT + KEY_MASK_CMD + KEY_2), MENU_VIEW_USE_2_VIEWPORTS_ALT);
|
||||
p->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/3_viewports", TTR("3 Viewports"), KEY_MASK_CMD + KEY_3), MENU_VIEW_USE_3_VIEWPORTS);
|
||||
p->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/3_viewports_alt", TTR("3 Viewports (Alt)"), KEY_MASK_ALT + KEY_MASK_CMD + KEY_3), MENU_VIEW_USE_3_VIEWPORTS_ALT);
|
||||
p->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/4_viewports", TTR("4 Viewports"), KEY_MASK_CMD + KEY_4), MENU_VIEW_USE_4_VIEWPORTS);
|
||||
p->add_separator();
|
||||
|
||||
p->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_origin", TTR("View Origin")), MENU_VIEW_ORIGIN);
|
||||
|
|
|
|||
|
|
@ -805,12 +805,10 @@ TextureRegionEditor::TextureRegionEditor(EditorNode *p_editor) {
|
|||
snap_mode_button->set_text(TTR("<None>"));
|
||||
PopupMenu *p = snap_mode_button->get_popup();
|
||||
p->set_hide_on_checkable_item_selection(false);
|
||||
p->add_item(TTR("<None>"), 0);
|
||||
p->add_item(TTR("Pixel Snap"), 1);
|
||||
p->add_item(TTR("Grid Snap"), 2);
|
||||
p->add_item(TTR("Auto Slice"), 3);
|
||||
for (int i = 0; i < 4; i++)
|
||||
p->set_item_as_checkable(i, true);
|
||||
p->add_radio_check_item(TTR("<None>"), 0);
|
||||
p->add_radio_check_item(TTR("Pixel Snap"), 1);
|
||||
p->add_radio_check_item(TTR("Grid Snap"), 2);
|
||||
p->add_radio_check_item(TTR("Auto Slice"), 3);
|
||||
p->set_item_checked(0, true);
|
||||
p->connect("id_pressed", this, "_set_snap_mode");
|
||||
hb_grid = memnew(HBoxContainer);
|
||||
|
|
|
|||
|
|
@ -692,6 +692,10 @@ ThemeEditor::ThemeEditor() {
|
|||
test_menu_button->get_popup()->add_check_item(TTR("Check Item"));
|
||||
test_menu_button->get_popup()->add_check_item(TTR("Checked Item"));
|
||||
test_menu_button->get_popup()->set_item_checked(2, true);
|
||||
test_menu_button->get_popup()->add_separator();
|
||||
test_menu_button->get_popup()->add_check_item(TTR("Radio Item"));
|
||||
test_menu_button->get_popup()->add_radio_check_item(TTR("Checked Radio Item"));
|
||||
test_menu_button->get_popup()->set_item_checked(5, true);
|
||||
first_vb->add_child(test_menu_button);
|
||||
|
||||
OptionButton *test_option_button = memnew(OptionButton);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue