-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppSettings.vb
271 lines (232 loc) · 9.79 KB
/
AppSettings.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
Imports System.IO
Imports System.Diagnostics
Imports Microsoft.Win32
Public Class AppSettings
Public change As Boolean
Public SaveClicked As Boolean
Private Sub Settings_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TextBox1.Text = My.Settings.Entry_BackgroundImagePath
TextBox2.Text = My.Settings.TheGame_BackgroundImagePath
InitializeEntryBackgroundSettings()
InitializeTheGameBackgroundSettings()
change = False
SaveClicked = False
End Sub
Private Sub Settings_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
If change = True Then
If SaveClicked = False Then
SaveClicked = False
Dim result As DialogResult = MessageBox.Show("Save settings?", "Confirm Save", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
Select Case result
Case DialogResult.Yes
If SaveAndApplySettings() = "Cancel" Then
e.Cancel = True
End If
Case DialogResult.No
' Do nothing and allow the form to close without saving
Case DialogResult.Cancel
e.Cancel = True ' Cancel the form close event
End Select
Else
If SaveAndApplySettings() = "Cancel" Then
e.Cancel = True
SaveClicked = False
End If
End If
End If
End Sub
Private Sub InitializeEntryBackgroundSettings()
If My.Settings.Entry_IsBackgroundAnImage Then
If My.Settings.Entry_IsBackgroundDefault Then
EntryDefaultBackgroundImage.Checked = True
BrowseButton1.Hide()
PickAColorButton1.Hide()
Else
EntrySelectBackground.Checked = True
BrowseButton1.Show()
PickAColorButton1.Hide()
End If
Else
EntryColorBackground.Checked = True
PickAColorButton1.Show()
BrowseButton1.Hide()
End If
End Sub
Private Sub InitializeTheGameBackgroundSettings()
If My.Settings.TheGame_IsBackgroundAnImage Then
TheGameSelectBackground.Checked = True
BrowseButton2.Show()
PickAColorButton2.Hide()
Else
If My.Settings.TheGame_IsBackgroundDefault Then
TheGameDefaultBackground.Checked = True
BrowseButton2.Hide()
PickAColorButton2.Hide()
Else
TheGameColorBackground.Checked = True
PickAColorButton2.Show()
BrowseButton2.Hide()
End If
End If
End Sub
Private Sub EntryBackground_CheckedChanged(sender As Object, e As EventArgs) Handles EntryDefaultBackgroundImage.CheckedChanged, EntrySelectBackground.CheckedChanged, EntryColorBackground.CheckedChanged
change = True
HandleEntryBackgroundSelection()
End Sub
Private Sub HandleEntryBackgroundSelection()
If EntryDefaultBackgroundImage.Checked Then
BrowseButton1.Hide()
PickAColorButton1.Hide()
TextBox1.Enabled = False
ElseIf EntrySelectBackground.Checked Then
BrowseButton1.Show()
PickAColorButton1.Hide()
TextBox1.Enabled = True
TextBox1.Text = My.Settings.Entry_BackgroundImagePath
Else
BrowseButton1.Hide()
PickAColorButton1.Show()
TextBox1.Enabled = False
End If
End Sub
Private Sub TheGameDefaultBackground_CheckedChanged(sender As Object, e As EventArgs) Handles TheGameDefaultBackground.CheckedChanged, TheGameSelectBackground.CheckedChanged, TheGameColorBackground.CheckedChanged
change = True
HandleTheGameBackgroundSelection()
End Sub
Private Sub HandleTheGameBackgroundSelection()
If TheGameDefaultBackground.Checked Then
BrowseButton2.Hide()
PickAColorButton2.Hide()
TextBox2.Enabled = False
TextBox2.Text = My.Settings.TheGame_BackgroundImagePath
ElseIf TheGameSelectBackground.Checked Then
BrowseButton2.Show()
PickAColorButton2.Hide()
TextBox2.Enabled = True
Else
PickAColorButton2.Show()
BrowseButton2.Hide()
TextBox2.Enabled = False
End If
End Sub
Private Sub Save_Settings_Click(sender As Object, e As EventArgs) Handles Save_Settings.Click
SaveClicked = True
Me.Close()
End Sub
Private Function SaveAndApplySettings() As String
' Appky changes
My.Settings.Save()
If ApplyEntryBackgroundSettings() = "Invalid" Then
Return "Cancel"
End If
If ApplyTheGameBackgroundSettings() = "Invalid" Then
Return "Cancel"
End If
Return "Proceed"
End Function
Private Function ApplyEntryBackgroundSettings() As String
If EntryDefaultBackgroundImage.Checked Then
My.Settings.Entry_IsBackgroundAnImage = True
My.Settings.Entry_IsBackgroundDefault = True
ElseIf EntrySelectBackground.Checked Then
My.Settings.Entry_IsBackgroundAnImage = True
My.Settings.Entry_IsBackgroundDefault = False
If String.IsNullOrWhiteSpace(TextBox1.Text.Trim()) Then
MsgBox("Please select an image before saving.")
Return "Invalid"
End If
Else
My.Settings.Entry_IsBackgroundAnImage = False
My.Settings.Entry_IsBackgroundDefault = False
End If
My.Settings.Save()
If My.Settings.Entry_IsBackgroundAnImage Then
If My.Settings.Entry_IsBackgroundDefault Then
Entry.SetBackgroundImage("Default")
Else
Entry.SetBackgroundImage("Selected")
End If
Else
Entry.SetBackgroundColor()
End If
Return "Valid"
End Function
Private Function ApplyTheGameBackgroundSettings() As String
If TheGameDefaultBackground.Checked Then
My.Settings.TheGame_IsBackgroundAnImage = False
My.Settings.TheGame_IsBackgroundDefault = True
ElseIf TheGameSelectBackground.Checked Then
My.Settings.TheGame_IsBackgroundAnImage = True
My.Settings.TheGame_IsBackgroundDefault = False
If String.IsNullOrWhiteSpace(TextBox2.Text.Trim()) Then
MsgBox("Please select an image before saving.")
Return "Invalid"
End If
Else
My.Settings.TheGame_IsBackgroundAnImage = False
My.Settings.TheGame_IsBackgroundDefault = False
End If
My.Settings.Save()
If My.Settings.TheGame_IsBackgroundAnImage Then
TheGame.SetBackgroundImage()
Else
If My.Settings.TheGame_IsBackgroundDefault Then
TheGame.SetBackgroundColor("Default")
Else
TheGame.SetBackgroundColor("Selected")
End If
End If
Return "Valid"
End Function
Private Sub ShowOpenFileDialogAndUpdateSetting(settingName As String)
If File.Exists(My.Settings(settingName)) Then
OpenFileDialog.InitialDirectory = Path.GetDirectoryName(My.Settings(settingName))
Else
OpenFileDialog.InitialDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "Others")
End If
OpenFileDialog.Filter = "Image files (*.png;*.jpg;*.jpeg)|*.png;*.jpg;*.jpeg|All files (*.*)|*.*"
OpenFileDialog.FilterIndex = 1
OpenFileDialog.RestoreDirectory = True
If OpenFileDialog.ShowDialog() = DialogResult.OK Then
Dim selectedFilePath As String = OpenFileDialog.FileName
My.Settings(settingName) = selectedFilePath
change = True
If settingName = "Entry_BackgroundImagePath" Then
TextBox1.Text = selectedFilePath
Else
TextBox2.Text = selectedFilePath
End If
End If
End Sub
Private Sub ShowOpenColorDialogAndUpdateSetting(settingName As String)
If ColorDialog.ShowDialog() = DialogResult.OK Then
My.Settings(settingName) = ColorDialog.Color
change = True
End If
End Sub
Private Sub BrowseButton1_Click(sender As Object, e As EventArgs) Handles BrowseButton1.Click
ShowOpenFileDialogAndUpdateSetting("Entry_BackgroundImagePath")
End Sub
Private Sub BrowseButton2_Click(sender As Object, e As EventArgs) Handles BrowseButton2.Click
ShowOpenFileDialogAndUpdateSetting("TheGame_BackgroundImagePath")
End Sub
Private Sub PickAColorButton1_Click(sender As Object, e As EventArgs) Handles PickAColorButton1.Click
ShowOpenColorDialogAndUpdateSetting("Entry_BackgroundColor")
End Sub
Private Sub PickAColorButton2_Click(sender As Object, e As EventArgs) Handles PickAColorButton2.Click
ShowOpenColorDialogAndUpdateSetting("TheGame_BackgroundColor")
End Sub
Private Sub OpenLink(url As String)
Try
Process.Start(New ProcessStartInfo(url) With {.UseShellExecute = True})
Catch ex As Exception
MsgBox("Unable to open link: " & ex.Message)
End Try
End Sub
Private Sub About_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles About_link.LinkClicked
OpenLink("https://github.com/Nischall01/DGame?tab=readme-ov-file#readme")
End Sub
Private Sub Update_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles Update_link.LinkClicked
OpenLink("https://github.com/Nischall01/DGame/releases/")
End Sub
End Class