Ejemplo n.º 1
0
 public void draw(GOut g) {
   try {
     Resource res = item.res.get();
     Tex tex = res.layer(Resource.imgc).tex();
     drawmain(g, tex);
     if (item.num >= 0) {
       g.atext(Integer.toString(item.num), tex.sz(), 1, 1);
     } else if (itemnum.get() != null) {
       g.aimage(itemnum.get(), tex.sz(), 1, 1);
     }
     if (item.meter > 0) {
       double a = ((double) item.meter) / 100.0;
       g.chcolor(255, 255, 255, 64);
       Coord half = Inventory.isqsz.div(2);
       g.prect(half, half.inv(), half, a * Math.PI * 2);
       g.chcolor();
     }
     if (olcol.get() != null) {
       if (cmask != res) {
         mask = null;
         if (tex instanceof TexI) mask = ((TexI) tex).mkmask();
         cmask = res;
       }
       if (mask != null) {
         g.chcolor(olcol.get());
         g.image(mask, Coord.z);
         g.chcolor();
       }
     }
   } catch (Loading e) {
     missing.loadwait();
     g.image(missing.layer(Resource.imgc).tex(), Coord.z, sz);
   }
 }
Ejemplo n.º 2
0
 public void draw(GOut g) {
   g.chcolor(0, 0, 0, 160);
   if (ctl == null || csz == null) {
     return;
   }
   g.frect(ctl, csz);
   g.chcolor();
   cdraw(g.reclip(xlate(Coord.z, true), asz));
   if (cap != null) {
     topless.draw(g, new Coord(0, th), sz.sub(0, th));
     g.image(tleft, Coord.z);
     Coord tmul = new Coord(tleft.sz().x, tdh);
     Coord tmbr = new Coord(sz.x - tright.sz().x, th);
     for (int x = tmul.x; x < tmbr.x; x += tmain.sz().x) {
       g.image(tmain, new Coord(x, tdh), tmul, tmbr);
     }
     g.image(tright, new Coord(sz.x - tright.sz().x, tdh));
     g.image(cap.tex(), capc.sub(0, cap.sz().y));
   } else {
     wbox.draw(g, Coord.z, sz);
   }
   /*
   if(cap != null) {
       GOut cg = og.reclip(new Coord(0, -7), sz.add(0, 7));
       int w = cap.tex().sz().x;
       cg.image(cl, new Coord((sz.x / 2) - (w / 2) - cl.sz().x, 0));
       cg.image(cm, new Coord((sz.x / 2) - (w / 2), 0), new Coord(w, cm.sz().y));
       cg.image(cr, new Coord((sz.x / 2) + (w / 2), 0));
       cg.image(cap.tex(), new Coord((sz.x / 2) - (w / 2), 0));
   }
   */
   super.draw(g);
 }
Ejemplo n.º 3
0
 public void draw(GOut g) {
   Tex at = null;
   if (none) {
   } else if (myown != null) {
     at = myown;
   } else {
     Gob gob = ui.sess.glob.oc.getgob(avagob);
     Avatar ava = null;
     if (gob != null) ava = gob.getattr(Avatar.class);
     if (ava != null) at = ava.rend;
   }
   GOut g2 = g.reclip(Window.wbox.tloff().add(unborder.inv()), asz);
   int yo;
   if (at == null) {
     at = missing;
     yo = 0;
   } else {
     g2.image(Equipory.bg, new Coord(Equipory.bg.sz().x / 2 - asz.x / 2, 20).inv());
     yo = (20 * asz.y) / dasz.y;
   }
   Coord tsz = new Coord((at.sz().x * asz.x) / dasz.x, (at.sz().y * asz.y) / dasz.y);
   g2.image(at, new Coord(tsz.x / 2 - asz.x / 2, yo).inv(), tsz);
   g.chcolor(color);
   Window.wbox.draw(g, Coord.z, asz.add(Window.wbox.bisz()).add(unborder.mul(2).inv()));
 }
Ejemplo n.º 4
0
  public void draw(GOut g) {
    Coord c = new Coord(xoff, 0);
    for (Spec s : inputs) {
      GOut sg = g.reclip(c, Inventory.invsq.sz());
      sg.image(Inventory.invsq, Coord.z);
      s.draw(sg);
      c = c.add(Inventory.sqsz.x, 0);
    }
    if (qmod != null) {
      g.image(qmodl.tex(), new Coord(0, qmy + 4));
      c = new Coord(xoff, qmy);
      int mx = -1;
      int pw = 0;
      int vl = 1;
      for (Indir<Resource> qm : qmod) {
        try {
          Tex t = qm.get().layer(Resource.imgc).tex();
          g.image(t, c);
          c = c.add(t.sz().x + 1, 0);
          if (c.x > mx) mx = c.x;

          try {
            Glob.CAttr attr = ui.gui.chrwdg.findattr(qm.get().basename());
            if (attr != null) {
              pw++;
              vl *= attr.comp;
              Tex txt = attr.comptex();
              g.image(txt, c);
              c = c.add(txt.sz().x + 8, 0);
            }
          } catch (Exception ignored) {
          }

        } catch (Loading l) {
        }
      }
      if (pw > 0) {
        g.image(
            Text.renderstroked(
                    String.format("Cap: %.0f", Math.floor(Math.pow(vl, 1.0f / pw))),
                    Color.WHITE,
                    Color.BLACK,
                    new Text.Foundry(Text.fraktur, 14).aa(true))
                .tex(),
            new Coord(mx + 30, qmy));
      }
    }
    c = new Coord(xoff, outy);
    for (Spec s : outputs) {
      GOut sg = g.reclip(c, Inventory.invsq.sz());
      sg.image(Inventory.invsq, Coord.z);
      s.draw(sg);
      c = c.add(Inventory.sqsz.x, 0);
    }
    super.draw(g);
  }
Ejemplo n.º 5
0
 public void draw(GOut g) {
   long now = System.currentTimeMillis();
   for (int y = 0; y < gsz.y; y++) {
     for (int x = 0; x < gsz.x; x++) {
       Coord p = bgsz.mul(new Coord(x, y));
       g.image(bg, p);
       Pagina btn = layout[x][y];
       if (btn != null) {
         Tex btex = btn.img.tex();
         g.image(btex, p.add(1, 1));
         if (btn.meter > 0) {
           double m = btn.meter / 1000.0;
           if (btn.dtime > 0) m += (1 - m) * (double) (now - btn.gettime) / (double) btn.dtime;
           m = Utils.clip(m, 0, 1);
           g.chcolor(255, 255, 255, 128);
           g.fellipse(p.add(bgsz.div(2)), bgsz.div(2), 90, (int) (90 + (360 * m)));
           g.chcolor();
         }
         if (btn.newp != 0) {
           if (btn.fstart == 0) {
             btn.fstart = now;
           } else {
             double ph = ((now - btn.fstart) / 1000.0) - (((x + (y * gsz.x)) * 0.15) % 1.0);
             if (ph < 1.25) {
               g.chcolor(255, 255, 255, (int) (255 * ((Math.cos(ph * Math.PI * 2) * -0.5) + 0.5)));
               g.image(glowmask(btn), p.sub(4, 4));
               g.chcolor();
             } else {
               g.chcolor(255, 255, 255, 128);
               g.image(glowmask(btn), p.sub(4, 4));
               g.chcolor();
             }
           }
         }
         if (btn == pressed) {
           g.chcolor(new Color(0, 0, 0, 128));
           g.frect(p.add(1, 1), btex.sz());
           g.chcolor();
         }
       }
     }
   }
   super.draw(g);
   if (dragging != null) {
     final Tex dt = dragging.img.tex();
     ui.drawafter(
         new UI.AfterDraw() {
           public void draw(GOut g) {
             g.image(dt, ui.mc.add(dt.sz().div(2).inv()));
           }
         });
   }
 }
Ejemplo n.º 6
0
 public void drawicons(GOut g) {
   OCache oc = ui.sess.glob.oc;
   synchronized (oc) {
     for (Gob gob : oc) {
       try {
         GobIcon icon = gob.getattr(GobIcon.class);
         if (icon != null) {
           Coord gc = p2c(gob.rc);
           Tex tex = icon.tex();
           g.image(tex, gc.sub(tex.sz().div(2)));
         }
       } catch (Loading l) {
       }
     }
   }
 }
Ejemplo n.º 7
0
 public void drawmain(GOut g, Tex tex) {
   g.image(tex, Coord.z);
   if (tex != ltex) {
     resize(upsize(tex.sz()));
     ltex = tex;
   }
 }
 public Sprite create(Owner owner, Resource res, Message sdt) {
   int m = sdt.uint8();
   GrowingPlant spr = new GrowingPlant(owner, res);
   spr.addnegative();
   Random rnd = owner.mkrandoom();
   int n = Config.simple_plants ? 1 : num;
   for (int i = 0; i < n; i++) {
     Coord c;
     if (Config.simple_plants) {
       c = neg.bc.add(neg.bs).sub(5, 5);
     } else {
       c = new Coord(rnd.nextInt(neg.bs.x), rnd.nextInt(neg.bs.y)).add(neg.bc);
     }
     Tex s = strands[m][rnd.nextInt(strands[m].length)];
     spr.add(s, 0, MapView.m2s(c), new Coord(s.sz().x / 2, s.sz().y).inv());
   }
   return (spr);
 }
Ejemplo n.º 9
0
 public void draw(GOut g) {
   long now = System.currentTimeMillis();
   int t = (int) (now % 1000);
   int b = (int) (255 * ((t < 500) ? (t) : (1000 - t)) / 500.0f);
   Inventory.invsq(g, Coord.z, gsz);
   for (int y = 0; y < gsz.y; y++) {
     for (int x = 0; x < gsz.x; x++) {
       Coord p = Inventory.sqoff(new Coord(x, y));
       Pagina btn = layout[x][y];
       if (btn != null) {
         Tex btex = btn.img.tex();
         if (btn.newp) {
           g.chcolor(b, 255, b, 255);
         }
         g.image(btex, p);
         g.chcolor();
         if (btn.meter > 0) {
           double m = btn.meter / 1000.0;
           if (btn.dtime > 0) m += (1 - m) * (double) (now - btn.gettime) / (double) btn.dtime;
           m = Utils.clip(m, 0, 1);
           g.chcolor(255, 255, 255, 128);
           g.fellipse(
               p.add(Inventory.isqsz.div(2)), Inventory.isqsz.div(2), 90, (int) (90 + (360 * m)));
           g.chcolor();
         }
         if (btn == pressed) {
           g.chcolor(new Color(0, 0, 0, 128));
           g.frect(p, btex.sz());
           g.chcolor();
         }
       }
     }
   }
   super.draw(g);
   if (dragging != null) {
     final Tex dt = dragging.img.tex();
     ui.drawafter(
         new UI.AfterDraw() {
           public void draw(GOut g) {
             g.image(dt, ui.mc.add(dt.sz().div(2).inv()));
           }
         });
   }
 }
Ejemplo n.º 10
0
  public void draw(GOut g) {
    updatepos();
    double now = System.currentTimeMillis() / 1000.0;

    for (Buff buff : fv.buffs.children(Buff.class))
      buff.draw(
          g.reclip(
              pcc.add(-buff.c.x - Buff.cframe.sz().x - 20, buff.c.y + pho - Buff.cframe.sz().y),
              buff.sz));
    if (fv.current != null) {
      for (Buff buff : fv.current.buffs.children(Buff.class))
        buff.draw(g.reclip(pcc.add(buff.c.x + 20, buff.c.y + pho - Buff.cframe.sz().y), buff.sz));

      g.aimage(ip.get().tex(), pcc.add(-75, 0), 1, 0.5);
      g.aimage(oip.get().tex(), pcc.add(75, 0), 0, 0.5);
    }

    if (now < fv.atkct) {
      int w = (int) ((fv.atkct - now) * 20);
      g.chcolor(255, 0, 128, 255);
      g.frect(pcc.add(-w, 20), new Coord(w * 2, 15));
      g.chcolor();
    }
    Coord ca = pcc.add(-(actions.length * actpitch) / 2, 45);
    for (int i = 0; i < actions.length; i++) {
      Indir<Resource> act = actions[i];
      try {
        if (act != null) {
          Tex img = act.get().layer(Resource.imgc).tex();
          g.image(img, ca);
          g.image(dyn[i] ? lframe : Buff.frame, ca.sub(Buff.imgoff));
          if (i == use) {
            g.chcolor(255, 0, 128, 255);
            Coord cc = ca.add(img.sz().x / 2, img.sz().y + 5);
            g.frect(cc.sub(2, 2), new Coord(5, 5));
            g.chcolor();
          }
        }
      } catch (Loading l) {
      }
      ca.x += actpitch;
    }
  }
Ejemplo n.º 11
0
 public Object tooltip(Coord c, Widget prev) {
   for (Buff buff : fv.buffs.children(Buff.class)) {
     Coord dc = pcc.add(-buff.c.x - Buff.cframe.sz().x - 20, buff.c.y + pho - Buff.cframe.sz().y);
     if (c.isect(dc, buff.sz)) {
       Object ret = buff.tooltip(c.sub(dc), prevtt);
       if (ret != null) {
         prevtt = buff;
         return (ret);
       }
     }
   }
   if (fv.current != null) {
     for (Buff buff : fv.current.buffs.children(Buff.class)) {
       Coord dc = pcc.add(buff.c.x + 20, buff.c.y + pho - Buff.cframe.sz().y);
       if (c.isect(dc, buff.sz)) {
         Object ret = buff.tooltip(c.sub(dc), prevtt);
         if (ret != null) {
           prevtt = buff;
           return (ret);
         }
       }
     }
   }
   Coord ca = pcc.add(-(actions.length * actpitch) / 2, 45);
   for (int i = 0; i < actions.length; i++) {
     Indir<Resource> act = actions[i];
     try {
       if (act != null) {
         Tex img = act.get().layer(Resource.imgc).tex();
         if (c.isect(ca, img.sz())) {
           if (dyn[i]) return ("Combat discovery");
           return (act.get().layer(Resource.tooltip).t);
         }
       }
     } catch (Loading l) {
     }
     ca.x += actpitch;
   }
   return (null);
 }
Ejemplo n.º 12
0
 public void draw(GOut g) {
   super.draw(g);
   if (lvlmask != null) {
     long now = System.currentTimeMillis();
     if (now - lvltime > 1000) {
       lvlmask.dispose();
       lvlmask = null;
     } else {
       g.chcolor(255, 255, 255, 255 - (int) ((255 * (now - lvltime)) / 1000));
       g.image(lvlmask, Coord.z);
     }
   }
 }
Ejemplo n.º 13
0
  /* XXX: Some strange javac bug seems to make it resolve the
   * trans() references to the wrong signature, thus the name
   * distinction. */
  public void _faces(
      MapMesh m, Tile t, int z, Surface.Vertex[] v, float[] tcx, float[] tcy, int[] f) {
    Tex tex = t.tex();
    float tl = tex.tcx(0),
        tt = tex.tcy(0),
        tw = tex.tcx(tex.sz().x) - tl,
        th = tex.tcy(tex.sz().y) - tt;
    GLState st = stfor(tex, z, t.t != 'g');
    MeshBuf buf = MapMesh.Model.get(m, st);

    MeshBuf.Tex btex = buf.layer(MeshBuf.tex);
    MeshVertex[] mv = new MeshVertex[v.length];
    for (int i = 0; i < v.length; i++) {
      mv[i] = new MeshVertex(buf, v[i]);
      btex.set(mv[i], new Coord3f(tl + (tw * tcx[i]), tt + (th * tcy[i]), 0));
    }
    for (int i = 0; i < f.length; i += 3) buf.new Face(mv[f[i]], mv[f[i + 1]], mv[f[i + 2]]);
  }
