-
-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathManagerTab_Livestock.cs
More file actions
942 lines (799 loc) · 40.4 KB
/
Copy pathManagerTab_Livestock.cs
File metadata and controls
942 lines (799 loc) · 40.4 KB
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
// Karel Kroeze
// ManagerTab_Livestock.cs
// 2016-12-09
using System;
using System.Collections.Generic;
using System.Linq;
using RimWorld;
using UnityEngine;
using Verse;
using static FluffyManager.Constants;
using static FluffyManager.Utilities;
using static FluffyManager.Widgets_Labels;
namespace FluffyManager
{
public class ManagerTab_Livestock : ManagerTab
{
private List<PawnKindDef> _availablePawnKinds;
private List<ManagerJob_Livestock> _currentJobs;
// init with 5's if new job.
private Dictionary<AgeAndSex, string> _newCounts =
Utilities_Livestock.AgeSexArray.ToDictionary( k => k, v => "5" );
private bool _onCurrentTab;
private Vector2 _scrollPosition = Vector2.zero;
private PawnKindDef _selectedAvailable;
private ManagerJob_Livestock _selectedCurrent;
private float optionsHeight = 1;
private Vector2 optionsScrollPosition = Vector2.zero;
public ManagerTab_Livestock( Manager manager ) : base( manager )
{
}
public override Texture2D Icon => Resources.IconLivestock;
// public override Texture2D Icon { get; }
public override IconAreas IconArea => IconAreas.Middle;
public override string Label => "FML.Livestock".Translate();
public override ManagerJob Selected
{
get => _selectedCurrent;
set
{
// set tab to current if we're moving to an actual job.
// in either case, available selection can be cleared.
_onCurrentTab = value != null;
_selectedAvailable = null;
_selectedCurrent = (ManagerJob_Livestock) value;
_newCounts =
_selectedCurrent?.Trigger?.CountTargets.ToDictionary( k => k.Key, v => v.Value.ToString() );
}
}
private List<MasterMode> GetMasterModes => Enum.GetValues( typeof( MasterMode ) ).Cast<MasterMode>().ToList();
public override void DoWindowContents( Rect canvas )
{
var leftRow = new Rect( 0f, 31f, DefaultLeftRowSize, canvas.height - 31f );
var contentCanvas = new Rect( leftRow.xMax + Margin, 0f,
canvas.width - leftRow.width - Margin, canvas.height );
DoLeftRow( leftRow );
DoContent( contentCanvas );
}
public override void PreOpen()
{
Refresh();
}
private void DoContent( Rect rect )
{
// background
Widgets.DrawMenuSection( rect );
// cop out if nothing is selected.
if ( _selectedCurrent == null )
{
Label( rect, "FM.Livestock.SelectPawnKind".Translate(), TextAnchor.MiddleCenter );
return;
}
// rects
var optionsColumnRect = new Rect(
rect.xMin,
rect.yMin,
rect.width * 3 / 5f,
rect.height - Margin - ButtonSize.y );
var animalsColumnRect = new Rect(
optionsColumnRect.xMax,
rect.yMin,
rect.width * 2 / 5f,
rect.height - Margin - ButtonSize.y );
var buttonRect = new Rect(
rect.xMax - ButtonSize.x,
rect.yMax - ButtonSize.y,
ButtonSize.x - Margin,
ButtonSize.y - Margin );
Vector2 position;
float width;
Widgets_Section.BeginSectionColumn( optionsColumnRect, "Livestock.Options", out position, out width );
Widgets_Section.Section( ref position, width, DrawTargetCountsSection,
"FM.Livestock.TargetCountsHeader".Translate() );
Widgets_Section.Section( ref position, width, DrawTamingSection, "FM.Livestock.TamingHeader".Translate() );
Widgets_Section.Section( ref position, width, DrawButcherSection,
"FM.Livestock.ButcherHeader".Translate() );
Widgets_Section.Section( ref position, width, DrawTrainingSection,
"FM.Livestock.TrainingHeader".Translate() );
Widgets_Section.Section( ref position, width, DrawAreaRestrictionsSection,
"FM.Livestock.AreaRestrictionsHeader".Translate() );
Widgets_Section.Section( ref position, width, DrawFollowSection, "FM.Livestock.FollowHeader".Translate() );
Widgets_Section.EndSectionColumn( "Livestock.Options", position );
// Start animals list
// get our pawnkind
Widgets_Section.BeginSectionColumn( animalsColumnRect, "Livestock.Animals", out position, out width );
Widgets_Section.Section( ref position, width, DrawTamedAnimalSection,
"FM.Livestock.AnimalsHeader"
.Translate( "FML.Tame".Translate(),
_selectedCurrent.Trigger.pawnKind.GetLabelPlural() )
.CapitalizeFirst() );
Widgets_Section.Section( ref position, width, DrawWildAnimalSection,
"FM.Livestock.AnimalsHeader"
.Translate( "FML.Wild".Translate(),
_selectedCurrent.Trigger.pawnKind.GetLabelPlural() )
.CapitalizeFirst() );
Widgets_Section.EndSectionColumn( "Livestock.Animals", position );
// add / remove to the stack
if ( _selectedCurrent.Managed )
{
if ( Widgets.ButtonText( buttonRect, "FM.Delete".Translate() ) )
{
_selectedCurrent.Delete();
_selectedCurrent = null;
_onCurrentTab = false;
Refresh();
return; // just skip to the next tick to avoid null reference errors.
}
TooltipHandler.TipRegion( buttonRect, "FMP.DeleteBillTooltip".Translate() );
}
else
{
if ( Widgets.ButtonText( buttonRect, "FM.Manage".Translate() ) )
{
_selectedCurrent.Managed = true;
_onCurrentTab = true;
Manager.For( manager ).JobStack.Add( _selectedCurrent );
Refresh();
}
TooltipHandler.TipRegion( buttonRect, "FMP.ManageBillTooltip".Translate() );
}
}
private float DrawTargetCountsSection( Vector2 pos, float width )
{
// counts table
var cols = 3;
var rows = 3;
var fifth = width / 5;
float[] widths = {fifth, fifth * 2, fifth * 2};
float[] heights = {ListEntryHeight * 2 / 3, ListEntryHeight, ListEntryHeight};
// set up a 3x3 table of rects
var countRects = new Rect[rows, cols];
for ( var x = 0; x < cols; x++ )
{
for ( var y = 0; y < rows; y++ )
// kindof overkill for a 3x3 table, but ok.
countRects[y, x] = new Rect(
pos.x + widths.Take( x ).Sum(),
pos.y + heights.Take( y ).Sum(),
widths[x],
heights[y] );
}
// headers
Label( countRects[0, 1], Gender.Female.ToString(), TextAnchor.LowerCenter, GameFont.Tiny );
Label( countRects[0, 2], Gender.Male.ToString(), TextAnchor.LowerCenter, GameFont.Tiny );
Label( countRects[1, 0], "FML.Adult".Translate(), TextAnchor.MiddleRight, GameFont.Tiny );
Label( countRects[2, 0], "FML.Juvenile".Translate(), TextAnchor.MiddleRight, GameFont.Tiny );
// fields
DoCountField( countRects[1, 1], AgeAndSex.AdultFemale );
DoCountField( countRects[1, 2], AgeAndSex.AdultMale );
DoCountField( countRects[2, 1], AgeAndSex.JuvenileFemale );
DoCountField( countRects[2, 2], AgeAndSex.JuvenileMale );
return 3 * ListEntryHeight;
}
private float DrawFollowSection( Vector2 pos, float width )
{
var start = pos;
var rowRect = new Rect( pos.x, pos.y, width, ListEntryHeight );
var buttonRect = new Rect(
rowRect.xMax * 3 / 4,
0f,
width * 1 / 4,
ListEntryHeight * 2 / 3 )
.CenteredOnYIn( rowRect );
// master selection
Label( rowRect, "FM.Livestock.MasterDefault".Translate(), "FM.Livestock.MasterDefault.Tip".Translate(),
TextAnchor.MiddleLeft, margin: Margin );
if ( Widgets.ButtonText( buttonRect, GetMasterLabel() ) )
{
var options = new List<FloatMenuOption>();
// modes
foreach ( var _mode in GetMasterModes.Where( mm => ( mm & MasterMode.All ) == mm ) )
options.Add( new FloatMenuOption( $"FM.Livestock.MasterMode.{_mode}".Translate(),
() => _selectedCurrent.Masters = _mode ) );
// specific pawns
foreach ( var pawn in _selectedCurrent.Trigger.pawnKind.GetMasterOptions( manager, MasterMode.All ) )
options.Add( new FloatMenuOption(
"FM.Livestock.Master".Translate( pawn.LabelShort,
pawn.skills.AverageOfRelevantSkillsFor(
WorkTypeDefOf.Handling ) ),
() =>
{
_selectedCurrent.Master = pawn;
_selectedCurrent.Masters = MasterMode.Specific;
} ) );
Find.WindowStack.Add( new FloatMenu( options ) );
}
// respect bonds?
rowRect.y += ListEntryHeight;
if ( _selectedCurrent.Masters != MasterMode.Default && _selectedCurrent.Masters != MasterMode.Specific )
DrawToggle( rowRect,
"FM.Livestock.RespectBonds".Translate(),
"FM.Livestock.RespectBonds.Tip".Translate(),
ref _selectedCurrent.RespectBonds );
else
Label( rowRect,
"FM.Livestock.RespectBonds".Translate(),
"FM.Livestock.RespectBonds.DisabledBecauseMastersNotSet".Translate(),
color: Color.grey, margin: Margin );
// default follow
rowRect.y += ListEntryHeight;
DrawToggle( rowRect,
"FM.Livestock.Follow".Translate(),
"FM.Livestock.Follow.Tip".Translate(),
ref _selectedCurrent.SetFollow );
if ( _selectedCurrent.SetFollow )
{
rowRect.y += ListEntryHeight;
var followRect = rowRect;
followRect.width /= 2f;
DrawToggle( followRect,
"FM.Livestock.FollowDrafted".Translate(),
"FM.Livestock.FollowDrafted.Tip".Translate(),
ref _selectedCurrent.FollowDrafted,
font: GameFont.Tiny );
followRect.x += followRect.width;
DrawToggle( followRect,
"FM.Livestock.FollowFieldwork".Translate(),
"FM.Livestock.FollowFieldwork.Tip".Translate(),
ref _selectedCurrent.FollowFieldwork,
font: GameFont.Tiny );
}
// follow when training
rowRect.y += ListEntryHeight;
TooltipHandler.TipRegion( rowRect, "FM.Livestock.FollowTraining.Tip".Translate() );
DrawToggle( rowRect,
"FM.Livestock.FollowTraining".Translate(),
"FM.Livestock.FollowTraining.Tip".Translate(),
ref _selectedCurrent.FollowTraining );
// master selection
if ( _selectedCurrent.FollowTraining )
{
rowRect.y += ListEntryHeight;
Label( rowRect, "FM.Livestock.MasterTraining".Translate(),
"FM.Livestock.MasterTraining.Tip".Translate(),
TextAnchor.MiddleLeft, margin: Margin );
buttonRect = buttonRect.CenteredOnYIn( rowRect );
if ( Widgets.ButtonText( buttonRect, GetTrainerLabel() ) )
{
var options = new List<FloatMenuOption>();
// modes
foreach ( var _mode in GetMasterModes.Where( mm => ( mm & MasterMode.Trainers ) == mm ) )
options.Add( new FloatMenuOption( $"FM.Livestock.MasterMode.{_mode}".Translate(),
() => _selectedCurrent.Trainers = _mode ) );
// specific pawns
foreach ( var pawn in _selectedCurrent.Trigger.pawnKind.GetTrainers( manager, MasterMode.Trainers )
)
options.Add( new FloatMenuOption(
"FM.Livestock.Master".Translate( pawn.LabelShort,
pawn.skills.AverageOfRelevantSkillsFor(
WorkTypeDefOf.Handling ) ),
() =>
{
_selectedCurrent.Trainer = pawn;
_selectedCurrent.Trainers = MasterMode.Specific;
} ) );
Find.WindowStack.Add( new FloatMenu( options ) );
}
}
return rowRect.yMax - start.y;
}
public string GetMasterLabel()
{
switch ( _selectedCurrent.Masters )
{
case MasterMode.Specific:
return _selectedCurrent.Master?.LabelShort ?? "FM.None".Translate();
default:
return $"FM.Livestock.MasterMode.{_selectedCurrent.Masters}".Translate();
}
}
public string GetTrainerLabel()
{
switch ( _selectedCurrent.Trainers )
{
case MasterMode.Specific:
return _selectedCurrent.Trainer.LabelShort;
default:
return $"FM.Livestock.MasterMode.{_selectedCurrent.Trainers}".Translate();
}
}
private float DrawAreaRestrictionsSection( Vector2 pos, float width )
{
var start = pos;
// restrict to area
var restrictAreaRect = new Rect( pos.x, pos.y, width, ListEntryHeight );
DrawToggle( restrictAreaRect,
"FML.RestrictToArea".Translate(),
"FML.RestrictToArea.Tip".Translate(),
ref _selectedCurrent.RestrictToArea );
pos.y += ListEntryHeight;
if ( _selectedCurrent.RestrictToArea )
{
DrawAreaSelectorPerGenderAndAge(pos, width, ref _selectedCurrent.RestrictArea);
pos.y += 3 * ListEntryHeight;
}
var sendToSlaughterAreaRect = new Rect( pos.x, pos.y, width, ListEntryHeight );
pos.y += ListEntryHeight;
if ( _selectedCurrent.ButcherExcess )
{
DrawToggle( sendToSlaughterAreaRect,
"FML.SendToSlaughterArea".Translate(),
"FML.SendToSlaughterArea.Tip".Translate(),
ref _selectedCurrent.SendToSlaughterArea );
if ( _selectedCurrent.SendToSlaughterArea )
{
var slaughterAreaRect = new Rect( pos.x, pos.y, width, ListEntryHeight );
AreaAllowedGUI.DoAllowedAreaSelectors( slaughterAreaRect, ref _selectedCurrent.SlaughterArea,
manager );
pos.y += ListEntryHeight;
}
}
else
{
sendToSlaughterAreaRect.xMin += Margin;
Label( sendToSlaughterAreaRect, "FML.SendToSlaughterArea".Translate(),
"FM.Livestock.DisabledBecauseSlaughterExcessDisabled".Translate(), TextAnchor.MiddleLeft,
color: Color.grey );
}
// restrict to hungry area
var RestrictHungryAreaRect = new Rect(pos.x, pos.y, width, ListEntryHeight);
DrawToggle(RestrictHungryAreaRect,
"FML.RestrictToHungryArea".Translate(),
"FML.RestrictToHungryArea.Tip".Translate(),
ref _selectedCurrent.RestrictToHungryArea);
pos.y += ListEntryHeight;
if (_selectedCurrent.RestrictToHungryArea)
{
if (_selectedCurrent.RestrictHungryArea.Count != _selectedCurrent.RestrictArea.Count)
{
_selectedCurrent.RestrictHungryArea = Utilities_Livestock.AgeSexArray.Select(k => (Area)null).ToList();
}
DrawAreaSelectorPerGenderAndAge(pos, width, ref _selectedCurrent.RestrictHungryArea);
pos.y += 3 * ListEntryHeight;
var HungryAreaFoodFullness = new Rect(pos.x, pos.y, width, ListEntryHeight);
HungryAreaFoodFullness.xMin += 3 * Margin;
DrawSlider(HungryAreaFoodFullness, "FML.SendToHungryAreaMaximumFoodNeed.Label".Translate(), "FML.SendToHungryAreaMaximumFoodNeed.Tip".Translate(),
ref _selectedCurrent.SendToHungryAreaMaximumFoodNeed);
pos.y += ListEntryHeight;
}
var sendToTrainingAreaRect = new Rect( pos.x, pos.y, width, ListEntryHeight );
pos.y += ListEntryHeight;
if ( _selectedCurrent.Training.Any )
{
DrawToggle( sendToTrainingAreaRect,
"FML.SendToTrainingArea".Translate(),
"FML.SendToTrainingArea.Tip".Translate(),
ref _selectedCurrent.SendToTrainingArea );
if ( _selectedCurrent.SendToTrainingArea )
{
var trainingAreaRect = new Rect( pos.x, pos.y, width, ListEntryHeight );
AreaAllowedGUI.DoAllowedAreaSelectors( trainingAreaRect, ref _selectedCurrent.TrainingArea,
manager );
pos.y += ListEntryHeight;
}
}
else
{
sendToTrainingAreaRect.xMin += Margin;
Label( sendToTrainingAreaRect, "FML.SendToTrainingArea".Translate(),
"FM.Livestock.DisabledBecauseNoTrainingSet".Translate(), TextAnchor.MiddleLeft,
color: Color.grey );
}
return pos.y - start.y;
}
private void DrawAreaSelectorPerGenderAndAge(Vector2 pos, float width, ref List<Area> restrictArea)
{
// area selectors table
// set up a 3x3 table of rects
var cols = 3;
var fifth = width / 5;
float[] widths = { fifth, fifth * 2, fifth * 2 };
float[] heights = { ListEntryHeight * 2 / 3, ListEntryHeight, ListEntryHeight };
var areaRects = new Rect[cols, cols];
for (var x = 0; x < cols; x++)
for (var y = 0; y < cols; y++)
areaRects[x, y] = new Rect(
widths.Take(x).Sum(),
pos.y + heights.Take(y).Sum(),
widths[x],
heights[y]);
// headers
Label(areaRects[1, 0], Gender.Female.ToString(), TextAnchor.LowerCenter, GameFont.Tiny);
Label(areaRects[2, 0], Gender.Male.ToString(), TextAnchor.LowerCenter, GameFont.Tiny);
Label(areaRects[0, 1], "FML.Adult".Translate(), TextAnchor.MiddleRight, GameFont.Tiny);
Label(areaRects[0, 2], "FML.Juvenile".Translate(), TextAnchor.MiddleRight, GameFont.Tiny);
// do the selectors
restrictArea[0] = AreaAllowedGUI.DoAllowedAreaSelectors(areaRects[1, 1], restrictArea[0], manager, Margin);
restrictArea[1] = AreaAllowedGUI.DoAllowedAreaSelectors(areaRects[2, 1], restrictArea[1], manager, Margin);
restrictArea[2] = AreaAllowedGUI.DoAllowedAreaSelectors(areaRects[1, 2], restrictArea[2], manager, Margin);
restrictArea[3] = AreaAllowedGUI.DoAllowedAreaSelectors(areaRects[2, 2], restrictArea[3], manager, Margin);
Text.Anchor = TextAnchor.UpperLeft; // DoAllowedAreaMode leaves the anchor in an incorrect state.
}
private float DrawTrainingSection( Vector2 pos, float width )
{
var trainingRect = new Rect( pos.x, pos.y, width, ListEntryHeight );
DrawTrainingSelector( trainingRect );
var height = ListEntryHeight;
if ( _selectedCurrent.Training.Any )
{
var trainYoungRect = new Rect( pos.x, pos.y + height, width, ListEntryHeight );
DrawToggle( trainYoungRect,
"FML.TrainYoung".Translate(),
"FML.TrainYoung.Tip".Translate(),
ref _selectedCurrent.Training.TrainYoung );
height += ListEntryHeight;
}
return height;
}
public void DrawTrainingSelector( Rect rect )
{
var cellCount = _selectedCurrent.Training.Count;
var cellWidth = ( rect.width - Margin * ( cellCount - 1 ) ) / cellCount;
var keys = _selectedCurrent.Training.Defs;
GUI.BeginGroup( rect );
for ( var i = 0; i < _selectedCurrent.Training.Count; i++ )
{
var cell = new Rect( i * ( cellWidth + Margin ), 0f, cellWidth, rect.height );
bool visible;
var report = _selectedCurrent.CanBeTrained( _selectedCurrent.Trigger.pawnKind, keys[i], out visible );
if ( visible && report.Accepted )
{
var checkOn = _selectedCurrent.Training[keys[i]];
DrawToggle( cell, keys[i].LabelCap, keys[i].description, ref checkOn, size: 16f,
font: GameFont.Tiny, wrap: false );
_selectedCurrent.Training[keys[i]] = checkOn;
}
else if ( visible )
{
Label( cell, keys[i].LabelCap, report.Reason, TextAnchor.MiddleCenter, GameFont.Tiny, Color.grey );
}
}
GUI.EndGroup();
}
private float DrawButcherSection( Vector2 pos, float width )
{
var start = pos;
// butchery stuff
var butcherExcessRect = new Rect( pos.x, pos.y, width, ListEntryHeight );
DrawToggle( butcherExcessRect,
"FML.ButcherExcess".Translate(),
"FML.ButcherExcess.Tip".Translate(),
ref _selectedCurrent.ButcherExcess );
pos.y += ListEntryHeight;
if ( _selectedCurrent.ButcherExcess )
{
var cellWidth = ( width - Margin * 2 ) / 3f;
var butcherOptionRect = new Rect( pos.x, pos.y, cellWidth, ListEntryHeight );
DrawToggle( butcherOptionRect,
"FML.ButcherTrained".Translate(),
"FML.ButcherTrained.Tip".Translate(),
ref _selectedCurrent.ButcherTrained, font: GameFont.Tiny, wrap: false );
butcherOptionRect.x += cellWidth + Margin;
DrawToggle( butcherOptionRect,
"FML.ButcherPregnant".Translate(),
"FML.ButcherPregnant.Tip".Translate(),
ref _selectedCurrent.ButcherPregnant, font: GameFont.Tiny, wrap: false );
butcherOptionRect.x += cellWidth + Margin;
DrawToggle( butcherOptionRect,
"FML.ButcherBonded".Translate(),
"FML.ButcherBonded.Tip".Translate(),
ref _selectedCurrent.ButcherBonded, font: GameFont.Tiny, wrap: false );
pos.y += ListEntryHeight;
}
return pos.y - start.y;
}
private float DrawTamingSection( Vector2 pos, float width )
{
var start = pos;
DrawToggle( ref pos, width,
"FML.TameMore".Translate(),
"FML.TameMore.Tip".Translate(),
ref _selectedCurrent.TryTameMore );
// area to tame from (if taming more);
if ( _selectedCurrent.TryTameMore )
{
AreaAllowedGUI.DoAllowedAreaSelectors( ref pos, width, ref _selectedCurrent.TameArea, manager );
DrawReachabilityToggle( ref pos, width, ref _selectedCurrent.CheckReachable );
DrawToggle( ref pos, width,
"FM.PathBasedDistance".Translate(),
"FM.PathBasedDistance.Tip".Translate(),
ref _selectedCurrent.PathBasedDistance, true );
}
return pos.y - start.y;
}
private float DrawTamedAnimalSection( Vector2 pos, float width )
{
var pawnKind = _selectedCurrent.Trigger.pawnKind;
var animals = pawnKind?.GetTame( manager );
return DrawAnimalSection( ref pos, width, "FML.Tame".Translate(), pawnKind, animals );
}
private float DrawWildAnimalSection( Vector2 pos, float width )
{
var pawnKind = _selectedCurrent.Trigger.pawnKind;
var animals = pawnKind?.GetWild( manager );
return DrawAnimalSection( ref pos, width, "FML.Wild".Translate(), pawnKind, animals );
}
private float DrawAnimalSection( ref Vector2 pos, float width, string type, PawnKindDef pawnKind,
IEnumerable<Pawn> animals )
{
if ( animals == null )
return 0;
var start = pos;
DrawAnimalListheader( ref pos, new Vector2( width, ListEntryHeight / 3 * 2 ), pawnKind );
if ( !animals.Any() )
{
Label( new Rect( pos.x, pos.y, width, ListEntryHeight ),
"FML.NoAnimals".Translate( type, pawnKind.GetLabelPlural() ),
TextAnchor.MiddleCenter, color: Color.grey );
pos.y += ListEntryHeight;
}
foreach ( var animal in animals )
DrawAnimalRow( ref pos, new Vector2( width, ListEntryHeight ), animal );
return pos.y - start.y;
}
private void DoCountField( Rect rect, AgeAndSex ageSex )
{
if ( _newCounts == null || _newCounts[ageSex] == null )
_newCounts =
_selectedCurrent?.Trigger?.CountTargets.ToDictionary( k => k.Key, v => v.Value.ToString() );
if ( !_newCounts[ageSex].IsInt() )
GUI.color = Color.red;
else
_selectedCurrent.Trigger.CountTargets[ageSex] = int.Parse( _newCounts[ageSex] );
_newCounts[ageSex] = Widgets.TextField( rect.ContractedBy( 1f ), _newCounts[ageSex] );
GUI.color = Color.white;
}
private void DoLeftRow( Rect rect )
{
// background (minus top line so we can draw tabs.)
Widgets.DrawMenuSection( rect );
// tabs
var tabs = new List<TabRecord>();
var availableTabRecord = new TabRecord( "FMP.Available".Translate(), delegate
{
_onCurrentTab = false;
Refresh();
}, !_onCurrentTab );
tabs.Add( availableTabRecord );
var currentTabRecord = new TabRecord( "FMP.Current".Translate(), delegate
{
_onCurrentTab = true;
Refresh();
}, _onCurrentTab );
tabs.Add( currentTabRecord );
TabDrawer.DrawTabs( rect, tabs );
var outRect = rect;
var viewRect = outRect.AtZero();
if ( _onCurrentTab )
DrawCurrentJobList( outRect, viewRect );
else
DrawAvailableJobList( outRect, viewRect );
}
private void DrawAnimalListheader( ref Vector2 pos, Vector2 size, PawnKindDef pawnKind )
{
var start = pos;
// use a third of available screenspace for labels
pos.x += size.x / 3f;
// gender, lifestage, current meat (and if applicable, milking + shearing)
var cols = 3;
// extra columns?
var milk = pawnKind.Milkable();
var wool = pawnKind.Shearable();
if ( milk )
cols++;
if ( wool )
cols++;
var colwidth = size.x * 2 / 3 / cols;
// gender header
var genderRect = new Rect( pos.x, pos.y, colwidth, size.y );
var genderMale =
new Rect( 0f, 0f, SmallIconSize, SmallIconSize ).CenteredIn( genderRect, -SmallIconSize / 2 );
var genderFemale =
new Rect( 0f, 0f, SmallIconSize, SmallIconSize ).CenteredIn( genderRect, SmallIconSize / 2 );
GUI.DrawTexture( genderMale, Resources.MaleIcon );
GUI.DrawTexture( genderFemale, Resources.FemaleIcon );
TooltipHandler.TipRegion( genderRect, "FML.GenderHeader".Translate() );
pos.x += colwidth;
// lifestage header
var ageRect = new Rect( pos.x, pos.y, colwidth, size.y );
var ageRectC = new Rect( 0f, 0f, SmallIconSize, SmallIconSize ).CenteredIn( ageRect, SmallIconSize / 2 );
var ageRectB = new Rect( 0f, 0f, SmallIconSize, SmallIconSize ).CenteredIn( ageRect );
var ageRectA = new Rect( 0f, 0f, SmallIconSize, SmallIconSize ).CenteredIn( ageRect, -SmallIconSize / 2 );
GUI.DrawTexture( ageRectC, Resources.LifeStages( 2 ) );
GUI.DrawTexture( ageRectB, Resources.LifeStages( 1 ) );
GUI.DrawTexture( ageRectA, Resources.LifeStages( 0 ) );
TooltipHandler.TipRegion( ageRect, "FML.AgeHeader".Translate() );
pos.x += colwidth;
// meat header
var meatRect = new Rect( pos.x, pos.y, colwidth, size.y );
var meatIconRect =
new Rect( 0f, 0f, SmallIconSize, SmallIconSize ).CenteredIn( meatRect );
GUI.DrawTexture( meatIconRect, Resources.MeatIcon );
TooltipHandler.TipRegion( meatRect, "FML.MeatHeader".Translate() );
pos.x += colwidth;
// milk header
if ( milk )
{
var milkRect = new Rect( pos.x, pos.y, colwidth, size.y );
var milkIconRect =
new Rect( 0f, 0f, SmallIconSize, SmallIconSize ).CenteredIn( milkRect );
GUI.DrawTexture( milkIconRect, Resources.MilkIcon );
TooltipHandler.TipRegion( milkRect, "FML.MilkHeader".Translate() );
pos.x += colwidth;
}
// wool header
if ( wool )
{
var woolRect = new Rect( pos.x, pos.y, colwidth, size.y );
var woolIconRect =
new Rect( 0f, 0f, MediumIconSize, MediumIconSize ).CenteredIn( woolRect );
GUI.DrawTexture( woolIconRect, Resources.WoolIcon );
TooltipHandler.TipRegion( woolRect, "FML.WoolHeader".Translate() );
pos.x += colwidth;
}
// start next row
pos.x = start.x;
pos.y += size.y;
}
private void DrawAnimalRow( ref Vector2 pos, Vector2 size, Pawn p )
{
var start = pos;
// highlights and interactivity.
var row = new Rect( pos.x, pos.y, size.x, size.y );
Widgets.DrawHighlightIfMouseover( row );
if ( Widgets.ButtonInvisible( row ) )
{
// move camera and select
Find.MainTabsRoot.EscapeCurrentTab();
CameraJumper.TryJump( p.PositionHeld, p.Map );
Find.Selector.ClearSelection();
if ( p.Spawned )
Find.Selector.Select( p );
}
// use a third of available screenspace for labels
var nameRect = new Rect( pos.x, pos.y, size.x / 3f, size.y );
Label( nameRect, p.LabelCap, TextAnchor.MiddleCenter, GameFont.Tiny );
pos.x += size.x / 3f;
// gender, lifestage, current meat (and if applicable, milking + shearing)
var cols = 3;
// extra columns?
if ( p.kindDef.Milkable() )
cols++;
if ( p.kindDef.Shearable() )
cols++;
var colwidth = size.x * 2 / 3 / cols;
// gender column
var genderRect = new Rect( pos.x, pos.y, colwidth, size.y );
var genderIconRect =
new Rect( 0f, 0f, SmallIconSize, SmallIconSize ).CenteredIn( genderRect );
switch ( p.gender )
{
case Gender.Female:
GUI.DrawTexture( genderIconRect, Resources.FemaleIcon );
break;
case Gender.Male:
GUI.DrawTexture( genderIconRect, Resources.MaleIcon );
break;
case Gender.None:
GUI.DrawTexture( genderIconRect, Resources.UnkownIcon );
break;
}
TooltipHandler.TipRegion( genderRect, p.gender.GetLabel() );
pos.x += colwidth;
// lifestage column
var ageRect = new Rect( pos.x, pos.y, colwidth, size.y );
var ageIconRect = new Rect( 0f, 0f, SmallIconSize, SmallIconSize ).CenteredIn( ageRect );
GUI.DrawTexture( ageIconRect, Resources.LifeStages( p.ageTracker.CurLifeStageIndex ) );
TooltipHandler.TipRegion( ageRect, p.ageTracker.AgeTooltipString );
pos.x += colwidth;
// meat column
var meatRect = new Rect( pos.x, pos.y, colwidth, size.y );
// NOTE: When splitting tabs into separate mods; estimated meat count is defined in the Hunting helper.
Label( meatRect, p.EstimatedMeatCount().ToString(),
"FML.Yields".Translate( p.RaceProps.meatDef.LabelCap, p.EstimatedMeatCount() ),
TextAnchor.MiddleCenter, GameFont.Tiny );
pos.x += colwidth;
// milk column
if ( p.Milkable() )
{
var milkRect = new Rect( pos.x, pos.y, colwidth, size.y );
var comp = p.TryGetComp<CompMilkable>();
Label( milkRect, comp.Fullness.ToString( "0%" ),
"FML.Yields".Translate( comp.Props.milkDef.LabelCap, comp.Props.milkAmount ),
TextAnchor.MiddleCenter, GameFont.Tiny );
}
if ( p.kindDef.Milkable() )
pos.x += colwidth;
// wool column
if ( p.Shearable() )
{
var woolRect = new Rect( pos.x, pos.y, colwidth, size.y );
var comp = p.TryGetComp<CompShearable>();
Label( woolRect, comp.Fullness.ToString( "0%" ),
"FML.Yields".Translate( comp.Props.woolDef.LabelCap, comp.Props.woolAmount ),
TextAnchor.MiddleCenter, GameFont.Tiny );
}
if ( p.kindDef.Milkable() )
pos.x += colwidth;
// do the carriage return on ref pos
pos.x = start.x;
pos.y += size.y;
}
private void DrawAvailableJobList( Rect outRect, Rect viewRect )
{
// set sizes
viewRect.height = _availablePawnKinds.Count * LargeListEntryHeight;
if ( viewRect.height > outRect.height )
viewRect.width -= ScrollbarWidth;
Widgets.BeginScrollView( outRect, ref _scrollPosition, viewRect );
GUI.BeginGroup( viewRect );
for ( var i = 0; i < _availablePawnKinds.Count; i++ )
{
// set up rect
var row = new Rect( 0f, LargeListEntryHeight * i, viewRect.width, LargeListEntryHeight );
// highlights
Widgets.DrawHighlightIfMouseover( row );
if ( i % 2 == 0 ) Widgets.DrawAltRect( row );
if ( _availablePawnKinds[i] == _selectedAvailable ) Widgets.DrawHighlightSelected( row );
// draw label
var label = _availablePawnKinds[i].LabelCap + "\n<i>" +
"FML.TameWildCount".Translate(
_availablePawnKinds[i].GetTame( manager ).Count(),
_availablePawnKinds[i].GetWild( manager ).Count() ) + "</i>";
Label( row, label, TextAnchor.MiddleLeft, margin: Margin * 2 );
// button
if ( Widgets.ButtonInvisible( row ) )
{
_selectedAvailable =
_availablePawnKinds[i]; // for highlighting to work
Selected = new ManagerJob_Livestock( _availablePawnKinds[i], manager ); // for details
}
}
GUI.EndGroup();
Widgets.EndScrollView();
}
private void DrawCurrentJobList( Rect outRect, Rect viewRect )
{
// set sizes
viewRect.height = _currentJobs.Count * LargeListEntryHeight;
if ( viewRect.height > outRect.height )
viewRect.width -= ScrollbarWidth;
Widgets.BeginScrollView( outRect, ref _scrollPosition, viewRect );
GUI.BeginGroup( viewRect );
for ( var i = 0; i < _currentJobs.Count; i++ )
{
// set up rect
var row = new Rect( 0f, LargeListEntryHeight * i, viewRect.width, LargeListEntryHeight );
// highlights
Widgets.DrawHighlightIfMouseover( row );
if ( i % 2 == 0 ) Widgets.DrawAltRect( row );
if ( _currentJobs[i] == _selectedCurrent ) Widgets.DrawHighlightSelected( row );
// draw label
_currentJobs[i].DrawListEntry( row, false );
// button
if ( Widgets.ButtonInvisible( row ) ) Selected = _currentJobs[i];
}
GUI.EndGroup();
Widgets.EndScrollView();
}
private void Refresh()
{
// currently managed
_currentJobs = Manager.For( manager ).JobStack.FullStack<ManagerJob_Livestock>();
// concatenate lists of animals on biome and animals in colony.
_availablePawnKinds = manager.map.Biome.AllWildAnimals.ToList();
_availablePawnKinds.AddRange(
manager.map.mapPawns.AllPawns
.Where( p => p.RaceProps.Animal )
.Select( p => p.kindDef ) );
_availablePawnKinds = _availablePawnKinds
// get distinct pawnkinds from the merges
.Distinct()
// remove already managed pawnkinds
.Where( pk => !_currentJobs.Select( job => job.Trigger.pawnKind ).Contains( pk ) )
// order by label
.OrderBy( def => def.LabelCap )
.ToList();
}
}
}