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

Lua UI API Extensions #5933

Merged
merged 20 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
42f0b95
Implement most common widget types for plugins
Noordfrees Jun 3, 2023
fcb5674
Add LuaPanel::get_child
Noordfrees Jun 3, 2023
798510f
Add Lua interface for Editboxes
Noordfrees Jun 4, 2023
d47892e
Add Lua interface for static textareas
Noordfrees Jun 4, 2023
b99733b
Add Lua interface for checkbox and radio groups
Noordfrees Jun 4, 2023
07d526c
Add Lua interface for spinbox
Noordfrees Jun 4, 2023
a9554f1
Add Lua interface for slider
Noordfrees Jun 4, 2023
251dade
Misc fixes
Noordfrees Jun 4, 2023
bce994e
'src/scripting/lua_ui.cc' was automatically formatted.
Noordfrees Jun 4, 2023
b66c3ec
Rename a variable
Noordfrees Jun 4, 2023
6660695
Merge branch 'master' into uiplugings-more-widgets
Noordfrees Jun 7, 2023
4acbfc6
Merge branch 'master' into uiplugings-more-widgets
Noordfrees Jun 17, 2023
3178a0a
Merge branch 'master' of github.com:widelands/widelands into uiplugin…
Noordfrees Jun 25, 2023
7fab75c
Implemente Lua interface for ProgressBar
Noordfrees Jun 25, 2023
d13be68
Merge branch 'master' into uiplugings-more-widgets
Noordfrees Jul 6, 2023
e678d9f
Merge branch 'master' into uiplugings-more-widgets
Noordfrees Jul 6, 2023
1fee39a
Merge branch 'master' into uiplugings-more-widgets
Noordfrees Jul 11, 2023
f33b234
Merge branch 'master' of github.com:widelands/widelands into uiplugin…
Noordfrees Jul 15, 2023
768d436
'src/scripting/lua_ui.cc' was automatically formatted.
Noordfrees Jul 15, 2023
ccc6733
Merge branch 'master' into uiplugings-more-widgets
hessenfarmer Jul 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1,482 changes: 1,324 additions & 158 deletions src/scripting/lua_ui.cc

Large diffs are not rendered by default.

274 changes: 270 additions & 4 deletions src/scripting/lua_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@
#include "scripting/lua.h"
#include "scripting/luna.h"
#include "ui_basic/button.h"
#include "ui_basic/checkbox.h"
#include "ui_basic/dropdown.h"
#include "ui_basic/multilinetextarea.h"
#include "ui_basic/progressbar.h"
#include "ui_basic/radiobutton.h"
#include "ui_basic/slider.h"
#include "ui_basic/spinbox.h"
#include "ui_basic/tabpanel.h"
#include "ui_basic/textarea.h"
#include "ui_basic/textinput.h"
#include "ui_basic/window.h"
#include "wui/interactive_base.h"

Expand Down Expand Up @@ -67,6 +75,8 @@ class LuaPanel : public LuaUiModuleClass {
/*
* Properties
*/
int get_name(lua_State* L);
int get_children(lua_State* L);
int get_buttons(lua_State* L);
int get_dropdowns(lua_State* L);
int get_tabs(lua_State* L);
Expand All @@ -79,6 +89,8 @@ class LuaPanel : public LuaUiModuleClass {
int set_position_x(lua_State* L);
int get_position_y(lua_State* L);
int set_position_y(lua_State* L);
int get_visible(lua_State* L);
int set_visible(lua_State* L);

/*
* Lua Methods
Expand All @@ -88,6 +100,7 @@ class LuaPanel : public LuaUiModuleClass {
int indicate(lua_State* L);
#endif
int create_child(lua_State* L);
int get_child(lua_State* L);

/*
* C Methods
Expand All @@ -109,7 +122,6 @@ class LuaButton : public LuaPanel {
/*
* Properties
*/
int get_name(lua_State* L);

/*
* Lua Methods
Expand All @@ -125,6 +137,261 @@ class LuaButton : public LuaPanel {
}
};

class LuaMultilineTextarea : public LuaPanel {
public:
LUNA_CLASS_HEAD(LuaMultilineTextarea);

LuaMultilineTextarea() = default;
explicit LuaMultilineTextarea(UI::Panel* p) : LuaPanel(p) {
}
explicit LuaMultilineTextarea(lua_State* L) : LuaPanel(L) {
}
~LuaMultilineTextarea() override = default;

/*
* Properties
*/
int get_text(lua_State* L);
int set_text(lua_State* L);

/*
* Lua Methods
*/

/*
* C Methods
*/
UI::MultilineTextarea* get() {
return dynamic_cast<UI::MultilineTextarea*>(panel_);
}
};

class LuaTextarea : public LuaPanel {
public:
LUNA_CLASS_HEAD(LuaTextarea);

LuaTextarea() = default;
explicit LuaTextarea(UI::Panel* p) : LuaPanel(p) {
}
explicit LuaTextarea(lua_State* L) : LuaPanel(L) {
}
~LuaTextarea() override = default;

/*
* Properties
*/
int get_text(lua_State* L);
int set_text(lua_State* L);

/*
* Lua Methods
*/

/*
* C Methods
*/
UI::Textarea* get() {
return dynamic_cast<UI::Textarea*>(panel_);
}
};

class LuaCheckbox : public LuaPanel {
public:
LUNA_CLASS_HEAD(LuaCheckbox);

LuaCheckbox() = default;
explicit LuaCheckbox(UI::Panel* p) : LuaPanel(p) {
}
explicit LuaCheckbox(lua_State* L) : LuaPanel(L) {
}
~LuaCheckbox() override = default;

/*
* Properties
*/
int get_state(lua_State* L);
int set_state(lua_State* L);

/*
* Lua Methods
*/
int set_enabled(lua_State* L);

/*
* C Methods
*/
UI::Checkbox* get() {
return dynamic_cast<UI::Checkbox*>(panel_);
}
};

class LuaRadioButton : public LuaPanel {
public:
LUNA_CLASS_HEAD(LuaRadioButton);

LuaRadioButton() = default;
explicit LuaRadioButton(UI::Panel* p) : LuaPanel(p) {
}
explicit LuaRadioButton(lua_State* L) : LuaPanel(L) {
}
~LuaRadioButton() override = default;

/*
* Properties
*/
int get_state(lua_State* L);
int set_state(lua_State* L);

/*
* Lua Methods
*/
int set_enabled(lua_State* L);

/*
* C Methods
*/
UI::Radiobutton* get() {
return dynamic_cast<UI::Radiobutton*>(panel_);
}
};

class LuaProgressBar : public LuaPanel {
public:
LUNA_CLASS_HEAD(LuaProgressBar);

LuaProgressBar() = default;
explicit LuaProgressBar(UI::Panel* p) : LuaPanel(p) {
}
explicit LuaProgressBar(lua_State* L) : LuaPanel(L) {
}
~LuaProgressBar() override = default;

/*
* Properties
*/
int get_state(lua_State* L);
int set_state(lua_State* L);
int get_total(lua_State* L);
int set_total(lua_State* L);
int get_show_percent(lua_State* L);
int set_show_percent(lua_State* L);

/*
* Lua Methods
*/

/*
* C Methods
*/
UI::ProgressBar* get() {
return dynamic_cast<UI::ProgressBar*>(panel_);
}
};

class LuaSpinBox : public LuaPanel {
public:
LUNA_CLASS_HEAD(LuaSpinBox);

LuaSpinBox() = default;
explicit LuaSpinBox(UI::Panel* p) : LuaPanel(p) {
}
explicit LuaSpinBox(lua_State* L) : LuaPanel(L) {
}
~LuaSpinBox() override = default;

/*
* Properties
*/
int get_value(lua_State* L);
int set_value(lua_State* L);

/*
* Lua Methods
*/
int set_unit_width(lua_State* L);
int set_interval(lua_State* L);
int add_replacement(lua_State* L);

/*
* C Methods
*/
UI::SpinBox* get() {
return dynamic_cast<UI::SpinBox*>(panel_);
}
};

class LuaSlider : public LuaPanel {
public:
LUNA_CLASS_HEAD(LuaSlider);

LuaSlider() = default;
explicit LuaSlider(UI::Panel* p) : LuaPanel(p) {
}
explicit LuaSlider(lua_State* L) : LuaPanel(L) {
}
~LuaSlider() override = default;

/*
* Properties
*/
int get_value(lua_State* L);
int set_value(lua_State* L);
int get_min_value(lua_State* L);
int set_min_value(lua_State* L);
int get_max_value(lua_State* L);
int set_max_value(lua_State* L);

/*
* Lua Methods
*/
int set_enabled(lua_State* L);
int set_cursor_fixed_height(lua_State* L);

/*
* C Methods
*/
UI::Slider* get() {
return dynamic_cast<UI::Slider*>(panel_);
}
};

class LuaTextInputPanel : public LuaPanel {
public:
LUNA_CLASS_HEAD(LuaTextInputPanel);

LuaTextInputPanel() = default;
explicit LuaTextInputPanel(UI::Panel* p) : LuaPanel(p) {
}
explicit LuaTextInputPanel(lua_State* L) : LuaPanel(L) {
}
~LuaTextInputPanel() override = default;

/*
* Properties
*/
int get_text(lua_State* L);
int set_text(lua_State* L);
int get_selected_text(lua_State* L);
int get_password(lua_State* L);
int set_password(lua_State* L);
int get_warning(lua_State* L);
int set_warning(lua_State* L);
int get_caret_pos(lua_State* L);
int set_caret_pos(lua_State* L);
int get_multiline(lua_State* L);

/*
* Lua Methods
*/

/*
* C Methods
*/
UI::AbstractTextInputPanel* get() {
return dynamic_cast<UI::AbstractTextInputPanel*>(panel_);
}
};

class LuaDropdown : public LuaPanel {
public:
LUNA_CLASS_HEAD(LuaDropdown);
Expand All @@ -139,7 +406,6 @@ class LuaDropdown : public LuaPanel {
/*
* Properties
*/
int get_name(lua_State* L);
int get_expanded(lua_State* L);
int get_no_of_items(lua_State* L);

Expand Down Expand Up @@ -173,7 +439,6 @@ class LuaTab : public LuaPanel {
/*
* Properties
*/
int get_name(lua_State* L);
int get_active(lua_State* L);

/*
Expand Down Expand Up @@ -203,7 +468,6 @@ class LuaWindow : public LuaPanel {
/*
* Properties
*/
int get_name(lua_State* L);

/*
* Lua Methods
Expand Down Expand Up @@ -272,6 +536,8 @@ class LuaMapView : public LuaPanel {
}
};

int upcasted_panel_to_lua(lua_State* L, UI::Panel* panel);

void luaopen_wlui(lua_State*);
} // namespace LuaUi

Expand Down
14 changes: 14 additions & 0 deletions src/ui_basic/panel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,20 @@ void Panel::set_tooltip(const std::string& text) {
}
}

Panel* Panel::find_child_by_name(const std::string& name, bool recurse) {
for (Panel* child = first_child_; child != nullptr; child = child->next_) {
if (child->get_name() == name) {
return child;
}
if (recurse) {
if (Panel* np = child->find_child_by_name(name, true); np != nullptr) {
return np;
}
}
}
return nullptr;
}

void Panel::find_all_children_at(const int16_t x,
const int16_t y,
std::vector<Panel*>& result) const {
Expand Down
1 change: 1 addition & 0 deletions src/ui_basic/panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ class Panel {
[[nodiscard]] Panel* get_last_child() {
return last_child_;
}
Panel* find_child_by_name(const std::string& name, bool recurse);

void move_to_top(bool on_top_of_equal_z = true);
[[nodiscard]] virtual ZOrder get_z() const {
Expand Down
7 changes: 5 additions & 2 deletions src/ui_basic/progressbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,21 @@ struct ProgressBar : public Panel {
int32_t h,
uint32_t orientation);

uint32_t get_state() const {
[[nodiscard]] uint32_t get_state() const {
return state_;
}
void set_state(uint32_t);
uint32_t get_total() const {
[[nodiscard]] uint32_t get_total() const {
return total_;
}
void set_total(uint32_t);

void set_show_percent(bool p) {
show_percent_ = p;
}
[[nodiscard]] bool get_show_percent() const {
return show_percent_;
}

protected:
void draw(RenderTarget&) override;
Expand Down