-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGuiScript.luau
More file actions
1115 lines (901 loc) · 33.3 KB
/
GuiScript.luau
File metadata and controls
1115 lines (901 loc) · 33.3 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
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
-- This script is responsible for working the gui
-- basic functions
function waitForChild(instance, name)
while not instance:findFirstChild(name) do
instance.ChildAdded:wait()
end
end
function waitForProperty(instance, name)
while not instance[name] do
instance.Changed:wait()
end
end
-- Locals
local Tool = script.Parent
waitForChild(Tool, "LuaGlobalVariables")
local variables = Tool.LuaGlobalVariables
waitForChild(variables, "InsertAsset")
local insertAsset = variables.InsertAsset
waitForChild(variables, "SwitchMode")
local switchMode = variables.SwitchMode
waitForChild(variables, "ShowAdminCategories")
local showAdminCategories = variables.ShowAdminCategories
waitForChild(variables, "ReloadCurrentAsset")
waitForChild(variables,"userIDs")
game:GetService("ContentProvider"):Preload("http://www.mercs.dev/asset?id=42163425")
game:GetService("ContentProvider"):Preload("http://www.mercs.dev/asset?id=42563487")
local BaseUrl = game:GetService("ContentProvider").BaseUrl
local buttonHeight = 64
local buttonWidth = buttonHeight
local waypointShowing = false
local showingPartPicker = true
local firstEquip = true
local Window
local Data
local loading = false
local startTime = 0
local SetCache = {}
local lastEnter = nil
-- For Restricting Stamper Tool
local buildingPlate
local partModel
-- wait for all of our set ids to load
local userIdsForStamperParts = variables.userIDs -- 7502714 This is UsabilityMan (on gametest)
function giveNewUserId(id)
local newUserId = Instance.new("IntValue")
newUserId.Name = "userID"
newUserId.Value = id
newUserId.Parent = userIdsForStamperParts
userIdsForStamperParts.Value = userIdsForStamperParts.Value + 1
end
BaseUrl = BaseUrl:lower()
local isRestricted = Instance.new("BoolValue")
isRestricted.Name = "IsRestricted"
isRestricted.Value = false
function isLocalWTRB()
waitForChild(game,"StarterGui")
if game.StarterGui:FindFirstChild("VersionGui") then
if game.StarterGui.VersionGui:FindFirstChild("VersionText", true) then
return true
end
end
return false
end
waitForProperty(game,"PlaceId")
if game.PlaceId == 41324860 or isLocalWTRB() then
isRestricted.Value = true
end
isRestricted.Parent = variables
giveNewUserId(18881789)
giveNewUserId(18881808)
if not isRestricted.Value then
giveNewUserId(18881829)
giveNewUserId(18881853)
giveNewUserId(18881866)
else
giveNewUserId(2409156)
giveNewUserId(19238067)
giveNewUserId(19238114)
end
while #userIdsForStamperParts:GetChildren() < userIdsForStamperParts.Value do userIdsForStamperParts.ChildAdded:wait() end
userIdsForStamperParts = userIdsForStamperParts:GetChildren()
local useAssetVersionId = false
local LargeThumbnailUrl
local SmallThumbnailUrl
local InsertRows = 0
local InsertColumns = 0
local insertButtons = {}
local CancelDuringLoad
local prevPart = {AssetNameValue = "",AssetIdValue = 0 ,InsertFrameButtonImage = ""}
local recentPartStack = {}
-- Connection Managers
local guiChangedCon = nil
local cloneButtonCon = nil
local partListClickCon = nil
local itemFrameChangedCon = nil
local setsNextPageCon = nil
local setsPrevPageCon = nil
local insertPanelCloseCon = nil
local minimizeCon = nil
local restoreCon = nil
local setButtonCons = {}
local insertButtonCons = {}
local recentPartStackCons = {}
local Mouse = nil
local currSetPage = 1
local mode = 0 -- 0 = main dialog, 1 = stamper, 2 = eyedropper
waitForChild(script.Parent,"StampGUI")
local stamperGui = script.Parent.StampGUI
waitForChild(stamperGui,"InsertPanel")
waitForChild(stamperGui.InsertPanel, "CancelButton")
local currStampGui = nil
local maxRecentParts = 4
for i = 1, maxRecentParts do
recentPartStack[i] = {AssetNameValue,AssetIdValue,InsertFrameButtonImage}
recentPartStack[i].AssetNameValue = ""
recentPartStack[i].AssetIdValue = ""
recentPartStack[i].InsertFrameButtonImage = ""
end
----------------------------------------------------------------------------------------
-- functions
function showBaseplateGuideArrows()
playerCharacter = Tool.Parent
if playerCharacter:FindFirstChild("Humanoid") and not playerCharacter:FindFirstChild("BasePlateGuide") then
newGuide = Tool.BasePlateGuide:Clone()
newGuide.Parent = playerCharacter
newGuide.Disabled = false
end
end
function setAssetUrls()
if useAssetVersionId then
LargeThumbnailUrl = BaseUrl .. "Game/Tools/ThumbnailAsset.ashx?fmt=png&wd=420&ht=420&assetversionid="
SmallThumbnailUrl = BaseUrl .. "Game/Tools/ThumbnailAsset.ashx?fmt=png&wd=75&ht=75&assetversionid="
else
LargeThumbnailUrl = BaseUrl .. "Game/Tools/ThumbnailAsset.ashx?fmt=png&wd=420&ht=420&aid="
SmallThumbnailUrl = BaseUrl .. "Game/Tools/ThumbnailAsset.ashx?fmt=png&wd=75&ht=75&aid="
end
end
function signalSwitchMode(mode)
switchMode.Mode.Value = mode
switchMode.Value = true
end
function goToClone()
cancelLoadingWindow()
closeInsertPanel()
cancelAssetPlacement()
mode = 2
--signalStamperScript("",0,"","",false)
signalSwitchMode("Clone")
currStampGui.StamperPanel.StamperButtons.ClonePanel.Visible = true
currStampGui.StamperPanel.StamperButtons.CloneButton.Selected = true
if currStampGui.Parent ~= nil then
currStampGui.StamperPanel.StamperButtons.ClonePanel:TweenPosition(UDim2.new(0, -88, 0, -8),Enum.EasingDirection.InOut,Enum.EasingStyle.Sine,0.35,true)
delay(0.3,function() currStampGui.StamperPanel.StamperButtons.ClonePanel.ClonePanelText.Visible = true end)
end
end
function goToStamp()
mode = 1
cancelLoadingWindow()
closeInsertPanel()
closeClonePanel()
end
function goToInsertPanel()
cancelLoadingWindow()
closeClonePanel()
pcall(function() currStampGui.InsertPanel.CancelButton.Modal = true end)
currStampGui.StamperPanel.StamperButtons.PartsButton.Selected = true
if not showingPartPicker then
showingPartPicker = true
if currStampGui.Parent ~= nil then
currStampGui.InsertPanel:TweenPosition(UDim2.new(0.2, 2, 0.1, 24),Enum.EasingDirection.InOut,Enum.EasingStyle.Sine,0.35,true)
end
else
closeInsertPanel()
reloadCurrentAsset()
end
end
function closeInsertPanel()
pcall(function() currStampGui.InsertPanel.CancelButton.Modal = false end)
currStampGui.StamperPanel.StamperButtons.PartsButton.Selected = false
showingPartPicker = false
if currStampGui.Parent ~= nil then
currStampGui.InsertPanel:TweenPosition(UDim2.new(0.2, 2, 1, 24),Enum.EasingDirection.InOut,Enum.EasingStyle.Sine,0.35,true)
end
end
function closeClonePanel()
currStampGui.StamperPanel.StamperButtons.ClonePanel.ClonePanelText.Visible = false
currStampGui.StamperPanel.StamperButtons.CloneButton.Selected = false
if currStampGui.Parent ~= nil then
currStampGui.StamperPanel.StamperButtons.ClonePanel:TweenPosition(UDim2.new(0, 0, 0, -8),Enum.EasingDirection.InOut,Enum.EasingStyle.Sine,0.35,true)
delay(0.3,function() currStampGui.StamperPanel.StamperButtons.ClonePanel.Visible = false end)
end
end
function cancelAssetPlacement()
gInitial90DegreeRotations = 0
Data.Stamp.Cancelled = true
Data.Stamp.Dragger = nil
if Data.Stamp.Model then
Data.Stamp.Model:Remove()
Data.Stamp.Model = nil
end
if Data.Stamp.CurrentParts then
for index, object in pairs(Data.Stamp.CurrentParts) do
object:Remove()
end
Data.Stamp.CurrentParts = nil
end
if Mouse then
Mouse.Icon ="rbxasset://textures\\ArrowCursor.png"
end
game.JointsService:ClearJoinAfterMoveJoints()
end
function hint(label)
-- Pass in a string, it shows a top hint. (Replaces previous hint, if exists)
_player = game.Players:GetPlayerFromCharacter(Tool.Parent)
if(_player.PlayerGui:FindFirstChild("topHint")~=nil) then
local topHint = _player.PlayerGui.topHint
topHint.Add.Label.Value = label
topHint.Add.Width.Value = 3 -- widest width
topHint.Add.Time.Value = 5
topHint.Add.Disabled = true
topHint.Add.Disabled = false
end
end
function getPlayer()
return game.Players:GetPlayerFromCharacter(script.Parent.Parent)
end
function getHumanoid()
local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
if player then
waitForProperty(player,"Character")
waitForChild(player.Character,"Humanoid")
return player.Character.Humanoid
else
return nil
end
end
function buildSetButton(name, setId, setImageId, i, count)
local button = currStampGui.InsertPanel.Sets.SetsLists.SetButtonExample:Clone()
button.Text = name
button.Name = "SetButton"
button.Visible = true
local setValue = Instance.new("IntValue")
setValue.Name = "SetId"
setValue.Value = setId
setValue.Parent = button
local setName = Instance.new("StringValue")
setName.Name = "SetName"
setName.Value = name
setName.Parent = button
return button
end
function previousSetPage()
local newIndex = math.max(0, Data.Category[Data.CurrentCategory].Index - (InsertRows * InsertColumns))
setSetIndex(newIndex)
end
function nextSetPage()
local newIndex = math.max(0, Data.Category[Data.CurrentCategory].Index + (InsertRows * InsertColumns))
setSetIndex(newIndex)
end
function setInsertButtonImageBehavior(insertFrame, visible, name, assetId)
if visible then
insertFrame.AssetName.Value = name
insertFrame.AssetId.Value = assetId
local newImageUrl = SmallThumbnailUrl .. assetId
if newImageUrl ~= insertFrame.Button.ButtonImage.Image then
delay(0,function()
game:GetService("ContentProvider"):Preload(SmallThumbnailUrl .. assetId)
insertFrame.Button.ButtonImage.Image = SmallThumbnailUrl .. assetId
end)
end
table.insert(insertButtonCons,
insertFrame.Button.MouseButton1Click:connect(function()
beginInsertAssetGui(insertFrame.AssetName.Value, insertFrame.AssetId.Value, insertFrame.Button.ButtonImage.Image, 1)
end)
)
insertFrame.Visible = true
else
insertFrame.Visible = false
end
end
function setSetIndex(dataOffset)
Data.Category[Data.CurrentCategory].Index = dataOffset
InsertRows = math.floor(currStampGui.InsertPanel.ItemsFrame.AbsoluteSize.Y/buttonHeight)
InsertColumns = math.floor(currStampGui.InsertPanel.ItemsFrame.AbsoluteSize.X/buttonWidth)
local PageSize = InsertRows * InsertColumns
local contents = Data.Category[Data.CurrentCategory].Contents
if contents then
local numOfPages = math.ceil((#contents)/(PageSize))
local currPage = math.ceil((dataOffset/PageSize) + 1)
currStampGui.InsertPanel.PagingControls.PageText.Text = tostring(currPage) .. "/" .. tostring(numOfPages)
currStampGui.InsertPanel.PagingControls.PageText.Visible = (numOfPages > 1)
currStampGui.InsertPanel.PagingControls.PreviousPageButton.Visible = (numOfPages > 1) and dataOffset > 1
currStampGui.InsertPanel.PagingControls.NextPageButton.Visible = (numOfPages > 1) and ((dataOffset - 1) + PageSize) < (#contents)
-- remove our buttons and their connections
for i = 1, #insertButtons do
insertButtons[i]:remove()
end
for i = 1, #insertButtonCons do
pcall(function() insertButtonCons[i]:disconnect() end)
end
insertButtonCons = {}
insertButtons = {}
local arrayPosition = 1
for y = 1, InsertRows do
for x = 1, InsertColumns do
local buttonPosition = UDim2.new(0,(buttonWidth)*(x-1),0, (buttonHeight)*(y-1))
local buttonCon
insertButtons[arrayPosition], buttonCon = buildInsertButton(buttonPosition)
table.insert(insertButtonCons,buttonCon)
insertButtons[arrayPosition].Parent = currStampGui.InsertPanel.ItemsFrame
arrayPosition = arrayPosition + 1
end
end
Data.InsertButtons = insertButtons
for index = 1, PageSize do
if insertButtons[index] then
if contents[index + dataOffset] then
local assetId
if useAssetVersionId then
assetId = contents[index + dataOffset].AssetVersionId
else
assetId = contents[index + dataOffset].AssetId
end
setInsertButtonImageBehavior(insertButtons[index], true, contents[index + dataOffset].Name, assetId)
else
setInsertButtonImageBehavior(insertButtons[index], false)
end
end
end
else
currStampGui.InsertPanel.PagingControls.PreviousPageButton.Visible = false
currStampGui.InsertPanel.PagingControls.NextPageButton.Visible = false
end
end
function moveLoadingLeft()
if (tick() - startTime > 5) and (currStampGui.Parent ~= nil) then
loading = false
cancelAssetPlacement()
goToInsertPanel()
end
if loading then
currStampGui.LoadDialog.LoadLabel:TweenPosition(UDim2.new(0, 0, 0, -8),Enum.EasingDirection.InOut,Enum.EasingStyle.Sine,0.7,true,function() moveLoadingRight() end)
end
end
function moveLoadingRight()
if (tick() - startTime > 5) and (currStampGui.Parent ~= nil) then
loading = false
cancelAssetPlacement()
goToInsertPanel()
end
if loading then
currStampGui.LoadDialog.LoadLabel:TweenPosition(UDim2.new(0, 180, 0, -8),Enum.EasingDirection.InOut,Enum.EasingStyle.Sine,0.7,true,function() moveLoadingLeft() end)
end
end
function moveLoadingWindow()
startTime = tick()
currStampGui.LoadDialog.Visible = true
loading = true
moveLoadingRight()
end
function cancelLoadingWindow()
currStampGui.LoadDialog.Visible = false
loading = false
end
function selectCategoryPage(buttons, page)
if buttons ~= Data.CurrentCategory then
if Data.CurrentCategory then
for key, button in pairs(Data.CurrentCategory) do
button.Visible = false
end
end
Data.CurrentCategory = buttons
if Data.Category[Data.CurrentCategory] == nil then
Data.Category[Data.CurrentCategory] = {}
if #buttons > 0 then
selectSet(buttons[1], buttons[1].SetName.Value, buttons[1].SetId.Value, 0)
end
else
Data.Category[Data.CurrentCategory].Button = nil
selectSet(Data.Category[Data.CurrentCategory].ButtonFrame, Data.Category[Data.CurrentCategory].SetName, Data.Category[Data.CurrentCategory].SetId, Data.Category[Data.CurrentCategory].Index)
end
if Data.Main.FrameHeight then
if Data.Category[Data.CurrentCategory].SetIndex then
layoutSetButtons(Data.Main.FrameHeight, Data.Category[Data.CurrentCategory].SetIndex)
else
layoutSetButtons(Data.Main.FrameHeight, 1)
end
end
end
end
function selectSet(button, setName, setId, setIndex)
if button and Data.Category[Data.CurrentCategory] ~= nil then
if button ~= Data.Category[Data.CurrentCategory].Button then
Data.Category[Data.CurrentCategory].Button = button
if SetCache[setId] == nil then
SetCache[setId] = game:GetService("InsertService"):GetCollection(setId)
end
Data.Category[Data.CurrentCategory].Contents = SetCache[setId]
Data.Category[Data.CurrentCategory].SetName = setName
Data.Category[Data.CurrentCategory].SetId = setId
end
setSetIndex(setIndex)
end
end
function selectCategory(button, category)
selectCategoryPage(category, 0)
end
function processCategory(sets, setPanel)
local setButtons = {}
local numSkipped = 0
for index, object in pairs(sets) do
if not showAdminCategories.Value and object.Name == "Beta" then
-- skip this if not an admin
numSkipped = numSkipped + 1
else
setButtons[index - numSkipped] = buildSetButton(object.Name, object.CategoryId, object.ImageAssetId, index - numSkipped, #sets)
setButtons[index - numSkipped].Parent = setPanel
end
end
return setButtons
end
function setsNextPageClick(totalSetPages, gridSize)
-- set our logic/gui correctly
if currSetPage >= totalSetPages then return end
currSetPage = currSetPage + 1
currStampGui.InsertPanel.PagingControls.PageText.Text = tostring(currSetPage) .. "/" .. tostring(totalSetPages)
if currSetPage == totalSetPages then
currStampGui.InsertPanel.PagingControls.NextPageButton.Visible = false
currStampGui.InsertPanel.PagingControls.PreviousPageButton.Visible = true
else
Window.Sets.PagingControls.NextPageButton.Visible = true
end
-- actually update the items
makeCurrentSetsPageVisible(gridSize)
end
function setsPrevPageClick(totalSetPages, gridSize)
-- set our logic/gui correctly
if currSetPage <= 1 then return end
currSetPage = currSetPage - 1
currStampGui.InsertPanel.PagingControls.PageText.Text = tostring(currSetPage) .. "/" .. tostring(totalSetPages)
if currSetPage == 1 then
currStampGui.InsertPanel.PagingControls.NextPageButton.Visible = true
currStampGui.InsertPanel.PagingControls.PreviousPageButton.Visible = false
else
currStampGui.InsertPanel.PagingControls.PreviousPageButton.Visible = true
end
-- actually update the items
makeCurrentSetsPageVisible(gridSize)
end
function resetAllSetButtonSelection()
local setButtons = Window.Sets.SetsLists:GetChildren()
for i = 1, #setButtons do
setButtons[i].Selected = false
setButtons[i].BackgroundTransparency = 1
setButtons[i].TextColor3 = Color3.new(1,1,1)
setButtons[i].BackgroundColor3 = Color3.new(1,1,1)
end
end
function populateSetsFrame()
local categories = #Data.UserCategoryButtons
local robloxMaxCat = categories
-- don't do anything until window is visible (otherwise we won't layout anything!)
while Window.Sets.SetsLists.AbsoluteSize.X <= 0 do
Window.Sets.SetsLists.Changed:wait()
end
while Window.Sets.SetsLists.SetButtonExample.AbsoluteSize.X <= 0 do
Window.Sets.SetsLists.SetButtonExample.Changed:wait()
end
local totalColumns = math.floor(Window.Sets.SetsLists.AbsoluteSize.X/Window.Sets.SetsLists.SetButtonExample.AbsoluteSize.X)
local totalRows = math.floor(Window.Sets.SetsLists.AbsoluteSize.Y/Window.Sets.SetsLists.SetButtonExample.AbsoluteSize.Y)
local currRow = 0
local buttonVisible = true
local masterCategory = 1
for i = 1, categories do
local userCategory = masterCategory -- needed to maintain local scope for categories in event listeners below
local button = Window.Sets.SetsLists.SetButtonExample:clone()
button.Name = "Set" .. tostring(Data.UserCategoryButtons[userCategory].SetName.Value) .. "Button"
button.Parent = Window.Sets.SetsLists
button.Position = UDim2.new(0,5,0,currRow * button.AbsoluteSize.Y)
button.Visible = buttonVisible
button.Text = tostring(Data.UserCategoryButtons[userCategory].SetName.Value)
if i == 1 then
button.Selected = true
button.BackgroundColor3 = Color3.new(0,204/255,0)
button.TextColor3 = Color3.new(0,0,0)
button.BackgroundTransparency = 0
end
button.MouseEnter:connect(function()
if not button.Selected then
button.BackgroundTransparency = 0
button.TextColor3 = Color3.new(0,0,0)
end
end)
button.MouseLeave:connect(function()
if not button.Selected then
button.BackgroundTransparency = 1
button.TextColor3 = Color3.new(1,1,1)
end
end)
setButtonCons[i] = button.MouseButton1Click:connect(function()
resetAllSetButtonSelection()
button.Selected = not button.Selected
button.BackgroundColor3 = Color3.new(0,204/255,0)
button.TextColor3 = Color3.new(0,0,0)
button.BackgroundTransparency = 0
selectSet(button, button.Text, Data.UserCategoryButtons[userCategory].SetId.Value, 0)
end)
masterCategory = masterCategory + 1
currRow = currRow + 1
end
-- don't use example button as the first set!
local example = currStampGui.InsertPanel.Sets.SetsLists.SetButtonExample
currStampGui.InsertPanel.Sets.SetsLists.SetButtonExample.Parent = nil
local buttons = currStampGui.InsertPanel.Sets.SetsLists:GetChildren()
example.Parent = currStampGui.InsertPanel.Sets.SetsLists
-- set first category as loaded for default
selectSet(buttons[1], buttons[1].Text, Data.UserCategoryButtons[1].SetId.Value, 0)
selectCategory(buttons[1], Data.UserCategoryButtons)
end
function layoutSetButtons(frameHeight, setIndex)
Data.Main.FrameHeight = frameHeight
Data.Main.InsertSets = math.floor(frameHeight / (height*2))
if #Data.CurrentCategory > Data.Main.InsertSets then
--Steal one entry since we have too many things
Data.Main.InsertSets = Data.Main.InsertSets - 1
end
Data.Category[Data.CurrentCategory].SetIndex = setIndex
end
function showLargePreview(insertButton)
if insertButton:FindFirstChild("AssetId") then
delay(0,function()
game:GetService("ContentProvider"):Preload(LargeThumbnailUrl .. tostring(insertButton.AssetId.Value))
currStampGui.InsertPanel.ItemPreview.LargePreview.Image = LargeThumbnailUrl .. tostring(insertButton.AssetId.Value)
end)
end
if insertButton:FindFirstChild("AssetName") then
currStampGui.InsertPanel.ItemPreview.TextPanel.RolloverText.Text = insertButton.AssetName.Value
end
end
function buildInsertButton(buttonPosition)
local insertButton = currStampGui.InsertPanel.ItemsFrame.InsertAssetButtonExample:clone()
insertButton.Position = buttonPosition
insertButton.Name = "InsertAssetButton"
insertButton.Visible = true
local mouseEnterCon = insertButton.MouseEnter:connect(function()
lastEnter = insertButton
delay(0.1,function()
if lastEnter == insertButton then
showLargePreview(insertButton)
end
end)
end)
return insertButton, mouseEnterCon
end
function minimizeStamperPanel()
currStampGui.StamperPanel.StamperButtons.Visible = false
currStampGui.StamperPanel.MinimizeButton.Visible = false
if currStampGui.Parent ~= nil then
currStampGui.StamperPanel:TweenSizeAndPosition(UDim2.new(0,0,0,0), UDim2.new(0.5,0,1,-92),Enum.EasingDirection.InOut,Enum.EasingStyle.Sine,0.5,true)
delay(0.5,function()
currStampGui.StamperPanel.RestoreButton.Visible = true
end)
end
end
function restoreStamperPanel()
currStampGui.StamperPanel.RestoreButton.Visible = false
if currStampGui.Parent ~= nil then
currStampGui.StamperPanel:TweenSizeAndPosition(UDim2.new(0,350,0,48), UDim2.new(0.5,-175,1,-135), Enum.EasingDirection.InOut,Enum.EasingStyle.Sine,0.5,true)
delay(0.5,function()
currStampGui.StamperPanel.StamperButtons.Visible = true
currStampGui.StamperPanel.MinimizeButton.Visible = true
end)
end
end
function setUpStamperGui()
pcall(function() currStampGui.InsertPanel.CancelButton.Modal = true end)
Window.Sets = currStampGui.InsertPanel.Sets
cloneButtonCon = currStampGui.StamperPanel.StamperButtons.CloneButton.MouseButton1Click:connect(goToClone)
partListClickCon = currStampGui.StamperPanel.StamperButtons.PartsButton.MouseButton1Click:connect(goToInsertPanel)
Data.Main = {}
Data.Category = {}
Data.Stamp = {}
Data.BaseCategoryButtons = {}
local userData = {}
for id = 1, #userIdsForStamperParts do
local newUserData = game:GetService("InsertService"):GetUserCategories(userIdsForStamperParts[id].Value)
if newUserData and #newUserData > 2 then
-- start at #3 to skip over My Decals and My Models for each account
for category = 3, #newUserData do
if newUserData[category].Name == "High Scalability" then
table.insert(userData,1,newUserData[category])
else
table.insert(userData, newUserData[category])
end
end
end
end
if userData then
Data.UserCategoryButtons = processCategory(userData, setPanel)
end
guiChangedCon = currStampGui.Changed:connect(function(prop)
if prop == "AbsoluteSize" then
wait()
setSetIndex(0)
end
end)
InsertRows = math.floor(currStampGui.InsertPanel.ItemsFrame.AbsoluteSize.Y/buttonHeight)
InsertColumns = math.floor(currStampGui.InsertPanel.ItemsFrame.AbsoluteSize.X/buttonWidth)
populateSetsFrame()
setsPrevPageCon = currStampGui.InsertPanel.PagingControls.PreviousPageButton.MouseButton1Click:connect(function() previousSetPage() end)
setsNextPageCon = currStampGui.InsertPanel.PagingControls.NextPageButton.MouseButton1Click:connect(function() nextSetPage() end)
insertPanelCloseCon = currStampGui.InsertPanel.CancelButton.MouseButton1Click:connect(function()
closeInsertPanel()
closeClonePanel()
reloadCurrentAsset()
end)
minimizeCon = currStampGui.StamperPanel.MinimizeButton.MouseButton1Click:connect(function() minimizeStamperPanel() end)
restoreCon = currStampGui.StamperPanel.RestoreButton.MouseButton1Click:connect(function() restoreStamperPanel() end)
end
-- signal to scripts we are ready to start manipulating objects
function signalStamperScript(assetName, assetId, image, stampMode)
insertAsset.AssetName.Value = assetName
insertAsset.AssetId.Value = assetId
insertAsset.Image.Value = image
insertAsset.StampMode.Value = stampMode
insertAsset.Updated.Value = true
end
function reloadCurrentAsset()
variables.ReloadCurrentAsset.Value = true
end
function beginInsertAssetGui(assetName, assetId, image, stampMode)
Data.Stamp.StampMode = stampMode
closeInsertPanel()
signalStamperScript("",0,"","",false)
moveLoadingWindow()
cancelAssetPlacement()
signalStamperScript(assetName, assetId, image, stampMode)
end
function cancelAssetLoad()
Data.Loading.Cancelled = true
insertComplete()
gInitial90DegreeRotations = 0
end
function inBounds2(part)
-- part must have a position property
local xOne= buildingPlate.Position.x + buildingPlate.Size.x/2
local xTwo = buildingPlate.Position.x - buildingPlate.Size.x/2
local zOne = buildingPlate.Position.z + buildingPlate.Size.z/2
local zTwo = buildingPlate.Position.z - buildingPlate.Size.z/2
if part.Position.x > xOne or part.Position.x < xTwo then return false end
if part.Position.z > zOne or part.Position.z < zTwo then return false end
return true
end
-- For Restricting Stamper Tool (isRestricted)
function showHelp_pointToBuildingplate()
if(buildingPlate==nil) then
hint("All building areas are taken. If you want to build, leave and join again.")
else
-- only show one waypoint at a time (because kids will click a million times outside their plate)
hint("Stamper Tool only works in your area.")
if(not waypointShowing) then
waypointShowing = true
local _character = Tool.Parent
waitForChild(_character, "Torso")
_player = game.Players:GetPlayerFromCharacter(_character)
_player.PlayerGui.showBaseplateWaypoint.target.Value = buildingPlate
_player.PlayerGui.showBaseplateWaypoint.Disabled = true
_player.PlayerGui.showBaseplateWaypoint.Disabled = false
-- Wait until character moves in bounds (check every 2 seconds)
while(not inBounds2(_character.Torso) and isEquipped) do wait(2) end
-- Then hide the waypoint
hideHelp_pointToBuildingplate()
end
end
end
function showHelp_tooManyParts()
hint("You have reached maximum number of parts! Delete some to put more down.")
end
function hideHelp_pointToBuildingplate()
waypointShowing = false
_player.PlayerGui.hideBaseplateWaypoint.Disabled = true
_player.PlayerGui.hideBaseplateWaypoint.Disabled = false
end
function setUpRestrictions()
playerModel = game.Workspace.ActiveParts:FindFirstChild(player.Name .. "'s parts")
local takenAreas = game.Workspace.BuildingAreas:GetChildren()
waitForChild(player, "playerNumber")
if(player.playerNumber.Value == 0) then
buildingPlate = nil
partModel = nil
else
waitForChild(game.Workspace, "BuildingAreas")
local buildingAreas = game.Workspace.BuildingAreas
waitForChild(buildingAreas, "Area"..tostring(player.playerNumber.Value))
local targetArea = buildingAreas:FindFirstChild("Area"..tostring(player.playerNumber.Value))
waitForChild(targetArea, "PlayerArea")
waitForChild(targetArea.PlayerArea, "BasePlate")
buildingPlate = targetArea.PlayerArea.BasePlate
partModel = targetArea.PlayerArea
end
-- Check if player is standing in bounds, if not show error
local _character = Tool.Parent
waitForChild(_character, "Torso")
_player = game.Players:GetPlayerFromCharacter(_character)
if(buildingPlate~=nil) then
if(not inBounds2(_character.Torso)) then
showHelp_pointToBuildingplate()
end
else
-- You have no building plate.
hint("All building areas are taken. If you want to build, leave and join again.")
end
end
function onInsertKeyDown(key)
if loading then return end -- don't try to switch while we're loading
key = string.lower(key)
-- go to mru buttons
if key == 'f' then
mruButtonClick(1)
elseif key == 'g' then
mruButtonClick(2)
elseif key == 'h' then
mruButtonClick(3)
elseif key == 'j' then
mruButtonClick(4)
end
end
function onEquippedLocal(mouse)
player = getPlayer()
if not player then
return
end
if Tool.PlayerOwner.Value and Tool.PlayerOwner.Value ~= player then return end
-- For Restricting Stamper Tool
if isRestricted.Value then
setUpRestrictions()
end
Mouse = mouse
if not firstEquip and currStampGui and Tool.SavedState.Value and Tool.PlayerOwner.Value == getPlayer() and Data and Data.FullyLoaded then
currStampGui.Parent = getPlayer().PlayerGui
if mode == 1 then -- if we were stamping, keep going
-- if we signal a negative asset, then that means keep going using whatever was in recent memory [don't reload from insert service]
signalStamperScript(insertAsset.AssetName.Value, -1, insertAsset.Image.Value, true)
elseif mode == 2 then -- time to clone
goToClone()
end
else
if firstEquip then
Tool.PlayerOwner.Value = player
firstEquip = false
end
CancelDuringLoad = false
resetCons()
Data = {}
Data.FullyLoaded = false
Window = {}
Window.Sets = {}
currStampGui = stamperGui:clone()
currStampGui.Parent = getPlayer().PlayerGui
wait()
setUpStamperGui()
if not(CancelDuringLoad) then
currStampGui.Parent = getPlayer().PlayerGui
Tool.SavedState.Value = currStampGui
end
Data.FullyLoaded = true
end
Mouse.KeyDown:connect(onInsertKeyDown)
end
function onUnequippedLocal()
if currStampGui then
Tool.SavedState.Value = currStampGui
currStampGui.Parent = nil
end
pcall(function()
cancelAssetPlacement()
Data.Loading.Cancelled = true
end)
CancelDuringLoad = true
end
function killConnection(connection)
if connection then connection:disconnect() end
end
function resetCons()
killConnection(guiChangedCon)
killConnection(cloneButtonCon)
killConnection(partListClickCon)
killConnection(itemFrameChangedCon)
killConnection(setsPrevPageCon)
killConnection(setsNextPageCon)
killConnection(insertPanelCloseCon)
killConnection(minimizeCon)
killConnection(restoreCon)
end
function onAncestryChanged(child,parent)
if Tool.PlayerOwner.Value and not Tool:IsDescendantOf(Tool.PlayerOwner.Value) and not Tool:IsDescendantOf(Tool.PlayerOwner.Value.Character) then
--Tool was dropped in some way, so we need to nuke our external state
Tool.SavedState.Value = nil
resetCons()
end
end
function getMaxNumOfRecentParts()
return maxRecentParts
end
function pushRecentStackBack()
for i = getMaxNumOfRecentParts() - 1, 1, -1 do
recentPartStack[i + 1].AssetNameValue = recentPartStack[i].AssetNameValue
recentPartStack[i + 1].AssetIdValue = recentPartStack[i].AssetIdValue
recentPartStack[i + 1].InsertFrameButtonImage = recentPartStack[i].InsertFrameButtonImage
end
end