-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuHandler.luau
More file actions
252 lines (201 loc) · 7.56 KB
/
MenuHandler.luau
File metadata and controls
252 lines (201 loc) · 7.56 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
local player = game.Players.LocalPlayer
local currentCamera = workspace.CurrentCamera
local mouse = player:GetMouse()
local TweenService = game:GetService("TweenService")
local cameraPart = workspace.Cameras:WaitForChild("MainCamera")
local maxTilt = 4
local MenuGui = script.Parent
local MainContainer = MenuGui.MainContainer
local CookingGameFrame = MainContainer.ActivitiesFrame.Cooking
local BounceGameFrame = MainContainer.ActivitiesFrame.Bounce
currentCamera.CameraType = Enum.CameraType.Scriptable
currentCamera.CFrame = cameraPart.CFrame
local foodAmount = {}
local hygieneAmount = {}
local gameAmount = {}
local StateHandler = require(game.ReplicatedStorage.Modules.StateHandler)
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local targetCFrame = cameraPart.CFrame * CFrame.Angles(
math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),
math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),
0
)
local tween = TweenService:Create(currentCamera, tweenInfo, {CFrame = targetCFrame})
local function updateCamera()
local targetCFrame = cameraPart.CFrame * CFrame.Angles(
math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),
math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),
0
)
tween = TweenService:Create(currentCamera, tweenInfo, {CFrame = targetCFrame})
tween:Play()
end
local conn = game:GetService("RunService").RenderStepped:Connect(function()
updateCamera()
end)
game.ReplicatedStorage.Remotes.LostEvent.Event:Connect(function(state)
if state == "lost" then
MenuGui.Button.Visible = false
MenuGui.MainContainer.Visible = false
MenuGui.Kitchen.Visible = false
MenuGui.Main.Visible = false
MenuGui.Shower.Visible = false
cameraPart = workspace.Cameras.AmbulanceCamera
elseif state == "restart" then
cameraPart = workspace.Cameras.MainCamera
foodAmount = {}
hygieneAmount = {}
else
MenuGui.Button.Visible = true
MenuGui.Kitchen.Visible = true
MenuGui.Main.Visible = true
MenuGui.Shower.Visible = true
cameraPart = workspace.Cameras.MainCamera
game.ReplicatedStorage.Remotes.MoveRoom:FireServer("Main")
end
end)
for i,v in (MenuGui:GetChildren()) do
if v:IsA("ImageButton") then
v.MouseButton1Up:Connect(function()
cameraPart = workspace.Cameras:WaitForChild(v.Name.."Camera")
game.ReplicatedStorage.Remotes.MoveRoom:FireServer(v.Name)
closeMainContainer()
if v.Name == "Kitchen" then
MenuGui.Button.Text = "Food Shop"
else if v.Name == "Main" then
MenuGui.Button.Text = "Activities"
else
MenuGui.Button.Text = "Hygiene Shop"
end
end
end)
end
end
MenuGui.Button.MouseButton1Up:Connect(function()
task.wait(0.1)
if MainContainer.Visible == true then
closeMainContainer()
else
MenuGui.ExpensesContainer.Visible = true
MainContainer.Visible = true
if MenuGui.Button.Text == "Food Shop" then
MainContainer.FoodFrame.Visible = true
MainContainer.HygieneFrame.Visible = false
MainContainer.ActivitiesFrame.Visible = false
elseif MenuGui.Button.Text == "Hygiene Shop" then
MainContainer.HygieneFrame.Visible = true
MainContainer.FoodFrame.Visible = false
MainContainer.ActivitiesFrame.Visible = false
else
MainContainer.HygieneFrame.Visible = false
MainContainer.FoodFrame.Visible = false
MainContainer.ActivitiesFrame.Visible = true
end
end
end)
function closeMainContainer()
MainContainer.Visible = false
MenuGui.ExpensesContainer.Visible = false
end
function updateValue(value, amount)
MenuGui.ExpensesContainer:FindFirstChild(value).Value += amount
MenuGui.ExpensesContainer:FindFirstChild(value .."Cost").Text = value .. ": $" .. MenuGui.ExpensesContainer:FindFirstChild(value).Value
MenuGui.ExpensesContainer.TotalCost.Text = "Total: $" .. (MenuGui.ExpensesContainer.Food.Value + MenuGui.ExpensesContainer.Hygiene.Value + MenuGui.ExpensesContainer.Activities.Value)
end
function InitializeMenus()
for i, v in (MenuGui.MainContainer.FoodFrame:GetChildren()) do
if v:IsA("Frame") and v.Name ~= "Template" then
v:Destroy()
end
end
for i, v in (MenuGui.MainContainer.HygieneFrame:GetChildren()) do
if v:IsA("Frame") and v.Name ~= "Template" then
v:Destroy()
end
end
-- For each model in food folder
for i, food in (game.ReplicatedStorage.Assets.Food:GetChildren()) do
local newFood = MainContainer.FoodFrame.Template:Clone()
local cost = food:GetAttribute("Cost")
newFood.Visible = true
newFood.Name = food.Name
-- handle how much of each item the player has
if not foodAmount[food] then
foodAmount[food] = 0
end
-- initialize new food button
newFood.Amount.Text = "x" .. foodAmount[food]
newFood.FoodName.Text = food.Name .. " $" .. cost
newFood.ImageLabel.Image = food:GetAttribute("Image")
newFood.Parent = MainContainer.FoodFrame
-- handle user purchase
newFood.BuyButton.MouseButton1Up:Connect(function()
if player.PlayerGui.StatsGui.Money.Value >= cost then
player.PlayerGui.StatsGui.Money.Value -= cost
foodAmount[food] += 1
newFood.Amount.Text = "x" .. foodAmount[food]
updateValue("Food", cost)
end
end)
-- handle user
newFood.UseButton.MouseButton1Up:Connect(function()
if foodAmount[food] > 0 then
-- tell server to spawn food
game.ReplicatedStorage.Remotes.GetFood:FireServer(food.Name)
foodAmount[food] -= 1
newFood.Amount.Text = "x" .. foodAmount[food]
end
end)
end
for i, item in (game.ReplicatedStorage.Assets.Hygiene:GetChildren()) do
local newItem = MainContainer.HygieneFrame.Template:Clone()
local cost = item:GetAttribute("Cost")
newItem.Visible = true
newItem.Name = item.Name
if not hygieneAmount[item] then
hygieneAmount[item] = 0
end
newItem.Amount.Text = "x" .. hygieneAmount[item]
newItem.ItemName.Text = item.Name .. " $" .. cost
newItem.ImageLabel.Image = item:GetAttribute("Image")
newItem.Parent = MainContainer.HygieneFrame
newItem.BuyButton.MouseButton1Up:Connect(function()
if player.PlayerGui.StatsGui.Money.Value >= cost then
player.PlayerGui.StatsGui.Money.Value -= cost
hygieneAmount[item] += 1
newItem.Amount.Text = "x" .. hygieneAmount[item]
updateValue("Hygiene", cost)
end
end)
newItem.UseButton.MouseButton1Up:Connect(function()
if hygieneAmount[item] > 0 then
game.ReplicatedStorage.Remotes.GetHygiene:FireServer(item.Name)
hygieneAmount[item] -= 1
newItem.Amount.Text = "x" .. hygieneAmount[item]
end
end)
end
end
game.ReplicatedStorage.Remotes.InitializePet.OnClientEvent:Connect(function()
MenuGui.Button.Visible = true
MenuGui.Kitchen.Visible = true
MenuGui.Main.Visible = true
MenuGui.Shower.Visible = true
InitializeMenus()
end)
CookingGameFrame.BuyButton.MouseButton1Up:Connect(function()
if player.PlayerGui.StatsGui.Money.Value >= 10 then
player.PlayerGui.StatsGui.Money.Value -= 10
MainContainer.ActivitiesFrame.CookingUse.Value += 1
CookingGameFrame.Amount.Text = "x" .. MainContainer.ActivitiesFrame.CookingUse.Value
updateValue("Activities", 10)
end
end)
BounceGameFrame.BuyButton.MouseButton1Up:Connect(function()
if player.PlayerGui.StatsGui.Money.Value >= 10 then
player.PlayerGui.StatsGui.Money.Value -= 10
MainContainer.ActivitiesFrame.BounceUse.Value += 1
BounceGameFrame.Amount.Text = "x" .. MainContainer.ActivitiesFrame.BounceUse.Value
updateValue("Activities", 10)
end
end)