Skip to content

Commit

Permalink
Merge pull request #140 from GenieClient/Dev-4-0-2-6
Browse files Browse the repository at this point in the history
This has been heavily tested on the Test Build and has been stable and unchanged for 2 weeks without incident. Thread cut was declared 12/3 and testing has continued.
  • Loading branch information
mj-colonel-panic authored Dec 17, 2022
2 parents 51209dc + 3929bed commit 06d16cd
Show file tree
Hide file tree
Showing 36 changed files with 3,430 additions and 3,040 deletions.
1 change: 1 addition & 0 deletions Core/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2890,6 +2890,7 @@ private void ListSettings()
EchoText("connectscript=" + oGlobals.Config.ConnectScript.ToString() + System.Environment.NewLine);
EchoText("checkforupdates=" + oGlobals.Config.CheckForUpdates.ToString() + System.Environment.NewLine);
EchoText("autoupdate=" + oGlobals.Config.AutoUpdate.ToString() + System.Environment.NewLine);
EchoText("automapperalpha=" + oGlobals.Config.AutoMapperAlpha.ToString() + System.Environment.NewLine);
}

private void ListColors()
Expand Down
9 changes: 7 additions & 2 deletions Core/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,11 @@ public void Connect(string sGenieKey, string sAccountName, string sPassword, str
DoConnect("eaccess.play.net", 7910);
}

public void DirectConnect(string Character, string Game, string Host, int Port, string Key)
{
m_sConnectKey = Key;
DirectConnect(Character, Game, Host, Port);
}
public void DirectConnect(string Character, string Game, string Host, int Port)
{
m_oLastUserActivity = DateTime.Now;
Expand Down Expand Up @@ -592,7 +597,7 @@ public void ParseGameRow(string sText)
default:
break;
}
m_oGlobals.VolatileHighlights.Add(new VolatileHighlight(sTmp, presetLabel, 0));
m_oGlobals.VolatileHighlights.Add(new VolatileHighlight(sTmp, presetLabel, sTextBuffer.Length));
if(presetLabel == "roomdesc")
{
PrintTextWithParse(sTmp, bIsPrompt: false, oWindowTarget: 0);
Expand Down Expand Up @@ -2724,7 +2729,7 @@ public void PrintTextWithParse(string sText, Color color, Color bgcolor, bool bI
}

// Line contains
if (!Information.IsNothing(m_oGlobals.HighlightList.RegexLine))
if (!Information.IsNothing(m_oGlobals.HighlightList.RegexLine) && !string.IsNullOrWhiteSpace(m_oGlobals.HighlightList.RegexLine.ToString()))
{
m_oMatchCollection = m_oGlobals.HighlightList.RegexLine.Matches(sText);
Highlights.Highlight oHighlightString;
Expand Down
139 changes: 76 additions & 63 deletions Forms/Components/ComponentRichTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using GenieClient.Genie;
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using static GenieClient.Genie.Globals;

namespace GenieClient
{
Expand Down Expand Up @@ -362,7 +363,7 @@ private void AddToBuffer(string sText, Color oColor, Color oBgColor, bool bMono
{
m_oRichTextBuffer.SelectionLength = 0;
m_oRichTextBuffer.SelectionStart = int.MaxValue;
int iStart = m_oRichTextBuffer.SelectionStart;
int startIndex = m_oRichTextBuffer.SelectionStart;
if (oColor != Color.Transparent & oColor != m_oEmptyColor)
{
m_oRichTextBuffer.SelectionColor = oColor;
Expand Down Expand Up @@ -397,66 +398,27 @@ private void AddToBuffer(string sText, Color oColor, Color oBgColor, bool bMono
if (sText.Length > 0)
{
m_oRichTextBuffer.SelectedText = sText;
ParseLineHighlight(iStart, sText);
}
}

private void ParseLineHighlight(int iStart, string sLine)
private void ParseLineHighlights(int StartIndex, string Line)
{
Genie.Globals.HighlightRegExp.Highlight oHighlight;
MatchCollection oMatchCollection;
if (Conversions.ToBoolean(m_oParentForm.Globals.HighlightRegExpList.AcquireReaderLock()))
if (m_oRichTextBuffer.Text.Contains("You also see") && m_oParentForm.Globals.RoomObjects.Count > 0)
{
ParseVolatileHighlights(m_oParentForm.Globals.RoomObjects);
}

// Presets and Bold
ParseVolatileHighlights(m_oParentForm.Globals.VolatileHighlights);

//RegExp
if (m_oParentForm.Globals.HighlightRegExpList.AcquireReaderLock())
{
try
{
foreach (DictionaryEntry de in (IEnumerable)m_oParentForm.Globals.HighlightRegExpList)
foreach (Globals.HighlightRegExp.Highlight oHighlight in m_oParentForm.Globals.HighlightRegExpList.Values)
{
oHighlight = (Genie.Globals.HighlightRegExp.Highlight)de.Value;
if (oHighlight.IsActive)
{
oMatchCollection = oHighlight.HighlightRegex.Matches(sLine.Trim(Conversions.ToChar(Constants.vbCr), Conversions.ToChar(Constants.vbLf)));
if (oMatchCollection.Count > 0)
{
foreach (Match oMatch in oMatchCollection)
{
if (oMatch.Groups.Count > 1) // () highlighting
{
for (int I = 1, loopTo = oMatch.Groups.Count - 1; I <= loopTo; I++)
{
int iDiff = sLine.Length - sLine.TrimStart(Conversions.ToChar(Constants.vbCr)).Length; // RichText does not add both cr+lf
m_oRichTextBuffer.SelectionStart = iStart + oMatch.Groups[I].Index + iDiff;
m_oRichTextBuffer.SelectionLength = oMatch.Groups[I].Length;
if (oHighlight.FgColor != Color.Transparent & oHighlight.FgColor != m_oEmptyColor)
{
m_oRichTextBuffer.SelectionColor = oHighlight.FgColor;
}

if (oHighlight.BgColor != Color.Transparent & oHighlight.FgColor != m_oEmptyColor)
{
m_oRichTextBuffer.SelectionBackColor = oHighlight.BgColor;
}
}
}
else // highlight whole line
{
m_oRichTextBuffer.SelectionStart = iStart;
m_oRichTextBuffer.SelectionLength = int.MaxValue;
if (oHighlight.FgColor != Color.Transparent & oHighlight.FgColor != m_oEmptyColor)
{
m_oRichTextBuffer.SelectionColor = oHighlight.FgColor;
}

if (oHighlight.BgColor != Color.Transparent & oHighlight.FgColor != m_oEmptyColor)
{
m_oRichTextBuffer.SelectionBackColor = oHighlight.BgColor;
}
}
}

if (Conversions.ToBoolean(oHighlight.SoundFile.Length > 0 && m_oParentForm.Globals.Config.bPlaySounds))
Sound.PlayWaveFile(oHighlight.SoundFile);
}
}
if (oHighlight.IsActive) ParseRegExpHighlight(oHighlight);
}
}
finally
Expand All @@ -470,6 +432,47 @@ private void ParseLineHighlight(int iStart, string sLine)
}
}

private void ParseRegExpHighlight(int StartIndex, string Line, Globals.HighlightRegExp.Highlight Highlight)
{
int iDiff = Line.Length - Line.TrimStart(Conversions.ToChar(Constants.vbCr)).Length; // RichText does not add both cr+lf
foreach (Match oMatch in Highlight.HighlightRegex.Matches(Line))
{
if (oMatch.Groups.Count > 1) // () highlighting
{
foreach (Group oGroup in oMatch.Groups)
{

m_oRichTextBuffer.SelectionStart = StartIndex + oGroup.Index - iDiff;
m_oRichTextBuffer.SelectionLength = oGroup.Length;
if (Highlight.FgColor != Color.Transparent & Highlight.FgColor != m_oEmptyColor)
{
m_oRichTextBuffer.SelectionColor = Highlight.FgColor;
}
if (Highlight.BgColor != Color.Transparent & Highlight.FgColor != m_oEmptyColor)
{
m_oRichTextBuffer.SelectionBackColor = Highlight.BgColor;
}
}
}
else // highlight the whole match
{
m_oRichTextBuffer.SelectionStart = StartIndex - iDiff;
m_oRichTextBuffer.SelectionLength = oMatch.Length;
if (Highlight.FgColor != Color.Transparent & Highlight.FgColor != m_oEmptyColor)
{
m_oRichTextBuffer.SelectionColor = Highlight.FgColor;
}

if (Highlight.BgColor != Color.Transparent & Highlight.FgColor != m_oEmptyColor)
{
m_oRichTextBuffer.SelectionBackColor = Highlight.BgColor;
}
}
if (Conversions.ToBoolean(Highlight.SoundFile.Length > 0 && m_oParentForm.Globals.Config.bPlaySounds))
Sound.PlayWaveFile(Highlight.SoundFile);
}
}

private Regex oClickRegex = new Regex("{([^{]*):([^{]*)}", MyRegexOptions.options);
private List<Link> LinkList = new List<Link>();

Expand All @@ -480,6 +483,25 @@ private class Link
public string Command;
}

private void ParseRegExpHighlight(HighlightRegExp.Highlight Highlight)
{
foreach (Match oMatch in Highlight.HighlightRegex.Matches(m_oRichTextBuffer.Text))
{
m_oRichTextBuffer.SelectionStart = oMatch.Groups[1].Index;
m_oRichTextBuffer.SelectionLength = oMatch.Groups[1].Length;
if (Highlight.FgColor != Color.Transparent & Highlight.FgColor != m_oEmptyColor)
{
m_oRichTextBuffer.SelectionColor = Highlight.FgColor;
}

if (Highlight.BgColor != Color.Transparent & Highlight.FgColor != m_oEmptyColor)
{
m_oRichTextBuffer.SelectionBackColor = Highlight.BgColor;
}
}

}

private void ParseVolatileHighlights(List<VolatileHighlight> highlightList)
{
foreach (VolatileHighlight highlight in highlightList.ToArray())
Expand Down Expand Up @@ -533,16 +555,7 @@ private void ParseVolatileHighlights(List<VolatileHighlight> highlightList)
private void ParseHighlights()
{
MatchCollection oMatchCollection;

if (m_oRichTextBuffer.Text.Contains("You also see") && m_oParentForm.Globals.RoomObjects.Count > 0)
{
ParseVolatileHighlights(m_oParentForm.Globals.RoomObjects);
}

// Presets and Bold
ParseVolatileHighlights(m_oParentForm.Globals.VolatileHighlights);


ParseLineHighlights(m_oRichTextBuffer.SelectionStart, m_oRichTextBuffer.Text);
// Highlight String
if (!Information.IsNothing(m_oParentForm.Globals.HighlightList.RegexString))
{
Expand Down
87 changes: 87 additions & 0 deletions Forms/Components/MenuRenderer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System;
using System.Drawing;
using System.Windows.Forms;


namespace GenieClient.Forms.Components
{
internal class MenuRenderer : ToolStripProfessionalRenderer
{
private Genie.Globals.Presets Presets;
public MenuRenderer(Genie.Globals.Presets PresetList) : base(new MenuColors(PresetList))
{
Presets = PresetList;
}

protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e)
{
base.OnRenderMenuItemBackground(e);
e.Item.ForeColor = Presets["ui.menu"].FgColor;
e.Item.BackColor = Presets["ui.menu"].BgColor;
}

protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
{
base.OnRenderToolStripBackground(e);
e.ToolStrip.ForeColor = Presets["ui.menu"].FgColor;
e.ToolStrip.BackColor = Presets["ui.menu"].BgColor;
}
}

internal class MenuColors : ProfessionalColorTable
{
Genie.Globals.Presets Presets;
public MenuColors(Genie.Globals.Presets PresetList)
{
Presets = PresetList;
}

public override Color MenuItemPressedGradientBegin
{
get { return Presets["ui.menu.highlight"].FgColor; }
}

public override Color MenuItemPressedGradientMiddle
{
get { return Color.Transparent; }
}
public override Color MenuItemPressedGradientEnd
{
get { return Color.Transparent; }
}

public override Color MenuItemSelectedGradientBegin
{
get { return Color.Transparent; }
}

public override Color MenuItemSelectedGradientEnd
{
get { return Presets["ui.menu.highlight"].FgColor; }
}

public override Color CheckBackground
{
get { return Presets["ui.menu.checked"].FgColor; }
}
public override Color CheckSelectedBackground
{
get { return Presets["ui.menu.highlight"].FgColor; }
}

public override Color ImageMarginGradientBegin
{
get { return Presets["ui.menu"].BgColor; }
}

public override Color ImageMarginGradientMiddle
{
get { return Presets["ui.menu"].BgColor; }
}

public override Color ImageMarginGradientEnd
{
get { return Presets["ui.menu"].BgColor; }
}
}
}
Loading

0 comments on commit 06d16cd

Please sign in to comment.