Imports TheAgent.frmHelper
Imports Microsoft.Win32
Public Class frmOption
'Carica le opzioni, genera checkbox e textbox a runtime per ogni frase
Private Sub frmOption_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim T As TextBox
Dim C As CheckBox
Dim Y As UInt16 = 19
'Aggiunta controlli
With frmHelper.Options
For I As Byte = 0 To UBound(.Sentences)
T = New TextBox
T.Name = "txtSen" & I
T.Tag = I
T.Text = .Sentences(I).Text
T.Size = New Size(210, 20)
T.Location = New Point(155, Y)
C = New CheckBox
C.Name = "chbSen" & I
C.Tag = I
C.Text = .Sentences(I).Tag
C.Checked = .Sentences(I).Play
C.Location = New Point(16, Y)
C.Width = 120
grpSen.Controls.Add(T)
grpSen.Controls.Add(C)
Y += 26
Next
Y = 19
For i As Byte = 0 To UBound(.PredSentences)
C = New CheckBox
C.Name = "chbPSen" & i
C.Tag = i
C.Text = .PredSentences(i).Tag
C.Checked = .PredSentences(i).Play
C.Location = New Point(16, Y)
C.Width = 370
grpPredSen.Controls.Add(C)
Y += 26
Next
'Varie
chbSpeakOnMouse.Checked = .Speak_On_MouseOver
chbBugTragedy.Checked = .Tragedy_On
'Riempimento della combobox del meteo
Dim Names() As String = [Enum].GetNames(GetType(clsOptions.MeteoZones))
Dim Selected As String = [Enum].GetName(GetType(clsOptions.MeteoZones), frmHelper.Options.Meteo)
Array.Sort(Names)
For I As Int16 = 0 To UBound(Names)
cmbMeteo.Items.Add(Names(I))
Next
cmbMeteo.SelectedItem = Selected
chbMeteo.Checked = .Meteo_On_startup
chbMeteoDetails.Checked = .Meteo_Detailed
'POP3
If .POP3_Enabled Then
cmdEnabledMail.Text = "Disattiva il controllo della posta"
End If
'Agente
cmbAgent.SelectedItem = .Agent
nudX.Value = .StartPos.X
nudY.Value = .StartPos.Y
End With
'Fumetti
With frmHelper.Agente.Balloon
lblFont.Text = .FontName + ", " & .FontSize & "pt"
lblFont.Font = New Font(.FontName, .FontSize)
chbBalloon.Checked = .Enabled
End With
End Sub
'Salva le opzioni sulle frasi
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
Dim T As TextBox
Dim C As CheckBox
With frmHelper.Options
'Frasi definite dall'utente
For I As Byte = 0 To UBound(.Sentences)
T = grpSen.Controls.Find("txtSen" & I, False)(0)
C = grpSen.Controls.Find("chbSen" & I, False)(0)
.Sentences(I).Text = T.Text
.Sentences(I).Play = C.Checked
Next
'Frasi preimpostate
For I As Byte = 0 To UBound(.PredSentences)
C = grpPredSen.Controls.Find("chbPSen" & I, False)(0)
.PredSentences(I).Play = C.Checked
Next
'Varie
.Speak_On_MouseOver = chbSpeakOnMouse.Checked
.Tragedy_On = chbBugTragedy.Checked
End With
MessageBox.Show("Salvataggio completato!", "Opzioni", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
'Cambia il font visualizzando la finestra di dialogo
Private Sub cmdFont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFont.Click
Dim F As New FontDialog
If F.ShowDialog = Windows.Forms.DialogResult.OK Then
lblFont.Text = F.Font.Name + ", " & F.Font.Size & "pt"
lblFont.Font = F.Font
End If
End Sub
'Salva le opzioni sull'agente
Private Sub cmdSaveAg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSaveAg.Click
'Fumetti e POP3
With frmHelper.Options
.Balloon_Enabled = chbBalloon.Checked
.Balloon_Font_Name = lblFont.Font.Name
.Balloon_Font_Size = lblFont.Font.Size
.POP3_Server = txtServer.Text
.POP3_Port = txtPort.Text
.POP3_User = txtUser.Text
.POP3_Password = txtPass.Text
End With
'Fumetti
With frmHelper.Agente.Balloon
.FontName = lblFont.Font.Name
.FontSize = lblFont.Font.Size
.Visible = chbBalloon.Checked
End With
'Agente
If cmbAgent.SelectedItem <> Nothing Then
frmHelper.Options.Agent = cmbAgent.SelectedItem
With frmHelper
Try
.Agente.Hide()
.AxAgent1.Characters.Unload(.Personaggio)
.Personaggio = cmbAgent.SelectedItem
.AxAgent1.Characters.Load(cmbAgent.SelectedItem, "C:\WINDOWS\msagent\chars\" + cmbAgent.SelectedItem + ".acs")
Catch Ex As Exception
End Try
.Agente = .AxAgent1.Characters(cmbAgent.SelectedItem)
.Agente.Show()
.Agente.MoveTo(.Position.X, .Position.Y)
End With
End If
'Meteo
For Each M As clsOptions.MeteoZones In [Enum].GetValues(GetType(clsOptions.MeteoZones))
If cmbMeteo.SelectedItem = M.ToString Then
frmHelper.Options.Meteo = M
Exit For
End If
Next
frmHelper.Options.Meteo_On_startup = chbMeteo.Checked
frmHelper.Options.Meteo_Detailed = chbMeteoDetails.Checked
MessageBox.Show("Salvataggio completato!", "Opzioni", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
'Preleva le posizioni attuali del form principale
Private Sub cmdCurPos_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCurPos.Click
With frmHelper
nudX.Value = .Position.X
nudY.Value = .Position.Y
End With
End Sub
'Imposta le voci di registro cosė da abilitare o disabilitare l'esecuzione automatica
'del programma
Private Sub chbAutoStart_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chbAutoStart.CheckedChanged
Dim RegKey As RegistryKey
RegKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
If chbAutoStart.Checked Then
RegKey.SetValue("The Agent", Application.ExecutablePath)
Else
If RegKey.GetValue("The Agent") <> Nothing Then
RegKey.DeleteValue("The Agent")
End If
End If
End Sub
'Attiva il controllo della posta
Private Sub cmdEnabledMail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEnabledMail.Click
If frmHelper.tmrControlMail.Enabled Then
cmdEnabledMail.Text = "Attiva il controllo della posta"
frmHelper.tmrControlMail.Stop()
frmHelper.Options.POP3_Enabled = False
Else
cmdEnabledMail.Text = "Disattiva il controllo della posta"
frmHelper.tmrControlMail.Start()
frmHelper.Options.POP3_Enabled = True
End If
End Sub
End Class