Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some moves towards UI isolation #175

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d9ca5a8
[ui-isolation] Extract some MessageBox calls from Network and Core
sorsarre Aug 30, 2021
1dbc0f1
[ui-isolation] Detach gums from WinForms clipboard API
sorsarre Aug 30, 2021
6cdee35
[ui-isolation] Re-implement Filters::Draw in UI code
sorsarre Aug 30, 2021
f808aaf
[ui-isolation] Use bool for OnCheckChanged in Filter
sorsarre Aug 30, 2021
95cfd3d
[ui-isolation] Detach WaypointManager from UI
sorsarre Aug 30, 2021
b2c34f9
[ui-isolation] Unify some listbox updates in UI and remove UI code fr…
sorsarre Aug 30, 2021
ac3a3a2
[ui-isolation] Remove UI code from OverheadManager
sorsarre Aug 30, 2021
6023ac1
[ui-isolation] Get rid of UI code in TargetFilterManager
sorsarre Aug 30, 2021
48c65df
[ui-isolation] Remove UI code from SoundMusicManager
sorsarre Aug 30, 2021
c5773dd
[ui-isolation] Make OverheadMessages read-only in OverheadManager
sorsarre Aug 30, 2021
b2d226a
[ui-isolation] Fix startup crash in WaypointManager
sorsarre Aug 31, 2021
3137e54
[ui-isolation] Pass handle instead of the whole form in Client.SetMap…
sorsarre Aug 31, 2021
a96ab07
Get rid of UI code in base Filter
sorsarre Sep 3, 2021
2a1365f
Remove UI code from WaypointManager
sorsarre Sep 3, 2021
3fa9373
Remove UI code from TextFilterManager
sorsarre Sep 3, 2021
987a52b
Add UpdateListBox method to main window
sorsarre Sep 3, 2021
83461fc
Merge branch 'ui-isolation-updatelistbox' into ui-isolation-waypoints
sorsarre Sep 3, 2021
14d8dbf
Merge branch 'ui-isolation-updatelistbox' into ui-isolation-textfilte…
sorsarre Sep 3, 2021
981bd61
Merge branch 'ui-isolation-updatelistbox' into ui-isolation-targetfil…
sorsarre Sep 3, 2021
ea4aed4
Get rid of UI code in TargetFilterManager
sorsarre Sep 3, 2021
53b8ca7
Get rid of UI code in OverheadManager
sorsarre Sep 3, 2021
7300cda
Fix up method names
sorsarre Sep 3, 2021
174705f
Merge branch 'ui-isolation-updatelistbox' into ui-isolation-soundmusi…
sorsarre Sep 3, 2021
b3f455e
Remove UI code from SoundMusicManager
sorsarre Sep 3, 2021
fe6d29d
Merge branch 'ui-isolation-filters' into ui-isolation-convergence
sorsarre Sep 3, 2021
414190f
Merge branch 'ui-isolation-waypoints' into ui-isolation-convergence
sorsarre Sep 3, 2021
419b8e5
Merge branch 'ui-isolation-textfiltermanager' into ui-isolation-conve…
sorsarre Sep 3, 2021
4b3d584
Merge branch 'ui-isolation-targetfiltermanager' into ui-isolation-con…
sorsarre Sep 3, 2021
ae0c56b
Merge branch 'ui-isolation-soundmusicmanager' into ui-isolation-conve…
sorsarre Sep 3, 2021
251200d
Merge branch 'ui-isolation-overheadmanager' into ui-isolation-converg…
sorsarre Sep 3, 2021
e39d7d6
Pass handle instead of the whole form in Client.SetMapWndHandle
sorsarre Sep 3, 2021
fb1af9d
Merge branch 'ui-isolation-setmapwndhandle' into ui-isolation-converg…
sorsarre Sep 3, 2021
1cf60a8
Merge branch 'ui-isolation' into ui-isolation-convergence
sorsarre Sep 4, 2021
3653927
Merge branch 'master' into ui-isolation-convergence
sorsarre Sep 4, 2021
f8b09a2
Merge branch 'master' into ui-isolation
sorsarre Sep 5, 2021
577b86f
[ui-isolation] Clean up some member naming issues
sorsarre Sep 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Razor/Client/ClassicUO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public class ClassicUOClient : Client
private static OnFocusLost _onFocusLost;
private IntPtr m_ClientWindow;

public override void SetMapWndHandle(Form mapWnd)
public override void SetMapWndHandle(IntPtr mapWndHandle)
{
}

Expand Down
3 changes: 1 addition & 2 deletions Razor/Client/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
using System.Diagnostics;
using System.Net;
using System.Text;
using System.Windows.Forms;

