void Creature::setOutfit(const Outfit& outfit) { Outfit oldOutfit = m_outfit; if(outfit.getCategory() != ThingCategoryCreature) { if(!g_things.isValidDatId(outfit.getAuxId(), outfit.getCategory())) return; m_outfit.setAuxId(outfit.getAuxId()); m_outfit.setCategory(outfit.getCategory()); } else { if(outfit.getId() > 0 && !g_things.isValidDatId(outfit.getId(), ThingCategoryCreature)) return; m_outfit = outfit; } m_walkAnimationPhase = 0; // might happen when player is walking and outfit is changed. callLuaField("onOutfitChange", m_outfit, oldOutfit); }
void ProtocolLogin::parseCharacterList(InputMessage& inputMessage) { typedef std::tuple<std::string, std::string, std::string, int> CharacterInfo; typedef std::vector<CharacterInfo> CharaterList; CharaterList charList; int numCharacters = inputMessage.getU8(); for(int i = 0; i < numCharacters; ++i) { std::string name = inputMessage.getString(); std::string world = inputMessage.getString(); uint32 ip = inputMessage.getU32(); uint16 port = inputMessage.getU16(); charList.push_back(CharacterInfo(name, world, Fw::ip2str(ip), port)); } int premDays = inputMessage.getU16(); callLuaField("onCharacterList", charList, premDays); }
void LocalPlayer::setHealth(double health, double maxHealth) { if(m_health != health || m_maxHealth != maxHealth) { double oldHealth = m_health; double oldMaxHealth = m_maxHealth; m_health = health; m_maxHealth = maxHealth; callLuaField("onHealthChange", health, maxHealth, oldHealth, oldMaxHealth); // cannot walk while dying if(health == 0) { if(isPreWalking()) stopWalk(); lockWalk(); } } }
void Creature::setHealthPercent(uint8 healthPercent) { if(healthPercent > 92) m_informationColor = Color(0x00, 0xBC, 0x00); else if(healthPercent > 60) m_informationColor = Color(0x50, 0xA1, 0x50); else if(healthPercent > 30) m_informationColor = Color(0xA1, 0xA1, 0x00); else if(healthPercent > 8) m_informationColor = Color(0xBF, 0x0A, 0x0A); else if(healthPercent > 3) m_informationColor = Color(0x91, 0x0F, 0x0F); else m_informationColor = Color(0x85, 0x0C, 0x0C); m_healthPercent = healthPercent; callLuaField("onHealthPercentChange", healthPercent); }
void UIWidget::applyStyle(const OTMLNodePtr& styleNode) { if(m_destroyed) return; if(styleNode->size() == 0) return; m_loadingStyle = true; try { // translate ! style tags for(const OTMLNodePtr& node : styleNode->children()) { if(node->tag()[0] == '!') { std::string tag = node->tag().substr(1); std::string code = stdext::format("tostring(%s)", node->value()); std::string origin = "@" + node->source() + ": [" + node->tag() + "]"; g_lua.evaluateExpression(code, origin); std::string value = g_lua.popString(); node->setTag(tag); node->setValue(value); } } onStyleApply(styleNode->tag(), styleNode); callLuaField("onStyleApply", styleNode->tag(), styleNode); if(m_firstOnStyle) { UIWidgetPtr parent = getParent(); if(isFocusable() && isExplicitlyVisible() && isExplicitlyEnabled() && parent && ((!parent->getFocusedChild() && parent->getAutoFocusPolicy() == Fw::AutoFocusFirst) || parent->getAutoFocusPolicy() == Fw::AutoFocusLast)) { focus(); } } m_firstOnStyle = false; } catch(stdext::exception& e) { g_logger.traceError(stdext::format("failed to apply style to widget '%s': %s", m_id, e.what())); } m_loadingStyle = false; }
void UIWidget::internalDestroy() { m_destroyed = true; m_visible = false; m_enabled = false; m_parent.reset(); m_focusedChild = nullptr; m_layout = nullptr; m_lockedChildren.clear(); for(const UIWidgetPtr& child : m_children) child->internalDestroy(); m_children.clear(); callLuaField("onDestroy"); releaseLuaFieldsTable(); g_ui.onWidgetDestroy(asUIWidget()); }
void UIWidget::internalDestroy() { m_destroyed = true; m_visible = false; m_enabled = false; m_focusedChild = nullptr; if(m_layout) { m_layout->setParent(nullptr); m_layout = nullptr; } m_parent = nullptr; m_lockedChildren.clear(); for(const UIWidgetPtr& child : m_children) child->internalDestroy(); m_children.clear(); callLuaField("onDestroy"); releaseLuaFieldsTable(); g_ui.onWidgetDestroy(static_self_cast<UIWidget>()); }
void Creature::onDisappear() { if(m_disappearEvent) m_disappearEvent->cancel(); m_oldPosition = m_position; // a pair onDisappear and onAppear events are fired even when creatures walks or turns, // so we must filter auto self = static_self_cast<Creature>(); m_disappearEvent = g_dispatcher.addEvent([self] { self->m_removed = true; self->stopWalk(); self->callLuaField("onDisappear"); // invalidate this creature position if(!self->isLocalPlayer()) self->setPosition(Position()); self->m_oldPosition = Position(); self->m_disappearEvent = nullptr; }); }
void ProtocolLogin::onError(const boost::system::error_code& error) { callLuaField("onError", error.message(), true); disconnect(); }
void Creature::onDeath() { callLuaField("onDeath"); }
void ProtocolLogin::parseMOTD(InputMessage& inputMessage) { std::string motd = inputMessage.getString(); callLuaField("onMotd", motd); }
void UITextEdit::onTextAreaUpdate(const Point& offset, const Size& visibleSize, const Size& totalSize) { callLuaField("onTextAreaUpdate", offset, visibleSize, totalSize); }
void UIWidget::onVisibilityChange(bool visible) { if(!isAnchored()) bindRectToParent(); callLuaField("onVisibilityChange", visible); }
void UIWidget::onChildFocusChange(const UIWidgetPtr& focusedChild, const UIWidgetPtr& unfocusedChild, Fw::FocusReason reason) { callLuaField("onChildFocusChange", focusedChild, unfocusedChild, reason); }
void UIMinimap::onCameraPositionChange(const Position& position, const Position& oldPosition) { callLuaField("onCameraPositionChange", position, oldPosition); }
void UIMinimap::onZoomChange(int zoom, int oldZoom) { callLuaField("onZoomChange", zoom, oldZoom); }
void Creature::setEmblem(uint8 emblem) { m_emblem = emblem; callLuaField("onEmblemChange", m_emblem); }
void Creature::setShield(uint8 shield) { m_shield = shield; callLuaField("onShieldChange", m_shield); }
void Creature::setSkull(uint8 skull) { m_skull = skull; callLuaField("onSkullChange", m_skull); }
void Creature::onPositionChange(const Position& newPos, const Position& oldPos) { callLuaField("onPositionChange", newPos, oldPos); }
void UIWidget::onLayoutUpdate() { callLuaField("onLayoutUpdate"); }
void Creature::setType(uint8 type) { m_type = type; callLuaField("onTypeChange", m_type); }
void UIWidget::onFocusChange(bool focused, Fw::FocusReason reason) { callLuaField("onFocusChange", focused, reason); }
void UIWidget::onFontChange(const std::string& font) { callLuaField("onFontChange", font); }
void UIWidget::onHoverChange(bool hovered) { callLuaField("onHoverChange", hovered); }
void UIWidget::onTextChange(const std::string& text, const std::string& oldText) { g_app->repaint(); callLuaField("onTextChange", text, oldText); }
void Container::onClose() { m_closed = true; callLuaField("onClose"); }
void ProtocolLogin::parseError(InputMessage& inputMessage) { std::string error = inputMessage.getString(); callLuaField("onError", error, false); }
void UIWidget::setChecked(bool checked) { if(setState(Fw::CheckedState, checked)) callLuaField("onCheckChange", checked); }
void Creature::setIcon(uint8 icon) { m_icon = icon; callLuaField("onIconChange", m_icon); }