Created
October 21, 2015 08:58
-
-
Save JanneSalokoski/fd0494ef0ee0a150f94a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local debug = false | |
local new_temperature = 0 | |
sim.ambientAirTemp(20) | |
-- Test Window | |
local testWindow = Window:new(-1, -1, 150, 55) | |
local currentY = 10 | |
--Example Textbox | |
local testTextbox = Textbox:new(10, currentY, select(1, testWindow:size())-20, 16, "", "[New ambient temperature]") | |
--Example button | |
currentY = currentY + 20 | |
local buttonPresses = 1 | |
local testButton = Button:new(10, currentY, (select(1, testWindow:size())-20)/2-3, 16, "Save") | |
testButton:action( | |
function(sender) | |
new_temperature = tonumber(testTextbox:text()) | |
if debug then print(new_temperature) end | |
sim.ambientAirTemp(new_temperature) | |
print("Temperature changed into " .. new_temperature .. "C") | |
end | |
) | |
-- Close button | |
local closeButton = Button:new((select(1, testWindow:size())-20)/2+10, currentY, (select(1, testWindow:size())-20)/2, 16, "Close") | |
closeButton:action(function() interface.closeWindow(testWindow) end) | |
testWindow:onTryExit(function() interface.closeWindow(testWindow) end) -- Allow the default exit events | |
testWindow:addComponent(testButton) | |
testWindow:addComponent(testTextbox) | |
testWindow:addComponent(closeButton) | |
local function handle_keys(key, keyNum, modifier, event) | |
if debug then | |
print("Key: " .. key) | |
print("KeyNum: " .. keyNum) | |
print("Modifier: " .. modifier) | |
print("Event: " .. event) | |
end | |
if key == 't' then | |
interface.showWindow(testWindow) | |
end | |
end | |
tpt.register_keypress(handle_keys) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment