void ProcessCommandResult(EvalBundle b) { var sb = new StringBuilder(); for (int i = 0; i < 20; i++) { var k = i.ToString(); if (!b.dict.ContainsKey(k)) { break; } if (i > 0) { sb.Append("\r\n"); } sb.Append(b.dict[k]); } PopupString(sb.ToString()); }
internal void Consider(EvalBundle b) { if (_fFiles) { return; } m_results.Items.Clear(); for (int i = 0; i < b.dict.Count; i++) { string key = i.ToString(); string val; if (!b.dict.TryGetValue(key, out val)) { continue; } var url = Config.uploads_mapping + val; AddImage(val, url); } }
void ProcessEvals(EvalBundle b) { readyRolls.Consider(b); if (accessLibraryDlg != null && b.path == "library-search") { accessLibraryDlg.Consider(b); } if (b.path == "map1") { map1.ConsiderEval(b); } else if (b.path == "map2") { map2.ConsiderEval(b); } if (b.path == "command-result") { ProcessCommandResult(b); } }
public void Consider(EvalBundle b) { if (b.dict == null) { return; } if (!b.dict.ContainsKey("purpose") || b.dict["purpose"] != "readyrolls") { return; } mainGrid.Children.Clear(); mainGrid.RowDefinitions.Clear(); var q = from el in b.dict.Keys orderby el select el; foreach (string k in q) { string v = b.dict[k]; if (k.Length < 3) { continue; } if (!k.StartsWith("\\")) { continue; } int n = k.IndexOf('\\', 1); if (n < 2) { continue; } string name = k.Substring(1, n - 1); string wpn = ""; int w = k.IndexOf("\\_wpn\\"); if (w > 0) { wpn = k.Substring(w + 6); w = wpn.IndexOf('\\'); if (w > 0) { wpn = wpn.Substring(0, w); } else { wpn = ""; } } int t = k.LastIndexOf('\\'); if (t < 0) { continue; } string tail = k.Substring(t + 1); if (k.EndsWith("\\parry") && wpn != "") { var parryStrip = new ParryStrip(); var apKey = k.Replace("\\parry", "\\ap"); if (!b.dict.ContainsKey(apKey)) { continue; } var parryAP = b.dict[apKey]; var parryPct = b.dict[k]; parryStrip.Init(name, parryChoice: wpn, ap: parryAP, parryPct: parryPct); AppendStripContents(name, parryStrip.Children, saveKey: k); } else if (k.EndsWith("\\attack") && wpn != "") { var srKey = k.Replace("\\attack", "\\sr"); if (!b.dict.ContainsKey(srKey)) { continue; } var dmgKey = k.Replace("\\attack", "\\dmg"); if (!b.dict.ContainsKey(dmgKey)) { continue; } var sr = b.dict[srKey]; var pct = v; var dmg = b.dict[dmgKey]; var attackStrip = new AttackStrip(); attackStrip.Init(name, weapon: wpn, sr: sr, pct: pct, damage: dmg, note: null); AppendStripContents(name, attackStrip.Children, saveKey: k); } else if (wpn == "") { switch (tail) { case "STR": case "CON": case "SIZ": case "INT": case "POW": case "DEX": case "APP": string stat = tail; var powStrip = new PowStrip(); powStrip.Init(name: name, stat: stat + " vs. " + stat, value: v); AppendStripContents(name, powStrip.Children, saveKey: k); break; default: string skill = tail; var skillStrip = new SkillStrip(); skillStrip.Init(name: name, skill: skill, sr: null, skillPct: v, note: null); AppendStripContents(name, skillStrip.Children, saveKey: k); break; } } } }
internal void ConsiderEval(EvalBundle b) { var dict = b.dict; if (dict == null || !dict.ContainsKey("purpose")) { return; } var purpose = dict["purpose"]; if (purpose != "icons") { return; } var q = from k in dict.Keys where k != "purpose" orderby k select k; double xPos = 40; double yPos = 40; BeginUndoUnit(); ClearHandles(); selectedList = new List <FrameworkElement>(); foreach (var k in q) { var v = dict[k]; FrameworkElement el = TryParseXaml(v); if (el == null) { var t = new TextBlock(); t.Text = "Error"; t.HorizontalAlignment = HorizontalAlignment.Left; t.VerticalAlignment = VerticalAlignment.Top; t.IsHitTestVisible = true; el = t; } el.Margin = new Thickness(xPos, yPos, 0, 0); el.Tag = FindFreeId(el); WireObject(el); AddCanvasChild(el); SaveFrameworkElement(el); selectedList.Add(el); var block = new TextBlock(); block.Margin = new Thickness(xPos + 40, yPos, 0, 0); block.HorizontalAlignment = HorizontalAlignment.Left; block.VerticalAlignment = VerticalAlignment.Top; block.Text = k; block.IsHitTestVisible = true; block.Foreground = strokeBrush; if (configuredFont) { // FontChooser.TransferFontProperties(fontSampleText, block); block.FontFamily = fontSampleText.FontFamily; block.FontWeight = fontSampleText.FontWeight; block.FontStyle = fontSampleText.FontStyle; block.FontStretch = fontSampleText.FontStretch; block.FontSize = fontSampleText.FontSize; block.TextDecorations = fontSampleText.TextDecorations; } el = block; el.Margin = new Thickness(xPos + 40, yPos, 0, 0); el.Tag = FindFreeId(el); WireObject(el); AddCanvasChild(el); SaveFrameworkElement(el); selectedList.Add(el); yPos += 40; } var sel = selectedList; Main.DelayAction(300, () => { if (sel == selectedList) { AddBoundingBoxesForSelection(); } }); }
public void OnHostEvent(object sender, ProgressChangedEventArgs e) { if (e.UserState is Exception) { Exception ex = e.UserState as Exception; PopupString(ex.ToString() + "\r\n" + ex.StackTrace.ToString()); } if (e.UserState is string) { /* * string line = (string)e.UserState; * * textHistory.AppendText(line + "\r\n"); * textHistory.ScrollToEnd(); */ } else if (e.UserState is EvalBundle) { EvalBundle b = (EvalBundle)e.UserState; ProcessEvals(b); } else if (e.UserState is DictBundle) { DictBundle b = (DictBundle)e.UserState; if (b.path == "download-result") { OfferDownloads(b); if (accessLibraryDlg != null) { accessLibraryDlg.Consider(b); } } else { if (b.path == "_gameaid/_filenames") { filenameDict = b.dict; } partyInfo1.Consider(b); partyInfo2.Consider(b); vs1.Consider(b); readyRolls.Consider(b); if (openSaveRollsDlg != null) { openSaveRollsDlg.Consider(b); } map1.Consider(b); map2.Consider(b); foreach (var sq in Squad.Children) { var sheet = sq as VirtualSheet; if (sheet != null) { sheet.Consider(b); } } } } else if (e.UserState is DownloadFile) { DownloadFile file = e.UserState as DownloadFile; // Configure open file dialog box var dlg = new System.Windows.Forms.SaveFileDialog(); dlg.Title = "Save Download"; dlg.FileName = file.name; dlg.DefaultExt = ".xlsx"; // Default file extension dlg.Filter = "Character Sheets (.xlsx)|*.xlsx"; // Filter files by extension dlg.OverwritePrompt = true; dlg.CheckPathExists = true; // Show open file dialog box System.Windows.Forms.DialogResult result = dlg.ShowDialog(); // Process open file dialog box results if (result == System.Windows.Forms.DialogResult.OK) { try { System.IO.File.WriteAllBytes(dlg.FileName, file.bytes); } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message); return; } } } else if (e.UserState is AudioReport) { AudioReport audio = e.UserState as AudioReport; string url = ""; switch (audio.desc) { case "speak": if (reader == null) { try { // tolerate reader acquisition failure more gracefully reader = new SpeechSynthesizer(); // var l = new List<VoiceInfo>(); // // foreach (InstalledVoice voice in reader.GetInstalledVoices()) // { // VoiceInfo info = voice.VoiceInfo; // string AudioFormats = ""; // foreach (SpeechAudioFormatInfo fmt in info.SupportedAudioFormats) // { // AudioFormats += String.Format("{0}\n", // fmt.EncodingFormat.ToString()); // } // // l.Add(info); // // } reader.SelectVoice("Microsoft Zira Desktop"); } catch { } } if (reader != null) { reader.SpeakAsync(audio.text); } break; case "ownage": switch (audio.killcount) { case 1: url = "http://myserver.com/uploads/killshot/1.mp3"; break; case 2: url = "http://myserver.com/uploads/killshot/4.mp3"; break; case 3: url = "http://myserver.com/uploads/killshot/6.mp3"; break; case 4: url = "http://myserver.com/uploads/killshot/7.mp3"; break; case 5: url = "http://myserver.com/uploads/killshot/10.mp3"; break; case 6: url = "http://myserver.com/uploads/killshot/9.mp3"; break; case 7: default: url = "http://myserver.com/uploads/killshot/14.mp3"; break; } break; case "fumble": url = "http://myserver.com/uploads/killshot/0.mp3"; break; default: url = "http://myserver.com/uploads/misc/" + audio.desc; break; } if (url != "") { var player = new System.Windows.Media.MediaPlayer(); player.Open(new Uri(url)); player.MediaOpened += new EventHandler((object s, EventArgs a) => { player.Play(); }); player.MediaEnded += new EventHandler((object s, EventArgs a) => { player.Close(); }); } } else if (e.UserState is HoursReport) { HoursReport h = e.UserState as HoursReport; vs1.SetRemainingHours(h.hours); } }
public void HandleHost(object sender, DoWorkEventArgs e) { BackgroundWorker b = (BackgroundWorker)sender; DictBundle pending = null; string a1, a2, a3, a4; for (;;) { try { hostClient = new System.Net.Sockets.TcpClient(server, 6668); NetworkStream stream = hostClient.GetStream(); HybridStreamReader r = new HybridStreamReader(stream); HybridStreamReader savedStream = null; SendHost("nick " + nick); SendHost("dir /"); SendHost("dir _maps/default"); string line; for (; ;) { if ((line = r.ReadLine()) == null) { if (savedStream != null) { r = savedStream; savedStream = null; continue; } break; } if (line.StartsWith("hours ")) { int hours; Parse2(line, out a1, out a2); Int32.TryParse(a2, out hours); var h = new HoursReport(); h.hours = hours; b.ReportProgress(1, h); } else if (line.StartsWith("audio ")) { int count; Parse3(line, out a1, out a2, out a3); var audio = new AudioReport(); audio.desc = a2; if (a2 == "ownage") { Int32.TryParse(a3, out count); audio.killcount = count; } else { audio.text = a3; } b.ReportProgress(1, audio); } else if (line.StartsWith("download ")) { int len; Parse3(line, out a1, out a2, out a3); Int32.TryParse(a3, out len); var bytes = new byte[len]; r.Read(bytes); var download = new DownloadFile(); download.name = a2; download.bytes = bytes; b.ReportProgress(1, download); } else if (line.StartsWith("compressed ")) { int clen, len; Parse3(line, out a1, out a2, out a3); Int32.TryParse(a2, out clen); Int32.TryParse(a3, out len); // switch to the saved stream savedStream = r; r = UncompressBytes(r, clen); if (r == null) { r = savedStream; } continue; } else if (line.StartsWith("begin eval ")) { pending = new EvalBundle(); Parse3(line, out a1, out a2, out a3); pending.path = a3; } else if (line.StartsWith("begin dir ")) { pending = new DictBundle(); Parse3(line, out a1, out a2, out a3); pending.path = a3; } else if (pending != null && line.StartsWith("v ")) { Parse4(line, out a1, out a2, out a3, out a4); if (a1 != "v" || a2 != pending.path) { continue; } if (!pending.dict.ContainsKey(a3)) { pending.dict.Add(a3, a4); } } else if (line.StartsWith("end dir ")) { b.ReportProgress(1, pending); pending = null; } else if (line.StartsWith("end eval ")) { b.ReportProgress(1, pending); pending = null; } else if (pending == null) { b.ReportProgress(1, line); } } } catch (Exception ex) { b.ReportProgress(0, ex); System.Threading.Thread.Sleep(5000); } } }