Comforts für den Hexerei-Mod

Kopiere diese Funktionen under die Mod-Funktionen in das lokale Skript:
-- * * * * * * * * * * * * * * * * * * * * 
-- Comforts
-- * * * * * * * * * * * * * * * * * * * * 

function TableCopyAppend(_dest, _source)
    for k,v in pairs(_source) do
        if type(v) == "table" then
              if not _dest[k] then
                _dest[k] = TableCopyAppend({},v);
              end
        else
            if not _dest[k] then
                  _dest[k] = v;
            end
        end
    end
    return _dest;
end

function GetDistance( _pos1, _pos2 )
    if (type(_pos1) == "string") or (type(_pos1) == "number") then
        _pos1 = GetPosition(_pos1);
    end
    if (type(_pos2) == "string") or (type(_pos2) == "number") then
        _pos2 = GetPosition(_pos2);
    end
    if type(_pos1) ~= "table" or type(_pos2) ~= "table" then
        return;
    end
    local xDistance = (_pos1.X - _pos2.X);
    local yDistance = (_pos1.Y - _pos2.Y);
    return math.sqrt((xDistance^2) + (yDistance^2));
end

function UserSetTexture(widget, file)
    assert((type(widget) == "string" or type(widget) == "number"));
    local mapname = Framework.GetCurrentMapName();
    local wID = (type(widget) == "string" and XGUIEng.GetWidgetID(widget)) or widget;
    local screenSize = {GUI.GetScreenSize()};

    local state = 1;
    if XGUIEng.IsButton(wID) == 1 then
        state = 7;
    end

    local uScale = 1920/screenSize[1];
    local screendiv = screenSize[1]/screenSize[2];
    local u = (200 - (screendiv < 1.55 and 40 or 0)) * uScale;
    local v = (200 - (screendiv < 1.55 and 40 or 0)) * uScale;

    XGUIEng.SetMaterialAlpha(wID,state, 255);
    XGUIEng.SetMaterialTexture(wID,state,file);
    XGUIEng.SetMaterialUV(wID,state,0,0,u,v);
end

function UserSetTextNormal(_title,_text,_disabledText)
    local lang = Network.GetDesiredLanguage()
    if lang ~= "de" then lang = "en" end

    if type(_title) == "table" then
        _title = _title[lang];
    end
    if type(_text) == "table" then
        _text = _text[lang];
    end
    if type(_disabledText) == "table" then
        _disabledText = _disabledText[lang];
    end

    local TooltipContainerPath = "/InGame/Root/Normal/TooltipNormal"
    local TooltipContainer = XGUIEng.GetWidgetID(TooltipContainerPath)
    local TooltipNameWidget = XGUIEng.GetWidgetID(TooltipContainerPath .. "/FadeIn/Name")
    local TooltipDescriptionWidget = XGUIEng.GetWidgetID(TooltipContainerPath .. "/FadeIn/Text")
    local TooltipBGWidget = XGUIEng.GetWidgetID(TooltipContainerPath .. "/FadeIn/BG")
    local TooltipFadeInContainer = XGUIEng.GetWidgetID(TooltipContainerPath .. "/FadeIn")
    local PositionWidget = XGUIEng.GetCurrentWidgetID()
    GUI_Tooltip.ResizeBG(TooltipBGWidget, TooltipDescriptionWidget)
    local TooltipContainerSizeWidgets = {TooltipBGWidget}
    GUI_Tooltip.SetPosition(TooltipContainer, TooltipContainerSizeWidgets, PositionWidget)
    GUI_Tooltip.FadeInTooltip(TooltipFadeInContainer)

    _title = _title or (lang == "de" and "Schalter" or "Button");
    _text = _text or (lang == "de" and "Dieser Button löst etwas aus." or "The Button will trigger something.");
    _disabledText = _disabledText or (lang == "de" and "Noch nicht bereit!" or "Not ready yet!");
    local disabled = ""
    if XGUIEng.IsButtonDisabled(PositionWidget) == 1 then
        disabled = disabled .. "{cr}{@color:255,32,32,255}" .. _disabledText
    end

    XGUIEng.SetText(TooltipNameWidget, Umlaute("{center}" .. _title))
    XGUIEng.SetText(TooltipDescriptionWidget, Umlaute(_text .. disabled))
    local Height = XGUIEng.GetTextHeight(TooltipDescriptionWidget, true)
    local W, H = XGUIEng.GetWidgetSize(TooltipDescriptionWidget)
    XGUIEng.SetWidgetSize(TooltipDescriptionWidget, W, Height)
end

