Adjustor mod plugin for VS
Revision | b07f611646d72b52d8c2ab2c03f3b0df55f4c3f6 (tree) |
---|---|
Zeit | 2019-06-01 07:39:50 |
Autor | melchior <melchior@user...> |
Commiter | melchior |
Fixed up Rotations from Variants
Tool mode text entries added
@@ -4,7 +4,7 @@ using System.Collections; | ||
4 | 4 | using System.Collections.Generic; |
5 | 5 | using System.Collections.ObjectModel; |
6 | 6 | using System.Linq; |
7 | -//using System.Text.RegularExpressions; | |
7 | +using System.Text.RegularExpressions; | |
8 | 8 | |
9 | 9 | using Vintagestory.API.Common; |
10 | 10 | using Vintagestory.API.Datastructures; |
@@ -60,6 +60,19 @@ namespace Adjustor | ||
60 | 60 | @"GenericTypedContainer", |
61 | 61 | }; |
62 | 62 | |
63 | + private static string[] _verticalVariantKeys = new string[] | |
64 | + { | |
65 | + "verticalorientation", | |
66 | + "rot", | |
67 | + }; | |
68 | + | |
69 | + private static string[] _horizontalVariantKeys = new string[] | |
70 | + { | |
71 | + "horizontalorientation", | |
72 | + "rot", | |
73 | + "side" | |
74 | + }; | |
75 | + | |
63 | 76 | public ItemAdjustor( ) : base( ) |
64 | 77 | { |
65 | 78 |
@@ -96,15 +109,7 @@ namespace Adjustor | ||
96 | 109 | /// <param name="entitySel">Entity sel.</param> |
97 | 110 | /// <param name="handHandling">Hand handling.</param> |
98 | 111 | public override void OnHeldInteractStart(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling) |
99 | - { | |
100 | - /* | |
101 | - if ( entitySel != null ) { | |
102 | - #if DEBUG | |
103 | - ClientApi.ShowChatMessage( string.Format("Got an Entity Selection: {0} - {1}", entitySel.Entity.Code.ToShortString(), entitySel.Face.Code ) ); | |
104 | - #endif | |
105 | - } | |
106 | - */ | |
107 | - | |
112 | + { | |
108 | 113 | if (blockSel == null) { |
109 | 114 | return; |
110 | 115 | } |
@@ -153,7 +158,7 @@ namespace Adjustor | ||
153 | 158 | BlockPos position = blockSel.Position; |
154 | 159 | Block thatBlock = byEntity.World.BlockAccessor.GetBlock(position); |
155 | 160 | IPlayer thePlayer = null; |
156 | - bool rotateHorizontal = false; | |
161 | + | |
157 | 162 | |
158 | 163 | if (byEntity is EntityPlayer) { |
159 | 164 | thePlayer = ServerApi.World.PlayerByUid((( EntityPlayer )byEntity).PlayerUID); |
@@ -170,88 +175,12 @@ namespace Adjustor | ||
170 | 175 | return false; |
171 | 176 | } |
172 | 177 | |
173 | - AssetLocation renamedAsset = null; | |
174 | - | |
175 | - switch (blockSel.Face.Axis) { | |
176 | - case EnumAxis.X: | |
177 | - case EnumAxis.Z: | |
178 | - rotateHorizontal = !byEntity.Controls.Sneak; | |
179 | - break; | |
180 | - | |
181 | - case EnumAxis.Y: | |
182 | - rotateHorizontal = byEntity.Controls.Sneak; | |
183 | - break; | |
184 | - } | |
185 | - | |
186 | - if (rotateHorizontal) { | |
187 | -#if DEBUG | |
188 | - ServerApi.SendMessage(thePlayer, GlobalConstants.CurrentChatGroup, "Angle N/E/W/S.", EnumChatType.Notification); | |
189 | -#endif | |
190 | - | |
191 | - //So many HORIZONTAL Special Cases... | |
192 | - renamedAsset = thatBlock.GetRotatedBlockCode(90);//Except Fences | |
193 | - | |
194 | - if (IsSlabUD(thatBlock)) renamedAsset = SpecialSlabHorizontalFlipCase(thatBlock); | |
195 | - | |
196 | - if (IsWoodLog(thatBlock)) renamedAsset = WoodOmniFlip(thatBlock, blockSel.Face.Axis, rotateHorizontal); //Wood logs also special | |
197 | - | |
198 | - | |
199 | - if (renamedAsset != thatBlock.Code) { | |
200 | -#if DEBUG | |
201 | - Logger.VerboseDebug("{0} Becomes {1}", thatBlock.Code, renamedAsset); | |
202 | -#endif | |
203 | - | |
204 | - var rotatedBlock = ServerApi.World.GetBlock(renamedAsset); | |
205 | - if (rotatedBlock != null) { | |
206 | - ServerApi.World.BlockAccessor.ExchangeBlock(rotatedBlock.BlockId, position); | |
207 | - } else { | |
208 | - Logger.VerboseDebug("{0} CAN'T EXCHANGE {1}", thatBlock.Code, renamedAsset); | |
209 | - } | |
210 | - } | |
178 | + if (this.CurrentRotationMode(slot) == RotationModes.Free) { | |
179 | + FreeRotation(blockSel, byEntity, thePlayer, thatBlock, position); | |
211 | 180 | } else { |
212 | -#if DEBUG | |
213 | - ServerApi.SendMessage(thePlayer, GlobalConstants.CurrentChatGroup, "Angle U/D.", EnumChatType.Notification); | |
214 | -#endif | |
215 | - | |
216 | - renamedAsset = thatBlock.GetVerticallyFlippedBlockCode( ); | |
217 | - | |
218 | - //Special Case for Slabs in N/E/S/W mode when trying to rotate them back 'up' | |
219 | - if (IsSlabNEWS(thatBlock)) renamedAsset = SpecialSlabVerticalFlipCase(thatBlock); | |
220 | - | |
221 | - if (IsWoodLog(thatBlock)) renamedAsset = WoodOmniFlip(thatBlock, blockSel.Face.Axis, rotateHorizontal); //Wood logs also special | |
222 | - | |
223 | - if (renamedAsset != thatBlock.Code) { | |
224 | - | |
225 | -#if DEBUG | |
226 | - Logger.VerboseDebug("{0} Becomes {1}", thatBlock.Code, renamedAsset); | |
227 | -#endif | |
228 | - | |
229 | - var rotatedBlock = ServerApi.World.GetBlock(renamedAsset); | |
230 | - if (rotatedBlock != null) { | |
231 | - ServerApi.World.BlockAccessor.ExchangeBlock(rotatedBlock.BlockId, position); | |
232 | - } else { | |
233 | - Logger.VerboseDebug("{0} CAN'T EXCHANGE {1}", thatBlock.Code, renamedAsset); | |
234 | - } | |
235 | - } | |
181 | + FixedRotation(this.CurrentRotationMode(slot),blockSel, byEntity, thePlayer, thatBlock, position); | |
236 | 182 | } |
237 | 183 | |
238 | - //System.Diagnostics.Debugger.Break( ); | |
239 | -#if SPAM | |
240 | - string firstName = thatBlock.Code.Path.Split( "-".ToCharArray( ) ).First( ); | |
241 | - | |
242 | - var variants = ServerApi.WorldManager.SearchBlockTypes(firstName, thatBlock.Code.Domain ); | |
243 | - | |
244 | - if ( variants != null && variants.Length > 0 ) { | |
245 | - | |
246 | - ServerApi.SendMessage(thePlayer, GlobalConstants.CurrentChatGroup, string.Format( "Block has {0} variants;", variants.Length ), EnumChatType.Notification ); | |
247 | - | |
248 | - foreach(var variant in variants) { | |
249 | - ServerApi.SendMessage(thePlayer, GlobalConstants.CurrentChatGroup,variant.Code.ToShortString(), EnumChatType.Notification ); | |
250 | - Logger.VerboseDebug("{0} has Variant: {1}", firstName, variant.Code ); | |
251 | - } | |
252 | - } | |
253 | -#endif | |
254 | - //secondsUsed += 0.5; | |
255 | 184 | |
256 | 185 | DamageItem(ServerApi.World, byEntity, slot); |
257 | 186 |
@@ -304,31 +233,31 @@ namespace Adjustor | ||
304 | 233 | |
305 | 234 | switch (rotateMode) { |
306 | 235 | case RotationModes.Free: |
307 | - DrawTextGlyph(cr, x, y, width, height, color, "FREE"); | |
236 | + DrawTextGlyph(cr, x, y, width, height, color, Lang.GetMatching("adjustor:rotation-free").ToUpperInvariant( )); | |
308 | 237 | break; |
309 | 238 | |
310 | 239 | case RotationModes.Up: |
311 | - DrawTextGlyph(cr, x, y, width, height, color, "UP"); | |
240 | + DrawTextGlyph(cr, x, y, width, height, color, Lang.GetMatching("adjustor:rotation-up").ToUpperInvariant( )); | |
312 | 241 | break; |
313 | 242 | |
314 | 243 | case RotationModes.Down: |
315 | - DrawTextGlyph(cr, x, y, width, height, color, "DOWN"); | |
244 | + DrawTextGlyph(cr, x, y, width, height, color, Lang.GetMatching("adjustor:rotation-down").ToUpperInvariant( )); | |
316 | 245 | break; |
317 | 246 | |
318 | 247 | case RotationModes.North: |
319 | - DrawTextGlyph(cr, x, y, width, height, color, "NORTH"); | |
248 | + DrawTextGlyph(cr, x, y, width, height, color, Lang.GetMatching("facing-north" ).ToUpperInvariant() ); | |
320 | 249 | break; |
321 | 250 | |
322 | 251 | case RotationModes.East: |
323 | - DrawTextGlyph(cr, x, y, width, height, color, "EAST"); | |
252 | + DrawTextGlyph(cr, x, y, width, height, color, Lang.GetMatching("facing-east").ToUpperInvariant( ) ); | |
324 | 253 | break; |
325 | 254 | |
326 | 255 | case RotationModes.West: |
327 | - DrawTextGlyph(cr, x, y, width, height, color, "WEST"); | |
256 | + DrawTextGlyph(cr, x, y, width, height, color,Lang.GetMatching("facing-west").ToUpperInvariant( ) ); | |
328 | 257 | break; |
329 | 258 | |
330 | 259 | case RotationModes.South: |
331 | - DrawTextGlyph(cr, x, y, width, height, color, "SOUTH"); | |
260 | + DrawTextGlyph(cr, x, y, width, height, color, Lang.GetMatching("facing-south").ToUpperInvariant( ) ); | |
332 | 261 | break; |
333 | 262 | |
334 | 263 | default: |
@@ -558,6 +487,174 @@ namespace Adjustor | ||
558 | 487 | return thatBlock.Code.FirstPathPart(0).StartsWith(@"log", StringComparison.Ordinal); |
559 | 488 | } |
560 | 489 | |
490 | + | |
491 | + | |
492 | + | |
493 | + /// <summary> | |
494 | + /// Rotation by any 'free' axis available to block | |
495 | + /// </summary> | |
496 | + /// <param name="blockSel">Block sel.</param> | |
497 | + /// <param name="byEntity">By entity.</param> | |
498 | + /// <param name="thePlayer">The player.</param> | |
499 | + private void FreeRotation(BlockSelection blockSel, EntityAgent byEntity, IPlayer thePlayer, Block thatBlock, BlockPos position) | |
500 | + { | |
501 | + bool rotateHorizontal = false; | |
502 | + AssetLocation renamedAsset = null; | |
503 | + | |
504 | + switch (blockSel.Face.Axis) { | |
505 | + case EnumAxis.X: | |
506 | + case EnumAxis.Z: | |
507 | + rotateHorizontal = !byEntity.Controls.Sneak; | |
508 | + break; | |
509 | + | |
510 | + case EnumAxis.Y: | |
511 | + rotateHorizontal = byEntity.Controls.Sneak; | |
512 | + break; | |
513 | + } | |
514 | + | |
515 | + if (rotateHorizontal) { | |
516 | +#if DEBUG | |
517 | + ServerApi.SendMessage(thePlayer, GlobalConstants.CurrentChatGroup, "Angle N/E/W/S.", EnumChatType.Notification); | |
518 | +#endif | |
519 | + | |
520 | + //So many HORIZONTAL Special Cases... | |
521 | + renamedAsset = thatBlock.GetRotatedBlockCode(90);//Except Fences | |
522 | + | |
523 | + if (IsSlabUD(thatBlock)) renamedAsset = SpecialSlabHorizontalFlipCase(thatBlock); | |
524 | + | |
525 | + if (IsWoodLog(thatBlock)) renamedAsset = WoodOmniFlip(thatBlock, blockSel.Face.Axis, rotateHorizontal); //Wood logs also special | |
526 | + | |
527 | + | |
528 | + if (renamedAsset != thatBlock.Code) { | |
529 | +#if DEBUG | |
530 | + Logger.VerboseDebug("{0} Becomes {1}", thatBlock.Code, renamedAsset); | |
531 | +#endif | |
532 | + | |
533 | + var rotatedBlock = ServerApi.World.GetBlock(renamedAsset); | |
534 | + if (rotatedBlock != null) { | |
535 | + ServerApi.World.BlockAccessor.ExchangeBlock(rotatedBlock.BlockId, position); | |
536 | + } else { | |
537 | + Logger.VerboseDebug("{0} CAN'T EXCHANGE {1}", thatBlock.Code, renamedAsset); | |
538 | + } | |
539 | + } | |
540 | + } else { | |
541 | +#if DEBUG | |
542 | + ServerApi.SendMessage(thePlayer, GlobalConstants.CurrentChatGroup, "Angle U/D.", EnumChatType.Notification); | |
543 | +#endif | |
544 | + | |
545 | + renamedAsset = thatBlock.GetVerticallyFlippedBlockCode( ); | |
546 | + | |
547 | + //Special Case for Slabs in N/E/S/W mode when trying to rotate them back 'up' | |
548 | + if (IsSlabNEWS(thatBlock)) renamedAsset = SpecialSlabVerticalFlipCase(thatBlock); | |
549 | + | |
550 | + if (IsWoodLog(thatBlock)) renamedAsset = WoodOmniFlip(thatBlock, blockSel.Face.Axis, rotateHorizontal); //Wood logs also special | |
551 | + | |
552 | + if (renamedAsset != thatBlock.Code) { | |
553 | + | |
554 | +#if DEBUG | |
555 | + Logger.VerboseDebug("{0} Becomes {1}", thatBlock.Code, renamedAsset); | |
556 | +#endif | |
557 | + | |
558 | + var rotatedBlock = ServerApi.World.GetBlock(renamedAsset); | |
559 | + if (rotatedBlock != null) { | |
560 | + ServerApi.World.BlockAccessor.ExchangeBlock(rotatedBlock.BlockId, position); | |
561 | + } else { | |
562 | + Logger.VerboseDebug("{0} CAN'T EXCHANGE {1}", thatBlock.Code, renamedAsset); | |
563 | + } | |
564 | + } | |
565 | + } | |
566 | + | |
567 | + | |
568 | + } | |
569 | + | |
570 | + /// <summary> | |
571 | + /// Fixed by type - force to that rotation; 'state' | |
572 | + /// </summary> | |
573 | + /// <param name="rotationModes">Rotation modes.</param> | |
574 | + /// <param name="blockSel">Block sel.</param> | |
575 | + /// <param name="byEntity">By entity.</param> | |
576 | + /// <param name="thePlayer">The player.</param> | |
577 | + /// <param name="thatBlock">That block.</param> | |
578 | + /// <param name="position">Position.</param> | |
579 | + private void FixedRotation(RotationModes rotationMode, BlockSelection blockSel, EntityAgent byEntity, IPlayer thePlayer, Block thatBlock, BlockPos position) | |
580 | + { | |
581 | + AssetLocation renamedAsset = RenameBlockFace(thatBlock, rotationMode); | |
582 | + | |
583 | + if (renamedAsset != null) { | |
584 | + | |
585 | + if (renamedAsset.Equals(thatBlock.Code) == false) { | |
586 | + #if DEBUG | |
587 | + Logger.VerboseDebug("{0} Forcing: {1}", thatBlock.Code, renamedAsset); | |
588 | + #endif | |
589 | + | |
590 | + var rotatedBlock = ServerApi.World.GetBlock(renamedAsset); | |
591 | + if (rotatedBlock != null) { | |
592 | + ServerApi.World.BlockAccessor.ExchangeBlock(rotatedBlock.BlockId, position); | |
593 | + } else { | |
594 | + Logger.VerboseDebug("{0} CAN'T EXCHANGE {1}", thatBlock.Code, renamedAsset); | |
595 | + } | |
596 | + } else { | |
597 | + Logger.VerboseDebug("{0} IDENTICAL!? {1}", thatBlock.Code, renamedAsset); | |
598 | + } | |
599 | + } | |
600 | + } | |
601 | + | |
602 | + private AssetLocation RenameBlockFace(Block thatBlock, RotationModes rotationMode) | |
603 | + { | |
604 | + string renamedLocationPath = null; | |
605 | + string rotationKey = null; | |
606 | + | |
607 | + switch (rotationMode) { | |
608 | + | |
609 | + case RotationModes.Up: | |
610 | + case RotationModes.Down: | |
611 | + | |
612 | + rotationKey = thatBlock.Variant.Keys.FirstOrDefault(_verticalVariantKeys.Contains);//There better be only 1 axies here! | |
613 | + if (!string.IsNullOrEmpty(rotationKey)) | |
614 | + { | |
615 | + string roatableValue = thatBlock.Variant[rotationKey]; | |
616 | + | |
617 | + renamedLocationPath = thatBlock.Code.Path.Replace(roatableValue, rotationMode.ToString().ToLowerInvariant() ); | |
618 | + | |
619 | + #if DEBUG | |
620 | + Logger.VerboseDebug("Variant vertical rotation {0}={1} to: {2}", rotationKey, roatableValue, renamedLocationPath); | |
621 | + #endif | |
622 | + | |
623 | + } | |
624 | + | |
625 | + break; | |
626 | + | |
627 | + case RotationModes.North: | |
628 | + case RotationModes.East: | |
629 | + case RotationModes.West: | |
630 | + case RotationModes.South: | |
631 | + | |
632 | + rotationKey = thatBlock.Variant.Keys.FirstOrDefault(_horizontalVariantKeys.Contains);//There better be only 1 axies here! | |
633 | + if (!string.IsNullOrEmpty(rotationKey)) { | |
634 | + string roatableValue = thatBlock.Variant[rotationKey]; | |
635 | + | |
636 | + renamedLocationPath = thatBlock.Code.Path.Replace(roatableValue, rotationMode.ToString( ).ToLowerInvariant( )); | |
637 | + | |
638 | + #if DEBUG | |
639 | + Logger.VerboseDebug("Variant horizontal rotation {0}={1} to: {2}", rotationKey, roatableValue, renamedLocationPath); | |
640 | + #endif | |
641 | + | |
642 | + } | |
643 | + break; | |
644 | + | |
645 | + default: | |
646 | + throw new InvalidOperationException("Rotation Mode not Permissible!" ); | |
647 | + } | |
648 | + | |
649 | + | |
650 | + if (!string.IsNullOrEmpty(renamedLocationPath)) { | |
651 | + | |
652 | + return new AssetLocation(thatBlock.Code.Domain, renamedLocationPath); | |
653 | + } | |
654 | + | |
655 | + return null; | |
656 | + } | |
657 | + | |
561 | 658 | #endregion |
562 | 659 | |
563 | 660 | #region SVG TOOL ICONS |
@@ -575,27 +672,29 @@ namespace Adjustor | ||
575 | 672 | Matrix matrix = cr.Matrix; |
576 | 673 | |
577 | 674 | cr.Save( ); |
675 | + /* | |
578 | 676 | float local_width = 220; |
579 | 677 | float local_height = 182; |
580 | 678 | float scale = Math.Min(width / local_width, height / local_height); |
581 | 679 | matrix.Translate(x + Math.Max(0, (width - local_width * scale) / 2), y + Math.Max(0, (height - local_height * scale) / 2)); |
582 | 680 | matrix.Scale(scale, scale); |
583 | 681 | cr.Matrix = matrix; |
682 | + */ | |
584 | 683 | |
585 | 684 | cr.Operator = Operator.Over; |
586 | 685 | pattern = new SolidPattern(ToCarioColor(color)); |
587 | 686 | cr.SetSource(pattern); |
588 | 687 | |
589 | 688 | cr.NewPath( ); |
590 | - cr.MoveTo(32, 16); | |
689 | + //cr.MoveTo(0, 16); | |
591 | 690 | cr.Tolerance = 0.1; |
592 | 691 | cr.Antialias = Antialias.Default; |
593 | 692 | cr.FillRule = FillRule.Winding; |
594 | 693 | |
595 | - stampy.DrawTextLine(cr, CairoFont.WhiteMediumText( ).WithFontSize(96), text, 32D, 16); | |
596 | - cr.LineWidth = 3D; | |
597 | - cr.MoveTo(64, 16); | |
598 | - cr.RelLineTo(0D, 248D); | |
694 | + stampy.DrawTextLine(cr, CairoFont.WhiteMediumText( ).WithFontSize(96F).WithWeight(FontWeight.Bold), text, 8D, 16D); | |
695 | + //cr.LineWidth = 3D; | |
696 | + //cr.MoveTo(64, 16); | |
697 | + //cr.RelLineTo(0D, 248D); | |
599 | 698 | |
600 | 699 | cr.FillPreserve( ); |
601 | 700 | } |
@@ -9,4 +9,8 @@ | ||
9 | 9 | "adjustor:item-adjustmenttool_crude": "Crude Adjustment Tool", |
10 | 10 | "adjustor:itemdesc-adjustmenttool-*": "Manipulate adjustable block types, without breaking them.", |
11 | 11 | "adjustor:itemdesc-adjustmenttool_crude": "Crudely manipulate adjustable block types, without breaking them.", |
12 | + "adjustor:rotation-up":"UP", | |
13 | + "adjustor:rotation-down":"DOWN", | |
14 | + "adjustor:rotation-free":"FREE", | |
15 | + "adjustor:rotation-fixed":"FIXED", | |
12 | 16 | } |