Some small UI improvements

Fixes #245
Fixes #262
Fixes #284
Fixes #285
This commit is contained in:
IntegratedQuantum 2024-03-24 20:00:21 +01:00
parent 16f0e4d37f
commit b6cffba122
3 changed files with 8 additions and 5 deletions

View File

@ -326,7 +326,7 @@ pub fn update(self: *GuiWindow) void {
pub fn updateSelected(self: *GuiWindow, mousePosition: Vec2f) void {
self.updateSelectedFn();
const windowSize = main.Window.getWindowSize()/@as(Vec2f, @splat(gui.scale));
if(self == grabbedWindow) if(grabPosition) |_grabPosition| {
if(self == grabbedWindow and self.titleBarExpanded) if(grabPosition) |_grabPosition| {
self.relativePosition[0] = .{.ratio = undefined};
self.relativePosition[1] = .{.ratio = undefined};
self.pos = (mousePosition - _grabPosition) + selfPositionWhenGrabbed;
@ -496,7 +496,7 @@ pub fn render(self: *const GuiWindow, mousePosition: Vec2f) void {
}
draw.restoreTranslation(oldTranslation);
draw.restoreScale(oldScale);
if(self == grabbedWindow and grabPosition != null) {
if(self == grabbedWindow and self.titleBarExpanded and grabPosition != null) {
self.drawOrientationLines();
}
}

View File

@ -453,7 +453,7 @@ pub fn mainButtonPressed() void {
_selectedWindow.mainButtonPressed(mousePosition);
_ = openWindows.orderedRemove(selectedI);
openWindows.appendAssumeCapacity(_selectedWindow);
} else if(main.game.world != null) {
} else if(main.game.world != null and inventory.carriedItemSlot.itemStack.item == null) {
main.Window.setMouseGrabbed(true);
}
}

View File

@ -25,7 +25,10 @@ const padding: f32 = 8;
var items: main.List(Item) = undefined;
pub fn tryTakingItems(index: usize, destination: *ItemStack, _: u16) void {
if(destination.item != null and !std.meta.eql(destination.item.?, items.items[index])) return;
trySwappingItems(index, destination);
}
pub fn trySwappingItems(index: usize, destination: *ItemStack) void {
destination.clear(); // Always replace the destination.
destination.item = items.items[index];
destination.amount = destination.item.?.stackSize();
}
@ -44,7 +47,7 @@ pub fn onOpen() void {
for(0..8) |_| {
if(i >= items.items.len) break;
const item = items.items[i];
row.add(ItemSlot.init(.{0, 0}, .{.item = item, .amount = 1}, &.{.tryTakingItems = &tryTakingItems}, i, .default, .takeOnly));
row.add(ItemSlot.init(.{0, 0}, .{.item = item, .amount = 1}, &.{.tryTakingItems = &tryTakingItems, .trySwappingItems = &trySwappingItems}, i, .default, .takeOnly));
i += 1;
}
list.add(row);