namespace Assistant
{
Expand Down Expand Up @@ -98,7 +97,7 @@ public void SetFeatures(ulong features)

public abstract bool ClientRunning { get; }

public abstract void SetMapWndHandle(Form mapWnd);
public abstract void SetMapWndHandle(IntPtr mapWndHandle);

public abstract void RequestStatbarPatch(bool preAOS);

Expand Down
4 changes: 2 additions & 2 deletions Razor/Client/OSI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ public override bool ClientRunning
}
}

public override void SetMapWndHandle(Form mapWnd)
public override void SetMapWndHandle(IntPtr mapWndHandle)
{
Platform.PostMessage(FindUOWindow(), WM_UONETEVENT, (IntPtr) UONetMessage.SetMapHWnd, mapWnd.Handle);
Platform.PostMessage(FindUOWindow(), WM_UONETEVENT, (IntPtr) UONetMessage.SetMapHWnd, mapWndHandle);
}

public override void RequestStatbarPatch(bool preAOS)
Expand Down
97 changes: 32 additions & 65 deletions Razor/Core/OverheadManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using Assistant.UI;
using Ultima;

namespace Assistant.Core
{
Expand All @@ -37,13 +33,10 @@ public class OverheadMessage

public static class OverheadManager
{
private static ListView _listView;

public static List<OverheadMessage> OverheadMessages = new List<OverheadMessage>();

public static void SetControls(ListView listView)
{
_listView = listView;
private static readonly List<OverheadMessage> _overheadMessages = new List<OverheadMessage>();
public static IReadOnlyList<OverheadMessage> OverheadMessages
{
get { return _overheadMessages; }
}

public static void Save(XmlTextWriter xml)
Expand Down Expand Up @@ -75,7 +68,7 @@ public static void Load(XmlElement node)
: Convert.ToInt32(el.GetAttribute("hue"))
};

OverheadMessages.Add(overheadMessage);
_overheadMessages.Add(overheadMessage);
}
}
catch
Expand All @@ -86,7 +79,7 @@ public static void Load(XmlElement node)

public static void ClearAll()
{
OverheadMessages.Clear();
_overheadMessages.Clear();
}

public static void Remove(string text)
Expand All @@ -95,37 +88,12 @@ public static void Remove(string text)
{
if (message.SearchMessage.Equals(text))
{
OverheadMessages.Remove(message);
_overheadMessages.Remove(message);
break;
}
}
}

public static void RedrawList()
{
_listView.SafeAction(s => s.Items.Clear());

foreach (OverheadMessage message in OverheadMessages)
{
ListViewItem item = new ListViewItem($"{message.SearchMessage}");
item.SubItems.Add(new ListViewItem.ListViewSubItem(item, message.MessageOverhead));

int hueIdx = message.Hue;

if (hueIdx > 0 && hueIdx < 3000)
item.SubItems[1].BackColor = Hues.GetHue(hueIdx - 1).GetColor(HueEntry.TextHueIDX);
else
item.SubItems[1].BackColor = SystemColors.Control;

item.SubItems[1].ForeColor =
(item.SubItems[1].BackColor.GetBrightness() < 0.35 ? Color.White : Color.Black);

item.UseItemStyleForSubItems = false;

_listView.SafeAction(s => s.Items.Add(item));
}
}

public static void DisplayOverheadMessage(string text)
{
if (Config.GetBool("ShowOverheadMessages") && OverheadMessages.Count > 0)
Expand Down Expand Up @@ -154,34 +122,33 @@ public static void DisplayOverheadMessage(string text)
}
}

