void TileMapEditor::_update_palette() { if (!node) return; int selected = get_selected_tile(); palette->clear(); Ref<TileSet> tileset=node->get_tileset(); if (tileset.is_null()) return; List<int> tiles; tileset->get_tile_list(&tiles); if (tiles.empty()) return; palette->set_max_columns(0); palette->set_icon_mode(ItemList::ICON_MODE_TOP); palette->set_max_text_lines(2); String filter = search_box->get_text().strip_edges(); for (List<int>::Element *E=tiles.front();E;E=E->next()) { String name; if (tileset->tile_get_name(E->get())!="") { name = tileset->tile_get_name(E->get()); } else { name = "#"+itos(E->get()); } if (filter != "" && name.findn(filter) == -1) continue; palette->add_item(name); Ref<Texture> tex = tileset->tile_get_texture(E->get()); if (tex.is_valid()) { Rect2 region = tileset->tile_get_region(E->get()); if (!region.has_no_area()) palette->set_item_icon_region(palette->get_item_count()-1, region); palette->set_item_icon(palette->get_item_count()-1, tex); } palette->set_item_metadata(palette->get_item_count()-1, E->get()); } if (selected != -1) set_selected_tile(selected); else palette->select(0, true); }
void TileMapEditor::_update_palette() { if (!node) return; palette->clear(); Ref<TileSet> tileset=node->get_tileset(); if (!tileset.is_valid()) return; List<int> tiles; tileset->get_tile_list(&tiles); if (display_mode == DISPLAY_THUMBNAIL) { palette->set_max_columns(0); palette->set_icon_mode(ItemList::ICON_MODE_TOP); } else if (display_mode == DISPLAY_LIST) { palette->set_max_columns(1); palette->set_icon_mode(ItemList::ICON_MODE_LEFT); } palette->set_max_text_lines(2); for(List<int>::Element *E=tiles.front();E;E=E->next()) { palette->add_item(""); Ref<Texture> tex = tileset->tile_get_texture(E->get()); if (tex.is_valid()) { Rect2 region = tileset->tile_get_region(E->get()); if (!region.has_no_area()) { Image data = VS::get_singleton()->texture_get_data(tex->get_rid()); Ref<ImageTexture> img = memnew( ImageTexture ); img->create_from_image(data.get_rect(region)); palette->set_item_icon(palette->get_item_count()-1, img); } else { palette->set_item_icon(palette->get_item_count()-1,tex); } } if (tileset->tile_get_name(E->get())!="") { palette->set_item_text(palette->get_item_count()-1, tileset->tile_get_name(E->get())); } else { palette->set_item_text(palette->get_item_count()-1, "#"+itos(E->get())); } palette->set_item_metadata(palette->get_item_count()-1, E->get()); } }
void Popup::popup(const Rect2 &bounds) { emit_signal("about_to_show"); show_modal(exclusive); // Fit the popup into the optionally provided bounds. if (!bounds.has_no_area()) { set_position(bounds.position); set_size(bounds.size); } _fix_size(); Control *focusable = find_next_valid_focus(); if (focusable) focusable->grab_focus(); _post_popup(); notification(NOTIFICATION_POST_POPUP); popped_up = true; }
void TileMapEditor::_draw_cell(int p_cell, const Point2i& p_point, bool p_flip_h, bool p_flip_v, bool p_transpose, const Matrix32& p_xform) { Ref<Texture> t = node->get_tileset()->tile_get_texture(p_cell); if (t.is_null()) return; Vector2 tile_ofs = node->get_tileset()->tile_get_texture_offset(p_cell); Rect2 r = node->get_tileset()->tile_get_region(p_cell); Size2 sc = p_xform.get_scale(); Rect2 rect = Rect2(); rect.pos = node->map_to_world(p_point) + node->get_cell_draw_offset(); if (r.has_no_area()) { rect.size = t->get_size(); } else { rect.size = r.size; } if (rect.size.y > rect.size.x) { if ((p_flip_h && (p_flip_v || p_transpose)) || (p_flip_v && !p_transpose)) tile_ofs.y += rect.size.y - rect.size.x; } else if (rect.size.y < rect.size.x) { if ((p_flip_v && (p_flip_h || p_transpose)) || (p_flip_h && !p_transpose)) tile_ofs.x += rect.size.x - rect.size.y; } if (p_transpose) { SWAP(tile_ofs.x, tile_ofs.y); } if (p_flip_h) { sc.x*=-1.0; tile_ofs.x*=-1.0; } if (p_flip_v) { sc.y*=-1.0; tile_ofs.y*=-1.0; } if (node->get_tile_origin()==TileMap::TILE_ORIGIN_TOP_LEFT) { rect.pos+=tile_ofs; } else if (node->get_tile_origin()==TileMap::TILE_ORIGIN_CENTER) { rect.pos+=node->get_cell_size()/2; Vector2 s = r.size; Vector2 center = (s/2) - tile_ofs; if (p_flip_h) rect.pos.x-=s.x-center.x; else rect.pos.x-=center.x; if (p_flip_v) rect.pos.y-=s.y-center.y; else rect.pos.y-=center.y; } rect.pos=p_xform.xform(rect.pos); rect.size*=sc; if (r.has_no_area()) canvas_item_editor->draw_texture_rect(t, rect, false, Color(1,1,1,0.5), p_transpose); else canvas_item_editor->draw_texture_rect_region(t, rect, r, Color(1,1,1,0.5), p_transpose); }