小修小改,没啥新功能
This commit is contained in:
notify 2023-12-09 23:25:26 +08:00 committed by GitHub
parent 5abbdc9b23
commit 94c1107c2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 110 additions and 168 deletions

View File

@ -84,7 +84,10 @@ Item {
text: (playerNum < capacity) ? Backend.translate("Enter") : text: (playerNum < capacity) ? Backend.translate("Enter") :
Backend.translate("Observe") Backend.translate("Observe")
enabled: !opTimer.running
onClicked: { onClicked: {
opTimer.start();
if (hasPassword) { if (hasPassword) {
lobby_dialog.sourceComponent = enterPassword; lobby_dialog.sourceComponent = enterPassword;
lobby_dialog.item.roomId = roomId; lobby_dialog.item.roomId = roomId;

View File

@ -81,15 +81,13 @@ Item {
} }
} }
ToolButton { Button {
id: menuButton id: menuButton
anchors.top: parent.top anchors.top: parent.top
anchors.topMargin: 12 anchors.topMargin: 12
anchors.right: parent.right anchors.right: parent.right
anchors.rightMargin: 36 anchors.rightMargin: 12
icon.source: AppPath + "/image/modmaker/menu" text: Backend.translate("Menu")
icon.width: 36
icon.height: 36
onClicked: { onClicked: {
if (menuContainer.visible){ if (menuContainer.visible){
menuContainer.close(); menuContainer.close();
@ -98,122 +96,48 @@ Item {
} }
} }
background.implicitWidth: 60
background.implicitHeight: 60
Menu { Menu {
id: menuContainer id: menuContainer
y: menuButton.height - 12 y: menuButton.height - 12
width: 115 width: 100
height: menuRow.height
verticalPadding: 0 MenuItem {
spacing: 15 id: quitButton
z: 2 text: Backend.translate("Quit")
background: Rectangle { onClicked: {
implicitWidth: 200 if (config.replaying) {
implicitHeight: 40 Backend.controlReplayer("shutdown");
color: "transparent" mainStack.pop();
border.color: "transparent" } else if (config.observing) {
ClientInstance.notifyServer("QuitRoom", "[]");
} else {
quitDialog.open();
}
}
} }
Column { MenuItem {
id: menuRow id: surrenderButton
width: menuContainer.width enabled: !config.observing && !config.replaying
Layout.fillWidth: true text: Backend.translate("Surrender")
spacing: 7 onClicked: {
if (isStarted && !getPhoto(Self.id).dead) {
Button { const surrenderCheck = JSON.parse(Backend.callLuaFunction('CheckSurrenderAvailable', [miscStatus.playedTime]));
id: quitButton if (!surrenderCheck.length) {
text: Backend.translate("Quit") surrenderDialog.informativeText = Backend.translate('Surrender is disabled in this mode');
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", "[]");
} else { } else {
quitDialog.open(); surrenderDialog.informativeText = surrenderCheck.map(str => `${Backend.translate(str.text)}${str.passed ? '√' : '×'}`).join('<br>');
} }
surrenderDialog.open();
} }
} }
}
MessageDialog { MenuItem {
id: quitDialog id: volumeButton
title: Backend.translate("Quit") text: Backend.translate("Audio Settings")
informativeText: Backend.translate("Are you sure to quit?") onClicked: {
buttons: MessageDialog.Ok | MessageDialog.Cancel volumeDialog.open();
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('<br>');
}
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();
}
} }
} }
} }
@ -988,57 +912,66 @@ Item {
anchors.fill: parent 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 id: volumeDialog
title: Backend.translate("Audio Settings") width: realMainWin.width * 0.5
anchors.centerIn: roomScene height: realMainWin.height * 0.5
ColumnLayout { anchors.centerIn: parent
RowLayout { background: Rectangle {
anchors.rightMargin: 8 color: "#EEEEEEEE"
spacing: 16 radius: 5
Text { border.color: "#A6967A"
text: Backend.translate("BGM Volume") border.width: 1
} }
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;
}
}
Loader {
anchors.centerIn: parent
width: parent.width / mainWindow.scale
height: parent.height / mainWindow.scale
scale: mainWindow.scale
source: AppPath + "/Fk/LobbyElement/AudioSetting.qml"
} }
} }

View File

@ -63,8 +63,11 @@ public class Helper {
return java.util.Locale.getDefault().toString(); return java.util.Locale.getDefault().toString();
} }
public static void PlaySound(String path) { static MediaPlayer mp;
MediaPlayer mp = new MediaPlayer();
public static void PlaySound(String path, float vol) {
// FIXME: 此法中途会被GC
mp = new MediaPlayer();
mp.setOnCompletionListener(new OnCompletionListener() { mp.setOnCompletionListener(new OnCompletionListener() {
@Override @Override
public void onCompletion(MediaPlayer mp) { public void onCompletion(MediaPlayer mp) {
@ -74,6 +77,7 @@ public class Helper {
}); });
try { try {
mp.setDataSource(path); mp.setDataSource(path);
mp.setVolume(vol, vol);
mp.prepare(); mp.prepare();
mp.start(); mp.start();
} catch (Exception e) { } catch (Exception e) {

View File

@ -15,17 +15,18 @@ function RandomAI:useActiveSkill(skill, card)
filter_func = Util.FalseFunc filter_func = Util.FalseFunc
end 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 "" return ""
end end
local max_try_times = 100 local max_try_times = 100
local selected_targets = {} local selected_targets = {}
local selected_cards = {} local selected_cards = {}
local min = skill:getMinTargetNum() -- FIXME: ...
local max = skill:getMaxTargetNum(player, card) -- local min = skill:getMinTargetNum()
local min_card = skill:getMinCardNum() -- local max = skill:getMaxTargetNum(player, card)
local max_card = skill:getMaxCardNum() -- local min_card = skill:getMinCardNum()
-- local max_card = skill:getMaxCardNum()
for _ = 0, max_try_times do for _ = 0, max_try_times do
if skill:feasible(selected_targets, selected_cards, self.player, card) then break end if skill:feasible(selected_targets, selected_cards, self.player, card) then break end
local avail_targets = table.filter(room:getAlivePlayers(), function(p) local avail_targets = table.filter(room:getAlivePlayers(), function(p)

View File

@ -324,7 +324,8 @@ void QmlBackend::playSound(const QString &name, int index) {
#ifdef Q_OS_ANDROID #ifdef Q_OS_ANDROID
QJniObject::callStaticMethod<void>("org/notify/FreeKill/Helper", "PlaySound", QJniObject::callStaticMethod<void>("org/notify/FreeKill/Helper", "PlaySound",
"(Ljava/lang/String;)V", QJniObject::fromString(fname).object<jstring>()); "(Ljava/lang/String;D)V", QJniObject::fromString(fname).object<jstring>(),
(float)(m_volume / 100));
#else #else
auto player = new QMediaPlayer; auto player = new QMediaPlayer;
auto output = new QAudioOutput; auto output = new QAudioOutput;