Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beautify UI #30

Merged
merged 1 commit into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
41 changes: 22 additions & 19 deletions TowerForge/TowerForge/AppMain/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="NJ9-hN-4Nf">
<device id="ipad10_9rounded" orientation="portrait" layout="fullscreen" appearance="light"/>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="NJ9-hN-4Nf">
<device id="ipad12_9" orientation="landscape" layout="fullscreen" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22684"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22504"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand All @@ -14,7 +14,7 @@
<objects>
<viewController title="GameViewController" wantsFullScreenLayout="YES" modalPresentationStyle="fullScreen" id="BV1-FR-VrT" customClass="GameViewController" customModule="TowerForge" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" multipleTouchEnabled="YES" contentMode="scaleToFill" id="3se-qz-xqx" customClass="SKView">
<rect key="frame" x="0.0" y="0.0" width="820" height="1180"/>
<rect key="frame" x="0.0" y="0.0" width="1366" height="1024"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<viewLayoutGuide key="safeArea" id="4qk-I5-YsI"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
Expand All @@ -29,41 +29,44 @@
<scene sceneID="vFw-SO-Nq3">
<objects>
<viewController title="MainMenuViewController" id="NJ9-hN-4Nf" customClass="MainMenuViewController" customModule="TowerForge" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="QTh-pm-dcu">
<rect key="frame" x="0.0" y="0.0" width="820" height="1180"/>
<view key="view" contentMode="scaleAspectFill" id="QTh-pm-dcu">
<rect key="frame" x="0.0" y="0.0" width="1366" height="1024"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Itc-dO-lSy">
<rect key="frame" x="357.5" y="722.5" width="105" height="35"/>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="filled" title="Play Game"/>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" image="background" translatesAutoresizingMaskIntoConstraints="NO" id="BeN-nt-myH">
<rect key="frame" x="0.0" y="389" width="1366" height="635"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</imageView>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" image="logo" translatesAutoresizingMaskIntoConstraints="NO" id="1WN-bo-aqT">
<rect key="frame" x="285" y="20" width="796" height="607"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</imageView>
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Itc-dO-lSy">
<rect key="frame" x="535" y="615" width="296" height="80"/>
<buttonConfiguration key="configuration" style="filled" title="Play Game">
<color key="baseForegroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</buttonConfiguration>
<connections>
<segue destination="BV1-FR-VrT" kind="show" identifier="segueToGame" id="hzG-cy-bt1"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="TowerForge" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bv5-8z-jVe">
<rect key="frame" x="252" y="302" width="316" height="76.5"/>
<fontDescription key="fontDescription" type="system" pointSize="64"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<viewLayoutGuide key="safeArea" id="0sR-0W-mF4"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstItem="bv5-8z-jVe" firstAttribute="centerY" secondItem="QTh-pm-dcu" secondAttribute="centerY" constant="-250" id="USB-XJ-Fmh"/>
<constraint firstItem="bv5-8z-jVe" firstAttribute="centerX" secondItem="QTh-pm-dcu" secondAttribute="centerX" id="VXw-SM-1j3"/>
<constraint firstItem="Itc-dO-lSy" firstAttribute="centerX" secondItem="QTh-pm-dcu" secondAttribute="centerX" id="WHv-Ev-8P8"/>
<constraint firstItem="Itc-dO-lSy" firstAttribute="centerY" secondItem="QTh-pm-dcu" secondAttribute="centerY" constant="150" id="cHw-CH-V3j"/>
</constraints>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="EMN-tQ-Alx" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-684.14634146341461" y="-2.0338983050847457"/>
<point key="canvasLocation" x="-684.33382137628109" y="-2.34375"/>
</scene>
</scenes>
<resources>
<image name="background" width="1000" height="500"/>
<image name="logo" width="1000" height="500"/>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "melee-1.png",
"filename" : "image-1.png.png",
"idiom" : "universal",
"scale" : "1x"
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "melee-2.png",
"filename" : "image-2.png.png",
"idiom" : "universal",
"scale" : "1x"
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "background.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions TowerForge/TowerForge/Assets.xcassets/logo.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "logo.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "start-button.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 7 additions & 6 deletions TowerForge/TowerForge/GameWorld.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class GameWorld {
systemManager = SystemManager()
eventManager = EventManager()
selectionNode = UnitSelectionNode()

