diff options
-rw-r--r-- | doc/classes/Engine.xml | 16 | ||||
-rw-r--r-- | doc/classes/bool.xml | 33 | ||||
-rw-r--r-- | editor/plugins/polygon_2d_editor_plugin.cpp | 1 | ||||
-rw-r--r-- | editor/plugins/texture_region_editor_plugin.cpp | 1 | ||||
-rw-r--r-- | scene/gui/graph_edit.cpp | 17 | ||||
-rw-r--r-- | scene/gui/scroll_container.cpp | 57 | ||||
-rw-r--r-- | scene/gui/scroll_container.h | 1 |
7 files changed, 68 insertions, 58 deletions
diff --git a/doc/classes/Engine.xml b/doc/classes/Engine.xml index 04e203793b..53ddde0e4a 100644 --- a/doc/classes/Engine.xml +++ b/doc/classes/Engine.xml @@ -41,7 +41,7 @@ <return type="int"> </return> <description> - Returns the total number of frames drawn. + Returns the total number of frames drawn. If the render loop is disabled with [code]--disable-render-loop[/code] via command line, this returns [code]0[/code]. See also [method get_idle_frames]. </description> </method> <method name="get_frames_per_second" qualifiers="const"> @@ -51,6 +51,13 @@ Returns the frames per second of the running game. </description> </method> + <method name="get_idle_frames" qualifiers="const"> + <return type="int"> + </return> + <description> + Returns the total number of frames passed since engine initialization which is advanced on each [b]idle frame[/b], regardless of whether the render loop is enabled. See also [method get_frames_drawn]. + </description> + </method> <method name="get_license_info" qualifiers="const"> <return type="Dictionary"> </return> @@ -72,6 +79,13 @@ Returns the main loop object (see [MainLoop] and [SceneTree]). </description> </method> + <method name="get_physics_frames" qualifiers="const"> + <return type="int"> + </return> + <description> + Returns the total number of frames passed since engine initialization which is advanced on each [b]physics frame[/b]. + </description> + </method> <method name="get_physics_interpolation_fraction" qualifiers="const"> <return type="float"> </return> diff --git a/doc/classes/bool.xml b/doc/classes/bool.xml index 533963b460..ba6a932d4f 100644 --- a/doc/classes/bool.xml +++ b/doc/classes/bool.xml @@ -4,7 +4,38 @@ Boolean built-in type. </brief_description> <description> - Boolean built-in type. + Boolean is a built-in type. It can represent any data type that is either a true or false value. You can think of it as an switch with on or off (1 or 0) setting . It's often used as part of programming logic in condition statements like [code]if[/code] statements. + [b]Note:[/b] In a code below [code]if can_shoot[/code] is equivalent of [code]if can_shoot == true[/code]. It is good practice to follow the natural spoken language structure when possible. Use [code]if can_shoot[/code] rather than [code]if can_shoot == true[/code] and use [code]if not can_shoot[/code] rather than [code]if can_shoot == false[/code]. + [codeblock] + var can_shoot = true + + func shoot(): + if can_shoot: + # Perform shooting actions here. + [/codeblock] + The following code will only create a bullet if both conditions are met: action "shoot" is pressed and if [code]can_shoot[/code] is [code]true[/code]. + [b]Note:[/b] [code]Input.is_action_pressed("shoot")[/code] is also a boolean that is [code]true[/code] when "shoot" is pressed and [code]false[/code] when "shoot" isn't pressed. + [codeblock] + var can_shoot = true + + func shoot(): + if can_shoot and Input.is_action_pressed("shoot"): + create_bullet() + [/codeblock] + The following code will set [code]can_shoot[/code] to [code]false[/code] and start a timer. This will prevent player from shooting until the timer runs out. Next [code]can_shoot[/code] will be set to [code]true[/code] again allowing player to shoot once again. + [codeblock] + var can_shoot = true + onready var cool_down = $CoolDownTimer + + func shoot(): + if can_shoot and Input.is_action_pressed("shoot"): + create_bullet() + can_shoot = false + cool_down.start() + + func _on_CoolDownTimer_timeout(): + can_shoot = true + [/codeblock] </description> <tutorials> </tutorials> diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp index dbb2934ffb..04d595461d 100644 --- a/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/editor/plugins/polygon_2d_editor_plugin.cpp @@ -1477,7 +1477,6 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) : uv_hscroll->set_step(0.001); uv_edit_draw->add_child(uv_hscroll); uv_hscroll->set_anchors_and_margins_preset(PRESET_BOTTOM_WIDE); - uv_hscroll->set_margin(MARGIN_RIGHT, -uv_vscroll->get_size().x * EDSCALE); uv_hscroll->connect("value_changed", this, "_uv_scroll_changed"); bone_scroll_main_vb = memnew(VBoxContainer); diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index 8672e936e0..f9b1e3b43a 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -1028,7 +1028,6 @@ TextureRegionEditor::TextureRegionEditor(EditorNode *p_editor) { hscroll->set_step(0.001); edit_draw->add_child(hscroll); hscroll->set_anchors_and_margins_preset(PRESET_BOTTOM_WIDE); - hscroll->set_margin(MARGIN_RIGHT, -vscroll->get_size().x * EDSCALE); hscroll->connect("value_changed", this, "_scroll_changed"); updating_scroll = false; diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 42bb8023f2..399f998cb9 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -289,20 +289,6 @@ void GraphEdit::_notification(int p_what) { zoom_plus->set_icon(get_icon("more")); snap_button->set_icon(get_icon("snap")); } - if (p_what == NOTIFICATION_READY) { - Size2 hmin = h_scroll->get_combined_minimum_size(); - Size2 vmin = v_scroll->get_combined_minimum_size(); - - v_scroll->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, -vmin.width); - v_scroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0); - v_scroll->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 0); - v_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0); - - h_scroll->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 0); - h_scroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0); - h_scroll->set_anchor_and_margin(MARGIN_TOP, ANCHOR_END, -hmin.height); - h_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0); - } if (p_what == NOTIFICATION_DRAW) { draw_style_box(get_stylebox("bg"), Rect2(Point2(), get_size())); @@ -1355,10 +1341,13 @@ GraphEdit::GraphEdit() { h_scroll = memnew(HScrollBar); h_scroll->set_name("_h_scroll"); top_layer->add_child(h_scroll); + h_scroll->set_anchors_and_margins_preset(PRESET_BOTTOM_WIDE); v_scroll = memnew(VScrollBar); v_scroll->set_name("_v_scroll"); top_layer->add_child(v_scroll); + v_scroll->set_anchors_and_margins_preset(PRESET_RIGHT_WIDE); + updating = false; connecting = false; right_disconnects = false; diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp index 4712f4cb9d..05645d0263 100644 --- a/scene/gui/scroll_container.cpp +++ b/scene/gui/scroll_container.cpp @@ -214,25 +214,6 @@ void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) { accept_event(); //accept event if scroll changed } -void ScrollContainer::_update_scrollbar_position() { - - Size2 hmin = h_scroll->get_combined_minimum_size(); - Size2 vmin = v_scroll->get_combined_minimum_size(); - - v_scroll->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, -vmin.width); - v_scroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0); - v_scroll->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 0); - v_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0); - - h_scroll->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 0); - h_scroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0); - h_scroll->set_anchor_and_margin(MARGIN_TOP, ANCHOR_END, -hmin.height); - h_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0); - - h_scroll->raise(); - v_scroll->raise(); -} - void ScrollContainer::_ensure_focused_visible(Control *p_control) { if (!follow_focus) { @@ -262,7 +243,8 @@ void ScrollContainer::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { - call_deferred("_update_scrollbar_position"); + h_scroll->call_deferred("raise"); + v_scroll->call_deferred("raise"); }; if (p_what == NOTIFICATION_READY) { @@ -317,6 +299,7 @@ void ScrollContainer::_notification(int p_what) { r.position += ofs; fit_child_in_rect(c, r); } + update(); }; @@ -408,21 +391,22 @@ void ScrollContainer::update_scrollbars() { Size2 hmin; Size2 vmin; - if (scroll_h) hmin = h_scroll->get_combined_minimum_size(); - if (scroll_v) vmin = v_scroll->get_combined_minimum_size(); + if (scroll_h) { + hmin = h_scroll->get_combined_minimum_size(); + } + if (scroll_v) { + vmin = v_scroll->get_combined_minimum_size(); + } Size2 min = child_max_size; - bool hide_scroll_v = !scroll_v || min.height <= size.height - hmin.height; - bool hide_scroll_h = !scroll_h || min.width <= size.width - vmin.width; + bool hide_scroll_v = !scroll_v || min.height <= size.height; + bool hide_scroll_h = !scroll_h || min.width <= size.width; if (hide_scroll_v) { v_scroll->hide(); scroll.y = 0; - - // modify the horizontal scrollbar's right anchor to fill the container's width - h_scroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0); } else { v_scroll->show(); @@ -434,18 +418,12 @@ void ScrollContainer::update_scrollbars() { } scroll.y = v_scroll->get_value(); - - // modify the horizontal scrollbar's right anchor to stop at the left of the vertical scrollbar - h_scroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -vmin.width); } if (hide_scroll_h) { h_scroll->hide(); scroll.x = 0; - - // modify the vertical scrollbar's bottom anchor to fill the container's height - v_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0); } else { h_scroll->show(); @@ -457,10 +435,11 @@ void ScrollContainer::update_scrollbars() { } scroll.x = h_scroll->get_value(); - - // modify the vertical scrollbar's bottom anchor to stop at the top of the horizontal scrollbar - v_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, -hmin.height); } + + // Avoid scrollbar overlapping. + h_scroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, hide_scroll_v ? 0 : -vmin.width); + v_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, hide_scroll_h ? 0 : -hmin.height); } void ScrollContainer::_scroll_moved(float) { @@ -571,7 +550,6 @@ void ScrollContainer::_bind_methods() { ClassDB::bind_method(D_METHOD("is_h_scroll_enabled"), &ScrollContainer::is_h_scroll_enabled); ClassDB::bind_method(D_METHOD("set_enable_v_scroll", "enable"), &ScrollContainer::set_enable_v_scroll); ClassDB::bind_method(D_METHOD("is_v_scroll_enabled"), &ScrollContainer::is_v_scroll_enabled); - ClassDB::bind_method(D_METHOD("_update_scrollbar_position"), &ScrollContainer::_update_scrollbar_position); ClassDB::bind_method(D_METHOD("_ensure_focused_visible"), &ScrollContainer::_ensure_focused_visible); ClassDB::bind_method(D_METHOD("set_h_scroll", "value"), &ScrollContainer::set_h_scroll); ClassDB::bind_method(D_METHOD("get_h_scroll"), &ScrollContainer::get_h_scroll); @@ -605,13 +583,14 @@ ScrollContainer::ScrollContainer() { h_scroll = memnew(HScrollBar); h_scroll->set_name("_h_scroll"); add_child(h_scroll); + h_scroll->connect("value_changed", this, "_scroll_moved"); + h_scroll->set_anchors_and_margins_preset(PRESET_BOTTOM_WIDE); v_scroll = memnew(VScrollBar); v_scroll->set_name("_v_scroll"); add_child(v_scroll); - - h_scroll->connect("value_changed", this, "_scroll_moved"); v_scroll->connect("value_changed", this, "_scroll_moved"); + v_scroll->set_anchors_and_margins_preset(PRESET_RIGHT_WIDE); drag_speed = Vector2(); drag_touching = false; diff --git a/scene/gui/scroll_container.h b/scene/gui/scroll_container.h index 6423b36fcc..608b29bd93 100644 --- a/scene/gui/scroll_container.h +++ b/scene/gui/scroll_container.h @@ -75,7 +75,6 @@ protected: void _scroll_moved(float); static void _bind_methods(); - void _update_scrollbar_position(); void _ensure_focused_visible(Control *p_node); public: |