Esempio n. 1
0
        /// <summary>
        /// Crop a region from the window picture.
        /// </summary>
        /// <param name="region">Window to crop.</param>
        public Bitmap GetRegionBitmap(WindowRegion region)
        {
            //If the region doesn't belong to this window, abort
            if (!_VirtualWindow.Regions.Contains(region))
            {
                return(null);
            }

            //Get the window picture
            Bitmap window = GetWindowBitmap();

            //If the picture is null, abort
            if (window == null)
            {
                return(null);
            }

            //Get the region's absolute rectangle for the window
            Rectangle regionRect = region.GetAbsoluteRect(window.Width, window.Height);

            //Create region bitmap
            Bitmap regionBitmap = new Bitmap(regionRect.Width, regionRect.Height);

            //Use FastBitmapLib
            using (var fastBmp = regionBitmap.FastLock())
            {
                //Copy the region from the window to the region bitmap
                fastBmp.CopyRegion(window, regionRect, new Rectangle(0, 0, regionBitmap.Width, regionBitmap.Height));
            }

            return(regionBitmap);
        }
Esempio n. 2
0
        public static async Task <string[]> GetAllChampions()
        {
            GraphicalWindow gWindow = Window.GraphicsWindow;

            string[] finalChampions = new string[10];

            Stopwatch sw = Stopwatch.StartNew();

            //Join the picking and not-picking champion regions together in a tuple list
            List <Tuple <WindowRegion, WindowRegion> > regionTuples = new List <Tuple <WindowRegion, WindowRegion> >();

            WindowRegion pairFirst = null;

            foreach (var item in Window.Regions)
            {
                var data = item.RegionData as ChampionWindowRegionData;

                if (!data.IsChoosing)
                {
                    pairFirst = item;
                }
                else
                {
                    regionTuples.Add(new Tuple <WindowRegion, WindowRegion>(pairFirst, item));
                }
            }


            int i = 0;

            foreach (var item in regionTuples)
            {
                var goodRegion = await GetGoodRegion(gWindow, item.Item1, item.Item2);

                Bitmap goodBitmap = gWindow.GetRegionBitmap(goodRegion.Item1);
                string champion   = goodRegion.Item2;

                if (champion == "")
                {
                    champion = "None";
                }

                finalChampions[i++] = champion;

                Debug.WriteLine("{0}\t{1}", goodRegion.Item1.Name, champion);
            }

            sw.Stop();

            Debug.WriteLine("Took {0} ms", sw.ElapsedMilliseconds);

            return(finalChampions);
        }
Esempio n. 3
0
        private static async Task <Tuple <WindowRegion, string> > GetGoodRegion(GraphicalWindow gWindow,
                                                                                WindowRegion region1, WindowRegion region2)
        {
            //Get both of the bitmaps
            Bitmap pBmp  = gWindow.GetRegionBitmap(region1);
            Bitmap npBmp = gWindow.GetRegionBitmap(region2);

            string pChamp, npChamp;

            //If the picking bitmap is an empty champion, it means that the user is picking, but he hasn't
            //chosen any champion yet
            if (SquareBitmapHelper.IsEmptyChampion(pBmp))
            {
                pChamp = "Empty";
            }
            else //If it isn't, try to get the champion
            {
                pChamp = await GetChampion(pBmp);
            }

            //If the locked champion bitmap isn't empty, the user has already picked a champion
            if (SquareBitmapHelper.IsEmptyChampion(npBmp))
            {
                npChamp = "Empty";
            }
            else
            {
                npChamp = await GetChampion(npBmp);
            }


            //TODO: Maybe switch the order of the following statements
            //If the picking champion is actually a champion, choose that as the "good one"
            if (pChamp != "")
            {
                return(new Tuple <WindowRegion, string>(region1, pChamp));
            }
            else if (npChamp != "") //The locked champion is valid, use that one
            {
                return(new Tuple <WindowRegion, string>(region2, npChamp));
            }

            return(null);
        }
Esempio n. 4
0
        /// <summary>
        /// Add default champion regions. If P = picking and N = not picking, the order is NPNPNP...
        /// </summary>
        public void AddChampionRegions()
        {
            //Add all the champion regions
            //I took these measurements from my launcher, so the launcher size is 1280x720

            int squareSize = 60;
            int startY     = 104;

            //Left side champion squares
            for (int i = 0; i < 5; i++)
            {
                int y = startY + (i * 80);

                AddChampionRegion(false, false, i, "Ally" + i, 18, y, squareSize, squareSize);
                AddChampionRegion(false, true, i, "AllyChoosing" + i, 56, y, squareSize, squareSize);
            }

            //Right side champion squares
            for (int i = 0; i < 5; i++)
            {
                int y = startY + (i * 80);
                AddChampionRegion(true, false, i, "Enemy" + i, 1202, y, squareSize, squareSize);
                AddChampionRegion(true, true, i, "EnemyChoosing" + i, 1164, y, squareSize, squareSize);
            }


            void AddChampionRegion(bool enemy, bool choosing, int index, string name, int x, int y, int w, int h,
                                   int launcherW = 1280, int launcherH = 720)
            {
                var region = WindowRegion.FromAbsolute(name, x, y, w, h, launcherW, launcherH);

                region.RegionData = new ChampionWindowRegionData
                {
                    Index      = index,
                    IsChoosing = choosing,
                    Team       = enemy ? ChampionTeam.Enemy : ChampionTeam.Ally
                };

                Regions.Add(region);
            }
        }