new content menu (WIP)
This commit is contained in:
parent
690e3f54c9
commit
5915b811f2
@ -1,4 +1,4 @@
|
||||
<panel size='400' padding='8' interval='8' color='0'>
|
||||
<label context='menu'>@Page does not exists</label>
|
||||
<label context='menu'>@Page not found</label>
|
||||
<button onclick='menu:back()'>@Back</button>
|
||||
</panel>
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
<panel size='550' color='0' padding='8' interval='5'>
|
||||
<panel id='packs_panel' size='540,10' color='0,0,0,50' max-length='400'>
|
||||
<!-- content is generated in script -->
|
||||
</panel>
|
||||
<button onclick='menu:back()'>@Back</button>
|
||||
</panel>
|
||||
@ -1,14 +0,0 @@
|
||||
function add_pack(packid, packinfo)
|
||||
local callback = string.format('core.add_packs({%q})', packid)
|
||||
packinfo.id = packid
|
||||
packinfo.callback = callback
|
||||
packinfo.icon = "gui/no_icon"
|
||||
document.packs_panel:add(gui.template("pack", packinfo))
|
||||
end
|
||||
|
||||
function on_open()
|
||||
local packs = pack.get_available()
|
||||
for i,id in ipairs(packs) do
|
||||
add_pack(id, pack.get_info(id))
|
||||
end
|
||||
end
|
||||
@ -1,7 +1,13 @@
|
||||
<panel size='550' color='0' padding='8' interval='5'>
|
||||
<panel id='packs_panel' size='540,10' color='0,0,0,50' max-length='400'>
|
||||
<container size='767,454' color='#0F1E2DB2' padding='8' interval='5' context='menu'>
|
||||
<panel id='packs_cur' pos='2' size='380,406' color='0' max-length='406'>
|
||||
<!-- content is generated in script -->
|
||||
</panel>
|
||||
<button onclick='menu.page = "add_packs"'>@Add</button>
|
||||
<button onclick='menu:back()'>@Back</button>
|
||||
</panel>
|
||||
<panel id='packs_add' pos='385,2' size='380,406' color='0' max-length='406'>
|
||||
<!-- content is generated in script -->
|
||||
</panel>
|
||||
<button id='apply_btn' pos='2,410' size='380,40' onclick='apply()'>@Apply</button>
|
||||
<button pos='385,410' size='338,40' onclick='menu:back()'>@Cancel</button>
|
||||
<image onclick='refresh()' interactive='true' src='gui/refresh'
|
||||
size='32' margin='7' gravity='bottom-right'
|
||||
color='#FFFFFF80' hover-color='#FFFFFF10'/>
|
||||
</container>
|
||||
|
||||
@ -1,19 +1,85 @@
|
||||
function add_pack(packid, packinfo)
|
||||
local remover = ''
|
||||
if packid ~= "base" then
|
||||
remover = string.format('core.remove_packs({%q})', packid)
|
||||
function on_open()
|
||||
refresh()
|
||||
end
|
||||
|
||||
-- // FIXME: dependency checks
|
||||
add_packs = {}
|
||||
rem_packs = {}
|
||||
|
||||
function apply()
|
||||
core.reconfig_packs(add_packs, rem_packs)
|
||||
end
|
||||
|
||||
function refresh_changes()
|
||||
document.apply_btn.enabled = (#add_packs>0) or (#rem_packs>0)
|
||||
end
|
||||
|
||||
function move_pack(id)
|
||||
-- cancel pack addition
|
||||
if table.has(add_packs, id) then
|
||||
document["pack_"..id]:move_into(document.packs_add)
|
||||
table.remove_value(add_packs, id)
|
||||
-- cancel pack removal
|
||||
elseif table.has(rem_packs, id) then
|
||||
document["pack_"..id]:move_into(document.packs_cur)
|
||||
table.remove_value(rem_packs, id)
|
||||
-- add pack
|
||||
elseif table.has(packs_installed, id) then
|
||||
document["pack_"..id]:move_into(document.packs_add)
|
||||
table.insert(rem_packs, id)
|
||||
-- remove pack
|
||||
else
|
||||
document["pack_"..id]:move_into(document.packs_cur)
|
||||
table.insert(add_packs, id)
|
||||
end
|
||||
refresh_changes()
|
||||
end
|
||||
|
||||
function place_pack(panel, packid, packinfo, callback)
|
||||
packinfo.id = packid
|
||||
callback = callback or ""
|
||||
if packinfo.has_indices then
|
||||
packid = packid.."*"
|
||||
end
|
||||
packinfo.id = packid
|
||||
packinfo.remover = remover
|
||||
document.packs_panel:add(gui.template("pack", packinfo))
|
||||
packinfo.id_verbose = packid
|
||||
packinfo.callback = callback
|
||||
panel:add(gui.template("pack", packinfo))
|
||||
end
|
||||
|
||||
function on_open()
|
||||
local packs = pack.get_installed()
|
||||
for i,id in ipairs(packs) do
|
||||
add_pack(id, pack.get_info(id))
|
||||
function refresh()
|
||||
packs_installed = pack.get_installed()
|
||||
packs_available = pack.get_available()
|
||||
|
||||
local packs_cur = document.packs_cur
|
||||
local packs_add = document.packs_add
|
||||
|
||||
packs_cur:clear()
|
||||
packs_add:clear()
|
||||
refresh_changes()
|
||||
|
||||
for i,id in ipairs(packs_installed) do
|
||||
local packinfo = pack.get_info(id)
|
||||
packinfo.index = i
|
||||
callback = id ~= "base" and string.format('move_pack("%s")', id) or nil
|
||||
place_pack(packs_cur, id, packinfo, callback)
|
||||
end
|
||||
|
||||
for i,id in ipairs(packs_available) do
|
||||
local packinfo = pack.get_info(id)
|
||||
packinfo.index = i
|
||||
callback = string.format('move_pack("%s")', id)
|
||||
place_pack(packs_add, id, packinfo, callback)
|
||||
end
|
||||
|
||||
-- apply packs movements
|
||||
for i,id in ipairs(packs_installed) do
|
||||
if table.has(rem_packs, id) then
|
||||
document["pack_"..id]:move_into(packs_add)
|
||||
end
|
||||
end
|
||||
for i,id in ipairs(packs_available) do
|
||||
if table.has(add_packs, id) then
|
||||
document["pack_"..id]:move_into(packs_cur)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<container onclick='%{callback}' size='540,80' color='#0F1E2DB2' hover-color='#0F1E2DF0'>
|
||||
<container id='pack_%{id}' onclick='%{callback}' size='540,80' color='#00000040' hover-color='#00000080' z-index="%{index}">
|
||||
<label color='#FFFFFF80' size='300,25' align='right' gravity='top-right'>
|
||||
[%{id}]
|
||||
[%{id_verbose}]
|
||||
</label>
|
||||
<label pos='78,6'>%{title}</label>
|
||||
<label if='%{creator}' color='#CCFFE5B2' size='300,20' align='right'
|
||||
@ -10,9 +10,5 @@
|
||||
<label pos='80,28' color='#FFFFFFB2'>
|
||||
%{description}
|
||||
</label>
|
||||
<button if='%{remover}' onclick='%{remover}' color='0' hover-color='#FFFFFF2B'
|
||||
gravity='center-right' margin='10' padding='0'>
|
||||
<image src='gui/cross' size='32,32' color='#FFFFFF80'/>
|
||||
</button>
|
||||
<image pos='8,8' src='%{icon}' size='64'></image>
|
||||
<image pos='8,8' src='%{icon}' size='64'/>
|
||||
</container>
|
||||
|
||||
@ -232,6 +232,37 @@ function session.reset_entry(name)
|
||||
session.entries[name] = nil
|
||||
end
|
||||
|
||||
function timeit(func, ...)
|
||||
local tm = time.uptime()
|
||||
func(...)
|
||||
print("[time mcs]", (time.uptime()-tm) * 1000000)
|
||||
end
|
||||
|
||||
function table.has(t, x)
|
||||
for i,v in ipairs(t) do
|
||||
if v == x then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function table.index(t, x)
|
||||
for i,v in ipairs(t) do
|
||||
if v == x then
|
||||
return i
|
||||
end
|
||||
end
|
||||
return -1
|
||||
end
|
||||
|
||||
function table.remove_value(t, x)
|
||||
local index = table.index(t, x)
|
||||
if index ~= -1 then
|
||||
table.remove(t, index)
|
||||
end
|
||||
end
|
||||
|
||||
-- Deprecated functions
|
||||
block_index = block.index
|
||||
block_name = block.name
|
||||
|
||||
@ -13,44 +13,44 @@ error.dependency-not-found=Die verwendete Abhängigkeit wurde nicht gefunden
|
||||
pack.remove-confirm=Alle vom Paket bereitgestellten Inhalte (dauerhaft) aus der Welt löschen?
|
||||
|
||||
# Меню
|
||||
menu.Apply=Anwenden
|
||||
menu.Audio=Klang
|
||||
menu.Back to Main Menu=Zurück zum Menü
|
||||
menu.Content Error=Inhaltsfehler
|
||||
menu.Content=Inhalt
|
||||
menu.Continue=Weitermachen
|
||||
menu.Controls=Kontrolle
|
||||
menu.Create World=Erschaffe eine Welt
|
||||
menu.missing-content=Fehlender Inhalt!
|
||||
menu.New World=Neue Welt
|
||||
menu.Quit=Ausfahrt
|
||||
menu.Continue=Weitermachen
|
||||
menu.Save and Quit to Menu=Speichern und zum Menü zurückkehren
|
||||
menu.missing-content=Fehlender Inhalt!
|
||||
menu.Content Error=Inhaltsfehler
|
||||
menu.Controls=Kontrolle
|
||||
menu.Back to Main Menu=Zurück zum Menü
|
||||
menu.Settings=Einstellungen
|
||||
menu.Content=Inhalt
|
||||
menu.Audio=Klang
|
||||
|
||||
world.Seed=Mais
|
||||
world.Name=Name
|
||||
|
||||
world.World generator=Weltgenerator
|
||||
world.generators.default=Normal
|
||||
world.generators.flat=Wohnung
|
||||
menu.Create World=Erschaffe eine Welt
|
||||
|
||||
world.Create World=Welt Erschaffen
|
||||
world.convert-request=Es gibt Änderungen in den Indizes! Die Welt bekehren?
|
||||
world.delete-confirm=Die Welt dauerhaft löschen?
|
||||
|
||||
# Настройки
|
||||
settings.Ambient=Hintergrund
|
||||
settings.Backlight=Hintergrundbeleuchtung
|
||||
settings.Camera Shaking=Wackelnde Kamera
|
||||
settings.Fog Curve=Nebelkurve
|
||||
settings.FOV=Sichtlinie
|
||||
settings.Language=Sprache
|
||||
settings.Load Distance=Ladeentfernung
|
||||
settings.Load Speed=Download-Geschwindigkeit
|
||||
settings.Fog Curve=Nebelkurve
|
||||
settings.Backlight=Hintergrundbeleuchtung
|
||||
settings.V-Sync=Vertikale Synchronisation
|
||||
settings.Camera Shaking=Wackelnde Kamera
|
||||
settings.Master Volume=Allgemeine Lautstärke
|
||||
settings.Mouse Sensitivity=Maus-Empfindlichkeit
|
||||
settings.Music=Musik
|
||||
settings.Regular Sounds=Normale Geräusche
|
||||
settings.UI Sounds=Interface-Sounds
|
||||
settings.Ambient=Hintergrund
|
||||
settings.Music=Musik
|
||||
|
||||
settings.FOV=Sichtlinie
|
||||
settings.Mouse Sensitivity=Maus-Empfindlichkeit
|
||||
settings.Language=Sprache
|
||||
settings.V-Sync=Vertikale Synchronisation
|
||||
|
||||
# Управление
|
||||
movement.forward=Vorwärts
|
||||
|
||||
@ -5,38 +5,53 @@ Ok=OK
|
||||
Cancel=Anulowanie
|
||||
Back=Powrót
|
||||
Continue=Kontynuacja
|
||||
Add=Dodać
|
||||
Converting world...=Konwersja świata w toku...
|
||||
|
||||
error.pack-not-found=Nie udało się znaleźć pakietu
|
||||
|
||||
# Menu
|
||||
menu.New World=Nowy Świat
|
||||
menu.Quit=Wyjście
|
||||
menu.Continue=Kontynuacja
|
||||
menu.Save and Quit to Menu=Zapisz i wyjdź do menu
|
||||
menu.missing-content=Brak treści!
|
||||
menu.Controls=Zarządzanie
|
||||
menu.Apply=Zastosować
|
||||
menu.Audio=Dźwięki
|
||||
menu.Back to Main Menu=Powrót do menu
|
||||
menu.Settings=Ustawienia
|
||||
menu.Content=Treść
|
||||
menu.Continue=Kontynuacja
|
||||
menu.Controls=Zarządzanie
|
||||
menu.Graphics=Grafika
|
||||
menu.Create World=Stwórz świat
|
||||
menu.missing-content=Brakująca treść!
|
||||
menu.New World=Nowy Świat
|
||||
menu.Page not found=Strona nie znaleziona
|
||||
menu.Quit=Wyjście
|
||||
menu.Save and Quit to Menu=Zapisz i wyjdź do menu
|
||||
menu.Settings=Ustawienia
|
||||
|
||||
world.Seed=Ziarno
|
||||
world.Name=Nazwa
|
||||
menu.Create World=Stwórz świat
|
||||
|
||||
world.World generator=Generator światła
|
||||
world.generators.default=Ekstremalne
|
||||
world.generators.flat=Mieszkanie
|
||||
world.Create World=Stwórz świat
|
||||
world.convert-request=Szykują się zmiany w indeksach! Przekształcić świat?
|
||||
world.delete-confirm=Trwale usunąć świat?
|
||||
|
||||
# Ustawienia
|
||||
settings.Ambient=Tło
|
||||
settings.Backlight=Podświetlenie
|
||||
settings.Camera Shaking=Drżąca kamera
|
||||
settings.Fog Curve=Krzywa mgły
|
||||
settings.FOV=Wzrok
|
||||
settings.Fullscreen=Pełny ekran
|
||||
settings.Gamma=Gamma
|
||||
settings.Language=Język
|
||||
settings.Load Distance=Odległość ładowania
|
||||
settings.Load Speed=Prędkość pobierania
|
||||
settings.Fog Curve=Krzywa mgły
|
||||
settings.Backlight=Podświetlenie
|
||||
settings.V-Sync=Synchronizacja pionowa
|
||||
|
||||
settings.FOV=Wzrok
|
||||
settings.Master Volume=Głośność główna
|
||||
settings.Mouse Sensitivity=Wrażliwość myszy
|
||||
settings.Language=Język
|
||||
settings.Music=Muzyka
|
||||
settings.Regular Sounds=Normalne dźwięki
|
||||
settings.UI Sounds=Dźwięki interfejsu
|
||||
settings.V-Sync=Synchronizacja pionowa
|
||||
|
||||
# Zarządzanie
|
||||
movement.forward=Naprzód
|
||||
|
||||
@ -13,48 +13,47 @@ error.dependency-not-found=Используемая зависимость не
|
||||
pack.remove-confirm=Удалить весь поставляемый паком/паками контент из мира (безвозвратно)?
|
||||
|
||||
# Меню
|
||||
menu.New World=Новый Мир
|
||||
menu.Quit=Выход
|
||||
menu.Continue=Продолжить
|
||||
menu.Save and Quit to Menu=Сохранить и Выйти в Меню
|
||||
menu.missing-content=Отсутствует Контент!
|
||||
menu.Page does not exists=Страница не существует
|
||||
menu.Apply=Применить
|
||||
menu.Audio=Звук
|
||||
menu.Back to Main Menu=Вернуться в Меню
|
||||
menu.Content Error=Ошибка Контента
|
||||
menu.Content=Контент
|
||||
menu.Continue=Продолжить
|
||||
menu.Controls=Управление
|
||||
menu.Graphics=Графика
|
||||
menu.Back to Main Menu=Вернуться в Меню
|
||||
menu.missing-content=Отсутствует Контент!
|
||||
menu.New World=Новый Мир
|
||||
menu.Page not found=Страница не найдена
|
||||
menu.Quit=Выход
|
||||
menu.Save and Quit to Menu=Сохранить и Выйти в Меню
|
||||
menu.Settings=Настройки
|
||||
menu.Content=Контент
|
||||
menu.Audio=Звук
|
||||
|
||||
world.Seed=Зерно
|
||||
world.Name=Название
|
||||
|
||||
world.World generator=Генератор мира
|
||||
world.generators.default=Обычный
|
||||
world.generators.flat=Плоский
|
||||
world.Create World=Создать Мир
|
||||
|
||||
world.convert-request=Есть изменения в индексах! Конвертировать мир?
|
||||
world.delete-confirm=Удалить мир безвозвратно?
|
||||
|
||||
# Настройки
|
||||
settings.Ambient=Фон
|
||||
settings.Backlight=Подсветка
|
||||
settings.Camera Shaking=Тряска Камеры
|
||||
settings.Fog Curve=Кривая Тумана
|
||||
settings.FOV=Поле Зрения
|
||||
settings.Fullscreen=Полный экран
|
||||
settings.Gamma=Гамма
|
||||
settings.Language=Язык
|
||||
settings.Load Distance=Дистанция Загрузки
|
||||
settings.Load Speed=Скорость Загрузки
|
||||
settings.Fog Curve=Кривая Тумана
|
||||
settings.Backlight=Подсветка
|
||||
settings.Gamma=Гамма
|
||||
settings.Fullscreen=Полноэкранный
|
||||
settings.V-Sync=Вертикальная Синхронизация
|
||||
settings.Camera Shaking=Тряска Камеры
|
||||
settings.Master Volume=Общая Громкость
|
||||
settings.Mouse Sensitivity=Чувствительность Мыши
|
||||
settings.Music=Музыка
|
||||
settings.Regular Sounds=Обычные Звуки
|
||||
settings.UI Sounds=Звуки Интерфейса
|
||||
settings.Ambient=Фон
|
||||
settings.Music=Музыка
|
||||
|
||||
settings.FOV=Поле Зрения
|
||||
settings.Mouse Sensitivity=Чувствительность Мыши
|
||||
settings.Language=Язык
|
||||
settings.V-Sync=Вертикальная Синхронизация
|
||||
|
||||
# Управление
|
||||
movement.forward=Вперёд
|
||||
|
||||
@ -5,19 +5,26 @@ Ok=Гаразд
|
||||
Cancel=Скасувати
|
||||
Back=Назад
|
||||
Continue=Продовжити
|
||||
Add=Додати
|
||||
Converting world...=Виконується конвертація світу...
|
||||
|
||||
error.pack-not-found=Не вдалося знайти пакет
|
||||
|
||||
# Меню
|
||||
menu.New World=Новий Світ
|
||||
menu.Quit=Вихід
|
||||
menu.Continue=Продовжити
|
||||
menu.Save and Quit to Menu=Зберегти і Вийти в Меню
|
||||
menu.missing-content=Відсутній Контент!
|
||||
menu.Controls=Керування
|
||||
menu.Apply=Застосувати
|
||||
menu.Audio=Звук
|
||||
menu.Back to Main Menu=Повернутися до Меню
|
||||
menu.Settings=Налаштування
|
||||
menu.Content Error=Помилка Контенту
|
||||
menu.Content=Контент
|
||||
menu.Continue=Продовжити
|
||||
menu.Controls=Керування
|
||||
menu.Graphics=Графіка
|
||||
menu.missing-content=Відсутній Контент!
|
||||
menu.New World=Новий Світ
|
||||
menu.Page not found=Сторінка не знайдена
|
||||
menu.Quit=Вихід
|
||||
menu.Save and Quit to Menu=Зберегти і Вийти в Меню
|
||||
menu.Settings=Налаштування
|
||||
world.Seed=Зерно
|
||||
world.Name=Назва
|
||||
menu.Create World=Створити Світ
|
||||
@ -28,15 +35,22 @@ world.generators.flat=Плоскі
|
||||
world.convert-request=Є зміни в індексах! Конвертувати світ?
|
||||
|
||||
# Налаштування
|
||||
settings.Ambient=Фон
|
||||
settings.Backlight=Підсвічування
|
||||
settings.Camera Shaking=Тряска Камери
|
||||
settings.Fog Curve=Крива Туману
|
||||
settings.FOV=Поле зору
|
||||
settings.Fullscreen=Повний екран
|
||||
settings.Gamma=Гамма
|
||||
settings.Language=Мова
|
||||
settings.Load Distance=Дистанція Завантаження
|
||||
settings.Load Speed=Швидкість Завантаження
|
||||
settings.Fog Curve=Крива Туману
|
||||
settings.Backlight=Підсвічування
|
||||
settings.V-Sync=Вертикальна Синхронізація
|
||||
|
||||
settings.FOV=Поле зору
|
||||
settings.Master Volume=Загальна Гучність
|
||||
settings.Mouse Sensitivity=Чутливість Миші
|
||||
settings.Language=Мова
|
||||
settings.Music=Музика
|
||||
settings.Regular Sounds=Звичайні Звуки
|
||||
settings.UI Sounds=Звуки інтерфейсу
|
||||
settings.V-Sync=Вертикальна Синхронізація
|
||||
|
||||
# Керування
|
||||
movement.forward=Уперед
|
||||
|
||||
BIN
res/textures/gui/circle.png
Normal file
BIN
res/textures/gui/circle.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.6 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 5.7 KiB |
BIN
res/textures/gui/refresh.png
Normal file
BIN
res/textures/gui/refresh.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.6 KiB |
@ -184,6 +184,7 @@ void AssetsLoader::addDefaults(AssetsLoader& loader, const Content* content) {
|
||||
loader.add(AssetType::texture, TEXTURES_FOLDER+"/gui/warning", "gui/warning");
|
||||
loader.add(AssetType::texture, TEXTURES_FOLDER+"/gui/error", "gui/error");
|
||||
loader.add(AssetType::texture, TEXTURES_FOLDER+"/gui/cross", "gui/cross");
|
||||
loader.add(AssetType::texture, TEXTURES_FOLDER+"/gui/refresh", "gui/refresh");
|
||||
if (content) {
|
||||
loader.processPreloadConfigs(content);
|
||||
|
||||
|
||||
@ -203,6 +203,9 @@ void Hud::processInput(bool visible) {
|
||||
setPause(true);
|
||||
}
|
||||
}
|
||||
if (!Window::isFocused() && !pause && !isInventoryOpen()) {
|
||||
setPause(true);
|
||||
}
|
||||
|
||||
if (!pause && visible && Events::jactive(BIND_HUD_INVENTORY)) {
|
||||
if (inventoryOpen) {
|
||||
|
||||
@ -125,6 +125,14 @@ void Container::remove(std::shared_ptr<UINode> selected) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
void Container::clear() {
|
||||
for (auto node : nodes) {
|
||||
node->setParent(nullptr);
|
||||
}
|
||||
nodes.clear();
|
||||
refresh();
|
||||
}
|
||||
|
||||
void Container::listenInterval(float interval, ontimeout callback, int repeat) {
|
||||
intervalEvents.push_back({callback, interval, 0.0f, repeat});
|
||||
}
|
||||
|
||||
@ -24,6 +24,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(std::shared_ptr<UINode> node, glm::vec2 pos);
|
||||
virtual void clear();
|
||||
virtual void remove(std::shared_ptr<UINode> node);
|
||||
virtual void scrolled(int value) override;
|
||||
virtual void setScrollable(bool flag);
|
||||
|
||||
@ -22,9 +22,13 @@ void Image::draw(const DrawContext* pctx, Assets* assets) {
|
||||
setSize(glm::vec2(texture->getWidth(), texture->getHeight()));
|
||||
}
|
||||
batch->texture(texture);
|
||||
batch->setColor(color);
|
||||
if (enabled) {
|
||||
batch->setColor(isPressed() ? pressedColor : (hover ? hoverColor : color));
|
||||
} else {
|
||||
batch->setColor({color.r, color.g, color.b, color.a * 0.5f});
|
||||
}
|
||||
batch->rect(pos.x, pos.y, size.x, size.y,
|
||||
0, 0, 0, UVRegion(), false, true, color);
|
||||
0, 0, 0, UVRegion(), false, true, batch->getColor());
|
||||
}
|
||||
|
||||
void Image::setAutoResize(bool flag) {
|
||||
|
||||
@ -52,6 +52,10 @@ void Panel::add(std::shared_ptr<UINode> node) {
|
||||
|
||||
void Panel::refresh() {
|
||||
UINode::refresh();
|
||||
std::stable_sort(nodes.begin(), nodes.end(), [](auto a, auto b) {
|
||||
return a->getZIndex() < b->getZIndex();
|
||||
});
|
||||
|
||||
float x = padding.x;
|
||||
float y = padding.y;
|
||||
glm::vec2 size = getSize();
|
||||
|
||||
@ -198,7 +198,18 @@ int UINode::getZIndex() const {
|
||||
return zindex;
|
||||
}
|
||||
|
||||
void UINode::lock() {
|
||||
void UINode::moveInto(
|
||||
std::shared_ptr<UINode> node,
|
||||
std::shared_ptr<Container> dest
|
||||
) {
|
||||
auto parent = node->getParent();
|
||||
if (auto container = dynamic_cast<Container*>(parent)) {
|
||||
container->remove(node);
|
||||
}
|
||||
if (parent) {
|
||||
parent->scrolled(0);
|
||||
}
|
||||
dest->add(node);
|
||||
}
|
||||
|
||||
vec2supplier UINode::getPositionFunc() const {
|
||||
|
||||
@ -17,6 +17,7 @@ class Assets;
|
||||
namespace gui {
|
||||
class UINode;
|
||||
class GUI;
|
||||
class Container;
|
||||
|
||||
using onaction = std::function<void(GUI*)>;
|
||||
using onnumberchange = std::function<void(GUI*, double)>;
|
||||
@ -188,7 +189,10 @@ namespace gui {
|
||||
parent->fullRefresh();
|
||||
}
|
||||
};
|
||||
virtual void lock();
|
||||
static void moveInto(
|
||||
std::shared_ptr<UINode> node,
|
||||
std::shared_ptr<Container> dest
|
||||
);
|
||||
|
||||
virtual vec2supplier getPositionFunc() const;
|
||||
virtual void setPositionFunc(vec2supplier);
|
||||
|
||||
@ -217,8 +217,9 @@ void EngineController::reopenWorld(World* world) {
|
||||
openWorld(wname, true);
|
||||
}
|
||||
|
||||
void EngineController::removePacks(
|
||||
void EngineController::reconfigPacks(
|
||||
LevelController* controller,
|
||||
std::vector<std::string> packsToAdd,
|
||||
std::vector<std::string> packsToRemove
|
||||
) {
|
||||
auto content = engine->getContent();
|
||||
@ -242,6 +243,9 @@ void EngineController::removePacks(
|
||||
manager.scan();
|
||||
|
||||
auto names = PacksManager::getNames(world->getPacks());
|
||||
for (const auto& id : packsToAdd) {
|
||||
names.push_back(id);
|
||||
}
|
||||
for (const auto& id : packsToRemove) {
|
||||
manager.exclude(id);
|
||||
names.erase(std::find(names.begin(), names.end(), id));
|
||||
@ -262,31 +266,3 @@ void EngineController::removePacks(
|
||||
removeFunc();
|
||||
}
|
||||
}
|
||||
|
||||
void EngineController::addPacks(
|
||||
LevelController* controller,
|
||||
std::vector<std::string> packs
|
||||
) {
|
||||
auto level = controller->getLevel();
|
||||
auto gui = engine->getGUI();
|
||||
auto world = level->getWorld();
|
||||
auto new_packs = PacksManager::getNames(world->getPacks());
|
||||
for (auto& id : packs) {
|
||||
new_packs.push_back(id);
|
||||
}
|
||||
|
||||
auto manager = engine->createPacksManager(world->wfile->getFolder());
|
||||
manager.scan();
|
||||
try {
|
||||
new_packs = manager.assembly(new_packs);
|
||||
} catch (const contentpack_error& err) {
|
||||
guiutil::alert(
|
||||
gui, langs::get(L"error.dependency-not-found")+
|
||||
L": "+util::str2wstr_utf8(err.getPackId())
|
||||
);
|
||||
return;
|
||||
}
|
||||
world->wfile->writePacks(manager.getAll(new_packs));
|
||||
controller->saveWorld();
|
||||
reopenWorld(world);
|
||||
}
|
||||
|
||||
@ -22,14 +22,10 @@ public:
|
||||
/// @param name world name
|
||||
void deleteWorld(std::string name);
|
||||
|
||||
void removePacks(
|
||||
void reconfigPacks(
|
||||
LevelController* controller,
|
||||
std::vector<std::string> packs
|
||||
);
|
||||
|
||||
void addPacks(
|
||||
LevelController* controller,
|
||||
std::vector<std::string> packs
|
||||
std::vector<std::string> packsToAdd,
|
||||
std::vector<std::string> packsToRemove
|
||||
);
|
||||
|
||||
void createWorld(
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
#include "../../../frontend/screens/MenuScreen.hpp"
|
||||
#include "../../../logic/LevelController.h"
|
||||
#include "../../../logic/EngineController.hpp"
|
||||
#include "../../../world/Level.h"
|
||||
#include "../../../window/Events.h"
|
||||
#include "../../../window/Window.h"
|
||||
#include "../../../world/WorldGenerators.h"
|
||||
@ -37,6 +38,12 @@ static int l_open_world(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_reopen_world(lua_State* L) {
|
||||
auto controller = scripting::engine->getController();
|
||||
controller->reopenWorld(scripting::level->getWorld());
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_close_world(lua_State* L) {
|
||||
if (scripting::controller == nullptr) {
|
||||
luaL_error(L, "no world open");
|
||||
@ -59,35 +66,30 @@ static int l_delete_world(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_remove_packs(lua_State* L) {
|
||||
static int l_reconfig_packs(lua_State* L) {
|
||||
if (!lua_istable(L, 1)) {
|
||||
luaL_error(L, "strings array expected as an argument");
|
||||
luaL_error(L, "strings array expected as the first argument");
|
||||
}
|
||||
std::vector<std::string> packs;
|
||||
int len = lua_objlen(L, 1);
|
||||
for (int i = 0; i < len; i++) {
|
||||
lua_rawgeti(L, -1, i+1);
|
||||
packs.push_back(lua_tostring(L, -1));
|
||||
if (!lua_istable(L, 2)) {
|
||||
luaL_error(L, "strings array expected as the second argument");
|
||||
}
|
||||
std::vector<std::string> addPacks;
|
||||
int addLen = lua_objlen(L, 1);
|
||||
for (int i = 0; i < addLen; i++) {
|
||||
lua_rawgeti(L, 1, i+1);
|
||||
addPacks.push_back(lua_tostring(L, -1));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
auto controller = scripting::engine->getController();
|
||||
controller->removePacks(scripting::controller, packs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_add_packs(lua_State* L) {
|
||||
if (!lua_istable(L, 1)) {
|
||||
luaL_error(L, "strings array expected as an argument");
|
||||
}
|
||||
std::vector<std::string> packs;
|
||||
int len = lua_objlen(L, 1);
|
||||
for (int i = 0; i < len; i++) {
|
||||
lua_rawgeti(L, -1, i+1);
|
||||
packs.push_back(lua_tostring(L, -1));
|
||||
std::vector<std::string> remPacks;
|
||||
int remLen = lua_objlen(L, 2);
|
||||
for (int i = 0; i < remLen; i++) {
|
||||
lua_rawgeti(L, 2, i+1);
|
||||
remPacks.push_back(lua_tostring(L, -1));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
auto controller = scripting::engine->getController();
|
||||
controller->addPacks(scripting::controller, packs);
|
||||
controller->reconfigPacks(scripting::controller, addPacks, remPacks);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -174,10 +176,10 @@ static int l_get_generators(lua_State* L) {
|
||||
const luaL_Reg corelib [] = {
|
||||
{"new_world", lua_wrap_errors<l_new_world>},
|
||||
{"open_world", lua_wrap_errors<l_open_world>},
|
||||
{"reopen_world", lua_wrap_errors<l_reopen_world>},
|
||||
{"close_world", lua_wrap_errors<l_close_world>},
|
||||
{"delete_world", lua_wrap_errors<l_delete_world>},
|
||||
{"add_packs", lua_wrap_errors<l_add_packs>},
|
||||
{"remove_packs", lua_wrap_errors<l_remove_packs>},
|
||||
{"reconfig_packs", lua_wrap_errors<l_reconfig_packs>},
|
||||
{"get_bindings", lua_wrap_errors<l_get_bindings>},
|
||||
{"get_setting", lua_wrap_errors<l_get_setting>},
|
||||
{"set_setting", lua_wrap_errors<l_set_setting>},
|
||||
|
||||
@ -27,7 +27,7 @@ using namespace gui;
|
||||
|
||||
struct DocumentNode {
|
||||
UiDocument* document;
|
||||
UINode* node;
|
||||
std::shared_ptr<UINode> node;
|
||||
};
|
||||
|
||||
static DocumentNode getDocumentNode(lua_State* L, const std::string& name, const std::string& nodeName) {
|
||||
@ -39,7 +39,7 @@ static DocumentNode getDocumentNode(lua_State* L, const std::string& name, const
|
||||
if (node == nullptr) {
|
||||
luaL_error(L, "document '%s' has no element with id '%s'", name.c_str(), nodeName.c_str());
|
||||
}
|
||||
return {doc, node.get()};
|
||||
return {doc, node};
|
||||
}
|
||||
|
||||
static bool getattr(lua_State* L, TrackBar* bar, const std::string& attr) {
|
||||
@ -137,9 +137,9 @@ static bool getattr(lua_State* L, TextBox* box, const std::string& attr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static DocumentNode getDocumentNode(lua_State* L) {
|
||||
lua_getfield(L, 1, "docname");
|
||||
lua_getfield(L, 1, "name");
|
||||
static DocumentNode getDocumentNode(lua_State* L, int idx=1) {
|
||||
lua_getfield(L, idx, "docname");
|
||||
lua_getfield(L, idx, "name");
|
||||
auto docname = lua_tostring(L, -2);
|
||||
auto name = lua_tostring(L, -1);
|
||||
auto node = getDocumentNode(L, docname, name);
|
||||
@ -149,14 +149,14 @@ static DocumentNode getDocumentNode(lua_State* L) {
|
||||
|
||||
static int menu_back(lua_State* L) {
|
||||
auto node = getDocumentNode(L);
|
||||
auto menu = dynamic_cast<Menu*>(node.node);
|
||||
auto menu = dynamic_cast<Menu*>(node.node.get());
|
||||
menu->back();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int menu_reset(lua_State* L) {
|
||||
auto node = getDocumentNode(L);
|
||||
auto menu = dynamic_cast<Menu*>(node.node);
|
||||
auto menu = dynamic_cast<Menu*>(node.node.get());
|
||||
menu->reset();
|
||||
return 0;
|
||||
}
|
||||
@ -249,7 +249,7 @@ static bool setattr(lua_State* L, InventoryView* view, const std::string& attr)
|
||||
|
||||
static int container_add(lua_State* L) {
|
||||
auto docnode = getDocumentNode(L);
|
||||
auto node = dynamic_cast<Container*>(docnode.node);
|
||||
auto node = dynamic_cast<Container*>(docnode.node.get());
|
||||
auto xmlsrc = lua_tostring(L, 2);
|
||||
try {
|
||||
auto subnode = guiutil::create(xmlsrc, docnode.document->getEnvironment());
|
||||
@ -261,6 +261,14 @@ static int container_add(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int container_clear(lua_State* L) {
|
||||
auto node = getDocumentNode(L, 1);
|
||||
if (auto container = std::dynamic_pointer_cast<Container>(node.node)) {
|
||||
container->clear();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool getattr(lua_State* L, Container* container, const std::string& attr) {
|
||||
if (container == nullptr)
|
||||
return false;
|
||||
@ -268,6 +276,9 @@ static bool getattr(lua_State* L, Container* container, const std::string& attr)
|
||||
if (attr == "add") {
|
||||
lua_pushcfunction(L, container_add);
|
||||
return true;
|
||||
} else if (attr == "clear") {
|
||||
lua_pushcfunction(L, container_clear);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -283,6 +294,13 @@ static bool getattr(lua_State* L, InventoryView* inventory, const std::string& a
|
||||
return false;
|
||||
}
|
||||
|
||||
static int uinode_move_into(lua_State* L) {
|
||||
auto node = getDocumentNode(L, 1);
|
||||
auto dest = getDocumentNode(L, 2);
|
||||
UINode::moveInto(node.node, std::dynamic_pointer_cast<Container>(dest.node));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_gui_getattr(lua_State* L) {
|
||||
auto docname = lua_tostring(L, 1);
|
||||
auto element = lua_tostring(L, 2);
|
||||
@ -307,23 +325,26 @@ static int l_gui_getattr(lua_State* L) {
|
||||
} else if (attr == "enabled") {
|
||||
lua_pushboolean(L, node->isEnabled());
|
||||
return 1;
|
||||
} else if (attr == "move_into") {
|
||||
lua_pushcfunction(L, uinode_move_into);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (getattr(L, dynamic_cast<Container*>(node), attr))
|
||||
if (getattr(L, dynamic_cast<Container*>(node.get()), attr))
|
||||
return 1;
|
||||
if (getattr(L, dynamic_cast<Button*>(node), attr))
|
||||
if (getattr(L, dynamic_cast<Button*>(node.get()), attr))
|
||||
return 1;
|
||||
if (getattr(L, dynamic_cast<Label*>(node), attr))
|
||||
if (getattr(L, dynamic_cast<Label*>(node.get()), attr))
|
||||
return 1;
|
||||
if (getattr(L, dynamic_cast<TextBox*>(node), attr))
|
||||
if (getattr(L, dynamic_cast<TextBox*>(node.get()), attr))
|
||||
return 1;
|
||||
if (getattr(L, dynamic_cast<TrackBar*>(node), attr))
|
||||
if (getattr(L, dynamic_cast<TrackBar*>(node.get()), attr))
|
||||
return 1;
|
||||
if (getattr(L, dynamic_cast<FullCheckBox*>(node), attr))
|
||||
if (getattr(L, dynamic_cast<FullCheckBox*>(node.get()), attr))
|
||||
return 1;
|
||||
if (getattr(L, dynamic_cast<Menu*>(node), attr))
|
||||
if (getattr(L, dynamic_cast<Menu*>(node.get()), attr))
|
||||
return 1;
|
||||
if (getattr(L, dynamic_cast<InventoryView*>(node), attr))
|
||||
if (getattr(L, dynamic_cast<InventoryView*>(node.get()), attr))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
@ -356,19 +377,19 @@ static int l_gui_setattr(lua_State* L) {
|
||||
} else if (attr == "enabled") {
|
||||
node->setEnabled(lua_toboolean(L, 4));
|
||||
} else {
|
||||
if (setattr(L, dynamic_cast<Button*>(node), attr))
|
||||
if (setattr(L, dynamic_cast<Button*>(node.get()), attr))
|
||||
return 0;
|
||||
if (setattr(L, dynamic_cast<Label*>(node), attr))
|
||||
if (setattr(L, dynamic_cast<Label*>(node.get()), attr))
|
||||
return 0;
|
||||
if (setattr(L, dynamic_cast<TextBox*>(node), attr))
|
||||
if (setattr(L, dynamic_cast<TextBox*>(node.get()), attr))
|
||||
return 0;
|
||||
if (setattr(L, dynamic_cast<TrackBar*>(node), attr))
|
||||
if (setattr(L, dynamic_cast<TrackBar*>(node.get()), attr))
|
||||
return 0;
|
||||
if (setattr(L, dynamic_cast<FullCheckBox*>(node), attr))
|
||||
if (setattr(L, dynamic_cast<FullCheckBox*>(node.get()), attr))
|
||||
return 0;
|
||||
if (setattr(L, dynamic_cast<Menu*>(node), attr))
|
||||
if (setattr(L, dynamic_cast<Menu*>(node.get()), attr))
|
||||
return 0;
|
||||
if (setattr(L, dynamic_cast<InventoryView*>(node), attr))
|
||||
if (setattr(L, dynamic_cast<InventoryView*>(node.get()), attr))
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
|
||||
@ -61,7 +61,7 @@ struct GraphicsSettings {
|
||||
/// @brief Enable blocks backlight to prevent complete darkness
|
||||
FlagSetting backlight {true};
|
||||
/// @brief Enable chunks frustum culling
|
||||
FlagSetting frustumCulling {true}; // redutant?
|
||||
FlagSetting frustumCulling {true};
|
||||
IntegerSetting skyboxResolution {64 + 32, 64, 128};
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user