Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Games
KNetWalk
Commits
a5b19dc0
Commit
a5b19dc0
authored
Nov 09, 2020
by
Ryan Loebs
Browse files
Add option to reverse mouse button mapping
parent
55d52b63
Changes
9
Hide whitespace changes
Inline
Side-by-side
src/gameview.cpp
View file @
a5b19dc0
...
...
@@ -38,7 +38,7 @@ GameView::GameView(QWidget *parent) :
QString
path
=
QStandardPaths
::
locate
(
QStandardPaths
::
AppDataLocation
,
QStringLiteral
(
"qml/main.qml"
));
setSource
(
QUrl
::
fromLocalFile
(
path
));
setRotateDuration
();
updateSettings
();
connect
(
rootObject
(),
SIGNAL
(
clicked
(
int
)),
this
,
SLOT
(
clicked
(
int
)));
connect
(
rootObject
(),
SIGNAL
(
rotated
(
int
,
int
)),
this
,
SLOT
(
rotated
(
int
,
int
)));
...
...
@@ -186,9 +186,10 @@ void GameView::solve()
emit
gameOver
(
QLatin1String
(
"solved"
));
}
void
GameView
::
setRotateDuration
()
void
GameView
::
updateSettings
()
{
rootObject
()
->
setProperty
(
"rotateDuration"
,
Settings
::
rotateDuration
());
rootObject
()
->
setProperty
(
"reverseButtons"
,
Settings
::
reverseButtons
());
}
QString
GameView
::
getCableCode
(
int
cables
)
...
...
src/gameview.h
View file @
a5b19dc0
...
...
@@ -41,7 +41,7 @@ public:
public
slots
:
void
setRotateDuration
();
void
updateSettings
();
signals:
void
newCell
(
const
QVariant
&
cable
,
const
QVariant
&
type
);
...
...
src/general.ui
View file @
a5b19dc0
...
...
@@ -12,6 +12,16 @@
</property>
<layout
class=
"QGridLayout"
>
<item
row=
"3"
column=
"1"
>
<widget
class=
"QLabel"
name=
"label"
>
<property
name=
"toolTip"
>
<string>
Duration for cell to complete one rotation in milliseconds
</string>
</property>
<property
name=
"text"
>
<string>
Rotate Duration:
</string>
</property>
</widget>
</item>
<item
row=
"4"
column=
"1"
>
<spacer>
<property
name=
"orientation"
>
<enum>
Qt::Vertical
</enum>
...
...
@@ -34,26 +44,13 @@
</property>
</widget>
</item>
<item
row=
"0"
column=
"3"
>
<spacer>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
<property
name=
"sizeHint"
stdset=
"0"
>
<size>
<width>
40
</width>
<height>
20
</height>
</size>
</property>
</spacer>
</item>
<item
row=
"2"
column=
"1"
>
<widget
class=
"QLabel"
name=
"label"
>
<property
name=
"toolTip"
>
<string>
Duration for cell to complete one rotation in milliseconds
</string>
<item
row=
"3"
column=
"2"
>
<widget
class=
"KPluralHandlingSpinBox"
name=
"kcfg_RotateDuration"
>
<property
name=
"specialValueText"
>
<string/>
</property>
<property
name=
"
text
"
>
<
string>
Rotate Duration:
</string
>
<property
name=
"
singleStep
"
>
<
number>
100
</number
>
</property>
</widget>
</item>
...
...
@@ -67,13 +64,23 @@
</property>
</widget>
</item>
<item
row=
"
2
"
column=
"
2
"
>
<
widget
class=
"KPluralHandlingSpinBox"
name=
"kcfg_RotateDuration"
>
<property
name=
"
specialValueText
"
>
<
string/
>
<item
row=
"
0
"
column=
"
3
"
>
<
spacer
>
<property
name=
"
orientation
"
>
<
enum>
Qt::Horizontal
</enum
>
</property>
<property
name=
"singleStep"
>
<number>
100
</number>
<property
name=
"sizeHint"
stdset=
"0"
>
<size>
<width>
40
</width>
<height>
20
</height>
</size>
</property>
</spacer>
</item>
<item
row=
"2"
column=
"1"
>
<widget
class=
"QCheckBox"
name=
"kcfg_ReverseButtons"
>
<property
name=
"text"
>
<string>
Reverse Mouse Buttons
</string>
</property>
</widget>
</item>
...
...
src/knetwalk.kcfg
View file @
a5b19dc0
...
...
@@ -18,6 +18,10 @@
<label>
Whether lock cell after rotation.
</label>
<default>
false
</default>
</entry>
<entry
name=
"ReverseButtons"
type=
"Bool"
key=
"ReverseButtons"
>
<label>
Use left click for clockwise and right click for counter-clockwise.
</label>
<default>
false
</default>
</entry>
<entry
name=
"RotateDuration"
type=
"Int"
key=
"RotateDuration"
>
<label>
Duration for cell to complete one rotation.
</label>
<min>
100
</min>
...
...
src/mainwindow.cpp
View file @
a5b19dc0
...
...
@@ -188,7 +188,7 @@ void MainWindow::configureSettings()
dialog
->
addPage
(
new
GeneralConfig
(
dialog
),
i18n
(
"General"
),
QStringLiteral
(
"games-config-options"
));
dialog
->
addPage
(
new
KgThemeSelector
(
m_view
->
getProvider
()),
i18n
(
"Theme"
),
QStringLiteral
(
"games-config-theme"
));
dialog
->
addPage
(
new
CustomGameConfig
(
dialog
),
i18n
(
"Custom Game"
),
QStringLiteral
(
"games-config-custom"
));
connect
(
dialog
,
&
KConfigDialog
::
settingsChanged
,
m_view
,
&
GameView
::
setRotateDuration
);
connect
(
dialog
,
&
KConfigDialog
::
settingsChanged
,
m_view
,
&
GameView
::
updateSettings
);
// dialog->setHelp(QString(),QLatin1String("knetwalk"));
dialog
->
show
();
}
...
...
src/qml/Cable.qml
View file @
a5b19dc0
...
...
@@ -21,7 +21,7 @@ CanvasItem {
spriteKey
:
"
cable
"
+
parent
.
sprite
anchors.fill
:
parent
rotation
:
parent
.
angle
opacity
:
(
main
.
state
==
"
paused
"
)?
0
:
1
opacity
:
(
main
.
state
==
=
"
paused
"
)?
0
:
1
Behavior
on
rotation
{
id
:
animate
NumberAnimation
{
...
...
src/qml/Cell.qml
View file @
a5b19dc0
...
...
@@ -30,24 +30,36 @@ Item{
Rectangle
{
anchors.fill
:
parent
color
:
"
black
"
opacity
:
(
locked
&&
main
.
state
==
"
running
"
)?
0.5
:
0
opacity
:
(
locked
&&
main
.
state
==
=
"
running
"
)?
0.5
:
0
}
MouseArea
{
anchors.fill
:
parent
enabled
:
main
.
state
==
"
running
"
enabled
:
main
.
state
==
=
"
running
"
acceptedButtons
:
Qt
.
LeftButton
|
Qt
.
RightButton
|
Qt
.
MiddleButton
hoverEnabled
:
true
onClicked
:
{
main
.
selected
=
index
if
(
mouse
.
button
==
Qt
.
LeftButton
)
{
main
.
rotateCounterclockwise
();
}
else
if
(
mouse
.
button
==
Qt
.
RightButton
)
{
main
.
rotateClockwise
();
}
else
if
(
mouse
.
button
==
Qt
.
MiddleButton
)
{
locked
=
!
locked
switch
(
mouse
.
button
)
{
case
Qt
.
LeftButton
:
if
(
main
.
reverseButtons
)
{
main
.
rotateClockwise
();
}
else
{
main
.
rotateCounterclockwise
();
}
break
;
case
Qt
.
RightButton
:
if
(
main
.
reverseButtons
)
{
main
.
rotateCounterclockwise
();
}
else
{
main
.
rotateClockwise
();
}
break
;
case
Qt
.
MiddleButton
:
locked
=
!
locked
;
break
;
}
}
onEntered
:
main
.
selected
=
index
...
...
src/qml/logic.js
View file @
a5b19dc0
...
...
@@ -46,7 +46,7 @@ function addCell(cable, type) {
cell
.
sprite
=
cable
;
cell
.
index
=
cells
.
length
;
cell
.
type
=
type
if
(
cable
!=
""
)
{
if
(
cable
!=
=
""
)
{
cableComponent
.
createObject
(
cell
);
createNode
(
type
,
cell
)
}
...
...
@@ -54,7 +54,7 @@ function addCell(cable, type) {
}
function
createNode
(
type
,
cell
)
{
if
(
type
!=
"
none
"
)
{
if
(
type
!=
=
"
none
"
)
{
var
node
=
canvasComponent
.
createObject
(
cell
);
node
.
spriteKey
=
cell
.
type
;
node
.
anchors
.
fill
=
cell
;
...
...
@@ -78,18 +78,18 @@ function reset(width, height) {
function
setSprite
(
index
,
cable
,
type
)
{
cells
[
index
].
angle
=
0
;
cells
[
index
].
sprite
=
cable
;
if
(
type
!=
"
none
"
){
if
(
type
!=
=
"
none
"
){
cells
[
index
].
type
=
type
;
nodes
[
cells
[
index
]].
spriteKey
=
type
;
}
}
function
rotate
(
direction
)
{
if
(
cells
[
selected
].
locked
||
cells
[
selected
].
sprite
==
""
)
{
if
(
cells
[
selected
].
locked
||
cells
[
selected
].
sprite
==
=
""
)
{
clicked
(
-
1
);
//invalid click
}
else
if
(
state
==
"
running
"
)
{
cells
[
selected
].
angle
+=
(
direction
==
"
clockwise
"
)?
90
:
-
90
;
else
if
(
state
==
=
"
running
"
)
{
cells
[
selected
].
angle
+=
(
direction
==
=
"
clockwise
"
)?
90
:
-
90
;
clicked
(
selected
);
}
}
...
...
src/qml/main.qml
View file @
a5b19dc0
...
...
@@ -22,6 +22,7 @@ Item {
id
:
main
property
int
selected
:
0
property
int
rotateDuration
:
300
property
bool
reverseButtons
:
false
property
string
state
property
alias
rows
:
grid
.
rows
property
alias
columns
:
grid
.
columns
...
...
@@ -59,7 +60,7 @@ Item {
y
:
grid
.
y
+
((
Logic
.
cells
.
length
>
selected
)?
Logic
.
cells
[
selected
].
y
:
0
)
width
:
grid
.
width
/
grid
.
columns
height
:
width
opacity
:
(
main
.
state
==
"
running
"
)?
0.2
:
0
opacity
:
(
main
.
state
==
=
"
running
"
)?
0.2
:
0
}
Rectangle
{
...
...
@@ -101,31 +102,31 @@ Item {
}
function
kbGoUp
()
{
if
(
state
==
"
running
"
)
{
if
(
state
==
=
"
running
"
)
{
selected
+=
(
selected
<
columns
)?
columns
*
(
rows
-
1
)
:
-
columns
;
}
}
function
kbGoDown
()
{
if
(
state
==
"
running
"
)
{
if
(
state
==
=
"
running
"
)
{
selected
+=
(
selected
<
columns
*
(
rows
-
1
))?
columns
:
-
columns
*
(
rows
-
1
);
}
}
function
kbGoLeft
()
{
if
(
state
==
"
running
"
)
{
if
(
state
==
=
"
running
"
)
{
selected
+=
(
selected
%
columns
==
0
)?
columns
-
1
:
-
1
;
}
}
function
kbGoRight
()
{
if
(
state
==
"
running
"
)
{
if
(
state
==
=
"
running
"
)
{
selected
+=
(
selected
%
columns
==
columns
-
1
)?
-
columns
+
1
:
1
;
}
}
function
toggleLock
()
{
if
(
state
==
"
running
"
)
{
if
(
state
==
=
"
running
"
)
{
Logic
.
cells
[
selected
].
locked
=
!
Logic
.
cells
[
selected
].
locked
;
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment