mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 11:34:54 +02:00
implement chat colors, rework on UI layout update system
This commit is contained in:
60
modules/game_console/console.lua
Normal file
60
modules/game_console/console.lua
Normal file
@@ -0,0 +1,60 @@
|
||||
Console = {}
|
||||
|
||||
-- private variables
|
||||
local SpeakTypes = {
|
||||
say = { color = '#FFFF00' },
|
||||
whisper = { color = '#FFFF00' },
|
||||
yell = { color = '#FFFF00' },
|
||||
monsterSay = { color = '#FE6500' },
|
||||
npcToPlayer = { color = '#5FF7F7' },
|
||||
channelYellow = { color = '#FFFF00' },
|
||||
channelWhite = { color = '#FFFFFF' },
|
||||
channelRed = { color = '#F55E5E' },
|
||||
channelOrange = { color = '#FE6500' },
|
||||
private = { color = '#FFFF00' },
|
||||
playerToNpc = { color = '#9F9DFD' },
|
||||
broadcast = { color = '#F55E5E' },
|
||||
privateRed = { color = '#F55E5E' }
|
||||
}
|
||||
|
||||
local consolePanel
|
||||
local consoleBuffer
|
||||
|
||||
-- public functions
|
||||
function Console.create()
|
||||
consolePanel = displayUI('console.otui', { parent = Game.gameBottomPanel } )
|
||||
consoleBuffer = consolePanel:getChildById('consoleBuffer')
|
||||
end
|
||||
|
||||
function Console.destroy()
|
||||
consolePanel:destroy()
|
||||
consolePanel = nil
|
||||
end
|
||||
|
||||
function Console.addText(text, color)
|
||||
color = color or 'white'
|
||||
|
||||
local label = createWidget('ConsoleLabel', consoleBuffer)
|
||||
label:setText(text)
|
||||
label:setForegroundColor(color)
|
||||
end
|
||||
|
||||
-- hooked events
|
||||
local function onCreatureSpeak(name, level, speaktypedesc, message)
|
||||
speaktype = SpeakTypes[speaktypedesc]
|
||||
if speaktype == nil then return end
|
||||
|
||||
if name then
|
||||
if Options.showLevelInConsole and level > 0 then
|
||||
message = name .. ' [' .. level .. ']: ' .. message
|
||||
else
|
||||
message = name .. ': ' .. message
|
||||
end
|
||||
end
|
||||
|
||||
Console.addText(message, speaktype.color)
|
||||
end
|
||||
|
||||
connect(Game, { onLogin = Console.create,
|
||||
onLogout = Console.destroy,
|
||||
onCreatureSpeak = onCreatureSpeak})
|
7
modules/game_console/console.otmod
Normal file
7
modules/game_console/console.otmod
Normal file
@@ -0,0 +1,7 @@
|
||||
Module
|
||||
name: game_console
|
||||
description: Manage chat window
|
||||
author: OTClient team
|
||||
website: https://github.com/edubart/otclient
|
||||
onLoad: |
|
||||
require 'console'
|
33
modules/game_console/console.otui
Normal file
33
modules/game_console/console.otui
Normal file
@@ -0,0 +1,33 @@
|
||||
ConsoleLabel < UILabel
|
||||
font: verdana-11px-antialised
|
||||
height: 14
|
||||
color: yellow
|
||||
|
||||
Panel
|
||||
id: consolePanel
|
||||
anchors.fill: parent
|
||||
|
||||
Panel
|
||||
id: consoleBuffer
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: consoleLineEdit.top
|
||||
margin-right: 6
|
||||
margin-left: 6
|
||||
margin-bottom: 2
|
||||
margin-top: 6
|
||||
layout:
|
||||
type: verticalBox
|
||||
align-bottom: true
|
||||
focusable: false
|
||||
|
||||
LineEdit
|
||||
id: consoleLineEdit
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
margin-right: 6
|
||||
margin-left: 6
|
||||
margin-bottom: 6
|
||||
always-active: true
|
Reference in New Issue
Block a user