-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from npackard/main
improvements to arrangement UI/logic, can now replace items w/ items from hotbar
- Loading branch information
Showing
6 changed files
with
174 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
2 changes: 1 addition & 1 deletion
2
Assets/UiItemController.cs.meta → ...deGame/Code/UIBoardItemController.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using UnityEngine.EventSystems; | ||
using UnityEngine.UI; | ||
|
||
public class UiInvItemController : MonoBehaviour, IPointerDownHandler, IPointerUpHandler | ||
{ | ||
public ArrangementController ac; // I realize this is jank, will polish later | ||
|
||
public Texture2D normalCursor; | ||
public Texture2D grabbyCursor; | ||
|
||
public Vector2 grabbyOffset = Vector2.zero; | ||
|
||
public int invIndex; | ||
|
||
// Start is called before the first frame update | ||
void Start() | ||
{ | ||
Cursor.SetCursor(normalCursor, Vector2.zero, CursorMode.Auto); | ||
} | ||
|
||
// Update is called once per frame | ||
void Update() | ||
{ | ||
|
||
} | ||
|
||
public void OnPointerDown(PointerEventData pointerEventData) { | ||
Cursor.SetCursor(grabbyCursor, grabbyOffset, CursorMode.Auto); | ||
} | ||
|
||
public void OnPointerUp(PointerEventData pointerEventData) { | ||
Cursor.SetCursor(normalCursor, Vector2.zero, CursorMode.Auto); | ||
Vector2 mouseCoords = Input.mousePosition; | ||
Vector2 boardLoc = FindTileLocation(mouseCoords); | ||
bool success = ac.UpdateBoard(boardLoc, invIndex, this.gameObject.GetComponent<Image>()); | ||
} | ||
|
||
private Vector2 FindTileLocation(Vector2 mouseCoords) { | ||
float relativeX = mouseCoords[0]; | ||
float relativeY = mouseCoords[1]; | ||
Vector2 boardPos = new Vector2(-1, -1); | ||
// first, make sure on board | ||
if (relativeX < Screen.width / 3 || relativeX > 2 * Screen.width / 3 || relativeY < .314 * Screen.height || relativeY > .87 * Screen.height) { | ||
return boardPos; | ||
} | ||
// find col | ||
if (relativeX < .45 * Screen.width) { | ||
boardPos = new Vector2(boardPos[0], 0); | ||
} else if (relativeX < .55 * Screen.width) { | ||
boardPos = new Vector2(boardPos[0], 1); | ||
} else if (relativeX < .65 * Screen.width) { | ||
boardPos = new Vector2(boardPos[0], 2); | ||
} else { | ||
boardPos = new Vector2(boardPos[0], -1); | ||
Debug.Log("you broke it. good job."); | ||
} | ||
// find row | ||
if (relativeY < Screen.height / 2) { | ||
boardPos = new Vector2(2, boardPos[1]); | ||
} else if (relativeY < .68 * Screen.height) { | ||
boardPos = new Vector2(1, boardPos[1]); | ||
} else if (relativeY < .86 * Screen.height) { | ||
boardPos = new Vector2(0, boardPos[1]); | ||
} else { | ||
boardPos = new Vector2(-1, boardPos[1]); | ||
Debug.Log("wow. you still broke it. i feel attacked."); | ||
} | ||
return boardPos; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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