mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-06 09:09:40 +02:00
start app with launcher, start SDL from launcher
kambala-decapitator/vcmi#33
This commit is contained in:
@@ -43,6 +43,7 @@ set(launcher_HEADERS
|
||||
launcherdirs.h
|
||||
jsonutils.h
|
||||
updatedialog_moc.h
|
||||
main.h
|
||||
)
|
||||
|
||||
set(launcher_FORMS
|
||||
@@ -54,7 +55,9 @@ set(launcher_FORMS
|
||||
)
|
||||
|
||||
if(APPLE_IOS)
|
||||
set(launcher_SRCS ${launcher_SRCS} ios/mainwindow_moc.mm)
|
||||
list(APPEND launcher_SRCS
|
||||
ios/mainwindow_moc.mm
|
||||
)
|
||||
endif()
|
||||
|
||||
assign_source_group(${launcher_SRCS} ${launcher_HEADERS} VCMI_launcher.rc)
|
||||
|
||||
@@ -10,16 +10,29 @@
|
||||
|
||||
#include "../mainwindow_moc.h"
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QWindow>
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
void MainWindow::startExecutable(QString /*name*/)
|
||||
{
|
||||
NSString * vcmiScheme = NSBundle.mainBundle.infoDictionary[@"LSApplicationQueriesSchemes"][0];
|
||||
[UIApplication.sharedApplication openURL:[NSURL URLWithString:[vcmiScheme stringByAppendingString:@":"]] options:@{} completionHandler:^(BOOL success) {
|
||||
if (success)
|
||||
return;
|
||||
auto alert = [UIAlertController alertControllerWithTitle:@"Can't open VCMI client" message:nil preferredStyle:UIAlertControllerStyleAlert];
|
||||
[alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];
|
||||
[UIApplication.sharedApplication.keyWindow.rootViewController presentViewController:alert animated:YES completion:nil];
|
||||
}];
|
||||
qApp->quit();
|
||||
[NSNotificationCenter.defaultCenter postNotificationName:@"StartGame" object:nil];
|
||||
}
|
||||
|
||||
void showQtWindow()
|
||||
{
|
||||
auto app = UIApplication.sharedApplication;
|
||||
auto qtNativeWindowIndex = [app.windows indexOfObjectPassingTest:^BOOL(__kindof UIWindow * _Nonnull window, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
return [NSStringFromClass([window class]) isEqualToString:@"QUIWindow"];
|
||||
}];
|
||||
Q_ASSERT(qtNativeWindowIndex != NSNotFound);
|
||||
|
||||
auto qtWindow = qApp->topLevelWindows()[0];
|
||||
auto qtWindowNativeView = (__bridge UIView*)reinterpret_cast<void*>(qtWindow->winId());
|
||||
|
||||
auto qtNativeWindow = app.windows[qtNativeWindowIndex];
|
||||
[qtNativeWindow.rootViewController.view addSubview:qtWindowNativeView];
|
||||
[qtNativeWindow makeKeyAndVisible];
|
||||
}
|
||||
|
||||
@@ -10,11 +10,15 @@
|
||||
#include <QApplication>
|
||||
#include "StdInc.h"
|
||||
#include "mainwindow_moc.h"
|
||||
#include "main.h"
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
QApplication vcmilauncher(argc, argv);
|
||||
MainWindow mainWindow;
|
||||
mainWindow.show();
|
||||
#ifdef Q_OS_IOS
|
||||
showQtWindow();
|
||||
#endif
|
||||
return vcmilauncher.exec();
|
||||
}
|
||||
|
||||
19
launcher/main.h
Normal file
19
launcher/main.h
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* main.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
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#ifdef Q_OS_IOS
|
||||
void showQtWindow();
|
||||
|
||||
#define main qt_main
|
||||
#endif
|
||||
int main(int argc, char * argv[]);
|
||||
Reference in New Issue
Block a user