function UserSetTextBuy(_title,_text,_disabledText,_costs,_inSettlement)
    local lang = Network.GetDesiredLanguage()
    if lang ~= "de" then lang = "en" end

    if type(_title) == "table" then
        _title = _title[lang];
    end
    if type(_text) == "table" then
        _text = _text[lang];
    end
    if type(_disabledText) == "table" then
        _disabledText = _disabledText[lang];
    end

    local TooltipContainerPath = "/InGame/Root/Normal/TooltipBuy"
    local TooltipContainer = XGUIEng.GetWidgetID(TooltipContainerPath)
    local TooltipNameWidget = XGUIEng.GetWidgetID(TooltipContainerPath .. "/FadeIn/Name")
    local TooltipDescriptionWidget = XGUIEng.GetWidgetID(TooltipContainerPath .. "/FadeIn/Text")
    local TooltipBGWidget = XGUIEng.GetWidgetID(TooltipContainerPath .. "/FadeIn/BG")
    local TooltipFadeInContainer = XGUIEng.GetWidgetID(TooltipContainerPath .. "/FadeIn")
    local TooltipCostsContainer = XGUIEng.GetWidgetID(TooltipContainerPath .. "/Costs")
    local PositionWidget = XGUIEng.GetCurrentWidgetID()
    GUI_Tooltip.ResizeBG(TooltipBGWidget, TooltipDescriptionWidget)
    GUI_Tooltip.SetCosts(TooltipCostsContainer, _costs, _inSettlement)
    local TooltipContainerSizeWidgets = {TooltipContainer, TooltipCostsContainer, TooltipBGWidget}
    GUI_Tooltip.SetPosition(TooltipContainer, TooltipContainerSizeWidgets, PositionWidget, nil, true)
    GUI_Tooltip.OrderTooltip(TooltipContainerSizeWidgets, TooltipFadeInContainer, TooltipCostsContainer, PositionWidget, TooltipBGWidget)
    GUI_Tooltip.FadeInTooltip(TooltipFadeInContainer)

    _title = _title or (lang == "de" and "Schalter" or "Button");
    _text = _text or (lang == "de" and "Dieser Button löst etwas aus." or "The Button will trigger something.");
    _disabledText = _disabledText or (lang == "de" and "Noch nicht bereit!" or "Not ready yet!");
    local disabled = ""
    if XGUIEng.IsButtonDisabled(PositionWidget) == 1 then
        disabled = disabled .. "{cr}{@color:255,32,32,255}" .. _disabledText
    end

    XGUIEng.SetText(TooltipNameWidget, Umlaute("{center}" .. _title))
    XGUIEng.SetText(TooltipDescriptionWidget, Umlaute(_text .. disabled))
    local Height = XGUIEng.GetTextHeight(TooltipDescriptionWidget, true)
    local W, H = XGUIEng.GetWidgetSize(TooltipDescriptionWidget)
    XGUIEng.SetWidgetSize(TooltipDescriptionWidget, W, Height)
end

function IsValidPosition(pos)
    if type(pos) == "table" then
        if (pos.X ~= nil and type(pos.X) == "number") and (pos.Y ~= nil and type(pos.Y) == "number") then
            local world = {Logic.WorldGetSize()}
            if pos.X <= world[1] and pos.X >= 0 and pos.Y <= world[2] and pos.Y >= 0 then
                return true
            end
        end
    end
    return false
end

function SucheAufTerritorium(_player,_territorium,_eTypeOr0,_eCat,_eCatTypeFilter)
    assert(type(_player) == "number")
    local tID
    if type(_territorium) == "string" then
        local allTerritories = {Logic.GetTerritories()}
        for i=1,#allTerritories do
            if Logic.GetTerritoryName(allTerritories[i]) == _territorium then
                tID = allTerritories[i]
            end
        end
    else
        tID = _territorium
    end

    local output = {}
    if (_eTypeOr0 == nil or _eTypeOr0 == 0) and (_eCat ~= nil and _eCat > 0) then
        local Units = {}
        local NumLast = 0;

        if _player == -1 then
            for i=0,8 do
                repeat
                    local localUnits = { Logic.GetEntitiesOfCategoryInTerritory(tID, i, _eCat, NumLast) }
                    if #localUnits > 0 then Units = Array_Append(Units,localUnits) end
                    NumLast = NumLast + #localUnits;
                until #localUnits == 0
            end
        else
            repeat
                local localUnits = { Logic.GetEntitiesOfCategoryInTerritory(tID, _player, _eCat, NumLast) }
                if #localUnits > 0 then Units = Array_Append(Units,localUnits) end
                NumLast = NumLast + #localUnits;
            until #localUnits == 0
        end

        if #Units > 0 then
            for i=1,#Units do
                if _eCatTypeFilter ~= nil then
                    if type(_eCatTypeFilter) == "table" then
                        local IsType = false
                        for j=1,#_eCatTypeFilter do
                            if Logic.GetEntityType(Units[i]) == _eCatTypeFilter[j] then
                                IsType = true
                            end
                        end
                        if IsType == true then
                            output[#output+1] = Units[i]
                        end
                    else
                        if Logic.GetEntityType(Units[i]) == _eCatTypeFilter then
                            output[#output+1] = Units[i]
                        end
                    end
                else
                    output[#output+1] = Units[i]
                end
            end
        end

    elseif (_eCat == nil or _eCat == 0) and (_eTypeOr0 ~= nil and _eTypeOr0 ~= 0) then
        if type(_eTypeOr0) == "number" then
            local found = GetPlayerEntities(_player,_eTypeOr0)

            for k,v in pairs(found)do
                local pos = GetPosition(v)
                if Logic.GetTerritoryAtPosition(pos.X,pos.Y) == tID then
                    table.insert(output,v)
                end
            end
        elseif type(_eTypeOr0) == "table" then
            for i=1,#_eTypeOr0 do
                local found = GetPlayerEntities(_player,_eTypeOr0[i])

                for k,v in pairs(found)do
                    local pos = GetPosition(v)
                    if Logic.GetTerritoryAtPosition(pos.X,pos.Y) == tID then
                        table.insert(output,v)
                    end
                end
            end
        end
    end

    return output, #output
end

function Inside(_data,_table,_recursive)
    for k,v in pairs(_table) do
        if type(v) == "table" then
            if _recursive then
                return Inside(_data,v,_recursive);
            else
                if v == _data then
                    return true;
                end
            end
        else
            if v == _data then
                return true;
            end
        end
    end
    return false;
end
Zurück zu Hexerei | Drucken | Tags
Sofern nicht anders angegeben, steht der Inhalt dieser Seite unter Lizenz Creative Commons Attribution-ShareAlike 3.0 License