Esempio n. 1
0
        /// <summary>
        /// Refresh Player Buttons - Used after Deleting a Note and resetting defaults
        /// Especially needed when we delete from Note Window that was not open by Click from table,
        /// but from NoteBrowser or from Click on SimilarNickName-Icon
        /// </summary>
        /// <param name="tablename"></param>
        public static void refreshPlayerButtons(string tablename)
        {
            PlayerButtonHandler pbh = TableHandler.buttonInventory[tablename];
            TableData           td  = TableHandler.getTableDataFromTableName(tablename);

            pbh.updateButtons(td, true);
        }
        /// <summary>
        /// Start TableModule ==> Scan Button Was clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void ControlButton_Click(object sender, EventArgs e)
        {
            ScanButton sb = new ScanButton();

            // Get ScanButton instance depending on where the request came from
            if (sender is ToolStripMenuItem) // From Context Menu
            {
                ToolStripMenuItem          tsi   = (ToolStripMenuItem)sender;
                ScanButtonContextMenuStrip pbcms = (ScanButtonContextMenuStrip)tsi.GetCurrentParent();
                sb = pbcms.parentButton;
            }
            else if (sender is ScanButton) // From LeftClick on ScanButton
            {
                sb = (ScanButton)sender;
            }
            else
            {
                throw new Exception("ControlButton_Click: Unknown Sender");
            }

            // Check Again for Size of the table
            checkEmulatorSize(sb.TableHandle);

            // Scan the table
            TableHandler.scan(sb);
        }
        /// <summary>
        /// Saves updated note (also to file)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSave_Click(object sender, EventArgs e)
        {
            /*
             * 1. Collect all info and save to list & save to file
             * 2. Check if avatar = null?
             */
            note.Color = colorBox.SelectedValue.ToString();
            note.Text  = noteTextBox.Text.Trim();
            note.Tags  = tagsTextBox.Text.Trim();

            // Convert Avatar to base64 encoded string
            if (note.Avatar != null)
            {
                note.Avatar = NoteHandler.imageToBase64(avatarBox.Image);
            }

            // Save Note
            NoteHandler.saveNote(note);
            NoteHandler.saveNotesToFile();
            NoteHandler.refreshNotesFromFile();

            // Update data representation as well as update playerbuttons
            TableHandler.refreshTableData(note, table);
            TableHandler.refreshPlayerButtons(table);

            this.Close();
        }
        static Dictionary <IntPtr, ScanButton> scanButtonList; // keeps track of all attached ScanButtons

        /// <summary>
        /// Initialize all of the above components
        /// </summary>
        public SessionHandler()
        {
            launchOCREngine();
            emuHandler   = new EmulatorHandler(GlobalSettings.General.EmulatorRegex); // Only retrieve pointers from windows which match regular expression
            emulatorList = emuHandler.getEmulatorList();
            tableHandler = new TableHandler(engine);
            NoteHandler.refreshNotesFromFile(); // Load Notes from JSON-Notefile
            alerterWorker  = new AlertWorker();
            scanButtonList = new Dictionary <IntPtr, ScanButton>();
        }
        /// <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);
        }
Esempio n. 6
0
        /// <summary>
        /// Refresh Table Data - Used after Deleting a Note and resetting defaults
        /// Especially needed when we delete from Note Window that was not open by Click from table,
        /// but from NoteBrowser or from Click on SimilarNickName-Icon
        /// </summary>
        /// <param name="note"></param>
        /// <param name="tablename"></param>
        public static void refreshTableData(Note note, string tablename)
        {
            TableData td = TableHandler.getTableDataFromTableName(tablename);

            if (td.playerIsSeated(note.Name))
            {
                string seatname = td.getSeatname(note.Name);
                td.setColor(seatname, System.Drawing.Color.FromName(note.getColor()));
                td.setNickname(seatname, note.Name);
                td.setAvatar(seatname, (Bitmap)NoteHandler.base64ToImage(note.Avatar));
            }
        }
        /// <summary>
        /// EventHandler - Delete Note from inside NoteWindow
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnDelNote_Click(object sender, EventArgs e)
        {
            // Remove vom Note-File
            NoteHandler.deleteNote(note.Name);
            NoteHandler.saveNotesToFile();
            NoteHandler.refreshNotesFromFile();

            // Remove tabledata as well as button
            TableHandler.refreshTableData(note, table);
            TableHandler.refreshPlayerButtons(table);

            this.Close();
        }
        /// <summary>
        /// If there is no Note stored for a player => Create a new note!
        /// </summary>
        /// <param name="playername"></param>
        /// <param name="tablename"></param>
        public void constructNewNote(string playername, string tablename)
        {
            // Construct Note from TableData
            TableData td       = TableHandler.getTableDataFromTableName(tablename);
            string    seatname = td.getSeatname(playername);

            note.Name = td.getNickname(seatname);

            if (td.getAvatar(seatname) == null)
            {
                note.Avatar = null;
            }
            else
            {
                note.Avatar = NoteHandler.imageToBase64(td.getAvatar(seatname));
            }

            loadValuesFromNote();
        }
        /// <summary>
        /// Remove ScanButton from single Instance
        /// </summary>
        /// <param name="sb"></param>
        public static void removeScanButton(ScanButton sb)
        {
            scanButtonList.Remove(sb.TableHandle);
            // bug if table hasnt been scanned
            if (!TableHandler.tableSessions.ContainsKey(sb.TableHandle))
            {
                //MessageBox.Show("Table was not scanned yet!");    // Debug
            }
            else
            {
                // Clear TableData and Button Inventory
                string tablename = TableHandler.tableSessions[sb.TableHandle].tablename;
                TableHandler.Dispose(sb.TableHandle);
                TableHandler.buttonInventory[tablename].Dispose();
            }

            // Dispose components
            sb.Dispose();
            sb.scanComboBox.Dispose();
            sb.checkBox.Dispose();
        }