Skip to content

Commit

Permalink
wiring up more ui to live db values
Browse files Browse the repository at this point in the history
  • Loading branch information
efroemling committed Nov 27, 2024
1 parent a78dc70 commit 744f4d1
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 49 deletions.
72 changes: 36 additions & 36 deletions .efrocachemap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### 1.7.37 (build 22114, api 9, 2024-11-26)
### 1.7.37 (build 22115, api 9, 2024-11-27)
- Bumping api version to 9. As you'll see below, there's some UI changes that
will require a bit of work for any UI mods to adapt to. If your mods don't
touch UI stuff at all you can simply bump your api version and call it a day.
Expand Down
9 changes: 7 additions & 2 deletions src/assets/ba_data/python/baclassic/_appmode.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ def update_for_primary_account(
tickets_text='-',
tokens_text='-',
league_rank_text='-',
achievements_percent_text='-',
level_text='-',
xp_text='-',
)

else:
Expand All @@ -199,14 +202,16 @@ def _on_sub_test_update(self, val: int | None) -> None:
def _on_classic_account_data_change(
self, val: bacommon.cloud.ClassicAccountLiveData
) -> None:
# pass
# print(f'GOT CLASSIC ACCOUNT DATA: {val}')
achp = round(val.achievements / max(val.achievements_total, 1) * 100.0)
_baclassic.set_root_ui_values(
tickets_text=str(val.tickets),
tokens_text=str(val.tokens),
league_rank_text=(
'-' if val.league_rank is None else f'#{val.league_rank}'
),
achievements_percent_text=f'{achp}%',
level_text=str(val.level),
xp_text=f'{val.xp}/{val.xpmax}',
)

