otland / forgottenserver

A free and open-source MMORPG server emulator written in C++
https://otland.net
GNU General Public License v2.0
1.58k stars 1.05k forks source link

TextWindow interactive #4668

Closed MillhioreBT closed 4 months ago

MillhioreBT commented 5 months ago

Changes Proposed

Modal windows allow interactivity and are very good and have a helper that makes it very comfortable to build complex window systems without so much code...

Some time ago in this PR I added tracking the ID of these classic windows. This PR brings a bit of interactivity for classic text windows through an helper.

here I will show you an example:

data/scripts/creaturescripts/player/#text_window_example.lua

local reactWindow = TalkAction("!textWindow")

function reactWindow.onSay(player, words, param, type)
    local txtWindow = TextWindow({
        itemId = 1234,
        text = "Write something here:",
        canWrite = true,
        length = 100,
        callback = function(player, item, text)
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You wrote: " .. text)
            return true
        end
    })

    txtWindow:sendToPlayer(player)
    return false
end

reactWindow:register()

Issues addressed: Nothing!