public bool Load() { if (!File.ExistsNow()) { RefreshUserPresets(); return(false); } var xml = Persistent.LoadXml(File); if (xml == null) { RimHUD.Mod.Error($"Unable to load preset '{Label}'"); return(false); } var docked = xml.Element(HudLayout.DockedElementName); var floating = xml.Element(HudLayout.FloatingElementName); if (docked != null) { HudLayout.Docked = HudLayout.FromXml(docked); } if (floating != null) { HudLayout.Floating = HudLayout.FromXml(floating); } Persistent.Save(); return(true); }
public static void UpdateHud(HudLayout hudLayout) { if (hudLayout == null) { return; } InitializeHotkeys(); var hwnd = new IntPtr(hudLayout.WindowId); if (!WinApi.IsWindow(hwnd)) { LogProvider.Log.Info($"Window {hwnd} doesn't exist."); return; } using (rwWindowsLock.Read()) { if (windows.ContainsKey(hwnd)) { if (!windows[hwnd].IsInitialized) { return; } windows[hwnd].Window.Dispatcher.Invoke(() => { windows[hwnd].Window.Initialize(hudLayout, hwnd); if (!WinApi.IsIconic(hwnd)) { windows[hwnd].Window.Refresh(); } }); return; } } WinApi.GetWindowThreadProcessId(hwnd, out uint processId); if (processId == 0) { return; } moveHook = WinApi.SetWinEventHook(WinApi.EVENT_SYSTEM_MOVESIZEEND, moveCallback, processId); closeHook = WinApi.SetWinEventHook(WinApi.EVENT_OBJECT_DESTROY, closeCallback, processId); createHook = WinApi.SetWinEventHook(WinApi.EVENT_OBJECT_NAMECHANGE, createCallback, processId); if (hudLayout.IsSpecialMode) { foregroundChangedHook = WinApi.SetWinEventHook(WinApi.EVENT_SYSTEM_FOREGROUND, foregroundChangedCallback, processId); } CreateHudWindow(hwnd, hudLayout); }
public static void AllToDefault() { SetToDefault(typeof(Theme)); foreach (var integration in GetIntegrations()) { SetToDefault(integration); } HudLayout.LoadDefaultAndSave(); }
private static void TryLoadPreset(ExternalMod mod, string id) { if (!mod.IsActive) { Dialog_Alert.Open(Lang.Get("Dialog_Config.Tab.Content.Layout.Preset.Invalid", mod.Name)); return; } HudLayout.LoadPreset(id); Dialog_Alert.Open(Lang.Get("Dialog_Config.Tab.Content.Layout.Preset.Loaded", mod.Name)); }
public void Update() { var updated = HudLayout.FromLayoutView(this); if (Docked) { HudLayout.Docked = updated; } else { HudLayout.Floating = updated; } }
public static void LoadLayouts(bool reset) { var docked = new FileInfo(Path.Combine(Mod.ConfigDirectory.FullName, HudLayout.DockedFileName)); var floating = new FileInfo(Path.Combine(Mod.ConfigDirectory.FullName, HudLayout.FloatingFileName)); if (!reset && docked.Exists && LoadXml(docked) is XElement dockedXe) { HudLayout.Docked = HudLayout.FromXml(dockedXe); } else { HudLayout.Docked.ToXml().Save(docked.FullName); } if (!reset && floating.Exists && LoadXml(floating) is XElement floatingXe) { HudLayout.Floating = HudLayout.FromXml(floatingXe); } else { HudLayout.Floating.ToXml().Save(floating.FullName); } }
private static void LoadLayouts() { var docked = new FileInfo(Path.Combine(Mod.ConfigDirectory.FullName, HudLayout.DockedFileName)); var floating = new FileInfo(Path.Combine(Mod.ConfigDirectory.FullName, HudLayout.FloatingFileName)); if (docked.Exists) { HudLayout.Docked = HudLayout.FromXml(XDocument.Load(docked.FullName)); } else { HudLayout.Docked.AsXDocument().Save(docked.FullName); } if (floating.Exists) { HudLayout.Floating = HudLayout.FromXml(XDocument.Load(floating.FullName)); } else { HudLayout.Floating.AsXDocument().Save(floating.FullName); } }
private static void RequiredReset() { Dialog_Alert.Open(Lang.Get("Alert.InvalidLayout")); HudLayout.LoadDefaultAndSave(); }
private static void PrepareWindow(HudWindowItem windowItem, HudLayout hudLayout, IntPtr windowHandle) { if (!hudLayout.IsSpecialMode) { return; } var isHiddenWindow = false; var dispatcherTimer = new DispatcherTimer(); var timerThrownException = false; var handle = windowItem.OverlayHandle; WinApi.SetWindowPos(handle, windowHandle, 0, 0, 0, 0, TopMostFlags); WinApi.SetWindowPos(windowHandle, handle, 0, 0, 0, 0, TopMostFlags); dispatcherTimer.Tick += (s, e) => { try { // handle minimize/restore if (!isHiddenWindow && WinApi.IsIconic(windowHandle)) { windowItem.Window.Hide(); isHiddenWindow = true; } else if (isHiddenWindow && !WinApi.IsIconic(windowHandle)) { windowItem.Window.Show(); isHiddenWindow = false; } var nextWindow = WinApi.GetWindow(handle, GetWindowType.GW_HWNDNEXT); if (nextWindow != windowHandle) { WinApi.SetWindowPos(windowHandle, handle, 0, 0, 0, 0, TopMostFlags); } var activeWindow = WinApi.GetForegroundWindow(); if (activeWindow != handle) { if (activeWindow == windowHandle && !windowItem.IsTopMost) { WinApi.SetWindowPos(handle, Hwnd.TopMost, 0, 0, 0, 0, TopMostFlags); windowItem.IsTopMost = true; } else if (activeWindow != windowHandle && windowItem.IsTopMost) { WinApi.SetWindowPos(handle, activeWindow, 0, 0, 0, 0, TopMostFlags); WinApi.SetWindowPos(handle, Hwnd.NoTopMost, 0, 0, 0, 0, TopMostFlags); windowItem.IsTopMost = false; } } else if (!windowItem.IsTopMost) { WinApi.SetForegroundWindow(windowHandle); WinApi.SetWindowPos(handle, Hwnd.TopMost, 0, 0, 0, 0, TopMostFlags); windowItem.IsTopMost = true; } } catch (Exception ex) { if (!timerThrownException) { LogProvider.Log.Error(typeof(HudPainter), "Failed to prepare window", ex); timerThrownException = true; } } }; dispatcherTimer.Interval = TimeSpan.FromMilliseconds(timerInterval); dispatcherTimer.Start(); }
private static WindowInteropHelper CreateWindowInteropHelper(HudWindow window, HudLayout hudLayout, IntPtr windowHandle) { if (hudLayout.IsSpecialMode) { return(new WindowInteropHelper(window)); } return(new WindowInteropHelper(window) { Owner = windowHandle }); }
private static void CreateHudWindow(IntPtr hwnd, HudLayout hudLayout) { var thread = new Thread(() => { try { var hudPanelService = ServiceLocator.Current.GetInstance <IHudPanelService>(hudLayout.PokerSite.ToString()); var window = new HudWindow(); var windowHandle = hudPanelService.GetWindowHandle(hwnd); if (!WinApi.IsWindow(windowHandle)) { LogProvider.Log.Info(typeof(HudPainter), $"Window {windowHandle} doesn't exist. HUD window can't be created."); return; } var windowInteropHelper = CreateWindowInteropHelper(window, hudLayout, hwnd); var windowItem = new HudWindowItem { Window = window, Handle = windowHandle, OverlayHandle = windowInteropHelper.EnsureHandle() }; using (rwWindowsLock.Write()) { if (windows.ContainsKey(hwnd)) { return; } windows.Add(hwnd, windowItem); } window.Closed += (s, e) => window.Dispatcher.InvokeShutdown(); window.Initialize(hudLayout, hwnd); window.Show(); WinApi.GetWindowRect(windowHandle, out RECT rect); SizeF dpi = Utils.GetCurrentDpi(); SizeF scale = new SizeF() { Width = 96f / dpi.Width, Height = 96f / dpi.Height }; window.Top = rect.Top * scale.Height; window.Left = rect.Left * scale.Width; window.Height = rect.Height * scale.Height; window.Width = rect.Width * scale.Width; windowItem.IsInitialized = true; PrepareWindow(windowItem, hudLayout, hwnd); if (!WinApi.IsIconic(hwnd)) { window.Refresh(); } // workaround for unresponsive PB window after attaching HUD if (hudLayout.PokerSite == EnumPokerSites.PokerBaazi) { WinApi.GetWindowRect(hwnd, out RECT rct); WinApi.SetWindowPos(hwnd, IntPtr.Zero, 0, 0, rct.Width + 1, rct.Height + 1, Swp.NOMOVE | Swp.NOZORDER | Swp.NOACTIVATE); WinApi.SetWindowPos(hwnd, IntPtr.Zero, 0, 0, rct.Width, rct.Height, Swp.NOMOVE | Swp.NOZORDER | Swp.NOACTIVATE); } System.Windows.Threading.Dispatcher.Run(); } catch (Exception e) { LogProvider.Log.Error(typeof(HudPainter), $"Failed to create HUD window for {hwnd}", e); } }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); }
private void LoadDefaultPreset() { HudLayout.LoadDefaultAndSave(); Dialog_Alert.Open(Lang.Get("Dialog_Config.Tab.Content.Preset.DefaultLoaded")); RefreshEditor(); }
public void Initialize(HudLayout layout, IntPtr hWnd) { if (layout == null) { return; } // clean old data Layout?.Cleanup(); Layout = layout; if (ViewModel != null) { ViewModel.SetLayout(layout); ViewModel.WindowHandle = hWnd; if (ViewModel.RefreshHud == null) { ViewModel.RefreshHud = Refresh; } } // set parents for tools Layout.ListHUDPlayer.Select(x => x.HudElement).ForEach(h => h.Tools.ForEach(t => t.Parent = h)); Layout.EmptySeatsViewModels.ForEach(h => h.Tools.ForEach(t => t.Parent = h)); if (hudPanelService == null) { hudPanelService = layout != null? ServiceLocator.Current.GetInstance <IHudPanelService>(layout.PokerSite.ToString()) : ServiceLocator.Current.GetInstance <IHudPanelService>(); } // remove old elements, but remember positions foreach (var panel in dgCanvas.Children.OfType <FrameworkElement>().ToList()) { var toolViewModel = panel.DataContext as HudBaseToolViewModel; ViewModel.UpdatePanelOffset(toolViewModel); if (panel.DataContext is HudTrackConditionsViewModel hudTrackConditionsViewModel) { trackerConditionsMeterPositionOffset = new Point(hudTrackConditionsViewModel.OffsetX ?? 0, hudTrackConditionsViewModel.OffsetY ?? 0); } dgCanvas.Children.Remove(panel); } dgCanvas.UpdateLayout(); // add new elements foreach (var playerHudContent in Layout.ListHUDPlayer) { if (playerHudContent.HudElement == null || string.IsNullOrEmpty(playerHudContent.Name) || playerHudContent.HudElement.Tools == null || playerHudContent.HudElement.Tools.Count < 1) { continue; } var isNoteIconSet = false; foreach (var toolViewModel in playerHudContent.HudElement.Tools.Where(x => x is IHudNonPopupToolViewModel).ToArray()) { if (!isNoteIconSet && toolViewModel is HudPlainStatBoxViewModel && !(toolViewModel is HudFourStatsBoxViewModel)) { (toolViewModel as HudPlainStatBoxViewModel).IsNoteIconEnabled = true; isNoteIconSet = true; } var toolKey = HudWindowViewModel.HudToolKey.BuildKey(toolViewModel); if (ViewModel.PanelOffsets.ContainsKey(toolKey)) { toolViewModel.OffsetX = ViewModel.PanelOffsets[toolKey].X; toolViewModel.OffsetY = ViewModel.PanelOffsets[toolKey].Y; } var panel = hudPanelService.Create(toolViewModel); if (panel != null) { dgCanvas.Children.Add(panel); } } } BuildTrackConditionsMeter(layout.HudTrackConditionsMeter); }
private static void LoadDefaultPreset() { HudLayout.LoadDefault(); Dialog_Alert.Open(Lang.Get("Dialog_Config.Tab.Content.Layout.Preset.DefaultLoaded")); }