diff --git a/.gitignore b/.gitignore index e98194ec..7134f6d3 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ /.cache/ /tags /.luarc.json +/.qmllint.ini # file produced by game /FreeKill diff --git a/CMakeLists.txt b/CMakeLists.txt index c8ffa7c9..75038278 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ # 2022-01-24 新建文件夹 2023-02-21 发布v0.0.1版本 # ------------------------------------------------------------ -cmake_minimum_required(VERSION 3.16) +cmake_minimum_required(VERSION 3.22) project(FreeKill VERSION 0.4.20) add_definitions(-DFK_VERSION=\"${CMAKE_PROJECT_VERSION}\") diff --git a/Fk/Config.qml b/Fk/Config.qml index 3542d309..4dacd173 100644 --- a/Fk/Config.qml +++ b/Fk/Config.qml @@ -63,6 +63,9 @@ QtObject { property list blockedUsers: [] property int totalTime: 0 // FIXME: only for notifying + onObservingChanged: lcall("SetObserving", observing); + //onReplayingChanged: lcall("SetReplaying", replaying); + // onDisabledGeneralsChanged: { // disableGeneralSchemes[disableSchemeIdx] = disabledGenerals; // } diff --git a/Fk/Pages/Lobby.qml b/Fk/Pages/Lobby.qml index 0c3ae593..3feca3ac 100644 --- a/Fk/Pages/Lobby.qml +++ b/Fk/Pages/Lobby.qml @@ -390,7 +390,6 @@ Item { config.replaying = false; if (playerNum < capacity) { config.observing = false; - lcall("SetObserving", false); mainWindow.busy = true; ClientInstance.notifyServer( "EnterRoom", @@ -398,7 +397,6 @@ Item { ); } else { config.observing = true; - lcall("SetObserving", true); mainWindow.busy = true; ClientInstance.notifyServer( "ObserveRoom", diff --git a/Fk/Pages/ModMaker.qml b/Fk/Pages/ModMaker.qml deleted file mode 100644 index b9d6360f..00000000 --- a/Fk/Pages/ModMaker.qml +++ /dev/null @@ -1,3 +0,0 @@ -import Fk.ModMaker as Md - -Md.ModMaker {} diff --git a/Fk/Pages/Room.qml b/Fk/Pages/Room.qml index c2294ebf..1bff8b4c 100644 --- a/Fk/Pages/Room.qml +++ b/Fk/Pages/Room.qml @@ -42,8 +42,6 @@ Item { property var selected_targets: [] property string responding_card - property bool respond_play: false - property bool autoPending: false property var extra_data: ({}) property var skippedUseEventId: [] @@ -353,6 +351,11 @@ Item { const total = dat["timeout"] * 1000; const now = Date.now(); // ms const elapsed = now - (dat["timestamp"] ?? now); + + if (total <= elapsd) { + roomScene.state = "notactive"; + } + progressAnim.from = (1 - elapsed / total) * 100.0; progressAnim.duration = total - elapsed; progress.visible = true; @@ -449,11 +452,12 @@ Item { text: luatr("Choose one handcard") textFont.pixelSize: 28 visible: { + if (roomScene.state === "notactive") return false; if (dashboard.handcardArea.length <= 15) { return false; } const cards = dashboard.handcardArea.cards; - for (const card in cards) { + for (const card of cards) { if (card.selectable) return true; } return false; @@ -1294,6 +1298,11 @@ Item { return Logic.getPhoto(id); } + function activate() { + if (state === "active") state = "notactive"; + state = "active"; + } + function applyChange(uiUpdate) { uiUpdate["_delete"]?.forEach(data => { if (data.type == "Interaction") { diff --git a/Fk/Pages/RoomLogic.js b/Fk/Pages/RoomLogic.js index ce0b422e..7e152306 100644 --- a/Fk/Pages/RoomLogic.js +++ b/Fk/Pages/RoomLogic.js @@ -809,7 +809,7 @@ callbacks["AskForGeneral"] = (data) => { const convert = data[2]; const heg = data[3]; roomScene.setPrompt(luatr("#AskForGeneral"), true); - roomScene.state = "active"; + roomScene.activate(); roomScene.popupBox.sourceComponent = Qt.createComponent("../RoomElement/ChooseGeneralBox.qml"); const box = roomScene.popupBox.item; @@ -830,15 +830,15 @@ callbacks["AskForSkillInvoke"] = (data) => { const prompt = data[1]; roomScene.promptText = prompt ? processPrompt(prompt) : luatr("#AskForSkillInvoke").arg(luatr(skill)); - // roomScene.state = "active"; + // roomScene.activate(); // roomScene.okCancel.visible = true; // roomScene.okButton.enabled = true; // roomScene.cancelButton.enabled = true; - roomScene.state = "active"; + roomScene.activate(); } callbacks["AskForArrangeCards"] = (data) => { - roomScene.state = "active"; + roomScene.activate(); roomScene.popupBox.sourceComponent = Qt.createComponent("../RoomElement/ArrangeCardsBox.qml"); const box = roomScene.popupBox.item; @@ -869,7 +869,7 @@ callbacks["AskForGuanxing"] = (data) => { const top_area_name = data.top_area_name; const bottom_area_name = data.bottom_area_name; const prompt = data.prompt; - roomScene.state = "active"; + roomScene.activate(); roomScene.popupBox.sourceComponent = Qt.createComponent("../RoomElement/GuanxingBox.qml"); const box = roomScene.popupBox.item; @@ -905,7 +905,7 @@ callbacks["AskForExchange"] = (data) => { const cards_name = []; const capacities = []; const limits = []; - roomScene.state = "active"; + roomScene.activate(); roomScene.popupBox.sourceComponent = Qt.createComponent("../RoomElement/GuanxingBox.qml"); let for_i = 0; @@ -944,7 +944,7 @@ callbacks["AskForChoice"] = (data) => { } else { roomScene.setPrompt(processPrompt(prompt), true); } - roomScene.state = "active"; + roomScene.activate(); let qmlSrc; if (!detailed) { qmlSrc = "../RoomElement/ChoiceBox.qml"; @@ -978,7 +978,7 @@ callbacks["AskForChoices"] = (data) => { } else { roomScene.setPrompt(processPrompt(prompt), true); } - roomScene.state = "active"; + roomScene.activate(); let qmlSrc; if (!detailed) { qmlSrc = "../RoomElement/CheckBox.qml"; @@ -1013,7 +1013,7 @@ callbacks["AskForCardChosen"] = (data) => { } else { roomScene.setPrompt(processPrompt(prompt), true); } - roomScene.state = "active"; + roomScene.activate(); roomScene.popupBox.sourceComponent = Qt.createComponent("../RoomElement/PlayerCardBox.qml"); @@ -1045,7 +1045,7 @@ callbacks["AskForCardsChosen"] = (data) => { roomScene.setPrompt(processPrompt(prompt), true); } - roomScene.state = "active"; + roomScene.activate(); roomScene.popupBox.sourceComponent = Qt.createComponent("../RoomElement/PlayerCardBox.qml"); const box = roomScene.popupBox.item; @@ -1070,7 +1070,7 @@ callbacks["AskForCardsChosen"] = (data) => { callbacks["AskForPoxi"] = (dat) => { const { type, data, extra_data, cancelable } = dat; - roomScene.state = "active"; + roomScene.activate(); roomScene.popupBox.sourceComponent = Qt.createComponent("../RoomElement/PoxiBox.qml"); const box = roomScene.popupBox.item; @@ -1096,7 +1096,7 @@ callbacks["AskForPoxi"] = (dat) => { callbacks["AskForMoveCardInBoard"] = (data) => { const { cards, cardsPosition, generalNames, playerIds } = data; - roomScene.state = "active"; + roomScene.activate(); roomScene.popupBox.sourceComponent = Qt.createComponent("../RoomElement/MoveCardInBoardBox.qml"); @@ -1133,7 +1133,8 @@ callbacks["MoveCards"] = (moves) => { // 切换状态 -> 向Lua询问UI情况 // 所以Lua一开始就要设置好各种亮灭的值 而这个自然是通过update callbacks["PlayCard"] = () => { - roomScene.state = "active"; + roomScene.activate(); + roomScene.okCancel.visible = true; } callbacks["LoseSkill"] = (data) => { @@ -1176,18 +1177,8 @@ callbacks["AskForUseActiveSkill"] = (data) => { roomScene.setPrompt(processPrompt(prompt), true); } - roomScene.respond_play = false; - roomScene.state = "active"; - - // if (lcall('GetSkillData', skill_name).isViewAsSkill) { - // roomScene.responding_card = "."; - // } - - // roomScene.autoPending = true; - // roomScene.extra_data = extra_data; - // // dashboard.startPending(skill_name); - // // roomScene.activateSkill(skill_name, true); - // cancelButton.enabled = cancelable; + roomScene.activate(); + roomScene.okCancel.visible = true; } callbacks["CancelRequest"] = () => { @@ -1212,7 +1203,8 @@ callbacks["AskForUseCard"] = (data) => { } else { roomScene.setPrompt(processPrompt(prompt), true); } - roomScene.state = "active"; + roomScene.activate(); + roomScene.okCancel.visible = true; if (extra_data != null) { if (extra_data.effectTo !== Self.id && roomScene.skippedUseEventId.find(id => id === extra_data.useEventId)) { @@ -1223,7 +1215,6 @@ callbacks["AskForUseCard"] = (data) => { } } // roomScene.responding_card = pattern; - // roomScene.respond_play = false; // disabledSkillNames && (dashboard.disabledSkillNames = disabledSkillNames); // roomScene.state = "responding"; // okButton.enabled = false; @@ -1243,13 +1234,8 @@ callbacks["AskForResponseCard"] = (data) => { } else { roomScene.setPrompt(processPrompt(prompt), true); } - roomScene.state = "active"; - // roomScene.responding_card = pattern; - // roomScene.respond_play = true; - // disabledSkillNames && (dashboard.disabledSkillNames = disabledSkillNames); - // roomScene.state = "responding"; - // okButton.enabled = false; - // cancelButton.enabled = true; + roomScene.activate(); + roomScene.okCancel.visible = true; } callbacks["WaitForNullification"] = () => { @@ -1436,7 +1422,7 @@ callbacks["FillAG"] = (data) => { } callbacks["AskForAG"] = (j) => { - roomScene.state = "active"; + roomScene.activate(); roomScene.manualBox.item.interactive = true; } @@ -1456,7 +1442,7 @@ callbacks["CloseAG"] = () => roomScene.manualBox.item.close(); callbacks["CustomDialog"] = (data) => { const path = data.path; const dat = data.data; - roomScene.state = "active"; + roomScene.activate(); roomScene.popupBox.source = AppPath + "/" + path; if (dat) { roomScene.popupBox.item.loadData(dat); @@ -1467,7 +1453,7 @@ callbacks["MiniGame"] = (data) => { const game = data.type; const dat = data.data; const gdata = lcall("GetMiniGame", game, Self.id, JSON.stringify(dat)); - roomScene.state = "active"; + roomScene.activate(); roomScene.popupBox.source = AppPath + "/" + gdata.qml_path + ".qml"; if (dat) { roomScene.popupBox.item.loadData(dat); @@ -1536,21 +1522,10 @@ callbacks["UpdateRequestUI"] = (uiUpdate) => { roomScene.promptText = processPrompt(uiUpdate["_prompt"]); if (uiUpdate._type == "Room") { - // 需要判断是不是第一次收到这样的数据,可以通过state判断 - // 因为是先收到Lua的数据,再切换状态的 - // FIXME: 当然了 非常可能出现因为网络延迟过大导致在active状态收到新Request的情况! - // if (roomScene.state === "notactive") { - // okCancel.visible = true; - // okButton.enabled = false; - // cancelButton.enabled = false; - // // endPhaseButton.visible = true; - // } roomScene.applyChange(uiUpdate); } } -// FIXME: 完全是因为ChangeSelf需要向服务器询问此人手牌信息导致不能直接暴力reply+设置notactive -// FIXME: 后面需要杀掉所有客户端未知牌 callbacks["ReplyToServer"] = (data) => { replyToServer(data); } diff --git a/Fk/Pages/qmldir b/Fk/Pages/qmldir index 077cbf73..c5f9aad6 100644 --- a/Fk/Pages/qmldir +++ b/Fk/Pages/qmldir @@ -12,4 +12,3 @@ PackageManage 1.0 PackageManage.qml Room 1.0 Room.qml Replay 1.0 Replay.qml TileButton 1.0 TileButton.qml -ModMaker 1.0 ModMaker.qml diff --git a/Fk/RoomElement/ChooseHandcard.qml b/Fk/RoomElement/ChooseHandcard.qml index 5a4e9a36..6a95e489 100644 --- a/Fk/RoomElement/ChooseHandcard.qml +++ b/Fk/RoomElement/ChooseHandcard.qml @@ -40,7 +40,7 @@ ColumnLayout { for (let cd of clist) { if (cd.cid == cid) { cd.selected = !cd.selected; - cd.clicked(); + cd.clicked(cd); finish(); } } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 93b6158a..ff6c407c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,6 +16,10 @@ add_custom_command( ${SWIG_SOURCE} ) +set(freekill_EXESRCS + "main.cpp" +) + set(freekill_SRCS # "main.cpp" "freekill.cpp" @@ -69,7 +73,7 @@ if (WIN32) set(CRYPTO_LIB OpenSSL::Crypto) set(GIT_LIB ${PROJECT_SOURCE_DIR}/lib/win/libgit2.dll) set(app_icon_resource_windows "${PROJECT_SOURCE_DIR}/image/icon.rc") - list(APPEND freekill_SRCS ${app_icon_resource_windows}) + list(APPEND freekill_EXESRCS ${app_icon_resource_windows}) elseif (ANDROID) set(LUA_LIB ${PROJECT_SOURCE_DIR}/lib/android/liblua54.so) set(SQLITE3_LIB ${PROJECT_SOURCE_DIR}/lib/android/libsqlite3.so) @@ -127,7 +131,7 @@ target_link_libraries(libFreeKill PRIVATE ${GIT_LIB} ${IDBFS_LIB} ) -target_sources(FreeKill PRIVATE main.cpp) +target_sources(FreeKill PRIVATE ${freekill_EXESRCS}) target_link_libraries(FreeKill PRIVATE libFreeKill ) diff --git a/src/network/router.cpp b/src/network/router.cpp index f599c11b..f65bdf37 100644 --- a/src/network/router.cpp +++ b/src/network/router.cpp @@ -186,7 +186,7 @@ void Router::handlePacket(const QByteArray &rawPacket) { if (!_room->isLobby()) { auto room = qobject_cast(_room); if (room->getThread()) { - room->getThread()->wakeUp(room->getId()); + room->getThread()->wakeUp(room->getId(), "reply"); // TODO: signal } } diff --git a/src/server/room.cpp b/src/server/room.cpp index 1724d34d..7b8402c9 100644 --- a/src/server/room.cpp +++ b/src/server/room.cpp @@ -608,7 +608,7 @@ void Room::setRequestTimer(int ms) { request_timer->setSingleShot(true); request_timer->setInterval(ms); connect(request_timer, &QTimer::timeout, this, [=](){ - m_thread->wakeUp(id); + m_thread->wakeUp(id, "request_timer"); }); request_timer->start(); } diff --git a/src/server/roomthread.h b/src/server/roomthread.h index aa80e88a..87c5093b 100644 --- a/src/server/roomthread.h +++ b/src/server/roomthread.h @@ -37,7 +37,7 @@ class RoomThread : public QThread { signals: void pushRequest(const QString &req); void delay(int roomId, int ms); - void wakeUp(int roomId); + void wakeUp(int roomId, const char *); protected: virtual void run(); diff --git a/src/server/scheduler.cpp b/src/server/scheduler.cpp index f0a9d211..5dd9b0d2 100644 --- a/src/server/scheduler.cpp +++ b/src/server/scheduler.cpp @@ -36,16 +36,17 @@ void Scheduler::handleRequest(const QString &req) { } void Scheduler::doDelay(int roomId, int ms) { - QTimer::singleShot(ms, [=](){ resumeRoom(roomId); }); + QTimer::singleShot(ms, [=](){ resumeRoom(roomId, "delay_done"); }); } -bool Scheduler::resumeRoom(int roomId) { +bool Scheduler::resumeRoom(int roomId, const char *reason) { lua_getglobal(L, "ResumeRoom"); lua_pushnumber(L, roomId); + lua_pushstring(L, reason); - int err = lua_pcall(L, 1, 1, 0); - const char *result = lua_tostring(L, -1); + int err = lua_pcall(L, 2, 1, 0); if (err) { + const char *result = lua_tostring(L, -1); qCritical() << result; lua_pop(L, 1); return true; diff --git a/src/server/scheduler.h b/src/server/scheduler.h index c304e76f..8a3f96c6 100644 --- a/src/server/scheduler.h +++ b/src/server/scheduler.h @@ -18,7 +18,7 @@ class Scheduler : public QObject { // 跨线程传递引用可能出问题! void handleRequest(const QString &req); void doDelay(int roomId, int ms); - bool resumeRoom(int roomId); + bool resumeRoom(int roomId, const char *reason); private: RoomThread *m_thread; diff --git a/src/server/server.cpp b/src/server/server.cpp index 7f8c99a8..2a4f5785 100644 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -366,7 +366,7 @@ void Server::onRoomAbandoned() { // FIXME: 但是这终归是内存泄漏!以后啥时候再改吧。 // room->deleteLater(); idle_rooms.push(room); - room->getThread()->wakeUp(room->getId()); + room->getThread()->wakeUp(room->getId(), "abandon"); room->getThread()->removeRoom(room); } diff --git a/src/server/serverplayer.cpp b/src/server/serverplayer.cpp index be5175ff..0950d48e 100644 --- a/src/server/serverplayer.cpp +++ b/src/server/serverplayer.cpp @@ -201,7 +201,7 @@ void ServerPlayer::onDisconnected() { } if (room->getThread()) { // && thinking()) { - room->getThread()->wakeUp(room->getId()); + room->getThread()->wakeUp(room->getId(), "player_disconnect"); } setState(Player::Offline); setSocket(nullptr); diff --git a/src/ui/qmlbackend.cpp b/src/ui/qmlbackend.cpp index 0657b07b..251d1be7 100644 --- a/src/ui/qmlbackend.cpp +++ b/src/ui/qmlbackend.cpp @@ -12,7 +12,6 @@ #include #include #include -// #include "mod.h" #endif #include @@ -481,10 +480,6 @@ void QmlBackend::installAESKey() { ClientInstance->installAESKey(aes_key.toLatin1()); } -void QmlBackend::createModBackend() { - //engine->rootContext()->setContextProperty("ModBackend", new ModMaker); -} - void QmlBackend::detectServer() { static const char *ask_str = "fkDetectServer"; diff --git a/src/ui/qmlbackend.h b/src/ui/qmlbackend.h index c23cabf2..0c789030 100644 --- a/src/ui/qmlbackend.h +++ b/src/ui/qmlbackend.h @@ -60,8 +60,6 @@ public: Q_INVOKABLE QString getAESKey() const; Q_INVOKABLE void installAESKey(); - Q_INVOKABLE void createModBackend(); - Q_INVOKABLE void detectServer(); Q_INVOKABLE void getServerInfo(const QString &addr, ushort port = 9527u);