Exemplo n.º 1
0
        private static CallbackResult OnObjectPicker(byte[] data, CallbackResult prevResult)
        {
            lock (syncRoot) {
                if (CurrentState == State.WaitMenu)
                {
                    Debug.Assert(waitQueue != null && waitQueue.Count > 0, "Empty waitQueue.");
                    Debug.Assert(waitQueue.Peek().IsMenu, "Target in top of the queue instead of menu.");

                    Menu          packet = new Menu(data);
                    WaitQuery     query  = waitQueue.Dequeue();
                    MenuSelection menu   = query.Menu;

                    if (packet.Title.ToLowerInvariant().Contains(menu.Name.ToLowerInvariant()))
                    {
                        // Cancel menu
                        if (menu.Option == null)
                        {
                            byte[] selectedData = PacketBuilder.ObjectPicked(packet.DialogSerial, packet.MenuSerial, 0, 0, 0);
                            Core.SendToServer(selectedData);

                            FinishWork();
                            query.Finish(RequestState.Completed);
                            return(CallbackResult.Eat);
                        }

                        // Select option
                        string option = menu.Option.ToLowerInvariant();
                        for (int i = 0; i < packet.Options.Count; i++)
                        {
                            if (packet.Options[i].Text.ToLowerInvariant().Contains(option))
                            {
                                byte[] selectedData = PacketBuilder.ObjectPicked(packet.DialogSerial, packet.MenuSerial, (ushort)(i + 1), packet.Options[i].Artwork, packet.Options[i].Hue);
                                Core.SendToServer(selectedData);

                                FinishWork();
                                query.Finish(RequestState.Completed);
                                return(CallbackResult.Eat);
                            }
                        }

                        Trace.WriteLine("Unable to find requested option. Menu passed to client.", "UIManager");
                    }
                    else
                    {
                        Trace.WriteLine("Unexpected menu received. Menu passed to client.", "UIManager");
                    }

                    query.Finish(RequestState.Failed);
                    FinishWork();
                }

                if (CurrentState != State.Ready)
                {
                    Reset();
                }

                return(CallbackResult.Normal);
            }
        }
Exemplo n.º 2
0
        public static IRequestResult WaitMenu(params string[] menus)
        {
            if (menus.Length > 0) {
                MenuSelection[] menuList = new MenuSelection[menus.Length / 2 + menus.Length % 2];

                for (int i = 0; i < menuList.Length; i++) {
                    menuList[i].Name = menus[i * 2];

                    if (i * 2 + 1 < menus.Length)
                        menuList[i].Option = menus[i * 2 + 1];
                }

                return UIManager.WaitForMenu(menuList);
            }
            else {
                ScriptErrorException.Throw("Invalid number of parameters.");
                return UIManager.FailedResult;
            }
        }
Exemplo n.º 3
0
        public static IRequestResult WaitMenu(params string[] menus)
        {
            if (menus.Length > 0)
            {
                MenuSelection[] menuList = new MenuSelection[menus.Length / 2 + menus.Length % 2];

                for (int i = 0; i < menuList.Length; i++)
                {
                    menuList[i].Name = menus[i * 2];

                    if (i * 2 + 1 < menus.Length)
                    {
                        menuList[i].Option = menus[i * 2 + 1];
                    }
                }

                return(UIManager.WaitForMenu(menuList));
            }
            else
            {
                ScriptErrorException.Throw("Invalid number of parameters.");
                return(UIManager.FailedResult);
            }
        }
Exemplo n.º 4
0
 public WaitQuery(MenuSelection menu)
 {
     ThreadId = Thread.CurrentThread.ManagedThreadId;
     Target   = null;
     Menu     = menu;
 }
Exemplo n.º 5
0
 public WaitQuery(IClientTarget target)
 {
     ThreadId = Thread.CurrentThread.ManagedThreadId;
     Target   = target;
     Menu     = new MenuSelection();
 }
Exemplo n.º 6
0
 public WaitQuery(MenuSelection menu)
 {
     ThreadId = Thread.CurrentThread.ManagedThreadId;
     Target = null;
     Menu = menu;
 }
Exemplo n.º 7
0
 public WaitQuery(IClientTarget target)
 {
     ThreadId = Thread.CurrentThread.ManagedThreadId;
     Target = target;
     Menu = new MenuSelection();
 }