void Start() { SetLockersInBlackSmith(); InitStartScales(); envanter = paper.transform.GetChild(6).gameObject; scrollBar = paper.transform.GetChild(8).gameObject; greenBoxParent = paper.transform.GetChild(5).gameObject; diffSlots = paper.transform.GetChild(4).gameObject; lsi = new LastSelectedItem(); slot = envanter.GetComponent <Slot>(); itemList = GameController.Instance.itemList; ps = player.GetComponent <PlayerState>(); categoryIndex = 0; }
void Start() { if (!GameController.Instance.firstGameOpen) { hints.SetActive(false); } SetLockersInWeaponry(); InitStartScales(); envanter = paper.transform.GetChild(6).gameObject; scrollBar = paper.transform.GetChild(8).gameObject; greenBoxParent = paper.transform.GetChild(5).gameObject; diffSlots = paper.transform.GetChild(4).gameObject; lsi = new LastSelectedItem(); slot = envanter.GetComponent <Slot>(); itemList = GameController.Instance.itemList; ps = player.GetComponent <PlayerState>(); categoryIndex = 0; }
/// <summary> /// Event fired as the user first presses down. /// Starts the press and hold timer /// </summary> /// <param name="sender">Source of the event.</param> /// <param name="e">Event arguments.</param> private void OnOwnerManipulationStarted(object sender, ManipulationStartedEventArgs e) { double animationOrigin = 0.5; menuPositionChanged = false; // Because the Loaded and Layout are not reliable. // Those events are not garenteed to happen before the first manipulation InitializePopup(); fingerPosition = e.ManipulationContainer.TransformToVisual(RootVisual).Transform(e.ManipulationOrigin); // Calculate animation origin in X coord animationOrigin = fingerPosition.X / RootVisual.ActualWidth; FrameworkElement newSelectedItem = null; int newSelectedIndex = -1; var listBox = Owner as ListBox; if (listBox == null) { // For non-listbox controls // Assign last selected item as the owner newSelectedItem = Owner; } else { // For listbox, use the VisualTreeHelper to look for the ListBoxItem // that is at the point of the gesture var listBoxItems = VisualTreeHelper.FindElementsInHostCoordinates( listBox.TransformToVisual(RootVisual).Transform(e.ManipulationOrigin) , listBox).OfType <ListBoxItem>(); if (listBoxItems.Count() > 0) { newSelectedItem = listBoxItems.First(); // Save the index for the listbox newSelectedIndex = listBox.ItemContainerGenerator .IndexFromContainer(newSelectedItem); } } // use Owner's data context as data context: allows binding context menu props to SelectedItem's context if (newSelectedItem != null) { DataContext = newSelectedItem.DataContext; } // Ability to disable the context menu if (!IsEnabled || Visibility == Visibility.Collapsed) { DataContext = null; return; } LastSelectedItem = newSelectedItem; LastSelectedIndex = newSelectedIndex; if (LastSelectedItem != null) { // Get the position on RootVisual coordinate var top = LastSelectedItem.TransformToVisual(RootVisual).Transform(new Point(0, 0)).Y; menuPosition = LastSelectedItem.ActualHeight + top; // Now make sure the menu fits on screen. // If it is too low, put it above the finger instead of below it // Caution: menuheight is set thru SizeChanged event handler, // which occurs only after OnApplyTemplate or LayoutUpdated // so the first attempt to open the context menu might have value 0 if (menuPosition + menuHeight > PageHeight) { menuPosition -= LastSelectedItem.ActualHeight; menuPositionChanged = true; } ExecuteAftertemplateApplied(() => { CalculateMenuHeight(); Point renderTransformOrigin = menuContainer.RenderTransformOrigin; renderTransformOrigin.X = animationOrigin; renderTransformOrigin.Y = menuPositionChanged ? 1.0 : 0.0; menuContainer.RenderTransformOrigin = renderTransformOrigin; var heightAnim = menuContainer.FindName("heightAnim") as DiscreteObjectKeyFrame; if (heightAnim != null) { heightAnim.Value = menuHeight; } var yScaleStart = menuContainer.FindName("YScaleStart") as EasingDoubleKeyFrame; if (yScaleStart != null) { yScaleStart.Value = 1 / menuHeight; } var positionAnimY1 = menuContainer.FindName("PositionAnimY1") as DiscreteObjectKeyFrame; var positionAnimY2 = menuContainer.FindName("PositionAnimY2") as DiscreteObjectKeyFrame; if (positionAnimY1 != null) { positionAnimY1.Value = 0; } if (positionAnimY2 != null) { positionAnimY2.Value = 0; } if (menuPositionChanged) { if (positionAnimY1 != null) { positionAnimY1.Value = 0; } if (positionAnimY2 != null) { positionAnimY2.Value = -menuHeight; } } }); // Start the timer - if only suitable visual element found tapAndHoldTimer.Start(); } }
void Start() { ps = player.GetComponent <PlayerState>(); lsi = new LastSelectedItem(); itemList = GameController.Instance.itemList; }