| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- //-----------------------------------------------------------------------------
- // Copyright (c) 2013 GarageGames, LLC
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to
- // deal in the Software without restriction, including without limitation the
- // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- // sell copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- // IN THE SOFTWARE.
- //-----------------------------------------------------------------------------
- function GuiEditorToy::create( %this )
- {
- exec("./assets/gui/guiEditorCtrl.gui");
- exec("./assets/gui/guiToolbox.gui");
- exec("./assets/gui/ColorSelectorTool.gui");
- exec("./assets/scripts/GuiEditorCtrlProperties.cs");
- // Set the sandbox drag mode availability.
- Sandbox.allowManipulation( pan );
- Sandbox.allowManipulation( pull );
- // Set the manipulation mode.
- Sandbox.useManipulation( pull );
- SandboxScene.clear();
- //SandboxWindow.delete();
- GuiEditor.blankGui = new GuiControl();
- // Reset the toy initially.
- GuiEditorToy.reset();
- }
- //-----------------------------------------------------------------------------
- function GuiEditorToy::destroy( %this )
- {
- }
- //-----------------------------------------------------------------------------
- function GuiEditorToy::reset(%this)
- {
- // Clear the scene.
- Canvas.setContent(GuiEditorCtrl);
- GuiEditorContent.add(GuiEditor.blankGui);
- GuiEditorCtrl.add(GuiTreeViewWindow);
- $GuiRootElement = GuiBlank;
- %rootSize = $GuiRootElement.extent;
- GuiEditor.setRoot(GuiBlank);
- GuiEditorTreeView.open(GuiBlank);
- GuiEditor.setFirstResponder();
- GuiEditor.setSnapToGrid("8");
- GuiEditorCtrl.add(GuiToolbox);
- GuiEditorCtrl.add(GuiInspectorWindow);
- //GuiEditorCtrl.add(CBBWindow);
- }
- function GuiEditorToy::save(%this)
- {
- %guiObj = GuiEditorContent.getObject(0);
- if(%guiObj == -1)
- {
- return;
- }
- if(%guiObj.getName() !$= "")
- {
- %name = %guiObj.getName() @ ".gui";
- }
- else
- {
- %name = "untitled.gui";
- }
- %fo = new FileObject();
- %fo.openForWrite(%name);
- %fo.writeLine("//--- Created With GUIEDITORTOY ---//");
- %fo.writeObject(%guiObj, "%guiContent = ");
- %fo.writeLine("//--- GUIEDITORTOY END ---//");
- %fo.close();
- %fo.delete();
- }
- //-----------------------------------------------------------------------------
- function GuiToolbox::onWake(%this)
- {
- %controls = enumerateConsoleClasses("GuiControl");
- %this-->toolboxList.clearItems();
- for(%i = 0; %i < getFieldCount(%controls); %i++)
- {
- %field = getField(%controls, %i);
- %this-->toolboxList.addItem(%field);
- }
- }
- //-----------------------------------------------------------------------------
- function GuiEditorToolboxDrag::onTouchDragged(%this, %index, %text)
- {
- %position = %this.getGlobalPosition();
- %cursorpos = Canvas.getCursorPos();
- %class = %this.getItemText(%this.getSelectedItem());
- %payload = eval("return new " @ %class @ "();");
- if(!isObject(%payload))
- return;
- %xOffset = getWord(%payload.extent, 0) / 2;
- %yOffset = getWord(%payload.extent, 1) / 2;
- // position where the drag will start, to prevent visible jumping.
- %xPos = getWord(%cursorpos, 0) - %xOffset;
- %yPos = getWord(%cursorpos, 1) - %yOffset;
- %dragCtrl = new GuiDragAndDropCtrl() {
- canSaveDynamicFields = "0";
- Profile = "GuiDragAndDropProfile";
- HorizSizing = "right";
- VertSizing = "bottom";
- Position = %xPos SPC %yPos;
- extent = %payload.extent;
- MinExtent = "32 32";
- canSave = "1";
- Visible = "1";
- hovertime = "1000";
- Text = %text;
- deleteOnMouseUp = true;
- };
- %dragCtrl.add(%payload);
- Canvas.getContent().add(%dragCtrl);
- %dragCtrl.startDragging(%xOffset, %yOffset);
- }
- //-----------------------------------------------------------------------------
- function GuiEditor::onControlDragged(%this, %payload, %position)
- {
- %pos = VectorSub(%position, GuiEditorContent.getGlobalPosition());
- %x = getWord(%pos, 0);
- %y = getWord(%pos, 1);
- %target = GuiEditorContent.findHitControl(%x, %y);
- while(! %target.isContainer )
- {
- %target = %target.getParent();
- }
- if(%target != %this.getCurrentAddset())
- {
- %this.setCurrentAddSet(%target);
- }
- GuiEditorCtrlProperties.update(%ctrl);
- }
- //-----------------------------------------------------------------------------
- function GuiEditor::onControlDropped(%this, %payload, %position)
- {
- %pos = %payload.getGlobalPosition();
- %x = getWord(%pos, 0);
- %y = getWord(%pos, 1);
- if(%x > $GuiRootElement.extent.x || %y > $GuiRootElement.extent.y)
- {
- messageBox("Error", "Cannot add a control outside the root gui element!");
- return;
- }
- %this.addNewCtrl(%payload);
- %payload.setPositionGlobal(%x, %y);
- %this.setFirstResponder();
- }
- //-----------------------------------------------------------------------------
- function GuiEditor::onSelect(%this, %ctrl)
- {
- GuiEditorCtrlProperties.update(%ctrl);
- GuiEditor.clearSelection();
- GuiEditor.select(%ctrl);
- GuiEditorTreeView.addSelection(%ctrl);
- }
- function GuiEditor::onSelectionMoved(%this, %ctrl)
- {
- GuiEditorCtrlProperties.update(%ctrl);
- }
- function GuiEditor::onClearSelected(%this)
- {
- GuiEditorTreeView.clearSelection();
- }
- function GuiEditor::onSelectionParentChange(%this)
- {
- GuiEditorTreeView.update();
- }
- function GuiEditor::onDelete(%this)
- {
- GuiEditorTreeView.update();
- GuiEditorCtrlProperties.update(0);
- }
- function GuiEditor::onAddSelected(%this,%ctrl)
- {
- GuiEditorTreeView.addSelection(%ctrl);
- GuiEditorTreeView.scrollVisibleByObjectId(%ctrl);
- }
- function GuiEditor::onRemoveSelected(%this,%ctrl)
- {
- GuiEditorTreeView.removeSelection(%ctrl);
- }
- //-----------------------------------------------------------------------------
- function GuiEditorTreeView::update(%this)
- {
- %obj = GuiEditorContent.getObject(0);
- if(!isObject(%obj))
- {
- GuiEditorTreeView.clear();
- }
- else
- {
- GuiEditorTreeView.open(GuiEditorContent.getObject(0));
- }
- }
- function GuiEditorTreeView::onRightMouseDown(%this, %item, %pts, %obj)
- {
- if(%obj)
- {
- GuiEditor.setCurrentAddSet(%obj);
- }
- }
- function GuiEditorTreeView::onAddSelection(%this, %ctrl)
- {
- GuiEditor.setFirstResponder();
- }
- function GuiEditorTreeView::onRemoveSelection(%this, %ctrl)
- {
- GuiEditor.removeSelection(%ctrl);
- }
- function GuiEditorTreeView::onDeleteSelection(%this)
- {
- GuiEditor.clearSelection();
- }
- function GuiEditorTreeView::onSelect(%this, %obj)
- {
- if(isObject(%obj))
- {
- GuiEditorCtrlProperties.update(%obj);
- GuiEditor.select(%obj);
- }
- }
|