home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 58 / pcpp58b_TRIBES.iso / Tribes / base / scripts.vol / editor.cs < prev    next >
Encoding:
Text File  |  1998-12-16  |  14.6 KB  |  641 lines

  1. function saveMission( %objName, %fileName )
  2. {
  3.    focusServer();
  4.     exportObjectToScript( %objName, "base\\", %fileName);
  5.    focusClient();
  6. }
  7.  
  8. function missionSaveObject( %objName, %fileName )
  9. {
  10.     focusServer();
  11.     exportObjectToScript( %objName, "temp\\", %fileName );
  12.     focusClient();
  13. }
  14.  
  15. function missionLoadObject( %objParentName, %fileName )
  16. {
  17.     focusServer();
  18.     setInstantGroup( %objParentName );
  19.     exec( %fileName ); // temp is in the path.
  20.     focusClient();
  21. }
  22.  
  23. function edit()
  24. {
  25.    GuiEditMode(MainWindow);
  26.    GuiInspect(MainWindow);
  27.    cursorOn(MainWindow);
  28. }
  29.  
  30. function ObjectToCamera::onAction()
  31. {
  32.    ME::ObjectToCamera();
  33. }
  34.  
  35. function CameraToObject::onAction()
  36. {
  37.    ME::CameraToObject();
  38. }
  39.  
  40. function ObjectToScreenCenter::onAction()
  41. {
  42.    ME::ObjectToSC();
  43. }
  44.  
  45. function MissionRegObject(%group, %name, %func, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10)
  46. {
  47.    if($ME::NumGroups == "")
  48.       $ME::NumGroups = 0;
  49.  
  50.    for(%i = 0; %i < $ME::NumGroups; %i++)
  51.       if($ME::Group[%i] == %group)
  52.          break;
  53.    if(%i == $ME::NumGroups)
  54.    {
  55.       $ME::Group[%i] = %group;
  56.       $ME::NumGroups++;
  57.    }
  58.    $ME::GroupEC[%group]++;
  59.    $ME::Group[%group, ($ME::GroupEC[%group] - 1)] = %name;
  60.  
  61.    %funcStr = %func @ "(";
  62.    for(%j = 1; %a[%j] != ""; %j++)
  63.    {
  64.       if(%a[%j + 1] == "")
  65.          %funcStr = %funcStr @ "\"" @ %a[%j] @ "\");";
  66.       else
  67.          %funcStr = %funcStr @ "\"" @ %a[%j] @ "\", ";
  68.    }
  69.    $ME::Func[%group, %name] = %funcStr;
  70. }
  71.  
  72. function GroupList::onAction()
  73. {
  74.    TextList::clear("NameList");
  75.    %group = Control::getValue("GroupList");
  76.    $ME::curGroup = %group;
  77.  
  78.    for(%i = 0; %i < $ME::GroupEC[%group]; %i++)
  79.       TextList::AddLine("NameList", $ME::Group[%group, %i]);
  80. }
  81.  
  82. function NameList::onAction()
  83. {
  84.    %name = Control::getValue("NameList");
  85.    %func = $ME::Func[$ME::curGroup, %name];
  86.    eval(%func);
  87. }
  88.  
  89. function MissionObjectList::onUnselected(%world, %obj)
  90. {
  91.    if(%obj == $ME::InspectObject && %world == $ME::InspectWorld)
  92.    {
  93.       MissionObjectList::Inspect(1, -1);
  94.       $ME::InspectObject = "";
  95.    }
  96.    
  97.    ME::onUnselected( %world, %obj );
  98. }
  99.  
  100. function MissionObjectList::onSelectionCleared()
  101. {
  102.    MissionObjectList::Inspect(1, -1);
  103.    $ME::InspectObject = "";
  104.    
  105.    ME::onSelectionCleared();
  106. }
  107.  
  108. function MissionObjectList::onSelected(%world, %obj)
  109. {
  110.    if($ME::InspectObject == "")
  111.    {
  112.       $ME::InspectObject = %obj;
  113.       $ME::InspectWorld = %world;
  114.       MissionObjectList::Inspect($ME::InspectWorld, %obj);
  115.       
  116.       // it's on the server:
  117.       focusServer();
  118.       %locked = %obj.locked;
  119.       focusClient();
  120.  
  121.       if(%locked)
  122.          Control::setText("LockButton", "Unlock");
  123.       else
  124.          Control::setText("LockButton", "Lock");
  125.    }
  126.    
  127.    ME::onSelected( %world, %obj );
  128. }
  129.  
  130. function ApplyButton::onAction()
  131. {
  132.    MissionObjectList::Apply();
  133. }
  134.  
  135. function LockButton::onAction()
  136. {
  137.    if($ME::InspectObject != "")
  138.    {
  139.       focusServer();
  140.       %locked = !$ME::InspectObject.locked;
  141.       $ME::InspectObject.locked = %locked;
  142.       focusClient();
  143.       if(%locked)
  144.          Control::setText("LockButton", "Unlock");
  145.       else
  146.          Control::setText("LockButton", "Lock");
  147.       MissionObjectList::Inspect($ME::InspectWorld, $ME::InspectObject);
  148.    }
  149. }
  150.  
  151. $ME::ShowEditObjects = true;
  152. $ME::ShowGrabHandles = true;
  153. $ME::SnapToGrid = false;
  154.  
  155. $ME::XGridSnap = 1;
  156. $ME::YGridSnap = 1;
  157. $ME::ZGridSnap = 0.001;
  158.  
  159. function ME::SnapToGrid()
  160. {
  161.    Control::setActive(XGridSnapCtrl, $ME::SnapToGrid);
  162.    Control::setActive(YGridSnapCtrl, $ME::SnapToGrid);
  163.    Control::setActive(ZGridSnapCtrl, $ME::SnapToGrid);
  164.    Control::setActive(UseTerrainGrid, $ME::SnapToGrid);
  165. }
  166.  
  167. $ME::ConstrainX = false;
  168. $ME::ConstrainY = false;
  169. $ME::ConstrainZ = false;
  170.  
  171. function UseTerrainGrid::onAction()
  172. {
  173.     ME::onUseTerrainGrid();
  174.     Control::setValue(XGridSnapCtrl, $ME::XGridSnap);
  175.     Control::setValue(YGridSnapCtrl, $ME::YGridSnap);
  176.     Control::setValue(ZGridSnapCtrl, $ME::ZGridSnap);
  177. }
  178.  
  179. $ME::RotateXAxis = false;
  180. $ME::RotateYAxis = false;
  181. $ME::RotateZAxis = true;
  182. $ME::RotationSnap = 90.0;
  183. $ME::SnapRotations = false;
  184.  
  185. function ME::SnapRotations()
  186. {
  187.    Control::setActive(RotationSnapCtrl, $ME::SnapRotations);
  188. }
  189.  
  190. $ME::DropAtCamera = false;
  191. $ME::DropWithRotAtCamera = false;
  192. $ME::DropBelowCamera = false;
  193. $ME::DropToScreenCenter = true;
  194. $ME::DropToSelectedObject = false;
  195.  
  196. $ME::ObjectsSnapToTerrain = false;
  197. $ME::UsePlaneMovement = false;
  198.  
  199. // just toggle the value for this flag variable
  200. function METogglePlaneMovement()
  201. {
  202.     if( $ME::UsePlaneMovement == "true" )
  203.     {
  204.         $ME::UsePlaneMovement = false;
  205.     }
  206.     else
  207.     {
  208.         $ME::UsePlaneMovement = true;
  209.     }
  210.     ME::GetConsoleOptions();
  211. }
  212.  
  213. function MEHideOptions()
  214. {
  215.    if( Control::getVisible("OptionsCtrl") )
  216.    {
  217.       Control::setVisible("OptionsCtrl", false);
  218.       ME::GetConsoleOptions();
  219.    }
  220.  
  221.    if( Control::getVisible("TedOptionsCtrl") )
  222.    {
  223.       Control::setVisible("TedOptionsCtrl", false );
  224.       Ted::GetConsoleOptions();
  225.    }
  226. }
  227.  
  228. function MEShowOptions()
  229. {
  230.    if($ME::Loaded)
  231.    {
  232.       if( Control::getVisible("HelpCtrl"))
  233.          return;
  234.         
  235.       if( Control::getVisible("MEObjectList") )
  236.       {
  237.          Control::setVisible("OptionsCtrl", true);
  238.          Control::setValue( MEUsePlaneMovement, $ME::UsePlaneMovement );
  239.          ME::SnapRotations();
  240.          ME::SnapToGrid();
  241.          return;
  242.       }
  243.       
  244.       if( Control::getVisible("TedBar") )
  245.       {
  246.          Control::setVisible("TedOptionsCtrl", true );
  247.          return;
  248.       }
  249.    }
  250. }
  251.  
  252. function METoggleOptions()
  253. {
  254.    if( Control::getVisible("MEObjectList" ) )
  255.       %optionName = "OptionsCtrl";
  256.    if( Control::getVisible("TedBar" ) )
  257.       %optionName = "TedOptionsCtrl";
  258.       
  259.    if( Control::getVisible( %optionName ) )
  260.    {
  261.       MEHideOptions();
  262.    }
  263.    else
  264.    {
  265.       MEShowOptions();
  266.    }
  267. }
  268.  
  269. //-----------------------------------------------------
  270.  
  271. function MEShowHelp()
  272. {
  273.    if($ME::Loaded)
  274.    {
  275.       if(Control::getVisible("OptionsCtrl"))
  276.          return;
  277.       if(Control::getVisible("TedOptionsCtrl"))
  278.          return;
  279.       Control::setVisible("HelpCtrl", true );
  280.    }
  281. }
  282.  
  283. function MEHideHelp()
  284. {
  285.    if($ME::Loaded)
  286.       Control::setVisible("HelpCtrl", false );
  287. }
  288.  
  289. function METoggleHelp()
  290. {
  291.    if( Control::getVisible("HelpCtrl"))
  292.    {
  293.       MEHideHelp();
  294.    }
  295.    else
  296.    {
  297.       MEShowHelp();
  298.    }
  299. }
  300.  
  301. //-----------------------------------------------------
  302.  
  303.  
  304. function MEShowCreator()
  305. {
  306.    if(!$ME::Loaded)
  307.       return;
  308.    
  309.    MEHideOptions();
  310.    MEHideHelp();
  311.    
  312.    unfocus(TedObject);
  313.    focus(MissionEditor);
  314.    focus(editCamera);
  315.    postAction(EditorGui, Attach, editCamera);
  316.    cursorOn(MainWindow);
  317.  
  318.    Control::setVisible("MEObjectList", true);
  319.    Control::setVisible("Inspector", false);
  320.    Control::setVisible("Creator", true);
  321.    Control::setVisible("TedBar", false);
  322.    Control::setVisible("SaveBar", true);
  323.  
  324.    TextList::clear("GroupList");
  325.    TextList::clear("NameList");
  326.  
  327.    for(%i = 0; %i < $ME::NumGroups; %i++)
  328.       TextList::AddLine("GroupList", $ME::Group[%i]);
  329. }
  330.  
  331. function MEShowInspector()
  332. {
  333.    if(!$ME::Loaded)
  334.       return;
  335.  
  336.    MEHideOptions();
  337.    MEHideHelp();
  338.  
  339.    unfocus(TedObject);
  340.    focus(MissionEditor);
  341.    focus(editCamera);
  342.    postAction(EditorGui, Attach, editCamera);
  343.    cursorOn(MainWindow);
  344.  
  345.    Control::setVisible("MEObjectList", true);
  346.    Control::setVisible("Inspector", true);
  347.    Control::setVisible("Creator", false);
  348.    Control::setVisible("TedBar", false);
  349.    Control::setVisible("SaveBar", true);
  350. }
  351.  
  352. function MEShowTed()
  353. {
  354.    if(!$ME::Loaded)
  355.       return;
  356.  
  357.    MEHideOptions();
  358.    MEHideHelp();
  359.    
  360.    Control::setVisible("TedBar", true);
  361.    Control::setVisible("SaveBar", true);
  362.    Control::setVisible("MEObjectList", false);
  363.    Control::setVisible("Inspector", false);
  364.    Control::setVisible("Creator", false);
  365.    unfocus(MissionEditor);
  366.    focus(TedObject);
  367.    focus(editCamera);
  368.    postAction(EditorGui, Attach, editCamera);
  369.    cursorOn(MainWindow);
  370.  
  371.    // set the right button to nothing
  372.    TED::setRButtonAction( "" );
  373.     
  374.    // set the terrain type popup
  375.    Popup::clear(TerrainTypes);
  376.    %i = Ted::getNumTerrainTypes();
  377.    if( $TED::success == true )
  378.       for( %j = 0; %j < %i; %j++ )
  379.          Popup::addLine( TerrainTypes, Ted::getTerrainTypeName(%j), %j );
  380.    Popup::setSelected(TerrainTypes, Ted::getTerrainType() );
  381.  
  382.    // set the detail level popup
  383.    Popup::clear(BrushDetail);
  384.    %i = Ted::getMaxBrushDetail();
  385.    if( $TED::success == true )
  386.       for( %j = 0; %j < %i; %j++ )
  387.          Popup::addLine( BrushDetail, "Level " @ %j, %j );
  388.    Popup::setSelected(BrushDetail, Ted::getBrushDetail() );
  389.  
  390.    // setup the buttons with default's if no pref
  391.    MESetupTedButton( TEDModeOne, select, true );
  392.    MESetupTedButton( TEDModeTwo, deselect, true );
  393.    MESetupTedButton( TEDModeThree, raiseHeight, true );
  394.    MESetupTedButton( TEDModeFour, lowerHeight, true );
  395.    
  396.    MESetupTedButton( TEDProcessAction, "" );
  397.    Control::setText( TEDProcessAction, " -- Selection Action --" );
  398. }
  399.  
  400. function MESetupTedButton( %button, %func, %usePref )
  401. {       
  402.    if( %usePref == "true" )
  403.    {
  404.       if( $pref::[%button] == "" )
  405.          $pref::[%button] = %func;
  406.       else
  407.          %func = $pref::[%button];
  408.    }
  409.    else if( %button != "TEDProcessAction" )
  410.    {
  411.       $pref::[%button] = %func;
  412.    }
  413.    
  414.    // set the ted mouse buttons..
  415.    Popup::clear(%button);
  416.    %selItem = 0;
  417.    %i = Ted::getNumActions();
  418.    if( $TED::success == true )
  419.    {
  420.       for( %j = 0; %j < %i; %j++ )
  421.       {
  422.          if( Ted::isActionMouseable( %j ) )
  423.          {
  424.             Popup::addLine( %button, Ted::getActionName(%j), %j );
  425.             if( Ted::getActionName(%j) == %func )
  426.                %selItem = %j;
  427.          }
  428.       }
  429.    }
  430.    Popup::setSelected(%button, %selItem );
  431. }
  432.  
  433. function MEMode()
  434. {
  435.    if (!isObject(editCamera))
  436.       return;
  437.  
  438.    $Server::timeLimit = 0;
  439.    if(!isObject(EditorGui))
  440.       GuiLoadContentCtrl("MainWindow", "gui\\editor.gui");
  441.  
  442.    if(!$ME::Loaded)
  443.       return;
  444.  
  445.    MEHideOptions();
  446.    MEHideHelp();
  447.    
  448.    MissionObjectList::ClearDisplayGroups();
  449.    MissionObjectList::AddDisplayGroup(1, "MissionGroup");
  450.    MissionObjectList::AddDisplayGroup(1, "MissionCleanup");
  451.    MissionObjectList::SetSelMode(1);
  452.    MEShowInspector();
  453.    ME::GetConsoleOptions();
  454. }
  455.  
  456. function MEGameMode()
  457. {
  458.    unfocus(TedObject);
  459.    unfocus(MissionEditor);
  460.    unfocus(editCamera);
  461.    GuiLoadContentCtrl(MainWindow, "gui\\play.gui");
  462.    cursorOff(MainWindow);
  463.    focus(playDelegate);
  464. }
  465.  
  466. function MEHide()
  467. {
  468.    if(!isObject(EditorGui))
  469.       GuiLoadContentCtrl("MainWindow", "gui\\editor.gui");
  470.  
  471.    focus(editCamera);
  472.    postAction(EditorGui, Attach, editCamera);
  473.  
  474.    Control::setVisible("TedBar", false);
  475.    Control::setVisible("MEObjectList", false);
  476.    Control::setVisible("Inspector", false);
  477.    Control::setVisible("Creator", false);
  478.    Control::setVisible("SaveBar", false);
  479.    MEHideOptions();
  480.    MEHideHelp();
  481. }
  482.  
  483. function MELSEdit()
  484. {
  485.    LSEditor( MainWindow );
  486.    flushTextureCache();
  487. }
  488.  
  489. //--------------------------------------------------------------
  490. // generic callback functions to pass along to current control
  491.  
  492. function MEDeleteSelection()
  493. {
  494.    if( Control::getVisible("MEObjectList") )
  495.       ME::DeleteSelection();
  496. }
  497.  
  498. function MECopySelection()
  499. {
  500.    if( Control::getVisible("TedBar") )
  501.       Ted::copy();
  502.    if( Control::getVisible("MEObjectList") )
  503.       ME::CopySelection();
  504. }
  505.  
  506. function MECutSelection()
  507. {
  508.    if( Control::getVisible("MEObjectList") )
  509.       ME::CutSelection();
  510. }
  511.  
  512. function MEPasteSelection()
  513. {
  514.    if( Control::getVisible("TedBar") )
  515.       Ted::floatPaste();
  516.    if( Control::getVisible("MEObjectList") )
  517.       ME::PasteSelection();
  518. }
  519.  
  520. function MEDuplicateSelection()
  521. {
  522.    if( Control::getVisible("TedBar") )
  523.       Ted::floatSelection();
  524.    if( Control::getVisible("MEObjectList") )
  525.       ME::DuplicateSelection();
  526. }
  527.  
  528. function MEUndo()
  529. {
  530.    if( Control::getVisible("TedBar") )
  531.       Ted::undo();
  532.    if( Control::getVisible("MEObjectList") )
  533.       ME::Undo();
  534. }
  535.  
  536. function MERedo()
  537. {
  538.    if( Control::getVisible("TedBar") )
  539.       Ted::redo();
  540.    if( Control::getVisible("MEObjectList") )
  541.       ME::Redo();
  542. }
  543.  
  544. //--------------------------------------------------------------
  545. // the popup buttons - right click brings up popup with functions
  546.  
  547. function TEDModeOne::onPressed()
  548. {
  549.    Ted::setLButtonAction( Ted::getActionName( Popup::getSelected( TEDModeOne ) ) );
  550.    Ted::setRButtonAction( "" );
  551. }
  552. function TEDModeOne::onSelect( %string, %level )
  553. {
  554.    MESetupTedButton( TEDModeOne, %string );
  555.    Ted::setLButtonAction( %string );
  556.    Ted::setRButtonAction( "" );
  557. }
  558.  
  559. function TEDModeTwo::onPressed()
  560. {
  561.    Ted::setLButtonAction( Ted::getActionName( Popup::getSelected( TEDModeTwo ) ) );
  562.    Ted::setRButtonAction( "" );
  563. }
  564. function TEDModeTwo::onSelect( %string, %level )
  565. {
  566.    MESetupTedButton( TEDModeTwo, %string );
  567.    Ted::setLButtonAction( %string );
  568.    Ted::setRButtonAction( "" );
  569. }
  570.  
  571. function TEDModeThree::onPressed()
  572. {
  573.    Ted::setLButtonAction( Ted::getActionName( Popup::getSelected( TEDModeThree ) ) );
  574.    Ted::setRButtonAction( "" );
  575. }
  576. function TEDModeThree::onSelect( %string, %level )
  577. {
  578.    MESetupTedButton( TEDModeThree, %string );
  579.    Ted::setLButtonAction( %string );
  580.    Ted::setRButtonAction( "" );
  581. }
  582.  
  583. function TEDModeFour::onPressed()
  584. {
  585.    Ted::setLButtonAction( Ted::getActionName( Popup::getSelected( TEDModeFour ) ) );
  586.    Ted::setRButtonAction( "" );
  587. }
  588. function TEDModeFour::onSelect( %string, %level )
  589. {
  590.    MESetupTedButton( TEDModeFour, %string );
  591.    Ted::setLButtonAction( %string );
  592.    Ted::setRButtonAction( "" );
  593. }
  594.  
  595. function TEDProcessAction::onSelect( %string, %level )
  596. {
  597.    Ted::processAction( Ted::getActionName( %level ) );
  598.    Control::setText( TEDProcessAction, " -- Selection Action --" );
  599. }
  600.  
  601. //--------------------------------------------------------------
  602.  
  603. function TerrainTypes::onSelect(%string, %level)
  604. {                                
  605.     TED::setTerrainType( %level );
  606. }
  607.  
  608. function BrushDetail::onSelect(%string, %level)
  609. {
  610.    Ted::setBrushDetail(%level);
  611. }
  612.  
  613. if(focusServer())
  614. {
  615.    focusClient();
  616.    if($ME::Loaded == "")
  617.    {
  618.       $Server::timeLimit = 0;
  619.       $ME::Loaded = true;
  620.       exec( "move.cs" );
  621.       ME::Move();
  622.       exec( "med.cs");
  623.       exec( "ted.cs");
  624.       exec( "RegisterObjects.cs");
  625.       ted();
  626.       MEMode();
  627.    }
  628. }
  629. else
  630. {
  631.    if($ME::CamLoaded == "")
  632.    {
  633.       // just give us da edit cam
  634.       $ME::CamLoaded = true;
  635.       exec("move.cs");
  636.       MEHide();
  637.    }
  638. }
  639.  
  640.  
  641.