diff --git a/addons/sketchfab/Api.gd b/addons/sketchfab/Api.gd index 522574f..532989d 100644 --- a/addons/sketchfab/Api.gd +++ b/addons/sketchfab/Api.gd @@ -93,11 +93,9 @@ func request_download(uid): return _handle_result(result) -func search_models(q, categories, animated, staff_picked, min_face_count, max_face_count, sort_by): - var query = { - "type": "models", - "downloadable": "true", - } +func search_models(q, categories, animated, staff_picked, min_face_count, max_face_count, sort_by, domain_suffix): + + var query = {} if q: query.q = q @@ -115,7 +113,9 @@ func search_models(q, categories, animated, staff_picked, min_face_count, max_fa query.sort_by = sort_by busy = true - requestor.request("%s/search" % BASE_PATH, query) + + var search_domain = BASE_PATH + domain_suffix + requestor.request(search_domain, query, { "token": get_token() }) var result = yield(requestor, "completed") busy = false diff --git a/addons/sketchfab/Main.gd b/addons/sketchfab/Main.gd index 36d4326..0666a8b 100644 --- a/addons/sketchfab/Main.gd +++ b/addons/sketchfab/Main.gd @@ -19,7 +19,15 @@ const SORT_BY_OPTIONS = [ ["Likes", "-likeCount"], ["Views", "-viewCount"], ] + +const SEARCH_DOMAIN = [ + ["Whole site", "/search?type=models&downloadable=true"], + ["Own models (PRO)", "/me/search?type=models&downloadable=true"], + ["Purchased models", "/me/models/purchases?"], +] + const SORT_BY_DEFAULT_INDEX = 1 +const DEFAULT_DOMAIN = 0 const SafeData = preload("res://addons/sketchfab/SafeData.gd") const Utils = preload("res://addons/sketchfab/Utils.gd") @@ -32,6 +40,9 @@ onready var search_animated = find_node("Search").find_node("Animated") onready var search_staff_picked = find_node("Search").find_node("StaffPicked") onready var search_face_count = find_node("Search").find_node("FaceCount") onready var search_sort_by = find_node("Search").find_node("SortBy") +onready var search_domain = find_node("Search").find_node("SearchDomain") +onready var cta_button = find_node("CTA") +onready var trailer = find_node("Trailer") onready var paginator = find_node("Paginator") @@ -87,6 +98,12 @@ func _notification(what): search_sort_by.add_item(item[0]) _commit_sort_by(SORT_BY_DEFAULT_INDEX) + for item in SEARCH_DOMAIN: + search_domain.add_item(item[0]) + _commit_domain(DEFAULT_DOMAIN) + search_domain.hide() + cta_button.hide() + logged.visible = false not_logged.visible = false login_name.text = cfg.get_value("api", "user", "") @@ -135,6 +152,10 @@ func _on_SortBy_item_selected(index): _commit_sort_by(index) _search() +func _on_SearchDomain_item_selected(index): + _commit_domain(index) + _search() + func _on_SearchButton_pressed(): _search() @@ -164,6 +185,9 @@ func _login(): cfg.save(CONFIG_FILE_PATH) func _populate_login(): + + search_domain.show() + _set_login_disabled(true) var user = yield(api.get_my_info(), "completed") _set_login_disabled(false) @@ -182,7 +206,9 @@ func _populate_login(): logged_name.text = "User: %s" % user["username"] var plan_name - if user["account"] == "pro": + if user["account"] == "plus": + plan_name = "PLUS" + elif user["account"] == "pro": plan_name = "PRO" elif user["account"] == "prem": plan_name = "PREMIUM" @@ -207,6 +233,10 @@ func _logout(): not_logged.visible = true logged.visible = false logged_avatar.url = null + search_domain.hide() + cta_button.hide() + trailer.modulate.a = 0.0 + search_domain.set_meta("__suffix", SEARCH_DOMAIN[0][1]) func _load_categories(): var result = yield(api.get_categories(), "completed") @@ -232,7 +262,8 @@ func _search(): search_staff_picked.pressed, search_face_count.get_meta("__data")[1], search_face_count.get_meta("__data")[2], - search_sort_by.get_meta("__key") + search_sort_by.get_meta("__key"), + search_domain.get_meta("__suffix") ) ##### Helpers @@ -288,6 +319,9 @@ func _commit_face_count(index): func _commit_sort_by(index): search_sort_by.set_meta("__key", SORT_BY_OPTIONS[index][1]) +func _commit_domain(index): + search_domain.set_meta("__suffix", SEARCH_DOMAIN[index][1]) + func _set_login_disabled(disabled): login_name.editable = !disabled login_password.editable = !disabled diff --git a/addons/sketchfab/Main.tscn b/addons/sketchfab/Main.tscn index e985138..d050f54 100644 --- a/addons/sketchfab/Main.tscn +++ b/addons/sketchfab/Main.tscn @@ -448,15 +448,43 @@ lines_skipped = 0 max_lines_visible = -1 _sections_unfolded = [ "Anchor", "Focus", "Margin", "Rect", "Size Flags" ] -[node name="Text" type="LineEdit" parent="Search/_/_" index="1"] +[node name="SearchDomain" type="OptionButton" parent="Search/_/_" index="1"] anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 anchor_bottom = 0.0 -margin_left = 56.0 -margin_right = 878.0 +margin_top = 5.0 +margin_right = 146.0 +margin_bottom = 19.0 +rect_pivot_offset = Vector2( 0, 0 ) +rect_clip_content = false +size_flags_horizontal = 1 +size_flags_vertical = 4 +toggle_mode = false +action_mode = 0 +enabled_focus_mode = 2 +shortcut = null +group = null +flat = false +align = 0 +items = [ ] +selected = -1 +_sections_unfolded = [ "Rect", "Size Flags" ] +rect_max_size = Vector2( 120, 0 ) + + +[node name="Text" type="LineEdit" parent="Search/_/_" index="2"] + +anchor_left = 0.0 +anchor_top = 0.0 +anchor_right = 0.0 +anchor_bottom = 0.0 + +margin_left = -56.0 +margin_right = -56 margin_bottom = 24.0 + rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false focus_mode = 2 @@ -472,7 +500,7 @@ caret_blink_speed = 0.65 caret_position = 0 _sections_unfolded = [ "Caret", "Placeholder", "Size Flags" ] -[node name="Button" type="Button" parent="Search/_/_" index="2"] +[node name="Button" type="Button" parent="Search/_/_" index="3"] anchor_left = 0.0 anchor_top = 0.0 @@ -868,46 +896,22 @@ custom_constants/hseparation = 16 columns = 6 _sections_unfolded = [ "Size Flags", "custom_constants" ] -[node name="Trailer" type="CenterContainer" parent="_2/Paginator/_" index="1"] +[node name="Trailer" type="VBoxContainer" parent="_2/Paginator/_" index="1"] modulate = Color( 1, 1, 1, 0 ) -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_top = 4.0 -margin_right = 1008.0 -margin_bottom = 104.0 -rect_min_size = Vector2( 0, 100 ) -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 size_flags_horizontal = 3 size_flags_vertical = 1 -use_top_left = false -_sections_unfolded = [ "Rect", "Size Flags" ] [node name="Label" type="Label" parent="_2/Paginator/_/Trailer" index="0"] -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_left = 471.0 -margin_top = 43.0 -margin_right = 537.0 -margin_bottom = 57.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 2 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 4 +size_flags_horizontal = 4 text = "Fetching..." -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 + +[node name="CTA" type="Button" parent="_2/Paginator/_/Trailer" index="1"] + +disabled=false +size_flags_horizontal = 4 +text = "Upgrade to PRO" [connection signal="pressed" from="Header/_/Logged/_/MainBlock/Logout" to="." method="_on_Logout_pressed"] @@ -931,6 +935,8 @@ max_lines_visible = -1 [connection signal="item_selected" from="Search/_/_3/_/_/SortBy" to="." method="_on_SortBy_item_selected"] +[connection signal="item_selected" from="Search/_/_/SearchDomain" to="." method="_on_SearchDomain_item_selected"] + [connection signal="item_selected" from="Search/_/_3/_/_2/FaceCount" to="." method="_on_FaceCount_item_selected"] diff --git a/addons/sketchfab/Paginator.gd b/addons/sketchfab/Paginator.gd index 194979a..905e475 100644 --- a/addons/sketchfab/Paginator.gd +++ b/addons/sketchfab/Paginator.gd @@ -8,6 +8,9 @@ var api = preload("res://addons/sketchfab/Api.gd").new() onready var grid = find_node("ResultsGrid") onready var trailer = find_node("Trailer") +onready var label = find_node("Label") +onready var cta_button = find_node("CTA") +onready var search_domain = find_node("SearchDomain") var next_page_url @@ -17,12 +20,14 @@ func _ready(): func _exit_tree(): api.term() -func search(query, categories, animated, staff_picked, min_face_count, max_face_count, sort_by): +func search(query, categories, animated, staff_picked, min_face_count, max_face_count, sort_by, domain_suffix): for item in grid.get_children(): grid.remove_child(item) queue_sort() trailer.modulate.a = 1.0 + label.text = "Fetching..." + cta_button.hide() yield(api.cancel(), "completed") var result = yield(api.search_models( query, @@ -31,16 +36,40 @@ func search(query, categories, animated, staff_picked, min_face_count, max_face_ staff_picked, min_face_count, max_face_count, - sort_by + sort_by, + domain_suffix ), "completed") trailer.modulate.a = 0.0 - _process_page(result) + var n_results = _process_page(result) + + # Upgrade to pro and empty results + if domain_suffix == "/me": + var user = yield(api.get_my_info(), "completed") + if user["account"] == "plus" || user["account"] == "basic": + trailer.modulate.a = 1.0 + label.text = "Access your personal library of 3D models" + cta_button.show() + cta_button.text = "Upgrade to PRO" + elif n_results == 0: + trailer.modulate.a = 1.0 + label.text = "No results found" + elif n_results == 0: + trailer.modulate.a = 1.0 + label.text = "No results found" + if domain_suffix == "/me/models/purchases": + cta_button.show() + cta_button.text = "Visit the Store" + else: + trailer.modulate.a = 0.0 + cta_button.hide() func _process(delta): if !api.busy && next_page_url && trailer.get_global_rect().intersects(get_viewport_rect()): # Fetch next page trailer.modulate.a = 1.0 + label.text = "Fetching..." + cta_button.hide() var result = yield(api.fetch_next_page(next_page_url), "completed") trailer.modulate.a = 0.0 @@ -66,3 +95,5 @@ func _process_page(result): # Set next page now we know the current one succeeded next_page_url = SafeData.string(result, "next") + + return results.size() diff --git a/addons/sketchfab/Requestor.gd b/addons/sketchfab/Requestor.gd index c06396e..4629c4a 100644 --- a/addons/sketchfab/Requestor.gd +++ b/addons/sketchfab/Requestor.gd @@ -118,7 +118,7 @@ func request(path, payload = null, options = DEFAULT_OPTIONS): if payload: var encoding = _get_option(options, "encoding") if encoding == "query": - uri += "?" + _dict_to_query_string(payload) + uri += "&" + _dict_to_query_string(payload) elif encoding == "json": headers.append("Content-Type: application/json") encoded_payload = to_json(payload) diff --git a/addons/sketchfab/plugin.cfg b/addons/sketchfab/plugin.cfg index 93d2bb0..dde9d89 100644 --- a/addons/sketchfab/plugin.cfg +++ b/addons/sketchfab/plugin.cfg @@ -3,5 +3,5 @@ name="Sketchfab" description="Sketchfab browsing & importing right inside Godot" author="Sketchfab" -version="1.0.1" +version="1.1.0" script="plugin.gd"