-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcardPickingUI.swift
More file actions
244 lines (219 loc) · 14.7 KB
/
cardPickingUI.swift
File metadata and controls
244 lines (219 loc) · 14.7 KB
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
//
// cardPickingUI.swift
// project-mars
//
// Created by Aleksandr Grin on 2/23/17.
// Copyright © 2017 AleksandrGrin. All rights reserved.
//
import Foundation
import SpriteKit
class cardPickingUI: SKNode {
var showHideUIButton:SpriteButton!
var cancelButton:SpriteButton!
var fullCardSelectionUI:SKSpriteNode!
var deOrbitAsteroidCard:SpriteButton!
var factoryDropCard:SpriteButton!
var crawlerDropCard:SpriteButton!
var repairTeamsCard:SpriteButton!
var closeCardMenu:SpriteButton!
var labelsList:Array<SKLabelNode> = []
init(size: CGSize){
super.init()
self.addShowHideButton(size: size)
self.createMainUIPage(size: size)
self.hideCardSelectionUI()
self.addCancelButton(size: size)
self.addCardButtons(size: size)
}
private func addShowHideButton(size: CGSize){
self.showHideUIButton = SpriteButton()
self.showHideUIButton.changeButtonText(to: "Cards")
self.showHideUIButton.changeButtonSize(to: CGSize(width: size.width / 5, height: size.height / 14))
self.showHideUIButton.position = CGPoint(x: size.width / 2 - 30, y: size.height / 5)
self.showHideUIButton.zPosition = 5
self.addChild(self.showHideUIButton)
}
private func addCancelButton(size: CGSize){
self.cancelButton = SpriteButton()
self.cancelButton.changeButtonText(to: "Cancel")
self.cancelButton.changeButtonSize(to: CGSize(width: size.width / 5, height: size.height / 14))
self.cancelButton.position = CGPoint(x: size.width / 2 - 30, y: self.showHideUIButton.position.y - self.showHideUIButton.size.height - 10)
self.cancelButton.zPosition = 5
self.cancelButton.isHidden = true
self.addChild(self.cancelButton)
}
private func createMainUIPage(size: CGSize){
self.fullCardSelectionUI = SKSpriteNode()
self.fullCardSelectionUI.texture = SKTexture(imageNamed: "Secondary_BG_final")
self.fullCardSelectionUI.size = CGSize(width: size.width - (size.width / 8), height: size.height - (size.height / 4))
self.fullCardSelectionUI.anchorPoint = CGPoint(x: 0.5, y: 0.5)
self.fullCardSelectionUI.position = CGPoint(x: 0, y: 0)
self.fullCardSelectionUI.zPosition = 10
self.addChild(self.fullCardSelectionUI)
}
private func addCardButtons(size: CGSize){
let spacingOffset:CGFloat = 16
let buttonWidth:CGFloat = 200
let interOptionSpacingFactor:CGFloat = 3
let labelSpacingFactor:CGFloat = 1.25
self.deOrbitAsteroidCard = SpriteButton()
self.deOrbitAsteroidCard.changeButtonText(to: "De-Orbit Asteroid")
self.deOrbitAsteroidCard.changeButtonSize(to: CGSize(width: buttonWidth, height: self.fullCardSelectionUI.size.height / spacingOffset))
self.deOrbitAsteroidCard.position = CGPoint(x: 0, y: self.fullCardSelectionUI.size.height / 2 - (self.fullCardSelectionUI.size.height / 10))
self.deOrbitAsteroidCard.zPosition = 11
self.deOrbitAsteroidCard.anchorPoint = CGPoint(x: 0.5, y: 0.5)
self.fullCardSelectionUI.addChild(self.deOrbitAsteroidCard)
let Asteroidlabel1 = SKLabelNode(text: "Cost: 30 minerals. You can have an asteroid dropped on a ")
Asteroidlabel1.position = CGPoint(x: 0, y: self.deOrbitAsteroidCard.position.y - self.deOrbitAsteroidCard.size.height*labelSpacingFactor)
Asteroidlabel1.fontColor = SKColor.white
Asteroidlabel1.fontName = "AvenirNext-Bold"
Asteroidlabel1.fontSize = 10
self.name = "Default"
self.fullCardSelectionUI.addChild(Asteroidlabel1)
self.labelsList.append(Asteroidlabel1)
let Asteroidlabel2 = SKLabelNode(text: "province to deal 10 damage to everything in the province.")
Asteroidlabel2.position = CGPoint(x: 0, y: self.deOrbitAsteroidCard.position.y - self.deOrbitAsteroidCard.size.height*labelSpacingFactor - 15)
Asteroidlabel2.fontColor = SKColor.white
Asteroidlabel2.fontName = "AvenirNext-Bold"
Asteroidlabel2.fontSize = 10
self.name = "Default"
self.fullCardSelectionUI.addChild(Asteroidlabel2)
self.labelsList.append(Asteroidlabel2)
self.factoryDropCard = SpriteButton()
self.factoryDropCard.changeButtonText(to: "Drop Extractor")
self.factoryDropCard.changeButtonSize(to: CGSize(width: buttonWidth, height: self.fullCardSelectionUI.size.height / spacingOffset))
self.factoryDropCard.position = CGPoint(x: 0, y: self.deOrbitAsteroidCard.position.y - self.deOrbitAsteroidCard.size.height*interOptionSpacingFactor)
self.factoryDropCard.zPosition = 11
self.factoryDropCard.anchorPoint = CGPoint(x: 0.5, y: 0.5)
self.fullCardSelectionUI.addChild(self.factoryDropCard)
let ExtractorLabel1 = SKLabelNode(text: "Cost: 10 minerals. You can have an extractor deployed on a ")
ExtractorLabel1.position = CGPoint(x: 0, y: self.factoryDropCard.position.y - self.factoryDropCard.size.height*labelSpacingFactor)
ExtractorLabel1.fontColor = SKColor.white
ExtractorLabel1.fontName = "AvenirNext-Bold"
ExtractorLabel1.fontSize = 10
self.name = "Default"
self.fullCardSelectionUI.addChild(ExtractorLabel1)
self.labelsList.append(ExtractorLabel1)
let ExtractorLabel2 = SKLabelNode(text: "province you control where the landship is not present.")
ExtractorLabel2.position = CGPoint(x: 0, y: self.factoryDropCard.position.y - self.factoryDropCard.size.height*labelSpacingFactor - 15)
ExtractorLabel2.fontColor = SKColor.white
ExtractorLabel2.fontName = "AvenirNext-Bold"
ExtractorLabel2.fontSize = 10
self.name = "Default"
self.fullCardSelectionUI.addChild(ExtractorLabel2)
self.labelsList.append(ExtractorLabel2)
self.crawlerDropCard = SpriteButton()
self.crawlerDropCard.changeButtonText(to: "Drop Crawlers")
self.crawlerDropCard.changeButtonSize(to: CGSize(width: buttonWidth, height: self.fullCardSelectionUI.size.height / spacingOffset))
self.crawlerDropCard.position = CGPoint(x: 0, y: self.factoryDropCard.position.y - self.factoryDropCard.size.height*interOptionSpacingFactor)
self.crawlerDropCard.zPosition = 11
self.crawlerDropCard.anchorPoint = CGPoint(x: 0.5, y: 0.5)
self.fullCardSelectionUI.addChild(self.crawlerDropCard)
let CrawlerLabel1 = SKLabelNode(text: "Cost: 20 minerals. You can have a detatchement of 5 ")
CrawlerLabel1.position = CGPoint(x: 0, y: self.crawlerDropCard.position.y - self.crawlerDropCard.size.height*labelSpacingFactor)
CrawlerLabel1.fontColor = SKColor.white
CrawlerLabel1.fontName = "AvenirNext-Bold"
CrawlerLabel1.fontSize = 10
self.name = "Default"
self.fullCardSelectionUI.addChild(CrawlerLabel1)
self.labelsList.append(CrawlerLabel1)
let CrawlerLabel2 = SKLabelNode(text: "crawlers deployed on a province you control.")
CrawlerLabel2.position = CGPoint(x: 0, y: self.crawlerDropCard.position.y - self.crawlerDropCard.size.height*labelSpacingFactor - 15)
CrawlerLabel2.fontColor = SKColor.white
CrawlerLabel2.fontName = "AvenirNext-Bold"
CrawlerLabel2.fontSize = 10
self.name = "Default"
self.fullCardSelectionUI.addChild(CrawlerLabel2)
self.labelsList.append(CrawlerLabel2)
self.repairTeamsCard = SpriteButton()
self.repairTeamsCard.changeButtonText(to: "Landship Repair Teams")
self.repairTeamsCard.changeButtonSize(to: CGSize(width: buttonWidth, height: self.fullCardSelectionUI.size.height / spacingOffset))
self.repairTeamsCard.position = CGPoint(x: 0, y: self.crawlerDropCard.position.y - self.crawlerDropCard.size.height*interOptionSpacingFactor)
self.repairTeamsCard.zPosition = 11
self.repairTeamsCard.anchorPoint = CGPoint(x: 0.5, y: 0.5)
self.fullCardSelectionUI.addChild(self.repairTeamsCard)
let repairLabel1 = SKLabelNode(text: "Cost: 10 minerals. Minerals are used to do emergency ")
repairLabel1.position = CGPoint(x: 0, y: self.repairTeamsCard.position.y - self.repairTeamsCard.size.height*labelSpacingFactor)
repairLabel1.fontColor = SKColor.white
repairLabel1.fontName = "AvenirNext-Bold"
repairLabel1.fontSize = 10
self.name = "Default"
self.fullCardSelectionUI.addChild(repairLabel1)
self.labelsList.append(repairLabel1)
let repairLabel2 = SKLabelNode(text: "repairs on your landship and restore it to full health.")
repairLabel2.position = CGPoint(x: 0, y: self.repairTeamsCard.position.y - self.repairTeamsCard.size.height*labelSpacingFactor - 15)
repairLabel2.fontColor = SKColor.white
repairLabel2.fontName = "AvenirNext-Bold"
repairLabel2.fontSize = 10
self.name = "Default"
self.fullCardSelectionUI.addChild(repairLabel2)
self.labelsList.append(repairLabel2)
self.closeCardMenu = SpriteButton()
self.closeCardMenu.changeButtonText(to: "Exit Card Menu")
self.closeCardMenu.changeButtonSize(to: CGSize(width: buttonWidth, height: self.fullCardSelectionUI.size.height / spacingOffset))
self.closeCardMenu.position = CGPoint(x: 0, y: self.repairTeamsCard.position.y - self.repairTeamsCard.size.height*interOptionSpacingFactor)
self.closeCardMenu.zPosition = 11
self.closeCardMenu.anchorPoint = CGPoint(x: 0.5, y: 0.5)
self.fullCardSelectionUI.addChild(self.closeCardMenu)
}
func hideCardSelectionUI(){
self.fullCardSelectionUI.isHidden = true
}
func showCardSelectionUI(){
self.fullCardSelectionUI.isHidden = false
}
func updateUIforOrientation(size: CGSize){
let spacingOffset:CGFloat = 16
let buttonWidth:CGFloat = 200
let interOptionSpacingFactor:CGFloat = 3
let labelSpacingFactor:CGFloat = 1.25
if self.fullCardSelectionUI != nil {
self.showHideUIButton.position = CGPoint(x: size.width / 2 - 30, y: size.height / 5)
self.cancelButton.position = CGPoint(x: size.width / 2 - 30, y: self.showHideUIButton.position.y - self.showHideUIButton.size.height - 10)
self.fullCardSelectionUI.size = CGSize(width: size.width - (size.width / 8), height: size.height - (size.height / 4))
self.fullCardSelectionUI.position = CGPoint(x: 0, y: 0)
self.deOrbitAsteroidCard.changeButtonSize(to: CGSize(width: buttonWidth, height: self.fullCardSelectionUI.size.height / spacingOffset))
self.deOrbitAsteroidCard.position = CGPoint(x: 0, y: self.fullCardSelectionUI.size.height / 2 - (self.fullCardSelectionUI.size.height / 10))
self.labelsList[0].position = CGPoint(x: 0, y: self.deOrbitAsteroidCard.position.y - self.deOrbitAsteroidCard.size.height*labelSpacingFactor)
self.labelsList[1].position = CGPoint(x: 0, y: self.deOrbitAsteroidCard.position.y - self.deOrbitAsteroidCard.size.height*labelSpacingFactor - 15)
self.factoryDropCard.changeButtonSize(to: CGSize(width: buttonWidth, height: self.fullCardSelectionUI.size.height / spacingOffset))
self.factoryDropCard.position = CGPoint(x: 0, y: self.deOrbitAsteroidCard.position.y - self.deOrbitAsteroidCard.size.height*interOptionSpacingFactor)
self.labelsList[2].position = CGPoint(x: 0, y: self.factoryDropCard.position.y - self.factoryDropCard.size.height*labelSpacingFactor)
self.labelsList[3].position = CGPoint(x: 0, y: self.factoryDropCard.position.y - self.factoryDropCard.size.height*labelSpacingFactor - 15)
self.crawlerDropCard.changeButtonSize(to: CGSize(width: buttonWidth, height: self.fullCardSelectionUI.size.height / spacingOffset))
self.crawlerDropCard.position = CGPoint(x: 0, y: self.factoryDropCard.position.y - self.factoryDropCard.size.height*interOptionSpacingFactor)
self.labelsList[4].position = CGPoint(x: 0, y: self.crawlerDropCard.position.y - self.crawlerDropCard.size.height*labelSpacingFactor)
self.labelsList[5].position = CGPoint(x: 0, y: self.crawlerDropCard.position.y - self.crawlerDropCard.size.height*labelSpacingFactor - 15)
self.repairTeamsCard.changeButtonSize(to: CGSize(width: buttonWidth, height: self.fullCardSelectionUI.size.height / spacingOffset))
self.repairTeamsCard.position = CGPoint(x: 0, y: self.crawlerDropCard.position.y - self.crawlerDropCard.size.height*interOptionSpacingFactor)
self.labelsList[6].position = CGPoint(x: 0, y: self.repairTeamsCard.position.y - self.repairTeamsCard.size.height*labelSpacingFactor)
self.labelsList[7].position = CGPoint(x: 0, y: self.repairTeamsCard.position.y - self.repairTeamsCard.size.height*labelSpacingFactor - 15)
self.closeCardMenu.changeButtonSize(to: CGSize(width: buttonWidth, height: self.fullCardSelectionUI.size.height / spacingOffset))
self.closeCardMenu.position = CGPoint(x: 0, y: self.repairTeamsCard.position.y - self.repairTeamsCard.size.height*interOptionSpacingFactor)
}
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.showHideUIButton = aDecoder.decodeObject(forKey: "showHideUIButton") as? SpriteButton!
self.fullCardSelectionUI = aDecoder.decodeObject(forKey: "fullCardSelectionUI") as? SKSpriteNode!
self.cancelButton = aDecoder.decodeObject(forKey: "cancel") as? SpriteButton!
self.deOrbitAsteroidCard = aDecoder.decodeObject(forKey: "deOrbit") as? SpriteButton!
self.factoryDropCard = aDecoder.decodeObject(forKey: "factory") as? SpriteButton!
self.crawlerDropCard = aDecoder.decodeObject(forKey: "crawler") as? SpriteButton!
self.repairTeamsCard = aDecoder.decodeObject(forKey: "repair") as? SpriteButton!
self.closeCardMenu = aDecoder.decodeObject(forKey: "closeMenu") as? SpriteButton!
self.labelsList = (aDecoder.decodeObject(forKey: "labels") as? Array<SKLabelNode>)!
}
override func encode(with aCoder: NSCoder) {
super.encode(with: aCoder)
aCoder.encode(self.showHideUIButton, forKey: "showHideUIButton")
aCoder.encode(self.fullCardSelectionUI, forKey: "fullCardSelectionUI")
aCoder.encode(self.cancelButton, forKey: "cancel")
aCoder.encode(self.deOrbitAsteroidCard, forKey: "deOrbit")
aCoder.encode(self.factoryDropCard, forKey: "factory")
aCoder.encode(self.crawlerDropCard, forKey: "crawler")
aCoder.encode(self.repairTeamsCard, forKey: "repair")
aCoder.encode(self.closeCardMenu, forKey: "closeMenu")
aCoder.encode(self.labelsList, forKey: "labels")
}
}