Skip to content

Commit

Permalink
svn r6427
Browse files Browse the repository at this point in the history
  • Loading branch information
sauerbraten committed Nov 29, 2020
1 parent 75de54a commit dd0b3a9
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 36 deletions.
33 changes: 24 additions & 9 deletions src/engine/3dgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ static float cursorx = 0.5f, cursory = 0.5f;
VARP(guiautotab, 6, 16, 40);
VARP(guiclicktab, 0, 0, 1);
VARP(guifadein, 0, 1, 1);
VARP(guipreviewtime, 0, 15, 1000);

static int lastpreview = 0;

static inline bool throttlepreview(bool loaded)
{
if(loaded) return true;
if(totalmillis - lastpreview < guipreviewtime) return false;
lastpreview = totalmillis;
return true;
}

struct gui : g3d_gui
{
Expand Down Expand Up @@ -287,12 +298,12 @@ struct gui : g3d_gui
return windowhit==this && hitx>=x && hity>=y && hitx<x+w && hity<y+h;
}

int image(Texture *t, float scale, bool overlaid)
int image(Texture *t, float scale, const char *overlaid)
{
autotab();
if(scale==0) scale = 1;
int size = (int)(scale*2*FONTH)-SHADOW;
if(visible()) icon_(t, overlaid, curx, cury, size, ishit(size+SHADOW, size+SHADOW));
if(visible()) icon_(t, overlaid!=NULL, curx, cury, size, ishit(size+SHADOW, size+SHADOW), overlaid);
return layout(size+SHADOW, size+SHADOW);
}

Expand All @@ -305,12 +316,12 @@ struct gui : g3d_gui
return layout(size+SHADOW, size+SHADOW);
}

int playerpreview(int model, int team, int weap, float sizescale, bool overlaid)
int playerpreview(int model, int team, int weap, float sizescale, const char *overlaid)
{
autotab();
if(sizescale==0) sizescale = 1;
int size = (int)(sizescale*2*FONTH)-SHADOW;
if(visible())
if(model>=0 && visible())
{
bool hit = ishit(size+SHADOW, size+SHADOW);
float xs = size, ys = size, xi = curx, yi = cury;
Expand Down Expand Up @@ -341,6 +352,7 @@ struct gui : g3d_gui
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
hudshader->set();
}
if(overlaid[0]) text_(overlaid, xi + xs/12, yi + ys - ys/12 - FONTH, hit ? 0xFF0000 : 0xFFFFFF, hit, hit);
if(!overlaytex) overlaytex = textureload("data/guioverlay.png", 3);
gle::color(light);
glBindTexture(GL_TEXTURE_2D, overlaytex->id);
Expand All @@ -350,12 +362,12 @@ struct gui : g3d_gui
return layout(size+SHADOW, size+SHADOW);
}

int modelpreview(const char *name, int anim, float sizescale, bool overlaid)
int modelpreview(const char *name, int anim, float sizescale, const char *overlaid, bool throttle)
{
autotab();
if(sizescale==0) sizescale = 1;
int size = (int)(sizescale*2*FONTH)-SHADOW;
if(visible())
if(name[0] && visible() && (!throttle || throttlepreview(modelloaded(name))))
{
bool hit = ishit(size+SHADOW, size+SHADOW);
float xs = size, ys = size, xi = curx, yi = cury;
Expand Down Expand Up @@ -397,6 +409,7 @@ struct gui : g3d_gui
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
hudshader->set();
}
if(overlaid[0]) text_(overlaid, xi + xs/12, yi + ys - ys/12 - FONTH, hit ? 0xFF0000 : 0xFFFFFF, hit, hit);
if(!overlaytex) overlaytex = textureload("data/guioverlay.png", 3);
gle::color(light);
glBindTexture(GL_TEXTURE_2D, overlaytex->id);
Expand All @@ -406,12 +419,12 @@ struct gui : g3d_gui
return layout(size+SHADOW, size+SHADOW);
}

int prefabpreview(const char *prefab, const vec &color, float sizescale, bool overlaid)
int prefabpreview(const char *prefab, const vec &color, float sizescale, const char *overlaid, bool throttle)
{
autotab();
if(sizescale==0) sizescale = 1;
int size = (int)(sizescale*2*FONTH)-SHADOW;
if(visible())
if(prefab[0] && visible() && (!throttle || throttlepreview(prefabloaded(prefab))))
{
bool hit = ishit(size+SHADOW, size+SHADOW);
float xs = size, ys = size, xi = curx, yi = cury;
Expand Down Expand Up @@ -442,6 +455,7 @@ struct gui : g3d_gui
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
hudshader->set();
}
if(overlaid[0]) text_(overlaid, xi + FONTH/2, yi + FONTH/2, hit ? 0xFF0000 : 0xFFFFFF, hit, hit);
if(!overlaytex) overlaytex = textureload("data/guioverlay.png", 3);
gle::color(light);
glBindTexture(GL_TEXTURE_2D, overlaytex->id);
Expand Down Expand Up @@ -638,7 +652,7 @@ struct gui : g3d_gui
hudshader->set();
}

void icon_(Texture *t, bool overlaid, int x, int y, int size, bool hit)
void icon_(Texture *t, bool overlaid, int x, int y, int size, bool hit, const char *title = NULL)
{
float scale = float(size)/max(t->xs, t->ys); //scale and preserve aspect ratio
float xs = t->xs*scale, ys = t->ys*scale;
Expand All @@ -660,6 +674,7 @@ struct gui : g3d_gui
glBindTexture(GL_TEXTURE_2D, overlaytex->id);
gle::color(light);
rect_(x, y, xs, ys, 0);
if(title) text_(title, x + xs/12, y + ys - ys/12 - FONTH, hit ? 0xFF0000 : 0xFFFFFF, hit && actionon, hit);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/engine/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ extern void commitchanges(bool force = false);
extern void rendereditcursor();
extern void tryedit();

extern bool prefabloaded(const char *name);
extern void renderprefab(const char *name, const vec &o, float yaw, float pitch, float roll, float size = 1, const vec &color = vec(1, 1, 1));
extern void previewprefab(const char *name, const vec &color);

Expand Down Expand Up @@ -489,6 +490,7 @@ extern void startmap(const char *name);
// rendermodel
struct mapmodelinfo { string name; model *m; };

extern bool modelloaded(const char *name);
extern void findanims(const char *pattern, vector<int> &anims);
extern void loadskin(const char *dir, const char *altdir, Texture *&skin, Texture *&masks);
extern mapmodelinfo *getmminfo(int i);
Expand Down
46 changes: 30 additions & 16 deletions src/engine/menus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,27 @@ static vec menupos;
static int menustart = 0;
static g3d_gui *cgui = NULL;

VAR(guitabnum, 1, 0, 0);

struct menu : g3d_callback
{
char *name, *header;
uint *contents, *init, *onclear;
bool showtab;
bool showtab, keeptab;
int menutab;

menu() : name(NULL), header(NULL), contents(NULL), init(NULL), onclear(NULL), showtab(true), menutab(1) {}
menu() : name(NULL), header(NULL), contents(NULL), init(NULL), onclear(NULL), showtab(true), keeptab(false), menutab(1) {}

void gui(g3d_gui &g, bool firstpass)
{
cgui = &g;
guitabnum = menutab;
cgui->start(menustart, 0.03f, showtab ? &menutab : NULL);
if(showtab) cgui->tab(header ? header : name, GUI_TITLE_COLOR);
execute(contents);
cgui->end();
cgui = NULL;
guitabnum = 0;
}

virtual void clear()
Expand Down Expand Up @@ -149,7 +153,7 @@ void pushgui(menu *m, int pos = -1)
else guistack.insert(pos, m);
if(pos < 0 || pos==guistack.length()-1)
{
m->menutab = 1;
if(!m->keeptab) m->menutab = 1;
menustart = totalmillis;
}
if(m->init) execute(m->init);
Expand Down Expand Up @@ -258,7 +262,7 @@ void guibutton(char *name, char *action, char *icon)
}
}

void guiimage(char *path, char *action, float *scale, int *overlaid, char *alt)
void guiimage(char *path, char *action, float *scale, int *overlaid, char *alt, char *title)
{
if(!cgui) return;
Texture *t = textureload(path, 0, true, false);
Expand All @@ -267,7 +271,7 @@ void guiimage(char *path, char *action, float *scale, int *overlaid, char *alt)
if(alt[0]) t = textureload(alt, 0, true, false);
if(t==notexture) return;
}
int ret = cgui->image(t, *scale, *overlaid!=0);
int ret = cgui->image(t, *scale, *overlaid!=0 ? title : NULL);
if(ret&G3D_UP)
{
if(*action)
Expand Down Expand Up @@ -582,15 +586,15 @@ COMMAND(guionclear, "s");
COMMAND(guistayopen, "e");
COMMAND(guinoautotab, "e");
COMMAND(guimerge, "e");

ICOMMAND(guikeeptab, "b", (int *keeptab), if(guistack.length()) guistack.last()->keeptab = *keeptab!=0);
COMMAND(guilist, "e");
COMMAND(guialign, "ie");
COMMAND(guititle, "s");
COMMAND(guibar,"");
COMMAND(guistrut,"fi");
COMMAND(guispring, "i");
COMMAND(guicolumn, "i");
COMMAND(guiimage,"ssfis");
COMMAND(guiimage,"ssfiss");
COMMAND(guislider,"sbbs");
COMMAND(guilistslider, "sss");
COMMAND(guinameslider, "ssss");
Expand All @@ -604,10 +608,10 @@ COMMAND(guieditor, "siii");
COMMAND(guicolor, "i");
COMMAND(guitextbox, "siii");

void guiplayerpreview(int *model, int *team, int *weap, char *action, float *scale, int *overlaid)
void guiplayerpreview(int *model, int *team, int *weap, char *action, float *scale, int *overlaid, char *title)
{
if(!cgui) return;
int ret = cgui->playerpreview(*model, *team, *weap, *scale, *overlaid!=0);
int ret = cgui->playerpreview(*model, *team, *weap, *scale, *overlaid!=0 ? title : NULL);
if(ret&G3D_UP)
{
if(*action)
Expand All @@ -617,9 +621,9 @@ void guiplayerpreview(int *model, int *team, int *weap, char *action, float *sca
}
}
}
COMMAND(guiplayerpreview, "iiisfi");
COMMAND(guiplayerpreview, "iiisfis");

void guimodelpreview(char *model, char *animspec, char *action, float *scale, int *overlaid)
void guimodelpreview(char *model, char *animspec, char *action, float *scale, int *overlaid, char *title, int *throttle)
{
if(!cgui) return;
int anim = ANIM_ALL;
Expand All @@ -638,7 +642,7 @@ void guimodelpreview(char *model, char *animspec, char *action, float *scale, in
if(anims.length()) anim = anims[0];
}
}
int ret = cgui->modelpreview(model, anim|ANIM_LOOP, *scale, *overlaid!=0);
int ret = cgui->modelpreview(model, anim|ANIM_LOOP, *scale, *overlaid!=0 ? title : NULL, *throttle!=0);
if(ret&G3D_UP)
{
if(*action)
Expand All @@ -647,13 +651,18 @@ void guimodelpreview(char *model, char *animspec, char *action, float *scale, in
if(shouldclearmenu) clearlater = true;
}
}
else if(ret&G3D_ROLLOVER)
{
alias("guirolloverpreviewname", model);
alias("guirolloverpreviewaction", action);
}
}
COMMAND(guimodelpreview, "sssfi");
COMMAND(guimodelpreview, "sssfisi");

void guiprefabpreview(char *prefab, int *color, char *action, float *scale, int *overlaid)
void guiprefabpreview(char *prefab, int *color, char *action, float *scale, int *overlaid, char *title, int *throttle)
{
if(!cgui) return;
int ret = cgui->prefabpreview(prefab, vec::hexcolor(*color), *scale, *overlaid!=0);
int ret = cgui->prefabpreview(prefab, vec::hexcolor(*color), *scale, *overlaid!=0 ? title : NULL, *throttle!=0);
if(ret&G3D_UP)
{
if(*action)
Expand All @@ -662,8 +671,13 @@ void guiprefabpreview(char *prefab, int *color, char *action, float *scale, int
if(shouldclearmenu) clearlater = true;
}
}
else if(ret&G3D_ROLLOVER)
{
alias("guirolloverpreviewname", prefab);
alias("guirolloverpreviewaction", action);
}
}
COMMAND(guiprefabpreview, "sisfi");
COMMAND(guiprefabpreview, "sisfisi");

struct change
{
Expand Down
39 changes: 32 additions & 7 deletions src/engine/octaedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,11 @@ void pasteblock(block3 &b, selinfo &sel, bool local)
sel.orient = o;
}

bool prefabloaded(const char *name)
{
return prefabs.access(name) != NULL;
}

prefab *loadprefab(const char *name, bool msg = true)
{
prefab *b = prefabs.access(name);
Expand Down Expand Up @@ -2754,13 +2759,16 @@ COMMAND(editmat, "ss");

extern int menudistance, menuautoclose;

VARP(texguiwidth, 1, 16, 1000);
VARP(texguiwidth, 1, 15, 1000);
VARP(texguiheight, 1, 8, 1000);
FVARP(texguiscale, 0.1f, 1.5f, 10.0f);
VARP(texguitime, 0, 15, 1000);
VARP(texguiname, 0, 1, 1);

static int lastthumbnail = 0;

VARP(texgui2d, 0, 1, 1);
VAR(texguinum, 1, -1, 0);

struct texturegui : g3d_callback
{
Expand All @@ -2773,11 +2781,14 @@ struct texturegui : g3d_callback
void gui(g3d_gui &g, bool firstpass)
{
int origtab = menutab, numtabs = max((slots.length() + texguiwidth*texguiheight - 1)/(texguiwidth*texguiheight), 1);
if(!firstpass) texguinum = -1;
g.start(menustart, 0.04f, &menutab);
bool oldautotab = g.allowautotab(false);
loopi(numtabs)
{
g.tab(!i ? "Textures" : NULL, 0xAAFFAA);
g.tab(!i ? "Textures" : NULL, 0xFFDD88);
if(i+1 != origtab) continue; //don't load textures on non-visible tabs!
Slot *rollover = NULL;
loop(h, texguiheight)
{
g.pushlist();
Expand All @@ -2794,46 +2805,60 @@ struct texturegui : g3d_callback
{
if(totalmillis-lastthumbnail<texguitime)
{
g.texture(dummyvslot, 1.0, false); //create an empty space
g.texture(dummyvslot, texguiscale, false); //create an empty space
continue;
}
loadthumbnail(slot);
lastthumbnail = totalmillis;
}
if(g.texture(vslot, 1.0f, true)&G3D_UP && (slot.loaded || slot.thumbnail!=notexture))
int ret = g.texture(vslot, texguiscale, true);
if(ret&G3D_ROLLOVER) { rollover = &slot; texguinum = ti; }
if(ret&G3D_UP && (slot.loaded || slot.thumbnail!=notexture))
{
edittex(vslot.index);
hudshader->set();
}
}
else
{
g.texture(dummyvslot, 1.0, false); //create an empty space
g.texture(dummyvslot, texguiscale, false); //create an empty space
}
}
g.poplist();
}
if(texguiname)
{
if(rollover)
{
defformatstring(name, "%d \f7:\fc %s", texguinum, rollover->sts[0].name);
g.title(name, 0xFFDD88);
}
else g.space(1);
}
}
g.allowautotab(oldautotab);
g.end();
}

void showtextures(bool on)
{
if(on != menuon && (menuon = on))
if(on == menuon) return;
if((menuon = on))
{
if(menustart <= lasttexmillis)
menutab = 1+clamp(lookupvslot(lasttex, false).slot->index, 0, slots.length()-1)/(texguiwidth*texguiheight);
menupos = menuinfrontofplayer();
menustart = starttime();
}
else texguinum = -1;
}

void show()
{
if(!menuon) return;
filltexlist();
extern int usegui2d;
if(!editmode || ((!texgui2d || !usegui2d) && camera1->o.dist(menupos) > menuautoclose)) menuon = false;
if(!editmode || ((!texgui2d || !usegui2d) && camera1->o.dist(menupos) > menuautoclose)) { menuon = false; texguinum = -1; }
else g3d_addgui(this, menupos, texgui2d ? GUI_2D : 0);
}
} gui;
Expand Down
Loading

0 comments on commit dd0b3a9

Please sign in to comment.