Skip to content

feat: adaptive ui loading#451

Merged
mehah merged 12 commits intoopentibiabr:mainfrom
BenDol:feat/adaptive_ui
Mar 3, 2023
Merged

feat: adaptive ui loading#451
mehah merged 12 commits intoopentibiabr:mainfrom
BenDol:feat/adaptive_ui

Conversation

@BenDol
Copy link
Contributor

@BenDol BenDol commented Mar 2, 2023

Adaptive UI Loading

The goal of this feature is to provide an efficient way to load the UI on the device running the client.

How does it work?

I've introduced a new data structure for defining the users device:

struct Device : type->DeviceType, os->OperatingSystem

Using this I will dynamically load data resources from their respective directory, this is handled in two ways:

  1. data resources like styles/fonts/particles can now be loaded from the device and/or os directories
data/
   |--styles/
      |--<base otui files>       1.   loads base styles
      |--mobile/
          |--<otui files>        2.   loads mobile styles/overrides
          |--android/
             |--<otui files>     2.1. loads android styles/overrides
          |--ios/
             |--<otui files>     2.2. loads ios styles/overrides
      |--console/
          |--<otui files>        3.   loads console styles/overrides
          |--xbox/
             |--<otui files>     3.1. loads xbox styles/overrides
          |--playstation/
             |--<otui files>     3.2. loads playstation styles/overrides

This will load the resource files in the given order and override

base -> device -> os
  1. loading styles via the file name rather than the data directory: this works in a similar way only it will also try to find the defined main widget from which ever otui file contains it, using the same priority flow as above.
modules
  |--game_battle
       |--battle.otui         // loads first
       |--battle.mobile.otui  // loads second, merges and takes priority over above
       |--battle.android.otui // loads last, merges and takes priority over above

I have provided a simple example in this pull request. With this system we can start building different user interfaces for the different devices.

Some other notable changes in this PR:

  • added widget max-size
  • added LogFine for more granular logging requirements
  • added m_level to the Logger to specify what log level you want to use output (level >= m_level -> log(...))
  • added onPropertyChange lua call to UIWidget::setProp

I am only really looking for feedback from maintainers.

Checklist

  • Data resource loading by device/os
  • File specific style loading by device/os
  • Module specific loading by device/os

Copy link
Member

@dudantas dudantas left a comment

Choose a reason for hiding this comment

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

The contribution is very good, congratulations, I just have a few small suggestions to make.
In some places the end line is missing, I also saw an exception that is handled but has no behaviour inside it, it would be interesting to put it in my view, as it facilitates debugging.

@BenDol BenDol requested review from mehah and tuliomagalhaes March 2, 2023 12:17
Copy link
Contributor

@tuliomagalhaes tuliomagalhaes left a comment

Choose a reason for hiding this comment

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

Amazing work! Thanks for doing this! 🚀

@conde2
Copy link
Contributor

conde2 commented Mar 2, 2023

Amazing pull request! I would suggest editting INT_MAX to a more c++ approach using std::numeric_limits::max

@beats-dh
Copy link
Contributor

beats-dh commented Mar 2, 2023

LGTM 🚀

@BenDol
Copy link
Contributor Author

BenDol commented Mar 3, 2023

Added supported devices to modules, now we can load modules specific to different devices.

Module
  name: game_cooldown
  description: Spellcooldowns
  author: OTClient team
  website: https://github.com/edubart/otclient
  sandboxed: true
  scripts: [ cooldown ]
  devices: [ desktop, console:xbox ]
  @onLoad: init()
  @onUnload: terminate()

In this example this module will only load on any desktop and xbox devices, if none are provided it loads on any device as usual.

@BenDol
Copy link
Contributor Author

BenDol commented Mar 3, 2023

@mehah This is completed now. Revisions might come later, but I think its in a good state to merge if you're happy with it.

@mehah mehah merged commit 09aa446 into opentibiabr:main Mar 3, 2023
@gaamelu
Copy link

gaamelu commented Mar 3, 2023

Amazing!!! Thanks for contributing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants