Skip to content

Commit

Permalink
EditorProperty: Fix range hint parsing with optional step
Browse files Browse the repository at this point in the history
This could lead to have a step of 0 when parsing e.g. "1,10,is_greater".
  • Loading branch information
akien-mga committed Feb 3, 2022
1 parent f44b7c3 commit 80306cc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
39 changes: 23 additions & 16 deletions editor/editor_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2642,18 +2642,20 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
int min = 0, max = 65535, step = 1;
bool greater = true, lesser = true;

if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
greater = false; //if using ranged, assume false by default
Vector<String> slices = p_hint_text.split(",");
if (p_hint == PROPERTY_HINT_RANGE && slices.size() >= 2) {
greater = false; // If using ranged, assume false by default.
lesser = false;
min = p_hint_text.get_slice(",", 0).to_int();
max = p_hint_text.get_slice(",", 1).to_int();
min = slices[0].to_int();
max = slices[1].to_int();

if (p_hint_text.get_slice_count(",") >= 3) {
step = p_hint_text.get_slice(",", 2).to_int();
if (slices.size() >= 3 && slices[2].is_valid_integer()) {
// Step is optional, could be something else if not a number.
step = slices[2].to_int();
}

for (int i = 2; i < p_hint_text.get_slice_count(","); i++) {
String slice = p_hint_text.get_slice(",", i).strip_edges();
for (int i = 2; i < slices.size(); i++) {
String slice = slices[i].strip_edges();
if (slice == "or_greater") {
greater = true;
}
Expand Down Expand Up @@ -2694,18 +2696,23 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
bool exp_range = false;
bool greater = true, lesser = true;

if ((p_hint == PROPERTY_HINT_RANGE || p_hint == PROPERTY_HINT_EXP_RANGE) && p_hint_text.get_slice_count(",") >= 2) {
greater = false; //if using ranged, assume false by default
Vector<String> slices = p_hint_text.split(",");
if ((p_hint == PROPERTY_HINT_RANGE || p_hint == PROPERTY_HINT_EXP_RANGE) && slices.size() >= 2) {
greater = false; // If using ranged, assume false by default.
lesser = false;
min = p_hint_text.get_slice(",", 0).to_double();
max = p_hint_text.get_slice(",", 1).to_double();
if (p_hint_text.get_slice_count(",") >= 3) {
step = p_hint_text.get_slice(",", 2).to_double();
min = slices[0].to_double();
max = slices[1].to_double();

if (slices.size() >= 3 && slices[2].is_valid_float()) {
// Step is optional, could be something else if not a number.
step = slices[2].to_double();
}

hide_slider = false;
exp_range = p_hint == PROPERTY_HINT_EXP_RANGE;
for (int i = 2; i < p_hint_text.get_slice_count(","); i++) {
String slice = p_hint_text.get_slice(",", i).strip_edges();

for (int i = 2; i < slices.size(); i++) {
String slice = slices[i].strip_edges();
if (slice == "or_greater") {
greater = true;
}
Expand Down
8 changes: 4 additions & 4 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1068,17 +1068,17 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
GLOBAL_DEF("rendering/2d/options/use_nvidia_rect_flicker_workaround", false);

GLOBAL_DEF("display/window/size/width", 1024);
ProjectSettings::get_singleton()->set_custom_property_info("display/window/size/width", PropertyInfo(Variant::INT, "display/window/size/width", PROPERTY_HINT_RANGE, "0,7680,or_greater")); // 8K resolution
ProjectSettings::get_singleton()->set_custom_property_info("display/window/size/width", PropertyInfo(Variant::INT, "display/window/size/width", PROPERTY_HINT_RANGE, "0,7680,1,or_greater")); // 8K resolution
GLOBAL_DEF("display/window/size/height", 600);
ProjectSettings::get_singleton()->set_custom_property_info("display/window/size/height", PropertyInfo(Variant::INT, "display/window/size/height", PROPERTY_HINT_RANGE, "0,4320,or_greater")); // 8K resolution
ProjectSettings::get_singleton()->set_custom_property_info("display/window/size/height", PropertyInfo(Variant::INT, "display/window/size/height", PROPERTY_HINT_RANGE, "0,4320,1,or_greater")); // 8K resolution
GLOBAL_DEF("display/window/size/resizable", true);
GLOBAL_DEF("display/window/size/borderless", false);
GLOBAL_DEF("display/window/size/fullscreen", false);
GLOBAL_DEF("display/window/size/always_on_top", false);
GLOBAL_DEF("display/window/size/test_width", 0);
ProjectSettings::get_singleton()->set_custom_property_info("display/window/size/test_width", PropertyInfo(Variant::INT, "display/window/size/test_width", PROPERTY_HINT_RANGE, "0,7680,or_greater")); // 8K resolution
ProjectSettings::get_singleton()->set_custom_property_info("display/window/size/test_width", PropertyInfo(Variant::INT, "display/window/size/test_width", PROPERTY_HINT_RANGE, "0,7680,1,or_greater")); // 8K resolution
GLOBAL_DEF("display/window/size/test_height", 0);
ProjectSettings::get_singleton()->set_custom_property_info("display/window/size/test_height", PropertyInfo(Variant::INT, "display/window/size/test_height", PROPERTY_HINT_RANGE, "0,4320,or_greater")); // 8K resolution
ProjectSettings::get_singleton()->set_custom_property_info("display/window/size/test_height", PropertyInfo(Variant::INT, "display/window/size/test_height", PROPERTY_HINT_RANGE, "0,4320,1,or_greater")); // 8K resolution

if (use_custom_res) {
if (!force_res) {
Expand Down
5 changes: 2 additions & 3 deletions scene/main/scene_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2057,15 +2057,14 @@ SceneTree::SceneTree() {
multiplayer_poll = true;
set_multiplayer(Ref<MultiplayerAPI>(memnew(MultiplayerAPI)));

//root->set_world_2d( Ref<World2D>( memnew( World2D )));
root->set_as_audio_listener(true);
root->set_as_audio_listener_2d(true);
current_scene = nullptr;

int ref_atlas_size = GLOBAL_DEF_RST("rendering/quality/reflections/atlas_size", 2048);
ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/reflections/atlas_size", PropertyInfo(Variant::INT, "rendering/quality/reflections/atlas_size", PROPERTY_HINT_RANGE, "0,8192,or_greater")); //next_power_of_2 will return a 0 as min value
ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/reflections/atlas_size", PropertyInfo(Variant::INT, "rendering/quality/reflections/atlas_size", PROPERTY_HINT_RANGE, "0,8192,1,or_greater")); // next_power_of_2 will return a 0 as min value.
int ref_atlas_subdiv = GLOBAL_DEF_RST("rendering/quality/reflections/atlas_subdiv", 8);
ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/reflections/atlas_subdiv", PropertyInfo(Variant::INT, "rendering/quality/reflections/atlas_subdiv", PROPERTY_HINT_RANGE, "0,32,or_greater")); //next_power_of_2 will return a 0 as min value
ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/reflections/atlas_subdiv", PropertyInfo(Variant::INT, "rendering/quality/reflections/atlas_subdiv", PROPERTY_HINT_RANGE, "0,32,1,or_greater")); // next_power_of_2 will return a 0 as min value.
int msaa_mode = GLOBAL_DEF("rendering/quality/filters/msaa", 0);
ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/filters/msaa", PropertyInfo(Variant::INT, "rendering/quality/filters/msaa", PROPERTY_HINT_ENUM, "Disabled,2x,4x,8x,16x,AndroidVR 2x,AndroidVR 4x"));
root->set_msaa(Viewport::MSAA(msaa_mode));
Expand Down

0 comments on commit 80306cc

Please sign in to comment.