From 0142444c83114b050231df3126649eae53edda4a Mon Sep 17 00:00:00 2001
From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54>
Date: Fri, 13 Aug 2010 14:56:48 +0000
Subject: [PATCH] improve online profile display

git-svn-id: http://svn.net-core.org/repos/t-engine4@1018 51575b47-30f0-44d4-a5cc-537603b46e54
---
 game/engine/Dialog.lua                        | 50 +++++++++++++--
 game/special/mainmenu/class/Game.lua          | 28 +++++++--
 .../special/mainmenu/dialogs/ProfileLogin.lua | 63 +++++++++++--------
 3 files changed, 103 insertions(+), 38 deletions(-)

diff --git a/game/engine/Dialog.lua b/game/engine/Dialog.lua
index 7318a4c2be..f100dbd327 100644
--- a/game/engine/Dialog.lua
+++ b/game/engine/Dialog.lua
@@ -46,7 +46,7 @@ function _M:simplePopup(title, text, fct, no_leave)
 end
 
 --- Requests a simple yes-no dialog
-function _M:yesnoPopup(title, text, fct)
+function _M:yesnoPopup(title, text, fct, yes_text, no_text)
 	local font = core.display.newFont("/data/font/Vera.ttf", 12)
 	local w, h = font:size(text)
 	local tw, th = font:size(title)
@@ -68,17 +68,57 @@ function _M:yesnoPopup(title, text, fct)
 	d.drawDialog = function(self, s)
 		s:drawColorStringCentered(self.font, text, 2, 2, self.iw - 2, 25 - 2)
 		if d.sel == 0 then
-			s:drawColorStringCentered(self.font, "Yes", 2, 25, self.iw / 2 - 2, 50 - 2, 0, 255, 255)
-			s:drawColorStringCentered(self.font, "No", 2 + self.iw / 2, 25, self.iw / 2 - 2, 50 - 2, 255, 255, 255)
+			s:drawColorStringCentered(self.font, yes_text or "Yes", 2, 25, self.iw / 2 - 2, 50 - 2, 0, 255, 255)
+			s:drawColorStringCentered(self.font, no_text or "No", 2 + self.iw / 2, 25, self.iw / 2 - 2, 50 - 2, 255, 255, 255)
 		else
-			s:drawColorStringCentered(self.font, "Yes", 2, 25, self.iw / 2 - 2, 50 - 2, 255, 255, 255)
-			s:drawColorStringCentered(self.font, "No", 2 + self.iw / 2, 25, self.iw / 2 - 2, 50 - 2, 0, 255, 255)
+			s:drawColorStringCentered(self.font, yes_text or "Yes", 2, 25, self.iw / 2 - 2, 50 - 2, 255, 255, 255)
+			s:drawColorStringCentered(self.font, no_text or "No", 2 + self.iw / 2, 25, self.iw / 2 - 2, 50 - 2, 0, 255, 255)
 		end
 	end
 	game:registerDialog(d)
 	return d
 end
 
+--- Requests a long yes-no dialog
+function _M:yesnoLongPopup(title, text, w, fct, yes_text, no_text)
+	local font = core.display.newFont("/data/font/Vera.ttf", 12)
+	local list = text:splitLines(w - 10, font)
+
+	local th = font:lineSkip()
+	local d = new(title, w + 8, th * #list + 75, nil, nil, nil, font)
+	d.sel = 0
+	d:keyCommands({},
+	{
+		ACCEPT = function() game:unregisterDialog(d) if fct then fct(d.sel == 0) end end,
+		MOVE_LEFT = "MOVE_UP",
+		MOVE_RIGHT = "MOVE_DOWN",
+		MOVE_UP = function() d.sel = 0 d.changed = true end,
+		MOVE_DOWN = function() d.sel = 1 d.changed = true end,
+	})
+	d:mouseZones{{x=2, y=0, w=d.iw, h=d.ih, fct=function(b, _, _, _, _, x, y)
+		d.sel = (x < d.iw / 2) and 0 or 1
+		d.changed = true
+		if b ~= "none" then game:unregisterDialog(d) if fct then fct(d.sel == 0) end end
+	end}}
+	d.drawDialog = function(self, s)
+		local h = 4
+		for i = 1, #list do
+			s:drawColorStringBlended(self.font, list[i], 5, h) h = h + th
+		end
+
+		if d.sel == 0 then
+			s:drawColorStringCentered(self.font, yes_text or "Yes", 2, 10 + h, self.iw / 2 - 2, 50 - 2, 0, 255, 255)
+			s:drawColorStringCentered(self.font, no_text or "No", 2 + self.iw / 2, 10 + h, self.iw / 2 - 2, 50 - 2, 255, 255, 255)
+		else
+			s:drawColorStringCentered(self.font, yes_text or "Yes", 2, 10 + h, self.iw / 2 - 2, 50 - 2, 255, 255, 255)
+			s:drawColorStringCentered(self.font, no_text or "No", 2 + self.iw / 2, 10 + h, self.iw / 2 - 2, 50 - 2, 0, 255, 255)
+		end
+		self.changed = false
+	end
+	game:registerDialog(d)
+	return d
+end
+
 --- Create a Dialog
 function _M:init(title, w, h, x, y, alpha, font)
 	self.title = title
diff --git a/game/special/mainmenu/class/Game.lua b/game/special/mainmenu/class/Game.lua
index 508ea16e7c..e2e2967c29 100644
--- a/game/special/mainmenu/class/Game.lua
+++ b/game/special/mainmenu/class/Game.lua
@@ -145,10 +145,23 @@ function _M:onQuit()
 	os.exit()
 end
 
+profile_help_text = [[#LIGHT_GREEN#T-Engine4#LAST# allows you to sync you player profile with the website #LIGHT_BLUE#http://te4.org/#LAST#
+
+This allows you to:
+* Play from several computers without having to copy unlocks and achievements.
+* Keep track of your modules progression, kill count, ...
+* Cool statistics for each module to help sharpen your gameplay style
+* Help the game developers balance and refine the game
+
+Later on you will have an online profile page you can show to people to brag.
+This is all optional, you are not forced to use this feature at all, but the developers would thank you if you did as it will
+make balancing easier.
+Online profile requires an internet connection, if not available it will wait and sync when it finds one.]]
+
 function _M:checkFirstTime()
 	if not profile.generic.firstrun then
 		profile:checkFirstRun()
-		Dialog:yesnoPopup("First run profile notification", "Do you want to create or login to an Online profile?", function(ret)
+		Dialog:yesnoLongPopup("First run profile notification", profile_help_text, 400, function(ret)
 			if ret then
 				self:selectStepOnlineProfile()
 			else
@@ -234,7 +247,7 @@ function _M:selectStepNew()
 	end
 	self:registerDialog(display_module)
 
-	self.step = ButtonList.new(self.mod_list, 10, 10, self.w * 0.24, (5 + 35) * #self.mod_list, nil, 5)	
+	self.step = ButtonList.new(self.mod_list, 10, 10, self.w * 0.24, (5 + 35) * #self.mod_list, nil, 5)
 	self.step.dialog = display_module
 	self:bindKeysToStep()
 end
@@ -402,6 +415,7 @@ function _M:selectStepProfile()
 				self:selectStepOnlineProfile()
 			end,
 		},
+--[[
 		{
 			name = "Browse Generic Profile",
 			fct = function()
@@ -414,6 +428,7 @@ function _M:selectStepProfile()
 				self:selectModuleProfile()
 			end,
 		},
+]]
 		{
 			name = "Exit",
 			fct = function()
@@ -437,13 +452,14 @@ function _M:selectStepOnlineProfile()
 		end)
 	else
 	local dialogdef = { }
-	dialogdef.name = "Profile login";
 	dialogdef.short = "Login";
 	dialogdef.fct = function(login) self:setPlayerLogin(login) end
-	Dialog:yesnoPopup("You are not registered", "Do you want to login to an existing profile?", function(ret)
+	Dialog:yesnoLongPopup("You are not registered", "You have no active online profile.\nDo you want to #LIGHT_GREEN#login#LAST# to an existing profile or #LIGHT_GREEN#create#LAST# a new one?", 400, function(ret)
+			ret = not ret
 			self.justlogin = ret
+			dialogdef.name = ret and "login" or "creation"
 			dialogdef.justlogin = ret
-			self:registerDialog(require('special.mainmenu.dialogs.ProfileLogin').new(dialogdef))
-		end)
+			self:registerDialog(require('special.mainmenu.dialogs.ProfileLogin').new(dialogdef, profile_help_text))
+		end, "Create", "Login")
 	end
 end
diff --git a/game/special/mainmenu/dialogs/ProfileLogin.lua b/game/special/mainmenu/dialogs/ProfileLogin.lua
index 95c1f5ec34..a6393c5f23 100644
--- a/game/special/mainmenu/dialogs/ProfileLogin.lua
+++ b/game/special/mainmenu/dialogs/ProfileLogin.lua
@@ -25,13 +25,16 @@ local TextBox = require "engine.TextBox"
 
 module(..., package.seeall, class.inherit(engine.Dialog))
 
-function _M:init(dialogdef)
-	engine.Dialog.init(self, "Profile Login "..dialogdef.name, 500, 400)	
+function _M:init(dialogdef, profile_help_text)
+	engine.Dialog.init(self, "Online profile "..dialogdef.name, 500, dialogdef.justlogin and 450 or 550)
+	self.profile_help_text = profile_help_text
 	self.dialogdef = dialogdef
 	self.alpha = 230
 	self.justlogin = dialogdef.justlogin
-	
-	self:keyCommands({        
+
+	self.lines = self.profile_help_text:splitLines(self.iw - 60, self.font)
+
+	self:keyCommands({
 		_DELETE = function()
 			if self.controls[self.state] and self.controls[self.state].delete then
 				self.controls[self.state]:delete()
@@ -46,15 +49,15 @@ function _M:init(dialogdef)
 		_UP = function()
 			self.state = self:changeFocus(false)
 		end,
-		_RIGHT = function()		
-			if self.state ~= "" and self.controls[self.state] and self.controls[self.state].moveRight then				
+		_RIGHT = function()
+			if self.state ~= "" and self.controls[self.state] and self.controls[self.state].moveRight then
 				self.controls[self.state]:moveRight(1)
 			else
 				self.state = self:changeFocus(true)
 			end
 		end,
 		_LEFT = function()
-			if self.state ~= "" and self.controls[self.state] and self.controls[self.state].moveLeft then				
+			if self.state ~= "" and self.controls[self.state] and self.controls[self.state].moveLeft then
 				self.controls[self.state]:moveLeft(1)
 			else
 				self.state = self:changeFocus(false)
@@ -65,10 +68,10 @@ function _M:init(dialogdef)
 				self.controls[self.state]:backSpace()
 			end
 		end,
-		__TEXTINPUT = function(c)			
+		__TEXTINPUT = function(c)
 			if self.state ~= "" and self.controls[self.state] and self.controls[self.state].type=="TextBox" then
 				self.controls[self.state]:textInput(c)
-			end			
+			end
 		end,
 		_RETURN = function()
 			if self.state ~= "" and self.controls[self.state] and self.controls[self.state].type=="Button" then
@@ -82,46 +85,52 @@ function _M:init(dialogdef)
 		end
 	})
 	self:setMouseHandling()
-	self:addControl(Button.new("ok", "Ok", 50, 330, 50, 30, self, self.font, function() self:okclick() end))
-	self:addControl(Button.new("cancel", "Canel", 400, 330, 50, 30, self, self.font, function() self:cancelclick() end))
-	self:addControl(TextBox.new({name="login",title="You Login:",min=2, max=25, x=30, y=30, w=350, h=30}, self, self.font, "login name"))
-	self:addControl(TextBox.new({name="pass",title="Password:",min=2, max=25, x=30, y=70, w=350, h=30}, self, self.font, "password"))
+
+	local basey = #self.lines * self.font:lineSkip() + 25
+
+	self:addControl(TextBox.new({name="login",title="Login:",min=2, max=25, x=30, y=basey + 5, w=350, h=30}, self, self.font, "login name"))
+	self:addControl(TextBox.new({name="pass",title ="Password:",min=2, max=25, x=30, y=basey + 45, w=350, h=30}, self, self.font, "password"))
 	if not self.justlogin then
-		self:addControl(TextBox.new({name="email",title="Email Address:",min=2, max=25, x=30, y=110, w=350, h=30}, self, self.font, "email address"))
-		self:addControl(TextBox.new({name="name",title="Name:",min=2, max=25, x=30, y=150, w=350, h=30}, self, self.font, "name"))
+		self:addControl(TextBox.new({name="email",title="Email Address:",min=2, max=25, x=30, y=basey + 85, w=350, h=30}, self, self.font, "email address"))
+		self:addControl(TextBox.new({name="name",title="Name:",min=2, max=25, x=30, y=basey + 125, w=350, h=30}, self, self.font, "name"))
+		self:addControl(Button.new("ok", "Ok", 50, basey + 165, 50, 30, self, self.font, function() self:okclick() end))
+		self:addControl(Button.new("cancel", "Canel", 400, basey + 165, 50, 30, self, self.font, function() self:cancelclick() end))
+	else
+		self:addControl(Button.new("ok", "Ok", 50, basey + 85, 50, 30, self, self.font, function() self:okclick() end))
+		self:addControl(Button.new("cancel", "Canel", 400, basey + 85, 50, 30, self, self.font, function() self:cancelclick() end))
 	end
-	self:focusControl("login")	
+	self:focusControl("login")
 end
 
 
 function _M:okclick()
-	game:unregisterDialog(self) 
-	results = self:databind()	
+	game:unregisterDialog(self)
+	local results = self:databind()
 	game:selectStepProfile()
 	game:createProfile(results)
 end
 
 function _M:cancelclick()
-	game:unregisterDialog(self) 
+	game:unregisterDialog(self)
 	game:selectStepProfile()
 end
 
 function _M:setMouseHandling()
 	self.old_mouse = engine.Mouse.current
 	self.mouse = engine.Mouse.new()
-	self.mouse:setCurrent()	
+	self.mouse:setCurrent()
 	game.mouse = self.mouse
 end
 
 
-function _M:drawDialog(s, w, h)    	
-	local y = 200
+function _M:drawDialog(s, w, h)
+	local y = 5
 	local x = 30
-	lines = { "What's the online profile for?", "* Playing from several computers without copying and worries.", "* Keep track of your modules progression.", "* For Example Kill Count, Unlockables unlocked and achievments in TOME", "* Unlimited possibilites for migrating your module information.", "* Cool statistics for each module to help sharpen your gameplay style", "* Who doesn't like statistics?"}
-	for i = 1, #lines do
-		r, g, b = s:drawColorStringBlended(self.font, lines[i], x, y + i * self.font:lineSkip(), r, g, b)		
-	end	
-	self:drawControls(s)	
+	local r, g, b
+	for i = 1, #self.lines do
+		r, g, b = s:drawColorStringBlended(self.font, self.lines[i], x, y + i * self.font:lineSkip(), r, g, b)
+	end
+	self:drawControls(s)
 end
 
 function _M:close()
-- 
GitLab