Imports System.Xml
Imports System.io
Public Class AddQuestform
Inherits System.Windows.Forms.Form
Friend Label2 As System.Windows.Forms.Label
Friend Label1 As System.Windows.Forms.Label
Friend TextBox1 As System.Windows.Forms.TextBox
Friend TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend ComboBox1 As System.Windows.Forms.ComboBox
Friend Label3 As System.Windows.Forms.Label
Dim mainform As WindowsApplication1.DefaultNamespace.MainForm
#Region " Windows Form Designer generated code "
Public Sub New(ByRef mainform As Form)
MyBase.New()
mainform = mainform
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Label3 = New System.Windows.Forms.Label
Me.ComboBox1 = New System.Windows.Forms.ComboBox
Me.Button1 = New System.Windows.Forms.Button
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(56, 64)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(112, 24)
Me.Label3.TabIndex = 5
Me.Label3.Text = "Name: "
'
'ComboBox1
'
Me.ComboBox1.Items.AddRange(New Object() {"Area1", "Area2", "Area3", "Area4"})
Me.ComboBox1.Location = New System.Drawing.Point(192, 16)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(144, 21)
Me.ComboBox1.TabIndex = 0
AddHandler Me.ComboBox1.SelectedIndexChanged, AddressOf Me.ComboBox1SelectedIndexChanged
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(200, 304)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(120, 48)
Me.Button1.TabIndex = 4
Me.Button1.Text = "Save!"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(192, 64)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(184, 20)
Me.TextBox2.TabIndex = 6
Me.TextBox2.Text = ""
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(192, 112)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(344, 168)
Me.TextBox1.TabIndex = 2
Me.TextBox1.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(56, 16)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(112, 24)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Select Area:"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(56, 120)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(112, 32)
Me.Label2.TabIndex = 3
Me.Label2.Text = "Commands (one per line):"
'
'AddQuestform
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(568, 374)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.ComboBox1)
Me.Name = "AddQuestform"
Me.Text = "AddQuestform"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If ComboBox1.SelectedIndex > -1 Then
Dim filename = ComboBox1.SelectedItem & ".xml"
Dim fStrm As FileStream
Try
fStrm = New FileStream(filename, FileMode.Truncate, FileAccess.Write)
Catch ex As Exception
Try
fStrm = New FileStream(filename, FileMode.Create, FileAccess.Write)
Catch ex2 As Exception
MessageBox.Show("cannot save file")
Exit Sub
End Try
End Try
Dim xtw As New XmlTextWriter(fStrm, System.Text.Encoding.UTF8)
xtw.Formatting = Formatting.Indented
xtw.Indentation = 2
xtw.QuoteChar = """"c
xtw.WriteStartDocument(True)
xtw.WriteStartElement("Quests")
For Each quest As QuestStorage In mainform.getComboBoxForArea(ComboBox1.SelectedItem)
xtw.WriteStartElement("Quest")
xtw.WriteElementString("Name", quest.ToString())
xtw.WriteStartElement("Commands")
For Each line As String In quest.getCommands()
xtw.WriteElementString("Command", line)
Next
xtw.WriteEndElement()
xtw.WriteEndElement()
Next
xtw.WriteStartElement("Quest")
xtw.WriteElementString("Name", TextBox2.Text)
xtw.WriteStartElement("Commands")
For Each line As String In TextBox1.Text.Split(vbCrLf)
If (line.Chars(0) = vbLf) Then
line = line.Substring(1)
End If
xtw.WriteElementString("Command", line)
Next
xtw.WriteEndElement()
xtw.WriteEndElement()
xtw.WriteEndElement()
xtw.WriteEndDocument()
xtw.Close()
mainform.loadQuests()
MessageBox.Show("Quest: " & TextBox2.Text & " is saved!")
End If
End Sub
Private Sub ComboBox1SelectedIndexChanged(sender As System.Object, e As System.EventArgs)
End Sub
End Class