CSXFile::CSXFile(CBGame *inGame, CScStack *Stack): CBScriptable(inGame) { Stack->CorrectParams(1); CScValue *Val = Stack->Pop(); m_Filename = NULL; if (!Val->IsNULL()) CBUtils::SetString(&m_Filename, Val->GetString()); m_ReadFile = NULL; m_WriteFile = NULL; m_Mode = 0; m_TextMode = false; }
CSXDate::CSXDate(CBGame *inGame, CScStack *Stack): CBScriptable(inGame) { Stack->CorrectParams(6); memset(&m_tm, 0, sizeof(m_tm)); CScValue *valYear = Stack->Pop(); m_tm.tm_year = valYear->GetInt() - 1900; m_tm.tm_mon = Stack->Pop()->GetInt() - 1; m_tm.tm_mday = Stack->Pop()->GetInt(); m_tm.tm_hour = Stack->Pop()->GetInt(); m_tm.tm_min = Stack->Pop()->GetInt(); m_tm.tm_sec = Stack->Pop()->GetInt(); if (valYear->IsNULL()) { time_t TimeNow; time(&TimeNow); memcpy(&m_tm, localtime(&TimeNow), sizeof(m_tm)); } mktime(&m_tm); }
////////////////////////////////////////////////////////////////////////// // high level scripting interface ////////////////////////////////////////////////////////////////////////// HRESULT CUIButton::ScCallMethod(CScScript *Script, CScStack *Stack, CScStack *ThisStack, char *Name) { ////////////////////////////////////////////////////////////////////////// // SetDisabledFont ////////////////////////////////////////////////////////////////////////// if (strcmp(Name, "SetDisabledFont") == 0) { Stack->CorrectParams(1); CScValue *Val = Stack->Pop(); if (m_FontDisable) Game->m_FontStorage->RemoveFont(m_FontDisable); if (Val->IsNULL()) { m_FontDisable = NULL; Stack->PushBool(true); } else { m_FontDisable = Game->m_FontStorage->AddFont(Val->GetString()); Stack->PushBool(m_FontDisable != NULL); } return S_OK; } ////////////////////////////////////////////////////////////////////////// // SetHoverFont ////////////////////////////////////////////////////////////////////////// else if (strcmp(Name, "SetHoverFont") == 0) { Stack->CorrectParams(1); CScValue *Val = Stack->Pop(); if (m_FontHover) Game->m_FontStorage->RemoveFont(m_FontHover); if (Val->IsNULL()) { m_FontHover = NULL; Stack->PushBool(true); } else { m_FontHover = Game->m_FontStorage->AddFont(Val->GetString()); Stack->PushBool(m_FontHover != NULL); } return S_OK; } ////////////////////////////////////////////////////////////////////////// // SetPressedFont ////////////////////////////////////////////////////////////////////////// else if (strcmp(Name, "SetPressedFont") == 0) { Stack->CorrectParams(1); CScValue *Val = Stack->Pop(); if (m_FontPress) Game->m_FontStorage->RemoveFont(m_FontPress); if (Val->IsNULL()) { m_FontPress = NULL; Stack->PushBool(true); } else { m_FontPress = Game->m_FontStorage->AddFont(Val->GetString()); Stack->PushBool(m_FontPress != NULL); } return S_OK; } ////////////////////////////////////////////////////////////////////////// // SetFocusedFont ////////////////////////////////////////////////////////////////////////// else if (strcmp(Name, "SetFocusedFont") == 0) { Stack->CorrectParams(1); CScValue *Val = Stack->Pop(); if (m_FontFocus) Game->m_FontStorage->RemoveFont(m_FontFocus); if (Val->IsNULL()) { m_FontFocus = NULL; Stack->PushBool(true); } else { m_FontFocus = Game->m_FontStorage->AddFont(Val->GetString()); Stack->PushBool(m_FontFocus != NULL); } return S_OK; } ////////////////////////////////////////////////////////////////////////// // SetDisabledImage ////////////////////////////////////////////////////////////////////////// else if (strcmp(Name, "SetDisabledImage") == 0) { Stack->CorrectParams(1); delete m_ImageDisable; m_ImageDisable = new CBSprite(Game); char *Filename = Stack->Pop()->GetString(); if (!m_ImageDisable || FAILED(m_ImageDisable->LoadFile(Filename))) { delete m_ImageDisable; m_ImageDisable = NULL; Stack->PushBool(false); } else Stack->PushBool(true); return S_OK; } ////////////////////////////////////////////////////////////////////////// // GetDisabledImage ////////////////////////////////////////////////////////////////////////// else if (strcmp(Name, "GetDisabledImage") == 0) { Stack->CorrectParams(0); if (!m_ImageDisable || !m_ImageDisable->m_Filename) Stack->PushNULL(); else Stack->PushString(m_ImageDisable->m_Filename); return S_OK; } ////////////////////////////////////////////////////////////////////////// // GetDisabledImageObject ////////////////////////////////////////////////////////////////////////// else if (strcmp(Name, "GetDisabledImageObject") == 0) { Stack->CorrectParams(0); if (!m_ImageDisable) Stack->PushNULL(); else Stack->PushNative(m_ImageDisable, true); return S_OK; } ////////////////////////////////////////////////////////////////////////// // SetHoverImage ////////////////////////////////////////////////////////////////////////// else if (strcmp(Name, "SetHoverImage") == 0) { Stack->CorrectParams(1); delete m_ImageHover; m_ImageHover = new CBSprite(Game); char *Filename = Stack->Pop()->GetString(); if (!m_ImageHover || FAILED(m_ImageHover->LoadFile(Filename))) { delete m_ImageHover; m_ImageHover = NULL; Stack->PushBool(false); } else Stack->PushBool(true); return S_OK; } ////////////////////////////////////////////////////////////////////////// // GetHoverImage ////////////////////////////////////////////////////////////////////////// else if (strcmp(Name, "GetHoverImage") == 0) { Stack->CorrectParams(0); if (!m_ImageHover || !m_ImageHover->m_Filename) Stack->PushNULL(); else Stack->PushString(m_ImageHover->m_Filename); return S_OK; } ////////////////////////////////////////////////////////////////////////// // GetHoverImageObject ////////////////////////////////////////////////////////////////////////// else if (strcmp(Name, "GetHoverImageObject") == 0) { Stack->CorrectParams(0); if (!m_ImageHover) Stack->PushNULL(); else Stack->PushNative(m_ImageHover, true); return S_OK; } ////////////////////////////////////////////////////////////////////////// // SetPressedImage ////////////////////////////////////////////////////////////////////////// else if (strcmp(Name, "SetPressedImage") == 0) { Stack->CorrectParams(1); delete m_ImagePress; m_ImagePress = new CBSprite(Game); char *Filename = Stack->Pop()->GetString(); if (!m_ImagePress || FAILED(m_ImagePress->LoadFile(Filename))) { delete m_ImagePress; m_ImagePress = NULL; Stack->PushBool(false); } else Stack->PushBool(true); return S_OK; } ////////////////////////////////////////////////////////////////////////// // GetPressedImage ////////////////////////////////////////////////////////////////////////// else if (strcmp(Name, "GetPressedImage") == 0) { Stack->CorrectParams(0); if (!m_ImagePress || !m_ImagePress->m_Filename) Stack->PushNULL(); else Stack->PushString(m_ImagePress->m_Filename); return S_OK; } ////////////////////////////////////////////////////////////////////////// // GetPressedImageObject ////////////////////////////////////////////////////////////////////////// else if (strcmp(Name, "GetPressedImageObject") == 0) { Stack->CorrectParams(0); if (!m_ImagePress) Stack->PushNULL(); else Stack->PushNative(m_ImagePress, true); return S_OK; } ////////////////////////////////////////////////////////////////////////// // SetFocusedImage ////////////////////////////////////////////////////////////////////////// else if (strcmp(Name, "SetFocusedImage") == 0) { Stack->CorrectParams(1); delete m_ImageFocus; m_ImageFocus = new CBSprite(Game); char *Filename = Stack->Pop()->GetString(); if (!m_ImageFocus || FAILED(m_ImageFocus->LoadFile(Filename))) { delete m_ImageFocus; m_ImageFocus = NULL; Stack->PushBool(false); } else Stack->PushBool(true); return S_OK; } ////////////////////////////////////////////////////////////////////////// // GetFocusedImage ////////////////////////////////////////////////////////////////////////// else if (strcmp(Name, "GetFocusedImage") == 0) { Stack->CorrectParams(0); if (!m_ImageFocus || !m_ImageFocus->m_Filename) Stack->PushNULL(); else Stack->PushString(m_ImageFocus->m_Filename); return S_OK; } ////////////////////////////////////////////////////////////////////////// // GetFocusedImageObject ////////////////////////////////////////////////////////////////////////// else if (strcmp(Name, "GetFocusedImageObject") == 0) { Stack->CorrectParams(0); if (!m_ImageFocus) Stack->PushNULL(); else Stack->PushNative(m_ImageFocus, true); return S_OK; } ////////////////////////////////////////////////////////////////////////// // Press ////////////////////////////////////////////////////////////////////////// else if (strcmp(Name, "Press") == 0) { Stack->CorrectParams(0); if (m_Visible && !m_Disable) { m_OneTimePress = true; m_OneTimePressTime = CBPlatform::GetTime(); } Stack->PushNULL(); return S_OK; } else return CUIObject::ScCallMethod(Script, Stack, ThisStack, Name); }
////////////////////////////////////////////////////////////////////////// // high level scripting interface ////////////////////////////////////////////////////////////////////////// HRESULT CAdTalkHolder::ScCallMethod(CScScript* Script, CScStack *Stack, CScStack *ThisStack, char *Name) { ////////////////////////////////////////////////////////////////////////// // SetSprite ////////////////////////////////////////////////////////////////////////// if(strcmp(Name, "SetSprite")==0){ Stack->CorrectParams(1); CScValue* Val = Stack->Pop(); bool SetCurrent = false; if(m_CurrentSprite && m_CurrentSprite == m_Sprite) SetCurrent = true; SAFE_DELETE(m_Sprite); if(Val->IsNULL()) { m_Sprite = NULL; if(SetCurrent) m_CurrentSprite = NULL; Stack->PushBool(true); } else { char* Filename = Val->GetString(); CBSprite* spr = new CBSprite(Game, this); if(!spr || FAILED(spr->LoadFile(Filename))){ Script->RuntimeError("SetSprite method failed for file '%s'", Filename); Stack->PushBool(false); } else { m_Sprite = spr; if(SetCurrent) m_CurrentSprite = m_Sprite; Stack->PushBool(true); } } return S_OK; } ////////////////////////////////////////////////////////////////////////// // GetSprite ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "GetSprite")==0){ Stack->CorrectParams(0); if(!m_Sprite || !m_Sprite->m_Filename) Stack->PushNULL(); else Stack->PushString(m_Sprite->m_Filename); return S_OK; } ////////////////////////////////////////////////////////////////////////// // GetSpriteObject ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "GetSpriteObject")==0){ Stack->CorrectParams(0); if(!m_Sprite) Stack->PushNULL(); else Stack->PushNative(m_Sprite, true); return S_OK; } ////////////////////////////////////////////////////////////////////////// // AddTalkSprite ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "AddTalkSprite")==0){ Stack->CorrectParams(2); char* Filename = Stack->Pop()->GetString(); bool Ex = Stack->Pop()->GetBool(); CBSprite* spr = new CBSprite(Game, this); if(!spr || FAILED(spr->LoadFile(Filename))){ Stack->PushBool(false); Script->RuntimeError("AddTalkSprite method failed for file '%s'", Filename); } else { if(Ex) m_TalkSpritesEx.Add(spr); else m_TalkSprites.Add(spr); Stack->PushBool(true); } return S_OK; } ////////////////////////////////////////////////////////////////////////// // RemoveTalkSprite ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "RemoveTalkSprite")==0){ Stack->CorrectParams(2); char* Filename = Stack->Pop()->GetString(); bool Ex = Stack->Pop()->GetBool(); int i; bool SetCurrent = false; bool SetTemp2 = false; if(Ex){ for(i=0; i<m_TalkSpritesEx.GetSize(); i++){ if(stricmp(m_TalkSpritesEx[i]->m_Filename, Filename)==0){ if(m_CurrentSprite==m_TalkSpritesEx[i]) SetCurrent = true; if(m_TempSprite2==m_TalkSpritesEx[i]) SetTemp2 = true; delete m_TalkSpritesEx[i]; m_TalkSpritesEx.RemoveAt(i); break; } } } else{ for(i=0; i<m_TalkSprites.GetSize(); i++){ if(stricmp(m_TalkSprites[i]->m_Filename, Filename)==0){ if(m_CurrentSprite==m_TalkSprites[i]) SetCurrent = true; if(m_TempSprite2==m_TalkSprites[i]) SetTemp2 = true; delete m_TalkSprites[i]; m_TalkSprites.RemoveAt(i); break; } } } Stack->PushBool(true); if(SetCurrent) m_CurrentSprite = m_Sprite; if(SetTemp2) m_TempSprite2 = m_Sprite; return S_OK; } ////////////////////////////////////////////////////////////////////////// // SetTalkSprite ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "SetTalkSprite")==0){ Stack->CorrectParams(2); char* Filename = Stack->Pop()->GetString(); bool Ex = Stack->Pop()->GetBool(); bool SetCurrent = false; bool SetTemp2 = false; CBSprite* spr = new CBSprite(Game, this); if(!spr || FAILED(spr->LoadFile(Filename))){ Stack->PushBool(false); Script->RuntimeError("SetTalkSprite method failed for file '%s'", Filename); } else { // delete current int i; if(Ex){ for(i=0; i<m_TalkSpritesEx.GetSize(); i++){ if(m_TalkSpritesEx[i]==m_CurrentSprite) SetCurrent = true; if(m_TalkSpritesEx[i]==m_TempSprite2) SetTemp2 = true; delete m_TalkSpritesEx[i]; } m_TalkSpritesEx.RemoveAll(); } else{ for(i=0; i<m_TalkSprites.GetSize(); i++){ if(m_TalkSprites[i]==m_CurrentSprite) SetCurrent = true; if(m_TalkSprites[i]==m_TempSprite2) SetTemp2 = true; delete m_TalkSprites[i]; } m_TalkSprites.RemoveAll(); } // set new if(Ex) m_TalkSpritesEx.Add(spr); else m_TalkSprites.Add(spr); Stack->PushBool(true); if(SetCurrent) m_CurrentSprite = spr; if(SetTemp2) m_TempSprite2 = spr; } return S_OK; } else return CAdObject::ScCallMethod(Script, Stack, ThisStack, Name); }
////////////////////////////////////////////////////////////////////////// // high level scripting interface ////////////////////////////////////////////////////////////////////////// HRESULT CBSprite::ScCallMethod(CScScript* Script, CScStack *Stack, CScStack *ThisStack, char *Name) { ////////////////////////////////////////////////////////////////////////// // GetFrame ////////////////////////////////////////////////////////////////////////// if(strcmp(Name, "GetFrame")==0) { Stack->CorrectParams(1); int Index = Stack->Pop()->GetInt(-1); if(Index<0 || Index>=m_Frames.GetSize()) { Script->RuntimeError("Sprite.GetFrame: Frame index %d is out of range.", Index); Stack->PushNULL(); } else Stack->PushNative(m_Frames[Index], true); return S_OK; } ////////////////////////////////////////////////////////////////////////// // DeleteFrame ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "DeleteFrame")==0) { Stack->CorrectParams(1); CScValue* Val = Stack->Pop(); if(Val->IsInt()) { int Index = Val->GetInt(-1); if(Index<0 || Index>=m_Frames.GetSize()) { Script->RuntimeError("Sprite.DeleteFrame: Frame index %d is out of range.", Index); } } else { CBFrame* Frame = (CBFrame*)Val->GetNative(); for(int i=0; i<m_Frames.GetSize(); i++) { if(m_Frames[i]==Frame) { if(i==m_CurrentFrame) m_LastFrameTime = 0; delete m_Frames[i]; m_Frames.RemoveAt(i); break; } } } Stack->PushNULL(); return S_OK; } ////////////////////////////////////////////////////////////////////////// // Reset ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "Reset")==0) { Stack->CorrectParams(0); Reset(); Stack->PushNULL(); return S_OK; } ////////////////////////////////////////////////////////////////////////// // AddFrame ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "AddFrame")==0) { Stack->CorrectParams(1); CScValue* Val = Stack->Pop(); char* Filename = NULL; if(!Val->IsNULL()) Filename = Val->GetString(); CBFrame* Frame = new CBFrame(Game); if(Filename!=NULL) { CBSubFrame* Sub = new CBSubFrame(Game); if(SUCCEEDED(Sub->SetSurface(Filename))) { Sub->SetDefaultRect(); Frame->m_Subframes.Add(Sub); } else delete Sub; } m_Frames.Add(Frame); Stack->PushNative(Frame, true); return S_OK; } ////////////////////////////////////////////////////////////////////////// // InsertFrame ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "InsertFrame")==0) { Stack->CorrectParams(2); int Index = Stack->Pop()->GetInt(); if(Index<0) Index = 0; CScValue* Val = Stack->Pop(); char* Filename = NULL; if(!Val->IsNULL()) Filename = Val->GetString(); CBFrame* Frame = new CBFrame(Game); if(Filename!=NULL) { CBSubFrame* Sub = new CBSubFrame(Game); if(SUCCEEDED(Sub->SetSurface(Filename))) Frame->m_Subframes.Add(Sub); else delete Sub; } if(Index>=m_Frames.GetSize()) m_Frames.Add(Frame); else m_Frames.InsertAt(Index, Frame); Stack->PushNative(Frame, true); return S_OK; } ////////////////////////////////////////////////////////////////////////// // Pause ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "Pause")==0) { Stack->CorrectParams(0); m_Paused = true; Stack->PushNULL(); return S_OK; } ////////////////////////////////////////////////////////////////////////// // Play ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "Play")==0) { Stack->CorrectParams(0); m_Paused = false; Stack->PushNULL(); return S_OK; } else return CBScriptHolder::ScCallMethod(Script, Stack, ThisStack, Name); }
////////////////////////////////////////////////////////////////////////// // high level scripting interface ////////////////////////////////////////////////////////////////////////// HRESULT CUIWindow::ScCallMethod(CScScript* Script, CScStack *Stack, CScStack *ThisStack, char *Name) { ////////////////////////////////////////////////////////////////////////// // GetWidget / GetControl ////////////////////////////////////////////////////////////////////////// if(strcmp(Name, "GetWidget")==0 || strcmp(Name, "GetControl")==0) { Stack->CorrectParams(1); CScValue* val = Stack->Pop(); if(val->GetType()==VAL_INT) { int widget= val->GetInt(); if(widget<0 || widget>=m_Widgets.GetSize()) Stack->PushNULL(); else Stack->PushNative(m_Widgets[widget], true); } else { for(int i=0; i<m_Widgets.GetSize(); i++) { if(CBPlatform::stricmp(m_Widgets[i]->m_Name, val->GetString())==0) { Stack->PushNative(m_Widgets[i], true); return S_OK; } } Stack->PushNULL(); } return S_OK; } ////////////////////////////////////////////////////////////////////////// // SetInactiveFont ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "SetInactiveFont")==0) { Stack->CorrectParams(1); if(m_FontInactive) Game->m_FontStorage->RemoveFont(m_FontInactive); m_FontInactive = Game->m_FontStorage->AddFont(Stack->Pop()->GetString()); Stack->PushBool(m_FontInactive!=NULL); return S_OK; } ////////////////////////////////////////////////////////////////////////// // SetInactiveImage ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "SetInactiveImage")==0) { Stack->CorrectParams(1); SAFE_DELETE(m_ImageInactive); m_ImageInactive = new CBSprite(Game); char* Filename = Stack->Pop()->GetString(); if(!m_ImageInactive || FAILED(m_ImageInactive->LoadFile(Filename))) { SAFE_DELETE(m_ImageInactive); Stack->PushBool(false); } else Stack->PushBool(true); return S_OK; } ////////////////////////////////////////////////////////////////////////// // GetInactiveImage ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "GetInactiveImage")==0) { Stack->CorrectParams(0); if(!m_ImageInactive || !m_ImageInactive->m_Filename) Stack->PushNULL(); else Stack->PushString(m_ImageInactive->m_Filename); return S_OK; } ////////////////////////////////////////////////////////////////////////// // GetInactiveImageObject ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "GetInactiveImageObject")==0) { Stack->CorrectParams(0); if(!m_ImageInactive) Stack->PushNULL(); else Stack->PushNative(m_ImageInactive, true); return S_OK; } ////////////////////////////////////////////////////////////////////////// // Close ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "Close")==0) { Stack->CorrectParams(0); Stack->PushBool(SUCCEEDED(Close())); return S_OK; } ////////////////////////////////////////////////////////////////////////// // GoExclusive ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "GoExclusive")==0) { Stack->CorrectParams(0); GoExclusive(); Script->WaitFor(this); Stack->PushNULL(); return S_OK; } ////////////////////////////////////////////////////////////////////////// // GoSystemExclusive ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "GoSystemExclusive")==0) { Stack->CorrectParams(1); char* Event = Stack->Pop()->GetString(); GoSystemExclusive(); if (Event != NULL) { ApplyEvent(Event); } Script->WaitFor(this); Stack->PushNULL(); return S_OK; } ////////////////////////////////////////////////////////////////////////// // Center ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "Center")==0) { Stack->CorrectParams(0); m_PosX = (Game->m_Renderer->m_Width - m_Width) / 2; m_PosY = (Game->m_Renderer->m_Height - m_Height) / 2; Stack->PushNULL(); return S_OK; } ////////////////////////////////////////////////////////////////////////// // LoadFromFile ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "LoadFromFile")==0) { Stack->CorrectParams(1); CScValue* Val = Stack->Pop(); Cleanup(); if(!Val->IsNULL()) { Stack->PushBool(SUCCEEDED(LoadFile(Val->GetString()))); } else Stack->PushBool(true); return S_OK; } ////////////////////////////////////////////////////////////////////////// // CreateButton ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "CreateButton")==0) { Stack->CorrectParams(1); CScValue* Val = Stack->Pop(); CUIButton* Btn = new CUIButton(Game); if(!Val->IsNULL()) Btn->SetName(Val->GetString()); Stack->PushNative(Btn, true); Btn->m_Parent = this; m_Widgets.Add(Btn); return S_OK; } ////////////////////////////////////////////////////////////////////////// // CreateStatic ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "CreateStatic")==0) { Stack->CorrectParams(1); CScValue* Val = Stack->Pop(); CUIText* Sta = new CUIText(Game); if(!Val->IsNULL()) Sta->SetName(Val->GetString()); Stack->PushNative(Sta, true); Sta->m_Parent = this; m_Widgets.Add(Sta); return S_OK; } ////////////////////////////////////////////////////////////////////////// // CreateEditor ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "CreateEditor")==0) { Stack->CorrectParams(1); CScValue* Val = Stack->Pop(); CUIEdit* Edi = new CUIEdit(Game); if(!Val->IsNULL()) Edi->SetName(Val->GetString()); Stack->PushNative(Edi, true); Edi->m_Parent = this; m_Widgets.Add(Edi); return S_OK; } ////////////////////////////////////////////////////////////////////////// // CreateWindow ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "CreateWindow")==0) { Stack->CorrectParams(1); CScValue* Val = Stack->Pop(); CUIWindow* Win = new CUIWindow(Game); if(!Val->IsNULL()) Win->SetName(Val->GetString()); Stack->PushNative(Win, true); Win->m_Parent = this; m_Widgets.Add(Win); return S_OK; } ////////////////////////////////////////////////////////////////////////// // DeleteControl / DeleteButton / DeleteStatic / DeleteEditor / DeleteWindow ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "DeleteControl")==0 || strcmp(Name, "DeleteButton")==0 || strcmp(Name, "DeleteStatic")==0 || strcmp(Name, "DeleteEditor")==0 || strcmp(Name, "DeleteWindow")==0) { Stack->CorrectParams(1); CScValue* val = Stack->Pop(); CUIObject* obj = (CUIObject*)val->GetNative(); for(int i=0; i<m_Widgets.GetSize(); i++) { if(m_Widgets[i]==obj) { delete m_Widgets[i]; m_Widgets.RemoveAt(i); if(val->GetType()==VAL_VARIABLE_REF) val->SetNULL(); } } Stack->PushNULL(); return S_OK; } else if SUCCEEDED(Game->WindowScriptMethodHook(this, Script, Stack, Name)) return S_OK; else return CUIObject::ScCallMethod(Script, Stack, ThisStack, Name);
////////////////////////////////////////////////////////////////////////// // high level scripting interface ////////////////////////////////////////////////////////////////////////// HRESULT CUIObject::ScCallMethod(CScScript* Script, CScStack *Stack, CScStack *ThisStack, char *Name) { ////////////////////////////////////////////////////////////////////////// // SetFont ////////////////////////////////////////////////////////////////////////// if(strcmp(Name, "SetFont")==0){ Stack->CorrectParams(1); CScValue* Val = Stack->Pop(); if(m_Font) Game->m_FontStorage->RemoveFont(m_Font); if(Val->IsNULL()) { m_Font = NULL; Stack->PushBool(true); } else { m_Font = Game->m_FontStorage->AddFont(Val->GetString()); Stack->PushBool(m_Font!=NULL); } return S_OK; } ////////////////////////////////////////////////////////////////////////// // SetImage ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "SetImage")==0){ Stack->CorrectParams(1); CScValue* Val = Stack->Pop(); SAFE_DELETE(m_Image); if(Val->IsNULL()){ Stack->PushBool(true); return S_OK; } m_Image = new CBSprite(Game); if(!m_Image || FAILED(m_Image->LoadFile(Val->GetString()))){ SAFE_DELETE(m_Image); Stack->PushBool(false); } else Stack->PushBool(true); return S_OK; } ////////////////////////////////////////////////////////////////////////// // GetImage ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "GetImage")==0){ Stack->CorrectParams(0); if(!m_Image || !m_Image->m_Filename) Stack->PushNULL(); else Stack->PushString(m_Image->m_Filename); return S_OK; } ////////////////////////////////////////////////////////////////////////// // GetImageObject ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "GetImageObject")==0){ Stack->CorrectParams(0); if(!m_Image) Stack->PushNULL(); else Stack->PushNative(m_Image, true); return S_OK; } ////////////////////////////////////////////////////////////////////////// // Focus ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "Focus")==0){ Stack->CorrectParams(0); Focus(); Stack->PushNULL(); return S_OK; } ////////////////////////////////////////////////////////////////////////// // MoveAfter / MoveBefore ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "MoveAfter")==0 || strcmp(Name, "MoveBefore")==0){ Stack->CorrectParams(1); if(m_Parent && m_Parent->m_Type == UI_WINDOW){ CUIWindow* win = (CUIWindow*)m_Parent; int i; bool found = false; CScValue* val = Stack->Pop(); // find directly if(val->IsNative()){ CUIObject* widget = (CUIObject*)val->GetNative(); for(i=0; i<win->m_Widgets.GetSize(); i++){ if(win->m_Widgets[i]==widget){ found = true; break; } } } // find by name else{ char* name = val->GetString(); for(i=0; i<win->m_Widgets.GetSize(); i++){ if(CBPlatform::stricmp(win->m_Widgets[i]->m_Name, name)==0){ found = true; break; } } } if(found){ bool done=false; for(int j=0; j<win->m_Widgets.GetSize(); j++){ if(win->m_Widgets[j]==this){ if(strcmp(Name, "MoveAfter")==0) i++; if(j>=i) j++; win->m_Widgets.InsertAt(i, this); win->m_Widgets.RemoveAt(j); done = true; Stack->PushBool(true); break; } } if(!done) Stack->PushBool(false); } else Stack->PushBool(false); } else Stack->PushBool(false); return S_OK; } ////////////////////////////////////////////////////////////////////////// // MoveToBottom ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "MoveToBottom")==0){ Stack->CorrectParams(0); if(m_Parent && m_Parent->m_Type == UI_WINDOW){ CUIWindow* win = (CUIWindow*)m_Parent; for(int i=0; i<win->m_Widgets.GetSize(); i++){ if(win->m_Widgets[i]==this){ win->m_Widgets.RemoveAt(i); win->m_Widgets.InsertAt(0, this); break; } } Stack->PushBool(true); } else Stack->PushBool(false); return S_OK; } ////////////////////////////////////////////////////////////////////////// // MoveToTop ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "MoveToTop")==0){ Stack->CorrectParams(0); if(m_Parent && m_Parent->m_Type == UI_WINDOW){ CUIWindow* win = (CUIWindow*)m_Parent; for(int i=0; i<win->m_Widgets.GetSize(); i++){ if(win->m_Widgets[i]==this){ win->m_Widgets.RemoveAt(i); win->m_Widgets.Add(this); break; } } Stack->PushBool(true); } else Stack->PushBool(false); return S_OK; } else return CBObject::ScCallMethod(Script, Stack, ThisStack, Name); }
////////////////////////////////////////////////////////////////////////// // high level scripting interface ////////////////////////////////////////////////////////////////////////// HRESULT CAdLayer::ScCallMethod(CScScript* Script, CScStack *Stack, CScStack *ThisStack, char *Name) { ////////////////////////////////////////////////////////////////////////// // GetNode ////////////////////////////////////////////////////////////////////////// if(strcmp(Name, "GetNode")==0) { Stack->CorrectParams(1); CScValue* val = Stack->Pop(); int node = -1; if(val->m_Type==VAL_INT) node = val->GetInt(); else{ // get by name for(int i=0; i<m_Nodes.GetSize(); i++){ if( (m_Nodes[i]->m_Type==OBJECT_ENTITY && CBPlatform::stricmp(m_Nodes[i]->m_Entity->m_Name, val->GetString())==0) || (m_Nodes[i]->m_Type==OBJECT_REGION && CBPlatform::stricmp(m_Nodes[i]->m_Region->m_Name, val->GetString())==0)){ node = i; break; } } } if(node<0 || node>= m_Nodes.GetSize()) Stack->PushNULL(); else{ switch(m_Nodes[node]->m_Type){ case OBJECT_ENTITY: Stack->PushNative(m_Nodes[node]->m_Entity, true); break; case OBJECT_REGION: Stack->PushNative(m_Nodes[node]->m_Region, true); break; default: Stack->PushNULL(); } } return S_OK; } ////////////////////////////////////////////////////////////////////////// // AddRegion / AddEntity ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "AddRegion")==0 || strcmp(Name, "AddEntity")==0) { Stack->CorrectParams(1); CScValue* Val = Stack->Pop(); CAdSceneNode* Node = new CAdSceneNode(Game); if(strcmp(Name, "AddRegion")==0) { CAdRegion* Region = new CAdRegion(Game); if(!Val->IsNULL()) Region->SetName(Val->GetString()); Node->SetRegion(Region); Stack->PushNative(Region, true); } else { CAdEntity* Entity = new CAdEntity(Game); if(!Val->IsNULL()) Entity->SetName(Val->GetString()); Node->SetEntity(Entity); Stack->PushNative(Entity, true); } m_Nodes.Add(Node); return S_OK; } ////////////////////////////////////////////////////////////////////////// // InsertRegion / InsertEntity ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "InsertRegion")==0 || strcmp(Name, "InsertEntity")==0) { Stack->CorrectParams(2); int Index = Stack->Pop()->GetInt(); CScValue* Val = Stack->Pop(); CAdSceneNode* Node = new CAdSceneNode(Game); if(strcmp(Name, "InsertRegion")==0) { CAdRegion* Region = new CAdRegion(Game); if(!Val->IsNULL()) Region->SetName(Val->GetString()); Node->SetRegion(Region); Stack->PushNative(Region, true); } else { CAdEntity* Entity = new CAdEntity(Game); if(!Val->IsNULL()) Entity->SetName(Val->GetString()); Node->SetEntity(Entity); Stack->PushNative(Entity, true); } if(Index < 0) Index = 0; if(Index <= m_Nodes.GetSize() - 1) m_Nodes.InsertAt(Index, Node); else m_Nodes.Add(Node); return S_OK; } ////////////////////////////////////////////////////////////////////////// // DeleteNode ////////////////////////////////////////////////////////////////////////// else if(strcmp(Name, "DeleteNode")==0) { Stack->CorrectParams(1); CScValue* Val = Stack->Pop(); CAdSceneNode* ToDelete = NULL; if(Val->IsNative()) { CBScriptable* Temp = Val->GetNative(); for(int i=0; i<m_Nodes.GetSize(); i++) { if(m_Nodes[i]->m_Region==Temp || m_Nodes[i]->m_Entity==Temp) { ToDelete = m_Nodes[i]; break; } } } else { int Index = Val->GetInt(); if(Index >= 0 && Index < m_Nodes.GetSize()) { ToDelete = m_Nodes[Index]; } } if(ToDelete==NULL) { Stack->PushBool(false); return S_OK; } for(int i=0; i<m_Nodes.GetSize(); i++) { if(m_Nodes[i]==ToDelete) { SAFE_DELETE(m_Nodes[i]); m_Nodes.RemoveAt(i); break; } } Stack->PushBool(true); return S_OK; } else return CBObject::ScCallMethod(Script, Stack, ThisStack, Name); }