aboutsummaryrefslogtreecommitdiff
path: root/src/join_party_menu.moon
blob: 3f7d309cd30bea86df1867db15955d3ab2b2c435 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
main = require "main"
world = require "world"
color = require "color"
bp = require "broadphase"
ui = require "ui"
import World from world

mod = ...

mod.node = am.group!
mod.node\append(am.sprite("data/join.png"))
default_text = "..."
mod.load = () ->
	mod.loaded = true
	print("Loading join_party_menu")
	main.root("screen")\append(mod.node)
	mod.buttons = ui.create_join_input(mod.node)
	mod.node\append(am.translate(0,-135)^ am.text(default_text, color.fg, "center","top")\tag("join_id"))
	touch_indicator = am.group!
	touch_cursor = am.sprite("data/cursor.png",vec4(1,1,1,1),"left","top")
	backspace = ui.create_any_button(mod.node,2,2,150,-25)
	backspace.node\append(am.translate(164,-41)^ am.scale(2)^ am.text("<-", color.fg, "left","top"))
	touch_loc = am.translate(0,0)^ touch_cursor
	touch_indicator\append(touch_loc)
	mod.node\append(touch_indicator)
	print("char selector:",char_selector)
	mod.node\action(coroutine.create(() ->
		while true
			if #main.win\active_touches! > 0
				touch = main.win\touch_position(1)
				touch_cursor.color = vec4(1,1,1,1)
				touch_loc.x = touch.x
				touch_loc.y = touch.y
				col_but = bp.check(touch.x, touch.y + 40)
				n = mod.node("join_id")
				if #col_but > 0
					touch_cursor.color = vec4(0.5,0.5,0.5,0.5)
				if main.win\touch_began(1)
					for _, button in pairs(mod.buttons)
						if col_but[1] == button
							if n.text == default_text
								n.text = ""
							print("Found pressed button",button)
							n.text = n.text .. button.text
					if col_but[1] == backspace
						n.text = n.text\sub(1,string.len(n.text)-1)
				if #n.text > 5
					print("Time to join!")
					lobby = require("lobby_menu")
					table.insert(main.action_queue,{lobby.load,{n.text}})
					mod.unload!

			coroutine.yield!
	))

mod.unload = () ->
	main.root("screen")\remove(mod.node)
	for _, button in pairs(mod.buttons)
		bp.remove(button)

mod