| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- import QtQuick 2.15
- import QtQuick.Controls 2.15
- Item {
- id: root
- property var colors: ({
- })
- property var playersModel: null
- property var teamIcons: []
- property var currentMapData: null
- property string mapTitle: "Select a map"
- property string mapPreview: ""
- signal addCPUClicked()
- signal removePlayerClicked(int index)
- signal playerColorClicked(int index)
- signal playerTeamClicked(int index)
- signal playerFactionClicked(int index)
- anchors.fill: parent
- Component {
- id: playerListItemComponent
- Loader {
- property var itemColors: root.colors
- property var itemPlayerData: model
- property var itemTeamIcons: root.teamIcons
- property bool itemCanRemove: !model.isHuman
- source: "./PlayerListItem.qml"
- onLoaded: {
- item.colors = Qt.binding(function() {
- return itemColors;
- });
- item.playerData = Qt.binding(function() {
- return itemPlayerData;
- });
- item.teamIcons = Qt.binding(function() {
- return itemTeamIcons;
- });
- item.canRemove = Qt.binding(function() {
- return itemCanRemove;
- });
- item.removeClicked.connect(function() {
- root.removePlayerClicked(index);
- });
- item.colorClicked.connect(function() {
- root.playerColorClicked(index);
- });
- item.teamClicked.connect(function() {
- root.playerTeamClicked(index);
- });
- item.factionClicked.connect(function() {
- root.playerFactionClicked(index);
- });
- }
- }
- }
- Text {
- id: title
- text: root.mapTitle
- color: colors.textMain
- font.pixelSize: 20
- font.bold: true
- elide: Text.ElideRight
- anchors {
- top: parent.top
- left: parent.left
- right: parent.right
- }
- }
- Item {
- id: playerSection
- height: Math.min(350, parent.height * 0.6)
- anchors {
- top: title.bottom
- topMargin: 16
- left: parent.left
- right: parent.right
- }
- Text {
- id: playerSectionTitle
- text: "Players (" + (playersModel ? playersModel.count : 0) + ")"
- color: colors.textMain
- font.pixelSize: 16
- font.bold: true
- }
- Text {
- id: playerSectionHint
- text: "Click color/team to cycle"
- color: colors.textSubLite
- font.pixelSize: 11
- font.italic: true
- anchors {
- left: playerSectionTitle.right
- leftMargin: 10
- verticalCenter: playerSectionTitle.verticalCenter
- }
- }
- Rectangle {
- id: playerListFrame
- radius: 8
- color: colors.cardBaseA
- border.color: colors.panelBr
- border.width: 1
- clip: true
- anchors {
- top: playerSectionTitle.bottom
- topMargin: 10
- left: parent.left
- right: parent.right
- bottom: addCPUBtn.top
- bottomMargin: 8
- }
- ListView {
- id: playerListView
- anchors.fill: parent
- anchors.margins: 8
- model: root.playersModel
- spacing: 6
- clip: true
- boundsBehavior: Flickable.StopAtBounds
- delegate: playerListItemComponent
- Item {
- anchors.fill: parent
- visible: !playersModel || playersModel.count === 0
- Text {
- anchors.centerIn: parent
- text: "Select a map to configure players"
- color: colors.textSub
- font.pixelSize: 13
- }
- }
- ScrollBar.vertical: ScrollBar {
- policy: ScrollBar.AsNeeded
- }
- }
- }
- Button {
- id: addCPUBtn
- text: "+ Add CPU"
- enabled: {
- if (!currentMapData || !currentMapData.player_ids)
- return false;
- if (!playersModel)
- return false;
- return playersModel.count < currentMapData.player_ids.length;
- }
- hoverEnabled: true
- onClicked: root.addCPUClicked()
- anchors {
- bottom: parent.bottom
- left: parent.left
- }
- MouseArea {
- id: addHover
- anchors.fill: parent
- hoverEnabled: true
- acceptedButtons: Qt.NoButton
- cursorShape: enabled ? Qt.PointingHandCursor : Qt.ArrowCursor
- }
- ToolTip {
- visible: addHover.containsMouse && enabled
- text: "Add AI player to the game"
- delay: 500
- }
- contentItem: Text {
- text: addCPUBtn.text
- font.pixelSize: 12
- font.bold: true
- color: enabled ? colors.addColor : colors.textSub
- horizontalAlignment: Text.AlignHCenter
- verticalAlignment: Text.AlignVCenter
- }
- background: Rectangle {
- implicitWidth: 100
- implicitHeight: 32
- radius: 6
- color: enabled ? (addCPUBtn.down ? Qt.darker(colors.addColor, 1.3) : (addHover.containsMouse ? Qt.darker(colors.addColor, 1.1) : colors.cardBaseA)) : colors.cardBaseA
- border.width: 1
- border.color: enabled ? colors.addColor : colors.thumbBr
- Behavior on color {
- ColorAnimation {
- duration: 150
- }
- }
- }
- }
- Text {
- text: {
- if (!currentMapData || !currentMapData.player_ids)
- return "";
- if (!playersModel)
- return "";
- var available = currentMapData.player_ids.length - playersModel.count;
- if (available <= 0)
- return "Max players reached";
- return available + " slot" + (available > 1 ? "s" : "") + " available";
- }
- color: colors.textSubLite
- font.pixelSize: 11
- anchors {
- left: addCPUBtn.right
- leftMargin: 10
- verticalCenter: addCPUBtn.verticalCenter
- }
- }
- }
- Rectangle {
- id: preview
- radius: 8
- color: "#031314"
- border.color: colors.thumbBr
- border.width: 1
- clip: true
- anchors {
- top: playerSection.bottom
- topMargin: 16
- left: parent.left
- right: parent.right
- bottom: parent.bottom
- }
- Image {
- id: previewImage
- anchors.fill: parent
- source: root.mapPreview
- asynchronous: true
- fillMode: Image.PreserveAspectFit
- visible: status === Image.Ready
- }
- Text {
- anchors.centerIn: parent
- visible: !previewImage.visible
- text: "(map preview)"
- color: colors.hint
- font.pixelSize: 14
- }
- }
- }
|