2007-11-20 22:00:00 +01:00
|
|
|
///////////////////////////////////////////////
|
|
|
|
// Functions Source File
|
|
|
|
///////////////////////
|
|
|
|
// This file belongs to dpmod/darkplaces
|
|
|
|
// AK contains all menu controlling stuff (sub-menus)
|
|
|
|
///////////////////////////////////////////////
|
|
|
|
|
|
|
|
// raise function
|
|
|
|
/* template
|
|
|
|
|
|
|
|
void(entity ent) raise_x =
|
|
|
|
{
|
|
|
|
entity old;
|
|
|
|
if(!ent._x)
|
|
|
|
return;
|
|
|
|
|
2007-11-22 22:00:00 +01:00
|
|
|
old = pev;
|
|
|
|
pev = ent;
|
|
|
|
pev._x();
|
|
|
|
pev = old;
|
2007-11-20 22:00:00 +01:00
|
|
|
};
|
|
|
|
*/
|
|
|
|
|
|
|
|
void(entity ent) raise_reinit =
|
|
|
|
{
|
|
|
|
entity old;
|
|
|
|
if(!ent._reinit)
|
|
|
|
return;
|
|
|
|
|
2007-11-22 22:00:00 +01:00
|
|
|
old = pev;
|
|
|
|
pev = ent;
|
|
|
|
pev._reinit();
|
|
|
|
pev = old;
|
2007-11-20 22:00:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void(entity ent) raise_destroy =
|
|
|
|
{
|
|
|
|
entity old;
|
|
|
|
if(!ent._destroy)
|
|
|
|
return;
|
|
|
|
|
2007-11-22 22:00:00 +01:00
|
|
|
old = pev;
|
|
|
|
pev = ent;
|
|
|
|
pev._destroy();
|
|
|
|
pev = old;
|
2007-11-20 22:00:00 +01:00
|
|
|
};
|
|
|
|
|
2007-11-23 22:00:00 +01:00
|
|
|
void(entity ent, float keynr, string ascii) raise_key =
|
2007-11-20 22:00:00 +01:00
|
|
|
{
|
|
|
|
entity old;
|
|
|
|
if(!ent._key)
|
|
|
|
return;
|
|
|
|
|
2007-11-22 22:00:00 +01:00
|
|
|
old = pev;
|
|
|
|
pev = ent;
|
|
|
|
pev._key(keynr, ascii);
|
|
|
|
pev = old;
|
2007-11-20 22:00:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void(entity ent) raise_draw =
|
|
|
|
{
|
|
|
|
entity old;
|
|
|
|
if(!ent._draw)
|
|
|
|
return;
|
|
|
|
|
2007-11-22 22:00:00 +01:00
|
|
|
old = pev;
|
|
|
|
pev = ent;
|
|
|
|
pev._draw();
|
|
|
|
pev = old;
|
2007-11-20 22:00:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void(entity ent) raise_mouse_enter =
|
|
|
|
{
|
|
|
|
entity old;
|
|
|
|
if(!ent._mouse_enter)
|
|
|
|
return;
|
|
|
|
|
2007-11-22 22:00:00 +01:00
|
|
|
old = pev;
|
|
|
|
pev = ent;
|
|
|
|
pev._mouse_enter();
|
|
|
|
pev = old;
|
2007-11-20 22:00:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void(entity ent) raise_mouse_leave =
|
|
|
|
{
|
|
|
|
entity old;
|
|
|
|
if(!ent._mouse_leave)
|
|
|
|
return;
|
|
|
|
|
2007-11-22 22:00:00 +01:00
|
|
|
old = pev;
|
|
|
|
pev = ent;
|
|
|
|
pev._mouse_leave();
|
|
|
|
pev = old;
|
2007-11-20 22:00:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void(entity ent) raise_action =
|
|
|
|
{
|
|
|
|
entity old;
|
|
|
|
if(!ent._action)
|
|
|
|
return;
|
|
|
|
|
2007-11-22 22:00:00 +01:00
|
|
|
old = pev;
|
|
|
|
pev = ent;
|
|
|
|
pev._action();
|
|
|
|
pev = old;
|
2007-11-20 22:00:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void(entity ent) raise_refresh =
|
|
|
|
{
|
|
|
|
entity old;
|
|
|
|
if(!ent._refresh)
|
|
|
|
return;
|
|
|
|
|
2007-11-22 22:00:00 +01:00
|
|
|
old = pev;
|
|
|
|
pev = ent;
|
|
|
|
pev._refresh();
|
|
|
|
pev = old;
|
2007-11-20 22:00:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// safe call control function functions
|
|
|
|
// default control functions
|
|
|
|
/* template
|
|
|
|
|
|
|
|
void(void) ctcall_x =
|
|
|
|
{
|
2007-11-22 22:00:00 +01:00
|
|
|
if(pev.x)
|
|
|
|
pev.x();
|
2007-11-20 22:00:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
*/
|
|
|
|
void(void) ctcall_init =
|
|
|
|
{
|
2007-11-22 22:00:00 +01:00
|
|
|
if(pev.init)
|
|
|
|
pev.init();
|
2007-11-20 22:00:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void(void) ctcall_reinit =
|
|
|
|
{
|
2007-11-22 22:00:00 +01:00
|
|
|
if(pev.reinit)
|
|
|
|
pev.reinit();
|
2007-11-20 22:00:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void(void) ctcall_destroy =
|
|
|
|
{
|
2007-11-22 22:00:00 +01:00
|
|
|
if(pev.destroy)
|
|
|
|
pev.destroy();
|
2007-11-20 22:00:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
float(float keynr, float ascii) ctcall_key =
|
|
|
|
{
|
2007-11-22 22:00:00 +01:00
|
|
|
if(pev.key)
|
|
|
|
return pev.key(keynr, ascii);
|
2007-11-20 22:00:00 +01:00
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
void(void) ctcall_draw =
|
|
|
|
{
|
2007-11-22 22:00:00 +01:00
|
|
|
if(pev.draw)
|
|
|
|
pev.draw();
|
2007-11-20 22:00:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void(void) ctcall_mouse_enter =
|
|
|
|
{
|
2007-11-22 22:00:00 +01:00
|
|
|
if(pev.mouse_enter)
|
|
|
|
pev.mouse_enter();
|
2007-11-20 22:00:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void(void) ctcall_mouse_leave =
|
|
|
|
{
|
2007-11-22 22:00:00 +01:00
|
|
|
if(pev.mouse_leave)
|
|
|
|
pev.mouse_leave();
|
2007-11-20 22:00:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void(void) ctcall_action =
|
|
|
|
{
|
2007-11-22 22:00:00 +01:00
|
|
|
if(pev.action)
|
|
|
|
pev.action();
|
2007-11-20 22:00:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void(void) ctcall_refresh =
|
|
|
|
{
|
2007-11-22 22:00:00 +01:00
|
|
|
if(pev.refresh)
|
|
|
|
pev.refresh();
|
2007-11-20 22:00:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// default control functions
|
|
|
|
/* template (expect defct_key)
|
|
|
|
|
|
|
|
void(void) defct_x =
|
|
|
|
{
|
|
|
|
ctcall_x();
|
|
|
|
};
|
|
|
|
|
|
|
|
*/
|
|
|
|
// defct_init not needed cause its the same like the type function
|
|
|
|
|
|
|
|
void(void) defct_reinit =
|
|
|
|
{
|
|
|
|
ctcall_reinit();
|
|
|
|
};
|
|
|
|
|
|
|
|
void(void) defct_destroy =
|
|
|
|
{
|
|
|
|
ctcall_destroy();
|
|
|
|
};
|
|
|
|
|
|
|
|
void(float keynr, float ascii) defct_key =
|
|
|
|
{
|
|
|
|
if(!ctcall_key(keynr, ascii))
|
|
|
|
def_keyevent(keynr, ascii);
|
|
|
|
};
|
|
|
|
|
|
|
|
void(void) defct_draw =
|
|
|
|
{
|
|
|
|
ctcall_draw();
|
|
|
|
};
|
|
|
|
|
|
|
|
void(void) defct_mouse_enter =
|
|
|
|
{
|
|
|
|
ctcall_mouse_enter();
|
|
|
|
};
|
|
|
|
|
|
|
|
void(void) defct_mouse_leave =
|
|
|
|
{
|
|
|
|
ctcall_mouse_leave();
|
|
|
|
};
|
|
|
|
|
|
|
|
void(void) defct_action =
|
|
|
|
{
|
|
|
|
ctcall_action();
|
|
|
|
};
|
|
|
|
|
|
|
|
void(void) defct_refresh =
|
|
|
|
{
|
|
|
|
// do first the own fresh stuff and *then* call refresh
|
|
|
|
def_refresh();
|
|
|
|
ctcall_refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
// default refresh function
|
|
|
|
void(void) def_refresh =
|
|
|
|
{
|
|
|
|
// refresh stuff
|
2007-11-22 22:00:00 +01:00
|
|
|
if(pev.flag & FLAG_AUTOSETCLICK)
|
2007-11-20 22:00:00 +01:00
|
|
|
{
|
2007-11-22 22:00:00 +01:00
|
|
|
pev.click_pos = pev.pos;
|
|
|
|
pev.click_size = pev.size;
|
2007-11-20 22:00:00 +01:00
|
|
|
}
|
2007-11-22 22:00:00 +01:00
|
|
|
if(pev.flag & FLAG_AUTOSETCLIP)
|
2007-11-20 22:00:00 +01:00
|
|
|
{
|
2007-11-22 22:00:00 +01:00
|
|
|
pev.clip_pos = pev.pos;
|
|
|
|
pev.clip_size = pev.size;
|
2007-11-20 22:00:00 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// default key function
|
|
|
|
void(float keynr, float ascii) def_keyevent =
|
|
|
|
{
|
|
|
|
if(keynr == K_ESCAPE)
|
|
|
|
{
|
|
|
|
// move up to the parent
|
|
|
|
menu_selectup();
|
|
|
|
} else if(keynr == K_LEFTARROW || keynr == K_UPARROW)
|
|
|
|
{
|
|
|
|
// move to the previous element
|
|
|
|
menu_loopprev();
|
|
|
|
|
2007-11-22 22:00:00 +01:00
|
|
|
if(menu_selected == pev)
|
2007-11-20 22:00:00 +01:00
|
|
|
{
|
2007-11-22 22:00:00 +01:00
|
|
|
if(pev._prev)
|
2007-11-20 22:00:00 +01:00
|
|
|
{
|
2007-11-22 22:00:00 +01:00
|
|
|
menu_selected = pev._prev;
|
2007-11-20 22:00:00 +01:00
|
|
|
menu_selectdown();
|
2007-11-22 22:00:00 +01:00
|
|
|
if(menu_selected != pev._prev)
|
2007-11-20 22:00:00 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-11-22 22:00:00 +01:00
|
|
|
menu_selected = pev;
|
2007-11-20 22:00:00 +01:00
|
|
|
}
|
|
|
|
} else if(keynr == K_RIGHTARROW || keynr == K_DOWNARROW)
|
|
|
|
{
|
|
|
|
// move to the next element
|
|
|
|
menu_loopnext();
|
|
|
|
|
2007-11-22 22:00:00 +01:00
|
|
|
if(menu_selected == pev)
|
2007-11-20 22:00:00 +01:00
|
|
|
{
|
2007-11-22 22:00:00 +01:00
|
|
|
if(pev._next)
|
2007-11-20 22:00:00 +01:00
|
|
|
{
|
2007-11-22 22:00:00 +01:00
|
|
|
menu_selected = pev._next;
|
2007-11-20 22:00:00 +01:00
|
|
|
menu_selectdown();
|
2007-11-22 22:00:00 +01:00
|
|
|
if(menu_selected != pev._next)
|
2007-11-20 22:00:00 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-11-22 22:00:00 +01:00
|
|
|
menu_selected = pev;
|
2007-11-20 22:00:00 +01:00
|
|
|
}
|
|
|
|
} else if(keynr == K_ENTER || keynr == K_MOUSE1)
|
|
|
|
{
|
2007-11-22 22:00:00 +01:00
|
|
|
eprint(pev);
|
2007-11-20 22:00:00 +01:00
|
|
|
print("Action called\n");
|
2007-11-22 22:00:00 +01:00
|
|
|
if(pev._action)
|
|
|
|
pev._action();
|
2007-11-20 22:00:00 +01:00
|
|
|
// move to the child menu
|
|
|
|
menu_selectdown();
|
|
|
|
} else if(keynr == K_TAB)
|
|
|
|
{
|
|
|
|
// select next and try to "go" down
|
2007-11-22 22:00:00 +01:00
|
|
|
if(pev._next)
|
2007-11-20 22:00:00 +01:00
|
|
|
{
|
2007-11-22 22:00:00 +01:00
|
|
|
menu_selected = pev._next;
|
2007-11-20 22:00:00 +01:00
|
|
|
menu_selectdown();
|
2007-11-22 22:00:00 +01:00
|
|
|
if(menu_selected != pev._next)
|
2007-11-20 22:00:00 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-11-22 22:00:00 +01:00
|
|
|
if(pev._prev)
|
2007-11-20 22:00:00 +01:00
|
|
|
{
|
2007-11-22 22:00:00 +01:00
|
|
|
menu_selected = pev._prev;
|
2007-11-20 22:00:00 +01:00
|
|
|
menu_selectdown();
|
2007-11-22 22:00:00 +01:00
|
|
|
if(menu_selected != pev._prev)
|
2007-11-20 22:00:00 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-11-22 22:00:00 +01:00
|
|
|
menu_selected = pev;
|
2007-11-20 22:00:00 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// a rect is described by the top-left point and its size
|
|
|
|
float(vector point, vector r_pos, vector r_size) inrect =
|
|
|
|
{
|
|
|
|
if(point_x < r_pos_x)
|
|
|
|
return false;
|
|
|
|
if(point_y < r_pos_y)
|
|
|
|
return false;
|
|
|
|
if(point_x > (r_pos_x + r_size_x))
|
|
|
|
return false;
|
|
|
|
if(point_y > (r_pos_y + r_size_y))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
vector(vector r_pos, vector r_size, vector c_pos, vector c_size) cliprectpos =
|
|
|
|
{
|
|
|
|
vector v;
|
|
|
|
|
|
|
|
// clip r_pos only
|
|
|
|
v_x = max(c_pos_x, r_pos_x);
|
|
|
|
v_y = max(c_pos_y, r_pos_y);
|
|
|
|
|
|
|
|
return v;
|
|
|
|
};
|
|
|
|
|
|
|
|
vector(vector r_pos, vector r_size, vector c_pos, vector c_size) cliprectsize =
|
|
|
|
{
|
|
|
|
vector v;
|
|
|
|
// safe version
|
|
|
|
//r_size_x = bound(c_pos_x, r_pos_x + r_size_x, c_pos_x + c_size_x) - bound(c_pos_x, r_pos_x, c_pos_x + c_size_x);
|
|
|
|
//r_size_y = bound(c_pos_y, r_pos_y + r_size_y, c_pos_y + c_size_y) - bound(c_pos_y, r_pos_y, c_pos_y + c_size_y);
|
|
|
|
v_x = min(c_pos_x + c_size_x, r_pos_x + r_size_x) - max(c_pos_x, r_pos_x);
|
|
|
|
v_y = min(c_pos_y + c_size_y, r_pos_y + r_size_y) - max(c_pos_y, r_pos_y);
|
|
|
|
|
|
|
|
if(v_x <= 0 || v_y <= 0)
|
|
|
|
v = '0 0 0';
|
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
void(void(void) reinitevent, void(void) destroyevent, void(float key, float ascii) keyevent, void(void) drawevent, void(void) mouse_enterevent, void(void) mouse_leaveevent, void(void) actionevent, void(void) refreshevent)
|
|
|
|
item_init =
|
|
|
|
{
|
2007-11-22 22:00:00 +01:00
|
|
|
pev._reinit = reinitevent;
|
|
|
|
pev._destroy = destroyevent;
|
2007-11-20 22:00:00 +01:00
|
|
|
|
2007-11-22 22:00:00 +01:00
|
|
|
pev._key = keyevent;
|
|
|
|
pev._draw = drawevent;
|
|
|
|
pev._mouse_enter = mouse_enterevent;
|
|
|
|
pev._mouse_leave = mouse_leaveevent;
|
|
|
|
pev._action = actionevent;
|
|
|
|
pev._refresh = refreshevent;
|
2007-11-20 22:00:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
float(float tfactor) getflicker =
|
|
|
|
{
|
|
|
|
// TODO: use tfactor to vary the result
|
|
|
|
return (sin(tfactor * time) + 1)/2;
|
|
|
|
};
|
|
|
|
|
|
|
|
float(string s) getaltstringcount =
|
|
|
|
{
|
|
|
|
float len;
|
|
|
|
float count;
|
|
|
|
float pos;
|
|
|
|
|
|
|
|
len = strlen(s);
|
|
|
|
count = 0;
|
|
|
|
for(pos = 0; pos < len; pos = pos + 1)
|
|
|
|
{
|
|
|
|
if(substring(s,pos,1) == "'")
|
|
|
|
count = count + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mod(count,2) == 1)
|
|
|
|
return 0; // bad string
|
|
|
|
|
|
|
|
return (count / 2);
|
|
|
|
};
|
|
|
|
|
|
|
|
string(float n, string s) getaltstring =
|
|
|
|
{
|
|
|
|
float start, length;
|
|
|
|
float tmp;
|
|
|
|
|
|
|
|
n = rint(n);
|
|
|
|
|
|
|
|
if(n >= getaltstringcount(s) || n < 0)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
// go to the beginning of the altstring
|
|
|
|
tmp = 0;
|
|
|
|
for(start = 0;tmp <= n * 2 ; start = start + 1)
|
|
|
|
{
|
|
|
|
if(substring(s, start, 1) == "'")
|
|
|
|
tmp = tmp + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(length = 0; substring(s, start + length, 1) != "'"; length = length + 1)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
return substring(s, start, length);
|
|
|
|
};
|
|
|
|
|