Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make texture list a real menu #208

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions config/menus/editing.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// ui_center [ui_edit_button2 [toggle edit mode] [edittoggle]]
ui_center [ui_button "map info" [show_ui mapinfo]]
ui_center [ui_button "geometry and texturing" [show_ui geometry]]
ui_center [ui_button (format "texture list %1" (dobindsearch showtexgui edit)) [clear_ui ; showtexgui ]]
ui_center [ui_button (format "texture list %1" (dobindsearch [show_ui texture_list] edit)) [show_ui texture_list]]
ui_center [ui_button "editing options" [show_ui editoptions]]
ui_center [ui_button "environment settings" [show_ui world]]
ui_center [ui_button "texture variations" [show_ui textures]]
Expand All @@ -25,7 +25,7 @@
//compass "^fs^fcQ^fSuit editing" Q [edittoggle]
compass "m^fs^fca^fSp info" A [show_ui mapinfo]
compass "^fs^fcg^fSeometry and texturing" G [show_ui geometry]
compass "^fs^fct^fSexture list" T [showtexgui]
compass "^fs^fct^fSexture list" T [show_ui texture_list]
compass "e^fs^fcd^fSiting options" D [show_ui editoptions]
compass "^fs^fcw^fSorld variables" W [show_ui world]
compass "texture ^fs^fcv^fSariations" V [show_ui textures]
Expand Down Expand Up @@ -446,8 +446,8 @@
ui_button "view the texture list"
ui_strut 1
ui_spring 1
ui_button (dobindsearch showtexgui edit)
] [clear_ui ; showtexgui ] [saycommand /showtexgui] [ui_tooltip showtexgui]
ui_button (dobindsearch [show_ui texture_list] edit)
] [clear_ui ; show_ui texture_list ] [saycommand /show_ui texture_list] [ui_tooltip "show_ui texture_list"]
ui_edit_button "^fdcycle textures via mouse wheel" [domodifier 6]
ui_edit_button "grab texture from selected face" gettex
ui_edit_button "repeat last texture change across the entire map" [allfaces 0; replace]
Expand Down Expand Up @@ -1291,7 +1291,7 @@
ui_center [ui_text "a blendmap creates smooth transitions on two-layer textures"]
ui_strut 1
ui_list [
ui_button "first look up a texture index in the texture list: #" [clear_ui; showtexgui]
ui_button "first look up a texture index in the texture list: #" [show_ui texture_list]
ui_strut 1
ui_textfield slotnum 4
]
Expand Down Expand Up @@ -2130,3 +2130,11 @@
]
]

new_ui texture_list [
ui_header "Select Texture"
ui_texture_list
] [
if (= $guipasses 0) [
ui_texture_list_init
]
]
2 changes: 1 addition & 1 deletion config/menus/options.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ waitbindtitles = [
]

editbindactions = [
"showtexgui" edittoggle "show_ui edit" "remip" "fullbright 0; patchlight"
"show_ui texture_list" edittoggle "show_ui edit" "remip" "fullbright 0; patchlight"
"fullbright 0; quicklight" "fullbright 0; calclight 1" savemap "changeoutline 1"
[showcompass editing] [show_ui materials] [if $blendpaintmode paintblendmap editdrag]
[if $blendpaintmode rotateblendbrush editextend] selcorners "universaldelta 1" "universaldelta -1"
Expand Down
2 changes: 1 addition & 1 deletion config/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ bind F12 [ screenshot ]
bind COMMA [ show_ui profile 2 ]
bind PERIOD [ show_ui team ]

editbind F1 [ showtexgui ]
editbind F1 [ show_ui texture_list ]
editbind F2 [ edittoggle ]
editbind F3 [ show_ui edit ]
editbind F4 [ remip ]
Expand Down
1 change: 0 additions & 1 deletion src/engine/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,6 @@ extern char *ui_skin_texture, *ui_skin_border_texture, *ui_overlay_texture, *ui_

extern void menu_progress();
extern void menu_main();
extern void menu_texture();
extern bool menuactive();
extern int cleargui(int n = 0, bool skip = true);

Expand Down
17 changes: 15 additions & 2 deletions src/engine/menus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,8 @@ bool showgui(const char *name, int tab, bool *keep)
return true;
}

extern bool closetexgui();
int cleargui(int n, bool skip)
{
if(closetexgui()) n--;
int clear = menustack.length();
if(n>0) clear = min(clear, n);
loopi(clear) if(!pop_ui(skip)) break;
Expand Down Expand Up @@ -975,3 +973,18 @@ void ui_console(int width, int height, const char *init)
}
}
ICOMMAND(0, consolegui, "iis", (int *w, int *h, char *i), ui_console(*w, *h, i));

