Warning, /education/gcompris/src/activities/oware/Pit.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - Pit.qml 0002 * 0003 * SPDX-FileCopyrightText: 2021 Harsh Kumar <hadron43@yahoo.com> 0004 * 0005 * Authors: 0006 * Harsh Kumar <hadron43@yahoo.com> 0007 * Timothée Giet <animtim@gmail.com> (redesign) 0008 * 0009 * SPDX-License-Identifier: GPL-3.0-or-later 0010 */ 0011 0012 import QtQuick 2.12 0013 import GCompris 1.0 0014 0015 import "../../core" 0016 import "oware.js" as Activity 0017 0018 Item { 0019 id: pit 0020 property int player 0021 property int index 0022 property bool responsive: true 0023 property bool label: true 0024 property bool highlight: false 0025 property string highlightColor: "#E77936" //orange 0026 property bool selected: false 0027 0028 height: circle.height 0029 0030 Component.onCompleted: { 0031 for(var i = 0; i < 9; ++i) 0032 representationListModel.append({ display: false }) 0033 updateListModel() 0034 } 0035 0036 // the number of seeds to be displayed in the pit 0037 property int seeds: 0 0038 0039 onSeedsChanged: updateListModel() 0040 0041 ListModel { 0042 id: representationListModel 0043 } 0044 0045 function updateListModel () { 0046 var representation = ["000000000", "000010000", "100000001", 0047 "000111000", "101000101", "101010101", 0048 "101101101", "111010111", "111101111", 0049 "111111111"] [Math.min(seeds, 9)] 0050 for(var i = 0; i < 9; ++i) 0051 representationListModel.set(i, { 0052 display: representation.charAt(i) == "1" 0053 }) 0054 } 0055 0056 function getSeedSize() { 0057 return 0.9 * gridView.cellWidth 0058 } 0059 0060 Rectangle { 0061 id: outline 0062 color: pit.selected ? "#D2D2D2" : (player === 1 ? "#23B582" : "#37539A") 0063 width: pit.selected ? 1.15 * circle.width : 1.05 * circle.width 0064 height: width 0065 radius: width * 0.5 0066 anchors.centerIn: circle 0067 visible: label 0068 } 0069 0070 Rectangle { 0071 id: circle 0072 color: pit.highlight ? pit.highlightColor : "#8a4f28" 0073 width: parent.width 0074 height: width 0075 radius: width * 0.5 0076 anchors { 0077 bottom: player === 1 ? parent.bottom : undefined 0078 top: player === 2 ? parent.top : undefined 0079 } 0080 0081 GridView { 0082 id: gridView 0083 width: 1.414 * circle.radius 0084 height: width 0085 anchors.verticalCenter: parent.verticalCenter 0086 anchors.horizontalCenter: parent.horizontalCenter 0087 cellWidth: width / 3 0088 cellHeight: cellWidth 0089 interactive: false 0090 0091 model: representationListModel 0092 delegate: Item { 0093 width: gridView.cellWidth 0094 height: gridView.cellHeight 0095 0096 Image { 0097 source: Activity.url + "seed.svg" 0098 width: 0.9 * parent.width 0099 height: width 0100 sourceSize.width: width 0101 visible: display 0102 anchors.horizontalCenter: parent.horizontalCenter 0103 anchors.verticalCenter: parent.verticalCenter 0104 } 0105 } 0106 } 0107 } 0108 0109 Rectangle { 0110 id: labelHandBg 0111 height: pitLabel.height 0112 width: pitLabel.width 0113 radius: height * 0.25 0114 color: "#80FFFFFF" 0115 visible: !label 0116 anchors.centerIn: circle 0117 } 0118 0119 GCText { 0120 id: pitLabel 0121 anchors { 0122 top: label && player === 2 ? circle.bottom : undefined 0123 topMargin: top != undefined ? board.margin : 0 0124 bottom: label && player === 1 ? circle.top : undefined 0125 bottomMargin: bottom != undefined ? board.margin : 0 0126 verticalCenter: label ? undefined : circle.verticalCenter 0127 horizontalCenter: circle.horizontalCenter 0128 } 0129 color: "#373737" 0130 verticalAlignment: Text.AlignVCenter 0131 horizontalAlignment: Text.AlignHCenter 0132 text: seeds.toString() 0133 width: parent.width * 0.5 0134 height: parent.height * 0.5 0135 fontSizeMode: Text.Fit 0136 } 0137 0138 MouseArea { 0139 anchors.centerIn: parent 0140 width: parent.width + margin 0141 height: width 0142 enabled: responsive 0143 onClicked: { 0144 Activity.processMove(player, index) 0145 } 0146 } 0147 }