game: new button to the scripts screen from the runestone message screen

This commit is contained in:
Crypto City 2021-05-15 18:01:22 +00:00
parent be3cb8dba4
commit d5254c43d8
5 changed files with 32 additions and 4 deletions

View File

@ -17,7 +17,7 @@ TBLayout: axis: y, distribution-position: "left top", distribution: "gravity"
TBToggleContainer: id: "message-container", toggle: "expanded", value: 1, gravity: "all"
TBEditField: id: "message", gravity: "all", multiline: 1, readonly: 1, skin: "runestone-message", is-focusable: 0
TBToggleContainer: id: "script-or-start-container", toggle: "expanded", gravity: "left right"
TBToggleContainer: id: "script-or-start-or-goto-container", toggle: "expanded", gravity: "left right"
TBLayout: axis: y
TBToggleContainer: id: "script-container", toggle: "expanded"
TBLayout: axis: y
@ -25,3 +25,10 @@ TBLayout: axis: y, distribution-position: "left top", distribution: "gravity"
TBToggleContainer: id: "start-container", toggle: "expanded"
TBLayout: axis: y
TBTextField: id: "start", gravity: "all", text: "Starting script, waiting for new block..."
TBToggleContainer: id: "goto-container", toggle: "expanded"
TBLayout: axis: y
TBSeparator: gravity: "all"
TBLayout: axis: x, gravity: "all"
TBTextField: text: "A script is running"
TBButton: id: "goto-script", text: "Go to script"
TBSeparator: gravity: "all"

View File

@ -43,11 +43,13 @@ UIRunestoneMessageDialog::UIRunestoneMessageDialog(Urho3D::Context *ctx, const G
messageWidget->SetText(runestone.message.c_str());
messageContainer->SetValue(!uiContainer->GetValue());
tb::TBToggleContainer *sc = GetWidgetByIDAndType<TBToggleContainer>(TBIDC("script-or-start-container"));
tb::TBToggleContainer *sc = GetWidgetByIDAndType<TBToggleContainer>(TBIDC("script-or-start-or-goto-container"));
sc->SetValue(runestone.script != 0);
GetWidgetByIDAndType<TBToggleContainer>(TBIDC("script-container"))->SetValue(1);
const bool has_script = game->playerState.script != 0 && game->playerState.script == runestone.script;
GetWidgetByIDAndType<TBToggleContainer>(TBIDC("script-container"))->SetValue(has_script ? 0 : 1);
GetWidgetByIDAndType<TBToggleContainer>(TBIDC("start-container"))->SetValue(0);
GetWidgetByIDAndType<TBToggleContainer>(TBIDC("goto-container"))->SetValue(has_script ? 1 : 0);
SubscribeToEvent(this, E_TB_WIDGET_EVENT, URHO3D_HANDLER(UIRunestoneMessageDialog, HandleTBMessage));
SubscribeToEvent(this, E_TB_WINDOW_CLOSED, URHO3D_HANDLER(UIRunestoneMessageDialog, HandleClose));
@ -179,6 +181,7 @@ void UIRunestoneMessageDialog::HandlePlay(StringHash eventType, VariantMap& even
GetWidgetByIDAndType<TBToggleContainer>(TBIDC("script-container"))->SetValue(0);
GetWidgetByIDAndType<TBToggleContainer>(TBIDC("start-container"))->SetValue(1);
GetWidgetByIDAndType<TBToggleContainer>(TBIDC("goto-container"))->SetValue(0);
}
void UIRunestoneMessageDialog::HandleViewSource(StringHash eventType, VariantMap& eventData)
@ -187,6 +190,12 @@ void UIRunestoneMessageDialog::HandleViewSource(StringHash eventType, VariantMap
d->SetSource(script_source.c_str());
}
void UIRunestoneMessageDialog::HandleGoToScript(StringHash eventType, VariantMap& eventData)
{
VariantMap newEventData;
SendEvent(E_RUNESTONE_MESSAGE_GO_TO_SCRIPT, newEventData);
}
void UIRunestoneMessageDialog::HandleTBMessage(StringHash eventType, VariantMap& eventData)
{
#define CONNECT(name, function) do { if (ev->target->GetID() == TBIDC(name)) function(eventType, eventData); } while(0)
@ -200,6 +209,7 @@ void UIRunestoneMessageDialog::HandleTBMessage(StringHash eventType, VariantMap&
{
CONNECT("play", HandlePlay);
CONNECT("view-source", HandleViewSource);
CONNECT("goto-script", HandleGoToScript);
CONNECT("close", HandleClose);
}

View File

@ -25,6 +25,7 @@ class Flag;
URHO3D_EVENT(E_RUNESTONE_MESSAGE_CLOSED, RunestoneMessageClosed) { }
URHO3D_EVENT(E_RUNESTONE_MESSAGE_PLAY_SCRIPT, RunestoneMessagePlayScript) { URHO3D_PARAM(P_SCRIPT, Script); URHO3D_PARAM(P_CITY, City); URHO3D_PARAM(P_FLAG, Flag); URHO3D_PARAM(P_X, X); URHO3D_PARAM(P_Y, Y); URHO3D_PARAM(P_H, H); URHO3D_PARAM(P_SCRIPT_NAME, ScriptName); }
URHO3D_EVENT(E_RUNESTONE_MESSAGE_GO_TO_SCRIPT, RunestoneMessageGoToScript) { }
class UIRunestoneMessageDialog: public UITBWindow
{
@ -38,6 +39,7 @@ public:
private:
void HandlePlay(Urho3D::StringHash eventType, Urho3D::VariantMap& eventData);
void HandleViewSource(Urho3D::StringHash eventType, Urho3D::VariantMap& eventData);
void HandleGoToScript(Urho3D::StringHash eventType, Urho3D::VariantMap& eventData);
void HandleTBMessage(Urho3D::StringHash eventType, Urho3D::VariantMap& eventData);
void HandleClose(Urho3D::StringHash eventType, Urho3D::VariantMap& eventData);

View File

@ -2016,6 +2016,9 @@ void UIUrho3D::OnTriggerRunestone(const std::shared_ptr<Flag> &flag, const cc::r
SubscribeToEvent(runestoneMessageDialog, E_RUNESTONE_MESSAGE_PLAY_SCRIPT, [this](StringHash eventType, VariantMap& eventData) {
SendEvent(E_CRYPTOCITY_PLAY_SCRIPT, eventData);
});
SubscribeToEvent(runestoneMessageDialog, E_RUNESTONE_MESSAGE_GO_TO_SCRIPT, [this](StringHash eventType, VariantMap& eventData) {
OpenScriptsScreen();
});
SendTutorialTrigger("screen-trigger-runestone");
}
@ -2157,7 +2160,7 @@ void UIUrho3D::HandleNewBuildingScript(StringHash eventType, VariantMap& eventDa
NewScriptMain(false);
}
void UIUrho3D::HandleScripts(StringHash eventType, VariantMap& eventData)
void UIUrho3D::OpenScriptsScreen()
{
if (scriptsDialog)
{
@ -2180,6 +2183,11 @@ void UIUrho3D::HandleScripts(StringHash eventType, VariantMap& eventData)
SendTutorialTrigger("screen-scripts");
}
void UIUrho3D::HandleScripts(StringHash eventType, VariantMap& eventData)
{
OpenScriptsScreen();
}
void UIUrho3D::HandleSetGlobalVariable(StringHash eventType, VariantMap& eventData)
{
if (setGlobalVariableDialog)

View File

@ -396,6 +396,7 @@ private:
void SendTutorialTrigger(const char *tag);
void NewScriptMain(bool game);
void OpenScriptsScreen();
private:
const GameState *gameState;