Пример #1
0
        /// <summary>
        /// Displays the <see cref="TrayPopup"/> control if
        /// it was set.
        /// </summary>
        private void ShowTrayPopup(Point cursorPosition)
        {
            if (IsDisposed)
            {
                return;
            }

            //raise preview event no matter whether popup is currently set
            //or not (enables client to set it on demand)
            var args = RaisePreviewTrayPopupOpenEvent();

            if (args.Handled)
            {
                return;
            }

            if (TrayPopup != null)
            {
                //use absolute position, but place the popup centered above the icon
                TrayPopupResolved.Placement = PlacementMode.AbsolutePoint;
                Point position = TrayInfo.GetTrayLocation();
                TrayPopupResolved.HorizontalOffset = position.X - 20;
                TrayPopupResolved.VerticalOffset   = position.Y - 1;

                //open popup
                TrayPopupResolved.IsOpen = true;

                IntPtr handle = IntPtr.Zero;
                if (TrayPopupResolved.Child != null)
                {
                    //try to get a handle on the popup itself (via its child)
                    HwndSource source = (HwndSource)PresentationSource.FromVisual(TrayPopupResolved.Child);
                    if (source != null)
                    {
                        handle = source.Handle;
                    }
                }

                //if we don't have a handle for the popup, fall back to the message sink
                if (handle == IntPtr.Zero)
                {
                    handle = messageSink.MessageWindowHandle;
                }

                //activate either popup or message sink to track deactivation.
                //otherwise, the popup does not close if the user clicks somewhere else
                WinApi.SetForegroundWindow(handle);

                //raise attached event - item should never be null unless developers
                //changed the CustomPopup directly...
                if (TrayPopup != null)
                {
                    RaisePopupOpenedEvent(TrayPopup);
                }

                //bubble routed event
                RaiseTrayPopupOpenEvent();
            }
        }
Пример #2
0
        public ChimeHelperTray(TaskbarIcon trayIcon)
        {
            _tray             = trayIcon;
            _tray.DataContext = MEETINGS_LOADING;

            // workaround for an apparent bug in TrayIcon where the first menu appearance
            // often happens in one of the corners of the screen. Calling GetTrayLocation
            // seems to wake Windows up to the real location which is then used subsequently.
            TrayInfo.GetTrayLocation();
        }
Пример #3
0
        protected ATCTray CreateTray(string mts, string tuIdent, string tuType, string source, string destination, string presetStateCode, float height, float width, float length, float weight, string color, TrayStatus status, uint trayStacks)
        {
            TrayInfo trayInfo = new TrayInfo();

            trayInfo.LoadColor  = LoadColor(color);
            trayInfo.filename   = Tray.Mesh;
            trayInfo.Status     = status;
            trayInfo.TrayStacks = trayStacks;

            //LoadHeight includes the height of the tray (50mm)
            trayInfo.LoadHeight = height;
            trayInfo.LoadWidth  = width;
            trayInfo.LoadLength = length;
            //TODO: Weight

            //Set the dimensions of a tray
            trayInfo.length = 0.65f;
            trayInfo.width  = 0.45f;
            trayInfo.height = 0.058f; // Actual size is 0.063f but reduced so visible space can be added in stack (0.005f space)

            ATCTray trayLoad = new ATCTray(trayInfo);

            trayLoad.TUIdent         = tuIdent;
            trayLoad.TUType          = tuType;
            trayLoad.Source          = source;
            trayLoad.Destination     = destination;
            trayLoad.PresetStateCode = presetStateCode;
            trayLoad.Weight          = weight;

            //Add project fields to load
            Load.Items.Add(trayLoad);

            if (ProjectFields.Count > 0)
            {
                foreach (string field in ProjectFields)
                {
                    trayLoad.ProjectFields.Add(field, "");
                }
            }

            return(trayLoad);
        }
Пример #4
0
 public static bool UploadBattery(string code, string trayCode)
 {
     if (!Current.mes.IsOffline)
     {
         TrayInfo trayInfo = new TrayInfo
         {
             TrayCode    = trayCode,
             BarcodeNo   = code,
             ProcessCode = Current.option.CurrentProcessCode,
             UserNumber  = TengDa.WF.Current.user.Number,
             InputTime   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
         };
         string msg = string.Empty;
         if (!Tafel.MES.MES.UploadBattery(trayInfo, out msg))
         {
             Error.Alert(msg);
             return(false);
         }
     }
     return(true);
 }
Пример #5
0
        /// <summary>
        /// Shows a custom control as a tooltip in the tray location.
        /// </summary>
        /// <param name="balloon"></param>
        /// <param name="animation">An optional animation for the popup.</param>
        /// <param name="timeout">The time after which the popup is being closed.
        /// Submit null in order to keep the balloon open inde
        /// </param>
        /// <exception cref="ArgumentNullException">If <paramref name="balloon"/>
        /// is a null reference.</exception>
        public void ShowCustomBalloon(UIElement balloon, PopupAnimation animation, int?timeout)
        {
            Dispatcher dispatcher = this.GetDispatcher();

            if (!dispatcher.CheckAccess())
            {
                dispatcher.InvokeAsync(
                    (() => ShowCustomBalloon(balloon, animation, timeout)),
                    DispatcherPriority.Normal
                    );
                return;
            }

            if (balloon == null)
            {
                throw new ArgumentNullException("balloon");
            }

            if (timeout.HasValue && timeout < 500)
            {
                throw new ArgumentOutOfRangeException("timeout", string.Format("Invalid timeout of {0} milliseconds. Timeout must be at least 500 ms", timeout));
            }

            if (this.IsDisposed)
            {
                throw new ObjectDisposedException(this.Name ?? this.GetType().Name);
            }

            //make sure we don't have an open balloon
            lock (this.SyncLock)
            {
                CloseBalloon();
            }

            // create an invisible popup that hosts the UIElement
            Popup popup = new Popup
            {
                AllowsTransparency = true
            };

            //provide the popup with the taskbar icon's data context
            UpdateDataContext(popup, null, DataContext);

            //don't animate by default - devs can use attached events or override
            popup.PopupAnimation = animation;

            //in case the balloon is cleaned up through routed events, the
            //control didn't remove the balloon from its parent popup when
            //if was closed the last time - just make sure it doesn't have
            //a parent that is a popup
            var parent = LogicalTreeHelper.GetParent(balloon) as Popup;

            if (parent != null)
            {
                parent.Child = null;
            }

            if (parent != null)
            {
                string msg =
                    "Cannot display control [{0}] in a new balloon popup - that control already has a parent. You may consider creating new balloons every time you want to show one.";
                msg = String.Format(msg, balloon);
                throw new InvalidOperationException(msg);
            }

            popup.Child = balloon;

            //don't set the PlacementTarget as it causes the popup to become hidden if the
            //TaskbarIcon's parent is hidden, too...
            //popup.PlacementTarget = this;

            popup.Placement = PlacementMode.AbsolutePoint;
            popup.StaysOpen = true;

            Point position = TrayInfo.GetTrayLocation();

            position = GetDeviceCoordinates(position);
            popup.HorizontalOffset = position.X - 1;
            popup.VerticalOffset   = position.Y - 1;

            //store reference
            lock (this.SyncLock)
            {
                SetCustomBalloon(popup);
            }

            //assign this instance as an attached property
            SetParentTaskbarIcon(balloon, this);

            //fire attached event
            RaiseBalloonShowingEvent(balloon, this);

            //display item
            popup.IsOpen = true;

            if (timeout.HasValue)
            {
                //register timer to close the popup
                balloonCloseTimer.Change(timeout.Value, Timeout.Infinite);
            }
        }
