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
a6a508e2
Commit
a6a508e2
authored
2 months ago
by
bionic85
Browse files
Options
Downloads
Patches
Plain Diff
started working on file settings stuff
parent
6c7a6a4a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
PuzzlePlayer/SettingForm.cs
+94
-1
94 additions, 1 deletion
PuzzlePlayer/SettingForm.cs
with
94 additions
and
1 deletion
PuzzlePlayer/SettingForm.cs
+
94
−
1
View file @
a6a508e2
...
...
@@ -8,18 +8,81 @@ using System.Windows.Forms;
namespace
PuzzlePlayer_Namespace
{
// struct for saving settings
internal
struct
Settings
(
Theme
t
,
string
fName
,
int
fSize
)
{
public
Theme
theme
=
t
;
public
string
fontName
=
fName
;
public
int
fontSize
=
fSize
;
public
override
string
ToString
()
{
return
$"SETTINGS|
{
fontName
}
|
{
fontSize
}
|
{
theme
.
ToString
()}
"
;
}
public
static
Settings
FromString
(
string
s
)
{
string
[]
split
=
s
.
Split
(
'|'
);
if
(
split
[
0
]
!=
"SETTINGS"
)
throw
new
Exception
(
"Invallid input string in FromString methode from Settings struct"
);
string
themeString
=
""
;
for
(
int
i
=
3
;
i
<
split
.
Length
;
i
++)
// add everything after the fontsize to the themestring
{
themeString
+=
split
[
i
];
}
return
new
Settings
(
Theme
.
FromString
(
themeString
),
split
[
1
],
int
.
Parse
(
split
[
2
]));
}
}
// struct for saving themes
internal
struct
Theme
(
string
s
,
Color
col1
,
Color
col2
,
Color
col3
)
{
public
string
name
=
s
;
public
Color
primaryColor
=
col1
;
public
Color
secondaryColor
=
col2
;
public
Color
tertiaryColor
=
col3
;
public
override
string
ToString
()
{
return
$"THEME|
{
name
}
|
{
primaryColor
.
ToArgb
()}
|
{
secondaryColor
.
ToArgb
()}
|
{
tertiaryColor
.
ToArgb
()}
|"
;
}
public
static
Theme
FromString
(
string
s
)
{
string
[]
split
=
s
.
Split
(
'|'
);
if
(
split
[
0
]
!=
"THEME"
)
throw
new
Exception
(
"Invallid input string in FromString methode from Theme struct"
);
Color
c1
=
Color
.
FromArgb
(
int
.
Parse
(
split
[
2
]));
Color
c2
=
Color
.
FromArgb
(
int
.
Parse
(
split
[
3
]));
Color
c3
=
Color
.
FromArgb
(
int
.
Parse
(
split
[
4
]));
return
new
Theme
(
split
[
1
],
c1
,
c2
,
c3
);
}
}
internal
class
SettingForm
:
Form
{
// Public variables for all settings
// Currently they are set to their default values
public
static
Color
primaryColor
=
Color
.
FromArgb
(
66
,
69
,
73
);
public
static
Color
secondaryColor
=
Color
.
FromArgb
(
54
,
57
,
62
);
public
static
Color
tertiaryColor
=
Color
.
FromArgb
(
0
,
0
,
0
);
public
static
int
fontSize
=
16
;
public
static
Font
mainFont
=
new
Font
(
"Gotham"
,
fontSize
);
public
static
string
mainFontName
=
"Gotham"
;
public
static
Font
mainFont
=
new
Font
(
mainFontName
,
fontSize
);
public
static
FlowLayoutPanel
settingsPanel
;
// For storing user settings
private
Settings
settings
;
private
static
string
filePath
=
"Settings.txt"
;
public
SettingForm
()
{
settings
=
GetUserSettings
();
SetUpUi
();
this
.
BackColor
=
primaryColor
;
...
...
@@ -31,6 +94,36 @@ namespace PuzzlePlayer_Namespace
Invalidate
();
}
private
Settings
GetUserSettings
()
{
StreamReader
reader
=
new
StreamReader
(
System
.
IO
.
File
.
OpenRead
(
filePath
));
Settings
?
newSettings
=
null
;
string
s
=
""
;
while
((
s
=
reader
.
ReadLine
())
!=
null
)
{
if
(
s
.
StartsWith
(
"SETTINGS"
))
{
newSettings
=
Settings
.
FromString
(
s
);
break
;
}
}
reader
.
Dispose
();
if
(
newSettings
!=
null
)
return
(
Settings
)
newSettings
;
else
MakeNewSettingsFile
();
// if the settings could not be read then a new file must be made
return
GetUserSettings
();
// after the new file is made it is save to call getUserSettings again
}
private
void
MakeNewSettingsFile
()
{
FileStream
fs
=
File
.
Create
(
filePath
);
StreamReader
reader
=
new
StreamReader
(
fs
);
throw
new
NotImplementedException
();
}
private
void
SetUpUi
()
{
this
.
ClientSize
=
new
Size
(
1115
,
755
);
...
...
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