-aggiunto script editor per file lua
-al momento funziona con textbox
This commit is contained in:
@@ -0,0 +1,170 @@
|
||||
Imports EgtUILib
|
||||
Imports EgtWPFLib5
|
||||
Imports System.IO
|
||||
Imports System.Text
|
||||
|
||||
Public Class ScriptWindowVM
|
||||
Inherits VMBase
|
||||
|
||||
#Region "FIELD & PROPERTIES"
|
||||
|
||||
Private m_sNameFile As String = String.Empty
|
||||
Public Property sNameFile As String
|
||||
Get
|
||||
Return m_sNameFile
|
||||
End Get
|
||||
Set(value As String)
|
||||
m_sNameFile = value
|
||||
NotifyPropertyChanged(NameOf(sNameFile))
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Private m_sRichTextParagraph As String = String.Empty
|
||||
Public Property sRichTextParagraph As String
|
||||
Get
|
||||
Return m_sRichTextParagraph
|
||||
End Get
|
||||
Set(value As String)
|
||||
'm_sRichTextParagraph = StringFromRichTextBox(Map.refScriptWindowV.sNameFile_RichTxBx)
|
||||
m_sRichTextParagraph = value
|
||||
NotifyPropertyChanged(NameOf(sRichTextParagraph))
|
||||
End Set
|
||||
End Property
|
||||
|
||||
#Region "Messages"
|
||||
|
||||
Public ReadOnly Property Title As String
|
||||
Get
|
||||
Return "Script File" ' Opzioni
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public ReadOnly Property Conferma_Msg As String
|
||||
Get
|
||||
Return EgtMsg(110003) ' Conferma
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public ReadOnly Property Salva_Msg As String
|
||||
Get
|
||||
Return EgtMsg(110013) ' Salva
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public ReadOnly Property Annulla_Msg As String
|
||||
Get
|
||||
Return EgtMsg(110004) ' Annulla
|
||||
End Get
|
||||
End Property
|
||||
|
||||
#End Region ' Messages
|
||||
|
||||
' Definizione Comandi
|
||||
Private m_ConfermaCmd As ICommand
|
||||
Private m_cmdSaveAs As ICommand
|
||||
|
||||
#End Region ' Fields & Properties
|
||||
|
||||
#Region "CONSTRUCTOR"
|
||||
|
||||
Sub New()
|
||||
m_sNameFile = "Prova"
|
||||
Map.SetRefScriptWindowVM(Me)
|
||||
End Sub
|
||||
|
||||
#End Region ' Constructor
|
||||
|
||||
#Region "METHODS"
|
||||
|
||||
Public Function SaveProject() As Boolean
|
||||
Dim sFile As String = ""
|
||||
Dim sFileName As String = ""
|
||||
' Se nome vuoto, assegno "New"
|
||||
If String.IsNullOrWhiteSpace(m_sNameFile) Then
|
||||
sFile = "New.lua"
|
||||
Else
|
||||
sFile = m_sNameFile & ".lua"
|
||||
End If
|
||||
' Eventuale sistemazione estensione
|
||||
sFile = IO.Path.ChangeExtension(sFile, "lua")
|
||||
' Assegnazione nome file con dialogo
|
||||
Dim SaveFileDialog As New EgtManageFileDialogV(Application.Current.MainWindow, New EgtManageFileDialogVM()) With {
|
||||
.Title = EgtMsg(110013), ' Salva
|
||||
.Filter = "lua files (*.lua)|*.lua",
|
||||
.FileName = sFile,
|
||||
.FilterIndex = 1,
|
||||
.InitialDirectory = Map.refMainWindowVM.MainWindowM.sTempDir,
|
||||
.ValidateNames = False,
|
||||
.OverwritePrompt = True,
|
||||
.Mode = 1
|
||||
}
|
||||
If SaveFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
|
||||
If Path.GetExtension(SaveFileDialog.SafeFileName).Equals(String.Empty) Then
|
||||
sFileName = SaveFileDialog.InitialDirectory & "\" & SaveFileDialog.SafeFileName & SaveFileDialog.SelFilter.sExstension.Trim("*"c)
|
||||
Else
|
||||
sFileName = SaveFileDialog.InitialDirectory & "\" & SaveFileDialog.SafeFileName
|
||||
End If
|
||||
End If
|
||||
Dim bOk = Map.refSceneHostVM.SaveProj(sFileName)
|
||||
File.WriteAllText(sFileName, m_sRichTextParagraph)
|
||||
' Imposto stato gestione mouse diretto della scena a nessuno
|
||||
Map.refSceneHostVM.MainScene.SetStatusNull()
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Private Sub SaveScript(sPathFileScript As String, sRichTextParagraph As String)
|
||||
Map.refSceneHostVM.SaveProj(sPathFileScript)
|
||||
File.WriteAllText(sPathFileScript, sRichTextParagraph)
|
||||
End Sub
|
||||
|
||||
Public Function StringFromRichTextBox(ByVal rtb As RichTextBox) As String
|
||||
Dim textRange As New TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd)
|
||||
Return textRange.Text
|
||||
End Function
|
||||
|
||||
#End Region ' Methods
|
||||
|
||||
#Region "COMMANDS"
|
||||
|
||||
#Region "ConfermCmd"
|
||||
|
||||
Public ReadOnly Property ConfermaCmd As ICommand
|
||||
Get
|
||||
If m_ConfermaCmd Is Nothing Then
|
||||
m_ConfermaCmd = New Command(AddressOf Conferma)
|
||||
End If
|
||||
Return m_ConfermaCmd
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public Sub Conferma()
|
||||
SaveScript(Map.refMainWindowVM.MainWindowM.sTempDir & "\" & m_sNameFile & ".lua", m_sRichTextParagraph)
|
||||
EgtLuaExecFile(Map.refMainWindowVM.MainWindowM.sTempDir & "\" & m_sNameFile & ".lua")
|
||||
' Imposto stato gestione mouse diretto della scena a nessuno
|
||||
Map.refSceneHostVM.MainScene.SetStatusNull()
|
||||
End Sub
|
||||
|
||||
#End Region ' ConfermaCmd
|
||||
|
||||
#Region "SaveAsCommand"
|
||||
|
||||
Public ReadOnly Property SalvaCmd As ICommand
|
||||
Get
|
||||
If m_cmdSaveAs Is Nothing Then
|
||||
m_cmdSaveAs = New Command(AddressOf SaveAs)
|
||||
End If
|
||||
Return m_cmdSaveAs
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public Sub SaveAs()
|
||||
SaveProject()
|
||||
End Sub
|
||||
|
||||
#End Region ' SaveAsCommand
|
||||
|
||||
#End Region ' Commands
|
||||
|
||||
End Class
|
||||
|
||||
|
||||
Reference in New Issue
Block a user