property_editor.cpp 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014
  1. /*************************************************************************/
  2. /* property_editor.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "property_editor.h"
  30. #include "scene/gui/label.h"
  31. #include "io/resource_loader.h"
  32. #include "io/image_loader.h"
  33. #include "object_type_db.h"
  34. #include "print_string.h"
  35. #include "globals.h"
  36. #include "scene/resources/font.h"
  37. #include "pair.h"
  38. #include "scene/scene_string_names.h"
  39. #include "editor_settings.h"
  40. #include "editor_import_export.h"
  41. void CustomPropertyEditor::_notification(int p_what) {
  42. if (p_what==NOTIFICATION_DRAW) {
  43. RID ci = get_canvas_item();
  44. get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size()));
  45. /*
  46. if (v.get_type()==Variant::COLOR) {
  47. VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2( 10,10,60, get_size().height-20 ), v );
  48. }*/
  49. }
  50. }
  51. void CustomPropertyEditor::_menu_option(int p_which) {
  52. switch(type) {
  53. case Variant::INT: {
  54. if (hint==PROPERTY_HINT_FLAGS) {
  55. int val = v;
  56. if (val&(1<<p_which)) {
  57. val&=~(1<<p_which);
  58. } else {
  59. val|=(1<<p_which);
  60. }
  61. v=val;
  62. emit_signal("variant_changed");
  63. }
  64. } break;
  65. case Variant::OBJECT: {
  66. switch(p_which) {
  67. case OBJ_MENU_LOAD: {
  68. file->set_mode(FileDialog::MODE_OPEN_FILE);
  69. List<String> extensions;
  70. String type=(hint==PROPERTY_HINT_RESOURCE_TYPE)?hint_text:String();
  71. ResourceLoader::get_recognized_extensions_for_type(type,&extensions);
  72. file->clear_filters();
  73. for (List<String>::Element *E=extensions.front();E;E=E->next()) {
  74. file->add_filter("*."+E->get()+" ; "+E->get().to_upper() );
  75. }
  76. file->popup_centered_ratio();
  77. } break;
  78. case OBJ_MENU_EDIT: {
  79. RefPtr RefPtr=v;
  80. if (!RefPtr.is_null()) {
  81. emit_signal("resource_edit_request");
  82. hide();
  83. }
  84. } break;
  85. case OBJ_MENU_CLEAR: {
  86. v=Variant();
  87. emit_signal("variant_changed");
  88. hide();
  89. } break;
  90. case OBJ_MENU_MAKE_UNIQUE: {
  91. RefPtr RefPtr=v;
  92. Ref<Resource> res_orig = RefPtr;
  93. if (res_orig.is_null())
  94. return;
  95. List<PropertyInfo> property_list;
  96. res_orig->get_property_list(&property_list);
  97. List< Pair<String,Variant> > propvalues;
  98. for(List<PropertyInfo>::Element *E=property_list.front();E;E=E->next()) {
  99. Pair<String,Variant> p;
  100. PropertyInfo &pi = E->get();
  101. if (pi.usage&PROPERTY_USAGE_STORAGE) {
  102. p.first=pi.name;
  103. p.second=res_orig->get(pi.name);
  104. }
  105. propvalues.push_back(p);
  106. }
  107. String orig_type = res_orig->get_type();
  108. print_line("orig type: "+orig_type);
  109. Object *inst = ObjectTypeDB::instance( orig_type );
  110. Ref<Resource> res = Ref<Resource>( inst->cast_to<Resource>() );
  111. ERR_FAIL_COND(res.is_null());
  112. for(List< Pair<String,Variant> >::Element *E=propvalues.front();E;E=E->next()) {
  113. Pair<String,Variant> &p=E->get();
  114. res->set(p.first,p.second);
  115. }
  116. v=res.get_ref_ptr();
  117. emit_signal("variant_changed");
  118. hide();
  119. } break;
  120. case OBJ_MENU_COPY: {
  121. EditorSettings::get_singleton()->set_resource_clipboard(v);
  122. } break;
  123. case OBJ_MENU_PASTE: {
  124. v=EditorSettings::get_singleton()->get_resource_clipboard();
  125. emit_signal("variant_changed");
  126. } break;
  127. case OBJ_MENU_REIMPORT: {
  128. RES r=v;
  129. if (r.is_valid() && r->get_import_metadata().is_valid()) {
  130. Ref<ResourceImportMetadata> rimd = r->get_import_metadata();
  131. Ref<EditorImportPlugin> eip = EditorImportExport::get_singleton()->get_import_plugin_by_name(rimd->get_editor());
  132. if (eip.is_valid()) {
  133. eip->import_dialog(r->get_path());
  134. }
  135. }
  136. } break;
  137. default: {
  138. ERR_FAIL_COND( inheritors_array.empty() );
  139. String intype=inheritors_array[p_which-TYPE_BASE_ID];
  140. Object *obj = ObjectTypeDB::instance(intype);
  141. ERR_BREAK( !obj );
  142. Resource *res=obj->cast_to<Resource>();
  143. ERR_BREAK( !res );
  144. v=Ref<Resource>(res).get_ref_ptr();
  145. emit_signal("variant_changed");
  146. } break;
  147. }
  148. } break;
  149. default:{}
  150. }
  151. }
  152. Variant CustomPropertyEditor::get_variant() const {
  153. return v;
  154. }
  155. String CustomPropertyEditor::get_name() const {
  156. return name;
  157. }
  158. bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Type p_type, const Variant& p_variant,int p_hint,String p_hint_text) {
  159. owner=p_owner;
  160. updating=true;
  161. name=p_name;
  162. v=p_variant;
  163. hint=p_hint;
  164. hint_text=p_hint_text;
  165. type_button->hide();
  166. color_picker->hide();
  167. texture_preview->hide();
  168. inheritors_array.clear();
  169. text_edit->hide();
  170. easing_draw->hide();
  171. for (int i=0;i<MAX_VALUE_EDITORS;i++) {
  172. value_editor[i]->hide();
  173. value_label[i]->hide();
  174. if (i<4)
  175. scroll[i]->hide();
  176. }
  177. for (int i=0;i<MAX_ACTION_BUTTONS;i++) {
  178. action_buttons[i]->hide();
  179. }
  180. for(int i=0;i<20;i++)
  181. checks20[i]->hide();
  182. type = (p_variant.get_type()!=Variant::NIL && p_variant.get_type()!=Variant::_RID && p_type!=Variant::OBJECT)? p_variant.get_type() : p_type;
  183. switch(type) {
  184. case Variant::INT:
  185. case Variant::REAL: {
  186. if (hint==PROPERTY_HINT_ALL_FLAGS) {
  187. uint32_t flgs = v;
  188. for(int i=0;i<2;i++) {
  189. Point2 ofs(4,4);
  190. ofs.y+=22*i;
  191. for(int j=0;j<10;j++) {
  192. Button *c=checks20[i*10+j];
  193. Point2 o=ofs;
  194. o.x+=j*22;
  195. if (j>=5)
  196. o.x+=4;
  197. c->set_pos(o);
  198. c->set_pressed( flgs & (1<<(i*10+j)) );
  199. c->show();
  200. }
  201. }
  202. set_size(checks20[19]->get_pos()+Size2(20,25));
  203. } else if (hint==PROPERTY_HINT_EXP_EASING) {
  204. easing_draw->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN,5);
  205. easing_draw->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,5);
  206. easing_draw->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN,5);
  207. easing_draw->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,30);
  208. type_button->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN,3);
  209. type_button->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,3);
  210. type_button->set_anchor_and_margin(MARGIN_TOP,ANCHOR_END,25);
  211. type_button->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,7);
  212. type_button->set_text("Preset..");
  213. type_button->get_popup()->clear();
  214. type_button->get_popup()->add_item("Linear",EASING_LINEAR);
  215. type_button->get_popup()->add_item("Ease In",EASING_EASE_IN);
  216. type_button->get_popup()->add_item("Ease Out",EASING_EASE_OUT);
  217. if (hint_text!="attenuation") {
  218. type_button->get_popup()->add_item("Zero",EASING_ZERO);
  219. type_button->get_popup()->add_item("Easing In-Out",EASING_IN_OUT);
  220. type_button->get_popup()->add_item("Easing Out-In",EASING_OUT_IN);
  221. }
  222. type_button->show();
  223. easing_draw->show();
  224. set_size(Size2(200,150));
  225. } else if (hint==PROPERTY_HINT_FLAGS) {
  226. menu->clear();
  227. Vector<String> flags = hint_text.split(",");
  228. for(int i=0;i<flags.size();i++) {
  229. String flag = flags[i];
  230. if (flag=="")
  231. continue;
  232. menu->add_check_item(flag,i);
  233. int f = v;
  234. if (f&(1<<i))
  235. menu->set_item_checked(menu->get_item_index(i),true);
  236. }
  237. menu->set_pos(get_pos());
  238. menu->popup();
  239. hide();
  240. updating=false;
  241. return false;
  242. } else {
  243. List<String> names;
  244. names.push_back("value:");
  245. config_value_editors(1,1,50,names);
  246. Vector3 vec=v;
  247. value_editor[0]->set_text( String::num(v) );
  248. }
  249. } break;
  250. case Variant::STRING: {
  251. if (hint==PROPERTY_HINT_FILE || hint==PROPERTY_HINT_GLOBAL_FILE) {
  252. List<String> names;
  253. names.push_back("File..");
  254. names.push_back("Clear");
  255. config_action_buttons(names);
  256. } else if (hint==PROPERTY_HINT_DIR || hint==PROPERTY_HINT_GLOBAL_DIR) {
  257. List<String> names;
  258. names.push_back("Dir..");
  259. names.push_back("Clear");
  260. config_action_buttons(names);
  261. } else if (hint==PROPERTY_HINT_ENUM) {
  262. } else if (hint==PROPERTY_HINT_MULTILINE_TEXT) {
  263. text_edit->show();
  264. text_edit->set_text(v);
  265. //action_buttons[0];
  266. int button_margin = get_constant("button_margin","Dialogs");
  267. int margin = get_constant("margin","Dialogs");
  268. action_buttons[0]->set_anchor( MARGIN_LEFT, ANCHOR_END );
  269. action_buttons[0]->set_anchor( MARGIN_TOP, ANCHOR_END );
  270. action_buttons[0]->set_anchor( MARGIN_RIGHT, ANCHOR_END );
  271. action_buttons[0]->set_anchor( MARGIN_BOTTOM, ANCHOR_END );
  272. action_buttons[0]->set_begin( Point2( 70, button_margin-5 ) );
  273. action_buttons[0]->set_end( Point2( margin, margin ) );
  274. action_buttons[0]->set_text("Close");
  275. action_buttons[0]->show();
  276. } else {
  277. List<String> names;
  278. names.push_back("string:");
  279. config_value_editors(1,1,50,names);
  280. Vector3 vec=v;
  281. value_editor[0]->set_text( v );
  282. }
  283. } break;
  284. case Variant::VECTOR2: {
  285. List<String> names;
  286. names.push_back("x");
  287. names.push_back("y");
  288. config_value_editors(2,2,10,names);
  289. Vector2 vec=v;
  290. value_editor[0]->set_text( String::num( vec.x) );
  291. value_editor[1]->set_text( String::num( vec.y) );
  292. } break;
  293. case Variant::RECT2: {
  294. List<String> names;
  295. names.push_back("x");
  296. names.push_back("y");
  297. names.push_back("w");
  298. names.push_back("h");
  299. config_value_editors(4,4,10,names);
  300. Rect2 r=v;
  301. value_editor[0]->set_text( String::num( r.pos.x) );
  302. value_editor[1]->set_text( String::num( r.pos.y) );
  303. value_editor[2]->set_text( String::num( r.size.x) );
  304. value_editor[3]->set_text( String::num( r.size.y) );
  305. } break;
  306. case Variant::VECTOR3: {
  307. List<String> names;
  308. names.push_back("x");
  309. names.push_back("y");
  310. names.push_back("z");
  311. config_value_editors(3,3,10,names);
  312. Vector3 vec=v;
  313. value_editor[0]->set_text( String::num( vec.x) );
  314. value_editor[1]->set_text( String::num( vec.y) );
  315. value_editor[2]->set_text( String::num( vec.z) );
  316. } break;
  317. case Variant::PLANE: {
  318. List<String> names;
  319. names.push_back("x");
  320. names.push_back("y");
  321. names.push_back("z");
  322. names.push_back("d");
  323. config_value_editors(4,4,10,names);
  324. Plane plane=v;
  325. value_editor[0]->set_text( String::num( plane.normal.x ) );
  326. value_editor[1]->set_text( String::num( plane.normal.y ) );
  327. value_editor[2]->set_text( String::num( plane.normal.z ) );
  328. value_editor[3]->set_text( String::num( plane.d ) );
  329. } break;
  330. case Variant::QUAT: {
  331. List<String> names;
  332. names.push_back("x");
  333. names.push_back("y");
  334. names.push_back("z");
  335. names.push_back("w");
  336. config_value_editors(4,4,10,names);
  337. Quat q=v;
  338. value_editor[0]->set_text( String::num( q.x ) );
  339. value_editor[1]->set_text( String::num( q.y ) );
  340. value_editor[2]->set_text( String::num( q.z ) );
  341. value_editor[3]->set_text( String::num( q.w ) );
  342. } break;
  343. case Variant::_AABB: {
  344. List<String> names;
  345. names.push_back("px");
  346. names.push_back("py");
  347. names.push_back("pz");
  348. names.push_back("sx");
  349. names.push_back("sy");
  350. names.push_back("sz");
  351. config_value_editors(6,3,16,names);
  352. AABB aabb=v;
  353. value_editor[0]->set_text( String::num( aabb.pos.x ) );
  354. value_editor[1]->set_text( String::num( aabb.pos.y ) );
  355. value_editor[2]->set_text( String::num( aabb.pos.z ) );
  356. value_editor[3]->set_text( String::num( aabb.size.x ) );
  357. value_editor[4]->set_text( String::num( aabb.size.y ) );
  358. value_editor[5]->set_text( String::num( aabb.size.z ) );
  359. } break;
  360. case Variant::MATRIX32: {
  361. List<String> names;
  362. names.push_back("xx");
  363. names.push_back("xy");
  364. names.push_back("yx");
  365. names.push_back("yy");
  366. names.push_back("ox");
  367. names.push_back("oy");
  368. config_value_editors(6,2,16,names);
  369. Matrix32 basis=v;
  370. for(int i=0;i<6;i++) {
  371. value_editor[i]->set_text( String::num( basis.elements[i/2][i%2] ) );
  372. }
  373. } break;
  374. case Variant::MATRIX3: {
  375. List<String> names;
  376. names.push_back("xx");
  377. names.push_back("xy");
  378. names.push_back("xz");
  379. names.push_back("yx");
  380. names.push_back("yy");
  381. names.push_back("yz");
  382. names.push_back("zx");
  383. names.push_back("zy");
  384. names.push_back("zz");
  385. config_value_editors(9,3,16,names);
  386. Matrix3 basis=v;
  387. for(int i=0;i<9;i++) {
  388. value_editor[i]->set_text( String::num( basis.elements[i/3][i%3] ) );
  389. }
  390. } break;
  391. case Variant::TRANSFORM: {
  392. List<String> names;
  393. names.push_back("xx");
  394. names.push_back("xy");
  395. names.push_back("xz");
  396. names.push_back("xo");
  397. names.push_back("yx");
  398. names.push_back("yy");
  399. names.push_back("yz");
  400. names.push_back("yo");
  401. names.push_back("zx");
  402. names.push_back("zy");
  403. names.push_back("zz");
  404. names.push_back("zo");
  405. config_value_editors(12,4,16,names);
  406. Transform tr=v;
  407. for(int i=0;i<9;i++) {
  408. value_editor[(i/3)*4+i%3]->set_text( String::num( tr.basis.elements[i/3][i%3] ) );
  409. }
  410. value_editor[3]->set_text( String::num( tr.origin.x ) );
  411. value_editor[7]->set_text( String::num( tr.origin.y ) );
  412. value_editor[11]->set_text( String::num( tr.origin.z ) );
  413. } break;
  414. case Variant::COLOR: {
  415. color_picker->show();
  416. color_picker->set_edit_alpha(hint!=PROPERTY_HINT_COLOR_NO_ALPHA);
  417. color_picker->set_color(v);
  418. set_size( Size2(350, color_picker->get_combined_minimum_size().height+10));
  419. /*
  420. int ofs=80;
  421. int m=10;
  422. int h=20;
  423. Color c=v;
  424. float values[4]={c.r,c.g,c.b,c.a};
  425. for (int i=0;i<4;i++) {
  426. int y=m+i*h;
  427. value_editor[i]->show();
  428. value_label[i]->show();
  429. value_label[i]->set_pos(Point2(ofs,y));
  430. scroll[i]->set_min(0);
  431. scroll[i]->set_max(1.0);
  432. scroll[i]->set_page(0);
  433. scroll[i]->set_pos(Point2(ofs+15,y+Math::floor((h-scroll[i]->get_minimum_size().height)/2.0)));
  434. scroll[i]->set_val(values[i]);
  435. scroll[i]->set_size(Size2(120,1));
  436. scroll[i]->show();
  437. value_editor[i]->set_pos(Point2(ofs+140,y));
  438. value_editor[i]->set_size(Size2(40,h));
  439. value_editor[i]->set_text( String::num(values[i],2 ));
  440. }
  441. value_label[0]->set_text("R");
  442. value_label[1]->set_text("G");
  443. value_label[2]->set_text("B");
  444. value_label[3]->set_text("A");
  445. Size2 new_size = value_editor[3]->get_pos() + value_editor[3]->get_size() + Point2(10,10);
  446. set_size( new_size );
  447. */
  448. } break;
  449. case Variant::IMAGE: {
  450. List<String> names;
  451. names.push_back("New");
  452. names.push_back("Load");
  453. names.push_back("Clear");
  454. config_action_buttons(names);
  455. } break;
  456. case Variant::NODE_PATH: {
  457. List<String> names;
  458. names.push_back("Assign");
  459. names.push_back("Clear");
  460. config_action_buttons(names);
  461. } break;
  462. case Variant::OBJECT: {
  463. if (hint!=PROPERTY_HINT_RESOURCE_TYPE)
  464. break;
  465. menu->clear();
  466. menu->set_size(Size2(1,1));
  467. if (hint_text!="") {
  468. for(int i=0;i<hint_text.get_slice_count(",");i++) {
  469. String base=hint_text.get_slice(",",i);
  470. Set<String> valid_inheritors;
  471. valid_inheritors.insert(base);
  472. List<String> inheritors;
  473. ObjectTypeDB::get_inheriters_from(base.strip_edges(),&inheritors);
  474. List<String>::Element *E=inheritors.front();
  475. while(E) {
  476. valid_inheritors.insert(E->get());
  477. E=E->next();
  478. }
  479. int idx=0;
  480. for(Set<String>::Element *E=valid_inheritors.front();E;E=E->next()) {
  481. String t = E->get();
  482. if (!ObjectTypeDB::can_instance(t))
  483. continue;
  484. inheritors_array.push_back(t);
  485. if (has_icon(t,"EditorIcons")) {
  486. menu->add_icon_item(get_icon(t,"EditorIcons"),"New "+t,TYPE_BASE_ID+idx);
  487. } else {
  488. menu->add_item("New "+t,TYPE_BASE_ID+idx);
  489. }
  490. idx++;
  491. }
  492. }
  493. if (menu->get_item_count())
  494. menu->add_separator();
  495. }
  496. menu->add_icon_item(get_icon("Load","EditorIcons"),"Load",OBJ_MENU_LOAD);
  497. if (!RES(v).is_null()) {
  498. menu->add_icon_item(get_icon("EditResource","EditorIcons"),"Edit",OBJ_MENU_EDIT);
  499. menu->add_icon_item(get_icon("Del","EditorIcons"),"Clear",OBJ_MENU_CLEAR);
  500. menu->add_icon_item(get_icon("Duplicate","EditorIcons"),"Make Unique",OBJ_MENU_MAKE_UNIQUE);
  501. RES r = v;
  502. if (r.is_valid() && r->get_path().is_resource_file() && r->get_import_metadata().is_valid()) {
  503. menu->add_separator();
  504. menu->add_icon_item(get_icon("Reload","EditorIcons"),"Re-Import",OBJ_MENU_REIMPORT);
  505. }
  506. }
  507. RES cb=EditorSettings::get_singleton()->get_resource_clipboard();
  508. bool paste_valid=cb.is_valid() && (hint_text=="" || ObjectTypeDB::is_type(cb->get_type(),hint_text));
  509. if (!RES(v).is_null() || paste_valid) {
  510. menu->add_separator();
  511. if (!RES(v).is_null()) {
  512. menu->add_item("Copy",OBJ_MENU_COPY);
  513. }
  514. if (paste_valid) {
  515. menu->add_item("Paste",OBJ_MENU_PASTE);
  516. }
  517. }
  518. menu->set_pos(get_pos());
  519. menu->popup();
  520. hide();
  521. updating=false;
  522. return false;
  523. } break;
  524. case Variant::INPUT_EVENT: {
  525. } break;
  526. case Variant::DICTIONARY: {
  527. } break;
  528. case Variant::RAW_ARRAY: {
  529. } break;
  530. case Variant::INT_ARRAY: {
  531. } break;
  532. case Variant::REAL_ARRAY: {
  533. } break;
  534. case Variant::STRING_ARRAY: {
  535. } break;
  536. case Variant::VECTOR3_ARRAY: {
  537. } break;
  538. case Variant::COLOR_ARRAY: {
  539. } break;
  540. default: {}
  541. }
  542. updating=false;
  543. return true;
  544. }
  545. void CustomPropertyEditor::_file_selected(String p_file) {
  546. switch(type) {
  547. case Variant::STRING: {
  548. if (hint==PROPERTY_HINT_FILE || hint==PROPERTY_HINT_DIR) {
  549. v=Globals::get_singleton()->localize_path(p_file);
  550. emit_signal("variant_changed");
  551. hide();
  552. }
  553. if (hint==PROPERTY_HINT_GLOBAL_FILE || hint==PROPERTY_HINT_GLOBAL_DIR) {
  554. v=p_file;
  555. emit_signal("variant_changed");
  556. hide();
  557. }
  558. } break;
  559. case Variant::OBJECT: {
  560. String type=(hint==PROPERTY_HINT_RESOURCE_TYPE)?hint_text:String();
  561. RES res = ResourceLoader::load(p_file,type);
  562. if (res.is_null()) {
  563. error->set_text("Error loading file: Not a resource!");
  564. error->popup_centered(Size2(300,80));
  565. break;
  566. }
  567. v=res.get_ref_ptr();
  568. emit_signal("variant_changed");
  569. hide();
  570. } break;
  571. case Variant::IMAGE: {
  572. Image image;
  573. Error err = ImageLoader::load_image(p_file,&image);
  574. ERR_EXPLAIN("Couldn't load image");
  575. ERR_FAIL_COND(err);
  576. v=image;
  577. emit_signal("variant_changed");
  578. hide();
  579. } break;
  580. default: {}
  581. }
  582. }
  583. void CustomPropertyEditor::_type_create_selected(int p_idx) {
  584. if (type==Variant::INT || type==Variant::REAL) {
  585. float newval=0;
  586. switch(p_idx) {
  587. case EASING_LINEAR: {
  588. newval=1;
  589. } break;
  590. case EASING_EASE_IN: {
  591. newval=2.0;
  592. } break;
  593. case EASING_EASE_OUT: {
  594. newval=0.5;
  595. } break;
  596. case EASING_ZERO: {
  597. newval=0;
  598. } break;
  599. case EASING_IN_OUT: {
  600. newval=-0.5;
  601. } break;
  602. case EASING_OUT_IN: {
  603. newval=-2.0;
  604. } break;
  605. }
  606. v=newval;
  607. emit_signal("variant_changed");
  608. easing_draw->update();
  609. } else if (type==Variant::OBJECT) {
  610. ERR_FAIL_INDEX(p_idx,inheritors_array.size());
  611. //List<String> inheritors;
  612. //ObjectTypeDB::get_inheriters_from(hint_text,&inheritors);
  613. //inheritors.push_front(hint_text);
  614. //ERR_FAIL_INDEX( p_idx, inheritors.size() );
  615. String intype=inheritors_array[p_idx];
  616. Object *obj = ObjectTypeDB::instance(intype);
  617. ERR_FAIL_COND( !obj );
  618. Resource *res=obj->cast_to<Resource>();
  619. ERR_FAIL_COND( !res );
  620. v=Ref<Resource>(res).get_ref_ptr();
  621. emit_signal("variant_changed");
  622. hide();
  623. }
  624. }
  625. void CustomPropertyEditor::_color_changed(const Color& p_color) {
  626. v=p_color;
  627. emit_signal("variant_changed");
  628. }
  629. void CustomPropertyEditor::_node_path_selected(NodePath p_path) {
  630. if (owner && owner->is_type("Node")) {
  631. Node *node = owner->cast_to<Node>();
  632. Node *tonode=node->get_node(p_path);
  633. if (tonode) {
  634. p_path=node->get_path_to(tonode);
  635. }
  636. }
  637. v=p_path;
  638. emit_signal("variant_changed");
  639. }
  640. void CustomPropertyEditor::_action_pressed(int p_which) {
  641. if (updating)
  642. return;
  643. switch(type) {
  644. case Variant::INT: {
  645. if (hint==PROPERTY_HINT_ALL_FLAGS) {
  646. uint32_t f = v;
  647. if (checks20[p_which]->is_pressed())
  648. f|=(1<<p_which);
  649. else
  650. f&=~(1<<p_which);
  651. v=f;
  652. emit_signal("variant_changed");
  653. }
  654. } break;
  655. case Variant::STRING: {
  656. if (hint==PROPERTY_HINT_MULTILINE_TEXT) {
  657. hide();
  658. } else if (hint==PROPERTY_HINT_FILE || hint==PROPERTY_HINT_GLOBAL_FILE) {
  659. if (p_which==0) {
  660. if (hint==PROPERTY_HINT_FILE)
  661. file->set_access(FileDialog::ACCESS_RESOURCES);
  662. else
  663. file->set_access(FileDialog::ACCESS_FILESYSTEM);
  664. file->set_mode(FileDialog::MODE_OPEN_FILE);
  665. file->clear_filters();
  666. file->clear_filters();
  667. if (hint_text!="") {
  668. Vector<String> extensions=hint_text.split(",");
  669. for(int i=0;i<extensions.size();i++) {
  670. String filter = extensions[i];
  671. if (filter.begins_with("."))
  672. filter="*"+extensions[i];
  673. else if (!filter.begins_with("*"))
  674. filter="*."+extensions[i];
  675. file->add_filter(filter+" ; "+extensions[i].to_upper() );
  676. }
  677. }
  678. file->popup_centered_ratio();
  679. } else {
  680. v="";
  681. emit_signal("variant_changed");
  682. hide();
  683. }
  684. } else if (hint==PROPERTY_HINT_DIR || hint==PROPERTY_HINT_GLOBAL_DIR) {
  685. if (p_which==0) {
  686. if (hint==PROPERTY_HINT_DIR)
  687. file->set_access(FileDialog::ACCESS_RESOURCES);
  688. else
  689. file->set_access(FileDialog::ACCESS_FILESYSTEM);
  690. file->set_mode(FileDialog::MODE_OPEN_DIR);
  691. file->clear_filters();
  692. file->popup_centered_ratio();
  693. } else {
  694. v="";
  695. emit_signal("variant_changed");
  696. hide();
  697. }
  698. }
  699. } break;
  700. case Variant::NODE_PATH: {
  701. if (p_which==0) {
  702. scene_tree->popup_centered_ratio();
  703. } else if (p_which==1) {
  704. v=NodePath();
  705. emit_signal("variant_changed");
  706. }
  707. } break;
  708. case Variant::OBJECT: {
  709. if (p_which==0) {
  710. ERR_FAIL_COND( inheritors_array.empty() );
  711. String intype=inheritors_array[0];
  712. if (hint==PROPERTY_HINT_RESOURCE_TYPE) {
  713. Object *obj = ObjectTypeDB::instance(intype);
  714. ERR_BREAK( !obj );
  715. Resource *res=obj->cast_to<Resource>();
  716. ERR_BREAK( !res );
  717. v=Ref<Resource>(res).get_ref_ptr();
  718. emit_signal("variant_changed");
  719. hide();
  720. }
  721. } else if (p_which==1) {
  722. file->set_access(FileDialog::ACCESS_RESOURCES);
  723. file->set_mode(FileDialog::MODE_OPEN_FILE);
  724. List<String> extensions;
  725. String type=(hint==PROPERTY_HINT_RESOURCE_TYPE)?hint_text:String();
  726. ResourceLoader::get_recognized_extensions_for_type(type,&extensions);
  727. file->clear_filters();
  728. for (List<String>::Element *E=extensions.front();E;E=E->next()) {
  729. file->add_filter("*."+E->get()+" ; "+E->get().to_upper() );
  730. }
  731. file->popup_centered_ratio();
  732. } else if (p_which==2) {
  733. RefPtr RefPtr=v;
  734. if (!RefPtr.is_null()) {
  735. emit_signal("resource_edit_request");
  736. hide();
  737. }
  738. } else if (p_which==3) {
  739. v=Variant();
  740. emit_signal("variant_changed");
  741. hide();
  742. } else if (p_which==4) {
  743. RefPtr RefPtr=v;
  744. Ref<Resource> res_orig = RefPtr;
  745. if (res_orig.is_null())
  746. return;
  747. List<PropertyInfo> property_list;
  748. res_orig->get_property_list(&property_list);
  749. List< Pair<String,Variant> > propvalues;
  750. for(List<PropertyInfo>::Element *E=property_list.front();E;E=E->next()) {
  751. Pair<String,Variant> p;
  752. PropertyInfo &pi = E->get();
  753. if (pi.usage&PROPERTY_USAGE_STORAGE) {
  754. p.first=pi.name;
  755. p.second=res_orig->get(pi.name);
  756. }
  757. propvalues.push_back(p);
  758. }
  759. Ref<Resource> res = Ref<Resource>( ObjectTypeDB::instance( res_orig->get_type() ));
  760. ERR_FAIL_COND(res.is_null());
  761. for(List< Pair<String,Variant> >::Element *E=propvalues.front();E;E=E->next()) {
  762. Pair<String,Variant> &p=E->get();
  763. res->set(p.first,p.second);
  764. }
  765. v=res.get_ref_ptr();
  766. emit_signal("variant_changed");
  767. hide();
  768. }
  769. } break;
  770. case Variant::IMAGE: {
  771. if (p_which==0) {
  772. //new image too difficult
  773. ERR_PRINT("New Image Unimplemented");
  774. } else if (p_which==1) {
  775. file->set_access(FileDialog::ACCESS_RESOURCES);
  776. file->set_mode(FileDialog::MODE_OPEN_FILE);
  777. List<String> extensions;
  778. ImageLoader::get_recognized_extensions(&extensions);
  779. file->clear_filters();
  780. for (List<String>::Element *E=extensions.front();E;E=E->next()) {
  781. file->add_filter("*."+E->get()+" ; "+E->get().to_upper() );
  782. }
  783. file->popup_centered_ratio();
  784. } else if (p_which==2) {
  785. v=Image();
  786. emit_signal("variant_changed");
  787. hide();
  788. }
  789. } break;
  790. default: {};
  791. }
  792. }
  793. void CustomPropertyEditor::_scroll_modified(double p_value) {
  794. if (updating)
  795. return;
  796. /*
  797. switch(type) {
  798. case Variant::COLOR: {
  799. for (int i=0;i<4;i++) {
  800. value_editor[i]->set_text( String::num(scroll[i]->get_val(),2) );
  801. }
  802. Color c;
  803. c.r=scroll[0]->get_val();
  804. c.g=scroll[1]->get_val();
  805. c.b=scroll[2]->get_val();
  806. c.a=scroll[3]->get_val();
  807. v=c;
  808. update();
  809. emit_signal("variant_changed");
  810. } break;
  811. default: {}
  812. }
  813. */
  814. }
  815. void CustomPropertyEditor::_drag_easing(const InputEvent& p_ev) {
  816. if (p_ev.type==InputEvent::MOUSE_MOTION && p_ev.mouse_motion.button_mask&BUTTON_MASK_LEFT) {
  817. float rel = p_ev.mouse_motion.relative_x;
  818. if (rel==0)
  819. return;
  820. bool flip=hint_text=="attenuation";
  821. if (flip)
  822. rel=-rel;
  823. float val = v;
  824. if (val==0)
  825. return;
  826. bool sg = val < 0;
  827. val = Math::absf(val);
  828. val = Math::log(val)/Math::log(2);
  829. //logspace
  830. val+=rel*0.05;
  831. //
  832. val = Math::pow(2,val);
  833. if (sg)
  834. val=-val;
  835. v=val;
  836. easing_draw->update();
  837. //emit_signal("variant_changed");
  838. emit_signal("variant_changed");
  839. }
  840. if (p_ev.type==InputEvent::MOUSE_BUTTON && p_ev.mouse_button.button_index==BUTTON_LEFT) {
  841. }
  842. }
  843. void CustomPropertyEditor::_draw_easing() {
  844. RID ci = easing_draw->get_canvas_item();
  845. Size2 s = easing_draw->get_size();
  846. Rect2 r(Point2(),s);
  847. r=r.grow(3);
  848. get_stylebox("normal","LineEdit")->draw(ci,r);
  849. //VisualServer::get_singleton()->canvas_item_add
  850. int points = 48;
  851. float prev=1.0;
  852. float exp=v;
  853. bool flip=hint_text=="attenuation";
  854. Ref<Font> f = get_font("font","Label");
  855. Color color = get_color("font_color","Label");
  856. for(int i=1;i<=points;i++) {
  857. float ifl = i/float(points);
  858. float iflp = (i-1)/float(points);
  859. float h = 1.0-Math::ease(ifl,exp);
  860. if (flip) {
  861. ifl=1.0-ifl;
  862. iflp=1.0-iflp;
  863. }
  864. VisualServer::get_singleton()->canvas_item_add_line(ci,Point2(iflp*s.width,prev*s.height),Point2(ifl*s.width,h*s.height),color);
  865. prev=h;
  866. }
  867. f->draw(ci,Point2(10,10+f->get_ascent()),String::num(exp,2),color);
  868. }
  869. void CustomPropertyEditor::_text_edit_changed() {
  870. v=text_edit->get_text();
  871. emit_signal("variant_changed");
  872. }
  873. void CustomPropertyEditor::_modified(String p_string) {
  874. if (updating)
  875. return;
  876. updating=true;
  877. switch(type) {
  878. case Variant::REAL: {
  879. if (hint!=PROPERTY_HINT_EXP_EASING) {
  880. v=value_editor[0]->get_text().to_double();
  881. emit_signal("variant_changed");
  882. }
  883. } break;
  884. case Variant::STRING: {
  885. v=value_editor[0]->get_text();
  886. emit_signal("variant_changed");
  887. } break;
  888. case Variant::VECTOR2: {
  889. Vector2 vec;
  890. vec.x=value_editor[0]->get_text().to_double();
  891. vec.y=value_editor[1]->get_text().to_double();
  892. v=vec;
  893. emit_signal("variant_changed");
  894. } break;
  895. case Variant::RECT2: {
  896. Rect2 r2;
  897. r2.pos.x=value_editor[0]->get_text().to_double();
  898. r2.pos.y=value_editor[1]->get_text().to_double();
  899. r2.size.x=value_editor[2]->get_text().to_double();
  900. r2.size.y=value_editor[3]->get_text().to_double();
  901. v=r2;
  902. emit_signal("variant_changed");
  903. } break;
  904. case Variant::VECTOR3: {
  905. Vector3 vec;
  906. vec.x=value_editor[0]->get_text().to_double();
  907. vec.y=value_editor[1]->get_text().to_double();
  908. vec.z=value_editor[2]->get_text().to_double();
  909. v=vec;
  910. emit_signal("variant_changed");
  911. } break;
  912. case Variant::PLANE: {
  913. Plane pl;
  914. pl.normal.x=value_editor[0]->get_text().to_double();
  915. pl.normal.y=value_editor[1]->get_text().to_double();
  916. pl.normal.z=value_editor[2]->get_text().to_double();
  917. pl.d=value_editor[3]->get_text().to_double();
  918. v=pl;
  919. emit_signal("variant_changed");
  920. } break;
  921. case Variant::QUAT: {
  922. Quat q;
  923. q.x=value_editor[0]->get_text().to_double();
  924. q.y=value_editor[1]->get_text().to_double();
  925. q.z=value_editor[2]->get_text().to_double();
  926. q.w=value_editor[3]->get_text().to_double();
  927. v=q;
  928. emit_signal("variant_changed");
  929. } break;
  930. case Variant::_AABB: {
  931. Vector3 pos;
  932. pos.x=value_editor[0]->get_text().to_double();
  933. pos.y=value_editor[1]->get_text().to_double();
  934. pos.z=value_editor[2]->get_text().to_double();
  935. Vector3 size;
  936. size.x=value_editor[3]->get_text().to_double();
  937. size.y=value_editor[4]->get_text().to_double();
  938. size.z=value_editor[5]->get_text().to_double();
  939. v=AABB(pos,size);
  940. emit_signal("variant_changed");
  941. } break;
  942. case Variant::MATRIX32: {
  943. Matrix3 m;
  944. for(int i=0;i<6;i++) {
  945. m.elements[i/2][i%2]=value_editor[i]->get_text().to_double();
  946. }
  947. v=m;
  948. emit_signal("variant_changed");
  949. } break;
  950. case Variant::MATRIX3: {
  951. Matrix3 m;
  952. for(int i=0;i<9;i++) {
  953. m.elements[i/3][i%3]=value_editor[i]->get_text().to_double();
  954. }
  955. v=m;
  956. emit_signal("variant_changed");
  957. } break;
  958. case Variant::TRANSFORM: {
  959. Matrix3 basis;
  960. for(int i=0;i<9;i++) {
  961. basis.elements[i/3][i%3]=value_editor[(i/3)*4+i%3]->get_text().to_double();
  962. }
  963. Vector3 origin;
  964. origin.x=value_editor[3]->get_text().to_double();
  965. origin.y=value_editor[7]->get_text().to_double();
  966. origin.z=value_editor[11]->get_text().to_double();
  967. v=Transform(basis,origin);
  968. emit_signal("variant_changed");
  969. } break;
  970. case Variant::COLOR: {
  971. /*
  972. for (int i=0;i<4;i++) {
  973. scroll[i]->set_val( value_editor[i]->get_text().to_double() );
  974. }
  975. Color c;
  976. c.r=value_editor[0]->get_text().to_double();
  977. c.g=value_editor[1]->get_text().to_double();
  978. c.b=value_editor[2]->get_text().to_double();
  979. c.a=value_editor[3]->get_text().to_double();
  980. v=c;
  981. update();
  982. emit_signal("variant_changed");
  983. */
  984. } break;
  985. case Variant::IMAGE: {
  986. } break;
  987. case Variant::NODE_PATH: {
  988. } break;
  989. case Variant::INPUT_EVENT: {
  990. } break;
  991. case Variant::DICTIONARY: {
  992. } break;
  993. case Variant::RAW_ARRAY: {
  994. } break;
  995. case Variant::INT_ARRAY: {
  996. } break;
  997. case Variant::REAL_ARRAY: {
  998. } break;
  999. case Variant::STRING_ARRAY: {
  1000. } break;
  1001. case Variant::VECTOR3_ARRAY: {
  1002. } break;
  1003. case Variant::COLOR_ARRAY: {
  1004. } break;
  1005. default: {}
  1006. }
  1007. updating=false;
  1008. }
  1009. void CustomPropertyEditor::_focus_enter() {
  1010. switch(type) {
  1011. case Variant::REAL:
  1012. case Variant::STRING:
  1013. case Variant::VECTOR2:
  1014. case Variant::RECT2:
  1015. case Variant::VECTOR3:
  1016. case Variant::PLANE:
  1017. case Variant::QUAT:
  1018. case Variant::_AABB:
  1019. case Variant::MATRIX32:
  1020. case Variant::MATRIX3:
  1021. case Variant::TRANSFORM: {
  1022. for (int i=0;i<MAX_VALUE_EDITORS;++i) {
  1023. if (value_editor[i]->has_focus()) {
  1024. value_editor[i]->select_all();
  1025. break;
  1026. }
  1027. }
  1028. } break;
  1029. default: {}
  1030. }
  1031. }
  1032. void CustomPropertyEditor::_focus_exit() {
  1033. switch(type) {
  1034. case Variant::REAL:
  1035. case Variant::STRING:
  1036. case Variant::VECTOR2:
  1037. case Variant::RECT2:
  1038. case Variant::VECTOR3:
  1039. case Variant::PLANE:
  1040. case Variant::QUAT:
  1041. case Variant::_AABB:
  1042. case Variant::MATRIX32:
  1043. case Variant::MATRIX3:
  1044. case Variant::TRANSFORM: {
  1045. for (int i=0;i<MAX_VALUE_EDITORS;++i) {
  1046. value_editor[i]->select(0, 0);
  1047. }
  1048. } break;
  1049. default: {}
  1050. }
  1051. }
  1052. void CustomPropertyEditor::config_action_buttons(const List<String>& p_strings) {
  1053. int w=100;
  1054. int h=18;
  1055. int m=5;
  1056. set_size( Size2( w, m*2+(h+m)*p_strings.size() ) );
  1057. for (int i=0;i<MAX_ACTION_BUTTONS;i++) {
  1058. if (i<p_strings.size()) {
  1059. action_buttons[i]->show();
  1060. action_buttons[i]->set_text(p_strings[i]);
  1061. action_buttons[i]->set_pos( Point2( m, m+i*(h+m) ));
  1062. action_buttons[i]->set_size( Size2( w-m*2, h ) );
  1063. action_buttons[i]->set_flat(true);
  1064. } else {
  1065. action_buttons[i]->hide();
  1066. }
  1067. }
  1068. }
  1069. void CustomPropertyEditor::config_value_editors(int p_amount, int p_columns,int p_label_w,const List<String>& p_strings) {
  1070. int w=80;
  1071. int h=20;
  1072. int m=10;
  1073. int rows=((p_amount-1)/p_columns)+1;
  1074. set_size( Size2( m*(1+p_columns)+(w+p_label_w)*p_columns, m*(1+rows)+h*rows ) );
  1075. for (int i=0;i<MAX_VALUE_EDITORS;i++) {
  1076. int c=i%p_columns;
  1077. int r=i/p_columns;
  1078. if (i<p_amount) {
  1079. value_editor[i]->show();
  1080. value_label[i]->show();
  1081. value_label[i]->set_text(i<p_strings.size()?p_strings[i]:String(""));
  1082. value_editor[i]->set_pos( Point2( m+p_label_w+c*(w+m+p_label_w), m+r*(h+m) ));
  1083. value_editor[i]->set_size( Size2( w, h ) );
  1084. value_label[i]->set_pos( Point2( m+c*(w+m+p_label_w), m+r*(h+m) ) );
  1085. value_editor[i]->set_editable(!read_only);
  1086. } else {
  1087. value_editor[i]->hide();
  1088. value_label[i]->hide();
  1089. }
  1090. }
  1091. }
  1092. void CustomPropertyEditor::_bind_methods() {
  1093. ObjectTypeDB::bind_method("_focus_enter", &CustomPropertyEditor::_focus_enter);
  1094. ObjectTypeDB::bind_method("_focus_exit", &CustomPropertyEditor::_focus_exit);
  1095. ObjectTypeDB::bind_method("_modified",&CustomPropertyEditor::_modified);
  1096. ObjectTypeDB::bind_method("_scroll_modified",&CustomPropertyEditor::_scroll_modified);
  1097. ObjectTypeDB::bind_method("_action_pressed",&CustomPropertyEditor::_action_pressed);
  1098. ObjectTypeDB::bind_method("_file_selected",&CustomPropertyEditor::_file_selected);
  1099. ObjectTypeDB::bind_method("_type_create_selected",&CustomPropertyEditor::_type_create_selected);
  1100. ObjectTypeDB::bind_method("_node_path_selected",&CustomPropertyEditor::_node_path_selected);
  1101. ObjectTypeDB::bind_method("_color_changed",&CustomPropertyEditor::_color_changed);
  1102. ObjectTypeDB::bind_method("_draw_easing",&CustomPropertyEditor::_draw_easing);
  1103. ObjectTypeDB::bind_method("_drag_easing",&CustomPropertyEditor::_drag_easing);
  1104. ObjectTypeDB::bind_method( "_text_edit_changed",&CustomPropertyEditor::_text_edit_changed);
  1105. ObjectTypeDB::bind_method( "_menu_option",&CustomPropertyEditor::_menu_option);
  1106. ADD_SIGNAL( MethodInfo("variant_changed") );
  1107. ADD_SIGNAL( MethodInfo("resource_edit_request") );
  1108. }
  1109. CustomPropertyEditor::CustomPropertyEditor() {
  1110. read_only=false;
  1111. updating=false;
  1112. for (int i=0;i<MAX_VALUE_EDITORS;i++) {
  1113. value_editor[i]=memnew( LineEdit );
  1114. add_child( value_editor[i] );
  1115. value_label[i]=memnew( Label );
  1116. add_child( value_label[i] );
  1117. value_editor[i]->hide();
  1118. value_label[i]->hide();
  1119. value_editor[i]->connect("text_entered", this,"_modified");
  1120. value_editor[i]->connect("focus_enter", this, "_focus_enter");
  1121. value_editor[i]->connect("focus_exit", this, "_focus_exit");
  1122. }
  1123. for(int i=0;i<4;i++) {
  1124. scroll[i] = memnew( HScrollBar );
  1125. scroll[i]->hide();
  1126. scroll[i]->set_min(0);
  1127. scroll[i]->set_max(1.0);
  1128. scroll[i]->set_step(0.01);
  1129. add_child(scroll[i]);
  1130. scroll[i]->connect("value_changed", this,"_scroll_modified");
  1131. }
  1132. for(int i=0;i<20;i++) {
  1133. checks20[i]=memnew( Button );
  1134. checks20[i]->set_toggle_mode(true);
  1135. checks20[i]->set_focus_mode(FOCUS_NONE);
  1136. add_child(checks20[i]);
  1137. checks20[i]->hide();
  1138. checks20[i]->connect("pressed",this,"_action_pressed",make_binds(i));
  1139. checks20[i]->set_tooltip("Bit "+itos(i)+", val "+itos(1<<i)+".");
  1140. }
  1141. text_edit = memnew( TextEdit );
  1142. add_child(text_edit);
  1143. text_edit->set_area_as_parent_rect();
  1144. for(int i=0;i<4;i++)
  1145. text_edit->set_margin((Margin)i,5);
  1146. text_edit->set_margin(MARGIN_BOTTOM,30);
  1147. text_edit->hide();
  1148. text_edit->connect("text_changed",this,"_text_edit_changed");
  1149. for (int i=0;i<MAX_ACTION_BUTTONS;i++) {
  1150. action_buttons[i]=memnew(Button);
  1151. action_buttons[i]->hide();
  1152. add_child(action_buttons[i]);
  1153. Vector<Variant> binds;
  1154. binds.push_back(i);
  1155. action_buttons[i]->connect("pressed", this,"_action_pressed",binds);
  1156. }
  1157. color_picker = memnew( ColorPicker );
  1158. add_child(color_picker);
  1159. color_picker->hide();
  1160. color_picker->set_area_as_parent_rect();
  1161. for(int i=0;i<4;i++)
  1162. color_picker->set_margin((Margin)i,5);
  1163. color_picker->connect("color_changed",this,"_color_changed");
  1164. set_as_toplevel(true);
  1165. file = memnew ( FileDialog );
  1166. add_child(file);
  1167. file->hide();
  1168. file->connect("file_selected", this,"_file_selected");
  1169. file->connect("dir_selected", this,"_file_selected");
  1170. error = memnew( ConfirmationDialog );
  1171. error->set_title("Error!");
  1172. add_child(error);
  1173. //error->get_cancel()->hide();
  1174. type_button = memnew( MenuButton );
  1175. add_child(type_button);
  1176. type_button->hide();
  1177. type_button->get_popup()->connect("item_pressed", this,"_type_create_selected");
  1178. scene_tree = memnew( SceneTreeDialog );
  1179. add_child(scene_tree);
  1180. scene_tree->connect("selected", this,"_node_path_selected");
  1181. texture_preview = memnew( TextureFrame );
  1182. add_child( texture_preview);
  1183. texture_preview->hide();
  1184. easing_draw=memnew( Control );
  1185. add_child(easing_draw);
  1186. easing_draw->hide();
  1187. easing_draw->connect("draw",this,"_draw_easing");
  1188. easing_draw->connect("input_event",this,"_drag_easing");
  1189. //easing_draw->emit_signal(SceneStringNames::get_singleton()->input_event,InputEvent());
  1190. easing_draw->set_default_cursor_shape(Control::CURSOR_MOVE);
  1191. menu = memnew(PopupMenu);
  1192. add_child(menu);
  1193. menu->connect("item_pressed",this,"_menu_option");
  1194. }
  1195. Node *PropertyEditor::get_instanced_node() {
  1196. //this sucks badly
  1197. if (!obj)
  1198. return NULL;
  1199. Node *node = obj->cast_to<Node>();
  1200. if (!node)
  1201. return NULL;
  1202. if (node->get_filename()=="")
  1203. return NULL;
  1204. if (!node->get_owner())
  1205. return NULL; //scene root i guess
  1206. return node;
  1207. }
  1208. TreeItem *PropertyEditor::find_item(TreeItem *p_item,const String& p_name) {
  1209. if (!p_item)
  1210. return NULL;
  1211. String name = p_item->get_metadata(1);
  1212. if (name==p_name) {
  1213. return p_item;
  1214. }
  1215. TreeItem *c=p_item->get_children();
  1216. while (c) {
  1217. TreeItem *found = find_item(c,p_name);
  1218. if (found)
  1219. return found;
  1220. c=c->get_next();
  1221. }
  1222. return NULL;
  1223. }
  1224. void PropertyEditor::_changed_callback(Object *p_changed,const char * p_prop) {
  1225. _changed_callbacks(p_changed,p_prop);
  1226. }
  1227. void PropertyEditor::_changed_callbacks(Object *p_changed,const String& p_prop) {
  1228. if (p_changed!=obj)
  1229. return;
  1230. if (changing)
  1231. return;
  1232. if (p_prop==String())
  1233. update_tree_pending=true;
  1234. else {
  1235. pending[p_prop]=p_prop;
  1236. }
  1237. }
  1238. void PropertyEditor::update_property(const String& p_prop) {
  1239. if (obj)
  1240. _changed_callbacks(obj,p_prop);
  1241. }
  1242. void PropertyEditor::set_item_text(TreeItem *p_item, int p_type, const String& p_name, int p_hint, const String& p_hint_text) {
  1243. switch( p_type ) {
  1244. case Variant::BOOL: {
  1245. p_item->set_checked( 1, obj->get( p_name ) );
  1246. } break;
  1247. case Variant::REAL:
  1248. case Variant::INT: {
  1249. if (p_hint==PROPERTY_HINT_ALL_FLAGS) {
  1250. tree->update();
  1251. break;
  1252. }
  1253. if (p_hint==PROPERTY_HINT_FLAGS) {
  1254. Vector<String> values = p_hint_text.split(",");
  1255. String flags;
  1256. int val = obj->get(p_name);
  1257. for(int i=0;i<values.size();i++) {
  1258. String v = values[i];
  1259. if (v=="")
  1260. continue;
  1261. if (!(val&(1<<i)))
  1262. continue;
  1263. if (flags!="")
  1264. flags+=", ";
  1265. flags+=v;
  1266. }
  1267. p_item->set_text(1, flags );
  1268. break;
  1269. }
  1270. if (p_hint==PROPERTY_HINT_EXP_EASING) {
  1271. p_item->set_text(1, String::num(obj->get( p_name ),2) );
  1272. break;
  1273. }
  1274. //p_item->set_cell_mode( 1, TreeItem::CELL_MODE_RANGE );
  1275. if (p_type==Variant::REAL) {
  1276. p_item->set_range(1, obj->get( p_name ) );
  1277. } else {
  1278. p_item->set_range(1, obj->get( p_name ) );
  1279. }
  1280. p_item->set_editable(1,!read_only);
  1281. } break;
  1282. case Variant::STRING:
  1283. if (p_hint==PROPERTY_HINT_ENUM) {
  1284. Vector<String> strings = p_hint_text.split(",");
  1285. String current = obj->get(p_name);
  1286. int idx=0;
  1287. for(int x=0;x<strings.size();x++) {
  1288. if (strings[x]==current) {
  1289. idx=x;
  1290. break;
  1291. }
  1292. }
  1293. p_item->set_text(1, p_hint_text);
  1294. p_item->set_range(1,idx);
  1295. break;
  1296. }
  1297. case Variant::VECTOR3:
  1298. case Variant::QUAT:
  1299. case Variant::VECTOR2:
  1300. case Variant::_AABB:
  1301. case Variant::RECT2:
  1302. case Variant::MATRIX32:
  1303. case Variant::MATRIX3:
  1304. case Variant::TRANSFORM: {
  1305. p_item->set_text(1,obj->get(p_name));
  1306. } break;
  1307. case Variant::COLOR: {
  1308. p_item->set_custom_bg_color(1,obj->get(p_name));
  1309. //p_item->set_text(1,obj->get(p_name));
  1310. } break;
  1311. case Variant::IMAGE: {
  1312. Image img = obj->get( p_name );
  1313. if (img.empty())
  1314. p_item->set_text(1,"[Image (empty)]");
  1315. else
  1316. p_item->set_text(1,"[Image "+itos(img.get_width())+"x"+itos(img.get_height())+"]");
  1317. } break;
  1318. case Variant::NODE_PATH: {
  1319. p_item->set_text(1,obj->get(p_name));
  1320. } break;
  1321. case Variant::OBJECT: {
  1322. if (obj->get( p_name ).get_type() == Variant::NIL || obj->get( p_name ).operator RefPtr().is_null()) {
  1323. p_item->set_text(1,"<null>");
  1324. Dictionary d = p_item->get_metadata(0);
  1325. int hint=d.has("hint")?d["hint"].operator int():-1;
  1326. String hint_text=d.has("hint_text")?d["hint_text"]:"";
  1327. if (hint==PROPERTY_HINT_RESOURCE_TYPE && hint_text == "Texture") {
  1328. p_item->set_icon(1,NULL);
  1329. }
  1330. } else {
  1331. RES res = obj->get( p_name ).operator RefPtr();
  1332. if (res->is_type("Texture")) {
  1333. int tw = EditorSettings::get_singleton()->get("property_editor/texture_preview_width");
  1334. p_item->set_icon_max_width(1,tw);
  1335. p_item->set_icon(1,res);
  1336. p_item->set_text(1,"");
  1337. } else if (res->get_name() != "") {
  1338. p_item->set_text(1, res->get_name());
  1339. } else if (res->get_path()!="" && !res->get_path().begins_with("local://")) {
  1340. p_item->set_text(1, res->get_path().get_file());
  1341. } else {
  1342. p_item->set_text(1,"<"+res->get_type()+">");
  1343. };
  1344. }
  1345. } break;
  1346. default: {};
  1347. }
  1348. }
  1349. void PropertyEditor::_notification(int p_what) {
  1350. if (p_what==NOTIFICATION_ENTER_SCENE) {
  1351. get_scene()->connect("node_removed",this,"_node_removed");
  1352. }
  1353. if (p_what==NOTIFICATION_EXIT_SCENE) {
  1354. edit(NULL);
  1355. }
  1356. if (p_what==NOTIFICATION_FIXED_PROCESS) {
  1357. changing=true;
  1358. if (update_tree_pending) {
  1359. update_tree();
  1360. update_tree_pending=false;
  1361. } else {
  1362. const String *k=NULL;
  1363. while ((k=pending.next(k))) {
  1364. TreeItem * item = find_item(tree->get_root(),*k);
  1365. if (!item)
  1366. continue;
  1367. if (get_instanced_node()) {
  1368. Dictionary d = get_instanced_node()->get_instance_state();
  1369. if (d.has(*k)) {
  1370. Variant v = obj->get(*k);
  1371. Variant vorig = d[*k];
  1372. int found=-1;
  1373. for(int i=0;i<item->get_button_count(1);i++) {
  1374. if (item->get_button_id(1,i)==3) {
  1375. found=i;
  1376. break;
  1377. }
  1378. }
  1379. bool changed = ! (v==vorig);
  1380. if ((found!=-1)!=changed) {
  1381. if (changed) {
  1382. item->add_button(1,get_icon("Reload","EditorIcons"),3);
  1383. } else {
  1384. item->erase_button(1,found);
  1385. }
  1386. }
  1387. }
  1388. }
  1389. Dictionary d=item->get_metadata(0);
  1390. set_item_text(item,d["type"],d["name"],d["hint"],d["hint_text"]);
  1391. }
  1392. }
  1393. pending.clear();
  1394. changing=false;
  1395. }
  1396. }
  1397. TreeItem *PropertyEditor::get_parent_node(String p_path,HashMap<String,TreeItem*>& item_paths,TreeItem *root) {
  1398. TreeItem *item=NULL;
  1399. if (p_path=="") {
  1400. item = root;
  1401. } else if (item_paths.has(p_path)) {
  1402. item = item_paths.get(p_path);
  1403. } else {
  1404. // printf("path %s parent path %s - item name %s\n",p_path.ascii().get_data(),p_path.left( p_path.find_last("/") ).ascii().get_data(),p_path.right( p_path.find_last("/") ).ascii().get_data() );
  1405. TreeItem *parent = get_parent_node( p_path.left( p_path.find_last("/") ),item_paths,root );
  1406. item = tree->create_item( parent );
  1407. String name = (p_path.find("/")!=-1)?p_path.right( p_path.find_last("/")+1 ):p_path;
  1408. if (capitalize_paths)
  1409. item->set_text(0, name.capitalize() );
  1410. else
  1411. item->set_text(0, name );
  1412. item->set_tooltip(0, p_path);
  1413. if (item->get_parent()!=root) {
  1414. item->set_icon( 0, get_icon("Folder","EditorIcons"));
  1415. }
  1416. item->set_editable(0,false);
  1417. item->set_selectable(0,false);
  1418. item->set_editable(1,false);
  1419. item->set_selectable(1,false);
  1420. if (item->get_parent()==root) {
  1421. item->set_custom_bg_color(0,get_color("prop_subsection","Editor"));
  1422. item->set_custom_bg_color(1,get_color("prop_subsection","Editor"));
  1423. }
  1424. item_paths[p_path]=item;
  1425. }
  1426. return item;
  1427. }
  1428. void PropertyEditor::update_tree() {
  1429. tree->clear();
  1430. if (!obj)
  1431. return;
  1432. HashMap<String,TreeItem*> item_path;
  1433. TreeItem *root = tree->create_item(NULL);
  1434. tree->set_hide_root(true);
  1435. /*
  1436. TreeItem *title = tree->create_item(root);
  1437. title->set_custom_bg_color(0,get_color("prop_section","Editor"));
  1438. title->set_text(0,"Property"); // todo, fetch name if ID exists in database
  1439. title->set_editable(0,false);
  1440. title->set_selectable(0,false);
  1441. title->set_custom_bg_color(1,get_color("prop_section","Editor"));
  1442. title->set_text(1,"Value"); // todo, fetch name if ID exists in database
  1443. title->set_editable(1,false);
  1444. title->set_selectable(1,false);
  1445. */
  1446. /*
  1447. if (obj->cast_to<Node>() || obj->cast_to<Resource>()) {
  1448. TreeItem *type = tree->create_item(root);
  1449. type->set_text(0,"Type"); // todo, fetch name if ID exists in database
  1450. type->set_text(1,obj->get_type()); // todo, fetch name if ID exists in database
  1451. if (has_icon(obj->get_type(),"EditorIcons"))
  1452. type->set_icon(1,get_icon(obj->get_type(),"EditorIcons") );
  1453. else
  1454. type->set_icon(1,get_icon("Object","EditorIcons") );
  1455. type->set_selectable(0,false);
  1456. type->set_selectable(1,false);
  1457. TreeItem *name = tree->create_item(root);
  1458. name->set_text(0,"Name"); // todo, fetch name if ID exists in database
  1459. if (obj->is_type("Resource"))
  1460. name->set_text(1,obj->cast_to<Resource>()->get_name());
  1461. else if (obj->is_type("Node"))
  1462. name->set_text(1,obj->cast_to<Node>()->get_name());
  1463. name->set_selectable(0,false);
  1464. name->set_selectable(1,false);
  1465. }
  1466. */
  1467. List<PropertyInfo> plist;
  1468. obj->get_property_list(&plist,true);
  1469. Color sscolor=get_color("prop_subsection","Editor");
  1470. TreeItem * current_category=NULL;
  1471. for (List<PropertyInfo>::Element *I=plist.front() ; I ; I=I->next()) {
  1472. PropertyInfo& p = I->get();
  1473. //make sure the property can be edited
  1474. if (p.usage&PROPERTY_USAGE_CATEGORY) {
  1475. if (!show_categories)
  1476. continue;
  1477. List<PropertyInfo>::Element *N=I->next();
  1478. bool valid=true;
  1479. //if no properties in category, skip
  1480. while(N) {
  1481. if (N->get().usage&PROPERTY_USAGE_EDITOR)
  1482. break;
  1483. if (N->get().usage&PROPERTY_USAGE_CATEGORY) {
  1484. valid=false;
  1485. break;
  1486. }
  1487. N=N->next();
  1488. }
  1489. if (!valid)
  1490. continue; //empty, ignore
  1491. TreeItem * sep = tree->create_item(root);
  1492. current_category=sep;
  1493. String type=p.name;
  1494. /*if (has_icon(type,"EditorIcons"))
  1495. sep->set_icon(0,get_icon(type,"EditorIcons") );
  1496. else
  1497. sep->set_icon(0,get_icon("Object","EditorIcons") );
  1498. print_line("CATEGORY: "+type);
  1499. */
  1500. sep->set_text(0,type);
  1501. sep->set_selectable(0,false);
  1502. sep->set_selectable(1,false);
  1503. sep->set_custom_bg_color(0,get_color("prop_category","Editor"));
  1504. sep->set_custom_bg_color(1,get_color("prop_category","Editor"));
  1505. //sep->set_custom_color(0,Color(1,1,1));
  1506. continue;
  1507. } else if ( ! (p.usage&PROPERTY_USAGE_EDITOR ) )
  1508. continue;
  1509. String path=p.name.left( p.name.find_last("/") ) ;
  1510. //printf("property %s\n",p.name.ascii().get_data());
  1511. TreeItem * parent = get_parent_node(path,item_path,current_category?current_category:root );
  1512. //if (parent->get_parent()==root)
  1513. // parent=root;
  1514. int level = 0;
  1515. if (parent!=root) {
  1516. level++;
  1517. TreeItem *parent_lev=parent;
  1518. while(parent_lev->get_parent()!=root) {
  1519. parent_lev=parent_lev->get_parent();
  1520. level++;
  1521. }
  1522. }
  1523. if (level>4)
  1524. level=4;
  1525. Color col = sscolor;
  1526. col.a=(level/4.0)*0.7;
  1527. TreeItem * item = tree->create_item( parent );
  1528. String name = (p.name.find("/")!=-1)?p.name.right( p.name.find_last("/")+1 ):p.name;
  1529. if (level>0) {
  1530. item->set_custom_bg_color(0,col);
  1531. //item->set_custom_bg_color(1,col);
  1532. }
  1533. item->set_editable(0,false);
  1534. item->set_selectable(0,false);
  1535. if (p.usage&PROPERTY_USAGE_CHECKABLE) {
  1536. item->set_cell_mode(0,TreeItem::CELL_MODE_CHECK);
  1537. item->set_selectable(0,true);
  1538. item->set_editable(0,true);
  1539. item->set_checked(0,p.usage&PROPERTY_USAGE_CHECKED);
  1540. }
  1541. if (capitalize_paths)
  1542. item->set_text( 0, name.capitalize() );
  1543. else
  1544. item->set_text( 0, name );
  1545. item->set_tooltip(0, p.name);
  1546. Dictionary d;
  1547. d["name"]=p.name;
  1548. d["type"]=(int)p.type;
  1549. d["hint"]=(int)p.hint;
  1550. d["hint_text"]=p.hint_string;
  1551. item->set_metadata( 0, d );
  1552. item->set_metadata( 1, p.name );
  1553. if (p.name==selected_property) {
  1554. item->select(1);
  1555. }
  1556. //printf("property %s type %i\n",p.name.ascii().get_data(),p.type);
  1557. switch( p.type ) {
  1558. case Variant::BOOL: {
  1559. item->set_cell_mode( 1, TreeItem::CELL_MODE_CHECK );
  1560. item->set_text(1,"On");
  1561. item->set_checked( 1, obj->get( p.name ) );
  1562. item->set_icon( 0, get_icon("Bool","EditorIcons") );
  1563. item->set_editable(1,!read_only);
  1564. } break;
  1565. case Variant::REAL:
  1566. case Variant::INT: {
  1567. if (p.hint==PROPERTY_HINT_EXP_EASING) {
  1568. item->set_cell_mode( 1, TreeItem::CELL_MODE_CUSTOM );
  1569. item->set_text(1, String::num(obj->get( p.name ),2) );
  1570. item->set_editable(1,!read_only);
  1571. item->set_icon( 0, get_icon("Curve","EditorIcons"));
  1572. break;
  1573. }
  1574. if (p.hint==PROPERTY_HINT_ALL_FLAGS) {
  1575. item->set_cell_mode( 1, TreeItem::CELL_MODE_CUSTOM );
  1576. item->set_editable(1,!read_only);
  1577. item->set_custom_draw(1,this,"_draw_flags");
  1578. break;
  1579. }
  1580. if (p.hint==PROPERTY_HINT_FLAGS) {
  1581. item->set_cell_mode( 1, TreeItem::CELL_MODE_CUSTOM );
  1582. item->set_editable(1,!read_only);
  1583. //item->set_icon( 0, get_icon("Curve","EditorIcons"));
  1584. Vector<String> values = p.hint_string.split(",");
  1585. String flags;
  1586. int val = obj->get(p.name);
  1587. for(int i=0;i<values.size();i++) {
  1588. String v = values[i];
  1589. if (v=="")
  1590. continue;
  1591. if (!(val&(1<<i)))
  1592. continue;
  1593. if (flags!="")
  1594. flags+=", ";
  1595. flags+=v;
  1596. }
  1597. item->set_text(1, flags );
  1598. break;
  1599. }
  1600. item->set_cell_mode( 1, TreeItem::CELL_MODE_RANGE );
  1601. if (p.hint==PROPERTY_HINT_RANGE || p.hint==PROPERTY_HINT_EXP_RANGE) {
  1602. int c = p.hint_string.get_slice_count(",");
  1603. float min=0,max=100,step=1;
  1604. if (c>=1) {
  1605. min=p.hint_string.get_slice(",",0).to_double();
  1606. }
  1607. if (c>=2) {
  1608. max=p.hint_string.get_slice(",",1).to_double();
  1609. }
  1610. if (p.type==Variant::REAL && c>=3) {
  1611. step= p.hint_string.get_slice(",",2).to_double();
  1612. }
  1613. item->set_range_config(1,min,max,step,p.hint==PROPERTY_HINT_EXP_RANGE);
  1614. } else if (p.hint==PROPERTY_HINT_ENUM) {
  1615. // int c = p.hint_string.get_slice_count(",");
  1616. item->set_text(1,p.hint_string);
  1617. item->set_icon( 0,get_icon("Enum","EditorIcons") );
  1618. item->set_range(1, obj->get( p.name ) );
  1619. item->set_editable(1,!read_only);
  1620. break;
  1621. } else {
  1622. if (p.type == Variant::REAL) {
  1623. item->set_range_config(1, -65536, 65535, 0.01);
  1624. } else {
  1625. item->set_range_config(1, -65536, 65535, 1);
  1626. }
  1627. };
  1628. if (p.type==Variant::REAL) {
  1629. item->set_icon( 0, get_icon("Real","EditorIcons"));
  1630. item->set_range(1, obj->get( p.name ) );
  1631. } else {
  1632. item->set_icon( 0,get_icon("Integer","EditorIcons") );
  1633. item->set_range(1, obj->get( p.name ) );
  1634. }
  1635. item->set_editable(1,!read_only);
  1636. } break;
  1637. case Variant::STRING: {
  1638. switch (p.hint) {
  1639. case PROPERTY_HINT_DIR:
  1640. case PROPERTY_HINT_FILE:
  1641. case PROPERTY_HINT_GLOBAL_DIR:
  1642. case PROPERTY_HINT_GLOBAL_FILE: {
  1643. item->set_cell_mode( 1, TreeItem::CELL_MODE_STRING );
  1644. item->set_editable(1,!read_only);
  1645. item->set_icon( 0, get_icon("File","EditorIcons") );
  1646. item->set_text(1,obj->get(p.name));
  1647. item->add_button(1,get_icon("Folder","EditorIcons"));
  1648. } break;
  1649. case PROPERTY_HINT_ENUM: {
  1650. item->set_cell_mode( 1, TreeItem::CELL_MODE_RANGE );
  1651. Vector<String> strings = p.hint_string.split(",");
  1652. String current = obj->get(p.name);
  1653. int idx=0;
  1654. for(int x=0;x<strings.size();x++) {
  1655. if (strings[x]==current) {
  1656. idx=x;
  1657. break;
  1658. }
  1659. }
  1660. item->set_text(1, p.hint_string);
  1661. item->set_range(1,idx);
  1662. item->set_editable( 1, !read_only );
  1663. item->set_icon( 0,get_icon("Enum","EditorIcons") );
  1664. } break;
  1665. default: {
  1666. item->set_cell_mode( 1, TreeItem::CELL_MODE_STRING );
  1667. item->set_editable(1,!read_only);
  1668. item->set_icon( 0, get_icon("String","EditorIcons") );
  1669. item->set_text(1,obj->get(p.name));
  1670. if (p.hint==PROPERTY_HINT_MULTILINE_TEXT)
  1671. item->add_button(1,get_icon("MultiLine","EditorIcons") );
  1672. } break;
  1673. }
  1674. } break;
  1675. case Variant::INT_ARRAY: {
  1676. item->set_cell_mode( 1, TreeItem::CELL_MODE_CUSTOM );
  1677. item->set_editable( 1, !read_only );
  1678. item->set_text(1,"[IntArray]");
  1679. item->set_icon( 0, get_icon("ArrayInt","EditorIcons") );
  1680. } break;
  1681. case Variant::REAL_ARRAY: {
  1682. item->set_cell_mode( 1, TreeItem::CELL_MODE_CUSTOM );
  1683. item->set_editable( 1, !read_only );
  1684. item->set_text(1,"[RealArray]");
  1685. item->set_icon( 0, get_icon("ArrayReal","EditorIcons") );
  1686. } break;
  1687. case Variant::STRING_ARRAY: {
  1688. item->set_cell_mode( 1, TreeItem::CELL_MODE_CUSTOM );
  1689. item->set_editable( 1, !read_only );
  1690. item->set_text(1,"[StringArray]");
  1691. item->set_icon( 0, get_icon("ArrayString","EditorIcons") );
  1692. } break;
  1693. case Variant::RAW_ARRAY: {
  1694. item->set_cell_mode( 1, TreeItem::CELL_MODE_CUSTOM );
  1695. item->set_editable( 1, !read_only );
  1696. item->set_text(1,"[Raw Data]");
  1697. item->set_icon( 0, get_icon("ArrayData","EditorIcons") );
  1698. } break;
  1699. case Variant::VECTOR2: {
  1700. item->set_cell_mode( 1, TreeItem::CELL_MODE_CUSTOM );
  1701. item->set_editable( 1, true );
  1702. item->set_text(1,obj->get(p.name));
  1703. item->set_icon( 0,get_icon("Vector2","EditorIcons") );
  1704. } break;
  1705. case Variant::RECT2: {
  1706. item->set_cell_mode( 1, TreeItem::CELL_MODE_CUSTOM );
  1707. item->set_editable( 1, true );
  1708. item->set_text(1,obj->get(p.name));
  1709. item->set_icon( 0,get_icon("Rect2","EditorIcons") );
  1710. } break;
  1711. case Variant::VECTOR3: {
  1712. item->set_cell_mode( 1, TreeItem::CELL_MODE_CUSTOM );
  1713. item->set_editable( 1, true );
  1714. item->set_text(1,obj->get(p.name));
  1715. item->set_icon( 0,get_icon("Vector","EditorIcons") );
  1716. } break;
  1717. case Variant::TRANSFORM: {
  1718. item->set_cell_mode( 1, TreeItem::CELL_MODE_CUSTOM );
  1719. item->set_editable( 1, true );
  1720. item->set_text(1,obj->get(p.name));
  1721. item->set_icon( 0,get_icon("Matrix","EditorIcons") );
  1722. } break;
  1723. case Variant::PLANE: {
  1724. item->set_cell_mode( 1, TreeItem::CELL_MODE_CUSTOM );
  1725. item->set_editable( 1, true );
  1726. item->set_text(1,obj->get(p.name));
  1727. item->set_icon( 0,get_icon("Plane","EditorIcons") );
  1728. } break;
  1729. case Variant::_AABB: {
  1730. item->set_cell_mode( 1, TreeItem::CELL_MODE_CUSTOM );
  1731. item->set_editable( 1, true );
  1732. item->set_text(1,"AABB");
  1733. item->set_icon( 0,get_icon("Rect3","EditorIcons") );
  1734. } break;
  1735. case Variant::QUAT: {
  1736. item->set_cell_mode( 1, TreeItem::CELL_MODE_CUSTOM );
  1737. item->set_editable( 1, true );
  1738. item->set_text(1,obj->get(p.name));
  1739. item->set_icon( 0,get_icon("Quat","EditorIcons") );
  1740. } break;
  1741. case Variant::COLOR: {
  1742. item->set_cell_mode( 1, TreeItem::CELL_MODE_CUSTOM );
  1743. item->set_editable( 1, !read_only );
  1744. // item->set_text(1,obj->get(p.name));
  1745. item->set_custom_bg_color(1,obj->get(p.name));
  1746. item->set_icon( 0,get_icon("Color","EditorIcons") );
  1747. } break;
  1748. case Variant::IMAGE: {
  1749. item->set_cell_mode( 1, TreeItem::CELL_MODE_CUSTOM );
  1750. item->set_editable( 1, !read_only );
  1751. Image img = obj->get( p.name );
  1752. if (img.empty())
  1753. item->set_text(1,"[Image (empty)]");
  1754. else
  1755. item->set_text(1,"[Image "+itos(img.get_width())+"x"+itos(img.get_height())+"]");
  1756. item->set_icon( 0,get_icon("Image","EditorIcons") );
  1757. } break;
  1758. case Variant::NODE_PATH: {
  1759. item->set_cell_mode( 1, TreeItem::CELL_MODE_CUSTOM );
  1760. item->set_editable( 1, !read_only );
  1761. item->set_text(1,obj->get(p.name));
  1762. } break;
  1763. case Variant::OBJECT: {
  1764. item->set_cell_mode( 1, TreeItem::CELL_MODE_CUSTOM );
  1765. item->set_editable( 1, !read_only );
  1766. item->add_button(1,get_icon("EditResource","EditorIcons"));
  1767. String type;
  1768. bool notnil=false;
  1769. if (obj->get( p.name ).get_type() == Variant::NIL || obj->get( p.name ).operator RefPtr().is_null()) {
  1770. item->set_text(1,"<null>");
  1771. } else {
  1772. RES res = obj->get( p.name ).operator RefPtr();
  1773. if (res->is_type("Texture")) {
  1774. int tw = EditorSettings::get_singleton()->get("property_editor/texture_preview_width");
  1775. item->set_icon_max_width(1,tw);
  1776. item->set_icon(1,res);
  1777. item->set_text(1,"");
  1778. } else if (res->get_name() != "") {
  1779. item->set_text(1, res->get_name());
  1780. } else if (res->get_path()!="" && !res->get_path().begins_with("local://")) {
  1781. item->set_text(1, res->get_path().get_file());
  1782. } else {
  1783. item->set_text(1,"<"+res->get_type()+">");
  1784. };
  1785. notnil=true;
  1786. }
  1787. if (p.hint==PROPERTY_HINT_RESOURCE_TYPE) {
  1788. //printf("prop %s , type %s\n",p.name.ascii().get_data(),p.hint_string.ascii().get_data());
  1789. if (has_icon(p.hint_string,"EditorIcons"))
  1790. item->set_icon( 0, get_icon(p.hint_string,"EditorIcons") );
  1791. else
  1792. item->set_icon( 0, get_icon("Object","EditorIcons") );
  1793. }
  1794. // item->double_click_signal.connect( Method1<int>( Method2<int,String>( this, &Editoritem_obj_edited ), p.name ) );
  1795. } break;
  1796. default: {};
  1797. }
  1798. if (keying) {
  1799. item->add_button(1,get_icon("Key","EditorIcons"),2);
  1800. }
  1801. if (get_instanced_node()) {
  1802. Dictionary d = get_instanced_node()->get_instance_state();
  1803. if (d.has(p.name)) {
  1804. Variant v = obj->get(p.name);
  1805. Variant vorig = d[p.name];
  1806. if (! (v==vorig)) {
  1807. item->add_button(1,get_icon("Reload","EditorIcons"),3);
  1808. }
  1809. }
  1810. }
  1811. }
  1812. }
  1813. void PropertyEditor::_item_selected() {
  1814. TreeItem *item = tree->get_selected();
  1815. ERR_FAIL_COND(!item);
  1816. selected_property=item->get_metadata(1);
  1817. }
  1818. void PropertyEditor::_edit_set(const String& p_name, const Variant& p_value) {
  1819. if (autoclear) {
  1820. TreeItem *item = tree->get_selected();
  1821. if (item && item->get_cell_mode(0)==TreeItem::CELL_MODE_CHECK) {
  1822. item->set_checked(0,true);
  1823. }
  1824. }
  1825. if (!undo_redo) {
  1826. obj->set(p_name,p_value);
  1827. _changed_callbacks(obj,p_name);
  1828. emit_signal(_prop_edited,p_name);
  1829. } else {
  1830. undo_redo->create_action("Set "+p_name,true);
  1831. undo_redo->add_do_property(obj,p_name,p_value);
  1832. undo_redo->add_undo_property(obj,p_name,obj->get(p_name));
  1833. undo_redo->add_do_method(this,"_changed_callback",obj,p_name);
  1834. undo_redo->add_undo_method(this,"_changed_callback",obj,p_name);
  1835. undo_redo->add_undo_method(this,"_changed_callback",obj,p_name);
  1836. Resource *r = obj->cast_to<Resource>();
  1837. if (r) {
  1838. if (!r->is_edited() && String(p_name)!="resource/edited") {
  1839. undo_redo->add_do_method(r,"set_edited",true);
  1840. undo_redo->add_undo_method(r,"set_edited",false);
  1841. }
  1842. }
  1843. _prop_edited_name[0]=p_name;
  1844. undo_redo->add_do_method(this,"emit_signal",_prop_edited,_prop_edited_name);
  1845. undo_redo->commit_action();
  1846. }
  1847. }
  1848. void PropertyEditor::_item_edited() {
  1849. TreeItem * item = tree->get_edited();
  1850. Dictionary d = item->get_metadata(0);
  1851. String name=d["name"];
  1852. if (tree->get_edited_column()==0) {
  1853. //property checked
  1854. if (autoclear) {
  1855. if (!item->is_checked(0)) {
  1856. obj->set(name,Variant());
  1857. update_property(name);
  1858. } else {
  1859. Variant::CallError ce;
  1860. obj->set(name,Variant::construct(Variant::Type(int(d["type"])),NULL,0,ce));
  1861. }
  1862. } else {
  1863. emit_signal("property_toggled",name,item->is_checked(0));
  1864. }
  1865. return;
  1866. }
  1867. if (autoclear && item->get_cell_mode(0)==TreeItem::CELL_MODE_CHECK && item->get_cell_mode(1)!=TreeItem::CELL_MODE_CUSTOM) {
  1868. item->set_checked(0,true);
  1869. }
  1870. int type=d["type"];
  1871. int hint= d["hint"];
  1872. String hint_text=d["hint_text"];
  1873. switch(type) {
  1874. case Variant::NIL: {
  1875. } break;
  1876. case Variant::BOOL: {
  1877. _edit_set(name,item->is_checked(1));
  1878. } break;
  1879. case Variant::INT:
  1880. case Variant::REAL: {
  1881. if (hint==PROPERTY_HINT_ALL_FLAGS)
  1882. break;
  1883. if (hint==PROPERTY_HINT_EXP_EASING)
  1884. break;
  1885. if (hint==PROPERTY_HINT_FLAGS)
  1886. break;
  1887. if (type==Variant::INT)
  1888. _edit_set(name,int(item->get_range(1)));
  1889. else
  1890. _edit_set(name,item->get_range(1));
  1891. } break;
  1892. case Variant::STRING: {
  1893. if (hint==PROPERTY_HINT_ENUM) {
  1894. int idx= item->get_range(1);
  1895. Vector<String> strings = hint_text.split(",");
  1896. String txt;
  1897. if (idx>=0 && idx<strings.size()) {
  1898. txt=strings[idx];
  1899. }
  1900. _edit_set(name,txt);
  1901. } else {
  1902. _edit_set(name,item->get_text(1));
  1903. }
  1904. } break;
  1905. // math types
  1906. case Variant::VECTOR3: {
  1907. } break;
  1908. case Variant::PLANE: {
  1909. } break;
  1910. case Variant::QUAT: {
  1911. } break;
  1912. case Variant::_AABB: {
  1913. } break;
  1914. case Variant::MATRIX3: {
  1915. } break;
  1916. case Variant::TRANSFORM: {
  1917. } break;
  1918. case Variant::COLOR: {
  1919. //_edit_set(name,item->get_custom_bg_color(0));
  1920. } break;
  1921. case Variant::IMAGE: {
  1922. } break;
  1923. case Variant::NODE_PATH: {
  1924. } break;
  1925. case Variant::INPUT_EVENT: {
  1926. } break;
  1927. case Variant::DICTIONARY: {
  1928. } break;
  1929. // arrays
  1930. case Variant::RAW_ARRAY: {
  1931. } break;
  1932. case Variant::INT_ARRAY: {
  1933. } break;
  1934. case Variant::REAL_ARRAY: {
  1935. } break;
  1936. case Variant::STRING_ARRAY: {
  1937. } break;
  1938. case Variant::VECTOR3_ARRAY: {
  1939. } break;
  1940. case Variant::COLOR_ARRAY: {
  1941. } break;
  1942. };
  1943. }
  1944. void PropertyEditor::_resource_edit_request() {
  1945. RES res=custom_editor->get_variant();
  1946. if (res.is_null())
  1947. return;
  1948. String name=custom_editor->get_name();
  1949. emit_signal("resource_selected",res.get_ref_ptr(),name);
  1950. }
  1951. void PropertyEditor::_custom_editor_edited() {
  1952. if (!obj)
  1953. return;
  1954. _edit_set(custom_editor->get_name(), custom_editor->get_variant());
  1955. }
  1956. void PropertyEditor::_custom_editor_request(bool p_arrow) {
  1957. TreeItem * item = tree->get_edited();
  1958. ERR_FAIL_COND(!item);
  1959. Dictionary d = item->get_metadata(0);
  1960. //int type=d["type"];
  1961. String name=d["name"];
  1962. Variant::Type type=Variant::NIL;
  1963. if (d.has("type"))
  1964. type=(Variant::Type)((int)(d["type"]));
  1965. Variant v=obj->get(name);
  1966. int hint=d.has("hint")?d["hint"].operator int():-1;
  1967. String hint_text=d.has("hint_text")?d["hint_text"]:"";
  1968. Rect2 where=tree->get_custom_popup_rect();
  1969. custom_editor->set_pos(where.pos);
  1970. if (custom_editor->edit(obj,name,type,v,hint,hint_text)) {
  1971. custom_editor->popup();
  1972. }
  1973. }
  1974. void PropertyEditor::edit(Object* p_object) {
  1975. if (obj==p_object)
  1976. return;
  1977. if (obj) {
  1978. obj->remove_change_receptor(this);
  1979. }
  1980. obj=p_object;
  1981. update_tree();
  1982. if (obj) {
  1983. obj->add_change_receptor(this);
  1984. }
  1985. }
  1986. void PropertyEditor::_edit_button(Object *p_item, int p_column, int p_button) {
  1987. TreeItem *ti = p_item->cast_to<TreeItem>();
  1988. ERR_FAIL_COND(!ti);
  1989. Dictionary d = ti->get_metadata(0);
  1990. if (p_button==2) {
  1991. if (!d.has("name"))
  1992. return;
  1993. String prop=d["name"];
  1994. emit_signal("property_keyed",prop,obj->get(prop));
  1995. } else if (p_button==3) {
  1996. if (!get_instanced_node())
  1997. return;
  1998. if (!d.has("name"))
  1999. return;
  2000. String prop=d["name"];
  2001. Dictionary d2 = get_instanced_node()->get_instance_state();
  2002. if (d2.has(prop)) {
  2003. _edit_set(prop,d2[prop]);
  2004. }
  2005. } else {
  2006. Dictionary d = ti->get_metadata(0);
  2007. if (!d.has("type"))
  2008. return;
  2009. if (!d.has("hint"))
  2010. return;
  2011. if (!d.has("name"))
  2012. return;
  2013. if (!d.has("hint_text"))
  2014. return;
  2015. int t = d["type"];
  2016. int h = d["hint"];
  2017. String n = d["name"];
  2018. String ht = d["hint_text"];
  2019. if (t==Variant::STRING) {
  2020. Variant v = obj->get(n);
  2021. custom_editor->edit(obj,n,(Variant::Type)t,v,h,ht);
  2022. //Rect2 where=tree->get_custom_popup_rect();
  2023. if (h==PROPERTY_HINT_FILE || h==PROPERTY_HINT_DIR || h==PROPERTY_HINT_GLOBAL_DIR || h==PROPERTY_HINT_GLOBAL_FILE) {
  2024. Rect2 where=tree->get_item_rect(ti,1);
  2025. where.pos-=tree->get_scroll();
  2026. where.pos+=tree->get_global_pos();
  2027. custom_editor->set_pos(where.pos);
  2028. custom_editor->popup();
  2029. } else {
  2030. custom_editor->popup_centered_ratio();
  2031. }
  2032. } else if (t==Variant::OBJECT) {
  2033. RES r = obj->get(n);
  2034. if (r.is_valid()) {
  2035. emit_signal("resource_selected",r,n);
  2036. }
  2037. }
  2038. }
  2039. }
  2040. void PropertyEditor::_node_removed(Node *p_node) {
  2041. if (p_node==obj) {
  2042. edit(NULL);
  2043. }
  2044. }
  2045. void PropertyEditor::set_keying(bool p_active) {
  2046. if (keying==p_active)
  2047. return;
  2048. keying=p_active;
  2049. update_tree();
  2050. }
  2051. void PropertyEditor::_draw_flags(Object *t,const Rect2& p_rect) {
  2052. TreeItem *ti = t->cast_to<TreeItem>();
  2053. if (!ti)
  2054. return;
  2055. Dictionary d = ti->get_metadata(0);
  2056. if (!d.has("name"))
  2057. return;
  2058. uint32_t f = obj->get(d["name"]);
  2059. int bsize = (p_rect.size.height*80/100)/2;
  2060. int h = bsize*2+1;
  2061. int vofs = (p_rect.size.height-h)/2;
  2062. for(int i=0;i<2;i++) {
  2063. Point2 ofs(4,vofs);
  2064. if (i==1)
  2065. ofs.y+=bsize+1;
  2066. ofs+=p_rect.pos;
  2067. for(int j=0;j<10;j++) {
  2068. Point2 o = ofs+Point2(j*(bsize+1),0);
  2069. if (j>=5)
  2070. o.x+=1;
  2071. uint32_t idx=i*10+j;
  2072. bool on=f&(1<<idx);
  2073. tree->draw_rect(Rect2(o,Size2(bsize,bsize)),Color(0,0,0,on?0.8:0.3));
  2074. }
  2075. }
  2076. }
  2077. void PropertyEditor::_bind_methods() {
  2078. ObjectTypeDB::bind_method( "_item_edited",&PropertyEditor::_item_edited);
  2079. ObjectTypeDB::bind_method( "_item_selected",&PropertyEditor::_item_selected);
  2080. ObjectTypeDB::bind_method( "_custom_editor_request",&PropertyEditor::_custom_editor_request);
  2081. ObjectTypeDB::bind_method( "_custom_editor_edited",&PropertyEditor::_custom_editor_edited);
  2082. ObjectTypeDB::bind_method( "_resource_edit_request",&PropertyEditor::_resource_edit_request);
  2083. ObjectTypeDB::bind_method( "_node_removed",&PropertyEditor::_node_removed);
  2084. ObjectTypeDB::bind_method( "_edit_button",&PropertyEditor::_edit_button);
  2085. ObjectTypeDB::bind_method( "_changed_callback",&PropertyEditor::_changed_callbacks);
  2086. ObjectTypeDB::bind_method( "_draw_flags",&PropertyEditor::_draw_flags);
  2087. ADD_SIGNAL( MethodInfo("property_toggled",PropertyInfo( Variant::STRING, "property"),PropertyInfo( Variant::BOOL, "value")));
  2088. ADD_SIGNAL( MethodInfo("resource_selected", PropertyInfo( Variant::OBJECT, "res"),PropertyInfo( Variant::STRING, "prop") ) );
  2089. ADD_SIGNAL( MethodInfo("property_keyed",PropertyInfo( Variant::STRING, "property")));
  2090. ADD_SIGNAL( MethodInfo("property_edited",PropertyInfo( Variant::STRING, "property")));
  2091. }
  2092. Tree *PropertyEditor::get_tree() {
  2093. return tree;
  2094. }
  2095. Label* PropertyEditor::get_top_label() {
  2096. return top_label;
  2097. }
  2098. void PropertyEditor::hide_top_label() {
  2099. top_label->hide();
  2100. tree->set_begin( Point2(0,0 ));
  2101. }
  2102. String PropertyEditor::get_selected_path() const {
  2103. TreeItem *ti = tree->get_selected();
  2104. if (!ti)
  2105. return "";
  2106. Dictionary d = ti->get_metadata(0);
  2107. if (d.has("name"))
  2108. return d["name"];
  2109. else
  2110. return "";
  2111. }
  2112. void PropertyEditor::set_capitalize_paths(bool p_capitalize) {
  2113. capitalize_paths=p_capitalize;
  2114. }
  2115. void PropertyEditor::set_autoclear(bool p_enable) {
  2116. autoclear=p_enable;
  2117. }
  2118. void PropertyEditor::set_show_categories(bool p_show) {
  2119. show_categories=p_show;
  2120. update_tree();
  2121. }
  2122. PropertyEditor::PropertyEditor() {
  2123. _prop_edited="property_edited";
  2124. _prop_edited_name.push_back(String());
  2125. undo_redo=NULL;
  2126. obj=NULL;
  2127. changing=false;
  2128. update_tree_pending=false;
  2129. top_label = memnew( Label );
  2130. top_label->set_text("Properties:");
  2131. top_label->set_anchor( MARGIN_RIGHT, ANCHOR_END );
  2132. top_label->set_begin( Point2( 10,0) );
  2133. top_label->set_end( Point2( 0,12) );
  2134. add_child(top_label);
  2135. tree = memnew( Tree );
  2136. tree->set_anchor( MARGIN_RIGHT, ANCHOR_END );
  2137. tree->set_anchor( MARGIN_BOTTOM, ANCHOR_END );
  2138. tree->set_begin( Point2(0,19 ));
  2139. tree->set_end( Point2(0,0 ));
  2140. tree->set_columns(2);
  2141. tree->set_column_expand(0,true);
  2142. tree->set_column_min_width(0,30);
  2143. tree->set_column_expand(1,true);
  2144. tree->set_column_min_width(1,18);
  2145. //tree->set_hide_root(true);
  2146. add_child( tree );
  2147. tree->connect("item_edited", this,"_item_edited",varray(),CONNECT_DEFERRED);
  2148. tree->connect("cell_selected", this,"_item_selected");
  2149. set_fixed_process(true);
  2150. custom_editor = memnew( CustomPropertyEditor );
  2151. add_child(custom_editor);
  2152. tree->connect("custom_popup_edited", this,"_custom_editor_request");
  2153. tree->connect("button_pressed", this,"_edit_button");
  2154. custom_editor->connect("variant_changed", this,"_custom_editor_edited");
  2155. custom_editor->connect("resource_edit_request", this,"_resource_edit_request",make_binds(),CONNECT_DEFERRED);
  2156. capitalize_paths=true;
  2157. autoclear=false;
  2158. tree->set_column_title(0,"Property");
  2159. tree->set_column_title(1,"Value");
  2160. tree->set_column_titles_visible(true);
  2161. keying=false;
  2162. read_only=false;
  2163. show_categories=false;
  2164. }
  2165. PropertyEditor::~PropertyEditor()
  2166. {
  2167. }