Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #95 from Nats-ji/overhaul
Browse files Browse the repository at this point in the history
Overhaul
  • Loading branch information
Nats-ji authored Feb 22, 2021
2 parents f18f0ec + 9ea501d commit 7d69479
Show file tree
Hide file tree
Showing 13 changed files with 366 additions and 103 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ builds/*
mods/braindance_protocol/braindance_protocol*.log
mods/braindance_protocol/db.sqlite3
mods/braindance_protocol/config.json
mods/braindance_protocol/favorites.json
mods/braindance_protocol/lang/*_old.lua
51 changes: 9 additions & 42 deletions mods/braindance_protocol/hotkeys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local BD = require("BD")
local protocols = require("protocols")
local ui = require("ui")
local i18n = require("i18n")
local Options = require("options")

local hotkeys = {}

Expand All @@ -15,54 +16,20 @@ hotkeys.bindings = {
end
ui.drawWindow = not ui.drawWindow
end
},

{
ID = "hotkey_godMode",
Callback = function() BD.Cheats.Player.GodModeToggle() end
},

{
ID = "hotkey_infStamina",
Callback = function() BD.Cheats.Player.InfiniteStaminaToggle() end
},

{
ID = "hotkey_slowMo",
Callback = function() BD.Cheats.Player.SlowMotionToggle() end
},

{
ID = "hotkey_addAmmo",
Callback = function() BD.Cheats.Ammo.AddAmmo() end
},

{
ID = "hotkey_infAmmo",
Callback = function() BD.Cheats.Ammo.InfiniteAmmoToggle() end
},

{
ID = "hotkey_noReload",
Callback = function() BD.Cheats.Ammo.InfiniteAmmoNoReloadToggle() end
},

{
ID = "hotkey_addMoney",
Callback = function() BD.Cheats.Player.AddMoney(10000) end
},

{
ID = "hotkey_forceKillNPC",
Callback = function() BD.Cheats.Player.ForceNPCDeath() end
},

}
}

function hotkeys:Register()
for _, v in ipairs(self.bindings) do
registerHotkey(v.ID, i18n(v.ID), v.Callback)
end
for _, v in ipairs(Options.fav_value.hk) do
for _, pv in ipairs(protocols.Items) do
if pv.id == v then
registerHotkey(pv.id:gsub(".","_"), i18n(pv.name), pv.cmd)
end
end
end
end

return hotkeys
5 changes: 5 additions & 0 deletions mods/braindance_protocol/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local hotkeys = require("hotkeys")
local ui = require("ui")
local Options = require("options")
Options:load()
Options:loadfav()

hotkeys:Register()
ui:Update()
Expand All @@ -12,4 +13,8 @@ registerForEvent("onInit", function()
print("[BD] Braindance Protocol Initialized!")
end)

registerForEvent("onShutdown", function()
Options:savefav()
end)

return BD
13 changes: 5 additions & 8 deletions mods/braindance_protocol/lang/cn.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
return {
cn = {
hotkey_interface = "打开界面" ,
hotkey_godMode = "切换上帝模式" ,
hotkey_infStamina = "切换无限耐力" ,
hotkey_slowMo = "切换慢动作" ,
hotkey_addAmmo = "添加弹药" ,
hotkey_infAmmo = "切换无限弹药" ,
hotkey_noReload = "切换无需装弹" ,
hotkey_addMoney = "添加钱" ,
hotkey_forceKillNPC = "杀死NPC" ,
window_title = "超梦协议" ,
button_addfav_tooltip = "添加至收藏" ,
button_addhk_tooltip = "添加至热键列表" ,
header_fav = "收藏" ,
text_hklist_none = "你还未添加任何协议到热键列表..." ,
searchbar_hint = "搜索协议..." ,
button_toggle_hklist_tooltip = "显示热键列表" ,
button_language = "简中" ,
button_language_tooltip = "选择语言" ,
button_update_lang = "更新语言文件" ,
Expand Down
15 changes: 6 additions & 9 deletions mods/braindance_protocol/lang/da.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
return {
da = {
hotkey_interface = "Åben BDP Brugerflade" ,
hotkey_godMode = "Udødelighed Toggle" ,
hotkey_infStamina = "Uendelig Stamina Toggle" ,
hotkey_slowMo = "Slow Motion Toggle" ,
hotkey_addAmmo = "Genopfyld Ammunition" ,
hotkey_infAmmo = "Uendelig Ammunition Toggle" ,
hotkey_noReload = "No Reload Toggle" ,
hotkey_addMoney = "Tilføj Nogle Penge" ,
hotkey_forceKillNPC = "Dræb NPC" ,
window_title = "Braindance Protokol" ,
-- button_addfav_tooltip = "Add to favorites" ,
-- button_addhk_tooltip = "Add to hotkey list" ,
-- header_fav = "Favorites" ,
-- text_hklist_none = "No protocol added to the hotkey list yet." ,
searchbar_hint = "Søg Protokol.." ,
-- button_toggle_hklist_tooltip = "Show Hotkey List" ,
button_language = "DA" ,
button_language_tooltip = "Vælg Sprog" ,
button_update_lang = "Opdater Sprog Filer" ,
Expand Down Expand Up @@ -859,4 +856,4 @@ return {
item_Vehicles_GetYaibaKusanagiMizuchi_tip = "Tilføj køretøjet Yaiba - Kusanagi 'Mizuchi'" ,
item_Vehicles_GetYaibaKusanagiMizuchi_btn = "Udfør"
}
}
}
13 changes: 5 additions & 8 deletions mods/braindance_protocol/lang/de.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
return {
de = {
-- hotkey_interface = "Open Protocol Interface" ,
-- hotkey_godMode = "God Mode Toggle" ,
-- hotkey_infStamina = "Infinite Stamina Toggle" ,
-- hotkey_slowMo = "Slow Motion Toggle" ,
-- hotkey_addAmmo = "Refill Ammunition" ,
-- hotkey_infAmmo = "Infinite Ammunition Toggle" ,
-- hotkey_noReload = "No Reload Toggle" ,
-- hotkey_addMoney = "Add Some Money" ,
-- hotkey_forceKillNPC = "Force Kill NPC" ,
window_title = "Braindance Protocol" ,
-- button_addfav_tooltip = "Add to favorites" ,
-- button_addhk_tooltip = "Add to hotkey list" ,
-- header_fav = "Favorites" ,
-- text_hklist_none = "No protocol added to the hotkey list yet." ,
-- searchbar_hint = "Search Protocol.." ,
-- button_toggle_hklist_tooltip = "Show Hotkey List" ,
button_language = "DE" ,
-- button_language_tooltip = "Select Language" ,
-- button_update_lang = "Update Language Files" ,
Expand Down
13 changes: 5 additions & 8 deletions mods/braindance_protocol/lang/en.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
return {
en = {
hotkey_interface = "Open Protocol Interface" ,
hotkey_godMode = "God Mode Toggle" ,
hotkey_infStamina = "Infinite Stamina Toggle" ,
hotkey_slowMo = "Slow Motion Toggle" ,
hotkey_addAmmo = "Refill Ammunition" ,
hotkey_infAmmo = "Infinite Ammunition Toggle" ,
hotkey_noReload = "No Reload Toggle" ,
hotkey_addMoney = "Add Some Money" ,
hotkey_forceKillNPC = "Force Kill NPC" ,
window_title = "Braindance Protocol" ,
button_addfav_tooltip = "Add to favorites" ,
button_addhk_tooltip = "Add to hotkey list" ,
header_fav = "Favorites" ,
text_hklist_none = "No protocol added to the hotkey list yet." ,
searchbar_hint = "Search Protocol.." ,
button_toggle_hklist_tooltip = "Show Hotkey List" ,
button_language = "EN" ,
button_language_tooltip = "Select Language" ,
button_update_lang = "Update Language Files" ,
Expand Down
13 changes: 5 additions & 8 deletions mods/braindance_protocol/lang/ru.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
return {
ru = {
-- hotkey_interface = "Open Protocol Interface" ,
-- hotkey_godMode = "God Mode Toggle" ,
-- hotkey_infStamina = "Infinite Stamina Toggle" ,
-- hotkey_slowMo = "Slow Motion Toggle" ,
-- hotkey_addAmmo = "Refill Ammunition" ,
-- hotkey_infAmmo = "Infinite Ammunition Toggle" ,
-- hotkey_noReload = "No Reload Toggle" ,
-- hotkey_addMoney = "Add Some Money" ,
-- hotkey_forceKillNPC = "Force Kill NPC" ,
window_title = "Протокол Брейнданса" ,
-- button_addfav_tooltip = "Add to favorites" ,
-- button_addhk_tooltip = "Add to hotkey list" ,
-- header_fav = "Favorites" ,
-- text_hklist_none = "No protocol added to the hotkey list yet." ,
-- searchbar_hint = "Search Protocol.." ,
-- button_toggle_hklist_tooltip = "Show Hotkey List" ,
button_language = "RU" ,
-- button_language_tooltip = "Select Language" ,
-- button_update_lang = "Update Language Files" ,
Expand Down
79 changes: 66 additions & 13 deletions mods/braindance_protocol/options.lua
Original file line number Diff line number Diff line change
@@ -1,41 +1,94 @@
local Options = {
filename = "config.json",
value = {}
config_file = "config.json",
fav_file = "favorites.json",
config_value = {},
fav_value = {},
}
local i18n = require("i18n")
local protocols = require("protocols")

function Options:loadfav()
local f = io.open(self.fav_file, "r")
if f then
self.fav_value = json.decode(f:read("*a"))
f:close()
for _, v in ipairs(self.fav_value.hk) do
for _, pv in ipairs(protocols.Items) do
if pv.id == v then
pv.hk = true
end
end
end
for _, v in ipairs(self.fav_value.fav) do
for _, pv in ipairs(protocols.Items) do
if pv.id == v then
pv.fav = true
end
end
end
else
self.fav_value = {
hk = {},
fav = {}
}
self:savefav()
end
end

function Options:savefav()
local f = io.open(self.fav_file, "w")
local jfav = json.encode(self.fav_value)
f:write(jfav)
f:close()
end

function Options:save()
local f = io.open(self.filename, "w")
local jconfig = json.encode(self.value)
local f = io.open(self.config_file, "w")
local jconfig = json.encode(self.config_value)
f:write(jconfig)
f:close()
end

function Options:load()
local f = io.open(self.filename, "r")
local f = io.open(self.config_file, "r")
if f then
self.value = json.decode(f:read("*a"))
self.config_value = json.decode(f:read("*a"))
f:close()
if self.value.lang == nil then
self.value.lang = "en"
if self.config_value.lang == nil then
self.config_value.lang = "en"
self:save()
end
else
self.value = { lang = "en" }
self.config_value = { lang = "en" }
self:save()
end
if self.value.lang ~= "en" then
if self.config_value.lang ~= "en" then
i18n.loadFile("lang/en.lua")
end
i18n.loadFile("lang/"..self.value.lang..".lua")
i18n.setLocale(self.value.lang)
i18n.loadFile("lang/"..self.config_value.lang..".lua")
i18n.setLocale(self.config_value.lang)
end

function Options:setLang(language)
i18n.loadFile("lang/"..language..".lua")
i18n.setLocale(language)
self.value.lang = language
self.config_value.lang = language
self:save()
end

function Options.removeOrinsert(tbl, value)
local remove, pos
for i, v in ipairs(tbl) do
if v == value then
remove = true
pos = i
end
end
if remove then
table.remove(tbl, pos)
else
table.insert(tbl, value)
end
end

return Options
4 changes: 3 additions & 1 deletion mods/braindance_protocol/ui/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ function ui:Draw()
ImGui.BeginChild("List", Childx+6, Childy)

if self.searchbar.text ~= "" then
self.searchlist:Draw()
self.searchlist.Draw()
elseif self.searchbar.draw_hklist then
self.list.DrawHKlist()
else
self.list.DrawTree()
end
Expand Down
Loading

0 comments on commit 7d69479

Please sign in to comment.