void ui_texture_list()
{
if(!cgui) return;
void ui_texture_list_(guient &);
ui_texture_list_(*cgui);
}
COMMAND(0, ui_texture_list, "");

void ui_texture_list_init()
{
void ui_texture_list_init_();
ui_texture_list_init_();
}
COMMAND(0, ui_texture_list_init, "");
237 changes: 105 additions & 132 deletions src/engine/octaedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2809,160 +2809,133 @@ FVAR(IDF_PERSIST, thumbsize, 0, 2, 25);

static int lastthumbnail = 0;
static const char *rotations[6] = { "none", "90 degrees", "180 degrees", "270 degrees", "flip x", "flip y" };
struct texturegui : guicb
{
bool menuon;
int menustart, menupage, menutex, rolltex;

texturegui() : menustart(-1), menutex(-1), rolltex(-1) {}

void gui(guient &g, bool firstpass)
{
extern VSlot dummyvslot;
int curtex = menutex, numpages = max((texmru.length() + thumbwidth*thumbheight - 1)/(thumbwidth*thumbheight), 1)-1;
if(autopreviewtexgui && texmru.inrange(rolltex)) curtex = rolltex;
if(menupage > numpages) menupage = numpages;
else if(menupage < 0) menupage = 0;
g.start(menustart, NULL, true);
static int menupage, menutex = -1, rolltex = -1;

void ui_texture_list_(guient &g)
{
bool menuon = true;
extern VSlot dummyvslot;
int curtex = menutex, numpages = max((texmru.length() + thumbwidth*thumbheight - 1)/(thumbwidth*thumbheight), 1)-1;
if(autopreviewtexgui && texmru.inrange(rolltex)) curtex = rolltex;
if(menupage > numpages) menupage = numpages;
else if(menupage < 0) menupage = 0;

uilist(g, {
g.space(2);
if(g.button("\fgauto apply", 0xFFFFFF, "checkbox", 0xFFFFFF, -1, true, autoapplytexgui ? "checkboxon" : NULL, ui_color_checkbox) & GUI_UP)
autoapplytexgui = autoapplytexgui ? 0 : 1;
g.space(2);
if(g.button("\fgauto preview", 0xFFFFFF, "checkbox", 0xFFFFFF, -1, true, autopreviewtexgui ? "checkboxon" : NULL, ui_color_checkbox) & GUI_UP)
autopreviewtexgui = autopreviewtexgui ? 0 : 1;
g.space(2);
if(g.button("\fgauto close", 0xFFFFFF, "checkbox", 0xFFFFFF, -1, true, autoclosetexgui ? "checkboxon" : NULL, autoclosetexgui > 1 ? ui_color_checkbox_two : ui_color_checkbox) & GUI_UP)
autoclosetexgui = autoclosetexgui ? (autoclosetexgui > 1 ? 0 : 2) : 1;
g.space(2);
if(g.button("\foreset order", 0xFFFFFF, NULL)&GUI_UP)
{
int old = texmru.inrange(menutex) ? texmru[menutex] : -1;
resettexmru();
curtex = menutex = rolltex = texmru.find(old);
}
});
g.space(1);
uilist(g, {
uilist(g, {
g.space(2);
if(g.button("\fgauto apply", 0xFFFFFF, "checkbox", 0xFFFFFF, -1, true, autoapplytexgui ? "checkboxon" : NULL, ui_color_checkbox) & GUI_UP)
autoapplytexgui = autoapplytexgui ? 0 : 1;
g.space(2);
if(g.button("\fgauto preview", 0xFFFFFF, "checkbox", 0xFFFFFF, -1, true, autopreviewtexgui ? "checkboxon" : NULL, ui_color_checkbox) & GUI_UP)
autopreviewtexgui = autopreviewtexgui ? 0 : 1;
g.space(2);
if(g.button("\fgauto close", 0xFFFFFF, "checkbox", 0xFFFFFF, -1, true, autoclosetexgui ? "checkboxon" : NULL, autoclosetexgui > 1 ? ui_color_checkbox_two : ui_color_checkbox) & GUI_UP)
autoclosetexgui = autoclosetexgui ? (autoclosetexgui > 1 ? 0 : 2) : 1;
g.space(2);
if(g.button("\foreset order", 0xFFFFFF, NULL)&GUI_UP)
if(texmru.inrange(curtex))
{
int old = texmru.inrange(menutex) ? texmru[menutex] : -1;
resettexmru();
curtex = menutex = rolltex = texmru.find(old);
VSlot &v = lookupvslot(texmru[curtex], false);
g.strut(60);
if(v.slot->sts.empty()) g.texture(dummyvslot, thumbheight*thumbsize/2, false);
else if(!v.slot->loaded && !v.slot->thumbnail)
{
if(totalmillis-lastthumbnail<thumbtime)
g.texture(dummyvslot, thumbheight*thumbsize/2, false); //create an empty space
loadthumbnail(*v.slot);
lastthumbnail = totalmillis;
}
int ret = g.texture(v, thumbheight*thumbsize/2, true);
if(ret&GUI_UP)
{
edittex(texmru[curtex]);
if(autoclosetexgui) menuon = false;
}
g.space(0.5f);
g.textf(" texture #%03d \fa(%s)", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, texmru[curtex], v.slot->sts.empty() ? "<no texture>" : v.slot->sts[0].name);
g.textf(" - scale: \fa%f", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, v.scale);
g.textf(" - rotation: \fa%d (%s)", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, v.rotation, rotations[clamp(v.rotation, 0, 5)]);
g.textf(" - offset: \fa%d %d", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, v.offset.x, v.offset.y);
g.textf(" - scroll: \fa%f %f", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, v.scroll.x, v.scroll.y);
g.textf(" - alpha: \fa%f \fAfront \fa%f \fAback", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, v.alphafront, v.alphaback);
g.textf(" - colour: \fr%f \fg%f \fb%f", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, v.colorscale[0], v.colorscale[1], v.colorscale[2]);
g.textf(" - palette: \fa%d %d", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, v.palette, v.palindex);
g.textf(" - coast: \fa%f", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, v.coastscale);
VSlot &vl = lookupvslot(v.layer);
g.textf(" - layer: \fa%03d (%s)", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, v.layer, vl.slot->sts.empty() ? "<no texture>" : vl.slot->sts[0].name);
loopv(v.params)
{
SlotShaderParam &p = v.params[i];
g.textf(" - shader: \fa%s %f %f %f %f %d %d", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, p.name, p.val[0], p.val[1], p.val[2], p.val[3], v.palette, v.palindex);
}
}
else g.image(textureload(nothumbtex, 3), thumbheight*thumbsize/2, true);
});
g.space(1);
uilist(g, {
uilist(g, {
if(texmru.inrange(curtex))
{
VSlot &v = lookupvslot(texmru[curtex], false);
g.strut(60);
if(v.slot->sts.empty()) g.texture(dummyvslot, thumbheight*thumbsize/2, false);
else if(!v.slot->loaded && !v.slot->thumbnail)
{
if(totalmillis-lastthumbnail<thumbtime)
g.texture(dummyvslot, thumbheight*thumbsize/2, false); //create an empty space
loadthumbnail(*v.slot);
lastthumbnail = totalmillis;
}
int ret = g.texture(v, thumbheight*thumbsize/2, true);
if(ret&GUI_UP)
{
edittex(texmru[curtex]);
if(autoclosetexgui) menuon = false;
}
g.space(0.5f);
g.textf(" texture #%03d \fa(%s)", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, texmru[curtex], v.slot->sts.empty() ? "<no texture>" : v.slot->sts[0].name);
g.textf(" - scale: \fa%f", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, v.scale);
g.textf(" - rotation: \fa%d (%s)", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, v.rotation, rotations[clamp(v.rotation, 0, 5)]);
g.textf(" - offset: \fa%d %d", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, v.offset.x, v.offset.y);
g.textf(" - scroll: \fa%f %f", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, v.scroll.x, v.scroll.y);
g.textf(" - alpha: \fa%f \fAfront \fa%f \fAback", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, v.alphafront, v.alphaback);
g.textf(" - colour: \fr%f \fg%f \fb%f", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, v.colorscale[0], v.colorscale[1], v.colorscale[2]);
g.textf(" - palette: \fa%d %d", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, v.palette, v.palindex);
g.textf(" - coast: \fa%f", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, v.coastscale);
VSlot &vl = lookupvslot(v.layer);
g.textf(" - layer: \fa%03d (%s)", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, v.layer, vl.slot->sts.empty() ? "<no texture>" : vl.slot->sts[0].name);
loopv(v.params)
{
SlotShaderParam &p = v.params[i];
g.textf(" - shader: \fa%s %f %f %f %f %d %d", 0xFFFFFF, NULL, 0, -1, false, NULL, 0xFFFFFF, p.name, p.val[0], p.val[1], p.val[2], p.val[3], v.palette, v.palindex);
}
}
else g.image(textureload(nothumbtex, 3), thumbheight*thumbsize/2, true);
});
g.space(1);
uilistv(g, 2, {
uilist(g, loop(h, thumbheight)
uilistv(g, 2, {
uilist(g, loop(h, thumbheight)
{
uilist(g, loop(w, thumbwidth)
{
uilist(g, loop(w, thumbwidth)
int ti = (menupage*thumbheight+h)*thumbwidth+w;
if(ti<texmru.length())
{
int ti = (menupage*thumbheight+h)*thumbwidth+w;
if(ti<texmru.length())
VSlot &v = lookupvslot(texmru[ti], false);
if(v.slot->sts.empty()) continue;
else if(!v.slot->loaded && !v.slot->thumbnail)
{
VSlot &v = lookupvslot(texmru[ti], false);
if(v.slot->sts.empty()) continue;
else if(!v.slot->loaded && !v.slot->thumbnail)
if(totalmillis-lastthumbnail<thumbtime)
{
if(totalmillis-lastthumbnail<thumbtime)
{
g.texture(dummyvslot, thumbsize, false); //create an empty space
continue;
}
loadthumbnail(*v.slot);
lastthumbnail = totalmillis;
g.texture(dummyvslot, thumbsize, false); //create an empty space
continue;
}
int ret = g.texture(v, thumbsize, true);
if(ret&GUI_UP)
loadthumbnail(*v.slot);
lastthumbnail = totalmillis;
}
int ret = g.texture(v, thumbsize, true);
if(ret&GUI_UP)
{
if(autoapplytexgui && (v.slot->loaded || v.slot->thumbnail!=notexture))
{
if(autoapplytexgui && (v.slot->loaded || v.slot->thumbnail!=notexture))
{
menutex = ti;
edittex(texmru[ti]);
hudshader->set();
if(autoclosetexgui > 1) menuon = false;
}
menutex = ti;
edittex(texmru[ti]);
hudshader->set();
if(autoclosetexgui > 1) menuon = false;
}
else if(ret&GUI_ROLLOVER) rolltex = ti;
}
else g.texture(dummyvslot, thumbsize, false); //create an empty space
});
else if(ret&GUI_ROLLOVER) rolltex = ti;
}
else g.texture(dummyvslot, thumbsize, false); //create an empty space
});
g.slider(menupage, 0, numpages, 0xFFFFFF, NULL, true, true);
});
g.slider(menupage, 0, numpages, 0xFFFFFF, NULL, true, true);
});
g.end();
}
});

void showtextures(bool on)
{
if(on != menuon && (menuon = on))
{
menustart = starttime();
cube &c = lookupcube(sel.o, -sel.grid);
rolltex = -1;
if(texmru.length() > 0)
{
if(!texmru.inrange(menutex = !isempty(c) ? texmru.find(c.texture[sel.orient]) : texmru.find(lasttex)))
menutex = 0;
menupage = clamp(menutex, 0, texmru.length()-1)/(thumbwidth*thumbheight);
}
else menutex = menupage = 0;
}
}
if(!menuon) cleargui(1);
}

void show()
void ui_texture_list_init_()
{
cube &c = lookupcube(sel.o, -sel.grid);
rolltex = -1;
if(texmru.length() > 0)
{
if(!menuon) return;
filltexlist();
if(!editmode) menuon = false;
else UI::addcb(this);
if(!texmru.inrange(menutex = !isempty(c) ? texmru.find(c.texture[sel.orient]) : texmru.find(lasttex)))
menutex = 0;
menupage = clamp(menutex, 0, texmru.length()-1)/(thumbwidth*thumbheight);
}
} gui;

void menu_texture() { gui.show(); }
bool closetexgui() { if(gui.menuon) { gui.menuon = false; return true; } return false; }

void showtexgui(int *n)
{
if(!editmode) { conoutf("\froperation only allowed in edit mode"); return; }
gui.showtextures(*n==0 ? !gui.menuon : *n==1);
else menutex = menupage = 0;
}

COMMAND(0, showtexgui, "i"); // 0/noargs = toggle, 1 = on, other = off - will autoclose when exiting editmode

void rendertexturepanel(int w, int h)
{
if((texpaneltimer -= curtime)>0 && editmode)
Expand Down
1 change: 0 additions & 1 deletion src/engine/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,6 @@ namespace UI
if(progressing) menu_progress();
else
{
menu_texture();
hud::gamemenus();
menu_main();
}
Expand Down