-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
556 additions
and
360 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Text; | ||
using WzComparerR2.Text; | ||
|
||
namespace WzComparerR2.Rendering | ||
{ | ||
public class XnaFontRenderer : TextRenderer<XnaFont> | ||
{ | ||
public XnaFontRenderer(SpriteBatchEx spriteBatch) | ||
{ | ||
this.SpriteBatch = spriteBatch; | ||
} | ||
|
||
public SpriteBatchEx SpriteBatch { get; set; } | ||
|
||
|
||
protected override void MeasureRuns(List<Run> runs) | ||
{ | ||
int x = 0; | ||
foreach (var run in runs) | ||
{ | ||
if (run.IsBreakLine) | ||
{ | ||
run.X = x; | ||
run.Length = 0; | ||
} | ||
else | ||
{ | ||
var size = base.font.MeasureString(base.sb, run.StartIndex, run.Length); | ||
run.X = x; | ||
run.Width = (int)size.X; | ||
x += run.Width; | ||
} | ||
} | ||
} | ||
|
||
protected override Rectangle[] MeasureChars(int startIndex, int length) | ||
{ | ||
var regions = new Rectangle[length]; | ||
int x = 0; | ||
for (int i = 0; i < length; i++) | ||
{ | ||
var rect = this.font.TryGetRect(this.sb[startIndex + i]); | ||
regions[i] = new Rectangle(x, 0, rect.Width, rect.Height); | ||
x += rect.Width; | ||
} | ||
return regions; | ||
} | ||
|
||
protected override void Flush(StringBuilder sb, int startIndex, int length, int x, int y, string colorID) | ||
{ | ||
var color = this.GetColor(colorID); | ||
var pos = new Microsoft.Xna.Framework.Vector2(x, y); | ||
this.SpriteBatch.DrawStringEx(this.font, sb, startIndex, length, pos, color); | ||
} | ||
|
||
public virtual Microsoft.Xna.Framework.Color GetColor(string colorID) | ||
{ | ||
switch (colorID) | ||
{ | ||
case "c": | ||
return new Microsoft.Xna.Framework.Color(255, 153, 0); | ||
default: | ||
return Microsoft.Xna.Framework.Color.White; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Drawing; | ||
|
||
namespace WzComparerR2.Text | ||
{ | ||
public abstract class DocElement | ||
{ | ||
} | ||
|
||
public sealed class Span : DocElement | ||
{ | ||
public string ColorID { get; set; } | ||
public string Text { get; set; } | ||
} | ||
|
||
public sealed class LineBreak : DocElement | ||
{ | ||
private LineBreak() { } | ||
public static readonly LineBreak Instance = new LineBreak(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace WzComparerR2.Text | ||
{ | ||
public class Parser | ||
{ | ||
private Parser() | ||
{ | ||
} | ||
|
||
public static IList<DocElement> Parse(string format) | ||
{ | ||
var elements = new List<DocElement>(); | ||
var sb = new StringBuilder(); | ||
var colorStack = new Stack<string>(); | ||
colorStack.Push(""); | ||
|
||
int strPos = 0; | ||
char curChar; | ||
|
||
int offset = 0; | ||
|
||
Action flushRun = () => | ||
{ | ||
if (offset < format.Length) | ||
{ | ||
elements.Add(new Span() | ||
{ | ||
Text = sb.ToString(offset, sb.Length - offset), | ||
ColorID = colorStack.Peek() | ||
}); | ||
offset = sb.Length; | ||
} | ||
}; | ||
|
||
while (strPos < format.Length) | ||
{ | ||
curChar = format[strPos++]; | ||
if (curChar == '\\') | ||
{ | ||
if (strPos < format.Length) | ||
{ | ||
curChar = format[strPos++]; | ||
switch (curChar) | ||
{ | ||
case 'r': curChar = '\r'; break; | ||
case 'n': curChar = '\n'; break; | ||
} | ||
} | ||
else //结束符处理 | ||
{ | ||
curChar = '#'; | ||
} | ||
} | ||
|
||
switch (curChar) | ||
{ | ||
case '#': | ||
if (strPos < format.Length && format[strPos] == 'c')//遇到#c 换橙刷子并flush | ||
{ | ||
flushRun(); | ||
colorStack.Push("c"); | ||
strPos++; | ||
} | ||
else if (strPos < format.Length && format[strPos] == 'g')//遇到#g(自定义) 换绿刷子并flush | ||
{ | ||
flushRun(); | ||
colorStack.Push("g"); | ||
strPos++; | ||
} | ||
else if (strPos < format.Length && format[strPos] == '$')//遇到#$(自定义) 换青色刷子并flush | ||
{ | ||
flushRun(); | ||
colorStack.Push("$"); | ||
strPos++; | ||
} | ||
else if (colorStack.Count == 1) //同#c | ||
{ | ||
flushRun(); | ||
colorStack.Push("c"); | ||
strPos++; | ||
} | ||
else//遇到# 换白刷子并flush | ||
{ | ||
flushRun(); | ||
colorStack.Pop(); | ||
} | ||
break; | ||
|
||
case '\r': //忽略 | ||
break; | ||
|
||
case '\n': //插入换行 | ||
flushRun(); | ||
elements.Add(LineBreak.Instance); | ||
break; | ||
|
||
default: | ||
sb.Append(curChar); | ||
break; | ||
} | ||
} | ||
|
||
flushRun(); | ||
return elements; | ||
} | ||
} | ||
} |
Oops, something went wrong.
79c4f70
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated my version with all your commits. I have noticed this change:
BEFORE
![](https://camo.githubusercontent.com/fdde4b5f9b7b66d9e6eba8ab51ff9600de2128ceab8fde2617ed739a4009e2b7/68747470733a2f2f63646e2e646973636f72646170702e636f6d2f6174746163686d656e74732f3234343435383131323836343438353337382f3333383431363338323230343936383936312f416e7469416c69617347726964467269742e706e67)
AFTER
![](https://camo.githubusercontent.com/b99173dd57bdcbca2f61a118b81b5605b3cf86f0dc883757775e1abe0baee476/68747470733a2f2f63646e2e646973636f72646170702e636f6d2f6174746163686d656e74732f3233363138303530323230303035373835362f3333383432383835363433383438393038382f312e706e67)
The alignment has been slightly shifted towards the right and the color of the set info is white as if you see it equipped. It should be gray.
EDIT 2:
It should be noted that for the color change to White. I did this commit before you pushed the update: KENNYSOFT@07dd56e (SetItemTooltipRender.cs > lines 241, 249, 264, 270)
I have fixed this issue of white text by reverting the code as linked above.
EDIT 3:
In-game
![](https://camo.githubusercontent.com/2a6beab9aeda382e4574c7ac10dd47b84457f7d5d5bcf0dc4be03824270cada0/68747470733a2f2f63646e2e646973636f72646170702e636f6d2f6174746163686d656e74732f38383939323135313634333336393437322f3333383435383631343736393338353437332f696e67616d652e706e67)
Simulation before your update
![](https://camo.githubusercontent.com/bbade16e6e67a02ca145c6c6ac8d0ff2aa7c787907024f0a3487165358f9afbe/68747470733a2f2f63646e2e646973636f72646170702e636f6d2f6174746163686d656e74732f38383939323135313634333336393437322f3333383435383636343130323932303139322f6265666f72652e706e67)
Simulation after your update
![](https://camo.githubusercontent.com/d7002290ee67d684a0a4496ecc26abdf28942319e4fca8d05cb3b91f89c65a05/68747470733a2f2f63646e2e646973636f72646170702e636f6d2f6174746163686d656e74732f38383939323135313634333336393437322f3333383435383639313031333537343635362f61667465722e706e67)
Before the update, it was
GearGraphics.DrawString(g, propStr, font, 11, 256, ref picH, 15)
(Almost everything in GearTooltipRender2.cs has 11 as value because it matched. I now changed it to 8 to match it, but as you can see the potential icon and text below is not exactly aligned.79c4f70
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Sunaries Maybe this example will tell you how the bugs come out.
79c4f70
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I'm still puzzled.
79c4f70
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Sunaries So.. maybe I missed
NoPadding
flags in GDI version,(Yes it's a bug and should be fixed :) ) and all of the antient GDI+(g.DrawString) codes missedStringFormat.GenericTypographic
parameter, so there are two offsets in the code.79c4f70
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, there's
StringFormat.GenericTypography
flag! That function is why I changed to GDI functions in KMS version. Now I can go back with GDI+.79c4f70
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Kagamia Adding
NoPadding
worked. :) Thank you.@KENNYSOFT Ah, I see. GDI+ is more beneficial than GDI.