Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Script.player = nil --entity "Player"
- function Script:Start()
- self.item01 = { Name="Tree", Texture="Materials/Developer/GreenGrid.tex" }
- self.item02 = { Name="Rock", Texture="Materials/Developer/GreyGrid.tex" }
- self.item03 = { Name="Water", Texture="Materials/Developer/BlueGrid.tex" }
- self.items = { self.item01, self.item02, self.item03 }
- self.Items = items
- self.window = Window:GetCurrent()
- self.windowWidth = self.window:GetWidth()
- self.windowHeight = self.window:GetHeight()
- gamemenuopen = 0
- self.mouseStart = 0
- self.options1 = 0
- self.options2 = 0
- self.options3 = 0
- self.menustrength = 0
- self.menudexterity = 0
- self.menuintelligence = 0
- self.mouseInv = 0
- self.oldmousex = 10
- self.oldmousey = 10
- self.context = Context:GetCurrent()
- -- load textures to be shown as "Button"
- self.button = Texture:Load("Materials/HUD/Btn_not_pressed.tex")
- self.button_pressed = Texture:Load("Materials/HUD/Btn_pressed.tex")
- self.inv_grid = Texture:Load("Materials/HUD/Inventory.tex")
- self.inv_grid_hover = Texture:Load("Materials/HUD/Inventory_hover.tex")
- -- change font and size for those buttons
- local font = Font:Load("Materials/Fonts/arial.ttf", 20)
- self.context:SetFont(font)
- font:Release()
- end
- --This function will be called after the world is rendered, before the screen is refreshed.
- --Use this to perform any 2D drawing you want the entity to display.
- function Script:PostRender(context)
- local mousepos = self.window:GetMousePosition()
- local mx = mousepos.x
- local my = mousepos.y
- -- check if Key "T" is hit, if yes switch state of variable "gamemenuopen"
- if self.window:KeyHit(Key.T) then
- if gamemenuopen == 0 then
- gamemenuopen = 1
- else
- gamemenuopen = 0
- end
- end
- if gamemenuopen == 0 then
- App.window:HideMouse()
- else
- App.window:ShowMouse()
- end
- -- if menu is open ...
- if gamemenuopen == 1 then
- self.context:SetColor(1,1,1)
- self.context:SetBlendMode(Blend.Alpha)
- -- if mouse cursor is within the red button named "Start"
- if self.mouseStart == 0 then
- self:Menu(self.context, "Start", 10, 10)
- self:ButtonClick(self.context, "Start", 10, 10)
- else
- -- change text to "Hit!"
- self:Menu(self.context, "Start", 10, 10)
- self:ButtonClick(self.context, "Start", 10, 10)
- self:Menu(self.context, "Character", 10, 200)
- self:ButtonClick(self.context, "Character", 10, 200)
- self:Menu(self.context, "Option 2", 10, 300)
- self:ButtonClick(self.context, "Option 2", 10, 300)
- self:Menu(self.context, "Option 3", 10, 400)
- self:ButtonClick(self.context, "Option 3", 10, 400)
- if self.options1 == 1 then
- self:Menu(self.context, "Strength", 250, 200)
- self:ButtonClick(self.context, "Strength", 250, 200)
- self:Menu(self.context, "Dexterity", 250, 240)
- self:ButtonClick(self.context, "Dexterity", 250, 240)
- self:Menu(self.context, "Intelligence", 250, 280)
- self:ButtonClick(self.context, "Intelligence", 250, 280)
- end
- if self.menustrength == 1 then
- self:Menu(self.context, "Lumberjacking", 500, 200)
- self:ButtonClick(self.context, "Lumberjacking", 500, 200)
- self:Menu(self.context, "Mining", 500, 240)
- self:ButtonClick(self.context, "Mining", 500, 240)
- end
- if self.menudexterity == 1 then
- self:Menu(self.context, "Hunting", 500, 200)
- self:ButtonClick(self.context, "Hunting", 500, 200)
- self:Menu(self.context, "Trapmaking", 500, 240)
- self:ButtonClick(self.context, "Trapmaking", 500, 240)
- end
- if self.menuintelligence == 1 then
- self:Menu(self.context, "Architecture", 500, 200)
- self:ButtonClick(self.context, "Architecture", 500, 200)
- end
- end
- -- show another button
- self:Menu(self.context, "Exit", 10, self.windowHeight-100)
- self:ButtonClick(self.context, "Exit", 10, self.windowHeight-100)
- -- draw Inventory
- self.context:SetBlendMode(Blend.Solid)
- end
- end
- -- define "Menu" function
- function Script:Menu(context, label, x, y)
- -- grab actual mouse position within the window
- local mousepos = self.window:GetMousePosition()
- -- store the mouse X and Y coordinates
- local mx = mousepos.x
- local my = mousepos.y
- -- draw the button image, with the image stored in "button_pressed if the mouse hovers over it"
- if mx >= x and my >= y and mx <= x+200 and my <= y+35 then
- self.context:DrawImage(self.button_pressed, x, y, 200, 35)
- self.context:DrawText(label, x+5, y+3)
- else
- -- draw the image stored in "button"
- self.context:DrawImage(self.button, x, y, 200, 35)
- self.context:DrawText(label, x+5, y+3)
- end
- end
- function Script:ButtonClick(context, label, x, y)
- local mousepos = self.window:GetMousePosition()
- local mx = mousepos.x
- local my = mousepos.y
- if mx >= x and my >= y and mx <= x+200 and my <= y+35 and self.window:MouseHit(Key.LButton) then
- if label == "Start" then
- if self.mouseStart == 0 then
- self.mouseStart = 1
- else
- self.mouseStart = 0
- local temp = self.window:GetMousePosition()
- self.oldmousex = temp.x
- self.oldmousey = temp.y
- end
- elseif label == "Exit" then
- App:ExitGame()
- end
- if label == "Character" then
- if self.options1 == 0 then
- self.options1 = 1
- else
- self.options1 = 0
- self.menustrength = 0
- self.menudexterity = 0
- self.menuintelligence = 0
- end
- end
- if label == "Option 2" then
- if self.options2 == 0 then
- self.options2 = 1
- else
- self.options2 = 0
- end
- end
- if label == "Option 3" then
- if self.options3 == 0 then
- self.options3 = 1
- else
- self.options3 = 0
- end
- end
- if label == "Strength" then
- if self.menustrength == 0 then
- self.menustrength = 1
- self.menudexterity = 0
- self.menuintelligence = 0
- else
- self.menustrength = 0
- end
- end
- if label == "Dexterity" then
- if self.menudexterity == 0 then
- self.menudexterity = 1
- self.menustrength = 0
- self.menuintelligence = 0
- else
- self.menudexterity = 0
- end
- end
- if label == "Intelligence" then
- if self.menuintelligence == 0 then
- self.menuintelligence = 1
- self.menustrength = 0
- self.menudexterity = 0
- else
- self.menuintelligence = 0
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement