123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- //-----------------------------------------------------------------------------
- // 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 AssetDictionary::onAdd(%this)
- {
- %this.newButton = new GuiButtonCtrl()
- {
- class = "NewAssetButton";
- Position = "5 27";
- Extent = "300 30";
- HorizSizing = "width";
- VertSizing = "height";
- Text = "New";
- };
- ThemeManager.setProfile(%this.newButton, "buttonProfile");
- %this.add(%this.newButton);
- %this.grid = new GuiGridCtrl()
- {
- Position="0 62";
- Extent = "310 50";
- HorizSizing = "width";
- VertSizing = "height";
- CellSizeX = 60;
- CellSizeY = 60;
- CellModeX = variable;
- CellSpacingX = 4;
- CellSpacingY = 4;
- OrderMode = "LRTB";
- };
- ThemeManager.setProfile(%this.grid, "emptyProfile");
- %this.add(%this.grid);
- }
- function AssetDictionary::load(%this)
- {
- %query = new AssetQuery();
- AssetDatabase.findAllAssets(%query);
- AssetDatabase.findAssetType(%query, %this.Type, true);
- for(%i = 0; %i < %query.getCount(); %i++)
- {
- %assetID = %query.getAsset(%i);
- if(!AssetDatabase.isAssetInternal(%assetID))
- {
- %this.addButton(%assetID);
- }
- }
- %query.delete();
- %this.newButton.text = "New" SPC %this.type;
- %this.newButton.type = %this.type;
- }
- function AssetDictionary::addButton(%this, %assetID)
- {
- %button = new GuiButtonCtrl()
- {
- Class = AssetDictionaryButton;
- HorizSizing="center";
- VertSizing="center";
- Extent = "100 100";
- Tooltip = AssetDatabase.getAssetName(%assetID);
- Text = "";
- AssetID = %assetID;
- Type = %this.Type;
- };
- ThemeManager.setProfile(%button, "itemSelectProfile");
- ThemeManager.setProfile(%button, "tipProfile", "TooltipProfile");
- %this.grid.add(%button);
- %this.fixSize();
- return %button;
- }
- function AssetDictionary::removeButton(%this, %assetID)
- {
- %button = %this.getButton(%assetID);
- if(isObject(%button))
- {
- %button.delete();
- %this.fixSize();
- return true;
- }
- return false;
- }
- function AssetDictionary::fixSize(%this)
- {
- if(%this.getExpanded())
- {
- %this.setExpanded(false);
- %this.setExpanded(true);
- }
- }
- function AssetDictionary::getButton(%this, %assetID)
- {
- for(%i = 0; %i < %this.grid.getCount(); %i++)
- {
- %button = %this.grid.getObject(%i);
- if(%button.AssetID $= %assetID)
- {
- return %button;
- }
- }
- return 0;
- }
- function AssetDictionary::unload(%this)
- {
- //Remove all the child gui controls
- for(%i = %this.grid.getCount() - 1; %i >= 0; %i--)
- {
- %obj = %this.grid.getObject(%i);
- %obj.delete();
- }
- }
- function AssetDictionary::reload(%this)
- {
- %this.unload();
- %this.load();
- }
- function AssetDictionarySprite::onAnimationEnd(%this, %animationAssetID)
- {
- %this.schedule(2000, "restartAnimation", %animationAssetID);
- }
- function AssetDictionarySprite::restartAnimation(%this, %animationAssetID)
- {
- %this.setAnimation(%animationAssetID);
- }
|