public static void SetOverheadHue()
{
ListViewItem selectedItem = _listView.Items[_listView.SelectedIndices[0]];

HueEntry h = new HueEntry(GetHue(selectedItem.SubItems[1].Text));

if (h.ShowDialog(Engine.MainWindow) == DialogResult.OK)
{
int hueIdx = h.Hue;

if (hueIdx > 0 && hueIdx < 3000)
selectedItem.SubItems[1].BackColor = Hues.GetHue(hueIdx - 1).GetColor(HueEntry.TextHueIDX);
else
selectedItem.SubItems[1].BackColor = Color.White;
public static void SetMessageHue(string text, int hue)
{
foreach (var message in OverheadMessages)
{
if (message.SearchMessage.Equals(text))
{
message.Hue = hue;
break;
}
}
}

selectedItem.SubItems[1].ForeColor = (selectedItem.SubItems[1].BackColor.GetBrightness() < 0.35
? Color.White
: Color.Black);
public static void AddOverheadMessage(OverheadMessage message)
{
_overheadMessages.Add(message);
}

foreach (OverheadMessage list in OverheadManager.OverheadMessages)
{
if (list.SearchMessage.Equals(selectedItem.Text))
{
list.Hue = hueIdx;
break;
}
}
}
public static void ReplaceOverheadMessage(string oldMessage, string newMessage)
{
foreach (var message in OverheadMessages)
{
if (message.MessageOverhead.Equals(oldMessage))
{
message.MessageOverhead = newMessage;
break;
}
}
}

public static int GetHue(string id)
Expand Down
35 changes: 6 additions & 29 deletions Razor/Core/TextFilterManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,28 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;
using System.Xml;
using Assistant.UI;

namespace Assistant.Core
{
public static class TextFilterManager
{
private static ListBox _filterTextList;

public static List<string> FilteredText = new List<string>();

public static void SetControls(ListBox filterTextList)
{
_filterTextList = filterTextList;
}
public delegate void ItemsChangedCallback();

public static ItemsChangedCallback OnItemsChanged { get; set; }

public static void AddFilter(string filter)
{
FilteredText.Add(filter);

RedrawList();
OnItemsChanged?.Invoke();
}

public static void RemoveFilter(string filter)
{
FilteredText.Remove(filter);

RedrawList();
OnItemsChanged?.Invoke();
}

public static void Save(XmlTextWriter xml)
Expand Down Expand Up @@ -89,7 +82,7 @@ public static void Load(XmlElement node)
FilteredText.Add(Convert.ToString(el.GetAttribute("text")));
}

RedrawList();
OnItemsChanged?.Invoke();
}
catch (Exception ex)
{
Expand All @@ -101,21 +94,5 @@ public static void ClearAll()
{
FilteredText.Clear();
}

public static void RedrawList()
{
_filterTextList?.SafeAction(s =>
{
s.BeginUpdate();
s.Items.Clear();

foreach (string text in FilteredText)
{
s.Items.Add(text);
}

s.EndUpdate();
});
}
}
}
43 changes: 9 additions & 34 deletions Razor/Core/WaypointManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,30 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;
using System.Xml;
using Assistant.UI;

namespace Assistant.Core
{
public static class WaypointManager
{
private static ListBox _waypointList;
private static WaypointDistanceTimer _waypointTimer;

public static Waypoint CurrentWaypoint;
private static int _curWaypointIndex;

public static List<Waypoint> Waypoints = new List<Waypoint>();

public delegate void WaypointsChangedCallback();

public static WaypointsChangedCallback OnWaypointsChanged;

public static void Initialize()
{
HotKey.Add(HKCategory.Misc, LocString.NextWaypoint, new HotKeyCallback(NextWaypoint));
HotKey.Add(HKCategory.Misc, LocString.PrevWaypoint, new HotKeyCallback(PrevWaypoint));
HotKey.Add(HKCategory.Misc, LocString.HideWaypoint, new HotKeyCallback(ClearWaypoint));
}

public static void SetControls(ListBox waypointList)
{
_waypointList = waypointList;
_waypointTimer = new WaypointDistanceTimer();
_waypointTimer.Stop();
}

public class Waypoint
{
public int X { get; set; }
Expand Down Expand Up @@ -86,17 +80,14 @@ public static void PrevWaypoint()
public static void AddWaypoint(Waypoint waypoint)
{
Waypoints.Add(waypoint);

RedrawList();
OnWaypointsChanged?.Invoke();
}

public static void RemoveWaypoint(Waypoint waypoint)
{
ClearWaypoint();

Waypoints.Remove(waypoint);

RedrawList();
Waypoints.Remove(waypoint);
OnWaypointsChanged?.Invoke();
}

public static void ShowWaypoint(Waypoint waypoint)
Expand Down Expand Up @@ -124,7 +115,7 @@ public static void ClearWaypoint()

public static void ResetTimer()
{
if (_waypointTimer.Running)
if (_waypointTimer != null && _waypointTimer.Running)
{
_waypointTimer.Stop();
_waypointTimer = new WaypointDistanceTimer();
Expand Down Expand Up @@ -221,7 +212,7 @@ public static void Load(XmlElement node)
Waypoints.Add(waypoint);
}

RedrawList();
OnWaypointsChanged?.Invoke();
}
catch (Exception ex)
{
Expand All @@ -233,21 +224,5 @@ public static void ClearAll()
{
Waypoints.Clear();
}

public static void RedrawList()
{
_waypointList?.SafeAction(s =>
{
s.BeginUpdate();
s.Items.Clear();

foreach (Waypoint waypoint in Waypoints)
{
s.Items.Add(waypoint);
}

s.EndUpdate();
});
}
}
}
Loading