Example #1
0
 public Task<IVendorSearchItem[]> FindVendorItemsAsync( SearchCriteria criteria, int page = 0 )
 {
     return new Task<IVendorSearchItem[]>( () =>
         {
             return FindVendorItems( criteria, page );
         } );
 }
Example #2
0
 public IVendorSearchItem[] FindVendorItems( SearchCriteria criteria, int page = 0 )
 {
     lock ( m_SyncRoot )
     {
         return m_WorldVendorItemsCache
             .Where( vi => vi.Valid && criteria.Matches( vi ) )
             .OrderBy( vi => vi.Price )
             .Skip( MaxResults * page )
             .Take( MaxResults )
             .ToArray();
     }
 }
Example #3
0
        public static SearchCriteria GetSearchCriteriaForPlayer(Mobile m)
        {
            SearchCriteria criteria;

            if (m_PlayerCriteria.ContainsKey(m))
                criteria = m_PlayerCriteria[m];
            else
                criteria = m_PlayerCriteria[m] = new SearchCriteria();

            return criteria;
        }
        public VendorSearchResultsGump( IVendorSearchItem[] items, SearchCriteria criteria, int page )
            : base(30, 30)
        {
            m_Items = items;
            m_Criteria = criteria;
            m_Page = page;

            int pageIndex = 0;

            AddPage( pageIndex++ );

            AddBackground( 0, 0, 500, 550, 0x7748 );
            AddHtmlLocalized( 50, 50, 400, 18, 1154509, 0x4BBD, false, false ); // <center>Vendor Search Results</center>

            AddHtmlLocalized( 162, 70, 102, 18, 1114513, "#1062218", 0x4BBD, false, false ); // <DIV ALIGN=CENTER>Price</DIV>
            AddHtmlLocalized( 274, 70, 61, 18, 1114513, "#1154644", 0x4BBD, false, false ); // <DIV ALIGN=CENTER>Facet</DIV>
            AddHtmlLocalized( 345, 70, 102, 18, 1114513, "#1154642", 0x4BBD, false, false ); // <DIV ALIGN=CENTER>Create Map</DIV>

            int yOffset = 0;

            for ( int i = 0; i < m_Items.Length; i++ )
            {
                IVendorSearchItem item = m_Items[i];

                if ( ( i % ResultsPerPage ) == 0 )
                {
                    AddPage( pageIndex );

                    if ( pageIndex > 1 )
                    {
                        AddButton( 50, 480, 0x7745, 0x7745, 0, GumpButtonType.Page, pageIndex - 1 );
                        AddHtmlLocalized( 90, 480, 255, 20, 1044044, 0x4BBD, false, false ); // PREV PAGE
                    }

                    bool thereAreMorePages = ( i + ResultsPerPage < m_Items.Length );

                    if ( thereAreMorePages )
                    {
                        AddButton( 430, 480, 0x7745, 0x7745, 0, GumpButtonType.Page, pageIndex + 1 );
                        AddHtmlLocalized( 355, 480, 70, 20, 1114514, "#1044045", 0x4BBD, false, false ); // <DIV ALIGN=RIGHT>NEXT PAGE</DIV>
                    }

                    pageIndex++;
                    yOffset = 0;
                }

                AddButtonTileArt( 50, 101 + yOffset, 0x918, 0x918, GumpButtonType.Page, 0, 0, item.Item.ItemID, item.Item.Hue, 18, 12 );
                AddItemPropertyTooltip( item.Item );

                AddHtmlLocalized( 162, 101 + yOffset, 102, 72, item.IsContained ? 1154598 : 1154645, item.Price.ToString( "N0" ), 0x6B55, false, false ); // <center>Container Price<BR>~1_cost~</center> / <center>~1_val~</center>
                AddHtmlLocalized( 274, 101 + yOffset, 102, 72, item.Item.Map.GetNameCliloc(), 0x6B55, false, false );
                AddButton( 386, 106 + yOffset, 0x7745, 0x7745, 100 + i, GumpButtonType.Reply, 0 );

                yOffset += 74;
            }

            if ( m_Items.Length == VendorItemFinder.MaxResults )
            {
                AddButton( 430, 480, 0x7745, 0x7745, 2, GumpButtonType.Reply, 0 );
                AddHtmlLocalized( 225, 480, 200, 20, 1114514, "#1154687", 0x4BBD, false, false ); // <DIV ALIGN=RIGHT>~1_TOKEN~</DIV>
            }
        }
        public VendorSearchQueryGump( Mobile m, SearchCriteria criteria, int feedback = -1 )
            : base(10, 10)
        {
            m_Mobile = m;
            m_Criteria = criteria;
            m_SelectedCriteria = criteria.GetSelectedCriteria().ToArray();

            AddPage( 0 );

            AddBackground( 0, 0, 780, 550, 0x7752 );
            AddBackground( 10, 50, 246, 22, 0x2486 );

            AddHtmlLocalized( 10, 10, 760, 18, 1114513, "#1154508", 0x4BBD, false, false ); // <DIV ALIGN=CENTER><center>Vendor Search Query</center></DIV>

            AddHtmlLocalized( 522, 30, 246, 18, 1154546, 0x4BBD, false, false ); // Selected Search Criteria

            int yOffset = 0;

            if ( m_Criteria.HasName )
            {
                AddHtmlLocalized( 562, 50 + ( yOffset * 22 ), 246, 18, 1154510, 0x6B55, false, false ); // Item Name
                AddButton( 522, 50 + ( yOffset * 22 ), 0xFB1, 0xFB2, 4, GumpButtonType.Reply, 0 );
                AddTooltip( 1154694 ); // Remove Selected Search Criteria
                yOffset++;
            }

            if ( m_Criteria.HasPrice )
            {
                AddHtmlLocalized( 562, 50 + ( yOffset * 22 ), 246, 18, 1154512, string.Format( "{0}\t{1}", m_Criteria.MinPrice.ToString( "N0" ), m_Criteria.MaxPrice.ToString( "N0" ) ), 0x6B55, false, false ); // Price Range (~1_INT~ to ~2_INT~)
                AddButton( 522, 50 + ( yOffset * 22 ), 0xFB1, 0xFB2, 5, GumpButtonType.Reply, 0 );
                AddTooltip( 1154694 ); // Remove Selected Search Criteria
                yOffset++;
            }

            for ( int i = 0; i < m_SelectedCriteria.Length; i++ )
            {
                SearchCriterion sc = m_SelectedCriteria[i];

                string args = sc.LabelArgs;

                if ( args == null )
                    AddHtmlLocalized( 562, 50 + ( yOffset * 22 ), 246, 18, sc.LabelNumber, 0x6B55, false, false );
                else
                    AddHtmlLocalized( 562, 50 + ( yOffset * 22 ), 246, 18, sc.LabelNumber, args, 0x6B55, false, false );

                AddButton( 522, 50 + ( yOffset * 22 ), 0xFB1, 0xFB2, 50 + i, GumpButtonType.Reply, 0 );
                AddTooltip( 1154694 ); // Remove Selected Search Criteria

                yOffset++;
            }

            AddHtmlLocalized( 10, 30, 246, 18, 1154510, 0x4BBD, false, false ); // Item Name
            AddTextEntry( 12, 52, 242, 18, 0x9C2, 1, m_Criteria.Name, 25 );

            string priceArgs = String.Format( "{0}\t{1}", m_Criteria.MinPrice.ToString( "N0" ), m_Criteria.MaxPrice.ToString( "N0" ) );
            AddButton( 10, 74, 0x7745, 0x7745, 0, GumpButtonType.Page, 2 );
            AddHtmlLocalized( 50, 74, 206, 20, 1154512, priceArgs, 0x4BBD, false, false ); // Price Range (~1_INT~ to ~2_INT~)

            var categories = SearchCriteriaCategory.AllCategories;

            for ( int i = 0; i < categories.Length; i++ )
            {
                SearchCriteriaCategory category = categories[i];

                AddButton( 10, 96 + ( i * 22 ), 0x7745, 0x7745, 0, GumpButtonType.Page, i + 3 );
                AddHtmlLocalized( 50, 96 + ( i * 22 ), 206, 20, category.Cliloc, 0x4BBD, false, false );
            }

            if ( feedback != -1 )
                AddHtmlLocalized( 110, 520, 660, 20, feedback, 0x7C00, false, false );

            AddButton( 10, 520, 0x7747, 0x7747, 0, GumpButtonType.Reply, 0 );
            AddHtmlLocalized( 50, 520, 50, 20, 1150300, 0x4BBD, false, false ); // CANCEL

            AddButton( 740, 520, 0x7746, 0x7746, 1, GumpButtonType.Reply, 0 );
            AddHtmlLocalized( 630, 520, 100, 20, 1114514, "#1154641", 0x4BBD, false, false ); // <DIV ALIGN=RIGHT>Search</DIV>

            AddButton( 740, 500, 0x7745, 0x7745, 2, GumpButtonType.Reply, 0 );
            AddHtmlLocalized( 630, 500, 100, 20, 1114514, "#1154588", 0x4BBD, false, false ); // <DIV ALIGN=RIGHT>Clear Search Criteria</DIV>

            AddPage( 2 );

            AddHtmlLocalized( 266, 30, 246, 18, 1154532, 0x4BBD, false, false ); // Minimum Price
            AddBackground( 266, 50, 246, 22, 0x2486 );
            AddTextEntry( 268, 52, 242, 18, 0x9C2, 2, m_Criteria.MinPrice.ToString(), 10 );

            AddHtmlLocalized( 266, 74, 246, 18, 1154533, 0x4BBD, false, false ); // Maximum Price
            AddBackground( 266, 94, 246, 22, 0x2486 );
            AddTextEntry( 268, 96, 242, 18, 0x9C2, 3, m_Criteria.MaxPrice.ToString(), 10 );

            AddButton( 266, 118, 0xFAB, 0xFAC, 3, GumpButtonType.Reply, 0 );
            AddHtmlLocalized( 306, 118, 100, 272, 1154534, 0x4BBD, false, false ); // Add Search Criteria

            for ( int i = 0; i < categories.Length; i++ )
            {
                SearchCriteriaCategory category = categories[i];

                int categoryIdx = 100 * ( i + 1 );

                AddPage( i + 3 );
                AddHtmlLocalized( 266, 30, 246, 18, category.Cliloc, 0x4BBD, false, false );

                for ( int j = 0; j < category.Criteria.Length; j++ )
                {
                    SearchCriterionEntry criterion = category.Criteria[j];
                    int criterionIdx = categoryIdx + j;

                    AddButton( 266, 50 + ( j * 22 ), 0x7745, 0x7745, criterionIdx, GumpButtonType.Reply, 0 );
                    AddHtmlLocalized( 306, 50 + ( j * 22 ), 246, 18, criterion.Cliloc, 0x4BBD, false, false );

                    string value = m_Criteria.GetSelectedValue( criterion.Criterion );

                    if ( value != null )
                    {
                        AddBackground( 482, 50 + ( j * 22 ), 30, 20, 0x2486 );
                        AddTextEntry( 484, 52 + ( j * 22 ), 26, 16, 0x9C2, criterionIdx, value, 3 );
                    }
                }
            }
        }
        public static void StartSearch( Mobile from, SearchCriteria criteria, int page )
        {
            if ( !IsInValidRegion( from ) )
            {
                // Before using vendor search, you must be in a justice region or a safe log-out location (such as an inn or a house which has you on its Owner, Co-owner, or Friends list).
                from.SendLocalizedMessage( 1154680 );
                return;
            }

            var resultsTask = VendorItemFinder.Instance.FindVendorItemsAsync( criteria, page );

            var pollingTimer = new TaskPollingTimer<IVendorSearchItem[]>( resultsTask, ( results ) =>
            {
                from.CloseGump( typeof( VendorSearchQueryGump ) );
                from.CloseGump( typeof( VendorSearchResultsGump ) );
                from.CloseGump( typeof( VendorSearchWaitGump ) );

                if ( results.Any() )
                {
                    from.SendGump( new VendorSearchQueryGump( from, criteria ) );
                    from.SendGump( new VendorSearchResultsGump( results, criteria, page ) );
                }
                else
                {
                    from.SendGump( new VendorSearchQueryGump( from, criteria, 1154587 ) ); // No items matched your search.
                }
            } );

            resultsTask.Start();
            pollingTimer.Start();

            from.SendGump( new VendorSearchWaitGump( pollingTimer ) );
        }