Ejemplo n.º 14
0
  void rootdraw(GLState.Applier state, UI ui, BGL gl) {
    GLState.Buffer ibuf = new GLState.Buffer(state.cfg);
    gstate.prep(ibuf);
    ostate.prep(ibuf);
    GOut g = new GOut(gl, state.cgl, state.cfg, state, ibuf, new Coord(w, h));
    state.set(ibuf);

    g.state(ostate);
    g.apply();
    gl.glClearColor(0, 0, 0, 1);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);
    synchronized (ui) {
      ui.draw(g);
    }

    if (Config.dbtext) {
      int y = h - 150;
      FastText.aprintf(
          g,
          new Coord(10, y -= 15),
          0,
          1,
          "FPS: %d (%d%%, %d%% idle)",
          fps,
          (int) (uidle * 100.0),
          (int) (ridle * 100.0));
      Runtime rt = Runtime.getRuntime();
      long free = rt.freeMemory(), total = rt.totalMemory();
      FastText.aprintf(
          g,
          new Coord(10, y -= 15),
          0,
          1,
          "Mem: %,011d/%,011d/%,011d/%,011d",
          free,
          total - free,
          total,
          rt.maxMemory());
      FastText.aprintf(g, new Coord(10, y -= 15), 0, 1, "Tex-current: %d", TexGL.num());
      FastText.aprintf(g, new Coord(10, y -= 15), 0, 1, "GL progs: %d", g.st.numprogs());
      GameUI gi = ui.root.findchild(GameUI.class);
      if ((gi != null) && (gi.map != null)) {
        try {
          FastText.aprintf(
              g, new Coord(10, y -= 15), 0, 1, "MV pos: %s (%s)", gi.map.getcc(), gi.map.camera);
        } catch (Loading e) {
        }
        if (gi.map.rls != null)
          FastText.aprintf(
              g,
              new Coord(10, y -= 15),
              0,
              1,
              "Rendered: %,d+%,d(%,d)",
              gi.map.rls.drawn,
              gi.map.rls.instanced,
              gi.map.rls.instancified);
      }
      if (Resource.remote().qdepth() > 0)
        FastText.aprintf(
            g,
            new Coord(10, y -= 15),
            0,
            1,
            "RQ depth: %d (%d)",
            Resource.remote().qdepth(),
            Resource.remote().numloaded());
    }
    Object tooltip;
    try {
      synchronized (ui) {
        tooltip = ui.root.tooltip(mousepos, ui.root);
      }
    } catch (Loading e) {
      tooltip = "...";
    }
    Tex tt = null;
    if (tooltip != null) {
      if (tooltip instanceof Text) {
        tt = ((Text) tooltip).tex();
      } else if (tooltip instanceof Tex) {
        tt = (Tex) tooltip;
      } else if (tooltip instanceof Indir<?>) {
        Indir<?> t = (Indir<?>) tooltip;
        Object o = t.get();
        if (o instanceof Tex) tt = (Tex) o;
      } else if (tooltip instanceof String) {
        if (((String) tooltip).length() > 0) tt = (Text.render((String) tooltip)).tex();
      }
    }
    if (tt != null) {
      Coord sz = tt.sz();
      Coord pos = mousepos.add(sz.inv());
      if (pos.x < 0) pos.x = 0;
      if (pos.y < 0) pos.y = 0;
      g.chcolor(244, 247, 21, 192);
      g.rect(pos.add(-3, -3), sz.add(6, 6));
      g.chcolor(35, 35, 35, 192);
      g.frect(pos.add(-2, -2), sz.add(4, 4));
      g.chcolor();
      g.image(tt, pos);
    }
    ui.lasttip = tooltip;
    Resource curs = ui.root.getcurs(mousepos);
    if (curs != null) {
      if (cursmode == "awt") {
        if (curs != lastcursor) {
          try {
            setCursor(makeawtcurs(curs.layer(Resource.imgc).img, curs.layer(Resource.negc).cc));
            lastcursor = curs;
          } catch (Exception e) {
            cursmode = "tex";
          }
        }
      } else if (cursmode == "tex") {
        Coord dc = mousepos.add(curs.layer(Resource.negc).cc.inv());
        g.image(curs.layer(Resource.imgc), dc);
      }
    }
    state.clean();
    GLObject.disposeall(state.cgl, gl);
  }
Ejemplo n.º 15
0
public class MenuGrid extends Widget {
  public static final Tex bg = Resource.loadtex("gfx/hud/invsq");
  public static final Coord bgsz = bg.sz().add(-1, -1);
  public static final Pagina next =
      new Glob.Pagina(Resource.local().loadwait("gfx/hud/sc-next").indir());
  public static final Pagina bk =
      new Glob.Pagina(Resource.local().loadwait("gfx/hud/sc-back").indir());
  public static final RichText.Foundry ttfnd =
      new RichText.Foundry(TextAttribute.FAMILY, "SansSerif", TextAttribute.SIZE, 10);
  private static Coord gsz = new Coord(4, 4);
  private Pagina cur, pressed, dragging, layout[][] = new Pagina[gsz.x][gsz.y];
  private UI.Grab grab;
  private int curoff = 0;
  private int pagseq = 0;
  private boolean loading = true;
  private Map<Character, Pagina> hotmap = new TreeMap<Character, Pagina>();

  @RName("scm")
  public static class $_ implements Factory {
    public Widget create(Widget parent, Object[] args) {
      return (new MenuGrid());
    }
  }

  public class PaginaException extends RuntimeException {
    public Pagina pag;

    public PaginaException(Pagina p) {
      super("Invalid pagina: " + p.res);
      pag = p;
    }
  }

  private boolean cons(Pagina p, Collection<Pagina> buf) {
    Pagina[] cp = new Pagina[0];
    Collection<Pagina> open, close = new HashSet<Pagina>();
    synchronized (ui.sess.glob.paginae) {
      open = new LinkedList<Pagina>();
      for (Pagina pag : ui.sess.glob.paginae) {
        if (pag.newp == 2) {
          pag.newp = 0;
          pag.fstart = 0;
        }
        open.add(pag);
      }
      for (Pagina pag : ui.sess.glob.pmap.values()) {
        if (pag.newp == 2) {
          pag.newp = 0;
          pag.fstart = 0;
        }
      }
    }
    boolean ret = true;
    while (!open.isEmpty()) {
      Iterator<Pagina> iter = open.iterator();
      Pagina pag = iter.next();
      iter.remove();
      try {
        AButton ad = pag.act();
        if (ad == null) throw (new PaginaException(pag));
        Pagina parent = paginafor(ad.parent);
        if ((pag.newp != 0) && (parent != null) && (parent.newp == 0)) {
          parent.newp = 2;
          parent.fstart = (parent.fstart == 0) ? pag.fstart : Math.min(parent.fstart, pag.fstart);
        }
        if (parent == p) buf.add(pag);
        else if ((parent != null) && !close.contains(parent) && !open.contains(parent))
          open.add(parent);
        close.add(pag);
      } catch (Loading e) {
        ret = false;
      }
    }
    return (ret);
  }

  public MenuGrid() {
    super(bgsz.mul(gsz).add(1, 1));
  }

  @Override
  protected void attach(UI ui) {
    super.attach(ui);
    Glob glob = ui.sess.glob;
    ObservableCollection<Pagina> p = glob.paginae;
    p.add(glob.paginafor(Resource.local().load("paginae/custom/plant-tree")));
    p.add(glob.paginafor(Resource.local().load("paginae/custom/fill-trough")));
    p.add(glob.paginafor(Resource.local().load("paginae/custom/fill-coop")));
    p.add(glob.paginafor(Resource.local().load("paginae/custom/fill-tarkiln")));
    p.add(glob.paginafor(Resource.local().load("paginae/custom/pick-mussels")));
    p.add(glob.paginafor(Resource.local().load("paginae/custom/fill-smelter")));
    p.add(glob.paginafor(Resource.local().load("paginae/custom/arrow-autoloader")));
  }

  private static Comparator<Pagina> sorter =
      new Comparator<Pagina>() {
        public int compare(Pagina a, Pagina b) {
          AButton aa = a.act(), ab = b.act();
          if ((aa.ad.length == 0) && (ab.ad.length > 0)) return (-1);
          if ((aa.ad.length > 0) && (ab.ad.length == 0)) return (1);
          return (aa.name.compareTo(ab.name));
        }
      };

  private void updlayout() {
    synchronized (ui.sess.glob.paginae) {
      List<Pagina> cur = new ArrayList<Pagina>();
      loading = !cons(this.cur, cur);
      Collections.sort(cur, sorter);
      int i = curoff;
      hotmap.clear();
      for (int y = 0; y < gsz.y; y++) {
        for (int x = 0; x < gsz.x; x++) {
          Pagina btn = null;
          if ((this.cur != null) && (x == gsz.x - 1) && (y == gsz.y - 1)) {
            btn = bk;
          } else if ((cur.size() > ((gsz.x * gsz.y) - 1)) && (x == gsz.x - 2) && (y == gsz.y - 1)) {
            btn = next;
          } else if (i < cur.size()) {
            Resource.AButton ad = cur.get(i).act();
            if (ad.hk != 0) hotmap.put(Character.toUpperCase(ad.hk), cur.get(i));
            btn = cur.get(i++);
          }
          layout[x][y] = btn;
        }
      }
      pagseq = ui.sess.glob.pagseq;
    }
  }

  private static Text rendertt(Resource res, boolean withpg) {
    Resource.AButton ad = res.layer(Resource.action);
    Resource.Pagina pg = res.layer(Resource.pagina);
    String tt = ad.name;
    int pos = tt.toUpperCase().indexOf(Character.toUpperCase(ad.hk));
    if (pos >= 0)
      tt =
          tt.substring(0, pos)
              + "$b{$col[255,128,0]{"
              + tt.charAt(pos)
              + "}}"
              + tt.substring(pos + 1);
    else if (ad.hk != 0) tt += " [" + ad.hk + "]";
    if (withpg && (pg != null)) {
      tt += "\n\n" + pg.text;
    }
    return (ttfnd.render(tt, 300));
  }

  private static Map<Pagina, Tex> glowmasks = new WeakHashMap<Pagina, Tex>();

  private Tex glowmask(Pagina pag) {
    Tex ret = glowmasks.get(pag);
    if (ret == null) {
      ret =
          new TexI(
              PUtils.glowmask(
                  PUtils.glowmask(pag.res().layer(Resource.imgc).img.getRaster()),
                  4,
                  new Color(32, 255, 32)));
      glowmasks.put(pag, ret);
    }
    return (ret);
  }

