Wrote patch for more player options as mentioned in #16
Hey, I wrote a patch to implement more player options (e.g. no CPU, or only play against one worm, ...) as mentioned in #16 (closed).
I can't fork the project tho, the button is grayed out.
Am I missing something here? If I can't fork, because my account is to new or I am not a contributer or whatever, here is the patch:
From cdc7ed60f2485800e6d8dfabe97704aa2350ff95 Mon Sep 17 00:00:00 2001
From: zeno <tmp-gnome-gitlab@groundzeno.net>
Date: Thu, 7 Dec 2023 14:11:57 +0100
Subject: [PATCH] implement more amounts of worms
---
data/ui/players.ui | 28 ++++++++++++++++++++++++++++
src/nibbles-window.vala | 7 +++----
src/players.vala | 17 ++++++++++++++++-
3 files changed, 47 insertions(+), 5 deletions(-)
diff --git a/data/ui/players.ui b/data/ui/players.ui
index e0f6c3c..cdd1de5 100644
--- a/data/ui/players.ui
+++ b/data/ui/players.ui
@@ -156,6 +156,34 @@
<property name="halign">center</property>
<property name="spacing">10</property>
<property name="vexpand">1</property>
+ <child>
+ <object class="GtkToggleButton" id="worms2">
+ <property name="visible">1</property>
+ <property name="use-underline">1</property>
+ <property name="label" translatable="1">x</property>
+ <property name="action-name">players.change-nibbles-number</property>
+ <property name="width-request">100</property>
+ <property name="action-target">@i 2</property>
+ <property name="sensitive" bind-source="worms2" bind-property="active" bind-flags="invert-boolean"/>
+ <style>
+ <class name="number-box"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkToggleButton" id="worms3">
+ <property name="visible">1</property>
+ <property name="use-underline">1</property>
+ <property name="label" translatable="1">x</property>
+ <property name="action-name">players.change-nibbles-number</property>
+ <property name="width-request">100</property>
+ <property name="action-target">@i 3</property>
+ <property name="sensitive" bind-source="worms3" bind-property="active" bind-flags="invert-boolean"/>
+ <style>
+ <class name="number-box"/>
+ </style>
+ </object>
+ </child>
<child>
<object class="GtkToggleButton" id="worms4">
<property name="visible">1</property>
diff --git a/src/nibbles-window.vala b/src/nibbles-window.vala
index 8cf0077..4f8ddd8 100644
--- a/src/nibbles-window.vala
+++ b/src/nibbles-window.vala
@@ -361,13 +361,12 @@ private class NibblesWindow : ApplicationWindow
/* Number of worms */
game.numhumans = settings.get_int ("players");
int numai = settings.get_int ("ai");
- if (numai + game.numhumans > NibblesGame.MAX_WORMS
- || numai + game.numhumans < 4)
+ if (numai + game.numhumans > NibblesGame.MAX_WORMS)
{
- numai = 4 - game.numhumans;
- settings.set_int ("ai", numai);
+ assert_not_reached ();
}
game.numai = numai;
+ // NOTE: set numai value to 0 here
players.set_values (game.numhumans, numai);
/* Speed screen */
diff --git a/src/players.vala b/src/players.vala
index d48e01e..7af5f8e 100644
--- a/src/players.vala
+++ b/src/players.vala
@@ -25,6 +25,8 @@ private class Players : Box
[GtkChild] private unowned ToggleButton players2;
[GtkChild] private unowned ToggleButton players3;
[GtkChild] private unowned ToggleButton players4;
+ [GtkChild] private unowned ToggleButton worms2;
+ [GtkChild] private unowned ToggleButton worms3;
[GtkChild] private unowned ToggleButton worms4;
[GtkChild] private unowned ToggleButton worms5;
[GtkChild] private unowned ToggleButton worms6;
@@ -99,21 +101,34 @@ private class Players : Box
switch (players_number_action.get_state ().get_int32 ())
{
case 1:
+ ((Widget)worms2).set_visible (true);
+ ((Widget)worms3).set_visible (true);
+ ((Label)worms2.get_child ()).set_markup (@"<b><span size=\"30.0pt\" font-family=\"Sans\">"+_(ai1_label)+"</span></b>");
+ ((Label)worms3.get_child ()).set_markup (@"<b><span size=\"30.0pt\" font-family=\"Sans\">"+_(ai2_label)+"</span></b>");
((Label)worms4.get_child ()).set_markup (@"<b><span size=\"30.0pt\" font-family=\"Sans\">"+_(ai3_label)+"</span></b>");
((Label)worms5.get_child ()).set_markup (@"<b><span size=\"30.0pt\" font-family=\"Sans\">"+_(ai4_label)+"</span></b>");
((Label)worms6.get_child ()).set_markup (@"<b><span size=\"30.0pt\" font-family=\"Sans\">"+_(ai5_label)+"</span></b>");
break;
case 2:
+ ((Widget)worms2).set_visible (true);
+ ((Widget)worms3).set_visible (true);
+ ((Label)worms2.get_child ()).set_markup (@"<b><span size=\"30.0pt\" font-family=\"Sans\">"+_(ai0_label)+"</span></b>");
+ ((Label)worms3.get_child ()).set_markup (@"<b><span size=\"30.0pt\" font-family=\"Sans\">"+_(ai1_label)+"</span></b>");
((Label)worms4.get_child ()).set_markup (@"<b><span size=\"30.0pt\" font-family=\"Sans\">"+_(ai2_label)+"</span></b>");
((Label)worms5.get_child ()).set_markup (@"<b><span size=\"30.0pt\" font-family=\"Sans\">"+_(ai3_label)+"</span></b>");
((Label)worms6.get_child ()).set_markup (@"<b><span size=\"30.0pt\" font-family=\"Sans\">"+_(ai4_label)+"</span></b>");
break;
case 3:
+ ((Widget)worms2).set_visible (false);
+ ((Widget)worms3).set_visible (true);
+ ((Label)worms3.get_child ()).set_markup (@"<b><span size=\"30.0pt\" font-family=\"Sans\">"+_(ai0_label)+"</span></b>");
((Label)worms4.get_child ()).set_markup (@"<b><span size=\"30.0pt\" font-family=\"Sans\">"+_(ai1_label)+"</span></b>");
((Label)worms5.get_child ()).set_markup (@"<b><span size=\"30.0pt\" font-family=\"Sans\">"+_(ai2_label)+"</span></b>");
((Label)worms6.get_child ()).set_markup (@"<b><span size=\"30.0pt\" font-family=\"Sans\">"+_(ai3_label)+"</span></b>");
break;
case 4:
+ ((Widget)worms2).set_visible (false);
+ ((Widget)worms3).set_visible (false);
((Label)worms4.get_child ()).set_markup (@"<b><span size=\"30.0pt\" font-family=\"Sans\">"+_(ai0_label)+"</span></b>");
((Label)worms5.get_child ()).set_markup (@"<b><span size=\"30.0pt\" font-family=\"Sans\">"+_(ai1_label)+"</span></b>");
((Label)worms6.get_child ()).set_markup (@"<b><span size=\"30.0pt\" font-family=\"Sans\">"+_(ai2_label)+"</span></b>");
@@ -126,7 +141,7 @@ private class Players : Box
private inline void change_nibbles_number (SimpleAction _nibbles_number_action, Variant variant)
{
int nibbles_number = variant.get_int32 ();
- if (nibbles_number < 4 || nibbles_number > 6)
+ if (nibbles_number < 2 || nibbles_number > 6)
assert_not_reached ();
_nibbles_number_action.set_state (nibbles_number);
}
--
2.43.0
Edited by Zeno Mat