/// <summary>
        /// Update Avatar from out of Note Window
        /// Basically just takes screenshot of Avatar-Rectangle and puts it into data representation
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnUpdateAvatar_Click(object sender, EventArgs e)
        {
            TableData td            = TableHandler.getTableDataFromTableName(table);
            Bitmap    screenshot    = Screenshot.CaptureApplication(td.tablePointer);
            string    seat          = td.getSeatname(note.Name);
            Bitmap    updatedAvatar = ScreenshotAnalyzer.getSingleAvatar(screenshot, seat, td.getTableSize());

            avatarBox.Image = updatedAvatar;
            note.Avatar     = NoteHandler.imageToBase64(updatedAvatar);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Triggers Tablescan where all info will be gathered and retrieve information will get separated into Data and GUI Parts
        /// </summary>
        /// <param name="button">ScanButton of table in focus</param>
        public static void scan(ScanButton button)
        {
            IntPtr handle = button.TableHandle;

            if (handle.Equals(IntPtr.Zero))
            {
                throw new Exception("Can't scan Zero Pointer");
            }

            // Get TableSize and check if supported by toolbox
            int tableSize = int.Parse(button.scanComboBox.SelectedItem.ToString());

            if (!GlobalSettings.General.SupportedTableSizes.Contains(tableSize))
            {
                throw new Exception("Unsupported Tablesize: " + tableSize);
            }

            // Init TableData with tablesize
            TableData table = new TableData(tableSize);

            // Retrieve Screenshot for table
            Bitmap screenshot = Screenshot.CaptureApplication(handle);

            // Checks if tablesize between scans has changed
            // If changed, means that we have to perform a completely new table (and get rid of locked seats and stuff)
            bool tableHasSameNumberOfSeats = true;

            // Table was scanned before
            if (tableSessions.ContainsKey(handle))
            {
                table = tableSessions[handle];

                // if tableSize from sessions is different than new one => start over with a new table since selection has changed (we sit on a new table)
                if (!table.getTableSize().Equals(tableSize))
                {
                    table                     = new TableData(tableSize);
                    table.tablename           = button.TableName;
                    table.tablePointer        = handle;
                    tableSessions[handle]     = table;
                    table.scanButton          = button;
                    tableHasSameNumberOfSeats = false;
                }
            }
            else // New Table aka First Scan of a table
            {
                table.tablename       = button.TableName;
                table.tablePointer    = handle;
                tableSessions[handle] = table;
                table.scanButton      = button;
            }

            // Get all unlocked Seats, as they are the only ones that should be scanned/updated from scratch
            Stack <string> scanTheseSeats = table.getUnlockedSeats();

            // Analyze those seats from screenshot
            ScreenshotAnalyzer scAnalyze = new ScreenshotAnalyzer(engine, screenshot, scanTheseSeats, tableSize);

            // Retrieve usable (aka string) information from the scan
            Dictionary <string, RawSeatInfo> unlockedSeatsInformation = scAnalyze.getRawSeatInfo();

            // Update/Set Retrieved info in TableData
            foreach (KeyValuePair <string, RawSeatInfo> kvp in unlockedSeatsInformation)
            {
                string      seat = kvp.Key;
                RawSeatInfo rsi  = kvp.Value;
                table.setNickname(seat, rsi.nicknameSTRING);
                table.setAvatar(seat, rsi.avatar);
            }

            // Run Button Creation at this point
            if (buttonInventory.ContainsKey(table.tablename))
            {
                if (tableHasSameNumberOfSeats) // Same table as before (probably)
                {
                    buttonInventory[table.tablename].removeUnlockedButtons(scanTheseSeats);
                    buttonInventory[table.tablename].updateButtons(table, false);
                }
                else // if there is a new table size than scan before => new table/remove all old buttons from display
                {
                    buttonInventory[table.tablename].removeAllButtons();
                    tableHasSameNumberOfSeats        = true;
                    buttonInventory[table.tablename] = new PlayerButtonHandler(table);
                }
            }
            else
            {
                buttonInventory[table.tablename] = new PlayerButtonHandler(table);
            }
        }