mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-28 13:36:00 +00:00
Harden auction display and trader stock init
This commit is contained in:
1 parent
77c8e418eb
commit
d657bab73c
11 files changed
+148
-41
No files matched your search
@@ -215,6 +215,9 @@ public class GuiAuction extends GuiContainerNPCInterface implements IGuiData,
|
||||
private void viewDetails() {
|
||||
if (selectedListingIndex >= 0 && selectedListingIndex < listings.size()) {
|
||||
AuctionListing listing = listings.get(selectedListingIndex);
|
||||
if (listing.item == null) {
|
||||
return;
|
||||
}
|
||||
setSubGui(new SubGuiAuctionDetails(this, listing));
|
||||
}
|
||||
}
|
||||
@@ -222,6 +225,9 @@ public class GuiAuction extends GuiContainerNPCInterface implements IGuiData,
|
||||
private void placeBid() {
|
||||
if (selectedListingIndex >= 0 && selectedListingIndex < listings.size()) {
|
||||
AuctionListing listing = listings.get(selectedListingIndex);
|
||||
if (listing.item == null) {
|
||||
return;
|
||||
}
|
||||
setSubGui(new SubGuiAuctionBid(this, listing, playerBalance));
|
||||
}
|
||||
}
|
||||
@@ -261,7 +267,7 @@ public class GuiAuction extends GuiContainerNPCInterface implements IGuiData,
|
||||
String line = formatListingLine(listing);
|
||||
displayList.add(line);
|
||||
}
|
||||
listingScroll.setList(displayList);
|
||||
listingScroll.setList(displayList, true, false);
|
||||
|
||||
if (selectedListingIndex >= 0 && selectedListingIndex < displayList.size()) {
|
||||
listingScroll.selected = selectedListingIndex;
|
||||
@@ -269,7 +275,9 @@ public class GuiAuction extends GuiContainerNPCInterface implements IGuiData,
|
||||
}
|
||||
|
||||
private String formatListingLine(AuctionListing listing) {
|
||||
String itemName = listing.item.getDisplayName();
|
||||
String itemName = listing.item == null
|
||||
? "Unknown"
|
||||
: listing.item.getDisplayName();
|
||||
if (itemName.length() > 15) {
|
||||
itemName = itemName.substring(0, 12) + "...";
|
||||
}
|
||||
@@ -324,12 +332,17 @@ public class GuiAuction extends GuiContainerNPCInterface implements IGuiData,
|
||||
|
||||
// Action buttons based on selection
|
||||
boolean hasSelection = selectedListingIndex >= 0 && selectedListingIndex < listings.size();
|
||||
if (hasSelection && listings.get(selectedListingIndex).item == null) {
|
||||
hasSelection = false;
|
||||
}
|
||||
if (getButton(50) != null) getButton(50).setEnabled(hasSelection);
|
||||
if (getButton(51) != null) getButton(51).setEnabled(hasSelection);
|
||||
|
||||
if (hasSelection && getButton(52) != null) {
|
||||
AuctionListing listing = listings.get(selectedListingIndex);
|
||||
getButton(52).setEnabled(listing.buyoutPrice > 0 && playerBalance >= listing.buyoutPrice);
|
||||
getButton(52).setEnabled(listing.item != null &&
|
||||
listing.buyoutPrice > 0 &&
|
||||
playerBalance >= listing.buyoutPrice);
|
||||
} else if (getButton(52) != null) {
|
||||
getButton(52).setEnabled(false);
|
||||
}
|
||||
@@ -392,18 +405,17 @@ public class GuiAuction extends GuiContainerNPCInterface implements IGuiData,
|
||||
|
||||
// ICustomScrollListener
|
||||
@Override
|
||||
public void scrollClicked(int scrollId, int index, boolean doubleClick, String selection) {
|
||||
public void customScrollClicked(int mouseX, int mouseY, int mouseButton, GuiCustomScroll scroll) {
|
||||
int index = scroll.selected;
|
||||
selectedListingIndex = index;
|
||||
updateButtonStates();
|
||||
|
||||
if (doubleClick && selectedListingIndex >= 0 && selectedListingIndex < listings.size()) {
|
||||
viewDetails();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scrollDoubleClicked(String selection, GuiCustomScroll scroll) {
|
||||
// Handled above
|
||||
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
|
||||
if (selectedListingIndex >= 0 && selectedListingIndex < listings.size()) {
|
||||
viewDetails();
|
||||
}
|
||||
}
|
||||
|
||||
// IGuiData
|
||||
|
||||
@@ -35,6 +35,12 @@ public class SubGuiAuctionBid extends SubGuiInterface {
|
||||
int y = guiTop + 10;
|
||||
int labelColor = 0x404040;
|
||||
|
||||
if (listing.item == null) {
|
||||
addLabel(new GuiNpcLabel(0, StatCollector.translateToLocal("auction.noItemSelected"), guiLeft + 40, y, 0xAA0000));
|
||||
addButton(new GuiNpcButton(31, guiLeft + 60, guiTop + 110, 80, 20, StatCollector.translateToLocal("gui.cancel")));
|
||||
return;
|
||||
}
|
||||
|
||||
// Title
|
||||
addLabel(new GuiNpcLabel(0, StatCollector.translateToLocal("auction.placeBid"), guiLeft + 70, y, labelColor));
|
||||
y += 18;
|
||||
@@ -70,8 +76,9 @@ public class SubGuiAuctionBid extends SubGuiInterface {
|
||||
// Bid input
|
||||
addLabel(new GuiNpcLabel(10, StatCollector.translateToLocal("auction.yourBid"), guiLeft + 15, y + 3, labelColor));
|
||||
bidField = new GuiNpcTextField(11, this, guiLeft + 80, y, 100, 16, String.valueOf(minBid));
|
||||
bidField.setNumbersOnly();
|
||||
bidField.setMinMaxDefault(minBid, 999999999, minBid);
|
||||
bidField.setIntegersOnly();
|
||||
int minBidInt = (int) Math.min(Integer.MAX_VALUE, Math.max(1L, minBid));
|
||||
bidField.setMinMaxDefault(minBidInt, Integer.MAX_VALUE, minBidInt);
|
||||
addTextField(bidField);
|
||||
y += 24;
|
||||
|
||||
@@ -179,7 +186,7 @@ public class SubGuiAuctionBid extends SubGuiInterface {
|
||||
}
|
||||
|
||||
private void placeBid() {
|
||||
long bidAmount = bidField.getInteger();
|
||||
long bidAmount = parseBid(bidField);
|
||||
long minBid = listing.getMinimumBid();
|
||||
|
||||
if (bidAmount < minBid) {
|
||||
@@ -199,6 +206,14 @@ public class SubGuiAuctionBid extends SubGuiInterface {
|
||||
close();
|
||||
}
|
||||
|
||||
private long parseBid(GuiNpcTextField field) {
|
||||
try {
|
||||
return Long.parseLong(field.getText());
|
||||
} catch (NumberFormatException e) {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
// Nothing to save
|
||||
|
||||
@@ -51,14 +51,14 @@ public class SubGuiAuctionCreate extends SubGuiInterface {
|
||||
// Starting price
|
||||
addLabel(new GuiNpcLabel(10, StatCollector.translateToLocal("auction.startingPrice"), guiLeft + 20, guiTop + 70, 0x404040));
|
||||
startingPriceField = new GuiNpcTextField(11, this, guiLeft + 100, guiTop + 68, 80, 14, "100");
|
||||
startingPriceField.setNumbersOnly();
|
||||
startingPriceField.setIntegersOnly();
|
||||
startingPriceField.setMinMaxDefault(1, 999999999, 100);
|
||||
addTextField(startingPriceField);
|
||||
|
||||
// Buyout price (optional)
|
||||
addLabel(new GuiNpcLabel(20, StatCollector.translateToLocal("auction.buyoutPrice"), guiLeft + 20, guiTop + 90, 0x404040));
|
||||
buyoutPriceField = new GuiNpcTextField(21, this, guiLeft + 100, guiTop + 88, 80, 14, "0");
|
||||
buyoutPriceField.setNumbersOnly();
|
||||
buyoutPriceField.setIntegersOnly();
|
||||
buyoutPriceField.setMinMaxDefault(0, 999999999, 0);
|
||||
addTextField(buyoutPriceField);
|
||||
addLabel(new GuiNpcLabel(22, StatCollector.translateToLocal("auction.noBuyoutHint"), guiLeft + 185, guiTop + 90, 0x888888));
|
||||
@@ -87,7 +87,7 @@ public class SubGuiAuctionCreate extends SubGuiInterface {
|
||||
|
||||
private long getListingFee() {
|
||||
EnumAuctionDuration duration = EnumAuctionDuration.values()[selectedDuration];
|
||||
return duration.getFee();
|
||||
return duration.getListingFee();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -113,8 +113,8 @@ public class SubGuiAuctionCreate extends SubGuiInterface {
|
||||
return;
|
||||
}
|
||||
|
||||
long startingPrice = startingPriceField.getInteger();
|
||||
long buyoutPrice = buyoutPriceField.getInteger();
|
||||
long startingPrice = parsePrice(startingPriceField, 1);
|
||||
long buyoutPrice = parsePrice(buyoutPriceField, 0);
|
||||
|
||||
if (startingPrice < 1) {
|
||||
startingPrice = 1;
|
||||
@@ -135,6 +135,14 @@ public class SubGuiAuctionCreate extends SubGuiInterface {
|
||||
close();
|
||||
}
|
||||
|
||||
private long parsePrice(GuiNpcTextField field, long defaultValue) {
|
||||
try {
|
||||
return Long.parseLong(field.getText());
|
||||
} catch (NumberFormatException e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
|
||||
@@ -34,6 +34,12 @@ public class SubGuiAuctionDetails extends SubGuiInterface {
|
||||
int labelColor = 0x404040;
|
||||
int valueColor = 0x000000;
|
||||
|
||||
if (listing.item == null) {
|
||||
addLabel(new GuiNpcLabel(0, StatCollector.translateToLocal("auction.noItemSelected"), guiLeft + 60, y, 0xAA0000));
|
||||
addButton(new GuiNpcButton(50, guiLeft + 80, guiTop + 175, 80, 20, StatCollector.translateToLocal("gui.close")));
|
||||
return;
|
||||
}
|
||||
|
||||
// Title
|
||||
addLabel(new GuiNpcLabel(0, StatCollector.translateToLocal("auction.auctionDetails"), guiLeft + 80, y, labelColor));
|
||||
y += 16;
|
||||
|
||||
Reference in new issue
Block a user