def _root_ui_menu_press(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/assets/ba_data/python/baenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

# Build number and version of the ballistica binary we expect to be
# using.
TARGET_BALLISTICA_BUILD = 22114
TARGET_BALLISTICA_BUILD = 22115
TARGET_BALLISTICA_VERSION = '1.7.37'


Expand Down
26 changes: 21 additions & 5 deletions src/ballistica/classic/python/methods/python_methods_classic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,21 @@ static auto PySetRootUIValues(PyObject* self, PyObject* args, PyObject* keywds)
const char* tickets_text;
const char* tokens_text;
const char* league_rank_text;
static const char* kwlist[] = {"tickets_text", "tokens_text",
"league_rank_text", nullptr};
if (!PyArg_ParseTupleAndKeywords(args, keywds, "sss",
const_cast<char**>(kwlist), &tickets_text,
&tokens_text, &league_rank_text)) {
const char* achievements_percent_text;
const char* level_text;
const char* xp_text;

static const char* kwlist[] = {"tickets_text",
"tokens_text",
"league_rank_text",
"achievements_percent_text",
"level_text",
"xp_text",
nullptr};
if (!PyArg_ParseTupleAndKeywords(
args, keywds, "ssssss", const_cast<char**>(kwlist), &tickets_text,
&tokens_text, &league_rank_text, &achievements_percent_text,
&level_text, &xp_text)) {
return nullptr;
}
BA_PRECONDITION(g_base->InLogicThread());
Expand All @@ -313,6 +323,9 @@ static auto PySetRootUIValues(PyObject* self, PyObject* args, PyObject* keywds)
appmode->SetRootUITicketsMeterText(tickets_text);
appmode->SetRootUITokensMeterText(tokens_text);
appmode->SetRootUILeagueRankText(league_rank_text);
appmode->SetRootUIAchievementsPercentText(achievements_percent_text);
appmode->SetRootUILevelText(level_text);
appmode->SetRootUIXPText(xp_text);

Py_RETURN_NONE;
BA_PYTHON_CATCH;
Expand All @@ -326,6 +339,9 @@ static PyMethodDef PySetRootUIValuesDef = {
"set_root_ui_values(tickets_text: str,\n"
" tokens_text: str,\n"
" league_rank_text: str,\n"
" achievements_percent_text: str,\n"
" level_text: str,\n"
" xp_text: str,\n"
") -> None\n"
"\n"
"(internal)",
Expand Down
53 changes: 53 additions & 0 deletions src/ballistica/classic/support/classic_app_mode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ void ClassicAppMode::Reset_() {
root_widget->SetTicketsMeterText(root_ui_tickets_meter_text_);
root_widget->SetTokensMeterText(root_ui_tokens_meter_text_);
root_widget->SetLeagueRankText(root_ui_league_rank_text_);
root_widget->SetAchievementPercentText(root_ui_achievement_percent_text_);
root_widget->SetLevelText(root_ui_level_text_);
root_widget->SetXPText(root_ui_xp_text_);
}
}

Expand Down Expand Up @@ -1587,4 +1590,54 @@ void ClassicAppMode::SetRootUILeagueRankText(const std::string text) {
}
}

void ClassicAppMode::SetRootUIAchievementsPercentText(const std::string text) {
BA_PRECONDITION(g_base->InLogicThread());
if (text == root_ui_achievement_percent_text_) {
return;
}
// Store the value.
root_ui_achievement_percent_text_ = text;

// Apply it to any existing UI.
if (uiv1_) {
if (auto* root_widget = uiv1_->root_widget()) {
root_widget->SetAchievementPercentText(root_ui_achievement_percent_text_);
}
}
}

void ClassicAppMode::SetRootUILevelText(const std::string text) {
BA_PRECONDITION(g_base->InLogicThread());
if (text == root_ui_level_text_) {
return;
}

// Store the value.
root_ui_level_text_ = text;

// Apply it to any existing UI.
if (uiv1_) {
if (auto* root_widget = uiv1_->root_widget()) {
root_widget->SetLevelText(root_ui_level_text_);
}
}
}

void ClassicAppMode::SetRootUIXPText(const std::string text) {
BA_PRECONDITION(g_base->InLogicThread());
if (text == root_ui_xp_text_) {
return;
}

// Store the value.
root_ui_xp_text_ = text;

// Apply it to any existing UI.
if (uiv1_) {
if (auto* root_widget = uiv1_->root_widget()) {
root_widget->SetXPText(root_ui_xp_text_);
}
}
}

} // namespace ballistica::classic
6 changes: 6 additions & 0 deletions src/ballistica/classic/support/classic_app_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ class ClassicAppMode : public base::AppMode {
void SetRootUITicketsMeterText(const std::string text);
void SetRootUITokensMeterText(const std::string text);
void SetRootUILeagueRankText(const std::string text);
void SetRootUIAchievementsPercentText(const std::string text);
void SetRootUILevelText(const std::string text);
void SetRootUIXPText(const std::string text);

private:
ClassicAppMode();
Expand Down Expand Up @@ -292,6 +295,9 @@ class ClassicAppMode : public base::AppMode {
std::string root_ui_tickets_meter_text_;
std::string root_ui_tokens_meter_text_;
std::string root_ui_league_rank_text_;
std::string root_ui_achievement_percent_text_;
std::string root_ui_level_text_;
std::string root_ui_xp_text_;
std::list<std::pair<millisecs_t, scene_v1::PlayerSpec> > banned_players_;
std::optional<float> idle_exit_minutes_{};
std::optional<uint32_t> internal_music_play_id_{};
Expand Down
2 changes: 1 addition & 1 deletion src/ballistica/shared/ballistica.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ auto main(int argc, char** argv) -> int {
namespace ballistica {

// These are set automatically via script; don't modify them here.
const int kEngineBuildNumber = 22114;
const int kEngineBuildNumber = 22115;
const char* kEngineVersion = "1.7.37";
const int kEngineApiVersion = 9;

Expand Down
24 changes: 21 additions & 3 deletions src/ballistica/ui_v1/widget/root_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ void RootWidget::AddMeter_(MeterType type, float h_align, float r, float g,
case MeterType::kTrophy:
league_rank_text_ = text;
break;
case MeterType::kLevel:
xp_text_ = text;
break;
default:
break;
}
Expand Down Expand Up @@ -330,7 +333,7 @@ void RootWidget::AddMeter_(MeterType type, float h_align, float r, float g,
td.color_r = 1.0f;
td.color_g = 1.0f;
td.color_b = 1.0f;
AddText_(td);
level_text_ = AddText_(td);
}
}
}
Expand Down Expand Up @@ -513,7 +516,7 @@ void RootWidget::Setup() {
account_name_text_ = AddText_(td);
}
}
AddMeter_(MeterType::kLevel, 0.0f, 1.0f, 1.0f, 1.0f, false, "456/1000");
AddMeter_(MeterType::kLevel, 0.0f, 1.0f, 1.0f, 1.0f, false, "");
AddMeter_(MeterType::kTrophy, 0.0f, 1.0f, 1.0f, 1.0f, false, "");

// Menu button (only shows up when we're not in a menu)
Expand Down Expand Up @@ -655,7 +658,7 @@ void RootWidget::Setup() {
td.color_r = 0.8f;
td.color_g = 0.75f;
td.color_b = 0.9f;
AddText_(td);
achievement_percent_text_ = AddText_(td);
}
}

Expand Down Expand Up @@ -1322,4 +1325,19 @@ void RootWidget::SetLeagueRankText(const std::string& val) {
league_rank_text_->widget->SetText(val);
}

void RootWidget::SetAchievementPercentText(const std::string& val) {
assert(achievement_percent_text_);
achievement_percent_text_->widget->SetText(val);
}

void RootWidget::SetLevelText(const std::string& val) {
assert(level_text_);
level_text_->widget->SetText(val);
}

void RootWidget::SetXPText(const std::string& val) {
assert(xp_text_);
xp_text_->widget->SetText(val);
}

} // namespace ballistica::ui_v1
6 changes: 6 additions & 0 deletions src/ballistica/ui_v1/widget/root_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class RootWidget : public ContainerWidget {
void SetTicketsMeterText(const std::string& val);
void SetTokensMeterText(const std::string& val);
void SetLeagueRankText(const std::string& val);
void SetAchievementPercentText(const std::string& val);
void SetLevelText(const std::string& val);
void SetXPText(const std::string& val);

private:
struct ButtonDef;
Expand Down Expand Up @@ -94,6 +97,9 @@ class RootWidget : public ContainerWidget {
Text* tickets_meter_text_{};
Text* tokens_meter_text_{};
Text* league_rank_text_{};
Text* achievement_percent_text_{};
Text* level_text_{};
Text* xp_text_{};
};

} // namespace ballistica::ui_v1
Expand Down

0 comments on commit 744f4d1

Please sign in to comment.