mirror of
https://github.com/1dot13/source.git
synced 2026-07-22 13:40:22 +02:00
o The popup will list attachments available for the given slot on the current weapon. Ones not in sector inventory will be greyed out. o It should show up after clicking on an empty attachment slot, provided these criteria are met: --> we are on the mapscreen --> the sector inventory is open --> the selected merc is in this sector --> there is no combat in this sector git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@4620 3b4a5df2-a311-0410-b5c6-a8a6f20db521
171 lines
4.0 KiB
C++
171 lines
4.0 KiB
C++
#ifndef POPUP_CALLBACK_CLASS
|
|
#define POPUP_CALLBACK_CLASS
|
|
|
|
class popupCallback;
|
|
|
|
template <typename R, typename P1> class popupCallbackFunction;
|
|
|
|
class popupCallback{
|
|
public:
|
|
popupCallback(void){}
|
|
~popupCallback(void){}
|
|
|
|
virtual void bind(void* newFun) = 0;
|
|
virtual bool call(void) = 0;
|
|
};
|
|
|
|
template <typename R, typename P1>
|
|
class popupCallbackFunction : public popupCallback{
|
|
protected:
|
|
R (*fun)(P1);
|
|
P1 param_1;
|
|
public:
|
|
popupCallbackFunction(void);
|
|
popupCallbackFunction(void * newFun, P1 param);
|
|
virtual void bind(void * newFun);
|
|
virtual bool call(void);
|
|
};
|
|
|
|
template<typename R,typename P1>
|
|
popupCallbackFunction<R,P1>::popupCallbackFunction(void){
|
|
this->fun = 0;
|
|
this->param_1 = P1();
|
|
};
|
|
|
|
template<typename R,typename P1>
|
|
popupCallbackFunction<R,P1>::popupCallbackFunction(void * newFun, P1 param){
|
|
this->fun = static_cast< R(*)(P1)>(newFun);
|
|
this->param_1 = param;
|
|
};
|
|
|
|
template<typename R,typename P1>
|
|
void popupCallbackFunction<R,P1>::bind(void * newFun){
|
|
this->fun = static_cast< R(*)(P1)>(newFun);
|
|
};
|
|
|
|
template<typename R,typename P1>
|
|
bool popupCallbackFunction<R,P1>::call(void){
|
|
return (bool)(this->fun)(this->param_1);
|
|
}
|
|
|
|
// no return type, one parameter
|
|
template <typename P1>
|
|
class popupCallbackFunction<void, typename P1> : public popupCallback{
|
|
protected:
|
|
void (*fun)(P1);
|
|
P1 param_1;
|
|
public:
|
|
popupCallbackFunction(void);
|
|
popupCallbackFunction(void * newFun, P1 param);
|
|
virtual void bind(void * newFun);
|
|
virtual bool call(void);
|
|
};
|
|
|
|
template<typename P1>
|
|
popupCallbackFunction<void,P1>::popupCallbackFunction(void){
|
|
this->fun = 0;
|
|
this->param_1 = P1();
|
|
};
|
|
|
|
template<typename P1>
|
|
popupCallbackFunction<void,P1>::popupCallbackFunction(void * newFun, P1 param){
|
|
this->fun = static_cast< void(*)(P1)>(newFun);
|
|
this->param_1 = param;
|
|
};
|
|
|
|
template<typename P1>
|
|
void popupCallbackFunction<void,P1>::bind(void * newFun){
|
|
this->fun = static_cast< void(*)(P1)>(newFun);
|
|
};
|
|
|
|
|
|
template<typename P1>
|
|
bool popupCallbackFunction<void,P1>::call(void){
|
|
try {
|
|
(this->fun)(this->param_1);
|
|
} catch (...) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
// returns something, no parameter
|
|
template <typename R>
|
|
class popupCallbackFunction<typename R, void> : public popupCallback{
|
|
protected:
|
|
R (*fun)(void);
|
|
public:
|
|
popupCallbackFunction(void);
|
|
popupCallbackFunction(void * newFun);
|
|
virtual void bind(void * newFun);
|
|
virtual bool call(void);
|
|
};
|
|
|
|
template<typename R>
|
|
popupCallbackFunction<R,void>::popupCallbackFunction(void){
|
|
this->fun = 0;
|
|
};
|
|
|
|
template<typename R>
|
|
popupCallbackFunction<R,void>::popupCallbackFunction(void * newFun){
|
|
this->fun = static_cast< R(*)(void)>(newFun);
|
|
};
|
|
|
|
template<typename R>
|
|
void popupCallbackFunction<R,void>::bind(void * newFun){
|
|
this->fun = static_cast< R(*)(void)>(newFun);
|
|
};
|
|
|
|
template<typename R>
|
|
bool popupCallbackFunction<R,void>::call(void){
|
|
return (bool)(this->fun)();
|
|
}
|
|
|
|
|
|
//template<>
|
|
//bool popupCallbackFunction<bool,void>::call(void){
|
|
// return (this->fun)();
|
|
//}
|
|
|
|
// no parameters/return types
|
|
template <>
|
|
class popupCallbackFunction<void, void> : public popupCallback{
|
|
protected:
|
|
void (*fun)(void);
|
|
public:
|
|
popupCallbackFunction(void){
|
|
this->fun = 0;
|
|
};
|
|
popupCallbackFunction(void * newFun){
|
|
this->fun = static_cast< void(*)(void)>(newFun);
|
|
};
|
|
virtual void bind(void * newFun){
|
|
this->fun = static_cast< void(*)(void)>(newFun);
|
|
};
|
|
virtual bool call(void){
|
|
try {
|
|
(this->fun)();
|
|
} catch (...) {
|
|
return false;
|
|
}
|
|
return true;
|
|
};
|
|
};
|
|
|
|
class popupCallbackLua : public popupCallback{
|
|
protected:
|
|
CHAR16 * functionName;
|
|
public:
|
|
popupCallbackLua(void);
|
|
popupCallbackLua(CHAR16 * newFunctionName){
|
|
this->functionName = newFunctionName;
|
|
};
|
|
virtual void bind(void * newFun){
|
|
this->functionName = static_cast< CHAR16* >(newFun);
|
|
};
|
|
virtual bool call(void){
|
|
return true;
|
|
};
|
|
};
|
|
|
|
#endif |