aboutsummaryrefslogtreecommitdiff
path: root/src/lobby_menu.moon
blob: 23081dcb330d6bad119632ca2ab6bdc17040c180 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
main = require "main"
color = require "color"
ui = require "ui"
world = require "world"
char = require "char"
player = require "player"
bp = require "broadphase"
action = require "action"
room = require "room"
import World from world
import LocalPlayer from player
import LobbyRoom from room

mod = ...

mod.node = am.group!
--mod.node\append(am.sprite("data/lobby_bg.png"))
mod.node\append(am.translate(0,main.height/2)^ am.text("Join lobby...", color.fg, "center","top")\tag("join_id"))
char_selector = am.translate(0,(main.height/2)+64)
mod.loaded = false
mod.load = (id) ->
	main.world = World!
	main.world\set_room(LobbyRoom!)
	main.world\join(id)
	mod.node("join_id").text = "Lobby id:" .. id
	main.root("screen")\append(mod.node)
	touch_indicator = am.group!
	touch_cursor = am.sprite("data/cursor.png",vec4(1,1,1,1),"left","top")
	touch_loc = am.translate(0,0)^ touch_cursor
	touch_indicator\append(touch_loc)
	char_selector = ui.create_char_selector2(mod.node)
	char_right, char_left, char_text = char_selector[1], char_selector[2], char_selector[3]
	mod.buttons = {char_left, char_right}
	classes = char.class_order
	class_s = 1
	char_right.color = color.transparent
	char_left.color = color.transparent
	mod.node\action(coroutine.create(() ->
		while not main.world.client_open!
			coroutine.yield!
		char_left.color = color.white
		char_right.color = color.white
		char_text.text = "Tumbler"
		main.world\load!
		action.sync_players!
		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 + 64)
				if #col_but > 0
					touch_cursor.color = vec4(0.5,0.5,0.5,0.5)
				if #col_but > 0 and main.win\touch_began(1)
					if col_but[1] == char_left
						class_s = class_s - 1
						if class_s == 0
							class_s = #classes
					if col_but[1] == char_right
						class_s = class_s + 1
						if class_s > #classes
							class_s = 1
					char_text.text = classes[class_s]
					action.request_class_change(classes[class_s])
			else
				touch_cursor.color = vec4(0,0,0,0)
			coroutine.yield!

	))
	mod.node\append(touch_indicator)
	mod.loaded = true

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

mod