NPCDialogs.cs 128 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587
  1. using System.Collections.Generic;
  2. using System.Globalization;
  3. using System.Text.RegularExpressions;
  4. using Client.MirControls;
  5. using Client.MirGraphics;
  6. using Client.MirNetwork;
  7. using Client.MirObjects;
  8. using Client.MirSounds;
  9. using Font = System.Drawing.Font;
  10. using C = ClientPackets;
  11. using S = ServerPackets;
  12. using System.Diagnostics;
  13. namespace Client.MirScenes.Dialogs
  14. {
  15. public sealed class NPCDialog : MirImageControl
  16. {
  17. public static Regex R = new Regex(@"<((.*?)\/(\@.*?))>");
  18. public static Regex C = new Regex(@"{((.*?)\/(.*?))}");
  19. public static Regex L = new Regex(@"\(((.*?)\/(.*?))\)");
  20. public static Regex B = new Regex(@"<<((.*?)\/(\@.*?))>>");
  21. // New regex patterns for NPC/Monster/Item linking (using IDX)
  22. public static Regex MonsterLink = new Regex(@"\[MONSTER:(?<idx>\d+)(\|(?<name>[^\]]+))?\]|<\$MONSTER:(?<idx>\d+)>", RegexOptions.IgnoreCase);
  23. public static Regex NPCLink = new Regex(@"\[NPC:(?<idx>\d+)(\|(?<name>[^\]]+))?\]|<\$NPC:(?<idx>\d+)>", RegexOptions.IgnoreCase);
  24. public static Regex ItemLink = new Regex(@"\[ITEM:(?<idx>\d+)(\|(?<name>[^\]]+))?\]|<\$ITEM:(?<idx>\d+)>", RegexOptions.IgnoreCase);
  25. public MirButton CloseButton, UpButton, DownButton, PositionBar, QuestButton, HelpButton;
  26. public MirLabel[] TextLabel;
  27. public List<MirLabel> TextButtons;
  28. public List<BigButton> BigButtons;
  29. public BigButtonDialog BigButtonDialog;
  30. public MirLabel NameLabel;
  31. Font font = new Font(Settings.FontName, 9F);
  32. private static readonly HashSet<int> PendingMapInfoRequests = new HashSet<int>();
  33. public List<string> CurrentLines = new List<string>();
  34. private int _index = 0;
  35. public int MaximumLines = 8;
  36. // Tooltip control for linked objects
  37. private MirControl _tooltipPanel;
  38. private MirImageControl _tooltipImage;
  39. private MirLabel _tooltipTitle;
  40. private MirLabel _tooltipContent;
  41. public NPCDialog()
  42. {
  43. Index = 995;
  44. Library = Libraries.Prguse;
  45. // Hide tooltip when dialog is clicked
  46. this.MouseDown += (o, e) => HideTooltip();
  47. TextLabel = new MirLabel[30];
  48. TextButtons = new List<MirLabel>();
  49. BigButtons = new List<BigButton>();
  50. Size = Size;
  51. AutoSize = false;
  52. MouseWheel += NPCDialog_MouseWheel;
  53. Sort = true;
  54. NameLabel = new MirLabel
  55. {
  56. Text = "",
  57. Parent = this,
  58. Font = new Font(Settings.FontName, 10F, FontStyle.Bold),
  59. ForeColour = Color.BurlyWood,
  60. Location = new Point(30, 6),
  61. AutoSize = true
  62. };
  63. UpButton = new MirButton
  64. {
  65. Index = 197,
  66. HoverIndex = 198,
  67. PressedIndex = 199,
  68. Library = Libraries.Prguse2,
  69. Parent = this,
  70. Size = new Size(16, 14),
  71. Location = new Point(417, 34),
  72. Sound = SoundList.ButtonA,
  73. Visible = false
  74. };
  75. UpButton.Click += (o, e) =>
  76. {
  77. if (_index <= 0) return;
  78. _index--;
  79. NewText(CurrentLines, false);
  80. UpdatePositionBar();
  81. };
  82. DownButton = new MirButton
  83. {
  84. Index = 207,
  85. HoverIndex = 208,
  86. Library = Libraries.Prguse2,
  87. PressedIndex = 209,
  88. Parent = this,
  89. Size = new Size(16, 14),
  90. Location = new Point(417, 175),
  91. Sound = SoundList.ButtonA,
  92. Visible = false
  93. };
  94. DownButton.Click += (o, e) =>
  95. {
  96. if (_index + MaximumLines >= CurrentLines.Count) return;
  97. _index++;
  98. NewText(CurrentLines, false);
  99. UpdatePositionBar();
  100. };
  101. PositionBar = new MirButton
  102. {
  103. Index = 205,
  104. HoverIndex = 206,
  105. PressedIndex = 206,
  106. Library = Libraries.Prguse2,
  107. Location = new Point(417, 47),
  108. Parent = this,
  109. Movable = true,
  110. Sound = SoundList.None,
  111. Visible = false
  112. };
  113. PositionBar.OnMoving += PositionBar_OnMoving;
  114. CloseButton = new MirButton
  115. {
  116. HoverIndex = 361,
  117. Index = 360,
  118. Location = new Point(413, 3),
  119. Library = Libraries.Prguse2,
  120. Parent = this,
  121. PressedIndex = 362,
  122. Sound = SoundList.ButtonA,
  123. };
  124. CloseButton.Click += (o, e) => Hide();
  125. HelpButton = new MirButton
  126. {
  127. Index = 257,
  128. HoverIndex = 258,
  129. PressedIndex = 259,
  130. Library = Libraries.Prguse2,
  131. Parent = this,
  132. Location = new Point(390, 3),
  133. Sound = SoundList.ButtonA,
  134. };
  135. HelpButton.Click += (o, e) => GameScene.Scene.HelpDialog.DisplayPage(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Purchasing));
  136. BigButtonDialog = new BigButtonDialog()
  137. {
  138. Parent = this,
  139. };
  140. QuestButton = new MirAnimatedButton()
  141. {
  142. Animated = true,
  143. AnimationCount = 10,
  144. Loop = true,
  145. AnimationDelay = 130,
  146. Index = 530,
  147. HoverIndex = 284,
  148. PressedIndex = 286,
  149. Library = Libraries.Title,
  150. Parent = this,
  151. Size = new Size(96, 25),
  152. Sound = SoundList.ButtonA,
  153. Visible = false
  154. };
  155. QuestButton.Click += (o, e) => GameScene.Scene.QuestListDialog.Toggle();
  156. // Initialize tooltip panel
  157. InitializeTooltipPanel();
  158. }
  159. private void InitializeTooltipPanel()
  160. {
  161. // Use simple background like item tooltips
  162. _tooltipPanel = new MirControl
  163. {
  164. Parent = GameScene.Scene,
  165. Visible = false,
  166. NotControl = true,
  167. Sort = true,
  168. BackColour = Color.FromArgb(240, 80, 60, 40), // Darker brownish color
  169. Border = true,
  170. BorderColour = Color.FromArgb(255, 120, 100, 80), // Brownish border
  171. DrawControlTexture = true,
  172. Modal = false
  173. };
  174. _tooltipImage = new MirImageControl
  175. {
  176. Parent = _tooltipPanel,
  177. Visible = false,
  178. NotControl = true,
  179. Size = new Size(48, 48),
  180. Location = new Point(10, 10),
  181. DrawImage = true
  182. };
  183. _tooltipTitle = new MirLabel
  184. {
  185. Parent = _tooltipPanel,
  186. AutoSize = true,
  187. ForeColour = Color.Yellow, // Title in yellow like KR
  188. Location = new Point(70, 5),
  189. NotControl = true,
  190. OutLine = true
  191. };
  192. _tooltipContent = new MirLabel
  193. {
  194. Parent = _tooltipPanel,
  195. AutoSize = true,
  196. ForeColour = Color.White, // Content in white
  197. Location = new Point(70, 25),
  198. NotControl = true,
  199. DrawFormat = TextFormatFlags.WordBreak | TextFormatFlags.ExpandTabs,
  200. OutLine = true
  201. };
  202. }
  203. void NPCDialog_MouseWheel(object sender, MouseEventArgs e)
  204. {
  205. int count = e.Delta / SystemInformation.MouseWheelScrollDelta;
  206. if (_index == 0 && count >= 0) return;
  207. if (_index == CurrentLines.Count - 1 && count <= 0) return;
  208. if (CurrentLines.Count <= MaximumLines) return;
  209. _index -= count;
  210. if (_index < 0) _index = 0;
  211. if (_index + MaximumLines > CurrentLines.Count - 1) _index = CurrentLines.Count - MaximumLines;
  212. NewText(CurrentLines, false);
  213. UpdatePositionBar();
  214. }
  215. void PositionBar_OnMoving(object sender, MouseEventArgs e)
  216. {
  217. int x = 417;
  218. int y = PositionBar.Location.Y;
  219. if (y >= 155) y = 155;
  220. if (y <= 47) y = 47;
  221. int location = y - 47;
  222. int interval = 108 / (CurrentLines.Count - MaximumLines);
  223. double yPoint = location / interval;
  224. _index = Convert.ToInt16(Math.Floor(yPoint));
  225. NewText(CurrentLines, false);
  226. PositionBar.Location = new Point(x, y);
  227. }
  228. private void UpdatePositionBar()
  229. {
  230. if (CurrentLines.Count <= MaximumLines) return;
  231. int interval = 108 / (CurrentLines.Count - MaximumLines);
  232. int x = 417;
  233. int y = 48 + (_index * interval);
  234. if (y >= 155) y = 155;
  235. if (y <= 47) y = 47;
  236. PositionBar.Location = new Point(x, y);
  237. }
  238. private void ButtonClicked(string action)
  239. {
  240. if (action == "@Exit")
  241. {
  242. Hide();
  243. return;
  244. }
  245. if (CMain.Time <= GameScene.NPCTime) return;
  246. GameScene.NPCTime = CMain.Time + 5000;
  247. Network.Enqueue(new C.CallNPC { ObjectID = GameScene.NPCID, Key = $"[{action}]" });
  248. }
  249. public void NewText(List<string> lines, bool resetIndex = true)
  250. {
  251. Size = TrueSize;
  252. if (resetIndex)
  253. {
  254. _index = 0;
  255. CurrentLines = lines;
  256. UpdatePositionBar();
  257. for (int i = lines.Count - 1; i >= 0; i--)
  258. {
  259. string currentLine = lines[i];
  260. List<Match> bigButtonSortedList = B.Matches(currentLine).Cast<Match>().OrderBy(o => o.Index).ToList();
  261. for (int j = 0; j < bigButtonSortedList.Count; j++)
  262. {
  263. Match match = bigButtonSortedList[j];
  264. Capture capture = match.Groups[1].Captures[0];
  265. string txt = match.Groups[2].Captures[0].Value;
  266. string action = match.Groups[3].Captures[0].Value;
  267. string colourString = "RoyalBlue";
  268. string[] actionSplit = action.Split('/');
  269. action = actionSplit[0];
  270. if (actionSplit.Length > 1)
  271. colourString = actionSplit[1];
  272. Color color = Color.FromName(colourString);
  273. BigButton button = new BigButton
  274. {
  275. Index = 841,
  276. HoverIndex = 842,
  277. PressedIndex = 843,
  278. Library = Libraries.Title,
  279. Sound = SoundList.ButtonA,
  280. Text = txt,
  281. FontColour = Color.White,
  282. ForeColour = color
  283. };
  284. button.Click += (o, e) =>
  285. {
  286. ButtonClicked(action);
  287. };
  288. BigButtons.Insert(0, button);
  289. }
  290. var bigButtonString = B.ToString();
  291. var oldCurrentLine = currentLine;
  292. currentLine = Regex.Replace(currentLine, bigButtonString, "");
  293. if (string.IsNullOrWhiteSpace(currentLine) && oldCurrentLine != currentLine)
  294. lines.RemoveAt(i);
  295. }
  296. if (BigButtons.Count > 0)
  297. {
  298. int minimumButtons = 0;
  299. if (string.IsNullOrWhiteSpace(string.Concat(lines)))
  300. {
  301. BigButtonDialog.Location = new Point(1, 27);
  302. minimumButtons = 4;
  303. }
  304. else
  305. BigButtonDialog.Location = new Point(1, Size.Height - 33);
  306. BigButtonDialog.Show(BigButtons, minimumButtons);
  307. Size = new Size(Size.Width, BigButtonDialog.Location.Y + BigButtonDialog.Size.Height);
  308. }
  309. }
  310. if (lines.Count > MaximumLines)
  311. {
  312. Index = 385;
  313. UpButton.Visible = true;
  314. DownButton.Visible = true;
  315. PositionBar.Visible = true;
  316. }
  317. else
  318. {
  319. Index = 384;
  320. UpButton.Visible = false;
  321. DownButton.Visible = false;
  322. PositionBar.Visible = false;
  323. }
  324. QuestButton.Location = new Point(172, Size.Height - 30);
  325. for (int i = 0; i < TextButtons.Count; i++)
  326. TextButtons[i].Dispose();
  327. for (int i = 0; i < TextLabel.Length; i++)
  328. {
  329. if (TextLabel[i] != null) TextLabel[i].Text = "";
  330. }
  331. TextButtons.Clear();
  332. int lastLine = lines.Count > MaximumLines ? ((MaximumLines + _index) > lines.Count ? lines.Count : (MaximumLines + _index)) : lines.Count;
  333. for (int i = _index; i < lastLine; i++)
  334. {
  335. TextLabel[i] = new MirLabel
  336. {
  337. Font = font,
  338. DrawFormat = TextFormatFlags.WordBreak,
  339. Visible = true,
  340. Parent = this,
  341. Size = new Size(420, 20),
  342. Location = new Point(8, 34 + (i - _index) * 18),
  343. NotControl = true
  344. };
  345. if (i >= lines.Count)
  346. {
  347. TextLabel[i].Text = string.Empty;
  348. continue;
  349. }
  350. string currentLine = lines[i];
  351. List<Match> matchList = R.Matches(currentLine).Cast<Match>().ToList();
  352. matchList.AddRange(C.Matches(currentLine).Cast<Match>());
  353. matchList.AddRange(L.Matches(currentLine).Cast<Match>());
  354. matchList.AddRange(MonsterLink.Matches(currentLine).Cast<Match>());
  355. matchList.AddRange(NPCLink.Matches(currentLine).Cast<Match>());
  356. matchList.AddRange(ItemLink.Matches(currentLine).Cast<Match>());
  357. int oldLength = currentLine.Length;
  358. foreach (Match match in matchList.OrderBy(o => o.Index).ToList())
  359. {
  360. int offSet = oldLength - currentLine.Length;
  361. // Handle new link types FIRST (Monster, NPC, Item)
  362. bool isMonsterLink = MonsterLink.Match(match.Value).Success;
  363. bool isNPCLink = NPCLink.Match(match.Value).Success;
  364. bool isItemLink = ItemLink.Match(match.Value).Success;
  365. if (isMonsterLink || isNPCLink || isItemLink)
  366. {
  367. // Extract the index from the link
  368. string linkIdx = match.Groups["idx"].Captures.Count > 0 ? match.Groups["idx"].Captures[0].Value : match.Groups["idx"].Value;
  369. string providedName = match.Groups["name"].Success ? match.Groups["name"].Captures[0].Value : null;
  370. string linkType = "ITEM";
  371. switch (true)
  372. {
  373. case true when isMonsterLink:
  374. linkType = "MONSTER";
  375. break;
  376. case true when isNPCLink:
  377. linkType = "NPC";
  378. break;
  379. }
  380. string displayName = GetDisplayNameForLink(linkType, linkIdx, providedName);
  381. if (string.IsNullOrEmpty(displayName)) displayName = $"LINK_{linkIdx}";
  382. int matchStart = match.Index - offSet;
  383. int matchLength = match.Length;
  384. currentLine = currentLine.Remove(matchStart, matchLength).Insert(matchStart, displayName);
  385. string textUpToLink = currentLine.Substring(0, matchStart);
  386. Point offset = CalculateLinkOffset(textUpToLink, TextLabel[i]);
  387. NewLink(displayName, linkType, linkIdx, TextLabel[i].Location.Add(offset));
  388. continue;
  389. }
  390. bool hasMultipleGroups = match.Groups.Count > 3 && match.Groups[2].Captures.Count > 0 && match.Groups[3].Captures.Count > 0;
  391. if (hasMultipleGroups)
  392. {
  393. Capture capture = match.Groups[1].Captures[0];
  394. string txt = match.Groups[2].Captures[0].Value;
  395. string action = match.Groups[3].Captures[0].Value;
  396. currentLine = currentLine.Remove(capture.Index - 1 - offSet, capture.Length + 2).Insert(capture.Index - 1 - offSet, txt);
  397. string text2 = currentLine.Substring(0, capture.Index - 1 - offSet) + " ";
  398. Size size2 = TextRenderer.MeasureText(CMain.Graphics, text2, TextLabel[i].Font, TextLabel[i].Size, TextFormatFlags.TextBoxControl);
  399. if (R.Match(match.Value).Success)
  400. NewButton(txt, action, TextLabel[i].Location.Add(new Point(size2.Width - 10, 0)));
  401. if (C.Match(match.Value).Success)
  402. NewColour(txt, action, TextLabel[i].Location.Add(new Point(size2.Width - 10, 0)));
  403. if (L.Match(match.Value).Success)
  404. NewButton(txt, null, TextLabel[i].Location.Add(new Point(size2.Width - 10, 0)), action);
  405. }
  406. }
  407. TextLabel[i].Text = currentLine;
  408. TextLabel[i].MouseWheel += NPCDialog_MouseWheel;
  409. }
  410. }
  411. private void NewButton(string text, string key, Point p, string link = "")
  412. {
  413. MirLabel temp = new MirLabel
  414. {
  415. AutoSize = true,
  416. Visible = true,
  417. Parent = this,
  418. Location = p,
  419. Text = text,
  420. ForeColour = Color.Yellow,
  421. Sound = SoundList.ButtonC,
  422. Font = font
  423. };
  424. temp.MouseEnter += (o, e) => temp.ForeColour = Color.Red;
  425. temp.MouseLeave += (o, e) => temp.ForeColour = Color.Yellow;
  426. temp.MouseDown += (o, e) => temp.ForeColour = Color.Yellow;
  427. temp.MouseUp += (o, e) => temp.ForeColour = Color.Red;
  428. if (!string.IsNullOrEmpty(link))
  429. {
  430. temp.Click += (o, e) =>
  431. {
  432. if (link.StartsWith("http://", true, CultureInfo.InvariantCulture))
  433. {
  434. System.Diagnostics.Process.Start(new ProcessStartInfo
  435. {
  436. FileName = link,
  437. UseShellExecute = true
  438. });
  439. }
  440. };
  441. }
  442. else
  443. {
  444. temp.Click += (o, e) =>
  445. {
  446. ButtonClicked(key);
  447. };
  448. }
  449. temp.MouseWheel += NPCDialog_MouseWheel;
  450. TextButtons.Add(temp);
  451. }
  452. private void NewColour(string text, string colour, Point p)
  453. {
  454. Color textColour = Color.FromName(colour);
  455. MirLabel temp = new MirLabel
  456. {
  457. AutoSize = true,
  458. Visible = true,
  459. Parent = this,
  460. Location = p,
  461. Text = text,
  462. ForeColour = textColour,
  463. Font = font
  464. };
  465. temp.MouseWheel += NPCDialog_MouseWheel;
  466. TextButtons.Add(temp);
  467. }
  468. private void NewLink(string text, string linkType, string linkName, Point p)
  469. {
  470. MirLabel temp = new MirLabel
  471. {
  472. AutoSize = true,
  473. Visible = true,
  474. Parent = this,
  475. Location = p,
  476. Text = text,
  477. ForeColour = Color.Cyan,
  478. Font = font,
  479. NotControl = false // Make sure it can receive mouse events
  480. };
  481. temp.MouseEnter += (o, e) =>
  482. {
  483. temp.ForeColour = Color.Orange;
  484. // All link types (MONSTER, NPC, ITEM) now use the custom ShowTooltip method
  485. ShowTooltip(linkType, linkName, temp.DisplayLocation);
  486. };
  487. temp.MouseLeave += (o, e) =>
  488. {
  489. temp.ForeColour = Color.Cyan;
  490. HideTooltip();
  491. };
  492. temp.Click += (o, e) =>
  493. {
  494. HideTooltip();
  495. };
  496. temp.MouseWheel += NPCDialog_MouseWheel;
  497. TextButtons.Add(temp);
  498. }
  499. private void ShowTooltip(string linkType, string linkName, Point anchor)
  500. {
  501. if (_tooltipPanel == null) return;
  502. string title = "";
  503. string content = "";
  504. bool showImage = false;
  505. switch (linkType)
  506. {
  507. case "MONSTER":
  508. // Get monster name instead of index
  509. if (int.TryParse(linkName, out int monsterIdx))
  510. {
  511. var monsterInfo = GameScene.MonsterInfoList.FirstOrDefault(x => x.Index == monsterIdx);
  512. if (monsterInfo != null)
  513. {
  514. string monsterName = string.IsNullOrEmpty(monsterInfo.GameName) ? monsterInfo.Name : monsterInfo.GameName;
  515. title = monsterName;
  516. content = GetMonsterInfo(linkName);
  517. // Show monster image
  518. if ((ushort)monsterInfo.Image < Libraries.Monsters.Length)
  519. {
  520. _tooltipImage.Library = Libraries.Monsters[(ushort)monsterInfo.Image];
  521. _tooltipImage.Index = 20;
  522. _tooltipImage.Location = new Point(10, 10);
  523. showImage = true;
  524. }
  525. }
  526. else
  527. {
  528. GameScene.RequestMonsterInfo(monsterIdx);
  529. title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.MonsterIndexTitle, linkName);
  530. content = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.MonsterInfoLoading);
  531. }
  532. }
  533. else
  534. {
  535. title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.MonsterIndexTitle, linkName);
  536. content = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.InvalidLinkIndex);
  537. }
  538. break;
  539. case "NPC":
  540. // Get NPC name instead of index
  541. if (int.TryParse(linkName, out int npcIdx))
  542. {
  543. var npcInfo = GameScene.NPCInfoList.FirstOrDefault(x => x.Index == npcIdx);
  544. if (npcInfo != null)
  545. {
  546. title = npcInfo.Name;
  547. content = GetNPCInfo(linkName);
  548. // Show NPC image
  549. if (npcInfo.Image < Libraries.NPCs.Length)
  550. {
  551. _tooltipImage.Library = Libraries.NPCs[npcInfo.Image];
  552. _tooltipImage.Index = 0;
  553. _tooltipImage.Location = new Point(10, 10);
  554. showImage = true;
  555. }
  556. }
  557. else
  558. {
  559. GameScene.RequestNPCInfo(npcIdx);
  560. title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NPCIndexTitle, linkName);
  561. content = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NPCInfoLoading);
  562. }
  563. }
  564. else
  565. {
  566. title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NPCIndexTitle, linkName);
  567. content = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.InvalidLinkIndex);
  568. }
  569. break;
  570. case "ITEM":
  571. // Get item name instead of index
  572. if (int.TryParse(linkName, out int itemIdx))
  573. {
  574. var item = GameScene.ItemInfoList.FirstOrDefault(x => x.Index == itemIdx);
  575. if (item != null)
  576. {
  577. title = item.FriendlyName ?? item.Name;
  578. content = GetItemInfo(linkName);
  579. // Show item image using Items_Tooltip_32bit library for KR style
  580. _tooltipImage.Library = Libraries.Items_Tooltip_32bit;
  581. _tooltipImage.Index = item.Image;
  582. _tooltipImage.Location = new Point(10, 10);
  583. showImage = true;
  584. }
  585. else
  586. {
  587. GameScene.RequestItemInfo(itemIdx);
  588. title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ItemIndexTitle, linkName);
  589. content = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ItemInfoLoading);
  590. }
  591. }
  592. else
  593. {
  594. title = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ItemIndexTitle, linkName);
  595. content = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.InvalidLinkIndex);
  596. }
  597. break;
  598. }
  599. // Set image size BEFORE setting text and calculating panel size
  600. int imageWidth = 0;
  601. int imageHeight = 0;
  602. if (showImage && _tooltipImage.Library != null)
  603. {
  604. // Get actual size from library
  605. Size libSize = _tooltipImage.Library.GetSize(_tooltipImage.Index);
  606. if (!libSize.IsEmpty)
  607. {
  608. imageWidth = libSize.Width;
  609. imageHeight = libSize.Height;
  610. _tooltipImage.Size = new Size(imageWidth, imageHeight);
  611. }
  612. else
  613. {
  614. // Fallback to Items library if Items_Tooltip_32bit image not found
  615. if (_tooltipImage.Library == Libraries.Items_Tooltip_32bit && linkType == "ITEM")
  616. {
  617. Size fallbackSize = Libraries.Items.GetSize(_tooltipImage.Index);
  618. if (!fallbackSize.IsEmpty)
  619. {
  620. _tooltipImage.Library = Libraries.Items;
  621. imageWidth = fallbackSize.Width;
  622. imageHeight = fallbackSize.Height;
  623. _tooltipImage.Size = new Size(imageWidth, imageHeight);
  624. }
  625. }
  626. }
  627. }
  628. // Now set text and position
  629. _tooltipTitle.Text = title;
  630. _tooltipContent.Text = content;
  631. if (showImage)
  632. {
  633. _tooltipTitle.Location = new Point(imageWidth + 20, 5);
  634. _tooltipContent.Location = new Point(imageWidth + 20, 27);
  635. }
  636. else
  637. {
  638. _tooltipTitle.Location = new Point(10, 5);
  639. _tooltipContent.Location = new Point(10, 27);
  640. }
  641. _tooltipImage.Visible = showImage;
  642. // Calculate panel size based on content
  643. int imageOffset = showImage ? imageWidth + 20 : 10;
  644. int contentHeight = _tooltipTitle.Size.Height + _tooltipContent.Size.Height + 30;
  645. // Panel height should be at least as tall as the image + padding at top and bottom
  646. int minPanelHeight = showImage ? imageHeight + 20 : contentHeight;
  647. int panelHeight = Math.Max(minPanelHeight, contentHeight);
  648. _tooltipPanel.Size = new Size(Math.Max(200, Math.Max(_tooltipTitle.Size.Width, _tooltipContent.Size.Width) + imageOffset + 20),
  649. panelHeight);
  650. _tooltipPanel.Location = new Point(anchor.X + 20, anchor.Y + 20);
  651. _tooltipPanel.BringToFront();
  652. _tooltipPanel.Sort = true;
  653. if (_tooltipPanel.Parent != null)
  654. {
  655. var parent = _tooltipPanel.Parent as MirControl;
  656. if (parent != null)
  657. {
  658. parent.InsertControl(parent.Controls.Count, _tooltipPanel);
  659. }
  660. }
  661. _tooltipPanel.Visible = true;
  662. }
  663. private void HideTooltip()
  664. {
  665. if (_tooltipPanel != null)
  666. _tooltipPanel.Visible = false;
  667. }
  668. private string GetMonsterInfo(string monsterIdx)
  669. {
  670. if (int.TryParse(monsterIdx, out int idx))
  671. {
  672. var monster = GameScene.MonsterInfoList.FirstOrDefault(x => x.Index == idx);
  673. if (monster != null)
  674. {
  675. return string.Join("\n", new[]
  676. {
  677. GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.MonsterTooltipLevel, monster.Level),
  678. GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.MonsterTooltipHealth, monster.Stats[Stat.HP]),
  679. GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.MonsterTooltipExperience, monster.Experience),
  680. GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.MonsterTooltipDC, monster.Stats[Stat.MinDC], monster.Stats[Stat.MaxDC]),
  681. GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.MonsterTooltipMC, monster.Stats[Stat.MinMC], monster.Stats[Stat.MaxMC]),
  682. GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.MonsterTooltipAC, monster.Stats[Stat.MinAC], monster.Stats[Stat.MaxAC]),
  683. GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.MonsterTooltipMAC, monster.Stats[Stat.MinMAC], monster.Stats[Stat.MaxMAC])
  684. });
  685. }
  686. GameScene.RequestMonsterInfo(idx);
  687. return GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.MonsterIndexLoading, idx);
  688. }
  689. return GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.InvalidMonsterIndex);
  690. }
  691. private string GetNPCInfo(string npcIdx)
  692. {
  693. if (int.TryParse(npcIdx, out int idx))
  694. {
  695. var npc = GameScene.NPCInfoList.FirstOrDefault(x => x.Index == idx);
  696. if (npc != null)
  697. {
  698. string mapName = string.Empty;
  699. // Try to get from current map if we're on that map
  700. if (GameScene.Scene.MapControl != null && GameScene.Scene.MapControl.Index == npc.MapIndex)
  701. {
  702. mapName = GameScene.Scene.MapControl.Title;
  703. }
  704. // Otherwise try MapInfoList
  705. else if (npc.MapIndex > 0 && GameScene.MapInfoList.TryGetValue(npc.MapIndex, out var mapInfo))
  706. {
  707. if (mapInfo?.MapInfo != null && !string.IsNullOrEmpty(mapInfo.MapInfo.Title))
  708. {
  709. mapName = mapInfo.MapInfo.Title;
  710. }
  711. }
  712. // Otherwise no map info yet; we will request it below if needed
  713. List<string> npcInfoLines = new List<string>
  714. {
  715. GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NPCTooltipName, npc.Name)
  716. };
  717. if (!string.IsNullOrWhiteSpace(mapName))
  718. {
  719. npcInfoLines.Add(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NPCTooltipLocation, mapName));
  720. }
  721. else if (npc.MapIndex > 0)
  722. {
  723. if (!PendingMapInfoRequests.Contains(npc.MapIndex) && !GameScene.MapInfoList.ContainsKey(npc.MapIndex))
  724. {
  725. PendingMapInfoRequests.Add(npc.MapIndex);
  726. Network.Enqueue(new C.RequestMapInfo() { MapIndex = npc.MapIndex });
  727. }
  728. // Show a loading placeholder while we wait for the map title to arrive.
  729. npcInfoLines.Add(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NPCTooltipLocation, GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NPCTooltipMapLoading)));
  730. }
  731. else
  732. {
  733. npcInfoLines.Add(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NPCTooltipLocation, GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NPCTooltipUnknownMap)));
  734. }
  735. npcInfoLines.Add(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NPCTooltipCoordinates, npc.Location.X, npc.Location.Y));
  736. return string.Join("\n", npcInfoLines);
  737. }
  738. GameScene.RequestNPCInfo(idx);
  739. return GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NPCIndexLoading, idx);
  740. }
  741. return GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.InvalidNPCIndex);
  742. }
  743. private string GetItemInfo(string itemIdx)
  744. {
  745. if (int.TryParse(itemIdx, out int idx))
  746. {
  747. var item = GameScene.ItemInfoList.FirstOrDefault(x => x.Index == idx);
  748. if (item != null)
  749. {
  750. List<string> infoLines = new List<string>();
  751. string localizedType = item.Type.ToLocalizedString();
  752. if (!string.IsNullOrEmpty(localizedType))
  753. {
  754. infoLines.Add(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ItemTooltipType, localizedType));
  755. }
  756. if (item.RequiredType == RequiredType.Level && item.RequiredAmount > 0)
  757. {
  758. infoLines.Add(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.RequiredLevel, item.RequiredAmount));
  759. }
  760. if (item.ClassBased)
  761. {
  762. infoLines.Add(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ClassRequired, item.RequiredClass.ToLocalizedString()));
  763. }
  764. if (item.Weight > 0)
  765. {
  766. infoLines.Add(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ItemTooltipWeight, item.Weight));
  767. }
  768. return string.Join("\n", infoLines);
  769. }
  770. GameScene.RequestItemInfo(idx);
  771. return GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ItemIndexLoading, idx);
  772. }
  773. return GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.InvalidItemIndex);
  774. }
  775. public static string GetDisplayNameForLink(string linkType, string linkIdx, string providedName = null)
  776. {
  777. if (!string.IsNullOrEmpty(providedName))
  778. return providedName;
  779. if (int.TryParse(linkIdx, out int idx))
  780. {
  781. switch (linkType)
  782. {
  783. case "ITEM":
  784. var item = GameScene.ItemInfoList.FirstOrDefault(x => x.Index == idx);
  785. if (item != null)
  786. return item.FriendlyName ?? item.Name ?? $"Item {idx}";
  787. GameScene.RequestItemInfo(idx);
  788. return $"Item {idx}";
  789. case "MONSTER":
  790. var monster = GameScene.MonsterInfoList.FirstOrDefault(x => x.Index == idx);
  791. if (monster != null)
  792. return string.IsNullOrEmpty(monster.GameName) ? monster.Name : monster.GameName;
  793. GameScene.RequestMonsterInfo(idx);
  794. return $"Monster {idx}";
  795. case "NPC":
  796. var npc = GameScene.NPCInfoList.FirstOrDefault(x => x.Index == idx);
  797. if (npc != null)
  798. return npc.Name;
  799. GameScene.RequestNPCInfo(idx);
  800. return $"NPC {idx}";
  801. default:
  802. return linkIdx;
  803. }
  804. }
  805. return linkIdx;
  806. }
  807. public static void ShowTooltipForLink(string linkType, string linkIdx, Point anchor)
  808. {
  809. if (GameScene.Scene.NPCDialog == null) return;
  810. GameScene.Scene.NPCDialog.ShowTooltip(linkType, linkIdx, anchor);
  811. }
  812. public static void HideTooltipForLink()
  813. {
  814. if (GameScene.Scene.NPCDialog == null) return;
  815. GameScene.Scene.NPCDialog.HideTooltip();
  816. }
  817. private static readonly TextFormatFlags LinkMeasureFlags = TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix;
  818. internal static Point CalculateLinkOffset(string text, MirLabel label)
  819. {
  820. if (label == null || string.IsNullOrEmpty(text))
  821. return Point.Empty;
  822. int maxWidth = Math.Max(1, label.Size.Width);
  823. int x = 0;
  824. int y = 0;
  825. foreach (char ch in text)
  826. {
  827. if (ch == '\r') continue;
  828. if (ch == '\n')
  829. {
  830. x = 0;
  831. y += label.Font.Height;
  832. continue;
  833. }
  834. string character = ch.ToString();
  835. Size size = TextRenderer.MeasureText(CMain.Graphics, character, label.Font, new Size(int.MaxValue, int.MaxValue), LinkMeasureFlags);
  836. if (x + size.Width > maxWidth && x > 0)
  837. {
  838. x = 0;
  839. y += label.Font.Height;
  840. }
  841. x += size.Width;
  842. }
  843. return new Point(x, y);
  844. }
  845. public void CheckQuestButtonDisplay()
  846. {
  847. NameLabel.Text = string.Empty;
  848. QuestButton.Visible = false;
  849. NPCObject npc = (NPCObject)MapControl.GetObject(GameScene.NPCID);
  850. if (npc != null)
  851. {
  852. string[] nameSplit = npc.Name.Split('_');
  853. NameLabel.Text = nameSplit[0];
  854. if (npc.GetAvailableQuests().Any())
  855. QuestButton.Visible = true;
  856. }
  857. }
  858. public override void Hide()
  859. {
  860. Visible = false;
  861. GameScene.Scene.NPCGoodsDialog.Hide();
  862. GameScene.Scene.NPCSubGoodsDialog.Hide();
  863. GameScene.Scene.NPCCraftGoodsDialog.Hide();
  864. GameScene.Scene.NPCDropDialog.Hide();
  865. GameScene.Scene.NPCAwakeDialog.Hide();
  866. GameScene.Scene.RefineDialog.Hide();
  867. GameScene.Scene.StorageDialog.Hide();
  868. GameScene.Scene.TrustMerchantDialog.Hide();
  869. GameScene.Scene.QuestListDialog.Hide();
  870. GameScene.Scene.InventoryDialog.Location = new Point(0, 0);
  871. GameScene.Scene.RollControl.Hide();
  872. GameScene.Scene.GuildTerritoryDialog.Hide();
  873. BigButtonDialog.Hide();
  874. HideTooltip();
  875. }
  876. public override void Show()
  877. {
  878. GameScene.Scene.InventoryDialog.Location = new Point(Size.Width + 5, 0);
  879. Visible = true;
  880. CheckQuestButtonDisplay();
  881. }
  882. }
  883. public sealed class NPCGoodsDialog : MirImageControl
  884. {
  885. public PanelType PType;
  886. public bool UsePearls;
  887. public int StartIndex;
  888. public UserItem SelectedItem;
  889. public List<UserItem> Goods = new List<UserItem>();
  890. public List<UserItem> DisplayGoods = new List<UserItem>();
  891. public MirGoodsCell[] Cells;
  892. public MirButton BuyButton, CloseButton;
  893. public MirImageControl BuyLabel;
  894. public MirButton UpButton, DownButton, PositionBar;
  895. public NPCGoodsDialog(PanelType type)
  896. {
  897. PType = type;
  898. Index = 1000;
  899. Library = Libraries.Prguse;
  900. Location = new Point(0, 224);
  901. Cells = new MirGoodsCell[8];
  902. Sort = true;
  903. for (int i = 0; i < Cells.Length; i++)
  904. {
  905. Cells[i] = new MirGoodsCell
  906. {
  907. Parent = this,
  908. Location = new Point(10, 34 + i * 33),
  909. Sound = SoundList.ButtonC
  910. };
  911. Cells[i].Click += (o, e) =>
  912. {
  913. SelectedItem = ((MirGoodsCell)o).Item;
  914. Update();
  915. if (PType == PanelType.Craft)
  916. {
  917. GameScene.Scene.CraftDialog.ResetCells();
  918. GameScene.Scene.CraftDialog.RefreshCraftCells(SelectedItem);
  919. if (!GameScene.Scene.CraftDialog.Visible)
  920. {
  921. GameScene.Scene.CraftDialog.Show();
  922. }
  923. }
  924. };
  925. Cells[i].MouseWheel += NPCGoodsPanel_MouseWheel;
  926. Cells[i].DoubleClick += (o, e) =>
  927. {
  928. if (PType == PanelType.Craft) return;
  929. BuyItem();
  930. };
  931. }
  932. CloseButton = new MirButton
  933. {
  934. HoverIndex = 361,
  935. Index = 360,
  936. Location = new Point(217, 3),
  937. Library = Libraries.Prguse2,
  938. Parent = this,
  939. PressedIndex = 362,
  940. Sound = SoundList.ButtonA,
  941. };
  942. CloseButton.Click += (o, e) => Hide();
  943. BuyButton = new MirButton
  944. {
  945. HoverIndex = 313,
  946. Index = 312,
  947. Location = new Point(77, 304),
  948. Library = Libraries.Title,
  949. Parent = this,
  950. PressedIndex = 314,
  951. Sound = SoundList.ButtonA,
  952. };
  953. BuyButton.Click += (o, e) => BuyItem();
  954. BuyLabel = new MirImageControl
  955. {
  956. Index = 27,
  957. Library = Libraries.Title,
  958. Parent = this,
  959. Location = new Point(20, 9),
  960. };
  961. if (PType == PanelType.Craft)
  962. {
  963. BuyLabel.Index = 12;
  964. BuyButton.Visible = false;
  965. }
  966. UpButton = new MirButton
  967. {
  968. Index = 197,
  969. HoverIndex = 198,
  970. Library = Libraries.Prguse2,
  971. Location = new Point(219, 35),
  972. Parent = this,
  973. PressedIndex = 199,
  974. Sound = SoundList.ButtonA
  975. };
  976. UpButton.Click += (o, e) =>
  977. {
  978. if (StartIndex == 0) return;
  979. StartIndex--;
  980. Update();
  981. };
  982. DownButton = new MirButton
  983. {
  984. Index = 207,
  985. HoverIndex = 208,
  986. Library = Libraries.Prguse2,
  987. Location = new Point(219, 284),
  988. Parent = this,
  989. PressedIndex = 209,
  990. Sound = SoundList.ButtonA
  991. };
  992. DownButton.Click += (o, e) =>
  993. {
  994. if (DisplayGoods.Count <= 8) return;
  995. if (StartIndex == DisplayGoods.Count - 8) return;
  996. StartIndex++;
  997. Update();
  998. };
  999. PositionBar = new MirButton
  1000. {
  1001. Index = 205,
  1002. HoverIndex = 206,
  1003. Library = Libraries.Prguse2,
  1004. Location = new Point(219, 49),
  1005. Parent = this,
  1006. PressedIndex = 206,
  1007. Movable = true,
  1008. Sound = SoundList.None
  1009. };
  1010. PositionBar.OnMoving += PositionBar_OnMoving;
  1011. PositionBar.MouseUp += (o, e) => Update();
  1012. }
  1013. private bool CheckSubGoods()
  1014. {
  1015. if (SelectedItem == null) return false;
  1016. if (PType == PanelType.Buy && !UsePearls)
  1017. {
  1018. var list = Goods.Where(x => x.Info.Index == SelectedItem.Info.Index).ToList();
  1019. if (list.Count > 1 || GameScene.Scene.NPCSubGoodsDialog.Visible)
  1020. {
  1021. GameScene.Scene.NPCSubGoodsDialog.NewGoods(list);
  1022. GameScene.Scene.NPCSubGoodsDialog.Show();
  1023. return true;
  1024. }
  1025. }
  1026. return false;
  1027. }
  1028. private void BuyItem()
  1029. {
  1030. if (SelectedItem == null) return;
  1031. if (CheckSubGoods())
  1032. {
  1033. return;
  1034. }
  1035. if (SelectedItem.Info.StackSize > 1)
  1036. {
  1037. ushort tempCount = SelectedItem.Count;
  1038. ushort maxQuantity = SelectedItem.Info.StackSize;
  1039. SelectedItem.Count = maxQuantity;
  1040. if (UsePearls)
  1041. {
  1042. if (SelectedItem.Price() > GameScene.User.PearlCount)
  1043. {
  1044. maxQuantity = Math.Min(ushort.MaxValue, (ushort)(GameScene.Gold / (SelectedItem.Price() / SelectedItem.Count)));
  1045. if (maxQuantity == 0)
  1046. {
  1047. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NotEnoughPearls), ChatType.System);
  1048. return;
  1049. }
  1050. }
  1051. }
  1052. else if (SelectedItem.Price() > GameScene.Gold)
  1053. {
  1054. maxQuantity = Math.Min(ushort.MaxValue, (ushort)(GameScene.Gold / (SelectedItem.Price() / SelectedItem.Count)));
  1055. if (maxQuantity == 0)
  1056. {
  1057. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.LowGold), ChatType.System);
  1058. return;
  1059. }
  1060. }
  1061. MapObject.User.GetMaxGain(SelectedItem);
  1062. if (SelectedItem.Count == 0)
  1063. {
  1064. SelectedItem.Count = tempCount;
  1065. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.YouNoBagSpace), ChatType.System);
  1066. return;
  1067. }
  1068. if (SelectedItem.Count < maxQuantity)
  1069. {
  1070. maxQuantity = SelectedItem.Count;
  1071. }
  1072. if (SelectedItem.Count > tempCount)
  1073. {
  1074. SelectedItem.Count = tempCount;
  1075. }
  1076. MirAmountBox amountBox = new(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.PurchaseAmount), SelectedItem.Image, maxQuantity, 0, SelectedItem.Count);
  1077. amountBox.OKButton.Click += (o, e) =>
  1078. {
  1079. if (amountBox.Amount > 0)
  1080. {
  1081. Network.Enqueue(new C.BuyItem { ItemIndex = SelectedItem.UniqueID, Count = (ushort)amountBox.Amount, Type = PanelType.Buy });
  1082. }
  1083. };
  1084. amountBox.Show();
  1085. }
  1086. else
  1087. {
  1088. if (SelectedItem.Info.Price > GameScene.Gold)
  1089. {
  1090. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.LowGold), ChatType.System);
  1091. return;
  1092. }
  1093. for (int i = 0; i < MapObject.User.Inventory.Length; i++)
  1094. {
  1095. if (MapObject.User.Inventory[i] == null) break;
  1096. if (i == MapObject.User.Inventory.Length - 1)
  1097. {
  1098. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.YouNoBagSpace), ChatType.System);
  1099. return;
  1100. }
  1101. }
  1102. Network.Enqueue(new C.BuyItem { ItemIndex = SelectedItem.UniqueID, Count = 1, Type = PanelType.Buy });
  1103. }
  1104. }
  1105. private void NPCGoodsPanel_MouseWheel(object sender, MouseEventArgs e)
  1106. {
  1107. int count = e.Delta / SystemInformation.MouseWheelScrollDelta;
  1108. if (StartIndex == 0 && count >= 0) return;
  1109. if (StartIndex == DisplayGoods.Count - 1 && count <= 0) return;
  1110. StartIndex -= count;
  1111. Update();
  1112. }
  1113. private void Update()
  1114. {
  1115. if (StartIndex > DisplayGoods.Count - 8) StartIndex = DisplayGoods.Count - 8;
  1116. if (StartIndex <= 0) StartIndex = 0;
  1117. if (DisplayGoods.Count > 8)
  1118. {
  1119. PositionBar.Visible = true;
  1120. int h = 233 - PositionBar.Size.Height;
  1121. h = (int)((h / (float)(DisplayGoods.Count - 8)) * StartIndex);
  1122. PositionBar.Location = new Point(219, 49 + h);
  1123. }
  1124. else
  1125. PositionBar.Visible = false;
  1126. for (int i = 0; i < 8; i++)
  1127. {
  1128. if (i + StartIndex >= DisplayGoods.Count)
  1129. {
  1130. Cells[i].Visible = false;
  1131. continue;
  1132. }
  1133. Cells[i].Visible = true;
  1134. var matchingGoods = Goods.Where(x => x.Info.Index == Cells[i].Item.Info.Index);
  1135. Cells[i].Item = DisplayGoods[i + StartIndex];
  1136. Cells[i].MultipleAvailable = matchingGoods.Count() > 1 && matchingGoods.Any(x => x.IsShopItem == false);
  1137. Cells[i].Border = SelectedItem != null && Cells[i].Item == SelectedItem;
  1138. Cells[i].UsePearls = UsePearls;
  1139. }
  1140. }
  1141. private void PositionBar_OnMoving(object sender, MouseEventArgs e)
  1142. {
  1143. const int x = 219;
  1144. int y = PositionBar.Location.Y;
  1145. if (y >= 282 - PositionBar.Size.Height) y = 282 - PositionBar.Size.Height;
  1146. if (y < 49) y = 49;
  1147. int h = 233 - PositionBar.Size.Height;
  1148. h = (int)Math.Round(((y - 49) / (h / (float)(DisplayGoods.Count - 8))));
  1149. PositionBar.Location = new Point(x, y);
  1150. if (h == StartIndex) return;
  1151. StartIndex = h;
  1152. Update();
  1153. }
  1154. public void NewGoods(IEnumerable<UserItem> list)
  1155. {
  1156. Goods.Clear();
  1157. DisplayGoods.Clear();
  1158. AddGoods(list);
  1159. }
  1160. public void AddGoods(IEnumerable<UserItem> list)
  1161. {
  1162. if (PType == PanelType.BuySub)
  1163. {
  1164. StartIndex = 0;
  1165. SelectedItem = null;
  1166. list = list.OrderBy(x => x.Price());
  1167. }
  1168. foreach (UserItem item in list)
  1169. {
  1170. //Normal shops just want to show one of each item type
  1171. if (PType == PanelType.Buy && !UsePearls)
  1172. {
  1173. Goods.Add(item);
  1174. if (DisplayGoods.Any(x => x.Info.Index == item.Info.Index)) continue;
  1175. }
  1176. DisplayGoods.Add(item);
  1177. }
  1178. if (GameScene.Scene.NPCSubGoodsDialog.Visible)
  1179. {
  1180. CheckSubGoods();
  1181. }
  1182. Update();
  1183. }
  1184. public override void Hide()
  1185. {
  1186. Visible = false;
  1187. if (GameScene.Scene.CraftDialog.Visible)
  1188. {
  1189. GameScene.Scene.CraftDialog.Hide();
  1190. }
  1191. }
  1192. public override void Show()
  1193. {
  1194. for (int i = 0; i < Cells.Length; i++)
  1195. {
  1196. Cells[i].Recipe = PType == PanelType.Craft;
  1197. }
  1198. Location = new Point(Location.X, GameScene.Scene.NPCDialog.Size.Height);
  1199. Visible = true;
  1200. GameScene.Scene.InventoryDialog.Show();
  1201. }
  1202. }
  1203. public sealed class NPCDropDialog : MirImageControl
  1204. {
  1205. public readonly MirButton ConfirmButton, HoldButton;
  1206. public readonly MirItemCell ItemCell;
  1207. public MirItemCell OldCell;
  1208. public readonly MirLabel InfoLabel;
  1209. public PanelType PType;
  1210. public static UserItem TargetItem;
  1211. public bool Hold;
  1212. public NPCDropDialog()
  1213. {
  1214. Index = 392;
  1215. Library = Libraries.Prguse;
  1216. Location = new Point(264, 224);
  1217. Sort = true;
  1218. Click += NPCDropPanel_Click;
  1219. HoldButton = new MirButton
  1220. {
  1221. HoverIndex = 294,
  1222. Index = 293,
  1223. Location = new Point(114, 36),
  1224. Library = Libraries.Title,
  1225. Parent = this,
  1226. PressedIndex = 295,
  1227. Sound = SoundList.ButtonA,
  1228. };
  1229. HoldButton.Click += (o, e) => Hold = !Hold;
  1230. ConfirmButton = new MirButton
  1231. {
  1232. HoverIndex = 291,
  1233. Index = 290,
  1234. Location = new Point(114, 62),
  1235. Library = Libraries.Title,
  1236. Parent = this,
  1237. PressedIndex = 292,
  1238. Sound = SoundList.ButtonA,
  1239. };
  1240. ConfirmButton.Click += (o, e) => Confirm();
  1241. InfoLabel = new MirLabel
  1242. {
  1243. AutoSize = true,
  1244. Location = new Point(30, 10),
  1245. Parent = this,
  1246. NotControl = true,
  1247. };
  1248. ItemCell = new MirItemCell
  1249. {
  1250. BorderColour = Color.Lime,
  1251. GridType = MirGridType.DropPanel,
  1252. Library = Libraries.Items,
  1253. Parent = this,
  1254. Location = new Point(38, 72),
  1255. };
  1256. ItemCell.Click += (o, e) => ItemCell_Click();
  1257. BeforeDraw += NPCDropPanel_BeforeDraw;
  1258. AfterDraw += NPCDropPanel_AfterDraw;
  1259. }
  1260. private void NPCDropPanel_AfterDraw(object sender, EventArgs e)
  1261. {
  1262. if (Hold)
  1263. Libraries.Title.Draw(295, 114 + DisplayLocation.X, 36 + DisplayLocation.Y);
  1264. }
  1265. private void NPCDropPanel_Click(object sender, EventArgs e)
  1266. {
  1267. MouseEventArgs me = e as MouseEventArgs;
  1268. if (me == null) return;
  1269. int x = me.X - DisplayLocation.X;
  1270. int y = me.Y - DisplayLocation.Y;
  1271. if (new Rectangle(20, 55, 75, 75).Contains(x, y))
  1272. ItemCell_Click();
  1273. }
  1274. private void Confirm()
  1275. {
  1276. if (TargetItem == null) return;
  1277. switch (PType)
  1278. {
  1279. case PanelType.Sell:
  1280. if (TargetItem.Info.Bind.HasFlag(BindMode.DontSell))
  1281. {
  1282. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.CannotSellItem), ChatType.System);
  1283. return;
  1284. }
  1285. if (GameScene.Gold + TargetItem.Price() / 2 <= uint.MaxValue)
  1286. {
  1287. Network.Enqueue(new C.SellItem { UniqueID = TargetItem.UniqueID, Count = TargetItem.Count });
  1288. TargetItem = null;
  1289. return;
  1290. }
  1291. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.CannotCarryMoreGold), ChatType.System);
  1292. break;
  1293. case PanelType.Repair:
  1294. if (TargetItem.Info.Bind.HasFlag(BindMode.DontRepair))
  1295. {
  1296. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.CannotRepairItem), ChatType.System);
  1297. return;
  1298. }
  1299. if (GameScene.Gold >= TargetItem.RepairPrice() * GameScene.NPCRate)
  1300. {
  1301. Network.Enqueue(new C.RepairItem { UniqueID = TargetItem.UniqueID });
  1302. TargetItem = null;
  1303. return;
  1304. }
  1305. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.LowGold), ChatType.System);
  1306. break;
  1307. case PanelType.SpecialRepair:
  1308. if ((TargetItem.Info.Bind.HasFlag(BindMode.DontRepair)) || (TargetItem.Info.Bind.HasFlag(BindMode.NoSRepair)))
  1309. {
  1310. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.CannotRepairItem), ChatType.System);
  1311. return;
  1312. }
  1313. if (GameScene.Gold >= (TargetItem.RepairPrice() * 3) * GameScene.NPCRate)
  1314. {
  1315. Network.Enqueue(new C.SRepairItem { UniqueID = TargetItem.UniqueID });
  1316. TargetItem = null;
  1317. return;
  1318. }
  1319. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.LowGold), ChatType.System);
  1320. break;
  1321. case PanelType.Consign:
  1322. if (TargetItem.Info.Bind.HasFlag(BindMode.DontStore) || TargetItem.Info.Bind.HasFlag(BindMode.DontSell))
  1323. {
  1324. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.CannotConsignItem), ChatType.System);
  1325. return;
  1326. }
  1327. MirAmountBox box = new MirAmountBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ConsignmentPrice), TargetItem.Image, Globals.MaxConsignment, Globals.MinConsignment)
  1328. {
  1329. InputTextBox = { Text = string.Empty },
  1330. Amount = 0
  1331. };
  1332. box.Show();
  1333. box.OKButton.Click += (o, e) =>
  1334. {
  1335. Network.Enqueue(new C.ConsignItem { UniqueID = TargetItem.UniqueID, Price = box.Amount, Type = MarketPanelType.Consign });
  1336. TargetItem = null;
  1337. };
  1338. return;
  1339. case PanelType.Disassemble:
  1340. Network.Enqueue(new C.DisassembleItem { UniqueID = TargetItem.UniqueID });
  1341. break;
  1342. case PanelType.Downgrade:
  1343. Network.Enqueue(new C.DowngradeAwakening { UniqueID = TargetItem.UniqueID });
  1344. break;
  1345. case PanelType.Reset:
  1346. if (TargetItem.Info.NeedIdentify == false)
  1347. {
  1348. Network.Enqueue(new C.ResetAddedItem { UniqueID = TargetItem.UniqueID });
  1349. }
  1350. break;
  1351. case PanelType.Refine:
  1352. for (int i = 0; i < GameScene.Scene.RefineDialog.Grid.Length; i++)
  1353. {
  1354. if (GameScene.Scene.RefineDialog.Grid[i].Item != null)
  1355. {
  1356. if (GameScene.Gold >= ((TargetItem.Info.RequiredAmount * 10) * GameScene.NPCRate))
  1357. {
  1358. Network.Enqueue(new C.RefineItem { UniqueID = TargetItem.UniqueID });
  1359. TargetItem = null;
  1360. return;
  1361. }
  1362. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.YouDontHaveEnoughGoldToRefine), TargetItem.FriendlyName), ChatType.System);
  1363. return;
  1364. }
  1365. }
  1366. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.YouHaventDepositedItemsToRefine), TargetItem.FriendlyName), ChatType.System);
  1367. break;
  1368. case PanelType.CheckRefine:
  1369. if (TargetItem.RefineAdded == 0)
  1370. {
  1371. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.ItemHasntBeenRefinedNoChecking), TargetItem.FriendlyName), ChatType.System);
  1372. return;
  1373. }
  1374. Network.Enqueue(new C.CheckRefine { UniqueID = TargetItem.UniqueID });
  1375. break;
  1376. case PanelType.ReplaceWedRing:
  1377. if (TargetItem.Info.Type != ItemType.Ring)
  1378. {
  1379. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.ItemIsNotRing), TargetItem.FriendlyName), ChatType.System);
  1380. return;
  1381. }
  1382. Network.Enqueue(new C.ReplaceWedRing { UniqueID = TargetItem.UniqueID });
  1383. break;
  1384. }
  1385. TargetItem = null;
  1386. OldCell.Locked = false;
  1387. OldCell = null;
  1388. }
  1389. private void ItemCell_Click()
  1390. {
  1391. if (OldCell != null)
  1392. {
  1393. OldCell.Locked = false;
  1394. TargetItem = null;
  1395. OldCell = null;
  1396. }
  1397. if (GameScene.SelectedCell != null && PType == PanelType.Disassemble)
  1398. {
  1399. if (GameScene.SelectedCell.Item.Info.Grade != ItemGrade.None &&
  1400. GameScene.SelectedCell.Item.Info.Type != ItemType.Awakening)
  1401. {
  1402. TargetItem = GameScene.SelectedCell.Item;
  1403. OldCell = GameScene.SelectedCell;
  1404. OldCell.Locked = true;
  1405. GameScene.SelectedCell = null;
  1406. return;
  1407. }
  1408. }
  1409. if (GameScene.SelectedCell != null && PType == PanelType.Downgrade)
  1410. {
  1411. if (GameScene.SelectedCell.Item.Awake.GetAwakeLevel() != 0)
  1412. {
  1413. TargetItem = GameScene.SelectedCell.Item;
  1414. OldCell = GameScene.SelectedCell;
  1415. OldCell.Locked = true;
  1416. GameScene.SelectedCell = null;
  1417. return;
  1418. }
  1419. }
  1420. if (GameScene.SelectedCell != null && PType == PanelType.Reset)
  1421. {
  1422. if (GameScene.SelectedCell.Item.IsAdded)
  1423. {
  1424. TargetItem = GameScene.SelectedCell.Item;
  1425. OldCell = GameScene.SelectedCell;
  1426. OldCell.Locked = true;
  1427. GameScene.SelectedCell = null;
  1428. return;
  1429. }
  1430. }
  1431. if (GameScene.SelectedCell != null && (PType == PanelType.Disassemble || PType == PanelType.Downgrade || PType == PanelType.Reset))
  1432. {
  1433. GameScene.SelectedCell.Locked = false;
  1434. GameScene.SelectedCell = null;
  1435. return;
  1436. }
  1437. //////////////////////////////////////
  1438. if (GameScene.SelectedCell == null || GameScene.SelectedCell.GridType != MirGridType.Inventory ||
  1439. (PType != PanelType.Sell && PType != PanelType.Consign && GameScene.SelectedCell.Item != null && GameScene.SelectedCell.Item.Info.Durability == 0))
  1440. return;
  1441. /*
  1442. if (GameScene.SelectedCell.Item != null && (GameScene.SelectedCell.Item.Info.StackSize > 1 && GameScene.SelectedCell.Item.Count > 1))
  1443. {
  1444. MirAmountBox amountBox = new MirAmountBox("Sell Amount:", GameScene.SelectedCell.Item.Image, GameScene.SelectedCell.Item.Count);
  1445. amountBox.OKButton.Click += (o, a) =>
  1446. {
  1447. TargetItem = GameScene.SelectedCell.Item.Clone();
  1448. TargetItem.Count = amountBox.Amount;
  1449. OldCell = GameScene.SelectedCell;
  1450. OldCell.Locked = true;
  1451. GameScene.SelectedCell = null;
  1452. if (Hold) Confirm();
  1453. };
  1454. amountBox.Show();
  1455. }
  1456. else
  1457. {
  1458. TargetItem = GameScene.SelectedCell.Item;
  1459. OldCell = GameScene.SelectedCell;
  1460. OldCell.Locked = true;
  1461. GameScene.SelectedCell = null;
  1462. if (Hold) Confirm();
  1463. }
  1464. */
  1465. TargetItem = GameScene.SelectedCell.Item;
  1466. OldCell = GameScene.SelectedCell;
  1467. OldCell.Locked = true;
  1468. GameScene.SelectedCell = null;
  1469. if (Hold) Confirm();
  1470. }
  1471. private void NPCDropPanel_BeforeDraw(object sender, EventArgs e)
  1472. {
  1473. string text;
  1474. HoldButton.Visible = true;
  1475. Index = 351;
  1476. Library = Libraries.Prguse2;
  1477. Location = new Point(264, GameScene.Scene.NPCDialog.Size.Height);
  1478. ConfirmButton.HoverIndex = 291;
  1479. ConfirmButton.Index = 290;
  1480. ConfirmButton.PressedIndex = 292;
  1481. ConfirmButton.Location = new Point(114, 62);
  1482. InfoLabel.Location = new Point(30, 10);
  1483. ItemCell.Location = new Point(38, 72);
  1484. switch (PType)
  1485. {
  1486. case PanelType.Sell:
  1487. text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Sale);
  1488. break;
  1489. case PanelType.Repair:
  1490. text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Repair);
  1491. break;
  1492. case PanelType.SpecialRepair:
  1493. text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SpecialRepair);
  1494. break;
  1495. case PanelType.Consign:
  1496. InfoLabel.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Consignment);
  1497. return;
  1498. case PanelType.Disassemble:
  1499. text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ItemWillBeDestroyed);
  1500. HoldButton.Visible = false;
  1501. Index = 711;
  1502. Library = Libraries.Title;
  1503. Location = new Point(234, 224);
  1504. ConfirmButton.HoverIndex = 716;
  1505. ConfirmButton.Index = 715;
  1506. ConfirmButton.PressedIndex = 717;
  1507. ConfirmButton.Location = new Point(62, 190);
  1508. InfoLabel.Location = new Point(44, 60);
  1509. ItemCell.Location = new Point(83, 94);
  1510. break;
  1511. case PanelType.Downgrade:
  1512. text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Downgrade);
  1513. HoldButton.Visible = false;
  1514. break;
  1515. case PanelType.Reset:
  1516. text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Reset);
  1517. HoldButton.Visible = false;
  1518. break;
  1519. case PanelType.Refine:
  1520. text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Refine);
  1521. HoldButton.Visible = false;
  1522. ConfirmButton.Visible = true;
  1523. GameScene.Scene.RefineDialog.Show();
  1524. break;
  1525. case PanelType.CheckRefine:
  1526. text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.CheckRefine);
  1527. HoldButton.Visible = false;
  1528. ConfirmButton.Visible = true;
  1529. break;
  1530. case PanelType.ReplaceWedRing:
  1531. text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ReplaceWedRing);
  1532. HoldButton.Visible = false;
  1533. ConfirmButton.Visible = true;
  1534. break;
  1535. default: return;
  1536. }
  1537. if (TargetItem != null)
  1538. {
  1539. switch (PType)
  1540. {
  1541. case PanelType.Sell:
  1542. text += (TargetItem.Price() / 2).ToString();
  1543. break;
  1544. case PanelType.Repair:
  1545. text += (TargetItem.RepairPrice() * GameScene.NPCRate).ToString();
  1546. break;
  1547. case PanelType.SpecialRepair:
  1548. text += ((TargetItem.RepairPrice() * 3) * GameScene.NPCRate).ToString();
  1549. break;
  1550. case PanelType.Disassemble:
  1551. text += TargetItem.DisassemblePrice().ToString();
  1552. break;
  1553. case PanelType.Downgrade:
  1554. text += TargetItem.DowngradePrice().ToString();
  1555. break;
  1556. case PanelType.Reset:
  1557. text += TargetItem.ResetPrice().ToString();
  1558. break;
  1559. case PanelType.Refine:
  1560. text += ((TargetItem.Info.RequiredAmount * 10) * GameScene.NPCRate).ToString();
  1561. break;
  1562. case PanelType.ReplaceWedRing:
  1563. text += ((TargetItem.Info.RequiredAmount * 10) * GameScene.NPCRate).ToString();
  1564. break;
  1565. default: return;
  1566. }
  1567. text += GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Gold2);
  1568. }
  1569. InfoLabel.Text = text;
  1570. }
  1571. public override void Hide()
  1572. {
  1573. if (OldCell != null)
  1574. {
  1575. OldCell.Locked = false;
  1576. TargetItem = null;
  1577. OldCell = null;
  1578. }
  1579. Visible = false;
  1580. }
  1581. public override void Show()
  1582. {
  1583. Hold = false;
  1584. GameScene.Scene.InventoryDialog.Show();
  1585. Visible = true;
  1586. }
  1587. }
  1588. public sealed class NPCAwakeDialog : MirImageControl
  1589. {
  1590. public MirButton UpgradeButton, CloseButton;
  1591. public MirItemCell[] ItemCells = new MirItemCell[7];
  1592. public MirDropDownBox SelectAwakeType;
  1593. public AwakeType CurrentAwakeType = AwakeType.None;
  1594. public MirLabel GoldLabel, NeedItemLabel1, NeedItemLabel2;
  1595. public static UserItem[] Items = new UserItem[7];
  1596. public static int[] ItemsIdx = new int[7];
  1597. public NPCAwakeDialog()
  1598. {
  1599. Index = 710;
  1600. Library = Libraries.Title;
  1601. Location = new Point(0, 0);
  1602. Sort = true;
  1603. Movable = true;
  1604. GoldLabel = new MirLabel
  1605. {
  1606. AutoSize = true,
  1607. Location = new Point(112, 354),
  1608. Parent = this,
  1609. NotControl = true,
  1610. };
  1611. NeedItemLabel1 = new MirLabel
  1612. {
  1613. AutoSize = true,
  1614. Location = new Point(67, 317),//
  1615. Parent = this,
  1616. NotControl = true,
  1617. };
  1618. NeedItemLabel2 = new MirLabel
  1619. {
  1620. AutoSize = true,
  1621. Location = new Point(192, 317),//(155, 316),
  1622. Parent = this,
  1623. NotControl = true,
  1624. };
  1625. UpgradeButton = new MirButton
  1626. {
  1627. HoverIndex = 713,
  1628. Index = 712,
  1629. Location = new Point(115, 391), //new Point(181, 135),
  1630. Library = Libraries.Title,
  1631. Parent = this,
  1632. PressedIndex = 714,
  1633. Sound = SoundList.ButtonA,
  1634. };
  1635. UpgradeButton.Click += (o, e) => Awakening();
  1636. CloseButton = new MirButton
  1637. {
  1638. HoverIndex = 361,
  1639. Index = 360,
  1640. Location = new Point(284, 4),
  1641. Library = Libraries.Prguse2,
  1642. Parent = this,
  1643. PressedIndex = 362,
  1644. Sound = SoundList.ButtonA,
  1645. };
  1646. CloseButton.Click += (o, e) => Hide();
  1647. ItemCells[0] = new MirItemCell
  1648. {
  1649. BorderColour = Color.Lime,
  1650. GridType = MirGridType.AwakenItem,
  1651. Library = Libraries.Items,
  1652. Parent = this,
  1653. Location = new Point(202, 91),
  1654. ItemSlot = 0,
  1655. };
  1656. //ItemCells[0].AfterDraw += (o, e) => ItemCell_AfterDraw();
  1657. //ItemCells[0].Click += (o, e) => ItemCell_Click();
  1658. ItemCells[1] = new MirItemCell //Required
  1659. {
  1660. BorderColour = Color.Lime,
  1661. GridType = MirGridType.AwakenItem,
  1662. Library = Libraries.Items,
  1663. Parent = this,
  1664. Location = new Point(31, 316),
  1665. ItemSlot = 1,
  1666. Enabled = false,
  1667. };
  1668. ItemCells[2] = new MirItemCell //Required
  1669. {
  1670. BorderColour = Color.Lime,
  1671. GridType = MirGridType.AwakenItem,
  1672. Library = Libraries.Items,
  1673. Parent = this,
  1674. Location = new Point(155, 316),
  1675. ItemSlot = 2,
  1676. Enabled = false,
  1677. };
  1678. ItemCells[3] = new MirItemCell
  1679. {
  1680. BorderColour = Color.Lime,
  1681. GridType = MirGridType.AwakenItem,
  1682. Library = Libraries.Items,
  1683. Parent = this,
  1684. Location = new Point(175, 199),
  1685. ItemSlot = 3,
  1686. };
  1687. ItemCells[4] = new MirItemCell
  1688. {
  1689. BorderColour = Color.Lime,
  1690. GridType = MirGridType.AwakenItem,
  1691. Library = Libraries.Items,
  1692. Parent = this,
  1693. Location = new Point(230, 199),
  1694. ItemSlot = 4,
  1695. };
  1696. ItemCells[5] = new MirItemCell
  1697. {
  1698. BorderColour = Color.Lime,
  1699. GridType = MirGridType.AwakenItem,
  1700. Library = Libraries.Items,
  1701. Parent = this,
  1702. Location = new Point(175, 256),
  1703. ItemSlot = 5,
  1704. };
  1705. ItemCells[6] = new MirItemCell
  1706. {
  1707. BorderColour = Color.Lime,
  1708. GridType = MirGridType.AwakenItem,
  1709. Library = Libraries.Items,
  1710. Parent = this,
  1711. Location = new Point(230, 256),
  1712. ItemSlot = 6,
  1713. };
  1714. SelectAwakeType = new MirDropDownBox()
  1715. {
  1716. Parent = this,
  1717. Location = new Point(35, 141),
  1718. Size = new Size(109, 14),
  1719. ForeColour = Color.White,
  1720. Visible = true,
  1721. Enabled = true,
  1722. };
  1723. SelectAwakeType.ValueChanged += (o, e) => OnAwakeTypeSelect(SelectAwakeType._WantedIndex);
  1724. }
  1725. public void ItemCellClear()
  1726. {
  1727. if (ItemCells[1].Item != null)
  1728. {
  1729. ItemCells[1].Item = null;
  1730. }
  1731. if (ItemCells[2].Item != null)
  1732. {
  1733. ItemCells[2].Item = null;
  1734. }
  1735. NeedItemLabel2.Text = "";
  1736. NeedItemLabel1.Text = "";
  1737. GoldLabel.Text = "";
  1738. }
  1739. public void ItemCell_Click()
  1740. {
  1741. ItemCellClear();
  1742. SelectAwakeType.Items.Clear();
  1743. if (Items[0] == null)
  1744. {
  1745. SelectAwakeType.Items.Add(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SelectUpgradeItem));
  1746. SelectAwakeType.SelectedIndex = SelectAwakeType.Items.Count - 1;
  1747. CurrentAwakeType = AwakeType.None;
  1748. }
  1749. else
  1750. {
  1751. if (Items[0].Awake.GetAwakeLevel() == 0)
  1752. {
  1753. SelectAwakeType.Items.Add(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SelectUpgradeType));
  1754. if (Items[0].Info.Type == ItemType.Weapon)
  1755. {
  1756. SelectAwakeType.Items.Add(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.BraveryGlyph));
  1757. SelectAwakeType.Items.Add(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.MagicGlyph));
  1758. SelectAwakeType.Items.Add(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SoulGlyph));
  1759. }
  1760. else if (Items[0].Info.Type == ItemType.Helmet)
  1761. {
  1762. SelectAwakeType.Items.Add(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ProtectionGlyph));
  1763. SelectAwakeType.Items.Add(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.EvilSlayerGlyph));
  1764. }
  1765. else
  1766. {
  1767. SelectAwakeType.Items.Add(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.BodyGlyph));
  1768. }
  1769. }
  1770. else
  1771. {
  1772. SelectAwakeType.Items.Add(getAwakeTypeText(Items[0].Awake.Type));
  1773. if (CurrentAwakeType != Items[0].Awake.Type)
  1774. {
  1775. CurrentAwakeType = Items[0].Awake.Type;
  1776. OnAwakeTypeSelect(0);
  1777. }
  1778. }
  1779. }
  1780. }
  1781. public string getAwakeTypeText(AwakeType type)
  1782. {
  1783. string typeName = "";
  1784. if (type == AwakeType.DC)
  1785. {
  1786. typeName = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.BraveryGlyph);
  1787. }
  1788. else if (type == AwakeType.MC)
  1789. {
  1790. typeName = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.MagicGlyph);
  1791. }
  1792. else if (type == AwakeType.SC)
  1793. {
  1794. typeName = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SoulGlyph);
  1795. }
  1796. else if (type == AwakeType.AC)
  1797. {
  1798. typeName = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ProtectionGlyph);
  1799. }
  1800. else if (type == AwakeType.MAC)
  1801. {
  1802. typeName = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.EvilSlayerGlyph);
  1803. }
  1804. else if (type == AwakeType.HPMP)
  1805. {
  1806. typeName = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.BodyGlyph);
  1807. }
  1808. else
  1809. {
  1810. typeName = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SelectUpgradeItem);
  1811. }
  1812. return typeName;
  1813. }
  1814. public AwakeType getAwakeType(string typeName)
  1815. {
  1816. AwakeType type = AwakeType.None;
  1817. if (typeName == GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.BraveryGlyph))
  1818. {
  1819. type = AwakeType.DC;
  1820. }
  1821. else if (typeName == GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.MagicGlyph))
  1822. {
  1823. type = AwakeType.MC;
  1824. }
  1825. else if (typeName == GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SoulGlyph))
  1826. {
  1827. type = AwakeType.SC;
  1828. }
  1829. else if (typeName == GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ProtectionGlyph))
  1830. {
  1831. type = AwakeType.AC;
  1832. }
  1833. else if (typeName == GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.EvilSlayerGlyph))
  1834. {
  1835. type = AwakeType.MAC;
  1836. }
  1837. else if (typeName == GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.BodyGlyph))
  1838. {
  1839. type = AwakeType.HPMP;
  1840. }
  1841. else
  1842. {
  1843. type = AwakeType.None;
  1844. }
  1845. return type;
  1846. }
  1847. public void OnAwakeTypeSelect(int Index)
  1848. {
  1849. SelectAwakeType.SelectedIndex = Index;
  1850. AwakeType type = getAwakeType(SelectAwakeType.Items[SelectAwakeType.SelectedIndex]);
  1851. CurrentAwakeType = type;
  1852. if (type != AwakeType.None)
  1853. {
  1854. Network.Enqueue(new C.AwakeningNeedMaterials { UniqueID = Items[0].UniqueID, Type = type });
  1855. }
  1856. }
  1857. public void setNeedItems(ItemInfo[] Materials, byte[] MaterialsCount)
  1858. {
  1859. if (MaterialsCount[0] != 0)
  1860. {
  1861. ItemCells[1].Item = new UserItem(Materials[0]);
  1862. ItemCells[1].Item.Count = MaterialsCount[0];
  1863. NeedItemLabel1.Text = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.NeedItemQuantity), Regex.Replace(ItemCells[1].Item.Info.Name, @"[\d-]", string.Empty), MaterialsCount[0].ToString());
  1864. }
  1865. else
  1866. {
  1867. ItemCells[1].Item = null;
  1868. NeedItemLabel1.Text = "";
  1869. }
  1870. if (MaterialsCount[1] != 0)
  1871. {
  1872. ItemCells[2].Item = new UserItem(Materials[1]);
  1873. ItemCells[2].Item.Count = MaterialsCount[1];
  1874. NeedItemLabel2.Text = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.NeedItemQuantity), Regex.Replace(ItemCells[2].Item.Info.Name, @"[\d-]", string.Empty), MaterialsCount[1].ToString());
  1875. }
  1876. else
  1877. {
  1878. ItemCells[2].Item = null;
  1879. NeedItemLabel2.Text = "";
  1880. }
  1881. if (ItemCells[0].Item != null)
  1882. GoldLabel.Text = ItemCells[0].Item.AwakeningPrice().ToString();
  1883. }
  1884. public bool CheckNeedMaterials()
  1885. {
  1886. int maxEqual = (Items[1] == null || Items[2] == null) ? 1 : 2;
  1887. int equal = 0;
  1888. for (int i = 1; i < 3; i++)
  1889. {
  1890. if (Items[i] == null) continue;
  1891. for (int j = 3; j < 5; j++)
  1892. {
  1893. if (Items[j] == null) continue;
  1894. if (Items[i].Info.Name == Items[j].Info.Name &&
  1895. Items[i].Count <= Items[j].Count)
  1896. equal++;
  1897. }
  1898. }
  1899. return equal >= maxEqual;
  1900. }
  1901. public void Awakening()
  1902. {
  1903. if (CheckNeedMaterials())
  1904. {
  1905. AwakeType type = getAwakeType(SelectAwakeType.Items[SelectAwakeType.SelectedIndex]);
  1906. if (type != AwakeType.None)
  1907. {
  1908. Network.Enqueue(new C.Awakening { UniqueID = Items[0].UniqueID, Type = type });
  1909. MapControl.AwakeningAction = true;
  1910. }
  1911. }
  1912. }
  1913. public override void Hide()
  1914. {
  1915. foreach (var item in ItemCells)
  1916. {
  1917. if (item.Item != null)
  1918. {
  1919. Network.Enqueue(new C.AwakeningLockedItem { UniqueID = item.Item.UniqueID, Locked = false });
  1920. item.Item = null;
  1921. }
  1922. }
  1923. for (int i = 0; i < ItemsIdx.Length; i++)
  1924. {
  1925. ItemsIdx[i] = 0;
  1926. }
  1927. ItemCell_Click();
  1928. Visible = false;
  1929. }
  1930. public override void Show()
  1931. {
  1932. Visible = true;
  1933. //GameScene.Scene.InventoryDialog.Location = new Point(Size.Width + 5, 0);
  1934. GameScene.Scene.InventoryDialog.Location = new Point(Size.Width + 5, Location.Y);
  1935. GameScene.Scene.InventoryDialog.Show();
  1936. }
  1937. }
  1938. public sealed class CraftDialog : MirImageControl
  1939. {
  1940. public UserItem RecipeItem;
  1941. public ClientRecipeInfo Recipe;
  1942. private const int _toolCount = 3;
  1943. private const int _ingredientCount = 6;
  1944. private static int _totalCount { get { return _toolCount + _ingredientCount; } }
  1945. public static UserItem[] Slots = new UserItem[_totalCount];
  1946. public static UserItem[] ShadowItems = new UserItem[_totalCount];
  1947. public Dictionary<MirItemCell, ulong> Selected = new Dictionary<MirItemCell, ulong>();
  1948. public MirItemCell[] Grid;
  1949. public MirButton CraftButton, AutoFillButton, CloseButton;
  1950. public MirLabel RecipeLabel;
  1951. public MirLabel PossibilityLabel;
  1952. public MirLabel GoldLabel;
  1953. public CraftDialog()
  1954. {
  1955. Index = 1109;
  1956. Library = Libraries.Prguse;
  1957. Location = new Point(0, 0);
  1958. Sort = true;
  1959. BeforeDraw += CraftDialog_BeforeDraw;
  1960. Movable = true;
  1961. RecipeLabel = new MirLabel
  1962. {
  1963. AutoSize = true,
  1964. Parent = this,
  1965. Location = new Point(22, 5),
  1966. Font = new Font(Settings.FontName, 10F, FontStyle.Bold),
  1967. ForeColour = Color.BurlyWood,
  1968. Visible = true,
  1969. NotControl = true
  1970. };
  1971. PossibilityLabel = new MirLabel
  1972. {
  1973. AutoSize = true,
  1974. ForeColour = Color.White,
  1975. Parent = this,
  1976. Location = new Point(10, 135),
  1977. Font = new Font(Settings.FontName, 8F),
  1978. Visible = true,
  1979. NotControl = true
  1980. };
  1981. GoldLabel = new MirLabel
  1982. {
  1983. AutoSize = true,
  1984. ForeColour = Color.White,
  1985. Parent = this,
  1986. Location = new Point(30, 190),
  1987. Font = new Font(Settings.FontName, 8F),
  1988. Visible = true,
  1989. NotControl = true
  1990. };
  1991. Grid = new MirItemCell[_totalCount];
  1992. for (int x = 0; x < _totalCount; x++)
  1993. {
  1994. if (x >= _toolCount)
  1995. {
  1996. Grid[x] = new MirItemCell
  1997. {
  1998. ItemSlot = x,
  1999. GridType = MirGridType.Craft,
  2000. Library = Libraries.Items,
  2001. Parent = this,
  2002. Size = new Size(35, 32),
  2003. Location = new Point(((x - _toolCount) * 40) + 52, 86),
  2004. Border = true,
  2005. BorderColour = Color.Lime
  2006. };
  2007. }
  2008. else
  2009. {
  2010. Grid[x] = new MirItemCell
  2011. {
  2012. ItemSlot = x,
  2013. GridType = MirGridType.Craft,
  2014. Library = Libraries.Items,
  2015. Parent = this,
  2016. Size = new Size(35, 32),
  2017. Location = new Point((x * 44) + 108, 44),
  2018. Border = true,
  2019. BorderColour = Color.Lime
  2020. };
  2021. }
  2022. Grid[x].Click += Grid_Click;
  2023. }
  2024. CloseButton = new MirButton
  2025. {
  2026. Index = 360,
  2027. HoverIndex = 361,
  2028. PressedIndex = 362,
  2029. Location = new Point(312, 3),
  2030. Library = Libraries.Prguse2,
  2031. Parent = this,
  2032. Sound = SoundList.ButtonA,
  2033. };
  2034. CloseButton.Click += (o, e) => Hide();
  2035. AutoFillButton = new MirButton
  2036. {
  2037. HoverIndex = 181,
  2038. Index = 180,
  2039. Location = new Point(165, 185),
  2040. Library = Libraries.Title,
  2041. Parent = this,
  2042. PressedIndex = 182,
  2043. Sound = SoundList.ButtonA
  2044. };
  2045. AutoFillButton.Click += (o, e) => AutoFill();
  2046. CraftButton = new MirButton
  2047. {
  2048. HoverIndex = 337,
  2049. Index = 336,
  2050. Location = new Point(215, 185),
  2051. Library = Libraries.Title,
  2052. Parent = this,
  2053. PressedIndex = 338,
  2054. Sound = SoundList.ButtonA,
  2055. GrayScale = true,
  2056. Enabled = false
  2057. };
  2058. CraftButton.Click += (o, e) => CraftItem();
  2059. }
  2060. void CraftDialog_BeforeDraw(object sender, EventArgs e)
  2061. {
  2062. if (!GameScene.Scene.InventoryDialog.Visible)
  2063. {
  2064. Hide();
  2065. return;
  2066. }
  2067. }
  2068. private void Grid_Click(object sender, EventArgs e)
  2069. {
  2070. MirItemCell cell = (MirItemCell)sender;
  2071. if (cell == null || cell.ShadowItem == null)
  2072. return;
  2073. if (GameScene.SelectedCell == null || GameScene.SelectedCell.GridType != MirGridType.Inventory || GameScene.SelectedCell.Locked)
  2074. return;
  2075. if (GameScene.SelectedCell.Item.Info != cell.ShadowItem.Info || cell.Item != null)
  2076. return;
  2077. if (cell.ItemSlot >= _toolCount)
  2078. {
  2079. if (GameScene.SelectedCell.Item.Count < cell.ShadowItem.Count)
  2080. return;
  2081. if (cell.ShadowItem.CurrentDura < cell.ShadowItem.MaxDura && GameScene.SelectedCell.Item.CurrentDura < cell.ShadowItem.CurrentDura)
  2082. return;
  2083. }
  2084. else
  2085. {
  2086. if (GameScene.SelectedCell.Item.CurrentDura < 1000M)
  2087. return;
  2088. }
  2089. cell.Item = GameScene.SelectedCell.Item;
  2090. Selected.Add(GameScene.SelectedCell, GameScene.SelectedCell.Item.UniqueID);
  2091. GameScene.SelectedCell.Locked = true;
  2092. GameScene.SelectedCell = null;
  2093. RefreshCraftCells(RecipeItem);
  2094. }
  2095. public override void Hide()
  2096. {
  2097. if (!Visible) return;
  2098. Visible = false;
  2099. ResetCells();
  2100. }
  2101. public override void Show()
  2102. {
  2103. Visible = true;
  2104. Location = new Point(GameScene.Scene.InventoryDialog.Location.X - 12, GameScene.Scene.InventoryDialog.Location.Y + 236);
  2105. }
  2106. private void AutoFill()
  2107. {
  2108. ResetCells(false);
  2109. if (RecipeItem == null) return;
  2110. List<int> usedSlots = new List<int>();
  2111. int j = 0;
  2112. foreach (var tool in Recipe.Tools)
  2113. {
  2114. for (int i = 0; i < UserObject.User.Inventory.Length; i++)
  2115. {
  2116. if (usedSlots.Contains(i)) continue;
  2117. var slot = UserObject.User.Inventory[i];
  2118. if (slot == null || tool.Info.Index != slot.Info.Index || slot.CurrentDura < 1000M) continue;
  2119. var cell = GameScene.Scene.InventoryDialog.GetCell(slot.UniqueID) ?? GameScene.Scene.BeltDialog.GetCell(slot.UniqueID);
  2120. if (cell.Locked) continue;
  2121. Selected.Add(cell, cell.Item.UniqueID);
  2122. cell.Locked = true;
  2123. Grid[j].Item = cell.Item;
  2124. break;
  2125. }
  2126. j++;
  2127. }
  2128. j = 3;
  2129. foreach (var ingredient in Recipe.Ingredients)
  2130. {
  2131. for (int i = 0; i < UserObject.User.Inventory.Length; i++)
  2132. {
  2133. if (usedSlots.Contains(i)) continue;
  2134. var slot = UserObject.User.Inventory[i];
  2135. if (slot == null || ingredient.Info.Index != slot.Info.Index) continue;
  2136. if (slot.Count < ingredient.Count) continue;
  2137. if (ingredient.CurrentDura < ingredient.MaxDura && slot.CurrentDura < ingredient.CurrentDura) continue;
  2138. var cell = GameScene.Scene.InventoryDialog.GetCell(slot.UniqueID) ?? GameScene.Scene.BeltDialog.GetCell(slot.UniqueID);
  2139. if (cell.Locked) continue;
  2140. Selected.Add(cell, cell.Item.UniqueID);
  2141. cell.Locked = true;
  2142. Grid[j].Item = cell.Item;
  2143. break;
  2144. }
  2145. j++;
  2146. }
  2147. RefreshCraftCells(RecipeItem);
  2148. }
  2149. private void CraftItem()
  2150. {
  2151. if (RecipeItem == null) return;
  2152. if (Selected.Count < Recipe.Tools.Count + Recipe.Ingredients.Count) return;
  2153. ushort max = 99;
  2154. //Max quantity based on available ingredients/tools
  2155. for (int i = 0; i < Grid.Length; i++)
  2156. {
  2157. if (Grid[i] == null || Grid[i].Item == null) continue;
  2158. ushort temp = 0;
  2159. if (i >= _toolCount)
  2160. {
  2161. temp = (ushort)(Grid[i].Item.Count / Grid[i].ShadowItem.Count);
  2162. }
  2163. else
  2164. {
  2165. temp = (ushort)Math.Floor(Grid[i].Item.CurrentDura / 1000M);
  2166. }
  2167. if (temp < max) max = temp;
  2168. }
  2169. if (max > (RecipeItem.Info.StackSize / RecipeItem.Count))
  2170. {
  2171. max = (ushort)(RecipeItem.Info.StackSize / RecipeItem.Count);
  2172. }
  2173. //TODO - Check Max slots spare against slots to be used (stacksize/quantity)
  2174. //TODO - GetMaxItemGain
  2175. if (max == 1)
  2176. {
  2177. if (Recipe.Gold > GameScene.Gold)
  2178. {
  2179. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.YouDoNotHaveEnoughGold), ChatType.System);
  2180. return;
  2181. }
  2182. }
  2183. if (max > 1)
  2184. {
  2185. MirAmountBox amountBox = new MirAmountBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.CraftAmount), RecipeItem.Info.Image, max, 0, max);
  2186. amountBox.OKButton.Click += (o, e) =>
  2187. {
  2188. if (amountBox.Amount > 0)
  2189. {
  2190. if (!HasCraftItems((ushort)amountBox.Amount))
  2191. {
  2192. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.YouDoNotHaveRequiredToolsOrIngredients), ChatType.System);
  2193. return;
  2194. }
  2195. if ((Recipe.Gold * amountBox.Amount) > GameScene.Gold)
  2196. {
  2197. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.YouDoNotHaveEnoughGold), ChatType.System);
  2198. return;
  2199. }
  2200. Network.Enqueue(new C.CraftItem
  2201. {
  2202. UniqueID = RecipeItem.UniqueID,
  2203. Count = (ushort)amountBox.Amount,
  2204. Slots = Selected.Select(x => x.Key.ItemSlot).ToArray()
  2205. });
  2206. }
  2207. };
  2208. amountBox.Show();
  2209. }
  2210. else
  2211. {
  2212. Network.Enqueue(new C.CraftItem
  2213. {
  2214. UniqueID = RecipeItem.UniqueID,
  2215. Count = 1,
  2216. Slots = Selected.Select(x => x.Key.ItemSlot).ToArray()
  2217. });
  2218. }
  2219. }
  2220. private bool HasCraftItems(ushort count)
  2221. {
  2222. for (int i = 0; i < Grid.Length; i++)
  2223. {
  2224. if (Grid[i].ShadowItem == null) continue;
  2225. if (i >= _toolCount)
  2226. {
  2227. if (Grid[i].Item == null || Grid[i].Item.Count < (Grid[i].ShadowItem.Count * count)) return false;
  2228. }
  2229. else
  2230. {
  2231. if (Grid[i].Item == null || (uint)Math.Floor(Grid[i].Item.CurrentDura / 1000M) < count) return false;
  2232. }
  2233. }
  2234. return true;
  2235. }
  2236. public void ResetCells(bool clearRecipe = true)
  2237. {
  2238. if (clearRecipe)
  2239. {
  2240. RecipeItem = null;
  2241. }
  2242. for (int j = 0; j < Grid.Length; j++)
  2243. {
  2244. Slots[j] = null;
  2245. ShadowItems[j] = null;
  2246. }
  2247. foreach (var key in Selected.Keys)
  2248. {
  2249. key.Locked = false;
  2250. }
  2251. Selected.Clear();
  2252. }
  2253. public MirItemCell GetCell(ulong id)
  2254. {
  2255. for (int i = 0; i < Grid.Length; i++)
  2256. {
  2257. if (Grid[i].Item == null || Grid[i].Item.UniqueID != id) continue;
  2258. return Grid[i];
  2259. }
  2260. return null;
  2261. }
  2262. public void UpdateCraftCells()
  2263. {
  2264. List<MirItemCell> invalidCells = new List<MirItemCell>();
  2265. foreach (var key in Selected.Keys)
  2266. {
  2267. MirItemCell cell = key;
  2268. ulong oldItem = Selected[key];
  2269. if (cell.Item == null || cell.Item.UniqueID != oldItem || (cell.Item.MaxDura > 1000M && cell.Item.CurrentDura < 1000M))
  2270. {
  2271. MirItemCell gridCell = GetCell(oldItem);
  2272. if (gridCell != null)
  2273. {
  2274. gridCell.Item = null;
  2275. }
  2276. cell.Locked = false;
  2277. invalidCells.Add(key);
  2278. }
  2279. }
  2280. foreach (var cell in invalidCells)
  2281. {
  2282. Selected.Remove(cell);
  2283. }
  2284. RefreshCraftCells(RecipeItem);
  2285. }
  2286. public void RefreshCraftCells(UserItem selectedItem)
  2287. {
  2288. RecipeItem = selectedItem;
  2289. CraftButton.Enabled = true;
  2290. CraftButton.GrayScale = false;
  2291. Recipe = GameScene.RecipeInfoList.SingleOrDefault(x => x.Item.ItemIndex == selectedItem.ItemIndex);
  2292. RecipeLabel.Text = Recipe.Item.FriendlyName;
  2293. PossibilityLabel.Text = (UserObject.User.Stats[Stat.CraftRatePercent] > 0 ? $"{Math.Min(100, Recipe.Chance + UserObject.User.Stats[Stat.CraftRatePercent])}% (+{UserObject.User.Stats[Stat.CraftRatePercent]}%)" : $"{Recipe.Chance}%") + " Chance of Success";
  2294. GoldLabel.Text = Recipe.Gold.ToString("###,###,##0");
  2295. for (int i = 0; i < Slots.Length; i++)
  2296. {
  2297. bool need;
  2298. if (i >= _toolCount)
  2299. {
  2300. if ((i - _toolCount) >= Recipe.Ingredients.Count) continue;
  2301. ShadowItems[i] = Recipe.Ingredients[i - _toolCount];
  2302. need = Grid[i].Item == null || Grid[i].Item.Count < Grid[i].ShadowItem.Count;
  2303. }
  2304. else
  2305. {
  2306. if (i >= Recipe.Tools.Count) continue;
  2307. ShadowItems[i] = Recipe.Tools[i];
  2308. need = Grid[i].Item == null || Grid[i].Item.Count < Grid[i].ShadowItem.Count;
  2309. }
  2310. if (need)
  2311. {
  2312. CraftButton.Enabled = false;
  2313. CraftButton.GrayScale = true;
  2314. }
  2315. }
  2316. }
  2317. }
  2318. public sealed class RefineDialog : MirImageControl
  2319. {
  2320. public MirItemCell[] Grid;
  2321. public MirButton RefineButton;
  2322. public RefineDialog()
  2323. {
  2324. Index = 1002;
  2325. Library = Libraries.Prguse;
  2326. Location = new Point(0, 225);
  2327. Sort = true;
  2328. MirImageControl TitleLabel = new MirImageControl
  2329. {
  2330. Index = 18,
  2331. Library = Libraries.Title,
  2332. Location = new Point(28, 8),
  2333. Parent = this
  2334. };
  2335. Grid = new MirItemCell[4 * 4];
  2336. for (int x = 0; x < 4; x++)
  2337. {
  2338. for (int y = 0; y < 4; y++)
  2339. {
  2340. int idx = 4 * y + x;
  2341. Grid[idx] = new MirItemCell
  2342. {
  2343. ItemSlot = idx,
  2344. GridType = MirGridType.Refine,
  2345. Library = Libraries.Items,
  2346. Parent = this,
  2347. Size = new Size(34, 32),
  2348. Location = new Point(x * 34 + 12 + x, y * 32 + 37 + y),
  2349. };
  2350. }
  2351. }
  2352. }
  2353. public override void Hide()
  2354. {
  2355. if (!Visible) return;
  2356. Visible = false;
  2357. RefineCancel();
  2358. }
  2359. public void RefineCancel()
  2360. {
  2361. Network.Enqueue(new C.RefineCancel());
  2362. }
  2363. public void RefineReset()
  2364. {
  2365. for (int i = 0; i < Grid.Length; i++)
  2366. Grid[i].Item = null;
  2367. }
  2368. public MirItemCell GetCell(ulong id)
  2369. {
  2370. for (int i = 0; i < Grid.Length; i++)
  2371. {
  2372. if (Grid[i].Item == null || Grid[i].Item.UniqueID != id) continue;
  2373. return Grid[i];
  2374. }
  2375. return null;
  2376. }
  2377. }
  2378. public sealed class StorageDialog : MirImageControl
  2379. {
  2380. public MirItemCell[] Grid;
  2381. public MirButton Storage1Button, Storage2Button, RentButton, ProtectButton, CloseButton;
  2382. public MirImageControl LockedPage;
  2383. public MirLabel RentalLabel, StoragePasswordLabel;
  2384. private bool _storageUnlocked;
  2385. private bool _pendingOpenAfterPasswordSet;
  2386. private bool _forcingPasswordSetup;
  2387. public StorageDialog()
  2388. {
  2389. Index = 586;
  2390. Library = Libraries.Prguse;
  2391. Location = new Point(0, 0);
  2392. Sort = true;
  2393. MirImageControl TitleLabel = new MirImageControl
  2394. {
  2395. Index = 0,
  2396. Library = Libraries.Title,
  2397. Location = new Point(18, 8),
  2398. Parent = this
  2399. };
  2400. LockedPage = new MirImageControl
  2401. {
  2402. Index = 2443,
  2403. Library = Libraries.Prguse,
  2404. Location = new Point(8, 59),
  2405. Parent = this,
  2406. Visible = false
  2407. };
  2408. Storage1Button = new MirButton
  2409. {
  2410. HoverIndex = 743,
  2411. Index = 743,
  2412. Location = new Point(8, 36),
  2413. Library = Libraries.Title,
  2414. Parent = this,
  2415. PressedIndex = 744,
  2416. Sound = SoundList.ButtonA,
  2417. };
  2418. Storage1Button.Click += (o, e) =>
  2419. {
  2420. RefreshStorage1();
  2421. };
  2422. Storage2Button = new MirButton
  2423. {
  2424. HoverIndex = 746,
  2425. Index = 746,
  2426. Location = new Point(80, 36),
  2427. Library = Libraries.Title,
  2428. Parent = this,
  2429. PressedIndex = 746,
  2430. Sound = SoundList.ButtonA,
  2431. Visible = true
  2432. };
  2433. Storage2Button.Click += (o, e) =>
  2434. {
  2435. RefreshStorage2();
  2436. };
  2437. RentButton = new MirButton
  2438. {
  2439. Index = 483,
  2440. HoverIndex = 484,
  2441. PressedIndex = 485,
  2442. Library = Libraries.Title,
  2443. Location = new Point(283, 33),
  2444. Parent = this,
  2445. Sound = SoundList.ButtonA,
  2446. Visible = true,
  2447. };
  2448. RentButton.Click += (o, e) =>
  2449. {
  2450. MirMessageBox messageBox;
  2451. if (GameScene.User.HasExpandedStorage)
  2452. messageBox = new MirMessageBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ExtendYourRentalPeriod), MirMessageBoxButtons.OKCancel);
  2453. else
  2454. messageBox = new MirMessageBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ExtraStorage), MirMessageBoxButtons.OKCancel);
  2455. messageBox.OKButton.Click += (o1, a) =>
  2456. {
  2457. Network.Enqueue(new C.Chat { Message = "@ADDSTORAGE" });
  2458. };
  2459. messageBox.Show();
  2460. };
  2461. ProtectButton = new MirButton
  2462. {
  2463. HoverIndex = 114,
  2464. Index = 113,
  2465. Location = new Point(328, 33),
  2466. Library = Libraries.Title,
  2467. Parent = this,
  2468. PressedIndex = 115,
  2469. Sound = SoundList.ButtonA,
  2470. Visible = true
  2471. };
  2472. ProtectButton.Click += (o, e) => ManageStoragePassword();
  2473. CloseButton = new MirButton
  2474. {
  2475. HoverIndex = 361,
  2476. Index = 360,
  2477. Location = new Point(363, 3),
  2478. Library = Libraries.Prguse2,
  2479. Parent = this,
  2480. PressedIndex = 362,
  2481. Sound = SoundList.ButtonA,
  2482. };
  2483. CloseButton.Click += (o, e) => Hide();
  2484. RentalLabel = new MirLabel
  2485. {
  2486. Parent = this,
  2487. Location = new Point(40, 322),
  2488. AutoSize = true,
  2489. DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter,
  2490. NotControl = true,
  2491. Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ExpandedStorageLocked),
  2492. ForeColour = Color.Red
  2493. };
  2494. StoragePasswordLabel = new MirLabel
  2495. {
  2496. Parent = this,
  2497. Location = new Point(40, 304),
  2498. AutoSize = true,
  2499. DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter,
  2500. NotControl = true,
  2501. ForeColour = Color.White,
  2502. Visible = false
  2503. };
  2504. Grid = new MirItemCell[10 * 16];
  2505. for (int x = 0; x < 10; x++)
  2506. {
  2507. for (int y = 0; y < 16; y++)
  2508. {
  2509. int idx = 10 * y + x;
  2510. Grid[idx] = new MirItemCell
  2511. {
  2512. ItemSlot = idx,
  2513. GridType = MirGridType.Storage,
  2514. Library = Libraries.Items,
  2515. Parent = this,
  2516. Location = new Point(x * 36 + 9 + x, y % 8 * 32 + 60 + y % 8),
  2517. };
  2518. if (idx >= Globals.StorageGridSize)
  2519. Grid[idx].Visible = false;
  2520. }
  2521. }
  2522. }
  2523. public override void Show()
  2524. {
  2525. if (GameScene.User == null) return;
  2526. ProtectButton.Enabled = GameScene.User.RequireStoragePassword;
  2527. if (!GameScene.User.RequireStoragePassword)
  2528. {
  2529. _storageUnlocked = true;
  2530. GameScene.Scene.InventoryDialog.Location = new Point(Size.Width + 5, Location.Y);
  2531. GameScene.Scene.InventoryDialog.Show();
  2532. RefreshStorage1();
  2533. Visible = true;
  2534. return;
  2535. }
  2536. if (!GameScene.User.HasStoragePassword)
  2537. {
  2538. GameScene.Scene.NPCDialog.Hide();
  2539. GameScene.Scene.InventoryDialog.Hide();
  2540. ForceStoragePasswordSetup();
  2541. return;
  2542. }
  2543. if (!_storageUnlocked)
  2544. {
  2545. GameScene.Scene.NPCDialog.Hide();
  2546. GameScene.Scene.InventoryDialog.Hide();
  2547. PromptStorageUnlock();
  2548. return;
  2549. }
  2550. GameScene.Scene.InventoryDialog.Location = new Point(Size.Width + 5, Location.Y);
  2551. GameScene.Scene.InventoryDialog.Show();
  2552. RefreshStorage1();
  2553. Visible = true;
  2554. }
  2555. public override void Hide()
  2556. {
  2557. _storageUnlocked = false;
  2558. base.Hide();
  2559. }
  2560. public void HandleStorageUnlockResult(S.StorageUnlockResult p)
  2561. {
  2562. if (GameScene.User != null)
  2563. GameScene.User.HasStoragePassword = p.HasPassword;
  2564. switch (p.Result)
  2565. {
  2566. case 0:
  2567. case 4:
  2568. _storageUnlocked = true;
  2569. Show();
  2570. return;
  2571. case 1:
  2572. SendStorageSystemMessage(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.StoragePasswordNotAcceptable));
  2573. return;
  2574. case 2:
  2575. SendStorageSystemMessage(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.StoragePasswordWrong));
  2576. return;
  2577. case 3:
  2578. SendStorageSystemMessage(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.StoragePasswordUnavailable));
  2579. return;
  2580. }
  2581. }
  2582. public void HandleStoragePasswordResult(S.StoragePasswordResult p)
  2583. {
  2584. bool hadPassword = GameScene.User != null && GameScene.User.HasStoragePassword;
  2585. if (GameScene.User != null)
  2586. {
  2587. GameScene.User.HasStoragePassword = p.HasPassword;
  2588. GameScene.User.StoragePasswordLastSet = p.LastSetTime;
  2589. }
  2590. StoragePasswordLabel.Visible = false;
  2591. switch (p.Result)
  2592. {
  2593. case 0:
  2594. SendStorageSystemMessage(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.StoragePasswordUnavailable));
  2595. return;
  2596. case 1:
  2597. case 3:
  2598. SendStorageSystemMessage(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.StoragePasswordNotAcceptable));
  2599. return;
  2600. case 2:
  2601. SendStorageSystemMessage(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.StoragePasswordWrong));
  2602. return;
  2603. case 5:
  2604. SendStorageSystemMessage(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.StoragePasswordNoPasswordSet));
  2605. return;
  2606. case 4:
  2607. _storageUnlocked = true;
  2608. if (p.Removing)
  2609. {
  2610. _pendingOpenAfterPasswordSet = false;
  2611. _forcingPasswordSetup = false;
  2612. SendStorageSystemMessage(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.StoragePasswordRemoveSuccess));
  2613. _storageUnlocked = false;
  2614. Hide();
  2615. return;
  2616. }
  2617. if (hadPassword)
  2618. SendStorageSystemMessage(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.StoragePasswordChangeSuccess));
  2619. else
  2620. SendStorageSystemMessage(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.StoragePasswordSetSuccess));
  2621. if (_pendingOpenAfterPasswordSet)
  2622. {
  2623. _pendingOpenAfterPasswordSet = false;
  2624. _forcingPasswordSetup = false;
  2625. Show();
  2626. }
  2627. return;
  2628. }
  2629. _pendingOpenAfterPasswordSet = false;
  2630. _forcingPasswordSetup = false;
  2631. }
  2632. private void SendStorageSystemMessage(string message)
  2633. {
  2634. GameScene.Scene?.ChatDialog.ReceiveChat(message, ChatType.System);
  2635. }
  2636. private void ManageStoragePassword()
  2637. {
  2638. if (GameScene.User == null) return;
  2639. if (!GameScene.User.RequireStoragePassword) return;
  2640. if (!GameScene.User.HasStoragePassword)
  2641. {
  2642. BeginSetStoragePassword();
  2643. return;
  2644. }
  2645. string prompt = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.StoragePasswordChangePrompt);
  2646. if (GameScene.User.StoragePasswordLastSet != DateTime.MinValue)
  2647. {
  2648. string lastSet = string.Format(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.StoragePasswordLastSetLabel),
  2649. GameScene.User.StoragePasswordLastSet.ToString("g"));
  2650. prompt = $"{prompt}{Environment.NewLine}{lastSet}";
  2651. }
  2652. MirMessageBox changePrompt = new MirMessageBox(prompt, MirMessageBoxButtons.OKCancel);
  2653. changePrompt.OKButton.Click += (o, e) => BeginChangeStoragePassword();
  2654. changePrompt.Show();
  2655. }
  2656. private void ForceStoragePasswordSetup()
  2657. {
  2658. _forcingPasswordSetup = true;
  2659. _pendingOpenAfterPasswordSet = true;
  2660. BeginSetStoragePassword(() => CancelStoragePasswordSetup(), true);
  2661. }
  2662. private void CancelStoragePasswordSetup()
  2663. {
  2664. _pendingOpenAfterPasswordSet = false;
  2665. _forcingPasswordSetup = false;
  2666. Hide();
  2667. }
  2668. private void BeginSetStoragePassword(Action onCancel = null, bool force = false)
  2669. {
  2670. PromptStoragePassword(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.StoragePasswordNewPrompt), newPassword =>
  2671. {
  2672. if (string.IsNullOrEmpty(newPassword))
  2673. {
  2674. if (force)
  2675. {
  2676. BeginSetStoragePassword(onCancel, true);
  2677. return false;
  2678. }
  2679. _pendingOpenAfterPasswordSet = false;
  2680. return false;
  2681. }
  2682. PromptStoragePassword(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.StoragePasswordConfirmPrompt), confirmPassword =>
  2683. {
  2684. if (!string.Equals(newPassword, confirmPassword, StringComparison.Ordinal))
  2685. {
  2686. SendStorageSystemMessage(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.StoragePasswordMismatch));
  2687. if (force)
  2688. {
  2689. BeginSetStoragePassword(onCancel, true);
  2690. return false;
  2691. }
  2692. _pendingOpenAfterPasswordSet = false;
  2693. return false;
  2694. }
  2695. Network.Enqueue(new C.SetStoragePassword { CurrentPassword = string.Empty, NewPassword = newPassword });
  2696. return true;
  2697. }, onCancel);
  2698. return true;
  2699. }, onCancel);
  2700. }
  2701. private void BeginChangeStoragePassword()
  2702. {
  2703. PromptStoragePassword(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.StoragePasswordCurrentPrompt), currentPassword =>
  2704. {
  2705. if (string.IsNullOrEmpty(currentPassword))
  2706. {
  2707. return false;
  2708. }
  2709. PromptStoragePassword(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.StoragePasswordNewPrompt), newPassword =>
  2710. {
  2711. if (string.IsNullOrEmpty(newPassword))
  2712. {
  2713. return false;
  2714. }
  2715. PromptStoragePassword(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.StoragePasswordConfirmPrompt), confirmPassword =>
  2716. {
  2717. if (!string.Equals(newPassword, confirmPassword, StringComparison.Ordinal))
  2718. {
  2719. SendStorageSystemMessage(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.StoragePasswordMismatch));
  2720. return false;
  2721. }
  2722. Network.Enqueue(new C.SetStoragePassword { CurrentPassword = currentPassword, NewPassword = newPassword });
  2723. return true;
  2724. });
  2725. return true;
  2726. });
  2727. return true;
  2728. });
  2729. }
  2730. private void PromptStorageUnlock()
  2731. {
  2732. PromptStoragePassword(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.StoragePasswordPrompt), password =>
  2733. {
  2734. if (string.IsNullOrEmpty(password))
  2735. {
  2736. return false;
  2737. }
  2738. Network.Enqueue(new C.UnlockStorage { Password = password });
  2739. return true;
  2740. }, () => Hide());
  2741. }
  2742. private void PromptStoragePassword(string prompt, Func<string, bool> onSubmit, Action onCancel = null)
  2743. {
  2744. string rules = string.Format(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.StoragePasswordRules),
  2745. Globals.MinPasswordLength, Globals.MaxPasswordLength);
  2746. MirInputBox inputBox = new MirInputBox($"{prompt}{Environment.NewLine}{rules}");
  2747. inputBox.InputTextBox.Password = true;
  2748. inputBox.OKButton.Enabled = false;
  2749. inputBox.InputTextBox.TextBox.TextChanged += (o, e) =>
  2750. {
  2751. inputBox.OKButton.Enabled = !string.IsNullOrEmpty(inputBox.InputTextBox.Text);
  2752. };
  2753. if (onCancel != null)
  2754. {
  2755. inputBox.CancelButton.Click += (o, e) =>
  2756. {
  2757. inputBox.Dispose();
  2758. onCancel();
  2759. };
  2760. }
  2761. inputBox.OKButton.Click += (o, e) =>
  2762. {
  2763. string value = inputBox.InputTextBox.Text;
  2764. if (string.IsNullOrEmpty(value) || onSubmit == null) return;
  2765. if (onSubmit.Invoke(value))
  2766. {
  2767. inputBox.Dispose();
  2768. return;
  2769. }
  2770. inputBox.InputTextBox.SetFocus();
  2771. };
  2772. inputBox.Show();
  2773. }
  2774. public void RefreshStorage1()
  2775. {
  2776. if (GameScene.User == null) return;
  2777. Storage1Button.Index = 743;
  2778. Storage1Button.HoverIndex = 743;
  2779. Storage2Button.Index = 746;
  2780. Storage2Button.HoverIndex = 746;
  2781. foreach (var grid in Grid)
  2782. {
  2783. if (grid.ItemSlot < Globals.StorageGridSize)
  2784. grid.Visible = true;
  2785. else
  2786. grid.Visible = false;
  2787. }
  2788. RentButton.Visible = false;
  2789. LockedPage.Visible = false;
  2790. RentalLabel.Visible = false;
  2791. StoragePasswordLabel.Visible = false;
  2792. }
  2793. public void RefreshStorage2()
  2794. {
  2795. if (GameScene.User == null) return;
  2796. Storage1Button.Index = 744;
  2797. Storage1Button.HoverIndex = 744;
  2798. Storage2Button.Index = 745;
  2799. Storage2Button.HoverIndex = 745;
  2800. RentalLabel.Visible = true;
  2801. if (GameScene.User.HasExpandedStorage)
  2802. {
  2803. RentButton.Visible = true;
  2804. LockedPage.Visible = false;
  2805. RentalLabel.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ExpandedStorageExpiresOn) + GameScene.User.ExpandedStorageExpiryTime.ToString();
  2806. RentalLabel.ForeColour = Color.White;
  2807. }
  2808. else
  2809. {
  2810. RentalLabel.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ExpandedStorageLocked);
  2811. RentalLabel.ForeColour = Color.Red;
  2812. RentButton.Visible = true;
  2813. LockedPage.Visible = true;
  2814. }
  2815. foreach (var grid in Grid)
  2816. {
  2817. if (grid.ItemSlot < Globals.StorageGridSize || !GameScene.User.HasExpandedStorage)
  2818. grid.Visible = false;
  2819. else
  2820. grid.Visible = true;
  2821. }
  2822. StoragePasswordLabel.Visible = false;
  2823. }
  2824. public MirItemCell GetCell(ulong id)
  2825. {
  2826. for (int i = 0; i < Grid.Length; i++)
  2827. {
  2828. if (Grid[i].Item == null || Grid[i].Item.UniqueID != id) continue;
  2829. return Grid[i];
  2830. }
  2831. return null;
  2832. }
  2833. }
  2834. public sealed class BigButtonDialog : MirImageControl
  2835. {
  2836. const int MaximumRows = 8;
  2837. private List<BigButton> CurrentButtons;
  2838. private int ScrollOffset = 0;
  2839. public BigButtonDialog()
  2840. {
  2841. Visible = false;
  2842. }
  2843. public void Show(List<BigButton> buttons, int minimumButtons)
  2844. {
  2845. if (Visible) return;
  2846. CurrentButtons = buttons;
  2847. for (int i = 0; i < Controls.Count; i++)
  2848. Controls[i].Dispose();
  2849. Controls.Clear();
  2850. Size = Size.Empty;
  2851. ScrollOffset = 0;
  2852. CurrentButtons.ToList().ForEach(b => b.MouseWheel += (o, e) => BigButtonDialog_MouseWheel(o, e));
  2853. int count = Math.Max(minimumButtons, buttons.Count);
  2854. for (int i = 0; i < Math.Min(count, MaximumRows); i++)
  2855. {
  2856. MirImageControl background = new MirImageControl()
  2857. {
  2858. Parent = this,
  2859. Library = Libraries.Title,
  2860. Location = new Point(buttons.Count == 1 ? -1 : 0, Size.Height),
  2861. Index = count == 1 ? 836 : (i == 0 ? 838 : (i == count - 1 ? 840 : 839)),
  2862. NotControl = false,
  2863. Visible = true,
  2864. };
  2865. background.MouseWheel += (o, e) => BigButtonDialog_MouseWheel(o, e);
  2866. Size = new Size(background.Size.Width, Size.Height + background.Size.Height);
  2867. }
  2868. RefreshButtons();
  2869. MirImageControl footer = new MirImageControl()
  2870. {
  2871. Parent = this,
  2872. Library = Libraries.Title,
  2873. Location = new Point(-1, Size.Height),
  2874. Index = 837,
  2875. NotControl = false,
  2876. Visible = true,
  2877. };
  2878. Size = new Size(Size.Width, Size.Height + footer.Size.Height);
  2879. if (buttons.Count > MaximumRows)
  2880. {
  2881. MirButton upButton = new MirButton
  2882. {
  2883. Index = 197,
  2884. HoverIndex = 198,
  2885. PressedIndex = 199,
  2886. Library = Libraries.Prguse2,
  2887. Parent = this,
  2888. Size = new Size(16, 14),
  2889. Sound = SoundList.ButtonA,
  2890. Location = new Point(Size.Width - 26, 17)
  2891. };
  2892. upButton.Click += (o, e) =>
  2893. {
  2894. ScrollUp();
  2895. };
  2896. MirButton downButton = new MirButton
  2897. {
  2898. Index = 207,
  2899. HoverIndex = 208,
  2900. Library = Libraries.Prguse2,
  2901. PressedIndex = 209,
  2902. Parent = this,
  2903. Size = new Size(16, 14),
  2904. Sound = SoundList.ButtonA,
  2905. Location = new Point(Size.Width - 26, Size.Height - 57)
  2906. };
  2907. downButton.Click += (o, e) =>
  2908. {
  2909. ScrollDown();
  2910. };
  2911. }
  2912. Visible = true;
  2913. }
  2914. public override void Hide()
  2915. {
  2916. Size = Size.Empty;
  2917. Visible = false;
  2918. }
  2919. private void RefreshButtons()
  2920. {
  2921. CurrentButtons.ToList().ForEach(b => b.Visible = false);
  2922. for (int i = 0; i < Math.Min(CurrentButtons.Count, MaximumRows); i++)
  2923. {
  2924. CurrentButtons[i + ScrollOffset].Parent = this;
  2925. CurrentButtons[i + ScrollOffset].Visible = true;
  2926. CurrentButtons[i + ScrollOffset].Location = new Point(97, 7 + i * 40);
  2927. }
  2928. }
  2929. private void BigButtonDialog_MouseWheel(object sender, MouseEventArgs e)
  2930. {
  2931. int count = e.Delta / SystemInformation.MouseWheelScrollDelta;
  2932. if (count > 0)
  2933. ScrollUp();
  2934. else if (count < 0)
  2935. ScrollDown();
  2936. }
  2937. private void ScrollUp()
  2938. {
  2939. if (ScrollOffset <= 0) return;
  2940. ScrollOffset--;
  2941. RefreshButtons();
  2942. }
  2943. private void ScrollDown()
  2944. {
  2945. if (ScrollOffset + MaximumRows >= CurrentButtons.Count) return;
  2946. ScrollOffset++;
  2947. RefreshButtons();
  2948. }
  2949. }
  2950. public sealed class BigButton : MirButton
  2951. {
  2952. #region Label
  2953. private MirLabel _shadowLabel;
  2954. #endregion
  2955. #region CenterText
  2956. public override bool CenterText
  2957. {
  2958. get
  2959. {
  2960. return _center;
  2961. }
  2962. set
  2963. {
  2964. _center = value;
  2965. if (_center)
  2966. {
  2967. _label.Size = Size;
  2968. _label.DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter;
  2969. _shadowLabel.Size = Size;
  2970. _shadowLabel.DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter;
  2971. }
  2972. else
  2973. {
  2974. _label.AutoSize = true;
  2975. _shadowLabel.AutoSize = true;
  2976. }
  2977. }
  2978. }
  2979. #endregion
  2980. #region Font Colour
  2981. public override Color FontColour
  2982. {
  2983. get
  2984. {
  2985. if (_label != null && !_label.IsDisposed)
  2986. return _label.ForeColour;
  2987. return Color.Empty;
  2988. }
  2989. set
  2990. {
  2991. if (_label != null && !_label.IsDisposed)
  2992. _label.ForeColour = value;
  2993. }
  2994. }
  2995. #endregion
  2996. #region Size
  2997. protected override void OnSizeChanged()
  2998. {
  2999. base.OnSizeChanged();
  3000. if (_shadowLabel != null && !_shadowLabel.IsDisposed)
  3001. _shadowLabel.Size = Size;
  3002. }
  3003. #endregion
  3004. #region Text
  3005. public override string Text
  3006. {
  3007. set
  3008. {
  3009. if (_label != null && !_label.IsDisposed)
  3010. {
  3011. _label.Text = value;
  3012. _label.Visible = !string.IsNullOrEmpty(value);
  3013. }
  3014. if (_shadowLabel != null && !_shadowLabel.IsDisposed)
  3015. {
  3016. _shadowLabel.Text = value;
  3017. _shadowLabel.Visible = !string.IsNullOrEmpty(value);
  3018. }
  3019. }
  3020. }
  3021. #endregion
  3022. public BigButton()
  3023. {
  3024. HoverIndex = -1;
  3025. PressedIndex = -1;
  3026. DisabledIndex = -1;
  3027. Sound = SoundList.ButtonB;
  3028. _shadowLabel = new MirLabel
  3029. {
  3030. NotControl = true,
  3031. Parent = this,
  3032. Location = new Point(2, 7),
  3033. AutoSize = false,
  3034. Size = new Size(237, 20),
  3035. DrawFormat = TextFormatFlags.HorizontalCenter,
  3036. ForeColour = Color.Black,
  3037. Font = ScaleFont(new Font(Settings.FontName, 12F, FontStyle.Bold))
  3038. };
  3039. _label = new MirLabel
  3040. {
  3041. NotControl = true,
  3042. Parent = this,
  3043. Location = new Point(0, 5),
  3044. AutoSize = false,
  3045. Size = new Size(237, 20),
  3046. DrawFormat = TextFormatFlags.HorizontalCenter,
  3047. Font = ScaleFont(new Font(Settings.FontName, 12F, FontStyle.Bold))
  3048. };
  3049. }
  3050. protected internal override void DrawControl()
  3051. {
  3052. base.DrawControl();
  3053. if (DrawImage && Library != null)
  3054. {
  3055. bool oldGray = DXManager.GrayScale;
  3056. if (GrayScale)
  3057. {
  3058. DXManager.SetGrayscale(true);
  3059. }
  3060. if (Blending)
  3061. Library.DrawBlend(Index + 3, DisplayLocation, Color.White, false, BlendingRate);
  3062. else
  3063. Library.Draw(Index + 3, DisplayLocation, Color.White, false, Opacity);
  3064. if (GrayScale) DXManager.SetGrayscale(oldGray);
  3065. }
  3066. }
  3067. #region Disposable
  3068. protected override void Dispose(bool disposing)
  3069. {
  3070. base.Dispose(disposing);
  3071. if (!disposing) return;
  3072. if (_shadowLabel != null && !_shadowLabel.IsDisposed)
  3073. _shadowLabel.Dispose();
  3074. _shadowLabel = null;
  3075. }
  3076. #endregion
  3077. }
  3078. }