mirror of
https://github.com/edubart/otclient.git
synced 2025-11-30 07:26:49 +01:00
implement chat colors, rework on UI layout update system
This commit is contained in:
@@ -178,7 +178,6 @@ function Terminal.addLine(text, color)
|
||||
terminalBuffer:getChildByIndex(1):destroy()
|
||||
else
|
||||
terminalBuffer:setHeight(terminalBuffer:getHeight() + LabelHeight)
|
||||
terminalBuffer:updateParentLayout()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ function Options.init()
|
||||
local booleanOptions = { vsync = true,
|
||||
showfps = true,
|
||||
fullscreen = false,
|
||||
classicControl = false }
|
||||
classicControl = false,
|
||||
showLevelInConsole = false}
|
||||
|
||||
for k,v in pairs(booleanOptions) do
|
||||
Settings.setDefault(k, v)
|
||||
|
||||
@@ -19,7 +19,7 @@ OptionCheckBox < CheckBox
|
||||
MainWindow
|
||||
id: optionsWindow
|
||||
title: Options
|
||||
size: 286 140
|
||||
size: 286 160
|
||||
@onEnter: Options.hide()
|
||||
@onEscape: Options.hide()
|
||||
|
||||
@@ -40,6 +40,10 @@ MainWindow
|
||||
id: classicControl
|
||||
text: Classic control
|
||||
|
||||
OptionCheckBox
|
||||
id: showLevelInConsole
|
||||
text: Show players level in console
|
||||
|
||||
Button
|
||||
text: Ok
|
||||
width: 64
|
||||
|
||||
@@ -20,7 +20,6 @@ function MessageBox.create(title, text, flags)
|
||||
-- set window size based on label size
|
||||
window:setWidth(math.max(label:getWidth() + 48, 120))
|
||||
window:setHeight(label:getHeight() + 64)
|
||||
window:updateParentLayout()
|
||||
|
||||
-- setup messagebox first button
|
||||
local buttonRight = window:getChildById('messageBoxRightButton')
|
||||
|
||||
@@ -10,7 +10,7 @@ Module
|
||||
- game_skills
|
||||
- game_textmessage
|
||||
- game_viplist
|
||||
- game_chat
|
||||
- game_console
|
||||
- game_outfit
|
||||
|
||||
onLoad: |
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
Chat = {}
|
||||
|
||||
-- private variables
|
||||
--[[
|
||||
local SpeakTypes = {
|
||||
say = { color = },
|
||||
whisper = { color = },
|
||||
yell,
|
||||
monsterSay,
|
||||
npcToPlayer,
|
||||
cgannelYellow,
|
||||
channelWhite,
|
||||
channelRed,
|
||||
channelOrange,
|
||||
private,
|
||||
playerToNpc,
|
||||
broadcast,
|
||||
privateRed
|
||||
}
|
||||
]]--
|
||||
|
||||
local chatPanel
|
||||
local chatBuffer
|
||||
|
||||
-- public functions
|
||||
function Chat.create()
|
||||
chatPanel = displayUI('chat.otui', { parent = Game.gameBottomPanel } )
|
||||
chatBuffer = chatPanel:getChildById('chatBuffer')
|
||||
end
|
||||
|
||||
function Chat.destroy()
|
||||
chatPanel:destroy()
|
||||
chatPanel = nil
|
||||
end
|
||||
|
||||
-- hooked events
|
||||
local function onCreatureSpeak(name, level, msgtype, message)
|
||||
style = 'ChatLabel'
|
||||
if name and level > 0 then
|
||||
message = name .. ' [' .. level .. ']: ' .. message
|
||||
style = 'YellowChatLabel'
|
||||
end
|
||||
|
||||
local label = createWidget(style)
|
||||
label:setText(message)
|
||||
chatBuffer:addChild(label)
|
||||
end
|
||||
|
||||
connect(Game, { onLogin = Chat.create,
|
||||
onLogout = Chat.destroy,
|
||||
onCreatureSpeak = onCreatureSpeak})
|
||||
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})
|
||||
@@ -1,7 +1,7 @@
|
||||
Module
|
||||
name: game_chat
|
||||
name: game_console
|
||||
description: Manage chat window
|
||||
author: OTClient team
|
||||
website: https://github.com/edubart/otclient
|
||||
onLoad: |
|
||||
require 'chat'
|
||||
require 'console'
|
||||
@@ -1,20 +1,18 @@
|
||||
ChatLabel < UILabel
|
||||
ConsoleLabel < UILabel
|
||||
font: verdana-11px-antialised
|
||||
height: 14
|
||||
|
||||
YellowChatLabel < ChatLabel
|
||||
color: yellow
|
||||
|
||||
Panel
|
||||
id: chatPanel
|
||||
id: consolePanel
|
||||
anchors.fill: parent
|
||||
|
||||
Panel
|
||||
id: chatBuffer
|
||||
id: consoleBuffer
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: chatLineEdit.top
|
||||
anchors.bottom: consoleLineEdit.top
|
||||
margin-right: 6
|
||||
margin-left: 6
|
||||
margin-bottom: 2
|
||||
@@ -25,7 +23,7 @@ Panel
|
||||
focusable: false
|
||||
|
||||
LineEdit
|
||||
id: chatLineEdit
|
||||
id: consoleLineEdit
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
@@ -58,7 +58,6 @@ function Skills.onSkillButtonClick(button)
|
||||
else
|
||||
button:setHeight(21 - 6)
|
||||
end
|
||||
button:updateParentLayout()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ local MessageTypes = {
|
||||
warning = { color = '#F55E5E', showOnConsole = true, windowLocation = 'center' },
|
||||
eventAdvance = { color = '#FFFFFF', showOnConsole = true, windowLocation = 'center' },
|
||||
eventDefault = { color = '#FFFFFF', showOnConsole = true, windowLocation = 'bottom' },
|
||||
eventOrange = { color = '#FE6500', showOnConsole = true, windowLocation = 'bottom' },
|
||||
statusDefault = { color = '#FFFFFF', showOnConsole = true, windowLocation = 'bottom' },
|
||||
infoDescription = { color = '#00EB00', showOnConsole = true, windowLocation = 'center' },
|
||||
statusSmall = { color = '#FFFFFF', showOnConsole = false, windowLocation = 'bottom' },
|
||||
|
||||
Reference in New Issue
Block a user