Advertisement
Guest User

Untitled

a guest
Feb 14th, 2014
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.35 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.         else
  67.             -- change text to "Hit!"
  68.             self:Menu(self.context, "Start", 10, 10)
  69.             self:Menu(self.context, "Character", 10, 200)
  70.             self:Menu(self.context, "Option 2", 10, 300)
  71.             self:Menu(self.context, "Option 3", 10, 400)
  72.            
  73.             if self.options1 == 1 then
  74.                 self:Menu(self.context, "Strength", 250, 200)
  75.                 self:Menu(self.context, "Dexterity", 250, 240)
  76.                 self:Menu(self.context, "Intelligence", 250, 280)
  77.             end
  78.             if self.menustrength == 1 then
  79.                 self:Menu(self.context, "Lumberjacking", 500, 200)
  80.                 self:Menu(self.context, "Mining", 500, 240)
  81.             end
  82.             if self.menudexterity == 1 then
  83.                 self:Menu(self.context, "Hunting", 500, 200)
  84.                 self:Menu(self.context, "Trapmaking", 500, 240)
  85.             end
  86.             if self.menuintelligence == 1 then
  87.                 self:Menu(self.context, "Architecture", 500, 200)
  88.             end
  89.         end
  90.  
  91.         -- show another button
  92.         self:Menu(self.context, "Exit", 10, self.windowHeight-100)
  93.         -- draw Inventory
  94.         self.context:SetBlendMode(Blend.Solid)
  95.     end
  96. end
  97.  
  98. -- define "Menu" function
  99. function Script:Menu(context, label, x, y)
  100.     -- grab actual mouse position within the window
  101.     local mousepos = self.window:GetMousePosition()
  102.     -- store the mouse X and Y coordinates
  103.     local mx = mousepos.x
  104.     local my = mousepos.y
  105.  
  106.     -- show the mouse Cursor
  107.     --self.window:ShowMouse()
  108.    
  109.     -- draw the button image, with the image stored in "button_pressed if the mouse hovers over it"
  110.     if mx >= x and my >= y and mx <= x+200 and my <= y+35 then
  111.         self.context:DrawImage(self.button_pressed, x, y, 200, 35)
  112.         self.context:DrawText(label, x+5, y+3)
  113.     else
  114.         -- draw the image stored in "button"
  115.         self.context:DrawImage(self.button, x, y, 200, 35)
  116.         self.context:DrawText(label, x+5, y+3)
  117.     end
  118.     -- check if someone clicked within the button "Start", if yes switch state of "mouseStart" between 1 and 0
  119.     if mx >= x and my >= y and mx <= x+200 and my <= y+35 and self.window:MouseHit(Key.LButton) then   
  120.         if label == "Start" then
  121.             if self.mouseStart == 0 then
  122.                 self.mouseStart = 1
  123.             else
  124.                 self.mouseStart = 0
  125.                 local temp = self.window:GetMousePosition()
  126.                 self.oldmousex = temp.x
  127.                 self.oldmousey = temp.y
  128.             end
  129.             elseif label == "Exit" then
  130.                 App:ExitGame()
  131.             end
  132.         if label == "Character" then
  133.             if self.options1 == 0 then
  134.                 self.options1 = 1
  135.             else
  136.                 self.options1 = 0
  137.                 self.menustrength = 0
  138.                 self.menudexterity = 0
  139.                 self.menuintelligence = 0
  140.             end
  141.         end
  142.         if label == "Option 2" then
  143.             if self.options2 == 0 then
  144.                 self.options2 = 1
  145.             else
  146.                 self.options2 = 0
  147.             end
  148.         end
  149.         if label == "Option 3" then
  150.             if self.options3 == 0 then
  151.                 self.options3 = 1
  152.             else
  153.                 self.options3 = 0
  154.             end
  155.         end
  156.         if label == "Strength" then
  157.             if self.menustrength == 0 then
  158.                 self.menustrength = 1
  159.                 self.menudexterity = 0
  160.                 self.menuintelligence = 0
  161.             else
  162.                 self.menustrength = 0
  163.             end
  164.         end
  165.         if label == "Dexterity" then
  166.             if self.menudexterity == 0 then
  167.                 self.menudexterity = 1
  168.                 self.menustrength = 0
  169.                 self.menuintelligence = 0
  170.             else
  171.                 self.menudexterity = 0
  172.             end
  173.         end
  174.         if label == "Intelligence" then
  175.             if self.menuintelligence == 0 then
  176.                 self.menuintelligence = 1
  177.                 self.menustrength = 0
  178.                 self.menudexterity = 0
  179.             else
  180.                 self.menuintelligence = 0
  181.             end
  182.         end
  183.     end
  184. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement