[gd_scene load_steps=11 format=2] [ext_resource path="user://maps/Archipelago/settings_buttons.gd" type="Script" id=4] [ext_resource path="user://maps/Archipelago/settings_screen.gd" type="Script" id=5] [ext_resource path="res://images/unchecked.png" type="Texture" id=7] [ext_resource path="res://images/checked.png" type="Texture" id=8] [ext_resource type="Theme" uid="uid://7w454egydi41" path="res://assets/themes/baseUI.tres" id="2_g4bvn"] [sub_resource type="StyleBoxFlat" id=1] bg_color = Color( 0, 0, 0, 0 ) [sub_resource type="StyleBoxFlat" id=2] bg_color = Color( 1, 1, 1, 1 ) border_width_left = 1 border_width_top = 1 border_width_right = 1 border_width_bottom = 1 border_color = Color( 1, 1, 0, 1 ) border_blend = true corner_radius_top_left = 3 corner_radius_top_right = 3 corner_radius_bottom_right = 3 corner_radius_bottom_left = 3 expand_offset_left = 5.0 expand_offset_right = 5.0 expand_offset_top = 5.0 expand_offset_bottom = 5.0 [node name="settings_screen" type="Node2D"] script = ExtResource( 5 ) [node name="Panel" type="Panel" parent="."] offset_right = 1920.0 offset_bottom = 1080.0 [node name="title" parent="Panel" type="Label"] offset_left = 0.0 offset_top = 75.0 offset_right = 1920.0 offset_bottom = 225.0 text = "ARCHIPELAGO" valign = 1 theme = ExtResource("2_g4bvn") [node name="credit" parent="Panel" type="Label"] visible = false offset_left = 1278.0 offset_top = 974.0 offset_right = 1868.0 offset_bottom = 1034.0 text = "Brenton Wildes" theme = ExtResource("2_g4bvn") [node name="connect_button" parent="Panel" type="Button"] offset_left = 255.0 offset_top = 875.0 offset_right = 891.0 offset_bottom = 1025.0 custom_colors/font_color_hover = Color( 1, 0.501961, 0, 1 ) text = "CONNECT" theme = ExtResource("2_g4bvn") script = ExtResource( 4 ) [node name="quit_button" parent="Panel" type="Button"] offset_left = 1102.0 offset_top = 875.0 offset_right = 1738.0 offset_bottom = 1025.0 custom_colors/font_color_hover = Color( 1, 0, 0, 1 ) text = "BACK" theme = ExtResource("2_g4bvn") script = ExtResource( 4 ) [node name="credit2" parent="Panel" type="Label"] offset_left = -105.0 offset_top = 346.0 offset_right = 485.0 offset_bottom = 410.0 custom_styles/normal = SubResource( 1 ) text = "SERVER" align = 2 theme = ExtResource("2_g4bvn") [node name="credit5" parent="Panel" type="Label"] offset_left = 1239.0 offset_top = 422.0 offset_right = 1829.0 offset_bottom = 486.0 custom_styles/normal = SubResource( 1 ) text = "OPTIONS" theme = ExtResource("2_g4bvn") [node name="credit3" parent="Panel" type="Label"] offset_left = -105.0 offset_top = 519.0 offset_right = 485.0 offset_bottom = 583.0 custom_styles/normal = SubResource( 1 ) text = "PLAYER" align = 2 theme = ExtResource("2_g4bvn") [node name="credit4" parent="Panel" type="Label"] offset_left = -105.0 offset_top = 704.0 offset_right = 485.0 offset_bottom = 768.0 custom_styles/normal = SubResource( 1 ) text = "PASSWORD" align = 2 theme = ExtResource("2_g4bvn") [node name="server_box" type="LineEdit" parent="Panel"] offset_left = 502.0 offset_top = 295.0 offset_right = 1144.0 offset_bottom = 445.0 custom_colors/selection_color = Color( 0.482353, 0, 0, 1 ) custom_colors/cursor_color = Color( 0, 0, 0, 1 ) custom_colors/font_color = Color( 0, 0, 0, 1 ) custom_styles/focus = SubResource( 2 ) align = 1 caret_blink = true [node name="player_box" type="LineEdit" parent="Panel"] offset_left = 502.0 offset_top = 477.0 offset_right = 1144.0 offset_bottom = 627.0 custom_colors/selection_color = Color( 0.482353, 0, 0, 1 ) custom_colors/cursor_color = Color( 0, 0, 0, 1 ) custom_colors/font_color = Color( 0, 0, 0, 1 ) custom_styles/focus = SubResource( 2 ) align = 1 caret_blink = true [node name="password_box" type="LineEdit" parent="Panel"] offset_left = 502.0 offset_top = 659.0 offset_right = 1144.0 offset_bottom = 809.0 custom_colors/selection_color = Color( 0.482353, 0, 0, 1 ) custom_colors/cursor_color = Color( 0, 0, 0, 1 ) custom_colors/font_color = Color( 0, 0, 0, 1 ) custom_styles/focus = SubResource( 2 ) align = 1 caret_blink = true [node name="AcceptDialog" type="AcceptDialog" parent="Panel"] offset_right = 83.0 offset_bottom = 58.0 [node name="connection_history" type="MenuButton" parent="Panel"] offset_left = 1239.0 offset_top = 276.0 offset_right = 1829.0 offset_bottom = 372.0 text = "connection history" flat = false [connection signal="pressed" from="Panel/connect_button" to="Panel/connect_button" method="_connect_pressed"] [connection signal="pressed" from="Panel/quit_button" to="Panel/quit_button" method="_back_pressed"] 4'>e882367 ^
#include "undo.h"
#include "frame.h"
Undoable::Undoable(std::string title, std::function<void ()> forward, std::function<void ()> backward)
{
this->title = title;
this->forward = forward;
this->backward = backward;
}
std::string Undoable::getTitle() const
{
return title;
}
void Undoable::apply()
{
forward();
}
void Undoable::undo()
{
backward();
}
wxBEGIN_EVENT_TABLE(UndoableTextBox, wxTextCtrl)
EVT_SET_FOCUS(UndoableTextBox::OnFocus)
EVT_KILL_FOCUS(UndoableTextBox::OnKillFocus)
wxEND_EVENT_TABLE()
UndoableTextBox::UndoableTextBox(wxWindow* parent, wxWindowID id, wxString startText, std::string undoType, MapeditFrame* realParent, const wxPoint& pos, const wxSize& size, long style) : wxTextCtrl(parent, id, startText, pos, size, style)
{
this->undoText = undoType;
this->realParent = realParent;
Init();
}
void UndoableTextBox::Init()
{
Bind(wxEVT_TEXT, &UndoableTextBox::OnTextChange, this);
curText = GetValue();
}
void UndoableTextBox::OnFocus(wxFocusEvent& event)
{
curText = GetValue();
event.Skip();
}
void UndoableTextBox::OnKillFocus(wxFocusEvent& event)
{
undo.reset();
event.Skip();
}
void UndoableTextBox::OnTextChange(wxCommandEvent& event)
{
if (!undo)
{
auto tempUndo = std::make_shared<Undo>(undoText, curText, *this);
realParent->commitAfter(tempUndo);
undo = tempUndo;
}
undo->newText = GetValue();
curText = GetValue();
event.Skip();
}
UndoableTextBox::Undo::Undo(std::string title, wxString origText, UndoableTextBox& parent) : origText(origText), parent(parent)
{
this->title = title;
}
void UndoableTextBox::Undo::apply()
{
parent.ChangeValue(newText);
}
void UndoableTextBox::Undo::undo()
{
parent.ChangeValue(origText);
}
void UndoableTextBox::Undo::endChanges()
{
parent.undo.reset();
}
UndoableChoice::UndoableChoice()
{
Init();
}
UndoableChoice::UndoableChoice(wxWindow* parent, wxWindowID id, MapeditFrame* realParent, const wxPoint& pos, const wxSize& size, int n, const wxString choices[], long style, const wxValidator& validator, const wxString& name) : wxChoice(parent, id, pos, size, n, choices, style, validator, name)
{
this->realParent = realParent;
Init();
}
void UndoableChoice::Init()
{
Bind(wxEVT_CHOICE, &UndoableChoice::OnChoose, this);
}
void UndoableChoice::OnChoose(wxCommandEvent& event)
{
int new_selection = GetSelection();
GetValidator()->TransferToWindow();
int old_selection = GetSelection();
realParent->commitAction(std::make_shared<Undoable>(("Set " + GetName()).ToStdString(), [=] () {
SetSelection(new_selection);
GetValidator()->TransferFromWindow();
}, [=] () {
SetSelection(old_selection);
GetValidator()->TransferFromWindow();
}));
event.Skip();
}
wxBEGIN_EVENT_TABLE(UndoableSlider, wxSlider)
EVT_SCROLL(UndoableSlider::OnSlide)
wxEND_EVENT_TABLE()
UndoableSlider::UndoableSlider()
{
Init();
}
UndoableSlider::UndoableSlider(wxWindow* parent, wxWindowID id, MapeditFrame* realParent, int value, int minvalue, int maxvalue, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name) : wxSlider(parent, id, value, minvalue, maxvalue, pos, size, style, validator, name)
{
this->realParent = realParent;
Init();
}
void UndoableSlider::Init()
{
}
void UndoableSlider::OnSlide(wxScrollEvent& event)
{
int new_value = GetValue();
GetValidator()->TransferToWindow();
int old_value = GetValue();
realParent->commitAction(std::make_shared<Undoable>(("Set " + GetName()).ToStdString(), [=] () {
SetValue(new_value);
GetValidator()->TransferFromWindow();
}, [=] () {
SetValue(old_value);
GetValidator()->TransferFromWindow();
}));
event.Skip();
}