OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4ScriptGuiWindowAction Class Reference

#include <C4ScriptGuiWindow.h>

Public Member Functions

 C4ScriptGuiWindowAction ()
 
 ~C4ScriptGuiWindowAction ()
 
void ClearPointers (C4Object *pObj)
 
bool Init (C4ValueArray *array, int32_t index=0)
 
void Execute (C4ScriptGuiWindow *parent, int32_t player, int32_t actionType)
 
bool ExecuteCommand (int32_t actionID, C4ScriptGuiWindow *parent, int32_t player)
 
const C4Value ToC4Value (bool first=true)
 

Friends

class C4ScriptGuiWindow
 

Detailed Description

Definition at line 88 of file C4ScriptGuiWindow.h.

Constructor & Destructor Documentation

C4ScriptGuiWindowAction::C4ScriptGuiWindowAction ( )
inline

Definition at line 105 of file C4ScriptGuiWindow.h.

Referenced by Init().

105 : value(0) { }

Here is the caller graph for this function:

C4ScriptGuiWindowAction::~C4ScriptGuiWindowAction ( )

Definition at line 64 of file C4ScriptGuiWindow.cpp.

References text.

65 {
66  if (text)
67  text->DecRef();
68  if (nextAction)
69  delete nextAction;
70 }

Member Function Documentation

void C4ScriptGuiWindowAction::ClearPointers ( C4Object pObj)

Definition at line 127 of file C4ScriptGuiWindow.cpp.

References ClearPointers(), and C4PropList::GetObject().

Referenced by ClearPointers().

128 {
129  C4Object *targetObj = target ? target->GetObject() : nullptr;
130 
131  if (targetObj == pObj)
132  {
133  // not only forget object, but completely invalidate action
134  action = 0;
135  target = nullptr;
136  }
137  if (nextAction)
138  nextAction->ClearPointers(pObj);
139 }
virtual C4Object * GetObject()
Definition: C4PropList.cpp:667
void ClearPointers(C4Object *pObj)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ScriptGuiWindowAction::Execute ( C4ScriptGuiWindow parent,
int32_t  player,
int32_t  actionType 
)

Definition at line 203 of file C4ScriptGuiWindow.cpp.

References C4Control::Add(), Call, CID_MenuCommand, Execute(), Game, C4ScriptGuiWindow::GetID(), C4GUI::Element::GetParent(), C4ScriptGuiWindow::GetSubWindow(), C4Game::Input, main(), MenuDebugLogF, SetTag, C4ScriptGuiWindow::SetTag(), and text.

Referenced by Execute(), C4ScriptGuiWindow::OnMouseIn(), C4ScriptGuiWindow::OnMouseOut(), and C4ScriptGuiWindow::ProcessMouseInput().

204 {
205  assert(parent && "C4ScriptGuiWindow::Execute must always be called with parent");
206  MenuDebugLogF("Excuting action (nextAction: %x, subwID: %d, target: %x, text: %s, type: %d)", nextAction, subwindowID, target, text->GetCStr(), actionType);
207 
208  // invalid ID? can be set by removal of target object
209  if (action)
210  {
211  // get menu main window
212  C4ScriptGuiWindow *main = parent;
213  C4ScriptGuiWindow *from = main;
214  while (!from->IsRoot())
215  {
216  main = from;
217  from = static_cast<C4ScriptGuiWindow*>(from->GetParent());
218  }
219 
220  switch (action)
221  {
223  {
224  if (!target) // ohject removed in the meantime?
225  break;
226  MenuDebugLogF("[ACTION REQUEST] action /call/");
227  // the action needs to be synchronized! Assemble command and put it into control queue!
228  Game.Input.Add(CID_MenuCommand, new C4ControlMenuCommand(id, player, main->GetID(), parent->GetID(), parent->target, actionType));
229  break;
230  }
231 
233  {
234  C4ScriptGuiWindow *window = main;
235  if (subwindowID == 0)
236  window = parent;
237  else if (subwindowID > 0)
238  {
239  C4Object *targetObj = dynamic_cast<C4Object*> (target);
240  window = main->GetSubWindow(subwindowID, targetObj);
241  }
242  if (window)
243  window->SetTag(text);
244  break;
245  }
246 
247  default:
248  assert(false && "C4ScriptGuiWindowAction without valid or invalidated ID");
249  break;
250  }
251  } // action
252 
253  if (nextAction)
254  {
255  nextAction->Execute(parent, player, actionType);
256  }
257 }
#define MenuDebugLogF(...)
C4Game Game
Definition: C4Globals.cpp:52
void Add(C4PacketType eType, C4ControlPacket *pCtrl)
Definition: C4Control.h:82
void SetTag(C4String *tag)
void Execute(C4ScriptGuiWindow *parent, int32_t player, int32_t actionType)
C4ScriptGuiWindow * GetSubWindow(int32_t childID, C4Object *childTarget)
Container * GetParent()
Definition: C4Gui.h:429
C4Control & Input
Definition: C4Game.h:82
int main(int argc, char *argv[])

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4ScriptGuiWindowAction::ExecuteCommand ( int32_t  actionID,
C4ScriptGuiWindow parent,
int32_t  player 
)

Definition at line 259 of file C4ScriptGuiWindow.cpp.

References C4VInt(), C4VNull, C4VObj(), Call, C4PropList::Call(), ExecuteCommand(), C4ScriptGuiWindow::GetID(), C4PropList::GetObject(), C4GUI::Element::GetParent(), main(), MenuDebugLogF, C4PropList::Status, and text.

Referenced by C4ScriptGuiWindow::Close(), and ExecuteCommand().

260 {
261  MenuDebugLogF("checking action %d (==%d?)\t\tmy action: %d", id, actionID, action);
262  // target has already been checked for validity
263  if (id == actionID && action)
264  {
265  assert(action == C4ScriptGuiWindowActionID::Call && "C4ControlMenuCommand for invalid action!");
266 
267  // get menu main window
268  C4ScriptGuiWindow *main = parent;
269  C4ScriptGuiWindow *from = main;
270  while (!from->IsRoot())
271  {
272  main = from;
273  from = static_cast<C4ScriptGuiWindow*>(from->GetParent());
274  }
275  MenuDebugLogF("command synced.. target: %x, targetObj: %x, func: %s", target, target->GetObject(), text->GetCStr());
276  C4AulParSet Pars(value, C4VInt(player), C4VInt(main->GetID()), C4VInt(parent->GetID()), (parent->target && parent->target->Status) ? C4VObj(parent->target) : C4VNull);
277  target->Call(text->GetCStr(), &Pars);
278  return true;
279  }
280  if (nextAction)
281  return nextAction->ExecuteCommand(actionID, parent, player);
282  return false;
283 }
#define MenuDebugLogF(...)
C4Value C4VInt(int32_t i)
Definition: C4Value.h:242
C4Value C4VObj(C4Object *pObj)
Definition: C4Value.cpp:88
virtual C4Object * GetObject()
Definition: C4PropList.cpp:667
Container * GetParent()
Definition: C4Gui.h:429
int32_t Status
Definition: C4PropList.h:168
const C4Value C4VNull
Definition: C4Value.cpp:30
int main(int argc, char *argv[])
bool ExecuteCommand(int32_t actionID, C4ScriptGuiWindow *parent, int32_t player)
C4Value Call(C4PropertyName k, C4AulParSet *pPars=nullptr, bool fPassErrors=false)
Definition: C4PropList.h:110

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4ScriptGuiWindowAction::Init ( C4ValueArray array,
int32_t  index = 0 
)

Definition at line 140 of file C4ScriptGuiWindow.cpp.

References C4ScriptGuiWindowAction(), Call, Game, C4Value::getArray(), C4Value::getInt(), C4ValueArray::GetItem(), C4Value::getObj(), C4Value::getPropList(), C4ValueArray::GetSize(), C4Value::getStr(), Init(), MenuDebugLogF, C4Game::ScriptGuiRoot, SetTag, and text.

Referenced by Init().

141 {
142  if (array->GetSize() == 0) // safety
143  return false;
144 
145  // an array of actions?
146  if (array->GetItem(0).getArray())
147  {
148  // add action to action chain?
149  if (index+1 < array->GetSize())
150  {
151  nextAction = new C4ScriptGuiWindowAction();
152  nextAction->Init(array, index + 1);
153  }
154  // continue with one sub array
155  array = array->GetItem(index).getArray();
156  if (!array) return false;
157  }
158  // retrieve type of action
159  int newAction = array->GetItem(0).getInt();
160  action = 0; // still invalid!
161 
162  // when loading, the array has a size of 6 with the 5th element being the ID
163  if (array->GetSize() == 6)
164  id = array->GetItem(3).getInt();
165 
166  switch (newAction)
167  {
169  if (array->GetSize() < 3) return false;
170  target = array->GetItem(1).getPropList();
171  text = array->GetItem(2).getStr();
172  if (!target || !text) return false;
173  if (array->GetSize() >= 4)
174  value = C4Value(array->GetItem(3));
175  text->IncRef();
176 
177  // important! needed to identify actions later!
178  if (!id)
179  {
180  id = ::Game.ScriptGuiRoot->GenerateActionID();
181  MenuDebugLogF("assigning action ID %d\t\taction:%d, text:%s", id, newAction, text->GetCStr());
182  }
183 
184  break;
185 
187  if (array->GetSize() < 4) return false;
188  text = array->GetItem(1).getStr();
189  if (!text) return false;
190  text->IncRef();
191  subwindowID = array->GetItem(2).getInt();
192  target = array->GetItem(3).getObj(); // getObj on purpose. Need to validate that.
193  break;
194 
195  default:
196  return false;
197  }
198 
199  action = newAction;
200  return true;
201 }
#define MenuDebugLogF(...)
C4String * getStr() const
Definition: C4Value.h:117
C4Game Game
Definition: C4Globals.cpp:52
bool Init(C4ValueArray *array, int32_t index=0)
const C4Value & GetItem(int32_t iElem) const
Definition: C4ValueArray.h:38
C4ValueArray * getArray() const
Definition: C4Value.h:118
int32_t GetSize() const
Definition: C4ValueArray.h:36
int32_t getInt() const
Definition: C4Value.h:112
std::unique_ptr< C4ScriptGuiWindow > ScriptGuiRoot
Definition: C4Game.h:233
C4Object * getObj() const
Definition: C4Value.cpp:68
C4PropList * getPropList() const
Definition: C4Value.h:116

Here is the call graph for this function:

Here is the caller graph for this function:

const C4Value C4ScriptGuiWindowAction::ToC4Value ( bool  first = true)

Definition at line 72 of file C4ScriptGuiWindow.cpp.

References Call, C4ValueArray::GetSize(), C4ValueArray::SetItem(), C4ValueArray::SetSize(), SetTag, text, and ToC4Value().

Referenced by ToC4Value().

73 {
74  C4ValueArray *array = new C4ValueArray();
75 
76  switch (action)
77  {
79  array->SetSize(4);
80  array->SetItem(0, C4Value(action));
81  array->SetItem(1, C4Value(target));
82  array->SetItem(2, C4Value(text));
83  array->SetItem(3, value);
84  break;
85 
87  array->SetSize(4);
88  array->SetItem(0, C4Value(action));
89  array->SetItem(1, C4Value(text));
90  array->SetItem(2, C4Value(subwindowID));
91  array->SetItem(3, C4Value(target));
92  break;
93 
94  case 0: // can actually happen if the action is invalidated
95  break;
96 
97  default:
98  assert(false && "trying to save C4ScriptGuiWindowAction without valid action");
99  break;
100  }
101 
102  assert (array->GetSize() < 6);
103  array->SetSize(6);
104  array->SetItem(5, C4Value(id));
105 
106  if (!first || !nextAction) return C4Value(array);
107 
108  // this action is the first in a chain of actions
109  // all following actions (and this one) have to be put into another array
110  C4ValueArray *container = new C4ValueArray();
111  int32_t size = 1;
112  container->SetSize(size);
113  container->SetItem(0, C4Value(array));
114 
115  C4ScriptGuiWindowAction *next = nextAction;
116  while (next)
117  {
118  C4Value val = next->ToC4Value(false);
119  ++size;
120  container->SetSize(size);
121  container->SetItem(size - 1, val);
122  next = next->nextAction;
123  }
124  return C4Value(container);
125 }
void SetItem(int32_t iElemNr, const C4Value &Value)
void SetSize(int32_t inSize)
int32_t GetSize() const
Definition: C4ValueArray.h:36
const C4Value ToC4Value(bool first=true)

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class C4ScriptGuiWindow
friend

Definition at line 90 of file C4ScriptGuiWindow.h.


The documentation for this class was generated from the following files: