Advertisement
Guest User

Untitled

a guest
Feb 15th, 2014
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.14 KB | None | 0 0
  1. Script.player = nil --entity "Player"
  2.  
  3. function Script:Start()
  4.     self.item01 = { Name="Tree", Texture="Materials/Developer/GreenGrid.tex" }
  5.     self.item02 = { Name="Rock", Texture="Materials/Developer/GreyGrid.tex" }
  6.     self.item03 = { Name="Water", Texture="Materials/Developer/BlueGrid.tex" }
  7.  
  8.     self.items = { self.item01, self.item02, self.item03 }
  9.     self.Items = items
  10.  
  11.     self.window = Window:GetCurrent()
  12.     self.windowWidth = self.window:GetWidth()
  13.     self.windowHeight = self.window:GetHeight()
  14.     gamemenuopen = 0
  15.     self.mouseStart = 0
  16.     self.options1 = 0
  17.     self.options2 = 0
  18.     self.options3 = 0
  19.     self.menustrength = 0
  20.     self.menudexterity = 0
  21.     self.menuintelligence = 0
  22.     self.mouseInv = 0
  23.     self.oldmousex = 10
  24.     self.oldmousey = 10
  25.     self.context = Context:GetCurrent()
  26.  
  27.     -- load textures to be shown as "Button"
  28.     self.button = Texture:Load("Materials/HUD/Btn_not_pressed.tex")
  29.     self.button_pressed = Texture:Load("Materials/HUD/Btn_pressed.tex")
  30.     self.inv_grid = Texture:Load("Materials/HUD/Inventory.tex")
  31.     self.inv_grid_hover = Texture:Load("Materials/HUD/Inventory_hover.tex")
  32.  
  33.     -- change font and size for those buttons
  34.     local font = Font:Load("Materials/Fonts/arial.ttf", 20)
  35.     self.context:SetFont(font)
  36.     font:Release()
  37. end
  38.  
  39. --This function will be called after the world is rendered, before the screen is refreshed.
  40. --Use this to perform any 2D drawing you want the entity to display.
  41. function Script:PostRender(context)
  42.     local mousepos = self.window:GetMousePosition()
  43.     local mx = mousepos.x
  44.     local my = mousepos.y
  45.  
  46.     -- check if Key "T" is hit, if yes switch state of variable "gamemenuopen"
  47.     if self.window:KeyHit(Key.T) then
  48.         if gamemenuopen == 0 then
  49.             gamemenuopen = 1
  50.         else
  51.             gamemenuopen = 0
  52.         end
  53.     end
  54.     if gamemenuopen == 0 then
  55.         App.window:HideMouse()
  56.     else
  57.         App.window:ShowMouse()
  58.     end
  59.     -- if menu is open  ...
  60.     if gamemenuopen == 1 then
  61.         self.context:SetColor(1,1,1)
  62.         self.context:SetBlendMode(Blend.Alpha)
  63.         -- if mouse cursor is within the red button named "Start"
  64.         if self.mouseStart == 0 then
  65.             self:Menu(self.context, "Start", 10, 10)
  66.             self:ButtonClick(self.context, "Start", 10, 10)
  67.         else
  68.             -- change text to "Hit!"
  69.             self:Menu(self.context, "Start", 10, 10)
  70.             self:ButtonClick(self.context, "Start", 10, 10)
  71.             self:Menu(self.context, "Character", 10, 200)
  72.             self:ButtonClick(self.context, "Character", 10, 200)
  73.             self:Menu(self.context, "Option 2", 10, 300)
  74.             self:ButtonClick(self.context, "Option 2", 10, 300)
  75.             self:Menu(self.context, "Option 3", 10, 400)
  76.             self:ButtonClick(self.context, "Option 3", 10, 400)
  77.            
  78.             if self.options1 == 1 then
  79.                 self:Menu(self.context, "Strength", 250, 200)
  80.                 self:ButtonClick(self.context, "Strength", 250, 200)
  81.                 self:Menu(self.context, "Dexterity", 250, 240)
  82.                 self:ButtonClick(self.context, "Dexterity", 250, 240)
  83.                 self:Menu(self.context, "Intelligence", 250, 280)
  84.                 self:ButtonClick(self.context, "Intelligence", 250, 280)
  85.             end
  86.             if self.menustrength == 1 then
  87.                 self:Menu(self.context, "Lumberjacking", 500, 200)
  88.                 self:ButtonClick(self.context, "Lumberjacking", 500, 200)
  89.                 self:Menu(self.context, "Mining", 500, 240)
  90.                 self:ButtonClick(self.context, "Mining", 500, 240)
  91.             end
  92.             if self.menudexterity == 1 then
  93.                 self:Menu(self.context, "Hunting", 500, 200)
  94.                 self:ButtonClick(self.context, "Hunting", 500, 200)
  95.                 self:Menu(self.context, "Trapmaking", 500, 240)
  96.                 self:ButtonClick(self.context, "Trapmaking", 500, 240)
  97.             end
  98.             if self.menuintelligence == 1 then
  99.                 self:Menu(self.context, "Architecture", 500, 200)
  100.                 self:ButtonClick(self.context, "Architecture", 500, 200)
  101.             end
  102.         end
  103.         -- show another button
  104.         self:Menu(self.context, "Exit", 10, self.windowHeight-100)
  105.         self:ButtonClick(self.context, "Exit", 10, self.windowHeight-100)
  106.         -- draw Inventory
  107.         self.context:SetBlendMode(Blend.Solid)
  108.     end
  109. end
  110.  
  111. -- define "Menu" function
  112. function Script:Menu(context, label, x, y)
  113.     -- grab actual mouse position within the window
  114.     local mousepos = self.window:GetMousePosition()
  115.     -- store the mouse X and Y coordinates
  116.     local mx = mousepos.x
  117.     local my = mousepos.y
  118.  
  119.     -- draw the button image, with the image stored in "button_pressed if the mouse hovers over it"
  120.     if mx >= x and my >= y and mx <= x+200 and my <= y+35 then
  121.         self.context:DrawImage(self.button_pressed, x, y, 200, 35)
  122.         self.context:DrawText(label, x+5, y+3)
  123.     else
  124.         -- draw the image stored in "button"
  125.         self.context:DrawImage(self.button, x, y, 200, 35)
  126.         self.context:DrawText(label, x+5, y+3)
  127.     end
  128. end
  129.  
  130.  
  131. function Script:ButtonClick(context, label, x, y)
  132.     local mousepos = self.window:GetMousePosition()
  133.     local mx = mousepos.x
  134.     local my = mousepos.y
  135.  
  136.     if mx >= x and my >= y and mx <= x+200 and my <= y+35 and self.window:MouseHit(Key.LButton) then   
  137.         if label == "Start" then
  138.             if self.mouseStart == 0 then
  139.                 self.mouseStart = 1
  140.             else
  141.                 self.mouseStart = 0
  142.                 local temp = self.window:GetMousePosition()
  143.                 self.oldmousex = temp.x
  144.                 self.oldmousey = temp.y
  145.             end
  146.             elseif label == "Exit" then
  147.                 App:ExitGame()
  148.             end
  149.         if label == "Character" then
  150.             if self.options1 == 0 then
  151.                 self.options1 = 1
  152.             else
  153.                 self.options1 = 0
  154.                 self.menustrength = 0
  155.                 self.menudexterity = 0
  156.                 self.menuintelligence = 0
  157.             end
  158.         end
  159.         if label == "Option 2" then
  160.             if self.options2 == 0 then
  161.                 self.options2 = 1
  162.             else
  163.                 self.options2 = 0
  164.             end
  165.         end
  166.         if label == "Option 3" then
  167.             if self.options3 == 0 then
  168.                 self.options3 = 1
  169.             else
  170.                 self.options3 = 0
  171.             end
  172.         end
  173.         if label == "Strength" then
  174.             if self.menustrength == 0 then
  175.                 self.menustrength = 1
  176.                 self.menudexterity = 0
  177.                 self.menuintelligence = 0
  178.             else
  179.                 self.menustrength = 0
  180.             end
  181.         end
  182.         if label == "Dexterity" then
  183.             if self.menudexterity == 0 then
  184.                 self.menudexterity = 1
  185.                 self.menustrength = 0
  186.                 self.menuintelligence = 0
  187.             else
  188.                 self.menudexterity = 0
  189.             end
  190.         end
  191.         if label == "Intelligence" then
  192.             if self.menuintelligence == 0 then
  193.                 self.menuintelligence = 1
  194.                 self.menustrength = 0
  195.                 self.menudexterity = 0
  196.             else
  197.                 self.menuintelligence = 0
  198.             end
  199.         end
  200.     end
  201. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement