package com.dunerealms.gui; import java.nio.file.*; import java.util.*; import java.util.regex.*; /** Market-shaped presentation. All dynamic content is text; actions live in the server session. */ final class MenuDocument { record Card(int slot,String title,List lore,String material,int amount,boolean action,String quality){} static String clean(String text){return text==null?"":text.replaceAll("[\\p{Co}\\p{Cc}&&[^\\n]]","").replaceAll("(?i)§[0-9a-fk-orx]","").trim();} static String escape(String text){return clean(text).replace("&","&").replace("<","<").replace(">",">").replace("\"",""").replace("'","'");} static String icon(Card card,Path root){ String name=card.title.toLowerCase(Locale.ROOT),semantic=switch(name){case "clan","your clan"->"clan";case "company","your companies"->"company";case "pol","your political offices"->"politics";case "your house"->"house";case "your mentat"->"mentat";case "exchange"->"exchange";case "mission journal","missions & turn-ins"->"quests";case "spacing guild"->"travel";default->"";}; if(!semantic.isEmpty()&&Files.isRegularFile(root.resolve("art/"+semantic+".png")))return "art/"+semantic+".png"; String material=card.material;if(!material.matches("[a-z0-9_]{1,70}"))return "";String relative="art/"+material+".png";return Files.isRegularFile(root.resolve(relative))?relative:""; } static String fact(Card c){for(String line:c.lore){Matcher m=Pattern.compile("[0-9][0-9,.]*\\s*DM").matcher(line);if(m.find())return m.group();}for(String line:c.lore)if(line.matches("(?i).*(progress|claimed|in progress|XP|complete).*"))return line.length()>35?line.substring(0,32)+"…":line;return c.amount>1?"× "+c.amount:c.action?"View →":"Details";} static String html(String title,String description,String player,List cards,int selected,Path root){ String lower=title.toLowerCase(Locale.ROOT),theme=lower.contains("quest")||lower.contains("mission")||lower.contains("research")||lower.contains("gurney")?"quest":"realm"; Card detail=cards.stream().filter(c->c.slot==selected).findFirst().orElse(cards.isEmpty()?null:cards.get(0)); StringBuilder b=new StringBuilder("DuneRealms
CHOAM · IMPERIAL SERVICES

").append(escape(title)).append("

").append(escape(player)).append("
"); if(!clean(description).isBlank())b.append("

").append(escape(description).replace("\n","
")).append("

"); for(int i=0;i
");for(Card c:cards.subList(i,Math.min(i+4,cards.size()))){ String image=icon(c,root);b.append(""); }b.append("
").append(theme.equals("quest")?"MISSIONS · YOUR JOURNEY CONTINUES":"DUNE REALMS · "+escape(title)).append("
");} b.append("
");return b.toString(); } private static final String CSS=""" *{box-sizing:border-box}html,body{margin:0;min-height:100%;font-family:Inter,sans-serif}body{border:3px solid #b69a50;box-shadow:inset 0 0 0 2px #122d1e;position:relative;color:#e9dfc1;--accent:#e1bc65;--edge:#8c743d;--glow:#e5bd5c30;background:radial-gradient(ellipse at 12% 20%,#a2803930,transparent 60%),linear-gradient(180deg,#09251de8,#041711fa),url(art/banner.png) center/cover}.ingame{--accent:#88c5e4;--edge:#477e93;--glow:#4babc330}.ingame .cubby{border-color:#477e93}.awning{height:22px;background:repeating-linear-gradient(90deg,#163d2b 0px,#163d2b 30px,#b69750 30px,#b69750 45px);box-shadow:inset 0 -8px 10px #0006,0 3px 4px #0005;border-bottom:4px solid #8e763f}header{height:91px;display:flex;align-items:center;gap:22px;padding:9px 30px}.logo{width:174px;height:66px;object-fit:contain;filter:drop-shadow(0 4px 8px #0008)}.heading{flex:1}.heading small{color:#aab89a;font-size:9px;letter-spacing:2.6px}h1{font:600 27px 'Source Serif 4',serif;color:#f1d797;margin:4px 0 0;line-height:1.15}.viewer{font-size:11px;color:#b9c6ac;white-space:nowrap}button{font-family:Inter,sans-serif;color:inherit;cursor:pointer}.close{font-family:Minecraft,monospace;background:#061c1688;border:1px solid #8e763f66;border-radius:2px;width:33px;height:33px;font-size:23px;color:#d9c798}.close:hover{background:#744633}main{display:grid;grid-template-columns:300px minmax(0,1fr);gap:22px;padding:0 30px;align-items:start}aside{position:relative;background:linear-gradient(180deg,#153629e8,#061c16f5);border:2px solid var(--edge);border-radius:2px;padding:15px 17px 18px;box-shadow:0 16px 35px #0007;min-height:430px;display:flex;flex-direction:column}aside:before,aside:after{content:"";position:absolute;width:10px;height:10px;border:3px solid #e6c575;pointer-events:none}aside:before{left:3px;top:3px;border-right:0;border-bottom:0}aside:after{right:3px;bottom:3px;border-left:0;border-top:0}.stage{height:140px;border-radius:10px;display:flex;align-items:center;justify-content:center;margin-bottom:13px;background:radial-gradient(circle at 50% 50%,var(--glow),transparent 68%),repeating-conic-gradient(from 0deg at 50% 60%,#dbc07118 0deg 12deg,transparent 12deg 36deg);overflow:hidden}.stage img{width:126px;height:126px;object-fit:contain;image-rendering:pixelated;filter:drop-shadow(0 10px 8px #0009)}.stage span{font-size:80px;color:var(--accent)}h2{font:600 23px 'Source Serif 4',serif;color:var(--accent);margin:0 0 7px;line-height:1.25}.quality{font-size:10px;letter-spacing:2px;margin:0 0 10px;padding:6px 8px;border:1px solid currentColor;border-radius:4px}.lore-box{margin-bottom:12px}.lore{font-size:12px;color:#b8c9b8;line-height:1.45;margin:7px 0;overflow-wrap:break-word}.section-title{font-size:11px;font-weight:600;color:var(--accent);border-top:1px solid #8b794644;padding-top:9px}.primary{margin-top:auto;min-height:41px;width:100%;border:1px solid #d9ba68;border-radius:2px;padding:10px;background:linear-gradient(180deg,#2f8d36,#145324);color:#fff1bd;font-family:Minecraft,monospace;font-weight:600;font-size:15px;box-shadow:inset 0 2px 0 #f6e9a96b,0 3px 0 #5f4e2b}.primary:hover{background:linear-gradient(180deg,#45a643,#20732f)}.shelves{min-width:0}.intro{font-size:11px;color:#b0c0af;line-height:1.45;margin:0 0 10px}.shelf{margin-bottom:14px}.goods{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:12px;align-items:end;padding:0 9px 10px}.slot{display:flex;align-items:center;flex-direction:column;text-align:center;border:0;background:transparent;padding:3px 0;min-width:0}.cubby{height:75px;width:91px;display:flex;align-items:center;justify-content:center;border-radius:2px;border:2px solid #b69c5f66;background:linear-gradient(180deg,#03110eaa,#0b251b88);box-shadow:inset 0 5px 10px #0007}.cubby img{width:60px;height:60px;object-fit:contain;image-rendering:pixelated;filter:drop-shadow(0 4px 4px #0007)}.sigil{font-size:38px;color:var(--accent)}.slot:hover .cubby,.slot.selected .cubby{border-color:var(--accent);box-shadow:0 0 14px var(--glow),inset 0 0 20px var(--glow)}.slot strong{font-size:11px;line-height:1.25;color:#dfd0a7;margin:6px 0;max-height:29px;overflow:hidden}.tag{font:10px Minecraft,monospace;background:#e5d3a5;color:#282317;border-radius:4px;padding:4px 6px;box-shadow:0 2px 0 #7f6c3b;max-width:100%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.board{height:15px;border-radius:3px;padding:2px 11px;font:9px Minecraft,monospace;letter-spacing:1.5px;color:#d7c698;background:linear-gradient(180deg,#a7915b,#5a502f 40%,#353a21 75%,#1e291c);box-shadow:0 7px 10px #0007,inset 0 1px 0 #e2d2a66b}footer{display:flex;justify-content:space-between;gap:15px;padding:14px 32px 15px;color:#8eaa94;font-size:9px;line-height:1.4}.common{color:#eee}.uncommon{color:#7cda8a}.rare{color:#7dbaf0}.very_rare{color:#c08aec}.legendary{color:#edc45d}.mythic{color:#f28fe4}.relic{color:#fff1b6}@media(max-width:850px){main{grid-template-columns:250px minmax(0,1fr);padding:0 20px;gap:15px}.goods{grid-template-columns:repeat(3,minmax(0,1fr))}.logo{width:140px}header{padding:8px 20px;gap:12px}h1{font-size:24px}}@media(max-width:600px){main{grid-template-columns:1fr}.goods{grid-template-columns:repeat(3,minmax(0,1fr))}aside{min-height:0}aside:before,aside:after{content:"";position:absolute;width:10px;height:10px;border:3px solid #e6c575;pointer-events:none}aside:before{left:3px;top:3px;border-right:0;border-bottom:0}aside:after{right:3px;bottom:3px;border-left:0;border-top:0}.stage{height:100px}.viewer{display:none}.logo{width:120px}h1{font-size:19px}header{height:82px}.heading small{display:none}} """; }