Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Progark gruppe 3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tobias Ingebrigt Ørstad
Progark gruppe 3
Commits
0825d354
Commit
0825d354
authored
5 years ago
by
Turid Cecilie Dahl
Browse files
Options
Downloads
Patches
Plain Diff
#90
Adds create user page + removes animation in loginstate
parent
76c5d7c7
No related branches found
No related tags found
1 merge request
!89
Resolve "Small frontend stuff"
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/core/src/com/gameware/game/states/LoginState.java
+99
-30
99 additions, 30 deletions
frontend/core/src/com/gameware/game/states/LoginState.java
with
99 additions
and
30 deletions
frontend/core/src/com/gameware/game/states/LoginState.java
+
99
−
30
View file @
0825d354
...
@@ -23,7 +23,8 @@ public class LoginState extends State {
...
@@ -23,7 +23,8 @@ public class LoginState extends State {
// Labels
// Labels
private
final
Label
titleLabel
=
new
Label
(
"GameWare"
,
skin
,
"big"
);
private
final
Label
titleLabel
=
new
Label
(
"GameWare"
,
skin
,
"big"
);
private
final
Label
subHeadLabel
=
new
Label
(
"Log in / Create User"
,
skin
,
"big"
);
private
final
Label
subHeadLabelLogIn
=
new
Label
(
"Log in"
,
skin
,
"big"
);
private
final
Label
subHeadLabelCreateUser
=
new
Label
(
"Create User"
,
skin
,
"big"
);
private
Label
errorLabel
=
new
Label
(
""
,
skin
,
"error"
);
private
Label
errorLabel
=
new
Label
(
""
,
skin
,
"error"
);
// Input fields
// Input fields
...
@@ -31,22 +32,23 @@ public class LoginState extends State {
...
@@ -31,22 +32,23 @@ public class LoginState extends State {
private
TextField
usernameInputField
;
private
TextField
usernameInputField
;
private
String
passwordInputText
=
"Password"
;
private
String
passwordInputText
=
"Password"
;
private
TextField
passwordInputField
;
private
TextField
passwordInputField
;
private
String
confirmPasswordInputText
=
"Confirm password"
;
private
TextField
confirmPasswordInputField
;
private
final
char
passwordCharacter
=
'*'
;
private
final
char
passwordCharacter
=
'*'
;
private
final
int
inputFieldWidth
=
Gdx
.
graphics
.
getWidth
()/
2
;
private
final
int
inputFieldWidth
=
Gdx
.
graphics
.
getWidth
()/
2
;
private
final
int
inputFieldHeight
=
Gdx
.
graphics
.
getHeight
()/
15
;
private
final
int
inputFieldHeight
=
Gdx
.
graphics
.
getHeight
()/
15
;
// Button texts
// Button texts
private
final
String
loginBtnText
=
"Log in"
;
private
final
String
loginBtnText
=
"Log in"
;
private
final
String
createUserText
=
"Create User"
;
private
final
String
signUpBtnText
=
"Sign Up"
;
private
final
String
signUpBtnText
=
"Sign Up"
;
private
final
String
backText
=
"Back"
;
// Feedback texts
// Feedback texts
private
final
String
wrongLoginText
=
"User not found"
;
private
final
String
wrongLoginText
=
"User not found"
;
private
final
String
takenUsernameText
=
"Username already taken"
;
private
final
String
takenUsernameText
=
"Username already taken"
;
private
final
String
ioExceptionText
=
"Something went wrong with query"
;
private
final
String
ioExceptionText
=
"Something went wrong with query"
;
private
final
String
passwordNotMatchingText
=
"Passwords do not match"
;
// Feedback label animation
private
final
int
animationDelay
=
2
;
private
final
int
animationDuration
=
1
;
// Loading text
// Loading text
private
LoadingText
loadingText
=
new
LoadingText
();
private
LoadingText
loadingText
=
new
LoadingText
();
...
@@ -54,6 +56,10 @@ public class LoginState extends State {
...
@@ -54,6 +56,10 @@ public class LoginState extends State {
private
boolean
signUpBtnClicked
=
false
;
private
boolean
signUpBtnClicked
=
false
;
// Variables
private
int
page
=
0
;
public
LoginState
(
GameStateManager
gsm
)
{
public
LoginState
(
GameStateManager
gsm
)
{
super
(
gsm
);
super
(
gsm
);
makeStage
();
makeStage
();
...
@@ -64,9 +70,11 @@ public class LoginState extends State {
...
@@ -64,9 +70,11 @@ public class LoginState extends State {
// Add widgets
// Add widgets
titleLabel
.
setFontScale
(
titleFontBigScale
);
titleLabel
.
setFontScale
(
titleFontBigScale
);
rootTable
.
add
(
titleLabel
).
expandY
();
rootTable
.
add
(
titleLabel
).
expandY
()
.
top
()
;
rootTable
.
row
();
rootTable
.
row
();
rootTable
.
add
(
subHeadLabel
).
expandY
();
if
(
page
==
0
)
{
rootTable
.
add
(
subHeadLabelLogIn
).
expandY
();
rootTable
.
row
();
rootTable
.
row
();
rootTable
.
add
(
makeUserInputField
()).
size
(
inputFieldWidth
,
inputFieldHeight
);
rootTable
.
add
(
makeUserInputField
()).
size
(
inputFieldWidth
,
inputFieldHeight
);
rootTable
.
row
();
rootTable
.
row
();
...
@@ -76,7 +84,22 @@ public class LoginState extends State {
...
@@ -76,7 +84,22 @@ public class LoginState extends State {
rootTable
.
row
();
rootTable
.
row
();
rootTable
.
add
(
makeLoginBtn
()).
size
(
buttonWidth
,
buttonHeight
);
rootTable
.
add
(
makeLoginBtn
()).
size
(
buttonWidth
,
buttonHeight
);
rootTable
.
row
();
rootTable
.
row
();
rootTable
.
add
(
makeSignUpBtn
()).
size
(
buttonWidth
,
buttonHeight
).
padBottom
(
spacingLarge
);
rootTable
.
add
(
makeCreateUserBtn
()).
size
(
buttonWidth
,
buttonHeight
).
padBottom
(
spacingMedium
).
expandY
().
top
();
}
else
if
(
page
==
1
){
rootTable
.
add
(
subHeadLabelCreateUser
).
expandY
().
spaceBottom
(
spacingMedium
);
rootTable
.
row
();
rootTable
.
add
(
makeUserInputField
()).
size
(
inputFieldWidth
,
inputFieldHeight
);
rootTable
.
row
();
rootTable
.
add
(
makePasswordInputField
()).
size
(
inputFieldWidth
,
inputFieldHeight
);
rootTable
.
row
();
rootTable
.
add
(
makeConfirmPasswordInputField
()).
size
(
inputFieldWidth
,
inputFieldHeight
);
rootTable
.
row
();
rootTable
.
add
(
errorLabel
);
rootTable
.
row
();
rootTable
.
add
(
makeSignUpBtn
()).
size
(
buttonWidth
,
buttonHeight
);
rootTable
.
row
();
rootTable
.
add
(
makeBackBtn
()).
expand
().
bottom
().
left
();
}
removeKeyPadAtTouch
();
removeKeyPadAtTouch
();
...
@@ -116,6 +139,22 @@ public class LoginState extends State {
...
@@ -116,6 +139,22 @@ public class LoginState extends State {
return
passwordInputField
;
return
passwordInputField
;
}
}
private
TextField
makeConfirmPasswordInputField
(
){
confirmPasswordInputField
=
new
TextField
(
confirmPasswordInputText
,
skin
);
confirmPasswordInputField
.
setPasswordCharacter
(
passwordCharacter
);
confirmPasswordInputField
.
addListener
(
new
ClickListener
()
{
@Override
public
void
clicked
(
InputEvent
event
,
float
x
,
float
y
)
{
super
.
clicked
(
event
,
x
,
y
);
if
(
confirmPasswordInputField
.
getText
().
equals
(
confirmPasswordInputText
)){
confirmPasswordInputField
.
setText
(
""
);
confirmPasswordInputField
.
setPasswordMode
(
true
);
}
}
});
return
confirmPasswordInputField
;
}
private
TextButton
makeLoginBtn
(
){
private
TextButton
makeLoginBtn
(
){
TextButton
loginBtn
=
new
TextButton
(
loginBtnText
,
skin
);
TextButton
loginBtn
=
new
TextButton
(
loginBtnText
,
skin
);
loginBtn
.
addListener
(
new
ClickListener
()
{
loginBtn
.
addListener
(
new
ClickListener
()
{
...
@@ -127,17 +166,51 @@ public class LoginState extends State {
...
@@ -127,17 +166,51 @@ public class LoginState extends State {
return
loginBtn
;
return
loginBtn
;
}
}
private
TextButton
makeCreateUserBtn
(
){
TextButton
createUserBtn
=
new
TextButton
(
createUserText
,
skin
);
createUserBtn
.
addListener
(
new
ClickListener
()
{
@Override
public
void
clicked
(
InputEvent
e
,
float
x
,
float
y
){
page
++;
errorLabel
.
setText
(
""
);
stage
.
clear
();
makeStage
();
}
});
return
createUserBtn
;
}
private
TextButton
makeSignUpBtn
(
){
private
TextButton
makeSignUpBtn
(
){
TextButton
signUpBtn
=
new
TextButton
(
signUpBtnText
,
skin
);
TextButton
signUpBtn
=
new
TextButton
(
signUpBtnText
,
skin
);
signUpBtn
.
addListener
(
new
ClickListener
()
{
signUpBtn
.
addListener
(
new
ClickListener
()
{
@Override
@Override
public
void
clicked
(
InputEvent
e
,
float
x
,
float
y
){
public
void
clicked
(
InputEvent
e
,
float
x
,
float
y
){
try
{
isValidPassword
();
setSignUpBtnClicked
();
setSignUpBtnClicked
();
}
catch
(
IllegalArgumentException
exception
){
errorLabel
.
setText
(
passwordNotMatchingText
);
}
}
}
});
});
return
signUpBtn
;
return
signUpBtn
;
}
}
private
TextButton
makeBackBtn
(){
TextButton
backBtn
=
new
TextButton
(
backText
,
skin
);
backBtn
.
addListener
(
new
ClickListener
()
{
@Override
public
void
clicked
(
InputEvent
e
,
float
x
,
float
y
){
page
--;
errorLabel
.
setText
(
""
);
stage
.
clear
();
makeStage
();
}
});
return
backBtn
;
}
// Handle click methods
// Handle click methods
private
void
handleLoginBtnClick
(){
private
void
handleLoginBtnClick
(){
...
@@ -157,12 +230,6 @@ public class LoginState extends State {
...
@@ -157,12 +230,6 @@ public class LoginState extends State {
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
// Add animation
errorLabel
.
getColor
().
a
=
1
;
errorLabel
.
addAction
(
Actions
.
sequence
(
new
DelayAction
(
animationDelay
),
Actions
.
fadeOut
(
animationDuration
)));
// Different feedback text depending on which exception
// Different feedback text depending on which exception
if
(
e
instanceof
NoSuchElementException
)
{
if
(
e
instanceof
NoSuchElementException
)
{
errorLabel
.
setText
(
wrongLoginText
);
errorLabel
.
setText
(
wrongLoginText
);
...
@@ -191,12 +258,6 @@ public class LoginState extends State {
...
@@ -191,12 +258,6 @@ public class LoginState extends State {
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
// Add animation
errorLabel
.
getColor
().
a
=
1
;
errorLabel
.
addAction
(
Actions
.
sequence
(
new
DelayAction
(
animationDelay
),
Actions
.
fadeOut
(
animationDuration
)));
// Different feedback text depending on which exception
// Different feedback text depending on which exception
if
(
e
instanceof
NoSuchElementException
)
{
if
(
e
instanceof
NoSuchElementException
)
{
errorLabel
.
setText
(
takenUsernameText
);
errorLabel
.
setText
(
takenUsernameText
);
...
@@ -221,6 +282,12 @@ public class LoginState extends State {
...
@@ -221,6 +282,12 @@ public class LoginState extends State {
}
}
private
void
isValidPassword
()
throws
IllegalArgumentException
{
if
(!
passwordInputField
.
getText
().
equals
(
confirmPasswordInputField
.
getText
())){
throw
new
IllegalArgumentException
();
}
}
@Override
@Override
public
void
update
(
float
dt
)
{
public
void
update
(
float
dt
)
{
super
.
update
(
dt
);
super
.
update
(
dt
);
...
@@ -264,5 +331,7 @@ public class LoginState extends State {
...
@@ -264,5 +331,7 @@ public class LoginState extends State {
public
void
reset
()
{
public
void
reset
()
{
usernameInputField
.
setText
(
usernameInputText
);
usernameInputField
.
setText
(
usernameInputText
);
passwordInputField
.
setText
(
passwordInputText
);
passwordInputField
.
setText
(
passwordInputText
);
confirmPasswordInputField
.
setText
(
confirmPasswordInputText
);
errorLabel
.
setText
(
""
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment