forked from townforge/townforge
game: multi page tutorial windows
This commit is contained in:
parent
a6b5210c2f
commit
0ad5f3d9e4
@ -5,8 +5,14 @@ WindowInfo
|
||||
TBLayout: axis: y, distribution: "gravity"
|
||||
TBEditField: id: "text", multiline: 1, adapt-to-content: 1, readonly: 1, gravity: "all", skin: "tutorial-text", virtual-width: 500
|
||||
TBTextField: gravity: "all"
|
||||
TBClickLabel: text: "Enable tutorial", gravity: "bottom"
|
||||
TBCheckBox: id: "enable-tutorial", value: 1
|
||||
TBLayout: axis: x, gravity: "left right", size: "available", distribution: "gravity"
|
||||
TBClickLabel: text: "Enable tutorial", gravity: "left"
|
||||
TBCheckBox: id: "enable-tutorial", value: 1
|
||||
TBTextField: gravity: "left right"
|
||||
TBLayout: axis: x, gravity: "bottom left right", size: "available", distribution: "gravity"
|
||||
TBTextField: gravity: "left right"
|
||||
TBToggleContainer: id: "prev-next-container", toggle: "expanded"
|
||||
TBLayout: axis: x
|
||||
TBButton: id: "prev", text: "<<"
|
||||
TBButton: id: "next", text: ">>"
|
||||
TBButton: id: "done", text: "Done", gravity: "right"
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <Urho3D/Urho3D.h>
|
||||
#include <tb/tb_editfield.h>
|
||||
#include <tb/tb_toggle_container.h>
|
||||
#include "ui-tb-window.h"
|
||||
#include "ui-urho3d.h"
|
||||
#include "tutorial.h"
|
||||
@ -10,29 +11,57 @@ using namespace tb;
|
||||
class TutorialWindow: public UITBWindow
|
||||
{
|
||||
public:
|
||||
TutorialWindow(Urho3D::Context *ctx, const GameState *game = nullptr, const std::vector<const char*> &text = {});
|
||||
TutorialWindow(Urho3D::Context *ctx, const GameState *game = nullptr, const char *text = "");
|
||||
|
||||
void HandleEnableTutorial(StringHash eventType, VariantMap& eventData);
|
||||
void HandleClose(StringHash eventType, VariantMap& eventData);
|
||||
void HandleTBMessage(StringHash eventType, VariantMap& eventData);
|
||||
void SetPage(uint32_t page);
|
||||
|
||||
public:
|
||||
const GameState *game;
|
||||
std::vector<TBStr> pages;
|
||||
uint32_t page;
|
||||
|
||||
tb::TBToggleContainer *prev_next_container;
|
||||
tb::TBButton *prev, *next;
|
||||
};
|
||||
|
||||
TutorialWindow::TutorialWindow(Urho3D::Context *ctx, const GameState *game, const char *text):
|
||||
TutorialWindow::TutorialWindow(Urho3D::Context *ctx, const GameState *game, const std::vector<const char*> &text):
|
||||
UITBWindow(ctx, "cc/tutorial-basic.tb.txt"),
|
||||
game(game)
|
||||
{
|
||||
TBEditField *w = GetWidgetByIDAndType<TBEditField>(TBIDC("text"));
|
||||
if (w)
|
||||
w->SetText(text);
|
||||
for (const char *s: text)
|
||||
pages.push_back(s);
|
||||
|
||||
SetPage(0);
|
||||
|
||||
GetWidgetByIDAndType<TBToggleContainer>(TBIDC("prev-next-container"))->SetValue(pages.size() > 1);
|
||||
|
||||
ResizeToFitContent();
|
||||
|
||||
SubscribeToEvent(this, E_TB_WIDGET_EVENT, URHO3D_HANDLER(TutorialWindow, HandleTBMessage));
|
||||
SubscribeToEvent(this, E_TB_WINDOW_CLOSED, URHO3D_HANDLER(TutorialWindow, HandleClose));
|
||||
}
|
||||
|
||||
TutorialWindow::TutorialWindow(Urho3D::Context *ctx, const GameState *game, const char *text):
|
||||
TutorialWindow(ctx, game, std::vector<const char*>(1, text))
|
||||
{
|
||||
}
|
||||
|
||||
void TutorialWindow::SetPage(unsigned page)
|
||||
{
|
||||
this->page = page;
|
||||
|
||||
TBEditField *w = GetWidgetByIDAndType<TBEditField>(TBIDC("text"));
|
||||
if (w)
|
||||
w->SetText(pages[page]);
|
||||
|
||||
GetWidgetByIDAndType<TBButton>(TBIDC("prev"))->SetState(WIDGET_STATE_DISABLED, page == 0);
|
||||
GetWidgetByIDAndType<TBButton>(TBIDC("next"))->SetState(WIDGET_STATE_DISABLED, page == pages.size() - 1);
|
||||
}
|
||||
|
||||
void TutorialWindow::HandleEnableTutorial(StringHash eventType, VariantMap& eventData)
|
||||
{
|
||||
using namespace TBWidgetEventNamespace;
|
||||
@ -52,6 +81,8 @@ void TutorialWindow::HandleTBMessage(Urho3D::StringHash eventType, Urho3D::Varia
|
||||
TBWidgetEvent *ev = (TBWidgetEvent*)eventData[P_WIDGET_EVENT].GetVoidPtr();
|
||||
if (ev->type == EVENT_TYPE_CLICK)
|
||||
{
|
||||
CONNECT("prev", [this](StringHash eventType, VariantMap& eventData) { SetPage(page ? page - 1 : page); });
|
||||
CONNECT("next", [this](StringHash eventType, VariantMap& eventData) { SetPage(page < pages.size() - 1 ? page + 1 : page); });
|
||||
CONNECT("done", HandleClose);
|
||||
}
|
||||
else if (ev->type == EVENT_TYPE_CHANGED)
|
||||
@ -92,10 +123,12 @@ static UITBWindow * display_player_tutorial(Context *ctx, const GameState *game)
|
||||
|
||||
static UITBWindow * display_node_tutorial(Context *ctx, const GameState *game)
|
||||
{
|
||||
return new TutorialWindow(ctx, game,
|
||||
return new TutorialWindow(ctx, game, {
|
||||
"The node keeps up with other Townforge nodes on the network. You can ask your node to mine, but long term mining is best done "
|
||||
"while the game is not running, since the game also takes substantial CPU time and memory\n"
|
||||
);
|
||||
"while the game is not running, since the game also takes substantial CPU time and memory\n",
|
||||
"Oh, a multipage tutorial!",
|
||||
"Yup, last page"
|
||||
});
|
||||
}
|
||||
|
||||
static UITBWindow * display_calendar_tutorial(Context *ctx, const GameState *game)
|
||||
|
Loading…
Reference in New Issue
Block a user