Exemplo 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);
   }
 }
Exemplo n.º 2
0
 public static Tex rendertt(Resource res, boolean withpg, boolean hotkey) {
   Resource.AButton ad = res.layer(Resource.action);
   Resource.Pagina pg = res.layer(Resource.pagina);
   String tt = ad.name;
   BufferedImage xp = null, food = null;
   if (hotkey) {
     int pos = tt.toUpperCase().indexOf(Character.toUpperCase(ad.hk));
     if (pos >= 0)
       tt =
           tt.substring(0, pos)
               + "$col[255,255,0]{"
               + tt.charAt(pos)
               + "}"
               + tt.substring(pos + 1);
     else if (ad.hk != 0) tt += " [" + ad.hk + "]";
   }
   if (withpg) {
     if (pg != null) {
       tt += "\n\n" + pg.text;
     }
     xp = getXPgain(ad.name);
     food = getFood(ad.name);
   }
   BufferedImage img = ttfnd.render(tt, 300).img;
   if (xp != null) {
     img = ItemInfo.catimgs(3, img, xp);
   }
   if (food != null) {
     img = ItemInfo.catimgs(3, img, food);
   }
   return (new TexI(img));
 }
 public Resource.Neg getneg() {
   Drawable d = getattr(Drawable.class);
   if (d instanceof ResDrawable) {
     ResDrawable rd = (ResDrawable) d;
     Resource r;
     if ((r = rd.res.get()) == null) return (null);
     return (r.layer(Resource.negc));
   } else if (d instanceof Layered) {
     Layered l = (Layered) d;
     Resource r;
     if ((r = l.base.get()) == null) return (null);
     return (r.layer(Resource.negc));
   }
   return (null);
 }
 public void newwidget(int id, String type, Coord c, int parent, Object... args)
     throws InterruptedException {
   WidgetFactory f;
   if (type.indexOf('/') >= 0) {
     int ver = -1, p;
     if ((p = type.indexOf(':')) > 0) {
       ver = Integer.parseInt(type.substring(p + 1));
       type = type.substring(0, p);
     }
     Resource res = Resource.load(type, ver);
     res.loadwaitint();
     f = res.layer(Resource.CodeEntry.class).get(WidgetFactory.class);
   } else {
     f = Widget.gettype(type);
   }
   synchronized (this) {
     Widget pwdg = widgets.get(parent);
     if (pwdg == null)
       throw (new UIException("Null parent widget " + parent + " for " + id, type, args));
     Widget wdg = f.create(c, pwdg, args);
     bind(wdg, id);
     wdg.binded();
     if (wdg instanceof MapView) mainview = (MapView) wdg;
   }
 }
Exemplo n.º 5
0
 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 HashSet<Pagina>(ui.sess.glob.paginae);
   }
   boolean ret = true;
   while (!open.isEmpty()) {
     Iterator<Pagina> iter = open.iterator();
     Pagina pag = iter.next();
     iter.remove();
     try {
       Resource r = pag.res();
       AButton ad = r.layer(Resource.action);
       if (ad == null) throw (new PaginaException(pag));
       Pagina parent = paginafor(ad.parent);
       if (parent == p) buf.add(pag);
       else if ((parent != null) && !close.contains(parent)) open.add(parent);
       close.add(pag);
     } catch (Loading e) {
       ret = false;
     }
   }
   return (ret);
 }
Exemplo n.º 6
0
 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));
 }
Exemplo n.º 7
0
 private BufferedImage tileimg(int t, BufferedImage[] texes) {
   BufferedImage img = texes[t];
   if (img == null) {
     Resource r = ui.sess.glob.map.tilesetr(t);
     if (r == null) return (null);
     Resource.Image ir = r.layer(Resource.imgc);
     if (ir == null) return (null);
     img = ir.img;
     texes[t] = img;
   }
   return (img);
 }
 public Factory(int stages, int variants, int num, boolean rev) {
   Resource res = Utils.myres(this.getClass());
   this.neg = res.layer(Resource.negc);
   this.num = num;
   strands = new Tex[stages][variants];
   if (rev) {
     for (Resource.Image img : res.layers(Resource.imgc)) {
       if (img.id != -1) strands[img.id / variants][img.id % variants] = img.tex();
     }
   } else {
     for (Resource.Image img : res.layers(Resource.imgc)) {
       if (img.id != -1) strands[img.id % stages][img.id / stages] = img.tex();
     }
   }
 }
Exemplo n.º 9
0
 public Tileset tileset(int i) {
   synchronized (csets) {
     Tileset cset = (csets[i] == null) ? null : (csets[i].get());
     if (cset == null) {
       Resource res = tilesetr(i);
       if (res == null) return (null);
       try {
         cset = res.layer(Resource.tileset);
       } catch (Loading e) {
         throw (new LoadingMap(e));
       }
       csets[i] = new SoftReference<Tileset>(cset);
     }
     return (cset);
   }
 }
Exemplo n.º 10
0
 public Pagina paginafor(String name) {
   Set<Pagina> pags = ui.sess.glob.paginae;
   for (Pagina p : pags) {
     Resource res = p.res();
     if (res == null) {
       continue;
     }
     AButton act = res.layer(Resource.action);
     if (act == null) {
       continue;
     }
     if (name.equals(act.name)) {
       return p;
     }
   }
   return null;
 }
Exemplo n.º 11
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);
  }
Exemplo n.º 12
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);
    }
  }