Esempio n. 1
0
    public CharPos charat(Coord c) {
      if (c.y < -sb.val) {
        if (msgs.size() < 1) return (null);
        Message msg = msgs.get(0);
        if (!(msg.text() instanceof RichText)) return (null);
        RichText.TextPart fp = null;
        for (RichText.Part part = ((RichText) msg.text()).parts; part != null; part = part.next) {
          if (part instanceof RichText.TextPart) {
            fp = (RichText.TextPart) part;
            break;
          }
        }
        if (fp == null) return (null);
        return (new CharPos(msg, fp, TextHitInfo.leading(0)));
      }

      Coord hc = new Coord();
      Message msg = messageat(c, hc);
      if ((msg == null) || !(msg.text() instanceof RichText)) return (null);
      RichText rt = (RichText) msg.text();
      RichText.Part p = rt.partat(hc);
      if (p == null) {
        RichText.TextPart lp = null;
        for (RichText.Part part = ((RichText) msg.text()).parts; part != null; part = part.next) {
          if (part instanceof RichText.TextPart) lp = (RichText.TextPart) part;
        }
        if (lp == null) return (null);
        return (new CharPos(msg, lp, TextHitInfo.trailing(lp.end - lp.start - 1)));
      }
      if (!(p instanceof RichText.TextPart)) return (null);
      RichText.TextPart tp = (RichText.TextPart) p;
      return (new CharPos(msg, tp, tp.charat(hc)));
    }
Esempio n. 2
0
  public void draw(BufferedImage buf) {
    WritableRaster dst = buf.getRaster();
    blit(dst, bg.getRaster(), Coord.z);

    alphablit(dst, rmeter(sbars[0].getRaster(), lmax[0], max), mc[0]);
    alphablit(
        dst, lmeter(sbars[1].getRaster(), lmax[1], max), mc[1].sub(bars[1].getWidth() - 1, 0));
    alphablit(
        dst, lmeter(sbars[2].getRaster(), lmax[2], max), mc[2].sub(bars[2].getWidth() - 1, 0));
    alphablit(dst, rmeter(sbars[3].getRaster(), lmax[3], max), mc[3]);

    if (lfood != null) {
      double e = foodeff(lfood);
      alphablit(dst, rgmeter(lfood, e, 0), mc[0]);
      alphablit(dst, lgmeter(lfood, e, 1), mc[1].sub(bars[1].getWidth() - 1, 0));
      alphablit(dst, lgmeter(lfood, e, 2), mc[2].sub(bars[1].getWidth() - 1, 0));
      alphablit(dst, rgmeter(lfood, e, 3), mc[3]);
    }

    alphablit(dst, rmeter(bars[0].getRaster(), lev[0], max), mc[0]);
    alphablit(dst, lmeter(bars[1].getRaster(), lev[1], max), mc[1].sub(bars[1].getWidth() - 1, 0));
    alphablit(dst, lmeter(bars[2].getRaster(), lev[2], max), mc[2].sub(bars[2].getWidth() - 1, 0));
    alphablit(dst, rmeter(bars[3].getRaster(), lev[3], max), mc[3]);

    StringBuilder tbuf = new StringBuilder();
    for (int i = 0; i < 4; i++)
      tbuf.append(
          String.format(
              "%s: %s/%s\n", rnm[i], Utils.fpformat(lev[i], 3, 1), Utils.fpformat(lmax[i], 3, 1)));
    tooltip = RichText.render(tbuf.toString(), 0).tex();
  }
