Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
puzzleplayer
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
Package Registry
Model registry
Operate
Environments
Terraform modules
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
Floris
puzzleplayer
Commits
3e626611
Commit
3e626611
authored
2 months ago
by
bionic85
Browse files
Options
Downloads
Patches
Plain Diff
UserDataManager class is done. Implementation is still needed
parent
4bdf5c89
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
PuzzlePlayer/Resources/Themes.txt
+3
-0
3 additions, 0 deletions
PuzzlePlayer/Resources/Themes.txt
PuzzlePlayer/UserDataManager.cs
+55
-61
55 additions, 61 deletions
PuzzlePlayer/UserDataManager.cs
with
58 additions
and
61 deletions
PuzzlePlayer/Resources/Themes.txt
0 → 100644
+
3
−
0
View file @
3e626611
THEME|Dark|66|69|73|54|57|62|0|0|0|True
THEME|Light|228|229|241|210|211|219|72|75|106|True
THEME|Pink|255|209|220|252|178|197|251|199|255|True
\ No newline at end of file
This diff is collapsed.
Click to expand it.
PuzzlePlayer/UserDataManager.cs
+
55
−
61
View file @
3e626611
...
...
@@ -6,53 +6,19 @@ using PuzzlePlayer_Namespace.Properties; // for accessing user settings
namespace
PuzzlePlayer_Namespace
{
// struct for saving settings
// saves the current selected theme and the font name and size
internal
struct
UserData
(
string
themeName
,
string
fName
,
int
fSize
)
{
public
const
string
prefix
=
"SETTINGS"
;
public
string
currentThemeName
=
themeName
;
public
string
fontName
=
fName
;
public
int
fontSize
=
fSize
;
public
override
string
ToString
()
{
return
$"
{
prefix
}
|
{
fontName
}
|
{
fontSize
}
|
{
currentThemeName
}
"
;
}
public
static
UserData
?
FromString
(
string
s
)
{
string
[]
split
=
s
.
Split
(
'|'
);
if
(
split
[
0
]
!=
prefix
)
return
null
;
try
{
string
fName
=
split
[
1
];
int
fSize
=
int
.
Parse
(
split
[
2
]);
string
tName
=
split
[
3
];
return
new
UserData
(
tName
,
fName
,
fSize
);
}
catch
(
Exception
)
{
return
null
;
//unreadable file will be handled somewhere else
}
}
}
// struct for saving themes
internal
struct
Theme
(
string
s
,
Color
col1
,
Color
col2
,
Color
col3
)
internal
struct
Theme
(
string
s
,
Color
col1
,
Color
col2
,
Color
col3
,
bool
isUnlockedByDefault
)
{
public
const
string
prefix
=
"THEME"
;
public
string
name
=
s
;
public
Color
primaryColor
=
col1
;
public
Color
secondaryColor
=
col2
;
public
Color
tertiaryColor
=
col3
;
public
bool
unlocked
=
isUnlockedByDefault
;
// keeps track if this theme is unlocked
public
override
string
ToString
()
{
return
$"
{
prefix
}
|
{
name
}
|
{
primaryColor
.
ToArgb
()}
|
{
secondaryColor
.
ToArgb
()}
|
{
tertiaryColor
.
ToArgb
()}
|
"
;
return
$"
{
prefix
}
|
{
name
}
|
{
primaryColor
.
R
}
|
{
primaryColor
.
G
}
|
{
primaryColor
.
B
}
|
{
secondaryColor
.
R
}
|
{
secondaryColor
.
G
}
|
{
secondaryColor
.
B
}
|
{
tertiaryColor
.
R
}
|
{
tertiaryColor
.
G
}
|
{
tertiaryColor
.
B
}
|
{
unlocked
}
"
;
}
public
static
Theme
?
FromString
(
string
s
)
...
...
@@ -62,11 +28,11 @@ namespace PuzzlePlayer_Namespace
return
null
;
try
{
Color
c1
=
Color
.
FromArgb
(
int
.
Parse
(
split
[
2
]));
Color
c2
=
Color
.
FromArgb
(
int
.
Parse
(
split
[
3
]));
Color
c3
=
Color
.
FromArgb
(
int
.
Parse
(
split
[
4
]));
Color
c1
=
Color
.
FromArgb
(
int
.
Parse
(
split
[
2
])
,
int
.
Parse
(
split
[
3
]),
int
.
Parse
(
split
[
4
])
);
Color
c2
=
Color
.
FromArgb
(
int
.
Parse
(
split
[
5
]),
int
.
Parse
(
split
[
6
]),
int
.
Parse
(
split
[
7
]));
Color
c3
=
Color
.
FromArgb
(
int
.
Parse
(
split
[
8
]),
int
.
Parse
(
split
[
9
]),
int
.
Parse
(
split
[
10
]));
return
new
Theme
(
split
[
1
],
c1
,
c2
,
c3
);
return
new
Theme
(
split
[
1
],
c1
,
c2
,
c3
,
bool
.
Parse
(
split
[
11
])
);
}
catch
(
Exception
)
{
...
...
@@ -82,37 +48,47 @@ namespace PuzzlePlayer_Namespace
public
int
Money
{
get
{
return
Settings
.
Default
.
Money
;
}
set
{
SetMoney
(
value
);
}
}
public
Font
MainFont
{
get
{
return
GetMainFont
();
}
}
public
Theme
Theme
{
get
{
return
GetCurrentTheme
();
}
}
public
UserData
Data
{
get
{
return
GetUserSettings
();
}
set
{
SetUserData
(
value
);
}
}
private
List
<(
Theme
,
bool
)>
unlockedThemes
=
new
List
<(
Theme
,
bool
)>()
;
private
List
<(
Theme
,
bool
)>
unlockedThemes
;
private
const
string
dataFilePath
=
"Data.txt"
;
private
const
string
themeFilePath
=
"Themes.txt"
;
private
const
string
moneyPrefix
=
"DO_NOT_TOUCH_THE_MONEY_CHEATER"
;
p
rivate
void
SetMoney
(
int
newValue
)
p
ublic
UserDataManager
(
)
{
if
(
newValue
<
0
)
return
;
Settings
.
Default
.
Money
=
newValue
;
Settings
.
Default
.
Save
();
unlockedThemes
=
GetUnlockedThemes
();
}
private
UserData
GetUserSetting
s
()
private
List
<(
Theme
,
bool
)>
GetUnlockedTheme
s
()
{
string
themeName
=
Settings
.
Default
.
ThemeName
;
string
fontName
=
Settings
.
Default
.
FontName
;
int
fontSize
=
Settings
.
Default
.
FontSize
;
List
<(
Theme
,
bool
)>
result
=
new
List
<(
Theme
,
bool
)>();
if
(!
File
.
Exists
(
themeFilePath
))
throw
new
Exception
(
"blijf van de theme file af kkr djalla"
);
using
(
StreamReader
sr
=
new
StreamReader
(
themeFilePath
))
{
while
(!
sr
.
EndOfStream
)
{
Theme
?
t
=
Theme
.
FromString
(
sr
.
ReadLine
());
if
(
t
==
null
)
throw
new
Exception
(
"blijf van de theme file af kkr djalla, ga t zelf maar fixen"
);
else
{
Theme
theme
=
(
Theme
)
t
;
result
.
Add
((
theme
,
theme
.
unlocked
));
}
}
}
return
new
UserData
(
themeName
,
fontName
,
fontSize
)
;
return
result
;
}
private
void
Set
UserData
(
UserData
newUserData
)
private
void
Set
Money
(
int
newValue
)
{
Settings
.
Default
.
FontName
=
newUserData
.
fontName
;
Settings
.
Default
.
FontSize
=
newUserData
.
fontSize
;
Settings
.
Default
.
ThemeName
=
newUserData
.
currentThemeName
;
if
(
newValue
<
0
)
return
;
Settings
.
Default
.
Money
=
newValue
;
Settings
.
Default
.
Save
();
}
...
...
@@ -133,8 +109,26 @@ namespace PuzzlePlayer_Namespace
private
Theme
GetCurrentTheme
()
{
string
currentThemeName
=
Settings
.
Default
.
ThemeName
;
foreach
((
Theme
,
bool
)
tb
in
unlockedThemes
)
{
if
(
tb
.
Item2
&&
currentThemeName
==
tb
.
Item1
.
name
)
return
tb
.
Item1
;
}
throw
new
Exception
(
"can't find the selected theme in unlocked themes"
);
}
public
void
SetCurrentTheme
(
string
newThemeName
)
{
foreach
((
Theme
,
bool
)
tb
in
unlockedThemes
)
{
if
(
tb
.
Item2
&&
newThemeName
==
tb
.
Item1
.
name
)
{
Settings
.
Default
.
ThemeName
=
newThemeName
;
Settings
.
Default
.
Save
();
return
;
}
}
}
}
}
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