-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MoreMechanisms.cs
2085 lines (1656 loc) · 86.4 KB
/
MoreMechanisms.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using ExampleMod.UI;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MoreMechanisms.Items;
using MoreMechanisms.Tiles;
using ReLogic.Graphics;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Terraria;
using Terraria.Audio;
using Terraria.DataStructures;
using Terraria.GameContent.UI;
using Terraria.GameContent.UI.Elements;
using Terraria.GameContent.UI.States;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ModLoader.IO;
using Terraria.UI;
using static Terraria.ModLoader.ModContent;
/*
-- TODO: 1.4 ADDITIONS --
add rain/storm/sandstorm sensors
add kite category to entity sensor
add golf ball category to entity sensor
add block that only collides with golf ball (not sure if possible?)
-- IDEAS --
spotlight
points at enemies/projectiles and makes a light on them
targets nearest enemy not already targeted by another spotlight
counter
configurable timer
forcefields
pistons
auto crafting tile
way to copy paste item/entity filters
(maybe like factorio?)
-- PARTIALLY IMPLEMENTED --
delay block
TODO: edit delay in ui
vacuum (hopper): suck items from world into inventory
toggleable by wire
itemducts: take items from inventories and push to others
TODO: maybe change to separate connector piece and separate filter piece
filter what items to take or push
TODO: integrate with magic storage
smart quarry which can selectively mine blocks or replace blocks
make it so it has a small range on its own but you can build a frame to make it bigger
make it have an inventory slot to put a pickaxe in and then it uses the stats of the pickaxe
turret with inventory for bullets
configure which entities to shoot
multiple tiers unlocked as game progresses
has max "power" and stats can be upgraded up to the power level (like ftl)
speed, damage, knockback, etc.
auto selling tile
item dropping tile
grand design upgrade with dedicated inventory slots and
TODO: the right click menu having extra buttons for mechanisms
*/
namespace MoreMechanisms {
public class MoreMechanisms : Mod {
public static MoreMechanisms instance;
public static HitTile globalHitTile = new HitTile();
Texture2D checkboxTexture;
Texture2D checkmarkTexture;
Texture2D xTexture;
Texture2D plusTexture;
Texture2D minusTexture;
internal UserInterface speakerUI;
internal SpeakerUIState speakerUIState;
internal UserInterface entitySensorUI;
internal EntitySensorUIState entitySensorUIState;
internal UserInterface itemFilterUI;
internal FilterUIState itemFilterUIState;
internal UserInterface quarryUI;
internal QuarryUIState quarryUIState;
internal UserInterface turretUI;
internal TurretUIState turretUIState;
public class SpeakerUIState : UIState {
UIPanel panel;
UIImage globalCheckboxMark;
UIText volumeText;
UIText pitchText;
internal int i, j;
List<UIPanel> buttons;
public override void OnInitialize() {
panel = new UIPanel();
panel.Width.Set(700, 0);
panel.Height.Set(500, 0);
panel.HAlign = 0.5f;
panel.VAlign = 0.25f;
UIText header = new UIText("Speaker", 1.2f);
header.HAlign = 0.5f; // 1
header.Top.Set(5, 0); // 2
panel.Append(header);
UIElement global = new UIElement();
global.Top.Set(30, 0);
global.Left.Set(30, 0);
global.Width.Set(160, 0);
global.Height.Set(25, 0);
global.SetPadding(0);
UIImage globalCheckbox = new UIImage(MoreMechanisms.instance.checkboxTexture);
globalCheckbox.Top.Set(0, 0);
globalCheckbox.Left.Set(5, 0);
//globalCheckbox.VAlign = 0.5f;
global.Append(globalCheckbox);
globalCheckboxMark = new UIImage(MoreMechanisms.instance.checkmarkTexture);
globalCheckbox.Append(globalCheckboxMark);
UIText globalCheckboxText = new UIText("Global playback", 1f);
globalCheckboxText.HAlign = 0f;
globalCheckboxText.VAlign = 0.5f;
globalCheckboxText.Left.Set(22, 0);
globalCheckboxText.Top.Set(4, 0);
globalCheckbox.Append(globalCheckboxText);
global.OnClick += (UIMouseEvent evt, UIElement listeningElement) => {
Main.PlaySound(SoundID.MenuTick);
Tile tile = Main.tile[this.i / 16, this.j / 16];
int left = (this.i / 16) - tile.frameX % 36 / 18;
int top = (this.j / 16) - tile.frameY / 18;
int index = GetInstance<TESpeaker>().Find(left, top);
if (index != -1) {
TESpeaker speakerEnt = (TESpeaker)TileEntity.ByID[index];
speakerEnt.global = !speakerEnt.global;
if (Main.netMode != NetmodeID.MultiplayerClient) {
speakerEnt.changed = true;
} else {
speakerEnt.ClientSendServer();
}
globalCheckboxMark.SetImage(speakerEnt.global ? MoreMechanisms.instance.checkmarkTexture : MoreMechanisms.instance.xTexture);
}
};
panel.Append(global);
volumeText = new UIText("Volume: 100%");
volumeText.Top.Set(65, 0);
volumeText.Left.Set(30 + 30, 0);
panel.Append(volumeText);
UIImageButton volumePlus = new UISilentImageButton(MoreMechanisms.instance.plusTexture);
volumePlus.Top.Set(65, 0);
volumePlus.Left.Set(30 - 10 + 20, 0);
volumePlus.Width.Set(25, 0);
volumePlus.Height.Set(25, 0);
volumePlus.OnClick += (UIMouseEvent evt, UIElement listeningElement) => {
Main.PlaySound(SoundID.MenuTick);
int amt = 10;
KeyboardState kS = Microsoft.Xna.Framework.Input.Keyboard.GetState();
if (kS.IsKeyDown(Keys.LeftShift)) {
amt = 1;
}
Tile tile = Main.tile[this.i / 16, this.j / 16];
int left = (this.i / 16) - tile.frameX % 36 / 18;
int top = (this.j / 16) - tile.frameY / 18;
int index = GetInstance<TESpeaker>().Find(left, top);
if (index != -1) {
TESpeaker speakerEnt = (TESpeaker)TileEntity.ByID[index];
speakerEnt.volume += amt;
if (speakerEnt.volume > 200) speakerEnt.volume = 200;
if (Main.netMode != NetmodeID.MultiplayerClient) {
speakerEnt.changed = true;
} else {
speakerEnt.ClientSendServer();
}
volumeText.SetText("Volume: " + speakerEnt.volume + "%");
}
};
panel.Append(volumePlus);
UIImageButton volumeMinus = new UISilentImageButton(MoreMechanisms.instance.minusTexture);
volumeMinus.Top.Set(65, 0);
volumeMinus.Left.Set(30 - 5, 0);
volumeMinus.Width.Set(25, 0);
volumeMinus.Height.Set(25, 0);
volumeMinus.OnClick += (UIMouseEvent evt, UIElement listeningElement) => {
Main.PlaySound(SoundID.MenuTick);
int amt = 10;
KeyboardState kS = Microsoft.Xna.Framework.Input.Keyboard.GetState();
if (kS.IsKeyDown(Keys.LeftShift)) {
amt = 1;
}
Tile tile = Main.tile[this.i / 16, this.j / 16];
int left = (this.i / 16) - tile.frameX % 36 / 18;
int top = (this.j / 16) - tile.frameY / 18;
int index = GetInstance<TESpeaker>().Find(left, top);
if (index != -1) {
TESpeaker speakerEnt = (TESpeaker)TileEntity.ByID[index];
speakerEnt.volume -= amt;
if (speakerEnt.volume < 0) speakerEnt.volume = 0;
if (Main.netMode != NetmodeID.MultiplayerClient) {
speakerEnt.changed = true;
} else {
speakerEnt.ClientSendServer();
}
volumeText.SetText("Volume: " + speakerEnt.volume + "%");
}
};
panel.Append(volumeMinus);
pitchText = new UIText("pitch: 100%");
pitchText.Top.Set(90, 0);
pitchText.Left.Set(30 + 30, 0);
panel.Append(pitchText);
UIImageButton pitchPlus = new UISilentImageButton(MoreMechanisms.instance.plusTexture);
pitchPlus.Top.Set(90, 0);
pitchPlus.Left.Set(30 - 10 + 20, 0);
pitchPlus.Width.Set(25, 0);
pitchPlus.Height.Set(25, 0);
pitchPlus.OnClick += (UIMouseEvent evt, UIElement listeningElement) => {
Main.PlaySound(SoundID.MenuTick);
int amt = 10;
KeyboardState kS = Microsoft.Xna.Framework.Input.Keyboard.GetState();
if (kS.IsKeyDown(Keys.LeftShift)) {
amt = 1;
}
Tile tile = Main.tile[this.i / 16, this.j / 16];
int left = (this.i / 16) - tile.frameX % 36 / 18;
int top = (this.j / 16) - tile.frameY / 18;
int index = GetInstance<TESpeaker>().Find(left, top);
if (index != -1) {
TESpeaker speakerEnt = (TESpeaker)TileEntity.ByID[index];
speakerEnt.pitch += amt;
if (speakerEnt.pitch > 200) speakerEnt.pitch = 200;
if (Main.netMode != NetmodeID.MultiplayerClient) {
speakerEnt.changed = true;
} else {
speakerEnt.ClientSendServer();
}
pitchText.SetText("Pitch: " + (speakerEnt.pitch >= 100 ? "+" : "") + (speakerEnt.pitch - 100) + "%");
}
};
panel.Append(pitchPlus);
UIImageButton pitchMinus = new UISilentImageButton(MoreMechanisms.instance.minusTexture);
pitchMinus.Top.Set(90, 0);
pitchMinus.Left.Set(30 - 5, 0);
pitchMinus.Width.Set(25, 0);
pitchMinus.Height.Set(25, 0);
pitchMinus.OnClick += (UIMouseEvent evt, UIElement listeningElement) => {
Main.PlaySound(SoundID.MenuTick);
int amt = 10;
KeyboardState kS = Microsoft.Xna.Framework.Input.Keyboard.GetState();
if (kS.IsKeyDown(Keys.LeftShift)) {
amt = 1;
}
Tile tile = Main.tile[this.i / 16, this.j / 16];
int left = (this.i / 16) - tile.frameX % 36 / 18;
int top = (this.j / 16) - tile.frameY / 18;
int index = GetInstance<TESpeaker>().Find(left, top);
if (index != -1) {
TESpeaker speakerEnt = (TESpeaker)TileEntity.ByID[index];
speakerEnt.pitch -= amt;
if (speakerEnt.pitch < 0) speakerEnt.pitch = 0;
if (Main.netMode != NetmodeID.MultiplayerClient) {
speakerEnt.changed = true;
} else {
speakerEnt.ClientSendServer();
}
pitchText.SetText("Pitch: " + (speakerEnt.pitch >= 100 ? "+" : "") + (speakerEnt.pitch - 100) + "%");
}
};
panel.Append(pitchMinus);
UIList list = new UIList();
list.Top.Pixels = 128f;
list.Width.Set(-32f, 1f);
list.Height.Set(-128f - 4, 1f);
list.ListPadding = 2f;
// temporary workaround until https://github.com/tModLoader/tModLoader/pull/749 gets merged
list.OnScrollWheel += OnScrollWheel_FixHotbarScroll;
panel.Append(list);
FixedUIScrollbar scroll = new FixedUIScrollbar();
scroll.SetView(100f, 1000f);
scroll.Top.Pixels = 128f;
scroll.Height.Set(-128f - 4, 1f);
scroll.HAlign = 1f;
panel.Append(scroll);
list.SetScrollbar(scroll);
var listOfFieldNames = typeof(SoundID).GetFields();
//Main.NewText(listOfFieldNames.Length);
//for (int ii = 0; ii < listOfFieldNames.Length; ii++) {
// Main.NewText(ii + " " + listOfFieldNames[ii].Name);
//}
buttons = new List<UIPanel>();
int cols = 4;
for (int i = 0; i < listOfFieldNames.Length; i += cols) {
UIElement container = new UISortableElement(i);
container.Width.Set(0f, 1f);
container.Height.Set(23f, 0f);
container.HAlign = 0.5f;
list.Add(container);
for (int j = 0; j < cols; j++) {
int e = i + j;
if (e >= listOfFieldNames.Length) break;
UIPanel button = new UIPanel();
button.Width.Set(0, 1f / cols - 0.005f);
button.Height.Set(23, 0);
button.HAlign = (j / (float)(cols - 1));
buttons.Add(button);
var name = listOfFieldNames[e].Name;
if (name.StartsWith("DD2_")) name = name.Substring(4);
UIText text = new UIText(name, name.Length > 19 ? 0.65f : 0.75f);
text.HAlign = text.VAlign = 0.5f;
button.Append(text);
button.OnClick += (UIMouseEvent evt, UIElement listeningElement) => {
ButtonClicked(e, evt, listeningElement);
};
container.Append(button);
}
}
list.Recalculate();
Append(panel);
}
public override void OnActivate() {
base.OnActivate();
Tile tile = Main.tile[this.i / 16, this.j / 16];
if (tile == null) return;
int left = (this.i / 16) - tile.frameX % 36 / 18;
int top = (this.j / 16) - tile.frameY / 18;
int index = GetInstance<TESpeaker>().Find(left, top);
if (index != -1) {
TESpeaker speakerEnt = (TESpeaker)TileEntity.ByID[index];
globalCheckboxMark.SetImage(speakerEnt.global ? MoreMechanisms.instance.checkmarkTexture : MoreMechanisms.instance.xTexture);
volumeText.SetText("Volume: " + speakerEnt.volume + "%");
pitchText.SetText("Pitch: " + (speakerEnt.pitch >= 100 ? "+" : "") + (speakerEnt.pitch - 100) + "%");
for (int ii = 0; ii < buttons.Count; ii++) {
buttons[ii].BackgroundColor = (ii == speakerEnt.soundId) ? new Color(128, 255, 128, 178) : new Color(44, 57, 105, 178);
}
}
}
private void ButtonClicked(int i, UIMouseEvent evt, UIElement listeningElement) {
for(int ii = 0; ii < buttons.Count; ii++) {
buttons[ii].BackgroundColor = (ii == i) ? new Color(128, 255, 128, 178) : new Color(44, 57, 105, 178);
}
//Main.NewText(((UIPanel)listeningElement).BackgroundColor.ToString());
var listOfFieldNames = typeof(SoundID).GetFields();
var sound = listOfFieldNames[i].GetValue(null);
if(sound is LegacySoundStyle) {
LegacySoundStyle sst = sound as LegacySoundStyle;
Main.PlaySound(sst);
} else if(sound is int) {
int snd = (int)sound;
Main.PlaySound(snd);
}
Tile tile = Main.tile[this.i / 16, this.j / 16];
int left = (this.i / 16) - tile.frameX % 36 / 18;
int top = (this.j / 16) - tile.frameY / 18;
int index = GetInstance<TESpeaker>().Find(left, top);
if (index != -1) {
TESpeaker speakerEnt = (TESpeaker)TileEntity.ByID[index];
speakerEnt.soundId = i;
if (Main.netMode != NetmodeID.MultiplayerClient) {
speakerEnt.changed = true;
} else {
speakerEnt.ClientSendServer();
}
}
}
internal static void OnScrollWheel_FixHotbarScroll(UIScrollWheelEvent evt, UIElement listeningElement) {
Main.LocalPlayer.ScrollHotbar(Terraria.GameInput.PlayerInput.ScrollWheelDelta / 120);
}
public override void Update(GameTime gameTime) {
base.Update(gameTime);
if (Main.LocalPlayer.talkNPC != -1) {
// When that happens, we can set the state of our UserInterface to null, thereby closing this UIState. This will trigger OnDeactivate above.
MoreMechanisms.instance.HideSpeakerUI();
}
if (panel.ContainsPoint(Main.MouseScreen)) {
Main.LocalPlayer.mouseInterface = true;
}
}
protected override void DrawSelf(SpriteBatch spriteBatch) {
base.DrawSelf(spriteBatch);
// This will hide the crafting menu similar to the reforge menu. For best results this UI is placed before "Vanilla: Inventory" to prevent 1 frame of the craft menu showing.
Main.HidePlayerCraftingMenu = true;
}
}
public class EntitySensorUIState : UIState {
UIText leftText;
UIText rightText;
UIText topText;
UIText bottomText;
UIPanel panel;
List<Tuple<string, UIImage>> triggerMarks;
internal int i, j;
public override void OnInitialize() {
panel = new UIPanel();
panel.Width.Set(320, 0);
panel.Height.Set(300, 0);
panel.HAlign = 0.5f;
panel.VAlign = 0.125f;
UIText header = new UIText("Entity Sensor", 1.2f);
header.HAlign = 0.5f;
header.Top.Set(5, 0);
panel.Append(header);
int maxRange = 24;
leftText = new UIText("Left: 0 tiles");
leftText.Top.Set(65, 0);
leftText.Left.Set(10 + 30, 0);
panel.Append(leftText);
UIImageButton leftPlus = new UISilentImageButton(MoreMechanisms.instance.plusTexture);
leftPlus.Top.Set(65, 0);
leftPlus.Left.Set(10 - 10 + 20, 0);
leftPlus.Width.Set(25, 0);
leftPlus.Height.Set(25, 0);
leftPlus.OnClick += (UIMouseEvent evt, UIElement listeningElement) => {
Main.PlaySound(SoundID.MenuTick);
int amt = 1;
KeyboardState kS = Microsoft.Xna.Framework.Input.Keyboard.GetState();
if (kS.IsKeyDown(Keys.LeftShift)) {
amt = 1;
}
Tile tile = Main.tile[this.i / 16, this.j / 16];
int left = (this.i / 16);
int top = (this.j / 16);
int index = GetInstance<TEEntitySensor>().Find(left, top);
if (index != -1) {
TEEntitySensor es = (TEEntitySensor)TileEntity.ByID[index];
es.left += amt;
if (es.left > maxRange) es.left = maxRange;
if (Main.netMode != NetmodeID.MultiplayerClient) {
es.changed = true;
} else {
es.ClientSendServer();
}
leftText.SetText("Left: " + es.left + " tiles");
}
};
panel.Append(leftPlus);
UIImageButton leftMinus = new UISilentImageButton(MoreMechanisms.instance.minusTexture);
leftMinus.Top.Set(65, 0);
leftMinus.Left.Set(10 - 5, 0);
leftMinus.Width.Set(25, 0);
leftMinus.Height.Set(25, 0);
leftMinus.OnClick += (UIMouseEvent evt, UIElement listeningElement) => {
Main.PlaySound(SoundID.MenuTick);
int amt = 1;
KeyboardState kS = Microsoft.Xna.Framework.Input.Keyboard.GetState();
if (kS.IsKeyDown(Keys.LeftShift)) {
amt = 1;
}
Tile tile = Main.tile[this.i / 16, this.j / 16];
int left = (this.i / 16);
int top = (this.j / 16);
int index = GetInstance<TEEntitySensor>().Find(left, top);
if (index != -1) {
TEEntitySensor es = (TEEntitySensor)TileEntity.ByID[index];
es.left -= amt;
if (es.left < -maxRange) es.left = -maxRange;
if (es.left < -es.right) es.left = -es.right;
if (Main.netMode != NetmodeID.MultiplayerClient) {
es.changed = true;
} else {
es.ClientSendServer();
}
leftText.SetText("Left: " + es.left + " tiles");
}
};
panel.Append(leftMinus);
rightText = new UIText("Right: 0 tiles");
rightText.Top.Set(90, 0);
rightText.Left.Set(10 + 30, 0);
panel.Append(rightText);
UIImageButton rightPlus = new UISilentImageButton(MoreMechanisms.instance.plusTexture);
rightPlus.Top.Set(90, 0);
rightPlus.Left.Set(10 - 10 + 20, 0);
rightPlus.Width.Set(25, 0);
rightPlus.Height.Set(25, 0);
rightPlus.OnClick += (UIMouseEvent evt, UIElement listeningElement) => {
Main.PlaySound(SoundID.MenuTick);
int amt = 1;
KeyboardState kS = Microsoft.Xna.Framework.Input.Keyboard.GetState();
if (kS.IsKeyDown(Keys.LeftShift)) {
amt = 1;
}
Tile tile = Main.tile[this.i / 16, this.j / 16];
int left = (this.i / 16);
int top = (this.j / 16);
int index = GetInstance<TEEntitySensor>().Find(left, top);
if (index != -1) {
TEEntitySensor es = (TEEntitySensor)TileEntity.ByID[index];
es.right += amt;
if (es.right > maxRange) es.right = maxRange;
//if (es.right < -es.right) es.right = -es.right;
if (Main.netMode != NetmodeID.MultiplayerClient) {
es.changed = true;
} else {
es.ClientSendServer();
}
rightText.SetText("Right: " + es.right + " tiles");
}
};
panel.Append(rightPlus);
UIImageButton rightMinus = new UISilentImageButton(MoreMechanisms.instance.minusTexture);
rightMinus.Top.Set(90, 0);
rightMinus.Left.Set(10 - 5, 0);
rightMinus.Width.Set(25, 0);
rightMinus.Height.Set(25, 0);
rightMinus.OnClick += (UIMouseEvent evt, UIElement listeningElement) => {
Main.PlaySound(SoundID.MenuTick);
int amt = 1;
KeyboardState kS = Microsoft.Xna.Framework.Input.Keyboard.GetState();
if (kS.IsKeyDown(Keys.LeftShift)) {
amt = 1;
}
Tile tile = Main.tile[this.i / 16, this.j / 16];
int left = (this.i / 16);
int top = (this.j / 16);
int index = GetInstance<TEEntitySensor>().Find(left, top);
if (index != -1) {
TEEntitySensor es = (TEEntitySensor)TileEntity.ByID[index];
es.right -= amt;
if (es.right < -maxRange) es.right = -maxRange;
if (es.right < -es.left) es.right = -es.left;
if (Main.netMode != NetmodeID.MultiplayerClient) {
es.changed = true;
} else {
es.ClientSendServer();
}
rightText.SetText("Right: " + es.right + " tiles");
}
};
panel.Append(rightMinus);
topText = new UIText("Top: 0 tiles");
topText.Top.Set(115, 0);
topText.Left.Set(10 + 30, 0);
panel.Append(topText);
UIImageButton topPlus = new UISilentImageButton(MoreMechanisms.instance.plusTexture);
topPlus.Top.Set(115, 0);
topPlus.Left.Set(10 - 10 + 20, 0);
topPlus.Width.Set(25, 0);
topPlus.Height.Set(25, 0);
topPlus.OnClick += (UIMouseEvent evt, UIElement listeningElement) => {
Main.PlaySound(SoundID.MenuTick);
int amt = 1;
KeyboardState kS = Microsoft.Xna.Framework.Input.Keyboard.GetState();
if (kS.IsKeyDown(Keys.LeftShift)) {
amt = 1;
}
Tile tile = Main.tile[this.i / 16, this.j / 16];
int left = (this.i / 16);
int top = (this.j / 16);
int index = GetInstance<TEEntitySensor>().Find(left, top);
if (index != -1) {
TEEntitySensor es = (TEEntitySensor)TileEntity.ByID[index];
es.top += amt;
if (es.top > maxRange) es.top = maxRange;
if (Main.netMode != NetmodeID.MultiplayerClient) {
es.changed = true;
} else {
es.ClientSendServer();
}
topText.SetText("Top: " + es.top + " tiles");
}
};
panel.Append(topPlus);
UIImageButton topMinus = new UISilentImageButton(MoreMechanisms.instance.minusTexture);
topMinus.Top.Set(115, 0);
topMinus.Left.Set(10 - 5, 0);
topMinus.Width.Set(25, 0);
topMinus.Height.Set(25, 0);
topMinus.OnClick += (UIMouseEvent evt, UIElement listeningElement) => {
Main.PlaySound(SoundID.MenuTick);
int amt = 1;
KeyboardState kS = Microsoft.Xna.Framework.Input.Keyboard.GetState();
if (kS.IsKeyDown(Keys.LeftShift)) {
amt = 1;
}
Tile tile = Main.tile[this.i / 16, this.j / 16];
int left = (this.i / 16);
int top = (this.j / 16);
int index = GetInstance<TEEntitySensor>().Find(left, top);
if (index != -1) {
TEEntitySensor es = (TEEntitySensor)TileEntity.ByID[index];
es.top -= amt;
if (es.top < -maxRange) es.top = -maxRange;
if (es.top < -es.bottom) es.top = -es.bottom;
if (Main.netMode != NetmodeID.MultiplayerClient) {
es.changed = true;
} else {
es.ClientSendServer();
}
topText.SetText("Top: " + es.top + " tiles");
}
};
panel.Append(topMinus);
bottomText = new UIText("Bottom: 0 tiles");
bottomText.Top.Set(140, 0);
bottomText.Left.Set(10 + 30, 0);
panel.Append(bottomText);
UIImageButton bottomPlus = new UISilentImageButton(MoreMechanisms.instance.plusTexture);
bottomPlus.Top.Set(140, 0);
bottomPlus.Left.Set(10 - 10 + 20, 0);
bottomPlus.Width.Set(25, 0);
bottomPlus.Height.Set(25, 0);
bottomPlus.OnClick += (UIMouseEvent evt, UIElement listeningElement) => {
Main.PlaySound(SoundID.MenuTick);
int amt = 1;
KeyboardState kS = Microsoft.Xna.Framework.Input.Keyboard.GetState();
if (kS.IsKeyDown(Keys.LeftShift)) {
amt = 1;
}
Tile tile = Main.tile[this.i / 16, this.j / 16];
int left = (this.i / 16);
int top = (this.j / 16);
int index = GetInstance<TEEntitySensor>().Find(left, top);
if (index != -1) {
TEEntitySensor es = (TEEntitySensor)TileEntity.ByID[index];
es.bottom += amt;
if (es.bottom > maxRange) es.bottom = maxRange;
if (Main.netMode != NetmodeID.MultiplayerClient) {
es.changed = true;
} else {
es.ClientSendServer();
}
bottomText.SetText("Bottom: " + es.bottom + " tiles");
}
};
panel.Append(bottomPlus);
UIImageButton bottomMinus = new UISilentImageButton(MoreMechanisms.instance.minusTexture);
bottomMinus.Top.Set(140, 0);
bottomMinus.Left.Set(10 - 5, 0);
bottomMinus.Width.Set(25, 0);
bottomMinus.Height.Set(25, 0);
bottomMinus.OnClick += (UIMouseEvent evt, UIElement listeningElement) => {
Main.PlaySound(SoundID.MenuTick);
int amt = 1;
KeyboardState kS = Microsoft.Xna.Framework.Input.Keyboard.GetState();
if (kS.IsKeyDown(Keys.LeftShift)) {
amt = 1;
}
Tile tile = Main.tile[this.i / 16, this.j / 16];
int left = (this.i / 16);
int top = (this.j / 16);
int index = GetInstance<TEEntitySensor>().Find(left, top);
if (index != -1) {
TEEntitySensor es = (TEEntitySensor)TileEntity.ByID[index];
es.bottom -= amt;
if (es.bottom < -maxRange) es.bottom = -maxRange;
if (es.bottom < -es.top) es.bottom = -es.top;
if (Main.netMode != NetmodeID.MultiplayerClient) {
es.changed = true;
} else {
es.ClientSendServer();
}
bottomText.SetText("Bottom: " + es.bottom + " tiles");
}
};
panel.Append(bottomMinus);
// trigger checkboxes
UIText triggerLabel = new UIText("Trigger On:", 1f);
triggerLabel.Top.Set(65 - 25, 0);
triggerLabel.Left.Set(-140f, 1f);
triggerLabel.Width.Set(160, 0);
triggerLabel.Height.Set(25, 0);
panel.Append(triggerLabel);
Tuple<string, string>[] triggers = {
Tuple.Create("Players" , "triggerPlayers"),
Tuple.Create("NPCs" , "triggerNPCs"),
Tuple.Create("Items" , "triggerItems"),
Tuple.Create("Coins" , "triggerCoins"),
Tuple.Create("Enemies" , "triggerEnemies"),
Tuple.Create("Projectiles", "triggerProjectiles"),
Tuple.Create("Pets" , "triggerPets"),
Tuple.Create("LightPets" , "triggerLightPets"),
Tuple.Create("Minions" , "triggerMinions"),
Tuple.Create("Sentries" , "triggerSentries")
};
triggerMarks = new List<Tuple<string, UIImage>>();
int ind = 0;
foreach(var tr in triggers) {
UIElement trPlayer = new UIElement();
trPlayer.Top.Set(60 + 22 * ind++, 0);
trPlayer.Left.Set(-110f, 1f);
trPlayer.Width.Set(160, 0);
trPlayer.Height.Set(25, 0);
trPlayer.SetPadding(0);
UIImage trPlayerCheckbox = new UIImage(MoreMechanisms.instance.checkboxTexture);
trPlayerCheckbox.Top.Set(0, 0);
trPlayerCheckbox.Left.Set(5, 0);
//globalCheckbox.VAlign = 0.5f;
trPlayer.Append(trPlayerCheckbox);
var trPlayerCheckboxMark = new UIImage(MoreMechanisms.instance.checkmarkTexture);
trPlayerCheckbox.Append(trPlayerCheckboxMark);
triggerMarks.Add(Tuple.Create(tr.Item2, trPlayerCheckboxMark));
UIText trPlayerCheckboxText = new UIText(tr.Item1, 1f);
trPlayerCheckboxText.HAlign = 0f;
trPlayerCheckboxText.VAlign = 0.5f;
trPlayerCheckboxText.Left.Set(22, 0);
trPlayerCheckboxText.Top.Set(4, 0);
trPlayerCheckbox.Append(trPlayerCheckboxText);
trPlayer.OnClick += (UIMouseEvent evt, UIElement listeningElement) => {
Main.PlaySound(SoundID.MenuTick);
Tile tile = Main.tile[this.i / 16, this.j / 16];
int left = (this.i / 16);
int top = (this.j / 16);
int index = GetInstance<TEEntitySensor>().Find(left, top);
if (index != -1) {
TEEntitySensor es = (TEEntitySensor)TileEntity.ByID[index];
FieldInfo field = typeof(EntityFilter).GetField(tr.Item2);
field.SetValue(es.filter, !(bool)field.GetValue(es.filter));
if (Main.netMode != NetmodeID.MultiplayerClient) {
es.changed = true;
} else {
es.ClientSendServer();
}
trPlayerCheckboxMark.SetImage((bool)field.GetValue(es.filter) ? MoreMechanisms.instance.checkmarkTexture : MoreMechanisms.instance.xTexture);
}
};
panel.Append(trPlayer);
}
Append(panel);
}
public override void OnActivate() {
base.OnActivate();
Tile tile = Main.tile[this.i / 16, this.j / 16];
if (tile == null) return;
int left = (this.i / 16);
int top = (this.j / 16);
int index = GetInstance<TEEntitySensor>().Find(left, top);
if (index != -1) {
TEEntitySensor es = (TEEntitySensor)TileEntity.ByID[index];
leftText.SetText("Left: " + es.left + " tiles");
rightText.SetText("Right: " + es.right + " tiles");
topText.SetText("Top: " + es.top + " tiles");
bottomText.SetText("Bottom: " + es.bottom + " tiles");
foreach(var tr in triggerMarks) {
FieldInfo field = typeof(EntityFilter).GetField(tr.Item1);
tr.Item2.SetImage((bool)field.GetValue(es.filter) ? MoreMechanisms.instance.checkmarkTexture : MoreMechanisms.instance.xTexture);
}
}
}
private void ButtonClicked(int i, UIMouseEvent evt, UIElement listeningElement) {
}
internal static void OnScrollWheel_FixHotbarScroll(UIScrollWheelEvent evt, UIElement listeningElement) {
Main.LocalPlayer.ScrollHotbar(Terraria.GameInput.PlayerInput.ScrollWheelDelta / 120);
}
public override void Update(GameTime gameTime) {
base.Update(gameTime);
if (Main.LocalPlayer.talkNPC != -1) {
// When that happens, we can set the state of our UserInterface to null, thereby closing this UIState. This will trigger OnDeactivate above.
MoreMechanisms.instance.HideSpeakerUI();
}
if (panel.ContainsPoint(Main.MouseScreen)) {
Main.LocalPlayer.mouseInterface = true;
}
}
protected override void DrawSelf(SpriteBatch spriteBatch) {
base.DrawSelf(spriteBatch);
// This will hide the crafting menu similar to the reforge menu. For best results this UI is placed before "Vanilla: Inventory" to prevent 1 frame of the craft menu showing.
Main.HidePlayerCraftingMenu = true;
}
}
public class FilterUIState : UIState {
UIPanel panel;
internal int i, j;
Item[] items;
bool whitelist;
Action<Item[], bool> callback;
public void Load(Item[] items, bool whitelist, Action<Item[], bool> callback) {
this.callback = callback;
this.items = items;
this.whitelist = whitelist;
RemoveAllChildren();
OnInitialize();
}
public override void OnInitialize() {
if (items == null) return;
panel = new UIPanel();
panel.Width.Set(420, 0);
panel.Height.Set(140, 0);
panel.HAlign = 0.5f;
panel.VAlign = 0.125f;
UIText header = new UIText("Filter", 1.2f);
header.HAlign = 0.5f;
header.Top.Set(3, 0);
panel.Append(header);
UIPanel whiteBlackList = new UIPanel();
whiteBlackList.Width.Set(80, 0);
whiteBlackList.Height.Set(25, 0);
whiteBlackList.Left.Set(-whiteBlackList.Width.Pixels, 1f);
whiteBlackList.Top.Set(0, 0f);
whiteBlackList.BackgroundColor = whitelist ? Color.White : Color.Black;
UIText whiteBlackListText = new UIText(whitelist ? "whitelist" : "blacklist", 0.8f);
whiteBlackListText.HAlign = 0.5f;
whiteBlackListText.VAlign = 0.5f;
whiteBlackListText.TextColor = Color.White;
whiteBlackList.Append(whiteBlackListText);
whiteBlackList.OnMouseDown += (UIMouseEvent evt, UIElement listeningElement) => {
Main.PlaySound(SoundID.MenuTick);
if(whiteBlackListText.Text == "whitelist") {
whiteBlackListText.SetText("blacklist");
whiteBlackList.BackgroundColor = Color.Black;
} else {
whiteBlackListText.SetText("whitelist");
whiteBlackList.BackgroundColor = Color.White;
}