Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: keybinds by oen | (limited) Part 1 #996

Merged
merged 11 commits into from
Dec 17, 2024
Merged

Conversation

InnerCircleTFS
Copy link
Contributor

Credits : oen

I’m not interested in the fan war between OTC, I liked this feature and I want it in my client. I’m sharing it.

Here is the original code for keybinds of Oen.

  • Part 1 integrates Keybins WITHOUT the walk. I could adapt it, but my intention is not to delay the Android branch any further, as it would cause conflicts in that branch. (game_joystick, game_walk)
    I will adapt Part 2 when that branch is merged in main repo.

  • Hotkeys are not adapted because I like the old version(me server is 10.98). If someone wants to adapt it in the future, I would appreciate it if they kept the old version compatible. :)

  • the "save" functionality is not adapted either, because I didn't like it. (if someone wants to do it, he should add a button and call this function applyChangedOptions() and setOption(key, option.value, option.force))

Keybinds system

Notes

  • Arrow keys are reserved and can NOT be used
  • Default keybinds can NOT share keys (you will be warned if it occurs)
  • Not every keybind is currently added, contributions in that matter are welcome
  • Some OTC keybinds are bound to UI/UX and should not be part of this Keybinds system
  • Action Bar is currently (yet) not integrated

Creating new keybind

Best place to add is init (or whatever onLoad executes) of your module.

Keybind.new(category, action, primary, secondary, alone)

Params

  • category (string) - category name, eg. "Dialogs"
  • action (string) - action name, eg. "Open Options" (creating "Dialogs: Open Options" name)
  • primary (string | table) - default primary key to trigger action, if used as string (can be empty but not nil), it will be applied to both Chat Modes, otherwise use table:
{
  [CHAT_MODE.ON] = "key", (can be empty)
  [CHAT_MODE.OFF] = "key" (can be empty)
}
  • secondary (string | table) - same as primary key
  • alone (bool, optional) - if true, action can be bound to only single key without modifiers (Ctrl, Alt, Shift)
Keybind.new("Dialogs", "Open Options", "Ctrl+O", "")

Keybind.new("Chat", "Send current chat line", { [CHAT_MODE.ON] = "Enter", [CHAT_MODE.OFF] = "" }, "") -- table for primary, string for secondary

Keybind.new("Movement", "Go North", {[CHAT_MODE.ON] = "", [CHAT_MODE.OFF] = "W"}, {[CHAT_MODE.ON] = "Numpad8", [CHAT_MODE.OFF] = ""}, true)

Binding keybinds

Creating keybinds is not enough, you have to make them do something. Binding is separated for multiple reasons but the most important one is that not everything is ready and loaded when client starts, some modules require player to enter the game to bind the keys. Must be used AFTER Keybind.new.

Keybind.bind(category, action, callbacks, widget)

Params

  • category (string) - category name, eg. "Dialogs"
  • action (string) - action name, eg. "Open Options"
  • callbacks (table) - table with table of config values:
{
  {
    type = (KEY_DOWN | KEY_UP | KEY_PRESS),
    callback = (function),
    alone = (bool)
  },
  -- can be multiple (see game_walking)
  {
    type = (KEY_DOWN | KEY_UP | KEY_PRESS),
    callback = (function),
    alone = (bool)
  }
}
  • widget (UIWidget, optional) - widget that should listen to key events (if not provided it will default to Root)

Example

  Keybind.bind("UI", "Toggle Full Map", {
    {
      type = KEY_DOWN,
      callback = toggleFullMap,
    }
  })

  Keybind.bind("Movement", "Go " .. DirectionString[North], {
    {
      type = KEY_DOWN,
      callback = function() changeWalkDir(dir) end,
      alone = true
    },
    {
      type = KEY_UP,
      callback = function() changeWalkDir(dir, true) end,
      alone = true
    },
    {
      type = KEY_PRESS,
      callback = function(c, k, ticks) smartWalk(dir, ticks) end
    }
  }, gameRootPanel)

Deleting Keybinds

Best place to add is terminate (or whatever onUnload executes) of your module. This is required, altho there is a check to prevent duplicate Keybinds, it is better to delete unused one before they readded in init or somewhere.

Keybind.delete(category, action)

Params

  • category (string) - category name, eg. "Dialogs"
  • action (string) - action name, eg. "Open Options"

Example

Keybind.delete("Dialogs", "Open Options")

Credits : oen

I’m not interested in the fan war between OTC, I liked this feature and I want it in my client. I’m sharing it.

@InnerCircleTFS
Copy link
Contributor Author

Notes:
There were minimal errors that pr fixed:

  • Shader and RuleViolation had the same hotkeys (Ctrl + Y), so I took the liberty of changing RuleViolation to Ctrl + U.
  • While testing, I noticed error in module game_cooldown that caused the console to lose focus.
  • When creating a button with
align-right: true
spacing: -5

The negative sign wasn't considered because it was uint8_t, so I changed it to int8_t.

If someone else could test it, I would appreciate it.

Copy link
Collaborator

@kokekanon kokekanon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parcial review

modules/client_options/options.lua Show resolved Hide resolved
modules/client_options/keybins.lua Outdated Show resolved Hide resolved
modules/client_options/keybins.lua Outdated Show resolved Hide resolved
modules/client_options/keybins.lua Outdated Show resolved Hide resolved
@@ -0,0 +1,766 @@

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@kokekanon
Copy link
Collaborator

that is visible in 8.6 change from onInit() to onGameStart()
image

@kokekanon
Copy link
Collaborator

kokekanon commented Dec 17, 2024

photoshop
quest log no work
and fps/ ping no work
image

@mehah
Copy link
Owner

mehah commented Dec 17, 2024

@kokekanon
@InnerCircleTFS done?

@InnerCircleTFS
Copy link
Contributor Author

@kokekanon @InnerCircleTFS done?

cee90ec fix bugs found by kokekanon

works in my environment

@mehah mehah requested a review from kokekanon December 17, 2024 18:43
Copy link
Collaborator

@kokekanon kokekanon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works so far,

only tested on windows.

no test in web client

@mehah mehah merged commit 06aa908 into mehah:main Dec 17, 2024
12 checks passed
vasconcellosdevictor pushed a commit to vasconcellosdevictor/otclient that referenced this pull request Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants