@@ -622,6 +622,7 @@ private void InternelDrawCreatureStatus(CommandBuffer commandBuffer) {
622622
623623 var rectDrawData = new List < ClassicStatusRectData > ( Constants . MaxCreatureCount * 4 ) ;
624624 var flagDrawData = new List < ClassicStatusFlagData > ( Constants . MaxCreatureCount * 4 ) ;
625+ var speechDrawData = new List < ClassicStatusFlagData > ( Constants . MaxCreatureCount * 4 ) ;
625626
626627 var descriptor = new ClassicStatusDescriptor ( ) {
627628 showNames = optionStorage . ShowNameForOtherCreatures ,
@@ -643,7 +644,7 @@ private void InternelDrawCreatureStatus(CommandBuffer commandBuffer) {
643644 int positionY = ( renderAtom . y - Constants . FieldSize ) / Constants . FieldSize ;
644645
645646 descriptor . showHealth = optionStorage . ShowHealthForOtherCreatures && ( ! creature . IsNPC || ! gameManager . GetFeature ( GameFeature . GameHideNpcNames ) ) ;
646- InternelDrawCreatureStatusClassic ( commandBuffer , creature , rectDrawData , flagDrawData ,
647+ InternelDrawCreatureStatusClassic ( commandBuffer , creature , rectDrawData , flagDrawData , speechDrawData ,
647648 renderAtom . x - Constants . FieldSize , renderAtom . y - Constants . FieldSize ,
648649 renderAtom . z >= _minZPlane [ positionY * Constants . MapSizeX + positionX ] , descriptor ) ;
649650 }
@@ -657,7 +658,7 @@ private void InternelDrawCreatureStatus(CommandBuffer commandBuffer) {
657658 descriptor . showMarks = optionStorage . ShowMarksForOwnCharacter ;
658659 descriptor . showIcons = false ;
659660
660- InternelDrawCreatureStatusClassic ( commandBuffer , Player , rectDrawData , flagDrawData ,
661+ InternelDrawCreatureStatusClassic ( commandBuffer , Player , rectDrawData , flagDrawData , speechDrawData ,
661662 renderAtom . x - Constants . FieldSize , renderAtom . y - Constants . FieldSize , true , descriptor ) ;
662663 }
663664
@@ -667,17 +668,16 @@ private void InternelDrawCreatureStatus(CommandBuffer commandBuffer) {
667668 var matrixArray = new Matrix4x4 [ rectDrawData . Count ] ;
668669 var exArray = new Vector4 [ rectDrawData . Count ] ;
669670
670- int i = 0 ;
671- foreach ( var data in rectDrawData ) {
671+ for ( int i = 0 ; i < rectDrawData . Count ; i ++ ) {
672+ var data = rectDrawData [ i ] ;
672673 matrixArray [ i ] = data . matrix ;
673674 exArray [ i ] = data . color ;
674- i ++ ;
675675 }
676676
677677 var matriciesToPass = new Matrix4x4 [ 1023 ] ;
678678 var exToPass = new Vector4 [ 1023 ] ;
679679
680- for ( i = 0 ; i < matrixArray . Length ; i += 1023 ) {
680+ for ( int i = 0 ; i < matrixArray . Length ; i += 1023 ) {
681681 int sliceSize = Mathf . Min ( 1023 , matrixArray . Length - i ) ;
682682 Array . Copy ( matrixArray , i , matriciesToPass , 0 , sliceSize ) ;
683683 Array . Copy ( exArray , i , exToPass , 0 , sliceSize ) ;
@@ -686,24 +686,31 @@ private void InternelDrawCreatureStatus(CommandBuffer commandBuffer) {
686686 Utils . GraphicsUtility . DrawTextureInstanced ( commandBuffer , matriciesToPass , sliceSize , coloredMaterial , props ) ;
687687 }
688688
689- matrixArray = new Matrix4x4 [ flagDrawData . Count ] ;
690- exArray = new Vector4 [ flagDrawData . Count ] ;
689+ var drawDataArray = new List < ClassicStatusFlagData > [ ] { flagDrawData , speechDrawData } ;
690+ var textureArray = new Texture2D [ ] { OpenTibiaUnity . GameManager . StateFlagsTexture , OpenTibiaUnity . GameManager . SpeechFlagsTexture } ;
691691
692- i = 0 ;
693- foreach ( var data in flagDrawData ) {
694- matrixArray [ i ] = data . matrix ;
695- exArray [ i ] = data . uv ;
696- i ++ ;
697- }
692+ for ( int i = 0 ; i < drawDataArray . Length ; i ++ ) {
693+ var drawData = drawDataArray [ i ] ;
694+ var texture = textureArray [ i ] ;
698695
699- for ( i = 0 ; i < matrixArray . Length ; i += 1023 ) {
700- int sliceSize = Mathf . Min ( 1023 , matrixArray . Length - i ) ;
701- Array . Copy ( matrixArray , i , matriciesToPass , 0 , sliceSize ) ;
702- Array . Copy ( exArray , i , exToPass , 0 , sliceSize ) ;
703- MaterialPropertyBlock props = new MaterialPropertyBlock ( ) ;
704- props . SetTexture ( "_MainTex" , OpenTibiaUnity . GameManager . StateFlagsTexture ) ;
705- props . SetVectorArray ( "_MainTex_UV" , exToPass ) ;
706- Utils . GraphicsUtility . DrawTextureInstanced ( commandBuffer , matriciesToPass , sliceSize , appearanceMaterial , props ) ;
696+ matrixArray = new Matrix4x4 [ drawData . Count ] ;
697+ exArray = new Vector4 [ drawData . Count ] ;
698+
699+ for ( int j = 0 ; j < drawData . Count ; j ++ ) {
700+ var data = drawData [ j ] ;
701+ matrixArray [ j ] = data . matrix ;
702+ exArray [ j ] = data . uv ;
703+ }
704+
705+ for ( int j = 0 ; j < matrixArray . Length ; j += 1023 ) {
706+ int sliceSize = Mathf . Min ( 1023 , matrixArray . Length - j ) ;
707+ Array . Copy ( matrixArray , j , matriciesToPass , 0 , sliceSize ) ;
708+ Array . Copy ( exArray , j , exToPass , 0 , sliceSize ) ;
709+ MaterialPropertyBlock props = new MaterialPropertyBlock ( ) ;
710+ props . SetTexture ( "_MainTex" , texture ) ;
711+ props . SetVectorArray ( "_MainTex_UV" , exToPass ) ;
712+ Utils . GraphicsUtility . DrawTextureInstanced ( commandBuffer , matriciesToPass , sliceSize , appearanceMaterial , props ) ;
713+ }
707714 }
708715 } else {
709716 foreach ( var data in rectDrawData ) {
@@ -712,9 +719,18 @@ private void InternelDrawCreatureStatus(CommandBuffer commandBuffer) {
712719 Utils . GraphicsUtility . DrawTexture ( commandBuffer , data . matrix , coloredMaterial , props ) ;
713720 }
714721
722+ var statesTexture = OpenTibiaUnity . GameManager . StateFlagsTexture ;
715723 foreach ( var data in flagDrawData ) {
716724 MaterialPropertyBlock props = new MaterialPropertyBlock ( ) ;
717- props . SetTexture ( "_MainTex" , OpenTibiaUnity . GameManager . StateFlagsTexture ) ;
725+ props . SetTexture ( "_MainTex" , statesTexture ) ;
726+ props . SetVector ( "_MainTex_UV" , data . uv ) ;
727+ Utils . GraphicsUtility . DrawTexture ( commandBuffer , data . matrix , appearanceMaterial , props ) ;
728+ }
729+
730+ var speechTexture = OpenTibiaUnity . GameManager . SpeechFlagsTexture ;
731+ foreach ( var data in speechDrawData ) {
732+ MaterialPropertyBlock props = new MaterialPropertyBlock ( ) ;
733+ props . SetTexture ( "_MainTex" , speechTexture ) ;
718734 props . SetVector ( "_MainTex_UV" , data . uv ) ;
719735 Utils . GraphicsUtility . DrawTexture ( commandBuffer , data . matrix , appearanceMaterial , props ) ;
720736 }
@@ -810,7 +826,8 @@ private void InternalDrawOnscreenMessages(CommandBuffer commandBuffer) {
810826 }
811827
812828 private void InternelDrawCreatureStatusClassic ( CommandBuffer commandBuffer , Creatures . Creature creature ,
813- List < ClassicStatusRectData > rectData , List < ClassicStatusFlagData > flagData ,
829+ List < ClassicStatusRectData > rectData ,
830+ List < ClassicStatusFlagData > flagData , List < ClassicStatusFlagData > speechData ,
814831 int rectX , int rectY , bool visible , ClassicStatusDescriptor descriptor ) {
815832 bool isLocalPlayer = creature . Id == Player . Id ;
816833 Color healthColor , manaColor ;
@@ -899,11 +916,11 @@ private void InternelDrawCreatureStatusClassic(CommandBuffer commandBuffer, Crea
899916 }
900917
901918 if ( descriptor . showMarks && ! creature . IsNPC || descriptor . showIcons && creature . IsNPC )
902- InternalDrawCreatureFlags ( creature , flagData , ( int ) initialScreenPosition . x , ( int ) initialScreenPosition . y , visible ) ;
919+ InternalDrawCreatureFlags ( creature , flagData , speechData , ( int ) initialScreenPosition . x , ( int ) initialScreenPosition . y , visible ) ;
903920 }
904921
905- private void InternalDrawCreatureFlags ( Creatures . Creature creature ,
906- List < ClassicStatusFlagData > flagData , float rectX , float rectY , bool visible ) {
922+ private void InternalDrawCreatureFlags ( Creatures . Creature creature , List < ClassicStatusFlagData > flagData ,
923+ List < ClassicStatusFlagData > speechData , float rectX , float rectY , bool visible ) {
907924 if ( ! creature . HasFlag )
908925 return ;
909926
@@ -924,8 +941,11 @@ private void InternalDrawCreatureFlags(Creatures.Creature creature,
924941 }
925942
926943 if ( creature . PKFlag > PKFlag . None ) {
927- var textureRect = NormalizeFlagRect ( GetPKFlagTextureRect ( creature . PKFlag ) , flagsTexture ) ;
928- Graphics . DrawTexture ( new Rect ( screenPosition , flagSize ) , flagsTexture , textureRect , 0 , 0 , 0 , 0 ) ;
944+ var r = NormalizeFlagRect ( GetPKFlagTextureRect ( creature . PKFlag ) , flagsTexture ) ;
945+ flagData . Add ( new ClassicStatusFlagData {
946+ matrix = Matrix4x4 . TRS ( screenPosition , Quaternion . Euler ( 180 , 0 , 0 ) , flagSize ) ,
947+ uv = new Vector4 ( r . width , r . height , r . x , r . y )
948+ } ) ;
929949
930950 screenPosition . x += Constants . StateFlagGap + Constants . StateFlagSize ;
931951 }
@@ -946,11 +966,12 @@ private void InternalDrawCreatureFlags(Creatures.Creature creature,
946966 speechCategory = OpenTibiaUnity . TicksMillis % 2048 <= 1024 ? SpeechCategory . Quest : SpeechCategory . Trader ;
947967
948968 if ( speechCategory > SpeechCategory . None ) {
949- // speech category is disabled internally
950- //var speechTexture = OpenTibiaUnity.GameManager.SpeechFlagsTexture;
951- //var textureRect = NormalizeFlagRect(GetSpeechFlagTextureRect(speechCategory), speechTexture);
952- //var screenRect = new Rect(screenPosition, new Vector2(Constants.SpeechFlagSize, Constants.SpeechFlagSize));
953- //Graphics.DrawTexture(screenRect, speechTexture, textureRect, 0, 0, 0, 0);
969+ var speechTexture = OpenTibiaUnity . GameManager . SpeechFlagsTexture ;
970+ var r = NormalizeFlagRect ( GetSpeechFlagTextureRect ( speechCategory ) , speechTexture ) ;
971+ speechData . Add ( new ClassicStatusFlagData {
972+ matrix = Matrix4x4 . TRS ( screenPosition , Quaternion . Euler ( 180 , 0 , 0 ) , new Vector2 ( Constants . SpeechFlagSize , Constants . SpeechFlagSize ) ) ,
973+ uv = new Vector4 ( r . width , r . height , r . x , r . y )
974+ } ) ;
954975
955976 dX += Constants . StateFlagGap + Constants . SpeechFlagSize ;
956977 screenPosition . x += Constants . StateFlagGap + Constants . SpeechFlagSize ;
0 commit comments