Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import generators
- import ui
- import chat
- import chrmgr
- import app
- import player
- import math
- import background
- import grp
- import wndMgr
- import chr
- import nonplayer
- import systemSetting
- import os
- import pack
- import dbg
- import uiCommon
- class Map3DObject(object):
- def __init__(self, id, vid, x, y, z, rx, ry, rz):
- self.id = id
- self.vid = vid
- self.x = x
- self.y = y
- self.z = z
- self.rx = rx
- self.ry = ry
- self.rz = rz
- def GetPosition(self):
- return self.x, self.y, self.z
- def GetRotation(self):
- return self.rx, self.ry, self.rz
- def GetVirtualID(self):
- return self.vid
- def GetRealID(self):
- if self.id >= 0:
- return self.id
- else:
- return (self.id - 0x7FFFFFFF)*-1
- def GetObjectNumber(self):
- return self.id
- class Item(ui.ListBoxEx.Item):
- def __init__(self, fileName):
- ui.ListBoxEx.Item.__init__(self)
- self.canLoad=0
- self.text=fileName
- self.textLine=self.__CreateTextLine(fileName)
- def __del__(self):
- ui.ListBoxEx.Item.__del__(self)
- def GetText(self):
- return self.text
- def OnMouseLeftButtonDoubleClick(self):
- self.parent.OnMouseLeftButtonDoubleClick()
- def __CreateTextLine(self, fileName):
- textLine=ui.TextLine()
- textLine.SetParent(self)
- textLine.SetPosition(0, 0)
- textLine.SetText(fileName)
- textLine.Show()
- return textLine
- class MapEditor(ui.ScriptWindow):
- def __init__(self):
- ui.ScriptWindow.__init__(self)
- self.ClearDictionary()
- #Board
- self.Board = ui.BoardWithTitleBar()
- self.Board.AddFlag("movable")
- self.Board.AddFlag("float")
- self.Board.SetTitleName("Map-Editor")
- self.Board.SetSize(500, 300)
- self.Board.SetPosition(30, systemSetting.GetHeight() - self.Board.GetHeight() - 70)
- self.Board.Show()
- self.Board.SetTop()
- #ObjectBrowserScrollBar
- self.ObjectBrowserScrollBar = ui.ScrollBar()
- wndMgr.SetParent(self.ObjectBrowserScrollBar.GetWindowHandle(), self.Board.GetWindowHandle())
- self.ObjectBrowserScrollBar.SetScrollBarSize(215)
- self.ObjectBrowserScrollBar.SetPosition(220, 50)
- self.ObjectBrowserScrollBar.Show()
- #ObjectBrowserBar
- self.ObjectBrowserBar = ui.SlotBar()
- wndMgr.SetParent(self.ObjectBrowserBar.GetWindowHandle(), self.Board.GetWindowHandle())
- self.ObjectBrowserBar.SetSize(200, 215)
- self.ObjectBrowserBar.SetPosition(15, 50)
- self.ObjectBrowserBar.Show()
- #ObjectBrowser
- self.ObjectBrowser = ui.ListBoxEx()
- wndMgr.SetParent(self.ObjectBrowser.GetWindowHandle(), self.ObjectBrowserBar.GetWindowHandle())
- self.ObjectBrowser.SetSize(200, 215)
- self.ObjectBrowser.SetItemSize(200, 20)
- self.ObjectBrowser.SetPosition(0, 1)
- self.ObjectBrowser.SetViewItemCount(10)
- self.ObjectBrowser.OnMouseLeftButtonDoubleClick = self.OnChangeDirectory
- self.ObjectBrowser.SetScrollBar(self.ObjectBrowserScrollBar)
- self.ObjectBrowser.Show()
- #PlacementBar
- self.PlacementBar = ui.HorizontalBar()
- wndMgr.SetParent(self.PlacementBar.GetWindowHandle(), self.Board.GetWindowHandle())
- self.PlacementBar.SetPosition(240, 55)
- self.PlacementBar.Create(244)
- self.PlacementBar.Show()
- #PlacementBarText
- self.PlacementBarText = ui.TextLine()
- wndMgr.SetParent(self.PlacementBarText.GetWindowHandle(), self.PlacementBar.GetWindowHandle())
- self.PlacementBarText.SetPosition(3, 2)
- self.PlacementBarText.SetText("Placement-Settings")
- self.PlacementBarText.Show()
- #RotXSliderBarText
- self.RotXSliderBarText = ui.TextLine()
- wndMgr.SetParent(self.RotXSliderBarText.GetWindowHandle(), self.Board.GetWindowHandle())
- self.RotXSliderBarText.SetPosition(240, 78)
- self.RotXSliderBarText.SetText("RotX:")
- self.RotXSliderBarText.Show()
- #RotXSliderBar
- self.RotXSliderBar = ui.SliderBar()
- wndMgr.SetParent(self.RotXSliderBar.GetWindowHandle(), self.Board.GetWindowHandle())
- self.RotXSliderBar.SetPosition(267, 80)
- self.RotXSliderBar.SetSliderPos(0.5)
- self.RotXSliderBar.backGroundImage.OnMouseLeftButtonDown = self.ResetSliderPosX
- self.RotXSliderBar.Show()
- #RotXSlot
- self.RotXSlot = ui.ImageBox()
- self.RotXSlot.LoadImage("d:/ymir work/ui/public/Parameter_Slot_00.sub")
- wndMgr.SetParent(self.RotXSlot.GetWindowHandle(), self.Board.GetWindowHandle())
- self.RotXSlot.SetPosition(445, 77)
- self.RotXSlot.Show()
- #RotXEditLine
- self.RotXEditLine = ui.EditLine()
- wndMgr.SetParent(self.RotXEditLine.GetWindowHandle(), self.RotXSlot.GetWindowHandle())
- self.RotXEditLine.SetPosition(3, 2)
- self.RotXEditLine.SetSize(30, 18)
- self.RotXEditLine.SetMax(6)
- self.RotXEditLine.SetUserMax(6)
- self.RotXEditLine.SetNumberMode()
- self.RotXEditLine.SetText("0.00")
- self.RotXEditLine.Show()
- #RotYSliderBarText
- self.RotYSliderBarText = ui.TextLine()
- wndMgr.SetParent(self.RotYSliderBarText.GetWindowHandle(), self.Board.GetWindowHandle())
- self.RotYSliderBarText.SetPosition(240, 78+25)
- self.RotYSliderBarText.SetText("RotY:")
- self.RotYSliderBarText.Show()
- #RotYSliderBar
- self.RotYSliderBar = ui.SliderBar()
- wndMgr.SetParent(self.RotYSliderBar.GetWindowHandle(), self.Board.GetWindowHandle())
- self.RotYSliderBar.SetPosition(267, 80+25)
- self.RotYSliderBar.SetSliderPos(0.5)
- self.RotYSliderBar.backGroundImage.OnMouseLeftButtonDown = self.ResetSliderPosY
- self.RotYSliderBar.Show()
- #RotYSlot
- self.RotYSlot = ui.ImageBox()
- self.RotYSlot.LoadImage("d:/ymir work/ui/public/Parameter_Slot_00.sub")
- wndMgr.SetParent(self.RotYSlot.GetWindowHandle(), self.Board.GetWindowHandle())
- self.RotYSlot.SetPosition(445, 77+25)
- self.RotYSlot.Show()
- #RotYEditLine
- self.RotYEditLine = ui.EditLine()
- wndMgr.SetParent(self.RotYEditLine.GetWindowHandle(), self.RotYSlot.GetWindowHandle())
- self.RotYEditLine.SetPosition(3, 2)
- self.RotYEditLine.SetSize(30, 18)
- self.RotYEditLine.SetMax(6)
- self.RotYEditLine.SetUserMax(6)
- self.RotYEditLine.SetNumberMode()
- self.RotYEditLine.SetText("0.00")
- self.RotYEditLine.Show()
- #RotZSliderBarText
- self.RotZSliderBarText = ui.TextLine()
- wndMgr.SetParent(self.RotZSliderBarText.GetWindowHandle(), self.Board.GetWindowHandle())
- self.RotZSliderBarText.SetPosition(240, 78+50)
- self.RotZSliderBarText.SetText("RotZ:")
- self.RotZSliderBarText.Show()
- #RotZSliderBar
- self.RotZSliderBar = ui.SliderBar()
- wndMgr.SetParent(self.RotZSliderBar.GetWindowHandle(), self.Board.GetWindowHandle())
- self.RotZSliderBar.SetPosition(267, 80+50)
- self.RotZSliderBar.SetSliderPos(0.5)
- self.RotZSliderBar.backGroundImage.OnMouseLeftButtonDown = self.ResetSliderPosZ
- self.RotZSliderBar.Show()
- #RotZSlot
- self.RotZSlot = ui.ImageBox()
- self.RotZSlot.LoadImage("d:/ymir work/ui/public/Parameter_Slot_00.sub")
- wndMgr.SetParent(self.RotZSlot.GetWindowHandle(), self.Board.GetWindowHandle())
- self.RotZSlot.SetPosition(445, 77+50)
- self.RotZSlot.Show()
- #RotZEditLine
- self.RotZEditLine = ui.EditLine()
- wndMgr.SetParent(self.RotZEditLine.GetWindowHandle(), self.RotZSlot.GetWindowHandle())
- self.RotZEditLine.SetPosition(3, 2)
- self.RotZEditLine.SetSize(30, 18)
- self.RotZEditLine.SetMax(6)
- self.RotZEditLine.SetUserMax(6)
- self.RotZEditLine.SetNumberMode()
- self.RotZEditLine.SetText("0.00")
- self.RotZEditLine.Show()
- #ControlXAxisText
- self.ControlXAxisText = ui.MakeTextLine(self.Board)
- self.ControlXAxisText.SetPosition(15, 0)
- self.ControlXAxisText.SetText("X:")
- #ControlXAxisMinus
- self.ControlXAxisMinus = ui.MakeButton(self.Board, 240, 160, "Decrease", "d:/ymir work/ui/game/windows/", "btn_minus_up.sub", "btn_minus_over.sub", "btn_minus_down.sub")
- self.ControlXAxisMinus.SetEvent(lambda : self.ControlXAxisEditLine.SetText(str(int(self.ControlXAxisEditLine.GetText()) - int(self.IncDecStepEditLine.GetText()))))
- #ControlXAxisSlot
- self.ControlXAxisSlot = ui.MakeImageBox(self.Board, "d:/ymir work/ui/public/Parameter_Slot_00.sub", 255, 157)
- #ControlXAxisEditLine
- self.ControlXAxisEditLine = ui.EditLine()
- wndMgr.SetParent(self.ControlXAxisEditLine.GetWindowHandle(), self.ControlXAxisSlot.GetWindowHandle())
- self.ControlXAxisEditLine.SetPosition(3, 2)
- self.ControlXAxisEditLine.SetSize(30, 18)
- self.ControlXAxisEditLine.SetMax(6)
- self.ControlXAxisEditLine.SetUserMax(6)
- self.ControlXAxisEditLine.SetNumberMode()
- self.ControlXAxisEditLine.SetText("0")
- self.ControlXAxisEditLine.Show()
- #ControlXAxisPlus
- self.ControlXAxisPlus = ui.MakeButton(self.Board, 297, 160, "Increase", "d:/ymir work/ui/game/windows/", "btn_plus_up.sub", "btn_plus_over.sub", "btn_plus_down.sub")
- self.ControlXAxisPlus.SetEvent(lambda : self.ControlXAxisEditLine.SetText(str(int(self.ControlXAxisEditLine.GetText()) + int(self.IncDecStepEditLine.GetText()))))
- #ControlYAxisText
- self.ControlYAxisText = ui.MakeTextLine(self.Board)
- self.ControlYAxisText.SetPosition(77+15, 0)
- self.ControlYAxisText.SetText("Y:")
- #ControlYAxisMinus
- self.ControlYAxisMinus = ui.MakeButton(self.Board, 240+77, 160, "Decrease", "d:/ymir work/ui/game/windows/", "btn_minus_up.sub", "btn_minus_over.sub", "btn_minus_down.sub")
- self.ControlYAxisMinus.SetEvent(lambda : self.ControlYAxisEditLine.SetText(str(int(self.ControlYAxisEditLine.GetText()) - int(self.IncDecStepEditLine.GetText()))))
- #ControlYAxisSlot
- self.ControlYAxisSlot = ui.MakeImageBox(self.Board, "d:/ymir work/ui/public/Parameter_Slot_00.sub", 255+77, 157)
- #ControlYAxisEditLine
- self.ControlYAxisEditLine = ui.EditLine()
- wndMgr.SetParent(self.ControlYAxisEditLine.GetWindowHandle(), self.ControlYAxisSlot.GetWindowHandle())
- self.ControlYAxisEditLine.SetPosition(3, 2)
- self.ControlYAxisEditLine.SetSize(30, 18)
- self.ControlYAxisEditLine.SetMax(6)
- self.ControlYAxisEditLine.SetUserMax(6)
- self.ControlYAxisEditLine.SetNumberMode()
- self.ControlYAxisEditLine.SetText("0")
- self.ControlYAxisEditLine.Show()
- #ControlYAxisPlus
- self.ControlYAxisPlus = ui.MakeButton(self.Board, 297+77, 160, "Increase", "d:/ymir work/ui/game/windows/", "btn_plus_up.sub", "btn_plus_over.sub", "btn_plus_down.sub")
- self.ControlYAxisPlus.SetEvent(lambda : self.ControlYAxisEditLine.SetText(str(int(self.ControlYAxisEditLine.GetText()) + int(self.IncDecStepEditLine.GetText()))))
- #ControlZAxisText
- self.ControlZAxisText = ui.MakeTextLine(self.Board)
- self.ControlZAxisText.SetPosition(77*2+15, 0)
- self.ControlZAxisText.SetText("Z:")
- #ControlZAxisMinus
- self.ControlZAxisMinus = ui.MakeButton(self.Board, 240+77*2, 160, "Decrease", "d:/ymir work/ui/game/windows/", "btn_minus_up.sub", "btn_minus_over.sub", "btn_minus_down.sub")
- self.ControlZAxisMinus.SetEvent(lambda : self.ControlZAxisEditLine.SetText(str(int(self.ControlZAxisEditLine.GetText()) - int(self.IncDecStepEditLine.GetText()))))
- #ControlZAxisSlot
- self.ControlZAxisSlot = ui.MakeImageBox(self.Board, "d:/ymir work/ui/public/Parameter_Slot_00.sub", 255+77*2, 157)
- #ControlZAxisEditLine
- self.ControlZAxisEditLine = ui.EditLine()
- wndMgr.SetParent(self.ControlZAxisEditLine.GetWindowHandle(), self.ControlZAxisSlot.GetWindowHandle())
- self.ControlZAxisEditLine.SetPosition(3, 2)
- self.ControlZAxisEditLine.SetSize(30, 18)
- self.ControlZAxisEditLine.SetMax(6)
- self.ControlZAxisEditLine.SetUserMax(6)
- self.ControlZAxisEditLine.SetNumberMode()
- self.ControlZAxisEditLine.SetText("0")
- self.ControlZAxisEditLine.Show()
- #ControlZAxisPlus
- self.ControlZAxisPlus = ui.MakeButton(self.Board, 297+77*2, 160, "Increase", "d:/ymir work/ui/game/windows/", "btn_plus_up.sub", "btn_plus_over.sub", "btn_plus_down.sub")
- self.ControlZAxisPlus.SetEvent(lambda : self.ControlZAxisEditLine.SetText(str(int(self.ControlZAxisEditLine.GetText()) + int(self.IncDecStepEditLine.GetText()))))
- #Hide Edit-Buttons
- self.ControlXAxisMinus.Hide()
- self.ControlXAxisPlus.Hide()
- self.ControlYAxisMinus.Hide()
- self.ControlYAxisPlus.Hide()
- self.ControlZAxisMinus.Hide()
- self.ControlZAxisPlus.Hide()
- #IncDecStepTextLine
- self.IncDecStepTextLine = ui.TextLine()
- wndMgr.SetParent(self.IncDecStepTextLine.GetWindowHandle(), self.Board.GetWindowHandle())
- self.IncDecStepTextLine.SetPosition(240, 180+2)
- self.IncDecStepTextLine.SetText("Increase/Decrease Step:")
- self.IncDecStepTextLine.Show()
- #IncDecStepSlot
- self.IncDecStepSlot = ui.MakeImageBox(self.Board, "d:/ymir work/ui/public/Parameter_Slot_00.sub", 350, 180)
- #IncDecStepEditLine
- self.IncDecStepEditLine = ui.EditLine()
- wndMgr.SetParent(self.IncDecStepEditLine.GetWindowHandle(), self.IncDecStepSlot.GetWindowHandle())
- self.IncDecStepEditLine.SetPosition(3, 2)
- self.IncDecStepEditLine.SetSize(30, 18)
- self.IncDecStepEditLine.SetMax(6)
- self.IncDecStepEditLine.SetUserMax(6)
- self.IncDecStepEditLine.SetNumberMode()
- self.IncDecStepEditLine.SetText("10")
- self.IncDecStepEditLine.Show()
- #ModeTextLine
- self.ModeTextLine = ui.TextLine()
- wndMgr.SetParent(self.ModeTextLine.GetWindowHandle(), self.Board.GetWindowHandle())
- self.ModeTextLine.SetPosition(240, 200+3)
- self.ModeTextLine.SetText("Mode:")
- self.ModeTextLine.Show()
- #ModeCustomizeButton
- self.ModeCustomizeButton = ui.RadioButton()
- wndMgr.SetParent(self.ModeCustomizeButton.GetWindowHandle(), self.Board.GetWindowHandle())
- self.ModeCustomizeButton.SetPosition(240+35, 200)
- self.ModeCustomizeButton.SetUpVisual("d:/ymir work/ui/public/Middle_Button_01.sub")
- self.ModeCustomizeButton.SetOverVisual("d:/ymir work/ui/public/Middle_Button_02.sub")
- self.ModeCustomizeButton.SetDownVisual("d:/ymir work/ui/public/Middle_Button_03.sub")
- self.ModeCustomizeButton.SetText("Customize")
- self.ModeCustomizeButton.SetUp()
- self.ModeCustomizeButton.SetEvent(ui.__mem_func__(self.OnChangeCustomizeMode))
- self.ModeCustomizeButton.Show()
- #ModeBuildButton
- self.ModeBuildButton = ui.RadioButton()
- wndMgr.SetParent(self.ModeBuildButton.GetWindowHandle(), self.Board.GetWindowHandle())
- self.ModeBuildButton.SetPosition(240+35+65, 200)
- self.ModeBuildButton.SetUpVisual("d:/ymir work/ui/public/Middle_Button_01.sub")
- self.ModeBuildButton.SetOverVisual("d:/ymir work/ui/public/Middle_Button_02.sub")
- self.ModeBuildButton.SetDownVisual("d:/ymir work/ui/public/Middle_Button_03.sub")
- self.ModeBuildButton.SetText("Build")
- self.ModeBuildButton.Down()
- self.ModeBuildButton.SetEvent(ui.__mem_func__(self.OnChangeBuildMode))
- self.ModeBuildButton.Show()
- #ModeTerrainButton
- self.ModeTerrainButton = ui.RadioButton()
- wndMgr.SetParent(self.ModeTerrainButton.GetWindowHandle(), self.Board.GetWindowHandle())
- self.ModeTerrainButton.SetPosition(240+35+65+65, 200)
- self.ModeTerrainButton.SetUpVisual("d:/ymir work/ui/public/Middle_Button_01.sub")
- self.ModeTerrainButton.SetOverVisual("d:/ymir work/ui/public/Middle_Button_02.sub")
- self.ModeTerrainButton.SetDownVisual("d:/ymir work/ui/public/Middle_Button_03.sub")
- self.ModeTerrainButton.SetText("Terrain")
- self.ModeTerrainButton.SetUp()
- #self.ModeTerrainButton.SetEvent(ui.__mem_func__(self.OnChangeBuildMode))
- self.ModeTerrainButton.Disable()
- self.ModeTerrainButton.Hide()
- #InstantBuildTextLine
- self.InstantBuildTextLine = ui.TextLine()
- wndMgr.SetParent(self.InstantBuildTextLine.GetWindowHandle(), self.Board.GetWindowHandle())
- self.InstantBuildTextLine.SetPosition(240, 225+3)
- self.InstantBuildTextLine.SetText("Instant Build:")
- self.InstantBuildTextLine.Show()
- #InstantBuildButtonON
- self.InstantBuildButtonON = ui.RadioButton()
- wndMgr.SetParent(self.InstantBuildButtonON.GetWindowHandle(), self.Board.GetWindowHandle())
- self.InstantBuildButtonON.SetPosition(240+65, 225)
- self.InstantBuildButtonON.SetUpVisual("d:/ymir work/ui/public/Small_Button_01.sub")
- self.InstantBuildButtonON.SetOverVisual("d:/ymir work/ui/public/Small_Button_02.sub")
- self.InstantBuildButtonON.SetDownVisual("d:/ymir work/ui/public/Small_Button_03.sub")
- self.InstantBuildButtonON.SetText("ON")
- self.InstantBuildButtonON.Down()
- self.InstantBuildButtonON.SetEvent(self.EnableInstantBuild)
- self.InstantBuildButtonON.Show()
- #InstantBuildButtonOFF
- self.InstantBuildButtonOFF = ui.RadioButton()
- wndMgr.SetParent(self.InstantBuildButtonOFF.GetWindowHandle(), self.Board.GetWindowHandle())
- self.InstantBuildButtonOFF.SetPosition(240+65+45, 225)
- self.InstantBuildButtonOFF.SetUpVisual("d:/ymir work/ui/public/Small_Button_01.sub")
- self.InstantBuildButtonOFF.SetOverVisual("d:/ymir work/ui/public/Small_Button_02.sub")
- self.InstantBuildButtonOFF.SetDownVisual("d:/ymir work/ui/public/Small_Button_03.sub")
- self.InstantBuildButtonOFF.SetText("OFF")
- self.InstantBuildButtonOFF.SetUp()
- self.InstantBuildButtonOFF.SetEvent(self.DisableInstantBuild)
- self.InstantBuildButtonOFF.Show()
- #NewInstanceButton
- self.NewInstanceButton = ui.Button()
- wndMgr.SetParent(self.NewInstanceButton.GetWindowHandle(), self.Board.GetWindowHandle())
- self.NewInstanceButton.SetPosition(240, 250)
- self.NewInstanceButton.SetUpVisual("d:/ymir work/ui/public/Large_Button_01.sub")
- self.NewInstanceButton.SetOverVisual("d:/ymir work/ui/public/Large_Button_02.sub")
- self.NewInstanceButton.SetDownVisual("d:/ymir work/ui/public/Large_Button_03.sub")
- self.NewInstanceButton.SetText("New Instance")
- self.NewInstanceButton.SetEvent(self.CreateNewInstance)
- self.NewInstanceButton.Hide()
- #ImportButton
- self.ImportButton = ui.Button()
- wndMgr.SetParent(self.ImportButton.GetWindowHandle(), self.Board.GetWindowHandle())
- self.ImportButton.SetPosition(240 + 100, 250)
- self.ImportButton.SetUpVisual("d:/ymir work/ui/public/Middle_Button_01.sub")
- self.ImportButton.SetOverVisual("d:/ymir work/ui/public/Middle_Button_02.sub")
- self.ImportButton.SetDownVisual("d:/ymir work/ui/public/Middle_Button_03.sub")
- self.ImportButton.SetText("Import")
- self.ImportButton.SetEvent(self.ImportMapDialog)
- self.ImportButton.Show()
- #ExportButton
- self.ExportButton = ui.Button()
- wndMgr.SetParent(self.ExportButton.GetWindowHandle(), self.Board.GetWindowHandle())
- self.ExportButton.SetPosition(240 + 100 + 65, 250)
- self.ExportButton.SetUpVisual("d:/ymir work/ui/public/Middle_Button_01.sub")
- self.ExportButton.SetOverVisual("d:/ymir work/ui/public/Middle_Button_02.sub")
- self.ExportButton.SetDownVisual("d:/ymir work/ui/public/Middle_Button_03.sub")
- self.ExportButton.SetText("Export")
- self.ExportButton.SetEvent(self.ExportMapDialog)
- self.ExportButton.Show()
- #Copyright
- self.CopyrightTextLine = ui.TextLine()
- wndMgr.SetParent(self.CopyrightTextLine.GetWindowHandle(), self.Board.GetWindowHandle())
- self.CopyrightTextLine.SetPosition(270+3, 280-3)
- self.CopyrightTextLine.Show()
- #PathComboBox
- self.PathComboBox = ui.ComboBox()
- wndMgr.SetParent(self.PathComboBox.GetWindowHandle(), self.Board.GetWindowHandle())
- self.PathComboBox.listBox.SetTextCenterAlign(0)
- self.PathComboBox.textLine.SetHorizontalAlignLeft()
- self.PathComboBox.textLine.SetWindowHorizontalAlignLeft()
- self.PathComboBox.SetCurrentItem(os.path.abspath(".\\map_object_editor"))
- self.PathComboBox.SetPosition(15, 30)
- self.PathComboBox.SetSize(468, 18)
- self.PathComboBox.SetEvent(ui.__mem_func__(self.OnSelectPath))
- self.PathComboBox.Show()
- self.SetTop()
- self.UpdateFileList(os.path.abspath(".\\map_object_editor"))
- self.DisableInstantBuild()
- def CreateNewInstance(self):
- self.OnChangeBuildMode()
- global CURRENT_INSTANCE
- global CURRENT_VNUM
- global CI_IS_AFFECT
- if CI_IS_AFFECT == FALSE:
- chr.testSetAddRenderModeRGB(CURRENT_INSTANCE, 0.0, 0.0, 0.0)
- self.SaveCurrentInstance()
- CURRENT_INSTANCE = CreateInstance(CURRENT_VNUM)
- def ImportMapDialog(self):
- ImportDialog = uiCommon.InputDialog()
- ImportDialog.Open()
- ImportDialog.SetTitle("Enter a Map-Directory to load the areadata-files from")
- ImportDialog.inputValue.SetText(background.GetCurrentMapName())
- ImportDialog.SetMaxLength(100)
- ImportDialog.SetAcceptEvent(ui.__mem_func__(self.ImportMap))
- ImportDialog.SetCancelEvent(self.ImportMapDialogClose)
- self.ImportDialog = ImportDialog
- def ImportMapDialogClose(self):
- self.ImportDialog.inputValue.KillFocus()
- self.ImportDialog.Close()
- def ImportMap(self):
- if len(self.ImportDialog.GetText()):
- global LoadMap
- LoadMap(self.ImportDialog.GetText())
- self.ImportMapDialogClose()
- return TRUE
- def ExportMapDialog(self):
- ExportDialog = uiCommon.InputDialog()
- ExportDialog.Open()
- ExportDialog.SetTitle("Enter a Map-Directory to store the areadata-files in")
- ExportDialog.inputValue.SetText("C:\\mytestmap")
- ExportDialog.SetMaxLength(100)
- ExportDialog.SetAcceptEvent(ui.__mem_func__(self.ExportMap))
- ExportDialog.SetCancelEvent(self.ExportMapDialogClose)
- self.ExportDialog = ExportDialog
- def ExportMapDialogClose(self):
- self.ExportDialog.inputValue.KillFocus()
- self.ExportDialog.Close()
- def ExportMap(self):
- if len(self.ExportDialog.GetText()):
- global SaveMap
- SaveMap(self.ExportDialog.GetText())
- self.ExportMapDialogClose()
- return TRUE
- def SaveCurrentInstance(self):
- global CURRENT_INSTANCE
- global CURRENT_VNUM
- SaveObject(CURRENT_VNUM, CURRENT_INSTANCE, float(self.ControlXAxisEditLine.GetText()), float(self.ControlYAxisEditLine.GetText()), float(self.ControlZAxisEditLine.GetText()), float(self.RotXEditLine.GetText()), float(self.RotYEditLine.GetText()), float(self.RotZEditLine.GetText()))
- def UpdateCurrentInstance(self):
- global CURRENT_INSTANCE
- global CURRENT_VNUM
- UpdateObject(CURRENT_VNUM, CURRENT_INSTANCE, float(self.ControlXAxisEditLine.GetText()), float(self.ControlYAxisEditLine.GetText()), float(self.ControlZAxisEditLine.GetText()), float(self.RotXEditLine.GetText()), float(self.RotYEditLine.GetText()), float(self.RotZEditLine.GetText()))
- def DisableInstantBuild(self):
- global INSTANT_BUILD
- INSTANT_BUILD = FALSE
- self.InstantBuildButtonON.SetUp()
- self.InstantBuildButtonOFF.Down()
- def EnableInstantBuild(self):
- global INSTANT_BUILD
- INSTANT_BUILD = TRUE
- self.InstantBuildButtonOFF.SetUp()
- self.InstantBuildButtonON.Down()
- def ResetSliderPosX(self):
- if self.RotXSliderBar.GetSliderPos() < 0.5 and float(self.RotXSliderBar.backGroundImage.GetMouseLocalPosition()[0])/float(self.RotXSliderBar.backGroundImage.GetWidth()) > 0.5 or self.RotXSliderBar.GetSliderPos() > 0.5 and float(self.RotXSliderBar.backGroundImage.GetMouseLocalPosition()[0])/float(self.RotXSliderBar.backGroundImage.GetWidth()) < 0.5:
- self.RotXSliderBar.SetSliderPos(0.5)
- else:
- self.RotXSliderBar.SetSliderPos(float(self.RotXSliderBar.backGroundImage.GetMouseLocalPosition()[0])/float(self.RotXSliderBar.backGroundImage.GetWidth()))
- def ResetSliderPosY(self):
- if self.RotYSliderBar.GetSliderPos() < 0.5 and float(self.RotYSliderBar.backGroundImage.GetMouseLocalPosition()[0])/float(self.RotYSliderBar.backGroundImage.GetWidth()) > 0.5 or self.RotYSliderBar.GetSliderPos() > 0.5 and float(self.RotYSliderBar.backGroundImage.GetMouseLocalPosition()[0])/float(self.RotYSliderBar.backGroundImage.GetWidth()) < 0.5:
- self.RotYSliderBar.SetSliderPos(0.5)
- else:
- self.RotYSliderBar.SetSliderPos(float(self.RotYSliderBar.backGroundImage.GetMouseLocalPosition()[0])/float(self.RotYSliderBar.backGroundImage.GetWidth()))
- def ResetSliderPosZ(self):
- if self.RotZSliderBar.GetSliderPos() < 0.5 and float(self.RotZSliderBar.backGroundImage.GetMouseLocalPosition()[0])/float(self.RotZSliderBar.backGroundImage.GetWidth()) > 0.5 or self.RotZSliderBar.GetSliderPos() > 0.5 and float(self.RotZSliderBar.backGroundImage.GetMouseLocalPosition()[0])/float(self.RotZSliderBar.backGroundImage.GetWidth()) < 0.5:
- self.RotZSliderBar.SetSliderPos(0.5)
- else:
- self.RotZSliderBar.SetSliderPos(float(self.RotZSliderBar.backGroundImage.GetMouseLocalPosition()[0])/float(self.RotZSliderBar.backGroundImage.GetWidth()))
- def KillFocus_Callback(self):
- self.RotXEditLine.KillFocus()
- self.RotYEditLine.KillFocus()
- self.RotZEditLine.KillFocus()
- self.ControlXAxisEditLine.KillFocus()
- self.ControlYAxisEditLine.KillFocus()
- self.ControlZAxisEditLine.KillFocus()
- self.IncDecStepEditLine.KillFocus()
- def OnChangeCustomizeMode(self):
- self.ModeBuildButton.SetUp()
- self.ModeCustomizeButton.Down()
- self.ControlXAxisMinus.Show()
- self.ControlXAxisPlus.Show()
- self.ControlYAxisMinus.Show()
- self.ControlYAxisPlus.Show()
- self.ControlZAxisMinus.Show()
- self.ControlZAxisPlus.Show()
- self.NewInstanceButton.Show()
- global CUSTOMIZE_MODE
- CUSTOMIZE_MODE = TRUE
- def OnChangeBuildMode(self):
- self.ModeCustomizeButton.SetUp()
- self.ModeBuildButton.Down()
- self.ControlXAxisMinus.Hide()
- self.ControlXAxisPlus.Hide()
- self.ControlYAxisMinus.Hide()
- self.ControlYAxisPlus.Hide()
- self.ControlZAxisMinus.Hide()
- self.ControlZAxisPlus.Hide()
- global CUSTOMIZE_MODE
- CUSTOMIZE_MODE = FALSE
- self.NewInstanceButton.Hide()
- def OnSelectPath(self):
- self.UpdateFileList(str(self.PathComboBox.listBox.textDict[self.PathComboBox.listBox.selectedLine]))
- self.PathComboBox.CloseListBox()
- def UpdateFileList(self, dir):
- self.ObjectBrowser.dir = dir
- contains = FALSE
- for i in xrange(len(self.PathComboBox.listBox.textDict)):
- if self.PathComboBox.listBox.textDict[i] == dir:
- contains = TRUE
- if contains == FALSE:
- if len(self.PathComboBox.listBox.textDict) == 10:
- self.PathComboBox.listBox.itemList.pop(0)
- self.PathComboBox.InsertItem(0, dir)
- self.PathComboBox.SetCurrentItem(dir)
- self.ObjectBrowser.RemoveAllItems()
- self.ObjectBrowser.AppendItem(Item(" >> .."))
- for filename in os.listdir(dir):
- if os.path.isdir(dir + "\\" + filename):
- self.ObjectBrowser.AppendItem(Item(" >> " + filename))
- for filename in os.listdir(dir):
- if os.path.isfile(dir + "\\" + filename) and (filename[-4:] == ".prb" or filename[-4:] == ".prd" or filename[-4:] == ".pre" or filename[-4:] == ".prt"):
- self.ObjectBrowser.AppendItem(Item(" " + filename))
- if self.ObjectBrowser.GetHeight()/20 >= len(self.ObjectBrowser.itemList):
- self.ObjectBrowserScrollBar.Hide()
- else:
- self.ObjectBrowserScrollBar.SetMiddleBarSize(float(self.ObjectBrowser.GetHeight()/20) / float(len(self.ObjectBrowser.itemList)))
- self.ObjectBrowserScrollBar.Show()
- def OnChangeDirectory(self):
- if (self.ObjectBrowser.GetSelectedItem().GetText() == " >> .."):
- self.UpdateFileList(os.path.abspath(os.path.join(self.ObjectBrowser.dir, '..')))
- return
- if (self.ObjectBrowser.GetSelectedItem().GetText().find(">>") == -1):
- self.OnSelectObject()
- return
- newdir = self.ObjectBrowser.dir + "\\" + self.ObjectBrowser.GetSelectedItem().GetText()[5:]
- if os.path.isdir(newdir):
- self.UpdateFileList(os.path.abspath(os.path.join(self.ObjectBrowser.dir, newdir)))
- def OnSelectObject(self):
- global CUSTOMIZE_MODE
- if CUSTOMIZE_MODE == TRUE:
- self.CreateNewInstance()
- global CURRENT_VNUM
- global CURRENT_INSTANCE
- global CreateRaceFromPRB
- global CreateRaceFromPRT
- global CreateInstance
- path = self.ObjectBrowser.dir.replace("\\", "/") + "/" + self.ObjectBrowser.GetSelectedItem().GetText()[2:]
- if os.path.isfile(path):
- chr.DeleteInstance(CURRENT_INSTANCE)
- if path[-4:] == ".pre":
- CURRENT_VNUM = CreateEffectFromPRE(path)
- elif path[-4:] == ".prt":
- CURRENT_VNUM = CreateRaceFromPRT(path)
- else:
- CURRENT_VNUM = CreateRaceFromPRB(path)
- global ControlWindow
- ControlWindow.PlacementBarText.SetText("Placement-Settings (" + GetObjectName(CURRENT_VNUM) + ")")
- CURRENT_INSTANCE = CreateInstance(CURRENT_VNUM)
- BUILDING_ALPHA = 0.1
- BUILDING_ALPHA_CHANGE = 0.4/app.GetUpdateFPS()/2
- BUILDING_ALPHA_CHANGE_MULTIPLICATOR = 1
- VIRTUAL_INSTANCE_MAX = 0x7FFFFFFF
- VIRTUAL_INSTANCE_INDEX = 0
- CURRENT_INSTANCE = 0
- CURRENT_VNUM = 0
- CI_IS_AFFECT = FALSE
- CREATED_RACES = []
- CREATED_EFFECTS = []
- EFFECT_DICT = {}
- OBJECTS = []
- OBJECT_NAME_DICT = {}
- CUSTOMIZE_MODE = FALSE
- INSTANT_BUILD = TRUE
- DRAG_MODE = FALSE
- old_sliderbar_rx = 0
- old_sliderbar_ry = 0
- old_sliderbar_rz = 0
- GRAB_DIF_X = 0
- GRAB_DIF_Y = 0
- GRAB_Z = 0
- def GrabCurrentInstance():
- global CURRENT_INSTANCE
- global GRAB_DIF_X
- global GRAB_DIF_Y
- global GRAB_Z
- global DRAG_MODE
- px, py, pz = background.GetPickingPoint()
- ox, oy, GRAB_Z = GetObject(CURRENT_INSTANCE).GetPosition()
- GRAB_DIF_X = ox - px
- GRAB_DIF_Y = oy - py
- DRAG_MODE = TRUE
- def DropCurrentInstance():
- global DRAG_MODE
- global GRAB_DIF_X
- global GRAB_DIF_Y
- global GRAB_Z
- global ControlWindow
- DRAG_MODE = FALSE
- GRAB_DIF_X = 0
- GRAB_DIF_Y = 0
- GRAB_Z = 0
- ControlWindow.UpdateCurrentInstance()
- def SelectNextObject(floatX, floatY, floatZ):
- global VIRTUAL_INSTANCE_MAX
- global VIRTUAL_INSTANCE_INDEX
- vid = VIRTUAL_INSTANCE_MAX
- shortest_distance = 40.0
- nearest_vid = 0
- while vid > VIRTUAL_INSTANCE_MAX - VIRTUAL_INSTANCE_INDEX:
- object = GetObject(vid)
- if object == 0:
- vid-=1
- continue
- vidx, vidy, vidz = object.GetPosition()
- #d = 2√( (x2-x1)² + (y2-y1)² + (z2-z1)² )
- distance = pow(( (vidx-floatX)*(vidx-floatX) + (vidy-floatY)*(vidy-floatY) + (vidz-floatZ)*(vidz-floatZ) ), 0.25)
- if distance <= shortest_distance:
- shortest_distance = distance
- nearest_vid = vid
- vid-=1
- if nearest_vid == 0:
- return
- global CURRENT_INSTANCE
- if nearest_vid == CURRENT_INSTANCE:
- GrabCurrentInstance()
- return
- global ControlWindow
- if GetObject(CURRENT_INSTANCE) == 0:
- ControlWindow.SaveCurrentInstance()
- else:
- ControlWindow.UpdateCurrentInstance()
- global CI_IS_AFFECT
- if CI_IS_AFFECT == FALSE:
- chr.testSetAddRenderModeRGB(CURRENT_INSTANCE, 0.0, 0.0, 0.0)
- CI_IS_AFFECT = IsEffect(GetObject(nearest_vid).GetObjectNumber())
- x, y, z = GetObject(nearest_vid).GetPosition()
- ControlWindow.ControlXAxisEditLine.SetText("%.0f" % round(x, 0))
- ControlWindow.ControlYAxisEditLine.SetText("%.0f" % round(y, 0))
- ControlWindow.ControlZAxisEditLine.SetText("%.0f" % round(z, 0))
- rx, ry, rz = GetObject(nearest_vid).GetRotation()
- ControlWindow.RotXEditLine.SetText("%.0f" % round(rx, 2))
- ControlWindow.RotYEditLine.SetText("%.2f" % round(ry, 2))
- ControlWindow.RotZEditLine.SetText("%.2f" % round(rz, 2))
- ControlWindow.RotXSliderBar.SetSliderPos(rx/360+0.5)
- ControlWindow.RotYSliderBar.SetSliderPos(ry/360+0.5)
- ControlWindow.RotZSliderBar.SetSliderPos(rz/360+0.5)
- CURRENT_INSTANCE = nearest_vid
- global CURRENT_VNUM
- CURRENT_VNUM = GetObject(nearest_vid).GetObjectNumber()
- ControlWindow.PlacementBarText.SetText("Placement-Settings (" + GetObjectName(GetObject(nearest_vid).GetObjectNumber()) + ")")
- def OnMouseLeftButtonDown():
- global ControlWindow
- ControlWindow.KillFocus_Callback()
- global CUSTOMIZE_MODE
- if CUSTOMIZE_MODE == TRUE:
- x, y, z = background.GetPickingPoint()
- SelectNextObject(x, y, z)
- else:
- SettleCurrentPosition()
- def OnMouseLeftButtonUp():
- global ControlWindow
- ControlWindow.KillFocus_Callback()
- global DRAG_MODE
- if DRAG_MODE == TRUE:
- DropCurrentInstance()
- #global CUSTOMIZE_MODE
- #if CUSTOMIZE_MODE == TRUE:
- # player.SetMouseState(player.MBT_LEFT, player.MBS_CLICK);
- def OnMouseRightButtonDown():
- global ControlWindow
- ControlWindow.KillFocus_Callback()
- player.SetMouseState(player.MBT_RIGHT, player.MBS_PRESS);
- def OnMouseRightButtonUp():
- global ControlWindow
- ControlWindow.KillFocus_Callback()
- player.SetMouseState(player.MBT_RIGHT, player.MBS_CLICK);
- def OnMouseMiddleButtonDown():
- global ControlWindow
- ControlWindow.KillFocus_Callback()
- player.SetMouseMiddleButtonState(player.MBS_PRESS);
- def OnMouseMiddleButtonUp():
- global ControlWindow
- ControlWindow.KillFocus_Callback()
- player.SetMouseMiddleButtonState(player.MBS_CLICK);
- def SaveObject(id, vid, x, y, z, rx, ry, rz):
- global OBJECTS
- OBJECTS.append(Map3DObject(id, vid, x, y, z, rx, ry, rz))
- def UpdateObject(id, vid, x, y, z, rx, ry, rz):
- o = GetObject(vid)
- o.__init__(id, vid, x, y, z, rx, ry, rz)
- def GetObject(vid):
- global OBJECTS
- for Map3DObject in OBJECTS:
- if Map3DObject.GetVirtualID() == vid:
- return Map3DObject
- return 0
- def DeleteObject(vid):
- item = GetObject(vid)
- if item != 0:
- global OBJECTS
- OBJECTS.remove(item)
- def GetObjectName(id):
- global OBJECT_NAME_DICT
- if OBJECT_NAME_DICT.has_key(id):
- return OBJECT_NAME_DICT[id]
- else:
- return ""
- def SettleCurrentPosition():
- global CURRENT_INSTANCE
- global CURRENT_VNUM
- global INSTANT_BUILD
- global CI_IS_AFFECT
- if CI_IS_AFFECT == FALSE:
- chr.testSetAddRenderModeRGB(CURRENT_INSTANCE, 0.0, 0.0, 0.0)
- global ControlWindow
- if INSTANT_BUILD == TRUE:
- x, y, z = background.GetPickingPoint()
- SaveObject(CURRENT_VNUM, CURRENT_INSTANCE, x, y, z, float(ControlWindow.RotXEditLine.GetText()), float(ControlWindow.RotYEditLine.GetText()), float(ControlWindow.RotZEditLine.GetText()))
- CURRENT_INSTANCE = CreateInstance(CURRENT_VNUM)
- else:
- ControlWindow.OnChangeCustomizeMode()
- wndMgr.OnceIgnoreMouseLeftButtonUpEvent()
- def Update():
- global CURRENT_INSTANCE
- background.SetVisiblePart(background.PART_OBJECT, 0);
- if CURRENT_INSTANCE == 0:
- return
- global CUSTOMIZE_MODE
- global ControlWindow
- if CUSTOMIZE_MODE == TRUE:
- global DRAG_MODE
- if DRAG_MODE == TRUE:
- x, y, z = background.GetPickingPoint()
- global GRAB_DIF_X
- global GRAB_DIF_Y
- global GRAB_Z
- x+=GRAB_DIF_X
- y+=GRAB_DIF_Y
- #z = GRAB_Z
- z = background.GetHeight(x, y)
- ControlWindow.ControlXAxisEditLine.SetText("%.0f" % round(x, 0))
- ControlWindow.ControlYAxisEditLine.SetText("%.0f" % round(y, 0))
- ControlWindow.ControlZAxisEditLine.SetText("%.0f" % round(z, 0))
- cameraX, cameraY, cameraZ = grp.GetCameraPosition()
- grp.RenderLine(100, 200, 300, 400)
- else:
- x = ControlWindow.ControlXAxisEditLine.GetText()
- y = ControlWindow.ControlYAxisEditLine.GetText()
- z = ControlWindow.ControlZAxisEditLine.GetText()
- if app.IsPressed(211) == TRUE:
- DeleteObject(CURRENT_INSTANCE)
- chr.DeleteInstance(CURRENT_INSTANCE)
- CURRENT_INSTANCE = 0
- return
- else:
- x, y, z = background.GetPickingPoint()
- ControlWindow.ControlXAxisEditLine.SetText("%.0f" % round(x, 0))
- ControlWindow.ControlYAxisEditLine.SetText("%.0f" % round(y, 0))
- ControlWindow.ControlZAxisEditLine.SetText("%.0f" % round(z, 0))
- UpdateBuildingAlpha()
- if (chr.HasInstance(CURRENT_INSTANCE) == FALSE):
- global CURRENT_VNUM
- CURRENT_INSTANCE = CreateInstance(CURRENT_VNUM)
- myVid = player.GetMainCharacterIndex()
- chr.SelectInstance(CURRENT_INSTANCE)
- chr.SetPixelPosition(int(x), int(y), int(z))
- UpdateRotation()
- chr.SelectInstance(myVid)
- def UpdateRotation():
- global old_sliderbar_rx
- global old_sliderbar_ry
- global old_sliderbar_rz
- global ControlWindow
- sliderbar_rx = ControlWindow.RotXSliderBar.GetSliderPos()*360-180
- rx = sliderbar_rx
- if (ControlWindow.RotXEditLine.GetText() == ""):
- edit_rx = sliderbar_rx
- else:
- edit_rx = float(ControlWindow.RotXEditLine.GetText())
- if (edit_rx != sliderbar_rx and app.IsPressed(app.DIK_RETURN)):
- rx = edit_rx
- ControlWindow.RotXSliderBar.SetSliderPos(edit_rx/360+0.5)
- elif (sliderbar_rx != old_sliderbar_rx):
- rx = sliderbar_rx
- ControlWindow.RotXEditLine.SetText("%.2f" % round(sliderbar_rx, 2))
- sliderbar_ry = ControlWindow.RotYSliderBar.GetSliderPos()*360-180
- ry = sliderbar_ry
- if (ControlWindow.RotYEditLine.GetText() == ""):
- edit_ry = sliderbar_ry
- else:
- edit_ry = float(ControlWindow.RotYEditLine.GetText())
- if (edit_ry != sliderbar_ry and app.IsPressed(app.DIK_RETURN)):
- ry = edit_ry
- ControlWindow.RotYSliderBar.SetSliderPos(edit_ry/360+0.5)
- elif (sliderbar_ry != old_sliderbar_ry):
- ry = sliderbar_ry
- ControlWindow.RotYEditLine.SetText("%.2f" % round(sliderbar_ry, 2))
- sliderbar_rz = ControlWindow.RotZSliderBar.GetSliderPos()*360-180
- rz = sliderbar_rz
- if (ControlWindow.RotZEditLine.GetText() == ""):
- edit_rz = sliderbar_rz
- else:
- edit_rz = float(ControlWindow.RotZEditLine.GetText())
- if (edit_rz != sliderbar_rz and app.IsPressed(app.DIK_RETURN)):
- rz = edit_rz
- ControlWindow.RotZSliderBar.SetSliderPos(edit_rz/360+0.5)
- elif (sliderbar_rz != old_sliderbar_rz):
- rz = sliderbar_rz
- ControlWindow.RotZEditLine.SetText("%.2f" % round(sliderbar_rz, 2))
- old_sliderbar_rx = sliderbar_rx
- old_sliderbar_ry = sliderbar_ry
- old_sliderbar_rz = sliderbar_rz
- chr.SetRotationAll(rx, ry, rz)
- def UpdateBuildingAlpha():
- global BUILDING_ALPHA
- global BUILDING_ALPHA_CHANGE
- global CURRENT_INSTANCE
- global BUILDING_ALPHA_CHANGE_MULTIPLICATOR
- global CI_IS_AFFECT
- if CI_IS_AFFECT == TRUE:
- return
- BUILDING_ALPHA = BUILDING_ALPHA + BUILDING_ALPHA_CHANGE
- chr.testSetAddRenderModeRGB(CURRENT_INSTANCE, BUILDING_ALPHA, BUILDING_ALPHA, BUILDING_ALPHA)
- if (BUILDING_ALPHA >= 0.4 or BUILDING_ALPHA <= 0):
- BUILDING_ALPHA_CHANGE_MULTIPLICATOR = BUILDING_ALPHA_CHANGE_MULTIPLICATOR * -1
- if app.GetUpdateFPS() != 0:
- BUILDING_ALPHA_CHANGE = (0.4/app.GetUpdateFPS())/2 * BUILDING_ALPHA_CHANGE_MULTIPLICATOR
- else:
- BUILDING_ALPHA_CHANGE = (0.4/30)/2 * BUILDING_ALPHA_CHANGE_MULTIPLICATOR
- def CreateInstance(race):
- global CI_IS_AFFECT
- if IsEffect(race):
- CI_IS_AFFECT = TRUE
- return CreateEffect(race)
- else:
- CI_IS_AFFECT = FALSE
- myVid = player.GetMainCharacterIndex()
- global VIRTUAL_INSTANCE_MAX
- global VIRTUAL_INSTANCE_INDEX
- idx = VIRTUAL_INSTANCE_MAX - VIRTUAL_INSTANCE_INDEX
- VIRTUAL_INSTANCE_INDEX = VIRTUAL_INSTANCE_INDEX + 1
- chr.CreateInstance(idx)
- chr.SelectInstance(idx)
- chr.SetVirtualID(idx)
- chr.SetInstanceType(chr.INSTANCE_TYPE_BUILDING)
- chr.SetRace(race)
- chr.SetArmor(0)
- chr.SetRotation(app.GetRandom(0, 360))
- #chr.SetNameString("test")
- chr.Refresh()
- chr.SetLoopMotion(chr.MOTION_WAIT)
- global BUILDING_ALPHA
- chr.testSetAddRenderModeRGB(idx, BUILDING_ALPHA, BUILDING_ALPHA, BUILDING_ALPHA)
- chr.SelectInstance(myVid)
- return idx
- def CreateEffect(race):
- myVid = player.GetMainCharacterIndex()
- global VIRTUAL_INSTANCE_MAX
- global VIRTUAL_INSTANCE_INDEX
- idx = VIRTUAL_INSTANCE_MAX - VIRTUAL_INSTANCE_INDEX
- VIRTUAL_INSTANCE_INDEX = VIRTUAL_INSTANCE_INDEX + 1
- chr.CreateInstance(idx)
- chr.SelectInstance(idx)
- chr.SetVirtualID(idx)
- chr.SetInstanceType(chr.INSTANCE_TYPE_BUILDING)
- chr.SetRace(0)
- chr.SetArmor(0)
- chr.SetRotation(app.GetRandom(0, 360))
- chr.Refresh()
- chr.SetLoopMotion(chr.MOTION_WAIT)
- global EFFECT_DICT
- #chrmgr.RegisterEffect(27+50, "Bip01", EFFECT_DICT[race])
- chrmgr.RegisterEffect(27+50, "", EFFECT_DICT[race])
- chrmgr.SetAffect(idx, 50, 1)
- chr.SetBlendRenderMode(idx, 0.0)
- chr.SelectInstance(myVid)
- return idx
- def AttachingData():
- """
- Group ShapeData
- {
- PathName ""
- ShapeDataCount 0
- }
- Group AttachingData
- {
- AttachingDataCount 2
- Group AttachingData00
- {
- AttachingDataType 1
- isAttaching 0
- AttachingModelIndex 0
- AttachingBoneName "Box01"
- CollisionType 1
- SphereDataCount 1
- Group SphereData00
- {
- Radius 60.000000
- Position 0.000000 0.000000 50.000000
- }
- }
- Group AttachingData01
- {
- AttachingDataType 1
- isAttaching 1
- AttachingModelIndex 0
- AttachingBoneName "ore"
- CollisionType 3
- SphereDataCount 1
- Group SphereData00
- {
- Radius 70.000000
- Position 0.000000 0.000000 50.000000
- }
- }
- }
- """
- def CreateRaceFromPRB(file):
- prbfile = open(file, "r").read().split("\n")
- vnum = long(prbfile[1].strip())
- if (vnum > 0x7FFFFFFF):
- vnum = vnum*-1 + 0x7FFFFFFF
- global CREATED_RACES
- if vnum in CREATED_RACES:
- return vnum
- CREATED_RACES.append(vnum)
- gr2path = prbfile[2].split("\"")[1]
- open("map_object_editor/CreateRaceFromPRB.msm", "w+").write("ScriptType RaceDataScript\n\nBaseModelFileName \"" + gr2path + "\"\n"+ AttachingData.__doc__)
- chrmgr.CreateRace(vnum)
- chrmgr.SelectRace(vnum)
- chrmgr.SetPathName("map_object_editor/")
- chrmgr.LoadRaceData("CreateRaceFromPRB.msm")
- chrmgr.RegisterAttachingBoneName(chr.PART_WEAPON, "equip_right_hand")
- global OBJECT_NAME_DICT
- OBJECT_NAME_DICT[vnum] = os.path.basename(file)
- return vnum
- def CreateRaceFromPRT(file):
- prtfile = open(file, "r").read().split("\n")
- vnum = long(prtfile[1].strip())
- if (vnum > 0x7FFFFFFF):
- vnum = vnum*-1 + 0x7FFFFFFF
- global CREATED_RACES
- if vnum in CREATED_RACES:
- return vnum
- CREATED_RACES.append(vnum)
- sptpath = prtfile[4].split("\"")[1]
- open("map_object_editor/CreateRaceFromPRT.msm", "w+").write("ScriptType RaceDataScript\n\nTreeFileName \"" + str(sptpath) + "\"\n"+ AttachingData.__doc__)
- chrmgr.CreateRace(vnum)
- chrmgr.SelectRace(vnum)
- chrmgr.SetPathName("map_object_editor/")
- chrmgr.LoadRaceData("CreateRaceFromPRT.msm")
- chrmgr.RegisterAttachingBoneName(chr.PART_WEAPON, "equip_right_hand")
- global OBJECT_NAME_DICT
- OBJECT_NAME_DICT[vnum] = os.path.basename(file)
- return vnum
- def CreateEffectFromPRE(file):
- prbfile = open(file, "r").read().split("\n")
- vnum = long(prbfile[1].strip())
- #if (vnum > 0x7FFFFFFF):
- #vnum = vnum*-1 + 0x7FFFFFFF
- global EFFECT_DICT
- if EFFECT_DICT.has_key(vnum):
- return vnum
- msepath = prbfile[2].split("\"")[1]
- #chrmgr.RegisterEffect(vnum, "Bip01", msepath)
- #dbg.TraceError("EFFECT_DICT[" + str(vnum) + "] = " + msepath)
- EFFECT_DICT[vnum] = msepath
- global OBJECT_NAME_DICT
- OBJECT_NAME_DICT[vnum] = os.path.basename(file)
- return vnum
- def IsEffect(vnum):
- global EFFECT_DICT
- return EFFECT_DICT.has_key(vnum)
- def dirwalk(dir):
- "walk a directory tree, using a generator (Snippet from http://code.activestate.com/recipes/105873-walk-a-directory-tree-using-a-generator/)"
- for f in os.listdir(dir):
- fullpath = os.path.join(dir,f)
- if os.path.isdir(fullpath) and not os.path.islink(fullpath):
- for x in dirwalk(fullpath): # recurse into subdir
- yield x
- else:
- yield fullpath
- def LoadAllObjects():
- for elem in dirwalk("map_object_editor"):
- if elem[-4:] == ".prb" or elem[-4:] == ".prd":
- CreateRaceFromPRB(elem)
- elif elem[-4:] == ".pre":
- CreateEffectFromPRE(elem)
- elif elem[-4:] == ".prt":
- CreateRaceFromPRT(elem)
- def LoadAreaData(filename):
- global BUILDING_ALPHA
- BUILDING_ALPHA = 0
- myVid = player.GetMainCharacterIndex()
- global CURRENT_INSTANCE
- areadata = pack.Get(filename).split("\n")
- #dbg.TraceError("areadata =" + str(filename))
- for i in xrange(len(areadata)):
- line = areadata[i].strip()
- if line.startswith("Start Object"):
- pos = areadata[i+1].strip().split()
- vnum = long(areadata[i+2].strip())
- #dbg.TraceError("truevnum =" + str(vnum))
- if (vnum > 0x7FFFFFFF and IsEffect(vnum) == FALSE):
- vnum = vnum*-1 + 0x7FFFFFFF
- global CREATED_RACES
- if not vnum in CREATED_RACES and IsEffect(vnum) == FALSE:
- rot = areadata[i+3].strip().split("#")
- additional_height = areadata[i+4].strip()
- SaveObject(vnum, -1, float(pos[0]), float(pos[1])*-1, float(pos[2])+float(additional_height), float(rot[0]), float(rot[1]), float(rot[2]))
- continue
- rot = areadata[i+3].strip().split("#")
- additional_height = areadata[i+4].strip()
- #dbg.TraceError("object=" + line + " vnum=" + str(vnum) + " vid=" + str(CURRENT_INSTANCE) + " x=" + str(float(pos[0])) + " y=" + str(float(pos[1])*-1) + " z=" + str(float(pos[2])) + " ry=" + str(float(rot[0])) + " rx=" + str(float(rot[1])) + " rz=" + str(float(rot[2])))
- CURRENT_INSTANCE = CreateInstance(vnum)
- chr.SelectInstance(CURRENT_INSTANCE)
- chr.SetPixelPosition(int(float(pos[0])), int(float(pos[1]))*-1, int(float(pos[2])+float(additional_height)))
- chr.SetRotationAll(float(rot[0]), float(rot[1]), float(rot[2]))
- SaveObject(vnum, CURRENT_INSTANCE, float(pos[0]), float(pos[1])*-1, float(pos[2])+float(additional_height), float(rot[0]), float(rot[1]), float(rot[2]))
- chr.SelectInstance(myVid)
- def LoadCurrentMap():
- LoadMap(background.GetCurrentMapName())
- def LoadMap(dir):
- SizeX, SizeY = GetMapSize(dir)
- for squareX in xrange(SizeX):
- for squareY in xrange(SizeY):
- LoadAreaData(dir + "/%.3i%.3i/areadata.txt" % (squareX, squareY))
- def GetMapSize(dir):
- mapSettings = pack.Get(dir + "/setting.txt")
- SizeX = int(mapSettings.split()[9])
- SizeY = int(mapSettings.split()[10])
- return SizeX, SizeY
- def SaveMap(dir):
- SizeX, SizeY = GetMapSize(background.GetCurrentMapName())
- for squareX in xrange(SizeX):
- for squareY in xrange(SizeY):
- ensure_dir(dir + "\\%.3i%.3i\\areadata.txt" % (squareX, squareY))
- SaveAreaData(dir + "\\%.3i%.3i\\areadata.txt" % (squareX, squareY), (squareX)*255*100, (squareY)*255*100, (squareX+1)*255*100, (squareY+1)*255*100)
- def ensure_dir(f):
- d = os.path.dirname(f)
- if not os.path.exists(d):
- os.makedirs(d)
- def SaveAreaData(filename, startX, startY, endX, endY):
- global VIRTUAL_INSTANCE_MAX
- global VIRTUAL_INSTANCE_INDEX
- vid = VIRTUAL_INSTANCE_MAX
- file = open(filename, "w+")
- file.write("AreaDataFile\n\n")
- #file.write("FROM (%d, %d) TO (%d, %d)\n" %(startX, startY, endX, endY))
- objectcount = 0
- while vid > VIRTUAL_INSTANCE_MAX - VIRTUAL_INSTANCE_INDEX:
- object = GetObject(vid)
- if object == 0:
- vid-=1
- continue
- vidx, vidy, vidz = object.GetPosition()
- vrx, vry, vrz = object.GetRotation()
- if (vidx >= startX and vidy >= startY and vidx < endX and vidy < endY):
- file.write("Start Object%.3i\n %.6f -%.6f %.6f\n %d\n %.6f#%.6f#%.6f\n %.6f\nEnd Object\n" % (objectcount, vidx, vidy, vidz, object.GetRealID(), vrx, vry, vrz, 0))
- objectcount+=1
- vid-=1
- file.write("\nObjectCount " + str(objectcount))
- chat.AppendChat(chat.CHAT_TYPE_INFO, "Ingame Map-Editor by musicinstructor")
- LoadAllObjects()
- LoadCurrentMap()
- CURRENT_VNUM = 944313422
- CURRENT_INSTANCE = CreateInstance(CURRENT_VNUM)
- #CURRENT_INSTANCE = CreateEffect(780392666)
- #CI_IS_AFFECT = TRUE
- app.SetCameraMaxDistance(350000)
- app.SetMinFog(350000)
- mapeditMain = ui.Window()
- mapeditMain.OnUpdate = Update
- mapeditMain.OnMouseLeftButtonDown = OnMouseLeftButtonDown
- mapeditMain.OnMouseLeftButtonUp = OnMouseLeftButtonUp
- mapeditMain.OnMouseRightButtonDown = OnMouseRightButtonDown
- mapeditMain.OnMouseRightButtonUp = OnMouseRightButtonUp
- mapeditMain.OnMouseMiddleButtonDown = OnMouseMiddleButtonDown
- mapeditMain.OnMouseMiddleButtonUp = OnMouseMiddleButtonUp
- mapeditMain.SetSize(systemSetting.GetWidth(), systemSetting.GetHeight())
- mapeditMain.Show()
- ControlWindow = MapEditor()
- ControlWindow.Show()
Advertisement
Add Comment
Please, Sign In to add comment