| 1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
|---|
| 2 | // Copyright (C) 1999-2019 Maciej Komosinski and Szymon Ulatowski. |
|---|
| 3 | // See LICENSE.txt for details. |
|---|
| 4 | |
|---|
| 5 | #ifndef _MUTABLEPARAM_H_ |
|---|
| 6 | #define _MUTABLEPARAM_H_ |
|---|
| 7 | |
|---|
| 8 | #include "mutparamiface.h" |
|---|
| 9 | #include <frams/util/extvalue.h> |
|---|
| 10 | #include "param.h" |
|---|
| 11 | #include <frams/util/callbacks.h> |
|---|
| 12 | |
|---|
| 13 | class VMachine; |
|---|
| 14 | class VMCode; |
|---|
| 15 | |
|---|
| 16 | class MutableParam : public SimpleAbstractParam, public MutableParamInterface |
|---|
| 17 | { |
|---|
| 18 | static const int staticprops; |
|---|
| 19 | static ParamEntry pe_tab[]; |
|---|
| 20 | /** group #0 cannot be removed by scripting */ |
|---|
| 21 | int persistgroup0; |
|---|
| 22 | SString grprefix; |
|---|
| 23 | SList entries; |
|---|
| 24 | SList groups; |
|---|
| 25 | int changed; |
|---|
| 26 | ParamEntry *entry(int i) { return (i < staticprops) ? pe_tab + i : ((ParamEntry*)entries(i - staticprops)); } |
|---|
| 27 | void *getTarget(int i) { return (i < staticprops) ? SimpleAbstractParam::getTarget(i) : (void*)entry(i)->offset; } |
|---|
| 28 | void call(int i, ExtValue* args, ExtValue *ret); |
|---|
| 29 | public: |
|---|
| 30 | void clear(int everything = 0); |
|---|
| 31 | int firstMutableIndex() { return staticprops; } |
|---|
| 32 | SString& groupname(int g) { return *((SString*)groups(g)); } |
|---|
| 33 | MutableParam(const char*n = 0, const char*g = 0, int gr0 = 1); |
|---|
| 34 | void setGroupName(const SString &n, int g = 0) { groupname(g) = n; } |
|---|
| 35 | ~MutableParam() { clear(1); } |
|---|
| 36 | int getGroupCount() { return groups.size(); } |
|---|
| 37 | int getPropCount() { return entries.size() + staticprops; } |
|---|
| 38 | const char *grname(int i) { return (i >= groups.size()) ? 0 : groupname(i).c_str(); } |
|---|
| 39 | int grmember(int g, int a); |
|---|
| 40 | |
|---|
| 41 | int addGroup(const SString& gname, int noprefix = 0); |
|---|
| 42 | void removeGroup(int pos); |
|---|
| 43 | |
|---|
| 44 | int findGroup(const SString name, int ignoreprefix = 0); |
|---|
| 45 | |
|---|
| 46 | /** @param data pointer to the variable. 0 will allocate new variable |
|---|
| 47 | @param position -1 = after the last one */ |
|---|
| 48 | int addProperty(void* data, const char* id, const char* type, const char* name, const char* help = 0, int flags = 0, int group = 0, int position = -1); |
|---|
| 49 | |
|---|
| 50 | int addProperty(ParamEntry *pe, int position = -1); |
|---|
| 51 | ParamEntry * removeProperty(ParamEntry *pe); |
|---|
| 52 | ParamEntry * removeProperty(int i); |
|---|
| 53 | |
|---|
| 54 | bool changeProperty(int i, const char* id, const char* type, const char* name, const char* help, int flags, int group); |
|---|
| 55 | |
|---|
| 56 | void notify(int id); |
|---|
| 57 | |
|---|
| 58 | int setInt(int, paInt); |
|---|
| 59 | int setDouble(int, double); |
|---|
| 60 | int setString(int, const SString &); |
|---|
| 61 | int setObject(int, const ExtObject &); |
|---|
| 62 | int setExtValue(int, const ExtValue &); |
|---|
| 63 | |
|---|
| 64 | #define STATRICKCLASS MutableParam |
|---|
| 65 | PARAMPROCDEF(p_clear); |
|---|
| 66 | PARAMPROCDEF(p_addprop); |
|---|
| 67 | PARAMPROCDEF(p_remprop); |
|---|
| 68 | PARAMPROCDEF(p_changeprop); |
|---|
| 69 | PARAMPROCDEF(p_addgroup); |
|---|
| 70 | PARAMPROCDEF(p_remgroup); |
|---|
| 71 | PARAMPROCDEF(p_exists); |
|---|
| 72 | PARAMGETDEF(changedname) { arg1->setString(id(changed)); } |
|---|
| 73 | #undef STATRICKCLASS |
|---|
| 74 | }; |
|---|
| 75 | |
|---|
| 76 | class ParamSaver |
|---|
| 77 | { |
|---|
| 78 | SList store; |
|---|
| 79 | public: |
|---|
| 80 | virtual bool shouldLoad(ParamInterface &pi, int i) { return true; } |
|---|
| 81 | ParamSaver() {} |
|---|
| 82 | ParamSaver(ParamInterface &pi) { loadFrom(pi); } |
|---|
| 83 | virtual ~ParamSaver() { clear(); } |
|---|
| 84 | void loadFrom(ParamInterface& p); |
|---|
| 85 | void saveTo(MutableParam& p); |
|---|
| 86 | void clear(); |
|---|
| 87 | }; |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | #endif |
|---|