BigMapDialog.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  1. using Client.MirControls;
  2. using Client.MirGraphics;
  3. using Client.MirNetwork;
  4. using Client.MirObjects;
  5. using Client.MirSounds;
  6. using SlimDX;
  7. using Font = System.Drawing.Font;
  8. using C = ClientPackets;
  9. namespace Client.MirScenes.Dialogs
  10. {
  11. public sealed class BigMapDialog : MirImageControl
  12. {
  13. MirLabel CoordinateLabel, TitleLabel;
  14. public MirButton CloseButton, ScrollUpButton, ScrollDownButton, ScrollBar, WorldButton, MyLocationButton, TeleportToButton, SearchButton;
  15. public MirTextBox SearchTextBox;
  16. private float GapPerRow;
  17. const int MaximumRows = 18;
  18. public int TargetMapIndex;
  19. private DateTime NextSearchTime;
  20. public BigMapViewPort ViewPort;
  21. public WorldMapImage WorldMap;
  22. private int scrollOffset;
  23. private int ScrollOffset
  24. {
  25. get { return scrollOffset; }
  26. set
  27. {
  28. scrollOffset = value;
  29. ScrollBar.Location = new Point(ScrollUpButton.Location.X, (int)(ScrollUpButton.Location.Y + 13 + scrollOffset * GapPerRow));
  30. }
  31. }
  32. private Point mouseLocation = Point.Empty;
  33. public Point MouseLocation
  34. {
  35. get { return mouseLocation; }
  36. set
  37. {
  38. if (mouseLocation == value) return;
  39. mouseLocation = value;
  40. MakeCoordinateLabel();
  41. }
  42. }
  43. private BigMapNPCRow selectedNPC;
  44. public BigMapNPCRow SelectedNPC
  45. {
  46. get { return selectedNPC; }
  47. set
  48. {
  49. if (value == selectedNPC) return;
  50. if (selectedNPC != null)
  51. selectedNPC.NameLabel.ForeColour = Color.White;
  52. selectedNPC = value;
  53. if (value != null)
  54. {
  55. selectedNPC.NameLabel.ForeColour = Color.Brown;
  56. ViewPort.SelectedNPCIcon.Index = selectedNPC.Info.Icon;
  57. ViewPort.SelectedNPCIcon.Visible = true;
  58. var map = GameScene.Scene.MapControl;
  59. TeleportToButton.Enabled = TargetMapIndex == map.Index && selectedNPC.Info.CanTeleportTo;
  60. }
  61. else
  62. {
  63. ViewPort.SelectedNPCIcon.Visible = false;
  64. TeleportToButton.Enabled = false;
  65. }
  66. }
  67. }
  68. private BigMapRecord currentRecord;
  69. public BigMapRecord CurrentRecord
  70. {
  71. get { return currentRecord; }
  72. set
  73. {
  74. if (currentRecord == value) return;
  75. SetButtonsVisibility(false);
  76. currentRecord = value;
  77. TitleLabel.Text = currentRecord != null ? currentRecord.MapInfo.Title : string.Empty;
  78. ViewPort.UserRadarDot.Visible = currentRecord != null && currentRecord.Index == GameScene.Scene.MapControl.Index;
  79. SetButtonsVisibility(true);
  80. }
  81. }
  82. public BigMapDialog()
  83. {
  84. Index = 820;
  85. Library = Libraries.Title;
  86. Sort = true;
  87. Location = Center;
  88. NotControl = false;
  89. ScrollUpButton = new MirButton
  90. {
  91. Index = 197,
  92. HoverIndex = 198,
  93. PressedIndex = 199,
  94. Location = new Point(Size.Width - 21, 48),
  95. Library = Libraries.Prguse2,
  96. Parent = this,
  97. Sound = SoundList.ButtonA,
  98. };
  99. ScrollUpButton.Click += (o, e) => ScrollUp();
  100. ScrollDownButton = new MirButton
  101. {
  102. Index = 207,
  103. HoverIndex = 208,
  104. PressedIndex = 209,
  105. Location = new Point(Size.Width - 21, 417),
  106. Library = Libraries.Prguse2,
  107. Parent = this,
  108. Sound = SoundList.ButtonA,
  109. };
  110. ScrollDownButton.Click += (o, e) => ScrollDown();
  111. ScrollBar = new MirButton
  112. {
  113. Index = 205,
  114. HoverIndex = 206,
  115. PressedIndex = 206,
  116. Location = new Point(Size.Width - 21, ScrollUpButton.Location.Y + 13),
  117. Library = Libraries.Prguse2,
  118. Parent = this,
  119. Movable = true,
  120. Sound = SoundList.ButtonA,
  121. };
  122. ScrollBar.OnMoving += (o, e) =>
  123. {
  124. var y = ScrollBar.Location.Y;
  125. if (y < 61)
  126. y = 61;
  127. if (y > 398)
  128. y = 398;
  129. var row = (y - ScrollUpButton.Location.Y + 13) / GapPerRow;
  130. ScrollOffset = (int)row;
  131. SetNPCButtonVisibility(true);
  132. };
  133. WorldButton = new MirButton
  134. {
  135. Index = 827,
  136. HoverIndex = 828,
  137. PressedIndex = 829,
  138. Location = new Point(250, Size.Height - 33),
  139. Library = Libraries.Title,
  140. Parent = this,
  141. Sound = SoundList.ButtonA,
  142. };
  143. WorldButton.Click += (o, e) => OpenWorldMap();
  144. MyLocationButton = new MirButton
  145. {
  146. Index = 824,
  147. HoverIndex = 825,
  148. PressedIndex = 826,
  149. Location = new Point(400, Size.Height - 33),
  150. Library = Libraries.Title,
  151. Parent = this,
  152. Sound = SoundList.ButtonA,
  153. };
  154. MyLocationButton.Click += (o, e) => TargetMyLocation();
  155. TeleportToButton = new MirButton
  156. {
  157. Index = 821,
  158. HoverIndex = 822,
  159. PressedIndex = 823,
  160. DisabledIndex = 823,
  161. Enabled = false,
  162. Location = new Point(Size.Width - 122, 432),
  163. Library = Libraries.Title,
  164. Parent = this,
  165. Sound = SoundList.ButtonA,
  166. };
  167. TeleportToButton.Click += (o, e) => TeleportToNPC();
  168. SearchButton = new MirButton
  169. {
  170. Index = 1340,
  171. HoverIndex = 1341,
  172. PressedIndex = 1342,
  173. Enabled = true,
  174. Location = new Point(23, Size.Height - 36),
  175. Library = Libraries.Prguse2,
  176. Parent = this,
  177. Sound = SoundList.ButtonA,
  178. Hint = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SearchForNPCs)
  179. };
  180. SearchButton.Click += (o, e) => Search();
  181. SearchTextBox = new MirTextBox
  182. {
  183. Location = new Point(59, Size.Height - 27),
  184. Parent = this,
  185. Font = new Font(Settings.FontName, 8F),
  186. Size = new Size(130, 10),
  187. MaxLength = Globals.MaxChatLength
  188. };
  189. SearchTextBox.TextBox.KeyPress += SearchTextBox_KeyPress;
  190. ViewPort = new BigMapViewPort()
  191. {
  192. Parent = this
  193. };
  194. CoordinateLabel = new MirLabel
  195. {
  196. AutoSize = true,
  197. ForeColour = Color.White,
  198. Location = new Point(519, 435),
  199. Parent = this,
  200. };
  201. TitleLabel = new MirLabel
  202. {
  203. ForeColour = Color.White,
  204. Parent = this,
  205. AutoSize = false,
  206. Size = new Size(699, 20),
  207. Location = new Point(19, 6),
  208. Font = new Font(Settings.FontName, 9F, FontStyle.Bold),
  209. DrawFormat = TextFormatFlags.HorizontalCenter
  210. };
  211. WorldMap = new WorldMapImage()
  212. {
  213. Parent = this,
  214. Location = new Point(10, 0)
  215. };
  216. CloseButton = new MirButton
  217. {
  218. HoverIndex = 361,
  219. Index = 360,
  220. Location = new Point(Size.Width - 25, 3),
  221. Library = Libraries.Prguse2,
  222. Parent = this,
  223. PressedIndex = 362,
  224. Sound = SoundList.ButtonA,
  225. };
  226. CloseButton.Click += (o, e) => Hide();
  227. SearchTextBox.Enabled = false;
  228. }
  229. private void MakeCoordinateLabel()
  230. {
  231. CoordinateLabel.Text = $"[ {MouseLocation.X}, {MouseLocation.Y} ]";
  232. }
  233. public void ShowCoordinateLabel()
  234. {
  235. CoordinateLabel.Visible = true;
  236. }
  237. public void HideCoordinateLabel()
  238. {
  239. CoordinateLabel.Visible = false;
  240. }
  241. public void WorldMapSetup(WorldMapSetup setup)
  242. {
  243. WorldButton.Visible = setup.Enabled;
  244. WorldMap.MakeButtons(setup.Icons);
  245. }
  246. public void Toggle()
  247. {
  248. if (Visible)
  249. Hide();
  250. else
  251. Show();
  252. }
  253. public override void Show()
  254. {
  255. var map = GameScene.Scene.MapControl;
  256. if (map.BigMap <= 0) return;
  257. SearchTextBox.Enabled = false;
  258. base.Show();
  259. TargetMyLocation();
  260. }
  261. private void TargetMyLocation()
  262. {
  263. var map = GameScene.Scene.MapControl;
  264. if (map == null) return;
  265. SetTargetMap(map.Index);
  266. }
  267. public void SetTargetMap(int MapIndex)
  268. {
  269. TargetMapIndex = MapIndex;
  270. CurrentRecord = null;
  271. ScrollOffset = 0;
  272. ScrollBar.Visible = false;
  273. WorldMap.Visible = false;
  274. SearchTextBox.Visible = true;
  275. SelectedNPC = null;
  276. if (!GameScene.MapInfoList.ContainsKey(MapIndex))
  277. Network.Enqueue(new C.RequestMapInfo() { MapIndex = MapIndex });
  278. else
  279. CurrentRecord = GameScene.MapInfoList[MapIndex];
  280. Redraw();
  281. }
  282. public void SetTargetNPC(uint NPCIndex)
  283. {
  284. if (CurrentRecord?.NPCButtons == null)
  285. return;
  286. foreach (BigMapNPCRow row in CurrentRecord.NPCButtons)
  287. {
  288. if (row.Info.ObjectID != NPCIndex) continue;
  289. SelectedNPC = row;
  290. return;
  291. }
  292. }
  293. private void SetButtonsVisibility(bool visible)
  294. {
  295. if (currentRecord == null) return;
  296. SetMovementButtonsVisibility(visible);
  297. SetNPCButtonVisibility(visible);
  298. }
  299. private void SetMovementButtonsVisibility(bool visible)
  300. {
  301. foreach (var button in currentRecord.MovementButtons.Values)
  302. button.Visible = visible;
  303. }
  304. private void SetNPCButtonVisibility(bool visible)
  305. {
  306. foreach (var row in currentRecord.NPCButtons)
  307. row.Visible = false;
  308. if (!visible) return;
  309. for (int i = ScrollOffset; i < ScrollOffset + MaximumRows; i++)
  310. {
  311. if (i >= currentRecord.NPCButtons.Count) return;
  312. currentRecord.NPCButtons[i].Location = new Point(590, 50 + (i - ScrollOffset) * 21);
  313. currentRecord.NPCButtons[i].Visible = true;
  314. }
  315. if (currentRecord.NPCButtons.Count <= MaximumRows) return;
  316. ScrollBar.Visible = true;
  317. var scrollHeight = ScrollDownButton.Location.Y - ScrollUpButton.Location.Y - 32;
  318. var extraRows = currentRecord.NPCButtons.Count - MaximumRows;
  319. GapPerRow = scrollHeight / (float)extraRows;
  320. }
  321. public void BigMap_MouseWheel(object sender, MouseEventArgs e)
  322. {
  323. int count = e.Delta / SystemInformation.MouseWheelScrollDelta;
  324. if (count > 0)
  325. ScrollUp();
  326. else if (count < 0)
  327. ScrollDown();
  328. }
  329. private void ScrollUp()
  330. {
  331. if (ScrollOffset == 0) return;
  332. ScrollOffset--;
  333. SetNPCButtonVisibility(true);
  334. }
  335. private void ScrollDown()
  336. {
  337. if (ScrollOffset >= currentRecord.NPCButtons.Count - MaximumRows) return;
  338. ScrollOffset++;
  339. SetNPCButtonVisibility(true);
  340. }
  341. private void OpenWorldMap()
  342. {
  343. WorldMap.Visible = true;
  344. SearchTextBox.Visible = false;
  345. SetButtonsVisibility(false);
  346. }
  347. private void TeleportToNPC()
  348. {
  349. if (SelectedNPC == null || !SelectedNPC.Info.CanTeleportTo) return;
  350. MirMessageBox messageBox = new MirMessageBox(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.TeleportToNpcForGold), GameScene.TeleportToNPCCost), MirMessageBoxButtons.YesNo);
  351. messageBox.YesButton.Click += (o, e) =>
  352. {
  353. if (GameScene.Gold < GameScene.TeleportToNPCCost)
  354. {
  355. MirMessageBox messageBox2 = new MirMessageBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NotEnoughGold), MirMessageBoxButtons.OK);
  356. messageBox2.Show();
  357. return;
  358. }
  359. Network.Enqueue(new C.TeleportToNPC { ObjectID = SelectedNPC.Info.ObjectID });
  360. };
  361. messageBox.Show();
  362. }
  363. private void Search()
  364. {
  365. if (!SearchTextBox.Enabled)
  366. {
  367. SearchTextBox.Enabled = true;
  368. SearchTextBox.SetFocus();
  369. }
  370. if (!string.IsNullOrWhiteSpace(SearchTextBox.Text) && SearchTextBox.Text.Length > 2) return;
  371. if (CMain.Now < NextSearchTime) return;
  372. NextSearchTime = CMain.Now.AddSeconds(1);
  373. Network.Enqueue(new C.SearchMap { Text = SearchTextBox.Text });
  374. }
  375. public void SearchTextBox_KeyPress(object sender, KeyPressEventArgs e)
  376. {
  377. if (sender == null || e.KeyChar != (char)Keys.Enter) return;
  378. e.Handled = true;
  379. if (SearchButton.Enabled)
  380. SearchButton.InvokeMouseClick(null);
  381. }
  382. #region Disposable
  383. protected override void Dispose(bool disposing)
  384. {
  385. if (disposing)
  386. {
  387. CoordinateLabel = null;
  388. CloseButton = null;
  389. ScrollUpButton = null;
  390. ScrollDownButton = null;
  391. ScrollBar = null;
  392. WorldButton = null;
  393. MyLocationButton = null;
  394. TeleportToButton = null;
  395. SearchButton = null;
  396. SearchTextBox = null;
  397. TitleLabel = null;
  398. }
  399. base.Dispose(disposing);
  400. }
  401. #endregion
  402. }
  403. public class WorldMapImage : MirImageControl
  404. {
  405. private new MirImageControl Border;
  406. private MirImageControl Clouds;
  407. private List<MirButton> ButtonList = new List<MirButton>();
  408. private MirLabel TitleLabel;
  409. public WorldMapImage()
  410. {
  411. Library = Libraries.Prguse2;
  412. Index = 1360;
  413. NotControl = false;
  414. Visible = false;
  415. Clouds = new MirImageControl()
  416. {
  417. Parent = this,
  418. Library = Libraries.Prguse2,
  419. Index = 1365,
  420. NotControl = true,
  421. Visible = true,
  422. Blending = true
  423. };
  424. Border = new MirImageControl()
  425. {
  426. Parent = this,
  427. Library = Libraries.Prguse2,
  428. Index = 1366,
  429. NotControl = true,
  430. Visible = true
  431. };
  432. TitleLabel = new MirLabel()
  433. {
  434. AutoSize = true,
  435. BackColour = Color.Black,
  436. ForeColour = Color.White,
  437. Parent = this,
  438. Visible = true
  439. };
  440. }
  441. public void MakeButtons(List<WorldMapIcon> icons)
  442. {
  443. foreach (WorldMapIcon icon in icons)
  444. {
  445. MirButton button = new MirButton()
  446. {
  447. Index = icon.ImageIndex,
  448. UseOffSet = true,
  449. Library = Libraries.MapLinkIcon,
  450. Parent = this,
  451. Sound = SoundList.ButtonA,
  452. OnlyDrawWhenActive = true
  453. };
  454. button.Click += (o, e) =>
  455. {
  456. GameScene.Scene.BigMapDialog.SetTargetMap(icon.MapIndex);
  457. };
  458. button.MouseEnter += (o, e) =>
  459. {
  460. TitleLabel.Text = icon.Title;
  461. TitleLabel.Location = new Point(Size.Width / 2 - TitleLabel.Size.Width / 2, 10);
  462. };
  463. button.MouseLeave += (o, e) =>
  464. {
  465. TitleLabel.Text = string.Empty;
  466. };
  467. ButtonList.Add(button);
  468. }
  469. }
  470. }
  471. public sealed class BigMapViewPort : MirControl
  472. {
  473. BigMapDialog ParentDialog;
  474. float ScaleX;
  475. float ScaleY;
  476. public MirImageControl SelectedNPCIcon, UserRadarDot;
  477. int BigMap_MouseCoordsProcessing_OffsetX, BigMap_MouseCoordsProcessing_OffsetY;
  478. public MirImageControl[] Players;
  479. public static Dictionary<string, Point> PlayerLocations = new Dictionary<string, Point>();
  480. public BigMapViewPort()
  481. {
  482. NotControl = false;
  483. Size = new Size(568, 380);
  484. SelectedNPCIcon = new MirImageControl
  485. {
  486. Library = Libraries.MapLinkIcon,
  487. NotControl = false,
  488. Parent = this,
  489. Visible = false
  490. };
  491. SelectedNPCIcon.MouseEnter += (o, e) => ParentDialog.MouseLocation = ParentDialog.SelectedNPC.Info.Location;
  492. UserRadarDot = new MirImageControl
  493. {
  494. Library = Libraries.Prguse2,
  495. Index = 1350,
  496. Parent = this,
  497. Visible = false,
  498. NotControl = true
  499. };
  500. Players = new MirImageControl[Globals.MaxGroup];
  501. for (int i = 0; i < Players.Length; i++)
  502. {
  503. Players[i] = new MirImageControl
  504. {
  505. Index = 1350,
  506. Library = Libraries.Prguse2,
  507. Parent = this,
  508. NotControl = false,
  509. Visible = false,
  510. };
  511. }
  512. BeforeDraw += (o, e) => OnBeforeDraw();
  513. MouseMove += UpdateBigMapCoordinates;
  514. ParentChanged += (o, e) => SetParent();
  515. MouseDown += OnMouseClick;
  516. }
  517. private void SetParent()
  518. {
  519. ParentDialog = (BigMapDialog)Parent;
  520. }
  521. private void UpdateBigMapCoordinates(object sender, MouseEventArgs e)
  522. {
  523. int MouseCoordsOnBigMap_MapValue_X = (int)((e.Location.X - BigMap_MouseCoordsProcessing_OffsetX) / ScaleX);
  524. int MouseCoordsOnBigMap_MapValue_Y = (int)((e.Location.Y - BigMap_MouseCoordsProcessing_OffsetY) / ScaleY);
  525. ParentDialog.MouseLocation = new Point(MouseCoordsOnBigMap_MapValue_X, MouseCoordsOnBigMap_MapValue_Y);
  526. }
  527. private void OnMouseClick(object sender, MouseEventArgs e)
  528. {
  529. int X = (int)((e.Location.X - BigMap_MouseCoordsProcessing_OffsetX) / ScaleX);
  530. int Y = (int)((e.Location.Y - BigMap_MouseCoordsProcessing_OffsetY) / ScaleY);
  531. var path = GameScene.Scene.MapControl.PathFinder.FindPath(MapObject.User.CurrentLocation, new Point(X, Y));
  532. if (path == null || path.Count == 0)
  533. {
  534. GameScene.Scene.ChatDialog.ReceiveChat(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.CouldNotFindPath), ChatType.System);
  535. }
  536. else
  537. {
  538. GameScene.Scene.MapControl.CurrentPath = path;
  539. GameScene.Scene.MapControl.AutoPath = true;
  540. }
  541. }
  542. private void OnBeforeDraw()
  543. {
  544. if (!Parent.Visible) return;
  545. MouseMove -= UpdateBigMapCoordinates;
  546. BigMapRecord currentRecord;
  547. if (!GameScene.MapInfoList.TryGetValue(ParentDialog.TargetMapIndex, out currentRecord))
  548. return;
  549. ParentDialog.CurrentRecord = currentRecord;
  550. int index = currentRecord.MapInfo.BigMap;
  551. if (index <= 0)
  552. return;
  553. MouseMove += UpdateBigMapCoordinates;
  554. Size = Libraries.MiniMap.GetSize(index);
  555. Rectangle viewRect = new Rectangle(0, 0, Math.Min(568, Size.Width), Math.Min(380, Size.Height));
  556. viewRect.X = 14 + (568 - viewRect.Width) / 2;
  557. viewRect.Y = 52 + (380 - viewRect.Height) / 2;
  558. Location = viewRect.Location;
  559. Size = viewRect.Size;
  560. BigMap_MouseCoordsProcessing_OffsetX = DisplayLocation.X;
  561. BigMap_MouseCoordsProcessing_OffsetY = DisplayLocation.Y;
  562. ScaleX = Size.Width / (float)currentRecord.MapInfo.Width;
  563. ScaleY = Size.Height / (float)currentRecord.MapInfo.Height;
  564. viewRect.Location = new Point(
  565. (int)(ScaleX * MapObject.User.CurrentLocation.X) - viewRect.Width / 2,
  566. (int)(ScaleY * MapObject.User.CurrentLocation.Y) - viewRect.Height / 2);
  567. if (viewRect.Right >= Size.Width)
  568. viewRect.X = Size.Width - viewRect.Width;
  569. if (viewRect.Bottom >= Size.Height)
  570. viewRect.Y = Size.Height - viewRect.Height;
  571. if (viewRect.X < 0) viewRect.X = 0;
  572. if (viewRect.Y < 0) viewRect.Y = 0;
  573. Libraries.MiniMap.Draw(index, DisplayLocation, Size, Color.FromArgb(255, 255, 255));
  574. int startPointX = (int)(viewRect.X / ScaleX);
  575. int startPointY = (int)(viewRect.Y / ScaleY);
  576. var map = GameScene.Scene.MapControl;
  577. if (ParentDialog.TargetMapIndex == map.Index)
  578. {
  579. float x;
  580. float y;
  581. foreach (var ob in MapControl.Objects.Values)
  582. {
  583. if (ob.Race == ObjectType.Item || ob.Dead || ob.Race == ObjectType.Spell || ob.ObjectID == MapObject.User.ObjectID) continue;
  584. x = ((ob.CurrentLocation.X - startPointX) * ScaleX) + DisplayLocation.X;
  585. y = ((ob.CurrentLocation.Y - startPointY) * ScaleY) + DisplayLocation.Y;
  586. Color colour;
  587. if (GroupDialog.GroupList.Contains(ob.Name) || ob.Name.EndsWith(string.Format("({0})", MapObject.User.Name)))
  588. colour = Color.FromArgb(0, 0, 255);
  589. else
  590. if (ob is PlayerObject)
  591. colour = Color.FromArgb(255, 255, 255);
  592. else if (ob is NPCObject || ob.AI == 6)
  593. colour = Color.FromArgb(0, 255, 50);
  594. else
  595. colour = Color.FromArgb(255, 0, 0);
  596. DXManager.Draw(DXManager.RadarTexture, new Rectangle(0, 0, 2, 2), new Vector3((float)(x - 0.5), (float)(y - 0.5), 0.0F), colour);
  597. }
  598. x = MapObject.User.CurrentLocation.X * ScaleX;
  599. y = MapObject.User.CurrentLocation.Y * ScaleY;
  600. var s = UserRadarDot.Size;
  601. UserRadarDot.Location = new Point((int)x - s.Width / 2, (int)y - s.Height / 2);
  602. if (GroupDialog.GroupList.Count > 0)
  603. {
  604. for (int i = 0; i < GameScene.Scene.GroupDialog.GroupMembers.Length; i++)
  605. {
  606. string groupMembersName = GameScene.Scene.GroupDialog.GroupMembers[i].Text;
  607. Players[i].Visible = false;
  608. foreach (var groupMembersMap in GroupDialog.GroupMembersMap.Where(x => x.Key == groupMembersName && x.Value == map.Title))
  609. {
  610. foreach (var groupMemberLocation in PlayerLocations.Where(x => x.Key == groupMembersMap.Key))
  611. {
  612. float alteredX = ((groupMemberLocation.Value.X - startPointX) * ScaleX);
  613. float alteredY = ((groupMemberLocation.Value.Y - startPointY) * ScaleY);
  614. if (groupMembersName != MapObject.User.Name)
  615. Players[i].Visible = true;
  616. Players[i].Hint = groupMemberLocation.Key;
  617. Players[i].Location = new Point((int)(alteredX - 0.5F) - 3, (int)(alteredY - 0.5F) - 3);
  618. }
  619. }
  620. }
  621. }
  622. else
  623. {
  624. for (int i = 0; i < Players.Length; i++)
  625. {
  626. Players[i].Visible = false;
  627. }
  628. }
  629. }
  630. else
  631. {
  632. for (int i = 0; i < Players.Length; i++)
  633. {
  634. Players[i].Visible = false;
  635. }
  636. }
  637. foreach (var record in ParentDialog.CurrentRecord.MovementButtons)
  638. {
  639. var movementInfo = record.Key;
  640. var button = record.Value;
  641. float x = movementInfo.Location.X * ScaleX;
  642. float y = movementInfo.Location.Y * ScaleY;
  643. var s = Libraries.MapLinkIcon.GetSize(button.Index);
  644. button.Location = new Point((int)x - s.Width / 2, (int)y - s.Height / 2);
  645. }
  646. if (ParentDialog.SelectedNPC != null && SelectedNPCIcon.Visible)
  647. {
  648. float x = ParentDialog.SelectedNPC.Info.Location.X * ScaleX;
  649. float y = ParentDialog.SelectedNPC.Info.Location.Y * ScaleY;
  650. var s = Libraries.MapLinkIcon.GetSize(SelectedNPCIcon.Index);
  651. SelectedNPCIcon.Location = new Point((int)x - s.Width / 2, (int)y - s.Height / 2);
  652. }
  653. }
  654. }
  655. public class BigMapNPCRow : MirButton
  656. {
  657. BigMapDialog ParentDialog;
  658. public ClientNPCInfo Info;
  659. public MirImageControl Icon;
  660. public MirLabel NameLabel;
  661. public BigMapNPCRow(ClientNPCInfo info)
  662. {
  663. Info = info;
  664. NotControl = false;
  665. Size = new Size(140, 25);
  666. Visible = false;
  667. Sound = SoundList.ButtonA;
  668. string name = Info.Name;
  669. if (Info.Name.Contains("_"))
  670. {
  671. string[] splitName = name.Split('_');
  672. name=string.Empty;
  673. for (int s = 0; s < splitName.Count(); s++)
  674. {
  675. if (splitName[s] == string.Empty) continue;
  676. if (s == splitName.Count() - 1)
  677. name += splitName[s];
  678. else name += $"({splitName[s]})";
  679. }
  680. }
  681. Icon = new MirImageControl
  682. {
  683. Index = info.Icon,
  684. Library = Libraries.MapLinkIcon,
  685. Location = new Point(1, 1),
  686. NotControl = true,
  687. Parent = this,
  688. Sound = SoundList.ButtonA
  689. };
  690. NameLabel = new MirLabel
  691. {
  692. AutoSize = true,
  693. ForeColour = Color.White,
  694. Location = new Point(23, 2),
  695. Parent = this,
  696. NotControl = true,
  697. Text = name,
  698. Sound = SoundList.ButtonA
  699. };
  700. MouseWheel += (o, e) => ParentDialog.BigMap_MouseWheel(o, e);
  701. ParentChanged += (o, e) => SetParent();
  702. Click += (o, e) => Select();
  703. }
  704. private void SetParent()
  705. {
  706. ParentDialog = (BigMapDialog)Parent;
  707. }
  708. private void Select()
  709. {
  710. ParentDialog.SelectedNPC = ParentDialog.SelectedNPC == this ? null : this;
  711. }
  712. }
  713. public class BigMapRecord
  714. {
  715. public int Index;
  716. public ClientMapInfo MapInfo;
  717. public Dictionary<ClientMovementInfo, MirButton> MovementButtons = new Dictionary<ClientMovementInfo, MirButton>();
  718. public List<BigMapNPCRow> NPCButtons = new List<BigMapNPCRow>();
  719. public BigMapRecord() { }
  720. }
  721. }