Last active
August 29, 2015 13:58
-
-
Save saward/9928520 to your computer and use it in GitHub Desktop.
Null vs undefined
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"gopkg.in/v0/qml" | |
) | |
type CraftElement struct { | |
Archetype *Archetype | |
Ready bool // True if the player has everything in place to craft this right now | |
} | |
type CraftModel struct { | |
Len int | |
Craftables []*CraftElement | |
} | |
func (cm *CraftModel) AddArchetype(a *Archetype) { | |
qml.Lock() | |
cm.Craftables = append(cm.Craftables, &CraftElement{a, false}) | |
cm.Len = len(cm.Craftables) | |
qml.Changed(cm, &cm.Len) | |
qml.Unlock() | |
} | |
func (cm *CraftModel) Get(index int) *CraftElement { | |
return cm.Craftables[index] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import QtQuick 2.1 | |
import QtQuick.Controls 1.1 | |
import QtQuick.Layouts 1.0 | |
// import GoExtensions 1.0 | |
CitWindow { | |
id: craftingWindow | |
width: 700 | |
height: 350 | |
Rectangle { | |
id: craftingRect | |
clip: true | |
x: content_x | |
y: content_y | |
width: content_width | |
height: content_height | |
property int selected: 0 | |
onSelectedChanged: { | |
selectionArea.text = "Selected is " + craftingRect.selected | |
} | |
Item { | |
anchors.left: parent.left | |
anchors.top: parent.top | |
width: parent.width/2 | |
height: parent.height | |
Component { | |
id: craftDelegate | |
Item { | |
width: parent.width; height: 40 | |
Column { | |
Text { text: '<b>Archetype:</b> ' + craftModel.get(index).archetype.simpleName } | |
} | |
MouseArea { | |
id: mouseArea | |
acceptedButtons: Qt.LeftButton | Qt.RightButton | |
width: parent.width | |
height: parent.height | |
hoverEnabled: true //this line will enable mouseArea.containsMouse | |
onClicked: { | |
craftingRect.selected = index | |
console.log("Selected: " + index + " and crselect: " + craftingRect.selected) | |
} | |
} | |
} | |
} | |
ListView { | |
anchors.fill: parent | |
model: craftModel.len | |
delegate: craftDelegate | |
highlight: Rectangle { color: "lightsteelblue"; radius: 5 } | |
focus: true | |
} | |
} | |
Item { | |
anchors.right: parent.right | |
anchors.top: parent.top | |
width: parent.width/2 | |
height: parent.height | |
Text { | |
id: selectionArea | |
text: "............Selected is " + craftingRect.selected | |
} | |
Button { | |
text: "craft!" | |
onClicked: { | |
var be = craftModel.get(craftingRect.selected) | |
game.createJob("craft", false, {"product_name": be.archetype.simpleName}) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment