//============================================================================= // // le_main.mel - initialize and setup up main dialog // //============================================================================= global int $le_selection_scriptjob; global string $le_current_selection[]; global string $le_dialog_name; global string $le_root_layout; global float $le_header[], $le_edit_data; global int $le_file_lock_status; // 0 = read only 1 = r/w global string $le_current_file; global string $le_last_focus; global string $le_icon_dir; //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // // main dialog // - spawns a "selection changed script job" global proc le_main () { global string $le_dialog_name = "level_editor"; global string $le_root_layout; global int $le_selection_scriptjob; global string $le_current_file; global string $le_icon_dir; string $layout; string $title = "Level Editor"; int $cwidth; $le_icon_dir = `getenv "ICON_DIR"`; eval ("source \"" + $le_icon_dir + "/le_build_object_menu.mel\""); source "le_file_io.mel"; source "le_utils.mel"; source "le_select_edit.mel"; source "le_event_editor.mel"; source "le_path_edit.mel"; le_init_string_tab(); if (`window -exists $le_dialog_name`) deleteUI $le_dialog_name; if (size ($le_current_file) > 0) { string $name = le_get_name ($le_current_file); $name = `substitute "\\.lock" $name ""`; $title += ": " + $name; } $le_dialog_name = `window -title $title -width 256 -height 64 -sizeable true -minimizeButton true -maximizeButton false -resizeToFitChildren false -menuBar true $le_dialog_name`; le_create_menus (); $cwidth = (`window -query -width $le_dialog_name`) - 8; $le_root_layout = ("rootLayout_" + $le_dialog_name); scrollLayout -horizontalScrollBarThickness 0 -verticalScrollBarThickness 16; rowColumnLayout -parent $le_dialog_name -numberOfColumns 1 -columnWidth 1 $cwidth -columnSpacing 1 4 $le_root_layout; window -edit -resizeToFitChildren true $le_dialog_name; $le_selection_scriptjob = 1; scriptJob -parent ($le_dialog_name) -event SelectionChanged "le_selection_changed ()"; le_selection_changed (); showWindow $le_dialog_name; string $all_jobs[] = `scriptJob -listJobs`; string $job; int $flag = true; for ($job in $all_jobs) { if (`match "le_unlock_current_file" $job` == "le_unlock_current_file") { $flag = false; break; } } if ($flag == true) scriptJob -event quitApplication "le_unlock_current_file()"; } /////////////////////////////////////////////////////////////////////////////////////////////////////////// // level entity dialog code // adding menus to dialog global proc le_create_menus () { menu -tearOff true "File"; menuItem -label "Load (.led)" -command ("le_load_file (\"\", \"\")"); menuItem -label "Save (.led)" -command ("le_save_file (\"\", \"\")"); menuItem -label "Unlock file" -command ("le_unlock_file (\"\", \"\")"); menuItem -label "Export and Crunch (.level and .dat)" -command ("le_export (\"\", \"\")"); menuItem -label "Load World (.mb)" -command ("le_load_world (\"\", \"\")"); menu -tearOff true "Edit"; menuItem -label "Copy" -command ("le_copy_selected_objects()"); menu -tearOff true "Level"; menuItem -label "Remove all level data" -command ("le_delete_all_layers()"); menuItem -label "Init level data" -command ("le_init_layers()"); menuItem -divider true; menuItem -label "Edit header" -command ("le_handle_header (\"create\")"); menu -tearOff true "Create"; menuItem -label "AI Path" -command ("le_handle_path (\"create_ai_path\")"); menuItem -label "Camera" -command ("le_handle_camera (\"create\")"); menuItem -label "Camera Path" -command ("le_handle_path (\"create_cam_path\")"); menuItem -label "Object" -command ("le_handle_object (\"create\")"); menuItem -label "Sound Object" -command ("le_handle_sound_object (\"create\")"); menuItem -label "World Object" -command ("le_handle_world_object (\"create\")"); menuItem -label "Zone" -command ("le_handle_zone (\"create\")"); } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // for each type, there is le_handle_ (string $action) // action is "create"/"assign"/"select"/"update" // which // 1. creates thing (if no thing), // 2. assigns attribute to thing (if no attribute), // 3. creates dialog (in $panel), with default values // 4. parses attribute string to modify controls global proc le_handle_zone (string $action) { global string $le_root_layout; global int $le_selection_scriptjob; string $thing; string $object[]; string $attr, $pairs[], $values[]; string $type_choice[2] = { "box", "sphere", "cylinder" }; float $pos[3]; float $rot[3]; float $scale[3]; // get thing if ($action == "create") { $le_selection_scriptjob = -1; // disable scriptjob $pos = le_get_focus (); $object = `polyCube -w 1 -h 1 -d 1 -ch 1 -name "zone"`; $thing = $object[0]; le_create_zone_layer(); layerEditorAddObjects Zones; le_place_thing ($thing, $pos); } else { string $sel[] = `ls -sl`; for ($thing in $sel) { if ($thing != "") { $attr = le_get_attributes ($thing); if ($attr != "") break; } } } if ($action == "update") { string $type; $attr = le_get_attributes ($thing); $pairs = le_pairs_from_attr ($attr); $values = le_values_from_pairs ($pairs, "type"); $type = $values[0]; $attr = "zone;"; $attr = le_parse_layout ($attr, $le_root_layout); le_apply_attributes ($thing, $attr); $pairs = le_pairs_from_attr ($attr); $values = le_values_from_pairs ($pairs, "type"); if ($values[0] != $type) { if ($values[0] == "box") $object = `polyCube -w 1 -h 1 -d 1 -ch 1 -name "zone"`; else if ($values[0] == "sphere") $object = `polySphere -radius 1 -ch 1 -subdivisionsX 12 -subdivisionsY 8 -name "zone"`; else if ($values[0] == "cylinder") $object = `polyCylinder -radius 1 -h 1 -ch 1 -subdivisionsX 12 -name "zone"`; delete `le_child ($thing)`; parent -shape -relative `le_child ($object[0])` $thing; delete $object[0]; select $thing; //???????????????????????? handy things to add here? // connectAttr ($thing+".scaleZ") ($thing+".scaleX"); // setAttr ($thing+".minScaleYLimit") 1; // setAttr ($thing+".minScaleYLimitEnable") 1; // setAttr ($thing+".minScaleXLimit") 1; // setAttr ($thing+".minScaleXLimitEnable") 1; } scriptJob -runOnce true -ie "le_handle_zone (\"touch\")"; return; //--------------------------------------------------------------------- } // get attribute if ($attr == "") { $pos = getAttr ($thing + ".translate"); $rot = getAttr ($thing + ".rotate"); $scale = getAttr ($thing + ".scale"); $attr = "zone;" + "type=" + $type_choice[0] + ";" + "translate=" + $pos[0] + "," + $pos[1] + "," + $pos[2] + ";" + "rotate=" + $rot[0] + "," + $rot[1] + "," + $rot[2] + ";" + "scale=" + $scale[0] + "," + $scale[1] + "," + $scale[2] + ";" + "object=;" + "camera=;"; le_apply_attributes ($thing, $attr); } // build dialog $pairs = le_pairs_from_attr ($attr); le_clear_layout (); setParent $le_root_layout; le_build_separator(); le_build_type ($thing, "Zone name", "zone"); le_build_separator(); $values = le_values_from_pairs ($pairs, "type"); le_build_choice ("type", $values[0], $type_choice, "le_handle_zone"); le_build_separator(); le_build_attr ($thing, "translate", 0); le_build_attr ($thing, "rotate", 0); le_build_attr ($thing, "scale", 0); // do object block $values = le_values_from_pairs ($pairs, "object"); le_build_separator(); le_build_noderef ("Object:", "object", $values, "le_handle_zone"); if ($values[0] != "") { le_build_separator(); le_build_zone_object_options ($thing); } } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& global proc le_update_zone (string $thing, string $type, string $object, string $camera) { string $thing; string $attr; float $pos[3]; float $rot[3]; float $scale[3]; // get attribute $pos = getAttr ($thing + ".translate"); $rot = getAttr ($thing + ".rotate"); $scale = getAttr ($thing + ".scale"); $attr = "zone;" + "type=" + $type + ";" + "translate=" + $pos[0] + "," + $pos[1] + "," + $pos[2] + ";" + "rotate=" + $rot[0] + "," + $rot[1] + "," + $rot[2] + ";" + "scale=" + $scale[0] + "," + $scale[1] + "," + $scale[2] + ";" + "object=" + $object + ";" + "camera=" + $camera + ";"; le_apply_attributes ($thing, $attr); } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& global proc le_handle_camera (string $action) { global string $le_root_layout; global int $le_selection_scriptjob; global int $le_event_group_index, $le_trigger_index, $le_action_index; global string $le_event_data[]; global string $le_action_tab[]; string $thing, $cam_type; string $object[]; string $attr, $pairs[], $values[]; float $fvalues[]; float $pos[3]; float $rot[3]; int $index; // get thing if ($action == "create") { $le_selection_scriptjob = -1; // disable scriptjob $pos = le_get_focus (); $object = `camera -name "camera"`; $thing = $object[0]; layerEditorAddObjects Objects; le_place_thing ($thing, $pos); scale 2 2 2 $thing; } else { string $sel[] = `ls -sl`; for ($thing in $sel) { if ($thing != "") { $attr = le_get_attributes ($thing); if ($attr != "") break; } } } if ($action == "update") { string $old_le_event_data[] = $le_event_data; clear $le_event_data; // get old camera type $attr = le_get_attributes ($thing); $pairs = le_pairs_from_attr ($attr); $cam_type = le_find_param_in_pairs ($pairs, "type"); // get newly entered data $attr = "camera;"; $attr = le_parse_layout ($attr, $le_root_layout); $pairs = le_pairs_from_attr ($attr); int $num_actions = 0; int $i, $value; string $name_tag; // copy first four entries (group and trigger) for ($i=0; $i<4; $i++) $le_event_data[$i] = $old_le_event_data[$i]; // set to start of action data in event_data array $index = 5; // path for track cam if ($cam_type == "track_cam") { $values = le_values_from_pairs ($pairs, "path"); if ($values[0] != "") { string $pattr = le_get_attributes ($values[0]); if ($pattr != "") { string $ppairs[] = le_pairs_from_attr ($pattr); if ($ppairs[0] == "path") { $i = le_find_in_tab ($le_action_tab, "Set camera path"); $le_event_data[$index++] = $le_action_tab[$i]; $le_event_data[$index++] = $values[0]; $num_actions++; } } } } // priority $value = `intField -q -value "int_priority_0"`; if ($value >= 0) { $i = le_find_in_tab ($le_action_tab, "Set camera priority"); $le_event_data[$index++] = $le_action_tab[$i]; $le_event_data[$index++] = $value; $num_actions++; } // time in $fvalue = `floatField -q -value "float_time_in_0"`; if ($fvalue >= 0) { $i = le_find_in_tab ($le_action_tab, "Set interp. time in (secs)"); $le_event_data[$index++] = $le_action_tab[$i]; $le_event_data[$index++] = $fvalue; $num_actions++; } // time out $fvalue = `floatField -q -value "float_time_out_0"`; if ($fvalue >= 0) { $i = le_find_in_tab ($le_action_tab, "Set interp. time out (secs)"); $le_event_data[$index++] = $le_action_tab[$i]; $le_event_data[$index++] = $fvalue; $num_actions++; } // time to look at if ($cam_type == "insta_plant_cam" || $cam_type == "insta_fixed_cam") { $fvalue = `floatField -q -value "float_time_look_0"`; if ($fvalue >= 0) { $i = le_find_in_tab ($le_action_tab, "Set look at time (secs)"); $le_event_data[$index++] = $le_action_tab[$i]; $le_event_data[$index++] = $fvalue; $num_actions++; } } // activate camera $le_event_data[$index++] = "Activate camera"; $num_actions++; // save total number of actions $le_event_data[4] = $num_actions; // update all event data le_update_event_data ($thing, $pairs); // get new zone $values = le_values_from_pairs ($pairs, "zone"); le_set_attr_from_param ($thing, "zone", $values[0]); // now rebuild the trigger entity entry from le_event_data le_rebuild_event_data ($thing); scriptJob -runOnce true -ie "le_handle_camera (\"touch\")"; return; } // get attribute if ($attr == "") { $pos = getAttr ($thing + ".translate"); $rot = getAttr ($thing + ".rotate"); $attr = "camera;" + "type=;" + "zone=;" + "translate=" + $pos[0] + "," + $pos[1] + "," + $pos[2] + ";" + "rotate=" + $rot[0] + "," + $rot[1] + "," + $rot[2] + ";" + "events=1,cam_data,1,Is main char in my zone,1,Activate camera;"; le_apply_attributes ($thing, $attr); } // build dialog $pairs = le_pairs_from_attr ($attr); le_clear_layout (); setParent $le_root_layout; $cam_type = le_find_param_in_pairs ($pairs, "type"); le_build_separator(); le_build_type ($thing, "Camera name", "camera"); le_build_separator(); le_build_camera_selector ($thing, $pairs); // pos le_build_separator(); le_build_attr ($thing, "translate", 0); // rot if ($cam_type == "fixed_cam" || $cam_type == "parented_fixed_cam" || $cam_type == "insta_fixed_cam" || $cam_type == "al_cam" || $cam_type == "al_insta_fixed" || $cam_type == "directional_cam" || $cam_type == "directional_climb_cam" || $cam_type == "2dscroll_cam") le_build_attr ($thing, "rotate", 0); // get event data $le_event_data = le_values_from_pairs ($pairs, "events"); // stuff into the group/trig/action tables // there should be one group and one trigger but many actions // group index -> 1, trig index -> 3, action index -> 5 le_build_event_lists(); // zone selector le_build_separator(); $values = le_values_from_pairs ($pairs, "zone"); le_build_noderef ("Zone:", "zone", $values, "le_handle_camera"); if ($values[0] != "") { le_build_separator(); le_build_object_zone_options ($thing); } // path if ($cam_type == "track_cam") { $index = le_find_in_tab ($le_event_data, "Set camera path"); if ($index == -1) $values[0] = ""; else $values[0] = $le_event_data[$index+1]; le_build_separator(); le_build_noderef ("Set camera path:", "path", $values, "le_handle_camera"); } // trigger le_build_separator(); le_build_camera_trigger ($thing); // priority $index = le_find_in_tab ($le_event_data, "Set camera priority"); if ($index == -1) $values[0] = -1; else $values[0] = $le_event_data[$index+1]; le_build_int ("Set camera priority (-1 = default)", "priority", $values, "le_handle_camera"); // time in $index = le_find_in_tab ($le_event_data, "Set interp. time in (secs)"); if ($index == -1) $values[0] = -1; else $values[0] = $le_event_data[$index+1]; le_build_float ("Set interp. time in (secs)", "time_in", $values, "le_handle_camera", 0); // time out $index = le_find_in_tab ($le_event_data, "Set interp. time out (secs)"); if ($index == -1) $values[0] = -1; else $values[0] = $le_event_data[$index+1]; le_build_float ("Set interp. time out (secs)", "time_out", $values, "le_handle_camera", 0); // time to look at if ($cam_type == "insta_plant_cam" || $cam_type == "insta_fixed_cam") { $index = le_find_in_tab ($le_event_data, "Set look at time (secs)"); if ($index == -1) $values[0] = -1; else $values[0] = $le_event_data[$index+1]; le_build_float ("Set look at time (secs)", "time_look", $values, "le_handle_camera", 0); } } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& global proc le_update_camera (string $thing, string $type, string $zone, string $events) { string $thing; string $attr; float $pos[3]; float $rot[3]; // get attribute $pos = getAttr ($thing + ".translate"); $rot = getAttr ($thing + ".rotate"); $attr = "camera;" + "type=" + $type + ";" + "zone=" + $zone + ";" + "translate=" + $pos[0] + "," + $pos[1] + "," + $pos[2] + ";" + "rotate=" + $rot[0] + "," + $rot[1] + "," + $rot[2] + ";" + "events=" + $events; le_apply_attributes ($thing, $attr); } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& global proc le_handle_path (string $action) { global string $le_root_layout; global int $le_selection_scriptjob; global int $le_path_point_script_job[]; string $thing, $attr, $pairs[], $values[], $type; float $fvalues[]; float $pos[3], $rot[3], $scale[3]; int $i, $num; // get thing if ($action == "create_ai_path") { float $pos2[3]; string $pdata1, $pdata2; $le_selection_scriptjob = -1; // disable scriptjob $pos = le_get_focus (); $pdata1 = " " + $pos[0] + " " + $pos[1] + " " + $pos[2]; $pos[0] += 20; $pdata2 = " " + $pos[0] + " " + $pos[1] + " " + $pos[2]; string $cmd = "curve -d 1 -ws -name \"path\" -p " + $pdata1 + " -p" + $pdata2 + "\n"; print ($cmd); $thing = `eval $cmd`; $pos2[0] = 0; $pos2[1] = 0; $pos2[2] = 0; layerEditorAddObjects AI; le_place_thing ($thing, $pos2); move $pos[0] $pos[1] $pos[2] ($thing+".scalePivot") ($thing+".rotatePivot"); setAttr ($thing + ".dispEP") 1; } else if ($action == "create_cam_path") { float $pos2[3]; string $pdata1, $pdata2; $le_selection_scriptjob = -1; // disable scriptjob $pos = le_get_focus (); $pdata1 = " " + $pos[0] + " " + $pos[1] + " " + $pos[2]; $pos[0] += 20; $pdata2 = " " + $pos[0] + " " + $pos[1] + " " + $pos[2]; string $cmd = "curve -d 1 -ws -name \"path\" -p " + $pdata1 + " -p" + $pdata2 + "\n"; print ($cmd); $thing = `eval $cmd`; $pos2[0] = 0; $pos2[1] = 0; $pos2[2] = 0; layerEditorAddObjects Cameras; le_place_thing ($thing, $pos2); move $pos[0] $pos[1] $pos[2] ($thing+".scalePivot") ($thing+".rotatePivot"); setAttr ($thing + ".dispEP") 1; } else { string $item, $sel[], $undotted_sel[]; $sel = `ls -sl`; for ($item in $sel) { tokenize $item "." $undotted_sel; $thing = $undotted_sel[0]; if ($thing != "") { $attr = le_get_attributes ($thing); if ($attr != "") break; } } } if ($action == "update") { string $label; int $index = 0; float $points[]; $attr = le_get_attributes ($thing); $pairs = le_pairs_from_attr ($attr); $type = le_find_param_in_pairs ($pairs, "type"); $attr = "path;"; $attr = le_parse_layout ($attr, $le_root_layout); $pairs = le_pairs_from_attr ($attr); $num = `getAttr ($thing + ".spans")`; for ($i=0; $i<=$num; $i++) { $label = ("float_point" + $i + "_0"); $points[$index] = `floatField -q -value $label`; setAttr ($thing + ".controlPoints[" + $i + "].xValue") $points[$index++]; $label = ("float_point" + $i + "_1"); $points[$index] = `floatField -q -value $label`; setAttr ($thing + ".controlPoints[" + $i + "].yValue") $points[$index++]; $label = ("float_point" + $i + "_2"); $points[$index] = `floatField -q -value $label`; setAttr ($thing + ".controlPoints[" + $i + "].zValue") $points[$index++]; } le_update_path ($thing, $type); scriptJob -runOnce true -ie "le_handle_path (\"touch\")"; return; } if ($action != "touch") { for ($i=0; $i