Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --@name Code.Lock
- --@author Mijyuoon
- --@include inc/sgos_sh
- --@sharedscreen
- --@moonscript
- require "inc/sgos"
- OS.Initialize!
- import Scr, Gui, Ents from OS.Libs
- --- Tab 1 (Code entry)
- TAB1_gui = CreateGUI
- __Name: "TabInput"
- Visible: false
- Dim: {
- x:64, y:134
- w:385, h:320 }
- State: 0
- AttN: 5
- Code: ""
- --- Tab 2 (Setup)
- TAB2_gui = CreateGUI
- __Name: "TabSetup"
- Visible: false
- Dim: {
- x:64, y:134
- w:385, h:320 }
- Flags: 0
- Code: ""
- --- Tab manager
- TABS_gui = CreateGUI
- __Name: "TabsBase"
- Visible: true
- Dim: {
- x:25, y:50
- w:462, h:435 }
- TabSel: 0
- StMsg: "$0"
- TABS_gui\Register!
- TAB1_gui\Register!
- TAB2_gui\Register!
- btninp = "123ABC456DEF7890>X"
- btnset = "123ABC456DEF7890<"
- tabdef = {
- { w:140, t:"INPUT", g:TAB1_gui }
- { w:140, t:"SETUP", g:TAB2_gui }
- }
- swhdef = {
- { w:120, t1:"SECURE", t2:"INPUT" }
- { w:130, t1:"DISABLE", t2:"LIMIT" }
- }
- _szx = -5
- for sw in *swhdef
- _szx += sw.w+5
- swhdef.sz = _szx/2
- canTab = (num, ... using nil) ->
- if tab = tabdef[num].g
- if tab.CanTab
- return tab\CanTab ...
- return true
- false
- getFlag = (num using nil) ->
- flgs = TAB2_gui\Get "Flags"
- (bit.band flgs, 2^(num-1)) != 0
- if CLIENT then
- import rep from string
- c_tb = Color 255,255,255
- c_tf = Color 80,180,180
- c_ub = Color 180,180,180
- c_uf = Color 40,100,100
- c_lb = Color 220,90,90
- c_bn = Color 0,100,200
- c_bg = Color 40,255,40
- c_br = Color 255,40,40
- c_by = Color 255,180,40
- c_wg = Color 50,180,50
- c_wr = Color 180,50,50
- c_wb = Color 10,80,180
- f_th = Scr.createFont "OCR A Extended", 32, 700
- f_uh = Scr.createFont "OCR A Extended", 28, 400
- f_bt = Scr.createFont "OCR A Extended", 48, 700
- f_sw = Scr.createFont "OCR A Extended", 24, 700
- icol = { c_tb, c_br, c_bg }
- imsg =
- "$L": {c: c_by, t:"SYS/ LOCKED"}
- "$A": {c: c_br, t:"NO SYS/ AUTH"}
- "$0": {c: c_tb, t:"CODE LOCK"}
- drawRectBr = (x,y,w,h,fc,bc,bw=5 using nil) ->
- Scr.drawRect x, y, w, h, fc
- Scr.drawRectOL x, y, w, h, bc, bw
- TABS_gui.OnRender = (using nil) =>
- {:x, :y, :w, :h} = @Dim
- local ts1, ts2
- tpx, num = x+20, 1
- for tk in *tabdef
- ofs, c1, c2, fn = if num == @TabSel
- ts1, ts2 = tpx, tk.w
- 0, c_tf, c_tb, f_th
- elseif not canTab num
- 20, c_uf, c_lb, f_uh
- else
- 20, c_uf, c_ub, f_uh
- drawRectBr tpx, y+ofs, tk.w, 60-ofs, c1, c2
- Scr.drawText tpx+tk.w/2, y+29+ofs/2, tk.t, 1, 1, c2, fn
- tpx += tk.w+5; num += 1
- if ts1
- drawRectBr x, y+55, w, h-55, c_tf, c_tb
- Scr.drawRect ts1+5, y+55, ts2-10, 5, c_tf
- else
- tph = (h-55)/5
- {t: txt, c: c1} = imsg[@StMsg]
- drawRectBr x, y+55, w, tph, c_uf, c_ub
- Scr.drawText x+w/2, y+55+tph/2, txt, 1, 1, c1, f_bt
- com_tab12_keypad = (bdef, yf, bk using nil) =>
- {:x, :y, :w, :h} = @Dim
- for iv = 1, 3 do for iu = 1, 6
- btxt = bdef[iu+6*(iv-1)]
- if btxt == "" then return
- bpx, bpy = x+66*(iu-1), y+yf+66*(iv-1)
- c1 = switch btxt
- when ">" then c_bg
- when "X","<" then c_br
- when "A","B","C" then c_by
- when "D","E","F" then c_by
- else c_bn
- bsz = (bk and btxt == bdef[-1]) and 120 or 54
- Scr.drawRect bpx, bpy, bsz, 54, c1
- Scr.drawText bpx+bsz/2, bpy+27, btxt, 1, 1, c_tb, f_bt
- TAB1_gui.OnRender = (using nil) =>
- {:x, :y, :w, :h} = @Dim
- com_tab12_keypad @, btninp, 134, false
- c1 = icol[@State+1] or c_tb
- txt = if msg = imsg[@Code]
- c1 = msg.c
- msg.t
- elseif getFlag 1
- "X"\rep #@Code
- else
- @Code
- drawRectBr x, y, w, 60, c_uf, c_tb, 6
- Scr.drawText x+w/2, y+30, txt, 1, 1, c1, f_bt
- if getFlag 2
- drawRectBr x, y+76, w, 42, c_wr, c_tb, 4
- else
- perc, atxt = @AttN/5, tostring @AttN
- drawRectBr x, y+76, w-48, 42, c_wb, c_tb, 4
- Scr.drawRect x+8, y+84, (w-64)*perc, 26, c_tb
- drawRectBr x+w-42, y+76, 42, 42, c_uf, c_tb, 4
- Scr.drawText x+w-21, y+96, atxt, 1, 1, c_tb, f_th
- TAB2_gui.OnRender = (using nil) =>
- {:x, :y, :w, :h} = @Dim
- com_tab12_keypad @, btnset, 74, true
- pcode = getFlag(1) and ("X"\rep #@Code) or @Code
- drawRectBr x, y, w, 60, c_uf, c_tb, 6
- Scr.drawText x+w/2, y+30, pcode, 1, 1, c_tb, f_bt
- bpx, num = x+w/2-swhdef.sz, 1
- for swh in *swhdef
- col = (bit.band(@Flags, num) > 0) and c_wg or c_wr
- drawRectBr bpx, y+274, swh.w, 56, col, c_tb
- Scr.drawText bpx+swh.w/2, y+301, swh.t1, 1, 2, c_tb, f_sw
- Scr.drawText bpx+swh.w/2, y+301, swh.t2, 1, 0, c_tb, f_sw
- bpx += swh.w+5; num *= 2
- TAB2_gui.CanTab = (using nil) =>
- if TABS_gui\Get"StMsg" == "$A"
- return false
- Ents.owner! == Ents.player!
- OS.OnRender = (using nil) ->
- Gui.dispatchRender!
- OS.Render!
- if SERVER
- import Time, Hook from OS.Libs
- OS.WireInputs "n=Clear", "n=UnAuth"
- OS.WireOutputs "n=Gra", "n=Den"
- inxy = (ck, x, y using nil) ->
- x <= ck and ck-y <= x
- tabSelect = (ix using nil) ->
- TABS_gui\Set "TabSel", ix
- for i = 1, #tabdef
- tab = tabdef[i].g
- tab\Set "Visible", ix == i
- setFailState = (sts, txt using nil) ->
- TABS_gui\Set "StMsg", txt
- cx, sts = if sts
- txt, 1
- else
- "", 0
- TAB1_gui\Set "Code", cx
- TAB1_gui\Set "State", sts
- stat_noauth = false
- funcSetAuth = (sts using stat_noauth) ->
- stat_noauth = not sts
- if not sts
- if TABS_gui\Get"TabSel" > 1
- tabSelect 0
- setFailState true, "$A"
- elseif TAB1_gui\Get"AttN" < 1
- setFailState true, "$L"
- else
- setFailState false, "$0"
- funcClearAtt = (using nil) ->
- attn = TAB1_gui\Get "AttN"
- TAB1_gui\Set "AttN", 5
- if not stat_noauth and attn == 0
- setFailState false, "$0"
- codeCheck = (act using nil) ->
- cu = TAB1_gui\Get "Code"
- cs = TAB2_gui\Get "Code"
- if #cu < 1 then return
- sts, wp = if cs == cu
- 2, "Gra"
- else
- 1, "Den"
- TAB1_gui\Set "State", sts
- if act then act (cs == cu)
- OS.WirePorts[wp] = 1
- local attn
- if cs != cu and not getFlag 2
- attn = TAB1_gui\Get"AttN"-1
- TAB1_gui\Set "AttN", attn
- if attn < 1
- setFailState true, "$L"
- Time.simple 0.5, ->
- if not attn or attn > 0
- setFailState false, "$0"
- OS.WirePorts[wp] = 0
- TABS_gui.OnInput = (ply using nil) =>
- {:x, :y, :w, :h} = @Dim
- px, py = Scr.cursorPos ply
- if not (px and py) then return true
- if inxy(py, y+25, 30) and inxy(px, x+20, w-40)
- tpx, num = x+20, 1
- for tk in *tabdef
- if inxy px, tpx+5, tk.w-10
- if not canTab num, ply then return false
- tabSelect (num != @TabSel) and num or 0
- return true
- tpx += tk.w+5; num += 1
- com_tab12_keypad = (bdef, ply, yf, bk using nil) =>
- {:x, :y, :w, :h} = @Dim
- px, py = Scr.cursorPos ply
- if inxy(px, x, w) and inxy(py, y+yf, 184)
- for iv = 1, 3 do for iu = 1, 6
- btxt = bdef[iu+6*(iv-1)]
- if btxt == "" then return nil
- bsz = (bk and btxt == bdef[-1]) and 120 or 54
- bpx, bpy = x+66*(iu-1), y+yf+66*(iv-1)
- if inxy(px, bpx, bsz) and inxy(py, bpy, 54)
- return btxt
- nil
- TAB1_gui.OnInput = (ply using nil) =>
- {:x, :y, :w, :h} = @Dim
- px, py = Scr.cursorPos ply
- if not (px and py) then return true
- if btxt = com_tab12_keypad @, btninp, ply, 134, false
- if @State > 0 then return true
- switch btxt
- when "X" then @Code = ""
- when ">" then codeCheck!
- else if #@Code < 12
- @Code ..= btxt
- return true
- TAB2_gui.OnInput = (ply using nil) =>
- {:x, :y, :w, :h} = @Dim
- px, py = Scr.cursorPos ply
- if not (px and py) then return true
- if btxt = com_tab12_keypad @, btnset, ply, 74, true
- if btxt == "<"
- @Code = @Code\sub 1, -2
- elseif #@Code < 12
- @Code ..= btxt
- return true
- sww, swx = swhdef.sz*2, x+w/2-swhdef.sz
- if inxy(px, swx, sww) and inxy(py, y+279, 46)
- bpx, num = swx, 1
- for swh in *swhdef
- if inxy(px, bpx+5, swh.w-10)
- @Flags = bit.bxor @Flags, num
- return true
- bpx += swh.w+5; num *= 2
- TAB2_gui.CanTab = (ply using nil) =>
- if stat_noauth then return false
- ply == Ents.owner!
- local use_timeout
- Hook.add "think", "idle", (using use_timeout) ->
- if not use_timeout then return
- if Time.curtime! >= use_timeout
- use_timeout = nil
- tabSelect 0
- OS.OnPlayerUse = (ply using use_timeout) ->
- Gui.dispatchInput ply
- use_timeout = Time.curtime! + 10
- OS.OnTrigger_Clear = (val using nil) ->
- if val < 1 then return
- funcClearAtt!
- OS.OnTrigger_UnAuth = (val using nil) ->
- funcSetAuth (val < 1)
- export _ENT = Ents.self!
- _ENT.is_CodeLock = true
- _ENT.funcSetAuth = wrapContext funcSetAuth
- _ENT.funcClearAtt = wrapContext funcClearAtt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement