mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-09-08 19:50:23 -04:00
Sort the creative inventory:
Item groups like glass and crystals are now at the bottom. Items at the top are now sorted. Fixes #341
This commit is contained in:
parent
3419034754
commit
a575edae45
@ -33,12 +33,26 @@ pub fn trySwappingItems(index: usize, destination: *ItemStack) void {
|
|||||||
destination.amount = destination.item.?.stackSize();
|
destination.amount = destination.item.?.stackSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn lessThan(_: void, lhs: Item, rhs: Item) bool {
|
||||||
|
if(lhs == .baseItem and rhs == .baseItem) {
|
||||||
|
const lhsFolders = std.mem.count(u8, lhs.baseItem.id, "/");
|
||||||
|
const rhsFolders = std.mem.count(u8, rhs.baseItem.id, "/");
|
||||||
|
if(lhsFolders < rhsFolders) return true;
|
||||||
|
if(lhsFolders > rhsFolders) return false;
|
||||||
|
return std.ascii.lessThanIgnoreCase(lhs.baseItem.id, rhs.baseItem.id);
|
||||||
|
} else {
|
||||||
|
if(lhs == .baseItem) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn onOpen() void {
|
pub fn onOpen() void {
|
||||||
items = main.List(Item).init(main.globalAllocator);
|
items = main.List(Item).init(main.globalAllocator);
|
||||||
var itemIterator = main.items.iterator();
|
var itemIterator = main.items.iterator();
|
||||||
while(itemIterator.next()) |item| {
|
while(itemIterator.next()) |item| {
|
||||||
items.append(Item{.baseItem = item.*});
|
items.append(Item{.baseItem = item.*});
|
||||||
}
|
}
|
||||||
|
std.mem.sort(Item, items.items, {}, lessThan);
|
||||||
|
|
||||||
const list = VerticalList.init(.{padding, padding + 16}, 140, 0);
|
const list = VerticalList.init(.{padding, padding + 16}, 140, 0);
|
||||||
var i: u32 = 0;
|
var i: u32 = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user