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 91 of file C4ScriptGuiWindow.h.

Constructor & Destructor Documentation

C4ScriptGuiWindowAction::C4ScriptGuiWindowAction ( )
inline

Definition at line 108 of file C4ScriptGuiWindow.h.

Referenced by Init().

108 : id(0), action(0), nextAction(0), target(0), text(0), value(0), subwindowID(0) { }

Here is the caller graph for this function:

C4ScriptGuiWindowAction::~C4ScriptGuiWindowAction ( )

Definition at line 67 of file C4ScriptGuiWindow.cpp.

References text.

68 {
69  if (text)
70  text->DecRef();
71  if (nextAction)
72  delete nextAction;
73 }

Member Function Documentation

void C4ScriptGuiWindowAction::ClearPointers ( C4Object pObj)

Definition at line 130 of file C4ScriptGuiWindow.cpp.

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

Referenced by ClearPointers().

131 {
132  C4Object *targetObj = target ? target->GetObject() : 0;
133 
134  if (targetObj == pObj)
135  {
136  // not only forget object, but completely invalidate action
137  action = 0;
138  target = 0;
139  }
140  if (nextAction)
141  nextAction->ClearPointers(pObj);
142 }
virtual C4Object * GetObject()
Definition: C4PropList.cpp:644
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 206 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().

207 {
208  assert(parent && "C4ScriptGuiWindow::Execute must always be called with parent");
209  MenuDebugLogF("Excuting action (nextAction: %x, subwID: %d, target: %x, text: %s, type: %d)", nextAction, subwindowID, target, text->GetCStr(), actionType);
210 
211  // invalid ID? can be set by removal of target object
212  if (action)
213  {
214  // get menu main window
215  C4ScriptGuiWindow *main = parent;
216  C4ScriptGuiWindow *from = main;
217  while (!from->IsRoot())
218  {
219  main = from;
220  from = static_cast<C4ScriptGuiWindow*>(from->GetParent());
221  }
222 
223  switch (action)
224  {
226  {
227  if (!target) // ohject removed in the meantime?
228  break;
229  MenuDebugLogF("[ACTION REQUEST] action /call/");
230  // the action needs to be synchronized! Assemble command and put it into control queue!
231  Game.Input.Add(CID_MenuCommand, new C4ControlMenuCommand(id, player, main->GetID(), parent->GetID(), parent->target, actionType));
232  break;
233  }
234 
236  {
237  C4ScriptGuiWindow *window = main;
238  if (subwindowID == 0)
239  window = parent;
240  else if (subwindowID > 0)
241  {
242  C4Object *targetObj = dynamic_cast<C4Object*> (target);
243  window = main->GetSubWindow(subwindowID, targetObj);
244  }
245  if (window)
246  window->SetTag(text);
247  break;
248  }
249 
250  default:
251  assert(false && "C4ScriptGuiWindowAction without valid or invalidated ID");
252  break;
253  }
254  } // action
255 
256  if (nextAction)
257  {
258  nextAction->Execute(parent, player, actionType);
259  }
260 }
#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:84
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 262 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(), ExecuteCommand(), and C4ScriptGuiWindow::ExecuteCommand().

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

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 143 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().

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

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

Referenced by ToC4Value().

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


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