Guest User

Untitled

a guest
Oct 21st, 2017
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 46.14 KB | None | 0 0
  1. from __future__ import generators
  2. import ui
  3. import chat
  4. import chrmgr
  5. import app
  6. import player
  7. import math
  8. import background
  9. import grp
  10. import wndMgr
  11. import chr
  12. import nonplayer
  13. import systemSetting
  14. import os
  15. import pack
  16. import dbg
  17. import uiCommon
  18.  
  19. class Map3DObject(object):
  20.     def __init__(self, id, vid, x, y, z, rx, ry, rz):
  21.         self.id = id
  22.         self.vid = vid
  23.         self.x = x
  24.         self.y = y
  25.         self.z = z
  26.         self.rx = rx
  27.         self.ry = ry
  28.         self.rz = rz
  29.    
  30.     def GetPosition(self):
  31.         return self.x, self.y, self.z
  32.  
  33.     def GetRotation(self):
  34.         return self.rx, self.ry, self.rz
  35.  
  36.     def GetVirtualID(self):
  37.         return self.vid
  38.    
  39.     def GetRealID(self):
  40.         if self.id >= 0:
  41.             return self.id
  42.         else:
  43.             return (self.id - 0x7FFFFFFF)*-1
  44.  
  45.     def GetObjectNumber(self):
  46.         return self.id
  47.  
  48. class Item(ui.ListBoxEx.Item):
  49.     def __init__(self, fileName):
  50.         ui.ListBoxEx.Item.__init__(self)
  51.         self.canLoad=0
  52.         self.text=fileName
  53.         self.textLine=self.__CreateTextLine(fileName)
  54.  
  55.     def __del__(self):
  56.         ui.ListBoxEx.Item.__del__(self)
  57.  
  58.     def GetText(self):
  59.         return self.text
  60.  
  61.     def OnMouseLeftButtonDoubleClick(self):
  62.         self.parent.OnMouseLeftButtonDoubleClick()
  63.  
  64.     def __CreateTextLine(self, fileName):
  65.         textLine=ui.TextLine()
  66.         textLine.SetParent(self)
  67.         textLine.SetPosition(0, 0)
  68.         textLine.SetText(fileName)
  69.         textLine.Show()
  70.         return textLine
  71.  
  72. class MapEditor(ui.ScriptWindow):
  73.     def __init__(self):
  74.         ui.ScriptWindow.__init__(self)
  75.         self.ClearDictionary()
  76.         #Board
  77.         self.Board = ui.BoardWithTitleBar()
  78.         self.Board.AddFlag("movable")
  79.         self.Board.AddFlag("float")
  80.         self.Board.SetTitleName("Map-Editor")
  81.         self.Board.SetSize(500, 300)
  82.         self.Board.SetPosition(30, systemSetting.GetHeight() - self.Board.GetHeight() - 70)
  83.         self.Board.Show()
  84.         self.Board.SetTop()
  85.         #ObjectBrowserScrollBar
  86.         self.ObjectBrowserScrollBar = ui.ScrollBar()
  87.         wndMgr.SetParent(self.ObjectBrowserScrollBar.GetWindowHandle(), self.Board.GetWindowHandle())
  88.         self.ObjectBrowserScrollBar.SetScrollBarSize(215)
  89.         self.ObjectBrowserScrollBar.SetPosition(220, 50)
  90.         self.ObjectBrowserScrollBar.Show()
  91.         #ObjectBrowserBar
  92.         self.ObjectBrowserBar = ui.SlotBar()
  93.         wndMgr.SetParent(self.ObjectBrowserBar.GetWindowHandle(), self.Board.GetWindowHandle())
  94.         self.ObjectBrowserBar.SetSize(200, 215)
  95.         self.ObjectBrowserBar.SetPosition(15, 50)
  96.         self.ObjectBrowserBar.Show()
  97.         #ObjectBrowser
  98.         self.ObjectBrowser = ui.ListBoxEx()
  99.         wndMgr.SetParent(self.ObjectBrowser.GetWindowHandle(), self.ObjectBrowserBar.GetWindowHandle())
  100.         self.ObjectBrowser.SetSize(200, 215)
  101.         self.ObjectBrowser.SetItemSize(200, 20)
  102.         self.ObjectBrowser.SetPosition(0, 1)
  103.         self.ObjectBrowser.SetViewItemCount(10)
  104.         self.ObjectBrowser.OnMouseLeftButtonDoubleClick = self.OnChangeDirectory
  105.         self.ObjectBrowser.SetScrollBar(self.ObjectBrowserScrollBar)
  106.         self.ObjectBrowser.Show()
  107.         #PlacementBar
  108.         self.PlacementBar = ui.HorizontalBar()
  109.         wndMgr.SetParent(self.PlacementBar.GetWindowHandle(), self.Board.GetWindowHandle())
  110.         self.PlacementBar.SetPosition(240, 55)
  111.         self.PlacementBar.Create(244)
  112.         self.PlacementBar.Show()
  113.         #PlacementBarText
  114.         self.PlacementBarText = ui.TextLine()
  115.         wndMgr.SetParent(self.PlacementBarText.GetWindowHandle(), self.PlacementBar.GetWindowHandle())
  116.         self.PlacementBarText.SetPosition(3, 2)
  117.         self.PlacementBarText.SetText("Placement-Settings")
  118.         self.PlacementBarText.Show()
  119.         #RotXSliderBarText
  120.         self.RotXSliderBarText = ui.TextLine()
  121.         wndMgr.SetParent(self.RotXSliderBarText.GetWindowHandle(), self.Board.GetWindowHandle())
  122.         self.RotXSliderBarText.SetPosition(240, 78)
  123.         self.RotXSliderBarText.SetText("RotX:")
  124.         self.RotXSliderBarText.Show()
  125.         #RotXSliderBar
  126.         self.RotXSliderBar = ui.SliderBar()
  127.         wndMgr.SetParent(self.RotXSliderBar.GetWindowHandle(), self.Board.GetWindowHandle())
  128.         self.RotXSliderBar.SetPosition(267, 80)
  129.         self.RotXSliderBar.SetSliderPos(0.5)
  130.         self.RotXSliderBar.backGroundImage.OnMouseLeftButtonDown = self.ResetSliderPosX
  131.         self.RotXSliderBar.Show()
  132.         #RotXSlot
  133.         self.RotXSlot = ui.ImageBox()
  134.         self.RotXSlot.LoadImage("d:/ymir work/ui/public/Parameter_Slot_00.sub")
  135.         wndMgr.SetParent(self.RotXSlot.GetWindowHandle(), self.Board.GetWindowHandle())
  136.         self.RotXSlot.SetPosition(445, 77)
  137.         self.RotXSlot.Show()
  138.         #RotXEditLine
  139.         self.RotXEditLine = ui.EditLine()
  140.         wndMgr.SetParent(self.RotXEditLine.GetWindowHandle(), self.RotXSlot.GetWindowHandle())
  141.         self.RotXEditLine.SetPosition(3, 2)
  142.         self.RotXEditLine.SetSize(30, 18)
  143.         self.RotXEditLine.SetMax(6)
  144.         self.RotXEditLine.SetUserMax(6)
  145.         self.RotXEditLine.SetNumberMode()
  146.         self.RotXEditLine.SetText("0.00")
  147.         self.RotXEditLine.Show()
  148.         #RotYSliderBarText
  149.         self.RotYSliderBarText = ui.TextLine()
  150.         wndMgr.SetParent(self.RotYSliderBarText.GetWindowHandle(), self.Board.GetWindowHandle())
  151.         self.RotYSliderBarText.SetPosition(240, 78+25)
  152.         self.RotYSliderBarText.SetText("RotY:")
  153.         self.RotYSliderBarText.Show()
  154.         #RotYSliderBar
  155.         self.RotYSliderBar = ui.SliderBar()
  156.         wndMgr.SetParent(self.RotYSliderBar.GetWindowHandle(), self.Board.GetWindowHandle())
  157.         self.RotYSliderBar.SetPosition(267, 80+25)
  158.         self.RotYSliderBar.SetSliderPos(0.5)
  159.         self.RotYSliderBar.backGroundImage.OnMouseLeftButtonDown = self.ResetSliderPosY
  160.         self.RotYSliderBar.Show()
  161.         #RotYSlot
  162.         self.RotYSlot = ui.ImageBox()
  163.         self.RotYSlot.LoadImage("d:/ymir work/ui/public/Parameter_Slot_00.sub")
  164.         wndMgr.SetParent(self.RotYSlot.GetWindowHandle(), self.Board.GetWindowHandle())
  165.         self.RotYSlot.SetPosition(445, 77+25)
  166.         self.RotYSlot.Show()
  167.         #RotYEditLine
  168.         self.RotYEditLine = ui.EditLine()
  169.         wndMgr.SetParent(self.RotYEditLine.GetWindowHandle(), self.RotYSlot.GetWindowHandle())
  170.         self.RotYEditLine.SetPosition(3, 2)
  171.         self.RotYEditLine.SetSize(30, 18)
  172.         self.RotYEditLine.SetMax(6)
  173.         self.RotYEditLine.SetUserMax(6)
  174.         self.RotYEditLine.SetNumberMode()
  175.         self.RotYEditLine.SetText("0.00")
  176.         self.RotYEditLine.Show()
  177.         #RotZSliderBarText
  178.         self.RotZSliderBarText = ui.TextLine()
  179.         wndMgr.SetParent(self.RotZSliderBarText.GetWindowHandle(), self.Board.GetWindowHandle())
  180.         self.RotZSliderBarText.SetPosition(240, 78+50)
  181.         self.RotZSliderBarText.SetText("RotZ:")
  182.         self.RotZSliderBarText.Show()
  183.         #RotZSliderBar
  184.         self.RotZSliderBar = ui.SliderBar()
  185.         wndMgr.SetParent(self.RotZSliderBar.GetWindowHandle(), self.Board.GetWindowHandle())
  186.         self.RotZSliderBar.SetPosition(267, 80+50)
  187.         self.RotZSliderBar.SetSliderPos(0.5)
  188.         self.RotZSliderBar.backGroundImage.OnMouseLeftButtonDown = self.ResetSliderPosZ
  189.         self.RotZSliderBar.Show()
  190.         #RotZSlot
  191.         self.RotZSlot = ui.ImageBox()
  192.         self.RotZSlot.LoadImage("d:/ymir work/ui/public/Parameter_Slot_00.sub")
  193.         wndMgr.SetParent(self.RotZSlot.GetWindowHandle(), self.Board.GetWindowHandle())
  194.         self.RotZSlot.SetPosition(445, 77+50)
  195.         self.RotZSlot.Show()
  196.         #RotZEditLine
  197.         self.RotZEditLine = ui.EditLine()
  198.         wndMgr.SetParent(self.RotZEditLine.GetWindowHandle(), self.RotZSlot.GetWindowHandle())
  199.         self.RotZEditLine.SetPosition(3, 2)
  200.         self.RotZEditLine.SetSize(30, 18)
  201.         self.RotZEditLine.SetMax(6)
  202.         self.RotZEditLine.SetUserMax(6)
  203.         self.RotZEditLine.SetNumberMode()
  204.         self.RotZEditLine.SetText("0.00")
  205.         self.RotZEditLine.Show()
  206.         #ControlXAxisText
  207.         self.ControlXAxisText = ui.MakeTextLine(self.Board)
  208.         self.ControlXAxisText.SetPosition(15, 0)
  209.         self.ControlXAxisText.SetText("X:")
  210.         #ControlXAxisMinus
  211.         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")
  212.         self.ControlXAxisMinus.SetEvent(lambda : self.ControlXAxisEditLine.SetText(str(int(self.ControlXAxisEditLine.GetText()) - int(self.IncDecStepEditLine.GetText()))))
  213.         #ControlXAxisSlot
  214.         self.ControlXAxisSlot = ui.MakeImageBox(self.Board, "d:/ymir work/ui/public/Parameter_Slot_00.sub", 255, 157)
  215.         #ControlXAxisEditLine
  216.         self.ControlXAxisEditLine = ui.EditLine()
  217.         wndMgr.SetParent(self.ControlXAxisEditLine.GetWindowHandle(), self.ControlXAxisSlot.GetWindowHandle())
  218.         self.ControlXAxisEditLine.SetPosition(3, 2)
  219.         self.ControlXAxisEditLine.SetSize(30, 18)
  220.         self.ControlXAxisEditLine.SetMax(6)
  221.         self.ControlXAxisEditLine.SetUserMax(6)
  222.         self.ControlXAxisEditLine.SetNumberMode()
  223.         self.ControlXAxisEditLine.SetText("0")
  224.         self.ControlXAxisEditLine.Show()
  225.         #ControlXAxisPlus
  226.         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")
  227.         self.ControlXAxisPlus.SetEvent(lambda : self.ControlXAxisEditLine.SetText(str(int(self.ControlXAxisEditLine.GetText()) + int(self.IncDecStepEditLine.GetText()))))
  228.         #ControlYAxisText
  229.         self.ControlYAxisText = ui.MakeTextLine(self.Board)
  230.         self.ControlYAxisText.SetPosition(77+15, 0)
  231.         self.ControlYAxisText.SetText("Y:")
  232.         #ControlYAxisMinus
  233.         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")
  234.         self.ControlYAxisMinus.SetEvent(lambda : self.ControlYAxisEditLine.SetText(str(int(self.ControlYAxisEditLine.GetText()) - int(self.IncDecStepEditLine.GetText()))))
  235.         #ControlYAxisSlot
  236.         self.ControlYAxisSlot = ui.MakeImageBox(self.Board, "d:/ymir work/ui/public/Parameter_Slot_00.sub", 255+77, 157)
  237.         #ControlYAxisEditLine
  238.         self.ControlYAxisEditLine = ui.EditLine()
  239.         wndMgr.SetParent(self.ControlYAxisEditLine.GetWindowHandle(), self.ControlYAxisSlot.GetWindowHandle())
  240.         self.ControlYAxisEditLine.SetPosition(3, 2)
  241.         self.ControlYAxisEditLine.SetSize(30, 18)
  242.         self.ControlYAxisEditLine.SetMax(6)
  243.         self.ControlYAxisEditLine.SetUserMax(6)
  244.         self.ControlYAxisEditLine.SetNumberMode()
  245.         self.ControlYAxisEditLine.SetText("0")
  246.         self.ControlYAxisEditLine.Show()
  247.         #ControlYAxisPlus
  248.         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")
  249.         self.ControlYAxisPlus.SetEvent(lambda : self.ControlYAxisEditLine.SetText(str(int(self.ControlYAxisEditLine.GetText()) + int(self.IncDecStepEditLine.GetText()))))
  250.         #ControlZAxisText
  251.         self.ControlZAxisText = ui.MakeTextLine(self.Board)
  252.         self.ControlZAxisText.SetPosition(77*2+15, 0)
  253.         self.ControlZAxisText.SetText("Z:")
  254.         #ControlZAxisMinus
  255.         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")
  256.         self.ControlZAxisMinus.SetEvent(lambda : self.ControlZAxisEditLine.SetText(str(int(self.ControlZAxisEditLine.GetText()) - int(self.IncDecStepEditLine.GetText()))))
  257.         #ControlZAxisSlot
  258.         self.ControlZAxisSlot = ui.MakeImageBox(self.Board, "d:/ymir work/ui/public/Parameter_Slot_00.sub", 255+77*2, 157)
  259.         #ControlZAxisEditLine
  260.         self.ControlZAxisEditLine = ui.EditLine()
  261.         wndMgr.SetParent(self.ControlZAxisEditLine.GetWindowHandle(), self.ControlZAxisSlot.GetWindowHandle())
  262.         self.ControlZAxisEditLine.SetPosition(3, 2)
  263.         self.ControlZAxisEditLine.SetSize(30, 18)
  264.         self.ControlZAxisEditLine.SetMax(6)
  265.         self.ControlZAxisEditLine.SetUserMax(6)
  266.         self.ControlZAxisEditLine.SetNumberMode()
  267.         self.ControlZAxisEditLine.SetText("0")
  268.         self.ControlZAxisEditLine.Show()
  269.         #ControlZAxisPlus
  270.         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")
  271.         self.ControlZAxisPlus.SetEvent(lambda : self.ControlZAxisEditLine.SetText(str(int(self.ControlZAxisEditLine.GetText()) + int(self.IncDecStepEditLine.GetText()))))
  272.         #Hide Edit-Buttons
  273.         self.ControlXAxisMinus.Hide()
  274.         self.ControlXAxisPlus.Hide()
  275.         self.ControlYAxisMinus.Hide()
  276.         self.ControlYAxisPlus.Hide()
  277.         self.ControlZAxisMinus.Hide()
  278.         self.ControlZAxisPlus.Hide()
  279.         #IncDecStepTextLine
  280.         self.IncDecStepTextLine = ui.TextLine()
  281.         wndMgr.SetParent(self.IncDecStepTextLine.GetWindowHandle(), self.Board.GetWindowHandle())
  282.         self.IncDecStepTextLine.SetPosition(240, 180+2)
  283.         self.IncDecStepTextLine.SetText("Increase/Decrease Step:")
  284.         self.IncDecStepTextLine.Show()
  285.         #IncDecStepSlot
  286.         self.IncDecStepSlot = ui.MakeImageBox(self.Board, "d:/ymir work/ui/public/Parameter_Slot_00.sub", 350, 180)
  287.         #IncDecStepEditLine
  288.         self.IncDecStepEditLine = ui.EditLine()
  289.         wndMgr.SetParent(self.IncDecStepEditLine.GetWindowHandle(), self.IncDecStepSlot.GetWindowHandle())
  290.         self.IncDecStepEditLine.SetPosition(3, 2)
  291.         self.IncDecStepEditLine.SetSize(30, 18)
  292.         self.IncDecStepEditLine.SetMax(6)
  293.         self.IncDecStepEditLine.SetUserMax(6)
  294.         self.IncDecStepEditLine.SetNumberMode()
  295.         self.IncDecStepEditLine.SetText("10")
  296.         self.IncDecStepEditLine.Show()
  297.         #ModeTextLine
  298.         self.ModeTextLine = ui.TextLine()
  299.         wndMgr.SetParent(self.ModeTextLine.GetWindowHandle(), self.Board.GetWindowHandle())
  300.         self.ModeTextLine.SetPosition(240, 200+3)
  301.         self.ModeTextLine.SetText("Mode:")
  302.         self.ModeTextLine.Show()
  303.         #ModeCustomizeButton
  304.         self.ModeCustomizeButton = ui.RadioButton()
  305.         wndMgr.SetParent(self.ModeCustomizeButton.GetWindowHandle(), self.Board.GetWindowHandle())
  306.         self.ModeCustomizeButton.SetPosition(240+35, 200)
  307.         self.ModeCustomizeButton.SetUpVisual("d:/ymir work/ui/public/Middle_Button_01.sub")
  308.         self.ModeCustomizeButton.SetOverVisual("d:/ymir work/ui/public/Middle_Button_02.sub")
  309.         self.ModeCustomizeButton.SetDownVisual("d:/ymir work/ui/public/Middle_Button_03.sub")
  310.         self.ModeCustomizeButton.SetText("Customize")
  311.         self.ModeCustomizeButton.SetUp()
  312.         self.ModeCustomizeButton.SetEvent(ui.__mem_func__(self.OnChangeCustomizeMode))
  313.         self.ModeCustomizeButton.Show()
  314.         #ModeBuildButton
  315.         self.ModeBuildButton = ui.RadioButton()
  316.         wndMgr.SetParent(self.ModeBuildButton.GetWindowHandle(), self.Board.GetWindowHandle())
  317.         self.ModeBuildButton.SetPosition(240+35+65, 200)
  318.         self.ModeBuildButton.SetUpVisual("d:/ymir work/ui/public/Middle_Button_01.sub")
  319.         self.ModeBuildButton.SetOverVisual("d:/ymir work/ui/public/Middle_Button_02.sub")
  320.         self.ModeBuildButton.SetDownVisual("d:/ymir work/ui/public/Middle_Button_03.sub")
  321.         self.ModeBuildButton.SetText("Build")
  322.         self.ModeBuildButton.Down()
  323.         self.ModeBuildButton.SetEvent(ui.__mem_func__(self.OnChangeBuildMode))
  324.         self.ModeBuildButton.Show()
  325.         #ModeTerrainButton
  326.         self.ModeTerrainButton = ui.RadioButton()
  327.         wndMgr.SetParent(self.ModeTerrainButton.GetWindowHandle(), self.Board.GetWindowHandle())
  328.         self.ModeTerrainButton.SetPosition(240+35+65+65, 200)
  329.         self.ModeTerrainButton.SetUpVisual("d:/ymir work/ui/public/Middle_Button_01.sub")
  330.         self.ModeTerrainButton.SetOverVisual("d:/ymir work/ui/public/Middle_Button_02.sub")
  331.         self.ModeTerrainButton.SetDownVisual("d:/ymir work/ui/public/Middle_Button_03.sub")
  332.         self.ModeTerrainButton.SetText("Terrain")
  333.         self.ModeTerrainButton.SetUp()
  334.         #self.ModeTerrainButton.SetEvent(ui.__mem_func__(self.OnChangeBuildMode))
  335.         self.ModeTerrainButton.Disable()
  336.         self.ModeTerrainButton.Hide()
  337.         #InstantBuildTextLine
  338.         self.InstantBuildTextLine = ui.TextLine()
  339.         wndMgr.SetParent(self.InstantBuildTextLine.GetWindowHandle(), self.Board.GetWindowHandle())
  340.         self.InstantBuildTextLine.SetPosition(240, 225+3)
  341.         self.InstantBuildTextLine.SetText("Instant Build:")
  342.         self.InstantBuildTextLine.Show()
  343.         #InstantBuildButtonON
  344.         self.InstantBuildButtonON = ui.RadioButton()
  345.         wndMgr.SetParent(self.InstantBuildButtonON.GetWindowHandle(), self.Board.GetWindowHandle())
  346.         self.InstantBuildButtonON.SetPosition(240+65, 225)
  347.         self.InstantBuildButtonON.SetUpVisual("d:/ymir work/ui/public/Small_Button_01.sub")
  348.         self.InstantBuildButtonON.SetOverVisual("d:/ymir work/ui/public/Small_Button_02.sub")
  349.         self.InstantBuildButtonON.SetDownVisual("d:/ymir work/ui/public/Small_Button_03.sub")
  350.         self.InstantBuildButtonON.SetText("ON")
  351.         self.InstantBuildButtonON.Down()
  352.         self.InstantBuildButtonON.SetEvent(self.EnableInstantBuild)
  353.         self.InstantBuildButtonON.Show()
  354.         #InstantBuildButtonOFF
  355.         self.InstantBuildButtonOFF = ui.RadioButton()
  356.         wndMgr.SetParent(self.InstantBuildButtonOFF.GetWindowHandle(), self.Board.GetWindowHandle())
  357.         self.InstantBuildButtonOFF.SetPosition(240+65+45, 225)
  358.         self.InstantBuildButtonOFF.SetUpVisual("d:/ymir work/ui/public/Small_Button_01.sub")
  359.         self.InstantBuildButtonOFF.SetOverVisual("d:/ymir work/ui/public/Small_Button_02.sub")
  360.         self.InstantBuildButtonOFF.SetDownVisual("d:/ymir work/ui/public/Small_Button_03.sub")
  361.         self.InstantBuildButtonOFF.SetText("OFF")
  362.         self.InstantBuildButtonOFF.SetUp()
  363.         self.InstantBuildButtonOFF.SetEvent(self.DisableInstantBuild)
  364.         self.InstantBuildButtonOFF.Show()
  365.         #NewInstanceButton
  366.         self.NewInstanceButton = ui.Button()
  367.         wndMgr.SetParent(self.NewInstanceButton.GetWindowHandle(), self.Board.GetWindowHandle())
  368.         self.NewInstanceButton.SetPosition(240, 250)
  369.         self.NewInstanceButton.SetUpVisual("d:/ymir work/ui/public/Large_Button_01.sub")
  370.         self.NewInstanceButton.SetOverVisual("d:/ymir work/ui/public/Large_Button_02.sub")
  371.         self.NewInstanceButton.SetDownVisual("d:/ymir work/ui/public/Large_Button_03.sub")
  372.         self.NewInstanceButton.SetText("New Instance")
  373.         self.NewInstanceButton.SetEvent(self.CreateNewInstance)
  374.         self.NewInstanceButton.Hide()
  375.         #ImportButton
  376.         self.ImportButton = ui.Button()
  377.         wndMgr.SetParent(self.ImportButton.GetWindowHandle(), self.Board.GetWindowHandle())
  378.         self.ImportButton.SetPosition(240 + 100, 250)
  379.         self.ImportButton.SetUpVisual("d:/ymir work/ui/public/Middle_Button_01.sub")
  380.         self.ImportButton.SetOverVisual("d:/ymir work/ui/public/Middle_Button_02.sub")
  381.         self.ImportButton.SetDownVisual("d:/ymir work/ui/public/Middle_Button_03.sub")
  382.         self.ImportButton.SetText("Import")
  383.         self.ImportButton.SetEvent(self.ImportMapDialog)
  384.         self.ImportButton.Show()
  385.         #ExportButton
  386.         self.ExportButton = ui.Button()
  387.         wndMgr.SetParent(self.ExportButton.GetWindowHandle(), self.Board.GetWindowHandle())
  388.         self.ExportButton.SetPosition(240 + 100 + 65, 250)
  389.         self.ExportButton.SetUpVisual("d:/ymir work/ui/public/Middle_Button_01.sub")
  390.         self.ExportButton.SetOverVisual("d:/ymir work/ui/public/Middle_Button_02.sub")
  391.         self.ExportButton.SetDownVisual("d:/ymir work/ui/public/Middle_Button_03.sub")
  392.         self.ExportButton.SetText("Export")
  393.         self.ExportButton.SetEvent(self.ExportMapDialog)
  394.         self.ExportButton.Show()
  395.  
  396.         #Copyright
  397.         self.CopyrightTextLine = ui.TextLine()
  398.         wndMgr.SetParent(self.CopyrightTextLine.GetWindowHandle(), self.Board.GetWindowHandle())
  399.         self.CopyrightTextLine.SetPosition(270+3, 280-3)
  400.         self.CopyrightTextLine.SetText("by [email protected] 2011-2012")
  401.         self.CopyrightTextLine.Show()
  402.  
  403.        
  404.         #PathComboBox
  405.         self.PathComboBox = ui.ComboBox()
  406.         wndMgr.SetParent(self.PathComboBox.GetWindowHandle(), self.Board.GetWindowHandle())
  407.         self.PathComboBox.listBox.SetTextCenterAlign(0)
  408.         self.PathComboBox.textLine.SetHorizontalAlignLeft()
  409.         self.PathComboBox.textLine.SetWindowHorizontalAlignLeft()
  410.         self.PathComboBox.SetCurrentItem(os.path.abspath(".\\map_object_editor"))
  411.         self.PathComboBox.SetPosition(15, 30)
  412.         self.PathComboBox.SetSize(468, 18)
  413.         self.PathComboBox.SetEvent(ui.__mem_func__(self.OnSelectPath))
  414.         self.PathComboBox.Show()
  415.         self.SetTop()
  416.         self.UpdateFileList(os.path.abspath(".\\map_object_editor"))
  417.         self.DisableInstantBuild()
  418.  
  419.     def CreateNewInstance(self):
  420.         self.OnChangeBuildMode()
  421.         global CURRENT_INSTANCE
  422.         global CURRENT_VNUM
  423.         global CI_IS_AFFECT
  424.         if CI_IS_AFFECT == FALSE:
  425.             chr.testSetAddRenderModeRGB(CURRENT_INSTANCE, 0.0, 0.0, 0.0)
  426.  
  427.         self.SaveCurrentInstance()
  428.         CURRENT_INSTANCE = CreateInstance(CURRENT_VNUM)
  429.  
  430.     def ImportMapDialog(self):
  431.         ImportDialog = uiCommon.InputDialog()
  432.         ImportDialog.Open()
  433.         ImportDialog.SetTitle("Enter a Map-Directory to load the areadata-files from")
  434.         ImportDialog.inputValue.SetText(background.GetCurrentMapName())
  435.         ImportDialog.SetMaxLength(100)
  436.         ImportDialog.SetAcceptEvent(ui.__mem_func__(self.ImportMap))
  437.         ImportDialog.SetCancelEvent(self.ImportMapDialogClose)
  438.         self.ImportDialog = ImportDialog
  439.    
  440.     def ImportMapDialogClose(self):
  441.         self.ImportDialog.inputValue.KillFocus()
  442.         self.ImportDialog.Close()
  443.    
  444.     def ImportMap(self):
  445.         if len(self.ImportDialog.GetText()):
  446.             global LoadMap
  447.             LoadMap(self.ImportDialog.GetText())
  448.        
  449.         self.ImportMapDialogClose()
  450.         return TRUE
  451.    
  452.     def ExportMapDialog(self):
  453.         ExportDialog = uiCommon.InputDialog()
  454.         ExportDialog.Open()
  455.         ExportDialog.SetTitle("Enter a Map-Directory to store the areadata-files in")
  456.         ExportDialog.inputValue.SetText("C:\\mytestmap")
  457.         ExportDialog.SetMaxLength(100)
  458.         ExportDialog.SetAcceptEvent(ui.__mem_func__(self.ExportMap))
  459.         ExportDialog.SetCancelEvent(self.ExportMapDialogClose)
  460.         self.ExportDialog = ExportDialog
  461.    
  462.     def ExportMapDialogClose(self):
  463.         self.ExportDialog.inputValue.KillFocus()
  464.         self.ExportDialog.Close()
  465.    
  466.     def ExportMap(self):
  467.         if len(self.ExportDialog.GetText()):
  468.             global SaveMap
  469.             SaveMap(self.ExportDialog.GetText())
  470.        
  471.         self.ExportMapDialogClose()
  472.         return TRUE
  473.    
  474.     def SaveCurrentInstance(self):
  475.         global CURRENT_INSTANCE
  476.         global CURRENT_VNUM
  477.         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()))
  478.  
  479.     def UpdateCurrentInstance(self):
  480.         global CURRENT_INSTANCE
  481.         global CURRENT_VNUM
  482.         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()))
  483.  
  484.     def DisableInstantBuild(self):
  485.         global INSTANT_BUILD
  486.         INSTANT_BUILD = FALSE
  487.         self.InstantBuildButtonON.SetUp()
  488.         self.InstantBuildButtonOFF.Down()
  489.  
  490.     def EnableInstantBuild(self):
  491.         global INSTANT_BUILD
  492.         INSTANT_BUILD = TRUE
  493.         self.InstantBuildButtonOFF.SetUp()
  494.         self.InstantBuildButtonON.Down()
  495.  
  496.     def ResetSliderPosX(self):
  497.         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:
  498.             self.RotXSliderBar.SetSliderPos(0.5)
  499.         else:
  500.             self.RotXSliderBar.SetSliderPos(float(self.RotXSliderBar.backGroundImage.GetMouseLocalPosition()[0])/float(self.RotXSliderBar.backGroundImage.GetWidth()))
  501.  
  502.     def ResetSliderPosY(self):
  503.         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:
  504.             self.RotYSliderBar.SetSliderPos(0.5)
  505.         else:
  506.             self.RotYSliderBar.SetSliderPos(float(self.RotYSliderBar.backGroundImage.GetMouseLocalPosition()[0])/float(self.RotYSliderBar.backGroundImage.GetWidth()))
  507.  
  508.     def ResetSliderPosZ(self):
  509.         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:
  510.             self.RotZSliderBar.SetSliderPos(0.5)
  511.         else:
  512.             self.RotZSliderBar.SetSliderPos(float(self.RotZSliderBar.backGroundImage.GetMouseLocalPosition()[0])/float(self.RotZSliderBar.backGroundImage.GetWidth()))
  513.  
  514.     def KillFocus_Callback(self):
  515.         self.RotXEditLine.KillFocus()
  516.         self.RotYEditLine.KillFocus()
  517.         self.RotZEditLine.KillFocus()
  518.         self.ControlXAxisEditLine.KillFocus()
  519.         self.ControlYAxisEditLine.KillFocus()
  520.         self.ControlZAxisEditLine.KillFocus()
  521.         self.IncDecStepEditLine.KillFocus()
  522.  
  523.     def OnChangeCustomizeMode(self):
  524.         self.ModeBuildButton.SetUp()
  525.         self.ModeCustomizeButton.Down()
  526.         self.ControlXAxisMinus.Show()
  527.         self.ControlXAxisPlus.Show()
  528.         self.ControlYAxisMinus.Show()
  529.         self.ControlYAxisPlus.Show()
  530.         self.ControlZAxisMinus.Show()
  531.         self.ControlZAxisPlus.Show()
  532.         self.NewInstanceButton.Show()
  533.         global CUSTOMIZE_MODE
  534.         CUSTOMIZE_MODE = TRUE
  535.    
  536.     def OnChangeBuildMode(self):
  537.         self.ModeCustomizeButton.SetUp()
  538.         self.ModeBuildButton.Down()
  539.         self.ControlXAxisMinus.Hide()
  540.         self.ControlXAxisPlus.Hide()
  541.         self.ControlYAxisMinus.Hide()
  542.         self.ControlYAxisPlus.Hide()
  543.         self.ControlZAxisMinus.Hide()
  544.         self.ControlZAxisPlus.Hide()
  545.         global CUSTOMIZE_MODE
  546.         CUSTOMIZE_MODE = FALSE
  547.         self.NewInstanceButton.Hide()
  548.  
  549.     def OnSelectPath(self):
  550.         self.UpdateFileList(str(self.PathComboBox.listBox.textDict[self.PathComboBox.listBox.selectedLine]))
  551.         self.PathComboBox.CloseListBox()
  552.  
  553.     def UpdateFileList(self, dir):
  554.         self.ObjectBrowser.dir = dir
  555.         contains = FALSE
  556.         for i in xrange(len(self.PathComboBox.listBox.textDict)):
  557.             if self.PathComboBox.listBox.textDict[i] == dir:
  558.                 contains = TRUE
  559.  
  560.         if contains == FALSE:
  561.             if len(self.PathComboBox.listBox.textDict) == 10:
  562.                 self.PathComboBox.listBox.itemList.pop(0)
  563.  
  564.             self.PathComboBox.InsertItem(0, dir)
  565.  
  566.         self.PathComboBox.SetCurrentItem(dir)
  567.         self.ObjectBrowser.RemoveAllItems()
  568.         self.ObjectBrowser.AppendItem(Item("  >> .."))
  569.         for filename in os.listdir(dir):
  570.             if os.path.isdir(dir + "\\" + filename):
  571.                 self.ObjectBrowser.AppendItem(Item("  >> " + filename))
  572.         for filename in os.listdir(dir):
  573.             if os.path.isfile(dir + "\\" + filename) and (filename[-4:] == ".prb" or filename[-4:] == ".prd" or filename[-4:] == ".pre" or filename[-4:] == ".prt"):
  574.                 self.ObjectBrowser.AppendItem(Item("  " + filename))
  575.         if self.ObjectBrowser.GetHeight()/20 >= len(self.ObjectBrowser.itemList):
  576.             self.ObjectBrowserScrollBar.Hide()
  577.         else:
  578.             self.ObjectBrowserScrollBar.SetMiddleBarSize(float(self.ObjectBrowser.GetHeight()/20) / float(len(self.ObjectBrowser.itemList)))
  579.             self.ObjectBrowserScrollBar.Show()
  580.  
  581.     def OnChangeDirectory(self):
  582.         if (self.ObjectBrowser.GetSelectedItem().GetText() == "  >> .."):
  583.             self.UpdateFileList(os.path.abspath(os.path.join(self.ObjectBrowser.dir, '..')))
  584.             return
  585.  
  586.         if (self.ObjectBrowser.GetSelectedItem().GetText().find(">>") == -1):
  587.             self.OnSelectObject()
  588.             return
  589.  
  590.         newdir = self.ObjectBrowser.dir + "\\" + self.ObjectBrowser.GetSelectedItem().GetText()[5:]
  591.         if os.path.isdir(newdir):
  592.             self.UpdateFileList(os.path.abspath(os.path.join(self.ObjectBrowser.dir, newdir)))
  593.  
  594.     def OnSelectObject(self):
  595.         global CUSTOMIZE_MODE
  596.         if CUSTOMIZE_MODE == TRUE:
  597.             self.CreateNewInstance()
  598.  
  599.         global CURRENT_VNUM
  600.         global CURRENT_INSTANCE
  601.         global CreateRaceFromPRB
  602.         global CreateRaceFromPRT
  603.         global CreateInstance
  604.         path = self.ObjectBrowser.dir.replace("\\", "/") + "/" + self.ObjectBrowser.GetSelectedItem().GetText()[2:]
  605.         if os.path.isfile(path):
  606.             chr.DeleteInstance(CURRENT_INSTANCE)
  607.             if path[-4:] == ".pre":
  608.                 CURRENT_VNUM = CreateEffectFromPRE(path)
  609.             elif path[-4:] == ".prt":
  610.                 CURRENT_VNUM = CreateRaceFromPRT(path)
  611.             else:
  612.                 CURRENT_VNUM = CreateRaceFromPRB(path)
  613.  
  614.             global ControlWindow
  615.             ControlWindow.PlacementBarText.SetText("Placement-Settings (" + GetObjectName(CURRENT_VNUM) + ")")
  616.             CURRENT_INSTANCE = CreateInstance(CURRENT_VNUM)
  617.  
  618.  
  619. BUILDING_ALPHA = 0.1
  620. BUILDING_ALPHA_CHANGE = 0.4/app.GetUpdateFPS()/2
  621. BUILDING_ALPHA_CHANGE_MULTIPLICATOR = 1
  622.  
  623. VIRTUAL_INSTANCE_MAX = 0x7FFFFFFF
  624. VIRTUAL_INSTANCE_INDEX = 0
  625. CURRENT_INSTANCE = 0
  626. CURRENT_VNUM = 0
  627.  
  628. CI_IS_AFFECT = FALSE
  629.  
  630. CREATED_RACES = []
  631. CREATED_EFFECTS = []
  632.  
  633. EFFECT_DICT = {}
  634.  
  635. OBJECTS = []
  636. OBJECT_NAME_DICT = {}
  637.  
  638. CUSTOMIZE_MODE = FALSE
  639. INSTANT_BUILD = TRUE
  640. DRAG_MODE = FALSE
  641.  
  642. old_sliderbar_rx = 0
  643. old_sliderbar_ry = 0
  644. old_sliderbar_rz = 0
  645.  
  646. GRAB_DIF_X = 0
  647. GRAB_DIF_Y = 0
  648. GRAB_Z = 0
  649.  
  650.  
  651. def GrabCurrentInstance():
  652.     global CURRENT_INSTANCE
  653.     global GRAB_DIF_X
  654.     global GRAB_DIF_Y
  655.     global GRAB_Z
  656.     global DRAG_MODE
  657.     px, py, pz = background.GetPickingPoint()
  658.     ox, oy, GRAB_Z = GetObject(CURRENT_INSTANCE).GetPosition()
  659.     GRAB_DIF_X = ox - px
  660.     GRAB_DIF_Y = oy - py
  661.     DRAG_MODE = TRUE
  662.  
  663. def DropCurrentInstance():
  664.     global DRAG_MODE
  665.     global GRAB_DIF_X
  666.     global GRAB_DIF_Y
  667.     global GRAB_Z
  668.     global ControlWindow
  669.     DRAG_MODE = FALSE
  670.     GRAB_DIF_X = 0
  671.     GRAB_DIF_Y = 0
  672.     GRAB_Z = 0
  673.     ControlWindow.UpdateCurrentInstance()
  674.  
  675. def SelectNextObject(floatX, floatY, floatZ):
  676.     global VIRTUAL_INSTANCE_MAX
  677.     global VIRTUAL_INSTANCE_INDEX
  678.     vid = VIRTUAL_INSTANCE_MAX
  679.     shortest_distance = 40.0
  680.     nearest_vid = 0
  681.     while vid > VIRTUAL_INSTANCE_MAX - VIRTUAL_INSTANCE_INDEX:
  682.         object = GetObject(vid)
  683.         if object == 0:
  684.             vid-=1
  685.             continue
  686.  
  687.         vidx, vidy, vidz = object.GetPosition()
  688.         #d = 2√( (x2-x1)² + (y2-y1)² + (z2-z1)² )
  689.         distance = pow(( (vidx-floatX)*(vidx-floatX) + (vidy-floatY)*(vidy-floatY) + (vidz-floatZ)*(vidz-floatZ) ), 0.25)
  690.         if distance <= shortest_distance:
  691.             shortest_distance = distance
  692.             nearest_vid = vid
  693.  
  694.         vid-=1
  695.  
  696.     if nearest_vid == 0:
  697.         return
  698.  
  699.     global CURRENT_INSTANCE
  700.     if nearest_vid == CURRENT_INSTANCE:
  701.         GrabCurrentInstance()
  702.         return
  703.  
  704.     global ControlWindow
  705.     if GetObject(CURRENT_INSTANCE) == 0:
  706.         ControlWindow.SaveCurrentInstance()
  707.     else:
  708.         ControlWindow.UpdateCurrentInstance()
  709.  
  710.     global CI_IS_AFFECT
  711.     if CI_IS_AFFECT == FALSE:
  712.         chr.testSetAddRenderModeRGB(CURRENT_INSTANCE, 0.0, 0.0, 0.0)
  713.  
  714.     CI_IS_AFFECT = IsEffect(GetObject(nearest_vid).GetObjectNumber())
  715.     x, y, z = GetObject(nearest_vid).GetPosition()
  716.     ControlWindow.ControlXAxisEditLine.SetText("%.0f" % round(x, 0))
  717.     ControlWindow.ControlYAxisEditLine.SetText("%.0f" % round(y, 0))
  718.     ControlWindow.ControlZAxisEditLine.SetText("%.0f" % round(z, 0))
  719.     rx, ry, rz = GetObject(nearest_vid).GetRotation()
  720.     ControlWindow.RotXEditLine.SetText("%.0f" % round(rx, 2))
  721.     ControlWindow.RotYEditLine.SetText("%.2f" % round(ry, 2))
  722.     ControlWindow.RotZEditLine.SetText("%.2f" % round(rz, 2))
  723.     ControlWindow.RotXSliderBar.SetSliderPos(rx/360+0.5)
  724.     ControlWindow.RotYSliderBar.SetSliderPos(ry/360+0.5)
  725.     ControlWindow.RotZSliderBar.SetSliderPos(rz/360+0.5)
  726.     CURRENT_INSTANCE = nearest_vid
  727.     global CURRENT_VNUM
  728.     CURRENT_VNUM = GetObject(nearest_vid).GetObjectNumber()
  729.     ControlWindow.PlacementBarText.SetText("Placement-Settings (" + GetObjectName(GetObject(nearest_vid).GetObjectNumber()) + ")")
  730.  
  731.  
  732. def OnMouseLeftButtonDown():
  733.     global ControlWindow
  734.     ControlWindow.KillFocus_Callback()
  735.     global CUSTOMIZE_MODE
  736.     if CUSTOMIZE_MODE == TRUE:
  737.         x, y, z = background.GetPickingPoint()
  738.         SelectNextObject(x, y, z)
  739.     else:
  740.         SettleCurrentPosition()
  741.  
  742. def OnMouseLeftButtonUp():
  743.     global ControlWindow
  744.     ControlWindow.KillFocus_Callback()
  745.     global DRAG_MODE
  746.     if DRAG_MODE == TRUE:
  747.         DropCurrentInstance()
  748.  
  749.     #global CUSTOMIZE_MODE
  750.     #if CUSTOMIZE_MODE == TRUE:
  751.     #   player.SetMouseState(player.MBT_LEFT, player.MBS_CLICK);
  752.  
  753. def OnMouseRightButtonDown():
  754.     global ControlWindow
  755.     ControlWindow.KillFocus_Callback()
  756.     player.SetMouseState(player.MBT_RIGHT, player.MBS_PRESS);
  757.  
  758. def OnMouseRightButtonUp():
  759.     global ControlWindow
  760.     ControlWindow.KillFocus_Callback()
  761.     player.SetMouseState(player.MBT_RIGHT, player.MBS_CLICK);
  762.  
  763. def OnMouseMiddleButtonDown():
  764.     global ControlWindow
  765.     ControlWindow.KillFocus_Callback()
  766.     player.SetMouseMiddleButtonState(player.MBS_PRESS);
  767.  
  768. def OnMouseMiddleButtonUp():
  769.     global ControlWindow
  770.     ControlWindow.KillFocus_Callback()
  771.     player.SetMouseMiddleButtonState(player.MBS_CLICK);
  772.  
  773. def SaveObject(id, vid, x, y, z, rx, ry, rz):
  774.     global OBJECTS
  775.     OBJECTS.append(Map3DObject(id, vid, x, y, z, rx, ry, rz))
  776.  
  777. def UpdateObject(id, vid, x, y, z, rx, ry, rz):
  778.     o = GetObject(vid)
  779.     o.__init__(id, vid, x, y, z, rx, ry, rz)
  780.  
  781. def GetObject(vid):
  782.     global OBJECTS
  783.     for Map3DObject in OBJECTS:
  784.         if Map3DObject.GetVirtualID() == vid:
  785.             return Map3DObject
  786.  
  787.     return 0
  788.  
  789. def DeleteObject(vid):
  790.     item = GetObject(vid)
  791.     if item != 0:
  792.         global OBJECTS
  793.         OBJECTS.remove(item)
  794.  
  795. def GetObjectName(id):
  796.     global OBJECT_NAME_DICT
  797.     if OBJECT_NAME_DICT.has_key(id):
  798.         return OBJECT_NAME_DICT[id]
  799.     else:
  800.         return ""
  801.  
  802. def SettleCurrentPosition():
  803.     global CURRENT_INSTANCE
  804.     global CURRENT_VNUM
  805.     global INSTANT_BUILD
  806.     global CI_IS_AFFECT
  807.     if CI_IS_AFFECT == FALSE:
  808.         chr.testSetAddRenderModeRGB(CURRENT_INSTANCE, 0.0, 0.0, 0.0)
  809.  
  810.     global ControlWindow
  811.     if INSTANT_BUILD == TRUE:
  812.         x, y, z = background.GetPickingPoint()
  813.         SaveObject(CURRENT_VNUM, CURRENT_INSTANCE, x, y, z, float(ControlWindow.RotXEditLine.GetText()), float(ControlWindow.RotYEditLine.GetText()), float(ControlWindow.RotZEditLine.GetText()))
  814.         CURRENT_INSTANCE = CreateInstance(CURRENT_VNUM)
  815.     else:
  816.         ControlWindow.OnChangeCustomizeMode()
  817.         wndMgr.OnceIgnoreMouseLeftButtonUpEvent()
  818.  
  819. def Update():
  820.     global CURRENT_INSTANCE
  821.     background.SetVisiblePart(background.PART_OBJECT, 0);
  822.     if CURRENT_INSTANCE == 0:
  823.         return
  824.  
  825.     global CUSTOMIZE_MODE
  826.     global ControlWindow
  827.     if CUSTOMIZE_MODE == TRUE:
  828.         global DRAG_MODE
  829.         if DRAG_MODE == TRUE:
  830.             x, y, z = background.GetPickingPoint()
  831.             global GRAB_DIF_X
  832.             global GRAB_DIF_Y
  833.             global GRAB_Z
  834.             x+=GRAB_DIF_X
  835.             y+=GRAB_DIF_Y
  836.             #z = GRAB_Z
  837.             z = background.GetHeight(x, y)
  838.             ControlWindow.ControlXAxisEditLine.SetText("%.0f" % round(x, 0))
  839.             ControlWindow.ControlYAxisEditLine.SetText("%.0f" % round(y, 0))
  840.             ControlWindow.ControlZAxisEditLine.SetText("%.0f" % round(z, 0))
  841.             cameraX, cameraY, cameraZ = grp.GetCameraPosition()
  842.             grp.RenderLine(100, 200, 300, 400)
  843.         else:
  844.             x = ControlWindow.ControlXAxisEditLine.GetText()
  845.             y = ControlWindow.ControlYAxisEditLine.GetText()
  846.             z = ControlWindow.ControlZAxisEditLine.GetText()
  847.         if app.IsPressed(211) == TRUE:
  848.             DeleteObject(CURRENT_INSTANCE)
  849.             chr.DeleteInstance(CURRENT_INSTANCE)
  850.             CURRENT_INSTANCE = 0
  851.             return
  852.  
  853.     else:
  854.         x, y, z = background.GetPickingPoint()
  855.         ControlWindow.ControlXAxisEditLine.SetText("%.0f" % round(x, 0))
  856.         ControlWindow.ControlYAxisEditLine.SetText("%.0f" % round(y, 0))
  857.         ControlWindow.ControlZAxisEditLine.SetText("%.0f" % round(z, 0))
  858.  
  859.     UpdateBuildingAlpha()
  860.     if (chr.HasInstance(CURRENT_INSTANCE) == FALSE):
  861.         global CURRENT_VNUM
  862.         CURRENT_INSTANCE = CreateInstance(CURRENT_VNUM)
  863.  
  864.     myVid = player.GetMainCharacterIndex()
  865.     chr.SelectInstance(CURRENT_INSTANCE)
  866.     chr.SetPixelPosition(int(x), int(y), int(z))
  867.     UpdateRotation()
  868.     chr.SelectInstance(myVid)
  869.  
  870. def UpdateRotation():
  871.     global old_sliderbar_rx
  872.     global old_sliderbar_ry
  873.     global old_sliderbar_rz
  874.     global ControlWindow
  875.     sliderbar_rx = ControlWindow.RotXSliderBar.GetSliderPos()*360-180
  876.     rx = sliderbar_rx
  877.     if (ControlWindow.RotXEditLine.GetText() == ""):
  878.         edit_rx = sliderbar_rx
  879.     else:
  880.         edit_rx = float(ControlWindow.RotXEditLine.GetText())
  881.  
  882.     if (edit_rx != sliderbar_rx and app.IsPressed(app.DIK_RETURN)):
  883.         rx = edit_rx
  884.         ControlWindow.RotXSliderBar.SetSliderPos(edit_rx/360+0.5)
  885.     elif (sliderbar_rx != old_sliderbar_rx):
  886.         rx = sliderbar_rx
  887.         ControlWindow.RotXEditLine.SetText("%.2f" % round(sliderbar_rx, 2))
  888.  
  889.     sliderbar_ry = ControlWindow.RotYSliderBar.GetSliderPos()*360-180
  890.     ry = sliderbar_ry
  891.     if (ControlWindow.RotYEditLine.GetText() == ""):
  892.         edit_ry = sliderbar_ry
  893.     else:
  894.         edit_ry = float(ControlWindow.RotYEditLine.GetText())
  895.  
  896.     if (edit_ry != sliderbar_ry and app.IsPressed(app.DIK_RETURN)):
  897.         ry = edit_ry
  898.         ControlWindow.RotYSliderBar.SetSliderPos(edit_ry/360+0.5)
  899.     elif (sliderbar_ry != old_sliderbar_ry):
  900.         ry = sliderbar_ry
  901.         ControlWindow.RotYEditLine.SetText("%.2f" % round(sliderbar_ry, 2))
  902.  
  903.     sliderbar_rz = ControlWindow.RotZSliderBar.GetSliderPos()*360-180
  904.     rz = sliderbar_rz
  905.     if (ControlWindow.RotZEditLine.GetText() == ""):
  906.         edit_rz = sliderbar_rz
  907.     else:
  908.         edit_rz = float(ControlWindow.RotZEditLine.GetText())
  909.  
  910.     if (edit_rz != sliderbar_rz and app.IsPressed(app.DIK_RETURN)):
  911.         rz = edit_rz
  912.         ControlWindow.RotZSliderBar.SetSliderPos(edit_rz/360+0.5)
  913.     elif (sliderbar_rz != old_sliderbar_rz):
  914.         rz = sliderbar_rz
  915.         ControlWindow.RotZEditLine.SetText("%.2f" % round(sliderbar_rz, 2))
  916.  
  917.     old_sliderbar_rx = sliderbar_rx
  918.     old_sliderbar_ry = sliderbar_ry
  919.     old_sliderbar_rz = sliderbar_rz
  920.     chr.SetRotationAll(rx, ry, rz)
  921.  
  922. def UpdateBuildingAlpha():
  923.     global BUILDING_ALPHA
  924.     global BUILDING_ALPHA_CHANGE
  925.     global CURRENT_INSTANCE
  926.     global BUILDING_ALPHA_CHANGE_MULTIPLICATOR
  927.     global CI_IS_AFFECT
  928.     if CI_IS_AFFECT == TRUE:
  929.         return
  930.  
  931.     BUILDING_ALPHA = BUILDING_ALPHA + BUILDING_ALPHA_CHANGE
  932.     chr.testSetAddRenderModeRGB(CURRENT_INSTANCE, BUILDING_ALPHA, BUILDING_ALPHA, BUILDING_ALPHA)
  933.     if (BUILDING_ALPHA >= 0.4 or BUILDING_ALPHA <= 0):
  934.         BUILDING_ALPHA_CHANGE_MULTIPLICATOR = BUILDING_ALPHA_CHANGE_MULTIPLICATOR * -1
  935.         if app.GetUpdateFPS() != 0:
  936.             BUILDING_ALPHA_CHANGE = (0.4/app.GetUpdateFPS())/2 * BUILDING_ALPHA_CHANGE_MULTIPLICATOR
  937.         else:
  938.             BUILDING_ALPHA_CHANGE = (0.4/30)/2 * BUILDING_ALPHA_CHANGE_MULTIPLICATOR
  939.  
  940. def CreateInstance(race):
  941.     global CI_IS_AFFECT
  942.     if IsEffect(race):
  943.         CI_IS_AFFECT = TRUE
  944.         return CreateEffect(race)
  945.     else:
  946.         CI_IS_AFFECT = FALSE
  947.  
  948.     myVid = player.GetMainCharacterIndex()
  949.     global VIRTUAL_INSTANCE_MAX
  950.     global VIRTUAL_INSTANCE_INDEX
  951.     idx = VIRTUAL_INSTANCE_MAX - VIRTUAL_INSTANCE_INDEX
  952.     VIRTUAL_INSTANCE_INDEX = VIRTUAL_INSTANCE_INDEX + 1
  953.     chr.CreateInstance(idx)
  954.     chr.SelectInstance(idx)
  955.     chr.SetVirtualID(idx)
  956.     chr.SetInstanceType(chr.INSTANCE_TYPE_BUILDING)
  957.     chr.SetRace(race)
  958.     chr.SetArmor(0)
  959.     chr.SetRotation(app.GetRandom(0, 360))
  960.     #chr.SetNameString("test")
  961.     chr.Refresh()
  962.     chr.SetLoopMotion(chr.MOTION_WAIT)
  963.     global BUILDING_ALPHA
  964.     chr.testSetAddRenderModeRGB(idx, BUILDING_ALPHA, BUILDING_ALPHA, BUILDING_ALPHA)
  965.     chr.SelectInstance(myVid)
  966.     return idx
  967.  
  968. def CreateEffect(race):
  969.     myVid = player.GetMainCharacterIndex()
  970.     global VIRTUAL_INSTANCE_MAX
  971.     global VIRTUAL_INSTANCE_INDEX
  972.     idx = VIRTUAL_INSTANCE_MAX - VIRTUAL_INSTANCE_INDEX
  973.     VIRTUAL_INSTANCE_INDEX = VIRTUAL_INSTANCE_INDEX + 1
  974.     chr.CreateInstance(idx)
  975.     chr.SelectInstance(idx)
  976.     chr.SetVirtualID(idx)
  977.     chr.SetInstanceType(chr.INSTANCE_TYPE_BUILDING)
  978.     chr.SetRace(0)
  979.     chr.SetArmor(0)
  980.     chr.SetRotation(app.GetRandom(0, 360))
  981.     chr.Refresh()
  982.     chr.SetLoopMotion(chr.MOTION_WAIT)
  983.     global EFFECT_DICT
  984.     #chrmgr.RegisterEffect(27+50, "Bip01", EFFECT_DICT[race])
  985.     chrmgr.RegisterEffect(27+50, "", EFFECT_DICT[race])
  986.     chrmgr.SetAffect(idx, 50, 1)
  987.     chr.SetBlendRenderMode(idx, 0.0)
  988.     chr.SelectInstance(myVid)
  989.     return idx
  990.  
  991. def AttachingData():
  992.     """
  993. Group ShapeData
  994. {
  995.     PathName         ""
  996.     ShapeDataCount       0
  997. }
  998. Group AttachingData
  999. {
  1000.    AttachingDataCount       2
  1001.    
  1002.    Group AttachingData00
  1003.    {
  1004.        AttachingDataType    1
  1005.        
  1006.        isAttaching          0
  1007.        AttachingModelIndex  0
  1008.        AttachingBoneName    "Box01"
  1009.        
  1010.        CollisionType        1
  1011.        
  1012.        SphereDataCount      1
  1013.        Group SphereData00
  1014.        {
  1015.            Radius           60.000000
  1016.            Position         0.000000 0.000000 50.000000
  1017.        }
  1018.    }
  1019.    
  1020.    Group AttachingData01
  1021.    {
  1022.        AttachingDataType    1
  1023.        
  1024.        isAttaching          1
  1025.        AttachingModelIndex  0
  1026.        AttachingBoneName    "ore"
  1027.        
  1028.        CollisionType        3
  1029.        
  1030.        SphereDataCount      1
  1031.        Group SphereData00
  1032.        {
  1033.            Radius           70.000000
  1034.            Position         0.000000 0.000000 50.000000
  1035.        }
  1036.    }
  1037. }
  1038.     """
  1039.  
  1040. def CreateRaceFromPRB(file):
  1041.     prbfile = open(file, "r").read().split("\n")
  1042.     vnum = long(prbfile[1].strip())
  1043.     if (vnum > 0x7FFFFFFF):
  1044.         vnum = vnum*-1 + 0x7FFFFFFF
  1045.  
  1046.     global CREATED_RACES
  1047.     if vnum in CREATED_RACES:
  1048.         return vnum
  1049.  
  1050.     CREATED_RACES.append(vnum)
  1051.     gr2path = prbfile[2].split("\"")[1]
  1052.     open("map_object_editor/CreateRaceFromPRB.msm", "w+").write("ScriptType            RaceDataScript\n\nBaseModelFileName     \"" + gr2path + "\"\n"+ AttachingData.__doc__)
  1053.     chrmgr.CreateRace(vnum)
  1054.     chrmgr.SelectRace(vnum)
  1055.     chrmgr.SetPathName("map_object_editor/")
  1056.     chrmgr.LoadRaceData("CreateRaceFromPRB.msm")
  1057.     chrmgr.RegisterAttachingBoneName(chr.PART_WEAPON, "equip_right_hand")
  1058.     global OBJECT_NAME_DICT
  1059.     OBJECT_NAME_DICT[vnum] = os.path.basename(file)
  1060.     return vnum
  1061.  
  1062. def CreateRaceFromPRT(file):
  1063.     prtfile = open(file, "r").read().split("\n")
  1064.     vnum = long(prtfile[1].strip())
  1065.     if (vnum > 0x7FFFFFFF):
  1066.         vnum = vnum*-1 + 0x7FFFFFFF
  1067.  
  1068.     global CREATED_RACES
  1069.     if vnum in CREATED_RACES:
  1070.         return vnum
  1071.  
  1072.     CREATED_RACES.append(vnum)
  1073.     sptpath = prtfile[4].split("\"")[1]
  1074.     open("map_object_editor/CreateRaceFromPRT.msm", "w+").write("ScriptType            RaceDataScript\n\nTreeFileName     \"" + str(sptpath) + "\"\n"+ AttachingData.__doc__)
  1075.     chrmgr.CreateRace(vnum)
  1076.     chrmgr.SelectRace(vnum)
  1077.     chrmgr.SetPathName("map_object_editor/")
  1078.     chrmgr.LoadRaceData("CreateRaceFromPRT.msm")
  1079.     chrmgr.RegisterAttachingBoneName(chr.PART_WEAPON, "equip_right_hand")
  1080.     global OBJECT_NAME_DICT
  1081.     OBJECT_NAME_DICT[vnum] = os.path.basename(file)
  1082.     return vnum
  1083.  
  1084.  
  1085. def CreateEffectFromPRE(file):
  1086.     prbfile = open(file, "r").read().split("\n")
  1087.     vnum = long(prbfile[1].strip())
  1088.     #if (vnum > 0x7FFFFFFF):
  1089.         #vnum = vnum*-1 + 0x7FFFFFFF
  1090.  
  1091.     global EFFECT_DICT
  1092.     if EFFECT_DICT.has_key(vnum):
  1093.         return vnum
  1094.  
  1095.     msepath = prbfile[2].split("\"")[1]
  1096.     #chrmgr.RegisterEffect(vnum, "Bip01", msepath)
  1097.     #dbg.TraceError("EFFECT_DICT[" + str(vnum) + "] = " + msepath)
  1098.     EFFECT_DICT[vnum] = msepath
  1099.     global OBJECT_NAME_DICT
  1100.     OBJECT_NAME_DICT[vnum] = os.path.basename(file)
  1101.     return vnum
  1102.  
  1103. def IsEffect(vnum):
  1104.     global EFFECT_DICT
  1105.     return EFFECT_DICT.has_key(vnum)
  1106.  
  1107. def dirwalk(dir):
  1108.     "walk a directory tree, using a generator (Snippet from http://code.activestate.com/recipes/105873-walk-a-directory-tree-using-a-generator/)"
  1109.     for f in os.listdir(dir):
  1110.         fullpath = os.path.join(dir,f)
  1111.         if os.path.isdir(fullpath) and not os.path.islink(fullpath):
  1112.             for x in dirwalk(fullpath):  # recurse into subdir
  1113.                 yield x
  1114.         else:
  1115.             yield fullpath
  1116.  
  1117. def LoadAllObjects():
  1118.     for elem in dirwalk("map_object_editor"):
  1119.         if elem[-4:] == ".prb" or elem[-4:] == ".prd":
  1120.             CreateRaceFromPRB(elem)
  1121.         elif elem[-4:] == ".pre":
  1122.             CreateEffectFromPRE(elem)
  1123.         elif elem[-4:] == ".prt":
  1124.             CreateRaceFromPRT(elem)
  1125.  
  1126. def LoadAreaData(filename):
  1127.     global BUILDING_ALPHA
  1128.     BUILDING_ALPHA = 0
  1129.     myVid = player.GetMainCharacterIndex()
  1130.     global CURRENT_INSTANCE
  1131.     areadata = pack.Get(filename).split("\n")
  1132.     #dbg.TraceError("areadata =" + str(filename))
  1133.     for i in xrange(len(areadata)):
  1134.         line = areadata[i].strip()
  1135.         if line.startswith("Start Object"):
  1136.             pos = areadata[i+1].strip().split()
  1137.             vnum = long(areadata[i+2].strip())
  1138.             #dbg.TraceError("truevnum =" + str(vnum))
  1139.             if (vnum > 0x7FFFFFFF and IsEffect(vnum) == FALSE):
  1140.                 vnum = vnum*-1 + 0x7FFFFFFF
  1141.  
  1142.             global CREATED_RACES
  1143.             if not vnum in CREATED_RACES and IsEffect(vnum) == FALSE:
  1144.                 rot =  areadata[i+3].strip().split("#")
  1145.                 additional_height = areadata[i+4].strip()
  1146.                 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]))
  1147.                 continue
  1148.  
  1149.             rot =  areadata[i+3].strip().split("#")
  1150.             additional_height = areadata[i+4].strip()
  1151.             #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])))
  1152.             CURRENT_INSTANCE = CreateInstance(vnum)
  1153.             chr.SelectInstance(CURRENT_INSTANCE)
  1154.             chr.SetPixelPosition(int(float(pos[0])), int(float(pos[1]))*-1, int(float(pos[2])+float(additional_height)))
  1155.             chr.SetRotationAll(float(rot[0]), float(rot[1]), float(rot[2]))
  1156.             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]))
  1157.             chr.SelectInstance(myVid)
  1158.  
  1159. def LoadCurrentMap():
  1160.     LoadMap(background.GetCurrentMapName())
  1161.  
  1162. def LoadMap(dir):
  1163.     SizeX, SizeY = GetMapSize(dir)
  1164.     for squareX in xrange(SizeX):
  1165.         for squareY in xrange(SizeY):
  1166.             LoadAreaData(dir + "/%.3i%.3i/areadata.txt" % (squareX, squareY))
  1167.  
  1168. def GetMapSize(dir):
  1169.     mapSettings = pack.Get(dir + "/setting.txt")
  1170.     SizeX = int(mapSettings.split()[9])
  1171.     SizeY = int(mapSettings.split()[10])
  1172.     return SizeX, SizeY
  1173.  
  1174. def SaveMap(dir):
  1175.     SizeX, SizeY = GetMapSize(background.GetCurrentMapName())
  1176.     for squareX in xrange(SizeX):
  1177.         for squareY in xrange(SizeY):
  1178.             ensure_dir(dir + "\\%.3i%.3i\\areadata.txt" % (squareX, squareY))
  1179.             SaveAreaData(dir + "\\%.3i%.3i\\areadata.txt" % (squareX, squareY), (squareX)*255*100, (squareY)*255*100, (squareX+1)*255*100, (squareY+1)*255*100)
  1180.  
  1181. def ensure_dir(f):
  1182.     d = os.path.dirname(f)
  1183.     if not os.path.exists(d):
  1184.         os.makedirs(d)
  1185.  
  1186. def SaveAreaData(filename, startX, startY, endX, endY):
  1187.     global VIRTUAL_INSTANCE_MAX
  1188.     global VIRTUAL_INSTANCE_INDEX
  1189.     vid = VIRTUAL_INSTANCE_MAX
  1190.     file = open(filename, "w+")
  1191.     file.write("AreaDataFile\n\n")
  1192.     #file.write("FROM (%d, %d) TO (%d, %d)\n" %(startX, startY, endX, endY))
  1193.     objectcount = 0
  1194.     while vid > VIRTUAL_INSTANCE_MAX - VIRTUAL_INSTANCE_INDEX:
  1195.         object = GetObject(vid)
  1196.         if object == 0:
  1197.             vid-=1
  1198.             continue
  1199.  
  1200.         vidx, vidy, vidz = object.GetPosition()
  1201.         vrx, vry, vrz = object.GetRotation()
  1202.         if (vidx >= startX and vidy >= startY and vidx < endX and vidy < endY):
  1203.             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))
  1204.             objectcount+=1
  1205.        
  1206.         vid-=1
  1207.    
  1208.     file.write("\nObjectCount " + str(objectcount))
  1209.    
  1210. chat.AppendChat(chat.CHAT_TYPE_INFO, "Ingame Map-Editor by musicinstructor")
  1211. LoadAllObjects()
  1212. LoadCurrentMap()
  1213. CURRENT_VNUM = 944313422
  1214. CURRENT_INSTANCE = CreateInstance(CURRENT_VNUM)
  1215. #CURRENT_INSTANCE = CreateEffect(780392666)
  1216. #CI_IS_AFFECT = TRUE
  1217.  
  1218.  
  1219.  
  1220. app.SetCameraMaxDistance(350000)
  1221. app.SetMinFog(350000)
  1222.  
  1223. mapeditMain = ui.Window()
  1224. mapeditMain.OnUpdate = Update
  1225. mapeditMain.OnMouseLeftButtonDown = OnMouseLeftButtonDown
  1226. mapeditMain.OnMouseLeftButtonUp = OnMouseLeftButtonUp
  1227. mapeditMain.OnMouseRightButtonDown = OnMouseRightButtonDown
  1228. mapeditMain.OnMouseRightButtonUp = OnMouseRightButtonUp
  1229. mapeditMain.OnMouseMiddleButtonDown = OnMouseMiddleButtonDown
  1230. mapeditMain.OnMouseMiddleButtonUp = OnMouseMiddleButtonUp
  1231. mapeditMain.SetSize(systemSetting.GetWidth(), systemSetting.GetHeight())
  1232. mapeditMain.Show()
  1233. ControlWindow = MapEditor()
  1234. ControlWindow.Show()
Advertisement
Add Comment
Please, Sign In to add comment