From 3ab21d84916f0746cd3a19c440267decc9e49d76 Mon Sep 17 00:00:00 2001 From: Andrey Filipenkov Date: Tue, 16 Aug 2022 12:54:44 +0300 Subject: [PATCH] show loading indicator when starting local server single player or hosting a multiplayer game --- client/CMT.cpp | 2 -- client/CMakeLists.txt | 2 ++ client/CPlayerInterface.cpp | 1 - client/CServerHandler.cpp | 16 ++++++++---- client/gui/SDL_Extensions.cpp | 2 +- client/ios/utils.h | 18 ++++++++++++++ client/ios/utils.mm | 46 +++++++++++++++++++++++++++++++++++ ios/CMakeLists.txt | 1 - ios/iOS_utils.h | 2 -- ios/iOS_utils.mm | 3 --- 10 files changed, 78 insertions(+), 15 deletions(-) create mode 100644 client/ios/utils.h create mode 100644 client/ios/utils.mm diff --git a/client/CMT.cpp b/client/CMT.cpp index 3b7a4f696..9a9139085 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -441,7 +441,6 @@ int main(int argc, char * argv[]) #ifndef VCMI_NO_THREADED_LOAD - // todo ios #ifdef VCMI_ANDROID // android loads the data quite slowly so we display native progressbar to prevent having only black screen for few seconds { CAndroidVMHelper vmHelper; @@ -1322,7 +1321,6 @@ static void handleEvent(SDL_Event & ev) { if((ev.type==SDL_QUIT) ||(ev.type == SDL_KEYDOWN && ev.key.keysym.sym==SDLK_F4 && (ev.key.keysym.mod & KMOD_ALT))) { - // todo ios #ifdef VCMI_ANDROID handleQuit(false); #else diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index d88841c3e..1f487d175 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -151,11 +151,13 @@ if(APPLE_IOS) ios/GameChatKeyboardHanlder.m ios/main.m ios/startSDL.mm + ios/utils.mm ) set(client_HEADERS ${client_HEADERS} CFocusableHelper.h ios/GameChatKeyboardHanlder.h ios/startSDL.h + ios/utils.h ) endif() diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 481893bb1..62463f048 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -364,7 +364,6 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose) for(int i = 1; i < 32; i += 2 * speed) { movementPxStep(details, i, hp, hero); - // todo ios #ifndef VCMI_ANDROID // currently android doesn't seem to be able to handle all these full redraws here, so let's disable it so at least it looks less choppy; // most likely this is connected with the way that this manual animation+framerate handling is solved diff --git a/client/CServerHandler.cpp b/client/CServerHandler.cpp index acdfe95a6..fe509ada3 100644 --- a/client/CServerHandler.cpp +++ b/client/CServerHandler.cpp @@ -24,8 +24,10 @@ #ifdef VCMI_ANDROID #include "../lib/CAndroidVMHelper.h" #elif defined(VCMI_IOS) +#include "ios/utils.h" #include "../server/CVCMIServer.h" -// todo ios + +#include #else #include "../lib/Interprocess.h" #endif @@ -185,8 +187,6 @@ void CServerHandler::startLocalServerAndConnect() envHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "startServer", true); } #elif defined(VCMI_IOS) - // todo ios: hide keyboard - logNetwork->info("[ios] create server thread"); boost::condition_variable cond; threadRunLocalServer = std::make_shared([&cond, this] { setThreadName("CVCMIServer"); @@ -196,7 +196,6 @@ void CServerHandler::startLocalServerAndConnect() CSH->campaignServerRestartLock.setn(false); }); threadRunLocalServer->detach(); - logNetwork->info("[ios] detach server thread"); #else threadRunLocalServer = std::make_shared(&CServerHandler::threadRunServer, this); //runs server executable; #endif @@ -214,13 +213,20 @@ void CServerHandler::startLocalServerAndConnect() logNetwork->info("waiting for server finished..."); androidTestServerReadyFlag = false; #elif defined(VCMI_IOS) - // todo ios { + dispatch_sync(dispatch_get_main_queue(), ^{ + iOS_utils::showLoadingIndicator(); + }); + boost::mutex m; boost::unique_lock lock{m}; logNetwork->info("waiting for server"); cond.wait(lock); logNetwork->info("server is ready"); + + dispatch_sync(dispatch_get_main_queue(), ^{ + iOS_utils::hideLoadingIndicator(); + }); } #else if(shm) diff --git a/client/gui/SDL_Extensions.cpp b/client/gui/SDL_Extensions.cpp index e0bf6cad7..410ddb4b8 100644 --- a/client/gui/SDL_Extensions.cpp +++ b/client/gui/SDL_Extensions.cpp @@ -21,7 +21,7 @@ #endif #ifdef VCMI_IOS -#include "iOS_utils.h" +#include "ios/utils.h" #endif const SDL_Color Colors::YELLOW = { 229, 215, 123, 0 }; diff --git a/client/ios/utils.h b/client/ios/utils.h new file mode 100644 index 000000000..f3a643d83 --- /dev/null +++ b/client/ios/utils.h @@ -0,0 +1,18 @@ +/* + * utils.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#pragma once + +namespace iOS_utils +{ +double screenScale(); + +void showLoadingIndicator(); +void hideLoadingIndicator(); +} diff --git a/client/ios/utils.mm b/client/ios/utils.mm new file mode 100644 index 000000000..41cb65f4f --- /dev/null +++ b/client/ios/utils.mm @@ -0,0 +1,46 @@ +/* + * utils.mm, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ + +#include "utils.h" + +#import + +namespace +{ +UIActivityIndicatorView *indicator; +} + +namespace iOS_utils +{ +double screenScale() +{ + return UIScreen.mainScreen.nativeScale; +} + +void showLoadingIndicator() +{ + NSCAssert(!indicator, @"activity indicator must be hidden before attempting to show it again"); + indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; + [indicator startAnimating]; + + auto mainView = UIApplication.sharedApplication.keyWindow.rootViewController.view; + mainView.userInteractionEnabled = NO; + [mainView addSubview:indicator]; + indicator.center = {CGRectGetMidX(mainView.bounds), CGRectGetMidY(mainView.bounds)}; +} + +void hideLoadingIndicator() +{ + indicator.superview.userInteractionEnabled = YES; + [indicator stopAnimating]; + [indicator removeFromSuperview]; + indicator = nil; +} +} diff --git a/ios/CMakeLists.txt b/ios/CMakeLists.txt index c3d6537c9..0f8359c1c 100644 --- a/ios/CMakeLists.txt +++ b/ios/CMakeLists.txt @@ -4,7 +4,6 @@ add_library(iOS_utils SHARED ) target_link_libraries(iOS_utils PRIVATE "-framework Foundation" - "-framework UIKit" ) target_include_directories(iOS_utils PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/ios/iOS_utils.h b/ios/iOS_utils.h index c56f82f7d..666644789 100644 --- a/ios/iOS_utils.h +++ b/ios/iOS_utils.h @@ -25,7 +25,5 @@ const char *bundlePath(); const char *frameworksPath(); const char *bundleIdentifier(); - -double screenScale(); } #pragma GCC visibility pop diff --git a/ios/iOS_utils.mm b/ios/iOS_utils.mm index 50fe76f3e..40772519c 100644 --- a/ios/iOS_utils.mm +++ b/ios/iOS_utils.mm @@ -11,7 +11,6 @@ #include "iOS_utils.h" #import -#import namespace { @@ -47,6 +46,4 @@ const char *bundlePath() { return NSBundle.mainBundle.bundlePath.fileSystemRepre const char *frameworksPath() { return NSBundle.mainBundle.privateFrameworksPath.fileSystemRepresentation; } const char *bundleIdentifier() { return NSBundle.mainBundle.bundleIdentifier.UTF8String; } - -double screenScale() { return UIScreen.mainScreen.nativeScale; } }