void RemoveNodeConnections(GameObject node, UserAction.Action action) { if (node.GetComponent <Node>().userValue > 0) { if (action != null) { action.removedOther = true; action.otherPosition = node.GetComponent <Node>().position; action.otherValue = node.GetComponent <Node>().userValue; action.otherHinted = node.GetComponent <Node>().hinted; } if (node.GetComponent <Node>().userValue == 1 || node.GetComponent <Node>().userValue == gameBoardAnswer.Count) { GetComponent <Appearance>().DestroyCircleByValue(node.GetComponent <Node>().userValue); } if (node.GetComponent <Node>().nextNode != null) { node.GetComponent <Node>().line.transform.position = new Vector3(10000, 10000, 0); node.GetComponent <Node>().nextNode = null; } if (node.GetComponent <Node>().previousNode != null) { node.GetComponent <Node>().previousNode.GetComponent <Node>().line.transform.position = new Vector3(10000, 10000, 0); node.GetComponent <Node>().previousNode.GetComponent <Node>().nextNode = null; } if (node.GetComponent <Node>().hinted == 1 && hintedNumbers.ContainsKey(node.GetComponent <Node>().value)) { hintedNumbers.Remove(node.GetComponent <Node>().value); } userPlacedNodes.Remove(node.GetComponent <Node>().userValue); } }
public static void LogAction(User user, UserAction.Action eventAction, string info) { var freshUser = GetUser(user.UserId); var action = new UserAction { Time = DateTime.Now, Event = eventAction, Description = info }; freshUser.Actions.Add(action); using (var sf = SessionFactory) { using (var session = sf.OpenSession()) { using (var trans = session.BeginTransaction()) { session.SaveOrUpdate(action); if (!NHibernateUtil.IsInitialized(freshUser.Actions)) { NHibernateUtil.Initialize(freshUser.Actions); } session.SaveOrUpdate(freshUser); trans.Commit(); } } } }
void CheckIfNodePlacedSomewhereElse(UserAction.Action action, int value) { if (userPlacedNodes.ContainsKey(value)) { GameObject node = userPlacedNodes[value]; if (action != null) { if (!action.removedOther) { action.removedOther = true; action.otherPosition = node.GetComponent <Node>().position; action.otherValue = node.GetComponent <Node>().userValue; action.otherHinted = node.GetComponent <Node>().hinted; } else { action.removedOtherOther = true; action.otherOtherPosition = node.GetComponent <Node>().position; action.otherOtherValue = node.GetComponent <Node>().userValue; action.otherOtherHinted = node.GetComponent <Node>().hinted; } } if (node.GetComponent <Node>().userValue == 1 || node.GetComponent <Node>().userValue == gameBoardAnswer.Count) { GetComponent <Appearance>().DestroyCircleByValue(node.GetComponent <Node>().userValue); } if (node.GetComponent <Node>().nextNode != null) { node.GetComponent <Node>().line.transform.position = new Vector3(10000, 10000, 0); node.GetComponent <Node>().nextNode = null; } if (node.GetComponent <Node>().previousNode != null) { node.GetComponent <Node>().previousNode.GetComponent <Node>().line.transform.position = new Vector3(10000, 10000, 0); node.GetComponent <Node>().previousNode.GetComponent <Node>().nextNode = null; } if (node.GetComponent <Node>().hinted == 1 && hintedNumbers.ContainsKey(node.GetComponent <Node>().value)) { hintedNumbers.Remove(node.GetComponent <Node>().value); } node.GetComponent <Node>().userValue = -1; SaveByIndex(node.GetComponent <Node>().value - 1); GetComponent <Appearance>().SetNodeToEmptyLook(node); userPlacedNodes.Remove(value); RecheckNeighborConnections(node); } }
void AddNode(GameObject node, int value, bool saveAction, int hinted) { Vector2 nodePosition = node.GetComponent <Node>().position; UserAction.Action action = new UserAction.Action { added = true, position = nodePosition, value = value, hinted = hinted }; if (!saveAction) { action = null; } if (hinted == 1 && !hintedNumbers.ContainsKey(node.GetComponent <Node>().value)) { hintedNumbers.Add(node.GetComponent <Node>().value, node); } RemoveNodeConnections(node, action); node.GetComponent <Node>().hinted = hinted; node.GetComponent <Node>().userValue = value; SaveByIndex(node.GetComponent <Node>().value - 1); GetComponent <Appearance>().SetNodeToUserPlacedLook(node); CheckIfNodePlacedSomewhereElse(action, value); GetComponent <UserAction>().AddAction(action); undoButton.GetComponent <Button>().interactable |= GetComponent <UserAction>().HaveActions(); userPlacedNodes.Add(value, node); AddLineToNeighbors(nodePosition, node); if (value == 1 || value == gameBoardAnswer.Count) { GetComponent <Appearance>().CreateStartEndCircle(node); } if (CheckIfWon()) { bool newBest; won = true; GetComponent <Timer>().GameFinished(); GetComponent <Menus>().WinMenuOpen(); newBest = GetComponent <PlayerPrefsManager>().SaveStats(); GetComponent <CongratsScreenManager>().SetUpGameWonScreen(newBest); GetComponent <Appearance>().MakeNodeHighlightClear(true); GetComponent <HapticFeedback>().SuccessTapticFeedback(); GetComponent <SoundManager>().PlayWinSound(); } }
void RemoveNode(GameObject node, bool saveAction) { UserAction.Action action = new UserAction.Action { added = false, position = node.GetComponent <Node>().position, value = node.GetComponent <Node>().userValue, hinted = node.GetComponent <Node>().hinted }; if (saveAction) { GetComponent <UserAction>().AddAction(action); undoButton.GetComponent <Button>().interactable |= GetComponent <UserAction>().HaveActions(); } RemoveNodeConnections(node, null); node.GetComponent <Node>().userValue = -1; SaveByIndex(node.GetComponent <Node>().value - 1); GetComponent <Appearance>().SetNodeToEmptyLook(node); }
public void Undo() { if (!won) { UserAction.Action action = GetComponent <UserAction>().PopAction(); if (action != null) { GameObject node = gameBoardPositions[action.position]; if (action.added) { int userValue = node.GetComponent <Node>().userValue; userPlacedNodes.Remove(node.GetComponent <Node>().userValue); RemoveNodeConnections(node, null); node.GetComponent <Node>().userValue = -1; SaveByIndex(node.GetComponent <Node>().value - 1); GetComponent <Appearance>().SetNodeToEmptyLook(node); if (action.removedOther) { GameObject otherNode = gameBoardPositions[action.otherPosition]; AddNode(otherNode, action.otherValue, false, action.otherHinted); } if (action.removedOtherOther) { GameObject otherNode = gameBoardPositions[action.otherOtherPosition]; AddNode(otherNode, action.otherOtherValue, false, action.otherOtherHinted); } GetComponent <NumberScroller>().HighlightNumber(userValue); } else { AddNode(node, action.value, false, action.hinted); } RecheckNeighborConnections(node); GetComponent <SoundManager>().Undo(); } undoButton.GetComponent <Button>().interactable &= GetComponent <UserAction>().HaveActions(); GetComponent <HapticFeedback>().SelectTapticFeedback(); } }
public ModifyUserForm(UserAction.Action action = Backend.Objects.UserAction.Action.CreateUser) { InitializeComponent(); WindowState = FormWindowState.Maximized; UserAction = action; switch (action) { case Backend.Objects.UserAction.Action.ModifyUser: if (GlobalStorage.CurrentUser.CanRemoveUsers() && BaseUser != null && BaseUser.UserId != GlobalStorage.CurrentUser.UserId) { //Remove user menu item var removeUserItem = new AppBarMenuTextItem(translationHelper1.GetTranslation("edit_user_delete")); removeUserItem.Click += (s, e) => { if (BaseUser != null) { Extensions.RunInAnotherThread(() => { DataManager.RemoveUser(BaseUser.UserId); this.InvokeIfRequired(Close); }); } }; appBar1.MenuItems.Add(removeUserItem); } translationHelper1.SetTranslationLocation(metroButton1, "edit_user_okbutton"); break; } translationHelper1.Translate(this); InitializePermissions(checkedListBox1); checkedListBox1.CheckOnClick = true; }