| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553 |
- $currentTarget = "";
- // Doing this in script might end up being a waste of time
- // but because of the way the current inspector is messing about
- // it is needed.
- function GuiEditorCtrlProperties::update(%this, %target)
- {
- // We can only get here from the guiEdit so its definitely a
- // gui control, no need to check.
- if(%target == 0)
- {
- GuiEditorCtrlProperties.clear();
- $currentTarget = "";
- }
- else
- {
- if($currentTarget != %target)
- {
- %this.build(%target);
- }
- else
- {
- // if we are locked update the gui to reflect it.
- if($currentTarget.getFieldValue("locked"))
- {
- $targetprevLocked = true;
- %this.build($currentTarget);
- }
- // if we were prev locked we need to rebuild
- else if($targetprevLocked)
- {
- // just so this isn't always happening
- // sometimes we only want to updateValues
- %this.build($currentTarget);
- $targetprevLocked = false;
- }
- // update values of fields.
- %this.updateValues(%target);
- }
- }
- }
- function GuiEditorCtrlProperties::updateValues(%this, %target)
- {
- // go through every field and updates.
- %count = %target.getFieldCount();
- for(%i = 0; %i < %count; %i++)
- {
- %field = %target.getField(%i);
- %fieldType = %target.getFieldType(%field);
- if(%fieldType $= "Point2I")
- {
- %fieldVal = %target.getFieldValue(%field);
- %fieldEditX = %field @ "editX";
- %fieldEditY = %field @ "editY";
- %fieldEditX.setText(%fieldVal.x);
- %fieldEditY.setText(%fieldVal.y);
-
- }
- else if(%fieldType $= "bool")
- {
- %fieldEdit = %field @ "edit";
- %fieldEdit.setStateOn(%target.getFieldValue(%field));
- }
- else
- {
- %fieldEdit = %field @ "edit";
- %fieldEdit.setText(%target.getFieldValue(%field));
- }
- }
- }
- function GuiEditorCtrlProperties::build(%this, %target)
- {
- // assign target so we can keep track.
- $currentTarget = %target;
- GuiEditorCtrlProperties.clear();
-
- // every field gets a gui
- %count = %target.getFieldCount();
- for(%i = 0; %i < %count; %i++)
- {
- %field = %target.getField(%i);
- // we only want the locked field.
- if($currentTarget.getFieldValue("locked"))
- {
- if(%field !$= "locked")
- {
- continue;
- }
- }
-
- %fieldCtrl = new GuiControl()
- {
- extent = "320 30";
- horizSizing = "right";
- vertSizing = "bottom";
- profile = "GuiDefaultProfile";
- visible = "1";
- };
-
- %fieldLabel = new GuiControl()
- {
- text = %field @ ": ";
- profile = "GuiTextRightProfile";
- Position = "10 0";
- extent = "150 30";
- horizSizing = "right";
- vertSizing = "bottom";
- visible = "1";
- };
-
- %fieldType = %target.getFieldType(%field);
- %fieldVal = %target.getFieldValue(%field);
- %fieldEdit = %this.buildEdit(%field,%fieldType,%fieldVal);
- %fieldCtrl.add(%fieldLabel);
- %fieldCtrl.add(%fieldEdit);
- GuiEditorCtrlProperties.add(%fieldCtrl);
- }
-
- // we don't want dynamic fields either.
- if($currentTarget.getFieldValue("locked"))
- {
- return;
- }
-
- // build dynamic fields
- %dynCtrl = new GuiPanelCtrl()
- {
- position = "10 0";
- extent = "320 20";
- horizSizing = "right";
- vertSizing = "bottom";
- profile = "GuiPanelProfile";
- visible = "1";
- Text = "Dynamic Fields";
- };
-
- GuiEditorCtrlProperties.add(%dynCtrl);
-
- %addDyn = new GuiControl()
- {
- Position = "0 20";
- extent = "320 30";
- horizSizing = "right";
- vertSizing = "bottom";
- profile = "GuiDefaultProfile";
- visible = "1";
- };
-
- %label = new GuiControl()
- {
- text = "Add Dynamic Field";
- profile = "GuiTextProfile";
- Position = "10 0";
- extent = "150 30";
- horizSizing = "right";
- vertSizing = "bottom";
- visible = "1";
- };
-
- %bttn = new GuiButtonCtrl()
- {
- text = "+";
- profile = "GuiButtonDynProfile";
- Position = "280 0";
- extent = "30 30";
- Command = "GuiEditorCtrlProperties.addDynamic();";
- };
-
- %addDyn.add(%label);
- %addDyn.add(%bttn);
- %dynCtrl.add(%addDyn);
- if(isObject(DynamicContainer))
- {
- DynamicContainer.clear();
- DynamicContainer.delete();
- }
-
- %dynChain = new GuiChainCtrl(DynamicContainer)
- {
- position = "0 50";
- extent = "320 30";
- };
-
- %dynCtrl.add(%dynChain);
-
- // dynamic fields need to be updated separately.
- // eventually should separate fields by group.
-
- GuiEditorCtrlProperties.updateDynamicFields();
- }
- function GuiEditorCtrlProperties::addDynamic(%this)
- {
- %name = "dynamicField" @ $currentTarget.getDynamicFieldCount();
- $currentTarget.setFieldValue(%name,"defaultValue");
-
- GuiEditorCtrlProperties.updateDynamicFields();
- }
- function GuiEditorCtrlProperties::removeDynamic(%this, %field)
- {
- // giving a dynamic field a null value deletes it.
- $currentTarget.setFieldValue(%field,"");
- GuiEditorCtrlProperties.updateDynamicFields();
- }
- function GuiEditorCtrlProperties::renameDynamic(%this, %field, %newName, %fieldVal)
- {
- $currentTarget.setFieldValue(%newName, %fieldVal);
- $currentTarget.setFieldValue(%field,"");
- GuiEditorCtrlProperties.updateDynamicFields();
- }
- function GuiEditorCtrlProperties::updateDynamicFields(%this)
- {
- %count = $currentTarget.getDynamicFieldCount();
- DynamicContainer.clear();
- for(%i = 0; %i < %count; %i++)
- {
- %field = $currentTarget.getDynamicField(%i);
- %fieldVal = $currentTarget.getFieldValue(%field);
-
-
- %dynCtrl = new GuiControl()
- {
- extent = "320 30";
- horizSizing = "right";
- vertSizing = "bottom";
- profile = "GuiDefaultProfile";
- visible = "1";
- };
-
- %label = new GuiTextEditCtrl()
- {
- text = %field;
- profile = "GuiTextEditProfile";
- Position = "10 0";
- extent = "130 30";
- horizSizing = "right";
- vertSizing = "bottom";
- visible = "1";
- };
-
- %val = new GuiTextEditCtrl()
- {
- text = %fieldVal;
- profile = "GuiTextEditProfile";
- Position = "140 0";
- extent = "130 30";
- horizSizing = "right";
- vertSizing = "bottom";
- visible = "1";
- };
- %label.setFieldValue("AltCommand", "GuiEditorCtrlProperties.renameDynamic(" @ %field @ "," @ %label.getId() @ ".getText()," @ %val.getId() @ ".getText());");
- %label.setFieldValue("Validate", "GuiEditorCtrlProperties.renameDynamic(" @ %field @ "," @ %label.getId() @ ".getText()," @ %val.getId() @ ".getText());");
-
- %val.setFieldValue("AltCommand", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %val.getId() @ ".getText());");
- %val.setFieldValue("Validate", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %val.getId() @ ".getText());");
-
- %bttn = new GuiButtonCtrl()
- {
- text = "X";
- profile = "GuiButtonDynProfile";
- Position = "280 0";
- extent = "30 30";
- };
-
- %bttn.setFieldValue("Command", "GuiEditorCtrlProperties.removeDynamic(" @ %field @ ");");
- %dynCtrl.add(%label);
- %dynCtrl.add(%val);
- %dynCtrl.add(%bttn);
- DynamicContainer.add(%dynCtrl);
- DynamicContainer.getParent().setExpanded(0);
- DynamicContainer.getParent().setExpanded(1);
- }
- }
- function GuiEditorCtrlProperties::setData(%this,%field, %val)
- {
- $currentTarget.setEditFieldValue(%field, %val);
- %this.update($currentTarget);
- }
- function GuiEditorCtrlProperties::buildEdit(%this,%field,%fieldType,%fieldVal)
- {
- // items yet to be added:
- // filename
- // RectI
- // assetIdString
- // audioAssetPtr
-
- %fieldEdit = %field @ "edit";
- echo(%field TAB %fieldType TAB %fieldVal);
-
- switch$(%fieldType)
- {
- case "float":
- %ctrl = new GuiTextEditCtrl(%fieldEdit)
- {
- Text = %fieldVal;
- Position = "160 0";
- extent = "160 30";
- horizSizing = "right";
- vertSizing = "bottom";
- visible = "1";
- Profile = "GuiTextEditProfile";
- };
- %ctrl.setFieldValue("AltCommand", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
- %ctrl.setFieldValue("Validate", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
- return %ctrl;
-
- case "ColorF":
- %ctrl = new GuiTextEditCtrl(%fieldEdit)
- {
- Text = %fieldVal;
- Position = "160 0";
- extent = "160 30";
- horizSizing = "right";
- vertSizing = "bottom";
- visible = "1";
- Profile = "GuiTextEditProfile";
- };
- %ctrl.setFieldValue("AltCommand", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
- %ctrl.setFieldValue("Validate", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
- return %ctrl;
-
- case "ColorI":
- %ctrl = new GuiTextEditCtrl(%fieldEdit)
- {
- Text = %fieldVal;
- Position = "160 0";
- extent = "160 30";
- horizSizing = "right";
- vertSizing = "bottom";
- visible = "1";
- Profile = "GuiTextEditProfile";
- };
- %ctrl.setFieldValue("AltCommand", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
- %ctrl.setFieldValue("Validate", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
- return %ctrl;
-
- case "SimObjectPtr":
- return %ctrl = new GuiControl(%fieldEdit)
- {
- Text = %fieldVal;
- Position = "160 0";
- extent = "160 30";
- horizSizing = "right";
- vertSizing = "bottom";
- visible = "1";
- Profile = "GuiTextProfile";
- };
-
- case "int":
- %ctrl = new GuiTextEditCtrl(%fieldEdit)
- {
- Text = %fieldVal;
- Position = "160 0";
- extent = "160 30";
- horizSizing = "right";
- vertSizing = "bottom";
- visible = "1";
- Profile = "GuiNumberEditProfile";
- };
- %ctrl.setFieldValue("AltCommand", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
- %ctrl.setFieldValue("Validate", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
- return %ctrl;
-
- case "bool":
- %ctrl = new GuiCheckBoxCtrl(%fieldEdit)
- {
- text = "";
- stateOn = %fieldVal;
- Position = "160 0";
- extent = "160 30";
- horizSizing = "relative";
- vertSizing = "relative";
- visible = "1";
- Profile = "GuiCheckBoxProfile";
- };
- %ctrl.setFieldValue("Command", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getStateOn());");
- return %ctrl;
-
- case "Point2I":
- return %this.buildPoint2ICtrl(%field,%fieldVal);
-
- case "Point2F":
- return %this.buildPoint2ICtrl(%field,%fieldVal);
-
- case "enumval":
- %ctrl = new GuiPopUpMenuCtrl(%fieldEdit)
- {
- text = %fieldVal;
- Position = "160 6";
- extent = "160 18";
- Profile="GuiPopUpMenuProfile2";
- HorizSizing="relative";
- VertSizing="relative";
- maxLength="1024";
- maxPopupHeight="200";
- bitmapBounds="16 16";
- };
- %cl = $currentTarget.getClassName();
- %ctrl.setEnumContent(%cl, %field);
- %ctrl.sort();
- %ctrl.setFieldValue("Command", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
- return %ctrl;
-
- case "GuiProfile":
- return %ctrl = %this.buildGuiProfileCtrl(%field, %fieldVal);
-
- default:
- // better lazy than complicated.
- %ctrl = new GuiTextEditCtrl(%fieldEdit)
- {
- Text = %fieldVal;
- Position = "160 0";
- extent = "160 30";
- horizSizing = "right";
- vertSizing = "bottom";
- visible = "1";
- Profile = "GuiTextEditProfile";
-
- };
- %ctrl.setFieldValue("AltCommand", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
- %ctrl.setFieldValue("Validate", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
- return %ctrl;
- }
-
- }
- function GuiEditorCtrlProperties::buildGuiProfileCtrl(%this,%field,%fieldVal)
- {
- %fieldEdit = %field @ "edit";
- %ctrl = new GuiPopUpMenuCtrl(%fieldEdit)
- {
- text = %fieldVal;
- Position = "160 6";
- extent = "160 18";
- Profile="GuiPopUpMenuProfile2";
- HorizSizing="relative";
- VertSizing="relative";
- maxLength="1024";
- maxPopupHeight="200";
- bitmapBounds="16 16";
- };
- %count = GuiDataGroup.getCount();
- for(%i = 0; %i < %count; %i++)
- {
- %obj = GuiDataGroup.getObject(%i);
- if(%obj.getClassName() $= "GuiControlProfile")
- {
- %cat = %obj.category;
- if(%cat !$= "")
- {
- echo(%cat);
- }
-
- if(%obj.getName() !$= "")
- {
- %ctrl.add(%obj.getName(), 0);
- }
- }
- }
- %ctrl.sort();
- %ctrl.setFieldValue("Command", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
- return %ctrl;
-
- }
- function GuiEditorCtrlProperties::buildPoint2ICtrl(%this,%field, %fieldVal)
- {
- %fieldEditX = %field @ "editX";
- %fieldEditY = %field @ "editY";
-
- %cont = new GuiControl()
- {
- extent = "160 30";
- Position = "160 0";
- horizSizing = "right";
- vertSizing = "bottom";
- profile = "GuiDefaultProfile";
- visible = "1";
- };
-
- %xLabel = new GuiControl()
- {
- text = "x:";
- extent = "30 30";
- Position = "0 0";
- horizSizing = "right";
- vertSizing = "bottom";
- profile = "GuiTextRightProfile";
- visible = "1";
- };
-
-
-
- %ctrlX = new GuiTextEditCtrl(%fieldEditX)
- {
- Text = %fieldVal.x;
- Position = "30 0";
- extent = "50 30";
- horizSizing = "right";
- vertSizing = "bottom";
- visible = "1";
- Profile = "GuiTextEditProfile";
- };
-
-
-
- %yLabel = new GuiControl()
- {
- text = "y:";
- extent = "30 30";
- Position = "80 0";
- horizSizing = "right";
- vertSizing = "bottom";
- profile = "GuiTextRightProfile";
- visible = "1";
- };
-
-
-
- %ctrlY = new GuiTextEditCtrl(%fieldEditY)
- {
- Text = %fieldVal.y;
- Position = "110 0";
- extent = "50 30";
- horizSizing = "right";
- vertSizing = "bottom";
- visible = "1";
- Profile = "GuiTextEditProfile";
- };
-
- %ctrlX.setFieldValue("AltCommand", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrlX.getId() @ ".getText() SPC " @ %ctrlY.getId() @ ".getText());");
- %ctrlX.setFieldValue("Validate", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrlX.getId() @ ".getText() SPC " @ %ctrlY.getId() @ ".getText());");
- %ctrlY.setFieldValue("AltCommand", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrlX.getId() @ ".getText() SPC " @ %ctrlY.getId() @ ".getText());");
- %ctrlY.setFieldValue("Validate", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrlX.getId() @ ".getText() SPC " @ %ctrlY.getId() @ ".getText());");
-
- %cont.add(%xLabel);
- %cont.add(%ctrlX);
- %cont.add(%yLabel);
- %cont.add(%ctrlY);
-
- return %cont;
-
- }
|