Blend 5 Posted January 3, 2019 Share Posted January 3, 2019 (edited) Hello devs. Here is my fix of lua color string. Look at screens. Here is the problem: And here is fixed screen: How to fix? Open uitip.py and find self.__AppendText(curTime, text) (must by Class TipBoard, not BigBoard) Repleace to: Quote self.__AppendText(curTime, self.notice(text)) After go to last line of Class TipBoard and paste: Quote def notice(self, text): if text.find("|h") >= 0: self.a = text.split("|h") return self.notice2(self.GetTextNot(self.a, len(self.a))) else: return self.notice2(text) def notice2(self, text): if text.find("|cFF") >= 0: self.x = text while self.x.find("|cFF") >=0: self.le = self.x.find("|cFF")+4 self.a = self.x.split("|cFF" + self.x[self.le] + self.x[self.le+1] + self.x[self.le+2] + self.x[self.le+3] + self.x[self.le+4] + self.x[self.le+5]) self.x = self.GetTextNot(self.a, len(self.a)) if self.x.find("|cff") >= 0: while self.x.find("|cff") >=0: self.le = self.x.find("|cff")+4 self.a = self.x.split("|cff" + self.x[self.le] + self.x[self.le+1] + self.x[self.le+2] + self.x[self.le+3] + self.x[self.le+4] + self.x[self.le+5]) self.x = self.GetTextNot(self.a, len(self.a)) return self.x else: return self.x else: return text def GetTextNot(self, text, c): self.out = "" for i in range(c): self.out = self.out + text return self.out Its all. Nothing hard. Fix by Blend. Edited August 25, 2022 by Metin2 Dev Core X - External 2 Internal 4 Link to comment Share on other sites More sharing options...
Active Member hachiwari 138 Posted January 4, 2019 Active Member Share Posted January 4, 2019 CleanCode:3 1 Link to comment Share on other sites More sharing options...
Forum Moderator VegaS™ 10275 Posted January 4, 2019 Forum Moderator Share Posted January 4, 2019 (edited) This fix is very bad, you can use RE library and fix it with 3-4 lines. https://docs.python.org/2/library/re.html m = re.search('\|c([a-zA-Z0-9]+)\|h', '|cFF29bfbf|hMetin2 is dead.') # TODO: Replace |h|r with: str() # TODO: Replace |c + m.groups()[0] + |h with: str() Is just an example, good luck. Edited August 21, 2022 by Metin2 Dev Core X - External 2 Internal 2 1 6 Check my GitHub Profile Click to find all the threads started by me [TOOL] Text file loader + JSON Link to comment Share on other sites More sharing options...
Blend 5 Posted January 4, 2019 Author Share Posted January 4, 2019 (edited) 15 minutes ago, VegaS™ said: This fix is very bad, you can use RE library and fix it with 3-4 lines. https://docs.python.org/2/library/re.html m = re.search('\|c([a-zA-Z0-9]+)\|h', '|cFF29bfbf|hMetin2 is dead.') # TODO: Replace |h|r with: str() # TODO: Replace |c + m.groups()[0] + |h with: str() Is just an example, good luck. Yes i know use re library, but my client get error if i use re, so i try to find fix without re library. Just with str.find() and str.split(). I think its good example for begginers to learn str. functions. Edited August 21, 2022 by Metin2 Dev Core X - External 2 Internal Link to comment Share on other sites More sharing options...
Active Member Exygo 1091 Posted January 4, 2019 Active Member Share Posted January 4, 2019 def StripColor(self,text): Search = re.search('\|c([a-zA-Z0-9]{0,8})', text) if Search: text = text.replace(Search.group(0),'') text = text.replace('|r','') text = text.replace('|h','') return text https://www.youtube.com/channel/UCQ8mAeda9TWq6SsTzB53emw/videos Link to comment Share on other sites More sharing options...
Premium North 1175 Posted January 6, 2019 Premium Share Posted January 6, 2019 On 1/4/2019 at 2:52 AM, Exygo said: def stripcolor(self, text): if re.search(#regex with groups here, text): return text[1] # returning group cleaned from the color match else: return text # If it doesn't match. This is how you should approach this problem, regex groups are made for this Link to comment Share on other sites More sharing options...
HITRON 695 Posted March 12, 2020 Share Posted March 12, 2020 Any other solution that can you read the colors instead of removing them from the string? Link to comment Share on other sites More sharing options...
Honorable Member Mali 41874 Posted March 16, 2020 Honorable Member Share Posted March 16, 2020 (edited) EterLib/TextBar.cpp: Spoiler #include <regex> void CTextBar::TextOut(int ix, int iy, const char * c_szText) { const auto x = std::regex_replace(c_szText, std::regex("\\|c[a-zA-Z0-9]+|\\|[r|R|H|h]"), ""); c_szText = x.c_str(); if (m_isBold) { // fix SIZE size { 0,0 }; GetTextExtent(c_szText, &size); ix = (500 - size.cx) / 2; } m_dib.TextOut(ix, iy, c_szText); Invalidate(); } or we can use colors instead of removing them https://metin2.download/picture/r3F9504x09DVmF8K988YXgTtGTP6KMUj/.gif Edited August 25, 2022 by Metin2 Dev Core X - External 2 Internal 24 1 6 11 Link to comment Share on other sites More sharing options...
Recommended Posts