InReaction IGUIObject::SendEvent(EGUIMessageType type, const CStr& EventName) { PROFILE2_EVENT("gui event"); PROFILE2_ATTR("type: %s", EventName.c_str()); PROFILE2_ATTR("object: %s", m_Name.c_str()); SGUIMessage msg(type); HandleMessage(msg); ScriptEvent(EventName); return (msg.skipped ? IN_PASS : IN_HANDLED); }
void CMiniMap::FireWorldClickEvent(int button, int clicks) { float x, z; GetMouseWorldCoordinates(x, z); CScriptValRooted coords; g_ScriptingHost.GetScriptInterface().Eval("({})", coords); g_ScriptingHost.GetScriptInterface().SetProperty(coords.get(), "x", x, false); g_ScriptingHost.GetScriptInterface().SetProperty(coords.get(), "z", z, false); ScriptEvent("worldclick", coords); UNUSED2(button); UNUSED2(clicks); }
void CMiniMap::FireWorldClickEvent(int UNUSED(button), int UNUSED(clicks)) { JSContext* cx = g_GUI->GetActiveGUI()->GetScriptInterface()->GetContext(); JSAutoRequest rq(cx); float x, z; GetMouseWorldCoordinates(x, z); JS::RootedValue coords(cx); g_GUI->GetActiveGUI()->GetScriptInterface()->Eval("({})", &coords); g_GUI->GetActiveGUI()->GetScriptInterface()->SetProperty(coords, "x", x, false); g_GUI->GetActiveGUI()->GetScriptInterface()->SetProperty(coords, "z", z, false); ScriptEvent("worldclick", coords); }
void CList::HandleMessage(SGUIMessage& Message) { IGUIScrollBarOwner::HandleMessage(Message); //IGUITextOwner::HandleMessage(Message); <== placed it after the switch instead! m_Modified = false; switch (Message.type) { case GUIM_SETTINGS_UPDATED: if (Message.value == "list") SetupText(); // If selected is changed, call "SelectionChange" if (Message.value == "selected") { // TODO: Check range // TODO only works if lower-case, shouldn't it be made case sensitive instead? ScriptEvent("selectionchange"); } if (Message.value == "scrollbar") SetupText(); // Update scrollbar if (Message.value == "scrollbar_style") { CStr scrollbar_style; GUI<CStr>::GetSetting(this, Message.value, scrollbar_style); GetScrollBar(0).SetScrollBarStyle(scrollbar_style); SetupText(); } break; case GUIM_MOUSE_PRESS_LEFT: { bool enabled; GUI<bool>::GetSetting(this, "enabled", enabled); if (!enabled) { CStrW soundPath; if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_disabled", soundPath) == PSRETURN_OK && !soundPath.empty()) g_SoundManager->PlayAsUI(soundPath.c_str(), false); break; } bool scrollbar; CGUIList* pList; GUI<bool>::GetSetting(this, "scrollbar", scrollbar); GUI<CGUIList>::GetSettingPointer(this, "list", pList); float scroll = 0.f; if (scrollbar) scroll = GetScrollBar(0).GetPos(); CRect rect = GetListRect(); CPos mouse = GetMousePos(); mouse.y += scroll; int set = -1; for (int i = 0; i < (int)pList->m_Items.size(); ++i) { if (mouse.y >= rect.top + m_ItemsYPositions[i] && mouse.y < rect.top + m_ItemsYPositions[i+1] && // mouse is not over scroll-bar !(mouse.x >= GetScrollBar(0).GetOuterRect().left && mouse.x <= GetScrollBar(0).GetOuterRect().right)) { set = i; } } if (set != -1) { GUI<int>::SetSetting(this, "selected", set); UpdateAutoScroll(); CStrW soundPath; if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) g_SoundManager->PlayAsUI(soundPath.c_str(), false); } break; } case GUIM_LOAD: { CStr scrollbar_style; GUI<CStr>::GetSetting(this, "scrollbar_style", scrollbar_style); GetScrollBar(0).SetScrollBarStyle(scrollbar_style); break; } default: break; } IGUITextOwner::HandleMessage(Message); }
void CList::HandleMessage(SGUIMessage &Message) { IGUIScrollBarOwner::HandleMessage(Message); //IGUITextOwner::HandleMessage(Message); <== placed it after the switch instead! switch (Message.type) { case GUIM_SETTINGS_UPDATED: if (Message.value == "list") { SetupText(); } // If selected is changed, call "SelectionChange" if (Message.value == "selected") { // TODO: Check range // TODO only works if lower-case, shouldn't it be made case sensitive instead? ScriptEvent("selectionchange"); } if (Message.value == "scrollbar") { SetupText(); } // Update scrollbar if (Message.value == "scrollbar_style") { CStr scrollbar_style; GUI<CStr>::GetSetting(this, Message.value, scrollbar_style); GetScrollBar(0).SetScrollBarStyle( scrollbar_style ); SetupText(); } break; case GUIM_MOUSE_PRESS_LEFT: { bool enabled; GUI<bool>::GetSetting(this, "enabled", enabled); if (!enabled) break; bool scrollbar; CGUIList *pList; GUI<bool>::GetSetting(this, "scrollbar", scrollbar); GUI<CGUIList>::GetSettingPointer(this, "list", pList); float scroll=0.f; if (scrollbar) { scroll = GetScrollBar(0).GetPos(); } CRect rect = GetListRect(); CPos mouse = GetMousePos(); mouse.y += scroll; int set=-1; for (int i=0; i<(int)pList->m_Items.size(); ++i) { if (mouse.y >= rect.top + m_ItemsYPositions[i] && mouse.y < rect.top + m_ItemsYPositions[i+1] && // mouse is not over scroll-bar !(mouse.x >= GetScrollBar(0).GetOuterRect().left && mouse.x <= GetScrollBar(0).GetOuterRect().right)) { set = i; } } if (set != -1) { GUI<int>::SetSetting(this, "selected", set); UpdateAutoScroll(); } } break; case GUIM_MOUSE_WHEEL_DOWN: { GetScrollBar(0).ScrollPlus(); // Since the scroll was changed, let's simulate a mouse movement // to check if scrollbar now is hovered SGUIMessage msg(GUIM_MOUSE_MOTION); HandleMessage(msg); break; } case GUIM_MOUSE_WHEEL_UP: { GetScrollBar(0).ScrollMinus(); // Since the scroll was changed, let's simulate a mouse movement // to check if scrollbar now is hovered SGUIMessage msg(GUIM_MOUSE_MOTION); HandleMessage(msg); break; } case GUIM_LOAD: { CStr scrollbar_style; GUI<CStr>::GetSetting(this, "scrollbar_style", scrollbar_style); GetScrollBar(0).SetScrollBarStyle( scrollbar_style ); } break; default: break; } IGUITextOwner::HandleMessage(Message); }