Skip to content
Permalink
Browse files

Language Field (#345)

* Add roleplay language field

This field displays an icon in the tooltip for a user indicating
their preferred roleplay language. On an upgrade, this will initialize
to the addon locale if set or will fall back to the client locale.

The setting can be changed from the dashboard as a new dropdown
with the RP status/RP XP options.

The icon will only display in tooltips if it differs from the
users currently selected locale; so you won't see enUS flags if
you're running TRP with the enUS locale selected since the info
isn't all that useful in that case.

* Fix Windows path slashes in submodules

* Appeasing the Luacheck and Travis gods

* Remove GetColoredName from read_globals

?

* Default LC field on profile import

* Rename icons table

* Normalize whitespace in luacheck

* Add Luacheck exclusions for TRP3_* globals

* Split dashboard status panel to its own file

Also relocated the MSA-based UIDropdownMenuTemplate to the general
purpose UI widgets.xml file, and refactored the dashboard status
code to be a bit simpler.

* Remove the unused NOTIFICATION_CHANGED event

* Minor comment fixes

* Fix inverted tooltip colors

* Remove trailing line from field tooltip

* Change color of "Advanced Settings" text

* Add more MSA globals to luacheck

* Re-remove the 7.2.5 GameTooltip workaround
  • Loading branch information...
Meorawr authored and Solanya committed Sep 4, 2019
1 parent 13595c0 commit e9058d9f98e39a6c5afb9a1e454371b745b97c7f
@@ -13,3 +13,6 @@
[submodule "totalRP3/libs/LibRPMedia"]
path = totalRP3/libs/LibRPMedia
url = https://github.com/wow-rp-addons/LibRPMedia
[submodule "totalRP3/libs/LibRealmInfo"]
path = totalRP3/libs/LibRealmInfo
url = https://github.com/phanx-wow/LibRealmInfo
@@ -75,6 +75,8 @@ read_globals = {
"XRP_RC",

-- MSA-DropDownMenu-1.0
"MSA_DROPDOWNMENU_OPEN_MENU",
"MSA_DROPDOWNMENU_INIT_MENU",
"MSA_CloseDropDownMenus",
"MSA_DropDownMenu_AddButton",
"MSA_DropDownMenu_AddSeparator",
@@ -19,6 +19,9 @@

local Ellyb = Ellyb(...);

-- Imports.
local Enums = AddOn_TotalRP3.Enums;

---@class Player : Object
local Player, _private = Ellyb.Class("Player")
---@type Player
@@ -146,7 +149,19 @@ function Player:IsCurrentUser()
end

function Player:IsInCharacter()
return self:GetInfo("character/RP") ~= 2
return self:GetRoleplayStatus() ~= Enums.ROLEPLAY_STATUS.OUT_OF_CHARACTER;
end

function Player:GetRoleplayLanguage()
return self:GetInfo("character/LC");
end

function Player:GetRoleplayExperience()
return self:GetInfo("character/XP");
end

function Player:GetRoleplayStatus()
return self:GetInfo("character/RP");
end

function Player:GetAccountType()
@@ -118,10 +118,25 @@ TRP3_API.events.listenToEvent(TRP3_API.events.WORKFLOW_ON_LOAD, function()
title = loc.CO_GENERAL_LOCALE,
listContent = localeTab,
listCallback = function(newLocaleCode)
if newLocaleCode ~= loc:GetActiveLocale():GetCode() then
Configuration.setValue("AddonLocale", newLocaleCode);
TRP3_API.popup.showConfirmPopup(loc.CO_GENERAL_CHANGELOCALE_ALERT:format(Ellyb.ColorManager.GREEN(loc:GetLocale(newLocaleCode):GetName())), ReloadUI);
if newLocaleCode == loc:GetActiveLocale():GetCode() then
-- Locale isn't changing.
return;
end

local oldLocale = Configuration.getValue("AddonLocale");
Configuration.setValue("AddonLocale", newLocaleCode);

-- If the user has any profiles that have an LC field matching
-- that of the locale we're swapping from, we'll assume they
-- probably want that changed. We could prompt, but we're
-- already doing that to reload the UI.
for _, profile in pairs(TRP3_Profiles) do
if profile.player and profile.player.character and profile.player.character.LC == oldLocale then
profile.player.character.LC = newLocaleCode;
end
end

TRP3_API.popup.showConfirmPopup(loc.CO_GENERAL_CHANGELOCALE_ALERT:format(Ellyb.ColorManager.GREEN(loc:GetLocale(newLocaleCode):GetName())), ReloadUI);
end,
listDefault = loc:GetActiveLocale():GetName(),
listCancel = true,
@@ -36,3 +36,17 @@ AddOn_TotalRP3.Enums.RELATIONSHIP_STATUS = {
DIVORCED = 4,
WIDOWED = 5,
}

-- ROLEPLAY_STATUS is an enumeration of roleplay statuses for a player unit.
AddOn_TotalRP3.Enums.ROLEPLAY_STATUS = {
IN_CHARACTER = 1,
OUT_OF_CHARACTER = 2,
};

-- ROLEPLAY_EXPERIENCE is an enumeration of roleplay experience entries for
-- a player, for example "beginner roleplayer".
AddOn_TotalRP3.Enums.ROLEPLAY_EXPERIENCE = {
BEGINNER = 1,
EXPERIENCED = 2,
VOLUNTEER = 3,
};
@@ -70,9 +70,6 @@ local Events = {
-- This is used by the tooltip and the target bar to be refreshed
REGISTER_ABOUT_READ = "REGISTER_ABOUT_READ",

-- Called when a notifications is created/read/removed
NOTIFICATION_CHANGED = "NOTIFICATION_CHANGED",

-- Called when Wow Event UPDATE_MOUSEOVER_UNIT is fired
-- Arg1 : Target ID
-- Arg2 : Target mode (Character, pet, battle pet ...)
@@ -589,9 +589,16 @@ function TRP3_API.profile.init()
wipe(profiles[profileID]);
profiles[profileID] = data;

-- Converting old music paths to new ID system
if data and data.player and data.player.about and data.player.about.MU and type(data.player.about.MU) == "string" then
profiles[profileID].player.about.MU = Utils.music.convertPathToID(data.player.about.MU);
if data then
-- Converting old music paths to new ID system
if data.player and data.player.about and data.player.about.MU and type(data.player.about.MU) == "string" then
profiles[profileID].player.about.MU = Utils.music.convertPathToID(data.player.about.MU);
end

-- Default preferred locale appropriately.
if data.character and not data.character.LC then
data.character.LC = TRP3_API.configuration.getValue("AddonLocale") or GetLocale();
end
end

TRP3_ProfileImport:Hide();
@@ -31,6 +31,8 @@ TRP3_API.ui = {
}

-- imports
local LibRealmInfo = LibStub:GetLibrary("LibRealmInfo");

local globals = TRP3_API.globals;
local loc = TRP3_API.loc;
local floor, tinsert, pairs, wipe, assert, _G, tostring, table, type, strconcat = floor, tinsert, pairs, wipe, assert, _G, tostring, table, type, strconcat;
@@ -1147,3 +1149,44 @@ function TRP3_API.ui.frame.setupMove(frame)
self:StopMovingOrSizing();
end)
end

--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
-- Locale Textures
--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

local LOCALE_ATLAS = [[Interface\AddOns\totalRP3\resources\locales]];
local LOCALE_ICONS = {
["deDE"] = CreateTextureMarkup(LOCALE_ATLAS, 64, 64, 16, 11, 0.00, 0.25, 0.00, 0.171875, 0, 0),
["enGB"] = CreateTextureMarkup(LOCALE_ATLAS, 64, 64, 16, 11, 0.25, 0.50, 0.00, 0.171875, 0, 0),
["enUS"] = CreateTextureMarkup(LOCALE_ATLAS, 64, 64, 16, 11, 0.50, 0.75, 0.00, 0.171875, 0, 0),
["esES"] = CreateTextureMarkup(LOCALE_ATLAS, 64, 64, 16, 11, 0.75, 1.00, 0.00, 0.171875, 0, 0),
["esMX"] = CreateTextureMarkup(LOCALE_ATLAS, 64, 64, 16, 11, 0.00, 0.25, 0.25, 0.421875, 0, 0),
["frFR"] = CreateTextureMarkup(LOCALE_ATLAS, 64, 64, 16, 11, 0.25, 0.50, 0.25, 0.421875, 0, 0),
["itIT"] = CreateTextureMarkup(LOCALE_ATLAS, 64, 64, 16, 11, 0.50, 0.75, 0.25, 0.421875, 0, 0),
["koKR"] = CreateTextureMarkup(LOCALE_ATLAS, 64, 64, 16, 11, 0.75, 1.00, 0.25, 0.421875, 0, 0),
["ptBR"] = CreateTextureMarkup(LOCALE_ATLAS, 64, 64, 16, 11, 0.00, 0.25, 0.50, 0.671875, 0, 0),
["ptPT"] = CreateTextureMarkup(LOCALE_ATLAS, 64, 64, 16, 11, 0.25, 0.50, 0.50, 0.671875, 0, 0),
["ruRU"] = CreateTextureMarkup(LOCALE_ATLAS, 64, 64, 16, 11, 0.50, 0.75, 0.50, 0.671875, 0, 0),
["zhCN"] = CreateTextureMarkup(LOCALE_ATLAS, 64, 64, 16, 11, 0.75, 1.00, 0.50, 0.671875, 0, 0),
["zhTW"] = CreateTextureMarkup(LOCALE_ATLAS, 64, 64, 16, 11, 0.00, 0.25, 0.75, 0.921875, 0, 0),
};

function TRP3_API.ui.misc.getLocaleIcon(localeCode)
-- Some regions should have their locale codes transformed for accuracy,
-- for example ptBR on EU realms should probably be ptPT.
local currentRegion = LibRealmInfo:GetCurrentRegion();
if not currentRegion then
currentRegion = GetCurrentRegionName();
end

if currentRegion == "EU" or currentRegion == "RU" then
-- EU/RU: enUS => enGB, ptBR => ptPT.
if localeCode == "enUS" then
localeCode = "enGB";
elseif localeCode == "ptBR" then
localeCode = "ptPT";
end
end

return LOCALE_ICONS[localeCode];
end
@@ -1163,4 +1163,138 @@
</OnLeave>
</Scripts>
</Frame>

<!--
Dropdown Menu
This mirrors UIDropDownMenuTemplate except the scripts for activating
the menu go through the MSA-DropDownMenu-1.0 library instead.
-->
<Frame name="TRP3_DropDownMenuTemplate" virtual="true">
<Size>
<AbsDimension x="40" y="32"/>
</Size>
<Layers>
<Layer level="ARTWORK">
<Texture name="$parentLeft" parentKey="Left" file="Interface\Glues\CharacterCreate\CharacterCreate-LabelFrame">
<Size>
<AbsDimension x="25" y="64"/>
</Size>
<Anchors>
<Anchor point="TOPLEFT">
<Offset>
<AbsDimension x="0" y="17"/>
</Offset>
</Anchor>
</Anchors>
<TexCoords left="0" right="0.1953125" top="0" bottom="1"/>
</Texture>
<Texture name="$parentMiddle" parentKey="Middle" file="Interface\Glues\CharacterCreate\CharacterCreate-LabelFrame">
<Size>
<AbsDimension x="115" y="64"/>
</Size>
<Anchors>
<Anchor point="LEFT" relativeKey="$parent.Left" relativePoint="RIGHT"/>
</Anchors>
<TexCoords left="0.1953125" right="0.8046875" top="0" bottom="1"/>
</Texture>
<Texture name="$parentRight" parentKey="Right" file="Interface\Glues\CharacterCreate\CharacterCreate-LabelFrame">
<Size>
<AbsDimension x="25" y="64"/>
</Size>
<Anchors>
<Anchor point="LEFT" relativeKey="$parent.Middle" relativePoint="RIGHT"/>
</Anchors>
<TexCoords left="0.8046875" right="1" top="0" bottom="1"/>
</Texture>
<FontString parentKey="Text" name="$parentText" inherits="GameFontHighlightSmall" wordwrap="false" justifyH="RIGHT">
<Size>
<AbsDimension x="0" y="10"/>
</Size>
<Anchors>
<Anchor point="RIGHT" relativeKey="$parent.Right">
<Offset>
<AbsDimension x="-43" y="2"/>
</Offset>
</Anchor>
</Anchors>
</FontString>
</Layer>
<Layer level="OVERLAY">
<Texture parentKey="Icon" name="$parentIcon" hidden="true">
<Size>
<AbsDimension x="16" y="16"/>
</Size>
<Anchors>
<Anchor point="LEFT">
<Offset x="30" y="2"/>
</Anchor>
</Anchors>
</Texture>
</Layer>
</Layers>
<Frames>
<Button parentKey="Button" name="$parentButton" motionScriptsWhileDisabled="true" >
<Size>
<AbsDimension x="24" y="24"/>
</Size>
<Anchors>
<Anchor point="TOPRIGHT" relativeKey="$parent.Right">
<Offset>
<AbsDimension x="-16" y="-18"/>
</Offset>
</Anchor>
</Anchors>
<Scripts>
<OnEnter>
ExecuteFrameScript(self:GetParent(), "OnEnter");
</OnEnter>
<OnLeave>
ExecuteFrameScript(self:GetParent(), "OnLeave");
</OnLeave>
<OnClick>
MSA_ToggleDropDownMenu(nil, nil, self:GetParent());
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
</OnClick>
</Scripts>
<NormalTexture name="$parentNormalTexture" parentKey="NormalTexture" file="Interface\ChatFrame\UI-ChatIcon-ScrollDown-Up">
<Size>
<AbsDimension x="24" y="24"/>
</Size>
<Anchors>
<Anchor point="RIGHT"/>
</Anchors>
</NormalTexture>
<PushedTexture name="$parentPushedTexture" parentKey="PushedTexture" file="Interface\ChatFrame\UI-ChatIcon-ScrollDown-Down">
<Size>
<AbsDimension x="24" y="24"/>
</Size>
<Anchors>
<Anchor point="RIGHT"/>
</Anchors>
</PushedTexture>
<DisabledTexture name="$parentDisabledTexture" parentKey="DisabledTexture" file="Interface\ChatFrame\UI-ChatIcon-ScrollDown-Disabled">
<Size>
<AbsDimension x="24" y="24"/>
</Size>
<Anchors>
<Anchor point="RIGHT"/>
</Anchors>
</DisabledTexture>
<HighlightTexture name="$parentHighlightTexture" parentKey="HighlightTexture" file="Interface\Buttons\UI-Common-MouseHilight" alphaMode="ADD">
<Size>
<AbsDimension x="24" y="24"/>
</Size>
<Anchors>
<Anchor point="RIGHT"/>
</Anchors>
</HighlightTexture>
</Button>
</Frames>
<Scripts>
<OnHide>
MSA_CloseDropDownMenus();
</OnHide>
</Scripts>
</Frame>
</Ui>
Submodule LibRealmInfo added at e8d40d
@@ -25,19 +25,20 @@
<Include file="CallbackHandler-1.0\CallbackHandler-1.0.xml" />
<Include file="LibDataBroker-1.1\LibDataBroker-1.1.lua" />
<Include file="LibDBIcon-1.0\LibDBIcon-1.0.lua" />
<Include file="LibRealmInfo\LibRealmInfo.lua" />

<!-- MSA DropDownMenu: Drop down library by Kaliel https://wow.curseforge.com/projects/msa-dropdownmenu-10 -->
<Include file="MSA-DropDownMenu-1.0\MSA-DropDownMenu-1.0.xml" />

<!-- Ellyb: shared library between our own projects -->
<Include file="Ellyb\Ellyb.xml" />

<!-- LibMSP: Newer version of the LibMSP, from https://github.com/Ellypse/LibMSP -->
<!-- LibMSP: Newer version of the LibMSP, from https://github.com/wow-rp-addons/LibMSP -->
<Include file="LibMSP\LibMSP.xml" />

<!-- LibDeflate https://github.com/SafeteeWoW/LibDeflate -->
<Include file="LibDeflate\lib.xml" />

<!-- LibRPMedia https://github.com/wow-rp-addons/LibRPMedia -->
<Include file="LibRPMedia\LibRPMedia-1.0.xml" />

0 comments on commit e9058d9

Please sign in to comment.
You can’t perform that action at this time.