grid = Grid(eventManager: eventManager, screenSize: screenSize)
if let scene = self.scene {
grid.generateTileMap(scene: scene)
Expand Down Expand Up @@ -82,16 +83,16 @@ class GameWorld {
selectionNode.delegate = grid
scene?.addChild(selectionNode)
// Position unit selection node on the left side of the screen
selectionNode.position = CGPoint(x: selectionNode.frame.width / 2, y: scene?.frame.midY ?? 300)
selectionNode.position = CGPoint(x: 500, y: selectionNode.height / 2)

// Calculate vertical spacing between unit nodes
let verticalSpacing = selectionNode.frame.height
var verticalY = 10.0
var horizontalX = 10.0
// Position unit nodes vertically aligned
for unitNode in selectionNode.unitNodes {
unitNode.position = CGPoint(x: selectionNode.frame.width / 2,
y: verticalY)
verticalY += verticalSpacing
let horizontalSpacing = unitNode.frame.width
unitNode.position = CGPoint(x: horizontalX,
y: 0)
horizontalX += horizontalSpacing
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions TowerForge/TowerForge/Grid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SpriteKit

class Grid: UnitSelectionNodeDelegate {
let DEFAULT_NO_OF_ROWS = 8
let DEFAULT_NO_OF_ROWS = 5

private var eventManager: EventManager
private var noOfRows: Int
Expand All @@ -30,7 +30,7 @@ class Grid: UnitSelectionNodeDelegate {

func generateTileMap(scene: SKScene) {
let screenWidth = self.width
let screenHeight = self.height
let screenHeight = self.height - 200
let tileSize = CGSize(width: screenHeight / CGFloat(noOfRows), height: screenHeight / CGFloat(noOfRows))

// Calculate the number of columns needed to cover the screen width
Expand All @@ -41,7 +41,7 @@ class Grid: UnitSelectionNodeDelegate {
let node = TFSpriteNode(imageName: "road-tile", height: tileSize.height, width: tileSize.width)
node.anchorPoint = CGPoint(x: 0, y: 0)
node.position = CGPoint(x: CGFloat(CGFloat(col) * tileSize.width),
y: CGFloat(CGFloat(row) * tileSize.height))
y: CGFloat(CGFloat(row) * tileSize.height) + 200)
node.zPosition = -100
scene.addChild(node)
}
Expand All @@ -50,10 +50,10 @@ class Grid: UnitSelectionNodeDelegate {

private func snapYPosition(yPosition: Double) -> Double {
let normalizedYPosition = normalizeYPosition(yPosition: yPosition)
let screenHeight = Double(UIScreen.main.bounds.height)
let screenHeight = Double(UIScreen.main.bounds.height) - 200
let rowHeight = screenHeight / Double(noOfRows)
let rowIndex = Int(normalizedYPosition / rowHeight)
let centerY = Double(rowIndex) * rowHeight + rowHeight / 2
let centerY = (Double(rowIndex) * rowHeight + rowHeight / 2) + 200
return denormalizeYPosition(yPosition: centerY)
}

Expand Down
4 changes: 4 additions & 0 deletions TowerForge/TowerForge/Nodes/UnitSelectionNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ class UnitSelectionNode: TFSpriteNode, UnitNodeDelegate {

isUserInteractionEnabled = true
let possibleUnits: [(TFEntity & PlayerSpawnable).Type] = SpawnableEntities.playerSpawnableEntities
var startingPoint = CGPoint(x: 400, y: 0)
for type in possibleUnits {
let unitNode = UnitNode(ofType: type)
unitNode.position = startingPoint
unitNodes.append(unitNode)
unitNode.delegate = self
addChild(unitNode)

startingPoint.x += 140
}
}

Expand Down