Esempio n. 3
0
  public static class ChatParser extends RichText.Parser {
    public static final Pattern urlpat =
        Pattern.compile(
            "\\b((https?://)|(www\\.[a-z0-9_.-]+\\.[a-z0-9_.-]+))[a-z0-9/_.~#%+?&:*=-]*",
            Pattern.CASE_INSENSITIVE);
    public static final Map<? extends Attribute, ?> urlstyle =
        RichText.fillattrs(
            TextAttribute.FOREGROUND,
            new Color(64, 175, 255),
            TextAttribute.UNDERLINE,
            TextAttribute.UNDERLINE_ON,
            TextAttribute.WEIGHT,
            TextAttribute.WEIGHT_BOLD);

    public ChatParser(Object... args) {
      super(args);
    }

    protected RichText.Part text(PState s, String text, Map<? extends Attribute, ?> attrs)
        throws IOException {
      RichText.Part ret = null;
      int p = 0;
      while (true) {
        Matcher m = urlpat.matcher(text);
        if (!m.find(p)) break;
        URL url;
        try {
          String su = text.substring(m.start(), m.end());
          if (su.indexOf(':') < 0) su = "http://" + su;
          url = new URL(su);
        } catch (java.net.MalformedURLException e) {
          p = m.end();
          continue;
        }
        RichText.Part lead = new RichText.TextPart(text.substring(0, m.start()), attrs);
        if (ret == null) ret = lead;
        else ret.append(lead);
        Map<Attribute, Object> na = new HashMap<Attribute, Object>(attrs);
        na.putAll(urlstyle);
        na.put(ChatAttribute.HYPERLINK, new FuckMeGentlyWithAChainsaw(url));
        ret.append(new RichText.TextPart(text.substring(m.start(), m.end()), na));
        p = m.end();
      }
      if (ret == null) ret = new RichText.TextPart(text, attrs);
      else ret.append(new RichText.TextPart(text.substring(p), attrs));
      return (ret);
    }
  }
Esempio n. 4
0
 public static BufferedImage longtip(GItem item, List<ItemInfo> info) {
   BufferedImage img = ItemInfo.longtip(info);
   Resource.Pagina pg = item.res.get().layer(Resource.pagina);
   if (pg != null) img = ItemInfo.catimgs(0, img, RichText.render("\n" + pg.text, 200).img);
   return (img);
 }
Esempio n. 5
0
  public Object tooltip(Coord mc, Widget prev) {
    Resource tres = null;
    Coord c;
    if (qmod != null) {
      c = new Coord(xoff, qmy);
      try {
        for (Indir<Resource> qm : qmod) {
          Tex t = qm.get().layer(Resource.imgc).tex();
          Coord sz = t.sz();
          try {
            Glob.CAttr attr = ui.gui.chrwdg.findattr(qm.get().basename());
            if (attr != null) {
              sz = sz.add(attr.comptex().sz().x + 8, 0);
            }
          } catch (Exception ignored) {
          }

          if (mc.isect(c, sz)) return (qm.get().layer(Resource.tooltip).t);
          c = c.add(sz.x + 1, 0);
        }
      } catch (Loading l) {
      }
    }
    find:
    {
      c = new Coord(xoff, 0);
      for (Spec s : inputs) {
        if (mc.isect(c, Inventory.invsq.sz())) {
          tres = s.res.get();
          break find;
        }
        c = c.add(31, 0);
      }
      c = new Coord(xoff, outy);
      for (Spec s : outputs) {
        if (mc.isect(c, Inventory.invsq.sz())) {
          tres = s.res.get();
          break find;
        }
        c = c.add(31, 0);
      }
    }
    Resource.Tooltip tt;
    if ((tres == null) || ((tt = tres.layer(Resource.tooltip)) == null)) return (null);
    if (lasttip != tres) {
      lasttip = tres;
      stip = ltip = null;
    }
    long now = System.currentTimeMillis();
    boolean sh = true;
    if (prev != this) hoverstart = now;
    else if (now - hoverstart > 1000) sh = false;
    if (sh) {
      if (stip == null) stip = Text.render(tt.t);
      return (stip);
    } else {
      if (ltip == null) {
        String t = tt.t;
        Resource.Pagina p = tres.layer(Resource.pagina);
        if (p != null) t += "\n\n" + tres.layer(Resource.pagina).text;
        ltip = RichText.render(t, 300);
      }
      return (ltip);
    }
  }