33#include " RA_Defs.h"
44#include " RA_Resource.h"
55
6- #include " api\FetchBadgeIds .hh"
6+ #include " context\IRcClient .hh"
77
88#include " data\context\EmulatorContext.hh"
99
2020#include " util\EnumOps.hh"
2121#include " util\Log.hh"
2222
23+ #include < rcheevos/include/rc_api_editor.h>
24+
2325using ra::data::models::AssetModelBase;
2426using ra::data::models::AchievementModel;
2527using ra::ui::viewmodels::AssetEditorViewModel;
@@ -513,6 +515,36 @@ void AssetEditorDialog::BadgeNameBinding::UpdateSourceFromText(const std::wstrin
513515
514516void AssetEditorDialog::BadgeNameBinding::UpdateTextFromSource (const std::wstring& sText )
515517{
518+ if (m_nMinimum == 0 && !ra::util::String::StartsWith (sText , L" local\\ " ))
519+ {
520+ const auto & pRcClient = ra::services::ServiceLocator::Get<ra::context::IRcClient>();
521+
522+ rc_api_fetch_badge_range_request_t api_params;
523+ memset (&api_params, 0 , sizeof (api_params));
524+
525+ rc_api_request_t api_request;
526+ const int nResult = rc_api_init_fetch_badge_range_request_hosted (&api_request, &api_params, pRcClient.GetHost ());
527+ if (nResult == RC_OK )
528+ {
529+ pRcClient.DispatchRequest (api_request, [this ](const rc_api_server_response_t & server_response, void *)
530+ {
531+ rc_api_fetch_badge_range_response_t api_response;
532+ const auto nResult = rc_api_process_fetch_badge_range_server_response (&api_response, &server_response);
533+ if (nResult == RC_OK )
534+ {
535+ SetRange (ra::to_signed (api_response.first_badge_id ),
536+ ra::to_signed (api_response.next_badge_id ) - 1 );
537+
538+ InvokeOnUIThread ([hWnd = m_hWndSpinner]() noexcept { ::EnableWindow (hWnd, true ); });
539+ }
540+
541+ rc_api_destroy_fetch_badge_range_response (&api_response);
542+ }, nullptr );
543+
544+ rc_api_destroy_request (&api_request);
545+ }
546+ }
547+
516548 InvokeOnUIThread ([this , sTextCopy = sText ]()
517549 {
518550 if (ra::util::String::StartsWith (sTextCopy , L" local\\ " ))
@@ -523,21 +555,7 @@ void AssetEditorDialog::BadgeNameBinding::UpdateTextFromSource(const std::wstrin
523555 else
524556 {
525557 SetWindowTextW (m_hWnd, sTextCopy .c_str ());
526-
527- if (m_nMinimum == 0 )
528- {
529- ::EnableWindow (m_hWndSpinner, false );
530-
531- ra::api::FetchBadgeIds::Request request;
532- request.CallAsync ([this ](const ra::api::FetchBadgeIds::Response& response) {
533- SetRange (ra::to_signed (response.FirstID ), ra::to_signed (response.NextID ) - 1 );
534- InvokeOnUIThread ([hWnd = m_hWndSpinner]() noexcept { ::EnableWindow (hWnd, true ); });
535- });
536- }
537- else
538- {
539- ::EnableWindow (m_hWndSpinner, true );
540- }
558+ ::EnableWindow (m_hWndSpinner, (m_nMinimum != 0 ));
541559 }
542560 });
543561}
0 commit comments