Difference between revisions of "Lua API/ko:Interface"

From The Powder Toy
Jump to: navigation, search
(예제 코드)
 
Line 103: Line 103:
 
==== ProgressBar:progress ====
 
==== ProgressBar:progress ====
 
  number ProgressBar:progress()
 
  number ProgressBar:progress()
Returns the progress value
+
진행 상태의 값을 반환합니다.
 +
 
 +
반환 값 : 진행 상태(1~100)
  
 
  nil ProgressBar:progress(number progress)
 
  nil ProgressBar:progress(number progress)
Sets the progress value
+
진행 상태를 설정합니다.
 +
 
 +
progress : 진행 상태로 설정할 값(1~100)
  
Progress ranges from 0 to 100, but a special case of <tt>-1</tt> will change the behaviour of the progress bar to intermediate (constantly scrolling to indicate progress)
+
ProgressBar의 범위는 0부터 최대 100까지이지만, -1의 경우에는 ProgressBar의 진행 상태를 중간으로 설정하게 됩니다.
 +
(constantly scrolling to indicate progress)
  
 
==== ProgressBar:status ====
 
==== ProgressBar:status ====
 
  string ProgressBar:status()
 
  string ProgressBar:status()
Returns the progress bar status
+
ProgressBar의 상태를 반환합니다.
 +
 
 +
반환 값 : ProgressBar의 상태
  
 
  nil ProgressBar:status(string status)
 
  nil ProgressBar:status(string status)
Sets the progress bar status
+
ProgressBar의 상태를 설정합니다.
 +
 
 +
status : ProgressBar의 상태로 설정할 값(문자열)
  
 
Status is simple a text representation of the current action being performed, for example "Working" or just a percentage
 
Status is simple a text representation of the current action being performed, for example "Working" or just a percentage
 +
"상태"는 ProgressBar이 실행하는 액션 또는 현재 상태를 간단히 나타내는 텍스트입니다. 예를 들어 "작동 중"이라거나, 또는 간단히 백분율로 표시할 수도 있습니다.
  
=== Slider ===
+
=== Slider 클래스 ===
 
  Slider Slider:new(number x, number y, number width, number height, [string steps = ""])
 
  Slider Slider:new(number x, number y, number width, number height, [string steps = ""])
Extends Component, fires "onValueChanged" when the value is changed (i.e used by the user)
+
Component 클래스를 상속받으며, 값이 바뀌었을 때 "onValueChanged"를 작동시킵니다.
 +
 
 +
x, y : 순서대로 x, y 좌표(정수)
 +
 
 +
width, height : 순서대로 너비, 높이(정수)
 +
 
 +
steps : 슬라이더의 최대값(정수)
  
 
==== Slider:action ====
 
==== Slider:action ====
 
  nil Slider:onValueChanged(function(sender, value) actionListener)
 
  nil Slider:onValueChanged(function(sender, value) actionListener)
Sets the listener for slider actions
+
슬라이더의 값이 바뀌었을 때 실행할 메소드를 설정합니다.
 +
 
 +
function(sender, value) actionListener : 슬라이더의 값이 바뀌었을 때 실행할 메소드
  
 
==== Slider:value ====
 
==== Slider:value ====

Latest revision as of 12:00, 20 August 2015

- 이 페이지는 아직 완벽히 번역되지 않았습니다.

이 카테고리는 버튼, 레이블 그리고 체크박스와 같은 UI 컴포넌트를 포함합니다. 가장 우선순위가 높은 창 관리자와 입력 이벤트에 관여할 수 있습니다.

클래스

Component 클래스

추상 클래스로, 생성자가 없습니다

Component:visible

boolean Component:visible()

컴포넌트의 가시성을 반환합니다.

반환 값 : 가시성 여부(true/false)

nil Component:visible(boolean visible)

컴포넌트의 가시성을 설정합니다.

visible : 가시성 여부(true/false 또는 boolean 변수)

Component:size

number, number Component:size()

컴포넌트의 너비와 높이를 반환합니다.

반환 값 : 순서대로 너비, 높이

nil Component:size(number width, number height)

width와 height으로 컴포넌트의 크기를 설정합니다.

width : 너비(정수)

height : 높이(정수)

Component:position

number, number Component:position()

컴포넌트의 x y 좌표를 반환합니다.

반환 값 : 순서대로 x, y(모두 정수)

nil Component:position(number x, number y)

컴포넌트의 좌표를 설정합니다.

x : x 좌표(정수)

y : y 좌표(정수)

Button 클래스

Button Button:new(number x, number y, number width, number height, [string text = "", [string tooltip = ""]])

Component 클래스를 상속받으며, 클릭하였을 때 "action"을 실행합니다.

x, y : 순서대로 x, y 좌표(정수)

width, height : 순서대로 너비, 높이(정수)

text : 버튼 안에 들어갈 문자열(문자열)

tooltip : 버튼의 툴팁(문자열)

Button:action

nil Button:action(function(sender) actionListener)

버튼을 클릭했을 때의 액션을 설정합니다.

Example:

--실제로는 한글로 사용하면 안됩니다.
local newButton = Button:new(10, 10, 100, 17, "누르면 텍스트가 바뀝니다")
newButton:action(function(sender) sender:text("텍스트가 바뀌었습니다") end)
interface.addComponent(newButton)

Button:text

string Button:text()

버튼의 텍스트를 반환합니다.

반환 값 : 버튼의 텍스트

nil Button:text(string text)

버튼의 텍스트를 설정합니다.

text : 버튼의 텍스트(문자열)

Button:enabled

boolean Button:enabled()

버튼의 활성화 여부를 반환합니다.

반환 값 : 버튼의 활성화 여부

nil Button:enabled(boolean enabled)

버튼의 활성화 여부를 설정합니다.

enabled : 버튼의 활성화 여부(true/false)

ProgressBar 클래스

ProgressBar ProgressBar:new(number x, number y, number width, number height, number progress, string status)

Component 클래스를 상속받으며, 작업을 진행하는 과정을 보여주기 위해 사용됩니다.

x, y : 순서대로 x, y 좌표(정수)

width, height : 순서대로 너비, 높이(정수)

progress : ProgressBar의 길이(1~100)

status : ProgressBar의 상태(문자열)

ProgressBar:progress

number ProgressBar:progress()

진행 상태의 값을 반환합니다.

반환 값 : 진행 상태(1~100)

nil ProgressBar:progress(number progress)

진행 상태를 설정합니다.

progress : 진행 상태로 설정할 값(1~100)

ProgressBar의 범위는 0부터 최대 100까지이지만, -1의 경우에는 ProgressBar의 진행 상태를 중간으로 설정하게 됩니다. (constantly scrolling to indicate progress)

ProgressBar:status

string ProgressBar:status()

ProgressBar의 상태를 반환합니다.

반환 값 : ProgressBar의 상태

nil ProgressBar:status(string status)

ProgressBar의 상태를 설정합니다.

status : ProgressBar의 상태로 설정할 값(문자열)

Status is simple a text representation of the current action being performed, for example "Working" or just a percentage "상태"는 ProgressBar이 실행하는 액션 또는 현재 상태를 간단히 나타내는 텍스트입니다. 예를 들어 "작동 중"이라거나, 또는 간단히 백분율로 표시할 수도 있습니다.

Slider 클래스

Slider Slider:new(number x, number y, number width, number height, [string steps = ""])

Component 클래스를 상속받으며, 값이 바뀌었을 때 "onValueChanged"를 작동시킵니다.

x, y : 순서대로 x, y 좌표(정수)

width, height : 순서대로 너비, 높이(정수)

steps : 슬라이더의 최대값(정수)

Slider:action

nil Slider:onValueChanged(function(sender, value) actionListener)

슬라이더의 값이 바뀌었을 때 실행할 메소드를 설정합니다.

function(sender, value) actionListener : 슬라이더의 값이 바뀌었을 때 실행할 메소드

Slider:value

number Slider:value()

Returns the value of the slider

nil Slider:value(number value)

Sets the value of the slider

Slider:steps

number Slider:steps()

Returns the number of steps the slider has

nil Slider:steps(number steps)

Sets the number of steps for the slider

Checkbox

Checkbox Checkbox:new(number x, number y, number width, number height, [string text = ""])

Extends Component, fires "onValueChanged" when the checkbox is checked or unchecked

Checkbox:action

nil Checkbox:action(function(sender, checked) actionListener)

Sets the listener for checkbox actions

Checkbox:text

string Checkbox:text()

Returns the checkbox text

nil Checkbox:text(string text)

Sets the text of the checkbox

Checkbox:checked

boolean Checkbox:checked()

Returns the checked state of the checkbox

nil Checkbox:checked(boolean checked)

Sets the checked state of the checkbox

Label

Label Label:new(number x, number y, number width, number height, [string text = ""])

Extends Component, is a simple selectable, readonly text field

Label:text

string Label:text()

Returns the label text

nil Label:text(string text)

Sets the text of the label

Textbox

Textbox Textbox:new(number x, number y, number width, number height [, string text = "" [, string placeholder = "" ]])

Extends Component, is a text input field, the placeholder text is shown if the component is no focused and contains no text

Textbox:onTextChanged

nil Textbox:onTextChanged(function(sender) textChangedListener)

Sets the listener for text changed actions

Textbox:text

string Textbox:text()

Returns the text in the field

nil Textbox:text(string text)

Sets the text of the field

Textbox:readonly

boolean Textbox:readonly()

Returns the readonly status of the field.

nil Textbox:readonly(boolean readonly)

Sets the readonly status of the field.

Window

Window Window:new(number x, number y, number width, number height)

A modal form to display components, using -1 for either x or y values will centre the Window on that axis.

Window:addComponent

nil Window:addComponent(Component newComponent)

Add a component to the window (The component must not have already been added to another Window object)

Window:removeComponent

nil Window:removeComponent(Component newComponent)

Remove a component from the window

Methods

interface.addComponent

nil interface.addComponent(Component newComponent)

Add a component to master game window.

interface.removeComponent

nil interface.removeComponent(Component newComponent)

Remove a component from the master game window.

interface.showWindow

nil interface.showWindow(Window newWindow)

Push a Window into the top of the modal stack

interface.closeWindow

nil interface.closeWindow(Window newWindow)

Pop a Window off the top of the modal stack. If the given Window is not the top item in the stack, this will have no effect,

예제 코드

이 코드는 interface API의 몇몇 기능에 대한 예제로, 테스트를 위한 기능을 가진 다양한 컴포넌트를 포함하는 창을 띄웁니다.

-- 아래에 나오는 한글은 모두 영어로 바꿔주십시오.
-- 파우더 토이에서는 한글이 정상적으로 출력되지 않습니다.

-- 테스트 창
local testWindow = Window:new(-1, -1, 300, 200)

local currentY = 10

--레이블 예제
local testLabel = Label:new(10, currentY, (select(1, testWindow:size())/2)-20, 16, "이것은 테스트용 레이블입니다")

--버튼 예제
local buttonPresses = 1
currentY = currentY + 20
local testButton = Button:new(10, currentY, (select(1, testWindow:size())/2)-20, 16, "이것은 테스트 버튼입니다")
testButton:enabled(false)
testButton:action(
	function(sender)
		sender:text(buttonPresses .. " 번 눌렸습니다")
		buttonPresses = buttonPresses + 1
	end
)

--텍스트박스 예제
currentY = currentY + 20
local textboxInfo = Label:new(10+((select(1, testWindow:size())/2)-20), currentY, (select(1, testWindow:size())/2)-20, 16, "문자 0개")
local testTextbox = Textbox:new(10, currentY, (select(1, testWindow:size())/2)-20, 16, "", "[여기에 입력을 해주세요]")
testTextbox:onTextChanged(
	function(sender)
		textboxInfo:text("문자 "..sender:text():len().."개");
	end
)

--체크박스 예제
currentY = currentY + 20
local testCheckbox = Checkbox:new(10, currentY, (select(1, testWindow:size())/2)-20, 16, "체크되지 않음");
testCheckbox:action(
	function(sender, checked)
		if(checked) then
			sender:text("체크됨")
		else
			sender:text("체크되지 않음")
		end
		testButton:enabled(checked);
	end
)

--Progress Bar 예제
currentY = currentY + 20
local testProgressBar = ProgressBar:new(10, currentY, (select(1, testWindow:size())/2)-20, 16, 0, "슬라이더: 0");

--슬라이더 예제
currentY = currentY + 20
local testSlider = Slider:new(10, currentY, (select(1, testWindow:size())/2)-20, 16, 10);
testSlider:onValueChanged(
	function(sender, value)
		testProgressBar:progress(value * 10)
		testProgressBar:status("슬라이더: " .. value)
	end
)

-- 닫기 버튼
local closeButton = Button:new(10, select(2, testWindow:size())-26, 100, 16, "닫기")

closeButton:action(function() interface.closeWindow(testWindow) end)

testWindow:onTryExit(function() interface.closeWindow(testWindow) end) -- Allow the default exit events
testWindow:onMouseMove(
	function(x, y, dx, dy)
		testLabel:text("마우스 위치: "..x..", "..y)
	end
)

testWindow:addComponent(testLabel)
testWindow:addComponent(testButton)
testWindow:addComponent(testTextbox)
testWindow:addComponent(testCheckbox)
testWindow:addComponent(testProgressBar)
testWindow:addComponent(testSlider)
testWindow:addComponent(textboxInfo)
testWindow:addComponent(closeButton)

interface.showWindow(testWindow)