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

Constructor & Destructor Documentation

◆ C4ScriptGuiWindowAction()

C4ScriptGuiWindowAction::C4ScriptGuiWindowAction ( )
inline

Definition at line 111 of file C4ScriptGuiWindow.h.

111 : value(0) { }

Referenced by Init().

Here is the caller graph for this function:

◆ ~C4ScriptGuiWindowAction()

C4ScriptGuiWindowAction::~C4ScriptGuiWindowAction ( )

Definition at line 64 of file C4ScriptGuiWindow.cpp.

65 {
66  if (text)
67  text->DecRef();
68  if (nextAction)
69  delete nextAction;
70 }
void DecRef()
Definition: C4StringTable.h:28

References C4RefCnt::DecRef().

Here is the call graph for this function:

Member Function Documentation

◆ ClearPointers()

void C4ScriptGuiWindowAction::ClearPointers ( C4Object pObj)

Definition at line 127 of file C4ScriptGuiWindow.cpp.

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:636
void ClearPointers(C4Object *pObj)

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

Referenced by ClearPointers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Execute()

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

Definition at line 203 of file C4ScriptGuiWindow.cpp.

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 }
C4Game Game
Definition: C4Globals.cpp:52
int main(int argc, char *argv[])
@ CID_MenuCommand
Definition: C4PacketBase.h:175
#define MenuDebugLogF(...)
void Add(C4PacketType eType, C4ControlPacket *pCtrl)
Definition: C4Control.h:82
Container * GetParent()
Definition: C4Gui.h:429
C4Control & Input
Definition: C4Game.h:82
void Execute(C4ScriptGuiWindow *parent, int32_t player, int32_t actionType)
void SetTag(C4String *tag)
const char * GetCStr() const
Definition: C4StringTable.h:49

References C4Control::Add(), C4ScriptGuiWindowActionID::Call, CID_MenuCommand, Execute(), Game, C4String::GetCStr(), C4ScriptGuiWindow::GetID(), C4GUI::Element::GetParent(), C4Game::Input, main(), MenuDebugLogF, C4ScriptGuiWindowPropertyName::player, C4ScriptGuiWindowActionID::SetTag, and C4ScriptGuiWindow::SetTag().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ExecuteCommand()

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

Definition at line 259 of file C4ScriptGuiWindow.cpp.

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 }
C4Value C4VObj(C4Object *pObj)
Definition: C4Value.cpp:88
const C4Value C4VNull
Definition: C4Value.cpp:30
C4Value C4VInt(int32_t i)
Definition: C4Value.h:239
int32_t Status
Definition: C4PropList.h:173
C4Value Call(C4PropertyName k, C4AulParSet *pPars=nullptr, bool fPassErrors=false)
Definition: C4PropList.h:114
bool ExecuteCommand(int32_t actionID, C4ScriptGuiWindow *parent, int32_t player)

References C4VInt(), C4VNull, C4VObj(), C4ScriptGuiWindowActionID::Call, C4PropList::Call(), ExecuteCommand(), C4String::GetCStr(), C4ScriptGuiWindow::GetID(), C4PropList::GetObject(), C4GUI::Element::GetParent(), main(), MenuDebugLogF, C4ScriptGuiWindowPropertyName::player, and C4PropList::Status.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Init()

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

Definition at line 140 of file C4ScriptGuiWindow.cpp.

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 }
std::unique_ptr< C4ScriptGuiWindow > ScriptGuiRoot
Definition: C4Game.h:234
void IncRef()
Definition: C4StringTable.h:27
bool Init(C4ValueArray *array, int32_t index=0)
const C4Value & GetItem(int32_t iElem) const
Definition: C4ValueArray.h:38
int32_t GetSize() const
Definition: C4ValueArray.h:36
C4ValueArray * getArray() const
Definition: C4Value.h:118
C4Object * getObj() const
Definition: C4Value.cpp:68
int32_t getInt() const
Definition: C4Value.h:112
C4String * getStr() const
Definition: C4Value.h:117
C4PropList * getPropList() const
Definition: C4Value.h:116

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

Referenced by Init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ToC4Value()

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

Definition at line 72 of file C4ScriptGuiWindow.cpp.

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 }
const C4Value ToC4Value(bool first=true)
void SetSize(int32_t inSize)
void SetItem(int32_t iElemNr, const C4Value &Value)

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

Referenced by ToC4Value().

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ C4ScriptGuiWindow

friend class C4ScriptGuiWindow
friend

Definition at line 96 of file C4ScriptGuiWindow.h.


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