Пример #6
0
        /// <summary>
        /// Shows a custom control as a tooltip in the tray location.
        /// </summary>
        /// <param name="balloon"></param>
        /// <param name="animation">An optional animation for the popup.</param>
        /// <param name="timeout">The time after which the popup is being closed.
        /// Submit null in order to keep the balloon open inde
        /// </param>
        /// <exception cref="ArgumentNullException">If <paramref name="balloon"/>
        /// is a null reference.</exception>
        public void ShowCustomBalloon(UIElement balloon, PopupAnimation animation, int?timeout)
        {
            if (!Application.Current.Dispatcher.CheckAccess())
            {
                var action = new Action(() => ShowCustomBalloon(balloon, animation, timeout));
                Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, action);
                return;
            }

            if (balloon == null)
            {
                throw new ArgumentNullException("balloon");
            }
            if (timeout.HasValue && timeout < 500)
            {
                string msg = "Invalid timeout of {0} milliseconds. Timeout must be at least 500 ms";
                msg = String.Format(msg, timeout);
                throw new ArgumentOutOfRangeException("timeout", msg);
            }

            EnsureNotDisposed();

            //make sure we don't have an open balloon
            lock (this)
            {
                CloseBalloon();
            }

            //create an invisible popup that hosts the UIElement
            Popup popup = new Popup();

            popup.AllowsTransparency = true;

            //provide the popup with the taskbar icon's data context
            UpdateDataContext(popup, null, DataContext);

            //don't animate by default - devs can use attached
            //events or override
            popup.PopupAnimation = animation;

            popup.Child = balloon;

            //don't set the PlacementTarget as it causes the popup to become hidden if the
            //TaskbarIcon's parent is hidden, too...
            //popup.PlacementTarget = this;

            popup.Placement = PlacementMode.AbsolutePoint;
            popup.StaysOpen = true;

            Point position = TrayInfo.GetTrayLocation();

            popup.HorizontalOffset = position.X - 1;
            popup.VerticalOffset   = position.Y - 1;

            //store reference
            lock (this)
            {
                SetCustomBalloon(popup);
            }

            //assign this instance as an attached property
            SetParentTaskbarIcon(balloon, this);

            //fire attached event
            RaiseBalloonShowingEvent(balloon, this);

            //display item
            popup.IsOpen = true;

            if (timeout.HasValue)
            {
                //register timer to close the popup
                balloonCloseTimer.Change(timeout.Value, Timeout.Infinite);
            }

            return;
        }
Пример #7
0
        /// <summary>
        /// Processes mouse events, which are bubbled
        /// through the class' routed events, trigger
        /// certain actions (e.g. show a popup), or
        /// both.
        /// </summary>
        /// <param name="me">Event flag.</param>
        private void OnMouseEvent(MouseEvent me)
        {
            if (IsDisposed)
            {
                return;
            }

            switch (me)
            {
            case MouseEvent.MouseMove:
                RaiseTrayMouseMoveEvent();
                //immediately return - there's nothing left to evaluate
                return;

            case MouseEvent.IconRightMouseDown:
                RaiseTrayRightMouseDownEvent();
                break;

            case MouseEvent.IconLeftMouseDown:
                RaiseTrayLeftMouseDownEvent();
                break;

            case MouseEvent.IconRightMouseUp:
                RaiseTrayRightMouseUpEvent();
                break;

            case MouseEvent.IconLeftMouseUp:
                RaiseTrayLeftMouseUpEvent();
                break;

            case MouseEvent.IconMiddleMouseDown:
                RaiseTrayMiddleMouseDownEvent();
                break;

            case MouseEvent.IconMiddleMouseUp:
                RaiseTrayMiddleMouseUpEvent();
                break;

            case MouseEvent.IconDoubleClick:
                //cancel single click timer
                singleClickTimer.Change(Timeout.Infinite, Timeout.Infinite);
                //bubble event
                RaiseTrayMouseDoubleClickEvent();
                break;

            case MouseEvent.BalloonToolTipClicked:
                RaiseTrayBalloonTipClickedEvent();
                break;

            default:
                throw new ArgumentOutOfRangeException("me", "Missing handler for mouse event flag: " + me);
            }


            //get mouse coordinates
            Point cursorPosition = new Point();

            if (messageSink.Version == NotifyIconVersion.Vista)
            {
                //physical cursor position is supported for Vista and above
                WinApi.GetPhysicalCursorPos(ref cursorPosition);
            }
            else
            {
                WinApi.GetCursorPos(ref cursorPosition);
            }

            cursorPosition = TrayInfo.GetDeviceCoordinates(cursorPosition);

            bool isLeftClickCommandInvoked = false;

            //show popup, if requested
            if (me.IsMatch(PopupActivation))
            {
                if (me == MouseEvent.IconLeftMouseUp)
                {
                    //show popup once we are sure it's not a double click
                    singleClickTimerAction = () =>
                    {
                        LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this);
                        ShowTrayPopup(cursorPosition);
                    };
                    singleClickTimer.Change(doubleClickWaitTime, Timeout.Infinite);
                    isLeftClickCommandInvoked = true;
                }
                else
                {
                    //show popup immediately
                    ShowTrayPopup(cursorPosition);
                }
            }


            //show context menu, if requested
            if (me.IsMatch(MenuActivation))
            {
                if (me == MouseEvent.IconLeftMouseUp)
                {
                    //show context menu once we are sure it's not a double click
                    singleClickTimerAction = () =>
                    {
                        LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this);
                        ShowContextMenu(cursorPosition);
                    };
                    singleClickTimer.Change(doubleClickWaitTime, Timeout.Infinite);
                    isLeftClickCommandInvoked = true;
                }
                else
                {
                    //show context menu immediately
                    ShowContextMenu(cursorPosition);
                }
            }

            //make sure the left click command is invoked on mouse clicks
            if (me == MouseEvent.IconLeftMouseUp && !isLeftClickCommandInvoked)
            {
                //show context menu once we are sure it's not a double click
                singleClickTimerAction =
                    () =>
                {
                    LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this);
                };
                singleClickTimer.Change(doubleClickWaitTime, Timeout.Infinite);
            }
        }
Пример #8
0
 public Point GetPopupTrayPosition()
 {
     return(TrayInfo.GetTrayLocation());
 }
Пример #9
0
        public static MessageToken <TipItem> ShowMessage(System.Windows.FrameworkElement balloon,
                                                         ObservableCollection <TipItem> data, int?timeout,
                                                         NotifyPosition position = NotifyPosition.ActiveScreen, PopupAnimation animation = PopupAnimation.None)
        {
            var dispatcher = balloon.Dispatcher;

            if (!dispatcher.CheckAccess())
            {
                return(dispatcher.Invoke(DispatcherPriority.Normal,
                                         (Func <MessageToken <TipItem> >)(() =>
                                                                          ShowMessage(balloon, data, timeout, position, animation))) as
                       MessageToken <TipItem>);
            }

            if (balloon == null)
            {
                throw new ArgumentNullException("balloon");
            }
            if (timeout.HasValue && timeout < 500)
            {
                var msg = "Invalid timeout of {0} milliseconds. Timeout must be at least 500 ms";
                msg = String.Format(msg, timeout);
                throw new ArgumentOutOfRangeException("timeout", msg);
            }

            if (LogicalTreeHelper.GetParent(balloon) is Popup parent)
            {
                parent.Child = null;
                var msg =
                    "Cannot display control [{0}] in a new balloon popup - that control already has a parent. You may consider creating new balloons every time you want to show one.";
                msg = String.Format(msg, balloon);
                throw new InvalidOperationException(msg);
            }

            var popup = new Popup();

            popup.AllowsTransparency = true;
            popup.PopupAnimation     = animation;
            popup.Placement          = PlacementMode.AbsolutePoint;
            popup.StaysOpen          = true;
            popup.DataContext        = data;

            Point point;

            switch (position)
            {
            case NotifyPosition.Caret:
            {
                var rect = Utils.Window.GetCurrentWindowCaretPosition();
                var X    = (rect.Left + rect.Width / 2 - balloon.ActualWidth / 2);
                var Y    = (rect.Bottom + rect.Height / 2 - balloon.ActualHeight / 2);
                if (X == 0 && Y == 0)
                {
                    goto case NotifyPosition.ActiveWindowCenter;
                }

                point = new Point(X, Y);
                break;
            }

            case NotifyPosition.ActiveWindowCenter:
            {
                var rect = Utils.Window.GetCurrentWindowRect();
                var X    = (rect.X + rect.Width / 2 - balloon.ActualWidth / 2);
                var Y    = (rect.Y + rect.Height / 2 - balloon.ActualHeight / 2);
                point = new Point(X, Y);
                break;
            }

            case NotifyPosition.ActiveScreen:
            {
                var screen = Screen.FromHandle(Utils.Window.CurrentWindowHandle);
                if (screen.Equals(Screen.PrimaryScreen))
                {
                    var p = TrayInfo.GetTrayLocation();
                    point = new Point(p.X, p.Y);
                    break;
                }

                var bounds = screen.Bounds;
                var X      = bounds.X + bounds.Width;
                var Y      = bounds.Y + bounds.Height;
                point = new Point(X, Y);
                break;
            }

            case NotifyPosition.Default:
            {
                var p = TrayInfo.GetTrayLocation();
                point = new Point(p.X, p.Y);
                break;
            }


            default:
                throw new ArgumentOutOfRangeException(nameof(position) + " not supported", position, null);
            }


            popup.Child            = balloon;
            popup.HorizontalOffset = point.X + 1;
            popup.VerticalOffset   = point.Y - 2;
            balloon.Focusable      = true;

            IInputElement element = null;

            popup.Opened += (s, a) =>
            {
                element = Keyboard.FocusedElement;
                var source = (HwndSource)PresentationSource.FromVisual(balloon);
                var handle = source.Handle;
                PInvokes.SetForegroundWindow(handle);
                Keyboard.Focus(balloon);
            };

            popup.IsOpen = true;
            popup.Focus();

            var r = new MessageToken <TipItem>(popup);

            popup.Closed += (s, a) =>
            {
                Keyboard.Focus(element);
                r.Close();
            };

            void TimerTick(object sender, EventArgs e)
            {
                r.Timer.Tick -= TimerTick;
                r.Close();
            }

            if (timeout.HasValue)
            {
                r.Timer = new DispatcherTimer {
                    Interval = TimeSpan.FromMilliseconds(timeout.Value)
                };
                r.Timer.Tick += TimerTick;
                r.Timer.Start();
            }

            return(r);
        }
Пример #10
0
 public ATCTray(TrayInfo info) : base(info)
 {
 }
Пример #11
0
    // Use this for initialization
    void Start()
    {
        //MenuManager.Instance.UIOnCampScreenPoped = true;
        //Instance = this;
        //panel.localScale = Vector2.one * 0.1f;
        //panel.DOScale(1, 0.6f).SetEase(Ease.OutBack);
        //GameManager.Instance.InResearch = true;

        _numSlotsTotal = NUM_SLOTS_PER_TRAYS * traysHorizontalLayouts.Length;
        _slots         = new List <ResearchSlotInterface>(_numSlotsTotal);

        //btnClose.onClick.AddListener(Btn_Close);

        //Read global research tray costs / booster multipliers / base costs:
        int trayLimit = GlobalProps.RESEARCH_TRAY_LIMIT.GetInt();
        int slotLimit = GlobalProps.RESEARCH_SLOT_LIMIT.GetInt();

        _trayCosts = new TrayInfo[trayLimit];
        string[] costUnlock = GlobalProps.RESEARCH_UNLOCK_COST.GetString().Split("\n");
        string[] costBoosts = GlobalProps.RESEARCH_BOOSTER_BASE.GetString().Split("\n");
        string[] costMultis = GlobalProps.RESEARCH_BOOSTER_MULTIPLIER.GetString().Split("\n");


        for (int t = 0; t < _trayCosts.Length; t++)
        {
            var trayInfo = _trayCosts[t] = new TrayInfo();
            trayInfo.costToBoostBase       = CurrencyManager.ParseToCost(costBoosts[t]);
            trayInfo.costToBoostMultiplier = float.Parse(costMultis[t]);
            trayInfo.costToUnlock          = new CurrencyManager.Cost[slotLimit];
            string[] costUnlockSplit = costUnlock[t].Split("=");

            if (costUnlockSplit.Length != 2)
            {
                Debug.LogError("Error parsing the GlobalProps.RESEARCH_UNLOCK_COST from JSON data.");
                continue;
            }

            CurrencyTypes type = costUnlockSplit[0].AsEnum <CurrencyTypes>();
            string[]      costUnlockPerSlot = costUnlockSplit[1].Split(",");

            if (costUnlockPerSlot.Length != slotLimit)
            {
                Debug.LogError("Incorrect # of values for {0} required to unlock slots, found {1}, should be {2}".Format2(type, costUnlockPerSlot.Length, slotLimit));
                continue;
            }

            for (int s = 0; s < slotLimit; s++)
            {
                int amount = int.Parse(costUnlockPerSlot[s]);
                trayInfo.costToUnlock[s] = new CurrencyManager.Cost(type, amount);
                //trace(trayInfo.costToUnlock[s].ToJSONString());
            }

            //CurrencyManager.ParseToCost(costUnlock[t]);
        }
        //DataManager.globals.GetGlobalAsString(GlobalProps.);

        //Create the actual Slot UI game-objects:
        InitSlots();

        GameAPIManager.API.Research.GetAllSlots()
        .Then(jsonSlots => {
            //Now assign their states from the Server's data:
            foreach (JSONNode jsonSlot in jsonSlots)
            {
                var jsonSlotGame = jsonSlot["game"];
                int trayID       = jsonSlotGame["trayID"].AsInt;
                int slotID       = jsonSlotGame["slotID"].AsInt;
                var slot         = GetSlotAt(trayID, slotID);

                if (slot == null)
                {
                    Debug.LogError("Cannot get <ResearchSlotInterface> at trayID {0}, slotID {1}".Format2(trayID, slotID));
                    continue;
                }

                GameAPIManager.API.Research.ProcessSlotData(slot, jsonSlotGame);
            }
        });
    }