diff --git a/program/CaseDefinition.cs b/program/CaseDefinition.cs index d8489be..0f68588 100644 --- a/program/CaseDefinition.cs +++ b/program/CaseDefinition.cs @@ -26,6 +26,8 @@ public string[] RegionSounds = new string[7]; public string[] RegionIcons = new string[7]; public int InhaleStart, ExhaleStart, ExhaleEnd; // fields, so TryParse(out …) compiles + /// Explanation image (C100.png … C999.png). Legacy: column 27. + /// Current mode: optional "Manual_File" column in cases.csv. public string ManualFile; public bool IsLegacy; @@ -87,7 +89,7 @@ char sep = lines[0].Contains("\t") ? '\t' : ','; // Header name -> column index, so adding or reordering columns is safe. - string[] header = lines[0].TrimStart(new[] { '\uFEFF' }).Split(sep); + string[] header = lines[0].TrimStart(new[] { '' }).Split(sep); var idx = new Dictionary(StringComparer.OrdinalIgnoreCase); for (int i = 0; i < header.Length; i++) { @@ -139,7 +141,8 @@ SoundPath = get(f, "Sound_File"), MapRight = get(f, "Image_Right"), MapLeft = get(f, "Image_Left"), - MapBack = get(f, "Image_Back") + MapBack = get(f, "Image_Back"), + ManualFile = get(f, "Manual_File") // optional column; "" when absent }); } @@ -151,6 +154,12 @@ // ── loader: legacy mode (cases_old.csv) ─────────────────────────── /// Reads the Python-format case.csv: no header, 28 positional columns. + /// 0 name + /// 1..21 7 regions × (map, sound, icon) + /// 22 duration parameter (unused) + /// 23 1 = heart case, else breath + /// 24..26 inhale start, exhale start, exhale end + /// 27 explanation image (C100.png … C999.png) public static List LoadLegacyCasesFromCsv(string path) { var list = new List(); @@ -173,7 +182,7 @@ { if (string.IsNullOrWhiteSpace(raw)) continue; - string line = raw.TrimStart('\uFEFF'); + string line = raw.TrimStart(''); string[] f = line.Split(line.Contains("\t") ? '\t' : ','); if (f.Length < 28) diff --git a/program/MapWindow.cs b/program/MapWindow.cs index 2b857a0..6103b01 100644 --- a/program/MapWindow.cs +++ b/program/MapWindow.cs @@ -320,7 +320,17 @@ BodyJacketRadio.Toggled += (s, e) => { if (BodyJacketRadio.Active) ReloadBody(); }; JacketSizeCombo.Changed += (s, e) => { ReloadBody(); SyncSpins(); MapArea.QueueDraw(); }; - MapExplainButton.Clicked += (s, e) => { /* open 解説 */ }; + // 解説を見る — shows the case's explanation image (C100.png … C999.png) + MapExplainButton.Clicked += (s, e) => ShowExplanation(); + + // former 再生テスト — now switches output: speaker <-> headphone jack + AudioOutput.Log += m => Logger.Write("output", m); + if (SoundTestButton != null) + { + SoundTestButton.Clicked += (s, e) => ToggleOutput(); + UpdateOutputButton(AudioOutput.Current(), null); + } + _lang.Changed += (s, e) => { UpdateOutputButton(AudioOutput.Current(), null); UpdateContactChip(true); }; HookView(ViewFrontRadio, "front"); HookView(ViewBackRadio, "back"); @@ -404,6 +414,7 @@ if (!_mouseProbe || a.Event.Button != 1) return; _mouseProbe = false; _lastPx = _lastPy = -1; + UpdateContactChip(); UpdateAudioFromPosition(); // mutes, unless a real tag is on the jacket MapArea.QueueDraw(); }; @@ -449,6 +460,173 @@ }; } + // ══════════════════════════════════════════════════════════════════ + // チェストピース 接触 / 未接触 chip (header, top-right) + // ══════════════════════════════════════════════════════════════════ + + private int _contactState = -1; // -1 unknown, 0 off, 1 on, 2 reader offline + + /// Green "接触中" while a chip is on the target (or the debug mouse probe + /// is held), red "未接触" otherwise, grey-red "リーダー未接続" when the + /// RFID reader is disconnected. Only touches the widget when it changes. + private void UpdateContactChip(bool force = false) + { + if (MapContactLabel == null) return; + + int state = (_hasPosition || _mouseProbe) ? 1 + : (_arduino != null && !_arduino.IsOpen && !AppConfig.DebugMode) ? 2 + : 0; + if (!force && state == _contactState) return; + _contactState = state; + + bool en = _lang != null && _lang.IsEnglish; + switch (state) + { + case 1: MapContactLabel.Text = en ? "Chest piece in contact" : "チェストピース接触中"; break; + case 2: MapContactLabel.Text = en ? "Reader not connected" : "リーダー未接続"; break; + default: MapContactLabel.Text = en ? "Chest piece not in contact" : "チェストピース未接触"; break; + } + + var ctx = MapContactLabel.StyleContext; + if (state == 1) ctx.AddClass("contact-ok"); else ctx.RemoveClass("contact-ok"); + } + + // ══════════════════════════════════════════════════════════════════ + // OUTPUT: speaker <-> headphone jack (the button that was 再生テスト) + // ══════════════════════════════════════════════════════════════════ + + private uint _outputMsgId; + + private void ToggleOutput() + { + string problem; + var now = AudioOutput.Toggle(out problem); + UpdateOutputButton(now, problem); + } + + /// Button shows where sound comes out now. A problem (no headphones + /// plugged in, no pactl) is shown on the button for 2.5 s. + private void UpdateOutputButton(AudioOutput.Kind now, string problem) + { + if (SoundTestButton == null) return; + bool en = _lang != null && _lang.IsEnglish; + + string label, icon; + switch (now) + { + case AudioOutput.Kind.Jack: + label = en ? "Output: Headphones" : "出力:イヤホン"; + icon = "audio-headphones-symbolic"; + break; + case AudioOutput.Kind.Speaker: + label = en ? "Output: Speaker" : "出力:スピーカー"; + icon = "audio-speakers-symbolic"; + break; + default: + label = en ? "Output: unknown" : "出力:不明"; + icon = "audio-card-symbolic"; + break; + } + + string msg = null; + if (problem == "jack-empty" || problem == "no-jack") + msg = en ? "No headphones plugged in" : "イヤホンが接続されていません"; + else if (problem == "no-speaker") + msg = en ? "No speaker output found" : "スピーカーが見つかりません"; + else if (problem != null) + msg = en ? "Cannot switch output" : "出力を切り替えられません"; + + var img = SoundTestButton.Image as Gtk.Image; + if (img != null) img.SetFromIconName(icon, IconSize.Button); + + if (_outputMsgId != 0) { GLib.Source.Remove(_outputMsgId); _outputMsgId = 0; } + if (msg != null) + { + SoundTestButton.Label = msg; + _outputMsgId = GLib.Timeout.Add(2500, () => + { + _outputMsgId = 0; + SoundTestButton.Label = label; + return false; + }); + } + else SoundTestButton.Label = label; + + SoundTestButton.TooltipText = en ? "Tap to switch speaker / headphones" + : "タップでスピーカー/イヤホンを切り替え"; + } + + // ══════════════════════════════════════════════════════════════════ + // 解説を見る — explanation image with a 戻る button + // ══════════════════════════════════════════════════════════════════ + + private void ShowExplanation() + { + bool en = _lang != null && _lang.IsEnglish; + string file = _case != null ? _case.ManualFile : null; + string path = AppMode.ResolveManual(file); + Logger.Write("explain", "case " + (_case != null ? _case.Number.ToString() : "-") + + " manual='" + (file ?? "") + "' -> " + (path ?? "(not found)")); + + var top = MapArea.Toplevel as Window; + int w = top != null ? top.AllocatedWidth : 1280; + int h = top != null ? top.AllocatedHeight : 800; + + var dlg = new Dialog(); + dlg.Name = "ExplainDialog"; + dlg.TransientFor = top; + dlg.Modal = true; + dlg.Decorated = false; + dlg.TypeHint = Gdk.WindowTypeHint.Dialog; + dlg.WindowPosition = WindowPosition.CenterOnParent; + dlg.SetDefaultSize((int)(w * 0.94), (int)(h * 0.94)); + + Box content = dlg.ContentArea; + content.Spacing = 12; + + const int buttonRow = 90; // room for 戻る + int maxW = (int)(w * 0.94) - 40, maxH = (int)(h * 0.94) - buttonRow - 40; + + Widget body = null; + if (path != null) + { + try + { + using (var raw = new Gdk.Pixbuf(path)) + { + double s = Math.Min(1.0, Math.Min((double)maxW / raw.Width, (double)maxH / raw.Height)); + int iw = Math.Max(1, (int)(raw.Width * s)), ih = Math.Max(1, (int)(raw.Height * s)); + var img = new Gtk.Image(raw.ScaleSimple(iw, ih, Gdk.InterpType.Bilinear)); + img.Name = "ExplainImage"; + body = img; + } + } + catch (Exception ex) + { + Logger.Write("explain", "load failed " + path + ": " + ex.Message); + } + } + + if (body == null) + { + var msg = new Label(en ? "No explanation image for this case." + : "この症例の解説画像はありません。"); + msg.Name = "ExplainMessage"; + msg.LineWrap = true; + body = msg; + } + content.PackStart(body, true, true, 10); + + // 戻る — same red as the page's back buttons + var back = (Button)dlg.AddButton(en ? "Back" : "戻る", (int)ResponseType.Close); + back.Name = "ExplainBackButton"; + dlg.DefaultResponse = ResponseType.Close; + + dlg.ShowAll(); + dlg.Run(); + dlg.Destroy(); + } + private void HookFilter(RadioButton rb, SoundFilter f) { if (rb == null) return; // older glade without the segment @@ -536,6 +714,7 @@ _currentY = y; _currentZ = z; _hasPosition = _highlighted.Count > 0; // marker only shows when a chip is actually on the target + UpdateContactChip(); string newView = DetermineViewFromZ(z); if (newView != _view) @@ -558,6 +737,7 @@ MuteVoices(); MapArea.QueueDraw(); } + UpdateContactChip(); // offline <-> 未接触, both directions } private void UpdateAudioFromPosition() @@ -671,6 +851,7 @@ _currentX = _currentY = _currentZ = 0f; if (_mouseProbe) UpdateAudioFromPosition(); // debug click still held else MuteVoices(); + UpdateContactChip(); MapArea.QueueDraw(); } @@ -829,6 +1010,8 @@ MapArea.QueueDraw(); UpdateTunerInfo(); + UpdateOutputButton(AudioOutput.Current(), null); // headphones may have been plugged in since + UpdateContactChip(true); if (!AppMode.Legacy) { @@ -1882,6 +2065,7 @@ _mouseBx = (wx - ox) / s; _mouseBy = (wy - oy) / s; _mouseProbe = true; + UpdateContactChip(); Logger.Write("debug", string.Format(CultureInfo.InvariantCulture, "mouse probe body({0:F0},{1:F0})", _mouseBx, _mouseBy)); diff --git a/program/touch_friendly.css b/program/touch_friendly.css index 55cd54b..11c6e02 100644 --- a/program/touch_friendly.css +++ b/program/touch_friendly.css @@ -630,4 +630,43 @@ #MapSectionLabel, #JacketSizeLabel { font-size: 14px; } #SoundTestButton { min-height: 40px; } -#SoundTestButton label { font-size: 18px; } \ No newline at end of file +#SoundTestButton label { font-size: 18px; } + +/* ── 解説を見る: explanation image window ── + Own toplevel, so the global `window` background and `button` rules at + the top of touch_friendly.css apply to it. Undo them, then restyle. */ +#ExplainDialog { + background-image: none; + background-color: #FFFFFF; + border: 3px solid #0B3B6B; +} +#ExplainDialog box, +#ExplainDialog .dialog-vbox, +#ExplainDialog .dialog-action-area { + background-color: transparent; + background-image: none; +} +#ExplainDialog .dialog-action-area { margin: 0 20px 16px 20px; } + +#ExplainMessage { + font-family: 'Noto Sans JP', 'IPAPGothic', sans-serif; + font-size: 28px; + font-weight: 700; + color: #1E2430; + margin: 40px; +} + +/* 戻る — same red as the page back buttons */ +#ExplainBackButton { + min-height: 60px; + min-width: 180px; + padding: 0 26px; + background-color: #C62828; + background-image: none; + border-width: 0; + border-radius: 12px; + outline-style: none; +} +#ExplainBackButton label { color: #FFFFFF; font-size: 22px; font-weight: 700; } +#ExplainBackButton:hover { background-color: #D33A3A; } +#ExplainBackButton:active { background-color: #A61F1F; } \ No newline at end of file