创建 WoW 插件 - 第 13 部分:生活质量的变化
Part 13: Quality of Life Changes
第 13 部分:生活质量的变化
Difficulty: ? Easy 难度: ? 容易
Congratulations on finishing your first World of Warcraft addon! Below, we'll cover some quality of life changes we can make that you may have noticed while developing the addon. Let's get into it!
恭喜您完成了您的第一个魔兽世界插件!下面,我们将介绍您可以在 开发插件时可能已经注意到的一些生活质量变化。让我们开始吧!
Final Step: Our Big QoL Change!
最后一步:我们的 QoL 重大变化!
Our big quality of life change is... you guessed it! The gold
, silver
and copper
display text in our addon's interface!
我们的生活质量发生重大变化是......你猜对了!金
、银
和铜
在我们插件的界面中显示文本!
This was (purposely) made poorly. In an effort to get it working, we skimped on the appearance of this information to the player. Not only was it horrible looking, but it was syntactically wrong. We're going to correct that now.
这是(故意)做得很差的。为了让它正常工作,我们忽略了这些信息对玩家的显示。它不仅看起来很糟糕,而且在语法上也是错误的。我们现在要纠正这个问题。
There are several ways to improve this: icons, colored text, etc. We're going to take the colored text route for now. Feel free to try and add icons for the coins yourself! It's challenging but fruitful! For now, let's make some changes.
有几种方法可以改善这种情况:图标、彩色文本等。我们现在将采用彩色文本路线。随意尝试自己为硬币添加图标!这很有挑战性,但很有成效!现在,让我们进行一些更改。
In our main .lua file, let's find our mainFrame.totalCurrency
property. We're going to make a slight modification. On the SetText()
line, we're going to change it to:
在我们的主 .lua 文件中,让我们找到我们的 mainFrame.totalCurrency
属性。我们将进行轻微的修改。在 SetText()
行中,我们要将其更改为:
mainFrame.totalCurrency:SetText("Total Currency Collected:")
This is going to be our "start line" for our currency display. Next, we're going to add some more FontStrings that will display our gold
, silver
and copper
separately, with some color!
这将是我们货币显示的“起跑线”。接下来,我们将添加更多的 FontString,它们将分别显示我们的 gold
、silver
和 copper
,并带有一些颜色!
Let's add this code right under the line we just modified!
让我们在我们刚刚修改的行下面添加此代码!
mainFrame.currencyGold = mainFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal") mainFrame.currencyGold:SetPoint("TOPLEFT", mainFrame.totalCurrency, "BOTTOMLEFT", 10, -15) mainFrame.currencyGold:SetText("|cFFFFD700Gold: |cFFFFFFFF" .. (MyAddonDB.gold or "0")) mainFrame.currencySilver = mainFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal") mainFrame.currencySilver:SetPoint("TOPLEFT", mainFrame.currencyGold, "BOTTOMLEFT", 0, -15) mainFrame.currencySilver:SetText("|cFFC7C7C7FSilver: |cFFFFFFFF" .. (MyAddonDB.silver or "0")) mainFrame.currencyCopper = mainFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal") mainFrame.currencyCopper:SetPoint("TOPLEFT", mainFrame.currencySilver, "BOTTOMLEFT", 0, -15) mainFrame.currencyCopper:SetText("|cFFD7BEA5Copper: |cFFFFFFFF" .. (MyAddonDB.copper or "0"))
You'll notice |cFF
and |r
are used to color the text and reset the text color.
您会注意到 |cFF
和 |r
用于为文本着色并重置文本颜色。
The code following |cFF
is HEX
color coding. For example, red text would be: |cFFFF0000
.|cFF
后面的代码是十六进制
颜色编码。例如,红色文本将为:|cFFFF0000
。
|cFF
+ FF0000
(Hex Color Code)|cFF
+ FF0000
(十六进制颜色代码)
Use |r
to reset your text color 1 level. By that I mean, if you use multiple |c
color codes without using |r
, you can overlap colors just fine, but using |r
will only revert one level of color change back. Let me give an example:
使用 |r
将文本颜色重置 1 级。我的意思是,如果你使用多个 |c
颜色代码而不使用 |r
,你可以很好地重叠颜色,但使用 |r
只会恢复一个级别的颜色变化。让我举个例子:
SetText("This is default yellow. |cFFFFFFFFThis is White! |cFFFF0000This is red! |r This is back to white, not default yellow!")
Hopefully that clears it up a bit!
希望这能稍微澄清一下!
Go ahead and login or /reload
your game to checkout the change we made! Visually, it should align much better with our standards! Once again, you can take this a step further and incorporate the icons into the text and make it pop even more!
继续登录或 /reload
您的游戏以查看我们所做的更改!从视觉上看,它应该更符合我们的标准!再一次,您可以更进一步,将图标合并到文本中,使其更加流行!
We're also going to delete totalCurrency:SetText()
from the "OnShow"
script for mainFrame
and add our gold
, silver
and copper
currency strings instead.
我们还将从 mainFrame
的 “OnShow”
脚本中删除 totalCurrency:SetText(),
并添加我们的金
、银
和铜
货币字符串。
The code, in its entirety for mainFrame:SetScript("OnShow", function()
, should look like this:
的代码(完整 mainFrame:SetScript("OnShow", function()
)应如下所示:
mainFrame:SetScript("OnShow", function() PlaySound(808) mainFrame.totalPlayerKills:SetText("Total Kills: " .. (MyAddonDB.kills or "0")) mainFrame.currencyGold:SetText("|cFFFFD700Gold: |cFFFFFFFF" .. (MyAddonDB.gold or "0")) mainFrame.currencySilver:SetText("|cFFC7C7C7FSilver: |cFFFFFFFF" .. (MyAddonDB.silver or "0")) mainFrame.currencyCopper:SetText("|cFFD7BEA5Copper: |cFFFFFFFF" .. (MyAddonDB.copper or "0")) end)
We can also go down a bit further in the code and do the same thing inside of our eventHandler
function for if mainFrame:IsShown() then
if then
statement. The full code here should look as such:
我们也可以在代码中更进一步,在 eventHandler
函数中对 if mainFrame:IsShown() then
if then 语句
执行相同的操作。此处的完整代码应如下所示:
if mainFrame:IsShown() then mainFrame.totalPlayerKills:SetText("Total Kills: " .. (MyAddonDB.kills or "0")) mainFrame.currencyGold:SetText("|cFFFFD700Gold: |cFFFFFFFF" .. (MyAddonDB.gold or "0")) mainFrame.currencySilver:SetText("|cFFC7C7C7FSilver: |cFFFFFFFF" .. (MyAddonDB.silver or "0")) mainFrame.currencyCopper:SetText("|cFFD7BEA5Copper: |cFFFFFFFF" .. (MyAddonDB.copper or "0")) end
We're done! Our addon is functioning perfectly (for now, and without much testing)!
我们完成了!我们的插件运行良好(目前,无需太多测试)!
We can test this some more and call it a day, or we can go one step further with a few bonus tasks and include some nice, new, shiny features! If you feel like giving that a go, let's do it! Click below for the bonus tasks!
我们可以对此进行更多测试,然后收工,或者我们可以更进一步,添加一些额外的任务,并包含一些漂亮的、新的、闪亮的功能!如果您想试一试,那就去做吧!点击下方查看奖励任务!