gui: team changes now handled in widget listeners

This commit is contained in:
triplefox 2012-12-20 21:47:28 -08:00
parent 8ada5fc755
commit 1503d40aa4
2 changed files with 49 additions and 45 deletions

View File

@ -383,10 +383,6 @@ typing_msg = nil
show_scores = false show_scores = false
quitting = false
team_change = false
-- load images -- load images
img_crosshair = client.img_load("pkg/base/gfx/crosshair.tga") img_crosshair = client.img_load("pkg/base/gfx/crosshair.tga")
@ -870,25 +866,7 @@ function h_key(key, state, modif)
elseif key == BTSK_SCORES then elseif key == BTSK_SCORES then
show_scores = state show_scores = state
elseif state then elseif state then
if team_change then if key == BTSK_DEBUG then
local team
if key == BTSK_TOOL1 then
team = 0
team_change = false
elseif key == BTSK_TOOL2 then
team = 1
team_change = false
end
if key == BTSK_QUIT then
team_change = false
else
local plr
plr = players[players.current]
if plr ~= nil and team ~= nil and team ~= plr.team then
common.net_send(nil, common.net_pack("Bbbz", 0x11, team, WPN_RIFLE, plr.name or ""))
end
end
elseif key == BTSK_DEBUG then
debug_enabled = not debug_enabled debug_enabled = not debug_enabled
elseif key == SDLK_F10 then elseif key == SDLK_F10 then
local s = "clsave/"..common.base_dir.."/vol/lastsav.icemap" local s = "clsave/"..common.base_dir.."/vol/lastsav.icemap"
@ -957,8 +935,6 @@ function h_key(key, state, modif)
common.net_send(nil, common.net_pack("BBBBB", common.net_send(nil, common.net_pack("BBBBB",
0x18, 0x00, 0x18, 0x00,
plr.blk_color[1],plr.blk_color[2],plr.blk_color[3])) plr.blk_color[1],plr.blk_color[2],plr.blk_color[3]))
elseif key == BTSK_TEAM then
team_change = true
end end
end end
end end

View File

@ -1097,6 +1097,7 @@ function new_player(settings)
bone_rotate(0) bone_rotate(0)
--TODO: use the actual yes/no key mappings
this.quit_msg = scene.textfield{wordwrap=false, color=0xFFFF3232, font=font_large, this.quit_msg = scene.textfield{wordwrap=false, color=0xFFFF3232, font=font_large,
text="Are you sure? (Y/N)", x = w/2, y = h/4, align_x = 0.5, align_y = 0.5, text="Are you sure? (Y/N)", x = w/2, y = h/4, align_x = 0.5, align_y = 0.5,
visible=false} visible=false}
@ -1104,32 +1105,59 @@ function new_player(settings)
--TODO: update bluetext/greentext with the actual keys (if changed in controls.json) --TODO: update bluetext/greentext with the actual keys (if changed in controls.json)
this.team_change_msg_b = scene.textfield{wordwrap=false, color=0xFF0000FF, font=font_large, this.team_change_msg_b = scene.textfield{wordwrap=false, color=0xFF0000FF, font=font_large,
text="Press 1 to join Blue", x = w/2, y = h/4, align_x = 0.5, align_y = 0.5, text="Press 1 to join Blue", x = w/2, y = h/4, align_x = 0.5, align_y = 0.5}
visible=false}
this.team_change_msg_g = scene.textfield{wordwrap=false, color=0xFF00FF00, font=font_large, this.team_change_msg_g = scene.textfield{wordwrap=false, color=0xFF00FF00, font=font_large,
text="Press 2 to join Green", x = w/2, y = h/4 + 40, align_x = 0.5, align_y = 0.5, text="Press 2 to join Green", x = w/2, y = h/4 + 40, align_x = 0.5, align_y = 0.5}
visible=false} this.team_change = scene.display_object{visible=false}
scene.root.add_child(this.team_change_msg_b) this.team_change.add_child(this.team_change_msg_b)
scene.root.add_child(this.team_change_msg_g) this.team_change.add_child(this.team_change_msg_g)
scene.root.add_child(this.team_change)
local function update_viz(dT) local function menus_visible()
this.team_change_msg_b.visible = team_change return this.quit_msg.visible or this.team_change.visible
this.team_change_msg_g.visible = team_change
end end
local function can_quit(options)
if this.quit_msg.visible and options.state then local function quit_events(options)
if options.state then
if this.quit_msg.visible then
if options.key == BTSK_YES then if options.key == BTSK_YES then
-- TODO: clean up -- TODO: clean up
client.hook_tick = nil client.hook_tick = nil
elseif options.key == BTSK_NO then elseif options.key == BTSK_NO then
this.quit_msg.visible = false this.quit_msg.visible = false
end end
elseif options.key == BTSK_QUIT then elseif options.key == BTSK_QUIT and not menus_visible() then
this.quit_msg.visible = true this.quit_msg.visible = true
end end
end end
this.quit_msg.add_listener(GE_DELTA_TIME, update_viz) end
this.quit_msg.add_listener(GE_BUTTON, can_quit) local function teamchange_events(options)
local viz = this.team_change.visible
if options.state then
if viz then
local team
if options.key == BTSK_TOOL1 then viz = false; team = 0
elseif options.key == BTSK_TOOL2 then viz = false; team = 1
elseif (options.key == BTSK_QUIT or options.key == BTSK_TEAM)
then viz = false
end
local plr
plr = players[players.current]
if plr ~= nil and team ~= nil and team ~= plr.team then
common.net_send(nil, common.net_pack("Bbbz", 0x11, team, WPN_RIFLE, plr.name or ""))
end
elseif options.key == BTSK_TEAM and not menus_visible() then
viz = true
end
end
this.team_change.visible = viz
end
this.quit_msg.add_listener(GE_BUTTON, quit_events)
this.team_change.add_listener(GE_BUTTON, teamchange_events)
this.scene = scene this.scene = scene
end end