1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
var BuilderInfo = View.extend({
el: "#builderInfo",
events: {
"mousedown": "stopPropagation",
"keydown": 'stopPropagation',
"change [name=x]": 'changeX',
"change [name=y]": 'changeY',
"change [name=width]": 'changeWidth',
"change [name=depth]": 'changeDepth',
"change [name=height]": 'changeHeight',
"keydown [name=width]": 'enterWidth',
"keydown [name=depth]": 'enterDepth',
"keydown [name=height]": 'enterHeight',
"change [name=units]": 'changeUnits',
"keydown [name=viewHeight]": 'enterViewHeight',
"change [name=viewHeight]": 'changeViewHeight',
"change [name=heightGlobal]": 'changeHeightGlobal',
"click [data-role=destroy-room]": 'destroy',
},
initialize: function(opt){
this.parent = opt.parent
this.$x = this.$("[name=x]")
this.$y = this.$("[name=y]")
this.$width = this.$("[name=width]")
this.$depth = this.$("[name=depth]")
this.$height = this.$("[name=height]")
this.$units = this.$("[name=units]")
this.$viewHeight = this.$("[name=viewHeight]")
this.$unitName = this.$(".unitName")
this.$noSelection = this.$(".no-selection")
this.$settings = this.$(".setting")
this.$heightGlobalCheckbox = this.$("[name=heightGlobal]")
app.on("builder-pick-room", this.pick.bind(this))
app.on("builder-destroy-room", this.hide.bind(this))
app.on("builder-pick-nothing", this.deselect.bind(this))
},
load: function(data){
this.$viewHeight.unitVal( window.viewHeight = data.viewHeight || app.defaults.viewHeight )
this.$units.val( data.units || "ft" )
this.$unitName.html( data.units || "ft" )
if (Rooms.regions.length == 0) {
this.changeHeightGlobal(true)
}
else {
var rooms = Rooms.values()
var height = rooms[0].height
var differentHeights = Rooms.some(function(room){
return room.height != height
})
this.changeHeightGlobal( ! differentHeights )
}
},
toggle: function(state){
this.$settings.toggle( !! this.room )
this.$noSelection.toggle( ! this.room )
this.$el.toggleClass("active", state)
if (state) {
this.$viewHeight.unitVal( window.viewHeight )
this.parent.cursor.message("builder")
}
else {
this.parent.cursor.message("start")
}
},
show: function(){
this.toggle(true)
},
hide: function(){
this.room = null
this.toggle(false)
},
room: null,
pick: function(room){
this.room = room
this.$width.unitVal( room.rect.x.length() )
this.$depth.unitVal( room.rect.y.length() )
this.$height.unitVal( room.height )
this.$x.unitVal( room.rect.x.a )
this.$y.unitVal( room.rect.y.a )
this.show()
},
deselect: function(){
this.room = null
this.toggle(true)
},
destroy: function(){
UndoStack.push({
type: "destroy-room",
undo: this.room.copy(),
redo: { id: this.room.id },
})
Rooms.remove(this.room)
app.tube("builder-destroy-room", this.room)
this.room = null
this.hide()
},
enterWidth: function(e){
if (e.keyCode == 13) this.changeWidth(e)
},
changeWidth: function(e){
e.stopPropagation()
this.room.rect.x.setLength( this.$width.unitVal() )
Rooms.rebuild()
},
enterDepth: function(e){
if (e.keyCode == 13) this.changeDepth(e)
},
changeDepth: function(e){
e.stopPropagation()
this.room.rect.y.setLength( this.$depth.unitVal() )
Rooms.rebuild()
},
enterHeight: function(e){
if (e.keyCode == 13) this.changeHeight(e)
},
changeHeight: function(e){
e.stopPropagation()
var height = this.room.height = this.$height.unitVal()
if (window.heightIsGlobal) {
Rooms.forEach(function(room){
room.height = height
})
}
Rooms.rebuild()
},
changeX: function(e){
e.stopPropagation()
this.room.rect.x.setPosition( this.$x.unitVal() )
Rooms.rebuild()
},
changeY: function(e){
e.stopPropagation()
this.room.rect.y.setPosition( this.$y.unitVal() )
Rooms.rebuild()
},
changeUnits: function(){
app.units = this.$units.val()
this.$('.units').resetUnitVal()
},
enterViewHeight: function(e){
if (e.keyCode == 13) this.changeViewHeight(e)
},
changeViewHeight: function(){
window.viewHeight = this.$viewHeight.unitVal( )
},
changeHeightGlobal: function(state){
if (typeof state == "boolean") {
this.$heightGlobalCheckbox.prop("checked", state)
window.heightIsGlobal = state
return
}
window.heightIsGlobal = this.$heightGlobalCheckbox.prop("checked")
},
})
|