  public void draw(GOut g) {
    long now = System.currentTimeMillis();
    for (int y = 0; y < gsz.y; y++) {
      for (int x = 0; x < gsz.x; x++) {
        Coord p = bgsz.mul(new Coord(x, y));
        g.image(bg, p);
        Pagina btn = layout[x][y];
        if (btn != null) {
          Tex btex = btn.img.tex();
          g.image(btex, p.add(1, 1));
          if (btn.meter > 0) {
            double m = btn.meter / 1000.0;
            if (btn.dtime > 0) m += (1 - m) * (double) (now - btn.gettime) / (double) btn.dtime;
            m = Utils.clip(m, 0, 1);
            g.chcolor(255, 255, 255, 128);
            g.fellipse(p.add(bgsz.div(2)), bgsz.div(2), 90, (int) (90 + (360 * m)));
            g.chcolor();
          }
          if (btn.newp != 0) {
            if (btn.fstart == 0) {
              btn.fstart = now;
            } else {
              double ph = ((now - btn.fstart) / 1000.0) - (((x + (y * gsz.x)) * 0.15) % 1.0);
              if (ph < 1.25) {
                g.chcolor(255, 255, 255, (int) (255 * ((Math.cos(ph * Math.PI * 2) * -0.5) + 0.5)));
                g.image(glowmask(btn), p.sub(4, 4));
                g.chcolor();
              } else {
                g.chcolor(255, 255, 255, 128);
                g.image(glowmask(btn), p.sub(4, 4));
                g.chcolor();
              }
            }
          }
          if (btn == pressed) {
            g.chcolor(new Color(0, 0, 0, 128));
            g.frect(p.add(1, 1), btex.sz());
            g.chcolor();
          }
        }
      }
    }
    super.draw(g);
    if (dragging != null) {
      final Tex dt = dragging.img.tex();
      ui.drawafter(
          new UI.AfterDraw() {
            public void draw(GOut g) {
              g.image(dt, ui.mc.add(dt.sz().div(2).inv()));
            }
          });
    }
  }

  private Pagina curttp = null;
  private boolean curttl = false;
  private Text curtt = null;
  private long hoverstart;

  public Object tooltip(Coord c, Widget prev) {
    Pagina pag = bhit(c);
    long now = System.currentTimeMillis();
    if ((pag != null) && (pag.act() != null)) {
      if (prev != this) hoverstart = now;
      boolean ttl = (now - hoverstart) > 500;
      if ((pag != curttp) || (ttl != curttl)) {
        curtt = rendertt(pag.res(), ttl);
        curttp = pag;
        curttl = ttl;
      }
      return (curtt);
    } else {
      hoverstart = now;
      return ("");
    }
  }

  private Pagina bhit(Coord c) {
    Coord bc = c.div(bgsz);
    if ((bc.x >= 0) && (bc.y >= 0) && (bc.x < gsz.x) && (bc.y < gsz.y)) return (layout[bc.x][bc.y]);
    else return (null);
  }

  public boolean mousedown(Coord c, int button) {
    Pagina h = bhit(c);
    if ((button == 1) && (h != null)) {
      pressed = h;
      grab = ui.grabmouse(this);
    }
    return (true);
  }

  public void mousemove(Coord c) {
    if ((dragging == null) && (pressed != null)) {
      Pagina h = bhit(c);
      if (h != pressed) dragging = pressed;
    }
  }

  private Pagina paginafor(Resource.Named res) {
    return (ui.sess.glob.paginafor(res));
  }

  private void use(Pagina r, boolean reset) {
    Collection<Pagina> sub = new LinkedList<Pagina>(), cur = new LinkedList<Pagina>();
    cons(r, sub);
    cons(this.cur, cur);
    if (sub.size() > 0) {
      this.cur = r;
      curoff = 0;
    } else if (r == bk) {
      this.cur = paginafor(this.cur.act().parent);
      curoff = 0;
    } else if (r == next) {
      if ((curoff + 14) >= cur.size()) curoff = 0;
      else curoff += 14;
    } else {
      r.newp = 0;
      use(r);
      if (reset) this.cur = null;
      curoff = 0;
    }
    updlayout();
  }

  public boolean use(Pagina r) {
    String[] ad = r.act().ad;
    if ((ad == null) || (ad.length < 1)) {
      return false;
    }
    if (ad[0].equals("@")) {
      usecustom(ad);
    } else {
      wdgmsg("act", (Object[]) ad);
    }
    return true;
  }

  private void usecustom(String[] ad) {
    if (ad[1].equals("plant-tree")) {
      if (ui != null && ui.gui != null) {
        ui.gui.add(new TreePlantTool(ui.gui), 300, 200);
      }
    } else if (ad[1].equals("fill-trough")) {
      ui.gui.tasks.add(new FeedEdiblesTask("trough"));
    } else if (ad[1].equals("fill-coop")) {
      ui.gui.tasks.add(new FeedEdiblesTask("chickencoop"));
    } else if (ad[1].equals("fill-tarkiln")) {
      ui.gui.tasks.add(new FeedBlocksTask("tarkiln"));
    } else if (ad[1].equals("pick-mussels")) {
      ui.gui.tasks.add(new Forager(200, Integer.MAX_VALUE, "mussels"));
    } else if (ad[1].equals("fill-smelter")) {
      ui.gui.tasks.add(new FeedCoalTask("smelter", 11));
    } else if (ad[1].equals("arrow-autoloader")) {
      Config.enableAutoloader = !Config.enableAutoloader;
      ui.gui.msg(
          String.format("Autoloader is now turned %s", Config.enableAutoloader ? "on" : "off"));
    }
  }

  public void tick(double dt) {
    if (loading || (pagseq != ui.sess.glob.pagseq)) updlayout();
  }

  public boolean mouseup(Coord c, int button) {
    Pagina h = bhit(c);
    if ((button == 1) && (grab != null)) {
      if (dragging != null) {
        ui.dropthing(ui.root, ui.mc, dragging.res());
        dragging = pressed = null;
      } else if (pressed != null) {
        if (pressed == h) use(h, false);
        pressed = null;
      }
      grab.remove();
      grab = null;
    }
    return (true);
  }

  public void uimsg(String msg, Object... args) {
    if (msg == "goto") {
      String resnm = (String) args[0];
      if (resnm.equals("")) {
        cur = null;
      } else {
        Resource.Named res = Resource.remote().load(resnm, (Integer) args[1]);
        cur = paginafor(res);
      }
      curoff = 0;
      updlayout();
    }
  }

  public boolean globtype(char k, KeyEvent ev) {
    if ((k == 27) && (this.cur != null)) {
      this.cur = null;
      curoff = 0;
      updlayout();
      return (true);
    } else if ((k == 8) && (this.cur != null)) {
      this.cur = paginafor(this.cur.act().parent);
      curoff = 0;
      updlayout();
      return (true);
    } else if ((k == 'N') && (layout[gsz.x - 2][gsz.y - 1] == next)) {
      use(next, false);
      return (true);
    }
    Pagina r = hotmap.get(Character.toUpperCase(k));
    if (r != null) {
      use(r, true);
      return (true);
    }
    return (false);
  }
}
Ejemplo n.º 16
0
 public void dispose() {
   if (tex != null) tex.dispose();
 }
Ejemplo n.º 17
0
public class Window extends Widget implements DTarget {
  private static final Tex tleft = Resource.loadtex("gfx/hud/wnd/tleft");
  private static final Tex tmain = Resource.loadtex("gfx/hud/wnd/tmain");
  private static final Tex tright = Resource.loadtex("gfx/hud/wnd/tright");
  public static final BufferedImage[] cbtni =
      new BufferedImage[] {
        Resource.loadimg("gfx/hud/wnd/cbtn"),
        Resource.loadimg("gfx/hud/wnd/cbtnd"),
        Resource.loadimg("gfx/hud/wnd/cbtnh")
      };
  public static final BufferedImage[] lbtni =
      new BufferedImage[] {
        Resource.loadimg("gfx/hud/wnd/lbtn"),
        Resource.loadimg("gfx/hud/wnd/lbtnd"),
        Resource.loadimg("gfx/hud/wnd/lbtnh")
      };
  public static final BufferedImage[] rbtni =
      new BufferedImage[] {
        Resource.loadimg("gfx/hud/wnd/rbtn"),
        Resource.loadimg("gfx/hud/wnd/rbtnd"),
        Resource.loadimg("gfx/hud/wnd/rbtnh")
      };
  public static final Color cc = new Color(248, 230, 190);
  public static final Text.Furnace cf =
      new Text.Imager(new Text.Foundry(new Font("Serif", Font.BOLD, 15), cc).aa(true)) {
        protected BufferedImage proc(Text text) {
          return (rasterimg(blurmask2(text.img.getRaster(), 1, 1, Color.BLACK)));
        }
      };
  public static final IBox fbox =
      new IBox("gfx/hud", "ftl", "ftr", "fbl", "fbr", "fl", "fr", "ft", "fb");
  public static final IBox swbox =
      new IBox("gfx/hud", "stl", "str", "sbl", "sbr", "sl", "sr", "st", "sb");
  public static final IBox wbox =
      new IBox("gfx/hud/wnd", "tl", "tr", "bl", "br", "vl", "vr", "ht", "hb");
  private static final IBox topless =
      new IBox(Tex.empty, Tex.empty, wbox.cbl, wbox.cbr, wbox.bl, wbox.br, Tex.empty, wbox.bb);
  private static final int th = tleft.sz().y, tdh = th - tmain.sz().y, tc = tdh + 18;
  private static final Coord capc = new Coord(20, th - 3);
  public Coord mrgn = new Coord(5, 5);
  protected Text cap;
  private boolean dt = false;
  protected boolean dm = false;
  public Coord ctl, csz, atl, asz, ac;
  protected Coord doff;
  protected final IButton cbtn;
  private final Collection<Widget> twdgs = new LinkedList<Widget>();

  // ******************************
  private static final String OPT_POS = "_pos";
  //    static Tex bg = Resource.loadtex("gfx/hud/bgtex");
  //    static Tex cl = Resource.loadtex("gfx/hud/cleft");
  //    static Tex cm = Resource.loadtex("gfx/hud/cmain");
  //    static Tex cr = Resource.loadtex("gfx/hud/cright");
  public Coord tlo, rbo;
  public boolean justclose = false;
  protected final String name;

  @RName("wnd")
  public static class $_ implements Factory {
    public Widget create(Coord c, Widget parent, Object[] args) {
      if (args.length < 2) return (new Window(c, (Coord) args[0], parent, null));
      else return (new Window(c, (Coord) args[0], parent, (String) args[1]));
    }
  }

  public Window(Coord c, Coord sz, Widget parent, String cap) {
    super(c, new Coord(0, 0), parent);
    if (cap != null) {
      this.cap = cf.render(cap);
      name = cap;
    } else {
      this.cap = null;
      name = null;
    }
    resize(sz);
    setfocustab(true);
    parent.setfocus(this);
    cbtn = new IButton(Coord.z, this, cbtni[0], cbtni[1], cbtni[2]);
    cbtn.recthit = true;
    addtwdg(cbtn);
    loadOpts();
  }

  public Coord contentsz() {
    Coord max = new Coord(0, 0);
    for (Widget wdg = child; wdg != null; wdg = wdg.next) {
      if (twdgs.contains(wdg)) continue;
      if (!wdg.visible) continue;
      Coord br = wdg.c.add(wdg.sz);
      if (br.x > max.x) max.x = br.x;
      if (br.y > max.y) max.y = br.y;
    }
    return (max.sub(1, 1));
  }

  protected void placetwdgs() {
    int x = sz.x - 5;
    for (Widget ch : twdgs) ch.c = xlate(new Coord(x -= ch.sz.x + 5, tc - (ch.sz.y / 2)), false);
  }

  public void addtwdg(Widget wdg) {
    twdgs.add(wdg);
    placetwdgs();
  }

  public void resize(Coord sz) {
    IBox box;
    int th;
    if (cap == null) {
      box = wbox;
      th = 0;
    } else {
      box = topless;
      th = Window.th;
    }
    sz = sz.add(box.bisz()).add(0, th).add(mrgn.mul(2));
    this.sz = sz;
    ctl = box.btloff().add(0, th);
    csz = sz.sub(box.bisz()).sub(0, th);
    atl = ctl.add(mrgn);
    asz = csz.sub(mrgn.mul(2));
    ac = new Coord();
    // ac = tlo.add(wbox.btloff()).add(mrgn);
    placetwdgs();
    for (Widget ch = child; ch != null; ch = ch.next) ch.presize();
  }

  public Coord xlate(Coord c, boolean in) {
    if (in) return (c.add(atl));
    else return (c.sub(atl));
  }

  public void cdraw(GOut g) {}

  public void draw(GOut g) {
    g.chcolor(0, 0, 0, 160);
    if (ctl == null || csz == null) {
      return;
    }
    g.frect(ctl, csz);
    g.chcolor();
    cdraw(g.reclip(xlate(Coord.z, true), asz));
    if (cap != null) {
      topless.draw(g, new Coord(0, th), sz.sub(0, th));
      g.image(tleft, Coord.z);
      Coord tmul = new Coord(tleft.sz().x, tdh);
      Coord tmbr = new Coord(sz.x - tright.sz().x, th);
      for (int x = tmul.x; x < tmbr.x; x += tmain.sz().x) {
        g.image(tmain, new Coord(x, tdh), tmul, tmbr);
      }
      g.image(tright, new Coord(sz.x - tright.sz().x, tdh));
      g.image(cap.tex(), capc.sub(0, cap.sz().y));
    } else {
      wbox.draw(g, Coord.z, sz);
    }
    /*
    if(cap != null) {
        GOut cg = og.reclip(new Coord(0, -7), sz.add(0, 7));
        int w = cap.tex().sz().x;
        cg.image(cl, new Coord((sz.x / 2) - (w / 2) - cl.sz().x, 0));
        cg.image(cm, new Coord((sz.x / 2) - (w / 2), 0), new Coord(w, cm.sz().y));
        cg.image(cr, new Coord((sz.x / 2) + (w / 2), 0));
        cg.image(cap.tex(), new Coord((sz.x / 2) - (w / 2), 0));
    }
    */
    super.draw(g);
  }

  public void uimsg(String msg, Object... args) {
    if (msg == "pack") {
      pack();
    } else if (msg == "dt") {
      dt = (Integer) args[0] != 0;
    } else {
      super.uimsg(msg, args);
    }
  }

  public boolean mousedown(Coord c, int button) {
    parent.setfocus(this);
    raise();
    if (super.mousedown(c, button)) return (true);
    if (c.y < tdh && cap != null) return (false);
    if (button == 1) {
      ui.grabmouse(this);
      dm = true;
      doff = c;
    }
    return (true);
  }

  public boolean mouseup(Coord c, int button) {
    if (dm) {
      canceldm();
      storeOpt(OPT_POS, this.c);
    } else {
      super.mouseup(c, button);
    }
    return (true);
  }

  public void canceldm() {
    if (dm) ui.grabmouse(null);
    dm = false;
  }

  public void mousemove(Coord c) {
    if (dm) {
      this.c = this.c.add(c.add(doff.inv()));
    } else {
      super.mousemove(c);
    }
  }

  public void wdgmsg(Widget sender, String msg, Object... args) {
    if (sender == cbtn) {
      if (justclose) ui.destroy(this);
      else wdgmsg("close");
    } else {
      super.wdgmsg(sender, msg, args);
    }
  }

  public boolean type(char key, java.awt.event.KeyEvent ev) {
    if (super.type(key, ev)) return (true);
    if (key == 27) {
      if (justclose) ui.destroy(this);
      else wdgmsg("close");
      return (true);
    }
    return (false);
  }

  public boolean drop(Coord cc, Coord ul) {
    if (dt) {
      wdgmsg("drop", cc);
      return (true);
    }
    return (false);
  }

  public boolean iteminteract(Coord cc, Coord ul) {
    return (false);
  }

  public Object tooltip(Coord c, Widget prev) {
    Object ret = super.tooltip(c, prev);
    if (ret != null) return (ret);
    else return ("");
  }

  protected void storeOpt(String opt, String value) {
    if (name == null) {
      return;
    }
    Config.setWindowOpt(name + opt, value);
  }

  protected void storeOpt(String opt, Coord value) {
    storeOpt(opt, value.toString());
  }

  protected void storeOpt(String opt, boolean value) {
    if (name == null) {
      return;
    }
    Config.setWindowOpt(name + opt, value);
  }

  protected Coord getOptCoord(String opt, Coord def) {
    synchronized (Config.window_props) {
      try {
        return new Coord(Config.window_props.getProperty(name + opt, def.toString()));
      } catch (Exception e) {
        return def;
      }
    }
  }

  protected boolean getOptBool(String opt, boolean def) {
    synchronized (Config.window_props) {
      try {
        return Config.window_props.getProperty(name + opt, null).equals("true");
      } catch (Exception e) {
        return def;
      }
    }
  }

  protected void loadOpts() {
    if (name == null) {
      return;
    }
    c = getOptCoord(OPT_POS, c);
  }
}
Ejemplo n.º 18
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);
    }
  }