/// <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); }
/// <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> /// Retrieve Information from Note and add it to relevant components /// </summary> private void loadValuesFromNote() { Text = note.Name; nameTextBox.Text = note.Name; noteTextBox.Text = note.Text; colorBox.SelectedItem = note.getColor(); tagsTextBox.Text = note.Tags; if (note.Avatar != null) { avatarBox.Image = 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> /// Implementing the Tooltip-Workaround found on StackOverflow /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_MouseHover(object sender, EventArgs e) { /* * Workaround found on StackOverflow since Button Tooltips are (still) buggy */ Button button = (Button)sender; string display = NoteHandler.getNote(button.Text).Text; Label dummy = (Label)button.Controls[0]; tip.Show(display, dummy); tip.AutoPopDelay = 0; tip.AutomaticDelay = 0; tip.ShowAlways = true; }
/// <summary> /// Manages search and display of tags /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void searchByTags_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { TextBox tb = (TextBox)sender; ImageList tagFindings = new ImageList(); tagFindings.ImageSize = new Size(65, 65); selectionTags.Items.Clear(); selectionTags.ShowGroups = false; List <Note> findings = NoteHandler.searchNoteByTags(tb.Text); for (int i = 0; i < findings.Count; i++) { tagFindings.Images.Add(NoteHandler.base64ToImage(findings.ElementAt(i).Avatar)); } ListViewItem lvi; ListViewItem.ListViewSubItem lvsi; selectionTags.BeginUpdate(); // Insert Items to ListView for (int x = 0; x < tagFindings.Images.Count; x++) { lvi = new ListViewItem(); lvi.Text = findings.ElementAt(x).Name; lvi.ImageIndex = x; lvi.Name = findings.ElementAt(x).Name; lvi.Tag = findings.ElementAt(x); lvsi = new ListViewItem.ListViewSubItem(); lvsi.Text = findings.ElementAt(x).Name; lvi.SubItems.Add(lvsi); selectionTags.Items.Add(lvi); } selectionTags.EndUpdate(); selectionTags.LargeImageList = tagFindings; selectionTags.View = View.LargeIcon; selectionTags.Refresh(); } }
/// <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> /// C# has a bug where tooltips for Buttons whicha re created during runtime will fail to show up /// Workaround is adding a transparent label on that button and attach the tooltip to that label /// If a Player has a note, we add a Note Icon to the left side of the button and implement the workaround for the tooltip /// </summary> /// <param name="button"></param> /// <param name="playername"></param> private void createToolTipAndNoteIcon(PlayerButton button, string playername) { string hasNote = NoteHandler.playerHasNote(playername); // check if note in note database if (hasNote == null || hasNote.Equals("")) { button.setNoteImage(false); } else { // if note-text was found, add note image to playerbutton button.setNoteImage(true); // clean up before adding new tooltip int controls = button.Controls.Count; if (controls > 0) { foreach (Control c in button.Controls) { c.Dispose(); } } // Create workaround/dummy Label Label dummy = new Label { Top = 3, Left = 3, Width = 20, Height = 20 }; dummy.BackColor = System.Drawing.Color.Transparent; dummy.ForeColor = System.Drawing.Color.Transparent; button.Controls.Add(dummy); // Set custom EventHandlers button.MouseHover += Button_MouseHover; button.MouseLeave += Button_MouseLeave; } }
/// <summary> /// Only one notewindow per player should be opened, set to foreground if double open /// !!! Bug: Seems like western nicknames work fine but chinese dont !!!+ /// /// Will get called from PlayerButton.Click /// /// </summary> /// <param name="playername"></param> /// <param name="tablename"></param> public FormNoteWindow(string playername, string tablename) { // Retrieve List of instances with the regex set to the playername EmulatorHandler doubleCheck = new EmulatorHandler(playername); List <IntPtr> doubleList = doubleCheck.getEmulatorList(); if (doubleList.Count == 0) // No window for the same player found { // Create new NoteWindow initComponents(); //Console.WriteLine("FormNoteWindow from PlayerButton.Click"); // Debug // Set Note from Loaded Notes this.note = NoteHandler.getNote(playername); table = tablename; // Check if note exists, if not: construct new from tabledata if (note.Name == null) { constructNewNote(playername, tablename); } else { loadValuesFromNote(); } // Set Location of the Form within table boundaries and not somewhere else on the screen setAppearanceLocation(tablename); this.Show(); } else // Already one open => Set to foreground! { WinAPI.SetForegroundWindow(doubleList[0]); } }
// Paint every button new from scratch private List <PlayerButton> paintButtons(Dictionary <string, PlayerButton> template, TableData tableData, bool force) // force = true enables repainting of buttons which are locked { foreach (PlayerButton button in buttonTemplate.Values) { if (!force) // if repainting is not forced, skip locked seats, otherwise force repaint for all buttons (necessary for completely new tables f.e.) { if (tableData.isSeatLocked(button.SeatName)) // only (re)paint unlocked seats { continue; } } string playername = tableData.getNickname(button.SeatName); if (playername == null) { continue; // skip empty/open seats } if (GlobalSettings.ButtonSettings.HideEmptyButtons) // Show Empty Buttons? yes/no { try { if (playername.Equals("")) { table.removeSeat(button.SeatName); continue; } } catch (Exception ex) { Console.WriteLine("HideEmptyButtons: \n" + ex.ToString()); } } // Create ContextMenuStrip for playerbutton and initialize with necessary information PlayerButtonContextMenuStrip pbcms = new PlayerButtonContextMenuStrip(); button.ContextMenuStrip = pbcms; button.Text = playername; button.BackColor = System.Drawing.Color.FromName(NoteHandler.getNote(playername).getColor()); button.SetPlayerNameContextMenu(playername, button.SeatName, tableData.tablename, tableData.isSeatLocked(button.SeatName)); button.SetParent(tableData.tablePointer); button.Visible = true; /* * Create ToolTip & NoteIcon if there are notes */ createToolTipAndNoteIcon(button, playername); /* * Check for alternate spellings in playernames ==> Levenshtein! */ if (tableData.isSeatLocked(button.SeatName)) { continue; // Makes no sense to update this for locked buttons [would popup icon if other player gets renamed] } if (playername.Length > GlobalSettings.Notes.PlayernameMinLengthForDistanceCheck) // Only check for playernames with 3+ characters { List <Note> similarNicks = NoteHandler.findSimilarNicknames(playername, GlobalSettings.Notes.LevenshteinMaxDistance); if (similarNicks.Count > 0) // Players with similar nicks have notes already { setSimilarNickImage(button, similarNicks); } } } return(buttonTemplate.Values.ToList()); }