Delete world feature
This commit is contained in:
parent
01344a9d1d
commit
9119caca65
@ -2,6 +2,7 @@
|
||||
menu.missing-content=Missing Content!
|
||||
world.convert-request=Content indices have changed! Convert world files?
|
||||
error.pack-not-found=Could not to find pack
|
||||
world.delete-confirm=Do you want to delete world forever?
|
||||
|
||||
# Bindings
|
||||
movement.forward=Forward
|
||||
|
||||
@ -24,6 +24,7 @@ world.Name=Название
|
||||
menu.Create World=Создать Мир
|
||||
|
||||
world.convert-request=Есть изменения в индексах! Конвертировать мир?
|
||||
world.delete-confirm=Удалить мир безвозвратно?
|
||||
|
||||
# Настройки
|
||||
settings.Load Distance=Дистанция Загрузки
|
||||
|
||||
BIN
res/textures/gui/delete_icon.png
Normal file
BIN
res/textures/gui/delete_icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 132 B After Width: | Height: | Size: 132 B |
@ -58,7 +58,8 @@ void AssetsLoader::addDefaults(AssetsLoader& loader, bool allAssets) {
|
||||
loader.add(ASSET_SHADER, SHADERS_FOLDER"/ui3d", "ui3d");
|
||||
loader.add(ASSET_SHADER, SHADERS_FOLDER"/background", "background");
|
||||
loader.add(ASSET_SHADER, SHADERS_FOLDER"/skybox_gen", "skybox_gen");
|
||||
loader.add(ASSET_TEXTURE, TEXTURES_FOLDER"/menubg.png", "menubg");
|
||||
loader.add(ASSET_TEXTURE, TEXTURES_FOLDER"/gui/menubg.png", "gui/menubg");
|
||||
loader.add(ASSET_TEXTURE, TEXTURES_FOLDER"/gui/delete_icon.png", "gui/delete_icon");
|
||||
loader.add(ASSET_FONT, FONTS_FOLDER"/font", "normal");
|
||||
}
|
||||
loader.add(ASSET_ATLAS, TEXTURES_FOLDER"/blocks", "blocks");
|
||||
|
||||
@ -62,8 +62,19 @@ void Label::size(vec2 sizenew) {
|
||||
UINode::size(vec2(UINode::size().x, sizenew.y));
|
||||
}
|
||||
|
||||
// ================================= Image ====================================
|
||||
Image::Image(string texture, vec2 size) : UINode(vec2(), size), texture(texture) {
|
||||
}
|
||||
|
||||
void Image::draw(Batch2D* batch, Assets* assets) {
|
||||
vec2 coord = calcCoord();
|
||||
batch->texture(assets->getTexture(texture));
|
||||
batch->color = color_;
|
||||
batch->rect(coord.x, coord.y, size_.x, size_.y, 0, 0, 0, UVRegion(), false, true, color_);
|
||||
}
|
||||
|
||||
// ================================= Button ===================================
|
||||
Button::Button(shared_ptr<UINode> content, glm::vec4 padding) : Panel(vec2(32,32), padding, 0) {
|
||||
Button::Button(shared_ptr<UINode> content, glm::vec4 padding) : Panel(vec2(34,32), padding, 0) {
|
||||
add(content);
|
||||
scrollable(false);
|
||||
}
|
||||
@ -100,6 +111,11 @@ Button* Button::textSupplier(wstringsupplier supplier) {
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
void Button::setHoverColor(glm::vec4 color) {
|
||||
hoverColor = color;
|
||||
}
|
||||
|
||||
void Button::drawBackground(Batch2D* batch, Assets* assets) {
|
||||
vec2 coord = calcCoord();
|
||||
batch->texture(nullptr);
|
||||
@ -133,6 +149,35 @@ void Button::textAlign(Align align) {
|
||||
}
|
||||
}
|
||||
|
||||
// ============================== RichButton ==================================
|
||||
RichButton::RichButton(vec2 size) : Container(vec2(), size) {
|
||||
}
|
||||
|
||||
void RichButton::mouseRelease(GUI* gui, int x, int y) {
|
||||
UINode::mouseRelease(gui, x, y);
|
||||
if (isInside(vec2(x, y))) {
|
||||
for (auto callback : actions) {
|
||||
callback(gui);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RichButton* RichButton::listenAction(onaction action) {
|
||||
actions.push_back(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
void RichButton::setHoverColor(glm::vec4 color) {
|
||||
hoverColor = color;
|
||||
}
|
||||
|
||||
void RichButton::drawBackground(Batch2D* batch, Assets* assets) {
|
||||
vec2 coord = calcCoord();
|
||||
batch->texture(nullptr);
|
||||
batch->color = (ispressed() ? pressedColor : (hover_ ? hoverColor : color_));
|
||||
batch->rect(coord.x, coord.y, size_.x, size_.y);
|
||||
}
|
||||
|
||||
// ================================ TextBox ===================================
|
||||
TextBox::TextBox(wstring placeholder, vec4 padding)
|
||||
: Panel(vec2(200,32), padding, 0, false),
|
||||
|
||||
@ -43,6 +43,15 @@ namespace gui {
|
||||
virtual void size(glm::vec2 size) override;
|
||||
};
|
||||
|
||||
class Image : public UINode {
|
||||
protected:
|
||||
std::string texture;
|
||||
public:
|
||||
Image(std::string texture, glm::vec2 size);
|
||||
|
||||
virtual void draw(Batch2D* batch, Assets* assets) override;
|
||||
};
|
||||
|
||||
class Button : public Panel {
|
||||
protected:
|
||||
glm::vec4 hoverColor {0.05f, 0.1f, 0.15f, 0.75f};
|
||||
@ -55,7 +64,7 @@ namespace gui {
|
||||
glm::vec4 padding=glm::vec4(2.0f),
|
||||
glm::vec4 margin=glm::vec4(1.0f));
|
||||
|
||||
virtual void drawBackground(Batch2D* batch, Assets* assets);
|
||||
virtual void drawBackground(Batch2D* batch, Assets* assets) override;
|
||||
|
||||
virtual std::shared_ptr<UINode> getAt(glm::vec2 pos, std::shared_ptr<UINode> self) override;
|
||||
|
||||
@ -68,6 +77,24 @@ namespace gui {
|
||||
virtual std::wstring text() const;
|
||||
|
||||
virtual Button* textSupplier(wstringsupplier supplier);
|
||||
|
||||
virtual void setHoverColor(glm::vec4 color);
|
||||
};
|
||||
|
||||
class RichButton : public Container {
|
||||
protected:
|
||||
glm::vec4 hoverColor {0.05f, 0.1f, 0.15f, 0.75f};
|
||||
glm::vec4 pressedColor {0.0f, 0.0f, 0.0f, 0.95f};
|
||||
std::vector<onaction> actions;
|
||||
public:
|
||||
RichButton(glm::vec2 size);
|
||||
|
||||
virtual void drawBackground(Batch2D* batch, Assets* assets) override;
|
||||
|
||||
virtual void mouseRelease(GUI*, int x, int y) override;
|
||||
virtual RichButton* listenAction(onaction action);
|
||||
|
||||
virtual void setHoverColor(glm::vec4 color);
|
||||
};
|
||||
|
||||
class TextBox : public Panel {
|
||||
|
||||
@ -98,6 +98,11 @@ void Container::add(UINode* node) {
|
||||
add(shared_ptr<UINode>(node));
|
||||
}
|
||||
|
||||
void Container::add(shared_ptr<UINode> node, glm::vec2 coord) {
|
||||
node->setCoord(coord);
|
||||
add(node);
|
||||
}
|
||||
|
||||
void Container::remove(shared_ptr<UINode> selected) {
|
||||
selected->setParent(nullptr);
|
||||
nodes.erase(std::remove_if(nodes.begin(), nodes.end(),
|
||||
@ -190,15 +195,12 @@ void Panel::refresh() {
|
||||
node->refresh();
|
||||
maxh = fmax(maxh, y+margin.y+node->size().y+margin.w+padding.w);
|
||||
}
|
||||
bool increased = maxh > size.y;
|
||||
if (resizing_) {
|
||||
if (maxLength_)
|
||||
this->size(vec2(glm::min(maxLength_, (int)(x+padding.z)), size.y));
|
||||
else
|
||||
this->size(vec2(x+padding.z, size.y));
|
||||
}
|
||||
if (increased)
|
||||
refresh();
|
||||
actualLength = size.y;
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,6 +39,7 @@ namespace gui {
|
||||
virtual std::shared_ptr<UINode> getAt(glm::vec2 pos, std::shared_ptr<UINode> self) override;
|
||||
virtual void add(std::shared_ptr<UINode> node);
|
||||
virtual void add(UINode* node);
|
||||
virtual void add(std::shared_ptr<UINode> node, glm::vec2 coord);
|
||||
virtual void remove(std::shared_ptr<UINode> node);
|
||||
virtual void scrolled(int value) override;
|
||||
virtual void scrollable(bool flag);
|
||||
|
||||
@ -194,13 +194,37 @@ Panel* create_worlds_panel(Engine* engine) {
|
||||
if (!entry.is_directory()) {
|
||||
continue;
|
||||
}
|
||||
auto name = entry.path().filename().u8string();
|
||||
auto btn = new Button(util::str2wstr_utf8(name),
|
||||
vec4(10.0f, 8.0f, 10.0f, 8.0f));
|
||||
auto folder = entry.path();
|
||||
auto name = folder.filename().u8string();
|
||||
auto namews = util::str2wstr_utf8(name);
|
||||
|
||||
auto btn = std::make_shared<RichButton>(vec2(390, 46));
|
||||
btn->color(vec4(1.0f, 1.0f, 1.0f, 0.1f));
|
||||
btn->setHoverColor(vec4(1.0f, 1.0f, 1.0f, 0.17f));
|
||||
btn->add(std::make_shared<Label>(namews), vec2(8, 8));
|
||||
btn->listenAction([=](GUI*) {
|
||||
open_world(name, engine);
|
||||
});
|
||||
|
||||
auto image = std::make_shared<Image>("gui/delete_icon", vec2(32, 32));
|
||||
image->color(vec4(1, 1, 1, 0.5f));
|
||||
|
||||
auto delbtn = std::make_shared<Button>(image, vec4(2));
|
||||
delbtn->color(vec4(0.0f));
|
||||
delbtn->setHoverColor(vec4(1.0f, 1.0f, 1.0f, 0.17f));
|
||||
|
||||
btn->add(delbtn, vec2(330, 3));
|
||||
|
||||
delbtn->listenAction([=](GUI* gui) {
|
||||
guiutil::confirm(gui, langs::get(L"delete-confirm", L"world")+
|
||||
L" ("+util::str2wstr_utf8(folder.u8string())+L")", [=]()
|
||||
{
|
||||
std::cout << "deleting " << folder.u8string() << std::endl;
|
||||
fs::remove_all(folder);
|
||||
menus::refresh_menus(engine, gui->getMenu());
|
||||
});
|
||||
});
|
||||
|
||||
panel->add(btn);
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ void MenuScreen::draw(float delta) {
|
||||
uint height = Window::height;
|
||||
|
||||
batch->begin();
|
||||
batch->texture(engine->getAssets()->getTexture("menubg"));
|
||||
batch->texture(engine->getAssets()->getTexture("gui/menubg"));
|
||||
batch->rect(0, 0,
|
||||
width, height, 0, 0, 0,
|
||||
UVRegion(0, 0, width/64, height/64),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user