@@ -906,20 +906,28 @@ public void DrawItemsAndLights()
906906 var mapItemHeight = Options . Instance . Map . MapItemHeight ;
907907
908908 // Draw map items.
909- foreach ( var ( key , tileItems ) in MapItems )
909+ foreach ( var ( tileIndex , itemInstancesOnTile ) in MapItems )
910910 {
911911 // Calculate tile coordinates.
912- var tileX = key % _width ;
913- var tileY = ( int ) Math . Floor ( key / ( float ) _width ) ;
912+ var tileX = tileIndex % _width ;
913+ var tileY = ( int ) Math . Floor ( tileIndex / ( float ) _width ) ;
914914
915915 // Loop through this in reverse to match client/server display and pick-up order.
916- for ( var index = tileItems . Count - 1 ; index >= 0 ; index -- )
916+ for ( var index = itemInstancesOnTile . Count - 1 ; index >= 0 ; index -- )
917917 {
918+ var mapItemInstance = itemInstancesOnTile [ index ] ;
919+ if ( ItemDescriptor . TryGet ( mapItemInstance . ItemId , out var itemDescriptor ) )
920+ {
921+ continue ;
922+ }
923+
918924 // Set up all information we need to draw this name.
919- var itemBase = ItemDescriptor . Get ( tileItems [ index ] . ItemId ) ;
920- var itemTex = Globals . ContentManager . GetTexture ( Framework . Content . TextureType . Item , itemBase . Icon ) ;
925+ var itemTexture = GameContentManager . Current . GetTexture (
926+ Framework . Content . TextureType . Item ,
927+ itemDescriptor . Icon
928+ ) ;
921929
922- if ( itemTex == null )
930+ if ( itemTexture == null )
923931 {
924932 continue ;
925933 }
@@ -933,10 +941,10 @@ public void DrawItemsAndLights()
933941
934942 // Draw the item texture.
935943 Graphics . DrawGameTexture (
936- itemTex ,
937- new FloatRect ( 0 , 0 , itemTex . Width , itemTex . Height ) ,
944+ itemTexture ,
945+ new FloatRect ( 0 , 0 , itemTexture . Width , itemTexture . Height ) ,
938946 new FloatRect ( textureXPosition , textureYPosition , mapItemWidth , mapItemHeight ) ,
939- itemBase . Color
947+ itemDescriptor . Color
940948 ) ;
941949 }
942950 }
@@ -961,77 +969,90 @@ public void DrawItemNames()
961969 return ;
962970 }
963971
972+ if ( Globals . Me is not { } player )
973+ {
974+ return ;
975+ }
976+
964977 // Get where our mouse is located and convert it to a tile based location.
965978 var mousePos = Graphics . ConvertToWorldPoint ( Globals . InputManager . GetMousePosition ( ) ) ;
966- var x = ( int ) ( mousePos . X - ( int ) X ) / _tileWidth ;
967- var y = ( int ) ( mousePos . Y - ( int ) Y ) / _tileHeight ;
979+ var x = ( int ) ( mousePos . X - X ) / _tileWidth ;
980+ var y = ( int ) ( mousePos . Y - Y ) / _tileHeight ;
968981 var mapId = Id ;
969982
970983 // Is this an actual location on this map?
971- if ( Globals . Me . TryGetRealLocation ( ref x , ref y , ref mapId ) && mapId = = Id )
984+ if ( ! player . TryGetRealLocation ( ref x , ref y , ref mapId ) || mapId ! = Id )
972985 {
973- // Apparently it is! Do we have any items to render here?
974- var tileItems = new List < IMapItemInstance > ( ) ;
975- if ( MapItems . TryGetValue ( y * _width + x , out tileItems ) )
976- {
977- var baseOffset = 0 ;
978- // Loop through this in reverse to match client/server display and pick-up order.
979- for ( var index = tileItems . Count - 1 ; index >= 0 ; index -- )
980- {
981- // Set up all information we need to draw this name.
982- var itemBase = ItemDescriptor . Get ( tileItems [ index ] . ItemId ) ;
983- var name = tileItems [ index ] . Descriptor . Name ;
984- var quantity = tileItems [ index ] . Quantity ;
985- var rarity = itemBase . Rarity ;
986- if ( tileItems [ index ] . Quantity > 1 )
987- {
988- name = Strings . General . MapItemStackable . ToString (
989- name ,
990- Strings . FormatQuantityAbbreviated ( quantity )
991- ) ;
992- }
986+ return ;
987+ }
993988
994- var color = CustomColors . Items . MapRarities . ContainsKey ( rarity )
995- ? CustomColors . Items . MapRarities [ rarity ]
996- : new LabelColor ( Color . White , Color . Black , new Color ( 100 , 0 , 0 , 0 ) ) ;
997- var textSize = Graphics . Renderer . MeasureText (
998- name ,
999- Graphics . EntityNameFont ,
1000- Graphics . EntityNameFontSize ,
1001- 1
1002- ) ;
1003- var offsetY = ( baseOffset * textSize . Y ) ;
1004- var destX = X + ( int ) Math . Ceiling ( ( ( x * _tileWidth ) + ( _tileHalfWidth ) ) - ( textSize . X / 2 ) ) ;
1005- var destY = Y + ( int ) Math . Ceiling ( ( ( y * _tileHeight ) - ( ( _tileHeight / 3 ) + textSize . Y ) ) ) - offsetY ;
989+ // Apparently it is! Do we have any items to render here?
990+ if ( ! MapItems . TryGetValue ( y * _width + x , out var tileItems ) )
991+ {
992+ return ;
993+ }
1006994
1007- // Do we need to draw a background?
1008- if ( color . Background != Color . Transparent )
1009- {
1010- Graphics . DrawGameTexture (
1011- Graphics . Renderer . WhitePixel ,
1012- new FloatRect ( 0 , 0 , 1 , 1 ) ,
1013- new FloatRect ( destX - 4 , destY , textSize . X + 8 , textSize . Y ) ,
1014- color . Background
1015- ) ;
1016- }
995+ var baseOffset = 0 ;
996+ // Loop through this in reverse to match client/server display and pick-up order.
997+ for ( var index = tileItems . Count - 1 ; index >= 0 ; index -- )
998+ {
999+ var mapItemInstance = tileItems [ index ] ;
1000+ if ( ! ItemDescriptor . TryGet ( mapItemInstance . ItemId , out var itemDescriptor ) ) {
1001+ continue ;
1002+ }
10171003
1018- // Finaly, draw the actual name!
1019- Graphics . Renderer . DrawString (
1020- name ,
1021- Graphics . EntityNameFont ,
1022- Graphics . EntityNameFontSize ,
1023- destX ,
1024- destY ,
1025- 1 ,
1026- color . Name ,
1027- true ,
1028- null ,
1029- color . Outline
1030- ) ;
1004+ // Set up all information we need to draw this name.
1005+ var name = mapItemInstance . Descriptor . Name ;
1006+ var quantity = mapItemInstance . Quantity ;
1007+ var rarity = itemDescriptor . Rarity ;
1008+ if ( mapItemInstance . Quantity > 1 )
1009+ {
1010+ name = Strings . General . MapItemStackable . ToString (
1011+ name ,
1012+ Strings . FormatQuantityAbbreviated ( quantity )
1013+ ) ;
1014+ }
10311015
1032- baseOffset ++ ;
1033- }
1016+ var color = CustomColors . Items . MapRarities . GetValueOrDefault (
1017+ rarity ,
1018+ new LabelColor ( Color . White , Color . Black , new Color ( 100 , 0 , 0 , 0 ) )
1019+ ) ;
1020+ var textSize = Graphics . Renderer . MeasureText (
1021+ name ,
1022+ Graphics . EntityNameFont ,
1023+ Graphics . EntityNameFontSize ,
1024+ 1
1025+ ) ;
1026+ var offsetY = ( baseOffset * textSize . Y ) ;
1027+ var destX = X + ( int ) Math . Ceiling ( ( ( x * _tileWidth ) + ( _tileHalfWidth ) ) - ( textSize . X / 2 ) ) ;
1028+ var destY = Y + ( int ) Math . Ceiling ( ( ( y * _tileHeight ) - ( ( _tileHeight / 3f ) + textSize . Y ) ) ) - offsetY ;
1029+
1030+ // Do we need to draw a background?
1031+ if ( color . Background != Color . Transparent )
1032+ {
1033+ Graphics . DrawGameTexture (
1034+ Graphics . Renderer . WhitePixel ,
1035+ new FloatRect ( 0 , 0 , 1 , 1 ) ,
1036+ new FloatRect ( destX - 4 , destY , textSize . X + 8 , textSize . Y ) ,
1037+ color . Background
1038+ ) ;
10341039 }
1040+
1041+ // Finaly, draw the actual name!
1042+ Graphics . Renderer . DrawString (
1043+ name ,
1044+ Graphics . EntityNameFont ,
1045+ Graphics . EntityNameFontSize ,
1046+ destX ,
1047+ destY ,
1048+ 1 ,
1049+ color . Name ,
1050+ true ,
1051+ null ,
1052+ color . Outline
1053+ ) ;
1054+
1055+ baseOffset ++ ;
10351056 }
10361057 }
10371058
0 commit comments