From 94c1107c2eb92e6d7eebf1cebf3fa522e2379194 Mon Sep 17 00:00:00 2001 From: notify Date: Sat, 9 Dec 2023 23:25:26 +0800 Subject: [PATCH] Ui2 (#293) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 小修小改,没啥新功能 --- Fk/Pages/Lobby.qml | 3 + Fk/Pages/Room.qml | 253 +++++++------------- android/src/org/notify/FreeKill/Helper.java | 8 +- lua/server/ai/random_ai.lua | 11 +- src/ui/qmlbackend.cpp | 3 +- 5 files changed, 110 insertions(+), 168 deletions(-) diff --git a/Fk/Pages/Lobby.qml b/Fk/Pages/Lobby.qml index 3140d411..9e73489c 100644 --- a/Fk/Pages/Lobby.qml +++ b/Fk/Pages/Lobby.qml @@ -84,7 +84,10 @@ Item { text: (playerNum < capacity) ? Backend.translate("Enter") : Backend.translate("Observe") + enabled: !opTimer.running + onClicked: { + opTimer.start(); if (hasPassword) { lobby_dialog.sourceComponent = enterPassword; lobby_dialog.item.roomId = roomId; diff --git a/Fk/Pages/Room.qml b/Fk/Pages/Room.qml index 9f4f1157..b2d9798c 100644 --- a/Fk/Pages/Room.qml +++ b/Fk/Pages/Room.qml @@ -81,15 +81,13 @@ Item { } } - ToolButton { + Button { id: menuButton anchors.top: parent.top anchors.topMargin: 12 anchors.right: parent.right - anchors.rightMargin: 36 - icon.source: AppPath + "/image/modmaker/menu" - icon.width: 36 - icon.height: 36 + anchors.rightMargin: 12 + text: Backend.translate("Menu") onClicked: { if (menuContainer.visible){ menuContainer.close(); @@ -98,122 +96,48 @@ Item { } } - background.implicitWidth: 60 - background.implicitHeight: 60 - Menu { id: menuContainer y: menuButton.height - 12 - width: 115 - height: menuRow.height - verticalPadding: 0 - spacing: 15 - z: 2 - background: Rectangle { - implicitWidth: 200 - implicitHeight: 40 - color: "transparent" - border.color: "transparent" + width: 100 + + MenuItem { + id: quitButton + text: Backend.translate("Quit") + onClicked: { + if (config.replaying) { + Backend.controlReplayer("shutdown"); + mainStack.pop(); + } else if (config.observing) { + ClientInstance.notifyServer("QuitRoom", "[]"); + } else { + quitDialog.open(); + } + } } - Column { - id: menuRow - width: menuContainer.width - Layout.fillWidth: true - spacing: 7 - - Button { - id: quitButton - text: Backend.translate("Quit") - font.pixelSize: 28 - Layout.fillWidth: true - width: menuContainer.width - height: menuContainer.width * 0.65 - onClicked: { - if (config.replaying) { - Backend.controlReplayer("shutdown"); - mainStack.pop(); - } else if (config.observing) { - ClientInstance.notifyServer("QuitRoom", "[]"); + MenuItem { + id: surrenderButton + enabled: !config.observing && !config.replaying + text: Backend.translate("Surrender") + onClicked: { + if (isStarted && !getPhoto(Self.id).dead) { + const surrenderCheck = JSON.parse(Backend.callLuaFunction('CheckSurrenderAvailable', [miscStatus.playedTime])); + if (!surrenderCheck.length) { + surrenderDialog.informativeText = Backend.translate('Surrender is disabled in this mode'); } else { - quitDialog.open(); + surrenderDialog.informativeText = surrenderCheck.map(str => `${Backend.translate(str.text)}(${str.passed ? '√' : '×'})`).join('
'); } + surrenderDialog.open(); } } + } - MessageDialog { - id: quitDialog - title: Backend.translate("Quit") - informativeText: Backend.translate("Are you sure to quit?") - buttons: MessageDialog.Ok | MessageDialog.Cancel - onButtonClicked: function (button) { - switch (button) { - case MessageDialog.Ok: { - ClientInstance.notifyServer("QuitRoom", "[]"); - break; - } - case MessageDialog.Cancel: { - quitDialog.close(); - } - } - } - } - - Button { - id: surrenderButton - enabled: !config.observing && !config.replaying - text: Backend.translate("Surrender") - font.pixelSize: 28 - Layout.fillWidth: true - width: menuContainer.width - height: menuContainer.width * 0.65 - onClicked: { - if (isStarted && !getPhoto(Self.id).dead) { - const surrenderCheck = JSON.parse(Backend.callLuaFunction('CheckSurrenderAvailable', [miscStatus.playedTime])); - if (!surrenderCheck.length) { - surrenderDialog.informativeText = Backend.translate('Surrender is disabled in this mode'); - } else { - surrenderDialog.informativeText = surrenderCheck.map(str => `${Backend.translate(str.text)}(${str.passed ? '√' : '×'})`).join('
'); - } - surrenderDialog.open(); - } - } - } - - MessageDialog { - id: surrenderDialog - title: Backend.translate("Surrender") - informativeText: '' - buttons: MessageDialog.Ok | MessageDialog.Cancel - onButtonClicked: function (button, role) { - switch (button) { - case MessageDialog.Ok: { - const surrenderCheck = JSON.parse(Backend.callLuaFunction('CheckSurrenderAvailable', [miscStatus.playedTime])); - if (surrenderCheck.length && !surrenderCheck.find(check => !check.passed)) { - ClientInstance.notifyServer("PushRequest", [ - "surrender", true - ]); - } - surrenderDialog.close(); - break; - } - case MessageDialog.Cancel: { - surrenderDialog.close(); - } - } - } - } - - Button { - id: volumeButton - text: Backend.translate("Audio Settings") - font.pixelSize: 28 - Layout.fillWidth: true - width: menuContainer.width - height: menuContainer.width * 0.65 - onClicked: { - volumeDialog.open(); - } + MenuItem { + id: volumeButton + text: Backend.translate("Audio Settings") + onClicked: { + volumeDialog.open(); } } } @@ -988,57 +912,66 @@ Item { anchors.fill: parent } - Dialog { + MessageDialog { + id: quitDialog + title: Backend.translate("Quit") + informativeText: Backend.translate("Are you sure to quit?") + buttons: MessageDialog.Ok | MessageDialog.Cancel + onButtonClicked: function (button) { + switch (button) { + case MessageDialog.Ok: { + ClientInstance.notifyServer("QuitRoom", "[]"); + break; + } + case MessageDialog.Cancel: { + quitDialog.close(); + } + } + } + } + + MessageDialog { + id: surrenderDialog + title: Backend.translate("Surrender") + informativeText: '' + buttons: MessageDialog.Ok | MessageDialog.Cancel + onButtonClicked: function (button, role) { + switch (button) { + case MessageDialog.Ok: { + const surrenderCheck = JSON.parse(Backend.callLuaFunction('CheckSurrenderAvailable', [miscStatus.playedTime])); + if (surrenderCheck.length && !surrenderCheck.find(check => !check.passed)) { + ClientInstance.notifyServer("PushRequest", [ + "surrender", true + ]); + } + surrenderDialog.close(); + break; + } + case MessageDialog.Cancel: { + surrenderDialog.close(); + } + } + } + } + + Popup { id: volumeDialog - title: Backend.translate("Audio Settings") - anchors.centerIn: roomScene - ColumnLayout { - RowLayout { - anchors.rightMargin: 8 - spacing: 16 - Text { - text: Backend.translate("BGM Volume") - } - Slider { - Layout.rightMargin: 16 - Layout.fillWidth: true - from: 0 - to: 100 - value: config.bgmVolume - onValueChanged: config.bgmVolume = value; - } - } - - RowLayout { - anchors.rightMargin: 8 - spacing: 16 - Text { - text: Backend.translate("Effect Volume") - } - Slider { - Layout.rightMargin: 16 - Layout.fillWidth: true - from: 0 - to: 100 - value: Backend.volume - onValueChanged: Backend.volume = value; - } - } - - Switch { - text: Backend.translate("Disable message audio") - checked: config.disableMsgAudio - onCheckedChanged: config.disableMsgAudio = checked; - } - - Switch { - text: Backend.translate("Hide unselectable cards") - checked: config.hideUseless - onCheckedChanged: { - config.hideUseless = checked; - } - } + width: realMainWin.width * 0.5 + height: realMainWin.height * 0.5 + anchors.centerIn: parent + background: Rectangle { + color: "#EEEEEEEE" + radius: 5 + border.color: "#A6967A" + border.width: 1 + } + Loader { + anchors.centerIn: parent + width: parent.width / mainWindow.scale + height: parent.height / mainWindow.scale + scale: mainWindow.scale + source: AppPath + "/Fk/LobbyElement/AudioSetting.qml" } } diff --git a/android/src/org/notify/FreeKill/Helper.java b/android/src/org/notify/FreeKill/Helper.java index 8229bee4..5963a30f 100644 --- a/android/src/org/notify/FreeKill/Helper.java +++ b/android/src/org/notify/FreeKill/Helper.java @@ -63,8 +63,11 @@ public class Helper { return java.util.Locale.getDefault().toString(); } - public static void PlaySound(String path) { - MediaPlayer mp = new MediaPlayer(); + static MediaPlayer mp; + + public static void PlaySound(String path, float vol) { + // FIXME: 此法中途会被GC + mp = new MediaPlayer(); mp.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { @@ -74,6 +77,7 @@ public class Helper { }); try { mp.setDataSource(path); + mp.setVolume(vol, vol); mp.prepare(); mp.start(); } catch (Exception e) { diff --git a/lua/server/ai/random_ai.lua b/lua/server/ai/random_ai.lua index aee2894f..1108b17b 100644 --- a/lua/server/ai/random_ai.lua +++ b/lua/server/ai/random_ai.lua @@ -15,17 +15,18 @@ function RandomAI:useActiveSkill(skill, card) filter_func = Util.FalseFunc end - if self.command == "PlayCard" and card and (not skill:canUse(player, card) or player:prohibitUse(card)) then + if self.command == "PlayCard" and (not skill:canUse(player, card) or player:prohibitUse(card)) then return "" end local max_try_times = 100 local selected_targets = {} local selected_cards = {} - local min = skill:getMinTargetNum() - local max = skill:getMaxTargetNum(player, card) - local min_card = skill:getMinCardNum() - local max_card = skill:getMaxCardNum() + -- FIXME: ... + -- local min = skill:getMinTargetNum() + -- local max = skill:getMaxTargetNum(player, card) + -- local min_card = skill:getMinCardNum() + -- local max_card = skill:getMaxCardNum() for _ = 0, max_try_times do if skill:feasible(selected_targets, selected_cards, self.player, card) then break end local avail_targets = table.filter(room:getAlivePlayers(), function(p) diff --git a/src/ui/qmlbackend.cpp b/src/ui/qmlbackend.cpp index 080d4f4b..5123c3ff 100644 --- a/src/ui/qmlbackend.cpp +++ b/src/ui/qmlbackend.cpp @@ -324,7 +324,8 @@ void QmlBackend::playSound(const QString &name, int index) { #ifdef Q_OS_ANDROID QJniObject::callStaticMethod("org/notify/FreeKill/Helper", "PlaySound", - "(Ljava/lang/String;)V", QJniObject::fromString(fname).object()); + "(Ljava/lang/String;D)V", QJniObject::fromString(fname).object(), + (float)(m_volume / 100)); #else auto player = new QMediaPlayer; auto output = new QAudioOutput;