summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-10-10 22:14:45 +0300
committerAndrei Karas <akaras@inbox.ru>2017-10-10 22:15:57 +0300
commitaa3f63fd497558a02feb3ddbc44f31eac091f39b (patch)
tree0e28b9b1f0501dd8be9e1a38db4ec1777fa3fbfa /src/gui
parent7c10a6b61e9d06a4ae9cc9f942dfacb6fcfd9d3d (diff)
downloadplus-aa3f63fd497558a02feb3ddbc44f31eac091f39b.tar.gz
plus-aa3f63fd497558a02feb3ddbc44f31eac091f39b.tar.bz2
plus-aa3f63fd497558a02feb3ddbc44f31eac091f39b.tar.xz
plus-aa3f63fd497558a02feb3ddbc44f31eac091f39b.zip
Remove most unused files.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/browserlink.h53
-rw-r--r--src/gui/buttoninfo.h49
-rw-r--r--src/gui/buttontext.h45
-rw-r--r--src/gui/chatlog.h48
-rw-r--r--src/gui/cliprect.h129
-rw-r--r--src/gui/color.h253
-rw-r--r--src/gui/colorpair.h43
-rw-r--r--src/gui/dialogsmanager.cpp222
-rw-r--r--src/gui/dialogsmanager.h65
-rw-r--r--src/gui/focushandler.cpp621
-rw-r--r--src/gui/focushandler.h410
-rw-r--r--src/gui/fonts/font.cpp499
-rw-r--r--src/gui/fonts/font.h158
-rw-r--r--src/gui/fonts/textchunk.cpp203
-rw-r--r--src/gui/fonts/textchunk.h75
-rw-r--r--src/gui/fonts/textchunklist.cpp153
-rw-r--r--src/gui/fonts/textchunklist.h60
-rw-r--r--src/gui/fonts/textchunksmall.cpp83
-rw-r--r--src/gui/fonts/textchunksmall.h49
-rw-r--r--src/gui/gui.cpp1515
-rw-r--r--src/gui/gui.h527
-rw-r--r--src/gui/mailmessage.h59
-rw-r--r--src/gui/models/avatarlistmodel.h44
-rw-r--r--src/gui/models/beingslistmodel.h66
-rw-r--r--src/gui/models/colorlistmodel.h87
-rw-r--r--src/gui/models/colormodel.cpp97
-rw-r--r--src/gui/models/colormodel.h69
-rw-r--r--src/gui/models/extendedlistmodel.h40
-rw-r--r--src/gui/models/extendednamesmodel.cpp68
-rw-r--r--src/gui/models/extendednamesmodel.h62
-rw-r--r--src/gui/models/fontsizechoicelistmodel.h92
-rw-r--r--src/gui/models/fontsmodel.h44
-rw-r--r--src/gui/models/iconsmodel.h88
-rw-r--r--src/gui/models/ignorechoiceslistmodel.h64
-rw-r--r--src/gui/models/itemsmodel.h88
-rw-r--r--src/gui/models/keylistmodel.h88
-rw-r--r--src/gui/models/langlistmodel.h145
-rw-r--r--src/gui/models/listmodel.h108
-rw-r--r--src/gui/models/magicschoolmodel.h73
-rw-r--r--src/gui/models/modelistmodel.cpp101
-rw-r--r--src/gui/models/modelistmodel.h70
-rw-r--r--src/gui/models/namesmodel.cpp68
-rw-r--r--src/gui/models/namesmodel.h64
-rw-r--r--src/gui/models/opengllistmodel.h53
-rw-r--r--src/gui/models/playerrelationlistmodel.h75
-rw-r--r--src/gui/models/playertablemodel.cpp148
-rw-r--r--src/gui/models/playertablemodel.h68
-rw-r--r--src/gui/models/questsmodel.h40
-rw-r--r--src/gui/models/serverslistmodel.h119
-rw-r--r--src/gui/models/shopitems.cpp206
-rw-r--r--src/gui/models/shopitems.h170
-rw-r--r--src/gui/models/skillmodel.cpp62
-rw-r--r--src/gui/models/skillmodel.h58
-rw-r--r--src/gui/models/sortlistmodelbuy.h71
-rw-r--r--src/gui/models/sortlistmodelinv.h69
-rw-r--r--src/gui/models/soundsmodel.h49
-rw-r--r--src/gui/models/tablemodel.cpp182
-rw-r--r--src/gui/models/tablemodel.h153
-rw-r--r--src/gui/models/targettypemodel.h64
-rw-r--r--src/gui/models/themesmodel.h49
-rw-r--r--src/gui/models/touchactionmodel.cpp91
-rw-r--r--src/gui/models/touchactionmodel.h49
-rw-r--r--src/gui/models/typelistmodel.h74
-rw-r--r--src/gui/models/updatelistmodel.h79
-rw-r--r--src/gui/models/updatetypemodel.h63
-rw-r--r--src/gui/models/worldlistmodel.h68
-rw-r--r--src/gui/mouseoverlink.h51
-rw-r--r--src/gui/onlineplayer.h90
-rw-r--r--src/gui/palette.cpp199
-rw-r--r--src/gui/palette.h158
-rw-r--r--src/gui/popupmanager.cpp113
-rw-r--r--src/gui/popupmanager.h71
-rw-r--r--src/gui/popups/beingpopup.cpp337
-rw-r--r--src/gui/popups/beingpopup.h68
-rw-r--r--src/gui/popups/itempopup.cpp465
-rw-r--r--src/gui/popups/itempopup.h103
-rw-r--r--src/gui/popups/popupmenu.cpp3613
-rw-r--r--src/gui/popups/popupmenu.h321
-rw-r--r--src/gui/popups/skillpopup.cpp250
-rw-r--r--src/gui/popups/skillpopup.h84
-rw-r--r--src/gui/popups/speechbubble.cpp98
-rw-r--r--src/gui/popups/speechbubble.h67
-rw-r--r--src/gui/popups/spellpopup.cpp123
-rw-r--r--src/gui/popups/spellpopup.h71
-rw-r--r--src/gui/popups/statuspopup.cpp171
-rw-r--r--src/gui/popups/statuspopup.h72
-rw-r--r--src/gui/popups/textboxpopup.cpp83
-rw-r--r--src/gui/popups/textboxpopup.h64
-rw-r--r--src/gui/popups/textpopup.cpp112
-rw-r--r--src/gui/popups/textpopup.h83
-rw-r--r--src/gui/rect.h226
-rw-r--r--src/gui/sdlinput.cpp405
-rw-r--r--src/gui/sdlinput.h391
-rw-r--r--src/gui/setupactiondata.h52
-rw-r--r--src/gui/setupinputpages.cpp80
-rw-r--r--src/gui/setupinputpages.h32
-rw-r--r--src/gui/shortcut/dropshortcut.cpp171
-rw-r--r--src/gui/shortcut/dropshortcut.h69
-rw-r--r--src/gui/shortcut/emoteshortcut.cpp115
-rw-r--r--src/gui/shortcut/emoteshortcut.h133
-rw-r--r--src/gui/shortcut/itemshortcut.cpp289
-rw-r--r--src/gui/shortcut/itemshortcut.h183
-rw-r--r--src/gui/shortcut/shortcutbase.cpp128
-rw-r--r--src/gui/shortcut/shortcutbase.h141
-rw-r--r--src/gui/shortcut/spellshortcut.cpp63
-rw-r--r--src/gui/shortcut/spellshortcut.h88
-rw-r--r--src/gui/skin.cpp152
-rw-r--r--src/gui/skin.h135
-rw-r--r--src/gui/theme.cpp1283
-rw-r--r--src/gui/theme.h207
-rw-r--r--src/gui/themecolorsidoperators.cpp30
-rw-r--r--src/gui/themecolorsidoperators.h28
-rw-r--r--src/gui/themeinfo.h64
-rw-r--r--src/gui/touchactiondata.cpp38
-rw-r--r--src/gui/touchactiondata.h28
-rw-r--r--src/gui/userpalette.cpp649
-rw-r--r--src/gui/userpalette.h250
-rw-r--r--src/gui/viewport.h32
-rw-r--r--src/gui/widgets/attrs/attrdisplay.cpp67
-rw-r--r--src/gui/widgets/attrs/attrdisplay.h82
-rw-r--r--src/gui/widgets/attrs/changedisplay.cpp119
-rw-r--r--src/gui/widgets/attrs/changedisplay.h61
-rw-r--r--src/gui/widgets/attrs/derdisplay.cpp40
-rw-r--r--src/gui/widgets/attrs/derdisplay.h44
-rw-r--r--src/gui/widgets/avatarlistbox.cpp740
-rw-r--r--src/gui/widgets/avatarlistbox.h64
-rw-r--r--src/gui/widgets/basiccontainer.cpp439
-rw-r--r--src/gui/widgets/basiccontainer.h213
-rw-r--r--src/gui/widgets/basiccontainer2.cpp128
-rw-r--r--src/gui/widgets/basiccontainer2.h153
-rw-r--r--src/gui/widgets/browserbox.cpp936
-rw-r--r--src/gui/widgets/browserbox.h210
-rw-r--r--src/gui/widgets/browserbox.inc30
-rw-r--r--src/gui/widgets/button.cpp934
-rw-r--r--src/gui/widgets/button.h347
-rw-r--r--src/gui/widgets/characterdisplay.cpp160
-rw-r--r--src/gui/widgets/characterdisplay.h93
-rw-r--r--src/gui/widgets/characterviewbase.h63
-rw-r--r--src/gui/widgets/characterviewnormal.cpp121
-rw-r--r--src/gui/widgets/characterviewnormal.h50
-rw-r--r--src/gui/widgets/characterviewsmall.cpp136
-rw-r--r--src/gui/widgets/characterviewsmall.h54
-rw-r--r--src/gui/widgets/chatinput.h105
-rw-r--r--src/gui/widgets/checkbox.cpp338
-rw-r--r--src/gui/widgets/checkbox.h216
-rw-r--r--src/gui/widgets/colorpage.cpp124
-rw-r--r--src/gui/widgets/colorpage.h48
-rw-r--r--src/gui/widgets/container.cpp60
-rw-r--r--src/gui/widgets/container.h51
-rw-r--r--src/gui/widgets/containerplacer.cpp44
-rw-r--r--src/gui/widgets/containerplacer.h73
-rw-r--r--src/gui/widgets/createwidget.h41
-rw-r--r--src/gui/widgets/desktop.cpp229
-rw-r--r--src/gui/widgets/desktop.h88
-rw-r--r--src/gui/widgets/dropdown.cpp580
-rw-r--r--src/gui/widgets/dropdown.h166
-rw-r--r--src/gui/widgets/emotepage.cpp167
-rw-r--r--src/gui/widgets/emotepage.h67
-rw-r--r--src/gui/widgets/emoteshortcutcontainer.cpp297
-rw-r--r--src/gui/widgets/emoteshortcutcontainer.h92
-rw-r--r--src/gui/widgets/equipmentbox.h41
-rw-r--r--src/gui/widgets/equipmentpage.h53
-rw-r--r--src/gui/widgets/extendedlistbox.cpp257
-rw-r--r--src/gui/widgets/extendedlistbox.h61
-rw-r--r--src/gui/widgets/extendedlistboxitem.h49
-rw-r--r--src/gui/widgets/flowcontainer.cpp97
-rw-r--r--src/gui/widgets/flowcontainer.h75
-rw-r--r--src/gui/widgets/guitable.cpp675
-rw-r--r--src/gui/widgets/guitable.h207
-rw-r--r--src/gui/widgets/horizontcontainer.cpp66
-rw-r--r--src/gui/widgets/horizontcontainer.h62
-rw-r--r--src/gui/widgets/icon.cpp105
-rw-r--r--src/gui/widgets/icon.h83
-rw-r--r--src/gui/widgets/inttextfield.cpp148
-rw-r--r--src/gui/widgets/inttextfield.h85
-rw-r--r--src/gui/widgets/itemcontainer.cpp1322
-rw-r--r--src/gui/widgets/itemcontainer.h223
-rw-r--r--src/gui/widgets/itemlinkhandler.cpp223
-rw-r--r--src/gui/widgets/itemlinkhandler.h61
-rw-r--r--src/gui/widgets/itemshortcutcontainer.cpp650
-rw-r--r--src/gui/widgets/itemshortcutcontainer.h89
-rw-r--r--src/gui/widgets/label.cpp292
-rw-r--r--src/gui/widgets/label.h195
-rw-r--r--src/gui/widgets/layout.cpp46
-rw-r--r--src/gui/widgets/layout.h66
-rw-r--r--src/gui/widgets/layoutarray.cpp313
-rw-r--r--src/gui/widgets/layoutarray.h127
-rw-r--r--src/gui/widgets/layoutcell.cpp136
-rw-r--r--src/gui/widgets/layoutcell.h196
-rw-r--r--src/gui/widgets/layouthelper.cpp79
-rw-r--r--src/gui/widgets/layouthelper.h91
-rw-r--r--src/gui/widgets/linepart.cpp33
-rw-r--r--src/gui/widgets/linepart.h102
-rw-r--r--src/gui/widgets/linkhandler.h49
-rw-r--r--src/gui/widgets/listbox.cpp446
-rw-r--r--src/gui/widgets/listbox.h296
-rw-r--r--src/gui/widgets/passwordfield.cpp55
-rw-r--r--src/gui/widgets/passwordfield.h55
-rw-r--r--src/gui/widgets/playerbox.cpp190
-rw-r--r--src/gui/widgets/playerbox.h112
-rw-r--r--src/gui/widgets/popup.cpp273
-rw-r--r--src/gui/widgets/popup.h193
-rw-r--r--src/gui/widgets/popuplist.cpp188
-rw-r--r--src/gui/widgets/popuplist.h84
-rw-r--r--src/gui/widgets/progressbar.cpp376
-rw-r--r--src/gui/widgets/progressbar.h166
-rw-r--r--src/gui/widgets/progressindicator.cpp98
-rw-r--r--src/gui/widgets/progressindicator.h54
-rw-r--r--src/gui/widgets/radiobutton.cpp373
-rw-r--r--src/gui/widgets/radiobutton.h247
-rw-r--r--src/gui/widgets/radiogroup.cpp41
-rw-r--r--src/gui/widgets/radiogroup.h41
-rw-r--r--src/gui/widgets/scrollarea.cpp1460
-rw-r--r--src/gui/widgets/scrollarea.h598
-rw-r--r--src/gui/widgets/selldialog.cpp397
-rw-r--r--src/gui/widgets/selldialog.h156
-rw-r--r--src/gui/widgets/serverslistbox.h159
-rw-r--r--src/gui/widgets/setupbuttonitem.cpp95
-rw-r--r--src/gui/widgets/setupbuttonitem.h69
-rw-r--r--src/gui/widgets/setupitem.cpp1338
-rw-r--r--src/gui/widgets/setupitem.h613
-rw-r--r--src/gui/widgets/setupquickitem.cpp117
-rw-r--r--src/gui/widgets/setupquickitem.h80
-rw-r--r--src/gui/widgets/setuptouchitem.cpp132
-rw-r--r--src/gui/widgets/setuptouchitem.h67
-rw-r--r--src/gui/widgets/shoplistbox.cpp310
-rw-r--r--src/gui/widgets/shoplistbox.h113
-rw-r--r--src/gui/widgets/shortcutcontainer.cpp159
-rw-r--r--src/gui/widgets/shortcutcontainer.h120
-rw-r--r--src/gui/widgets/skilllistbox.h290
-rw-r--r--src/gui/widgets/skillrectanglelistbox.h418
-rw-r--r--src/gui/widgets/slider.cpp517
-rw-r--r--src/gui/widgets/slider.h337
-rw-r--r--src/gui/widgets/sliderlist.cpp240
-rw-r--r--src/gui/widgets/sliderlist.h89
-rw-r--r--src/gui/widgets/spellshortcutcontainer.cpp371
-rw-r--r--src/gui/widgets/spellshortcutcontainer.h86
-rw-r--r--src/gui/widgets/staticbrowserbox.cpp781
-rw-r--r--src/gui/widgets/staticbrowserbox.h194
-rw-r--r--src/gui/widgets/statspage.cpp88
-rw-r--r--src/gui/widgets/statspage.h61
-rw-r--r--src/gui/widgets/statspagebasic.cpp163
-rw-r--r--src/gui/widgets/statspagebasic.h67
-rw-r--r--src/gui/widgets/tabbedarea.cpp827
-rw-r--r--src/gui/widgets/tabbedarea.h299
-rw-r--r--src/gui/widgets/tabs/chat/battletab.cpp44
-rw-r--r--src/gui/widgets/tabs/chat/battletab.h43
-rw-r--r--src/gui/widgets/tabs/chat/channeltab.cpp77
-rw-r--r--src/gui/widgets/tabs/chat/channeltab.h51
-rw-r--r--src/gui/widgets/tabs/chat/chattab.cpp563
-rw-r--r--src/gui/widgets/tabs/chat/chattab.h216
-rw-r--r--src/gui/widgets/tabs/chat/emulateguildtab.cpp108
-rw-r--r--src/gui/widgets/tabs/chat/emulateguildtab.h59
-rw-r--r--src/gui/widgets/tabs/chat/gmtab.cpp57
-rw-r--r--src/gui/widgets/tabs/chat/gmtab.h49
-rw-r--r--src/gui/widgets/tabs/chat/guildtab.cpp125
-rw-r--r--src/gui/widgets/tabs/chat/guildtab.h56
-rw-r--r--src/gui/widgets/tabs/chat/langtab.cpp38
-rw-r--r--src/gui/widgets/tabs/chat/langtab.h39
-rw-r--r--src/gui/widgets/tabs/chat/partytab.cpp151
-rw-r--r--src/gui/widgets/tabs/chat/partytab.h58
-rw-r--r--src/gui/widgets/tabs/chat/tradetab.cpp50
-rw-r--r--src/gui/widgets/tabs/chat/tradetab.h46
-rw-r--r--src/gui/widgets/tabs/chat/whispertab.cpp130
-rw-r--r--src/gui/widgets/tabs/chat/whispertab.h73
-rw-r--r--src/gui/widgets/tabs/debugwindowtabs.cpp492
-rw-r--r--src/gui/widgets/tabs/debugwindowtabs.h129
-rw-r--r--src/gui/widgets/tabs/setup_audio.cpp214
-rw-r--r--src/gui/widgets/tabs/setup_audio.h47
-rw-r--r--src/gui/widgets/tabs/setup_chat.cpp347
-rw-r--r--src/gui/widgets/tabs/setup_chat.h40
-rw-r--r--src/gui/widgets/tabs/setup_colors.cpp491
-rw-r--r--src/gui/widgets/tabs/setup_colors.h91
-rw-r--r--src/gui/widgets/tabs/setup_input.cpp399
-rw-r--r--src/gui/widgets/tabs/setup_input.h105
-rw-r--r--src/gui/widgets/tabs/setup_joystick.cpp184
-rw-r--r--src/gui/widgets/tabs/setup_joystick.h62
-rw-r--r--src/gui/widgets/tabs/setup_misc.cpp518
-rw-r--r--src/gui/widgets/tabs/setup_misc.h52
-rw-r--r--src/gui/widgets/tabs/setup_mods.cpp129
-rw-r--r--src/gui/widgets/tabs/setup_mods.h50
-rw-r--r--src/gui/widgets/tabs/setup_perfomance.cpp209
-rw-r--r--src/gui/widgets/tabs/setup_perfomance.h46
-rw-r--r--src/gui/widgets/tabs/setup_players.cpp211
-rw-r--r--src/gui/widgets/tabs/setup_players.h49
-rw-r--r--src/gui/widgets/tabs/setup_quick.cpp118
-rw-r--r--src/gui/widgets/tabs/setup_quick.h45
-rw-r--r--src/gui/widgets/tabs/setup_relations.cpp266
-rw-r--r--src/gui/widgets/tabs/setup_relations.h79
-rw-r--r--src/gui/widgets/tabs/setup_theme.cpp415
-rw-r--r--src/gui/widgets/tabs/setup_theme.h113
-rw-r--r--src/gui/widgets/tabs/setup_touch.cpp134
-rw-r--r--src/gui/widgets/tabs/setup_touch.h44
-rw-r--r--src/gui/widgets/tabs/setup_video.cpp534
-rw-r--r--src/gui/widgets/tabs/setup_video.h88
-rw-r--r--src/gui/widgets/tabs/setup_visual.cpp252
-rw-r--r--src/gui/widgets/tabs/setup_visual.h51
-rw-r--r--src/gui/widgets/tabs/setuptab.cpp44
-rw-r--r--src/gui/widgets/tabs/setuptab.h74
-rw-r--r--src/gui/widgets/tabs/setuptabscroll.cpp163
-rw-r--r--src/gui/widgets/tabs/setuptabscroll.h81
-rw-r--r--src/gui/widgets/tabs/shortcuttab.h47
-rw-r--r--src/gui/widgets/tabs/skilltab.h88
-rw-r--r--src/gui/widgets/tabs/socialattacktab.h77
-rw-r--r--src/gui/widgets/tabs/socialfriendsfunctor.h59
-rw-r--r--src/gui/widgets/tabs/socialfriendstab.h127
-rw-r--r--src/gui/widgets/tabs/socialguildtab.h179
-rw-r--r--src/gui/widgets/tabs/socialguildtab2.h106
-rw-r--r--src/gui/widgets/tabs/socialnavigationtab.h308
-rw-r--r--src/gui/widgets/tabs/socialpartytab.h171
-rw-r--r--src/gui/widgets/tabs/socialpickuptab.h75
-rw-r--r--src/gui/widgets/tabs/socialplayerstab.h198
-rw-r--r--src/gui/widgets/tabs/socialtab.h143
-rw-r--r--src/gui/widgets/tabs/socialtabbase.h84
-rw-r--r--src/gui/widgets/tabs/tab.cpp488
-rw-r--r--src/gui/widgets/tabs/tab.h245
-rw-r--r--src/gui/widgets/tabstrip.cpp124
-rw-r--r--src/gui/widgets/tabstrip.h57
-rw-r--r--src/gui/widgets/textbox.cpp647
-rw-r--r--src/gui/widgets/textbox.h329
-rw-r--r--src/gui/widgets/textfield.cpp837
-rw-r--r--src/gui/widgets/textfield.h293
-rw-r--r--src/gui/widgets/textpreview.cpp151
-rw-r--r--src/gui/widgets/textpreview.h144
-rw-r--r--src/gui/widgets/vertcontainer.cpp89
-rw-r--r--src/gui/widgets/vertcontainer.h66
-rw-r--r--src/gui/widgets/virtshortcutcontainer.cpp383
-rw-r--r--src/gui/widgets/virtshortcutcontainer.h92
-rw-r--r--src/gui/widgets/widget.cpp526
-rw-r--r--src/gui/widgets/widget.h1181
-rw-r--r--src/gui/widgets/widget2.h117
-rw-r--r--src/gui/widgets/widgetgroup.cpp87
-rw-r--r--src/gui/widgets/widgetgroup.h69
-rw-r--r--src/gui/widgets/window.cpp1499
-rw-r--r--src/gui/widgets/window.h725
-rw-r--r--src/gui/widgets/windowcontainer.cpp105
-rw-r--r--src/gui/widgets/windowcontainer.h74
-rw-r--r--src/gui/windowmanager.cpp498
-rw-r--r--src/gui/windowmanager.h87
-rw-r--r--src/gui/windowmenu.cpp493
-rw-r--r--src/gui/windowmenu.h118
-rw-r--r--src/gui/windows/bankwindow.cpp102
-rw-r--r--src/gui/windows/bankwindow.h64
-rw-r--r--src/gui/windows/buydialog.cpp794
-rw-r--r--src/gui/windows/buydialog.h207
-rw-r--r--src/gui/windows/buyingstoreselldialog.cpp70
-rw-r--r--src/gui/windows/buyingstoreselldialog.h55
-rw-r--r--src/gui/windows/buyselldialog.cpp167
-rw-r--r--src/gui/windows/buyselldialog.h86
-rw-r--r--src/gui/windows/changeemaildialog.cpp186
-rw-r--r--src/gui/windows/changeemaildialog.h81
-rw-r--r--src/gui/windows/changepassworddialog.cpp177
-rw-r--r--src/gui/windows/changepassworddialog.h76
-rw-r--r--src/gui/windows/charcreatedialog.cpp885
-rw-r--r--src/gui/windows/charcreatedialog.h171
-rw-r--r--src/gui/windows/chardeleteconfirm.h65
-rw-r--r--src/gui/windows/charselectdialog.cpp644
-rw-r--r--src/gui/windows/charselectdialog.h136
-rw-r--r--src/gui/windows/chatwindow.cpp2181
-rw-r--r--src/gui/windows/chatwindow.h406
-rw-r--r--src/gui/windows/confirmdialog.cpp120
-rw-r--r--src/gui/windows/confirmdialog.h71
-rw-r--r--src/gui/windows/connectiondialog.cpp90
-rw-r--r--src/gui/windows/connectiondialog.h69
-rw-r--r--src/gui/windows/cutinwindow.cpp153
-rw-r--r--src/gui/windows/cutinwindow.h61
-rw-r--r--src/gui/windows/debugwindow.cpp173
-rw-r--r--src/gui/windows/debugwindow.h78
-rw-r--r--src/gui/windows/didyouknowwindow.cpp188
-rw-r--r--src/gui/windows/didyouknowwindow.h76
-rw-r--r--src/gui/windows/editdialog.cpp80
-rw-r--r--src/gui/windows/editdialog.h72
-rw-r--r--src/gui/windows/editserverdialog.cpp297
-rw-r--r--src/gui/windows/editserverdialog.h86
-rw-r--r--src/gui/windows/eggselectiondialog.cpp67
-rw-r--r--src/gui/windows/eggselectiondialog.h45
-rw-r--r--src/gui/windows/emotewindow.cpp278
-rw-r--r--src/gui/windows/emotewindow.h89
-rw-r--r--src/gui/windows/equipmentwindow.cpp848
-rw-r--r--src/gui/windows/equipmentwindow.h167
-rw-r--r--src/gui/windows/helpwindow.cpp220
-rw-r--r--src/gui/windows/helpwindow.h92
-rw-r--r--src/gui/windows/insertcarddialog.cpp79
-rw-r--r--src/gui/windows/insertcarddialog.h49
-rw-r--r--src/gui/windows/inventorywindow.cpp1083
-rw-r--r--src/gui/windows/inventorywindow.h210
-rw-r--r--src/gui/windows/itemamountwindow.cpp504
-rw-r--r--src/gui/windows/itemamountwindow.h123
-rw-r--r--src/gui/windows/killstats.cpp479
-rw-r--r--src/gui/windows/killstats.h116
-rw-r--r--src/gui/windows/logindialog.cpp402
-rw-r--r--src/gui/windows/logindialog.h113
-rw-r--r--src/gui/windows/maileditwindow.cpp278
-rw-r--r--src/gui/windows/maileditwindow.h92
-rw-r--r--src/gui/windows/mailviewwindow.cpp269
-rw-r--r--src/gui/windows/mailviewwindow.h80
-rw-r--r--src/gui/windows/mailwindow.cpp393
-rw-r--r--src/gui/windows/mailwindow.h108
-rw-r--r--src/gui/windows/minimap.cpp540
-rw-r--r--src/gui/windows/minimap.h95
-rw-r--r--src/gui/windows/ministatuswindow.cpp594
-rw-r--r--src/gui/windows/ministatuswindow.h151
-rw-r--r--src/gui/windows/npcdialog.cpp1395
-rw-r--r--src/gui/windows/npcdialog.h324
-rw-r--r--src/gui/windows/npcselldialog.cpp154
-rw-r--r--src/gui/windows/npcselldialog.h59
-rw-r--r--src/gui/windows/okdialog.cpp94
-rw-r--r--src/gui/windows/okdialog.h72
-rw-r--r--src/gui/windows/outfitwindow.cpp749
-rw-r--r--src/gui/windows/outfitwindow.h133
-rw-r--r--src/gui/windows/questswindow.cpp483
-rw-r--r--src/gui/windows/questswindow.h105
-rw-r--r--src/gui/windows/quitdialog.cpp260
-rw-r--r--src/gui/windows/quitdialog.h84
-rw-r--r--src/gui/windows/registerdialog.cpp317
-rw-r--r--src/gui/windows/registerdialog.h95
-rw-r--r--src/gui/windows/serverdialog.cpp902
-rw-r--r--src/gui/windows/serverdialog.h150
-rw-r--r--src/gui/windows/serverinfowindow.cpp184
-rw-r--r--src/gui/windows/serverinfowindow.h68
-rw-r--r--src/gui/windows/setupwindow.cpp335
-rw-r--r--src/gui/windows/setupwindow.h96
-rw-r--r--src/gui/windows/shopselldialog.cpp60
-rw-r--r--src/gui/windows/shopselldialog.h54
-rw-r--r--src/gui/windows/shopwindow.cpp1175
-rw-r--r--src/gui/windows/shopwindow.h207
-rw-r--r--src/gui/windows/shortcutwindow.cpp269
-rw-r--r--src/gui/windows/shortcutwindow.h100
-rw-r--r--src/gui/windows/skilldialog.cpp1432
-rw-r--r--src/gui/windows/skilldialog.h237
-rw-r--r--src/gui/windows/socialwindow.cpp659
-rw-r--r--src/gui/windows/socialwindow.h171
-rw-r--r--src/gui/windows/statuswindow.cpp652
-rw-r--r--src/gui/windows/statuswindow.h119
-rw-r--r--src/gui/windows/textcommandeditor.cpp344
-rw-r--r--src/gui/windows/textcommandeditor.h116
-rw-r--r--src/gui/windows/textdialog.cpp135
-rw-r--r--src/gui/windows/textdialog.h85
-rw-r--r--src/gui/windows/textselectdialog.cpp192
-rw-r--r--src/gui/windows/textselectdialog.h104
-rw-r--r--src/gui/windows/tradewindow.cpp553
-rw-r--r--src/gui/windows/tradewindow.h214
-rw-r--r--src/gui/windows/updaterwindow.cpp1217
-rw-r--r--src/gui/windows/updaterwindow.h252
-rw-r--r--src/gui/windows/whoisonline.cpp909
-rw-r--r--src/gui/windows/whoisonline.h182
-rw-r--r--src/gui/windows/worldselectdialog.cpp134
-rw-r--r--src/gui/windows/worldselectdialog.h77
448 files changed, 0 insertions, 100884 deletions
diff --git a/src/gui/browserlink.h b/src/gui/browserlink.h
deleted file mode 100644
index a8dc0cb6f..000000000
--- a/src/gui/browserlink.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- * Copyright (C) 2009 Aethyra Development Team
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_BROWSERLINK_H
-#define GUI_BROWSERLINK_H
-
-#include <string>
-
-#include "localconsts.h"
-
-struct BrowserLink final
-{
- BrowserLink() :
- x1(0),
- x2(0),
- y1(0),
- y2(0),
- link(),
- caption()
- {
- }
-
- A_DEFAULT_COPY(BrowserLink)
-
- int x1;
- int x2;
- int y1;
- int y2;
- std::string link;
- std::string caption;
-};
-
-#endif // GUI_BROWSERLINK_H
diff --git a/src/gui/buttoninfo.h b/src/gui/buttoninfo.h
deleted file mode 100644
index d6039e08f..000000000
--- a/src/gui/buttoninfo.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_BUTTONINFO_H
-#define GUI_BUTTONINFO_H
-
-#include "enums/input/inputaction.h"
-
-#include "enums/simpletypes/visible.h"
-
-#include "localconsts.h"
-
-class Button;
-
-struct ButtonInfo final
-{
- ButtonInfo(Button *const button0,
- const InputActionT key0,
- const Visible visible0) :
- button(button0),
- key(key0),
- visible(visible0)
- {
- }
-
- A_DELETE_COPY(ButtonInfo)
-
- Button *button;
- InputActionT key;
- Visible visible;
-};
-#endif // GUI_BUTTONINFO_H
diff --git a/src/gui/buttontext.h b/src/gui/buttontext.h
deleted file mode 100644
index f827859b6..000000000
--- a/src/gui/buttontext.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_BUTTONTEXT_H
-#define GUI_BUTTONTEXT_H
-
-#include "enums/input/inputaction.h"
-
-#include "localconsts.h"
-
-#include <string>
-
-struct ButtonText final
-{
- ButtonText(const std::string &text0,
- const InputActionT key0) :
- text(text0),
- key(key0)
- {
- }
-
- A_DELETE_COPY(ButtonText)
-
- std::string text;
- InputActionT key;
-};
-
-#endif // GUI_BUTTONTEXT_H
diff --git a/src/gui/chatlog.h b/src/gui/chatlog.h
deleted file mode 100644
index 20820ad13..000000000
--- a/src/gui/chatlog.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_CHATLOG_H
-#define GUI_CHATLOG_H
-
-#include "enums/gui/chatmsgtype.h"
-
-#include <string>
-
-#include "localconsts.h"
-
-/** One item in the chat log */
-struct CHATLOG final
-{
- CHATLOG() :
- nick(),
- text(),
- own(ChatMsgType::BY_UNKNOWN)
- {
- }
-
- A_DELETE_COPY(CHATLOG)
-
- std::string nick;
- std::string text;
- ChatMsgTypeT own;
-};
-#endif // GUI_CHATLOG_H
diff --git a/src/gui/cliprect.h b/src/gui/cliprect.h
deleted file mode 100644
index 149420b8c..000000000
--- a/src/gui/cliprect.h
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_CLIPRECT_H
-#define GUI_CLIPRECT_H
-
-#include "gui/rect.h"
-
-#include "localconsts.h"
-
-/**
- * A rectangle used when dealing with clipping. A clip rectangle is
- * a regular rectangle extended with variables for x offsets and y
- * offsets. The offsets are used for calculations from relative
- * screen coordinates to actual screen coordinates.
- */
-class ClipRect final : public Rect
-{
- public:
- /**
- * Constructor.
- */
- ClipRect() :
- Rect(0, 0, 0, 0),
- xOffset(0),
- yOffset(0)
- {
- }
-
- /**
- * Constructor.
- *
- * @param x0 The rectangle x coordinate.
- * @param y0 The rectangle y coordinate.
- * @param width0 The rectangle width.
- * @param height0 The rectangle height.
- * @param xOffset0 The offset of the x coordinate. Used to for
- * calculating the actual screen coordinate from
- * the relative screen coordinate.
- * @param yOffset0 The offset of the y coordinate. Used to for
- * calculating the actual screen coordinate from
- * the relative screen coordinate.
- */
- ClipRect(const int x0,
- const int y0,
- const int width0,
- const int height0,
- const int xOffset0,
- const int yOffset0) :
- Rect(x0, y0, width0, height0),
- xOffset(xOffset0),
- yOffset(yOffset0)
- {
- }
-
- A_DELETE_COPY(ClipRect)
-
- /**
- * Holds the x offset of the x coordinate.
- */
- int xOffset;
-
- /**
- * Holds the y offset of the y coordinate.
- */
- int yOffset;
-};
-
-#endif // GUI_CLIPRECT_H
diff --git a/src/gui/color.h b/src/gui/color.h
deleted file mode 100644
index c4a1aab01..000000000
--- a/src/gui/color.h
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_COLOR_H
-#define GUI_COLOR_H
-
-#include "utils/cast.h"
-
-#include "localconsts.h"
-
-/**
- * Represents a color with red, green, blue and alpha components.
- */
-class Color final
-{
- public:
- /**
- * Constructor. Initializes the color to black.
- */
- constexpr Color() :
- r(0U),
- g(0U),
- b(0U),
- a(255U)
- {
- }
-
- /**
- * Constructor. Constructs a color from the bytes in an integer.
- * Call it with a hexadecimal constant for HTML-style color
- * representation.
- * The alpha component is 255 by default.
- *
- * EXAMPLE: Color(0xff50a0) constructs a very nice pinkish color.
- *
- * NOTE: Because of this constructor, integers will be automatically
- * casted to a color by your compiler.
- *
- * @param color The color to initialise the object with.
- */
- explicit constexpr Color(const unsigned int color) :
- r((color >> 16) & 0xFFU),
- g((color >> 8) & 0xFFU),
- b(color & 0xFFU),
- a(255U)
- {
- }
-
- /**
- * Constructor. The default alpha value is 255.
- *
- * @param ar Red color component (range 0-255).
- * @param ag Green color component (range 0-255).
- * @param ab Blue color component (range 0-255).
- * @param aa Alpha, used for transparency. A value of 0 means
- * totaly transparent, 255 is totaly opaque.
- */
- constexpr Color(const unsigned int ar,
- const unsigned int ag,
- const unsigned int ab,
- const unsigned int aa = 255) :
- r(ar),
- g(ag),
- b(ab),
- a(aa)
- {
- }
-
-
- A_DEFAULT_COPY(Color)
-
- /**
- * Adds the RGB values of two colors together. The values will be
- * clamped if they go out of range.
- *
- * WARNING: This function will reset the alpha value of the
- * returned color to 255.
- *
- * @param color A color to add to this color.
- * @return The added colors with an alpha value set to 255.
- */
- constexpr2 Color operator+(const Color& color) const
- {
- Color result(r + color.r,
- g + color.g,
- b + color.b,
- 255U);
-
- result.r = (result.r > 255U ? 255U : result.r);
- result.g = (result.g > 255U ? 255U : result.g);
- result.b = (result.b > 255U ? 255U : result.b);
-
- return result;
- }
-
- /**
- * Subtracts the RGB values of one color from another.
- * The values will be clamped if they go out of range.
- *
- * WARNING: This function will reset the alpha value of the
- * returned color to 255.
- *
- * @param color A color to subtract from this color.
- * @return The subtracted colors with an alpha value set to 255.
- */
- constexpr2 Color operator-(const Color& color) const
- {
- Color result(r - color.r,
- g - color.g,
- b - color.b,
- 255U);
-
- result.r = (result.r > 255U ? 255U : result.r);
- result.g = (result.g > 255U ? 255U : result.g);
- result.b = (result.b > 255U ? 255U : result.b);
-
- return result;
- }
-
- /**
- * Multiplies the RGB values of a color with a float value.
- * The values will be clamped if they go out of range.
- *
- * @param value The value to multiply the color with.
- * @return The multiplied colors. The alpha value will, unlike
- * the add and subtract operations, be multiplied as
- * well.
- */
- constexpr2 Color operator*(const float value) const
- {
- Color result(CAST_U32(static_cast<float>(r) * value),
- CAST_U32(static_cast<float>(g) * value),
- CAST_U32(static_cast<float>(b) * value),
- a);
-
- result.r = (result.r > 255U ? 255U : result.r);
- result.g = (result.g > 255U ? 255U : result.g);
- result.b = (result.b > 255U ? 255U : result.b);
-
- return result;
- }
-
- /**
- * Compares two colors.
- *
- * @return True if the two colors have the same RGBA components
- * false otherwise.
- */
- constexpr bool operator==(const Color& color) const
- {
- return r == color.r &&
- g == color.g &&
- b == color.b &&
- a == color.a;
- }
-
- /**
- * Compares two colors.
- *
- * @return True if the two colors have different RGBA components,
- * false otherwise.
- */
- constexpr bool operator!=(const Color& color) const
- {
- return !(r == color.r &&
- g == color.g &&
- b == color.b &&
- a == color.a);
- }
-
- /**
- * Holds the red color component (range 0-255).
- */
- unsigned int r;
-
- /**
- * Holds the green color component (range 0-255).
- */
- unsigned int g;
-
- /**
- * Holds the blue color component (range 0-255).
- */
- unsigned int b;
-
- /**
- * Holds the alpha color component. A value of 0 means totally
- * transparent while a value of 255 is considered opaque.
- */
- unsigned int a;
-};
-
-#endif // GUI_COLOR_H
diff --git a/src/gui/colorpair.h b/src/gui/colorpair.h
deleted file mode 100644
index f3089868e..000000000
--- a/src/gui/colorpair.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_COLORPAIR_H
-#define GUI_COLORPAIR_H
-
-#include "localconsts.h"
-
-class Color;
-
-struct ColorPair final
-{
- constexpr ColorPair(const Color *const c1,
- const Color *const c2) :
- color1(c1),
- color2(c2)
- {
- }
-
- A_DEFAULT_COPY(ColorPair)
-
- const Color *color1;
- const Color *color2;
-};
-
-#endif // GUI_COLORPAIR_H
diff --git a/src/gui/dialogsmanager.cpp b/src/gui/dialogsmanager.cpp
deleted file mode 100644
index f24352a43..000000000
--- a/src/gui/dialogsmanager.cpp
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/dialogsmanager.h"
-
-#include "configuration.h"
-#include "settings.h"
-
-#include "being/playerinfo.h"
-
-#include "gui/widgets/createwidget.h"
-
-#include "gui/windows/confirmdialog.h"
-
-#ifndef DYECMD
-#include "gui/widgets/selldialog.h"
-
-#include "gui/windows/buyselldialog.h"
-#include "gui/windows/buydialog.h"
-#include "gui/windows/updaterwindow.h"
-
-#include "listeners/playerpostdeathlistener.h"
-#endif // DYECMD
-
-#include "listeners/weightlistener.h"
-
-#include "net/inventoryhandler.h"
-
-#include "resources/db/deaddb.h"
-
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-#ifdef WIN32
-#undef ERROR
-#endif // WIN32
-
-OkDialog *deathNotice = nullptr;
-DialogsManager *dialogsManager = nullptr;
-OkDialog *weightNotice = nullptr;
-time_t weightNoticeTime = 0;
-
-#ifndef DYECMD
-namespace
-{
- PlayerPostDeathListener postDeathListener;
- WeightListener weightListener;
-} // namespace
-#endif // DYECMD
-
-DialogsManager::DialogsManager() :
- AttributeListener(),
- PlayerDeathListener()
-{
-}
-
-void DialogsManager::closeDialogs()
-{
-#ifndef DYECMD
- NpcDialog::clearDialogs();
- BuyDialog::closeAll();
- BuySellDialog::closeAll();
- NpcDialog::closeAll();
- SellDialog::closeAll();
- if (inventoryHandler != nullptr)
- inventoryHandler->destroyStorage();
-#endif // DYECMD
-
- if (deathNotice != nullptr)
- {
- deathNotice->scheduleDelete();
- deathNotice = nullptr;
- }
-}
-
-void DialogsManager::createUpdaterWindow()
-{
-#ifndef DYECMD
- CREATEWIDGETV(updaterWindow, UpdaterWindow,
- settings.updateHost,
- settings.oldUpdates,
- false,
- UpdateType::Normal);
-#endif // DYECMD
-}
-
-Window *DialogsManager::openErrorDialog(const std::string &header,
- const std::string &message,
- const Modal modal)
-{
- if (settings.supportUrl.empty() || config.getBoolValue("hidesupport"))
- {
- OkDialog *const dialog = CREATEWIDGETR(OkDialog,
- header,
- message,
- // TRANSLATORS: ok dialog button
- _("Close"),
- DialogType::ERROR,
- modal,
- ShowCenter_true,
- nullptr,
- 260);
- return dialog;
- }
- ConfirmDialog *const dialog = CREATEWIDGETR(ConfirmDialog,
- header,
- strprintf("%s %s", message.c_str(),
- // TRANSLATORS: error message question
- _("Do you want to open support page?")),
- SOUND_ERROR,
- false,
- modal);
- return dialog;
-}
-
-void DialogsManager::playerDeath()
-{
-#ifndef DYECMD
- if (deathNotice == nullptr)
- {
- CREATEWIDGETV(deathNotice, OkDialog,
- // TRANSLATORS: message header
- _("Message"),
- DeadDB::getRandomString(),
- // TRANSLATORS: ok dialog button
- _("Revive"),
- DialogType::OK,
- Modal_false,
- ShowCenter_true,
- nullptr,
- 260);
- deathNotice->addActionListener(&postDeathListener);
- }
-#endif // DYECMD
-}
-
-#ifndef DYECMD
-void DialogsManager::attributeChanged(const AttributesT id,
- const int64_t oldVal,
- const int64_t newVal)
-{
- if (id == Attributes::TOTAL_WEIGHT)
- {
- if ((weightNotice == nullptr) && config.getBoolValue("weightMsg"))
- {
- int percent = settings.overweightPercent;
- if (percent < 1)
- percent = 50;
- const int max = PlayerInfo::getAttribute(
- Attributes::MAX_WEIGHT) * percent / 100;
- const int total = CAST_S32(oldVal);
- if (newVal >= max && total < max)
- {
- weightNoticeTime = cur_time + 5;
- CREATEWIDGETV(weightNotice, OkDialog,
- // TRANSLATORS: message header
- _("Message"),
- // TRANSLATORS: weight message
- _("You are carrying more than "
- "half your weight. You are "
- "unable to regain health."),
- // TRANSLATORS: ok dialog button
- _("OK"),
- DialogType::OK,
- Modal_false,
- ShowCenter_true,
- nullptr,
- 260);
- weightNotice->addActionListener(
- &weightListener);
- }
- else if (newVal < max && total >= max)
- {
- weightNoticeTime = cur_time + 5;
- CREATEWIDGETV(weightNotice, OkDialog,
- // TRANSLATORS: message header
- _("Message"),
- // TRANSLATORS: weight message
- _("You are carrying less than "
- "half your weight. You "
- "can regain health."),
- // TRANSLATORS: ok dialog button
- _("OK"),
- DialogType::OK,
- Modal_false,
- ShowCenter_true,
- nullptr,
- 260);
- weightNotice->addActionListener(
- &weightListener);
- }
- }
- }
-}
-#else // DYECMD
-
-void DialogsManager::attributeChanged(const AttributesT id A_UNUSED,
- const int64_t oldVal A_UNUSED,
- const int64_t newVal A_UNUSED)
-{
-}
-#endif // DYECMD
diff --git a/src/gui/dialogsmanager.h b/src/gui/dialogsmanager.h
deleted file mode 100644
index 04ace68e2..000000000
--- a/src/gui/dialogsmanager.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_DIALOGSMANAGER_H
-#define GUI_DIALOGSMANAGER_H
-
-#include "enums/simpletypes/modal.h"
-
-#include "listeners/attributelistener.h"
-#include "listeners/playerdeathlistener.h"
-
-#include <string>
-
-#include "localconsts.h"
-
-class Window;
-
-class DialogsManager final : public AttributeListener,
- public PlayerDeathListener
-{
- public:
- DialogsManager();
-
- virtual ~DialogsManager()
- { }
-
- A_DELETE_COPY(DialogsManager)
-
- static void closeDialogs();
-
- static void createUpdaterWindow();
-
- static Window *openErrorDialog(const std::string &header,
- const std::string &message,
- const Modal modal) RETURNS_NONNULL;
-
- void playerDeath() override final;
-
- void attributeChanged(const AttributesT id,
- const int64_t oldVal,
- const int64_t newVal) override final;
-};
-
-extern DialogsManager *dialogsManager;
-
-#endif // GUI_DIALOGSMANAGER_H
diff --git a/src/gui/focushandler.cpp b/src/gui/focushandler.cpp
deleted file mode 100644
index ebfc988ac..000000000
--- a/src/gui/focushandler.cpp
+++ /dev/null
@@ -1,621 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/focushandler.h"
-
-#include "gui/gui.h"
-
-#include "gui/widgets/window.h"
-
-#include "listeners/focuslistener.h"
-
-#include "utils/foreach.h"
-
-#include "debug.h"
-
-FocusHandler::FocusHandler() :
- mWidgets(),
- mFocusedWidget(nullptr),
- mModalFocusedWidget(nullptr),
- mModalMouseInputFocusedWidget(nullptr),
- mDraggedWidget(nullptr),
- mLastWidgetWithMouse(nullptr),
- mLastWidgetWithModalFocus(nullptr),
- mLastWidgetWithModalMouseInputFocus(nullptr),
- mLastWidgetPressed(nullptr),
- mModalStack()
-{
-}
-
-void FocusHandler::requestModalFocus(Widget *const widget)
-{
- /* If there is another widget with modal focus, remove its modal focus
- * and put it on the modal widget stack.
- */
- if ((mModalFocusedWidget != nullptr) && mModalFocusedWidget != widget)
- {
- mModalStack.push_front(mModalFocusedWidget);
- mModalFocusedWidget = nullptr;
- }
-
- mModalFocusedWidget = widget;
- if ((mFocusedWidget != nullptr) && !mFocusedWidget->isModalFocused())
- focusNone();
-}
-
-void FocusHandler::releaseModalFocus(Widget *const widget)
-{
- mModalStack.remove(widget);
-
- if (mModalFocusedWidget == widget)
- {
- mModalFocusedWidget = nullptr;
-
- /* Check if there were any previously modal widgets that'd still like
- * to regain their modal focus.
- */
- if (!mModalStack.empty())
- {
- requestModalFocus(mModalStack.front());
- mModalStack.pop_front();
- }
- }
-}
-
-void FocusHandler::remove(Widget *const widget)
-{
- releaseModalFocus(widget);
-
- if (isFocused(widget))
- mFocusedWidget = nullptr;
-
- FOR_EACH (WidgetIterator, iter, mWidgets)
- {
- if ((*iter) == widget)
- {
- mWidgets.erase(iter);
- break;
- }
- }
-
- if (mDraggedWidget == widget)
- {
- mDraggedWidget = nullptr;
- return;
- }
-
- if (mLastWidgetWithMouse == widget)
- {
- mLastWidgetWithMouse = nullptr;
- return;
- }
-
- if (mLastWidgetWithModalFocus == widget)
- {
- mLastWidgetWithModalFocus = nullptr;
- return;
- }
-
- if (mLastWidgetWithModalMouseInputFocus == widget)
- {
- mLastWidgetWithModalMouseInputFocus = nullptr;
- return;
- }
-
- if (mLastWidgetPressed == widget)
- {
- mLastWidgetPressed = nullptr;
- return;
- }
-}
-
-void FocusHandler::tabNext()
-{
- if (mFocusedWidget != nullptr)
- {
- if (!mFocusedWidget->isTabOutEnabled())
- return;
- }
-
- if (mWidgets.empty())
- {
- mFocusedWidget = nullptr;
- return;
- }
-
- int i;
- int focusedWidget = -1;
- const int sz = CAST_S32(mWidgets.size());
- for (i = 0; i < sz; ++ i)
- {
- if (mWidgets[i] == mFocusedWidget)
- focusedWidget = i;
- }
- const int focused = focusedWidget;
- bool done = false;
-
- // i is a counter that ensures that the following loop
- // won't get stuck in an infinite loop
- i = sz;
- do
- {
- ++ focusedWidget;
-
- if (i == 0)
- {
- focusedWidget = -1;
- break;
- }
-
- -- i;
-
- if (focusedWidget >= sz)
- focusedWidget = 0;
-
- if (focusedWidget == focused)
- return;
-
- const Widget *const widget = mWidgets.at(focusedWidget);
- if (widget->isFocusable() && widget->isTabInEnabled() &&
- ((mModalFocusedWidget == nullptr) || widget->isModalFocused()))
- {
- done = true;
- }
- }
- while (!done);
-
- if (focusedWidget >= 0)
- {
- mFocusedWidget = mWidgets.at(focusedWidget);
- Event focusEvent(mFocusedWidget);
- distributeFocusGainedEvent(focusEvent);
- }
-
- if (focused >= 0)
- {
- Event focusEvent(mWidgets.at(focused));
- distributeFocusLostEvent(focusEvent);
- }
-
- checkForWindow();
-}
-
-void FocusHandler::tabPrevious()
-{
- if (mFocusedWidget != nullptr)
- {
- if (!mFocusedWidget->isTabOutEnabled())
- return;
- }
-
- if (mWidgets.empty())
- {
- mFocusedWidget = nullptr;
- return;
- }
-
- int i;
- int focusedWidget = -1;
- const int sz = CAST_S32(mWidgets.size());
- for (i = 0; i < sz; ++ i)
- {
- if (mWidgets[i] == mFocusedWidget)
- focusedWidget = i;
- }
- const int focused = focusedWidget;
- bool done = false;
-
- // i is a counter that ensures that the following loop
- // won't get stuck in an infinite loop
- i = sz;
- do
- {
- -- focusedWidget;
-
- if (i == 0)
- {
- focusedWidget = -1;
- break;
- }
-
- -- i;
-
- if (focusedWidget <= 0)
- focusedWidget = sz - 1;
-
- if (focusedWidget == focused)
- return;
-
- const Widget *const widget = mWidgets.at(focusedWidget);
- if (widget->isFocusable() && widget->isTabInEnabled() &&
- ((mModalFocusedWidget == nullptr) || widget->isModalFocused()))
- {
- done = true;
- }
- }
- while (!done);
-
- if (focusedWidget >= 0)
- {
- mFocusedWidget = mWidgets.at(focusedWidget);
- Event focusEvent(mFocusedWidget);
- distributeFocusGainedEvent(focusEvent);
- }
-
- if (focused >= 0)
- {
- Event focusEvent(mWidgets.at(focused));
- distributeFocusLostEvent(focusEvent);
- }
-
- checkForWindow();
-}
-
-void FocusHandler::checkForWindow() const
-{
- if (mFocusedWidget != nullptr)
- {
- Widget *widget = mFocusedWidget->getParent();
-
- while (widget != nullptr)
- {
- Window *const window = dynamic_cast<Window*>(widget);
-
- if (window != nullptr)
- {
- window->requestMoveToTop();
- break;
- }
-
- widget = widget->getParent();
- }
- }
-}
-
-void FocusHandler::distributeFocusGainedEvent(const Event &focusEvent)
-{
- if (gui != nullptr)
- gui->distributeGlobalFocusGainedEvent(focusEvent);
-
- const Widget *const sourceWidget = focusEvent.getSource();
-
- if (sourceWidget == nullptr)
- return;
- std::list<FocusListener*> focusListeners
- = sourceWidget->getFocusListeners();
-
- // Send the event to all focus listeners of the widget.
- for (std::list<FocusListener*>::const_iterator
- it = focusListeners.begin();
- it != focusListeners.end();
- ++ it)
- {
- (*it)->focusGained(focusEvent);
- }
-}
-
-void FocusHandler::requestFocus(const Widget *const widget)
-{
- if ((widget == nullptr) || widget == mFocusedWidget)
- return;
-
- int toBeFocusedIndex = -1;
- for (unsigned int i = 0, fsz = CAST_U32(
- mWidgets.size()); i < fsz; ++i)
- {
- if (mWidgets[i] == widget)
- {
- toBeFocusedIndex = i;
- break;
- }
- }
-
- if (toBeFocusedIndex < 0)
- return;
-
- Widget *const oldFocused = mFocusedWidget;
-
- if (oldFocused != widget)
- {
- mFocusedWidget = mWidgets.at(toBeFocusedIndex);
-
- if (oldFocused != nullptr)
- {
- Event focusEvent(oldFocused);
- distributeFocusLostEvent(focusEvent);
- }
-
- Event focusEvent(mWidgets.at(toBeFocusedIndex));
- distributeFocusGainedEvent(focusEvent);
- }
-}
-
-void FocusHandler::requestModalMouseInputFocus(Widget *const widget)
-{
- if ((mModalMouseInputFocusedWidget != nullptr)
- && mModalMouseInputFocusedWidget != widget)
- {
- return;
- }
-
- mModalMouseInputFocusedWidget = widget;
-}
-
-void FocusHandler::releaseModalMouseInputFocus(const Widget *const widget)
-{
- if (mModalMouseInputFocusedWidget == widget)
- mModalMouseInputFocusedWidget = nullptr;
-}
-
-Widget* FocusHandler::getFocused() const
-{
- return mFocusedWidget;
-}
-
-Widget* FocusHandler::getModalFocused() const
-{
- return mModalFocusedWidget;
-}
-
-Widget* FocusHandler::getModalMouseInputFocused() const
-{
- return mModalMouseInputFocusedWidget;
-}
-
-void FocusHandler::focusNext()
-{
- int i;
- int focusedWidget = -1;
- const int sz = CAST_S32(mWidgets.size());
- for (i = 0; i < sz; ++i)
- {
- if (mWidgets[i] == mFocusedWidget)
- focusedWidget = i;
- }
- const int focused = focusedWidget;
-
- // i is a counter that ensures that the following loop
- // won't get stuck in an infinite loop
- i = sz;
- do
- {
- ++ focusedWidget;
-
- if (i == 0)
- {
- focusedWidget = -1;
- break;
- }
-
- -- i;
-
- if (focusedWidget >= sz)
- focusedWidget = 0;
-
- if (focusedWidget == focused)
- return;
- }
- while (!mWidgets.at(focusedWidget)->isFocusable());
-
- if (focusedWidget >= 0)
- {
- mFocusedWidget = mWidgets.at(focusedWidget);
-
- Event focusEvent(mFocusedWidget);
- distributeFocusGainedEvent(focusEvent);
- }
-
- if (focused >= 0)
- {
- Event focusEvent(mWidgets.at(focused));
- distributeFocusLostEvent(focusEvent);
- }
-}
-
-void FocusHandler::focusPrevious()
-{
- if (mWidgets.empty())
- {
- mFocusedWidget = nullptr;
- return;
- }
-
- int i;
- int focusedWidget = -1;
- const int sz = CAST_S32(mWidgets.size());
- for (i = 0; i < sz; ++ i)
- {
- if (mWidgets[i] == mFocusedWidget)
- focusedWidget = i;
- }
- const int focused = focusedWidget;
-
- // i is a counter that ensures that the following loop
- // won't get stuck in an infinite loop
- i = sz;
- do
- {
- -- focusedWidget;
-
- if (i == 0)
- {
- focusedWidget = -1;
- break;
- }
-
- -- i;
-
- if (focusedWidget <= 0)
- focusedWidget = sz - 1;
-
- if (focusedWidget == focused)
- return;
- }
- while (!mWidgets.at(focusedWidget)->isFocusable());
-
- if (focusedWidget >= 0)
- {
- mFocusedWidget = mWidgets.at(focusedWidget);
- Event focusEvent(mFocusedWidget);
- distributeFocusGainedEvent(focusEvent);
- }
-
- if (focused >= 0)
- {
- Event focusEvent(mWidgets.at(focused));
- distributeFocusLostEvent(focusEvent);
- }
-}
-
-bool FocusHandler::isFocused(const Widget *const widget) const
-{
- return mFocusedWidget == widget;
-}
-
-void FocusHandler::add(Widget *const widget)
-{
- mWidgets.push_back(widget);
-}
-
-void FocusHandler::focusNone()
-{
- if (mFocusedWidget != nullptr)
- {
- Widget *const focused = mFocusedWidget;
- mFocusedWidget = nullptr;
-
- Event focusEvent(focused);
- distributeFocusLostEvent(focusEvent);
- }
-}
-
-void FocusHandler::distributeFocusLostEvent(const Event& focusEvent)
-{
- const Widget *const sourceWidget = focusEvent.getSource();
- if (sourceWidget == nullptr)
- return;
-
- std::list<FocusListener*> focusListeners
- = sourceWidget->getFocusListeners();
-
- // Send the event to all focus listeners of the widget.
- for (std::list<FocusListener*>::const_iterator
- it = focusListeners.begin();
- it != focusListeners.end();
- ++ it)
- {
- (*it)->focusLost(focusEvent);
- }
-}
-
-Widget* FocusHandler::getDraggedWidget() const
-{
- return mDraggedWidget;
-}
-
-void FocusHandler::setDraggedWidget(Widget *const draggedWidget)
-{
- mDraggedWidget = draggedWidget;
-}
-
-Widget* FocusHandler::getLastWidgetWithMouse() const
-{
- return mLastWidgetWithMouse;
-}
-
-void FocusHandler::setLastWidgetWithMouse(Widget *const lastWidgetWithMouse)
-{
- mLastWidgetWithMouse = lastWidgetWithMouse;
-}
-
-Widget* FocusHandler::getLastWidgetWithModalFocus() const
-{
- return mLastWidgetWithModalFocus;
-}
-
-void FocusHandler::setLastWidgetWithModalFocus(Widget *const widget)
-{
- mLastWidgetWithModalFocus = widget;
-}
-
-Widget* FocusHandler::getLastWidgetWithModalMouseInputFocus() const
-{
- return mLastWidgetWithModalMouseInputFocus;
-}
-
-void FocusHandler::setLastWidgetWithModalMouseInputFocus(Widget *const widget)
-{
- mLastWidgetWithModalMouseInputFocus = widget;
-}
-
-Widget* FocusHandler::getLastWidgetPressed() const
-{
- return mLastWidgetPressed;
-}
-
-void FocusHandler::setLastWidgetPressed(Widget *const lastWidgetPressed)
-{
- mLastWidgetPressed = lastWidgetPressed;
-}
diff --git a/src/gui/focushandler.h b/src/gui/focushandler.h
deleted file mode 100644
index 248ae8f71..000000000
--- a/src/gui/focushandler.h
+++ /dev/null
@@ -1,410 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_FOCUSHANDLER_H
-#define GUI_FOCUSHANDLER_H
-
-#include "utils/vector.h"
-
-#include <list>
-
-#include "localconsts.h"
-
-class Event;
-class Widget;
-
-/**
- * The focus handler. This focus handler does exactly the same as the Guichan
- * focus handler, but keeps a stack of modal widgets to be able to handle
- * multiple modal focus requests.
- */
-class FocusHandler final
-{
- public:
- FocusHandler();
-
- A_DELETE_COPY(FocusHandler)
-
- /**
- * Requests focus for a widget. Focus will only be granted to a widget
- * if it's focusable and if no other widget has modal focus.
- * If a widget receives focus a focus event will be sent to the
- * focus listeners of the widget.
- *
- * @param widget The widget to request focus for.
- * @see isFocused, Widget::requestFocus
- */
- void requestFocus(const Widget *const widget);
-
- /**
- * Requests modal focus for a widget. Focus will only be granted
- * to a widget if it's focusable and if no other widget has modal
- * focus.
- *
- * @param widget The widget to request modal focus for.
- * @throws Exception when another widget already has modal focus.
- * @see releaseModalFocus, Widget::requestModalFocus
- */
- void requestModalFocus(Widget *const widget);
-
- /**
- * Requests modal mouse input focus for a widget. Focus will only
- * be granted to a widget if it's focusable and if no other widget
- * has modal mouse input focus.
- *
- * Modal mouse input focus means no other widget then the widget with
- * modal mouse input focus will receive mouse input. The widget with
- * modal mouse input focus will also receive mouse input no matter what
- * the mouse input is or where the mouse input occurs.
- *
- * @param widget The widget to focus for modal mouse input focus.
- * @throws Exception when another widget already has modal mouse input
- * focus.
- * @see releaseModalMouseInputFocus, Widget::requestModalMouseInputFocus
- */
- void requestModalMouseInputFocus(Widget *const widget);
-
- /**
- * Releases modal focus if the widget has modal focus.
- * If the widget doesn't have modal focus no relase will occur.
- *
- * @param widget The widget to release modal focus for.
- * @see reuqestModalFocus, Widget::releaseModalFocus
- */
- void releaseModalFocus(Widget *const widget);
-
- /**
- * Releases modal mouse input focus if the widget has modal mouse input
- * focus. If the widget doesn't have modal mouse input focus no relase
- * will occur.
- *
- * @param widget the widget to release modal mouse input focus for.
- * @see requestModalMouseInputFocus, Widget::releaseModalMouseInputFocus
- */
- void releaseModalMouseInputFocus(const Widget *const widget);
-
- /**
- * Checks if a widget is focused.
- *
- * @param widget The widget to check.
- * @return True if the widget is focused, false otherwise.
- * @see Widget::isFocused
- */
- bool isFocused(const Widget *const widget) const;
-
- /**
- * Gets the widget with focus.
- *
- * @return The widget with focus. NULL if no widget has focus.
- */
- Widget* getFocused() const A_WARN_UNUSED;
-
- /**
- * Gets the widget with modal focus.
- *
- * @return The widget with modal focus. NULL if no widget has
- * modal focus.
- */
- Widget* getModalFocused() const A_WARN_UNUSED;
-
- /**
- * Gets the widget with modal mouse input focus.
- *
- * @return The widget with modal mouse input focus. NULL if
- * no widget has modal mouse input focus.
- */
- Widget* getModalMouseInputFocused() const A_WARN_UNUSED;
-
- /**
- * Focuses the next widget added to a conainer.
- * If no widget has focus the first widget gets focus. The order
- * in which the widgets are focused is determined by the order
- * they were added to a container.
- *
- * @see focusPrevious
- */
- void focusNext();
-
- /**
- * Focuses the previous widget added to a contaienr.
- * If no widget has focus the first widget gets focus. The order
- * in which the widgets are focused is determined by the order
- * they were added to a container.
- *
- * @see focusNext
- */
- void focusPrevious();
-
- /**
- * Adds a widget to by handles by the focus handler.
- *
- * @param widget The widget to add.
- * @see remove
- */
- void add(Widget *const widget);
-
- /**
- * Removes a widget from the focus handler.
- *
- * @param widget The widget to remove.
- * @see add
- */
- void remove(Widget *const widget);
-
- /**
- * Focuses nothing. A focus event will also be sent to the
- * focused widget's focus listeners if a widget has focus.
- */
- void focusNone();
-
- /**
- * Focuses the next widget which allows tabbing in unless
- * the current focused Widget disallows tabbing out.
- *
- * @see tabPrevious
- */
- void tabNext();
-
- /**
- * Focuses the previous widget which allows tabbing in unless
- * current focused widget disallows tabbing out.
- *
- * @see tabNext
- */
- void tabPrevious();
-
- /**
- * Gets the widget being dragged. Used by the Gui class to
- * keep track of the dragged widget.
- *
- * @return the widget being dragged.
- * @see setDraggedWidget
- */
- Widget* getDraggedWidget() const A_WARN_UNUSED;
-
- /**
- * Sets the widget being dragged. Used by the Gui class to
- * keep track of the dragged widget.
- *
- * @param draggedWidget The widget being dragged.
- * @see getDraggedWidget
- */
- void setDraggedWidget(Widget *const draggedWidget);
-
- /**
- * Gets the last widget with the mouse. Used by the Gui class
- * to keep track the last widget with the mouse.
- *
- * @return The last widget with the mouse.
- * @see setLastWidgetWithMouse
- */
- Widget* getLastWidgetWithMouse() const A_WARN_UNUSED;
-
- /**
- * Sets the last widget with the mouse. Used by the Gui class
- * to keep track the last widget with the mouse.
- *
- * @param lastWidgetWithMouse The last widget with the mouse.
- * @see getLastWidgetWithMouse
- */
- void setLastWidgetWithMouse(Widget *const lastWidgetWithMouse);
-
- /**
- * Gets the last widget with modal focus.
- *
- * @return The last widget with modal focus.
- * @see setLastWidgetWithModalFocus
- */
- Widget* getLastWidgetWithModalFocus() const A_WARN_UNUSED;
-
- /**
- * Sets the last widget with modal focus.
- *
- * @param widget The last widget with modal focus.
- * @see getLastWidgetWithModalFocus
- */
- void setLastWidgetWithModalFocus(Widget *const widget);
-
- /**
- * Gets the last widget with modal mouse input focus.
- *
- * @return The last widget with modal mouse input focus.
- * @see setLastWidgetWithModalMouseInputFocus
- */
- Widget* getLastWidgetWithModalMouseInputFocus() const A_WARN_UNUSED;
-
- /**
- * Sets the last widget with modal mouse input focus.
- *
- * @param widget The last widget with modal mouse input focus.
- * @see getLastWidgetWithModalMouseInputFocus
- */
- void setLastWidgetWithModalMouseInputFocus(Widget *const widget);
-
- /**
- * Gets the last widget pressed. Used by the Gui class to keep track
- * of pressed widgets.
- *
- * @return The last widget pressed.
- * @see setLastWidgetPressed
- */
- Widget* getLastWidgetPressed() const A_WARN_UNUSED;
-
- /**
- * Sets the last widget pressed. Used by the Gui class to keep track
- * of pressed widgets.
- *
- * @param lastWidgetPressed The last widget pressed.
- * @see getLastWidgetPressed
- */
- void setLastWidgetPressed(Widget *const lastWidgetPressed);
-
- private:
- /**
- * Checks to see if the widget tabbed to is in a window, and if it is,
- * it requests the window be moved to the top.
- */
- void checkForWindow() const;
-
- /**
- * Distributes a focus lost event.
- *
- * @param focusEvent the event to distribute.
- */
- static void distributeFocusLostEvent(const Event& focusEvent);
-
- /**
- * Distributes a focus gained event.
- *
- * @param focusEvent the event to distribute.
- */
- static void distributeFocusGainedEvent(const Event& focusEvent);
-
- /**
- * Typedef.
- */
- typedef STD_VECTOR<Widget*> WidgetVector;
-
- /**
- * Typedef.
- */
- typedef WidgetVector::iterator WidgetIterator;
-
- /**
- * Holds the widgets currently being handled by the
- * focus handler.
- */
- WidgetVector mWidgets;
-
- /**
- * Holds the focused widget. NULL if no widget has focus.
- */
- Widget* mFocusedWidget;
-
- /**
- * Holds the modal focused widget. NULL if no widget has
- * modal focused.
- */
- Widget* mModalFocusedWidget;
-
- /**
- * Holds the modal mouse input focused widget. NULL if no widget
- * is being dragged.
- */
- Widget* mModalMouseInputFocusedWidget;
-
- /**
- * Holds the dragged widget. NULL if no widget is
- * being dragged.
- */
- Widget* mDraggedWidget;
-
- /**
- * Holds the last widget with the mouse.
- */
- Widget* mLastWidgetWithMouse;
-
- /**
- * Holds the last widget with modal focus.
- */
- Widget* mLastWidgetWithModalFocus;
-
- /**
- * Holds the last widget with modal mouse input focus.
- */
- Widget* mLastWidgetWithModalMouseInputFocus;
-
- /**
- * Holds the last widget pressed.
- */
- Widget* mLastWidgetPressed;
-
- /**
- * Stack of widgets that have requested modal forcus.
- */
- std::list<Widget*> mModalStack;
-};
-
-#endif // GUI_FOCUSHANDLER_H
diff --git a/src/gui/fonts/font.cpp b/src/gui/fonts/font.cpp
deleted file mode 100644
index 2ac2bcb4a..000000000
--- a/src/gui/fonts/font.cpp
+++ /dev/null
@@ -1,499 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2009 Aethyra Development Team
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/fonts/font.h"
-
-#include "fs/files.h"
-#include "fs/paths.h"
-
-#include "fs/virtfs/tools.h"
-#ifdef USE_SDL2
-#include "fs/virtfs/rwops.h"
-#endif // USE_SDL2
-
-#include "gui/fonts/textchunk.h"
-
-#include "render/graphics.h"
-
-#include "resources/imagehelper.h"
-
-#include "resources/image/image.h"
-
-#include "utils/checkutils.h"
-#include "utils/delete2.h"
-#include "utils/sdlcheckutils.h"
-#include "utils/stringutils.h"
-#include "utils/timer.h"
-
-#include "debug.h"
-
-const unsigned int CACHE_SIZE = 256;
-const unsigned int CACHE_SIZE_SMALL1 = 2;
-const unsigned int CACHE_SIZE_SMALL2 = 50;
-const unsigned int CACHE_SIZE_SMALL3 = 170;
-const unsigned int CLEAN_TIME = 7;
-
-bool Font::mSoftMode(false);
-
-extern char *strBuf;
-
-static int fontCounter;
-
-Font::Font(std::string filename,
- int size,
- const int style) :
- mFont(nullptr),
- mCreateCounter(0),
- mDeleteCounter(0),
- mCleanTime(cur_time + CLEAN_TIME)
-{
- if (fontCounter == 0)
- {
- mSoftMode = imageHelper->useOpenGL() == RENDER_SOFTWARE;
- if (TTF_Init() == -1)
- {
- logger->error("Unable to initialize SDL_ttf: " +
- std::string(SDL_GetError()));
- }
- }
-
- if (size < 4)
- {
- reportAlways("Error: requested load font %s with size %d",
- filename.c_str(),
- size);
- size = 4;
- }
-
- if (fontCounter == 0)
- {
- strBuf = new char[65535];
- memset(strBuf, 0, 65535);
- }
-
- ++fontCounter;
-
- fixDirSeparators(filename);
- logger->log("Attempt to load font: %s",
- filename.c_str());
- mFont = openFont(filename.c_str(), size);
-
- if (mFont == nullptr)
- {
- logger->log("Error normal loading font " + filename);
-
- filename = "fonts/dejavusans.ttf";
- mFont = openFont(fixDirSeparators(filename).c_str(), size);
- if (mFont == nullptr)
- {
-#ifdef UNITTESTS
- reportAlways("Font load failed %s",
- filename.c_str());
-#endif // UNITTESTS
- logger->error("Font::Font: " +
- std::string(SDL_GetError()));
- }
- else
- {
- logger->log("Loaded fallback font %s, %d",
- filename.c_str(),
- size);
- }
- }
- else
- {
- logger->log("Loaded font %s, %d",
- filename.c_str(),
- size);
- }
-
- TTF_SetFontStyle(mFont, style);
-}
-
-Font::~Font()
-{
- TTF_CloseFont(mFont);
- mFont = nullptr;
- --fontCounter;
- clear();
-
- if (fontCounter == 0)
- {
- TTF_Quit();
- delete []strBuf;
- }
-}
-
-TTF_Font *Font::openFont(const char *const name,
- const int size)
-{
-#ifdef USE_SDL2
- SDL_RWops *const rw = VirtFs::rwopsOpenRead(name);
- if (rw)
- {
- logger->log("Loading virtfs font file: %s",
- name);
- return TTF_OpenFontIndexRW(rw, 1, size, 0);
- }
-#endif
- const std::string path = VirtFs::getPath(name);
- if (Files::existsLocal(path) == false)
- {
-#ifndef UNITTESTS
- // +++ in future need trigger assert in unit tests here too
- reportAlways("Font::openFont font not exists: %s",
- path.c_str());
-#endif // UNITTESTS
- return nullptr;
- }
- logger->log("Loading physical font file: %s",
- path.c_str());
- return TTF_OpenFontIndex(path.c_str(),
- size, 0);
-}
-
-void Font::loadFont(std::string filename,
- const int size,
- const int style)
-{
- if (fontCounter == 0 && TTF_Init() == -1)
- {
- logger->log("Unable to initialize SDL_ttf: " +
- std::string(SDL_GetError()));
- return;
- }
-
- fixDirSeparators(filename);
- TTF_Font *const font = openFont(filename.c_str(), size);
-
- if (font == nullptr)
- {
- logger->log("Font::Font: " +
- std::string(SDL_GetError()));
- return;
- }
-
- if (mFont != nullptr)
- TTF_CloseFont(mFont);
-
- mFont = font;
- TTF_SetFontStyle(mFont, style);
- clear();
-}
-
-void Font::clear()
-{
- for (size_t f = 0; f < CACHES_NUMBER; f ++)
- mCache[f].clear();
-}
-
-void Font::drawString(Graphics *const graphics,
- Color col,
- const Color &col2,
- const std::string &text,
- const int x, const int y)
-{
- BLOCK_START("Font::drawString")
- if (text.empty())
- {
- BLOCK_END("Font::drawString")
- return;
- }
-
-// Color col = graphics->getColor();
-// const Color &col2 = graphics->getColor2();
- const float alpha = static_cast<float>(col.a) / 255.0F;
-
- /* The alpha value is ignored at string generation so avoid caching the
- * same text with different alpha values.
- */
- col.a = 255;
-
- const unsigned char chr = text[0];
- TextChunkList *const cache = &mCache[chr];
-
- std::map<TextChunkSmall, TextChunk*> &search = cache->search;
- std::map<TextChunkSmall, TextChunk*>::iterator i
- = search.find(TextChunkSmall(text, col, col2));
- if (i != search.end())
- {
- TextChunk *const chunk2 = (*i).second;
- cache->moveToFirst(chunk2);
- Image *const image = chunk2->img;
- if (image != nullptr)
- {
- image->setAlpha(alpha);
- graphics->drawImage(image, x, y);
- }
- }
- else
- {
- if (cache->size >= CACHE_SIZE)
- {
-#ifdef DEBUG_FONT_COUNTERS
- mDeleteCounter ++;
-#endif // DEBUG_FONT_COUNTERS
-
- cache->removeBack();
- }
-#ifdef DEBUG_FONT_COUNTERS
- mCreateCounter ++;
-#endif // DEBUG_FONT_COUNTERS
-
- TextChunk *chunk2 = new TextChunk(text, col, col2, this);
-
- chunk2->generate(mFont, alpha);
- cache->insertFirst(chunk2);
-
- const Image *const image = chunk2->img;
- if (image != nullptr)
- graphics->drawImage(image, x, y);
- }
- BLOCK_END("Font::drawString")
-}
-
-void Font::slowLogic(const int rnd)
-{
- BLOCK_START("Font::slowLogic")
- if (mCleanTime == 0)
- {
- mCleanTime = cur_time + CLEAN_TIME + rnd;
- }
- else if (mCleanTime < cur_time)
- {
- doClean();
- mCleanTime = cur_time + CLEAN_TIME + rnd;
- }
- BLOCK_END("Font::slowLogic")
-}
-
-int Font::getWidth(const std::string &text) const
-{
- if (text.empty())
- return 0;
-
- const unsigned char chr = text[0];
- TextChunkList *const cache = &mCache[chr];
-
- std::map<std::string, TextChunk*> &search = cache->searchWidth;
- std::map<std::string, TextChunk*>::iterator i = search.find(text);
- if (i != search.end())
- {
- TextChunk *const chunk = (*i).second;
- cache->moveToFirst(chunk);
- const Image *const image = chunk->img;
- if (image != nullptr)
- return image->getWidth();
- return 0;
- }
-
- // if string was not drawed
- int w, h;
- getSafeUtf8String(text, strBuf);
- TTF_SizeUTF8(mFont, strBuf, &w, &h);
- return w;
-}
-
-int Font::getHeight() const
-{
- return TTF_FontHeight(mFont);
-}
-
-void Font::doClean()
-{
- for (unsigned int f = 0; f < CACHES_NUMBER; f ++)
- {
- TextChunkList *const cache = &mCache[f];
- const size_t size = CAST_SIZE(cache->size);
-#ifdef DEBUG_FONT_COUNTERS
- logger->log("ptr: %u, size: %ld", f, size);
-#endif // DEBUG_FONT_COUNTERS
-
- if (size > CACHE_SIZE_SMALL3)
- {
-#ifdef DEBUG_FONT_COUNTERS
- mDeleteCounter += 100;
-#endif // DEBUG_FONT_COUNTERS
-
- cache->removeBack(100);
-#ifdef DEBUG_FONT_COUNTERS
- logger->log("delete3");
-#endif // DEBUG_FONT_COUNTERS
- }
- else if (size > CACHE_SIZE_SMALL2)
- {
-#ifdef DEBUG_FONT_COUNTERS
- mDeleteCounter += 20;
-#endif // DEBUG_FONT_COUNTERS
-
- cache->removeBack(20);
-#ifdef DEBUG_FONT_COUNTERS
- logger->log("delete2");
-#endif // DEBUG_FONT_COUNTERS
- }
- else if (size > CACHE_SIZE_SMALL1)
- {
-#ifdef DEBUG_FONT_COUNTERS
- mDeleteCounter ++;
-#endif // DEBUG_FONT_COUNTERS
-
- cache->removeBack();
-#ifdef DEBUG_FONT_COUNTERS
- logger->log("delete1");
-#endif // DEBUG_FONT_COUNTERS
- }
- }
-}
-
-int Font::getStringIndexAt(const std::string& text, const int x) const
-{
- const size_t sz = text.size();
- for (size_t i = 0; i < sz; ++i)
- {
- if (getWidth(text.substr(0, i)) > x)
- return CAST_S32(i);
- }
-
- return CAST_S32(sz);
-}
-
-const TextChunkList *Font::getCache() const noexcept2
-{
- return mCache;
-}
-
-void Font::generate(TextChunk &chunk)
-{
- const std::string &text = chunk.text;
- if (text.empty())
- return;
-
- const unsigned char chr = text[0];
- TextChunkList *const cache = &mCache[chr];
- Color &col = chunk.color;
- Color &col2 = chunk.color2;
- const int oldAlpha = col.a;
- col.a = 255;
-
- TextChunkSmall key(text, col, col2);
- std::map<TextChunkSmall, TextChunk*> &search = cache->search;
- std::map<TextChunkSmall, TextChunk*>::iterator i = search.find(key);
- if (i != search.end())
- {
- TextChunk *const chunk2 = (*i).second;
- cache->moveToFirst(chunk2);
-// search.erase(key);
- cache->remove(chunk2);
- chunk.img = chunk2->img;
- chunk2->img = nullptr;
- delete chunk2;
-// logger->log("cached image: " + chunk.text);
- }
- else
- {
- if (cache->size >= CACHE_SIZE)
- {
-#ifdef DEBUG_FONT_COUNTERS
- mDeleteCounter ++;
-#endif // DEBUG_FONT_COUNTERS
-
- cache->removeBack();
- }
-#ifdef DEBUG_FONT_COUNTERS
- mCreateCounter ++;
-#endif // DEBUG_FONT_COUNTERS
-
- const float alpha = static_cast<float>(chunk.color.a) / 255.0F;
- chunk.generate(mFont, alpha);
-// logger->log("generate image: " + chunk.text);
- }
- col.a = oldAlpha;
-}
-
-void Font::insertChunk(TextChunk *const chunk)
-{
- if ((chunk == nullptr) || chunk->text.empty() || (chunk->img == nullptr))
- return;
-// logger->log("insert chunk: text=%s, color: %d,%d,%d",
-// chunk->text.c_str(), chunk->color.r, chunk->color.g, chunk->color.b);
- const unsigned char chr = chunk->text[0];
- TextChunkList *const cache = &mCache[chr];
-
- std::map<TextChunkSmall, TextChunk*> &search = cache->search;
- std::map<TextChunkSmall, TextChunk*>::iterator i
- = search.find(TextChunkSmall(chunk->text,
- chunk->color, chunk->color2));
- if (i != search.end())
- {
- delete2(chunk->img);
- return;
- }
-
- TextChunk *const chunk2 = new TextChunk(chunk->text,
- chunk->color, chunk->color2, chunk->textFont);
- chunk2->img = chunk->img;
- cache->insertFirst(chunk2);
-}
diff --git a/src/gui/fonts/font.h b/src/gui/fonts/font.h
deleted file mode 100644
index 4f3670374..000000000
--- a/src/gui/fonts/font.h
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- * Copyright (C) 2009 Aethyra Development Team
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_FONTS_FONT_H
-#define GUI_FONTS_FONT_H
-
-#include "gui/fonts/textchunklist.h"
-
-PRAGMA48(GCC diagnostic push)
-PRAGMA48(GCC diagnostic ignored "-Wshadow")
-#include <SDL_ttf.h>
-PRAGMA48(GCC diagnostic pop)
-
-#include "localconsts.h"
-
-class Graphics;
-
-const unsigned int CACHES_NUMBER = 256;
-
-/**
- * A wrapper around SDL_ttf for allowing the use of TrueType fonts.
- *
- * <b>NOTE:</b> This class initializes SDL_ttf as necessary.
- */
-class Font final
-{
- public:
- Font(std::string filename,
- int size,
- const int style);
-
- A_DELETE_COPY(Font)
-
- ~Font();
-
- void loadFont(std::string filename,
- const int size,
- const int style) restrict2;
-
- int getWidth(const std::string &text) const restrict2 A_WARN_UNUSED;
-
- int getHeight() const restrict2 A_WARN_UNUSED;
-
- const TextChunkList *getCache() const restrict2 noexcept2
- A_CONST A_WARN_UNUSED;
-
- /**
- * @see Font::drawString
- */
- void drawString(Graphics *restrict const graphics,
- Color col,
- const Color &restrict col2,
- const std::string &restrict text,
- const int x,
- const int y) restrict2 A_NONNULL(2);
-
- void clear() restrict2;
-
- void doClean() restrict2;
-
- void slowLogic(const int rnd) restrict2;
-
- unsigned int getCreateCounter() const restrict2 noexcept2 A_WARN_UNUSED
- { return mCreateCounter; }
-
- unsigned int getDeleteCounter() const restrict2 noexcept2 A_WARN_UNUSED
- { return mDeleteCounter; }
-
- int getStringIndexAt(const std::string &restrict text,
- const int x) const restrict2 A_WARN_UNUSED;
-
- void generate(TextChunk &restrict chunk) restrict2;
-
- void insertChunk(TextChunk *const chunk) restrict2;
-
- static bool mSoftMode;
-
- private:
- static TTF_Font *openFont(const char *restrict const name,
- const int size);
-
- TTF_Font *restrict mFont;
- unsigned int mCreateCounter;
- unsigned int mDeleteCounter;
-
- // Word surfaces cache
- time_t mCleanTime;
- mutable TextChunkList mCache[CACHES_NUMBER];
-};
-
-#ifdef UNITTESTS
-extern int textChunkCnt;
-#endif // UNITTESTS
-
-#endif // GUI_FONTS_FONT_H
diff --git a/src/gui/fonts/textchunk.cpp b/src/gui/fonts/textchunk.cpp
deleted file mode 100644
index 22dcd18dc..000000000
--- a/src/gui/fonts/textchunk.cpp
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2009 Aethyra Development Team
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/fonts/textchunk.h"
-
-#include "sdlshared.h"
-
-#include "gui/fonts/font.h"
-
-#include "resources/surfaceimagehelper.h"
-
-#include "resources/image/image.h"
-
-#include "utils/delete2.h"
-#include "utils/sdlcheckutils.h"
-#include "utils/stringutils.h"
-
-#include "debug.h"
-
-namespace
-{
- const int OUTLINE_SIZE = 1;
-} // namespace
-
-char *restrict strBuf = nullptr;
-
-#ifdef UNITTESTS
-int textChunkCnt = 0;
-#endif // UNITTESTS
-
-TextChunk::TextChunk() :
- img(nullptr),
- textFont(nullptr),
- text(),
- color(),
- color2(),
- prev(nullptr),
- next(nullptr)
-{
-#ifdef UNITTESTS
- textChunkCnt ++;
-#endif // UNITTESTS
-}
-
-TextChunk::TextChunk(const std::string &restrict text0,
- const Color &restrict color0,
- const Color &restrict color1,
- Font *restrict const font) :
- img(nullptr),
- textFont(font),
- text(text0),
- color(color0),
- color2(color1),
- prev(nullptr),
- next(nullptr)
-{
-#ifdef UNITTESTS
- textChunkCnt ++;
-#endif // UNITTESTS
-}
-
-TextChunk::~TextChunk()
-{
- delete2(img);
-#ifdef UNITTESTS
- textChunkCnt --;
-#endif // UNITTESTS
-}
-
-bool TextChunk::operator==(const TextChunk &restrict chunk) const
-{
- return chunk.text == text && chunk.color == color
- && chunk.color2 == color2;
-}
-
-void TextChunk::generate(TTF_Font *restrict const font,
- const float alpha)
-{
- BLOCK_START("TextChunk::generate")
- SDL_Color sdlCol;
- sdlCol.b = CAST_U8(color.b);
- sdlCol.r = CAST_U8(color.r);
- sdlCol.g = CAST_U8(color.g);
-#ifdef USE_SDL2
- sdlCol.a = 255;
-#else // USE_SDL2
-
- sdlCol.unused = 0;
-#endif // USE_SDL2
-
- getSafeUtf8String(text, strBuf);
-
- SDL_Surface *surface = MTTF_RenderUTF8_Blended(
- font, strBuf, sdlCol);
-
- if (surface == nullptr)
- {
- img = nullptr;
- BLOCK_END("TextChunk::generate")
- return;
- }
-
- const int width = surface->w;
- const int height = surface->h;
-
- if (color.r != color2.r || color.g != color2.g
- || color.b != color2.b)
- { // outlining
- SDL_Color sdlCol2;
- SDL_Surface *const background = imageHelper->create32BitSurface(
- width, height);
- if (background == nullptr)
- {
- img = nullptr;
- MSDL_FreeSurface(surface);
- BLOCK_END("TextChunk::generate")
- return;
- }
- sdlCol2.b = CAST_U8(color2.b);
- sdlCol2.r = CAST_U8(color2.r);
- sdlCol2.g = CAST_U8(color2.g);
-#ifdef USE_SDL2
- sdlCol2.a = 255;
-#else // USE_SDL2
-
- sdlCol2.unused = 0;
-#endif // USE_SDL2
-
- SDL_Surface *const surface2 = MTTF_RenderUTF8_Blended(
- font, strBuf, sdlCol2);
- if (surface2 == nullptr)
- {
- img = nullptr;
- MSDL_FreeSurface(surface);
- BLOCK_END("TextChunk::generate")
- return;
- }
- SDL_Rect rect =
- {
- OUTLINE_SIZE,
- 0,
- static_cast<Uint16>(surface->w),
- static_cast<Uint16>(surface->h)
- };
- SurfaceImageHelper::combineSurface(surface2, nullptr,
- background, &rect);
- rect.x = -OUTLINE_SIZE;
- SurfaceImageHelper::combineSurface(surface2, nullptr,
- background, &rect);
- rect.x = 0;
- rect.y = -OUTLINE_SIZE;
- SurfaceImageHelper::combineSurface(surface2, nullptr,
- background, &rect);
- rect.y = OUTLINE_SIZE;
- SurfaceImageHelper::combineSurface(surface2, nullptr,
- background, &rect);
- rect.x = 0;
- rect.y = 0;
- SurfaceImageHelper::combineSurface(surface, nullptr,
- background, &rect);
- MSDL_FreeSurface(surface);
- MSDL_FreeSurface(surface2);
- surface = background;
- }
- img = imageHelper->createTextSurface(
- surface, width, height, alpha);
- MSDL_FreeSurface(surface);
-
- BLOCK_END("TextChunk::generate")
-}
-
-void TextChunk::deleteImage()
-{
- if (textFont != nullptr)
- {
- textFont->insertChunk(this);
- img = nullptr;
- }
- else
- {
- delete2(img);
- }
-}
diff --git a/src/gui/fonts/textchunk.h b/src/gui/fonts/textchunk.h
deleted file mode 100644
index bbd50fdff..000000000
--- a/src/gui/fonts/textchunk.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- * Copyright (C) 2009 Aethyra Development Team
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_FONTS_TEXTCHUNK_H
-#define GUI_FONTS_TEXTCHUNK_H
-
-#include "gui/color.h"
-
-#include <string>
-
-PRAGMA48(GCC diagnostic push)
-PRAGMA48(GCC diagnostic ignored "-Wshadow")
-#include <SDL_ttf.h>
-PRAGMA48(GCC diagnostic pop)
-
-#include "localconsts.h"
-
-class Font;
-class Image;
-
-class TextChunk final
-{
- public:
- TextChunk();
-
- TextChunk(const std::string &restrict text0,
- const Color &restrict color0,
- const Color &restrict color1,
- Font *restrict const font);
-
- A_DELETE_COPY(TextChunk)
-
- ~TextChunk();
-
- bool operator==(const TextChunk &restrict chunk) const restrict2;
-
- void generate(TTF_Font *restrict const font,
- const float alpha) restrict2;
-
- void deleteImage() restrict2;
-
- Image *restrict img;
- Font *restrict textFont;
- std::string text;
- Color color;
- Color color2;
- TextChunk *restrict prev;
- TextChunk *restrict next;
-};
-
-#ifdef UNITTESTS
-extern int textChunkCnt;
-#endif // UNITTESTS
-
-#endif // GUI_FONTS_TEXTCHUNK_H
diff --git a/src/gui/fonts/textchunklist.cpp b/src/gui/fonts/textchunklist.cpp
deleted file mode 100644
index 4ce39406b..000000000
--- a/src/gui/fonts/textchunklist.cpp
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/fonts/textchunklist.h"
-
-#include "gui/fonts/textchunk.h"
-
-#include "debug.h"
-
-TextChunkList::TextChunkList() :
- start(nullptr),
- end(nullptr),
- size(0),
- search(),
- searchWidth()
-{
-}
-
-void TextChunkList::insertFirst(TextChunk *restrict const item)
-{
- TextChunk *restrict const oldFirst = start;
- if (start != nullptr)
- start->prev = item;
- item->prev = nullptr;
- if (oldFirst != nullptr)
- item->next = oldFirst;
- else
- end = item;
- start = item;
- size ++;
- search[TextChunkSmall(item->text, item->color, item->color2)] = item;
- searchWidth[item->text] = item;
-}
-
-void TextChunkList::moveToFirst(TextChunk *restrict const item)
-{
- if (item == start)
- return;
-
- TextChunk *restrict const oldPrev = item->prev;
- if (oldPrev != nullptr)
- oldPrev->next = item->next;
- TextChunk *restrict const oldNext = item->next;
- if (oldNext != nullptr)
- oldNext->prev = item->prev;
- else
- end = oldPrev;
- TextChunk *restrict const oldFirst = start;
- if (start != nullptr)
- start->prev = item;
- item->prev = nullptr;
- item->next = oldFirst;
- start = item;
-}
-
-void TextChunkList::remove(const TextChunk *restrict const item)
-{
- if (item == nullptr)
- return;
-
- TextChunk *restrict const oldPrev = item->prev;
- TextChunk *restrict const oldNext = item->next;
- if (oldPrev != nullptr)
- oldPrev->next = item->next;
- else
- start = oldNext;
- if (oldNext != nullptr)
- oldNext->prev = item->prev;
- else
- end = oldPrev;
-
- search.erase(TextChunkSmall(item->text,
- item->color, item->color2));
- searchWidth.erase(item->text);
- size --;
-}
-
-void TextChunkList::removeBack()
-{
- TextChunk *restrict oldEnd = end;
- if (oldEnd != nullptr)
- {
- end = oldEnd->prev;
- if (end != nullptr)
- end->next = nullptr;
- else
- start = nullptr;
- search.erase(TextChunkSmall(oldEnd->text,
- oldEnd->color, oldEnd->color2));
- searchWidth.erase(oldEnd->text);
- delete oldEnd;
- size --;
- }
-}
-
-void TextChunkList::removeBack(int n)
-{
- TextChunk *restrict item = end;
- while ((n != 0) && (item != nullptr))
- {
- n --;
- TextChunk *oldEnd = item;
- item = item->prev;
- search.erase(TextChunkSmall(oldEnd->text,
- oldEnd->color, oldEnd->color2));
- searchWidth.erase(oldEnd->text);
- delete oldEnd;
- size --;
- }
- if (item != nullptr)
- {
- item->next = nullptr;
- end = item;
- }
- else
- {
- start = nullptr;
- end = nullptr;
- }
-}
-
-void TextChunkList::clear()
-{
- search.clear();
- searchWidth.clear();
- TextChunk *restrict item = start;
- while (item != nullptr)
- {
- TextChunk *restrict const item2 = item->next;
- delete item;
- item = item2;
- }
- start = nullptr;
- end = nullptr;
- size = 0;
-}
diff --git a/src/gui/fonts/textchunklist.h b/src/gui/fonts/textchunklist.h
deleted file mode 100644
index fff198445..000000000
--- a/src/gui/fonts/textchunklist.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_FONTS_TEXTCHUNKLIST_H
-#define GUI_FONTS_TEXTCHUNKLIST_H
-
-#include "gui/fonts/textchunksmall.h"
-
-#include <map>
-
-#include "localconsts.h"
-
-class TextChunk;
-
-class TextChunkList final
-{
- public:
- TextChunkList();
-
- A_DELETE_COPY(TextChunkList)
-
- void insertFirst(TextChunk *restrict const item)
- restrict2 A_NONNULL(2);
-
- void moveToFirst(TextChunk *restrict const item)
- restrict2 A_NONNULL(2);
-
- void remove(const TextChunk *restrict const item) restrict2;
-
- void removeBack() restrict2;
-
- void removeBack(int n) restrict2;
-
- void clear() restrict2;
-
- TextChunk *restrict start;
- TextChunk *restrict end;
- uint32_t size;
- std::map<TextChunkSmall, TextChunk*> search;
- std::map<std::string, TextChunk*> searchWidth;
-};
-
-#endif // GUI_FONTS_TEXTCHUNKLIST_H
diff --git a/src/gui/fonts/textchunksmall.cpp b/src/gui/fonts/textchunksmall.cpp
deleted file mode 100644
index 73e8ad386..000000000
--- a/src/gui/fonts/textchunksmall.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/fonts/textchunksmall.h"
-
-#include "gui/fonts/font.h"
-
-#include "debug.h"
-
-TextChunkSmall::TextChunkSmall(const std::string &text0,
- const Color &color0,
- const Color &color1) :
- text(text0),
- color(color0),
- color2(color1)
-{
-}
-
-TextChunkSmall::TextChunkSmall(const TextChunkSmall &old) :
- text(old.text),
- color(old.color),
- color2(old.color2)
-{
-}
-
-TextChunkSmall &TextChunkSmall::operator=(const TextChunkSmall &chunk)
-{
- text = chunk.text;
- color = chunk.color;
- color2 = chunk.color2;
- return *this;
-}
-
-bool TextChunkSmall::operator==(const TextChunkSmall &chunk) const
-{
- return chunk.text == text &&
- chunk.color == color &&
- chunk.color2 == color2;
-}
-
-bool TextChunkSmall::operator<(const TextChunkSmall &chunk) const
-{
- if (chunk.text != text)
- return chunk.text > text;
-
- const Color &restrict c = chunk.color;
- if (c.r != color.r)
- return c.r > color.r;
- if (c.g != color.g)
- return c.g > color.g;
- if (c.b != color.b)
- return c.b > color.b;
-
- const Color &restrict c2 = chunk.color2;
- if (c2.r != color2.r)
- return c2.r > color2.r;
- if (c2.g != color2.g)
- return c2.g > color2.g;
- if (c2.b != color2.b)
- return c2.b > color2.b;
-
- if (c.a != color.a && Font::mSoftMode)
- return c.a > color.a;
-
- return false;
-}
diff --git a/src/gui/fonts/textchunksmall.h b/src/gui/fonts/textchunksmall.h
deleted file mode 100644
index 0896c3591..000000000
--- a/src/gui/fonts/textchunksmall.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_FONTS_TEXTCHUNKSMALL_H
-#define GUI_FONTS_TEXTCHUNKSMALL_H
-
-#include "gui/color.h"
-
-#include <string>
-
-#include "localconsts.h"
-
-class TextChunkSmall final
-{
- public:
- A_DEFAULT_COPY(TextChunkSmall)
-
- TextChunkSmall(const std::string &restrict text0,
- const Color &restrict color0,
- const Color &restrict color1);
-
- TextChunkSmall(const TextChunkSmall &restrict old);
-
- bool operator==(const TextChunkSmall &restrict chunk) const restrict2;
- bool operator<(const TextChunkSmall &restrict chunk) const restrict2;
- TextChunkSmall &operator=(const TextChunkSmall &restrict chunk)
- restrict2;
- std::string text;
- Color color;
- Color color2;
-};
-#endif // GUI_FONTS_TEXTCHUNKSMALL_H
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
deleted file mode 100644
index 3fab73d0a..000000000
--- a/src/gui/gui.cpp
+++ /dev/null
@@ -1,1515 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/gui.h"
-
-#include "gui/focushandler.h"
-#include "gui/sdlinput.h"
-#include "gui/viewport.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/widgets/label.h"
-#include "gui/widgets/window.h"
-
-#include "gui/widgets/tabs/tab.h"
-
-#ifndef DYECMD
-#include "dragdrop.h"
-#else // DYECMD
-#include "resources/image/image.h"
-#endif // DYECMD
-#include "settings.h"
-
-#include "listeners/focuslistener.h"
-#include "listeners/guiconfiglistener.h"
-#include "listeners/keylistener.h"
-
-#include "input/inputmanager.h"
-
-#include "input/touch/touchmanager.h"
-
-#include "render/renderers.h"
-
-#include "resources/imageset.h"
-
-#include "resources/resourcemanager/resourcemanager.h"
-
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-#include "utils/langs.h"
-#include "utils/sdlsharedhelper.h"
-#include "utils/timer.h"
-
-#include "net/ipc.h"
-
-#include "debug.h"
-
-Gui *gui = nullptr;
-Font *boldFont = nullptr;
-
-Gui::Gui() :
- mTop(nullptr),
- mGraphics(nullptr),
- mInput(nullptr),
- mFocusHandler(new FocusHandler),
- mKeyListeners(),
- mLastMousePressButton(MouseButton::EMPTY),
- mLastMousePressTimeStamp(0U),
- mLastMouseX(0),
- mLastMouseY(0),
- mClickCount(1),
- mLastMouseDragButton(MouseButton::EMPTY),
- mWidgetWithMouseQueue(),
- mConfigListener(new GuiConfigListener(this)),
- mGuiFont(nullptr),
- mInfoParticleFont(nullptr),
- mHelpFont(nullptr),
- mSecureFont(nullptr),
- mNpcFont(nullptr),
- mMouseCursors(nullptr),
- mMouseCursorAlpha(1.0F),
- mMouseInactivityTimer(0),
- mCursorType(Cursor::CURSOR_POINTER),
-#ifdef ANDROID
- mLastMouseRealX(0),
- mLastMouseRealY(0),
-#endif // ANDROID
- mFocusListeners(),
- mForegroundColor(theme->getColor(ThemeColorId::TEXT, 255)),
- mForegroundColor2(theme->getColor(ThemeColorId::TEXT_OUTLINE, 255)),
- mTime(0),
- mTime10(0),
- mCustomCursor(false),
- mDoubleClick(true)
-{
-}
-
-void Gui::postInit(Graphics *const graphics)
-{
- logger->log1("Initializing GUI...");
- // Set graphics
- setGraphics(graphics);
-
- // Set input
- guiInput = new SDLInput;
- setInput(guiInput);
-
- // Set focus handler
- delete mFocusHandler;
- mFocusHandler = new FocusHandler;
-
- // Initialize top GUI widget
- WindowContainer *const guiTop = new WindowContainer(nullptr);
- guiTop->setFocusable(true);
- guiTop->setSize(graphics->mWidth, graphics->mHeight);
- guiTop->setOpaque(Opaque_false);
- Window::setWindowContainer(guiTop);
- setTop(guiTop);
-
- const StringVect langs = getLang();
- const bool isJapan = (!langs.empty() && langs[0].size() > 3
- && langs[0].substr(0, 3) == "ja_");
- const bool isChinese = (!langs.empty() && langs[0].size() > 3
- && langs[0].substr(0, 3) == "zh_");
-
- // Set global font
- const int fontSize = config.getIntValue("fontSize");
- std::string fontFile = config.getValue("font", "");
- if (isJapan)
- {
- fontFile = config.getValue("japanFont", "");
- if (fontFile.empty())
- fontFile = branding.getStringValue("japanFont");
- }
- else if (isChinese)
- {
- fontFile = config.getValue("chinaFont", "");
- if (fontFile.empty())
- fontFile = branding.getStringValue("chinaFont");
- }
- if (fontFile.empty())
- fontFile = branding.getStringValue("font");
-
- mGuiFont = new Font(fontFile, fontSize, TTF_STYLE_NORMAL);
-
- // Set particle font
- fontFile = config.getValue("particleFont", "");
- if (isJapan)
- {
- fontFile = config.getValue("japanFont", "");
- if (fontFile.empty())
- fontFile = branding.getStringValue("japanFont");
- }
- else if (isChinese)
- {
- fontFile = config.getValue("chinaFont", "");
- if (fontFile.empty())
- fontFile = branding.getStringValue("chinaFont");
- }
- if (fontFile.empty())
- fontFile = branding.getStringValue("particleFont");
-
- mInfoParticleFont = new Font(fontFile, fontSize, TTF_STYLE_BOLD);
-
- // Set bold font
- fontFile = config.getValue("boldFont", "");
- if (fontFile.empty())
- fontFile = branding.getStringValue("boldFont");
-
- boldFont = new Font(fontFile, fontSize, TTF_STYLE_NORMAL);
-
- // Set help font
- fontFile = config.getValue("helpFont", "");
- if (fontFile.empty())
- fontFile = branding.getStringValue("helpFont");
-
- mHelpFont = new Font(fontFile, fontSize, TTF_STYLE_NORMAL);
-
- // Set secure font
- fontFile = config.getValue("secureFont", "");
- if (fontFile.empty())
- fontFile = branding.getStringValue("secureFont");
-
- mSecureFont = new Font(fontFile, fontSize, TTF_STYLE_NORMAL);
-
- // Set npc font
- const int npcFontSize = config.getIntValue("npcfontSize");
- fontFile = config.getValue("npcFont", "");
- if (isJapan)
- {
- fontFile = config.getValue("japanFont", "");
- if (fontFile.empty())
- fontFile = branding.getStringValue("japanFont");
- }
- else if (isChinese)
- {
- fontFile = config.getValue("chinaFont", "");
- if (fontFile.empty())
- fontFile = branding.getStringValue("chinaFont");
- }
- if (fontFile.empty())
- fontFile = branding.getStringValue("npcFont");
-
- mNpcFont = new Font(fontFile, npcFontSize, TTF_STYLE_NORMAL);
-
- Widget::setGlobalFont(mGuiFont);
-
- // Initialize mouse cursor and listen for changes to the option
- setUseCustomCursor(config.getBoolValue("customcursor"));
- setDoubleClick(config.getBoolValue("doubleClick"));
- config.addListener("customcursor", mConfigListener);
- config.addListener("doubleClick", mConfigListener);
-}
-
-Gui::~Gui()
-{
- config.removeListeners(mConfigListener);
- delete2(mConfigListener);
-
- if (mMouseCursors != nullptr)
- {
- mMouseCursors->decRef();
- mMouseCursors = nullptr;
- }
-
- if (windowContainer != nullptr)
- windowContainer->slowLogic();
- Widget *top = mTop;
- if (Widget::widgetExists(mTop))
- setTop(nullptr);
- Window::setWindowContainer(nullptr);
- delete top;
-
- delete2(mGuiFont);
- delete2(boldFont);
- delete2(mHelpFont);
- delete2(mSecureFont);
- delete2(mInfoParticleFont);
- delete2(mNpcFont);
- delete2(guiInput);
- delete2(theme);
-
- delete2(mFocusHandler);
- Label::finalCleanup();
- Tab::finalCleanup();
- Widget::cleanGlobalFont();
-}
-
-void Gui::logic()
-{
- BLOCK_START("Gui::logic")
- ResourceManager::clearScheduled();
-
- if (mTop == nullptr)
- {
- BLOCK_END("Gui::logic")
- return;
- }
-
- handleModalFocus();
- handleModalMouseInputFocus();
-
- if (guiInput != nullptr)
- handleMouseInput();
-
- mTop->logic();
- BLOCK_END("Gui::logic")
-}
-
-void Gui::slowLogic()
-{
- BLOCK_START("Gui::slowLogic")
- Palette::advanceGradients();
-
- // Fade out mouse cursor after extended inactivity
- if (mMouseInactivityTimer < 100 * 15)
- {
- ++mMouseInactivityTimer;
- mMouseCursorAlpha = std::min(1.0F, mMouseCursorAlpha + 0.05F);
- }
- else
- {
- mMouseCursorAlpha = std::max(0.0F, mMouseCursorAlpha - 0.005F);
- }
- if (mGuiFont != nullptr)
- mGuiFont->slowLogic(0);
- if (mInfoParticleFont != nullptr)
- mInfoParticleFont->slowLogic(1);
- if (mHelpFont != nullptr)
- mHelpFont->slowLogic(2);
- if (mSecureFont != nullptr)
- mSecureFont->slowLogic(3);
- if (boldFont != nullptr)
- boldFont->slowLogic(4);
- if (mNpcFont != nullptr)
- mNpcFont->slowLogic(5);
- if (windowContainer != nullptr)
- windowContainer->slowLogic();
-
- const time_t time = cur_time;
- if (mTime != time)
- {
- logger->flush();
- if (ipc != nullptr)
- ipc->flush();
- mTime = time;
-
- if (time > mTime10 || mTime10 - time > 10)
- {
- mTime10 = time + 10;
- ResourceManager::cleanOrphans();
- guiInput->simulateMouseMove();
- }
- }
-
- BLOCK_END("Gui::slowLogic")
-}
-
-void Gui::clearFonts()
-{
- if (mGuiFont != nullptr)
- mGuiFont->clear();
- if (mInfoParticleFont != nullptr)
- mInfoParticleFont->clear();
- if (mHelpFont != nullptr)
- mHelpFont->clear();
- if (mSecureFont != nullptr)
- mSecureFont->clear();
- if (boldFont != nullptr)
- boldFont->clear();
- if (mNpcFont != nullptr)
- mNpcFont->clear();
-}
-
-bool Gui::handleInput()
-{
- if (mInput != nullptr)
- return handleKeyInput();
- return false;
-}
-
-bool Gui::handleKeyInput()
-{
- if (guiInput == nullptr)
- return false;
-
- BLOCK_START("Gui::handleKeyInput")
- bool consumed(false);
-
- while (!mInput->isKeyQueueEmpty())
- {
- const KeyInput keyInput = guiInput->dequeueKeyInput();
-
- KeyEvent eventToGlobalKeyListeners(nullptr,
- keyInput.getType(),
- keyInput.getActionId(), keyInput.getKey());
-
-#ifdef USE_SDL2
- if (!keyInput.getText().empty())
- eventToGlobalKeyListeners.setText(keyInput.getText());
-#endif // USE_SDL2
-
- distributeKeyEventToGlobalKeyListeners(
- eventToGlobalKeyListeners);
-
- // If a global key listener consumes the event it will not be
- // sent further to the source of the event.
- if (eventToGlobalKeyListeners.isConsumed())
- {
- consumed = true;
- continue;
- }
-
- if (mFocusHandler != nullptr)
- {
- bool eventConsumed = false;
-
- // Send key inputs to the focused widgets
- if (mFocusHandler->getFocused() != nullptr)
- {
- KeyEvent event(getKeyEventSource(),
- keyInput.getType(),
- keyInput.getActionId(), keyInput.getKey());
-#ifdef USE_SDL2
- if (!keyInput.getText().empty())
- event.setText(keyInput.getText());
-#endif // USE_SDL2
-
- if (!mFocusHandler->getFocused()->isFocusable())
- mFocusHandler->focusNone();
- else
- distributeKeyEvent(event);
-
- eventConsumed = event.isConsumed();
- if (eventConsumed)
- consumed = true;
- }
-
- // If the key event hasn't been consumed and
- // tabbing is enable check for tab press and
- // change focus.
- if (!eventConsumed && keyInput.getActionId()
- == InputAction::GUI_TAB &&
- keyInput.getType() == KeyEventType::PRESSED)
- {
- if (inputManager.isActionActive(InputAction::GUI_MOD))
- mFocusHandler->tabPrevious();
- else
- mFocusHandler->tabNext();
- }
- }
- } // end while
- BLOCK_END("Gui::handleKeyInput")
- return consumed;
-}
-
-void Gui::draw()
-{
- BLOCK_START("Gui::draw 1")
- Widget *const top = getTop();
- if (top == nullptr)
- return;
- mGraphics->pushClipArea(top->getDimension());
-
- if (isBatchDrawRenders(openGLMode))
- {
- top->draw(mGraphics);
- touchManager.draw();
- }
- else
- {
- top->safeDraw(mGraphics);
- touchManager.safeDraw();
- }
-
- int mouseX;
- int mouseY;
- const MouseStateType button = getMouseState(mouseX, mouseY);
-
- if ((settings.mouseFocused ||
- ((button & SDL_BUTTON(1)) != 0)) &&
- mMouseCursors != nullptr &&
- mCustomCursor &&
- mMouseCursorAlpha > 0.0F)
- {
-#ifndef DYECMD
- const Image *const image = dragDrop.getItemImage();
- if (mGuiFont != nullptr)
- {
- const std::string &str = dragDrop.getText();
- if (!str.empty())
- {
- const int posX = mouseX - mGuiFont->getWidth(str) / 2;
- const int posY = mouseY +
- (image != nullptr ? image->mBounds.h / 2 : 0);
- mGuiFont->drawString(mGraphics,
- mForegroundColor, mForegroundColor2,
- str,
- posX, posY);
- }
- }
- if (image != nullptr)
- {
- const int posX = mouseX - (image->mBounds.w / 2);
- const int posY = mouseY - (image->mBounds.h / 2);
- mGraphics->drawImage(image, posX, posY);
- }
-#endif // DYECMD
-
- Image *const mouseCursor = mMouseCursors->get(
- CAST_SIZE(mCursorType));
- if (mouseCursor != nullptr)
- {
- mouseCursor->setAlpha(mMouseCursorAlpha);
- mGraphics->drawImage(mouseCursor, mouseX - 15, mouseY - 17);
- }
- }
-
- mGraphics->popClipArea();
- BLOCK_END("Gui::draw 1")
-}
-
-void Gui::videoResized() const
-{
- WindowContainer *const top = static_cast<WindowContainer *>(getTop());
-
- if (top != nullptr)
- {
- const int oldWidth = top->getWidth();
- const int oldHeight = top->getHeight();
-
- top->setSize(mainGraphics->mWidth, mainGraphics->mHeight);
- top->adjustAfterResize(oldWidth, oldHeight);
- }
-
- if (viewport != nullptr)
- viewport->videoResized();
- Widget::distributeWindowResizeEvent();
-}
-
-void Gui::setUseCustomCursor(const bool customCursor)
-{
- if (settings.options.hideCursor)
- {
- SDL::showCursor(false);
- return;
- }
- if (customCursor != mCustomCursor)
- {
- mCustomCursor = customCursor;
-
- if (mCustomCursor)
- {
- // Hide the SDL mouse cursor
- SDL::showCursor(false);
-
- // Load the mouse cursor
- if (mMouseCursors != nullptr)
- mMouseCursors->decRef();
- mMouseCursors = Theme::getImageSetFromTheme("mouse.png", 40, 40);
-
- if (mMouseCursors == nullptr)
- logger->log("Error: Unable to load mouse cursors.");
- }
- else
- {
- // Show the SDL mouse cursor
- SDL::showCursor(true);
-
- // Unload the mouse cursor
- if (mMouseCursors != nullptr)
- {
- mMouseCursors->decRef();
- mMouseCursors = nullptr;
- }
- }
- }
-}
-
-void Gui::handleMouseMoved(const MouseInput &mouseInput)
-{
- // Check if the mouse leaves the application window.
- if (mTop != nullptr &&
- !mWidgetWithMouseQueue.empty() &&
- (mouseInput.getX() < 0 ||
- mouseInput.getY() < 0 ||
- !mTop->getDimension().isPointInRect(mouseInput.getX(),
- mouseInput.getY())))
- {
- // Distribute an event to all widgets in the
- // "widget with mouse" queue.
- while (!mWidgetWithMouseQueue.empty())
- {
- Widget *const widget = mWidgetWithMouseQueue.front();
-
- if (Widget::widgetExists(widget))
- {
- distributeMouseEvent(widget,
- MouseEventType::EXITED,
- mouseInput.getButton(),
- mouseInput.getX(),
- mouseInput.getY(),
- true,
- true);
- }
-
- mWidgetWithMouseQueue.pop_front();
- }
-
- mMouseInactivityTimer = 0;
- return;
- }
-
- const int mouseX = mouseInput.getX();
- const int mouseY = mouseInput.getY();
- const MouseButtonT button = mouseInput.getButton();
-
- // Check if there is a need to send mouse exited events by
- // traversing the "widget with mouse" queue.
- bool widgetWithMouseQueueCheckDone = mWidgetWithMouseQueue.empty();
- while (!widgetWithMouseQueueCheckDone)
- {
- unsigned int iterations = 0;
- for (std::deque<Widget*>::iterator
- iter = mWidgetWithMouseQueue.begin();
- iter != mWidgetWithMouseQueue.end();
- ++ iter)
- {
- Widget *const widget = *iter;
-
- // If a widget in the "widget with mouse queue" doesn't
- // exists anymore it should be removed from the queue.
- if (!Widget::widgetExists(widget))
- {
- mWidgetWithMouseQueue.erase(iter);
- break;
- }
- else
- {
- int x;
- int y;
- widget->getAbsolutePosition(x, y);
-
- if (x > mouseX
- || y > mouseY
- || x + widget->getWidth() <= mouseX
- || y + widget->getHeight() <= mouseY
- || !widget->isVisible())
- {
- distributeMouseEvent(widget,
- MouseEventType::EXITED,
- button,
- mouseX,
- mouseY,
- true,
- true);
- mClickCount = 1;
- mLastMousePressTimeStamp = 0U;
- mWidgetWithMouseQueue.erase(iter);
- break;
- }
- }
-
- iterations++;
- }
-
- widgetWithMouseQueueCheckDone =
- (CAST_SIZE(iterations) == mWidgetWithMouseQueue.size());
- }
-
- // Check all widgets below the mouse to see if they are
- // present in the "widget with mouse" queue. If a widget
- // is not then it should be added and an entered event should
- // be sent to it.
- Widget* parent = getMouseEventSource(mouseX, mouseY);
- Widget* widget = parent;
-
- // If a widget has modal mouse input focus then it will
- // always be returned from getMouseEventSource, but we only wan't to
- // send mouse entered events if the mouse has actually entered the
- // widget with modal mouse input focus, hence we need to check if
- // that's the case. If it's not we should simply ignore to send any
- // mouse entered events.
- if ((mFocusHandler->getModalMouseInputFocused() != nullptr)
- && widget == mFocusHandler->getModalMouseInputFocused()
- && Widget::widgetExists(widget) &&
- (widget != nullptr))
- {
- int x, y;
- widget->getAbsolutePosition(x, y);
-
- if (x > mouseX || y > mouseY
- || x + widget->getWidth() <= mouseX
- || y + widget->getHeight() <= mouseY)
- {
- parent = nullptr;
- }
- }
-
- while (parent != nullptr)
- {
- parent = widget->getParent();
-
- // Check if the widget is present in the "widget with mouse" queue.
- bool widgetIsPresentInQueue = false;
- FOR_EACH (std::deque<Widget*>::const_iterator,
- iter, mWidgetWithMouseQueue)
- {
- if (*iter == widget)
- {
- widgetIsPresentInQueue = true;
- break;
- }
- }
-
- // Widget is not present, send an entered event and add
- // it to the "widget with mouse" queue.
- if (!widgetIsPresentInQueue
- && Widget::widgetExists(widget))
- {
- distributeMouseEvent(widget,
- MouseEventType::ENTERED,
- button,
- mouseX,
- mouseY,
- true,
- true);
- mWidgetWithMouseQueue.push_front(widget);
- }
-
- const Widget *const swap = widget;
- widget = parent;
- parent = swap->getParent();
- }
-
- if (mFocusHandler->getDraggedWidget() != nullptr)
- {
- distributeMouseEvent(mFocusHandler->getDraggedWidget(),
- MouseEventType::DRAGGED,
- mLastMouseDragButton,
- mouseX,
- mouseY);
- }
- else
- {
- Widget *const sourceWidget = getMouseEventSource(mouseX, mouseY);
- distributeMouseEvent(sourceWidget,
- MouseEventType::MOVED,
- button,
- mouseX,
- mouseY);
- }
- mMouseInactivityTimer = 0;
-}
-
-void Gui::handleMousePressed(const MouseInput &mouseInput)
-{
- const int x = mouseInput.getX();
- const int y = mouseInput.getY();
- const MouseButtonT button = mouseInput.getButton();
- const unsigned int timeStamp = mouseInput.getTimeStamp();
-
- Widget *sourceWidget = getMouseEventSource(x, y);
-
- if (mFocusHandler->getDraggedWidget() != nullptr)
- sourceWidget = mFocusHandler->getDraggedWidget();
-
- if (sourceWidget == nullptr)
- return;
- int sourceWidgetX;
- int sourceWidgetY;
- sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY);
-
- if (((mFocusHandler->getModalFocused() != nullptr)
- && sourceWidget->isModalFocused())
- || (mFocusHandler->getModalFocused() == nullptr))
- {
- sourceWidget->requestFocus();
- }
-
- if (mDoubleClick &&
- timeStamp - mLastMousePressTimeStamp < 250U &&
- mLastMousePressButton == button)
- {
- mClickCount ++;
- }
- else
- {
- mClickCount = 1;
- }
-
- distributeMouseEvent(sourceWidget, MouseEventType::PRESSED, button, x, y);
- mFocusHandler->setLastWidgetPressed(sourceWidget);
- mFocusHandler->setDraggedWidget(sourceWidget);
- mLastMouseDragButton = button;
- mLastMousePressButton = button;
- mLastMousePressTimeStamp = timeStamp;
-}
-
-void Gui::updateFonts()
-{
- const int fontSize = config.getIntValue("fontSize");
- std::string fontFile = config.getValue("font", "");
- if (fontFile.empty())
- fontFile = branding.getStringValue("font");
-
- mGuiFont->loadFont(fontFile, fontSize, TTF_STYLE_NORMAL);
-
- fontFile = config.getValue("particleFont", "");
- if (fontFile.empty())
- fontFile = branding.getStringValue("particleFont");
-
- mInfoParticleFont->loadFont(fontFile, fontSize, TTF_STYLE_BOLD);
-
- fontFile = config.getValue("boldFont", "");
- if (fontFile.empty())
- fontFile = branding.getStringValue("boldFont");
-
- boldFont->loadFont(fontFile, fontSize, TTF_STYLE_NORMAL);
-
- const int npcFontSize = config.getIntValue("npcfontSize");
-
- fontFile = config.getValue("npcFont", "");
- if (fontFile.empty())
- fontFile = branding.getStringValue("npcFont");
-
- mNpcFont->loadFont(fontFile, npcFontSize, TTF_STYLE_NORMAL);
-}
-
-void Gui::distributeMouseEvent(Widget *const source,
- const MouseEventTypeT type,
- const MouseButtonT button,
- const int x, const int y,
- const bool force,
- const bool toSourceOnly)
-{
- if ((source == nullptr) || (mFocusHandler == nullptr))
- return;
-
- Widget *widget = source;
-
- if (!force)
- {
- if (mFocusHandler->getModalFocused() != nullptr
- && !widget->isModalFocused())
- {
- return;
- }
- if (mFocusHandler->getModalMouseInputFocused() != nullptr
- && !widget->isModalMouseInputFocused())
- {
- return;
- }
- }
-
- MouseEvent event(source,
- type, button,
- x, y, mClickCount);
-
- Widget* parent = source;
- while (parent != nullptr)
- {
- // If the widget has been removed due to input
- // cancel the distribution.
- if (!Widget::widgetExists(widget))
- break;
-
- parent = widget->getParent();
-
- if (widget->isEnabled() || force)
- {
- int widgetX;
- int widgetY;
- widget->getAbsolutePosition(widgetX, widgetY);
-
- event.setX(x - widgetX);
- event.setY(y - widgetY);
-
- std::list<MouseListener*> mouseListeners
- = widget->getMouseListeners();
-
- const MouseEventTypeT mouseType = event.getType();
- // Send the event to all mouse listeners of the widget.
- FOR_EACH (std::list<MouseListener*>::const_iterator,
- it, mouseListeners)
- {
- switch (mouseType)
- {
- case MouseEventType::ENTERED:
- (*it)->mouseEntered(event);
- break;
- case MouseEventType::EXITED:
- (*it)->mouseExited(event);
- break;
- case MouseEventType::MOVED:
- (*it)->mouseMoved(event);
- break;
- case MouseEventType::PRESSED:
- (*it)->mousePressed(event);
- break;
- case MouseEventType::RELEASED:
- case MouseEventType::RELEASED2:
- (*it)->mouseReleased(event);
- break;
- case MouseEventType::WHEEL_MOVED_UP:
- (*it)->mouseWheelMovedUp(event);
- break;
- case MouseEventType::WHEEL_MOVED_DOWN:
- (*it)->mouseWheelMovedDown(event);
- break;
- case MouseEventType::DRAGGED:
- (*it)->mouseDragged(event);
- break;
- case MouseEventType::CLICKED:
- (*it)->mouseClicked(event);
- break;
- default:
- break;
- }
- }
-
- if (toSourceOnly)
- break;
- }
-
- const Widget *const swap = widget;
- widget = parent;
- parent = swap->getParent();
-
-#ifndef DYECMD
- if (type == MouseEventType::RELEASED)
- dragDrop.clear();
-#endif // DYECMD
-
- if ((widget == nullptr) || event.isConsumed())
- break;
-
- // If a non modal focused widget has been reach
- // and we have modal focus cancel the distribution.
- if ((mFocusHandler->getModalFocused() != nullptr)
- && !widget->isModalFocused())
- {
- break;
- }
-
- // If a non modal mouse input focused widget has been reach
- // and we have modal mouse input focus cancel the distribution.
- if ((mFocusHandler->getModalMouseInputFocused() != nullptr)
- && !widget->isModalMouseInputFocused())
- {
- break;
- }
- }
-}
-
-void Gui::resetClickCount()
-{
- mClickCount = 1;
- mLastMousePressTimeStamp = 0;
-}
-
-MouseEvent *Gui::createMouseEvent(Window *const widget)
-{
- if ((viewport == nullptr) || (widget == nullptr))
- return nullptr;
-
- int x = 0;
- int y = 0;
- int mouseX = 0;
- int mouseY = 0;
-
- getAbsolutePosition(widget, x, y);
- getMouseState(mouseX, mouseY);
-
- return new MouseEvent(widget,
- MouseEventType::MOVED,
- MouseButton::EMPTY,
- mouseX - x,
- mouseY - y,
- mClickCount);
-}
-
-void Gui::getAbsolutePosition(Widget *restrict widget,
- int &restrict x,
- int &restrict y)
-{
- if (widget == nullptr)
- return;
- x = 0;
- y = 0;
- while (widget->getParent() != nullptr)
- {
- x += widget->getX();
- y += widget->getY();
- widget = widget->getParent();
- }
-}
-
-void Gui::handleMouseInput()
-{
- BLOCK_START("Gui::handleMouseInput")
- while (!mInput->isMouseQueueEmpty())
- {
- const MouseInput mouseInput = guiInput->dequeueMouseInput();
-
- if (touchManager.processEvent(mouseInput))
- {
-#ifdef ANDROID
-#ifndef USE_SDL2
- SDL_WarpMouse(mLastMouseX, mLastMouseY,
- mLastMouseRealX, mLastMouseRealY);
-#endif // USE_SDL2
-#endif // ANDROID
-
- mMouseInactivityTimer = 0;
- continue;
- }
-
- // Save the current mouse state. It will be needed if modal focus
- // changes or modal mouse input focus changes.
- mLastMouseX = mouseInput.getX();
- mLastMouseY = mouseInput.getY();
-#ifdef ANDROID
- mLastMouseRealX = mouseInput.getRealX();
- mLastMouseRealY = mouseInput.getRealY();
-#endif // ANDROID
-
- switch (mouseInput.getType())
- {
- case MouseEventType::PRESSED:
- handleMousePressed(mouseInput);
- break;
- case MouseEventType::RELEASED:
- handleMouseReleased(mouseInput);
- break;
- case MouseEventType::MOVED:
- handleMouseMoved(mouseInput);
- break;
- case MouseEventType::WHEEL_MOVED_DOWN:
- handleMouseWheelMovedDown(mouseInput);
- break;
- case MouseEventType::WHEEL_MOVED_UP:
- handleMouseWheelMovedUp(mouseInput);
- break;
- case MouseEventType::CLICKED:
- case MouseEventType::ENTERED:
- case MouseEventType::EXITED:
- case MouseEventType::DRAGGED:
- case MouseEventType::RELEASED2:
- default:
- break;
- }
- }
- BLOCK_END("Gui::handleMouseInput")
-}
-
-void Gui::handleMouseReleased(const MouseInput &mouseInput)
-{
- Widget *sourceWidget = getMouseEventSource(
- mouseInput.getX(), mouseInput.getY());
-
- int sourceWidgetX;
- int sourceWidgetY;
- if (mFocusHandler->getDraggedWidget() != nullptr)
- {
- if (sourceWidget != mFocusHandler->getLastWidgetPressed())
- mFocusHandler->setLastWidgetPressed(nullptr);
-
- Widget *const oldWidget = sourceWidget;
- sourceWidget = mFocusHandler->getDraggedWidget();
- if ((oldWidget != nullptr) && oldWidget != sourceWidget)
- {
- oldWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY);
- distributeMouseEvent(oldWidget,
- MouseEventType::RELEASED2,
- mouseInput.getButton(),
- mouseInput.getX(),
- mouseInput.getY());
- }
- }
-
- if (sourceWidget == nullptr)
- return;
- sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY);
- distributeMouseEvent(sourceWidget,
- MouseEventType::RELEASED,
- mouseInput.getButton(),
- mouseInput.getX(),
- mouseInput.getY());
-
- if (mouseInput.getButton() == mLastMousePressButton
- && mFocusHandler->getLastWidgetPressed() == sourceWidget)
- {
- distributeMouseEvent(sourceWidget,
- MouseEventType::CLICKED,
- mouseInput.getButton(),
- mouseInput.getX(),
- mouseInput.getY());
-
- mFocusHandler->setLastWidgetPressed(nullptr);
- }
- else
- {
- mLastMousePressButton = MouseButton::EMPTY;
- mClickCount = 0;
- }
-
- if (mFocusHandler->getDraggedWidget() != nullptr)
- mFocusHandler->setDraggedWidget(nullptr);
-}
-
-void Gui::addGlobalFocusListener(FocusListener* focusListener)
-{
- mFocusListeners.push_back(focusListener);
-}
-
-void Gui::removeGlobalFocusListener(FocusListener* focusListener)
-{
- mFocusListeners.remove(focusListener);
-}
-
-void Gui::distributeGlobalFocusGainedEvent(const Event &focusEvent)
-{
- for (FocusListenerIterator iter = mFocusListeners.begin();
- iter != mFocusListeners.end();
- ++ iter)
- {
- (*iter)->focusGained(focusEvent);
- }
-}
-
-void Gui::removeDragged(const Widget *const widget)
-{
- if (mFocusHandler == nullptr)
- return;
-
- if (mFocusHandler->getDraggedWidget() == widget)
- mFocusHandler->setDraggedWidget(nullptr);
-}
-
-MouseStateType Gui::getMouseState(int &x, int &y)
-{
- const MouseStateType res = SDL_GetMouseState(&x, &y);
- const int scale = mainGraphics->getScale();
- x /= scale;
- y /= scale;
- return res;
-}
-
-void Gui::setTop(Widget *const top)
-{
- if (mTop != nullptr)
- mTop->setFocusHandler(nullptr);
- if (top != nullptr)
- top->setFocusHandler(mFocusHandler);
-
- mTop = top;
-}
-
-void Gui::setGraphics(Graphics *const graphics)
-{
- mGraphics = graphics;
-}
-
-Graphics* Gui::getGraphics() const
-{
- return mGraphics;
-}
-
-void Gui::setInput(SDLInput *const input)
-{
- mInput = input;
-}
-
-SDLInput* Gui::getInput() const
-{
- return mInput;
-}
-
-void Gui::addGlobalKeyListener(KeyListener *const keyListener)
-{
- mKeyListeners.push_back(keyListener);
-}
-
-void Gui::removeGlobalKeyListener(KeyListener *const keyListener)
-{
- mKeyListeners.remove(keyListener);
-}
-
-void Gui::handleMouseWheelMovedDown(const MouseInput& mouseInput)
-{
- Widget* sourceWidget = getMouseEventSource(
- mouseInput.getX(), mouseInput.getY());
-
- if (mFocusHandler->getDraggedWidget() != nullptr)
- sourceWidget = mFocusHandler->getDraggedWidget();
-
- if (sourceWidget != nullptr)
- {
- int sourceWidgetX = 0;
- int sourceWidgetY = 0;
-
- sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY);
- distributeMouseEvent(sourceWidget,
- MouseEventType::WHEEL_MOVED_DOWN,
- mouseInput.getButton(),
- mouseInput.getX(),
- mouseInput.getY());
- }
-}
-
-void Gui::handleMouseWheelMovedUp(const MouseInput& mouseInput)
-{
- Widget* sourceWidget = getMouseEventSource(
- mouseInput.getX(), mouseInput.getY());
-
- if (mFocusHandler->getDraggedWidget() != nullptr)
- sourceWidget = mFocusHandler->getDraggedWidget();
-
- if (sourceWidget != nullptr)
- {
- int sourceWidgetX;
- int sourceWidgetY;
-
- sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY);
- distributeMouseEvent(sourceWidget,
- MouseEventType::WHEEL_MOVED_UP,
- mouseInput.getButton(),
- mouseInput.getX(),
- mouseInput.getY());
- }
-}
-
-Widget* Gui::getWidgetAt(const int x, const int y) const
-{
- // If the widget's parent has no child then we have found the widget..
- Widget* parent = mTop;
- Widget* child = mTop;
- Widget* selectable = mTop;
-
- while (child != nullptr)
- {
- Widget *const swap = child;
- int parentX, parentY;
- parent->getAbsolutePosition(parentX, parentY);
- child = parent->getWidgetAt(x - parentX, y - parentY);
- parent = swap;
- if (parent->isSelectable())
- selectable = parent;
- }
-
- return selectable;
-}
-
-Widget* Gui::getMouseEventSource(const int x, const int y) const
-{
- Widget *const widget = getWidgetAt(x, y);
- if (widget == nullptr)
- return nullptr;
-
- if (mFocusHandler != nullptr &&
- mFocusHandler->getModalMouseInputFocused() != nullptr &&
- !widget->isModalMouseInputFocused())
- {
- return mFocusHandler->getModalMouseInputFocused();
- }
-
- return widget;
-}
-
-Widget* Gui::getKeyEventSource() const
-{
- Widget* widget = mFocusHandler->getFocused();
-
- while (widget != nullptr &&
- widget->getInternalFocusHandler() != nullptr &&
- widget->getInternalFocusHandler()->getFocused() != nullptr)
- {
- widget = widget->getInternalFocusHandler()->getFocused();
- }
-
- return widget;
-}
-
-void Gui::distributeKeyEvent(KeyEvent &event) const
-{
- Widget* parent = event.getSource();
- Widget* widget = parent;
-
- if (parent == nullptr)
- return;
- if (mFocusHandler->getModalFocused() != nullptr &&
- !widget->isModalFocused())
- {
- return;
- }
- if (mFocusHandler->getModalMouseInputFocused() != nullptr &&
- !widget->isModalMouseInputFocused())
- {
- return;
- }
-
- while (parent != nullptr)
- {
- // If the widget has been removed due to input
- // cancel the distribution.
- if (!Widget::widgetExists(widget))
- break;
-
- parent = widget->getParent();
-
- if (widget->isEnabled())
- {
- std::list<KeyListener*> keyListeners
- = widget->getKeyListeners();
-
- const KeyEventTypeT eventType = event.getType();
- // Send the event to all key listeners of the source widget.
- FOR_EACH (std::list<KeyListener*>::const_iterator,
- it, keyListeners)
- {
- switch (eventType)
- {
- case KeyEventType::PRESSED:
- (*it)->keyPressed(event);
- break;
- case KeyEventType::RELEASED:
- (*it)->keyReleased(event);
- break;
- default:
- break;
- }
- }
- }
-
- const Widget *const swap = widget;
- widget = parent;
- parent = swap->getParent();
-
- // If a non modal focused widget has been reach
- // and we have modal focus cancel the distribution.
- if ((widget != nullptr) &&
- (mFocusHandler->getModalFocused() != nullptr) &&
- !widget->isModalFocused())
- {
- break;
- }
- }
-}
-
-void Gui::distributeKeyEventToGlobalKeyListeners(KeyEvent& event)
-{
- BLOCK_START("Gui::distributeKeyEventToGlobalKeyListeners")
- const KeyEventTypeT eventType = event.getType();
- FOR_EACH (KeyListenerListIterator, it, mKeyListeners)
- {
- switch (eventType)
- {
- case KeyEventType::PRESSED:
- (*it)->keyPressed(event);
- break;
- case KeyEventType::RELEASED:
- (*it)->keyReleased(event);
- break;
- default:
- break;
- }
-
- if (event.isConsumed())
- break;
- }
- BLOCK_END("Gui::distributeKeyEventToGlobalKeyListeners")
-}
-
-void Gui::handleModalMouseInputFocus()
-{
- BLOCK_START("Gui::handleModalMouseInputFocus")
- Widget *const lastModalWidget
- = mFocusHandler->getLastWidgetWithModalMouseInputFocus();
- Widget *const modalWidget = mFocusHandler->getModalMouseInputFocused();
- if (lastModalWidget != modalWidget)
- {
- // Check if modal mouse input focus has been gained by a widget.
- if (lastModalWidget == nullptr)
- {
- handleModalFocusGained();
- mFocusHandler->setLastWidgetWithModalMouseInputFocus(modalWidget);
- }
- // Check if modal mouse input focus has been released.
- else
- {
- handleModalFocusReleased();
- mFocusHandler->setLastWidgetWithModalMouseInputFocus(nullptr);
- }
- }
- BLOCK_END("Gui::handleModalMouseInputFocus")
-}
-
-void Gui::handleModalFocus()
-{
- BLOCK_START("Gui::handleModalFocus")
- Widget *const lastModalWidget
- = mFocusHandler->getLastWidgetWithModalFocus();
- Widget *const modalWidget = mFocusHandler->getModalFocused();
-
- if (lastModalWidget != modalWidget)
- {
- // Check if modal focus has been gained by a widget.
- if (lastModalWidget == nullptr)
- {
- handleModalFocusGained();
- mFocusHandler->setLastWidgetWithModalFocus(modalWidget);
- }
- // Check if modal focus has been released.
- else
- {
- handleModalFocusReleased();
- mFocusHandler->setLastWidgetWithModalFocus(nullptr);
- }
- }
- BLOCK_END("Gui::handleModalFocus")
-}
-
-void Gui::handleModalFocusGained()
-{
- // Distribute an event to all widgets in the "widget with mouse" queue.
- while (!mWidgetWithMouseQueue.empty())
- {
- Widget *const widget = mWidgetWithMouseQueue.front();
-
- if (Widget::widgetExists(widget))
- {
- distributeMouseEvent(widget,
- MouseEventType::EXITED,
- mLastMousePressButton,
- mLastMouseX,
- mLastMouseY,
- true,
- true);
- }
-
- mWidgetWithMouseQueue.pop_front();
- }
-
- mFocusHandler->setLastWidgetWithModalMouseInputFocus(
- mFocusHandler->getModalMouseInputFocused());
-}
-
-void Gui::handleModalFocusReleased()
-{
- // Check all widgets below the mouse to see if they are
- // present in the "widget with mouse" queue. If a widget
- // is not then it should be added and an entered event should
- // be sent to it.
- Widget* widget = getMouseEventSource(mLastMouseX, mLastMouseY);
- Widget* parent = widget;
-
- while (parent != nullptr &&
- widget != nullptr)
- {
- parent = widget->getParent();
-
- // Check if the widget is present in the "widget with mouse" queue.
- bool widgetIsPresentInQueue = false;
- FOR_EACH (std::deque<Widget*>::const_iterator,
- iter, mWidgetWithMouseQueue)
- {
- if (*iter == widget)
- {
- widgetIsPresentInQueue = true;
- break;
- }
- }
-
- // Widget is not present, send an entered event and add
- // it to the "widget with mouse" queue.
- if (!widgetIsPresentInQueue && Widget::widgetExists(widget))
- {
- distributeMouseEvent(widget,
- MouseEventType::ENTERED,
- mLastMousePressButton,
- mLastMouseX,
- mLastMouseY,
- false,
- true);
- mWidgetWithMouseQueue.push_front(widget);
- }
-
- const Widget *const swap = widget;
- widget = parent;
- parent = swap->getParent();
- }
-}
-
-int Gui::getMousePressLength() const
-{
- if (mLastMousePressTimeStamp == 0u)
- return 0;
- unsigned int ticks = SDL_GetTicks();
- if (ticks > mLastMousePressTimeStamp)
- return ticks - mLastMousePressTimeStamp;
- return mLastMousePressTimeStamp - ticks;
-}
diff --git a/src/gui/gui.h b/src/gui/gui.h
deleted file mode 100644
index a846f1a5d..000000000
--- a/src/gui/gui.h
+++ /dev/null
@@ -1,527 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_GUI_H
-#define GUI_GUI_H
-
-#include "gui/color.h"
-
-#include "enums/events/mousebutton.h"
-#include "enums/events/mouseeventtype.h"
-
-#include "enums/resources/cursor.h"
-
-#include <deque>
-#include <list>
-
-#include "localconsts.h"
-
-class Event;
-class FocusHandler;
-class FocusListener;
-class Graphics;
-class GuiConfigListener;
-class ImageSet;
-class KeyEvent;
-class KeyListener;
-class MouseEvent;
-class MouseInput;
-class Font;
-class SDLInput;
-class Widget;
-class Window;
-
-#ifdef USE_SDL2
-#define MouseStateType uint32_t
-#else // USE_SDL2
-#define MouseStateType uint8_t
-#endif // USE_SDL2
-
-/**
- * \defgroup GUI Core GUI related classes (widgets)
- */
-
-/**
- * \defgroup Interface User interface related classes (windows, dialogs)
- */
-
-/**
- * Main GUI class.
- *
- * \ingroup GUI
- */
-class Gui final
-{
- public:
- /**
- * Constructor.
- */
- Gui();
-
- A_DELETE_COPY(Gui)
-
- /**
- * Destructor.
- */
- ~Gui();
-
- void postInit(Graphics *const graphics) A_NONNULL(2);
-
- /**
- * Performs logic of the GUI. Overridden to track mouse pointer
- * activity.
- */
- void logic();
-
- void slowLogic();
-
- void clearFonts();
-
- /**
- * Draws the whole Gui by calling draw functions down in the
- * Gui hierarchy. It also draws the mouse pointer.
- */
- void draw();
-
- /**
- * Called when the application window has been resized.
- */
- void videoResized() const;
-
- FocusHandler *getFocusHandler() const noexcept2 A_WARN_UNUSED
- { return mFocusHandler; }
-
- /**
- * Return game font.
- */
- Font *getFont() const RETURNS_NONNULL A_WARN_UNUSED
- { return mGuiFont; }
-
- /**
- * Return help font.
- */
- Font *getHelpFont() const RETURNS_NONNULL A_WARN_UNUSED
- { return mHelpFont; }
-
- /**
- * Return secure font.
- */
- Font *getSecureFont() const RETURNS_NONNULL A_WARN_UNUSED
- { return mSecureFont; }
-
- /**
- * Return npc font.
- */
- Font *getNpcFont() const RETURNS_NONNULL A_WARN_UNUSED
- { return mNpcFont; }
-
- /**
- * Return the Font used for "Info Particles", i.e. ones showing, what
- * you picked up, etc.
- */
- Font *getInfoParticleFont() const RETURNS_NONNULL A_WARN_UNUSED
- { return mInfoParticleFont; }
-
- /**
- * Sets whether a custom cursor should be rendered.
- */
- void setUseCustomCursor(const bool customCursor);
-
- /**
- * Sets which cursor should be used.
- */
- void setCursorType(const CursorT index)
- { mCursorType = index; }
-
- void setDoubleClick(const bool b)
- { mDoubleClick = b; }
-
- void updateFonts();
-
- bool handleInput();
-
- bool handleKeyInput();
-
- void resetClickCount();
-
- MouseEvent *createMouseEvent(Window *const widget) A_WARN_UNUSED;
-
- static void getAbsolutePosition(Widget *restrict widget,
- int &restrict x,
- int &restrict y);
-
- void addGlobalFocusListener(FocusListener* focusListener);
-
- void removeGlobalFocusListener(FocusListener* focusListener);
-
- void distributeGlobalFocusGainedEvent(const Event &focusEvent);
-
- void removeDragged(const Widget *const widget);
-
- int getLastMouseX() const
- { return mLastMouseX; }
-
- int getLastMouseY() const
- { return mLastMouseY; }
-
- static MouseStateType getMouseState(int &x, int &y);
-
- /**
- * Sets the top widget. The top widget is the root widget
- * of the GUI. If you want a GUI to be able to contain more
- * than one widget the top widget should be a container.
- *
- * @param top The top widget.
- * @see Container
- */
- void setTop(Widget *const top);
-
- /**
- * Gets the top widget. The top widget is the root widget
- * of the GUI.
- *
- * @return The top widget. NULL if no top widget has been set.
- */
- Widget* getTop() const noexcept2 A_WARN_UNUSED
- { return mTop; }
-
- /**
- * Sets the graphics object to use for drawing.
- *
- * @param graphics The graphics object to use for drawing.
- * @see getGraphics, AllegroGraphics, HGEGraphics,
- * OpenLayerGraphics, OpenGLGraphics, SDLGraphics
- */
- void setGraphics(Graphics *const graphics) A_NONNULL(2);
-
- /**
- * Gets the graphics object used for drawing.
- *
- * @return The graphics object used for drawing. NULL if no
- * graphics object has been set.
- * @see setGraphics, AllegroGraphics, HGEGraphics,
- * OpenLayerGraphics, OpenGLGraphics, SDLGraphics
- */
- Graphics* getGraphics() const RETURNS_NONNULL A_WARN_UNUSED;
-
- /**
- * Sets the input object to use for input handling.
- *
- * @param input The input object to use for input handling.
- * @see getInput, AllegroInput, HGEInput, OpenLayerInput,
- * SDLInput
- */
- void setInput(SDLInput *const input) A_NONNULL(2);
-
- /**
- * Gets the input object being used for input handling.
- *
- * @return The input object used for handling input. NULL if no
- * input object has been set.
- * @see setInput, AllegroInput, HGEInput, OpenLayerInput,
- * SDLInput
- */
- SDLInput* getInput() const A_WARN_UNUSED;
-
- /**
- * Adds a global key listener to the Gui. A global key listener
- * will receive all key events generated from the GUI and global
- * key listeners will receive the events before key listeners
- * of widgets.
- *
- * @param keyListener The key listener to add.
- * @see removeGlobalKeyListener
- */
- void addGlobalKeyListener(KeyListener *const keyListener);
-
- /**
- * Removes global key listener from the Gui.
- *
- * @param keyListener The key listener to remove.
- * @throws Exception if the key listener hasn't been added.
- * @see addGlobalKeyListener
- */
- void removeGlobalKeyListener(KeyListener *const keyListener);
-
- bool isLongPress() const
- { return getMousePressLength() > 250; }
-
- int getMousePressLength() const;
-
- protected:
- void handleMouseMoved(const MouseInput &mouseInput);
-
- void handleMouseReleased(const MouseInput &mouseInput);
-
- void handleMousePressed(const MouseInput &mouseInput);
-
- void handleMouseInput();
-
- void distributeMouseEvent(Widget *const source,
- const MouseEventTypeT type,
- const MouseButtonT button,
- const int x, const int y,
- const bool force = false,
- const bool toSourceOnly = false);
-
- /**
- *
- * Handles mouse wheel moved down input.
- *
- * @param mouseInput The mouse input to handle.
- */
- void handleMouseWheelMovedDown(const MouseInput& mouseInput);
-
- /**
- * Handles mouse wheel moved up input.
- *
- * @param mouseInput The mouse input to handle.
- */
- void handleMouseWheelMovedUp(const MouseInput& mouseInput);
-
- /**
- * Gets the widget at a certain position.
- *
- * @return The widget at a certain position.
- */
- Widget* getWidgetAt(const int x, const int y) const A_WARN_UNUSED;
-
- /**
- * Gets the source of the mouse event.
- *
- * @return The source widget of the mouse event.
- */
- Widget* getMouseEventSource(const int x,
- const int y) const A_WARN_UNUSED;
-
- /**
- * Gets the source of the key event.
- *
- * @return The source widget of the key event.
- */
- Widget* getKeyEventSource() const A_WARN_UNUSED;
-
- /**
- * Distributes a key event.
- *
- * @param event The key event to distribute.
-
- */
- void distributeKeyEvent(KeyEvent &event) const;
-
- /**
- * Distributes a key event to the global key listeners.
- *
- * @param event The key event to distribute.
- *
- */
- void distributeKeyEventToGlobalKeyListeners(KeyEvent& event);
-
- /**
- * Handles modal mouse input focus. Modal mouse input focus needs
- * to be checked at each logic iteration as it might be necessary to
- * distribute mouse entered or mouse exited events.
- *
- */
- void handleModalMouseInputFocus();
-
- /**
- * Handles modal focus. Modal focus needs to be checked at
- * each logic iteration as it might be necessary to distribute
- * mouse entered or mouse exited events.
- *
- */
- void handleModalFocus();
-
- /**
- * Handles modal focus gained. If modal focus has been gained it might
- * be necessary to distribute mouse entered or mouse exited events.
- *
- */
- void handleModalFocusGained();
-
- /**
- * Handles modal mouse input focus gained. If modal focus has been
- * gained it might be necessary to distribute mouse entered or mouse
- * exited events.
- *
- */
- void handleModalFocusReleased();
-
- private:
- /**
- * Holds the top widget.
- */
- Widget* mTop;
-
- /**
- * Holds the graphics implementation used.
- */
- Graphics* mGraphics A_NONNULLPOINTER;
-
- /**
- * Holds the input implementation used.
- */
- SDLInput* mInput A_NONNULLPOINTER;
-
- /**
- * Holds the focus handler for the Gui.
- */
- FocusHandler* mFocusHandler A_NONNULLPOINTER;
-
- /**
- * Typedef.
- */
- typedef std::list<KeyListener*> KeyListenerList;
-
- /**
- * Typedef.
- */
- typedef KeyListenerList::iterator KeyListenerListIterator;
-
- /**
- * Holds the global key listeners of the Gui.
- */
- KeyListenerList mKeyListeners;
-
- /**
- * Holds the last mouse button pressed.
- */
- MouseButtonT mLastMousePressButton;
-
- /**
- * Holds the last mouse press time stamp.
- */
- unsigned int mLastMousePressTimeStamp;
-
- /**
- * Holds the last mouse x coordinate.
- */
- int mLastMouseX;
-
- /**
- * Holds the last mouse y coordinate.
- */
- int mLastMouseY;
-
- /**
- * Holds the current click count. Used to keep track
- * of clicks for a the last pressed button.
- */
- int mClickCount;
-
- /**
- * Holds the last button used when a drag of a widget
- * was initiated. Used to be able to release a drag
- * when the same button is released.
- */
- MouseButtonT mLastMouseDragButton;
-
- /**
- * Holds a stack with all the widgets with the mouse.
- * Used to properly distribute mouse events.
- */
- std::deque<Widget*> mWidgetWithMouseQueue;
-
- GuiConfigListener *mConfigListener;
- /** The global GUI font */
- Font *mGuiFont A_NONNULLPOINTER;
- /** Font for Info Particles */
- Font *mInfoParticleFont A_NONNULLPOINTER;
- /** Font for Help Window */
- Font *mHelpFont A_NONNULLPOINTER;
- /** Font for secure labels */
- Font *mSecureFont A_NONNULLPOINTER;
- /** Font for npc text */
- Font *mNpcFont A_NONNULLPOINTER;
- /** Mouse cursor images */
- ImageSet *mMouseCursors;
- float mMouseCursorAlpha;
- int mMouseInactivityTimer;
- CursorT mCursorType;
-#ifdef ANDROID
- uint16_t mLastMouseRealX;
- uint16_t mLastMouseRealY;
-#endif // ANDROID
-
- typedef std::list<FocusListener*> FocusListenerList;
- typedef FocusListenerList::iterator FocusListenerIterator;
- FocusListenerList mFocusListeners;
- Color mForegroundColor;
- Color mForegroundColor2;
- time_t mTime;
- time_t mTime10;
- bool mCustomCursor; /**< Show custom cursor */
- bool mDoubleClick;
-};
-
-extern Gui *gui; /**< The GUI system */
-
-/**
- * Bolded text font
- */
-extern Font *boldFont A_NONNULLPOINTER;
-
-#endif // GUI_GUI_H
diff --git a/src/gui/mailmessage.h b/src/gui/mailmessage.h
deleted file mode 100644
index f96a6d675..000000000
--- a/src/gui/mailmessage.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2015-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MAILMESSAGE_H
-#define GUI_MAILMESSAGE_H
-
-#include "enums/net/mailmessagetype.h"
-
-#include <string>
-
-#include "localconsts.h"
-
-struct MailMessage final
-{
- MailMessage() :
- title(),
- sender(),
- strTime(),
- text(),
- id(0),
- time(0),
- expireTime(0),
- money(0),
- type(MailMessageType::Text),
- read(false)
- {
- }
-
- A_DELETE_COPY(MailMessage)
-
- std::string title;
- std::string sender;
- std::string strTime;
- std::string text;
- int64_t id;
- int time;
- int expireTime;
- int64_t money;
- MailMessageType::Type type;
- bool read;
-};
-#endif // GUI_MAILMESSAGE_H
diff --git a/src/gui/models/avatarlistmodel.h b/src/gui/models/avatarlistmodel.h
deleted file mode 100644
index 67ec6846a..000000000
--- a/src/gui/models/avatarlistmodel.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_AVATARLISTMODEL_H
-#define GUI_MODELS_AVATARLISTMODEL_H
-
-#include "avatar.h"
-
-#include "gui/models/listmodel.h"
-
-class AvatarListModel notfinal : public ListModel
-{
- public:
- AvatarListModel() :
- ListModel()
- { }
-
- A_DELETE_COPY(AvatarListModel)
-
- virtual Avatar *getAvatarAt(const int i) A_WARN_UNUSED = 0;
-
- std::string getElementAt(int i) override final A_WARN_UNUSED
- { return getAvatarAt(i)->getName(); }
-};
-
-#endif // GUI_MODELS_AVATARLISTMODEL_H
diff --git a/src/gui/models/beingslistmodel.h b/src/gui/models/beingslistmodel.h
deleted file mode 100644
index a0a9d2920..000000000
--- a/src/gui/models/beingslistmodel.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_BEINGSLISTMODEL_H
-#define GUI_MODELS_BEINGSLISTMODEL_H
-
-#include "gui/models/avatarlistmodel.h"
-
-#include "utils/cast.h"
-#include "utils/dtor.h"
-#include "utils/vector.h"
-
-class BeingsListModel final : public AvatarListModel
-{
- public:
- BeingsListModel() :
- AvatarListModel(),
- mMembers()
- {
- }
-
- A_DELETE_COPY(BeingsListModel)
-
- ~BeingsListModel()
- {
- delete_all(mMembers);
- mMembers.clear();
- }
-
- STD_VECTOR<Avatar*> *getMembers() RETURNS_NONNULL A_WARN_UNUSED
- {
- return &mMembers;
- }
-
- Avatar *getAvatarAt(int index) override final
- {
- return mMembers[index];
- }
-
- int getNumberOfElements() override final
- {
- return CAST_S32(mMembers.size());
- }
-
- STD_VECTOR<Avatar*> mMembers;
-};
-
-#endif // GUI_MODELS_BEINGSLISTMODEL_H
diff --git a/src/gui/models/colorlistmodel.h b/src/gui/models/colorlistmodel.h
deleted file mode 100644
index bb2d413c2..000000000
--- a/src/gui/models/colorlistmodel.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_COLORLISTMODEL_H
-#define GUI_MODELS_COLORLISTMODEL_H
-
-#include "gui/models/listmodel.h"
-
-#include "utils/gettext.h"
-
-const char *COLOR_NAME[14] =
-{
- // TRANSLATORS: chat color
- N_("default"),
- // TRANSLATORS: chat color
- N_("black"),
- // TRANSLATORS: chat color
- N_("red"),
- // TRANSLATORS: chat color
- N_("green"),
- // TRANSLATORS: chat color
- N_("blue"),
- // TRANSLATORS: chat color
- N_("gold"),
- // TRANSLATORS: chat color
- N_("yellow"),
- // TRANSLATORS: chat color
- N_("pink"),
- // TRANSLATORS: chat color
- N_("purple"),
- // TRANSLATORS: chat color
- N_("grey"),
- // TRANSLATORS: chat color
- N_("brown"),
- // TRANSLATORS: chat color
- N_("rainbow 1"),
- // TRANSLATORS: chat color
- N_("rainbow 2"),
- // TRANSLATORS: chat color
- N_("rainbow 3"),
-};
-
-class ColorListModel final : public ListModel
-{
- public:
- ColorListModel() :
- ListModel()
- { }
-
- A_DELETE_COPY(ColorListModel)
-
- ~ColorListModel()
- { }
-
- int getNumberOfElements() override final
- {
- return 14;
- }
-
- std::string getElementAt(int i) override final
- {
- if (i >= getNumberOfElements() || i < 0)
- return "???";
- return gettext(COLOR_NAME[i]);
- }
-};
-
-#endif // GUI_MODELS_COLORLISTMODEL_H
diff --git a/src/gui/models/colormodel.cpp b/src/gui/models/colormodel.cpp
deleted file mode 100644
index 3bbded2e2..000000000
--- a/src/gui/models/colormodel.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/models/colormodel.h"
-
-#include "gui/widgets/widget2.h"
-
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-ColorModel::ColorModel() :
- ListModel(),
- mNames(),
- mColors()
-{
-}
-
-ColorModel::~ColorModel()
-{
-}
-
-int ColorModel::getNumberOfElements()
-{
- return CAST_S32(mNames.size());
-}
-
-std::string ColorModel::getElementAt(int i)
-{
- if (i >= getNumberOfElements() || i < 0)
- return "???";
- return mNames[CAST_SIZE(i)];
-}
-
-const ColorPair *ColorModel::getColorAt(const int i) const
-{
- if (i >= CAST_S32(mColors.size()) || i < 0)
- return &mColors[0];
-
- return &mColors[CAST_SIZE(i)];
-}
-
-void ColorModel::add(const std::string &name, const Color *const color1,
- const Color *const color2)
-{
- mNames.push_back(name);
- mColors.push_back(ColorPair(color1, color2));
-}
-
-#define addColor(name, color) \
- model->add(name, &widget->getThemeColor(ThemeColorId::color), \
- &widget->getThemeColor(ThemeColorId::color##_OUTLINE));
-
-ColorModel *ColorModel::createDefault(const Widget2 *const widget)
-{
- ColorModel *const model = new ColorModel;
- if (widget == nullptr)
- return model;
- // TRANSLATORS: color name
- addColor(_("black"), BLACK);
- // TRANSLATORS: color name
- addColor(_("red"), RED);
- // TRANSLATORS: color name
- addColor(_("green"), GREEN);
- // TRANSLATORS: color name
- addColor(_("blue"), BLUE);
- // TRANSLATORS: color name
- addColor(_("gold"), ORANGE);
- // TRANSLATORS: color name
- addColor(_("yellow"), YELLOW);
- // TRANSLATORS: color name
- addColor(_("pink"), PINK);
- // TRANSLATORS: color name
- addColor(_("purple"), PURPLE);
- // TRANSLATORS: color name
- addColor(_("grey"), GRAY);
- // TRANSLATORS: color name
- addColor(_("brown"), BROWN);
- return model;
-}
diff --git a/src/gui/models/colormodel.h b/src/gui/models/colormodel.h
deleted file mode 100644
index 9d621dfbe..000000000
--- a/src/gui/models/colormodel.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_COLORMODEL_H
-#define GUI_MODELS_COLORMODEL_H
-
-#include "utils/stringvector.h"
-
-#include "gui/colorpair.h"
-
-#include "gui/models/listmodel.h"
-
-#include "localconsts.h"
-
-class Color;
-class Widget2;
-
-class ColorModel final : public ListModel
-{
- public:
- ColorModel();
-
- A_DELETE_COPY(ColorModel)
-
- virtual ~ColorModel();
-
- int getNumberOfElements() override final A_WARN_UNUSED;
-
- std::string getElementAt(int i) override final A_WARN_UNUSED;
-
- const ColorPair *getColorAt(const int i)
- const RETURNS_NONNULL A_WARN_UNUSED;
-
- StringVect &getNames() A_WARN_UNUSED
- { return mNames; }
-
- size_t size() A_WARN_UNUSED
- { return mNames.size(); }
-
- void add(const std::string &name,
- const Color *const color1,
- const Color *const color2);
-
- static ColorModel *createDefault(const Widget2 *const widget)
- RETURNS_NONNULL;
-
- protected:
- StringVect mNames;
- STD_VECTOR<ColorPair> mColors;
-};
-
-#endif // GUI_MODELS_COLORMODEL_H
diff --git a/src/gui/models/extendedlistmodel.h b/src/gui/models/extendedlistmodel.h
deleted file mode 100644
index 981a96897..000000000
--- a/src/gui/models/extendedlistmodel.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_EXTENDEDLISTMODEL_H
-#define GUI_MODELS_EXTENDEDLISTMODEL_H
-
-#include "gui/models/listmodel.h"
-
-#include "resources/image/image.h"
-
-class ExtendedListModel notfinal : public ListModel
-{
- public:
- ExtendedListModel() :
- ListModel()
- { }
-
- A_DELETE_COPY(ExtendedListModel)
-
- virtual const Image *getImageAt(int i) A_WARN_UNUSED = 0;
-};
-
-#endif // GUI_MODELS_EXTENDEDLISTMODEL_H
diff --git a/src/gui/models/extendednamesmodel.cpp b/src/gui/models/extendednamesmodel.cpp
deleted file mode 100644
index 76191ae5a..000000000
--- a/src/gui/models/extendednamesmodel.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/models/extendednamesmodel.h"
-
-#include "utils/cast.h"
-#include "utils/foreach.h"
-
-#include "debug.h"
-
-ExtendedNamesModel::ExtendedNamesModel() :
- mNames(),
- mImages()
-{
-}
-
-ExtendedNamesModel::~ExtendedNamesModel()
-{
- clear();
-}
-
-int ExtendedNamesModel::getNumberOfElements()
-{
- return CAST_S32(mNames.size());
-}
-
-std::string ExtendedNamesModel::getElementAt(int i)
-{
- if (i >= getNumberOfElements() || i < 0)
- return "???";
- return mNames[CAST_SIZE(i)];
-}
-
-const Image *ExtendedNamesModel::getImageAt(int i)
-{
- if (i >= CAST_S32(mImages.size()) || i < 0)
- return nullptr;
-
- return mImages[CAST_SIZE(i)];
-}
-
-void ExtendedNamesModel::clear()
-{
- mNames.clear();
- FOR_EACH (STD_VECTOR<Image*>::iterator, it, mImages)
- {
- if (*it != nullptr)
- (*it)->decRef();
- }
- mImages.clear();
-}
diff --git a/src/gui/models/extendednamesmodel.h b/src/gui/models/extendednamesmodel.h
deleted file mode 100644
index 2e85a4b2b..000000000
--- a/src/gui/models/extendednamesmodel.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_EXTENDEDNAMESMODEL_H
-#define GUI_MODELS_EXTENDEDNAMESMODEL_H
-
-#include "utils/stringvector.h"
-
-#include "gui/models/extendedlistmodel.h"
-
-class ExtendedNamesModel notfinal : public ExtendedListModel
-{
- public:
- ExtendedNamesModel();
-
- A_DELETE_COPY(ExtendedNamesModel)
-
- virtual ~ExtendedNamesModel();
-
- int getNumberOfElements() override final A_WARN_UNUSED;
-
- std::string getElementAt(int i) override final A_WARN_UNUSED;
-
- const Image *getImageAt(int i) override final A_WARN_UNUSED;
-
- StringVect &getNames() A_WARN_UNUSED
- { return mNames; }
-
- STD_VECTOR<Image*> &getImages() A_WARN_UNUSED
- { return mImages; }
-
- size_t size() A_WARN_UNUSED
- { return mNames.size(); }
-
- void add(const std::string &str)
- { mNames.push_back(str); }
-
- void clear();
-
- protected:
- StringVect mNames;
- STD_VECTOR<Image*> mImages;
-};
-
-#endif // GUI_MODELS_EXTENDEDNAMESMODEL_H
diff --git a/src/gui/models/fontsizechoicelistmodel.h b/src/gui/models/fontsizechoicelistmodel.h
deleted file mode 100644
index 79aecf2fb..000000000
--- a/src/gui/models/fontsizechoicelistmodel.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_FONTSIZECHOICELISTMODEL_H
-#define GUI_MODELS_FONTSIZECHOICELISTMODEL_H
-
-#include "gui/models/listmodel.h"
-
-#include "utils/gettext.h"
-
-#include "localconsts.h"
-
-const int maxFontSizes = 16;
-
-const char *SIZE_NAME[maxFontSizes] =
-{
- // TRANSLATORS: font size
- N_("Very small (8)"),
- // TRANSLATORS: font size
- N_("Very small (9)"),
- // TRANSLATORS: font size
- N_("Tiny (10)"),
- // TRANSLATORS: font size
- N_("Small (11)"),
- // TRANSLATORS: font size
- N_("Medium (12)"),
- // TRANSLATORS: font size
- N_("Normal (13)"),
- // TRANSLATORS: font size
- N_("Large (14)"),
- // TRANSLATORS: font size
- N_("Large (15)"),
- // TRANSLATORS: font size
- N_("Large (16)"),
- // TRANSLATORS: font size
- N_("Big (17)"),
- // TRANSLATORS: font size
- N_("Big (18)"),
- // TRANSLATORS: font size
- N_("Big (19)"),
- // TRANSLATORS: font size
- N_("Very big (20)"),
- // TRANSLATORS: font size
- N_("Very big (21)"),
- // TRANSLATORS: font size
- N_("Very big (22)"),
- // TRANSLATORS: font size
- N_("Huge (23)")
-};
-
-class FontSizeChoiceListModel final : public ListModel
-{
- public:
- FontSizeChoiceListModel() :
- ListModel()
- { }
-
- A_DELETE_COPY(FontSizeChoiceListModel)
-
- ~FontSizeChoiceListModel()
- { }
-
- int getNumberOfElements() override final A_WARN_UNUSED
- { return maxFontSizes; }
-
- std::string getElementAt(int i) override final A_WARN_UNUSED
- {
- if (i >= getNumberOfElements() || i < 0)
- return "???";
-
- return gettext(SIZE_NAME[i]);
- }
-};
-
-#endif // GUI_MODELS_FONTSIZECHOICELISTMODEL_H
diff --git a/src/gui/models/fontsmodel.h b/src/gui/models/fontsmodel.h
deleted file mode 100644
index b7f5fc4be..000000000
--- a/src/gui/models/fontsmodel.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_FONTSMODEL_H
-#define GUI_MODELS_FONTSMODEL_H
-
-#include "gui/theme.h"
-
-#include "gui/models/namesmodel.h"
-
-#include "localconsts.h"
-
-class FontsModel final : public NamesModel
-{
- public:
- FontsModel() :
- NamesModel()
- { Theme::fillFontsList(mNames); }
-
- A_DELETE_COPY(FontsModel)
-
- ~FontsModel()
- { }
-};
-
-#endif // GUI_MODELS_FONTSMODEL_H
diff --git a/src/gui/models/iconsmodel.h b/src/gui/models/iconsmodel.h
deleted file mode 100644
index 4028895fb..000000000
--- a/src/gui/models/iconsmodel.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_ICONSMODEL_H
-#define GUI_MODELS_ICONSMODEL_H
-
-#include "gui/models/listmodel.h"
-
-#include "utils/foreach.h"
-
-#include "resources/iteminfo.h"
-
-#include "resources/db/itemdb.h"
-
-#include <list>
-
-#include "localconsts.h"
-
-class IconsModel final : public ListModel
-{
- public:
- IconsModel() :
- mStrings()
- {
- const std::map<int, ItemInfo*> &items = ItemDB::getItemInfos();
- std::list<std::string> tempStrings;
-
- for (std::map<int, ItemInfo*>::const_iterator
- i = items.begin(), i_end = items.end();
- i != i_end; ++i)
- {
- if (i->first < 0)
- continue;
-
- const ItemInfo &info = (*i->second);
- const std::string &name = info.getName();
- if (name != "unnamed" && !info.getName().empty()
- && info.getName() != "unnamed")
- {
- tempStrings.push_back(name);
- }
- }
- tempStrings.sort();
- mStrings.push_back("");
- FOR_EACH (std::list<std::string>::const_iterator, i, tempStrings)
- mStrings.push_back(*i);
- }
-
- A_DELETE_COPY(IconsModel)
-
- ~IconsModel()
- { }
-
- int getNumberOfElements() override final
- {
- return CAST_S32(mStrings.size());
- }
-
- std::string getElementAt(int i) override final
- {
- if (i < 0 || i >= getNumberOfElements())
- return "???";
- return mStrings.at(i);
- }
- private:
- StringVect mStrings;
-};
-
-#endif // GUI_MODELS_ICONSMODEL_H
diff --git a/src/gui/models/ignorechoiceslistmodel.h b/src/gui/models/ignorechoiceslistmodel.h
deleted file mode 100644
index 6cd8bbe87..000000000
--- a/src/gui/models/ignorechoiceslistmodel.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_IGNORECHOICESLISTMODEL_H
-#define GUI_MODELS_IGNORECHOICESLISTMODEL_H
-
-#include "gui/models/playerrelationlistmodel.h"
-
-#include "being/playerignorestrategy.h"
-#include "being/playerrelations.h"
-
-#include "utils/cast.h"
-
-/**
- * Class for choosing one of the various `what to do when ignoring a player' options
- */
-class IgnoreChoicesListModel final : public ListModel
-{
- public:
- IgnoreChoicesListModel() :
- ListModel()
- { }
-
- A_DELETE_COPY(IgnoreChoicesListModel)
-
- ~IgnoreChoicesListModel()
- { }
-
- int getNumberOfElements() override final
- {
- return CAST_S32(playerRelations.
- getPlayerIgnoreStrategies()->size());
- }
-
- std::string getElementAt(int i) override final
- {
- if (i >= getNumberOfElements() || i < 0)
- return "???";
-
- return (*playerRelations.getPlayerIgnoreStrategies())
- [i]->mDescription;
- }
-};
-
-#endif // GUI_MODELS_IGNORECHOICESLISTMODEL_H
diff --git a/src/gui/models/itemsmodel.h b/src/gui/models/itemsmodel.h
deleted file mode 100644
index a49a7cfc5..000000000
--- a/src/gui/models/itemsmodel.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_ITEMSMODEL_H
-#define GUI_MODELS_ITEMSMODEL_H
-
-#include "gui/models/listmodel.h"
-
-#include "resources/iteminfo.h"
-
-#include "resources/db/itemdb.h"
-
-#include "utils/foreach.h"
-
-#include <list>
-
-#include "localconsts.h"
-
-class ItemsModal final : public ListModel
-{
- public:
- ItemsModal() :
- mStrings()
- {
- const std::map<int, ItemInfo*> &items = ItemDB::getItemInfos();
- std::list<std::string> tempStrings;
-
- for (std::map<int, ItemInfo*>::const_iterator
- i = items.begin(), i_end = items.end();
- i != i_end; ++i)
- {
- if (i->first < 0)
- continue;
-
- const ItemInfo &info = *i->second;
- const std::string &name = info.getName();
- if (name != "unnamed" && !info.getName().empty()
- && info.getName() != "unnamed")
- {
- tempStrings.push_back(name);
- }
- }
- tempStrings.sort();
- FOR_EACH (std::list<std::string>::const_iterator, i, tempStrings)
- mStrings.push_back(*i);
- }
-
- A_DELETE_COPY(ItemsModal)
-
- ~ItemsModal()
- { }
-
- int getNumberOfElements() override final
- {
- return CAST_S32(mStrings.size());
- }
-
- std::string getElementAt(int i) override final
- {
- if (i < 0 || i >= getNumberOfElements())
- return "???";
- return mStrings.at(i);
- }
-
- private:
- StringVect mStrings;
-};
-
-#endif // GUI_MODELS_ITEMSMODEL_H
diff --git a/src/gui/models/keylistmodel.h b/src/gui/models/keylistmodel.h
deleted file mode 100644
index 601426f8a..000000000
--- a/src/gui/models/keylistmodel.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007 Joshua Langley <joshlangley@optusnet.com.au>
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_KEYLISTMODEL_H
-#define GUI_MODELS_KEYLISTMODEL_H
-
-#include "gui/setupactiondata.h"
-
-#include "gui/models/listmodel.h"
-
-#include "localconsts.h"
-
-extern SetupActionData *const setupActionData[];
-
-/**
- * The list model for key function list.
- *
- * \ingroup Interface
- */
-class KeyListModel final : public ListModel
-{
- public:
- KeyListModel() :
- mDataNum(0),
- mSelectedData(0),
- mSize(0)
- {
- }
-
- A_DELETE_COPY(KeyListModel)
-
- /**
- * Returns the number of elements in container.
- */
- int getNumberOfElements() override final
- { return mSize; }
-
- /**
- * Returns element from container.
- */
- std::string getElementAt(int i) override final
- { return setupActionData[mSelectedData][i].text; }
-
- /**
- * Sets element from container.
- */
- void setElementAt(const int i, const std::string &caption)
- { setupActionData[mSelectedData][i].text = caption; }
-
- void setSize(const int size) noexcept2
- { mSize = size; }
-
- void setDataNum(const int num) noexcept2
- { mDataNum = num; }
-
- void setSelectedData(const int i) noexcept2
- { mSelectedData = i; }
-
- int getSelectedData() const noexcept2 A_WARN_UNUSED
- { return mSelectedData; }
-
- private:
- int mDataNum;
- int mSelectedData;
- int mSize;
-};
-
-#endif // GUI_MODELS_KEYLISTMODEL_H
diff --git a/src/gui/models/langlistmodel.h b/src/gui/models/langlistmodel.h
deleted file mode 100644
index f8c67ad30..000000000
--- a/src/gui/models/langlistmodel.h
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_LANGLISTMODEL_H
-#define GUI_MODELS_LANGLISTMODEL_H
-
-#include "gui/models/extendedlistmodel.h"
-
-#include "resources/loaders/imageloader.h"
-
-#include "utils/gettext.h"
-
-#include "localconsts.h"
-
-struct Language final
-{
- A_DEFAULT_COPY(Language)
-
- std::string name;
- std::string value;
- std::string icon;
-};
-
-const int langs_count = 22;
-
-const Language LANG_NAME[langs_count] =
-{
- // TRANSLATORS: language
- {N_("(default)"), "", ""},
- // TRANSLATORS: language
- {N_("Catalan"), "ca_ES", "ca.png"},
- // TRANSLATORS: language
- {N_("Chinese (China)"), "zh_CN", "cn.png"},
- // TRANSLATORS: language
- {N_("Chinese (Hong Kong)"), "zh_HK", "hk.png"},
- // TRANSLATORS: language
- {N_("Czech"), "cs_CZ", "cz.png"},
- // TRANSLATORS: language
- {N_("Dutch (Belgium/Flemish)"), "nl_BE", "nl_BE.png"},
- // TRANSLATORS: language
- {N_("English"), "C", "en.png"},
- // TRANSLATORS: language
- {N_("Finnish"), "fi_FI", "fi.png"},
- // TRANSLATORS: language
- {N_("French"), "fr_FR", "fr.png"},
- // TRANSLATORS: language
- {N_("German"), "de_DE", "de.png"},
- // TRANSLATORS: language
- {N_("Indonesian"), "id_ID", "id.png"},
- // TRANSLATORS: language
- {N_("Italian"), "it_IT", "it.png"},
- // TRANSLATORS: language
- {N_("Japanese"), "ja_JP", "jp.png"},
- // TRANSLATORS: language
- {N_("Polish"), "pl_PL", "pl.png"},
- // TRANSLATORS: language
- {N_("Portuguese"), "pt_PT", "pt.png"},
- // TRANSLATORS: language
- {N_("Portuguese (Brazilian)"), "pt_BR", "pt_BR.png"},
- // TRANSLATORS: language
- {N_("Russian"), "ru_RU", "ru.png"},
- // TRANSLATORS: language
- {N_("Spanish (Castilian)"), "es_ES", "es.png"},
- // TRANSLATORS: language
- {N_("Swedish (Sweden)"), "sv_SE", "se.png"},
- // TRANSLATORS: language
- {N_("Turkish"), "tr_TR", "tr.png"},
- // TRANSLATORS: language
- {N_("Ukrainian"), "uk_UA", "ua.png"},
- // TRANSLATORS: language
- {N_("Esperanto"), "eo", "eo.png"}
-};
-
-class LangListModel final : public ExtendedListModel
-{
- public:
- LangListModel()
- {
- for (int f = 0; f < langs_count; f ++)
- {
- const std::string icon = LANG_NAME[f].icon;
- if (!icon.empty())
- {
- mIcons[f] = Loader::getImage("graphics/flags/"
- + icon);
- }
- else
- {
- mIcons[f] = nullptr;
- }
- }
- }
-
- A_DELETE_COPY(LangListModel)
-
- ~LangListModel()
- {
- for (int f = 0; f < langs_count; f ++)
- {
- Image *const img = mIcons[f];
- if (img != nullptr)
- img->decRef();
- }
- }
-
- int getNumberOfElements() override final A_WARN_UNUSED
- { return langs_count; }
-
- std::string getElementAt(int i) override final A_WARN_UNUSED
- {
- if (i >= getNumberOfElements() || i < 0)
- return "???";
-
- return gettext(LANG_NAME[i].name.c_str());
- }
-
- const Image *getImageAt(int i) override final A_WARN_UNUSED
- {
- if (i >= getNumberOfElements() || i < 0)
- return nullptr;
- return mIcons[i];
- }
-
- Image *mIcons[langs_count] A_NONNULLPOINTER;
-};
-
-#endif // GUI_MODELS_LANGLISTMODEL_H
diff --git a/src/gui/models/listmodel.h b/src/gui/models/listmodel.h
deleted file mode 100644
index df8db8b54..000000000
--- a/src/gui/models/listmodel.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_MODELS_LISTMODEL_H
-#define GUI_MODELS_LISTMODEL_H
-
-#include <string>
-
-#include "localconsts.h"
-
-/**
- * An interface for a model that represents a list. It is
- * used in certain widgets, like the ListBox, to handle a
- * lists with string elements. If you want to use widgets
- * like ListBox, make a derived class from this class that
- * represents your list.
- */
-class ListModel notfinal
-{
- public:
- ListModel()
- { }
-
- A_DELETE_COPY(ListModel)
-
- /**
- * Destructor.
- */
- virtual ~ListModel()
- { }
-
- /**
- * Gets the number of elements in the list.
- *
- * @return The number of elements in the list
- */
- virtual int getNumberOfElements() A_WARN_UNUSED = 0;
-
- /**
- * Gets an element at a certain index in the list.
- *
- * @param i An index in the list.
- * @return An element as a string at the a certain index.
- */
- virtual std::string getElementAt(int i) A_WARN_UNUSED = 0;
-};
-
-#endif // GUI_MODELS_LISTMODEL_H
diff --git a/src/gui/models/magicschoolmodel.h b/src/gui/models/magicschoolmodel.h
deleted file mode 100644
index 2dcd01880..000000000
--- a/src/gui/models/magicschoolmodel.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_MAGICSCHOOLMODEL_H
-#define GUI_MODELS_MAGICSCHOOLMODEL_H
-
-#include "gui/models/listmodel.h"
-
-#include "utils/gettext.h"
-
-#include "localconsts.h"
-
-const char *MAGIC_SCHOOL_TEXT[6] =
-{
- // TRANSLATORS: magic school
- N_("General Magic"),
- // TRANSLATORS: magic school
- N_("Life Magic"),
- // TRANSLATORS: magic school
- N_("War Magic"),
- // TRANSLATORS: magic school
- N_("Transmute Magic"),
- // TRANSLATORS: magic school
- N_("Nature Magic"),
- // TRANSLATORS: magic school
- N_("Astral Magic")
-};
-
-class MagicSchoolModel final : public ListModel
-{
- public:
- MagicSchoolModel() :
- ListModel()
- { }
-
- A_DELETE_COPY(MagicSchoolModel)
-
- ~MagicSchoolModel()
- { }
-
- int getNumberOfElements() override final
- {
- return 6;
- }
-
- std::string getElementAt(int i) override final
- {
- if (i >= getNumberOfElements() || i < 0)
- return "???";
- return MAGIC_SCHOOL_TEXT[i];
- }
-};
-
-#endif // GUI_MODELS_MAGICSCHOOLMODEL_H
diff --git a/src/gui/models/modelistmodel.cpp b/src/gui/models/modelistmodel.cpp
deleted file mode 100644
index d1253b9f1..000000000
--- a/src/gui/models/modelistmodel.cpp
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "render/graphics.h"
-
-#include "utils/sdlhelper.h"
-#include "utils/stringutils.h"
-
-#include "gui/models/modelistmodel.h"
-
-#include <algorithm>
-
-#include "debug.h"
-
-#ifndef ANDROID
-static bool modeSorter(const std::string &mode1, const std::string &mode2)
-{
- const int width1 = atoi(mode1.substr(0, mode1.find('x')).c_str());
- const int height1 = atoi(mode1.substr(mode1.find('x') + 1).c_str());
- if ((width1 == 0) || (height1 == 0))
- return false;
-
- const int width2 = atoi(mode2.substr(0, mode2.find('x')).c_str());
- const int height2 = atoi(mode2.substr(mode2.find('x') + 1).c_str());
- if ((width2 == 0) || (height2 == 0))
- return false;
- if (width1 != width2)
- return width1 < width2;
-
- if (height1 != height2)
- return height1 < height2;
-
- return false;
-}
-#endif // ANDROID
-
-ModeListModel::ModeListModel() :
- ListModel(),
- mVideoModes()
-{
- SDL::getAllVideoModes(mVideoModes);
-#ifndef ANDROID
- addCustomMode("640x480");
- addCustomMode("800x600");
- addCustomMode("1024x768");
- addCustomMode("1280x1024");
- addCustomMode("1400x900");
- addCustomMode("1500x990");
- addCustomMode(toString(mainGraphics->mActualWidth).append("x")
- .append(toString(mainGraphics->mActualHeight)));
-
- std::sort(mVideoModes.begin(), mVideoModes.end(), &modeSorter);
- mVideoModes.push_back("custom");
-#endif // ANDROID
-}
-
-#ifndef ANDROID
-void ModeListModel::addCustomMode(const std::string &mode)
-{
- StringVectCIter it = mVideoModes.begin();
- const StringVectCIter it_end = mVideoModes.end();
- while (it != it_end)
- {
- if (*it == mode)
- return;
- ++ it;
- }
- mVideoModes.push_back(mode);
-}
-#endif // ANDROID
-
-int ModeListModel::getIndexOf(const std::string &widthXHeightMode)
-{
- std::string currentMode;
- for (int i = 0; i < getNumberOfElements(); i++)
- {
- currentMode = getElementAt(i);
- if (currentMode == widthXHeightMode)
- return i;
- }
- return -1;
-}
diff --git a/src/gui/models/modelistmodel.h b/src/gui/models/modelistmodel.h
deleted file mode 100644
index ed4d449d7..000000000
--- a/src/gui/models/modelistmodel.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_MODELISTMODEL_H
-#define GUI_MODELS_MODELISTMODEL_H
-
-#include "gui/models/listmodel.h"
-
-#include "utils/cast.h"
-#include "utils/stringvector.h"
-
-#include "localconsts.h"
-
-class ModeListModel final : public ListModel
-{
- public:
- ModeListModel();
-
- A_DELETE_COPY(ModeListModel)
-
- ~ModeListModel()
- { }
-
- /**
- * Returns the number of elements in container.
- */
- int getNumberOfElements() override final
- { return CAST_S32(mVideoModes.size()); }
-
- /**
- * Returns element from container.
- */
- std::string getElementAt(int i) override final
- { return mVideoModes[CAST_SIZE(i)]; }
-
- /**
- * Returns the index corresponding to the given video mode.
- * E.g.: "800x600".
- * or -1 if not found.
- */
- int getIndexOf(const std::string &widthXHeightMode);
-
- private:
-#ifndef ANDROID
- void addCustomMode(const std::string &mode);
-#endif // ANDROID
-
- StringVect mVideoModes;
-};
-
-#endif // GUI_MODELS_MODELISTMODEL_H
diff --git a/src/gui/models/namesmodel.cpp b/src/gui/models/namesmodel.cpp
deleted file mode 100644
index 5344a7a7d..000000000
--- a/src/gui/models/namesmodel.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/models/namesmodel.h"
-
-#include "utils/cast.h"
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-NamesModel::NamesModel() :
- ListModel(),
- mNames()
-{
-}
-
-NamesModel::~NamesModel()
-{
-}
-
-int NamesModel::getNumberOfElements()
-{
- return CAST_S32(mNames.size());
-}
-
-std::string NamesModel::getElementAt(int i)
-{
- if (i >= getNumberOfElements() || i < 0)
- return "???";
- return mNames[CAST_SIZE(i)];
-}
-
-void NamesModel::fillFromArray(const char *const *const arr,
- const std::size_t sz)
-{
- if (arr == nullptr)
- return;
- for (size_t f = 0; f < sz; f ++)
- mNames.push_back(gettext(arr[f]));
-}
-
-void NamesModel::fillFromVector(const StringVect &vect)
-{
- FOR_EACH(StringVectCIter, it, vect)
- {
- const std::string str = *it;
- if (!str.empty())
- mNames.push_back(str);
- }
-}
diff --git a/src/gui/models/namesmodel.h b/src/gui/models/namesmodel.h
deleted file mode 100644
index a239bd9aa..000000000
--- a/src/gui/models/namesmodel.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_NAMESMODEL_H
-#define GUI_MODELS_NAMESMODEL_H
-
-#include "utils/stringvector.h"
-
-#include "gui/models/listmodel.h"
-
-#include "localconsts.h"
-
-class NamesModel notfinal : public ListModel
-{
- public:
- NamesModel();
-
- A_DELETE_COPY(NamesModel)
-
- virtual ~NamesModel();
-
- int getNumberOfElements() override final A_WARN_UNUSED;
-
- std::string getElementAt(int i) override final A_WARN_UNUSED;
-
- StringVect &getNames() noexcept2 A_WARN_UNUSED
- { return mNames; }
-
- size_t size() const noexcept2 A_WARN_UNUSED
- { return mNames.size(); }
-
- void clear()
- { mNames.clear(); }
-
- void add(const std::string &str)
- { mNames.push_back(str); }
-
- void fillFromArray(const char *const *const arr,
- const std::size_t size);
-
- void fillFromVector(const StringVect &vect);
-
- protected:
- StringVect mNames;
-};
-
-#endif // GUI_MODELS_NAMESMODEL_H
diff --git a/src/gui/models/opengllistmodel.h b/src/gui/models/opengllistmodel.h
deleted file mode 100644
index 085dd17a5..000000000
--- a/src/gui/models/opengllistmodel.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_OPENGLLISTMODEL_H
-#define GUI_MODELS_OPENGLLISTMODEL_H
-
-#include "gui/models/listmodel.h"
-
-#include "render/rendererslistsdl.h"
-
-#include "localconsts.h"
-
-class OpenGLListModel final : public ListModel
-{
- public:
- OpenGLListModel() :
- ListModel()
- { }
-
- A_DELETE_COPY(OpenGLListModel)
-
- ~OpenGLListModel()
- { }
-
- int getNumberOfElements() override final
- { return renderModesListSize; }
-
- std::string getElementAt(int i) override final
- {
- if (i >= getNumberOfElements() || i < 0)
- return "???";
- return gettext(OPENGL_NAME[i]);
- }
-};
-
-#endif // GUI_MODELS_OPENGLLISTMODEL_H
diff --git a/src/gui/models/playerrelationlistmodel.h b/src/gui/models/playerrelationlistmodel.h
deleted file mode 100644
index 5e58d4905..000000000
--- a/src/gui/models/playerrelationlistmodel.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_PLAYERRELATIONLISTMODEL_H
-#define GUI_MODELS_PLAYERRELATIONLISTMODEL_H
-
-#include "being/playerrelation.h"
-
-#include "gui/models/listmodel.h"
-
-#include "utils/gettext.h"
-
-static const char *const RELATION_NAMES[PlayerRelation::RELATIONS_NR] =
-{
- // TRANSLATORS: relation type
- N_("Neutral"),
- // TRANSLATORS: relation type
- N_("Friend"),
- // TRANSLATORS: relation type
- N_("Disregarded"),
- // TRANSLATORS: relation type
- N_("Ignored"),
- // TRANSLATORS: relation type
- N_("Erased"),
- // TRANSLATORS: relation type
- N_("Blacklisted"),
- // TRANSLATORS: relation type
- N_("Enemy")
-};
-
-class PlayerRelationListModel final : public ListModel
-{
- public:
- PlayerRelationListModel() :
- ListModel()
- { }
-
- A_DELETE_COPY(PlayerRelationListModel)
-
- ~PlayerRelationListModel()
- { }
-
- int getNumberOfElements() override final
- {
- return PlayerRelation::RELATIONS_NR;
- }
-
- std::string getElementAt(int i) override final
- {
- if (i >= getNumberOfElements() || i < 0)
- return "";
- return gettext(RELATION_NAMES[i]);
- }
-};
-
-#endif // GUI_MODELS_PLAYERRELATIONLISTMODEL_H
diff --git a/src/gui/models/playertablemodel.cpp b/src/gui/models/playertablemodel.cpp
deleted file mode 100644
index 271b6a5bb..000000000
--- a/src/gui/models/playertablemodel.cpp
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/models/playertablemodel.h"
-
-#include "being/playerrelations.h"
-
-#include "gui/widgets/dropdown.h"
-#include "gui/widgets/label.h"
-
-#include "gui/models/playerrelationlistmodel.h"
-
-#include "utils/delete2.h"
-#include "utils/dtor.h"
-
-#include "debug.h"
-
-static const int COLUMNS_NR = 2; // name plus listbox
-static const int NAME_COLUMN = 0;
-static const unsigned int RELATION_CHOICE_COLUMN = 1;
-
-static const unsigned int ROW_HEIGHT = 12;
-// The following column widths really shouldn't be hardcoded
-// but should scale with the size of the widget... except
-// that, right now, the widget doesn't exactly scale either.
-static const unsigned int NAME_COLUMN_WIDTH = 230;
-static const unsigned int RELATION_CHOICE_COLUMN_WIDTH = 80;
-
-#define WIDGET_AT(row, column) (((row) * COLUMNS_NR) + column)
-
-PlayerTableModel::PlayerTableModel(const Widget2 *const widget) :
- Widget2(widget),
- TableModel(),
- mPlayers(nullptr),
- mWidgets(),
- mListModel(new PlayerRelationListModel)
-{
- playerRelationsUpdated();
-}
-
-PlayerTableModel::~PlayerTableModel()
-{
- freeWidgets();
- delete2(mListModel)
- delete2(mPlayers)
-}
-
-int PlayerTableModel::getRows() const
-{
- if (mPlayers != nullptr)
- return CAST_S32(mPlayers->size());
- return 0;
-}
-
-int PlayerTableModel::getColumns() const
-{
- return COLUMNS_NR;
-}
-
-int PlayerTableModel::getRowHeight() const
-{
- return ROW_HEIGHT;
-}
-
-int PlayerTableModel::getColumnWidth(const int index) const
-{
- if (index == NAME_COLUMN)
- return NAME_COLUMN_WIDTH;
- return RELATION_CHOICE_COLUMN_WIDTH;
-}
-
-void PlayerTableModel::playerRelationsUpdated()
-{
- signalBeforeUpdate();
-
- freeWidgets();
- StringVect *const player_names = playerRelations.getPlayers();
- delete mPlayers;
- mPlayers = player_names;
-
- // set up widgets
- for (unsigned int r = 0, fsz = CAST_U32(
- player_names->size()); r < fsz; ++r)
- {
- const std::string name = (*player_names)[r];
- Widget *const widget = new Label(this, name);
- mWidgets.push_back(widget);
-
- DropDown *const choicebox = new DropDown(this, mListModel);
- choicebox->setSelected(CAST_S32(
- playerRelations.getRelation(name)));
- mWidgets.push_back(choicebox);
- }
-
- signalAfterUpdate();
-}
-
-void PlayerTableModel::updateModelInRow(const int row) const
-{
- const DropDown *const choicebox = static_cast<DropDown *>(
- getElementAt(row, RELATION_CHOICE_COLUMN));
- if (choicebox == nullptr)
- return;
- playerRelations.setRelation(getPlayerAt(row),
- static_cast<RelationT>(
- choicebox->getSelected()));
-}
-
-Widget *PlayerTableModel::getElementAt(int row, int column) const
-{
- return mWidgets[WIDGET_AT(row, column)];
-}
-
-void PlayerTableModel::freeWidgets()
-{
- delete2(mPlayers)
- delete_all(mWidgets);
- mWidgets.clear();
-}
-
-std::string PlayerTableModel::getPlayerAt(const int index) const
-{
- if ((mPlayers == nullptr) || index < 0
- || index >= CAST_S32(mPlayers->size()))
- {
- return std::string();
- }
- return (*mPlayers)[index];
-}
diff --git a/src/gui/models/playertablemodel.h b/src/gui/models/playertablemodel.h
deleted file mode 100644
index dfb00eeb4..000000000
--- a/src/gui/models/playertablemodel.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_PLAYERTABLEMODEL_H
-#define GUI_MODELS_PLAYERTABLEMODEL_H
-
-#include "gui/widgets/widget2.h"
-
-#include "gui/models/tablemodel.h"
-
-#include "localconsts.h"
-
-class PlayerRelationListModel;
-
-class PlayerTableModel final : public Widget2,
- public TableModel
-{
- public:
- explicit PlayerTableModel(const Widget2 *const widget);
-
- A_DELETE_COPY(PlayerTableModel)
-
- ~PlayerTableModel();
-
- int getRows() const override final;
-
- int getColumns() const override final A_CONST;
-
- int getRowHeight() const override final A_CONST;
-
- int getColumnWidth(const int index) const override final A_CONST;
-
- void playerRelationsUpdated();
-
- void updateModelInRow(const int row) const;
-
- Widget *getElementAt(int row, int column) const override final;
-
- void freeWidgets();
-
- std::string getPlayerAt(const int index) const;
-
- protected:
- StringVect *mPlayers;
- STD_VECTOR<Widget *> mWidgets;
- PlayerRelationListModel *mListModel;
-};
-
-#endif // GUI_MODELS_PLAYERTABLEMODEL_H
diff --git a/src/gui/models/questsmodel.h b/src/gui/models/questsmodel.h
deleted file mode 100644
index f80e7a32d..000000000
--- a/src/gui/models/questsmodel.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_QUESTSMODEL_H
-#define GUI_MODELS_QUESTSMODEL_H
-
-#include "gui/models/extendednamesmodel.h"
-
-class QuestsModel final : public ExtendedNamesModel
-{
- public:
- QuestsModel() :
- ExtendedNamesModel()
- {
- }
-
- A_DELETE_COPY(QuestsModel)
-
- ~QuestsModel()
- { }
-};
-
-#endif // GUI_MODELS_QUESTSMODEL_H
diff --git a/src/gui/models/serverslistmodel.h b/src/gui/models/serverslistmodel.h
deleted file mode 100644
index 8e236ebe0..000000000
--- a/src/gui/models/serverslistmodel.h
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_SERVERSLISTMODEL_H
-#define GUI_MODELS_SERVERSLISTMODEL_H
-
-#include "gui/gui.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/windows/serverdialog.h"
-
-#include "gui/models/listmodel.h"
-
-#include "utils/gettext.h"
-
-/**
- * Server and Port List Model
- */
-class ServersListModel final : public ListModel
-{
- public:
- typedef std::pair<int, std::string> VersionString;
-
- ServersListModel(ServerInfos *const servers,
- ServerDialog *const parent) :
- mServers(servers),
- mVersionStrings(servers != nullptr ? servers->size() : 0,
- VersionString(0, "")),
- mParent(parent)
- {
- }
-
- A_DELETE_COPY(ServersListModel)
-
- /**
- * Used to get number of line in the list
- */
- int getNumberOfElements() override final A_WARN_UNUSED
- {
- MutexLocker lock = mParent->lock();
- return CAST_S32(mServers->size());
- }
-
- /**
- * Used to get an element from the list
- */
- std::string getElementAt(int elementIndex)
- override final A_WARN_UNUSED
- {
- MutexLocker lock = mParent->lock();
- const ServerInfo &server = mServers->at(elementIndex);
- std::string myServer;
- if (server.freeType == ServerFreeType::NonFree)
- {
- // TRANSLATORS: server license comment
- myServer.append(_("(NON FREE)"));
- myServer.append(" ");
- }
- else if (server.freeType == ServerFreeType::Unknown)
- {
- // TRANSLATORS: server license comment
- myServer.append(_("(UNKNOWN)"));
- myServer.append(" ");
- }
- myServer.append(server.hostname);
- return myServer;
- }
-
- /**
- * Used to get the corresponding Server struct
- */
- const ServerInfo &getServer(const int elementIndex) const A_WARN_UNUSED
- { return mServers->at(elementIndex); }
-
- void setVersionString(const int index, const std::string &version)
- {
- if (index < 0 || index >= CAST_S32(mVersionStrings.size()))
- return;
-
- if (version.empty() || (gui == nullptr))
- {
- mVersionStrings[index] = VersionString(0, "");
- }
- else
- {
- mVersionStrings[index] = VersionString(
- gui->getFont()->getWidth(version), version);
- }
- }
-
- private:
- typedef STD_VECTOR<VersionString> VersionStrings;
-
- ServerInfos *mServers;
- VersionStrings mVersionStrings;
- ServerDialog *mParent;
-};
-
-#endif // GUI_MODELS_SERVERSLISTMODEL_H
diff --git a/src/gui/models/shopitems.cpp b/src/gui/models/shopitems.cpp
deleted file mode 100644
index 27e05ff12..000000000
--- a/src/gui/models/shopitems.cpp
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/models/shopitems.h"
-
-#include "resources/item/shopitem.h"
-
-#include "utils/dtor.h"
-#include "utils/foreach.h"
-
-#include "debug.h"
-
-ShopItems::ShopItems(const bool mergeDuplicates,
- const std::string &currency) :
- ListModel(),
- mAllShopItems(),
- mShopItems(),
- mCurrency(currency),
- mMergeDuplicates(mergeDuplicates)
-{
-}
-
-ShopItems::~ShopItems()
-{
- clear();
-}
-
-std::string ShopItems::getElementAt(int i)
-{
- if (i < 0 || CAST_U32(i)
- >= CAST_U32(mShopItems.size()) || (mShopItems.at(i) == nullptr))
- {
- return "";
- }
-
- return mShopItems.at(i)->getDisplayName();
-}
-
-ShopItem *ShopItems::addItem(const int id,
- const ItemTypeT type,
- const ItemColor color,
- const int amount,
- const int price)
-{
- ShopItem *const item = new ShopItem(-1,
- id,
- type,
- color,
- amount,
- price,
- mCurrency);
- mShopItems.push_back(item);
- mAllShopItems.push_back(item);
- return item;
-}
-
-ShopItem *ShopItems::addItemNoDup(const int id,
- const ItemTypeT type,
- const ItemColor color,
- const int amount,
- const int price)
-{
- ShopItem *item = findItem(id, color);
- if (item == nullptr)
- {
- item = new ShopItem(-1,
- id,
- type,
- color,
- amount,
- price,
- mCurrency);
- mShopItems.push_back(item);
- mAllShopItems.push_back(item);
- }
- return item;
-}
-
-ShopItem *ShopItems::addItem2(const int inventoryIndex,
- const int id,
- const ItemTypeT type,
- const ItemColor color,
- const int quantity,
- const int price)
-{
- ShopItem *item = nullptr;
- if (mMergeDuplicates)
- item = findItem(id, color);
-
- if (item != nullptr)
- {
- item->addDuplicate(inventoryIndex, quantity);
- }
- else
- {
- item = new ShopItem(inventoryIndex,
- id,
- type,
- color,
- quantity,
- price,
- mCurrency);
- mShopItems.push_back(item);
- mAllShopItems.push_back(item);
- }
- return item;
-}
-
-ShopItem *ShopItems::at(const size_t i) const
-{
- if (i >= mShopItems.size())
- return nullptr;
-
- return mShopItems.at(i);
-}
-
-bool ShopItems::findInAllItems(STD_VECTOR<ShopItem*>::iterator &it,
- const ShopItem *const item)
-{
- const STD_VECTOR<ShopItem*>::iterator it_end = mAllShopItems.end();
- for (it = mAllShopItems.begin(); it != it_end; ++ it)
- {
- if (*it == item)
- return true;
- }
- return false;
-}
-
-void ShopItems::erase(const unsigned int i)
-{
- if (i >= CAST_U32(mShopItems.size()))
- return;
-
- const ShopItem *const item = *(mShopItems.begin() + i);
- STD_VECTOR<ShopItem*>::iterator it;
- if (findInAllItems(it, item))
- mAllShopItems.erase(it);
- mShopItems.erase(mShopItems.begin() + i);
-}
-
-void ShopItems::del(const unsigned int i)
-{
- if (i >= CAST_U32(mShopItems.size()))
- return;
-
- ShopItem *item = *(mShopItems.begin() + i);
- STD_VECTOR<ShopItem*>::iterator it;
- if (findInAllItems(it, item))
- mAllShopItems.erase(it);
- mShopItems.erase(mShopItems.begin() + i);
- delete item;
-}
-
-void ShopItems::clear()
-{
- delete_all(mAllShopItems);
- mAllShopItems.clear();
- mShopItems.clear();
-}
-
-ShopItem *ShopItems::findItem(const int id,
- const ItemColor color) const
-{
- STD_VECTOR<ShopItem*>::const_iterator it = mShopItems.begin();
- const STD_VECTOR<ShopItem*>::const_iterator e = mShopItems.end();
- while (it != e)
- {
- ShopItem *const item = *it;
- if (item->getId() == id && item->getColor() == color)
- return item;
-
- ++it;
- }
-
- return nullptr;
-}
-
-void ShopItems::updateList()
-{
- mShopItems.clear();
- FOR_EACH (STD_VECTOR<ShopItem*>::iterator, it, mAllShopItems)
- {
- ShopItem *const item = *it;
- if ((item != nullptr) && item->isVisible())
- mShopItems.push_back(item);
- }
-}
diff --git a/src/gui/models/shopitems.h b/src/gui/models/shopitems.h
deleted file mode 100644
index 26c5a94e4..000000000
--- a/src/gui/models/shopitems.h
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_SHOPITEMS_H
-#define GUI_MODELS_SHOPITEMS_H
-
-#include "enums/resources/item/itemtype.h"
-
-#include "enums/simpletypes/itemcolor.h"
-
-#include "gui/models/listmodel.h"
-
-#include "utils/cast.h"
-#include "utils/vector.h"
-
-#include "localconsts.h"
-
-class ShopItem;
-
-/**
- * This class handles the list of items available in a shop.
- *
- * The addItem routine can automatically check, if an item already exists and
- * only adds duplicates to the old item, if one is found. The original
- * distribution of the duplicates can be retrieved from the item.
- *
- * This functionality can be enabled in the constructor.
- */
-class ShopItems final : public ListModel
-{
- public:
- /**
- * Constructor.
- *
- * @param mergeDuplicates lets the Shop look for duplicate entries and
- * merges them to one item.
- */
- ShopItems(const bool mergeDuplicates,
- const std::string &currency);
-
- A_DELETE_COPY(ShopItems)
-
- ~ShopItems();
-
- /**
- * Adds an item to the list.
- */
- ShopItem *addItem(const int id,
- const ItemTypeT type,
- const ItemColor color,
- const int amount,
- const int price);
-
- /**
- * Adds an item to the list (used by sell dialog). Looks for
- * duplicate entries, if mergeDuplicates was turned on.
- *
- * @param inventoryIndex the inventory index of the item
- * @param id the id of the item
- * @param amount number of available copies of the item
- * @param price price of the item
- */
- ShopItem *addItem2(const int inventoryIndex,
- const int id,
- const ItemTypeT type,
- const ItemColor color,
- const int amount,
- const int price);
-
- ShopItem *addItemNoDup(const int id,
- const ItemTypeT type,
- const ItemColor color,
- const int amount,
- const int price);
-
- /**
- * Returns the number of items in the shop.
- */
- int getNumberOfElements() override final A_WARN_UNUSED
- { return CAST_S32(mShopItems.size()); }
-
- bool empty() const noexcept2 A_WARN_UNUSED
- { return mShopItems.empty(); }
-
- /**
- * Returns the name of item number i in the shop.
- *
- * @param i the index to retrieve
- */
- std::string getElementAt(int i) override final A_WARN_UNUSED;
-
- /**
- * Returns the item number i in the shop.
- */
- ShopItem *at(const size_t i) const A_WARN_UNUSED;
-
- /**
- * Removes an element from the shop.
- *
- * @param i index to remove
- */
- void erase(const unsigned int i);
-
- /**
- * Removes an element from the shop and destroy it.
- *
- * @param i index to remove
- */
- void del(const unsigned int i);
-
- /**
- * Clears the list of items in the shop.
- */
- void clear();
-
- STD_VECTOR<ShopItem*> &items() A_WARN_UNUSED
- { return mShopItems; }
-
- STD_VECTOR<ShopItem*> &allItems() A_WARN_UNUSED
- { return mAllShopItems; }
-
- void setMergeDuplicates(const bool b)
- { mMergeDuplicates = b; }
-
- void updateList();
-
- private:
- /**
- * Searches the current items in the shop for the specified
- * id and returns the item if found, or 0 else.
- *
- * @return the item found or 0
- */
- ShopItem *findItem(const int id,
- const ItemColor color) const A_WARN_UNUSED;
-
- bool findInAllItems(STD_VECTOR<ShopItem*>::iterator &it,
- const ShopItem *const item);
-
- /** The list of items in the shop. */
- STD_VECTOR<ShopItem*> mAllShopItems;
-
- STD_VECTOR<ShopItem*> mShopItems;
-
- std::string mCurrency;
-
- /** Look for duplicate entries on addition. */
- bool mMergeDuplicates;
-};
-
-#endif // GUI_MODELS_SHOPITEMS_H
diff --git a/src/gui/models/skillmodel.cpp b/src/gui/models/skillmodel.cpp
deleted file mode 100644
index 4d22280d8..000000000
--- a/src/gui/models/skillmodel.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/models/skillmodel.h"
-
-#include "utils/foreach.h"
-
-#include "resources/skill/skilldata.h"
-
-#include "debug.h"
-
-SkillModel::SkillModel() :
- ListModel(),
- mSkills(),
- mVisibleSkills()
-{
-}
-
-SkillInfo *SkillModel::getSkillAt(const int i) const
-{
- if (i < 0 || i >= CAST_S32(mVisibleSkills.size()))
- return nullptr;
- return mVisibleSkills.at(i);
-}
-
-std::string SkillModel::getElementAt(int i)
-{
- const SkillInfo *const info = getSkillAt(i);
- if (info != nullptr)
- return info->data->name;
- return std::string();
-}
-
-void SkillModel::updateVisibilities()
-{
- mVisibleSkills.clear();
-
- FOR_EACH (SkillList::const_iterator, it, mSkills)
- {
- if (((*it) != nullptr) && (*it)->visible == Visible_true)
- mVisibleSkills.push_back((*it));
- }
-}
diff --git a/src/gui/models/skillmodel.h b/src/gui/models/skillmodel.h
deleted file mode 100644
index 6c7792508..000000000
--- a/src/gui/models/skillmodel.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_SKILLMODEL_H
-#define GUI_MODELS_SKILLMODEL_H
-
-#include "gui/models/listmodel.h"
-
-#include "utils/cast.h"
-
-#include "resources/skill/skillinfo.h"
-
-#include "localconsts.h"
-
-class SkillModel final : public ListModel
-{
- public:
- SkillModel();
-
- A_DELETE_COPY(SkillModel)
-
- SkillInfo *getSkillAt(const int i) const;
-
- std::string getElementAt(int i) override final;
-
- int getNumberOfElements() override final
- { return CAST_S32(mVisibleSkills.size()); }
-
- void addSkill(SkillInfo *const info)
- { mSkills.push_back(info); }
-
- void updateVisibilities();
-
- private:
- SkillList mSkills;
- SkillList mVisibleSkills;
-};
-
-#endif // GUI_MODELS_SKILLMODEL_H
diff --git a/src/gui/models/sortlistmodelbuy.h b/src/gui/models/sortlistmodelbuy.h
deleted file mode 100644
index 3af489222..000000000
--- a/src/gui/models/sortlistmodelbuy.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_SORTLISTMODELBUY_H
-#define GUI_MODELS_SORTLISTMODELBUY_H
-
-#include "gui/models/listmodel.h"
-
-#include "utils/gettext.h"
-
-static const char *const SORT_NAME_BUY[7] =
-{
- // TRANSLATORS: buy dialog sort type.
- N_("unsorted"),
- // TRANSLATORS: buy dialog sort type.
- N_("by price"),
- // TRANSLATORS: buy dialog sort type.
- N_("by name"),
- // TRANSLATORS: buy dialog sort type.
- N_("by id"),
- // TRANSLATORS: buy dialog sort type.
- N_("by weight"),
- // TRANSLATORS: buy dialog sort type.
- N_("by amount"),
- // TRANSLATORS: buy dialog sort type.
- N_("by type")
-};
-
-class SortListModelBuy final : public ListModel
-{
- public:
- SortListModelBuy() :
- ListModel()
- { }
-
- A_DELETE_COPY(SortListModelBuy)
-
- ~SortListModelBuy()
- { }
-
- int getNumberOfElements() override final
- { return 7; }
-
- std::string getElementAt(int i) override final
- {
- if (i >= getNumberOfElements() || i < 0)
- return "???";
- return gettext(SORT_NAME_BUY[i]);
- }
-};
-
-#endif // GUI_MODELS_SORTLISTMODELBUY_H
diff --git a/src/gui/models/sortlistmodelinv.h b/src/gui/models/sortlistmodelinv.h
deleted file mode 100644
index 3561d2621..000000000
--- a/src/gui/models/sortlistmodelinv.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_SORTLISTMODELINV_H
-#define GUI_MODELS_SORTLISTMODELINV_H
-
-#include "gui/models/listmodel.h"
-
-#include "utils/gettext.h"
-
-static const char *const SORT_NAME_INVENTORY[6] =
-{
- // TRANSLATORS: inventory sort mode
- N_("default"),
- // TRANSLATORS: inventory sort mode
- N_("by name"),
- // TRANSLATORS: inventory sort mode
- N_("by id"),
- // TRANSLATORS: inventory sort mode
- N_("by weight"),
- // TRANSLATORS: inventory sort mode
- N_("by amount"),
- // TRANSLATORS: inventory sort mode
- N_("by type")
-};
-
-class SortListModelInv final : public ListModel
-{
- public:
- SortListModelInv() :
- ListModel()
- { }
-
- A_DELETE_COPY(SortListModelInv)
-
- ~SortListModelInv()
- { }
-
- int getNumberOfElements() override final
- { return 6; }
-
- std::string getElementAt(int i) override final
- {
- if (i >= getNumberOfElements() || i < 0)
- return "???";
-
- return gettext(SORT_NAME_INVENTORY[i]);
- }
-};
-
-#endif // GUI_MODELS_SORTLISTMODELINV_H
diff --git a/src/gui/models/soundsmodel.h b/src/gui/models/soundsmodel.h
deleted file mode 100644
index ad66049a3..000000000
--- a/src/gui/models/soundsmodel.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_SOUNDSMODEL_H
-#define GUI_MODELS_SOUNDSMODEL_H
-
-#include "gui/theme.h"
-
-#include "gui/models/namesmodel.h"
-
-#include "utils/gettext.h"
-
-#include "localconsts.h"
-
-class SoundsModel final : public NamesModel
-{
- public:
- SoundsModel() :
- NamesModel()
- {
- mNames.push_back(gettext("(no sound)"));
- Theme::fillSoundsList(mNames);
- }
-
- A_DELETE_COPY(SoundsModel)
-
- ~SoundsModel()
- { }
-};
-
-#endif // GUI_MODELS_SOUNDSMODEL_H
diff --git a/src/gui/models/tablemodel.cpp b/src/gui/models/tablemodel.cpp
deleted file mode 100644
index 08cfb6d83..000000000
--- a/src/gui/models/tablemodel.cpp
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/models/tablemodel.h"
-
-#include "utils/dtor.h"
-
-#include "gui/widgets/widget.h"
-
-#include "listeners/tablemodellistener.h"
-
-#include "debug.h"
-
-void TableModel::installListener(TableModelListener *const listener)
-{
- if (listener != nullptr)
- listeners.insert(listener);
-}
-
-void TableModel::removeListener(TableModelListener *const listener)
-{
- if (listener != nullptr)
- listeners.erase(listener);
-}
-
-void TableModel::signalBeforeUpdate()
-{
- for (std::set<TableModelListener *>::const_iterator it = listeners.begin();
- it != listeners.end(); ++it)
- {
- (*it)->modelUpdated(false);
- }
-}
-
-void TableModel::signalAfterUpdate()
-{
- for (std::set<TableModelListener *>::const_iterator it = listeners.begin();
- it != listeners.end(); ++it)
- {
- if (*it != nullptr)
- (*it)->modelUpdated(true);
- }
-}
-
-
-#define WIDGET_AT(row, column) (((row) * mColumns) + (column))
-#define DYN_SIZE(h) ((h) >= 0)
-
-StaticTableModel::StaticTableModel(const int row, const int column) :
- TableModel(),
- mRows(row),
- mColumns(column),
- mHeight(1),
- mTableModel(),
- mWidths()
-{
- mTableModel.resize(row * column, nullptr);
- mWidths.resize(column, 1);
-}
-
-StaticTableModel::~StaticTableModel()
-{
- delete_all(mTableModel);
- mTableModel.clear();
-}
-
-void StaticTableModel::resize()
-{
- mRows = getRows();
- mColumns = getColumns();
- mTableModel.resize(mRows * mColumns, nullptr);
-}
-
-void StaticTableModel::set(const int row, const int column,
- Widget *const widget)
-{
- if ((widget == nullptr) || row >= mRows || row < 0
- || column >= mColumns || column < 0)
- {
- // raise exn?
- return;
- }
-
- if (DYN_SIZE(mHeight)
- && widget->getHeight() > mHeight)
- {
- mHeight = widget->getHeight();
- }
-
- if (DYN_SIZE(mWidths[column])
- && widget->getWidth() > mWidths[column])
- {
- mWidths[column] = widget->getWidth();
- }
-
- signalBeforeUpdate();
-
- delete mTableModel[WIDGET_AT(row, column)];
-
- mTableModel[WIDGET_AT(row, column)] = widget;
-
- signalAfterUpdate();
-}
-
-Widget *StaticTableModel::getElementAt(const int row,
- const int column) const
-{
- return mTableModel[WIDGET_AT(row, column)];
-}
-
-void StaticTableModel::fixColumnWidth(const int column, const int width)
-{
- if (width < 0 || column < 0 || column >= mColumns)
- return;
-
- mWidths[column] = -width; // Negate to tag as fixed
-}
-
-void StaticTableModel::fixRowHeight(const int height)
-{
- if (height < 0)
- return;
-
- mHeight = -height;
-}
-
-int StaticTableModel::getRowHeight() const
-{
- return abs(mHeight);
-}
-
-int StaticTableModel::getColumnWidth(const int column) const
-{
- if (column < 0 || column >= mColumns)
- return 0;
-
- return abs(mWidths[column]);
-}
-
-int StaticTableModel::getRows() const
-{
- return mRows;
-}
-
-int StaticTableModel::getColumns() const
-{
- return mColumns;
-}
-
-int StaticTableModel::getWidth() const
-{
- int width = 0;
-
- for (size_t i = 0, sz = mWidths.size(); i < sz; i++)
- width += mWidths[i];
-
- return width;
-}
-
-int StaticTableModel::getHeight() const
-{
- return mColumns * mHeight;
-}
diff --git a/src/gui/models/tablemodel.h b/src/gui/models/tablemodel.h
deleted file mode 100644
index 23f286c2e..000000000
--- a/src/gui/models/tablemodel.h
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_TABLEMODEL_H
-#define GUI_MODELS_TABLEMODEL_H
-
-#include "utils/vector.h"
-
-#include <set>
-
-#include "localconsts.h"
-
-class Widget;
-
-class TableModelListener;
-
-/**
- * A model for a regular table of widgets.
- */
-class TableModel notfinal
-{
- public:
- A_DELETE_COPY(TableModel)
-
- virtual ~TableModel()
- { }
-
- /**
- * Determines the number of rows (lines) in the table
- */
- virtual int getRows() const A_WARN_UNUSED = 0;
-
- /**
- * Determines the number of columns in each row
- */
- virtual int getColumns() const A_WARN_UNUSED = 0;
-
- /**
- * Determines the height for each row
- */
- virtual int getRowHeight() const A_WARN_UNUSED = 0;
-
- /**
- * Determines the width of each individual column
- */
- virtual int getColumnWidth(const int index) const A_WARN_UNUSED = 0;
-
- /**
- * Retrieves the widget stored at the specified location
- * within the table.
- */
- virtual Widget *getElementAt(const int row, const int column)
- const A_WARN_UNUSED = 0;
-
- virtual void installListener(TableModelListener *const listener);
-
- virtual void removeListener(TableModelListener *const listener);
-
- protected:
- TableModel() :
- listeners()
- {
- }
-
- /**
- * Tells all listeners that the table is about to see an update
- */
- virtual void signalBeforeUpdate();
-
- /**
- * Tells all listeners that the table has seen an update
- */
- virtual void signalAfterUpdate();
-
- private:
- std::set<TableModelListener *> listeners;
-};
-
-
-class StaticTableModel final : public TableModel
-{
- public:
- StaticTableModel(const int width, const int height);
-
- A_DELETE_COPY(StaticTableModel)
-
- ~StaticTableModel();
-
- /**
- * Inserts a widget into the table model.
- * The model is resized to accomodate the widget's width and height,
- * unless column width / row height have been fixed.
- */
- void set(const int row, const int column, Widget *const widget);
-
- /**
- * Fixes the column width for a given column; this overrides dynamic
- * width inference.
- *
- * Semantics are undefined for width 0.
- */
- void fixColumnWidth(const int column, const int width);
-
- /**
- * Fixes the row height; this overrides dynamic height inference.
- *
- * Semantics are undefined for width 0.
- */
- void fixRowHeight(const int height);
-
- /**
- * Resizes the table model
- */
- void resize();
-
- int getRows() const override final A_WARN_UNUSED;
- int getColumns() const override final A_WARN_UNUSED;
- int getRowHeight() const override final A_WARN_UNUSED;
- int getWidth() const A_WARN_UNUSED;
- int getHeight() const A_WARN_UNUSED;
- int getColumnWidth(const int index) const override final A_WARN_UNUSED;
- Widget *getElementAt(const int row,
- const int column) const override final
- A_WARN_UNUSED;
-
- protected:
- int mRows;
- int mColumns;
- int mHeight;
- STD_VECTOR<Widget *> mTableModel;
- STD_VECTOR<int> mWidths;
-};
-
-#endif // GUI_MODELS_TABLEMODEL_H
diff --git a/src/gui/models/targettypemodel.h b/src/gui/models/targettypemodel.h
deleted file mode 100644
index ec049bf66..000000000
--- a/src/gui/models/targettypemodel.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_TARGETTYPEMODEL_H
-#define GUI_MODELS_TARGETTYPEMODEL_H
-
-#include "gui/models/listmodel.h"
-
-#include "utils/gettext.h"
-
-const char *TARGET_TYPE_TEXT[3] =
-{
- // TRANSLATORS: target type
- N_("No Target"),
- // TRANSLATORS: target type
- N_("Allow Target"),
- // TRANSLATORS: target type
- N_("Need Target")
-};
-
-class TargetTypeModel final : public ListModel
-{
- public:
- TargetTypeModel() :
- ListModel()
- { }
-
- A_DELETE_COPY(TargetTypeModel)
-
- ~TargetTypeModel()
- { }
-
- int getNumberOfElements() override final
- {
- return 3;
- }
-
- std::string getElementAt(int i) override final
- {
- if (i >= getNumberOfElements() || i < 0)
- return "???";
- return TARGET_TYPE_TEXT[i];
- }
-};
-
-#endif // GUI_MODELS_TARGETTYPEMODEL_H
diff --git a/src/gui/models/themesmodel.h b/src/gui/models/themesmodel.h
deleted file mode 100644
index c68cc0a2f..000000000
--- a/src/gui/models/themesmodel.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_THEMESMODEL_H
-#define GUI_MODELS_THEMESMODEL_H
-
-#include "gui/theme.h"
-
-#include "gui/models/namesmodel.h"
-
-#include "utils/gettext.h"
-
-#include "localconsts.h"
-
-class ThemesModel final : public NamesModel
-{
- public:
- ThemesModel() :
- NamesModel()
- {
- mNames.push_back(gettext("(default)"));
- Theme::fillSkinsList(mNames);
- }
-
- A_DELETE_COPY(ThemesModel)
-
- ~ThemesModel()
- { }
-};
-
-#endif // GUI_MODELS_THEMESMODEL_H
diff --git a/src/gui/models/touchactionmodel.cpp b/src/gui/models/touchactionmodel.cpp
deleted file mode 100644
index 1998d2752..000000000
--- a/src/gui/models/touchactionmodel.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/setupactiondata.h"
-#include "gui/touchactiondata.h"
-
-#include "gui/models/touchactionmodel.h"
-
-#include "utils/foreach.h"
-
-#include <algorithm>
-
-#include "debug.h"
-
-const int touchActionDataSize = 5;
-
-static class SortTouchActionFunctor final
-{
- public:
- A_DEFAULT_COPY(SortTouchActionFunctor)
-
- bool operator() (const SetupActionData *const data1,
- const SetupActionData *const data2) const
- {
- if ((data1 == nullptr) || (data2 == nullptr))
- return false;
- return data1->name < data2->name;
- }
-} touchActionSorter;
-
-TouchActionsModel::TouchActionsModel() :
- NamesModel(),
- mActionId(),
- mActionToSelection()
-{
- STD_VECTOR<SetupActionData*> data;
-
- for (int f = 0, fsz = touchActionDataSize; f < fsz; f ++)
- {
- int k = 0;
- while (!touchActionData[f][k].name.empty())
- {
- data.push_back(&touchActionData[f][k]);
- k ++;
- }
- }
-
- std::sort(data.begin(), data.end(), touchActionSorter);
- int cnt = 0;
- FOR_EACH (STD_VECTOR<SetupActionData*>::iterator, it, data)
- {
- const SetupActionData *const data1 = *it;
- mNames.push_back(data1->name);
- mActionId.push_back(data1->actionId);
- mActionToSelection[data1->actionId] = cnt;
- cnt ++;
- }
-}
-
-InputActionT TouchActionsModel::getActionFromSelection(const int sel) const
-{
- if (sel < 0 || sel > static_cast<signed int>(mActionId.size()))
- return InputAction::NO_VALUE;
- return mActionId[sel];
-}
-
-int TouchActionsModel::getSelectionFromAction(const InputActionT action) const
-{
- const std::map<InputActionT, int>::const_iterator it
- = mActionToSelection.find(action);
- if (it == mActionToSelection.end())
- return 0;
- return (*it).second;
-}
diff --git a/src/gui/models/touchactionmodel.h b/src/gui/models/touchactionmodel.h
deleted file mode 100644
index 2d8cff02a..000000000
--- a/src/gui/models/touchactionmodel.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_TOUCHACTIONMODEL_H
-#define GUI_MODELS_TOUCHACTIONMODEL_H
-
-#include "enums/input/inputaction.h"
-
-#include "gui/models/namesmodel.h"
-
-#include <map>
-
-class TouchActionsModel final : public NamesModel
-{
- public:
- TouchActionsModel();
-
- A_DELETE_COPY(TouchActionsModel)
-
- ~TouchActionsModel()
- { }
-
- InputActionT getActionFromSelection(const int sel) const;
-
- int getSelectionFromAction(const InputActionT action) const;
-
- private:
- STD_VECTOR<InputActionT> mActionId;
- std::map<InputActionT, int> mActionToSelection;
-};
-
-#endif // GUI_MODELS_TOUCHACTIONMODEL_H
diff --git a/src/gui/models/typelistmodel.h b/src/gui/models/typelistmodel.h
deleted file mode 100644
index 681e019fc..000000000
--- a/src/gui/models/typelistmodel.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2012 The Mana Developers
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_TYPELISTMODEL_H
-#define GUI_MODELS_TYPELISTMODEL_H
-
-#include "gui/models/listmodel.h"
-
-/**
- * Server Type List Model
- */
-class TypeListModel final : public ListModel
-{
- public:
- TypeListModel() :
- ListModel()
- { }
-
- A_DELETE_COPY(TypeListModel)
-
- /**
- * Used to get number of line in the list
- */
- int getNumberOfElements() override final A_WARN_UNUSED
-#if defined(TMWA_SUPPORT)
- { return 3; }
-#else // defined(TMWA_SUPPORT)
- { return 2; }
-#endif // defined(TMWA_SUPPORT)
-
- /**
- * Used to get an element from the list
- */
- std::string getElementAt(int elementIndex)
- override final A_WARN_UNUSED
- {
-#ifdef TMWA_SUPPORT
- if (elementIndex == 0)
- return "TmwAthena";
- else if (elementIndex == 1)
- return "Hercules";
- else if (elementIndex == 2)
- return "Evol2";
- else
-#else // TMWA_SUPPORT
- if (elementIndex == 0)
- return "Hercules";
- else if (elementIndex == 1)
- return "Evol2";
- else
-#endif // TMWA_SUPPORT
- return "Unknown";
- }
-};
-
-#endif // GUI_MODELS_TYPELISTMODEL_H
diff --git a/src/gui/models/updatelistmodel.h b/src/gui/models/updatelistmodel.h
deleted file mode 100644
index cd4ba50c3..000000000
--- a/src/gui/models/updatelistmodel.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_UPDATELISTMODEL_H
-#define GUI_MODELS_UPDATELISTMODEL_H
-
-#include "gui/models/listmodel.h"
-
-#include "net/serverinfo.h"
-
-#include "utils/cast.h"
-#include "utils/foreach.h"
-
-#include "localconsts.h"
-
-class UpdateListModel final : public ListModel
-{
- public:
- explicit UpdateListModel(ServerInfo *const server) :
- ListModel(),
- mNames(),
- mServer(server)
- {
- FOR_EACH(STD_VECTOR<HostsGroup>::const_iterator,
- it,
- server->updateHosts)
- {
- const HostsGroup &group = *it;
- mNames.push_back(group.name);
- }
- }
-
- A_DELETE_COPY(UpdateListModel)
-
- ~UpdateListModel()
- { }
-
- int getNumberOfElements() override final
- {
- return CAST_S32(mNames.size());
- }
-
- std::string getElementAt(int i) override final
- {
- if (i >= getNumberOfElements() || i < 0)
- return "???";
- return mNames[i];
- }
-
- bool empty() const
- {
- return mNames.empty();
- }
-
- protected:
- StringVect mNames;
- ServerInfo *mServer;
-};
-
-#endif // GUI_MODELS_UPDATELISTMODEL_H
diff --git a/src/gui/models/updatetypemodel.h b/src/gui/models/updatetypemodel.h
deleted file mode 100644
index 232be8223..000000000
--- a/src/gui/models/updatetypemodel.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_UPDATETYPEMODEL_H
-#define GUI_MODELS_UPDATETYPEMODEL_H
-
-#include "utils/gettext.h"
-
-#include "gui/models/listmodel.h"
-
-const char *UPDATE_TYPE_TEXT[3] =
-{
- // TRANSLATORS: update type
- N_("Normal"),
- // TRANSLATORS: update type
- N_("Auto Close"),
- // TRANSLATORS: update type
- N_("Skip"),
-};
-
-class UpdateTypeModel final : public ListModel
-{
- public:
- UpdateTypeModel()
- { }
-
- A_DELETE_COPY(UpdateTypeModel)
-
- ~UpdateTypeModel()
- { }
-
- int getNumberOfElements() override final
- {
- return 3;
- }
-
- std::string getElementAt(int i) override final
- {
- if (i >= getNumberOfElements() || i < 0)
- return "???";
- return gettext(UPDATE_TYPE_TEXT[i]);
- }
-};
-
-#endif // GUI_MODELS_UPDATETYPEMODEL_H
diff --git a/src/gui/models/worldlistmodel.h b/src/gui/models/worldlistmodel.h
deleted file mode 100644
index 3be179c61..000000000
--- a/src/gui/models/worldlistmodel.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MODELS_WORLDLISTMODEL_H
-#define GUI_MODELS_WORLDLISTMODEL_H
-
-#include "gui/models/listmodel.h"
-
-#include "utils/cast.h"
-#include "utils/stringutils.h"
-
-#include "net/worldinfo.h"
-
-/**
- * The list model for the server list.
- */
-class WorldListModel final : public ListModel
-{
- public:
- explicit WorldListModel(const Worlds &worlds) :
- mWorlds(worlds)
- {
- }
-
- A_DELETE_COPY(WorldListModel)
-
- ~WorldListModel()
- { }
-
- int getNumberOfElements() override final
- {
- return CAST_S32(mWorlds.size());
- }
-
- std::string getElementAt(int i) override final
- {
- const WorldInfo *const si = mWorlds[i];
- if (si != nullptr)
- {
- return std::string(si->name).append(" (").append(
- toString(si->online_users)).append(")");
- }
- return "???";
- }
- private:
- Worlds mWorlds;
-};
-
-#endif // GUI_MODELS_WORLDLISTMODEL_H
diff --git a/src/gui/mouseoverlink.h b/src/gui/mouseoverlink.h
deleted file mode 100644
index 758d02b6e..000000000
--- a/src/gui/mouseoverlink.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_MOUSEOVERLINK_H
-#define GUI_MOUSEOVERLINK_H
-
-#include "gui/browserlink.h"
-
-#include "localconsts.h"
-
-struct MouseOverLink final
-{
- MouseOverLink(const int x,
- const int y) :
- mX(x),
- mY(y)
- { }
-
- A_DEFAULT_COPY(MouseOverLink)
-
- bool operator() (const BrowserLink &link) const
- {
- return mX >= link.x1 &&
- mX < link.x2 &&
- mY >= link.y1 &&
- mY < link.y2;
- }
- const int mX;
- const int mY;
-};
-
-#endif // GUI_MOUSEOVERLINK_H
diff --git a/src/gui/onlineplayer.h b/src/gui/onlineplayer.h
deleted file mode 100644
index 43ebb5c5f..000000000
--- a/src/gui/onlineplayer.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_ONLINEPLAYER_H
-#define GUI_ONLINEPLAYER_H
-
-#include "enums/being/gender.h"
-
-#include <string>
-
-#include "localconsts.h"
-
-class OnlinePlayer final
-{
- public:
- OnlinePlayer(const std::string &nick,
- const unsigned char status,
- const signed char level,
- const GenderT gender,
- const signed char version) :
- mNick(nick),
- mText(),
- mStatus(status),
- mLevel(level),
- mVersion(version),
- mGender(gender),
- mIsGM(false)
- {
- }
-
- A_DELETE_COPY(OnlinePlayer)
-
- const std::string getNick() const noexcept2 A_WARN_UNUSED
- { return mNick; }
-
- unsigned char getStaus() const noexcept2 A_WARN_UNUSED
- { return mStatus; }
-
- void setIsGM(const bool b)
- { mIsGM = b; }
-
- char getVersion() const noexcept2 A_WARN_UNUSED
- { return mVersion; }
-
- char getLevel() const noexcept2 A_WARN_UNUSED
- { return mLevel; }
-
- const std::string getText() const noexcept2 A_WARN_UNUSED
- { return mText; }
-
- void setText(std::string str);
-
- void setLevel(const char level) noexcept2
- { mLevel = level; }
-
- private:
- std::string mNick;
-
- std::string mText;
-
- unsigned char mStatus;
-
- signed char mLevel;
-
- signed char mVersion;
-
- GenderT mGender;
-
- bool mIsGM;
-};
-
-#endif // GUI_ONLINEPLAYER_H
diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp
deleted file mode 100644
index 7fcf153fe..000000000
--- a/src/gui/palette.cpp
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 Douglas Boffey <dougaboffey@netscape.net>
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/palette.h"
-
-#include "utils/foreach.h"
-#include "utils/timer.h"
-
-#ifndef USE_SDL2
-#include <cmath>
-#endif // USE_SDL2
-
-#include "debug.h"
-
-const Color Palette::BLACK = Color(0, 0, 0);
-Palette::Palettes Palette::mInstances;
-
-const Color Palette::RAINBOW_COLORS[7] =
-{
- Color(255, 0, 0),
- Color(255, 153, 0),
- Color(255, 255, 0),
- Color(0, 153, 0),
- Color(0, 204, 204),
- Color(51, 0, 153),
- Color(153, 0, 153)
-};
-
-const int Palette::RAINBOW_COLOR_COUNT = 7;
-
-Palette::Palette(const int size) :
- mRainbowTime(tick_time),
- mColors(Colors(size)),
- mCharColors(),
- mGradVector()
-{
- mInstances.insert(this);
-}
-
-Palette::~Palette()
-{
- mInstances.erase(this);
-}
-
-const Color& Palette::getCharColor(const signed char c, bool &valid) const
-{
- const CharColors::const_iterator it = mCharColors.find(c);
- if (it != mCharColors.end())
- {
- valid = true;
- return mColors[(*it).second].color;
- }
-
- valid = false;
- return BLACK;
-}
-
-void Palette::advanceGradients()
-{
- FOR_EACH (Palettes::const_iterator, it, mInstances)
- (*it)->advanceGradient();
-}
-
-void Palette::advanceGradient()
-{
- const int time = get_elapsed_time(mRainbowTime);
- if (time > 5)
- {
- // For slower systems, advance can be greater than one (advance > 1
- // skips advance-1 steps). Should make gradient look the same
- // independent of the framerate.
- const int advance = time / 5;
-
- for (size_t i = 0, sz = mGradVector.size(); i < sz; i++)
- {
- ColorElem *const elem A_NONNULLPOINTER = mGradVector[i];
- if (elem == nullptr)
- continue;
-
- int delay = elem->delay;
- const GradientTypeT &grad = elem->grad;
-
- if (grad == GradientType::PULSE)
- delay = delay / 20;
-
- const int numOfColors = (elem->grad == GradientType::SPECTRUM ? 6 :
- grad == GradientType::PULSE ? 127 :
- RAINBOW_COLOR_COUNT);
-
- elem->gradientIndex = (elem->gradientIndex + advance)
- % (delay * numOfColors);
-
- const int gradIndex = elem->gradientIndex;
- const int pos = delay != 0 ? (gradIndex % delay) : gradIndex;
- int colIndex;
- if (delay != 0)
- colIndex = gradIndex / delay;
- else
- colIndex = gradIndex;
-
- Color &color = elem->color;
- int colVal;
-
- if (grad == GradientType::PULSE)
- {
- colVal = CAST_S32(255.0 *
- sin(M_PI * colIndex / numOfColors));
-
- const Color &col = elem->testColor;
-
- color.r = ((colVal * col.r) / 255) % (col.r + 1);
- color.g = ((colVal * col.g) / 255) % (col.g + 1);
- color.b = ((colVal * col.b) / 255) % (col.b + 1);
- }
- else if (grad == GradientType::SPECTRUM)
- {
- if ((colIndex % 2) != 0)
- { // falling curve
- if (delay != 0)
- {
- colVal = CAST_S32(255.0 *
- (cos(M_PI * pos / delay) + 1) / 2);
- }
- else
- {
- colVal = CAST_S32(255.0 *
- (cos(M_PI * pos) + 1) / 2);
- }
- }
- else
- { // ascending curve
- if (delay != 0)
- {
- colVal = CAST_S32(255.0 * (cos(M_PI *
- (delay - pos) / delay) + 1) / 2);
- }
- else
- {
- colVal = CAST_S32(255.0 * (cos(M_PI *
- (delay - pos)) + 1) / 2);
- }
- }
-
- color.r = (colIndex == 0 || colIndex == 5) ? 255 :
- (colIndex == 1 || colIndex == 4) ? colVal : 0;
- color.g = (colIndex == 1 || colIndex == 2) ? 255 :
- (colIndex == 0 || colIndex == 3) ? colVal : 0;
- color.b = (colIndex == 3 || colIndex == 4) ? 255 :
- (colIndex == 2 || colIndex == 5) ? colVal : 0;
- }
- else if (elem->grad == GradientType::RAINBOW)
- {
- const Color &startCol = RAINBOW_COLORS[colIndex];
- const Color &destCol
- = RAINBOW_COLORS[(colIndex + 1) % numOfColors];
- double startColVal;
- double destColVal;
-
- if (delay != 0)
- startColVal = (cos(M_PI * pos / delay) + 1) / 2;
- else
- startColVal = 0;
-
- destColVal = 1 - startColVal;
-
- color.r = CAST_S32(startColVal
- * startCol.r + destColVal * destCol.r);
-
- color.g = CAST_S32(startColVal
- * startCol.g + destColVal * destCol.g);
-
- color.b = CAST_S32(startColVal
- * startCol.b + destColVal * destCol.b);
- }
- }
-
- mRainbowTime = tick_time;
- }
-}
diff --git a/src/gui/palette.h b/src/gui/palette.h
deleted file mode 100644
index 048dacf54..000000000
--- a/src/gui/palette.h
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 Douglas Boffey <dougaboffey@netscape.net>
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_PALETTE_H
-#define GUI_PALETTE_H
-
-#include "enums/gui/gradienttype.h"
-
-#include "gui/color.h"
-
-#include "utils/vector.h"
-
-#include <map>
-#include <set>
-#include <string>
-
-// Default Gradient Delay
-#define GRADIENT_DELAY 40
-
-/**
- * Class controlling the game's color palette.
- */
-class Palette notfinal
-{
- public:
- /** Black Color Constant */
- static const Color BLACK;
-
- A_DELETE_COPY(Palette)
-
- /**
- * Returns the color associated with a character, if it exists. Returns
- * Palette::BLACK if the character is not found.
- *
- * @param c character requested
- * @param valid indicate whether character is known
- *
- * @return the requested color or Palette::BLACK
- */
- const Color &getCharColor(const signed char c,
- bool &valid) const A_WARN_UNUSED;
-
- /**
- * Get the character used by the specified color.
- *
- * @param type the color type of the color
- *
- * @return the color char of the color with the given index
- */
- inline char getColorChar(const int type) const A_WARN_UNUSED
- { return mColors[CAST_SIZE(type)].ch; }
-
- /**
- * Updates all colors, that are non-static.
- */
- static void advanceGradients();
-
- protected:
- /** Colors used for the rainbow gradient */
- static const Color RAINBOW_COLORS[7];
- static const int RAINBOW_COLOR_COUNT;
-
- /** Time tick, that gradient-type colors were updated the last time. */
- int mRainbowTime;
-
- typedef std::set<Palette*> Palettes;
- static Palettes mInstances;
-
- /**
- * Constructor
- */
- explicit Palette(const int size);
-
- /**
- * Destructor
- */
- virtual ~Palette();
-
- void advanceGradient();
-
- struct ColorElem final
- {
- ColorElem() :
- type(0),
- color(0),
- testColor(0),
- committedColor(0),
- text(),
- ch(0),
- grad(GradientType::STATIC),
- committedGrad(GradientType::STATIC),
- gradientIndex(0),
- delay(0),
- committedDelay(0)
- {
- }
-
- A_DEFAULT_COPY(ColorElem)
-
- int type;
- Color color;
- Color testColor;
- Color committedColor;
- std::string text;
- signed char ch;
- GradientTypeT grad;
- GradientTypeT committedGrad;
- int gradientIndex;
- int delay;
- int committedDelay;
-
- void set(const int type0,
- const Color &color0,
- const GradientTypeT grad0,
- const int delay0)
- {
- type = type0;
- color = color0;
- testColor = color0;
- grad = grad0;
- delay = delay0;
- gradientIndex = rand();
- }
-
- inline unsigned int getRGB() const noexcept2 A_WARN_UNUSED
- {
- return (committedColor.r << 16) | (committedColor.g << 8) |
- committedColor.b;
- }
- };
- typedef STD_VECTOR<ColorElem> Colors;
- typedef std::map<unsigned char, int> CharColors;
- Colors mColors;
- CharColors mCharColors;
- STD_VECTOR<ColorElem*> mGradVector;
-};
-
-#endif // GUI_PALETTE_H
diff --git a/src/gui/popupmanager.cpp b/src/gui/popupmanager.cpp
deleted file mode 100644
index 134aaac7b..000000000
--- a/src/gui/popupmanager.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/popupmanager.h"
-
-#include "sdlshared.h"
-
-#ifndef DYECMD
-#include "gui/popups/beingpopup.h"
-#include "gui/popups/itempopup.h"
-#include "gui/popups/popupmenu.h"
-#endif // DYECMD
-#include "gui/popups/textpopup.h"
-
-#include "debug.h"
-
-PopupManager *popupManager = nullptr;
-
-PopupManager::PopupManager()
-{
-}
-
-PopupManager::~PopupManager()
-{
-}
-
-void PopupManager::closePopupMenu()
-{
-#ifndef DYECMD
- if (popupMenu != nullptr)
- popupMenu->handleLink("cancel", nullptr);
-#endif // DYECMD
-}
-
-void PopupManager::hideBeingPopup()
-{
-#ifndef DYECMD
- if (beingPopup != nullptr)
- beingPopup->setVisible(Visible_false);
-#endif // DYECMD
-}
-
-void PopupManager::hideTextPopup()
-{
- if (textPopup != nullptr)
- textPopup->setVisible(Visible_false);
-}
-
-void PopupManager::hidePopupMenu()
-{
-#ifndef DYECMD
- if (popupMenu != nullptr)
- popupMenu->setVisible(Visible_false);
-#endif // DYECMD
-}
-
-void PopupManager::hideItemPopup()
-{
-#ifndef DYECMD
- if (itemPopup != nullptr)
- itemPopup->hide();
-#endif // DYECMD
-}
-
-bool PopupManager::isPopupMenuVisible()
-{
-#ifndef DYECMD
- return popupMenu != nullptr ? popupMenu->isPopupVisible() : false;
-#else
- return false;
-#endif // DYECMD
-}
-
-void PopupManager::clearPopup()
-{
-#ifndef DYECMD
- if (popupMenu != nullptr)
- popupMenu->clear();
-#endif // DYECMD
-}
-
-bool PopupManager::isTextPopupVisible()
-{
- return textPopup != nullptr ? textPopup->isPopupVisible() : false;
-}
-
-bool PopupManager::isBeingPopupVisible()
-{
-#ifndef DYECMD
- return beingPopup != nullptr ? beingPopup->isPopupVisible() : false;
-#else // DYECMD
- return false;
-#endif // DYECMD
-}
diff --git a/src/gui/popupmanager.h b/src/gui/popupmanager.h
deleted file mode 100644
index a3dd08a54..000000000
--- a/src/gui/popupmanager.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_POPUPMANAGER_H
-#define GUI_POPUPMANAGER_H
-
-#include "localconsts.h"
-
-class PopupManager final
-{
- public:
- /**
- * Constructor.
- */
- PopupManager() A_CONST;
-
- A_DELETE_COPY(PopupManager)
-
- /**
- * Destructor.
- */
- ~PopupManager() A_CONST;
-
- static bool isBeingPopupVisible() A_WARN_UNUSED;
-
- static bool isTextPopupVisible() A_WARN_UNUSED;
-
- /**
- * Closes the popup menu. Needed for when the player dies or switching
- * maps.
- */
- static void closePopupMenu();
-
- /**
- * Hides the BeingPopup.
- */
- static void hideBeingPopup();
-
- static void hideTextPopup();
-
- static void hideItemPopup();
-
- static bool isPopupMenuVisible() A_WARN_UNUSED;
-
- static void clearPopup();
-
- static void hidePopupMenu();
-};
-
-extern PopupManager *popupManager;
-
-#endif // GUI_POPUPMANAGER_H
diff --git a/src/gui/popups/beingpopup.cpp b/src/gui/popups/beingpopup.cpp
deleted file mode 100644
index 299683f6d..000000000
--- a/src/gui/popups/beingpopup.cpp
+++ /dev/null
@@ -1,337 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/popups/beingpopup.h"
-
-#include "being/being.h"
-#include "being/homunculusinfo.h"
-#include "being/petinfo.h"
-#include "being/playerinfo.h"
-#include "being/playerrelations.h"
-
-#include "gui/gui.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/widgets/label.h"
-
-#include "resources/chatobject.h"
-
-#include "resources/db/groupdb.h"
-
-#include "utils/gettext.h"
-#include "utils/foreach.h"
-#include "utils/stringutils.h"
-
-#include "debug.h"
-
-BeingPopup *beingPopup = nullptr;
-
-BeingPopup::BeingPopup() :
- Popup("BeingPopup", "beingpopup.xml"),
- mBeingName(new Label(this, "A")),
- mLabels()
-{
- // Being Name
- mBeingName->setFont(boldFont);
- mBeingName->setPosition(0, 0);
-
- const int fontHeight = mBeingName->getHeight();
- setMinHeight(fontHeight);
- addLabels(fontHeight);
-}
-
-BeingPopup::~BeingPopup()
-{
-}
-
-void BeingPopup::postInit()
-{
- Popup::postInit();
- add(mBeingName);
- FOR_EACH (STD_VECTOR<Label*>::iterator, it, mLabels)
- {
- add(*it);
- }
-}
-
-void BeingPopup::addLabels(const int fontHeight)
-{
- for (int f = 0; f < 11; f ++)
- {
- Label *const label = new Label(this, "A");
- label->setPosition(0, fontHeight * (f + 1));
- label->setForegroundColorAll(getThemeColor(ThemeColorId::POPUP),
- getThemeColor(ThemeColorId::POPUP_OUTLINE));
- mLabels.push_back(label);
- }
-}
-
-void BeingPopup::show(const int x, const int y, Being *const b)
-{
- if (b == nullptr)
- {
- setVisible(Visible_false);
- return;
- }
-
- int num = 0;
- Label *ptr = nullptr;
- b->updateComment();
-
- if (b->getType() == ActorType::Npc && b->getComment().empty())
- {
- setVisible(Visible_false);
- return;
- }
-
- mBeingName->setCaption(b->getName() + b->getGenderSignWithSpace());
- if (gui != nullptr)
- {
- if (playerRelations.isGoodName(b))
- mBeingName->setFont(boldFont);
- else
- mBeingName->setFont(gui->getSecureFont());
- }
- if (b->isAdvanced())
- {
- mBeingName->setForegroundColorAll(getThemeColor(
- ThemeColorId::PLAYER_ADVANCED), getThemeColor(
- ThemeColorId::PLAYER_ADVANCED_OUTLINE));
- }
- else
- {
- mBeingName->setForegroundColorAll(getThemeColor(ThemeColorId::POPUP),
- getThemeColor(ThemeColorId::POPUP_OUTLINE));
- }
-
- mBeingName->adjustSize();
- FOR_EACH (STD_VECTOR<Label*>::iterator, it, mLabels)
- {
- (*it)->setCaption(std::string());
- }
-
- const ActorTypeT type = b->getType();
- if (type == ActorType::Pet)
- {
- const PetInfo *const info = PlayerInfo::getPet();
- if ((info != nullptr) && info->id == b->getId())
- {
- ptr = mLabels[num];
- // TRANSLATORS: being popup label
- ptr->setCaption(strprintf(_("Hungry: %d"),
- info->hungry));
- ptr->adjustSize();
- num ++;
- ptr = mLabels[num];
- // TRANSLATORS: being popup label
- ptr->setCaption(strprintf(_("Intimacy: %d"),
- info->intimacy));
- ptr->adjustSize();
- num ++;
- }
- }
- else if (type == ActorType::Homunculus)
- {
- const HomunculusInfo *const info = PlayerInfo::getHomunculus();
- if ((info != nullptr) && info->id == b->getId())
- {
- ptr = mLabels[num];
- // TRANSLATORS: being popup label
- ptr->setCaption(strprintf(_("Hungry: %d"),
- info->hungry));
- ptr->adjustSize();
- num ++;
- ptr = mLabels[num];
- // TRANSLATORS: being popup label
- ptr->setCaption(strprintf(_("Intimacy: %d"),
- info->intimacy));
- ptr->adjustSize();
- num ++;
- }
- }
- else
- {
- const int groupId = b->getGroupId();
- const std::string &groupName = GroupDb::getLongName(groupId);
- if (!groupName.empty())
- {
- ptr = mLabels[num];
- // TRANSLATORS: being popup label
- ptr->setCaption(strprintf(_("Group: %s (%d)"),
- groupName.c_str(),
- groupId));
- ptr->adjustSize();
- num ++;
- }
-
- if (!(b->getPartyName().empty()))
- {
- ptr = mLabels[num];
- // TRANSLATORS: being popup label
- ptr->setCaption(strprintf(_("Party: %s"),
- b->getPartyName().c_str()));
- ptr->adjustSize();
- num ++;
- }
-
- if (!(b->getGuildName().empty()))
- {
- ptr = mLabels[num];
- // TRANSLATORS: being popup label
- ptr->setCaption(strprintf(_("Guild: %s"),
- b->getGuildName().c_str()));
- ptr->adjustSize();
- num ++;
- }
-
- if (b->getPvpRank() > 0)
- {
- ptr = mLabels[num];
- // TRANSLATORS: being popup label
- ptr->setCaption(strprintf(_("Pvp rank: %u"),
- b->getPvpRank()));
- ptr->adjustSize();
- num ++;
- }
-
- if (!b->getBuyBoard().empty())
- {
- ptr = mLabels[num];
- // TRANSLATORS: being popup label
- ptr->setCaption(strprintf(_("Buy shop: %s"),
- b->getBuyBoard().c_str()));
- ptr->adjustSize();
- num ++;
- }
-
- if (!b->getSellBoard().empty())
- {
- ptr = mLabels[num];
- // TRANSLATORS: being popup label
- ptr->setCaption(strprintf(_("Sell shop: %s"),
- b->getSellBoard().c_str()));
- ptr->adjustSize();
- num ++;
- }
-
- if (!b->getComment().empty())
- {
- ptr = mLabels[num];
- // TRANSLATORS: being popup label
- ptr->setCaption(strprintf(_("Comment: %s"),
- b->getComment().c_str()));
- ptr->adjustSize();
- num ++;
- }
-
- const std::string effects = b->getStatusEffectsString();
- if (!effects.empty())
- {
- ptr = mLabels[num];
- // TRANSLATORS: being popup label
- ptr->setCaption(strprintf(_("Effects: %s"),
- effects.c_str()));
- ptr->adjustSize();
- num ++;
- }
-
- const ChatObject *const chat = b->getChat();
- if (chat != nullptr)
- {
- ptr = mLabels[num];
- // TRANSLATORS: being popup label
- ptr->setCaption(strprintf(_("Chat room: %s"),
- chat->title.c_str()));
- ptr->adjustSize();
- num ++;
- }
- }
-
- const int level = b->getLevel();
- if (level > 1)
- {
- ptr = mLabels[num];
- // TRANSLATORS: being popup label
- ptr->setCaption(strprintf(_("Level: %d"),
- level));
- ptr->adjustSize();
- num ++;
- }
-
- const int maxHp = b->getMaxHP();
- if (maxHp > 0)
- {
- int hp = b->getHP();
- if (hp == 0)
- hp = maxHp - b->getDamageTaken();
- if (hp > 0)
- {
- ptr = mLabels[num];
- // TRANSLATORS: being popup label
- ptr->setCaption(strprintf(_("Hp: %d/%d"),
- hp,
- maxHp));
- ptr->adjustSize();
- num ++;
- }
- }
-
- ptr = mLabels[num];
- // TRANSLATORS: being popup label
- ptr->setCaption(strprintf(_("Particles: %u"),
- CAST_U32(b->getParticlesCount())));
- ptr->adjustSize();
- num ++;
-
- const size_t sz = mLabels.size();
- for (size_t f = num; f < sz; f ++)
- {
- mLabels[f]->setCaption(std::string());
- }
-
- int minWidth = mBeingName->getWidth();
- const int height1 = getFont()->getHeight();
- int height = height1;
- FOR_EACH (STD_VECTOR<Label*>::iterator, it, mLabels)
- {
- const Label *const label = *it;
- if (label != nullptr)
- {
- if (label->getWidth() > minWidth)
- minWidth = label->getWidth();
- if (!label->getCaption().empty())
- height += height1;
- }
- }
-
- setContentSize(minWidth, height);
- position(x, y);
-}
-
-#ifdef USE_PROFILER
-void BeingPopup::logic()
-{
- BLOCK_START("BeingPopup::logic")
- logicChildren();
- BLOCK_END("BeingPopup::logic")
-}
-#endif // USE_PROFILER
diff --git a/src/gui/popups/beingpopup.h b/src/gui/popups/beingpopup.h
deleted file mode 100644
index a14f44568..000000000
--- a/src/gui/popups/beingpopup.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_POPUPS_BEINGPOPUP_H
-#define GUI_POPUPS_BEINGPOPUP_H
-
-#include "gui/widgets/popup.h"
-
-class Being;
-class Label;
-
-/**
- * A popup that displays information about a being.
- */
-class BeingPopup final : public Popup
-{
- public:
- /**
- * Constructor. Initializes the being popup.
- */
- BeingPopup();
-
- A_DELETE_COPY(BeingPopup)
-
- /**
- * Destructor. Cleans up the being popup on deletion.
- */
- ~BeingPopup();
-
- /**
- * Sets the info to be displayed given a particular player.
- */
- void show(const int x, const int y, Being *const b);
-
- void postInit() override final;
-
-#ifdef USE_PROFILER
- void logic();
-#endif // USE_PROFILER
-
- private:
- void addLabels(const int fontHeight);
-
- Label *mBeingName A_NONNULLPOINTER;
- STD_VECTOR<Label*> mLabels;
-};
-
-extern BeingPopup *beingPopup;
-
-#endif // GUI_POPUPS_BEINGPOPUP_H
diff --git a/src/gui/popups/itempopup.cpp b/src/gui/popups/itempopup.cpp
deleted file mode 100644
index 28de3b641..000000000
--- a/src/gui/popups/itempopup.cpp
+++ /dev/null
@@ -1,465 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 The Legend of Mazzeroth Development Team
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/popups/itempopup.h"
-
-#include "actormanager.h"
-#include "configuration.h"
-
-#include "gui/gui.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/widgets/icon.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/textbox.h"
-
-#include "net/beinghandler.h"
-#ifdef TMWA_SUPPORT
-#include "net/net.h"
-#endif // TMWA_SUPPORT
-
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-#include "utils/stdmove.h"
-
-#include "utils/translation/podict.h"
-
-#include "resources/iteminfo.h"
-
-#include "resources/db/itemoptiondb.h"
-#include "resources/db/unitsdb.h"
-
-#include "resources/image/image.h"
-
-#include "resources/item/item.h"
-#include "resources/item/itemfieldtype.h"
-#include "resources/item/itemoptionslist.h"
-
-#include "resources/loaders/imageloader.h"
-
-#include "debug.h"
-
-ItemPopup *itemPopup = nullptr;
-
-ItemPopup::ItemPopup() :
- Popup("ItemPopup", "itempopup.xml"),
- mItemName(new Label(this)),
- mItemDesc(new TextBox(this)),
- mItemEffect(new TextBox(this)),
- mItemWeight(new TextBox(this)),
- mItemCards(new TextBox(this)),
- mItemOptions(new TextBox(this)),
- mItemType(ItemDbType::UNUSABLE),
- mIcon(new Icon(this, nullptr)),
- mLastName(),
- mCardsStr(),
- mItemOptionsStr(),
- mLastId(0),
- mLastColor(ItemColor_one)
-{
- // Item name
- mItemName->setFont(boldFont);
- mItemName->setPosition(0, 0);
-
- const int fontHeight = getFont()->getHeight();
-
- // Item description
- mItemDesc->setEditable(false);
- mItemDesc->setPosition(0, fontHeight);
- mItemDesc->setForegroundColorAll(getThemeColor(ThemeColorId::POPUP),
- getThemeColor(ThemeColorId::POPUP_OUTLINE));
-
- // Item effect
- mItemEffect->setEditable(false);
- mItemEffect->setPosition(0, 2 * fontHeight);
- mItemEffect->setForegroundColorAll(getThemeColor(ThemeColorId::POPUP),
- getThemeColor(ThemeColorId::POPUP_OUTLINE));
-
- // Item weight
- mItemWeight->setEditable(false);
- mItemWeight->setPosition(0, 3 * fontHeight);
- mItemWeight->setForegroundColorAll(getThemeColor(ThemeColorId::POPUP),
- getThemeColor(ThemeColorId::POPUP_OUTLINE));
-
- // Item cards
- mItemCards->setEditable(false);
- mItemCards->setPosition(0, 4 * fontHeight);
- mItemCards->setForegroundColorAll(getThemeColor(ThemeColorId::POPUP),
- getThemeColor(ThemeColorId::POPUP_OUTLINE));
-
- // Item options
- mItemOptions->setEditable(false);
- mItemOptions->setPosition(0, 5 * fontHeight);
- mItemOptions->setForegroundColorAll(getThemeColor(ThemeColorId::POPUP),
- getThemeColor(ThemeColorId::POPUP_OUTLINE));
-}
-
-void ItemPopup::postInit()
-{
- Popup::postInit();
- add(mItemName);
- add(mItemDesc);
- add(mItemEffect);
- add(mItemWeight);
- add(mItemCards);
- add(mItemOptions);
- add(mIcon);
-
- addMouseListener(this);
-}
-
-ItemPopup::~ItemPopup()
-{
- if (mIcon != nullptr)
- {
- Image *const image = mIcon->getImage();
- if (image != nullptr)
- image->decRef();
- }
-}
-
-void ItemPopup::setItem(const Item *const item,
- const bool showImage)
-{
- if (item == nullptr)
- return;
-
- const ItemInfo &ii = item->getInfo();
- setItem(ii,
- item->getColor(),
- showImage,
- item->getId(),
- item->getCards(),
- item->getOptions());
- if (item->getRefine() > 0)
- {
- mLastName = ii.getName();
- mLastColor = item->getColor();
- mLastId = item->getId();
-#ifdef TMWA_SUPPORT
- if (Net::getNetworkType() == ServerType::TMWATHENA)
- {
- mItemName->setCaption(strprintf("%s (+%u), %d",
- ii.getName().c_str(),
- CAST_U32(item->getRefine()),
- ii.getId()));
- }
- else
-#endif // TMWA_SUPPORT
- {
- mItemName->setCaption(strprintf("%s (+%u), %d",
- ii.getName(item->getColor()).c_str(),
- CAST_U32(item->getRefine()),
- ii.getId()));
- }
- mItemName->adjustSize();
- const unsigned minWidth = mItemName->getWidth() + 8;
- if (CAST_U32(getWidth()) < minWidth)
- setWidth(minWidth);
- }
-}
-
-void ItemPopup::setItem(const ItemInfo &item,
- const ItemColor color,
- const bool showImage,
- int id,
- const int *const cards,
- const ItemOptionsList *const options)
-{
- if (mIcon == nullptr)
- return;
-
- std::string cardsStr;
- std::string optionsStr;
-
- if (item.getName() == mLastName &&
- color == mLastColor &&
- id == mLastId)
- {
- cardsStr = getCardsString(cards);
- optionsStr = getOptionsString(options);
- if (mItemOptionsStr == optionsStr &&
- mCardsStr == cardsStr)
- {
- return;
- }
- }
- else
- {
- cardsStr = getCardsString(cards);
- optionsStr = getOptionsString(options);
- }
- mItemOptionsStr = STD_MOVE(optionsStr);
- mCardsStr = STD_MOVE(cardsStr);
-
- if (id == -1)
- id = item.getId();
-
- int space = 0;
-
- Image *const oldImage = mIcon->getImage();
- if (oldImage != nullptr)
- oldImage->decRef();
-
- if (showImage)
- {
- Image *const image = Loader::getImage(combineDye2(
- pathJoin(paths.getStringValue("itemIcons"),
- item.getDisplay().image),
- item.getDyeIconColorsString(color)));
-
- mIcon->setImage(image);
- if (image != nullptr)
- {
- mIcon->setPosition(0, 0);
- space = mIcon->getWidth();
- }
- }
- else
- {
- mIcon->setImage(nullptr);
- }
-
- mItemType = item.getType();
-
- mLastName = item.getName();
- mLastColor = color;
- mLastId = id;
-
-#ifdef TMWA_SUPPORT
- if (Net::getNetworkType() == ServerType::TMWATHENA)
- {
- mItemName->setCaption(strprintf("%s, %d",
- item.getName().c_str(), id));
- mItemDesc->setTextWrapped(item.getDescription(), 196);
- }
- else
-#endif // TMWA_SUPPORT
- {
- mItemName->setCaption(strprintf("%s, %d",
- item.getName(color).c_str(), id));
- mItemDesc->setTextWrapped(item.getDescription(color), 196);
- }
-
- mItemName->adjustSize();
- setLabelColor(mItemName, mItemType);
- mItemName->setPosition(space, 0);
-
- mItemEffect->setTextWrapped(item.getEffect(), 196);
- // TRANSLATORS: popup label
- mItemWeight->setTextWrapped(strprintf(_("Weight: %s"),
- UnitsDb::formatWeight(item.getWeight()).c_str()), 196);
- mItemCards->setTextWrapped(mCardsStr, 196);
- mItemOptions->setTextWrapped(mItemOptionsStr, 196);
-
- int minWidth = mItemName->getWidth() + space;
-
- if (mItemName->getWidth() + space > minWidth)
- minWidth = mItemName->getWidth() + space;
- if (mItemDesc->getMinWidth() > minWidth)
- minWidth = mItemDesc->getMinWidth();
- if (mItemEffect->getMinWidth() > minWidth)
- minWidth = mItemEffect->getMinWidth();
- if (mItemWeight->getMinWidth() > minWidth)
- minWidth = mItemWeight->getMinWidth();
- if (mItemCards->getMinWidth() > minWidth)
- minWidth = mItemCards->getMinWidth();
- if (mItemOptions->getMinWidth() > minWidth)
- minWidth = mItemOptions->getMinWidth();
-
- const int numRowsDesc = mItemDesc->getNumberOfRows();
- const int numRowsEffect = mItemEffect->getNumberOfRows();
- const int numRowsWeight = mItemWeight->getNumberOfRows();
- const int numRowsCards = mItemCards->getNumberOfRows();
- const int numRowsOptions = mItemOptions->getNumberOfRows();
- const int height = getFont()->getHeight();
-
- if (item.getEffect().empty())
- {
- setContentSize(minWidth,
- (numRowsDesc + 2 + numRowsWeight + numRowsCards + numRowsOptions) *
- height);
- mItemWeight->setPosition(0, (numRowsDesc + 2) * height);
- mItemCards->setPosition(0, (numRowsDesc + numRowsWeight + 2) * height);
- mItemOptions->setPosition(0,
- (numRowsDesc + numRowsWeight + numRowsCards + 2) * height);
- }
- else
- {
- setContentSize(minWidth, (numRowsDesc + numRowsEffect + 2
- + numRowsWeight + numRowsCards + numRowsOptions) * height);
- mItemEffect->setPosition(0, (numRowsDesc + 2) * height);
- mItemWeight->setPosition(0, (numRowsDesc + numRowsEffect + 2)
- * height);
- mItemCards->setPosition(0, (numRowsDesc + numRowsEffect
- + numRowsWeight + 2) * height);
- mItemOptions->setPosition(0, (numRowsDesc + numRowsEffect
- + numRowsWeight + numRowsCards + 2) * height);
- }
-
- mItemDesc->setPosition(0, 2 * height);
-}
-
-std::string ItemPopup::getCardsString(const int *const cards)
-{
- if (cards == nullptr)
- return std::string();
-
- std::string label;
-
- switch (cards[0])
- {
- case 0xfe: // named item
- {
- const int32_t charId = cards[2] + 65536 * cards[3];
- std::string name = actorManager->findCharById(charId);
- if (name.empty())
- {
- name = toString(charId);
- beingHandler->requestNameByCharId(charId);
- mLastId = 0; // allow recreate popup with same data
- }
- // TRANSLATORS: named item description
- label.append(strprintf(_("Item named: %s"), name.c_str()));
- return label;
- }
- case 0x00FFU: // forged item
- {
- return label;
- }
- case 0xFF00U:
- {
- return label;
- }
- default:
- {
- for (int f = 0; f < maxCards; f ++)
- {
- const int id = cards[f];
- if (id != 0)
- {
- if (!label.empty())
- label.append(" / ");
- const ItemInfo &info = ItemDB::get(id);
- label.append(info.getName());
- }
- }
- if (label.empty())
- return label;
- // TRANSLATORS: popup label
- return _("Cards: ") + label;
- }
- }
-}
-
-std::string ItemPopup::getOptionsString(const ItemOptionsList *const options)
-{
- if (options == nullptr || translator == nullptr)
- return std::string();
- const size_t sz = options->size();
- std::string effect;
- for (size_t f = 0; f < sz; f ++)
- {
- const ItemOption &option = options->get(f);
- if (option.index == 0)
- continue;
- const STD_VECTOR<ItemFieldType*> &fields = ItemOptionDb::getFields(
- option.index);
- if (fields.empty())
- continue;
- const std::string valueStr = toString(option.value);
- FOR_EACH (STD_VECTOR<ItemFieldType*>::const_iterator, it, fields)
- {
- const ItemFieldType *const field = *it;
- std::string value = valueStr;
- if (!effect.empty())
- effect.append(" / ");
- if (field->sign && value[0] != '-')
- value = std::string("+").append(value);
- const std::string format = translator->getStr(field->description);
- effect.append(strprintf(format.c_str(),
- value.c_str()));
- }
- }
- if (effect.empty())
- return effect;
- // TRANSLATORS: popup label
- return _("Options: ") + effect;
-}
-
-#define caseSetColor(name1, name2) \
- case name1: \
- { \
- return label->setForegroundColorAll(getThemeColor(name2), \
- getThemeColor(name2##_OUTLINE)); \
- }
-void ItemPopup::setLabelColor(Label *label,
- const ItemDbTypeT type) const
-{
- switch (type)
- {
- caseSetColor(ItemDbType::UNUSABLE, ThemeColorId::GENERIC)
- caseSetColor(ItemDbType::USABLE, ThemeColorId::USABLE)
- caseSetColor(ItemDbType::EQUIPMENT_ONE_HAND_WEAPON,
- ThemeColorId::ONEHAND)
- caseSetColor(ItemDbType::EQUIPMENT_TWO_HANDS_WEAPON,
- ThemeColorId::TWOHAND)
- caseSetColor(ItemDbType::EQUIPMENT_TORSO, ThemeColorId::TORSO)
- caseSetColor(ItemDbType::EQUIPMENT_ARMS, ThemeColorId::ARMS)
- caseSetColor(ItemDbType::EQUIPMENT_HEAD, ThemeColorId::HEAD)
- caseSetColor(ItemDbType::EQUIPMENT_LEGS, ThemeColorId::LEGS)
- caseSetColor(ItemDbType::EQUIPMENT_SHIELD, ThemeColorId::SHIELD)
- caseSetColor(ItemDbType::EQUIPMENT_RING, ThemeColorId::RING)
- caseSetColor(ItemDbType::EQUIPMENT_NECKLACE, ThemeColorId::NECKLACE)
- caseSetColor(ItemDbType::EQUIPMENT_FEET, ThemeColorId::FEET)
- caseSetColor(ItemDbType::EQUIPMENT_AMMO, ThemeColorId::AMMO)
- caseSetColor(ItemDbType::EQUIPMENT_CHARM, ThemeColorId::CHARM)
- caseSetColor(ItemDbType::SPRITE_RACE, ThemeColorId::UNKNOWN_ITEM)
- caseSetColor(ItemDbType::SPRITE_HAIR, ThemeColorId::UNKNOWN_ITEM)
- caseSetColor(ItemDbType::CARD, ThemeColorId::CARD)
- default:
- {
- return label->setForegroundColorAll(getThemeColor(
- ThemeColorId::UNKNOWN_ITEM), getThemeColor(
- ThemeColorId::UNKNOWN_ITEM_OUTLINE));
- }
- }
-}
-#undef caseSetColor
-
-void ItemPopup::mouseMoved(MouseEvent &event)
-{
- Popup::mouseMoved(event);
-
- // When the mouse moved on top of the popup, hide it
- setVisible(Visible_false);
- resetPopup();
-}
-
-void ItemPopup::resetPopup()
-{
- mLastName.clear();
- mLastColor = ItemColor_one;
- mLastId = 0;
-}
diff --git a/src/gui/popups/itempopup.h b/src/gui/popups/itempopup.h
deleted file mode 100644
index fff3b817d..000000000
--- a/src/gui/popups/itempopup.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 The Legend of Mazzeroth Development Team
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_POPUPS_ITEMPOPUP_H
-#define GUI_POPUPS_ITEMPOPUP_H
-
-#include "enums/resources/item/itemdbtype.h"
-
-#include "enums/simpletypes/itemcolor.h"
-
-#include "gui/widgets/popup.h"
-
-class Icon;
-class Item;
-class ItemInfo;
-class Label;
-class TextBox;
-
-struct ItemOptionsList;
-
-/**
- * A popup that displays information about an item.
- */
-class ItemPopup final : public Popup
-{
- public:
- /**
- * Constructor. Initializes the item popup.
- */
- ItemPopup();
-
- A_DELETE_COPY(ItemPopup)
-
- /**
- * Destructor. Cleans up the item popup on deletion.
- */
- ~ItemPopup();
-
- void postInit() override final;
-
- /**
- * Sets the info to be displayed given a particular item.
- */
- void setItem(const ItemInfo &item,
- const ItemColor color,
- const bool showImage,
- int id,
- const int *const cards,
- const ItemOptionsList *const options);
-
- void setItem(const Item *const item,
- const bool showImage);
-
- void mouseMoved(MouseEvent &event) override final;
-
- void resetPopup();
-
- private:
- std::string getCardsString(const int *const cards);
-
- std::string getOptionsString(const ItemOptionsList *const options);
-
- Label *mItemName A_NONNULLPOINTER;
- TextBox *mItemDesc A_NONNULLPOINTER;
- TextBox *mItemEffect A_NONNULLPOINTER;
- TextBox *mItemWeight A_NONNULLPOINTER;
- TextBox *mItemCards A_NONNULLPOINTER;
- TextBox *mItemOptions A_NONNULLPOINTER;
- ItemDbTypeT mItemType;
- Icon *mIcon A_NONNULLPOINTER;
- std::string mLastName;
- std::string mCardsStr;
- std::string mItemOptionsStr;
- int mLastId;
- ItemColor mLastColor;
-
- void setLabelColor(Label *label,
- const ItemDbTypeT type) const A_NONNULL(2);
-};
-
-extern ItemPopup *itemPopup;
-
-#endif // GUI_POPUPS_ITEMPOPUP_H
diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp
deleted file mode 100644
index 752caff72..000000000
--- a/src/gui/popups/popupmenu.cpp
+++ /dev/null
@@ -1,3613 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/popups/popupmenu.h"
-
-#include "actormanager.h"
-#include "configuration.h"
-#include "party.h"
-#include "settings.h"
-
-#include "being/flooritem.h"
-#include "being/localplayer.h"
-#include "being/playerinfo.h"
-#include "being/playerrelation.h"
-#include "being/playerrelations.h"
-
-#include "const/spells.h"
-
-#include "enums/resources/map/mapitemtype.h"
-
-#include "input/inputmanager.h"
-
-#include "gui/buttontext.h"
-#include "gui/gui.h"
-#include "gui/popupmanager.h"
-#include "gui/viewport.h"
-#include "gui/windowmenu.h"
-
-#include "gui/windows/chatwindow.h"
-#include "gui/windows/inventorywindow.h"
-#include "gui/windows/minimap.h"
-#include "gui/windows/ministatuswindow.h"
-#include "gui/windows/npcdialog.h"
-#include "gui/windows/outfitwindow.h"
-#include "gui/windows/socialwindow.h"
-#include "gui/windows/textcommandeditor.h"
-#include "gui/windows/textdialog.h"
-#include "gui/windows/tradewindow.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/progressbar.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/staticbrowserbox.h"
-#include "gui/widgets/textfield.h"
-
-#include "gui/widgets/tabs/chat/whispertab.h"
-
-#include "net/adminhandler.h"
-#include "net/chathandler.h"
-#include "net/guildhandler.h"
-#include "net/npchandler.h"
-#include "net/net.h"
-
-#ifdef TMWA_SUPPORT
-#include "net/tmwa/guildmanager.h"
-#endif // TMWA_SUPPORT
-
-#include "resources/chatobject.h"
-#include "resources/groupinfo.h"
-#include "resources/iteminfo.h"
-#include "resources/itemmenuitem.h"
-
-#include "resources/db/groupdb.h"
-#include "resources/db/npcdb.h"
-
-#include "resources/item/item.h"
-
-#include "resources/map/map.h"
-#include "resources/map/mapitem.h"
-#include "resources/map/speciallayer.h"
-
-#include "resources/skill/skillinfo.h"
-
-#include "utils/checkutils.h"
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-std::string tradePartnerName;
-
-PopupMenu *popupMenu = nullptr;
-
-PopupMenu::PopupMenu() :
- Popup("PopupMenu", "popupmenu.xml"),
- mBrowserBox(new StaticBrowserBox(this, Opaque_true,
- "popupbrowserbox.xml")),
- mScrollArea(nullptr),
- mBeingId(BeingId_zero),
- mFloorItemId(BeingId_zero),
- mItemId(0),
- mItemIndex(-1),
- mItemColor(ItemColor_one),
- mMapItem(nullptr),
- mTab(nullptr),
- mSpell(nullptr),
- mCallerWindow(nullptr),
- mRenameListener(),
- mPlayerListener(),
- mDialog(nullptr),
- mButton(nullptr),
- mGroup(nullptr),
- mName(),
- mExtName(),
- mTextField(nullptr),
- mType(ActorType::Unknown),
- mSubType(BeingTypeId_zero),
- mX(0),
- mY(0),
- mAllowCleanMenu(true)
-{
- mBrowserBox->setOpaque(Opaque_false);
- mBrowserBox->setLinkHandler(this);
- mRenameListener.setMapItem(nullptr);
- mRenameListener.setDialog(nullptr);
- mPlayerListener.setNick("");
- mPlayerListener.setDialog(nullptr);
- mPlayerListener.setType(ActorType::Unknown);
- mScrollArea = new ScrollArea(this, mBrowserBox, Opaque_false);
- mScrollArea->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO);
- addMouseListener(this);
-}
-
-void PopupMenu::postInit()
-{
- Popup::postInit();
- add(mScrollArea);
-}
-
-void PopupMenu::initPopup()
-{
- if (localPlayer == nullptr)
- return;
- const int groupId = localPlayer->getGroupId();
- mGroup = GroupDb::getGroup(groupId);
-}
-
-bool PopupMenu::isAllowCommand(const ServerCommandTypeT command)
-{
- if (mGroup == nullptr)
- return false;
-#ifdef TMWA_SUPPORT
- // allow any commands for legacy if group > 0
- if (Net::getNetworkType() == ServerType::TMWATHENA &&
- localPlayer != nullptr &&
- localPlayer->isGM())
- {
- return true;
- }
-#endif
- if (mGroup->mPermissions[CAST_SIZE(ServerPermissionType::all_commands)] ==
- Enable_true)
- {
- return true;
- }
- const ServerCommandEnable::Type enabled =
- mGroup->mCommands[CAST_SIZE(command)];
- return (enabled & ServerCommandEnable::Self) != 0;
-}
-
-bool PopupMenu::isAllowOtherCommand(const ServerCommandTypeT command)
-{
- if (mGroup == nullptr ||
- localPlayer == nullptr)
- return false;
-#ifdef TMWA_SUPPORT
- // allow any commands for legacy if group > 0
- if (Net::getNetworkType() == ServerType::TMWATHENA &&
- localPlayer->isGM())
- {
- return true;
- }
-#endif
- const ServerCommandEnable::Type enabled =
- mGroup->mCommands[CAST_SIZE(command)];
- if (mName == localPlayer->getName())
- return (enabled & ServerCommandEnable::Self) != 0;
- return (enabled & ServerCommandEnable::Other) != 0;
-}
-
-void PopupMenu::showPopup(const int x, const int y, const Being *const being)
-{
- if (being == nullptr ||
- localPlayer == nullptr ||
- actorManager == nullptr)
- {
- return;
- }
-
- initPopup();
- mBeingId = being->getId();
- mName = being->getName();
- mExtName = being->getExtName();
- mType = being->getType();
- mSubType = being->getSubType();
- mBrowserBox->clearRows();
- mX = x;
- mY = y;
-
- const std::string &name = mName;
- if (being->getType() != ActorType::SkillUnit)
- {
- mBrowserBox->addRow(name + being->getGenderSignWithSpace());
- }
-
- switch (being->getType())
- {
- case ActorType::Player:
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: trade with player
- mBrowserBox->addRow("/trade 'NAME'", _("Trade"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: trade attack player
- mBrowserBox->addRow("/attack 'NAME'", _("Attack"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: send whisper to player
- mBrowserBox->addRow("/whispertext 'NAME'", _("Whisper"));
- addMailCommands();
- addGmCommands();
- mBrowserBox->addSeparator("##3---");
-
-#ifdef TMWA_SUPPORT
- if (Net::getNetworkType() == ServerType::TMWATHENA)
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: heal player
- mBrowserBox->addRow("/heal :'BEINGID'", _("Heal"));
- mBrowserBox->addSeparator("##3---");
- }
-#endif // TMWA_SUPPORT
-
- addPlayerRelation(name);
- mBrowserBox->addSeparator("##3---");
-
- addFollow();
- addPartyName(being->getPartyName());
-
- const Guild *const guild1 = being->getGuild();
- const Guild *const guild2 = localPlayer->getGuild();
- if (guild2 != nullptr)
- {
- if (guild1 != nullptr)
- {
- if (guild1->getId() == guild2->getId())
- {
- mBrowserBox->addRow("/kickguild 'NAME'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: kick player from guild
- _("Kick from guild"));
- if (guild2->getServerGuild())
- {
- mBrowserBox->addRow(strprintf(
- "@@guild-pos|%s >@@",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: change player position in guild
- _("Change pos in guild")));
- }
- }
- }
- else if (guild2->getMember(mName) != nullptr)
- {
- mBrowserBox->addRow("/kickguild 'NAME'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: kick player from guild
- _("Kick from guild"));
- if (guild2->getServerGuild())
- {
- mBrowserBox->addRow(strprintf(
- "@@guild-pos|%s >@@",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: change player position in guild
- _("Change pos in guild")));
- }
- }
- else
- {
-#ifdef TMWA_SUPPORT
- if (guild2->getServerGuild() ||
- (guildManager != nullptr && guildManager->havePower()))
-#endif // TMWA_SUPPORT
- {
- mBrowserBox->addRow("/guild 'NAME'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: invite player to guild
- _("Invite to guild"));
- }
- }
- }
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: set player invisible for self by id
- mBrowserBox->addRow("/nuke 'NAME'", _("Nuke"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: move to player location
- mBrowserBox->addRow("/navigateto 'NAME'", _("Move"));
- addPlayerMisc();
- addBuySell(being);
- addChat(being);
- break;
- }
-
- case ActorType::Npc:
- if (!addBeingMenu())
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: talk with npc
- mBrowserBox->addRow("/talk 'NAME'", _("Talk"));
-#ifdef TMWA_SUPPORT
- if (Net::getNetworkType() != ServerType::TMWATHENA)
-#endif
- {
- mBrowserBox->addRow("/whispertext NPC:'NAME'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: whisper to npc
- _("Whisper"));
- }
- // TRANSLATORS: popup menu item
- // TRANSLATORS: buy from npc
- mBrowserBox->addRow("/buy 'NAME'", _("Buy"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: sell to npc
- mBrowserBox->addRow("/sell 'NAME'", _("Sell"));
- }
-
- addGmCommands();
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: move to npc location
- mBrowserBox->addRow("/navigateto 'NAME'", _("Move"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add comment to npc
- mBrowserBox->addRow("addcomment", _("Add comment"));
- addChat(being);
- break;
-
- case ActorType::Monster:
- {
- // Monsters can be attacked
- // TRANSLATORS: popup menu item
- // TRANSLATORS: attack monster
- mBrowserBox->addRow("/attack :'BEINGID'", _("Attack"));
- addCatchPetCommands();
- addGmCommands();
- mBrowserBox->addSeparator("##3---");
-
- if (config.getBoolValue("enableAttackFilter"))
- {
- mBrowserBox->addSeparator("##3---");
- if (actorManager->isInAttackList(name)
- || actorManager->isInIgnoreAttackList(name)
- || actorManager->isInPriorityAttackList(name))
- {
- mBrowserBox->addRow("/removeattack 'NAME'",
- // TRANSLATORS: remove monster from attack list
- // TRANSLATORS: popup menu item
- _("Remove from attack list"));
- }
- else
- {
- mBrowserBox->addRow("/addpriorityattack 'NAME'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add monster to priotiry attack list
- _("Add to priority attack list"));
- mBrowserBox->addRow("/addattack 'NAME'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add monster to attack list
- _("Add to attack list"));
- mBrowserBox->addRow("/addignoreattack 'NAME'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add monster to ignore list
- _("Add to ignore list"));
- }
- }
- break;
- }
-
- case ActorType::Mercenary:
- // TRANSLATORS: popup menu item
- // TRANSLATORS: Mercenary move to master
- mBrowserBox->addRow("/mercenarytomaster", _("Move to master"));
- addGmCommands();
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: fire mercenary
- mBrowserBox->addRow("/firemercenary", _("Fire"));
- mBrowserBox->addSeparator("##3---");
- break;
-
- case ActorType::Homunculus:
- {
- const HomunculusInfo *const info = PlayerInfo::getHomunculus();
- if (info != nullptr)
- {
- mBrowserBox->addRow("/homunculustomaster",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: homunculus move to master
- _("Move to master"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: feed homunculus
- mBrowserBox->addRow("/homunculusfeed", _("Feed"));
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: pet rename item
- mBrowserBox->addRow("/sethomunname", _("Rename"));
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: delete homunculus
- mBrowserBox->addRow("/homunculusfire", _("Kill"));
- mBrowserBox->addSeparator("##3---");
- }
- addGmCommands();
- break;
- }
- case ActorType::Pet:
- if (being->getOwner() == localPlayer)
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: feed pet
- mBrowserBox->addRow("/petfeed", _("Feed"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: pet drop loot
- mBrowserBox->addRow("/petdroploot", _("Drop loot"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: pet unequip item
- mBrowserBox->addRow("/petunequip", _("Unequip"));
- addGmCommands();
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: pet rename item
- mBrowserBox->addRow("/setpetname", _("Rename"));
- mBrowserBox->addSeparator("##3---");
- const BeingInfo *const info = being->getInfo();
- std::string msg;
- if (info != nullptr)
- msg = info->getString(0);
- if (!msg.empty())
- {
- mBrowserBox->addRow("/petreturnegg", msg.c_str());
- }
- else
- {
- mBrowserBox->addRow("/petreturnegg",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: pet return to egg
- _("Return to egg"));
- }
- mBrowserBox->addSeparator("##3---");
- }
- else
- {
- addCatchPetCommands();
- }
- break;
- case ActorType::SkillUnit:
- {
- const BeingId id = being->getCreatorId();
- std::string creatorName;
- Being *const creator = actorManager->findBeing(id);
- if (creator != nullptr)
- creatorName = creator->getName();
- else
- creatorName = actorManager->getSeenPlayerById(id);
-
- if (creatorName.empty())
- creatorName = strprintf("?%d", CAST_S32(id));
-
- mBrowserBox->addRow(strprintf("%s, %d (%s)",
- name.c_str(),
- CAST_S32(being->getSubType()),
- creatorName.c_str()));
- break;
- }
- case ActorType::Avatar:
- case ActorType::Unknown:
- case ActorType::FloorItem:
- case ActorType::Portal:
- case ActorType::Elemental:
- default:
- break;
- }
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add being name to chat
- mBrowserBox->addRow("/addtext 'NAME'", _("Add name to chat"));
- mBrowserBox->addSeparator("##3---");
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(x, y);
-}
-
-bool PopupMenu::addBeingMenu()
-{
- Being *being = actorManager->findBeing(mBeingId);
- if (being == nullptr)
- return false;
-
- BeingInfo *const info = NPCDB::get(fromInt(
- being->getSubType(), BeingTypeId));
- if (info == nullptr)
- return false;
-
- const STD_VECTOR<BeingMenuItem> &menu = info->getMenu();
- FOR_EACH (STD_VECTOR<BeingMenuItem>::const_iterator, it, menu)
- {
- const BeingMenuItem &item = *it;
- mBrowserBox->addRow("/" + item.command, item.name.c_str());
- }
- return true;
-}
-
-void PopupMenu::setMousePos()
-{
- if (viewport != nullptr)
- {
- mX = viewport->mMouseX;
- mY = viewport->mMouseY;
- }
- else
- {
- Gui::getMouseState(mX, mY);
- }
-}
-
-void PopupMenu::setMousePos2()
-{
- if (mX == 0 && mY == 0)
- {
- if (viewport != nullptr)
- {
- mX = viewport->mMouseX;
- mY = viewport->mMouseY;
- }
- else
- {
- Gui::getMouseState(mX, mY);
- }
- }
-}
-
-void PopupMenu::showPopup(const int x, const int y,
- const STD_VECTOR<ActorSprite*> &beings)
-{
- initPopup();
- mX = x;
- mY = y;
- mBrowserBox->clearRows();
- // TRANSLATORS: popup menu header
- mBrowserBox->addRow(_("Players"));
- FOR_EACH (STD_VECTOR<ActorSprite*>::const_iterator, it, beings)
- {
- const Being *const being = dynamic_cast<const Being*>(*it);
- const ActorSprite *const actor = *it;
- if ((being != nullptr) && !being->getName().empty())
- {
- mBrowserBox->addRow(strprintf("@@player_%u|%s >@@",
- CAST_U32(being->getId()), (being->getName()
- + being->getGenderSignWithSpace()).c_str()));
- }
- else if (actor->getType() == ActorType::FloorItem)
- {
- const FloorItem *const floorItem
- = static_cast<const FloorItem*>(actor);
- mBrowserBox->addRow(strprintf("@@flooritem_%u|%s >@@",
- CAST_U32(actor->getId()),
- floorItem->getName().c_str()));
- }
- }
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
- showPopup(x, y);
-}
-
-void PopupMenu::showPlayerPopup(const std::string &nick)
-{
- if (nick.empty() || (localPlayer == nullptr))
- return;
-
- initPopup();
- setMousePos();
- mName = nick;
- mExtName = nick;
- mBeingId = BeingId_zero;
- mType = ActorType::Player;
- mSubType = BeingTypeId_zero;
- mBrowserBox->clearRows();
-
- const std::string &name = mName;
-
- mBrowserBox->addRow(name);
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: send whisper to player
- mBrowserBox->addRow("/whispertext 'NAME'", _("Whisper"));
- addMailCommands();
- addGmCommands();
- mBrowserBox->addSeparator("##3---");
-
- addPlayerRelation(name);
- mBrowserBox->addSeparator("##3---");
-
- addFollow();
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add comment to player
- mBrowserBox->addRow("addcomment", _("Add comment"));
-
- if (localPlayer->isInParty())
- {
- const Party *const party = localPlayer->getParty();
- if (party != nullptr)
- {
- const PartyMember *const member = party->getMember(mName);
- if (member != nullptr)
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: kick player from party
- mBrowserBox->addRow("/kickparty 'NAME'", _("Kick from party"));
- mBrowserBox->addSeparator("##3---");
- const PartyMember *const o = party->getMember(
- localPlayer->getName());
- showAdoptCommands();
- if ((o != nullptr) && member->getMap() == o->getMap())
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: move to player position
- mBrowserBox->addRow("/navigate 'X' 'Y'", _("Move"));
- }
- }
- }
- }
-
- const Guild *const guild2 = localPlayer->getGuild();
- if (guild2 != nullptr)
- {
- if (guild2->getMember(mName) != nullptr)
- {
-#ifdef TMWA_SUPPORT
- if (guild2->getServerGuild() || (guildManager != nullptr
- && guildManager->havePower()))
-#endif // TMWA_SUPPORT
- {
- mBrowserBox->addRow("/kickguild 'NAME'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: kick player from guild
- _("Kick from guild"));
- }
- if (guild2->getServerGuild())
- {
- mBrowserBox->addRow(strprintf(
- // TRANSLATORS: popup menu item
- // TRANSLATORS: change player position in guild
- "@@guild-pos|%s >@@", _("Change pos in guild")));
- }
- }
- else
- {
-#ifdef TMWA_SUPPORT
- if (guild2->getServerGuild() || (guildManager != nullptr
- && guildManager->havePower()))
-#endif // TMWA_SUPPORT
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: invite player to guild
- mBrowserBox->addRow("/guild 'NAME'", _("Invite to guild"));
- }
- }
- }
-
- addBuySellDefault();
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add player name to chat
- mBrowserBox->addRow("/addtext 'NAME'", _("Add name to chat"));
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(mX, mY);
-}
-
-void PopupMenu::showPopup(const int x, const int y,
- const FloorItem *const floorItem)
-{
- if (floorItem == nullptr)
- return;
-
- initPopup();
- mX = x;
- mY = y;
- mFloorItemId = floorItem->getId();
- mItemId = floorItem->getItemId();
- mType = ActorType::FloorItem;
- mSubType = BeingTypeId_zero;
- for (int f = 0; f < maxCards; f ++)
- mItemCards[f] = floorItem->getCard(f);
- mBrowserBox->clearRows();
- const std::string name = floorItem->getName();
- mName = name;
- mExtName = name;
-
- mBrowserBox->addRow(name);
-
- if (config.getBoolValue("enablePickupFilter"))
- {
- if (actorManager->isInPickupList(name)
- || (actorManager->isInPickupList("")
- && !actorManager->isInIgnorePickupList(name)))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: pickup item from ground
- mBrowserBox->addRow("/pickup 'FLOORID'", _("Pick up"));
- mBrowserBox->addSeparator("##3---");
- }
- addPickupFilter(name);
- }
- else
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: pickup item from ground
- mBrowserBox->addRow("/pickup 'FLOORID'", _("Pick up"));
- }
- addProtection();
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add item name to chat
- mBrowserBox->addRow("/addchat 'FLOORID''CARDS'", _("Add to chat"));
- mBrowserBox->addSeparator("##3---");
- addGmCommands();
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(mX, mY);
-}
-
-void PopupMenu::showPopup(const int x, const int y, MapItem *const mapItem)
-{
- if (mapItem == nullptr)
- return;
-
- initPopup();
- mMapItem = mapItem;
- mX = x;
- mY = y;
-
- mBrowserBox->clearRows();
-
- // TRANSLATORS: popup menu header
- mBrowserBox->addRow(_("Map Item"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: rename map item
- mBrowserBox->addRow("rename map", _("Rename"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: remove map item
- mBrowserBox->addRow("remove map", _("Remove"));
-
- if (isAllowCommand(ServerCommandType::slide))
- {
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: warp to map item
- mBrowserBox->addRow("/slide 'MAPX' 'MAPY'", _("Warp"));
- }
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(x, y);
-}
-
-void PopupMenu::showMapPopup(const int x, const int y,
- const int x2, const int y2,
- const bool isMinimap)
-{
- initPopup();
- mX = x2;
- mY = y2;
-
- if (isMinimap)
- mCallerWindow = minimap;
-
- mBrowserBox->clearRows();
-
- // TRANSLATORS: popup menu header
- mBrowserBox->addRow(_("Map Item"));
-
- if (isAllowCommand(ServerCommandType::slide))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: warp to map item
- mBrowserBox->addRow("/slide 'MAPX' 'MAPY'", _("Warp"));
- }
- // TRANSLATORS: popup menu item
- // TRANSLATORS: move to map item
- mBrowserBox->addRow("/navigate 'X' 'Y'", _("Move"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: move camera to map item
- mBrowserBox->addRow("/movecamera 'X' 'Y'", _("Move camera"));
- if (settings.cameraMode != 0)
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: restore camera to default view
- mBrowserBox->addRow("/restorecamera", _("Restore camera"));
- }
- mBrowserBox->addSeparator("##3---");
- if (isMinimap)
- {
- // TRANSLATORS: popup menu item
- mBrowserBox->addRow("window close", _("Close"));
- }
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(x, y);
-}
-
-void PopupMenu::showOutfitsWindowPopup(const int x, const int y)
-{
- initPopup();
- mX = x;
- mY = y;
- mCallerWindow = outfitWindow;
-
- mBrowserBox->clearRows();
-
- // TRANSLATORS: popup menu header
- mBrowserBox->addRow(_("Outfits"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: copy selected outfit to chat input
- mBrowserBox->addRow("/outfittochat", _("Add to chat"));
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: copy equipment from player to outfit
- mBrowserBox->addRow("/itemstooutfit", _("Copy from player"));
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: clear selected outfit
- mBrowserBox->addRow("/clearoutfit", _("Clear outfit"));
- mBrowserBox->addSeparator("##3---");
-
- addWindowMenu(outfitWindow);
- mBrowserBox->addSeparator("##3---");
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(x, y);
-}
-
-void PopupMenu::showSpellPopup(const int x, const int y,
- TextCommand *const cmd)
-{
- if (cmd == nullptr)
- return;
-
- initPopup();
- mBrowserBox->clearRows();
-
- mSpell = cmd;
- mX = x;
- mY = y;
-
- // TRANSLATORS: popup menu header
- mBrowserBox->addRow(_("Spells"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: edit selected spell
- mBrowserBox->addRow("edit spell", _("Edit spell"));
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(x, y);
-}
-
-void PopupMenu::showChatPopup(const int x, const int y, ChatTab *const tab)
-{
- if (tab == nullptr ||
- actorManager == nullptr ||
- localPlayer == nullptr)
- {
- return;
- }
-
- initPopup();
- mTab = tab;
- mX = x;
- mY = y;
- mCallerWindow = chatWindow;
-
- mBrowserBox->clearRows();
-
- const ChatTabTypeT &type = tab->getType();
- if (type == ChatTabType::WHISPER || type == ChatTabType::CHANNEL)
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close chat tab
- mBrowserBox->addRow("/close", _("Close"));
- }
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: remove all text from chat tab
- mBrowserBox->addRow("/chatclear", _("Clear"));
- mBrowserBox->addSeparator("##3---");
-
- if (tab->getAllowHighlight())
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: disable chat tab highlight
- mBrowserBox->addRow("/disablehighlight", _("Disable highlight"));
- }
- else
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: enable chat tab highlight
- mBrowserBox->addRow("/enablehighlight", _("Enable highlight"));
- }
- if (tab->getRemoveNames())
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: do not remove player names from chat tab
- mBrowserBox->addRow("/dontremovename", _("Don't remove name"));
- }
- else
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: remove player names from chat tab
- mBrowserBox->addRow("/removename", _("Remove name"));
- }
- if (tab->getNoAway())
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: enable away messages in chat tab
- mBrowserBox->addRow("/enableaway", _("Enable away"));
- }
- else
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: disable away messages in chat tab
- mBrowserBox->addRow("/disableaway", _("Disable away"));
- }
- mBrowserBox->addSeparator("##3---");
- if (type == ChatTabType::PARTY)
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: enable away messages in chat tab
- mBrowserBox->addRow("/leaveparty", _("Leave"));
- mBrowserBox->addSeparator("##3---");
- }
- // TRANSLATORS: popup menu item
- // TRANSLATORS: copy selected text to clipboard
- mBrowserBox->addRow("/chatclipboard 'X' 'Y'", _("Copy to clipboard"));
- mBrowserBox->addSeparator("##3---");
-
- if (type == ChatTabType::WHISPER)
- {
- const WhisperTab *const wTab = static_cast<WhisperTab*>(tab);
- const std::string &name = wTab->getNick();
-
- const Being* const being = actorManager->findBeingByName(
- name, ActorType::Player);
-
- addGmCommands();
- if (being != nullptr)
- {
- mBeingId = being->getId();
- mName = being->getName();
- mExtName = being->getExtName();
- mType = being->getType();
- mSubType = being->getSubType();
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: trade with player
- mBrowserBox->addRow("/trade 'NAME'", _("Trade"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: attack player
- mBrowserBox->addRow("/attack 'NAME'", _("Attack"));
- addMailCommands();
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: heal player
- mBrowserBox->addRow("/heal :'BEINGID'", _("Heal"));
- mBrowserBox->addSeparator("##3---");
- addPlayerRelation(name);
- mBrowserBox->addSeparator("##3---");
- addFollow();
- // TRANSLATORS: popup menu item
- // TRANSLATORS: move to player position
- mBrowserBox->addRow("/navigateto 'NAME'", _("Move"));
- addPlayerMisc();
- addBuySell(being);
- mBrowserBox->addSeparator("##3---");
- addParty(wTab->getNick());
- const Guild *const guild1 = being->getGuild();
- const Guild *const guild2 = localPlayer->getGuild();
- if (guild2 != nullptr)
- {
- if (guild1 != nullptr)
- {
- if (guild1->getId() == guild2->getId())
- {
-#ifdef TMWA_SUPPORT
- if (guild2->getServerGuild() ||
- (guildManager != nullptr &&
- guildManager->havePower()))
-#endif // TMWA_SUPPORT
- {
- mBrowserBox->addRow("/kickguild 'NAME'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: kick player from guild
- _("Kick from guild"));
- }
- if (guild2->getServerGuild())
- {
- mBrowserBox->addRow(strprintf("@@guild-pos|%s >@@",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: change player position in guild
- _("Change pos in guild")));
- }
- }
- }
- else
- {
-#ifdef TMWA_SUPPORT
- if (guild2->getServerGuild() || (guildManager != nullptr
- && guildManager->havePower()))
-#endif // TMWA_SUPPORT
- {
- mBrowserBox->addRow("/guild 'NAME'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: invite player to guild
- _("Invite to guild"));
- }
- }
- }
- }
- else
- {
- mBeingId = BeingId_zero;
- mName = name;
- mExtName = name;
- mType = ActorType::Player;
- mSubType = BeingTypeId_zero;
- addPlayerRelation(name);
- mBrowserBox->addSeparator("##3---");
- addMailCommands();
- addFollow();
-
- if (localPlayer->isInParty())
- {
- const Party *const party = localPlayer->getParty();
- if (party != nullptr)
- {
- const PartyMember *const m = party->getMember(mName);
- if (m != nullptr)
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: move to player location
- mBrowserBox->addRow("/navigateto 'NAME'", _("Move"));
- }
- }
- }
- addPlayerMisc();
- addBuySellDefault();
- if (Net::getNetworkType() != ServerType::TMWATHENA)
- addParty(wTab->getNick());
- mBrowserBox->addSeparator("##3---");
- }
- }
-
- addWindowMenu(chatWindow);
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(x, y);
-}
-
-void PopupMenu::showChangePos(const int x, const int y)
-{
- initPopup();
- mBrowserBox->clearRows();
- // TRANSLATORS: popup menu header
- mBrowserBox->addRow(_("Change guild position"));
-
- if (localPlayer == nullptr)
- return;
-
- mX = x;
- mY = y;
- const Guild *const guild = localPlayer->getGuild();
- if (guild != nullptr)
- {
- const PositionsMap &map = guild->getPositions();
- FOR_EACH (PositionsMap::const_iterator, itr, map)
- {
- mBrowserBox->addRow(strprintf("@@guild-pos-%u|%s@@",
- itr->first, itr->second.c_str()));
- }
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(x, y);
- }
- else
- {
- mBeingId = BeingId_zero;
- mFloorItemId = BeingId_zero;
- mItemIndex = -1;
- mItemId = 0;
- for (int f = 0; f < maxCards; f ++)
- mItemCards[f] = 0;
- mMapItem = nullptr;
- mName.clear();
- mExtName.clear();
- mType = ActorType::Unknown;
- mSubType = BeingTypeId_zero;
- mX = 0;
- mY = 0;
- setVisible(Visible_false);
- }
-}
-
-void PopupMenu::showWindowPopup(Window *const window)
-{
- if (window == nullptr)
- return;
-
- initPopup();
- setMousePos();
- mCallerWindow = window;
- mBrowserBox->clearRows();
- // TRANSLATORS: popup menu header
- mBrowserBox->addRow(_("window"));
-
- addWindowMenu(window);
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(mX, mY);
-}
-
-void PopupMenu::addWindowMenu(const Window *const window)
-{
- if (window == nullptr)
- return;
-
- initPopup();
- if (window->getAlowClose())
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close window
- mBrowserBox->addRow("window close", _("Close"));
- }
-
- if (window->isStickyButtonLock())
- {
- if (window->isSticky())
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: unlock window
- mBrowserBox->addRow("window unlock", _("Unlock"));
- }
- else
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: lock window
- mBrowserBox->addRow("window lock", _("Lock"));
- }
- }
-}
-
-void PopupMenu::showEmoteType()
-{
- initPopup();
- setMousePos();
-
- mBrowserBox->clearRows();
- // TRANSLATORS: popup menu header
- mBrowserBox->addRow(_("Show emotes for:"));
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: show emotes for player
- mBrowserBox->addRow("/setemotetype player", _("Player"));
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: show emotes for pet
- mBrowserBox->addRow("/setemotetype pet", _("Pet"));
-
- if (Net::getNetworkType() == ServerType::EVOL2)
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: show emotes for homuncules
- mBrowserBox->addRow("/setemotetype homun", _("Homunculus"));
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: show emotes for mercenary
- mBrowserBox->addRow("/setemotetype merc", _("Mercenary"));
- }
- mBrowserBox->addSeparator("##3---");
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(mX, mY);
-}
-
-void PopupMenu::handleLink(const std::string &link,
- MouseEvent *event A_UNUSED)
-{
- Being *being = nullptr;
- if (actorManager != nullptr)
- being = actorManager->findBeing(mBeingId);
-
- mAllowCleanMenu = true;
-
- if (link == "remove map" && (mMapItem != nullptr))
- {
- if (viewport != nullptr)
- {
- const Map *const map = viewport->getMap();
- if (map != nullptr)
- {
- SpecialLayer *const specialLayer = map->getSpecialLayer();
- if (specialLayer != nullptr)
- {
- const bool isHome = (mMapItem->getType()
- == CAST_S32(MapItemType::HOME));
- const int x = static_cast<int>(mMapItem->getX());
- const int y = static_cast<int>(mMapItem->getY());
- specialLayer->setTile(x, y,
- CAST_S32(MapItemType::EMPTY));
- specialLayer->updateCache();
- if (socialWindow != nullptr)
- socialWindow->removePortal(x, y);
- if (isHome && (localPlayer != nullptr))
- {
- localPlayer->removeHome();
- localPlayer->saveHomes();
- }
- }
- }
- }
- }
- else if (link == "rename map" && (mMapItem != nullptr))
- {
- mRenameListener.setMapItem(mMapItem);
- CREATEWIDGETV(mDialog, TextDialog,
- // TRANSLATORS: dialog caption
- // TRANSLATORS: number of chars in string should be near original
- _("Rename map sign "),
- // TRANSLATORS: label
- // TRANSLATORS: number of chars in string should be near original
- _("Name: "));
- mRenameListener.setDialog(mDialog);
- mDialog->setText(mMapItem->getComment());
- mDialog->setActionEventId("ok");
- mDialog->addActionListener(&mRenameListener);
- }
- else if (link == "edit spell" && (mSpell != nullptr))
- {
- CREATEWIDGET(TextCommandEditor, mSpell);
- }
- else if (link == "addcomment" && !mName.empty())
- {
- TextDialog *const dialog = CREATEWIDGETR(TextDialog,
- // TRANSLATORS: dialog caption
- // TRANSLATORS: number of chars in string should be near original
- _("Player comment "),
- // TRANSLATORS: label
- // TRANSLATORS: number of chars in string should be near original
- _("Comment: "));
- mPlayerListener.setDialog(dialog);
- mPlayerListener.setNick(mName);
- mPlayerListener.setType(mType);
-
- if (being != nullptr)
- {
- being->updateComment();
- dialog->setText(being->getComment());
- }
- else
- {
- dialog->setText(Being::loadComment(mName,
- static_cast<ActorTypeT>(mType)));
- }
- dialog->setActionEventId("ok");
- dialog->addActionListener(&mPlayerListener);
- }
- else if (link == "guild-pos" && !mName.empty())
- {
- showChangePos(getX(), getY());
- return;
- }
- else if (link == "clipboard copy")
- {
- if (mTextField != nullptr)
- mTextField->handleCopy();
- }
- else if (link == "clipboard paste")
- {
- if (mTextField != nullptr)
- mTextField->handlePaste();
- }
- else if (link == "gm" && !mName.empty())
- {
- showGMPopup(mName);
- return;
- }
- else if (link == "mute" && !mName.empty())
- {
- showMuteCommands();
- return;
- }
- else if (link == "show" && !mName.empty())
- {
- showPlayerMenu();
- return;
- }
- else if (link == "window close" && (mCallerWindow != nullptr))
- {
- if (Widget::widgetExists(mCallerWindow))
- mCallerWindow->close();
- }
- else if (link == "window unlock" && (mCallerWindow != nullptr))
- {
- if (Widget::widgetExists(mCallerWindow))
- mCallerWindow->setSticky(false);
- }
- else if (link == "window lock" && (mCallerWindow != nullptr))
- {
- if (Widget::widgetExists(mCallerWindow))
- mCallerWindow->setSticky(true);
- }
- else if (link == "join chat" && (being != nullptr))
- {
- const ChatObject *const chat = being->getChat();
- if (chat != nullptr)
- chatHandler->joinChat(chat, "");
- }
- else if (link == "craftmenu")
- {
- showCraftPopup();
- return;
- }
- else if (link.compare(0, 10, "guild-pos-") == 0)
- {
- if (localPlayer != nullptr)
- {
- const int num = atoi(link.substr(10).c_str());
- const Guild *const guild = localPlayer->getGuild();
- if (guild != nullptr)
- {
- guildHandler->changeMemberPostion(
- guild->getMember(mName), num);
- }
- }
- }
- else if (link.compare(0, 7, "player_") == 0)
- {
- if (actorManager != nullptr)
- {
- mBeingId = fromInt(atoi(link.substr(7).c_str()), BeingId);
- being = actorManager->findBeing(mBeingId);
- if (being != nullptr)
- {
- showPopup(getX(), getY(), being);
- return;
- }
- }
- }
- else if (link.compare(0, 10, "flooritem_") == 0)
- {
- if (actorManager != nullptr)
- {
- const BeingId id = fromInt(atoi(
- link.substr(10).c_str()), BeingId);
- if (id != BeingId_zero)
- {
- const FloorItem *const item = actorManager->findItem(id);
- if (item != nullptr)
- {
- mFloorItemId = item->getId();
- mItemId = item->getItemId();
- for (int f = 0; f < maxCards; f ++)
- mItemCards[f] = item->getCard(f);
- showPopup(getX(), getY(), item);
- return;
- }
- }
- }
- }
- else if (link.compare(0, 12, "hide button_") == 0)
- {
- if (windowMenu != nullptr)
- windowMenu->showButton(link.substr(12), Visible_false);
- }
- else if (link.compare(0, 12, "show button_") == 0)
- {
- if (windowMenu != nullptr)
- windowMenu->showButton(link.substr(12), Visible_true);
- }
- else if (link.compare(0, 9, "hide bar_") == 0)
- {
- if (miniStatusWindow != nullptr)
- miniStatusWindow->showBar(link.substr(9), Visible_false);
- }
- else if (link.compare(0, 9, "show bar_") == 0)
- {
- if (miniStatusWindow != nullptr)
- miniStatusWindow->showBar(link.substr(9), Visible_true);
- }
- else if (link.compare(0, 12, "show window_") == 0)
- {
- const int id = atoi(link.substr(12).c_str());
- if (id >= 0)
- inputManager.executeAction(static_cast<InputActionT>(id));
- }
- else if (link.compare(0, 6, "mute_+") == 0)
- {
- if (being != nullptr)
- {
- const int time = atoi(link.substr(6).c_str());
- adminHandler->mute(being, 1, time);
- }
- }
- else if (link.compare(0, 6, "mute_-") == 0)
- {
- if (being != nullptr)
- {
- const int time = atoi(link.substr(6).c_str());
- adminHandler->mute(being, 0, time);
- }
- }
- else if (!link.empty() && link[0] == '/')
- {
- std::string cmd = link.substr(1);
- replaceAll(cmd, "'NAME'", mName);
- replaceAll(cmd, "'ENAME'", escapeString(mName));
- replaceAll(cmd, "'EXTNAME'", mExtName);
- replaceAll(cmd, "'EEXTNAME'", escapeString(mExtName));
- replaceAll(cmd, "'X'", toString(mX));
- replaceAll(cmd, "'Y'", toString(mY));
- replaceAll(cmd, "'BEINGID'", toString(toInt(mBeingId, int)));
- replaceAll(cmd, "'FLOORID'", toString(toInt(mFloorItemId, int)));
- replaceAll(cmd, "'ITEMID'", toString(mItemId));
- replaceAll(cmd, "'ITEMCOLOR'", toString(toInt(mItemColor, int)));
- replaceAll(cmd, "'BEINGTYPEID'", toString(CAST_S32(mType)));
- replaceAll(cmd, "'BEINGSUBTYPEID'", toString(CAST_S32(mSubType)));
- replaceAll(cmd, "'PLAYER'", localPlayer->getName());
- replaceAll(cmd, "'EPLAYER'", escapeString(localPlayer->getName()));
- replaceAll(cmd, "'PLAYERX'", toString(localPlayer->getTileX()));
- replaceAll(cmd, "'PLAYERY'", toString(localPlayer->getTileY()));
- if (mItemIndex >= 0)
- replaceAll(cmd, "'INVINDEX'", toString(mItemIndex));
- else
- replaceAll(cmd, "'INVINDEX'", "0");
- if (mMapItem != nullptr)
- {
- replaceAll(cmd, "'MAPX'", toString(mMapItem->getX()));
- replaceAll(cmd, "'MAPY'", toString(mMapItem->getY()));
- }
- else
- {
- replaceAll(cmd, "'MAPX'", toString(mX));
- replaceAll(cmd, "'MAPY'", toString(mY));
- }
-
- std::string cards;
- for (int f = 0; f < maxCards; f ++)
- {
- const int id = mItemCards[f];
- if (id != 0)
- {
- cards.append(",");
- cards.append(toString(id));
- }
- }
- replaceAll(cmd, "'CARDS'", cards);
- replaceAll(cmd, "'ECARDS'", escapeString(cards));
- if (actorManager != nullptr)
- {
- if (being == nullptr)
- {
- being = actorManager->findBeingByName(mName,
- ActorType::Player);
- }
- }
- if (being != nullptr)
- replaceAll(cmd, "'PARTY'", being->getPartyName());
- else
- replaceAll(cmd, "'PARTY'", "");
-
- const size_t pos = cmd.find(' ');
- const std::string type(cmd, 0, pos);
- std::string args(cmd, pos == std::string::npos ? cmd.size() : pos + 1);
- args = trim(args);
- inputManager.executeChatCommand(type, args, mTab);
- }
- // Unknown actions
- else if (link != "cancel")
- {
- reportAlways("PopupMenu: Warning, unknown action '%s'", link.c_str());
- }
-
- if (!mAllowCleanMenu)
- return;
-
- setVisible(Visible_false);
-
- mBeingId = BeingId_zero;
- mFloorItemId = BeingId_zero;
- mItemId = 0;
- mItemIndex = -1;
- for (int f = 0; f < maxCards; f ++)
- mItemCards[f] = 0;
- mItemColor = ItemColor_one;
- mMapItem = nullptr;
- mTab = nullptr;
- mSpell = nullptr;
- mCallerWindow = nullptr;
- mDialog = nullptr;
- mButton = nullptr;
- mName.clear();
- mExtName.clear();
- mTextField = nullptr;
- mType = ActorType::Unknown;
- mSubType = BeingTypeId_zero;
- mX = 0;
- mY = 0;
-}
-
-void PopupMenu::showPopup(Window *const parent,
- const int x, const int y,
- const Item *const item,
- const InventoryTypeT type)
-{
- if (item == nullptr)
- return;
-
- initPopup();
- mItemId = item->getId();
- mItemIndex = item->getInvIndex();
- for (int f = 0; f < maxCards; f ++)
- mItemCards[f] = item->getCard(f);
- mItemColor = item->getColor();
- mCallerWindow = parent;
- mX = x;
- mY = y;
- mName.clear();
- mExtName.clear();
- mBrowserBox->clearRows();
-
- const int cnt = item->getQuantity();
- const bool isProtected = PlayerInfo::isItemProtected(mItemId);
-
- switch (type)
- {
- case InventoryType::Inventory:
- if (tradeWindow != nullptr &&
- tradeWindow->isWindowVisible() &&
- !isProtected)
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add item to trade
- mBrowserBox->addRow("/addtrade 'INVINDEX'", _("Add to trade"));
- if (cnt > 1)
- {
- if (cnt > 10)
- {
- mBrowserBox->addRow("/addtrade 'INVINDEX' 10",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add 10 item amount to trade
- _("Add to trade 10"));
- }
- mBrowserBox->addRow("/addtrade 'INVINDEX' /",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add half item amount to trade
- _("Add to trade half"));
- mBrowserBox->addRow("/addtrade 'INVINDEX' -1",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add all amount except one item to trade
- _("Add to trade all-1"));
- mBrowserBox->addRow("/addtrade 'INVINDEX' all",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add all amount item to trade
- _("Add to trade all"));
- }
- mBrowserBox->addSeparator("##3---");
- }
- if (InventoryWindow::isStorageActive())
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add item to storage
- mBrowserBox->addRow("/invtostorage 'INVINDEX'", _("Store"));
- if (cnt > 1)
- {
- if (cnt > 10)
- {
- mBrowserBox->addRow("/invtostorage 'INVINDEX' 10",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add 10 item amount to storage
- _("Store 10"));
- }
- mBrowserBox->addRow("/invtostorage 'INVINDEX' /",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add half item amount to storage
- _("Store half"));
- mBrowserBox->addRow("/invtostorage 'INVINDEX' -1",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add all except one item to storage
- _("Store all-1"));
- mBrowserBox->addRow("/invtostorage 'INVINDEX' all",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add all item amount to storage
- _("Store all"));
- }
- mBrowserBox->addSeparator("##3---");
- }
- if (npcHandler != nullptr)
- {
- NpcDialog *const dialog = npcHandler->getCurrentNpcDialog();
- if ((dialog != nullptr) &&
- dialog->getInputState() == NpcInputState::ITEM_CRAFT)
- {
- mBrowserBox->addRow("craftmenu",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: sub menu for craft
- _("Move to craft..."));
- }
- }
- addItemMenu(item, InventoryType::Inventory);
- addDrop(item, isProtected);
- break;
-
- case InventoryType::Storage:
- // TRANSLATORS: popup menu item
- // TRANSLATORS: get item from storage
- mBrowserBox->addRow("/storagetoinv 'INVINDEX'", _("Retrieve"));
- if (cnt > 1)
- {
- if (cnt > 10)
- {
- mBrowserBox->addRow("/storagetoinv 'INVINDEX' 10",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: get 10 item amount from storage
- _("Retrieve 10"));
- }
- mBrowserBox->addRow("/storagetoinv 'INVINDEX' /",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: get half item amount from storage
- _("Retrieve half"));
- mBrowserBox->addRow("/storagetoinv 'INVINDEX' -1",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: get all except one item amount from storage
- _("Retrieve all-1"));
- mBrowserBox->addRow("/storagetoinv 'INVINDEX' all",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: get all item amount from storage
- _("Retrieve all"));
- mBrowserBox->addSeparator("##3---");
- }
- addItemMenu(item, InventoryType::Storage);
- break;
- case InventoryType::Cart:
- addItemMenu(item, InventoryType::Cart);
- break;
-
- case InventoryType::Trade:
- case InventoryType::Npc:
- case InventoryType::Vending:
- case InventoryType::MailEdit:
- case InventoryType::MailView:
- case InventoryType::Craft:
- case InventoryType::TypeEnd:
- default:
- break;
- }
-
-
- addProtection();
- if (config.getBoolValue("enablePickupFilter"))
- {
- mName = item->getName();
- mExtName = mName;
- mBrowserBox->addSeparator("##3---");
- addPickupFilter(mName);
- }
- addGmCommands();
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add item name to chat
- mBrowserBox->addRow("/addchat 'ITEMID''CARDS'", _("Add to chat"));
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(x, y);
-}
-
-void PopupMenu::showItemPopup(const int x, const int y,
- const int itemId,
- const ItemColor color)
-{
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- return;
-
- Item *const item = inv->findItem(itemId, color);
- if (item != nullptr)
- {
- showItemPopup(x, y, item);
- }
- else
- {
- initPopup();
- mItemId = itemId;
- mItemIndex = -1;
- mItemColor = color;
- for (int f = 0; f < maxCards; f ++)
- mItemCards[f] = 0;
- mX = x;
- mY = y;
- mBrowserBox->clearRows();
-
- if (!PlayerInfo::isItemProtected(mItemId))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: use item
- mBrowserBox->addRow("/use 'ITEMID'", _("Use"));
- }
- addProtection();
- addGmCommands();
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(x, y);
- }
-}
-
-void PopupMenu::showItemPopup(const int x, const int y,
- const Item *const item)
-{
- initPopup();
- mX = x;
- mY = y;
- if (item != nullptr)
- {
- mItemId = item->getId();
- mItemColor = item->getColor();
- mItemIndex = item->getInvIndex();
- for (int f = 0; f < maxCards; f ++)
- mItemCards[f] = item->getCard(f);
- }
- else
- {
- mItemId = 0;
- mItemColor = ItemColor_one;
- mItemIndex = -1;
- for (int f = 0; f < maxCards; f ++)
- mItemCards[f] = 0;
- }
- mName.clear();
- mExtName.clear();
- mBrowserBox->clearRows();
-
- if (item != nullptr)
- {
- const bool isProtected = PlayerInfo::isItemProtected(mItemId);
- addUse(item);
- addDrop(item, isProtected);
- if (InventoryWindow::isStorageActive())
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add item to storage
- mBrowserBox->addRow("/invtostorage 'INVINDEX'", _("Store"));
- }
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add item name to chat
- mBrowserBox->addRow("/addchat 'ITEMID''CARDS'", _("Add to chat"));
-
- if (config.getBoolValue("enablePickupFilter"))
- {
- mName = item->getName();
- mExtName = mName;
- mBrowserBox->addSeparator("##3---");
- addPickupFilter(mName);
- }
- }
- addProtection();
- addGmCommands();
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(x, y);
-}
-
-void PopupMenu::showDropPopup(const int x,
- const int y,
- const Item *const item)
-{
- initPopup();
- mX = x;
- mY = y;
- mName.clear();
- mExtName.clear();
- mBrowserBox->clearRows();
-
- if (item != nullptr)
- {
- mItemId = item->getId();
- mItemColor = item->getColor();
- mItemIndex = item->getInvIndex();
- for (int f = 0; f < maxCards; f ++)
- mItemCards[f] = item->getCard(f);
- const bool isProtected = PlayerInfo::isItemProtected(mItemId);
- addUse(item);
- addDrop(item, isProtected);
- if (InventoryWindow::isStorageActive())
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add item to storage
- mBrowserBox->addRow("/invtostorage 'INVINDEX'", _("Store"));
- }
- addProtection();
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add item name to chat
- mBrowserBox->addRow("/addchat 'ITEMID''CARDS'", _("Add to chat"));
- if (config.getBoolValue("enablePickupFilter"))
- {
- mName = item->getName();
- mExtName = mName;
- mBrowserBox->addSeparator("##3---");
- addPickupFilter(mName);
- }
- }
- addGmCommands();
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- mBrowserBox->addRow("/cleardrops", _("Clear drop window"));
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(x, y);
-}
-
-void PopupMenu::showPopup(const int x, const int y, Button *const button)
-{
- if ((button == nullptr) || (windowMenu == nullptr))
- return;
-
- initPopup();
- mButton = button;
- mX = x;
- mY = y;
-
- mBrowserBox->clearRows();
- STD_VECTOR<Button *> names = windowMenu->getButtons();
- for (STD_VECTOR<Button *>::const_iterator it = names.begin(),
- it_end = names.end(); it != it_end; ++ it)
- {
- const Button *const btn = *it;
- if ((btn == nullptr) || btn->getActionEventId() == "SET")
- continue;
-
- if (btn->mVisible == Visible_true)
- {
- mBrowserBox->addRow(strprintf("@@hide button_%s|%s %s (%s)@@",
- // TRANSLATORS: popup menu item
- btn->getActionEventId().c_str(), _("Hide"),
- btn->getDescription().c_str(), btn->getCaption().c_str()));
- }
- else
- {
- mBrowserBox->addRow(strprintf("@@show button_%s|%s %s (%s)@@",
- // TRANSLATORS: popup menu item
- btn->getActionEventId().c_str(), _("Show"),
- btn->getDescription().c_str(), btn->getCaption().c_str()));
- }
- }
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(x, y);
-}
-
-void PopupMenu::showPopup(const int x, const int y, const ProgressBar *const b)
-{
- if ((b == nullptr) || (miniStatusWindow == nullptr))
- return;
-
- initPopup();
- mName = b->text();
- mExtName = mName;
- mX = x;
- mY = y;
-
- mBrowserBox->clearRows();
- STD_VECTOR <ProgressBar*> bars = miniStatusWindow->getBars();
- ProgressBar *onlyBar = nullptr;
- int cnt = 0;
-
- // search for alone visible bar
- for (STD_VECTOR <ProgressBar*>::const_iterator it = bars.begin(),
- it_end = bars.end(); it != it_end; ++it)
- {
- ProgressBar *const bar = *it;
- if (bar == nullptr)
- continue;
-
- if (bar->mVisible == Visible_true)
- {
- cnt ++;
- onlyBar = bar;
- }
- }
- if (cnt > 1)
- onlyBar = nullptr;
-
- for (STD_VECTOR <ProgressBar*>::const_iterator it = bars.begin(),
- it_end = bars.end(); it != it_end; ++it)
- {
- ProgressBar *const bar = *it;
- if ((bar == nullptr) || bar == onlyBar)
- continue;
-
- if (bar->mVisible == Visible_true)
- {
- mBrowserBox->addRow(strprintf("@@hide bar_%s|%s %s@@",
- // TRANSLATORS: popup menu item
- bar->getActionEventId().c_str(), _("Hide"),
- bar->getId().c_str()));
- }
- else
- {
- mBrowserBox->addRow(strprintf("@@show bar_%s|%s %s@@",
- // TRANSLATORS: popup menu item
- bar->getActionEventId().c_str(), _("Show"),
- bar->getId().c_str()));
- }
- }
-
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- mBrowserBox->addRow("/yellowbar", _("Open yellow bar settings"));
- // TRANSLATORS: popup menu item
- mBrowserBox->addRow("/resetmodifiers", _("Reset yellow bar"));
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: copy status to chat
- mBrowserBox->addRow("/bartochat 'NAME'", _("Copy to chat"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(x, y);
-}
-
-void PopupMenu::showAttackMonsterPopup(const int x, const int y,
- const std::string &name,
- const int type)
-{
- if ((localPlayer == nullptr) || (actorManager == nullptr))
- return;
-
- initPopup();
- mName = name;
- mExtName = name;
- mType = ActorType::Monster;
- mSubType = BeingTypeId_zero;
- mX = x;
- mY = y;
-
- mBrowserBox->clearRows();
-
- if (name.empty())
- {
- // TRANSLATORS: popup menu header
- mBrowserBox->addRow(_("(default)"));
- }
- else
- {
- mBrowserBox->addRow(name);
- }
- switch (type)
- {
- case MapItemType::ATTACK:
- {
- const int idx = actorManager->getAttackMobIndex(name);
- const int size = actorManager->getAttackMobsSize();
- if (idx > 0)
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: move attack target up
- mBrowserBox->addRow("/moveattackup 'NAME'", _("Move up"));
- }
- if (idx + 1 < size)
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: move attack target down
- mBrowserBox->addRow("/moveattackdown 'NAME'", _("Move down"));
- }
- break;
- }
- case MapItemType::PRIORITY:
- {
- const int idx = actorManager->
- getPriorityAttackMobIndex(name);
- const int size = actorManager->getPriorityAttackMobsSize();
- if (idx > 0)
- {
- mBrowserBox->addRow("/movepriorityattackup 'NAME'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: move attack target up
- _("Move up"));
- }
- if (idx + 1 < size)
- {
- mBrowserBox->addRow("/movepriorityattackdown 'NAME'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: move attack target down
- _("Move down"));
- }
- break;
- }
- case MapItemType::IGNORE_:
- break;
- default:
- break;
- }
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: remove attack target
- mBrowserBox->addRow("/removeattack 'NAME'", _("Remove"));
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(x, y);
-}
-
-void PopupMenu::showPickupItemPopup(const int x, const int y,
- const std::string &name)
-{
- if ((localPlayer == nullptr) || (actorManager == nullptr))
- return;
-
- initPopup();
- mName = name;
- mExtName = name;
- mType = ActorType::FloorItem;
- mSubType = BeingTypeId_zero;
- mX = x;
- mY = y;
-
- mBrowserBox->clearRows();
-
- if (name.empty())
- {
- // TRANSLATORS: popup menu header
- mBrowserBox->addRow(_("(default)"));
- }
- else
- {
- mBrowserBox->addRow(name);
- }
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: remove item from pickup filter
- mBrowserBox->addRow("/removepickup 'NAME'", _("Remove"));
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(x, y);
-}
-
-void PopupMenu::showUndressPopup(const int x, const int y,
- const Being *const being,
- const Item *const item)
-{
- if ((being == nullptr) || (item == nullptr))
- return;
-
- initPopup();
- mBeingId = being->getId();
- mItemId = item->getId();
- mItemColor = item->getColor();
- mItemIndex = item->getInvIndex();
- for (int f = 0; f < maxCards; f ++)
- mItemCards[f] = item->getCard(f);
- mX = x;
- mY = y;
-
- mBrowserBox->clearRows();
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: undress item from player
- mBrowserBox->addRow("/undress :'BEINGID' 'ITEMID'", _("Undress"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add item name to chat
- mBrowserBox->addRow("/addchat 'ITEMID''CARDS'", _("Add to chat"));
- addGmCommands();
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(x, y);
-}
-
-void PopupMenu::showTextFieldPopup(TextField *const input)
-{
- initPopup();
- setMousePos();
- mTextField = input;
-
- mBrowserBox->clearRows();
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: copy text to clipboard
- mBrowserBox->addRow("clipboard copy", _("Copy"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: paste text from clipboard
- mBrowserBox->addRow("clipboard paste", _("Paste"));
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(mX, mY);
-}
-
-void PopupMenu::showLinkPopup(const std::string &link)
-{
- initPopup();
- setMousePos();
- mName = link;
- mExtName = link;
-
- mBrowserBox->clearRows();
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: open link in browser
- mBrowserBox->addRow("/open 'NAME'", _("Open link"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: copy link to clipboard
- mBrowserBox->addRow("/clipboardcopy 'NAME'", _("Copy to clipboard"));
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(mX, mY);
-}
-
-void PopupMenu::showWindowsPopup()
-{
- initPopup();
- setMousePos();
- mBrowserBox->clearRows();
- const STD_VECTOR<ButtonText*> &names = windowMenu->getButtonTexts();
- // TRANSLATORS: popup menu header
- mBrowserBox->addRow(_("Show window"));
-
- FOR_EACH (STD_VECTOR<ButtonText*>::const_iterator, it, names)
- {
- const ButtonText *const btn = *it;
- if (btn == nullptr)
- continue;
-
- mBrowserBox->addRow(strprintf("show window_%d",
- CAST_S32(btn->key)),
- btn->text.c_str());
- }
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(mX, mY);
-}
-
-void PopupMenu::showNpcDialogPopup(const BeingId npcId,
- const int x, const int y)
-{
- initPopup();
- mBeingId = npcId;
- mX = x;
- mY = y;
- mBrowserBox->clearRows();
- // TRANSLATORS: popup menu item
- // TRANSLATORS: copy npc text to clipboard
- mBrowserBox->addRow("/npcclipboard 'X' 'Y'", _("Copy to clipboard"));
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(x, y);
-}
-
-void PopupMenu::showSkillPopup(const SkillInfo *const info)
-{
- if (info == nullptr)
- return;
-
- initPopup();
- setMousePos();
-
- // using mItemId as skill id
- mItemId = info->id;
- // using mItemIndex as skill level
- mItemIndex = info->level;
- mBrowserBox->clearRows();
-
- // TRANSLATORS: popup menu header
- mBrowserBox->addRow(_("Skill"));
- mBrowserBox->addRow("/addskillshortcut 'ITEMID'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add skill to shortcurs tab
- _("Add skill shortcut"));
- mBrowserBox->addSeparator("##3---");
- mBrowserBox->addRow("/showskilllevels 'ITEMID'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: set skill level
- _("Skill level..."));
- mBrowserBox->addRow("/showskilltypes 'ITEMID'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: set skill cast type
- _("Skill cast type..."));
- mBrowserBox->addRow("/showskilloffsetx 'ITEMID'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: set skill cast offset by x
- _("Skill offset by x..."));
- mBrowserBox->addRow("/showskilloffsety 'ITEMID'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: set skill cast offset by y
- _("Skill offset by y..."));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(mX, mY);
-}
-
-void PopupMenu::showSkillOffsetPopup(const SkillInfo *const info,
- const bool isOffsetX)
-{
- if (info == nullptr)
- return;
-
- initPopup();
- setMousePos2();
-
- // using mItemId as skill id
- mItemId = info->id;
- // using mItemIndex as skill level
- mItemIndex = info->level;
- mBrowserBox->clearRows();
- char letter = ' ';
-
- if (isOffsetX)
- {
- // TRANSLATORS: popup menu header
- mBrowserBox->addRow(_("Skill cast offset by x"));
- letter = 'x';
- }
- else
- {
- // TRANSLATORS: popup menu header
- mBrowserBox->addRow(_("Skill cast offset by y"));
- letter = 'y';
- }
- for (int f = -9; f <= 9; f ++)
- {
- const std::string command = strprintf(
- "/setskilloffset%c 'ITEMID' %d", letter, f);
- if (f == 0)
- {
- mBrowserBox->addRow(command,
- strprintf("%d", f).c_str());
- }
- else
- {
- mBrowserBox->addRow(command,
- strprintf("%+d", f).c_str());
- }
- }
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
- showPopup(mX, mY);
-}
-
-void PopupMenu::showSkillLevelPopup(const SkillInfo *const info)
-{
- if (info == nullptr)
- return;
-
- initPopup();
- setMousePos2();
-
- // using mItemId as skill id
- mItemId = info->id;
- // using mItemIndex as skill level
- mItemIndex = info->level;
-
- for (int f = 0; f < maxCards; f ++)
- mItemCards[f] = 0;
- mBrowserBox->clearRows();
- // TRANSLATORS: popup menu item
- // TRANSLATORS: skill level header
- mBrowserBox->addRow(_("Select skill level"));
- for (int f = 1; f <= mItemIndex; f ++)
- {
- mBrowserBox->addRow(strprintf("/selectskilllevel %d %d", mItemId, f),
- // TRANSLATORS: popup menu item
- // TRANSLATORS: skill level
- strprintf(_("Level: %d"), f).c_str());
- }
- mBrowserBox->addRow(strprintf("/selectskilllevel %d 0", mItemId),
- // TRANSLATORS: popup menu item
- // TRANSLATORS: skill level
- _("Max level"));
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(mX, mY);
-}
-
-void PopupMenu::showSkillTypePopup(const SkillInfo *const info)
-{
- if (info == nullptr)
- return;
-
- initPopup();
- setMousePos2();
-
- // using mItemId as skill id
- mItemId = info->id;
- // using mItemIndex as skill level
- mItemIndex = info->level;
-
- for (int f = 0; f < maxCards; f ++)
- mItemCards[f] = 0;
- mBrowserBox->clearRows();
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: skill cast type header
- mBrowserBox->addRow(_("Select skill cast type"));
- mBrowserBox->addRow(strprintf("/selectskilltype %d 0", mItemId),
- // TRANSLATORS: popup menu item
- // TRANSLATORS: skill cast type
- _("Default"));
- mBrowserBox->addRow(strprintf("/selectskilltype %d 1", mItemId),
- // TRANSLATORS: popup menu item
- // TRANSLATORS: skill cast type
- _("Target"));
- mBrowserBox->addRow(strprintf("/selectskilltype %d 2", mItemId),
- // TRANSLATORS: popup menu item
- // TRANSLATORS: skill cast type
- _("Mouse position"));
- mBrowserBox->addRow(strprintf("/selectskilltype %d 3", mItemId),
- // TRANSLATORS: popup menu item
- // TRANSLATORS: skill cast type
- _("Self"));
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(mX, mY);
-}
-
-void PopupMenu::showPopup(int x, int y)
-{
- PopupManager::hideItemPopup();
- const int pad2 = 2 * mPadding;
- mBrowserBox->setPosition(mPadding, mPadding);
- mScrollArea->setPosition(mPadding, mPadding);
- mBrowserBox->updateHeight();
- // add padding to initial size before draw browserbox
- int height = mBrowserBox->getHeight();
- if (height + pad2 >= mainGraphics->getHeight())
- {
- height = mainGraphics->getHeight() - pad2;
- mBrowserBox->setWidth(mBrowserBox->getWidth() + 5);
- mScrollArea->setWidth(mBrowserBox->getWidth() + pad2 + 10);
- setContentSize(mBrowserBox->getWidth() + pad2 + 20,
- height + pad2);
- }
- else
- {
- mBrowserBox->setWidth(mBrowserBox->getWidth());
- mScrollArea->setWidth(mBrowserBox->getWidth() + pad2);
- setContentSize(mBrowserBox->getWidth() + pad2,
- height + pad2);
- }
- if (mainGraphics->mWidth < (x + getWidth() + 5))
- x = mainGraphics->mWidth - getWidth();
- if (mainGraphics->mHeight < (y + getHeight() + 5))
- y = mainGraphics->mHeight - getHeight();
- mScrollArea->setHeight(height);
- setPosition(x, y);
- setVisible(Visible_true);
- requestMoveToTop();
- mAllowCleanMenu = false;
-}
-
-void PopupMenu::addNormalRelations()
-{
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add player to disregarded list
- mBrowserBox->addRow("/disregard 'NAME'", _("Disregard"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add player to ignore list
- mBrowserBox->addRow("/ignore 'NAME'", _("Ignore"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add player to black list
- mBrowserBox->addRow("/blacklist 'NAME'", _("Black list"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add player to enemy list
- mBrowserBox->addRow("/enemy 'NAME'", _("Set as enemy"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add player to erased list
- mBrowserBox->addRow("/erase 'NAME'", _("Erase"));
-}
-
-void PopupMenu::addPlayerRelation(const std::string &name)
-{
- switch (playerRelations.getRelation(name))
- {
- case Relation::NEUTRAL:
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add player to friends list
- mBrowserBox->addRow("/friend 'NAME'", _("Be friend"));
- addNormalRelations();
- break;
-
- case Relation::FRIEND:
- addNormalRelations();
- break;
-
- case Relation::BLACKLISTED:
- // TRANSLATORS: popup menu item
- // TRANSLATORS: remove player from ignore list
- mBrowserBox->addRow("/unignore 'NAME'", _("Unignore"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add player to disregarded list
- mBrowserBox->addRow("/disregard 'NAME'", _("Disregard"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add player to ignore list
- mBrowserBox->addRow("/ignore 'NAME'", _("Ignore"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add player to enemy list
- mBrowserBox->addRow("/enemy 'NAME'", _("Set as enemy"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add player to erased list
- mBrowserBox->addRow("/erase 'NAME'", _("Erase"));
- break;
-
- case Relation::DISREGARDED:
- // TRANSLATORS: popup menu item
- // TRANSLATORS: remove player from ignore list
- mBrowserBox->addRow("/unignore 'NAME'", _("Unignore"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add player to completle ignore list
- mBrowserBox->addRow("/ignore 'NAME'", _("Completely ignore"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add player to erased list
- mBrowserBox->addRow("/erase 'NAME'", _("Erase"));
- break;
-
- case Relation::IGNORED:
- // TRANSLATORS: popup menu item
- // TRANSLATORS: remove player from ignore list
- mBrowserBox->addRow("/unignore 'NAME'", _("Unignore"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add player to erased list
- mBrowserBox->addRow("/erase 'NAME'", _("Erase"));
- break;
-
- case Relation::ENEMY2:
- // TRANSLATORS: popup menu item
- // TRANSLATORS: remove player from ignore list
- mBrowserBox->addRow("/unignore 'NAME'", _("Unignore"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add player to disregarded list
- mBrowserBox->addRow("/disregard 'NAME'", _("Disregard"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add player to ignore list
- mBrowserBox->addRow("/ignore 'NAME'", _("Ignore"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add player to black list
- mBrowserBox->addRow("/blacklist 'NAME'", _("Black list"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add player to erased list
- mBrowserBox->addRow("/erase 'NAME'", _("Erase"));
- break;
-
- case Relation::ERASED:
- // TRANSLATORS: popup menu item
- // TRANSLATORS: remove player from ignore list
- mBrowserBox->addRow("/unignore 'NAME'", _("Unignore"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add player to disregarded list
- mBrowserBox->addRow("/disregard 'NAME'", _("Disregard"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add player to ignore list
- mBrowserBox->addRow("/ignore 'NAME'", _("Completely ignore"));
- break;
-
- default:
- break;
- }
-}
-
-void PopupMenu::addFollow()
-{
- if (features.getBoolValue("allowFollow"))
- {
- // TRANSLATORS: popup menu item
- mBrowserBox->addRow("/follow 'NAME'", _("Follow"));
- }
- // TRANSLATORS: popup menu item
- // TRANSLATORS: imitate player
- mBrowserBox->addRow("/imitation 'NAME'", _("Imitate"));
-}
-
-void PopupMenu::addBuySell(const Being *const being)
-{
- if ((playerRelations.getDefault() & PlayerRelation::TRADE) != 0u)
- {
- mBrowserBox->addSeparator("##3---");
- const bool haveVending =
- (Net::getNetworkType() != ServerType::TMWATHENA);
- if (being->isSellShopEnabled())
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: buy item
- mBrowserBox->addRow("/buy 'NAME'", _("Buy"));
- }
- else if (!haveVending)
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: buy item
- mBrowserBox->addRow("/buy 'NAME'", _("Buy (?)"));
- }
- if (being->isBuyShopEnabled())
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: sell item
- mBrowserBox->addRow("/sell 'NAME'", _("Sell"));
- }
- else if (!haveVending)
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: sell item
- mBrowserBox->addRow("/sell 'NAME'", _("Sell (?)"));
- }
- }
-}
-
-void PopupMenu::addBuySellDefault()
-{
- if ((playerRelations.getDefault() & PlayerRelation::TRADE) != 0u)
- {
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: buy item
- mBrowserBox->addRow("/buy 'NAME'", _("Buy (?)"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: sell item
- mBrowserBox->addRow("/sell 'NAME'", _("Sell (?)"));
- }
-}
-
-void PopupMenu::addPartyName(const std::string &partyName)
-{
- if (localPlayer->isInParty())
- {
- if (localPlayer->getParty() != nullptr)
- {
- if (localPlayer->getParty()->getName() != partyName)
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: invite player to party
- mBrowserBox->addRow("/party 'NAME'", _("Invite to party"));
- }
- else
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: kick player from party
- mBrowserBox->addRow("/kickparty 'NAME'", _("Kick from party"));
- showAdoptCommands();
- }
- mBrowserBox->addSeparator("##3---");
- }
- }
-}
-
-void PopupMenu::addParty(const std::string &nick)
-{
- if (localPlayer->isInParty())
- {
- const Party *const party = localPlayer->getParty();
- if (party != nullptr)
- {
- if (!party->isMember(nick))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: invite player to party
- mBrowserBox->addRow("/party 'NAME'", _("Invite to party"));
- }
- else
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: kick player from party
- mBrowserBox->addRow("/kickparty 'NAME'", _("Kick from party"));
- showAdoptCommands();
- }
- mBrowserBox->addSeparator("##3---");
- }
- }
-}
-
-void PopupMenu::addChat(const Being *const being)
-{
- if (being == nullptr)
- return;
- const ChatObject *const chat = being->getChat();
- if (chat != nullptr)
- {
- mBrowserBox->addRow("join chat",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: invite player to party
- strprintf(_("Join chat %s"), chat->title.c_str()).c_str());
- mBrowserBox->addSeparator("##3---");
- }
-}
-
-void PopupMenu::addPlayerMisc()
-{
- // TRANSLATORS: popup menu item
- mBrowserBox->addRow("/showitems :'BEINGID'", _("Show Items"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: undress player
- mBrowserBox->addRow("/undress :'BEINGID'", _("Undress"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add comment to player
- mBrowserBox->addRow("addcomment", _("Add comment"));
-}
-
-void PopupMenu::addPickupFilter(const std::string &name)
-{
- if (actorManager->isInPickupList(name)
- || actorManager->isInIgnorePickupList(name))
- {
- mBrowserBox->addRow("/removepickup 'NAME'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: remove item from pickup list
- _("Remove from pickup list"));
- }
- else
- {
- mBrowserBox->addRow("/addpickup 'NAME'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: popup menu item
- _("Add to pickup list"));
- mBrowserBox->addRow("/ignorepickup 'NAME'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add item to pickup list
- _("Add to ignore list"));
- }
-}
-
-void PopupMenu::showPopup(const int x, const int y,
- ListModel *const model)
-{
- if (model == nullptr)
- return;
-
- mBrowserBox->clearRows();
- for (int f = 0, sz = model->getNumberOfElements(); f < sz; f ++)
- {
- mBrowserBox->addRow(strprintf("dropdown_%d", f),
- model->getElementAt(f).c_str());
- }
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
- showPopup(x, y);
-}
-
-void PopupMenu::clear()
-{
- if (mDialog != nullptr)
- {
- mDialog->close();
- mDialog = nullptr;
- }
- mItemIndex = -1;
- mItemId = 0;
- for (int f = 0; f < maxCards; f ++)
- mItemCards[f] = 0;
- mMapItem = nullptr;
- mTab = nullptr;
- mSpell = nullptr;
- mCallerWindow = nullptr;
- mButton = nullptr;
- mTextField = nullptr;
-}
-
-void PopupMenu::addProtection()
-{
- if (PlayerInfo::isItemProtected(mItemId))
- {
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: remove protection from item
- mBrowserBox->addRow("/unprotectitem 'ITEMID'", _("Unprotect item"));
- }
- else
- {
- if (mItemId < SPELL_MIN_ID)
- {
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: add protection to item
- mBrowserBox->addRow("/protectitem 'ITEMID'", _("Protect item"));
- }
- }
-}
-
-void PopupMenu::addUse(const Item *const item)
-{
- const ItemInfo &info = item->getInfo();
- const std::string &str = (item->isEquipment() == Equipm_true
- && item->isEquipped() == Equipped_true)
- ? info.getUseButton2() : info.getUseButton();
-
- if (str.empty())
- {
- // TRANSLATORS: popup menu item
- mBrowserBox->addRow("/useinv 'INVINDEX'", _("Use"));
- }
- else
- {
- // TRANSLATORS: popup menu item
- mBrowserBox->addRow("/useinv 'INVINDEX'", str.c_str());
- }
-}
-
-void PopupMenu::addItemMenu(const Item *const item,
- const InventoryTypeT type)
-{
- const ItemInfo &info = item->getInfo();
- const STD_VECTOR<ItemMenuItem> *menu = nullptr;
- switch (type)
- {
- case InventoryType::Inventory:
- menu = &info.getInventoryMenuConst();
- break;
- case InventoryType::Storage:
- menu = &info.getStorageMenuConst();
- break;
- case InventoryType::Cart:
- menu = &info.getCartMenuConst();
- break;
- case InventoryType::Trade:
- case InventoryType::Npc:
- case InventoryType::Vending:
- case InventoryType::MailEdit:
- case InventoryType::MailView:
- case InventoryType::Craft:
- case InventoryType::TypeEnd:
- default:
- return;
- }
-
- const bool firstMode = (item->isEquipment() == Equipm_true ?
- (item->isEquipped() != Equipped_true) : (item->getQuantity() == 1));
-
- FOR_EACHP (STD_VECTOR<ItemMenuItem>::const_iterator, it, menu)
- {
- const ItemMenuItem &menuItem = *it;
- const std::string &name = firstMode ?
- menuItem.name1 : menuItem.name2;
- const std::string &command = firstMode ?
- menuItem.command1 : menuItem.command2;
- if (command.empty() ||
- name.empty())
- {
- continue;
- }
- mBrowserBox->addRow("/" + command, name.c_str());
- }
- mBrowserBox->addSeparator("##3---");
-}
-
-void PopupMenu::addDrop(const Item *const item,
- const bool isProtected)
-{
- if (!isProtected)
- {
- mBrowserBox->addSeparator("##3---");
- if (item->getQuantity() > 1)
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: drop item
- mBrowserBox->addRow("/dropinv 'INVINDEX'", _("Drop..."));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: drop all item amount
- mBrowserBox->addRow("/dropinvall 'INVINDEX'", _("Drop all"));
- }
- else
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: drop item
- mBrowserBox->addRow("/dropinv 'INVINDEX'", _("Drop"));
- }
- }
-}
-
-void PopupMenu::addGmCommands()
-{
- if (localPlayer->isGM())
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: gm commands
- mBrowserBox->addRow("gm", _("GM..."));
- }
-}
-
-void PopupMenu::showPlayerMenu()
-{
- mBrowserBox->clearRows();
- // TRANSLATORS: popup menu header
- mBrowserBox->addRow(strprintf(_("Show %s"),
- mName.c_str()));
- if (isAllowCommand(ServerCommandType::accinfo))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: show player account info
- mBrowserBox->addRow("/showaccountinfo 'NAME'", _("Account info"));
- }
- if (isAllowOtherCommand(ServerCommandType::exp))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: show player level
- mBrowserBox->addRow("/showlevel 'NAME'", _("Level"));
- }
- if (isAllowOtherCommand(ServerCommandType::stats))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: show player stats
- mBrowserBox->addRow("/showstats 'NAME'", _("Stats"));
- }
- if (isAllowOtherCommand(ServerCommandType::itemlist))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: show player inventory list
- mBrowserBox->addRow("/showinventory 'NAME'", _("Inventory"));
- }
- if (isAllowOtherCommand(ServerCommandType::storagelist))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: show player storage list
- mBrowserBox->addRow("/showstorage 'NAME'", _("Storage"));
- }
- if (isAllowOtherCommand(ServerCommandType::cartlist))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: show player cart list
- mBrowserBox->addRow("/showcart 'NAME'", _("Cart"));
- }
- if (isAllowOtherCommand(ServerCommandType::commands))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: gm commands
- mBrowserBox->addRow("/gmcommands 'NAME'", _("Commands"));
- }
- if (isAllowOtherCommand(ServerCommandType::charcommands))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: gm char commands
- mBrowserBox->addRow("/gmcharcommands 'NAME'", _("Char commands"));
- }
- // TRANSLATORS: popup menu item
- // TRANSLATORS: back to gm menu
- mBrowserBox->addRow("gm", _("Back"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
- showPopup(getX(), getY());
-}
-
-void PopupMenu::showPlayerGMCommands(const std::string &name)
-{
- if (localPlayer == nullptr)
- return;
- const bool legacy = Net::getNetworkType() == ServerType::TMWATHENA;
- if (!legacy && isAllowCommand(ServerCommandType::where))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: find player position
- mBrowserBox->addRow("/locateplayer 'NAME'", _("Locate"));
- }
- if (legacy)
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: check player ip
- mBrowserBox->addRow("/ipcheck 'NAME'", _("Check ip"));
- }
- if (isAllowCommand(ServerCommandType::jumpto))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: go to player position
- mBrowserBox->addRow("/gotopc 'NAME'", _("Goto"));
- }
- if (isAllowCommand(ServerCommandType::recall))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: recall player to current position
- mBrowserBox->addRow("/recallpc 'NAME'", _("Recall"));
- }
- if (isAllowOtherCommand(ServerCommandType::alive))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: revive player
- mBrowserBox->addRow("/alive 'NAME'", _("Revive"));
- }
- if (!legacy)
- {
- Being *const being = actorManager->findBeingByName(name,
- ActorType::Player);
- if (being != nullptr && being == localPlayer)
- {
- if (!being->getPartyName().empty() &&
- isAllowCommand(ServerCommandType::partyrecall))
- {
- mBrowserBox->addRow("/partyrecall 'PARTY'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: recall all party members to player location
- _("Recall party"));
- }
- if (!being->getGuildName().empty() &&
- isAllowCommand(ServerCommandType::guildrecall))
- {
- mBrowserBox->addRow("/guildrecall 'PARTY'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: recall all guild members to player location
- _("Recall guild"));
- }
- }
- if (localPlayer->isInParty())
- {
- const Party *const party = localPlayer->getParty();
- if (party != nullptr &&
- party->isMember(name) &&
- isAllowCommand(ServerCommandType::changeleader))
- {
- mBrowserBox->addRow("/gmpartyleader 'NAME'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: give party leader status
- _("Give party leader"));
- }
- }
-
- if (isAllowCommand(ServerCommandType::nuke))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: nuke player
- mBrowserBox->addRow("/gmnuke 'NAME'", _("Nuke"));
- }
- if (isAllowOtherCommand(ServerCommandType::kill))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: kill player
- mBrowserBox->addRow("/kill 'NAME'", _("Kill"));
- }
- if (mBeingId != BeingId_zero)
- {
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: show menu
- mBrowserBox->addRow("show", _("Show..."));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: mute menu
- mBrowserBox->addRow("mute", _("Mute..."));
- }
- }
- if (legacy)
- {
- if (localPlayer->getName() == mName)
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: hide player
- mBrowserBox->addRow("/hide", _("Hide"));
- mBrowserBox->addSeparator("##3---");
- }
- }
- else
- {
- if (isAllowOtherCommand(ServerCommandType::heal))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: heal player
- mBrowserBox->addRow("/gmheal 'NAME'", _("Heal"));
- }
- if (isAllowOtherCommand(ServerCommandType::monsterignore))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: enable immortal mode for player
- mBrowserBox->addRow("/immortal 'NAME'", _("Immortal"));
- }
- if (isAllowCommand(ServerCommandType::jail))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: send player to jail
- mBrowserBox->addRow("/jail 'NAME'", _("Jail"));
- }
- if (isAllowCommand(ServerCommandType::unjail))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: restore player from jail
- mBrowserBox->addRow("/unjail 'NAME'", _("Unjail"));
- }
- if (name == localPlayer->getName() &&
- isAllowCommand(ServerCommandType::hide))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: hide player
- mBrowserBox->addRow("/hide 'NAME'", _("Hide"));
- }
- mBrowserBox->addSeparator("##3---");
- if (isAllowOtherCommand(ServerCommandType::killer))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: set player as killer
- mBrowserBox->addRow("/killer 'NAME'", _("Killer"));
- }
- if (isAllowOtherCommand(ServerCommandType::killable))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: set player as killable
- mBrowserBox->addRow("/killable 'NAME'", _("Killable"));
- }
- if (isAllowOtherCommand(ServerCommandType::save))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: set player save position
- mBrowserBox->addRow("/savepos 'NAME'", _("Set save"));
- }
- if (isAllowOtherCommand(ServerCommandType::load))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: warp player to save position
- mBrowserBox->addRow("/loadpos 'NAME'", _("Warp to save"));
- }
- if (isAllowOtherCommand(ServerCommandType::jump))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: warp player to random position on same map
- mBrowserBox->addRow("/randomwarp 'NAME'", _("Warp to random"));
- }
- mBrowserBox->addSeparator("##3---");
- if (isAllowCommand(ServerCommandType::clone))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: spawn player clone
- mBrowserBox->addRow("/spawnclone 'NAME'", _("Spawn clone"));
- }
- if (isAllowCommand(ServerCommandType::slaveclone))
- {
- mBrowserBox->addRow("/spawnslaveclone 'NAME'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: spawn slave player clone
- _("Spawn slave clone"));
- }
- if (isAllowCommand(ServerCommandType::evilclone))
- {
- mBrowserBox->addRow("/spawnevilclone 'NAME'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: spawn evil player clone
- _("Spawn evil clone"));
- }
- mBrowserBox->addSeparator("##3---");
- if (isAllowOtherCommand(ServerCommandType::breakguild))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: break guild
- mBrowserBox->addRow("/gmbreakguild 'NAME'", _("Break guild"));
- }
- }
- if (mBeingId != BeingId_zero &&
- isAllowCommand(ServerCommandType::kick))
- {
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: kick player
- mBrowserBox->addRow("/kick :'BEINGID'", _("Kick"));
- }
-}
-
-void PopupMenu::showMuteCommands()
-{
- mBrowserBox->clearRows();
- // TRANSLATORS: popup menu header
- mBrowserBox->addRow(strprintf(_("Mute %s"),
- mName.c_str()));
- if (mBeingId != BeingId_zero &&
- Net::getNetworkType() != ServerType::TMWATHENA &&
- isAllowCommand(ServerCommandType::mute))
- {
- mBrowserBox->addRow("mute_+1",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: mute player
- strprintf(_("Mute %d"), 1).c_str());
- mBrowserBox->addRow("mute_+5",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: mute player
- strprintf(_("Mute %d"), 5).c_str());
- mBrowserBox->addRow("mute_+10",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: mute player
- strprintf(_("Mute %d"), 10).c_str());
- mBrowserBox->addRow("mute_+15",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: mute player
- strprintf(_("Mute %d"), 15).c_str());
- mBrowserBox->addRow("mute_+30",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: mute player
- strprintf(_("Mute %d"), 30).c_str());
-
- mBrowserBox->addRow("mute_-1",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: mute player
- strprintf(_("Unmute %d"), 1).c_str());
- mBrowserBox->addRow("mute_-5",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: mute player
- strprintf(_("Unmute %d"), 5).c_str());
- mBrowserBox->addRow("mute_-10",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: mute player
- strprintf(_("Unmute %d"), 10).c_str());
- mBrowserBox->addRow("mute_-15",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: mute player
- strprintf(_("Unmute %d"), 15).c_str());
- mBrowserBox->addRow("mute_-30",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: mute player
- strprintf(_("Unmute %d"), 30).c_str());
- mBrowserBox->addSeparator("##3---");
- }
- // TRANSLATORS: popup menu item
- // TRANSLATORS: back to gm menu
- mBrowserBox->addRow("gm", _("Back"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
- showPopup(getX(), getY());
-}
-
-void PopupMenu::showNpcGMCommands()
-{
- if (mBeingId != BeingId_zero)
- {
- if (isAllowCommand(ServerCommandType::kick))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: kick player
- mBrowserBox->addRow("/kick :'BEINGID'", _("Kick"));
- }
- const bool legacy = Net::getNetworkType() == ServerType::TMWATHENA;
- if (!legacy)
- {
- if (isAllowCommand(ServerCommandType::hidenpc))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: hide npc
- mBrowserBox->addRow("/hidenpc 'EXTNAME'", _("Hide"));
- }
- mBrowserBox->addSeparator("##3---");
- if (isAllowCommand(ServerCommandType::npcmove))
- {
- mBrowserBox->addRow("/npcmove 'EEXTNAME' 'PLAYERX' 'PLAYERY'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: warp npc to player location
- _("Recall"));
- }
- if (isAllowCommand(ServerCommandType::disguise))
- {
- mBrowserBox->addRow("/disguise 'BEINGSUBTYPEID'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: disguise to npc
- _("Disguise"));
- }
- if (isAllowCommand(ServerCommandType::tonpc))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: warp to npc
- mBrowserBox->addRow("/gotonpc 'EXTNAME'", _("Goto"));
- }
- }
- }
-}
-
-void PopupMenu::showMonsterGMCommands()
-{
- if (mBeingId != BeingId_zero)
- {
- const bool legacy = Net::getNetworkType() == ServerType::TMWATHENA;
- if (isAllowCommand(ServerCommandType::kick))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: kick monster
- mBrowserBox->addRow("/kick :'BEINGID'", _("Kick"));
- }
- if (isAllowCommand(ServerCommandType::monster))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: spawn monster
- mBrowserBox->addRow("/spawn 'BEINGSUBTYPEID'", _("Spawn same"));
- }
- if (!legacy)
- {
- if (isAllowCommand(ServerCommandType::summon))
- {
- mBrowserBox->addRow("/spawnslave 'BEINGSUBTYPEID'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: spawn slave monster
- _("Spawn slave"));
- }
- if (isAllowCommand(ServerCommandType::disguise))
- {
- mBrowserBox->addRow("/disguise 'BEINGSUBTYPEID'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: disguise to monster
- _("Disguise"));
- }
- mBrowserBox->addSeparator("##3---");
- if (isAllowCommand(ServerCommandType::mobinfo))
- {
- mBrowserBox->addRow("/monsterinfo 'BEINGSUBTYPEID'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: show monster information
- _("Info"));
- }
- if (isAllowCommand(ServerCommandType::mobsearch))
- {
- mBrowserBox->addRow("/mobsearch 'BEINGSUBTYPEID'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: show selected monster in current map
- _("Search"));
- }
- if (isAllowCommand(ServerCommandType::whereis))
- {
- mBrowserBox->addRow("/mobspawnsearch 'BEINGSUBTYPEID'",
- // TRANSLATORS: popup menu item
- // TRANSLATORS: show selected monster spawns in all maps
- _("Search spawns"));
- }
- }
- }
-}
-
-void PopupMenu::showFloorItemGMCommands()
-{
- const bool legacy = Net::getNetworkType() == ServerType::TMWATHENA;
- if (legacy)
- return;
- if (isAllowCommand(ServerCommandType::iteminfo))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: show item information
- mBrowserBox->addRow("/iteminfo 'ITEMID'", _("Info"));
- }
- if (isAllowCommand(ServerCommandType::whodrops))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: show who drops item
- mBrowserBox->addRow("/whodrops 'ITEMID'", _("Who drops"));
- }
-}
-
-void PopupMenu::showItemGMCommands()
-{
- const bool legacy = Net::getNetworkType() == ServerType::TMWATHENA;
- if (legacy)
- return;
- if (isAllowCommand(ServerCommandType::iteminfo))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: show item information
- mBrowserBox->addRow("/iteminfo 'ITEMID'", _("Info"));
- }
- if (isAllowCommand(ServerCommandType::whodrops))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: show who drops item
- mBrowserBox->addRow("/whodrops 'ITEMID'", _("Who drops"));
- }
- mBrowserBox->addSeparator("##3---");
- if (isAllowCommand(ServerCommandType::item))
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: gm create item
- mBrowserBox->addRow("/createitem 'ITEMID' 1", _("Add 1"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: gm create item
- mBrowserBox->addRow("/createitem 'ITEMID' 5", _("Add 5"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: gm create item
- mBrowserBox->addRow("/createitem 'ITEMID' 10", _("Add 10"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: gm create item
- mBrowserBox->addRow("/createitem 'ITEMID' 100", _("Add 100"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: gm create item
- mBrowserBox->addRow("/createitem 'ITEMID' 1000", _("Add 1000"));
- // TRANSLATORS: popup menu item
- // TRANSLATORS: gm create item
- mBrowserBox->addRow("/createitem 'ITEMID' 10000", _("Add 10000"));
- }
-}
-
-void PopupMenu::showGMPopup(const std::string &name)
-{
- mBrowserBox->clearRows();
- // TRANSLATORS: popup menu header
- mBrowserBox->addRow(_("GM commands"));
- if (localPlayer->isGM())
- {
- switch (mType)
- {
- case ActorType::Player:
- showPlayerGMCommands(name);
- break;
- case ActorType::Npc:
- showNpcGMCommands();
- break;
- case ActorType::Monster:
- showMonsterGMCommands();
- break;
- case ActorType::FloorItem:
- showFloorItemGMCommands();
- break;
- case ActorType::Homunculus:
- showHomunGMCommands();
- break;
- case ActorType::Pet:
- showPetGMCommands();
- break;
- case ActorType::Mercenary:
- showMercenaryGMCommands();
- break;
- case ActorType::SkillUnit:
- break;
- default:
- case ActorType::Unknown:
- if (mItemId != 0)
- showItemGMCommands();
- break;
- case ActorType::Portal:
- case ActorType::Avatar:
- case ActorType::Elemental:
- break;
- }
- }
-
- mBrowserBox->addSeparator("##3---");
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(getX(), getY());
-}
-
-void PopupMenu::showHomunGMCommands()
-{
-}
-
-void PopupMenu::showPetGMCommands()
-{
-}
-
-void PopupMenu::showMercenaryGMCommands()
-{
-}
-
-void PopupMenu::showCraftPopup()
-{
- mBrowserBox->clearRows();
-
- for (int f = 0; f < 9; f ++)
- {
- const std::string cmd = strprintf("/craft %d", f);
- mBrowserBox->addRow(cmd,
- // TRANSLATORS: popup menu item
- // TRANSLATORS: move current item to craft slot
- strprintf(_("Move to craft %d"), f + 1).c_str());
- }
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
-
- showPopup(mX, mY);
-}
-
-void PopupMenu::addMailCommands()
-{
- if (Net::getNetworkType() == ServerType::TMWATHENA)
- return;
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: open mail dialog
- mBrowserBox->addRow("/mailto 'NAME'", _("Mail to..."));
-}
-
-void PopupMenu::addCatchPetCommands()
-{
- if (Net::getNetworkType() == ServerType::TMWATHENA)
- return;
- // TRANSLATORS: popup menu item
- // TRANSLATORS: catch pet command
- mBrowserBox->addRow("/catchpet :'BEINGID'", _("Taming pet"));
-}
-
-void PopupMenu::showAdoptCommands()
-{
- if (Net::getNetworkType() == ServerType::TMWATHENA)
- return;
- // TRANSLATORS: popup menu item
- // TRANSLATORS: adopt child command
- mBrowserBox->addRow("/adoptchild 'NAME'", _("Adopt child"));
-}
-
-void PopupMenu::addSocialMenu()
-{
- initPopup();
- mBrowserBox->clearRows();
- setMousePos();
- const Party *const party = localPlayer->getParty();
- if (party != nullptr)
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: leave party
- mBrowserBox->addRow("/leaveparty", _("Leave party"));
- }
- else
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: create party
- mBrowserBox->addRow("/createparty", _("Create party"));
- }
-
- if (Net::getNetworkType() != ServerType::TMWATHENA)
- {
- const Guild *const guild = localPlayer->getGuild();
- if (guild != nullptr)
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: leave guild
- mBrowserBox->addRow("/leaveguild", _("Leave guild"));
- }
- else
- {
- // TRANSLATORS: popup menu item
- // TRANSLATORS: create guild
- mBrowserBox->addRow("/createguild", _("Create guild"));
- }
- }
- mBrowserBox->addSeparator("##3---");
-}
-
-void PopupMenu::showPartyPopup()
-{
- addSocialMenu();
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
- showPopup(mX, mY);
-}
-
-void PopupMenu::showGuildPopup()
-{
- addSocialMenu();
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: change guild notice message
- mBrowserBox->addRow("/guildnotice", _("Change notice"));
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
- showPopup(mX, mY);
-}
-
-void PopupMenu::showAttackPopup()
-{
- addSocialMenu();
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
- showPopup(mX, mY);
-}
-
-void PopupMenu::showNavigationPopup()
-{
- addSocialMenu();
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
- showPopup(mX, mY);
-}
-
-void PopupMenu::showPickupPopup()
-{
- addSocialMenu();
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
- showPopup(mX, mY);
-}
-
-void PopupMenu::showPlayersPopup()
-{
- addSocialMenu();
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
- showPopup(mX, mY);
-}
-
-void PopupMenu::showFriendsPopup()
-{
- addSocialMenu();
-
- // TRANSLATORS: popup menu item
- // TRANSLATORS: close menu
- mBrowserBox->addRow("cancel", _("Cancel"));
- showPopup(mX, mY);
-}
-
-void PopupMenu::moveUp()
-{
- mBrowserBox->moveSelectionUp();
-}
-
-void PopupMenu::moveDown()
-{
- mBrowserBox->moveSelectionDown();
-}
-
-void PopupMenu::select()
-{
- mBrowserBox->selectSelection();
-}
diff --git a/src/gui/popups/popupmenu.h b/src/gui/popups/popupmenu.h
deleted file mode 100644
index 5b554e197..000000000
--- a/src/gui/popups/popupmenu.h
+++ /dev/null
@@ -1,321 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_POPUPS_POPUPMENU_H
-#define GUI_POPUPS_POPUPMENU_H
-
-#ifndef DYECMD
-
-#include "const/resources/item/cards.h"
-
-#include "enums/inventorytype.h"
-
-#include "enums/resources/servercommandtype.h"
-
-#include "enums/simpletypes/beingid.h"
-#include "enums/simpletypes/beingtypeid.h"
-#include "enums/simpletypes/itemcolor.h"
-
-#include "gui/widgets/linkhandler.h"
-#include "gui/widgets/popup.h"
-
-#include "listeners/playerlistener.h"
-#include "listeners/renamelistener.h"
-
-#include "localconsts.h"
-
-class ActorSprite;
-class Being;
-class Button;
-class ChatTab;
-class FloorItem;
-class Item;
-class ListModel;
-class MapItem;
-class ProgressBar;
-class ScrollArea;
-class StaticBrowserBox;
-class TextCommand;
-class TextDialog;
-class TextField;
-class Window;
-
-struct GroupInfo;
-struct SkillInfo;
-
-/**
- * Window showing popup menu.
- */
-class PopupMenu final : public Popup, public LinkHandler
-{
- public:
- /**
- * Constructor.
- */
- PopupMenu();
-
- A_DELETE_COPY(PopupMenu)
-
- void postInit() override final;
-
- /**
- * Shows the being related popup menu at the specified mouse coords.
- */
- void showPopup(const int x, const int y, const Being *const being);
-
- /**
- * Shows the beings related popup menu at the specified mouse coords.
- */
- void showPopup(const int x, const int y,
- const STD_VECTOR<ActorSprite*> &beings);
-
- void showPlayerPopup(const std::string &nick);
-
- /**
- * Shows the floor item related popup menu at the specified
- * mouse coords.
- */
- void showPopup(const int x, const int y,
- const FloorItem *const floorItem);
-
- /**
- * Shows the related popup menu when right click on the inventory
- * at the specified mouse coordinates.
- */
- void showPopup(Window *const parent,
- const int x, const int y,
- const Item *const item,
- const InventoryTypeT type);
-
- void showPopup(const int x, const int y, Button *const button);
-
- void showPopup(const int x, const int y, const ProgressBar *const bar);
-
- void showPopup(const int x, const int y, MapItem *const mapItem);
-
- void showItemPopup(const int x,
- const int y,
- const Item *const item);
-
- void showItemPopup(const int x, const int y,
- const int itemId,
- const ItemColor color);
-
- void showDropPopup(const int x,
- const int y,
- const Item *const item);
-
- void showOutfitsWindowPopup(const int x, const int y);
-
- void showSpellPopup(const int x, const int y, TextCommand *const cmd);
-
- void showAttackMonsterPopup(const int x, const int y,
- const std::string &name,
- const int type);
-
- void showPickupItemPopup(const int x, const int y,
- const std::string &name);
-
- void showUndressPopup(const int x, const int y,
- const Being *const being,
- const Item *const item);
-
- void showMapPopup(const int x, const int y,
- const int x2, const int y2,
- const bool isMinimap);
-
- /**
- * Shows the related popup menu when right click on the chat
- * at the specified mouse coordinates.
- */
- void showChatPopup(const int x, const int y, ChatTab *const tab);
-
- void showChangePos(const int x, const int y);
-
- void showPopup(const int x, const int y, ListModel *const model);
-
- void showTextFieldPopup(TextField *const input);
-
- void showLinkPopup(const std::string &link);
-
- void showWindowsPopup();
-
- void showNpcDialogPopup(const BeingId npcId,
- const int x, const int y);
-
- void showWindowPopup(Window *const window);
-
- void showSkillPopup(const SkillInfo *const info);
-
- void showSkillLevelPopup(const SkillInfo *const info);
-
- void showSkillTypePopup(const SkillInfo *const info);
-
- void showSkillOffsetPopup(const SkillInfo *const info,
- const bool isOffsetX);
-
- void showCraftPopup();
-
- void showEmoteType();
-
- void showPartyPopup();
-
- void showGuildPopup();
-
- void showAttackPopup();
-
- void showNavigationPopup();
-
- void showPickupPopup();
-
- void showPlayersPopup();
-
- void showFriendsPopup();
-
- /**
- * Handles link action.
- */
- void handleLink(const std::string &link,
- MouseEvent *event A_UNUSED) override final;
-
- void clear() override final;
-
- void moveUp();
-
- void moveDown();
-
- void select();
-
- private:
- void initPopup();
-
- bool isAllowCommand(const ServerCommandTypeT command);
-
- bool isAllowOtherCommand(const ServerCommandTypeT command);
-
- void setMousePos();
-
- void setMousePos2();
-
- void addPlayerRelation(const std::string &name);
-
- void addFollow();
-
- void addBuySell(const Being *const being) A_NONNULL(2);
-
- void addParty(const std::string &nick);
-
- void addPartyName(const std::string &partyName);
-
- void addBuySellDefault();
-
- void addPlayerMisc();
-
- void addPickupFilter(const std::string &name);
-
- void addProtection();
-
- void addUse(const Item *const item) A_NONNULL(2);
-
- void addItemMenu(const Item *const item,
- const InventoryTypeT type) A_NONNULL(2);
-
- void addDrop(const Item *const item,
- const bool isProtected) A_NONNULL(2);
-
- void addGmCommands();
-
- void showMuteCommands();
-
- void showPlayerMenu();
-
- void showFloorItemGMCommands();
-
- void showItemGMCommands();
-
- void addNormalRelations();
-
- void addWindowMenu(const Window *const window);
-
- void showHomunGMCommands();
-
- void showPetGMCommands();
-
- void showMercenaryGMCommands();
-
- void addChat(const Being *const being);
-
- void addMailCommands();
-
- void addCatchPetCommands();
-
- void showGMPopup(const std::string &name);
-
- void showPlayerGMCommands(const std::string &name);
-
- void showNpcGMCommands();
-
- void showMonsterGMCommands();
-
- void showAdoptCommands();
-
- void addSocialMenu();
-
- bool addBeingMenu();
-
- StaticBrowserBox *mBrowserBox A_NONNULLPOINTER;
- ScrollArea *mScrollArea A_NONNULLPOINTER;
-
- BeingId mBeingId;
- BeingId mFloorItemId;
- int mItemId;
- int mItemIndex;
- int mItemCards[maxCards];
- ItemColor mItemColor;
- MapItem *mMapItem;
- ChatTab *mTab;
- TextCommand *mSpell;
- Window *mCallerWindow;
- RenameListener mRenameListener;
- PlayerListener mPlayerListener;
- TextDialog *mDialog;
- Button *mButton;
- const GroupInfo *mGroup;
- std::string mName;
- std::string mExtName;
- TextField *mTextField;
- ActorTypeT mType;
- BeingTypeId mSubType;
- int mX;
- int mY;
- bool mAllowCleanMenu;
-
- /**
- * Shared code for the various showPopup functions.
- */
- void showPopup(int x, int y);
-};
-
-extern PopupMenu *popupMenu;
-
-#endif // DYE_CMD
-#endif // GUI_POPUPS_POPUPMENU_H
diff --git a/src/gui/popups/skillpopup.cpp b/src/gui/popups/skillpopup.cpp
deleted file mode 100644
index c2a583e30..000000000
--- a/src/gui/popups/skillpopup.cpp
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 The Legend of Mazzeroth Development Team
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/popups/skillpopup.h"
-
-#include "gui/gui.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/widgets/label.h"
-#include "gui/widgets/textbox.h"
-
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include "resources/skill/skilldata.h"
-#include "resources/skill/skillinfo.h"
-
-#include "debug.h"
-
-SkillPopup *skillPopup = nullptr;
-
-SkillPopup::SkillPopup() :
- Popup("SkillPopup", "skillpopup.xml"),
- mSkillName(new Label(this)),
- mSkillDesc(new TextBox(this)),
- mSkillEffect(new TextBox(this)),
- mSkillLevel(new TextBox(this)),
- mSkillCastType(new TextBox(this)),
- mCastType(CastType::Default),
- mLastId(0U),
- mLastLevel(-1),
- mOffsetX(0),
- mOffsetY(0)
-{
- mSkillName->setFont(boldFont);
- mSkillName->setPosition(0, 0);
- mSkillName->setForegroundColorAll(getThemeColor(ThemeColorId::POPUP),
- getThemeColor(ThemeColorId::POPUP_OUTLINE));
-
- const int fontHeight = getFont()->getHeight();
-
- mSkillDesc->setEditable(false);
- mSkillDesc->setPosition(0, fontHeight);
- mSkillDesc->setForegroundColorAll(getThemeColor(ThemeColorId::POPUP),
- getThemeColor(ThemeColorId::POPUP_OUTLINE));
-
- mSkillEffect->setEditable(false);
- mSkillEffect->setPosition(0, 2 * fontHeight);
- mSkillEffect->setForegroundColorAll(getThemeColor(ThemeColorId::POPUP),
- getThemeColor(ThemeColorId::POPUP_OUTLINE));
-
- mSkillLevel->setEditable(false);
- mSkillLevel->setPosition(0, 3 * fontHeight);
- mSkillLevel->setForegroundColorAll(getThemeColor(ThemeColorId::POPUP),
- getThemeColor(ThemeColorId::POPUP_OUTLINE));
-
- mSkillCastType->setEditable(false);
- mSkillCastType->setPosition(0, 4 * fontHeight);
- mSkillCastType->setForegroundColorAll(getThemeColor(ThemeColorId::POPUP),
- getThemeColor(ThemeColorId::POPUP_OUTLINE));
-}
-
-void SkillPopup::postInit()
-{
- Popup::postInit();
- add(mSkillName);
- add(mSkillDesc);
- add(mSkillEffect);
- add(mSkillLevel);
- add(mSkillCastType);
-
- addMouseListener(this);
-}
-
-SkillPopup::~SkillPopup()
-{
-}
-
-void SkillPopup::show(const SkillInfo *const skill,
- const int level,
- const CastTypeT castType,
- const int offsetX,
- const int offsetY)
-{
- if ((skill == nullptr) ||
- (skill->data == nullptr) ||
- (skill->id == mLastId &&
- level == mLastLevel &&
- castType == mCastType &&
- offsetX == mOffsetX &&
- offsetY == mOffsetY))
- {
- return;
- }
-
- mLastId = skill->id;
- mLastLevel = level;
- mCastType = castType;
- mOffsetX = offsetX;
- mOffsetY = offsetY;
-
- mSkillName->setCaption(skill->data->dispName);
- mSkillName->adjustSize();
- mSkillName->setPosition(0, 0);
-
- std::string description = skill->data->description;
- std::string effect = skill->skillEffect;
- if (description.empty())
- {
- description = effect;
- effect.clear();
- }
- mSkillDesc->setTextWrapped(description, 196);
- mSkillEffect->setTextWrapped(effect, 196);
- if (level != 0)
- {
- mSkillLevel->setTextWrapped(strprintf(
- // TRANSLATORS: skill level
- _("Level: %d / %d"), level, skill->level),
- 196);
- }
- else
- {
- if (skill->level != 0)
- {
- mSkillLevel->setTextWrapped(strprintf(
- // TRANSLATORS: skill level
- _("Level: %d"), skill->level),
- 196);
- }
- else
- {
- mSkillLevel->setTextWrapped(
- // TRANSLATORS: skill level for tmw fake skills
- _("Level: Unknown"),
- 196);
- }
- }
- std::string castStr;
- switch (castType)
- {
- case CastType::Default:
- default:
- // TRANSLATORS: skill cast type
- castStr = _("Default");
- break;
- case CastType::Target:
- // TRANSLATORS: skill cast type
- castStr = _("Target");
- break;
- case CastType::Position:
- // TRANSLATORS: skill cast type
- castStr = _("Mouse position");
- break;
- case CastType::Self:
- // TRANSLATORS: skill cast type
- castStr = _("Self position");
- break;
- }
- if (offsetX != 0 ||
- offsetY != 0)
- {
- castStr.append(strprintf(" (%+d,%+d)",
- offsetX,
- offsetY));
- }
- mSkillCastType->setTextWrapped(strprintf(
- // TRANSLATORS: skill cast type
- _("Cast type: %s"),
- castStr.c_str()), 196);
-
- int minWidth = mSkillName->getWidth();
-
- if (mSkillName->getWidth() > minWidth)
- minWidth = mSkillName->getWidth();
- if (mSkillDesc->getMinWidth() > minWidth)
- minWidth = mSkillDesc->getMinWidth();
- if (mSkillEffect->getMinWidth() > minWidth)
- minWidth = mSkillEffect->getMinWidth();
- if (mSkillLevel->getMinWidth() > minWidth)
- minWidth = mSkillLevel->getMinWidth();
- if (mSkillCastType->getMinWidth() > minWidth)
- minWidth = mSkillCastType->getMinWidth();
-
- const int numRowsDesc = mSkillDesc->getNumberOfRows();
- const int numRowsEffect = mSkillEffect->getNumberOfRows();
- const int numRowsLevel = mSkillLevel->getNumberOfRows();
- const int numRowsCast = mSkillCastType->getNumberOfRows();
- const int height = getFont()->getHeight();
-
- if (skill->skillEffect.empty())
- {
- setContentSize(minWidth,
- (numRowsDesc + numRowsLevel + numRowsCast + 1) * height);
- mSkillLevel->setPosition(0, (numRowsDesc + 1) * height);
- mSkillCastType->setPosition(0, (numRowsDesc + 2) * height);
- }
- else
- {
- setContentSize(minWidth,
- (numRowsDesc + numRowsLevel + numRowsEffect + numRowsCast + 1) *
- height);
- mSkillEffect->setPosition(0, (numRowsDesc + 1) * height);
- mSkillLevel->setPosition(0,
- (numRowsDesc + numRowsEffect + 1) * height);
- mSkillCastType->setPosition(0,
- (numRowsDesc + numRowsEffect + 2) * height);
- }
-
- mSkillDesc->setPosition(0, 1 * height);
-}
-
-void SkillPopup::mouseMoved(MouseEvent &event)
-{
- Popup::mouseMoved(event);
-
- // When the mouse moved on top of the popup, hide it
- setVisible(Visible_false);
- mLastId = 0;
-}
-
-void SkillPopup::reset()
-{
- mLastId = 0;
- mLastLevel = 0;
- mCastType = CastType::Default;
- mOffsetX = 0;
- mOffsetY = 0;
-}
diff --git a/src/gui/popups/skillpopup.h b/src/gui/popups/skillpopup.h
deleted file mode 100644
index d62916ed0..000000000
--- a/src/gui/popups/skillpopup.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 The Legend of Mazzeroth Development Team
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_POPUPS_SKILLPOPUP_H
-#define GUI_POPUPS_SKILLPOPUP_H
-
-#include "gui/widgets/popup.h"
-
-#include "enums/resources/skill/casttype.h"
-
-class Label;
-class TextBox;
-
-struct SkillInfo;
-
-/**
- * A popup that displays information about an item.
- */
-class SkillPopup final : public Popup
-{
- public:
- /**
- * Constructor. Initializes the skill popup.
- */
- SkillPopup();
-
- A_DELETE_COPY(SkillPopup)
-
- /**
- * Destructor. Cleans up the skill popup on deletion.
- */
- ~SkillPopup();
-
- void postInit() override final;
-
- /**
- * Sets the info to be displayed given a particular item.
- */
- void show(const SkillInfo *const skill,
- const int level,
- const CastTypeT type,
- const int offsetX,
- const int offsetY);
-
- void mouseMoved(MouseEvent &event) override final;
-
- void reset();
-
- private:
- Label *mSkillName A_NONNULLPOINTER;
- TextBox *mSkillDesc A_NONNULLPOINTER;
- TextBox *mSkillEffect A_NONNULLPOINTER;
- TextBox *mSkillLevel A_NONNULLPOINTER;
- TextBox *mSkillCastType A_NONNULLPOINTER;
- CastTypeT mCastType;
- unsigned int mLastId;
- int mLastLevel;
- int mOffsetX;
- int mOffsetY;
-};
-
-extern SkillPopup *skillPopup;
-
-#endif // GUI_POPUPS_SKILLPOPUP_H
diff --git a/src/gui/popups/speechbubble.cpp b/src/gui/popups/speechbubble.cpp
deleted file mode 100644
index 1ae67fb99..000000000
--- a/src/gui/popups/speechbubble.cpp
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 The Legend of Mazzeroth Development Team
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/popups/speechbubble.h"
-
-#include "gui/gui.h"
-#include "gui/skin.h"
-#include "gui/viewport.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/widgets/label.h"
-#include "gui/widgets/staticbrowserbox.h"
-
-#include "debug.h"
-
-SpeechBubble::SpeechBubble() :
- Popup("Speech", "speechbubble.xml"),
- mText(),
- mSpacing(mSkin != nullptr ? mSkin->getOption("spacing") : 2),
- mCaption(new Label(this)),
- mSpeechBox(new StaticBrowserBox(this, Opaque_true,
- "speechbrowserbox.xml"))
-{
- setContentSize(140, 46);
- setMinWidth(8);
- setMinHeight(8);
-
- mCaption->setFont(boldFont);
- mSpeechBox->setOpaque(Opaque_false);
- mSpeechBox->setForegroundColorAll(getThemeColor(ThemeColorId::BUBBLE_TEXT),
- getThemeColor(ThemeColorId::BUBBLE_TEXT_OUTLINE));
-}
-
-void SpeechBubble::postInit()
-{
- Popup::postInit();
- add(mCaption);
- add(mSpeechBox);
-}
-
-void SpeechBubble::setCaption(const std::string &name,
- const Color *const color1,
- const Color *const color2)
-{
- mCaption->setCaption(name);
- mCaption->adjustSize();
- mCaption->setForegroundColorAll(*color1, *color2);
-}
-
-void SpeechBubble::setText(const std::string &text, const bool showName)
-{
- if (text == mText && (mCaption->getWidth() <= mSpeechBox->getWidth()))
- return;
-
- mSpeechBox->setForegroundColorAll(getThemeColor(ThemeColorId::BUBBLE_TEXT),
- getThemeColor(ThemeColorId::BUBBLE_TEXT_OUTLINE));
-
- int width = mCaption->getWidth();
- mSpeechBox->clearRows();
- mSpeechBox->addRow(text);
- mSpeechBox->updateHeight();
-
- const int speechWidth = mSpeechBox->getWidth();
- const int nameHeight = showName ? mCaption->getHeight() + mSpacing : 0;
-
- if (width < speechWidth)
- width = speechWidth;
-
- setContentSize(width, getFont()->getHeight() + nameHeight);
- mCaption->setPosition(0, 0);
- mSpeechBox->setPosition(0, nameHeight);
-}
-
-void SpeechBubble::requestMoveToBackground()
-{
- windowContainer->moveWidgetAfter(viewport, this);
-}
diff --git a/src/gui/popups/speechbubble.h b/src/gui/popups/speechbubble.h
deleted file mode 100644
index 694a6eb2a..000000000
--- a/src/gui/popups/speechbubble.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 The Legend of Mazzeroth Development Team
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_POPUPS_SPEECHBUBBLE_H
-#define GUI_POPUPS_SPEECHBUBBLE_H
-
-#include "gui/widgets/popup.h"
-
-class Label;
-class StaticBrowserBox;
-
-class SpeechBubble final : public Popup
-{
- public:
- /**
- * Constructor. Initializes the speech bubble.
- */
- SpeechBubble();
-
- A_DELETE_COPY(SpeechBubble)
-
- void postInit() override final;
-
- /**
- * Sets the name displayed for the speech bubble, and in what color.
- */
- void setCaption(const std::string &name,
- const Color *const color1 = &theme->getColor(
- ThemeColorId::BUBBLE_NAME, 255),
- const Color *const color2 = &theme->getColor(
- ThemeColorId::BUBBLE_NAME_OUTLINE, 255));
-
- /**
- * Sets the text to be displayed.
- */
- void setText(const std::string &text, const bool showName = true);
-
- void requestMoveToBackground();
-
- private:
- std::string mText;
- int mSpacing;
- Label *mCaption A_NONNULLPOINTER;
- StaticBrowserBox *mSpeechBox A_NONNULLPOINTER;
-};
-
-#endif // GUI_POPUPS_SPEECHBUBBLE_H
diff --git a/src/gui/popups/spellpopup.cpp b/src/gui/popups/spellpopup.cpp
deleted file mode 100644
index 16169d81e..000000000
--- a/src/gui/popups/spellpopup.cpp
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 The Legend of Mazzeroth Development Team
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/popups/spellpopup.h"
-
-#include "textcommand.h"
-
-#include "gui/gui.h"
-
-#include "gui/widgets/label.h"
-
-#include "debug.h"
-
-SpellPopup *spellPopup = nullptr;
-
-SpellPopup::SpellPopup() :
- Popup("SpellPopup", "spellpopup.xml"),
- mItemName(new Label(this)),
- mItemComment(new Label(this))
-{
- mItemName->setFont(boldFont);
- mItemName->setForegroundColorAll(getThemeColor(ThemeColorId::POPUP),
- getThemeColor(ThemeColorId::POPUP_OUTLINE));
- mItemComment->setForegroundColorAll(getThemeColor(ThemeColorId::POPUP),
- getThemeColor(ThemeColorId::POPUP_OUTLINE));
-}
-
-void SpellPopup::postInit()
-{
- Popup::postInit();
- add(mItemName);
- add(mItemComment);
-
- addMouseListener(this);
-}
-
-SpellPopup::~SpellPopup()
-{
-}
-
-void SpellPopup::setItem(const TextCommand *const spell)
-{
- if (spell != nullptr)
- {
- mItemName->setCaption(spell->getName());
- mItemComment->setCaption(spell->getComment());
- }
- else
- {
- mItemName->setCaption("?");
- mItemComment->setCaption("");
- }
-
- mItemName->adjustSize();
- mItemComment->adjustSize();
- int minWidth = mItemName->getWidth();
- if (mItemComment->getWidth() > minWidth)
- minWidth = mItemComment->getWidth();
-
- mItemName->setPosition(0, 0);
- const int fontHeight = mItemName->getHeight();
- mItemComment->setPosition(0, fontHeight);
- if (!mItemComment->getCaption().empty())
- setContentSize(minWidth, 2 * fontHeight);
- else
- setContentSize(minWidth, fontHeight);
-}
-
-void SpellPopup::view(const int x, const int y)
-{
- const int distance = 20;
-
- int posX = std::max(0, x - getWidth() / 2);
- int posY = y + distance;
-
- const Rect &rect = mDimension;
- const int w = rect.width;
- const int h = rect.height;
- if (posX + w > mainGraphics->mWidth)
- {
- if (mainGraphics->mWidth > w)
- posX = mainGraphics->mWidth - w;
- else
- posX = 0;
- }
- if (posY + h > mainGraphics->mHeight)
- {
- if (y > h + distance)
- posY = y - h - distance;
- }
-
- setPosition(posX, posY);
- setVisible(Visible_true);
- requestMoveToTop();
-}
-
-void SpellPopup::mouseMoved(MouseEvent &event)
-{
- Popup::mouseMoved(event);
-
- // When the mouse moved on top of the popup, hide it
- setVisible(Visible_false);
-}
diff --git a/src/gui/popups/spellpopup.h b/src/gui/popups/spellpopup.h
deleted file mode 100644
index 6b9d84238..000000000
--- a/src/gui/popups/spellpopup.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 The Legend of Mazzeroth Development Team
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_POPUPS_SPELLPOPUP_H
-#define GUI_POPUPS_SPELLPOPUP_H
-
-#include "gui/widgets/popup.h"
-
-class Label;
-class TextCommand;
-
-/**
- * A popup that displays information about an item.
- */
-class SpellPopup final : public Popup
-{
- public:
- /**
- * Constructor. Initializes the item popup.
- */
- SpellPopup();
-
- A_DELETE_COPY(SpellPopup)
-
- /**
- * Destructor. Cleans up the item popup on deletion.
- */
- ~SpellPopup();
-
- void postInit() override final;
-
- /**
- * Sets the info to be displayed given a particular item.
- */
- void setItem(const TextCommand *const spell);
-
- /**
- * Sets the location to display the item popup.
- */
- void view(const int x, const int y);
-
- void mouseMoved(MouseEvent &event) override final;
-
- private:
- Label *mItemName A_NONNULLPOINTER;
- Label *mItemComment A_NONNULLPOINTER;
-};
-
-extern SpellPopup *spellPopup;
-
-#endif // GUI_POPUPS_SPELLPOPUP_H
diff --git a/src/gui/popups/statuspopup.cpp b/src/gui/popups/statuspopup.cpp
deleted file mode 100644
index 544a37b56..000000000
--- a/src/gui/popups/statuspopup.cpp
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 The Legend of Mazzeroth Development Team
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/popups/statuspopup.h"
-
-#include "gamemodifiers.h"
-
-#include "gui/widgets/label.h"
-
-#include "input/inputmanager.h"
-
-#include "utils/stringutils.h"
-
-#include "gui/fonts/font.h"
-
-#include "debug.h"
-
-#define addLabel(num) \
- { \
- Label *const label = mLabels[num]; \
- label->setPosition(0, y); \
- label->setForegroundColorAll(getThemeColor(ThemeColorId::POPUP), \
- getThemeColor(ThemeColorId::POPUP_OUTLINE)); \
- add(label); \
- y += fontHeight; \
- }
-
-StatusPopup::StatusPopup() :
- Popup("StatusPopup", "statuspopup.xml"),
- mLabels()
-{
- for (int f = 0; f < STATUSPOPUP_NUM_LABELS; f ++)
- mLabels[f] = new Label(this);
-}
-
-void StatusPopup::postInit()
-{
- Popup::postInit();
- const int fontHeight = getFont()->getHeight();
- int y = 0;
- addLabel(0);
- addLabel(1);
- addLabel(2);
- addLabel(3);
- y += 4;
- addLabel(4);
- addLabel(5);
- addLabel(9);
- addLabel(10);
- y += 4;
- addLabel(6);
- addLabel(7);
- y += 4;
- addLabel(8);
- y += 4;
- addLabel(12);
- addLabel(13);
- addLabel(14);
- addLabel(15);
- y += 4;
- addLabel(11);
-}
-
-StatusPopup::~StatusPopup()
-{
-}
-
-void StatusPopup::update()
-{
- updateLabels();
-
- int maxWidth = mLabels[0]->getWidth();
-
- for (int f = 0; f < STATUSPOPUP_NUM_LABELS; f ++)
- {
- const int width = mLabels[f]->getWidth();
- if (width > maxWidth)
- maxWidth = width;
- }
-
- const int pad2 = 2 * mPadding;
- maxWidth += pad2;
- setWidth(maxWidth);
- setHeight(mLabels[11]->getY()
- + mLabels[11]->getHeight() + pad2);
-}
-
-void StatusPopup::view(const int x, const int y)
-{
- const int distance = 20;
-
- int posX = std::max(0, x - getWidth() / 2);
- int posY = y + distance;
-
- if (posX + getWidth() > mainGraphics->mWidth)
- posX = mainGraphics->mWidth - getWidth();
- if (posY + getHeight() > mainGraphics->mHeight)
- posY = y - getHeight() - distance;
-
- update();
-
- setPosition(posX, posY);
- setVisible(Visible_true);
- requestMoveToTop();
-}
-
-void StatusPopup::setLabelText(const int num,
- const std::string &text,
- const InputActionT key) const
-{
- Label *const label = mLabels[num];
- label->setCaption(strprintf("%s %s", text.c_str(),
- inputManager.getKeyValueString(key).c_str()));
- label->adjustSize();
-}
-
-void StatusPopup::updateLabels() const
-{
- setLabelText(0, GameModifiers::getMoveTypeString(),
- InputAction::INVERT_DIRECTION);
- setLabelText(1, GameModifiers::getCrazyMoveTypeString(),
- InputAction::CHANGE_CRAZY_MOVES_TYPE);
- setLabelText(2, GameModifiers::getMoveToTargetTypeString(),
- InputAction::CHANGE_MOVE_TO_TARGET);
- setLabelText(3, GameModifiers::getFollowModeString(),
- InputAction::CHANGE_FOLLOW_MODE);
- setLabelText(4, GameModifiers::getAttackWeaponTypeString(),
- InputAction::CHANGE_ATTACK_WEAPON_TYPE);
- setLabelText(5, GameModifiers::getAttackTypeString(),
- InputAction::CHANGE_ATTACK_TYPE);
- setLabelText(6, GameModifiers::getQuickDropCounterString(),
- InputAction::SWITCH_QUICK_DROP);
- setLabelText(7, GameModifiers::getPickUpTypeString(),
- InputAction::CHANGE_PICKUP_TYPE);
- setLabelText(8, GameModifiers::getMapDrawTypeString(),
- InputAction::PATHFIND);
- setLabelText(9, GameModifiers::getMagicAttackTypeString(),
- InputAction::SWITCH_MAGIC_ATTACK);
- setLabelText(10, GameModifiers::getPvpAttackTypeString(),
- InputAction::SWITCH_PVP_ATTACK);
- setLabelText(11, GameModifiers::getGameModifiersString(),
- InputAction::DISABLE_GAME_MODIFIERS);
- setLabelText(12, GameModifiers::getImitationModeString(),
- InputAction::CHANGE_IMITATION_MODE);
- setLabelText(13, GameModifiers::getAwayModeString(),
- InputAction::AWAY);
- setLabelText(14, GameModifiers::getCameraModeString(),
- InputAction::CAMERA);
- setLabelText(15, GameModifiers::getTargetingTypeString(),
- InputAction::CHANGE_TARGETING_TYPE);
-}
diff --git a/src/gui/popups/statuspopup.h b/src/gui/popups/statuspopup.h
deleted file mode 100644
index 6ffff5799..000000000
--- a/src/gui/popups/statuspopup.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 The Legend of Mazzeroth Development Team
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_POPUPS_STATUSPOPUP_H
-#define GUI_POPUPS_STATUSPOPUP_H
-
-#include "enums/input/inputaction.h"
-
-#include "gui/widgets/popup.h"
-
-class Label;
-
-const int STATUSPOPUP_NUM_LABELS = 16;
-
-/**
- * A popup that displays information about an item.
- */
-class StatusPopup final : public Popup
-{
- public:
- /**
- * Constructor. Initializes the item popup.
- */
- StatusPopup();
-
- A_DELETE_COPY(StatusPopup)
-
- void postInit() override final;
-
- /**
- * Destructor. Cleans up the item popup on deletion.
- */
- ~StatusPopup();
-
- /**
- * Sets the location to display the item popup.
- */
- void view(const int x, const int y);
-
- void update();
-
- private:
- void updateLabels() const;
-
- void setLabelText(const int num,
- const std::string &text,
- const InputActionT key) const;
-
- Label *mLabels[STATUSPOPUP_NUM_LABELS] A_NONNULLPOINTER;
-};
-
-#endif // GUI_POPUPS_STATUSPOPUP_H
diff --git a/src/gui/popups/textboxpopup.cpp b/src/gui/popups/textboxpopup.cpp
deleted file mode 100644
index 873d6018c..000000000
--- a/src/gui/popups/textboxpopup.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 The Legend of Mazzeroth Development Team
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/popups/textboxpopup.h"
-
-#include "gui/widgets/textbox.h"
-
-#include "gui/fonts/font.h"
-
-#include "render/graphics.h"
-
-#include "debug.h"
-
-TextBoxPopup *textBoxPopup = nullptr;
-
-TextBoxPopup::TextBoxPopup() :
- Popup("TextBoxPopup", "textboxpopup.xml"),
- mTextBox(new TextBox(this))
-{
-}
-
-void TextBoxPopup::postInit()
-{
- Popup::postInit();
- const int fontHeight = getFont()->getHeight();
- setMinHeight(fontHeight);
- mTextBox->setEditable(false);
- mTextBox->setOpaque(Opaque_false);
- add(mTextBox);
- addMouseListener(this);
-}
-
-TextBoxPopup::~TextBoxPopup()
-{
-}
-
-void TextBoxPopup::show(const int x, const int y, const std::string &str)
-{
- mTextBox->setTextWrapped(str, 190);
- setContentSize(mTextBox->getWidth(), mTextBox->getHeight());
- const int distance = 20;
-
- const Rect &rect = mDimension;
- int posX = std::max(0, x - rect.width / 2);
- int posY = y + distance;
-
- if (posX + rect.width > mainGraphics->mWidth)
- posX = mainGraphics->mWidth - rect.width;
- if (posY + rect.height > mainGraphics->mHeight)
- posY = y - rect.height - distance;
-
- setPosition(posX, posY);
- setVisible(Visible_true);
- requestMoveToTop();
-}
-
-void TextBoxPopup::mouseMoved(MouseEvent &event)
-{
- Popup::mouseMoved(event);
-
- // When the mouse moved on top of the popup, hide it
- setVisible(Visible_false);
-}
diff --git a/src/gui/popups/textboxpopup.h b/src/gui/popups/textboxpopup.h
deleted file mode 100644
index 8316905ac..000000000
--- a/src/gui/popups/textboxpopup.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 The Legend of Mazzeroth Development Team
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_POPUPS_TEXTBOXPOPUP_H
-#define GUI_POPUPS_TEXTBOXPOPUP_H
-
-#include "gui/widgets/popup.h"
-
-class TextBox;
-
-/**
- * A popup that displays information about an item.
- */
-class TextBoxPopup final : public Popup
-{
- public:
- /**
- * Constructor. Initializes the item popup.
- */
- TextBoxPopup();
-
- A_DELETE_COPY(TextBoxPopup)
-
- /**
- * Destructor. Cleans up the item popup on deletion.
- */
- ~TextBoxPopup();
-
- void postInit() override final;
-
- /**
- * Sets the text to be displayed.
- */
- void show(const int x, const int y, const std::string &str);
-
- void mouseMoved(MouseEvent &event) override final;
-
- private:
- TextBox *mTextBox A_NONNULLPOINTER;
-};
-
-extern TextBoxPopup *textBoxPopup;
-
-#endif // GUI_POPUPS_TEXTBOXPOPUP_H
diff --git a/src/gui/popups/textpopup.cpp b/src/gui/popups/textpopup.cpp
deleted file mode 100644
index c8b951aea..000000000
--- a/src/gui/popups/textpopup.cpp
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 The Legend of Mazzeroth Development Team
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/popups/textpopup.h"
-
-#include "gui/widgets/label.h"
-
-#include "gui/fonts/font.h"
-
-#include "debug.h"
-
-TextPopup *textPopup = nullptr;
-
-TextPopup::TextPopup() :
- Popup("TextPopup", "textpopup.xml"),
- mText()
-{
-}
-
-void TextPopup::postInit()
-{
- Popup::postInit();
- const int fontHeight = getFont()->getHeight();
- int y = 0;
- for (int f = 0; f < TEXTPOPUPCOUNT; f ++)
- {
- Label *const label = new Label(this);
- mText[f] = label;
- label->setPosition(0, y);
- label->setForegroundColorAll(getThemeColor(ThemeColorId::POPUP),
- getThemeColor(ThemeColorId::POPUP_OUTLINE));
- add(label);
- y += fontHeight;
- }
- addMouseListener(this);
-}
-
-TextPopup::~TextPopup()
-{
-}
-
-void TextPopup::show(const int x, const int y, const std::string &str1,
- const std::string &str2, const std::string &str3)
-{
- mText[0]->setCaption(str1);
- mText[1]->setCaption(str2);
- mText[2]->setCaption(str3);
-
- int minWidth = 0;
- for (int f = 0; f < TEXTPOPUPCOUNT; f ++)
- {
- Label *const label = mText[f];
- label->adjustSize();
- const int width = label->getWidth();
- if (width > minWidth)
- minWidth = width;
- }
-
- const int pad2 = 2 * mPadding;
- minWidth += pad2;
- setWidth(minWidth);
-
- int cnt = 1;
- if (!str2.empty())
- cnt ++;
- if (!str3.empty())
- cnt ++;
-
- setHeight(pad2 + mText[0]->getFont()->getHeight() * cnt);
- const int distance = 20;
-
- const Rect &rect = mDimension;
- int posX = std::max(0, x - rect.width / 2);
- int posY = y + distance;
-
- if (posX + rect.width > mainGraphics->mWidth)
- posX = mainGraphics->mWidth - rect.width;
- if (posY + rect.height > mainGraphics->mHeight)
- posY = y - rect.height - distance;
-
- setPosition(posX, posY);
- setVisible(Visible_true);
- requestMoveToTop();
-}
-
-void TextPopup::mouseMoved(MouseEvent &event)
-{
- Popup::mouseMoved(event);
-
- // When the mouse moved on top of the popup, hide it
- setVisible(Visible_false);
-}
diff --git a/src/gui/popups/textpopup.h b/src/gui/popups/textpopup.h
deleted file mode 100644
index 8a67d5660..000000000
--- a/src/gui/popups/textpopup.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 The Legend of Mazzeroth Development Team
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_POPUPS_TEXTPOPUP_H
-#define GUI_POPUPS_TEXTPOPUP_H
-
-#include "gui/widgets/popup.h"
-
-class Label;
-
-const int TEXTPOPUPCOUNT = 3;
-
-/**
- * A popup that displays information about an item.
- */
-class TextPopup final : public Popup
-{
- public:
- /**
- * Constructor. Initializes the item popup.
- */
- TextPopup();
-
- A_DELETE_COPY(TextPopup)
-
- /**
- * Destructor. Cleans up the item popup on deletion.
- */
- ~TextPopup();
-
- void postInit() override final;
-
- /**
- * Sets the text to be displayed.
- */
- void show(const int x, const int y, const std::string &str1)
- {
- show(x, y, str1, static_cast<const char*>(""),
- static_cast<const char*>(""));
- }
-
- /**
- * Sets the text to be displayed.
- */
- void show(const int x, const int y, const std::string &str1,
- const std::string &str2)
- { show(x, y, str1, str2, static_cast<const char*>("")); }
-
- /**
- * Sets the text to be displayed.
- */
- void show(const int x, const int y, const std::string &str1,
- const std::string &str2, const std::string &str3);
-
- void mouseMoved(MouseEvent &event) override final;
-
- private:
- Label *mText[TEXTPOPUPCOUNT];
-};
-
-extern TextPopup *textPopup;
-
-#endif // GUI_POPUPS_TEXTPOPUP_H
diff --git a/src/gui/rect.h b/src/gui/rect.h
deleted file mode 100644
index 0f72d2b6c..000000000
--- a/src/gui/rect.h
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_RECT_H
-#define GUI_RECT_H
-
-#include "localconsts.h"
-
-/**
- * Represents a rectangle.
- */
-class Rect notfinal
-{
- public:
- /**
- * Constructor. The default rectangle is an empty rectangle
- * at the coordinates (0,0).
- */
- constexpr Rect() :
- x(0),
- y(0),
- width(0),
- height(0)
- {
- }
-
- /**
- * Constructor.
- *
- * @param x_ The x coordinate of the rectangle.
- * @param y_ The y coordinate of the rectangle.
- * @param width_ The width of the rectangle.
- * @param height_ The height of the rectangle.
- */
- constexpr Rect(const int x_,
- const int y_,
- const int width_,
- const int height_) :
- x(x_),
- y(y_),
- width(width_),
- height(height_)
- {
- }
-
- constexpr Rect(const Rect &r) :
- x(r.x),
- y(r.y),
- width(r.width),
- height(r.height)
- {
- }
-
- A_DEFAULT_COPY(Rect)
-
- Rect &operator=(const Rect &r)
- {
- x = r.x;
- y = r.y;
- width = r.width;
- height = r.height;
- return *this;
- }
-
- virtual ~Rect()
- { }
-
- /**
- * Sets the dimension of a rectangle.
- *
- * @param x0 The x coordinate of the rectangle.
- * @param y0 The y coordinate of the rectangle.
- * @param width0 The width of the rectangle.
- * @param height0 The height of the rectangle.
- */
- void setAll(const int x0,
- const int y0,
- const int width0,
- const int height0)
- {
- x = x0;
- y = y0;
- width = width0;
- height = height0;
- }
-
- /**
- * Checks if another rectangle intersects with the rectangle.
- *
- * @param rectangle Another rectangle to check for intersection.
- * @return True if the rectangles intersect, false otherwise.
- */
- bool isIntersecting(const Rect& rectangle) const A_WARN_UNUSED
- {
- int x_ = x;
- int y_ = y;
- int width_ = width;
- int height_ = height;
-
- x_ -= rectangle.x;
- y_ -= rectangle.y;
-
- if (x_ < 0)
- {
- width_ += x_;
- }
- else if (x_ + width_ > rectangle.width)
- {
- width_ = rectangle.width - x_;
- }
-
- if (y_ < 0)
- {
- height_ += y_;
- }
- else if (y_ + height_ > rectangle.height)
- {
- height_ = rectangle.height - y_;
- }
-
- if (width_ <= 0 || height_ <= 0)
- {
- return false;
- }
-
- return true;
- }
-
- /**
- * Checks if a point is inside the rectangle
- *
- * @param x_ The x coordinate of the point.
- * @param y_ The y coordinate of the point.
- * @return True if the point is inside the rectangle.
- */
- bool isPointInRect(const int x_,
- const int y_) const A_WARN_UNUSED
- {
- return x_ >= x
- && y_ >= y
- && x_ < x + width
- && y_ < y + height;
- }
-
- /**
- * Holds the x coordinate of the rectangle.
- */
- int x;
-
- /**
- * Holds the x coordinate of the rectangle.
- */
- int y;
-
- /**
- * Holds the width of the rectangle.
- */
- int width;
-
- /**
- * Holds the height of the rectangle.
- */
- int height;
-};
-
-#endif // GUI_RECT_H
diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp
deleted file mode 100644
index 3fd122002..000000000
--- a/src/gui/sdlinput.cpp
+++ /dev/null
@@ -1,405 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004, 2005, 2006, 2007 Olof Naessén and Per Larsson
- * Copyright (C) 2007-2010 The Mana World Development Team
- *
- * Js_./
- * Per Larsson a.k.a finalman _RqZ{a<^_aa
- * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a//
- * _Qhm`] _f "'c 1!5m
- * Visit: http://guichan.darkbits.org )Qk<P ` _: :+' .' "{[
- * .)j(] .d_/ '-( P . S
- * License: (BSD) <Td/Z <fP"5(\"??"\a. .L
- * Redistribution and use in source and _dV>ws?a-?' ._/L #'
- * binary forms, with or without )4d[#7r, . ' )d`)[
- * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam'
- * that the following conditions are met: j<<WP+k/);. _W=j f
- * 1. Redistributions of source code must .$%w\/]Q . ."' . mj$
- * retain the above copyright notice, ]E.pYY(Q]>. a J@\
- * this list of conditions and the j(]1u<sE"L,. . ./^ ]{a
- * following disclaimer. 4'_uomm\. )L);-4 (3=
- * 2. Redistributions in binary form must )_]X{Z('a_"a7'<a"a, ]"[
- * reproduce the above copyright notice, #}<]m7`Za??4,P-"'7. ).m
- * this list of conditions and the ]d2e)Q(<Q( ?94 b- LQ/
- * following disclaimer in the <B!</]C)d_, '(<' .f. =C+m
- * documentation and/or other materials .Z!=J ]e []('-4f _ ) -.)m]'
- * provided with the distribution. .w[5]' _[ /.)_-"+? _/ <W"
- * 3. Neither the name of Guichan nor the :$we` _! + _/ . j?
- * names of its contributors may be used =3)= _f (_yQmWW$#( "
- * to endorse or promote products derived - W, sQQQQmZQ#Wwa]..
- * from this software without specific (js, \[QQW$QWW#?!V"".
- * prior written permission. ]y:.<\.. .
- * -]n w/ ' [.
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT )/ )/ !
- * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY < (; sac , '
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, ]^ .- %
- * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF c < r
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR aga< <La
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 5% )P'-3L
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR _bQf` y`..)a
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, ,J?4P'.P"_(\?d'.,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES _Pa,)!f/<[]/ ?"
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT _2-..:. .r+_,.. .
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ?a.<%"' " -'.a_ _,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ^
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "sdlshared.h"
-
-#include "input/inputmanager.h"
-
-#include "gui/gui.h"
-#include "gui/sdlinput.h"
-
-#include "render/graphics.h"
-
-PRAGMA48(GCC diagnostic push)
-PRAGMA48(GCC diagnostic ignored "-Wshadow")
-#include <SDL_timer.h>
-PRAGMA48(GCC diagnostic pop)
-
-#include "debug.h"
-
-extern volatile time_t cur_time;
-
-SDLInput *guiInput = nullptr;
-
-SDLInput::SDLInput() :
- mKeyInputQueue(),
- mMouseInputQueue(),
- mMouseMoveTime(0),
- mMouseDown(false),
- mMouseInWindow(true)
-{
-}
-
-KeyInput SDLInput::dequeueKeyInput()
-{
- if (mKeyInputQueue.empty())
- return KeyInput();
-
- KeyInput keyInput = mKeyInputQueue.front();
- mKeyInputQueue.pop();
-
- return keyInput;
-}
-
-MouseInput SDLInput::dequeueMouseInput()
-{
- MouseInput mouseInput;
-
- if (mMouseInputQueue.empty())
- return MouseInput();
-
- mouseInput = mMouseInputQueue.front();
- mMouseInputQueue.pop();
-
- return mouseInput;
-}
-
-void SDLInput::pushInput(const SDL_Event &event)
-{
- BLOCK_START("SDLInput::pushInput")
- KeyInput keyInput;
- MouseInput mouseInput;
-
- switch (event.type)
- {
- case SDL_KEYDOWN:
- {
- keyInput.setType(KeyEventType::PRESSED);
- convertKeyEventToKey(event, keyInput);
- mKeyInputQueue.push(keyInput);
- break;
- }
-
- case SDL_KEYUP:
- {
- keyInput.setType(KeyEventType::RELEASED);
- convertKeyEventToKey(event, keyInput);
- mKeyInputQueue.push(keyInput);
- break;
- }
-
-#ifdef USE_SDL2
- case SDL_TEXTINPUT:
- keyInput.setType(KeyEventType::PRESSED);
- keyInput.setKey(Key(KeyValue::TEXTINPUT));
- keyInput.setText(event.text.text);
- mKeyInputQueue.push(keyInput);
- break;
-
- case SDL_MOUSEWHEEL:
- {
- const int y = event.wheel.y;
- if (y)
- {
- mouseInput.setX(gui->getLastMouseX());
- mouseInput.setY(gui->getLastMouseY());
-#ifdef ANDROID
- mouseInput.setReal(0, 0);
-#endif // ANDROID
-
- mouseInput.setButton(MouseButton::WHEEL);
- if (y > 0)
- mouseInput.setType(MouseEventType::WHEEL_MOVED_UP);
- else
- mouseInput.setType(MouseEventType::WHEEL_MOVED_DOWN);
- mouseInput.setTimeStamp(SDL_GetTicks());
- mMouseInputQueue.push(mouseInput);
- }
-
- break;
- }
-#endif // USE_SDL2
-
-#ifdef ANDROID
-#ifndef USE_SDL2
- case SDL_ACCELEROMETER:
- break;
-#endif // USE_SDL2
-#endif // ANDROID
-
- case SDL_MOUSEBUTTONDOWN:
- {
- mMouseDown = true;
- const int scale = mainGraphics->getScale();
- const int x = event.button.x / scale;
- const int y = event.button.y / scale;
- mouseInput.setX(x);
- mouseInput.setY(y);
-#ifdef ANDROID
-#ifdef USE_SDL2
- mouseInput.setReal(x, y);
-#else // USE_SDL2
-
- mouseInput.setReal(event.button.realx / scale,
- event.button.realy / scale);
-#endif // USE_SDL2
-#endif // ANDROID
-
- mouseInput.setButton(convertMouseButton(event.button.button));
-
-#ifndef USE_SDL2
- if (event.button.button == SDL_BUTTON_WHEELDOWN)
- mouseInput.setType(MouseEventType::WHEEL_MOVED_DOWN);
- else if (event.button.button == SDL_BUTTON_WHEELUP)
- mouseInput.setType(MouseEventType::WHEEL_MOVED_UP);
- else
-#endif // USE_SDL2
- mouseInput.setType(MouseEventType::PRESSED);
- mouseInput.setTimeStamp(SDL_GetTicks());
- mMouseInputQueue.push(mouseInput);
- break;
- }
- case SDL_MOUSEBUTTONUP:
- {
- mMouseDown = false;
- const int scale = mainGraphics->getScale();
- const int x = event.button.x / scale;
- const int y = event.button.y / scale;
- mouseInput.setX(x);
- mouseInput.setY(y);
-#ifdef ANDROID
-#ifdef USE_SDL2
- mouseInput.setReal(x, y);
-#else // USE_SDL2
-
- mouseInput.setReal(event.button.realx / scale,
- event.button.realy / scale);
-#endif // USE_SDL2
-#endif // ANDROID
-
- mouseInput.setButton(convertMouseButton(event.button.button));
- mouseInput.setType(MouseEventType::RELEASED);
- mouseInput.setTimeStamp(SDL_GetTicks());
- mMouseInputQueue.push(mouseInput);
- break;
- }
- case SDL_MOUSEMOTION:
- {
- const int scale = mainGraphics->getScale();
- const int x = event.motion.x / scale;
- const int y = event.motion.y / scale;
- mouseInput.setX(x);
- mouseInput.setY(y);
-#ifdef ANDROID
-#ifdef USE_SDL2
- mouseInput.setReal(x, y);
-#else // USE_SDL2
-
- mouseInput.setReal(event.motion.realx / scale,
- event.motion.realy / scale);
-#endif // USE_SDL2
-#endif // ANDROID
-
- mouseInput.setButton(MouseButton::EMPTY);
- mouseInput.setType(MouseEventType::MOVED);
- mouseInput.setTimeStamp(SDL_GetTicks());
- mMouseInputQueue.push(mouseInput);
- mMouseMoveTime = cur_time;
- break;
- }
-#ifndef USE_SDL2
- case SDL_ACTIVEEVENT:
- /*
- * This occurs when the mouse leaves the window and the Gui-chan
- * application loses its mousefocus.
- */
- if ((event.active.state & SDL_APPMOUSEFOCUS) != 0 &&
- event.active.gain == 0u)
- {
- mMouseInWindow = false;
-
- if (!mMouseDown)
- {
- mouseInput.setX(-1);
- mouseInput.setY(-1);
- mouseInput.setButton(MouseButton::EMPTY);
- mouseInput.setType(MouseEventType::MOVED);
- mMouseInputQueue.push(mouseInput);
- mMouseMoveTime = cur_time;
- }
- }
-
- if ((event.active.state & SDL_APPMOUSEFOCUS) != 0 &&
- event.active.gain != 0u)
- {
- mMouseInWindow = true;
- }
- break;
-#endif // USE_SDL2
-
- default:
- break;
- } // end switch
- BLOCK_END("SDLInput::pushInput")
-}
-
-void SDLInput::convertKeyEventToKey(const SDL_Event &event, KeyInput &keyInput)
-{
- keyInput.setKey(Key(convertKeyCharacter(event)));
- const InputActionT actionId = inputManager.getActionByKey(event);
- if (actionId > InputAction::NO_VALUE)
- keyInput.setActionId(actionId);
-}
-
-MouseButtonT SDLInput::convertMouseButton(const int button)
-{
- switch (button)
- {
- case SDL_BUTTON_LEFT:
- return MouseButton::LEFT;
- case SDL_BUTTON_RIGHT:
- return MouseButton::RIGHT;
- case SDL_BUTTON_MIDDLE:
- return MouseButton::MIDDLE;
-#ifndef USE_SDL2
- case SDL_BUTTON_WHEELUP:
- case SDL_BUTTON_WHEELDOWN:
- return MouseButton::EMPTY;
-#endif // USE_SDL2
-
- default:
- // We have an unknown mouse type which is ignored.
- logger->log("unknown button type: %d", button);
- return MouseButton::EMPTY;
- }
-}
-
-void SDLInput::simulateMouseClick(const int x, const int y,
- const MouseButtonT button)
-{
- MouseInput mouseInput;
- mouseInput.setX(x);
- mouseInput.setY(y);
- mouseInput.setReal(x, y);
- mouseInput.setButton(MouseButton::EMPTY);
- mouseInput.setType(MouseEventType::MOVED);
- mouseInput.setTimeStamp(SDL_GetTicks());
- mMouseInputQueue.push(mouseInput);
- mouseInput.setButton(button);
- mouseInput.setType(MouseEventType::PRESSED);
- mouseInput.setTimeStamp(SDL_GetTicks());
- mMouseInputQueue.push(mouseInput);
- mouseInput.setType(MouseEventType::RELEASED);
- mouseInput.setTimeStamp(SDL_GetTicks());
- mMouseInputQueue.push(mouseInput);
-}
-
-void SDLInput::simulateMouseMove()
-{
- if (gui == nullptr)
- return;
-
- if (mMouseMoveTime == cur_time)
- return;
-
- mMouseMoveTime = cur_time;
- int x, y;
- Gui::getMouseState(x, y);
-
- MouseInput mouseInput;
- mouseInput.setX(x);
- mouseInput.setY(y);
- mouseInput.setReal(x, y);
- mouseInput.setButton(MouseButton::EMPTY);
- mouseInput.setType(MouseEventType::MOVED);
- mouseInput.setTimeStamp(SDL_GetTicks());
- mMouseInputQueue.push(mouseInput);
-}
-
-void SDLInput::simulateKey(const int guiKey,
- const InputActionT actionId)
-{
- KeyInput keyInput;
- keyInput.setType(KeyEventType::PRESSED);
-#ifdef USE_SDL2
- char str[2];
- str[0] = CAST_S8(guiKey);
- str[1] = 0;
-
- keyInput.setKey(Key(KeyValue::TEXTINPUT));
- keyInput.setText(str);
- if (guiKey >= 32)
- mKeyInputQueue.push(keyInput);
-#endif // USE_SDL2
-
- keyInput.setKey(Key(guiKey));
- if (actionId > InputAction::NO_VALUE)
- keyInput.setActionId(actionId);
- mKeyInputQueue.push(keyInput);
- keyInput.setType(KeyEventType::RELEASED);
- mKeyInputQueue.push(keyInput);
-}
diff --git a/src/gui/sdlinput.h b/src/gui/sdlinput.h
deleted file mode 100644
index 5910911ef..000000000
--- a/src/gui/sdlinput.h
+++ /dev/null
@@ -1,391 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004, 2005, 2006, 2007 Olof Naessén and Per Larsson
- * Copyright (C) 2007-2010 The Mana World Development Team
- *
- * Js_./
- * Per Larsson a.k.a finalman _RqZ{a<^_aa
- * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a//
- * _Qhm`] _f "'c 1!5m
- * Visit: http://guichan.darkbits.org )Qk<P ` _: :+' .' "{[
- * .)j(] .d_/ '-( P . S
- * License: (BSD) <Td/Z <fP"5(\"??"\a. .L
- * Redistribution and use in source and _dV>ws?a-?' ._/L #'
- * binary forms, with or without )4d[#7r, . ' )d`)[
- * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam'
- * that the following conditions are met: j<<WP+k/);. _W=j f
- * 1. Redistributions of source code must .$%w\/]Q . ."' . mj$
- * retain the above copyright notice, ]E.pYY(Q]>. a J@\
- * this list of conditions and the j(]1u<sE"L,. . ./^ ]{a
- * following disclaimer. 4'_uomm\. )L);-4 (3=
- * 2. Redistributions in binary form must )_]X{Z('a_"a7'<a"a, ]"[
- * reproduce the above copyright notice, #}<]m7`Za??4,P-"'7. ).m
- * this list of conditions and the ]d2e)Q(<Q( ?94 b- LQ/
- * following disclaimer in the <B!</]C)d_, '(<' .f. =C+m
- * documentation and/or other materials .Z!=J ]e []('-4f _ ) -.)m]'
- * provided with the distribution. .w[5]' _[ /.)_-"+? _/ <W"
- * 3. Neither the name of Guichan nor the :$we` _! + _/ . j?
- * names of its contributors may be used =3)= _f (_yQmWW$#( "
- * to endorse or promote products derived - W, sQQQQmZQ#Wwa]..
- * from this software without specific (js, \[QQW$QWW#?!V"".
- * prior written permission. ]y:.<\.. .
- * -]n w/ ' [.
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT )/ )/ !
- * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY < (; sac , '
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, ]^ .- %
- * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF c < r
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR aga< <La
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 5% )P'-3L
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR _bQf` y`..)a
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, ,J?4P'.P"_(\?d'.,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES _Pa,)!f/<[]/ ?"
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT _2-..:. .r+_,.. .
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ?a.<%"' " -'.a_ _,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ^
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_SDLINPUT_H
-#define GUI_SDLINPUT_H
-
-#include "enums/input/keyvalue.h"
-
-#include "input/keyinput.h"
-
-#include "utils/cast.h"
-
-PRAGMA48(GCC diagnostic push)
-PRAGMA48(GCC diagnostic ignored "-Wshadow")
-#include <SDL_events.h>
-PRAGMA48(GCC diagnostic pop)
-
-#ifdef USE_SDL2
-#include "sdlshared.h"
-#endif // USE_SDL2
-
-#include "input/mouseinput.h"
-
-#include <queue>
-
-/**
- * SDL implementation of SDLInput.
- */
-class SDLInput final
-{
- public:
- /**
- * Constructor.
- */
- SDLInput();
-
- A_DELETE_COPY(SDLInput)
-
- /**
- * Pushes an SDL event. It should be called at least once per frame to
- * update input with user input.
- *
- * @param event an event from SDL.
- */
- void pushInput(const SDL_Event &event);
-
- KeyInput dequeueKeyInput() A_WARN_UNUSED;
-
- bool isKeyQueueEmpty() const noexcept2 A_WARN_UNUSED
- { return mKeyInputQueue.empty(); }
-
- bool isMouseQueueEmpty() const noexcept2 A_WARN_UNUSED
- { return mMouseInputQueue.empty(); }
-
- MouseInput dequeueMouseInput() A_WARN_UNUSED;
-
- void simulateMouseClick(const int x, const int y,
- const MouseButtonT button);
-
- void simulateMouseMove();
-
- void simulateKey(const int guiKey,
- const InputActionT actionId);
-
- protected:
- /**
- * Converts a mouse button from SDL to a Guichan mouse button
- * representation.
- *
- * @param button an SDL mouse button.
- * @return a Guichan mouse button.
- */
- static MouseButtonT convertMouseButton(const int button) A_WARN_UNUSED;
-
- /**
- * Converts an SDL event key to a key value.
- *
- * @param event an SDL event with a key to convert.
- * @return a key value.
- * @see Key
- */
- constexpr2 static int convertKeyCharacter(const SDL_Event &event)
- A_WARN_UNUSED
- {
- const SDL_keysym keysym = event.key.keysym;
-#ifdef USE_SDL2
- int value = keysym.scancode;
-#else // USE_SDL2
-
- int value = keysym.unicode;
-#endif // USE_SDL2
-
- PRAGMA45(GCC diagnostic push)
- PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
- switch (keysym.sym)
- {
- case SDLK_TAB:
- value = KeyValue::TAB;
- break;
- case SDLK_LALT:
- value = KeyValue::LEFT_ALT;
- break;
- case SDLK_RALT:
- value = KeyValue::RIGHT_ALT;
- break;
- case SDLK_LSHIFT:
- value = KeyValue::LEFT_SHIFT;
- break;
- case SDLK_RSHIFT:
- value = KeyValue::RIGHT_SHIFT;
- break;
- case SDLK_LCTRL:
- value = KeyValue::LEFT_CONTROL;
- break;
- case SDLK_RCTRL:
- value = KeyValue::RIGHT_CONTROL;
- break;
- case SDLK_BACKSPACE:
- value = KeyValue::BACKSPACE;
- break;
- case SDLK_PAUSE:
- value = KeyValue::PAUSE;
- break;
- case SDLK_SPACE:
- // Special characters like ~ (tilde) ends up
- // with the keysym.sym SDLK_SPACE which
- // without this check would be lost. The check
- // is only valid on key down events in SDL.
-#ifndef USE_SDL2
- if (event.type == SDL_KEYUP ||
- keysym.unicode == ' ')
-#endif // USE_SDL2
- {
- value = KeyValue::SPACE;
- }
- break;
- case SDLK_ESCAPE:
-#ifdef USE_SDL2
- case SDLK_AC_BACK:
-#endif // USE_SDL2
- value = KeyValue::ESCAPE;
- break;
- case SDLK_DELETE:
- value = KeyValue::DELETE_;
- break;
- case SDLK_INSERT:
- value = KeyValue::INSERT;
- break;
- case SDLK_HOME:
- value = KeyValue::HOME;
- break;
- case SDLK_END:
- value = KeyValue::END;
- break;
- case SDLK_PAGEUP:
- value = KeyValue::PAGE_UP;
- break;
- case SDLK_PRINT:
- value = KeyValue::PRINT_SCREEN;
- break;
- case SDLK_PAGEDOWN:
- value = KeyValue::PAGE_DOWN;
- break;
- case SDLK_F1:
- value = KeyValue::F1;
- break;
- case SDLK_F2:
- value = KeyValue::F2;
- break;
- case SDLK_F3:
- value = KeyValue::F3;
- break;
- case SDLK_F4:
- value = KeyValue::F4;
- break;
- case SDLK_F5:
- value = KeyValue::F5;
- break;
- case SDLK_F6:
- value = KeyValue::F6;
- break;
- case SDLK_F7:
- value = KeyValue::F7;
- break;
- case SDLK_F8:
- value = KeyValue::F8;
- break;
- case SDLK_F9:
- value = KeyValue::F9;
- break;
- case SDLK_F10:
- value = KeyValue::F10;
- break;
- case SDLK_F11:
- value = KeyValue::F11;
- break;
- case SDLK_F12:
- value = KeyValue::F12;
- break;
- case SDLK_F13:
- value = KeyValue::F13;
- break;
- case SDLK_F14:
- value = KeyValue::F14;
- break;
- case SDLK_F15:
- value = KeyValue::F15;
- break;
- case SDLK_NUMLOCK:
- value = KeyValue::NUM_LOCK;
- break;
- case SDLK_CAPSLOCK:
- value = KeyValue::CAPS_LOCK;
- break;
- case SDLK_SCROLLOCK:
- value = KeyValue::SCROLL_LOCK;
- break;
- case SDLK_RMETA:
- value = KeyValue::RIGHT_META;
- break;
- case SDLK_LMETA:
- value = KeyValue::LEFT_META;
- break;
-#ifndef USE_SDL2
- case SDLK_LSUPER:
- value = KeyValue::LEFT_SUPER;
- break;
- case SDLK_RSUPER:
- value = KeyValue::RIGHT_SUPER;
- break;
-#endif // USE_SDL2
-
- case SDLK_MODE:
- value = KeyValue::ALT_GR;
- break;
- case SDLK_UP:
- value = KeyValue::UP;
- break;
- case SDLK_DOWN:
- value = KeyValue::DOWN;
- break;
- case SDLK_LEFT:
- value = KeyValue::LEFT;
- break;
- case SDLK_RIGHT:
- value = KeyValue::RIGHT;
- break;
- case SDLK_RETURN:
- value = KeyValue::ENTER;
- break;
- case SDLK_KP_ENTER:
- value = KeyValue::ENTER;
- break;
-
- default:
- break;
- }
- PRAGMA45(GCC diagnostic pop)
-
- if ((CAST_U32(keysym.mod) & KMOD_NUM) == 0u)
- {
- PRAGMA45(GCC diagnostic push)
- PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
- switch (keysym.sym)
- {
- case SDLK_KP0:
- value = KeyValue::INSERT;
- break;
- case SDLK_KP1:
- value = KeyValue::END;
- break;
- case SDLK_KP2:
- value = KeyValue::DOWN;
- break;
- case SDLK_KP3:
- value = KeyValue::PAGE_DOWN;
- break;
- case SDLK_KP4:
- value = KeyValue::LEFT;
- break;
- case SDLK_KP5:
- value = 0;
- break;
- case SDLK_KP6:
- value = KeyValue::RIGHT;
- break;
- case SDLK_KP7:
- value = KeyValue::HOME;
- break;
- case SDLK_KP8:
- value = KeyValue::UP;
- break;
- case SDLK_KP9:
- value = KeyValue::PAGE_UP;
- break;
- default:
- break;
- }
- PRAGMA45(GCC diagnostic pop)
- }
- return value;
- }
-
- static void convertKeyEventToKey(const SDL_Event &event,
- KeyInput &keyInput);
-
- std::queue<KeyInput> mKeyInputQueue;
- std::queue<MouseInput> mMouseInputQueue;
- time_t mMouseMoveTime;
-
- bool mMouseDown;
- bool mMouseInWindow;
-};
-
-extern SDLInput *guiInput; /**< GUI input */
-
-#endif // GUI_SDLINPUT_H
diff --git a/src/gui/setupactiondata.h b/src/gui/setupactiondata.h
deleted file mode 100644
index 4dd591e6b..000000000
--- a/src/gui/setupactiondata.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007 Joshua Langley <joshlangley@optusnet.com.au>
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_SETUPACTIONDATA_H
-#define GUI_SETUPACTIONDATA_H
-
-#include "enums/input/inputaction.h"
-
-#include <string>
-
-#include "localconsts.h"
-
-struct SetupActionData final
-{
-#ifdef ADVGCC
- SetupActionData(const std::string &name0,
- const InputActionT actionId0,
- const std::string &text0) :
- name(name0),
- actionId(actionId0),
- text(text0)
- { }
-
- A_DELETE_COPY(SetupActionData)
-#endif // ADVGCC
-
- std::string name;
- const InputActionT actionId;
- std::string text;
-};
-
-#endif // GUI_SETUPACTIONDATA_H
diff --git a/src/gui/setupinputpages.cpp b/src/gui/setupinputpages.cpp
deleted file mode 100644
index f9bb4764c..000000000
--- a/src/gui/setupinputpages.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007 Joshua Langley <joshlangley@optusnet.com.au>
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "const/gui/pages.h"
-
-#include "gui/setupinputpages.h"
-
-#include "utils/gettext.h"
-
-#include "input/pages/basic.h"
-#include "input/pages/chat.h"
-#include "input/pages/craft.h"
-#include "input/pages/emotes.h"
-#include "input/pages/gui.h"
-#include "input/pages/move.h"
-#include "input/pages/other.h"
-#include "input/pages/outfits.h"
-#include "input/pages/shortcuts.h"
-#include "input/pages/windows.h"
-
-#include "debug.h"
-
-const char *const pages[SETUP_PAGES + 1] =
-{
- // TRANSLATORS: input tab sub tab name
- N_("Basic"),
- // TRANSLATORS: input tab sub tab name
- N_("Move"),
- // TRANSLATORS: input tab sub tab name
- N_("Shortcuts"),
- // TRANSLATORS: input tab sub tab name
- N_("Windows"),
- // TRANSLATORS: input tab sub tab name
- N_("Craft"),
- // TRANSLATORS: input tab sub tab name
- N_("Emotes"),
- // TRANSLATORS: input tab sub tab name
- N_("Outfits"),
- // TRANSLATORS: input tab sub tab name
- N_("Chat"),
- // TRANSLATORS: input tab sub tab name
- N_("Other"),
- // TRANSLATORS: input tab sub tab name
- N_("Gui"),
- nullptr
-};
-
-SetupActionData *const setupActionData[SETUP_PAGES] =
-{
- setupActionDataBasic,
- setupActionDataMove,
- setupActionDataShortcuts,
- setupActionDataWindows,
- setupActionDataCraft,
- setupActionDataEmotes,
- setupActionDataOutfits,
- setupActionDataChat,
- setupActionDataOther,
- setupActionDataGui
-};
diff --git a/src/gui/setupinputpages.h b/src/gui/setupinputpages.h
deleted file mode 100644
index 953837808..000000000
--- a/src/gui/setupinputpages.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007 Joshua Langley <joshlangley@optusnet.com.au>
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_SETUPINPUTPAGES_H
-#define GUI_SETUPINPUTPAGES_H
-
-struct SetupActionData;
-
-extern const char *const pages[];
-extern SetupActionData *const setupActionData[];
-
-#endif // GUI_SETUPINPUTPAGES_H
diff --git a/src/gui/shortcut/dropshortcut.cpp b/src/gui/shortcut/dropshortcut.cpp
deleted file mode 100644
index f9876ebee..000000000
--- a/src/gui/shortcut/dropshortcut.cpp
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/shortcut/dropshortcut.h"
-
-#include "settings.h"
-
-#include "being/localplayer.h"
-#include "being/playerinfo.h"
-
-#include "resources/inventory/inventory.h"
-
-#include "resources/item/item.h"
-
-#include "net/packetlimiter.h"
-
-#include "debug.h"
-
-static const int DROP_SHORTCUT_ITEMS = 16;
-
-DropShortcut *dropShortcut = nullptr;
-
-DropShortcut::DropShortcut() :
- ShortcutBase("drop", "dropColor", DROP_SHORTCUT_ITEMS),
- mLastDropIndex(0)
-{
- clear(false);
- load();
-}
-
-DropShortcut::~DropShortcut()
-{
-}
-
-void DropShortcut::dropFirst() const
-{
- if (localPlayer == nullptr)
- return;
-
- if (!PacketLimiter::limitPackets(PacketType::PACKET_DROP))
- return;
-
- const int itemId = getItem(0);
- const ItemColor itemColor = getItemColor(0);
- if (PlayerInfo::isItemProtected(itemId))
- return;
-
- if (itemId > 0)
- {
- const Item *const item = PlayerInfo::getInventory()
- ->findItem(itemId, itemColor);
- if ((item != nullptr) && (item->getQuantity() != 0))
- {
- const int cnt = settings.quickDropCounter;
- if (localPlayer->isServerBuggy())
- {
- PlayerInfo::dropItem(item, cnt, Sfx_true);
- }
- else
- {
- for (int i = 0; i < cnt; i++)
- PlayerInfo::dropItem(item, 1, Sfx_false);
- }
- }
- }
-}
-
-void DropShortcut::dropItems(const int cnt)
-{
- if (localPlayer == nullptr)
- return;
-
- if (localPlayer->isServerBuggy())
- {
- dropItem(settings.quickDropCounter);
- return;
- }
-
- int n = 0;
- const int sz = settings.quickDropCounter;
- for (int f = 0; f < 9; f++)
- {
- for (int i = 0; i < sz; i++)
- {
- if (!PacketLimiter::limitPackets(PacketType::PACKET_DROP))
- return;
- if (dropItem())
- n++;
- }
- if (n >= cnt)
- break;
- }
-}
-
-bool DropShortcut::dropItem(const int cnt)
-{
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- return false;
-
- int itemId = 0;
- ItemColor itemColor = ItemColor_one;
- while (mLastDropIndex < DROP_SHORTCUT_ITEMS &&
- itemId < 1)
- {
- if (!PlayerInfo::isItemProtected(itemId))
- {
- itemId = getItem(mLastDropIndex);
- itemColor = getItemColor(mLastDropIndex);
- }
- mLastDropIndex ++;
- }
-
- if (itemId > 0)
- {
- const Item *const item = inv->findItem(itemId, itemColor);
- if ((item != nullptr) &&
- item->getQuantity() > 0)
- {
- PlayerInfo::dropItem(item, cnt, Sfx_true);
- return true;
- }
- }
- if (mLastDropIndex >= DROP_SHORTCUT_ITEMS)
- mLastDropIndex = 0;
-
- if (itemId < 1)
- {
- while (mLastDropIndex < DROP_SHORTCUT_ITEMS &&
- itemId < 1)
- {
- if (!PlayerInfo::isItemProtected(itemId))
- {
- itemId = getItem(mLastDropIndex);
- itemColor = getItemColor(mLastDropIndex);
- }
- mLastDropIndex++;
- }
- if (itemId > 0)
- {
- const Item *const item = inv->findItem(itemId, itemColor);
- if ((item != nullptr) && item->getQuantity() > 0)
- {
- PlayerInfo::dropItem(item, cnt, Sfx_true);
- return true;
- }
- }
- if (mLastDropIndex >= DROP_SHORTCUT_ITEMS)
- mLastDropIndex = 0;
- }
- return false;
-}
diff --git a/src/gui/shortcut/dropshortcut.h b/src/gui/shortcut/dropshortcut.h
deleted file mode 100644
index b3993b96e..000000000
--- a/src/gui/shortcut/dropshortcut.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_SHORTCUT_DROPSHORTCUT_H
-#define GUI_SHORTCUT_DROPSHORTCUT_H
-
-#include "gui/shortcut/shortcutbase.h"
-
-#include "localconsts.h"
-
-/**
- * The class which keeps track of the item shortcuts.
- */
-class DropShortcut final : public ShortcutBase
-{
- public:
- /**
- * Constructor.
- */
- DropShortcut();
-
- A_DELETE_COPY(DropShortcut)
-
- /**
- * Destructor.
- */
- ~DropShortcut();
-
- /**
- * Drop first item.
- */
- void dropFirst() const;
-
- /**
- * Drop all items in cicle.
- */
- void dropItems(const int cnt = 1);
-
- private:
- /**
- * Drop item in cicle.
- */
- bool dropItem(const int cnt = 1);
-
- int mLastDropIndex;
-};
-
-extern DropShortcut *dropShortcut;
-
-#endif // GUI_SHORTCUT_DROPSHORTCUT_H
diff --git a/src/gui/shortcut/emoteshortcut.cpp b/src/gui/shortcut/emoteshortcut.cpp
deleted file mode 100644
index 8131a11a2..000000000
--- a/src/gui/shortcut/emoteshortcut.cpp
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 Aethyra Development Team
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/shortcut/emoteshortcut.h"
-
-#include "configuration.h"
-#include "settings.h"
-
-#include "being/localplayer.h"
-
-#include "net/homunculushandler.h"
-#include "net/mercenaryhandler.h"
-#include "net/pethandler.h"
-
-#include "resources/db/emotedb.h"
-
-#include "debug.h"
-
-EmoteShortcut *emoteShortcut = nullptr;
-
-EmoteShortcut::EmoteShortcut() :
- mEmoteSelected(0)
-{
- for (int i = 0; i < SHORTCUT_EMOTES; i++)
- mEmotes[i] = 0;
-}
-
-EmoteShortcut::~EmoteShortcut()
-{
- save();
-}
-
-void EmoteShortcut::load()
-{
- for (unsigned char i = 0, j = 0,
- fsz = CAST_U8(EmoteDB::getLast());
- i <= fsz && j < SHORTCUT_EMOTES;
- i++)
- {
- const EmoteSprite *const sprite = EmoteDB::getSprite(i, true);
- if (sprite != nullptr)
- {
- mEmotes[j] = CAST_U8(i + 1);
- j ++;
- }
- }
-}
-
-void EmoteShortcut::save() const
-{
- for (int i = 0; i < SHORTCUT_EMOTES; i++)
- {
- const unsigned char emoteId = mEmotes[i] != 0u ? mEmotes[i]
- : CAST_U8(0);
- serverConfig.setValue("emoteshortcut" + toString(i),
- CAST_U32(emoteId));
- }
-}
-
-void EmoteShortcut::useEmotePlayer(const size_t index) const
-{
- if (index <= CAST_SIZE(SHORTCUT_EMOTES))
- {
- if (mEmotes[index - 1] > 0)
- LocalPlayer::emote(mEmotes[index - 1]);
- }
-}
-
-void EmoteShortcut::useEmote(const size_t index) const
-{
- if (localPlayer == nullptr)
- return;
-
- if (index <= CAST_SIZE(SHORTCUT_EMOTES))
- {
- if (mEmotes[index - 1] > 0)
- {
- const uint8_t emote = mEmotes[index - 1];
- switch (settings.emoteType)
- {
- case EmoteType::Player:
- default:
- LocalPlayer::emote(emote);
- break;
- case EmoteType::Pet:
- petHandler->emote(emote);
- break;
- case EmoteType::Homunculus:
- homunculusHandler->emote(emote);
- break;
- case EmoteType::Mercenary:
- mercenaryHandler->emote(emote);
- break;
- }
- }
- }
-}
diff --git a/src/gui/shortcut/emoteshortcut.h b/src/gui/shortcut/emoteshortcut.h
deleted file mode 100644
index 2ecc2c1b7..000000000
--- a/src/gui/shortcut/emoteshortcut.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 Aethyra Development Team
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_SHORTCUT_EMOTESHORTCUT_H
-#define GUI_SHORTCUT_EMOTESHORTCUT_H
-
-#include "const/emoteshortcut.h"
-
-#include "utils/cast.h"
-
-#include "localconsts.h"
-
-/**
- * The class which keeps track of the emote shortcuts.
- */
-class EmoteShortcut final
-{
- public:
- /**
- * Constructor.
- */
- EmoteShortcut();
-
- A_DELETE_COPY(EmoteShortcut)
-
- /**
- * Destructor.
- */
- ~EmoteShortcut();
-
- /**
- * Load the configuration information.
- */
- void load();
-
- /**
- * Returns the shortcut Emote ID specified by the index.
- *
- * @param index Index of the shortcut Emote.
- */
- unsigned char getEmote(const size_t index) const A_WARN_UNUSED
- { return mEmotes[index]; }
-
- /**
- * Returns the amount of shortcut Emotes.
- */
- static unsigned int getEmoteCount() A_WARN_UNUSED
- { return SHORTCUT_EMOTES; }
-
- /**
- * Returns the emote ID that is currently selected.
- */
- unsigned char getEmoteSelected() const noexcept2 A_WARN_UNUSED
- { return mEmoteSelected; }
-
- /**
- * Adds the selected emote ID to the emotes specified by the index.
- *
- * @param index Index of the emotes.
- */
- void setEmote(const size_t index)
- { mEmotes[index] = mEmoteSelected; }
-
- /**
- * Adds a emoticon to the emotes store specified by the index.
- *
- * @param index Index of the emote.
- * @param emoteId ID of the emote.
- */
- void setEmotes(const size_t index,
- const unsigned char emoteId)
- { mEmotes[index] = emoteId; }
-
- /**
- * Set the Emote that is selected.
- *
- * @param emoteId The ID of the emote that is to be assigned.
- */
- void setEmoteSelected(const unsigned char emoteId)
- { mEmoteSelected = emoteId; }
-
- /**
- * A flag to check if the Emote is selected.
- */
- bool isEmoteSelected() const noexcept2 A_WARN_UNUSED
- { return mEmoteSelected != 0u; }
-
- /**
- * Remove a Emote from the shortcut.
- */
- void removeEmote(const size_t index)
- { if (index < CAST_SIZE(SHORTCUT_EMOTES)) mEmotes[index] = 0; }
-
- /**
- * Try to use the Emote specified by the index.
- *
- * @param index Index of the emote shortcut.
- */
- void useEmote(const size_t index) const;
-
- void useEmotePlayer(const size_t index) const;
-
- private:
- /**
- * Save the configuration information.
- */
- void save() const;
-
- unsigned char mEmotes[SHORTCUT_EMOTES]; // The emote stored.
- unsigned char mEmoteSelected; // The emote held by cursor.
-};
-
-extern EmoteShortcut *emoteShortcut;
-
-#endif // GUI_SHORTCUT_EMOTESHORTCUT_H
diff --git a/src/gui/shortcut/itemshortcut.cpp b/src/gui/shortcut/itemshortcut.cpp
deleted file mode 100644
index f47bfd296..000000000
--- a/src/gui/shortcut/itemshortcut.cpp
+++ /dev/null
@@ -1,289 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/shortcut/itemshortcut.h"
-
-#include "configuration.h"
-#include "spellmanager.h"
-
-#include "being/playerinfo.h"
-
-#include "const/spells.h"
-
-#include "const/resources/skill.h"
-
-#include "gui/windows/skilldialog.h"
-
-#include "resources/inventory/inventory.h"
-
-#include "resources/item/item.h"
-
-#include "debug.h"
-
-ItemShortcut *itemShortcut[SHORTCUT_TABS];
-
-ItemShortcut::ItemShortcut(const size_t number) :
- mItems(),
- mItemColors(),
- mItemData(),
- mNumber(number),
- mItemSelected(-1),
- mItemColorSelected(ItemColor_one)
-{
- load();
-}
-
-ItemShortcut::~ItemShortcut()
-{
- logger->log1("ItemShortcut::~ItemShortcut");
-}
-
-void ItemShortcut::load()
-{
- std::string name;
- std::string color;
- std::string data;
- if (mNumber == SHORTCUT_AUTO_TAB)
- return;
-
- const Configuration *cfg = &serverConfig;
- if (mNumber != 0)
- {
- name = std::string("shortcut").append(
- toString(CAST_S32(mNumber))).append("_");
- color = std::string("shortcutColor").append(
- toString(CAST_U32(mNumber))).append("_");
- data = std::string("shortcutData").append(
- toString(CAST_U32(mNumber))).append("_");
- }
- else
- {
- name = "shortcut";
- color = "shortcutColor";
- data = "shortcutData";
- }
- for (unsigned int i = 0; i < SHORTCUT_ITEMS; i++)
- {
- const int itemId = cfg->getValue(name + toString(i), -1);
- const ItemColor itemColor = fromInt(
- cfg->getValue(color + toString(i), 1),
- ItemColor);
-
- mItems[i] = itemId;
- mItemColors[i] = itemColor;
- mItemData[i] = cfg->getValue(data + toString(i), std::string());
- }
-}
-
-void ItemShortcut::save() const
-{
- std::string name;
- std::string color;
- std::string data;
- if (mNumber == SHORTCUT_AUTO_TAB)
- return;
- if (mNumber != 0)
- {
- name = std::string("shortcut").append(
- toString(CAST_S32(mNumber))).append("_");
- color = std::string("shortcutColor").append(
- toString(CAST_U32(mNumber))).append("_");
- data = std::string("shortcutData").append(
- toString(CAST_U32(mNumber))).append("_");
- }
- else
- {
- name = "shortcut";
- color = "shortcutColor";
- data = "shortcutData";
- }
-
- for (unsigned int i = 0; i < SHORTCUT_ITEMS; i++)
- {
- const int itemId = mItems[i] != 0 ? mItems[i] : -1;
- const int itemColor = toInt(mItemColors[i], int);
- if (itemId != -1)
- {
- const std::string itemData = mItemData[i];
- serverConfig.setValue(name + toString(i), itemId);
- serverConfig.setValue(color + toString(i), itemColor);
- serverConfig.setValue(data + toString(i), itemData);
- }
- else
- {
- serverConfig.deleteKey(name + toString(i));
- serverConfig.deleteKey(color + toString(i));
- serverConfig.deleteKey(data + toString(i));
- }
- }
-}
-
-void ItemShortcut::clear()
-{
- for (size_t i = 0; i < SHORTCUT_ITEMS; i++)
- {
- mItems[i] = 0;
- mItemColors[i] = ItemColor_zero;
- mItemData[i].clear();
- }
-}
-
-void ItemShortcut::useItem(const size_t index) const
-{
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- return;
-
- const int itemId = mItems[index];
- const ItemColor itemColor = mItemColors[index];
- if (itemId >= 0)
- {
- if (itemId < SPELL_MIN_ID)
- {
- const Item *const item = inv->findItem(itemId, itemColor);
- if (item != nullptr && item->getQuantity() != 0)
- PlayerInfo::useEquipItem(item, 0, Sfx_true);
- }
- else if (itemId < SKILL_MIN_ID && (spellManager != nullptr))
- {
- spellManager->useItem(itemId);
- }
- else if (skillDialog != nullptr)
- {
- skillDialog->useItem(itemId,
- fromBool(config.getBoolValue("skillAutotarget"), AutoTarget),
- toInt(itemColor, int),
- mItemData[index]);
- }
- }
-}
-
-void ItemShortcut::equipItem(const size_t index) const
-{
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- return;
-
- const int itemId = mItems[index];
- if (itemId != 0)
- {
- const Item *const item = inv->findItem(itemId, mItemColors[index]);
- if ((item != nullptr) && (item->getQuantity() != 0))
- {
- if (item->isEquipment() == Equipm_true)
- {
- if (item->isEquipped() == Equipped_false)
- PlayerInfo::equipItem(item, Sfx_true);
- }
- }
- }
-}
-void ItemShortcut::unequipItem(const size_t index) const
-{
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- return;
-
- const int itemId = mItems[index];
- if (itemId != 0)
- {
- const Item *const item = inv->findItem(itemId, mItemColors[index]);
- if ((item != nullptr) && (item->getQuantity() != 0))
- {
- if (item->isEquipment() == Equipm_true)
- {
- if (item->isEquipped() == Equipped_true)
- PlayerInfo::unequipItem(item, Sfx_true);
- }
- }
- }
-}
-
-void ItemShortcut::setItemSelected(const Item *const item)
-{
- if (item != nullptr)
- {
- mItemSelected = item->getId();
- mItemColorSelected = item->getColor();
- }
- else
- {
- mItemSelected = -1;
- mItemColorSelected = ItemColor_one;
- }
-}
-
-void ItemShortcut::setItem(const size_t index)
-{
- mItems[index] = mItemSelected;
- mItemColors[index] = mItemColorSelected;
- save();
-}
-
-void ItemShortcut::setItem(const size_t index,
- const int item,
- const ItemColor color)
-{
- mItems[index] = item;
- mItemColors[index] = color;
- save();
-}
-
-void ItemShortcut::setItemFast(const size_t index,
- const int item,
- const ItemColor color)
-{
- mItems[index] = item;
- mItemColors[index] = color;
-}
-
-void ItemShortcut::swap(const size_t index1,
- const size_t index2)
-{
- if (CAST_U32(index1) >= SHORTCUT_ITEMS ||
- CAST_U32(index2) >= SHORTCUT_ITEMS)
- {
- return;
- }
-
- const int tmpItem = mItems[index1];
- mItems[index1] = mItems[index2];
- mItems[index2] = tmpItem;
- const ItemColor tmpColor = mItemColors[index1];
- mItemColors[index1] = mItemColors[index2];
- mItemColors[index2] = tmpColor;
-
- const std::string tmpData = mItemData[index1];
- mItemData[index1] = mItemData[index2];
- mItemData[index2] = tmpData;
- save();
-}
-
-size_t ItemShortcut::getFreeIndex() const
-{
- for (size_t i = 0; i < SHORTCUT_ITEMS; i++)
- {
- if (mItems[i] < 0)
- return i;
- }
- return SHORTCUT_ITEMS;
-}
diff --git a/src/gui/shortcut/itemshortcut.h b/src/gui/shortcut/itemshortcut.h
deleted file mode 100644
index 5e77e9152..000000000
--- a/src/gui/shortcut/itemshortcut.h
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_SHORTCUT_ITEMSHORTCUT_H
-#define GUI_SHORTCUT_ITEMSHORTCUT_H
-
-#include "const/itemshortcut.h"
-
-#include "enums/simpletypes/itemcolor.h"
-
-#include <string>
-
-#include "localconsts.h"
-
-class Item;
-
-/**
- * The class which keeps track of the item shortcuts.
- */
-class ItemShortcut final
-{
- public:
- /**
- * Constructor.
- */
- explicit ItemShortcut(const size_t number);
-
- A_DELETE_COPY(ItemShortcut)
-
- /**
- * Destructor.
- */
- ~ItemShortcut();
-
- /**
- * Load the configuration information.
- */
- void load();
-
- /**
- * Save the configuration information.
- */
- void save() const;
-
- /**
- * Returns the shortcut item ID specified by the index.
- *
- * @param index Index of the shortcut item.
- */
- int getItem(const size_t index) const A_WARN_UNUSED
- { return mItems[index]; }
-
- ItemColor getItemColor(const size_t index) const A_WARN_UNUSED
- { return mItemColors[index]; }
-
- void setItemData(const size_t index,
- const std::string &data)
- { mItemData[index] = data; }
-
- std::string getItemData(const size_t index) const A_WARN_UNUSED
- { return mItemData[index]; }
-
- /**
- * Returns the amount of shortcut items.
- */
- constexpr static int getItemCount() A_WARN_UNUSED
- { return SHORTCUT_ITEMS; }
-
- /**
- * Returns the item ID that is currently selected.
- */
- int getItemSelected() const noexcept2 A_WARN_UNUSED
- { return mItemSelected; }
-
- /**
- * Adds the selected item ID to the items specified by the index.
- *
- * @param index Index of the items.
- */
- void setItem(const size_t index);
-
- void setItem(const size_t index,
- const int item,
- const ItemColor color);
-
- void setItemFast(const size_t index,
- const int item,
- const ItemColor color);
-
- /**
- * Adds an item to the items store specified by the index.
- *
- * @param index Index of the item.
- * @param itemId ID of the item.
- */
- void setItems(const size_t index,
- const int itemId,
- const ItemColor color)
- { mItems[index] = itemId; mItemColors[index] = color; save(); }
-
- /**
- * Set the item that is selected.
- *
- * @param itemId The ID of the item that is to be assigned.
- */
- void setItemSelected(const int itemId)
- { mItemSelected = itemId; }
-
- void setItemSelected(const Item *const item);
-
- /**
- * Returns selected shortcut item ID.
- */
- int getSelectedItem() const noexcept2 A_WARN_UNUSED
- { return mItemSelected; }
-
- /**
- * A flag to check if the item is selected.
- */
- bool isItemSelected() const noexcept2 A_WARN_UNUSED
- { return mItemSelected > -1; }
-
- /**
- * Remove a item from the shortcut.
- */
- void removeItem(const size_t index)
- { mItems[index] = -1; save(); }
-
- /**
- * Try to use the item specified by the index.
- *
- * @param index Index of the item shortcut.
- */
- void useItem(const size_t index) const;
-
- /**
- * Equip a item from the shortcut.
- */
- void equipItem(const size_t index) const;
-
- /**
- * UnEquip a item from the shortcut.
- */
- void unequipItem(const size_t index) const;
-
- void swap(const size_t index1,
- const size_t index2);
-
- void clear();
-
- size_t getFreeIndex() const A_WARN_UNUSED;
-
- private:
- int mItems[SHORTCUT_ITEMS]; /**< The items. */
- ItemColor mItemColors[SHORTCUT_ITEMS]; /**< The item colors. */
- std::string mItemData[SHORTCUT_ITEMS];
- size_t mNumber;
- int mItemSelected;
- ItemColor mItemColorSelected;
-};
-
-extern ItemShortcut *itemShortcut[SHORTCUT_TABS];
-
-#endif // GUI_SHORTCUT_ITEMSHORTCUT_H
diff --git a/src/gui/shortcut/shortcutbase.cpp b/src/gui/shortcut/shortcutbase.cpp
deleted file mode 100644
index 489805517..000000000
--- a/src/gui/shortcut/shortcutbase.cpp
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/shortcut/shortcutbase.h"
-
-#include "configuration.h"
-
-#include "resources/item/item.h"
-
-#include "debug.h"
-
-ShortcutBase::ShortcutBase(const std::string &itemName,
- const std::string &colorName,
- const int maxSize) :
- mItems(new int[maxSize]),
- mItemColors(new ItemColor[maxSize]),
- mItemName(itemName),
- mColorName(colorName),
- mMaxSize(maxSize),
- mItemSelected(-1),
- mItemColorSelected(ItemColor_one)
-{
- clear(false);
- load();
-}
-
-ShortcutBase::~ShortcutBase()
-{
- delete [] mItems;
- mItems = nullptr;
- delete [] mItemColors;
- mItemColors = nullptr;
-}
-
-void ShortcutBase::load()
-{
- const Configuration *cfg = &serverConfig;
-
- for (size_t i = 0; i < mMaxSize; i++)
- {
- const std::string num = toString(CAST_S32(i));
- const int itemId = cfg->getValue(mItemName + num, -1);
- const ItemColor itemColor = fromInt(
- cfg->getValue(mColorName + num, -1),
- ItemColor);
-
- if (itemId != -1)
- {
- mItems[i] = itemId;
- mItemColors[i] = itemColor;
- }
- }
-}
-
-void ShortcutBase::save() const
-{
- for (size_t i = 0; i < mMaxSize; i++)
- {
- const int itemId = mItems[i] != 0 ? mItems[i] : -1;
- const int itemColor = (mItemColors[i] != ItemColor_zero)
- ? toInt(mItemColors[i], int) : 1;
- const std::string num = toString(CAST_S32(i));
- if (itemId != -1)
- {
- serverConfig.setValue(mItemName + num, itemId);
- serverConfig.setValue(mColorName + num, itemColor);
- }
- else
- {
- serverConfig.deleteKey(mItemName + num);
- serverConfig.deleteKey(mColorName + num);
- }
- }
-}
-
-void ShortcutBase::setItemSelected(const Item *const item)
-{
- if (item != nullptr)
- {
- mItemSelected = item->getId();
- mItemColorSelected = item->getColor();
- }
- else
- {
- mItemSelected = -1;
- mItemColorSelected = ItemColor_one;
- }
-}
-
-void ShortcutBase::setItem(const size_t index)
-{
- if (index >= mMaxSize)
- return;
-
- mItems[index] = mItemSelected;
- mItemColors[index] = mItemColorSelected;
- save();
-}
-
-void ShortcutBase::clear(const bool isSave)
-{
- for (size_t i = 0; i < mMaxSize; i++)
- {
- mItems[i] = -1;
- mItemColors[i] = ItemColor_one;
- }
- if (isSave)
- save();
-}
diff --git a/src/gui/shortcut/shortcutbase.h b/src/gui/shortcut/shortcutbase.h
deleted file mode 100644
index 90ca41ee7..000000000
--- a/src/gui/shortcut/shortcutbase.h
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_SHORTCUT_SHORTCUTBASE_H
-#define GUI_SHORTCUT_SHORTCUTBASE_H
-
-#include "enums/simpletypes/itemcolor.h"
-
-#include "utils/cast.h"
-
-#include <string>
-
-#include "localconsts.h"
-
-class Item;
-
-/**
- * The class which keeps track of the item shortcuts.
- */
-class ShortcutBase notfinal
-{
- public:
- /**
- * Constructor.
- */
- ShortcutBase(const std::string &itemName,
- const std::string &colorName,
- const int maxSize);
-
- A_DELETE_COPY(ShortcutBase)
-
- /**
- * Destructor.
- */
- virtual ~ShortcutBase();
-
- /**
- * Load the configuration information.
- */
- void load();
-
- /**
- * Save the configuration information.
- */
- void save() const;
-
- /**
- * Returns the shortcut item ID specified by the index.
- *
- * @param index Index of the shortcut item.
- */
- int getItem(const size_t index) const A_WARN_UNUSED
- { return mItems[index]; }
-
- ItemColor getItemColor(const size_t index) const A_WARN_UNUSED
- { return mItemColors[index]; }
-
- /**
- * Returns the amount of shortcut items.
- */
- int getItemCount() const noexcept2 A_WARN_UNUSED
- { return CAST_S32(mMaxSize); }
-
- /**
- * Returns the item ID that is currently selected.
- */
- int getItemSelected() const noexcept2 A_WARN_UNUSED
- { return mItemSelected; }
-
- /**
- * Adds the selected item ID to the items specified by the index.
- *
- * @param index Index of the items.
- */
- void setItem(const size_t index);
-
- /**
- * Adds an item to the items store specified by the index.
- *
- * @param index Index of the item.
- * @param itemId ID of the item.
- */
- void setItems(const size_t index,
- const int itemId,
- const ItemColor color)
- { mItems[index] = itemId; mItemColors[index] = color; save(); }
-
- /**
- * Set the item that is selected.
- *
- * @param itemId The ID of the item that is to be assigned.
- */
- void setItemSelected(const int itemId)
- { mItemSelected = itemId; }
-
- void setItemSelected(const Item *const item);
-
- /**
- * A flag to check if the item is selected.
- */
- bool isItemSelected() const noexcept2 A_WARN_UNUSED
- { return mItemSelected > -1; }
-
- /**
- * Remove a item from the shortcut.
- */
- void removeItem(const size_t index)
- { mItems[index] = -1; save(); }
-
- void clear(const bool isSave = true);
-
- private:
- int *mItems A_NONNULLPOINTER;
- ItemColor *mItemColors A_NONNULLPOINTER;
- std::string mItemName;
- std::string mColorName;
- size_t mMaxSize;
- int mItemSelected;
- ItemColor mItemColorSelected;
-};
-
-#endif // GUI_SHORTCUT_SHORTCUTBASE_H
diff --git a/src/gui/shortcut/spellshortcut.cpp b/src/gui/shortcut/spellshortcut.cpp
deleted file mode 100644
index 14eaa2f48..000000000
--- a/src/gui/shortcut/spellshortcut.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/shortcut/spellshortcut.h"
-
-#include "spellmanager.h"
-#include "textcommand.h"
-
-#include "debug.h"
-
-SpellShortcut *spellShortcut = nullptr;
-
-SpellShortcut::SpellShortcut() :
- mItemSelected(-1)
-{
- load();
-}
-
-SpellShortcut::~SpellShortcut()
-{
-}
-
-void SpellShortcut::load()
-{
- for (unsigned f = 0; f < SPELLS_SIZE; f ++)
- mItems[f] = -1;
-
- if (spellManager == nullptr)
- return;
-
- const STD_VECTOR<TextCommand*> &spells = spellManager->getAll();
- unsigned k = 0;
-
- for (STD_VECTOR<TextCommand*>::const_iterator i = spells.begin(),
- i_end = spells.end(); i != i_end && k < SPELLS_SIZE; ++i)
- {
- mItems[k++] = (*i)->getId();
- }
-}
-
-unsigned int SpellShortcut::getSpellsCount() const
-{
- return SPELL_SHORTCUT_ITEMS;
-}
diff --git a/src/gui/shortcut/spellshortcut.h b/src/gui/shortcut/spellshortcut.h
deleted file mode 100644
index 4eab518a6..000000000
--- a/src/gui/shortcut/spellshortcut.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_SHORTCUT_SPELLSHORTCUT_H
-#define GUI_SHORTCUT_SPELLSHORTCUT_H
-
-#include "const/spells.h"
-
-/**
- * The class which keeps track of the item shortcuts.
- */
-class SpellShortcut final
-{
- public:
- /**
- * Constructor.
- */
- SpellShortcut();
-
- A_DELETE_COPY(SpellShortcut)
-
- /**
- * Destructor.
- */
- ~SpellShortcut() A_CONST;
-
- /**
- * Load the configuration information.
- */
- void load();
-
- unsigned int getSpellsCount() const A_CONST A_WARN_UNUSED;
-
- /**
- * Set the item that is selected.
- *
- * @param itemId The ID of the item that is to be assigned.
- */
- void setItemSelected(const int itemId) noexcept2
- { mItemSelected = itemId; }
-
- /**
- * A flag to check if the item is selected.
- */
- bool isItemSelected() const noexcept2 A_WARN_UNUSED
- { return mItemSelected > -1; }
-
- /**
- * Returns selected shortcut item ID.
- */
- int getSelectedItem() const noexcept2 A_WARN_UNUSED
- { return mItemSelected; }
-
- /**
- * Returns the shortcut item ID specified by the index.
- *
- * @param index Index of the shortcut item.
- */
- int getItem(const size_t index) const
- { return mItems[index]; }
-
- private:
- int mItems[SPELLS_SIZE];
- int mItemSelected; /**< The item held by cursor. */
-};
-
-extern SpellShortcut *spellShortcut;
-
-#endif // GUI_SHORTCUT_SPELLSHORTCUT_H
diff --git a/src/gui/skin.cpp b/src/gui/skin.cpp
deleted file mode 100644
index 45317fa0d..000000000
--- a/src/gui/skin.cpp
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 The Legend of Mazzeroth Development Team
- * Copyright (C) 2009 Aethyra Development Team
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/skin.h"
-
-#include "settings.h"
-
-#include "enums/resources/imageposition.h"
-
-#include "resources/imagerect.h"
-
-#include "resources/image/image.h"
-
-#include "utils/delete2.h"
-
-#include "debug.h"
-
-Skin::Skin(ImageRect *const restrict skin,
- const ImageRect *const restrict images,
- const std::string &filePath, const std::string &name,
- const int padding, const int titlePadding,
- StringIntMap *restrict const options) :
- instances(1),
- mFilePath(filePath),
- mName(name),
- mBorder(skin),
- mCloseImage(images != nullptr ? images->grid[0] : nullptr),
- mCloseImageHighlighted(images != nullptr ? images->grid[1] : nullptr),
- mStickyImageUp(images != nullptr ? images->grid[2] : nullptr),
- mStickyImageDown(images != nullptr ? images->grid[3] : nullptr),
- mPadding(padding),
- mTitlePadding(titlePadding),
- mOptions(options)
-{
- if (mCloseImageHighlighted == nullptr)
- {
- mCloseImageHighlighted = mCloseImage;
- if (mCloseImageHighlighted != nullptr)
- mCloseImageHighlighted->incRef();
- }
-}
-
-Skin::~Skin()
-{
- for (int i = 0; i < 9; i++)
- {
- if ((mBorder != nullptr) && (mBorder->grid[i] != nullptr))
- {
- mBorder->grid[i]->decRef();
- mBorder->grid[i] = nullptr;
- }
- }
-
- if (mCloseImage != nullptr)
- {
- mCloseImage->decRef();
- mCloseImage = nullptr;
- }
-
- if (mCloseImageHighlighted != nullptr)
- {
- mCloseImageHighlighted->decRef();
- mCloseImageHighlighted = nullptr;
- }
-
- if (mStickyImageUp != nullptr)
- {
- mStickyImageUp->decRef();
- mStickyImageUp = nullptr;
- }
-
- if (mStickyImageDown != nullptr)
- {
- mStickyImageDown->decRef();
- mStickyImageDown = nullptr;
- }
-
- delete2(mOptions);
- delete2(mBorder);
-}
-
-void Skin::updateAlpha(const float minimumOpacityAllowed)
-{
- const float alpha = static_cast<float>(
- std::max(static_cast<double>(minimumOpacityAllowed),
- static_cast<double>(settings.guiAlpha)));
-
- if (mBorder != nullptr)
- {
- for (int i = 0; i < 9; i++)
- {
- if (mBorder->grid[i] != nullptr)
- mBorder->grid[i]->setAlpha(alpha);
- }
- }
-
- if (mCloseImage != nullptr)
- mCloseImage->setAlpha(alpha);
- if (mCloseImageHighlighted != nullptr)
- mCloseImageHighlighted->setAlpha(alpha);
- if (mStickyImageUp != nullptr)
- mStickyImageUp->setAlpha(alpha);
- if (mStickyImageDown != nullptr)
- mStickyImageDown->setAlpha(alpha);
-}
-
-int Skin::getMinWidth() const
-{
- if ((mBorder == nullptr) ||
- (mBorder->grid[ImagePosition::UPPER_LEFT] == nullptr) ||
- (mBorder->grid[ImagePosition::UPPER_RIGHT] == nullptr))
- {
- return 1;
- }
-
- return mBorder->grid[ImagePosition::UPPER_LEFT]->getWidth() +
- mBorder->grid[ImagePosition::UPPER_RIGHT]->getWidth();
-}
-
-int Skin::getMinHeight() const
-{
- if ((mBorder == nullptr) ||
- (mBorder->grid[ImagePosition::UPPER_LEFT] == nullptr) ||
- (mBorder->grid[ImagePosition::LOWER_LEFT] == nullptr))
- {
- return 1;
- }
-
- return mBorder->grid[ImagePosition::UPPER_LEFT]->getHeight() +
- mBorder->grid[ImagePosition::LOWER_LEFT]->getHeight();
-}
diff --git a/src/gui/skin.h b/src/gui/skin.h
deleted file mode 100644
index acba303ac..000000000
--- a/src/gui/skin.h
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 The Legend of Mazzeroth Development Team
- * Copyright (C) 2009 Aethyra Development Team
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_SKIN_H
-#define GUI_SKIN_H
-
-#include "utils/stringmap.h"
-
-#include "localconsts.h"
-
-class Image;
-class ImageRect;
-
-class Skin final
-{
- public:
- Skin(ImageRect *const restrict skin,
- const ImageRect *const restrict images,
- const std::string &filePath,
- const std::string &name,
- const int padding,
- const int titlePadding,
- StringIntMap *restrict const options) A_NONNULL(8);
-
- A_DELETE_COPY(Skin)
-
- ~Skin();
-
- /**
- * Returns the skin's name. Useful for giving a human friendly skin
- * name if a dialog for skin selection for a specific window type is
- * done.
- */
- const std::string &getName() const noexcept2 A_WARN_UNUSED
- { return mName; }
-
- /**
- * Returns the skin's xml file path.
- */
- const std::string &getFilePath() const noexcept2 A_WARN_UNUSED
- { return mFilePath; }
-
- /**
- * Returns the background skin.
- */
- const ImageRect &getBorder() const noexcept2 A_WARN_UNUSED
- { return *mBorder; }
-
- /**
- * Returns the image used by a close button for this skin.
- */
- const Image *getCloseImage(const bool state) const
- noexcept2 A_WARN_UNUSED
- { return state ? mCloseImageHighlighted : mCloseImage; }
-
- /**
- * Returns the image used by a sticky button for this skin.
- */
- const Image *getStickyImage(const bool state) const
- noexcept2 A_WARN_UNUSED
- { return state ? mStickyImageDown : mStickyImageUp; }
-
- /**
- * Returns the minimum width which can be used with this skin.
- */
- int getMinWidth() const A_WARN_UNUSED;
-
- /**
- * Returns the minimum height which can be used with this skin.
- */
- int getMinHeight() const A_WARN_UNUSED;
-
- /**
- * Updates the alpha value of the skin
- */
- void updateAlpha(const float minimumOpacityAllowed = 0.0F);
-
- int getPadding() const noexcept2 A_WARN_UNUSED
- { return mPadding; }
-
- int getTitlePadding() const noexcept2 A_WARN_UNUSED
- { return mTitlePadding; }
-
- int getOption(const std::string &name) const A_WARN_UNUSED
- {
- if (mOptions->find(name) != mOptions->end())
- return (*mOptions)[name];
- return 0;
- }
-
- int getOption(const std::string &name,
- const int def) const A_WARN_UNUSED
- {
- if (mOptions->find(name) != mOptions->end())
- return (*mOptions)[name];
- return def;
- }
-
- int instances;
-
- private:
- std::string mFilePath; /**< File name path for the skin */
- std::string mName; /**< Name of the skin to use */
- ImageRect *mBorder; /**< The window border and background */
- Image *mCloseImage; /**< Close Button Image */
- Image *mCloseImageHighlighted; /**< Highlighted close Button Image */
- Image *mStickyImageUp; /**< Sticky Button Image */
- Image *mStickyImageDown; /**< Sticky Button Image */
- int mPadding;
- int mTitlePadding;
- StringIntMap *mOptions A_NONNULLPOINTER;
-};
-
-#endif // GUI_SKIN_H
diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp
deleted file mode 100644
index cbc0d654c..000000000
--- a/src/gui/theme.cpp
+++ /dev/null
@@ -1,1283 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 The Legend of Mazzeroth Development Team
- * Copyright (C) 2009 Aethyra Development Team
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/theme.h"
-
-#include "configuration.h"
-#include "graphicsmanager.h"
-
-#include "const/gui/theme.h"
-
-#include "fs/virtfs/fs.h"
-#include "fs/virtfs/list.h"
-
-#include "gui/skin.h"
-#include "gui/themeinfo.h"
-
-#include "resources/imagerect.h"
-
-#include "resources/dye/dyepalette.h"
-
-#include "resources/image/image.h"
-
-#include "resources/loaders/imageloader.h"
-#include "resources/loaders/imagesetloader.h"
-#include "resources/loaders/subimageloader.h"
-#include "resources/loaders/subimagesetloader.h"
-#include "resources/loaders/xmlloader.h"
-
-#include "utils/dtor.h"
-#include "utils/foreach.h"
-
-#include "debug.h"
-
-static std::string defaultThemePath;
-
-std::string Theme::mThemePath;
-std::string Theme::mThemeName;
-std::string Theme::mScreenDensity;
-
-Theme *theme = nullptr;
-
-// Set the theme path...
-static void initDefaultThemePath()
-{
- defaultThemePath = branding.getStringValue("guiThemePath");
-
- logger->log("defaultThemePath: " + defaultThemePath);
- if (!defaultThemePath.empty() &&
- VirtFs::isDirectory(defaultThemePath))
- {
- return;
- }
- defaultThemePath = "themes/";
-}
-
-Theme::Theme() :
- Palette(CAST_S32(ThemeColorId::THEME_COLORS_END) * THEME_PALETTES),
- mSkins(),
- mMinimumOpacity(-1.0F),
- mProgressColors(ProgressColors(CAST_SIZE(
- ProgressColorId::THEME_PROG_END)))
-{
- initDefaultThemePath();
-
- config.addListener("guialpha", this);
-
- mColors[CAST_SIZE(ThemeColorId::HIGHLIGHT)].ch = 'H';
- mColors[CAST_SIZE(ThemeColorId::CHAT)].ch = 'C';
- mColors[CAST_SIZE(ThemeColorId::GM)].ch = 'G';
- mColors[CAST_SIZE(ThemeColorId::GLOBAL)].ch = 'g';
- mColors[CAST_SIZE(ThemeColorId::PLAYER)].ch = 'Y';
- mColors[CAST_SIZE(ThemeColorId::WHISPER_TAB)].ch = 'W';
- mColors[CAST_SIZE(ThemeColorId::WHISPER_TAB_OFFLINE)].ch = 'w';
- mColors[CAST_SIZE(ThemeColorId::IS)].ch = 'I';
- mColors[CAST_SIZE(ThemeColorId::PARTY_CHAT_TAB)].ch = 'P';
- mColors[CAST_SIZE(ThemeColorId::GUILD_CHAT_TAB)].ch = 'U';
- mColors[CAST_SIZE(ThemeColorId::SERVER)].ch = 'S';
- mColors[CAST_SIZE(ThemeColorId::LOGGER)].ch = 'L';
- mColors[CAST_SIZE(ThemeColorId::HYPERLINK)].ch = '<';
- mColors[CAST_SIZE(ThemeColorId::SELFNICK)].ch = 's';
- mColors[CAST_SIZE(ThemeColorId::OLDCHAT)].ch = 'o';
- mColors[CAST_SIZE(ThemeColorId::AWAYCHAT)].ch = 'a';
- mCharColors['H'] = CAST_S32(ThemeColorId::HIGHLIGHT);
- mCharColors['C'] = CAST_S32(ThemeColorId::CHAT);
- mCharColors['G'] = CAST_S32(ThemeColorId::GM);
- mCharColors['g'] = CAST_S32(ThemeColorId::GLOBAL);
- mCharColors['Y'] = CAST_S32(ThemeColorId::PLAYER);
- mCharColors['W'] = CAST_S32(ThemeColorId::WHISPER_TAB);
- mCharColors['w'] = CAST_S32(ThemeColorId::WHISPER_TAB_OFFLINE);
- mCharColors['I'] = CAST_S32(ThemeColorId::IS);
- mCharColors['P'] = CAST_S32(ThemeColorId::PARTY_CHAT_TAB);
- mCharColors['U'] = CAST_S32(ThemeColorId::GUILD_CHAT_TAB);
- mCharColors['S'] = CAST_S32(ThemeColorId::SERVER);
- mCharColors['L'] = CAST_S32(ThemeColorId::LOGGER);
- mCharColors['<'] = CAST_S32(ThemeColorId::HYPERLINK);
- mCharColors['s'] = CAST_S32(ThemeColorId::SELFNICK);
- mCharColors['o'] = CAST_S32(ThemeColorId::OLDCHAT);
- mCharColors['a'] = CAST_S32(ThemeColorId::AWAYCHAT);
-
- // here need use outlined colors
- mCharColors['H' | 0x80]
- = CAST_S32(ThemeColorId::HIGHLIGHT_OUTLINE);
- mCharColors['C' | 0x80] = CAST_S32(ThemeColorId::CHAT_OUTLINE);
- mCharColors['G' | 0x80] = CAST_S32(ThemeColorId::GM_OUTLINE);
- mCharColors['g' | 0x80] = CAST_S32(ThemeColorId::GLOBAL_OUTLINE);
- mCharColors['Y' | 0x80] = CAST_S32(ThemeColorId::PLAYER_OUTLINE);
- mCharColors['W' | 0x80]
- = CAST_S32(ThemeColorId::WHISPER_TAB_OUTLINE);
- mCharColors['w' | 0x80]
- = CAST_S32(ThemeColorId::WHISPER_TAB_OFFLINE_OUTLINE);
- mCharColors['I' | 0x80] = CAST_S32(ThemeColorId::IS_OUTLINE);
- mCharColors['P' | 0x80]
- = CAST_S32(ThemeColorId::PARTY_CHAT_TAB_OUTLINE);
- mCharColors['U' | 0x80]
- = CAST_S32(ThemeColorId::GUILD_CHAT_TAB_OUTLINE);
- mCharColors['S' | 0x80] = CAST_S32(ThemeColorId::SERVER_OUTLINE);
- mCharColors['L' | 0x80] = CAST_S32(ThemeColorId::LOGGER_OUTLINE);
- mCharColors['<' | 0x80]
- = CAST_S32(ThemeColorId::HYPERLINK_OUTLINE);
- mCharColors['s' | 0x80] = CAST_S32(ThemeColorId::SELFNICK_OUTLINE);
- mCharColors['o' | 0x80] = CAST_S32(ThemeColorId::OLDCHAT_OUTLINE);
- mCharColors['a' | 0x80] = CAST_S32(ThemeColorId::AWAYCHAT_OUTLINE);
-}
-
-Theme::~Theme()
-{
- delete_all(mSkins);
- config.removeListener("guialpha", this);
- CHECKLISTENERS
- delete_all(mProgressColors);
-}
-
-Color Theme::getProgressColor(const ProgressColorIdT type,
- const float progress)
-{
- int color[3] = {0, 0, 0};
-
- if (theme != nullptr)
- {
- const DyePalette *const dye
- = theme->mProgressColors[CAST_SIZE(type)];
-
- if (dye != nullptr)
- {
- dye->getColor(progress, color);
- }
- else
- {
- logger->log("color not found: "
- + toString(CAST_S32(type)));
- }
- }
-
- return Color(color[0], color[1], color[2]);
-}
-
-Skin *Theme::load(const std::string &filename,
- const std::string &filename2,
- const bool full,
- const std::string &restrict defaultPath)
-{
- // Check if this skin was already loaded
-
- const SkinIterator skinIterator = mSkins.find(filename);
- if (mSkins.end() != skinIterator)
- {
- if (skinIterator->second != nullptr)
- skinIterator->second->instances++;
- return skinIterator->second;
- }
-
- Skin *skin = nullptr;
- if (mScreenDensity.empty())
- { // if no density detected
- skin = readSkin(filename, full);
- if ((skin == nullptr) && !filename2.empty() && filename2 != filename)
- skin = readSkin(filename2, full);
- if ((skin == nullptr) && filename2 != "window.xml")
- skin = readSkin("window.xml", full);
- }
- else
- { // first use correct density images
- const std::string endStr("_" + mScreenDensity + ".xml");
- std::string name = filename;
- if (findCutLast(name, ".xml"))
- skin = readSkin(name + endStr, full);
- if (skin == nullptr)
- skin = readSkin(filename, full);
- if ((skin == nullptr) && !filename2.empty() && filename2 != filename)
- {
- name = filename2;
- if (findCutLast(name, ".xml"))
- skin = readSkin(name + endStr, full);
- if (skin == nullptr)
- skin = readSkin(filename2, full);
- }
- if ((skin == nullptr) && filename2 != "window.xml")
- {
- skin = readSkin("window" + endStr, full);
- if (skin == nullptr)
- skin = readSkin("window.xml", full);
- }
- }
-
- if (skin == nullptr)
- {
- // Try falling back on the defaultPath if this makes sense
- if (filename != defaultPath)
- {
- logger->log("Error loading skin '%s', falling back on default.",
- filename.c_str());
-
- skin = readSkin(defaultPath, full);
- }
-
- if (skin == nullptr)
- {
- logger->log(strprintf("Error: Loading default skin '%s' failed. "
- "Make sure the skin file is valid.",
- defaultPath.c_str()));
- }
- }
-
- mSkins[filename] = skin;
- return skin;
-}
-
-void Theme::unload(Skin *const skin)
-{
- if (skin == nullptr)
- return;
- skin->instances --;
- if (skin->instances == 0)
- {
- SkinIterator it = mSkins.begin();
- const SkinIterator it_end = mSkins.end();
- while (it != it_end)
- {
- if (it->second == skin)
- {
- mSkins.erase(it);
- break;
- }
- ++ it;
- }
- delete skin;
- }
-}
-
-void Theme::setMinimumOpacity(const float minimumOpacity)
-{
- if (minimumOpacity > 1.0F)
- return;
-
- mMinimumOpacity = minimumOpacity;
- updateAlpha();
-}
-
-void Theme::updateAlpha()
-{
- FOR_EACH (SkinIterator, iter, mSkins)
- {
- Skin *const skin = iter->second;
- if (skin != nullptr)
- skin->updateAlpha(mMinimumOpacity);
- }
-}
-
-void Theme::optionChanged(const std::string &name A_UNUSED)
-{
- updateAlpha();
-}
-
-struct SkinParameter final
-{
- A_DEFAULT_COPY(SkinParameter)
- int index;
- std::string name;
-};
-
-static const SkinParameter skinParam[] =
-{
- {0, "top-left-corner"},
- {0, "standart"},
- {0, "up"},
- {0, "hstart"},
- {0, "in"},
- {0, "normal"},
- {1, "top-edge"},
- {1, "highlighted"},
- {1, "down"},
- {1, "hmiddle"},
- {1, "in-highlighted"},
- {1, "checked"},
- {2, "top-right-corner"},
- {2, "pressed"},
- {2, "left"},
- {2, "hend"},
- {2, "out"},
- {2, "disabled"},
- {3, "left-edge"},
- {3, "disabled"},
- {3, "right"},
- {3, "hgrip"},
- {3, "out-highlighted"},
- {3, "disabled-checked"},
- {4, "bg-quad"},
- {4, "vstart"},
- {4, "normal-highlighted"},
- {5, "right-edge"},
- {5, "vmiddle"},
- {5, "checked-highlighted"},
- {6, "bottom-left-corner"},
- {6, "vend"},
- {7, "bottom-edge"},
- {7, "vgrip"},
- {8, "bottom-right-corner"},
-};
-
-static const SkinParameter imageParam[] =
-{
- {0, "closeImage"},
- {1, "closeImageHighlighted"},
- {2, "stickyImageUp"},
- {3, "stickyImageDown"},
-};
-
-struct SkinHelper final
-{
- SkinHelper() :
- partType(),
- xPos(),
- yPos(),
- width(),
- height(),
- rect(),
- node(),
- image()
- {
- }
-
- A_DELETE_COPY(SkinHelper)
-
- std::string partType;
- int xPos;
- int yPos;
- int width;
- int height;
- ImageRect *rect;
- XmlNodePtr *node;
- Image *image;
-
- bool loadList(const SkinParameter *const params,
- const size_t size) A_NONNULL(2)
- {
- for (size_t f = 0; f < size; f ++)
- {
- const SkinParameter &param = params[f];
- if (partType == param.name)
- {
- rect->grid[param.index] = Loader::getSubImage(
- image,
- xPos, yPos,
- width, height);
- return true;
- }
- }
- return false;
- }
-};
-
-Skin *Theme::readSkin(const std::string &filename, const bool full)
-{
- if (filename.empty())
- return nullptr;
-
- const std::string path = resolveThemePath(filename);
- if (!VirtFs::exists(path))
- return nullptr;
- XML::Document *const doc = Loader::getXml(path,
- UseVirtFs_true,
- SkipError_true);
- if (doc == nullptr)
- return nullptr;
- XmlNodeConstPtr rootNode = doc->rootNode();
- if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "skinset"))
- {
- doc->decRef();
- return nullptr;
- }
-
- const std::string skinSetImage = XML::getProperty(rootNode, "image", "");
-
- if (skinSetImage.empty())
- {
- logger->log1("Theme::readSkin(): Skinset does not define an image!");
- doc->decRef();
- return nullptr;
- }
-
- Image *const dBorders = Theme::getImageFromTheme(skinSetImage);
- ImageRect *const border = new ImageRect;
- ImageRect *const images = new ImageRect;
- int padding = 3;
- int titlePadding = 4;
- int titlebarHeight = 0;
- int titlebarHeightRelative = 0;
- int closePadding = 3;
- int stickySpacing = 3;
- int stickyPadding = 3;
- int resizePadding = 2;
- StringIntMap *const mOptions = new StringIntMap;
-
- // iterate <widget>'s
- for_each_xml_child_node(widgetNode, rootNode)
- {
- if (!xmlNameEqual(widgetNode, "widget"))
- continue;
-
- const std::string widgetType =
- XML::getProperty(widgetNode, "type", "unknown");
- if (widgetType == "Window")
- {
- SkinHelper helper;
- const int globalXPos = XML::getProperty(widgetNode, "xpos", 0);
- const int globalYPos = XML::getProperty(widgetNode, "ypos", 0);
- for_each_xml_child_node(partNode, widgetNode)
- {
- if (xmlNameEqual(partNode, "part"))
- {
- helper.partType = XML::getProperty(
- partNode, "type", "unknown");
- helper.xPos = XML::getProperty(
- partNode, "xpos", 0) + globalXPos;
- helper.yPos = XML::getProperty(
- partNode, "ypos", 0) + globalYPos;
- helper.width = XML::getProperty(partNode, "width", 0);
- helper.height = XML::getProperty(partNode, "height", 0);
- if ((helper.width == 0) || (helper.height == 0))
- continue;
- helper.image = dBorders;
-
- helper.rect = border;
- if (!helper.loadList(skinParam,
- sizeof(skinParam) / sizeof(SkinParameter)))
- {
- helper.rect = images;
- helper.loadList(imageParam,
- sizeof(imageParam) / sizeof(SkinParameter));
- }
- }
- else if (full && xmlNameEqual(partNode, "option"))
- {
- const std::string name = XML::getProperty(
- partNode, "name", "");
- if (name == "padding")
- {
- padding = XML::getProperty(partNode, "value", 3);
- }
- else if (name == "titlePadding")
- {
- titlePadding = XML::getProperty(partNode, "value", 4);
- }
- else if (name == "closePadding")
- {
- closePadding = XML::getProperty(partNode, "value", 3);
- }
- else if (name == "stickySpacing")
- {
- stickySpacing = XML::getProperty(partNode, "value", 3);
- }
- else if (name == "stickyPadding")
- {
- stickyPadding = XML::getProperty(partNode, "value", 3);
- }
- else if (name == "titlebarHeight")
- {
- titlebarHeight = XML::getProperty(
- partNode, "value", 0);
- }
- else if (name == "titlebarHeightRelative")
- {
- titlebarHeightRelative = XML::getProperty(
- partNode, "value", 0);
- }
- else if (name == "resizePadding")
- {
- resizePadding = XML::getProperty(
- partNode, "value", 2);
- }
- else
- {
- (*mOptions)[name] = XML::getProperty(
- partNode, "value", 0);
- }
- }
- }
- }
- else
- {
- logger->log("Theme::readSkin(): Unknown widget type '%s'",
- widgetType.c_str());
- }
- }
-
- if (dBorders != nullptr)
- dBorders->decRef();
-
- (*mOptions)["closePadding"] = closePadding;
- (*mOptions)["stickyPadding"] = stickyPadding;
- (*mOptions)["stickySpacing"] = stickySpacing;
- (*mOptions)["titlebarHeight"] = titlebarHeight;
- (*mOptions)["titlebarHeightRelative"] = titlebarHeightRelative;
- (*mOptions)["resizePadding"] = resizePadding;
-
- Skin *const skin = new Skin(border, images, filename, "", padding,
- titlePadding, mOptions);
- delete images;
- skin->updateAlpha(mMinimumOpacity);
- doc->decRef();
- return skin;
-}
-
-bool Theme::tryThemePath(const std::string &themeName)
-{
- if (!themeName.empty())
- {
- const std::string path = defaultThemePath + themeName;
- if (VirtFs::exists(path))
- {
- mThemePath = path;
- mThemeName = themeName;
- if (theme != nullptr)
- theme->loadColors("");
- return true;
- }
- }
-
- return false;
-}
-
-void Theme::fillSkinsList(StringVect &list)
-{
- VirtFs::getDirs(branding.getStringValue("guiThemePath"), list);
- std::sort(list.begin(), list.end());
-}
-
-void Theme::fillFontsList(StringVect &list)
-{
- VirtFs::permitLinks(true);
- VirtFs::getFiles(branding.getStringValue("fontsPath"), list);
- std::sort(list.begin(), list.end());
- VirtFs::permitLinks(false);
-}
-
-void Theme::fillSoundsList(StringVect &list)
-{
- VirtFs::List *const skins = VirtFs::enumerateFiles(
- branding.getStringValue("systemsounds"));
-
- FOR_EACH (StringVectCIter, i, skins->names)
- {
- if (!VirtFs::isDirectory((branding.getStringValue(
- "systemsounds") + *i)))
- {
- std::string str = *i;
- if (findCutLast(str, ".ogg"))
- list.push_back(str);
- }
- }
-
- VirtFs::freeList(skins);
- std::sort(list.begin(), list.end());
-}
-
-void Theme::selectSkin()
-{
- prepareThemePath();
- mScreenDensity = graphicsManager.getDensityString();
-}
-
-void Theme::prepareThemePath()
-{
- initDefaultThemePath();
-
- mThemePath.clear();
- mThemeName.clear();
-
- // Try theme from settings
- if (tryThemePath(config.getStringValue("theme")))
- return;
-
- // Try theme from branding
- if (tryThemePath(branding.getStringValue("theme")))
- return;
-
- if (mThemePath.empty())
- mThemePath = "graphics/gui";
-
- theme->loadColors(mThemePath);
-
- logger->log("Selected Theme: " + mThemePath);
-}
-
-std::string Theme::resolveThemePath(const std::string &path)
-{
- // Need to strip off any dye info for the existence tests
- const int pos = CAST_S32(path.find('|'));
- std::string file;
- if (pos > 0)
- file = path.substr(0, pos);
- else
- file = path;
-
- // File with path
- if (file.find('/') != std::string::npos)
- {
- // Might be a valid path already
- if (VirtFs::exists(file))
- return path;
- }
-
- // Try the theme
- file = pathJoin(getThemePath(), file);
-
- if (VirtFs::exists(file))
- return pathJoin(getThemePath(), path);
-
- // Backup
- return pathJoin(branding.getStringValue("guiPath"), path);
-}
-
-Image *Theme::getImageFromTheme(const std::string &path)
-{
- return Loader::getImage(resolveThemePath(path));
-}
-
-ImageSet *Theme::getImageSetFromTheme(const std::string &path,
- const int w, const int h)
-{
- return Loader::getImageSet(resolveThemePath(path), w, h);
-}
-
-static int readColorType(const std::string &type)
-{
- static const std::string colors[CAST_SIZE(
- ThemeColorId::THEME_COLORS_END)] =
- {
- "BROWSERBOX",
- "BROWSERBOX_OUTLINE",
- "SELFNICK",
- "SELFNICK_OUTLINE",
- "TEXT",
- "TEXT_OUTLINE",
- "CARET",
- "SHADOW",
- "OUTLINE",
- "BORDER",
- "PROGRESS_BAR",
- "PROGRESS_BAR_OUTLINE",
- "BUTTON",
- "BUTTON_OUTLINE",
- "BUTTON_DISABLED",
- "BUTTON_DISABLED_OUTLINE",
- "BUTTON_HIGHLIGHTED",
- "BUTTON_HIGHLIGHTED_OUTLINE",
- "BUTTON_PRESSED",
- "BUTTON_PRESSED_OUTLINE",
- "CHECKBOX",
- "CHECKBOX_OUTLINE",
- "DROPDOWN",
- "DROPDOWN_OUTLINE",
- "LABEL",
- "LABEL_OUTLINE",
- "LISTBOX",
- "LISTBOX_OUTLINE",
- "LISTBOX_SELECTED",
- "LISTBOX_SELECTED_OUTLINE",
- "RADIOBUTTON",
- "RADIOBUTTON_OUTLINE",
- "POPUP",
- "POPUP_OUTLINE",
- "TAB",
- "TAB_OUTLINE",
- "TAB_HIGHLIGHTED",
- "TAB_HIGHLIGHTED_OUTLINE",
- "TAB_SELECTED",
- "TAB_SELECTED_OUTLINE",
- "TEXTBOX",
- "TEXTFIELD",
- "TEXTFIELD_OUTLINE",
- "WINDOW",
- "WINDOW_OUTLINE",
- "BATTLE_CHAT_TAB",
- "BATTLE_CHAT_TAB_OUTLINE",
- "CHANNEL_CHAT_TAB",
- "CHANNEL_CHAT_TAB_OUTLINE",
- "PARTY_CHAT_TAB",
- "PARTY_CHAT_TAB_OUTLINE",
- "PARTY_SOCIAL_TAB",
- "PARTY_SOCIAL_TAB_OUTLINE",
- "GUILD_CHAT_TAB",
- "GUILD_CHAT_TAB_OUTLINE",
- "GUILD_SOCIAL_TAB",
- "GUILD_SOCIAL_TAB_OUTLINE",
- "GM_CHAT_TAB",
- "GM_CHAT_TAB_OUTLINE",
- "BATTLE_CHAT_TAB_HIGHLIGHTED",
- "BATTLE_CHAT_TAB_HIGHLIGHTED_OUTLINE",
- "CHANNEL_CHAT_TAB_HIGHLIGHTED",
- "CHANNEL_CHAT_TAB_HIGHLIGHTED_OUTLINE",
- "PARTY_CHAT_TAB_HIGHLIGHTED",
- "PARTY_CHAT_TAB_HIGHLIGHTED_OUTLINE",
- "PARTY_SOCIAL_TAB_HIGHLIGHTED",
- "PARTY_SOCIAL_TAB_HIGHLIGHTED_OUTLINE",
- "GUILD_CHAT_TAB_HIGHLIGHTED",
- "GUILD_CHAT_TAB_HIGHLIGHTED_OUTLINE",
- "GUILD_SOCIAL_TAB_HIGHLIGHTED",
- "GUILD_SOCIAL_TAB_HIGHLIGHTED_OUTLINE",
- "GM_CHAT_TAB_HIGHLIGHTED",
- "GM_CHAT_TAB_HIGHLIGHTED_OUTLINE",
- "BATTLE_CHAT_TAB_SELECTED",
- "BATTLE_CHAT_TAB_SELECTED_OUTLINE",
- "CHANNEL_CHAT_TAB_SELECTED",
- "CHANNEL_CHAT_TAB_SELECTED_OUTLINE",
- "PARTY_CHAT_TAB_SELECTED",
- "PARTY_CHAT_TAB_SELECTED_OUTLINE",
- "PARTY_SOCIAL_TAB_SELECTED",
- "PARTY_SOCIAL_TAB_SELECTED_OUTLINE",
- "GUILD_CHAT_TAB_SELECTED",
- "GUILD_CHAT_TAB_SELECTED_OUTLINE",
- "GUILD_SOCIAL_TAB_SELECTED",
- "GUILD_SOCIAL_TAB_SELECTED_OUTLINE",
- "GM_CHAT_TAB_SELECTED",
- "GM_CHAT_TAB_SELECTED_OUTLINE",
- "BACKGROUND",
- "BACKGROUND_GRAY",
- "SCROLLBAR_GRAY",
- "DROPDOWN_SHADOW",
- "HIGHLIGHT",
- "HIGHLIGHT_OUTLINE",
- "TAB_FLASH",
- "TAB_FLASH_OUTLINE",
- "TAB_PLAYER_FLASH",
- "TAB_PLAYER_FLASH_OUTLINE",
- "SHOP_WARNING",
- "ITEM_EQUIPPED",
- "ITEM_EQUIPPED_OUTLINE",
- "ITEM_NOT_EQUIPPED",
- "ITEM_NOT_EQUIPPED_OUTLINE",
- "CHAT",
- "CHAT_OUTLINE",
- "GM",
- "GM_OUTLINE",
- "GLOBAL",
- "GLOBAL_OUTLINE",
- "PLAYER",
- "PLAYER_OUTLINE",
- "WHISPER_TAB",
- "WHISPER_TAB_OUTLINE",
- "WHISPER_TAB_OFFLINE",
- "WHISPER_TAB_OFFLINE_OUTLINE",
- "WHISPER_TAB_HIGHLIGHTED",
- "WHISPER_TAB_HIGHLIGHTED_OUTLINE",
- "WHISPER_TAB_OFFLINE_HIGHLIGHTED",
- "WHISPER_TAB_OFFLINE_HIGHLIGHTED_OUTLINE",
- "WHISPER_TAB_SELECTED",
- "WHISPER_TAB_SELECTED_OUTLINE",
- "WHISPER_TAB_OFFLINE_SELECTED",
- "WHISPER_TAB_OFFLINE_SELECTED_OUTLINE",
- "IS",
- "IS_OUTLINE",
- "SERVER",
- "SERVER_OUTLINE",
- "LOGGER",
- "LOGGER_OUTLINE",
- "HYPERLINK",
- "HYPERLINK_OUTLINE",
- "UNKNOWN_ITEM",
- "UNKNOWN_ITEM_OUTLINE",
- "GENERIC",
- "GENERIC_OUTLINE",
- "HEAD",
- "HEAD_OUTLINE",
- "USABLE",
- "USABLE_OUTLINE",
- "TORSO",
- "TORSO_OUTLINE",
- "ONEHAND",
- "ONEHAND_OUTLINE",
- "LEGS",
- "LEGS_OUTLINE",
- "FEET",
- "FEET_OUTLINE",
- "TWOHAND",
- "TWOHAND_OUTLINE",
- "SHIELD",
- "SHIELD_OUTLINE",
- "RING",
- "RING_OUTLINE",
- "NECKLACE",
- "NECKLACE_OUTLINE",
- "ARMS",
- "ARMS_OUTLINE",
- "AMMO",
- "AMMO_OUTLINE",
- "SERVER_VERSION_NOT_SUPPORTED",
- "SERVER_VERSION_NOT_SUPPORTED_OUTLINE",
- "WARNING",
- "WARNING_OUTLINE",
- "CHARM",
- "CHARM_OUTLINE",
- "CARD",
- "CARD_OUTLINE",
- "PLAYER_ADVANCED",
- "PLAYER_ADVANCED_OUTLINE",
- "BUBBLE_NAME",
- "BUBBLE_NAME_OUTLINE",
- "BUBBLE_TEXT",
- "BUBBLE_TEXT_OUTLINE",
- "BLACK",
- "BLACK_OUTLINE",
- "RED",
- "RED_OUTLINE",
- "GREEN",
- "GREEN_OUTLINE",
- "BLUE",
- "BLUE_OUTLINE",
- "ORANGE",
- "ORANGE_OUTLINE",
- "YELLOW",
- "YELLOW_OUTLINE",
- "PINK",
- "PINK_OUTLINE",
- "PURPLE",
- "PURPLE_OUTLINE",
- "GRAY",
- "GRAY_OUTLINE",
- "BROWN",
- "BROWN_OUTLINE",
- "STATUSBAR_ON",
- "STATUSBAR_OFF",
- "TABLE_BACKGROUND",
- "SLOTS_BAR",
- "SLOTS_BAR_OUTLINE",
- "HP_BAR",
- "HP_BAR_OUTLINE",
- "MP_BAR",
- "MP_BAR_OUTLINE",
- "NO_MP_BAR",
- "NO_MP_BAR_OUTLINE",
- "XP_BAR",
- "XP_BAR_OUTLINE",
- "WEIGHT_BAR",
- "WEIGHT_BAR_OUTLINE",
- "MONEY_BAR",
- "MONEY_BAR_OUTLINE",
- "ARROWS_BAR",
- "ARROWS_BAR_OUTLINE",
- "STATUS_BAR",
- "STATUS_BAR_OUTLINE",
- "JOB_BAR",
- "JOB_BAR_OUTLINE",
- "OLDCHAT",
- "OLDCHAT_OUTLINE",
- "AWAYCHAT",
- "AWAYCHAT_OUTLINE",
- "SKILL_COOLDOWN",
- "TEXT_DISABLED",
- "TEXT_DISABLED_OUTLINE"
- };
-
- if (type.empty())
- return -1;
-
- for (int i = 0; i < CAST_S32(ThemeColorId::THEME_COLORS_END); i++)
- {
- if (compareStrI(type, colors[i]) == 0)
- return i;
- }
-
- return -1;
-}
-
-static Color readColor(const std::string &description)
-{
- const int size = static_cast<int>(description.length());
- if (size < 7 || description[0] != '#')
- {
- logger->log("Error, invalid theme color palette: %s",
- description.c_str());
- return Palette::BLACK;
- }
-
- unsigned int v = 0;
- for (int i = 1; i < 7; ++i)
- {
- signed const char c = description[i];
- int n;
-
- if ('0' <= c && c <= '9')
- {
- n = c - '0';
- }
- else if ('A' <= c && c <= 'F')
- {
- n = c - 'A' + 10;
- }
- else if ('a' <= c && c <= 'f')
- {
- n = c - 'a' + 10;
- }
- else
- {
- logger->log("Error, invalid theme color palette: %s",
- description.c_str());
- return Palette::BLACK;
- }
-
- v = (v << 4) | n;
- }
-
- return Color(v);
-}
-
-static GradientTypeT readColorGradient(const std::string &grad)
-{
- static const std::string grads[] =
- {
- "STATIC",
- "PULSE",
- "SPECTRUM",
- "RAINBOW"
- };
-
- if (grad.empty())
- return GradientType::STATIC;
-
- for (int i = 0; i < 4; i++)
- {
- if (compareStrI(grad, grads[i]) != 0)
- return static_cast<GradientTypeT>(i);
- }
-
- return GradientType::STATIC;
-}
-
-static int readProgressType(const std::string &type)
-{
- static const std::string colors[CAST_SIZE(
- ProgressColorId::THEME_PROG_END)] =
- {
- "HP",
- "HP_POISON",
- "MP",
- "NO_MP",
- "EXP",
- "INVY_SLOTS",
- "WEIGHT",
- "JOB",
- "UPDATE",
- "MONEY",
- "ARROWS",
- "STATUS"
- };
-
- if (type.empty())
- return -1;
-
- for (int i = 0; i < CAST_S32(ProgressColorId::THEME_PROG_END); i++)
- {
- if (compareStrI(type, colors[i]) == 0)
- return i;
- }
-
- return -1;
-}
-
-void Theme::loadColors(std::string file)
-{
- if (file.empty())
- file = "colors.xml";
- else
- file = pathJoin(file, "colors.xml");
-
- XML::Document *const doc = Loader::getXml(resolveThemePath(file),
- UseVirtFs_true,
- SkipError_false);
- if (doc == nullptr)
- return;
- XmlNodeConstPtrConst root = doc->rootNode();
-
- if ((root == nullptr) || !xmlNameEqual(root, "colors"))
- {
- logger->log("Error loading colors file: %s", file.c_str());
- doc->decRef();
- return;
- }
-
- logger->log("Loading colors file: %s", file.c_str());
-
- for_each_xml_child_node(paletteNode, root)
- {
- if (xmlNameEqual(paletteNode, "progressbar"))
- {
- const int type = readProgressType(XML::getProperty(
- paletteNode, "id", ""));
- if (type < 0)
- continue;
-
- mProgressColors[type] = new DyePalette(XML::getProperty(
- paletteNode, "color", ""), 6);
- }
- else if (!xmlNameEqual(paletteNode, "palette"))
- {
- continue;
- }
-
- const int paletteId = XML::getProperty(paletteNode, "id", 1);
- if (paletteId < 0 || paletteId >= THEME_PALETTES)
- continue;
-
- for_each_xml_child_node(node, paletteNode)
- {
- if (xmlNameEqual(node, "color"))
- {
- const std::string id = XML::getProperty(node, "id", "");
- const int type = readColorType(id);
- if (type < 0)
- continue;
-
- const std::string temp = XML::getProperty(node, "color", "");
- if (temp.empty())
- continue;
-
- const Color color = readColor(temp);
- const GradientTypeT grad = readColorGradient(
- XML::getProperty(node, "effect", ""));
- mColors[paletteId * CAST_SIZE(
- ThemeColorId::THEME_COLORS_END) + type].set(
- type, color, grad, 10);
-
- if (!findLast(id, "_OUTLINE"))
- {
- const int type2 = readColorType(id + "_OUTLINE");
- if (type2 < 0)
- continue;
- const int idx = paletteId
- * CAST_S32(ThemeColorId::THEME_COLORS_END);
- mColors[idx + type2] = mColors[idx + type];
- }
- }
- }
- }
- doc->decRef();
-}
-
-#define loadGrid() \
- { \
- const ImageRect &rect = skin->getBorder(); \
- for (int f = start; f <= end; f ++) \
- { \
- if (rect.grid[f]) \
- { \
- image.grid[f] = rect.grid[f]; \
- image.grid[f]->incRef(); \
- } \
- } \
- }
-
-void Theme::loadRect(ImageRect &image,
- const std::string &name,
- const std::string &name2,
- const int start,
- const int end)
-{
- Skin *const skin = load(name, name2, false);
- if (skin != nullptr)
- {
- loadGrid();
- unload(skin);
- }
-}
-
-Skin *Theme::loadSkinRect(ImageRect &image,
- const std::string &name,
- const std::string &name2,
- const int start,
- const int end)
-{
- Skin *const skin = load(name, name2);
- if (skin != nullptr)
- loadGrid();
- return skin;
-}
-
-void Theme::unloadRect(const ImageRect &rect,
- const int start,
- const int end)
-{
- for (int f = start; f <= end; f ++)
- {
- if (rect.grid[f] != nullptr)
- rect.grid[f]->decRef();
- }
-}
-
-Image *Theme::getImageFromThemeXml(const std::string &name,
- const std::string &name2)
-{
- if (theme == nullptr)
- return nullptr;
-
- Skin *const skin = theme->load(name, name2, false);
- if (skin != nullptr)
- {
- const ImageRect &rect = skin->getBorder();
- if (rect.grid[0] != nullptr)
- {
- Image *const image = rect.grid[0];
- image->incRef();
- theme->unload(skin);
- return image;
- }
- theme->unload(skin);
- }
- return nullptr;
-}
-
-ImageSet *Theme::getImageSetFromThemeXml(const std::string &name,
- const std::string &name2,
- const int w, const int h)
-{
- if (theme == nullptr)
- return nullptr;
-
- Skin *const skin = theme->load(name, name2, false);
- if (skin != nullptr)
- {
- const ImageRect &rect = skin->getBorder();
- if (rect.grid[0] != nullptr)
- {
- Image *const image = rect.grid[0];
- const SDL_Rect &rect2 = image->mBounds;
- if ((rect2.w != 0u) && (rect2.h != 0u))
- {
- ImageSet *const imageSet = Loader::getSubImageSet(
- image, w, h);
- theme->unload(skin);
- return imageSet;
- }
- }
- theme->unload(skin);
- }
- return nullptr;
-}
-
-#define readValue(name) \
- { \
- tmpData = reinterpret_cast<XmlChar*>( \
- XmlNodeGetContent(infoNode)); \
- info->name = tmpData; \
- XmlFree(tmpData); \
- }
-
-#define readIntValue(name) \
- { \
- tmpData = reinterpret_cast<XmlChar*>( \
- XmlNodeGetContent(infoNode)); \
- info->name = atoi(tmpData); \
- XmlFree(tmpData); \
- }
-
-#define readFloatValue(name) \
- { \
- tmpData = reinterpret_cast<XmlChar*>( \
- XmlNodeGetContent(infoNode)); \
- info->name = static_cast<float>(atof(tmpData)); \
- XmlFree(tmpData); \
- }
-
-ThemeInfo *Theme::loadInfo(const std::string &themeName)
-{
- std::string path;
- if (themeName.empty())
- {
- path = "graphics/gui/info.xml";
- }
- else
- {
- path = pathJoin(defaultThemePath,
- themeName,
- "info.xml");
- }
- logger->log("loading: " + path);
- XML::Document *const doc = Loader::getXml(path,
- UseVirtFs_true,
- SkipError_false);
- if (doc == nullptr)
- return nullptr;
- XmlNodeConstPtrConst rootNode = doc->rootNode();
-
- if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "info"))
- {
- doc->decRef();
- return nullptr;
- }
-
- ThemeInfo *const info = new ThemeInfo;
-
- const std::string fontSize2("fontSize_" + mScreenDensity);
- const std::string npcfontSize2("npcfontSize_" + mScreenDensity);
- XmlChar *tmpData = nullptr;
- for_each_xml_child_node(infoNode, rootNode)
- {
- if (xmlNameEqual(infoNode, "name"))
- readValue(name)
- else if (xmlNameEqual(infoNode, "copyright"))
- readValue(copyright)
- else if (xmlNameEqual(infoNode, "font"))
- readValue(font)
- else if (xmlNameEqual(infoNode, "boldFont"))
- readValue(boldFont)
- else if (xmlNameEqual(infoNode, "particleFont"))
- readValue(particleFont)
- else if (xmlNameEqual(infoNode, "helpFont"))
- readValue(helpFont)
- else if (xmlNameEqual(infoNode, "secureFont"))
- readValue(secureFont)
- else if (xmlNameEqual(infoNode, "npcFont"))
- readValue(npcFont)
- else if (xmlNameEqual(infoNode, "japanFont"))
- readValue(japanFont)
- else if (xmlNameEqual(infoNode, "chinaFont"))
- readValue(chinaFont)
- else if (xmlNameEqual(infoNode, "fontSize"))
- readIntValue(fontSize)
- else if (xmlNameEqual(infoNode, "npcfontSize"))
- readIntValue(npcfontSize)
- else if (xmlNameEqual(infoNode, "guialpha"))
- readFloatValue(guiAlpha)
- else if (xmlNameEqual(infoNode, fontSize2.c_str()))
- readIntValue(fontSize)
- else if (xmlNameEqual(infoNode, npcfontSize2.c_str()))
- readIntValue(npcfontSize)
- }
- doc->decRef();
- return info;
-}
-
-ThemeColorIdT Theme::getIdByChar(const signed char c, bool &valid) const
-{
- const CharColors::const_iterator it = mCharColors.find(c);
- if (it != mCharColors.end())
- {
- valid = true;
- return static_cast<ThemeColorIdT>((*it).second);
- }
-
- valid = false;
- return ThemeColorId::BROWSERBOX;
-}
diff --git a/src/gui/theme.h b/src/gui/theme.h
deleted file mode 100644
index 8618468d9..000000000
--- a/src/gui/theme.h
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 The Legend of Mazzeroth Development Team
- * Copyright (C) 2009 Aethyra Development Team
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_THEME_H
-#define GUI_THEME_H
-
-#include "logger.h"
-
-#include "enums/gui/progresscolorid.h"
-#include "enums/gui/themecolorid.h"
-
-#include "listeners/configlistener.h"
-
-#include "gui/palette.h"
-
-#include "utils/stringvector.h"
-
-#include "localconsts.h"
-
-class DyePalette;
-class Image;
-class ImageRect;
-class ImageSet;
-class Skin;
-class Theme;
-
-struct ThemeInfo;
-
-extern Theme *theme;
-
-class Theme final : public Palette,
- public ConfigListener
-{
- public:
- Theme();
-
- ~Theme();
-
- A_DELETE_COPY(Theme)
-
- static void prepareThemePath();
-
- static void selectSkin();
-
- static std::string getThemePath() A_WARN_UNUSED
- { return mThemePath; }
-
- static std::string getThemeName() A_WARN_UNUSED
- { return mThemeName; }
-
- static void fillSkinsList(StringVect &list);
-
- static void fillFontsList(StringVect &list);
-
- static void fillSoundsList(StringVect &list);
-
- /**
- * Returns the patch to the given gui resource relative to the theme
- * or, if it isn't in the theme, relative to 'graphics/gui'.
- */
- static std::string resolveThemePath(const std::string &path)
- A_WARN_UNUSED;
-
- static Image *getImageFromTheme(const std::string &path) A_WARN_UNUSED;
-
- static ImageSet *getImageSetFromTheme(const std::string &path,
- const int w,
- const int h) A_WARN_UNUSED;
-
- static ImageSet *getImageSetFromThemeXml(const std::string &name,
- const std::string &name2,
- const int w,
- const int h)A_WARN_UNUSED;
-
- static Color getProgressColor(const ProgressColorIdT type,
- const float progress) A_WARN_UNUSED;
-
- /**
- * Loads a skin.
- */
- Skin *load(const std::string &filename,
- const std::string &filename2,
- const bool full = true,
- const std::string
- &restrict defaultPath = getThemePath()) A_WARN_UNUSED;
-
- Skin *loadSkinRect(ImageRect &image,
- const std::string &name,
- const std::string &name2,
- const int start = 0,
- const int end = 8) A_WARN_UNUSED;
-
- void unload(Skin *const skin);
-
- /**
- * Updates the alpha values of all of the skins.
- */
- void updateAlpha();
-
- /**
- * Get the minimum opacity allowed to skins.
- */
- float getMinimumOpacity() const noexcept2 A_WARN_UNUSED
- { return mMinimumOpacity; }
-
- /**
- * Gets the color associated with the type. Sets the alpha channel
- * before returning.
- *
- * @param type the color type requested
- * @param alpha alpha channel to use
- *
- * @return the requested color
- */
- inline const Color &getColor(ThemeColorIdT type,
- const unsigned int alpha = 255U)
- A_WARN_UNUSED
- {
- if (CAST_SIZE(type) >= mColors.size())
- {
- logger->log("incorrect color request type: %d from %u",
- CAST_S32(type),
- CAST_U32(mColors.size()));
- type = ThemeColorId::BROWSERBOX;
- }
- Color *const col = &mColors[CAST_SIZE(type)].color;
- col->a = alpha;
- return *col;
- }
-
- ThemeColorIdT getIdByChar(const signed char c,
- bool &valid) const A_WARN_UNUSED;
-
- /**
- * Set the minimum opacity allowed to skins.
- * Set a negative value to free the minimum allowed.
- */
- void setMinimumOpacity(const float minimumOpacity);
-
- void optionChanged(const std::string &name) override final;
-
- void loadRect(ImageRect &image,
- const std::string &name,
- const std::string &name2,
- const int start = 0,
- const int end = 8);
-
- static void unloadRect(const ImageRect &rect,
- const int start = 0,
- const int end = 8);
-
- static Image *getImageFromThemeXml(const std::string &name,
- const std::string &name2)
- A_WARN_UNUSED;
-
- static ThemeInfo *loadInfo(const std::string &themeName) A_WARN_UNUSED;
-
- private:
- Skin *readSkin(const std::string &filename0,
- const bool full) A_WARN_UNUSED;
-
- // Map containing all window skins
- typedef std::map<std::string, Skin*> Skins;
- typedef Skins::iterator SkinIterator;
-
- Skins mSkins;
-
- static std::string mThemePath;
- static std::string mThemeName;
- static std::string mScreenDensity;
-
- static bool tryThemePath(const std::string &themePath) A_WARN_UNUSED;
-
- void loadColors(std::string file = "");
-
- /**
- * Tells if the current skins opacity
- * should not get less than the given value
- */
- float mMinimumOpacity;
-
- typedef STD_VECTOR<DyePalette*> ProgressColors;
- ProgressColors mProgressColors;
-};
-
-#endif // GUI_THEME_H
diff --git a/src/gui/themecolorsidoperators.cpp b/src/gui/themecolorsidoperators.cpp
deleted file mode 100644
index df3a7e65b..000000000
--- a/src/gui/themecolorsidoperators.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2015-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/themecolorsidoperators.h"
-
-#include "utils/cast.h"
-
-#include "debug.h"
-
-ThemeColorIdT operator+(const ThemeColorIdT &id, const int& i)
-{
- return static_cast<ThemeColorIdT>(CAST_S32(id) + i);
-}
diff --git a/src/gui/themecolorsidoperators.h b/src/gui/themecolorsidoperators.h
deleted file mode 100644
index 7d7f13eca..000000000
--- a/src/gui/themecolorsidoperators.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2015-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_THEMECOLORSIDOPERATORS_H
-#define GUI_THEMECOLORSIDOPERATORS_H
-
-#include "enums/gui/themecolorid.h"
-
-ThemeColorIdT operator+(const ThemeColorIdT &id, const int& i);
-
-#endif // GUI_THEMECOLORSIDOPERATORS_H
diff --git a/src/gui/themeinfo.h b/src/gui/themeinfo.h
deleted file mode 100644
index 5514924a2..000000000
--- a/src/gui/themeinfo.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_THEMEINFO_H
-#define GUI_THEMEINFO_H
-
-#include <string>
-
-#include "localconsts.h"
-
-struct ThemeInfo final
-{
- ThemeInfo() :
- name(),
- copyright(),
- font(),
- boldFont(),
- particleFont(),
- helpFont(),
- secureFont(),
- npcFont(),
- japanFont(),
- chinaFont(),
- fontSize(0),
- npcfontSize(0),
- guiAlpha(0.0F)
- {
- }
-
- A_DELETE_COPY(ThemeInfo)
-
- std::string name;
- std::string copyright;
- std::string font;
- std::string boldFont;
- std::string particleFont;
- std::string helpFont;
- std::string secureFont;
- std::string npcFont;
- std::string japanFont;
- std::string chinaFont;
- int fontSize;
- int npcfontSize;
- float guiAlpha;
-};
-
-#endif // GUI_THEMEINFO_H
diff --git a/src/gui/touchactiondata.cpp b/src/gui/touchactiondata.cpp
deleted file mode 100644
index d8c42b6d9..000000000
--- a/src/gui/touchactiondata.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/touchactiondata.h"
-
-#include "input/pages/basic.h"
-#include "input/pages/chat.h"
-#include "input/pages/other.h"
-#include "input/pages/shortcuts.h"
-#include "input/pages/windows.h"
-
-#include "debug.h"
-
-SetupActionData *const touchActionData[] =
-{
- setupActionDataBasic,
- setupActionDataWindows,
- setupActionDataChat,
- setupActionDataOther,
- setupActionDataShortcuts
-};
diff --git a/src/gui/touchactiondata.h b/src/gui/touchactiondata.h
deleted file mode 100644
index 99954d906..000000000
--- a/src/gui/touchactiondata.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_TOUCHACTIONDATA_H
-#define GUI_TOUCHACTIONDATA_H
-
-struct SetupActionData;
-
-extern SetupActionData *const touchActionData[];
-
-#endif // GUI_TOUCHACTIONDATA_H
diff --git a/src/gui/userpalette.cpp b/src/gui/userpalette.cpp
deleted file mode 100644
index 79e3758ac..000000000
--- a/src/gui/userpalette.cpp
+++ /dev/null
@@ -1,649 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 Douglas Boffey <dougaboffey@netscape.net>
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/userpalette.h"
-
-#include "configuration.h"
-
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-UserPalette *userPalette = nullptr;
-
-const std::string ColorTypeNames[CAST_SIZE(
- UserColorId::USER_COLOR_LAST)] =
-{
- "",
- "ColorBeing",
- "ColorFriend",
- "ColorDisregarded",
- "ColorIgnored",
- "ColorErased",
- "ColorEnemy",
- "ColorPlayer",
- "ColorSelf",
- "ColorGM",
- "ColorNPC",
- "ColorMonster",
- "ColorPet",
- "ColorMercenary",
- "ColorHomunculus",
- "ColorSkillUnit",
- "ColorParty",
- "ColorGuild",
- "ColorTeam1",
- "ColorTeam2",
- "ColorTeam3",
- "",
- "ColorParticle",
- "ColorPickupInfo",
- "ColorExpInfo",
- "",
- "ColorPlayerHp",
- "ColorPlayerHp2",
- "ColorMonsterHp",
- "ColorMonsterHp2",
- "ColorHomunHp",
- "ColorHomunHp2",
- "ColorMercHp",
- "ColorMercHp2",
- "ColorElementalHp",
- "ColorElementalHp2",
- "",
- "ColorHitPlayerMonster",
- "ColorHitMonsterPlayer",
- "ColorHitPlayerPlayer",
- "ColorHitCritical",
- "ColorHitLocalPlayerMonster",
- "ColorHitLocalPlayerCritical",
- "ColorHitLocalPlayerMiss",
- "ColorMiss",
- "",
- "ColorPortalHighlight",
- "ColorCollisionHighlight",
- "ColorCollisionAirHighlight",
- "ColorCollisionWaterHighlight",
- "ColorCollisionMonsterHighlight",
- "ColorCollisionGroundtopHighlight",
- "ColorWalkableTileHighlight",
- "ColorNet",
- "",
- "ColorAttackRange",
- "ColorAttackRangeBorder",
- "ColorMonsterAttackRange",
- "ColorSkillAttackRange",
- "",
- "ColorFloorItemText",
- "ColorHomePlace",
- "ColorHomePlaceBorder",
- "ColorRoadPoint",
-};
-
-std::string UserPalette::getConfigName(const std::string &typeName)
-{
- std::string res("Color" + typeName);
- size_t pos = 5;
- for (size_t i = 0; i < typeName.length(); i++)
- {
- if (i == 0 || typeName[i] == '_')
- {
- if (i > 0)
- i++;
-
- res[pos] = typeName[i];
- }
- else
- {
- res[pos] = CAST_S8(tolower(typeName[i]));
- }
- pos ++;
- }
- res.erase(pos, res.length() - pos);
- return res;
-}
-
-UserPalette::UserPalette() :
- Palette(CAST_S32(UserColorId::USER_COLOR_LAST)),
- ListModel()
-{
- mColors[CAST_SIZE(UserColorId::BEING)] = ColorElem();
- mColors[CAST_SIZE(UserColorId::PC)] = ColorElem();
- mColors[CAST_SIZE(UserColorId::SELF)] = ColorElem();
- mColors[CAST_SIZE(UserColorId::GM)] = ColorElem();
- mColors[CAST_SIZE(UserColorId::NPC)] = ColorElem();
- mColors[CAST_SIZE(UserColorId::MONSTER)] = ColorElem();
-
- addLabel(UserColorId::LABEL_BEING,
- // TRANSLATORS: palette label
- _("Beings"));
- addColor(UserColorId::BEING,
- 0xffffff,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Being"));
- addColor(UserColorId::FRIEND,
- 0xb0ffb0,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Friend names"));
- addColor(UserColorId::DISREGARDED,
- 0xa00000,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Disregarded names"));
- addColor(UserColorId::IGNORED,
- 0xff0000,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Ignored names"));
- addColor(UserColorId::ERASED,
- 0xff0000,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Erased names"));
- addColor(UserColorId::ENEMY,
- 0xff4040,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Enemy"));
- addColor(UserColorId::PC,
- 0xffffff,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Other players names"));
- addColor(UserColorId::SELF,
- 0xff8040,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Own name"));
- addColor(UserColorId::GM,
- 0x00ff00,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("GM names"));
- addColor(UserColorId::NPC,
- 0xc8c8ff,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("NPCs"));
- addColor(UserColorId::MONSTER,
- 0xff4040,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Monsters"));
- addColor(UserColorId::PET,
- 0xffffff,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Pets"));
- addColor(UserColorId::MERCENARY,
- 0xffffff,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Mercenary"));
- addColor(UserColorId::HOMUNCULUS,
- 0xffffff,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Homunculus"));
- addColor(UserColorId::SKILLUNIT,
- 0xffffff,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Skill unit"));
- addColor(UserColorId::PARTY,
- 0xff00d8,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Party members"));
- addColor(UserColorId::GUILD,
- 0xff00d8,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Guild members"));
- addColor(UserColorId::TEAM1,
- 0x0000ff,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- strprintf(_("Team %d"), 1));
- addColor(UserColorId::TEAM2,
- 0x00a020,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- strprintf(_("Team %d"), 2));
- addColor(UserColorId::TEAM3,
- 0xffff20,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- strprintf(_("Team %d"), 3));
- addLabel(UserColorId::LABEL_PARTICLES,
- // TRANSLATORS: palette label
- _("Particles"));
- addColor(UserColorId::PARTICLE,
- 0xffffff,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Particle effects"));
- addColor(UserColorId::PICKUP_INFO,
- 0x28dc28,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Pickup notification"));
- addColor(UserColorId::EXP_INFO,
- 0xffff00,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Exp notification"));
- addLabel(UserColorId::LABEL_HP,
- // TRANSLATORS: palette label
- _("Hp bars"));
- addColor(UserColorId::PLAYER_HP,
- 0x00ff00,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Player HP bar"), 50);
- addColor(UserColorId::PLAYER_HP2,
- 0xff0000,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Player HP bar (second color)"),
- 50);
- addColor(UserColorId::MONSTER_HP,
- 0x00ff00,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Monster HP bar"),
- 50);
- addColor(UserColorId::MONSTER_HP2,
- 0xff0000,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Monster HP bar (second color)"),
- 50);
- addColor(UserColorId::HOMUN_HP,
- 0x00ff00,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Homunculus HP bar"),
- 50);
- addColor(UserColorId::HOMUN_HP2,
- 0xff0000,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Homunculus HP bar (second color)"),
- 50);
- addColor(UserColorId::MERC_HP,
- 0x00ff00,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Mercenary HP bar"),
- 50);
- addColor(UserColorId::MERC_HP2,
- 0xff0000,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Mercenary HP bar (second color)"),
- 50);
-
- addColor(UserColorId::ELEMENTAL_HP,
- 0x00ff00,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Elemental HP bar"),
- 50);
- addColor(UserColorId::ELEMENTAL_HP2,
- 0xff0000,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Elemental HP bar (second color)"),
- 50);
- addLabel(UserColorId::LABEL_HITS,
- // TRANSLATORS: palette label
- _("Hits"));
- addColor(UserColorId::HIT_PLAYER_MONSTER,
- 0x0064ff,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Player hits monster"));
- addColor(UserColorId::HIT_MONSTER_PLAYER,
- 0xff3232,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Monster hits player"));
- addColor(UserColorId::HIT_PLAYER_PLAYER,
- 0xff5050,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Other player hits local player"));
- addColor(UserColorId::HIT_CRITICAL,
- 0xff0000,
- GradientType::RAINBOW,
- // TRANSLATORS: palette color
- _("Critical Hit"));
- addColor(UserColorId::HIT_LOCAL_PLAYER_MONSTER,
- 0x00ff00,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Local player hits monster"));
- addColor(UserColorId::HIT_LOCAL_PLAYER_CRITICAL,
- 0xff0000,
- GradientType::RAINBOW,
- // TRANSLATORS: palette color
- _("Local player critical hit"));
- addColor(UserColorId::HIT_LOCAL_PLAYER_MISS,
- 0x00ffa6,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Local player miss"));
- addColor(UserColorId::MISS, 0xffff00,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Misses"));
- addLabel(UserColorId::LABEL_TILES,
- // TRANSLATORS: palette label
- _("Tiles"));
- addColor(UserColorId::PORTAL_HIGHLIGHT,
- 0xC80000,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Portal highlight"));
- addColor(UserColorId::COLLISION_HIGHLIGHT,
- 0x0000C8,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Default collision highlight"),
- 64);
- addColor(UserColorId::AIR_COLLISION_HIGHLIGHT,
- 0xe0e0ff,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Air collision highlight"),
- 64);
- addColor(UserColorId::WATER_COLLISION_HIGHLIGHT,
- 0x2050e0,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Water collision highlight"),
- 64);
- addColor(UserColorId::MONSTER_COLLISION_HIGHLIGHT,
- 0x2050e0,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Monster collision highlight"),
- 64);
- addColor(UserColorId::GROUNDTOP_COLLISION_HIGHLIGHT,
- 0xffff00,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Special ground collision highlight"),
- 20);
- addColor(UserColorId::WALKABLE_HIGHLIGHT,
- 0x00D000,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Walkable highlight"),
- 255);
- addColor(UserColorId::NET,
- 0x000000,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Tiles border"), 64);
- addLabel(UserColorId::LABEL_RANGES,
- // TRANSLATORS: palette label
- _("Ranges"));
- addColor(UserColorId::ATTACK_RANGE,
- 0xffffff,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Local player attack range"),
- 5);
- addColor(UserColorId::ATTACK_RANGE_BORDER,
- 0x0,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Local player attack range border"),
- 76);
- addColor(UserColorId::MONSTER_ATTACK_RANGE,
- 0xff0000,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Monster attack range"),
- 20);
- addColor(UserColorId::SKILL_ATTACK_RANGE,
- 0x0,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Skill attack range border"),
- 76);
- addLabel(UserColorId::LABEL_OTHER,
- // TRANSLATORS: palette label
- _("Other"));
- addColor(UserColorId::FLOOR_ITEM_TEXT,
- 0xffffff,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Floor item amount color"),
- 100);
- addColor(UserColorId::HOME_PLACE,
- 0xffffff,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Home place"),
- 20);
- addColor(UserColorId::HOME_PLACE_BORDER,
- 0xffff00,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Home place border"),
- 200);
- addColor(UserColorId::ROAD_POINT,
- 0x000000,
- GradientType::STATIC,
- // TRANSLATORS: palette color
- _("Road point"), 100);
- commit(true);
-}
-
-UserPalette::~UserPalette()
-{
- FOR_EACH (Colors::const_iterator, col, mColors)
- {
- if (col->grad == GradientType::LABEL)
- continue;
- const std::string &configName = ColorTypeNames[col->type];
- config.setValue(configName + "Gradient",
- CAST_S32(col->committedGrad));
- config.setValue(configName + "Delay", col->delay);
-
- if (col->grad == GradientType::STATIC ||
- col->grad == GradientType::PULSE)
- {
- char buffer[20];
- snprintf(buffer, sizeof(buffer), "0x%06x", col->getRGB());
- buffer[19] = 0;
- config.setValue(configName, std::string(buffer));
- }
- }
-}
-
-void UserPalette::setColor(const UserColorIdT type,
- const int r,
- const int g,
- const int b)
-{
- Color &color = mColors[CAST_SIZE(type)].color;
- color.r = r;
- color.g = g;
- color.b = b;
-}
-
-void UserPalette::setGradient(const UserColorIdT type,
- const GradientTypeT grad)
-{
- ColorElem *const elem = &mColors[CAST_SIZE(type)];
-
- if (elem->grad != GradientType::STATIC && grad == GradientType::STATIC)
- {
- const size_t sz = mGradVector.size();
- for (size_t i = 0; i < sz; i++)
- {
- if (mGradVector[i] == elem)
- {
- mGradVector.erase(mGradVector.begin() + i);
- break;
- }
- }
- }
- else if (elem->grad == GradientType::STATIC &&
- grad != GradientType::STATIC)
- {
- mGradVector.push_back(elem);
- }
-
- if (elem->grad != grad)
- elem->grad = grad;
-}
-
-std::string UserPalette::getElementAt(int i)
-{
- if (i < 0 || i >= getNumberOfElements())
- return "";
-
- return mColors[i].text;
-}
-
-void UserPalette::commit(const bool commitNonStatic)
-{
- FOR_EACH (Colors::iterator, i, mColors)
- {
- i->committedGrad = i->grad;
- i->committedDelay = i->delay;
- if (commitNonStatic || i->grad == GradientType::STATIC)
- i->committedColor = i->color;
- else if (i->grad == GradientType::PULSE)
- i->committedColor = i->testColor;
- }
-}
-
-void UserPalette::rollback()
-{
- FOR_EACH (Colors::iterator, i, mColors)
- {
- if (i->grad != i->committedGrad)
- setGradient(static_cast<UserColorIdT>(i->type), i->committedGrad);
-
- const Color &committedColor = i->committedColor;
- setGradientDelay(static_cast<UserColorIdT>(i->type),
- i->committedDelay);
- setColor(static_cast<UserColorIdT>(i->type),
- committedColor.r,
- committedColor.g,
- committedColor.b);
-
- if (i->grad == GradientType::PULSE)
- {
- Color &testColor = i->testColor;
- testColor.r = committedColor.r;
- testColor.g = committedColor.g;
- testColor.b = committedColor.b;
- }
- }
-}
-
-int UserPalette::getColorTypeAt(const int i)
-{
- if (i < 0 || i >= getNumberOfElements())
- return 0;
-
- return mColors[i].type;
-}
-
-void UserPalette::addColor(const UserColorIdT type,
- const unsigned rgb,
- GradientTypeT grad,
- const std::string &text,
- int delay)
-{
- const unsigned maxType = sizeof(ColorTypeNames)
- / sizeof(ColorTypeNames[0]);
-
- if (CAST_U32(type) >= maxType)
- return;
-
- const std::string &configName = ColorTypeNames[CAST_SIZE(type)];
- char buffer[20];
- snprintf(buffer, sizeof(buffer), "0x%06x", rgb);
- buffer[19] = 0;
-
- const std::string rgbString = config.getValue(
- configName, std::string(buffer));
- unsigned int rgbValue = 0;
- if (rgbString.length() == 8 && rgbString[0] == '0' && rgbString[1] == 'x')
- rgbValue = atox(rgbString);
- else
- rgbValue = atoi(rgbString.c_str());
- const Color &trueCol = Color(rgbValue);
- grad = static_cast<GradientTypeT>(config.getValue(
- configName + "Gradient",
- CAST_S32(grad)));
- delay = config.getValueInt(configName + "Delay", delay);
- mColors[CAST_SIZE(type)].set(CAST_S32(type),
- trueCol, grad, delay);
- mColors[CAST_SIZE(type)].text = text;
-
- if (grad != GradientType::STATIC)
- mGradVector.push_back(&mColors[CAST_SIZE(type)]);
-}
-
-void UserPalette::addLabel(const UserColorIdT type,
- const std::string &text)
-{
- const unsigned maxType = sizeof(ColorTypeNames)
- / sizeof(ColorTypeNames[0]);
-
- if (CAST_U32(type) >= maxType)
- return;
-
-
- mColors[CAST_SIZE(type)] = ColorElem();
- const std::string str(" \342\200\225\342\200\225\342\200\225"
- "\342\200\225\342\200\225 ");
- mColors[CAST_SIZE(type)].grad = GradientType::LABEL;
- mColors[CAST_SIZE(type)].text =
- std::string(str).append(text).append(str);
-}
-
-int UserPalette::getIdByChar(const signed char c, bool &valid) const
-{
- const CharColors::const_iterator it = mCharColors.find(c);
- if (it != mCharColors.end())
- {
- valid = true;
- return (*it).second;
- }
-
- valid = false;
- return 0;
-}
diff --git a/src/gui/userpalette.h b/src/gui/userpalette.h
deleted file mode 100644
index 4f7e0e941..000000000
--- a/src/gui/userpalette.h
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 Douglas Boffey <dougaboffey@netscape.net>
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_USERPALETTE_H
-#define GUI_USERPALETTE_H
-
-#include "logger.h"
-
-#include "enums/gui/usercolorid.h"
-
-#include "gui/palette.h"
-
-#include "gui/models/listmodel.h"
-
-/**
- * Class controlling the game's color palette.
- */
-class UserPalette final : public Palette, public ListModel
-{
- public:
- /**
- * Constructor
- */
- UserPalette();
-
- A_DELETE_COPY(UserPalette)
-
- /**
- * Destructor
- */
- ~UserPalette();
-
- /**
- * Gets the committed color associated with the specified type.
- *
- * @param type the color type requested
- *
- * @return the requested committed color
- */
- inline const Color &getCommittedColor(const UserColorIdT type)
- const A_WARN_UNUSED
- {
- return mColors[CAST_SIZE(type)].committedColor;
- }
-
- /**
- * Gets the test color associated with the specified type.
- *
- * @param type the color type requested
- *
- * @return the requested test color
- */
- inline const Color &getTestColor(const UserColorIdT type)
- const A_WARN_UNUSED
- { return mColors[CAST_SIZE(type)].testColor; }
-
- /**
- * Sets the test color associated with the specified type.
- *
- * @param type the color type requested
- * @param color the color that should be tested
- */
- inline void setTestColor(const UserColorIdT type,
- const Color &color)
- { mColors[CAST_SIZE(type)].testColor = color; }
-
- /**
- * Sets the color for the specified type.
- *
- * @param type color to be set
- * @param r red component
- * @param g green component
- * @param b blue component
- */
- void setColor(const UserColorIdT type,
- const int r,
- const int g,
- const int b);
-
- /**
- * Sets the gradient type for the specified color.
- *
- * @param grad gradient type to set
- */
- void setGradient(const UserColorIdT type,
- const GradientTypeT grad);
-
- void setGradientDelay(const UserColorIdT type,
- const int delay)
- { mColors[CAST_SIZE(type)].delay = delay; }
-
- /**
- * Returns the number of colors known.
- *
- * @return the number of colors known
- */
- inline int getNumberOfElements() override final A_WARN_UNUSED
- { return CAST_S32(mColors.size()); }
-
- /**
- * Returns the name of the ith color.
- *
- * @param i index of color interested in
- *
- * @return the name of the color
- */
- std::string getElementAt(int i) override final A_WARN_UNUSED;
-
- /**
- * Commit the colors
- */
- inline void commit()
- { commit(false); }
-
- /**
- * Rollback the colors
- */
- void rollback();
-
- /**
- * Gets the ColorType used by the color for the element at index i in
- * the current color model.
- *
- * @param i the index of the color
- *
- * @return the color type of the color with the given index
- */
- int getColorTypeAt(const int i) A_WARN_UNUSED;
-
- /**
- * Gets the color associated with the type. Sets the alpha channel
- * before returning.
- *
- * @param type the color type requested
- * @param alpha alpha channel to use
- *
- * @return the requested color
- */
- inline const Color &getColor(UserColorIdT type,
- const unsigned int alpha = 255U)
- A_WARN_UNUSED
- {
- if (CAST_SIZE(type) >= mColors.size())
- {
- logger->log("incorrect color request type: %d from %u",
- CAST_S32(type),
- CAST_U32(mColors.size()));
- type = UserColorId::BEING;
- }
- Color* col = &mColors[CAST_SIZE(type)].color;
- col->a = alpha;
- return *col;
- }
-
- int getIdByChar(const signed char c, bool &valid) const A_WARN_UNUSED;
-
- /**
- * Gets the GradientType associated with the specified type.
- *
- * @param type the color type of the color
- *
- * @return the gradient type of the color with the given index
- */
- inline GradientTypeT getGradientType(const UserColorIdT type)
- const A_WARN_UNUSED
- { return mColors[CAST_SIZE(type)].grad; }
-
- /**
- * Gets the gradient delay for the specified type.
- *
- * @param type the color type of the color
- *
- * @return the gradient delay of the color with the given index
- */
- inline int getGradientDelay(const UserColorIdT type)
- const A_WARN_UNUSED
- { return mColors[CAST_SIZE(type)].delay; }
-
- inline const Color &getColorWithAlpha(const UserColorIdT type)
- A_WARN_UNUSED
- {
- Color *const col = &mColors[CAST_SIZE(type)].color;
- col->a = CAST_U32(
- mColors[CAST_SIZE(type)].delay);
- return *col;
- }
-
- private:
- /**
- * Define a color replacement.
- *
- * @param i the index of the color to replace
- * @param r red component
- * @param g green component
- * @param b blue component
- */
- void setColorAt(int i, int r, int g, int b);
-
- /**
- * Commit the colors. Commit the non-static color values, if
- * commitNonStatic is true. Only needed in the constructor.
- */
- void commit(const bool commitNonStatic);
-
- /**
- * Prefixes the given string with "Color", lowercases all letters but
- * the first and all following a '_'. All '_'s will be removed.
- *
- * E.g.: HIT_PLAYER_MONSTER -> HitPlayerMonster
- *
- * @param typeName string to transform
- *
- * @return the transformed string
- */
- static std::string getConfigName(const std::string &typeName)
- A_WARN_UNUSED;
-
- void addColor(const UserColorIdT type,
- const unsigned rgb,
- GradientTypeT grad,
- const std::string &text,
- int delay = GRADIENT_DELAY);
-
- void addLabel(const UserColorIdT type,
- const std::string &text);
-};
-
-extern UserPalette *userPalette;
-
-#endif // GUI_USERPALETTE_H
diff --git a/src/gui/viewport.h b/src/gui/viewport.h
deleted file mode 100644
index 615e1d796..000000000
--- a/src/gui/viewport.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_VIEWPORT_H
-#define GUI_VIEWPORT_H
-
-#ifdef DYECMD
-#include "progs/dyecmd/gui/viewport.h"
-PROGS_DYECMD_GUI_VIEWPORT_H
-#else
-#include "progs/manaplus/gui/viewport.h"
-PROGS_MANAPLUS_GUI_VIEWPORT_H
-#endif // DYECMD
-
-#endif // GUI_VIEWPORT_H
diff --git a/src/gui/widgets/attrs/attrdisplay.cpp b/src/gui/widgets/attrs/attrdisplay.cpp
deleted file mode 100644
index 3b91fef9d..000000000
--- a/src/gui/widgets/attrs/attrdisplay.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/attrs/attrdisplay.h"
-
-#include "being/playerinfo.h"
-
-#include "gui/widgets/layouthelper.h"
-
-#include "utils/delete2.h"
-#include "utils/stringutils.h"
-
-#include "debug.h"
-
-AttrDisplay::AttrDisplay(const Widget2 *const widget,
- const AttributesT id,
- const std::string &restrict name,
- const std::string &restrict shortName) :
- Container(widget),
- mId(id),
- mName(name),
- mShortName(shortName),
- mLayout(new LayoutHelper(this)),
- mLabel(new Label(this, name)),
- mValue(new Label(this, "1 "))
-{
- setSize(100, 32);
-
- setSelectable(false);
- mLabel->setAlignment(Graphics::CENTER);
- mValue->setAlignment(Graphics::CENTER);
-}
-
-AttrDisplay::~AttrDisplay()
-{
- delete2(mLayout);
-}
-
-std::string AttrDisplay::update()
-{
- const int base = PlayerInfo::getStatBase(mId);
- const int bonus = PlayerInfo::getStatMod(mId);
- std::string value = toString(base + bonus);
- if (bonus != 0)
- value.append(strprintf("=%d%+d", base, bonus));
- mValue->setCaption(value);
- return mName;
-}
diff --git a/src/gui/widgets/attrs/attrdisplay.h b/src/gui/widgets/attrs/attrdisplay.h
deleted file mode 100644
index f682e41f5..000000000
--- a/src/gui/widgets/attrs/attrdisplay.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_ATTRS_ATTRDISPLAY_H
-#define GUI_WIDGETS_ATTRS_ATTRDISPLAY_H
-
-#include "enums/being/attributes.h"
-
-#include "gui/widgets/container.h"
-
-#include "gui/widgets/label.h"
-
-#include "localconsts.h"
-
-class LayoutHelper;
-
-class AttrDisplay notfinal : public Container
-{
- public:
- enum Type
- {
- DERIVED = 0,
- CHANGEABLE,
- UNKNOWN
- };
-
- A_DELETE_COPY(AttrDisplay)
-
- virtual ~AttrDisplay();
-
- virtual std::string update();
-
- virtual Type getType() const
- { return UNKNOWN; }
-
- std::string getValue() const
- {
- if (mValue == nullptr)
- return "-";
- return mValue->getCaption();
- }
-
- const std::string &getShortName() const
- { return mShortName; }
-
- protected:
- AttrDisplay(const Widget2 *const widget,
- const AttributesT id,
- const std::string &restrict name,
- const std::string &restrict shortName);
-
- const AttributesT mId;
- const std::string mName;
- const std::string mShortName;
-
- LayoutHelper *mLayout;
- Label *mLabel;
- Label *mValue;
-};
-
-typedef std::map<AttributesT, AttrDisplay*> Attrs;
-
-#endif // GUI_WIDGETS_ATTRS_ATTRDISPLAY_H
diff --git a/src/gui/widgets/attrs/changedisplay.cpp b/src/gui/widgets/attrs/changedisplay.cpp
deleted file mode 100644
index e1af1eb76..000000000
--- a/src/gui/widgets/attrs/changedisplay.cpp
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/attrs/changedisplay.h"
-
-#include "configuration.h"
-
-#include "being/playerinfo.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/layouthelper.h"
-
-#include "net/net.h"
-#include "net/playerhandler.h"
-
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-ChangeDisplay::ChangeDisplay(const Widget2 *const widget,
- const AttributesT id,
- const std::string &restrict name,
- const std::string &restrict shortName) :
- AttrDisplay(widget, id, name, shortName),
- ActionListener(),
- mNeeded(1),
- // TRANSLATORS: status window label
- mPoints(new Label(this, _("Max"))),
- // TRANSLATORS: status window label (plus sign)
- mInc(new Button(this, _("+"), "inc", this))
-{
- // Do the layout
- ContainerPlacer place = mLayout->getPlacer(0, 0);
-
- place(0, 0, mLabel, 3);
- place(4, 0, mValue, 2);
- place(6, 0, mInc);
- place(7, 0, mPoints);
-}
-
-std::string ChangeDisplay::update()
-{
- if (mNeeded > 0)
- {
- mPoints->setCaption(toString(mNeeded));
- }
- else
- {
- // TRANSLATORS: status bar label
- mPoints->setCaption(_("Max"));
- }
-
- mInc->setEnabled(PlayerInfo::getAttribute(Attributes::PLAYER_CHAR_POINTS)
- >= mNeeded && mNeeded > 0);
-
- return AttrDisplay::update();
-}
-
-void ChangeDisplay::setPointsNeeded(const int needed)
-{
- mNeeded = needed;
- update();
-}
-
-void ChangeDisplay::action(const ActionEvent &event)
-{
- if (event.getSource() == mInc)
- {
- int cnt = 1;
- if (config.getBoolValue("quickStats"))
- {
- cnt = mInc->getClickCount();
- if (cnt > 10)
- cnt = 10;
- }
-
- const int newpoints = PlayerInfo::getAttribute(
- Attributes::PLAYER_CHAR_POINTS) - cnt;
- PlayerInfo::setAttribute(Attributes::PLAYER_CHAR_POINTS,
- newpoints);
-
- const int newbase = PlayerInfo::getStatBase(mId) + cnt;
- PlayerInfo::setStatBase(mId, newbase);
-
- if (Net::getNetworkType() != ServerType::TMWATHENA)
- {
- playerHandler->increaseAttribute(mId, cnt);
- }
- else
- {
- for (int f = 0; f < cnt; f ++)
- {
- playerHandler->increaseAttribute(mId, 1);
- if (cnt != 1)
- SDL_Delay(100);
- }
- }
- }
-}
diff --git a/src/gui/widgets/attrs/changedisplay.h b/src/gui/widgets/attrs/changedisplay.h
deleted file mode 100644
index 4e9d1076d..000000000
--- a/src/gui/widgets/attrs/changedisplay.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_ATTRS_CHANGEDISPLAY_H
-#define GUI_WIDGETS_ATTRS_CHANGEDISPLAY_H
-
-#include "gui/widgets/attrs/attrdisplay.h"
-
-#include "listeners/actionlistener.h"
-
-#include "localconsts.h"
-
-class Button;
-
-class ChangeDisplay final : public AttrDisplay,
- public ActionListener
-{
- public:
- ChangeDisplay(const Widget2 *const widget,
- const AttributesT id,
- const std::string &restrict name,
- const std::string &restrict shortName);
-
- A_DELETE_COPY(ChangeDisplay)
-
- std::string update() override final;
-
- Type getType() const override final
- { return CHANGEABLE; }
-
- void setPointsNeeded(const int needed);
-
- void action(const ActionEvent &event) override final;
-
- private:
- int mNeeded;
-
- Label *mPoints;
- Button *mInc;
-};
-
-#endif // GUI_WIDGETS_ATTRS_CHANGEDISPLAY_H
diff --git a/src/gui/widgets/attrs/derdisplay.cpp b/src/gui/widgets/attrs/derdisplay.cpp
deleted file mode 100644
index 2c20c3713..000000000
--- a/src/gui/widgets/attrs/derdisplay.cpp
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/attrs/derdisplay.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/layouthelper.h"
-
-#include "debug.h"
-
-DerDisplay::DerDisplay(const Widget2 *const widget,
- const AttributesT id,
- const std::string &restrict name,
- const std::string &restrict shortName) :
- AttrDisplay(widget, id, name, shortName)
-{
- ContainerPlacer place = mLayout->getPlacer(0, 0);
-
- place(0, 0, mLabel, 3);
- place(3, 0, mValue, 2);
-}
diff --git a/src/gui/widgets/attrs/derdisplay.h b/src/gui/widgets/attrs/derdisplay.h
deleted file mode 100644
index 8b841694e..000000000
--- a/src/gui/widgets/attrs/derdisplay.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_ATTRS_DERDISPLAY_H
-#define GUI_WIDGETS_ATTRS_DERDISPLAY_H
-
-#include "gui/widgets/attrs/attrdisplay.h"
-
-#include "localconsts.h"
-
-class DerDisplay final : public AttrDisplay
-{
- public:
- DerDisplay(const Widget2 *const widget,
- const AttributesT id,
- const std::string &restrict name,
- const std::string &restrict shortName);
-
- A_DELETE_COPY(DerDisplay)
-
- Type getType() const override final
- { return DERIVED; }
-};
-
-#endif // GUI_WIDGETS_ATTRS_DERDISPLAY_H
diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp
deleted file mode 100644
index 383efb397..000000000
--- a/src/gui/widgets/avatarlistbox.cpp
+++ /dev/null
@@ -1,740 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/avatarlistbox.h"
-
-#include "actormanager.h"
-#include "configuration.h"
-
-#include "being/localplayer.h"
-
-#include "enums/resources/map/mapitemtype.h"
-
-#include "gui/gui.h"
-#include "gui/popupmanager.h"
-#include "gui/skin.h"
-#include "gui/viewport.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/popups/popupmenu.h"
-
-#include "gui/models/avatarlistmodel.h"
-
-#include "gui/windows/chatwindow.h"
-
-#include "render/vertexes/imagecollection.h"
-
-#include "resources/image/image.h"
-
-#include "resources/map/map.h"
-
-#include "debug.h"
-
-int AvatarListBox::instances = 0;
-Image *AvatarListBox::onlineIcon = nullptr;
-Image *AvatarListBox::offlineIcon = nullptr;
-
-AvatarListBox::AvatarListBox(const Widget2 *const widget,
- AvatarListModel *const model) :
- ListBox(widget, model, "avatarlistbox.xml"),
- mImagePadding(mSkin != nullptr ? mSkin->getOption("imagePadding") : 0),
- mShowGender(config.getBoolValue("showgender")),
- mShowLevel(config.getBoolValue("showlevel"))
-{
- instances++;
-
- if (instances == 1)
- {
- onlineIcon = Theme::getImageFromThemeXml("circle-on.xml", "");
- offlineIcon = Theme::getImageFromThemeXml("circle-off.xml", "");
- }
-
- setWidth(200);
-
- config.addListener("showgender", this);
- config.addListener("showlevel", this);
-
- mForegroundColor = getThemeColor(ThemeColorId::TEXT);
- mForegroundColor2 = getThemeColor(ThemeColorId::TEXT_OUTLINE);
-}
-
-AvatarListBox::~AvatarListBox()
-{
- config.removeListeners(this);
- CHECKLISTENERS
-
- instances--;
-
- if (instances == 0)
- {
- if (onlineIcon != nullptr)
- {
- onlineIcon->decRef();
- onlineIcon = nullptr;
- }
- if (offlineIcon != nullptr)
- {
- offlineIcon->decRef();
- offlineIcon = nullptr;
- }
- }
-}
-
-void AvatarListBox::draw(Graphics *const graphics)
-{
- BLOCK_START("AvatarListBox::draw")
- if ((mListModel == nullptr) || (localPlayer == nullptr))
- {
- BLOCK_END("AvatarListBox::draw")
- return;
- }
-
- const Widget *const parent = mParent;
- if (parent == nullptr)
- return;
-
- AvatarListModel *const model = static_cast<AvatarListModel *>(
- mListModel);
- updateAlpha();
-
- Font *const font = getFont();
- const int fontHeight = font->getHeight();
- const int parentWidth = parent->getWidth();
- const std::string &name = localPlayer->getName();
-
- // Draw the list elements
- ImageCollection vertexes;
- const int num = model->getNumberOfElements();
- for (int i = 0, y = 0;
- i < num;
- ++i, y += fontHeight)
- {
- const Avatar *const a = model->getAvatarAt(i);
- if (a == nullptr)
- continue;
-
- const MapItemType::Type type = static_cast<MapItemType::Type>(
- a->getType());
- if (type != MapItemType::SEPARATOR)
- {
- // Draw online status
- const Image *const icon = a->getOnline()
- ? onlineIcon : offlineIcon;
- if (icon != nullptr)
- {
- graphics->calcTileCollection(&vertexes, icon,
- mImagePadding, y + mPadding);
- }
- }
- }
-
- graphics->finalize(&vertexes);
- graphics->drawTileCollection(&vertexes);
-
- for (int i = 0, y = 0;
- i < num;
- ++i, y += fontHeight)
- {
- const Avatar *const a = model->getAvatarAt(i);
- if (a == nullptr)
- continue;
-
- const MapItemType::Type type = static_cast<MapItemType::Type>(
- a->getType());
- std::string text;
-
- if (a->getMaxHp() > 0)
- {
- if (mShowLevel && a->getLevel() > 1)
- {
- text = strprintf("%s %d/%d (%d)", a->getComplexName().c_str(),
- a->getHp(), a->getMaxHp(), a->getLevel());
- }
- else
- {
- text = strprintf("%s %d/%d", a->getComplexName().c_str(),
- a->getHp(), a->getMaxHp());
- }
- const bool isPoison = a->getPoison();
- if (a->getMaxHp() != 0)
- {
- const ProgressColorIdT themeColor = (isPoison
- ? ProgressColorId::PROG_HP_POISON
- : ProgressColorId::PROG_HP);
- Color color = Theme::getProgressColor(
- themeColor, static_cast<float>(a->getHp())
- / static_cast<float>(a->getMaxHp()));
- color.a = 80;
- graphics->setColor(color);
- graphics->fillRectangle(Rect(mPadding, y + mPadding,
- parentWidth * a->getHp() / a->getMaxHp()
- - 2 * mPadding, fontHeight));
- }
- }
- else if (a->getDamageHp() != 0 && a->getName() != name)
- {
- if (mShowLevel && a->getLevel() > 1)
- {
- text = strprintf("%s -%d (%d)", a->getComplexName().c_str(),
- a->getDamageHp(), a->getLevel());
- }
- else
- {
- text = strprintf("%s -%d", a->getComplexName().c_str(),
- a->getDamageHp());
- }
-
- const ProgressColorIdT themeColor = (a->getPoison()
- ? ProgressColorId::PROG_HP_POISON : ProgressColorId::PROG_HP);
- Color color = Theme::getProgressColor(themeColor, 1);
- color.a = 80;
- graphics->setColor(color);
- graphics->fillRectangle(Rect(mPadding, y + mPadding,
- parentWidth * a->getDamageHp() / 1024
- - 2 * mPadding, fontHeight));
-
- if (a->getLevel() > 1)
- {
- graphics->setColor(mForegroundColor);
- int minHp = 40 + ((a->getLevel() - 1) * 5);
- if (minHp < 0)
- minHp = 40;
-
- graphics->drawLine(parentWidth * minHp / 1024
- + mPadding, y + mPadding,
- parentWidth * minHp / 1024, y + fontHeight);
- }
- }
- else
- {
- if (mShowLevel && a->getLevel() > 1)
- {
- text = strprintf("%s (%d)", a->getComplexName().c_str(),
- a->getLevel());
- }
- else
- {
- text = a->getComplexName();
- }
- }
-
- if (!a->getMap().empty())
- {
- if (a->getX() != -1)
- {
- text.append(strprintf(" [%d,%d %s]", a->getX(), a->getY(),
- a->getMap().c_str()));
- }
- else
- {
- text.append(strprintf(" [%s]", a->getMap().c_str()));
- }
- }
-
- if (graphics->getSecure())
- {
- if (mShowGender)
- {
- switch (a->getGender())
- {
- case Gender::FEMALE:
- text.append(" \u2640 ");
- break;
- case Gender::MALE:
- text.append(" \u2642 ");
- break;
- default:
- case Gender::UNSPECIFIED:
- case Gender::OTHER:
- break;
- }
- }
- }
- else
- {
- if (mShowGender)
- {
- switch (a->getGender())
- {
- case Gender::FEMALE:
- text.append(strprintf(" \u2640 %s",
- a->getAdditionString().c_str()));
- break;
- case Gender::MALE:
- text.append(strprintf(" \u2642 %s",
- a->getAdditionString().c_str()));
- break;
- default:
- case Gender::UNSPECIFIED:
- case Gender::OTHER:
- break;
- }
- }
- else
- {
- text.append(a->getAdditionString());
- }
- }
-
- // Draw Name
- if (a->getDisplayBold())
- {
- if (type == MapItemType::SEPARATOR)
- {
- boldFont->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- text,
- mImagePadding + mPadding,
- y + mPadding);
- }
- else
- {
- boldFont->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- text,
- 15 + mImagePadding + mPadding,
- y + mPadding);
- }
- }
- else
- {
- if (type == MapItemType::SEPARATOR)
- {
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- text,
- mImagePadding + mPadding,
- y + mPadding);
- }
- else
- {
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- text,
- 15 + mImagePadding + mPadding,
- y + mPadding);
- }
- }
- }
-
- setWidth(parentWidth - 10);
- BLOCK_END("AvatarListBox::draw")
-}
-
-void AvatarListBox::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("AvatarListBox::draw")
- if ((mListModel == nullptr) || (localPlayer == nullptr))
- {
- BLOCK_END("AvatarListBox::draw")
- return;
- }
-
- const Widget *const parent = mParent;
- if (parent == nullptr)
- return;
-
- AvatarListModel *const model = static_cast<AvatarListModel *>(
- mListModel);
- updateAlpha();
-
- Font *const font = getFont();
- const int fontHeight = font->getHeight();
- const int parentWidth = parent->getWidth();
- const std::string &name = localPlayer->getName();
-
- // Draw the list elements
- const int num = model->getNumberOfElements();
- for (int i = 0, y = 0;
- i < num;
- ++i, y += fontHeight)
- {
- const Avatar *const a = model->getAvatarAt(i);
- if (a == nullptr)
- continue;
-
- const MapItemType::Type type = static_cast<MapItemType::Type>(
- a->getType());
- if (type != MapItemType::SEPARATOR)
- {
- // Draw online status
- const Image *const icon = a->getOnline()
- ? onlineIcon : offlineIcon;
- if (icon != nullptr)
- graphics->drawImage(icon, mImagePadding, y + mPadding);
- }
- }
-
- for (int i = 0, y = 0;
- i < model->getNumberOfElements();
- ++i, y += fontHeight)
- {
- const Avatar *const a = model->getAvatarAt(i);
- if (a == nullptr)
- continue;
-
- const MapItemType::Type type = static_cast<MapItemType::Type>(
- a->getType());
- std::string text;
-
- if (a->getMaxHp() > 0)
- {
- if (mShowLevel && a->getLevel() > 1)
- {
- text = strprintf("%s %d/%d (%d)", a->getComplexName().c_str(),
- a->getHp(), a->getMaxHp(), a->getLevel());
- }
- else
- {
- text = strprintf("%s %d/%d", a->getComplexName().c_str(),
- a->getHp(), a->getMaxHp());
- }
- const bool isPoison = a->getPoison();
- if (a->getMaxHp() != 0)
- {
- const ProgressColorIdT themeColor = (isPoison
- ? ProgressColorId::PROG_HP_POISON
- : ProgressColorId::PROG_HP);
- Color color = Theme::getProgressColor(
- themeColor, static_cast<float>(a->getHp())
- / static_cast<float>(a->getMaxHp()));
- color.a = 80;
- graphics->setColor(color);
- graphics->fillRectangle(Rect(mPadding, y + mPadding,
- parentWidth * a->getHp() / a->getMaxHp()
- - 2 * mPadding, fontHeight));
- }
- }
- else if (a->getDamageHp() != 0 && a->getName() != name)
- {
- if (mShowLevel && a->getLevel() > 1)
- {
- text = strprintf("%s -%d (%d)", a->getComplexName().c_str(),
- a->getDamageHp(), a->getLevel());
- }
- else
- {
- text = strprintf("%s -%d", a->getComplexName().c_str(),
- a->getDamageHp());
- }
-
- const ProgressColorIdT themeColor = (a->getPoison()
- ? ProgressColorId::PROG_HP_POISON : ProgressColorId::PROG_HP);
- Color color = Theme::getProgressColor(themeColor, 1);
- color.a = 80;
- graphics->setColor(color);
- graphics->fillRectangle(Rect(mPadding, y + mPadding,
- parentWidth * a->getDamageHp() / 1024
- - 2 * mPadding, fontHeight));
-
- if (a->getLevel() > 1)
- {
- graphics->setColor(mForegroundColor);
- int minHp = 40 + ((a->getLevel() - 1) * 5);
- if (minHp < 0)
- minHp = 40;
-
- graphics->drawLine(parentWidth * minHp / 1024
- + mPadding, y + mPadding,
- parentWidth * minHp / 1024, y + fontHeight);
- }
- }
- else
- {
- if (mShowLevel && a->getLevel() > 1)
- {
- text = strprintf("%s (%d)", a->getComplexName().c_str(),
- a->getLevel());
- }
- else
- {
- text = a->getComplexName();
- }
- }
-
- if (!a->getMap().empty())
- {
- if (a->getX() != -1)
- {
- text.append(strprintf(" [%d,%d %s]", a->getX(), a->getY(),
- a->getMap().c_str()));
- }
- else
- {
- text.append(strprintf(" [%s]", a->getMap().c_str()));
- }
- }
-
- if (graphics->getSecure())
- {
- if (mShowGender)
- {
- switch (a->getGender())
- {
- case Gender::FEMALE:
- text.append(" \u2640 ");
- break;
- case Gender::MALE:
- text.append(" \u2642 ");
- break;
- default:
- case Gender::UNSPECIFIED:
- case Gender::OTHER:
- break;
- }
- }
- }
- else
- {
- if (mShowGender)
- {
- switch (a->getGender())
- {
- case Gender::FEMALE:
- text.append(strprintf(" \u2640 %s",
- a->getAdditionString().c_str()));
- break;
- case Gender::MALE:
- text.append(strprintf(" \u2642 %s",
- a->getAdditionString().c_str()));
- break;
- default:
- case Gender::UNSPECIFIED:
- case Gender::OTHER:
- break;
- }
- }
- else
- {
- text.append(a->getAdditionString());
- }
- }
-
- // Draw Name
- if (a->getDisplayBold())
- {
- if (type == MapItemType::SEPARATOR)
- {
- boldFont->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- text,
- mImagePadding + mPadding,
- y + mPadding);
- }
- else
- {
- boldFont->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- text,
- 15 + mImagePadding + mPadding,
- y + mPadding);
- }
- }
- else
- {
- if (type == MapItemType::SEPARATOR)
- {
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- text,
- mImagePadding + mPadding,
- y + mPadding);
- }
- else
- {
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- text,
- 15 + mImagePadding + mPadding,
- y + mPadding);
- }
- }
- }
-
- setWidth(parentWidth - 10);
- BLOCK_END("AvatarListBox::draw")
-}
-
-void AvatarListBox::mousePressed(MouseEvent &event)
-{
- if (actorManager == nullptr ||
- localPlayer == nullptr ||
- popupManager == nullptr)
- {
- return;
- }
-
- const int height = getFont()->getHeight();
- if (height == 0)
- return;
-
- const int y = (event.getY() - mPadding) / height;
- if ((mListModel == nullptr) || y > mListModel->getNumberOfElements())
- return;
-
- setSelected(y);
- distributeActionEvent();
- const int selected = getSelected();
- AvatarListModel *const model = static_cast<AvatarListModel *>(
- mListModel);
- if (model == nullptr)
- return;
- const Avatar *ava = model->getAvatarAt(selected);
- if (ava == nullptr)
- return;
-
- const MapItemType::Type type = static_cast<MapItemType::Type>(
- ava->getType());
-
- event.consume();
- const MouseButtonT eventButton = event.getButton();
- if (eventButton == MouseButton::LEFT)
- {
-#ifdef TMWA_SUPPORT
- if (type == MapItemType::EMPTY)
- {
- const Being *const being = actorManager->findBeingByName(
- ava->getName(), ActorType::Player);
- if (being != nullptr)
- actorManager->heal(being);
- }
- else
-#endif // TMWA_SUPPORT
- {
- localPlayer->navigateTo(ava->getX(), ava->getY());
- }
- }
- else if (eventButton == MouseButton::RIGHT)
- {
- switch (type)
- {
- case MapItemType::EMPTY:
- {
- const Avatar *const avatar = model->getAvatarAt(selected);
- if (avatar != nullptr)
- {
- const Being *const being = actorManager->findBeingByName(
- avatar->getName(), ActorType::Player);
- if (being != nullptr)
- {
- popupMenu->showPopup(viewport->mMouseX,
- viewport->mMouseY,
- being);
- }
- else
- {
- popupMenu->showPlayerPopup(avatar->getName());
- }
- }
- break;
- }
- case MapItemType::ATTACK:
- case MapItemType::PRIORITY:
- case MapItemType::IGNORE_:
- {
- std::string name;
- if (model->getAvatarAt(selected)->getLevel() == 0)
- name.clear();
- else
- name = model->getAvatarAt(selected)->getName();
-
- popupMenu->showAttackMonsterPopup(viewport->mMouseX,
- viewport->mMouseY,
- name,
- model->getAvatarAt(selected)->getType());
- break;
- }
- case MapItemType::PICKUP:
- case MapItemType::NOPICKUP:
- {
- std::string name;
- if (model->getAvatarAt(selected)->getLevel() == 0)
- name.clear();
- else
- name = model->getAvatarAt(selected)->getName();
-
- popupMenu->showPickupItemPopup(viewport->mMouseX,
- viewport->mMouseY,
- name);
- break;
- }
- case MapItemType::HOME:
- case MapItemType::ROAD:
- case MapItemType::CROSS:
- case MapItemType::ARROW_UP:
- case MapItemType::ARROW_DOWN:
- case MapItemType::ARROW_LEFT:
- case MapItemType::ARROW_RIGHT:
- case MapItemType::PORTAL:
- case MapItemType::MUSIC:
- case MapItemType::SEPARATOR:
- {
- break;
- }
- default:
- {
- const Map *const map = viewport->getMap();
- ava = model->getAvatarAt(selected);
- if ((map != nullptr) && (ava != nullptr))
- {
- MapItem *const mapItem = map->findPortalXY(
- ava->getX(), ava->getY());
- popupMenu->showPopup(viewport->mMouseX,
- viewport->mMouseY,
- mapItem);
- }
- break;
- }
- }
- }
- else if (eventButton == MouseButton::MIDDLE)
- {
- if (type == MapItemType::EMPTY && (chatWindow != nullptr))
- {
- const std::string &name = model->getAvatarAt(selected)->getName();
- const WhisperTab *const tab = chatWindow->addWhisperTab(
- name, name, true);
- if (tab != nullptr)
- chatWindow->saveState();
- }
- }
-}
-
-void AvatarListBox::mouseReleased(MouseEvent &event A_UNUSED)
-{
-}
-
-void AvatarListBox::optionChanged(const std::string &value)
-{
- if (value == "showgender")
- mShowGender = config.getBoolValue("showgender");
- else if (value == "showlevel")
- mShowLevel = config.getBoolValue("showlevel");
-}
diff --git a/src/gui/widgets/avatarlistbox.h b/src/gui/widgets/avatarlistbox.h
deleted file mode 100644
index 8af27256b..000000000
--- a/src/gui/widgets/avatarlistbox.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_AVATARLISTBOX_H
-#define GUI_WIDGETS_AVATARLISTBOX_H
-
-#include "gui/widgets/listbox.h"
-
-class AvatarListModel;
-class Image;
-
-class AvatarListBox final : public ListBox,
- public ConfigListener
-{
- public:
- AvatarListBox(const Widget2 *const widget,
- AvatarListModel *const model);
-
- A_DELETE_COPY(AvatarListBox)
-
- ~AvatarListBox();
-
- /**
- * Draws the list box.
- */
- void draw(Graphics *gcnGraphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *gcnGraphics) override final A_NONNULL(2);
-
- void mousePressed(MouseEvent &event) override final;
-
- void mouseReleased(MouseEvent &event A_UNUSED) override final A_CONST;
-
- void optionChanged(const std::string &value) override final;
-
- private:
- int mImagePadding;
- bool mShowGender;
- bool mShowLevel;
-
- static int instances;
- static Image *onlineIcon;
- static Image *offlineIcon;
-};
-
-#endif // GUI_WIDGETS_AVATARLISTBOX_H
diff --git a/src/gui/widgets/basiccontainer.cpp b/src/gui/widgets/basiccontainer.cpp
deleted file mode 100644
index 768733ae5..000000000
--- a/src/gui/widgets/basiccontainer.cpp
+++ /dev/null
@@ -1,439 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/basiccontainer.h"
-
-#include "utils/foreach.h"
-
-#include "render/graphics.h"
-
-#include <algorithm>
-
-#include "debug.h"
-
-BasicContainer::~BasicContainer()
-{
- clear();
-}
-
-void BasicContainer::moveToTop(Widget *const widget) restrict2
-{
- FOR_EACH (WidgetListIterator, iter, mWidgets)
- {
- if (*iter == widget)
- {
- mWidgets.erase(iter);
- mWidgets.push_back(widget);
- break;
- }
- }
- FOR_EACH (WidgetListIterator, iter, mLogicWidgets)
- {
- if (*iter == widget)
- {
- mLogicWidgets.erase(iter);
- mLogicWidgets.push_back(widget);
- return;
- }
- }
-}
-
-void BasicContainer::moveToBottom(Widget *const widget) restrict2
-{
- const WidgetListIterator iter = std::find(mWidgets.begin(),
- mWidgets.end(), widget);
- if (iter != mWidgets.end())
- {
- mWidgets.erase(iter);
- mWidgets.insert(mWidgets.begin(), widget);
- }
-
- const WidgetListIterator iter2 = std::find(mLogicWidgets.begin(),
- mLogicWidgets.end(), widget);
- if (iter2 != mLogicWidgets.end())
- {
- mLogicWidgets.erase(iter2);
- mLogicWidgets.insert(mLogicWidgets.begin(), widget);
- }
-}
-
-void BasicContainer::death(const Event &restrict event) restrict2
-{
- const WidgetListIterator iter = std::find(mWidgets.begin(),
- mWidgets.end(), event.getSource());
- if (iter != mWidgets.end())
- mWidgets.erase(iter);
-
- const WidgetListIterator iter2 = std::find(mLogicWidgets.begin(),
- mLogicWidgets.end(), event.getSource());
- if (iter2 != mLogicWidgets.end())
- mLogicWidgets.erase(iter2);
-}
-
-Rect BasicContainer::getChildrenArea() restrict2
-{
- return Rect(0, 0, mDimension.width, mDimension.height);
-}
-
-void BasicContainer::focusNext() restrict2
-{
- WidgetListConstIterator it;
-
- for (it = mWidgets.begin(); it != mWidgets.end(); ++ it)
- {
- if ((*it)->isFocused())
- break;
- }
-
- const WidgetListConstIterator end = it;
-
- if (it == mWidgets.end())
- it = mWidgets.begin();
-
- ++ it;
-
- for ( ; it != end; ++ it)
- {
- if (it == mWidgets.end())
- it = mWidgets.begin();
-
- if ((*it)->isFocusable())
- {
- (*it)->requestFocus();
- return;
- }
- }
-}
-
-void BasicContainer::focusPrevious() restrict2
-{
- WidgetListReverseIterator it;
-
- for (it = mWidgets.rbegin(); it != mWidgets.rend(); ++ it)
- {
- if ((*it)->isFocused())
- break;
- }
-
- const WidgetListReverseIterator end = it;
-
- ++ it;
-
- if (it == mWidgets.rend())
- it = mWidgets.rbegin();
-
- for ( ; it != end; ++ it)
- {
- if (it == mWidgets.rend())
- it = mWidgets.rbegin();
-
- if ((*it)->isFocusable())
- {
- (*it)->requestFocus();
- return;
- }
- }
-}
-
-Widget *BasicContainer::getWidgetAt(int x, int y) restrict2
-{
- const Rect r = getChildrenArea();
-
- if (!r.isPointInRect(x, y))
- return nullptr;
-
- x -= r.x;
- y -= r.y;
-
- for (WidgetListReverseIterator it = mWidgets.rbegin();
- it != mWidgets.rend(); ++ it)
- {
- const Widget *restrict const widget = *it;
- if (widget->isVisible() &&
- widget->getDimension().isPointInRect(x, y))
- {
- return *it;
- }
- }
-
- return nullptr;
-}
-
-void BasicContainer::logic() restrict2
-{
- BLOCK_START("BasicContainer::logic")
- if (mVisible == Visible_false)
- {
- BLOCK_END("BasicContainer::logic")
- return;
- }
- logicChildren();
- BLOCK_END("BasicContainer::logic")
-}
-
-void BasicContainer::setFocusHandler(FocusHandler *restrict2 const
- focusHandler) restrict2
-{
- Widget::setFocusHandler(focusHandler);
-
- if (mInternalFocusHandler != nullptr)
- return;
-
- FOR_EACH (WidgetListConstIterator, iter, mWidgets)
- (*iter)->setFocusHandler(focusHandler);
-}
-
-void BasicContainer::add(Widget *const widget) restrict2
-{
- if (widget == nullptr)
- return;
- mWidgets.push_back(widget);
- if (widget->isAllowLogic())
- mLogicWidgets.push_back(widget);
-
- if (mInternalFocusHandler == nullptr)
- widget->setFocusHandler(getFocusHandler());
- else
- widget->setFocusHandler(mInternalFocusHandler);
-
- widget->setParent(this);
- widget->addDeathListener(this);
-}
-
-void BasicContainer::remove(Widget *const restrict widget) restrict2
-{
- if (widget == nullptr)
- return;
- FOR_EACH (WidgetListIterator, iter, mWidgets)
- {
- if (*iter == widget)
- {
- mWidgets.erase(iter);
- widget->setFocusHandler(nullptr);
- widget->setWindow(nullptr);
- widget->setParent(nullptr);
- widget->removeDeathListener(this);
- break;
- }
- }
- FOR_EACH (WidgetListIterator, iter, mLogicWidgets)
- {
- if (*iter == widget)
- {
- mLogicWidgets.erase(iter);
- return;
- }
- }
-}
-
-void BasicContainer::clear() restrict2
-{
- FOR_EACH (WidgetListConstIterator, iter, mWidgets)
- {
- Widget *restrict const widget = *iter;
- widget->setFocusHandler(nullptr);
- widget->setWindow(nullptr);
- widget->setParent(nullptr);
- widget->removeDeathListener(this);
- }
-
- mWidgets.clear();
- mLogicWidgets.clear();
-}
-
-void BasicContainer::drawChildren(Graphics *const restrict graphics) restrict2
-{
- BLOCK_START("BasicContainer::drawChildren")
- graphics->pushClipArea(getChildrenArea());
-
- FOR_EACH (WidgetListConstIterator, iter, mWidgets)
- {
- Widget *restrict const widget = *iter;
- if (widget->mVisible == Visible_true)
- {
- // If the widget has a frame,
- // draw it before drawing the widget
- if (widget->mFrameSize > 0)
- {
- Rect rec = widget->mDimension;
- const int frame = CAST_S32(widget->mFrameSize);
- const int frame2 = frame * 2;
- rec.x -= frame;
- rec.y -= frame;
- rec.width += frame2;
- rec.height += frame2;
- graphics->pushClipArea(rec);
- BLOCK_START("BasicContainer::drawChildren 1")
- widget->drawFrame(graphics);
- BLOCK_END("BasicContainer::drawChildren 1")
- graphics->popClipArea();
- }
-
- graphics->pushClipArea(widget->mDimension);
- BLOCK_START("BasicContainer::drawChildren 2")
- widget->draw(graphics);
- BLOCK_END("BasicContainer::drawChildren 2")
- graphics->popClipArea();
- }
- }
-
- graphics->popClipArea();
- BLOCK_END("BasicContainer::drawChildren")
-}
-
-void BasicContainer::safeDrawChildren(Graphics *const restrict graphics)
- restrict2
-{
- BLOCK_START("BasicContainer::drawChildren")
- graphics->pushClipArea(getChildrenArea());
-
- FOR_EACH (WidgetListConstIterator, iter, mWidgets)
- {
- Widget *restrict const widget = *iter;
- if (widget->mVisible == Visible_true)
- {
- // If the widget has a frame,
- // draw it before drawing the widget
- if (widget->mFrameSize > 0)
- {
- Rect rec = widget->mDimension;
- const int frame = CAST_S32(widget->mFrameSize);
- const int frame2 = frame * 2;
- rec.x -= frame;
- rec.y -= frame;
- rec.width += frame2;
- rec.height += frame2;
- graphics->pushClipArea(rec);
- BLOCK_START("BasicContainer::drawChildren 1")
- widget->safeDrawFrame(graphics);
- BLOCK_END("BasicContainer::drawChildren 1")
- graphics->popClipArea();
- }
-
- graphics->pushClipArea(widget->mDimension);
- BLOCK_START("BasicContainer::drawChildren 2")
- widget->safeDraw(graphics);
- BLOCK_END("BasicContainer::drawChildren 2")
- graphics->popClipArea();
- }
- }
-
- graphics->popClipArea();
- BLOCK_END("BasicContainer::drawChildren")
-}
-
-void BasicContainer::logicChildren() restrict2
-{
- BLOCK_START("BasicContainer::logicChildren")
- FOR_EACH (WidgetListConstIterator, iter, mLogicWidgets)
- (*iter)->logic();
- BLOCK_END("BasicContainer::logicChildren")
-}
-
-void BasicContainer::showWidgetPart(Widget *restrict const widget,
- const Rect &restrict area) restrict2
-{
- if (widget == nullptr)
- return;
-
- const Rect widgetArea = getChildrenArea();
-
- const int x = widget->mDimension.x;
- const int y = widget->mDimension.y;
- const int ax = area.x + x;
- const int ay = area.y + y;
-
- if (ax < 0)
- widget->setX(-area.x);
- else if (ax + area.width > widgetArea.width)
- widget->setX(widgetArea.width - area.x - area.width);
-
- if (ay < 0)
- widget->setY(-area.y);
- else if (ay + area.height > widgetArea.height)
- widget->setY(widgetArea.height - area.y - area.height);
-}
-
-void BasicContainer::setInternalFocusHandler(FocusHandler *const restrict
- focusHandler) restrict2
-{
- Widget::setInternalFocusHandler(focusHandler);
-
- FocusHandler *const restrict handler = mInternalFocusHandler != nullptr ?
- mInternalFocusHandler : getFocusHandler();
- FOR_EACH (WidgetListConstIterator, iter, mWidgets)
- {
- (*iter)->setFocusHandler(handler);
- }
-}
-
-Widget *BasicContainer::findFirstWidget(const std::set<Widget*> &restrict list)
- restrict2
-{
- FOR_EACHR (WidgetListReverseIterator, iter, mWidgets)
- {
- if (list.find(*iter) != list.end())
- return *iter;
- }
- return nullptr;
-}
diff --git a/src/gui/widgets/basiccontainer.h b/src/gui/widgets/basiccontainer.h
deleted file mode 100644
index 9ab658a76..000000000
--- a/src/gui/widgets/basiccontainer.h
+++ /dev/null
@@ -1,213 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_BASICCONTAINER_H
-#define GUI_WIDGETS_BASICCONTAINER_H
-
-#include "gui/widgets/widget.h"
-
-#include "listeners/widgetdeathlistener.h"
-
-/**
- * A base class for containers. The class implements the most
- * common things for a container. If you are implementing a
- * container, consider inheriting from this class.
- *
- * @see Container
- */
-class BasicContainer notfinal : public Widget,
- public WidgetDeathListener
-{
- public:
- explicit BasicContainer(const Widget2 *restrict const widget) :
- Widget(widget),
- WidgetDeathListener(),
- mWidgets(),
- mLogicWidgets()
- { }
-
- A_DELETE_COPY(BasicContainer)
-
- /**
- * Destructor
- */
- virtual ~BasicContainer();
-
- /**
- * Shows a certain part of a widget in the basic container.
- * Used when widgets want a specific part to be visible in
- * its parent. An example is a TextArea that wants a specific
- * part of its text to be visible when a TextArea is a child
- * of a ScrollArea.
- *
- * @param widget The widget whom wants a specific part of
- * itself to be visible.
- * @param area The rectangle to be visible.
- */
- void showWidgetPart(Widget *restrict const widget,
- const Rect &restrict area) restrict2 override;
-
- // Inherited from Widget
-
- void moveToTop(Widget *const widget) restrict2 override;
-
- void moveToBottom(Widget *const widget) restrict2 override;
-
- Rect getChildrenArea() restrict2 override A_WARN_UNUSED;
-
- void focusNext() restrict2 override;
-
- void focusPrevious() restrict2 override;
-
- void logic() restrict2 override;
-
- void setFocusHandler(FocusHandler *restrict const focusHandler)
- restrict2 override;
-
- void setInternalFocusHandler(FocusHandler *const restrict focusHandler)
- restrict2;
-
- Widget *getWidgetAt(int x, int y) restrict2 override A_WARN_UNUSED;
-
- // Inherited from WidgetDeathListener
-
- void death(const Event &restrict event) restrict2 override;
-
- Widget *findFirstWidget(const std::set<Widget*> &restrict list)
- restrict2;
-
- /**
- * Adds a widget to the basic container.
- *
- * @param widget The widget to add.
- * @see remove, clear
- */
- void add(Widget *const widget) restrict2;
-
- /**
- * Removes a widget from the basic container.
- *
- * @param widget The widget to remove.
- * @see add, clear
- */
- virtual void remove(Widget *const restrict widget) restrict2;
-
- /**
- * Clears the basic container from all widgets.
- *
- * @see remove, clear
- */
- virtual void clear() restrict2;
-
- protected:
- /**
- * Draws the children widgets of the basic container.
- *
- * @param graphics A graphics object to draw with.
- */
- virtual void drawChildren(Graphics *const restrict graphics)
- restrict2 A_NONNULL(2);
-
- virtual void safeDrawChildren(Graphics *const restrict graphics)
- restrict2 A_NONNULL(2);
-
- /**
- * Calls logic for the children widgets of the basic
- * container.
- */
- virtual void logicChildren() restrict2;
-
- /**
- * Typedef.
- */
- typedef STD_VECTOR<Widget *> WidgetList;
-
- /**
- * Typedef.
- */
- typedef WidgetList::iterator WidgetListIterator;
-
- /**
- * Typedef.
- */
- typedef WidgetList::const_iterator WidgetListConstIterator;
-
- /**
- * Typedef.
- */
- typedef WidgetList::reverse_iterator WidgetListReverseIterator;
-
- /**
- * Typedef.
- */
- typedef WidgetList::const_reverse_iterator WidgetListCReverseIterator;
-
- /**
- * Holds all widgets of the basic container.
- */
- WidgetList mWidgets;
-
- WidgetList mLogicWidgets;
-};
-
-#endif // GUI_WIDGETS_BASICCONTAINER_H
diff --git a/src/gui/widgets/basiccontainer2.cpp b/src/gui/widgets/basiccontainer2.cpp
deleted file mode 100644
index ad143010d..000000000
--- a/src/gui/widgets/basiccontainer2.cpp
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * For comments regarding functions please see the header file.
- */
-
-#include "gui/widgets/basiccontainer2.h"
-
-#include "render/graphics.h"
-
-#include "debug.h"
-
-BasicContainer2::BasicContainer2(const Widget2 *const widget) :
- BasicContainer(widget),
- mOpaque(Opaque_true)
-{
-}
-
-BasicContainer2::~BasicContainer2()
-{
-}
-
-void BasicContainer2::draw(Graphics *const graphics)
-{
- BLOCK_START("BasicContainer2::draw")
- if (mOpaque == Opaque_true)
- {
- graphics->setColor(mBaseColor);
- graphics->fillRectangle(Rect(0, 0,
- mDimension.width, mDimension.height));
- }
-
- drawChildren(graphics);
- BLOCK_END("BasicContainer2::draw")
-}
-
-void BasicContainer2::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("BasicContainer2::draw")
- if (mOpaque == Opaque_true)
- {
- graphics->setColor(mBaseColor);
- graphics->fillRectangle(Rect(0, 0,
- mDimension.width, mDimension.height));
- }
-
- safeDrawChildren(graphics);
- BLOCK_END("BasicContainer2::draw")
-}
-
-void BasicContainer2::add(Widget *const widget)
-{
- // +++ need move all add() calls from constructors
- // and after this method can be deleted
- // and virtual moved to basiccontainer
- BasicContainer::add(widget);
-}
-
-void BasicContainer2::addXY(Widget *const widget,
- const int x,
- const int y)
-{
- if (widget == nullptr)
- return;
- widget->setPosition(x, y);
- BasicContainer::add(widget);
-}
diff --git a/src/gui/widgets/basiccontainer2.h b/src/gui/widgets/basiccontainer2.h
deleted file mode 100644
index e26923d74..000000000
--- a/src/gui/widgets/basiccontainer2.h
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_BASICCONTAINER2_H
-#define GUI_WIDGETS_BASICCONTAINER2_H
-
-#include "gui/widgets/basiccontainer.h"
-
-#include "enums/simpletypes/opaque.h"
-
-/**
- * An implementation of a container able to contain other widgets. A widget's
- * position in the container is relative to the container itself and not the screen.
- * A container is the most common widget to use as the Gui's top widget as makes the Gui
- * able to contain more than one widget.
- *
- * @see Gui::setTop
- */
-class BasicContainer2: public BasicContainer
-{
- public:
- /**
- * Constructor. A container is opauqe as default, if you want a
- * none opaque container call setQpaque(false).
- *
- * @see setOpaque, isOpaque
- */
- explicit BasicContainer2(const Widget2 *const widget);
-
- /**
- * Destructor.
- */
- virtual ~BasicContainer2();
-
- /**
- * Sets the container to be opaque or not. If the container
- * is opaque its background will be drawn, if it's not opaque
- * its background will not be drawn, and thus making the container
- * completely transparent.
- *
- * NOTE: This is not the same as to set visibility. A non visible
- * container will not itself nor will it draw its content.
- *
- * @param opaque True if the container should be opaque, false otherwise.
- * @see isOpaque
- */
- void setOpaque(Opaque opaque)
- { mOpaque = opaque; }
-
- /**
- * Checks if the container is opaque or not.
- *
- * @return True if the container is opaque, false otherwise.
- * @see setOpaque
- */
- bool isOpaque() const
- { return mOpaque == Opaque_true; }
-
- /**
- * Adds a widget to the container.
- *
- * @param widget The widget to add.
- * @see remove, clear
- */
- virtual void add(Widget *const widget);
-
- /**
- * Adds a widget to the container and also specifies the widget's
- * position in the container. The position is relative to the container
- * and not relative to the screen.
- *
- * @param widget The widget to add.
- * @param x The x coordinate for the widget.
- * @param y The y coordinate for the widget.
- * @see remove, clear
- */
- void addXY(Widget *const widget,
- const int x, const int y);
-
- // Inherited from Widget
-
- void draw(Graphics *const graphics) override A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override A_NONNULL(2);
-
- protected:
- /**
- * True if the container is opaque, false otherwise.
- */
- Opaque mOpaque;
-};
-
-#endif // GUI_WIDGETS_BASICCONTAINER2_H
diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp
deleted file mode 100644
index 6d65a11cb..000000000
--- a/src/gui/widgets/browserbox.cpp
+++ /dev/null
@@ -1,936 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- * Copyright (C) 2009 Aethyra Development Team
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/browserbox.h"
-
-#include "enums/gui/linkhighlightmode.h"
-
-#include "gui/gui.h"
-#include "gui/mouseoverlink.h"
-#include "gui/skin.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/widgets/browserbox.inc"
-#include "gui/widgets/linkhandler.h"
-
-#include "render/graphics.h"
-
-#include "resources/imageset.h"
-
-#include "resources/image/image.h"
-
-#include "resources/loaders/imageloader.h"
-#include "resources/loaders/imagesetloader.h"
-
-#include "utils/browserboxtools.h"
-#include "utils/checkutils.h"
-#include "utils/foreach.h"
-#include "utils/stringutils.h"
-#include "utils/timer.h"
-#include "utils/translation/podict.h"
-
-#include <algorithm>
-
-#include "debug.h"
-
-ImageSet *BrowserBox::mEmotes = nullptr;
-int BrowserBox::mInstances = 0;
-
-BrowserBox::BrowserBox(const Widget2 *const widget,
- const Opaque opaque,
- const std::string &skin) :
- Widget(widget),
- MouseListener(),
- WidgetListener(),
- mTextRows(),
- mTextRowLinksCount(),
- mLineParts(),
- mLinks(),
- mLinkHandler(nullptr),
- mSkin(nullptr),
- mHighlightMode(0),
- mSelectedLink(-1),
- mMaxRows(0),
- mHeight(0),
- mWidth(0),
- mYStart(0),
- mUpdateTime(-1),
- mPadding(0),
- mNewLinePadding(15U),
- mItemPadding(0),
- mDataWidth(0),
- mHighlightColor(getThemeColor(ThemeColorId::HIGHLIGHT)),
- mHyperLinkColor(getThemeColor(ThemeColorId::HYPERLINK)),
- mOpaque(opaque),
- mUseLinksAndUserColors(true),
- mUseEmotes(true),
- mAlwaysUpdate(true),
- mProcessVars(false),
- mEnableImages(false),
- mEnableKeys(false),
- mEnableTabs(false)
-{
- mAllowLogic = false;
-
- setFocusable(true);
- addMouseListener(this);
- addWidgetListener(this);
-
- mBackgroundColor = getThemeColor(ThemeColorId::BACKGROUND);
-
- if (theme != nullptr)
- mSkin = theme->load(skin, "browserbox.xml");
- if (mInstances == 0)
- {
- mEmotes = Loader::getImageSet(
- "graphics/sprites/chatemotes.png", 17, 18);
- }
- mInstances ++;
-
- if (mSkin != nullptr)
- {
- mPadding = mSkin->getPadding();
- mNewLinePadding = CAST_U32(
- mSkin->getOption("newLinePadding", 15));
- mItemPadding = mSkin->getOption("itemPadding");
- if (mSkin->getOption("highlightBackground") != 0)
- mHighlightMode |= LinkHighlightMode::BACKGROUND;
- if (mSkin->getOption("highlightUnderline") != 0)
- mHighlightMode |= LinkHighlightMode::UNDERLINE;
- }
-
- readColor(BLACK);
- readColor(RED);
- readColor(GREEN);
- readColor(BLUE);
- readColor(ORANGE);
- readColor(YELLOW);
- readColor(PINK);
- readColor(PURPLE);
- readColor(GRAY);
- readColor(BROWN);
-
- mForegroundColor = getThemeColor(ThemeColorId::BROWSERBOX);
- mForegroundColor2 = getThemeColor(ThemeColorId::BROWSERBOX_OUTLINE);
-}
-
-BrowserBox::~BrowserBox()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- if (theme != nullptr)
- {
- theme->unload(mSkin);
- mSkin = nullptr;
- }
-
- mInstances --;
- if (mInstances == 0)
- {
- if (mEmotes != nullptr)
- {
- mEmotes->decRef();
- mEmotes = nullptr;
- }
- }
-}
-
-void BrowserBox::setLinkHandler(LinkHandler* linkHandler)
-{
- mLinkHandler = linkHandler;
-}
-
-void BrowserBox::addRow(const std::string &row, const bool atTop)
-{
- std::string tmp = row;
- std::string newRow;
- const Font *const font = getFont();
- int linksCount = 0;
-
- if (getWidth() < 0)
- return;
-
- if (mProcessVars)
- {
- BrowserBoxTools::replaceVars(tmp);
- }
-
- // Use links and user defined colors
- if (mUseLinksAndUserColors)
- {
- BrowserLink bLink;
-
- // Check for links in format "@@link|Caption@@"
- const uint32_t sz = CAST_U32(mTextRows.size());
-
- if (mEnableKeys)
- {
- BrowserBoxTools::replaceKeys(tmp);
- }
-
- size_t idx1 = tmp.find("@@");
- while (idx1 != std::string::npos)
- {
- const size_t idx2 = tmp.find('|', idx1);
- const size_t idx3 = tmp.find("@@", idx2);
-
- if (idx2 == std::string::npos || idx3 == std::string::npos)
- break;
- bLink.link = tmp.substr(idx1 + 2, idx2 - (idx1 + 2));
- bLink.caption = tmp.substr(idx2 + 1, idx3 - (idx2 + 1));
- bLink.y1 = CAST_S32(sz) * font->getHeight();
- bLink.y2 = bLink.y1 + font->getHeight();
- if (bLink.caption.empty())
- {
- bLink.caption = BrowserBoxTools::replaceLinkCommands(
- bLink.link);
- if (translator != nullptr)
- bLink.caption = translator->getStr(bLink.caption);
- }
-
- newRow.append(tmp.substr(0, idx1));
-
- std::string tmp2 = newRow;
- idx1 = tmp2.find("##");
- while (idx1 != std::string::npos)
- {
- tmp2.erase(idx1, 3);
- idx1 = tmp2.find("##");
- }
- bLink.x1 = font->getWidth(tmp2) - 1;
- bLink.x2 = bLink.x1 + font->getWidth(bLink.caption) + 1;
-
- if (atTop)
- mLinks.insert(mLinks.begin(), bLink);
- else
- mLinks.push_back(bLink);
- linksCount ++;
-
- newRow.append("##<").append(bLink.caption);
-
- tmp.erase(0, idx3 + 2);
- if (!tmp.empty())
- newRow.append("##>");
-
- idx1 = tmp.find("@@");
- }
-
- newRow.append(tmp);
- }
- // Don't use links and user defined colors
- else
- {
- newRow = row;
- }
-
- if (mEnableTabs)
- {
- BrowserBoxTools::replaceTabs(newRow);
- }
-
- if (atTop)
- {
- mTextRows.push_front(newRow);
- mTextRowLinksCount.push_front(linksCount);
- }
- else
- {
- mTextRows.push_back(newRow);
- mTextRowLinksCount.push_back(linksCount);
- }
-
- // discard older rows when a row limit has been set
- if (mMaxRows > 0 && !mTextRows.empty())
- {
- while (mTextRows.size() > CAST_SIZE(mMaxRows))
- {
- mTextRows.pop_front();
- int cnt = mTextRowLinksCount.front();
- mTextRowLinksCount.pop_front();
-
- while ((cnt != 0) && !mLinks.empty())
- {
- mLinks.erase(mLinks.begin());
- cnt --;
- }
- }
- }
-
- const int fontHeight = font->getHeight();
- unsigned int y = 0;
- unsigned int nextChar;
- const char *const hyphen = "~";
- const unsigned int hyphenWidth = CAST_U32(
- font->getWidth(hyphen));
- unsigned int x = 0;
-
- FOR_EACH (TextRowCIter, i, mTextRows)
- {
- std::string tempRow = *i;
- for (uint32_t j = 0, sz = CAST_U32(tempRow.size());
- j < sz;
- j++)
- {
- const std::string character = tempRow.substr(j, 1);
- x += CAST_U32(font->getWidth(character));
- nextChar = j + 1;
-
- // Wraping between words (at blank spaces)
- if (nextChar < sz && tempRow.at(nextChar) == ' ')
- {
- int nextSpacePos = CAST_U32(
- tempRow.find(' ', (nextChar + 1)));
- if (nextSpacePos <= 0)
- nextSpacePos = CAST_U32(sz) - 1U;
-
- const unsigned int nextWordWidth =
- CAST_U32(font->getWidth(
- tempRow.substr(nextChar,
- (CAST_U32(nextSpacePos) - nextChar))));
-
- if ((x + nextWordWidth + 10)
- > CAST_U32(getWidth()))
- {
- x = mNewLinePadding; // Ident in new line
- y += 1;
- j ++;
- }
- }
- // Wrapping looong lines (brutal force)
- else if ((x + 2 * hyphenWidth)
- > CAST_U32(getWidth()))
- {
- x = mNewLinePadding; // Ident in new line
- y += 1;
- }
- }
- }
-
- setHeight(fontHeight * (CAST_S32(
- CAST_U32(mTextRows.size()) + y)));
- mUpdateTime = 0;
- updateHeight();
-}
-
-void BrowserBox::addRow(const std::string &cmd, const char *const text)
-{
- addRow(strprintf("@@%s|%s@@", encodeLinkText(cmd).c_str(),
- encodeLinkText(text).c_str()));
-}
-
-void BrowserBox::addImage(const std::string &path)
-{
- if (!mEnableImages)
- return;
-
- mTextRows.push_back("~~~" + path);
- mTextRowLinksCount.push_back(0);
-}
-
-void BrowserBox::clearRows()
-{
- mTextRows.clear();
- mTextRowLinksCount.clear();
- mLinks.clear();
- setWidth(0);
- setHeight(0);
- mSelectedLink = -1;
- mUpdateTime = 0;
- mDataWidth = 0;
- updateHeight();
-}
-
-void BrowserBox::mousePressed(MouseEvent &event)
-{
- if (mLinkHandler == nullptr)
- return;
-
- const LinkIterator i = std::find_if(mLinks.begin(), mLinks.end(),
- MouseOverLink(event.getX(), event.getY()));
-
- if (i != mLinks.end())
- {
- mLinkHandler->handleLink(i->link, &event);
- event.consume();
- }
-}
-
-void BrowserBox::mouseMoved(MouseEvent &event)
-{
- const LinkIterator i = std::find_if(mLinks.begin(), mLinks.end(),
- MouseOverLink(event.getX(), event.getY()));
-
- mSelectedLink = (i != mLinks.end())
- ? CAST_S32(i - mLinks.begin()) : -1;
-}
-
-void BrowserBox::mouseExited(MouseEvent &event A_UNUSED)
-{
- mSelectedLink = -1;
-}
-
-void BrowserBox::draw(Graphics *const graphics)
-{
- BLOCK_START("BrowserBox::draw")
- const ClipRect &cr = graphics->getTopClip();
- mYStart = cr.y - cr.yOffset;
- const int yEnd = mYStart + cr.height;
- if (mYStart < 0)
- mYStart = 0;
-
- if (mDimension.width != mWidth)
- {
- mWidth = mDimension.width;
- mHeight = calcHeight();
- setHeight(mHeight);
- mUpdateTime = cur_time;
- if (mDimension.width != mWidth)
- reportAlways("browserbox resize in draw");
- }
-
- if (mOpaque == Opaque_true)
- {
- graphics->setColor(mBackgroundColor);
- graphics->fillRectangle(Rect(0, 0,
- mDimension.width, mDimension.height));
- }
-
- if (mSelectedLink >= 0 &&
- mSelectedLink < CAST_S32(mLinks.size()))
- {
- if ((mHighlightMode & LinkHighlightMode::BACKGROUND) != 0u)
- {
- BrowserLink &link = mLinks[CAST_SIZE(mSelectedLink)];
- graphics->setColor(mHighlightColor);
- graphics->fillRectangle(Rect(
- link.x1,
- link.y1,
- link.x2 - link.x1,
- link.y2 - link.y1));
- }
-
- if ((mHighlightMode & LinkHighlightMode::UNDERLINE) != 0u)
- {
- BrowserLink &link = mLinks[CAST_SIZE(mSelectedLink)];
- graphics->setColor(mHyperLinkColor);
- graphics->drawLine(
- link.x1,
- link.y2,
- link.x2,
- link.y2);
- }
- }
-
- Font *const font = getFont();
-
- FOR_EACH (LinePartCIter, i, mLineParts)
- {
- const LinePart &part = *i;
- if (part.mY + 50 < mYStart)
- continue;
- if (part.mY > yEnd)
- break;
- if (part.mType == 0u)
- {
- if (part.mBold)
- {
- boldFont->drawString(graphics,
- part.mColor,
- part.mColor2,
- part.mText,
- part.mX, part.mY);
- }
- else
- {
- font->drawString(graphics,
- part.mColor,
- part.mColor2,
- part.mText,
- part.mX, part.mY);
- }
- }
- else if (part.mImage != nullptr)
- {
- graphics->drawImage(part.mImage, part.mX, part.mY);
- }
- }
-
- BLOCK_END("BrowserBox::draw")
-}
-
-void BrowserBox::safeDraw(Graphics *const graphics)
-{
- BrowserBox::draw(graphics);
-}
-
-int BrowserBox::calcHeight()
-{
- unsigned int y = CAST_U32(mPadding);
- int wrappedLines = 0;
- int moreHeight = 0;
- int maxWidth = mDimension.width - mPadding;
- int link = 0;
- bool bold = false;
- unsigned int wWidth = CAST_U32(maxWidth);
-
- if (maxWidth < 0)
- return 1;
-
- const Font *const font = getFont();
- const int fontHeight = font->getHeight() + 2 * mItemPadding;
- const int fontWidthMinus = font->getWidth("-");
- const char *const hyphen = "~";
- const int hyphenWidth = font->getWidth(hyphen);
-
- Color selColor[2] = {mForegroundColor, mForegroundColor2};
- const Color textColor[2] = {mForegroundColor, mForegroundColor2};
- mLineParts.clear();
-
- FOR_EACH (TextRowCIter, i, mTextRows)
- {
- unsigned int x = CAST_U32(mPadding);
- const std::string row = *(i);
- bool wrapped = false;
- int objects = 0;
-
- // Check for separator lines
- if (row.find("---", 0) == 0)
- {
- const int dashWidth = fontWidthMinus;
- for (x = CAST_U32(mPadding); x < wWidth; x ++)
- {
- mLineParts.push_back(LinePart(CAST_S32(x),
- CAST_S32(y) + mItemPadding,
- selColor[0], selColor[1], "-", false));
- x += CAST_U32(CAST_S32(
- dashWidth) - 2);
- }
-
- y += CAST_U32(fontHeight);
- continue;
- }
- else if (mEnableImages && row.find("~~~", 0) == 0)
- {
- std::string str = row.substr(3);
- const size_t sz = str.size();
- if (sz > 2 && str.substr(sz - 1) == "~")
- str = str.substr(0, sz - 1);
- Image *const img = Loader::getImage(str);
- if (img != nullptr)
- {
- img->incRef();
- mLineParts.push_back(LinePart(CAST_S32(x),
- CAST_S32(y) + mItemPadding,
- selColor[0], selColor[1], img));
- y += CAST_U32(img->getHeight() + 2);
- moreHeight += img->getHeight();
- if (img->getWidth() > maxWidth)
- maxWidth = img->getWidth() + 2;
- }
- continue;
- }
-
- Color prevColor[2];
- prevColor[0] = selColor[0];
- prevColor[1] = selColor[1];
- bold = false;
-
- const int xPadding = CAST_S32(mNewLinePadding) + mPadding;
-
- for (size_t start = 0, end = std::string::npos;
- start != std::string::npos;
- start = end, end = std::string::npos)
- {
- bool processed(false);
-
- // Wrapped line continuation shall be indented
- if (wrapped)
- {
- y += CAST_U32(fontHeight);
- x = CAST_U32(xPadding);
- wrapped = false;
- }
-
- size_t idx1 = end;
- size_t idx2 = end;
-
- // "Tokenize" the string at control sequences
- if (mUseLinksAndUserColors)
- idx1 = row.find("##", start + 1);
- if (start == 0 || mUseLinksAndUserColors)
- {
- // Check for color change in format "##x", x = [L,P,0..9]
- if (row.find("##", start) == start && row.size() > start + 2)
- {
- const signed char c = row.at(start + 2);
-
- bool valid(false);
- const Color col[2] =
- {
- getThemeCharColor(c, valid),
- getThemeCharColor(CAST_S8(
- c | 0x80), valid)
- };
-
- if (c == '>')
- {
- selColor[0] = prevColor[0];
- selColor[1] = prevColor[1];
- }
- else if (c == '<')
- {
- prevColor[0] = selColor[0];
- prevColor[1] = selColor[1];
- selColor[0] = col[0];
- selColor[1] = col[1];
- }
- else if (c == 'B')
- {
- bold = true;
- }
- else if (c == 'b')
- {
- bold = false;
- }
- else if (valid)
- {
- selColor[0] = col[0];
- selColor[1] = col[1];
- }
- else
- {
- switch (c)
- {
- case '0':
- selColor[0] = mColors[0][ColorName::BLACK];
- selColor[1] = mColors[1][ColorName::BLACK];
- break;
- case '1':
- selColor[0] = mColors[0][ColorName::RED];
- selColor[1] = mColors[1][ColorName::RED];
- break;
- case '2':
- selColor[0] = mColors[0][ColorName::GREEN];
- selColor[1] = mColors[1][ColorName::GREEN];
- break;
- case '3':
- selColor[0] = mColors[0][ColorName::BLUE];
- selColor[1] = mColors[1][ColorName::BLUE];
- break;
- case '4':
- selColor[0] = mColors[0][ColorName::ORANGE];
- selColor[1] = mColors[1][ColorName::ORANGE];
- break;
- case '5':
- selColor[0] = mColors[0][ColorName::YELLOW];
- selColor[1] = mColors[1][ColorName::YELLOW];
- break;
- case '6':
- selColor[0] = mColors[0][ColorName::PINK];
- selColor[1] = mColors[1][ColorName::PINK];
- break;
- case '7':
- selColor[0] = mColors[0][ColorName::PURPLE];
- selColor[1] = mColors[1][ColorName::PURPLE];
- break;
- case '8':
- selColor[0] = mColors[0][ColorName::GRAY];
- selColor[1] = mColors[1][ColorName::GRAY];
- break;
- case '9':
- selColor[0] = mColors[0][ColorName::BROWN];
- selColor[1] = mColors[1][ColorName::BROWN];
- break;
- default:
- selColor[0] = textColor[0];
- selColor[1] = textColor[1];
- break;
- }
- }
-
- if (c == '<' && link < CAST_S32(mLinks.size()))
- {
- int size;
- if (bold)
- {
- size = boldFont->getWidth(
- mLinks[CAST_SIZE(link)].caption) + 1;
- }
- else
- {
- size = font->getWidth(
- mLinks[CAST_SIZE(link)].caption) + 1;
- }
-
- BrowserLink &linkRef = mLinks[CAST_SIZE(
- link)];
- linkRef.x1 = CAST_S32(x);
- linkRef.y1 = CAST_S32(y);
- linkRef.x2 = linkRef.x1 + size;
- linkRef.y2 = CAST_S32(y) + fontHeight - 1;
- link++;
- }
-
- processed = true;
- start += 3;
- if (start == row.size())
- break;
- }
- }
- if (mUseEmotes)
- idx2 = row.find("%%", start + 1);
- if (idx1 < idx2)
- end = idx1;
- else
- end = idx2;
- if (mUseEmotes)
- {
- // check for emote icons
- if (row.size() > start + 2 && row.substr(start, 2) == "%%")
- {
- if (objects < 5)
- {
- const int cid = row.at(start + 2) - '0';
- if (cid >= 0)
- {
- if (mEmotes != nullptr)
- {
- const size_t sz = mEmotes->size();
- if (CAST_SIZE(cid) < sz)
- {
- Image *const img = mEmotes->get(
- CAST_SIZE(cid));
- if (img != nullptr)
- {
- mLineParts.push_back(LinePart(
- CAST_S32(x),
- CAST_S32(y) + mItemPadding,
- selColor[0], selColor[1], img));
- x += 18;
- }
- }
- }
- }
- objects ++;
- processed = true;
- }
-
- start += 3;
- if (start == row.size())
- {
- if (x > mDataWidth)
- mDataWidth = x;
- break;
- }
- }
- }
- const size_t len = (end == std::string::npos) ? end : end - start;
-
- if (start >= row.length())
- break;
-
- std::string part = row.substr(start, len);
- int width = 0;
- if (bold)
- width = boldFont->getWidth(part);
- else
- width = font->getWidth(part);
-
- // Auto wrap mode
- if (wWidth > 0 &&
- width > 0 &&
- (x + CAST_U32(width) + 10) > wWidth)
- {
- bool forced = false;
-
- /* FIXME: This code layout makes it easy to crash remote
- clients by talking garbage. Forged long utf-8 characters
- will cause either a buffer underflow in substr or an
- infinite loop in the main loop. */
- do
- {
- if (!forced)
- end = row.rfind(' ', end);
-
- // Check if we have to (stupidly) force-wrap
- if (end == std::string::npos || end <= start)
- {
- forced = true;
- end = row.size();
- x += CAST_U32(hyphenWidth);
- continue;
- }
-
- // Skip to the start of the current character
- while ((row[end] & 192) == 128)
- end--;
- end--; // And then to the last byte of the previous one
-
- part = row.substr(start, end - start + 1);
- if (bold)
- width = boldFont->getWidth(part);
- else
- width = font->getWidth(part);
- }
- while (end > start &&
- width > 0 &&
- (x + CAST_U32(width) + 10) > wWidth);
-
- if (forced)
- {
- x -= CAST_U32(hyphenWidth);
- mLineParts.push_back(LinePart(
- CAST_S32(wWidth) - hyphenWidth,
- CAST_S32(y) + mItemPadding,
- selColor[0], selColor[1], hyphen, bold));
- end++; // Skip to the next character
- }
- else
- {
- end += 2; // Skip to after the space
- }
-
- wrapped = true;
- wrappedLines++;
- }
-
- mLineParts.push_back(LinePart(CAST_S32(x),
- CAST_S32(y) + mItemPadding,
- selColor[0], selColor[1], part.c_str(), bold));
-
- if (bold)
- width = boldFont->getWidth(part);
- else
- width = font->getWidth(part);
-
- if (width == 0 && !processed)
- break;
-
- x += CAST_U32(width);
- if (x > mDataWidth)
- mDataWidth = x;
- }
- y += CAST_U32(fontHeight);
- }
- if (CAST_S32(wWidth) != maxWidth)
- setWidth(maxWidth);
-
- return (CAST_S32(mTextRows.size()) + wrappedLines)
- * fontHeight + moreHeight + 2 * mPadding;
-}
-
-void BrowserBox::updateHeight()
-{
- if (mAlwaysUpdate || mUpdateTime != cur_time
- || mTextRows.size() < 3 || (mUpdateTime == 0))
- {
- mWidth = mDimension.width;
- mHeight = calcHeight();
- setHeight(mHeight);
- mUpdateTime = cur_time;
- }
-}
-
-void BrowserBox::updateSize(const bool always)
-{
- if (always)
- mUpdateTime = 0;
- updateHeight();
-}
-
-std::string BrowserBox::getTextAtPos(const int x, const int y) const
-{
- int textX = 0;
- int textY = 0;
-
- getAbsolutePosition(textX, textY);
- if (x < textX || y < textY)
- return std::string();
-
- textY = y - textY;
- std::string str;
- int lastY = 0;
-
- FOR_EACH (LinePartCIter, i, mLineParts)
- {
- const LinePart &part = *i;
- if (part.mY + 50 < mYStart)
- continue;
- if (part.mY > textY)
- break;
-
- if (part.mY > lastY)
- {
- str = part.mText;
- lastY = part.mY;
- }
- else
- {
- str.append(part.mText);
- }
- }
-
- return str;
-}
-
-void BrowserBox::setForegroundColorAll(const Color &color1,
- const Color &color2)
-{
- mForegroundColor = color1;
- mForegroundColor2 = color2;
-}
-
-void BrowserBox::moveSelectionUp()
-{
- if (mSelectedLink <= 0)
- mSelectedLink = CAST_S32(mLinks.size()) - 1;
- else
- mSelectedLink --;
-}
-
-void BrowserBox::moveSelectionDown()
-{
- mSelectedLink ++;
- if (mSelectedLink >= static_cast<signed int>(mLinks.size()))
- mSelectedLink = 0;
-}
-
-void BrowserBox::selectSelection()
-{
- if ((mLinkHandler == nullptr) ||
- mSelectedLink < 0 ||
- mSelectedLink >= static_cast<signed int>(mLinks.size()))
- {
- return;
- }
-
- mLinkHandler->handleLink(mLinks[CAST_SIZE(mSelectedLink)].link,
- nullptr);
-}
-
-void BrowserBox::widgetResized(const Event &event A_UNUSED)
-{
- updateHeight();
-}
diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h
deleted file mode 100644
index 45502ba5a..000000000
--- a/src/gui/widgets/browserbox.h
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- * Copyright (C) 2009 Aethyra Development Team
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_BROWSERBOX_H
-#define GUI_WIDGETS_BROWSERBOX_H
-
-#include "enums/simpletypes/opaque.h"
-
-#include "enums/gui/colorname.h"
-
-#include "gui/browserlink.h"
-
-#include "gui/widgets/linepart.h"
-#include "gui/widgets/widget.h"
-
-#include "listeners/mouselistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "localconsts.h"
-
-class LinkHandler;
-
-/**
- * A simple browser box able to handle links and forward events to the
- * parent conteiner.
- */
-class BrowserBox final : public Widget,
- public MouseListener,
- public WidgetListener
-{
- public:
- /**
- * Constructor.
- */
- BrowserBox(const Widget2 *const widget,
- const Opaque opaque,
- const std::string &skin);
-
- A_DELETE_COPY(BrowserBox)
-
- /**
- * Destructor.
- */
- ~BrowserBox();
-
- /**
- * Sets the handler for links.
- */
- void setLinkHandler(LinkHandler *linkHandler);
-
- /**
- * Sets the BrowserBox opacity.
- */
- void setOpaque(Opaque opaque)
- { mOpaque = opaque; }
-
- /**
- * Sets the maximum numbers of rows in the browser box. 0 = no limit.
- */
- void setMaxRow(unsigned max)
- { mMaxRows = max; }
-
- /**
- * Adds a text row to the browser.
- */
- void addRow(const std::string &row, const bool atTop = false);
-
- /**
- * Adds a menu line to the browser.
- */
- void addRow(const std::string &cmd, const char *const text);
-
- void addImage(const std::string &path);
-
- /**
- * Remove all rows.
- */
- void clearRows();
-
- /**
- * Handles mouse actions.
- */
- void mousePressed(MouseEvent &event) override final;
-
- void mouseMoved(MouseEvent &event) override final;
-
- void mouseExited(MouseEvent& event) override final;
-
- /**
- * Draws the browser box.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void updateHeight();
-
- void updateSize(const bool always);
-
- typedef std::list<std::string> TextRows;
-
- TextRows &getRows() noexcept2 A_WARN_UNUSED
- { return mTextRows; }
-
- bool hasRows() const noexcept2 A_WARN_UNUSED
- { return !mTextRows.empty(); }
-
- void setAlwaysUpdate(const bool n) noexcept2
- { mAlwaysUpdate = n; }
-
- void setProcessVars(const bool n) noexcept2
- { mProcessVars = n; }
-
- void setEnableImages(const bool n) noexcept2
- { mEnableImages = n; }
-
- void setEnableKeys(const bool n) noexcept2
- { mEnableKeys = n; }
-
- void setEnableTabs(const bool n) noexcept2
- { mEnableTabs = n; }
-
- std::string getTextAtPos(const int x, const int y) const A_WARN_UNUSED;
-
- int getPadding() const noexcept2 A_WARN_UNUSED
- { return mPadding; }
-
- void setForegroundColorAll(const Color &color1,
- const Color &color2);
-
- unsigned int getDataWidth() const noexcept2 A_WARN_UNUSED
- { return mDataWidth; }
-
- void moveSelectionUp();
-
- void moveSelectionDown();
-
- void selectSelection();
-
- void widgetResized(const Event &event) override final;
-
- private:
- int calcHeight() A_WARN_UNUSED;
-
- typedef TextRows::iterator TextRowIterator;
- typedef TextRows::const_iterator TextRowCIter;
- TextRows mTextRows;
- std::list<int> mTextRowLinksCount;
-
- typedef STD_VECTOR<LinePart> LinePartList;
- typedef LinePartList::iterator LinePartIterator;
- typedef LinePartList::const_iterator LinePartCIter;
- LinePartList mLineParts;
-
- typedef STD_VECTOR<BrowserLink> Links;
- typedef Links::iterator LinkIterator;
- Links mLinks;
-
- LinkHandler *mLinkHandler;
- Skin *mSkin;
- unsigned int mHighlightMode;
- int mSelectedLink;
- unsigned int mMaxRows;
- int mHeight;
- int mWidth;
- int mYStart;
- time_t mUpdateTime;
- int mPadding;
- unsigned int mNewLinePadding;
- int mItemPadding;
- unsigned int mDataWidth;
-
- Color mHighlightColor;
- Color mHyperLinkColor;
- Color mColors[2][ColorName::COLORS_MAX];
-
- Opaque mOpaque;
- bool mUseLinksAndUserColors;
- bool mUseEmotes;
- bool mAlwaysUpdate;
- bool mProcessVars;
- bool mEnableImages;
- bool mEnableKeys;
- bool mEnableTabs;
-
- static ImageSet *mEmotes;
- static int mInstances;
-};
-
-#endif // GUI_WIDGETS_BROWSERBOX_H
diff --git a/src/gui/widgets/browserbox.inc b/src/gui/widgets/browserbox.inc
deleted file mode 100644
index 25c8744c0..000000000
--- a/src/gui/widgets/browserbox.inc
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_BROWSERBOX_INC
-#define GUI_WIDGETS_BROWSERBOX_INC
-
-#define readColor(color) \
- mColors[0][ColorName::color] = getThemeColor(ThemeColorId::color); \
- mColors[1][ColorName::color] = getThemeColor(ThemeColorId::color##_OUTLINE)
-
-#endif // GUI_WIDGETS_BROWSERBOX_INC
diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp
deleted file mode 100644
index 0c2600583..000000000
--- a/src/gui/widgets/button.cpp
+++ /dev/null
@@ -1,934 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/button.h"
-
-#include "settings.h"
-
-#include "resources/imageset.h"
-#include "resources/imagerect.h"
-
-#include "resources/image/image.h"
-
-#include "gui/gui.h"
-#include "gui/skin.h"
-
-#include "gui/fonts/font.h"
-
-#include "render/renderers.h"
-
-#include "render/vertexes/imagecollection.h"
-
-#include "utils/delete2.h"
-
-#include "debug.h"
-
-int Button::mInstances = 0;
-float Button::mAlpha = 1.0;
-
-static std::string const data[Button::BUTTON_COUNT] =
-{
- "button.xml",
- "button_highlighted.xml",
- "button_pressed.xml",
- "button_disabled.xml"
-};
-
-Skin *Button::button[BUTTON_COUNT];
-
-Button::Button(const Widget2 *const widget) :
- Widget(widget),
- MouseListener(),
- KeyListener(),
- FocusListener(),
- WidgetListener(),
- mCaption(),
- mDescription(),
- mTextChunk(),
- mVertexes2(new ImageCollection),
- mEnabledColor(getThemeColor(ThemeColorId::BUTTON)),
- mEnabledColor2(getThemeColor(ThemeColorId::BUTTON_OUTLINE)),
- mDisabledColor(getThemeColor(ThemeColorId::BUTTON_DISABLED)),
- mDisabledColor2(getThemeColor(ThemeColorId::BUTTON_DISABLED_OUTLINE)),
- mHighlightedColor(getThemeColor(ThemeColorId::BUTTON_HIGHLIGHTED)),
- mHighlightedColor2(getThemeColor(
- ThemeColorId::BUTTON_HIGHLIGHTED_OUTLINE)),
- mPressedColor(getThemeColor(ThemeColorId::BUTTON_PRESSED)),
- mPressedColor2(getThemeColor(ThemeColorId::BUTTON_PRESSED_OUTLINE)),
- mImages(nullptr),
- mImageSet(nullptr),
- mAlignment(Graphics::CENTER),
- mClickCount(0),
- mSpacing(),
- mTag(0),
- mMode(0),
- mXOffset(0),
- mYOffset(0),
- mImageWidth(0),
- mImageHeight(0),
- mHasMouse(false),
- mKeyPressed(false),
- mMousePressed(false),
- mStick(false),
- mPressed(false),
- mTextChanged(true)
-{
- init();
- adjustSize();
-}
-
-Button::Button(const Widget2 *const widget,
- const std::string &restrict caption,
- const std::string &restrict actionEventId,
- ActionListener *const listener) :
- Widget(widget),
- MouseListener(),
- KeyListener(),
- FocusListener(),
- WidgetListener(),
- mCaption(caption),
- mDescription(),
- mTextChunk(),
- mVertexes2(new ImageCollection),
- mEnabledColor(getThemeColor(ThemeColorId::BUTTON)),
- mEnabledColor2(getThemeColor(ThemeColorId::BUTTON_OUTLINE)),
- mDisabledColor(getThemeColor(ThemeColorId::BUTTON_DISABLED)),
- mDisabledColor2(getThemeColor(ThemeColorId::BUTTON_DISABLED_OUTLINE)),
- mHighlightedColor(getThemeColor(ThemeColorId::BUTTON_HIGHLIGHTED)),
- mHighlightedColor2(getThemeColor(
- ThemeColorId::BUTTON_HIGHLIGHTED_OUTLINE)),
- mPressedColor(getThemeColor(ThemeColorId::BUTTON_PRESSED)),
- mPressedColor2(getThemeColor(ThemeColorId::BUTTON_PRESSED_OUTLINE)),
- mImages(nullptr),
- mImageSet(nullptr),
- mAlignment(Graphics::CENTER),
- mClickCount(0),
- mSpacing(),
- mTag(0),
- mMode(0),
- mXOffset(0),
- mYOffset(0),
- mImageWidth(0),
- mImageHeight(0),
- mHasMouse(false),
- mKeyPressed(false),
- mMousePressed(false),
- mStick(false),
- mPressed(false),
- mTextChanged(true)
-{
- init();
- adjustSize();
- setActionEventId(actionEventId);
-
- if (listener != nullptr)
- addActionListener(listener);
-}
-
-Button::Button(const Widget2 *const widget,
- const std::string &restrict caption,
- const std::string &restrict imageName,
- const int imageWidth, const int imageHeight,
- const std::string &restrict actionEventId,
- ActionListener *const listener) :
- Widget(widget),
- MouseListener(),
- KeyListener(),
- FocusListener(),
- WidgetListener(),
- mCaption(caption),
- mDescription(),
- mTextChunk(),
- mVertexes2(new ImageCollection),
- mEnabledColor(getThemeColor(ThemeColorId::BUTTON)),
- mEnabledColor2(getThemeColor(ThemeColorId::BUTTON_OUTLINE)),
- mDisabledColor(getThemeColor(ThemeColorId::BUTTON_DISABLED)),
- mDisabledColor2(getThemeColor(ThemeColorId::BUTTON_DISABLED_OUTLINE)),
- mHighlightedColor(getThemeColor(ThemeColorId::BUTTON_HIGHLIGHTED)),
- mHighlightedColor2(getThemeColor(
- ThemeColorId::BUTTON_HIGHLIGHTED_OUTLINE)),
- mPressedColor(getThemeColor(ThemeColorId::BUTTON_PRESSED)),
- mPressedColor2(getThemeColor(ThemeColorId::BUTTON_PRESSED_OUTLINE)),
- mImages(nullptr),
- mImageSet(nullptr),
- mAlignment(Graphics::CENTER),
- mClickCount(0),
- mSpacing(),
- mTag(0),
- mMode(0),
- mXOffset(0),
- mYOffset(0),
- mImageWidth(imageWidth),
- mImageHeight(imageHeight),
- mHasMouse(false),
- mKeyPressed(false),
- mMousePressed(false),
- mStick(false),
- mPressed(false),
- mTextChanged(true)
-{
- init();
- loadImageSet(imageName);
- adjustSize();
- setActionEventId(actionEventId);
-
- if (listener != nullptr)
- addActionListener(listener);
-}
-
-Button::Button(const Widget2 *const widget,
- const std::string &restrict imageName,
- const int imageWidth, const int imageHeight,
- const std::string &restrict actionEventId,
- ActionListener *const listener) :
- Widget(widget),
- MouseListener(),
- KeyListener(),
- FocusListener(),
- WidgetListener(),
- mCaption(),
- mDescription(),
- mTextChunk(),
- mVertexes2(new ImageCollection),
- mEnabledColor(getThemeColor(ThemeColorId::BUTTON)),
- mEnabledColor2(getThemeColor(ThemeColorId::BUTTON_OUTLINE)),
- mDisabledColor(getThemeColor(ThemeColorId::BUTTON_DISABLED)),
- mDisabledColor2(getThemeColor(ThemeColorId::BUTTON_DISABLED_OUTLINE)),
- mHighlightedColor(getThemeColor(ThemeColorId::BUTTON_HIGHLIGHTED)),
- mHighlightedColor2(getThemeColor(
- ThemeColorId::BUTTON_HIGHLIGHTED_OUTLINE)),
- mPressedColor(getThemeColor(ThemeColorId::BUTTON_PRESSED)),
- mPressedColor2(getThemeColor(ThemeColorId::BUTTON_PRESSED_OUTLINE)),
- mImages(nullptr),
- mImageSet(nullptr),
- mAlignment(Graphics::CENTER),
- mClickCount(0),
- mSpacing(),
- mTag(0),
- mMode(0),
- mXOffset(0),
- mYOffset(0),
- mImageWidth(imageWidth),
- mImageHeight(imageHeight),
- mHasMouse(false),
- mKeyPressed(false),
- mMousePressed(false),
- mStick(false),
- mPressed(false),
- mTextChanged(true)
-{
- init();
- loadImageSet(imageName);
- adjustSize();
- setActionEventId(actionEventId);
-
- if (listener != nullptr)
- addActionListener(listener);
-}
-
-Button::Button(const Widget2 *const widget,
- const std::string &restrict caption,
- const std::string &restrict imageName,
- const std::string &restrict actionEventId,
- ActionListener *const listener) :
- Widget(widget),
- MouseListener(),
- KeyListener(),
- FocusListener(),
- WidgetListener(),
- mCaption(caption),
- mDescription(),
- mTextChunk(),
- mVertexes2(new ImageCollection),
- mEnabledColor(getThemeColor(ThemeColorId::BUTTON)),
- mEnabledColor2(getThemeColor(ThemeColorId::BUTTON_OUTLINE)),
- mDisabledColor(getThemeColor(ThemeColorId::BUTTON_DISABLED)),
- mDisabledColor2(getThemeColor(ThemeColorId::BUTTON_DISABLED_OUTLINE)),
- mHighlightedColor(getThemeColor(ThemeColorId::BUTTON_HIGHLIGHTED)),
- mHighlightedColor2(getThemeColor(
- ThemeColorId::BUTTON_HIGHLIGHTED_OUTLINE)),
- mPressedColor(getThemeColor(ThemeColorId::BUTTON_PRESSED)),
- mPressedColor2(getThemeColor(ThemeColorId::BUTTON_PRESSED_OUTLINE)),
- mImages(nullptr),
- mImageSet(nullptr),
- mAlignment(Graphics::CENTER),
- mClickCount(0),
- mSpacing(),
- mTag(0),
- mMode(0),
- mXOffset(0),
- mYOffset(0),
- mImageWidth(0),
- mImageHeight(0),
- mHasMouse(false),
- mKeyPressed(false),
- mMousePressed(false),
- mStick(false),
- mPressed(false),
- mTextChanged(true)
-{
- init();
- loadImage(imageName);
- adjustSize();
- setActionEventId(actionEventId);
-
- if (listener != nullptr)
- addActionListener(listener);
-}
-
-void Button::init()
-{
- mAllowLogic = false;
- addMouseListener(this);
- addKeyListener(this);
- addFocusListener(this);
- addWidgetListener(this);
-
- setFocusable(true);
- setFrameSize(0);
-
- if (mInstances == 0)
- {
- if (theme != nullptr)
- {
- for (int mode = 0; mode < BUTTON_COUNT; mode ++)
- {
- Skin *const skin = theme->load(data[mode], "button.xml");
- if (skin != nullptr)
- {
- button[mode] = skin;
- mSpacing[mode] = skin->getOption("spacing");
- }
- }
- }
-
- updateAlpha();
- }
-
- mInstances++;
-}
-
-Button::~Button()
-{
- if (mWindow != nullptr)
- mWindow->removeWidgetListener(this);
-
- if (gui != nullptr)
- gui->removeDragged(this);
-
- mInstances--;
-
- if (mInstances == 0 && (theme != nullptr))
- {
- for (int mode = 0; mode < BUTTON_COUNT; mode ++)
- theme->unload(button[mode]);
- }
- delete2(mVertexes2);
- if (mImageSet != nullptr)
- {
- mImageSet->decRef();
- mImageSet = nullptr;
- }
- if (mImages != nullptr)
- {
- for (int f = 0; f < BUTTON_COUNT; f ++)
- mImages[f] = nullptr;
- delete [] mImages;
- mImages = nullptr;
- }
- mTextChunk.deleteImage();
-}
-
-void Button::loadImage(const std::string &imageName)
-{
- if (mImageSet != nullptr)
- {
- mImageSet->decRef();
- mImageSet = nullptr;
- }
- Image *const image = Theme::getImageFromThemeXml(imageName, "");
- mImages = new Image*[BUTTON_COUNT];
- for (int f = 0; f < BUTTON_COUNT; f ++)
- mImages[f] = image;
-}
-
-void Button::loadImageSet(const std::string &imageName)
-{
- if (mImageSet != nullptr)
- {
- mImageSet->decRef();
- mImageSet = nullptr;
- }
- mImageSet = Theme::getImageSetFromTheme(imageName,
- mImageWidth, mImageHeight);
- if (mImageSet == nullptr)
- return;
- mImages = new Image*[BUTTON_COUNT];
- mImages[0] = nullptr;
- for (size_t f = 0; f < BUTTON_COUNT; f ++)
- {
- Image *const img = mImageSet->get(f);
- if (img != nullptr)
- mImages[f] = img;
- else
- mImages[f] = mImages[0];
- }
-}
-
-void Button::updateAlpha()
-{
- const float alpha = std::max(settings.guiAlpha,
- theme->getMinimumOpacity());
-
- if (mAlpha != alpha)
- {
- mAlpha = alpha;
- for (int mode = 0; mode < BUTTON_COUNT; mode ++)
- {
- for (int a = 0; a < 9; a ++)
- {
- Skin *const skin = button[mode];
- if (skin != nullptr)
- {
- const ImageRect &rect = skin->getBorder();
- Image *const image = rect.grid[a];
- if (image != nullptr)
- image->setAlpha(mAlpha);
- }
- }
- }
- }
-}
-
-void Button::draw(Graphics *const graphics)
-{
- BLOCK_START("Button::draw")
- int mode;
-
- if (!isEnabled())
- mode = BUTTON_DISABLED;
- else if (isPressed2())
- mode = BUTTON_PRESSED;
- else if (mHasMouse)
- mode = BUTTON_HIGHLIGHTED;
- else
- mode = BUTTON_STANDARD;
-
- const Skin *const skin = button[mode];
- if (skin == nullptr)
- {
- BLOCK_END("Button::draw")
- return;
- }
-
- updateAlpha();
-
- bool recalc = false;
- if (mRedraw)
- {
- recalc = true;
- }
- else
- {
- // because we don't know where parent windows was moved,
- // need recalc vertexes
- ClipRect &rect = graphics->getTopClip();
- if (rect.xOffset != mXOffset || rect.yOffset != mYOffset)
- {
- recalc = true;
- mXOffset = rect.xOffset;
- mYOffset = rect.yOffset;
- }
- else if (mMode != mode)
- {
- recalc = true;
- mMode = mode;
- }
- else if (graphics->getRedraw())
- {
- recalc = true;
- }
- }
-
- const int padding = skin->getPadding();
- const int spacing = mSpacing[mode];
-
- if (recalc)
- mTextChanged = true;
-
- int imageX = 0;
- int imageY = 0;
- int textX = 0;
- const Rect &rect = mDimension;
- const int width = rect.width;
- const int height = rect.height;
- Font *const font = getFont();
- int textY = height / 2 - font->getHeight() / 2;
- if (mImages != nullptr)
- imageY = height / 2 - mImageHeight / 2;
-
-// need move calculation from draw!!!
-
- switch (mAlignment)
- {
- default:
- case Graphics::LEFT:
- {
- if (mImages != nullptr)
- {
- imageX = padding;
- textX = padding + mImageWidth + spacing;
- }
- else
- {
- textX = padding;
- }
- break;
- }
- case Graphics::CENTER:
- {
- const int width1 = font->getWidth(mCaption);
- if (mImages != nullptr)
- {
- const int w = width1 + mImageWidth + spacing;
- imageX = (width - w) / 2;
- textX = imageX + mImageWidth + spacing - width1 / 2;
- }
- else
- {
- textX = (width - width1) / 2;
- }
- break;
- }
- case Graphics::RIGHT:
- {
- const int width1 = font->getWidth(mCaption);
- textX = width - width1 - padding;
- imageX = textX - width1 - spacing;
- break;
- }
- }
-
- if (recalc)
- {
- mRedraw = false;
- mMode = mode;
- mVertexes2->clear();
- graphics->calcWindow(mVertexes2,
- 0, 0,
- width, height,
- skin->getBorder());
-
- if (mImages != nullptr)
- {
- if (isPressed())
- {
- graphics->calcTileCollection(mVertexes2,
- mImages[mode],
- imageX + 1, imageY + 1);
- }
- else
- {
- graphics->calcTileCollection(mVertexes2,
- mImages[mode],
- imageX, imageY);
- }
- }
- graphics->finalize(mVertexes2);
- }
- graphics->drawTileCollection(mVertexes2);
-
- if (isPressed())
- {
- textX ++;
- textY ++;
- }
-
- if (mTextChanged)
- {
- mTextChunk.textFont = font;
- mTextChunk.deleteImage();
- mTextChunk.text = mCaption;
- switch (mode)
- {
- case BUTTON_DISABLED:
- mTextChunk.color = mDisabledColor;
- mTextChunk.color2 = mDisabledColor2;
- break;
- case BUTTON_PRESSED:
- mTextChunk.color = mPressedColor;
- mTextChunk.color2 = mPressedColor2;
- break;
- case BUTTON_HIGHLIGHTED:
- mTextChunk.color = mHighlightedColor;
- mTextChunk.color2 = mHighlightedColor2;
- break;
- default:
- mTextChunk.color = mEnabledColor;
- mTextChunk.color2 = mEnabledColor2;
- break;
- }
- font->generate(mTextChunk);
- mTextChanged = false;
- }
-
- const Image *const image = mTextChunk.img;
- if (image != nullptr)
- graphics->drawImage(image, textX, textY);
-
- BLOCK_END("Button::draw")
-}
-
-void Button::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("Button::safeDraw")
- int mode;
-
- if (!isEnabled())
- mode = BUTTON_DISABLED;
- else if (isPressed2())
- mode = BUTTON_PRESSED;
- else if (mHasMouse || isFocused())
- mode = BUTTON_HIGHLIGHTED;
- else
- mode = BUTTON_STANDARD;
-
- const Skin *const skin = button[mode];
- if (skin == nullptr)
- {
- BLOCK_END("Button::safeDraw")
- return;
- }
-
- updateAlpha();
-
- if (mMode != mode)
- {
- mTextChanged = true;
- mMode = mode;
- }
-
- const int padding = skin->getPadding();
- const int spacing = mSpacing[mode];
-
- int imageX = 0;
- int imageY = 0;
- int textX = 0;
- const Rect &rect = mDimension;
- const int width = rect.width;
- const int height = rect.height;
- Font *const font = getFont();
- int textY = height / 2 - font->getHeight() / 2;
- if (mImages != nullptr)
- imageY = height / 2 - mImageHeight / 2;
-
-// need move calculation from draw!!!
-
- switch (mAlignment)
- {
- default:
- case Graphics::LEFT:
- {
- if (mImages != nullptr)
- {
- imageX = padding;
- textX = padding + mImageWidth + spacing;
- }
- else
- {
- textX = padding;
- }
- break;
- }
- case Graphics::CENTER:
- {
- const int width1 = font->getWidth(mCaption);
- if (mImages != nullptr)
- {
- const int w = width1 + mImageWidth + spacing;
- imageX = (width - w) / 2;
- textX = imageX + mImageWidth + spacing - width1 / 2;
- }
- else
- {
- textX = (width - width1) / 2;
- }
- break;
- }
- case Graphics::RIGHT:
- {
- const int width1 = font->getWidth(mCaption);
- textX = width - width1 - padding;
- imageX = textX - width1 - spacing;
- break;
- }
- }
-
- graphics->drawImageRect(0, 0, width, height, skin->getBorder());
-
- if (mImages != nullptr)
- {
- if (isPressed())
- graphics->drawImage(mImages[mode], imageX + 1, imageY + 1);
- else
- graphics->drawImage(mImages[mode], imageX, imageY);
- }
-
- if (isPressed())
- {
- textX ++;
- textY ++;
- }
-
- if (mTextChanged)
- {
- mTextChunk.textFont = font;
- mTextChunk.deleteImage();
- mTextChunk.text = mCaption;
- switch (mode)
- {
- case BUTTON_DISABLED:
- mTextChunk.color = mDisabledColor;
- mTextChunk.color2 = mDisabledColor2;
- break;
- case BUTTON_PRESSED:
- mTextChunk.color = mPressedColor;
- mTextChunk.color2 = mPressedColor2;
- break;
- case BUTTON_HIGHLIGHTED:
- mTextChunk.color = mHighlightedColor;
- mTextChunk.color2 = mHighlightedColor2;
- break;
- default:
- mTextChunk.color = mEnabledColor;
- mTextChunk.color2 = mEnabledColor2;
- break;
- }
- font->generate(mTextChunk);
- mTextChanged = false;
- }
-
- const Image *const image = mTextChunk.img;
- if (image != nullptr)
- graphics->drawImage(image, textX, textY);
-
- BLOCK_END("Button::safeDraw")
-}
-
-void Button::mouseReleased(MouseEvent& event)
-{
- if (event.getButton() == MouseButton::LEFT)
- {
- if (mStick)
- mPressed = !mPressed;
-
- if (mMousePressed && mHasMouse)
- {
- mMousePressed = false;
- mClickCount = event.getClickCount();
- distributeActionEvent();
- }
- else
- {
- mMousePressed = false;
- mClickCount = 0;
- }
- event.consume();
- }
-}
-
-void Button::widgetResized(const Event &event A_UNUSED)
-{
- mRedraw = true;
-}
-
-void Button::widgetMoved(const Event &event A_UNUSED)
-{
- mRedraw = true;
-}
-
-void Button::widgetHidden(const Event &event A_UNUSED)
-{
- if (isBatchDrawRenders(openGLMode))
- mVertexes2->clear();
- mTextChunk.deleteImage();
- mRedraw = true;
- mTextChanged = true;
-}
-
-void Button::adjustSize()
-{
- const Font *const font = getFont();
- const Skin *const skin = button[BUTTON_STANDARD];
- if (skin == nullptr)
- return;
- const int padding = skin->getPadding();
-
- if (mImages != nullptr)
- {
- const int spacing = mSpacing[BUTTON_STANDARD];
- const int width = font->getWidth(mCaption);
- if (width != 0)
- setWidth(width + mImageWidth + spacing + 2 * padding);
- else
- setWidth(mImageWidth + 2 * padding);
- int height = font->getHeight();
- if (height < mImageHeight)
- height = mImageHeight;
- setHeight(height + 2 * padding);
- }
- else
- {
- setWidth(font->getWidth(mCaption) + 2 * padding);
- setHeight(font->getHeight() + 2 * padding);
- }
-}
-
-void Button::keyPressed(KeyEvent& event)
-{
- const InputActionT action = event.getActionId();
-
- if (action == InputAction::GUI_SELECT)
- {
- mKeyPressed = true;
- event.consume();
- }
-}
-
-void Button::keyReleased(KeyEvent& event)
-{
- const InputActionT action = event.getActionId();
-
- if (action == InputAction::GUI_SELECT && mKeyPressed)
- {
- mKeyPressed = false;
- if (mStick)
- mPressed = !mPressed;
- distributeActionEvent();
- event.consume();
- }
-}
-
-bool Button::isPressed2() const
-{
- return mPressed || isPressed();
-}
-
-bool Button::isPressed() const
-{
- if (mMousePressed)
- return mHasMouse;
- return mKeyPressed;
-}
-
-void Button::focusLost(const Event& event A_UNUSED)
-{
- mMousePressed = false;
- mKeyPressed = false;
-}
-
-void Button::mousePressed(MouseEvent& event)
-{
- if (event.getButton() == MouseButton::LEFT)
- {
- mMousePressed = true;
- event.consume();
- }
-}
-
-void Button::mouseEntered(MouseEvent& event A_UNUSED)
-{
- mHasMouse = true;
-}
-
-void Button::mouseExited(MouseEvent& event A_UNUSED)
-{
- mHasMouse = false;
-}
-
-void Button::mouseDragged(MouseEvent& event)
-{
- event.consume();
-}
-
-void Button::setParent(Widget *widget)
-{
- if (mWindow != nullptr)
- mWindow->addWidgetListener(this);
- Widget::setParent(widget);
-}
-
-void Button::setWindow(Widget *const widget)
-{
- if ((widget == nullptr) && (mWindow != nullptr))
- {
- mWindow->removeWidgetListener(this);
- mWindow = nullptr;
- }
- else
- {
- Widget2::setWindow(widget);
- }
-}
diff --git a/src/gui/widgets/button.h b/src/gui/widgets/button.h
deleted file mode 100644
index 4e6b5ba16..000000000
--- a/src/gui/widgets/button.h
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_BUTTON_H
-#define GUI_WIDGETS_BUTTON_H
-
-#include "gui/fonts/textchunk.h"
-
-#include "gui/widgets/widget.h"
-
-#include "listeners/focuslistener.h"
-#include "listeners/keylistener.h"
-#include "listeners/mouselistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "render/graphics.h"
-
-#include "localconsts.h"
-
-class Image;
-class ImageCollection;
-class ImageSet;
-class Skin;
-
-const std::string BUTTON_PLAY = "buttonplay.png";
-
-/**
- * Button widget. Same as the Guichan button but with custom look.
- *
- * \ingroup GUI
- */
-class Button final : public Widget,
- public MouseListener,
- public KeyListener,
- public FocusListener,
- public WidgetListener
-{
- public:
- /**
- * Default constructor.
- */
- explicit Button(const Widget2 *const widget);
-
- /**
- * Constructor, sets the caption of the button to the given string and
- * adds the given action listener.
- */
- Button(const Widget2 *const widget,
- const std::string &restrict caption,
- const std::string &restrict actionEventId,
- ActionListener *const listener);
-
- /**
- * Constructor, sets the caption of the button to the given string and
- * adds the given action listener.
- */
- Button(const Widget2 *const widget,
- const std::string &restrict caption,
- const std::string &restrict imageName,
- const int imageWidth, const int imageHeight,
- const std::string &actionEventId,
- ActionListener *const listener);
-
- /**
- * Constructor, sets the caption of the button to the given string and
- * adds the given action listener.
- */
- Button(const Widget2 *const widget,
- const std::string &restrict imageName,
- const int imageWidth, const int imageHeight,
- const std::string &restrict actionEventId,
- ActionListener *const listener);
-
- /**
- * Constructor, sets the caption of the button to the given string and
- * adds the given action listener.
- */
- Button(const Widget2 *const widget,
- const std::string &restrict imageName,
- const std::string &restrict caption,
- const std::string &restrict actionEventId,
- ActionListener *const listener);
-
- A_DELETE_COPY(Button)
-
- /**
- * Destructor.
- */
- ~Button();
-
- /**
- * Draws the button.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Update the alpha value to the button components.
- */
- static void updateAlpha();
-
- void mouseReleased(MouseEvent& event) override final;
-
- void setDescription(const std::string &text)
- { mDescription = text; }
-
- std::string getDescription() const noexcept2 A_WARN_UNUSED
- { return mDescription; }
-
- int getClickCount() const noexcept2 A_WARN_UNUSED
- { return mClickCount; }
-
- void setTag(int tag)
- { mTag = tag; }
-
- int getTag() const noexcept2 A_WARN_UNUSED
- { return mTag; }
-
- void setStick(bool b)
- { mStick = b; }
-
- void setPressed(bool b)
- { mPressed = b; }
-
- void widgetResized(const Event &event) override final;
-
- void widgetMoved(const Event &event) override final;
-
- void widgetHidden(const Event &event) override final;
-
- void loadImage(const std::string &imageName);
-
- void loadImageSet(const std::string &imageName);
-
- void adjustSize();
-
- void keyPressed(KeyEvent &event) override final;
-
- void keyReleased(KeyEvent &event) override final;
-
- bool isPressed2() const A_WARN_UNUSED;
-
- /**
- * Sets the caption of the button. It's advisable to call
- * adjustSize after setting of the caption to adjust the
- * button's size to fit the caption.
- *
- * @param caption The caption of the button.
- * @see getCaption, adjustSize
- */
- void setCaption(const std::string& caption)
- { mCaption = caption; mTextChanged = true; }
-
- /**
- * Gets the caption of the button.
- *
- * @return The caption of the button.
- */
- const std::string& getCaption() const noexcept2 A_WARN_UNUSED
- { return mCaption; }
-
- /**
- * Sets the alignment of the caption. The alignment is relative
- * to the center of the button.
- *
- * @param alignment The alignment of the caption.
- * @see getAlignment, Graphics
- */
- void setAlignment(Graphics::Alignment alignment) noexcept2
- { mAlignment = alignment; }
-
- /**
- * Gets the alignment of the caption.
- *
- * @return The alignment of the caption.
- * @see setAlignment, Graphics
- */
- Graphics::Alignment getAlignment() const noexcept2 A_WARN_UNUSED
- { return mAlignment; }
-
- void focusLost(const Event& event) override final;
-
- void mousePressed(MouseEvent& event) override final;
-
- void mouseEntered(MouseEvent& event) override final;
-
- void mouseExited(MouseEvent& event) override final;
-
- void mouseDragged(MouseEvent& event) override final;
-
- void setParent(Widget *widget) override final;
-
- void setWindow(Widget *const widget) override final;
-
- void setImageWidth(const int width) noexcept2
- { mImageWidth = width; }
-
- void setImageHeight(const int height) noexcept2
- { mImageHeight = height; }
-
- enum
- {
- BUTTON_STANDARD = 0, // 0
- BUTTON_HIGHLIGHTED, // 1
- BUTTON_PRESSED, // 2
- BUTTON_DISABLED, // 3
- BUTTON_COUNT // 4 - Must be last.
- };
-
- private:
- /**
- * Checks if the button is pressed. Convenient method to use
- * when overloading the draw method of the button.
- *
- * @return True if the button is pressed, false otherwise.
- */
- bool isPressed() const;
-
- void init();
-
- static Skin *button[BUTTON_COUNT]; /**< Button state graphics */
- static int mInstances; /**< Number of button instances */
- static float mAlpha;
-
- /**
- * Holds the caption of the button.
- */
- std::string mCaption;
-
- std::string mDescription;
-
- TextChunk mTextChunk;
-
- ImageCollection *mVertexes2 A_NONNULLPOINTER;
- Color mEnabledColor;
- Color mEnabledColor2;
- Color mDisabledColor;
- Color mDisabledColor2;
- Color mHighlightedColor;
- Color mHighlightedColor2;
- Color mPressedColor;
- Color mPressedColor2;
- Image **mImages;
- ImageSet *mImageSet;
-
- /**
- * Holds the alignment of the caption.
- */
- Graphics::Alignment mAlignment;
-
- int mClickCount;
-
- /**
- * Holds the spacing between the border and the caption.
- */
- int mSpacing[BUTTON_COUNT];
-
- int mTag;
- int mMode;
- int mXOffset;
- int mYOffset;
- int mImageWidth;
- int mImageHeight;
- /**
- * True if the mouse is ontop of the button, false otherwise.
- */
- bool mHasMouse;
-
- /**
- * True if a key has been pressed, false otherwise.
- */
- bool mKeyPressed;
-
- /**
- * True if a mouse has been pressed, false otherwise.
- */
- bool mMousePressed;
-
- bool mStick;
- bool mPressed;
- bool mTextChanged;
-};
-
-#endif // GUI_WIDGETS_BUTTON_H
diff --git a/src/gui/widgets/characterdisplay.cpp b/src/gui/widgets/characterdisplay.cpp
deleted file mode 100644
index e5743615a..000000000
--- a/src/gui/widgets/characterdisplay.cpp
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/characterdisplay.h"
-
-#include "gui/gui.h"
-
-#include "gui/windows/charselectdialog.h"
-
-#include "gui/popups/textpopup.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layouthelper.h"
-
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include "resources/db/unitsdb.h"
-
-#include "net/character.h"
-
-#include "debug.h"
-
-CharacterDisplay::CharacterDisplay(const Widget2 *const widget,
- CharSelectDialog *const charSelectDialog) :
- Container(widget),
- MouseListener(),
- WidgetListener(),
- mCharacter(nullptr),
- mPlayerBox(new PlayerBox(nullptr)),
- mName(new Label(this, "wwwwwwwwwwwwwwwwwwwwwwww"))
-{
- mPlayerBox->setActionEventId("select");
- mPlayerBox->addActionListener(charSelectDialog);
- setActionEventId("use");
- addActionListener(charSelectDialog);
-
- LayoutHelper h(this);
- ContainerPlacer placer = h.getPlacer(0, 0);
-
- placer(0, 0, mPlayerBox, 3, 5);
- placer(0, 5, mName, 3);
-
- update();
-
- mName->setAlignment(Graphics::CENTER);
- mName->adjustSize();
-
- if (mainGraphics->getWidth() > 800)
- setWidth(120);
- else
- setWidth(80);
- setHeight(120);
- addMouseListener(this);
- addWidgetListener(this);
-}
-
-CharacterDisplay::~CharacterDisplay()
-{
-}
-
-void CharacterDisplay::setCharacter(Net::Character *const character)
-{
- if (mCharacter == character)
- return;
-
- mCharacter = character;
- mPlayerBox->setPlayer(character != nullptr ? character->dummy : nullptr);
- update();
-}
-
-void CharacterDisplay::requestFocus()
-{
-}
-
-void CharacterDisplay::setActive(const bool active A_UNUSED)
-{
-}
-
-void CharacterDisplay::update()
-{
- if (mCharacter != nullptr)
- mName->setCaption(mCharacter->dummy->getName());
- else
- mName->setCaption("");
- const int width = mPlayerBox->getWidth();
- mName->resizeTo(width, width);
-
- distributeResizedEvent();
-}
-
-void CharacterDisplay::widgetHidden(const Event &event A_UNUSED)
-{
- if (textPopup != nullptr)
- textPopup->setVisible(Visible_false);
-}
-
-void CharacterDisplay::mouseExited(MouseEvent &event A_UNUSED)
-{
- if (textPopup != nullptr)
- textPopup->setVisible(Visible_false);
-}
-
-void CharacterDisplay::mouseMoved(MouseEvent &event A_UNUSED)
-{
- if (gui == nullptr ||
- textPopup == nullptr ||
- mCharacter == nullptr)
- {
- return;
- }
-
- int mouseX = 0;
- int mouseY = 0;
- Gui::getMouseState(mouseX, mouseY);
- const std::string &name = mName->getCaption();
- if (!name.empty())
- {
- textPopup->show(mouseX, mouseY,
- name,
- // TRANSLATORS: character level
- strprintf(_("Level: %u"),
- CAST_U32(
- mCharacter->data.mAttributes[Attributes::PLAYER_BASE_LEVEL])),
- // TRANSLATORS: character money
- strprintf(_("Money: %s"), UnitsDb::formatCurrency64(
- mCharacter->data.mAttributes[Attributes::MONEY]).c_str()));
- }
- else
- {
- textPopup->setVisible(Visible_false);
- }
-}
-
-void CharacterDisplay::mousePressed(MouseEvent &event)
-{
- event.consume();
- if (event.getClickCount() == 2)
- distributeActionEvent();
-}
diff --git a/src/gui/widgets/characterdisplay.h b/src/gui/widgets/characterdisplay.h
deleted file mode 100644
index def986b2d..000000000
--- a/src/gui/widgets/characterdisplay.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_CHARACTERDISPLAY_H
-#define GUI_WIDGETS_CHARACTERDISPLAY_H
-
-#include "gui/widgets/container.h"
-#include "gui/widgets/playerbox.h"
-
-#include "listeners/widgetlistener.h"
-
-#include "localconsts.h"
-
-class CharSelectDialog;
-class Label;
-
-namespace Net
-{
- struct Character;
-} // namespace Net
-
-class CharacterDisplay final : public Container,
- public MouseListener,
- public WidgetListener
-{
- public:
- CharacterDisplay(const Widget2 *const widget,
- CharSelectDialog *const charSelectDialog);
-
- A_DELETE_COPY(CharacterDisplay)
-
- ~CharacterDisplay();
-
- void setCharacter(Net::Character *const character);
-
- Net::Character *getCharacter() const
- { return mCharacter; }
-
- void requestFocus() override final A_CONST;
-
- void setActive(const bool active) A_CONST;
-
- bool isSelectFocused() const
- { return false; }
-
- bool isDeleteFocused() const
- { return false; }
-
- void focusSelect()
- { }
-
- void focusDelete()
- { }
-
- void setSelect(bool b)
- { mPlayerBox->setSelected(b); }
-
- void widgetHidden(const Event &event) override final;
-
- void mouseExited(MouseEvent &event) override final;
-
- void mouseMoved(MouseEvent &event) override final;
-
- void mousePressed(MouseEvent &event) override final;
-
- void update();
-
- private:
- Net::Character *mCharacter;
- PlayerBox *mPlayerBox A_NONNULLPOINTER;
- Label *mName A_NONNULLPOINTER;
-};
-
-#endif // GUI_WIDGETS_CHARACTERDISPLAY_H
diff --git a/src/gui/widgets/characterviewbase.h b/src/gui/widgets/characterviewbase.h
deleted file mode 100644
index ad12efb26..000000000
--- a/src/gui/widgets/characterviewbase.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_CHARACTERVIEWBASE_H
-#define GUI_WIDGETS_CHARACTERVIEWBASE_H
-
-#include "gui/windows/charselectdialog.h"
-
-#include "gui/widgets/container.h"
-
-#include "localconsts.h"
-
-class CharacterViewBase notfinal : public Container,
- public ActionListener
-{
- public:
- A_DELETE_COPY(CharacterViewBase)
-
- virtual ~CharacterViewBase()
- { }
-
- virtual void show(const int i) = 0;
-
- virtual void resize() = 0;
-
- int getSelected() const
- {
- return mSelected;
- }
-
- protected:
- CharacterViewBase(CharSelectDialog *const widget, const int padding) :
- Container(widget),
- ActionListener(),
- mParent(widget),
- mPadding(padding),
- mSelected(0)
- {
- }
-
- CharSelectDialog *mParent;
- int mPadding;
- int mSelected;
-};
-
-#endif // GUI_WIDGETS_CHARACTERVIEWBASE_H
diff --git a/src/gui/widgets/characterviewnormal.cpp b/src/gui/widgets/characterviewnormal.cpp
deleted file mode 100644
index c52616b85..000000000
--- a/src/gui/widgets/characterviewnormal.cpp
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/characterviewnormal.h"
-
-#include "configuration.h"
-
-#include "gui/widgets/characterdisplay.h"
-
-#include "utils/foreach.h"
-
-#include "debug.h"
-
-namespace
-{
- int perRowCount = 5;
-} // namespace
-
-CharacterViewNormal::CharacterViewNormal(CharSelectDialog *const widget,
- STD_VECTOR<CharacterDisplay*>
- *const entries,
- const int padding) :
- CharacterViewBase(widget, padding),
- mCharacterEntries(entries),
- mRows(2)
-{
- addKeyListener(widget);
- if (entries != nullptr)
- {
- FOR_EACHP (STD_VECTOR<CharacterDisplay*>::iterator,
- it, entries)
- {
- CharacterDisplay *const character = *it;
- add(character);
- character->setVisible(Visible_true);
- }
- const size_t sz = mCharacterEntries->size();
- if (mSelected >= 0 && mSelected < CAST_S32(sz))
- {
- CharacterDisplay *const display = (*mCharacterEntries)[mSelected];
- if (display != nullptr)
- display->setSelect(false);
- }
- if (sz > 0)
- {
- mSelected = 0;
- CharacterDisplay *const display = (*mCharacterEntries)[0];
- display->setSelect(true);
- setWidth(display->getWidth() * perRowCount + mPadding * 2);
- }
- else
- {
- mSelected = -1;
- }
- mRows = CAST_S32(sz / perRowCount);
-
- if (mRows * perRowCount != CAST_S32(sz))
- mRows ++;
- }
-
- setHeight((105 + config.getIntValue("fontSize")) * mRows);
-}
-
-CharacterViewNormal::~CharacterViewNormal()
-{
- removeKeyListener(mParent);
-}
-
-void CharacterViewNormal::show(const int i)
-{
- const int sz = CAST_S32(mCharacterEntries->size());
- if (i >= 0 && i < sz)
- {
- if (mSelected >= 0)
- (*mCharacterEntries)[mSelected]->setSelect(false);
- mSelected = i;
- (*mCharacterEntries)[i]->setSelect(true);
- }
-}
-
-void CharacterViewNormal::resize()
-{
- const size_t sz = mCharacterEntries->size();
- if (sz == 0)
- return;
- const CharacterDisplay *const firtChar = (*mCharacterEntries)[0];
- int y = 0;
- const int width = firtChar->getWidth();
- const int height = firtChar->getHeight();
- int x = 0;
- for (size_t f = 0; f < sz; f ++, x ++)
- {
- if (x >= perRowCount)
- {
- x = 0;
- y += height;
- }
- (*mCharacterEntries)[f]->setPosition(x * width, y);
- }
-}
-
-void CharacterViewNormal::action(const ActionEvent &event A_UNUSED)
-{
-}
diff --git a/src/gui/widgets/characterviewnormal.h b/src/gui/widgets/characterviewnormal.h
deleted file mode 100644
index 344549092..000000000
--- a/src/gui/widgets/characterviewnormal.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_CHARACTERVIEWNORMAL_H
-#define GUI_WIDGETS_CHARACTERVIEWNORMAL_H
-
-#include "gui/widgets/characterviewbase.h"
-
-#include "localconsts.h"
-
-class CharacterViewNormal final : public CharacterViewBase
-{
- public:
- CharacterViewNormal(CharSelectDialog *const widget,
- STD_VECTOR<CharacterDisplay*> *const entries,
- const int padding);
-
- A_DELETE_COPY(CharacterViewNormal)
-
- ~CharacterViewNormal();
-
- void show(const int i) override final;
-
- void resize() override;
-
- void action(const ActionEvent &event A_UNUSED) override final A_CONST;
-
- private:
- STD_VECTOR<CharacterDisplay*> *mCharacterEntries;
- int mRows;
-};
-
-#endif // GUI_WIDGETS_CHARACTERVIEWNORMAL_H
diff --git a/src/gui/widgets/characterviewsmall.cpp b/src/gui/widgets/characterviewsmall.cpp
deleted file mode 100644
index a2fbdc8d4..000000000
--- a/src/gui/widgets/characterviewsmall.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/characterviewsmall.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/characterdisplay.h"
-#include "gui/widgets/label.h"
-
-#include "utils/foreach.h"
-#include "utils/stringutils.h"
-
-#include "debug.h"
-
-CharacterViewSmall::CharacterViewSmall(CharSelectDialog *const widget,
- STD_VECTOR<CharacterDisplay*>
- *const entries,
- const int padding) :
- CharacterViewBase(widget, padding),
- mSelectedEntry(nullptr),
- mPrevious(new Button(this, "<", "prev", this)),
- mNext(new Button(this, ">", "next", this)),
- mNumber(new Label(this, "??")),
- mCharacterEntries(entries)
-{
- addKeyListener(widget);
- if (entries != nullptr)
- {
- FOR_EACHP (STD_VECTOR<CharacterDisplay*>::iterator,
- it, entries)
- {
- add(*it);
- }
- const int sz = CAST_S32(mCharacterEntries->size());
- if (sz > 0)
- {
- mSelected = 0;
- mSelectedEntry = (*mCharacterEntries)[mSelected];
- mSelectedEntry->setVisible(Visible_true);
- mNumber->setCaption(strprintf("%d / %d", mSelected + 1, sz));
- mNumber->adjustSize();
- }
- else
- {
- mSelected = -1;
- mSelectedEntry = nullptr;
- mNumber->setCaption("0 / 0");
- mNumber->adjustSize();
- }
- }
- add(mPrevious);
- add(mNext);
- add(mNumber);
-
- setHeight(200);
-}
-
-CharacterViewSmall::~CharacterViewSmall()
-{
- removeKeyListener(mParent);
-}
-
-void CharacterViewSmall::show(const int i)
-{
- const int sz = CAST_S32(mCharacterEntries->size());
- if (sz <= 0)
- return;
- if (mSelectedEntry != nullptr)
- mSelectedEntry->setVisible(Visible_false);
- if (i >= sz)
- mSelected = 0;
- else if (i < 0)
- mSelected = sz - 1;
- else
- mSelected = i;
- mSelectedEntry = (*mCharacterEntries)[mSelected];
- mSelectedEntry->setVisible(Visible_true);
- mNumber->setCaption(strprintf("%d / %d", mSelected + 1, sz));
- mNumber->adjustSize();
-}
-
-void CharacterViewSmall::resize()
-{
- const int sz = CAST_S32(mCharacterEntries->size());
- if (sz <= 0)
- return;
- const CharacterDisplay *const firtChar = (*mCharacterEntries)[0];
- const int w = mDimension.width;
- const int h = mDimension.height;
- const int x = (w - firtChar->getWidth()) / 2;
- const int y = (h - firtChar->getHeight()) / 2;
- FOR_EACHP (STD_VECTOR<CharacterDisplay*>::iterator,
- it, mCharacterEntries)
- {
- (*it)->setPosition(x, y);
- }
- const int y2 = (h - mPrevious->getHeight()) / 2;
- const int y3 = y2 - 55;
- mPrevious->setPosition(x - mPrevious->getWidth() - 10, y3);
- mNext->setPosition(w - x + 10, y3);
- mNumber->setPosition(10, y2);
-}
-
-void CharacterViewSmall::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "next")
- {
- mSelected ++;
- show(mSelected);
- mParent->updateState();
- }
- else if (eventId == "prev")
- {
- mSelected --;
- show(mSelected);
- mParent->updateState();
- }
-}
diff --git a/src/gui/widgets/characterviewsmall.h b/src/gui/widgets/characterviewsmall.h
deleted file mode 100644
index f363c608e..000000000
--- a/src/gui/widgets/characterviewsmall.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_CHARACTERVIEWSMALL_H
-#define GUI_WIDGETS_CHARACTERVIEWSMALL_H
-
-#include "gui/widgets/characterviewbase.h"
-
-#include "localconsts.h"
-
-class Label;
-
-class CharacterViewSmall final : public CharacterViewBase
-{
- public:
- CharacterViewSmall(CharSelectDialog *const widget,
- STD_VECTOR<CharacterDisplay*> *const entries,
- const int padding);
- A_DELETE_COPY(CharacterViewSmall)
-
- ~CharacterViewSmall();
-
- void show(const int i) override final;
-
- void resize() override final;
-
- void action(const ActionEvent &event) override final;
-
- private:
- CharacterDisplay *mSelectedEntry;
- Button *mPrevious;
- Button *mNext;
- Label *mNumber;
- STD_VECTOR<CharacterDisplay*> *mCharacterEntries;
-};
-
-#endif // GUI_WIDGETS_CHARACTERVIEWSMALL_H
diff --git a/src/gui/widgets/chatinput.h b/src/gui/widgets/chatinput.h
deleted file mode 100644
index 92c7dc341..000000000
--- a/src/gui/widgets/chatinput.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_CHATINPUT_H
-#define GUI_WIDGETS_CHATINPUT_H
-
-#include "gui/windows/chatwindow.h"
-
-#include "configuration.h"
-
-#include "gui/windows/emotewindow.h"
-
-#include "gui/widgets/textfield.h"
-
-#include "localconsts.h"
-
-/**
- * The chat input hides when it loses focus. It is also invisible by default.
- */
-class ChatInput final : public TextField
-{
- public:
- explicit ChatInput(ChatWindow *const window) :
- TextField(window, "", LoseFocusOnTab_false),
- mWindow(window),
- mFocusGaining(false)
- {
- setVisible(Visible_false);
- addFocusListener(this);
- }
-
- A_DELETE_COPY(ChatInput)
-
- /**
- * Called if the chat input loses focus. It will set itself to
- * invisible as result.
- */
- void focusLost(const Event &event) override final
- {
- TextField::focusLost(event);
- if (mFocusGaining || !config.getBoolValue("protectChatFocus"))
- {
- processVisible(Visible_false);
- if (chatWindow != nullptr)
- chatWindow->updateVisibility();
- mFocusGaining = false;
- return;
- }
- mFocusGaining = true;
- requestFocus();
- mFocusGaining = false;
- }
-
- void processVisible(const Visible n)
- {
- if (mWindow == nullptr || isVisible() == (n == Visible_true))
- return;
-
- if (n == Visible_false)
- mFocusGaining = true;
- setVisible(n);
- if (config.getBoolValue("hideChatInput")
- || config.getBoolValue("showEmotesButton"))
- {
- mWindow->adjustTabSize();
- }
- if (emoteWindow != nullptr)
- {
- emoteWindow->hide();
- }
- }
-
- void unprotectFocus()
- { mFocusGaining = true; }
-
- void setVisible(Visible visible)
- {
- TextField::setVisible(visible);
- }
-
- private:
- ChatWindow *mWindow;
- bool mFocusGaining;
-};
-
-#endif // GUI_WIDGETS_CHATINPUT_H
diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp
deleted file mode 100644
index ab1227b08..000000000
--- a/src/gui/widgets/checkbox.cpp
+++ /dev/null
@@ -1,338 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/checkbox.h"
-
-#include "settings.h"
-
-#include "gui/gui.h"
-#include "gui/skin.h"
-
-#include "gui/fonts/font.h"
-
-#include "render/graphics.h"
-
-#include "resources/imagerect.h"
-
-#include "resources/image/image.h"
-
-#include "debug.h"
-
-int CheckBox::instances = 0;
-Skin *CheckBox::mSkin = nullptr;
-float CheckBox::mAlpha = 1.0;
-
-CheckBox::CheckBox(const Widget2 *const widget,
- const std::string &restrict caption,
- const bool selected,
- ActionListener *const listener,
- const std::string &restrict eventId) :
- Widget(widget),
- ToolTipListener(),
- KeyListener(),
- WidgetListener(),
- mSelected(selected),
- mCaption(),
- mTextChunk(),
- mPadding(0),
- mImagePadding(0),
- mImageSize(9),
- mSpacing(2),
- mTextX(0 + 9 + 2),
- mHasMouse(false),
- mDrawBox(true),
- mTextChanged(true)
-{
- setCaption(caption);
- mAllowLogic = false;
-
- setFocusable(true);
- addMouseListener(this);
- addKeyListener(this);
-
- mForegroundColor2 = getThemeColor(ThemeColorId::CHECKBOX_OUTLINE);
- if (instances == 0)
- {
- if (theme != nullptr)
- {
- mSkin = theme->load("checkbox.xml", "");
- updateAlpha();
- }
- }
-
- instances++;
-
- if (!eventId.empty())
- setActionEventId(eventId);
-
- if (listener != nullptr)
- addActionListener(listener);
-
- mForegroundColor = getThemeColor(ThemeColorId::CHECKBOX);
- if (mSkin != nullptr)
- {
- mPadding = mSkin->getPadding();
- mImagePadding = mSkin->getOption("imagePadding");
- mImageSize = mSkin->getOption("imageSize");
- mSpacing = mSkin->getOption("spacing");
- mDrawBox = (mSkin->getOption("drawBox", 1) != 0);
- mTextX = mPadding + mImageSize + mSpacing;
- }
- adjustSize();
-}
-
-CheckBox::~CheckBox()
-{
- if (mWindow != nullptr)
- mWindow->removeWidgetListener(this);
-
- if (gui != nullptr)
- gui->removeDragged(this);
-
- instances--;
-
- if (instances == 0)
- {
- if (theme != nullptr)
- theme->unload(mSkin);
- }
-}
-
-void CheckBox::draw(Graphics *const graphics)
-{
- BLOCK_START("CheckBox::draw")
- drawBox(graphics);
-
- Font *const font = getFont();
-
- if (mTextChanged)
- {
- mTextChunk.textFont = font;
- mTextChunk.deleteImage();
- mTextChunk.text = mCaption;
- mTextChunk.color = mForegroundColor;
- mTextChunk.color2 = mForegroundColor2;
- font->generate(mTextChunk);
- mTextChanged = false;
- }
-
- const Image *const image = mTextChunk.img;
- if (image != nullptr)
- graphics->drawImage(image, mTextX, mPadding);
-
- BLOCK_END("CheckBox::draw")
-}
-
-void CheckBox::safeDraw(Graphics *const graphics)
-{
- CheckBox::draw(graphics);
-}
-
-void CheckBox::updateAlpha()
-{
- const float alpha = std::max(settings.guiAlpha,
- theme->getMinimumOpacity());
-
- if (mAlpha != alpha)
- {
- mAlpha = alpha;
- if (mSkin != nullptr)
- {
- const ImageRect &rect = mSkin->getBorder();
- for (int a = 0; a < 6; a ++)
- {
- Image *const image = rect.grid[a];
- if (image != nullptr)
- image->setAlpha(mAlpha);
- }
- }
- }
-}
-
-void CheckBox::drawBox(Graphics *const graphics)
-{
- if ((mSkin == nullptr) || !mDrawBox)
- return;
-
- const ImageRect &rect = mSkin->getBorder();
- int index = 0;
-
- if (mEnabled && mVisible == Visible_true)
- {
- if (mSelected)
- {
- if (mHasMouse)
- index = 5;
- else
- index = 1;
- }
- else
- {
- if (mHasMouse)
- index = 4;
- else
- index = 0;
- }
- }
- else
- {
- if (mSelected)
- index = 3;
- else
- index = 2;
- }
- const Image *const box = rect.grid[index];
-
- updateAlpha();
-
- if (box != nullptr)
- {
- graphics->drawImage(box,
- mImagePadding,
- (getHeight() - mImageSize) / 2);
- }
-}
-
-void CheckBox::mouseEntered(MouseEvent& event A_UNUSED)
-{
- mHasMouse = true;
-}
-
-void CheckBox::mouseExited(MouseEvent& event)
-{
- mHasMouse = false;
- ToolTipListener::mouseExited(event);
-}
-
-void CheckBox::keyPressed(KeyEvent& event)
-{
- const InputActionT action = event.getActionId();
-
- if (action == InputAction::GUI_SELECT)
- {
- toggleSelected();
- event.consume();
- }
-}
-
-void CheckBox::adjustSize()
-{
- setHeight(getFont()->getHeight() + 2 * mPadding);
- setWidth(mImagePadding + mImageSize + mSpacing
- + getFont()->getWidth(mCaption) + mPadding);
-}
-
-void CheckBox::mouseClicked(MouseEvent& event)
-{
- if (event.getButton() == MouseButton::LEFT)
- {
- toggleSelected();
- event.consume();
- }
-}
-
-void CheckBox::mouseDragged(MouseEvent& event)
-{
- event.consume();
-}
-
-void CheckBox::toggleSelected()
-{
- mSelected = !mSelected;
- distributeActionEvent();
-}
-
-void CheckBox::setCaption(const std::string& caption)
-{
- if (caption != mCaption)
- mTextChanged = true;
- mCaption = caption;
-}
-
-void CheckBox::setParent(Widget *widget)
-{
- if (mWindow != nullptr)
- mWindow->addWidgetListener(this);
- Widget::setParent(widget);
-}
-
-void CheckBox::widgetHidden(const Event &event A_UNUSED)
-{
- mTextChanged = true;
- mTextChunk.deleteImage();
-}
-
-void CheckBox::setWindow(Widget *const widget)
-{
- if ((widget == nullptr) && (mWindow != nullptr))
- {
- mWindow->removeWidgetListener(this);
- mWindow = nullptr;
- }
- else
- {
- Widget2::setWindow(widget);
- }
-}
diff --git a/src/gui/widgets/checkbox.h b/src/gui/widgets/checkbox.h
deleted file mode 100644
index 27e0a118b..000000000
--- a/src/gui/widgets/checkbox.h
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_CHECKBOX_H
-#define GUI_WIDGETS_CHECKBOX_H
-
-#include "listeners/keylistener.h"
-#include "listeners/tooltiplistener.h"
-
-#include "listeners/widgetlistener.h"
-
-#include "gui/fonts/textchunk.h"
-
-#include "gui/widgets/widget.h"
-
-#include "localconsts.h"
-
-class Skin;
-
-/**
- * Check box widget. Same as the Guichan check box but with custom look.
- *
- * \ingroup GUI
- */
-class CheckBox final : public Widget,
- public ToolTipListener,
- public KeyListener,
- public WidgetListener
-{
- public:
- /**
- * Constructor.
- */
- CheckBox(const Widget2 *const widget,
- const std::string &restrict caption,
- const bool selected = false,
- ActionListener *const listener = nullptr,
- const std::string &restrict eventId = "");
-
- A_DELETE_COPY(CheckBox)
-
- /**
- * Destructor.
- */
- ~CheckBox();
-
- /**
- * Draws the caption, then calls drawBox to draw the check box.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Update the alpha value to the checkbox components.
- */
- void updateAlpha();
-
- /**
- * Draws the check box, not the caption.
- */
- void drawBox(Graphics *const graphics) A_NONNULL(2);
-
- /**
- * Called when the mouse enteres the widget area.
- */
- void mouseEntered(MouseEvent& event) override final;
-
- /**
- * Called when the mouse leaves the widget area.
- */
- void mouseExited(MouseEvent& event) override final;
-
- void keyPressed(KeyEvent& event) override final;
-
- void adjustSize();
-
- /**
- * Checks if the check box is selected.
- *
- * @return True if the check box is selected, false otherwise.
- * @see setSelected
- */
- bool isSelected() const
- { return mSelected; }
-
- /**
- * Sets the check box to be selected or not.
- *
- * @param selected True if the check box should be set as selected.
- * @see isSelected
- */
- void setSelected(const bool selected)
- { mSelected = selected; }
-
- /**
- * Gets the caption of the check box.
- *
- * @return The caption of the check box.
- * @see setCaption
- */
- const std::string &getCaption() const
- { return mCaption; }
-
- /**
- * Sets the caption of the check box. It's advisable to call
- * adjustSize after setting of the caption to adjust the
- * check box's size to fit the caption.
- *
- * @param caption The caption of the check box.
- * @see getCaption, adjustSize
- */
- void setCaption(const std::string& caption);
-
- void mouseClicked(MouseEvent& event) override final;
-
- void mouseDragged(MouseEvent& event) override final;
-
- void setParent(Widget *widget) override final;
-
- void widgetHidden(const Event &event) override final;
-
- void setWindow(Widget *const widget) override final;
-
- private:
- void toggleSelected();
-
- /**
- * True if the check box is selected, false otherwise.
- */
- bool mSelected;
-
- /**
- * Holds the caption of the check box.
- */
- std::string mCaption;
-
- TextChunk mTextChunk;
-
- int mPadding;
- int mImagePadding;
- int mImageSize;
- int mSpacing;
- int mTextX;
- bool mHasMouse;
- bool mDrawBox;
- bool mTextChanged;
-
- static int instances;
- static Skin *mSkin;
- static float mAlpha;
-};
-
-#endif // GUI_WIDGETS_CHECKBOX_H
diff --git a/src/gui/widgets/colorpage.cpp b/src/gui/widgets/colorpage.cpp
deleted file mode 100644
index fa3099c2c..000000000
--- a/src/gui/widgets/colorpage.cpp
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/colorpage.h"
-
-#include "gui/skin.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/models/colormodel.h"
-
-#include "render/graphics.h"
-
-#include "debug.h"
-
-ColorPage::ColorPage(const Widget2 *const widget,
- ListModel *const listModel,
- const std::string &skin) :
- ListBox(widget, listModel, skin)
-{
- mItemPadding = mSkin != nullptr ? mSkin->getOption("itemPadding") : 1;
- const Font *const font = getFont();
- mRowHeight = CAST_U32(font->getHeight() +
- 2 * mItemPadding);
- if (mListModel != nullptr)
- {
- setHeight(CAST_S32(getRowHeight()) *
- mListModel->getNumberOfElements()
- + 2 * mPadding + 20);
- }
-}
-
-ColorPage::~ColorPage()
-{
-}
-
-void ColorPage::draw(Graphics *const graphics)
-{
- BLOCK_START("ColorPage::draw")
-
- const ColorModel *const model = static_cast<const ColorModel*>(
- mListModel);
-
- mHighlightColor.a = CAST_U32(mAlpha * 255.0F);
- updateAlpha();
- Font *const font = getFont();
-
- const int rowHeight = CAST_S32(getRowHeight());
- const int width = mDimension.width;
-
- if (mSelected >= 0)
- {
- graphics->setColor(mHighlightColor);
- graphics->fillRectangle(Rect(mPadding,
- rowHeight * mSelected + mPadding,
- mDimension.width - 2 * mPadding, rowHeight));
-
- const ColorPair *const colors = model->getColorAt(mSelected);
- const std::string str = mListModel->getElementAt(mSelected);
- font->drawString(graphics,
- *colors->color1,
- *colors->color2,
- str,
- (width - font->getWidth(str)) / 2,
- mSelected * rowHeight + mPadding);
- }
-
- const int sz = mListModel->getNumberOfElements();
- for (int i = 0, y = mPadding; i < sz; ++i, y += rowHeight)
- {
- if (i != mSelected)
- {
- const ColorPair *const colors = model->getColorAt(i);
- const std::string str = mListModel->getElementAt(i);
- font->drawString(graphics,
- *colors->color1,
- *colors->color2,
- str,
- (width - font->getWidth(str)) / 2,
- y);
- }
- }
-
- BLOCK_END("ColorPage::draw")
-}
-
-void ColorPage::safeDraw(Graphics *const graphics)
-{
- ColorPage::draw(graphics);
-}
-
-void ColorPage::resetAction()
-{
- setSelected(-1);
-}
-
-void ColorPage::adjustSize()
-{
- BLOCK_START("ColorPage::adjustSize")
- if (mListModel != nullptr)
- {
- setHeight(CAST_S32(getRowHeight()) *
- mListModel->getNumberOfElements() +
- 2 * mPadding + 20);
- }
- BLOCK_END("ColorPage::adjustSize")
-}
diff --git a/src/gui/widgets/colorpage.h b/src/gui/widgets/colorpage.h
deleted file mode 100644
index 6b0d4122b..000000000
--- a/src/gui/widgets/colorpage.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_COLORPAGE_H
-#define GUI_WIDGETS_COLORPAGE_H
-
-#include "gui/widgets/listbox.h"
-
-#include "localconsts.h"
-
-class ColorPage final : public ListBox
-{
- public:
- ColorPage(const Widget2 *const widget,
- ListModel *const listModel,
- const std::string &skin);
-
- A_DELETE_COPY(ColorPage)
-
- ~ColorPage();
-
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void resetAction();
-
- void adjustSize() override final;
-};
-
-#endif // GUI_WIDGETS_COLORPAGE_H
diff --git a/src/gui/widgets/container.cpp b/src/gui/widgets/container.cpp
deleted file mode 100644
index 2da444728..000000000
--- a/src/gui/widgets/container.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/container.h"
-
-#include "gui/gui.h"
-
-#include "debug.h"
-
-Container::Container(const Widget2 *const widget) :
- BasicContainer2(widget)
-{
- setOpaque(Opaque_false);
-}
-
-Container::~Container()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
- removeControls();
-}
-
-void Container::removeControls()
-{
- while (!mWidgets.empty())
- delete mWidgets.front();
-}
-
-bool Container::safeRemove(Widget *const widget)
-{
- for (WidgetListConstIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++iter)
- {
- if (*iter == widget)
- {
- remove(widget);
- return true;
- }
- }
- return false;
-}
diff --git a/src/gui/widgets/container.h b/src/gui/widgets/container.h
deleted file mode 100644
index 2d6e59001..000000000
--- a/src/gui/widgets/container.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_CONTAINER_H
-#define GUI_WIDGETS_CONTAINER_H
-
-#include "gui/widgets/basiccontainer2.h"
-
-/**
- * A widget container.
- *
- * The main difference between the standard Guichan container and this one is
- * that childs added to this container are automatically deleted when the
- * container is deleted.
- *
- * This container is also non-opaque by default.
- */
-class Container notfinal : public BasicContainer2
-{
- public:
- explicit Container(const Widget2 *const widget);
-
- A_DELETE_COPY(Container)
-
- virtual ~Container();
-
- bool safeRemove(Widget *const widget);
-
- void removeControls();
-};
-
-#endif // GUI_WIDGETS_CONTAINER_H
diff --git a/src/gui/widgets/containerplacer.cpp b/src/gui/widgets/containerplacer.cpp
deleted file mode 100644
index 634a87fcd..000000000
--- a/src/gui/widgets/containerplacer.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/containerplacer.h"
-
-#include "gui/widgets/basiccontainer2.h"
-#include "gui/widgets/layoutcell.h"
-
-#include "debug.h"
-
-ContainerPlacer ContainerPlacer::at(const int x, const int y)
-{
- return ContainerPlacer(mContainer,
- mCell != nullptr ? &mCell->at(x, y) : nullptr);
-}
-
-LayoutCell &ContainerPlacer::operator()
- (const int x, const int y, Widget *const wg, const int w, const int h)
-{
- if (mContainer != nullptr)
- mContainer->add(wg);
- if (mCell != nullptr)
- return mCell->place(wg, x, y, w, h);
- return LayoutCell::emptyCell;
-}
diff --git a/src/gui/widgets/containerplacer.h b/src/gui/widgets/containerplacer.h
deleted file mode 100644
index cd1e0221e..000000000
--- a/src/gui/widgets/containerplacer.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_CONTAINERPLACER_H
-#define GUI_WIDGETS_CONTAINERPLACER_H
-
-#include "localconsts.h"
-
-class BasicContainer2;
-class LayoutCell;
-class Widget;
-
-/**
- * This class is a helper for adding widgets to nested tables in a window.
- */
-class ContainerPlacer final
-{
- public:
- explicit ContainerPlacer(BasicContainer2 *const c = nullptr,
- LayoutCell *const lc = nullptr) :
- mContainer(c),
- mCell(lc)
- {}
-
- A_DEFAULT_COPY(ContainerPlacer)
-
- /**
- * Gets the pointed cell.
- */
- LayoutCell &getCell() A_WARN_UNUSED
- { return *mCell; }
-
- /**
- * Returns a placer for the same container but to an inner cell.
- */
- ContainerPlacer at(const int x,
- const int y) A_WARN_UNUSED;
-
- /**
- * Adds the given widget to the container and places it in the layout.
- * @see LayoutArray::place
- */
- LayoutCell &operator()(const int x,
- const int y,
- Widget *const wg,
- const int w = 1,
- const int h = 1);
-
- private:
- BasicContainer2 *mContainer;
- LayoutCell *mCell;
-};
-
-#endif // GUI_WIDGETS_CONTAINERPLACER_H
diff --git a/src/gui/widgets/createwidget.h b/src/gui/widgets/createwidget.h
deleted file mode 100644
index 5f5579d24..000000000
--- a/src/gui/widgets/createwidget.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2015-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_CREATEWIDGET_H
-#define GUI_WIDGETS_CREATEWIDGET_H
-
-#define CREATEWIDGETV(var, type, ...) \
- var = new type(__VA_ARGS__); \
- var->postInit()
-
-#define CREATEWIDGET(type, ...) \
- (new type(__VA_ARGS__))->postInit()
-
-#define CREATEWIDGETV0(var, type) \
- var = new type; \
- var->postInit()
-
-#define CREATEWIDGETR(type, ...) \
- static_cast<type*>(Widget::callPostInit(new type(__VA_ARGS__)))
-
-#define CREATEWIDGETR0(type) \
- static_cast<type*>(Widget::callPostInit(new type))
-
-#endif // GUI_WIDGETS_CREATEWIDGET_H
diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp
deleted file mode 100644
index 87eb14c48..000000000
--- a/src/gui/widgets/desktop.cpp
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 The Mana World Development Team
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/desktop.h"
-
-#include "configuration.h"
-#include "main.h"
-
-#include "gui/skin.h"
-
-#include "gui/widgets/staticbrowserbox.h"
-
-#include "input/inputmanager.h"
-
-#include "render/opengl/opengldebug.h"
-
-#include "resources/imagehelper.h"
-#include "resources/wallpaper.h"
-
-#include "resources/image/image.h"
-
-#include "resources/loaders/rescaledloader.h"
-
-#include "resources/resourcemanager/resourcemanager.h"
-
-#include "render/graphics.h"
-
-#include "debug.h"
-
-Desktop *desktop = nullptr;
-
-Desktop::Desktop(const Widget2 *const widget) :
- Container(widget),
- LinkHandler(),
- WidgetListener(),
- mWallpaper(nullptr),
- mVersionLabel(new StaticBrowserBox(this, Opaque_false,
- "browserbox.xml")),
- mSkin(nullptr),
- mBackgroundGrayColor(getThemeColor(ThemeColorId::BACKGROUND_GRAY)),
- mShowBackground(true)
-{
- mBackgroundColor = getThemeColor(ThemeColorId::BACKGROUND, 128);
-
- addWidgetListener(this);
-
- Wallpaper::loadWallpapers();
-
- if (theme != nullptr)
- mSkin = theme->load("desktop.xml", "");
-
- if (mSkin != nullptr)
- mShowBackground = (mSkin->getOption("showBackground") != 0);
-
- const std::string appName = branding.getValue("appName", std::string());
- if (appName.empty())
- {
- mVersionLabel->addRow(FULL_VERSION);
- }
- else
- {
- mVersionLabel->addRow(strprintf("%s (%s)", FULL_VERSION,
- appName.c_str()));
- }
- mVersionLabel->addRow("copyright",
- "(C) ManaPlus developers, http://manaplus.org");
- mVersionLabel->setLinkHandler(this);
- mVersionLabel->updateHeight();
-}
-
-Desktop::~Desktop()
-{
- if (mWallpaper != nullptr)
- {
- mWallpaper->decRef();
- mWallpaper = nullptr;
- }
- if (theme != nullptr)
- theme->unload(mSkin);
-}
-
-void Desktop::postInit()
-{
- if (mSkin != nullptr)
- {
- addXY(mVersionLabel,
- mSkin->getOption("versionX", 25),
- mSkin->getOption("versionY", 2));
- }
- else
- {
- addXY(mVersionLabel, 25, 2);
- }
-}
-
-void Desktop::reloadWallpaper()
-{
- Wallpaper::loadWallpapers();
- setBestFittingWallpaper();
-}
-
-void Desktop::widgetResized(const Event &event A_UNUSED)
-{
- mVersionLabel->setSize(getWidth(), getHeight());
- mVersionLabel->updateHeight();
- setBestFittingWallpaper();
-}
-
-void Desktop::draw(Graphics *const graphics)
-{
- BLOCK_START("Desktop::draw")
- GLDEBUG_START("Desktop::draw")
-
- const Rect &rect = mDimension;
- const int width = rect.width;
- const int height = rect.height;
- if (mWallpaper != nullptr)
- {
- const int wallpWidth = mWallpaper->getWidth();
- const int wallpHeight = mWallpaper->getHeight();
-
- if (width > wallpWidth || height > wallpHeight)
- {
- graphics->setColor(mBackgroundGrayColor);
- graphics->fillRectangle(Rect(0, 0, width, height));
- }
-
- if (imageHelper->useOpenGL() == RENDER_SOFTWARE)
- {
- graphics->drawImage(mWallpaper,
- (width - wallpWidth) / 2,
- (height - wallpHeight) / 2);
- }
- else
- {
- graphics->drawRescaledImage(mWallpaper, 0, 0, width, height);
- }
- }
- else
- {
- graphics->setColor(mBackgroundGrayColor);
- graphics->fillRectangle(Rect(0, 0, width, height));
- }
-
- Container::draw(graphics);
- GLDEBUG_END()
- BLOCK_END("Desktop::draw")
-}
-
-void Desktop::safeDraw(Graphics *const graphics)
-{
- Desktop::draw(graphics);
-}
-
-void Desktop::setBestFittingWallpaper()
-{
- if (!mShowBackground || !config.getBoolValue("showBackground"))
- return;
-
- const std::string wallpaperName =
- Wallpaper::getWallpaper(getWidth(), getHeight());
-
- Image *const nWallPaper = Theme::getImageFromTheme(wallpaperName);
-
- if (nWallPaper != nullptr)
- {
- if (mWallpaper != nullptr)
- {
- ResourceManager::decRefDelete(mWallpaper);
- mWallpaper = nullptr;
- }
-
- const Rect &rect = mDimension;
- const int width = rect.width;
- const int height = rect.height;
-
- if (imageHelper->useOpenGL() == RENDER_SOFTWARE &&
- (nWallPaper->getWidth() != width ||
- nWallPaper->getHeight() != height))
- {
- // We rescale to obtain a fullscreen wallpaper...
- Image *const newRsclWlPpr = Loader::getRescaled(
- nWallPaper, width, height);
-
- if (newRsclWlPpr != nullptr)
- {
- ResourceManager::decRefDelete(nWallPaper);
- // We replace the resource in the resource manager
- mWallpaper = newRsclWlPpr;
- }
- else
- {
- mWallpaper = nWallPaper;
- }
- }
- else
- {
- mWallpaper = nWallPaper;
- }
- }
- else
- {
- logger->log("Couldn't load %s as wallpaper", wallpaperName.c_str());
- }
-}
-
-void Desktop::handleLink(const std::string &link, MouseEvent *event A_UNUSED)
-{
- if (link == "copyright")
- inputManager.executeAction(InputAction::WINDOW_ABOUT);
-}
diff --git a/src/gui/widgets/desktop.h b/src/gui/widgets/desktop.h
deleted file mode 100644
index 8a655892d..000000000
--- a/src/gui/widgets/desktop.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 The Mana World Development Team
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_DESKTOP_H
-#define GUI_WIDGETS_DESKTOP_H
-
-#include "gui/widgets/container.h"
-
-#include "gui/widgets/linkhandler.h"
-
-#include "listeners/widgetlistener.h"
-
-#include "localconsts.h"
-
-class StaticBrowserBox;
-class Image;
-class Skin;
-
-/**
- * Desktop widget, for drawing a background image and color.
- *
- * It picks the best fitting background image. If the image doesn't fit, a
- * background color is drawn and the image is centered.
- *
- * When the desktop widget is resized, the background image is automatically
- * updated.
- *
- * The desktop also displays the client version in the top-right corner.
- *
- * \ingroup GUI
- */
-class Desktop final : public Container,
- public LinkHandler,
- public WidgetListener
-{
- public:
- explicit Desktop(const Widget2 *const widget);
-
- A_DELETE_COPY(Desktop)
-
- ~Desktop();
-
- /**
- * Has to be called after updates have been loaded.
- */
- void reloadWallpaper();
-
- void widgetResized(const Event &event) override final;
-
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void postInit() override final;
-
- void handleLink(const std::string &link,
- MouseEvent *event) override final;
- private:
- void setBestFittingWallpaper();
-
- Image *mWallpaper;
- StaticBrowserBox *mVersionLabel;
- Skin *mSkin;
- Color mBackgroundGrayColor;
- bool mShowBackground;
-};
-
-extern Desktop *desktop;
-
-#endif // GUI_WIDGETS_DESKTOP_H
diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp
deleted file mode 100644
index cb9eef73d..000000000
--- a/src/gui/widgets/dropdown.cpp
+++ /dev/null
@@ -1,580 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2006-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/dropdown.h"
-
-#include "settings.h"
-
-#include "gui/gui.h"
-#include "gui/skin.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/models/extendedlistmodel.h"
-
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/popuplist.h"
-
-#include "render/graphics.h"
-
-#include "resources/imagerect.h"
-
-#include "debug.h"
-
-int DropDown::instances = 0;
-Image *DropDown::buttons[2][2];
-ImageRect DropDown::skinRect;
-float DropDown::mAlpha = 1.0;
-Skin *DropDown::mSkin = nullptr;
-
-static std::string const dropdownFiles[2] =
-{
- "dropdown.xml",
- "dropdown_pressed.xml"
-};
-
-DropDown::DropDown(const Widget2 *const widget,
- ListModel *const listModel,
- const bool extended,
- const Modal modal,
- ActionListener *const listener,
- const std::string &eventId) :
- ActionListener(),
- BasicContainer(widget),
- KeyListener(),
- MouseListener(),
- FocusListener(),
- SelectionListener(),
- mPopup(CREATEWIDGETR(PopupList, this, listModel, extended, modal)),
- mShadowColor(getThemeColor(ThemeColorId::DROPDOWN_SHADOW)),
- mHighlightColor(getThemeColor(ThemeColorId::HIGHLIGHT)),
- mPadding(1),
- mImagePadding(2),
- mSpacing(0),
- mFoldedUpHeight(0),
- mSelectionListeners(),
- mExtended(extended),
- mDroppedDown(false),
- mPushed(false),
- mIsDragged(false)
-{
- mAllowLogic = false;
- mFrameSize = 2;
- mForegroundColor2 = getThemeColor(ThemeColorId::DROPDOWN_OUTLINE);
-
- mPopup->setHeight(100);
-
- // Initialize graphics
- if (instances == 0 && (theme != nullptr))
- {
- // Load the background skin
- for (int i = 0; i < 2; i ++)
- {
- Skin *const skin = theme->load(dropdownFiles[i], "dropdown.xml");
- if (skin != nullptr)
- {
- if (i == 0)
- mSkin = skin;
- const ImageRect &rect = skin->getBorder();
- for (int f = 0; f < 2; f ++)
- {
- if (rect.grid[f] != nullptr)
- {
- rect.grid[f]->incRef();
- buttons[f][i] = rect.grid[f];
- buttons[f][i]->setAlpha(mAlpha);
- }
- else
- {
- buttons[f][i] = nullptr;
- }
- }
- if (i != 0)
- theme->unload(skin);
- }
- else
- {
- for (int f = 0; f < 2; f ++)
- buttons[f][i] = nullptr;
- }
- }
-
- // get the border skin
- theme->loadRect(skinRect, "dropdown_background.xml", "");
- }
-
- instances++;
-
- setWidth(100);
- setFocusable(true);
- setListModel(listModel);
-
- if (mPopup->getSelected() < 0)
- mPopup->setSelected(0);
-
- addMouseListener(this);
- addKeyListener(this);
- addFocusListener(this);
-
- adjustHeight();
-// mPopup->setForegroundColorAll(getThemeColor(ThemeColorId::DROPDOWN),
-// getThemeColor(ThemeColorId::DROPDOWN_OUTLINE));
- mForegroundColor = getThemeColor(ThemeColorId::DROPDOWN);
- mForegroundColor2 = getThemeColor(ThemeColorId::DROPDOWN_OUTLINE);
-
- if (!eventId.empty())
- setActionEventId(eventId);
-
- if (listener != nullptr)
- addActionListener(listener);
-
- mPopup->adjustSize();
-
- if (mSkin != nullptr)
- {
- mSpacing = mSkin->getOption("spacing");
- mFrameSize = CAST_U32(mSkin->getOption("frameSize"));
- mPadding = mSkin->getPadding();
- mImagePadding = mSkin->getOption("imagePadding");
- }
- adjustHeight();
-}
-
-DropDown::~DropDown()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- instances--;
- if (instances == 0)
- {
- for (int f = 0; f < 2; f ++)
- {
- for (int i = 0; i < 2; i ++)
- {
- if (buttons[f][i] != nullptr)
- buttons[f][i]->decRef();
- }
- }
- if (theme != nullptr)
- {
- theme->unload(mSkin);
- Theme::unloadRect(skinRect);
- }
- }
-}
-
-void DropDown::updateAlpha()
-{
- const float alpha = std::max(settings.guiAlpha,
- theme->getMinimumOpacity());
-
- if (mAlpha != alpha)
- {
- mAlpha = alpha;
-
- if (buttons[0][0] != nullptr)
- buttons[0][0]->setAlpha(mAlpha);
- if (buttons[0][1] != nullptr)
- buttons[0][1]->setAlpha(mAlpha);
- if (buttons[1][0] != nullptr)
- buttons[1][0]->setAlpha(mAlpha);
- if (buttons[1][1] != nullptr)
- buttons[1][1]->setAlpha(mAlpha);
-
- for (int a = 0; a < 9; a++)
- {
- if (skinRect.grid[a] != nullptr)
- skinRect.grid[a]->setAlpha(mAlpha);
- }
- }
-}
-
-void DropDown::draw(Graphics *const graphics)
-{
- BLOCK_START("DropDown::draw")
- int h;
-
- if (mDroppedDown)
- h = mFoldedUpHeight;
- else
- h = mDimension.height;
-
- updateAlpha();
-
- const unsigned int alpha = CAST_U32(mAlpha * 255.0F);
- const int pad = 2 * mPadding;
- mHighlightColor.a = alpha;
- mShadowColor.a = alpha;
-
- ListModel *const model = mPopup->getListModel();
- if ((model != nullptr) && mPopup->getSelected() >= 0)
- {
- Font *const font = getFont();
- if (mExtended)
- {
- const int sel = mPopup->getSelected();
- ExtendedListModel *const model2
- = static_cast<ExtendedListModel *>(model);
- const Image *const image = model2->getImageAt(sel);
- if (image == nullptr)
- {
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor2,
- model->getElementAt(sel),
- mPadding, mPadding);
- }
- else
- {
- graphics->drawImage(image,
- mImagePadding,
- (mDimension.height - image->getHeight()) / 2 + mPadding);
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor2,
- model->getElementAt(sel),
- image->getWidth() + mImagePadding + mSpacing, mPadding);
- }
- }
- else
- {
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor2,
- model->getElementAt(mPopup->getSelected()),
- mPadding, mPadding);
- }
- }
-
- if (isFocused())
- {
- graphics->setColor(mHighlightColor);
- graphics->drawRectangle(Rect(mPadding, mPadding,
- mDimension.width - h - pad, h - pad));
- }
-
- drawButton(graphics);
-
- if (mDroppedDown)
- {
- // Draw two lines separating the ListBox with selected
- // element view.
- const int w = mDimension.width;
- graphics->setColor(mHighlightColor);
- graphics->drawLine(0, h, w, h);
- graphics->setColor(mShadowColor);
- graphics->drawLine(0, h + 1, w, h + 1);
- }
- BLOCK_END("DropDown::draw")
-}
-
-void DropDown::safeDraw(Graphics *const graphics)
-{
- DropDown::draw(graphics);
-}
-
-void DropDown::drawFrame(Graphics *const graphics)
-{
- BLOCK_START("DropDown::drawFrame")
- const int bs2 = CAST_S32(getFrameSize());
- const Rect &rect = mDimension;
- graphics->drawImageRect(0, 0,
- rect.width + bs2, rect.height + bs2,
- skinRect);
- BLOCK_END("DropDown::drawFrame")
-}
-
-void DropDown::safeDrawFrame(Graphics *const graphics)
-{
- BLOCK_START("DropDown::drawFrame")
- const int bs2 = CAST_S32(getFrameSize());
- const Rect &rect = mDimension;
- graphics->drawImageRect(0, 0,
- rect.width + bs2, rect.height + bs2,
- skinRect);
- BLOCK_END("DropDown::drawFrame")
-}
-
-void DropDown::drawButton(Graphics *const graphics)
-{
- const int height = mDroppedDown ? mFoldedUpHeight : mDimension.height;
-
- Image *image = buttons[mDroppedDown][mPushed];
- if (image != nullptr)
- {
- graphics->drawImage(image,
- mDimension.width - image->getWidth() - mImagePadding,
- (height - image->getHeight()) / 2);
- }
-}
-
-void DropDown::keyPressed(KeyEvent& event)
-{
- if (event.isConsumed())
- return;
-
- const InputActionT actionId = event.getActionId();
- PRAGMA45(GCC diagnostic push)
- PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
- switch (actionId)
- {
- case InputAction::GUI_SELECT:
- case InputAction::GUI_SELECT2:
- dropDown();
- break;
-
- case InputAction::GUI_UP:
- setSelected(getSelected() - 1);
- break;
-
- case InputAction::GUI_DOWN:
- setSelected(getSelected() + 1);
- break;
-
- case InputAction::GUI_HOME:
- setSelected(0);
- break;
-
- case InputAction::GUI_END:
- if (mPopup->getListModel() != nullptr)
- {
- setSelected(mPopup->getListModel()->
- getNumberOfElements() - 1);
- }
- break;
-
- default:
- return;
- }
- PRAGMA45(GCC diagnostic pop)
-
- event.consume();
-}
-
-void DropDown::hideDrop(bool event)
-{
- if (event)
- distributeActionEvent();
- mPopup->setVisible(Visible_false);
-}
-
-void DropDown::mousePressed(MouseEvent& event)
-{
- event.consume();
- // If we have a mouse press on the widget.
- if (event.getButton() == MouseButton::LEFT
- && !mDroppedDown && event.getSource() == this)
- {
- mPushed = true;
- dropDown();
- }
- else
- {
- mPushed = false;
- foldUp();
- hideDrop();
- }
-}
-
-void DropDown::mouseReleased(MouseEvent &event)
-{
- if (mIsDragged)
- mPushed = false;
-
- const MouseButtonT button = event.getButton();
- const int x = event.getX();
- const int y = event.getY();
- // Released outside of widget. Can happen when we have modal
- // input focus.
- if ((0 > y || y >= mDimension.height || x < 0 || x >= mDimension.width)
- && button == MouseButton::LEFT)
- {
- if (mIsDragged)
- foldUp();
- }
- else if (button == MouseButton::LEFT)
- {
- mPushed = false;
- }
-
- mIsDragged = false;
-}
-
-void DropDown::mouseDragged(MouseEvent &event)
-{
- mIsDragged = true;
- event.consume();
-}
-
-void DropDown::mouseWheelMovedUp(MouseEvent& event)
-{
- setSelected(getSelected() - 1);
- event.consume();
-}
-
-void DropDown::mouseWheelMovedDown(MouseEvent& event)
-{
- setSelected(getSelected() + 1);
- event.consume();
-}
-
-void DropDown::setSelectedString(const std::string &str)
-{
- ListModel *const listModel = mPopup->getListModel();
- if (listModel == nullptr)
- return;
-
- for (int f = 0; f < listModel->getNumberOfElements(); f ++)
- {
- if (listModel->getElementAt(f) == str)
- {
- setSelected(f);
- break;
- }
- }
-}
-
-std::string DropDown::getSelectedString() const
-{
- ListModel *const listModel = mPopup->getListModel();
- if (listModel == nullptr)
- return "";
-
- return listModel->getElementAt(getSelected());
-}
-
-void DropDown::adjustHeight()
-{
- setHeight(getFont()->getHeight() + 2 * mPadding);
-}
-
-void DropDown::dropDown()
-{
- if (!mDroppedDown)
- {
- if (mParent == nullptr)
- return;
- mDroppedDown = true;
- mFoldedUpHeight = getHeight();
- adjustHeight();
-
- int x = 0;
- int y = 0;
- getAbsolutePosition(x, y);
- const int frame = CAST_S32(mParent->getFrameSize());
- const int pad = mPopup->getPadding();
- const int pad2 = pad * 2;
-
- // here width should be adjusted on some other parameters
- mPopup->setWidth(mDimension.width - pad2 + 8);
- mPopup->show(x - mPadding - frame - 1, y + mDimension.height);
- mPopup->requestMoveToTop();
- mPopup->requestFocus();
- }
-}
-
-void DropDown::foldUp()
-{
- if (mDroppedDown)
- {
- mDroppedDown = false;
- adjustHeight();
- }
-}
-
-int DropDown::getSelected() const
-{
- return mPopup->getSelected();
-}
-
-void DropDown::setSelected(int selected)
-{
- if (selected >= 0)
- mPopup->setSelected(selected);
-}
-
-void DropDown::setListModel(ListModel *const listModel)
-{
- mPopup->setListModel(listModel);
-
- if (mPopup->getSelected() < 0)
- mPopup->setSelected(0);
-
- adjustHeight();
-}
-
-ListModel *DropDown::getListModel()
-{
- return mPopup->getListModel();
-}
-
-void DropDown::action(const ActionEvent &actionEvent A_UNUSED)
-{
- foldUp();
- distributeActionEvent();
-}
-
-Rect DropDown::getChildrenArea()
-{
- if (mDroppedDown)
- {
- // Calculate the children area (with the one pixel border in mind)
- return Rect(1, mFoldedUpHeight + 1,
- mDimension.width - 2, mDimension.height - mFoldedUpHeight - 2);
- }
-
- return Rect();
-}
-
-void DropDown::valueChanged(const SelectionEvent& event A_UNUSED)
-{
-}
-
-void DropDown::updateSelection()
-{
- mDroppedDown = false;
- mPushed = false;
- distributeActionEvent();
- distributeValueChangedEvent();
-}
-
-void DropDown::addSelectionListener(SelectionListener* selectionListener)
-{
- mSelectionListeners.push_back(selectionListener);
-}
-
-void DropDown::removeSelectionListener(SelectionListener* listener)
-{
- mSelectionListeners.remove(listener);
-}
-
-void DropDown::distributeValueChangedEvent()
-{
- for (SelectionListenerIterator iter = mSelectionListeners.begin();
- iter != mSelectionListeners.end();
- ++iter)
- {
- SelectionEvent event(this);
- (*iter)->valueChanged(event);
- }
-}
diff --git a/src/gui/widgets/dropdown.h b/src/gui/widgets/dropdown.h
deleted file mode 100644
index 029850766..000000000
--- a/src/gui/widgets/dropdown.h
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2006-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_DROPDOWN_H
-#define GUI_WIDGETS_DROPDOWN_H
-
-#include "enums/simpletypes/modal.h"
-
-#include "gui/widgets/basiccontainer.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/focuslistener.h"
-#include "listeners/keylistener.h"
-#include "listeners/mouselistener.h"
-#include "listeners/selectionlistener.h"
-
-#include "localconsts.h"
-
-class Image;
-class ListModel;
-class PopupList;
-class Skin;
-
-/**
- * A drop down box from which you can select different values.
- *
- * A ListModel provides the contents of the drop down. To be able to use
- * DropDown you must give DropDown an implemented ListModel which represents
- * your list.
- */
-class DropDown final : public ActionListener,
- public BasicContainer,
- public KeyListener,
- public MouseListener,
- public FocusListener,
- public SelectionListener
-{
- public:
- DropDown(const Widget2 *const widget,
- ListModel *const listModel,
- const bool extended = false,
- const Modal modal = Modal_false,
- ActionListener *const listener = nullptr,
- const std::string &eventId = "");
-
- A_DELETE_COPY(DropDown)
-
- ~DropDown();
-
- /**
- * Update the alpha value to the graphic components.
- */
- void updateAlpha();
-
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void drawFrame(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDrawFrame(Graphics *const graphics) override final
- A_NONNULL(2);
-
- // Inherited from KeyListener
-
- void keyPressed(KeyEvent& event) override final;
-
- // Inherited from MouseListener
-
- void mousePressed(MouseEvent& event) override final;
-
- void mouseReleased(MouseEvent& event) override final;
-
- void mouseDragged(MouseEvent& event) override final;
-
- void mouseWheelMovedUp(MouseEvent& event) override final;
-
- void mouseWheelMovedDown(MouseEvent& event) override final;
-
- void setSelectedString(const std::string &str);
-
- std::string getSelectedString() const A_WARN_UNUSED;
-
- void valueChanged(const SelectionEvent& event) override final A_CONST;
-
- void updateSelection();
-
- void adjustHeight();
-
- void dropDown();
-
- void foldUp();
-
- void hideDrop(bool event = true);
-
- int getSelected() const;
-
- void setSelected(int selected);
-
- void setListModel(ListModel *const listModel);
-
- ListModel *getListModel();
-
- void addSelectionListener(SelectionListener* listener);
-
- void removeSelectionListener(SelectionListener* selectionListener);
-
- Rect getChildrenArea() override;
-
- void action(const ActionEvent &actionEvent) override;
-
- void distributeValueChangedEvent();
-
- protected:
- /**
- * Draws the button with the little down arrow.
- *
- * @param graphics a Graphics object to draw with.
- */
- void drawButton(Graphics *const graphics) A_NONNULL(2);
-
- PopupList *mPopup A_NONNULLPOINTER;
- Color mShadowColor;
- Color mHighlightColor;
- int mPadding;
- int mImagePadding;
- int mSpacing;
- int mFoldedUpHeight;
-
- typedef std::list<SelectionListener*> SelectionListenerList;
- SelectionListenerList mSelectionListeners;
- typedef SelectionListenerList::iterator SelectionListenerIterator;
-
- bool mExtended;
- bool mDroppedDown;
- bool mPushed;
- bool mIsDragged;
-
- // Add own Images.
- static int instances;
- static Image *buttons[2][2];
- static ImageRect skinRect;
- static float mAlpha;
- static Skin *mSkin;
-};
-
-#endif // GUI_WIDGETS_DROPDOWN_H
diff --git a/src/gui/widgets/emotepage.cpp b/src/gui/widgets/emotepage.cpp
deleted file mode 100644
index 27721a86c..000000000
--- a/src/gui/widgets/emotepage.cpp
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/emotepage.h"
-
-#include "render/graphics.h"
-
-#include "render/vertexes/imagecollection.h"
-
-#include "resources/imageset.h"
-
-#include "resources/loaders/imagesetloader.h"
-
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-
-#include "debug.h"
-
-namespace
-{
- const unsigned int emoteWidth = 17;
- const unsigned int emoteHeight = 18;
-} // namespace
-
-EmotePage::EmotePage(const Widget2 *const widget) :
- Widget(widget),
- MouseListener(),
- WidgetListener(),
- mEmotes(Loader::getImageSet(
- "graphics/sprites/chatemotes.png", emoteWidth, emoteHeight)),
- mVertexes(new ImageCollection),
- mSelectedIndex(-1)
-{
- addMouseListener(this);
- addWidgetListener(this);
- mAllowLogic = false;
-}
-
-EmotePage::~EmotePage()
-{
- if (mEmotes != nullptr)
- {
- mEmotes->decRef();
- mEmotes = nullptr;
- }
- delete2(mVertexes);
-}
-
-void EmotePage::draw(Graphics *const graphics)
-{
- BLOCK_START("EmotePage::draw")
-
- if (mRedraw)
- {
- if (mEmotes == nullptr)
- return;
-
- const STD_VECTOR<Image*> &images = mEmotes->getImages();
-
- const unsigned int width = mDimension.width;
- unsigned int x = 0;
- unsigned int y = 0;
-
- mRedraw = false;
- mVertexes->clear();
- FOR_EACH (STD_VECTOR<Image*>::const_iterator, it, images)
- {
- const Image *const image = *it;
- if (image != nullptr)
- {
- graphics->calcTileCollection(mVertexes, image, x, y);
- x += emoteWidth;
- if (x + emoteWidth > width)
- {
- x = 0;
- y += emoteHeight;
- }
- }
- }
- graphics->finalize(mVertexes);
- }
- graphics->drawTileCollection(mVertexes);
-
- BLOCK_END("EmotePage::draw")
-}
-
-void EmotePage::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("EmotePage::safeDraw")
-
- if (mEmotes == nullptr)
- return;
-
- const STD_VECTOR<Image*> &images = mEmotes->getImages();
-
- const unsigned int width = mDimension.width;
- unsigned int x = 0;
- unsigned int y = 0;
-
- FOR_EACH (STD_VECTOR<Image*>::const_iterator, it, images)
- {
- const Image *const image = *it;
- if (image != nullptr)
- {
- graphics->drawImage(image, x, y);
- x += emoteWidth;
- if (x + emoteWidth > width)
- {
- x = 0;
- y += emoteHeight;
- }
- }
- }
-
- BLOCK_END("EmotePage::safeDraw")
-}
-
-void EmotePage::mousePressed(MouseEvent &event)
-{
- mSelectedIndex = getIndexFromGrid(event.getX(), event.getY());
- event.consume();
- distributeActionEvent();
-}
-
-int EmotePage::getIndexFromGrid(const int x, const int y) const
-{
- const int width = mDimension.width;
- if (x < 0 || x > width || y < 0 || y > mDimension.height)
- return -1;
- const int cols = width / emoteWidth;
- const int index = (y / emoteHeight) * cols + (x / emoteWidth);
- if (index >= CAST_S32(mEmotes->size()))
- return -1;
- return index;
-}
-
-void EmotePage::resetAction()
-{
- mSelectedIndex = -1;
-}
-
-void EmotePage::widgetResized(const Event &event A_UNUSED)
-{
- mRedraw = true;
-}
-
-void EmotePage::widgetMoved(const Event &event A_UNUSED)
-{
- mRedraw = true;
-}
diff --git a/src/gui/widgets/emotepage.h b/src/gui/widgets/emotepage.h
deleted file mode 100644
index a833e569f..000000000
--- a/src/gui/widgets/emotepage.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_EMOTEPAGE_H
-#define GUI_WIDGETS_EMOTEPAGE_H
-
-#include "listeners/mouselistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "gui/widgets/widget.h"
-
-#include "localconsts.h"
-
-class ImageCollection;
-
-class EmotePage final : public Widget,
- public MouseListener,
- public WidgetListener
-{
- public:
- explicit EmotePage(const Widget2 *const widget);
-
- A_DELETE_COPY(EmotePage)
-
- ~EmotePage();
-
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void mousePressed(MouseEvent &event) override final;
-
- int getIndexFromGrid(const int x, const int y) const;
-
- void widgetResized(const Event &event A_UNUSED) override final;
-
- void widgetMoved(const Event &event A_UNUSED) override final;
-
- void resetAction();
-
- int getSelectedIndex() const
- { return mSelectedIndex; }
-
- private:
- ImageSet *mEmotes;
- ImageCollection *mVertexes;
- int mSelectedIndex;
-};
-
-#endif // GUI_WIDGETS_EMOTEPAGE_H
diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp
deleted file mode 100644
index 37acf7263..000000000
--- a/src/gui/widgets/emoteshortcutcontainer.cpp
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 Aethyra Development Team
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/emoteshortcutcontainer.h"
-
-#include "settings.h"
-
-#include "input/inputmanager.h"
-
-#include "gui/viewport.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/shortcut/emoteshortcut.h"
-
-#include "gui/popups/popupmenu.h"
-#include "gui/popups/textpopup.h"
-
-#include "input/inputactionoperators.h"
-
-#include "resources/emotesprite.h"
-
-#include "resources/db/emotedb.h"
-
-#include "resources/image/image.h"
-
-#include "resources/sprite/animatedsprite.h"
-
-#include "utils/stringutils.h"
-
-#include "debug.h"
-
-static const int MAX_ITEMS = 48;
-
-EmoteShortcutContainer::EmoteShortcutContainer(Widget2 *restrict const
- widget) :
- ShortcutContainer(widget),
- mEmoteImg(),
- mEmoteClicked(false),
- mEmoteMoved(0)
-{
- if (mBackgroundImg != nullptr)
- mBackgroundImg->setAlpha(settings.guiAlpha);
-
- // Setup emote sprites
- for (int i = 0; i <= EmoteDB::getLast(); i++)
- {
- const EmoteSprite *const sprite = EmoteDB::getSprite(i, true);
- if ((sprite != nullptr) && (sprite->sprite != nullptr))
- mEmoteImg.push_back(sprite);
- }
-
- mMaxItems = MAX_ITEMS;
-}
-
-EmoteShortcutContainer::~EmoteShortcutContainer()
-{
-}
-
-void EmoteShortcutContainer::setWidget2(const Widget2 *restrict const widget)
- restrict2
-{
- Widget2::setWidget2(widget);
- mForegroundColor = getThemeColor(ThemeColorId::TEXT);
- mForegroundColor2 = getThemeColor(ThemeColorId::TEXT_OUTLINE);
-}
-
-void EmoteShortcutContainer::draw(Graphics *restrict graphics) restrict2
-{
- if (emoteShortcut == nullptr)
- return;
-
- BLOCK_START("EmoteShortcutContainer::draw")
- if (settings.guiAlpha != mAlpha)
- {
- if (mBackgroundImg != nullptr)
- mBackgroundImg->setAlpha(mAlpha);
- mAlpha = settings.guiAlpha;
- }
-
- Font *const font = getFont();
- drawBackground(graphics);
-
- unsigned sz = CAST_U32(mEmoteImg.size());
- if (sz > mMaxItems)
- sz = mMaxItems;
- for (unsigned i = 0; i < sz; i++)
- {
- const EmoteSprite *restrict const emoteImg = mEmoteImg[i];
- if (emoteImg != nullptr)
- {
- const AnimatedSprite *restrict const sprite = emoteImg->sprite;
- if (sprite != nullptr)
- {
- sprite->draw(graphics,
- (i % mGridWidth) * mBoxWidth + 2,
- (i / mGridWidth) * mBoxHeight + 10);
- }
- }
- }
- for (unsigned i = 0; i < mMaxItems; i++)
- {
- const int emoteX = (i % mGridWidth) * mBoxWidth;
- const int emoteY = (i / mGridWidth) * mBoxHeight;
-
- // Draw emote keyboard shortcut.
- const std::string key = inputManager.getKeyValueString(
- InputAction::EMOTE_1 + i);
-
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor2,
- key,
- emoteX + 2, emoteY + 2);
- }
-
- BLOCK_END("EmoteShortcutContainer::draw")
-}
-
-void EmoteShortcutContainer::safeDraw(Graphics *restrict graphics) restrict2
-{
- if (emoteShortcut == nullptr)
- return;
-
- BLOCK_START("EmoteShortcutContainer::draw")
- if (settings.guiAlpha != mAlpha)
- {
- if (mBackgroundImg != nullptr)
- mBackgroundImg->setAlpha(mAlpha);
- mAlpha = settings.guiAlpha;
- }
-
- Font *const font = getFont();
- safeDrawBackground(graphics);
-
- unsigned sz = CAST_U32(mEmoteImg.size());
- if (sz > mMaxItems)
- sz = mMaxItems;
- for (unsigned i = 0; i < sz; i++)
- {
- const EmoteSprite *restrict const emoteImg = mEmoteImg[i];
- if (emoteImg != nullptr)
- {
- const AnimatedSprite *restrict const sprite = emoteImg->sprite;
- if (sprite != nullptr)
- {
- sprite->draw(graphics,
- (i % mGridWidth) * mBoxWidth + 2,
- (i / mGridWidth) * mBoxHeight + 10);
- }
- }
- }
- for (unsigned i = 0; i < mMaxItems; i++)
- {
- const int emoteX = (i % mGridWidth) * mBoxWidth;
- const int emoteY = (i / mGridWidth) * mBoxHeight;
-
- // Draw emote keyboard shortcut.
- const std::string key = inputManager.getKeyValueString(
- InputAction::EMOTE_1 + i);
-
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor2,
- key,
- emoteX + 2, emoteY + 2);
- }
-
- BLOCK_END("EmoteShortcutContainer::draw")
-}
-
-void EmoteShortcutContainer::mouseDragged(MouseEvent &restrict event A_UNUSED)
- restrict2
-{
-}
-
-void EmoteShortcutContainer::mousePressed(MouseEvent &restrict event) restrict2
-{
- if (event.isConsumed())
- return;
-
- if (event.getButton() == MouseButton::LEFT)
- {
- if (emoteShortcut == nullptr)
- return;
-
- const int index = getIndexFromGrid(event.getX(), event.getY());
-
- if (index == -1)
- return;
-
- event.consume();
- // Stores the selected emote if there is one.
- if (emoteShortcut->isEmoteSelected())
- {
- emoteShortcut->setEmote(index);
- emoteShortcut->setEmoteSelected(0);
- }
- else if (emoteShortcut->getEmote(index) != 0u)
- {
- mEmoteClicked = true;
- }
- }
- else if (event.getButton() == MouseButton::RIGHT)
- {
- if (popupMenu != nullptr)
- {
- event.consume();
- popupMenu->showEmoteType();
- }
- }
-}
-
-void EmoteShortcutContainer::mouseReleased(MouseEvent &restrict event)
- restrict2
-{
- if (emoteShortcut == nullptr)
- return;
-
- if (event.getButton() == MouseButton::LEFT)
- {
- const int index = getIndexFromGrid(event.getX(), event.getY());
-
- if (emoteShortcut->isEmoteSelected())
- emoteShortcut->setEmoteSelected(0);
-
- if (index == -1)
- {
- mEmoteMoved = 0;
- return;
- }
-
- if (mEmoteMoved != 0u)
- {
- emoteShortcut->setEmotes(index, mEmoteMoved);
- mEmoteMoved = 0;
- }
- else if ((emoteShortcut->getEmote(index) != 0u) && mEmoteClicked)
- {
- emoteShortcut->useEmote(index + 1);
- }
-
- mEmoteClicked = false;
- }
-}
-
-void EmoteShortcutContainer::mouseMoved(MouseEvent &restrict event) restrict2
-{
- if ((emoteShortcut == nullptr) || (textPopup == nullptr))
- return;
-
- const int index = getIndexFromGrid(event.getX(), event.getY());
-
- if (index == -1)
- return;
-
- textPopup->setVisible(Visible_false);
-
- if (CAST_SIZE(index) < mEmoteImg.size() && (mEmoteImg[index] != nullptr))
- {
- const EmoteSprite *restrict const sprite = mEmoteImg[index];
- textPopup->show(viewport->mMouseX, viewport->mMouseY,
- strprintf("%s, %d", sprite->name.c_str(), sprite->id));
- }
-}
-
-void EmoteShortcutContainer::mouseExited(MouseEvent &restrict event A_UNUSED)
- restrict2
-{
- if (textPopup != nullptr)
- textPopup->setVisible(Visible_false);
-}
-
-void EmoteShortcutContainer::widgetHidden(const Event &restrict event A_UNUSED)
- restrict2
-{
- if (textPopup != nullptr)
- textPopup->setVisible(Visible_false);
-}
diff --git a/src/gui/widgets/emoteshortcutcontainer.h b/src/gui/widgets/emoteshortcutcontainer.h
deleted file mode 100644
index 14895d7a0..000000000
--- a/src/gui/widgets/emoteshortcutcontainer.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 Aethyra Development Team
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_EMOTESHORTCUTCONTAINER_H
-#define GUI_WIDGETS_EMOTESHORTCUTCONTAINER_H
-
-#include "gui/widgets/shortcutcontainer.h"
-
-struct EmoteSprite;
-
-/**
- * An emote shortcut container. Used to quickly use emoticons.
- *
- * \ingroup GUI
- */
-class EmoteShortcutContainer final : public ShortcutContainer
-{
- public:
- /**
- * Constructor. Initializes the graphic.
- */
- explicit EmoteShortcutContainer(Widget2 *restrict const widget);
-
- A_DELETE_COPY(EmoteShortcutContainer)
-
- /**
- * Destructor.
- */
- ~EmoteShortcutContainer();
-
- /**
- * Draws the items.
- */
- void draw(Graphics *restrict graphics)
- restrict2 override final A_NONNULL(2);
-
- void safeDraw(Graphics *restrict graphics)
- restrict2 override final A_NONNULL(2);
-
- /**
- * Handles mouse when dragged.
- */
- void mouseDragged(MouseEvent &restrict event)
- restrict2 override final A_CONST;
-
- /**
- * Handles mouse when pressed.
- */
- void mousePressed(MouseEvent &restrict event) restrict2 override final;
-
- /**
- * Handles mouse release.
- */
- void mouseReleased(MouseEvent &restrict event)
- restrict2 override final;
-
- void mouseMoved(MouseEvent &restrict event) restrict2 override final;
-
- void mouseExited(MouseEvent &restrict event) restrict2 override final;
-
- void widgetHidden(const Event &restrict event)
- restrict2 override final;
-
- void setWidget2(const Widget2 *restrict const widget)
- restrict2 override final;
-
- private:
- STD_VECTOR<const EmoteSprite*> mEmoteImg;
-
- bool mEmoteClicked;
- unsigned char mEmoteMoved;
-};
-
-#endif // GUI_WIDGETS_EMOTESHORTCUTCONTAINER_H
diff --git a/src/gui/widgets/equipmentbox.h b/src/gui/widgets/equipmentbox.h
deleted file mode 100644
index 055332b2b..000000000
--- a/src/gui/widgets/equipmentbox.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_EQUIPMENTBOX_H
-#define GUI_WIDGETS_EQUIPMENTBOX_H
-
-#include "localconsts.h"
-
-class Image;
-
-struct EquipmentBox final
-{
- EquipmentBox(const int x0, const int y0, Image *const img) :
- x(x0), y(y0), image(img)
- { }
-
- A_DELETE_COPY(EquipmentBox)
-
- int x;
- int y;
- Image *image;
-};
-
-#endif // GUI_WIDGETS_EQUIPMENTBOX_H
diff --git a/src/gui/widgets/equipmentpage.h b/src/gui/widgets/equipmentpage.h
deleted file mode 100644
index f868478fb..000000000
--- a/src/gui/widgets/equipmentpage.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_EQUIPMENTPAGE_H
-#define GUI_WIDGETS_EQUIPMENTPAGE_H
-
-#include "utils/vector.h"
-
-#include "localconsts.h"
-
-class PlayerBox;
-
-struct EquipmentBox;
-
-struct EquipmentPage final
-{
- EquipmentPage() :
- boxes(),
- x(0),
- y(0),
- width(0),
- height(0),
- showPlayerBox(true)
- { }
-
- A_DELETE_COPY(EquipmentPage)
-
- STD_VECTOR<EquipmentBox*> boxes;
- int x;
- int y;
- int width;
- int height;
- bool showPlayerBox;
-};
-
-#endif // GUI_WIDGETS_EQUIPMENTPAGE_H
diff --git a/src/gui/widgets/extendedlistbox.cpp b/src/gui/widgets/extendedlistbox.cpp
deleted file mode 100644
index 271160726..000000000
--- a/src/gui/widgets/extendedlistbox.cpp
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/extendedlistbox.h"
-
-#include "gui/models/extendedlistmodel.h"
-
-#include "gui/skin.h"
-
-#include "gui/fonts/font.h"
-
-#include "render/graphics.h"
-
-#include "debug.h"
-
-ExtendedListBox::ExtendedListBox(const Widget2 *const widget,
- ListModel *const listModel,
- const std::string &skin,
- const unsigned int rowHeight) :
- ListBox(widget, listModel, skin),
- mImagePadding(mSkin != nullptr ? mSkin->getOption("imagePadding") : 0),
- mSpacing(mSkin != nullptr ? mSkin->getOption("spacing") : 0),
- mHeight(0),
- mListItems(),
- mSelectedItems()
-{
- if (rowHeight != 0u)
- mRowHeight = rowHeight;
-}
-
-ExtendedListBox::~ExtendedListBox()
-{
-}
-
-void ExtendedListBox::draw(Graphics *const graphics)
-{
- if (mListModel == nullptr)
- return;
-
- BLOCK_START("ExtendedListBox::draw")
- ExtendedListModel *const model = static_cast<ExtendedListModel *>(
- mListModel);
-
- updateAlpha();
- Font *const font = getFont();
-
- const int height = CAST_S32(mRowHeight);
- const int pad2 = 2 + mPadding;
- const int width = mDimension.width;
- int textPos = (height - font->getHeight()) / 2 + mPadding;
- if (textPos < 0)
- textPos = 0;
-
- const int sz = mListModel->getNumberOfElements();
- mListItems.clear();
- mSelectedItems.clear();
- int y = 0;
- const int insideWidth = width - pad2;
- for (int f = 0; f < sz; f ++)
- {
- int row = f;
- bool useImage = true;
- std::string str = mListModel->getElementAt(f);
- int strWidth = font->getWidth(str) + 8;
-
- const Image *const image = model->getImageAt(row);
- if (image != nullptr)
- strWidth += image->getWidth() + mImagePadding;
-
- STD_VECTOR<ExtendedListBoxItem> &list =
- row == mSelected ? mSelectedItems : mListItems;
-
- if (insideWidth < strWidth)
- {
- const size_t strSize = str.size();
- size_t divPos = strSize / 2;
- if (divPos > 0 && CAST_U8(
- str[divPos - 1]) >= 0xc0)
- {
- divPos --;
- }
- for (size_t d = divPos; d > 10; d --)
- {
- if (str[d] == 32)
- {
- divPos = d + 1;
- break;
- }
- }
- list.push_back(ExtendedListBoxItem(row,
- str.substr(0, divPos), useImage, y));
- str = str.substr(divPos);
- y += height;
- useImage = false;
- }
- list.push_back(ExtendedListBoxItem(row, str, useImage, y));
-
- y += height;
- }
- mHeight = y + height;
-
- const size_t itemsSz = mListItems.size();
- const size_t selSz = mSelectedItems.size();
- int minY = -1;
- int maxY = -1;
- for (size_t f = 0; f < selSz; f ++)
- {
- const ExtendedListBoxItem &item = mSelectedItems[f];
- const int y1 = item.y;
- if (minY == -1)
- minY = y1;
- if (maxY < y1)
- maxY = y1;
- }
-
- if (minY != -1)
- {
- mHighlightColor.a = CAST_U32(mAlpha * 255.0F);
- graphics->setColor(mHighlightColor);
- graphics->fillRectangle(Rect(mPadding, minY + mPadding,
- width - pad2, maxY - minY + height));
- }
-
- for (size_t f = 0; f < itemsSz; ++f)
- {
- const ExtendedListBoxItem &item = mListItems[f];
- const int row1 = item.row;
- if (item.image)
- {
- const Image *const image = model->getImageAt(row1);
- if (image != nullptr)
- {
- graphics->drawImage(image,
- mImagePadding,
- item.y + (height - image->getHeight()) / 2 + mPadding);
- }
- }
- }
-
- for (size_t f = 0; f < itemsSz; ++f)
- {
- const ExtendedListBoxItem &item = mListItems[f];
- const int row1 = item.row;
- const int y1 = item.y;
- const Image *const image = model->getImageAt(row1);
- if ((image == nullptr) || !item.image)
- {
- font->drawString(graphics,
- mForegroundColor, mForegroundColor2,
- item.text,
- mPadding, y1 + textPos);
- }
- else
- {
- font->drawString(graphics,
- mForegroundColor, mForegroundColor2,
- item.text,
- image->getWidth() + mImagePadding + mSpacing, y1 + textPos);
- }
- }
-
- for (size_t f = 0; f < selSz; ++f)
- {
- const ExtendedListBoxItem &item = mSelectedItems[f];
- const int row1 = item.row;
- const int y1 = item.y;
- const Image *const image = model->getImageAt(row1);
- if ((image == nullptr) || !item.image)
- {
- font->drawString(graphics,
- mForegroundSelectedColor, mForegroundSelectedColor2,
- item.text,
- mPadding, y1 + textPos);
- }
- else
- {
- font->drawString(graphics,
- mForegroundSelectedColor, mForegroundSelectedColor2,
- item.text,
- image->getWidth() + mImagePadding + mSpacing, y1 + textPos);
- }
- }
-
- for (size_t f = 0; f < selSz; ++f)
- {
- const ExtendedListBoxItem &item = mSelectedItems[f];
- const int row1 = item.row;
- if (item.image)
- {
- const Image *const image = model->getImageAt(row1);
- if (image != nullptr)
- {
- graphics->drawImage(image,
- mImagePadding,
- item.y + (height - image->getHeight()) / 2 + mPadding);
- }
- }
- }
-
- BLOCK_END("ExtendedListBox::draw")
-}
-
-void ExtendedListBox::safeDraw(Graphics *const graphics)
-{
- ExtendedListBox::draw(graphics);
-}
-
-void ExtendedListBox::adjustSize()
-{
- if (mHeight != 0)
- setHeight(mHeight + 2 * mPadding);
- else
- ListBox::adjustSize();
-}
-
-int ExtendedListBox::getSelectionByMouse(const int y) const
-{
- if (mListItems.empty() && mSelectedItems.empty())
- return ListBox::getSelectionByMouse(y);
-
- const int height = CAST_S32(mRowHeight);
- const size_t itemsSz = mListItems.size();
- for (size_t f = 0; f < itemsSz; f ++)
- {
- const ExtendedListBoxItem &item = mListItems[f];
- const int y2 = item.y + mPadding;
- if (y2 <= y && y2 + height > y)
- return item.row;
- }
-
- const size_t selSz = mSelectedItems.size();
- for (size_t f = 0; f < selSz; f ++)
- {
- const ExtendedListBoxItem &item = mSelectedItems[f];
- const int y2 = item.y + mPadding;
- if (y2 <= y && y2 + height > y)
- return item.row;
- }
- return 0;
-}
diff --git a/src/gui/widgets/extendedlistbox.h b/src/gui/widgets/extendedlistbox.h
deleted file mode 100644
index 6d97ee6d3..000000000
--- a/src/gui/widgets/extendedlistbox.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_EXTENDEDLISTBOX_H
-#define GUI_WIDGETS_EXTENDEDLISTBOX_H
-
-#include "gui/widgets/extendedlistboxitem.h"
-#include "gui/widgets/listbox.h"
-
-class ExtendedListBox final : public ListBox
-{
- public:
- /**
- * Constructor.
- */
- ExtendedListBox(const Widget2 *const widget,
- ListModel *const listModel,
- const std::string &skin,
- const unsigned int rowHeight = 13);
-
- A_DELETE_COPY(ExtendedListBox)
-
- ~ExtendedListBox();
-
- /**
- * Draws the list box.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void adjustSize() override;
-
- int getSelectionByMouse(const int y) const override final;
-
- protected:
- int mImagePadding;
- int mSpacing;
- int mHeight;
- STD_VECTOR<ExtendedListBoxItem> mListItems;
- STD_VECTOR<ExtendedListBoxItem> mSelectedItems;
-};
-
-#endif // GUI_WIDGETS_EXTENDEDLISTBOX_H
diff --git a/src/gui/widgets/extendedlistboxitem.h b/src/gui/widgets/extendedlistboxitem.h
deleted file mode 100644
index dc2d8b459..000000000
--- a/src/gui/widgets/extendedlistboxitem.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_EXTENDEDLISTBOXITEM_H
-#define GUI_WIDGETS_EXTENDEDLISTBOXITEM_H
-
-#include <string>
-
-#include "localconsts.h"
-
-struct ExtendedListBoxItem final
-{
- ExtendedListBoxItem(const int row0,
- const std::string &text0,
- const bool image0,
- const int y0) :
- row(row0),
- text(text0),
- image(image0),
- y(y0)
- {
- }
-
- A_DEFAULT_COPY(ExtendedListBoxItem)
-
- int row;
- std::string text;
- bool image;
- int y;
-};
-
-#endif // GUI_WIDGETS_EXTENDEDLISTBOXITEM_H
diff --git a/src/gui/widgets/flowcontainer.cpp b/src/gui/widgets/flowcontainer.cpp
deleted file mode 100644
index ee3181636..000000000
--- a/src/gui/widgets/flowcontainer.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/flowcontainer.h"
-
-#include "debug.h"
-
-FlowContainer::FlowContainer(const Widget2 *const widget,
- const int boxWidth,
- const int boxHeight) :
- Container(widget),
- WidgetListener(),
- mBoxWidth(boxWidth),
- mBoxHeight(boxHeight),
- mGridWidth(1),
- mGridHeight(1)
-{
- addWidgetListener(this);
- if (mBoxWidth == 0)
- mBoxWidth = 1;
- if (mBoxHeight == 0)
- mBoxHeight = 1;
-}
-
-void FlowContainer::widgetResized(const Event &event A_UNUSED)
-{
- if (getWidth() < mBoxWidth)
- {
- setWidth(mBoxWidth);
- return;
- }
-
- const int itemCount = CAST_S32(mWidgets.size());
-
- if (mBoxWidth == 0)
- mGridWidth = getWidth();
- else
- mGridWidth = getWidth() / mBoxWidth;
-
- if (mGridWidth < 1)
- mGridWidth = 1;
-
- mGridHeight = itemCount / mGridWidth;
-
- if (itemCount % mGridWidth != 0 || mGridHeight < 1)
- ++mGridHeight;
-
- int height = mGridHeight * mBoxHeight;
-
- if (getHeight() != height)
- {
- setHeight(height);
- return;
- }
-
- int i = 0;
- height = 0;
- for (WidgetList::const_iterator it = mWidgets.begin();
- it != mWidgets.end(); ++it)
- {
- const int x = i % mGridWidth * mBoxWidth;
- (*it)->setPosition(x, height);
-
- i++;
-
- if (i % mGridWidth == 0)
- height += mBoxHeight;
- }
-}
-
-void FlowContainer::add(Widget *const widget)
-{
- if (widget == nullptr)
- return;
-
- Container::add(widget);
- widget->setSize(mBoxWidth, mBoxHeight);
- widgetResized(Event(nullptr));
-}
diff --git a/src/gui/widgets/flowcontainer.h b/src/gui/widgets/flowcontainer.h
deleted file mode 100644
index be91853a6..000000000
--- a/src/gui/widgets/flowcontainer.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_FLOWCONTAINER_H
-#define GUI_WIDGETS_FLOWCONTAINER_H
-
-#include "gui/widgets/container.h"
-
-#include "listeners/widgetlistener.h"
-
-#include "localconsts.h"
-
-/**
- * A container that arranges its contents like words on a page.
- *
- * \ingroup GUI
- */
-class FlowContainer final : public Container,
- public WidgetListener
-{
- public:
- /**
- * Constructor. Initializes the shortcut container.
- */
- FlowContainer(const Widget2 *const widget,
- const int boxWidth,
- const int boxHeight);
-
- A_DELETE_COPY(FlowContainer)
-
- /**
- * Destructor.
- */
- ~FlowContainer()
- { }
-
- /**
- * Invoked when a widget changes its size. This is used to determine
- * the new height of the container.
- */
- void widgetResized(const Event &event) override final;
-
- int getBoxWidth() const noexcept2 A_WARN_UNUSED
- { return mBoxWidth; }
-
- int getBoxHeight() const noexcept2 A_WARN_UNUSED
- { return mBoxHeight; }
-
- void add(Widget *const widget) override final;
-
- private:
- int mBoxWidth;
- int mBoxHeight;
- int mGridWidth, mGridHeight;
-};
-
-#endif // GUI_WIDGETS_FLOWCONTAINER_H
diff --git a/src/gui/widgets/guitable.cpp b/src/gui/widgets/guitable.cpp
deleted file mode 100644
index 4a0f88246..000000000
--- a/src/gui/widgets/guitable.cpp
+++ /dev/null
@@ -1,675 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/guitable.h"
-
-#include "settings.h"
-
-#include "gui/gui.h"
-
-#include "gui/models/tablemodel.h"
-
-#include "listeners/guitableactionlistener.h"
-
-#include "render/graphics.h"
-
-#include "utils/delete2.h"
-#include "utils/dtor.h"
-
-#include "debug.h"
-
-float GuiTable::mAlpha = 1.0;
-
-GuiTable::GuiTable(const Widget2 *const widget,
- TableModel *const initial_model,
- const Opaque opacity) :
- Widget(widget),
- MouseListener(),
- KeyListener(),
- TableModelListener(),
- mModel(nullptr),
- mTopWidget(nullptr),
- mActionListeners2(),
- mHighlightColor(getThemeColor(ThemeColorId::HIGHLIGHT)),
- mSelectedRow(-1),
- mSelectedColumn(-1),
- mLinewiseMode(false),
- mWrappingEnabled(false),
- mOpaque(opacity),
- mSelectableGui(true)
-{
- mAllowLogic = false;
- mBackgroundColor = getThemeColor(ThemeColorId::BACKGROUND);
-
- setModel(initial_model);
- setFocusable(true);
-
- addMouseListener(this);
- addKeyListener(this);
-}
-
-GuiTable::~GuiTable()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- uninstallActionListeners();
- delete2(mModel);
-}
-
-const TableModel *GuiTable::getModel() const
-{
- return mModel;
-}
-
-void GuiTable::setModel(TableModel *const new_model)
-{
- if (mModel != nullptr)
- {
- uninstallActionListeners();
- mModel->removeListener(this);
- }
-
- mModel = new_model;
- installActionListeners();
-
- new_model->installListener(this);
- recomputeDimensions();
-}
-
-void GuiTable::recomputeDimensions()
-{
- if (mModel == nullptr)
- return;
-
- const int rows_nr = mModel->getRows();
- const int columns_nr = mModel->getColumns();
- int width = 0;
-
- if (mSelectableGui)
- {
- if (mSelectedRow >= rows_nr)
- mSelectedRow = rows_nr - 1;
-
- if (mSelectedColumn >= columns_nr)
- mSelectedColumn = columns_nr - 1;
- }
-
- for (int i = 0; i < columns_nr; i++)
- width += getColumnWidth(i);
-
- setWidth(width);
- setHeight(getRowHeight() * rows_nr);
-}
-
-void GuiTable::setSelected(const int row, const int column)
-{
- mSelectedColumn = column;
- mSelectedRow = row;
-}
-
-int GuiTable::getSelectedRow() const
-{
- return mSelectedRow;
-}
-
-int GuiTable::getSelectedColumn() const
-{
- return mSelectedColumn;
-}
-
-int GuiTable::getRowHeight() const
-{
- return mModel->getRowHeight() + 4; // border
-}
-
-int GuiTable::getColumnWidth(const int i) const
-{
- return mModel->getColumnWidth(i) + 4; // border
-}
-
-void GuiTable::setSelectedRow(const int selected)
-{
- if (!mSelectableGui)
- {
- mSelectedRow = -1;
- }
- else
- {
- const int rows = mModel->getRows();
- if (selected < 0 && !mWrappingEnabled)
- {
- mSelectedRow = -1;
- }
- else if (selected >= rows && mWrappingEnabled)
- {
- mSelectedRow = 0;
- }
- else if ((selected >= rows && !mWrappingEnabled) ||
- (selected < 0 && mWrappingEnabled))
- {
- mSelectedRow = rows - 1;
- }
- else
- {
- mSelectedRow = selected;
- }
- }
-}
-
-void GuiTable::setSelectedColumn(const int selected)
-{
- const int columns = mModel->getColumns();
- if ((selected >= columns && mWrappingEnabled) ||
- (selected < 0 && !mWrappingEnabled))
- {
- mSelectedColumn = 0;
- }
- else if ((selected >= columns && !mWrappingEnabled) ||
- (selected < 0 && mWrappingEnabled))
- {
- mSelectedColumn = columns - 1;
- }
- else
- {
- mSelectedColumn = selected;
- }
-}
-
-void GuiTable::uninstallActionListeners()
-{
- delete_all(mActionListeners2);
- mActionListeners2.clear();
-}
-
-void GuiTable::installActionListeners()
-{
- const int rows = mModel->getRows();
- const int columns = mModel->getColumns();
-
- for (int row = 0; row < rows; ++row)
- {
- for (int column = 0; column < columns; ++column)
- {
- Widget *const widget = mModel->getElementAt(row, column);
- if (widget != nullptr)
- {
- mActionListeners2.push_back(new GuiTableActionListener(
- this, widget, row, column));
- }
- }
- }
-
- setFocusHandler(getFocusHandler());
-}
-
-// -- widget ops
-void GuiTable::draw(Graphics *const graphics)
-{
- if (getRowHeight() == 0)
- return;
-
- BLOCK_START("GuiTable::draw")
- if (settings.guiAlpha != mAlpha)
- mAlpha = settings.guiAlpha;
-
- const Rect &rect = mDimension;
- const int width = rect.width;
- const int height = rect.height;
- const int y = rect.y;
- if (mOpaque == Opaque_true)
- {
- mBackgroundColor.a = CAST_U32(mAlpha * 255.0F);
- graphics->setColor(mBackgroundColor);
- graphics->fillRectangle(Rect(0, 0, width, height));
- }
-
- // First, determine how many rows we need to draw,
- // and where we should start.
- int rHeight = getRowHeight();
- if (rHeight == 0)
- rHeight = 1;
- int first_row = -(y / rHeight);
-
- if (first_row < 0)
- first_row = 0;
-
- unsigned int rows_nr = CAST_U32(1 +
- height / rHeight); // May overestimate by one.
- unsigned int max_rows_nr;
- if (mModel->getRows() < first_row)
- {
- max_rows_nr = 0U;
- }
- else
- {
- max_rows_nr = CAST_U32(
- mModel->getRows() - first_row); // clip if neccessary:
- }
- if (max_rows_nr < rows_nr)
- rows_nr = max_rows_nr;
-
- // Now determine the first and last column
- // Take the easy way out; these are usually bounded and all visible.
- const unsigned first_column = 0;
- const unsigned last_column1 = CAST_U32(
- mModel->getColumns());
-
- int y_offset = first_row * rHeight;
-
- for (unsigned int r = CAST_U32(first_row);
- r < CAST_U32(first_row) + rows_nr;
- ++r)
- {
- int x_offset = 0;
-
- for (unsigned c = first_column; c + 1 <= last_column1; ++c)
- {
- Widget *const widget = mModel->getElementAt(CAST_S32(r),
- CAST_S32(c));
- const int cWidth = CAST_S32(getColumnWidth(
- CAST_S32(c)));
- if (widget != nullptr)
- {
- Rect bounds(x_offset, y_offset, cWidth, rHeight);
-
- if (widget == mTopWidget)
- {
- bounds.height = widget->getHeight();
- bounds.width = widget->getWidth();
- }
-
- widget->setDimension(bounds);
-
- if (mSelectedRow > -1)
- {
- mHighlightColor.a = CAST_U32(
- mAlpha * 255.0F);
- graphics->setColor(mHighlightColor);
-
- if (mLinewiseMode && r == CAST_U32(
- mSelectedRow) && c == 0)
- {
- graphics->fillRectangle(Rect(0, y_offset,
- width, rHeight));
- }
- else if (!mLinewiseMode && mSelectedColumn > 0
- && c == CAST_U32(mSelectedColumn)
- && r == CAST_U32(mSelectedRow))
- {
- graphics->fillRectangle(Rect(
- x_offset, y_offset, cWidth, rHeight));
- }
- }
- graphics->pushClipArea(bounds);
- widget->draw(graphics);
- graphics->popClipArea();
- }
-
- x_offset += cWidth;
- }
-
- y_offset += rHeight;
- }
-
- if (mTopWidget != nullptr)
- {
- const Rect &bounds = mTopWidget->getDimension();
- graphics->pushClipArea(bounds);
- mTopWidget->draw(graphics);
- graphics->popClipArea();
- }
- BLOCK_END("GuiTable::draw")
-}
-
-void GuiTable::safeDraw(Graphics *const graphics)
-{
- if (getRowHeight() == 0)
- return;
-
- BLOCK_START("GuiTable::draw")
- if (settings.guiAlpha != mAlpha)
- mAlpha = settings.guiAlpha;
-
- const Rect &rect = mDimension;
- const int width = rect.width;
- const int height = rect.height;
- const int y = rect.y;
- if (mOpaque == Opaque_true)
- {
- mBackgroundColor.a = CAST_U32(mAlpha * 255.0F);
- graphics->setColor(mBackgroundColor);
- graphics->fillRectangle(Rect(0, 0, width, height));
- }
-
- // First, determine how many rows we need to draw,
- // and where we should start.
- int rHeight = getRowHeight();
- if (rHeight == 0)
- rHeight = 1;
- int first_row = -(y / rHeight);
-
- if (first_row < 0)
- first_row = 0;
-
- unsigned int rows_nr = CAST_U32(
- 1 + height / rHeight); // May overestimate by one.
- unsigned int max_rows_nr;
- if (mModel->getRows() < first_row)
- {
- max_rows_nr = 0;
- }
- else
- {
- max_rows_nr = CAST_U32(
- mModel->getRows() - first_row); // clip if neccessary:
- }
- if (max_rows_nr < rows_nr)
- rows_nr = max_rows_nr;
-
- // Now determine the first and last column
- // Take the easy way out; these are usually bounded and all visible.
- const unsigned int first_column = 0;
- const unsigned int last_column1 = CAST_U32(
- mModel->getColumns());
-
- int y_offset = first_row * rHeight;
-
- for (unsigned int r = CAST_U32(first_row);
- r < CAST_U32(first_row + CAST_S32(rows_nr));
- ++r)
- {
- int x_offset = 0;
-
- for (unsigned c = first_column; c + 1 <= last_column1; ++c)
- {
- Widget *const widget = mModel->getElementAt(CAST_S32(r),
- CAST_S32(c));
- const int cWidth = CAST_S32(getColumnWidth(
- CAST_S32(c)));
- if (widget != nullptr)
- {
- Rect bounds(x_offset, y_offset, cWidth, rHeight);
-
- if (widget == mTopWidget)
- {
- bounds.height = widget->getHeight();
- bounds.width = widget->getWidth();
- }
-
- widget->setDimension(bounds);
-
- if (mSelectedRow > -1)
- {
- mHighlightColor.a = CAST_U32(
- mAlpha * 255.0F);
- graphics->setColor(mHighlightColor);
-
- if (mLinewiseMode && r == CAST_U32(
- mSelectedRow) && c == 0)
- {
- graphics->fillRectangle(Rect(0, y_offset,
- width, rHeight));
- }
- else if (!mLinewiseMode && mSelectedColumn > 0
- && c == CAST_U32(mSelectedColumn)
- && r == CAST_U32(mSelectedRow))
- {
- graphics->fillRectangle(Rect(
- x_offset, y_offset, cWidth, rHeight));
- }
- }
- graphics->pushClipArea(bounds);
- widget->safeDraw(graphics);
- graphics->popClipArea();
- }
-
- x_offset += cWidth;
- }
-
- y_offset += rHeight;
- }
-
- if (mTopWidget != nullptr)
- {
- const Rect &bounds = mTopWidget->getDimension();
- graphics->pushClipArea(bounds);
- mTopWidget->safeDraw(graphics);
- graphics->popClipArea();
- }
- BLOCK_END("GuiTable::draw")
-}
-
-void GuiTable::moveToTop(Widget *const widget)
-{
- Widget::moveToTop(widget);
- mTopWidget = widget;
-}
-
-void GuiTable::moveToBottom(Widget *const widget)
-{
- Widget::moveToBottom(widget);
- if (widget == mTopWidget)
- mTopWidget = nullptr;
-}
-
-Rect GuiTable::getChildrenArea()
-{
- return Rect(0, 0, mDimension.width, mDimension.height);
-}
-
-// -- KeyListener notifications
-void GuiTable::keyPressed(KeyEvent& event)
-{
- const InputActionT action = event.getActionId();
-
- if (action == InputAction::GUI_SELECT)
- {
- distributeActionEvent();
- event.consume();
- }
- else if (action == InputAction::GUI_UP)
- {
- setSelectedRow(mSelectedRow - 1);
- event.consume();
- }
- else if (action == InputAction::GUI_DOWN)
- {
- setSelectedRow(mSelectedRow + 1);
- event.consume();
- }
- else if (action == InputAction::GUI_LEFT)
- {
- setSelectedColumn(mSelectedColumn - 1);
- event.consume();
- }
- else if (action == InputAction::GUI_RIGHT)
- {
- setSelectedColumn(mSelectedColumn + 1);
- event.consume();
- }
- else if (action == InputAction::GUI_HOME)
- {
- setSelectedRow(0);
- setSelectedColumn(0);
- event.consume();
- }
- else if (action == InputAction::GUI_END && (mModel != nullptr))
- {
- setSelectedRow(mModel->getRows() - 1);
- setSelectedColumn(mModel->getColumns() - 1);
- event.consume();
- }
-}
-
-// -- MouseListener notifications
-void GuiTable::mousePressed(MouseEvent& event)
-{
- if (!mSelectableGui)
- return;
-
- if (event.getButton() == MouseButton::LEFT)
- {
- const int row = getRowForY(event.getY());
- const int column = getColumnForX(event.getX());
-
- if (row > -1 && column > -1 &&
- row < mModel->getRows() && column < mModel->getColumns())
- {
- mSelectedColumn = column;
- mSelectedRow = row;
- event.consume();
- }
-
- distributeActionEvent();
- }
-}
-
-void GuiTable::mouseWheelMovedUp(MouseEvent& event)
-{
- if (isFocused())
- {
- const int selRow = getSelectedRow();
- if (selRow > 0 || (selRow == 0 && mWrappingEnabled))
- setSelectedRow(selRow - 1);
- event.consume();
- }
-}
-
-void GuiTable::mouseWheelMovedDown(MouseEvent& event)
-{
- if (isFocused())
- {
- setSelectedRow(getSelectedRow() + 1);
- event.consume();
- }
-}
-
-void GuiTable::mouseDragged(MouseEvent& event)
-{
- if (event.getButton() != MouseButton::LEFT)
- return;
-
- // Make table selection update on drag
- const int x = std::max(0, event.getX());
- const int y = std::max(0, event.getY());
-
- setSelectedRow(getRowForY(y));
- setSelectedColumn(getColumnForX(x));
-}
-
-void GuiTable::modelUpdated(const bool completed)
-{
- if (completed)
- {
- recomputeDimensions();
- installActionListeners();
- }
- else
- { // before the update?
- mTopWidget = nullptr; // No longer valid in general
- uninstallActionListeners();
- }
-}
-
-Widget *GuiTable::getWidgetAt(int x, int y)
-{
- if (mModel == nullptr)
- return nullptr;
-
- const int row = getRowForY(y);
- const int column = getColumnForX(x);
-
- if (mTopWidget != nullptr &&
- mTopWidget->getDimension().isPointInRect(x, y))
- {
- return mTopWidget;
- }
-
- if (row > -1 && column > -1)
- {
- Widget *const w = mModel->getElementAt(row, column);
- if (w != nullptr && w->isFocusable())
- return w;
- }
- return nullptr;
-}
-
-int GuiTable::getRowForY(const int y) const
-{
- int row = -1;
-
- const int rowHeight = getRowHeight();
- if (rowHeight > 0)
- row = y / rowHeight;
-
- if (row < 0 || row >= mModel->getRows())
- return -1;
- return row;
-}
-
-int GuiTable::getColumnForX(const int x) const
-{
- int column;
- int delta = 0;
-
- const int colnum = mModel->getColumns();
- for (column = 0; column < colnum; column ++)
- {
- delta += getColumnWidth(column);
- if (x <= delta)
- break;
- }
-
- if (column < 0 || column >= colnum)
- return -1;
- return column;
-}
-
-void GuiTable::setFocusHandler(FocusHandler *const focusHandler)
-{
- // add check for focusHandler. may be need remove it?
-
- if (focusHandler == nullptr)
- return;
-
- Widget::setFocusHandler(focusHandler);
-
- const int rows = mModel->getRows();
- const int cols = mModel->getColumns();
- for (int r = 0; r < rows; ++r)
- {
- for (int c = 0; c < cols ; ++c)
- {
- Widget *const w = mModel->getElementAt(r, c);
- if (w != nullptr)
- w->setFocusHandler(focusHandler);
- }
- }
-}
-
-void GuiTable::requestFocus()
-{
- if (mFocusHandler == nullptr)
- return;
- Widget::requestFocus();
-}
diff --git a/src/gui/widgets/guitable.h b/src/gui/widgets/guitable.h
deleted file mode 100644
index 30eb73523..000000000
--- a/src/gui/widgets/guitable.h
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_GUITABLE_H
-#define GUI_WIDGETS_GUITABLE_H
-
-#include "localconsts.h"
-
-#include "enums/simpletypes/opaque.h"
-
-#include "listeners/keylistener.h"
-#include "listeners/mouselistener.h"
-#include "listeners/tablemodellistener.h"
-
-#include "gui/widgets/widget.h"
-
-class GuiTableActionListener;
-class TableModel;
-
-/**
- * A table, with rows and columns made out of sub-widgets. Largely inspired by
- * (and can be thought of as a generalisation of) the guichan listbox
- * implementation.
- *
- * Normally you want this within a ScrollArea.
- *
- * \ingroup GUI
- */
-class GuiTable final : public Widget,
- public MouseListener,
- public KeyListener,
- public TableModelListener
-{
- // so that the action listener can call distributeActionEvent
- friend class GuiTableActionListener;
-
- public:
- GuiTable(const Widget2 *const widget,
- TableModel *const initial_model,
- const Opaque opacity = Opaque_true);
-
- A_DELETE_COPY(GuiTable)
-
- ~GuiTable();
-
- /**
- * Sets the table model
- *
- * Note that actions issued by widgets returned from the model will
- * update the table selection, but only AFTER any event handlers
- * installed within the widget have been triggered. To be notified
- * after such an update, add an action listener to the table instead.
- */
- void setModel(TableModel *const m);
-
- /**
- * Retrieves the active table model
- */
- const TableModel *getModel() const A_WARN_UNUSED RETURNS_NONNULL;
-
- void setSelected(const int row, const int column);
-
- int getSelectedRow() const A_WARN_UNUSED;
-
- int getSelectedColumn() const A_WARN_UNUSED;
-
- void setSelectedRow(const int selected);
-
- void setSelectedColumn(const int selected);
-
- bool isWrappingEnabled() const noexcept2 A_WARN_UNUSED
- { return mWrappingEnabled; }
-
- void setWrappingEnabled(bool wrappingEnabled)
- { mWrappingEnabled = wrappingEnabled; }
-
- Rect getChildrenArea() override final A_WARN_UNUSED;
-
- /**
- * Toggle whether to use linewise selection mode, in which the table
- * selects an entire line at a time, rather than a single cell.
- *
- * Note that column information is tracked even in linewise selection
- * mode;
- *
- * this mode therefore only affects visualisation.
- *
- * Disabled by default.
- *
- * \param linewise: Whether to enable linewise selection mode
- */
- void setLinewiseSelection(bool linewise)
- { mLinewiseMode = linewise; }
-
- // Inherited from Widget
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- Widget *getWidgetAt(int x, int y) override final A_WARN_UNUSED;
-
- void moveToTop(Widget *const widget) override final;
-
- void moveToBottom(Widget *const widget) override final;
-
- void setFocusHandler(FocusHandler *const focusHandler) override final;
-
- // Inherited from KeyListener
- void keyPressed(KeyEvent& event) override final;
-
- /**
- * Sets the table to be opaque, that is sets the table
- * to display its background.
- *
- * @param opaque True if the table should be opaque, false otherwise.
- */
- void setOpaque(Opaque opaque)
- { mOpaque = opaque; }
-
- /**
- * Checks if the table is opaque, that is if the table area displays
- * its background.
- *
- * @return True if the table is opaque, false otherwise.
- */
- bool isOpaque() const noexcept2 A_WARN_UNUSED
- { return mOpaque == Opaque_true; }
-
- // Inherited from MouseListener
- void mousePressed(MouseEvent& event) override final;
-
- void mouseWheelMovedUp(MouseEvent& event) override final;
-
- void mouseWheelMovedDown(MouseEvent& event) override final;
-
- void mouseDragged(MouseEvent& event) override final;
-
- // Constraints inherited from TableModelListener
- void modelUpdated(const bool completed) override final;
-
- void requestFocus() override;
-
- void setSelectableGui(bool b)
- { mSelectableGui = b; }
-
- protected:
- /** Frees all action listeners on inner widgets. */
- void uninstallActionListeners();
-
- /** Installs all action listeners on inner widgets. */
- void installActionListeners();
-
- int getRowHeight() const A_WARN_UNUSED;
-
- int getColumnWidth(const int i) const A_WARN_UNUSED;
-
- private:
- int getRowForY(const int y) const A_WARN_UNUSED; // -1 on error
-
- int getColumnForX(const int x) const A_WARN_UNUSED; // -1 on error
-
- void recomputeDimensions();
-
- static float mAlpha;
-
- TableModel *mModel A_NONNULLPOINTER;
-
- /** If someone moves a fresh widget to the top, we must display it. */
- Widget *mTopWidget;
-
- /** Vector for compactness; used as a list in practice. */
- STD_VECTOR<GuiTableActionListener *> mActionListeners2;
-
- /**
- * Holds the background color of the table.
- */
- Color mHighlightColor;
-
- int mSelectedRow;
- int mSelectedColumn;
-
- bool mLinewiseMode;
- bool mWrappingEnabled;
- Opaque mOpaque;
- bool mSelectableGui;
-};
-
-#endif // GUI_WIDGETS_GUITABLE_H
diff --git a/src/gui/widgets/horizontcontainer.cpp b/src/gui/widgets/horizontcontainer.cpp
deleted file mode 100644
index 8a026329a..000000000
--- a/src/gui/widgets/horizontcontainer.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/horizontcontainer.h"
-
-#include "debug.h"
-
-HorizontContainer::HorizontContainer(const Widget2 *const widget,
- const int height,
- const int spacing) :
- Container(widget),
- WidgetListener(),
- ToolTipListener(),
- mSpacing(spacing),
- mCount(0),
- mLastX(spacing)
-{
- setHeight(height);
- addWidgetListener(this);
- addMouseListener(this);
-}
-
-void HorizontContainer::add(Widget *const widget)
-{
- add(widget, mSpacing);
-}
-
-void HorizontContainer::add(Widget *const widget, const int spacing)
-{
- if (widget == nullptr)
- return;
-
- Container::add(widget);
- widget->setPosition(mLastX, spacing);
- mCount++;
- mLastX += widget->getWidth() + 2 * mSpacing;
-}
-
-void HorizontContainer::clear()
-{
- Container::clear();
-
- mCount = 0;
-}
-
-void HorizontContainer::widgetResized(const Event &event A_UNUSED)
-{
-}
diff --git a/src/gui/widgets/horizontcontainer.h b/src/gui/widgets/horizontcontainer.h
deleted file mode 100644
index a010f172e..000000000
--- a/src/gui/widgets/horizontcontainer.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_HORIZONTCONTAINER_H
-#define GUI_WIDGETS_HORIZONTCONTAINER_H
-
-#include "gui/widgets/container.h"
-
-#include "listeners/tooltiplistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "localconsts.h"
-
-/**
- * A widget container.
- *
- * This container places it's contents veritcally.
- */
-class HorizontContainer final : public Container,
- public WidgetListener,
- public ToolTipListener
-{
- public:
- HorizontContainer(const Widget2 *const widget,
- const int height,
- const int spacing);
-
- A_DELETE_COPY(HorizontContainer)
-
- void add(Widget *const widget) override final;
-
- void add(Widget *const widget, const int spacing);
-
- void clear() override;
-
- void widgetResized(const Event &event) override final A_CONST;
-
- protected:
- int mSpacing;
- int mCount;
- int mLastX;
-};
-
-#endif // GUI_WIDGETS_HORIZONTCONTAINER_H
diff --git a/src/gui/widgets/icon.cpp b/src/gui/widgets/icon.cpp
deleted file mode 100644
index dbe46a21a..000000000
--- a/src/gui/widgets/icon.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/icon.h"
-
-#include "gui/gui.h"
-
-#include "render/graphics.h"
-
-#include "resources/image/image.h"
-
-#include "resources/loaders/imageloader.h"
-
-#include "debug.h"
-
-Icon::Icon(const Widget2 *const widget,
- const std::string &file,
- const AutoRelease autoRelease) :
- Widget(widget),
- mImage(Loader::getImage(file)),
- mAutoRelease(autoRelease)
-{
- if (mImage != nullptr)
- {
- const SDL_Rect &bounds = mImage->mBounds;
- setSize(bounds.w, bounds.h);
- }
- mAllowLogic = false;
-}
-
-Icon::Icon(const Widget2 *const widget,
- Image *const image,
- const AutoRelease autoRelease) :
- Widget(widget),
- mImage(image),
- mAutoRelease(autoRelease)
-{
- if (mImage != nullptr)
- {
- const SDL_Rect &bounds = mImage->mBounds;
- setSize(bounds.w, bounds.h);
- }
- mAllowLogic = false;
-}
-
-Icon::~Icon()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
- if ((mImage != nullptr) && mAutoRelease == AutoRelease_true)
- mImage->decRef();
-}
-
-void Icon::setImage(Image *const image)
-{
- mImage = image;
- if (mImage != nullptr)
- {
- const SDL_Rect &bounds = mImage->mBounds;
- setSize(bounds.w, bounds.h);
- }
-}
-
-void Icon::draw(Graphics *const graphics)
-{
- BLOCK_START("Icon::draw")
- if (mImage != nullptr)
- {
- graphics->drawImage(mImage,
- (mDimension.width - mImage->mBounds.w) / 2,
- (mDimension.height - mImage->mBounds.h) / 2);
- }
- BLOCK_END("Icon::draw")
-}
-
-void Icon::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("Icon::draw")
- if (mImage != nullptr)
- {
- graphics->drawImage(mImage,
- (mDimension.width - mImage->mBounds.w) / 2,
- (mDimension.height - mImage->mBounds.h) / 2);
- }
- BLOCK_END("Icon::draw")
-}
diff --git a/src/gui/widgets/icon.h b/src/gui/widgets/icon.h
deleted file mode 100644
index f0849d505..000000000
--- a/src/gui/widgets/icon.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_ICON_H
-#define GUI_WIDGETS_ICON_H
-
-#include "gui/widgets/widget.h"
-
-#include "enums/simpletypes/autorelease.h"
-
-#include "localconsts.h"
-
-class Image;
-
-/**
- * An icon.
- *
- * \ingroup GUI
- */
-class Icon final : public Widget
-{
- public:
- /**
- * Constructor.
- */
- Icon(const Widget2 *const widget,
- const std::string &filename,
- const AutoRelease autoRelease = AutoRelease_false);
-
- /**
- * Constructor, uses an existing Image.
- */
- Icon(const Widget2 *const widget,
- Image *const image,
- const AutoRelease autoRelease = AutoRelease_false);
-
- A_DELETE_COPY(Icon)
-
- ~Icon();
-
- /**
- * Gets the current Image.
- */
- Image *getImage() const noexcept2 A_WARN_UNUSED
- { return mImage; }
-
- /**
- * Sets the image to display.
- */
- void setImage(Image *const image);
-
- /**
- * Draws the Icon.
- */
- void draw(Graphics *const g) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const g) override final A_NONNULL(2);
-
- private:
- Image *mImage;
- AutoRelease mAutoRelease;
-};
-
-#endif // GUI_WIDGETS_ICON_H
diff --git a/src/gui/widgets/inttextfield.cpp b/src/gui/widgets/inttextfield.cpp
deleted file mode 100644
index 41436d310..000000000
--- a/src/gui/widgets/inttextfield.cpp
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/inttextfield.h"
-
-#ifdef USE_SDL2
-#include "enums/input/keyvalue.h"
-#endif // USE_SDL2
-
-#include "utils/stringutils.h"
-
-#include <sstream>
-
-#include "debug.h"
-
-IntTextField::IntTextField(const Widget2 *const widget,
- const int def,
- const int min,
- const int max,
- const Enable enabled,
- const int width) :
- TextField(widget, toString(def)),
- mMin(0),
- mMax(0),
- mDefault(def),
- mValue(def)
-{
- if (min != 0 || max != 0)
- setRange(min, max);
-
- setEnabled(enabled == Enable_true);
- if (width != 0)
- setWidth(width);
-}
-
-void IntTextField::keyPressed(KeyEvent &event)
-{
- const InputActionT action = event.getActionId();
-
- if (action == InputAction::GUI_DELETE
- || action == InputAction::GUI_BACKSPACE)
- {
- setText(std::string());
- if (mSendAlwaysEvents)
- distributeActionEvent();
-
- event.consume();
- }
-
-#ifdef USE_SDL2
- const int val = event.getKey().getValue();
- if (val != KeyValue::TEXTINPUT)
- return;
-
- const std::string str = event.getText();
- if (str.empty())
- return;
- const size_t sz = str.size();
- for (size_t f = 0; f < sz; f ++)
- {
- const char chr = str[f];
- if (chr < '0' || chr > '9')
- return;
- }
-#else // USE_SDL2
-
- if (!event.getKey().isNumber())
- return;
-#endif // USE_SDL2
-
- TextField::keyPressed(event);
-
- std::istringstream s(getText());
- int i;
- s >> i;
- setValue(i);
- if (mSendAlwaysEvents)
- distributeActionEvent();
-}
-
-void IntTextField::setRange(const int min, const int max)
-{
- mMin = min;
- mMax = max;
-
- if (mValue < mMin)
- mValue = mMin;
- else if (mValue > mMax)
- mValue = mMax;
-
- if (mDefault < mMin)
- mDefault = mMin;
- else if (mDefault > mMax)
- mDefault = mMax;
-}
-
-int IntTextField::getValue() const
-{
- return getText().empty() ? mMin : mValue;
-}
-
-void IntTextField::setValue(const int i)
-{
- if (i < mMin)
- mValue = mMin;
- else if (i > mMax)
- mValue = mMax;
- else
- mValue = i;
-
- const std::string valStr = toString(mValue);
- setText(valStr);
- setCaretPosition(CAST_U32(valStr.length()) + 1);
-}
-
-void IntTextField::setDefaultValue(const int value)
-{
- if (value < mMin)
- mDefault = mMin;
- else if (value > mMax)
- mDefault = mMax;
- else
- mDefault = value;
-}
-
-void IntTextField::reset()
-{
- setValue(mDefault);
-}
diff --git a/src/gui/widgets/inttextfield.h b/src/gui/widgets/inttextfield.h
deleted file mode 100644
index b8ac8564f..000000000
--- a/src/gui/widgets/inttextfield.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_INTTEXTFIELD_H
-#define GUI_WIDGETS_INTTEXTFIELD_H
-
-#include "enums/simpletypes/enable.h"
-
-#include "gui/widgets/textfield.h"
-
-/**
- * TextBox which only accepts numbers as input.
- */
-class IntTextField final : public TextField
-{
- public:
- /**
- * Constructor, sets default value.
- */
- explicit IntTextField(const Widget2 *const widget,
- const int def = 0,
- const int min = 0,
- const int max = 0,
- const Enable enabled = Enable_true,
- const int width = 0);
-
- A_DELETE_COPY(IntTextField)
-
- /**
- * Sets the minimum and maximum values of the text box.
- */
- void setRange(const int minimum, const int maximum);
-
- /**
- * Returns the value in the text box.
- */
- int getValue() const A_WARN_UNUSED;
-
- /**
- * Reset the field to the default value.
- */
- void reset();
-
- /**
- * Set the value of the text box to the specified value.
- */
- void setValue(const int value);
-
- /**
- * Set the default value of the text box to the specified value.
- */
- void setDefaultValue(const int value);
-
- /**
- * Responds to key presses.
- */
- void keyPressed(KeyEvent &event) override final;
-
- private:
- int mMin; /**< Minimum value */
- int mMax; /**< Maximum value */
- int mDefault; /**< Default value */
- int mValue; /**< Current value */
-};
-
-#endif // GUI_WIDGETS_INTTEXTFIELD_H
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
deleted file mode 100644
index b6ac3cff3..000000000
--- a/src/gui/widgets/itemcontainer.cpp
+++ /dev/null
@@ -1,1322 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/itemcontainer.h"
-
-#include "dragdrop.h"
-#include "settings.h"
-
-#include "being/playerinfo.h"
-
-#include "gui/gui.h"
-#include "gui/skin.h"
-#include "gui/viewport.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/shortcut/itemshortcut.h"
-
-#include "gui/popups/itempopup.h"
-
-#include "gui/windows/chatwindow.h"
-#include "gui/windows/inventorywindow.h"
-#include "gui/windows/shopwindow.h"
-#include "gui/windows/shortcutwindow.h"
-#include "gui/windows/itemamountwindow.h"
-#include "gui/windows/maileditwindow.h"
-#include "gui/windows/npcdialog.h"
-
-#include "input/inputmanager.h"
-
-#include "net/inventoryhandler.h"
-#include "net/net.h"
-#include "net/mail2handler.h"
-#include "net/npchandler.h"
-#include "net/tradehandler.h"
-
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include "render/vertexes/imagecollection.h"
-
-#include "resources/iteminfo.h"
-
-#include <algorithm>
-
-#include "debug.h"
-
-namespace
-{
- class ItemIdPair final
- {
- public:
- A_DELETE_COPY(ItemIdPair)
-
- ItemIdPair(const int id, Item *const item) :
- mId(id), mItem(item)
- {
- }
-
- int mId;
- Item* mItem;
- };
-
- class SortItemAlphaFunctor final
- {
- public:
- A_DEFAULT_COPY(SortItemAlphaFunctor)
-
- bool operator() (const ItemIdPair *const pair1,
- const ItemIdPair *const pair2) const
- {
- const Item *const item1 = pair1->mItem;
- const Item *const item2 = pair2->mItem;
- if ((item1 == nullptr) || (item2 == nullptr))
- return false;
-
- const std::string name1 = item1->getInfo().getName(
- item1->getColor());
- const std::string name2 = item2->getInfo().getName(
- item2->getColor());
- if (name1 == name2)
- {
- return item1->getInvIndex() <
- item2->getInvIndex();
- }
- return name1 < name2;
- }
- } itemAlphaInvSorter;
-
- class SortItemIdFunctor final
- {
- public:
- A_DEFAULT_COPY(SortItemIdFunctor)
-
- bool operator() (const ItemIdPair *const pair1,
- const ItemIdPair *const pair2) const
- {
- if ((pair1->mItem == nullptr) || (pair2->mItem == nullptr))
- return false;
-
- const int id1 = pair1->mItem->getId();
- const int id2 = pair2->mItem->getId();
- if (id1 == id2)
- {
- return pair1->mItem->getInvIndex() <
- pair2->mItem->getInvIndex();
- }
- return id1 < id2;
- }
- } itemIdInvSorter;
-
- class SortItemWeightFunctor final
- {
- public:
- A_DEFAULT_COPY(SortItemWeightFunctor)
-
- bool operator() (const ItemIdPair *const pair1,
- const ItemIdPair *const pair2) const
- {
- if ((pair1->mItem == nullptr) || (pair2->mItem == nullptr))
- return false;
-
- const int w1 = pair1->mItem->getInfo().getWeight();
- const int w2 = pair2->mItem->getInfo().getWeight();
- if (w1 == w2)
- {
- const std::string name1 =
- pair1->mItem->getInfo().getName();
- const std::string name2 =
- pair2->mItem->getInfo().getName();
- if (name1 == name2)
- {
- return pair1->mItem->getInvIndex() <
- pair2->mItem->getInvIndex();
- }
- return name1 < name2;
- }
- return w1 < w2;
- }
- } itemWeightInvSorter;
-
- class SortItemAmountFunctor final
- {
- public:
- A_DEFAULT_COPY(SortItemAmountFunctor)
-
- bool operator() (const ItemIdPair *const pair1,
- const ItemIdPair *const pair2) const
- {
- if ((pair1->mItem == nullptr) || (pair2->mItem == nullptr))
- return false;
-
- const int c1 = pair1->mItem->getQuantity();
- const int c2 = pair2->mItem->getQuantity();
- if (c1 == c2)
- {
- const std::string name1 =
- pair1->mItem->getInfo().getName();
- const std::string name2 =
- pair2->mItem->getInfo().getName();
- if (name1 == name2)
- {
- return pair1->mItem->getInvIndex() <
- pair2->mItem->getInvIndex();
- }
- return name1 < name2;
- }
- return c1 < c2;
- }
- } itemAmountInvSorter;
-
- class SortItemTypeFunctor final
- {
- public:
- A_DEFAULT_COPY(SortItemTypeFunctor)
-
- bool operator() (const ItemIdPair *const pair1,
- const ItemIdPair *const pair2) const
- {
- if ((pair1->mItem == nullptr) || (pair2->mItem == nullptr))
- return false;
-
- const ItemInfo &info1 = pair1->mItem->getInfo();
- const ItemInfo &info2 = pair2->mItem->getInfo();
- const ItemDbTypeT t1 = info1.getType();
- const ItemDbTypeT t2 = info2.getType();
- if (t1 == t2)
- {
- const std::string &name1 = info1.getName();
- const std::string &name2 = info2.getName();
- if (name1 == name2)
- {
- return pair1->mItem->getInvIndex() <
- pair2->mItem->getInvIndex();
- }
- return name1 < name2;
- }
- return t1 < t2;
- }
- } itemTypeInvSorter;
-} // namespace
-
-ItemContainer::ItemContainer(const Widget2 *const widget,
- Inventory *const inventory,
- const int maxColumns,
- const ShowEmptyRows showEmptyRows,
- const ForceQuantity forceQuantity) :
- Widget(widget),
- KeyListener(),
- MouseListener(),
- WidgetListener(),
- mInventory(inventory),
- mSelImg(Theme::getImageFromThemeXml("item_selection.xml", "")),
- mProtectedImg(Theme::getImageFromTheme("lock.png")),
- mCellBackgroundImg(Theme::getImageFromThemeXml("inventory_cell.xml", "")),
- mName(),
- mShowMatrix(nullptr),
- mSkin(theme != nullptr ? theme->load("itemcontainer.xml", "") : nullptr),
- mVertexes(new ImageCollection),
- mEquipedColor(getThemeColor(ThemeColorId::ITEM_EQUIPPED)),
- mEquipedColor2(getThemeColor(ThemeColorId::ITEM_EQUIPPED_OUTLINE)),
- mUnEquipedColor(getThemeColor(ThemeColorId::ITEM_NOT_EQUIPPED)),
- mUnEquipedColor2(getThemeColor(ThemeColorId::ITEM_NOT_EQUIPPED_OUTLINE)),
- mSelectionListeners(),
- mGridColumns(1),
- mGridRows(1),
- mDrawRows(1),
- mSelectedIndex(-1),
- mLastUsedSlot(-1),
- mTag(0),
- mSortType(0),
- mClicks(1),
- mBoxWidth(mSkin != nullptr ? mSkin->getOption("boxWidth", 35) : 35),
- mBoxHeight(mSkin != nullptr ? mSkin->getOption("boxHeight", 43) : 43),
- mEquippedTextPadding(mSkin != nullptr ? mSkin->getOption(
- "equippedTextPadding", 29) : 29),
- mPaddingItemX(mSkin != nullptr ? mSkin->getOption("paddingItemX", 0) : 0),
- mPaddingItemY(mSkin != nullptr ? mSkin->getOption("paddingItemY", 0) : 0),
- mMaxColumns(maxColumns),
- mSelectionStatus(SEL_NONE),
- mForceQuantity(forceQuantity),
- mShowEmptyRows(showEmptyRows),
- mDescItems(false)
-{
- setFocusable(true);
- addKeyListener(this);
- addMouseListener(this);
- addWidgetListener(this);
- mAllowLogic = false;
-}
-
-ItemContainer::~ItemContainer()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- if (mSelImg != nullptr)
- {
- mSelImg->decRef();
- mSelImg = nullptr;
- }
- if (mProtectedImg != nullptr)
- {
- mProtectedImg->decRef();
- mProtectedImg = nullptr;
- }
- if (mCellBackgroundImg != nullptr)
- {
- mCellBackgroundImg->decRef();
- mCellBackgroundImg = nullptr;
- }
-
- if (theme != nullptr)
- theme->unload(mSkin);
-
- delete []mShowMatrix;
- delete2(mVertexes);
-}
-
-void ItemContainer::logic()
-{
- BLOCK_START("ItemContainer::logic")
- Widget::logic();
-
- if (mInventory == nullptr)
- {
- BLOCK_END("ItemContainer::logic")
- return;
- }
-
- const int lastUsedSlot = mInventory->getLastUsedSlot();
-
- if (lastUsedSlot != mLastUsedSlot)
- {
- mLastUsedSlot = lastUsedSlot;
- adjustHeight();
- }
- BLOCK_END("ItemContainer::logic")
-}
-
-void ItemContainer::draw(Graphics *const graphics)
-{
- if ((mInventory == nullptr) || (mShowMatrix == nullptr))
- return;
-
- BLOCK_START("ItemContainer::draw")
- Font *const font = getFont();
-
- if (mCellBackgroundImg != nullptr)
- {
- if (mRedraw || graphics->getRedraw())
- {
- mRedraw = false;
- mVertexes->clear();
-
- const int invSize = mInventory->getSize();
- const int maxRows = mShowEmptyRows == ShowEmptyRows_true ?
- std::max(invSize / mGridColumns, mGridRows) : mGridRows;
- const int maxColumns = mGridColumns > invSize ?
- invSize : mGridColumns;
- for (int j = 0; j < maxRows; j++)
- {
- const int intY0 = j * mBoxHeight;
- for (int i = 0; i < maxColumns; i++)
- {
- int itemX = i * mBoxWidth;
- int itemY = intY0;
- graphics->calcTileCollection(mVertexes,
- mCellBackgroundImg,
- itemX + mPaddingItemX,
- itemY + mPaddingItemY);
- }
- }
- graphics->finalize(mVertexes);
- }
- graphics->drawTileCollection(mVertexes);
- }
-
- for (int j = 0; j < mDrawRows; j++)
- {
- const int intY0 = j * mBoxHeight;
- int itemIndex = j * mGridColumns - 1;
- for (int i = 0; i < mGridColumns; i++)
- {
- int itemX = i * mBoxWidth;
- int itemY = intY0;
- itemIndex ++;
- if (mShowMatrix[itemIndex] < 0)
- continue;
-
- const Item *const item = mInventory->getItem(
- mShowMatrix[itemIndex]);
-
- if ((item == nullptr) || item->getId() == 0)
- continue;
-
- Image *const image = item->getImage();
- if (image != nullptr)
- {
- if (mShowMatrix[itemIndex] == mSelectedIndex)
- {
- if (mSelImg != nullptr)
- graphics->drawImage(mSelImg, itemX, itemY);
- }
- image->setAlpha(1.0F); // ensure the image if fully drawn...
- graphics->drawImage(image,
- itemX + mPaddingItemX,
- itemY + mPaddingItemY);
- if ((mProtectedImg != nullptr) && PlayerInfo::isItemProtected(
- item->getId()))
- {
- graphics->drawImage(mProtectedImg,
- itemX + mPaddingItemX,
- itemY + mPaddingItemY);
- }
- }
- }
- }
-
- for (int j = 0; j < mDrawRows; j++)
- {
- const int intY0 = j * mBoxHeight;
- int itemIndex = j * mGridColumns - 1;
- for (int i = 0; i < mGridColumns; i++)
- {
- int itemX = i * mBoxWidth;
- int itemY = intY0;
- itemIndex ++;
- if (mShowMatrix[itemIndex] < 0)
- continue;
-
- const Item *const item = mInventory->getItem(
- mShowMatrix[itemIndex]);
-
- if ((item == nullptr) || item->getId() == 0)
- continue;
-
- // Draw item caption
- std::string caption;
- if (item->getQuantity() > 1 ||
- mForceQuantity == ForceQuantity_true)
- {
- caption = toString(item->getQuantity());
- }
- else if (item->isEquipped() == Equipped_true)
- {
- // TRANSLATORS: Text under equipped items (should be small)
- caption = _("Eq.");
- }
-
- if (item->isEquipped() == Equipped_true)
- {
- font->drawString(graphics,
- mEquipedColor, mEquipedColor2,
- caption,
- itemX + (mBoxWidth - font->getWidth(caption)) / 2,
- itemY + mEquippedTextPadding);
- }
- else
- {
- font->drawString(graphics,
- mUnEquipedColor, mUnEquipedColor2,
- caption,
- itemX + (mBoxWidth - font->getWidth(caption)) / 2,
- itemY + mEquippedTextPadding);
- }
- }
- }
- BLOCK_END("ItemContainer::draw")
-}
-
-void ItemContainer::safeDraw(Graphics *const graphics)
-{
- if ((mInventory == nullptr) || (mShowMatrix == nullptr))
- return;
-
- BLOCK_START("ItemContainer::draw")
- Font *const font = getFont();
-
- if (mCellBackgroundImg != nullptr)
- {
- const int invSize = mInventory->getSize();
- const int maxRows = mShowEmptyRows == ShowEmptyRows_true ?
- std::max(invSize / mGridColumns, mGridRows) : mGridRows;
- const int maxColumns = mGridColumns > invSize ?
- invSize : mGridColumns;
- for (int j = 0; j < maxRows; j++)
- {
- const int intY0 = j * mBoxHeight;
- for (int i = 0; i < maxColumns; i++)
- {
- int itemX = i * mBoxWidth;
- int itemY = intY0;
- graphics->drawImage(mCellBackgroundImg,
- itemX + mPaddingItemX,
- itemY + mPaddingItemY);
- }
- }
- }
-
- for (int j = 0; j < mDrawRows; j++)
- {
- const int intY0 = j * mBoxHeight;
- int itemIndex = j * mGridColumns - 1;
- for (int i = 0; i < mGridColumns; i++)
- {
- int itemX = i * mBoxWidth;
- int itemY = intY0;
- itemIndex ++;
- if (mShowMatrix[itemIndex] < 0)
- continue;
-
- const Item *const item = mInventory->getItem(
- mShowMatrix[itemIndex]);
-
- if ((item == nullptr) || item->getId() == 0)
- continue;
-
- Image *const image = item->getImage();
- if (image != nullptr)
- {
- if (mShowMatrix[itemIndex] == mSelectedIndex)
- {
- if (mSelImg != nullptr)
- graphics->drawImage(mSelImg, itemX, itemY);
- }
- image->setAlpha(1.0F); // ensure the image if fully drawn...
- graphics->drawImage(image,
- itemX + mPaddingItemX,
- itemY + mPaddingItemY);
- if ((mProtectedImg != nullptr) && PlayerInfo::isItemProtected(
- item->getId()))
- {
- graphics->drawImage(mProtectedImg,
- itemX + mPaddingItemX,
- itemY + mPaddingItemY);
- }
- }
- }
- }
-
- for (int j = 0; j < mDrawRows; j++)
- {
- const int intY0 = j * mBoxHeight;
- int itemIndex = j * mGridColumns - 1;
- for (int i = 0; i < mGridColumns; i++)
- {
- int itemX = i * mBoxWidth;
- int itemY = intY0;
- itemIndex ++;
- if (mShowMatrix[itemIndex] < 0)
- continue;
-
- const Item *const item = mInventory->getItem(
- mShowMatrix[itemIndex]);
-
- if ((item == nullptr) || item->getId() == 0)
- continue;
-
- // Draw item caption
- std::string caption;
- if (item->getQuantity() > 1 ||
- mForceQuantity == ForceQuantity_true)
- {
- caption = toString(item->getQuantity());
- }
- else if (item->isEquipped() == Equipped_true)
- {
- // TRANSLATORS: Text under equipped items (should be small)
- caption = _("Eq.");
- }
-
- if (item->isEquipped() == Equipped_true)
- {
- font->drawString(graphics,
- mEquipedColor, mEquipedColor2,
- caption,
- itemX + (mBoxWidth - font->getWidth(caption)) / 2,
- itemY + mEquippedTextPadding);
- }
- else
- {
- font->drawString(graphics,
- mUnEquipedColor, mUnEquipedColor2,
- caption,
- itemX + (mBoxWidth - font->getWidth(caption)) / 2,
- itemY + mEquippedTextPadding);
- }
- }
- }
- BLOCK_END("ItemContainer::draw")
-}
-
-void ItemContainer::selectNone()
-{
- dragDrop.clear();
-
- setSelectedIndex(-1);
- mSelectionStatus = SEL_NONE;
-/*
- if (outfitWindow)
- outfitWindow->setItemSelected(-1);
- if (shopWindow)
- shopWindow->setItemSelected(-1);
-*/
-}
-
-void ItemContainer::setSelectedIndex(const int newIndex)
-{
- if (mSelectedIndex != newIndex)
- {
- mSelectedIndex = newIndex;
- distributeValueChangedEvent();
- }
-}
-
-Item *ItemContainer::getSelectedItem() const
-{
- if (mInventory != nullptr)
- return mInventory->getItem(mSelectedIndex);
- return nullptr;
-}
-
-void ItemContainer::distributeValueChangedEvent()
-{
- FOR_EACH (SelectionListenerIterator, i, mSelectionListeners)
- {
- if (*i != nullptr)
- {
- SelectionEvent event(this);
- (*i)->valueChanged(event);
- }
- }
-}
-
-void ItemContainer::keyPressed(KeyEvent &event A_UNUSED)
-{
-}
-
-void ItemContainer::keyReleased(KeyEvent &event A_UNUSED)
-{
-}
-
-void ItemContainer::mousePressed(MouseEvent &event)
-{
- if (mInventory == nullptr)
- return;
-
- const MouseButtonT button = event.getButton();
- mClicks = event.getClickCount();
-
- if (button == MouseButton::LEFT || button == MouseButton::RIGHT)
- {
- event.consume();
- const int index = getSlotIndex(event.getX(), event.getY());
- if (index == Inventory::NO_SLOT_INDEX)
- return;
-
- Item *const item = mInventory->getItem(index);
-
- // put item name into chat window
- if ((item != nullptr) && mDescItems && (chatWindow != nullptr))
- chatWindow->addItemText(item->getInfo().getName());
-
- DragDropSourceT src = DragDropSource::Empty;
- switch (mInventory->getType())
- {
- case InventoryType::Inventory:
- src = DragDropSource::Inventory;
- break;
- case InventoryType::Storage:
- src = DragDropSource::Storage;
- break;
- case InventoryType::Trade:
- src = DragDropSource::Trade;
- break;
- case InventoryType::Npc:
- src = DragDropSource::Npc;
- break;
- case InventoryType::Cart:
- src = DragDropSource::Cart;
- break;
- case InventoryType::MailEdit:
- src = DragDropSource::MailEdit;
- break;
- case InventoryType::MailView:
- src = DragDropSource::MailView;
- break;
- case InventoryType::Craft:
- src = DragDropSource::Craft;
- break;
- default:
- case InventoryType::Vending:
- case InventoryType::TypeEnd:
- break;
- }
- if (src == DragDropSource::MailView)
- return;
- if (mSelectedIndex == index && mClicks != 2)
- {
- dragDrop.dragItem(item, src, index);
- dragDrop.select(item);
- mSelectionStatus = SEL_DESELECTING;
- }
- else if ((item != nullptr) && (item->getId() != 0))
- {
- if (index >= 0)
- {
- dragDrop.dragItem(item, src, index);
- dragDrop.select(item);
- setSelectedIndex(index);
- mSelectionStatus = SEL_SELECTING;
-
- if (itemShortcutWindow != nullptr)
- {
- const int num = itemShortcutWindow->getTabIndex();
- if (num >= 0 && num < CAST_S32(SHORTCUT_TABS))
- {
- if (itemShortcut[num] != nullptr)
- itemShortcut[num]->setItemSelected(item);
- }
- }
- if (shopWindow != nullptr)
- shopWindow->setItemSelected(item->getId());
- }
- }
- else
- {
- dragDrop.deselect();
- selectNone();
- }
- }
-}
-
-void ItemContainer::mouseDragged(MouseEvent &event A_UNUSED)
-{
- if (mSelectionStatus != SEL_NONE)
- mSelectionStatus = SEL_DRAGGING;
-}
-
-void ItemContainer::mouseReleased(MouseEvent &event)
-{
- if (mClicks == 2 ||
- inventoryHandler == nullptr ||
- tradeHandler == nullptr)
- {
- return;
- }
-
- switch (mSelectionStatus)
- {
- case SEL_SELECTING:
- mSelectionStatus = SEL_SELECTED;
- break;
- case SEL_DESELECTING:
- selectNone();
- break;
- case SEL_DRAGGING:
- mSelectionStatus = SEL_SELECTED;
- break;
- case SEL_NONE:
- case SEL_SELECTED:
- default:
- break;
- };
-
- if (dragDrop.isEmpty())
- {
- const int index = getSlotIndex(event.getX(), event.getY());
- if (index == Inventory::NO_SLOT_INDEX)
- return;
- if (index == mSelectedIndex || mSelectedIndex == -1)
- return;
- inventoryHandler->moveItem(mSelectedIndex, index);
- selectNone();
- }
- else if (mInventory != nullptr)
- {
- const DragDropSourceT src = dragDrop.getSource();
- DragDropSourceT dst = DragDropSource::Empty;
- switch (mInventory->getType())
- {
- case InventoryType::Inventory:
- dst = DragDropSource::Inventory;
- break;
- case InventoryType::Storage:
- dst = DragDropSource::Storage;
- break;
- case InventoryType::Trade:
- dst = DragDropSource::Trade;
- break;
- case InventoryType::Npc:
- dst = DragDropSource::Npc;
- break;
- case InventoryType::MailEdit:
- dst = DragDropSource::MailEdit;
- break;
- case InventoryType::MailView:
- dst = DragDropSource::MailView;
- break;
- case InventoryType::Cart:
- dst = DragDropSource::Cart;
- break;
- case InventoryType::Craft:
- dst = DragDropSource::Craft;
- break;
- default:
- case InventoryType::Vending:
- case InventoryType::TypeEnd:
- break;
- }
- InventoryTypeT srcContainer = InventoryType::TypeEnd;
- InventoryTypeT dstContainer = InventoryType::TypeEnd;
- bool checkProtection(false);
- Inventory *inventory = nullptr;
- if (src == DragDropSource::Inventory
- && dst == DragDropSource::Storage)
- {
- srcContainer = InventoryType::Inventory;
- dstContainer = InventoryType::Storage;
- inventory = PlayerInfo::getInventory();
- }
- else if (src == DragDropSource::Storage
- && dst == DragDropSource::Inventory)
- {
- srcContainer = InventoryType::Storage;
- dstContainer = InventoryType::Inventory;
- inventory = PlayerInfo::getStorageInventory();
- }
- if (src == DragDropSource::Inventory
- && dst == DragDropSource::Cart)
- {
- srcContainer = InventoryType::Inventory;
- dstContainer = InventoryType::Cart;
- inventory = PlayerInfo::getInventory();
- }
- if (src == DragDropSource::Inventory
- && dst == DragDropSource::Inventory)
- {
- if (Net::getNetworkType() == ServerType::TMWATHENA)
- return;
- const int index = getSlotIndex(event.getX(), event.getY());
- if (index == Inventory::NO_SLOT_INDEX)
- return;
- if (index == mSelectedIndex || mSelectedIndex == -1)
- return;
- if (inventoryWindow != nullptr)
- inventoryWindow->combineItems(index, mSelectedIndex);
- return;
- }
- else if (src == DragDropSource::Cart
- && dst == DragDropSource::Inventory)
- {
- srcContainer = InventoryType::Cart;
- dstContainer = InventoryType::Inventory;
- inventory = PlayerInfo::getCartInventory();
- }
- else if (src == DragDropSource::Cart
- && dst == DragDropSource::Storage)
- {
- srcContainer = InventoryType::Cart;
- dstContainer = InventoryType::Storage;
- inventory = PlayerInfo::getCartInventory();
- }
- else if (src == DragDropSource::Storage
- && dst == DragDropSource::Cart)
- {
- srcContainer = InventoryType::Storage;
- dstContainer = InventoryType::Cart;
- inventory = PlayerInfo::getStorageInventory();
- }
- if (src == DragDropSource::Inventory
- && dst == DragDropSource::Trade)
- {
- checkProtection = true;
- inventory = PlayerInfo::getInventory();
- }
- else if (src == DragDropSource::Inventory &&
- dst == DragDropSource::Npc)
- {
- inventory = PlayerInfo::getInventory();
- if (inventory != nullptr)
- {
- Item *const item = inventory->getItem(dragDrop.getTag());
- if (mInventory->addVirtualItem(
- item,
- getSlotByXY(event.getX(), event.getY()),
- 1))
- {
- inventory->virtualRemove(item, 1);
- }
- }
- return;
- }
- else if (src == DragDropSource::Inventory &&
- dst == DragDropSource::MailEdit)
- {
- inventory = PlayerInfo::getInventory();
- if (inventory == nullptr)
- return;
- Item *const item = inventory->getItem(dragDrop.getTag());
- if (item == nullptr)
- return;
- if (settings.enableNewMailSystem)
- {
- if (item->getQuantity() > 1
- && !inputManager.isActionActive(InputAction::STOP_ATTACK))
- {
- ItemAmountWindow::showWindow(
- ItemAmountWindowUsage::MailAdd,
- mailEditWindow,
- item);
- }
- else
- {
- mail2Handler->addItem(item, 1);
- }
- }
- else
- {
- if (mInventory->addVirtualItem(
- item,
- getSlotByXY(event.getX(), event.getY()),
- 1))
- {
- inventory->virtualRemove(item, 1);
- }
- }
- return;
- }
- else if (src == DragDropSource::Npc)
- {
- inventory = PlayerInfo::getInventory();
- if (dst == DragDropSource::Npc)
- {
- const Item *const item = mInventory->getItem(
- dragDrop.getTag());
- const int index = getSlotByXY(event.getX(), event.getY());
- if (index == Inventory::NO_SLOT_INDEX)
- {
- if (inventory != nullptr)
- inventory->virtualRestore(item, 1);
- mInventory->removeItemAt(dragDrop.getTag());
- return;
- }
- mInventory->removeItemAt(index);
- mInventory->setItem(index,
- item->getId(),
- item->getType(),
- 1,
- 1,
- item->getColor(),
- item->getIdentified(),
- item->getDamaged(),
- item->getFavorite(),
- Equipm_false,
- Equipped_false);
- Item *const item2 = mInventory->getItem(index);
- if (item2 != nullptr)
- item2->setTag(item->getTag());
- mInventory->removeItemAt(dragDrop.getTag());
- }
- else
- {
- if (inventory != nullptr)
- {
- const Item *const item = inventory->getItem(
- dragDrop.getTag());
- if (item != nullptr)
- {
- inventory->virtualRestore(item, 1);
- mInventory->removeItemAt(dragDrop.getTag());
- }
- }
- return;
- }
- }
- else if (src == DragDropSource::Inventory &&
- dst == DragDropSource::Craft)
- {
- inventory = PlayerInfo::getInventory();
- if (inventory != nullptr)
- {
- Item *const item = inventory->getItem(dragDrop.getTag());
- if ((item == nullptr) || item->isEquipped() == Equipped_true)
- return;
- const int slot = getSlotByXY(event.getX(), event.getY());
- if (item->getQuantity() > 1
- && !inputManager.isActionActive(InputAction::STOP_ATTACK))
- {
- ItemAmountWindow::showWindow(
- ItemAmountWindowUsage::CraftAdd,
- npcHandler->getCurrentNpcDialog(),
- item,
- 0,
- slot);
- }
- else
- {
- if (mInventory->addVirtualItem(
- item,
- slot,
- 1))
- {
- inventory->virtualRemove(item, 1);
- }
- }
- }
- return;
- }
- else if (src == DragDropSource::Craft)
- {
- inventory = PlayerInfo::getInventory();
- if (dst == DragDropSource::Craft)
- {
- const Item *const item = mInventory->getItem(
- dragDrop.getTag());
- const int index = getSlotByXY(event.getX(), event.getY());
- if (index == Inventory::NO_SLOT_INDEX)
- {
- if (inventory != nullptr)
- {
- inventory->virtualRestore(item,
- item->getQuantity());
- mInventory->removeItemAt(dragDrop.getTag());
- }
- return;
- }
- mInventory->moveItem(index, dragDrop.getTag());
- }
- else
- {
- if (inventory != nullptr)
- {
- const Item *const item = inventory->getItem(
- dragDrop.getTag());
- if (item != nullptr)
- {
- inventory->virtualRestore(item,
- item->getQuantity());
- mInventory->removeItemAt(dragDrop.getTag());
- }
- }
- return;
- }
- }
- else if (src == DragDropSource::MailEdit)
- {
- if (event.getType() == MouseEventType::RELEASED2)
- return;
- if (settings.enableNewMailSystem)
- {
- if (mailEditWindow == nullptr)
- return;
- inventory = mailEditWindow->getInventory();
- if (inventory == nullptr)
- return;
- const Item *const item = inventory->getItem(dragDrop.getTag());
- if (item == nullptr)
- return;
- mail2Handler->removeItem(item->getTag(),
- item->getQuantity());
- }
- else
- {
- inventory = PlayerInfo::getInventory();
- if (inventory == nullptr)
- return;
- const Item *const item = inventory->getItem(dragDrop.getTag());
- if (item == nullptr)
- return;
- mInventory->removeItemAt(dragDrop.getTag());
- }
- return;
- }
-
- if (inventory != nullptr)
- {
- const Item *const item = inventory->getItem(dragDrop.getTag());
- if (item != nullptr)
- {
- if (srcContainer != InventoryType::TypeEnd)
- { // inventory <--> storage, cart
- inventoryHandler->moveItem2(srcContainer,
- item->getInvIndex(),
- item->getQuantity(),
- dstContainer);
- }
- else
- { // inventory --> trade
- if (!checkProtection || !PlayerInfo::isItemProtected(
- item->getId()))
- {
- tradeHandler->addItem(item, item->getQuantity());
- }
- }
- }
- }
- }
-}
-
-void ItemContainer::mouseMoved(MouseEvent &event)
-{
- if (mInventory == nullptr)
- return;
-
- const Item *const item = mInventory->getItem(
- getSlotIndex(event.getX(), event.getY()));
-
- if ((item != nullptr) && (viewport != nullptr))
- {
- itemPopup->setItem(item, false);
- itemPopup->position(viewport->mMouseX, viewport->mMouseY);
- }
- else
- {
- itemPopup->setVisible(Visible_false);
- }
-}
-
-void ItemContainer::mouseExited(MouseEvent &event A_UNUSED)
-{
- itemPopup->setVisible(Visible_false);
-}
-
-void ItemContainer::widgetResized(const Event &event A_UNUSED)
-{
- updateSize();
-}
-
-void ItemContainer::updateSize()
-{
- mGridColumns = std::min(mMaxColumns,
- std::max(1, mDimension.width / mBoxWidth));
- if (mGridColumns > mMaxColumns)
- mGridColumns = mMaxColumns;
- adjustHeight();
- mRedraw = true;
-}
-
-void ItemContainer::widgetMoved(const Event &event A_UNUSED)
-{
- mRedraw = true;
-}
-
-void ItemContainer::adjustHeight()
-{
- if (mGridColumns == 0)
- return;
-
- mGridRows = (mLastUsedSlot + 1) / mGridColumns;
- if (mGridRows == 0 || (mLastUsedSlot + 1) % mGridColumns > 0)
- ++mGridRows;
-
- const int invSize = mInventory->getSize();
- int maxRows = mShowEmptyRows == ShowEmptyRows_true ?
- std::max(invSize / mGridColumns, mGridRows) : mGridRows;
-
- if (mShowEmptyRows == ShowEmptyRows_true)
- {
- if (mGridColumns * maxRows < invSize)
- maxRows ++;
- mGridRows = maxRows;
- }
-
- const int num = updateMatrix();
- if (mShowEmptyRows == ShowEmptyRows_false)
- {
- mDrawRows = num / mGridColumns;
- if (mDrawRows == 0 || num % mGridColumns > 0)
- ++mDrawRows;
-
- maxRows = mDrawRows;
- }
- else
- {
- mDrawRows = mGridRows;
- }
- setHeight(maxRows * mBoxHeight);
-}
-
-int ItemContainer::updateMatrix()
-{
- if (mInventory == nullptr)
- return 0;
-
- mRedraw = true;
- delete []mShowMatrix;
- mShowMatrix = new int[CAST_SIZE(mGridRows * mGridColumns)];
-
- STD_VECTOR<ItemIdPair*> sortedItems;
- int i = 0;
- int j = 0;
-
- std::string temp = mName;
- toLower(temp);
-
- const unsigned int invSize = mInventory->getSize();
- for (unsigned int idx = 0; idx < invSize; idx ++)
- {
- Item *const item = mInventory->getItem(idx);
-
- if (item == nullptr ||
- item->getId() == 0 ||
- !item->isHaveTag(mTag) ||
- item->getQuantity() == 0)
- {
- if (mShowEmptyRows == ShowEmptyRows_true)
- sortedItems.push_back(new ItemIdPair(idx, nullptr));
- continue;
- }
-
- if (!item->isHaveTag(mTag))
- continue;
-
- if (mName.empty())
- {
- sortedItems.push_back(new ItemIdPair(idx, item));
- continue;
- }
- std::string name = item->getInfo().getName();
- toLower(name);
- if (name.find(temp) != std::string::npos)
- sortedItems.push_back(new ItemIdPair(idx, item));
- }
-
- switch (mSortType)
- {
- case 0:
- default:
- break;
- case 1:
- std::sort(sortedItems.begin(), sortedItems.end(),
- itemAlphaInvSorter);
- break;
- case 2:
- std::sort(sortedItems.begin(), sortedItems.end(), itemIdInvSorter);
- break;
- case 3:
- std::sort(sortedItems.begin(), sortedItems.end(),
- itemWeightInvSorter);
- break;
- case 4:
- std::sort(sortedItems.begin(), sortedItems.end(),
- itemAmountInvSorter);
- break;
- case 5:
- std::sort(sortedItems.begin(), sortedItems.end(),
- itemTypeInvSorter);
- break;
- }
-
- int jMult = j * mGridColumns;
- const int maxSize = mGridRows * mGridColumns;
- FOR_EACH (STD_VECTOR<ItemIdPair*>::const_iterator, iter, sortedItems)
- {
- if (jMult >= maxSize)
- break;
-
- mShowMatrix[jMult + i] = (*iter)->mId;
-
- i ++;
- if (i >= mGridColumns)
- {
- i = 0;
- j ++;
- jMult += mGridColumns;
- }
- }
-
- for (int idx = j * mGridColumns + i; idx < maxSize; idx ++)
- mShowMatrix[idx] = -1;
-
- const int num = CAST_S32(sortedItems.size());
- for (size_t idx = 0, sz = num; idx < sz; idx ++)
- delete sortedItems[idx];
- return num;
-}
-
-int ItemContainer::getSlotIndex(int x, int y) const
-{
- if (mShowMatrix == nullptr)
- return Inventory::NO_SLOT_INDEX;
-
- if (x < mDimension.width && y < mDimension.height && x >= 0 && y >= 0)
- {
- if (x > mBoxWidth * mGridColumns)
- return Inventory::NO_SLOT_INDEX;
- const int idx = (y / mBoxHeight) * mGridColumns + (x / mBoxWidth);
- if (idx >= 0 && idx < mGridRows * mGridColumns
- && mShowMatrix[idx] >= 0)
- {
- return mShowMatrix[idx];
- }
- }
-
- return Inventory::NO_SLOT_INDEX;
-}
-
-int ItemContainer::getSlotByXY(int x, int y) const
-{
- if (mShowMatrix == nullptr)
- return Inventory::NO_SLOT_INDEX;
-
- if (x < mDimension.width && y < mDimension.height && x >= 0 && y >= 0)
- {
- if (x > mBoxWidth * mGridColumns)
- return Inventory::NO_SLOT_INDEX;
- const int idx = (y / mBoxHeight) * mGridColumns + (x / mBoxWidth);
- if (idx >= 0 && idx < mGridRows * mGridColumns)
- return idx;
- }
-
- return Inventory::NO_SLOT_INDEX;
-}
-
-void ItemContainer::setFilter(const int tag)
-{
- mTag = tag;
- adjustHeight();
-}
-
-void ItemContainer::setSortType(const int sortType)
-{
- mSortType = sortType;
- updateMatrix();
-}
-
-void ItemContainer::setCellBackgroundImage(const std::string &xmlName)
-{
- if (mCellBackgroundImg != nullptr)
- mCellBackgroundImg->decRef();
- mCellBackgroundImg = Theme::getImageFromThemeXml(xmlName, "");
- mRedraw = true;
-}
-
-void ItemContainer::setMaxColumns(const int maxColumns)
-{
- mMaxColumns = maxColumns;
- updateSize();
-}
diff --git a/src/gui/widgets/itemcontainer.h b/src/gui/widgets/itemcontainer.h
deleted file mode 100644
index c992c43f5..000000000
--- a/src/gui/widgets/itemcontainer.h
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_ITEMCONTAINER_H
-#define GUI_WIDGETS_ITEMCONTAINER_H
-
-#include "listeners/keylistener.h"
-#include "listeners/mouselistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "enums/simpletypes/forcequantity.h"
-#include "enums/simpletypes/showemptyrows.h"
-
-#include "gui/widgets/widget.h"
-
-#include "localconsts.h"
-
-class Image;
-class ImageCollection;
-class Inventory;
-class Item;
-class SelectionListener;
-
-/**
- * An item container. Used to show items in inventory and trade dialog.
- *
- * \ingroup GUI
- */
-class ItemContainer final : public Widget,
- public KeyListener,
- public MouseListener,
- public WidgetListener
-{
- public:
- ItemContainer(const Widget2 *const widget,
- Inventory *const inventory,
- const int maxColumns = 100000,
- const ShowEmptyRows showEmptyRows = ShowEmptyRows_false,
- const ForceQuantity forceQuantity = ForceQuantity_false);
-
- A_DELETE_COPY(ItemContainer)
-
- /**
- * Destructor.
- */
- ~ItemContainer();
-
- /**
- * Necessary for checking how full the inventory is.
- */
- void logic() override final;
-
- /**
- * Draws the items.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- // KeyListener
- void keyPressed(KeyEvent &event) override final A_CONST;
- void keyReleased(KeyEvent &event) override final A_CONST;
-
- // MouseListener
- void mousePressed(MouseEvent &event) override final;
- void mouseDragged(MouseEvent &event) override final;
- void mouseReleased(MouseEvent &event) override final;
- void mouseMoved(MouseEvent &event) override final;
- void mouseExited(MouseEvent &event) override final;
-
- // WidgetListener
- void widgetResized(const Event &event) override final;
-
- void widgetMoved(const Event &event) override final;
-
- /**
- * Returns the selected item.
- */
- Item *getSelectedItem() const A_WARN_UNUSED;
-
- /**
- * Sets selected item to NULL.
- */
- void selectNone();
-
- /**
- * Adds a listener to the list that's notified each time a change to
- * the selection occurs.
- */
- void addSelectionListener(SelectionListener *listener)
- { mSelectionListeners.push_back(listener); }
-
- /**
- * Removes a listener from the list that's notified each time a change
- * to the selection occurs.
- */
- void removeSelectionListener(SelectionListener *listener)
- { mSelectionListeners.remove(listener); }
-
- void setFilter(const int tag);
-
- void setSortType(const int sortType);
-
- void setName(const std::string &str)
- { mName = str; }
-
- int updateMatrix();
-
- bool getClickCount() const noexcept2 A_WARN_UNUSED
- { return mClicks != 0; }
-
- void unsetInventory() noexcept2
- { mInventory = nullptr; }
-
- void setInventory(Inventory *const inventory) noexcept2
- { mInventory = inventory; }
-
- void setCellBackgroundImage(const std::string &xmlName);
-
- void setMaxColumns(const int maxColumns);
-
- private:
- enum Direction
- {
- Left = 0,
- Right,
- Up,
- Down
- };
-
- enum SelectionState
- {
- SEL_NONE = 0,
- SEL_SELECTED,
- SEL_SELECTING,
- SEL_DESELECTING,
- SEL_DRAGGING
- };
-
- /**
- * Sets the currently selected item.
- */
- void setSelectedIndex(const int index);
-
- /**
- * Determine and set the height of the container.
- */
- void adjustHeight();
-
- /**
- * Sends out selection events to the list of selection listeners.
- */
- void distributeValueChangedEvent();
-
- void updateSize();
-
- /**
- * Gets the inventory slot index based on the cursor position.
- *
- * @param x The X coordinate position.
- * @param y The Y coordinate position.
- * @return The slot index on success, -1 on failure.
- */
- int getSlotIndex(int x, int y) const;
-
- int getSlotByXY(int x, int y) const;
-
- Inventory *mInventory;
- Image *mSelImg;
- Image *mProtectedImg;
- Image *mCellBackgroundImg;
- std::string mName;
-
- int *mShowMatrix;
- Skin *mSkin;
- ImageCollection *mVertexes;
- Color mEquipedColor;
- Color mEquipedColor2;
- Color mUnEquipedColor;
- Color mUnEquipedColor2;
- typedef std::list<SelectionListener*> SelectionListenerList;
- typedef SelectionListenerList::iterator SelectionListenerIterator;
- SelectionListenerList mSelectionListeners;
- int mGridColumns;
- int mGridRows;
- int mDrawRows;
- int mSelectedIndex;
- int mLastUsedSlot;
- int mTag;
- int mSortType;
- int mClicks;
- int mBoxWidth;
- int mBoxHeight;
- int mEquippedTextPadding;
- int mPaddingItemX;
- int mPaddingItemY;
- int mMaxColumns;
- SelectionState mSelectionStatus;
- ForceQuantity mForceQuantity;
- ShowEmptyRows mShowEmptyRows;
- bool mDescItems;
-};
-
-#endif // GUI_WIDGETS_ITEMCONTAINER_H
diff --git a/src/gui/widgets/itemlinkhandler.cpp b/src/gui/widgets/itemlinkhandler.cpp
deleted file mode 100644
index 403573daf..000000000
--- a/src/gui/widgets/itemlinkhandler.cpp
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/itemlinkhandler.h"
-
-#include "itemcolormanager.h"
-#include "settings.h"
-
-#include "gui/viewport.h"
-
-#include "gui/popups/itempopup.h"
-#include "gui/popups/popupmenu.h"
-
-#include "gui/widgets/createwidget.h"
-
-#include "gui/windows/confirmdialog.h"
-#include "gui/windows/helpwindow.h"
-#include "gui/windows/questswindow.h"
-
-#include "input/inputmanager.h"
-
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include "resources/db/itemdb.h"
-
-#include "listeners/inputactionremotelistener.h"
-#include "listeners/openurllistener.h"
-
-#include "debug.h"
-
-namespace
-{
- OpenUrlListener listener;
-} // namespace
-
-ItemLinkHandler::ItemLinkHandler() :
- LinkHandler(),
- mAllowCommands(true)
-{
-}
-
-ItemLinkHandler::~ItemLinkHandler()
-{
-}
-
-void ItemLinkHandler::handleCommandLink(const std::string &link,
- const std::string &prefix)
-{
- std::string cmd;
- std::string args;
-
- const std::string cmdStr = link.substr(prefix.size());
- if (!parse2Str(cmdStr, cmd, args))
- {
- cmd = cmdStr;
- args.clear();
- }
- if (mAllowCommands)
- {
- inputManager.executeRemoteChatCommand(cmd, args, nullptr);
- }
- else
- {
- inputActionRemoteListener.setCommand(cmd, args);
- ConfirmDialog *const confirmDlg = CREATEWIDGETR(ConfirmDialog,
- // TRANSLATORS: dialog message
- _("Run command"),
- strprintf("/%s %s", cmd.c_str(), args.c_str()),
- SOUND_REQUEST,
- false,
- Modal_true);
- confirmDlg->addActionListener(&inputActionRemoteListener);
- }
-}
-
-void ItemLinkHandler::handleHelpLink(const std::string &link)
-{
- if (helpWindow != nullptr)
- {
- helpWindow->loadHelp(link.substr(7));
- helpWindow->requestMoveToTop();
- }
-}
-
-void ItemLinkHandler::handleHttpLink(const std::string &link,
- const MouseEvent *const event)
-{
- if (event == nullptr)
- return;
- std::string url = link;
- replaceAll(url, " ", "");
- listener.url = url;
- const MouseButtonT button = event->getButton();
- if (button == MouseButton::LEFT)
- {
- ConfirmDialog *const confirmDlg = CREATEWIDGETR(ConfirmDialog,
- // TRANSLATORS: dialog message
- _("Open url"),
- url,
- SOUND_REQUEST,
- false,
- Modal_true);
- confirmDlg->addActionListener(&listener);
- }
- else if (button == MouseButton::RIGHT)
- {
- if (popupMenu != nullptr)
- popupMenu->showLinkPopup(url);
- }
-}
-
-void ItemLinkHandler::handleItemLink(const std::string &link)
-{
- if ((itemPopup == nullptr) || link.empty())
- return;
-
- const char ch = link[0];
- if (ch < '0' || ch > '9')
- return;
-
- STD_VECTOR<int> str;
- splitToIntVector(str, link, ',');
- if (str.empty())
- return;
-
- const int id = str[0];
-
- if (id > 0)
- {
- str.erase(str.begin());
- while (str.size() < maxCards)
- str.push_back(0);
- const ItemColor color =
- ItemColorManager::getColorFromCards(&str[0]);
-
- const ItemInfo &itemInfo = ItemDB::get(id);
- // +++ need add support for options.
- itemPopup->setItem(itemInfo, color, true, -1, &str[0], nullptr);
- if (itemPopup->isPopupVisible())
- {
- itemPopup->setVisible(Visible_false);
- }
- else if (viewport != nullptr)
- {
- itemPopup->position(viewport->mMouseX,
- viewport->mMouseY);
- }
- }
-}
-
-void ItemLinkHandler::handleSearchLink(const std::string &link)
-{
- if (helpWindow != nullptr)
- {
- helpWindow->search(link.substr(1));
- helpWindow->requestMoveToTop();
- }
-}
-
-void ItemLinkHandler::handleLink(const std::string &link,
- MouseEvent *const event)
-{
- if (link.empty())
- return;
-
- if (strStartWith(link, "http://") || strStartWith(link, "https://"))
- {
- handleHttpLink(link, event);
- }
- else if (link[0] == '?')
- {
- handleSearchLink(link);
- }
- else if (strStartWith(link, "help://"))
- {
- handleHelpLink(link);
- }
- else if (strStartWith(link, settings.linkCommandSymbol))
- {
- handleCommandLink(link, settings.linkCommandSymbol);
- }
- else if (strStartWith(link, "="))
- {
- handleCommandLink(link, "=");
- }
- else if (link == "news")
- {
- if (helpWindow != nullptr)
- helpWindow->loadHelpSimple("news");
- }
- else if (link == "copyright")
- {
- inputManager.executeAction(InputAction::WINDOW_ABOUT);
- }
- else if (link[0] == 'q')
- {
- questsWindow->selectQuest(atoi(link.substr(1).c_str()));
- }
- else
- {
- handleItemLink(link);
- }
-}
diff --git a/src/gui/widgets/itemlinkhandler.h b/src/gui/widgets/itemlinkhandler.h
deleted file mode 100644
index bc90f71d1..000000000
--- a/src/gui/widgets/itemlinkhandler.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_ITEMLINKHANDLER_H
-#define GUI_WIDGETS_ITEMLINKHANDLER_H
-
-#include "gui/widgets/linkhandler.h"
-
-#include "localconsts.h"
-
-class ItemLinkHandler final : public LinkHandler
-{
- public:
- ItemLinkHandler();
-
- A_DELETE_COPY(ItemLinkHandler)
-
- ~ItemLinkHandler();
-
- void handleLink(const std::string &link,
- MouseEvent *event) override final;
-
- void setAllowCommands(const bool b)
- { mAllowCommands = b; }
-
- private:
- void handleCommandLink(const std::string &link,
- const std::string &prefix);
-
- static void handleHelpLink(const std::string &link);
-
- static void handleHttpLink(const std::string &link,
- const MouseEvent *const event);
-
- static void handleItemLink(const std::string &link);
-
- static void handleSearchLink(const std::string &link);
-
- bool mAllowCommands;
-};
-
-#endif // GUI_WIDGETS_ITEMLINKHANDLER_H
diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp
deleted file mode 100644
index 9f667caba..000000000
--- a/src/gui/widgets/itemshortcutcontainer.cpp
+++ /dev/null
@@ -1,650 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/itemshortcutcontainer.h"
-
-#include "dragdrop.h"
-#include "settings.h"
-#include "spellmanager.h"
-
-#include "being/playerinfo.h"
-
-#include "input/inputmanager.h"
-
-#include "gui/viewport.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/shortcut/itemshortcut.h"
-#include "gui/shortcut/spellshortcut.h"
-
-#include "gui/popups/itempopup.h"
-#include "gui/popups/popupmenu.h"
-#include "gui/popups/skillpopup.h"
-#include "gui/popups/spellpopup.h"
-
-#include "gui/windows/inventorywindow.h"
-#include "gui/windows/skilldialog.h"
-
-#include "input/inputactionoperators.h"
-
-#include "const/resources/skill.h"
-
-#include "utils/stringutils.h"
-
-#include "debug.h"
-
-ItemShortcutContainer::ItemShortcutContainer(Widget2 *const widget,
- const unsigned number) :
- ShortcutContainer(widget),
- mItemClicked(false),
- mNumber(number),
- mEquipedColor(getThemeColor(ThemeColorId::ITEM_EQUIPPED)),
- mEquipedColor2(getThemeColor(ThemeColorId::ITEM_EQUIPPED_OUTLINE)),
- mUnEquipedColor(getThemeColor(ThemeColorId::ITEM_NOT_EQUIPPED)),
- mUnEquipedColor2(getThemeColor(ThemeColorId::ITEM_NOT_EQUIPPED_OUTLINE))
-{
- mMaxItems = ItemShortcut::getItemCount();
-}
-
-ItemShortcutContainer::~ItemShortcutContainer()
-{
-}
-
-void ItemShortcutContainer::setWidget2(const Widget2 *const widget)
-{
- Widget2::setWidget2(widget);
- mEquipedColor = getThemeColor(ThemeColorId::ITEM_EQUIPPED);
- mEquipedColor2 = getThemeColor(ThemeColorId::ITEM_EQUIPPED_OUTLINE);
- mUnEquipedColor = getThemeColor(ThemeColorId::ITEM_NOT_EQUIPPED);
- mUnEquipedColor2 = getThemeColor(ThemeColorId::ITEM_NOT_EQUIPPED_OUTLINE);
- mForegroundColor = getThemeColor(ThemeColorId::TEXT);
- mForegroundColor2 = getThemeColor(ThemeColorId::TEXT_OUTLINE);
-}
-
-void ItemShortcutContainer::draw(Graphics *const graphics)
-{
- BLOCK_START("ItemShortcutContainer::draw")
- const ItemShortcut *const selShortcut = itemShortcut[mNumber];
- if (selShortcut == nullptr)
- {
- BLOCK_END("ItemShortcutContainer::draw")
- return;
- }
-
- if (settings.guiAlpha != mAlpha)
- {
- if (mBackgroundImg != nullptr)
- mBackgroundImg->setAlpha(mAlpha);
- mAlpha = settings.guiAlpha;
- }
-
- Font *const font = getFont();
- drawBackground(graphics);
-
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- {
- BLOCK_END("ItemShortcutContainer::draw")
- return;
- }
-
- // +++ for future usage need reorder drawing images before text or back
- for (unsigned i = 0; i < mMaxItems; i++)
- {
- const int itemX = (i % mGridWidth) * mBoxWidth;
- const int itemY = (i / mGridWidth) * mBoxHeight;
-
- // Draw item keyboard shortcut.
- const std::string key = inputManager.getKeyValueString(
- InputAction::SHORTCUT_1 + i);
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- key,
- itemX + 2, itemY + 2);
-
- const int itemId = selShortcut->getItem(i);
- const ItemColor itemColor = selShortcut->getItemColor(i);
-
- if (itemId < 0)
- continue;
-
- // this is item
- if (itemId < SPELL_MIN_ID)
- {
- const Item *const item = inv->findItem(itemId, itemColor);
- if (item != nullptr)
- {
- // Draw item icon.
- Image *const image = item->getImage();
- if (image != nullptr)
- {
- std::string caption;
- if (item->getQuantity() > 1)
- caption = toString(item->getQuantity());
- else if (item->isEquipped() == Equipped_true)
- caption = "Eq.";
-
- image->setAlpha(1.0F);
- graphics->drawImage(image, itemX, itemY);
- if (item->isEquipped() == Equipped_true)
- {
- font->drawString(graphics,
- mEquipedColor,
- mEquipedColor2,
- caption,
- itemX + (mBoxWidth - font->getWidth(caption)) / 2,
- itemY + mBoxHeight - 14);
- }
- else
- {
- font->drawString(graphics,
- mUnEquipedColor,
- mUnEquipedColor2,
- caption,
- itemX + (mBoxWidth - font->getWidth(caption)) / 2,
- itemY + mBoxHeight - 14);
- }
- }
- }
- }
- else if (itemId < SKILL_MIN_ID && (spellManager != nullptr))
- { // this is magic shortcut
- const TextCommand *const spell = spellManager
- ->getSpellByItem(itemId);
- if (spell != nullptr)
- {
- if (!spell->isEmpty())
- {
- Image *const image = spell->getImage();
-
- if (image != nullptr)
- {
- image->setAlpha(1.0F);
- graphics->drawImage(image, itemX, itemY);
- }
- }
-
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- spell->getSymbol(),
- itemX + 2, itemY + mBoxHeight / 2);
- }
- }
- else if (skillDialog != nullptr)
- {
- const SkillInfo *const skill = skillDialog->getSkill(
- itemId - SKILL_MIN_ID);
- if (skill != nullptr)
- {
- Image *const image = skill->data->icon;
-
- if (image != nullptr)
- {
- image->setAlpha(1.0F);
- graphics->drawImage(image, itemX, itemY);
- }
- if (!skill->data->haveIcon)
- {
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- skill->data->shortName,
- itemX + 2,
- itemY + mBoxHeight / 2);
- }
- }
- }
- }
- BLOCK_END("ItemShortcutContainer::draw")
-}
-
-void ItemShortcutContainer::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("ItemShortcutContainer::draw")
- const ItemShortcut *const selShortcut = itemShortcut[mNumber];
- if (selShortcut == nullptr)
- {
- BLOCK_END("ItemShortcutContainer::draw")
- return;
- }
-
- if (settings.guiAlpha != mAlpha)
- {
- if (mBackgroundImg != nullptr)
- mBackgroundImg->setAlpha(mAlpha);
- mAlpha = settings.guiAlpha;
- }
-
- Font *const font = getFont();
- safeDrawBackground(graphics);
-
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- {
- BLOCK_END("ItemShortcutContainer::draw")
- return;
- }
-
- // +++ for future usage need reorder drawing images before text or back
- for (unsigned i = 0; i < mMaxItems; i++)
- {
- const int itemX = (i % mGridWidth) * mBoxWidth;
- const int itemY = (i / mGridWidth) * mBoxHeight;
-
- // Draw item keyboard shortcut.
- const std::string key = inputManager.getKeyValueString(
- InputAction::SHORTCUT_1 + i);
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- key,
- itemX + 2, itemY + 2);
-
- const int itemId = selShortcut->getItem(i);
- const ItemColor itemColor = selShortcut->getItemColor(i);
-
- if (itemId < 0)
- continue;
-
- // this is item
- if (itemId < SPELL_MIN_ID)
- {
- const Item *const item = inv->findItem(itemId, itemColor);
- if (item != nullptr)
- {
- // Draw item icon.
- Image *const image = item->getImage();
- if (image != nullptr)
- {
- std::string caption;
- if (item->getQuantity() > 1)
- caption = toString(item->getQuantity());
- else if (item->isEquipped() == Equipped_true)
- caption = "Eq.";
-
- image->setAlpha(1.0F);
- graphics->drawImage(image, itemX, itemY);
- if (item->isEquipped() == Equipped_true)
- {
- font->drawString(graphics,
- mEquipedColor,
- mEquipedColor2,
- caption,
- itemX + (mBoxWidth - font->getWidth(caption)) / 2,
- itemY + mBoxHeight - 14);
- }
- else
- {
- font->drawString(graphics,
- mUnEquipedColor,
- mUnEquipedColor2,
- caption,
- itemX + (mBoxWidth - font->getWidth(caption)) / 2,
- itemY + mBoxHeight - 14);
- }
- }
- }
- }
- else if (itemId < SKILL_MIN_ID && (spellManager != nullptr))
- { // this is magic shortcut
- const TextCommand *const spell = spellManager
- ->getSpellByItem(itemId);
- if (spell != nullptr)
- {
- if (!spell->isEmpty())
- {
- Image *const image = spell->getImage();
-
- if (image != nullptr)
- {
- image->setAlpha(1.0F);
- graphics->drawImage(image, itemX, itemY);
- }
- }
-
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- spell->getSymbol(),
- itemX + 2, itemY + mBoxHeight / 2);
- }
- }
- else if (skillDialog != nullptr)
- {
- const SkillInfo *const skill = skillDialog->getSkill(
- itemId - SKILL_MIN_ID);
- if (skill != nullptr)
- {
- Image *const image = skill->data->icon;
-
- if (image != nullptr)
- {
- image->setAlpha(1.0F);
- graphics->drawImage(image, itemX, itemY);
- }
- if (!skill->data->haveIcon)
- {
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- skill->data->shortName,
- itemX + 2,
- itemY + mBoxHeight / 2);
- }
- }
- }
- }
- BLOCK_END("ItemShortcutContainer::draw")
-}
-
-void ItemShortcutContainer::mouseDragged(MouseEvent &event)
-{
- if (mNumber == SHORTCUT_AUTO_TAB)
- return;
- ItemShortcut *const selShortcut = itemShortcut[mNumber];
- if (selShortcut == nullptr)
- return;
-
- if (event.getButton() == MouseButton::LEFT)
- {
- if (dragDrop.isEmpty() && mItemClicked)
- {
- mItemClicked = false;
-
- const int index = getIndexFromGrid(event.getX(), event.getY());
- if (index == -1)
- return;
-
- const int itemId = selShortcut->getItem(index);
- const ItemColor itemColor = selShortcut->getItemColor(index);
-
- if (itemId < 0)
- return;
-
- event.consume();
- if (itemId < SPELL_MIN_ID)
- { // items
- if (PlayerInfo::getInventory() == nullptr)
- return;
-
- const Item *const item = PlayerInfo::getInventory()->findItem(
- itemId, itemColor);
-
- if (item != nullptr)
- {
- selShortcut->removeItem(index);
- dragDrop.dragItem(item, DragDropSource::Shortcuts, index);
- }
- else
- {
- dragDrop.clear();
- }
- }
- else if (itemId < SKILL_MIN_ID)
- { // spells/commands
- if (spellManager == nullptr)
- {
- dragDrop.clear();
- return;
- }
-
- const TextCommand *const spell = spellManager->getSpellByItem(
- itemId);
- if (spell != nullptr)
- {
- selShortcut->removeItem(index);
- dragDrop.dragCommand(spell,
- DragDropSource::Shortcuts, index);
- dragDrop.setItem(itemId);
- }
- else
- {
- dragDrop.clear();
- }
- }
- else
- { // skills
- if (skillDialog == nullptr)
- {
- dragDrop.clear();
- return;
- }
- const SkillInfo *const skill
- = skillDialog->getSkillByItem(itemId);
- if (skill != nullptr)
- {
- const std::string itemData = selShortcut->getItemData(
- index);
- selShortcut->removeItem(index);
- dragDrop.dragSkill(skill,
- DragDropSource::Shortcuts,
- index);
- dragDrop.setItem(itemId);
- dragDrop.setItemColor(itemColor);
- dragDrop.setItemData(itemData);
- }
- else
- {
- dragDrop.clear();
- }
- }
- }
- }
-}
-
-void ItemShortcutContainer::mousePressed(MouseEvent &event)
-{
- ItemShortcut *const selShortcut = itemShortcut[mNumber];
- if (selShortcut == nullptr)
- return;
-
- const int index = getIndexFromGrid(event.getX(), event.getY());
-
- if (index == -1)
- return;
-
- if (event.getButton() == MouseButton::LEFT)
- {
- event.consume();
- // Stores the selected item if theirs one.
- if (selShortcut->isItemSelected() && (inventoryWindow != nullptr) &&
- (inventoryWindow->isWindowVisible()
- || selShortcut->getSelectedItem() >= SPELL_MIN_ID))
- {
- selShortcut->setItem(index);
- selShortcut->setItemSelected(-1);
- if (spellShortcut != nullptr)
- spellShortcut->setItemSelected(-1);
- inventoryWindow->unselectItem();
- }
- else if (selShortcut->getItem(index) != 0)
- {
- mItemClicked = true;
- }
- }
- else if (event.getButton() == MouseButton::RIGHT)
- {
- event.consume();
- if (popupMenu != nullptr &&
- viewport != nullptr)
- {
- popupMenu->showItemPopup(viewport->mMouseX,
- viewport->mMouseY,
- selShortcut->getItem(index),
- selShortcut->getItemColor(index));
- }
- }
-}
-
-void ItemShortcutContainer::mouseReleased(MouseEvent &event)
-{
- ItemShortcut *const selShortcut = itemShortcut[mNumber];
- if (selShortcut == nullptr)
- return;
-
- if (event.getButton() == MouseButton::LEFT)
- {
- if (selShortcut->isItemSelected())
- selShortcut->setItemSelected(-1);
-
- const int index = getIndexFromGrid(event.getX(), event.getY());
- if (index == -1)
- return;
-
- if (dragDrop.isEmpty())
- {
- if ((selShortcut->getItem(index) != 0) && mItemClicked)
- selShortcut->useItem(index);
- }
- else
- {
- if (dragDrop.getSource() == DragDropSource::Shortcuts)
- {
- const int oldIndex = dragDrop.getTag();
- selShortcut->setItem(oldIndex, dragDrop.getItem(),
- dragDrop.getItemColor());
- selShortcut->swap(oldIndex, index);
- }
- else
- {
- selShortcut->setItemData(index,
- dragDrop.getItemData());
- selShortcut->setItem(index, dragDrop.getItem(),
- dragDrop.getItemColor());
- }
- dragDrop.clear();
- dragDrop.deselect();
- }
-
- mItemClicked = false;
- }
-}
-
-void ItemShortcutContainer::mouseMoved(MouseEvent &event)
-{
- const ItemShortcut *const selShortcut = itemShortcut[mNumber];
- if (selShortcut == nullptr)
- return;
-
- const int index = getIndexFromGrid(event.getX(), event.getY());
-
- if (index == -1)
- return;
-
- const int itemId = selShortcut->getItem(index);
- const ItemColor itemColor = selShortcut->getItemColor(index);
-
- if (itemId < 0)
- return;
-
- if (itemId < SPELL_MIN_ID)
- {
- skillPopup->setVisible(Visible_false);
- spellPopup->setVisible(Visible_false);
-
- Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- return;
-
- const Item *const item = inv->findItem(itemId, itemColor);
- if ((item != nullptr) && (viewport != nullptr))
- {
- itemPopup->setItem(item, false);
- itemPopup->position(viewport->mMouseX, viewport->mMouseY);
- }
- else
- {
- itemPopup->setVisible(Visible_false);
- }
- }
- else if (itemId < SKILL_MIN_ID && (spellManager != nullptr))
- {
- skillPopup->setVisible(Visible_false);
- itemPopup->setVisible(Visible_false);
- const TextCommand *const spell = spellManager->getSpellByItem(itemId);
- if ((spell != nullptr) && (viewport != nullptr))
- {
- spellPopup->setItem(spell);
- spellPopup->view(viewport->mMouseX,
- viewport->mMouseY);
- }
- else
- {
- spellPopup->setVisible(Visible_false);
- }
- }
- else if (skillDialog != nullptr)
- {
- itemPopup->setVisible(Visible_false);
- spellPopup->setVisible(Visible_false);
- const SkillInfo *const skill = skillDialog->getSkillByItem(itemId);
- if (skill == nullptr)
- return;
-
- const std::string data = selShortcut->getItemData(index);
- CastTypeT castType = CastType::Default;
- int offsetX = 0;
- int offsetY = 0;
- if (!data.empty())
- {
- STD_VECTOR<int> vect;
- splitToIntVector(vect, data, ' ');
- const size_t sz = vect.size();
- if (sz > 0)
- castType = static_cast<CastTypeT>(vect[0]);
- if (sz > 2)
- {
- offsetX = vect[1];
- offsetY = vect[2];
- }
- }
- skillPopup->show(skill,
- toInt(itemColor, int),
- castType,
- offsetX,
- offsetY);
- skillPopup->position(viewport->mMouseX,
- viewport->mMouseY);
- }
-}
-
-// Hide ItemTooltip
-void ItemShortcutContainer::mouseExited(MouseEvent &event A_UNUSED)
-{
- if (itemPopup != nullptr)
- itemPopup->setVisible(Visible_false);
- if (spellPopup != nullptr)
- spellPopup->setVisible(Visible_false);
- if (skillPopup != nullptr)
- skillPopup->setVisible(Visible_false);
-}
-
-void ItemShortcutContainer::widgetHidden(const Event &event A_UNUSED)
-{
- if (itemPopup != nullptr)
- itemPopup->setVisible(Visible_false);
- if (spellPopup != nullptr)
- spellPopup->setVisible(Visible_false);
-}
diff --git a/src/gui/widgets/itemshortcutcontainer.h b/src/gui/widgets/itemshortcutcontainer.h
deleted file mode 100644
index 146834f4d..000000000
--- a/src/gui/widgets/itemshortcutcontainer.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_ITEMSHORTCUTCONTAINER_H
-#define GUI_WIDGETS_ITEMSHORTCUTCONTAINER_H
-
-#include "gui/widgets/shortcutcontainer.h"
-
-/**
- * An item shortcut container. Used to quickly use items.
- *
- * \ingroup GUI
- */
-class ItemShortcutContainer final : public ShortcutContainer
-{
- public:
- /**
- * Constructor. Initializes the graphic.
- */
- ItemShortcutContainer(Widget2 *const widget,
- const unsigned number);
-
- A_DELETE_COPY(ItemShortcutContainer)
-
- /**
- * Destructor.
- */
- ~ItemShortcutContainer();
-
- /**
- * Draws the items.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Handles mouse when dragged.
- */
- void mouseDragged(MouseEvent &event) override final;
-
- /**
- * Handles mouse when pressed.
- */
- void mousePressed(MouseEvent &event) override final;
-
- /**
- * Handles mouse release.
- */
- void mouseReleased(MouseEvent &event) override final;
-
- void widgetHidden(const Event &event) override final;
-
- void mouseExited(MouseEvent &event) override final;
-
- void mouseMoved(MouseEvent &event) override final;
-
- void setWidget2(const Widget2 *const widget) override final;
-
- private:
- bool mItemClicked;
- unsigned mNumber;
-
- Color mEquipedColor;
- Color mEquipedColor2;
- Color mUnEquipedColor;
- Color mUnEquipedColor2;
-};
-
-#endif // GUI_WIDGETS_ITEMSHORTCUTCONTAINER_H
diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp
deleted file mode 100644
index aeacddbdb..000000000
--- a/src/gui/widgets/label.cpp
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 Aethyra Development Team
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/label.h"
-
-#include "gui/gui.h"
-#include "gui/skin.h"
-
-#include "gui/fonts/font.h"
-
-#include "debug.h"
-
-Skin *Label::mSkin = nullptr;
-int Label::mInstances = 0;
-
-Label::Label(const Widget2 *const widget) :
- Widget(widget),
- WidgetListener(),
- ToolTipListener(),
- mCaption(),
- mTextChunk(),
- mAlignment(Graphics::LEFT),
- mPadding(0),
- mTextChanged(true)
-{
- init();
-}
-
-Label::Label(const Widget2 *const widget,
- const std::string &caption) :
- Widget(widget),
- WidgetListener(),
- ToolTipListener(),
- mCaption(caption),
- mTextChunk(),
- mAlignment(Graphics::LEFT),
- mPadding(0),
- mTextChanged(true)
-{
- const Font *const font = getFont();
- setWidth(font->getWidth(caption));
- setHeight(font->getHeight());
- init();
-}
-
-Label::~Label()
-{
- if (mWindow != nullptr)
- mWindow->removeWidgetListener(this);
-
- if (gui != nullptr)
- gui->removeDragged(this);
-
- mInstances --;
- if (mInstances == 0)
- {
- if (theme != nullptr)
- theme->unload(mSkin);
- }
- removeMouseListener(this);
- mTextChunk.deleteImage();
-}
-
-void Label::init()
-{
- addMouseListener(this);
- mAllowLogic = false;
- mForegroundColor = getThemeColor(ThemeColorId::LABEL);
- mForegroundColor2 = getThemeColor(ThemeColorId::LABEL_OUTLINE);
- if (mInstances == 0)
- {
- if (theme != nullptr)
- mSkin = theme->load("label.xml", "");
- }
- mInstances ++;
-
- if (mSkin != nullptr)
- mPadding = mSkin->getPadding();
- else
- mPadding = 0;
- setSelectable(false);
-}
-
-void Label::draw(Graphics *const graphics)
-{
- BLOCK_START("Label::draw")
- int textX;
- const Rect &rect = mDimension;
- const int textY = rect.height / 2 - getFont()->getHeight() / 2;
- Font *const font = getFont();
-
- switch (mAlignment)
- {
- case Graphics::LEFT:
- default:
- textX = mPadding;
- break;
- case Graphics::CENTER:
- textX = (rect.width - font->getWidth(mCaption)) / 2;
- break;
- case Graphics::RIGHT:
- if (rect.width > mPadding)
- textX = rect.width - mPadding - font->getWidth(mCaption);
- else
- textX = 0;
- break;
- }
-
- if (mTextChanged)
- {
- mTextChunk.textFont = font;
- mTextChunk.deleteImage();
- mTextChunk.text = mCaption;
- mTextChunk.color = mForegroundColor;
- mTextChunk.color2 = mForegroundColor2;
- font->generate(mTextChunk);
- mTextChanged = false;
- }
-
- const Image *const image = mTextChunk.img;
- if (image != nullptr)
- graphics->drawImage(image, textX, textY);
- BLOCK_END("Label::draw")
-}
-
-void Label::safeDraw(Graphics *const graphics)
-{
- Label::draw(graphics);
-}
-
-void Label::adjustSize()
-{
- const Font *const font = getFont();
- const int pad2 = 2 * mPadding;
- setWidth(font->getWidth(mCaption) + pad2);
- setHeight(font->getHeight() + pad2);
-}
-
-void Label::setForegroundColor(const Color &color)
-{
- if (mForegroundColor != color || mForegroundColor2 != color)
- mTextChanged = true;
-// logger->log("Label::setForegroundColor: " + mCaption);
- mForegroundColor = color;
- mForegroundColor2 = color;
-}
-
-void Label::setForegroundColorAll(const Color &color1,
- const Color &color2)
-{
- if (mForegroundColor != color1 || mForegroundColor2 != color2)
- mTextChanged = true;
-// logger->log("Label::setForegroundColorAll: " + mCaption);
- mForegroundColor = color1;
- mForegroundColor2 = color2;
-}
-
-void Label::resizeTo(const int maxSize, const int minSize)
-{
- const Font *const font = getFont();
- const int pad2 = 2 * mPadding;
- setHeight(font->getHeight() + pad2);
-
- if (font->getWidth(mCaption) + pad2 > maxSize)
- {
- const int dots = font->getWidth("...");
- if (dots > maxSize)
- {
- setWidth(maxSize);
- return;
- }
- const size_t szChars = mCaption.size();
- for (size_t f = 1; f < szChars - 1; f ++)
- {
- const std::string text = mCaption.substr(0, szChars - f);
- const int width = font->getWidth(text) + dots + pad2;
- if (width <= maxSize)
- {
- setCaption(text + "...");
- setWidth(width);
- return;
- }
- }
- setWidth(maxSize);
- }
- else
- {
- int sz = font->getWidth(mCaption) + pad2;
- if (sz < minSize)
- sz = minSize;
- setWidth(sz);
- }
-}
-
-void Label::setCaption(const std::string& caption)
-{
- if (caption != mCaption)
- mTextChanged = true;
- mCaption = caption;
-}
-
-void Label::setParent(Widget *const widget)
-{
- if (mWindow != nullptr)
- mWindow->addWidgetListener(this);
- Widget::setParent(widget);
-}
-
-void Label::setWindow(Widget *const widget)
-{
- if ((widget == nullptr) && (mWindow != nullptr))
- {
- mWindow->removeWidgetListener(this);
- mWindow = nullptr;
- }
- else
- {
- Widget2::setWindow(widget);
- }
-}
-
-void Label::widgetHidden(const Event &event A_UNUSED)
-{
- mTextChanged = true;
- mTextChunk.deleteImage();
-}
-
-void Label::finalCleanup()
-{
- mSkin = nullptr;
-}
diff --git a/src/gui/widgets/label.h b/src/gui/widgets/label.h
deleted file mode 100644
index 26790258c..000000000
--- a/src/gui/widgets/label.h
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 Aethyra Development Team
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_LABEL_H
-#define GUI_WIDGETS_LABEL_H
-
-#include "gui/fonts/textchunk.h"
-
-#include "gui/widgets/widget.h"
-
-#include "listeners/tooltiplistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "render/graphics.h"
-
-#include "localconsts.h"
-
-class Skin;
-
-/**
- * Label widget. Same as the Guichan label but modified to use the palette
- * system.
- *
- * \ingroup GUI
- */
-class Label final : public Widget,
- public WidgetListener,
- public ToolTipListener
-{
- public:
- /**
- * Constructor.
- */
- explicit Label(const Widget2 *const widget);
-
- /**
- * Constructor. This version of the constructor sets the label with an
- * inintialization string.
- */
- Label(const Widget2 *const widget,
- const std::string &caption);
-
- A_DELETE_COPY(Label)
-
- ~Label();
-
- void init();
-
- /**
- * Draws the label.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void adjustSize();
-
- void setForegroundColor(const Color &color);
-
- void setForegroundColorAll(const Color &color1,
- const Color &color2);
-
- void resizeTo(const int maxSize, const int minSize);
-
- /**
- * Gets the caption of the label.
- *
- * @return The caption of the label.
- * @see setCaption
- */
- const std::string &getCaption() const
- { return mCaption; }
-
- /**
- * Sets the caption of the label. It's advisable to call
- * adjustSize after setting of the caption to adjust the
- * label's size to fit the caption.
- *
- * @param caption The caption of the label.
- * @see getCaption, adjustSize
- */
- void setCaption(const std::string& caption);
-
- /**
- * Sets the alignment of the caption. The alignment is relative
- * to the center of the label.
- *
- * @param alignment The alignment of the caption of the label.
- * @see getAlignment, Graphics
- */
- void setAlignment(Graphics::Alignment alignment)
- { mAlignment = alignment; }
-
- /**
- * Gets the alignment of the caption. The alignment is relative to
- * the center of the label.
- *
- * @return The alignment of caption of the label.
- * @see setAlignmentm Graphics
- */
- Graphics::Alignment getAlignment() const
- { return mAlignment; }
-
- void setParent(Widget *const widget) override final;
-
- void setWindow(Widget *const widget) override final;
-
- void widgetHidden(const Event &event) override final;
-
- static Skin *mSkin;
-
- static int mInstances;
-
- static void finalCleanup();
-
- private:
- /**
- * Holds the caption of the label.
- */
- std::string mCaption;
-
- TextChunk mTextChunk;
-
- /**
- * Holds the alignment of the caption.
- */
- Graphics::Alignment mAlignment;
-
- int mPadding;
-
- bool mTextChanged;
-};
-
-#endif // GUI_WIDGETS_LABEL_H
diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp
deleted file mode 100644
index 0a9464dd2..000000000
--- a/src/gui/widgets/layout.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/layout.h"
-
-#include "debug.h"
-
-Layout::Layout() :
- LayoutCell(),
- mComputed(false)
-{
- getArray();
- setPadding(6);
-}
-
-void Layout::reflow(int &restrict nw, int &restrict nh)
-{
- if (!mComputed)
- {
- computeSizes();
- mComputed = true;
- }
-
- nw = (nw == 0 ? mSize[0] + 2 * mHPadding : nw);
- nh = (nh == 0 ? mSize[1] + 2 * mVPadding : nh);
- LayoutCell::reflow(0, 0, nw, nh);
-}
diff --git a/src/gui/widgets/layout.h b/src/gui/widgets/layout.h
deleted file mode 100644
index 4e9c8f8c3..000000000
--- a/src/gui/widgets/layout.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_LAYOUT_H
-#define GUI_WIDGETS_LAYOUT_H
-
-#include "gui/widgets/layoutcell.h"
-
-#include "localconsts.h"
-
-/**
- * This class is an helper for setting the position of widgets. They are
- * positioned along the cells of some rectangular tables. The layout may either
- * be a single table or a tree of nested tables.
- *
- * The size of a given table column can either be set manually or be chosen
- * from the widest widget of the column. An empty column has a AUTO_DEF width,
- * which means it will be extended so that the layout fits its minimum width.
- *
- * The process is similar for table rows. By default, there is a spacing of 4
- * pixels between rows and between columns, and a margin of 6 pixels around the
- * whole layout.
- */
-class Layout final : public LayoutCell
-{
- public:
- Layout();
-
- A_DELETE_COPY(Layout)
-
- /**
- * Sets the margin around the layout.
- */
- void setMargin(int m)
- { setPadding(m); }
-
- /**
- * Sets the positions of all the widgets.
- * @see LayoutArray::reflow
- */
- void reflow(int &restrict nW, int &restrict nH);
-
- private:
- bool mComputed;
-};
-
-#endif // GUI_WIDGETS_LAYOUT_H
diff --git a/src/gui/widgets/layoutarray.cpp b/src/gui/widgets/layoutarray.cpp
deleted file mode 100644
index 6269d8b5b..000000000
--- a/src/gui/widgets/layoutarray.cpp
+++ /dev/null
@@ -1,313 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/layoutarray.h"
-
-#include "enums/gui/layouttype.h"
-
-#include "gui/widgets/layoutcell.h"
-#include "gui/widgets/widget.h"
-
-#include <cassert>
-
-#include "debug.h"
-
-LayoutArray::LayoutArray() :
- mCells(),
- mSpacing(4)
-{
-}
-
-LayoutArray::~LayoutArray()
-{
- STD_VECTOR <STD_VECTOR <LayoutCell *> >::iterator
- i = mCells.begin();
- const STD_VECTOR <STD_VECTOR <LayoutCell *> >::iterator
- i_end = mCells.end();
- while (i != i_end)
- {
- STD_VECTOR< LayoutCell * >::iterator j = i->begin();
- const STD_VECTOR< LayoutCell * >::iterator j_end = i->end();
- while (j != j_end)
- {
- delete *j;
- ++j;
- }
- ++i;
- }
-}
-
-LayoutCell &LayoutArray::at(const int x, const int y,
- const int w, const int h)
-{
- resizeGrid(x + w, y + h);
- LayoutCell *&cell = mCells[CAST_SIZE(y)][static_cast<size_t>(x)];
- if (cell == nullptr)
- cell = new LayoutCell;
- return *cell;
-}
-
-void LayoutArray::resizeGrid(int w, const int h)
-{
- const bool extW = (w != 0) && w > CAST_S32(mSizes[0].size());
- const bool extH = (h != 0) && h > CAST_S32(mSizes[1].size());
-
- if (!extW && !extH)
- return;
-
- if (extH)
- {
- mSizes[1].resize(CAST_SIZE(h), LayoutType::DEF);
- mCells.resize(CAST_SIZE(h));
- if (!extW)
- w = CAST_S32(mSizes[0].size());
- }
-
- if (extW)
- mSizes[0].resize(CAST_SIZE(w), LayoutType::DEF);
-
- STD_VECTOR <STD_VECTOR <LayoutCell *> >::iterator
- i = mCells.begin();
- const STD_VECTOR <STD_VECTOR <LayoutCell *> >::iterator
- i_end = mCells.end();
- while (i != i_end)
- {
- i->resize(CAST_SIZE(w), nullptr);
- ++i;
- }
-}
-
-void LayoutArray::setColWidth(const int n, const int w)
-{
- resizeGrid(n + 1, 0);
- mSizes[0U][CAST_SIZE(n)] = w;
-}
-
-void LayoutArray::setRowHeight(const int n, const int h)
-{
- resizeGrid(0, n + 1);
- mSizes[1][CAST_SIZE(n)] = h;
-}
-
-void LayoutArray::matchColWidth(const int n1, const int n2)
-{
- resizeGrid(std::max(n1, n2) + 1, 0);
- const STD_VECTOR<int> widths = getSizes(0, LayoutType::DEF);
- const int s = std::max(widths[CAST_SIZE(n1)],
- widths[CAST_SIZE(n2)]);
- mSizes[0][CAST_SIZE(n1)] = s;
- mSizes[0][CAST_SIZE(n2)] = s;
-}
-
-void LayoutArray::extend(const int x, const int y, const int w, const int h)
-{
- LayoutCell &cell = at(x, y, w, h);
- cell.mExtent[0] = w;
- cell.mExtent[1] = h;
-}
-
-LayoutCell &LayoutArray::place(Widget *const widget, const int x,
- const int y, const int w, const int h)
-{
- LayoutCell &cell = at(x, y, w, h);
- assert(cell.mType == LayoutCell::NONE);
- cell.mType = LayoutCell::WIDGET;
- cell.mWidget = widget;
- if (widget != nullptr)
- {
- cell.mSize[0] = w == 1 ? widget->getWidth() : 0;
- cell.mSize[1] = h == 1 ? widget->getHeight() : 0;
- }
- else
- {
- cell.mSize[0] = 1;
- cell.mSize[1] = 1;
- }
- cell.mExtent[0] = w;
- cell.mExtent[1] = h;
- cell.mHPadding = 0;
- cell.mVPadding = 0;
- cell.mAlign[0] = LayoutCell::FILL;
- cell.mAlign[1] = LayoutCell::FILL;
- int &cs = mSizes[0][CAST_SIZE(x)];
- int &rs = mSizes[1][CAST_SIZE(y)];
- if (cs == LayoutType::DEF && w == 1)
- cs = 0;
- if (rs == LayoutType::DEF && h == 1)
- rs = 0;
- return cell;
-}
-
-void LayoutArray::align(int &restrict pos, int &restrict size, const int dim,
- LayoutCell const &restrict cell,
- const int *restrict const sizes,
- const int sizeCount) const
-{
- if (dim < 0 || dim >= 2)
- return;
- int size_max = sizes[0];
- int cnt = cell.mExtent[dim];
- if ((sizeCount != 0) && cell.mExtent[dim] > sizeCount)
- cnt = sizeCount;
-
- for (int i = 1; i < cnt; ++i)
- size_max += sizes[i] + mSpacing;
- size = std::min<int>(cell.mSize[dim], size_max);
-
- switch (cell.mAlign[dim])
- {
- case LayoutCell::LEFT:
- return;
- case LayoutCell::RIGHT:
- pos += size_max - size;
- return;
- case LayoutCell::CENTER:
- pos += (size_max - size) / 2;
- return;
- case LayoutCell::FILL:
- size = size_max;
- return;
- default:
- logger->log1("LayoutArray::align unknown layout");
- return;
- }
-}
-
-STD_VECTOR<int> LayoutArray::getSizes(const int dim, int upp) const
-{
- if (dim < 0 || dim >= 2)
- return mSizes[1];
-
- const int gridW = CAST_S32(mSizes[0].size());
- const int gridH = CAST_S32(mSizes[1].size());
- STD_VECTOR<int> sizes = mSizes[dim];
-
- // Compute minimum sizes.
- for (int gridY = 0; gridY < gridH; ++gridY)
- {
- for (int gridX = 0; gridX < gridW; ++gridX)
- {
- const LayoutCell *const cell = mCells[CAST_SIZE(gridY)]
- [CAST_SIZE(gridX)];
- if ((cell == nullptr) || cell->mType == LayoutCell::NONE)
- continue;
-
- if (cell->mExtent[dim] == 1)
- {
- const int n = (dim == 0 ? gridX : gridY);
- const int s = cell->mSize[dim] + cell->mVPadding * 2;
- if (s > sizes[CAST_SIZE(n)])
- sizes[CAST_SIZE(n)] = s;
- }
- }
- }
-
- if (upp == LayoutType::DEF)
- return sizes;
-
- // Compute the FILL sizes.
- const int nb = CAST_S32(sizes.size());
- int nbFill = 0;
- for (int i = 0; i < nb; ++i)
- {
- if (mSizes[CAST_SIZE(dim)][static_cast<size_t>(i)]
- <= LayoutType::DEF)
- {
- ++nbFill;
- if (mSizes[CAST_SIZE(dim)][static_cast<size_t>(i)] ==
- LayoutType::SET ||
- sizes[CAST_SIZE(i)] <= LayoutType::DEF)
- {
- sizes[CAST_SIZE(i)] = 0;
- }
- }
- upp -= sizes[CAST_SIZE(i)] + mSpacing;
- }
- upp = upp + mSpacing;
-
- if (nbFill == 0)
- return sizes;
-
- for (int i = 0; i < nb; ++i)
- {
- if (mSizes[CAST_SIZE(dim)][static_cast<size_t>(i)] >
- LayoutType::DEF)
- {
- continue;
- }
-
- const int s = upp / nbFill;
- sizes[CAST_SIZE(i)] += s;
- upp -= s;
- --nbFill;
- }
-
- return sizes;
-}
-
-int LayoutArray::getSize(const int dim) const
-{
- STD_VECTOR<int> sizes = getSizes(dim, LayoutType::DEF);
- int size = 0;
- const int nb = CAST_S32(sizes.size());
- for (int i = 0; i < nb; ++i)
- {
- if (sizes[CAST_SIZE(i)] > LayoutType::DEF)
- size += sizes[CAST_SIZE(i)];
- size += mSpacing;
- }
- return size - mSpacing;
-}
-
-void LayoutArray::reflow(const int nx, const int ny,
- const int nw, const int nh)
-{
- const int gridW = CAST_S32(mSizes[0].size());
- const int gridH = CAST_S32(mSizes[1].size());
-
- STD_VECTOR<int> widths = getSizes(0, nw);
- STD_VECTOR<int> heights = getSizes(1, nh);
-
- const int szW = CAST_S32(widths.size());
- const int szH = CAST_S32(heights.size());
- int y = ny;
- for (int gridY = 0; gridY < gridH; ++gridY)
- {
- int x = nx;
- for (int gridX = 0; gridX < gridW; ++gridX)
- {
- LayoutCell *const cell = mCells[CAST_SIZE(gridY)]
- [CAST_SIZE(gridX)];
- if ((cell != nullptr) && cell->mType != LayoutCell::NONE)
- {
- int dx = x, dy = y, dw = 0, dh = 0;
- align(dx, dw, 0, *cell,
- &widths[CAST_SIZE(gridX)], szW - gridX);
- align(dy, dh, 1, *cell,
- &heights[CAST_SIZE(gridY)], szH - gridY);
- cell->reflow(dx, dy, dw, dh);
- }
- x += widths[CAST_SIZE(gridX)] + mSpacing;
- }
- y += heights[CAST_SIZE(gridY)] + mSpacing;
- }
-}
diff --git a/src/gui/widgets/layoutarray.h b/src/gui/widgets/layoutarray.h
deleted file mode 100644
index cca05e091..000000000
--- a/src/gui/widgets/layoutarray.h
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_LAYOUTARRAY_H
-#define GUI_WIDGETS_LAYOUTARRAY_H
-
-#include "utils/vector.h"
-
-#include "localconsts.h"
-
-class LayoutCell;
-class Widget;
-
-/**
- * This class contains a rectangular array of cells.
- */
-class LayoutArray final
-{
- friend class LayoutCell;
-
- public:
- LayoutArray();
-
- A_DEFAULT_COPY(LayoutArray)
-
- ~LayoutArray();
-
- /**
- * Returns a reference on the cell at given position.
- */
- LayoutCell &at(const int x, const int y,
- const int w = 1, const int h = 1) A_WARN_UNUSED;
-
- /**
- * Places a widget in a given cell.
- * @param w number of columns the widget spawns.
- * @param h number of rows the widget spawns.
- * @note When @a w is 1, the width of column @a x is reset to zero if
- * it was AUTO_DEF. Similarly for @a h.
- */
- LayoutCell &place(Widget *const widget, const int x, const int y,
- const int w = 1, const int h = 1);
-
- /**
- * Sets the minimum width of a column.
- */
- void setColWidth(const int n, const int w);
-
- /**
- * Sets the minimum height of a row.
- */
- void setRowHeight(const int n, const int h);
-
- /**
- * Sets the widths of two columns to the maximum of their widths.
- */
- void matchColWidth(const int n1, const int n2);
-
- /**
- * Spawns a cell over several columns/rows.
- */
- void extend(const int x, const int y, const int w, const int h);
-
- /**
- * Computes and sets the positions of all the widgets.
- * @param nW width of the array, used to resize the AUTO_ columns.
- * @param nH height of the array, used to resize the AUTO_ rows.
- */
- void reflow(const int nX, const int nY, const int nW, const int nH);
-
- private:
- // Copy not allowed, as the array owns all its cells.
- explicit LayoutArray(LayoutArray const &);
- LayoutArray &operator=(LayoutArray const &);
-
- /**
- * Gets the position and size of a widget along a given axis
- */
- void align(int &restrict pos,
- int &restrict size,
- const int dim,
- LayoutCell const &restrict cell,
- const int *restrict const sizes,
- const int sizeCount) const A_NONNULL(6);
-
- /**
- * Ensures the private vectors are large enough.
- */
- void resizeGrid(int w, const int h);
-
- /**
- * Gets the column/row sizes along a given axis.
- * @param upp target size for the array. Ignored if AUTO_DEF.
- */
- STD_VECTOR<int> getSizes(const int dim, int upp) const A_WARN_UNUSED;
-
- /**
- * Gets the total size along a given axis.
- */
- int getSize(const int dim) const A_WARN_UNUSED;
-
- STD_VECTOR<int> mSizes[2];
- STD_VECTOR< STD_VECTOR < LayoutCell * > > mCells;
-
- int mSpacing;
-};
-
-#endif // GUI_WIDGETS_LAYOUTARRAY_H
diff --git a/src/gui/widgets/layoutcell.cpp b/src/gui/widgets/layoutcell.cpp
deleted file mode 100644
index 7db5d0783..000000000
--- a/src/gui/widgets/layoutcell.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/layoutcell.h"
-
-#include "gui/widgets/layoutarray.h"
-#include "gui/widgets/widget.h"
-
-#include "utils/delete2.h"
-
-#include "debug.h"
-
-static LayoutArray tempArray;
-LayoutCell LayoutCell::emptyCell;
-
-LayoutCell::~LayoutCell()
-{
- if (mType == ARRAY)
- delete2(mArray)
-}
-
-LayoutArray &LayoutCell::getArray()
-{
- if (mType == WIDGET)
- return tempArray;
- if (mType == ARRAY)
- {
- if (mArray == nullptr)
- return tempArray;
- return *mArray;
- }
-
- mArray = new LayoutArray;
- mType = ARRAY;
- mExtent[0] = 1;
- mExtent[1] = 1;
- mHPadding = 0;
- mVPadding = 0;
- mAlign[0] = FILL;
- mAlign[1] = FILL;
- return *mArray;
-}
-
-void LayoutCell::reflow(int nx, int ny, int nw, int nh)
-{
- if (mType == NONE)
- return;
-
- nx += mHPadding;
- ny += mVPadding;
- nw -= 2 * mHPadding;
- nh -= 2 * mVPadding;
- if (mType == ARRAY)
- mArray->reflow(nx, ny, nw, nh);
- else
- mWidget->setDimension(Rect(nx, ny, nw, nh));
-}
-
-void LayoutCell::computeSizes()
-{
- if (mType != ARRAY)
- return;
-
- STD_VECTOR <STD_VECTOR <LayoutCell *> >::const_iterator
- i = mArray->mCells.begin();
- const STD_VECTOR <STD_VECTOR <LayoutCell *> >::const_iterator
- i_end = mArray->mCells.end();
- while (i != i_end)
- {
- STD_VECTOR <LayoutCell *>::const_iterator j = i->begin();
- while (j != i->end())
- {
- LayoutCell *const cell = *j;
- if ((cell != nullptr) && cell->mType == ARRAY)
- cell->computeSizes();
-
- ++j;
- }
- ++i;
- }
-
- mSize[0] = mArray->getSize(0);
- mSize[1] = mArray->getSize(1);
-}
-
-LayoutCell &LayoutCell::at(const int x, const int y)
-{
- return getArray().at(x, y);
-}
-
-LayoutCell &LayoutCell::place(Widget *const wg,
- const int x, const int y,
- const int w, const int h)
-{
- return getArray().place(wg, x, y, w, h);
-}
-
-void LayoutCell::matchColWidth(const int n1, const int n2)
-{
- getArray().matchColWidth(n1, n2);
-}
-
-void LayoutCell::setColWidth(const int n, const int w)
-{
- getArray().setColWidth(n, w);
-}
-
-void LayoutCell::setRowHeight(const int n, const int h)
-{
- getArray().setRowHeight(n, h);
-}
-
-void LayoutCell::extend(const int x, const int y,
- const int w, const int h)
-{
- getArray().extend(x, y, w, h);
-}
diff --git a/src/gui/widgets/layoutcell.h b/src/gui/widgets/layoutcell.h
deleted file mode 100644
index e6404cfde..000000000
--- a/src/gui/widgets/layoutcell.h
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_LAYOUTCELL_H
-#define GUI_WIDGETS_LAYOUTCELL_H
-
-#include "localconsts.h"
-
-class LayoutArray;
-class Widget;
-
-/**
- * This class describes the formatting of a widget in the cell of a layout
- * table. Horizontally, a widget can either fill the width of the cell (minus
- * the cell padding), or it can retain its size and be flushed left, or flush
- * right, or centered in the cell. The process is similar for the vertical
- * alignment, except that top is represented by LEFT and bottom by RIGHT.
- */
-class LayoutCell notfinal
-{
- friend class Layout;
- friend class LayoutArray;
-
- public:
- A_DEFAULT_COPY(LayoutCell)
-
- enum Alignment
- {
- LEFT = 0,
- RIGHT,
- CENTER,
- FILL
- };
-
- virtual ~LayoutCell();
-
- /**
- * Sets the padding around the cell content.
- */
- LayoutCell &setPadding(int p)
- { mHPadding = p; mVPadding = p; return *this; }
-
- /**
- * Sets the vertical padding around the cell content.
- */
- LayoutCell &setVPadding(int p)
- { mVPadding = p; return *this; }
-
- /**
- * Sets the horisontal padding around the cell content.
- */
- LayoutCell &setHPadding(int p)
- { mHPadding = p; return *this; }
-
- /**
- * Sets the horizontal alignment of the cell content.
- */
- LayoutCell &setHAlign(const Alignment a)
- { mAlign[0] = a; return *this; }
-
- /**
- * Sets the vertical alignment of the cell content.
- */
- LayoutCell &setVAlign(const Alignment a)
- { mAlign[1] = a; return *this; }
-
- /**
- * @see LayoutArray::at
- */
- LayoutCell &at(const int x, const int y) A_WARN_UNUSED;
-
- /**
- * @see LayoutArray::place
- */
- LayoutCell &place(Widget *const wg,
- const int x, const int y,
- const int w = 1, const int h = 1);
-
- /**
- * @see LayoutArray::matchColWidth
- */
- void matchColWidth(const int n1, const int n2);
-
- /**
- * @see LayoutArray::setColWidth
- */
- void setColWidth(const int n, const int w);
-
- /**
- * @see LayoutArray::setRowHeight
- */
- void setRowHeight(const int n, const int h);
-
- /**
- * @see LayoutArray::extend.
- */
- void extend(const int x, const int y,
- const int w, const int h);
-
- /**
- * Sets the minimum widths and heights of this cell and of all the
- * inner cells.
- */
- void computeSizes();
-
- void setType(int t)
- { mType = t; }
-
- int getWidth() const noexcept2 A_WARN_UNUSED
- { return mExtent[0]; }
-
- int getHeight() const noexcept2 A_WARN_UNUSED
- { return mExtent[1]; }
-
- void setWidth(const int w) noexcept2
- { mExtent[0] = w; }
-
- void setHeight(const int h) noexcept2
- { mExtent[1] = h; }
-
- enum
- {
- NONE = 0,
- WIDGET,
- ARRAY
- };
-
- static LayoutCell emptyCell;
-
- private:
- LayoutCell() :
- mWidget(nullptr),
- mHPadding(0),
- mVPadding(0),
- mType(NONE)
- {
- mExtent[0] = 0;
- mExtent[1] = 0;
- mAlign[0] = LEFT;
- mAlign[1] = LEFT;
- mNbFill[0] = 0;
- mNbFill[1] = 0;
- mSize[0] = 0;
- mSize[1] = 0;
- }
-
- // Copy not allowed, as the cell may own an array.
- explicit LayoutCell(LayoutCell const &);
- LayoutCell &operator=(LayoutCell const &);
-
- union
- {
- Widget *mWidget;
- LayoutArray *mArray;
- };
-
- /**
- * Returns the embedded array. Creates it if the cell does not contain
- * anything yet. Aborts if it contains a widget.
- */
- LayoutArray &getArray();
-
- /**
- * @see LayoutArray::reflow
- */
- void reflow(int nx, int ny, int nw, int nh);
-
- int mSize[2];
- int mHPadding;
- int mVPadding;
- int mExtent[2];
- Alignment mAlign[2];
- int mNbFill[2];
- int mType;
-};
-
-#endif // GUI_WIDGETS_LAYOUTCELL_H
diff --git a/src/gui/widgets/layouthelper.cpp b/src/gui/widgets/layouthelper.cpp
deleted file mode 100644
index 19114c1ae..000000000
--- a/src/gui/widgets/layouthelper.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/layouthelper.h"
-
-#include "gui/widgets/basiccontainer2.h"
-#include "gui/widgets/containerplacer.h"
-
-#include "debug.h"
-
-LayoutHelper::LayoutHelper(BasicContainer2 *const container) :
- WidgetListener(),
- mLayout(),
- mContainer(container)
-{
- if (mContainer != nullptr)
- mContainer->addWidgetListener(this);
-}
-
-LayoutHelper::~LayoutHelper()
-{
- if (mContainer != nullptr)
- mContainer->removeWidgetListener(this);
-}
-
-const Layout &LayoutHelper::getLayout() const
-{
- return mLayout;
-}
-
-LayoutCell &LayoutHelper::place(const int x, const int y,
- Widget *const wg,
- const int w, const int h)
-{
- if (mContainer != nullptr)
- mContainer->add(wg);
- return mLayout.place(wg, x, y, w, h);
-}
-
-ContainerPlacer LayoutHelper::getPlacer(const int x, const int y)
-{
- return ContainerPlacer(mContainer, &mLayout.at(x, y));
-}
-
-void LayoutHelper::reflowLayout(int w, int h)
-{
- mLayout.reflow(w, h);
- if (mContainer != nullptr)
- mContainer->setSize(w, h);
-}
-
-void LayoutHelper::widgetResized(const Event &event A_UNUSED)
-{
- if (mContainer == nullptr)
- return;
- const Rect area = mContainer->getChildrenArea();
- int w = area.width;
- int h = area.height;
- mLayout.reflow(w, h);
-}
diff --git a/src/gui/widgets/layouthelper.h b/src/gui/widgets/layouthelper.h
deleted file mode 100644
index 0f84e280c..000000000
--- a/src/gui/widgets/layouthelper.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_LAYOUTHELPER_H
-#define GUI_WIDGETS_LAYOUTHELPER_H
-
-#include "gui/widgets/layout.h"
-
-#include "listeners/widgetlistener.h"
-
-class BasicContainer2;
-class ContainerPlacer;
-
-/**
- * A helper class for adding a layout to a Guichan container widget. The layout
- * will register itself as a widget listener and relayout the widgets in the
- * container dynamically on resize.
- */
-class LayoutHelper final : public WidgetListener
-{
- public:
- /**
- * Constructor.
- */
- explicit LayoutHelper(BasicContainer2 *const container);
-
- A_DELETE_COPY(LayoutHelper)
-
- /**
- * Destructor.
- */
- ~LayoutHelper();
-
- /**
- * Gets the layout handler.
- */
- const Layout &getLayout() const A_WARN_UNUSED A_CONST;
-
- /**
- * Computes the position of the widgets according to the current
- * layout. Resizes the managed container so that the layout fits.
- *
- * @note This function is meant to be called with fixed-size
- * containers.
- *
- * @param w if non-zero, force the container to this width.
- * @param h if non-zero, force the container to this height.
- */
- void reflowLayout(int w = 0, int h = 0);
-
- /**
- * Adds a widget to the container and sets it at given cell.
- */
- LayoutCell &place(const int x, const int y, Widget *const wg,
- const int w = 1, const int h = 1);
-
- /**
- * Returns a proxy for adding widgets in an inner table of the layout.
- */
- ContainerPlacer getPlacer(const int x, const int y) A_WARN_UNUSED;
-
- /**
- * Called whenever the managed container changes size.
- */
- void widgetResized(const Event &event) override final;
-
- private:
- Layout mLayout; /**< Layout handler */
- BasicContainer2 *mContainer; /**< Managed container */
-};
-
-#endif // GUI_WIDGETS_LAYOUTHELPER_H
diff --git a/src/gui/widgets/linepart.cpp b/src/gui/widgets/linepart.cpp
deleted file mode 100644
index 2e1cab392..000000000
--- a/src/gui/widgets/linepart.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 Aethyra Development Team
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/linepart.h"
-
-#include "resources/image/image.h"
-
-#include "debug.h"
-
-LinePart::~LinePart()
-{
- if (mImage != nullptr)
- mImage->decRef();
- mImage = nullptr;
-}
diff --git a/src/gui/widgets/linepart.h b/src/gui/widgets/linepart.h
deleted file mode 100644
index d88a6543e..000000000
--- a/src/gui/widgets/linepart.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 Aethyra Development Team
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_LINEPART_H
-#define GUI_WIDGETS_LINEPART_H
-
-#include "gui/color.h"
-
-#include <string>
-
-#include "localconsts.h"
-
-class Image;
-
-class LinePart final
-{
- public:
- LinePart(const int x, const int y, const Color &color,
- const Color &color2, const std::string &text,
- const bool bold) :
- mX(x),
- mY(y),
- mColor(color),
- mColor2(color2),
- mText(text),
- mType(0),
- mImage(nullptr),
- mBold(bold)
- {
- }
-
- LinePart(const int x, const int y, const Color &color,
- const Color &color2, Image *const image) :
- mX(x),
- mY(y),
- mColor(color),
- mColor2(color2),
- mText(),
- mType(1),
- mImage(image),
- mBold(false)
- {
- }
-
- LinePart(const LinePart &l) :
- mX(l.mX),
- mY(l.mY),
- mColor(l.mColor),
- mColor2(l.mColor2),
- mText(l.mText),
- mType(l.mType),
- mImage(l.mImage),
- mBold(l.mBold)
- {
- }
-
- LinePart &operator=(const LinePart &l)
- {
- mX = l.mX;
- mY = l.mY;
- mColor = l.mColor;
- mColor2 = l.mColor2;
- mText = l.mText;
- mType = l.mType;
- mImage = l.mImage;
- mBold = l.mBold;
- return *this;
- }
-
- A_DEFAULT_COPY(LinePart)
-
- ~LinePart();
-
- int mX;
- int mY;
- Color mColor;
- Color mColor2;
- std::string mText;
- unsigned char mType;
- Image *mImage;
- bool mBold;
-};
-
-#endif // GUI_WIDGETS_LINEPART_H
diff --git a/src/gui/widgets/linkhandler.h b/src/gui/widgets/linkhandler.h
deleted file mode 100644
index 3b46e9fd3..000000000
--- a/src/gui/widgets/linkhandler.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_LINKHANDLER_H
-#define GUI_WIDGETS_LINKHANDLER_H
-
-#include <string>
-
-#include "listeners/mouselistener.h"
-
-/**
- * A simple interface to windows that need to handle links from BrowserBox
- * widget.
- */
-class LinkHandler notfinal
-{
- public:
- LinkHandler()
- { }
-
- A_DELETE_COPY(LinkHandler)
-
- virtual ~LinkHandler()
- { }
-
- virtual void handleLink(const std::string &link,
- MouseEvent *event) = 0;
-};
-
-#endif // GUI_WIDGETS_LINKHANDLER_H
diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp
deleted file mode 100644
index 0bf590f6b..000000000
--- a/src/gui/widgets/listbox.cpp
+++ /dev/null
@@ -1,446 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/listbox.h"
-
-#include "settings.h"
-
-#include "gui/focushandler.h"
-#include "gui/gui.h"
-#include "gui/skin.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/models/listmodel.h"
-
-#include "listeners/selectionlistener.h"
-
-#include "utils/foreach.h"
-
-#include "render/graphics.h"
-
-#include "debug.h"
-
-float ListBox::mAlpha = 1.0;
-
-ListBox::ListBox(const Widget2 *const widget,
- ListModel *const listModel,
- const std::string &skin) :
- Widget(widget),
- MouseListener(),
- KeyListener(),
- mSelected(-1),
- mListModel(listModel),
- mWrappingEnabled(false),
- mSelectionListeners(),
- mHighlightColor(getThemeColor(ThemeColorId::HIGHLIGHT)),
- mForegroundSelectedColor(getThemeColor(ThemeColorId::LISTBOX_SELECTED)),
- mForegroundSelectedColor2(getThemeColor(
- ThemeColorId::LISTBOX_SELECTED_OUTLINE)),
- mOldSelected(-1),
- mPadding(0),
- mPressedIndex(-2),
- mRowHeight(0),
- mItemPadding(1),
- mSkin(nullptr),
- mDistributeMousePressed(true),
- mCenterText(false)
-{
- setWidth(100);
- setFocusable(true);
- addMouseListener(this);
- addKeyListener(this);
-
- mForegroundColor = getThemeColor(ThemeColorId::LISTBOX);
- mForegroundColor2 = getThemeColor(ThemeColorId::LISTBOX_OUTLINE);
-
- if (theme != nullptr)
- mSkin = theme->load(skin, "listbox.xml");
-
- if (mSkin != nullptr)
- {
- mPadding = mSkin->getPadding();
- mItemPadding = mSkin->getOption("itemPadding");
- }
-
- const Font *const font = getFont();
- mRowHeight = CAST_U32(
- font->getHeight() + 2 * mItemPadding);
-}
-
-void ListBox::postInit()
-{
- adjustSize();
-}
-
-ListBox::~ListBox()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- if (theme != nullptr)
- theme->unload(mSkin);
-}
-
-void ListBox::updateAlpha()
-{
- const float alpha = std::max(settings.guiAlpha,
- theme->getMinimumOpacity());
-
- if (mAlpha != alpha)
- mAlpha = alpha;
-}
-
-void ListBox::draw(Graphics *const graphics)
-{
- if (mListModel == nullptr)
- return;
-
- BLOCK_START("ListBox::draw")
- updateAlpha();
-
- mHighlightColor.a = CAST_U32(mAlpha * 255.0F);
- graphics->setColor(mHighlightColor);
- Font *const font = getFont();
- const int rowHeight = CAST_S32(getRowHeight());
- const int width = mDimension.width;
-
- if (mCenterText)
- {
- // Draw filled rectangle around the selected list element
- if (mSelected >= 0)
- {
- graphics->fillRectangle(Rect(mPadding,
- rowHeight * mSelected + mPadding,
- mDimension.width - 2 * mPadding, rowHeight));
-
- const std::string str = mListModel->getElementAt(mSelected);
- font->drawString(graphics,
- mForegroundSelectedColor,
- mForegroundSelectedColor2,
- str,
- (width - font->getWidth(str)) / 2,
- mSelected * rowHeight + mPadding + mItemPadding);
- }
- // Draw the list elements
- const int sz = mListModel->getNumberOfElements();
- for (int i = 0, y = mPadding + mItemPadding;
- i < sz; ++i, y += rowHeight)
- {
- if (i != mSelected)
- {
- const std::string str = mListModel->getElementAt(i);
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor2,
- str,
- (width - font->getWidth(str)) / 2, y);
- }
- }
- }
- else
- {
- // Draw filled rectangle around the selected list element
- if (mSelected >= 0)
- {
- graphics->fillRectangle(Rect(mPadding,
- rowHeight * mSelected + mPadding,
- mDimension.width - 2 * mPadding, rowHeight));
-
- const std::string str = mListModel->getElementAt(mSelected);
- font->drawString(graphics,
- mForegroundSelectedColor,
- mForegroundSelectedColor2,
- str,
- mPadding,
- mSelected * rowHeight + mPadding + mItemPadding);
- }
- // Draw the list elements
- const int sz = mListModel->getNumberOfElements();
- for (int i = 0, y = mPadding + mItemPadding; i < sz;
- ++i, y += rowHeight)
- {
- if (i != mSelected)
- {
- const std::string str = mListModel->getElementAt(i);
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor2,
- str,
- mPadding, y);
- }
- }
- }
- BLOCK_END("ListBox::draw")
-}
-
-void ListBox::keyPressed(KeyEvent &event)
-{
- const InputActionT action = event.getActionId();
- if (action == InputAction::GUI_SELECT)
- {
- distributeActionEvent();
- event.consume();
- }
- else if (action == InputAction::GUI_UP)
- {
- if (mSelected > 0)
- {
- setSelected(mSelected - 1);
- }
- else if (mSelected == 0 &&
- mWrappingEnabled &&
- getListModel() != nullptr)
- {
- setSelected(getListModel()->getNumberOfElements() - 1);
- }
- event.consume();
- }
- else if (action == InputAction::GUI_DOWN)
- {
- const int num = getListModel()->getNumberOfElements() - 1;
- if (mSelected < num)
- setSelected(mSelected + 1);
- else if (mSelected == num && mWrappingEnabled)
- setSelected(0);
- event.consume();
- }
- else if (action == InputAction::GUI_HOME)
- {
- setSelected(0);
- event.consume();
- }
- else if (action == InputAction::GUI_END && (getListModel() != nullptr))
- {
- setSelected(getListModel()->getNumberOfElements() - 1);
- event.consume();
- }
-}
-
-void ListBox::safeDraw(Graphics *const graphics)
-{
- ListBox::draw(graphics);
-}
-
-// Don't do anything on scrollwheel. ScrollArea will deal with that.
-
-void ListBox::mouseWheelMovedUp(MouseEvent &event A_UNUSED)
-{
-}
-
-void ListBox::mouseWheelMovedDown(MouseEvent &event A_UNUSED)
-{
-}
-
-void ListBox::mousePressed(MouseEvent &event)
-{
- mPressedIndex = getSelectionByMouse(event.getY());
- if (mMouseConsume && mPressedIndex != -1)
- event.consume();
-}
-
-void ListBox::mouseReleased(MouseEvent &event)
-{
- if (mPressedIndex != getSelectionByMouse(event.getY()))
- return;
-
- if (mDistributeMousePressed)
- {
- mouseReleased1(event);
- }
- else
- {
- switch (event.getClickCount())
- {
- case 1:
- mouseDragged(event);
- mOldSelected = mSelected;
- break;
- case 2:
- if (gui != nullptr)
- gui->resetClickCount();
- if (mOldSelected == mSelected)
- mouseReleased1(event);
- else
- mouseDragged(event);
- mOldSelected = mSelected;
- break;
- default:
- mouseDragged(event);
- mOldSelected = mSelected;
- break;
- }
- }
- mPressedIndex = -2;
-}
-
-void ListBox::mouseReleased1(const MouseEvent &event)
-{
- if (event.getButton() == MouseButton::LEFT)
- {
- setSelected(std::max(0, getSelectionByMouse(event.getY())));
- distributeActionEvent();
- }
-}
-
-void ListBox::mouseDragged(MouseEvent &event)
-{
- if (event.getButton() != MouseButton::LEFT || getRowHeight() == 0)
- return;
-
- // Make list selection update on drag, but guard against negative y
- if (getRowHeight() != 0u)
- setSelected(std::max(0, getSelectionByMouse(event.getY())));
-}
-
-void ListBox::refocus()
-{
- if (mFocusHandler == nullptr)
- return;
-
- if (isFocusable())
- mFocusHandler->requestFocus(this);
-}
-
-void ListBox::adjustSize()
-{
- BLOCK_START("ListBox::adjustSize")
- if (mListModel != nullptr)
- {
- setHeight(CAST_S32(getRowHeight()) *
- mListModel->getNumberOfElements() + 2 * mPadding);
- }
- BLOCK_END("ListBox::adjustSize")
-}
-
-void ListBox::logic()
-{
- BLOCK_START("ListBox::logic")
- adjustSize();
- BLOCK_END("ListBox::logic")
-}
-
-int ListBox::getSelectionByMouse(const int y) const
-{
- if (y < mPadding)
- return -1;
- return (y - mPadding) / CAST_S32(getRowHeight());
-}
-
-void ListBox::setSelected(const int selected)
-{
- if (mListModel == nullptr)
- {
- mSelected = -1;
- }
- else
- {
- if (selected < 0)
- mSelected = -1;
- else if (selected >= mListModel->getNumberOfElements())
- mSelected = mListModel->getNumberOfElements() - 1;
- else
- mSelected = selected;
- }
-
- Rect scroll;
-
- if (mSelected < 0)
- scroll.y = 0;
- else
- scroll.y = CAST_S32(getRowHeight()) * mSelected;
-
- scroll.height = CAST_S32(getRowHeight());
- showPart(scroll);
-
- distributeValueChangedEvent();
-}
-
-void ListBox::setListModel(ListModel *const listModel)
-{
- mSelected = -1;
- mListModel = listModel;
- adjustSize();
-}
-
-void ListBox::addSelectionListener(SelectionListener *const selectionListener)
-{
- mSelectionListeners.push_back(selectionListener);
-}
-
-void ListBox::removeSelectionListener(SelectionListener *const
- selectionListener)
-{
- mSelectionListeners.remove(selectionListener);
-}
-
-void ListBox::distributeValueChangedEvent()
-{
- FOR_EACH (SelectionListenerIterator, iter, mSelectionListeners)
- {
- SelectionEvent event(this);
- (*iter)->valueChanged(event);
- }
-}
diff --git a/src/gui/widgets/listbox.h b/src/gui/widgets/listbox.h
deleted file mode 100644
index 5c90058a8..000000000
--- a/src/gui/widgets/listbox.h
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_LISTBOX_H
-#define GUI_WIDGETS_LISTBOX_H
-
-#include "gui/widgets/widget.h"
-
-#include "listeners/keylistener.h"
-#include "listeners/mouselistener.h"
-
-#include "localconsts.h"
-
-class Skin;
-class KeyEvent;
-class ListModel;
-class MouseEvent;
-class SelectionListener;
-class Widget2;
-
-/**
- * A list box, meant to be used inside a scroll area. Same as the Guichan list
- * box except this one doesn't have a background, instead completely relying
- * on the scroll area. It also adds selection listener functionality.
- *
- * \ingroup GUI
- */
-class ListBox notfinal : public Widget,
- public MouseListener,
- public KeyListener
-{
- public:
- /**
- * Constructor.
- */
- ListBox(const Widget2 *const widget,
- ListModel *const listModel,
- const std::string &skin);
-
- A_DELETE_COPY(ListBox)
-
- virtual ~ListBox();
-
- void postInit() override;
-
- /**
- * Draws the list box.
- */
- void draw(Graphics *const graphics) override A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override A_NONNULL(2);
-
- /**
- * Update the alpha value to the graphic components.
- */
- void updateAlpha();
-
- // Inherited from KeyListener
-
- void keyPressed(KeyEvent& event) override final;
-
- // Inherited from MouseListener
-
- void mouseWheelMovedUp(MouseEvent& event) override final A_CONST;
-
- void mouseWheelMovedDown(MouseEvent& event) override final A_CONST;
-
- void mousePressed(MouseEvent &event) override;
-
- void mouseReleased(MouseEvent &event) override;
-
- void mouseReleased1(const MouseEvent &event);
-
- void mouseDragged(MouseEvent &event) override;
-
- void refocus();
-
- void setDistributeMousePressed(const bool b) noexcept2
- { mDistributeMousePressed = b; }
-
- virtual void adjustSize();
-
- void logic() override final;
-
- virtual int getSelectionByMouse(const int y) const;
-
- void setCenter(const bool b) noexcept2
- { mCenterText = b; }
-
- int getPressedIndex() const noexcept2 A_WARN_UNUSED
- { return mPressedIndex; }
-
- virtual unsigned int getRowHeight() const A_WARN_UNUSED
- { return mRowHeight; }
-
- void setRowHeight(unsigned int n) noexcept2
- { mRowHeight = n; }
-
- /**
- * Gets the selected item as an index in the list model.
- *
- * @return the selected item as an index in the list model.
- * @see setSelected
- */
- int getSelected() const noexcept2 A_WARN_UNUSED
- { return mSelected; }
-
- /**
- * Sets the selected item. The selected item is represented by
- * an index from the list model.
- *
- * @param selected the selected item as an index from the list model.
- * @see getSelected
- */
- void setSelected(const int selected);
-
- /**
- * Sets the list model to use.
- *
- * @param listModel the list model to use.
- * @see getListModel
- */
- void setListModel(ListModel *listModel);
-
- /**
- * Gets the list model used.
- *
- * @return the list model used.
- * @see setListModel
- */
- ListModel *getListModel() const noexcept2 A_WARN_UNUSED
- { return mListModel; }
-
- /**
- * Checks whether the list box wraps when selecting items with a
- * keyboard.
- *
- * Wrapping means that the selection of items will be wrapped. That is,
- * if the first item is selected and up is pressed, the last item will
- * get selected. If the last item is selected and down is pressed, the
- * first item will get selected.
- *
- * @return true if wrapping is enabled, fasle otherwise.
- * @see setWrappingEnabled
- */
- bool isWrappingEnabled() const noexcept2 A_WARN_UNUSED
- { return mWrappingEnabled; }
-
- /**
- * Sets the list box to wrap or not when selecting items with a
- * keyboard.
- *
- * Wrapping means that the selection of items will be wrapped. That is,
- * if the first item is selected and up is pressed, the last item will
- * get selected. If the last item is selected and down is pressed, the
- * first item will get selected.
- *
- * @see isWrappingEnabled
- */
- void setWrappingEnabled(const bool wrappingEnabled) noexcept2
- { mWrappingEnabled = wrappingEnabled; }
-
- /**
- * Adds a selection listener to the list box. When the selection
- * changes an event will be sent to all selection listeners of the
- * list box.
- *
- * If you delete your selection listener, be sure to also remove it
- * using removeSelectionListener().
- *
- * @param selectionListener The selection listener to add.
- */
- void addSelectionListener(SelectionListener *const selectionListener);
-
- /**
- * Removes a selection listener from the list box.
- *
- * @param selectionListener The selection listener to remove.
- */
- void removeSelectionListener(SelectionListener *const
- selectionListener);
-
- /**
- * Distributes a value changed event to all selection listeners
- * of the list box.
- */
- void distributeValueChangedEvent();
-
- protected:
- /**
- * The selected item as an index in the list model.
- */
- int mSelected;
-
- /**
- * The list model to use.
- */
- ListModel *mListModel;
-
- /**
- * True if wrapping is enabled, false otherwise.
- */
- bool mWrappingEnabled;
-
- /**
- * Typdef.
- */
- typedef std::list<SelectionListener*> SelectionListenerList;
-
- /**
- * The selection listeners of the list box.
- */
- SelectionListenerList mSelectionListeners;
-
- /**
- * Typedef.
- */
- typedef SelectionListenerList::iterator SelectionListenerIterator;
-
- Color mHighlightColor;
- Color mForegroundSelectedColor;
- Color mForegroundSelectedColor2;
- int mOldSelected;
- int mPadding;
- int mPressedIndex;
- unsigned int mRowHeight;
- int mItemPadding;
- Skin *mSkin;
- static float mAlpha;
- bool mDistributeMousePressed;
- bool mCenterText;
-};
-
-#endif // GUI_WIDGETS_LISTBOX_H
diff --git a/src/gui/widgets/passwordfield.cpp b/src/gui/widgets/passwordfield.cpp
deleted file mode 100644
index bc2ca4827..000000000
--- a/src/gui/widgets/passwordfield.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/passwordfield.h"
-
-#include "gui/skin.h"
-
-#include "debug.h"
-
-PasswordField::PasswordField(const Widget2 *const widget,
- const std::string &text) :
- TextField(widget, text),
- mPasswordChar(mSkin != nullptr ? CAST_8(
- mSkin->getOption("passwordChar", 42))
- : CAST_8(42))
-{
-}
-
-void PasswordField::draw(Graphics *const graphics)
-{
- BLOCK_START("PasswordField::draw")
- // std::string uses cow, thus cheap copy
- const std::string original = mText;
- if (mPasswordChar != 0)
- mText.assign(mText.length(), mPasswordChar);
- else
- mText.clear();
- TextField::draw(graphics);
- mText = original;
- BLOCK_END("PasswordField::draw")
-}
-
-void PasswordField::safeDraw(Graphics *const graphics)
-{
- PasswordField::draw(graphics);
-}
diff --git a/src/gui/widgets/passwordfield.h b/src/gui/widgets/passwordfield.h
deleted file mode 100644
index 93dded8d5..000000000
--- a/src/gui/widgets/passwordfield.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_PASSWORDFIELD_H
-#define GUI_WIDGETS_PASSWORDFIELD_H
-
-#include "gui/widgets/textfield.h"
-
-/**
- * A password field.
- *
- * \ingroup GUI
- */
-class PasswordField final : public TextField
-{
- public:
- /**
- * Constructor, initializes the password field with the given string.
- */
- explicit PasswordField(const Widget2 *const widget,
- const std::string &text = "");
-
- A_DELETE_COPY(PasswordField)
-
- /**
- * Draws the password field.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- protected:
- char mPasswordChar;
-};
-
-#endif // GUI_WIDGETS_PASSWORDFIELD_H
diff --git a/src/gui/widgets/playerbox.cpp b/src/gui/widgets/playerbox.cpp
deleted file mode 100644
index b6217383f..000000000
--- a/src/gui/widgets/playerbox.cpp
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/playerbox.h"
-
-#include "settings.h"
-
-#include "being/being.h"
-
-#include "gui/gui.h"
-#include "gui/skin.h"
-
-#include "render/graphics.h"
-
-#include "resources/image/image.h"
-
-#include "debug.h"
-
-PlayerBox::PlayerBox(Widget2 *const widget,
- Being *const being,
- const std::string &skin,
- const std::string &selectedSkin) :
- Widget(widget),
- MouseListener(),
- mBeing(being),
- mAlpha(1.0),
- mBackground(),
- mSelectedBackground(),
- mSkin(nullptr),
- mSelectedSkin(nullptr),
- mOffsetX(-mapTileSize / 2),
- mOffsetY(-mapTileSize),
- mDrawBackground(false),
- mSelected(false)
-{
- init(skin, selectedSkin);
-}
-
-PlayerBox::PlayerBox(Widget2 *const widget,
- const std::string &skin,
- const std::string &selectedSkin) :
- Widget(widget),
- MouseListener(),
- mBeing(nullptr),
- mAlpha(1.0),
- mBackground(),
- mSelectedBackground(),
- mSkin(nullptr),
- mSelectedSkin(nullptr),
- mOffsetX(-mapTileSize / 2),
- mOffsetY(-mapTileSize),
- mDrawBackground(false),
- mSelected(false)
-{
- init(skin, selectedSkin);
-}
-
-PlayerBox::~PlayerBox()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- Theme::unloadRect(mBackground);
- Theme::unloadRect(mSelectedBackground);
- mBeing = nullptr;
-}
-
-void PlayerBox::init(std::string name, std::string selectedName)
-{
- mAllowLogic = false;
- setFrameSize(2);
- addMouseListener(this);
-
- if (theme != nullptr)
- {
- if (name.empty())
- name = "playerbox.xml";
- mSkin = theme->loadSkinRect(mBackground,
- name, "playerbox_background.xml");
- if (mSkin != nullptr)
- {
- mDrawBackground = (mSkin->getOption("drawbackground") != 0);
- mOffsetX = mSkin->getOption("offsetX", -mapTileSize / 2);
- mOffsetY = mSkin->getOption("offsetY", -mapTileSize);
- mFrameSize = mSkin->getOption("frameSize", 2);
- }
- if (selectedName.empty())
- selectedName = "playerboxselected.xml";
- mSelectedSkin = theme->loadSkinRect(mSelectedBackground,
- selectedName, "playerbox_background.xml");
- }
- else
- {
- for (int f = 0; f < 9; f ++)
- mBackground.grid[f] = nullptr;
- for (int f = 0; f < 9; f ++)
- mSelectedBackground.grid[f] = nullptr;
- }
-}
-
-void PlayerBox::draw(Graphics *const graphics)
-{
- BLOCK_START("PlayerBox::draw")
- if (mBeing != nullptr)
- {
- const int bs = mFrameSize;
- const int x = mDimension.width / 2 + bs + mOffsetX;
- const int y = mDimension.height - bs + mOffsetY;
- mBeing->drawBasic(graphics, x, y);
- }
-
- if (settings.guiAlpha != mAlpha)
- {
- const float alpha = settings.guiAlpha;
- for (int a = 0; a < 9; a++)
- {
- if (mBackground.grid[a] != nullptr)
- mBackground.grid[a]->setAlpha(alpha);
- }
- }
- BLOCK_END("PlayerBox::draw")
-}
-
-void PlayerBox::safeDraw(Graphics *const graphics)
-{
- PlayerBox::draw(graphics);
-}
-
-void PlayerBox::drawFrame(Graphics *const graphics)
-{
- BLOCK_START("PlayerBox::drawFrame")
- if (mDrawBackground)
- {
- const int bs = mFrameSize * 2;
- const int w = mDimension.width + bs;
- const int h = mDimension.height + bs;
-
- if (!mSelected)
- graphics->drawImageRect(0, 0, w, h, mBackground);
- else
- graphics->drawImageRect(0, 0, w, h, mSelectedBackground);
- }
- BLOCK_END("PlayerBox::drawFrame")
-}
-
-void PlayerBox::safeDrawFrame(Graphics *const graphics)
-{
- BLOCK_START("PlayerBox::drawFrame")
- if (mDrawBackground)
- {
- const int bs = mFrameSize * 2;
- const int w = mDimension.width + bs;
- const int h = mDimension.height + bs;
-
- if (!mSelected)
- graphics->drawImageRect(0, 0, w, h, mBackground);
- else
- graphics->drawImageRect(0, 0, w, h, mSelectedBackground);
- }
- BLOCK_END("PlayerBox::drawFrame")
-}
-
-void PlayerBox::mouseReleased(MouseEvent& event)
-{
- if (event.getButton() == MouseButton::LEFT)
- {
- if (!mActionEventId.empty())
- distributeActionEvent();
- event.consume();
- }
-}
diff --git a/src/gui/widgets/playerbox.h b/src/gui/widgets/playerbox.h
deleted file mode 100644
index b223f1dcb..000000000
--- a/src/gui/widgets/playerbox.h
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_PLAYERBOX_H
-#define GUI_WIDGETS_PLAYERBOX_H
-
-#include "gui/widgets/widget.h"
-
-#include "listeners/mouselistener.h"
-
-#include "resources/imagerect.h"
-
-#include "localconsts.h"
-
-class Being;
-class Skin;
-
-/**
- * A box showing a player character.
- *
- * \ingroup GUI
- */
-class PlayerBox final : public Widget,
- public MouseListener
-{
- public:
- /**
- * Constructor. Takes the initial player character that this box should
- * display, which defaults to <code>NULL</code>.
- */
- PlayerBox(Widget2 *const widget,
- Being *const being,
- const std::string &skin = "",
- const std::string &selectedSkin = "");
-
- explicit PlayerBox(Widget2 *const widget,
- const std::string &skin = "",
- const std::string &selectedSkin = "");
-
- A_DELETE_COPY(PlayerBox)
-
- /**
- * Destructor.
- */
- ~PlayerBox();
-
- void init(std::string name, std::string selectedName);
-
- /**
- * Sets a new player character to be displayed by this box. Setting the
- * player to <code>NULL</code> causes the box not to draw any
- * character.
- */
- void setPlayer(Being *being)
- { mBeing = being; }
-
- /**
- * Draws the scroll area.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Draws the background and border of the scroll area.
- */
- void drawFrame(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDrawFrame(Graphics *const graphics) override final
- A_NONNULL(2);
-
- Being *getBeing() A_WARN_UNUSED
- { return mBeing; }
-
- void setSelected(bool b)
- { mSelected = b; }
-
- void mouseReleased(MouseEvent& event) override final;
-
- private:
- Being *mBeing;
- float mAlpha;
- ImageRect mBackground;
- ImageRect mSelectedBackground;
- Skin *mSkin;
- Skin *mSelectedSkin;
- int mOffsetX;
- int mOffsetY;
- bool mDrawBackground;
- bool mSelected;
-};
-
-#endif // GUI_WIDGETS_PLAYERBOX_H
diff --git a/src/gui/widgets/popup.cpp b/src/gui/widgets/popup.cpp
deleted file mode 100644
index 0f5c5a31a..000000000
--- a/src/gui/widgets/popup.cpp
+++ /dev/null
@@ -1,273 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- * Copyright (C) 2009 Aethyra Development Team
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/popup.h"
-
-#include "gui/popupmanager.h"
-#include "gui/skin.h"
-
-#include "gui/widgets/windowcontainer.h"
-
-#include "utils/delete2.h"
-
-#include "render/graphics.h"
-
-#include "render/vertexes/imagecollection.h"
-
-#include "debug.h"
-
-Popup::Popup(const std::string &name,
- std::string skin) :
- Container(nullptr),
- MouseListener(),
- WidgetListener(),
- mPadding(3),
- mSkin(nullptr),
- mPopupName(name),
- mVertexes(new ImageCollection),
- mMinWidth(100),
- mMinHeight(40),
- mMaxWidth(mainGraphics->mWidth),
- mMaxHeight(mainGraphics->mHeight),
- mInit(false)
-{
- logger->log("Popup::Popup(\"%s\")", name.c_str());
-
- mWindow = this;
-
- addWidgetListener(this);
-
- if (skin.empty())
- skin = "popup.xml";
-
- if (theme != nullptr)
- {
- mSkin = theme->load(skin, "popup.xml");
- if (mSkin != nullptr)
- {
- setPadding(mSkin->getPadding());
- setPalette(mSkin->getOption("palette"));
- }
- }
-
- if (windowContainer != nullptr)
- windowContainer->add(this);
-
- // Popups are invisible by default
- setVisible(Visible_false);
-}
-
-Popup::~Popup()
-{
- logger->log("Popup::~Popup(\"%s\")", mPopupName.c_str());
-
- delete2(mVertexes);
-
- if (mSkin != nullptr)
- {
- if (theme != nullptr)
- theme->unload(mSkin);
- mSkin = nullptr;
- }
-
- if (!mInit)
- {
- logger->log("error: Popup created without calling postInit(): "
- + mPopupName);
- }
-}
-
-void Popup::setWindowContainer(WindowContainer *const wc)
-{
- windowContainer = wc;
-}
-
-void Popup::draw(Graphics *const graphics)
-{
- BLOCK_START("Popup::draw")
-
- if (mSkin != nullptr)
- {
- if (mRedraw)
- {
- mRedraw = false;
- mVertexes->clear();
- graphics->calcWindow(mVertexes,
- 0, 0,
- mDimension.width, mDimension.height,
- mSkin->getBorder());
- }
- // need cache or remove calc call.
- graphics->finalize(mVertexes);
- graphics->drawTileCollection(mVertexes);
- }
-
- drawChildren(graphics);
- BLOCK_END("Popup::draw")
-}
-
-void Popup::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("Popup::safeDraw")
-
- if (mSkin != nullptr)
- {
- graphics->drawImageRect(0, 0,
- mDimension.width, mDimension.height,
- mSkin->getBorder());
- }
-
- safeDrawChildren(graphics);
- BLOCK_END("Popup::safeDraw")
-}
-
-Rect Popup::getChildrenArea()
-{
- const int pad2 = mPadding * 2;
- return Rect(mPadding, mPadding,
- mDimension.width - pad2, mDimension.height - pad2);
-}
-
-void Popup::setContentSize(int width, int height)
-{
- const int pad2 = mPadding * 2;
- width += pad2;
- height += pad2;
-
- if (mMinWidth > width)
- width = mMinWidth;
- else if (mMaxWidth < width)
- width = mMaxWidth;
- if (mMinHeight > height)
- height = mMinHeight;
- else if (mMaxHeight < height)
- height = mMaxHeight;
-
- setSize(width, height);
- mRedraw = true;
-}
-
-void Popup::setLocationRelativeTo(const Widget *const widget)
-{
- if (widget == nullptr)
- return;
-
- int wx, wy;
- int x, y;
-
- widget->getAbsolutePosition(wx, wy);
- getAbsolutePosition(x, y);
-
- setPosition(mDimension.x + (wx + (widget->getWidth()
- - mDimension.width) / 2 - x),
- mDimension.y + (wy + (widget->getHeight()
- - mDimension.height) / 2 - y));
- mRedraw = true;
-}
-
-void Popup::setMinWidth(const int width)
-{
- if (mSkin != nullptr)
- {
- mMinWidth = width > mSkin->getMinWidth()
- ? width : mSkin->getMinWidth();
- }
- else
- {
- mMinWidth = width;
- }
-}
-
-void Popup::setMinHeight(const int height)
-{
- if (mSkin != nullptr)
- {
- mMinHeight = height > mSkin->getMinHeight() ?
- height : mSkin->getMinHeight();
- }
- else
- {
- mMinHeight = height;
- }
-}
-
-void Popup::setMaxWidth(const int width)
-{
- mMaxWidth = width;
-}
-
-void Popup::setMaxHeight(const int height)
-{
- mMaxHeight = height;
-}
-
-void Popup::scheduleDelete()
-{
- windowContainer->scheduleDelete(this);
-}
-
-void Popup::position(const int x, const int y)
-{
- const int distance = 20;
-
- const int width = mDimension.width;
- const int height = mDimension.height;
- int posX = std::max(0, x - width / 2);
- int posY = y + distance;
-
- if (posX + width > mainGraphics->mWidth)
- posX = mainGraphics->mWidth - width;
- if (posY + height > mainGraphics->mHeight)
- posY = y - height - distance;
-
- setPosition(posX, posY);
- setVisible(Visible_true);
- requestMoveToTop();
- mRedraw = true;
-}
-
-void Popup::mouseMoved(MouseEvent &event A_UNUSED)
-{
- if (popupManager != nullptr)
- {
- PopupManager::hideBeingPopup();
- PopupManager::hideTextPopup();
- }
- mRedraw = true;
-}
-
-void Popup::hide()
-{
- setVisible(Visible_false);
- mRedraw = true;
-}
-
-void Popup::widgetResized(const Event &event A_UNUSED)
-{
- mRedraw = true;
-}
-
-void Popup::widgetMoved(const Event &event A_UNUSED)
-{
- mRedraw = true;
-}
diff --git a/src/gui/widgets/popup.h b/src/gui/widgets/popup.h
deleted file mode 100644
index 92fbaf78a..000000000
--- a/src/gui/widgets/popup.h
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- * Copyright (C) 2009 Aethyra Development Team
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_POPUP_H
-#define GUI_WIDGETS_POPUP_H
-
-#include "gui/widgets/container.h"
-
-#include "listeners/mouselistener.h"
-#include "listeners/widgetlistener.h"
-
-class ImageCollection;
-class Skin;
-class WindowContainer;
-
-/**
- * A light version of the Window class. Particularly suited for popup type
- * functionality that doesn't need to be resized or moved around by the mouse
- * once created, but only needs to display some simple content, like a static
- * message.
- *
- * Popups, in general, shouldn't also need to update their content once
- * created, although this is not an explicit requirement to use the popup
- * class.
- *
- * \ingroup GUI
- */
-class Popup notfinal : public Container,
- public MouseListener,
- public WidgetListener
-{
- public:
- /**
- * Constructor. Initializes the title to the given text and hooks
- * itself into the popup container.
- *
- * @param name A human readable name for the popup. Only useful for
- * debugging purposes.
- * @param skin The location where the Popup's skin XML can be found.
- */
- explicit Popup(const std::string &name = "",
- std::string skin = "");
-
- A_DELETE_COPY(Popup)
-
- /**
- * Destructor. Deletes all the added widgets.
- */
- virtual ~Popup();
-
- /**
- * Sets the window container to be used by new popups.
- */
- static void setWindowContainer(WindowContainer *const windowContainer);
-
- /**
- * Draws the popup.
- */
- void draw(Graphics *const graphics) override A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override A_NONNULL(2);
-
- /**
- * Sets the size of this popup.
- */
- void setContentSize(int width, int height);
-
- /**
- * Sets the location relative to the given widget.
- */
- void setLocationRelativeTo(const Widget *const widget);
-
- void mouseMoved(MouseEvent &event) override;
-
- /**
- * Sets the minimum width of the popup.
- */
- void setMinWidth(const int width);
-
- int getMinWidth() const noexcept2 A_WARN_UNUSED
- { return mMinWidth; }
-
- /**
- * Sets the minimum height of the popup.
- */
- void setMinHeight(const int height);
-
- int getMinHeight() const noexcept2 A_WARN_UNUSED
- { return mMinHeight; }
-
- /**
- * Sets the maximum width of the popup.
- */
- void setMaxWidth(const int width);
-
- int getMaxWidth() const noexcept2 A_WARN_UNUSED
- { return mMaxWidth; }
-
- /**
- * Sets the minimum height of the popup.
- */
- void setMaxHeight(const int height);
-
- int getMaxHeight() const noexcept2 A_WARN_UNUSED
- { return mMaxHeight; }
-
- /**
- * Gets the padding of the popup. The padding is the distance between
- * the popup border and the content.
- *
- * @return The padding of the popup.
- * @see setPadding
- */
- int getPadding() const noexcept2 A_WARN_UNUSED
- { return mPadding; }
-
- void setPadding(int padding) noexcept2
- { mPadding = padding; }
-
- /**
- * Sets the name of the popup. This is only useful for debug purposes.
- */
- void setPopupName(const std::string &name) noexcept2
- { mPopupName = name; }
-
- const std::string &getPopupName() const noexcept2
- { return mPopupName; }
-
- /**
- * Schedule this popup for deletion. It will be deleted at the start
- * of the next logic update.
- */
- void scheduleDelete();
-
- // Inherited from BasicContainer
-
- Rect getChildrenArea() override;
-
- /**
- * Sets the location to display the popup. Tries to horizontally center
- * the popup and provide a vertical buffer between the given point and
- * the popup. Prevents the popup from extending off-screen, if
- * possible.
- */
- void position(const int x, const int y);
-
- void hide();
-
- void widgetResized(const Event &event) override;
-
- void widgetMoved(const Event &event) override final;
-
- bool isPopupVisible() const noexcept2
- { return mVisible == Visible_true; }
-
- void postInit() override
- { mInit = true; }
-
- protected:
- int mPadding; /**< Holds the padding of the popup. */
- Skin *mSkin; /**< Skin in use by this popup */
-
- private:
- std::string mPopupName; /**< Name of the popup */
- ImageCollection *mVertexes A_NONNULLPOINTER;
- int mMinWidth; /**< Minimum popup width */
- int mMinHeight; /**< Minimum popup height */
- int mMaxWidth; /**< Maximum popup width */
- int mMaxHeight; /**< Maximum popup height */
- bool mInit;
-};
-
-#endif // GUI_WIDGETS_POPUP_H
diff --git a/src/gui/widgets/popuplist.cpp b/src/gui/widgets/popuplist.cpp
deleted file mode 100644
index 0260945ce..000000000
--- a/src/gui/widgets/popuplist.cpp
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/popuplist.h"
-
-#include "gui/gui.h"
-
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/dropdown.h"
-#include "gui/widgets/extendedlistbox.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "render/graphics.h"
-
-#include "debug.h"
-
-PopupList::PopupList(DropDown *const widget,
- ListModel *const listModel,
- const bool extended,
- const Modal modal) :
- Popup("PopupList", "popuplist.xml"),
- FocusListener(),
- mListModel(listModel),
- mListBox(extended ? CREATEWIDGETR(ExtendedListBox,
- widget, listModel, "extendedlistbox.xml", 0) :
- CREATEWIDGETR(ListBox,
- widget, listModel, "popuplistbox.xml")),
- mScrollArea(new ScrollArea(this, mListBox, Opaque_false)),
- mDropDown(widget),
- mPressedIndex(-2),
- mModal(modal)
-{
- mListBox->setMouseConsume(false);
- mScrollArea->setMouseConsume(false);
- mAllowLogic = false;
- setFocusable(true);
-
- mListBox->setDistributeMousePressed(true);
- mScrollArea->setPosition(mPadding, mPadding);
-}
-
-void PopupList::postInit()
-{
- Popup::postInit();
- add(mScrollArea);
-
- if (gui != nullptr)
- gui->addGlobalFocusListener(this);
-
- addKeyListener(mDropDown);
- addMouseListener(this);
- adjustSize();
-}
-
-PopupList::~PopupList()
-{
- if (mParent != nullptr)
- mParent->removeFocusListener(this);
- if (gui != nullptr)
- gui->removeGlobalFocusListener(this);
- removeKeyListener(mDropDown);
-}
-
-void PopupList::show(int x, int y)
-{
- int len = mListBox->getHeight() + 8;
- if (len > 250)
- len = 250;
- setContentSize(mListBox->getWidth() + 8, len);
- const int width = mDimension.width;
- const int height = mDimension.height;
- if (mainGraphics->mWidth < (x + width + 5))
- x = mainGraphics->mWidth - width;
- if (mainGraphics->mHeight < (y + height + 5))
- y = mainGraphics->mHeight - height;
- setPosition(x, y);
- setVisible(Visible_true);
- requestMoveToTop();
- if (mModal == Modal_true)
- requestModalFocus();
-}
-
-void PopupList::widgetResized(const Event &event)
-{
- Popup::widgetResized(event);
- adjustSize();
-}
-
-void PopupList::setSelected(const int selected)
-{
- if (mListBox == nullptr)
- return;
-
- mListBox->setSelected(selected);
-}
-
-int PopupList::getSelected() const
-{
- if (mListBox == nullptr)
- return -1;
-
- return mListBox->getSelected();
-}
-
-void PopupList::setListModel(ListModel *const model)
-{
- if (mListBox != nullptr)
- mListBox->setListModel(model);
- mListModel = model;
-}
-
-void PopupList::adjustSize()
-{
- const int pad2 = 2 * mPadding;
- const int width = mDimension.width - pad2;
- mScrollArea->setWidth(width);
- mScrollArea->setHeight(mDimension.height - pad2);
- mListBox->adjustSize();
- mListBox->setWidth(width);
-}
-
-void PopupList::mousePressed(MouseEvent& event)
-{
- mPressedIndex = mListBox->getSelectionByMouse(
- event.getY() + mPadding);
- event.consume();
-}
-
-void PopupList::mouseReleased(MouseEvent& event)
-{
- if (mPressedIndex != mListBox->getSelectionByMouse(
- event.getY() + mPadding))
- {
- mPressedIndex = -2;
- return;
- }
-
- mPressedIndex = -2;
- if (event.getSource() == mScrollArea)
- return;
- if (mDropDown != nullptr)
- mDropDown->updateSelection();
- setVisible(Visible_false);
- if (mModal == Modal_true)
- releaseModalFocus();
-}
-
-void PopupList::focusGained(const Event& event)
-{
- const Widget *const source = event.getSource();
- if (mVisible == Visible_false ||
- source == this ||
- source == mListBox ||
- source == mScrollArea ||
- source == mDropDown)
- {
- return;
- }
-
- if (mDropDown != nullptr)
- mDropDown->updateSelection();
- setVisible(Visible_false);
- if (mModal == Modal_true)
- releaseModalFocus();
-}
-
-void PopupList::focusLost(const Event& event A_UNUSED)
-{
- if (mDropDown != nullptr)
- mDropDown->updateSelection();
-}
diff --git a/src/gui/widgets/popuplist.h b/src/gui/widgets/popuplist.h
deleted file mode 100644
index 02c38b4ed..000000000
--- a/src/gui/widgets/popuplist.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_POPUPLIST_H
-#define GUI_WIDGETS_POPUPLIST_H
-
-#include "enums/simpletypes/modal.h"
-
-#include "gui/widgets/popup.h"
-
-#include "listeners/focuslistener.h"
-
-#include "localconsts.h"
-
-class DropDown;
-class ListBox;
-class ListModel;
-class ScrollArea;
-
-class PopupList final : public Popup,
- public FocusListener
-{
- public:
- PopupList(DropDown *const widget,
- ListModel *const listModel,
- const bool extended,
- const Modal modal = Modal_false);
-
- ~PopupList();
-
- A_DELETE_COPY(PopupList)
-
- void postInit() override final;
-
- void show(int x, int y);
-
- void widgetResized(const Event &event) override final;
-
- void setSelected(const int selected);
-
- int getSelected() const;
-
- void setListModel(ListModel *const model);
-
- ListModel *getListModel() const
- { return mListModel; }
-
- void adjustSize();
-
- void focusGained(const Event& event A_UNUSED) override final;
-
- void focusLost(const Event& event A_UNUSED) override final;
-
- void mousePressed(MouseEvent& event) override final;
-
- void mouseReleased(MouseEvent& event) override final;
-
- private:
- ListModel *mListModel;
- ListBox *mListBox A_NONNULLPOINTER;
- ScrollArea *mScrollArea A_NONNULLPOINTER;
- DropDown *mDropDown;
- int mPressedIndex;
- Modal mModal;
-};
-
-#endif // GUI_WIDGETS_POPUPLIST_H
diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp
deleted file mode 100644
index 7299140c6..000000000
--- a/src/gui/widgets/progressbar.cpp
+++ /dev/null
@@ -1,376 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/progressbar.h"
-
-#include "settings.h"
-
-#include "gui/gui.h"
-#include "gui/skin.h"
-
-#include "gui/fonts/font.h"
-
-#include "utils/delete2.h"
-
-#include "render/graphics.h"
-
-#include "render/vertexes/imagecollection.h"
-
-#include "debug.h"
-
-int ProgressBar::mInstances = 0;
-float ProgressBar::mAlpha = 1.0;
-
-ProgressBar::ProgressBar(const Widget2 *const widget,
- float progress,
- const int width,
- const int height,
- const ProgressColorIdT backColor,
- const std::string &skin,
- const std::string &skinFill) :
- Widget(widget),
- WidgetListener(),
- mFillRect(),
- mTextChunk(),
- mSkin(nullptr),
- mProgress(progress),
- mProgressToGo(progress),
- mBackgroundColorToGo(),
- mText(),
- mVertexes(new ImageCollection),
- mProgressPalette(backColor),
- mPadding(2),
- mFillPadding(3),
- mFillImage(false),
- mSmoothProgress(true),
- mSmoothColorChange(true),
- mTextChanged(true)
-{
- mBackgroundColor = Theme::getProgressColor(
- backColor >= ProgressColorId::PROG_HP
- ? backColor : ProgressColorId::PROG_HP,
- mProgress);
- mBackgroundColorToGo = mBackgroundColor;
- mForegroundColor2 = getThemeColor(ThemeColorId::PROGRESS_BAR_OUTLINE);
-
- // The progress value is directly set at load time:
- if (mProgress > 1.0F || mProgress < 0.0F)
- mProgress = 1.0F;
-
- mForegroundColor = getThemeColor(ThemeColorId::PROGRESS_BAR);
- addWidgetListener(this);
- setSize(width, height);
-
- if (theme != nullptr)
- {
- mSkin = theme->load(skin, "progressbar.xml");
- if (mSkin != nullptr)
- {
- setPadding(mSkin->getPadding());
- mFillPadding = mSkin->getOption("fillPadding");
- mFillImage = mSkin->getOption("fillImage") != 0;
- if (mFillImage)
- theme->loadRect(mFillRect, skinFill, "progressbar_fill.xml");
- }
- setHeight(2 * mPadding + getFont()->getHeight() + 2);
- }
-
- mInstances++;
-}
-
-ProgressBar::~ProgressBar()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- mInstances--;
- if (mSkin != nullptr)
- {
- if (theme != nullptr)
- theme->unload(mSkin);
- mSkin = nullptr;
- }
- Theme::unloadRect(mFillRect);
- delete2(mVertexes);
- mTextChunk.deleteImage();
-}
-
-void ProgressBar::logic()
-{
- BLOCK_START("ProgressBar::logic")
- if (mSmoothColorChange && mBackgroundColorToGo != mBackgroundColor)
- {
- // Smoothly changing the color for a nicer effect.
- if (mBackgroundColorToGo.r > mBackgroundColor.r)
- mBackgroundColor.r++;
- if (mBackgroundColorToGo.g > mBackgroundColor.g)
- mBackgroundColor.g++;
- if (mBackgroundColorToGo.b > mBackgroundColor.b)
- mBackgroundColor.b++;
- if (mBackgroundColorToGo.r < mBackgroundColor.r)
- mBackgroundColor.r--;
- if (mBackgroundColorToGo.g < mBackgroundColor.g)
- mBackgroundColor.g--;
- if (mBackgroundColorToGo.b < mBackgroundColor.b)
- mBackgroundColor.b--;
- mRedraw = true;
- }
-
- if (mSmoothProgress && mProgressToGo != mProgress)
- {
- // Smoothly showing the progressbar changes.
- if (mProgressToGo > mProgress)
- mProgress = std::min(1.0F, mProgress + 0.005F);
- if (mProgressToGo < mProgress)
- mProgress = std::max(0.0F, mProgress - 0.005F);
- mRedraw = true;
- }
- BLOCK_END("ProgressBar::logic")
-}
-
-void ProgressBar::updateAlpha()
-{
- const float alpha = std::max(settings.guiAlpha,
- theme->getMinimumOpacity());
- mAlpha = alpha;
-}
-
-void ProgressBar::draw(Graphics *const graphics)
-{
- BLOCK_START("ProgressBar::draw")
- if (mSkin == nullptr)
- {
- BLOCK_END("ProgressBar::draw")
- return;
- }
-
- updateAlpha();
- mBackgroundColor.a = CAST_U32(mAlpha * 255);
-
- if (mRedraw || graphics->getRedraw())
- {
- mRedraw = false;
- mVertexes->clear();
- graphics->calcWindow(mVertexes, 0, 0,
- mDimension.width, mDimension.height, mSkin->getBorder());
- if (mFillImage)
- {
- const unsigned int pad = 2 * mFillPadding;
- const int maxWidth = mDimension.width - pad;
- int width = CAST_S32(mProgress
- * static_cast<float>(maxWidth));
- if (width > 0)
- {
- if (width > maxWidth)
- width = maxWidth;
- graphics->calcWindow(mVertexes, mFillPadding, mFillPadding,
- width, mDimension.height - pad, mFillRect);
- }
- }
- graphics->finalize(mVertexes);
- }
-
- graphics->drawTileCollection(mVertexes);
-
- // The bar
- if (!mFillImage && mProgress > 0)
- {
- graphics->setColor(mBackgroundColor);
- const unsigned int pad = 2 * mFillPadding;
- const int maxWidth = mDimension.width - pad;
- int width = CAST_S32(mProgress * static_cast<float>(maxWidth));
- if (width > 0)
- {
- if (width > maxWidth)
- width = maxWidth;
- graphics->fillRectangle(Rect(mFillPadding, mFillPadding,
- width, mDimension.height - pad));
- }
- }
-
- // The label
- if (!mText.empty())
- {
- Font *const font = gui->getFont();
- if (mTextChanged)
- {
- mTextChunk.textFont = font;
- mTextChunk.deleteImage();
- mTextChunk.text = mText;
- mTextChunk.color = mForegroundColor;
- mTextChunk.color2 = mForegroundColor2;
- font->generate(mTextChunk);
- mTextChanged = false;
- }
-
- const Image *const image = mTextChunk.img;
- if (image != nullptr)
- {
- const int textX = (mDimension.width - font->getWidth(mText)) / 2;
- const int textY = (mDimension.height - font->getHeight()) / 2;
- graphics->drawImage(image, textX, textY);
- }
- }
- BLOCK_END("ProgressBar::draw")
-}
-
-void ProgressBar::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("ProgressBar::safeDraw")
- if (mSkin == nullptr)
- {
- BLOCK_END("ProgressBar::safeDraw")
- return;
- }
-
- updateAlpha();
- mBackgroundColor.a = CAST_U32(mAlpha * 255);
-
- graphics->drawImageRect(0, 0, mDimension.width, mDimension.height,
- mSkin->getBorder());
- if (mFillImage)
- {
- const unsigned int pad = 2 * mFillPadding;
- const int maxWidth = mDimension.width - pad;
- int width = CAST_S32(mProgress
- * static_cast<float>(maxWidth));
- if (width > 0)
- {
- if (width > maxWidth)
- width = maxWidth;
- graphics->drawImageRect(mFillPadding, mFillPadding,
- width, mDimension.height - pad, mFillRect);
- }
- }
-
- // The bar
- if (!mFillImage && mProgress > 0)
- {
- graphics->setColor(mBackgroundColor);
- const unsigned int pad = 2 * mFillPadding;
- const int maxWidth = mDimension.width - pad;
- int width = CAST_S32(mProgress * static_cast<float>(maxWidth));
- if (width > 0)
- {
- if (width > maxWidth)
- width = maxWidth;
- graphics->fillRectangle(Rect(mFillPadding, mFillPadding,
- width, mDimension.height - pad));
- }
- }
-
- // The label
- if (!mText.empty())
- {
- Font *const font = gui->getFont();
- if (mTextChanged)
- {
- mTextChunk.textFont = font;
- mTextChunk.deleteImage();
- mTextChunk.text = mText;
- mTextChunk.color = mForegroundColor;
- mTextChunk.color2 = mForegroundColor2;
- font->generate(mTextChunk);
- mTextChanged = false;
- }
-
- const Image *const image = mTextChunk.img;
- if (image != nullptr)
- {
- const int textX = (mDimension.width - font->getWidth(mText)) / 2;
- const int textY = (mDimension.height - font->getHeight()) / 2;
- graphics->drawImage(image, textX, textY);
- }
- }
- BLOCK_END("ProgressBar::safeDraw")
-}
-
-void ProgressBar::setProgress(const float progress)
-{
- const float p = std::min(1.0F, std::max(0.0F, progress));
- mProgressToGo = p;
- mRedraw = true;
-
- if (!mSmoothProgress)
- mProgress = p;
-
- if (mProgressPalette >= ProgressColorId::PROG_HP)
- {
- mBackgroundColorToGo = Theme::getProgressColor(
- mProgressPalette, progress);
- }
-}
-
-void ProgressBar::setProgressPalette(const ProgressColorIdT progressPalette)
-{
- const ProgressColorIdT oldPalette = mProgressPalette;
- mProgressPalette = progressPalette;
- mRedraw = true;
-
- if (mProgressPalette != oldPalette &&
- mProgressPalette >= ProgressColorId::PROG_HP)
- {
- mBackgroundColorToGo = Theme::getProgressColor(
- mProgressPalette, mProgressToGo);
- }
-}
-
-void ProgressBar::setBackgroundColor(const Color &color)
-{
- mRedraw = true;
- mBackgroundColorToGo = color;
-
- if (!mSmoothColorChange)
- mBackgroundColor = color;
-}
-
-void ProgressBar::setColor(const Color &color1, const Color &color2)
-{
- mForegroundColor = color1;
- mForegroundColor2 = color2;
- mTextChanged = true;
-}
-
-void ProgressBar::widgetResized(const Event &event A_UNUSED)
-{
- mRedraw = true;
-}
-
-void ProgressBar::widgetMoved(const Event &event A_UNUSED)
-{
- mRedraw = true;
-}
-
-void ProgressBar::setText(const std::string &str)
-{
- if (mText != str)
- {
- mText = str;
- mTextChanged = true;
- }
-}
-
-void ProgressBar::widgetHidden(const Event &event A_UNUSED)
-{
- mTextChanged = true;
- mTextChunk.deleteImage();
-}
diff --git a/src/gui/widgets/progressbar.h b/src/gui/widgets/progressbar.h
deleted file mode 100644
index 466f067b4..000000000
--- a/src/gui/widgets/progressbar.h
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_PROGRESSBAR_H
-#define GUI_WIDGETS_PROGRESSBAR_H
-
-#include "gui/fonts/textchunk.h"
-
-#include "gui/widgets/widget.h"
-
-#include "listeners/widgetlistener.h"
-
-#include "resources/imagerect.h"
-
-#include "localconsts.h"
-
-class ImageCollection;
-class Skin;
-
-/**
- * A progress bar.
- *
- * \ingroup GUI
- */
-class ProgressBar final : public Widget,
- public WidgetListener
-{
- public:
- /**
- * Constructor, initializes the progress with the given value.
- */
- ProgressBar(const Widget2 *const widget,
- float progress,
- const int width,
- const int height,
- const ProgressColorIdT backColor,
- const std::string &skin,
- const std::string &skinFill);
-
- A_DELETE_COPY(ProgressBar)
-
- ~ProgressBar();
-
- /**
- * Performs progress bar logic (fading colors)
- */
- void logic() override final;
-
- /**
- * Update the alpha value to the graphic components.
- */
- void updateAlpha();
-
- /**
- * Draws the progress bar.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Sets the current progress.
- */
- void setProgress(const float progress);
-
- /**
- * Returns the current progress.
- */
- float getProgress() const noexcept2 A_WARN_UNUSED
- { return mProgress; }
-
- /**
- * Change the ProgressPalette for this ProgressBar to follow or -1 to
- * disable this and manage color manually.
- */
- void setProgressPalette(const ProgressColorIdT progressPalette);
-
- /**
- * Change the color of the progress bar.
- */
- void setBackgroundColor(const Color &color);
-
- void setColor(const Color &color1, const Color &color2);
-
- /**
- * Returns the color of the progress bar.
- */
- const Color &getBackgroundColor() const noexcept2 A_WARN_UNUSED
- { return mBackgroundColor; }
-
- /**
- * Sets the text shown on the progress bar.
- */
- void setText(const std::string &str);
-
- /**
- * Returns the text shown on the progress bar.
- */
- const std::string &text() const noexcept2 A_WARN_UNUSED
- { return mText; }
-
- /**
- * Set whether the progress is moved smoothly.
- */
- void setSmoothProgress(bool smoothProgress) noexcept2
- { mSmoothProgress = smoothProgress; }
-
- /**
- * Set whether the color changing is made smoothly.
- */
- void setSmoothColorChange(bool smoothColorChange) noexcept2
- { mSmoothColorChange = smoothColorChange; }
-
- void widgetResized(const Event &event) override final;
-
- void widgetMoved(const Event &event) override final;
-
- void widgetHidden(const Event &event) override final;
-
- void setPadding(unsigned int padding) noexcept2
- { mPadding = padding; }
-
- private:
- ImageRect mFillRect;
- TextChunk mTextChunk;
- Skin *mSkin;
- float mProgress;
- float mProgressToGo;
-
- Color mBackgroundColorToGo;
-
- std::string mText;
- ImageCollection *mVertexes A_NONNULLPOINTER;
- ProgressColorIdT mProgressPalette;
- unsigned int mPadding;
- unsigned int mFillPadding;
-
- static int mInstances;
- static float mAlpha;
-
- bool mFillImage;
- bool mSmoothProgress;
- bool mSmoothColorChange;
- bool mTextChanged;
-};
-
-#endif // GUI_WIDGETS_PROGRESSBAR_H
diff --git a/src/gui/widgets/progressindicator.cpp b/src/gui/widgets/progressindicator.cpp
deleted file mode 100644
index abeee678c..000000000
--- a/src/gui/widgets/progressindicator.cpp
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/progressindicator.h"
-
-#include "gui/gui.h"
-
-#include "resources/imageset.h"
-
-#include "resources/animation/animation.h"
-#include "resources/animation/simpleanimation.h"
-
-#include "utils/delete2.h"
-
-#include "debug.h"
-
-ProgressIndicator::ProgressIndicator(const Widget2 *const widget) :
- Widget(widget),
- mIndicator(nullptr)
-{
- ImageSet *const images = Theme::getImageSetFromTheme(
- "progress-indicator.png", 32, 32);
-
- if (images != nullptr)
- {
- Animation *const anim = new Animation("progress indicator");
- for (ImageSet::size_type i = 0, fsz = images->size();
- i < fsz;
- ++i)
- {
- anim->addFrame(images->get(i), 100, 0, 0, 100);
- }
- mIndicator = new SimpleAnimation(anim);
- images->decRef();
- }
-
- setSize(32, 32);
-}
-
-ProgressIndicator::~ProgressIndicator()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- delete2(mIndicator);
-}
-
-void ProgressIndicator::logic()
-{
- BLOCK_START("ProgressIndicator::logic")
- if (mIndicator != nullptr)
- mIndicator->update(10);
- BLOCK_END("ProgressIndicator::logic")
-}
-
-void ProgressIndicator::draw(Graphics *const graphics)
-{
- BLOCK_START("ProgressIndicator::draw")
- if (mIndicator != nullptr)
- {
- // Draw the indicator centered on the widget
- const int x = (mDimension.width - 32) / 2;
- const int y = (mDimension.height - 32) / 2;
- mIndicator->draw(graphics, x, y);
- }
- BLOCK_END("ProgressIndicator::draw")
-}
-
-void ProgressIndicator::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("ProgressIndicator::draw")
- if (mIndicator != nullptr)
- {
- // Draw the indicator centered on the widget
- const int x = (mDimension.width - 32) / 2;
- const int y = (mDimension.height - 32) / 2;
- mIndicator->draw(graphics, x, y);
- }
- BLOCK_END("ProgressIndicator::draw")
-}
diff --git a/src/gui/widgets/progressindicator.h b/src/gui/widgets/progressindicator.h
deleted file mode 100644
index 6220a57c4..000000000
--- a/src/gui/widgets/progressindicator.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_PROGRESSINDICATOR_H
-#define GUI_WIDGETS_PROGRESSINDICATOR_H
-
-#include "gui/widgets/widget.h"
-
-#include "localconsts.h"
-
-class SimpleAnimation;
-
-/**
- * A widget that indicates progress. Suitable to use instead of a progress bar
- * in cases where it is unknown how long something is going to take.
- */
-class ProgressIndicator final : public Widget
-{
- public:
- explicit ProgressIndicator(const Widget2 *const widget);
-
- A_DELETE_COPY(ProgressIndicator)
-
- ~ProgressIndicator();
-
- void logic() override final;
-
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- private:
- SimpleAnimation *mIndicator;
-};
-
-#endif // GUI_WIDGETS_PROGRESSINDICATOR_H
diff --git a/src/gui/widgets/radiobutton.cpp b/src/gui/widgets/radiobutton.cpp
deleted file mode 100644
index 71b7171ae..000000000
--- a/src/gui/widgets/radiobutton.cpp
+++ /dev/null
@@ -1,373 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/radiobutton.h"
-
-#include "settings.h"
-
-#include "gui/gui.h"
-#include "gui/skin.h"
-
-#include "gui/fonts/font.h"
-
-#include "render/graphics.h"
-
-#include "resources/imagerect.h"
-
-#include "resources/image/image.h"
-
-#include "debug.h"
-
-int RadioButton::instances = 0;
-Skin *RadioButton::mSkin = nullptr;
-float RadioButton::mAlpha = 1.0;
-
-RadioButton::GroupMap RadioButton::mGroupMap;
-
-RadioButton::RadioButton(const Widget2 *const widget,
- const std::string &restrict caption,
- const std::string &restrict group,
- const bool marked) :
- Widget(widget),
- MouseListener(),
- KeyListener(),
- WidgetListener(),
- mSelected(false),
- mCaption(),
- mGroup(),
- mTextChunk(),
- mPadding(0),
- mImagePadding(0),
- mImageSize(9),
- mSpacing(2),
- mTextX(0 + 9 + 2),
- mHasMouse(false),
- mTextChanged(true)
-{
- mAllowLogic = false;
- setCaption(caption);
- setGroup(group);
- setSelected(marked);
-
- setFocusable(true);
- addMouseListener(this);
- addKeyListener(this);
-
- mForegroundColor = getThemeColor(ThemeColorId::RADIOBUTTON);
- mForegroundColor2 = getThemeColor(ThemeColorId::RADIOBUTTON_OUTLINE);
- if (instances == 0)
- {
- if (theme != nullptr)
- {
- mSkin = theme->load("radio.xml", "");
- updateAlpha();
- }
- }
-
- instances++;
-
- if (mSkin != nullptr)
- {
- mPadding = mSkin->getPadding();
- mImagePadding = mSkin->getOption("imagePadding");
- mImageSize = mSkin->getOption("imageSize");
- mSpacing = mSkin->getOption("spacing");
- mTextX = mPadding + mImageSize + mSpacing;
- }
-
- adjustSize();
-}
-
-RadioButton::~RadioButton()
-{
- if (mWindow != nullptr)
- mWindow->removeWidgetListener(this);
-
- setGroup(std::string());
-
- if (gui != nullptr)
- gui->removeDragged(this);
-
- instances--;
-
- if (instances == 0)
- {
- if (theme != nullptr)
- theme->unload(mSkin);
- }
-}
-
-void RadioButton::updateAlpha()
-{
- const float alpha = std::max(settings.guiAlpha,
- theme->getMinimumOpacity());
-
- if (mAlpha != alpha)
- {
- mAlpha = alpha;
- if (mSkin != nullptr)
- {
- const ImageRect &rect = mSkin->getBorder();
- for (int a = 0; a < 4; a ++)
- {
- Image *const image = rect.grid[a];
- if (image != nullptr)
- image->setAlpha(mAlpha);
- }
- }
- }
-}
-
-void RadioButton::drawBox(Graphics *const graphics)
-{
- if (mSkin == nullptr)
- return;
-
- const ImageRect &rect = mSkin->getBorder();
- int index = 0;
-
- if (mEnabled && mVisible == Visible_true)
- {
- if (mSelected)
- {
- if (mHasMouse)
- index = 1;
- else
- index = 0;
- }
- else
- {
- if (mHasMouse)
- index = 3;
- else
- index = 2;
- }
- }
- else
- {
- if (mSelected)
- index = 0;
- else
- index = 2;
- }
-
- const Image *const box = rect.grid[index];
-
- updateAlpha();
-
- if (box != nullptr)
- {
- graphics->drawImage(box,
- mImagePadding,
- (getHeight() - mImageSize) / 2);
- }
-}
-
-void RadioButton::draw(Graphics *const graphics)
-{
- BLOCK_START("RadioButton::draw")
- drawBox(graphics);
-
- Font *const font = getFont();
-
- if (mTextChanged)
- {
- mTextChunk.textFont = font;
- mTextChunk.deleteImage();
- mTextChunk.text = mCaption;
- mTextChunk.color = mForegroundColor;
- mTextChunk.color2 = mForegroundColor2;
- font->generate(mTextChunk);
- mTextChanged = false;
- }
-
- const Image *const image = mTextChunk.img;
- if (image != nullptr)
- graphics->drawImage(image, mTextX, mPadding);
-
- BLOCK_END("RadioButton::draw")
-}
-
-void RadioButton::safeDraw(Graphics *const graphics)
-{
- RadioButton::draw(graphics);
-}
-
-void RadioButton::mouseEntered(MouseEvent& event A_UNUSED)
-{
- mHasMouse = true;
-}
-
-void RadioButton::mouseExited(MouseEvent& event A_UNUSED)
-{
- mHasMouse = false;
-}
-
-void RadioButton::keyPressed(KeyEvent& event)
-{
- const InputActionT action = event.getActionId();
- if (action == InputAction::GUI_SELECT)
- {
- setSelected(true);
- distributeActionEvent();
- event.consume();
- }
-}
-
-void RadioButton::adjustSize()
-{
- Font *const font = getFont();
- setHeight(font->getHeight() + 2 * mPadding);
- setWidth(mImagePadding + mImageSize + mSpacing
- + font->getWidth(mCaption) + mPadding);
-}
-
-void RadioButton::setSelected(const bool selected)
-{
- if (selected && !mGroup.empty())
- {
- for (GroupIterator iter = mGroupMap.lower_bound(mGroup),
- iterEnd = mGroupMap.upper_bound(mGroup);
- iter != iterEnd;
- ++ iter)
- {
- if ((iter->second != nullptr) && iter->second->isSelected())
- iter->second->setSelected(false);
- }
- }
-
- mSelected = selected;
-}
-
-void RadioButton::mouseClicked(MouseEvent& event)
-{
- if (event.getButton() == MouseButton::LEFT)
- {
- setSelected(true);
- event.consume();
- distributeActionEvent();
- }
-}
-
-void RadioButton::mouseDragged(MouseEvent& event)
-{
- event.consume();
-}
-
-void RadioButton::setGroup(const std::string &group)
-{
- if (!mGroup.empty())
- {
- for (GroupIterator iter = mGroupMap.lower_bound(mGroup),
- iterEnd = mGroupMap.upper_bound(mGroup);
- iter != iterEnd;
- ++ iter)
- {
- if (iter->second == this)
- {
- mGroupMap.erase(iter);
- break;
- }
- }
- }
-
- if (!group.empty())
- mGroupMap.insert(std::pair<std::string, RadioButton *>(group, this));
-
- mGroup = group;
-}
-
-void RadioButton::setCaption(const std::string& caption)
-{
- if (caption != mCaption)
- mTextChanged = true;
- mCaption = caption;
-}
-
-void RadioButton::setParent(Widget *widget)
-{
- if (mWindow != nullptr)
- mWindow->addWidgetListener(this);
- Widget::setParent(widget);
-}
-
-void RadioButton::widgetHidden(const Event &event A_UNUSED)
-{
- mTextChanged = true;
- mTextChunk.deleteImage();
-}
-
-void RadioButton::setWindow(Widget *const widget)
-{
- if ((widget == nullptr) && (mWindow != nullptr))
- {
- mWindow->removeWidgetListener(this);
- mWindow = nullptr;
- }
- else
- {
- Widget2::setWindow(widget);
- }
-}
diff --git a/src/gui/widgets/radiobutton.h b/src/gui/widgets/radiobutton.h
deleted file mode 100644
index 37bafab29..000000000
--- a/src/gui/widgets/radiobutton.h
+++ /dev/null
@@ -1,247 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_RADIOBUTTON_H
-#define GUI_WIDGETS_RADIOBUTTON_H
-
-#include "listeners/keylistener.h"
-#include "listeners/mouselistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "gui/fonts/textchunk.h"
-
-#include "gui/widgets/widget.h"
-
-#include "localconsts.h"
-
-class Skin;
-
-/**
- * Guichan based RadioButton with custom look
- */
-class RadioButton final : public Widget,
- public MouseListener,
- public KeyListener,
- public WidgetListener
-
-{
- public:
- /**
- * Constructor.
- */
- RadioButton(const Widget2 *const widget,
- const std::string &restrict caption,
- const std::string &restrict group,
- const bool marked = false);
-
- A_DELETE_COPY(RadioButton)
-
- /**
- * Destructor.
- */
- ~RadioButton();
-
- /**
- * Draws the radiobutton, not the caption.
- */
- void drawBox(Graphics *const graphics) A_NONNULL(2);
-
- /**
- * Implementation of the draw methods.
- * Thus, avoiding the rhomb around the radio button.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Called when the mouse enteres the widget area.
- */
- void mouseEntered(MouseEvent& event) override final;
-
- /**
- * Called when the mouse leaves the widget area.
- */
- void mouseExited(MouseEvent& event) override final;
-
- void keyPressed(KeyEvent& event) override final;
-
- void updateAlpha();
-
- void adjustSize();
-
- /**
- * Checks if the radio button is selected.
- *
- * @return True if the radio button is selecte, false otherwise.
- * @see setSelected
- */
- bool isSelected() const
- { return mSelected; }
-
- /**
- * Sets the radio button to selected or not.
- *
- * @param selected True if the radio button should be selected,
- * false otherwise.
- * @see isSelected
- */
- void setSelected(const bool selected);
-
- /**
- * Gets the caption of the radio button.
- *
- * @return The caption of the radio button.
- * @see setCaption
- */
- const std::string &getCaption() const
- { return mCaption; }
-
- /**
- * Sets the caption of the radio button. It's advisable to call
- * adjustSize after setting of the caption to adjust the
- * radio button's size to fit the caption.
- *
- * @param caption The caption of the radio button.
- * @see getCaption, adjustSize
- */
- void setCaption(const std::string &caption);
-
- void mouseClicked(MouseEvent& event) override final;
-
- void mouseDragged(MouseEvent& event) override final;
-
- /**
- * Sets the group the radio button should belong to. Note that
- * a radio button group is unique per application, not per Gui object
- * as the group is stored in a static map.
- *
- * @param group The name of the group.
- * @see getGroup
- */
- void setGroup(const std::string &group);
-
- /**
- * Gets the group the radio button belongs to.
- *
- * @return The group the radio button belongs to.
- * @see setGroup
- */
- const std::string &getGroup() const
- { return mGroup; }
-
- void setParent(Widget *widget) override final;
-
- void widgetHidden(const Event &event) override final;
-
- void setWindow(Widget *const widget) override final;
-
- private:
- static int instances;
- static Skin *mSkin;
- static float mAlpha;
-
- /**
- * True if the radio button is selected, false otherwise.
- */
- bool mSelected;
-
- /**
- * Holds the caption of the radio button.
- */
- std::string mCaption;
-
- /**
- * Holds the group of the radio button.
- */
- std::string mGroup;
-
- TextChunk mTextChunk;
-
- /**
- * Typdef.
- */
- typedef std::multimap<std::string, RadioButton *> GroupMap;
-
- /**
- * Typdef.
- */
- typedef GroupMap::iterator GroupIterator;
-
- /**
- * Holds all available radio button groups.
- */
- static GroupMap mGroupMap;
-
- int mPadding;
- int mImagePadding;
- int mImageSize;
- int mSpacing;
- int mTextX;
- bool mHasMouse;
- bool mTextChanged;
-};
-
-#endif // GUI_WIDGETS_RADIOBUTTON_H
diff --git a/src/gui/widgets/radiogroup.cpp b/src/gui/widgets/radiogroup.cpp
deleted file mode 100644
index 5e500c18f..000000000
--- a/src/gui/widgets/radiogroup.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/radiogroup.h"
-
-#include "gui/widgets/radiobutton.h"
-
-#include "debug.h"
-
-RadioGroup::RadioGroup(const Widget2 *const widget,
- const std::string &group, const int height,
- const int spacing) :
- WidgetGroup(widget, group, height, spacing)
-{
-}
-
-Widget *RadioGroup::createWidget(const std::string &text,
- const bool pressed A_UNUSED) const
-{
- RadioButton *const widget = new RadioButton(
- this, text, mGroup, mCount == 0);
- widget->adjustSize();
- return widget;
-}
diff --git a/src/gui/widgets/radiogroup.h b/src/gui/widgets/radiogroup.h
deleted file mode 100644
index 346efc754..000000000
--- a/src/gui/widgets/radiogroup.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_RADIOGROUP_H
-#define GUI_WIDGETS_RADIOGROUP_H
-
-#include "gui/widgets/widgetgroup.h"
-
-class RadioGroup final : public WidgetGroup
-{
- public:
- RadioGroup(const Widget2 *const widget,
- const std::string &group,
- const int height,
- const int spacing);
-
- A_DELETE_COPY(RadioGroup)
-
- Widget *createWidget(const std::string &name,
- const bool pressed)
- const override final A_WARN_UNUSED;
-};
-
-#endif // GUI_WIDGETS_RADIOGROUP_H
diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp
deleted file mode 100644
index e22ecdcf3..000000000
--- a/src/gui/widgets/scrollarea.cpp
+++ /dev/null
@@ -1,1460 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/scrollarea.h"
-
-#include "settings.h"
-
-#include "gui/gui.h"
-#include "gui/skin.h"
-
-#include "utils/delete2.h"
-#include "utils/stringutils.h"
-
-#include "render/graphics.h"
-
-#include "render/vertexes/imagecollection.h"
-
-#include "resources/imagerect.h"
-
-#include "resources/image/image.h"
-
-#include "debug.h"
-
-int ScrollArea::instances = 0;
-float ScrollArea::mAlpha = 1.0;
-bool ScrollArea::mShowButtons = true;
-int ScrollArea::mMarkerSize = 0;
-int ScrollArea::mScrollbarSize = 12;
-ImageRect ScrollArea::background;
-ImageRect ScrollArea::vMarker;
-ImageRect ScrollArea::vMarkerHi;
-ImageRect ScrollArea::vBackground;
-ImageRect ScrollArea::hBackground;
-Image *ScrollArea::buttons[4][2];
-
-static std::string const buttonFiles[2] =
-{
- "scrollbuttons.xml",
- "scrollbuttons_pressed.xml"
-};
-
-ScrollArea::ScrollArea(Widget2 *const widget2,
- Widget *const widget,
- const Opaque opaque,
- const std::string &skin) :
- BasicContainer(widget2),
- MouseListener(),
- WidgetListener(),
- mVertexes(new ImageCollection),
- mVertexes2(new ImageCollection),
- mHPolicy(SHOW_AUTO),
- mVPolicy(SHOW_AUTO),
- mVScroll(0),
- mHScroll(0),
- mScrollbarWidth(12),
- mUpButtonScrollAmount(10),
- mDownButtonScrollAmount(10),
- mLeftButtonScrollAmount(10),
- mRightButtonScrollAmount(10),
- mHorizontalMarkerDragOffset(0),
- mVerticalMarkerDragOffset(0),
- mX(0),
- mY(0),
- mClickX(0),
- mClickY(0),
- mXOffset(0),
- mYOffset(0),
- mDrawWidth(0),
- mDrawHeight(0),
- mVBarVisible(false),
- mHBarVisible(false),
- mUpButtonPressed(false),
- mDownButtonPressed(false),
- mLeftButtonPressed(false),
- mRightButtonPressed(false),
- mIsVerticalMarkerDragged(false),
- mIsHorizontalMarkerDragged(false),
- mOpaque(Opaque_true),
- mHasMouse(false)
-{
- setContent(widget);
- addMouseListener(this);
- mOpaque = opaque;
- init(skin);
-}
-
-ScrollArea::~ScrollArea()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- // Garbage collection
- delete getContent();
-
- instances--;
- if (instances == 0)
- {
- Theme::unloadRect(background);
- Theme::unloadRect(vMarker);
- Theme::unloadRect(vMarkerHi);
- Theme::unloadRect(vBackground);
- Theme::unloadRect(hBackground);
- for (int i = 0; i < 2; i ++)
- {
- for (int f = UP; f < BUTTONS_DIR; f ++)
- {
- if (buttons[f][i] != nullptr)
- buttons[f][i]->decRef();
- }
- }
- }
-
- delete2(mVertexes);
- delete2(mVertexes2);
-
- setContent(nullptr);
-}
-
-void ScrollArea::init(std::string skinName)
-{
- setOpaque(mOpaque);
-
- setUpButtonScrollAmount(2);
- setDownButtonScrollAmount(2);
- setLeftButtonScrollAmount(2);
- setRightButtonScrollAmount(2);
-
- if (instances == 0)
- {
- for (int f = 0; f < 9; f ++)
- {
- background.grid[f] = nullptr;
- vMarker.grid[f] = nullptr;
- vMarkerHi.grid[f] = nullptr;
- vBackground.grid[f] = nullptr;
- hBackground.grid[f] = nullptr;
- }
-
- // +++ here probably need move background from static
- if (skinName.empty())
- skinName = "scroll_background.xml";
- if (theme != nullptr)
- {
- theme->loadRect(background, skinName, "scroll_background.xml");
- theme->loadRect(vMarker, "scroll.xml", "");
- theme->loadRect(vMarkerHi, "scroll_highlighted.xml", "scroll.xml");
- theme->loadRect(vBackground, "scroll_vbackground.xml", "");
- theme->loadRect(hBackground, "scroll_hbackground.xml", "");
- }
-
- for (int i = 0; i < 2; i ++)
- {
- Skin *skin = nullptr;
- if (theme != nullptr)
- skin = theme->load(buttonFiles[i], "scrollbuttons.xml");
- if (skin != nullptr)
- {
- const ImageRect &rect = skin->getBorder();
- for (int f = UP; f < BUTTONS_DIR; f ++)
- {
- if (rect.grid[f] != nullptr)
- rect.grid[f]->incRef();
- buttons[f][i] = rect.grid[f];
- }
- if (i == 0)
- {
- mShowButtons = (skin->getOption("showbuttons", 1) == 1);
- mMarkerSize = skin->getOption("markersize", 0);
- mScrollbarSize = skin->getOption("scrollbarsize", 12);
- }
- }
- else
- {
- for (int f = UP; f < BUTTONS_DIR; f ++)
- buttons[f][i] = nullptr;
- }
- if (theme != nullptr)
- theme->unload(skin);
- }
- }
- mScrollbarWidth = mScrollbarSize;
- instances++;
-}
-
-void ScrollArea::logic()
-{
- BLOCK_START("ScrollArea::logic")
- if (!isVisible())
- {
- BLOCK_END("ScrollArea::logic")
- return;
- }
-
- checkPolicies();
-
- setVerticalScrollAmount(mVScroll);
- setHorizontalScrollAmount(mHScroll);
-
- Widget *const content = getContent();
- if (content != nullptr)
- {
- unsigned int frameSize = content->getFrameSize();
- content->setPosition(-mHScroll + frameSize, -mVScroll + frameSize);
- content->logic();
-
- // When no scrollbar in a certain direction,
- // adapt content size to match the content dimension exactly.
- frameSize = 2 * content->getFrameSize();
- if (mHPolicy == ScrollArea::SHOW_NEVER)
- {
- content->setWidth((mVBarVisible ? (mDimension.width
- - mScrollbarWidth) : mDimension.width) - frameSize);
- }
- if (mVPolicy == ScrollArea::SHOW_NEVER)
- {
- content->setHeight((mHBarVisible ? (mDimension.height
- - mScrollbarWidth) : mDimension.height) - frameSize);
- }
- }
-
- if (mUpButtonPressed)
- setVerticalScrollAmount(mVScroll - mUpButtonScrollAmount);
- else if (mDownButtonPressed)
- setVerticalScrollAmount(mVScroll + mDownButtonScrollAmount);
- else if (mLeftButtonPressed)
- setHorizontalScrollAmount(mHScroll - mLeftButtonScrollAmount);
- else if (mRightButtonPressed)
- setHorizontalScrollAmount(mHScroll + mRightButtonScrollAmount);
- BLOCK_END("ScrollArea::logic")
-}
-
-void ScrollArea::updateAlpha()
-{
- const float alpha = std::max(settings.guiAlpha,
- theme->getMinimumOpacity());
-
- if (alpha != mAlpha)
- {
- mAlpha = alpha;
- for (int a = 0; a < 9; a++)
- {
- if (background.grid[a] != nullptr)
- background.grid[a]->setAlpha(mAlpha);
- if (hBackground.grid[a] != nullptr)
- hBackground.grid[a]->setAlpha(mAlpha);
- if (vBackground.grid[a] != nullptr)
- vBackground.grid[a]->setAlpha(mAlpha);
- if (vMarker.grid[a] != nullptr)
- vMarker.grid[a]->setAlpha(mAlpha);
- if (vMarkerHi.grid[a] != nullptr)
- vMarkerHi.grid[a]->setAlpha(mAlpha);
- }
- }
-}
-
-void ScrollArea::draw(Graphics *const graphics)
-{
- BLOCK_START("ScrollArea::draw")
- if (mVBarVisible || mHBarVisible)
- {
- if (mOpaque == Opaque_false)
- updateCalcFlag(graphics);
- // need add caching or remove calc calls.
-// if (mRedraw)
- {
- mVertexes->clear();
- if (mVBarVisible)
- {
- if (mShowButtons)
- {
- calcButton(graphics, UP);
- calcButton(graphics, DOWN);
- }
- calcVBar(graphics);
- calcVMarker(graphics);
- }
-
- if (mHBarVisible)
- {
- if (mShowButtons)
- {
- calcButton(graphics, LEFT);
- calcButton(graphics, RIGHT);
- }
- calcHBar(graphics);
- calcHMarker(graphics);
- }
- graphics->finalize(mVertexes);
- }
- graphics->drawTileCollection(mVertexes);
- }
-
- updateAlpha();
-
- if (mRedraw)
- {
- const bool redraw = graphics->getRedraw();
- graphics->setRedraw(true);
- drawChildren(graphics);
- graphics->setRedraw(redraw);
- }
- else
- {
- drawChildren(graphics);
- }
- mRedraw = false;
- BLOCK_END("ScrollArea::draw")
-}
-
-void ScrollArea::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("ScrollArea::draw")
- if (mVBarVisible)
- {
- if (mShowButtons)
- {
- drawButton(graphics, UP);
- drawButton(graphics, DOWN);
- }
- drawVBar(graphics);
- drawVMarker(graphics);
- }
-
- if (mHBarVisible)
- {
- if (mShowButtons)
- {
- drawButton(graphics, LEFT);
- drawButton(graphics, RIGHT);
- }
- drawHBar(graphics);
- drawHMarker(graphics);
- }
-
- updateAlpha();
-
- safeDrawChildren(graphics);
- mRedraw = false;
- BLOCK_END("ScrollArea::draw")
-}
-
-void ScrollArea::updateCalcFlag(const Graphics *const graphics)
-{
- if (!mRedraw)
- {
- // because we don't know where parent windows was moved,
- // need recalc vertexes
- const ClipRect &rect = graphics->getTopClip();
- if (rect.xOffset != mXOffset || rect.yOffset != mYOffset)
- {
- mRedraw = true;
- mXOffset = rect.xOffset;
- mYOffset = rect.yOffset;
- }
- else if (rect.width != mDrawWidth || rect.height != mDrawHeight)
- {
- mRedraw = true;
- mDrawWidth = rect.width;
- mDrawHeight = rect.height;
- }
- else if (graphics->getRedraw())
- {
- mRedraw = true;
- }
- }
-}
-
-void ScrollArea::drawFrame(Graphics *const graphics)
-{
- BLOCK_START("ScrollArea::drawFrame")
- if (mOpaque == Opaque_true)
- {
- const int bs = mFrameSize * 2;
- const int w = mDimension.width + bs;
- const int h = mDimension.height + bs;
-
- updateCalcFlag(graphics);
-
- if (mRedraw)
- {
- mVertexes2->clear();
- graphics->calcWindow(mVertexes2,
- 0, 0,
- w, h,
- background);
- graphics->finalize(mVertexes2);
- }
- graphics->drawTileCollection(mVertexes2);
- }
- BLOCK_END("ScrollArea::drawFrame")
-}
-
-void ScrollArea::safeDrawFrame(Graphics *const graphics)
-{
- BLOCK_START("ScrollArea::drawFrame")
- if (mOpaque == Opaque_true)
- {
- const int bs = mFrameSize * 2;
- const int w = mDimension.width + bs;
- const int h = mDimension.height + bs;
-
- updateCalcFlag(graphics);
- graphics->drawImageRect(0, 0,
- w, h,
- background);
- }
- BLOCK_END("ScrollArea::drawFrame")
-}
-
-void ScrollArea::setOpaque(Opaque opaque)
-{
- mOpaque = opaque;
- setFrameSize(mOpaque == Opaque_true ? 2 : 0);
-}
-
-Image *ScrollArea::getImageByState(Rect &dim, const BUTTON_DIR dir)
-{
- int state = 0;
-
- switch (dir)
- {
- case UP:
- state = mUpButtonPressed ? 1 : 0;
- dim = getUpButtonDimension();
- break;
- case DOWN:
- state = mDownButtonPressed ? 1 : 0;
- dim = getDownButtonDimension();
- break;
- case LEFT:
- state = mLeftButtonPressed ? 1 : 0;
- dim = getLeftButtonDimension();
- break;
- case RIGHT:
- state = mRightButtonPressed ? 1 : 0;
- dim = getRightButtonDimension();
- break;
- case BUTTONS_DIR:
- default:
- logger->log("ScrollArea::drawButton unknown dir: "
- + toString(CAST_U32(dir)));
- return nullptr;
- }
- return buttons[CAST_SIZE(dir)][state];
-}
-
-void ScrollArea::drawButton(Graphics *const graphics,
- const BUTTON_DIR dir)
-{
- Rect dim;
- const Image *const image = getImageByState(dim, dir);
-
- if (image != nullptr)
- graphics->drawImage(image, dim.x, dim.y);
-}
-
-void ScrollArea::calcButton(Graphics *const graphics,
- const BUTTON_DIR dir)
-{
- Rect dim;
- const Image *const image = getImageByState(dim, dir);
-
- if (image != nullptr)
- {
- static_cast<Graphics*>(graphics)->calcTileCollection(
- mVertexes, image, dim.x, dim.y);
- }
-}
-
-void ScrollArea::drawVBar(Graphics *const graphics) const
-{
- const Rect &dim = getVerticalBarDimension();
-
- if (vBackground.grid[4] != nullptr)
- {
- graphics->drawPattern(vBackground.grid[4],
- dim.x, dim.y, dim.width, dim.height);
- }
- if (vBackground.grid[1] != nullptr)
- {
- graphics->drawPattern(vBackground.grid[1],
- dim.x, dim.y,
- dim.width, vBackground.grid[1]->getHeight());
- }
- if (vBackground.grid[7] != nullptr)
- {
- graphics->drawPattern(vBackground.grid[7],
- dim.x, dim.height - vBackground.grid[7]->getHeight() + dim.y,
- dim.width, vBackground.grid[7]->getHeight());
- }
-}
-
-void ScrollArea::calcVBar(const Graphics *const graphics)
-{
- const Rect &dim = getVerticalBarDimension();
-
- if (vBackground.grid[4] != nullptr)
- {
- graphics->calcPattern(mVertexes,
- vBackground.grid[4],
- dim.x, dim.y,
- dim.width, dim.height);
- }
- if (vBackground.grid[1] != nullptr)
- {
- graphics->calcPattern(mVertexes,
- vBackground.grid[1],
- dim.x, dim.y,
- dim.width, vBackground.grid[1]->getHeight());
- }
- if (vBackground.grid[7] != nullptr)
- {
- graphics->calcPattern(mVertexes,
- vBackground.grid[7],
- dim.x, dim.height - vBackground.grid[7]->getHeight() + dim.y,
- dim.width, vBackground.grid[7]->getHeight());
- }
-}
-
-void ScrollArea::drawHBar(Graphics *const graphics) const
-{
- const Rect &dim = getHorizontalBarDimension();
-
- if (hBackground.grid[4] != nullptr)
- {
- graphics->drawPattern(hBackground.grid[4],
- dim.x, dim.y,
- dim.width, dim.height);
- }
-
- if (hBackground.grid[3] != nullptr)
- {
- graphics->drawPattern(hBackground.grid[3],
- dim.x, dim.y,
- hBackground.grid[3]->getWidth(), dim.height);
- }
-
- if (hBackground.grid[5] != nullptr)
- {
- graphics->drawPattern(hBackground.grid[5],
- dim.x + dim.width - hBackground.grid[5]->getWidth(),
- dim.y,
- hBackground.grid[5]->getWidth(),
- dim.height);
- }
-}
-
-void ScrollArea::calcHBar(const Graphics *const graphics)
-{
- const Rect &dim = getHorizontalBarDimension();
-
- if (hBackground.grid[4] != nullptr)
- {
- graphics->calcPattern(mVertexes,
- hBackground.grid[4],
- dim.x, dim.y,
- dim.width, dim.height);
- }
-
- if (hBackground.grid[3] != nullptr)
- {
- graphics->calcPattern(mVertexes,
- hBackground.grid[3],
- dim.x, dim.y,
- hBackground.grid[3]->getWidth(), dim.height);
- }
-
- if (hBackground.grid[5] != nullptr)
- {
- graphics->calcPattern(mVertexes,
- hBackground.grid[5],
- dim.x + dim.width - hBackground.grid[5]->getWidth(),
- dim.y,
- hBackground.grid[5]->getWidth(),
- dim.height);
- }
-}
-
-void ScrollArea::drawVMarker(Graphics *const graphics)
-{
- const Rect &dim = getVerticalMarkerDimension();
-
- if ((mHasMouse) && (mX > (mDimension.width - mScrollbarWidth)))
- {
- graphics->drawImageRect(dim.x, dim.y,
- dim.width, dim.height,
- vMarkerHi);
- }
- else
- {
- graphics->drawImageRect(dim.x, dim.y,
- dim.width, dim.height,
- vMarker);
- }
-}
-
-void ScrollArea::calcVMarker(Graphics *const graphics)
-{
- const Rect &dim = getVerticalMarkerDimension();
-
- if ((mHasMouse) && (mX > (mDimension.width - mScrollbarWidth)))
- {
- graphics->calcWindow(mVertexes,
- dim.x, dim.y,
- dim.width, dim.height,
- vMarkerHi);
- }
- else
- {
- graphics->calcWindow(mVertexes,
- dim.x, dim.y,
- dim.width, dim.height,
- vMarker);
- }
-}
-
-void ScrollArea::drawHMarker(Graphics *const graphics)
-{
- const Rect dim = getHorizontalMarkerDimension();
-
- if ((mHasMouse) && (mY > (mDimension.height - mScrollbarWidth)))
- {
- graphics->drawImageRect(dim.x, dim.y,
- dim.width, dim.height,
- vMarkerHi);
- }
- else
- {
- graphics->drawImageRect(
- dim.x, dim.y,
- dim.width, dim.height,
- vMarker);
- }
-}
-
-void ScrollArea::calcHMarker(Graphics *const graphics)
-{
- const Rect dim = getHorizontalMarkerDimension();
-
- if ((mHasMouse) && (mY > (mDimension.height - mScrollbarWidth)))
- {
- graphics->calcWindow(mVertexes,
- dim.x, dim.y,
- dim.width, dim.height,
- vMarkerHi);
- }
- else
- {
- graphics->calcWindow(mVertexes,
- dim.x, dim.y,
- dim.width, dim.height,
- vMarker);
- }
-}
-
-void ScrollArea::mouseMoved(MouseEvent& event)
-{
- mX = event.getX();
- mY = event.getY();
-}
-
-void ScrollArea::mouseEntered(MouseEvent& event A_UNUSED)
-{
- mHasMouse = true;
-}
-
-void ScrollArea::mouseExited(MouseEvent& event A_UNUSED)
-{
- mHasMouse = false;
-}
-
-void ScrollArea::widgetResized(const Event &event A_UNUSED)
-{
- mRedraw = true;
- const unsigned int frameSize = 2 * mFrameSize;
- Widget *const content = getContent();
- if (content != nullptr)
- {
- content->setSize(mDimension.width - frameSize,
- mDimension.height - frameSize);
- }
-}
-
-void ScrollArea::widgetMoved(const Event& event A_UNUSED)
-{
- mRedraw = true;
-}
-
-void ScrollArea::mousePressed(MouseEvent& event)
-{
- const int x = event.getX();
- const int y = event.getY();
-
- if (getUpButtonDimension().isPointInRect(x, y))
- {
- setVerticalScrollAmount(mVScroll
- - mUpButtonScrollAmount);
- mUpButtonPressed = true;
- event.consume();
- }
- else if (getDownButtonDimension().isPointInRect(x, y))
- {
- setVerticalScrollAmount(mVScroll
- + mDownButtonScrollAmount);
- mDownButtonPressed = true;
- event.consume();
- }
- else if (getLeftButtonDimension().isPointInRect(x, y))
- {
- setHorizontalScrollAmount(mHScroll
- - mLeftButtonScrollAmount);
- mLeftButtonPressed = true;
- event.consume();
- }
- else if (getRightButtonDimension().isPointInRect(x, y))
- {
- setHorizontalScrollAmount(mHScroll
- + mRightButtonScrollAmount);
- mRightButtonPressed = true;
- event.consume();
- }
- else if (getVerticalMarkerDimension().isPointInRect(x, y))
- {
- mIsHorizontalMarkerDragged = false;
- mIsVerticalMarkerDragged = true;
-
- mVerticalMarkerDragOffset = y - getVerticalMarkerDimension().y;
- event.consume();
- }
- else if (getVerticalBarDimension().isPointInRect(x, y))
- {
- if (y < getVerticalMarkerDimension().y)
- {
- setVerticalScrollAmount(mVScroll
- - CAST_S32(getChildrenArea().height * 0.1));
- }
- else
- {
- setVerticalScrollAmount(mVScroll
- + CAST_S32(getChildrenArea().height * 0.1));
- }
- event.consume();
- }
- else if (getHorizontalMarkerDimension().isPointInRect(x, y))
- {
- mIsHorizontalMarkerDragged = true;
- mIsVerticalMarkerDragged = false;
- mHorizontalMarkerDragOffset = x - getHorizontalMarkerDimension().x;
- event.consume();
- }
- else if (getHorizontalBarDimension().isPointInRect(x, y))
- {
- if (x < getHorizontalMarkerDimension().x)
- {
- setHorizontalScrollAmount(mHScroll
- - CAST_S32(getChildrenArea().width * 0.1));
- }
- else
- {
- setHorizontalScrollAmount(mHScroll
- + CAST_S32(getChildrenArea().width * 0.1));
- }
- event.consume();
- }
-
- if (event.getButton() == MouseButton::LEFT &&
- !event.isConsumed())
- {
- mClickX = event.getX();
- mClickY = event.getY();
- }
-}
-
-void ScrollArea::mouseReleased(MouseEvent& event)
-{
- if (event.getButton() == MouseButton::LEFT &&
- mClickX != 0 &&
- mClickY != 0)
- {
- if (!event.isConsumed())
- {
-#ifdef ANDROID
- int dx = mClickX - event.getX();
- int dy = mClickY - event.getY();
-#else // ANDROID
-
- int dx = event.getX() - mClickX;
- int dy = event.getY() - mClickY;
-#endif // ANDROID
-
- if ((dx < 20 && dx > 0) || (dx > -20 && dx < 0))
- dx = 0;
-
- if ((dy < 20 && dy > 0) || (dy > -20 && dy < 0))
- dy = 0;
-
- if (abs(dx) > abs(dy))
- {
- int s = mHScroll + dx;
- if (s < 0)
- {
- s = 0;
- }
- else
- {
- const int maxH = getHorizontalMaxScroll();
- if (s > maxH)
- s = maxH;
- }
-
- setHorizontalScrollAmount(s);
- }
- else if (dy != 0)
- {
- int s = mVScroll + dy;
- if (s < 0)
- {
- s = 0;
- }
- else
- {
- const int maxV = getVerticalMaxScroll();
- if (s > maxV)
- s = maxV;
- }
-
- setVerticalScrollAmount(s);
- }
- mClickX = 0;
- mClickY = 0;
- if (mMouseConsume && ((dx != 0) || (dy != 0)))
- event.consume();
- }
- }
- mUpButtonPressed = false;
- mDownButtonPressed = false;
- mLeftButtonPressed = false;
- mRightButtonPressed = false;
- mIsHorizontalMarkerDragged = false;
- mIsVerticalMarkerDragged = false;
- if (mMouseConsume)
- event.consume();
- mRedraw = true;
-}
-
-void ScrollArea::mouseDragged(MouseEvent &event)
-{
- if (mIsVerticalMarkerDragged)
- {
- const Rect barDim = getVerticalBarDimension();
-
- const int pos = event.getY() - barDim.y
- - mVerticalMarkerDragOffset;
- const int length = getVerticalMarkerDimension().height;
-
- if ((barDim.height - length) > 0)
- {
- setVerticalScrollAmount((getVerticalMaxScroll() * pos)
- / (barDim.height - length));
- }
- else
- {
- setVerticalScrollAmount(0);
- }
- }
-
- if (mIsHorizontalMarkerDragged)
- {
- const Rect barDim = getHorizontalBarDimension();
-
- const int pos = event.getX() - barDim.x
- - mHorizontalMarkerDragOffset;
- const int length = getHorizontalMarkerDimension().width;
-
- if ((barDim.width - length) > 0)
- {
- setHorizontalScrollAmount((getHorizontalMaxScroll() * pos)
- / (barDim.width - length));
- }
- else
- {
- setHorizontalScrollAmount(0);
- }
- }
-
- event.consume();
- mRedraw = true;
-}
-
-Rect ScrollArea::getVerticalBarDimension() const
-{
- if (!mVBarVisible)
- return Rect(0, 0, 0, 0);
-
- const int height = mShowButtons ? mScrollbarWidth : 0;
- if (mHBarVisible)
- {
- return Rect(mDimension.width - mScrollbarWidth,
- height,
- mScrollbarWidth,
- mDimension.height - 2 * height - mScrollbarWidth);
- }
-
- return Rect(mDimension.width - mScrollbarWidth,
- height,
- mScrollbarWidth,
- mDimension.height - 2 * height);
-}
-
-Rect ScrollArea::getHorizontalBarDimension() const
-{
- if (!mHBarVisible)
- return Rect(0, 0, 0, 0);
-
- const int width = mShowButtons ? mScrollbarWidth : 0;
- if (mVBarVisible)
- {
- return Rect(width,
- mDimension.height - mScrollbarWidth,
- mDimension.width - 2 * width - mScrollbarWidth,
- mScrollbarWidth);
- }
-
- return Rect(width,
- mDimension.height - mScrollbarWidth,
- mDimension.width - 2 * width,
- mScrollbarWidth);
-}
-
-Rect ScrollArea::getVerticalMarkerDimension()
-{
- if (!mVBarVisible)
- return Rect(0, 0, 0, 0);
-
- int length, pos;
- int height;
- const int h2 = mShowButtons
- ? mScrollbarWidth : mMarkerSize / 2;
- const Widget *content;
- if (!mWidgets.empty())
- content = *mWidgets.begin();
- else
- content = nullptr;
-
- if (mHBarVisible)
- height = mDimension.height - 2 * h2 - mScrollbarWidth;
- else
- height = mDimension.height - 2 * h2;
-
- const int maxV = getVerticalMaxScroll();
- if ((mMarkerSize != 0) && (maxV != 0))
- {
- pos = (mVScroll * height / maxV - mMarkerSize / 2);
- length = mMarkerSize;
- }
- else
- {
- if (content != nullptr)
- {
- const int h3 = content->getHeight();
- if (h3 != 0)
- length = (height * getChildrenArea().height) / h3;
- else
- length = height;
- }
- else
- {
- length = height;
- }
-
- if (length < mScrollbarWidth)
- length = mScrollbarWidth;
-
- if (length > height)
- length = height;
-
- const int maxScroll = getVerticalMaxScroll();
- if (maxScroll != 0)
- pos = ((height - length) * mVScroll) / maxScroll;
- else
- pos = 0;
- }
-
- return Rect(mDimension.width - mScrollbarWidth, h2 + pos,
- mScrollbarWidth, length);
-}
-
-Rect ScrollArea::getHorizontalMarkerDimension()
-{
- if (!mHBarVisible)
- return Rect(0, 0, 0, 0);
-
- int length, pos;
- int width;
- const int w2 = mShowButtons
- ? mScrollbarWidth : mMarkerSize / 2;
- const Widget *content;
- if (!mWidgets.empty())
- content = *mWidgets.begin();
- else
- content = nullptr;
-
- if (mVBarVisible)
- width = mDimension.width - 2 * w2 - mScrollbarWidth;
- else
- width = mDimension.width - w2 - mScrollbarWidth;
-
- const int maxH = getHorizontalMaxScroll();
- if ((mMarkerSize != 0) && (maxH != 0))
- {
- pos = (mHScroll * width / maxH - mMarkerSize / 2);
- length = mMarkerSize;
- }
- else
- {
- if (content != nullptr)
- {
- const int w3 = content->getWidth();
- if (w3 != 0)
- length = (width * getChildrenArea().width) / w3;
- else
- length = width;
- }
- else
- {
- length = width;
- }
-
- if (length < mScrollbarWidth)
- length = mScrollbarWidth;
-
- if (length > width)
- length = width;
-
- if (getHorizontalMaxScroll() != 0)
- {
- pos = ((width - length) * mHScroll)
- / getHorizontalMaxScroll();
- }
- else
- {
- pos = 0;
- }
- }
-
- return Rect(w2 + pos, mDimension.height - mScrollbarWidth,
- length, mScrollbarWidth);
-}
-
-Rect ScrollArea::getUpButtonDimension() const
-{
- if (!mVBarVisible || !mShowButtons)
- return Rect(0, 0, 0, 0);
-
- return Rect(mDimension.width - mScrollbarWidth, 0,
- mScrollbarWidth, mScrollbarWidth);
-}
-
-Rect ScrollArea::getDownButtonDimension() const
-{
- if (!mVBarVisible || !mShowButtons)
- return Rect(0, 0, 0, 0);
-
- if (mHBarVisible)
- {
- return Rect(mDimension.width - mScrollbarWidth,
- mDimension.height - mScrollbarWidth * 2,
- mScrollbarWidth,
- mScrollbarWidth);
- }
-
- return Rect(mDimension.width - mScrollbarWidth,
- mDimension.height - mScrollbarWidth,
- mScrollbarWidth,
- mScrollbarWidth);
-}
-
-Rect ScrollArea::getLeftButtonDimension() const
-{
- if (!mHBarVisible || !mShowButtons)
- return Rect(0, 0, 0, 0);
-
- return Rect(0, mDimension.height - mScrollbarWidth,
- mScrollbarWidth, mScrollbarWidth);
-}
-
-Rect ScrollArea::getRightButtonDimension() const
-{
- if (!mHBarVisible || !mShowButtons)
- return Rect(0, 0, 0, 0);
-
- if (mVBarVisible)
- {
- return Rect(mDimension.width - mScrollbarWidth*2,
- mDimension.height - mScrollbarWidth,
- mScrollbarWidth,
- mScrollbarWidth);
- }
-
- return Rect(mDimension.width - mScrollbarWidth,
- mDimension.height - mScrollbarWidth,
- mScrollbarWidth,
- mScrollbarWidth);
-}
-
-void ScrollArea::setContent(Widget* widget)
-{
- if (widget != nullptr)
- {
- clear();
- add(widget);
- widget->setPosition(0, 0);
- }
- else
- {
- clear();
- }
-
- checkPolicies();
-}
-
-Widget* ScrollArea::getContent()
-{
- if (!mWidgets.empty())
- return *mWidgets.begin();
-
- return nullptr;
-}
-
-void ScrollArea::setHorizontalScrollPolicy(const ScrollPolicy hPolicy)
-{
- mHPolicy = hPolicy;
- checkPolicies();
-}
-
-void ScrollArea::setVerticalScrollPolicy(const ScrollPolicy vPolicy)
-{
- mVPolicy = vPolicy;
- checkPolicies();
-}
-
-void ScrollArea::setScrollPolicy(const ScrollPolicy hPolicy,
- const ScrollPolicy vPolicy)
-{
- mHPolicy = hPolicy;
- mVPolicy = vPolicy;
- checkPolicies();
-}
-
-void ScrollArea::setVerticalScrollAmount(const int vScroll)
-{
- const int max = getVerticalMaxScroll();
-
- mVScroll = vScroll;
-
- if (vScroll > max)
- mVScroll = max;
-
- if (vScroll < 0)
- mVScroll = 0;
-}
-
-void ScrollArea::setHorizontalScrollAmount(int hScroll)
-{
- const int max = getHorizontalMaxScroll();
-
- mHScroll = hScroll;
-
- if (hScroll > max)
- mHScroll = max;
- else if (hScroll < 0)
- mHScroll = 0;
-}
-
-void ScrollArea::setScrollAmount(const int hScroll, const int vScroll)
-{
- setHorizontalScrollAmount(hScroll);
- setVerticalScrollAmount(vScroll);
-}
-
-int ScrollArea::getHorizontalMaxScroll()
-{
- checkPolicies();
-
- const Widget *const content = getContent();
- if (content == nullptr)
- return 0;
-
- const int value = content->getWidth() - getChildrenArea().width +
- 2 * content->getFrameSize();
-
- if (value < 0)
- return 0;
-
- return value;
-}
-
-int ScrollArea::getVerticalMaxScroll()
-{
- checkPolicies();
-
- const Widget *const content = getContent();
- if (content == nullptr)
- return 0;
-
- int value;
-
- value = content->getHeight() - getChildrenArea().height +
- 2 * content->getFrameSize();
-
- if (value < 0)
- return 0;
-
- return value;
-}
-
-void ScrollArea::setScrollbarWidth(const int width)
-{
- if (width > 0)
- mScrollbarWidth = width;
-}
-
-void ScrollArea::showWidgetPart(Widget *const widget, const Rect &area)
-{
- const Widget *const content = getContent();
- if (widget != content || (content == nullptr))
- return;
-
- BasicContainer::showWidgetPart(widget, area);
-
- setHorizontalScrollAmount(content->getFrameSize()
- - content->getX());
- setVerticalScrollAmount(content->getFrameSize()
- - content->getY());
-}
-
-Rect ScrollArea::getChildrenArea()
-{
- const Rect area = Rect(0, 0,
- mVBarVisible ? (getWidth() - mScrollbarWidth) : getWidth(),
- mHBarVisible ? (getHeight() - mScrollbarWidth) : getHeight());
-
- if (area.width < 0 || area.height < 0)
- return Rect();
-
- return area;
-}
-
-Widget *ScrollArea::getWidgetAt(int x, int y)
-{
- if (getChildrenArea().isPointInRect(x, y))
- return getContent();
-
- return nullptr;
-}
-
-void ScrollArea::setWidth(int width)
-{
- Widget::setWidth(width);
- checkPolicies();
-}
-
-void ScrollArea::setHeight(int height)
-{
- Widget::setHeight(height);
- checkPolicies();
-}
-
-void ScrollArea::setDimension(const Rect& dimension)
-{
- Widget::setDimension(dimension);
- checkPolicies();
-}
-
-void ScrollArea::mouseWheelMovedUp(MouseEvent& event)
-{
- if (event.isConsumed())
- return;
-
- setVerticalScrollAmount(mVScroll
- - getChildrenArea().height / 8);
-
- event.consume();
-}
-
-void ScrollArea::mouseWheelMovedDown(MouseEvent& event)
-{
- if (event.isConsumed())
- return;
-
- setVerticalScrollAmount(mVScroll
- + getChildrenArea().height / 8);
-
- event.consume();
-}
-
-void ScrollArea::checkPolicies()
-{
- const int w = getWidth();
- const int h = getHeight();
-
- mHBarVisible = false;
- mVBarVisible = false;
-
- const Widget *const content = getContent();
- if (content == nullptr)
- {
- mHBarVisible = (mHPolicy == SHOW_ALWAYS);
- mVBarVisible = (mVPolicy == SHOW_ALWAYS);
- return;
- }
-
- if (mHPolicy == SHOW_AUTO &&
- mVPolicy == SHOW_AUTO)
- {
- if (content->getWidth() <= w
- && content->getHeight() <= h)
- {
- mHBarVisible = false;
- mVBarVisible = false;
- }
-
- if (content->getWidth() > w)
- {
- mHBarVisible = true;
- }
-
- if ((content->getHeight() > h)
- || (mHBarVisible && content->getHeight()
- > h - mScrollbarWidth))
- {
- mVBarVisible = true;
- }
-
- if (mVBarVisible && content->getWidth() > w - mScrollbarWidth)
- mHBarVisible = true;
-
- return;
- }
-
- switch (mHPolicy)
- {
- case SHOW_NEVER:
- mHBarVisible = false;
- break;
-
- case SHOW_ALWAYS:
- mHBarVisible = true;
- break;
-
- case SHOW_AUTO:
- if (mVPolicy == SHOW_NEVER)
- {
- mHBarVisible = (content->getWidth() > w);
- }
- else // (mVPolicy == SHOW_ALWAYS)
- {
- mHBarVisible = (content->getWidth()
- > w - mScrollbarWidth);
- }
- break;
-
- default:
- break;
- }
-
- switch (mVPolicy)
- {
- case SHOW_NEVER:
- mVBarVisible = false;
- break;
-
- case SHOW_ALWAYS:
- mVBarVisible = true;
- break;
-
- case SHOW_AUTO:
- if (mHPolicy == SHOW_NEVER)
- {
- mVBarVisible = (content->getHeight() > h);
- }
- else // (mHPolicy == SHOW_ALWAYS)
- {
- mVBarVisible = (content->getHeight()
- > h - mScrollbarWidth);
- }
- break;
- default:
- break;
- }
-}
-
-bool ScrollArea::isSelectable() const noexcept2
-{
- if (mVBarVisible || mHBarVisible)
- return true;
- return Widget::isSelectable();
-}
diff --git a/src/gui/widgets/scrollarea.h b/src/gui/widgets/scrollarea.h
deleted file mode 100644
index 50b194d28..000000000
--- a/src/gui/widgets/scrollarea.h
+++ /dev/null
@@ -1,598 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_SCROLLAREA_H
-#define GUI_WIDGETS_SCROLLAREA_H
-
-#include "gui/widgets/basiccontainer.h"
-
-#include "enums/simpletypes/opaque.h"
-
-#include "listeners/mouselistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "localconsts.h"
-
-class Image;
-class ImageCollection;
-
-/**
- * A scroll area.
- *
- * Contrary to Guichan's scroll area, this scroll area takes ownership over its
- * content. However, it won't delete a previously set content widget when
- * setContent is called!
- *
- * \ingroup GUI
- */
-class ScrollArea final : public BasicContainer,
- public MouseListener,
- public WidgetListener
-{
- public:
- /**
- * Scrollpolicies for the horizontal and vertical scrollbar.
- * The policies are:
- *
- * SHOW_ALWAYS - Always show the scrollbars no matter what.
- * SHOW_NEVER - Never show the scrollbars no matter waht.
- * SHOW_AUTO - Show the scrollbars only when needed. That is if the
- * content grows larger then the ScrollArea.
- */
- enum ScrollPolicy
- {
- SHOW_ALWAYS = 0,
- SHOW_NEVER,
- SHOW_AUTO
- };
-
- ScrollArea(Widget2 *const widget2,
- Widget *const widget,
- const Opaque opaque = Opaque_true,
- const std::string &skin = "");
-
- A_DELETE_COPY(ScrollArea)
-
- /**
- * Destructor. Also deletes the content.
- */
- ~ScrollArea();
-
- /**
- * Logic function optionally adapts width or height of contents. This
- * depends on the scrollbar settings.
- */
- void logic() override final;
-
- /**
- * Update the alpha value to the graphic components.
- */
- void updateAlpha();
-
- /**
- * Draws the scroll area.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Draws the background and border of the scroll area.
- */
- void drawFrame(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDrawFrame(Graphics *const graphics) override final
- A_NONNULL(2);
-
- /**
- * Sets whether the widget should draw its background or not.
- */
- void setOpaque(Opaque opaque);
-
- /**
- * Returns whether the widget draws its background or not.
- */
- bool isOpaque() const noexcept2 A_WARN_UNUSED
- { return mOpaque == Opaque_true; }
-
- /**
- * Called when the mouse moves in the widget area.
- */
- void mouseMoved(MouseEvent& event) override final;
-
- /**
- * Called when the mouse enteres the widget area.
- */
- void mouseEntered(MouseEvent& event) override final;
-
- /**
- * Called when the mouse leaves the widget area.
- */
- void mouseExited(MouseEvent& event) override final;
-
- void mousePressed(MouseEvent& event) override final;
-
- void mouseReleased(MouseEvent& event) override final;
-
- void mouseDragged(MouseEvent &event) override final;
-
- void widgetResized(const Event &event) override final;
-
- void widgetMoved(const Event &event) override final;
-
- Rect getVerticalBarDimension() const;
-
- Rect getHorizontalBarDimension() const;
-
- Rect getVerticalMarkerDimension();
-
- Rect getHorizontalMarkerDimension();
-
- Rect getUpButtonDimension() const;
-
- Rect getDownButtonDimension() const;
-
- Rect getLeftButtonDimension() const;
-
- Rect getRightButtonDimension() const;
-
- /**
- * Sets the content.
- *
- * @param widget The content of the scroll area.
- */
- void setContent(Widget* widget);
-
- /**
- * Gets the content.
- *
- * @return The content of the scroll area.
- */
- Widget* getContent();
-
- /**
- * Sets the horizontal scrollbar policy. See enum with policies.
- *
- * @param hPolicy The policy for the horizontal scrollbar.
- * @see getHorizontalScrollPolicy
- */
- void setHorizontalScrollPolicy(const ScrollPolicy hPolicy);
-
- /**
- * Gets the horizontal scrollbar policy. See enum with policies.
- *
- * @return The policy for the horizontal scrollbar policy.
- * @see setHorizontalScrollPolicy, setScrollPolicy
- */
- ScrollPolicy getHorizontalScrollPolicy() const
- { return mHPolicy; }
-
- /**
- * Sets the vertical scrollbar policy. See enum with policies.
- *
- * @param vPolicy The policy for the vertical scrollbar.
- * @see getVerticalScrollPolicy
- */
- void setVerticalScrollPolicy(const ScrollPolicy vPolicy);
-
- /**
- * Gets the vertical scrollbar policy. See enum with policies.
- *
- * @return The policy for the vertical scrollbar.
- * @see setVerticalScrollPolicy, setScrollPolicy
- */
- ScrollPolicy getVerticalScrollPolicy() const
- { return mVPolicy; }
-
- /**
- * Sets the horizontal and vertical scrollbar policy.
- *
- * @param hPolicy The policy for the horizontal scrollbar.
- * @param vPolicy The policy for the vertical scrollbar.
- * @see getVerticalScrollPolicy, getHorizontalScrollPolicy
- */
- void setScrollPolicy(const ScrollPolicy hPolicy,
- const ScrollPolicy vPolicy);
-
- /**
- * Sets the amount to scroll vertically.
- *
- * @param vScroll The amount to scroll.
- * @see getVerticalScrollAmount
- */
- void setVerticalScrollAmount(const int vScroll);
-
- /**
- * Gets the amount that is scrolled vertically.
- *
- * @return The scroll amount on vertical scroll.
- * @see setVerticalScrollAmount, setScrollAmount
- */
- int getVerticalScrollAmount() const
- { return mVScroll; }
-
- /**
- * Sets the amount to scroll horizontally.
- *
- * @param hScroll The amount to scroll.
- * @see getHorizontalScrollAmount
- */
- void setHorizontalScrollAmount(int hScroll);
-
- /**
- * Gets the amount that is scrolled horizontally.
- *
- * @return The scroll amount on horizontal scroll.
- * @see setHorizontalScrollAmount, setScrollAmount
- */
- int getHorizontalScrollAmount() const
- { return mHScroll; }
-
- /**
- * Sets the amount to scroll horizontally and vertically.
- *
- * @param hScroll The amount to scroll on horizontal scroll.
- * @param vScroll The amount to scroll on vertical scroll.
- * @see getHorizontalScrollAmount, getVerticalScrollAmount
- */
- void setScrollAmount(const int hScroll, const int vScroll);
-
- /**
- * Gets the maximum amount of horizontal scroll.
- *
- * @return The horizontal max scroll.
- */
- int getHorizontalMaxScroll();
-
- /**
- * Gets the maximum amount of vertical scroll.
- *
- * @return The vertical max scroll.
- */
- int getVerticalMaxScroll();
-
- /**
- * Sets the width of the scroll bars.
- *
- * @param width The width of the scroll bars.
- * @see getScrollbarWidth
- */
- void setScrollbarWidth(const int width);
-
- /**
- * Gets the width of the scroll bars.
- *
- * @return the width of the ScrollBar.
- * @see setScrollbarWidth
- */
- int getScrollbarWidth() const
- { return mScrollbarWidth; }
-
- /**
- * Sets the amount to scroll in pixels when the left scroll button is
- * pushed.
- *
- * @param amount The amount to scroll in pixels.
- * @see getLeftButtonScrollAmount
- */
- void setLeftButtonScrollAmount(const int amount)
- { mLeftButtonScrollAmount = amount; }
-
- /**
- * Sets the amount to scroll in pixels when the right scroll button is
- * pushed.
- *
- * @param amount The amount to scroll in pixels.
- * @see getRightButtonScrollAmount
- */
- void setRightButtonScrollAmount(const int amount)
- { mRightButtonScrollAmount = amount; }
-
- /**
- * Sets the amount to scroll in pixels when the up scroll button is
- * pushed.
- *
- * @param amount The amount to scroll in pixels.
- * @see getUpButtonScrollAmount
- */
- void setUpButtonScrollAmount(const int amount)
- { mUpButtonScrollAmount = amount; }
-
- /**
- * Sets the amount to scroll in pixels when the down scroll button is
- * pushed.
- *
- * @param amount The amount to scroll in pixels.
- * @see getDownButtonScrollAmount
- */
- void setDownButtonScrollAmount(const int amount)
- { mDownButtonScrollAmount = amount; }
-
- /**
- * Gets the amount to scroll in pixels when the left scroll button is
- * pushed.
- *
- * @return The amount to scroll in pixels.
- * @see setLeftButtonScrollAmount
- */
- int getLeftButtonScrollAmount() const
- { return mLeftButtonScrollAmount; }
-
- /**
- * Gets the amount to scroll in pixels when the right scroll button is
- * pushed.
- *
- * @return The amount to scroll in pixels.
- * @see setRightButtonScrollAmount
- */
- int getRightButtonScrollAmount() const
- { return mRightButtonScrollAmount; }
-
- /**
- * Gets the amount to scroll in pixels when the up scroll button is
- * pushed.
- *
- * @return The amount to scroll in pixels.
- * @see setUpButtonScrollAmount
- */
- int getUpButtonScrollAmount() const
- { return mUpButtonScrollAmount; }
-
- /**
- * Gets the amount to scroll in pixels when the down scroll button is
- * pushed.
- *
- * @return The amount to scroll in pixels.
- * @see setDownButtonScrollAmount
- */
- int getDownButtonScrollAmount() const
- { return mDownButtonScrollAmount; }
-
- void showWidgetPart(Widget *const widget,
- const Rect &area) override final;
-
- Rect getChildrenArea() override final;
-
- Widget *getWidgetAt(int x, int y) override final;
-
- void setWidth(int width);
-
- void setHeight(int height);
-
- void setDimension(const Rect& dimension);
-
- void mouseWheelMovedUp(MouseEvent& event) override final;
-
- void mouseWheelMovedDown(MouseEvent& event) override final;
-
- bool isSelectable() const noexcept2 override final A_WARN_UNUSED;
-
- protected:
- enum BUTTON_DIR
- {
- UP = 0,
- DOWN,
- LEFT,
- RIGHT,
- BUTTONS_DIR
- };
-
- /**
- * Initializes the scroll area.
- */
- void init(std::string skinName);
-
- /**
- * Checks the policies for the scroll bars.
- */
- void checkPolicies();
-
- void drawButton(Graphics *const graphics,
- const BUTTON_DIR dir) A_NONNULL(2);
- void calcButton(Graphics *const graphics,
- const BUTTON_DIR dir) A_NONNULL(2);
- void drawVBar(Graphics *const graphics) const A_NONNULL(2);
- void drawHBar(Graphics *const graphics) const A_NONNULL(2);
- void drawVMarker(Graphics *const graphics) A_NONNULL(2);
- void drawHMarker(Graphics *const graphics) A_NONNULL(2);
-
- void calcVBar(const Graphics *const graphics) A_NONNULL(2);
- void calcHBar(const Graphics *const graphics) A_NONNULL(2);
- void calcVMarker(Graphics *const graphics) A_NONNULL(2);
- void calcHMarker(Graphics *const graphics) A_NONNULL(2);
-
- Image *getImageByState(Rect &dim, const BUTTON_DIR dir);
-
- void updateCalcFlag(const Graphics *const graphics) A_NONNULL(2);
-
- static int instances;
- static float mAlpha;
- static bool mShowButtons;
- static int mMarkerSize;
- static int mScrollbarSize;
- static ImageRect background;
- static ImageRect vMarker;
- static ImageRect vMarkerHi;
- static ImageRect vBackground;
- static ImageRect hBackground;
- static Image *buttons[4][2];
-
- ImageCollection *mVertexes A_NONNULLPOINTER;
- ImageCollection *mVertexes2 A_NONNULLPOINTER;
-
- /**
- * Holds the horizontal scroll bar policy.
- */
- ScrollPolicy mHPolicy;
-
- /**
- * Holds the vertical scroll bar policy.
- */
- ScrollPolicy mVPolicy;
-
- /**
- * Holds the vertical scroll amount.
- */
- int mVScroll;
-
- /**
- * Holds the horizontal scroll amount.
- */
- int mHScroll;
-
- /**
- * Holds the width of the scroll bars.
- */
- int mScrollbarWidth;
-
- /**
- * Holds the up button scroll amount.
- */
- int mUpButtonScrollAmount;
-
- /**
- * Holds the down button scroll amount.
- */
- int mDownButtonScrollAmount;
-
- /**
- * Holds the left button scroll amount.
- */
- int mLeftButtonScrollAmount;
-
- /**
- * Holds the right button scroll amount.
- */
- int mRightButtonScrollAmount;
-
- /**
- * Holds the horizontal markers drag offset.
- */
- int mHorizontalMarkerDragOffset;
-
- /**
- * Holds the vertical markers drag offset.
- */
- int mVerticalMarkerDragOffset;
-
- int mX;
- int mY;
- int mClickX;
- int mClickY;
- int mXOffset;
- int mYOffset;
- int mDrawWidth;
- int mDrawHeight;
-
- /**
- * True if the vertical scroll bar is visible, false otherwise.
- */
- bool mVBarVisible;
-
- /**
- * True if the horizontal scroll bar is visible, false otherwise.
- */
- bool mHBarVisible;
-
- /**
- * True if the up button is pressed, false otherwise.
- */
- bool mUpButtonPressed;
-
- /**
- * True if the down button is pressed, false otherwise.
- */
- bool mDownButtonPressed;
-
- /**
- * True if the left button is pressed, false otherwise.
- */
- bool mLeftButtonPressed;
-
- /**
- * True if the right button is pressed, false otherwise.
- */
- bool mRightButtonPressed;
-
- /**
- * True if the vertical marked is dragged.
- */
- bool mIsVerticalMarkerDragged;
-
- /**
- * True if the horizontal marked is dragged.
- */
- bool mIsHorizontalMarkerDragged;
-
- /**
- * True if the scroll area should be opaque (that is
- * display its background), false otherwise.
- */
- Opaque mOpaque;
-
- bool mHasMouse;
-};
-
-#endif // GUI_WIDGETS_SCROLLAREA_H
diff --git a/src/gui/widgets/selldialog.cpp b/src/gui/widgets/selldialog.cpp
deleted file mode 100644
index 68b9a039f..000000000
--- a/src/gui/widgets/selldialog.cpp
+++ /dev/null
@@ -1,397 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/selldialog.h"
-
-#include "const/resources/currency.h"
-
-#include "enums/gui/layouttype.h"
-
-#include "gui/windows/setupwindow.h"
-
-#include "gui/models/shopitems.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layout.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/shoplistbox.h"
-#include "gui/widgets/slider.h"
-
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include "resources/db/unitsdb.h"
-
-#include "resources/item/shopitem.h"
-
-#include "debug.h"
-
-SellDialog::DialogList SellDialog::instances;
-
-SellDialog::SellDialog(const IsSell isSell,
- const Advanced advanced) :
- // TRANSLATORS: sell dialog name
- Window(_("Sell"), Modal_false, nullptr, "sell.xml"),
- ActionListener(),
- SelectionListener(),
- mSellButton(nullptr),
- mQuitButton(nullptr),
- mConfirmButton(nullptr),
- mAddMaxButton(nullptr),
- mIncreaseButton(nullptr),
- mDecreaseButton(nullptr),
- mShopItemList(nullptr),
- mScrollArea(nullptr),
- mMoneyLabel(nullptr),
- mQuantityLabel(nullptr),
- mSlider(nullptr),
- mShopItems(nullptr),
- mPlayerMoney(0),
- mMaxItems(0),
- mAmountItems(0),
- mIsSell(isSell),
- mAdvanced(advanced)
-{
-}
-
-void SellDialog::postInit()
-{
- Window::postInit();
- setWindowName("Sell");
- setResizable(true);
- setCloseButton(true);
- setStickyButtonLock(true);
- setMinWidth(260);
- setMinHeight(220);
- setDefaultSize(260, 230, ImagePosition::CENTER);
-
- if (setupWindow != nullptr)
- setupWindow->registerWindowForReset(this);
-
- // Create a ShopItems instance, that is aware of duplicate entries.
- mShopItems = new ShopItems(true,
- DEFAULT_CURRENCY);
-
- if (mAdvanced == Advanced_true)
- mShopItems->setMergeDuplicates(false);
-
- mShopItemList = CREATEWIDGETR(ShopListBox,
- this,
- mShopItems,
- mShopItems,
- ShopListBoxType::Unknown);
- mShopItemList->setProtectItems(true);
- mScrollArea = new ScrollArea(this, mShopItemList,
- fromBool(getOptionBool("showbackground"), Opaque),
- "sell_background.xml");
- mScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
-
- mSellButton = new Button(this,
- // TRANSLATORS: sell dialog button
- mAdvanced == Advanced_true ? _("Add") : _("Sell"),
- "presell",
- this);
- // TRANSLATORS: sell dialog button
- mQuitButton = new Button(this, _("Quit"), "quit", this);
-
- initButtons();
-
- mSellButton->setEnabled(false);
-
- mShopItemList->setDistributeMousePressed(false);
- mShopItemList->setPriceCheck(false);
- mShopItemList->addSelectionListener(this);
- mShopItemList->setActionEventId("sell");
- mShopItemList->addActionListener(this);
-
- ContainerPlacer placer;
- placer = getPlacer(0, 0);
-
- if (mIsSell == IsSell_true)
- {
- // TRANSLATORS: sell dialog button
- mIncreaseButton = new Button(this, _("+"), "inc", this);
- // TRANSLATORS: sell dialog button
- mDecreaseButton = new Button(this, _("-"), "dec", this);
- // TRANSLATORS: sell dialog button
- mAddMaxButton = new Button(this, _("Max"), "max", this);
- mSlider = new Slider(this, 1.0, 1.0);
-
- mQuantityLabel = new Label(this, strprintf(
- "%d / %d", mAmountItems, mMaxItems));
- mQuantityLabel->setAlignment(Graphics::CENTER);
- // TRANSLATORS: sell dialog label
- mMoneyLabel = new Label(this, strprintf(_("Price: %s / Total: %s"),
- "", ""));
- if (mAdvanced == Advanced_true)
- {
- // TRANSLATORS: sell dialog button
- mConfirmButton = new Button(this, _("Sell"), "confirm", this);
- mConfirmButton->setEnabled(false);
- }
-
- mDecreaseButton->adjustSize();
- mDecreaseButton->setWidth(mIncreaseButton->getWidth());
- mIncreaseButton->setEnabled(false);
- mDecreaseButton->setEnabled(false);
- mSlider->setEnabled(false);
- mSlider->setActionEventId("slider");
- mSlider->addActionListener(this);
-
- placer(0, 0, mScrollArea, 8, 5).setPadding(3);
- placer(0, 5, mDecreaseButton);
- placer(1, 5, mSlider, 3);
- placer(4, 5, mIncreaseButton);
- placer(5, 5, mQuantityLabel, 2);
- placer(7, 5, mAddMaxButton);
- placer(0, 6, mMoneyLabel, 8);
- if (mAdvanced == Advanced_true)
- {
- placer(5, 7, mSellButton);
- placer(6, 7, mConfirmButton);
- }
- else
- {
- placer(6, 7, mSellButton);
- }
- placer(7, 7, mQuitButton);
- }
- else
- {
- placer(0, 0, mScrollArea, 8, 5).setPadding(3);
- placer(6, 5, mSellButton);
- placer(7, 5, mQuitButton);
- }
-
- Layout &layout = getLayout();
- layout.setRowHeight(0, LayoutType::SET);
-
- center();
- loadWindowState();
-
- instances.push_back(this);
- setVisible(Visible_true);
- enableVisibleSound(true);
-}
-
-SellDialog::~SellDialog()
-{
- delete2(mShopItems);
- instances.remove(this);
-}
-
-void SellDialog::reset()
-{
- mShopItems->clear();
- if (mSlider != nullptr)
- mSlider->setValue(0);
- mShopItemList->setSelected(-1);
- updateButtonsAndLabels();
-}
-
-void SellDialog::addItem(const Item *const item, const int price)
-{
- if (item == nullptr)
- return;
-
- mShopItems->addItem2(item->getInvIndex(),
- item->getId(),
- item->getType(),
- item->getColor(),
- item->getQuantity(),
- price);
-
- mShopItemList->adjustSize();
-}
-
-ShopItem *SellDialog::addItem(const int id,
- const ItemTypeT type,
- const ItemColor color,
- const int amount,
- const int price)
-{
- ShopItem *const item = mShopItems->addItem(id,
- type,
- color,
- amount,
- price);
- mShopItemList->adjustSize();
- return item;
-}
-
-
-void SellDialog::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
-
- if (eventId == "quit")
- {
- close();
- return;
- }
-
- const int selectedItem = mShopItemList->getSelected();
-
- // The following actions require a valid item selection
- if (selectedItem == -1
- || selectedItem >= mShopItems->getNumberOfElements())
- {
- return;
- }
-
- if (eventId == "slider")
- {
- if (mSlider != nullptr)
- {
- mAmountItems = CAST_S32(mSlider->getValue());
- updateButtonsAndLabels();
- }
- }
- else if (eventId == "inc" &&
- mSlider != nullptr &&
- mAmountItems < mMaxItems)
- {
- mAmountItems++;
- mSlider->setValue(mAmountItems);
- updateButtonsAndLabels();
- }
- else if (eventId == "dec" &&
- mSlider != nullptr &&
- mAmountItems > 1)
- {
- mAmountItems--;
- mSlider->setValue(mAmountItems);
- updateButtonsAndLabels();
- }
- else if (eventId == "max" &&
- mSlider != nullptr)
- {
- mAmountItems = mMaxItems;
- mSlider->setValue(mAmountItems);
- updateButtonsAndLabels();
- }
- else if (eventId == "presell" ||
- eventId == "sell" ||
- eventId == "yes" ||
- eventId == "confirm")
- {
- sellAction(event);
- }
-}
-
-void SellDialog::valueChanged(const SelectionEvent &event A_UNUSED)
-{
- // Reset amount of items and update labels
- mAmountItems = 1;
- if (mSlider != nullptr)
- {
- mSlider->setValue(0);
- mSlider->setScale(1, mMaxItems);
- }
- updateButtonsAndLabels();
-}
-
-void SellDialog::setMoney(const int amount)
-{
- mPlayerMoney = amount;
- mShopItemList->setPlayersMoney(amount);
-}
-
-void SellDialog::updateButtonsAndLabels()
-{
- const int selectedItem = mShopItemList->getSelected();
- int income = 0;
- ShopItem *item = nullptr;
-
- if (selectedItem > -1 && (mShopItems->at(selectedItem) != nullptr))
- {
- item = mShopItems->at(selectedItem);
- if (item != nullptr)
- {
- mMaxItems = item->getQuantity();
- if (mAmountItems > mMaxItems)
- mAmountItems = mMaxItems;
- income = mAmountItems * mShopItems->at(selectedItem)->getPrice();
- }
- else
- {
- mMaxItems = 0;
- mAmountItems = 0;
- }
- }
- else
- {
- mMaxItems = 0;
- mAmountItems = 0;
- }
-
- // Update Buttons and slider
- mSellButton->setEnabled(mAmountItems > 0);
- if (mDecreaseButton != nullptr)
- mDecreaseButton->setEnabled(mAmountItems > 1);
- if (mIncreaseButton != nullptr)
- mIncreaseButton->setEnabled(mAmountItems < mMaxItems);
- if (mSlider != nullptr)
- mSlider->setEnabled(mMaxItems > 1);
-
- if (mQuantityLabel != nullptr)
- {
- // Update the quantity and money labels
- mQuantityLabel->setCaption(strprintf("%d / %d",
- mAmountItems, mMaxItems));
- }
- if (mMoneyLabel != nullptr)
- {
- // TRANSLATORS: sell dialog label
- mMoneyLabel->setCaption(strprintf(_("Price: %s / Total: %s"),
- UnitsDb::formatCurrency(income).c_str(),
- UnitsDb::formatCurrency(mPlayerMoney + income).c_str()));
- }
- if (item != nullptr)
- item->update();
-}
-
-void SellDialog::setVisible(Visible visible)
-{
- Window::setVisible(visible);
-
- if (visible == Visible_true)
- {
- if (mShopItemList != nullptr)
- mShopItemList->requestFocus();
- }
- else
- {
- scheduleDelete();
- }
-}
-
-void SellDialog::closeAll()
-{
- FOR_EACH (DialogList::const_iterator, it, instances)
- (*it)->close();
-}
diff --git a/src/gui/widgets/selldialog.h b/src/gui/widgets/selldialog.h
deleted file mode 100644
index e17d3116a..000000000
--- a/src/gui/widgets/selldialog.h
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_SELLDIALOG_H
-#define GUI_WIDGETS_SELLDIALOG_H
-
-#include "enums/resources/item/itemtype.h"
-
-#include "enums/simpletypes/advanced.h"
-#include "enums/simpletypes/issell.h"
-#include "enums/simpletypes/itemcolor.h"
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/selectionlistener.h"
-
-class Button;
-class Item;
-class Label;
-class ScrollArea;
-class ShopItem;
-class ShopItems;
-class ShopListBox;
-class Slider;
-
-/**
- * The sell dialog.
- *
- * \ingroup Interface
- */
-class SellDialog notfinal : public Window,
- public ActionListener,
- private SelectionListener
-{
- public:
- /**
- * Constructor.
- */
- SellDialog(const IsSell isSell,
- const Advanced advanced);
-
- A_DELETE_COPY(SellDialog)
-
- /**
- * Destructor
- */
- ~SellDialog();
-
- /**
- * Resets the dialog, clearing inventory.
- */
- void reset();
-
- /**
- * Adds an item to the inventory.
- */
- void addItem(const Item *const item,
- const int price);
-
- /**
- * Called when receiving actions from the widgets.
- */
- void action(const ActionEvent &event) override final;
-
- /**
- * Updates labels according to selected item.
- *
- * @see SelectionListener::selectionChanged
- */
- void valueChanged(const SelectionEvent &event) override final;
-
- /**
- * Gives Player's Money amount
- */
- void setMoney(const int amount);
-
- /**
- * Sets the visibility of this window.
- */
- void setVisible(Visible visible) override final;
-
- ShopItem *addItem(const int id,
- const ItemTypeT type,
- const ItemColor color,
- const int amount,
- const int price);
-
- /**
- * Returns true if any instances exist.
- */
- static bool isActive() A_WARN_UNUSED
- { return !instances.empty(); }
-
- /**
- * Closes all instances.
- */
- static void closeAll();
-
- void postInit() override;
-
- protected:
- typedef std::list<SellDialog*> DialogList;
- static DialogList instances;
-
- /**
- * Updates the state of buttons and labels.
- */
- void updateButtonsAndLabels();
-
- virtual void sellAction(const ActionEvent &event) = 0;
-
- virtual void initButtons()
- { }
-
- Button *mSellButton A_NONNULLPOINTER;
- Button *mQuitButton A_NONNULLPOINTER;
- Button *mConfirmButton A_NONNULLPOINTER;
- Button *mAddMaxButton;
- Button *mIncreaseButton;
- Button *mDecreaseButton;
- ShopListBox *mShopItemList A_NONNULLPOINTER;
- ScrollArea *mScrollArea A_NONNULLPOINTER;
- Label *mMoneyLabel;
- Label *mQuantityLabel;
- Slider *mSlider;
- ShopItems *mShopItems A_NONNULLPOINTER;
-
- int mPlayerMoney;
- int mMaxItems;
- int mAmountItems;
-
- IsSell mIsSell;
- Advanced mAdvanced;
-};
-
-#endif // GUI_WIDGETS_SELLDIALOG_H
diff --git a/src/gui/widgets/serverslistbox.h b/src/gui/widgets/serverslistbox.h
deleted file mode 100644
index 20d019f8d..000000000
--- a/src/gui/widgets/serverslistbox.h
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_SERVERSLISTBOX_H
-#define GUI_WIDGETS_SERVERSLISTBOX_H
-
-#include "gui/widgets/listbox.h"
-
-#include "gui/models/serverslistmodel.h"
-
-#include "localconsts.h"
-
-class ServersListBox final : public ListBox
-{
- public:
- ServersListBox(const Widget2 *const widget,
- ServersListModel *const model) :
- ListBox(widget, model, "serverslistbox.xml"),
- mNotSupportedColor(getThemeColor(
- ThemeColorId::SERVER_VERSION_NOT_SUPPORTED)),
- mNotSupportedColor2(getThemeColor(
- ThemeColorId::SERVER_VERSION_NOT_SUPPORTED_OUTLINE))
- {
- mHighlightColor = getThemeColor(ThemeColorId::HIGHLIGHT);
- }
-
- A_DELETE_COPY(ServersListBox)
-
- void draw(Graphics *const graphics) override final A_NONNULL(2)
- {
- if (mListModel == nullptr)
- return;
-
- ServersListModel *const model
- = static_cast<ServersListModel *>(mListModel);
-
- updateAlpha();
-
- mHighlightColor.a = CAST_S32(mAlpha * 255.0F);
- graphics->setColor(mHighlightColor);
-
- const int height = getRowHeight();
- mNotSupportedColor.a = CAST_S32(mAlpha * 255.0F);
-
- // Draw filled rectangle around the selected list element
- if (mSelected >= 0)
- {
- graphics->fillRectangle(Rect(mPadding,
- height * mSelected + mPadding,
- getWidth() - 2 * mPadding,
- height));
- }
-
- Font *const font1 = boldFont;
- Font *const font2 = getFont();
- const int fontHeight = font1->getHeight();
- const int pad1 = fontHeight + mPadding;
- const int pad2 = height / 4 + mPadding;
- const int width = getWidth();
- // Draw the list elements
- for (int i = 0, y = 0; i < model->getNumberOfElements();
- ++i, y += height)
- {
- const ServerInfo &info = model->getServer(i);
-
- const Color *color1;
- const Color *color2;
- if (mSelected == i)
- {
- color1 = &mForegroundSelectedColor;
- color2 = &mForegroundSelectedColor2;
- }
- else
- {
- color1 = &mForegroundColor;
- color2 = &mForegroundColor2;
- }
-
- int top;
- int x = mPadding;
-
- if (!info.name.empty())
- {
- x += font1->getWidth(info.name) + 15;
- font1->drawString(graphics,
- *color1,
- *color2,
- info.name,
- mPadding,
- y + mPadding);
- top = y + pad1;
- }
- else
- {
- top = y + pad2;
- }
-
- if (!info.description.empty())
- {
- font2->drawString(graphics,
- *color1,
- *color2,
- info.description,
- x,
- y + mPadding);
- }
- font2->drawString(graphics,
- *color1,
- *color2,
- model->getElementAt(i),
- mPadding,
- top);
-
- if (info.version.first > 0)
- {
- font2->drawString(graphics,
- mNotSupportedColor,
- mNotSupportedColor2,
- info.version.second,
- width - info.version.first - mPadding,
- top);
- }
- }
- }
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2)
- {
- ServersListBox::draw(graphics);
- }
-
- unsigned int getRowHeight() const override final
- {
- return 2 * getFont()->getHeight() + 5;
- }
- private:
- Color mNotSupportedColor;
- Color mNotSupportedColor2;
-};
-
-#endif // GUI_WIDGETS_SERVERSLISTBOX_H
diff --git a/src/gui/widgets/setupbuttonitem.cpp b/src/gui/widgets/setupbuttonitem.cpp
deleted file mode 100644
index 07612f08c..000000000
--- a/src/gui/widgets/setupbuttonitem.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/setupbuttonitem.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/horizontcontainer.h"
-#include "gui/widgets/vertcontainer.h"
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-#include "debug.h"
-
-SetupButtonItem::SetupButtonItem(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict actionEventId,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ActionListener *const listener) :
- SetupItem(text, description, "", parent, eventName, MainConfig_false),
- mHorizont(nullptr),
- mButton(nullptr)
-{
- mValueType = VSTR;
- mWidget = new Button(this, text, actionEventId, listener);
- createControls();
-}
-
-SetupButtonItem::~SetupButtonItem()
-{
- mHorizont = nullptr;
- mWidget = nullptr;
- mButton = nullptr;
-}
-
-void SetupButtonItem::save()
-{
-}
-
-void SetupButtonItem::cancel(const std::string &eventName A_UNUSED)
-{
-}
-
-void SetupButtonItem::externalUpdated(const std::string &eventName A_UNUSED)
-{
-}
-
-void SetupButtonItem::rereadValue()
-{
-}
-
-void SetupButtonItem::createControls()
-{
- mHorizont = new HorizontContainer(this, 32, 2);
-
- // TRANSLATORS: setup item button
- mHorizont->add(mWidget);
-
- mParent->getContainer()->add2(mHorizont, true, 4);
- mParent->addControl(this);
-// mWidget->addActionListener(this);
-}
-
-void SetupButtonItem::fromWidget()
-{
-}
-
-void SetupButtonItem::toWidget()
-{
-}
-
-void SetupButtonItem::action(const ActionEvent &event A_UNUSED)
-{
-}
-
-void SetupButtonItem::apply(const std::string &eventName A_UNUSED)
-{
-}
diff --git a/src/gui/widgets/setupbuttonitem.h b/src/gui/widgets/setupbuttonitem.h
deleted file mode 100644
index b4f99328b..000000000
--- a/src/gui/widgets/setupbuttonitem.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_SETUPBUTTONITEM_H
-#define GUI_WIDGETS_SETUPBUTTONITEM_H
-
-#include "gui/widgets/setupitem.h"
-
-class Button;
-class HorizontContainer;
-class SetupTabScroll;
-
-class SetupButtonItem final : public SetupItem
-{
- public:
- SetupButtonItem(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict actionEventId,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ActionListener *const listener);
-
- A_DELETE_COPY(SetupButtonItem)
-
- ~SetupButtonItem();
-
- void createControls();
-
- void fromWidget() override final A_CONST;
-
- void toWidget() override final A_CONST;
-
- void action(const ActionEvent &event) override final A_CONST;
-
- void apply(const std::string &eventName) override final A_CONST;
-
- void cancel(const std::string &eventName A_UNUSED)
- override final A_CONST;
-
- void externalUpdated(const std::string &eventName A_UNUSED)
- override final A_CONST;
-
- void rereadValue() override final A_CONST;
-
- void save() override final A_CONST;
-
- protected:
- HorizontContainer *mHorizont;
- Button *mButton;
-};
-
-#endif // GUI_WIDGETS_SETUPBUTTONITEM_H
diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp
deleted file mode 100644
index cc6ded02e..000000000
--- a/src/gui/widgets/setupitem.cpp
+++ /dev/null
@@ -1,1338 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/setupitem.h"
-
-#include "configuration.h"
-#include "soundmanager.h"
-
-#include "gui/gui.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/models/listmodel.h"
-
-#include "gui/windows/editdialog.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/checkbox.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/dropdown.h"
-#include "gui/widgets/horizontcontainer.h"
-#include "gui/widgets/inttextfield.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/slider.h"
-#include "gui/widgets/sliderlist.h"
-#include "gui/widgets/vertcontainer.h"
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-#include "utils/base64.h"
-#include "utils/gettext.h"
-#include "utils/stdmove.h"
-#include "utils/mathutils.h"
-
-#include "debug.h"
-
-SetupItem::SetupItem(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const MainConfig mainConfig) :
- ActionListener(),
- Widget2(parent),
- mText(text),
- mDescription(description),
- mKeyName(keyName),
- mParent(parent),
- mEventName(eventName),
- mValue(),
- mDefault(),
- mWidget(nullptr),
- mTempWidgets(),
- mValueType(VBOOL),
- mMainConfig(mainConfig),
- mUseDefault(false)
-{
-}
-
-SetupItem::SetupItem(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const std::string &restrict def,
- const MainConfig mainConfig) :
- ActionListener(),
- Widget2(parent),
- mText(text),
- mDescription(description),
- mKeyName(keyName),
- mParent(parent),
- mEventName(eventName),
- mValue(),
- mDefault(def),
- mWidget(nullptr),
- mTempWidgets(),
- mValueType(VBOOL),
- mMainConfig(mainConfig),
- mUseDefault(true)
-{
-}
-
-SetupItem::~SetupItem()
-{
-}
-
-Configuration *SetupItem::getConfig() const
-{
- if (mMainConfig == MainConfig_true)
- return &config;
- return &serverConfig;
-}
-
-void SetupItem::load()
-{
- if (mKeyName.empty())
- return;
-
- const Configuration *const cfg = getConfig();
- if (mUseDefault)
- {
- mValue = cfg->getValue(mKeyName, mDefault);
- }
- else
- {
- switch (mValueType)
- {
- case VBOOL:
- if (cfg->getBoolValue(mKeyName))
- mValue = "1";
- else
- mValue = "0";
- break;
- case VSTR:
- default:
- mValue = cfg->getStringValue(mKeyName);
- break;
- case VINT:
- mValue = toString(cfg->getIntValue(mKeyName));
- break;
- case VNONE:
- break;
- }
- }
-}
-
-void SetupItem::save()
-{
- if (mKeyName.empty())
- return;
-
- Configuration *const cfg = getConfig();
- cfg->setValue(mKeyName, mValue);
-}
-
-std::string SetupItem::getActionEventId() const
-{
- if (mWidget == nullptr)
- return std::string();
-
- return mWidget->getActionEventId();
-}
-
-void SetupItem::action(const ActionEvent &event)
-{
- if (mWidget == nullptr)
- return;
-
- if (event.getId() == mWidget->getActionEventId())
- doAction();
-}
-
-void SetupItem::doAction()
-{
- fromWidget();
-}
-
-void SetupItem::apply(const std::string &eventName A_UNUSED)
-{
- save();
-}
-
-void SetupItem::cancel(const std::string &eventName A_UNUSED)
-{
- load();
- toWidget();
-}
-
-void SetupItem::externalUpdated(const std::string &eventName A_UNUSED)
-{
- load();
- toWidget();
-}
-
-void SetupItem::externalUnloaded(const std::string &eventName A_UNUSED)
-{
-}
-
-void SetupItem::fixFirstItemSize(Widget *const widget)
-{
- if (widget == nullptr)
- return;
- const int maxSize = mParent->getPreferredFirstItemSize();
- if (widget->getWidth() < maxSize)
- widget->setWidth(maxSize);
-}
-
-void SetupItem::rereadValue()
-{
- load();
- toWidget();
-}
-
-SetupItemCheckBox::SetupItemCheckBox(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, mainConfig),
- mCheckBox(nullptr)
-{
- createControls();
-}
-
-SetupItemCheckBox::SetupItemCheckBox(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const std::string &restrict def,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
- mCheckBox(nullptr)
-{
- createControls();
-}
-
-SetupItemCheckBox::~SetupItemCheckBox()
-{
- mWidget = nullptr;
-}
-
-void SetupItemCheckBox::createControls()
-{
- load();
- mCheckBox = new CheckBox(this, mText, mValue != "0", mParent, mEventName);
- mCheckBox->setToolTip(mDescription);
- mWidget = mCheckBox;
- mParent->getContainer()->add1(mWidget);
- mParent->addControl(this);
- mParent->addActionListener(this);
- mWidget->addActionListener(this);
-}
-
-void SetupItemCheckBox::fromWidget()
-{
- if (mCheckBox == nullptr)
- return;
-
- if (mCheckBox->isSelected())
- mValue = "1";
- else
- mValue = "0";
-}
-
-void SetupItemCheckBox::toWidget()
-{
- if (mCheckBox == nullptr)
- return;
-
- mCheckBox->setSelected(mValue != "0");
-}
-
-
-SetupItemTextField::SetupItemTextField(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const MainConfig mainConfig,
- const UseBase64 useBase64) :
- SetupItem(text, description, keyName, parent, eventName, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mTextField(nullptr),
- mButton(nullptr),
- mEditDialog(nullptr),
- mUseBase64(useBase64)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupItemTextField::SetupItemTextField(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const std::string &restrict def,
- const MainConfig mainConfig,
- const UseBase64 useBase64) :
- SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mTextField(nullptr),
- mButton(nullptr),
- mEditDialog(nullptr),
- mUseBase64(useBase64)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupItemTextField::~SetupItemTextField()
-{
- mHorizont = nullptr;
- mWidget = nullptr;
- mTextField = nullptr;
- mLabel = nullptr;
- mButton = nullptr;
-}
-
-void SetupItemTextField::save()
-{
- if (mUseBase64 == UseBase64_true)
- {
- std::string normalValue = mValue;
- mValue = encodeBase64String(mValue);
- SetupItem::save();
- mValue = STD_MOVE(normalValue);
- }
- else
- {
- SetupItem::save();
- }
-}
-
-void SetupItemTextField::cancel(const std::string &eventName A_UNUSED)
-{
- load();
- if (mUseBase64 == UseBase64_true)
- mValue = decodeBase64String(mValue);
- toWidget();
-}
-
-void SetupItemTextField::externalUpdated(const std::string &eventName A_UNUSED)
-{
- load();
- if (mUseBase64 == UseBase64_true)
- mValue = decodeBase64String(mValue);
- toWidget();
-}
-
-void SetupItemTextField::rereadValue()
-{
- load();
- if (mUseBase64 == UseBase64_true)
- mValue = decodeBase64String(mValue);
- toWidget();
-}
-
-void SetupItemTextField::createControls()
-{
- load();
- if (mUseBase64 == UseBase64_true)
- mValue = decodeBase64String(mValue);
- mHorizont = new HorizontContainer(this, 32, 2);
-
- mLabel = new Label(this, mText);
- mLabel->setToolTip(mDescription);
- mTextField = new TextField(this,
- mValue,
- LoseFocusOnTab_true,
- mParent,
- mEventName);
- // TRANSLATORS: setup item button
- mButton = new Button(this, _("Edit"), mEventName + "_EDIT", mParent);
- mWidget = mTextField;
- mTextField->setWidth(200);
- fixFirstItemSize(mLabel);
- mHorizont->add(mLabel);
- mHorizont->add(mTextField);
- mHorizont->add(mButton);
-
- mParent->getContainer()->add2(mHorizont, true, 4);
- mParent->addControl(this);
- mParent->addControl(this, mEventName + "_EDIT");
- mParent->addControl(this, mEventName + "_EDIT_OK");
- mParent->addActionListener(this);
- mWidget->addActionListener(this);
- mButton->addActionListener(this);
-}
-
-void SetupItemTextField::fromWidget()
-{
- if (mTextField == nullptr)
- return;
-
- mValue = mTextField->getText();
-}
-
-void SetupItemTextField::toWidget()
-{
- if (mTextField == nullptr)
- return;
-
- mTextField->setText(mValue);
-}
-
-void SetupItemTextField::action(const ActionEvent &event)
-{
- if (mTextField == nullptr)
- return;
-
- const std::string &eventId = event.getId();
- if ((mWidget != nullptr) && eventId == mWidget->getActionEventId())
- {
- fromWidget();
- }
- else if (eventId == mEventName + "_EDIT")
- {
- mEditDialog = CREATEWIDGETR(EditDialog,
- mText,
- mTextField->getText(),
- mEventName + "_EDIT_OK");
- mEditDialog->addActionListener(this);
- }
- else if (eventId == mEventName + "_EDIT_OK")
- {
- mTextField->setText(mEditDialog->getMsg());
- mEditDialog = nullptr;
- }
-}
-
-void SetupItemTextField::apply(const std::string &eventName)
-{
- if (eventName != mEventName)
- return;
-
- fromWidget();
- save();
-}
-
-SetupItemIntTextField::SetupItemIntTextField(const std::string &restrict text,
- const std::string &restrict
- description,
- const std::string &restrict
- keyName,
- SetupTabScroll *restrict
- const parent,
- const std::string &restrict
- eventName,
- const int min, const int max,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mTextField(nullptr),
- mButton(nullptr),
- mEditDialog(nullptr),
- mMin(min),
- mMax(max)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupItemIntTextField::SetupItemIntTextField(const std::string &restrict text,
- const std::string &restrict
- description,
- const std::string &restrict
- keyName,
- SetupTabScroll *restrict
- const parent,
- const std::string &restrict
- eventName,
- const int min, const int max,
- const std::string &restrict def,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mTextField(nullptr),
- mButton(nullptr),
- mEditDialog(nullptr),
- mMin(min),
- mMax(max)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupItemIntTextField::~SetupItemIntTextField()
-{
- mHorizont = nullptr;
- mWidget = nullptr;
- mTextField = nullptr;
- mLabel = nullptr;
- mButton = nullptr;
-}
-
-void SetupItemIntTextField::createControls()
-{
- load();
- mHorizont = new HorizontContainer(this, 32, 2);
-
- mLabel = new Label(this, mText);
- mLabel->setToolTip(mDescription);
- mTextField = new IntTextField(this, atoi(mValue.c_str()),
- mMin, mMax, Enable_true, 30);
- mTextField->setActionEventId(mEventName);
- mTextField->addActionListener(mParent);
-
- // TRANSLATORS: setup item button
- mButton = new Button(this, _("Edit"), mEventName + "_EDIT", mParent);
- mWidget = mTextField;
- mTextField->setWidth(50);
- fixFirstItemSize(mLabel);
- mHorizont->add(mLabel);
- mHorizont->add(mTextField);
- mHorizont->add(mButton);
-
- mParent->getContainer()->add2(mHorizont, true, 4);
- mParent->addControl(this);
- mParent->addControl(this, mEventName + "_EDIT");
- mParent->addControl(this, mEventName + "_EDIT_OK");
- mParent->addActionListener(this);
- mWidget->addActionListener(this);
- mButton->addActionListener(this);
-}
-
-void SetupItemIntTextField::fromWidget()
-{
- if (mTextField == nullptr)
- return;
-
- mValue = mTextField->getText();
-}
-
-void SetupItemIntTextField::toWidget()
-{
- if (mTextField == nullptr)
- return;
-
- mTextField->setText(mValue);
-}
-
-void SetupItemIntTextField::action(const ActionEvent &event)
-{
- if (mTextField == nullptr)
- return;
-
- const std::string &eventId = event.getId();
- if ((mWidget != nullptr) && eventId == mWidget->getActionEventId())
- {
- fromWidget();
- }
- else if (eventId == mEventName + "_EDIT")
- {
- mEditDialog = CREATEWIDGETR(EditDialog,
- mText,
- mTextField->getText(),
- mEventName + "_EDIT_OK");
- mEditDialog->addActionListener(this);
- }
- else if (eventId == mEventName + "_EDIT_OK")
- {
- mTextField->setValue(atoi(mEditDialog->getMsg().c_str()));
- mEditDialog = nullptr;
- }
-}
-
-void SetupItemIntTextField::apply(const std::string &eventName)
-{
- if (eventName != mEventName)
- return;
-
- fromWidget();
- save();
-}
-
-
-SetupItemLabel::SetupItemLabel(const std::string &restrict text,
- const std::string &restrict description,
- SetupTabScroll *restrict const parent,
- const Separator separator) :
- SetupItem(text, description, "", parent, "", "", MainConfig_true),
- mLabel(nullptr),
- mIsSeparator(separator)
-{
- mValueType = VNONE;
- createControls();
-}
-
-SetupItemLabel::~SetupItemLabel()
-{
- mWidget = nullptr;
- mLabel = nullptr;
-}
-
-void SetupItemLabel::createControls()
-{
- if (mIsSeparator == Separator_true)
- {
- const std::string str(" \342\200\225\342\200\225\342\200\225"
- "\342\200\225\342\200\225 ");
- mLabel = new Label(this, std::string(str).append(mText).append(str));
- }
- else
- {
- mLabel = new Label(this, mText);
- }
- mLabel->setToolTip(mDescription);
-
- mWidget = mLabel;
- mParent->getContainer()->add1(mWidget);
- mParent->addControl(this);
- mParent->addActionListener(this);
- mWidget->addActionListener(this);
-}
-
-void SetupItemLabel::fromWidget()
-{
-}
-
-void SetupItemLabel::toWidget()
-{
-}
-
-void SetupItemLabel::action(const ActionEvent &event A_UNUSED)
-{
-}
-
-void SetupItemLabel::apply(const std::string &eventName A_UNUSED)
-{
-}
-
-
-SetupItemDropDown::SetupItemDropDown(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const int width,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mModel(model),
- mDropDown(nullptr),
- mWidth(width)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupItemDropDown::SetupItemDropDown(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const int width,
- const std::string &restrict def,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mModel(model),
- mDropDown(nullptr),
- mWidth(width)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupItemDropDown::~SetupItemDropDown()
-{
- mHorizont = nullptr;
- mWidget = nullptr;
- mModel = nullptr;
- mDropDown = nullptr;
- mLabel = nullptr;
-}
-
-void SetupItemDropDown::createControls()
-{
- load();
- mHorizont = new HorizontContainer(this, 32, 2);
-
- mLabel = new Label(this, mText);
- mLabel->setToolTip(mDescription);
- mDropDown = new DropDown(this, mModel);
- mDropDown->setActionEventId(mEventName);
- mDropDown->addActionListener(mParent);
- mDropDown->setWidth(mWidth);
- mDropDown->setSelected(selectionByValue());
-
- mWidget = mDropDown;
- if (!mText.empty())
- fixFirstItemSize(mLabel);
- mHorizont->add(mLabel);
- mHorizont->add(mDropDown);
-
- mParent->getContainer()->add2(mHorizont, true, 4);
- mParent->addControl(this);
- mParent->addActionListener(this);
- mWidget->addActionListener(this);
-}
-
-int SetupItemDropDown::selectionByValue()
-{
- return atoi(mValue.c_str());
-}
-
-void SetupItemDropDown::fromWidget()
-{
- if (mDropDown == nullptr)
- return;
-
- mValue = toString(mDropDown->getSelected());
-}
-
-void SetupItemDropDown::toWidget()
-{
- if (mDropDown == nullptr)
- return;
-
- mDropDown->setSelected(selectionByValue());
-}
-
-
-SetupItemDropDownStr::SetupItemDropDownStr(const std::string &restrict text,
- const std::string &restrict
- description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const
- parent,
- const std::string &restrict
- eventName,
- ListModel *restrict const model,
- const int width,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mModel(model),
- mDropDown(nullptr),
- mWidth(width)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupItemDropDownStr::SetupItemDropDownStr(const std::string &restrict text,
- const std::string &restrict
- description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const
- parent,
- const std::string &restrict
- eventName,
- ListModel *restrict const model,
- const int width,
- const std::string &restrict def,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mModel(model),
- mDropDown(nullptr),
- mWidth(width)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupItemDropDownStr::~SetupItemDropDownStr()
-{
- mHorizont = nullptr;
- mWidget = nullptr;
- mModel = nullptr;
- mDropDown = nullptr;
- mLabel = nullptr;
-}
-
-void SetupItemDropDownStr::createControls()
-{
- load();
- mHorizont = new HorizontContainer(this, 32, 2);
-
- mLabel = new Label(this, mText);
- mLabel->setToolTip(mDescription);
- mDropDown = new DropDown(this, mModel);
- mDropDown->setActionEventId(mEventName);
- mDropDown->addActionListener(mParent);
- mDropDown->setWidth(mWidth);
- mDropDown->setSelected(selectionByValue());
-
- mWidget = mDropDown;
- if (!mText.empty())
- fixFirstItemSize(mLabel);
- mHorizont->add(mLabel);
- mHorizont->add(mDropDown);
-
- mParent->getContainer()->add2(mHorizont, true, 4);
- mParent->addControl(this);
- mParent->addActionListener(this);
- mWidget->addActionListener(this);
-}
-
-int SetupItemDropDownStr::selectionByValue()
-{
- const int sz = mModel->getNumberOfElements();
- for (int f = 0; f < sz; f ++)
- {
- if (mModel->getElementAt(f) == mValue)
- {
- return f;
- }
- }
- return 0;
-}
-
-void SetupItemDropDownStr::fromWidget()
-{
- if (mDropDown == nullptr)
- return;
-
- const int sel = mDropDown->getSelected();
- // use first element in model as empty string
- if (sel == 0 || sel >= mModel->getNumberOfElements())
- mValue.clear();
- else
- mValue = mModel->getElementAt(sel);
-}
-
-void SetupItemDropDownStr::toWidget()
-{
- if (mDropDown == nullptr)
- return;
-
- mDropDown->setSelected(selectionByValue());
-}
-
-
-SetupItemSlider::SetupItemSlider(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const double min,
- const double max,
- const double step,
- const int width,
- const OnTheFly onTheFly,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mSlider(nullptr),
- mMin(min),
- mMax(max),
- mStep(step),
- mWidth(width),
- mOnTheFly(onTheFly)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupItemSlider::SetupItemSlider(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const double min,
- const double max,
- const double step,
- const std::string &restrict def,
- const int width,
- const OnTheFly onTheFly,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mSlider(nullptr),
- mMin(min),
- mMax(max),
- mStep(step),
- mWidth(width),
- mOnTheFly(onTheFly)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupItemSlider::~SetupItemSlider()
-{
- mHorizont = nullptr;
- mWidget = nullptr;
- mSlider = nullptr;
- mLabel = nullptr;
-}
-
-void SetupItemSlider::createControls()
-{
- load();
- mHorizont = new HorizontContainer(this, 32, 2);
-
- mLabel = new Label(this, mText);
- mLabel->setToolTip(mDescription);
- mSlider = new Slider(this, mMin, mMax, mStep);
- mSlider->setActionEventId(mEventName);
- mSlider->addActionListener(mParent);
- mSlider->setValue(atof(mValue.c_str()));
- mSlider->setHeight(30);
-
- mWidget = mSlider;
- mSlider->setWidth(mWidth);
- mSlider->setHeight(40);
- fixFirstItemSize(mLabel);
- mHorizont->add(mLabel);
- mHorizont->add(mSlider, -10);
-
- mParent->getContainer()->add2(mHorizont, true, 4);
- mParent->addControl(this);
- mParent->addActionListener(this);
- mWidget->addActionListener(this);
-}
-
-void SetupItemSlider::fromWidget()
-{
- if (mSlider == nullptr)
- return;
-
- mValue = toString(mSlider->getValue());
-}
-
-void SetupItemSlider::toWidget()
-{
- if (mSlider == nullptr)
- return;
-
- mSlider->setValue(atof(mValue.c_str()));
-}
-
-void SetupItemSlider::action(const ActionEvent &event A_UNUSED)
-{
- fromWidget();
- if (mOnTheFly == OnTheFly_true)
- save();
-}
-
-void SetupItemSlider::apply(const std::string &eventName)
-{
- if (eventName != mEventName)
- return;
-
- fromWidget();
- save();
-}
-
-
-SetupItemSlider2::SetupItemSlider2(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const int min,
- const int max,
- const int step,
- SetupItemNames *restrict const values,
- const OnTheFly onTheFly,
- const MainConfig mainConfig,
- const DoNotAlign doNotAlign) :
- SetupItem(text, description, keyName, parent, eventName, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mLabel2(nullptr),
- mSlider(nullptr),
- mValues(values),
- mMin(min),
- mMax(max),
- mStep(step),
- mInvertValue(0),
- mInvert(false),
- mOnTheFly(onTheFly),
- mDoNotAlign(doNotAlign)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupItemSlider2::SetupItemSlider2(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const int min,
- const int max,
- const int step,
- SetupItemNames *restrict const values,
- const std::string &restrict def,
- const OnTheFly onTheFly,
- const MainConfig mainConfig,
- const DoNotAlign doNotAlign) :
- SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mLabel2(nullptr),
- mSlider(nullptr),
- mValues(values),
- mMin(min),
- mMax(max),
- mStep(step),
- mInvertValue(0),
- mInvert(false),
- mOnTheFly(onTheFly),
- mDoNotAlign(doNotAlign)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupItemSlider2::~SetupItemSlider2()
-{
- mHorizont = nullptr;
- mWidget = nullptr;
- mSlider = nullptr;
- mLabel = nullptr;
-}
-
-void SetupItemSlider2::createControls()
-{
- load();
- mHorizont = new HorizontContainer(this, 32, 2);
-
- const int width = getMaxWidth();
-
- mLabel = new Label(this, mText);
- mLabel->setToolTip(mDescription);
- mLabel2 = new Label(this, "");
- mLabel2->setWidth(width);
- mSlider = new Slider(this, mMin, mMax, mStep);
- mSlider->setActionEventId(mEventName);
- mSlider->addActionListener(mParent);
- mSlider->setValue(atof(mValue.c_str()));
- mSlider->setHeight(30);
-
- mWidget = mSlider;
- mSlider->setWidth(150);
- mSlider->setHeight(40);
- if (mDoNotAlign == DoNotAlign_false)
- fixFirstItemSize(mLabel);
- mHorizont->add(mLabel);
- mHorizont->add(mSlider, -10);
- mHorizont->add(mLabel2);
-
- mParent->getContainer()->add2(mHorizont, true, 4);
- mParent->addControl(this);
- mParent->addActionListener(this);
- mWidget->addActionListener(this);
- updateLabel();
-}
-
-int SetupItemSlider2::getMaxWidth()
-{
- if ((mValues == nullptr) || (gui == nullptr))
- return 1;
-
- int maxWidth = 0;
- SetupItemNamesConstIter it = mValues->begin();
- const SetupItemNamesConstIter it_end = mValues->end();
- const Font *const font = gui->getFont();
-
- while (it != it_end)
- {
- const int w = font->getWidth(*it);
- if (w > maxWidth)
- maxWidth = w;
-
- ++ it;
- }
- return maxWidth;
-}
-
-void SetupItemSlider2::fromWidget()
-{
- if (mSlider == nullptr)
- return;
-
- int val = roundDouble(mSlider->getValue());
- if (mInvert)
- val = mInvertValue - val;
- mValue = toString(val);
-}
-
-void SetupItemSlider2::toWidget()
-{
- if (mSlider == nullptr)
- return;
-
- int val = roundDouble(atof(mValue.c_str()));
- if (mInvert)
- val = mInvertValue - val;
- mSlider->setValue(val);
- updateLabel();
-}
-
-void SetupItemSlider2::action(const ActionEvent &event A_UNUSED)
-{
- fromWidget();
- updateLabel();
- if (mOnTheFly == OnTheFly_true)
- save();
-}
-
-void SetupItemSlider2::updateLabel()
-{
- int val = CAST_S32(mSlider->getValue()) - mMin;
- if (val < 0)
- {
- val = 0;
- }
- else
- {
- const int sz = CAST_S32(mValues->size());
- if (val >= sz)
- val = sz - 1;
- }
- std::string str = mValues->at(val);
- mLabel2->setCaption(str);
-}
-
-void SetupItemSlider2::apply(const std::string &eventName)
-{
- if (eventName != mEventName)
- return;
-
- fromWidget();
- save();
-}
-
-void SetupItemSlider2::setInvertValue(const int v)
-{
- mInvert = true;
- mInvertValue = v;
- toWidget();
-}
-
-
-SetupItemSliderList::SetupItemSliderList(const std::string &restrict text,
- const std::string &restrict
- description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const int width,
- const OnTheFly onTheFly,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mSlider(nullptr),
- mModel(model),
- mWidth(width),
- mOnTheFly(onTheFly)
-{
- mValueType = VSTR;
-}
-
-SetupItemSliderList::SetupItemSliderList(const std::string &restrict text,
- const std::string &restrict
- description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const std::string &restrict def,
- const int width,
- const OnTheFly onTheFly,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mSlider(nullptr),
- mModel(model),
- mWidth(width),
- mOnTheFly(onTheFly)
-{
- mValueType = VSTR;
-}
-
-SetupItemSliderList::~SetupItemSliderList()
-{
- mHorizont = nullptr;
- mWidget = nullptr;
- mSlider = nullptr;
- mLabel = nullptr;
-}
-
-void SetupItemSliderList::createControls()
-{
- load();
- mHorizont = new HorizontContainer(this, 32, 2);
-
- mLabel = new Label(this, mText);
- mLabel->setToolTip(mDescription);
- mSlider = new SliderList(this, mModel);
- mSlider->postInit2(mParent, mEventName);
- mSlider->setSelectedString(mValue);
- mSlider->adjustSize();
-
- mWidget = mSlider;
- fixFirstItemSize(mLabel);
- mHorizont->add(mLabel, 5);
- mHorizont->add(mSlider);
-
- addMoreControls();
-
- mParent->getContainer()->add2(mHorizont, true, 4);
- mParent->addControl(this);
- mParent->addActionListener(this);
- mWidget->addActionListener(this);
-}
-
-void SetupItemSliderList::fromWidget()
-{
- if (mSlider == nullptr)
- return;
-
- mValue = mSlider->getSelectedString();
-}
-
-void SetupItemSliderList::toWidget()
-{
- if (mSlider == nullptr)
- return;
-
- mSlider->setSelectedString(mValue);
-}
-
-void SetupItemSliderList::action(const ActionEvent &event A_UNUSED)
-{
- fromWidget();
- if (mOnTheFly == OnTheFly_true)
- save();
-}
-
-void SetupItemSliderList::apply(const std::string &eventName)
-{
- if (eventName != mEventName)
- return;
-
- fromWidget();
- save();
-}
-
-SetupItemSound::SetupItemSound(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const int width,
- const OnTheFly onTheFly,
- const MainConfig mainConfig) :
- SetupItemSliderList(text, description, keyName, parent, eventName,
- model, width, onTheFly, mainConfig),
- mButton(nullptr)
-{
- createControls();
-}
-
-void SetupItemSound::addMoreControls()
-{
- mButton = new Button(this, BUTTON_PLAY, 16, 16,
- mEventName + "_PLAY", this);
- if (mHorizont != nullptr)
- mHorizont->add(mButton);
-}
-
-void SetupItemSound::action(const ActionEvent &event)
-{
- if (event.getId() == mEventName + "_PLAY")
- {
- if ((mSlider != nullptr) && (mSlider->getSelected() != 0))
- {
- soundManager.playGuiSfx(pathJoin(branding.getStringValue(
- "systemsounds"),
- mSlider->getSelectedString()).append(".ogg"));
- }
- }
- else
- {
- SetupItemSliderList::action(event);
- }
-}
-
-SetupItemSliderInt::SetupItemSliderInt(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const int min,
- const int width,
- const OnTheFly onTheFly,
- const MainConfig mainConfig) :
- SetupItemSliderList(text, description, keyName, parent, eventName,
- model, width, onTheFly, mainConfig),
- mMin(min)
-{
- createControls();
-}
-
-void SetupItemSliderInt::addMoreControls()
-{
- toWidget();
-}
-
-void SetupItemSliderInt::fromWidget()
-{
- if (mSlider == nullptr)
- return;
-
- mValue = toString(mSlider->getSelected() + mMin);
-}
-
-void SetupItemSliderInt::toWidget()
-{
- if (mSlider == nullptr)
- return;
-
- mSlider->setSelected(atoi(mValue.c_str()) - mMin);
-}
diff --git a/src/gui/widgets/setupitem.h b/src/gui/widgets/setupitem.h
deleted file mode 100644
index eec63a4bc..000000000
--- a/src/gui/widgets/setupitem.h
+++ /dev/null
@@ -1,613 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_SETUPITEM_H
-#define GUI_WIDGETS_SETUPITEM_H
-
-#include "enums/simpletypes/donotalign.h"
-#include "enums/simpletypes/mainconfig.h"
-#include "enums/simpletypes/onthefly.h"
-#include "enums/simpletypes/usebase64.h"
-#include "enums/simpletypes/separator.h"
-
-#include "gui/widgets/widget2.h"
-
-#include "listeners/actionlistener.h"
-
-#include <list>
-
-class Button;
-class CheckBox;
-class Configuration;
-class DropDown;
-class EditDialog;
-class HorizontContainer;
-class IntTextField;
-class Label;
-class ListModel;
-class SetupTabScroll;
-class Slider;
-class SliderList;
-class TextField;
-
-class SetupItem notfinal : public ActionListener,
- public Widget2
-{
- public:
- enum
- {
- VBOOL = 0,
- VSTR,
- VINT,
- VNONE
- };
-
- A_DELETE_COPY(SetupItem)
-
- virtual ~SetupItem();
-
- void load();
-
- virtual void save();
-
- virtual void fromWidget() = 0;
-
- virtual void toWidget() = 0;
-
- void setWidget(Widget *widget)
- { mWidget = widget; }
-
- Widget *getWidget() const noexcept2 A_WARN_UNUSED
- { return mWidget; }
-
- Configuration *getConfig() const RETURNS_NONNULL A_WARN_UNUSED;
-
- virtual std::string getActionEventId() const A_WARN_UNUSED;
-
- void action(const ActionEvent &event) override;
-
- virtual void doAction();
-
- virtual void apply(const std::string &eventName);
-
- virtual void cancel(const std::string &eventName);
-
- virtual void externalUpdated(const std::string &eventName);
-
- virtual void externalUnloaded(const std::string &eventName) A_CONST;
-
- MainConfig isMainConfig() const noexcept2 A_WARN_UNUSED
- { return mMainConfig; }
-
- void fixFirstItemSize(Widget *const widget);
-
- virtual void rereadValue();
-
- void setValue(const std::string &str) noexcept2
- { mValue = str; }
-
- std::string getValue() const noexcept2
- { return mValue; }
-
- std::string getEventName() const noexcept2
- { return mEventName; }
-
- protected:
- SetupItem(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const MainConfig mainConfig);
-
- SetupItem(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const std::string &def,
- const MainConfig mainConfig);
-
- std::string mText;
-
- std::string mDescription;
-
- std::string mKeyName;
-
- SetupTabScroll *mParent;
-
- std::string mEventName;
-
- std::string mValue;
-
- std::string mDefault;
-
- Widget *mWidget;
-
- std::list<Widget*> mTempWidgets;
-
- int mValueType;
-
- MainConfig mMainConfig;
-
- bool mUseDefault;
-};
-
-class SetupItemCheckBox final : public SetupItem
-{
- public:
- SetupItemCheckBox(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const MainConfig mainConfig = MainConfig_true);
-
- SetupItemCheckBox(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const std::string &restrict def,
- const MainConfig mainConfig = MainConfig_true);
-
- A_DELETE_COPY(SetupItemCheckBox)
-
- ~SetupItemCheckBox();
-
- void createControls();
-
- void fromWidget() override final;
-
- void toWidget() override final;
-
- protected:
- CheckBox *mCheckBox;
-};
-
-class SetupItemTextField final : public SetupItem
-{
- public:
- SetupItemTextField(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const MainConfig mainConfig = MainConfig_true,
- const UseBase64 useBase64 = UseBase64_false);
-
- SetupItemTextField(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const std::string &restrict def,
- const MainConfig mainConfig = MainConfig_true,
- const UseBase64 useBase64 = UseBase64_false);
-
- A_DELETE_COPY(SetupItemTextField)
-
- ~SetupItemTextField();
-
- void createControls();
-
- void fromWidget() override final;
-
- void toWidget() override final;
-
- void action(const ActionEvent &event) override final;
-
- void apply(const std::string &eventName) override final;
-
- void cancel(const std::string &eventName A_UNUSED) override final;
-
- void externalUpdated(const std::string &eventName A_UNUSED)
- override final;
-
- void rereadValue() override final;
-
- void save() override final;
-
- void setUseBase64(const UseBase64 b)
- { mUseBase64 = b; }
-
- protected:
- HorizontContainer *mHorizont;
- Label *mLabel;
- TextField *mTextField;
- Button *mButton;
- EditDialog *mEditDialog;
- UseBase64 mUseBase64;
-};
-
-class SetupItemIntTextField final : public SetupItem
-{
- public:
- SetupItemIntTextField(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const int min, const int max,
- const MainConfig mainConfig = MainConfig_true);
-
- SetupItemIntTextField(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const int min, const int max,
- const std::string &restrict def,
- const MainConfig mainConfig = MainConfig_true);
-
- A_DELETE_COPY(SetupItemIntTextField)
-
- ~SetupItemIntTextField();
-
- void createControls();
-
- void fromWidget() override final;
-
- void toWidget() override final;
-
- void action(const ActionEvent &event) override final;
-
- void apply(const std::string &eventName) override final;
-
- protected:
- HorizontContainer *mHorizont;
- Label *mLabel;
- IntTextField *mTextField;
- Button *mButton;
- EditDialog *mEditDialog;
- int mMin;
- int mMax;
-};
-
-class SetupItemLabel final : public SetupItem
-{
- public:
- SetupItemLabel(const std::string &restrict text,
- const std::string &restrict description,
- SetupTabScroll *restrict const parent,
- const Separator separator = Separator_true);
-
- A_DELETE_COPY(SetupItemLabel)
-
- ~SetupItemLabel();
-
- void createControls();
-
- void fromWidget() override final A_CONST;
-
- void toWidget() override final A_CONST;
-
- void action(const ActionEvent &event) override final A_CONST;
-
- void apply(const std::string &eventName) override final A_CONST;
-
- protected:
- Label *mLabel;
- Separator mIsSeparator;
-};
-
-class SetupItemDropDown final : public SetupItem
-{
- public:
- SetupItemDropDown(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const int width,
- const MainConfig mainConfig = MainConfig_true);
-
- SetupItemDropDown(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const int width,
- const std::string &restrict def,
- const MainConfig mainConfig = MainConfig_true);
-
- A_DELETE_COPY(SetupItemDropDown)
-
- ~SetupItemDropDown();
-
- void createControls();
-
- void fromWidget() override final;
-
- void toWidget() override final;
-
- int selectionByValue();
-
- protected:
- HorizontContainer *mHorizont;
- Label *mLabel;
- ListModel *mModel;
- DropDown *mDropDown;
- int mWidth;
-};
-
-class SetupItemDropDownStr final : public SetupItem
-{
- public:
- SetupItemDropDownStr(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const int width,
- const MainConfig mainConfig = MainConfig_true);
-
- SetupItemDropDownStr(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const int width,
- const std::string &restrict def,
- const MainConfig mainConfig = MainConfig_true);
-
- A_DELETE_COPY(SetupItemDropDownStr)
-
- ~SetupItemDropDownStr();
-
- void createControls();
-
- void fromWidget() override final;
-
- void toWidget() override final;
-
- int selectionByValue();
-
- protected:
- HorizontContainer *mHorizont;
- Label *mLabel;
- ListModel *mModel;
- DropDown *mDropDown;
- int mWidth;
-};
-
-class SetupItemSlider final : public SetupItem
-{
- public:
- SetupItemSlider(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const double min,
- const double max,
- const double step,
- const int width,
- const OnTheFly onTheFly,
- const MainConfig mainConfig);
-
- SetupItemSlider(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const double min,
- const double max,
- const double step,
- const std::string &restrict def,
- const int width,
- const OnTheFly onTheFly,
- const MainConfig mainConfig);
-
- A_DELETE_COPY(SetupItemSlider)
-
- ~SetupItemSlider();
-
- void createControls();
-
- void fromWidget() override final;
-
- void toWidget() override final;
-
- void action(const ActionEvent &event) override final;
-
- void apply(const std::string &eventName) override final;
-
- void updateLabel();
-
- protected:
- HorizontContainer *mHorizont;
- Label *mLabel;
- Slider *mSlider;
- double mMin;
- double mMax;
- double mStep;
- int mWidth;
- OnTheFly mOnTheFly;
-};
-
-typedef STD_VECTOR<std::string> SetupItemNames;
-typedef SetupItemNames::iterator SetupItemNamesIter;
-typedef SetupItemNames::const_iterator SetupItemNamesConstIter;
-
-class SetupItemSlider2 final : public SetupItem
-{
- public:
- SetupItemSlider2(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const int min, const int max, const int step,
- SetupItemNames *restrict const values,
- const OnTheFly onTheFly,
- const MainConfig mainConfig,
- const DoNotAlign doNotAlign);
-
- SetupItemSlider2(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const int min, const int max, const int step,
- SetupItemNames *restrict const values,
- const std::string &restrict def,
- const OnTheFly onTheFly,
- const MainConfig mainConfig,
- const DoNotAlign doNotAlign);
-
- A_DELETE_COPY(SetupItemSlider2)
-
- ~SetupItemSlider2();
-
- void createControls();
-
- void fromWidget() override final;
-
- void toWidget() override final;
-
- void action(const ActionEvent &event) override final;
-
- void apply(const std::string &eventName) override final;
-
- void setInvertValue(const int v);
-
- protected:
- void updateLabel();
-
- int getMaxWidth();
-
- HorizontContainer *mHorizont;
- Label *mLabel;
- Label *mLabel2;
- Slider *mSlider;
- SetupItemNames *mValues;
- int mMin;
- int mMax;
- int mStep;
- int mInvertValue;
- bool mInvert;
- OnTheFly mOnTheFly;
- DoNotAlign mDoNotAlign;
-};
-
-class SetupItemSliderList notfinal : public SetupItem
-{
- public:
- A_DELETE_COPY(SetupItemSliderList)
-
- virtual ~SetupItemSliderList();
-
- void createControls();
-
- void fromWidget() override;
-
- void toWidget() override;
-
- void action(const ActionEvent &event) override;
-
- void apply(const std::string &eventName) override final;
-
- virtual void addMoreControls() = 0;
-
- protected:
- SetupItemSliderList(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const int width = 150,
- const OnTheFly onTheFly = OnTheFly_false,
- const MainConfig mainConfig = MainConfig_true);
-
- SetupItemSliderList(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const std::string &restrict def,
- const int width = 150,
- const OnTheFly onTheFly = OnTheFly_false,
- const MainConfig mainConfig = MainConfig_true);
-
- HorizontContainer *mHorizont;
- Label *mLabel;
- SliderList *mSlider;
- ListModel *mModel;
- int mWidth;
- OnTheFly mOnTheFly;
-};
-
-class SetupItemSound final : public SetupItemSliderList
-{
- public:
- SetupItemSound(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const int width = 150,
- const OnTheFly onTheFly = OnTheFly_false,
- const MainConfig mainConfig = MainConfig_true);
-
- A_DELETE_COPY(SetupItemSound)
-
- void action(const ActionEvent &event) override final;
-
- void addMoreControls() override final;
-
- protected:
- Button *mButton;
-};
-
-class SetupItemSliderInt final : public SetupItemSliderList
-{
- public:
- SetupItemSliderInt(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const int min,
- const int width = 150,
- const OnTheFly onTheFly = OnTheFly_false,
- const MainConfig mainConfig = MainConfig_true);
-
- A_DELETE_COPY(SetupItemSliderInt)
-
- void addMoreControls() override final;
-
- void fromWidget() override final;
-
- void toWidget() override final;
-
- protected:
- int mMin;
-};
-
-#endif // GUI_WIDGETS_SETUPITEM_H
diff --git a/src/gui/widgets/setupquickitem.cpp b/src/gui/widgets/setupquickitem.cpp
deleted file mode 100644
index 238a8a213..000000000
--- a/src/gui/widgets/setupquickitem.cpp
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/setupquickitem.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/horizontcontainer.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/vertcontainer.h"
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-#include "debug.h"
-
-SetupQuickItem::SetupQuickItem(const std::string &restrict description,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const ModifierGetFuncPtr getFunc,
- const ModifierChangeFuncPtr changeFunc) :
- SetupItem("", description, "", parent, eventName, MainConfig_false),
- GameModifierListener(),
- mHorizont(nullptr),
- mButton(nullptr),
- mLabel(nullptr),
- mGetFunc(getFunc),
- mChangeFunc(changeFunc)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupQuickItem::~SetupQuickItem()
-{
- mHorizont = nullptr;
- mWidget = nullptr;
- mButton = nullptr;
-}
-
-void SetupQuickItem::save()
-{
-}
-
-void SetupQuickItem::cancel(const std::string &eventName A_UNUSED)
-{
-}
-
-void SetupQuickItem::externalUpdated(const std::string &eventName A_UNUSED)
-{
-}
-
-void SetupQuickItem::rereadValue()
-{
-}
-
-void SetupQuickItem::createControls()
-{
- mHorizont = new HorizontContainer(this, 32, 2);
-
- mWidget = new Button(this, ">", mEventName + "_CHANGE", nullptr);
- mLabel = new Label(this, std::string());
- mLabel->setToolTip(mDescription);
- mLabel->adjustSize();
-
- mHorizont->add(mWidget, 5);
- mHorizont->add(mLabel);
-
- mParent->getContainer()->add2(mHorizont, true, 4);
- mParent->addControl(this);
- mWidget->addActionListener(this);
- toWidget();
-}
-
-void SetupQuickItem::fromWidget()
-{
-}
-
-void SetupQuickItem::toWidget()
-{
- mLabel->setCaption(mGetFunc());
- mLabel->adjustSize();
-}
-
-void SetupQuickItem::action(const ActionEvent &event)
-{
- if (event.getId() == mEventName + "_CHANGE")
- {
- // need change game modifier
- mChangeFunc(true);
- toWidget();
- }
-}
-
-void SetupQuickItem::apply(const std::string &eventName A_UNUSED)
-{
-}
-
-void SetupQuickItem::gameModifiersChanged()
-{
- toWidget();
-}
diff --git a/src/gui/widgets/setupquickitem.h b/src/gui/widgets/setupquickitem.h
deleted file mode 100644
index 24a9507a4..000000000
--- a/src/gui/widgets/setupquickitem.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_SETUPQUICKITEM_H
-#define GUI_WIDGETS_SETUPQUICKITEM_H
-
-#include "gui/widgets/setupitem.h"
-
-#include "listeners/gamemodifierlistener.h"
-
-class Button;
-class HorizontContainer;
-class Label;
-class SetupTabScroll;
-
-typedef std::string (*ModifierGetFuncPtr)();
-typedef void (*ModifierChangeFuncPtr)(const bool forward);
-
-class SetupQuickItem final : public SetupItem,
- public GameModifierListener
-{
- public:
- SetupQuickItem(const std::string &restrict description,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ModifierGetFuncPtr getFunc,
- ModifierChangeFuncPtr changeFunc);
-
- A_DELETE_COPY(SetupQuickItem)
-
- ~SetupQuickItem();
-
- void createControls();
-
- void fromWidget() override final A_CONST;
-
- void toWidget() override final;
-
- void action(const ActionEvent &event) override final;
-
- void apply(const std::string &eventName) override final A_CONST;
-
- void cancel(const std::string &eventName A_UNUSED) override final
- A_CONST;
-
- void externalUpdated(const std::string &eventName A_UNUSED)
- override final A_CONST;
-
- void rereadValue() override final A_CONST;
-
- void save() override final A_CONST;
-
- void gameModifiersChanged() override final;
-
- protected:
- HorizontContainer *mHorizont;
- Button *mButton;
- Label *mLabel;
- ModifierGetFuncPtr mGetFunc;
- ModifierChangeFuncPtr mChangeFunc;
-};
-
-#endif // GUI_WIDGETS_SETUPQUICKITEM_H
diff --git a/src/gui/widgets/setuptouchitem.cpp b/src/gui/widgets/setuptouchitem.cpp
deleted file mode 100644
index 122853c7e..000000000
--- a/src/gui/widgets/setuptouchitem.cpp
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/setuptouchitem.h"
-
-#include "gui/models/touchactionmodel.h"
-
-#include "gui/widgets/dropdown.h"
-#include "gui/widgets/horizontcontainer.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/vertcontainer.h"
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-#include "utils/stringutils.h"
-
-#include "debug.h"
-
-SetupActionDropDown::SetupActionDropDown(const std::string &restrict text,
- const std::string &restrict
- description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- TouchActionsModel *restrict
- const model,
- const int width,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mModel(model),
- mDropDown(nullptr),
- mWidth(width)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupActionDropDown::SetupActionDropDown(const std::string &restrict text,
- const std::string &restrict
- description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- TouchActionsModel *restrict
- const model,
- const int width,
- const std::string &restrict def,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mModel(model),
- mDropDown(nullptr),
- mWidth(width)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupActionDropDown::~SetupActionDropDown()
-{
- mHorizont = nullptr;
- mWidget = nullptr;
- mModel = nullptr;
- mDropDown = nullptr;
- mLabel = nullptr;
-}
-
-void SetupActionDropDown::createControls()
-{
- if (mModel == nullptr)
- return;
-
- load();
- mHorizont = new HorizontContainer(this, 32, 2);
-
- mLabel = new Label(this, mText);
- mLabel->setToolTip(mDescription);
- mDropDown = new DropDown(this, mModel);
- mDropDown->setActionEventId(mEventName);
- mDropDown->addActionListener(mParent);
- mDropDown->setWidth(mWidth);
- mDropDown->setSelected(mModel->getSelectionFromAction(
- static_cast<InputActionT>(atoi(mValue.c_str()))));
-
- mWidget = mDropDown;
- fixFirstItemSize(mLabel);
- mHorizont->add(mLabel);
- mHorizont->add(mDropDown);
-
- mParent->getContainer()->add2(mHorizont, true, 4);
- mParent->addControl(this);
- mParent->addActionListener(this);
- mWidget->addActionListener(this);
-}
-
-void SetupActionDropDown::fromWidget()
-{
- if ((mDropDown == nullptr) || (mModel == nullptr))
- return;
-
- mValue = toString(CAST_S32(mModel->getActionFromSelection(
- mDropDown->getSelected())));
-}
-
-void SetupActionDropDown::toWidget()
-{
- if ((mDropDown == nullptr) || (mModel == nullptr))
- return;
-
- mDropDown->setSelected(mModel->getSelectionFromAction(
- static_cast<InputActionT>(atoi(mValue.c_str()))));
-}
diff --git a/src/gui/widgets/setuptouchitem.h b/src/gui/widgets/setuptouchitem.h
deleted file mode 100644
index 55521b684..000000000
--- a/src/gui/widgets/setuptouchitem.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_SETUPTOUCHITEM_H
-#define GUI_WIDGETS_SETUPTOUCHITEM_H
-
-#include "gui/widgets/setupitem.h"
-
-class TouchActionsModel;
-
-class SetupActionDropDown final : public SetupItem
-{
- public:
- SetupActionDropDown(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- TouchActionsModel *restrict const model,
- const int width,
- const MainConfig mainConfig = MainConfig_true);
-
- SetupActionDropDown(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- TouchActionsModel *restrict const model,
- const int width, const std::string &def,
- const MainConfig mainConfig = MainConfig_true);
-
- A_DELETE_COPY(SetupActionDropDown)
-
- ~SetupActionDropDown();
-
- void createControls();
-
- void fromWidget() override final;
-
- void toWidget() override final;
-
- protected:
- HorizontContainer *mHorizont;
- Label *mLabel;
- TouchActionsModel *mModel;
- DropDown *mDropDown;
- int mWidth;
-};
-
-#endif // GUI_WIDGETS_SETUPTOUCHITEM_H
diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp
deleted file mode 100644
index 3df46b854..000000000
--- a/src/gui/widgets/shoplistbox.cpp
+++ /dev/null
@@ -1,310 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/shoplistbox.h"
-
-#include "dragdrop.h"
-#include "settings.h"
-
-#include "being/playerinfo.h"
-
-#include "gui/viewport.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/popups/itempopup.h"
-#include "gui/popups/popupmenu.h"
-
-#include "gui/models/shopitems.h"
-
-#include "gui/windows/itemamountwindow.h"
-
-#include "net/net.h"
-
-#include "resources/inventory/inventory.h"
-
-#include "resources/item/shopitem.h"
-
-#include "debug.h"
-
-const int ITEM_ICON_SIZE = 32;
-
-ShopListBox::ShopListBox(const Widget2 *const widget,
- ListModel *const listModel,
- const ShopListBoxTypeT type) :
- ListBox(widget, listModel, "shoplistbox.xml"),
- mPlayerMoney(0),
- mShopItems(nullptr),
- mWarningColor(getThemeColor(ThemeColorId::SHOP_WARNING)),
- mType(type),
- mPriceCheck(true),
- mProtectItems(false)
-{
- mRowHeight = getFont()->getHeight();
- mHighlightColor = getThemeColor(ThemeColorId::HIGHLIGHT);
- mForegroundColor = getThemeColor(ThemeColorId::LISTBOX);
- mBackgroundColor = getThemeColor(ThemeColorId::BACKGROUND);
-}
-
-ShopListBox::ShopListBox(const Widget2 *const widget,
- ListModel *const listModel,
- ShopItems *const shopListModel,
- const ShopListBoxTypeT type) :
- ListBox(widget, listModel, "shoplistbox.xml"),
- mPlayerMoney(0),
- mShopItems(shopListModel),
- mWarningColor(getThemeColor(ThemeColorId::SHOP_WARNING)),
- mType(type),
- mPriceCheck(true),
- mProtectItems(false)
-{
- mRowHeight = std::max(getFont()->getHeight(), ITEM_ICON_SIZE);
- mHighlightColor = getThemeColor(ThemeColorId::HIGHLIGHT);
- mForegroundColor = getThemeColor(ThemeColorId::LISTBOX);
- mBackgroundColor = getThemeColor(ThemeColorId::BACKGROUND);
-}
-
-void ShopListBox::setPlayersMoney(const int money)
-{
- mPlayerMoney = money;
-}
-
-void ShopListBox::draw(Graphics *const graphics)
-{
- BLOCK_START("ShopListBox::draw")
- if ((mListModel == nullptr) || (mShopItems == nullptr))
- {
- BLOCK_END("ShopListBox::draw")
- return;
- }
-
- if (settings.guiAlpha != mAlpha)
- mAlpha = settings.guiAlpha;
-
- const unsigned int alpha = CAST_U32(mAlpha * 255.0F);
- Font *const font = getFont();
-
- const int sz = mListModel->getNumberOfElements();
- const int fontHeigh = getFont()->getHeight();
- const int width = mDimension.width - 2 * mPadding;
- // Draw the list elements
- for (int i = 0, y = 0;
- i < sz;
- ++i, y += mRowHeight)
- {
- bool needDraw(false);
- Color temp;
- Color* backgroundColor = &mBackgroundColor;
-
- ShopItem *const item = mShopItems->at(i);
- if ((item != nullptr) &&
- (item->getDisabled() ||
- (mPlayerMoney < item->getPrice() && mPriceCheck) ||
- (mProtectItems && PlayerInfo::isItemProtected(item->getId()))))
- {
- if (i != mSelected)
- {
- backgroundColor = &mWarningColor;
- backgroundColor->a = alpha;
- }
- else
- {
- temp = mWarningColor;
- temp.r = (temp.r + mHighlightColor.r) / 2;
- temp.g = (temp.g + mHighlightColor.g) / 2;
- temp.b = (temp.b + mHighlightColor.b) / 2;
- temp.a = alpha;
- backgroundColor = &temp;
- }
- needDraw = true;
- }
- else if (i == mSelected)
- {
- mHighlightColor.a = alpha;
- backgroundColor = &mHighlightColor;
- needDraw = true;
- }
- else
- {
- mBackgroundColor.a = alpha;
- }
-
- if (needDraw)
- {
- graphics->setColor(*backgroundColor);
- graphics->fillRectangle(Rect(mPadding, y + mPadding,
- width, mRowHeight));
- }
-
- if ((mShopItems != nullptr) && (item != nullptr))
- {
- Image *const icon = item->getImage();
- if (icon != nullptr)
- {
- icon->setAlpha(1.0F);
- graphics->drawImage(icon, mPadding, y + mPadding);
- }
- }
- if (mSelected == i)
- {
- font->drawString(graphics,
- mForegroundSelectedColor,
- mForegroundSelectedColor2,
- mListModel->getElementAt(i),
- ITEM_ICON_SIZE + mPadding,
- y + (ITEM_ICON_SIZE - fontHeigh) / 2 + mPadding);
- }
- else
- {
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor2,
- mListModel->getElementAt(i),
- ITEM_ICON_SIZE + mPadding,
- y + (ITEM_ICON_SIZE - fontHeigh) / 2 + mPadding);
- }
- }
- BLOCK_END("ShopListBox::draw")
-}
-
-void ShopListBox::safeDraw(Graphics *const graphics)
-{
- ShopListBox::draw(graphics);
-}
-
-void ShopListBox::adjustSize()
-{
- BLOCK_START("ShopListBox::adjustSize")
- if (mListModel != nullptr)
- {
- setHeight(mRowHeight * mListModel->getNumberOfElements()
- + 2 * mPadding);
- }
- BLOCK_END("ShopListBox::adjustSize")
-}
-
-void ShopListBox::setPriceCheck(const bool check)
-{
- mPriceCheck = check;
-}
-
-void ShopListBox::mouseMoved(MouseEvent &event)
-{
- if ((itemPopup == nullptr) || (mRowHeight == 0u))
- return;
-
- if (mShopItems == nullptr)
- {
- itemPopup->hide();
- return;
- }
-
- const int index = (event.getY() - mPadding) / mRowHeight;
-
- if (index < 0 || index >= mShopItems->getNumberOfElements())
- {
- itemPopup->hide();
- }
- else
- {
- const Item *const item = mShopItems->at(index);
- if (item != nullptr)
- {
- itemPopup->setItem(item, false);
- itemPopup->position(viewport->mMouseX, viewport->mMouseY);
- }
- else
- {
- itemPopup->setVisible(Visible_false);
- }
- }
-}
-
-void ShopListBox::mouseReleased(MouseEvent& event)
-{
- ListBox::mouseReleased(event);
- if (event.getType() == MouseEventType::RELEASED2)
- {
- if (dragDrop.isEmpty())
- return;
- const DragDropSourceT src = dragDrop.getSource();
- if (mType != ShopListBoxType::SellShop &&
- mType != ShopListBoxType::BuyShop)
- {
- return;
- }
- if (mType == ShopListBoxType::SellShop &&
- Net::getNetworkType() != ServerType::TMWATHENA &&
- src != DragDropSource::Cart)
- {
- return;
- }
- Inventory *inventory;
- if (src == DragDropSource::Inventory)
- inventory = PlayerInfo::getInventory();
- else if (src == DragDropSource::Cart)
- inventory = PlayerInfo::getCartInventory();
- else
- return;
- if (inventory == nullptr)
- return;
- Item *const item = inventory->getItem(dragDrop.getTag());
- if (mType == ShopListBoxType::BuyShop)
- {
- ItemAmountWindow::showWindow(
- ItemAmountWindowUsage::ShopBuyAdd,
- nullptr,
- item);
- }
- else
- {
- ItemAmountWindow::showWindow(
- ItemAmountWindowUsage::ShopSellAdd,
- nullptr,
- item);
- }
- }
-
- if (event.getButton() == MouseButton::RIGHT)
- {
- setSelected(std::max(0, getSelectionByMouse(event.getY())));
-
- if (mSelected < 0 || mSelected >= mShopItems->getNumberOfElements())
- return;
-
- Item *const item = mShopItems->at(mSelected);
- if ((popupMenu != nullptr) && (viewport != nullptr))
- {
- popupMenu->showItemPopup(viewport->mMouseX,
- viewport->mMouseY,
- item);
- }
- }
-}
-
-void ShopListBox::mouseExited(MouseEvent& event A_UNUSED)
-{
- if (itemPopup == nullptr)
- return;
-
- itemPopup->hide();
-}
diff --git a/src/gui/widgets/shoplistbox.h b/src/gui/widgets/shoplistbox.h
deleted file mode 100644
index 2e79d16bb..000000000
--- a/src/gui/widgets/shoplistbox.h
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_SHOPLISTBOX_H
-#define GUI_WIDGETS_SHOPLISTBOX_H
-
-#include "gui/widgets/listbox.h"
-
-#include "enums/gui/shoplistboxtype.h"
-
-class ShopItems;
-
-/**
- * A list box, meant to be used inside a scroll area. Same as the Guichan list
- * box except this one doesn't have a background, instead completely relying
- * on the scroll area. It also adds selection listener functionality.
- *
- * \ingroup GUI
- */
-class ShopListBox final : public ListBox
-{
- public:
- /**
- * Constructor.
- */
- ShopListBox(const Widget2 *const widget,
- ListModel *const listModel,
- const ShopListBoxTypeT type);
-
- /**
- * Constructor with shopitems
- */
- ShopListBox(const Widget2 *const widget,
- ListModel *const listModel,
- ShopItems *const shopListModel,
- const ShopListBoxTypeT type);
-
- A_DELETE_COPY(ShopListBox)
-
- /**
- * Draws the list box.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * gives information about the current player's money
- */
- void setPlayersMoney(const int money);
-
- /**
- * Adjust List draw size
- */
- void adjustSize() override final;
-
- /**
- * Set on/off the disabling of too expensive items.
- * (Good for selling mode.)
- */
- void setPriceCheck(const bool check);
-
- void mouseMoved(MouseEvent &event) override final;
-
- void mouseReleased(MouseEvent& event) override final;
-
- void mouseExited(MouseEvent& event) override final;
-
- void setProtectItems(bool p)
- { mProtectItems = p; }
-
- void setType(const ShopListBoxTypeT type)
- { mType = type; }
-
- ShopListBoxTypeT getType() const
- { return mType; }
-
- private:
- int mPlayerMoney;
-
- /**
- * Keeps another pointer to the same listModel, permitting to
- * use the ShopItems specific functions.
- */
- ShopItems *mShopItems;
-
- Color mWarningColor;
- ShopListBoxTypeT mType;
-
- bool mPriceCheck;
- bool mProtectItems;
-};
-
-#endif // GUI_WIDGETS_SHOPLISTBOX_H
diff --git a/src/gui/widgets/shortcutcontainer.cpp b/src/gui/widgets/shortcutcontainer.cpp
deleted file mode 100644
index a2b90514d..000000000
--- a/src/gui/widgets/shortcutcontainer.cpp
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/shortcutcontainer.h"
-
-#include "settings.h"
-
-#include "gui/gui.h"
-
-#include "utils/delete2.h"
-
-#include "resources/image/image.h"
-
-#include "render/graphics.h"
-
-#include "render/vertexes/imagecollection.h"
-
-#include "debug.h"
-
-float ShortcutContainer::mAlpha = 1.0;
-
-ShortcutContainer::ShortcutContainer(Widget2 *const widget) :
- Widget(widget),
- WidgetListener(),
- MouseListener(),
- mBackgroundImg(nullptr),
- mMaxItems(0),
- mBoxWidth(1),
- mBoxHeight(1),
- mGridWidth(1),
- mGridHeight(1),
- mVertexes(new ImageCollection)
-{
- mAllowLogic = false;
-
- addMouseListener(this);
- addWidgetListener(this);
-
- mForegroundColor = getThemeColor(ThemeColorId::TEXT);
- mForegroundColor2 = getThemeColor(ThemeColorId::TEXT_OUTLINE);
-
- mBackgroundImg = Theme::getImageFromThemeXml(
- "item_shortcut_background.xml", "background.xml");
-
- if (mBackgroundImg != nullptr)
- {
- mBackgroundImg->setAlpha(settings.guiAlpha);
- mBoxHeight = mBackgroundImg->getHeight();
- mBoxWidth = mBackgroundImg->getWidth();
- }
- else
- {
- mBoxHeight = 1;
- mBoxWidth = 1;
- }
-}
-
-ShortcutContainer::~ShortcutContainer()
-{
- if (mBackgroundImg != nullptr)
- {
- mBackgroundImg->decRef();
- mBackgroundImg = nullptr;
- }
-
- if (gui != nullptr)
- gui->removeDragged(this);
-
- delete2(mVertexes);
-}
-
-void ShortcutContainer::widgetResized(const Event &event A_UNUSED)
-{
- mGridWidth = mDimension.width / mBoxWidth;
-
- if (mGridWidth < 1)
- mGridWidth = 1;
-
- mGridHeight = mMaxItems / CAST_U32(mGridWidth);
-
- if (mMaxItems % mGridWidth != 0 || mGridHeight < 1)
- ++mGridHeight;
-
- setHeight(mGridHeight * mBoxHeight);
- mRedraw = true;
-}
-
-int ShortcutContainer::getIndexFromGrid(const int pointX,
- const int pointY) const
-{
- const Rect tRect = Rect(0, 0,
- mGridWidth * mBoxWidth, mGridHeight * mBoxHeight);
-
- int index = ((pointY / mBoxHeight) * mGridWidth) + pointX / mBoxWidth;
-
- if (!tRect.isPointInRect(pointX, pointY) ||
- index >= CAST_S32(mMaxItems) || index < 0)
- {
- index = -1;
- }
-
- return index;
-}
-
-void ShortcutContainer::drawBackground(Graphics *const g)
-{
- if (mBackgroundImg != nullptr)
- {
- if (mRedraw)
- {
- mRedraw = false;
- mVertexes->clear();
- for (unsigned i = 0; i < mMaxItems; i ++)
- {
- g->calcTileCollection(mVertexes, mBackgroundImg,
- (i % mGridWidth) * mBoxWidth,
- (i / mGridWidth) * mBoxHeight);
- }
- g->finalize(mVertexes);
- }
- g->drawTileCollection(mVertexes);
- }
-}
-
-void ShortcutContainer::safeDrawBackground(Graphics *const g)
-{
- if (mBackgroundImg != nullptr)
- {
- for (unsigned i = 0; i < mMaxItems; i ++)
- {
- g->drawImage(mBackgroundImg, (i % mGridWidth) * mBoxWidth,
- (i / mGridWidth) * mBoxHeight);
- }
- }
-}
-
-void ShortcutContainer::widgetMoved(const Event& event A_UNUSED)
-{
- mRedraw = true;
-}
diff --git a/src/gui/widgets/shortcutcontainer.h b/src/gui/widgets/shortcutcontainer.h
deleted file mode 100644
index b7076dfc2..000000000
--- a/src/gui/widgets/shortcutcontainer.h
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_SHORTCUTCONTAINER_H
-#define GUI_WIDGETS_SHORTCUTCONTAINER_H
-
-#include "gui/widgets/widget.h"
-
-#include "listeners/mouselistener.h"
-#include "listeners/widgetlistener.h"
-
-class Image;
-class ImageCollection;
-
-/**
- * A generic shortcut container.
- *
- * \ingroup GUI
- */
-class ShortcutContainer notfinal : public Widget,
- public WidgetListener,
- public MouseListener
-{
- public:
- A_DELETE_COPY(ShortcutContainer)
-
- /**
- * Destructor.
- */
- virtual ~ShortcutContainer();
-
- /**
- * Invoked when a widget changes its size. This is used to determine
- * the new height of the container.
- */
- void widgetResized(const Event &event) override final;
-
- void widgetMoved(const Event& event) override final;
-
- /**
- * Handles mouse when dragged.
- */
- void mouseDragged(MouseEvent &event A_UNUSED) override
- {
- }
-
- /**
- * Handles mouse when pressed.
- */
- void mousePressed(MouseEvent &event A_UNUSED) override
- {
- }
-
- /**
- * Handles mouse release.
- */
- void mouseReleased(MouseEvent &event A_UNUSED) override
- {
- }
-
- int getMaxItems() const noexcept2 A_WARN_UNUSED
- { return mMaxItems; }
-
- int getBoxWidth() const noexcept2 A_WARN_UNUSED
- { return mBoxWidth; }
-
- int getBoxHeight() const noexcept2 A_WARN_UNUSED
- { return mBoxHeight; }
-
- void drawBackground(Graphics *const g) A_NONNULL(2);
-
- void safeDrawBackground(Graphics *const g) A_NONNULL(2);
-
- protected:
- /**
- * Constructor. Initializes the shortcut container.
- */
- explicit ShortcutContainer(Widget2 *const widget);
-
- /**
- * Gets the index from the grid provided the point is in an item box.
- *
- * @param pointX X coordinate of the point.
- * @param pointY Y coordinate of the point.
- * @return index on success, -1 on failure.
- */
- int getIndexFromGrid(const int pointX,
- const int pointY) const A_WARN_UNUSED;
-
- Image *mBackgroundImg;
- static float mAlpha;
-
- unsigned mMaxItems;
- int mBoxWidth;
- int mBoxHeight;
- int mGridWidth;
- int mGridHeight;
- ImageCollection *mVertexes;
-};
-
-#endif // GUI_WIDGETS_SHORTCUTCONTAINER_H
diff --git a/src/gui/widgets/skilllistbox.h b/src/gui/widgets/skilllistbox.h
deleted file mode 100644
index 4f7e2a61b..000000000
--- a/src/gui/widgets/skilllistbox.h
+++ /dev/null
@@ -1,290 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_SKILLLISTBOX_H
-#define GUI_WIDGETS_SKILLLISTBOX_H
-
-#include "const/resources/skill.h"
-
-#include "dragdrop.h"
-
-#include "gui/skin.h"
-#include "gui/viewport.h"
-
-#include "gui/widgets/listbox.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/models/skillmodel.h"
-
-#include "gui/popups/popupmenu.h"
-#include "gui/popups/skillpopup.h"
-
-#include "utils/delete2.h"
-
-#include "render/graphics.h"
-
-#include "localconsts.h"
-
-class SkillModel;
-
-class SkillListBox final : public ListBox
-{
- public:
- SkillListBox(const Widget2 *const widget,
- SkillModel *const model) :
- ListBox(widget, model, "skilllistbox.xml"),
- mModel(model),
- mTextColor(getThemeColor(ThemeColorId::TEXT)),
- mTextColor2(getThemeColor(ThemeColorId::TEXT_OUTLINE)),
- mCooldownColor(getThemeColor(ThemeColorId::SKILL_COOLDOWN)),
- mTextPadding(mSkin != nullptr ?
- mSkin->getOption("textPadding", 34) : 34),
- mSpacing(mSkin != nullptr ? mSkin->getOption("spacing", 0) : 0),
- mSkillClicked(false)
- {
- mRowHeight = getFont()->getHeight() * 2 + mSpacing + 2 * mPadding;
- mHighlightColor = getThemeColor(ThemeColorId::HIGHLIGHT);
-
- if (mRowHeight < 34)
- mRowHeight = 34;
- }
-
- A_DELETE_COPY(SkillListBox)
-
- ~SkillListBox()
- {
- delete2(mModel)
- }
-
- SkillInfo *getSelectedInfo() const
- {
- const int selected = getSelected();
- if ((mListModel == nullptr) || selected < 0
- || selected > mListModel->getNumberOfElements())
- {
- return nullptr;
- }
-
- return static_cast<SkillModel*>(mListModel)->getSkillAt(selected);
- }
-
- void draw(Graphics *const graphics) override final A_NONNULL(2)
- {
- if (mListModel == nullptr)
- return;
-
- SkillModel *const model = static_cast<SkillModel*>(mListModel);
- updateAlpha();
-
- mHighlightColor.a = CAST_S32(mAlpha * 255.0F);
- graphics->setColor(mHighlightColor);
-
- const int width1 = getWidth();
- const int usableWidth = width1 - 2 * mPadding;
-
- // Draw filled rectangle around the selected list element
- if (mSelected >= 0)
- {
- graphics->fillRectangle(Rect(mPadding, getRowHeight()
- * mSelected + mPadding, usableWidth,
- getRowHeight()));
- }
-
- // Draw the list elements
- Font *const font = getFont();
- const int space = font->getHeight() + mSpacing;
- const int width2 = width1 - mPadding;
-
- graphics->setColor(mCooldownColor);
- for (int i = 0, y = 1 + mPadding;
- i < model->getNumberOfElements();
- ++i, y += getRowHeight())
- {
- SkillInfo *const e = model->getSkillAt(i);
- if (e != nullptr)
- {
- if (e->cooldown != 0)
- {
- graphics->fillRectangle(Rect(mPadding, y,
- usableWidth * 100 / e->cooldown, 10));
- }
- }
- }
-
- for (int i = 0, y = 1 + mPadding;
- i < model->getNumberOfElements();
- ++i, y += getRowHeight())
- {
- SkillInfo *const e = model->getSkillAt(i);
- if (e != nullptr)
- {
- const SkillData *const data = e->data;
- const std::string &description = data->description;
- graphics->drawImage(data->icon, mPadding, y);
- font->drawString(graphics,
- mTextColor,
- mTextColor2,
- data->name,
- mTextPadding, y);
- if (!description.empty())
- {
- font->drawString(graphics,
- mTextColor,
- mTextColor2,
- description,
- mTextPadding,
- y + space);
- }
-
- if (e->skillLevelWidth < 0)
- {
- // Add one for padding
- e->skillLevelWidth = font->getWidth(e->skillLevel) + 1;
- }
-
- font->drawString(graphics,
- mTextColor,
- mTextColor2,
- e->skillLevel,
- width2 - e->skillLevelWidth,
- y);
- }
- }
- }
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2)
- {
- SkillListBox::draw(graphics);
- }
-
- unsigned int getRowHeight() const override final
- { return mRowHeight; }
-
- const SkillInfo *getSkillByEvent(const MouseEvent &event) const
- {
- const int y = (event.getY() + mPadding) / getRowHeight();
- if (mModel == nullptr || y >= mModel->getNumberOfElements())
- return nullptr;
- const SkillInfo *const skill = mModel->getSkillAt(y);
- if (skill == nullptr)
- return nullptr;
- return skill;
- }
-
- void mouseMoved(MouseEvent &event) override final
- {
- ListBox::mouseMoved(event);
- if ((viewport == nullptr) || !dragDrop.isEmpty())
- return;
-
- const SkillInfo *const skill = getSkillByEvent(event);
- if (skill == nullptr)
- return;
- skillPopup->show(skill,
- skill->customSelectedLevel,
- skill->customCastType,
- skill->customOffsetX,
- skill->customOffsetY);
- skillPopup->position(viewport->mMouseX,
- viewport->mMouseY);
- }
-
- void mouseDragged(MouseEvent &event) override final
- {
- if (event.getButton() == MouseButton::LEFT)
- {
- if (dragDrop.isEmpty())
- {
- if (mSkillClicked)
- {
- mSkillClicked = false;
- const SkillInfo *const skill = getSkillByEvent(event);
- if (skill == nullptr)
- return;
- dragDrop.dragSkill(skill, DragDropSource::Skills);
- dragDrop.setItem(skill->id + SKILL_MIN_ID);
- dragDrop.setItemData(skill->toDataStr());
- }
- ListBox::mouseDragged(event);
- }
- }
- else
- {
- ListBox::mouseDragged(event);
- }
- }
-
- void mousePressed(MouseEvent &event) override final
- {
- ListBox::mousePressed(event);
- const MouseButtonT button = event.getButton();
- if (button == MouseButton::LEFT ||
- button == MouseButton::RIGHT)
- {
- const SkillInfo *const skill = getSkillByEvent(event);
- if (skill == nullptr)
- return;
- event.consume();
- mSkillClicked = true;
- SkillModel *const model = static_cast<SkillModel*>(
- mListModel);
- if ((model != nullptr) &&
- mSelected >= 0 &&
- model->getSkillAt(mSelected) == skill)
- {
- skillPopup->hide();
- if (button == MouseButton::LEFT &&
- event.getX() >
- getWidth() - mPadding - skill->skillLevelWidth)
- {
- popupMenu->showSkillLevelPopup(skill);
- }
- else if (button == MouseButton::RIGHT)
- {
- popupMenu->showSkillPopup(skill);
- }
- }
- }
- }
-
- void mouseReleased(MouseEvent &event) override final
- {
- ListBox::mouseReleased(event);
- }
-
- void mouseExited(MouseEvent &event A_UNUSED) override final
- {
- skillPopup->hide();
- }
-
- private:
- SkillModel *mModel;
- Color mTextColor;
- Color mTextColor2;
- Color mCooldownColor;
- int mTextPadding;
- int mSpacing;
- bool mSkillClicked;
-};
-
-#endif // GUI_WIDGETS_SKILLLISTBOX_H
diff --git a/src/gui/widgets/skillrectanglelistbox.h b/src/gui/widgets/skillrectanglelistbox.h
deleted file mode 100644
index a3139260c..000000000
--- a/src/gui/widgets/skillrectanglelistbox.h
+++ /dev/null
@@ -1,418 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_SKILLRECTANGLELISTBOX_H
-#define GUI_WIDGETS_SKILLRECTANGLELISTBOX_H
-
-#include "const/resources/skill.h"
-
-#include "dragdrop.h"
-#include "settings.h"
-
-#include "gui/skin.h"
-#include "gui/viewport.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/models/skillmodel.h"
-
-#include "gui/popups/popupmenu.h"
-#include "gui/popups/skillpopup.h"
-
-#include "utils/delete2.h"
-
-#include "render/graphics.h"
-
-#include "localconsts.h"
-
-class SkillModel;
-
-class SkillRectangleListBox final : public Widget,
- public MouseListener
-{
- public:
- SkillRectangleListBox(const Widget2 *const widget,
- SkillModel *const model) :
- Widget(widget),
- MouseListener(),
- mHighlightColor(getThemeColor(ThemeColorId::HIGHLIGHT)),
- mTextColor(getThemeColor(ThemeColorId::TEXT)),
- mTextColor2(getThemeColor(ThemeColorId::TEXT_OUTLINE)),
- mCooldownColor(getThemeColor(ThemeColorId::SKILL_COOLDOWN)),
- mForegroundSelectedColor(getThemeColor(
- ThemeColorId::LISTBOX_SELECTED)),
- mForegroundSelectedColor2(getThemeColor(
- ThemeColorId::LISTBOX_SELECTED_OUTLINE)),
- mModel(model),
- mSkin(nullptr),
- mSelected(-1),
- mPadding(2),
- mBoxWidth(80),
- mBoxHeight(70),
- mIconXOffset(24),
- mIconYOffset(10),
- mTextXOffset(0),
- mTextYOffset(44),
- mSkillClicked(false)
- {
- if (theme != nullptr)
- {
- mSkin = theme->load("skillrectanglelistbox.xml",
- "listbox.xml");
- }
-
- if (mSkin != nullptr)
- {
- mPadding = mSkin->getPadding();
- mBoxWidth = mSkin->getOption("boxWidth", 80);
- mBoxHeight = mSkin->getOption("boxHeight", 70);
- mIconXOffset = mSkin->getOption("iconXOffset", 24);
- mIconYOffset = mSkin->getOption("iconYOffset", 10);
- mTextXOffset = mSkin->getOption("textXOffset", 0);
- mTextYOffset = mSkin->getOption("textYOffset", 44);
- }
- Font *const font = getFont();
- int minWidth = font->getWidth("Lvl: 10/10") + mTextXOffset + 2;
- int minHeight = font->getHeight() + mTextYOffset + 2;
- if (mBoxWidth < minWidth)
- mBoxWidth = minWidth;
- if (mBoxHeight < minHeight)
- mBoxHeight = minHeight;
- int maxX = 0;
- int maxY = 0;
- for (int i = 0;
- i < model->getNumberOfElements();
- ++i)
- {
- SkillInfo *const e = model->getSkillAt(i);
- if (e != nullptr)
- {
- if (e->x > maxX)
- maxX = e->x;
- if (e->y > maxY)
- maxY = e->y;
- }
- }
- maxX ++;
- maxY ++;
- setWidth(maxX * mBoxWidth);
- setHeight(maxY * mBoxHeight);
- addMouseListener(this);
- }
-
- A_DELETE_COPY(SkillRectangleListBox)
-
- ~SkillRectangleListBox()
- {
- delete2(mModel)
- }
-
- SkillInfo *getSelectedInfo() const
- {
- if (mModel == nullptr)
- return nullptr;
- const int selected = mSelected;
- if (selected < 0 ||
- selected > mModel->getNumberOfElements())
- {
- return nullptr;
- }
-
- return mModel->getSkillAt(selected);
- }
-
- void draw(Graphics *const graphics) override final A_NONNULL(2)
- {
- if (mModel == nullptr)
- return;
-
- SkillModel *const model = mModel;
- updateAlpha();
-
- int maxX = 0;
- int maxY = 0;
- mHighlightColor.a = CAST_S32(mAlpha * 255.0F);
- graphics->setColor(mHighlightColor);
- Font *const font = getFont();
- if (mSelected >= 0)
- {
- SkillInfo *const e = model->getSkillAt(mSelected);
- if (e != nullptr)
- {
- const int x = e->x * mBoxWidth + mPadding;
- const int y = e->y * mBoxHeight + mPadding;
-
- graphics->fillRectangle(Rect(x, y,
- mBoxWidth, mBoxHeight));
-
- const int xOffset = (mBoxWidth -
- font->getWidth(e->skillLevel)) / 2;
- font->drawString(graphics,
- mForegroundSelectedColor,
- mForegroundSelectedColor,
- e->skillLevel,
- x + mTextXOffset + xOffset,
- y + mTextYOffset);
- }
- }
-
- // +++ need split drawing icons and text
- for (int i = 0;
- i < model->getNumberOfElements();
- ++i)
- {
- SkillInfo *const e = model->getSkillAt(i);
- if (e != nullptr)
- {
- if (e->x > maxX)
- maxX = e->x;
- if (e->y > maxY)
- maxY = e->y;
- const SkillData *const data = e->data;
- const int x = e->x * mBoxWidth + mPadding;
- const int y = e->y * mBoxHeight + mPadding;
-
- graphics->drawImage(data->icon,
- x + mIconXOffset,
- y + mIconYOffset);
-
- if (i != mSelected)
- {
- const int width1 = font->getWidth(e->skillLevel);
- const int xOffset = (mBoxWidth -
- width1) / 2;
- font->drawString(graphics,
- mTextColor,
- mTextColor2,
- e->skillLevel,
- x + mTextXOffset + xOffset,
- y + mTextYOffset);
- if (e->skillLevelWidth < 0)
- {
- // Add one for padding
- e->skillLevelWidth = width1 + 1;
- }
- }
- else
- {
- if (e->skillLevelWidth < 0)
- {
- // Add one for padding
- e->skillLevelWidth = font->getWidth(
- e->skillLevel) + 1;
- }
- }
- }
- }
- maxX ++;
- maxY ++;
- setWidth(maxX * mBoxWidth);
- setHeight(maxY * mBoxHeight);
- }
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2)
- {
- SkillRectangleListBox::draw(graphics);
- }
-
- const SkillInfo *getSkillByEvent(const MouseEvent &event) const
- {
- if (mModel == nullptr)
- return nullptr;
- const int posX = (event.getX() - mPadding) / mBoxWidth;
- const int posY = (event.getY() - mPadding) / mBoxHeight;
- for (int i = 0;
- i < mModel->getNumberOfElements();
- ++i)
- {
- SkillInfo *const e = mModel->getSkillAt(i);
- if (e != nullptr)
- {
- if (posX == e->x && posY == e->y)
- return e;
- }
- }
- return nullptr;
- }
-
- int getSelectionByEvent(const MouseEvent &event) const
- {
- if (mModel == nullptr)
- return -1;
- const int posX = (event.getX() - mPadding) / mBoxWidth;
- const int posY = (event.getY() - mPadding) / mBoxHeight;
- for (int i = 0;
- i < mModel->getNumberOfElements();
- ++i)
- {
- SkillInfo *const e = mModel->getSkillAt(i);
- if (e != nullptr)
- {
- if (posX == e->x && posY == e->y)
- return i;
- }
- }
- return -1;
- }
-
- void mouseMoved(MouseEvent &event) override final
- {
- if ((viewport == nullptr) || !dragDrop.isEmpty())
- return;
-
- const SkillInfo *const skill = getSkillByEvent(event);
- if (skill == nullptr)
- return;
- skillPopup->show(skill,
- skill->customSelectedLevel,
- skill->customCastType,
- skill->customOffsetX,
- skill->customOffsetY);
- skillPopup->position(viewport->mMouseX,
- viewport->mMouseY);
- }
-
- void mouseDragged(MouseEvent &event) override final
- {
- if (event.getButton() != MouseButton::LEFT)
- return;
- setSelected(std::max(0, getSelectionByEvent(event)));
-
- if (dragDrop.isEmpty())
- {
- if (mSkillClicked)
- {
- mSkillClicked = false;
- const SkillInfo *const skill = getSkillByEvent(event);
- if (skill == nullptr)
- return;
- dragDrop.dragSkill(skill, DragDropSource::Skills);
- dragDrop.setItem(skill->id + SKILL_MIN_ID);
- dragDrop.setItemData(skill->toDataStr());
- }
- }
- }
-
- void mousePressed(MouseEvent &event) override final
- {
- const MouseButtonT button = event.getButton();
- if (button == MouseButton::LEFT ||
- button == MouseButton::RIGHT)
- {
- const SkillInfo *const skill = getSkillByEvent(event);
- if (skill == nullptr)
- return;
- event.consume();
- mSkillClicked = true;
- SkillModel *const model = mModel;
- if ((model != nullptr) &&
- mSelected >= 0 &&
- model->getSkillAt(mSelected) == skill)
- {
- skillPopup->hide();
-
- const int x = skill->x * mBoxWidth + mPadding;
- const int y = skill->y * mBoxHeight + mPadding;
- Font *const font = getFont();
- const int height = font->getHeight();
- const int eventX = event.getX();
- const int eventY = event.getY() - mTextYOffset;
- if (button == MouseButton::LEFT)
- {
- if (eventX >= x + mTextXOffset &&
- eventX <= x + mBoxWidth - mTextXOffset &&
- eventY >= y &&
- eventY <= y + height)
- {
- popupMenu->showSkillLevelPopup(skill);
- }
- }
- else if (button == MouseButton::RIGHT)
- {
- popupMenu->showSkillPopup(skill);
- }
- }
- }
- }
-
- void mouseReleased(MouseEvent &event) override final
- {
- if (event.getButton() == MouseButton::LEFT)
- {
- setSelected(std::max(0, getSelectionByEvent(event)));
- distributeActionEvent();
- }
- }
-
- void mouseExited(MouseEvent &event A_UNUSED) override final
- {
- skillPopup->hide();
- }
-
- void updateAlpha()
- {
- const float alpha = std::max(settings.guiAlpha,
- theme->getMinimumOpacity());
-
- if (mAlpha != alpha)
- mAlpha = alpha;
- }
-
- void setSelected(const int selected)
- {
- if (mModel == nullptr)
- {
- mSelected = -1;
- }
- else
- {
- if (selected < 0)
- mSelected = -1;
- else if (selected >= mModel->getNumberOfElements())
- mSelected = mModel->getNumberOfElements() - 1;
- else
- mSelected = selected;
- }
- }
-
- private:
- Color mHighlightColor;
- Color mTextColor;
- Color mTextColor2;
- Color mCooldownColor;
- Color mForegroundSelectedColor;
- Color mForegroundSelectedColor2;
- SkillModel *mModel;
- Skin *mSkin;
- int mSelected;
- int mPadding;
- int mBoxWidth;
- int mBoxHeight;
- int mIconXOffset;
- int mIconYOffset;
- int mTextXOffset;
- int mTextYOffset;
- bool mSkillClicked;
- static float mAlpha;
-};
-
-float SkillRectangleListBox::mAlpha = 1.0;
-
-#endif // GUI_WIDGETS_SKILLRECTANGLELISTBOX_H
diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp
deleted file mode 100644
index 0d25ad2c5..000000000
--- a/src/gui/widgets/slider.cpp
+++ /dev/null
@@ -1,517 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/slider.h"
-
-#include "settings.h"
-
-#include "enums/gui/slidergrid.h"
-
-#include "gui/gui.h"
-
-#include "utils/delete2.h"
-
-#include "resources/imagerect.h"
-
-#include "resources/image/image.h"
-
-#include "render/graphics.h"
-
-#include "render/vertexes/imagecollection.h"
-
-#include "debug.h"
-
-ImageRect Slider::buttons[2];
-float Slider::mAlpha = 1.0;
-int Slider::mInstances = 0;
-
-static std::string const data[2] =
-{
- "slider.xml",
- "slider_highlighted.xml"
-};
-
-Slider::Slider(Widget2 *const widget,
- const double scaleEnd,
- const double stepLength) :
- Widget(widget),
- MouseListener(),
- KeyListener(),
- mValue(0),
- mStepLength(stepLength),
- mScaleStart(0),
- mScaleEnd(scaleEnd),
- mOrientation(Orientation::HORIZONTAL),
- mVertexes(new ImageCollection),
- mMarkerLength(10),
- mHasMouse(false)
-{
- init();
-}
-
-Slider::Slider(Widget2 *const widget,
- const double scaleStart,
- const double scaleEnd,
- const double stepLength) :
- Widget(widget),
- MouseListener(),
- KeyListener(),
- mValue(scaleStart),
- mStepLength(stepLength),
- mScaleStart(scaleStart),
- mScaleEnd(scaleEnd),
- mOrientation(Orientation::HORIZONTAL),
- mVertexes(new ImageCollection),
- mMarkerLength(10),
- mHasMouse(false)
-{
- init();
-}
-
-Slider::~Slider()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- delete2(mVertexes);
- mInstances--;
- if (mInstances == 0)
- {
- for (int mode = 0; mode < 2; mode ++)
- Theme::unloadRect(buttons[mode]);
- }
-}
-
-void Slider::init()
-{
- mAllowLogic = false;
- setFocusable(true);
- setFrameSize(1);
-
- addMouseListener(this);
- addKeyListener(this);
-
- setFrameSize(0);
-
- // Load resources
- if (mInstances == 0)
- {
- if (theme != nullptr)
- {
- for (int mode = 0; mode < 2; mode ++)
- theme->loadRect(buttons[mode], data[mode], "slider.xml", 0, 8);
- }
- updateAlpha();
- }
-
- mInstances++;
-
- if (buttons[0].grid[SliderGrid::HGRIP] != nullptr)
- setMarkerLength(buttons[0].grid[SliderGrid::HGRIP]->getWidth());
-}
-
-void Slider::updateAlpha()
-{
- const float alpha = std::max(settings.guiAlpha,
- theme->getMinimumOpacity());
-
- if (alpha != mAlpha)
- {
- mAlpha = alpha;
- for (int f = 0; f < 2; f ++)
- {
- for (int d = 0; d < SliderGrid::SLIDER_MAX; d ++)
- {
- if (buttons[f].grid[d] != nullptr)
- buttons[f].grid[d]->setAlpha(mAlpha);
- }
- }
- }
-}
-
-void Slider::draw(Graphics *const graphics)
-{
- BLOCK_START("Slider::draw")
- if ((buttons[0].grid[SliderGrid::HSTART] == nullptr) ||
- (buttons[1].grid[SliderGrid::HSTART] == nullptr) ||
- (buttons[0].grid[SliderGrid::HEND] == nullptr))
- {
- BLOCK_END("Slider::draw")
- return;
- }
-
- int w = getWidth();
- const int h = getHeight();
- const int y = mHasMouse ?
- (h - buttons[1].grid[SliderGrid::HSTART]->getHeight()) / 2 :
- (h - buttons[0].grid[SliderGrid::HSTART]->getHeight()) / 2;
-
- updateAlpha();
-
- if (mRedraw || graphics->getRedraw())
- {
- int x = 0;
- mRedraw = false;
- mVertexes->clear();
- if (!mHasMouse)
- {
- graphics->calcTileCollection(mVertexes,
- buttons[0].grid[SliderGrid::HSTART],
- x, y);
-
- const int width = buttons[0].grid[SliderGrid::HSTART]->getWidth();
- w -= width + buttons[0].grid[SliderGrid::HEND]->getWidth();
- x += width;
-
- if (buttons[0].grid[SliderGrid::HMID] != nullptr)
- {
- const Image *const hMid = buttons[0].grid[SliderGrid::HMID];
- graphics->calcPattern(mVertexes,
- hMid,
- x, y,
- w, hMid->getHeight());
- }
-
- x += w;
- graphics->calcTileCollection(mVertexes,
- buttons[0].grid[SliderGrid::HEND],
- x, y);
-
- const Image *const img = buttons[0].grid[SliderGrid::HGRIP];
- if (img != nullptr)
- {
- graphics->calcTileCollection(mVertexes,
- img,
- getMarkerPosition(),
- (mDimension.height - img->getHeight()) / 2);
- }
- }
- else
- {
- graphics->calcTileCollection(mVertexes,
- buttons[1].grid[SliderGrid::HSTART],
- x, y);
-
- const int width = buttons[1].grid[SliderGrid::HSTART]->getWidth();
- w -= width;
- if (buttons[1].grid[SliderGrid::HEND] != nullptr)
- w -= buttons[1].grid[SliderGrid::HEND]->getWidth();
- x += width;
-
- if (buttons[1].grid[SliderGrid::HMID] != nullptr)
- {
- const Image *const hMid = buttons[1].grid[SliderGrid::HMID];
- graphics->calcPattern(mVertexes,
- hMid,
- x, y,
- w, hMid->getHeight());
- }
-
- x += w;
- if (buttons[1].grid[SliderGrid::HEND] != nullptr)
- {
- graphics->calcTileCollection(mVertexes,
- buttons[1].grid[SliderGrid::HEND], x, y);
- }
-
- const Image *const img = buttons[1].grid[SliderGrid::HGRIP];
- if (img != nullptr)
- {
- graphics->calcTileCollection(mVertexes,
- img,
- getMarkerPosition(),
- (mDimension.height - img->getHeight()) / 2);
- }
- }
- graphics->finalize(mVertexes);
- }
- graphics->drawTileCollection(mVertexes);
-
- BLOCK_END("Slider::draw")
-}
-
-void Slider::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("Slider::draw")
- if ((buttons[0].grid[SliderGrid::HSTART] == nullptr) ||
- (buttons[1].grid[SliderGrid::HSTART] == nullptr) ||
- (buttons[0].grid[SliderGrid::HEND] == nullptr))
- {
- BLOCK_END("Slider::draw")
- return;
- }
-
- int w = getWidth();
- const int h = getHeight();
- int x = 0;
- const int y = mHasMouse ?
- (h - buttons[1].grid[SliderGrid::HSTART]->getHeight()) / 2 :
- (h - buttons[0].grid[SliderGrid::HSTART]->getHeight()) / 2;
-
- updateAlpha();
-
- if (!mHasMouse)
- {
- graphics->drawImage(buttons[0].grid[SliderGrid::HSTART], x, y);
- const int width = buttons[0].grid[SliderGrid::HSTART]->getWidth();
- w -= width + buttons[0].grid[SliderGrid::HEND]->getWidth();
- x += width;
-
- if (buttons[0].grid[SliderGrid::HMID] != nullptr)
- {
- const Image *const hMid = buttons[0].grid[SliderGrid::HMID];
- graphics->drawPattern(hMid, x, y, w, hMid->getHeight());
- }
-
- x += w;
- graphics->drawImage(buttons[0].grid[SliderGrid::HEND], x, y);
-
- const Image *const img = buttons[0].grid[SliderGrid::HGRIP];
- if (img != nullptr)
- {
- graphics->drawImage(img, getMarkerPosition(),
- (mDimension.height - img->getHeight()) / 2);
- }
- }
- else
- {
- graphics->drawImage(buttons[1].grid[SliderGrid::HSTART], x, y);
-
- const int width = buttons[1].grid[SliderGrid::HSTART]->getWidth();
- w -= width;
- if (buttons[1].grid[SliderGrid::HEND] != nullptr)
- w -= buttons[1].grid[SliderGrid::HEND]->getWidth();
- x += width;
-
- if (buttons[1].grid[SliderGrid::HMID] != nullptr)
- {
- const Image *const hMid = buttons[1].grid[SliderGrid::HMID];
- graphics->drawPattern(hMid, x, y, w, hMid->getHeight());
- }
-
- x += w;
- if (buttons[1].grid[SliderGrid::HEND] != nullptr)
- graphics->drawImage(buttons[1].grid[SliderGrid::HEND], x, y);
-
- const Image *const img = buttons[1].grid[SliderGrid::HGRIP];
- if (img != nullptr)
- {
- graphics->drawImage(img, getMarkerPosition(),
- (mDimension.height - img->getHeight()) / 2);
- }
- }
-
- BLOCK_END("Slider::draw")
-}
-
-void Slider::mouseEntered(MouseEvent& event A_UNUSED)
-{
- mHasMouse = true;
- mRedraw = true;
-}
-
-void Slider::mouseExited(MouseEvent& event A_UNUSED)
-{
- mHasMouse = false;
- mRedraw = true;
-}
-
-void Slider::mousePressed(MouseEvent &event)
-{
- const int x = event.getX();
- const int y = event.getY();
- const int width = mDimension.width;
- const int height = mDimension.height;
-
- if (event.getButton() == MouseButton::LEFT
- && x >= 0 && x <= width && y >= 0 && y <= height)
- {
- event.consume();
- if (mOrientation == Orientation::HORIZONTAL)
- setValue(markerPositionToValue(x - mMarkerLength / 2));
- else
- setValue(markerPositionToValue(height - y - mMarkerLength / 2));
- distributeActionEvent();
- }
-}
-
-void Slider::mouseDragged(MouseEvent &event)
-{
- if (mOrientation == Orientation::HORIZONTAL)
- {
- setValue(markerPositionToValue(event.getX() - mMarkerLength / 2));
- }
- else
- {
- setValue(markerPositionToValue(
- mDimension.height - event.getY() - mMarkerLength / 2));
- }
-
- distributeActionEvent();
-
- event.consume();
-}
-
-void Slider::mouseWheelMovedUp(MouseEvent &event)
-{
- setValue(mValue + mStepLength);
- distributeActionEvent();
- event.consume();
-}
-
-void Slider::mouseWheelMovedDown(MouseEvent &event)
-{
- setValue(mValue - mStepLength);
- distributeActionEvent();
- event.consume();
-}
-
-void Slider::keyPressed(KeyEvent& event)
-{
- const InputActionT action = event.getActionId();
-
- if (mOrientation == Orientation::HORIZONTAL)
- {
- if (action == InputAction::GUI_RIGHT)
- {
- setValue(mValue + mStepLength);
- distributeActionEvent();
- event.consume();
- }
- else if (action == InputAction::GUI_LEFT)
- {
- setValue(mValue - mStepLength);
- distributeActionEvent();
- event.consume();
- }
- }
- else
- {
- if (action == InputAction::GUI_UP)
- {
- setValue(mValue + mStepLength);
- distributeActionEvent();
- event.consume();
- }
- else if (action == InputAction::GUI_DOWN)
- {
- setValue(mValue - mStepLength);
- distributeActionEvent();
- event.consume();
- }
- }
-}
-
-void Slider::setScale(const double scaleStart, const double scaleEnd)
-{
- mScaleStart = scaleStart;
- mScaleEnd = scaleEnd;
-}
-
-void Slider::setValue(const double value)
-{
- mRedraw = true;
- if (value > mScaleEnd)
- mValue = mScaleEnd;
- else if (value < mScaleStart)
- mValue = mScaleStart;
- else
- mValue = value;
- mValue = CAST_S32((mValue - mScaleStart) / mStepLength)
- * mStepLength + mScaleStart;
-}
-
-double Slider::markerPositionToValue(const int v) const
-{
- int w;
- if (mOrientation == Orientation::HORIZONTAL)
- w = mDimension.width;
- else
- w = mDimension.height;
-
- const double pos = v / (static_cast<double>(w) - mMarkerLength);
- return (1.0 - pos) * mScaleStart + pos * mScaleEnd;
-}
-
-int Slider::valueToMarkerPosition(const double value) const
-{
- int v;
- if (mOrientation == Orientation::HORIZONTAL)
- v = mDimension.width;
- else
- v = mDimension.height;
-
- const int w = CAST_S32((v - mMarkerLength)
- * (value - mScaleStart)
- / (mScaleEnd - mScaleStart));
-
- if (w < 0)
- return 0;
-
- if (w > v - mMarkerLength)
- return v - mMarkerLength;
-
- return w;
-}
diff --git a/src/gui/widgets/slider.h b/src/gui/widgets/slider.h
deleted file mode 100644
index 49acafc28..000000000
--- a/src/gui/widgets/slider.h
+++ /dev/null
@@ -1,337 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_SLIDER_H
-#define GUI_WIDGETS_SLIDER_H
-
-#include "enums/gui/orientation.h"
-
-#include "listeners/keylistener.h"
-#include "listeners/mouselistener.h"
-
-#include "gui/widgets/widget.h"
-
-#include "localconsts.h"
-
-class ImageCollection;
-
-/**
- * Slider widget. Same as the Guichan slider but with custom look.
- *
- * \ingroup GUI
- */
-class Slider final : public Widget,
- public MouseListener,
- public KeyListener
-{
- public:
- /**
- * Constructor with scale start equal to 0.
- */
- Slider(Widget2 *const widget,
- const double scaleEnd,
- const double stepLength);
-
- /**
- * Constructor.
- */
- Slider(Widget2 *const widget,
- const double scaleStart,
- const double scaleEnd,
- const double stepLength);
-
- A_DELETE_COPY(Slider)
-
- /**
- * Destructor.
- */
- ~Slider();
-
- /**
- * Update the alpha value to the graphic components.
- */
- void updateAlpha();
-
- /**
- * Draws the slider.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Called when the mouse enteres the widget area.
- */
- void mouseEntered(MouseEvent& event) override final;
-
- /**
- * Called when the mouse leaves the widget area.
- */
- void mouseExited(MouseEvent& event) override final;
-
- void mousePressed(MouseEvent &event) override final;
-
- void mouseDragged(MouseEvent &event) override final;
-
- void mouseWheelMovedUp(MouseEvent &event) override final;
-
- void mouseWheelMovedDown(MouseEvent &event) override final;
-
- void keyPressed(KeyEvent& event) override final;
-
- /**
- * Sets the scale of the slider.
- *
- * @param scaleStart The start value of the scale.
- * @param scaleEnd tThe end of value the scale.
- * @see getScaleStart, getScaleEnd
- */
- void setScale(const double scaleStart, const double scaleEnd);
-
- /**
- * Gets the start value of the scale.
- *
- * @return The start value of the scale.
- * @see setScaleStart, setScale
- */
- double getScaleStart() const
- { return mScaleStart; }
-
- /**
- * Sets the start value of the scale.
- *
- * @param scaleStart The start value of the scale.
- * @see getScaleStart
- */
- void setScaleStart(const double scaleStart)
- { mScaleStart = scaleStart; }
-
- /**
- * Gets the end value of the scale.
- *
- * @return The end value of the scale.
- * @see setScaleEnd, setScale
- */
- double getScaleEnd() const
- { return mScaleEnd; }
-
- /**
- * Sets the end value of the scale.
- *
- * @param scaleEnd The end value of the scale.
- * @see getScaleEnd
- */
- void setScaleEnd(const double scaleEnd)
- { mScaleEnd = scaleEnd; }
-
- /**
- * Sets the current selected value.
- *
- * @param value The current selected value.
- * @see getValue
- */
- void setValue(const double value);
-
- /**
- * Gets the current selected value.
- *
- * @return The current selected value.
- * @see setValue
- */
- double getValue() const
- { return mValue; }
-
- /**
- * Gets the length of the marker.
- *
- * @return The length of the marker.
- * @see setMarkerLength
- */
- int getMarkerLength() const
- { return mMarkerLength; }
-
- /**
- * Sets the length of the marker.
- *
- * @param length The length for the marker.
- * @see getMarkerLength
- */
- void setMarkerLength(const int length)
- { mMarkerLength = length; }
-
- /**
- * Sets the orientation of the slider. A slider can be drawn vertically
- * or horizontally.
- *
- * @param orientation The orientation of the slider.
- * @see getOrientation
- */
- void setOrientation(const OrientationT orientation)
- { mOrientation = orientation; }
-
- /**
- * Gets the orientation of the slider. A slider can be drawn vertically
- * or horizontally.
- *
- * @return The orientation of the slider.
- * @see setOrientation
- */
- OrientationT getOrientation() const
- { return mOrientation; }
-
- /**
- * Sets the step length. The step length is used when the keys LEFT
- * and RIGHT are pressed to step in the scale.
- *
- * @param length The step length.
- * @see getStepLength
- */
- void setStepLength(const double length)
- { mStepLength = length; }
-
- /**
- * Gets the step length. The step length is used when the keys LEFT
- * and RIGHT are pressed to step in the scale.
- *
- * @return the step length.
- * @see setStepLength
- */
- double getStepLength() const
- { return mStepLength; }
-
- private:
- /**
- * Used to initialize instances.
- */
- void init();
-
- /**
- * Converts a marker position to a value in the scale.
- *
- * @param position The position to convert.
- * @return A scale value corresponding to the position.
- * @see valueToMarkerPosition
- */
- double markerPositionToValue(const int position) const;
-
- /**
- * Converts a value to a marker position.
- *
- * @param value The value to convert.
- * @return A marker position corresponding to the value.
- * @see markerPositionToValue
- */
- int valueToMarkerPosition(const double value) const;
-
- /**
- * Gets the marker position of the current selected value.
- *
- * @return The marker position of the current selected value.
- */
- int getMarkerPosition() const
- { return valueToMarkerPosition(getValue()); }
-
- static ImageRect buttons[2];
- static float mAlpha;
- static int mInstances;
-
- /**
- * Holds the current selected value.
- */
- double mValue;
-
- /**
- * Holds the step length. The step length is used when the keys LEFT
- * and RIGHT are pressed to step in the scale.
- */
- double mStepLength;
-
- /**
- * Holds the start value of the scale.
- */
- double mScaleStart;
-
- /**
- * Holds the end value of the scale.
- */
- double mScaleEnd;
-
- /**
- * Holds the orientation of the slider. A slider can be drawn
- * vertically or horizontally.
- */
- OrientationT mOrientation;
-
- ImageCollection *mVertexes A_NONNULLPOINTER;
-
- /**
- * Holds the length of the marker.
- */
- int mMarkerLength;
-
- bool mHasMouse;
-};
-
-#endif // GUI_WIDGETS_SLIDER_H
diff --git a/src/gui/widgets/sliderlist.cpp b/src/gui/widgets/sliderlist.cpp
deleted file mode 100644
index edce0cf02..000000000
--- a/src/gui/widgets/sliderlist.cpp
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/sliderlist.h"
-
-#include "gui/gui.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/models/listmodel.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/label.h"
-
-#include "debug.h"
-
-static const int buttonWidth = 27;
-static const int buttonSpace = 30;
-static const int sliderHeight = 30;
-
-SliderList::SliderList(const Widget2 *const widget,
- ListModel *const listModel) :
- Container(widget),
- ActionListener(),
- MouseListener(),
- mButtons(),
- mLabel(new Label(this)),
- mListModel(listModel),
- mPrevEventId(),
- mNextEventId(),
- mOldWidth(0),
- mSelectedIndex(0)
-{
- mAllowLogic = false;
- setHeight(sliderHeight);
-}
-
-void SliderList::postInit2(ActionListener *const listener,
- const std::string &eventId)
-{
- mPrevEventId = eventId + "_prev";
- mNextEventId = eventId + "_next";
-
- mButtons[0] = new Button(this, "<", mPrevEventId, this);
- mButtons[1] = new Button(this, ">", mNextEventId, this);
-
- add(mButtons[0]);
- add(mLabel);
- add(mButtons[1]);
-
- if (!eventId.empty())
- setActionEventId(eventId);
-
- if (listener != nullptr)
- addActionListener(listener);
-
- updateLabel();
- addMouseListener(this);
-}
-
-SliderList::~SliderList()
-{
-}
-
-void SliderList::updateAlpha()
-{
- Button::updateAlpha();
-}
-
-void SliderList::mouseWheelMovedUp(MouseEvent& event)
-{
- setSelected(mSelectedIndex - 1);
- event.consume();
-}
-
-void SliderList::mouseWheelMovedDown(MouseEvent& event)
-{
- setSelected(mSelectedIndex + 1);
- event.consume();
-}
-
-void SliderList::resize()
-{
- const int width = getWidth();
-
- mButtons[0]->setWidth(buttonWidth);
- mLabel->setWidth(width - buttonSpace * 2);
- mButtons[1]->setPosition(width - buttonSpace + 3, 0);
- mButtons[1]->setWidth(buttonWidth);
- updateLabel();
-}
-
-void SliderList::draw(Graphics *const graphics)
-{
- BLOCK_START("SliderList::draw")
- const int width = mDimension.width;
- if (mOldWidth != width)
- {
- resize();
- mOldWidth = width;
- }
- Container::draw(graphics);
- BLOCK_END("SliderList::draw")
-}
-
-void SliderList::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("SliderList::draw")
- const int width = mDimension.width;
- if (mOldWidth != width)
- {
- resize();
- mOldWidth = width;
- }
- Container::draw(graphics);
- BLOCK_END("SliderList::draw")
-}
-
-void SliderList::updateLabel()
-{
- if ((mListModel == nullptr) || mSelectedIndex < 0
- || mSelectedIndex >= mListModel->getNumberOfElements())
- {
- return;
- }
-
- mLabel->setCaption(mListModel->getElementAt(mSelectedIndex));
- mLabel->adjustSize();
- const int space = mDimension.width - buttonSpace * 2;
- const int labelWidth = mLabel->getWidth();
- int labelY = (mDimension.height - mLabel->getHeight()) / 2;
- if (labelY < 0)
- labelY = 0;
-
- if (space < 0 || space < labelWidth)
- mLabel->setPosition(buttonSpace, labelY);
- else
- mLabel->setPosition(buttonSpace + (space - labelWidth) / 2, labelY);
-}
-
-void SliderList::action(const ActionEvent &event)
-{
- if (mListModel == nullptr)
- return;
-
- const std::string &eventId = event.getId();
- if (eventId == mPrevEventId)
- {
- mSelectedIndex --;
- if (mSelectedIndex < 0)
- mSelectedIndex = mListModel->getNumberOfElements() - 1;
- }
- else if (eventId == mNextEventId)
- {
- mSelectedIndex ++;
- if (mSelectedIndex >= mListModel->getNumberOfElements())
- mSelectedIndex = 0;
- }
- updateLabel();
- distributeActionEvent();
-}
-
-void SliderList::setSelectedString(const std::string &str)
-{
- if (mListModel == nullptr)
- return;
-
- for (int f = 0; f < mListModel->getNumberOfElements(); f ++)
- {
- if (mListModel->getElementAt(f) == str)
- {
- setSelected(f);
- break;
- }
- }
-}
-
-std::string SliderList::getSelectedString() const
-{
- if (mListModel == nullptr)
- return std::string();
-
- return mListModel->getElementAt(mSelectedIndex);
-}
-
-void SliderList::setSelected(const int idx)
-{
- if (mListModel == nullptr)
- return;
-
- mSelectedIndex = idx;
- const int num = mListModel->getNumberOfElements();
- if (mSelectedIndex >= num)
- mSelectedIndex = 0;
- if (mSelectedIndex < 0)
- mSelectedIndex = num - 1;
- updateLabel();
-}
-
-void SliderList::adjustSize()
-{
- setWidth(getMaxLabelWidth() + 60);
- updateLabel();
-}
-
-int SliderList::getMaxLabelWidth() const
-{
- if ((mListModel == nullptr) || (gui == nullptr))
- return 1;
-
- int maxWidth = 0;
- const Font *const font = getFont();
-
- const int num = mListModel->getNumberOfElements();
- for (int f = 0; f < num; f ++)
- {
- const int w = font->getWidth(mListModel->getElementAt(f));
- if (w > maxWidth)
- maxWidth = w;
- }
-
- return maxWidth;
-}
diff --git a/src/gui/widgets/sliderlist.h b/src/gui/widgets/sliderlist.h
deleted file mode 100644
index 6f4336531..000000000
--- a/src/gui/widgets/sliderlist.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_SLIDERLIST_H
-#define GUI_WIDGETS_SLIDERLIST_H
-
-#include "listeners/actionlistener.h"
-#include "listeners/mouselistener.h"
-
-#include "gui/widgets/container.h"
-
-#include "localconsts.h"
-
-class Button;
-class Label;
-class ListModel;
-
-class SliderList final : public Container,
- public ActionListener,
- public MouseListener
-{
- public:
- SliderList(const Widget2 *const widget,
- ListModel *const listModel);
-
- A_DELETE_COPY(SliderList)
-
- ~SliderList();
-
- void postInit2(ActionListener *const listener,
- const std::string &eventId);
-
- void updateAlpha();
-
- void mouseWheelMovedUp(MouseEvent& event) override final;
-
- void mouseWheelMovedDown(MouseEvent& event) override final;
-
- void resize();
-
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void action(const ActionEvent &event) override final;
-
- void setSelectedString(const std::string &str);
-
- std::string getSelectedString() const A_WARN_UNUSED;
-
- void setSelected(const int idx);
-
- void adjustSize();
-
- int getSelected() const noexcept2 A_WARN_UNUSED
- { return mSelectedIndex; }
-
- protected:
- void updateLabel();
-
- int getMaxLabelWidth() const A_WARN_UNUSED;
-
- Button *mButtons[2] A_NONNULLPOINTER;
- Label *mLabel A_NONNULLPOINTER;
- ListModel *mListModel;
- std::string mPrevEventId;
- std::string mNextEventId;
- int mOldWidth;
- int mSelectedIndex;
-};
-
-#endif // GUI_WIDGETS_SLIDERLIST_H
diff --git a/src/gui/widgets/spellshortcutcontainer.cpp b/src/gui/widgets/spellshortcutcontainer.cpp
deleted file mode 100644
index ffa23ffa1..000000000
--- a/src/gui/widgets/spellshortcutcontainer.cpp
+++ /dev/null
@@ -1,371 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/spellshortcutcontainer.h"
-
-#include "dragdrop.h"
-#include "settings.h"
-#include "spellmanager.h"
-
-#include "gui/viewport.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/shortcut/itemshortcut.h"
-#include "gui/shortcut/spellshortcut.h"
-
-#include "gui/popups/popupmenu.h"
-#include "gui/popups/spellpopup.h"
-
-#include "gui/windows/shortcutwindow.h"
-
-#include "debug.h"
-
-SpellShortcutContainer::SpellShortcutContainer(Widget2 *const widget,
- const unsigned number) :
- ShortcutContainer(widget),
- mNumber(number),
- mSpellClicked(false)
-{
- if (spellShortcut != nullptr)
- mMaxItems = spellShortcut->getSpellsCount();
- else
- mMaxItems = 0;
-}
-
-SpellShortcutContainer::~SpellShortcutContainer()
-{
-}
-
-void SpellShortcutContainer::setWidget2(const Widget2 *const widget)
-{
- Widget2::setWidget2(widget);
- mForegroundColor = getThemeColor(ThemeColorId::TEXT);
- mForegroundColor2 = getThemeColor(ThemeColorId::TEXT_OUTLINE);
-}
-
-void SpellShortcutContainer::draw(Graphics *const graphics)
-{
- if (spellShortcut == nullptr)
- return;
-
- BLOCK_START("SpellShortcutContainer::draw")
- if (settings.guiAlpha != mAlpha)
- {
- mAlpha = settings.guiAlpha;
- if (mBackgroundImg != nullptr)
- mBackgroundImg->setAlpha(mAlpha);
- }
-
- Font *const font = getFont();
-
- const int selectedId = spellShortcut->getSelectedItem();
- graphics->setColor(mForegroundColor);
- drawBackground(graphics);
-
- // +++ in future need reorder images and string drawing.
- for (unsigned i = 0; i < mMaxItems; i++)
- {
- const int itemX = (i % mGridWidth) * mBoxWidth;
- const int itemY = (i / mGridWidth) * mBoxHeight;
-
- const int itemId = getItemByIndex(i);
- if (selectedId >= 0 && itemId == selectedId)
- {
- graphics->drawRectangle(Rect(itemX + 1, itemY + 1,
- mBoxWidth - 1, mBoxHeight - 1));
- }
-
- if (spellManager == nullptr)
- continue;
-
- const TextCommand *const spell = spellManager->getSpell(itemId);
- if (spell != nullptr)
- {
- if (!spell->isEmpty())
- {
- Image *const image = spell->getImage();
-
- if (image != nullptr)
- {
- image->setAlpha(1.0F);
- graphics->drawImage(image, itemX, itemY);
- }
- }
-
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor2,
- spell->getSymbol(),
- itemX + 2, itemY + mBoxHeight / 2);
- }
- }
-
- BLOCK_END("SpellShortcutContainer::draw")
-}
-
-void SpellShortcutContainer::safeDraw(Graphics *const graphics)
-{
- if (spellShortcut == nullptr)
- return;
-
- BLOCK_START("SpellShortcutContainer::draw")
- if (settings.guiAlpha != mAlpha)
- {
- mAlpha = settings.guiAlpha;
- if (mBackgroundImg != nullptr)
- mBackgroundImg->setAlpha(mAlpha);
- }
-
- Font *const font = getFont();
-
- const int selectedId = spellShortcut->getSelectedItem();
- graphics->setColor(mForegroundColor);
- safeDrawBackground(graphics);
-
- // +++ in future need reorder images and string drawing.
- for (unsigned i = 0; i < mMaxItems; i++)
- {
- const int itemX = (i % mGridWidth) * mBoxWidth;
- const int itemY = (i / mGridWidth) * mBoxHeight;
-
- const int itemId = getItemByIndex(i);
- if (selectedId >= 0 && itemId == selectedId)
- {
- graphics->drawRectangle(Rect(itemX + 1, itemY + 1,
- mBoxWidth - 1, mBoxHeight - 1));
- }
-
- if (spellManager == nullptr)
- continue;
-
- const TextCommand *const spell = spellManager->getSpell(itemId);
- if (spell != nullptr)
- {
- if (!spell->isEmpty())
- {
- Image *const image = spell->getImage();
-
- if (image != nullptr)
- {
- image->setAlpha(1.0F);
- graphics->drawImage(image, itemX, itemY);
- }
- }
-
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor2,
- spell->getSymbol(),
- itemX + 2, itemY + mBoxHeight / 2);
- }
- }
-
- BLOCK_END("SpellShortcutContainer::draw")
-}
-
-void SpellShortcutContainer::mouseDragged(MouseEvent &event)
-{
- if (event.getButton() == MouseButton::LEFT)
- {
- if (dragDrop.isEmpty() && mSpellClicked)
- {
- mSpellClicked = false;
- const int index = getIndexFromGrid(event.getX(), event.getY());
-
- if (index == -1)
- return;
-
- const int itemId = getItemByIndex(index);
- if (itemId < 0)
- return;
- event.consume();
- TextCommand *const spell = spellManager->getSpell(itemId);
- if (spell != nullptr)
- {
- dragDrop.dragCommand(spell, DragDropSource::Spells, index);
- dragDrop.setItem(spell->getId() + SPELL_MIN_ID);
- }
- else
- {
- dragDrop.clear();
- mSpellClicked = false;
- }
- }
- }
-}
-
-void SpellShortcutContainer::mousePressed(MouseEvent &event)
-{
- const int index = getIndexFromGrid(event.getX(), event.getY());
-
- if (index == -1)
- return;
-
- const MouseButtonT eventButton = event.getButton();
- if (eventButton == MouseButton::LEFT)
- {
- const int itemId = getItemByIndex(index);
- if (itemId > 0)
- mSpellClicked = true;
- event.consume();
- }
- else if (eventButton == MouseButton::MIDDLE)
- {
- if ((spellShortcut == nullptr) || (spellManager == nullptr))
- return;
-
- event.consume();
- const int itemId = getItemByIndex(index);
- spellManager->invoke(itemId);
- }
-}
-
-void SpellShortcutContainer::mouseReleased(MouseEvent &event)
-{
- if ((spellShortcut == nullptr) || (spellManager == nullptr))
- return;
-
- const int index = getIndexFromGrid(event.getX(), event.getY());
-
- if (index == -1)
- {
- dragDrop.clear();
- return;
- }
-
- const int itemId = getItemByIndex(index);
- const MouseButtonT eventButton = event.getButton();
-
- if (eventButton == MouseButton::LEFT)
- {
- mSpellClicked = false;
-
- if (itemId < 0)
- return;
-
- const int selectedId = spellShortcut->getSelectedItem();
- event.consume();
-
- if (!dragDrop.isEmpty())
- {
- if (dragDrop.getSource() == DragDropSource::Spells)
- {
- const int oldIndex = dragDrop.getTag();
- const int idx = mNumber * SPELL_SHORTCUT_ITEMS;
- spellManager->swap(idx + index, idx + oldIndex);
- spellManager->save();
- dragDrop.clear();
- dragDrop.deselect();
- }
- }
- else
- {
- if (selectedId != itemId)
- {
- const TextCommand *const
- spell = spellManager->getSpell(itemId);
- if ((spell != nullptr) && !spell->isEmpty())
- {
- const int num = itemShortcutWindow->getTabIndex();
- if (num >= 0 && num < CAST_S32(SHORTCUT_TABS)
- && (itemShortcut[num] != nullptr))
- {
- itemShortcut[num]->setItemSelected(
- spell->getId() + SPELL_MIN_ID);
- }
- spellShortcut->setItemSelected(spell->getId());
- }
- }
- else
- {
- const int num = itemShortcutWindow->getTabIndex();
- if (num >= 0 && num < CAST_S32(SHORTCUT_TABS)
- && (itemShortcut[num] != nullptr))
- {
- itemShortcut[num]->setItemSelected(-1);
- }
- spellShortcut->setItemSelected(-1);
- }
- }
- }
- else if (eventButton == MouseButton::RIGHT)
- {
- TextCommand *spell = nullptr;
- if (itemId >= 0)
- spell = spellManager->getSpell(itemId);
-
- if ((spell != nullptr) && (popupMenu != nullptr))
- {
- popupMenu->showSpellPopup(viewport->mMouseX,
- viewport->mMouseY,
- spell);
- }
- }
-}
-
-// Show ItemTooltip
-void SpellShortcutContainer::mouseMoved(MouseEvent &event)
-{
- if (spellPopup == nullptr ||
- spellShortcut == nullptr ||
- spellManager == nullptr)
- {
- return;
- }
-
- const int index = getIndexFromGrid(event.getX(), event.getY());
-
- if (index == -1)
- return;
-
- const int itemId = getItemByIndex(index);
- spellPopup->setVisible(Visible_false);
- const TextCommand *const spell = spellManager->getSpell(itemId);
- if ((spell != nullptr) && !spell->isEmpty())
- {
- spellPopup->setItem(spell);
- spellPopup->view(viewport->mMouseX, viewport->mMouseY);
- }
- else
- {
- spellPopup->setVisible(Visible_false);
- }
-}
-
-void SpellShortcutContainer::mouseExited(MouseEvent &event A_UNUSED)
-{
- if (spellPopup != nullptr)
- spellPopup->setVisible(Visible_false);
-}
-
-void SpellShortcutContainer::widgetHidden(const Event &event A_UNUSED)
-{
- if (spellPopup != nullptr)
- spellPopup->setVisible(Visible_false);
-}
-
-int SpellShortcutContainer::getItemByIndex(const int index) const
-{
- return spellShortcut->getItem(
- (mNumber * SPELL_SHORTCUT_ITEMS) + index);
-}
diff --git a/src/gui/widgets/spellshortcutcontainer.h b/src/gui/widgets/spellshortcutcontainer.h
deleted file mode 100644
index 872ca5e1a..000000000
--- a/src/gui/widgets/spellshortcutcontainer.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_SPELLSHORTCUTCONTAINER_H
-#define GUI_WIDGETS_SPELLSHORTCUTCONTAINER_H
-
-#include "gui/widgets/shortcutcontainer.h"
-
-/**
- * An item shortcut container. Used to quickly use items.
- *
- * \ingroup GUI
- */
-class SpellShortcutContainer final : public ShortcutContainer
-{
- public:
- /**
- * Constructor. Initializes the graphic.
- */
- SpellShortcutContainer(Widget2 *const widget,
- const unsigned number);
-
- A_DELETE_COPY(SpellShortcutContainer)
-
- /**
- * Destructor.
- */
- ~SpellShortcutContainer();
-
- /**
- * Draws the items.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Handles mouse when dragged.
- */
- void mouseDragged(MouseEvent &event) override final;
-
- /**
- * Handles mouse when pressed.
- */
- void mousePressed(MouseEvent &event) override final;
-
- /**
- * Handles mouse release.
- */
- void mouseReleased(MouseEvent &event) override final;
-
- void widgetHidden(const Event &event) override final;
-
- void mouseExited(MouseEvent &event) override final;
-
- void mouseMoved(MouseEvent &event) override final;
-
- void setWidget2(const Widget2 *const widget) override final;
-
- int getItemByIndex(const int index) const A_WARN_UNUSED;
-
- private:
- unsigned int mNumber;
- bool mSpellClicked;
-};
-
-#endif // GUI_WIDGETS_SPELLSHORTCUTCONTAINER_H
diff --git a/src/gui/widgets/staticbrowserbox.cpp b/src/gui/widgets/staticbrowserbox.cpp
deleted file mode 100644
index de0d787a7..000000000
--- a/src/gui/widgets/staticbrowserbox.cpp
+++ /dev/null
@@ -1,781 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- * Copyright (C) 2009 Aethyra Development Team
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/staticbrowserbox.h"
-
-#include "enums/gui/linkhighlightmode.h"
-
-#include "gui/gui.h"
-#include "gui/mouseoverlink.h"
-#include "gui/skin.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/widgets/browserbox.inc"
-#include "gui/widgets/linkhandler.h"
-
-#include "render/graphics.h"
-
-#include "resources/imageset.h"
-
-#include "resources/image/image.h"
-
-#include "resources/loaders/imageloader.h"
-#include "resources/loaders/imagesetloader.h"
-
-#include "utils/browserboxtools.h"
-#include "utils/checkutils.h"
-#include "utils/foreach.h"
-#include "utils/stdmove.h"
-#include "utils/stringutils.h"
-#include "utils/translation/podict.h"
-
-#include <algorithm>
-
-#include "debug.h"
-
-ImageSet *StaticBrowserBox::mEmotes = nullptr;
-int StaticBrowserBox::mInstances = 0;
-
-StaticBrowserBox::StaticBrowserBox(const Widget2 *const widget,
- const Opaque opaque,
- const std::string &skin) :
- Widget(widget),
- MouseListener(),
- mTextRows(),
- mTextRowLinksCount(),
- mLineParts(),
- mLinks(),
- mLinkHandler(nullptr),
- mSkin(nullptr),
- mHighlightMode(0),
- mSelectedLink(-1),
- mHeight(0),
- mWidth(0),
- mYStart(0),
- mPadding(0),
- mNewLinePadding(15U),
- mItemPadding(0),
- mHighlightColor(getThemeColor(ThemeColorId::HIGHLIGHT)),
- mHyperLinkColor(getThemeColor(ThemeColorId::HYPERLINK)),
- mOpaque(opaque),
- mUseLinksAndUserColors(true),
- mUseEmotes(true),
- mProcessVars(false),
- mEnableImages(false),
- mEnableKeys(false),
- mEnableTabs(false),
- mSeparator(false)
-{
- mAllowLogic = false;
-
- setFocusable(true);
- addMouseListener(this);
-
- mBackgroundColor = getThemeColor(ThemeColorId::BACKGROUND);
-
- if (theme != nullptr)
- mSkin = theme->load(skin, "browserbox.xml");
- if (mInstances == 0)
- {
- mEmotes = Loader::getImageSet(
- "graphics/sprites/chatemotes.png", 17, 18);
- }
- mInstances ++;
-
- if (mSkin != nullptr)
- {
- mPadding = mSkin->getPadding();
- mNewLinePadding = CAST_U32(
- mSkin->getOption("newLinePadding", 15));
- mItemPadding = mSkin->getOption("itemPadding");
- if (mSkin->getOption("highlightBackground") != 0)
- mHighlightMode |= LinkHighlightMode::BACKGROUND;
- if (mSkin->getOption("highlightUnderline") != 0)
- mHighlightMode |= LinkHighlightMode::UNDERLINE;
- }
-
- readColor(BLACK);
- readColor(RED);
- readColor(GREEN);
- readColor(BLUE);
- readColor(ORANGE);
- readColor(YELLOW);
- readColor(PINK);
- readColor(PURPLE);
- readColor(GRAY);
- readColor(BROWN);
-
- mForegroundColor = getThemeColor(ThemeColorId::BROWSERBOX);
- mForegroundColor2 = getThemeColor(ThemeColorId::BROWSERBOX_OUTLINE);
-}
-
-StaticBrowserBox::~StaticBrowserBox()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- if (theme != nullptr)
- {
- theme->unload(mSkin);
- mSkin = nullptr;
- }
-
- mInstances --;
- if (mInstances == 0)
- {
- if (mEmotes != nullptr)
- {
- mEmotes->decRef();
- mEmotes = nullptr;
- }
- }
-}
-
-void StaticBrowserBox::setLinkHandler(LinkHandler* linkHandler)
-{
- mLinkHandler = linkHandler;
-}
-
-void StaticBrowserBox::addSeparator(const std::string &row)
-{
- if (mSeparator)
- return;
- addRow(row, false);
- mSeparator = true;
-}
-
-void StaticBrowserBox::addRow(const std::string &row,
- const bool atTop)
-{
- std::string tmp = row;
- std::string newRow;
- size_t idx1;
- const Font *const font = getFont();
- int linksCount = 0;
-
- if (getWidth() < 0)
- return;
-
- mSeparator = false;
-
- if (mProcessVars)
- {
- BrowserBoxTools::replaceVars(tmp);
- }
-
- // Use links and user defined colors
- if (mUseLinksAndUserColors)
- {
- BrowserLink bLink;
-
- // Check for links in format "@@link|Caption@@"
- const uint32_t sz = CAST_U32(mTextRows.size());
-
- if (mEnableKeys)
- {
- BrowserBoxTools::replaceKeys(tmp);
- }
-
- idx1 = tmp.find("@@");
- while (idx1 != std::string::npos)
- {
- const size_t idx2 = tmp.find('|', idx1);
- const size_t idx3 = tmp.find("@@", idx2);
-
- if (idx2 == std::string::npos || idx3 == std::string::npos)
- break;
- bLink.link = tmp.substr(idx1 + 2, idx2 - (idx1 + 2));
- bLink.caption = tmp.substr(idx2 + 1, idx3 - (idx2 + 1));
- bLink.y1 = CAST_S32(sz) * font->getHeight();
- bLink.y2 = bLink.y1 + font->getHeight();
- if (bLink.caption.empty())
- {
- bLink.caption = BrowserBoxTools::replaceLinkCommands(
- bLink.link);
- if (translator != nullptr)
- bLink.caption = translator->getStr(bLink.caption);
- }
-
- newRow.append(tmp.substr(0, idx1));
-
- std::string tmp2 = newRow;
- idx1 = tmp2.find("##");
- while (idx1 != std::string::npos)
- {
- tmp2.erase(idx1, 3);
- idx1 = tmp2.find("##");
- }
- bLink.x1 = font->getWidth(tmp2) - 1;
- bLink.x2 = bLink.x1 + font->getWidth(bLink.caption) + 1;
-
- if (atTop)
- mLinks.insert(mLinks.begin(), bLink);
- else
- mLinks.push_back(bLink);
- linksCount ++;
-
- newRow.append("##<").append(bLink.caption);
-
- tmp.erase(0, idx3 + 2);
- if (!tmp.empty())
- newRow.append("##>");
-
- idx1 = tmp.find("@@");
- }
-
- newRow.append(tmp);
- }
- // Don't use links and user defined colors
- else
- {
- newRow = row;
- }
-
- if (mEnableTabs)
- {
- BrowserBoxTools::replaceTabs(newRow);
- }
-
- if (atTop)
- {
- mTextRows.push_front(newRow);
- mTextRowLinksCount.push_front(linksCount);
- }
- else
- {
- mTextRows.push_back(newRow);
- mTextRowLinksCount.push_back(linksCount);
- }
-
- std::string plain = STD_MOVE(newRow);
- // workaround if used only one string started from bold
- // width for this string can be calculated wrong
- // this workaround fix width if string start from bold sign
- const bool startBold = (plain.find("##B") == 0);
- for (idx1 = plain.find("##");
- idx1 != std::string::npos;
- idx1 = plain.find("##"))
- {
- plain.erase(idx1, 3);
- }
-
- // Adjust the StaticBrowserBox size. This need only for implementing "---"
- const int w = startBold ?
- boldFont->getWidth(plain) : font->getWidth(plain) + 2 * mPadding;
- if (w > getWidth())
- setWidth(w);
-}
-
-void StaticBrowserBox::addRow(const std::string &cmd,
- const char *const text)
-{
- addRow(strprintf("@@%s|%s@@", encodeLinkText(cmd).c_str(),
- encodeLinkText(text).c_str()));
-}
-
-void StaticBrowserBox::addImage(const std::string &path)
-{
- if (!mEnableImages)
- return;
-
- mTextRows.push_back("~~~" + path);
- mTextRowLinksCount.push_back(0);
-}
-
-void StaticBrowserBox::clearRows()
-{
- mTextRows.clear();
- mTextRowLinksCount.clear();
- mLinks.clear();
- setWidth(0);
- setHeight(0);
- mSelectedLink = -1;
-}
-
-void StaticBrowserBox::mousePressed(MouseEvent &event)
-{
- if (mLinkHandler == nullptr)
- return;
-
- const LinkIterator i = std::find_if(mLinks.begin(), mLinks.end(),
- MouseOverLink(event.getX(), event.getY()));
-
- if (i != mLinks.end())
- {
- mLinkHandler->handleLink(i->link, &event);
- event.consume();
- }
-}
-
-void StaticBrowserBox::mouseMoved(MouseEvent &event)
-{
- const LinkIterator i = std::find_if(mLinks.begin(), mLinks.end(),
- MouseOverLink(event.getX(), event.getY()));
-
- mSelectedLink = (i != mLinks.end())
- ? CAST_S32(i - mLinks.begin()) : -1;
-}
-
-void StaticBrowserBox::mouseExited(MouseEvent &event A_UNUSED)
-{
- mSelectedLink = -1;
-}
-
-void StaticBrowserBox::draw(Graphics *const graphics)
-{
- BLOCK_START("StaticBrowserBox::draw")
- const ClipRect &cr = graphics->getTopClip();
- mYStart = cr.y - cr.yOffset;
- const int yEnd = mYStart + cr.height;
- if (mYStart < 0)
- mYStart = 0;
-
- if (mDimension.width != mWidth)
- {
- updateHeight();
- reportAlways("browserbox resize in draw: %d, %d",
- mDimension.width,
- mWidth);
- }
-
- if (mOpaque == Opaque_true)
- {
- graphics->setColor(mBackgroundColor);
- graphics->fillRectangle(Rect(0, 0,
- mDimension.width, mDimension.height));
- }
-
- if (mSelectedLink >= 0 &&
- mSelectedLink < CAST_S32(mLinks.size()))
- {
- if ((mHighlightMode & LinkHighlightMode::BACKGROUND) != 0u)
- {
- BrowserLink &link = mLinks[CAST_SIZE(mSelectedLink)];
- graphics->setColor(mHighlightColor);
- graphics->fillRectangle(Rect(
- link.x1,
- link.y1,
- link.x2 - link.x1,
- link.y2 - link.y1));
- }
-
- if ((mHighlightMode & LinkHighlightMode::UNDERLINE) != 0u)
- {
- BrowserLink &link = mLinks[CAST_SIZE(mSelectedLink)];
- graphics->setColor(mHyperLinkColor);
- graphics->drawLine(
- link.x1,
- link.y2,
- link.x2,
- link.y2);
- }
- }
-
- Font *const font = getFont();
-
- FOR_EACH (LinePartCIter, i, mLineParts)
- {
- const LinePart &part = *i;
- if (part.mY + 50 < mYStart)
- continue;
- if (part.mY > yEnd)
- break;
- if (part.mType == 0u)
- {
- if (part.mBold)
- {
- boldFont->drawString(graphics,
- part.mColor,
- part.mColor2,
- part.mText,
- part.mX, part.mY);
- }
- else
- {
- font->drawString(graphics,
- part.mColor,
- part.mColor2,
- part.mText,
- part.mX, part.mY);
- }
- }
- else if (part.mImage != nullptr)
- {
- graphics->drawImage(part.mImage, part.mX, part.mY);
- }
- }
-
- BLOCK_END("StaticBrowserBox::draw")
-}
-
-void StaticBrowserBox::safeDraw(Graphics *const graphics)
-{
- StaticBrowserBox::draw(graphics);
-}
-
-void StaticBrowserBox::updateHeight()
-{
- unsigned int y = CAST_U32(mPadding);
- int moreHeight = 0;
- int link = 0;
- bool bold = false;
- const unsigned int wWidth = CAST_U32(mDimension.width - mPadding);
- const Font *const font = getFont();
- const int fontHeight = font->getHeight() + 2 * mItemPadding;
- const int fontWidthMinus = font->getWidth("-");
-
- Color selColor[2] = {mForegroundColor, mForegroundColor2};
- const Color textColor[2] = {mForegroundColor, mForegroundColor2};
- mLineParts.clear();
- uint32_t dataWidth = 0;
-
- if (mSeparator)
- {
- mSeparator = false;
- mTextRows.pop_back();
- }
-
- FOR_EACH (TextRowCIter, i, mTextRows)
- {
- unsigned int x = CAST_U32(mPadding);
- const std::string row = *(i);
- int objects = 0;
-
- // Check for separator lines
- if (row.find("---", 0) == 0)
- {
- const int dashWidth = fontWidthMinus;
- for (x = CAST_U32(mPadding); x < wWidth; x ++)
- {
- mLineParts.push_back(LinePart(CAST_S32(x),
- CAST_S32(y) + mItemPadding,
- selColor[0], selColor[1], "-", false));
- x += CAST_U32(CAST_S32(
- dashWidth) - 2);
- }
-
- y += CAST_U32(fontHeight);
- continue;
- }
- else if (mEnableImages && row.find("~~~", 0) == 0)
- {
- std::string str = row.substr(3);
- const size_t sz = str.size();
- if (sz > 2 && str.substr(sz - 1) == "~")
- str = str.substr(0, sz - 1);
- Image *const img = Loader::getImage(str);
- if (img != nullptr)
- {
- img->incRef();
- mLineParts.push_back(LinePart(CAST_S32(x),
- CAST_S32(y) + mItemPadding,
- selColor[0], selColor[1], img));
- y += CAST_U32(img->getHeight() + 2);
- moreHeight += img->getHeight();
- if (img->getWidth() + mPadding + 2 > CAST_S32(dataWidth))
- dataWidth = img->getWidth() + 2 + mPadding;
- }
- continue;
- }
-
- Color prevColor[2];
- prevColor[0] = selColor[0];
- prevColor[1] = selColor[1];
- bold = false;
-
- for (size_t start = 0, end = std::string::npos;
- start != std::string::npos;
- start = end, end = std::string::npos)
- {
- size_t idx1 = end;
- size_t idx2 = end;
-
- // "Tokenize" the string at control sequences
- if (mUseLinksAndUserColors)
- idx1 = row.find("##", start + 1);
- if (start == 0 || mUseLinksAndUserColors)
- {
- // Check for color change in format "##x", x = [L,P,0..9]
- if (row.find("##", start) == start && row.size() > start + 2)
- {
- const signed char c = row.at(start + 2);
-
- bool valid(false);
- const Color col[2] =
- {
- getThemeCharColor(c, valid),
- getThemeCharColor(CAST_S8(
- c | 0x80), valid)
- };
-
- if (c == '>')
- {
- selColor[0] = prevColor[0];
- selColor[1] = prevColor[1];
- }
- else if (c == '<')
- {
- prevColor[0] = selColor[0];
- prevColor[1] = selColor[1];
- selColor[0] = col[0];
- selColor[1] = col[1];
- }
- else if (c == 'B')
- {
- bold = true;
- }
- else if (c == 'b')
- {
- bold = false;
- }
- else if (valid)
- {
- selColor[0] = col[0];
- selColor[1] = col[1];
- }
- else
- {
- switch (c)
- {
- case '0':
- selColor[0] = mColors[0][ColorName::BLACK];
- selColor[1] = mColors[1][ColorName::BLACK];
- break;
- case '1':
- selColor[0] = mColors[0][ColorName::RED];
- selColor[1] = mColors[1][ColorName::RED];
- break;
- case '2':
- selColor[0] = mColors[0][ColorName::GREEN];
- selColor[1] = mColors[1][ColorName::GREEN];
- break;
- case '3':
- selColor[0] = mColors[0][ColorName::BLUE];
- selColor[1] = mColors[1][ColorName::BLUE];
- break;
- case '4':
- selColor[0] = mColors[0][ColorName::ORANGE];
- selColor[1] = mColors[1][ColorName::ORANGE];
- break;
- case '5':
- selColor[0] = mColors[0][ColorName::YELLOW];
- selColor[1] = mColors[1][ColorName::YELLOW];
- break;
- case '6':
- selColor[0] = mColors[0][ColorName::PINK];
- selColor[1] = mColors[1][ColorName::PINK];
- break;
- case '7':
- selColor[0] = mColors[0][ColorName::PURPLE];
- selColor[1] = mColors[1][ColorName::PURPLE];
- break;
- case '8':
- selColor[0] = mColors[0][ColorName::GRAY];
- selColor[1] = mColors[1][ColorName::GRAY];
- break;
- case '9':
- selColor[0] = mColors[0][ColorName::BROWN];
- selColor[1] = mColors[1][ColorName::BROWN];
- break;
- default:
- selColor[0] = textColor[0];
- selColor[1] = textColor[1];
- break;
- }
- }
-
- if (c == '<' && link < CAST_S32(mLinks.size()))
- {
- int size;
- if (bold)
- {
- size = boldFont->getWidth(
- mLinks[CAST_SIZE(link)].caption) + 1;
- }
- else
- {
- size = font->getWidth(
- mLinks[CAST_SIZE(link)].caption) + 1;
- }
-
- BrowserLink &linkRef = mLinks[CAST_SIZE(
- link)];
- linkRef.x1 = CAST_S32(x);
- linkRef.y1 = CAST_S32(y);
- linkRef.x2 = linkRef.x1 + size;
- linkRef.y2 = CAST_S32(y) + fontHeight - 1;
- link++;
- }
-
- start += 3;
- if (start == row.size())
- break;
- }
- }
- if (mUseEmotes)
- idx2 = row.find("%%", start + 1);
- if (idx1 < idx2)
- end = idx1;
- else
- end = idx2;
- if (mUseEmotes)
- {
- // check for emote icons
- if (row.size() > start + 2 && row.substr(start, 2) == "%%")
- {
- if (objects < 5)
- {
- const int cid = row.at(start + 2) - '0';
- if (cid >= 0)
- {
- if (mEmotes != nullptr)
- {
- const size_t sz = mEmotes->size();
- if (CAST_SIZE(cid) < sz)
- {
- Image *const img = mEmotes->get(
- CAST_SIZE(cid));
- if (img != nullptr)
- {
- mLineParts.push_back(LinePart(
- CAST_S32(x),
- CAST_S32(y) + mItemPadding,
- selColor[0], selColor[1], img));
- x += 18;
- }
- }
- }
- }
- objects ++;
- }
-
- start += 3;
- if (start == row.size())
- {
- if (x > dataWidth)
- dataWidth = x;
- break;
- }
- }
- }
- const size_t len = (end == std::string::npos) ? end : end - start;
-
- if (start >= row.length())
- break;
-
- std::string part = row.substr(start, len);
-
- mLineParts.push_back(LinePart(CAST_S32(x),
- CAST_S32(y) + mItemPadding,
- selColor[0], selColor[1], part.c_str(), bold));
-
- int width = 0;
- if (bold)
- width = boldFont->getWidth(part);
- else
- width = font->getWidth(part);
-
- x += CAST_U32(width);
- if (x > dataWidth)
- dataWidth = x;
- }
- y += CAST_U32(fontHeight);
- }
- mWidth = dataWidth + mPadding;
- mHeight = CAST_S32(mTextRows.size())
- * fontHeight + moreHeight + 2 * mPadding;
- setSize(mWidth,
- mHeight);
-}
-
-std::string StaticBrowserBox::getTextAtPos(const int x,
- const int y) const
-{
- int textX = 0;
- int textY = 0;
-
- getAbsolutePosition(textX, textY);
- if (x < textX || y < textY)
- return std::string();
-
- textY = y - textY;
- std::string str;
- int lastY = 0;
-
- FOR_EACH (LinePartCIter, i, mLineParts)
- {
- const LinePart &part = *i;
- if (part.mY + 50 < mYStart)
- continue;
- if (part.mY > textY)
- break;
-
- if (part.mY > lastY)
- {
- str = part.mText;
- lastY = part.mY;
- }
- else
- {
- str.append(part.mText);
- }
- }
-
- return str;
-}
-
-void StaticBrowserBox::setForegroundColorAll(const Color &color1,
- const Color &color2)
-{
- mForegroundColor = color1;
- mForegroundColor2 = color2;
-}
-
-void StaticBrowserBox::moveSelectionUp()
-{
- if (mSelectedLink <= 0)
- mSelectedLink = CAST_S32(mLinks.size()) - 1;
- else
- mSelectedLink --;
-}
-
-void StaticBrowserBox::moveSelectionDown()
-{
- mSelectedLink ++;
- if (mSelectedLink >= static_cast<signed int>(mLinks.size()))
- mSelectedLink = 0;
-}
-
-void StaticBrowserBox::selectSelection()
-{
- if ((mLinkHandler == nullptr) ||
- mSelectedLink < 0 ||
- mSelectedLink >= static_cast<signed int>(mLinks.size()))
- {
- return;
- }
-
- mLinkHandler->handleLink(mLinks[CAST_SIZE(mSelectedLink)].link,
- nullptr);
-}
diff --git a/src/gui/widgets/staticbrowserbox.h b/src/gui/widgets/staticbrowserbox.h
deleted file mode 100644
index ff5862577..000000000
--- a/src/gui/widgets/staticbrowserbox.h
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- * Copyright (C) 2009 Aethyra Development Team
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_STATICBROWSERBOX_H
-#define GUI_WIDGETS_STATICBROWSERBOX_H
-
-#include "enums/simpletypes/opaque.h"
-
-#include "enums/gui/colorname.h"
-
-#include "gui/browserlink.h"
-
-#include "gui/widgets/linepart.h"
-#include "gui/widgets/widget.h"
-
-#include "listeners/mouselistener.h"
-
-#include "localconsts.h"
-
-class LinkHandler;
-
-/**
- * A simple browser box able to handle links and forward events to the
- * parent conteiner.
- */
-class StaticBrowserBox final : public Widget,
- public MouseListener
-{
- public:
- /**
- * Constructor.
- */
- StaticBrowserBox(const Widget2 *const widget,
- const Opaque opaque,
- const std::string &skin);
-
- A_DELETE_COPY(StaticBrowserBox)
-
- /**
- * Destructor.
- */
- ~StaticBrowserBox();
-
- /**
- * Sets the handler for links.
- */
- void setLinkHandler(LinkHandler *linkHandler);
-
- /**
- * Sets the StaticBrowserBox opacity.
- */
- void setOpaque(Opaque opaque)
- { mOpaque = opaque; }
-
- void addSeparator(const std::string &row);
-
- /**
- * Adds a text row to the browser.
- */
- void addRow(const std::string &row,
- const bool atTop = false);
-
- /**
- * Adds a menu line to the browser.
- */
- void addRow(const std::string &cmd,
- const char *const text);
-
- void addImage(const std::string &path);
-
- /**
- * Remove all rows.
- */
- void clearRows();
-
- /**
- * Handles mouse actions.
- */
- void mousePressed(MouseEvent &event) override final;
-
- void mouseMoved(MouseEvent &event) override final;
-
- void mouseExited(MouseEvent& event) override final;
-
- /**
- * Draws the browser box.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void updateHeight();
-
- void updateSize();
-
- typedef std::list<std::string> TextRows;
-
- TextRows &getRows() noexcept2 A_WARN_UNUSED
- { return mTextRows; }
-
- bool hasRows() const noexcept2 A_WARN_UNUSED
- { return !mTextRows.empty(); }
-
- void setProcessVars(const bool n) noexcept2
- { mProcessVars = n; }
-
- void setEnableImages(const bool n) noexcept2
- { mEnableImages = n; }
-
- void setEnableKeys(const bool n) noexcept2
- { mEnableKeys = n; }
-
- void setEnableTabs(const bool n) noexcept2
- { mEnableTabs = n; }
-
- std::string getTextAtPos(const int x,
- const int y) const A_WARN_UNUSED;
-
- int getPadding() const noexcept2 A_WARN_UNUSED
- { return mPadding; }
-
- void setForegroundColorAll(const Color &color1,
- const Color &color2);
-
- void moveSelectionUp();
-
- void moveSelectionDown();
-
- void selectSelection();
-
- private:
- typedef TextRows::iterator TextRowIterator;
- typedef TextRows::const_iterator TextRowCIter;
- TextRows mTextRows;
- std::list<int> mTextRowLinksCount;
-
- typedef STD_VECTOR<LinePart> LinePartList;
- typedef LinePartList::iterator LinePartIterator;
- typedef LinePartList::const_iterator LinePartCIter;
- LinePartList mLineParts;
-
- typedef STD_VECTOR<BrowserLink> Links;
- typedef Links::iterator LinkIterator;
- Links mLinks;
-
- LinkHandler *mLinkHandler;
- Skin *mSkin;
- unsigned int mHighlightMode;
- int mSelectedLink;
- int mHeight;
- int mWidth;
- int mYStart;
- int mPadding;
- unsigned int mNewLinePadding;
- int mItemPadding;
-
- Color mHighlightColor;
- Color mHyperLinkColor;
- Color mColors[2][ColorName::COLORS_MAX];
-
- Opaque mOpaque;
- bool mUseLinksAndUserColors;
- bool mUseEmotes;
- bool mProcessVars;
- bool mEnableImages;
- bool mEnableKeys;
- bool mEnableTabs;
- bool mSeparator;
-
- static ImageSet *mEmotes;
- static int mInstances;
-};
-
-#endif // GUI_WIDGETS_STATICBROWSERBOX_H
diff --git a/src/gui/widgets/statspage.cpp b/src/gui/widgets/statspage.cpp
deleted file mode 100644
index 0540b1a24..000000000
--- a/src/gui/widgets/statspage.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/statspage.h"
-
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/vertcontainer.h"
-
-#include "gui/widgets/attrs/derdisplay.h"
-
-#include "utils/foreach.h"
-
-#include "resources/db/statdb.h"
-
-#include "debug.h"
-
-StatsPage::StatsPage(const Widget2 *const widget,
- const std::string &page) :
- Container(widget),
- WidgetListener(),
- AttributeListener(),
- StatListener(),
- mAttrs(),
- mAttrCont(new VertContainer(this, 32)),
- mAttrScroll(new ScrollArea(this, mAttrCont, Opaque_false))
-{
- addWidgetListener(this);
- setSelectable(false);
-
- mAttrScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- mAttrScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO);
- mAttrScroll->setSelectable(false);
- mAttrCont->setSelectable(false);
-
- add(mAttrScroll);
- const STD_VECTOR<BasicStat> &basicStats = StatDb::getStats(page);
- FOR_EACH (STD_VECTOR<BasicStat>::const_iterator, it, basicStats)
- {
- const BasicStat &stat = *it;
- AttrDisplay *disp = new DerDisplay(this,
- stat.attr,
- stat.name,
- stat.tag);
- disp->update();
- mAttrCont->add2(disp, true);
- mAttrs[stat.attr] = disp;
- }
-}
-
-void StatsPage::widgetResized(const Event &event A_UNUSED)
-{
- mAttrScroll->setSize(getWidth(), getHeight());
-}
-
-void StatsPage::attributeChanged(const AttributesT id,
- const int64_t oldVal A_UNUSED,
- const int64_t newVal A_UNUSED)
-{
- const Attrs::const_iterator it = mAttrs.find(id);
- if (it != mAttrs.end() && (it->second != nullptr))
- it->second->update();
-}
-
-void StatsPage::statChanged(const AttributesT id,
- const int oldVal1 A_UNUSED,
- const int oldVal2 A_UNUSED)
-{
- const Attrs::const_iterator it = mAttrs.find(id);
- if (it != mAttrs.end() && (it->second != nullptr))
- it->second->update();
-}
diff --git a/src/gui/widgets/statspage.h b/src/gui/widgets/statspage.h
deleted file mode 100644
index ad62aebeb..000000000
--- a/src/gui/widgets/statspage.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_STATSPAGE_H
-#define GUI_WIDGETS_STATSPAGE_H
-
-#include "gui/widgets/attrs/attrdisplay.h"
-
-#include "listeners/attributelistener.h"
-#include "listeners/statlistener.h"
-
-#include "localconsts.h"
-
-class ScrollArea;
-class VertContainer;
-
-class StatsPage final : public Container,
- public WidgetListener,
- public AttributeListener,
- public StatListener
-{
- public:
- StatsPage(const Widget2 *const widget,
- const std::string &page);
-
- A_DELETE_COPY(StatsPage)
-
- void widgetResized(const Event &event) override final;
-
- void attributeChanged(const AttributesT id,
- const int64_t oldVal,
- const int64_t newVal) override final;
-
- void statChanged(const AttributesT id,
- const int oldVal1,
- const int oldVal2) override final;
-
- private:
- Attrs mAttrs;
- VertContainer *mAttrCont A_NONNULLPOINTER;
- ScrollArea *mAttrScroll A_NONNULLPOINTER;
-};
-
-#endif // GUI_WIDGETS_STATSPAGE_H
diff --git a/src/gui/widgets/statspagebasic.cpp b/src/gui/widgets/statspagebasic.cpp
deleted file mode 100644
index 249d4f337..000000000
--- a/src/gui/widgets/statspagebasic.cpp
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/statspagebasic.h"
-
-#include "being/playerinfo.h"
-
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/vertcontainer.h"
-
-#include "gui/widgets/attrs/changedisplay.h"
-
-#include "utils/gettext.h"
-#include "utils/foreach.h"
-#include "utils/stringutils.h"
-
-#include "resources/db/statdb.h"
-
-#include "debug.h"
-
-StatsPageBasic::StatsPageBasic(const Widget2 *const widget) :
- Container(widget),
- WidgetListener(),
- AttributeListener(),
- StatListener(),
- mAttrs(),
- mAttrCont(new VertContainer(this, 32)),
- mAttrScroll(new ScrollArea(this, mAttrCont, Opaque_false)),
- mCharacterPointsLabel(new Label(this, "C"))
-{
- addWidgetListener(this);
- setSelectable(false);
-
- mAttrScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- mAttrScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO);
- mAttrScroll->setSelectable(false);
- mAttrCont->setSelectable(false);
-
- add(mAttrScroll);
- const STD_VECTOR<BasicStat> &basicStats = StatDb::getBasicStats();
- FOR_EACH (STD_VECTOR<BasicStat>::const_iterator, it, basicStats)
- {
- const BasicStat &stat = *it;
- AttrDisplay *disp = new ChangeDisplay(this,
- stat.attr,
- stat.name,
- stat.tag);
- disp->update();
- mAttrCont->add2(disp, true);
- mAttrs[stat.attr] = disp;
- }
-
- // TRANSLATORS: status window label
- mCharacterPointsLabel->setCaption(strprintf(_("Character points: %d"),
- PlayerInfo::getAttribute(Attributes::PLAYER_CHAR_POINTS)));
- mCharacterPointsLabel->adjustSize();
- mAttrCont->add1(mCharacterPointsLabel);
-}
-
-void StatsPageBasic::widgetResized(const Event &event A_UNUSED)
-{
- mAttrScroll->setSize(getWidth(), getHeight());
-}
-
-void StatsPageBasic::statChanged(const AttributesT id,
- const int oldVal1 A_UNUSED,
- const int oldVal2 A_UNUSED)
-{
- const Attrs::const_iterator it = mAttrs.find(id);
- if (it != mAttrs.end() && (it->second != nullptr))
- it->second->update();
-}
-
-void StatsPageBasic::attributeChanged(const AttributesT id,
- const int64_t oldVal A_UNUSED,
- const int64_t newVal)
-{
- PRAGMA45(GCC diagnostic push)
- PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
- switch (id)
- {
- case Attributes::PLAYER_CHAR_POINTS:
- mCharacterPointsLabel->setCaption(strprintf(
- // TRANSLATORS: status window label
- _("Character points: %d"), CAST_S32(newVal)));
-
- mCharacterPointsLabel->adjustSize();
- // Update all attributes
- for (Attrs::const_iterator it = mAttrs.begin();
- it != mAttrs.end(); ++it)
- {
- if (it->second != nullptr)
- it->second->update();
- }
- return;
-
- case Attributes::PLAYER_CORR_POINTS:
- // Update all attributes
- for (Attrs::const_iterator it = mAttrs.begin();
- it != mAttrs.end(); ++it)
- {
- if (it->second != nullptr)
- it->second->update();
- }
- return;
-
- default:
- break;
- }
- PRAGMA45(GCC diagnostic pop)
- const Attrs::const_iterator it = mAttrs.find(id);
- if (it != mAttrs.end() && (it->second != nullptr))
- it->second->update();
-}
-
-void StatsPageBasic::setPointsNeeded(const AttributesT id,
- const int needed)
-{
- const Attrs::const_iterator it = mAttrs.find(id);
-
- if (it != mAttrs.end())
- {
- AttrDisplay *const disp = it->second;
- if ((disp != nullptr) && disp->getType() == AttrDisplay::CHANGEABLE)
- static_cast<ChangeDisplay*>(disp)->setPointsNeeded(needed);
- }
-}
-
-std::string StatsPageBasic::getStatsStr() const
-{
- Attrs::const_iterator it = mAttrs.begin();
- const Attrs::const_iterator it_end = mAttrs.end();
- std::string str;
- while (it != it_end)
- {
- const ChangeDisplay *const attr = dynamic_cast<ChangeDisplay*>(
- (*it).second);
- if (attr != nullptr)
- {
- str.append(strprintf("%s:%s ", attr->getShortName().c_str(),
- attr->getValue().c_str()));
- }
- ++ it;
- }
- return str;
-}
diff --git a/src/gui/widgets/statspagebasic.h b/src/gui/widgets/statspagebasic.h
deleted file mode 100644
index d56b8aeff..000000000
--- a/src/gui/widgets/statspagebasic.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_STATSPAGEBASIC_H
-#define GUI_WIDGETS_STATSPAGEBASIC_H
-
-#include "gui/widgets/attrs/attrdisplay.h"
-
-#include "listeners/attributelistener.h"
-#include "listeners/statlistener.h"
-
-#include "localconsts.h"
-
-class Label;
-class ScrollArea;
-class VertContainer;
-
-class StatsPageBasic final : public Container,
- public WidgetListener,
- public AttributeListener,
- public StatListener
-{
- public:
- explicit StatsPageBasic(const Widget2 *const widget);
-
- A_DELETE_COPY(StatsPageBasic)
-
- void widgetResized(const Event &event) override final;
-
- void attributeChanged(const AttributesT id,
- const int64_t oldVal,
- const int64_t newVal) override final;
-
- void statChanged(const AttributesT id,
- const int oldVal1,
- const int oldVal2) override final;
-
- void setPointsNeeded(const AttributesT id,
- const int needed);
-
- std::string getStatsStr() const;
-
- private:
- Attrs mAttrs;
- VertContainer *mAttrCont A_NONNULLPOINTER;
- ScrollArea *mAttrScroll A_NONNULLPOINTER;
- Label *mCharacterPointsLabel A_NONNULLPOINTER;
-};
-
-#endif // GUI_WIDGETS_STATSPAGEBASIC_H
diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp
deleted file mode 100644
index e89f60418..000000000
--- a/src/gui/widgets/tabbedarea.cpp
+++ /dev/null
@@ -1,827 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/tabbedarea.h"
-
-#include "gui/gui.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/tabs/tab.h"
-
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-
-#include "debug.h"
-
-TabbedArea::TabbedArea(const Widget2 *const widget) :
- ActionListener(),
- BasicContainer(widget),
- KeyListener(),
- MouseListener(),
- WidgetListener(),
- mArrowButton(),
- mSelectedTab(nullptr),
- mTabContainer(new BasicContainer2(widget)),
- mWidgetContainer(new BasicContainer2(widget)),
- mTabsToDelete(),
- mTabs(),
- mTabsWidth(0),
- mVisibleTabsWidth(0),
- mTabScrollIndex(0),
- mRightMargin(0),
- mOpaque(Opaque_false),
- mEnableScrollButtons(false),
- mFollowDownScroll(false),
- mBlockSwitching(true),
- mResizeHeight(true)
-{
- setFocusable(true);
- addKeyListener(this);
- addMouseListener(this);
-}
-
-void TabbedArea::postInit()
-{
- mTabContainer->setOpaque(Opaque_false);
-
- add(mTabContainer);
- add(mWidgetContainer);
-
- mWidgetContainer->setOpaque(Opaque_false);
- addWidgetListener(this);
-
- mArrowButton[0] = new Button(this, "<", "shift_left", this);
- mArrowButton[1] = new Button(this, ">", "shift_right", this);
-
- widgetResized(Event(nullptr));
-}
-
-TabbedArea::~TabbedArea()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- // +++ virtual method calls
- remove(mTabContainer);
- remove(mWidgetContainer);
-
- delete2(mTabContainer);
- delete2(mWidgetContainer);
-
- for (size_t i = 0, sz = mTabsToDelete.size(); i < sz; i++)
- delete2(mTabsToDelete[i])
-
- delete2(mArrowButton[0]);
- delete2(mArrowButton[1]);
-}
-
-void TabbedArea::enableScrollButtons(const bool enable)
-{
- if (mEnableScrollButtons && !enable)
- {
- if (mArrowButton[0] != nullptr)
- remove(mArrowButton[0]);
- if (mArrowButton[1] != nullptr)
- remove(mArrowButton[1]);
- }
- else if (!mEnableScrollButtons && enable)
- {
- if (mArrowButton[0] != nullptr)
- add(mArrowButton[0]);
- if (mArrowButton[1] != nullptr)
- add(mArrowButton[1]);
- }
- mEnableScrollButtons = enable;
-}
-
-int TabbedArea::getNumberOfTabs() const
-{
- return CAST_S32(mTabs.size());
-}
-
-Tab *TabbedArea::getTab(const std::string &name) const
-{
- TabContainer::const_iterator itr = mTabs.begin();
- const TabContainer::const_iterator itr_end = mTabs.end();
- while (itr != itr_end)
- {
- if ((*itr).first->getCaption() == name)
- return static_cast<Tab*>((*itr).first);
-
- ++itr;
- }
- return nullptr;
-}
-
-void TabbedArea::draw(Graphics *const graphics)
-{
- BLOCK_START("TabbedArea::draw")
- if (mTabs.empty())
- {
- BLOCK_END("TabbedArea::draw")
- return;
- }
-
- drawChildren(graphics);
- BLOCK_END("TabbedArea::draw")
-}
-
-void TabbedArea::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("TabbedArea::draw")
- if (mTabs.empty())
- {
- BLOCK_END("TabbedArea::draw")
- return;
- }
-
- safeDrawChildren(graphics);
- BLOCK_END("TabbedArea::draw")
-}
-
-Widget *TabbedArea::getWidget(const std::string &name) const
-{
- TabContainer::const_iterator itr = mTabs.begin();
- const TabContainer::const_iterator itr_end = mTabs.end();
- while (itr != itr_end)
- {
- if ((*itr).first->getCaption() == name)
- return (*itr).second;
-
- ++itr;
- }
-
- return nullptr;
-}
-
-Widget *TabbedArea::getCurrentWidget() const
-{
- const Tab *const tab = getSelectedTab();
-
- if (tab != nullptr)
- return getWidget(tab->getCaption());
- return nullptr;
-}
-
-void TabbedArea::addTab(Tab *const tab,
- Widget *const widget)
-{
- if ((tab == nullptr) || (widget == nullptr))
- return;
-
- tab->setTabbedArea(this);
- tab->addActionListener(this);
-
- mTabContainer->add(tab);
- mTabs.push_back(std::pair<Tab*, Widget*>(tab, widget));
-
- if ((mSelectedTab == nullptr) && tab->mVisible == Visible_true)
- setSelectedTab(tab);
-
- adjustTabPositions();
- adjustSize();
-
- const int frameSize = 2 * mFrameSize;
- widget->setSize(getWidth() - frameSize,
- getHeight() - frameSize - mTabContainer->getHeight());
-
- widgetResized(Event(nullptr));
- updateTabsWidth();
- updateArrowEnableState();
-}
-
-void TabbedArea::adjustWidget(Widget *const widget) const
-{
- if (widget == nullptr)
- return;
- const int frameSize = 2 * mFrameSize;
- widget->setSize(getWidth() - frameSize,
- getHeight() - frameSize - mTabContainer->getHeight());
-}
-
-void TabbedArea::addTab(const std::string &caption, Widget *const widget)
-{
- Tab *const tab = new Tab(this);
- tab->setCaption(caption);
- mTabsToDelete.push_back(tab);
-
- addTab(tab, widget);
-}
-
-void TabbedArea::addTab(Image *const image, Widget *const widget)
-{
- Tab *const tab = new Tab(this);
- tab->setImage(image);
- mTabsToDelete.push_back(tab);
-
- addTab(tab, widget);
-}
-
-bool TabbedArea::isTabSelected(const size_t index) const
-{
- if (index >= mTabs.size())
- return false;
-
- return mSelectedTab == mTabs[index].first;
-}
-
-bool TabbedArea::isTabPresent(const Tab *const tab) const
-{
- FOR_EACH (TabContainer::const_iterator, it, mTabs)
- {
- if ((*it).first == tab || (*it).second == tab)
- return true;
- }
- return false;
-}
-
-bool TabbedArea::isTabSelected(const Tab *const tab) const
-{
- return mSelectedTab == tab;
-}
-
-void TabbedArea::setSelectedTabByIndex(const size_t index)
-{
- if (index >= mTabs.size())
- return;
-
- setSelectedTab(mTabs[index].first);
-}
-
-void TabbedArea::removeTab(Tab *const tab)
-{
- int tabIndexToBeSelected = -1;
-
- if (tab == mSelectedTab)
- {
- const int index = getSelectedTabIndex();
- const size_t sz = mTabs.size();
- if (index == CAST_S32(sz) - 1 && sz == 1)
- tabIndexToBeSelected = -1;
- else
- tabIndexToBeSelected = index - 1;
- }
-
- for (TabContainer::iterator iter = mTabs.begin();
- iter != mTabs.end(); ++iter)
- {
- if (iter->first == tab)
- {
- mTabContainer->remove(tab);
- mTabs.erase(iter);
- break;
- }
- }
-
- for (STD_VECTOR<Tab*>::iterator iter2 = mTabsToDelete.begin();
- iter2 != mTabsToDelete.end(); ++iter2)
- {
- if (*iter2 == tab)
- {
- mTabsToDelete.erase(iter2);
- delete tab;
- break;
- }
- }
-
- const int tabsSize = CAST_S32(mTabs.size());
- if (tabIndexToBeSelected >= tabsSize)
- tabIndexToBeSelected = tabsSize - 1;
- if (tabIndexToBeSelected < -1)
- tabIndexToBeSelected = -1;
-
- if (tabIndexToBeSelected == -1)
- {
- mSelectedTab = nullptr;
- mWidgetContainer->clear();
- }
- else
- {
- setSelectedTabByIndex(tabIndexToBeSelected);
- }
-
- adjustSize();
- updateTabsWidth();
- widgetResized(Event(nullptr));
-}
-
-void TabbedArea::logic()
-{
- BLOCK_START("TabbedArea::logic")
- logicChildren();
- BLOCK_END("TabbedArea::logic")
-}
-
-void TabbedArea::mousePressed(MouseEvent &event)
-{
- if (event.isConsumed())
- return;
-
- if (event.getButton() == MouseButton::LEFT)
- {
- Widget *const widget = mTabContainer->getWidgetAt(
- event.getX(), event.getY());
- Tab *const tab = dynamic_cast<Tab *>(widget);
-
- if (tab != nullptr)
- {
- event.consume();
- setSelectedTab(tab);
- requestFocus();
- }
- }
-}
-
-void TabbedArea::setSelectedTab(Tab *const tab)
-{
- for (size_t i = 0; i < mTabs.size(); i++)
- {
- if (mTabs[i].first == mSelectedTab)
- mWidgetContainer->remove(mTabs[i].second);
- }
-
- for (size_t i = 0; i < mTabs.size(); i++)
- {
- if (mTabs[i].first == tab)
- {
- mSelectedTab = tab;
- mWidgetContainer->add(mTabs[i].second);
- }
- }
-
- Tab *const newTab = tab;
-
- if (newTab != nullptr)
- newTab->setCurrent();
-
- widgetResized(Event(nullptr));
-}
-
-void TabbedArea::setSelectedTabDefault()
-{
- if (mSelectedTab == nullptr ||
- mSelectedTab->mVisible == Visible_false)
- {
- for (size_t i = 0; i < mTabs.size(); i++)
- {
- Tab *const tab = mTabs[i].first;
- if ((tab != nullptr) && tab->mVisible == Visible_true)
- {
- setSelectedTab(tab);
- return;
- }
- }
- }
-}
-
-int TabbedArea::getSelectedTabIndex() const
-{
- for (unsigned int i = 0, fsz = CAST_U32(mTabs.size());
- i < fsz;
- i++)
- {
- if (mTabs[i].first == mSelectedTab)
- return i;
- }
-
- return -1;
-}
-
-void TabbedArea::setSelectedTabByName(const std::string &name)
-{
- FOR_EACH (TabContainer::const_iterator, itr, mTabs)
- {
- if (((*itr).first != nullptr) && (*itr).first->getCaption() == name)
- {
- setSelectedTab((*itr).first);
- return;
- }
- }
-}
-
-void TabbedArea::widgetResized(const Event &event A_UNUSED)
-{
- adjustSize();
-
- const int frameSize = 2 * mFrameSize;
- const int widgetFrameSize = 2 * mWidgetContainer->getFrameSize();
- const int w1 = mDimension.width;
- const int h1 = mDimension.height;
- const int width = w1 - frameSize - widgetFrameSize;
- const int height = h1 - frameSize
- - mWidgetContainer->getY() - widgetFrameSize;
-
- Widget *const w = getCurrentWidget();
- ScrollArea *const scr = dynamic_cast<ScrollArea *>(w);
- if (scr != nullptr)
- {
- if (mFollowDownScroll && height != 0)
- {
- const Rect &rect = w->getDimension();
- if (rect.height != 0 && rect.height > height + 2)
- {
- if (scr->getVerticalScrollAmount()
- >= scr->getVerticalMaxScroll() - 2
- && scr->getVerticalScrollAmount()
- <= scr->getVerticalMaxScroll() + 2)
- {
- const int newScroll = scr->getVerticalScrollAmount()
- + rect.height - height;
- w->setSize(mWidgetContainer->getWidth() - frameSize,
- mWidgetContainer->getHeight() - frameSize);
- if (newScroll != 0)
- scr->setVerticalScrollAmount(newScroll);
- }
- }
- }
- }
-
- if (mArrowButton[1] != nullptr)
- {
- // Check whether there is room to show more tabs now.
- int innerWidth = w1 - 4 - mArrowButton[0]->getWidth()
- - mArrowButton[1]->getWidth() - mRightMargin;
- if (innerWidth < 0)
- innerWidth = 0;
-
- int newWidth = mVisibleTabsWidth;
- while ((mTabScrollIndex != 0u) && newWidth < innerWidth)
- {
- Tab *const tab = mTabs[mTabScrollIndex - 1].first;
- if ((tab != nullptr) && tab->mVisible == Visible_true)
- {
- newWidth += tab->getWidth();
- if (newWidth < innerWidth)
- --mTabScrollIndex;
- }
- }
-
- if (mArrowButton[1] != nullptr)
- {
- // Move the right arrow to fit the windows content.
- newWidth = width - mArrowButton[1]->getWidth() - mRightMargin;
- if (newWidth < 0)
- newWidth = 0;
- mArrowButton[1]->setPosition(newWidth, 0);
- }
- }
-
- updateArrowEnableState();
- adjustTabPositions();
-}
-
-void TabbedArea::updateTabsWidth()
-{
- mTabsWidth = 0;
- FOR_EACH (TabContainer::const_iterator, itr, mTabs)
- {
- Tab *const tab = (*itr).first;
- if ((tab != nullptr) && tab->mVisible == Visible_true)
- mTabsWidth += tab->getWidth();
- }
- updateVisibleTabsWidth();
-}
-
-void TabbedArea::updateVisibleTabsWidth()
-{
- mVisibleTabsWidth = 0;
- for (size_t i = mTabScrollIndex, sz = mTabs.size(); i < sz; ++i)
- {
- Tab *const tab = mTabs[i].first;
- if ((tab != nullptr) && tab->mVisible == Visible_true)
- mVisibleTabsWidth += CAST_S32(tab->getWidth());
- }
-}
-
-void TabbedArea::adjustSize()
-{
- int maxTabHeight = 0;
-
- const int width = mDimension.width;
- const int height = mDimension.height;
-
- for (size_t i = 0, sz = mTabs.size(); i < sz; i++)
- {
- if (mTabs[i].first->getHeight() > maxTabHeight)
- maxTabHeight = mTabs[i].first->getHeight();
- }
-
- mTabContainer->setSize(width - mRightMargin, maxTabHeight);
-
- mWidgetContainer->setPosition(0, maxTabHeight);
- mWidgetContainer->setSize(width, height - maxTabHeight);
- Widget *const w = getCurrentWidget();
- if (w != nullptr)
- {
- const int wFrameSize = w->getFrameSize();
- const int frame2 = 2 * wFrameSize;
-
- w->setPosition(wFrameSize, wFrameSize);
- if (mResizeHeight)
- {
- w->setSize(mWidgetContainer->getWidth() - frame2,
- mWidgetContainer->getHeight() - frame2);
- }
- else
- {
- w->setSize(mWidgetContainer->getWidth() - frame2,
- w->getHeight());
- }
- }
-}
-
-void TabbedArea::adjustTabPositions()
-{
- int maxTabHeight = 0;
- const size_t sz = mTabs.size();
- for (size_t i = 0; i < sz; ++i)
- {
- const Tab *const tab = mTabs[i].first;
- if ((tab != nullptr) &&
- tab->mVisible == Visible_true &&
- tab->getHeight() > maxTabHeight)
- {
- maxTabHeight = tab->getHeight();
- }
- }
-
- int x = (mEnableScrollButtons && mArrowButton[0]->mVisible == Visible_true)
- ? mArrowButton[0]->getWidth() : 0;
- for (size_t i = mTabScrollIndex; i < sz; ++i)
- {
- Tab *const tab = mTabs[i].first;
- if ((tab == nullptr) || tab->mVisible == Visible_false)
- continue;
- tab->setPosition(x, maxTabHeight - tab->getHeight());
- x += tab->getWidth();
- }
-
- // If the tabs are scrolled, we hide them away.
- if (mTabScrollIndex > 0)
- {
- x = 0;
- for (unsigned i = 0; i < mTabScrollIndex; ++i)
- {
- Tab *const tab = mTabs[i].first;
- if ((tab != nullptr) && tab->mVisible == Visible_true)
- {
- x -= tab->getWidth();
- tab->setPosition(x, maxTabHeight - tab->getHeight());
- }
- }
- }
-}
-
-void TabbedArea::action(const ActionEvent& actionEvent)
-{
- Widget *const source = actionEvent.getSource();
- Tab *const tab = dynamic_cast<Tab *>(source);
-
- if (tab != nullptr)
- {
- setSelectedTab(tab);
- }
- else
- {
- const std::string &eventId = actionEvent.getId();
- if (eventId == "shift_left")
- {
- if (mTabScrollIndex != 0u)
- --mTabScrollIndex;
- }
- else if (eventId == "shift_right")
- {
- if (CAST_SIZE(mTabScrollIndex) < mTabs.size() - 1)
- ++mTabScrollIndex;
- }
- adjustTabPositions();
- updateArrowEnableState();
- }
-}
-
-void TabbedArea::updateArrowEnableState()
-{
- updateTabsWidth();
- if ((mArrowButton[0] == nullptr) || (mArrowButton[1] == nullptr))
- return;
-
- const int width = mDimension.width;
- if (mTabsWidth > width - 4
- - mArrowButton[0]->getWidth()
- - mArrowButton[1]->getWidth() - mRightMargin)
- {
- mArrowButton[0]->setVisible(Visible_true);
- mArrowButton[1]->setVisible(Visible_true);
- }
- else
- {
- mArrowButton[0]->setVisible(Visible_false);
- mArrowButton[1]->setVisible(Visible_false);
- mTabScrollIndex = 0;
- }
-
- // Left arrow consistency check
- if (mTabScrollIndex == 0u)
- mArrowButton[0]->setEnabled(false);
- else
- mArrowButton[0]->setEnabled(true);
-
- // Right arrow consistency check
- if (mVisibleTabsWidth < width - 4
- - mArrowButton[0]->getWidth()
- - mArrowButton[1]->getWidth() - mRightMargin)
- {
- mArrowButton[1]->setEnabled(false);
- }
- else
- {
- mArrowButton[1]->setEnabled(true);
- }
-}
-
-Tab *TabbedArea::getTabByIndex(const int index) const
-{
- if (index < 0 || index >= CAST_S32(mTabs.size()))
- return nullptr;
- return static_cast<Tab*>(mTabs[index].first);
-}
-
-Widget *TabbedArea::getWidgetByIndex(const int index) const
-{
- if (index < 0 || index >= CAST_S32(mTabs.size()))
- return nullptr;
- return mTabs[index].second;
-}
-
-void TabbedArea::removeAll(const bool del)
-{
- if (getSelectedTabIndex() != -1)
- {
- setSelectedTabByIndex(CAST_U32(0));
- }
- while (getNumberOfTabs() > 0)
- {
- const int idx = getNumberOfTabs() - 1;
- Tab *tab = mTabs[idx].first;
- Widget *widget = mTabs[idx].second;
- removeTab(tab);
- if (del)
- {
- delete tab;
- delete widget;
- }
- }
-}
-
-void TabbedArea::setWidth(int width)
-{
- // +++ need use virtual
- Widget::setWidth(width);
- adjustSize();
-}
-
-void TabbedArea::setHeight(int height)
-{
- // +++ need use virtual
- Widget::setHeight(height);
- adjustSize();
-}
-
-void TabbedArea::setSize(int width, int height)
-{
- // +++ need use virtual
- Widget::setSize(width, height);
- adjustSize();
-}
-
-void TabbedArea::setDimension(const Rect &dimension)
-{
- // +++ need use virtual
- Widget::setDimension(dimension);
- adjustSize();
-}
-
-void TabbedArea::keyPressed(KeyEvent& event)
-{
- if (mBlockSwitching || event.isConsumed() || !isFocused())
- return;
-
- const InputActionT actionId = event.getActionId();
-
- if (actionId == InputAction::GUI_LEFT)
- {
- int index = getSelectedTabIndex();
- index--;
-
- if (index < 0)
- return;
-
- setSelectedTab(mTabs[index].first);
- event.consume();
- }
- else if (actionId == InputAction::GUI_RIGHT)
- {
- int index = getSelectedTabIndex();
- index++;
-
- if (index >= CAST_S32(mTabs.size()))
- return;
-
- setSelectedTab(mTabs[index].first);
- event.consume();
- }
-}
-
-void TabbedArea::death(const Event &event)
-{
- Tab *const tab = dynamic_cast<Tab*>(event.getSource());
-
- if (tab != nullptr)
- removeTab(tab);
- else
- BasicContainer::death(event);
-}
-
-void TabbedArea::selectNextTab()
-{
- int tab = getSelectedTabIndex();
- tab++;
- if (tab == CAST_S32(mTabs.size()))
- tab = 0;
- setSelectedTab(mTabs[tab].first);
-}
-
-void TabbedArea::selectPrevTab()
-{
- int tab = getSelectedTabIndex();
-
- if (tab == 0)
- tab = CAST_S32(mTabs.size());
- if (tab < 0)
- return;
- tab--;
- setSelectedTab(mTabs[tab].first);
-}
diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h
deleted file mode 100644
index c971da391..000000000
--- a/src/gui/widgets/tabbedarea.h
+++ /dev/null
@@ -1,299 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_TABBEDAREA_H
-#define GUI_WIDGETS_TABBEDAREA_H
-
-#include "listeners/keylistener.h"
-#include "listeners/mouselistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "gui/widgets/basiccontainer2.h"
-
-#include "listeners/actionlistener.h"
-
-class Button;
-class Image;
-class Tab;
-
-/**
- * A tabbed area, the same as the guichan tabbed area in 0.8, but extended
- */
-class TabbedArea final : public ActionListener,
- public BasicContainer,
- public KeyListener,
- public MouseListener,
- public WidgetListener
-{
- public:
- /**
- * Constructor.
- */
- explicit TabbedArea(const Widget2 *const widget);
-
- A_DELETE_COPY(TabbedArea)
-
- ~TabbedArea();
-
- void postInit() override final;
-
- /**
- * Draw the tabbed area.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Return how many tabs have been created.
- */
- int getNumberOfTabs() const A_WARN_UNUSED;
-
- /**
- * Return tab with specified name as caption.
- */
- Tab *getTab(const std::string &name) const A_WARN_UNUSED;
-
- Tab *getTabByIndex(const int index) const A_WARN_UNUSED;
-
- Widget *getWidgetByIndex(const int index) const A_WARN_UNUSED;
-
- /**
- * Returns the widget with the tab that has specified caption
- */
- Widget *getWidget(const std::string &name) const A_WARN_UNUSED;
-
- /**
- * Returns the widget for the current tab
- */
- Widget *getCurrentWidget() const A_WARN_UNUSED;
-
- /**
- * Add a tab. Overridden since it needs to size the widget.
- *
- * @param tab The tab widget for the tab.
- * @param widget The widget to view when the tab is selected.
- */
- void addTab(Tab *const tab, Widget *const widget);
-
- void addTab(const std::string &caption, Widget *const widget);
-
- void addTab(Image *const image, Widget *const widget);
-
- bool isTabSelected(const size_t index) const A_WARN_UNUSED;
-
- bool isTabSelected(const Tab *const tab) const A_WARN_UNUSED;
-
- bool isTabPresent(const Tab *const tab) const A_WARN_UNUSED;
-
- /**
- * Overload the remove tab function as it's broken in guichan 0.8.
- */
- void removeTab(Tab *const tab);
-
- void removeAll(const bool del = true);
-
- /**
- * Overload the logic function since it's broken in guichan 0.8.
- */
- void logic() override final;
-
- int getContainerHeight() const noexcept2 A_WARN_UNUSED
- { return mWidgetContainer->getHeight(); }
-
- void setSelectedTab(Tab *const tab);
-
- void setSelectedTabDefault();
-
- void setSelectedTabByIndex(const size_t index);
-
- int getSelectedTabIndex() const A_WARN_UNUSED;
-
- Tab* getSelectedTab() const noexcept2 A_WARN_UNUSED
- { return mSelectedTab; }
-
- void setOpaque(const Opaque opaque)
- { mOpaque = opaque; }
-
- bool isOpaque() const noexcept2 A_WARN_UNUSED
- { return mOpaque == Opaque_true; }
-
- void adjustSize();
-
- void setSelectedTabByName(const std::string &name);
-
- void widgetResized(const Event &event) override final;
-
-/*
- void moveLeft(Tab *tab);
-
- void moveRight(Tab *tab);
-*/
- void adjustTabPositions();
-
- void action(const ActionEvent& actionEvent) override final;
-
- // Inherited from MouseListener
-
- void mousePressed(MouseEvent &event) override final;
-
- void enableScrollButtons(const bool enable);
-
- void setRightMargin(const int n) noexcept2
- { mRightMargin = n; }
-
- int getRightMargin() const noexcept2 A_WARN_UNUSED
- { return mRightMargin; }
-
- void setFollowDownScroll(const bool n) noexcept2
- { mFollowDownScroll = n; }
-
- bool getFollowDownScroll() const noexcept2 A_WARN_UNUSED
- { return mFollowDownScroll; }
-
- void keyPressed(KeyEvent& event) override final;
-
- void setBlockSwitching(const bool b) noexcept2
- { mBlockSwitching = b; }
-
- void setWidth(int width);
-
- void setHeight(int height);
-
- void setSize(int width, int height);
-
- void setDimension(const Rect &dimension);
-
- void death(const Event &event) override final;
-
- void setResizeHeight(bool b) noexcept2
- { mResizeHeight = b; }
-
- void adjustWidget(Widget *const widget) const;
-
- void selectNextTab();
-
- void selectPrevTab();
-
- Widget *getTabContainer() const noexcept2 A_WARN_UNUSED
- { return mTabContainer; }
-
- Widget *getWidgetContainer() const noexcept2 A_WARN_UNUSED
- { return mWidgetContainer; }
-
- private:
- typedef STD_VECTOR <std::pair<Tab*, Widget*> > TabContainer;
-
- /** The tab arrows */
- Button *mArrowButton[2] A_NONNULLPOINTER;
-
- /** Check whether the arrow should be clickable */
- void updateArrowEnableState();
-
- /**
- * Update the overall width of all tab. Used to know whether the arrows
- * have to be drawn or not.
- */
- void updateTabsWidth();
-
- Tab* mSelectedTab;
- BasicContainer2* mTabContainer A_NONNULLPOINTER;
- BasicContainer2* mWidgetContainer A_NONNULLPOINTER;
- STD_VECTOR<Tab*> mTabsToDelete;
- TabContainer mTabs;
-
- /**
- * The overall width of all tab.
- */
- int mTabsWidth;
-
- /**
- * Update the overall width of visible tab. Used to know whether
- * the arrows have to be enable or not.
- */
- void updateVisibleTabsWidth();
-
- /**
- * The overall width of visible tab.
- */
- int mVisibleTabsWidth;
-
- /**
- * The tab scroll index. When scrolling with the arrows, the tabs
- * must be displayed according to the current index.
- * So the first tab displayed may not be the first in the list.
- * @note the index must start at 0.
- */
- unsigned int mTabScrollIndex;
- int mRightMargin;
-
- Opaque mOpaque;
- bool mEnableScrollButtons;
- bool mFollowDownScroll;
- bool mBlockSwitching;
- bool mResizeHeight;
-};
-
-#endif // GUI_WIDGETS_TABBEDAREA_H
diff --git a/src/gui/widgets/tabs/chat/battletab.cpp b/src/gui/widgets/tabs/chat/battletab.cpp
deleted file mode 100644
index fc45fd5e1..000000000
--- a/src/gui/widgets/tabs/chat/battletab.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/chat/battletab.h"
-
-#include "configuration.h"
-
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-BattleTab *battleChatTab = nullptr;
-
-BattleTab::BattleTab(const Widget2 *const widget) :
- // TRANSLATORS: battle chat tab name
- ChatTab(widget, _("Battle"), "", "#Battle", ChatTabType::BATTLE)
-{
- setTabColors(ThemeColorId::BATTLE_CHAT_TAB);
- if (config.getBoolValue("showChatHistory"))
- loadFromLogFile("#Battle");
-}
-
-BattleTab::~BattleTab()
-{
-}
diff --git a/src/gui/widgets/tabs/chat/battletab.h b/src/gui/widgets/tabs/chat/battletab.h
deleted file mode 100644
index 24f69c8b9..000000000
--- a/src/gui/widgets/tabs/chat/battletab.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_CHAT_BATTLETAB_H
-#define GUI_WIDGETS_TABS_CHAT_BATTLETAB_H
-
-#include "gui/widgets/tabs/chat/chattab.h"
-
-/**
- * A tab for a party chat channel.
- */
-class BattleTab final : public ChatTab
-{
- public:
- explicit BattleTab(const Widget2 *const widget);
-
- A_DELETE_COPY(BattleTab)
-
- ~BattleTab();
-};
-
-extern BattleTab *battleChatTab;
-
-#endif // GUI_WIDGETS_TABS_CHAT_BATTLETAB_H
diff --git a/src/gui/widgets/tabs/chat/channeltab.cpp b/src/gui/widgets/tabs/chat/channeltab.cpp
deleted file mode 100644
index 37e6237a0..000000000
--- a/src/gui/widgets/tabs/chat/channeltab.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/chat/channeltab.h"
-
-#include "gui/widgets/windowcontainer.h"
-
-#include "gui/windows/chatwindow.h"
-
-#include "net/chathandler.h"
-
-#include "debug.h"
-
-ChannelTab::ChannelTab(const Widget2 *const widget,
- const std::string &channel) :
- ChatTab(widget, channel, channel, channel, ChatTabType::CHANNEL)
-{
- setTabColors(ThemeColorId::CHANNEL_CHAT_TAB);
-}
-
-ChannelTab::~ChannelTab()
-{
- if (chatWindow != nullptr)
- chatWindow->removeChannel(mChannelName);
-}
-
-void ChannelTab::handleInput(const std::string &msg)
-{
- std::string newMsg;
- newMsg = ChatWindow::doReplace(msg);
- chatHandler->channelMessage(mChannelName, newMsg);
-}
-
-bool ChannelTab::handleCommand(const std::string &restrict type,
- const std::string &restrict args A_UNUSED)
-{
- if (type == "close")
- {
- if (windowContainer != nullptr)
- windowContainer->scheduleDelete(this);
- else
- delete this;
- if (chatWindow != nullptr)
- chatWindow->defaultTab();
- }
- else
- {
- return false;
- }
-
- return true;
-}
-
-void ChannelTab::getAutoCompleteCommands(StringVect& commands) const
-{
- commands.push_back("/close");
- commands.push_back(mChannelName);
-}
diff --git a/src/gui/widgets/tabs/chat/channeltab.h b/src/gui/widgets/tabs/chat/channeltab.h
deleted file mode 100644
index 3ac51e59d..000000000
--- a/src/gui/widgets/tabs/chat/channeltab.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_CHAT_CHANNELTAB_H
-#define GUI_WIDGETS_TABS_CHAT_CHANNELTAB_H
-
-#include "gui/widgets/tabs/chat/chattab.h"
-
-/**
- * A tab for a chat channel.
- */
-class ChannelTab final : public ChatTab
-{
- public:
- ChannelTab(const Widget2 *const widget,
- const std::string &channel);
-
- A_DELETE_COPY(ChannelTab)
-
- ~ChannelTab();
-
- protected:
- void handleInput(const std::string &msg) override final;
-
- bool handleCommand(const std::string &restrict type,
- const std::string &restrict args) override final;
-
- void getAutoCompleteCommands(StringVect& commands)
- const override final;
-};
-
-#endif // GUI_WIDGETS_TABS_CHAT_CHANNELTAB_H
diff --git a/src/gui/widgets/tabs/chat/chattab.cpp b/src/gui/widgets/tabs/chat/chattab.cpp
deleted file mode 100644
index e4f6d751a..000000000
--- a/src/gui/widgets/tabs/chat/chattab.cpp
+++ /dev/null
@@ -1,563 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/chat/chattab.h"
-
-#include "chatlogger.h"
-#include "configuration.h"
-#include "settings.h"
-#include "soundmanager.h"
-
-#include "being/localplayer.h"
-
-#include "const/sound.h"
-
-#include "gui/chatlog.h"
-#include "gui/windowmanager.h"
-
-#include "gui/windows/chatwindow.h"
-#include "gui/windows/helpwindow.h"
-
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/itemlinkhandler.h"
-#include "gui/widgets/tabbedarea.h"
-
-#include "input/inputmanager.h"
-
-#include "net/chathandler.h"
-#include "net/net.h"
-
-#include "utils/chatutils.h"
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#ifdef WIN32
-#include <sys/time.h>
-#endif // WIN32
-
-#include <sstream>
-
-#include "debug.h"
-
-ChatTab *localChatTab = nullptr;
-ChatTab *debugChatTab = nullptr;
-
-static const unsigned int MAX_WORD_SIZE = 50;
-
-ChatTab::ChatTab(const Widget2 *const widget,
- const std::string &name,
- const std::string &channel,
- const std::string &logName,
- const ChatTabTypeT &type) :
- Tab(widget),
- mTextOutput(new BrowserBox(this, Opaque_true,
- "browserbox.xml")),
- mScrollArea(new ScrollArea(this, mTextOutput, Opaque_false)),
- mChannelName(channel),
- mLogName(logName),
- mType(type),
- mAllowHightlight(true),
- mRemoveNames(false),
- mNoAway(false),
- mShowOnline(false)
-{
- setCaption(name);
-
- mTextOutput->setOpaque(Opaque_false);
- mTextOutput->setMaxRow(config.getIntValue("ChatLogLength"));
- if (chatWindow != nullptr)
- mTextOutput->setLinkHandler(chatWindow->mItemLinkHandler);
- mTextOutput->setAlwaysUpdate(false);
-
- mScrollArea->setScrollPolicy(ScrollArea::SHOW_NEVER,
- ScrollArea::SHOW_ALWAYS);
- mScrollArea->setScrollAmount(0, 1);
-
- if (chatWindow != nullptr)
- chatWindow->addTab(this);
- mTextOutput->updateSize(true);
-}
-
-ChatTab::~ChatTab()
-{
- if (chatWindow != nullptr)
- chatWindow->removeTab(this);
-
- delete2(mTextOutput);
- delete2(mScrollArea);
-}
-
-void ChatTab::chatLog(std::string line,
- ChatMsgTypeT own,
- const IgnoreRecord ignoreRecord,
- const TryRemoveColors tryRemoveColors)
-{
- // Trim whitespace
- trim(line);
-
- if (line.empty())
- return;
-
- if (tryRemoveColors == TryRemoveColors_true &&
- own == ChatMsgType::BY_OTHER &&
- config.getBoolValue("removeColors"))
- {
- line = removeColors(line);
- if (line.empty())
- return;
- }
-
- const unsigned lineLim = config.getIntValue("chatMaxCharLimit");
- if (lineLim > 0 && line.length() > lineLim)
- line = line.substr(0, lineLim);
-
- if (line.empty())
- return;
-
- CHATLOG tmp;
- tmp.own = own;
- tmp.nick.clear();
- tmp.text = line;
-
- const size_t pos = line.find(" : ");
- if (pos != std::string::npos)
- {
- if (line.length() <= pos + 3)
- return;
-
- tmp.nick = line.substr(0, pos);
- tmp.text = line.substr(pos + 3);
- }
- else
- {
- // Fix the owner of welcome message.
- if (line.length() > 7 && line.substr(0, 7) == "Welcome")
- own = ChatMsgType::BY_SERVER;
- }
-
- // *implements actions in a backwards compatible way*
- if ((own == ChatMsgType::BY_PLAYER || own == ChatMsgType::BY_OTHER) &&
- tmp.text.at(0) == '*' &&
- tmp.text.at(tmp.text.length()-1) == '*')
- {
- tmp.text[0] = ' ';
- tmp.text.erase(tmp.text.length() - 1);
- own = ChatMsgType::ACT_IS;
- }
-
- std::string lineColor("##C");
- switch (own)
- {
- case ChatMsgType::BY_GM:
- if (tmp.nick.empty())
- {
- // TRANSLATORS: chat message
- tmp.nick = std::string(_("Global announcement:")).append(" ");
- lineColor = "##G";
- }
- else
- {
- // TRANSLATORS: chat message
- tmp.nick = strprintf(_("Global announcement from %s:"),
- tmp.nick.c_str()).append(" ");
- lineColor = "##g"; // Equiv. to BrowserBox::RED
- }
- break;
- case ChatMsgType::BY_PLAYER:
- tmp.nick.append(": ");
- lineColor = "##Y";
- break;
- case ChatMsgType::BY_OTHER:
- case ChatMsgType::BY_UNKNOWN:
- tmp.nick.append(": ");
- lineColor = "##C";
- break;
- case ChatMsgType::BY_SERVER:
- // TRANSLATORS: chat message
- tmp.nick.clear();
- tmp.text = line;
- lineColor = "##S";
- break;
- case ChatMsgType::BY_CHANNEL:
- tmp.nick.clear();
- lineColor = "##2"; // Equiv. to BrowserBox::GREEN
- break;
- case ChatMsgType::ACT_WHISPER:
- // TRANSLATORS: chat message
- tmp.nick = strprintf(_("%s whispers: %s"), tmp.nick.c_str(), "");
- lineColor = "##W";
- break;
- case ChatMsgType::ACT_IS:
- lineColor = "##I";
- break;
- case ChatMsgType::BY_LOGGER:
- tmp.nick.clear();
- tmp.text = line;
- lineColor = "##L";
- break;
- default:
- break;
- }
-
- if (tmp.nick == ": ")
- {
- tmp.nick.clear();
- lineColor = "##S";
- }
-
- // if configured, move magic messages log to debug chat tab
- if (Net::getNetworkType() == ServerType::TMWATHENA
- && (localChatTab != nullptr) && this == localChatTab
- && ((config.getBoolValue("showMagicInDebug")
- && own == ChatMsgType::BY_PLAYER
- && tmp.text.length() > 1
- && tmp.text.at(0) == '#'
- && tmp.text.at(1) != '#')
- || (config.getBoolValue("serverMsgInDebug")
- && (own == ChatMsgType::BY_SERVER
- || tmp.nick.empty()))))
- {
- if (debugChatTab != nullptr)
- debugChatTab->chatLog(line, own, ignoreRecord, tryRemoveColors);
- return;
- }
-
- // Get the current system time
- time_t t;
- time(&t);
-
- if (config.getBoolValue("useLocalTime"))
- {
- const tm *const timeInfo = localtime(&t);
- if (timeInfo != nullptr)
- {
- line = strprintf("%s[%02d:%02d] %s%s", lineColor.c_str(),
- timeInfo->tm_hour, timeInfo->tm_min, tmp.nick.c_str(),
- tmp.text.c_str());
- }
- else
- {
- line = strprintf("%s %s%s", lineColor.c_str(),
- tmp.nick.c_str(), tmp.text.c_str());
- }
- }
- else
- {
- // Format the time string properly
- std::stringstream timeStr;
- timeStr << "[" << ((((t / 60) / 60) % 24 < 10) ? "0" : "")
- << CAST_S32(((t / 60) / 60) % 24)
- << ":" << (((t / 60) % 60 < 10) ? "0" : "")
- << CAST_S32((t / 60) % 60)
- << "] ";
- line = std::string(lineColor).append(timeStr.str()).append(
- tmp.nick).append(tmp.text);
- }
-
- if (config.getBoolValue("enableChatLog"))
- saveToLogFile(line);
-
- mTextOutput->setMaxRow(config.getIntValue("chatMaxLinesLimit"));
-
- // We look if the Vertical Scroll Bar is set at the max before
- // adding a row, otherwise the max will always be a row higher
- // at comparison.
- if (mScrollArea->getVerticalScrollAmount() + 2 >=
- mScrollArea->getVerticalMaxScroll())
- {
- addRow(line);
- mScrollArea->setVerticalScrollAmount(
- mScrollArea->getVerticalMaxScroll());
- }
- else
- {
- addRow(line);
- }
-
- if ((chatWindow != nullptr) && this == localChatTab)
- chatWindow->addToAwayLog(line);
-
- mScrollArea->logic();
- if (own != ChatMsgType::BY_PLAYER)
- {
- if (own == ChatMsgType::BY_SERVER &&
- (getType() == ChatTabType::PARTY ||
- getType() == ChatTabType::CHANNEL ||
- getType() == ChatTabType::GUILD))
- {
- return;
- }
-
- const TabbedArea *const tabArea = getTabbedArea();
- if (tabArea == nullptr)
- return;
-
- const bool notFocused = WindowManager::getIsMinimized() ||
- (!settings.mouseFocused &&
- settings.inputFocused == KeyboardFocus::Unfocused);
-
- if (this != tabArea->getSelectedTab() || notFocused)
- {
- if (getFlash() == 0)
- {
- if (chatWindow != nullptr &&
- chatWindow->findHighlight(tmp.text))
- {
- setFlash(2);
- soundManager.playGuiSound(SOUND_HIGHLIGHT);
- }
- else
- {
- setFlash(1);
- }
- }
- else if (getFlash() == 2)
- {
- if (chatWindow != nullptr &&
- chatWindow->findHighlight(tmp.text))
- {
- soundManager.playGuiSound(SOUND_HIGHLIGHT);
- }
- }
- }
-
- if ((getAllowHighlight() ||
- own == ChatMsgType::BY_GM) &&
- (this != tabArea->getSelectedTab() ||
- notFocused))
- {
- if (own == ChatMsgType::BY_GM)
- {
- if (chatWindow != nullptr)
- chatWindow->unHideWindow();
- soundManager.playGuiSound(SOUND_GLOBAL);
- }
- else if (own != ChatMsgType::BY_SERVER)
- {
- if (chatWindow != nullptr)
- chatWindow->unHideWindow();
- playNewMessageSound();
- }
- WindowManager::newChatMessage();
- }
- }
-}
-
-void ChatTab::chatLog(const std::string &nick, std::string msg)
-{
- if (localPlayer == nullptr)
- return;
-
- const ChatMsgTypeT byWho = (nick == localPlayer->getName()
- ? ChatMsgType::BY_PLAYER : ChatMsgType::BY_OTHER);
- if (byWho == ChatMsgType::BY_OTHER && config.getBoolValue("removeColors"))
- msg = removeColors(msg);
- chatLog(std::string(nick).append(" : ").append(msg),
- byWho,
- IgnoreRecord_false,
- TryRemoveColors_false);
-}
-
-void ChatTab::chatInput(const std::string &message)
-{
- std::string msg = message;
- trim(msg);
-
- if (msg.empty())
- return;
-
- replaceItemLinks(msg);
- replaceVars(msg);
-
- switch (msg[0])
- {
- case '/':
- handleCommandStr(std::string(msg, 1));
- break;
- case '?':
- if (msg.size() > 1 &&
- msg[1] != '!' &&
- msg[1] != '?' &&
- msg[1] != '.' &&
- msg[1] != ' ' &&
- msg[1] != ',')
- {
- handleHelp(std::string(msg, 1));
- }
- else
- {
- handleInput(msg);
- }
- break;
- default:
- handleInput(msg);
- break;
- }
-}
-
-void ChatTab::scroll(const int amount)
-{
- const int range = mScrollArea->getHeight() / 8 * amount;
- Rect scr;
- scr.y = mScrollArea->getVerticalScrollAmount() + range;
- scr.height = abs(range);
- mTextOutput->showPart(scr);
-}
-
-void ChatTab::clearText()
-{
- mTextOutput->clearRows();
-}
-
-void ChatTab::handleInput(const std::string &msg)
-{
- if (chatHandler)
- {
- chatHandler->talk(ChatWindow::doReplace(msg),
- mChannelName);
- }
-}
-
-void ChatTab::handleCommandStr(const std::string &msg)
-{
- const size_t pos = msg.find(' ');
- const std::string type(msg, 0, pos);
- std::string args(msg, pos == std::string::npos ? msg.size() : pos + 1);
-
- args = trim(args);
- if (!handleCommand(type, args))
- inputManager.executeChatCommand(type, args, this);
-}
-
-void ChatTab::handleHelp(const std::string &msg)
-{
- if (helpWindow != nullptr)
- {
- helpWindow->search(msg);
- helpWindow->requestMoveToTop();
- }
-}
-
-bool ChatTab::handleCommands(const std::string &type, const std::string &args)
-{
- // need split to commands and call each
-
- return handleCommand(type, args);
-}
-
-void ChatTab::saveToLogFile(const std::string &msg) const
-{
- if (chatLogger != nullptr)
- {
- if (getType() == ChatTabType::INPUT)
- {
- chatLogger->log(msg);
- }
- else if (getType() == ChatTabType::DEBUG)
- {
- if (config.getBoolValue("enableDebugLog"))
- chatLogger->log("#Debug", msg);
- }
- else if (!mLogName.empty())
- {
- chatLogger->log(mLogName, msg);
- }
- }
-}
-
-void ChatTab::addRow(std::string &line)
-{
- if (line.find("[@@http") == std::string::npos)
- {
- size_t idx = 0;
- for (size_t f = 0; f < line.length(); f++)
- {
- if (line.at(f) == ' ')
- {
- idx = f;
- }
- else if (f - idx > MAX_WORD_SIZE)
- {
- line.insert(f, " ");
- idx = f;
- }
- }
- }
- mTextOutput->addRow(line);
-}
-
-void ChatTab::loadFromLogFile(const std::string &name)
-{
- if (chatLogger != nullptr)
- {
- std::list<std::string> list;
- chatLogger->loadLast(name, list, 5);
- std::list<std::string>::const_iterator i = list.begin();
- while (i != list.end())
- {
- std::string line("##o" + *i);
- addRow(line);
- ++i;
- }
- }
-}
-
-void ChatTab::addNewRow(std::string &line)
-{
- if (mScrollArea->getVerticalScrollAmount() >=
- mScrollArea->getVerticalMaxScroll())
- {
- addRow(line);
- mScrollArea->setVerticalScrollAmount(
- mScrollArea->getVerticalMaxScroll());
- }
- else
- {
- addRow(line);
- }
- mScrollArea->logic();
-}
-
-void ChatTab::playNewMessageSound() const
-{
- soundManager.playGuiSound(SOUND_WHISPER);
-}
-
-void ChatTab::showOnline(const std::string &nick,
- const Online online)
-{
- if (!mShowOnline)
- return;
-
- if (online == Online_true)
- {
- // TRANSLATORS: chat message
- chatLog(strprintf(_("%s is now Online."), nick.c_str()),
- ChatMsgType::BY_SERVER);
- }
- else
- {
- // TRANSLATORS: chat message
- chatLog(strprintf(_("%s is now Offline."), nick.c_str()),
- ChatMsgType::BY_SERVER);
- }
-}
diff --git a/src/gui/widgets/tabs/chat/chattab.h b/src/gui/widgets/tabs/chat/chattab.h
deleted file mode 100644
index 440501af4..000000000
--- a/src/gui/widgets/tabs/chat/chattab.h
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_CHAT_CHATTAB_H
-#define GUI_WIDGETS_TABS_CHAT_CHATTAB_H
-
-#include "enums/gui/chatmsgtype.h"
-#include "enums/gui/chattabtype.h"
-
-#include "enums/simpletypes/ignorerecord.h"
-#include "enums/simpletypes/online.h"
-#include "enums/simpletypes/tryremovecolors.h"
-
-#include "gui/widgets/browserbox.h"
-
-#include "gui/widgets/tabs/tab.h"
-
-#include "localconsts.h"
-
-class ScrollArea;
-
-#define debugMsg(str) \
- if (debugChatTab) \
- debugChatTab->chatLog(str, ChatMsgType::BY_SERVER);
-
-#define setTabColors(name) \
- setTabColor(&getThemeColor(name), \
- &getThemeColor(name##_OUTLINE)); \
- setHighlightedTabColor(&getThemeColor(name##_HIGHLIGHTED), \
- &getThemeColor(name##_HIGHLIGHTED_OUTLINE)); \
- setSelectedTabColor(&getThemeColor(name##_SELECTED), \
- &getThemeColor(name##_SELECTED_OUTLINE))
-
-/**
- * A tab for the chat window. This is special to ease chat handling.
- */
-class ChatTab notfinal : public Tab
-{
- public:
- /**
- * Constructor.
- */
- ChatTab(const Widget2 *const widget,
- const std::string &name,
- const std::string &channel,
- const std::string &logName,
- const ChatTabTypeT &type);
-
- A_DELETE_COPY(ChatTab)
-
- virtual ~ChatTab();
-
- /**
- * Adds a line of text to our message list. Parameters:
- *
- * @param line Text message.
- * @param own Type of message (usually the owner-type).
- * @param ignoreRecord should this not be recorded?
- * @param tryRemoveColors try remove color if configured
- */
- void chatLog(std::string line,
- ChatMsgTypeT own,
- const IgnoreRecord ignoreRecord = IgnoreRecord_false,
- const TryRemoveColors tryRemoveColors
- = TryRemoveColors_true);
-
- /**
- * Adds the text to the message list
- *
- * @param msg The message text which is to be sent.
- */
- void chatLog(const std::string &nick, std::string msg);
-
- /**
- * Determines whether the message is a command or message, then
- * sends the given message to the game server to be said, or to the
- * command handler
- *
- * @param msg The message text which is to be sent.
- */
- void chatInput(const std::string &msg);
-
- /**
- * Scrolls the chat window
- *
- * @param amount direction and amount to scroll. Negative numbers scroll
- * up, positive numbers scroll down. The absolute amount indicates the
- * amount of 1/8ths of chat window real estate that should be scrolled.
- */
- void scroll(const int amount);
-
- /**
- * Clears the text from the tab
- */
- void clearText();
-
- /**
- * Handle special commands. Allows a tab to handle commands it
- * defines itself.
- *
- * @returns true if the command was handled
- * false if the command was not handled
- */
- virtual bool handleCommand(const std::string &restrict type A_UNUSED,
- const std::string &restrict args A_UNUSED)
- { return false; }
-
- /**
- * Handle special commands. Allows a tab to handle commands it
- * defines itself.
- *
- * @returns true if the command was handled
- * false if the command was not handled
- */
- virtual bool handleCommands(const std::string &type,
- const std::string &args);
-
- /**
- * Returns type of the being.
- */
- ChatTabTypeT getType() const noexcept2 A_WARN_UNUSED
- { return mType; }
-
- void saveToLogFile(const std::string &msg) const;
-
- const std::list<std::string> &getRows() const A_WARN_UNUSED
- { return mTextOutput->getRows(); }
-
- bool hasRows() const A_WARN_UNUSED
- { return mTextOutput->hasRows(); }
-
- void loadFromLogFile(const std::string &name);
-
- bool getAllowHighlight() const noexcept2 A_WARN_UNUSED
- { return mAllowHightlight; }
-
- void setAllowHighlight(const bool n) noexcept2
- { mAllowHightlight = n; }
-
- bool getRemoveNames() const noexcept2 A_WARN_UNUSED
- { return mRemoveNames; }
-
- void setRemoveNames(const bool n) noexcept2
- { mRemoveNames = n; }
-
- bool getNoAway() const noexcept2 A_WARN_UNUSED
- { return mNoAway; }
-
- void setNoAway(const bool n) noexcept2
- { mNoAway = n; }
-
- void addNewRow(std::string &line);
-
- void showOnline(const std::string &nick,
- const Online online);
-
- virtual void playNewMessageSound() const;
-
- const std::string &getChannelName() const
- { return mChannelName; }
-
- protected:
- friend class ChatWindow;
- friend class WhisperWindow;
-
- void setCurrent() override final
- { setFlash(0); }
-
- virtual void handleInput(const std::string &msg);
-
- virtual void handleCommandStr(const std::string &msg);
-
- virtual void handleHelp(const std::string &msg);
-
- virtual void getAutoCompleteList(StringVect &names A_UNUSED) const
- {}
-
- virtual void getAutoCompleteCommands(StringVect &names A_UNUSED) const
- {}
-
- void addRow(std::string &line);
-
- BrowserBox *mTextOutput A_NONNULLPOINTER;
- ScrollArea *mScrollArea;
- std::string mChannelName;
- std::string mLogName;
- ChatTabTypeT mType;
- bool mAllowHightlight;
- bool mRemoveNames;
- bool mNoAway;
- bool mShowOnline;
-};
-
-extern ChatTab *localChatTab;
-extern ChatTab *debugChatTab;
-
-#endif // GUI_WIDGETS_TABS_CHAT_CHATTAB_H
diff --git a/src/gui/widgets/tabs/chat/emulateguildtab.cpp b/src/gui/widgets/tabs/chat/emulateguildtab.cpp
deleted file mode 100644
index 4e94bf11d..000000000
--- a/src/gui/widgets/tabs/chat/emulateguildtab.cpp
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifdef TMWA_SUPPORT
-
-#include "gui/widgets/tabs/chat/emulateguildtab.h"
-
-#include "configuration.h"
-#include "soundmanager.h"
-
-#include "const/sound.h"
-
-#include "gui/windows/chatwindow.h"
-
-#include "utils/gettext.h"
-
-#include "net/tmwa/guildmanager.h"
-
-#include "debug.h"
-
-EmulateGuildTab::EmulateGuildTab(const Widget2 *const widget) :
- // TRANSLATORS: guild chat tab name
- ChatTab(widget, _("Guild"), "", "#Guild", ChatTabType::GUILD),
- ConfigListener()
-{
- setTabColors(ThemeColorId::GUILD_CHAT_TAB);
- mShowOnline = config.getBoolValue("showGuildOnline");
- config.addListener("showGuildOnline", this);
-}
-
-EmulateGuildTab::~EmulateGuildTab()
-{
- config.removeListeners(this);
- CHECKLISTENERS
-}
-
-bool EmulateGuildTab::handleCommand(const std::string &restrict type,
- const std::string &restrict args)
-{
- if (type == "invite")
- GuildManager::invite(args);
- else if (type == "leave")
- GuildManager::leave();
- else if (type == "kick")
- GuildManager::kick(args);
- else if (type == "notice")
- GuildManager::notice(args);
- else
- return false;
-
- return true;
-}
-
-void EmulateGuildTab::handleInput(const std::string &msg)
-{
- if (guildManager == nullptr)
- return;
- guildManager->chat(ChatWindow::doReplace(msg));
-}
-
-void EmulateGuildTab::getAutoCompleteList(StringVect &names) const
-{
- if (guildManager == nullptr)
- return;
-
- guildManager->getNames(names);
-}
-
-void EmulateGuildTab::getAutoCompleteCommands(StringVect &names) const
-{
- names.push_back("/help");
- names.push_back("/invite ");
- names.push_back("/leave");
- names.push_back("/kick ");
- names.push_back("/notice ");
-}
-
-void EmulateGuildTab::playNewMessageSound() const
-{
- soundManager.playGuiSound(SOUND_GUILD);
-}
-
-void EmulateGuildTab::optionChanged(const std::string &value)
-{
- if (value == "showGuildOnline")
- mShowOnline = config.getBoolValue("showGuildOnline");
-}
-
-#endif // TMWA_SUPPORT
diff --git a/src/gui/widgets/tabs/chat/emulateguildtab.h b/src/gui/widgets/tabs/chat/emulateguildtab.h
deleted file mode 100644
index 3cf3a0e59..000000000
--- a/src/gui/widgets/tabs/chat/emulateguildtab.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_CHAT_EMULATEGUILDTAB_H
-#define GUI_WIDGETS_TABS_CHAT_EMULATEGUILDTAB_H
-
-#ifdef TMWA_SUPPORT
-
-#include "gui/widgets/tabs/chat/chattab.h"
-
-/**
- * Emulate guild tab, because server not support normal guilds.
- */
-class EmulateGuildTab final : public ChatTab,
- public ConfigListener
-{
- public:
- explicit EmulateGuildTab(const Widget2 *const widget);
-
- A_DELETE_COPY(EmulateGuildTab)
-
- ~EmulateGuildTab();
-
- bool handleCommand(const std::string &restrict type,
- const std::string &restrict args) override final;
-
- void playNewMessageSound() const override final;
-
- void optionChanged(const std::string &value) override final;
-
- protected:
- void handleInput(const std::string &msg) override final;
-
- void getAutoCompleteList(StringVect &names) const override final;
-
- void getAutoCompleteCommands(StringVect &names) const override final;
-};
-
-#endif // TMWA_SUPPORT
-#endif // GUI_WIDGETS_TABS_CHAT_EMULATEGUILDTAB_H
diff --git a/src/gui/widgets/tabs/chat/gmtab.cpp b/src/gui/widgets/tabs/chat/gmtab.cpp
deleted file mode 100644
index 3a63cbd2d..000000000
--- a/src/gui/widgets/tabs/chat/gmtab.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/chat/gmtab.h"
-
-#include "const/gui/chat.h"
-
-#include "gui/windows/chatwindow.h"
-
-#include "utils/gettext.h"
-
-#include "net/chathandler.h"
-
-#include "debug.h"
-
-GmTab *gmChatTab = nullptr;
-
-GmTab::GmTab(const Widget2 *const widget) :
- // TRANSLATORS: gb tab name
- ChatTab(widget, _("GM"), GM_CHANNEL, "#GM", ChatTabType::GM)
-{
- setTabColors(ThemeColorId::GM_CHAT_TAB);
-}
-
-GmTab::~GmTab()
-{
-}
-
-void GmTab::handleInput(const std::string &msg)
-{
- chatHandler->channelMessage(mChannelName, ChatWindow::doReplace(msg));
-}
-
-void GmTab::handleCommandStr(const std::string &msg A_UNUSED)
-{
-}
-
-void GmTab::getAutoCompleteList(StringVect &names A_UNUSED) const
-{
-}
diff --git a/src/gui/widgets/tabs/chat/gmtab.h b/src/gui/widgets/tabs/chat/gmtab.h
deleted file mode 100644
index a8dd46fd3..000000000
--- a/src/gui/widgets/tabs/chat/gmtab.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_CHAT_GMTAB_H
-#define GUI_WIDGETS_TABS_CHAT_GMTAB_H
-
-#include "gui/widgets/tabs/chat/chattab.h"
-
-/**
- * A tab for whispers from a single player.
- */
-class GmTab final : public ChatTab
-{
- public:
- explicit GmTab(const Widget2 *const widget);
-
- A_DELETE_COPY(GmTab)
-
- ~GmTab();
-
- protected:
- void getAutoCompleteList(StringVect &names) const
- override final A_CONST;
-
- void handleInput(const std::string &msg) override final;
-
- void handleCommandStr(const std::string &msg) override final A_CONST;
-};
-
-extern GmTab *gmChatTab;
-
-#endif // GUI_WIDGETS_TABS_CHAT_GMTAB_H
diff --git a/src/gui/widgets/tabs/chat/guildtab.cpp b/src/gui/widgets/tabs/chat/guildtab.cpp
deleted file mode 100644
index 51416b8ef..000000000
--- a/src/gui/widgets/tabs/chat/guildtab.cpp
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/chat/guildtab.h"
-
-#include "configuration.h"
-#include "soundmanager.h"
-
-#include "const/sound.h"
-
-#include "gui/windows/chatwindow.h"
-
-#include "input/inputmanager.h"
-
-#include "net/guildhandler.h"
-
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-namespace EAthena
-{
- extern Guild *taGuild;
-} // namespace EAthena
-
-GuildTab::GuildTab(const Widget2 *const widget) :
- // TRANSLATORS: guild chat tab name
- ChatTab(widget, _("Guild"), "", "#Guild", ChatTabType::GUILD)
-{
- setTabColors(ThemeColorId::GUILD_CHAT_TAB);
- mShowOnline = config.getBoolValue("showGuildOnline");
- config.addListener("showGuildOnline", this);
-}
-
-GuildTab::~GuildTab()
-{
- config.removeListeners(this);
- CHECKLISTENERS
-}
-
-bool GuildTab::handleCommand(const std::string &restrict type,
- const std::string &restrict args)
-{
- if (type == "invite" && (EAthena::taGuild != nullptr))
- {
- guildHandler->invite(args);
- }
- else if (type == "leave" && (EAthena::taGuild != nullptr))
- {
- inputManager.executeChatCommand(InputAction::LEAVE_GUILD,
- std::string(),
- this);
- }
- else if (type == "kick" && (EAthena::taGuild != nullptr))
- {
- inputManager.executeChatCommand(InputAction::KICK_GUILD,
- args,
- this);
- }
- else if (type == "notice" && (EAthena::taGuild != nullptr))
- {
- inputManager.executeChatCommand(InputAction::GUILD_NOTICE,
- args,
- this);
- }
- else
- {
- return false;
- }
-
- return true;
-}
-
-void GuildTab::handleInput(const std::string &msg)
-{
- if (EAthena::taGuild == nullptr)
- return;
-
- guildHandler->chat(ChatWindow::doReplace(msg));
-}
-
-void GuildTab::getAutoCompleteList(StringVect &names) const
-{
- if (EAthena::taGuild != nullptr)
- EAthena::taGuild->getNames(names);
-}
-
-void GuildTab::getAutoCompleteCommands(StringVect &names) const
-{
- names.push_back("/help");
- names.push_back("/invite ");
- names.push_back("/kick ");
- names.push_back("/notice ");
- names.push_back("/leave");
-}
-
-void GuildTab::playNewMessageSound() const
-{
- soundManager.playGuiSound(SOUND_GUILD);
-}
-
-void GuildTab::optionChanged(const std::string &value)
-{
- if (value == "showGuildOnline")
- mShowOnline = config.getBoolValue("showGuildOnline");
-}
diff --git a/src/gui/widgets/tabs/chat/guildtab.h b/src/gui/widgets/tabs/chat/guildtab.h
deleted file mode 100644
index 5aa540ecb..000000000
--- a/src/gui/widgets/tabs/chat/guildtab.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_CHAT_GUILDTAB_H
-#define GUI_WIDGETS_TABS_CHAT_GUILDTAB_H
-
-#include "gui/widgets/tabs/chat/chattab.h"
-
-/**
- * A tab for a guild chat channel.
- */
-class GuildTab notfinal : public ChatTab,
- public ConfigListener
-{
- public:
- explicit GuildTab(const Widget2 *const widget);
-
- A_DELETE_COPY(GuildTab)
-
- virtual ~GuildTab();
-
- bool handleCommand(const std::string &restrict type,
- const std::string &restrict args) override final;
-
- void playNewMessageSound() const override final;
-
- void optionChanged(const std::string &value) override final;
-
- protected:
- void handleInput(const std::string &msg) override final;
-
- void getAutoCompleteList(StringVect &names) const override final;
-
- void getAutoCompleteCommands(StringVect &names) const override final;
-};
-
-#endif // GUI_WIDGETS_TABS_CHAT_GUILDTAB_H
diff --git a/src/gui/widgets/tabs/chat/langtab.cpp b/src/gui/widgets/tabs/chat/langtab.cpp
deleted file mode 100644
index ba1e21711..000000000
--- a/src/gui/widgets/tabs/chat/langtab.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/chat/langtab.h"
-
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-LangTab *langChatTab = nullptr;
-
-LangTab::LangTab(const Widget2 *const widget,
- const std::string &lang) :
- // TRANSLATORS: lang chat tab name
- ChatTab(widget, _("Lang"), lang + " ", "#Lang", ChatTabType::LANG)
-{
-}
-
-LangTab::~LangTab()
-{
-}
diff --git a/src/gui/widgets/tabs/chat/langtab.h b/src/gui/widgets/tabs/chat/langtab.h
deleted file mode 100644
index 773431e85..000000000
--- a/src/gui/widgets/tabs/chat/langtab.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_CHAT_LANGTAB_H
-#define GUI_WIDGETS_TABS_CHAT_LANGTAB_H
-
-#include "gui/widgets/tabs/chat/chattab.h"
-
-class LangTab final : public ChatTab
-{
- public:
- LangTab(const Widget2 *const widget,
- const std::string &lang);
-
- A_DELETE_COPY(LangTab)
-
- ~LangTab();
-};
-
-extern LangTab *langChatTab;
-
-#endif // GUI_WIDGETS_TABS_CHAT_LANGTAB_H
diff --git a/src/gui/widgets/tabs/chat/partytab.cpp b/src/gui/widgets/tabs/chat/partytab.cpp
deleted file mode 100644
index befbb0393..000000000
--- a/src/gui/widgets/tabs/chat/partytab.cpp
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/chat/partytab.h"
-
-#include "configuration.h"
-#include "party.h"
-#include "soundmanager.h"
-
-#include "being/localplayer.h"
-
-#include "const/sound.h"
-
-#include "gui/windows/chatwindow.h"
-
-#include "input/inputmanager.h"
-
-#include "net/net.h"
-#include "net/partyhandler.h"
-
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-PartyTab *partyTab = nullptr;
-
-PartyTab::PartyTab(const Widget2 *const widget) :
- // TRANSLATORS: party chat tab name
- ChatTab(widget, _("Party"), "", "#Party", ChatTabType::PARTY)
-{
- setTabColors(ThemeColorId::PARTY_CHAT_TAB);
- mShowOnline = config.getBoolValue("showPartyOnline");
- config.addListener("showPartyOnline", this);
-}
-
-PartyTab::~PartyTab()
-{
- config.removeListeners(this);
- CHECKLISTENERS
-}
-
-void PartyTab::handleInput(const std::string &msg)
-{
- partyHandler->chat(ChatWindow::doReplace(msg));
-}
-
-bool PartyTab::handleCommand(const std::string &restrict type,
- const std::string &restrict args)
-{
- if (type == "invite")
- {
- partyHandler->invite(args);
- }
- else if (type == "leave")
- {
- inputManager.executeChatCommand(InputAction::LEAVE_PARTY,
- args,
- this);
- }
- else if (type == "kick")
- {
- inputManager.executeChatCommand(InputAction::KICK_PARTY,
- args,
- this);
- }
- else if (type == "item")
- {
- inputManager.executeChatCommand(InputAction::PARTY_ITEM_SHARE,
- args,
- this);
- }
- else if (type == "autoitem")
- {
- inputManager.executeChatCommand(InputAction::PARTY_AUTO_ITEM_SHARE,
- args,
- this);
- }
- else if (type == "exp")
- {
- inputManager.executeChatCommand(InputAction::PARTY_EXP_SHARE,
- args,
- this);
- }
- else if (type == "setleader" &&
- Net::getNetworkType() != ServerType::TMWATHENA)
- {
- inputManager.executeChatCommand(
- InputAction::COMMAND_CHANGE_PARTY_LEADER,
- args,
- this);
- }
- else
- {
- return false;
- }
-
- return true;
-}
-
-void PartyTab::getAutoCompleteList(StringVect &names) const
-{
- if (localPlayer == nullptr)
- return;
-
- const Party *const p = localPlayer->getParty();
-
- if (p != nullptr)
- p->getNames(names);
-}
-
-void PartyTab::getAutoCompleteCommands(StringVect &names) const
-{
- names.push_back("/help");
- names.push_back("/invite ");
- names.push_back("/leave");
- names.push_back("/kick ");
- names.push_back("/item");
- names.push_back("/exp");
- if (Net::getNetworkType() != ServerType::TMWATHENA)
- names.push_back("/setleader ");
-}
-
-void PartyTab::playNewMessageSound() const
-{
- soundManager.playGuiSound(SOUND_GUILD);
-}
-
-void PartyTab::optionChanged(const std::string &value)
-{
- if (value == "showPartyOnline")
- mShowOnline = config.getBoolValue("showPartyOnline");
-}
diff --git a/src/gui/widgets/tabs/chat/partytab.h b/src/gui/widgets/tabs/chat/partytab.h
deleted file mode 100644
index a987c9362..000000000
--- a/src/gui/widgets/tabs/chat/partytab.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_CHAT_PARTYTAB_H
-#define GUI_WIDGETS_TABS_CHAT_PARTYTAB_H
-
-#include "gui/widgets/tabs/chat/chattab.h"
-
-/**
- * A tab for a party chat channel.
- */
-class PartyTab notfinal : public ChatTab,
- public ConfigListener
-{
- public:
- explicit PartyTab(const Widget2 *const widget);
-
- A_DELETE_COPY(PartyTab)
-
- virtual ~PartyTab();
-
- bool handleCommand(const std::string &restrict type,
- const std::string &restrict args) override final;
-
- void playNewMessageSound() const override final;
-
- void optionChanged(const std::string &value) override final;
-
- protected:
- void handleInput(const std::string &msg) override final;
-
- void getAutoCompleteList(StringVect &names) const override final;
-
- void getAutoCompleteCommands(StringVect &names) const override final;
-};
-
-extern PartyTab *partyTab;
-
-#endif // GUI_WIDGETS_TABS_CHAT_PARTYTAB_H
diff --git a/src/gui/widgets/tabs/chat/tradetab.cpp b/src/gui/widgets/tabs/chat/tradetab.cpp
deleted file mode 100644
index e16e5c08b..000000000
--- a/src/gui/widgets/tabs/chat/tradetab.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/chat/tradetab.h"
-
-#include "const/gui/chat.h"
-
-#include "gui/windows/chatwindow.h"
-
-#include "net/chathandler.h"
-
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-TradeTab *tradeChatTab = nullptr;
-
-TradeTab::TradeTab(const Widget2 *const widget) :
- // TRANSLATORS: trade chat tab name
- ChatTab(widget, _("Trade"), TRADE_CHANNEL, "#Trade", ChatTabType::TRADE)
-{
-}
-
-TradeTab::~TradeTab()
-{
-}
-
-void TradeTab::handleInput(const std::string &msg)
-{
- chatHandler->channelMessage(mChannelName, ChatWindow::doReplace(msg));
-}
diff --git a/src/gui/widgets/tabs/chat/tradetab.h b/src/gui/widgets/tabs/chat/tradetab.h
deleted file mode 100644
index 26c9bf8f6..000000000
--- a/src/gui/widgets/tabs/chat/tradetab.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_CHAT_TRADETAB_H
-#define GUI_WIDGETS_TABS_CHAT_TRADETAB_H
-
-#include "gui/widgets/tabs/chat/chattab.h"
-
-/**
- * A tab for a party chat channel.
- */
-class TradeTab final : public ChatTab
-{
- public:
- explicit TradeTab(const Widget2 *const widget);
-
- A_DELETE_COPY(TradeTab)
-
- ~TradeTab();
-
- protected:
- void handleInput(const std::string &msg) override final;
-};
-
-extern TradeTab *tradeChatTab;
-
-#endif // GUI_WIDGETS_TABS_CHAT_TRADETAB_H
diff --git a/src/gui/widgets/tabs/chat/whispertab.cpp b/src/gui/widgets/tabs/chat/whispertab.cpp
deleted file mode 100644
index 73b73a17c..000000000
--- a/src/gui/widgets/tabs/chat/whispertab.cpp
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/chat/whispertab.h"
-
-#include "being/localplayer.h"
-
-#include "net/chathandler.h"
-
-#include "gui/windows/chatwindow.h"
-
-#include "gui/widgets/windowcontainer.h"
-
-#include "utils/chatutils.h"
-
-#include "debug.h"
-
-WhisperTab::WhisperTab(const Widget2 *const widget,
- const std::string &caption,
- const std::string &nick) :
- ChatTab(widget, caption, nick, nick, ChatTabType::WHISPER),
- mNick(nick)
-{
- setWhisperTabColors();
-}
-
-WhisperTab::~WhisperTab()
-{
- if (chatWindow != nullptr)
- chatWindow->removeWhisper(mNick);
-}
-
-void WhisperTab::handleInput(const std::string &msg)
-{
- std::string newMsg;
- newMsg = ChatWindow::doReplace(msg);
- chatHandler->privateMessage(mNick, newMsg);
-
- if (localPlayer != nullptr)
- chatLog(localPlayer->getName(), newMsg);
- else
- chatLog("?", newMsg);
-}
-
-void WhisperTab::handleCommandStr(const std::string &msg)
-{
- if (msg == "close")
- {
- delete this;
- return;
- }
-
- const size_t pos = msg.find(' ');
- const std::string type(msg, 0, pos);
-
- if (type == "me")
- {
- const std::string args(msg, pos == std::string::npos
- ? msg.size() : pos + 1);
- std::string str = textToMe(args);
- chatHandler->privateMessage(mNick, str);
- if (localPlayer != nullptr)
- chatLog(localPlayer->getName(), str);
- else
- chatLog("?", str);
- }
- else
- {
- ChatTab::handleCommandStr(msg);
- }
-}
-
-bool WhisperTab::handleCommand(const std::string &restrict type,
- const std::string &restrict args A_UNUSED)
-{
- if (type == "close")
- {
- if (windowContainer != nullptr)
- windowContainer->scheduleDelete(this);
- else
- delete this;
- if (chatWindow != nullptr)
- chatWindow->defaultTab();
- }
- else
- {
- return false;
- }
-
- return true;
-}
-
-void WhisperTab::getAutoCompleteList(StringVect &names) const
-{
- names.push_back(mNick);
-}
-
-void WhisperTab::getAutoCompleteCommands(StringVect& commands) const
-{
- commands.push_back("/close");
-}
-
-void WhisperTab::setWhisperTabColors()
-{
- setTabColors(ThemeColorId::WHISPER_TAB);
-}
-
-void WhisperTab::setWhisperTabOfflineColors()
-{
- setTabColors(ThemeColorId::WHISPER_TAB_OFFLINE);
-}
diff --git a/src/gui/widgets/tabs/chat/whispertab.h b/src/gui/widgets/tabs/chat/whispertab.h
deleted file mode 100644
index 1d3c03857..000000000
--- a/src/gui/widgets/tabs/chat/whispertab.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_CHAT_WHISPERTAB_H
-#define GUI_WIDGETS_TABS_CHAT_WHISPERTAB_H
-
-#include "gui/widgets/tabs/chat/chattab.h"
-
-/**
- * A tab for whispers from a single player.
- */
-class WhisperTab final : public ChatTab
-{
- public:
- A_DELETE_COPY(WhisperTab)
-
- const std::string &getNick() const noexcept2 A_WARN_UNUSED
- { return mNick; }
-
- bool handleCommand(const std::string &restrict type,
- const std::string &restrict args) override final;
-
- void setWhisperTabColors();
-
- void setWhisperTabOfflineColors();
-
- protected:
- friend class ChatWindow;
-
- void getAutoCompleteList(StringVect &names) const override final;
-
- void getAutoCompleteCommands(StringVect& commands)
- const override final;
-
- /**
- * Constructor.
- *
- * @param nick the name of the player this tab is whispering to
- */
- WhisperTab(const Widget2 *const widget,
- const std::string &caption,
- const std::string &nick);
-
- ~WhisperTab();
-
- void handleInput(const std::string &msg) override final;
-
- void handleCommandStr(const std::string &msg) override final;
-
- private:
- std::string mNick;
-};
-
-#endif // GUI_WIDGETS_TABS_CHAT_WHISPERTAB_H
diff --git a/src/gui/widgets/tabs/debugwindowtabs.cpp b/src/gui/widgets/tabs/debugwindowtabs.cpp
deleted file mode 100644
index 321c3bcad..000000000
--- a/src/gui/widgets/tabs/debugwindowtabs.cpp
+++ /dev/null
@@ -1,492 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/debugwindowtabs.h"
-
-#include "game.h"
-
-#include "being/localplayer.h"
-
-#include "particle/particleengine.h"
-
-#include "gui/viewport.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layouthelper.h"
-
-#ifdef USE_OPENGL
-#include "resources/imagehelper.h"
-#endif // USE_OPENGL
-
-#include "resources/map/map.h"
-
-#include "net/packetcounters.h"
-
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-#include "utils/timer.h"
-
-#include "debug.h"
-
-MapDebugTab::MapDebugTab(const Widget2 *const widget) :
- DebugTab(widget),
- // TRANSLATORS: debug window label
- mMusicFileLabel(new Label(this, _("Music:"))),
- // TRANSLATORS: debug window label
- mMapLabel(new Label(this, _("Map:"))),
- // TRANSLATORS: debug window label
- mMapNameLabel(new Label(this, _("Map name:"))),
- // TRANSLATORS: debug window label
- mMinimapLabel(new Label(this, _("Minimap:"))),
- mTileMouseLabel(new Label(this, strprintf("%s (%d, %d)",
- // TRANSLATORS: debug window label
- _("Cursor:"), 0, 0))),
- mParticleCountLabel(new Label(this, strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Particle count:"), 88888))),
- mMapActorCountLabel(new Label(this, strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Map actors count:"), 88888))),
- // TRANSLATORS: debug window label
- mXYLabel(new Label(this, strprintf("%s (?,?)", _("Player Position:")))),
- mTexturesLabel(nullptr),
- mUpdateTime(0),
-#ifdef DEBUG_DRAW_CALLS
- mDrawCallsLabel(new Label(this, strprintf("%s %s",
- // TRANSLATORS: debug window label
- _("Draw calls:"), "?"))),
-#endif // DEBUG_DRAW_CALLS
-#ifdef DEBUG_BIND_TEXTURE
- mBindsLabel(new Label(this, strprintf("%s %s",
- // TRANSLATORS: debug window label
- _("Texture binds:"), "?"))),
-#endif // DEBUG_BIND_TEXTURE
- // TRANSLATORS: debug window label, frames per second
- mFPSLabel(new Label(this, strprintf(_("%d FPS"), 0))),
- // TRANSLATORS: debug window label, logic per second
- mLPSLabel(new Label(this, strprintf(_("%d LPS"), 0))),
- mFPSText()
-{
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
-
-#ifdef USE_OPENGL
- switch (imageHelper->useOpenGL())
- {
- case RENDER_SOFTWARE:
- // TRANSLATORS: debug window label
- mFPSText = _("%d FPS (Software)");
- break;
- case RENDER_NORMAL_OPENGL:
- case RENDER_NULL:
- case RENDER_LAST:
- default:
- // TRANSLATORS: debug window label
- mFPSText = _("%d FPS (normal OpenGL)");
- break;
- case RENDER_SAFE_OPENGL:
- // TRANSLATORS: debug window label
- mFPSText = _("%d FPS (safe OpenGL)");
- break;
- case RENDER_GLES_OPENGL:
- // TRANSLATORS: debug window label
- mFPSText = _("%d FPS (mobile OpenGL ES)");
- break;
- case RENDER_GLES2_OPENGL:
- // TRANSLATORS: debug window label
- mFPSText = _("%d FPS (mobile OpenGL ES 2)");
- break;
- case RENDER_MODERN_OPENGL:
- // TRANSLATORS: debug window label
- mFPSText = _("%d FPS (modern OpenGL)");
- break;
- case RENDER_SDL2_DEFAULT:
- // TRANSLATORS: debug window label
- mFPSText = _("%d FPS (SDL2 default)");
- break;
- };
-#else // USE_OPENGL
-
- // TRANSLATORS: debug window label
- mFPSText = _("%d FPS (Software)");
-#endif // USE_OPENGL
-
- place(0, 0, mFPSLabel, 2);
- place(0, 1, mLPSLabel, 2);
- place(0, 2, mMusicFileLabel, 2);
- place(0, 3, mMapLabel, 2);
- place(0, 4, mMapNameLabel, 2);
- place(0, 5, mMinimapLabel, 2);
- place(0, 6, mXYLabel, 2);
- place(0, 7, mTileMouseLabel, 2);
- place(0, 8, mParticleCountLabel, 2);
- place(0, 9, mMapActorCountLabel, 2);
-#ifdef USE_OPENGL
-#if defined (DEBUG_OPENGL_LEAKS) || defined(DEBUG_DRAW_CALLS) \
- || defined(DEBUG_BIND_TEXTURE)
- int n = 10;
-#endif // defined (DEBUG_OPENGL_LEAKS) || defined(DEBUG_DRAW_CALLS)
- // || defined(DEBUG_BIND_TEXTURE)
-#ifdef DEBUG_OPENGL_LEAKS
- mTexturesLabel = new Label(this, strprintf("%s %s",
- // TRANSLATORS: debug window label
- _("Textures count:"), "?"));
- place(0, n, mTexturesLabel, 2);
- n ++;
-#endif // DEBUG_OPENGL_LEAKS
-#ifdef DEBUG_DRAW_CALLS
- place(0, n, mDrawCallsLabel, 2);
- n ++;
-#endif // DEBUG_DRAW_CALLS
-#ifdef DEBUG_BIND_TEXTURE
- place(0, n, mBindsLabel, 2);
-#endif // DEBUG_BIND_TEXTURE
-#endif // USE_OPENGL
-
- place.getCell().matchColWidth(0, 0);
- place = h.getPlacer(0, 1);
- setDimension(Rect(0, 0, 600, 300));
-}
-
-void MapDebugTab::logic()
-{
- BLOCK_START("MapDebugTab::logic")
- if (localPlayer != nullptr)
- {
- // TRANSLATORS: debug window label
- mXYLabel->setCaption(strprintf("%s (%d, %d)", _("Player Position:"),
- localPlayer->getTileX(), localPlayer->getTileY()));
- }
- else
- {
- // TRANSLATORS: debug window label
- mXYLabel->setCaption(strprintf("%s (?, ?)", _("Player Position:")));
- }
-
- Game *const game = Game::instance();
- const Map *const map = game != nullptr ? game->getCurrentMap() : nullptr;
- if (map != nullptr &&
- viewport != nullptr)
- {
- // Get the current mouse position
- const int mouseTileX = (viewport->mMouseX + viewport->getCameraX())
- / map->getTileWidth();
- const int mouseTileY = (viewport->mMouseY + viewport->getCameraY())
- / map->getTileHeight();
- mTileMouseLabel->setCaption(strprintf("%s (%d, %d)",
- // TRANSLATORS: debug window label
- _("Cursor:"), mouseTileX, mouseTileY));
-
- // TRANSLATORS: debug window label
- mMusicFileLabel->setCaption(strprintf("%s %s", _("Music:"),
- map->getProperty("music").c_str()));
- // TRANSLATORS: debug window label
- mMinimapLabel->setCaption(strprintf("%s %s", _("Minimap:"),
- map->getProperty("minimap").c_str()));
- // TRANSLATORS: debug window label
- mMapLabel->setCaption(strprintf("%s %s", _("Map:"),
- map->getProperty("_realfilename").c_str()));
- // TRANSLATORS: debug window label
- mMapNameLabel->setCaption(strprintf("%s %s", _("Map name:"),
- map->getProperty("name").c_str()));
-
- if (mUpdateTime != cur_time)
- {
- mUpdateTime = cur_time;
- // TRANSLATORS: debug window label
- mParticleCountLabel->setCaption(strprintf(_("Particle count: %d"),
- ParticleEngine::particleCount));
-
- mMapActorCountLabel->setCaption(
- // TRANSLATORS: debug window label
- strprintf("%s %d", _("Map actors count:"),
- map->getActorsCount()));
-#ifdef USE_OPENGL
-#ifdef DEBUG_OPENGL_LEAKS
- mTexturesLabel->setCaption(strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Textures count:"), textures_count));
-#endif // DEBUG_OPENGL_LEAKS
-#ifdef DEBUG_DRAW_CALLS
- if (mainGraphics)
- {
- mDrawCallsLabel->setCaption(strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Draw calls:"), mainGraphics->getDrawCalls()));
- }
-#endif // DEBUG_DRAW_CALLS
-#ifdef DEBUG_BIND_TEXTURE
- if (mainGraphics)
- {
- mBindsLabel->setCaption(strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Texture binds:"), mainGraphics->getBinds()));
- }
-#endif // DEBUG_BIND_TEXTURE
-#endif // USE_OPENGL
- }
- }
- else
- {
- // TRANSLATORS: debug window label
- mTileMouseLabel->setCaption(strprintf("%s (?, ?)", _("Cursor:")));
- // TRANSLATORS: debug window label
- mMusicFileLabel->setCaption(strprintf("%s ?", _("Music:")));
- // TRANSLATORS: debug window label
- mMinimapLabel->setCaption(strprintf("%s ?", _("Minimap:")));
- // TRANSLATORS: debug window label
- mMapLabel->setCaption(strprintf("%s ?", _("Map:")));
- // TRANSLATORS: debug window label
- mMapNameLabel->setCaption(strprintf("%s ?", _("Map name:")));
-
- mMapActorCountLabel->setCaption(
- // TRANSLATORS: debug window label
- strprintf("%s ?", _("Map actors count:")));
- }
-
- mMapActorCountLabel->adjustSize();
- mParticleCountLabel->adjustSize();
-
- mFPSLabel->setCaption(strprintf(mFPSText.c_str(), fps));
- // TRANSLATORS: debug window label, logic per second
- mLPSLabel->setCaption(strprintf(_("%d LPS"), lps));
- BLOCK_END("MapDebugTab::logic")
-}
-
-TargetDebugTab::TargetDebugTab(const Widget2 *const widget) :
- DebugTab(widget),
- // TRANSLATORS: debug window label
- mTargetLabel(new Label(this, strprintf("%s ?", _("Target:")))),
- // TRANSLATORS: debug window label
- mTargetIdLabel(new Label(this, strprintf("%s ? ", _("Target Id:")))),
- mTargetTypeLabel(new Label(this, strprintf(
- // TRANSLATORS: debug window label
- "%s ? ", _("Target type:")))),
- // TRANSLATORS: debug window label
- mTargetLevelLabel(new Label(this, strprintf("%s ?", _("Target level:")))),
- // TRANSLATORS: debug window label
- mTargetRaceLabel(new Label(this, strprintf("%s ?", _("Target race:")))),
- // TRANSLATORS: debug window label
- mTargetPartyLabel(new Label(this, strprintf("%s ?", _("Target party:")))),
- // TRANSLATORS: debug window label
- mTargetGuildLabel(new Label(this, strprintf("%s ?", _("Target guild:")))),
- // TRANSLATORS: debug window label
- mAttackDelayLabel(new Label(this, strprintf("%s ?", _("Attack delay:")))),
- // TRANSLATORS: debug window label
- mMinHitLabel(new Label(this, strprintf("%s ?", _("Minimal hit:")))),
- // TRANSLATORS: debug window label
- mMaxHitLabel(new Label(this, strprintf("%s ?", _("Maximum hit:")))),
- // TRANSLATORS: debug window label
- mCriticalHitLabel(new Label(this, strprintf("%s ?", _("Critical hit:")))),
- // TRANSLATORS: debug window label
- mKarmaLabel(new Label(this, strprintf("%s ?", _("Karma:")))),
- // TRANSLATORS: debug window label
- mMannerLabel(new Label(this, strprintf("%s ?", _("Manner:")))),
- // TRANSLATORS: debug window label
- mEffectsLabel(new Label(this, strprintf("%s ?", _("Effects:"))))
-{
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
-
- place(0, 0, mTargetLabel, 2);
- place(0, 1, mTargetIdLabel, 2);
- place(0, 2, mTargetTypeLabel, 2);
- place(0, 3, mTargetLevelLabel, 2);
- place(0, 4, mTargetRaceLabel, 2);
- place(0, 5, mAttackDelayLabel, 2);
- place(0, 6, mTargetPartyLabel, 2);
- place(0, 7, mTargetGuildLabel, 2);
- place(0, 8, mMinHitLabel, 2);
- place(0, 9, mMaxHitLabel, 2);
- place(0, 10, mCriticalHitLabel, 2);
- place(0, 11, mKarmaLabel, 2);
- place(0, 12, mMannerLabel, 2);
- place(0, 13, mEffectsLabel, 2);
-
- place.getCell().matchColWidth(0, 0);
- place = h.getPlacer(0, 1);
- setDimension(Rect(0, 0, 600, 300));
-}
-
-void TargetDebugTab::logic()
-{
- BLOCK_START("TargetDebugTab::logic")
- if ((localPlayer != nullptr) && (localPlayer->getTarget() != nullptr))
- {
- const Being *const target = localPlayer->getTarget();
-
- // TRANSLATORS: debug window label
- mTargetLabel->setCaption(strprintf("%s %s (%d, %d)", _("Target:"),
- target->getName().c_str(), target->getTileX(),
- target->getTileY()));
-
- mTargetIdLabel->setCaption(strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Target Id:"), toInt(target->getId(), int)));
- mTargetTypeLabel->setCaption(strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Target type:"), toInt(target->getSubType(), int)));
- if (target->getLevel() != 0)
- {
- mTargetLevelLabel->setCaption(strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Target Level:"), target->getLevel()));
- }
- else
- {
- mTargetLevelLabel->setCaption(strprintf("%s ?",
- // TRANSLATORS: debug window label
- _("Target Level:")));
- }
-
- mTargetRaceLabel->setCaption(strprintf("%s %s",
- // TRANSLATORS: debug window label
- _("Target race:"), target->getRaceName().c_str()));
-
- // TRANSLATORS: debug window label
- mTargetPartyLabel->setCaption(strprintf("%s %s", _("Target Party:"),
- target->getPartyName().c_str()));
-
- // TRANSLATORS: debug window label
- mTargetGuildLabel->setCaption(strprintf("%s %s", _("Target Guild:"),
- target->getGuildName().c_str()));
-
- mMinHitLabel->setCaption(strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Minimal hit:"), target->getMinHit()));
- mMaxHitLabel->setCaption(strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Maximum hit:"), target->getMaxHit()));
- mCriticalHitLabel->setCaption(strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Critical hit:"), target->getCriticalHit()));
- mKarmaLabel->setCaption(strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Karma:"), target->getKarma()));
- mMannerLabel->setCaption(strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Manner:"), target->getManner()));
- mEffectsLabel->setCaption(strprintf("%s %s",
- // TRANSLATORS: debug window label
- _("Effects:"), target->getStatusEffectsString().c_str()));
-
- const int delay = target->getAttackDelay();
- if (delay != 0)
- {
- mAttackDelayLabel->setCaption(strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Attack delay:"), delay));
- }
- else
- {
- mAttackDelayLabel->setCaption(strprintf(
- // TRANSLATORS: debug window label
- "%s ?", _("Attack delay:")));
- }
- }
- else
- {
- // TRANSLATORS: debug window label
- mTargetLabel->setCaption(strprintf("%s ?", _("Target:")));
- // TRANSLATORS: debug window label
- mTargetIdLabel->setCaption(strprintf("%s ?", _("Target Id:")));
- // TRANSLATORS: debug window label
- mTargetTypeLabel->setCaption(strprintf("%s ?", _("Target type:")));
- // TRANSLATORS: debug window label
- mTargetLevelLabel->setCaption(strprintf("%s ?", _("Target Level:")));
- // TRANSLATORS: debug window label
- mTargetPartyLabel->setCaption(strprintf("%s ?", _("Target Party:")));
- // TRANSLATORS: debug window label
- mTargetGuildLabel->setCaption(strprintf("%s ?", _("Target Guild:")));
- // TRANSLATORS: debug window label
- mAttackDelayLabel->setCaption(strprintf("%s ?", _("Attack delay:")));
- // TRANSLATORS: debug window label
- mMinHitLabel->setCaption(strprintf("%s ?", _("Minimal hit:")));
- // TRANSLATORS: debug window label
- mMaxHitLabel->setCaption(strprintf("%s ?", _("Maximum hit:")));
- // TRANSLATORS: debug window label
- mCriticalHitLabel->setCaption(strprintf("%s ?", _("Critical hit:")));
- // TRANSLATORS: debug window label
- mKarmaLabel->setCaption(strprintf("%s ?", _("Karma:")));
- // TRANSLATORS: debug window label
- mMannerLabel->setCaption(strprintf("%s ?", _("Manner:")));
- // TRANSLATORS: debug window label
- mEffectsLabel->setCaption(strprintf("%s ?", _("Effects:")));
- }
-
- mTargetLabel->adjustSize();
- mTargetIdLabel->adjustSize();
- mTargetTypeLabel->adjustSize();
- mTargetLevelLabel->adjustSize();
- mTargetPartyLabel->adjustSize();
- mTargetGuildLabel->adjustSize();
- mAttackDelayLabel->adjustSize();
- mMinHitLabel->adjustSize();
- mMaxHitLabel->adjustSize();
- mCriticalHitLabel->adjustSize();
- mKarmaLabel->adjustSize();
- mMannerLabel->adjustSize();
- mEffectsLabel->adjustSize();
- BLOCK_END("TargetDebugTab::logic")
-}
-
-NetDebugTab::NetDebugTab(const Widget2 *const widget) :
- DebugTab(widget),
- mPingLabel(new Label(this, " ")),
- mInPackets1Label(new Label(this, " ")),
- mOutPackets1Label(new Label(this, " "))
-{
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
-
- place(0, 0, mPingLabel, 2);
- place(0, 1, mInPackets1Label, 2);
- place(0, 2, mOutPackets1Label, 2);
-
- place.getCell().matchColWidth(0, 0);
- place = h.getPlacer(0, 1);
- setDimension(Rect(0, 0, 600, 300));
-}
-
-void NetDebugTab::logic()
-{
- BLOCK_START("NetDebugTab::logic")
- if (localPlayer != nullptr)
- {
- // TRANSLATORS: debug window label
- mPingLabel->setCaption(strprintf(_("Ping: %s ms"),
- localPlayer->getPingTime().c_str()));
- }
- else
- {
- // TRANSLATORS: debug window label
- mPingLabel->setCaption(strprintf(_("Ping: %s ms"), "0"));
- }
- // TRANSLATORS: debug window label
- mInPackets1Label->setCaption(strprintf(_("In: %d bytes/s"),
- PacketCounters::getInBytes()));
- // TRANSLATORS: debug window label
- mOutPackets1Label->setCaption(strprintf(_("Out: %d bytes/s"),
- PacketCounters::getOutBytes()));
- BLOCK_END("NetDebugTab::logic")
-}
diff --git a/src/gui/widgets/tabs/debugwindowtabs.h b/src/gui/widgets/tabs/debugwindowtabs.h
deleted file mode 100644
index 566987cd0..000000000
--- a/src/gui/widgets/tabs/debugwindowtabs.h
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_DEBUGWINDOWTABS_H
-#define GUI_WIDGETS_TABS_DEBUGWINDOWTABS_H
-
-#include "gui/widgets/container.h"
-
-class Label;
-
-class DebugTab notfinal : public Container
-{
- friend class DebugWindow;
-
- public:
- A_DELETE_COPY(DebugTab)
-
- void logic() override
- {
- }
-
- void resize(const int x, const int y)
- { setDimension(Rect(0, 0, x, y)); }
-
- protected:
- explicit DebugTab(const Widget2 *const widget) :
- Container(widget)
- { setSelectable(false); }
-};
-
-class MapDebugTab final : public DebugTab
-{
- friend class DebugWindow;
-
- public:
- explicit MapDebugTab(const Widget2 *const widget);
-
- A_DELETE_COPY(MapDebugTab)
-
- void logic() override final;
-
- private:
- Label *mMusicFileLabel A_NONNULLPOINTER;
- Label *mMapLabel A_NONNULLPOINTER;
- Label *mMapNameLabel A_NONNULLPOINTER;
- Label *mMinimapLabel A_NONNULLPOINTER;
- Label *mTileMouseLabel A_NONNULLPOINTER;
- Label *mParticleCountLabel A_NONNULLPOINTER;
- Label *mMapActorCountLabel A_NONNULLPOINTER;
- Label *mXYLabel A_NONNULLPOINTER;
- Label *mTexturesLabel A_NONNULLPOINTER;
- time_t mUpdateTime;
-#ifdef DEBUG_DRAW_CALLS
- Label *mDrawCallsLabel A_NONNULLPOINTER;
-#endif // DEBUG_DRAW_CALLS
-#ifdef DEBUG_BIND_TEXTURE
- Label *mBindsLabel A_NONNULLPOINTER;
-#endif // DEBUG_BIND_TEXTURE
-
- Label *mFPSLabel A_NONNULLPOINTER;
- Label *mLPSLabel A_NONNULLPOINTER;
- std::string mFPSText;
-};
-
-class TargetDebugTab final : public DebugTab
-{
- friend class DebugWindow;
-
- public:
- explicit TargetDebugTab(const Widget2 *const widget);
-
- A_DELETE_COPY(TargetDebugTab)
-
- void logic() override final;
-
- private:
- Label *mTargetLabel A_NONNULLPOINTER;
- Label *mTargetIdLabel A_NONNULLPOINTER;
- Label *mTargetTypeLabel A_NONNULLPOINTER;
- Label *mTargetLevelLabel A_NONNULLPOINTER;
- Label *mTargetRaceLabel A_NONNULLPOINTER;
- Label *mTargetPartyLabel A_NONNULLPOINTER;
- Label *mTargetGuildLabel A_NONNULLPOINTER;
- Label *mAttackDelayLabel A_NONNULLPOINTER;
- Label *mMinHitLabel A_NONNULLPOINTER;
- Label *mMaxHitLabel A_NONNULLPOINTER;
- Label *mCriticalHitLabel A_NONNULLPOINTER;
- Label *mKarmaLabel A_NONNULLPOINTER;
- Label *mMannerLabel A_NONNULLPOINTER;
- Label *mEffectsLabel A_NONNULLPOINTER;
-};
-
-class NetDebugTab final : public DebugTab
-{
- friend class DebugWindow;
-
- public:
- explicit NetDebugTab(const Widget2 *const widget);
-
- A_DELETE_COPY(NetDebugTab)
-
- void logic() override final;
-
- private:
- Label *mPingLabel A_NONNULLPOINTER;
- Label *mInPackets1Label A_NONNULLPOINTER;
- Label *mOutPackets1Label A_NONNULLPOINTER;
-};
-
-#endif // GUI_WIDGETS_TABS_DEBUGWINDOWTABS_H
diff --git a/src/gui/widgets/tabs/setup_audio.cpp b/src/gui/widgets/tabs/setup_audio.cpp
deleted file mode 100644
index 6275ff59a..000000000
--- a/src/gui/widgets/tabs/setup_audio.cpp
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_audio.h"
-
-#include "resources/map/map.h"
-
-#include "configuration.h"
-#include "soundmanager.h"
-
-#include "gui/viewport.h"
-
-#include "gui/models/soundsmodel.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "utils/delete2.h"
-
-#include "debug.h"
-
-Setup_Audio::Setup_Audio(const Widget2 *const widget) :
- SetupTabScroll(widget),
- mSoundModel(new SoundsModel),
- mChannelsList(new SetupItemNames)
-{
- // TRANSLATORS: audio tab in settings
- setName(_("Audio"));
-
- // Do the layout
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
- place(0, 0, mScroll, 10, 10);
-
- // TRANSLATORS: settings option
- new SetupItemLabel(_("Basic settings"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable Audio"), "", "sound", this, "soundEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable music"), "",
- "playMusic", this, "playMusicEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable game sfx"), "",
- "playBattleSound", this, "playBattleSoundEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable gui sfx"), "",
- "playGuiSound", this, "playGuiSoundEvent");
-
- // TRANSLATORS: settings option
- new SetupItemSlider(_("Sfx volume"), "", "sfxVolume",
- this, "sfxVolumeEvent", 0, SoundManager::getMaxVolume(), 1,
- 150,
- OnTheFly_true,
- MainConfig_true);
-
- // TRANSLATORS: settings option
- new SetupItemSlider(_("Music volume"), "", "musicVolume",
- this, "musicVolumeEvent", 0, SoundManager::getMaxVolume(), 1,
- 150,
- OnTheFly_true,
- MainConfig_true);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable music fade out"), "",
- "fadeoutmusic", this, "fadeoutmusicEvent");
-
- // TRANSLATORS: settings option
- new SetupItemIntTextField(_("Audio frequency"), "",
- "audioFrequency", this, "audioFrequencyEvent", 14000, 192000);
-
- // TRANSLATORS: audio type
- mChannelsList->push_back(_("mono"));
- // TRANSLATORS: audio type
- mChannelsList->push_back(_("stereo"));
- // TRANSLATORS: audio type
- mChannelsList->push_back(_("surround"));
- // TRANSLATORS: audio type
- mChannelsList->push_back(_("surround+center+lfe"));
- // TRANSLATORS: settings option
- new SetupItemSlider2(_("Audio channels"), "", "audioChannels", this,
- "audioChannels", 1, 4, 1, mChannelsList,
- OnTheFly_false,
- MainConfig_true,
- DoNotAlign_false);
-
- // TRANSLATORS: settings option
- new SetupItemIntTextField(_("Parallel number of sounds"), "",
- "parallelAudioChannels", this, "parallelAudioChannelsEvent", 1, 1000);
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Sound effects"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemSound(_("Information dialog sound"), "",
- "soundinfo", this, "soundinfoEvent", mSoundModel);
-
- // TRANSLATORS: settings option
- new SetupItemSound(_("Request dialog sound"), "",
- "soundrequest", this, "soundrequestEvent", mSoundModel);
-
- // TRANSLATORS: settings option
- new SetupItemSound(_("Whisper message sound"), "",
- "soundwhisper", this, "soundwhisperEvent", mSoundModel);
-
- // TRANSLATORS: settings option
- new SetupItemSound(_("Guild / Party message sound"), "",
- "soundguild", this, "soundguildEvent", mSoundModel);
-
- // TRANSLATORS: settings option
- new SetupItemSound(_("Highlight message sound"), "",
- "soundhighlight", this, "soundhighlightEvent", mSoundModel);
-
- // TRANSLATORS: settings option
- new SetupItemSound(_("Global message sound"), "",
- "soundglobal", this, "soundglobalEvent", mSoundModel);
-
- // TRANSLATORS: settings option
- new SetupItemSound(_("Error message sound"), "",
- "sounderror", this, "sounderrorEvent", mSoundModel);
-
- // TRANSLATORS: settings option
- new SetupItemSound(_("Trade request sound"), "",
- "soundtrade", this, "soundtradeEvent", mSoundModel);
-
- // TRANSLATORS: settings option
- new SetupItemSound(_("Show window sound"), "",
- "soundshowwindow", this, "soundshowwindowEvent", mSoundModel);
-
- // TRANSLATORS: settings option
- new SetupItemSound(_("Hide window sound"), "",
- "soundhidewindow", this, "soundhidewindowEvent", mSoundModel);
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Other"), "", this);
-
-#ifdef USE_MUMBLE
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable mumble voice chat"), "",
- "enableMumble", this, "enableMumbleEvent");
-#endif // USE_MUMBLE
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Download music"), "",
- "download-music", this, "download-musicEvent");
-
- setDimension(Rect(0, 0, 550, 350));
-}
-
-Setup_Audio::~Setup_Audio()
-{
- delete2(mSoundModel);
- delete2(mChannelsList);
-}
-
-void Setup_Audio::apply()
-{
- SetupTabScroll::apply();
- if (config.getBoolValue("sound"))
- {
- soundManager.init();
- if (config.getBoolValue("playMusic"))
- {
- if (viewport != nullptr)
- { // in game
- const Map *const map = viewport->getMap();
- if (map != nullptr)
- {
- soundManager.playMusic(map->getMusicFile(),
- SkipError_false);
- }
- }
- else
- { // not in game
- soundManager.playMusic(branding.getValue(
- "loginMusic",
- "keprohm.ogg"),
- SkipError_true);
- }
- }
- else
- {
- soundManager.stopMusic();
- }
- }
- else
- {
- soundManager.close();
- }
-}
diff --git a/src/gui/widgets/tabs/setup_audio.h b/src/gui/widgets/tabs/setup_audio.h
deleted file mode 100644
index d76add16c..000000000
--- a/src/gui/widgets/tabs/setup_audio.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_AUDIO_H
-#define GUI_WIDGETS_TABS_SETUP_AUDIO_H
-
-#include "gui/widgets/setupitem.h"
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-class Setup_Audio final : public SetupTabScroll
-{
- public:
- explicit Setup_Audio(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Audio)
-
- ~Setup_Audio();
-
- void apply() override final;
-
- private:
- ListModel *mSoundModel;
-
- SetupItemNames *mChannelsList;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_AUDIO_H
diff --git a/src/gui/widgets/tabs/setup_chat.cpp b/src/gui/widgets/tabs/setup_chat.cpp
deleted file mode 100644
index b27e1ec53..000000000
--- a/src/gui/widgets/tabs/setup_chat.cpp
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_chat.h"
-
-#include "gui/windows/chatwindow.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/setupitem.h"
-
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-Setup_Chat::Setup_Chat(const Widget2 *const widget) :
- SetupTabScroll(widget)
-{
- // TRANSLATORS: settings tab name
- setName(_("Chat"));
-
- // Do the layout
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
- place(0, 0, mScroll, 10, 10);
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Window"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Auto hide chat window"),
- // TRANSLATORS: settings description
- _("Chat window will be automatically hidden when not in use.\n\n"
- "Hit Enter or hover mouse to show chat again."),
- "autohideChat", this, "autohideChatEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Protect chat focus"),
- // TRANSLATORS: settings description
- _("Enables aggressive protection of input focus in chat window.\n\n"
- "Note: no other text inputs will be allowed to receive text input "
- "when you typing in chat window."),
- "protectChatFocus", this, "protectChatFocusEvent");
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Colors"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Remove colors from received chat messages"),
- // TRANSLATORS: settings description
- _("Enable this setting to strip colors from incoming chat messages. "
- "All messages will use default chat text color if this enabled."),
- "removeColors", this, "removeColorsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show chat colors list"),
- // TRANSLATORS: settings description
- _("Enable this setting to show color selection drop-down in chat "
- "window. Chat window will display color selection drop-down.\n\n"
- "It allows one to select default color of outgoing chat messages "
- "easily, but also occupies some space in chat window."),
- "showChatColorsList", this, "showChatColorsListEvent");
-
-
- // TRANSLATORS: settings option
- new SetupItemLabel(_("Commands"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Allow magic and GM commands in all chat tabs"),
- // TRANSLATORS: settings description
- _("Enable this setting to be able to type spells and GM commands in "
- "any tab."),
- "allowCommandsInChatTabs", this, "allowCommandsInChatTabsEvent");
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Limits"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemIntTextField(_("Limit max chars in chat line"),
- // TRANSLATORS: settings description
- _("Limits how many characters will be shown in longest lines "
- "of text displayed in chat.\n\n"
- "Note: long lines can make client slower. Lines longer than this "
- "limit will be truncated."),
- "chatMaxCharLimit", this, "chatMaxCharLimitEvent", 0, 500);
-
- // TRANSLATORS: settings option
- new SetupItemIntTextField(_("Limit max lines in chat"),
- // TRANSLATORS: settings description
- _("Limits how many lines chat will keep in scrollback buffer. Chat "
- "keeps specified number of last lines of text. Oldest lines exceeding "
- "this limit are discarded from scrollback buffer.\n\n"
- "Note: keeping too many lines in scroll buffer can slow client down."),
- "chatMaxLinesLimit", this, "chatMaxLinesLimitEvent", 0, 500);
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Logs"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable chat Log"),
- // TRANSLATORS: settings description
- _("If you enable this setting, chat logs will be written to disk.\n\n"
- "Note: chat logs can take noticeable amount of disk space over time."),
- "enableChatLog", this, "enableChatLogEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable debug chat Log"),
- // TRANSLATORS: settings description
- _("If you enable this, debug chat tab also will be logged to disk."),
- "enableDebugLog", this, "enableDebugLogEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show chat history"),
- // TRANSLATORS: settings description
- _("If this setting enabled, client will load old chat tabs content "
- "from logs on startup instead of starting with empty chat tabs."),
- "showChatHistory", this, "showChatHistoryEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show party online messages"),
- // TRANSLATORS: settings description
- _("If this setting is enabled, online status changes of party members"
- " will be shown in party tab of chat.\n\nThis adds some extra noise "
- "to chat, but allows one to see when your buddies are coming online."),
- "showPartyOnline", this, "showPartyOnlineEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show guild online messages"),
- // TRANSLATORS: settings description
- _("If this setting is enabled, online status changes of guild members"
- " will be shown in guild tab of chat.\n\nThis adds some extra noise "
- "to chat, but allows one to see when your buddies are coming online."),
- "showGuildOnline", this, "showGuildOnlineEvent");
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Messages"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Hide shop messages"),
- // TRANSLATORS: settings description
- _("If this setting enabled, no messages related to built-in ManaPlus "
- "shop will be displayed in chat. Disable this setting if you want "
- "to see shop-related messages.\n\nNote: technically, ManaPlus shop "
- "implemented as usual private messages with special content. If you "
- "disable this setting, you will be able to see these messages and get "
- "idea when other players are looking at your shop."),
- "hideShopMessages", this, "hideShopMessagesEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show MVP messages"),
- // TRANSLATORS: settings description
- _("Enable this setting to see MVP messages from server.\n\n"
- "Note: MVP messages are not used on TMW/Evol/etc servers, so this "
- "feature usually makes little difference."),
- "showMVP", this, "showMVPEvent");
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Tabs"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Put all whispers in tabs"),
- // TRANSLATORS: settings description
- _("If this setting enabled, all whispers (private messages) will "
- "be placed in separate tabs, separate tab for each player. If this "
- "setting disabled, all whispers will appear in General tab.\n\n"
- "Note: putting all whispers to single General tab is known to be "
- "confusing. Think twice before disabling this feature."),
- "whispertab", this, "whispertabEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Log magic messages in debug tab"),
- // TRANSLATORS: settings description
- _("If this setting is enabled, spell invocation will be shown in "
- "Debug tab. If disabled, it will be shown in General tab instead.\n\n"
- "Note: it does not affects server replies related to spells."),
- "showMagicInDebug", this, "showMagicInDebugEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show server messages in debug tab"),
- // TRANSLATORS: settings description
- _("If this setting is enabled, server messages will be shown in "
- "Debug tab of chat. If disabled, server messages will appear in "
- "General chat instead.\n\nNote: according to 4144, disabling this "
- "could also make you to lose some debug messages from client in "
- "Debug tab since these are fake server messages."),
- "serverMsgInDebug", this, "serverMsgInDebugEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable trade tab"),
- // TRANSLATORS: settings description
- _("Enables trade tab. Trade tab is basically some filter. Messages "
- "containing words typical for trades will go to Trade tab. This "
- "will make General tab less noisy. If this setting is disabled, all "
- "trade related players messages will stay in General tab."),
- "enableTradeTab", this, "enableTradeTabEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable gm tab"),
- // TRANSLATORS: settings description
- _("If enabled, GM tab will appear in chat. It displays text related "
- "GM activity.\n\nNote: this setting only makes difference for "
- "GMs (Game Masters) since this tab only appears for GMs."),
- "enableGmTab", this, "enableGmTabEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable language tab"),
- // TRANSLATORS: settings description
- _("If this feature enabled, language tab will appear if server "
- "supports this feature.\n\nNote: only supported by Evol server yet."),
- "enableLangTab", this, "enableLangTabEvent",
- MainConfig_false);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show all languages messages"),
- // TRANSLATORS: settings description
- _("If this setting enabled and server supports different chats "
- "for different languages, you will see messages for all languages, "
- "regardless of your language preferences.\n\nNote: it only works "
- "on servers supporting language tabs feature, like Evol."),
- "showAllLang", this, "showAllLangEvent",
- MainConfig_false);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable battle tab"),
- // TRANSLATORS: settings description
- _("If this setting enabled, Battle tab will appear in chat. This "
- "tab will contain messages related to battles, like damage and "
- "experience gain, if battle messages are enabled.\n\n"
- "Note: client restart required to take effect."),
- "enableBattleTab", this, "enableBattleTabEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show battle events"),
- // TRANSLATORS: settings description
- _("If this setting enabled, messages related to battle like damage "
- "or experience gain will be displayed in Debug or Battle tab. If "
- "disabled, no battle messages will be displayed."),
- "showBattleEvents", this, "showBattleEventsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Resize chat tabs if need"),
- // TRANSLATORS: settings description
- _("If this feature enabled, text in chat will be automatically "
- "adjusted to adapt to appearance of chat input field when you "
- "typing message and when input field of chat disappears. If disabled, "
- "chat input area will always occupy its place, which could be "
- "otherwise usable for text.\n\n"
- "Note: its mostly about jumpy attitude vs "
- "less usable space for text."),
- "hideChatInput", this, "hideChatInputEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable trade spam filter"),
- "", "enableTradeFilter", this, "enableTradeFilterEvent");
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Time"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Use local time"),
- // TRANSLATORS: settings description
- _("If this feature enabled, timestamps in chat will use local times. "
- "If disabled, server time will be used (often it is GMT+0)."),
- "useLocalTime", this, "useLocalTimeEvent");
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Other"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemTextField(_("Highlight words (separated by comma)"),
- // TRANSLATORS: settings description
- _("Here you can specify some extra words which will also cause "
- "highlighting. Use comma to separate words.\n\nNote: frequent "
- "highlights are annoying - use it with caution."),
- "highlightWords", this, "highlightWordsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemTextField(_("Globals ignore names (separated by comma)"),
- // TRANSLATORS: settings description
- _("This setting allows you to ignore some global messages if "
- "particular sender (NPC, GM) annoys you too much. Global will be "
- "moved to Debug instead.\n\nNote: careless use of this feature can "
- "make you to miss important announces!"),
- "globalsFilter", this, "globalsFilterEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show emotes button in chat"),
- // TRANSLATORS: settings description
- _("If this setting enabled, button will appear near text input "
- "field. This button allows one to invoke composing window, which "
- "allows one to insert smiles and text formatting easily.\n\n"
- "Note: same window can also be invoked by hotkey when typing, usually "
- "F1 by default."),
- "showEmotesButton", this, "showEmotesButtonEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show motd server message on start"),
- // TRANSLATORS: settings description
- _("If this setting enabled, client will display server MOTD (message"
- " of the day) once you connect to server. Disable it to hide MOTD."),
- "showmotd", this, "showmotdEvent");
-
- setDimension(Rect(0, 0, 550, 350));
-}
-
-void Setup_Chat::apply()
-{
- SetupTabScroll::apply();
-
- if (chatWindow != nullptr)
- {
- chatWindow->adjustTabSize();
- chatWindow->parseHighlights();
- }
-}
-
-void Setup_Chat::externalUpdated()
-{
- reread("enableLangTab");
- reread("showAllLang");
-}
diff --git a/src/gui/widgets/tabs/setup_chat.h b/src/gui/widgets/tabs/setup_chat.h
deleted file mode 100644
index 2b18b0489..000000000
--- a/src/gui/widgets/tabs/setup_chat.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_CHAT_H
-#define GUI_WIDGETS_TABS_SETUP_CHAT_H
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-class Setup_Chat final : public SetupTabScroll
-{
- public:
- explicit Setup_Chat(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Chat)
-
- void apply() override final;
-
- void externalUpdated() override final;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_CHAT_H
diff --git a/src/gui/widgets/tabs/setup_colors.cpp b/src/gui/widgets/tabs/setup_colors.cpp
deleted file mode 100644
index 4f2b35113..000000000
--- a/src/gui/widgets/tabs/setup_colors.cpp
+++ /dev/null
@@ -1,491 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 Douglas Boffey <dougaboffey@netscape.net>
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_colors.h"
-
-#include "gui/gui.h"
-#include "gui/userpalette.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/widgets/browserbox.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/listbox.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/slider.h"
-#include "gui/widgets/textfield.h"
-#include "gui/widgets/textpreview.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include <cmath>
-
-#include "debug.h"
-
-const char *const Setup_Colors::rawmsg =
- // TRANSLATORS: color selection preview message
- N_("This is what the color looks like");
-
-Setup_Colors::Setup_Colors(const Widget2 *const widget) :
- SetupTab(widget),
- SelectionListener(),
- mColorBox(CREATEWIDGETR(ListBox, this, userPalette, "")),
- mScroll(new ScrollArea(this, mColorBox,
- Opaque_true, "setup_colors_background.xml")),
- mPreview(new BrowserBox(this, Opaque_true,
- "browserbox.xml")),
- mTextPreview(new TextPreview(this, gettext(rawmsg))),
- mPreviewBox(new ScrollArea(this, mPreview, Opaque_true,
- "setup_colors_preview_background.xml")),
- mSelected(-1),
- // TRANSLATORS: colors tab. label.
- mGradTypeLabel(new Label(this, _("Type:"))),
- mGradTypeSlider(new Slider(this, 0.0, 3.0, 1.0)),
- mGradTypeText(new Label(this)),
- // TRANSLATORS: colors tab. label.
- mGradDelayLabel(new Label(this, _("Delay:"))),
- mGradDelaySlider(new Slider(this, 20.0, 100.0, 1.0)),
- mGradDelayText(new TextField(this)),
- // TRANSLATORS: colors tab. label.
- mRedLabel(new Label(this, _("Red:"))),
- mRedSlider(new Slider(this, 0.0, 255.0, 1.0)),
- mRedText(new TextField(this)),
- // TRANSLATORS: colors tab. label.
- mGreenLabel(new Label(this, _("Green:"))),
- mGreenSlider(new Slider(this, 0.0, 255.0, 1.0)),
- mGreenText(new TextField(this)),
- // TRANSLATORS: colors tab. label.
- mBlueLabel(new Label(this, _("Blue:"))),
- mBlueSlider(new Slider(this, 0.0, 255.0, 1.0)),
- mBlueText(new TextField(this))
-{
- // TRANSLATORS: settings colors tab name
- setName(_("Colors"));
- mColorBox->addSelectionListener(this);
- mScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- mPreview->setOpaque(Opaque_false);
-
- // don't do anything with links
- mPreview->setLinkHandler(nullptr);
-
- mPreviewBox->setHeight(20);
- mPreviewBox->setScrollPolicy(ScrollArea::SHOW_NEVER,
- ScrollArea::SHOW_NEVER);
-
- mGradTypeSlider->setWidth(180);
- mGradTypeSlider->setActionEventId("slider_grad");
- mGradTypeSlider->setValue(0);
- mGradTypeSlider->addActionListener(this);
- mGradTypeSlider->setEnabled(false);
-
- // TRANSLATORS: color type
- std::string longText = _("Static");
-
- const Font *const font = getFont();
- // TRANSLATORS: color type
- if (getFont()->getWidth(_("Pulse")) > font->getWidth(longText))
- {
- // TRANSLATORS: color type
- longText = _("Pulse");
- }
- // TRANSLATORS: color type
- if (getFont()->getWidth(_("Rainbow")) > font->getWidth(longText))
- {
- // TRANSLATORS: color type
- longText = _("Rainbow");
- }
- // TRANSLATORS: color type
- if (getFont()->getWidth(_("Spectrum")) > font->getWidth(longText))
- {
- // TRANSLATORS: color type
- longText = _("Spectrum");
- }
-
- mGradTypeText->setCaption(longText);
-
- mGradDelayText->setWidth(40);
- mGradDelayText->setRange(20, 100);
- mGradDelayText->setNumeric(true);
- mGradDelayText->setEnabled(false);
-
- mGradDelaySlider->setWidth(180);
- mGradDelaySlider->setValue(mGradDelayText->getValue());
- mGradDelaySlider->setActionEventId("slider_graddelay");
- mGradDelaySlider->addActionListener(this);
- mGradDelaySlider->setEnabled(false);
-
- mRedText->setWidth(40);
- mRedText->setRange(0, 255);
- mRedText->setNumeric(true);
- mRedText->setEnabled(false);
-
- mRedSlider->setWidth(180);
- mRedSlider->setValue(mRedText->getValue());
- mRedSlider->setActionEventId("slider_red");
- mRedSlider->addActionListener(this);
- mRedSlider->setEnabled(false);
-
- mGreenText->setWidth(40);
- mGreenText->setRange(0, 255);
- mGreenText->setNumeric(true);
- mGreenText->setEnabled(false);
-
- mGreenSlider->setWidth(180);
- mGreenSlider->setValue(mGreenText->getValue());
- mGreenSlider->setActionEventId("slider_green");
- mGreenSlider->addActionListener(this);
- mGreenSlider->setEnabled(false);
-
- mBlueText->setWidth(40);
- mBlueText->setRange(0, 255);
- mBlueText->setNumeric(true);
- mBlueText->setEnabled(false);
-
- mBlueSlider->setWidth(180);
- mBlueSlider->setValue(mBlueText->getValue());
- mBlueSlider->setActionEventId("slider_blue");
- mBlueSlider->addActionListener(this);
- mBlueSlider->setEnabled(false);
-
- setOpaque(Opaque_false);
-
- // Do the layout
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
-
- place(0, 0, mScroll, 6, 6).setPadding(2);
- place(0, 6, mPreviewBox, 6).setPadding(2);
- place(0, 7, mGradTypeLabel, 3);
- place(3, 7, mGradTypeSlider);
- place(4, 7, mGradTypeText, 2).setPadding(1);
- place(0, 8, mRedLabel, 3);
- place(3, 8, mRedSlider);
- place(5, 8, mRedText).setPadding(1);
- place(0, 9, mGreenLabel, 3);
- place(3, 9, mGreenSlider);
- place(5, 9, mGreenText).setPadding(1);
- place(0, 10, mBlueLabel, 3);
- place(3, 10, mBlueSlider);
- place(5, 10, mBlueText).setPadding(1);
- place(0, 11, mGradDelayLabel, 3);
- place(3, 11, mGradDelaySlider);
- place(5, 11, mGradDelayText).setPadding(1);
-
- mGradTypeText->setCaption("");
-
- setDimension(Rect(0, 0, 365, 350));
-}
-
-Setup_Colors::~Setup_Colors()
-{
- if ((mPreviewBox != nullptr) && mPreviewBox->getContent() == mPreview)
- delete2(mTextPreview)
- else
- delete2(mPreview)
-}
-
-void Setup_Colors::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "slider_grad")
- {
- updateGradType();
- updateColor();
- return;
- }
-
- if (eventId == "slider_graddelay")
- {
- mGradDelayText->setText(toString(
- std::floor(mGradDelaySlider->getValue())));
- updateColor();
- return;
- }
- if (eventId == "slider_red")
- {
- mRedText->setText(toString(std::floor(mRedSlider->getValue())));
- updateColor();
- return;
- }
- if (eventId == "slider_green")
- {
- mGreenText->setText(toString(std::floor(mGreenSlider->getValue())));
- updateColor();
- return;
- }
- if (eventId == "slider_blue")
- {
- mBlueText->setText(toString(std::floor(mBlueSlider->getValue())));
- updateColor();
- return;
- }
-}
-
-void Setup_Colors::valueChanged(const SelectionEvent &event A_UNUSED)
-{
- if (userPalette == nullptr)
- return;
-
- mSelected = mColorBox->getSelected();
- const UserColorIdT type = static_cast<UserColorIdT>(
- userPalette->getColorTypeAt(mSelected));
- const Color *col = &userPalette->getColor(type);
- const GradientTypeT grad = userPalette->getGradientType(type);
- const int delay = userPalette->getGradientDelay(type);
- const Visible showControls = fromBool(grad != GradientType::LABEL,
- Visible);
- mPreview->setVisible(showControls);
- mPreviewBox->setVisible(showControls);
- mTextPreview->setVisible(showControls);
- mGradTypeLabel->setVisible(showControls);
- mGradTypeSlider->setVisible(showControls);
- mGradTypeText->setVisible(showControls);
- mGradDelayLabel->setVisible(showControls);
- mGradDelaySlider->setVisible(showControls);
- mGradDelayText->setVisible(showControls);
- mRedLabel->setVisible(showControls);
- mRedSlider->setVisible(showControls);
- mRedText->setVisible(showControls);
- mGreenLabel->setVisible(showControls);
- mGreenSlider->setVisible(showControls);
- mGreenText->setVisible(showControls);
- mBlueLabel->setVisible(showControls);
- mBlueSlider->setVisible(showControls);
- mBlueText->setVisible(showControls);
-
- mPreview->clearRows();
- mPreviewBox->setContent(mTextPreview);
- mTextPreview->setFont(boldFont);
- mTextPreview->setTextColor(col);
- mTextPreview->setTextBGColor(nullptr);
- mTextPreview->setOpaque(Opaque_false);
- mTextPreview->setShadow(true);
- mTextPreview->setOutline(true);
- mTextPreview->useTextAlpha(false);
-
-// probably need combite both switches and add all mssing color ids.
-
- PRAGMA45(GCC diagnostic push)
- PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
- switch (type)
- {
- case UserColorId::AIR_COLLISION_HIGHLIGHT:
- case UserColorId::WATER_COLLISION_HIGHLIGHT:
- case UserColorId::MONSTER_COLLISION_HIGHLIGHT:
- case UserColorId::GROUNDTOP_COLLISION_HIGHLIGHT:
- case UserColorId::COLLISION_HIGHLIGHT:
- case UserColorId::PORTAL_HIGHLIGHT:
- case UserColorId::HOME_PLACE:
- case UserColorId::ROAD_POINT:
- case UserColorId::NET:
- mTextPreview->setBGColor(col);
- mTextPreview->setOpaque(Opaque_true);
- mTextPreview->setOutline(false);
- mTextPreview->setShadow(false);
- break;
- case UserColorId::ATTACK_RANGE_BORDER:
- case UserColorId::HOME_PLACE_BORDER:
- if (gui != nullptr)
- mTextPreview->setFont(gui->getFont());
- mTextPreview->setTextColor(col);
- mTextPreview->setOutline(false);
- mTextPreview->setShadow(false);
- break;
- case UserColorId::PARTICLE:
- case UserColorId::EXP_INFO:
- case UserColorId::PICKUP_INFO:
- case UserColorId::HIT_PLAYER_MONSTER:
- case UserColorId::HIT_MONSTER_PLAYER:
- case UserColorId::HIT_CRITICAL:
- case UserColorId::MISS:
- case UserColorId::HIT_LOCAL_PLAYER_MONSTER:
- case UserColorId::HIT_LOCAL_PLAYER_CRITICAL:
- case UserColorId::HIT_LOCAL_PLAYER_MISS:
- case UserColorId::ATTACK_RANGE:
- case UserColorId::MONSTER_ATTACK_RANGE:
- case UserColorId::FLOOR_ITEM_TEXT:
- case UserColorId::SKILL_ATTACK_RANGE:
- mTextPreview->setShadow(false);
- break;
- default:
- break;
- }
-
- switch (type)
- {
- case UserColorId::PORTAL_HIGHLIGHT:
- case UserColorId::ATTACK_RANGE:
- case UserColorId::ATTACK_RANGE_BORDER:
- case UserColorId::MONSTER_ATTACK_RANGE:
- case UserColorId::SKILL_ATTACK_RANGE:
- case UserColorId::HOME_PLACE:
- case UserColorId::HOME_PLACE_BORDER:
- case UserColorId::AIR_COLLISION_HIGHLIGHT:
- case UserColorId::WATER_COLLISION_HIGHLIGHT:
- case UserColorId::MONSTER_COLLISION_HIGHLIGHT:
- case UserColorId::GROUNDTOP_COLLISION_HIGHLIGHT:
- case UserColorId::COLLISION_HIGHLIGHT:
- case UserColorId::WALKABLE_HIGHLIGHT:
- case UserColorId::ROAD_POINT:
- case UserColorId::MONSTER_HP:
- case UserColorId::MONSTER_HP2:
- case UserColorId::HOMUN_HP:
- case UserColorId::HOMUN_HP2:
- case UserColorId::MERC_HP:
- case UserColorId::MERC_HP2:
- case UserColorId::ELEMENTAL_HP:
- case UserColorId::ELEMENTAL_HP2:
- case UserColorId::PLAYER_HP:
- case UserColorId::PLAYER_HP2:
- case UserColorId::FLOOR_ITEM_TEXT:
- case UserColorId::NET:
- // TRANSLATORS: colors tab. label.
- mGradDelayLabel->setCaption(_("Alpha:"));
- mGradDelayText->setRange(0, 255);
- mGradDelaySlider->setScale(0, 255);
- break;
- default:
- // TRANSLATORS: colors tab. label.
- mGradDelayLabel->setCaption(_("Delay:"));
- mGradDelayText->setRange(20, 100);
- mGradDelaySlider->setScale(20, 100);
- break;
- }
- PRAGMA45(GCC diagnostic pop)
- if (grad != GradientType::STATIC && grad != GradientType::PULSE)
- { // If nonstatic color, don't display the current, but the committed
- // color at the sliders
- col = &userPalette->getCommittedColor(type);
- }
- else if (grad == GradientType::PULSE)
- {
- col = &userPalette->getTestColor(type);
- }
-
- setEntry(mGradDelaySlider, mGradDelayText, delay);
- setEntry(mRedSlider, mRedText, col->r);
- setEntry(mGreenSlider, mGreenText, col->g);
- setEntry(mBlueSlider, mBlueText, col->b);
-
- mGradTypeSlider->setValue(CAST_S32(grad));
- updateGradType();
- mGradTypeSlider->setEnabled(true);
-}
-
-void Setup_Colors::setEntry(Slider *const s, TextField *const t,
- const int value)
-{
- if (s != nullptr)
- s->setValue(value);
- if (t != nullptr)
- t->setText(toString(value));
-}
-
-void Setup_Colors::apply()
-{
- if (userPalette != nullptr)
- userPalette->commit();
-}
-
-void Setup_Colors::cancel()
-{
- if (userPalette == nullptr)
- return;
-
- userPalette->rollback();
- const UserColorIdT type = static_cast<UserColorIdT>(
- userPalette->getColorTypeAt(mSelected));
- const Color *const col = &userPalette->getColor(type);
- mGradTypeSlider->setValue(CAST_S32(
- userPalette->getGradientType(type)));
- const int delay = userPalette->getGradientDelay(type);
- setEntry(mGradDelaySlider, mGradDelayText, delay);
- setEntry(mRedSlider, mRedText, col->r);
- setEntry(mGreenSlider, mGreenText, col->g);
- setEntry(mBlueSlider, mBlueText, col->b);
-}
-
-void Setup_Colors::updateGradType()
-{
- if (mSelected == -1 || (userPalette == nullptr))
- return;
-
- mSelected = mColorBox->getSelected();
- const UserColorIdT type = static_cast<UserColorIdT>(
- userPalette->getColorTypeAt(mSelected));
- const GradientTypeT grad = userPalette->getGradientType(type);
-
- mGradTypeText->setCaption(
- // TRANSLATORS: color type
- (grad == GradientType::STATIC) ? _("Static") :
- // TRANSLATORS: color type
- (grad == GradientType::PULSE) ? _("Pulse") :
- // TRANSLATORS: color type
- (grad == GradientType::RAINBOW) ? _("Rainbow") : _("Spectrum"));
-
- const bool enable = (grad == GradientType::STATIC ||
- grad == GradientType::PULSE);
- const bool delayEnable = true;
-
- mGradDelayText->setEnabled(delayEnable);
- mGradDelaySlider->setEnabled(delayEnable);
-
- mRedText->setEnabled(enable);
- mRedSlider->setEnabled(enable);
- mGreenText->setEnabled(enable);
- mGreenSlider->setEnabled(enable);
- mBlueText->setEnabled(enable);
- mBlueSlider->setEnabled(enable);
-}
-
-void Setup_Colors::updateColor() const
-{
- if (mSelected == -1 || (userPalette == nullptr))
- return;
-
- const UserColorIdT type = static_cast<UserColorIdT>(
- userPalette->getColorTypeAt(mSelected));
- const GradientTypeT grad = static_cast<GradientTypeT>(
- CAST_S32(mGradTypeSlider->getValue()));
- const int delay = CAST_S32(mGradDelaySlider->getValue());
- userPalette->setGradient(type, grad);
- userPalette->setGradientDelay(type, delay);
-
- if (grad == GradientType::STATIC)
- {
- userPalette->setColor(type,
- CAST_S32(mRedSlider->getValue()),
- CAST_S32(mGreenSlider->getValue()),
- CAST_S32(mBlueSlider->getValue()));
- }
- else if (grad == GradientType::PULSE)
- {
- userPalette->setTestColor(type, Color(
- CAST_S32(mRedSlider->getValue()),
- CAST_S32(mGreenSlider->getValue()),
- CAST_S32(mBlueSlider->getValue())));
- }
-}
diff --git a/src/gui/widgets/tabs/setup_colors.h b/src/gui/widgets/tabs/setup_colors.h
deleted file mode 100644
index 1ba74f340..000000000
--- a/src/gui/widgets/tabs/setup_colors.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 Douglas Boffey <dougaboffey@netscape.net>
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_COLORS_H
-#define GUI_WIDGETS_TABS_SETUP_COLORS_H
-
-#include "gui/widgets/tabs/setuptab.h"
-
-#include "listeners/selectionlistener.h"
-
-class BrowserBox;
-class Label;
-class ListBox;
-class ScrollArea;
-class Slider;
-class TextField;
-class TextPreview;
-
-class Setup_Colors final : public SetupTab,
- public SelectionListener
-{
- public:
- explicit Setup_Colors(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Colors)
-
- ~Setup_Colors();
-
- void apply() override final;
-
- void cancel() override final;
-
- void action(const ActionEvent &event) override final;
-
- void valueChanged(const SelectionEvent &event) override final;
-
- private:
- static const char *const rawmsg;
-
- ListBox *mColorBox A_NONNULLPOINTER;
- ScrollArea *mScroll A_NONNULLPOINTER;
- BrowserBox *mPreview A_NONNULLPOINTER;
- TextPreview *mTextPreview A_NONNULLPOINTER;
- ScrollArea *mPreviewBox A_NONNULLPOINTER;
- int mSelected;
-
- Label *mGradTypeLabel A_NONNULLPOINTER;
- Slider *mGradTypeSlider A_NONNULLPOINTER;
- Label *mGradTypeText A_NONNULLPOINTER;
-
- Label *mGradDelayLabel A_NONNULLPOINTER;
- Slider *mGradDelaySlider A_NONNULLPOINTER;
- TextField *mGradDelayText A_NONNULLPOINTER;
-
- Label *mRedLabel A_NONNULLPOINTER;
- Slider *mRedSlider A_NONNULLPOINTER;
- TextField *mRedText A_NONNULLPOINTER;
-
- Label *mGreenLabel A_NONNULLPOINTER;
- Slider *mGreenSlider A_NONNULLPOINTER;
- TextField *mGreenText A_NONNULLPOINTER;
-
- Label *mBlueLabel A_NONNULLPOINTER;
- Slider *mBlueSlider A_NONNULLPOINTER;
- TextField *mBlueText A_NONNULLPOINTER;
-
- static void setEntry(Slider *const s, TextField *const t,
- const int value);
- void updateColor() const;
- void updateGradType();
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_COLORS_H
diff --git a/src/gui/widgets/tabs/setup_input.cpp b/src/gui/widgets/tabs/setup_input.cpp
deleted file mode 100644
index dc1e531f8..000000000
--- a/src/gui/widgets/tabs/setup_input.cpp
+++ /dev/null
@@ -1,399 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007 Joshua Langley <joshlangley@optusnet.com.au>
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_input.h"
-
-#include "configuration.h"
-
-#include "const/gui/pages.h"
-
-#include "input/inputactionoperators.h"
-#include "input/inputmanager.h"
-#include "input/keyboardconfig.h"
-
-#include "input/pages/craft.h"
-#include "input/pages/emotes.h"
-#include "input/pages/move.h"
-#include "input/pages/outfits.h"
-#include "input/pages/shortcuts.h"
-
-#include "gui/gui.h"
-#include "gui/setupinputpages.h"
-
-#include "gui/windows/okdialog.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/listbox.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/tabstrip.h"
-
-#include "gui/models/keylistmodel.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-Setup_Input::Setup_Input(const Widget2 *const widget) :
- SetupTab(widget),
- mKeyListModel(new KeyListModel),
- mKeyList(CREATEWIDGETR(ListBox, this, mKeyListModel, "")),
- // TRANSLATORS: button in input settings tab
- mAssignKeyButton(new Button(this, _("Assign"), "assign", this)),
- // TRANSLATORS: button in input settings tab
- mUnassignKeyButton(new Button(this, _("Unassign"), "unassign", this)),
- // TRANSLATORS: button in input settings tab
- mDefaultButton(new Button(this, _("Default"), "default", this)),
- // TRANSLATORS: button in input settings tab
- mResetKeysButton(new Button(this, _("Reset all keys"), "resetkeys", this)),
- mTabs(new TabStrip(this, config.getIntValue("fontSize") + 10)),
- mScrollArea(new ScrollArea(this, mKeyList,
- Opaque_true, "setup_input_background.xml")),
- mKeySetting(false),
- mActionDataSize(new int [SETUP_PAGES])
-{
- inputManager.setSetupInput(this);
- // TRANSLATORS: setting tab name
- setName(_("Input"));
-
- mKeyListModel->setSelectedData(0);
-
- for (int f = 0; f < SETUP_PAGES; f ++)
- {
- int cnt = 0;
- while (!setupActionData[f][cnt].name.empty())
- cnt ++;
- mActionDataSize[f] = cnt;
- }
-
- mKeyListModel->setSize(mActionDataSize[0]);
- refreshKeys();
- if (gui != nullptr)
- mKeyList->setFont(gui->getHelpFont());
- mKeyList->addActionListener(this);
-
- mScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- mAssignKeyButton->addActionListener(this);
- mAssignKeyButton->setEnabled(false);
- mUnassignKeyButton->addActionListener(this);
- mUnassignKeyButton->setEnabled(false);
- mResetKeysButton->addActionListener(this);
- mDefaultButton->addActionListener(this);
-
- mTabs->addActionListener(this);
- mTabs->setActionEventId("tabs_");
- int k = 0;
- while (pages[k] != nullptr)
- {
- mTabs->addButton(gettext(pages[k]), pages[k], false);
- k ++;
- }
-
- fixTranslations();
-
- // Do the layout
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
-
- place(0, 0, mTabs, 5);
- place(0, 1, mScrollArea, 5, 5).setPadding(2);
- place(0, 6, mResetKeysButton);
- place(2, 6, mAssignKeyButton);
- place(3, 6, mUnassignKeyButton);
- place(4, 6, mDefaultButton);
-
- int width = 600;
- if (config.getIntValue("screenwidth") >= 730)
- width += 100;
-
- setDimension(Rect(0, 0, width, 350));
-}
-
-Setup_Input::~Setup_Input()
-{
- delete2(mKeyList);
- delete2(mKeyListModel);
- delete2(mAssignKeyButton);
- delete2(mUnassignKeyButton);
- delete2(mResetKeysButton);
- delete [] mActionDataSize;
- mActionDataSize = nullptr;
- delete2(mScrollArea);
-}
-
-void Setup_Input::apply()
-{
- keyUnresolved();
- InputActionT key1, key2;
-
- if (inputManager.hasConflicts(key1, key2))
- {
- const std::string str1 = keyToString(key1);
- const std::string str2 = keyToString(key2);
-
- CREATEWIDGET(OkDialog,
- // TRANSLATORS: input settings error header
- _("Key Conflict(s) Detected."),
- // TRANSLATORS: input settings error
- strprintf(_("Conflict \"%s\" and \"%s\" keys. "
- "Resolve them, or gameplay may result in strange behaviour."),
- gettext(str1.c_str()), gettext(str2.c_str())),
- // TRANSLATORS: ok dialog button
- _("OK"),
- DialogType::ERROR,
- Modal_true,
- ShowCenter_true,
- nullptr,
- 260);
- }
- keyboard.setEnabled(true);
- inputManager.store();
-}
-
-void Setup_Input::cancel()
-{
- keyUnresolved();
- inputManager.retrieve();
- keyboard.setEnabled(true);
- refreshKeys();
-}
-
-void Setup_Input::action(const ActionEvent &event)
-{
- const std::string &id = event.getId();
- const int selectedData = mKeyListModel->getSelectedData();
-
- if (event.getSource() == mKeyList)
- {
- if (!mKeySetting)
- {
- const int i(mKeyList->getSelected());
- if (i >= 0 && i < mActionDataSize[selectedData])
- {
- if (setupActionData[selectedData][i].actionId
- == InputAction::NO_VALUE)
- {
- mAssignKeyButton->setEnabled(false);
- mUnassignKeyButton->setEnabled(false);
- }
- else
- {
- mAssignKeyButton->setEnabled(true);
- mUnassignKeyButton->setEnabled(true);
- }
- }
- }
- }
- else if (id == "assign")
- {
- mKeySetting = true;
- mAssignKeyButton->setEnabled(false);
- keyboard.setEnabled(false);
- const int i(mKeyList->getSelected());
- if (i >= 0 && i < mActionDataSize[selectedData])
- {
- const SetupActionData &key = setupActionData[selectedData][i];
- const InputActionT ik = key.actionId;
- inputManager.setNewKeyIndex(ik);
- mKeyListModel->setElementAt(i, std::string(
- gettext(key.name.c_str())).append(": ?"));
- }
- }
- else if (id == "unassign")
- {
- const int i(mKeyList->getSelected());
- if (i >= 0 && i < mActionDataSize[selectedData])
- {
- const SetupActionData &key = setupActionData[selectedData][i];
- const InputActionT ik = key.actionId;
- inputManager.setNewKeyIndex(ik);
- refreshAssignedKey(mKeyList->getSelected());
- inputManager.unassignKey();
- inputManager.setNewKeyIndex(InputAction::NO_VALUE);
- }
- mAssignKeyButton->setEnabled(true);
- }
- else if (id == "resetkeys")
- {
- inputManager.resetKeys();
- InputManager::update();
- refreshKeys();
- }
- else if (id == "default")
- {
- const int i(mKeyList->getSelected());
- if (i >= 0 && i < mActionDataSize[selectedData])
- {
- const SetupActionData &key = setupActionData[selectedData][i];
- const InputActionT ik = key.actionId;
- inputManager.makeDefault(ik);
- refreshKeys();
- }
- }
- else if (strStartWith(id, "tabs_"))
- {
- int k = 0;
- std::string str("tabs_");
- while (pages[k] != nullptr)
- {
- if (str + pages[k] == id)
- break;
- k ++;
- }
- if ((pages[k] != nullptr) && str + pages[k] == id)
- {
- mKeyListModel->setSelectedData(k);
- mKeyListModel->setSize(mActionDataSize[k]);
- refreshKeys();
- mKeyList->setSelected(0);
- }
- }
-}
-
-void Setup_Input::refreshAssignedKey(const int index)
-{
- const int selectedData = mKeyListModel->getSelectedData();
- const SetupActionData &key = setupActionData[selectedData][index];
- if (key.actionId == InputAction::NO_VALUE)
- {
- const std::string str(" \342\200\225\342\200\225\342\200\225"
- "\342\200\225\342\200\225 ");
- mKeyListModel->setElementAt(index,
- str + gettext(key.name.c_str()) + str);
- }
- else
- {
- std::string str = gettext(key.name.c_str());
- unsigned int sz = 20;
- if (mainGraphics->mWidth > 800)
- sz = 30;
- while (str.size() < sz)
- str.append(" ");
- mKeyListModel->setElementAt(index, strprintf("%s: %s", str.c_str(),
- inputManager.getKeyStringLong(key.actionId).c_str()));
- }
-}
-
-void Setup_Input::newKeyCallback(const InputActionT index)
-{
- mKeySetting = false;
- const int i = keyToSetupData(index);
- if (i >= 0)
- refreshAssignedKey(i);
- mAssignKeyButton->setEnabled(true);
-}
-
-int Setup_Input::keyToSetupData(const InputActionT index) const
-{
- const int selectedData = mKeyListModel->getSelectedData();
- for (int i = 0; i < mActionDataSize[selectedData]; i++)
- {
- const SetupActionData &key = setupActionData[selectedData][i];
- if (key.actionId == index)
- return i;
- }
- return -1;
-}
-
-std::string Setup_Input::keyToString(const InputActionT index) const
-{
- for (int f = 0; f < SETUP_PAGES; f ++)
- {
- for (int i = 0; i < mActionDataSize[f]; i++)
- {
- const SetupActionData &key = setupActionData[f][i];
- if (key.actionId == index)
- return key.name;
- }
- }
- // TRANSLATORS: unknown key name
- return _("unknown");
-}
-
-void Setup_Input::refreshKeys()
-{
- const int selectedData = mKeyListModel->getSelectedData();
- for (int i = 0; i < mActionDataSize[selectedData]; i++)
- refreshAssignedKey(i);
-}
-
-void Setup_Input::keyUnresolved()
-{
- if (mKeySetting)
- {
- newKeyCallback(inputManager.getNewKeyIndex());
- inputManager.setNewKeyIndex(InputAction::NO_VALUE);
- }
-}
-
-void Setup_Input::fixTranslation(SetupActionData *const actionDatas,
- const InputActionT actionStart,
- const InputActionT actionEnd,
- const std::string &text)
-{
- int k = 0;
-
- while (!actionDatas[k].name.empty())
- {
- SetupActionData &data = actionDatas[k];
-
- const InputActionT actionId = data.actionId;
- if (actionId >= actionStart && actionId <= actionEnd)
- {
- data.name = strprintf(gettext(text.c_str()),
- actionId - actionStart + 1);
- }
- k ++;
- }
-}
-
-void Setup_Input::fixTranslations()
-{
- fixTranslation(setupActionDataShortcuts,
- InputAction::SHORTCUT_1,
- InputAction::SHORTCUT_20,
- "Item Shortcut %d");
-
- fixTranslation(setupActionDataEmotes,
- InputAction::EMOTE_1,
- InputAction::EMOTE_48,
- "Emote Shortcut %d");
-
- fixTranslation(setupActionDataCraft,
- InputAction::CRAFT_1,
- InputAction::CRAFT_9,
- "Craft shortcut %d");
-
- fixTranslation(setupActionDataOutfits,
- InputAction::OUTFIT_1,
- InputAction::OUTFIT_48,
- "Outfit Shortcut %d");
-
- fixTranslation(setupActionDataMove,
- InputAction::MOVE_TO_POINT_1,
- InputAction::MOVE_TO_POINT_48,
- "Move to point Shortcut %d");
-}
diff --git a/src/gui/widgets/tabs/setup_input.h b/src/gui/widgets/tabs/setup_input.h
deleted file mode 100644
index 2da411b2c..000000000
--- a/src/gui/widgets/tabs/setup_input.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007 Joshua Langley <joshlangley@optusnet.com.au>
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_INPUT_H
-#define GUI_WIDGETS_TABS_SETUP_INPUT_H
-
-#include "enums/input/inputaction.h"
-
-#include "gui/widgets/tabs/setuptab.h"
-
-class Button;
-class ListBox;
-class KeyListModel;
-class ScrollArea;
-class TabStrip;
-
-struct SetupActionData;
-
-class Setup_Input final : public SetupTab
-{
- public:
- /**
- * Constructor
- */
- explicit Setup_Input(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Input)
-
- /**
- * Destructor
- */
- ~Setup_Input();
-
- void apply() override final;
-
- void cancel() override final;
-
- void action(const ActionEvent &event) override final;
-
- /**
- * Get an update on the assigned key.
- */
- void refreshAssignedKey(const int index);
-
- /**
- * The callback function when a new key has been pressed.
- */
- void newKeyCallback(const InputActionT index);
-
- /**
- * Shorthand method to update all the keys.
- */
- void refreshKeys();
-
- /**
- * If a key function is unresolved, then this reverts it.
- */
- void keyUnresolved();
-
- int keyToSetupData(const InputActionT index) const A_WARN_UNUSED;
-
- std::string keyToString(const InputActionT index) const A_WARN_UNUSED;
-
- private:
- static void fixTranslations();
-
- static void fixTranslation(SetupActionData *const actionDatas,
- const InputActionT actionStart,
- const InputActionT actionEnd,
- const std::string &text) A_NONNULL(1);
-
- KeyListModel *mKeyListModel;
- ListBox *mKeyList;
-
- Button *mAssignKeyButton;
- Button *mUnassignKeyButton;
- Button *mDefaultButton;
- Button *mResetKeysButton;
- TabStrip *mTabs;
- ScrollArea *mScrollArea;
- bool mKeySetting; /**< flag to check if key being set. */
- int *mActionDataSize;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_INPUT_H
diff --git a/src/gui/widgets/tabs/setup_joystick.cpp b/src/gui/widgets/tabs/setup_joystick.cpp
deleted file mode 100644
index 84cd60521..000000000
--- a/src/gui/widgets/tabs/setup_joystick.cpp
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_joystick.h"
-
-#include "configuration.h"
-
-#include "input/joystick.h"
-
-#include "gui/models/namesmodel.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/checkbox.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/dropdown.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layouthelper.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-Setup_Joystick::Setup_Joystick(const Widget2 *const widget) :
- SetupTab(widget),
- mCalibrateLabel(new Label(this,
- // TRANSLATORS: joystick settings tab label
- _("Press the button to start calibration"))),
- // TRANSLATORS: joystick settings tab button
- mCalibrateButton(new Button(this, _("Calibrate"), "calibrate", this)),
- // TRANSLATORS: joystick settings tab button
- mDetectButton(new Button(this, _("Detect joysticks"), "detect", this)),
- // TRANSLATORS: joystick settings tab checkbox
- mJoystickEnabled(new CheckBox(this, _("Enable joystick"))),
- mNamesModel(new NamesModel),
- mNamesDropDown(new DropDown(this, mNamesModel)),
- // TRANSLATORS: joystick settings tab checkbox
- mUseInactiveCheckBox(new CheckBox(this, _("Use joystick if client "
- "window inactive"), config.getBoolValue("useInactiveJoystick"))),
- mOriginalJoystickEnabled(config.getBoolValue("joystickEnabled"))
-{
- // TRANSLATORS: joystick settings tab name
- setName(_("Joystick"));
-
- Joystick::getNames(mNamesModel->getNames());
-
- mJoystickEnabled->setSelected(mOriginalJoystickEnabled);
- mJoystickEnabled->setActionEventId("joystick");
- mJoystickEnabled->addActionListener(this);
- mCalibrateButton->setEnabled(mOriginalJoystickEnabled);
-
- mNamesDropDown->setActionEventId("name");
- mNamesDropDown->addActionListener(this);
-
- if (joystick != nullptr)
- {
- mNamesDropDown->setSelected(joystick->getNumber());
- }
- else
- {
- unsigned int sel = config.getIntValue("selectedJoystick");
- if (sel >= CAST_U32(mNamesModel->size()))
- sel = 0;
- mNamesDropDown->setSelected(sel);
- }
-
- // Do the layout
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
-
- place(0, 0, mJoystickEnabled);
- place(0, 1, mNamesDropDown);
- place(0, 2, mUseInactiveCheckBox);
- place(0, 3, mDetectButton);
- place(0, 4, mCalibrateLabel);
- place(0, 5, mCalibrateButton);
-
- setDimension(Rect(0, 0, 365, 75));
-}
-
-Setup_Joystick::~Setup_Joystick()
-{
- delete2(mNamesModel);
-}
-
-void Setup_Joystick::action(const ActionEvent &event)
-{
- const Widget *const source = event.getSource();
- if (source == mJoystickEnabled)
- {
- setTempEnabled(mJoystickEnabled->isSelected());
- }
- else if (source == mNamesDropDown)
- {
- if (joystick != nullptr)
- joystick->setNumber(mNamesDropDown->getSelected());
- }
- else if (source == mDetectButton)
- {
- if (joystick != nullptr)
- {
- joystick->reload();
- Joystick::getNames(mNamesModel->getNames());
- mNamesDropDown->setSelected(joystick->getNumber());
- }
- }
- else
- {
- if (joystick == nullptr)
- return;
-
- if (joystick->isCalibrating())
- {
- // TRANSLATORS: joystick settings tab button
- mCalibrateButton->setCaption(_("Calibrate"));
- mCalibrateLabel->setCaption
- // TRANSLATORS: joystick settings tab label
- (_("Press the button to start calibration"));
- joystick->finishCalibration();
- }
- else
- {
- // TRANSLATORS: joystick settings tab button
- mCalibrateButton->setCaption(_("Stop"));
- mCalibrateLabel->setCaption(
- // TRANSLATORS: joystick settings tab label
- _("Rotate the stick and don't press buttons"));
- joystick->startCalibration();
- }
- }
-}
-
-void Setup_Joystick::setTempEnabled(const bool sel)
-{
- Joystick::setEnabled(sel);
- mCalibrateButton->setEnabled(sel);
- if (joystick != nullptr)
- {
- if (sel)
- joystick->open();
- else
- joystick->close();
- }
-}
-
-void Setup_Joystick::cancel()
-{
- Joystick::setEnabled(mOriginalJoystickEnabled);
-
- if (mOriginalJoystickEnabled != mJoystickEnabled->isSelected())
- setTempEnabled(mOriginalJoystickEnabled);
-
- mJoystickEnabled->setSelected(mOriginalJoystickEnabled);
-}
-
-void Setup_Joystick::apply()
-{
- if (joystick == nullptr)
- return;
-
- config.setValue("joystickEnabled", Joystick::isEnabled());
-
- config.setValue("useInactiveJoystick", mUseInactiveCheckBox->isSelected());
- joystick->setUseInactive(mUseInactiveCheckBox->isSelected());
-}
diff --git a/src/gui/widgets/tabs/setup_joystick.h b/src/gui/widgets/tabs/setup_joystick.h
deleted file mode 100644
index c66ab8687..000000000
--- a/src/gui/widgets/tabs/setup_joystick.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_JOYSTICK_H
-#define GUI_WIDGETS_TABS_SETUP_JOYSTICK_H
-
-#include "gui/widgets/tabs/setuptab.h"
-
-class Button;
-class CheckBox;
-class DropDown;
-class Label;
-class NamesModel;
-
-class Setup_Joystick final : public SetupTab
-{
- public:
- explicit Setup_Joystick(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Joystick)
-
- ~Setup_Joystick();
-
- void apply() override final;
-
- void cancel() override final;
-
- void action(const ActionEvent &event) override final;
-
- void setTempEnabled(const bool sel);
-
- private:
- Label *mCalibrateLabel A_NONNULLPOINTER;
- Button *mCalibrateButton A_NONNULLPOINTER;
- Button *mDetectButton A_NONNULLPOINTER;
- CheckBox *mJoystickEnabled A_NONNULLPOINTER;
- NamesModel *mNamesModel A_NONNULLPOINTER;
- DropDown *mNamesDropDown A_NONNULLPOINTER;
- CheckBox *mUseInactiveCheckBox A_NONNULLPOINTER;
- bool mOriginalJoystickEnabled A_NONNULLPOINTER;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_JOYSTICK_H
diff --git a/src/gui/widgets/tabs/setup_misc.cpp b/src/gui/widgets/tabs/setup_misc.cpp
deleted file mode 100644
index 07b4c5193..000000000
--- a/src/gui/widgets/tabs/setup_misc.cpp
+++ /dev/null
@@ -1,518 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_misc.h"
-
-#include "configuration.h"
-
-#include "const/resources/map/map.h"
-
-#include "gui/models/namesmodel.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/setupbuttonitem.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "listeners/uploadlistener.h"
-
-#include "net/net.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-static const int shortcutsListSize = 3;
-
-static const char *const shortcutsList[] =
-{
- // TRANSLATORS: show buttons at top right corner type
- N_("Always show"),
- // TRANSLATORS: show buttons at top right corner type
- N_("Auto hide in small resolution"),
- // TRANSLATORS: show buttons at top right corner type
- N_("Always auto hide")
-};
-
-static const int proxyTypeListSize = 8;
-
-static const char *const proxyTypeList[] =
-{
- // TRANSLATORS: Proxy type selection
- N_("System proxy"),
- // TRANSLATORS: Proxy type selection
- N_("Direct connection"),
- "HTTP",
- "HTTP 1.0",
- "SOCKS4",
- "SOCKS4A",
- "SOCKS5",
- // TRANSLATORS: Proxy type selection
- N_("SOCKS5 hostname")
-};
-
-static const int densityListSize = 7;
-
-static const char *const densityList[] =
-{
- // TRANSLATORS: screen density type
- N_("default"),
- // TRANSLATORS: screen density type
- N_("low"),
- // TRANSLATORS: screen density type
- N_("medium"),
- // TRANSLATORS: screen density type
- N_("tv"),
- // TRANSLATORS: screen density type
- N_("high"),
- // TRANSLATORS: screen density type
- N_("xhigh"),
- // TRANSLATORS: screen density type
- N_("xxhigh")
-};
-
-#ifdef USE_SDL2
-static const int sdlLogListSize = 7;
-
-static const char *const sdlLogList[] =
-{
- // TRANSLATORS: sdl2 log level
- N_("default"),
- // TRANSLATORS: sdl2 log level
- N_("verbose"),
- // TRANSLATORS: sdl2 log level
- N_("debug"),
- // TRANSLATORS: sdl2 log level
- N_("info"),
- // TRANSLATORS: sdl2 log level
- N_("warn"),
- // TRANSLATORS: sdl2 log level
- N_("error"),
- // TRANSLATORS: sdl2 log level
- N_("critical")
-};
-#endif // USE_SDL2
-
-Setup_Misc::Setup_Misc(const Widget2 *const widget) :
- SetupTabScroll(widget),
- mProxyTypeList(new NamesModel),
- mShortcutsList(new NamesModel),
-#ifdef USE_SDL2
- mSdlLogList(new NamesModel),
-#endif // USE_SDL2
- mDensityList(new NamesModel)
-{
- // TRANSLATORS: misc tab in settings
- setName(_("Misc"));
-
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
- place(0, 0, mScroll, 10, 10);
-
- // TRANSLATORS: settings option
- new SetupItemLabel(_("Monsters"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show damage inflicted to monsters"), "",
- "showMonstersTakedDamage", this, "showMonstersTakedDamageEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Auto target only reachable monsters"), "",
- "targetOnlyReachable", this, "targetOnlyReachableEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Select auto target for attack skills"), "",
- "skillAutotarget", this, "skillAutotargetEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Highlight monster attack range"), "",
- "highlightMonsterAttackRange", this,
- "highlightMonsterAttackRangeEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show monster hp bar"), "",
- "showMobHP", this, "showMobHPEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Cycle monster targets"), "",
- "cycleMonsters", this, "cycleMonstersEvent");
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Map"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show warps particles"), "",
- "warpParticle", this, "warpParticleEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Highlight map portals"), "",
- "highlightMapPortals", this, "highlightMapPortalsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Highlight floor items"), "",
- "floorItemsHighlight", this, "floorItemsHighlightEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Highlight player attack range"), "",
- "highlightAttackRange", this, "highlightAttackRangeEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show extended minimaps"), "",
- "showExtMinimaps", this, "showExtMinimapsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Draw path"), "", "drawPath",
- this, "drawPathEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Draw hotkeys on map"), "", "drawHotKeys",
- this, "drawHotKeysEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable lazy scrolling"), "",
- "enableLazyScrolling", this, "enableLazyScrollingEvent");
-
- // TRANSLATORS: settings option
- new SetupItemIntTextField(_("Scroll laziness"), "", "ScrollLaziness",
- this, "ScrollLazinessEvent", 1, 160);
-
- // TRANSLATORS: settings option
- new SetupItemIntTextField(_("Scroll radius"), "", "ScrollRadius",
- this, "ScrollRadiusEvent", 0, mapTileSize);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Auto resize minimaps"), "", "autoresizeminimaps",
- this, "autoresizeminimapsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Play map animations"), "", "playMapAnimations",
- this, "playMapAnimationsEvent");
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Moving"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Auto fix position"), "",
- "autofixPos", this, "autofixPosEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show server side position"), "",
- "showserverpos", this, "showserverposEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Attack while moving"), "",
- "attackMoving", this, "attackMovingEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Attack next target"), "",
- "attackNext", this, "attackNextEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Sync player move"), "", "syncPlayerMove",
- this, "syncPlayerMoveEvent");
-
- // TRANSLATORS: settings option
- new SetupItemIntTextField(_("Sync player move distance"), "",
- "syncPlayerMoveDistance",
- this, "syncPlayerMoveDistanceEvent", 1, 30);
-
- // TRANSLATORS: settings option
- new SetupItemTextField(_("Crazy move A program"), "",
- "crazyMoveProgram", this, "crazyMoveProgramEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Mouse relative moves "
- "(good for touch interfaces)"), "", "mouseDirectionMove",
- this, "mouseDirectionMoveEvent");
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Player"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show own hp bar"), "",
- "showOwnHP", this, "showOwnHPEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable quick stats"), "",
- "quickStats", this, "quickStatsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Cycle player targets"), "",
- "cyclePlayers", this, "cyclePlayersEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show job exp messages"), "",
- "showJobExp", this, "showJobExpEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show players popups"), "",
- "showBeingPopup", this, "showBeingPopupEvent");
-
- // TRANSLATORS: settings option
- new SetupItemTextField(_("Afk message"), "",
- "afkMessage", this, "afkMessageEvent",
- MainConfig_false);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show job"), "", "showJob",
- this, "showJobEvent",
- MainConfig_false);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable attack filter"), "",
- "enableAttackFilter", this, "enableAttackFilterEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable pickup filter"), "",
- "enablePickupFilter", this, "enablePickupFilterEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable advert protocol"), "",
- "enableAdvert", this, "enableAdvertEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enabled pets support"),
- "", "usepets", this, "usepetsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable weight notifications"), "",
- "weightMsg", this, "weightMsgEvent");
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Shop"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Accept sell/buy requests"), "",
- "autoShop", this, "autoShopEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable shop mode"), "",
- "tradebot", this, "tradebotEvent");
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("NPC"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Cycle npc targets"), "",
- "cycleNPC", this, "cycleNPCEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Log NPC dialogue"), "", "logNpcInGui",
- this, "logNpcInGuiEvent");
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Bots support"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable guild bot support and disable native "
- "guild support"), "", "enableGuildBot", this,
- "enableGuildBotEvent",
- "0",
- MainConfig_false);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable manamarket bot support"),
- "", "enableManaMarketBot", this,
- "enableManaMarketBotEvent",
- "0",
- MainConfig_false);
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Keyboard"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemIntTextField(_("Repeat delay"), "",
- "repeateDelay", this, "repeateDelayEvent", 0, 10000);
-
- // TRANSLATORS: settings option
- new SetupItemIntTextField(_("Repeat interval"), "",
- "repeateInterval", this, "repeateIntervalEvent", 0, 10000);
-
- // TRANSLATORS: settings option
- new SetupItemIntTextField(_("Custom repeat interval"), "",
- "repeateInterval2", this, "repeateInterval2Event", 0, 10000);
-
-#ifdef USE_SDL2
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable alt-tab workaround"), "",
- "blockAltTab", this, "blockAltTabEvent");
-#endif // USE_SDL2
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Windows"), "", this);
-
- mShortcutsList->fillFromArray(&shortcutsList[0], shortcutsListSize);
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Shortcut buttons"), "", "autohideButtons", this,
- "autohideButtonsEvent", mShortcutsList, 200);
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Proxy server"), "", this);
-
- mProxyTypeList->fillFromArray(&proxyTypeList[0], proxyTypeListSize);
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Proxy type"), "", "downloadProxyType", this,
- "downloadProxyTypeEvent", mProxyTypeList, 200);
-
- // TRANSLATORS: settings option
- new SetupItemTextField(_("Proxy address:port"), "",
- "downloadProxy", this, "downloadProxyEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Tunnel through HTTP proxy"), "",
- "downloadProxyTunnel", this, "downloadProxyTunnelEvent");
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Logging"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable OpenGL version check "
- "(do not disable)"), "", "checkOpenGLVersion", this,
- "checkOpenGLVersionEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable debug log"), "",
- "debugLog", this, "debugLogEvent");
-
- // TRANSLATORS: settings option
- new SetupItemTextField(_("Ignore logging packets"), "",
- "ignorelogpackets", this, "ignorelogpacketsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Log unimplemented packets"), "",
- "unimplimentedLog", this, "unimplimentedLogEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable OpenGL log"), "",
- "debugOpenGL", this, "debugOpenGLEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable input log"), "",
- "logInput", this, "logInputEvent");
-
-#ifdef USE_SDL2
- mSdlLogList->fillFromArray(&sdlLogList[0], sdlLogListSize);
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("SDL logging level"), "",
- "sdlLogLevel", this, "sdlLogLevelEvent", mSdlLogList, 100);
-#endif // USE_SDL2
-
- // TRANSLATORS: settings option
- new SetupButtonItem(_("Upload log file"), "", "upload",
- this, "uploadLog", &uploadListener);
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Other"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable server side attack"), "",
- "serverAttack", this, "serverAttackEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Hide support page link on error"), "",
- "hidesupport", this, "hidesupportEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable double clicks"), "",
- "doubleClick", this, "doubleClickEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable bot checker"), "",
- "enableBotCheker", this, "enableBotChekerEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable buggy servers protection "
- "(do not disable)"), "", "enableBuggyServers", this,
- "enableBuggyServersEvent",
- MainConfig_false);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Low traffic mode"), "", "lowTraffic",
- this, "lowTrafficEvent");
-
-#ifndef ANDROID
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Use FBO for screenshots (only for opengl)"),
- "", "usefbo", this, "usefboEvent");
-#endif // ANDROID
-
-#ifndef WIN32
- // TRANSLATORS: settings option
- new SetupItemTextField(_("Screenshot directory"), "",
- "screenshotDirectory3", this, "screenshotDirectory3Event",
- MainConfig_true,
- UseBase64_true);
-#endif // WIN32
-
- // TRANSLATORS: settings option
- new SetupItemIntTextField(_("Network delay between sub servers"),
- "", "networksleep", this, "networksleepEvent", 0, 10000);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show background"), "", "showBackground",
- this, "showBackgroundEvent");
-
- mDensityList->fillFromArray(&densityList[0], densityListSize);
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Screen density override"), "",
- "screenDensity", this, "screenDensityEvent", mDensityList, 100);
-
- setDimension(Rect(0, 0, 550, 350));
-}
-
-Setup_Misc::~Setup_Misc()
-{
- delete2(mProxyTypeList);
- delete2(mShortcutsList);
- delete2(mDensityList);
-#ifdef USE_SDL2
- delete2(mSdlLogList);
-#endif // USE_SDL2
-}
-
-void Setup_Misc::apply()
-{
- SetupTabScroll::apply();
-
- logger->setDebugLog(config.getBoolValue("debugLog"));
- logger->setReportUnimplemented(config.getBoolValue("unimplimentedLog"));
- Net::loadIgnorePackets();
-}
-
-void Setup_Misc::externalUpdated()
-{
- reread("showJob");
- reread("enableGuildBot");
- reread("enableManaMarketBot");
- reread("enableBuggyServers");
- reread("afkMessage");
-}
diff --git a/src/gui/widgets/tabs/setup_misc.h b/src/gui/widgets/tabs/setup_misc.h
deleted file mode 100644
index 787f4c181..000000000
--- a/src/gui/widgets/tabs/setup_misc.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_MISC_H
-#define GUI_WIDGETS_TABS_SETUP_MISC_H
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-class NamesModel;
-
-class Setup_Misc final : public SetupTabScroll
-{
- public:
- explicit Setup_Misc(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Misc)
-
- ~Setup_Misc();
-
- void apply() override final;
-
- void externalUpdated() override final;
-
- protected:
- NamesModel *mProxyTypeList;
- NamesModel *mShortcutsList;
-#ifdef USE_SDL2
- NamesModel *mSdlLogList;
-#endif // USE_SDL2
- NamesModel *mDensityList;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_MISC_H
diff --git a/src/gui/widgets/tabs/setup_mods.cpp b/src/gui/widgets/tabs/setup_mods.cpp
deleted file mode 100644
index c3ca23245..000000000
--- a/src/gui/widgets/tabs/setup_mods.cpp
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_mods.h"
-
-#include "configuration.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/setupitem.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "resources/db/moddb.h"
-
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-Setup_Mods::Setup_Mods(const Widget2 *const widget) :
- SetupTabScroll(widget)
-{
- // TRANSLATORS: mods tab in settings
- setName(_("Mods"));
-
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
- place(0, 0, mScroll, 10, 10);
-
- setDimension(Rect(0, 0, 550, 350));
-}
-
-Setup_Mods::~Setup_Mods()
-{
-}
-
-void Setup_Mods::apply()
-{
- SetupTabScroll::apply();
- saveMods();
-}
-
-void Setup_Mods::externalUpdated()
-{
- clear();
- loadMods();
-}
-
-void Setup_Mods::loadMods()
-{
- std::string modsString = serverConfig.getValue("mods", "");
- std::set<std::string> modsList;
- splitToStringSet(modsList, modsString, '|');
-
- const ModInfos &mods = ModDB::getAll();
- if (mods.empty())
- {
- // TRANSLATORS: settings label
- new SetupItemLabel(_("No mods present"), "", this,
- Separator_false);
- return;
- }
-
- FOR_EACH (ModInfoCIterator, it, mods)
- {
- const ModInfo *const info = (*it).second;
- if (info == nullptr)
- continue;
-
- std::string name = info->getName();
- replaceAll(name, "|", "");
- SetupItem *const item = new SetupItemCheckBox(
- info->getDescription(), "", "", this, name);
- if (modsList.find(name) != modsList.end())
- item->setValue("1");
- else
- item->setValue("0");
- item->toWidget();
- }
-}
-
-void Setup_Mods::saveMods() const
-{
- const ModInfos &mods = ModDB::getAll();
- if (mods.empty())
- return;
-
- std::string modsString;
- const std::set<SetupItem*> &modsList = getAllItems();
- FOR_EACH (std::set<SetupItem*>::const_iterator, it, modsList)
- {
- const SetupItem *const item = *it;
- if (item == nullptr)
- continue;
- const std::string val = item->getValue();
- if (val == "1")
- {
- const std::string key = item->getEventName();
- if (!modsString.empty())
- modsString.append("|");
- modsString.append(key);
- }
- }
- serverConfig.setValue("mods", modsString);
-}
-
-void Setup_Mods::externalUnloaded()
-{
- clear();
-}
diff --git a/src/gui/widgets/tabs/setup_mods.h b/src/gui/widgets/tabs/setup_mods.h
deleted file mode 100644
index 488915d31..000000000
--- a/src/gui/widgets/tabs/setup_mods.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_MODS_H
-#define GUI_WIDGETS_TABS_SETUP_MODS_H
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-class Setup_Mods final : public SetupTabScroll
-{
- public:
- explicit Setup_Mods(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Mods)
-
- ~Setup_Mods();
-
- void apply() override final;
-
- void externalUpdated() override final;
-
- void externalUnloaded() override final;
-
- void loadMods();
-
- void saveMods() const;
-
- protected:
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_MODS_H
diff --git a/src/gui/widgets/tabs/setup_perfomance.cpp b/src/gui/widgets/tabs/setup_perfomance.cpp
deleted file mode 100644
index e12bd2872..000000000
--- a/src/gui/widgets/tabs/setup_perfomance.cpp
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_perfomance.h"
-
-#include "gui/models/namesmodel.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/setupitem.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-#ifdef USE_SDL2
-#include "configuration.h"
-#include "utils/sdlhelper.h"
-#endif // USE_SDL2
-
-#include "debug.h"
-
-static const int texturesListSize = 5;
-
-static const char *const texturesList[] =
-{
- // TRANSLATORS: texture compression type
- N_("No"),
- "s3tc",
- "fxt1",
- "ARB",
- "bptc"
-};
-
-Setup_Perfomance::Setup_Perfomance(const Widget2 *const widget) :
- SetupTabScroll(widget),
-#ifdef USE_SDL2
- mSdlDriversList(new NamesModel),
-#endif // USE_SDL2
- mTexturesList(new NamesModel)
-{
- // TRANSLATORS: settings tab name
- setName(_("Performance"));
-
- // Do the layout
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
- place(0, 0, mScroll, 10, 10);
-
-#ifdef USE_SDL2
- StringVect sdlDriversList;
- SDL::getRenderers(sdlDriversList,
- config.getStringValue("sdlDriver"));
- sdlDriversList.insert(sdlDriversList.begin(),
- // TRANSLATORS: sdl driver name
- N_("default"));
-#endif // USE_SDL2
-
- // TRANSLATORS: settings option
- new SetupItemLabel(_("Better performance (enable for better performance)"),
- "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Auto adjust performance"), "",
- "adjustPerfomance", this, "adjustPerfomanceEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Hw acceleration"), "",
- "hwaccel", this, "hwaccelEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable opacity cache (Software, can "
- "use much memory)"), "", "alphaCache", this, "alphaCacheEvent");
-
-#ifndef USE_SDL2
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable map reduce (Software)"), "",
- "enableMapReduce", this, "enableMapReduceEvent");
-#endif // USE_SDL2
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable compound sprite delay (Software)"), "",
- "enableCompoundSpriteDelay", this, "enableCompoundSpriteDelayEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable delayed images load (OpenGL)"), "",
- "enableDelayedAnimations", this, "enableDelayedAnimationsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable texture sampler (OpenGL)"), "",
- "useTextureSampler", this, "useTextureSamplerEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable OpenGL context creation"),
- "", "openglContext", this, "openglContextEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable OpenGL direct state access"),
- "", "enableDSA", this, "enableDSAEvent");
-
-
- // TRANSLATORS: settings option
- new SetupItemLabel(_("Better quality (disable for better performance)"),
- "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable alpha channel fix (Software, can "
- "be very slow)"), "Can slow down drawing", "enableAlphaFix",
- this, "enableAlphaFixEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show beings transparency"), "",
- "beingopacity", this, "beingopacityEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable reorder sprites (need for mods support)."),
- "", "enableReorderSprites", this, "enableReorderSpritesEvent");
-
-
-#ifndef USE_SDL2
- // TRANSLATORS: settings option
- new SetupItemLabel(_("Small memory (enable for lower memory usage)"),
- "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Disable advanced beings caching (Software)"), "",
- "disableAdvBeingCaching", this, "disableAdvBeingCachingEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Disable beings caching (Software)"), "",
- "disableBeingCaching", this, "disableBeingCachingEvent");
-#endif // USE_SDL2
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Different options (enable or disable can "
- "improve performance)"), "", this);
-
-#ifdef USE_SDL2
- mSdlDriversList->fillFromVector(sdlDriversList);
- new SetupItemDropDownStr(
- // TRANSLATORS: settings option
- _("Try first sdl driver (only for SDL2 default mode)"),
- "", "sdlDriver", this, "sdlDriverEvent", mSdlDriversList, 100);
-#endif // USE_SDL2
-
- mTexturesList->fillFromArray(&texturesList[0], texturesListSize);
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Enable texture compression (OpenGL)"), "",
- "compresstextures", this, "compresstexturesEvent", mTexturesList, 100);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable rectangular texture extension (OpenGL)"),
- "", "rectangulartextures", this, "rectangulartexturesEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Use new texture internal format (OpenGL)"),
- "", "newtextures", this, "newtexturesEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable texture atlases (OpenGL)"), "",
- "useAtlases", this, "useAtlasesEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Cache all sprites per map (can use "
- "additional memory)"), "", "uselonglivesprites", this,
- "uselonglivespritesEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Cache all sounds (can use additional memory)"),
- "", "uselonglivesounds", this,
- "uselonglivesoundsEvent");
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Critical options (DO NOT change if you don't "
- "know what you're doing)"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Disable logging in game (do not enable)"),
- "", "disableLoggingInGame", this, "disableLoggingInGameEvent");
-
- setDimension(Rect(0, 0, 550, 350));
-}
-
-Setup_Perfomance::~Setup_Perfomance()
-{
- delete2(mTexturesList);
-#ifdef USE_SDL2
- delete2(mSdlDriversList);
-#endif // USE_SDL2
-}
diff --git a/src/gui/widgets/tabs/setup_perfomance.h b/src/gui/widgets/tabs/setup_perfomance.h
deleted file mode 100644
index 95030a8e5..000000000
--- a/src/gui/widgets/tabs/setup_perfomance.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_PERFOMANCE_H
-#define GUI_WIDGETS_TABS_SETUP_PERFOMANCE_H
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-class NamesModel;
-
-class Setup_Perfomance final : public SetupTabScroll
-{
- public:
- explicit Setup_Perfomance(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Perfomance)
-
- ~Setup_Perfomance();
-
- private:
-#ifdef USE_SDL2
- NamesModel *mSdlDriversList;
-#endif // USE_SDL2
- NamesModel *mTexturesList;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_PERFOMANCE_H
diff --git a/src/gui/widgets/tabs/setup_players.cpp b/src/gui/widgets/tabs/setup_players.cpp
deleted file mode 100644
index 6d964799d..000000000
--- a/src/gui/widgets/tabs/setup_players.cpp
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_players.h"
-
-#include "configuration.h"
-#include "settings.h"
-
-#include "gui/models/namesmodel.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/setupitem.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-static const int badgesListSize = 4;
-
-static const char *const badgesList[] =
-{
- // TRANSLATORS: screen badges type
- N_("hide"),
- // TRANSLATORS: screen badges type
- N_("show at top"),
- // TRANSLATORS: screen badges type
- N_("show at right"),
- // TRANSLATORS: screen badges type
- N_("show at bottom"),
-};
-
-static const int visibleNamesListSize = 3;
-
-static const char *const visibleNamesList[] =
-{
- // TRANSLATORS: visible name type
- N_("hide"),
- // TRANSLATORS: visible name type
- N_("show"),
- // TRANSLATORS: visible name type
- N_("show on selection")
-};
-
-static const int topDownListSize = 2;
-
-static const char *const topDownList[] =
-{
- // TRANSLATORS: show on top or down
- N_("top"),
- // TRANSLATORS: show on top or down
- N_("bottom")
-};
-
-Setup_Players::Setup_Players(const Widget2 *const widget) :
- SetupTabScroll(widget),
- mBadgesList(new NamesModel),
- mVisibleNamesList(new NamesModel),
- mVisibleNamesPosList(new NamesModel)
-{
- // TRANSLATORS: settings tab name
- setName(_("Players"));
-
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
- place(0, 0, mScroll, 10, 10);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show gender"), "",
- "showgender", this, "showgenderEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show level"), "",
- "showlevel", this, "showlevelEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show own name"), "",
- "showownname", this, "showownnameEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable extended mouse targeting"), "",
- "extMouseTargeting", this, "extMouseTargetingEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Target dead players"), "",
- "targetDeadPlayers", this, "targetDeadPlayersEvent");
-
- mVisibleNamesList->fillFromArray(&visibleNamesList[0],
- visibleNamesListSize);
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Show player names"), "",
- "visiblenames", this, "visiblenamesEvent",
- mVisibleNamesList, 150);
-
- mVisibleNamesPosList->fillFromArray(&topDownList[0],
- topDownListSize);
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Show player names at"), "",
- "visiblenamespos", this, "visiblenamesposEvent",
- mVisibleNamesPosList, 150);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Auto move names"), "",
- "moveNames", this, "moveNamesEvent");
-
- mBadgesList->fillFromArray(&badgesList[0], badgesListSize);
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Badges"), "",
- "showBadges", this, "showBadgesEvent", mBadgesList, 150);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Secure trades"), "",
- "securetrades", this, "securetradesEvent");
-
- // TRANSLATORS: settings option
- new SetupItemTextField(_("Unsecure chars in names"), "",
- "unsecureChars", this, "unsecureCharsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show statuses"), "",
- "showPlayersStatus", this, "showPlayersStatusEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show ip addresses on screenshots"), "",
- "showip", this, "showipEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Allow self heal with mouse click"), "",
- "selfMouseHeal", this, "selfMouseHealEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Group friends in who is online window"), "",
- "groupFriends", this, "groupFriendsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Hide erased players nicks"), "",
- "hideErased", this, "hideErasedEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Collect players id and seen log"),
- "", "enableIdCollecting", this, "enableIdCollectingEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Use special diagonal speed in players moving"),
- "", "useDiagonalSpeed", this, "useDiagonalSpeedEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Log players actions (for GM)"),
- "", "logPlayerActions", this, "logPlayerActionsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Create screenshots for each complete trades"),
- "", "tradescreenshot", this, "tradescreenshotEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Emulate right mouse button by long mouse click"
- " (useful for touch interfaces)"),
- "", "longmouseclick", this, "longmouseclickEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable remote commands"),
- "", "enableRemoteCommands", this, "enableRemoteCommandsEvent",
- "1",
- MainConfig_false);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Allow move character by mouse"),
- "", "allowMoveByMouse", this, "allowMoveByMouseEvent");
-
- setDimension(Rect(0, 0, 550, 350));
-}
-
-Setup_Players::~Setup_Players()
-{
- delete2(mBadgesList);
- delete2(mVisibleNamesList);
- delete2(mVisibleNamesPosList);
-}
-
-void Setup_Players::externalUpdated()
-{
- reread("enableRemoteCommands");
-}
-
-void Setup_Players::apply()
-{
- SetupTabScroll::apply();
- settings.enableRemoteCommands = (serverConfig.getValue(
- "enableRemoteCommands", 1) != 0);
-}
diff --git a/src/gui/widgets/tabs/setup_players.h b/src/gui/widgets/tabs/setup_players.h
deleted file mode 100644
index d29d41781..000000000
--- a/src/gui/widgets/tabs/setup_players.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_PLAYERS_H
-#define GUI_WIDGETS_TABS_SETUP_PLAYERS_H
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-class NamesModel;
-
-class Setup_Players final : public SetupTabScroll
-{
- public:
- explicit Setup_Players(const Widget2 *const widget);
-
- ~Setup_Players();
-
- A_DELETE_COPY(Setup_Players)
-
- void apply() override final;
-
- void externalUpdated() override final;
-
- private:
- NamesModel *mBadgesList;
- NamesModel *mVisibleNamesList;
- NamesModel *mVisibleNamesPosList;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_PLAYERS_H
diff --git a/src/gui/widgets/tabs/setup_quick.cpp b/src/gui/widgets/tabs/setup_quick.cpp
deleted file mode 100644
index f86707fe1..000000000
--- a/src/gui/widgets/tabs/setup_quick.cpp
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_quick.h"
-
-#include "gamemodifiers.h"
-
-#include "gui/models/namesmodel.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/setupquickitem.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-Setup_Quick::Setup_Quick(const Widget2 *const widget) :
- SetupTabScroll(widget),
- mMoveTypeList(new NamesModel),
- mCrazyMoveTypeList(new NamesModel)
-{
- // TRANSLATORS: quick tab in settings
- setName(_("Quick"));
-
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
- place(0, 0, mScroll, 10, 10);
-
- new SetupQuickItem("", this, "moveTypeEvent",
- &GameModifiers::getMoveTypeString,
- &GameModifiers::changeMoveType);
-
- new SetupQuickItem("", this, "crazyMoveTypeEvent",
- &GameModifiers::getCrazyMoveTypeString,
- &GameModifiers::changeCrazyMoveType);
-
- new SetupQuickItem("", this, "moveToTargetTypeEvent",
- &GameModifiers::getMoveToTargetTypeString,
- &GameModifiers::changeMoveToTargetType);
-
- new SetupQuickItem("", this, "followModeEvent",
- &GameModifiers::getFollowModeString,
- &GameModifiers::changeFollowMode);
-
- new SetupQuickItem("", this, "attackWeaponTypeEvent",
- &GameModifiers::getAttackWeaponTypeString,
- &GameModifiers::changeAttackWeaponType);
-
- new SetupQuickItem("", this, "attackTypeEvent",
- &GameModifiers::getAttackTypeString,
- &GameModifiers::changeAttackType);
-
- new SetupQuickItem("", this, "magicAttackTypeEvent",
- &GameModifiers::getMagicAttackTypeString,
- &GameModifiers::changeMagicAttackType);
-
- new SetupQuickItem("", this, "pvpAttackTypeEvent",
- &GameModifiers::getPvpAttackTypeString,
- &GameModifiers::changePvpAttackType);
-
- new SetupQuickItem("", this, "quickDropCounterEvent",
- &GameModifiers::getQuickDropCounterString,
- &GameModifiers::changeQuickDropCounter);
-
- new SetupQuickItem("", this, "pickUpTypeEvent",
- &GameModifiers::getPickUpTypeString,
- &GameModifiers::changePickUpType);
-
- new SetupQuickItem("", this, "mapDrawTypeEvent",
- &GameModifiers::getMapDrawTypeString,
- &GameModifiers::changeMapDrawType);
-
- new SetupQuickItem("", this, "imitationModeEvent",
- &GameModifiers::getImitationModeString,
- &GameModifiers::changeImitationMode);
-
- new SetupQuickItem("", this, "CameraModeEvent",
- &GameModifiers::getCameraModeString,
- &GameModifiers::changeCameraMode);
-
- new SetupQuickItem("", this, "awayModeEvent",
- &GameModifiers::getAwayModeString,
- &GameModifiers::changeAwayMode);
-
- new SetupQuickItem("", this, "targetingTypeEvent",
- &GameModifiers::getTargetingTypeString,
- &GameModifiers::changeTargetingType);
-
- setDimension(Rect(0, 0, 550, 350));
-}
-
-Setup_Quick::~Setup_Quick()
-{
- delete2(mMoveTypeList);
- delete2(mCrazyMoveTypeList);
-}
diff --git a/src/gui/widgets/tabs/setup_quick.h b/src/gui/widgets/tabs/setup_quick.h
deleted file mode 100644
index f174153ee..000000000
--- a/src/gui/widgets/tabs/setup_quick.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_QUICK_H
-#define GUI_WIDGETS_TABS_SETUP_QUICK_H
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-class NamesModel;
-
-class Setup_Quick final : public SetupTabScroll
-{
- public:
- explicit Setup_Quick(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Quick)
-
- ~Setup_Quick();
-
- protected:
- NamesModel *mMoveTypeList;
-
- NamesModel *mCrazyMoveTypeList;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_QUICK_H
diff --git a/src/gui/widgets/tabs/setup_relations.cpp b/src/gui/widgets/tabs/setup_relations.cpp
deleted file mode 100644
index 4cc81a300..000000000
--- a/src/gui/widgets/tabs/setup_relations.cpp
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_relations.h"
-
-#include "actormanager.h"
-
-#include "being/localplayer.h"
-
-#include "gui/models/ignorechoiceslistmodel.h"
-#include "gui/models/playertablemodel.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/checkbox.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/dropdown.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/guitable.h"
-
-#include "utils/delete2.h"
-
-#include "debug.h"
-
-static const int COLUMNS_NR = 2; // name plus listbox
-static const int NAME_COLUMN = 0;
-static const unsigned int NAME_COLUMN_WIDTH = 230;
-static const unsigned int RELATION_CHOICE_COLUMN = 1;
-static const unsigned int RELATION_CHOICE_COLUMN_WIDTH = 80;
-
-static const std::string ACTION_DELETE("delete");
-static const std::string ACTION_TABLE("table");
-static const std::string ACTION_STRATEGY("strategy");
-
-static const char *const table_titles[COLUMNS_NR] =
-{
- // TRANSLATORS: relations table header
- N_("Name"),
- // TRANSLATORS: relations table header
- N_("Relation")
-};
-
-Setup_Relations::Setup_Relations(const Widget2 *const widget) :
- SetupTab(widget),
- PlayerRelationsListener(),
- mPlayerTableTitleModel(new StaticTableModel(1, COLUMNS_NR)),
- mPlayerTableModel(new PlayerTableModel(this)),
- mPlayerTable(new GuiTable(this, mPlayerTableModel)),
- mPlayerTitleTable(new GuiTable(this, mPlayerTableTitleModel)),
- mPlayerScrollArea(new ScrollArea(this, mPlayerTable)),
- // TRANSLATORS: relation dialog button
- mDefaultTrading(new CheckBox(this, _("Allow trading"),
- (playerRelations.getDefault() & PlayerRelation::TRADE) != 0u)),
- // TRANSLATORS: relation dialog button
- mDefaultWhisper(new CheckBox(this, _("Allow whispers"),
- (playerRelations.getDefault() & PlayerRelation::WHISPER) != 0u)),
- // TRANSLATORS: relation dialog button
- mDeleteButton(new Button(this, _("Delete"), ACTION_DELETE, this)),
- mIgnoreActionChoicesModel(new IgnoreChoicesListModel),
- mIgnoreActionChoicesBox(new DropDown(widget, mIgnoreActionChoicesModel))
-{
- // TRANSLATORS: relation dialog name
- setName(_("Relations"));
-
- mPlayerTable->setOpaque(Opaque_false);
-
- mPlayerTableTitleModel->fixColumnWidth(NAME_COLUMN, NAME_COLUMN_WIDTH);
- mPlayerTableTitleModel->fixColumnWidth(RELATION_CHOICE_COLUMN,
- RELATION_CHOICE_COLUMN_WIDTH);
- mPlayerTitleTable->setBackgroundColor(getThemeColor(
- ThemeColorId::TABLE_BACKGROUND));
- mPlayerTitleTable->setSelectableGui(false);
-
- for (int i = 0; i < COLUMNS_NR; i++)
- {
- mPlayerTableTitleModel->set(0, i, new Label(
- this, gettext(table_titles[i])));
- }
-
- mPlayerTitleTable->setLinewiseSelection(true);
-
- mPlayerScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- mPlayerTable->setActionEventId(ACTION_TABLE);
- mPlayerTable->setLinewiseSelection(true);
- mPlayerTable->addActionListener(this);
-
- // TRANSLATORS: relation dialog label
- Label *const ignore_action_label = new Label(this, _("When ignoring:"));
-
- mIgnoreActionChoicesBox->setActionEventId(ACTION_STRATEGY);
- mIgnoreActionChoicesBox->addActionListener(this);
-
- int ignore_strategy_index = 0; // safe default
-
- if (playerRelations.getPlayerIgnoreStrategy() != nullptr)
- {
- ignore_strategy_index = playerRelations.getPlayerIgnoreStrategyIndex(
- playerRelations.getPlayerIgnoreStrategy()->mShortName);
- if (ignore_strategy_index < 0)
- ignore_strategy_index = 0;
- }
- mIgnoreActionChoicesBox->setSelected(ignore_strategy_index);
- mIgnoreActionChoicesBox->adjustHeight();
-
- reset();
-
- // Do the layout
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
-
- place(0, 0, mPlayerTitleTable, 6);
- place(0, 1, mPlayerScrollArea, 6, 4).setPadding(2);
- place(0, 5, mDeleteButton);
- place(3, 5, ignore_action_label, 1);
- place(4, 5, mIgnoreActionChoicesBox, 2).setPadding(2);
- place(3, 6, mDefaultTrading, 3);
- place(3, 7, mDefaultWhisper, 3);
-
- playerRelations.addListener(this);
-
- setDimension(Rect(0, 0, 500, 350));
-}
-
-Setup_Relations::~Setup_Relations()
-{
- playerRelations.removeListener(this);
- delete2(mIgnoreActionChoicesModel);
-}
-
-
-void Setup_Relations::reset()
-{
- // We now have to search through the list of ignore choices to find the
- // current selection. We could use an index into the table of config
- // options in playerRelations instead of strategies to sidestep this.
- int selection = 0;
- for (size_t i = 0, sz = playerRelations.getPlayerIgnoreStrategies()
- ->size(); i < sz; ++ i)
- {
- if ((*playerRelations.getPlayerIgnoreStrategies())[i] ==
- playerRelations.getPlayerIgnoreStrategy())
- {
- selection = CAST_S32(i);
- break;
- }
- }
- mIgnoreActionChoicesBox->setSelected(selection);
-}
-
-void Setup_Relations::apply()
-{
- playerRelations.store();
-
- const unsigned int old_default_relations = playerRelations.getDefault() &
- ~(PlayerRelation::TRADE | PlayerRelation::WHISPER);
- playerRelations.setDefault(old_default_relations
- | (mDefaultTrading->isSelected() ? PlayerRelation::TRADE : 0)
- | (mDefaultWhisper->isSelected() ? PlayerRelation::WHISPER : 0));
-
- if (actorManager != nullptr)
- actorManager->updatePlayerNames();
-
- if (localPlayer != nullptr)
- localPlayer->setCheckNameSetting(true);
-}
-
-void Setup_Relations::cancel()
-{
-}
-
-void Setup_Relations::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == ACTION_TABLE)
- {
- // temporarily eliminate ourselves: we are fully aware of this change,
- // so there is no need for asynchronous updates. (In fact, thouse
- // might destroy the widet that triggered them, which would be rather
- // embarrassing.)
- playerRelations.removeListener(this);
-
- const int row = mPlayerTable->getSelectedRow();
- if (row >= 0)
- mPlayerTableModel->updateModelInRow(row);
-
- playerRelations.addListener(this);
- }
- else if (eventId == ACTION_DELETE)
- {
- const int player_index = mPlayerTable->getSelectedRow();
-
- if (player_index < 0)
- return;
-
- playerRelations.removePlayer(mPlayerTableModel->getPlayerAt(
- player_index));
- }
- else if (eventId == ACTION_STRATEGY)
- {
- const int sel = mIgnoreActionChoicesBox->getSelected();
- if (sel < 0)
- return;
- PlayerIgnoreStrategy *const s =
- (*playerRelations.getPlayerIgnoreStrategies())[sel];
-
- playerRelations.setPlayerIgnoreStrategy(s);
- }
-}
-
-void Setup_Relations::updatedPlayer(const std::string &name A_UNUSED)
-{
- mPlayerTableModel->playerRelationsUpdated();
- mDefaultTrading->setSelected(
- (playerRelations.getDefault() & PlayerRelation::TRADE) != 0u);
- mDefaultWhisper->setSelected(
- (playerRelations.getDefault() & PlayerRelation::WHISPER) != 0u);
- if (localPlayer != nullptr)
- localPlayer->updateName();
-}
-
-void Setup_Relations::updateAll()
-{
- PlayerTableModel *const model = new PlayerTableModel(this);
- mPlayerTable->setModel(model);
- delete mPlayerTableModel;
- mPlayerTableModel = model;
- int ignore_strategy_index = 0; // safe default
-
- if (playerRelations.getPlayerIgnoreStrategy() != nullptr)
- {
- ignore_strategy_index = playerRelations.getPlayerIgnoreStrategyIndex(
- playerRelations.getPlayerIgnoreStrategy()->mShortName);
- if (ignore_strategy_index < 0)
- ignore_strategy_index = 0;
- }
- mIgnoreActionChoicesBox->setSelected(ignore_strategy_index);
- mIgnoreActionChoicesBox->adjustHeight();
- reset();
-}
-void Setup_Relations::externalUpdated()
-{
- mDefaultTrading->setSelected(
- (playerRelations.getDefault() & PlayerRelation::TRADE) != 0u);
- mDefaultWhisper->setSelected(
- (playerRelations.getDefault() & PlayerRelation::WHISPER) != 0u);
-}
diff --git a/src/gui/widgets/tabs/setup_relations.h b/src/gui/widgets/tabs/setup_relations.h
deleted file mode 100644
index 879450891..000000000
--- a/src/gui/widgets/tabs/setup_relations.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_RELATIONS_H
-#define GUI_WIDGETS_TABS_SETUP_RELATIONS_H
-
-#include "gui/widgets/tabs/setuptab.h"
-
-#include "listeners/playerrelationslistener.h"
-
-class Button;
-class CheckBox;
-class DropDown;
-class GuiTable;
-class ListModel;
-class PlayerTableModel;
-class ScrollArea;
-class StaticTableModel;
-
-class Setup_Relations final : public SetupTab,
- public PlayerRelationsListener
-{
- public:
- explicit Setup_Relations(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Relations)
-
- ~Setup_Relations();
-
- void apply() override final;
-
- void cancel() override final A_CONST;
-
- void reset();
-
- void action(const ActionEvent &event) override final;
-
- void updatedPlayer(const std::string &name) override final;
-
- void updateAll() override final;
-
- void externalUpdated() override final;
-
- private:
- StaticTableModel *mPlayerTableTitleModel;
- PlayerTableModel *mPlayerTableModel;
- GuiTable *mPlayerTable;
- GuiTable *mPlayerTitleTable;
- ScrollArea *mPlayerScrollArea;
-
- CheckBox *mDefaultTrading;
- CheckBox *mDefaultWhisper;
-
- Button *mDeleteButton;
-
- ListModel *mIgnoreActionChoicesModel;
- DropDown *mIgnoreActionChoicesBox;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_RELATIONS_H
diff --git a/src/gui/widgets/tabs/setup_theme.cpp b/src/gui/widgets/tabs/setup_theme.cpp
deleted file mode 100644
index 47cbb2b92..000000000
--- a/src/gui/widgets/tabs/setup_theme.cpp
+++ /dev/null
@@ -1,415 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_theme.h"
-
-#include "gui/gui.h"
-#include "gui/themeinfo.h"
-
-#include "gui/windows/okdialog.h"
-
-#include "gui/models/fontsizechoicelistmodel.h"
-#include "gui/models/fontsmodel.h"
-#include "gui/models/langlistmodel.h"
-#include "gui/models/themesmodel.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/dropdown.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layouthelper.h"
-
-#include "configuration.h"
-
-#include "utils/delete2.h"
-
-#include "debug.h"
-
-const char* ACTION_THEME = "theme";
-const char* ACTION_FONT = "font";
-const char* ACTION_LANG = "lang";
-const char* ACTION_BOLD_FONT = "bold font";
-const char* ACTION_PARTICLE_FONT = "particle font";
-const char* ACTION_HELP_FONT = "help font";
-const char* ACTION_SECURE_FONT = "secure font";
-const char* ACTION_NPC_FONT = "npc font";
-const char* ACTION_JAPAN_FONT = "japanese font";
-const char* ACTION_CHINA_FONT = "chinese font";
-const char* ACTION_INFO = "info";
-
-Setup_Theme::Setup_Theme(const Widget2 *const widget) :
- SetupTab(widget),
- // TRANSLATORS: theme settings label
- mThemeLabel(new Label(this, _("Gui theme"))),
- mThemesModel(new ThemesModel),
- mThemeDropDown(new DropDown(this, mThemesModel)),
- mTheme(config.getStringValue("theme")),
- mInfo(Theme::loadInfo(mTheme)),
- mFontsModel(new FontsModel),
- // TRANSLATORS: theme settings label
- mFontLabel(new Label(this, _("Main Font"))),
- mFontDropDown(new DropDown(this, mFontsModel)),
- mFont(config.getStringValue("font")),
- mLangListModel(new LangListModel),
- // TRANSLATORS: theme settings label
- mLangLabel(new Label(this, _("Language"))),
- mLangDropDown(new DropDown(this, mLangListModel, true)),
- mLang(config.getStringValue("lang")),
- // TRANSLATORS: theme settings label
- mBoldFontLabel(new Label(this, _("Bold font"))),
- mBoldFontDropDown(new DropDown(this, mFontsModel)),
- mBoldFont(config.getStringValue("boldFont")),
- // TRANSLATORS: theme settings label
- mParticleFontLabel(new Label(this, _("Particle font"))),
- mParticleFontDropDown(new DropDown(this, mFontsModel)),
- mParticleFont(config.getStringValue("particleFont")),
- // TRANSLATORS: theme settings label
- mHelpFontLabel(new Label(this, _("Help font"))),
- mHelpFontDropDown(new DropDown(this, mFontsModel)),
- mHelpFont(config.getStringValue("helpFont")),
- // TRANSLATORS: theme settings label
- mSecureFontLabel(new Label(this, _("Secure font"))),
- mSecureFontDropDown(new DropDown(this, mFontsModel)),
- mSecureFont(config.getStringValue("secureFont")),
- // TRANSLATORS: theme settings label
- mNpcFontLabel(new Label(this, _("Npc font"))),
- mNpcFontDropDown(new DropDown(this, mFontsModel)),
- mNpcFont(config.getStringValue("npcFont")),
- // TRANSLATORS: theme settings label
- mJapanFontLabel(new Label(this, _("Japanese font"))),
- mJapanFontDropDown(new DropDown(this, mFontsModel)),
- mJapanFont(config.getStringValue("japanFont")),
- // TRANSLATORS: theme settings label
- mChinaFontLabel(new Label(this, _("Chinese font"))),
- mChinaFontDropDown(new DropDown(this, mFontsModel)),
- mChinaFont(config.getStringValue("chinaFont")),
- mFontSizeListModel(new FontSizeChoiceListModel),
- // TRANSLATORS: theme settings label
- mFontSizeLabel(new Label(this, _("Font size"))),
- mFontSize(config.getIntValue("fontSize")),
- mFontSizeDropDown(new DropDown(this, mFontSizeListModel)),
- mNpcFontSizeListModel(new FontSizeChoiceListModel),
- // TRANSLATORS: theme settings label
- mNpcFontSizeLabel(new Label(this, _("Npc font size"))),
- mNpcFontSize(config.getIntValue("npcfontSize")),
- mNpcFontSizeDropDown(new DropDown(this, mNpcFontSizeListModel)),
- // TRANSLATORS: button name with information about selected theme
- mInfoButton(new Button(this, _("i"), ACTION_INFO, this)),
- mThemeInfo()
-{
- // TRANSLATORS: theme settings tab name
- setName(_("Theme"));
-
- mThemeDropDown->setActionEventId(ACTION_THEME);
- mThemeDropDown->addActionListener(this);
- mFontDropDown->setActionEventId(ACTION_FONT);
- mFontDropDown->addActionListener(this);
- mLangDropDown->setActionEventId(ACTION_LANG);
- mLangDropDown->addActionListener(this);
- mBoldFontDropDown->setActionEventId(ACTION_BOLD_FONT);
- mBoldFontDropDown->addActionListener(this);
- mParticleFontDropDown->setActionEventId(ACTION_PARTICLE_FONT);
- mParticleFontDropDown->addActionListener(this);
- mHelpFontDropDown->setActionEventId(ACTION_HELP_FONT);
- mHelpFontDropDown->addActionListener(this);
- mSecureFontDropDown->setActionEventId(ACTION_SECURE_FONT);
- mSecureFontDropDown->addActionListener(this);
- mNpcFontDropDown->setActionEventId(ACTION_NPC_FONT);
- mNpcFontDropDown->addActionListener(this);
- mJapanFontDropDown->setActionEventId(ACTION_JAPAN_FONT);
- mJapanFontDropDown->addActionListener(this);
- mChinaFontDropDown->setActionEventId(ACTION_CHINA_FONT);
- mChinaFontDropDown->addActionListener(this);
- mFontSizeDropDown->setSelected(mFontSize - 9);
- mFontSizeDropDown->adjustHeight();
- mNpcFontSizeDropDown->setSelected(mNpcFontSize - 9);
- mNpcFontSizeDropDown->adjustHeight();
-
- const std::string skin = Theme::getThemeName();
- if (!skin.empty())
- mThemeDropDown->setSelectedString(skin);
- else
- mThemeDropDown->setSelected(0);
-
- const std::string str = config.getStringValue("lang");
- for (int f = 0; f < langs_count; f ++)
- {
- if (LANG_NAME[f].value == str)
- {
- mLangDropDown->setSelected(f);
- break;
- }
- }
-
- mFontDropDown->setSelectedString(getFileName(
- config.getStringValue("font")));
- mBoldFontDropDown->setSelectedString(getFileName(
- config.getStringValue("boldFont")));
- mParticleFontDropDown->setSelectedString(getFileName(
- config.getStringValue("particleFont")));
- mHelpFontDropDown->setSelectedString(getFileName(
- config.getStringValue("helpFont")));
- mSecureFontDropDown->setSelectedString(getFileName(
- config.getStringValue("secureFont")));
- mNpcFontDropDown->setSelectedString(getFileName(
- config.getStringValue("npcFont")));
- mJapanFontDropDown->setSelectedString(getFileName(
- config.getStringValue("japanFont")));
- mChinaFontDropDown->setSelectedString(getFileName(
- config.getStringValue("chinaFont")));
-
- updateInfo();
-
- // Do the layout
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
-
- place(0, 0, mThemeLabel, 5);
- place(0, 1, mLangLabel, 5);
- place(0, 2, mFontSizeLabel, 5);
- place(0, 3, mNpcFontSizeLabel, 5);
- place(0, 4, mFontLabel, 5);
- place(0, 5, mBoldFontLabel, 5);
- place(0, 6, mParticleFontLabel, 5);
- place(0, 7, mHelpFontLabel, 5);
- place(0, 8, mSecureFontLabel, 5);
- place(0, 9, mNpcFontLabel, 5);
- place(0, 10, mJapanFontLabel, 5);
- place(0, 11, mChinaFontLabel, 5);
-
- place(6, 0, mThemeDropDown, 10);
- place(6, 1, mLangDropDown, 10);
- place(6, 2, mFontSizeDropDown, 10);
- place(6, 3, mNpcFontSizeDropDown, 10);
- place(6, 4, mFontDropDown, 10);
- place(6, 5, mBoldFontDropDown, 10);
- place(6, 6, mParticleFontDropDown, 10);
- place(6, 7, mHelpFontDropDown, 10);
- place(6, 8, mSecureFontDropDown, 10);
- place(6, 9, mNpcFontDropDown, 10);
- place(6, 10, mJapanFontDropDown, 10);
- place(6, 11, mChinaFontDropDown, 10);
-
- place(17, 0, mInfoButton, 1);
-
- int size = mainGraphics->mWidth - 10;
- const int maxWidth = mFontSize * 30 + 290;
- if (size < 465)
- size = 465;
- else if (size > maxWidth)
- size = maxWidth;
-
- setDimension(Rect(0, 0, size, 500));
-}
-
-Setup_Theme::~Setup_Theme()
-{
- delete2(mInfo);
- delete2(mThemesModel);
- delete2(mFontsModel);
- delete2(mFontSizeListModel);
- delete2(mNpcFontSizeListModel);
- delete2(mLangListModel);
- delete2(mInfo);
-}
-
-void Setup_Theme::updateInfo()
-{
- delete mInfo;
- mInfo = Theme::loadInfo(mTheme);
- if (mInfo != nullptr)
- {
- // TRANSLATORS: theme name
- mThemeInfo = std::string(_("Name: ")).append(mInfo->name)
- // TRANSLATORS: theme copyright
- .append("\n").append(_("Copyright:")).append("\n")
- .append(mInfo->copyright);
- }
- else
- {
- mThemeInfo.clear();
- }
- replaceAll(mThemeInfo, "\\n", "\n");
- mInfoButton->setEnabled(!mThemeInfo.empty());
-}
-
-void Setup_Theme::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == ACTION_THEME)
- {
- if (mThemeDropDown->getSelected() == 0)
- mTheme.clear();
- else
- mTheme = mThemeDropDown->getSelectedString();
- updateInfo();
- }
- else if (eventId == ACTION_FONT)
- {
- mFont = mFontDropDown->getSelectedString();
- }
- else if (eventId == ACTION_LANG)
- {
- const int id = mLangDropDown->getSelected();
- if (id < 0 || id >= langs_count)
- mLang.clear();
- else
- mLang = LANG_NAME[id].value;
- }
- else if (eventId == ACTION_BOLD_FONT)
- {
- mBoldFont = mBoldFontDropDown->getSelectedString();
- }
- else if (eventId == ACTION_PARTICLE_FONT)
- {
- mParticleFont = mParticleFontDropDown->getSelectedString();
- }
- else if (eventId == ACTION_HELP_FONT)
- {
- mHelpFont = mHelpFontDropDown->getSelectedString();
- }
- else if (eventId == ACTION_SECURE_FONT)
- {
- mSecureFont = mSecureFontDropDown->getSelectedString();
- }
- else if (eventId == ACTION_NPC_FONT)
- {
- mNpcFont = mNpcFontDropDown->getSelectedString();
- }
- else if (eventId == ACTION_JAPAN_FONT)
- {
- mJapanFont = mJapanFontDropDown->getSelectedString();
- }
- else if (eventId == ACTION_CHINA_FONT)
- {
- mChinaFont = mChinaFontDropDown->getSelectedString();
- }
- else if (eventId == ACTION_INFO)
- {
- CREATEWIDGET(OkDialog,
- // TRANSLATORS: theme info dialog header
- _("Theme info"),
- mThemeInfo,
- // TRANSLATORS: ok dialog button
- _("OK"),
- DialogType::OK,
- Modal_true,
- ShowCenter_true,
- nullptr,
- 600);
- }
-}
-
-void Setup_Theme::cancel()
-{
- mTheme = config.getStringValue("theme");
- mLang = config.getStringValue("lang");
- mFont = getFileName(config.getStringValue("font"));
- mBoldFont = getFileName(config.getStringValue("boldFont"));
- mParticleFont = getFileName(config.getStringValue("particleFont"));
- mHelpFont = getFileName(config.getStringValue("helpFont"));
- mSecureFont = getFileName(config.getStringValue("secureFont"));
- mNpcFont = getFileName(config.getStringValue("npcFont"));
- mJapanFont = getFileName(config.getStringValue("japanFont"));
- mChinaFont = getFileName(config.getStringValue("chinaFont"));
-}
-
-#define updateField(name1, name2) if (!mInfo->name1.empty()) \
- name2 = mInfo->name1;
-
-void Setup_Theme::apply()
-{
- if (config.getStringValue("theme") != mTheme)
- {
- CREATEWIDGET(OkDialog,
- // TRANSLATORS: theme message dialog
- _("Theme Changed"),
- // TRANSLATORS: ok dialog message
- _("Restart your client for the change to take effect."),
- // TRANSLATORS: ok dialog button
- _("OK"),
- DialogType::OK,
- Modal_true,
- ShowCenter_true,
- nullptr,
- 260);
- }
-
- config.setValue("selectedSkin", "");
- if (config.getStringValue("theme") != mTheme && (mInfo != nullptr))
- {
- updateField(font, mFont);
- updateField(boldFont, mBoldFont);
- updateField(particleFont, mParticleFont);
- updateField(helpFont, mHelpFont);
- updateField(secureFont, mSecureFont);
- updateField(npcFont, mNpcFont);
- updateField(japanFont, mJapanFont);
- updateField(chinaFont, mChinaFont);
- if (mInfo->fontSize != 0)
- {
- const int size = mInfo->fontSize - 9;
- if (size >= 0)
- mFontSizeDropDown->setSelected(size);
- }
- if (mInfo->npcfontSize != 0)
- {
- const int size = mInfo->npcfontSize - 9;
- if (size >= 0)
- mNpcFontSizeDropDown->setSelected(size);
- }
- if (mInfo->guiAlpha > 0.01F)
- config.setValue("guialpha", mInfo->guiAlpha);
- }
- config.setValue("theme", mTheme);
- config.setValue("lang", mLang);
- if (config.getValue("font", "dejavusans.ttf") != mFont
- || config.getValue("boldFont", "dejavusans-bold.ttf") != mBoldFont
- || config.getValue("particleFont", "dejavusans.ttf") != mParticleFont
- || config.getValue("helpFont", "dejavusansmono.ttf") != mHelpFont
- || config.getValue("secureFont", "dejavusansmono.ttf") != mSecureFont
- || config.getValue("npcFont", "dejavusans.ttf") != mNpcFont
- || config.getValue("japanFont", "mplus-1p-regular.ttf") != mJapanFont
- || config.getValue("chinaFont", "fonts/wqy-microhei.ttf")
- != mChinaFont
- || config.getIntValue("fontSize")
- != CAST_S32(mFontSizeDropDown->getSelected()) + 9
- || config.getIntValue("npcfontSize")
- != CAST_S32(mNpcFontSizeDropDown->getSelected()) + 9)
- {
- config.setValue("font", "fonts/" + getFileName(mFont));
- config.setValue("boldFont", "fonts/" + getFileName(mBoldFont));
- config.setValue("particleFont", "fonts/" + getFileName(mParticleFont));
- config.setValue("helpFont", "fonts/" + getFileName(mHelpFont));
- config.setValue("secureFont", "fonts/" + getFileName(mSecureFont));
- config.setValue("npcFont", "fonts/" + getFileName(mNpcFont));
- config.setValue("japanFont", "fonts/" + getFileName(mJapanFont));
- config.setValue("chinaFont", "fonts/" + getFileName(mChinaFont));
- config.setValue("fontSize", mFontSizeDropDown->getSelected() + 9);
- config.setValue("npcfontSize",
- mNpcFontSizeDropDown->getSelected() + 9);
- gui->updateFonts();
- }
-}
-
-#undef updateField
diff --git a/src/gui/widgets/tabs/setup_theme.h b/src/gui/widgets/tabs/setup_theme.h
deleted file mode 100644
index 57798f243..000000000
--- a/src/gui/widgets/tabs/setup_theme.h
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_THEME_H
-#define GUI_WIDGETS_TABS_SETUP_THEME_H
-
-#include "gui/widgets/tabs/setuptab.h"
-
-class Button;
-class DropDown;
-class FontsModel;
-class FontSizeChoiceListModel;
-class Label;
-class LangListModel;
-class ThemesModel;
-
-class Setup_Theme final : public SetupTab
-{
- public:
- explicit Setup_Theme(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Theme)
-
- ~Setup_Theme();
-
- void apply() override final;
-
- void cancel() override final;
-
- void action(const ActionEvent &event) override final;
-
- void updateInfo();
-
- private:
- Label *mThemeLabel;
- ThemesModel *mThemesModel A_NONNULLPOINTER;
- DropDown *mThemeDropDown;
- std::string mTheme;
- ThemeInfo *mInfo;
-
- FontsModel *mFontsModel A_NONNULLPOINTER;
- Label *mFontLabel A_NONNULLPOINTER;
- DropDown *mFontDropDown A_NONNULLPOINTER;
- std::string mFont;
-
- LangListModel *mLangListModel A_NONNULLPOINTER;
-
- Label *mLangLabel A_NONNULLPOINTER;
- DropDown *mLangDropDown A_NONNULLPOINTER;
- std::string mLang;
-
- Label *mBoldFontLabel A_NONNULLPOINTER;
- DropDown *mBoldFontDropDown A_NONNULLPOINTER;
- std::string mBoldFont;
-
- Label *mParticleFontLabel A_NONNULLPOINTER;
- DropDown *mParticleFontDropDown A_NONNULLPOINTER;
- std::string mParticleFont;
-
- Label *mHelpFontLabel A_NONNULLPOINTER;
- DropDown *mHelpFontDropDown A_NONNULLPOINTER;
- std::string mHelpFont;
-
- Label *mSecureFontLabel A_NONNULLPOINTER;
- DropDown *mSecureFontDropDown A_NONNULLPOINTER;
- std::string mSecureFont;
-
- Label *mNpcFontLabel A_NONNULLPOINTER;
- DropDown *mNpcFontDropDown A_NONNULLPOINTER;
- std::string mNpcFont;
-
- Label *mJapanFontLabel A_NONNULLPOINTER;
- DropDown *mJapanFontDropDown A_NONNULLPOINTER;
- std::string mJapanFont;
-
- Label *mChinaFontLabel A_NONNULLPOINTER;
- DropDown *mChinaFontDropDown A_NONNULLPOINTER;
- std::string mChinaFont;
-
- FontSizeChoiceListModel *mFontSizeListModel A_NONNULLPOINTER;
- Label *mFontSizeLabel;
- int mFontSize;
- DropDown *mFontSizeDropDown;
-
- FontSizeChoiceListModel *mNpcFontSizeListModel A_NONNULLPOINTER;
- Label *mNpcFontSizeLabel;
- int mNpcFontSize;
- DropDown *mNpcFontSizeDropDown A_NONNULLPOINTER;
-
- Button *mInfoButton A_NONNULLPOINTER;
- std::string mThemeInfo;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_THEME_H
diff --git a/src/gui/widgets/tabs/setup_touch.cpp b/src/gui/widgets/tabs/setup_touch.cpp
deleted file mode 100644
index c8558fef9..000000000
--- a/src/gui/widgets/tabs/setup_touch.cpp
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_touch.h"
-
-#include "gui/models/touchactionmodel.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/setuptouchitem.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include "debug.h"
-
-static const int sizeListSize = 4;
-
-static const char *const sizeList[] =
-{
- // TRANSLATORS: onscreen button size
- N_("Small"),
- // TRANSLATORS: onscreen button size
- N_("Normal"),
- // TRANSLATORS: onscreen button size
- N_("Medium"),
- // TRANSLATORS: onscreen button size
- N_("Large")
-};
-
-static const int formatListSize = 6;
-
-static const char *const formatList[] =
-{
- "2x1",
- "2x2",
- "3x3",
- "4x2",
- "4x3",
- "3x2"
-};
-
-Setup_Touch::Setup_Touch(const Widget2 *const widget) :
- SetupTabScroll(widget),
- mSizeList(new NamesModel),
- mFormatList(new NamesModel),
- mActionsList(new TouchActionsModel)
-{
- // TRANSLATORS: touch settings tab
- setName(_("Touch"));
-
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
- place(0, 0, mScroll, 10, 10);
- mSizeList->fillFromArray(&sizeList[0], sizeListSize);
- mFormatList->fillFromArray(&formatList[0], formatListSize);
-
- // TRANSLATORS: settings option
- new SetupItemLabel(_("Onscreen keyboard"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show onscreen keyboard icon"), "",
- "showScreenKeyboard", this, "showScreenKeyboardEvent");
-
- // TRANSLATORS: settings option
- new SetupActionDropDown(_("Keyboard icon action"), "",
- "screenActionKeyboard", this, "screenActionKeyboardEvent",
- mActionsList, 250);
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Onscreen joystick"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show onscreen joystick"), "",
- "showScreenJoystick", this, "showScreenJoystickEvent");
-
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Joystick size"), "", "screenJoystickSize", this,
- "screenJoystickEvent", mSizeList, 100);
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Onscreen buttons"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show onscreen buttons"), "",
- "showScreenButtons", this, "showScreenButtonsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Buttons format"), "", "screenButtonsFormat", this,
- "screenButtonsFormatEvent", mFormatList, 100);
-
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Buttons size"), "", "screenButtonsSize", this,
- "screenButtonsSizeEvent", mSizeList, 100);
-
- for (unsigned int f = 0; f < 12; f ++)
- {
- std::string key = strprintf("screenActionButton%u", f);
- std::string event = strprintf("screenActionButton%uEvent", f);
- // TRANSLATORS: settings option
- new SetupActionDropDown(strprintf(_("Button %u action"), f + 1), "",
- key, this, event, mActionsList, 250);
- }
-
- setDimension(Rect(0, 0, 550, 350));
-}
-
-Setup_Touch::~Setup_Touch()
-{
- delete2(mSizeList);
- delete2(mFormatList);
- delete2(mActionsList);
-}
diff --git a/src/gui/widgets/tabs/setup_touch.h b/src/gui/widgets/tabs/setup_touch.h
deleted file mode 100644
index a87a46c77..000000000
--- a/src/gui/widgets/tabs/setup_touch.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_TOUCH_H
-#define GUI_WIDGETS_TABS_SETUP_TOUCH_H
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-class NamesModel;
-class TouchActionsModel;
-
-class Setup_Touch final : public SetupTabScroll
-{
- public:
- explicit Setup_Touch(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Touch)
-
- ~Setup_Touch();
-
- protected:
- NamesModel *mSizeList;
- NamesModel *mFormatList;
- TouchActionsModel *mActionsList;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_TOUCH_H
diff --git a/src/gui/widgets/tabs/setup_video.cpp b/src/gui/widgets/tabs/setup_video.cpp
deleted file mode 100644
index b5b74e2b9..000000000
--- a/src/gui/widgets/tabs/setup_video.cpp
+++ /dev/null
@@ -1,534 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_video.h"
-
-#include "gui/windowmanager.h"
-
-#include "gui/windows/okdialog.h"
-#include "gui/windows/textdialog.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/checkbox.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/listbox.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/slider.h"
-#include "gui/widgets/dropdown.h"
-
-#include "utils/delete2.h"
-
-#if defined(USE_OPENGL) && !defined(ANDROID) && !defined(__APPLE__)
-#include "graphicsmanager.h"
-
-#include "test/testmain.h"
-#endif // defined(USE_OPENGL) && !defined(ANDROID) && !defined(__APPLE__)
-
-#if defined(ANDROID) || defined(__APPLE__) || !defined(USE_OPENGL)
-#include "configuration.h"
-#endif // defined(ANDROID) || defined(__APPLE__) || !defined(USE_OPENGL)
-
-#if defined(ANDROID) || defined(__APPLE__)
-#include "utils/stringutils.h"
-#endif // defined(ANDROID) || defined(__APPLE__)
-
-#include "gui/models/modelistmodel.h"
-#include "gui/models/opengllistmodel.h"
-
-#include <sstream>
-
-#include "debug.h"
-
-Setup_Video::Setup_Video(const Widget2 *const widget) :
- SetupTab(widget),
- KeyListener(),
- mFullScreenEnabled(config.getBoolValue("screen")),
- mOpenGLEnabled(intToRenderType(config.getIntValue("opengl"))),
- mFps(config.getIntValue("fpslimit")),
- mAltFps(config.getIntValue("altfpslimit")),
- mModeListModel(new ModeListModel),
- mOpenGLListModel(new OpenGLListModel),
- mModeList(CREATEWIDGETR(ListBox, widget, mModeListModel, "")),
- // TRANSLATORS: video settings checkbox
- mFsCheckBox(new CheckBox(this, _("Full screen"), mFullScreenEnabled)),
- mOpenGLDropDown(new DropDown(widget, mOpenGLListModel)),
- // TRANSLATORS: video settings checkbox
- mFpsCheckBox(new CheckBox(this, _("FPS limit:"))),
- mFpsSlider(new Slider(this, 2.0, 160.0, 1.0)),
- mFpsLabel(new Label(this)),
- mAltFpsSlider(new Slider(this, 2.0, 160.0, 1.0)),
- // TRANSLATORS: video settings label
- mAltFpsLabel(new Label(this, _("Alt FPS limit: "))),
-#if !defined(ANDROID) && !defined(__APPLE__) && !defined(__native_client__)
- // TRANSLATORS: video settings button
- mDetectButton(new Button(this, _("Detect best mode"), "detect", this)),
-#endif // !defined(ANDROID) && !defined(__APPLE__) &&
- // !defined(__native_client__)
- mDialog(nullptr),
- mCustomCursorEnabled(config.getBoolValue("customcursor")),
- mEnableResize(config.getBoolValue("enableresize")),
- mNoFrame(config.getBoolValue("noframe")),
-#ifdef USE_SDL2
- mAllowHighDPI(config.getBoolValue("allowHighDPI")),
- // TRANSLATORS: video settings checkbox
- mAllowHighDPICheckBox(new CheckBox(this, _("High DPI"), mAllowHighDPI)),
-#endif // USE_SDL2
- mCustomCursorCheckBox(new CheckBox(this,
-#ifdef ANDROID
- // TRANSLATORS: video settings checkbox
- _("Show cursor"),
-#else // ANDROID
- // TRANSLATORS: video settings checkbox
- _("Custom cursor"),
-#endif // ANDROID
- mCustomCursorEnabled)),
- // TRANSLATORS: video settings checkbox
- mEnableResizeCheckBox(new CheckBox(this, _("Enable resize"),
- mEnableResize)),
- // TRANSLATORS: video settings checkbox
- mNoFrameCheckBox(new CheckBox(this, _("No frame"), mNoFrame))
-{
- // TRANSLATORS: video settings tab name
- setName(_("Video"));
-
- ScrollArea *const scrollArea = new ScrollArea(this, mModeList,
- Opaque_true, "setup_video_background.xml");
- scrollArea->setWidth(150);
- scrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
-
- mOpenGLDropDown->setSelected(renderToIndex[mOpenGLEnabled]);
-
- mModeList->setEnabled(true);
-
- // TRANSLATORS: video settings label
- mFpsLabel->setCaption(mFps > 0 ? toString(mFps) : _("None"));
- mFpsLabel->setWidth(60);
- // TRANSLATORS: video settings label
- mAltFpsLabel->setCaption(_("Alt FPS limit: ") + (mAltFps > 0 ?
- // TRANSLATORS: video settings label value
- toString(mAltFps) : _("None")));
- mAltFpsLabel->setWidth(150);
- mFpsSlider->setEnabled(mFps > 0);
- mFpsSlider->setValue(mFps);
- mAltFpsSlider->setEnabled(mAltFps > 0);
- mAltFpsSlider->setValue(mAltFps);
- mFpsCheckBox->setSelected(mFps > 0);
-
- // Pre-select the current video mode.
- const std::string videoMode = toString(
- mainGraphics->mActualWidth).append("x").append(
- toString(mainGraphics->mActualHeight));
- mModeList->setSelected(mModeListModel->getIndexOf(videoMode));
-
- mModeList->setActionEventId("videomode");
- mCustomCursorCheckBox->setActionEventId("customcursor");
- mFpsCheckBox->setActionEventId("fpslimitcheckbox");
- mFpsSlider->setActionEventId("fpslimitslider");
- mAltFpsSlider->setActionEventId("altfpslimitslider");
- mOpenGLDropDown->setActionEventId("opengl");
- mEnableResizeCheckBox->setActionEventId("enableresize");
- mNoFrameCheckBox->setActionEventId("noframe");
-#ifdef USE_SDL2
- mAllowHighDPICheckBox->setActionEventId("allowHighDPI");
- mAllowHighDPICheckBox->addActionListener(this);
-#endif // USE_SDL2
-
- mModeList->addActionListener(this);
- mCustomCursorCheckBox->addActionListener(this);
- mFpsCheckBox->addActionListener(this);
- mFpsSlider->addActionListener(this);
- mAltFpsSlider->addActionListener(this);
- mOpenGLDropDown->addActionListener(this);
- mEnableResizeCheckBox->addActionListener(this);
- mNoFrameCheckBox->addActionListener(this);
-
- // Do the layout
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
-
- place(0, 0, scrollArea, 1, 5).setPadding(2);
- place(0, 5, mOpenGLDropDown, 1);
-
- place(1, 0, mFsCheckBox, 2);
-
- place(1, 1, mCustomCursorCheckBox, 3);
-
- place(1, 2, mEnableResizeCheckBox, 2);
- place(1, 3, mNoFrameCheckBox, 2);
-#ifdef USE_SDL2
- place(1, 4, mAllowHighDPICheckBox, 2);
-#endif // USE_SDL2
-
- place(0, 6, mFpsSlider);
- place(1, 6, mFpsCheckBox).setPadding(3);
- place(2, 6, mFpsLabel).setPadding(1);
-
- place(0, 7, mAltFpsSlider);
- place(1, 7, mAltFpsLabel).setPadding(3);
-
-#if !defined(ANDROID) && !defined(__APPLE__) && !defined(__native_client__)
- place(0, 8, mDetectButton);
-#else // !defined(ANDROID) && !defined(__APPLE__) &&
- // !defined(__native_client__)
- mNoFrameCheckBox->setEnabled(false);
- mEnableResizeCheckBox->setEnabled(false);
-#ifndef __native_client__
- mFsCheckBox->setEnabled(false);
-#endif // __native_client__
-#endif // !defined(ANDROID) && !defined(__APPLE__) &&
- // !defined(__native_client__)
-
- int width = 600;
-
- if (config.getIntValue("screenwidth") >= 730)
- width += 100;
-
- setDimension(Rect(0, 0, width, 300));
-}
-
-Setup_Video::~Setup_Video()
-{
- delete2(mModeListModel);
- delete2(mModeList);
- delete2(mOpenGLListModel);
- delete2(mDialog);
-}
-
-void Setup_Video::apply()
-{
- // Full screen changes
- bool fullscreen = mFsCheckBox->isSelected();
- if (fullscreen != config.getBoolValue("screen"))
- {
- /* The OpenGL test is only necessary on Windows, since switching
- * to/from full screen works fine on Linux. On Windows we'd have to
- * reinitialize the OpenGL state and reload all textures.
- *
- * See http://libsdl.org/cgi/docwiki.cgi/SDL_SetVideoMode
- */
-
-#if defined(WIN32) || defined(__APPLE__) || defined(ANDROID)
- // checks for opengl usage
- if (intToRenderType(config.getIntValue("opengl")) == RENDER_SOFTWARE)
- {
-#endif // defined(WIN32) || defined(__APPLE__) || defined(ANDROID)
- if (!WindowManager::setFullScreen(fullscreen))
- {
- fullscreen = !fullscreen;
- if (!WindowManager::setFullScreen(fullscreen))
- {
- std::stringstream errorMsg;
- if (fullscreen)
- {
- // TRANSLATORS: video error message
- errorMsg << _("Failed to switch to windowed mode "
- "and restoration of old mode also "
- "failed!") << std::endl;
- }
- else
- {
- // TRANSLATORS: video error message
- errorMsg << _("Failed to switch to fullscreen mode"
- " and restoration of old mode also "
- "failed!") << std::endl;
- }
- logger->safeError(errorMsg.str());
- }
- }
-#if defined(WIN32) || defined(__APPLE__) || defined(ANDROID)
- }
- else
- {
- CREATEWIDGET(OkDialog,
- // TRANSLATORS: video settings warning
- _("Switching to Full Screen"),
- // TRANSLATORS: video settings warning
- _("Restart needed for changes to take effect."),
- // TRANSLATORS: ok dialog button
- _("OK"),
- DialogType::OK,
- Modal_true,
- ShowCenter_true,
- nullptr,
- 260);
- }
-#endif // defined(WIN32) || defined(__APPLE__) || defined(ANDROID)
-
- config.setValue("screen", fullscreen);
- }
-
- const int sel = mOpenGLDropDown->getSelected();
- RenderType mode = RENDER_SOFTWARE;
- if (sel >= 0 && CAST_U32(sel) < sizeof(indexToRender))
- mode = indexToRender[mOpenGLDropDown->getSelected()];
-
- // OpenGL change
- if (mode != mOpenGLEnabled)
- {
- config.setValue("opengl", CAST_S32(mode));
-
- // OpenGL can currently only be changed by restarting, notify user.
- CREATEWIDGET(OkDialog,
- // TRANSLATORS: video settings warning
- _("Changing to OpenGL"),
- // TRANSLATORS: video settings warning
- _("Applying change to OpenGL requires restart."),
- // TRANSLATORS: ok dialog button
- _("OK"),
- DialogType::OK,
- Modal_true,
- ShowCenter_true,
- nullptr,
- 260);
- }
-
- mFps = mFpsCheckBox->isSelected() ?
- CAST_S32(mFpsSlider->getValue()) : 0;
-
- mAltFps = CAST_S32(mAltFpsSlider->getValue());
-
- mFpsSlider->setEnabled(mFps > 0);
-
- mAltFpsSlider->setEnabled(mAltFps > 0);
-
- // FPS change
- config.setValue("fpslimit", mFps);
- config.setValue("altfpslimit", mAltFps);
-
- // We sync old and new values at apply time
- mFullScreenEnabled = config.getBoolValue("screen");
- mCustomCursorEnabled = config.getBoolValue("customcursor");
-
- mOpenGLEnabled = intToRenderType(config.getIntValue("opengl"));
- mEnableResize = config.getBoolValue("enableresize");
- mNoFrame = config.getBoolValue("noframe");
-#ifdef USE_SDL2
- mAllowHighDPI = config.getBoolValue("allowHighDPI");
-#endif // USE_SDL2
-}
-
-void Setup_Video::cancel()
-{
- mFpsCheckBox->setSelected(mFps > 0);
- mFsCheckBox->setSelected(mFullScreenEnabled);
- mOpenGLDropDown->setSelected(renderToIndex[mOpenGLEnabled]);
- mCustomCursorCheckBox->setSelected(mCustomCursorEnabled);
- mFpsSlider->setEnabled(mFps > 0);
- mFpsSlider->setValue(mFps);
- mAltFpsSlider->setEnabled(mAltFps > 0);
- mAltFpsSlider->setValue(mAltFps);
- mFpsLabel->setCaption(mFpsCheckBox->isSelected()
- // TRANSLATORS: video settings label
- ? toString(mFps) : _("None"));
- // TRANSLATORS: video settings label
- mAltFpsLabel->setCaption(_("Alt FPS limit: ") + toString(mAltFps));
- mEnableResizeCheckBox->setSelected(mEnableResize);
- mNoFrameCheckBox->setSelected(mNoFrame);
-#ifdef USE_SDL2
- mAllowHighDPICheckBox->setSelected(mAllowHighDPI);
-#endif // USE_SDL2
-
- config.setValue("screen", mFullScreenEnabled);
-
- // Set back to the current video mode.
- std::string videoMode = toString(mainGraphics->mActualWidth).append("x")
- .append(toString(mainGraphics->mActualHeight));
- mModeList->setSelected(mModeListModel->getIndexOf(videoMode));
- config.setValue("screenwidth", mainGraphics->mActualWidth);
- config.setValue("screenheight", mainGraphics->mActualHeight);
-
- config.setValue("customcursor", mCustomCursorEnabled);
- config.setValue("opengl", CAST_S32(mOpenGLEnabled));
- config.setValue("enableresize", mEnableResize);
-#ifdef USE_SDL2
- config.setValue("allowHighDPI", mAllowHighDPI);
-#endif // USE_SDL2
-}
-
-void Setup_Video::action(const ActionEvent &event)
-{
- const std::string &id = event.getId();
-
- if (id == "videomode")
- {
- std::string mode = mModeListModel->getElementAt(
- mModeList->getSelected());
-
- if (mode == "custom")
- {
- if (mDialog != nullptr)
- {
- mode = mDialog->getText();
- mDialog = nullptr;
- }
- else
- {
- CREATEWIDGETV(mDialog, TextDialog,
- // TRANSLATORS: resolution question dialog
- _("Custom resolution (example: 1024x768)"),
- // TRANSLATORS: resolution question dialog
- _("Enter new resolution: "));
- mDialog->setActionEventId("videomode");
- mDialog->addActionListener(this);
- return;
- }
- }
- const int width = atoi(mode.substr(0, mode.find('x')).c_str());
- const int height = atoi(mode.substr(mode.find('x') + 1).c_str());
- if ((width == 0) || (height == 0))
- return;
-
- if (width != mainGraphics->mActualWidth
- || height != mainGraphics->mActualHeight)
- {
-#if defined(WIN32) || defined(__APPLE__) || defined(ANDROID)
- if (intToRenderType(config.getIntValue("opengl"))
- == RENDER_SOFTWARE)
- {
- WindowManager::doResizeVideo(width, height, false);
- }
- else
- {
- if (width < mainGraphics->mActualWidth
- || height < mainGraphics->mActualHeight)
- {
- CREATEWIDGET(OkDialog,
- // TRANSLATORS: video settings warning
- _("Screen Resolution Changed"),
- // TRANSLATORS: video settings warning
- _("Restart your client for the change to take effect.")
- // TRANSLATORS: video settings warning
- + std::string("\n") + _("Some windows may be moved to "
- "fit the lowered resolution."),
- // TRANSLATORS: ok dialog button
- _("OK"),
- DialogType::OK,
- Modal_true,
- ShowCenter_true,
- nullptr,
- 260);
- }
- else
- {
- CREATEWIDGET(OkDialog,
- // TRANSLATORS: video settings warning
- _("Screen Resolution Changed"),
- // TRANSLATORS: video settings warning
- _("Restart your client for the change"
- " to take effect."),
- // TRANSLATORS: ok dialog button
- _("OK"),
- DialogType::OK,
- Modal_true,
- ShowCenter_true,
- nullptr,
- 260);
- }
- }
-#else // defined(WIN32) || defined(__APPLE__) || defined(ANDROID)
-
- mainGraphics->setWindowSize(width, height);
- WindowManager::doResizeVideo(width, height, false);
-#endif // defined(WIN32) || defined(__APPLE__) || defined(ANDROID)
- }
-
- config.setValue("oldscreen", config.getBoolValue("screen"));
- config.setValue("oldscreenwidth", mainGraphics->mActualWidth);
- config.setValue("oldscreenheight", mainGraphics->mActualHeight);
- config.setValue("screenwidth", width);
- config.setValue("screenheight", height);
- }
- if (id == "~videomode")
- {
- mDialog = nullptr;
- }
- else if (id == "customcursor")
- {
- config.setValue("customcursor", mCustomCursorCheckBox->isSelected());
- }
- else if (id == "fpslimitcheckbox" || id == "fpslimitslider")
- {
- int tempFps = CAST_S32(mFpsSlider->getValue());
- if (id == "fpslimitcheckbox" && !mFpsSlider->isEnabled())
- tempFps = 60;
- else
- tempFps = tempFps > 0 ? tempFps : 60;
- mFps = mFpsCheckBox->isSelected() ? tempFps : 0;
- // TRANSLATORS: video settings label
- const std::string text = mFps > 0 ? toString(mFps) : _("None");
-
- mFpsLabel->setCaption(text);
- mFpsSlider->setEnabled(mFps > 0);
- mFpsSlider->setValue(mFps);
- }
- else if (id == "altfpslimitslider")
- {
- int tempFps = CAST_S32(mAltFpsSlider->getValue());
- tempFps = tempFps > 0 ? tempFps : CAST_S32(
- mAltFpsSlider->getScaleStart());
- mAltFps = tempFps;
- // TRANSLATORS: video settings label
- const std::string text = mAltFps > 0 ? toString(mAltFps) : _("None");
-
- // TRANSLATORS: video settings label
- mAltFpsLabel->setCaption(_("Alt FPS limit: ") + text);
- mAltFpsSlider->setEnabled(mAltFps > 0);
- mAltFpsSlider->setValue(mAltFps);
- }
- else if (id == "enableresize")
- {
- config.setValue("enableresize", mEnableResizeCheckBox->isSelected());
- }
- else if (id == "noframe")
- {
- config.setValue("noframe", mNoFrameCheckBox->isSelected());
- }
-#ifdef USE_SDL2
- else if (id == "allowHighDPI")
- {
- config.setValue("allowHighDPI", mAllowHighDPICheckBox->isSelected());
- }
-#endif // USE_SDL2
-#if defined(USE_OPENGL) && !defined(ANDROID) && !defined(__APPLE__)
- else if (id == "detect")
- {
- TestMain *test = graphicsManager.startDetection();
- if (test != nullptr)
- {
- Configuration &conf = test->getConfig();
- const int val = conf.getValueInt("opengl", -1);
- if (val >= 0 && CAST_U32(val)
- < sizeof(renderToIndex) / sizeof(int))
- {
- mOpenGLDropDown->setSelected(renderToIndex[val]);
- }
- config.setValue("textureSize",
- conf.getValue("textureSize", "1024,1024,1024,1024,1024,1024"));
- config.setValue("testInfo", conf.getValue("testInfo", ""));
- delete test;
- }
- }
-#endif // defined(USE_OPENGL) && !defined(ANDROID) && !defined(__APPLE__)
-}
diff --git a/src/gui/widgets/tabs/setup_video.h b/src/gui/widgets/tabs/setup_video.h
deleted file mode 100644
index e327a29d8..000000000
--- a/src/gui/widgets/tabs/setup_video.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_VIDEO_H
-#define GUI_WIDGETS_TABS_SETUP_VIDEO_H
-
-#include "gui/widgets/tabs/setuptab.h"
-
-#include "listeners/keylistener.h"
-
-class Button;
-class CheckBox;
-class DropDown;
-class Label;
-class ListBox;
-class ModeListModel;
-class OpenGLListModel;
-class Slider;
-class TextDialog;
-
-class Setup_Video final : public SetupTab,
- public KeyListener
-{
- public:
- explicit Setup_Video(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Video)
-
- ~Setup_Video();
-
- void apply() override final;
-
- void cancel() override final;
-
- void action(const ActionEvent &event) override final;
-
- private:
- bool mFullScreenEnabled;
- RenderType mOpenGLEnabled;
- int mFps;
- int mAltFps;
- ModeListModel *mModeListModel;
- OpenGLListModel *mOpenGLListModel;
- ListBox *mModeList;
- CheckBox *mFsCheckBox;
- DropDown *mOpenGLDropDown;
- CheckBox *mFpsCheckBox;
- Slider *mFpsSlider;
- Label *mFpsLabel;
- Slider *mAltFpsSlider;
- Label *mAltFpsLabel;
-#if !defined(ANDROID) && !defined(__APPLE__) && !defined(__native_client__)
- Button *mDetectButton;
-#endif // !defined(ANDROID) && !defined(__APPLE__) &&
- // !defined(__native_client__)
- TextDialog *mDialog;
- bool mCustomCursorEnabled;
- bool mEnableResize;
- bool mNoFrame;
-#ifdef USE_SDL2
- bool mAllowHighDPI;
- CheckBox *mAllowHighDPICheckBox;
-#endif // USE_SDL2
- CheckBox *mCustomCursorCheckBox;
- CheckBox *mEnableResizeCheckBox;
- CheckBox *mNoFrameCheckBox;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_VIDEO_H
diff --git a/src/gui/widgets/tabs/setup_visual.cpp b/src/gui/widgets/tabs/setup_visual.cpp
deleted file mode 100644
index de5cc8b3b..000000000
--- a/src/gui/widgets/tabs/setup_visual.cpp
+++ /dev/null
@@ -1,252 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_visual.h"
-
-#include "gui/windowmanager.h"
-
-#include "gui/models/namesmodel.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include "debug.h"
-
-static const int speachListSize = 4;
-
-static const char *const speachList[] =
-{
- // TRANSLATORS: speach type
- N_("No text"),
- // TRANSLATORS: speach type
- N_("Text"),
- // TRANSLATORS: speach type
- N_("Bubbles, no names"),
- // TRANSLATORS: speach type
- N_("Bubbles with names")
-};
-
-static const int ambientFxListSize = 3;
-
-static const char *const ambientFxList[] =
-{
- // TRANSLATORS: ambient effect type
- N_("off"),
- // TRANSLATORS: ambient effect type
- N_("low"),
- // TRANSLATORS: ambient effect type
- N_("high")
-};
-
-static const int particleTypeListSize = 3;
-
-static const char *const particleTypeList[] =
-{
- // TRANSLATORS: patricle effects type
- N_("best quality"),
- // TRANSLATORS: patricle effects type
- N_("normal"),
- // TRANSLATORS: patricle effects type
- N_("best performance")
-};
-
-static const int vSyncListSize = 3;
-
-static const char *const vSyncList[] =
-{
- // TRANSLATORS: vsync type
- N_("default"),
- // TRANSLATORS: vsync type
- N_("off"),
- // TRANSLATORS: vsync type
- N_("on")
-};
-
-Setup_Visual::Setup_Visual(const Widget2 *const widget) :
- SetupTabScroll(widget),
- mSpeachList(new NamesModel),
- mAmbientFxList(new NamesModel),
- mParticleList(new SetupItemNames),
- mParticleTypeList(new NamesModel),
- mVSyncList(new NamesModel),
- mScaleList(new NamesModel)
-{
- // TRANSLATORS: settings tab name
- setName(_("Visual"));
- // Do the layout
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
- place(0, 0, mScroll, 10, 10);
-
- mPreferredFirstItemSize = 150;
-
- // TRANSLATORS: settings option
- new SetupItemLabel(_("Scale"), "", this);
-
- for (int f = 1; f <= 7; f ++)
- {
- // TRANSLATORS: particle details
- mScaleList->add(toString(f) + "x");
- }
- // TRANSLATORS: settings option
- new SetupItemSliderInt(_("Scale"), "",
- "scale", this, "scaleEvent", mScaleList, 1);
-
- // TRANSLATORS: settings option
- new SetupItemLabel(_("Notifications"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show pickup notifications in chat"), "",
- "showpickupchat", this, "showpickupchatEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show pickup notifications as particle effects"),
- "", "showpickupparticle", this, "showpickupparticleEvent");
-
- // TRANSLATORS: settings option
- new SetupItemLabel(_("Effects"), "", this);
-
-#ifndef ANDROID
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Grab mouse and keyboard input"),
- "", "grabinput", this, "grabinputEvent");
-#endif // ANDROID
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Blurring textures (OpenGL)"),
- "", "blur", this, "blurEvent");
-
- // TRANSLATORS: settings option
- new SetupItemSlider(_("Gui opacity"), "", "guialpha",
- this, "guialphaEvent", 0.1, 1.01, 0.1, 150,
- OnTheFly_true,
- MainConfig_true);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable gui opacity"),
- "", "enableGuiOpacity", this, "enableGuiOpacityEvent");
-
- mSpeachList->fillFromArray(&speachList[0], speachListSize);
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Overhead text"), "", "speech", this,
- "speechEvent", mSpeachList, 200);
-
- mAmbientFxList->fillFromArray(&ambientFxList[0], ambientFxListSize);
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Ambient FX"), "", "OverlayDetail", this,
- "OverlayDetailEvent", mAmbientFxList, 100);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show particle effects"), "",
- "particleeffects", this, "particleeffectsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show particle effects from maps"), "",
- "mapparticleeffects", this, "mapparticleeffectsEvent");
-
- // TRANSLATORS: particle details
- mParticleList->push_back(_("low"));
- // TRANSLATORS: particle details
- mParticleList->push_back(_("medium"));
- // TRANSLATORS: particle details
- mParticleList->push_back(_("high"));
- // TRANSLATORS: particle details
- mParticleList->push_back(_("max"));
- // TRANSLATORS: settings option
- (new SetupItemSlider2(_("Particle detail"), "", "particleEmitterSkip",
- this, "particleEmitterSkipEvent", 0, 3, 1, mParticleList,
- OnTheFly_true,
- MainConfig_true,
- DoNotAlign_false))->setInvertValue(3);
-
- mParticleTypeList->fillFromArray(&particleTypeList[0],
- particleTypeListSize);
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Particle physics"), "", "particleFastPhysics",
- this, "particleFastPhysicsEvent", mParticleTypeList, 200);
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Gamma"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable gamma control"),
- "", "enableGamma", this, "enableGammaEvent");
-
- // TRANSLATORS: settings option
- new SetupItemSlider(_("Gamma"), "", "gamma",
- this, "gammeEvent", 1, 20, 1, 350,
- OnTheFly_true,
- MainConfig_true);
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Other"), "", this);
-
- mVSyncList->fillFromArray(&vSyncList[0], vSyncListSize);
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Vsync"), "", "vsync", this,
- "vsyncEvent", mVSyncList, 100);
-
-#if defined(WIN32) || defined(__APPLE__)
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Center game window"),
- "", "centerwindow", this, "centerwindowEvent");
-#endif // defined(WIN32) || defined(__APPLE__)
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Allow screensaver to run"),
- "", "allowscreensaver", this, "allowscreensaverEvent");
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Screenshots"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Add water mark into screenshots"),
- "", "addwatermark", this, "addwatermarkEvent");
-
- setDimension(Rect(0, 0, 550, 350));
-}
-
-Setup_Visual::~Setup_Visual()
-{
- delete2(mSpeachList);
- delete2(mAmbientFxList);
- delete2(mParticleList);
- delete2(mParticleTypeList);
- delete2(mVSyncList);
- delete2(mScaleList);
-}
-
-void Setup_Visual::apply()
-{
- SetupTabScroll::apply();
- WindowManager::applyGrabMode();
-#ifndef WIN32
- WindowManager::applyScale();
-#endif // WIN32
-}
diff --git a/src/gui/widgets/tabs/setup_visual.h b/src/gui/widgets/tabs/setup_visual.h
deleted file mode 100644
index 08d1c7848..000000000
--- a/src/gui/widgets/tabs/setup_visual.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_VISUAL_H
-#define GUI_WIDGETS_TABS_SETUP_VISUAL_H
-
-#include "gui/widgets/setupitem.h"
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-class NamesModel;
-
-class Setup_Visual final : public SetupTabScroll
-{
- public:
- explicit Setup_Visual(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Visual)
-
- ~Setup_Visual();
-
- void apply() override final;
-
- private:
- NamesModel *mSpeachList;
- NamesModel *mAmbientFxList;
- SetupItemNames *mParticleList;
- NamesModel *mParticleTypeList;
- NamesModel *mVSyncList;
- NamesModel *mScaleList;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_VISUAL_H
diff --git a/src/gui/widgets/tabs/setuptab.cpp b/src/gui/widgets/tabs/setuptab.cpp
deleted file mode 100644
index d5f43b4b8..000000000
--- a/src/gui/widgets/tabs/setuptab.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setuptab.h"
-
-#include "debug.h"
-
-SetupTab::SetupTab(const Widget2 *const widget) :
- Container(widget),
- ActionListener(),
- WidgetListener(),
- mName()
-{
- setOpaque(Opaque_false);
- addWidgetListener(this);
- setSelectable(false);
-}
-
-void SetupTab::externalUpdated()
-{
-}
-
-void SetupTab::externalUnloaded()
-{
-}
diff --git a/src/gui/widgets/tabs/setuptab.h b/src/gui/widgets/tabs/setuptab.h
deleted file mode 100644
index 6b1082088..000000000
--- a/src/gui/widgets/tabs/setuptab.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUPTAB_H
-#define GUI_WIDGETS_TABS_SETUPTAB_H
-
-#include "gui/widgets/container.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "localconsts.h"
-
-/**
- * A container for the contents of a tab in the setup window.
- */
-class SetupTab notfinal : public Container,
- public ActionListener,
- public WidgetListener
-{
- public:
- A_DELETE_COPY(SetupTab)
-
- const std::string &getName() const noexcept2 A_WARN_UNUSED
- { return mName; }
-
- /**
- * Called when the Apply button is pressed in the setup window.
- */
- virtual void apply() = 0;
-
- /**
- * Called when the Cancel button is pressed in the setup window.
- */
- virtual void cancel() = 0;
-
- virtual void externalUpdated() A_CONST;
-
- virtual void externalUnloaded() A_CONST;
-
- protected:
- explicit SetupTab(const Widget2 *const widget);
-
- /**
- * Sets the name displayed on the tab. Should be set in the
- * constructor of a subclass.
- */
- void setName(const std::string &name) noexcept2
- { mName = name; }
-
- private:
- std::string mName;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUPTAB_H
diff --git a/src/gui/widgets/tabs/setuptabscroll.cpp b/src/gui/widgets/tabs/setuptabscroll.cpp
deleted file mode 100644
index 0cb623687..000000000
--- a/src/gui/widgets/tabs/setuptabscroll.cpp
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/setupitem.h"
-#include "gui/widgets/vertcontainer.h"
-
-#include "utils/delete2.h"
-
-#include "debug.h"
-
-SetupTabScroll::SetupTabScroll(const Widget2 *const widget) :
- SetupTab(widget),
- mContainer(new VertContainer(this, 25, false, 8)),
- mScroll(new ScrollArea(this, mContainer, Opaque_false)),
- mItems(),
- mAllItems(),
- mPreferredFirstItemSize(200)
-{
- mScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- mScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO);
- mScroll->setSelectable(false);
- mContainer->setSelectable(false);
-}
-
-SetupTabScroll::~SetupTabScroll()
-{
- mScroll = nullptr;
- delete2(mContainer);
- removeItems();
-}
-
-void SetupTabScroll::removeItems()
-{
- std::set<SetupItem*>::iterator it = mAllItems.begin();
- const std::set<SetupItem*>::iterator it_end = mAllItems.end();
- while (it != it_end)
- {
- delete *it;
- ++ it;
- }
- mAllItems.clear();
-
- mItems.clear();
-}
-
-void SetupTabScroll::clear()
-{
- removeItems();
- mContainer->removeControls();
- mContainer->clear();
-}
-
-void SetupTabScroll::addControl(SetupItem *const widget)
-{
- if (widget == nullptr)
- return;
- const std::string actionId = widget->getActionEventId();
- if (!actionId.empty())
- {
- const std::map<std::string, SetupItem*>::iterator iter
- = mItems.find(actionId);
- if (iter != mItems.end())
- {
- delete (*iter).second;
- mItems.erase(iter);
- }
- mItems[actionId] = widget;
- }
- mAllItems.insert(widget);
-}
-
-void SetupTabScroll::addControl(SetupItem *const widget,
- const std::string &event)
-{
- const std::map<std::string, SetupItem*>::iterator iter
- = mItems.find(event);
- if (iter != mItems.end())
- {
- delete (*iter).second;
- mItems.erase(iter);
- }
- mItems[event] = widget;
- mAllItems.insert(widget);
-}
-
-void SetupTabScroll::apply()
-{
- for (std::map<std::string, SetupItem*>::const_iterator
- iter = mItems.begin(), iter_end = mItems.end();
- iter != iter_end; ++ iter)
- {
- if ((*iter).second != nullptr)
- (*iter).second->apply((*iter).first);
- }
-}
-
-void SetupTabScroll::cancel()
-{
- for (std::map<std::string, SetupItem*>::const_iterator
- iter = mItems.begin(), iter_end = mItems.end();
- iter != iter_end; ++ iter)
- {
- if ((*iter).second != nullptr)
- (*iter).second->cancel((*iter).first);
- }
-}
-
-void SetupTabScroll::externalUpdated()
-{
- for (std::map<std::string, SetupItem*>::const_iterator
- iter = mItems.begin(), iter_end = mItems.end();
- iter != iter_end; ++ iter)
- {
- SetupItem *const widget = (*iter).second;
- if ((widget != nullptr) && widget->isMainConfig() == MainConfig_false)
- widget->externalUpdated((*iter).first);
- }
-}
-
-void SetupTabScroll::externalUnloaded()
-{
- for (std::map<std::string, SetupItem*>::const_iterator
- iter = mItems.begin(), iter_end = mItems.end();
- iter != iter_end; ++ iter)
- {
- SetupItem *const widget = (*iter).second;
- if ((widget != nullptr) && widget->isMainConfig() == MainConfig_false)
- widget->externalUnloaded((*iter).first);
- }
-}
-
-void SetupTabScroll::widgetResized(const Event &event A_UNUSED)
-{
- mScroll->setWidth(getWidth() - 12);
- mScroll->setHeight(getHeight() - 12 - 12);
-}
-
-void SetupTabScroll::reread(const std::string &name)
-{
- SetupItem *const item = mItems[name + "Event"];
- if (item != nullptr)
- item->rereadValue();
-}
diff --git a/src/gui/widgets/tabs/setuptabscroll.h b/src/gui/widgets/tabs/setuptabscroll.h
deleted file mode 100644
index 655b98c85..000000000
--- a/src/gui/widgets/tabs/setuptabscroll.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUPTABSCROLL_H
-#define GUI_WIDGETS_TABS_SETUPTABSCROLL_H
-
-#include "gui/widgets/tabs/setuptab.h"
-
-#include "localconsts.h"
-
-class SetupItem;
-class ScrollArea;
-class VertContainer;
-
-class SetupTabScroll notfinal : public SetupTab
-{
- public:
- explicit SetupTabScroll(const Widget2 *const widget);
-
- A_DELETE_COPY(SetupTabScroll)
-
- virtual ~SetupTabScroll();
-
- void addControl(SetupItem *const widget);
-
- void addControl(SetupItem *const widget, const std::string &event);
-
- VertContainer *getContainer() const noexcept2 A_WARN_UNUSED
- { return mContainer; }
-
- void apply() override;
-
- void cancel() override final;
-
- void externalUpdated() override;
-
- void externalUnloaded() override;
-
- void action(const ActionEvent &event A_UNUSED) override final
- { }
-
- int getPreferredFirstItemSize() const noexcept2 A_WARN_UNUSED
- { return mPreferredFirstItemSize; }
-
- void widgetResized(const Event &event) override final;
-
- void reread(const std::string &name);
-
- void clear() override final;
-
- const std::set<SetupItem*> &getAllItems() const noexcept2
- { return mAllItems; }
-
- protected:
- void removeItems();
-
- VertContainer *mContainer;
- ScrollArea *mScroll;
- std::map<std::string, SetupItem*> mItems;
- std::set<SetupItem*> mAllItems;
- int mPreferredFirstItemSize;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUPTABSCROLL_H
diff --git a/src/gui/widgets/tabs/shortcuttab.h b/src/gui/widgets/tabs/shortcuttab.h
deleted file mode 100644
index 61652777f..000000000
--- a/src/gui/widgets/tabs/shortcuttab.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SHORTCUTTAB_H
-#define GUI_WIDGETS_TABS_SHORTCUTTAB_H
-
-#include "gui/widgets/tabs/tab.h"
-
-#include "localconsts.h"
-
-class ShortcutContainer;
-
-class ShortcutTab final : public Tab
-{
- public:
- ShortcutTab(const Widget2 *const widget,
- const std::string &name,
- ShortcutContainer *const content) :
- Tab(widget),
- mContent(content)
- {
- setCaption(name);
- }
-
- A_DELETE_COPY(ShortcutTab)
-
- ShortcutContainer* mContent;
-};
-
-#endif // GUI_WIDGETS_TABS_SHORTCUTTAB_H
diff --git a/src/gui/widgets/tabs/skilltab.h b/src/gui/widgets/tabs/skilltab.h
deleted file mode 100644
index 9086a4d0c..000000000
--- a/src/gui/widgets/tabs/skilltab.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SKILLTAB_H
-#define GUI_WIDGETS_TABS_SKILLTAB_H
-
-#include "gui/windows/skilldialog.h"
-
-#include "gui/widgets/skilllistbox.h"
-#include "gui/widgets/skillrectanglelistbox.h"
-
-#include "gui/widgets/tabs/tab.h"
-
-#include "localconsts.h"
-
-class SkillTab final : public Tab
-{
- public:
- SkillTab(const Widget2 *const widget,
- const std::string &name,
- SkillListBox *const listBox) :
- Tab(widget),
- mListBox(listBox),
- mRectangleListBox(nullptr)
- {
- setCaption(name);
- }
-
- SkillTab(const Widget2 *const widget,
- const std::string &name,
- SkillRectangleListBox *const listBox) :
- Tab(widget),
- mListBox(nullptr),
- mRectangleListBox(listBox)
- {
- setCaption(name);
- }
-
- A_DELETE_COPY(SkillTab)
-
- ~SkillTab()
- {
- delete2(mListBox)
- delete2(mRectangleListBox)
- }
-
- SkillInfo *getSelectedInfo() const
- {
- if (mListBox != nullptr)
- return mListBox->getSelectedInfo();
- else if (mRectangleListBox != nullptr)
- return mRectangleListBox->getSelectedInfo();
- else
- return nullptr;
- }
-
- protected:
- void setCurrent() override
- {
- if (skillDialog != nullptr)
- skillDialog->updateTabSelection();
- }
-
- private:
- SkillListBox *mListBox;
- SkillRectangleListBox *mRectangleListBox;
-};
-
-#endif // GUI_WIDGETS_TABS_SKILLTAB_H
diff --git a/src/gui/widgets/tabs/socialattacktab.h b/src/gui/widgets/tabs/socialattacktab.h
deleted file mode 100644
index e876a60ae..000000000
--- a/src/gui/widgets/tabs/socialattacktab.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SOCIALATTACKTAB_H
-#define GUI_WIDGETS_TABS_SOCIALATTACKTAB_H
-
-#include "gui/widgets/tabs/socialtab.h"
-
-#include "being/localplayer.h"
-
-#include "gui/models/beingslistmodel.h"
-
-#include "gui/widgets/tabs/socialtabbase.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include "localconsts.h"
-
-class SocialAttackTab final : public SocialTab
-{
- public:
- SocialAttackTab(const Widget2 *const widget,
- const Opaque showBackground) :
- SocialTab(widget),
- mBeings(new BeingsListModel)
- {
- createControls(mBeings, showBackground);
-
- // TRANSLATORS: Attack filter tab name in social window.
- // TRANSLATORS: Should be small
- setCaption(_("Atk"));
- mMenuAction = "attack";
- }
-
- A_DELETE_COPY(SocialAttackTab)
-
- ~SocialAttackTab()
- {
- delete2(mList)
- delete2(mScroll)
- delete2(mBeings)
- }
-
- void updateList() override final
- {
- updateAtkListStart();
- // TRANSLATORS: mobs group name in social window
- addAvatars(PriorityAttackMob, _("Priority mobs"), PRIORITY);
- // TRANSLATORS: mobs group name in social window
- addAvatars(AttackMob, _("Attack mobs"), ATTACK);
- // TRANSLATORS: mobs group name in social window
- addAvatars(IgnoreAttackMob, _("Ignore mobs"), IGNORE_);
- }
-
- private:
- BeingsListModel *mBeings;
-};
-
-#endif // GUI_WIDGETS_TABS_SOCIALATTACKTAB_H
diff --git a/src/gui/widgets/tabs/socialfriendsfunctor.h b/src/gui/widgets/tabs/socialfriendsfunctor.h
deleted file mode 100644
index e68647a77..000000000
--- a/src/gui/widgets/tabs/socialfriendsfunctor.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SOCIALFRIENDSFUNCTOR_H
-#define GUI_WIDGETS_TABS_SOCIALFRIENDSFUNCTOR_H
-
-#include "avatar.h"
-
-#include "utils/stringutils.h"
-
-#include "localconsts.h"
-
-class SortFriendsFunctor final
-{
- public:
- A_DEFAULT_COPY(SortFriendsFunctor)
-
- bool operator() (const Avatar *const m1,
- const Avatar *const m2) const
- {
- if ((m1 == nullptr) || (m2 == nullptr))
- return false;
-
- if (m1->getOnline() != m2->getOnline())
- {
- return static_cast<int>(m1->getOnline()) >
- static_cast<int>(m2->getOnline());
- }
-
- if (m1->getName() != m2->getName())
- {
- std::string s1 = m1->getName();
- std::string s2 = m2->getName();
- toLower(s1);
- toLower(s2);
- return s1 < s2;
- }
- return false;
- }
-};
-
-#endif // GUI_WIDGETS_TABS_SOCIALFRIENDSFUNCTOR_H
diff --git a/src/gui/widgets/tabs/socialfriendstab.h b/src/gui/widgets/tabs/socialfriendstab.h
deleted file mode 100644
index d1cd942cd..000000000
--- a/src/gui/widgets/tabs/socialfriendstab.h
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SOCIALFRIENDSTAB_H
-#define GUI_WIDGETS_TABS_SOCIALFRIENDSTAB_H
-
-#include "gui/widgets/tabs/socialtab.h"
-
-#include "actormanager.h"
-
-#include "being/playerrelations.h"
-
-#include "gui/models/beingslistmodel.h"
-
-#include "gui/windows/whoisonline.h"
-
-#include "gui/widgets/tabs/socialfriendsfunctor.h"
-
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-
-#include "localconsts.h"
-
-class SocialFriendsTab final : public SocialTab
-{
- public:
- SocialFriendsTab(const Widget2 *const widget,
- const std::string &name,
- const Opaque showBackground) :
- SocialTab(widget),
- mBeings(new BeingsListModel),
- mFriendSorter()
- {
- createControls(mBeings, showBackground);
-
- getPlayersAvatars();
- setCaption(name);
- mMenuAction = "friends";
- }
-
- A_DELETE_COPY(SocialFriendsTab)
-
- ~SocialFriendsTab()
- {
- delete2(mList)
- delete2(mScroll)
- delete2(mBeings)
- }
-
- void updateList() override final
- {
- getPlayersAvatars();
- }
-
- void getPlayersAvatars()
- {
- if (actorManager == nullptr)
- return;
-
- STD_VECTOR<Avatar*> *const avatars = mBeings->getMembers();
-
- STD_VECTOR<Avatar*>::iterator ia = avatars->begin();
- while (ia != avatars->end())
- {
- delete *ia;
- ++ ia;
- }
- avatars->clear();
-
- const StringVect *const players
- = playerRelations.getPlayersByRelation(Relation::FRIEND);
-
- const std::set<std::string> &players2
- = whoIsOnline->getOnlineNicks();
-
- if (players == nullptr)
- return;
-
- int online = 0;
- int total = 0;
-
- FOR_EACHP (StringVectCIter, it, players)
- {
- Avatar *const ava = new Avatar(*it);
- if (actorManager->findBeingByName(*it, ActorType::Player) !=
- nullptr || players2.find(*it) != players2.end())
- {
- ava->setOnline(true);
- online ++;
- }
- total ++;
- avatars->push_back(ava);
- }
- std::sort(avatars->begin(), avatars->end(), mFriendSorter);
- delete players;
-
- // TRANSLATORS: social window label
- mCounterString = strprintf(_("Friends: %u/%u"),
- CAST_U32(online),
- CAST_U32(total));
- updateCounter();
- }
-
- private:
- BeingsListModel *mBeings;
- SortFriendsFunctor mFriendSorter;
-};
-
-#endif // GUI_WIDGETS_TABS_SOCIALFRIENDSTAB_H
diff --git a/src/gui/widgets/tabs/socialguildtab.h b/src/gui/widgets/tabs/socialguildtab.h
deleted file mode 100644
index 8652a54fe..000000000
--- a/src/gui/widgets/tabs/socialguildtab.h
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SOCIALGUILDTAB_H
-#define GUI_WIDGETS_TABS_SOCIALGUILDTAB_H
-
-#include "gui/widgets/tabs/socialtab.h"
-
-#include "being/localplayer.h"
-
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include "net/guildhandler.h"
-
-#include "localconsts.h"
-
-class SocialGuildTab final : public SocialTab,
- public ActionListener
-{
- public:
- SocialGuildTab(const Widget2 *const widget,
- Guild *const guild,
- const Opaque showBackground) :
- SocialTab(widget),
- ActionListener(),
- mGuild(guild)
- {
- // TRANSLATORS: tab in social window
- setCaption(_("Guild"));
-
- setTabColor(&getThemeColor(ThemeColorId::GUILD_SOCIAL_TAB),
- &getThemeColor(ThemeColorId::GUILD_SOCIAL_TAB_OUTLINE));
- setHighlightedTabColor(&getThemeColor(
- ThemeColorId::GUILD_SOCIAL_TAB_HIGHLIGHTED), &getThemeColor(
- ThemeColorId::GUILD_SOCIAL_TAB_HIGHLIGHTED_OUTLINE));
- setSelectedTabColor(&getThemeColor(
- ThemeColorId::GUILD_SOCIAL_TAB_SELECTED),
- &getThemeColor(
- ThemeColorId::GUILD_SOCIAL_TAB_SELECTED_OUTLINE));
-
- createControls(guild, showBackground);
- mMenuAction = "guild";
- }
-
- A_DELETE_COPY(SocialGuildTab)
-
- ~SocialGuildTab()
- {
- delete2(mList)
- delete2(mScroll)
- }
-
- void action(const ActionEvent &event) override final
- {
- const std::string &eventId = event.getId();
- if (eventId == "do invite")
- {
- const std::string name = mInviteDialog->getText();
- guildHandler->invite(name);
-
- if (localChatTab != nullptr)
- {
- localChatTab->chatLog(strprintf(
- // TRANSLATORS: chat message
- _("Invited user %s to guild %s."),
- name.c_str(),
- mGuild->getName().c_str()),
- ChatMsgType::BY_SERVER);
- }
- mInviteDialog = nullptr;
- }
- else if (eventId == "~do invite")
- {
- mInviteDialog = nullptr;
- }
- else if (eventId == "yes")
- {
- guildHandler->leave(mGuild->getId());
- if (localChatTab != nullptr)
- {
- localChatTab->chatLog(strprintf(
- // TRANSLATORS: chat message
- _("Guild %s quit requested."),
- mGuild->getName().c_str()),
- ChatMsgType::BY_SERVER);
- }
- mConfirmDialog = nullptr;
- }
- else if (eventId == "~yes")
- {
- mConfirmDialog = nullptr;
- }
- }
-
- void invite() override final
- {
- CREATEWIDGETV(mInviteDialog, TextDialog,
- // TRANSLATORS: guild invite message
- _("Member Invite to Guild"),
- // TRANSLATORS: guild invite message
- strprintf(_("Who would you like to invite to guild %s?"),
- mGuild->getName().c_str()), socialWindow);
- mInviteDialog->setActionEventId("do invite");
- mInviteDialog->addActionListener(this);
- }
-
- void leave() override final
- {
- CREATEWIDGETV(mConfirmDialog, ConfirmDialog,
- // TRANSLATORS: guild leave message
- _("Leave Guild?"),
- // TRANSLATORS: guild leave message
- strprintf(_("Are you sure you want to leave guild %s?"),
- mGuild->getName().c_str()), SOUND_REQUEST, socialWindow);
- mConfirmDialog->addActionListener(this);
- }
-
- void buildCounter(const int online0, const int total0) override final
- {
- if ((online0 != 0) || (total0 != 0))
- {
- // TRANSLATORS: social window label
- mCounterString = strprintf(_("Members: %u/%u"),
- CAST_U32(online0),
- CAST_U32(total0));
- }
- else
- {
- if (localPlayer == nullptr)
- return;
-
- const Guild *const guild = localPlayer->getGuild();
- if (guild == nullptr)
- return;
-
- const Guild::MemberList *const members = guild->getMembers();
- int online = 0;
- int total = 0;
- FOR_EACHP (Guild::MemberList::const_iterator, it, members)
- {
- if ((*it)->getOnline())
- online ++;
- total ++;
- }
-
- // TRANSLATORS: social window label
- mCounterString = strprintf(_("Players: %u/%u"),
- CAST_U32(online),
- CAST_U32(total));
- }
- updateCounter();
- }
-
- private:
- Guild *mGuild;
-};
-
-#endif // GUI_WIDGETS_TABS_SOCIALGUILDTAB_H
diff --git a/src/gui/widgets/tabs/socialguildtab2.h b/src/gui/widgets/tabs/socialguildtab2.h
deleted file mode 100644
index ff8544232..000000000
--- a/src/gui/widgets/tabs/socialguildtab2.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SOCIALGUILDTAB2_H
-#define GUI_WIDGETS_TABS_SOCIALGUILDTAB2_H
-
-#include "gui/widgets/tabs/socialtab.h"
-
-#include "guild.h"
-
-#include "being/localplayer.h"
-
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include "localconsts.h"
-
-class SocialGuildTab2 final : public SocialTab,
- public ActionListener
-{
- public:
- SocialGuildTab2(const Widget2 *const widget,
- Guild *const guild,
- const Opaque showBackground) :
- SocialTab(widget),
- ActionListener()
- {
- // TRANSLATORS: tab in social window
- setCaption(_("Guild"));
-
- setTabColor(&getThemeColor(ThemeColorId::GUILD_SOCIAL_TAB),
- &getThemeColor(ThemeColorId::GUILD_SOCIAL_TAB_OUTLINE));
- setHighlightedTabColor(&getThemeColor(
- ThemeColorId::GUILD_SOCIAL_TAB_HIGHLIGHTED),
- &getThemeColor(
- ThemeColorId::GUILD_SOCIAL_TAB_HIGHLIGHTED_OUTLINE));
- setSelectedTabColor(&getThemeColor(
- ThemeColorId::GUILD_SOCIAL_TAB_SELECTED),
- &getThemeColor(
- ThemeColorId::GUILD_SOCIAL_TAB_SELECTED_OUTLINE));
-
- createControls(guild, showBackground);
- mMenuAction = "guild";
- }
-
- A_DELETE_COPY(SocialGuildTab2)
-
- ~SocialGuildTab2()
- {
- delete2(mList)
- delete2(mScroll)
- }
-
- void action(const ActionEvent &event A_UNUSED) override final
- {
- }
-
- void buildCounter(const int online0 A_UNUSED,
- const int total0 A_UNUSED) override final
- {
- if (localPlayer == nullptr)
- return;
-
- const Guild *const guild = localPlayer->getGuild();
- if (guild == nullptr)
- return;
-
- const Guild::MemberList *const members = guild->getMembers();
- int online = 0;
- int total = 0;
- FOR_EACHP (Guild::MemberList::const_iterator, it, members)
- {
- if ((*it)->getOnline())
- online ++;
- total ++;
- }
-
- // TRANSLATORS: social window label
- mCounterString = strprintf(_("Players: %u/%u"),
- CAST_U32(online),
- CAST_U32(total));
- updateCounter();
- }
-};
-
-#endif // GUI_WIDGETS_TABS_SOCIALGUILDTAB2_H
diff --git a/src/gui/widgets/tabs/socialnavigationtab.h b/src/gui/widgets/tabs/socialnavigationtab.h
deleted file mode 100644
index 1b049f055..000000000
--- a/src/gui/widgets/tabs/socialnavigationtab.h
+++ /dev/null
@@ -1,308 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SOCIALNAVIGATIONTAB_H
-#define GUI_WIDGETS_TABS_SOCIALNAVIGATIONTAB_H
-
-#include "gui/widgets/tabs/socialtab.h"
-
-#include "actormanager.h"
-#include "configuration.h"
-
-#include "gui/models/beingslistmodel.h"
-
-#include "gui/windows/outfitwindow.h"
-
-#include "being/localplayer.h"
-
-#include "input/keyboardconfig.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include "resources/map/map.h"
-#include "resources/map/mapitem.h"
-#include "resources/map/speciallayer.h"
-
-#include "localconsts.h"
-
-class Avatar;
-
-class SocialNavigationTab final : public SocialTab
-{
- public:
- SocialNavigationTab(const Widget2 *const widget,
- const Opaque showBackground) :
- SocialTab(widget),
- mBeings(new BeingsListModel)
- {
- createControls(mBeings, showBackground);
-
- // TRANSLATORS: Navigation tab name in social window.
- // TRANSLATORS: Should be small
- setCaption(_("Nav"));
- mMenuAction = "navigation";
- }
-
- A_DELETE_COPY(SocialNavigationTab)
-
- ~SocialNavigationTab()
- {
- delete2(mList)
- delete2(mScroll)
- delete2(mBeings)
- }
-
- void updateList() override final
- {
- if ((socialWindow == nullptr) || (localPlayer == nullptr))
- return;
-
- const Map *const map = socialWindow->getMap();
- if ((map == nullptr) || map->empty())
- return;
-
- if (socialWindow->getProcessedPortals())
- return;
-
- STD_VECTOR<Avatar*> *const avatars = mBeings->getMembers();
- STD_VECTOR<MapItem*> portals = map->getPortals();
-
- STD_VECTOR<MapItem*>::const_iterator i = portals.begin();
- const SpecialLayer *const specialLayer = map->getSpecialLayer();
-
- STD_VECTOR<Avatar*>::iterator ia = avatars->begin();
-
- while (ia != avatars->end())
- {
- delete *ia;
- ++ ia;
- }
-
- avatars->clear();
-
- int online = 0;
- int total = 0;
-
- int idx = 0;
- while (i != portals.end())
- {
- MapItem *portal = *i;
- if (portal == nullptr)
- continue;
-
- const int x = portal->getX();
- const int y = portal->getY();
-
- const std::string name = strprintf("%s [%d %d]",
- portal->getComment().c_str(), x, y);
-
- Avatar *const ava = new Avatar(name);
- if (localPlayer != nullptr)
- ava->setOnline(localPlayer->isReachable(x, y, true));
- else
- ava->setOnline(false);
- ava->setLevel(-1);
- ava->setType(portal->getType());
- ava->setX(x);
- ava->setY(y);
- avatars->push_back(ava);
-
- if (ava->getOnline())
- online ++;
- total ++;
-
- if (config.getBoolValue("drawHotKeys")
- && idx < 80 && (outfitWindow != nullptr))
- {
- Being *const being = actorManager
- ->findPortalByTile(x, y);
- if (being != nullptr)
- {
- being->setName(KeyboardConfig::getKeyShortString(
- OutfitWindow::keyName(idx)));
- }
-
- if (specialLayer != nullptr)
- {
- portal = specialLayer->getTile(
- ava->getX(), ava->getY());
- if (portal != nullptr)
- {
- portal->setName(KeyboardConfig::getKeyShortString(
- OutfitWindow::keyName(idx)));
- }
- }
- }
-
- ++i;
- idx ++;
- }
- if (socialWindow != nullptr)
- socialWindow->setProcessedPortals(true);
-
- // TRANSLATORS: social window label
- mCounterString = strprintf(_("Portals: %u/%u"),
- CAST_U32(online),
- CAST_U32(total));
- updateCounter();
- }
-
- void selectIndex(const unsigned num) override final
- {
- if (localPlayer == nullptr)
- return;
-
- STD_VECTOR<Avatar*> *const avatars = mBeings->getMembers();
- if (avatars->size() <= CAST_SIZE(num))
- return;
-
- const Avatar *const ava = avatars->at(num);
- if ((ava != nullptr) && (localPlayer != nullptr))
- localPlayer->navigateTo(ava->getX(), ava->getY());
- }
-
- void updateNames()
- {
- if (socialWindow == nullptr)
- return;
-
- STD_VECTOR<Avatar*> *const avatars = mBeings->getMembers();
-
- const Map *const map = socialWindow->getMap();
- if (map == nullptr)
- return;
-
- STD_VECTOR<Avatar*>::const_iterator i = avatars->begin();
- const STD_VECTOR<Avatar*>::const_iterator i_end = avatars->end();
- while (i != i_end)
- {
- Avatar *const ava = *i;
- if (ava == nullptr)
- break;
-
- const MapItem *const item = map->findPortalXY(
- ava->getX(), ava->getY());
- if (item != nullptr)
- {
- const std::string name = strprintf("%s [%d %d]",
- item->getComment().c_str(),
- item->getX(), item->getY());
- ava->setName(name);
- ava->setOriginalName(name);
- }
-
- ++i;
- }
- }
-
- int getPortalIndex(const int x, const int y)
- {
- if (socialWindow == nullptr)
- return -1;
-
- STD_VECTOR<Avatar*> *const avatars = mBeings->getMembers();
- const Map *const map = socialWindow->getMap();
- if (map == nullptr)
- return -1;
-
- STD_VECTOR<Avatar*>::const_iterator i = avatars->begin();
- const STD_VECTOR<Avatar*>::const_iterator i_end = avatars->end();
- unsigned num = 0;
- while (i != i_end)
- {
- const Avatar *const ava = *i;
- if (ava == nullptr)
- break;
-
- if (ava->getX() == x && ava->getY() == y)
- return num;
-
- ++i;
- num ++;
- }
- return -1;
- }
-
- void addPortal(const int x, const int y)
- {
- if ((socialWindow == nullptr) || (localPlayer == nullptr))
- return;
-
- const Map *const map = socialWindow->getMap();
- if (map == nullptr)
- return;
-
- STD_VECTOR<Avatar*> *const avatars = mBeings->getMembers();
- const MapItem *const portal = map->findPortalXY(x, y);
- if (portal == nullptr)
- return;
-
- const std::string name = strprintf("%s [%d %d]",
- portal->getComment().c_str(), x, y);
-
- Avatar *const ava = new Avatar(name);
- if (localPlayer != nullptr)
- ava->setOnline(localPlayer->isReachable(x, y, true));
- else
- ava->setOnline(false);
- ava->setLevel(-1);
- ava->setType(portal->getType());
- ava->setX(x);
- ava->setY(y);
- avatars->push_back(ava);
- }
-
- void removePortal(const int x, const int y)
- {
- if ((socialWindow == nullptr) || (localPlayer == nullptr))
- return;
-
- const Map *const map = socialWindow->getMap();
- if (map == nullptr)
- return;
-
- STD_VECTOR<Avatar*> *const avatars = mBeings->getMembers();
- STD_VECTOR<Avatar*>::iterator i = avatars->begin();
- const STD_VECTOR<Avatar*>::iterator i_end = avatars->end();
-
- while (i != i_end)
- {
- Avatar *ava = (*i);
-
- if (ava == nullptr)
- break;
-
- if (ava->getX() == x && ava->getY() == y)
- {
- delete ava;
- avatars->erase(i);
- return;
- }
-
- ++ i;
- }
- }
-
- private:
- BeingsListModel *mBeings;
-};
-
-#endif // GUI_WIDGETS_TABS_SOCIALNAVIGATIONTAB_H
diff --git a/src/gui/widgets/tabs/socialpartytab.h b/src/gui/widgets/tabs/socialpartytab.h
deleted file mode 100644
index d7f22c1f7..000000000
--- a/src/gui/widgets/tabs/socialpartytab.h
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SOCIALPARTYTAB_H
-#define GUI_WIDGETS_TABS_SOCIALPARTYTAB_H
-
-#include "gui/widgets/tabs/socialtab.h"
-
-#include "party.h"
-
-#include "being/localplayer.h"
-
-#include "net/partyhandler.h"
-
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include "localconsts.h"
-
-class SocialPartyTab final : public SocialTab,
- public ActionListener
-{
- public:
- SocialPartyTab(const Widget2 *const widget,
- Party *const party,
- const Opaque showBackground) :
- SocialTab(widget),
- ActionListener(),
- mParty(party)
- {
- // TRANSLATORS: tab in social window
- setCaption(_("Party"));
-
- setTabColor(&getThemeColor(ThemeColorId::PARTY_SOCIAL_TAB),
- &getThemeColor(ThemeColorId::PARTY_SOCIAL_TAB_OUTLINE));
- setHighlightedTabColor(&getThemeColor(
- ThemeColorId::PARTY_SOCIAL_TAB_HIGHLIGHTED), &getThemeColor(
- ThemeColorId::PARTY_SOCIAL_TAB_HIGHLIGHTED_OUTLINE));
- setSelectedTabColor(&getThemeColor(
- ThemeColorId::PARTY_SOCIAL_TAB_SELECTED),
- &getThemeColor(
- ThemeColorId::PARTY_SOCIAL_TAB_SELECTED_OUTLINE));
-
- createControls(party, showBackground);
- mMenuAction = "party";
- }
-
- A_DELETE_COPY(SocialPartyTab)
-
- ~SocialPartyTab()
- {
- delete2(mList)
- delete2(mScroll)
- }
-
- void action(const ActionEvent &event) override final
- {
- const std::string &eventId = event.getId();
- if (eventId == "do invite")
- {
- const std::string name = mInviteDialog->getText();
- partyHandler->invite(name);
-
- if (localChatTab != nullptr)
- {
- localChatTab->chatLog(strprintf(
- // TRANSLATORS: chat message
- _("Invited user %s to party."),
- name.c_str()),
- ChatMsgType::BY_SERVER);
- }
- mInviteDialog = nullptr;
- }
- else if (eventId == "~do invite")
- {
- mInviteDialog = nullptr;
- }
- else if (eventId == "yes")
- {
- partyHandler->leave();
- if (localChatTab != nullptr)
- {
- localChatTab->chatLog(strprintf(
- // TRANSLATORS: tab in social window
- _("Party %s quit requested."),
- mParty->getName().c_str()),
- ChatMsgType::BY_SERVER);
- }
- mConfirmDialog = nullptr;
- }
- else if (eventId == "~yes")
- {
- mConfirmDialog = nullptr;
- }
- }
-
- void invite() override final
- {
- CREATEWIDGETV(mInviteDialog, TextDialog,
- // TRANSLATORS: party invite message
- _("Member Invite to Party"),
- // TRANSLATORS: party invite message
- strprintf(_("Who would you like to invite to party %s?"),
- mParty->getName().c_str()), socialWindow);
- mInviteDialog->setActionEventId("do invite");
- mInviteDialog->addActionListener(this);
- }
-
- void leave() override final
- {
- CREATEWIDGETV(mConfirmDialog, ConfirmDialog,
- // TRANSLATORS: party leave message
- _("Leave Party?"),
- // TRANSLATORS: party leave message
- strprintf(_("Are you sure you want to leave party %s?"),
- mParty->getName().c_str()), SOUND_REQUEST, socialWindow);
- mConfirmDialog->addActionListener(this);
- }
-
- void buildCounter(const int online0 A_UNUSED,
- const int total0 A_UNUSED) override final
- {
- if (localPlayer == nullptr)
- return;
-
- const Party *const party = localPlayer->getParty();
- if (party == nullptr)
- return;
-
- const Party::MemberList *const members = party->getMembers();
- int online = 0;
- int total = 0;
- FOR_EACHP (Party::MemberList::const_iterator, it, members)
- {
- if ((*it)->getOnline())
- online ++;
- total ++;
- }
-
- // TRANSLATORS: social window label
- mCounterString = strprintf(_("Players: %u/%u"),
- CAST_U32(online),
- CAST_U32(total));
- updateCounter();
- }
-
- private:
- Party *mParty;
-};
-
-#endif // GUI_WIDGETS_TABS_SOCIALPARTYTAB_H
diff --git a/src/gui/widgets/tabs/socialpickuptab.h b/src/gui/widgets/tabs/socialpickuptab.h
deleted file mode 100644
index 93d00e81a..000000000
--- a/src/gui/widgets/tabs/socialpickuptab.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SOCIALPICKUPTAB_H
-#define GUI_WIDGETS_TABS_SOCIALPICKUPTAB_H
-
-#include "gui/widgets/tabs/socialtab.h"
-
-#include "being/localplayer.h"
-
-#include "gui/models/beingslistmodel.h"
-
-#include "gui/widgets/tabs/socialtabbase.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include "localconsts.h"
-
-class SocialPickupTab final : public SocialTab
-{
- public:
- SocialPickupTab(const Widget2 *const widget,
- const Opaque showBackground) :
- SocialTab(widget),
- mBeings(new BeingsListModel)
- {
- createControls(mBeings, showBackground);
-
- // TRANSLATORS: Pickup filter tab name in social window.
- // TRANSLATORS: Should be small
- setCaption(_("Pik"));
- mMenuAction = "pickup";
- }
-
- A_DELETE_COPY(SocialPickupTab)
-
- ~SocialPickupTab()
- {
- delete2(mList)
- delete2(mScroll)
- delete2(mBeings)
- }
-
- void updateList() override final
- {
- updateAtkListStart();
- // TRANSLATORS: items group name in social window
- addAvatars(PickupItem, _("Pickup items"), PICKUP);
- // TRANSLATORS: items group name in social window
- addAvatars(IgnorePickupItem, _("Ignore items"), NOPICKUP);
- }
-
- private:
- BeingsListModel *mBeings;
-};
-
-#endif // GUI_WIDGETS_TABS_SOCIALPICKUPTAB_H
diff --git a/src/gui/widgets/tabs/socialplayerstab.h b/src/gui/widgets/tabs/socialplayerstab.h
deleted file mode 100644
index c43093fca..000000000
--- a/src/gui/widgets/tabs/socialplayerstab.h
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SOCIALPLAYERSTAB_H
-#define GUI_WIDGETS_TABS_SOCIALPLAYERSTAB_H
-
-#include "gui/widgets/tabs/socialtab.h"
-
-#include "actormanager.h"
-#include "party.h"
-
-#include "being/being.h"
-
-#include "gui/models/beingslistmodel.h"
-
-#include "utils/gettext.h"
-#include "utils/delete2.h"
-#include "utils/stringutils.h"
-
-#include "localconsts.h"
-
-class Avatar;
-class Being;
-
-class SocialPlayersTab final : public SocialTab
-{
- public:
- SocialPlayersTab(const Widget2 *const widget,
- const std::string &name,
- const Opaque showBackground) :
- SocialTab(widget),
- mBeings(new BeingsListModel)
- {
- createControls(mBeings, showBackground);
-
- getPlayersAvatars();
- setCaption(name);
- mMenuAction = "players";
- }
-
- A_DELETE_COPY(SocialPlayersTab)
-
- ~SocialPlayersTab()
- {
- delete2(mList)
- delete2(mScroll)
- delete2(mBeings)
- }
-
- void updateList() override final
- {
- getPlayersAvatars();
- }
-
- void updateAvatar(const std::string &name) override final
- {
- if (actorManager == nullptr)
- return;
-
- BLOCK_START("SocialPlayersTab::updateAvatar")
- Avatar *const avatar = findAvatarbyName(name);
- if (avatar == nullptr)
- return;
- if (Party::getParty(1) != nullptr)
- {
- const PartyMember *const
- pm = Party::getParty(1)->getMember(name);
- if ((pm != nullptr) && pm->getMaxHp() > 0)
- {
- avatar->setMaxHp(pm->getMaxHp());
- avatar->setHp(pm->getHp());
- }
- }
- const Being *const being = actorManager->findBeingByName(
- name, ActorType::Player);
- if (being != nullptr)
- {
- avatar->setDamageHp(being->getDamageTaken());
- avatar->setLevel(being->getLevel());
- avatar->setGender(being->getGender());
- avatar->setIp(being->getIp());
- avatar->setPoison(being->getPoison());
- }
- BLOCK_END("SocialPlayersTab::updateAvatar")
- }
-
- void resetDamage(const std::string &name) override final
- {
- if (actorManager == nullptr)
- return;
-
- Avatar *const avatar = findAvatarbyName(name);
- if (avatar == nullptr)
- return;
- avatar->setDamageHp(0);
- Being *const being = actorManager->findBeingByName(
- name, ActorType::Player);
-
- if (being != nullptr)
- being->setDamageTaken(0);
- }
-
- Avatar* findAvatarbyName(const std::string &name)
- {
- STD_VECTOR<Avatar*> *const avatars = mBeings->getMembers();
- Avatar *ava = nullptr;
- STD_VECTOR<Avatar*>::const_iterator i = avatars->begin();
- const STD_VECTOR<Avatar*>::const_iterator i_end = avatars->end();
- while (i != i_end)
- {
- ava = (*i);
- if ((ava != nullptr) && ava->getName() == name)
- return ava;
- ++i;
- }
- ava = new Avatar(name);
- ava->setOnline(true);
- avatars->push_back(ava);
- return ava;
- }
-
- void getPlayersAvatars()
- {
- STD_VECTOR<Avatar*> *const avatars = mBeings->getMembers();
- if (actorManager != nullptr)
- {
- StringVect names;
- actorManager->getPlayerNames(names, NpcNames_false);
-
- STD_VECTOR<Avatar*>::iterator ai = avatars->begin();
- while (ai != avatars->end())
- {
- bool finded = false;
- const Avatar *const ava = (*ai);
- if (ava == nullptr)
- break;
-
- StringVectCIter i = names.begin();
- const StringVectCIter i_end = names.end();
- while (i != i_end)
- {
- if (ava->getName() == (*i) && !(*i).empty())
- {
- finded = true;
- break;
- }
- ++i;
- }
-
- if (!finded)
- {
- delete *ai;
- ai = avatars->erase(ai);
- }
- else
- {
- ++ai;
- }
- }
-
- StringVectCIter i = names.begin();
- const StringVectCIter i_end = names.end();
-
- while (i != i_end)
- {
- if (!(*i).empty())
- updateAvatar(*i);
- ++i;
- }
- }
- // TRANSLATORS: social window label
- mCounterString = strprintf(_("Visible players: %d"),
- CAST_S32(avatars->size()));
- updateCounter();
- }
-
- private:
- BeingsListModel *mBeings;
-};
-
-#endif // GUI_WIDGETS_TABS_SOCIALPLAYERSTAB_H
diff --git a/src/gui/widgets/tabs/socialtab.h b/src/gui/widgets/tabs/socialtab.h
deleted file mode 100644
index 1c94aaede..000000000
--- a/src/gui/widgets/tabs/socialtab.h
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SOCIALTAB_H
-#define GUI_WIDGETS_TABS_SOCIALTAB_H
-
-#include "gui/windows/socialwindow.h"
-
-#include "gui/windows/confirmdialog.h"
-#include "gui/windows/textdialog.h"
-
-#include "gui/widgets/avatarlistbox.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "gui/widgets/tabs/tab.h"
-
-#include "localconsts.h"
-
-class AvatarListModel;
-
-class SocialTab notfinal : public Tab
-{
- public:
- A_DELETE_COPY(SocialTab)
-
- virtual void invite()
- {
- }
-
- virtual void leave()
- {
- }
-
- virtual void updateList()
- {
- }
-
- virtual void updateAvatar(const std::string &name A_UNUSED)
- {
- }
-
- virtual void resetDamage(const std::string &name A_UNUSED)
- {
- }
-
- virtual void selectIndex(const unsigned num A_UNUSED)
- {
- }
-
- virtual void buildCounter(const int online A_UNUSED,
- const int total A_UNUSED)
- {
- }
-
- protected:
- friend class SocialWindow;
-
- explicit SocialTab(const Widget2 *const widget) :
- Tab(widget),
- mInviteDialog(nullptr),
- mConfirmDialog(nullptr),
- mScroll(nullptr),
- mList(nullptr),
- mCounterString(),
- mMenuAction("menu")
- {
- }
-
- virtual ~SocialTab()
- {
- // Cleanup dialogs
- if (mInviteDialog != nullptr)
- {
- mInviteDialog->close();
- mInviteDialog->scheduleDelete();
- mInviteDialog = nullptr;
- }
-
- if (mConfirmDialog != nullptr)
- {
- mConfirmDialog->close();
- mConfirmDialog->scheduleDelete();
- mConfirmDialog = nullptr;
- }
- }
-
- void createControls(AvatarListModel *const listModel,
- const Opaque showBackground)
- {
- CREATEWIDGETV(mList, AvatarListBox, this, listModel);
- mScroll = new ScrollArea(this, mList, showBackground,
- "social_background.xml");
-
- mScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_AUTO);
- mScroll->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS);
- }
-
- void setCurrent() override final
- {
- updateCounter();
- updateMenu();
- }
-
- void updateCounter() const
- {
- if (socialWindow != nullptr)
- socialWindow->updateCounter(this, mCounterString);
- }
-
- void updateMenu() const
- {
- if (socialWindow != nullptr)
- socialWindow->updateMenu(this, mMenuAction);
- }
-
- TextDialog *mInviteDialog;
- ConfirmDialog *mConfirmDialog;
- ScrollArea *mScroll;
- AvatarListBox *mList;
- std::string mCounterString;
- std::string mMenuAction;
-};
-
-#endif // GUI_WIDGETS_TABS_SOCIALTAB_H
diff --git a/src/gui/widgets/tabs/socialtabbase.h b/src/gui/widgets/tabs/socialtabbase.h
deleted file mode 100644
index 03a02bb1f..000000000
--- a/src/gui/widgets/tabs/socialtabbase.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SOCIALTABBASE_H
-#define GUI_WIDGETS_TABS_SOCIALTABBASE_H
-
-#include "actormanager.h"
-
-ACTORMANAGER_H
-
-#include "enums/resources/map/mapitemtype.h"
-
-ENUMS_RESOURCES_MAP_MAPITEMTYPE_H
-
-#define addAvatars(mob, str, type) \
-{\
- ava = new Avatar(str);\
- ava->setOnline(false);\
- ava->setLevel(-1);\
- ava->setType(MapItemType::SEPARATOR);\
- ava->setX(0);\
- ava->setY(0);\
- avatars->push_back(ava);\
- mobs = actorManager->get##mob##s();\
- i = mobs.begin();\
- i_end = mobs.end();\
- while (i != i_end)\
- {\
- std::string name;\
- int level = -1;\
- if ((*i).empty())\
- {\
- name = _("(default)");\
- level = 0;\
- }\
- else\
- {\
- name = *i;\
- }\
- ava = new Avatar(name);\
- ava->setOnline(true);\
- ava->setLevel(level);\
- ava->setType(MapItemType::type);\
- ava->setX(0);\
- ava->setY(0);\
- avatars->push_back(ava);\
- ++ i;\
- }\
-}
-
-#define updateAtkListStart() \
- if (!socialWindow || !localPlayer || !actorManager)\
- return;\
- STD_VECTOR<Avatar*> *const avatars = mBeings->getMembers();\
- STD_VECTOR<Avatar*>::iterator ia = avatars->begin();\
- while (ia != avatars->end())\
- {\
- delete *ia;\
- ++ ia;\
- }\
- avatars->clear();\
- Avatar *ava = nullptr;\
- std::list<std::string> mobs;\
- std::list<std::string>::const_iterator i;\
- std::list<std::string>::const_iterator i_end;
-
-#endif // GUI_WIDGETS_TABS_SOCIALTABBASE_H
diff --git a/src/gui/widgets/tabs/tab.cpp b/src/gui/widgets/tabs/tab.cpp
deleted file mode 100644
index 36c2a3f40..000000000
--- a/src/gui/widgets/tabs/tab.cpp
+++ /dev/null
@@ -1,488 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/tabs/tab.h"
-
-#include "settings.h"
-
-#include "gui/gui.h"
-#include "gui/skin.h"
-
-#include "gui/widgets/label.h"
-#include "gui/widgets/tabbedarea.h"
-
-#include "render/vertexes/imagecollection.h"
-
-#include "resources/imagerect.h"
-
-#include "resources/image/image.h"
-
-#include "utils/delete2.h"
-
-#include "debug.h"
-
-int Tab::mInstances = 0;
-float Tab::mAlpha = 1.0;
-
-namespace
-{
- std::string const data[Tab::TAB_COUNT] =
- {
- "tab.xml",
- "tab_highlighted.xml",
- "tab_selected.xml",
- "tab_unused.xml"
- };
-} // namespace
-
-Skin *Tab::tabImg[Tab::TAB_COUNT];
-
-Tab::Tab(const Widget2 *const widget) :
- BasicContainer(widget),
- MouseListener(),
- WidgetListener(),
- mLabel(new Label(this)),
- mTabbedArea(nullptr),
- mTabColor(&getThemeColor(ThemeColorId::TAB)),
- mTabOutlineColor(&getThemeColor(ThemeColorId::TAB_OUTLINE)),
- mTabHighlightedColor(&getThemeColor(ThemeColorId::TAB_HIGHLIGHTED)),
- mTabHighlightedOutlineColor(&getThemeColor(
- ThemeColorId::TAB_HIGHLIGHTED_OUTLINE)),
- mTabSelectedColor(&getThemeColor(ThemeColorId::TAB_SELECTED)),
- mTabSelectedOutlineColor(&getThemeColor(
- ThemeColorId::TAB_SELECTED_OUTLINE)),
- mFlashColor(&getThemeColor(ThemeColorId::TAB_FLASH)),
- mFlashOutlineColor(&getThemeColor(ThemeColorId::TAB_FLASH_OUTLINE)),
- mPlayerFlashColor(&getThemeColor(ThemeColorId::TAB_PLAYER_FLASH)),
- mPlayerFlashOutlineColor(&getThemeColor(
- ThemeColorId::TAB_PLAYER_FLASH_OUTLINE)),
- mFlash(0),
- mVertexes(new ImageCollection),
- mImage(nullptr),
- mMode(0),
- mLabelMode(-1),
- mHasMouse(false)
-{
- init();
-}
-
-Tab::~Tab()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- mInstances--;
- if (mInstances == 0 && (theme != nullptr))
- {
- for (int mode = 0; mode < TAB_COUNT; mode ++)
- theme->unload(tabImg[mode]);
- }
-
- delete2(mLabel);
-
- if (mImage != nullptr)
- {
- mImage->decRef();
- mImage = nullptr;
- }
- delete2(mVertexes);
-}
-
-void Tab::init()
-{
- addMouseListener(this);
- setFocusable(false);
- setFrameSize(0);
- mFlash = 0;
-
- addWidgetListener(this);
-
- if (mInstances == 0)
- {
- // Load the skin
- if (theme != nullptr)
- {
- for (int mode = 0; mode < TAB_COUNT; mode ++)
- tabImg[mode] = theme->load(data[mode], "tab.xml");
- }
- updateAlpha();
- }
- mInstances++;
-
- add(mLabel);
-
- const Skin *const skin = tabImg[TAB_STANDARD];
- if (skin == nullptr)
- return;
- const int padding = skin->getPadding();
-
- mLabel->setPosition(padding, padding);
-}
-
-void Tab::updateAlpha()
-{
- const float alpha = std::max(settings.guiAlpha,
- theme->getMinimumOpacity());
-
- if (alpha != mAlpha)
- {
- mAlpha = alpha;
- for (int a = 0; a < 9; a++)
- {
- for (int t = 0; t < TAB_COUNT; t++)
- {
- Skin *const skin = tabImg[t];
- if (skin != nullptr)
- {
- const ImageRect &rect = skin->getBorder();
- Image *const image = rect.grid[a];
- if (image != nullptr)
- image->setAlpha(mAlpha);
- }
- }
- }
- }
-}
-
-void Tab::draw(Graphics *const graphics)
-{
- BLOCK_START("Tab::draw")
- int mode = TAB_STANDARD;
-
- // check which type of tab to draw
- if (mTabbedArea != nullptr)
- {
- int labelMode = mFlash;
-
- if (mTabbedArea->isTabSelected(this))
- {
- labelMode = 3;
- mode = TAB_SELECTED;
- // if tab is selected, it doesnt need to highlight activity
- mFlash = 0;
- }
- else if (labelMode == 0)
- {
- if (mHasMouse)
- {
- labelMode = 4;
- mode = TAB_HIGHLIGHTED;
- }
- }
- else if (mHasMouse)
- {
- mode = TAB_HIGHLIGHTED;
- }
-
- // mRedraw need here because no other way to say label to change color
- // +++ text from label must be moved to tab itself
- if (labelMode != mLabelMode || mRedraw)
- {
- mLabelMode = labelMode;
- switch (labelMode)
- {
- case 0: // default state
- default:
- mLabel->setForegroundColorAll(*mTabColor,
- *mTabOutlineColor);
- break;
- case 1: // mFlash == 1
- mLabel->setForegroundColorAll(*mFlashColor,
- *mFlashOutlineColor);
- break;
- case 2: // mFlash == 2
- mLabel->setForegroundColorAll(*mPlayerFlashColor,
- *mPlayerFlashOutlineColor);
- break;
- case 3: // mTabbedArea->isTabSelected(this)
- mLabel->setForegroundColorAll(*mTabSelectedColor,
- *mTabSelectedOutlineColor);
- break;
- case 4: // mHasMouse
- mLabel->setForegroundColorAll(*mTabHighlightedColor,
- *mTabHighlightedOutlineColor);
- break;
- }
- }
- }
-
- const Skin *const skin = tabImg[mode];
- if (skin == nullptr)
- {
- BLOCK_END("Tab::draw")
- return;
- }
-
- updateAlpha();
-
- const ImageRect &rect = skin->getBorder();
- if (mRedraw || mode != mMode || graphics->getRedraw())
- {
- mMode = mode;
- mRedraw = false;
- mVertexes->clear();
- graphics->calcWindow(mVertexes,
- 0, 0,
- mDimension.width, mDimension.height,
- rect);
-
- if (mImage != nullptr)
- {
- const Skin *const skin1 = tabImg[TAB_STANDARD];
- if (skin1 != nullptr)
- {
- const int padding = skin1->getPadding();
- graphics->calcTileCollection(mVertexes,
- mImage,
- padding,
- padding);
- }
- }
- graphics->finalize(mVertexes);
- }
-
- graphics->drawTileCollection(mVertexes);
-
- drawChildren(graphics);
- BLOCK_END("Tab::draw")
-}
-
-void Tab::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("Tab::draw")
- int mode = TAB_STANDARD;
-
- // check which type of tab to draw
- if (mTabbedArea != nullptr)
- {
- int labelMode = mFlash;
-
- if (mTabbedArea->isTabSelected(this))
- {
- labelMode = 3;
- mode = TAB_SELECTED;
- // if tab is selected, it doesnt need to highlight activity
- mFlash = 0;
- }
- else if (labelMode == 0)
- {
- if (mHasMouse)
- {
- labelMode = 4;
- mode = TAB_HIGHLIGHTED;
- }
- }
- else if (mHasMouse)
- {
- mode = TAB_HIGHLIGHTED;
- }
-
- if (labelMode != mLabelMode)
- {
- mLabelMode = labelMode;
- switch (labelMode)
- {
- case 0: // default state
- default:
- mLabel->setForegroundColorAll(*mTabColor,
- *mTabOutlineColor);
- break;
- case 1: // mFlash == 1
- mLabel->setForegroundColorAll(*mFlashColor,
- *mFlashOutlineColor);
- break;
- case 2: // mFlash == 2
- mLabel->setForegroundColorAll(*mPlayerFlashColor,
- *mPlayerFlashOutlineColor);
- break;
- case 3: // mTabbedArea->isTabSelected(this)
- mLabel->setForegroundColorAll(*mTabSelectedColor,
- *mTabSelectedOutlineColor);
- break;
- case 4: // mHasMouse
- mLabel->setForegroundColorAll(*mTabHighlightedColor,
- *mTabHighlightedOutlineColor);
- break;
- }
- }
- }
-
- const Skin *const skin = tabImg[mode];
- if (skin == nullptr)
- {
- BLOCK_END("Tab::draw")
- return;
- }
-
- updateAlpha();
-
- graphics->drawImageRect(0, 0,
- mDimension.width, mDimension.height,
- skin->getBorder());
- if (mImage != nullptr)
- {
- const Skin *const skin1 = tabImg[TAB_STANDARD];
- if (skin1 != nullptr)
- {
- const int padding = skin1->getPadding();
- graphics->drawImage(mImage, padding, padding);
- }
- }
-
- safeDrawChildren(graphics);
- BLOCK_END("Tab::draw")
-}
-
-void Tab::widgetResized(const Event &event A_UNUSED)
-{
- mRedraw = true;
-}
-
-void Tab::widgetMoved(const Event &event A_UNUSED)
-{
- mRedraw = true;
-}
-
-void Tab::setLabelFont(Font *const font)
-{
- if (mLabel == nullptr)
- return;
-
- mLabel->setFont(font);
- mLabel->adjustSize();
- adjustSize();
- mRedraw = true;
-}
-
-
-void Tab::adjustSize()
-{
- const Skin *const skin = tabImg[TAB_STANDARD];
- if (skin == nullptr)
- return;
- const int pad2 = skin->getPadding() * 2;
-
- if (mImage != nullptr)
- {
- const SDL_Rect &rect = mImage->mBounds;
- setSize(rect.w + pad2, rect.h + pad2);
- }
- else
- {
- setSize(mLabel->getWidth() + pad2,
- mLabel->getHeight() + pad2);
- }
-
- if (mTabbedArea != nullptr)
- mTabbedArea->adjustTabPositions();
-}
-
-void Tab::setTabbedArea(TabbedArea* tabbedArea)
-{
- mTabbedArea = tabbedArea;
-}
-
-TabbedArea* Tab::getTabbedArea() const
-{
- return mTabbedArea;
-}
-
-void Tab::setCaption(const std::string &caption)
-{
- mLabel->setCaption(caption);
- mLabel->adjustSize();
- adjustSize();
-}
-
-void Tab::setImage(Image *const image)
-{
- if (mImage != nullptr)
- mImage->decRef();
- mImage = image;
- adjustSize();
-}
-
-const std::string &Tab::getCaption() const
-{
- return mLabel->getCaption();
-}
-
-void Tab::mouseEntered(MouseEvent& event A_UNUSED)
-{
- mHasMouse = true;
-}
-
-void Tab::mouseExited(MouseEvent& event A_UNUSED)
-{
- mHasMouse = false;
-}
-
-void Tab::finalCleanup()
-{
- for (int f = 0; f < TAB_COUNT; f ++)
- {
- tabImg[f] = nullptr;
- }
-}
diff --git a/src/gui/widgets/tabs/tab.h b/src/gui/widgets/tabs/tab.h
deleted file mode 100644
index e6a816072..000000000
--- a/src/gui/widgets/tabs/tab.h
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_TABS_TAB_H
-#define GUI_WIDGETS_TABS_TAB_H
-
-#include "gui/widgets/basiccontainer.h"
-
-#include "listeners/mouselistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "localconsts.h"
-
-class ImageCollection;
-class Label;
-class Skin;
-class TabbedArea;
-
-/**
- * A tab, the same as the Guichan tab in 0.8, but extended
- */
-class Tab notfinal : public BasicContainer,
- public MouseListener,
- public WidgetListener
-{
- public:
- explicit Tab(const Widget2 *const widget);
-
- A_DELETE_COPY(Tab)
-
- virtual ~Tab();
-
- enum
- {
- TAB_STANDARD = 0,
- TAB_HIGHLIGHTED = 1,
- TAB_SELECTED = 2,
- TAB_UNUSED = 3,
- TAB_COUNT = 4 // Must be last
- };
-
- /**
- * Update the alpha value to the graphic components.
- */
- void updateAlpha();
-
- /**
- * Draw the tabbed area.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Set the normal color for the tab's text.
- */
- void setTabColor(const Color *const color1,
- const Color *const color2)
- {
- mTabColor = color1;
- mTabOutlineColor = color2;
- mRedraw = true;
- }
-
- /**
- * Set the highlighted color for the tab's text.
- */
- void setHighlightedTabColor(const Color *const color1,
- const Color *const color2)
- {
- mTabHighlightedColor = color1;
- mTabHighlightedOutlineColor = color2;
- mRedraw = true;
- }
-
- /**
- * Set the selected color for the tab's text.
- */
- void setSelectedTabColor(const Color *const color1,
- const Color *const color2)
- {
- mTabSelectedColor = color1;
- mTabSelectedOutlineColor = color2;
- mRedraw = true;
- }
-
- /**
- * Set the flash color for the tab's text.
- */
- void setFlashTabColor(const Color *const color1,
- const Color *const color2)
- {
- mFlashColor = color1;
- mFlashOutlineColor = color2;
- mRedraw = true;
- }
-
- /**
- * Set the player flash color for the tab's text.
- */
- void setPlayerFlashTabColor(const Color *const color1,
- const Color *const color2)
- {
- mPlayerFlashColor = color1;
- mPlayerFlashOutlineColor = color2;
- mRedraw = true;
- }
-
- /**
- * Set tab flashing state
- */
- void setFlash(const int flash)
- { mFlash = flash; mRedraw = true; }
-
- int getFlash() const noexcept2 A_WARN_UNUSED
- { return mFlash; }
-
- void widgetResized(const Event &event) override final;
-
- void widgetMoved(const Event &event) override final;
-
- void setLabelFont(Font *const font);
-
- Label *getLabel() const noexcept2 A_WARN_UNUSED
- { return mLabel; }
-
- void adjustSize();
-
- void setTabbedArea(TabbedArea* tabbedArea);
-
- TabbedArea* getTabbedArea() const A_WARN_UNUSED;
-
- void setCaption(const std::string& caption);
-
- const std::string &getCaption() const A_WARN_UNUSED;
-
- void mouseEntered(MouseEvent &event) override final;
-
- void mouseExited(MouseEvent &event) override final;
-
- void setImage(Image *const image);
-
- static void finalCleanup();
-
- protected:
- friend class TabbedArea;
-
- virtual void setCurrent()
- { }
-
- Label* mLabel A_NONNULLPOINTER;
-
- TabbedArea* mTabbedArea;
-
- private:
- /** Load images if no other instances exist yet */
- void init();
-
- static Skin *tabImg[TAB_COUNT]; /**< Tab state graphics */
- static int mInstances; /**< Number of tab instances */
- static float mAlpha;
-
- const Color *mTabColor;
- const Color *mTabOutlineColor;
- const Color *mTabHighlightedColor;
- const Color *mTabHighlightedOutlineColor;
- const Color *mTabSelectedColor;
- const Color *mTabSelectedOutlineColor;
- const Color *mFlashColor;
- const Color *mFlashOutlineColor;
- const Color *mPlayerFlashColor;
- const Color *mPlayerFlashOutlineColor;
- int mFlash;
- ImageCollection *mVertexes A_NONNULLPOINTER;
- Image *mImage;
- int mMode;
- int mLabelMode;
-
- protected:
- bool mHasMouse;
-};
-
-#endif // GUI_WIDGETS_TABS_TAB_H
diff --git a/src/gui/widgets/tabstrip.cpp b/src/gui/widgets/tabstrip.cpp
deleted file mode 100644
index 6b3dbe417..000000000
--- a/src/gui/widgets/tabstrip.cpp
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabstrip.h"
-
-#include "gui/widgets/button.h"
-
-#include "utils/foreach.h"
-
-#include "debug.h"
-
-TabStrip::TabStrip(const Widget2 *const widget,
- const std::string &group,
- const int height,
- const int spacing) :
- WidgetGroup(widget, group, height, spacing),
- mPressFirst(true)
-{
- mAllowLogic = false;
-}
-
-TabStrip::TabStrip(const Widget2 *const widget,
- const int height,
- const int spacing) :
- WidgetGroup(widget, "", height, spacing),
- mPressFirst(true)
-{
- mAllowLogic = false;
-}
-
-Widget *TabStrip::createWidget(const std::string &text,
- const bool pressed) const
-{
- Button *const widget = new Button(this);
- widget->setStick(true);
- widget->setCaption(text);
- widget->adjustSize();
- if (((mCount == 0) && mPressFirst) || pressed)
- widget->setPressed(true);
- widget->setTag(CAST_S32(mWidgets.size()));
- return widget;
-}
-
-void TabStrip::action(const ActionEvent &event)
-{
- WidgetGroup::action(event);
- if (event.getSource() != nullptr)
- {
- Widget *const widget = event.getSource();
- Button *const button = static_cast<Button*>(widget);
- if (button == nullptr)
- return;
- if (button->isPressed2())
- {
- FOR_EACH (WidgetListConstIterator, iter, mWidgets)
- {
- if (*iter != widget)
- {
- Button *const button2 = static_cast<Button*>(*iter);
- button2->setPressed(false);
- }
- }
- }
- else
- {
- button->setPressed(true);
- }
- }
-}
-
-void TabStrip::nextTab()
-{
- FOR_EACH (WidgetListConstIterator, iter, mWidgets)
- {
- Button *button = static_cast<Button*>(*iter);
- if (button->isPressed2())
- {
- button->setPressed(false);
- ++iter;
- if (iter == mWidgets.end())
- iter = mWidgets.begin();
- button = static_cast<Button*>(*iter);
- action(ActionEvent(button, button->getActionEventId()));
- return;
- }
- }
-}
-
-void TabStrip::prevTab()
-{
- FOR_EACH (WidgetListConstIterator, iter, mWidgets)
- {
- Button *button = static_cast<Button*>(*iter);
- if (button->isPressed2())
- {
- button->setPressed(false);
- if (iter == mWidgets.begin())
- iter = mWidgets.end();
- if (iter == mWidgets.begin())
- return;
- --iter;
- button = static_cast<Button*>(*iter);
- action(ActionEvent(button, button->getActionEventId()));
- return;
- }
- }
-}
diff --git a/src/gui/widgets/tabstrip.h b/src/gui/widgets/tabstrip.h
deleted file mode 100644
index e1e4ca486..000000000
--- a/src/gui/widgets/tabstrip.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABSTRIP_H
-#define GUI_WIDGETS_TABSTRIP_H
-
-#include "gui/widgets/widgetgroup.h"
-
-class TabStrip final : public WidgetGroup
-{
- public:
- TabStrip(const Widget2 *const widget,
- const std::string &group,
- const int height,
- const int spacing = 0);
-
- TabStrip(const Widget2 *const widget,
- const int height,
- const int spacing = 0);
-
- A_DELETE_COPY(TabStrip)
-
- Widget *createWidget(const std::string &name,
- const bool pressed)
- const override final A_WARN_UNUSED;
-
- void action(const ActionEvent &event) override final;
-
- void nextTab();
-
- void prevTab();
-
- void setPressFirst(const bool press)
- { mPressFirst = press; }
-
- protected:
- bool mPressFirst;
-};
-
-#endif // GUI_WIDGETS_TABSTRIP_H
diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp
deleted file mode 100644
index 5d1696835..000000000
--- a/src/gui/widgets/textbox.cpp
+++ /dev/null
@@ -1,647 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/textbox.h"
-
-#include "gui/gui.h"
-
-#include "gui/fonts/font.h"
-
-#include "render/graphics.h"
-
-#include <sstream>
-
-#include "debug.h"
-
-TextBox::TextBox(const Widget2 *const widget) :
- Widget(widget),
- MouseListener(),
- KeyListener(),
- mTextRows(),
- mCaretColumn(0),
- mCaretRow(0),
- mMinWidth(getWidth()),
- mEditable(true),
- mOpaque(Opaque_true)
-{
- mAllowLogic = false;
- setText("");
- setFocusable(true);
-
- addMouseListener(this);
- addKeyListener(this);
- adjustSize();
-
- mForegroundColor = getThemeColor(ThemeColorId::TEXTBOX);
- setOpaque(Opaque_false);
- setFrameSize(0);
-}
-
-TextBox::~TextBox()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-}
-
-void TextBox::setTextWrapped(const std::string &text, const int minDimension)
-{
- // Make sure parent scroll area sets width of this widget
- if (getParent() != nullptr)
- getParent()->logic();
-
- // Take the supplied minimum dimension as a starting
- // point and try to beat it
- mMinWidth = minDimension;
-
- const size_t textSize = text.size();
- size_t spacePos = text.rfind(' ', textSize);
-
- if (spacePos != std::string::npos)
- {
- const std::string word = text.substr(spacePos + 1);
- const int length = getFont()->getWidth(word);
-
- if (length > mMinWidth)
- mMinWidth = length;
- }
-
- std::stringstream wrappedStream;
- size_t newlinePos;
- size_t lastNewlinePos = 0;
- int minWidth = 0;
- int xpos;
-
- do
- {
- // Determine next piece of string to wrap
- newlinePos = text.find('\n', lastNewlinePos);
-
- if (newlinePos == std::string::npos)
- newlinePos = textSize;
-
- std::string line =
- text.substr(lastNewlinePos, newlinePos - lastNewlinePos);
- size_t lastSpacePos = 0;
- xpos = 0;
- const Font *const font = getFont();
- const int spaceWidth = font->getWidth(" ");
- size_t sz = line.size();
-
- do
- {
- spacePos = line.find(' ', lastSpacePos);
-
- if (spacePos == std::string::npos)
- spacePos = sz;
-
- const std::string word =
- line.substr(lastSpacePos, spacePos - lastSpacePos);
-
- const int width = font->getWidth(word);
-
- if (xpos == 0 && width > mMinWidth)
- {
- mMinWidth = width;
- xpos = width;
- wrappedStream << word;
- }
- else if (xpos != 0 && xpos + spaceWidth + width <=
- mMinWidth)
- {
- xpos += spaceWidth + width;
- wrappedStream << " " << word;
- }
- else if (lastSpacePos == 0)
- {
- xpos += width;
- wrappedStream << word;
- }
- else
- {
- if (xpos > minWidth)
- minWidth = xpos;
-
- // The window wasn't big enough. Resize it and try again.
- if (minWidth > mMinWidth)
- {
- mMinWidth = minWidth;
- wrappedStream.clear();
- wrappedStream.str("");
- lastNewlinePos = 0;
- newlinePos = text.find('\n', lastNewlinePos);
- if (newlinePos == std::string::npos)
- newlinePos = textSize;
- line = text.substr(lastNewlinePos, newlinePos -
- lastNewlinePos);
- sz = line.size();
- break;
- }
- else
- {
- wrappedStream << "\n" << word;
- }
- xpos = width;
- }
- lastSpacePos = spacePos + 1;
- }
- while (spacePos != sz);
-
- if (text.find('\n', lastNewlinePos) != std::string::npos)
- wrappedStream << "\n";
-
- lastNewlinePos = newlinePos + 1;
- }
- while (newlinePos != textSize);
-
- if (xpos > minWidth)
- minWidth = xpos;
-
- mMinWidth = minWidth;
-
- setText(wrappedStream.str());
-}
-
-void TextBox::setText(const std::string& text)
-{
- mCaretColumn = 0;
- mCaretRow = 0;
-
- mTextRows.clear();
- if (text.empty())
- {
- adjustSize();
- return;
- }
-
- size_t pos;
- size_t lastPos = 0;
- int length;
- do
- {
- pos = text.find('\n', lastPos);
-
- if (pos != std::string::npos)
- length = CAST_S32(pos - lastPos);
- else
- length = CAST_S32(text.size() - lastPos);
- std::string sub = text.substr(lastPos, length);
- mTextRows.push_back(sub);
- lastPos = pos + 1;
- } while (pos != std::string::npos);
-
- adjustSize();
-}
-
-void TextBox::keyPressed(KeyEvent& event)
-{
- const Key &key = event.getKey();
- const InputActionT action = event.getActionId();
-
- PRAGMA45(GCC diagnostic push)
- PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
- switch (action)
- {
- case InputAction::GUI_LEFT:
- {
- --mCaretColumn;
- if (mCaretColumn < 0)
- {
- --mCaretRow;
-
- if (mCaretRow < 0)
- {
- mCaretRow = 0;
- mCaretColumn = 0;
- }
- else
- {
- mCaretColumn = CAST_S32(
- mTextRows[mCaretRow].size());
- }
- }
- break;
- }
-
- case InputAction::GUI_RIGHT:
- {
- ++mCaretColumn;
- if (mCaretColumn > CAST_S32(mTextRows[mCaretRow].size()))
- {
- ++ mCaretRow;
-
- const int sz = CAST_S32(mTextRows.size());
- if (mCaretRow >= sz)
- {
- mCaretRow = sz - 1;
- if (mCaretRow < 0)
- mCaretRow = 0;
-
- mCaretColumn = CAST_S32(
- mTextRows[mCaretRow].size());
- }
- else
- {
- mCaretColumn = 0;
- }
- }
- break;
- }
-
- case InputAction::GUI_DOWN:
- {
- setCaretRow(mCaretRow + 1);
- break;
- }
- case InputAction::GUI_UP:
- {
- setCaretRow(mCaretRow - 1);
- break;
- }
- case InputAction::GUI_HOME:
- {
- mCaretColumn = 0;
- break;
- }
- case InputAction::GUI_END:
- {
- mCaretColumn = CAST_S32(mTextRows[mCaretRow].size());
- break;
- }
-
- case InputAction::GUI_SELECT2:
- {
- if (mEditable)
- {
- mTextRows.insert(mTextRows.begin() + mCaretRow + 1,
- mTextRows[mCaretRow].substr(mCaretColumn,
- mTextRows[mCaretRow].size() - mCaretColumn));
- mTextRows[mCaretRow].resize(mCaretColumn);
- ++mCaretRow;
- mCaretColumn = 0;
- }
- break;
- }
-
- case InputAction::GUI_BACKSPACE:
- {
- if (mCaretColumn != 0 && mEditable)
- {
- mTextRows[mCaretRow].erase(mCaretColumn - 1, 1);
- --mCaretColumn;
- }
- else if (mCaretColumn == 0 && mCaretRow != 0 && mEditable)
- {
- mCaretColumn = CAST_S32(
- mTextRows[mCaretRow - 1].size());
- mTextRows[mCaretRow - 1] += mTextRows[mCaretRow];
- mTextRows.erase(mTextRows.begin() + mCaretRow);
- --mCaretRow;
- }
- break;
- }
-
- case InputAction::GUI_DELETE:
- {
- if (mCaretColumn < CAST_S32(
- mTextRows[mCaretRow].size()) && mEditable)
- {
- mTextRows[mCaretRow].erase(mCaretColumn, 1);
- }
- else if (mCaretColumn == CAST_S32(
- mTextRows[mCaretRow].size()) &&
- mCaretRow < (CAST_S32(mTextRows.size()) - 1) &&
- mEditable)
- {
- mTextRows[mCaretRow] += mTextRows[mCaretRow + 1];
- mTextRows.erase(mTextRows.begin() + mCaretRow + 1);
- }
- break;
- }
-
- case InputAction::GUI_PAGE_UP:
- {
- Widget *const par = getParent();
-
- if (par != nullptr)
- {
- const int rowsPerPage = par->getChildrenArea().height
- / getFont()->getHeight();
- mCaretRow -= rowsPerPage;
-
- if (mCaretRow < 0)
- mCaretRow = 0;
- }
- break;
- }
-
- case InputAction::GUI_PAGE_DOWN:
- {
- Widget *const par = getParent();
-
- if (par != nullptr)
- {
- const int rowsPerPage = par->getChildrenArea().height
- / getFont()->getHeight();
- mCaretRow += rowsPerPage;
-
- const int sz = CAST_S32(mTextRows.size());
- if (mCaretRow >= sz)
- mCaretRow = sz - 1;
- }
- break;
- }
-
- case InputAction::GUI_TAB:
- {
- if (mEditable)
- {
- mTextRows[mCaretRow].insert(mCaretColumn, std::string(" "));
- mCaretColumn += 4;
- }
- break;
- }
-
- default:
- {
- if (key.isCharacter() && mEditable)
- {
- mTextRows[mCaretRow].insert(mCaretColumn,
- std::string(1, CAST_S8(key.getValue())));
- ++ mCaretColumn;
- }
- break;
- }
- }
- PRAGMA45(GCC diagnostic pop)
-
- adjustSize();
- scrollToCaret();
-
- event.consume();
-}
-
-void TextBox::draw(Graphics *const graphics)
-{
- BLOCK_START("TextBox::draw")
- if (mOpaque == Opaque_true)
- {
- graphics->setColor(mBackgroundColor);
- graphics->fillRectangle(Rect(0, 0, getWidth(), getHeight()));
- }
-
- Font *const font = getFont();
- if (isFocused() && isEditable())
- {
- drawCaret(graphics, font->getWidth(
- mTextRows[mCaretRow].substr(0, mCaretColumn)),
- mCaretRow * font->getHeight());
- }
-
- const int fontHeight = font->getHeight();
-
- for (size_t i = 0, sz = mTextRows.size(); i < sz; i++)
- {
- // Move the text one pixel so we can have a caret before a letter.
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor2,
- mTextRows[i], 1,
- CAST_S32(i * CAST_SIZE(fontHeight)));
- }
- BLOCK_END("TextBox::draw")
-}
-
-void TextBox::safeDraw(Graphics *const graphics)
-{
- TextBox::draw(graphics);
-}
-
-void TextBox::setForegroundColor(const Color &color)
-{
- mForegroundColor = color;
- mForegroundColor2 = color;
-}
-
-void TextBox::setForegroundColorAll(const Color &color1,
- const Color &color2)
-{
- mForegroundColor = color1;
- mForegroundColor2 = color2;
-}
-
-std::string TextBox::getText() const
-{
- if (mTextRows.empty())
- return std::string();
-
- int i;
- std::string text;
-
- const int sz = CAST_S32(mTextRows.size());
- for (i = 0; i < sz - 1; ++ i)
- text.append(mTextRows[i]).append("\n");
- text.append(mTextRows[i]);
-
- return text;
-}
-
-void TextBox::setTextRow(const int row, const std::string& text)
-{
- mTextRows[row] = text;
-
- if (mCaretRow == row)
- setCaretColumn(mCaretColumn);
-
- adjustSize();
-}
-
-void TextBox::setCaretPosition(unsigned int position)
-{
- for (int row = 0, fsz = CAST_S32(mTextRows.size());
- row < fsz;
- row ++)
- {
- if (position <= mTextRows[row].size())
- {
- mCaretRow = row;
- mCaretColumn = position;
- return; // we are done
- }
-
- position--;
- }
-
- // position beyond end of text
- mCaretRow = CAST_S32(mTextRows.size() - 1);
- mCaretColumn = CAST_S32(mTextRows[mCaretRow].size());
-}
-
-void TextBox::setCaretRow(const int row)
-{
- mCaretRow = row;
-
- const int sz = CAST_S32(mTextRows.size());
- if (mCaretRow >= sz)
- mCaretRow = sz - 1;
-
- if (mCaretRow < 0)
- mCaretRow = 0;
-
- setCaretColumn(mCaretColumn);
-}
-
-unsigned int TextBox::getCaretPosition() const
-{
- int pos = 0, row;
-
- for (row = 0; row < mCaretRow; row++)
- pos += CAST_S32(mTextRows[row].size());
-
- return pos + mCaretColumn;
-}
-
-void TextBox::setCaretColumn(const int column)
-{
- mCaretColumn = column;
-
- const int sz = CAST_S32(mTextRows[mCaretRow].size());
- if (mCaretColumn > sz)
- mCaretColumn = sz;
-
- if (mCaretColumn < 0)
- mCaretColumn = 0;
-}
-
-void TextBox::setCaretRowColumn(const int row, const int column)
-{
- setCaretRow(row);
- setCaretColumn(column);
-}
-
-void TextBox::scrollToCaret()
-{
- const Font *const font = getFont();
- Rect scroll;
- scroll.x = font->getWidth(mTextRows[mCaretRow].substr(0, mCaretColumn));
- scroll.y = font->getHeight() * mCaretRow;
- scroll.width = font->getWidth(" ");
- // add 2 for some extra space
- scroll.height = font->getHeight() + 2;
- showPart(scroll);
-}
-
-void TextBox::addRow(const std::string &row)
-{
- mTextRows.push_back(row);
- adjustSize();
-}
-
-void TextBox::mousePressed(MouseEvent& event)
-{
- if (event.getButton() == MouseButton::LEFT)
- {
- const int height = getFont()->getHeight();
- if (height == 0)
- return;
-
- event.consume();
- mCaretRow = event.getY() / height;
-
- const int sz = CAST_S32(mTextRows.size());
- if (mCaretRow >= sz)
- mCaretRow = sz - 1;
-
- mCaretColumn = getFont()->getStringIndexAt(
- mTextRows[mCaretRow], event.getX());
- }
-}
-
-void TextBox::mouseDragged(MouseEvent& event)
-{
- event.consume();
-}
-
-void TextBox::drawCaret(Graphics *const graphics,
- const int x,
- const int y) const
-{
- graphics->setColor(mForegroundColor);
- graphics->drawLine(x, getFont()->getHeight() + y, x, y);
-}
-
-void TextBox::adjustSize()
-{
- int width = 0;
- const Font *const font = getFont();
- for (size_t i = 0, sz = mTextRows.size(); i < sz; ++i)
- {
- const int w = font->getWidth(mTextRows[i]);
- if (width < w)
- width = w;
- }
-
- setWidth(width + 1);
- setHeight(font->getHeight() * CAST_S32(mTextRows.size()));
-}
diff --git a/src/gui/widgets/textbox.h b/src/gui/widgets/textbox.h
deleted file mode 100644
index 6ce28ed4b..000000000
--- a/src/gui/widgets/textbox.h
+++ /dev/null
@@ -1,329 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_TEXTBOX_H
-#define GUI_WIDGETS_TEXTBOX_H
-
-#include "gui/widgets/widget.h"
-
-#include "enums/simpletypes/opaque.h"
-
-#include "listeners/keylistener.h"
-#include "listeners/mouselistener.h"
-
-#include "localconsts.h"
-
-/**
- * A text box, meant to be used inside a scroll area. Same as the Guichan text
- * box except this one doesn't have a background or border, instead completely
- * relying on the scroll area.
- *
- * \ingroup GUI
- */
-class TextBox final : public Widget,
- public MouseListener,
- public KeyListener
-{
- public:
- /**
- * Constructor.
- */
- explicit TextBox(const Widget2 *const widget);
-
- A_DELETE_COPY(TextBox)
-
- ~TextBox();
-
- /**
- * Sets the text after wrapping it to the current width of the widget.
- */
- void setTextWrapped(const std::string &text, const int minDimension);
-
- /**
- * Get the minimum text width for the text box.
- */
- int getMinWidth() const noexcept2 A_WARN_UNUSED
- { return mMinWidth; }
-
- void keyPressed(KeyEvent& event) override final;
-
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void setForegroundColor(const Color &color);
-
- void setForegroundColorAll(const Color &color1,
- const Color &color2);
-
- /**
- * Sets the text of the text box.
- *
- * @param text The text of the text box.
- * @see getText
- */
- void setText(const std::string& text);
-
- /**
- * Gets the text of the text box.
- *
- * @return The text of the text box.
- * @see setText
- */
- std::string getText() const;
-
- /**
- * Gets a certain row from the text.
- *
- * @param row The number of the row to get from the text.
- * @return A row from the text of the text box.
- * @see setTextRow
- */
- const std::string& getTextRow(const int row) const
- { return mTextRows[row]; }
-
- /**
- * Sets the text of a certain row of the text.
- *
- * @param row The number of the row to set in the text.
- * @param text The text to set in the given row number.
- * @see getTextRow
- */
- void setTextRow(const int row, const std::string& text);
-
- /**
- * Gets the number of rows in the text.
- *
- * @return The number of rows in the text.
- */
- unsigned int getNumberOfRows() const
- { return CAST_S32(mTextRows.size()); }
-
- /**
- * Gets the caret position in the text.
- *
- * @return The caret position in the text.
- * @see setCaretPosition
- */
- unsigned int getCaretPosition() const;
-
- /**
- * Sets the position of the caret in the text.
- *
- * @param position the positon of the caret.
- * @see getCaretPosition
- */
- void setCaretPosition(unsigned int position);
-
- /**
- * Gets the row number where the caret is currently located.
- *
- * @return The row number where the caret is currently located.
- * @see setCaretRow
- */
- unsigned int getCaretRow() const
- { return mCaretRow; }
-
- /**
- * Sets the row where the caret should be currently located.
- *
- * @param The row where the caret should be currently located.
- * @see getCaretRow
- */
- void setCaretRow(const int row);
-
- /**
- * Gets the column where the caret is currently located.
- *
- * @return The column where the caret is currently located.
- * @see setCaretColumn
- */
- unsigned int getCaretColumn() const;
-
- /**
- * Sets the column where the caret should be currently located.
- *
- * @param The column where the caret should be currently located.
- * @see getCaretColumn
- */
- void setCaretColumn(const int column);
-
- /**
- * Sets the row and the column where the caret should be curretly
- * located.
- *
- * @param row The row where the caret should be currently located.
- * @param column The column where the caret should be currently located.
- * @see getCaretRow, getCaretColumn
- */
- void setCaretRowColumn(const int row, const int column);
-
- /**
- * Scrolls the text to the caret if the text box is in a scroll area.
- *
- * @see ScrollArea
- */
- void scrollToCaret();
-
- /**
- * Checks if the text box is editable.
- *
- * @return True it the text box is editable, false otherwise.
- * @see setEditable
- */
- bool isEditable() const
- { return mEditable; }
-
- /**
- * Sets the text box to be editable or not.
- *
- * @param editable True if the text box should be editable, false otherwise.
- */
- void setEditable(const bool editable)
- { mEditable = editable; }
-
- /**
- * Adds a row of text to the end of the text.
- *
- * @param row The row to add.
- */
- void addRow(const std::string &row);
-
- /**
- * Checks if the text box is opaque. An opaque text box will draw
- * it's background and it's text. A non opaque text box only draw it's
- * text making it transparent.
- *
- * @return True if the text box is opaque, false otherwise.
- * @see setOpaque
- */
- bool isOpaque() const noexcept2
- { return mOpaque == Opaque_true; }
-
- /**
- * Sets the text box to be opaque or not. An opaque text box will draw
- * it's background and it's text. A non opaque text box only draw it's
- * text making it transparent.
- *
- * @param opaque True if the text box should be opaque, false otherwise.
- * @see isOpaque
- */
- void setOpaque(const Opaque opaque) noexcept2
- { mOpaque = opaque; }
-
- void fontChanged() override final
- { adjustSize(); }
-
- void mousePressed(MouseEvent& event) override final;
-
- void mouseDragged(MouseEvent& event) override final;
-
- private:
- /**
- * Draws the caret. Overloaded this method if you want to
- * change the style of the caret.
- *
- * @param graphics a Graphics object to draw with.
- * @param x the x position.
- * @param y the y position.
- */
- void drawCaret(Graphics *const graphics,
- const int x,
- const int y) const A_NONNULL(2);
-
- /**
- * Adjusts the text box's size to fit the text.
- */
- void adjustSize();
-
- /**
- * Holds all the rows of the text.
- */
- STD_VECTOR<std::string> mTextRows;
-
- /**
- * Holds the current column of the caret.
- */
- int mCaretColumn;
-
- /**
- * Holds the current row of the caret.
- */
- int mCaretRow;
-
- int mMinWidth;
-
- /**
- * True if the text box is editable, false otherwise.
- */
- bool mEditable;
-
- /**
- * True if the text box is editable, false otherwise.
- */
- Opaque mOpaque;
-};
-
-#endif // GUI_WIDGETS_TEXTBOX_H
diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp
deleted file mode 100644
index e536b5b13..000000000
--- a/src/gui/widgets/textfield.cpp
+++ /dev/null
@@ -1,837 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/textfield.h"
-
-#include "settings.h"
-
-#ifdef USE_SDL2
-#include "enums/input/keyvalue.h"
-#endif // USE_SDL2
-
-#include "gui/gui.h"
-#include "gui/skin.h"
-#ifdef ANDROID
-#include "gui/windowmanager.h"
-#endif // ANDROID
-
-#include "gui/fonts/font.h"
-
-#include "gui/popups/popupmenu.h"
-
-#include "input/inputmanager.h"
-
-#include "utils/copynpaste.h"
-#include "utils/stringutils.h"
-
-#ifndef USE_SDL2
-#include "utils/timer.h"
-#endif // USE_SDL2
-
-#include "render/graphics.h"
-
-#include "resources/imagerect.h"
-
-#include "resources/image/image.h"
-
-#undef DELETE // Win32 compatibility hack
-
-#include "debug.h"
-
-Skin *TextField::mSkin;
-int TextField::instances = 0;
-float TextField::mAlpha = 1.0;
-ImageRect TextField::skin;
-
-TextField::TextField(const Widget2 *restrict const widget,
- const std::string &restrict text,
- const LoseFocusOnTab loseFocusOnTab,
- ActionListener *restrict const listener,
- const std::string &restrict eventId,
- const bool sendAlwaysEvents) :
- Widget(widget),
- FocusListener(),
- KeyListener(),
- MouseListener(),
- WidgetListener(),
- mText(text),
- mTextChunk(),
- mCaretPosition(0),
- mXScroll(0),
- mCaretColor(&getThemeColor(ThemeColorId::CARET)),
- mMinimum(0),
- mMaximum(0),
- mLastEventPaste(0),
- mPadding(1),
- mNumeric(false),
- mLoseFocusOnTab(loseFocusOnTab),
- mAllowSpecialActions(true),
- mSendAlwaysEvents(sendAlwaysEvents),
- mTextChanged(true)
-{
- mAllowLogic = false;
- setFocusable(true);
- addMouseListener(this);
- addKeyListener(this);
-
- setFrameSize(2);
- mForegroundColor = getThemeColor(ThemeColorId::TEXTFIELD);
- mForegroundColor2 = getThemeColor(ThemeColorId::TEXTFIELD_OUTLINE);
-
- addFocusListener(this);
-
- if (instances == 0)
- {
- if (theme != nullptr)
- {
- mSkin = theme->loadSkinRect(skin, "textfield.xml",
- "textfield_background.xml");
- }
- }
-
- instances++;
-
- if (mSkin != nullptr)
- {
- mPadding = mSkin->getPadding();
- mFrameSize = mSkin->getOption("frameSize", 2);
- }
-
- adjustSize();
- if (!eventId.empty())
- setActionEventId(eventId);
-
- if (listener != nullptr)
- addActionListener(listener);
-}
-
-TextField::~TextField()
-{
- if (mWindow != nullptr)
- mWindow->removeWidgetListener(this);
-
- if (gui != nullptr)
- gui->removeDragged(this);
-
- instances--;
- if (instances == 0)
- {
- if (theme != nullptr)
- {
- theme->unload(mSkin);
- Theme::unloadRect(skin);
- }
- }
- mTextChunk.deleteImage();
-}
-
-void TextField::updateAlpha()
-{
- const float alpha = std::max(settings.guiAlpha,
- theme->getMinimumOpacity());
-
- if (alpha != mAlpha)
- {
- mAlpha = alpha;
- for (int a = 0; a < 9; a++)
- {
- if (skin.grid[a] != nullptr)
- skin.grid[a]->setAlpha(mAlpha);
- }
- }
-}
-
-void TextField::draw(Graphics *const graphics)
-{
- BLOCK_START("TextField::draw")
- updateAlpha();
-
- Font *const font = getFont();
- if (isFocused())
- {
- drawCaret(graphics,
- font->getWidth(mText.substr(0, mCaretPosition)) - mXScroll);
- }
-
- if (mTextChanged)
- {
- mTextChunk.textFont = font;
- mTextChunk.deleteImage();
- mTextChunk.text = mText;
- mTextChunk.color = mForegroundColor;
- mTextChunk.color2 = mForegroundColor2;
- font->generate(mTextChunk);
- mTextChanged = false;
- }
-
- const Image *const image = mTextChunk.img;
- if (image != nullptr)
- graphics->drawImage(image, mPadding - mXScroll, mPadding);
-
- BLOCK_END("TextField::draw")
-}
-
-void TextField::safeDraw(Graphics *const graphics)
-{
- TextField::draw(graphics);
-}
-
-void TextField::drawFrame(Graphics *const graphics)
-{
- BLOCK_START("TextField::drawFrame")
- const int bs = 2 * mFrameSize;
- graphics->drawImageRect(0,
- 0,
- mDimension.width + bs,
- mDimension.height + bs,
- skin);
- BLOCK_END("TextField::drawFrame")
-}
-
-void TextField::safeDrawFrame(Graphics *const graphics)
-{
- BLOCK_START("TextField::drawFrame")
- const int bs = 2 * mFrameSize;
- graphics->drawImageRect(0,
- 0,
- mDimension.width + bs,
- mDimension.height + bs,
- skin);
- BLOCK_END("TextField::drawFrame")
-}
-
-void TextField::setNumeric(const bool numeric)
-{
- mNumeric = numeric;
- if (!numeric)
- return;
-
- const char *const text = mText.c_str();
- for (const char *textPtr = text; *textPtr != 0; ++textPtr)
- {
- if (*textPtr < '0' || *textPtr > '9')
- {
- setText(mText.substr(0, textPtr - text));
- return;
- }
- }
-}
-
-int TextField::getValue() const
-{
- if (!mNumeric)
- return 0;
-
- const int value = atoi(mText.c_str());
- if (value < mMinimum)
- return mMinimum;
-
- if (value > mMaximum)
- return mMaximum;
-
- return value;
-}
-
-void TextField::keyPressed(KeyEvent &event)
-{
- const int val = event.getKey().getValue();
-
-#ifdef USE_SDL2
- if (val == KeyValue::TEXTINPUT)
- {
- std::string str = event.getText();
- mText.insert(mCaretPosition, str);
- mTextChanged = true;
- mCaretPosition += CAST_U32(str.size());
- event.consume();
- fixScroll();
- if (mSendAlwaysEvents)
- distributeActionEvent();
- return;
- }
- bool consumed(false);
-#else // USE_SDL2
-
- if (val >= 32)
- {
- if (mNumeric)
- {
- if ((val >= '0' && val <= '9') ||
- (val == '-' && mCaretPosition == 0u))
- {
- char buf[2];
- buf[0] = CAST_8(val);
- buf[1] = 0;
- mText.insert(mCaretPosition, std::string(buf));
- mTextChanged = true;
- mCaretPosition += 1;
- event.consume();
- fixScroll();
- if (mSendAlwaysEvents)
- distributeActionEvent();
- return;
- }
- }
- else if ((mMaximum == 0) ||
- CAST_S32(mText.size()) < mMaximum)
- {
- int len;
- if (val < 128)
- len = 1; // 0xxxxxxx
- else if (val < 0x800)
- len = 2; // 110xxxxx 10xxxxxx
- else if (val < 0x10000)
- len = 3; // 1110xxxx 10xxxxxx 10xxxxxx
- else
- len = 4; // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
-
- char buf[4];
- for (int i = 0; i < len; ++ i)
- {
- buf[i] = CAST_8(val >> (6 * (len - i - 1)));
- if (i > 0)
- buf[i] = CAST_8((buf[i] & 63) | 128);
- }
-
- if (len > 1)
- buf[0] |= CAST_8(255U << (8 - len));
-
- mText.insert(mCaretPosition, std::string(buf, buf + len));
- mCaretPosition += len;
- mTextChanged = true;
- event.consume();
- fixScroll();
- if (mSendAlwaysEvents)
- distributeActionEvent();
- return;
- }
- }
-
- /* In UTF-8, 10xxxxxx is only used for inner parts of characters. So skip
- them when processing key presses. */
-
- // unblock past key
- if (val != 22)
- mLastEventPaste = 0;
-
- bool consumed(false);
-#endif // USE_SDL2
-
- const InputActionT action = event.getActionId();
- if (!inputManager.isActionActive(InputAction::GUI_CTRL))
- {
- if (!handleNormalKeys(action, consumed))
- {
- if (consumed)
- event.consume();
- return;
- }
- }
- else
- {
- handleCtrlKeys(action, consumed);
- }
-
- if (mSendAlwaysEvents)
- distributeActionEvent();
-
- if (consumed)
- event.consume();
- fixScroll();
-}
-
-bool TextField::handleNormalKeys(const InputActionT action, bool &consumed)
-{
- PRAGMA45(GCC diagnostic push)
- PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
- switch (action)
- {
- case InputAction::GUI_LEFT:
- {
- consumed = true;
- while (mCaretPosition > 0)
- {
- --mCaretPosition;
- if ((mText[mCaretPosition] & 192) != 128)
- break;
- }
- break;
- }
-
- case InputAction::GUI_RIGHT:
- {
- consumed = true;
- const unsigned sz = CAST_U32(mText.size());
- while (mCaretPosition < sz)
- {
- ++mCaretPosition;
- if (mCaretPosition == sz ||
- (mText[mCaretPosition] & 192) != 128)
- {
- break;
- }
- }
- break;
- }
-
- case InputAction::GUI_DELETE:
- {
- consumed = true;
- unsigned sz = CAST_U32(mText.size());
- while (mCaretPosition < sz)
- {
- --sz;
- mText.erase(mCaretPosition, 1);
- mTextChanged = true;
- if (mCaretPosition == sz ||
- (mText[mCaretPosition] & 192) != 128)
- {
- break;
- }
- }
- break;
- }
-
- case InputAction::GUI_BACKSPACE:
- consumed = true;
- deleteCharLeft(mText, &mCaretPosition);
- mTextChanged = true;
- break;
-
- case InputAction::GUI_SELECT2:
- distributeActionEvent();
- consumed = true;
- fixScroll();
- return false;
-
- case InputAction::GUI_HOME:
- mCaretPosition = 0;
- consumed = true;
- break;
-
- case InputAction::GUI_END:
- mCaretPosition = CAST_U32(mText.size());
- consumed = true;
- break;
-
- case InputAction::GUI_TAB:
- if (mLoseFocusOnTab == LoseFocusOnTab_true)
- return false;
- consumed = true;
- break;
-
- default:
- break;
- }
- PRAGMA45(GCC diagnostic pop)
- return true;
-}
-
-void TextField::handleCtrlKeys(const InputActionT action, bool &consumed)
-{
- PRAGMA45(GCC diagnostic push)
- PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
- switch (action)
- {
- case InputAction::GUI_LEFT:
- {
- moveCaretWordBack();
- consumed = true;
- break;
- }
- case InputAction::GUI_RIGHT:
- {
- moveCaretWordForward();
- consumed = true;
- break;
- }
- case InputAction::GUI_B:
- {
- if (mAllowSpecialActions)
- {
- moveCaretBack();
- consumed = true;
- }
- break;
- }
- case InputAction::GUI_F:
- {
- moveCaretForward();
- consumed = true;
- break;
- }
- case InputAction::GUI_D:
- {
- caretDelete();
- consumed = true;
- break;
- }
- case InputAction::GUI_E:
- {
- mCaretPosition = CAST_S32(mText.size());
- consumed = true;
- break;
- }
- case InputAction::GUI_H:
- {
- deleteCharLeft(mText, &mCaretPosition);
- mTextChanged = true;
- consumed = true;
- break;
- }
- case InputAction::GUI_K:
- {
- mText = mText.substr(0, mCaretPosition);
- mTextChanged = true;
- consumed = true;
- break;
- }
- case InputAction::GUI_U:
- {
- caretDeleteToStart();
- consumed = true;
- break;
- }
- case InputAction::GUI_C:
- {
- handleCopy();
- consumed = true;
- break;
- }
- case InputAction::GUI_V:
- {
-#ifdef USE_SDL2
- handlePaste();
-#else // USE_SDL2
-
- // hack to prevent paste key sticking
- if ((mLastEventPaste != 0) && mLastEventPaste > cur_time)
- break;
- handlePaste();
- mLastEventPaste = cur_time + 2;
-#endif // USE_SDL2
-
- consumed = true;
- break;
- }
- case InputAction::GUI_W:
- {
- caretDeleteWord();
- consumed = true;
- break;
- }
- default:
- break;
- }
- PRAGMA45(GCC diagnostic pop)
-}
-
-void TextField::moveCaretBack()
-{
- while (mCaretPosition > 0)
- {
- --mCaretPosition;
- if ((mText[mCaretPosition] & 192) != 128)
- break;
- }
-}
-
-void TextField::moveCaretForward()
-{
- const unsigned sz = CAST_U32(mText.size());
- while (mCaretPosition < sz)
- {
- ++mCaretPosition;
- if (mCaretPosition == sz || (mText[mCaretPosition] & 192) != 128)
- break;
- }
-}
-
-void TextField::caretDelete()
-{
- unsigned sz = CAST_U32(mText.size());
- while (mCaretPosition < sz)
- {
- --sz;
- mText.erase(mCaretPosition, 1);
- if (mCaretPosition == sz || (mText[mCaretPosition] & 192) != 128)
- break;
- }
- mTextChanged = true;
-}
-
-void TextField::handlePaste()
-{
- std::string text = getText();
- size_t caretPos = CAST_SIZE(getCaretPosition());
-
- if (retrieveBuffer(text, caretPos))
- {
- setText(text);
- setCaretPosition(CAST_U32(caretPos));
- }
-}
-
-void TextField::caretDeleteToStart()
-{
- if (mCaretPosition > 0)
- {
- mText = mText.substr(mCaretPosition);
- mCaretPosition = 0;
- }
- mTextChanged = true;
-}
-
-void TextField::moveCaretWordBack()
-{
- const unsigned int oldCaret = mCaretPosition;
- while (mCaretPosition > 0)
- {
- if (!isWordSeparator(mText[mCaretPosition - 1]))
- break;
- mCaretPosition --;
- }
- if (oldCaret != mCaretPosition)
- return;
- while (mCaretPosition > 0)
- {
- if (isWordSeparator(mText[mCaretPosition - 1]))
- break;
- mCaretPosition --;
- }
-}
-
-void TextField::moveCaretWordForward()
-{
- const unsigned sz = CAST_U32(mText.size());
- const unsigned int oldCaret = mCaretPosition;
- while (mCaretPosition < sz)
- {
- if (!isWordSeparator(mText[mCaretPosition]))
- break;
- mCaretPosition ++;
- }
- if (oldCaret != mCaretPosition)
- return;
- while (mCaretPosition < sz)
- {
- if (isWordSeparator(mText[mCaretPosition]))
- break;
- mCaretPosition ++;
- }
-}
-
-void TextField::caretDeleteWord()
-{
- while (mCaretPosition > 0)
- {
- deleteCharLeft(mText, &mCaretPosition);
- if (mCaretPosition > 0 && isWordSeparator(mText[mCaretPosition - 1]))
- break;
- }
- mTextChanged = true;
-}
-
-void TextField::handleCopy() const
-{
- std::string text = getText();
- sendBuffer(text);
-}
-
-void TextField::drawCaret(Graphics* graphics, int x)
-{
- const ClipRect &clipArea = graphics->getTopClip();
-
- graphics->setColor(*mCaretColor);
- graphics->drawLine(x + mPadding, clipArea.height - mPadding,
- x + mPadding, mPadding);
-}
-
-void TextField::adjustSize()
-{
- setWidth(getFont()->getWidth(mText) + 2 * mPadding + 1);
- adjustHeight();
-
- fixScroll();
-}
-
-void TextField::adjustHeight()
-{
- setHeight(getFont()->getHeight() + 2 * mPadding);
-}
-
-void TextField::fixScroll()
-{
- if (isFocused())
- {
- const int caretX = getFont()->getWidth(
- mText.substr(0, mCaretPosition));
-
- const int width = mDimension.width;
- const int pad = 2 * mPadding;
- if (caretX - mXScroll >= width - pad)
- {
- mXScroll = caretX - width + pad;
- }
- else if (caretX - mXScroll <= 0)
- {
- mXScroll = caretX - width / 2;
-
- if (mXScroll < 0)
- mXScroll = 0;
- }
- }
-}
-
-void TextField::setCaretPosition(unsigned int position)
-{
- const unsigned int sz = CAST_U32(mText.size());
- if (position > sz)
- mCaretPosition = CAST_S32(sz);
- else
- mCaretPosition = position;
-
- fixScroll();
-}
-
-void TextField::fontChanged()
-{
- fixScroll();
-}
-
-void TextField::mousePressed(MouseEvent &event)
-{
-#ifdef ANDROID
- if (!WindowManager::isKeyboardVisible())
- inputManager.executeAction(InputAction::SHOW_KEYBOARD);
-#endif // ANDROID
-
- event.consume();
- if (event.getButton() == MouseButton::RIGHT)
- {
-#ifndef DYECMD
- if (popupMenu != nullptr)
- popupMenu->showTextFieldPopup(this);
-#endif // DYECMD
- }
- else if (event.getButton() == MouseButton::LEFT)
- {
- mCaretPosition = getFont()->getStringIndexAt(
- mText, event.getX() + mXScroll);
- fixScroll();
- }
-}
-
-void TextField::focusGained(const Event &event A_UNUSED)
-{
-#ifdef ANDROID
- if (!WindowManager::isKeyboardVisible())
- inputManager.executeAction(InputAction::SHOW_KEYBOARD);
-#endif // ANDROID
-}
-
-void TextField::focusLost(const Event &event A_UNUSED)
-{
-}
-
-void TextField::setText(const std::string& text)
-{
- const unsigned int sz = CAST_U32(text.size());
- if (sz < mCaretPosition)
- mCaretPosition = sz;
- mText = text;
- mTextChanged = true;
-}
-
-void TextField::mouseDragged(MouseEvent& event)
-{
- event.consume();
-}
-
-void TextField::widgetHidden(const Event &event A_UNUSED)
-{
- mTextChanged = true;
- mTextChunk.deleteImage();
-}
-
-void TextField::setParent(Widget *widget)
-{
- if (mWindow != nullptr)
- mWindow->addWidgetListener(this);
- Widget::setParent(widget);
-}
-
-void TextField::setWindow(Widget *const widget)
-{
- if ((widget == nullptr) && (mWindow != nullptr))
- {
- mWindow->removeWidgetListener(this);
- mWindow = nullptr;
- }
- else
- {
- Widget2::setWindow(widget);
- }
-}
diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h
deleted file mode 100644
index 8001008a1..000000000
--- a/src/gui/widgets/textfield.h
+++ /dev/null
@@ -1,293 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_TEXTFIELD_H
-#define GUI_WIDGETS_TEXTFIELD_H
-
-#include "listeners/focuslistener.h"
-#include "listeners/keylistener.h"
-#include "listeners/mouselistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "enums/simpletypes/losefocusontab.h"
-
-#include "gui/fonts/textchunk.h"
-
-#include "gui/widgets/widget.h"
-
-#include "localconsts.h"
-
-/**
- * A text field.
- *
- * \ingroup GUI
- */
-class TextField notfinal : public Widget,
- public FocusListener,
- public KeyListener,
- public MouseListener,
- public WidgetListener
-{
- public:
- /**
- * Constructor, initializes the text field with the given string.
- */
- explicit TextField(const Widget2 *restrict const widget,
- const std::string &restrict text = "",
- const LoseFocusOnTab loseFocusOnTab =
- LoseFocusOnTab_true,
- ActionListener *restrict
- const listener = nullptr,
- const std::string &restrict eventId = "",
- const bool sendAlwaysEvents = false);
-
- A_DELETE_COPY(TextField)
-
- virtual ~TextField();
-
- /**
- * Draws the text field.
- */
- void draw(Graphics *const graphics) override A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override A_NONNULL(2);
-
- /**
- * Update the alpha value to the graphic components.
- */
- void updateAlpha();
-
- /**
- * Draws the background and border.
- */
- void drawFrame(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDrawFrame(Graphics *const graphics) override final
- A_NONNULL(2);
-
- /**
- * Determine whether the field should be numeric or not
- */
- void setNumeric(const bool numeric);
-
- /**
- * Set the range on the field if it is numeric
- */
- void setRange(const int min,
- const int max)
- {
- mMinimum = min;
- mMaximum = max;
- }
-
- /**
- * Processes one keypress.
- */
- void keyPressed(KeyEvent &event) override;
-
- /**
- * Set the minimum value for a range
- */
- void setMinimum(const int min)
- { mMinimum = min; }
-
- /**
- * Set the maximum value for a range
- */
- void setMaximum(const int max)
- { mMaximum = max; }
-
- /**
- * Return the value for a numeric field
- */
- int getValue() const A_WARN_UNUSED;
-
- void setSendAlwaysEvents(const bool b) noexcept2
- { mSendAlwaysEvents = b; }
-
- void adjustSize();
-
- void adjustHeight();
-
- void setCaretPosition(unsigned int position);
-
- void mousePressed(MouseEvent &event) override final;
-
- void handlePaste();
-
- void handleCopy() const;
-
-#ifdef ANDROID
- void focusGained(const Event &event) override final;
-#else // ANDROID
-
- void focusGained(const Event &event) override final A_CONST;
-#endif // ANDROID
-
- void focusLost(const Event &event) override A_CONST;
-
- void moveCaretBack();
-
- void moveCaretForward();
-
- void moveCaretWordBack();
-
- void moveCaretWordForward();
-
- void caretDelete();
-
- void caretDeleteToStart();
-
- void caretDeleteWord();
-
- void setAllowSpecialActions(const bool b)
- { mAllowSpecialActions = b; }
-
- std::string getTextBeforeCaret() const
- { return mText.substr(0, mCaretPosition); }
-
- /**
- * Sets the text of the text field.
- *
- * @param text The text of the text field.
- * @see getText
- */
- void setText(const std::string& text);
-
- /**
- * Gets the text of the text field.
- *
- * @return The text of the text field.
- * @see setText
- */
- const std::string& getText() const
- { return mText; }
-
- /**
- * Gets the caret position. As there is only one line of text
- * in a text field the position is the caret's x coordinate.
- *
- * @return The caret position.
- * @see setCaretPosition
- */
- unsigned int getCaretPosition() const
- { return mCaretPosition; }
-
- void mouseDragged(MouseEvent& event) override final;
-
- void widgetHidden(const Event &event) override final;
-
- void setParent(Widget *widget) override final;
-
- void setWindow(Widget *const widget) override final;
-
- protected:
- void drawCaret(Graphics* graphics, int x) A_NONNULL(2);
-
- void fixScroll();
-
- void fontChanged() override;
-
- bool handleNormalKeys(const InputActionT action, bool &consumed);
-
- void handleCtrlKeys(const InputActionT action, bool &consumed);
-
- static Skin *mSkin;
-
- /**
- * Holds the text of the text box.
- */
- std::string mText;
-
- TextChunk mTextChunk;
-
- /**
- * Holds the caret position.
- */
- unsigned int mCaretPosition;
-
- /**
- * Holds the amount scrolled in x. If a user types more characters than
- * the text field can display, due to the text field being to small, the
- * text needs to scroll in order to show the last type character.
- */
- int mXScroll;
-
- const Color *mCaretColor;
- static int instances;
- static float mAlpha;
- static ImageRect skin;
- int mMinimum;
- int mMaximum;
- time_t mLastEventPaste;
- int mPadding;
- bool mNumeric;
- LoseFocusOnTab mLoseFocusOnTab;
- bool mAllowSpecialActions;
- bool mSendAlwaysEvents;
- bool mTextChanged;
-};
-
-#endif // GUI_WIDGETS_TEXTFIELD_H
diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp
deleted file mode 100644
index 53f84badc..000000000
--- a/src/gui/widgets/textpreview.cpp
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2006-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/textpreview.h"
-
-#include "settings.h"
-
-#include "gui/gui.h"
-#include "gui/skin.h"
-
-#include "gui/fonts/font.h"
-
-#include "render/graphics.h"
-
-#include "debug.h"
-
-int TextPreview::instances = 0;
-float TextPreview::mAlpha = 1.0;
-Skin *TextPreview::mSkin = nullptr;
-
-TextPreview::TextPreview(const Widget2 *const widget,
- const std::string &text) :
- Widget(widget),
- mFont(gui->getFont()),
- mText(text),
- mTextColor(&getThemeColor(ThemeColorId::TEXT)),
- mTextColor2(&getThemeColor(ThemeColorId::TEXT_OUTLINE)),
- mBGColor(&getThemeColor(ThemeColorId::BACKGROUND)),
- mTextBGColor(nullptr),
- mPadding(0),
- mTextAlpha(false),
- mOpaque(Opaque_false),
- mShadow(false),
- mOutline(false)
-{
- mAllowLogic = false;
- if (instances == 0)
- {
- if (theme != nullptr)
- mSkin = theme->load("textpreview.xml", "");
- }
-
- instances++;
-
- if (mSkin != nullptr)
- mPadding = mSkin->getOption("padding", 0);
-
- adjustSize();
-}
-
-TextPreview::~TextPreview()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- instances--;
-
- if (instances == 0)
- {
- if (theme != nullptr)
- theme->unload(mSkin);
- }
-}
-
-void TextPreview::draw(Graphics *const graphics)
-{
- if (mFont == nullptr)
- return;
-
- BLOCK_START("TextPreview::draw")
- if (settings.guiAlpha != mAlpha)
- mAlpha = settings.guiAlpha;
-
- const int intAlpha = CAST_S32(mAlpha * 255.0F);
- const int alpha = mTextAlpha ? intAlpha : 255;
-
- if (mOpaque == Opaque_true)
- {
- graphics->setColor(Color(CAST_S32(mBGColor->r),
- CAST_S32(mBGColor->g),
- CAST_S32(mBGColor->b),
- CAST_S32(mAlpha * 255.0F)));
- graphics->fillRectangle(Rect(0, 0,
- mDimension.width, mDimension.height));
- }
-
- if (mTextBGColor != nullptr)
- {
- const int x = mFont->getWidth(mText) + 1
- + 2 * ((mOutline || mShadow) ? 1 :0);
- const int y = mFont->getHeight() + 1
- + 2 * ((mOutline || mShadow) ? 1 : 0);
- graphics->setColor(Color(CAST_S32(mTextBGColor->r),
- CAST_S32(mTextBGColor->g),
- CAST_S32(mTextBGColor->b),
- intAlpha));
- graphics->fillRectangle(Rect(mPadding, mPadding, x, y));
- }
-
- Color color1(mTextColor->r, mTextColor->g, mTextColor->b, alpha);
-
- if (mOutline && mTextColor != mTextColor2)
- {
- const Color &color2 = getThemeColor(ThemeColorId::OUTLINE, 255);
- mFont->drawString(graphics,
- color1,
- color2,
- mText,
- mPadding + 1, mPadding + 1);
- }
- else
- {
- Color color2(mTextColor2->r, mTextColor2->g, mTextColor2->b, alpha);
- mFont->drawString(graphics,
- color1,
- color2,
- mText,
- mPadding + 1, mPadding + 1);
- }
-
- BLOCK_END("TextPreview::draw")
-}
-
-void TextPreview::safeDraw(Graphics *const graphics)
-{
- TextPreview::draw(graphics);
-}
-
-void TextPreview::adjustSize()
-{
- setHeight(getFont()->getHeight() + 2 * mPadding);
-}
diff --git a/src/gui/widgets/textpreview.h b/src/gui/widgets/textpreview.h
deleted file mode 100644
index 7f4a5e873..000000000
--- a/src/gui/widgets/textpreview.h
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2006-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TEXTPREVIEW_H
-#define GUI_WIDGETS_TEXTPREVIEW_H
-
-#include "gui/widgets/widget.h"
-
-#include "enums/simpletypes/opaque.h"
-
-#include "localconsts.h"
-
-/**
- * Preview widget for particle colors, etc.
- */
-class TextPreview final : public Widget
-{
- public:
- TextPreview(const Widget2 *const widget,
- const std::string &text);
-
- A_DELETE_COPY(TextPreview)
-
- ~TextPreview();
-
- inline void setTextColor(const Color *color)
- { mTextColor = color; adjustSize(); }
-
- inline void setTextColor2(const Color *color)
- { mTextColor2 = color; adjustSize(); }
-
- /**
- * Sets the text to use the set alpha value.
- *
- * @param alpha whether to use alpha values for the text or not
- */
- inline void useTextAlpha(const bool alpha)
- { mTextAlpha = alpha; }
-
- /**
- * Sets the color the text background is drawn in. This is only the
- * rectangle directly behind the text, not to full widget.
- *
- * @param color the color to set
- */
- inline void setTextBGColor(const Color *color)
- { mTextBGColor = color; }
-
- /**
- * Sets the background color of the widget.
- *
- * @param color the color to set
- */
- inline void setBGColor(const Color *color)
- { mBGColor = color; }
-
- /**
- * Sets the font to render the text in.
- *
- * @param font the font to use.
- */
- inline void setFont(Font *const font)
- { mFont = font; }
-
- /**
- * Sets whether to use a shadow while rendering.
- *
- * @param shadow true, if a shadow is wanted, false else
- */
- inline void setShadow(const bool shadow)
- { mShadow = shadow; }
-
- /**
- * Sets whether to use an outline while rendering.
- *
- * @param outline true, if an outline is wanted, false else
- */
- inline void setOutline(const bool outline)
- { mOutline = outline; }
-
- /**
- * Widget's draw method. Does the actual job.
- *
- * @param graphics graphics to draw into
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Set opacity for this widget (whether or not to show the background
- * color)
- *
- * @param opaque Whether the widget should be opaque or not
- */
- void setOpaque(const Opaque opaque) noexcept2
- { mOpaque = opaque; }
-
- /**
- * Gets opacity for this widget (whether or not the background color
- * is shown below the widget)
- */
- bool isOpaque() const noexcept2 A_WARN_UNUSED
- { return mOpaque == Opaque_true; }
-
- void adjustSize();
-
- private:
- Font *mFont;
- std::string mText;
- const Color *mTextColor;
- const Color *mTextColor2;
- const Color *mBGColor;
- const Color *mTextBGColor;
- int mPadding;
- static int instances;
- static float mAlpha;
- static Skin *mSkin;
- bool mTextAlpha;
- Opaque mOpaque;
- bool mShadow;
- bool mOutline;
-};
-
-#endif // GUI_WIDGETS_TEXTPREVIEW_H
diff --git a/src/gui/widgets/vertcontainer.cpp b/src/gui/widgets/vertcontainer.cpp
deleted file mode 100644
index 53e082501..000000000
--- a/src/gui/widgets/vertcontainer.cpp
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/vertcontainer.h"
-
-#include "utils/foreach.h"
-
-#include "debug.h"
-
-VertContainer::VertContainer(const Widget2 *const widget,
- const int verticalItemSize,
- const bool resizable,
- const int leftSpacing) :
- Container(widget),
- WidgetListener(),
- mResizableWidgets(),
- mVerticalItemSize(verticalItemSize),
- mCount(0),
- mNextY(0),
- mLeftSpacing(leftSpacing),
- mVerticalSpacing(0),
- mResizable(resizable)
-{
- addWidgetListener(this);
-}
-
-void VertContainer::add1(Widget *const widget, const int spacing)
-{
- add2(widget, mResizable, spacing);
-}
-
-void VertContainer::add2(Widget *const widget, const bool resizable,
- const int spacing)
-{
- if (widget == nullptr)
- return;
-
- Container::add(widget);
- widget->setPosition(mLeftSpacing, mNextY);
- if (resizable)
- {
- widget->setSize(mDimension.width - mLeftSpacing,
- mVerticalItemSize * 5);
- mResizableWidgets.push_back(widget);
- }
- else if (widget->getHeight() > mVerticalItemSize)
- {
- widget->setSize(widget->getWidth(), mVerticalItemSize);
- }
-
- if (spacing == -1)
- mNextY += mVerticalItemSize + (mVerticalSpacing * 2);
- else
- mNextY += mVerticalItemSize + (spacing * 2);
- setHeight(mNextY);
-}
-
-void VertContainer::clear()
-{
- Container::clear();
-
- mCount = 0;
- mNextY = 0;
- mResizableWidgets.clear();
-}
-
-void VertContainer::widgetResized(const Event &event A_UNUSED)
-{
- FOR_EACH (STD_VECTOR<Widget*>::const_iterator, it, mResizableWidgets)
- (*it)->setWidth(getWidth());
-}
diff --git a/src/gui/widgets/vertcontainer.h b/src/gui/widgets/vertcontainer.h
deleted file mode 100644
index c0dd118cf..000000000
--- a/src/gui/widgets/vertcontainer.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_VERTCONTAINER_H
-#define GUI_WIDGETS_VERTCONTAINER_H
-
-#include "gui/widgets/container.h"
-
-#include "listeners/widgetlistener.h"
-
-#include "localconsts.h"
-
-/**
- * A widget container.
- *
- * This container places it's contents veritcally.
- */
-class VertContainer final : public Container,
- public WidgetListener
-{
- public:
- VertContainer(const Widget2 *const widget,
- const int verticalItemSize,
- const bool resizable = true,
- const int leftSpacing = 0);
-
- A_DELETE_COPY(VertContainer)
-
- void add2(Widget *const widget, const bool resizable,
- const int spacing = -1);
-
- void add1(Widget *const widget, const int spacing = -1);
-
- void clear() override final;
-
- void widgetResized(const Event &event) override final;
-
- private:
- STD_VECTOR<Widget*> mResizableWidgets;
- int mVerticalItemSize;
- int mCount;
- int mNextY;
- int mLeftSpacing;
- int mVerticalSpacing;
- bool mResizable;
-};
-
-#endif // GUI_WIDGETS_VERTCONTAINER_H
diff --git a/src/gui/widgets/virtshortcutcontainer.cpp b/src/gui/widgets/virtshortcutcontainer.cpp
deleted file mode 100644
index 6b7642a3d..000000000
--- a/src/gui/widgets/virtshortcutcontainer.cpp
+++ /dev/null
@@ -1,383 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/virtshortcutcontainer.h"
-
-#include "dragdrop.h"
-#include "settings.h"
-
-#include "being/playerinfo.h"
-
-#include "gui/viewport.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/shortcut/shortcutbase.h"
-
-#include "gui/popups/itempopup.h"
-#include "gui/popups/popupmenu.h"
-
-#include "gui/windows/inventorywindow.h"
-
-#include "utils/stringutils.h"
-
-#include "debug.h"
-
-VirtShortcutContainer::VirtShortcutContainer(Widget2 *const widget,
- ShortcutBase *const shortcut) :
- ShortcutContainer(widget),
- mItemClicked(false),
- mEquipedColor(getThemeColor(ThemeColorId::ITEM_EQUIPPED)),
- mEquipedColor2(getThemeColor(ThemeColorId::ITEM_EQUIPPED_OUTLINE)),
- mUnEquipedColor(getThemeColor(ThemeColorId::ITEM_NOT_EQUIPPED)),
- mUnEquipedColor2(getThemeColor(ThemeColorId::ITEM_NOT_EQUIPPED_OUTLINE)),
- mShortcut(shortcut)
-{
- if (mShortcut != nullptr)
- mMaxItems = mShortcut->getItemCount();
- else
- mMaxItems = 0;
-}
-
-VirtShortcutContainer::~VirtShortcutContainer()
-{
-}
-
-void VirtShortcutContainer::setWidget2(const Widget2 *const widget)
-{
- Widget2::setWidget2(widget);
- mEquipedColor = getThemeColor(ThemeColorId::ITEM_EQUIPPED);
- mEquipedColor2 = getThemeColor(ThemeColorId::ITEM_EQUIPPED_OUTLINE);
- mUnEquipedColor = getThemeColor(ThemeColorId::ITEM_NOT_EQUIPPED);
- mUnEquipedColor2 = getThemeColor(ThemeColorId::ITEM_NOT_EQUIPPED_OUTLINE);
-}
-
-void VirtShortcutContainer::draw(Graphics *const graphics)
-{
- if (mShortcut == nullptr)
- return;
-
- BLOCK_START("VirtShortcutContainer::draw")
- if (settings.guiAlpha != mAlpha)
- {
- mAlpha = settings.guiAlpha;
- if (mBackgroundImg != nullptr)
- mBackgroundImg->setAlpha(mAlpha);
- }
-
- drawBackground(graphics);
-
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- {
- BLOCK_END("VirtShortcutContainer::draw")
- return;
- }
-
- Font *const font = getFont();
-
- for (unsigned i = 0; i < mMaxItems; i++)
- {
- const int itemX = (i % mGridWidth) * mBoxWidth;
- const int itemY = (i / mGridWidth) * mBoxHeight;
-
- if (mShortcut->getItem(i) < 0)
- continue;
-
- const Item *const item = inv->findItem(mShortcut->getItem(i),
- mShortcut->getItemColor(i));
-
- if (item != nullptr)
- {
- // Draw item icon.
- Image *const image = item->getImage();
-
- if (image != nullptr)
- {
- std::string caption;
- if (item->getQuantity() > 1)
- caption = toString(item->getQuantity());
- else if (item->isEquipped() == Equipped_true)
- caption = "Eq.";
-
- image->setAlpha(1.0F);
- graphics->drawImage(image, itemX, itemY);
- if (item->isEquipped() == Equipped_true)
- {
- font->drawString(graphics,
- mEquipedColor,
- mEquipedColor2,
- caption,
- itemX + (mBoxWidth - font->getWidth(caption)) / 2,
- itemY + mBoxHeight - 14);
- }
- else
- {
- font->drawString(graphics,
- mUnEquipedColor,
- mUnEquipedColor2,
- caption,
- itemX + (mBoxWidth - font->getWidth(caption)) / 2,
- itemY + mBoxHeight - 14);
- }
- }
- }
- }
- BLOCK_END("VirtShortcutContainer::draw")
-}
-
-void VirtShortcutContainer::safeDraw(Graphics *const graphics)
-{
- if (mShortcut == nullptr)
- return;
-
- BLOCK_START("VirtShortcutContainer::safeDraw")
- if (settings.guiAlpha != mAlpha)
- {
- mAlpha = settings.guiAlpha;
- if (mBackgroundImg != nullptr)
- mBackgroundImg->setAlpha(mAlpha);
- }
-
- safeDrawBackground(graphics);
-
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- {
- BLOCK_END("VirtShortcutContainer::safeDraw")
- return;
- }
-
- Font *const font = getFont();
-
- for (unsigned i = 0; i < mMaxItems; i++)
- {
- const int itemX = (i % mGridWidth) * mBoxWidth;
- const int itemY = (i / mGridWidth) * mBoxHeight;
-
- if (mShortcut->getItem(i) < 0)
- continue;
-
- const Item *const item = inv->findItem(mShortcut->getItem(i),
- mShortcut->getItemColor(i));
-
- if (item != nullptr)
- {
- // Draw item icon.
- Image *const image = item->getImage();
-
- if (image != nullptr)
- {
- std::string caption;
- if (item->getQuantity() > 1)
- caption = toString(item->getQuantity());
- else if (item->isEquipped() == Equipped_true)
- caption = "Eq.";
-
- image->setAlpha(1.0F);
- graphics->drawImage(image, itemX, itemY);
- if (item->isEquipped() == Equipped_true)
- {
- font->drawString(graphics,
- mEquipedColor,
- mEquipedColor2,
- caption,
- itemX + (mBoxWidth - font->getWidth(caption)) / 2,
- itemY + mBoxHeight - 14);
- }
- else
- {
- font->drawString(graphics,
- mUnEquipedColor,
- mUnEquipedColor2,
- caption,
- itemX + (mBoxWidth - font->getWidth(caption)) / 2,
- itemY + mBoxHeight - 14);
- }
- }
- }
- }
- BLOCK_END("VirtShortcutContainer::safeDraw")
-}
-
-void VirtShortcutContainer::mouseDragged(MouseEvent &event)
-{
- if (mShortcut == nullptr)
- return;
-
- if (event.getButton() == MouseButton::LEFT)
- {
- if (dragDrop.isEmpty() && mItemClicked)
- {
- const int index = getIndexFromGrid(event.getX(), event.getY());
-
- if (index == -1)
- return;
-
- const int itemId = mShortcut->getItem(index);
- const ItemColor itemColor = mShortcut->getItemColor(index);
-
- if (itemId < 0)
- return;
-
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- return;
-
- Item *const item = inv->findItem(itemId, itemColor);
-
- if (item != nullptr)
- {
- dragDrop.dragItem(item, DragDropSource::Drop);
- mShortcut->removeItem(index);
- }
- else
- {
- dragDrop.clear();
- }
- }
- }
-}
-
-void VirtShortcutContainer::mousePressed(MouseEvent &event)
-{
- if ((mShortcut == nullptr) || (inventoryWindow == nullptr))
- return;
-
- const int index = getIndexFromGrid(event.getX(), event.getY());
-
- if (index == -1)
- return;
-
- event.consume();
-
- const MouseButtonT eventButton = event.getButton();
- if (eventButton == MouseButton::LEFT)
- {
- if (mShortcut->getItem(index) > 0)
- {
- mItemClicked = true;
- }
- else
- {
- if (dragDrop.isSelected())
- {
- mShortcut->setItems(index, dragDrop.getSelected(),
- dragDrop.getSelectedColor());
- dragDrop.deselect();
- }
- }
- }
- else if (eventButton == MouseButton::RIGHT)
- {
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- return;
-
- Item *const item = inv->findItem(mShortcut->getItem(index),
- mShortcut->getItemColor(index));
-
- if (popupMenu != nullptr)
- {
- popupMenu->showDropPopup(viewport->mMouseX,
- viewport->mMouseY,
- item);
- }
- }
-}
-
-void VirtShortcutContainer::mouseReleased(MouseEvent &event)
-{
- if (mShortcut == nullptr)
- return;
-
- if (event.getButton() == MouseButton::LEFT)
- {
- if (mShortcut->isItemSelected())
- mShortcut->setItemSelected(-1);
-
- const int index = getIndexFromGrid(event.getX(), event.getY());
- if (index == -1)
- {
- dragDrop.clear();
- return;
- }
- if (!dragDrop.isEmpty())
- {
- if (dragDrop.isSourceItemContainer())
- {
- mShortcut->setItems(index, dragDrop.getItem(),
- dragDrop.getItemColor());
- dragDrop.clear();
- dragDrop.deselect();
- }
- }
-
- mItemClicked = false;
- }
-}
-
-// Show ItemTooltip
-void VirtShortcutContainer::mouseMoved(MouseEvent &event)
-{
- if (mShortcut == nullptr)
- return;
-
- const int index = getIndexFromGrid(event.getX(), event.getY());
-
- if (index == -1)
- return;
-
- const int itemId = mShortcut->getItem(index);
- const ItemColor itemColor = mShortcut->getItemColor(index);
-
- if (itemId < 0)
- return;
-
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- return;
-
- const Item *const item = inv->findItem(itemId, itemColor);
-
- if ((item != nullptr) && (viewport != nullptr))
- {
- itemPopup->setItem(item, false);
- itemPopup->position(viewport->mMouseX, viewport->mMouseY);
- }
- else
- {
- itemPopup->setVisible(Visible_false);
- }
-}
-
-void VirtShortcutContainer::mouseExited(MouseEvent &event A_UNUSED)
-{
- if (itemPopup != nullptr)
- itemPopup->setVisible(Visible_false);
-}
-
-void VirtShortcutContainer::widgetHidden(const Event &event A_UNUSED)
-{
- if (itemPopup != nullptr)
- itemPopup->setVisible(Visible_false);
-}
diff --git a/src/gui/widgets/virtshortcutcontainer.h b/src/gui/widgets/virtshortcutcontainer.h
deleted file mode 100644
index 989a6c8d7..000000000
--- a/src/gui/widgets/virtshortcutcontainer.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_VIRTSHORTCUTCONTAINER_H
-#define GUI_WIDGETS_VIRTSHORTCUTCONTAINER_H
-
-#include "gui/widgets/shortcutcontainer.h"
-
-class ShortcutBase;
-
-/**
- * An item shortcut container. Used to quickly use items.
- *
- * \ingroup GUI
- */
-class VirtShortcutContainer final : public ShortcutContainer
-{
- public:
- /**
- * Constructor. Initializes the graphic.
- */
- VirtShortcutContainer(Widget2 *const widget,
- ShortcutBase *const shortcut);
-
- A_DELETE_COPY(VirtShortcutContainer)
-
- /**
- * Destructor.
- */
- ~VirtShortcutContainer();
-
- /**
- * Draws the items.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Handles mouse when dragged.
- */
- void mouseDragged(MouseEvent &event) override final;
-
- /**
- * Handles mouse when pressed.
- */
- void mousePressed(MouseEvent &event) override final;
-
- /**
- * Handles mouse release.
- */
- void mouseReleased(MouseEvent &event) override final;
-
- void widgetHidden(const Event &event) override final;
-
- void mouseExited(MouseEvent &event) override final;
-
- void mouseMoved(MouseEvent &event) override final;
-
- void setWidget2(const Widget2 *const widget) override final;
-
- private:
- bool mItemClicked;
-
- Color mEquipedColor;
- Color mEquipedColor2;
- Color mUnEquipedColor;
- Color mUnEquipedColor2;
-
- ShortcutBase *mShortcut;
-};
-
-#endif // GUI_WIDGETS_VIRTSHORTCUTCONTAINER_H
diff --git a/src/gui/widgets/widget.cpp b/src/gui/widgets/widget.cpp
deleted file mode 100644
index 47bca1fb3..000000000
--- a/src/gui/widgets/widget.cpp
+++ /dev/null
@@ -1,526 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * For comments regarding functions please see the header file.
- */
-
-#include "gui/widgets/widget.h"
-
-#include "gui/focushandler.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/widgetdeathlistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "utils/foreach.h"
-
-#include "debug.h"
-
-Font* Widget::mGlobalFont = nullptr;
-std::list<Widget*> Widget::mAllWidgets;
-std::set<Widget*> Widget::mAllWidgetsSet;
-
-Widget::Widget(const Widget2 *const widget) :
- Widget2(widget),
- mVisible(Visible_true),
- mMouseListeners(),
- mKeyListeners(),
- mActionListeners(),
- mDeathListeners(),
- mFocusListeners(),
- mWidgetListeners(),
- mForegroundColor(0x000000),
- mBackgroundColor(0xffffff),
- mBaseColor(0x808090),
- mDimension(),
- mActionEventId(),
- mId(),
- mFocusHandler(nullptr),
- mInternalFocusHandler(nullptr),
- mParent(nullptr),
- mCurrentFont(nullptr),
- mFrameSize(0),
- mFocusable(false),
- mTabIn(true),
- mTabOut(true),
- mEnabled(true),
- mAllowLogic(true),
- mMouseConsume(true),
- mRedraw(true),
- mSelectable(true)
-{
- mAllWidgets.push_back(this);
- mAllWidgetsSet.insert(this);
-}
-
-Widget::~Widget()
-{
- FOR_EACH (WidgetDeathListenerIterator, iter, mDeathListeners)
- {
- Event event(this);
- (*iter)->death(event);
- }
-
- // +++ call to virtual member
- setFocusHandler(nullptr);
-
- mAllWidgets.remove(this);
- mAllWidgetsSet.erase(this);
-}
-
-void Widget::setWidth(const int width)
-{
- Rect newDimension = mDimension;
- newDimension.width = width;
- setDimension(newDimension);
-}
-
-void Widget::setHeight(const int height)
-{
- Rect newDimension = mDimension;
- newDimension.height = height;
- setDimension(newDimension);
-}
-
-void Widget::setX(const int x)
-{
- Rect newDimension = mDimension;
- newDimension.x = x;
- setDimension(newDimension);
-}
-
-void Widget::setY(const int y)
-{
- Rect newDimension = mDimension;
- newDimension.y = y;
- setDimension(newDimension);
-}
-
-void Widget::setPosition(const int x, const int y)
-{
- Rect newDimension = mDimension;
- newDimension.x = x;
- newDimension.y = y;
- setDimension(newDimension);
-}
-
-void Widget::setDimension(const Rect& dimension)
-{
- const Rect oldDimension = mDimension;
- mDimension = dimension;
-
- if (mDimension.width != oldDimension.width
- || mDimension.height != oldDimension.height)
- {
- distributeResizedEvent();
- }
-
- if (mDimension.x != oldDimension.x || mDimension.y != oldDimension.y)
- distributeMovedEvent();
-}
-
-bool Widget::isFocused() const
-{
- if (mFocusHandler == nullptr)
- return false;
-
- return mFocusHandler->isFocused(this);
-}
-
-void Widget::setFocusable(const bool focusable)
-{
- if (!focusable && isFocused() && (mFocusHandler != nullptr))
- mFocusHandler->focusNone();
- mFocusable = focusable;
-}
-
-bool Widget::isFocusable() const
-{
- return mFocusable && isVisible() && isEnabled();
-}
-
-void Widget::requestFocus()
-{
- if (mFocusHandler == nullptr)
- return;
-
- if (isFocusable())
- mFocusHandler->requestFocus(this);
-}
-
-void Widget::requestMoveToTop()
-{
- if (mParent != nullptr)
- mParent->moveToTop(this);
-}
-
-void Widget::requestMoveToBottom()
-{
- if (mParent != nullptr)
- mParent->moveToBottom(this);
-}
-
-void Widget::setVisible(Visible visible)
-{
- if (visible == Visible_false && isFocused() && (mFocusHandler != nullptr))
- mFocusHandler->focusNone();
-
- if (visible == Visible_true)
- distributeShownEvent();
- else
- distributeHiddenEvent();
-
- mVisible = visible;
-}
-
-void Widget::setFocusHandler(FocusHandler *const focusHandler)
-{
- if (mFocusHandler != nullptr)
- {
- releaseModalFocus();
- mFocusHandler->remove(this);
- }
-
- if (focusHandler != nullptr)
- focusHandler->add(this);
-
- mFocusHandler = focusHandler;
-}
-
-void Widget::addActionListener(ActionListener *const actionListener)
-{
- mActionListeners.push_back(actionListener);
-}
-
-void Widget::removeActionListener(ActionListener *const actionListener)
-{
- mActionListeners.remove(actionListener);
-}
-
-void Widget::addDeathListener(WidgetDeathListener *const deathListener)
-{
- mDeathListeners.push_back(deathListener);
-}
-
-void Widget::removeDeathListener(WidgetDeathListener *const deathListener)
-{
- mDeathListeners.remove(deathListener);
-}
-
-void Widget::addKeyListener(KeyListener *const keyListener)
-{
- mKeyListeners.push_back(keyListener);
-}
-
-void Widget::removeKeyListener(KeyListener *const keyListener)
-{
- mKeyListeners.remove(keyListener);
-}
-
-void Widget::addFocusListener(FocusListener *const focusListener)
-{
- mFocusListeners.push_back(focusListener);
-}
-
-void Widget::removeFocusListener(FocusListener *const focusListener)
-{
- mFocusListeners.remove(focusListener);
-}
-
-void Widget::addMouseListener(MouseListener *const mouseListener)
-{
- mMouseListeners.push_back(mouseListener);
-}
-
-void Widget::removeMouseListener(MouseListener *const mouseListener)
-{
- mMouseListeners.remove(mouseListener);
-}
-
-void Widget::addWidgetListener(WidgetListener *const widgetListener)
-{
- mWidgetListeners.push_back(widgetListener);
-}
-
-void Widget::removeWidgetListener(WidgetListener *const widgetListener)
-{
- mWidgetListeners.remove(widgetListener);
-}
-
-void Widget::getAbsolutePosition(int& x, int& y) const
-{
- if (mParent == nullptr)
- {
- x = mDimension.x;
- y = mDimension.y;
- return;
- }
-
- int parentX;
- int parentY;
-
- mParent->getAbsolutePosition(parentX, parentY);
-
- const Rect &rect = mParent->getChildrenArea();
- x = parentX + mDimension.x + rect.x;
- y = parentY + mDimension.y + rect.y;
-}
-
-Font* Widget::getFont() const
-{
- if (mCurrentFont == nullptr)
- return mGlobalFont;
- return mCurrentFont;
-}
-
-void Widget::setGlobalFont(Font *const font)
-{
- mGlobalFont = font;
-
- FOR_EACH (std::list<Widget*>::const_iterator, iter, mAllWidgets)
- {
- if ((*iter)->mCurrentFont == nullptr)
- (*iter)->fontChanged();
- }
-}
-
-void Widget::setFont(Font *const font)
-{
- mCurrentFont = font;
- fontChanged();
-}
-
-void Widget::distributeWindowResizeEvent()
-{
- FOR_EACH (std::list<Widget*>::const_iterator, iter, mAllWidgets)
- (*iter)->windowResized();
-}
-
-bool Widget::widgetExists(const Widget *const widget)
-{
- return mAllWidgetsSet.find(const_cast<Widget*>(widget))
- != mAllWidgetsSet.end();
-}
-
-void Widget::setSize(const int width, const int height)
-{
- Rect newDimension = mDimension;
- newDimension.width = width;
- newDimension.height = height;
- setDimension(newDimension);
-}
-
-bool Widget::isEnabled() const
-{
- return mEnabled && isVisible();
-}
-
-void Widget::requestModalFocus()
-{
- if (mFocusHandler == nullptr)
- return;
- mFocusHandler->requestModalFocus(this);
-}
-
-void Widget::requestModalMouseInputFocus()
-{
- if (mFocusHandler == nullptr)
- return;
- mFocusHandler->requestModalMouseInputFocus(this);
-}
-
-void Widget::releaseModalFocus()
-{
- if (mFocusHandler == nullptr)
- return;
- mFocusHandler->releaseModalFocus(this);
-}
-
-void Widget::releaseModalMouseInputFocus()
-{
- if (mFocusHandler == nullptr)
- return;
- mFocusHandler->releaseModalMouseInputFocus(this);
-}
-
-bool Widget::isModalFocused() const
-{
- if (mFocusHandler == nullptr)
- return false;
-
- if (mParent != nullptr)
- {
- return (mFocusHandler->getModalFocused() == this)
- || mParent->isModalFocused();
- }
-
- return mFocusHandler->getModalFocused() == this;
-}
-
-bool Widget::isModalMouseInputFocused() const
-{
- if (mFocusHandler == nullptr)
- return false;
-
- if (mParent != nullptr)
- {
- return (mFocusHandler->getModalMouseInputFocused() == this)
- || mParent->isModalMouseInputFocused();
- }
-
- return mFocusHandler->getModalMouseInputFocused() == this;
-}
-
-const std::list<MouseListener*> &Widget::getMouseListeners() const
-{
- return mMouseListeners;
-}
-
-const std::list<KeyListener*> &Widget::getKeyListeners() const
-{
- return mKeyListeners;
-}
-
-const std::list<FocusListener*> &Widget::getFocusListeners() const
-{
- return mFocusListeners;
-}
-
-Rect Widget::getChildrenArea()
-{
- return Rect(0, 0, 0, 0);
-}
-
-FocusHandler* Widget::getInternalFocusHandler()
-{
- return mInternalFocusHandler;
-}
-
-void Widget::setInternalFocusHandler(FocusHandler *const focusHandler)
-{
- mInternalFocusHandler = focusHandler;
-}
-
-void Widget::distributeResizedEvent()
-{
- FOR_EACH (WidgetListenerIterator, iter, mWidgetListeners)
- {
- Event event(this);
- (*iter)->widgetResized(event);
- }
-}
-
-void Widget::distributeMovedEvent()
-{
- FOR_EACH (WidgetListenerIterator, iter, mWidgetListeners)
- {
- Event event(this);
- (*iter)->widgetMoved(event);
- }
-}
-
-void Widget::distributeHiddenEvent()
-{
- FOR_EACH (WidgetListenerIterator, iter, mWidgetListeners)
- {
- Event event(this);
- (*iter)->widgetHidden(event);
- }
-}
-
-void Widget::distributeActionEvent()
-{
- FOR_EACH (ActionListenerIterator, iter, mActionListeners)
- {
- ActionEvent actionEvent(this, mActionEventId);
- (*iter)->action(actionEvent);
- }
-}
-
-void Widget::distributeShownEvent()
-{
- FOR_EACH (WidgetListenerIterator, iter, mWidgetListeners)
- {
- Event event(this);
- (*iter)->widgetShown(event);
- }
-}
-
-void Widget::showPart(const Rect &rectangle)
-{
- if (mParent != nullptr)
- mParent->showWidgetPart(this, rectangle);
-}
-
-void Widget::windowResized()
-{
- mRedraw = true;
-}
-
-Widget *Widget::callPostInit(Widget *const widget)
-{
- if (widget != nullptr)
- widget->postInit();
- return widget;
-}
diff --git a/src/gui/widgets/widget.h b/src/gui/widgets/widget.h
deleted file mode 100644
index bb41054d2..000000000
--- a/src/gui/widgets/widget.h
+++ /dev/null
@@ -1,1181 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_WIDGET_H
-#define GUI_WIDGETS_WIDGET_H
-
-#include "enums/simpletypes/visible.h"
-
-#include "gui/rect.h"
-
-#include "gui/widgets/widget2.h"
-
-#include <list>
-
-#include "localconsts.h"
-
-class ActionListener;
-class WidgetDeathListener;
-class FocusHandler;
-class FocusListener;
-class Font;
-class Graphics;
-class KeyListener;
-class MouseListener;
-class WidgetListener;
-
-/**
- * Abstract class for widgets of Guichan. It contains basic functions
- * every widget should have.
- *
- * NOTE: Functions begining with underscore "_" should not
- * be overloaded unless you know what you are doing
- *
- * @author Olof Naessén
- * @author Per Larsson.
- */
-class Widget notfinal : public Widget2
-{
- public:
- friend class BasicContainer;
-
- /**
- * Constructor. Resets member variables. Noteable, a widget is not
- * focusable as default, therefore, widgets that are supposed to be
- * focusable should overide this default in their own constructor.
- */
- explicit Widget(const Widget2 *const widget);
-
- A_DELETE_COPY(Widget)
-
- /**
- * Default destructor.
- */
- virtual ~Widget();
-
- /**
- * Draws the widget. It is called by the parent widget when it is time
- * for the widget to draw itself. The graphics object is set up so
- * that all drawing is relative to the widget, i.e coordinate (0,0) is
- * the top left corner of the widget. It is not possible to draw
- * outside of a widget's dimension.
- *
- * @param graphics aA graphics object to draw with.
- */
- virtual void draw(Graphics *const graphics) A_NONNULL(2) = 0;
-
- virtual void safeDraw(Graphics *const graphics) A_NONNULL(2) = 0;
-
- /**
- * Called when a widget is given a chance to draw a frame around itself.
- * The frame is not considered a part of the widget, it only allows a frame
- * to be drawn around the widget, thus a frame will never be included when
- * calculating if a widget should receive events from user input. Also
- * a widget's frame will never be included when calculating a widget's
- * position.
- *
- * The size of the frame is calculated using the widget's frame size.
- * If a widget has a frame size of 10 pixels than the area the drawFrame
- * function can draw to will be the size of the widget with an additional
- * extension of 10 pixels in each direction.
- *
- * An example when drawFrame is a useful function is if a widget needs
- * a glow around itself.
- *
- * @param graphics A graphics object to draw with.
- * @see setFrameSize, getFrameSize
- */
- virtual void drawFrame(Graphics* graphics A_UNUSED) A_NONNULL(2)
- { }
-
- virtual void safeDrawFrame(Graphics* graphics A_UNUSED) A_NONNULL(2)
- { }
-
- /**
- * Sets the size of the widget's frame. The frame is not considered a part of
- * the widget, it only allows a frame to be drawn around the widget, thus a frame
- * will never be included when calculating if a widget should receive events
- * from user input. Also a widget's frame will never be included when calculating
- * a widget's position.
- *
- * A frame size of 0 means that the widget has no frame. The default frame size
- * is 0.
- *
- * @param frameSize The size of the widget's frame.
- * @see getFrameSize, drawFrame
- */
- void setFrameSize(const unsigned int frameSize) noexcept2
- { mFrameSize = frameSize; }
-
- /**
- * Gets the size of the widget's frame. The frame is not considered a part of
- * the widget, it only allows a frame to be drawn around the widget, thus a frame
- * will never be included when calculating if a widget should receive events
- * from user input. Also a widget's frame will never be included when calculating
- * a widget's position.
- *
- * A frame size of 0 means that the widget has no frame. The default frame size
- * is 0.
- *
- * @return The size of the widget's frame.
- * @see setFrameSize, drawFrame
- */
- unsigned int getFrameSize() const noexcept2 A_WARN_UNUSED
- { return mFrameSize; }
-
- /**
- * Called for all widgets in the gui each time Gui::logic is called.
- * You can do logic stuff here like playing an animation.
- *
- * @see Gui::logic
- */
- virtual void logic()
- { }
-
- /**
- * Gets the widget's parent container.
- *
- * @return The widget's parent container. NULL if the widget
- * has no parent.
- */
- Widget* getParent() const noexcept2 A_WARN_UNUSED
- { return mParent; }
-
- /**
- * Sets the width of the widget.
- *
- * @param width The width of the widget.
- * @see getWidth, setHeight, getHeight, setSize,
- * setDimension, getDimensi
- */
- void setWidth(const int width);
-
- /**
- * Gets the width of the widget.
- *
- * @return The width of the widget.
- * @see setWidth, setHeight, getHeight, setSize,
- * setDimension, getDimension
- */
- int getWidth() const noexcept2 A_WARN_UNUSED
- { return mDimension.width; }
-
- /**
- * Sets the height of the widget.
- *
- * @param height The height of the widget.
- * @see getHeight, setWidth, getWidth, setSize,
- * setDimension, getDimension
- */
- void setHeight(const int height);
-
- /**
- * Gets the height of the widget.
- *
- * @return The height of the widget.
- * @see setHeight, setWidth, getWidth, setSize,
- * setDimension, getDimension
- */
- int getHeight() const noexcept2 A_WARN_UNUSED
- { return mDimension.height; }
-
- /**
- * Sets the size of the widget.
- *
- * @param width The width of the widget.
- * @param height The height of the widget.
- * @see setWidth, setHeight, getWidth, getHeight,
- * setDimension, getDimension
- */
- void setSize(const int width, const int height);
-
- /**
- * Sets the x coordinate of the widget. The coordinate is
- * relateive to the widget's parent.
- *
- * @param x The x coordinate of the widget.
- * @see getX, setY, getY, setPosition, setDimension, getDimension
- */
- void setX(const int x);
-
- /**
- * Gets the x coordinate of the widget. The coordinate is
- * relative to the widget's parent.
- *
- * @return The x coordinate of the widget.
- * @see setX, setY, getY, setPosition, setDimension, getDimension
- */
- int getX() const noexcept2 A_WARN_UNUSED
- { return mDimension.x; }
-
- /**
- * Sets the y coordinate of the widget. The coordinate is
- * relative to the widget's parent.
- *
- * @param y The y coordinate of the widget.
- * @see setY, setX, getX, setPosition, setDimension, getDimension
- */
- void setY(const int y);
-
- /**
- * Gets the y coordinate of the widget. The coordinate is
- * relative to the widget's parent.
- *
- * @return The y coordinate of the widget.
- * @see setY, setX, getX, setPosition, setDimension, getDimension
- */
- int getY() const noexcept2 A_WARN_UNUSED
- { return mDimension.y; }
-
- /**
- * Sets position of the widget. The position is relative
- * to the widget's parent.
- *
- * @param x The x coordinate of the widget.
- * @param y The y coordinate of the widget.
- * @see setX, getX, setY, getY, setDimension, getDimension
- */
- void setPosition(const int x, const int y);
-
- /**
- * Sets the dimension of the widget. The dimension is
- * relative to the widget's parent.
- *
- * @param dimension The dimension of the widget.
- * @see getDimension, setX, getX, setY, getY, setPosition
- */
- void setDimension(const Rect& dimension);
-
- /**
- * Gets the dimension of the widget. The dimension is
- * relative to the widget's parent.
- *
- * @return The dimension of the widget.
- * @see getDimension, setX, getX, setY, getY, setPosition
- */
- const Rect& getDimension() const noexcept2 A_WARN_UNUSED
- { return mDimension; }
-
- /**
- * Sets the widget to be fosusable, or not.
- *
- * @param focusable True if the widget should be focusable,
- * false otherwise.
- * @see isFocusable
- */
- void setFocusable(const bool focusable);
-
- /**
- * Checks if a widget is focsable.
- *
- * @return True if the widget should be focusable, false otherwise.
- * @see setFocusable
- */
- bool isFocusable() const A_WARN_UNUSED;
-
- /**
- * Checks if the widget is focused.
- *
- * @return True if the widget is focused, false otherwise.
- */
- virtual bool isFocused() const A_WARN_UNUSED;
-
- /**
- * Sets the widget to enabled, or not. A disabled
- * widget will never recieve mouse or key events.
- *
- * @param enabled True if widget should be enabled,
- * false otherwise.
- * @see isEnabled
- */
- void setEnabled(const bool enabled) noexcept2
- { mEnabled = enabled; }
-
- /**
- * Checks if the widget is enabled. A disabled
- * widget will never recieve mouse or key events.
- *
- * @return True if widget is enabled, false otherwise.
- * @see setEnabled
- */
- bool isEnabled() const A_WARN_UNUSED;
-
- /**
- * Sets the widget to be visible, or not.
- *
- * @param visible True if widget should be visible, false otherwise.
- * @see isVisible
- */
- void setVisible(Visible visible);
-
- /**
- * Checks if the widget is visible.
- *
- * @return True if widget is be visible, false otherwise.
- * @see setVisible
- */
- bool isVisible() const A_WARN_UNUSED
- {
- return mVisible == Visible_true &&
- ((mParent == nullptr) || mParent->isVisible());
- }
-
- /**
- * Sets the base color of the widget.
- *
- * @param color The baseground color.
- * @see getBaseColor
- */
- void setBaseColor(const Color& color) noexcept2
- { mBaseColor = color; }
-
- /**
- * Gets the base color.
- *
- * @return The base color.
- * @see setBaseColor
- */
- const Color& getBaseColor() const noexcept2 A_WARN_UNUSED
- { return mBaseColor; }
-
- /**
- * Sets the foreground color.
- *
- * @param color The foreground color.
- * @see getForegroundColor
- */
- void setForegroundColor(const Color& color) noexcept2
- { mForegroundColor = color; }
-
- /**
- * Gets the foreground color.
- *
- * @see setForegroundColor
- */
- const Color& getForegroundColor() const noexcept2 A_WARN_UNUSED
- { return mForegroundColor; }
-
- /**
- * Sets the background color.
- *
- * @param color The background Color.
- * @see setBackgroundColor
- */
- void setBackgroundColor(const Color &color) noexcept2
- { mBackgroundColor = color; }
-
- /**
- * Gets the background color.
- *
- * @see setBackgroundColor
- */
- const Color &getBackgroundColor() const noexcept2 A_WARN_UNUSED
- { return mBackgroundColor; }
-
- /**
- * Requests focus for the widget. A widget will only recieve focus
- * if it is focusable.
- */
- virtual void requestFocus();
-
- /**
- * Requests a move to the top in the parent widget.
- */
- virtual void requestMoveToTop();
-
- /**
- * Requests a move to the bottom in the parent widget.
- */
- virtual void requestMoveToBottom();
-
- /**
- * Sets the focus handler to be used.
- *
- * WARNING: This function is used internally and should not
- * be called or overloaded unless you know what you
- * are doing.
- *
- * @param focusHandler The focus handler to use.
- * @see getFocusHandler
- */
- virtual void setFocusHandler(FocusHandler *const focusHandler);
-
- /**
- * Gets the focus handler used.
- *
- * WARNING: This function is used internally and should not
- * be called or overloaded unless you know what you
- * are doing.
- *
- * @return The focus handler used.
- * @see setFocusHandler
- */
- FocusHandler* getFocusHandler() noexcept2 A_WARN_UNUSED
- { return mFocusHandler; }
-
- /**
- * Adds an action listener to the widget. When an action event
- * is fired by the widget the action listeners of the widget
- * will get notified.
- *
- * @param actionListener The action listener to add.
- * @see removeActionListener
- */
- void addActionListener(ActionListener *const actionListener);
-
- /**
- * Removes an added action listener from the widget.
- *
- * @param actionListener The action listener to remove.
- * @see addActionListener
- */
- void removeActionListener(ActionListener *const actionListener);
-
- /**
- * Adds a death listener to the widget. When a death event is
- * fired by the widget the death listeners of the widget will
- * get notified.
- *
- * @param deathListener The death listener to add.
- * @see removeDeathListener
- */
- void addDeathListener(WidgetDeathListener *const deathListener);
-
- /**
- * Removes an added death listener from the widget.
- *
- * @param deathListener The death listener to remove.
- * @see addDeathListener
- */
- void removeDeathListener(WidgetDeathListener *const deathListener);
-
- /**
- * Adds a mouse listener to the widget. When a mouse event is
- * fired by the widget the mouse listeners of the widget will
- * get notified.
- *
- * @param mouseListener The mouse listener to add.
- * @see removeMouseListener
- */
- void addMouseListener(MouseListener *const mouseListener);
-
- /**
- * Removes an added mouse listener from the widget.
- *
- * @param mouseListener The mouse listener to remove.
- * @see addMouseListener
- */
- void removeMouseListener(MouseListener *const mouseListener);
-
- /**
- * Adds a key listener to the widget. When a key event is
- * fired by the widget the key listeners of the widget will
- * get notified.
- *
- * @param keyListener The key listener to add.
- * @see removeKeyListener
- */
- void addKeyListener(KeyListener *const keyListener);
-
- /**
- * Removes an added key listener from the widget.
- *
- * @param keyListener The key listener to remove.
- * @see addKeyListener
- */
- void removeKeyListener(KeyListener *const keyListener);
-
- /**
- * Adds a focus listener to the widget. When a focus event is
- * fired by the widget the key listeners of the widget will
- * get notified.
- *
- * @param focusListener The focus listener to add.
- * @see removeFocusListener
- */
- void addFocusListener(FocusListener *const focusListener);
-
- /**
- * Removes an added focus listener from the widget.
- *
- * @param focusListener The focus listener to remove.
- * @see addFocusListener
- */
- void removeFocusListener(FocusListener *const focusListener);
-
- /**
- * Adds a widget listener to the widget. When a widget event is
- * fired by the widget the key listeners of the widget will
- * get notified.
- *
- * @param widgetListener The widget listener to add.
- * @see removeWidgetListener
- */
- void addWidgetListener(WidgetListener *const widgetListener);
-
- /**
- * Removes an added widget listener from the widget.
- *
- * @param widgetListener The widget listener to remove.
- * @see addWidgetListener
- */
- void removeWidgetListener(WidgetListener *const widgetListener);
-
- /**
- * Sets the action event identifier of the widget. The identifier is
- * used to be able to identify which action has occured.
- *
- * NOTE: An action event identifier should not be used to identify a
- * certain widget but rather a certain event in your application.
- * Several widgets can have the same action event identifer.
- *
- * @param actionEventId The action event identifier.
- * @see getActionEventId
- */
- void setActionEventId(const std::string &actionEventId) noexcept2
- { mActionEventId = actionEventId; }
-
- /**
- * Gets the action event identifier of the widget.
- *
- * @return The action event identifier of the widget.
- * @see setActionEventId
- */
- const std::string &getActionEventId() const noexcept2
- { return mActionEventId; }
-
- /**
- * Gets the absolute position on the screen for the widget.
- *
- * @param x The absolute x coordinate will be stored in this parameter.
- * @param y The absolute y coordinate will be stored in this parameter.
- */
- virtual void getAbsolutePosition(int& x, int& y) const;
-
- /**
- * Sets the parent of the widget. A parent must be a BasicContainer.
- *
- * WARNING: This function is used internally and should not
- * be called or overloaded unless you know what you
- * are doing.
- *
- * @param parent The parent of the widget.
- * @see getParent
- */
- virtual void setParent(Widget* parent)
- { mParent = parent; }
-
- /**
- * Gets the font set for the widget. If no font has been set,
- * the global font will be returned. If no global font has been set,
- * the default font will be returend.
- *
- * @return The font set for the widget.
- * @see setFont, setGlobalFont
- */
- Font *getFont() const RETURNS_NONNULL A_WARN_UNUSED;
-
- /**
- * Sets the global font to be used by default for all widgets.
- *
- * @param font The global font.
- * @see getGlobalFont
- */
- static void setGlobalFont(Font *const font);
-
- static Font *getGloablFont()
- { return mGlobalFont; }
-
- static void cleanGlobalFont()
- { mGlobalFont = nullptr; }
-
- /**
- * Sets the font for the widget. If NULL is passed, the global font
- * will be used.
- *
- * @param font The font to set for the widget.
- * @see getFont
- */
- void setFont(Font *const font);
-
- /**
- * Called when the font has changed. If the change is global,
- * this function will only be called if the widget doesn't have a
- * font already set.
- */
- virtual void fontChanged()
- { }
-
- /**
- * Checks if a widget exists or not, that is if it still exists
- * an instance of the object.
- *
- * @param widget The widget to check.
- * @return True if an instance of the widget exists, false otherwise.
- */
- static bool widgetExists(const Widget *const widget) A_WARN_UNUSED;
-
- /**
- * Checks if tab in is enabled. Tab in means that you can set focus
- * to this widget by pressing the tab button. If tab in is disabled
- * then the focus handler will skip this widget and focus the next
- * in its focus order.
- *
- * @return True if tab in is enabled, false otherwise.
- * @see setTabInEnabled
- */
- bool isTabInEnabled() const noexcept2 A_WARN_UNUSED
- { return mTabIn; }
-
- /**
- * Sets tab in enabled, or not. Tab in means that you can set focus
- * to this widget by pressing the tab button. If tab in is disabled
- * then the FocusHandler will skip this widget and focus the next
- * in its focus order.
- *
- * @param enabled True if tab in should be enabled, false otherwise.
- * @see isTabInEnabled
- */
- void setTabInEnabled(const bool enabled) noexcept2
- { mTabIn = enabled; }
-
- /**
- * Checks if tab out is enabled. Tab out means that you can lose
- * focus to this widget by pressing the tab button. If tab out is
- * disabled then the FocusHandler ignores tabbing and focus will
- * stay with this widget.
- *
- * @return True if tab out is enabled, false otherwise.
- * @see setTabOutEnabled
- */
- bool isTabOutEnabled() const noexcept2 A_WARN_UNUSED
- { return mTabOut; }
-
- /**
- * Sets tab out enabled. Tab out means that you can lose
- * focus to this widget by pressing the tab button. If tab out is
- * disabled then the FocusHandler ignores tabbing and focus will
- * stay with this widget.
- *
- * @param enabled True if tab out should be enabled, false otherwise.
- * @see isTabOutEnabled
- */
- void setTabOutEnabled(const bool enabled) noexcept2
- { mTabOut = enabled; }
-
- /**
- * Requests modal focus. When a widget has modal focus, only that
- * widget and it's children may recieve input.
- *
- * @throws Exception if another widget already has modal focus.
- * @see releaseModalFocus, isModalFocused
- */
- void requestModalFocus();
-
- /**
- * Requests modal mouse input focus. When a widget has modal input focus
- * that widget will be the only widget receiving input even if the input
- * occurs outside of the widget and no matter what the input is.
- *
- * @throws Exception if another widget already has modal focus.
- * @see releaseModalMouseInputFocus, isModalMouseInputFocused
- */
- virtual void requestModalMouseInputFocus();
-
- /**
- * Releases modal focus. Modal focus will only be released if the
- * widget has modal focus.
- *
- * @see requestModalFocus, isModalFocused
- */
- virtual void releaseModalFocus();
-
- /**
- * Releases modal mouse input focus. Modal mouse input focus will only
- * be released if the widget has modal mouse input focus.
- *
- * @see requestModalMouseInputFocus, isModalMouseInputFocused
- */
- virtual void releaseModalMouseInputFocus();
-
- /**
- * Checks if the widget or it's parent has modal focus.
- *
- * @return True if the widget has modal focus, false otherwise.
- * @see requestModalFocus, releaseModalFocus
- */
- virtual bool isModalFocused() const A_WARN_UNUSED;
-
- /**
- * Checks if the widget or it's parent has modal mouse input focus.
- *
- * @return True if the widget has modal mouse input focus, false
- * otherwise.
- * @see requestModalMouseInputFocus, releaseModalMouseInputFocus
- */
- virtual bool isModalMouseInputFocused() const A_WARN_UNUSED;
-
- /**
- * Gets a widget from a certain position in the widget.
- * This function is used to decide which gets mouse input,
- * thus it can be overloaded to change that behaviour.
- *
- * NOTE: This always returns NULL if the widget is not
- * a container.
- *
- * @param x The x coordinate of the widget to get.
- * @param y The y coordinate of the widget to get.
- * @return The widget at the specified coodinate, NULL
- * if no widget is found.
- */
- virtual Widget *getWidgetAt(int x A_UNUSED,
- int y A_UNUSED) A_WARN_UNUSED
- { return nullptr; }
-
- /**
- * Gets the mouse listeners of the widget.
- *
- * @return The mouse listeners of the widget.
- */
- const std::list<MouseListener*>& getMouseListeners() const
- A_CONST A_WARN_UNUSED;
-
- /**
- * Gets the key listeners of the widget.
- *
- * @return The key listeners of the widget.
- */
- const std::list<KeyListener*>& getKeyListeners() const
- A_CONST A_WARN_UNUSED;
-
- /**
- * Gets the focus listeners of the widget.
- *
- * @return The focus listeners of the widget.
- */
- const std::list<FocusListener*>& getFocusListeners() const
- A_CONST A_WARN_UNUSED;
-
- /**
- * Gets the area of the widget occupied by the widget's children.
- * By default this method returns an empty rectangle as not all
- * widgets are containers. If you want to make a container this
- * method should return the area where the children resides. This
- * method is used when drawing children of a widget when computing
- * clip rectangles for the children.
- *
- * An example of a widget that overloads this method is ScrollArea.
- * A ScrollArea has a view of its contant and that view is the
- * children area. The size of a ScrollArea's children area might
- * vary depending on if the scroll bars of the ScrollArea is shown
- * or not.
- *
- * @return The area of the widget occupied by the widget's children.
- * @see BasicContainer
- * @see BasicContainer::getChildrenArea
- * @see BasicContainer::drawChildren
- */
- virtual Rect getChildrenArea() A_WARN_UNUSED;
-
- /**
- * Gets the internal focus handler used.
- *
- * @return the internalFocusHandler used. If no internal focus handler
- * is used, NULL will be returned.
- * @see setInternalFocusHandler
- */
- virtual FocusHandler* getInternalFocusHandler() A_WARN_UNUSED;
-
- /**
- * Sets the internal focus handler. An internal focus handler is
- * needed if both a widget in the widget and the widget itself
- * should be foucsed at the same time.
- *
- * @param focusHandler The internal focus handler to be used.
- * @see getInternalFocusHandler
- */
- void setInternalFocusHandler(FocusHandler *const internalFocusHandler);
-
- /**
- * Moves a widget to the top of this widget. The moved widget will be
- * drawn above all other widgets in this widget.
- *
- * @param widget The widget to move to the top.
- * @see moveToBottom
- */
- virtual void moveToTop(Widget* widget A_UNUSED)
- { }
-
- /**
- * Moves a widget in this widget to the bottom of this widget.
- * The moved widget will be drawn below all other widgets in this widget.
- *
- * @param widget The widget to move to the bottom.
- * @see moveToTop
- */
- virtual void moveToBottom(Widget* widget A_UNUSED)
- { }
-
- /**
- * Focuses the next widget in the widget.
- *
- * @see moveToBottom
- */
- virtual void focusNext()
- { }
-
- /**
- * Focuses the previous widget in the widget.
- *
- * @see moveToBottom
- */
- virtual void focusPrevious()
- { }
-
- /**
- * Tries to show a specific part of a widget by moving it. Used if the
- * widget should act as a container.
- *
- * @param widget The target widget.
- * @param area The area to show.
- */
- virtual void showWidgetPart(Widget *const widget A_UNUSED,
- const Rect &area A_UNUSED)
- { }
-
- /**
- * Sets an id of a widget. An id can be useful if a widget needs to be
- * identified in a container. For example, if widgets are created by an
- * XML document, a certain widget can be retrieved given that the widget
- * has an id.
- *
- * @param id The id to set to the widget.
- * @see getId
- */
- void setId(const std::string& id)
- { mId = id; }
-
- const std::string& getId() const noexcept2 A_WARN_UNUSED
- { return mId; }
-
- /**
- * Shows a certain part of a widget in the widget's parent.
- * Used when widgets want a specific part to be visible in
- * its parent. An example is a TextArea that wants a specific
- * part of its text to be visible when a TextArea is a child
- * of a ScrollArea.
- *
- * @param rectangle The rectangle to be shown.
- */
- virtual void showPart(const Rect &rectangle);
-
- bool isAllowLogic() const noexcept2 A_WARN_UNUSED
- { return mAllowLogic; }
-
- void setMouseConsume(const bool b) noexcept2
- { mMouseConsume = b; }
-
- bool isMouseConsume() const noexcept2 A_WARN_UNUSED
- { return mMouseConsume; }
-
- void setRedraw(const bool b) noexcept2
- { mRedraw = b; }
-
- virtual bool isSelectable() const noexcept2 A_WARN_UNUSED
- { return mSelectable; }
-
- void setSelectable(const bool selectable) noexcept2
- { mSelectable = selectable; }
-
- static void distributeWindowResizeEvent();
-
- void windowResized();
-
- static Widget *callPostInit(Widget *const widget) RETURNS_NONNULL;
-
- virtual void postInit()
- { }
-
- /**
- * True if the widget visible, false otherwise.
- */
- Visible mVisible;
-
- protected:
- /**
- * Distributes an action event to all action listeners
- * of the widget.
- */
- void distributeActionEvent();
-
- /**
- * Distributes resized events to all of the widget's listeners.
- */
- void distributeResizedEvent();
-
- /**
- * Distributes moved events to all of the widget's listeners.
- */
- void distributeMovedEvent();
-
- /**
- * Distributes hidden events to all of the widget's listeners.
- *
- * @author Olof Naessén
- */
- void distributeHiddenEvent();
-
- /**
- * Distributes shown events to all of the widget's listeners.
- *
- * @author Olof Naessén
- */
- void distributeShownEvent();
-
- /**
- * Typdef.
- */
- typedef std::list<MouseListener*> MouseListenerList;
-
- /**
- * Typdef.
- */
- typedef MouseListenerList::iterator MouseListenerIterator;
-
- /**
- * Holds the mouse listeners of the widget.
- */
- MouseListenerList mMouseListeners;
-
- /**
- * Typdef.
- */
- typedef std::list<KeyListener*> KeyListenerList;
-
- /**
- * Holds the key listeners of the widget.
- */
- KeyListenerList mKeyListeners;
-
- /**
- * Typdef.
- */
- typedef KeyListenerList::iterator KeyListenerIterator;
-
- /**
- * Typdef.
- */
- typedef std::list<ActionListener*> ActionListenerList;
-
- /**
- * Holds the action listeners of the widget.
- */
- ActionListenerList mActionListeners;
-
- /**
- * Typdef.
- */
- typedef ActionListenerList::iterator ActionListenerIterator;
-
- /**
- * Typdef.
- */
- typedef std::list<WidgetDeathListener*> WidgetDeathListenerList;
-
- /**
- * Holds the death listeners of the widget.
- */
- WidgetDeathListenerList mDeathListeners;
-
- /**
- * Typdef.
- */
- typedef WidgetDeathListenerList::iterator WidgetDeathListenerIterator;
-
- /**
- * Typdef.
- */
- typedef std::list<FocusListener*> FocusListenerList;
-
- /**
- * Holds the focus listeners of the widget.
- */
- FocusListenerList mFocusListeners;
-
- /**
- * Typdef.
- */
- typedef FocusListenerList::iterator FocusListenerIterator;
-
- typedef std::list<WidgetListener*> WidgetListenerList;
-
- /**
- * Holds the widget listeners of the widget.
- */
- WidgetListenerList mWidgetListeners;
-
- /**
- * Typdef.
- */
- typedef WidgetListenerList::iterator WidgetListenerIterator;
-
- /**
- * Holds the foreground color of the widget.
- */
- Color mForegroundColor;
-
- /**
- * Holds the background color of the widget.
- */
- Color mBackgroundColor;
-
- /**
- * Holds the base color of the widget.
- */
- Color mBaseColor;
-
- /**
- * Holds the dimension of the widget.
- */
- Rect mDimension;
-
- /**
- * Holds the action event of the widget.
- */
- std::string mActionEventId;
-
- /**
- * Holds the id of the widget.
- */
- std::string mId;
-
- /**
- * Holds the focus handler used by the widget.
- */
- FocusHandler* mFocusHandler;
-
- /**
- * Holds the focus handler used by the widget. NULL
- * if no internal focus handler is used.
- */
- FocusHandler* mInternalFocusHandler;
-
- /**
- * Holds the parent of the widget. NULL if the widget
- * has no parent.
- */
- Widget* mParent;
-
- /**
- * Holds the font used by the widget.
- */
- Font* mCurrentFont;
-
- /**
- * Holds the frame size of the widget.
- */
- unsigned int mFrameSize;
-
- /**
- * True if the widget focusable, false otherwise.
- */
- bool mFocusable;
-
- /**
- * True if the widget has tab in enabled, false otherwise.
- */
- bool mTabIn;
-
- /**
- * True if the widget has tab in enabled, false otherwise.
- */
- bool mTabOut;
-
- /**
- * True if the widget is enabled, false otherwise.
- */
- bool mEnabled;
-
- bool mAllowLogic;
-
- bool mMouseConsume;
-
- bool mRedraw;
-
- bool mSelectable;
-
- /**
- * Holds the global font used by the widget.
- */
- static Font* mGlobalFont;
-
- private:
- /**
- * Holds a list of all instances of widgets.
- */
- static std::list<Widget*> mAllWidgets;
-
- static std::set<Widget*> mAllWidgetsSet;
-};
-
-#endif // GUI_WIDGETS_WIDGET_H
diff --git a/src/gui/widgets/widget2.h b/src/gui/widgets/widget2.h
deleted file mode 100644
index 12103e317..000000000
--- a/src/gui/widgets/widget2.h
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_WIDGET2_H
-#define GUI_WIDGETS_WIDGET2_H
-
-#include "const/gui/theme.h"
-
-#include "enums/render/rendertype.h"
-
-#include "gui/themecolorsidoperators.h"
-#include "gui/theme.h"
-
-#include "localconsts.h"
-
-class Widget;
-
-class Widget2 notfinal
-{
- public:
- A_DEFAULT_COPY(Widget2)
-
- virtual ~Widget2()
- {
- }
-
- inline const Color &getThemeColor(const ThemeColorIdT type,
- const unsigned int alpha = 255U)
- const A_WARN_UNUSED A_INLINE
- {
- return theme->getColor(type + mPaletteOffset, alpha);
- }
-
- inline const Color &getThemeCharColor(const signed char c,
- bool &valid)
- const A_WARN_UNUSED A_INLINE
- {
- if (theme == nullptr)
- return Palette::BLACK;
- const ThemeColorIdT colorId = theme->getIdByChar(c, valid);
- if (valid)
- return theme->getColor(colorId + mPaletteOffset, 255U);
- return Palette::BLACK;
- }
-
- virtual void setWidget2(const Widget2 *const widget)
- {
- mPaletteOffset = widget != nullptr ? widget->mPaletteOffset : 0;
- }
-
- void setPalette(int palette)
- {
- mPaletteOffset = palette * CAST_S32(
- ThemeColorId::THEME_COLORS_END);
- checkPalette();
- setWidget2(this);
- }
-
- void checkPalette()
- {
- if (mPaletteOffset < 0 ||
- mPaletteOffset >= THEME_PALETTES * CAST_S32(
- ThemeColorId::THEME_COLORS_END))
- {
- mPaletteOffset = 0;
- }
- }
-
- void setForegroundColor2(const Color &color) noexcept2
- {
- mForegroundColor2 = color;
- }
-
- Widget* getWindow() const noexcept2 A_WARN_UNUSED
- {
- return mWindow;
- }
-
- virtual void setWindow(Widget *const window)
- {
- mWindow = window;
- }
-
- protected:
- explicit Widget2(const Widget2 *const widget) :
- mPaletteOffset(widget != nullptr ? widget->mPaletteOffset : 0),
- mWindow(widget != nullptr ? widget->getWindow() : nullptr),
- mForegroundColor2()
- {
- checkPalette();
- }
-
- int mPaletteOffset;
- Widget *mWindow;
- Color mForegroundColor2;
-};
-
-extern RenderType openGLMode;
-
-#endif // GUI_WIDGETS_WIDGET2_H
diff --git a/src/gui/widgets/widgetgroup.cpp b/src/gui/widgets/widgetgroup.cpp
deleted file mode 100644
index 72524b07c..000000000
--- a/src/gui/widgets/widgetgroup.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/widgetgroup.h"
-
-#include "debug.h"
-
-WidgetGroup::WidgetGroup(const Widget2 *const widget,
- const std::string &group,
- const int height,
- const int spacing) :
- Container(widget),
- WidgetListener(),
- ActionListener(),
- mSpacing(spacing),
- mCount(0),
- mGroup(group),
- mLastX(spacing)
-{
- setHeight(height);
- addWidgetListener(this);
-}
-
-void WidgetGroup::addButton(const std::string &restrict text,
- const std::string &restrict tag,
- const bool pressed)
-{
- if (text.empty() || tag.empty())
- return;
-
- Widget *const widget = createWidget(text, pressed);
- if (widget != nullptr)
- {
- widget->setActionEventId(mActionEventId + tag);
- widget->addActionListener(this);
- addWidget(widget, mSpacing);
- }
-}
-
-void WidgetGroup::action(const ActionEvent &event)
-{
- for (ActionListenerIterator iter = mActionListeners.begin();
- iter != mActionListeners.end(); ++iter)
- {
- (*iter)->action(event);
- }
-}
-
-void WidgetGroup::addWidget(Widget *const widget,
- const int spacing)
-{
- if (widget == nullptr)
- return;
-
- Container::add(widget);
- widget->setPosition(mLastX, spacing);
- mCount++;
- mLastX += widget->getWidth() + 2 * mSpacing;
-}
-
-void WidgetGroup::clear()
-{
- Container::clear();
-
- mCount = 0;
-}
-
-void WidgetGroup::widgetResized(const Event &event A_UNUSED)
-{
-}
diff --git a/src/gui/widgets/widgetgroup.h b/src/gui/widgets/widgetgroup.h
deleted file mode 100644
index 129581ebc..000000000
--- a/src/gui/widgets/widgetgroup.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_WIDGETGROUP_H
-#define GUI_WIDGETS_WIDGETGROUP_H
-
-#include "gui/widgets/container.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "localconsts.h"
-
-class WidgetGroup notfinal : public Container,
- public WidgetListener,
- public ActionListener
-{
- public:
- A_DELETE_COPY(WidgetGroup)
-
- virtual void addButton(const std::string &restrict text,
- const std::string &restrict tag,
- const bool pressed);
-
- void action(const ActionEvent &event) override;
-
- virtual void addWidget(Widget *const widget,
- const int spacing);
-
- void clear() override final;
-
- void widgetResized(const Event &event) override final A_CONST;
-
- virtual Widget *createWidget(const std::string &name,
- const bool pressed)
- const A_WARN_UNUSED = 0;
-
- protected:
- WidgetGroup(const Widget2 *const widget,
- const std::string &group,
- const int height,
- const int spacing);
-
- int mSpacing;
- int mCount;
- std::string mGroup;
-
- private:
- int mLastX;
-};
-
-#endif // GUI_WIDGETS_WIDGETGROUP_H
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
deleted file mode 100644
index b192bad35..000000000
--- a/src/gui/widgets/window.cpp
+++ /dev/null
@@ -1,1499 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/window.h"
-
-#include "client.h"
-#include "configuration.h"
-#ifndef DYECMD
-#include "dragdrop.h"
-#else // DYECMD
-#include "resources/image/image.h"
-#endif // DYECMD
-#include "soundmanager.h"
-
-#include "const/sound.h"
-
-#include "gui/focushandler.h"
-#include "gui/gui.h"
-#include "gui/popupmanager.h"
-#include "gui/skin.h"
-#include "gui/viewport.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/popups/popupmenu.h"
-
-#include "gui/windows/setupwindow.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/layout.h"
-
-#include "render/renderers.h"
-
-#include "render/vertexes/imagecollection.h"
-
-#include "utils/checkutils.h"
-#include "utils/delete2.h"
-
-#include "debug.h"
-
-const int resizeMask = 8 + 4 + 2 + 1;
-
-int Window::windowInstances = 0;
-int Window::mouseResize = 0;
-
-Window::Window(const std::string &caption,
- const Modal modal,
- Window *const parent,
- std::string skin) :
- BasicContainer2(nullptr),
- MouseListener(),
- WidgetListener(),
- mCaption(caption),
- mAlignment(Graphics::CENTER),
- mPadding(2),
- mTitleBarHeight(16),
- mMovable(Move_true),
- mDragOffsetX(0),
- mDragOffsetY(0),
- mMoved(false),
- mSkin(nullptr),
- mDefaultX(0),
- mDefaultY(0),
- mDefaultWidth(0),
- mDefaultHeight(0),
- mCaptionOffsetX(7),
- mCaptionOffsetY(5),
- mShowTitle(true),
- mLastRedraw(true),
- mGrip(nullptr),
- mParentWindow(parent),
- mLayout(nullptr),
- mCloseRect(),
- mStickyRect(),
- mGripRect(),
- mTextChunk(),
- mWindowName("window"),
- mMinWinWidth(100),
- mMinWinHeight(40),
- mMaxWinWidth(mainGraphics->mWidth),
- mMaxWinHeight(mainGraphics->mHeight),
- mVertexes(new ImageCollection),
- mCaptionAlign(Graphics::LEFT),
- mTitlePadding(4),
- mGripPadding(2),
- mResizeHandles(-1),
- mOldResizeHandles(-1),
- mClosePadding(0),
- mStickySpacing(0),
- mStickyPadding(0),
- mCaptionFont(getFont()),
- mModal(modal),
- mCloseWindowButton(false),
- mDefaultVisible(false),
- mSaveVisible(false),
- mStickyButton(false),
- mSticky(false),
- mStickyButtonLock(false),
- mPlayVisibleSound(false),
- mInit(false),
- mTextChanged(true),
- mAllowClose(false)
-{
- logger->log("Window::Window(\"%s\")", caption.c_str());
-
- mWindow = this;
-
- windowInstances++;
-
-// mFrameSize = 1;
- addMouseListener(this);
-
- setFrameSize(0);
- setPadding(3);
- setTitleBarHeight(20);
-
- if (skin.empty())
- skin = "window.xml";
-
- int childPalette = 1;
- // Loads the skin
- if (theme != nullptr)
- {
- mSkin = theme->load(skin, "window.xml");
- if (mSkin != nullptr)
- {
- setPadding(mSkin->getPadding());
- if (getOptionBool("titlebarBold"))
- mCaptionFont = boldFont;
- mTitlePadding = mSkin->getTitlePadding();
- mGripPadding = getOption("resizePadding");
- mCaptionOffsetX = getOption("captionoffsetx");
- if (mCaptionOffsetX == 0)
- mCaptionOffsetX = 7;
- mCaptionOffsetY = getOption("captionoffsety");
- if (mCaptionOffsetY == 0)
- mCaptionOffsetY = 5;
- mCaptionAlign = static_cast<Graphics::Alignment>(
- getOption("captionalign"));
- if (mCaptionAlign < Graphics::LEFT
- || mCaptionAlign > Graphics::RIGHT)
- {
- mCaptionAlign = Graphics::LEFT;
- }
- setTitleBarHeight(CAST_U32(
- getOption("titlebarHeight")));
- if (mTitleBarHeight == 0u)
- mTitleBarHeight = mCaptionFont->getHeight() + mPadding;
-
- mTitleBarHeight += getOption("titlebarHeightRelative");
- setPalette(getOption("palette"));
- childPalette = getOption("childPalette");
- mShowTitle = getOptionBool("showTitle", true);
- mClosePadding = getOption("closePadding");
- mStickySpacing = getOption("stickySpacing");
- mStickyPadding = getOption("stickyPadding");
- }
- }
-
- // Add this window to the window container
- if (windowContainer != nullptr)
- windowContainer->add(this);
-
- if (mModal == Modal_true)
- {
- gui->setCursorType(Cursor::CURSOR_POINTER);
- requestModalFocus();
- }
-
- // Windows are invisible by default
- setVisible(Visible_false, false);
-
- addWidgetListener(this);
- mForegroundColor = getThemeColor(ThemeColorId::WINDOW);
- mForegroundColor2 = getThemeColor(ThemeColorId::WINDOW_OUTLINE);
- setPalette(childPalette);
-}
-
-void Window::postInit()
-{
- if (mInit)
- {
- reportAlways("error: Window created with calling postInit() "
- "more than once: %s",
- mWindowName.c_str());
- }
- mInit = true;
-}
-
-Window::~Window()
-{
- logger->log("Window::~Window(\"%s\")", getCaption().c_str());
-
- if (gui != nullptr)
- gui->removeDragged(this);
-
-#ifndef DYECMD
- if (setupWindow != nullptr)
- setupWindow->unregisterWindowForReset(this);
-#endif // DYECMD
-
- client->windowRemoved(this);
-
- saveWindowState();
-
- delete2(mLayout);
-
- while (!mWidgets.empty())
- delete mWidgets.front();
-
- mWidgets.clear();
-
- removeWidgetListener(this);
- delete2(mVertexes);
-
- windowInstances--;
-
- if (mSkin != nullptr)
- {
- if (theme != nullptr)
- theme->unload(mSkin);
- mSkin = nullptr;
- }
- if (mGrip != nullptr)
- {
- mGrip->decRef();
- mGrip = nullptr;
- }
- if (!mInit)
- {
- reportAlways("error: Window created without calling postInit(): %s",
- mWindowName.c_str());
- }
-}
-
-void Window::setWindowContainer(WindowContainer *const wc)
-{
- windowContainer = wc;
-}
-
-void Window::draw(Graphics *const graphics)
-{
- if (mSkin == nullptr)
- return;
-
- BLOCK_START("Window::draw")
- bool update = false;
-
- if (mResizeHandles != mOldResizeHandles)
- {
- mRedraw = true;
- mOldResizeHandles = mResizeHandles;
- }
- if (mRedraw)
- {
- mLastRedraw = true;
- mRedraw = false;
- update = true;
- mVertexes->clear();
- graphics->calcWindow(mVertexes,
- 0, 0,
- mDimension.width,
- mDimension.height,
- mSkin->getBorder());
-
- // Draw Close Button
- if (mCloseWindowButton)
- {
- const Image *const button = mSkin->getCloseImage(
- mResizeHandles == CLOSE);
- if (button != nullptr)
- {
- graphics->calcTileCollection(mVertexes,
- button,
- mCloseRect.x,
- mCloseRect.y);
- }
- }
- // Draw Sticky Button
- if (mStickyButton)
- {
- const Image *const button = mSkin->getStickyImage(mSticky);
- if (button != nullptr)
- {
- graphics->calcTileCollection(mVertexes,
- button,
- mStickyRect.x,
- mStickyRect.y);
- }
- }
-
- if (mGrip != nullptr)
- {
- graphics->calcTileCollection(mVertexes,
- mGrip,
- mGripRect.x,
- mGripRect.y);
- }
- graphics->finalize(mVertexes);
- }
- else
- {
- mLastRedraw = false;
- }
- graphics->drawTileCollection(mVertexes);
-
- // Draw title
- if (mShowTitle)
- {
- int x;
- switch (mCaptionAlign)
- {
- case Graphics::LEFT:
- default:
- x = mCaptionOffsetX;
- break;
- case Graphics::CENTER:
- x = mCaptionOffsetX - mCaptionFont->getWidth(mCaption) / 2;
- break;
- case Graphics::RIGHT:
- x = mCaptionOffsetX - mCaptionFont->getWidth(mCaption);
- break;
- }
- if (mTextChanged)
- {
- mTextChunk.textFont = mCaptionFont;
- mTextChunk.deleteImage();
- mTextChunk.text = mCaption;
- mTextChunk.color = mForegroundColor;
- mTextChunk.color2 = mForegroundColor2;
- mCaptionFont->generate(mTextChunk);
- mTextChanged = false;
- }
-
- const Image *const image = mTextChunk.img;
- if (image != nullptr)
- graphics->drawImage(image, x, mCaptionOffsetY);
- }
-
- if (update)
- {
- graphics->setRedraw(update);
- drawChildren(graphics);
- graphics->setRedraw(false);
- }
- else
- {
- drawChildren(graphics);
- }
- BLOCK_END("Window::draw")
-}
-
-void Window::safeDraw(Graphics *const graphics)
-{
- if (mSkin == nullptr)
- return;
-
- BLOCK_START("Window::safeDraw")
-
- graphics->drawImageRect(0, 0,
- mDimension.width,
- mDimension.height,
- mSkin->getBorder());
-
- // Draw Close Button
- if (mCloseWindowButton)
- {
- const Image *const button = mSkin->getCloseImage(
- mResizeHandles == CLOSE);
- if (button != nullptr)
- graphics->drawImage(button, mCloseRect.x, mCloseRect.y);
- }
- // Draw Sticky Button
- if (mStickyButton)
- {
- const Image *const button = mSkin->getStickyImage(mSticky);
- if (button != nullptr)
- graphics->drawImage(button, mStickyRect.x, mStickyRect.y);
- }
-
- if (mGrip != nullptr)
- graphics->drawImage(mGrip, mGripRect.x, mGripRect.y);
-
- // Draw title
- if (mShowTitle)
- {
- int x;
- switch (mCaptionAlign)
- {
- case Graphics::LEFT:
- default:
- x = mCaptionOffsetX;
- break;
- case Graphics::CENTER:
- x = mCaptionOffsetX - mCaptionFont->getWidth(mCaption) / 2;
- break;
- case Graphics::RIGHT:
- x = mCaptionOffsetX - mCaptionFont->getWidth(mCaption);
- break;
- }
- if (mTextChanged)
- {
- mTextChunk.textFont = mCaptionFont;
- mTextChunk.deleteImage();
- mTextChunk.text = mCaption;
- mTextChunk.color = mForegroundColor;
- mTextChunk.color2 = mForegroundColor2;
- mCaptionFont->generate(mTextChunk);
- mTextChanged = false;
- }
-
- const Image *const image = mTextChunk.img;
- if (image != nullptr)
- graphics->drawImage(image, x, mCaptionOffsetY);
- }
-
- safeDrawChildren(graphics);
-
- BLOCK_END("Window::safeDraw")
-}
-
-void Window::setContentSize(int width, int height)
-{
- width = width + 2 * mPadding;
- height = height + mPadding + mTitleBarHeight;
-
- if (mMinWinWidth > width)
- width = mMinWinWidth;
- else if (mMaxWinWidth < width)
- width = mMaxWinWidth;
- if (mMinWinHeight > height)
- height = mMinWinHeight;
- else if (mMaxWinHeight < height)
- height = mMaxWinHeight;
-
- setSize(width, height);
-}
-
-void Window::setLocationRelativeTo(const Widget *const widget)
-{
- if (widget == nullptr)
- return;
-
- int wx, wy;
- int x, y;
-
- widget->getAbsolutePosition(wx, wy);
- getAbsolutePosition(x, y);
-
- setPosition(mDimension.x + (wx + (widget->getWidth()
- - mDimension.width) / 2 - x),
- mDimension.y + (wy + (widget->getHeight()
- - mDimension.height) / 2 - y));
-}
-
-void Window::setLocationHorisontallyRelativeTo(const Widget *const widget)
-{
- if (widget == nullptr)
- return;
-
- int wx, wy;
- int x, y;
-
- widget->getAbsolutePosition(wx, wy);
- getAbsolutePosition(x, y);
-
- setPosition(mDimension.x + (wx + (widget->getWidth()
- - mDimension.width) / 2 - x), 0);
-}
-
-void Window::setLocationRelativeTo(const ImagePosition::Type &position,
- int offsetX, int offsetY)
-{
- if (position == ImagePosition::UPPER_LEFT)
- {
- }
- else if (position == ImagePosition::UPPER_CENTER)
- {
- offsetX += (mainGraphics->mWidth - mDimension.width) / 2;
- }
- else if (position == ImagePosition::UPPER_RIGHT)
- {
- offsetX += mainGraphics->mWidth - mDimension.width;
- }
- else if (position == ImagePosition::LEFT)
- {
- offsetY += (mainGraphics->mHeight - mDimension.height) / 2;
- }
- else if (position == ImagePosition::CENTER)
- {
- offsetX += (mainGraphics->mWidth - mDimension.width) / 2;
- offsetY += (mainGraphics->mHeight - mDimension.height) / 2;
- }
- else if (position == ImagePosition::RIGHT)
- {
- offsetX += mainGraphics->mWidth - mDimension.width;
- offsetY += (mainGraphics->mHeight - mDimension.height) / 2;
- }
- else if (position == ImagePosition::LOWER_LEFT)
- {
- offsetY += mainGraphics->mHeight - mDimension.height;
- }
- else if (position == ImagePosition::LOWER_CENTER)
- {
- offsetX += (mainGraphics->mWidth - mDimension.width) / 2;
- offsetY += mainGraphics->mHeight - mDimension.height;
- }
- else if (position == ImagePosition::LOWER_RIGHT)
- {
- offsetX += mainGraphics->mWidth - mDimension.width;
- offsetY += mainGraphics->mHeight - mDimension.height;
- }
-
- setPosition(offsetX, offsetY);
-}
-
-void Window::setMinWidth(const int width)
-{
- if (mSkin != nullptr)
- {
- mMinWinWidth = width > mSkin->getMinWidth()
- ? width : mSkin->getMinWidth();
- }
- else
- {
- mMinWinWidth = width;
- }
-}
-
-void Window::setMinHeight(const int height)
-{
- if (mSkin != nullptr)
- {
- mMinWinHeight = height > mSkin->getMinHeight()
- ? height : mSkin->getMinHeight();
- }
- else
- {
- mMinWinHeight = height;
- }
-}
-
-void Window::setMaxWidth(const int width)
-{
- mMaxWinWidth = width;
-}
-
-void Window::setMaxHeight(const int height)
-{
- mMaxWinHeight = height;
-}
-
-void Window::setResizable(const bool r)
-{
- if ((mGrip != nullptr) == r)
- return;
-
- if (mGrip != nullptr)
- mGrip->decRef();
- if (r)
- {
- mGrip = Theme::getImageFromThemeXml("resize.xml", "");
- if (mGrip != nullptr)
- {
- mGripRect.x = mDimension.width - mGrip->getWidth() - mGripPadding;
- mGripRect.y = mDimension.height - mGrip->getHeight()
- - mGripPadding;
- }
- else
- {
- mGripRect.x = 0;
- mGripRect.y = 0;
- }
- }
- else
- {
- mGrip = nullptr;
- }
-}
-
-void Window::widgetResized(const Event &event A_UNUSED)
-{
- if (mGrip != nullptr)
- {
- mGripRect.x = mDimension.width - mGrip->getWidth() - mGripPadding;
- mGripRect.y = mDimension.height - mGrip->getHeight() - mGripPadding;
- }
-
- if (mLayout != nullptr)
- {
- const Rect area = getChildrenArea();
- int w = area.width;
- int h = area.height;
- mLayout->reflow(w, h);
- }
- if (mSkin != nullptr)
- {
- const bool showClose = mCloseWindowButton
- && (mSkin->getCloseImage(false) != nullptr);
- if (showClose)
- {
- const Image *const button = mSkin->getCloseImage(false);
- if (button != nullptr)
- {
- const int buttonWidth = button->getWidth();
- mCloseRect.x = mDimension.width - buttonWidth - mClosePadding;
- mCloseRect.y = mClosePadding;
- mCloseRect.width = buttonWidth;
- mCloseRect.height = button->getHeight();
- }
- }
- if (mStickyButton)
- {
- const Image *const button = mSkin->getStickyImage(mSticky);
- if (button != nullptr)
- {
- const int buttonWidth = button->getWidth();
- int x = mDimension.width - buttonWidth
- - mStickySpacing - mClosePadding;
-
- if (showClose)
- x -= mSkin->getCloseImage(false)->getWidth();
-
- mStickyRect.x = x;
- mStickyRect.y = mStickyPadding;
- mStickyRect.width = buttonWidth;
- mStickyRect.height = button->getHeight();
- }
- }
- }
- else
- {
- mCloseRect.x = 0;
- mCloseRect.y = 0;
- mCloseRect.width = 0;
- mCloseRect.height = 0;
- mStickyRect.x = 0;
- mStickyRect.y = 0;
- mStickyRect.width = 0;
- mStickyRect.height = 0;
- }
-
- mRedraw = true;
-}
-
-void Window::widgetMoved(const Event& event A_UNUSED)
-{
- mRedraw = true;
-}
-
-void Window::widgetHidden(const Event &event A_UNUSED)
-{
- if (isBatchDrawRenders(openGLMode))
- mVertexes->clear();
-
- mTextChunk.deleteImage();
-
- mTextChanged = true;
- mRedraw = true;
-
- if (gui != nullptr)
- gui->setCursorType(Cursor::CURSOR_POINTER);
-
- if (mFocusHandler == nullptr)
- return;
-
- for (WidgetListConstIterator it = mWidgets.begin();
- it != mWidgets.end(); ++ it)
- {
- if (mFocusHandler->isFocused(*it))
- mFocusHandler->focusNone();
- }
-}
-
-void Window::setCloseButton(const bool flag)
-{
- mCloseWindowButton = flag;
- if (flag)
- mAllowClose = true;
-}
-
-bool Window::isResizable() const
-{
- return mGrip != nullptr;
-}
-
-void Window::setStickyButton(const bool flag)
-{
- mStickyButton = flag;
-}
-
-void Window::setSticky(const bool sticky)
-{
- mSticky = sticky;
- mRedraw = true;
-}
-
-void Window::setStickyButtonLock(const bool lock)
-{
- mStickyButtonLock = lock;
- mStickyButton = lock;
-}
-
-void Window::setVisible(Visible visible)
-{
- setVisible(visible, false);
-}
-
-void Window::setVisible(const Visible visible, const bool forceSticky)
-{
- if (visible == mVisible)
- return;
-
- // Check if the window is off screen...
- if (visible == Visible_true)
- ensureOnScreen();
- else
- mResizeHandles = 0;
-
- if (mStickyButtonLock)
- {
- BasicContainer2::setVisible(visible);
- }
- else
- {
- BasicContainer2::setVisible(fromBool((!forceSticky && mSticky) ||
- visible == Visible_true, Visible));
- }
- if (visible == Visible_true)
- {
- if (mPlayVisibleSound)
- soundManager.playGuiSound(SOUND_SHOW_WINDOW);
- if (gui != nullptr)
- {
- MouseEvent *const event = reinterpret_cast<MouseEvent*>(
- gui->createMouseEvent(this));
- if (event != nullptr)
- {
- const int x = event->getX();
- const int y = event->getY();
- if (x >= 0 && x <= mDimension.width
- && y >= 0 && y <= mDimension.height)
- {
- mouseMoved(*event);
- }
- delete event;
- }
- }
- }
- else
- {
- if (mPlayVisibleSound)
- soundManager.playGuiSound(SOUND_HIDE_WINDOW);
- }
-}
-
-void Window::scheduleDelete()
-{
- windowContainer->scheduleDelete(this);
-}
-
-void Window::mousePressed(MouseEvent &event)
-{
- if (event.isConsumed())
- return;
-
- if (event.getSource() == this)
- {
- if (getParent() != nullptr)
- getParent()->moveToTop(this);
-
- mDragOffsetX = event.getX();
- mDragOffsetY = event.getY();
- mMoved = event.getY() <= CAST_S32(mTitleBarHeight);
- }
-
- const MouseButtonT button = event.getButton();
- if (button == MouseButton::LEFT)
- {
- const int x = event.getX();
- const int y = event.getY();
-
- // Handle close button
- if (mCloseWindowButton &&
- mSkin != nullptr &&
- mCloseRect.isPointInRect(x, y))
- {
- mouseResize = 0;
- mMoved = false;
- event.consume();
- close();
- return;
- }
-
- // Handle sticky button
- if (mStickyButton &&
- mSkin != nullptr &&
- mStickyRect.isPointInRect(x, y))
- {
- setSticky(!isSticky());
- mouseResize = 0;
- mMoved = false;
- event.consume();
- return;
- }
-
- // Handle window resizing
- mouseResize = getResizeHandles(event) & resizeMask;
- if (mouseResize != 0)
- event.consume();
- if (canMove())
- mMoved = (mouseResize == 0);
- else
- mMoved = false;
- }
-#ifndef DYECMD
- else if (button == MouseButton::RIGHT)
- {
- if (popupMenu != nullptr)
- {
- event.consume();
- popupMenu->showWindowPopup(this);
- }
- }
-#endif // DYECMD
-}
-
-void Window::close()
-{
- setVisible(Visible_false);
-}
-
-void Window::mouseReleased(MouseEvent &event A_UNUSED)
-{
- if ((mGrip != nullptr) && (mouseResize != 0))
- {
- mouseResize = 0;
- if (gui != nullptr)
- gui->setCursorType(Cursor::CURSOR_POINTER);
- }
-
- mMoved = false;
-}
-
-void Window::mouseEntered(MouseEvent &event)
-{
- updateResizeHandler(event);
-}
-
-void Window::mouseExited(MouseEvent &event A_UNUSED)
-{
- if ((mGrip != nullptr) && (mouseResize == 0) && (gui != nullptr))
- gui->setCursorType(Cursor::CURSOR_POINTER);
-}
-
-void Window::updateResizeHandler(MouseEvent &event)
-{
- if (gui == nullptr)
- return;
-
-#ifndef DYECMD
- if (!dragDrop.isEmpty())
- return;
-#endif // DYECMD
-
- mResizeHandles = getResizeHandles(event);
-
- // Changes the custom mouse cursor based on it's current position.
- switch (mResizeHandles & resizeMask)
- {
- case BOTTOM | RIGHT:
- case TOP | LEFT:
- gui->setCursorType(Cursor::CURSOR_RESIZE_DOWN_RIGHT);
- break;
- case TOP | RIGHT:
- case BOTTOM | LEFT:
- gui->setCursorType(Cursor::CURSOR_RESIZE_DOWN_LEFT);
- break;
- case BOTTOM:
- case TOP:
- gui->setCursorType(Cursor::CURSOR_RESIZE_DOWN);
- break;
- case RIGHT:
- case LEFT:
- gui->setCursorType(Cursor::CURSOR_RESIZE_ACROSS);
- break;
- default:
- gui->setCursorType(Cursor::CURSOR_POINTER);
- break;
- }
-}
-
-void Window::mouseMoved(MouseEvent &event)
-{
- updateResizeHandler(event);
- if ((popupManager != nullptr) && !event.isConsumed())
- {
- PopupManager::hideBeingPopup();
- PopupManager::hideTextPopup();
- }
-}
-
-bool Window::canMove() const
-{
- return !mStickyButtonLock || !mSticky;
-}
-
-void Window::mouseDragged(MouseEvent &event)
-{
- if (canMove())
- {
- if (!event.isConsumed() && event.getSource() == this)
- {
- if (isMovable() && mMoved)
- {
- setPosition(event.getX() - mDragOffsetX + getX(),
- event.getY() - mDragOffsetY + getY());
- }
-
- event.consume();
- }
- }
- else
- {
- if (!event.isConsumed() && event.getSource() == this)
- event.consume();
- return;
- }
-
- // Keep guichan window inside screen when it may be moved
- if (isMovable() && mMoved)
- {
- setPosition(std::min(mainGraphics->mWidth - mDimension.width,
- std::max(0, mDimension.x)),
- std::min(mainGraphics->mHeight - mDimension.height,
- std::max(0, mDimension.y)));
- }
-
- if ((mouseResize != 0) && !mMoved)
- {
- const int dx = event.getX() - mDragOffsetX;
- const int dy = event.getY() - mDragOffsetY;
- Rect newDim = getDimension();
-
- if ((mouseResize & (TOP | BOTTOM)) != 0)
- {
- const int newHeight = newDim.height
- + ((mouseResize & TOP) != 0 ? -dy : dy);
- newDim.height = std::min(mMaxWinHeight,
- std::max(mMinWinHeight, newHeight));
-
- if ((mouseResize & TOP) != 0)
- newDim.y -= newDim.height - getHeight();
- }
-
- if ((mouseResize & (LEFT | RIGHT)) != 0)
- {
- const int newWidth = newDim.width
- + ((mouseResize & LEFT) != 0 ? -dx : dx);
- newDim.width = std::min(mMaxWinWidth,
- std::max(mMinWinWidth, newWidth));
-
- if ((mouseResize & LEFT) != 0)
- newDim.x -= newDim.width - mDimension.width;
- }
-
- // Keep guichan window inside screen (supports resizing any side)
- if (newDim.x < 0)
- {
- newDim.width += newDim.x;
- newDim.x = 0;
- }
- if (newDim.y < 0)
- {
- newDim.height += newDim.y;
- newDim.y = 0;
- }
- if (newDim.x + newDim.width > mainGraphics->mWidth)
- newDim.width = mainGraphics->mWidth - newDim.x;
- if (newDim.y + newDim.height > mainGraphics->mHeight)
- newDim.height = mainGraphics->mHeight - newDim.y;
-
- // Update mouse offset when dragging bottom or right border
- if ((mouseResize & BOTTOM) != 0)
- mDragOffsetY += newDim.height - mDimension.height;
-
- if ((mouseResize & RIGHT) != 0)
- mDragOffsetX += newDim.width - mDimension.width;
-
- // Set the new window and content dimensions
- setDimension(newDim);
- }
-}
-
-void Window::setModal(const Modal modal)
-{
- if (mModal != modal)
- {
- mModal = modal;
- if (mModal == Modal_true)
- {
- if (gui != nullptr)
- gui->setCursorType(Cursor::CURSOR_POINTER);
- requestModalFocus();
- }
- else
- {
- releaseModalFocus();
- }
- }
-}
-
-void Window::loadWindowState()
-{
- const std::string &name = mWindowName;
- if (name.empty())
- return;
-
- setPosition(config.getValueInt(name + "WinX", mDefaultX),
- config.getValueInt(name + "WinY", mDefaultY));
-
- if (mSaveVisible)
- {
- setVisible(fromBool(config.getValueBool(name
- + "Visible", mDefaultVisible), Visible));
- }
-
- if (mStickyButton)
- {
- setSticky(config.getValueBool(name
- + "Sticky", isSticky()));
- }
-
- if (mGrip != nullptr)
- {
- int width = config.getValueInt(name + "WinWidth", mDefaultWidth);
- int height = config.getValueInt(name + "WinHeight", mDefaultHeight);
-
- if (getMinWidth() > width)
- width = getMinWidth();
- else if (getMaxWidth() < width)
- width = getMaxWidth();
- if (getMinHeight() > height)
- height = getMinHeight();
- else if (getMaxHeight() < height)
- height = getMaxHeight();
-
- setSize(width, height);
- }
- else
- {
- setSize(mDefaultWidth, mDefaultHeight);
- }
-
- // Check if the window is off screen...
- ensureOnScreen();
-
- if (viewport != nullptr)
- {
- int width = mDimension.width;
- int height = mDimension.height;
-
- if (mDimension.x + width > viewport->getWidth())
- width = viewport->getWidth() - mDimension.x;
- if (mDimension.y + height > viewport->getHeight())
- height = viewport->getHeight() - mDimension.y;
- if (width < 0)
- width = 0;
- if (height < 0)
- height = 0;
- setSize(width, height);
- }
-}
-
-void Window::saveWindowState()
-{
- // Saving X, Y and Width and Height for resizables in the config
- if (!mWindowName.empty() && mWindowName != "window")
- {
- config.setValue(mWindowName + "WinX", mDimension.x);
- config.setValue(mWindowName + "WinY", mDimension.y);
-
- if (mSaveVisible)
- config.setValue(mWindowName + "Visible", isWindowVisible());
-
- if (mStickyButton)
- config.setValue(mWindowName + "Sticky", isSticky());
-
- if (mGrip != nullptr)
- {
- if (getMinWidth() > mDimension.width)
- setWidth(getMinWidth());
- else if (getMaxWidth() < mDimension.width)
- setWidth(getMaxWidth());
- if (getMinHeight() > mDimension.height)
- setHeight(getMinHeight());
- else if (getMaxHeight() < mDimension.height)
- setHeight(getMaxHeight());
-
- config.setValue(mWindowName + "WinWidth", mDimension.width);
- config.setValue(mWindowName + "WinHeight", mDimension.height);
- }
- }
-}
-
-void Window::setDefaultSize(const int defaultX, const int defaultY,
- int defaultWidth, int defaultHeight)
-{
- if (mMinWinWidth > defaultWidth)
- defaultWidth = mMinWinWidth;
- else if (mMaxWinWidth < defaultWidth)
- defaultWidth = mMaxWinWidth;
- if (mMinWinHeight > defaultHeight)
- defaultHeight = mMinWinHeight;
- else if (mMaxWinHeight < defaultHeight)
- defaultHeight = mMaxWinHeight;
-
- mDefaultX = defaultX;
- mDefaultY = defaultY;
- mDefaultWidth = defaultWidth;
- mDefaultHeight = defaultHeight;
-}
-
-void Window::setDefaultSize()
-{
- mDefaultX = mDimension.x;
- mDefaultY = mDimension.y;
- mDefaultWidth = mDimension.width;
- mDefaultHeight = mDimension.height;
-}
-
-void Window::setDefaultSize(const int defaultWidth, const int defaultHeight,
- const ImagePosition::Type &position,
- const int offsetX, const int offsetY)
-{
- int x = 0;
- int y = 0;
-
- if (position == ImagePosition::UPPER_LEFT)
- {
- }
- else if (position == ImagePosition::UPPER_CENTER)
- {
- x = (mainGraphics->mWidth - defaultWidth) / 2;
- }
- else if (position == ImagePosition::UPPER_RIGHT)
- {
- x = mainGraphics->mWidth - defaultWidth;
- }
- else if (position == ImagePosition::LEFT)
- {
- y = (mainGraphics->mHeight - defaultHeight) / 2;
- }
- else if (position == ImagePosition::CENTER)
- {
- x = (mainGraphics->mWidth - defaultWidth) / 2;
- y = (mainGraphics->mHeight - defaultHeight) / 2;
- }
- else if (position == ImagePosition::RIGHT)
- {
- x = mainGraphics->mWidth - defaultWidth;
- y = (mainGraphics->mHeight - defaultHeight) / 2;
- }
- else if (position == ImagePosition::LOWER_LEFT)
- {
- y = mainGraphics->mHeight - defaultHeight;
- }
- else if (position == ImagePosition::LOWER_CENTER)
- {
- x = (mainGraphics->mWidth - defaultWidth) / 2;
- y = mainGraphics->mHeight - defaultHeight;
- }
- else if (position == ImagePosition::LOWER_RIGHT)
- {
- x = mainGraphics->mWidth - defaultWidth;
- y = mainGraphics->mHeight - defaultHeight;
- }
-
- mDefaultX = x - offsetX;
- mDefaultY = y - offsetY;
- mDefaultWidth = defaultWidth;
- mDefaultHeight = defaultHeight;
-}
-
-void Window::resetToDefaultSize()
-{
- setPosition(mDefaultX, mDefaultY);
- setSize(mDefaultWidth, mDefaultHeight);
- saveWindowState();
-}
-
-void Window::adjustPositionAfterResize(const int oldScreenWidth,
- const int oldScreenHeight)
-{
- // If window was aligned to the right or bottom, keep it there
- const int rightMargin = oldScreenWidth - (mDimension.x + mDimension.width);
- const int bottomMargin = oldScreenHeight
- - (mDimension.y + mDimension.height);
- if (mDimension.x > 0 && mDimension.x > rightMargin)
- mDimension.x = mainGraphics->mWidth - rightMargin - mDimension.width;
- if (mDimension.y > 0 && mDimension.y > bottomMargin)
- {
- mDimension.y = mainGraphics->mHeight
- - bottomMargin - mDimension.height;
- }
-
- ensureOnScreen();
- adjustSizeToScreen();
-}
-
-void Window::adjustSizeToScreen()
-{
- if (mGrip == nullptr)
- return;
-
- const int screenWidth = mainGraphics->mWidth;
- const int screenHeight = mainGraphics->mHeight;
- const int oldWidth = mDimension.width;
- const int oldHeight = mDimension.height;
- if (oldWidth + mDimension.x > screenWidth)
- mDimension.x = 0;
- if (oldHeight + mDimension.y > screenHeight)
- mDimension.x = 0;
- if (mDimension.width > screenWidth)
- mDimension.width = screenWidth;
- if (mDimension.height > screenHeight)
- mDimension.height = screenHeight;
- if (oldWidth != mDimension.width || oldHeight != mDimension.height)
- widgetResized(Event(this));
-}
-
-int Window::getResizeHandles(const MouseEvent &event)
-{
- if (event.getX() < 0 || event.getY() < 0)
- return 0;
-
- int resizeHandles = 0;
- const unsigned y = event.getY();
- const unsigned x = event.getX();
- if (mCloseRect.isPointInRect(x, y))
- return CLOSE;
-
- if (!mStickyButtonLock || !mSticky)
- {
- if ((mGrip != nullptr) &&
- (y > mTitleBarHeight ||
- (CAST_S32(y) < mPadding &&
- CAST_S32(mTitleBarHeight) > mPadding)))
- {
- if (!getWindowArea().isPointInRect(x, y)
- && event.getSource() == this)
- {
- resizeHandles |= (x > mDimension.width - resizeBorderWidth)
- ? RIGHT : (x < resizeBorderWidth) ? LEFT : 0;
- resizeHandles |= (y > mDimension.height - resizeBorderWidth)
- ? BOTTOM : (y < resizeBorderWidth) ? TOP : 0;
- }
- if (x >= CAST_U32(mGripRect.x)
- && y >= CAST_U32(mGripRect.y))
- {
- mDragOffsetX = x;
- mDragOffsetY = y;
- resizeHandles |= BOTTOM | RIGHT;
- }
- }
- }
-
- return resizeHandles;
-}
-
-bool Window::isResizeAllowed(const MouseEvent &event) const
-{
- const int y = event.getY();
-
- if ((mGrip != nullptr) &&
- (y > CAST_S32(mTitleBarHeight) ||
- y < mPadding))
- {
- const int x = event.getX();
-
- if (!getWindowArea().isPointInRect(x, y) && event.getSource() == this)
- return true;
-
- if (x >= mGripRect.x && y >= mGripRect.y)
- return true;
- }
-
- return false;
-}
-
-Layout &Window::getLayout()
-{
- if (mLayout == nullptr)
- mLayout = new Layout;
- return *mLayout;
-}
-
-void Window::clearLayout()
-{
- clear();
-
- // Recreate layout instance when one is present
- if (mLayout != nullptr)
- {
- delete mLayout;
- mLayout = new Layout;
- }
-}
-
-LayoutCell &Window::place(const int x, const int y, Widget *const wg,
- const int w, const int h)
-{
- add(wg);
- return getLayout().place(wg, x, y, w, h);
-}
-
-ContainerPlacer Window::getPlacer(const int x, const int y)
-{
- return ContainerPlacer(this, &getLayout().at(x, y));
-}
-
-void Window::reflowLayout(int w, int h)
-{
- if (mLayout == nullptr)
- return;
-
- mLayout->reflow(w, h);
- delete2(mLayout);
- setContentSize(w, h);
-}
-
-void Window::redraw()
-{
- if (mLayout != nullptr)
- {
- const Rect area = getChildrenArea();
- int w = area.width;
- int h = area.height;
- mLayout->reflow(w, h);
- }
-}
-
-void Window::center()
-{
- setLocationRelativeTo(getParent());
-}
-
-void Window::centerHorisontally()
-{
- setLocationHorisontallyRelativeTo(getParent());
-}
-
-void Window::ensureOnScreen()
-{
- // Skip when a window hasn't got any size initialized yet
- if (mDimension.width == 0 && mDimension.height == 0)
- return;
-
- // Check the left and bottom screen boundaries
- if (mDimension.x + mDimension.width > mainGraphics->mWidth)
- mDimension.x = mainGraphics->mWidth - mDimension.width;
- if (mDimension.y + mDimension.height > mainGraphics->mHeight)
- mDimension.y = mainGraphics->mHeight - mDimension.height;
-
- // But never allow the windows to disappear in to the right and top
- if (mDimension.x < 0)
- mDimension.x = 0;
- if (mDimension.y < 0)
- mDimension.y = 0;
-}
-
-Rect Window::getWindowArea() const
-{
- return Rect(mPadding,
- mPadding,
- mDimension.width - mPadding * 2,
- mDimension.height - mPadding * 2);
-}
-
-int Window::getOption(const std::string &name, const int def) const
-{
- if (mSkin != nullptr)
- {
- const int val = mSkin->getOption(name);
- if (val != 0)
- return val;
- return def;
- }
- return def;
-}
-
-bool Window::getOptionBool(const std::string &name, const bool def) const
-{
- if (mSkin != nullptr)
- return mSkin->getOption(name, static_cast<int>(def)) != 0;
- return def;
-}
-
-Rect Window::getChildrenArea()
-{
- return Rect(mPadding,
- mTitleBarHeight,
- mDimension.width - mPadding * 2,
- mDimension.height - mPadding - mTitleBarHeight);
-}
-
-void Window::resizeToContent()
-{
- int w = 0;
- int h = 0;
- for (WidgetListConstIterator it = mWidgets.begin();
- it != mWidgets.end(); ++ it)
- {
- const Widget *const widget = *it;
- const int x = widget->getX();
- const int y = widget->getY();
- const int width = widget->getWidth();
- const int height = widget->getHeight();
- if (x + width > w)
- w = x + width;
-
- if (y + height > h)
- h = y + height;
- }
-
- setSize(w + 2 * mPadding,
- h + mPadding + mTitleBarHeight);
-}
-
-#ifdef USE_PROFILER
-void Window::logic()
-{
- BLOCK_START("Window::logic")
- logicChildren();
- BLOCK_END("Window::logic")
-}
-#endif // USE_PROFILER
diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h
deleted file mode 100644
index d089680af..000000000
--- a/src/gui/widgets/window.h
+++ /dev/null
@@ -1,725 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_WINDOW_H
-#define GUI_WIDGETS_WINDOW_H
-
-#include "enums/simpletypes/modal.h"
-#include "enums/simpletypes/move.h"
-
-#include "enums/resources/imageposition.h"
-
-#include "gui/fonts/textchunk.h"
-
-#include "gui/widgets/basiccontainer2.h"
-
-#include "listeners/mouselistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "render/graphics.h"
-
-#include "localconsts.h"
-
-class ContainerPlacer;
-class ImageCollection;
-class Layout;
-class LayoutCell;
-class Skin;
-class WindowContainer;
-
-/**
- * A window. This window can be dragged around and has a title bar. Windows are
- * invisible by default.
- *
- * \ingroup GUI
- */
-class Window notfinal : public BasicContainer2,
- public MouseListener,
- public WidgetListener
-{
- public:
- /**
- * Constructor. Initializes the title to the given text and hooks
- * itself into the window container.
- *
- * @param caption The initial window title, "Window" by default.
- * @param modal Block input to other windows.
- * @param parent The parent window. This is the window standing above
- * this one in the window hiearchy. When reordering,
- * a window will never go below its parent window.
- * @param skin The location where the window's skin XML can be found.
- */
- explicit Window(const std::string &caption = "Window",
- const Modal modal = Modal_false,
- Window *const parent = nullptr,
- std::string skin = "");
-
- A_DELETE_COPY(Window)
-
- /**
- * Destructor. Deletes all the added widgets.
- */
- virtual ~Window();
-
- /**
- * Sets the window container to be used by new windows.
- */
- static void setWindowContainer(WindowContainer *const windowContainer);
-
- /**
- * Draws the window.
- */
- void draw(Graphics *const graphics) override A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override A_NONNULL(2);
-
- /**
- * Sets the size of this window.
- */
- void setContentSize(int width, int height);
-
- /**
- * Sets the location relative to the given widget.
- */
- void setLocationRelativeTo(const Widget *const widget);
-
- /**
- * Sets the location relative to the given widget (only horisontally)
- */
- void setLocationHorisontallyRelativeTo(const Widget
- *const widget);
-
- /**
- * Sets the location relative to the given enumerated position.
- */
- void setLocationRelativeTo(const ImagePosition::Type &position,
- int offsetX = 0, int offsetY = 0);
-
- /**
- * Sets whether or not the window can be resized.
- */
- void setResizable(const bool resize);
-
- void redraw();
-
- /**
- * Called whenever the widget changes size.
- */
- void widgetResized(const Event &event) override;
-
- void widgetMoved(const Event& event) override;
-
- /**
- * Called whenever the widget is hidden.
- */
- void widgetHidden(const Event &event) override;
-
- /**
- * Sets whether or not the window has a close button.
- */
- void setCloseButton(const bool flag);
-
- bool getCloseButton() const noexcept2 A_WARN_UNUSED
- { return mCloseWindowButton; }
-
- void setAllowClose(const bool b)
- { mAllowClose = b; }
-
- bool getAlowClose() const noexcept2 A_WARN_UNUSED
- { return mCloseWindowButton || mAllowClose; }
-
- /**
- * Returns whether the window can be resized.
- */
- bool isResizable() const A_WARN_UNUSED;
-
- /**
- * Sets the minimum width of the window.
- */
- void setMinWidth(const int width);
-
- int getMinWidth() const noexcept2 A_WARN_UNUSED
- { return mMinWinWidth; }
-
- /**
- * Sets the minimum height of the window.
- */
- void setMinHeight(const int height);
-
- int getMinHeight() const noexcept2 A_WARN_UNUSED
- { return mMinWinHeight; }
-
- /**
- * Sets the maximum width of the window.
- */
- void setMaxWidth(const int width);
-
- int getMaxWidth() const noexcept2 A_WARN_UNUSED
- { return mMaxWinWidth; }
-
- /**
- * Sets the minimum height of the window.
- */
- void setMaxHeight(const int height);
-
- int getMaxHeight() const noexcept2 A_WARN_UNUSED
- { return mMaxWinHeight; }
-
- /**
- * Sets flag to show a title or not.
- */
- void setShowTitle(bool flag)
- { mShowTitle = flag; }
-
- /**
- * Sets whether or not the window has a sticky button.
- */
- void setStickyButton(const bool flag);
-
- /**
- * Sets whether the window is sticky. A sticky window will not have
- * its visibility set to false on a general setVisible(false) call.
- * Use this to set the default before you call loadWindowState().
- */
- void setSticky(const bool sticky);
-
- /**
- * Returns whether the window is sticky.
- */
- bool isSticky() const noexcept2 A_WARN_UNUSED
- { return mSticky; }
-
- /**
- * Sets whether the window sticky mean window locked or not.
- */
- void setStickyButtonLock(const bool sticky);
-
- /**
- * Returns whether the window sticky locking window.
- */
- bool isStickyButtonLock() const noexcept2 A_WARN_UNUSED
- { return mStickyButtonLock; }
-
- /**
- * Overloads window setVisible by Guichan to allow sticky window
- * handling.
- */
- virtual void setVisible(Visible visible);
-
- /**
- * Overloads window setVisible by Guichan to allow sticky window
- * handling, or not, if you force the sticky state.
- */
- void setVisible(const Visible visible, const bool forceSticky);
-
- /**
- * Returns whether the window is visible by default.
- */
- bool isDefaultVisible() const noexcept2 A_WARN_UNUSED
- { return mDefaultVisible; }
-
- /**
- * Sets whether the window is visible by default.
- */
- void setDefaultVisible(const bool save)
- { mDefaultVisible = save; }
-
- /**
- * Returns whether the window will save it's visibility.
- */
- bool willSaveVisible() const
- { return mSaveVisible; }
-
- /**
- * Sets whether the window will save it's visibility.
- */
- void setSaveVisible(const bool save)
- { mSaveVisible = save; }
-
- void postInit() override;
-
- /**
- * Returns the parent window.
- *
- * @return The parent window or <code>NULL</code> if there is none.
- */
- Window *getParentWindow() const
- { return mParentWindow; }
-
- /**
- * Schedule this window for deletion. It will be deleted at the start
- * of the next logic update.
- */
- virtual void scheduleDelete();
-
- /**
- * Starts window resizing when appropriate.
- */
- void mousePressed(MouseEvent &event) override;
-
- /**
- * Implements window resizing and makes sure the window is not
- * dragged/resized outside of the screen.
- */
- void mouseDragged(MouseEvent &event) override;
-
- /**
- * Implements custom cursor image changing context, based on mouse
- * relative position.
- */
- void mouseMoved(MouseEvent &event) override;
-
- /**
- * When the mouse button has been let go, this ensures that the mouse
- * custom cursor is restored back to it's standard image.
- */
- void mouseReleased(MouseEvent &event) override;
-
- /**
- * When the mouse leaves the window this ensures that the custom cursor
- * is restored back to it's standard image.
- */
- void mouseExited(MouseEvent &event) override;
-
- void mouseEntered(MouseEvent &event) override;
-
- void updateResizeHandler(MouseEvent &event);
-
- /**
- * Sets the name of the window. This is not the window title.
- */
- void setWindowName(const std::string &name)
- { mWindowName = name; }
-
- /**
- * Returns the name of the window. This is not the window title.
- */
- const std::string &getWindowName() const noexcept2 A_WARN_UNUSED
- { return mWindowName; }
-
- /**
- * Reads the position (and the size for resizable windows) in the
- * configuration based on the given string.
- * Uses the default values when config values are missing.
- * Don't forget to set these default values and resizable before
- * calling this function.
- */
- void loadWindowState();
-
- /**
- * Saves the window state so that when the window is reloaded, it'll
- * maintain its previous state and location.
- */
- void saveWindowState();
-
- /**
- * Set the default win pos and size.
- * (which can be different of the actual ones.)
- */
- void setDefaultSize(const int defaultX, const int defaultY,
- int defaultWidth, int defaultHeight);
-
- /**
- * Set the default win pos and size to the current ones.
- */
- void setDefaultSize();
-
- /**
- * Set the default win pos and size.
- * (which can be different of the actual ones.)
- * This version of setDefaultSize sets the window's position based
- * on a relative enumerated position, rather than a coordinate position.
- */
- void setDefaultSize(const int defaultWidth, const int defaultHeight,
- const ImagePosition::Type &position,
- const int offsetx = 0, const int offsetY = 0);
-
- /**
- * Reset the win pos and size to default. Don't forget to set defaults
- * first.
- */
- virtual void resetToDefaultSize();
-
- /**
- * Adjusts the window position after the application window has been
- * resized.
- */
- void adjustPositionAfterResize(const int oldScreenWidth,
- const int oldScreenHeight);
-
- /**
- * Gets the layout handler for this window.
- */
- Layout &getLayout() A_WARN_UNUSED;
-
- /**
- * Clears the window's layout (useful for redesigning the window). Does
- * not delete the widgets!
- */
- void clearLayout();
-
- /**
- * Computes the position of the widgets according to the current
- * layout. Resizes the window so that the layout fits. Deletes the
- * layout.
- * @param w if non-zero, force the window to this width.
- * @param h if non-zero, force the window to this height.
- * @note This function is meant to be called with fixed-size windows.
- */
- void reflowLayout(int w = 0, int h = 0);
-
- /**
- * Adds a widget to the window and sets it at given cell.
- */
- LayoutCell &place(const int x, const int y, Widget *const wg,
- const int w = 1, const int h = 1);
-
- /**
- * Returns a proxy for adding widgets in an inner table of the layout.
- */
- ContainerPlacer getPlacer(const int x, const int y) A_WARN_UNUSED;
-
- /**
- * Positions the window in the center of it's parent.
- */
- void center();
-
- /**
- * Positions the window in the horisontal center of it's parent.
- */
- void centerHorisontally();
-
- /**
- * Overrideable functionality for when the window is to close. This
- * allows for class implementations to clean up or do certain actions
- * on window close they couldn't do otherwise.
- */
- virtual void close();
-
- /**
- * Allows the windows modal status to change
- */
- void setModal(const Modal modal);
-
- Rect getWindowArea() const A_WARN_UNUSED;
-
- bool isResizeAllowed(const MouseEvent &event) const A_WARN_UNUSED;
-
- void setCaptionFont(Font *font)
- { mCaptionFont = font; }
-
- void enableVisibleSound(bool b)
- { mPlayVisibleSound = b; }
-
- bool isWindowVisible() const noexcept2 A_WARN_UNUSED
- { return mVisible == Visible_true; }
-
- /**
- * Sets the padding of the window. The padding is the distance between the
- * window border and the content.
- *
- * @param padding The padding of the window.
- * @see getPadding
- */
- void setPadding(int padding)
- { mPadding = padding; }
-
- /**
- * Gets the padding of the window. The padding is the distance between the
- * window border and the content.
- *
- * @return The padding of the window.
- * @see setPadding
- */
- int getPadding() const
- { return mPadding; }
-
- /**
- * Sets the title bar height.
- *
- * @param height The title height value.
- * @see getTitleBarHeight
- */
- void setTitleBarHeight(unsigned int height)
- { mTitleBarHeight = height; }
-
- /**
- * Gets the title bar height.
- *
- * @return The title bar height.
- * @see setTitleBarHeight
- */
- unsigned int getTitleBarHeight() const
- { return mTitleBarHeight; }
-
- /**
- * Sets the caption of the window.
- *
- * @param caption The caption of the window.
- * @see getCaption
- */
- void setCaption(const std::string& caption)
- { mCaption = caption; mTextChanged = true; }
-
- /**
- * Gets the caption of the window.
- *
- * @return the caption of the window.
- * @see setCaption
- */
- const std::string& getCaption() const
- { return mCaption; }
-
- /**
- * Sets the alignment of the caption.
- *
- * @param alignment The alignment of the caption.
- * @see getAlignment, Graphics
- */
- void setAlignment(Graphics::Alignment alignment)
- { mAlignment = alignment; }
-
- /**
- * Gets the alignment of the caption.
- *
- * @return The alignment of caption.
- * @see setAlignment, Graphics
- */
- Graphics::Alignment getAlignment() const
- { return mAlignment; }
-
- /**
- * Sets the window to be moveble or not.
- *
- * @param movable True if the window should be movable, false otherwise.
- * @see isMovable
- */
- void setMovable(Move movable)
- { mMovable = movable; }
-
- /**
- * Checks if the window is movable.
- *
- * @return True if the window is movable, false otherwise.
- * @see setMovable
- */
- bool isMovable() const
- { return mMovable == Move_true; }
-
- Rect getChildrenArea() override;
-
- /**
- * Resizes the window to fit the content.
- */
- virtual void resizeToContent();
-
-#ifdef USE_PROFILER
- virtual void logic();
-#endif // USE_PROFILER
-
- protected:
- bool canMove() const A_WARN_UNUSED;
-
- int getOption(const std::string &name,
- const int def = 0) const A_WARN_UNUSED;
-
- bool getOptionBool(const std::string &name,
- const bool def = false) const A_WARN_UNUSED;
-
- void setTitlePadding(const int p) noexcept2
- { mTitlePadding = p; }
-
- int getTitlePadding() const noexcept2 A_WARN_UNUSED
- { return mTitlePadding; }
-
- /**
- * Holds the caption of the window.
- */
- std::string mCaption;
-
- /**
- * Holds the alignment of the caption.
- */
- Graphics::Alignment mAlignment;
-
- /**
- * Holds the padding of the window.
- */
- int mPadding;
-
- /**
- * Holds the title bar height of the window.
- */
- unsigned int mTitleBarHeight;
-
- /**
- * True if the window is movable, false otherwise.
- */
- Move mMovable;
-
- /**
- * Holds a drag offset as an x coordinate where the drag of the window
- * started if the window is being dragged. It's used to move the window
- * correctly when dragged.
- */
- int mDragOffsetX;
-
- /**
- * Holds a drag offset as an y coordinate where the drag of the window
- * started if the window is being dragged. It's used to move the window
- * correctly when dragged.
- */
- int mDragOffsetY;
-
- /**
- * True if the window is being moved, false otherwise.
- */
- bool mMoved;
-
- Skin *mSkin; /**< Skin in use by this window */
- int mDefaultX; /**< Default window X position */
- int mDefaultY; /**< Default window Y position */
- int mDefaultWidth; /**< Default window width */
- int mDefaultHeight; /**< Default window height */
- int mCaptionOffsetX;
- int mCaptionOffsetY;
- bool mShowTitle; /**< Window has a title bar */
- bool mLastRedraw;
-
- private:
- enum ResizeHandles
- {
- TOP = 0x01,
- RIGHT = 0x02,
- BOTTOM = 0x04,
- LEFT = 0x08,
- CLOSE = 0x10
- };
-
- /**
- * Ensures the window is on the screen, moving it if necessary. This is
- * used by loadWindowState and setVisible(true), and when the screen
- * is resized.
- */
- void ensureOnScreen();
-
- void adjustSizeToScreen();
-
- /**
- * Determines if the mouse is in a resize area and returns appropriate
- * resize handles. Also initializes drag offset in case the resize
- * grip is used.
- *
- * @see ResizeHandles
- */
- int getResizeHandles(const MouseEvent &event) A_WARN_UNUSED;
-
- Image *mGrip; /**< Resize grip */
- Window *mParentWindow; /**< The parent window */
- Layout *mLayout; /**< Layout handler */
- Rect mCloseRect; /**< Close button rectangle */
- Rect mStickyRect; /**< Sticky button rectangle */
- Rect mGripRect; /**< Resize grip rectangle */
- TextChunk mTextChunk;
- std::string mWindowName; /**< Name of the window */
- int mMinWinWidth; /**< Minimum window width */
- int mMinWinHeight; /**< Minimum window height */
- int mMaxWinWidth; /**< Maximum window width */
- int mMaxWinHeight; /**< Maximum window height */
-
- static int mouseResize; /**< Active resize handles */
- static int windowInstances; /**< Number of Window instances */
-
-
- /**
- * The width of the resize border. Is independent of the actual window
- * border width, and determines mostly the size of the corner area
- * where two borders are moved at the same time.
- */
- static const unsigned resizeBorderWidth = 10;
- ImageCollection *mVertexes A_NONNULLPOINTER;
- Graphics::Alignment mCaptionAlign;
- int mTitlePadding;
- int mGripPadding;
- int mResizeHandles;
- int mOldResizeHandles;
- int mClosePadding;
- int mStickySpacing;
- int mStickyPadding;
- Font *mCaptionFont A_NONNULLPOINTER;
- Modal mModal; /**< Window is modal */
- bool mCloseWindowButton; /**< Window has a close button */
- bool mDefaultVisible; /**< Window's default visibility */
- bool mSaveVisible; /**< Window will save visibility */
- bool mStickyButton; /**< Window has a sticky button */
- bool mSticky; /**< Window resists hiding*/
- bool mStickyButtonLock; /**< Window locked if sticky enabled*/
- bool mPlayVisibleSound;
- bool mInit;
- bool mTextChanged;
- bool mAllowClose;
-};
-
-#endif // GUI_WIDGETS_WINDOW_H
diff --git a/src/gui/widgets/windowcontainer.cpp b/src/gui/widgets/windowcontainer.cpp
deleted file mode 100644
index e054e27ad..000000000
--- a/src/gui/widgets/windowcontainer.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/windowcontainer.h"
-
-#include "gui/widgets/window.h"
-
-#include "utils/dtor.h"
-#include "utils/foreach.h"
-
-#include "debug.h"
-
-WindowContainer *windowContainer = nullptr;
-
-WindowContainer::WindowContainer(const Widget2 *const widget) :
- Container(widget),
- mDeathList()
-{
-}
-
-void WindowContainer::slowLogic()
-{
- delete_all(mDeathList);
- mDeathList.clear();
-}
-
-void WindowContainer::scheduleDelete(Widget *const widget)
-{
- if (widget != nullptr)
- mDeathList.push_back(widget);
-}
-
-void WindowContainer::adjustAfterResize(const int oldScreenWidth,
- const int oldScreenHeight)
-{
- FOR_EACH (WidgetListIterator, i, mWidgets)
- {
- if (Window *const window = dynamic_cast<Window*>(*i))
- window->adjustPositionAfterResize(oldScreenWidth, oldScreenHeight);
- }
-}
-
-void WindowContainer::moveWidgetAfter(Widget *const after,
- Widget *const widget)
-{
- const WidgetListIterator widgetIter = std::find(
- mWidgets.begin(), mWidgets.end(), widget);
-
- if (widgetIter != mWidgets.end())
- {
- WidgetListIterator afterIter = std::find(
- mWidgets.begin(), mWidgets.end(), after);
-
- if (afterIter != mWidgets.end())
- {
- ++ afterIter;
- mWidgets.erase(widgetIter);
- mWidgets.insert(afterIter, widget);
- }
- }
-
- const WidgetListIterator widgetIter2 = std::find(
- mLogicWidgets.begin(), mLogicWidgets.end(), widget);
-
- if (widgetIter2 != mLogicWidgets.end())
- {
- WidgetListIterator afterIter = std::find(
- mLogicWidgets.begin(), mLogicWidgets.end(), after);
-
- if (afterIter != mLogicWidgets.end())
- {
- ++ afterIter;
- mLogicWidgets.erase(widgetIter2);
- mLogicWidgets.insert(afterIter, widget);
- }
- }
-}
-
-#ifdef USE_PROFILER
-void WindowContainer::draw(Graphics *const graphics)
-{
- BLOCK_START("WindowContainer::draw")
- Container::draw(graphics);
- BLOCK_END("WindowContainer::draw")
-}
-#endif // USE_PROFILER
diff --git a/src/gui/widgets/windowcontainer.h b/src/gui/widgets/windowcontainer.h
deleted file mode 100644
index 98a62ac28..000000000
--- a/src/gui/widgets/windowcontainer.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_WINDOWCONTAINER_H
-#define GUI_WIDGETS_WINDOWCONTAINER_H
-
-#include "gui/widgets/container.h"
-
-/**
- * A window container. This container adds functionality for more convenient
- * widget (windows in particular) destruction.
- *
- * \ingroup GUI
- */
-class WindowContainer notfinal : public Container
-{
- public:
- explicit WindowContainer(const Widget2 *const widget);
-
- A_DELETE_COPY(WindowContainer)
-
- void slowLogic();
-
- /**
- * Schedule a widget for deletion. It will be deleted at the start of
- * the next logic update.
- */
- void scheduleDelete(Widget *const widget);
-
- /**
- * Ensures that all visible windows are on the screen after the screen
- * has been resized.
- */
- void adjustAfterResize(const int oldScreenWidth,
- const int oldScreenHeight);
-
- void moveWidgetAfter(Widget *const before,
- Widget *const widget);
-
-#ifdef USE_PROFILER
- void draw(Graphics *const graphics) override A_NONNULL(2);
-#endif // UNITTESTS
-
- private:
- /**
- * List of widgets that are scheduled to be deleted.
- */
- typedef STD_VECTOR<Widget*> Widgets;
- typedef Widgets::iterator WidgetIterator;
- Widgets mDeathList;
-};
-
-extern WindowContainer *windowContainer;
-
-#endif // GUI_WIDGETS_WINDOWCONTAINER_H
diff --git a/src/gui/windowmanager.cpp b/src/gui/windowmanager.cpp
deleted file mode 100644
index c7b81d1a9..000000000
--- a/src/gui/windowmanager.cpp
+++ /dev/null
@@ -1,498 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windowmanager.h"
-
-#include "client.h"
-#include "configuration.h"
-#include "game.h"
-#include "main.h"
-#include "settings.h"
-#include "spellmanager.h"
-
-#include "fs/virtfs/tools.h"
-
-#include "gui/gui.h"
-#include "gui/userpalette.h"
-
-#include "gui/shortcut/spellshortcut.h"
-
-#include "gui/popups/textpopup.h"
-
-#ifdef DYECMD
-#include "render/graphics.h"
-#else // DYECMD
-#include "gui/popups/beingpopup.h"
-#include "gui/popups/itempopup.h"
-#include "gui/popups/popupmenu.h"
-#include "gui/popups/skillpopup.h"
-#include "gui/popups/spellpopup.h"
-#include "gui/popups/textboxpopup.h"
-
-#include "gui/windows/chatwindow.h"
-#include "gui/windows/debugwindow.h"
-#include "gui/windows/didyouknowwindow.h"
-#include "gui/windows/equipmentwindow.h"
-#include "gui/windows/helpwindow.h"
-#include "gui/windows/setupwindow.h"
-#include "gui/windows/skilldialog.h"
-#include "gui/windows/questswindow.h"
-
-#include "gui/widgets/tabs/chat/chattab.h"
-
-#include "utils/gettext.h"
-#endif // DYECMD
-
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/desktop.h"
-
-#include "input/touch/touchmanager.h"
-
-#include "utils/delete2.h"
-#include "utils/sdlcheckutils.h"
-#include "utils/sdlhelper.h"
-#ifdef __native_client__
-#include "utils/naclmessages.h"
-#endif // __native_client__
-
-PRAGMA48(GCC diagnostic push)
-PRAGMA48(GCC diagnostic ignored "-Wshadow")
-#ifdef ANDROID
-#ifndef USE_SDL2
-#include <SDL_screenkeyboard.h>
-#endif // USE_SDL2
-#endif // ANDROID
-
-#ifdef USE_SDL2
-#include <SDL2_framerate.h>
-#else // USE_SDL2
-#include <SDL_framerate.h>
-#endif // USE_SDL2
-
-#include <SDL_image.h>
-
-#ifdef WIN32
-#include <SDL_syswm.h>
-#endif // WIN32
-PRAGMA48(GCC diagnostic pop)
-
-#include "debug.h"
-
-FPSmanager fpsManager;
-
-namespace
-{
- SDL_Surface *mIcon(nullptr);
-#ifndef USE_SDL2
- int mKeyboardHeight(0);
-#endif // USE_SDL2
-
- bool mIsMinimized(false);
- bool mNewMessageFlag(false);
-} // namespace
-
-void WindowManager::init()
-{
- // Initialize frame limiting
- fpsManager.framecount = 0;
- fpsManager.rateticks = 0;
- fpsManager.lastticks = 0;
- fpsManager.rate = 0;
-}
-
-void WindowManager::createWindows()
-{
- userPalette = new UserPalette;
-#ifndef DYECMD
- CREATEWIDGETV0(setupWindow, SetupWindow);
- CREATEWIDGETV0(helpWindow, HelpWindow);
- CREATEWIDGETV0(didYouKnowWindow, DidYouKnowWindow);
- CREATEWIDGETV0(popupMenu, PopupMenu);
- CREATEWIDGETV0(beingPopup, BeingPopup);
- CREATEWIDGETV0(textBoxPopup, TextBoxPopup);
- CREATEWIDGETV0(itemPopup, ItemPopup);
- CREATEWIDGETV0(spellPopup, SpellPopup);
- CREATEWIDGETV0(skillPopup, SkillPopup);
- delete2(debugChatTab);
- if (chatWindow != nullptr)
- {
- chatWindow->scheduleDelete();
- chatWindow = nullptr;
- }
- CREATEWIDGETV(chatWindow, ChatWindow,
- "DebugChat");
- // TRANSLATORS: chat tab header
- debugChatTab = new ChatTab(chatWindow, _("Debug"), "",
- "#Debug", ChatTabType::DEBUG);
- debugChatTab->setAllowHighlight(false);
- chatWindow->setVisible(Visible_false);
- if (debugWindow != nullptr)
- {
- debugWindow->scheduleDelete();
- debugWindow = nullptr;
- }
- CREATEWIDGETV(debugWindow, DebugWindow,
- "DebugDebug");
-#endif // DYECMD
-
- CREATEWIDGETV0(textPopup, TextPopup);
-}
-
-void WindowManager::createValidateWindows()
-{
-#ifndef DYECMD
- CREATEWIDGETV0(skillDialog, SkillDialog);
- skillDialog->loadSkills();
- CREATEWIDGETV(beingEquipmentWindow, EquipmentWindow,
- nullptr, nullptr, true);
- CREATEWIDGETV0(questsWindow, QuestsWindow);
-#endif // DYECMD
-}
-
-void WindowManager::deleteValidateWindows()
-{
-#ifndef DYECMD
- delete2(skillDialog);
- delete2(beingEquipmentWindow);
- delete2(questsWindow);
-#endif // DYECMD
-}
-
-void WindowManager::deleteWindows()
-{
-#ifndef DYECMD
- delete2(textBoxPopup);
- delete2(beingPopup);
- delete2(itemPopup);
- delete2(spellPopup);
- delete2(skillPopup);
- delete2(popupMenu);
- delete2(didYouKnowWindow);
- delete2(helpWindow);
- delete2(setupWindow);
- delete2(userPalette);
- delete2(spellManager)
- delete2(spellShortcut)
-
- delete2(debugChatTab);
- delete2(chatWindow);
- delete2(debugWindow);
-#endif // DYECMD
-
- delete2(textPopup);
-}
-
-void WindowManager::initTitle()
-{
- if (settings.options.test.empty())
- {
- settings.windowCaption = strprintf("%s %s",
- branding.getStringValue("appName").c_str(),
- SMALL_VERSION);
- }
- else
- {
- settings.windowCaption = strprintf(
- "Please wait - VIDEO MODE TEST - %s %s - Please wait",
- branding.getStringValue("appName").c_str(),
- SMALL_VERSION);
- }
-
- SDL::SetWindowTitle(mainGraphics->getWindow(),
- settings.windowCaption.c_str());
-}
-
-void WindowManager::updateTitle()
-{
- std::string str;
- if (settings.login.empty())
- str = settings.serverName;
- else
- str.append(settings.login).append(" ").append(settings.serverName);
- if (str.empty())
- {
- settings.windowCaption = strprintf("%s %s",
- branding.getStringValue("appName").c_str(),
- SMALL_VERSION);
- }
- else
- {
- settings.windowCaption = strprintf("%s %s - %s",
- branding.getStringValue("appName").c_str(),
- SMALL_VERSION,
- str.c_str());
- }
- SDL::SetWindowTitle(mainGraphics->getWindow(),
- settings.windowCaption.c_str());
-}
-
-void WindowManager::setFramerate(const unsigned int fpsLimit)
-{
- if (fpsLimit == 0u)
- return;
-
- if (!settings.limitFps)
- return;
-
- SDL_setFramerate(&fpsManager, fpsLimit);
-}
-
-int WindowManager::getFramerate()
-{
- if (!settings.limitFps)
- return 0;
-
- return SDL_getFramerate(&fpsManager);
-}
-
-void WindowManager::doResizeVideo(const int actualWidth,
- const int actualHeight,
- const bool always)
-{
- if (!always
- && mainGraphics->mActualWidth == actualWidth
- && mainGraphics->mActualHeight == actualHeight)
- {
- return;
- }
-
-#ifdef __native_client__
- naclPostMessage("resize-window",
- strprintf("%d,%d", actualWidth, actualHeight));
-#else // __native_client__
-
- resizeVideo(actualWidth, actualHeight, always);
-#endif // __native_client__
-}
-
-void WindowManager::resizeVideo(int actualWidth,
- int actualHeight,
- const bool always)
-{
- // Keep a minimum size. This isn't adhered to by the actual window, but
- // it keeps some window positions from getting messed up.
- actualWidth = std::max(470, actualWidth);
- actualHeight = std::max(320, actualHeight);
-
- if (mainGraphics == nullptr)
- return;
- if (!always
- && mainGraphics->mActualWidth == actualWidth
- && mainGraphics->mActualHeight == actualHeight)
- {
- return;
- }
-
- if (mainGraphics->resizeScreen(actualWidth, actualHeight))
- {
- const int width = mainGraphics->mWidth;
- const int height = mainGraphics->mHeight;
- touchManager.resize(width, height);
-
- if (gui != nullptr)
- gui->videoResized();
-
- if (desktop != nullptr)
- desktop->setSize(width, height);
-
- client->moveButtons(width);
-
-#ifndef DYECMD
- Game *const game = Game::instance();
- if (game != nullptr)
- Game::videoResized(width, height);
-#endif // DYECMD
-
- if (gui != nullptr)
- gui->draw();
-
- config.setValue("screenwidth", actualWidth);
- config.setValue("screenheight", actualHeight);
- }
-}
-
-bool WindowManager::setFullScreen(const bool fs)
-{
-#ifdef __native_client__
- naclPostMessage("set-fullscreen",
- fs ? "on" : "off");
- return true;
-#else // __native_client__
-
- if (mainGraphics == nullptr)
- return false;
- return mainGraphics->setFullscreen(fs);
-#endif // __native_client__
-}
-
-void WindowManager::applyGrabMode()
-{
- SDL::grabInput(mainGraphics->getWindow(),
- config.getBoolValue("grabinput"));
-}
-
-void WindowManager::applyGamma()
-{
- if (config.getBoolValue("enableGamma"))
- {
- SDL::setGamma(mainGraphics->getWindow(),
- config.getFloatValue("gamma"));
- }
-}
-
-void WindowManager::applyVSync()
-{
- const int val = config.getIntValue("vsync");
- if (val > 0 && val < 2)
- SDL::setVsync(val);
-}
-
-void WindowManager::applyKeyRepeat()
-{
-#ifndef USE_SDL2
- SDL_EnableKeyRepeat(config.getIntValue("repeateDelay"),
- config.getIntValue("repeateInterval"));
-#endif // USE_SDL2
-}
-
-void WindowManager::applyScale()
-{
- const int scale = config.getIntValue("scale");
- if (mainGraphics->getScale() == scale)
- return;
- mainGraphics->setScale(scale);
- doResizeVideo(mainGraphics->mActualWidth,
- mainGraphics->mActualHeight,
- true);
-}
-
-void WindowManager::setIsMinimized(const bool n)
-{
- mIsMinimized = n;
- if (!n && mNewMessageFlag)
- {
- mNewMessageFlag = false;
- SDL::SetWindowTitle(mainGraphics->getWindow(),
- settings.windowCaption.c_str());
- }
-}
-
-void WindowManager::newChatMessage()
-{
- if (!mNewMessageFlag && mIsMinimized)
- {
- // show * on window caption
- SDL::SetWindowTitle(mainGraphics->getWindow(),
- ("*" + settings.windowCaption).c_str());
- mNewMessageFlag = true;
- }
-}
-
-void WindowManager::setIcon()
-{
-#ifndef ANDROID
- std::string iconFile = branding.getValue("appIcon", "icons/manaplus");
-#ifdef WIN32
- iconFile.append(".ico");
-#else // WIN32
-
- iconFile.append(".png");
-#endif // WIN32
-
- iconFile = VirtFs::getPath(iconFile);
- logger->log("Loading icon from file: %s", iconFile.c_str());
-
-#ifdef WIN32
- static SDL_SysWMinfo pInfo;
- if (mainGraphics)
- SDL::getWindowWMInfo(mainGraphics->getWindow(), &pInfo);
- else
- SDL::getWindowWMInfo(nullptr, &pInfo);
- // Attempt to load icon from .ico file
- HICON icon = static_cast<HICON>(LoadImage(nullptr,
- iconFile.c_str(),
- IMAGE_ICON,
- 64, 64,
- LR_LOADFROMFILE));
- // If it's failing, we load the default resource file.
- if (!icon)
- {
- logger->log("icon load error");
- icon = LoadIcon(GetModuleHandle(nullptr), "A");
- }
- if (icon)
- {
-#ifdef WIN64
- SetClassLongPtr(pInfo.window,
- GCLP_HICON,
- reinterpret_cast<LONG_PTR>(icon));
-#else // WIN64
- SetClassLong(pInfo.window,
- GCL_HICON,
- reinterpret_cast<LONG>(icon));
-#endif // WIN64
- }
-#else // WIN32
-
- mIcon = MIMG_Load(iconFile.c_str());
- if (mIcon != nullptr)
- {
-#ifdef USE_SDL2
- SDL_SetSurfaceAlphaMod(mIcon, SDL_ALPHA_OPAQUE);
-#else // USE_SDL2
-
- SDL_SetAlpha(mIcon, SDL_SRCALPHA, SDL_ALPHA_OPAQUE);
-#endif // USE_SDL2
-
- SDL::SetWindowIcon(mainGraphics->getWindow(), mIcon);
- }
-#endif // WIN32
-#endif // ANDROID
-}
-
-bool WindowManager::isKeyboardVisible()
-{
-#ifdef USE_SDL2
- return SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE;
-#else // USE_SDL2
-
- return mKeyboardHeight > 1;
-#endif // USE_SDL2
-}
-
-bool WindowManager::getIsMinimized()
-{
- return mIsMinimized;
-}
-
-#ifndef USE_SDL2
-void WindowManager::updateScreenKeyboard(const int height)
-{
- mKeyboardHeight = height;
-}
-#endif // USE_SDL2
-
-void WindowManager::deleteIcon()
-{
- MSDL_FreeSurface(mIcon);
- mIcon = nullptr;
-}
diff --git a/src/gui/windowmanager.h b/src/gui/windowmanager.h
deleted file mode 100644
index 8662f39a1..000000000
--- a/src/gui/windowmanager.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWMANAGER_H
-#define GUI_WINDOWMANAGER_H
-
-#include "localconsts.h"
-
-namespace WindowManager
-{
- void init();
-
- bool getIsMinimized() A_WARN_UNUSED;
-
- void setIsMinimized(const bool n);
-
- void newChatMessage();
-
- bool isKeyboardVisible();
-
- void setFramerate(const unsigned int fpsLimit);
-
- int getFramerate() A_WARN_UNUSED;
-
- void applyGrabMode();
-
- void applyGamma();
-
- void applyVSync();
-
- void applyKeyRepeat();
-
- void doResizeVideo(const int actualWidth,
- const int actualHeight,
- const bool always);
-
- void resizeVideo(int actualWidth,
- int actualHeight,
- const bool always);
-
- bool setFullScreen(const bool fs);
-
- void applyScale();
-
-#ifndef USE_SDL2
- void updateScreenKeyboard(const int height);
-#endif // USE_SDL2
-
- void reloadWallpaper();
-
- void createWindows();
-
- void deleteWindows();
-
- void initTitle();
-
- void setIcon();
-
- void deleteIcon();
-
- void updateTitle();
-
- void createValidateWindows();
-
- void deleteValidateWindows();
-} // namespace WindowManager
-
-#endif // GUI_WINDOWMANAGER_H
diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp
deleted file mode 100644
index 477aa719d..000000000
--- a/src/gui/windowmenu.cpp
+++ /dev/null
@@ -1,493 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windowmenu.h"
-
-#include "configuration.h"
-
-#include "input/inputmanager.h"
-
-#include "gui/buttoninfo.h"
-#include "gui/buttontext.h"
-#include "gui/popupmanager.h"
-#include "gui/skin.h"
-
-#include "gui/popups/popupmenu.h"
-#include "gui/popups/textpopup.h"
-
-#include "gui/windows/skilldialog.h"
-
-#include "gui/widgets/button.h"
-
-#include "utils/dtor.h"
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-WindowMenu *windowMenu = nullptr;
-
-WindowMenu::WindowMenu(const Widget2 *const widget) :
- Container(widget),
- ConfigListener(),
- ActionListener(),
- SelectionListener(),
- MouseListener(),
- mSkin(theme != nullptr ? theme->load("windowmenu.xml", "") : nullptr),
- mPadding(mSkin != nullptr ? mSkin->getPadding() : 1),
- mSpacing(mSkin != nullptr ? mSkin->getOption("spacing", 3) : 3),
- mButtons(),
- mButtonTexts(),
- mButtonNames(),
- mHaveMouse(false),
- mAutoHide(1),
- mSmallWindow(mainGraphics->getWidth() < 600)
-{
- int x = mPadding;
- int h = 0;
-
- setFocusable(false);
- // TRANSLATORS: short button name for who is online window.
- addButton(N_("ONL"),
- // TRANSLATORS: long button name for who is online window.
- _("Who is online"), x, h, InputAction::WINDOW_ONLINE);
- // TRANSLATORS: short button name for help window.
- addButton(N_("HLP"),
- // TRANSLATORS: long button name for help window.
- _("Help"), x, h, InputAction::WINDOW_HELP);
- // TRANSLATORS: short button name for quests window.
- addButton(N_("QE"),
- // TRANSLATORS: long button name for quests window.
- _("Quests"), x, h, InputAction::WINDOW_QUESTS);
- // TRANSLATORS: short button name for kill stats window.
- addButton(N_("KS"),
- // TRANSLATORS: long button name for kill stats window.
- _("Kill stats"), x, h, InputAction::WINDOW_KILLS);
- addButton(":-)",
- // TRANSLATORS: long button name for emotes window.
- _("Smilies"), x, h, InputAction::WINDOW_EMOTE_SHORTCUT);
- // TRANSLATORS: short button name for chat window.
- addButton(N_("CH"),
- // TRANSLATORS: longt button name for chat window.
- _("Chat"), x, h, InputAction::WINDOW_CHAT,
-#ifdef ANDROID
- Visible_true);
-#else // ANDROID
- Visible_false);
-#endif // ANDROID
-
- // TRANSLATORS: short button name for status window.
- addButton(N_("STA"),
- // TRANSLATORS: long button name for status window.
- _("Status"), x, h, InputAction::WINDOW_STATUS);
- // TRANSLATORS: short button name for equipment window.
- addButton(N_("EQU"),
- // TRANSLATORS: long button name for equipment window.
- _("Equipment"), x, h, InputAction::WINDOW_EQUIPMENT);
- // TRANSLATORS: short button name for inventory window.
- addButton(N_("INV"),
- // TRANSLATORS: long button name for inventory window.
- _("Inventory"), x, h, InputAction::WINDOW_INVENTORY);
- // TRANSLATORS: short button name for cart window.
- addButton(N_("CA"),
- // TRANSLATORS: long button name for cart window.
- _("Cart"), x, h, InputAction::WINDOW_CART);
- // TRANSLATORS: short button name for map window.
- addButton(N_("MAP"),
- // TRANSLATORS: long button name for map window.
- _("Map"), x, h, InputAction::WINDOW_MINIMAP,
- Visible_false);
-
- if (skillDialog->hasSkills())
- {
- // TRANSLATORS: short button name for skills window.
- addButton(N_("SKI"),
- // TRANSLATORS: long button name for skills window.
- _("Skills"), x, h, InputAction::WINDOW_SKILL);
- }
-
- // TRANSLATORS: short button name for social window.
- addButton(N_("SOC"),
- // TRANSLATORS: long button name for social window.
- _("Social"), x, h, InputAction::WINDOW_SOCIAL);
- // TRANSLATORS: short button name for shortcuts window.
- addButton(N_("SH"),
- // TRANSLATORS: long button name for shortcuts window.
- _("Shortcuts"), x, h, InputAction::WINDOW_SHORTCUT);
- // TRANSLATORS: short button name for spells window.
- addButton(N_("SP"),
- // TRANSLATORS: long button name for spells window.
- _("Spells"), x, h, InputAction::WINDOW_SPELLS);
- // TRANSLATORS: short button name for drops window.
- addButton(N_("DR"),
- // TRANSLATORS: long button name for drops window.
- _("Drop"), x, h, InputAction::WINDOW_DROP,
- Visible_false);
- // TRANSLATORS: short button name for did you know window.
- addButton(N_("YK"),
- // TRANSLATORS: long button name for did you know window.
- _("Did you know"), x, h, InputAction::WINDOW_DIDYOUKNOW,
- Visible_false);
- // TRANSLATORS: short button name for shop window.
- addButton(N_("SHP"),
- // TRANSLATORS: long button name for shop window.
- _("Shop"), x, h, InputAction::WINDOW_SHOP,
- Visible_false);
- // TRANSLATORS: short button name for outfits window.
- addButton(N_("OU"),
- // TRANSLATORS: long button name for outfits window.
- _("Outfits"), x, h, InputAction::WINDOW_OUTFIT,
- Visible_false);
- // TRANSLATORS: short button name for updates window.
- addButton(N_("UP"),
- // TRANSLATORS: long button name for updates window.
- _("Updates"), x, h, InputAction::WINDOW_UPDATER,
- Visible_false);
- // TRANSLATORS: short button name for bank window.
- addButton(N_("BA"),
- // TRANSLATORS: long button name for bank window.
- _("Bank"), x, h, InputAction::WINDOW_BANK,
- Visible_true);
- // TRANSLATORS: short button name for mail window.
- addButton(N_("MA"),
- // TRANSLATORS: long button name for mail window.
- _("Mail"), x, h, InputAction::WINDOW_MAIL,
- Visible_true);
- // TRANSLATORS: short button name for server info window.
- addButton(N_("SI"),
- // TRANSLATORS: long button name for server info window.
- _("Server info"), x, h, InputAction::WINDOW_SERVER_INFO,
- Visible_true);
- // TRANSLATORS: short button name for debug window.
- addButton(N_("DBG"),
- // TRANSLATORS: long button name for debug window.
- _("Debug"), x, h, InputAction::WINDOW_DEBUG,
-#ifdef ANDROID
- Visible_true);
-#else // ANDROID
- Visible_false);
-#endif // ANDROID
-
- // TRANSLATORS: short button name for windows list menu.
- addButton(N_("WIN"),
- // TRANSLATORS: long button name for windows list menu.
- _("Windows"), x, h, InputAction::SHOW_WINDOWS,
- Visible_false);
- // TRANSLATORS: short button name for setup window.
- addButton(N_("SET"),
- // TRANSLATORS: long button name for setup window.
- _("Setup"), x, h, InputAction::WINDOW_SETUP);
-
- x += mPadding - mSpacing;
- if (mainGraphics != nullptr)
- setDimension(Rect(mainGraphics->mWidth - x, 0, x, h));
-
- loadButtons();
-
- addMouseListener(this);
- setVisible(Visible_true);
-
- config.addListener("autohideButtons", this);
- mAutoHide = config.getIntValue("autohideButtons");
-}
-
-WindowMenu::~WindowMenu()
-{
- config.removeListener("autohideButtons", this);
- CHECKLISTENERS
-
- for (std::map <std::string, ButtonInfo*>::iterator
- it = mButtonNames.begin(),
- it_fend = mButtonNames.end(); it != it_fend; ++it)
- {
- delete (*it).second;
- }
- mButtonNames.clear();
- FOR_EACH (STD_VECTOR <Button*>::iterator, it, mButtons)
- {
- Button *const btn = *it;
- if (btn == nullptr)
- continue;
- if (btn->mVisible == Visible_false)
- delete btn;
- }
- delete_all(mButtonTexts);
- mButtonTexts.clear();
- if (mSkin != nullptr)
- {
- if (theme != nullptr)
- theme->unload(mSkin);
- mSkin = nullptr;
- }
-}
-
-void WindowMenu::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- const std::map <std::string, ButtonInfo*>::iterator
- it = mButtonNames.find(eventId);
- if (it == mButtonNames.end())
- return;
-
- const ButtonInfo *const info = (*it).second;
- if (info == nullptr)
- return;
-
- inputManager.executeAction(info->key);
-}
-
-void WindowMenu::addButton(const char *const text,
- const std::string &description,
- int &restrict x,
- int &restrict h,
- const InputActionT key,
- const Visible visible)
-{
- Button *const btn = new Button(this, gettext(text), text, this);
- btn->setPosition(x, mPadding);
- btn->setDescription(description);
- btn->setTag(CAST_S32(key));
- add(btn);
- btn->setFocusable(false);
- x += btn->getWidth() + mSpacing;
- h = btn->getHeight() + 2 * mPadding;
- mButtons.push_back(btn);
- mButtonNames[text] = new ButtonInfo(btn, key, visible);
- if (key != InputAction::SHOW_WINDOWS)
- mButtonTexts.push_back(new ButtonText(description, key));
-}
-
-void WindowMenu::mousePressed(MouseEvent &event)
-{
- if (popupManager == nullptr)
- return;
-
- if (event.getButton() == MouseButton::RIGHT)
- {
- if (mSmallWindow)
- return;
-
- event.consume();
- Button *const btn = dynamic_cast<Button*>(event.getSource());
- if (btn == nullptr)
- return;
- if (popupMenu != nullptr)
- {
- popupMenu->showPopup(getX() + event.getX(),
- getY() + event.getY(), btn);
- }
- }
-}
-
-void WindowMenu::mouseMoved(MouseEvent &event)
-{
- mHaveMouse = true;
-
- if (textPopup == nullptr)
- return;
-
- if (event.getSource() == this)
- {
- textPopup->hide();
- return;
- }
-
- const Button *const btn = dynamic_cast<const Button *>(
- event.getSource());
-
- if (btn == nullptr)
- {
- textPopup->hide();
- return;
- }
-
- const int x = event.getX();
- const int y = event.getY();
- const InputActionT key = static_cast<InputActionT>(btn->getTag());
- const Rect &rect = mDimension;
- if (key != InputAction::NO_VALUE)
- {
- textPopup->show(x + rect.x, y + rect.y, btn->getDescription(),
- // TRANSLATORS: short key name
- strprintf(_("Key: %s"), inputManager.getKeyValueString(
- key).c_str()));
- }
- else
- {
- textPopup->show(x + rect.x, y + rect.y, btn->getDescription());
- }
-}
-
-void WindowMenu::mouseExited(MouseEvent& event A_UNUSED)
-{
- mHaveMouse = false;
- if (textPopup == nullptr)
- return;
-
- textPopup->hide();
-}
-
-void WindowMenu::showButton(const std::string &name,
- const Visible visible)
-{
- const ButtonInfo *const info = mButtonNames[name];
- if ((info == nullptr) || (info->button == nullptr))
- return;
-
- info->button->setVisible(visible);
- updateButtons();
- saveButtons();
-}
-
-void WindowMenu::updateButtons()
-{
- int x = mPadding;
- int h = 0;
- FOR_EACH (STD_VECTOR <Button*>::const_iterator, it, mButtons)
- safeRemove(*it);
- const int pad2 = 2 * mPadding;
- FOR_EACH (STD_VECTOR <Button*>::iterator, it, mButtons)
- {
- Button *const btn = *it;
- if (btn == nullptr)
- continue;
- if (btn->mVisible == Visible_true)
- {
- btn->setPosition(x, mPadding);
- add(btn);
- x += btn->getWidth() + mSpacing;
- h = btn->getHeight() + pad2;
- }
- }
- x += mPadding - mSpacing;
- if (mainGraphics != nullptr)
- setDimension(Rect(mainGraphics->mWidth - x, 0, x, h));
-}
-
-void WindowMenu::loadButtons()
-{
- if (!mSmallWindow)
- {
- if (config.getValue("windowmenu0", "").empty())
- {
- for (std::map <std::string, ButtonInfo*>::iterator
- it = mButtonNames.begin(),
- it_fend = mButtonNames.end(); it != it_fend; ++it)
- {
- const ButtonInfo *const info = (*it).second;
- if (info == nullptr ||
- info->button == nullptr ||
- info->visible == Visible_true)
- {
- continue;
- }
- info->button->setVisible(Visible_false);
- }
- updateButtons();
- return;
- }
-
- for (int f = 0; f < 30; f ++)
- {
- const std::string str = config.getValue(
- "windowmenu" + toString(f), "");
- if (str.empty() || str == "SET")
- continue;
- const ButtonInfo *const info = mButtonNames[str];
- if ((info == nullptr) || (info->button == nullptr))
- continue;
- info->button->setVisible(Visible_false);
- }
- }
- else
- {
- for (std::map <std::string, ButtonInfo*>::iterator
- it = mButtonNames.begin(),
- it_fend = mButtonNames.end(); it != it_fend; ++it)
- {
- const ButtonInfo *const info = (*it).second;
- if ((info == nullptr) || (info->button == nullptr))
- continue;
- Button *const button = info->button;
- const std::string &str = button->getActionEventId();
- button->setVisible(fromBool(
- str == "SET" || str == "WIN", Visible));
- }
- }
- updateButtons();
-}
-
-void WindowMenu::saveButtons() const
-{
- int i = 0;
- FOR_EACH (STD_VECTOR <Button*>::const_iterator, it, mButtons)
- {
- const Button *const btn = *it;
- if ((btn != nullptr) && btn->mVisible == Visible_false)
- {
- config.setValue("windowmenu" + toString(i),
- btn->getActionEventId());
- i ++;
- }
- }
- for (int f = i; f < 30; f ++)
- config.deleteKey("windowmenu" + toString(f));
-}
-
-void WindowMenu::drawChildren(Graphics *const graphics)
-{
- if (mHaveMouse ||
- mAutoHide == 0 ||
- (mAutoHide == 1 &&
- mainGraphics != nullptr &&
- (mSmallWindow || mainGraphics->mWidth > 800)))
- {
- Container::drawChildren(graphics);
- }
-}
-
-void WindowMenu::safeDrawChildren(Graphics *const graphics)
-{
- if (mHaveMouse ||
- mAutoHide == 0 ||
- (mAutoHide == 1 &&
- mainGraphics != nullptr &&
- (mSmallWindow || mainGraphics->mWidth > 800)))
- {
- Container::safeDrawChildren(graphics);
- }
-}
-
-void WindowMenu::optionChanged(const std::string &name)
-{
- if (name == "autohideButtons")
- mAutoHide = config.getIntValue("autohideButtons");
-}
-
-#ifdef USE_PROFILER
-void WindowMenu::logicChildren()
-{
- BLOCK_START("WindowMenu::logicChildren")
- BasicContainer::logicChildren();
- BLOCK_END("WindowMenu::logicChildren")
-}
-#endif // USE_PROFILER
diff --git a/src/gui/windowmenu.h b/src/gui/windowmenu.h
deleted file mode 100644
index 780fe29ea..000000000
--- a/src/gui/windowmenu.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWMENU_H
-#define GUI_WINDOWMENU_H
-
-#include "enums/input/inputaction.h"
-
-#include "gui/widgets/container.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/mouselistener.h"
-#include "listeners/selectionlistener.h"
-
-#include "localconsts.h"
-
-class Button;
-
-struct ButtonInfo;
-struct ButtonText;
-
-/**
- * The window menu. Allows showing and hiding many of the different windows
- * used in the game.
- *
- * \ingroup Interface
- */
-class WindowMenu final : public Container,
- public ConfigListener,
- public ActionListener,
- public SelectionListener,
- public MouseListener
-{
- public:
- explicit WindowMenu(const Widget2 *const widget);
-
- A_DELETE_COPY(WindowMenu)
-
- ~WindowMenu();
-
- void action(const ActionEvent &event) override final;
-
- void mousePressed(MouseEvent &event) override final;
-
- void mouseMoved(MouseEvent &event) override final;
-
- void mouseExited(MouseEvent& event A_UNUSED) override final;
-
- std::map <std::string, ButtonInfo*> &getButtonNames() A_WARN_UNUSED
- { return mButtonNames; }
-
- STD_VECTOR <Button*> &getButtons() A_WARN_UNUSED
- { return mButtons; }
-
- STD_VECTOR <ButtonText*> &getButtonTexts() A_WARN_UNUSED
- { return mButtonTexts; }
-
- void showButton(const std::string &name, const Visible visible);
-
- void loadButtons();
-
- void saveButtons() const;
-
- void optionChanged(const std::string &name) override final;
-
-#ifdef USE_PROFILER
- void logicChildren();
-#endif // USE_PROFILER
-
- protected:
- void drawChildren(Graphics *const graphics) override final
- A_NONNULL(2);
-
- void safeDrawChildren(Graphics *const graphics) override final
- A_NONNULL(2);
-
- private:
- inline void addButton(const char *const text,
- const std::string &description,
- int &restrict x, int &restrict h,
- const InputActionT key,
- const Visible visible = Visible_true);
-
- void updateButtons();
-
- Skin *mSkin;
- int mPadding;
- int mSpacing;
- STD_VECTOR <Button*> mButtons;
- STD_VECTOR <ButtonText*> mButtonTexts;
- std::map <std::string, ButtonInfo*> mButtonNames;
- bool mHaveMouse;
- int mAutoHide;
- bool mSmallWindow;
-};
-
-extern WindowMenu *windowMenu;
-
-#endif // GUI_WINDOWMENU_H
diff --git a/src/gui/windows/bankwindow.cpp b/src/gui/windows/bankwindow.cpp
deleted file mode 100644
index 242d30aa1..000000000
--- a/src/gui/windows/bankwindow.cpp
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/bankwindow.h"
-
-#include "net/bankhandler.h"
-
-#include "gui/windows/setupwindow.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/inttextfield.h"
-#include "gui/widgets/label.h"
-
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include "resources/db/unitsdb.h"
-
-#include "debug.h"
-
-BankWindow *bankWindow = nullptr;
-
-BankWindow::BankWindow() :
- // TRANSLATORS: bank window name
- Window(_("Bank"), Modal_false, nullptr, "bank.xml"),
- ActionListener(),
- BankListener(),
- mBankMoneyLabel(new Label(this, strprintf(
- // TRANSLATORS: bank window money label
- _("Money in bank: %s"), " "))),
- mInputMoneyTextField(new IntTextField(this, 0, 0, 2147483647)),
- // TRANSLATORS: bank window button
- mWithdrawButton(new Button(this, _("Withdraw"), "withdraw", this)),
- // TRANSLATORS: bank window button
- mDepositButton(new Button(this, _("Deposit"), "deposit", this))
-{
- setWindowName("Bank");
- setCloseButton(true);
-
- if (setupWindow != nullptr)
- setupWindow->registerWindowForReset(this);
-
- mBankMoneyLabel->adjustSize();
- ContainerPlacer placer = getPlacer(0, 0);
- placer(0, 0, mBankMoneyLabel, 7);
- placer(0, 1, mInputMoneyTextField, 10);
- placer(0, 2, mDepositButton, 5);
- placer(5, 2, mWithdrawButton, 5);
-
- setContentSize(300, 100);
- setDefaultSize(300, 100, ImagePosition::CENTER, 0, 0);
-
- center();
- setDefaultSize();
- loadWindowState();
- reflowLayout(300);
- enableVisibleSound(true);
-}
-
-BankWindow::~BankWindow()
-{
-}
-
-void BankWindow::widgetShown(const Event &event)
-{
- if (event.getSource() == this)
- bankHandler->check();
-}
-
-void BankWindow::bankMoneyChanged(const int money)
-{
- // TRANSLATORS: bank window money label
- mBankMoneyLabel->setCaption(strprintf(_("Money in bank: %s"),
- UnitsDb::formatCurrency(money).c_str()));
-}
-
-void BankWindow::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "deposit")
- bankHandler->deposit(mInputMoneyTextField->getValue());
- else if (eventId == "withdraw")
- bankHandler->withdraw(mInputMoneyTextField->getValue());
-}
diff --git a/src/gui/windows/bankwindow.h b/src/gui/windows/bankwindow.h
deleted file mode 100644
index 046b11ec4..000000000
--- a/src/gui/windows/bankwindow.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_BANKWINDOW_H
-#define GUI_WINDOWS_BANKWINDOW_H
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/banklistener.h"
-
-class Button;
-class IntTextField;
-class Label;
-
-/**
- * A dialog to choose between buying or selling at a shop.
- *
- * \ingroup Interface
- */
-class BankWindow final : public Window,
- public ActionListener,
- public BankListener
-{
- public:
- BankWindow();
-
- A_DELETE_COPY(BankWindow)
-
- ~BankWindow();
-
- void action(const ActionEvent &event) override final;
-
- void widgetShown(const Event &event) override final;
-
- void bankMoneyChanged(const int money) override final;
-
- private:
- Label *mBankMoneyLabel;
- IntTextField *mInputMoneyTextField;
- Button *mWithdrawButton;
- Button *mDepositButton;
-};
-
-extern BankWindow *bankWindow;
-
-#endif // GUI_WINDOWS_BANKWINDOW_H
diff --git a/src/gui/windows/buydialog.cpp b/src/gui/windows/buydialog.cpp
deleted file mode 100644
index db1dc6e50..000000000
--- a/src/gui/windows/buydialog.cpp
+++ /dev/null
@@ -1,794 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/buydialog.h"
-
-#include "actormanager.h"
-#include "configuration.h"
-
-#include "being/being.h"
-
-#include "enums/gui/layouttype.h"
-
-#include "gui/windows/setupwindow.h"
-#ifdef TMWA_SUPPORT
-#include "gui/windows/tradewindow.h"
-#endif // TMWA_SUPPORT
-
-#include "gui/models/shopitems.h"
-#include "gui/models/sortlistmodelbuy.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/dropdown.h"
-#include "gui/widgets/inttextfield.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layout.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/shoplistbox.h"
-#include "gui/widgets/slider.h"
-
-#include "net/adminhandler.h"
-#include "net/buysellhandler.h"
-#include "net/cashshophandler.h"
-#include "net/markethandler.h"
-#include "net/net.h"
-#include "net/vendinghandler.h"
-#include "net/npchandler.h"
-
-#include "resources/iteminfo.h"
-
-#include "resources/db/unitsdb.h"
-
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-
-#include <algorithm>
-
-#include "debug.h"
-
-namespace
-{
- class SortItemPriceFunctor final
- {
- public:
- A_DEFAULT_COPY(SortItemPriceFunctor)
-
- bool operator() (const ShopItem *const item1,
- const ShopItem *const item2) const
- {
- if ((item1 == nullptr) || (item2 == nullptr))
- return false;
-
- const int price1 = item1->getPrice();
- const int price2 = item2->getPrice();
- if (price1 == price2)
- return item1->getDisplayName() < item2->getDisplayName();
- return price1 < price2;
- }
- } itemPriceBuySorter;
-
- class SortItemNameFunctor final
- {
- public:
- A_DEFAULT_COPY(SortItemNameFunctor)
-
- bool operator() (const ShopItem *const item1,
- const ShopItem *const item2) const
- {
- if ((item1 == nullptr) || (item2 == nullptr))
- return false;
-
- const std::string &name1 = item1->getDisplayName();
- const std::string &name2 = item2->getDisplayName();
- if (name1 == name2)
- return item1->getPrice() < item2->getPrice();
- return name1 < name2;
- }
- } itemNameBuySorter;
-
- class SortItemIdFunctor final
- {
- public:
- A_DEFAULT_COPY(SortItemIdFunctor)
-
- bool operator() (const ShopItem *const item1,
- const ShopItem *const item2) const
- {
- if ((item1 == nullptr) || (item2 == nullptr))
- return false;
-
- const int id1 = item1->getId();
- const int id2 = item2->getId();
- if (id1 == id2)
- return item1->getPrice() < item2->getPrice();
- return id1 < id2;
- }
- } itemIdBuySorter;
-
- class SortItemWeightFunctor final
- {
- public:
- A_DEFAULT_COPY(SortItemWeightFunctor)
-
- bool operator() (const ShopItem *const item1,
- const ShopItem *const item2) const
- {
- if ((item1 == nullptr) || (item2 == nullptr))
- return false;
-
- const int weight1 = item1->getInfo().getWeight();
- const int weight2 = item2->getInfo().getWeight();
- if (weight1 == weight2)
- return item1->getPrice() < item2->getPrice();
- return weight1 < weight2;
- }
- } itemWeightBuySorter;
-
- class SortItemAmountFunctor final
- {
- public:
- A_DEFAULT_COPY(SortItemAmountFunctor)
-
- bool operator() (const ShopItem *const item1,
- const ShopItem *const item2) const
- {
- if ((item1 == nullptr) || (item2 == nullptr))
- return false;
-
- const int amount1 = item1->getQuantity();
- const int amount2 = item2->getQuantity();
- if (amount1 == amount2)
- return item1->getPrice() < item2->getPrice();
- return amount1 < amount2;
- }
- } itemAmountBuySorter;
-
- class SortItemTypeFunctor final
- {
- public:
- A_DEFAULT_COPY(SortItemTypeFunctor)
-
- bool operator() (const ShopItem *const item1,
- const ShopItem *const item2) const
- {
- if ((item1 == nullptr) || (item2 == nullptr))
- return false;
-
- const ItemDbTypeT type1 = item1->getInfo().getType();
- const ItemDbTypeT type2 = item2->getInfo().getType();
- if (type1 == type2)
- return item1->getPrice() < item2->getPrice();
- return type1 < type2;
- }
- } itemTypeBuySorter;
-} // namespace
-
-BuyDialog::DialogList BuyDialog::instances;
-
-BuyDialog::BuyDialog() :
- // TRANSLATORS: buy dialog name
- Window(_("Create items"), Modal_false, nullptr, "buy.xml"),
- ActionListener(),
- SelectionListener(),
- mSortModel(nullptr),
- mSortDropDown(nullptr),
- mFilterTextField(new TextField(this, "", LoseFocusOnTab_true,
- this, "namefilter", true)),
- mFilterLabel(nullptr),
- mNick(),
- mCurrency(),
- mNpcId(fromInt(Items, BeingId)),
- mMoney(0),
- mAmountItems(0),
- mMaxItems(0),
- mAdvanced(false)
-{
- init();
-}
-
-BuyDialog::BuyDialog(const BeingId npcId,
- const std::string &currency) :
- // TRANSLATORS: buy dialog name
- Window(_("Buy"), Modal_false, nullptr, "buy.xml"),
- ActionListener(),
- SelectionListener(),
- mSortModel(nullptr),
- mSortDropDown(nullptr),
- mFilterTextField(new TextField(this, "", LoseFocusOnTab_true,
- this, "namefilter", true)),
- mFilterLabel(nullptr),
- mNick(),
- mCurrency(currency),
- mNpcId(npcId),
- mMoney(0),
- mAmountItems(0),
- mMaxItems(0),
- mAdvanced(Net::getNetworkType() != ServerType::TMWATHENA)
-{
- init();
-}
-
-#ifdef TMWA_SUPPORT
-BuyDialog::BuyDialog(const std::string &nick,
- const std::string &currency) :
- // TRANSLATORS: buy dialog name
- Window(_("Buy"), Modal_false, nullptr, "buy.xml"),
- ActionListener(),
- SelectionListener(),
- mSortModel(new SortListModelBuy),
- mSortDropDown(new DropDown(this, mSortModel, false,
- Modal_false, this, "sort")),
- mFilterTextField(new TextField(this, "", LoseFocusOnTab_true,
- this, "namefilter", true)),
- mFilterLabel(nullptr),
- mNick(nick),
- mCurrency(currency),
- mNpcId(fromInt(Nick, BeingId)),
- mMoney(0),
- mAmountItems(0),
- mMaxItems(0),
- mAdvanced(false)
-{
- init();
-}
-#endif // TMWA_SUPPORT
-
-BuyDialog::BuyDialog(const Being *const being,
- const std::string &currency) :
- // TRANSLATORS: buy dialog name
- Window(_("Buy"), Modal_false, nullptr, "buy.xml"),
- ActionListener(),
- SelectionListener(),
- mSortModel(new SortListModelBuy),
- mSortDropDown(new DropDown(this, mSortModel, false,
- Modal_false, this, "sort")),
- mFilterTextField(new TextField(this, "", LoseFocusOnTab_true,
- this, "namefilter", true)),
- mFilterLabel(nullptr),
- mNick(being != nullptr ? being->getName() : std::string()),
- mCurrency(currency),
- mNpcId(fromInt(Vending, BeingId)),
- mMoney(0),
- mAmountItems(0),
- mMaxItems(0),
- mAdvanced(true)
-{
- init();
-}
-
-void BuyDialog::init()
-{
- setWindowName("Buy");
- setResizable(true);
- setCloseButton(true);
- setStickyButtonLock(true);
- setMinWidth(260);
- setMinHeight(220);
- setDefaultSize(260, 230, ImagePosition::CENTER);
-
-#ifdef TMWA_SUPPORT
- // reset advance flag for personal shops
- if (mAdvanced &&
- mNpcId == fromInt(Nick, BeingId))
- {
- mAdvanced = false;
- }
-#endif // TMWA_SUPPORT
-
- if (setupWindow != nullptr)
- setupWindow->registerWindowForReset(this);
-
- mShopItems = new ShopItems(false,
- mCurrency);
-
- CREATEWIDGETV(mShopItemList, ShopListBox, this,
- mShopItems, mShopItems, ShopListBoxType::Unknown);
- mScrollArea = new ScrollArea(this, mShopItemList,
- fromBool(getOptionBool("showbackground"), Opaque),
- "buy_background.xml");
- mScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
-
- mSlider = new Slider(this, 1.0, 1.0);
- mQuantityLabel = new Label(this, strprintf(
- "%d / %d", mAmountItems, mMaxItems));
- mQuantityLabel->setAlignment(Graphics::CENTER);
- mMoneyLabel = new Label(this, strprintf(
- // TRANSLATORS: buy dialog label
- _("Price: %s / Total: %s"), "", ""));
-
- mAmountField = new IntTextField(this, 1, 1, 123);
- mAmountField->setActionEventId("amount");
- mAmountField->addActionListener(this);
- mAmountField->setSendAlwaysEvents(true);
- mAmountField->setEnabled(false);
-
- // TRANSLATORS: buy dialog label
- mAmountLabel = new Label(this, _("Amount:"));
- mAmountLabel->adjustSize();
-
- // TRANSLATORS: This is a narrow symbol used to denote 'increasing'.
- // You may change this symbol if your language uses another.
- mIncreaseButton = new Button(this, _("+"), "inc", this);
- // TRANSLATORS: This is a narrow symbol used to denote 'decreasing'.
- // You may change this symbol if your language uses another.
- mDecreaseButton = new Button(this, _("-"), "dec", this);
- mBuyButton = new Button(this, mNpcId == fromInt(Items, BeingId)
- // TRANSLATORS: buy dialog button
- ? _("Create") : (mAdvanced ? _("Add") : _("Buy")), "buy", this);
- if (mAdvanced)
- {
- // TRANSLATORS: buy dialog button
- mConfirmButton = new Button(this, _("Buy"), "confirm", this);
- mConfirmButton->setEnabled(false);
- }
- else
- {
- mConfirmButton = nullptr;
- }
- // TRANSLATORS: buy dialog button
- mQuitButton = new Button(this, _("Quit"), "quit", this);
- // TRANSLATORS: buy dialog button
- mAddMaxButton = new Button(this, _("Max"), "max", this);
-
- mDecreaseButton->adjustSize();
- mDecreaseButton->setWidth(mIncreaseButton->getWidth());
-
- mIncreaseButton->setEnabled(false);
- mDecreaseButton->setEnabled(false);
- mBuyButton->setEnabled(false);
- mSlider->setEnabled(false);
-
- mSlider->setActionEventId("slider");
- mSlider->addActionListener(this);
-
- mShopItemList->setDistributeMousePressed(false);
- mShopItemList->setActionEventId("buy");
- mShopItemList->addActionListener(this);
- mShopItemList->addSelectionListener(this);
-
- mFilterTextField->setWidth(100);
-
- ContainerPlacer placer = getPlacer(0, 0);
- placer(0, 0, mScrollArea, 9, 5).setPadding(3);
- placer(0, 5, mDecreaseButton);
- placer(1, 5, mSlider, 4);
- placer(5, 5, mIncreaseButton);
- placer(6, 5, mQuantityLabel, 2);
- placer(8, 5, mAddMaxButton);
- placer(0, 6, mAmountLabel, 2);
- placer(2, 6, mAmountField, 2);
- placer(0, 7, mMoneyLabel, 8);
- if (mSortDropDown != nullptr)
- {
- placer(0, 8, mSortDropDown, 2);
- }
- else
- {
- // TRANSLATORS: buy dialog label
- mFilterLabel = new Label(this, _("Filter:"));
- mFilterLabel->adjustSize();
- placer(0, 8, mFilterLabel, 2);
- }
- placer(2, 8, mFilterTextField, 2);
- if (mAdvanced)
- {
- placer(6, 8, mBuyButton);
- placer(7, 8, mConfirmButton);
- }
- else
- {
- placer(7, 8, mBuyButton);
- }
- placer(8, 8, mQuitButton);
-
- Layout &layout = getLayout();
- layout.setRowHeight(0, LayoutType::SET);
-
- center();
- loadWindowState();
- enableVisibleSound(true);
-
- instances.push_back(this);
- setVisible(Visible_true);
-
- if (mSortDropDown != nullptr)
- mSortDropDown->setSelected(config.getIntValue("buySortOrder"));
-}
-
-BuyDialog::~BuyDialog()
-{
- delete2(mShopItems);
- delete2(mSortModel);
- instances.remove(this);
- if (buySellHandler != nullptr)
- buySellHandler->cleanDialogReference(this);
-}
-
-void BuyDialog::setMoney(const int amount)
-{
- mMoney = amount;
- mShopItemList->setPlayersMoney(amount);
-
- updateButtonsAndLabels();
-}
-
-void BuyDialog::reset()
-{
- mShopItems->clear();
- mShopItemList->adjustSize();
-
- // Reset previous selected items to prevent failing asserts
- mShopItemList->setSelected(-1);
- mSlider->setValue(0);
-
- setMoney(0);
-}
-
-ShopItem *BuyDialog::addItem(const int id,
- const ItemTypeT type,
- const ItemColor color,
- const int amount,
- const int price)
-{
- ShopItem *const item = mShopItems->addItem(id,
- type,
- color,
- amount,
- price);
- mShopItemList->adjustSize();
- return item;
-}
-
-void BuyDialog::sort()
-{
- if ((mSortDropDown != nullptr) && (mShopItems != nullptr))
- {
- STD_VECTOR<ShopItem*> &items = mShopItems->items();
- switch (mSortDropDown->getSelected())
- {
- case 1:
- std::sort(items.begin(), items.end(), itemPriceBuySorter);
- break;
- case 2:
- std::sort(items.begin(), items.end(), itemNameBuySorter);
- break;
- case 3:
- std::sort(items.begin(), items.end(), itemIdBuySorter);
- break;
- case 4:
- std::sort(items.begin(), items.end(), itemWeightBuySorter);
- break;
- case 5:
- std::sort(items.begin(), items.end(), itemAmountBuySorter);
- break;
- case 6:
- std::sort(items.begin(), items.end(), itemTypeBuySorter);
- break;
- case 0:
- default:
- break;
- }
- }
-}
-
-void BuyDialog::close()
-{
- switch (toInt(mNpcId, int))
- {
-#ifdef TMWA_SUPPORT
- case Nick:
-#endif // TMWA_SUPPORT
- case Items:
- break;
- case Market:
- marketHandler->close();
- break;
- case Cash:
- cashShopHandler->close();
- break;
- case Vending:
- vendingHandler->close();
- break;
- default:
- buySellHandler->close();
- break;
- }
- Window::close();
-}
-
-void BuyDialog::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "quit")
- {
- close();
- return;
- }
- else if (eventId == "sort")
- {
- sort();
- if (mSortDropDown != nullptr)
- config.setValue("buySortOrder", mSortDropDown->getSelected());
- return;
- }
- else if (eventId == "namefilter")
- {
- applyNameFilter(mFilterTextField->getText());
- }
-
- const int selectedItem = mShopItemList->getSelected();
-
- // The following actions require a valid selection
- if (selectedItem < 0 || selectedItem >= mShopItems->getNumberOfElements())
- return;
-
- if (eventId == "slider")
- {
- mAmountItems = CAST_S32(mSlider->getValue());
- mAmountField->setValue(mAmountItems);
- updateButtonsAndLabels();
- }
- else if (eventId == "inc" && mAmountItems < mMaxItems)
- {
- mAmountItems++;
- mSlider->setValue(mAmountItems);
- mAmountField->setValue(mAmountItems);
- updateButtonsAndLabels();
- }
- else if (eventId == "dec" && mAmountItems > 1)
- {
- mAmountItems--;
- mSlider->setValue(mAmountItems);
- mAmountField->setValue(mAmountItems);
- updateButtonsAndLabels();
- }
- else if (eventId == "max")
- {
- mAmountItems = mMaxItems;
- mSlider->setValue(mAmountItems);
- mAmountField->setValue(mAmountItems);
- updateButtonsAndLabels();
- }
- else if (eventId == "amount")
- {
- mAmountItems = mAmountField->getValue();
- mSlider->setValue(mAmountItems);
- updateButtonsAndLabels();
- }
- else if (eventId == "buy" && mAmountItems > 0 && mAmountItems <= mMaxItems)
- {
- ShopItem *const item = mShopItems->at(selectedItem);
- if (item == nullptr)
- return;
- if (mNpcId == fromInt(Items, BeingId))
- {
- adminHandler->createItems(item->getId(),
- item->getColor(),
- mAmountItems);
- }
-#ifdef TMWA_SUPPORT
- else if (mNpcId == fromInt(Nick, BeingId))
- {
- if (tradeWindow != nullptr)
- {
- buySellHandler->sendBuyRequest(mNick,
- item, mAmountItems);
- tradeWindow->addAutoMoney(mNick,
- item->getPrice() * mAmountItems);
- }
- }
-#endif // TMWA_SUPPORT
- else if (mNpcId == fromInt(Vending, BeingId))
- {
- item->increaseUsedQuantity(mAmountItems);
- item->update();
- if (mConfirmButton != nullptr)
- mConfirmButton->setEnabled(true);
- }
-#ifdef TMWA_SUPPORT
- else if (mNpcId != fromInt(Nick, BeingId))
-#else
- else
-#endif // TMWA_SUPPORT
- {
- if (mAdvanced)
- {
- item->increaseUsedQuantity(mAmountItems);
- item->update();
- if (mConfirmButton != nullptr)
- mConfirmButton->setEnabled(true);
- }
- else if (mNpcId == fromInt(Market, BeingId))
- {
- marketHandler->buyItem(item->getId(),
- item->getType(),
- item->getColor(),
- mAmountItems);
- item->increaseQuantity(-mAmountItems);
- item->update();
- }
- else if (mNpcId == fromInt(Cash, BeingId))
- {
- cashShopHandler->buyItem(item->getPrice(),
- item->getId(),
- item->getColor(),
- mAmountItems);
- }
- else
- {
- npcHandler->buyItem(mNpcId,
- item->getId(),
- item->getColor(),
- mAmountItems);
- }
-
- updateSlider(selectedItem);
- }
- }
- else if (eventId == "confirm")
- {
- STD_VECTOR<ShopItem*> &items = mShopItems->allItems();
-
- if (mNpcId == fromInt(Market, BeingId))
- {
- marketHandler->buyItems(items);
- }
- else if (mNpcId == fromInt(Vending, BeingId))
- {
- const Being *const being = actorManager->findBeingByName(
- mNick,
- ActorType::Player);
- if (being != nullptr)
- {
- vendingHandler->buyItems(being,
- items);
- }
- }
- else if (mNpcId == fromInt(Cash, BeingId))
- {
- cashShopHandler->buyItems(0, items);
- }
- else
- {
- npcHandler->buyItems(items);
- }
- close();
- }
-}
-
-void BuyDialog::updateSlider(const int selectedItem)
-{
- // Update money and adjust the max number of items
- // that can be bought
- mMaxItems -= mAmountItems;
- const ShopItem *const item = mShopItems->at(selectedItem);
- if (item != nullptr)
- setMoney(mMoney - mAmountItems * item->getPrice());
- else
- setMoney(mMoney);
-
- // Reset selection
- mAmountItems = 1;
- mSlider->setScale(1, mMaxItems);
- mSlider->setValue(1);
-}
-
-void BuyDialog::valueChanged(const SelectionEvent &event A_UNUSED)
-{
- // Reset amount of items and update labels
- mAmountItems = 1;
- mSlider->setValue(1);
-
- updateButtonsAndLabels();
- mSlider->setScale(1, mMaxItems);
- mAmountField->setRange(1, mMaxItems);
- mAmountField->setValue(1);
-}
-
-void BuyDialog::updateButtonsAndLabels()
-{
- const int selectedItem = mShopItemList->getSelected();
- int price = 0;
-
- if (selectedItem > -1)
- {
- const ShopItem *const item = mShopItems->at(selectedItem);
- if (item != nullptr)
- {
- const int itemPrice = item->getPrice();
-
- // Calculate how many the player can afford
- if (mNpcId == fromInt(Items, BeingId))
- mMaxItems = 100;
- else if (itemPrice != 0)
- mMaxItems = mMoney / itemPrice;
- else
- mMaxItems = 1;
-
- if (item->getQuantity() > 0 && mMaxItems > item->getQuantity())
- mMaxItems = item->getQuantity();
-
- if (mAmountItems > mMaxItems)
- mAmountItems = mMaxItems;
-
- price = mAmountItems * itemPrice;
- }
- }
- else
- {
- mMaxItems = 0;
- mAmountItems = 0;
- }
-
- mIncreaseButton->setEnabled(mAmountItems < mMaxItems);
- mDecreaseButton->setEnabled(mAmountItems > 1);
- mBuyButton->setEnabled(mAmountItems > 0);
- mSlider->setEnabled(mMaxItems > 1);
- mAmountField->setEnabled(mAmountItems > 0);
-
- mQuantityLabel->setCaption(strprintf("%d / %d", mAmountItems, mMaxItems));
- // TRANSLATORS: buy dialog label
- mMoneyLabel->setCaption(strprintf(_("Price: %s / Total: %s"),
- UnitsDb::formatCurrency(mCurrency, price).c_str(),
- UnitsDb::formatCurrency(mCurrency, mMoney - price).c_str()));
-}
-
-void BuyDialog::setVisible(Visible visible)
-{
- Window::setVisible(visible);
-
- if (visible == Visible_true && (mShopItemList != nullptr))
- mShopItemList->requestFocus();
- else
- scheduleDelete();
-}
-
-void BuyDialog::closeAll()
-{
- FOR_EACH (DialogList::const_iterator, it, instances)
- {
- if (*it != nullptr)
- (*it)->close();
- }
-}
-
-void BuyDialog::applyNameFilter(const std::string &filter)
-{
- STD_VECTOR<ShopItem*> &items = mShopItems->allItems();
- std::string filterStr = filter;
- toLower(filterStr);
- FOR_EACH (STD_VECTOR<ShopItem*>::iterator, it, items)
- {
- ShopItem *const item = *it;
- if (item == nullptr)
- continue;
- std::string name = item->getName();
- toLower(name);
- if (name.find(filterStr) != std::string::npos)
- item->setVisible(true);
- else
- item->setVisible(false);
- }
- mShopItems->updateList();
-}
diff --git a/src/gui/windows/buydialog.h b/src/gui/windows/buydialog.h
deleted file mode 100644
index 7914c0ef3..000000000
--- a/src/gui/windows/buydialog.h
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_BUYDIALOG_H
-#define GUI_WINDOWS_BUYDIALOG_H
-
-#include "enums/resources/item/itemtype.h"
-
-#include "enums/simpletypes/beingid.h"
-#include "enums/simpletypes/itemcolor.h"
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/selectionlistener.h"
-
-class Being;
-class Button;
-class DropDown;
-class ShopItem;
-class ShopItems;
-class ShopListBox;
-class SortListModelBuy;
-class IntTextField;
-class Label;
-class ScrollArea;
-class Slider;
-class TextField;
-
-/**
- * The buy dialog.
- *
- * \ingroup Interface
- */
-class BuyDialog final : public Window,
- public ActionListener,
- public SelectionListener
-{
- public:
- /**
- * Constructor.
- *
- * @see Window::Window
- */
- BuyDialog();
-
- /**
- * Constructor.
- *
- * @see Window::Window
- */
- BuyDialog(const BeingId npcId,
- const std::string &currency);
-
-#ifdef TMWA_SUPPORT
- /**
- * Constructor.
- *
- * @see Window::Window
- */
- BuyDialog(const std::string &nick,
- const std::string &currency);
-#endif // TMWA_SUPPORT
-
- /**
- * Constructor.
- *
- * @see Window::Window
- */
- BuyDialog(const Being *const being,
- const std::string &currency);
-
- A_DELETE_COPY(BuyDialog)
-
- /**
- * Destructor
- */
- ~BuyDialog();
-
- enum
- {
-#ifdef TMWA_SUPPORT
- Nick = -1,
-#endif // TMWA_SUPPORT
- Items = -2,
- Market = -3,
- Cash = -4,
- Vending = -5
- };
-
- void init();
-
- /**
- * Resets the dialog, clearing shop inventory.
- */
- void reset();
-
- /**
- * Sets the amount of available money.
- */
- void setMoney(const int amount);
-
- /**
- * Adds an item to the shop inventory.
- */
- ShopItem *addItem(const int id,
- const ItemTypeT type,
- const ItemColor color,
- const int amount,
- const int price);
-
- /**
- * Called when receiving actions from the widgets.
- */
- void action(const ActionEvent &event) override final;
-
- /**
- * Returns the number of items in the shop inventory.
- */
- int getNumberOfElements() A_WARN_UNUSED;
-
- /**
- * Updates the labels according to the selected item.
- */
- void valueChanged(const SelectionEvent &event) override final;
-
- /**
- * Updates the state of buttons and labels.
- */
- void updateButtonsAndLabels();
-
- /**
- * Sets the visibility of this window.
- */
- void setVisible(Visible visible) override final;
-
- void sort();
-
- void close() override final;
-
- /**
- * Returns true if any instances exist.
- */
- static bool isActive() A_WARN_UNUSED
- { return !instances.empty(); }
-
- /**
- * Closes all instances.
- */
- static void closeAll();
-
- private:
- void updateSlider(const int selectedItem);
-
- void applyNameFilter(const std::string &filter);
-
- typedef std::list<BuyDialog*> DialogList;
- static DialogList instances;
-
- Button *mBuyButton A_NONNULLPOINTER;
- Button *mConfirmButton A_NONNULLPOINTER;
- Button *mQuitButton A_NONNULLPOINTER;
- Button *mAddMaxButton A_NONNULLPOINTER;
- Button *mIncreaseButton A_NONNULLPOINTER;
- Button *mDecreaseButton A_NONNULLPOINTER;
- ShopListBox *mShopItemList A_NONNULLPOINTER;
- ScrollArea *mScrollArea A_NONNULLPOINTER;
- Label *mMoneyLabel A_NONNULLPOINTER;
- Label *mQuantityLabel A_NONNULLPOINTER;
- Slider *mSlider A_NONNULLPOINTER;
- Label *mAmountLabel A_NONNULLPOINTER;
- IntTextField *mAmountField A_NONNULLPOINTER;
- ShopItems *mShopItems A_NONNULLPOINTER;
- SortListModelBuy *mSortModel;
- DropDown *mSortDropDown;
- TextField *mFilterTextField A_NONNULLPOINTER;
- Label *mFilterLabel;
-
- std::string mNick;
- std::string mCurrency;
- BeingId mNpcId;
- int mMoney;
- int mAmountItems;
- int mMaxItems;
- bool mAdvanced;
-};
-
-#endif // GUI_WINDOWS_BUYDIALOG_H
diff --git a/src/gui/windows/buyingstoreselldialog.cpp b/src/gui/windows/buyingstoreselldialog.cpp
deleted file mode 100644
index 369d52223..000000000
--- a/src/gui/windows/buyingstoreselldialog.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/buyingstoreselldialog.h"
-
-#include "actormanager.h"
-
-#include "being/playerinfo.h"
-
-#include "gui/models/shopitems.h"
-
-#include "gui/widgets/shoplistbox.h"
-
-#include "net/buyingstorehandler.h"
-
-#include "resources/inventory/inventory.h"
-
-#include "resources/item/shopitem.h"
-
-#include "debug.h"
-
-BuyingStoreSellDialog::BuyingStoreSellDialog(const BeingId accountId,
- const int storeId) :
- SellDialog(IsSell_true, Advanced_false),
- mAccountId(accountId),
- mStoreId(storeId)
-{
-}
-
-void BuyingStoreSellDialog::sellAction(const ActionEvent &event A_UNUSED)
-{
- if (mAmountItems <= 0 || mAmountItems > mMaxItems)
- return;
-
- const int selectedItem = mShopItemList->getSelected();
- const ShopItem *const item1 = mShopItems->at(selectedItem);
- if ((item1 == nullptr) || PlayerInfo::isItemProtected(item1->getId()))
- return;
- const Being *const being = actorManager->findBeing(mAccountId);
- if (being == nullptr)
- return;
- const Item *const item2 = PlayerInfo::getInventory()->findItem(
- item1->getId(),
- item1->getColor());
- if (item2 == nullptr)
- return;
-
- mPlayerMoney += mAmountItems * item1->getPrice();
- mMaxItems -= mAmountItems;
- buyingStoreHandler->sell(being, mStoreId, item2, mAmountItems);
-}
diff --git a/src/gui/windows/buyingstoreselldialog.h b/src/gui/windows/buyingstoreselldialog.h
deleted file mode 100644
index db2005213..000000000
--- a/src/gui/windows/buyingstoreselldialog.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_BUYINGSTORESELLDIALOG_H
-#define GUI_WINDOWS_BUYINGSTORESELLDIALOG_H
-
-#include "enums/simpletypes/beingid.h"
-
-#include "gui/widgets/selldialog.h"
-
-/**
- * The sell dialog.
- *
- * \ingroup Interface
- */
-class BuyingStoreSellDialog final : public SellDialog
-{
- public:
- /**
- * Constructor.
- *
- * @see Window::Window
- */
- BuyingStoreSellDialog(const BeingId accountId,
- const int storeId);
-
- A_DELETE_COPY(BuyingStoreSellDialog)
-
- protected:
- void sellAction(const ActionEvent &event) override final;
-
- BeingId mAccountId;
- int mStoreId;
-};
-
-#endif // GUI_WINDOWS_BUYINGSTORESELLDIALOG_H
diff --git a/src/gui/windows/buyselldialog.cpp b/src/gui/windows/buyselldialog.cpp
deleted file mode 100644
index 26cf2af17..000000000
--- a/src/gui/windows/buyselldialog.cpp
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/buyselldialog.h"
-
-#include "actormanager.h"
-
-#include "net/buysellhandler.h"
-#include "net/npchandler.h"
-
-#include "gui/windows/setupwindow.h"
-
-#include "gui/widgets/button.h"
-
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-BuySellDialog::DialogList BuySellDialog::dialogInstances;
-
-BuySellDialog::BuySellDialog(const BeingId npcId) :
- // TRANSLATORS: shop window name
- Window(_("Shop"), Modal_false, nullptr, "buysell.xml"),
- ActionListener(),
- mNpcId(npcId),
- mNick(""),
- mBuyButton(nullptr)
-{
- init();
-}
-
-BuySellDialog::BuySellDialog(const std::string &nick) :
- // TRANSLATORS: shop window name
- Window(_("Shop"), Modal_false, nullptr, "buysell.xml"),
- ActionListener(),
- mNpcId(BeingId_negOne),
- mNick(nick),
- mBuyButton(nullptr)
-{
- init();
-}
-
-void BuySellDialog::init()
-{
- setWindowName("BuySell");
- setCloseButton(true);
-
- if (setupWindow != nullptr)
- setupWindow->registerWindowForReset(this);
-
- static const char *const buttonNames[] =
- {
- // TRANSLATORS: shop window button
- N_("Buy"),
- // TRANSLATORS: shop window button
- N_("Sell"),
- // TRANSLATORS: shop window button
- N_("Cancel"),
- nullptr
- };
- const int buttonPadding = getOption("buttonpadding", 10);
- int x = buttonPadding;
- const int y = buttonPadding;
-
- for (const char *const *curBtn = buttonNames;
- *curBtn != nullptr;
- curBtn++)
- {
- Button *const btn = new Button(this, gettext(*curBtn), *curBtn, this);
- if (mBuyButton == nullptr)
- mBuyButton = btn; // For focus request
- btn->setPosition(x, y);
- add(btn);
- x += btn->getWidth() + buttonPadding;
- }
- if (mBuyButton != nullptr)
- {
- mBuyButton->requestFocus();
- setContentSize(x, 2 * y + mBuyButton->getHeight());
- }
-
- center();
- setDefaultSize();
- loadWindowState();
- enableVisibleSound(true);
-
- dialogInstances.push_back(this);
- setVisible(Visible_true);
-}
-
-BuySellDialog::~BuySellDialog()
-{
- dialogInstances.remove(this);
-}
-
-void BuySellDialog::setVisible(Visible visible)
-{
- Window::setVisible(visible);
-
- if (visible == Visible_true)
- {
- if (mBuyButton != nullptr)
- mBuyButton->requestFocus();
- }
- else
- {
- scheduleDelete();
- }
-}
-
-void BuySellDialog::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "Buy")
- {
- if (mNpcId != BeingId_negOne)
- {
- const Being *const being = actorManager->findBeing(mNpcId);
- if (being != nullptr)
- npcHandler->buy(being);
- else
- npcHandler->buy(mNpcId);
- }
- else
- {
- buySellHandler->requestSellList(mNick);
- }
- }
- else if (eventId == "Sell")
- {
- if (mNpcId != BeingId_negOne)
- npcHandler->sell(mNpcId);
- else
- buySellHandler->requestBuyList(mNick);
- }
-
- close();
-}
-
-void BuySellDialog::closeAll()
-{
- FOR_EACH (DialogList::const_iterator, it, dialogInstances)
- {
- if (*it != nullptr)
- (*it)->close();
- }
-}
diff --git a/src/gui/windows/buyselldialog.h b/src/gui/windows/buyselldialog.h
deleted file mode 100644
index b2a527d16..000000000
--- a/src/gui/windows/buyselldialog.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_BUYSELLDIALOG_H
-#define GUI_WINDOWS_BUYSELLDIALOG_H
-
-#include "enums/simpletypes/beingid.h"
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-
-class Button;
-
-/**
- * A dialog to choose between buying or selling at a shop.
- *
- * \ingroup Interface
- */
-class BuySellDialog final : public Window,
- public ActionListener
-{
- public:
- /**
- * Constructor. The action listener passed will receive "sell", "buy"
- * or "cancel" events when the respective buttons are pressed.
- *
- * @see Window::Window
- */
- explicit BuySellDialog(const BeingId npcId);
-
- explicit BuySellDialog(const std::string &nick);
-
- A_DELETE_COPY(BuySellDialog)
-
- ~BuySellDialog();
-
- void init();
-
- void setVisible(Visible visible) override final;
-
- /**
- * Called when receiving actions from the widgets.
- */
- void action(const ActionEvent &event) override final;
-
- /**
- * Returns true if any instances exist.
- */
- static bool isActive() A_WARN_UNUSED
- { return !dialogInstances.empty(); }
-
- /**
- * Closes all instances.
- */
- static void closeAll();
-
- private:
- typedef std::list<BuySellDialog*> DialogList;
- static DialogList dialogInstances;
-
- BeingId mNpcId;
- std::string mNick;
- Button *mBuyButton;
-};
-
-#endif // GUI_WINDOWS_BUYSELLDIALOG_H
diff --git a/src/gui/windows/changeemaildialog.cpp b/src/gui/windows/changeemaildialog.cpp
deleted file mode 100644
index 9d9358967..000000000
--- a/src/gui/windows/changeemaildialog.cpp
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/changeemaildialog.h"
-
-#include "client.h"
-
-#include "gui/windows/okdialog.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/textfield.h"
-
-#include "listeners/wrongdatanoticelistener.h"
-
-#include "net/logindata.h"
-#include "net/loginhandler.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include <sstream>
-
-#include "debug.h"
-
-ChangeEmailDialog::ChangeEmailDialog(LoginData &data) :
- // TRANSLATORS: change email dialog header
- Window(_("Change Email Address"), Modal_true, nullptr, "changeemail.xml"),
- ActionListener(),
- mFirstEmailField(new TextField(this)),
- mSecondEmailField(new TextField(this)),
- // TRANSLATORS: button in change email dialog
- mChangeEmailButton(new Button(this, _("Change Email Address"),
- "change_email", this)),
- // TRANSLATORS: button in change email dialog
- mCancelButton(new Button(this, _("Cancel"), "cancel", this)),
- mWrongDataNoticeListener(new WrongDataNoticeListener),
- mLoginData(&data)
-{
- // TRANSLATORS: label in change email dialog
- Label *const accountLabel = new Label(this, strprintf(_("Account: %s"),
- mLoginData->username.c_str()));
- Label *const newEmailLabel = new Label(this,
- // TRANSLATORS: label in change email dialog
- _("Type new email address twice:"));
-
- const int width = 200;
- const int height = 130;
- setContentSize(width, height);
-
- accountLabel->setPosition(5, 5);
- accountLabel->setWidth(130);
-
- newEmailLabel->setPosition(
- 5, accountLabel->getY() + accountLabel->getHeight() + 7);
- newEmailLabel->setWidth(width - 5);
-
- mFirstEmailField->setPosition(
- 5, newEmailLabel->getY() + newEmailLabel->getHeight() + 7);
- mFirstEmailField->setWidth(130);
-
- mSecondEmailField->setPosition(
- 5, mFirstEmailField->getY() + mFirstEmailField->getHeight() + 7);
- mSecondEmailField->setWidth(130);
-
- mCancelButton->setPosition(
- width - 5 - mCancelButton->getWidth(),
- height - 5 - mCancelButton->getHeight());
- mChangeEmailButton->setPosition(
- mCancelButton->getX() - 5 - mChangeEmailButton->getWidth(),
- mCancelButton->getY());
-
- add(accountLabel);
- add(newEmailLabel);
- add(mFirstEmailField);
- add(mSecondEmailField);
- add(mChangeEmailButton);
- add(mCancelButton);
-
- center();
- mFirstEmailField->requestFocus();
-
- mFirstEmailField->setActionEventId("change_email");
- mSecondEmailField->setActionEventId("change_email");
-}
-
-ChangeEmailDialog::~ChangeEmailDialog()
-{
- delete2(mWrongDataNoticeListener);
-}
-
-void ChangeEmailDialog::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "cancel")
- {
- client->setState(State::CHAR_SELECT);
- }
- else if (eventId == "change_email")
- {
- const std::string username = mLoginData->username;
- const std::string &newFirstEmail = mFirstEmailField->getText();
- const std::string &newSecondEmail = mSecondEmailField->getText();
- logger->log("ChangeEmailDialog::Email change, Username is %s",
- username.c_str());
-
- std::stringstream errorMsg;
- int error = 0;
-
- const unsigned int min = loginHandler->getMinPasswordLength();
- const unsigned int max = loginHandler->getMaxPasswordLength();
-
- if (newFirstEmail.length() < min)
- {
- // First email address too short
- // TRANSLATORS: change email error
- errorMsg << strprintf(_("The new email address needs to be at "
- "least %u characters long."), min);
- error = 1;
- }
- else if (newFirstEmail.length() > max)
- {
- // First email address too long
- // TRANSLATORS: change email error
- errorMsg << strprintf(_("The new email address needs to be "
- "less than %u characters long."), max);
- error = 1;
- }
- else if (newFirstEmail != newSecondEmail)
- {
- // Second Pass mismatch
- // TRANSLATORS: change email error
- errorMsg << _("The email address entries mismatch.");
- error = 2;
- }
-
- if (error > 0)
- {
- if (error == 1)
- mWrongDataNoticeListener->setTarget(this->mFirstEmailField);
- else // if (error == 2)
- mWrongDataNoticeListener->setTarget(this->mSecondEmailField);
-
- OkDialog *const dlg = CREATEWIDGETR(OkDialog,
- // TRANSLATORS: change email error header
- _("Error"),
- errorMsg.str(),
- // TRANSLATORS: ok dialog button
- _("OK"),
- DialogType::ERROR,
- Modal_true,
- ShowCenter_true,
- nullptr,
- 260);
- dlg->addActionListener(mWrongDataNoticeListener);
- }
- else
- {
- // No errors detected, change account password.
- mChangeEmailButton->setEnabled(false);
- // Set the new email address
- mLoginData->email = newFirstEmail;
- client->setState(State::CHANGEEMAIL_ATTEMPT);
- }
- }
-}
diff --git a/src/gui/windows/changeemaildialog.h b/src/gui/windows/changeemaildialog.h
deleted file mode 100644
index c20dffd9e..000000000
--- a/src/gui/windows/changeemaildialog.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_CHANGEEMAILDIALOG_H
-#define GUI_WINDOWS_CHANGEEMAILDIALOG_H
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-
-class Button;
-class LoginData;
-class TextField;
-class WrongDataNoticeListener;
-
-/**
- * The Change email dialog.
- *
- * \ingroup Interface
- */
-class ChangeEmailDialog final : public Window,
- public ActionListener
-{
- public:
- /**
- * Constructor.
- *
- * @see Window::Window
- */
- explicit ChangeEmailDialog(LoginData &data);
-
- A_DELETE_COPY(ChangeEmailDialog)
-
- /**
- * Destructor.
- */
- ~ChangeEmailDialog();
-
- /**
- * Called when receiving actions from the widgets.
- */
- void action(const ActionEvent &event) override final;
-
- /**
- * This is used to pass the pointer to where the new email should be
- * put when the dialog finishes.
- */
- static void setEmail(std::string *email);
-
- private:
- TextField *mFirstEmailField A_NONNULLPOINTER;
- TextField *mSecondEmailField A_NONNULLPOINTER;
-
- Button *mChangeEmailButton A_NONNULLPOINTER;
- Button *mCancelButton A_NONNULLPOINTER;
-
- WrongDataNoticeListener *mWrongDataNoticeListener A_NONNULLPOINTER;
-
- LoginData *mLoginData A_NONNULLPOINTER;
-};
-
-#endif // GUI_WINDOWS_CHANGEEMAILDIALOG_H
diff --git a/src/gui/windows/changepassworddialog.cpp b/src/gui/windows/changepassworddialog.cpp
deleted file mode 100644
index ca29a8ef1..000000000
--- a/src/gui/windows/changepassworddialog.cpp
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/changepassworddialog.h"
-
-#include "client.h"
-
-#include "gui/windows/okdialog.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/passwordfield.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layoutcell.h"
-
-#include "listeners/wrongdatanoticelistener.h"
-
-#include "net/logindata.h"
-#include "net/loginhandler.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include <sstream>
-
-#include "debug.h"
-
-ChangePasswordDialog::ChangePasswordDialog(LoginData &data) :
- // TRANSLATORS: change password window name
- Window(_("Change Password"), Modal_true, nullptr, "changepassword.xml"),
- ActionListener(),
- mOldPassField(new PasswordField(this)),
- mFirstPassField(new PasswordField(this)),
- mSecondPassField(new PasswordField(this)),
- // TRANSLATORS: change password dialog button
- mChangePassButton(new Button(this, _("Change Password"),
- "change_password", this)),
- // TRANSLATORS: change password dialog button
- mCancelButton(new Button(this, _("Cancel"), "cancel", this)),
- mWrongDataNoticeListener(new WrongDataNoticeListener),
- mLoginData(&data)
-{
- Label *const accountLabel = new Label(this,
- // TRANSLATORS: change password dialog label
- strprintf(_("Account: %s"), mLoginData->username.c_str()));
-
- place(0, 0, accountLabel, 3);
- // TRANSLATORS: change password dialog label
- place(0, 1, new Label(this, _("Password:")), 3);
- place(0, 2, mOldPassField, 3).setPadding(1);
- // TRANSLATORS: change password dialog label
- place(0, 3, new Label(this, _("Type new password twice:")), 3);
- place(0, 4, mFirstPassField, 3).setPadding(1);
- place(0, 5, mSecondPassField, 3).setPadding(1);
- place(1, 6, mCancelButton);
- place(2, 6, mChangePassButton);
- reflowLayout(200);
-
- center();
- mOldPassField->requestFocus();
-
- mOldPassField->setActionEventId("change_password");
- mFirstPassField->setActionEventId("change_password");
- mSecondPassField->setActionEventId("change_password");
-}
-
-ChangePasswordDialog::~ChangePasswordDialog()
-{
- delete2(mWrongDataNoticeListener);
-}
-
-void ChangePasswordDialog::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "cancel")
- {
- client->setState(State::CHAR_SELECT);
- }
- else if (eventId == "change_password")
- {
- const std::string username = mLoginData->username;
- const std::string &oldPassword = mOldPassField->getText();
- const std::string &newFirstPass = mFirstPassField->getText();
- const std::string &newSecondPass = mSecondPassField->getText();
- logger->log("ChangePasswordDialog::Password change, Username is %s",
- username.c_str());
-
- std::stringstream errorMsg;
- int error = 0;
-
- const unsigned int min = loginHandler->getMinPasswordLength();
- const unsigned int max = loginHandler->getMaxPasswordLength();
-
- // Check old Password
- if (oldPassword.empty())
- {
- // No old password
- // TRANSLATORS: change password error
- errorMsg << _("Enter the old password first.");
- error = 1;
- }
- else if (newFirstPass.length() < min)
- {
- // First password too short
- // TRANSLATORS: change password error
- errorMsg << strprintf(_("The new password needs to be at least"
- " %u characters long."), min);
- error = 2;
- }
- else if (newFirstPass.length() > max)
- {
- // First password too long
- // TRANSLATORS: change password error
- errorMsg << strprintf(_("The new password needs to be less "
- "than %u characters long."), max);
- error = 2;
- }
- else if (newFirstPass != newSecondPass)
- {
- // Second Pass mismatch
- // TRANSLATORS: change password error
- errorMsg << _("The new password entries mismatch.");
- error = 3;
- }
-
- if (error > 0)
- {
- if (error == 1)
- mWrongDataNoticeListener->setTarget(this->mOldPassField);
- else if (error == 2)
- mWrongDataNoticeListener->setTarget(this->mFirstPassField);
- else // if (error == 3)
- mWrongDataNoticeListener->setTarget(this->mSecondPassField);
-
- OkDialog *const dlg = CREATEWIDGETR(OkDialog,
- // TRANSLATORS: change password error header
- _("Error"),
- errorMsg.str(),
- // TRANSLATORS: ok dialog button
- _("OK"),
- DialogType::ERROR,
- Modal_true,
- ShowCenter_true,
- nullptr,
- 260);
- dlg->addActionListener(mWrongDataNoticeListener);
- }
- else
- {
- // No errors detected, change account password.
- mChangePassButton->setEnabled(false);
- // Set the new password
- mLoginData->password = oldPassword;
- mLoginData->newPassword = newFirstPass;
- client->setState(State::CHANGEPASSWORD_ATTEMPT);
- }
- }
-}
diff --git a/src/gui/windows/changepassworddialog.h b/src/gui/windows/changepassworddialog.h
deleted file mode 100644
index dd5c0d152..000000000
--- a/src/gui/windows/changepassworddialog.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_CHANGEPASSWORDDIALOG_H
-#define GUI_WINDOWS_CHANGEPASSWORDDIALOG_H
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-
-class Button;
-class LoginData;
-class TextField;
-class WrongDataNoticeListener;
-
-/**
- * The Change password dialog.
- *
- * \ingroup Interface
- */
-class ChangePasswordDialog final : public Window,
- public ActionListener
-{
- public:
- /**
- * Constructor
- *
- * @see Window::Window
- */
- explicit ChangePasswordDialog(LoginData &data);
-
- A_DELETE_COPY(ChangePasswordDialog)
-
- /**
- * Destructor
- */
- ~ChangePasswordDialog();
-
- /**
- * Called when receiving actions from the widgets.
- */
- void action(const ActionEvent &event) override final;
-
- private:
- TextField *mOldPassField A_NONNULLPOINTER;
- TextField *mFirstPassField A_NONNULLPOINTER;
- TextField *mSecondPassField A_NONNULLPOINTER;
-
- Button *mChangePassButton A_NONNULLPOINTER;
- Button *mCancelButton A_NONNULLPOINTER;
-
- WrongDataNoticeListener *mWrongDataNoticeListener A_NONNULLPOINTER;
-
- LoginData *mLoginData A_NONNULLPOINTER;
-};
-
-#endif // GUI_WINDOWS_CHANGEPASSWORDDIALOG_H
diff --git a/src/gui/windows/charcreatedialog.cpp b/src/gui/windows/charcreatedialog.cpp
deleted file mode 100644
index 9037ac614..000000000
--- a/src/gui/windows/charcreatedialog.cpp
+++ /dev/null
@@ -1,885 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/charcreatedialog.h"
-
-#include "configuration.h"
-
-#include "enums/being/beingdirection.h"
-
-#include "being/being.h"
-
-#include "gui/windows/okdialog.h"
-
-#include "gui/widgets/button.h"
-#include "gui/windows/charselectdialog.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/playerbox.h"
-#include "gui/widgets/slider.h"
-#include "gui/widgets/tabstrip.h"
-#include "gui/widgets/textfield.h"
-
-#include "net/charserverhandler.h"
-#include "net/serverfeatures.h"
-
-#include "resources/iteminfo.h"
-
-#include "resources/db/chardb.h"
-#include "resources/db/colordb.h"
-#include "resources/db/itemdb.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-#undef ERROR
-
-static const BeingActionT actions[] =
-{
- BeingAction::STAND,
- BeingAction::SIT,
- BeingAction::MOVE,
- BeingAction::ATTACK,
- BeingAction::DEAD
-};
-
-static const uint8_t directions[] =
-{
- BeingDirection::DOWN,
- BeingDirection::RIGHT,
- BeingDirection::UP,
- BeingDirection::LEFT
-};
-
-CharCreateDialog::CharCreateDialog(CharSelectDialog *const parent,
- const int slot) :
- // TRANSLATORS: char create dialog name
- Window(_("New Character"), Modal_true, parent, "charcreate.xml"),
- ActionListener(),
- KeyListener(),
- mCharSelectDialog(parent),
- mNameField(new TextField(this, "")),
- // TRANSLATORS: char create dialog label
- mNameLabel(new Label(this, _("Name:"))),
- mNextHairColorButton(nullptr),
- mPrevHairColorButton(nullptr),
- mHairColorLabel(nullptr),
- mHairColorNameLabel(nullptr),
- mNextHairStyleButton(nullptr),
- mPrevHairStyleButton(nullptr),
- mHairStyleLabel(nullptr),
- mHairStyleNameLabel(nullptr),
- mNextRaceButton(nullptr),
- mPrevRaceButton(nullptr),
- mRaceLabel(nullptr),
- mRaceNameLabel(nullptr),
- mNextLookButton(nullptr),
- mPrevLookButton(nullptr),
- mLookLabel(nullptr),
- mLookNameLabel(nullptr),
- // TRANSLATORS: char create dialog button
- mActionButton(new Button(this, _("^"), "action", this)),
- // TRANSLATORS: char create dialog button
- mRotateButton(new Button(this, _(">"), "rotate", this)),
- mAttributeSlider(),
- mAttributeLabel(),
- mAttributeValue(),
- mAttributesLeft(new Label(this,
- // TRANSLATORS: char create dialog label
- strprintf(_("Please distribute %d points"), 99))),
- // TRANSLATORS: char create dialog button
- mCreateButton(new Button(this, _("Create"), "create", this)),
- // TRANSLATORS: char create dialog button
- mCancelButton(new Button(this, _("Cancel"), "cancel", this)),
- mPlayer(Being::createBeing(BeingId_zero,
- ActorType::Player,
- BeingTypeId_zero,
- nullptr)),
- mPlayerBox(new PlayerBox(this, mPlayer, "charcreate_playerbox.xml",
- "charcreate_selectedplayerbox.xml")),
- mGenderStrip(nullptr),
- mMaxPoints(0),
- mUsedPoints(0),
- mRace(CharDB::getMinRace()),
- mLook(0),
- mMinLook(CharDB::getMinLook()),
- mMaxLook(CharDB::getMaxLook()),
- mMinRace(CharDB::getMinRace()),
- mMaxRace(CharDB::getMaxRace()),
- mHairStyle(0),
- mHairColor(0),
- mMaxY(0U),
- mSlot(slot),
- mDefaultGender(Gender::FEMALE),
- mGender(Gender::UNSPECIFIED),
- maxHairColor(CharDB::getMaxHairColor()),
- minHairColor(CharDB::getMinHairColor()),
- maxHairStyle(CharDB::getMaxHairStyle()),
- minHairStyle(CharDB::getMinHairStyle()),
- mAction(0),
- mDirection(0)
-{
- setStickyButtonLock(true);
- setSticky(true);
- setWindowName("NewCharacter");
-
- const int w = 480;
- const int h = 350;
- setContentSize(w, h);
-
- mPlayer->setGender(Gender::MALE);
- const STD_VECTOR<BeingSlot> &items = CharDB::getDefaultItems();
- int i = 1;
- for (STD_VECTOR<BeingSlot>::const_iterator it = items.begin(),
- it_fend = items.end();
- it != it_fend;
- ++ it, i ++)
- {
- const BeingSlot &beingSlot = *it;
- mPlayer->setSpriteCards(i,
- beingSlot.spriteId,
- beingSlot.cardsId);
- }
-
- if (maxHairColor == 0u)
- maxHairColor = ColorDB::getHairSize();
- if (maxHairStyle == 0u)
- maxHairStyle = ItemDB::getNumOfHairstyles();
-
- if (maxHairStyle != 0u)
- {
- mHairStyle = (CAST_U32(rand())
- % maxHairStyle) + minHairStyle;
- }
- else
- {
- mHairStyle = 0;
- }
- if (maxHairColor != 0u)
- {
- mHairColor = (CAST_U32(rand())
- % maxHairColor) + minHairColor;
- }
- else
- {
- mHairColor = 0;
- }
-
- mNameField->setMaximum(24);
-
- if (maxHairColor > minHairColor)
- {
- // TRANSLATORS: This is a narrow symbol used to denote 'next'.
- // You may change this symbol if your language uses another.
- // TRANSLATORS: char create dialog button
- mNextHairColorButton = new Button(this, _(">"), "nextcolor", this);
- // TRANSLATORS: This is a narrow symbol used to denote 'previous'.
- // You may change this symbol if your language uses another.
- // TRANSLATORS: char create dialog button
- mPrevHairColorButton = new Button(this, _("<"), "prevcolor", this);
- // TRANSLATORS: char create dialog label
- mHairColorLabel = new Label(this, _("Hair color:"));
- mHairColorNameLabel = new Label(this, "");
- }
-
- if (maxHairStyle > minHairStyle)
- {
- // TRANSLATORS: char create dialog button
- mNextHairStyleButton = new Button(this, _(">"), "nextstyle", this);
- // TRANSLATORS: char create dialog button
- mPrevHairStyleButton = new Button(this, _("<"), "prevstyle", this);
- // TRANSLATORS: char create dialog label
- mHairStyleLabel = new Label(this, _("Hair style:"));
- mHairStyleNameLabel = new Label(this, "");
- }
-
- if (serverFeatures->haveRaceSelection() && mMinRace < mMaxRace)
- {
- // TRANSLATORS: char create dialog button
- mNextRaceButton = new Button(this, _(">"), "nextrace", this);
- // TRANSLATORS: char create dialog button
- mPrevRaceButton = new Button(this, _("<"), "prevrace", this);
- // TRANSLATORS: char create dialog label
- mRaceLabel = new Label(this, _("Race:"));
- mRaceNameLabel = new Label(this, "");
- }
- if (serverFeatures->haveLookSelection() && mMinLook < mMaxLook)
- {
- // TRANSLATORS: char create dialog button
- mNextLookButton = new Button(this, _(">"), "nextlook", this);
- // TRANSLATORS: char create dialog button
- mPrevLookButton = new Button(this, _("<"), "prevlook", this);
- // TRANSLATORS: char create dialog label
- mLookLabel = new Label(this, _("Look:"));
- mLookNameLabel = new Label(this, "");
- }
-
- if (serverFeatures->haveCreateCharGender())
- {
- const int forceGender = features.getIntValue("forceCharGender");
- if (forceGender == -1)
- {
- const int size = config.getIntValue("fontSize");
- mGenderStrip = new TabStrip(this,
- "gender_" + getWindowName(),
- size + 16);
- mGenderStrip->setPressFirst(false);
- mGenderStrip->addActionListener(this);
- mGenderStrip->setActionEventId("gender_");
- // TRANSLATORS: one char size female character gender
- mGenderStrip->addButton(_("F"), "f", false);
- if (features.getIntValue("forceAccountGender") == -1)
- {
- if (serverFeatures->haveCharOtherGender())
- {
- // TRANSLATORS: one char size male character gender
- mGenderStrip->addButton(_("M"), "m", true);
- // TRANSLATORS: one char size other character gender
- mGenderStrip->addButton(_("O"), "o", false);
- }
- else
- {
- // TRANSLATORS: one char size male character gender
- mGenderStrip->addButton(_("M"), "m", false);
- // TRANSLATORS: one char size unknown character gender
- mGenderStrip->addButton(_("U"), "u", true);
- }
- }
- else
- {
- // TRANSLATORS: one char size male character gender
- mGenderStrip->addButton(_("M"), "m", true);
- if (serverFeatures->haveCharOtherGender())
- {
- // TRANSLATORS: one char size other character gender
- mGenderStrip->addButton(_("O"), "o", false);
- }
- }
-
-
- mGenderStrip->setVisible(Visible_true);
- add(mGenderStrip);
-
- mGenderStrip->setPosition(385, 130);
- mGenderStrip->setWidth(500);
- mGenderStrip->setHeight(50);
- }
- else
- {
- mGender = Being::intToGender(CAST_U8(forceGender));
- mPlayer->setGender(mGender);
- }
- }
-
- mPlayerBox->setWidth(74);
-
- mNameField->setActionEventId("create");
- mNameField->addActionListener(this);
-
- mPlayerBox->setDimension(Rect(360, 0, 110, 90));
- mActionButton->setPosition(385, 100);
- mRotateButton->setPosition(415, 100);
-
- mNameLabel->setPosition(mPadding, 2);
- mNameField->setDimension(Rect(60, 2,
- 300, mNameField->getHeight()));
-
- const uint32_t labelPadding = getOption("labelPadding", 2);
- const uint32_t leftX = 120 + mPadding;
- const uint32_t rightX = 300 + mPadding;
- const uint32_t labelX = mPadding;
- uint32_t nameX = leftX + labelPadding;
- uint32_t y = 30;
- if (mPrevHairColorButton != nullptr)
- nameX += mPrevHairColorButton->getWidth();
- else if (mPrevHairStyleButton != nullptr)
- nameX += mPrevHairStyleButton->getWidth();
- else if (mPrevLookButton != nullptr)
- nameX += mPrevLookButton->getWidth();
- else if (mPrevRaceButton != nullptr)
- nameX += mPrevRaceButton->getWidth();
-
- if (maxHairColor > minHairColor)
- {
- mPrevHairColorButton->setPosition(leftX, y);
- mNextHairColorButton->setPosition(rightX, y);
- y += 5;
- mHairColorLabel->setPosition(labelX, y);
- mHairColorNameLabel->setPosition(nameX, y);
- y += 24;
- }
- if (maxHairStyle > minHairStyle)
- {
- mPrevHairStyleButton->setPosition(leftX, y);
- mNextHairStyleButton->setPosition(rightX, y);
- y += 5;
- mHairStyleLabel->setPosition(labelX, y);
- mHairStyleNameLabel->setPosition(nameX, y);
- y += 24;
- }
-
- if (serverFeatures->haveLookSelection() && mMinLook < mMaxLook)
- {
- if (mPrevLookButton != nullptr)
- mPrevLookButton->setPosition(leftX, y);
- if (mNextLookButton != nullptr)
- mNextLookButton->setPosition(rightX, y);
- y += 5;
- if (mLookLabel != nullptr)
- mLookLabel->setPosition(labelX, y);
- if (mLookNameLabel != nullptr)
- mLookNameLabel->setPosition(nameX, y); // 93
- y += 24;
- }
- if (serverFeatures->haveRaceSelection() && mMinRace < mMaxRace)
- {
- if (mPrevRaceButton != nullptr)
- mPrevRaceButton->setPosition(leftX, y);
- if (mNextRaceButton != nullptr)
- mNextRaceButton->setPosition(rightX, y);
- y += 5;
- if (mRaceLabel != nullptr)
- mRaceLabel->setPosition(labelX, y);
- if (mRaceNameLabel != nullptr)
- mRaceNameLabel->setPosition(nameX, y);
- }
- mMaxY = y + 29 + getTitlePadding();
-
- updateSliders();
- setButtonsPosition(w, h);
-
- add(mPlayerBox);
- add(mNameField);
- add(mNameLabel);
-
- if (maxHairColor > minHairColor)
- {
- add(mNextHairColorButton);
- add(mPrevHairColorButton);
- add(mHairColorLabel);
- add(mHairColorNameLabel);
- }
-
- if (maxHairStyle > minHairStyle)
- {
- add(mNextHairStyleButton);
- add(mPrevHairStyleButton);
- add(mHairStyleLabel);
- add(mHairStyleNameLabel);
- }
- add(mActionButton);
- add(mRotateButton);
-
- if (serverFeatures->haveLookSelection() && mMinLook < mMaxLook)
- {
- add(mNextLookButton);
- add(mPrevLookButton);
- add(mLookLabel);
- add(mLookNameLabel);
- }
-
- if (serverFeatures->haveRaceSelection() && mMinRace < mMaxRace)
- {
- add(mNextRaceButton);
- add(mPrevRaceButton);
- add(mRaceLabel);
- add(mRaceNameLabel);
- }
-
- add(mAttributesLeft);
- add(mCreateButton);
- add(mCancelButton);
-
- center();
- setVisible(Visible_true);
- mNameField->requestFocus();
-
- updateHair();
- if (serverFeatures->haveRaceSelection() && mMinRace < mMaxRace)
- updateRace();
- if (serverFeatures->haveLookSelection() && mMinLook < mMaxLook)
- updateLook();
- updatePlayer();
-
- addKeyListener(this);
-}
-
-CharCreateDialog::~CharCreateDialog()
-{
- delete2(mPlayer);
-
- if (charServerHandler != nullptr)
- charServerHandler->setCharCreateDialog(nullptr);
-}
-
-void CharCreateDialog::action(const ActionEvent &event)
-{
- const std::string &id = event.getId();
- if (id == "create")
- {
- if (getName().length() >= 4)
- {
- // Attempt to create the character
- mCreateButton->setEnabled(false);
-
- STD_VECTOR<int> atts;
- const size_t sz = mAttributeSlider.size();
- for (size_t i = 0; i < sz; i++)
- {
- atts.push_back(CAST_S32(
- mAttributeSlider[i]->getValue()));
- }
- for (size_t i = sz; i < 6; i ++)
- atts.push_back(1);
-
- const int characterSlot = mSlot;
-
- charServerHandler->newCharacter(getName(),
- characterSlot,
- mGender,
- mHairStyle,
- mHairColor,
- CAST_U8(mRace),
- CAST_U8(mLook),
- atts);
- }
- else
- {
- CREATEWIDGET(OkDialog,
- // TRANSLATORS: char creation error
- _("Error"),
- // TRANSLATORS: char creation error
- _("Your name needs to be at least 4 characters."),
- // TRANSLATORS: ok dialog button
- _("OK"),
- DialogType::ERROR,
- Modal_true,
- ShowCenter_true,
- nullptr,
- 260);
- }
- }
- else if (id == "cancel")
- {
- scheduleDelete();
- }
- else if (id == "nextcolor")
- {
- mHairColor ++;
- updateHair();
- }
- else if (id == "prevcolor")
- {
- mHairColor --;
- updateHair();
- }
- else if (id == "nextstyle")
- {
- mHairStyle ++;
- updateHair();
- }
- else if (id == "prevstyle")
- {
- mHairStyle --;
- updateHair();
- }
- else if (id == "nextrace")
- {
- mRace ++;
- updateRace();
- }
- else if (id == "prevrace")
- {
- mRace --;
- updateRace();
- }
- else if (id == "nextlook")
- {
- mLook ++;
- updateLook();
- }
- else if (id == "prevlook")
- {
- mLook --;
- updateLook();
- }
- else if (id == "statslider")
- {
- updateSliders();
- }
- else if (id == "action")
- {
- mAction ++;
- if (mAction >= 5)
- mAction = 0;
- updatePlayer();
- }
- else if (id == "rotate")
- {
- mDirection ++;
- if (mDirection >= 4)
- mDirection = 0;
- updatePlayer();
- }
- else if (id == "gender_m")
- {
- mGender = Gender::MALE;
- mPlayer->setGender(Gender::MALE);
- }
- else if (id == "gender_f")
- {
- mGender = Gender::FEMALE;
- mPlayer->setGender(Gender::FEMALE);
- }
- else if (id == "gender_u")
- {
- mGender = Gender::UNSPECIFIED;
- mPlayer->setGender(mDefaultGender);
- }
- else if (id == "gender_o")
- {
- mGender = Gender::OTHER;
- mPlayer->setGender(Gender::OTHER);
- }
-}
-
-std::string CharCreateDialog::getName() const
-{
- std::string name = mNameField->getText();
- trim(name);
- return name;
-}
-
-void CharCreateDialog::updateSliders()
-{
- for (size_t i = 0, sz = mAttributeSlider.size(); i < sz; i++)
- {
- // Update captions
- mAttributeValue[i]->setCaption(
- toString(CAST_S32(mAttributeSlider[i]->getValue())));
- mAttributeValue[i]->adjustSize();
- }
-
- // Update distributed points
- const int pointsLeft = mMaxPoints - getDistributedPoints();
- if (pointsLeft == 0)
- {
- // TRANSLATORS: char create dialog label
- mAttributesLeft->setCaption(_("Character stats OK"));
- mCreateButton->setEnabled(true);
- }
- else
- {
- mCreateButton->setEnabled(false);
- if (pointsLeft > 0)
- {
- mAttributesLeft->setCaption(
- // TRANSLATORS: char create dialog label
- strprintf(_("Please distribute %d points"), pointsLeft));
- }
- else
- {
- mAttributesLeft->setCaption(
- // TRANSLATORS: char create dialog label
- strprintf(_("Please remove %d points"), -pointsLeft));
- }
- }
-
- mAttributesLeft->adjustSize();
-}
-
-void CharCreateDialog::unlock()
-{
- mCreateButton->setEnabled(true);
-}
-
-int CharCreateDialog::getDistributedPoints() const
-{
- int points = 0;
-
- for (size_t i = 0, sz = mAttributeSlider.size(); i < sz; i++)
- points += CAST_S32(mAttributeSlider[i]->getValue());
- return points;
-}
-
-void CharCreateDialog::setAttributes(const StringVect &labels,
- int available,
- const int min, const int max)
-{
- size_t sz;
-
- if (min == max || available == 0)
- {
- sz = 0U;
- available = 0;
- }
- else
- {
- sz = labels.size();
- }
-
- mMaxPoints = available;
-
- for (size_t i = 0; i < mAttributeLabel.size(); i++)
- {
- remove(mAttributeLabel[i]);
- delete2(mAttributeLabel[i])
- remove(mAttributeSlider[i]);
- delete2(mAttributeSlider[i])
- remove(mAttributeValue[i]);
- delete2(mAttributeValue[i])
- }
-
- mAttributeLabel.resize(sz);
- mAttributeSlider.resize(sz);
- mAttributeValue.resize(sz);
-
- const uint32_t w = 480;
- uint32_t h = 350;
- uint32_t y = 89;
- if (serverFeatures->haveLookSelection() && mMinLook < mMaxLook)
- y += 29;
- if (serverFeatures->haveRaceSelection() && mMinRace < mMaxRace)
- y += 29;
-
- for (size_t i = 0; i < sz; i++)
- {
- mAttributeLabel[i] = new Label(this, labels[i]);
- mAttributeLabel[i]->setWidth(70);
- mAttributeLabel[i]->setPosition(mPadding,
- y + CAST_S32(i * 24));
- mAttributeLabel[i]->adjustSize();
- add(mAttributeLabel[i]);
-
- mAttributeSlider[i] = new Slider(this, min, max, 1.0);
- mAttributeSlider[i]->setDimension(Rect(140 + mPadding,
- y + CAST_S32(i * 24),
- 150,
- 12));
- mAttributeSlider[i]->setActionEventId("statslider");
- mAttributeSlider[i]->addActionListener(this);
- add(mAttributeSlider[i]);
-
- mAttributeValue[i] = new Label(this, toString(min));
- mAttributeValue[i]->setPosition(295 + mPadding,
- y + CAST_S32(i * 24));
- add(mAttributeValue[i]);
- }
-
- updateSliders();
- if (available == 0)
- {
- mAttributesLeft->setVisible(Visible_false);
- h = y;
- }
- else
- {
- h = y +
- CAST_S32(sz) * 24 +
- mAttributesLeft->getHeight() +
- getPadding();
- }
- if (serverFeatures->haveCreateCharGender() &&
- features.getIntValue("forceCharGender") == -1 &&
- y < 160)
- {
- if (h < 160)
- h = 160;
- }
- if (h < mMaxY)
- h = mMaxY;
- if (serverFeatures->haveCreateCharGender())
- {
- const int forceGender = features.getIntValue("forceCharGender");
- if (forceGender == -1 && h < 180)
- h = 180;
- else if (h < 120)
- h = 120;
- }
- h += mCreateButton->getHeight();
-
- setContentSize(w, h);
- setButtonsPosition(w, h);
-}
-
-void CharCreateDialog::setDefaultGender(const GenderT gender)
-{
- if (features.getIntValue("forceCharGender") != -1)
- return;
-
- mDefaultGender = gender;
- mPlayer->setGender(gender);
-}
-
-void CharCreateDialog::updateHair()
-{
- if (mHairStyle <= 0)
- mHairStyle = ItemDB::getNumOfHairstyles() - 1;
- else
- mHairStyle %= ItemDB::getNumOfHairstyles();
- if (mHairStyle < CAST_S32(minHairStyle)
- || mHairStyle > CAST_S32(maxHairStyle))
- {
- mHairStyle = minHairStyle;
- }
- const ItemInfo &item = ItemDB::get(-mHairStyle);
- if (mHairStyleNameLabel != nullptr)
- {
- mHairStyleNameLabel->setCaption(item.getName());
- mHairStyleNameLabel->resizeTo(150, 150);
- }
-
- if (ColorDB::getHairSize() != 0)
- mHairColor %= ColorDB::getHairSize();
- else
- mHairColor = 0;
- if (mHairColor < 0)
- mHairColor += ColorDB::getHairSize();
- if (mHairColor < CAST_S32(minHairColor)
- || mHairColor > CAST_S32(maxHairColor))
- {
- mHairColor = minHairColor;
- }
- if (mHairColorNameLabel != nullptr)
- {
- mHairColorNameLabel->setCaption(ColorDB::getHairColorName(
- fromInt(mHairColor, ItemColor)));
- mHairColorNameLabel->resizeTo(150, 150);
- }
-
- mPlayer->setSpriteColor(charServerHandler->hairSprite(),
- mHairStyle * -1,
- item.getDyeColorsString(fromInt(mHairColor, ItemColor)));
- updatePlayer();
-}
-
-void CharCreateDialog::updateRace()
-{
- if (mRace < mMinRace)
- mRace = mMaxRace;
- else if (mRace > mMaxRace)
- mRace = mMinRace;
-
- updateLook();
-}
-
-void CharCreateDialog::updateLook()
-{
- const ItemInfo &item = ItemDB::get(-100 - mRace);
- const int sz = item.getColorsSize();
- if (sz > 0 && serverFeatures->haveLookSelection())
- {
- if (mLook < 0)
- mLook = sz - 1;
- if (mLook > mMaxLook)
- mLook = mMinLook;
- if (mLook >= sz)
- mLook = mMinLook;
- }
- else
- {
- mLook = 0;
- }
- mPlayer->setSubtype(fromInt(mRace, BeingTypeId),
- CAST_U8(mLook));
- if (mRaceNameLabel != nullptr)
- {
- mRaceNameLabel->setCaption(item.getName());
- mRaceNameLabel->resizeTo(150, 150);
- }
- if (mLookNameLabel != nullptr)
- {
- mLookNameLabel->setCaption(item.getColorName(
- fromInt(mLook, ItemColor)));
- mLookNameLabel->resizeTo(150, 150);
- }
-}
-
-void CharCreateDialog::logic()
-{
- BLOCK_START("CharCreateDialog::logic")
- if (mPlayer != nullptr)
- mPlayer->logic();
- BLOCK_END("CharCreateDialog::logic")
-}
-
-void CharCreateDialog::updatePlayer()
-{
- if (mPlayer != nullptr)
- {
- mPlayer->setDirection(directions[mDirection]);
- mPlayer->setAction(actions[mAction], 0);
- }
-}
-
-void CharCreateDialog::keyPressed(KeyEvent &event)
-{
- const InputActionT actionId = event.getActionId();
- PRAGMA45(GCC diagnostic push)
- PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
- switch (actionId)
- {
- case InputAction::GUI_CANCEL:
- event.consume();
- action(ActionEvent(mCancelButton,
- mCancelButton->getActionEventId()));
- break;
-
- default:
- break;
- }
- PRAGMA45(GCC diagnostic pop)
-}
-
-void CharCreateDialog::setButtonsPosition(const int w, const int h)
-{
- const int h2 = h - 5 - mCancelButton->getHeight();
- if (mainGraphics->getHeight() < 480)
- {
- if (mMaxPoints != 0)
- {
- mCreateButton->setPosition(337, 160);
- mCancelButton->setPosition(337 + mCreateButton->getWidth(), 160);
- }
- else
- {
- mCancelButton->setPosition(
- w / 2,
- 160);
- mCreateButton->setPosition(
- mCancelButton->getX() - 5 - mCreateButton->getWidth(),
- 160);
- }
- }
- else
- {
- mCancelButton->setPosition(
- w / 2,
- h2);
- mCreateButton->setPosition(
- mCancelButton->getX() - 5 - mCreateButton->getWidth(),
- h2);
- }
- mAttributesLeft->setPosition(15, h2 - mAttributesLeft->getHeight());
-}
diff --git a/src/gui/windows/charcreatedialog.h b/src/gui/windows/charcreatedialog.h
deleted file mode 100644
index 5c4fdfcc3..000000000
--- a/src/gui/windows/charcreatedialog.h
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_CHARCREATEDIALOG_H
-#define GUI_WINDOWS_CHARCREATEDIALOG_H
-
-#include "enums/being/gender.h"
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/keylistener.h"
-
-class Being;
-class Button;
-class CharSelectDialog;
-class Label;
-class PlayerBox;
-class Slider;
-class TabStrip;
-class TextField;
-
-/**
- * Character creation dialog.
- *
- * \ingroup Interface
- */
-class CharCreateDialog final : public Window,
- public ActionListener,
- public KeyListener
-{
- public:
- /**
- * Constructor.
- */
- CharCreateDialog(CharSelectDialog *const parent, const int slot);
-
- A_DELETE_COPY(CharCreateDialog)
-
- /**
- * Destructor.
- */
- ~CharCreateDialog();
-
- void action(const ActionEvent &event) override final;
-
- /**
- * Unlocks the dialog, enabling the create character button again.
- */
- void unlock();
-
- void setAttributes(const StringVect &labels,
- int available,
- const int min, const int max);
-
- void setDefaultGender(const GenderT gender = Gender::FEMALE);
-
- void logic() override final;
-
- void updatePlayer();
-
- void keyPressed(KeyEvent &event) override final;
-
- private:
- int getDistributedPoints() const A_WARN_UNUSED;
-
- void updateSliders();
-
- void setButtonsPosition(const int w, const int h);
-
- /**
- * Returns the name of the character to create.
- */
- std::string getName() const A_WARN_UNUSED;
-
- /**
- * Communicate character creation to the server.
- */
- void attemptCharCreate();
-
- void updateHair();
-
- void updateRace();
-
- void updateLook();
-
- CharSelectDialog *mCharSelectDialog;
-
- TextField *mNameField A_NONNULLPOINTER;
- Label *mNameLabel A_NONNULLPOINTER;
- Button *mNextHairColorButton A_NONNULLPOINTER;
- Button *mPrevHairColorButton A_NONNULLPOINTER;
- Label *mHairColorLabel A_NONNULLPOINTER;
- Label *mHairColorNameLabel A_NONNULLPOINTER;
- Button *mNextHairStyleButton A_NONNULLPOINTER;
- Button *mPrevHairStyleButton A_NONNULLPOINTER;
- Label *mHairStyleLabel A_NONNULLPOINTER;
- Label *mHairStyleNameLabel A_NONNULLPOINTER;
- Button *mNextRaceButton;
- Button *mPrevRaceButton;
- Label *mRaceLabel;
- Label *mRaceNameLabel;
- Button *mNextLookButton;
- Button *mPrevLookButton;
- Label *mLookLabel;
- Label *mLookNameLabel;
-
- Button *mActionButton;
- Button *mRotateButton;
-
- STD_VECTOR<Slider*> mAttributeSlider;
- STD_VECTOR<Label*> mAttributeLabel;
- STD_VECTOR<Label*> mAttributeValue;
- Label *mAttributesLeft;
-
- Button *mCreateButton;
- Button *mCancelButton;
-
- Being *mPlayer;
- PlayerBox *mPlayerBox;
-
- TabStrip *mGenderStrip;
-
- int mMaxPoints;
- int mUsedPoints;
-
- int mRace;
- int mLook;
- int mMinLook;
- int mMaxLook;
- int mMinRace;
- int mMaxRace;
-
- int mHairStyle;
- int mHairColor;
- uint32_t mMaxY;
-
- int mSlot;
-
- GenderT mDefaultGender;
- GenderT mGender;
-
- unsigned int maxHairColor;
- unsigned int minHairColor;
- unsigned int maxHairStyle;
- unsigned int minHairStyle;
-
- unsigned int mAction;
- unsigned int mDirection;
-};
-
-#endif // GUI_WINDOWS_CHARCREATEDIALOG_H
diff --git a/src/gui/windows/chardeleteconfirm.h b/src/gui/windows/chardeleteconfirm.h
deleted file mode 100644
index 7049050a3..000000000
--- a/src/gui/windows/chardeleteconfirm.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_CHARDELETECONFIRM_H
-#define GUI_WINDOWS_CHARDELETECONFIRM_H
-
-#include "gui/windows/charselectdialog.h"
-#include "gui/windows/confirmdialog.h"
-
-#include "utils/gettext.h"
-
-#include "localconsts.h"
-
-/**
- * Listener for confirming character deletion.
- */
-class CharDeleteConfirm final : public ConfirmDialog
-{
- public:
- CharDeleteConfirm(CharSelectDialog *const m, const int index) :
- // TRANSLATORS: char deletion message
- ConfirmDialog(_("Confirm Character Delete"),
- // TRANSLATORS: char deletion message
- _("Are you sure you want to delete this character?"),
- SOUND_REQUEST, false, Modal_false, m),
- mMaster(m),
- mIndex(index)
- {
- }
-
- A_DELETE_COPY(CharDeleteConfirm)
-
- void action(const ActionEvent &event) override final
- {
- if (event.getId() == "yes" && (mMaster != nullptr))
- mMaster->askPasswordForDeletion(mIndex);
-
- ConfirmDialog::action(event);
- }
-
- private:
- CharSelectDialog *mMaster;
- int mIndex;
-};
-
-#endif // GUI_WINDOWS_CHARDELETECONFIRM_H
diff --git a/src/gui/windows/charselectdialog.cpp b/src/gui/windows/charselectdialog.cpp
deleted file mode 100644
index 5a0a02acb..000000000
--- a/src/gui/windows/charselectdialog.cpp
+++ /dev/null
@@ -1,644 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/charselectdialog.h"
-
-#include "client.h"
-#include "configuration.h"
-
-#include "listeners/charrenamelistener.h"
-#include "listeners/pincodelistener.h"
-
-#include "gui/windows/charcreatedialog.h"
-#include "gui/windows/chardeleteconfirm.h"
-#include "gui/windows/editdialog.h"
-#include "gui/windows/logindialog.h"
-#include "gui/windows/okdialog.h"
-#include "gui/windows/textdialog.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/characterdisplay.h"
-#include "gui/widgets/characterviewnormal.h"
-#include "gui/widgets/characterviewsmall.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/createwidget.h"
-
-#include "net/character.h"
-#include "net/charserverhandler.h"
-#include "net/logindata.h"
-#ifdef TMWA_SUPPORT
-#include "net/net.h"
-#endif // TMWA_SUPPORT
-#include "net/serverfeatures.h"
-
-#include "utils/foreach.h"
-
-#include "resources/db/unitsdb.h"
-
-#include "debug.h"
-
-// Character slots per row in the dialog
-static const int SLOTS_PER_ROW = 5;
-
-CharSelectDialog::CharSelectDialog(LoginData &data) :
- // TRANSLATORS: char select dialog name
- Window(strprintf(_("Account %s (last login time %s)"),
- data.username.c_str(), data.lastLogin.c_str()),
- Modal_false,
- nullptr,
- "char.xml"),
- ActionListener(),
- KeyListener(),
- mLoginData(&data),
- // TRANSLATORS: char select dialog. button.
- mSwitchLoginButton(new Button(this, _("Switch"), "switch", this)),
- // TRANSLATORS: char select dialog. button.
- mChangePasswordButton(new Button(this, _("Password"),
- "change_password", this)),
- // TRANSLATORS: char select dialog. button.
- mPlayButton(new Button(this, _("Play"), "use", this)),
- // TRANSLATORS: char select dialog. button.
- mInfoButton(new Button(this, _("Info"), "info", this)),
- // TRANSLATORS: char select dialog. button.
- mDeleteButton(new Button(this, _("Delete"), "delete", this)),
- // TRANSLATORS: char select dialog. button.
- mRenameButton(nullptr),
- mCharacterView(nullptr),
- mCharacterEntries(0),
- mCharServerHandler(charServerHandler),
- mDeleteDialog(nullptr),
- mDeleteIndex(-1),
- mLocked(false),
- mSmallScreen(mainGraphics->getWidth() < 470
- || mainGraphics->getHeight() < 370)
-{
- setCloseButton(true);
- setFocusable(true);
-
- ContainerPlacer placer;
- placer = getPlacer(0, 0);
-
- placer(0, 0, mSwitchLoginButton);
-
- int n = 1;
- placer(n, 0, mChangePasswordButton);
- n ++;
- placer(n, 0, mDeleteButton);
- n ++;
-#ifdef TMWA_SUPPORT
- if (Net::getNetworkType() != ServerType::TMWATHENA)
-#endif
- {
- mRenameButton = new Button(this,
- // TRANSLATORS: character rename button
- _("Rename"),
- "rename",
- this);
- placer(n, 0, mRenameButton);
- n ++;
- }
- placer(n, 0, mInfoButton);
- n ++;
-
- for (int i = 0; i < CAST_S32(mLoginData->characterSlots); i++)
- {
- CharacterDisplay *const character = new CharacterDisplay(this, this);
- character->setVisible(Visible_false);
- mCharacterEntries.push_back(character);
- }
-
- placer(0, 2, mPlayButton);
-
- if (!mSmallScreen)
- {
- mCharacterView = new CharacterViewNormal(
- this, &mCharacterEntries, mPadding);
- placer(0, 1, mCharacterView, 10);
- int sz = 410 + 2 * mPadding;
- if (config.getIntValue("fontSize") > 18)
- sz = 500 + 2 * mPadding;
- const int width = mCharacterView->getWidth() + 2 * mPadding;
- if (sz < width)
- sz = width;
- if (sz > mainGraphics->getWidth())
- sz = mainGraphics->getWidth();
- reflowLayout(sz);
- }
- else
- {
- // TRANSLATORS: char select dialog name
- setCaption(strprintf(_("Account %s"), mLoginData->username.c_str()));
- mCharacterView = new CharacterViewSmall(
- this, &mCharacterEntries, mPadding);
- mCharacterView->setWidth(mainGraphics->getWidth()
- - 2 * getPadding());
- placer(0, 1, mCharacterView, 10);
- reflowLayout();
- }
- addKeyListener(this);
- center();
-
- charServerHandler->setCharSelectDialog(this);
- mCharacterView->show(0);
- updateState();
-}
-
-CharSelectDialog::~CharSelectDialog()
-{
-}
-
-void CharSelectDialog::postInit()
-{
- Window::postInit();
- setVisible(Visible_true);
- requestFocus();
- if (charServerHandler->isNeedCreatePin())
- {
- EditDialog *const dialog = CREATEWIDGETR(EditDialog,
- // TRANSLATORS: pin code dialog header.
- _("Please set new pincode"),
- "",
- "OK");
- dialog->addActionListener(&pincodeListener);
- }
-}
-
-void CharSelectDialog::action(const ActionEvent &event)
-{
- // Check if a button of a character was pressed
- const Widget *const sourceParent = event.getSource()->getParent();
- int selected = -1;
- for (unsigned int i = 0, fsz = CAST_U32(
- mCharacterEntries.size());
- i < fsz;
- ++i)
- {
- if (mCharacterEntries[i] == sourceParent)
- {
- selected = i;
- mCharacterView->show(i);
- updateState();
- break;
- }
- }
- if (selected == -1)
- selected = mCharacterView->getSelected();
-
- const std::string &eventId = event.getId();
-
- if (selected >= 0)
- {
- if (eventId == "use")
- {
- use(selected);
- return;
- }
- else if (eventId == "delete"
- && (mCharacterEntries[selected]->getCharacter() != nullptr))
- {
- CREATEWIDGET(CharDeleteConfirm, this, selected);
- return;
- }
- else if (eventId == "rename"
- && (mCharacterEntries[selected]->getCharacter() != nullptr))
- {
- const LocalPlayer *const player = mCharacterEntries[
- selected]->getCharacter()->dummy;
- EditDialog *const dialog = CREATEWIDGETR(EditDialog,
- // TRANSLATORS: character rename dialog header.
- _("Please enter new name"),
- player->getName(),
- "OK");
- charRenameListener.setId(player->getId());
- charRenameListener.setDialog(dialog);
- dialog->addActionListener(&charRenameListener);
- }
- else if (eventId == "info")
- {
- Net::Character *const character = mCharacterEntries[
- selected]->getCharacter();
- if (character == nullptr)
- return;
-
- const LocalPlayer *const data = character->dummy;
- if (data == nullptr)
- return;
-
- const std::string strExp = toString(CAST_U64(
- character->data.mAttributes[Attributes::PLAYER_EXP]));
- const std::string msg = strprintf(
- // TRANSLATORS: char select dialog. player info message.
- _("Hp: %u/%u\nMp: %u/%u\nLevel: %u\n"
- "Experience: %s\nMoney: %s"),
- CAST_U32(
- character->data.mAttributes[Attributes::PLAYER_HP]),
- CAST_U32(
- character->data.mAttributes[Attributes::PLAYER_MAX_HP]),
- CAST_U32(
- character->data.mAttributes[Attributes::PLAYER_MP]),
- CAST_U32(
- character->data.mAttributes[Attributes::PLAYER_MAX_MP]),
- CAST_U32(
- character->data.mAttributes[Attributes::PLAYER_BASE_LEVEL]),
- strExp.c_str(),
- UnitsDb::formatCurrency(CAST_S32(
- character->data.mAttributes[Attributes::MONEY])).c_str());
- CREATEWIDGET(OkDialog, data->getName(), msg,
- // TRANSLATORS: ok dialog button
- _("OK"),
- DialogType::SILENCE,
- Modal_true,
- ShowCenter_true,
- nullptr,
- 260);
- }
- }
- if (eventId == "switch")
- {
- charServerHandler->clear();
- close();
- }
- else if (eventId == "change_password")
- {
- client->setState(State::CHANGEPASSWORD);
- }
- else if (eventId == "change_email")
- {
- client->setState(State::CHANGEEMAIL);
- }
- else if (eventId == "try delete character")
- {
- if ((mDeleteDialog != nullptr) && mDeleteIndex != -1)
- {
- if (serverFeatures->haveEmailOnDelete())
- {
- attemptCharacterDelete(mDeleteIndex, mDeleteDialog->getText());
- mDeleteDialog = nullptr;
- }
- else if (mDeleteDialog->getText() == LoginDialog::savedPassword)
- {
- attemptCharacterDelete(mDeleteIndex, "");
- mDeleteDialog = nullptr;
- }
- else
- {
- CREATEWIDGET(OkDialog,
- // TRANSLATORS: error header
- _("Error"),
- // TRANSLATORS: error message
- _("Incorrect password"),
- // TRANSLATORS: ok dialog button
- _("OK"),
- DialogType::ERROR,
- Modal_true,
- ShowCenter_true,
- nullptr,
- 260);
- }
- }
- mDeleteIndex = -1;
- }
-}
-
-void CharSelectDialog::use(const int selected)
-{
- if ((mCharacterEntries[selected] != nullptr)
- && (mCharacterEntries[selected]->getCharacter() != nullptr))
- {
- attemptCharacterSelect(selected);
- }
- else
- {
- CharCreateDialog *const charCreateDialog =
- CREATEWIDGETR(CharCreateDialog, this, selected);
- mCharServerHandler->setCharCreateDialog(charCreateDialog);
- }
-}
-
-void CharSelectDialog::keyPressed(KeyEvent &event)
-{
- const InputActionT actionId = event.getActionId();
- PRAGMA45(GCC diagnostic push)
- PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
- switch (actionId)
- {
- case InputAction::GUI_CANCEL:
- event.consume();
- action(ActionEvent(mSwitchLoginButton,
- mSwitchLoginButton->getActionEventId()));
- break;
-
- case InputAction::GUI_RIGHT:
- {
- event.consume();
- int idx = mCharacterView->getSelected();
- if (idx >= 0)
- {
- idx ++;
- if (idx == SLOTS_PER_ROW)
- break;
- mCharacterView->show(idx);
- updateState();
- }
- break;
- }
-
- case InputAction::GUI_LEFT:
- {
- event.consume();
- int idx = mCharacterView->getSelected();
- if (idx >= 0)
- {
- if ((idx == 0) || idx == SLOTS_PER_ROW)
- break;
- idx --;
- mCharacterView->show(idx);
- updateState();
- }
- break;
- }
-
- case InputAction::GUI_UP:
- {
- event.consume();
- int idx = mCharacterView->getSelected();
- if (idx >= 0)
- {
- if (idx < SLOTS_PER_ROW)
- break;
- idx -= SLOTS_PER_ROW;
- mCharacterView->show(idx);
- updateState();
- }
- break;
- }
-
- case InputAction::GUI_DOWN:
- {
- event.consume();
- int idx = mCharacterView->getSelected();
- if (idx >= 0)
- {
- if (idx >= SLOTS_PER_ROW)
- break;
- idx += SLOTS_PER_ROW;
- mCharacterView->show(idx);
- updateState();
- }
- break;
- }
-
- case InputAction::GUI_DELETE:
- {
- event.consume();
- const int idx = mCharacterView->getSelected();
- if (idx >= 0 && (mCharacterEntries[idx] != nullptr)
- && (mCharacterEntries[idx]->getCharacter() != nullptr))
- {
- CREATEWIDGET(CharDeleteConfirm, this, idx);
- }
- break;
- }
-
- case InputAction::GUI_SELECT:
- {
- event.consume();
- use(mCharacterView->getSelected());
- break;
- }
- default:
- break;
- }
- PRAGMA45(GCC diagnostic pop)
-}
-
-/**
- * Communicate character deletion to the server.
- */
-void CharSelectDialog::attemptCharacterDelete(const int index,
- const std::string &email)
-{
- if (mLocked)
- return;
-
- if (mCharacterEntries[index] != nullptr)
- {
- mCharServerHandler->deleteCharacter(
- mCharacterEntries[index]->getCharacter(),
- email);
- }
- lock();
-}
-
-void CharSelectDialog::askPasswordForDeletion(const int index)
-{
- mDeleteIndex = index;
- if (serverFeatures->haveEmailOnDelete())
- {
- CREATEWIDGETV(mDeleteDialog, TextDialog,
- // TRANSLATORS: char deletion question.
- _("Enter your email for deleting character"),
- // TRANSLATORS: email label.
- _("Enter email:"),
- this, false);
- }
- else
- {
- CREATEWIDGETV(mDeleteDialog, TextDialog,
- // TRANSLATORS: char deletion question.
- _("Enter password for deleting character"),
- // TRANSLATORS: email label.
- _("Enter password:"),
- this, true);
- }
- mDeleteDialog->setActionEventId("try delete character");
- mDeleteDialog->addActionListener(this);
-}
-
-/**
- * Communicate character selection to the server.
- */
-void CharSelectDialog::attemptCharacterSelect(const int index)
-{
- if (mLocked || (mCharacterEntries[index] == nullptr))
- return;
-
- setVisible(Visible_false);
- if (mCharServerHandler != nullptr)
- {
- mCharServerHandler->chooseCharacter(
- mCharacterEntries[index]->getCharacter());
- }
- lock();
-}
-
-void CharSelectDialog::setCharacters(const Net::Characters &characters)
-{
- // Reset previous characters
- FOR_EACH (STD_VECTOR<CharacterDisplay*>::const_iterator,
- iter, mCharacterEntries)
- {
- if (*iter != nullptr)
- (*iter)->setCharacter(nullptr);
- }
-
- FOR_EACH (Net::Characters::const_iterator, i, characters)
- setCharacter(*i);
- updateState();
-}
-
-void CharSelectDialog::setCharacter(Net::Character *const character)
-{
- if (character == nullptr)
- return;
- const int characterSlot = character->slot;
- if (characterSlot >= CAST_S32(mCharacterEntries.size()))
- {
- logger->log("Warning: slot out of range: %d", character->slot);
- return;
- }
-
- if (mCharacterEntries[characterSlot] != nullptr)
- mCharacterEntries[characterSlot]->setCharacter(character);
-}
-
-void CharSelectDialog::lock()
-{
- if (!mLocked)
- setLocked(true);
-}
-
-void CharSelectDialog::unlock()
-{
- setLocked(false);
-}
-
-void CharSelectDialog::setLocked(const bool locked)
-{
- mLocked = locked;
-
- if (mSwitchLoginButton != nullptr)
- mSwitchLoginButton->setEnabled(!locked);
- if (mChangePasswordButton != nullptr)
- mChangePasswordButton->setEnabled(!locked);
- mPlayButton->setEnabled(!locked);
- if (mDeleteButton != nullptr)
- mDeleteButton->setEnabled(!locked);
-
- for (size_t i = 0, sz = mCharacterEntries.size(); i < sz; ++i)
- {
- if (mCharacterEntries[i] != nullptr)
- mCharacterEntries[i]->setActive(!mLocked);
- }
-}
-
-bool CharSelectDialog::selectByName(const std::string &name,
- const SelectAction selAction)
-{
- if (mLocked)
- return false;
-
- for (size_t i = 0, sz = mCharacterEntries.size(); i < sz; ++i)
- {
- if (mCharacterEntries[i] != nullptr)
- {
- const Net::Character *const character
- = mCharacterEntries[i]->getCharacter();
- if (character != nullptr)
- {
- if (character->dummy != nullptr &&
- character->dummy->getName() == name)
- {
- mCharacterView->show(CAST_S32(i));
- updateState();
- if (selAction == Choose)
- attemptCharacterSelect(CAST_S32(i));
- return true;
- }
- }
- }
- }
-
- return false;
-}
-
-void CharSelectDialog::close()
-{
- client->setState(State::SWITCH_LOGIN);
- Window::close();
-}
-
-void CharSelectDialog::widgetResized(const Event &event)
-{
- Window::widgetResized(event);
- mCharacterView->resize();
-}
-
-void CharSelectDialog::updateState()
-{
- const int idx = mCharacterView->getSelected();
- if (idx == -1)
- {
- mPlayButton->setEnabled(false);
- return;
- }
- mPlayButton->setEnabled(true);
-
- if (mCharacterEntries[idx] != nullptr &&
- mCharacterEntries[idx]->getCharacter() != nullptr)
- {
- // TRANSLATORS: char select dialog. button.
- mPlayButton->setCaption(_("Play"));
-
- const LocalPlayer *const player = mCharacterEntries[
- idx]->getCharacter()->dummy;
- if ((player != nullptr) && (mRenameButton != nullptr))
- mRenameButton->setEnabled(player->getRename() ? true : false);
- }
- else
- {
- // TRANSLATORS: char select dialog. button.
- mPlayButton->setCaption(_("Create"));
- }
-}
-
-void CharSelectDialog::setName(const BeingId id, const std::string &newName)
-{
- for (unsigned int i = 0, fsz = CAST_U32(
- mCharacterEntries.size());
- i < fsz;
- ++i)
- {
- if (mCharacterEntries[i] == nullptr)
- continue;
- CharacterDisplay *const character = mCharacterEntries[i];
- if (character == nullptr)
- continue;
- LocalPlayer *const player = character->getCharacter()->dummy;
- if ((player != nullptr) && player->getId() == id)
- {
- player->setName(newName);
- character->update();
- return;
- }
- }
-}
diff --git a/src/gui/windows/charselectdialog.h b/src/gui/windows/charselectdialog.h
deleted file mode 100644
index 9cf56bfd6..000000000
--- a/src/gui/windows/charselectdialog.h
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_CHARSELECTDIALOG_H
-#define GUI_WINDOWS_CHARSELECTDIALOG_H
-
-#include "enums/simpletypes/beingid.h"
-
-#include "gui/widgets/window.h"
-
-#include "net/characters.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/keylistener.h"
-
-class Button;
-class CharacterDisplay;
-class CharacterViewBase;
-class LoginData;
-class TextDialog;
-
-namespace Net
-{
- class CharServerHandler;
-} // namespace Net
-
-/**
- * Character selection dialog.
- *
- * \ingroup Interface
- */
-class CharSelectDialog final : public Window,
- public ActionListener,
- public KeyListener
-{
- public:
- friend class CharDeleteConfirm;
- friend class Net::CharServerHandler;
-
- /**
- * Constructor.
- */
- explicit CharSelectDialog(LoginData &data);
-
- A_DELETE_COPY(CharSelectDialog)
-
- ~CharSelectDialog();
-
- void action(const ActionEvent &event) override final;
-
- void keyPressed(KeyEvent &event) override final;
-
- enum SelectAction
- {
- Focus = 0,
- Choose
- };
-
- /**
- * Attempt to select the character with the given name. Returns whether
- * a character with the given name was found.
- *
- * \param action determines what to do when a character with the given
- * name was found (just focus or also try to choose this
- * character).
- */
- bool selectByName(const std::string &name,
- const SelectAction action = Focus);
-
- void askPasswordForDeletion(const int index);
-
- void close() override final;
-
- void widgetResized(const Event &event) override final;
-
- void updateState();
-
- void postInit() override final;
-
- void setName(const BeingId id, const std::string &newName);
-
- private:
- void attemptCharacterDelete(const int index,
- const std::string &email);
-
- void attemptCharacterSelect(const int index);
-
- void setCharacters(const Net::Characters &characters);
-
- void setCharacter(Net::Character *const character);
-
- void use(const int selected);
-
- void lock();
- void unlock();
- void setLocked(const bool locked);
-
- LoginData *mLoginData A_NONNULLPOINTER;
-
- Button *mSwitchLoginButton A_NONNULLPOINTER;
- Button *mChangePasswordButton A_NONNULLPOINTER;
- Button *mPlayButton A_NONNULLPOINTER;
- Button *mInfoButton A_NONNULLPOINTER;
- Button *mDeleteButton A_NONNULLPOINTER;
- Button *mRenameButton;
- CharacterViewBase *mCharacterView;
-
- STD_VECTOR<CharacterDisplay*> mCharacterEntries;
-
- Net::CharServerHandler *mCharServerHandler;
- TextDialog *mDeleteDialog;
- int mDeleteIndex;
- bool mLocked;
- bool mSmallScreen;
-};
-
-#endif // GUI_WINDOWS_CHARSELECTDIALOG_H
diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp
deleted file mode 100644
index aa899202d..000000000
--- a/src/gui/windows/chatwindow.cpp
+++ /dev/null
@@ -1,2181 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/chatwindow.h"
-
-#include "actormanager.h"
-#include "game.h"
-#include "guild.h"
-#include "party.h"
-#include "settings.h"
-#include "spellmanager.h"
-
-#include "being/localplayer.h"
-#include "being/playerinfo.h"
-#include "being/playerrelations.h"
-
-#include "const/gui/chat.h"
-
-#include "fs/virtfs/tools.h"
-
-#include "input/inputmanager.h"
-
-#include "gui/focushandler.h"
-#include "gui/gui.h"
-#include "gui/skin.h"
-#include "gui/viewport.h"
-
-#include "gui/models/colorlistmodel.h"
-
-#include "gui/popups/popupmenu.h"
-
-#include "gui/windows/setupwindow.h"
-#include "gui/windows/whoisonline.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/chatinput.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/dropdown.h"
-#include "gui/widgets/itemlinkhandler.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/tabbedarea.h"
-
-#include "gui/widgets/tabs/chat/battletab.h"
-#include "gui/widgets/tabs/chat/channeltab.h"
-#include "gui/widgets/tabs/chat/gmtab.h"
-#include "gui/widgets/tabs/chat/langtab.h"
-#include "gui/widgets/tabs/chat/tradetab.h"
-#include "gui/widgets/tabs/chat/whispertab.h"
-
-#include "render/opengl/opengldebug.h"
-
-#include "resources/db/textdb.h"
-
-#include "net/chathandler.h"
-#include "net/net.h"
-
-#include "utils/copynpaste.h"
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-
-#include "utils/translation/podict.h"
-
-#include <sys/stat.h>
-
-#include <sstream>
-
-#include "debug.h"
-
-ChatWindow *chatWindow = nullptr;
-
-static const char *const ACTION_COLOR_PICKER = "color picker";
-
-ChatWindow::ChatWindow(const std::string &name) :
- // TRANSLATORS: chat window name
- Window(_("Chat"), Modal_false, nullptr, "chat.xml"),
- ActionListener(),
- KeyListener(),
- AttributeListener(),
- mItemLinkHandler(new ItemLinkHandler),
- mChatTabs(CREATEWIDGETR(TabbedArea, this)),
- mChatInput(new ChatInput(this)),
- mRainbowColor(0U),
- mWhispers(),
- mChannels(),
- mHistory(),
- mCurHist(),
- mCommands(),
- mCustomWords(),
- mTradeFilter(),
- mColorListModel(new ColorListModel),
- mColorPicker(new DropDown(this, mColorListModel)),
- mChatButton(new Button(this, ":)", "openemote", this)),
- mAwayLog(),
- mHighlights(),
- mGlobalsFilter(),
- mChatColor(config.getIntValue("chatColor")),
- mEmoteButtonSpacing(mSkin != nullptr ?
- mSkin->getOption("emoteButtonSpacing", 2) : 2),
- mEmoteButtonY(mSkin != nullptr ?
- mSkin->getOption("emoteButtonY", -2) : -2),
- mChatHistoryIndex(0),
- mReturnToggles(config.getBoolValue("ReturnToggles")),
- mGMLoaded(false),
- mHaveMouse(false),
- mAutoHide(config.getBoolValue("autohideChat")),
- mShowBattleEvents(config.getBoolValue("showBattleEvents")),
- mShowAllLang(serverConfig.getValue("showAllLang", 0) != 0),
- mEnableTradeFilter(config.getBoolValue("enableTradeFilter")),
- mTmpVisible(false)
-{
- setWindowName(name);
-
- if (setupWindow != nullptr)
- setupWindow->registerWindowForReset(this);
-
- setShowTitle(false);
- setResizable(true);
- setDefaultVisible(true);
- setSaveVisible(true);
- setStickyButtonLock(true);
-
- int w = 600;
-#ifdef ANDROID
- if (mainGraphics->getWidth() < 710)
- w = mainGraphics->getWidth() - 110;
- if (w < 100)
- w = 100;
- if (mainGraphics->getHeight() < 480)
- setDefaultSize(w, 90, ImagePosition::UPPER_LEFT, -110, -35);
- else
- setDefaultSize(w, 123, ImagePosition::UPPER_LEFT, -110, -35);
-#else // ANDROID
-
- if (mainGraphics->getWidth() < 600)
- w = mainGraphics->getWidth() - 10;
- if (w < 100)
- w = 100;
- setDefaultSize(w, 123, ImagePosition::LOWER_LEFT);
-#endif // ANDROID
-
- setMinWidth(150);
- setMinHeight(90);
-
- setTitleBarHeight(getPadding() + getTitlePadding());
-
- if (emoteWindow != nullptr)
- emoteWindow->addListeners(this);
-
- mChatButton->adjustSize();
-
- mChatTabs->enableScrollButtons(true);
- mChatTabs->setFollowDownScroll(true);
- mChatTabs->setResizeHeight(false);
-
- mChatInput->setActionEventId("chatinput");
- mChatInput->addActionListener(this);
- mChatInput->setAllowSpecialActions(false);
-
- mColorPicker->setActionEventId(ACTION_COLOR_PICKER);
- mColorPicker->addActionListener(this);
- mColorPicker->setSelected(mChatColor);
-
- mItemLinkHandler->setAllowCommands(false);
-
- loadWindowState();
-
- mColorPicker->setPosition(this->getWidth() - mColorPicker->getWidth()
- - 2 * mPadding - 8 - 16, mPadding);
-
- // Add key listener to chat input to be able to respond to up/down
- mChatInput->addKeyListener(this);
- mCurHist = mHistory.end();
- mColorPicker->setVisible(fromBool(config.getBoolValue(
- "showChatColorsList"), Visible));
- updateTabsMargin();
-
- fillCommands();
- if ((localPlayer != nullptr) && localPlayer->isGM())
- loadGMCommands();
- initTradeFilter();
- loadCustomList();
- parseHighlights();
- parseGlobalsFilter();
-
- config.addListener("autohideChat", this);
- config.addListener("showBattleEvents", this);
- config.addListener("globalsFilter", this);
- config.addListener("enableTradeFilter", this);
-
- enableVisibleSound(true);
-}
-
-ChatWindow::~ChatWindow()
-{
- config.removeListeners(this);
- CHECKLISTENERS
- saveState();
- config.setValue("ReturnToggles", mReturnToggles);
- removeAllWhispers();
- removeAllChannels();
- delete2(mItemLinkHandler);
- delete2(mColorPicker);
- delete2(mColorListModel);
-}
-
-void ChatWindow::postInit()
-{
- Window::postInit();
- add(mChatTabs);
- add(mChatInput);
- add(mColorPicker);
- add(mChatButton);
- updateVisibility();
-}
-
-void ChatWindow::loadCommandsFile(const std::string &name)
-{
- StringVect list;
- VirtFs::loadTextFile(name, list);
- StringVectCIter it = list.begin();
- const StringVectCIter it_end = list.end();
-
- while (it != it_end)
- {
- const std::string str = *it;
- if (!str.empty())
- mCommands.push_back(str);
- ++ it;
- }
-}
-
-void ChatWindow::fillCommands()
-{
- loadCommandsFile("chatcommands.txt");
- inputManager.addChatCommands(mCommands);
-}
-
-void ChatWindow::loadGMCommands()
-{
- if (mGMLoaded)
- return;
-
- loadCommandsFile("gmcommands.txt");
- mGMLoaded = true;
-}
-
-void ChatWindow::updateTabsMargin()
-{
- if (mColorPicker->mVisible == Visible_true)
- mChatTabs->setRightMargin(mColorPicker->getWidth() + 16 + 8);
- else
- mChatTabs->setRightMargin(8);
-}
-
-void ChatWindow::adjustTabSize()
-{
- const Rect area = getChildrenArea();
-
- const int aw = area.width;
- const int ah = area.height;
- const int frame = mChatInput->getFrameSize();
- const int inputHeight = mChatInput->getHeight();
- const bool showEmotes = config.getBoolValue("showEmotesButton");
- int maxHeight = inputHeight;
- if (showEmotes)
- {
- const int buttonHeight = mChatButton->getHeight();
- if (buttonHeight > maxHeight)
- maxHeight = buttonHeight;
- }
- const int frame2 = 2 * frame;
- const int awFrame2 = aw - frame2;
- int y = ah - maxHeight - frame;
- mChatInput->setPosition(frame, y);
- mChatTabs->setWidth(awFrame2);
- const int height = ah - frame2 - (maxHeight + frame2);
- if (mChatInput->mVisible == Visible_true ||
- !config.getBoolValue("hideChatInput"))
- {
- mChatTabs->setHeight(height);
- }
- else
- {
- mChatTabs->setHeight(height + maxHeight);
- }
- updateTabsMargin();
-
- if (showEmotes)
- {
- const int chatButtonSize = mChatButton->getWidth();
- int w = awFrame2 - chatButtonSize;
- const int x = aw - frame - chatButtonSize;
- w -= mEmoteButtonSpacing;
- y += mEmoteButtonY;
- mChatInput->setWidth(w);
- mChatButton->setVisible(mChatInput->mVisible);
- mChatButton->setPosition(x, y);
- }
- else
- {
- mChatInput->setWidth(awFrame2);
- mChatButton->setVisible(Visible_false);
- }
-
- const ChatTab *const tab = getFocused();
- if (tab != nullptr)
- {
- Widget *const content = tab->mScrollArea;
- if (content != nullptr)
- {
- const int contentFrame2 = 2 * content->getFrameSize();
- content->setSize(mChatTabs->getWidth() - contentFrame2,
- mChatTabs->getContainerHeight() - contentFrame2);
- content->logic();
- }
- }
-
- mColorPicker->setPosition(this->getWidth() - mColorPicker->getWidth()
- - 2 * mPadding - 8 - 16, mPadding);
-
- mChatTabs->adjustSize();
-}
-
-void ChatWindow::widgetResized(const Event &event)
-{
- Window::widgetResized(event);
-
- adjustTabSize();
-}
-
-ChatTab *ChatWindow::getFocused() const
-{
- return static_cast<ChatTab*>(mChatTabs->getSelectedTab());
-}
-
-void ChatWindow::clearTab(ChatTab *const tab)
-{
- if (tab != nullptr)
- tab->clearText();
-}
-
-void ChatWindow::clearTab() const
-{
- clearTab(getFocused());
-}
-
-void ChatWindow::prevTab()
-{
- if (mChatTabs == nullptr)
- return;
-
- int tab = mChatTabs->getSelectedTabIndex();
-
- if (tab <= 0)
- tab = mChatTabs->getNumberOfTabs();
- tab--;
-
- mChatTabs->setSelectedTabByIndex(tab);
-}
-
-void ChatWindow::nextTab()
-{
- if (mChatTabs == nullptr)
- return;
-
- int tab = mChatTabs->getSelectedTabIndex();
-
- tab++;
- if (tab == mChatTabs->getNumberOfTabs())
- tab = 0;
-
- mChatTabs->setSelectedTabByIndex(tab);
-}
-
-void ChatWindow::selectTabByType(const ChatTabTypeT &type)
-{
- if (mChatTabs == nullptr)
- return;
-
- int sz = mChatTabs->getNumberOfTabs();
- for (int f = 0; f < sz; f ++)
- {
- ChatTab *const tab = dynamic_cast<ChatTab*>(
- mChatTabs->getTabByIndex(f));
- if ((tab != nullptr) && tab->getType() == type)
- {
- mChatTabs->setSelectedTab(tab);
- break;
- }
- }
-}
-
-void ChatWindow::closeTab() const
-{
- if (mChatTabs == nullptr)
- return;
-
- ChatTab *const tab = dynamic_cast<ChatTab*>(mChatTabs->getTabByIndex(
- mChatTabs->getSelectedTabIndex()));
- if (tab == nullptr)
- return;
- const ChatTabTypeT &type = tab->getType();
- if (type == ChatTabType::WHISPER || type == ChatTabType::CHANNEL)
- tab->handleCommand("close", "");
-}
-
-void ChatWindow::defaultTab()
-{
- if (mChatTabs != nullptr)
- mChatTabs->setSelectedTabByIndex(CAST_U32(0));
-}
-
-void ChatWindow::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "chatinput")
- {
- std::string message = mChatInput->getText();
-
- if (!message.empty())
- {
- // If message different from previous, put it in the history
- if (mHistory.empty() || message != mHistory.back())
- mHistory.push_back(message);
-
- // Reset history iterator
- mCurHist = mHistory.end();
-
- // Send the message to the server
- chatInput(addColors(message));
-
- // Clear the text from the chat input
- mChatInput->setText("");
- }
-
- if (message.empty() || !mReturnToggles)
- {
- // Remove focus and hide input
- mChatInput->unprotectFocus();
- if (mFocusHandler != nullptr)
- mFocusHandler->focusNone();
-
- // If the chatWindow is shown up because you want to send a message
- // It should hide now
- if (mTmpVisible)
- setVisible(Visible_false);
- }
- }
- else if (eventId == "emote")
- {
- if (emoteWindow != nullptr)
- {
- const std::string str = emoteWindow->getSelectedEmote();
- if (!str.empty())
- {
- addInputText(str, false);
- emoteWindow->clearEmote();
- }
- }
- }
- else if (eventId == "openemote")
- {
- if (emoteWindow != nullptr)
- {
- if (emoteWindow->mVisible == Visible_true)
- emoteWindow->hide();
- else
- emoteWindow->show();
- }
- }
- else if (eventId == "color")
- {
- if (emoteWindow != nullptr)
- {
- const std::string str = emoteWindow->getSelectedColor();
- if (!str.empty())
- {
- addInputText(str, false);
- emoteWindow->clearColor();
- }
- }
- }
- else if (eventId == "font")
- {
- if (emoteWindow != nullptr)
- {
- const std::string str = emoteWindow->getSelectedFont();
- if (!str.empty())
- {
- addInputText(str, false);
- emoteWindow->clearFont();
- }
- }
- }
- else if (eventId == "text")
- {
- if ((emoteWindow != nullptr) && (reverseDictionary != nullptr))
- {
- const int idx = emoteWindow->getSelectedTextIndex();
- if (idx >= 0)
- {
- const std::string str = TextDb::getByIndex(idx);
- const std::string enStr = reverseDictionary->getStr(str);
- addInputText(enStr, false);
- }
- emoteWindow->clearText();
- }
- }
- else if (eventId == ACTION_COLOR_PICKER)
- {
- if (mColorPicker != nullptr)
- {
- mChatColor = mColorPicker->getSelected();
- config.setValue("chatColor", mChatColor);
- }
- }
-
- if (mColorPicker != nullptr)
- {
- const Visible vis = fromBool(config.getBoolValue(
- "showChatColorsList"), Visible);
- if (mColorPicker->mVisible != vis)
- mColorPicker->setVisible(vis);
- }
-}
-
-bool ChatWindow::requestChatFocus()
-{
- // Make sure chatWindow is visible
- if (!isWindowVisible())
- {
- setVisible(Visible_true);
-
- /*
- * This is used to hide chatWindow after sending the message. There is
- * a trick here, because setVisible will set mTmpVisible to false, you
- * have to put this sentence *after* setVisible, not before it
- */
- mTmpVisible = true;
- }
-
- // Don't do anything else if the input is already visible and has focus
- if (mChatInput->isVisible() && mChatInput->isFocused())
- return false;
-
- // Give focus to the chat input
- mChatInput->processVisible(Visible_true);
- unHideWindow();
- mChatInput->requestFocus();
- return true;
-}
-
-bool ChatWindow::isInputFocused() const
-{
- return mChatInput->isFocused();
-}
-
-void ChatWindow::removeTab(ChatTab *const tab)
-{
- mChatTabs->removeTab(tab);
-}
-
-void ChatWindow::addTab(ChatTab *const tab)
-{
- if (tab == nullptr)
- return;
-
- mChatTabs->addTab(tab, tab->mScrollArea);
- logic();
-}
-
-void ChatWindow::removeWhisper(const std::string &nick)
-{
- std::string tempNick = nick;
- toLower(tempNick);
- mWhispers.erase(tempNick);
-}
-
-void ChatWindow::removeChannel(const std::string &name)
-{
- std::string tempName = name;
- toLower(tempName);
- mChannels.erase(tempName);
- chatHandler->partChannel(name);
-}
-
-void ChatWindow::removeAllWhispers()
-{
- std::list<ChatTab*> tabs;
-
- FOR_EACH (TabMap::iterator, iter, mWhispers)
- tabs.push_back(iter->second);
-
- for (std::list<ChatTab*>::iterator it = tabs.begin();
- it != tabs.end(); ++it)
- {
- delete *it;
- }
-
- mWhispers.clear();
-}
-
-void ChatWindow::removeAllChannels()
-{
- std::list<ChatTab*> tabs;
-
- FOR_EACH (ChannelMap::iterator, iter, mChannels)
- tabs.push_back(iter->second);
-
- for (std::list<ChatTab*>::iterator it = tabs.begin();
- it != tabs.end(); ++it)
- {
- delete *it;
- }
-
- mChannels.clear();
-}
-
-void ChatWindow::ignoreAllWhispers()
-{
- for (TabMap::iterator iter = mWhispers.begin();
- iter != mWhispers.end();
- ++ iter)
- {
- WhisperTab *const tab = iter->second;
- if (tab != nullptr)
- {
- if (playerRelations.getRelation(tab->getNick())
- != Relation::IGNORED)
- {
- playerRelations.setRelation(tab->getNick(),
- Relation::IGNORED);
- }
- tab->handleCommand("close", "");
- }
- }
-}
-
-void ChatWindow::chatInput(const std::string &message) const
-{
- ChatTab *tab = nullptr;
- std::string msg = message;
- trim(msg);
-
- if (config.getBoolValue("allowCommandsInChatTabs")
- && msg.length() > 1
- && ((msg.at(0) == '#' && msg.at(1) != '#') || msg.at(0) == '@')
- && (localChatTab != nullptr))
- {
- tab = localChatTab;
- }
- else
- {
- tab = getFocused();
- if (tab == nullptr)
- tab = localChatTab;
- }
- if (tab != nullptr)
- tab->chatInput(msg);
- Game *const game = Game::instance();
- if (game != nullptr)
- game->setValidSpeed();
-}
-
-void ChatWindow::localChatInput(const std::string &msg) const
-{
- if (localChatTab != nullptr)
- localChatTab->chatInput(msg);
- else
- chatInput(msg);
-}
-
-void ChatWindow::doPresent() const
-{
- if (actorManager == nullptr)
- return;
-
- const ActorSprites &actors = actorManager->getAll();
- std::string response;
- int playercount = 0;
-
- FOR_EACH (ActorSpritesIterator, it, actors)
- {
- if ((*it)->getType() == ActorType::Player)
- {
- if (!response.empty())
- response.append(", ");
- response.append(static_cast<Being*>(*it)->getName());
- playercount ++;
- }
- }
-
- ChatTab *const tab = getFocused();
- if (tab != nullptr)
- {
- const std::string log = strprintf(
- // TRANSLATORS: chat message
- _("Present: %s; %d players are present."),
- response.c_str(), playercount);
- tab->chatLog(log, ChatMsgType::BY_SERVER);
- }
-}
-
-void ChatWindow::scroll(const int amount) const
-{
- if (!isWindowVisible())
- return;
-
- ChatTab *const tab = getFocused();
- if (tab != nullptr)
- tab->scroll(amount);
-}
-
-void ChatWindow::mousePressed(MouseEvent &event)
-{
- if (event.isConsumed())
- return;
-
- if (event.getButton() == MouseButton::RIGHT)
- {
- if (popupMenu != nullptr)
- {
- ChatTab *const cTab = dynamic_cast<ChatTab*>(
- mChatTabs->getSelectedTab());
- if (cTab != nullptr)
- {
- event.consume();
- if (inputManager.isActionActive(InputAction::CHAT_MOD))
- {
- inputManager.executeChatCommand(
- InputAction::CLOSE_CHAT_TAB,
- std::string(), cTab);
- }
- else
- {
- popupMenu->showChatPopup(viewport->mMouseX,
- viewport->mMouseY,
- cTab);
- }
- }
- }
- }
-
- Window::mousePressed(event);
-
- if (event.isConsumed())
- return;
-
- if (event.getButton() == MouseButton::LEFT)
- {
- const int clicks = event.getClickCount();
- if (clicks == 2)
- {
- toggleChatFocus();
- if (gui != nullptr)
- gui->resetClickCount();
- }
- else if (clicks == 1)
- {
- const ChatTab *const tab = getFocused();
- if (tab != nullptr)
- mMoved = !isResizeAllowed(event);
- }
- }
-
- mDragOffsetX = event.getX();
- mDragOffsetY = event.getY();
-}
-
-void ChatWindow::mouseDragged(MouseEvent &event)
-{
- Window::mouseDragged(event);
-
- if (event.isConsumed())
- return;
-
- if (canMove() && isMovable() && mMoved)
- {
- int newX = std::max(0, getX() + event.getX() - mDragOffsetX);
- int newY = std::max(0, getY() + event.getY() - mDragOffsetY);
- newX = std::min(mainGraphics->mWidth - getWidth(), newX);
- newY = std::min(mainGraphics->mHeight - getHeight(), newY);
- setPosition(newX, newY);
- }
-}
-
-#define ifKey(key, str) \
- else if (actionId == key) \
- { \
- temp = str; \
- }
-
-void ChatWindow::keyPressed(KeyEvent &event)
-{
- const InputActionT actionId = event.getActionId();
- std::string temp;
- if (actionId == InputAction::GUI_DOWN)
- {
- if (mCurHist != mHistory.end())
- {
- // Move forward through the history
- const HistoryIterator prevHist = mCurHist++;
- addCurrentToHistory();
-
- if (mCurHist != mHistory.end())
- {
- mChatInput->setText(*mCurHist);
- mChatInput->setCaretPosition(CAST_U32(
- mChatInput->getText().length()));
- }
- else
- {
- mChatInput->setText("");
- mCurHist = prevHist;
- }
- }
- else if (!mChatInput->getText().empty())
- {
- if (addCurrentToHistory())
- mCurHist = mHistory.end();
- mChatInput->setText("");
- }
- }
- else if (actionId == InputAction::GUI_UP &&
- mCurHist != mHistory.begin() &&
- !mHistory.empty())
- {
- // Move backward through the history
- --mCurHist;
- addCurrentToHistory();
- mChatInput->setText(*mCurHist);
- mChatInput->setCaretPosition(CAST_U32(
- mChatInput->getText().length()));
- }
- else if (actionId == InputAction::GUI_INSERT &&
- !mChatInput->getText().empty())
- {
- const std::string str = mChatInput->getText();
- // Add the current message to the history and clear the text
- if (mHistory.empty() || str != mHistory.back())
- mHistory.push_back(str);
- mCurHist = mHistory.end();
- mChatInput->setText(std::string());
- }
- else if (actionId == InputAction::GUI_TAB &&
- !mChatInput->getText().empty())
- {
- autoComplete();
- return;
- }
- else if (actionId == InputAction::GUI_CANCEL &&
- mChatInput->mVisible == Visible_true)
- {
- mChatInput->processVisible(Visible_false);
- }
- else if (actionId == InputAction::CHAT_PREV_HISTORY &&
- mChatInput->mVisible == Visible_true)
- {
- const ChatTab *const tab = getFocused();
- if ((tab != nullptr) && tab->hasRows())
- {
- if (mChatHistoryIndex == 0u)
- {
- mChatHistoryIndex = CAST_U32(
- tab->getRows().size());
-
- mChatInput->setText("");
- mChatInput->setCaretPosition(0);
- return;
- }
-
- mChatHistoryIndex --;
-
- unsigned int f = 0;
- const std::list<std::string> &rows = tab->getRows();
- for (std::list<std::string>::const_iterator it = rows.begin(),
- it_end = rows.end(); it != it_end; ++ it, f ++)
- {
- if (f == mChatHistoryIndex)
- mChatInput->setText(*it);
- }
- mChatInput->setCaretPosition(CAST_U32(
- mChatInput->getText().length()));
- }
- }
- else if (actionId == InputAction::CHAT_NEXT_HISTORY &&
- mChatInput->mVisible == Visible_true)
- {
- const ChatTab *const tab = getFocused();
- if ((tab != nullptr) && tab->hasRows())
- {
- const std::list<std::string> &rows = tab->getRows();
- const size_t &tabSize = rows.size();
- if (CAST_SIZE(mChatHistoryIndex) + 1 < tabSize)
- {
- mChatHistoryIndex ++;
- }
- else if (CAST_SIZE(mChatHistoryIndex) < tabSize)
- {
- mChatHistoryIndex ++;
- mChatInput->setText("");
- mChatInput->setCaretPosition(0);
- return;
- }
- else
- {
- mChatHistoryIndex = 0;
- }
-
- unsigned int f = 0;
- for (std::list<std::string>::const_iterator
- it = rows.begin(), it_end = rows.end();
- it != it_end; ++it, f++)
- {
- if (f == mChatHistoryIndex)
- mChatInput->setText(*it);
- }
- mChatInput->setCaretPosition(CAST_U32(
- mChatInput->getText().length()));
- }
- }
- else if (actionId == InputAction::GUI_F1)
- {
- if (emoteWindow != nullptr)
- {
- if (emoteWindow->mVisible == Visible_true)
- emoteWindow->hide();
- else
- emoteWindow->show();
- }
- }
- ifKey(InputAction::GUI_F2, "\u2318")
- ifKey(InputAction::GUI_F3, "\u263A")
- ifKey(InputAction::GUI_F4, "\u2665")
- ifKey(InputAction::GUI_F5, "\u266A")
- ifKey(InputAction::GUI_F6, "\u266B")
- ifKey(InputAction::GUI_F7, "\u26A0")
- ifKey(InputAction::GUI_F8, "\u2622")
- ifKey(InputAction::GUI_F9, "\u262E")
- ifKey(InputAction::GUI_F10, "\u2605")
- ifKey(InputAction::GUI_F11, "\u2618")
- ifKey(InputAction::GUI_F12, "\u2592")
-
- if (inputManager.isActionActive(InputAction::GUI_CTRL))
- {
- if (actionId == InputAction::GUI_B)
- {
- std::string inputText = mChatInput->getTextBeforeCaret();
- toLower(inputText);
- const size_t idx = inputText.rfind("##b");
- if (idx == std::string::npos
- || mChatInput->getTextBeforeCaret().substr(idx, 3) == "##b")
- {
- temp = "##B";
- }
- else
- {
- temp = "##b";
- }
- }
- }
-
- if (!temp.empty())
- addInputText(temp, false);
-}
-
-#undef ifKey
-
-bool ChatWindow::addCurrentToHistory()
-{
- const std::string &str = mChatInput->getText();
- if (str.empty())
- return false;
- FOR_EACH (HistoryIterator, it, mHistory)
- {
- if (*it == str)
- return false;
- }
- mHistory.push_back(str);
- return true;
-}
-
-void ChatWindow::attributeChanged(const AttributesT id,
- const int64_t oldVal,
- const int64_t newVal)
-{
- if (!mShowBattleEvents)
- return;
- PRAGMA45(GCC diagnostic push)
- PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
- switch (id)
- {
- case Attributes::PLAYER_EXP:
- {
- if (oldVal > newVal)
- break;
- const int64_t change = newVal - oldVal;
- if (change != 0)
- {
- battleChatLog(std::string("+").append(toString(
- CAST_U64(change))).append(" xp"),
- ChatMsgType::BY_SERVER);
- }
- break;
- }
- case Attributes::PLAYER_BASE_LEVEL:
- battleChatLog(std::string(
- "Level: ").append(toString(CAST_S32(
- newVal))),
- ChatMsgType::BY_SERVER);
- break;
- case Attributes::PLAYER_JOB_EXP:
- {
- if (!config.getBoolValue("showJobExp"))
- return;
- if (oldVal > newVal ||
- PlayerInfo::getAttribute(
- Attributes::PLAYER_JOB_EXP_NEEDED) == 0)
- {
- return;
- }
- const int64_t change = newVal - oldVal;
- if (change != 0)
- {
- battleChatLog(std::string("+").append(toString(CAST_U64(
- change))).append(" job"),
- ChatMsgType::BY_SERVER);
- }
- break;
- }
- default:
- break;
- };
- PRAGMA45(GCC diagnostic pop)
-}
-
-void ChatWindow::addInputText(const std::string &text, const bool space)
-{
- const int caretPos = mChatInput->getCaretPosition();
- const std::string &inputText = mChatInput->getText();
-
- std::ostringstream ss;
- ss << inputText.substr(0, caretPos) << text;
- if (space)
- ss << " ";
-
- ss << inputText.substr(caretPos);
- mChatInput->setText(ss.str());
- mChatInput->setCaretPosition(caretPos + CAST_S32(
- text.length()) + CAST_S32(space));
- requestChatFocus();
-}
-
-void ChatWindow::addItemText(const std::string &item)
-{
- std::ostringstream text;
- text << "[" << item << "]";
- addInputText(text.str());
-}
-
-void ChatWindow::setVisible(Visible visible)
-{
- Window::setVisible(visible);
-
- /*
- * For whatever reason, if setVisible is called, the mTmpVisible effect
- * should be disabled.
- */
- mTmpVisible = false;
-}
-
-void ChatWindow::addWhisper(const std::string &restrict nick,
- const std::string &restrict mes,
- const ChatMsgTypeT own)
-{
- if (mes.empty() || (localPlayer == nullptr))
- return;
-
- std::string playerName = localPlayer->getName();
- std::string tempNick = nick;
-
- toLower(playerName);
- toLower(tempNick);
-
- if (tempNick == playerName)
- return;
-
- WhisperTab *tab = nullptr;
- const TabMap::const_iterator i = mWhispers.find(tempNick);
-
- if (i != mWhispers.end())
- {
- tab = i->second;
- }
- else if (config.getBoolValue("whispertab"))
- {
- tab = addWhisperTab(nick, nick);
- if (tab != nullptr)
- saveState();
- }
-
- if (tab != nullptr)
- {
- if (own == ChatMsgType::BY_PLAYER)
- {
- tab->chatInput(mes);
- }
- else if (own == ChatMsgType::BY_SERVER)
- {
- tab->chatLog(mes, ChatMsgType::BY_SERVER);
- }
- else
- {
- if (tab->getRemoveNames())
- {
- std::string msg = mes;
- const size_t idx = mes.find(':');
- if (idx != std::string::npos && idx > 0)
- {
- std::string nick2 = msg.substr(0, idx);
- msg = msg.substr(idx + 1);
- nick2 = removeColors(nick2);
- nick2 = trim(nick2);
- if (config.getBoolValue("removeColors"))
- msg = removeColors(msg);
- msg = trim(msg);
- tab->chatLog(nick2, msg);
- }
- else
- {
- if (config.getBoolValue("removeColors"))
- msg = removeColors(msg);
- tab->chatLog(msg, ChatMsgType::BY_SERVER);
- }
- }
- else
- {
- tab->chatLog(nick, mes);
- }
- localPlayer->afkRespond(tab, nick);
- }
- }
- else if (localChatTab != nullptr)
- {
- if (own == ChatMsgType::BY_PLAYER)
- {
- chatHandler->privateMessage(nick, mes);
-
- // TRANSLATORS: chat message
- localChatTab->chatLog(strprintf(_("Whispering to %s: %s"),
- nick.c_str(), mes.c_str()),
- ChatMsgType::BY_PLAYER);
- }
- else
- {
- localChatTab->chatLog(std::string(nick).append(
- " : ").append(mes),
- ChatMsgType::ACT_WHISPER,
- IgnoreRecord_false);
- if (localPlayer != nullptr)
- localPlayer->afkRespond(nullptr, nick);
- }
- }
-}
-
-WhisperTab *ChatWindow::addWhisperTab(const std::string &caption,
- const std::string &nick,
- const bool switchTo)
-{
- if (localPlayer == nullptr)
- return nullptr;
-
- std::string playerName = localPlayer->getName();
- std::string tempNick = nick;
-
- toLower(playerName);
- toLower(tempNick);
-
- const TabMap::const_iterator i = mWhispers.find(tempNick);
- WhisperTab *ret = nullptr;
-
- if (tempNick == playerName)
- return nullptr;
-
- if (i != mWhispers.end())
- {
- ret = i->second;
- }
- else
- {
- ret = new WhisperTab(this, caption, nick);
- if ((gui != nullptr) && !playerRelations.isGoodName(nick))
- ret->setLabelFont(gui->getSecureFont());
- mWhispers[tempNick] = ret;
- if (config.getBoolValue("showChatHistory"))
- ret->loadFromLogFile(nick);
- }
-
- if (switchTo)
- mChatTabs->setSelectedTab(ret);
-
- return ret;
-}
-
-WhisperTab *ChatWindow::getWhisperTab(const std::string &nick) const
-{
- if (localPlayer == nullptr)
- return nullptr;
-
- std::string playerName = localPlayer->getName();
- std::string tempNick = nick;
-
- toLower(playerName);
- toLower(tempNick);
-
- const TabMap::const_iterator i = mWhispers.find(tempNick);
- WhisperTab *ret = nullptr;
-
- if (tempNick == playerName)
- return nullptr;
-
- if (i != mWhispers.end())
- ret = i->second;
-
- return ret;
-}
-
-ChatTab *ChatWindow::addSpecialChannelTab(const std::string &name,
- const bool switchTo)
-{
- ChatTab *ret = nullptr;
- if (name == TRADE_CHANNEL)
- {
- if (tradeChatTab == nullptr)
- {
- tradeChatTab = new TradeTab(chatWindow);
- tradeChatTab->setAllowHighlight(false);
- chatHandler->joinChannel(tradeChatTab->getChannelName());
- }
- ret = tradeChatTab;
- }
- else if (name == GM_CHANNEL)
- {
- if (gmChatTab == nullptr)
- {
- gmChatTab = new GmTab(chatWindow);
- chatHandler->joinChannel(gmChatTab->getChannelName());
- }
- ret = gmChatTab;
- }
- if (switchTo)
- mChatTabs->setSelectedTab(ret);
-
- return ret;
-}
-
-ChatTab *ChatWindow::addChannelTab(const std::string &name,
- const bool switchTo)
-{
- std::string tempName = name;
- toLower(tempName);
-
- ChatTab *const tab = addSpecialChannelTab(name, switchTo);
- if (tab != nullptr)
- return tab;
-
- const ChannelMap::const_iterator i = mChannels.find(tempName);
- ChannelTab *ret = nullptr;
-
- if (i != mChannels.end())
- {
- ret = i->second;
- }
- else
- {
- ret = new ChannelTab(this, name);
- mChannels[tempName] = ret;
- ret->setAllowHighlight(false);
- if (config.getBoolValue("showChatHistory"))
- ret->loadFromLogFile(name);
- }
-
- if (switchTo)
- mChatTabs->setSelectedTab(ret);
-
- return ret;
-}
-
-ChatTab *ChatWindow::addChatTab(const std::string &name,
- const bool switchTo,
- const bool join)
-{
- if (Net::getNetworkType() != ServerType::TMWATHENA &&
- name.size() > 1 &&
- name[0] == '#')
- {
- ChatTab *const tab = addChannelTab(name, switchTo);
- if ((tab != nullptr) && join)
- chatHandler->joinChannel(name);
- return tab;
- }
- return addWhisperTab(name, name, switchTo);
-}
-
-void ChatWindow::postConnection()
-{
- FOR_EACH (ChannelMap::const_iterator, iter, mChannels)
- {
- ChatTab *const tab = iter->second;
- if (tab == nullptr)
- return;
- chatHandler->joinChannel(tab->getChannelName());
- }
- if (langChatTab != nullptr)
- chatHandler->joinChannel(langChatTab->getChannelName());
-}
-
-#define changeColor(fun) \
- { \
- msg = removeColors(msg); \
- int skip = 0; \
- const size_t sz = msg.length(); \
- for (size_t f = 0; f < sz; f ++) \
- { \
- if (skip > 0) \
- { \
- newMsg += msg.at(f); \
- skip --; \
- continue; \
- } \
- const unsigned char ch = CAST_U8(msg.at(f)); \
- if (f + 2 < sz && msg.substr(f, 2) == "%%") \
- { \
- newMsg += msg.at(f); \
- skip = 2; \
- } \
- else if (ch > 0xc0 || ch < 0x80) \
- { \
- newMsg += "##" + toString(fun) + msg.at(f); \
- if (mRainbowColor > 9U) \
- mRainbowColor = 0U; \
- } \
- else \
- { \
- newMsg += msg.at(f); \
- } \
- } \
- }
-
-std::string ChatWindow::addColors(std::string &msg)
-{
- // default color or chat command
- if (mChatColor == 0 || msg.length() == 0 || msg.at(0) == '#'
- || msg.at(0) == '/' || msg.at(0) == '@' || msg.at(0) == '!')
- {
- return msg;
- }
-
- std::string newMsg;
- const int cMap[] = {1, 4, 5, 2, 3, 6, 7, 9, 0, 8};
-
- // rainbow
- switch (mChatColor)
- {
- case 11:
- changeColor(mRainbowColor++)
- return newMsg;
- case 12:
- changeColor(cMap[mRainbowColor++])
- return newMsg;
- case 13:
- changeColor(cMap[9-mRainbowColor++])
- return newMsg;
- default:
- break;
- }
-
- // simple colors
- return std::string("##").append(toString(mChatColor - 1)).append(msg);
-}
-
-#undef changeColor
-
-void ChatWindow::autoComplete()
-{
- const int caretPos = mChatInput->getCaretPosition();
- int startName = 0;
- const std::string &inputText = mChatInput->getText();
- std::string name = inputText.substr(0, caretPos);
-
- for (int f = caretPos - 1; f > -1; f --)
- {
- if (isWordSeparator(inputText[f]))
- {
- startName = f + 1;
- name = inputText.substr(f + 1, caretPos - f);
- break;
- }
- }
-
- if (caretPos - 1 + 1 == startName)
- return;
-
- const ChatTab *const cTab = static_cast<ChatTab*>(
- mChatTabs->getSelectedTab());
- StringVect nameList;
-
- if (cTab != nullptr)
- cTab->getAutoCompleteList(nameList);
- std::string newName = autoComplete(nameList, name);
- if (!newName.empty() && (startName == 0))
- secureChatCommand(newName);
-
- if ((cTab != nullptr) && newName.empty())
- {
- cTab->getAutoCompleteCommands(nameList);
- newName = autoComplete(nameList, name);
- }
-
- if (newName.empty() && (actorManager != nullptr))
- {
- actorManager->getPlayerNames(nameList, NpcNames_true);
- newName = autoComplete(nameList, name);
- if (!newName.empty() && (startName == 0))
- secureChatCommand(newName);
- }
- if (newName.empty())
- newName = autoCompleteHistory(name);
- if (newName.empty() && (spellManager != nullptr))
- newName = spellManager->autoComplete(name);
- if (newName.empty())
- newName = autoComplete(name, &mCommands);
- if (newName.empty() && (actorManager != nullptr))
- {
- actorManager->getMobNames(nameList);
- newName = autoComplete(nameList, name);
- }
- if (newName.empty())
- newName = autoComplete(name, &mCustomWords);
- if (newName.empty())
- {
- whoIsOnline->getPlayerNames(nameList);
- newName = autoComplete(nameList, name);
- }
-
- if (!newName.empty())
- {
- mChatInput->setText(inputText.substr(0, startName).append(newName)
- .append(inputText.substr(caretPos,
- inputText.length() - caretPos)));
-
- const int len = caretPos - CAST_S32(name.length())
- + CAST_S32(newName.length());
-
- if (startName > 0)
- mChatInput->setCaretPosition(len + 1);
- else
- mChatInput->setCaretPosition(len);
- }
-}
-
-std::string ChatWindow::autoComplete(const StringVect &names,
- std::string partName)
-{
- StringVectCIter i = names.begin();
- const StringVectCIter i_end = names.end();
- toLower(partName);
- std::string newName;
-
- while (i != i_end)
- {
- if (!i->empty())
- {
- std::string name = *i;
- toLower(name);
-
- const size_t pos = name.find(partName, 0);
- if (pos == 0)
- {
- if (!newName.empty())
- newName = findSameSubstringI(*i, newName);
- else
- newName = *i;
- }
- }
- ++i;
- }
-
- return newName;
-}
-
-std::string ChatWindow::autoComplete(const std::string &partName,
- const History *const words) const
-{
- if (words == nullptr)
- return "";
-
- ChatCommands::const_iterator i = words->begin();
- const ChatCommands::const_iterator i_end = words->end();
- StringVect nameList;
-
- while (i != i_end)
- {
- const std::string line = *i;
- if (line.find(partName, 0) == 0)
- nameList.push_back(line);
- ++i;
- }
- return autoComplete(nameList, partName);
-}
-
-/*
-void ChatWindow::moveTabLeft(ChatTab *tab)
-{
- mChatTabs->moveLeft(tab);
-}
-
-void ChatWindow::moveTabRight(ChatTab *tab)
-{
- mChatTabs->moveRight(tab);
-}
-*/
-
-std::string ChatWindow::autoCompleteHistory(const std::string &partName) const
-{
- History::const_iterator i = mHistory.begin();
- const History::const_iterator i_end = mHistory.end();
- StringVect nameList;
-
- while (i != i_end)
- {
- std::string line = *i;
- unsigned int f = 0;
- while (f < line.length() && !isWordSeparator(line.at(f)))
- f++;
-
- line = line.substr(0, f);
- if (!line.empty())
- nameList.push_back(line);
-
- ++i;
- }
- return autoComplete(nameList, partName);
-}
-
-bool ChatWindow::resortChatLog(std::string line,
- ChatMsgTypeT own,
- const std::string &channel,
- const IgnoreRecord ignoreRecord,
- const TryRemoveColors tryRemoveColors)
-{
- if (own == ChatMsgType::BY_UNKNOWN)
- {
- const size_t pos = line.find(" : ");
- if (pos != std::string::npos)
- {
- if (line.length() <= pos + 3)
- own = ChatMsgType::BY_SERVER;
- else if (line.substr(0, pos) == localPlayer->getName())
- own = ChatMsgType::BY_PLAYER;
- else
- own = ChatMsgType::BY_OTHER;
- }
- else
- {
- own = ChatMsgType::BY_SERVER;
- }
- }
-
- std::string prefix;
- if (!channel.empty())
- {
- prefix = std::string("##3").append(channel).append("##0");
- }
- else if (mEnableTradeFilter &&
- (tradeChatTab != nullptr) &&
- findI(line, mTradeFilter) != std::string::npos)
- {
- // TRANSLATORS: prefix for moved message to trade tab.
- tradeChatTab->chatLog(std::string("##S") + _("Moved: ") + line,
- own,
- ignoreRecord,
- tryRemoveColors);
- if (own == ChatMsgType::BY_PLAYER)
- {
- own = ChatMsgType::BY_SERVER;
- // TRANSLATORS: moved message to trade tab warning.
- line = _("Your message was moved to trade tab");
- }
- else
- {
- return false;
- }
- }
-
- size_t idx2 = line.find(": ");
- if (idx2 != std::string::npos)
- {
- std::string tmpNick = line.substr(0, idx2);
- if (tmpNick.find('#') != std::string::npos ||
- tmpNick.find(':') != std::string::npos ||
- tmpNick.find('%') != std::string::npos ||
- tmpNick.find('@') != std::string::npos ||
- tmpNick.size() < 5 ||
- tmpNick[0] == '@' ||
- tmpNick[0] == '/' ||
- tmpNick[0] == '!'
- )
- {
- replaceAll(tmpNick, "#", "_");
- replaceAll(tmpNick, "%", "_");
- // TRANSLATORS: error message
- line = _("Broken nick detected: ") + line;
- own = ChatMsgType::BY_SERVER;
- }
- const size_t idx = line.find(": \302\202");
- if (idx == idx2)
- {
- if (line.find(": \302\202\302") != std::string::npos)
- {
- if (line.find(": \302\202\302e") != std::string::npos)
- {
- // Do nothing. Before was local pet emote
- }
- else if (line.find(": \302\202\302m") != std::string::npos)
- {
- // Do nothing. Before was local pet move
- }
- else if (line.find(": \302\202\302d") != std::string::npos)
- {
- // Do nothing. Before was local pet direction
- }
- else if (line.find(": \302\202\302a") != std::string::npos)
- {
- // Do nothing. Before was local pet ai enable/disable
- }
- // ignore other special message formats.
- return false;
- }
-
- // pet talk message detected
- if (line.find(": \302\202\303 ") != std::string::npos)
- {
- // Do nothing. Before was local pet talk
- return false;
- }
- if (line.find(": \302\202\304") != std::string::npos)
- {
- replaceAll(line, ": \302\202\304", ": ");
- }
-
- if (tradeChatTab != nullptr)
- {
- line = line.erase(idx + 2, 2);
- tradeChatTab->chatLog(prefix + line,
- own,
- ignoreRecord,
- tryRemoveColors);
- }
- else if (localChatTab != nullptr)
- {
- line = line.erase(idx + 2, 2);
- localChatTab->chatLog(prefix + line,
- own,
- ignoreRecord,
- tryRemoveColors);
- }
- return false;
- }
- }
-
- if (!channel.empty())
- {
- if (langChatTab != nullptr)
- {
- if (langChatTab->getChannelName() == channel)
- {
- langChatTab->chatLog(line, own, ignoreRecord, tryRemoveColors);
- }
- else if (mShowAllLang)
- {
- langChatTab->chatLog(prefix + line,
- own,
- ignoreRecord,
- tryRemoveColors);
- }
- }
- else if (Net::getNetworkType() != ServerType::TMWATHENA)
- {
- channelChatLog(channel, line, own, ignoreRecord, tryRemoveColors);
- return false;
- }
- else if (mShowAllLang)
- {
- localChatTab->chatLog(prefix + line,
- own,
- ignoreRecord,
- tryRemoveColors);
- }
- }
- else if ((localChatTab != nullptr) && channel.empty())
- {
- localChatTab->chatLog(line, own, ignoreRecord, tryRemoveColors);
- }
- return true;
-}
-
-void ChatWindow::battleChatLog(const std::string &line, ChatMsgTypeT own,
- const IgnoreRecord ignoreRecord,
- const TryRemoveColors tryRemoveColors)
-{
- if (own == ChatMsgType::BY_UNKNOWN)
- own = ChatMsgType::BY_SERVER;
- if (battleChatTab != nullptr)
- battleChatTab->chatLog(line, own, ignoreRecord, tryRemoveColors);
- else if (debugChatTab != nullptr)
- debugChatTab->chatLog(line, own, ignoreRecord, tryRemoveColors);
-}
-
-void ChatWindow::channelChatLog(const std::string &channel,
- const std::string &line,
- ChatMsgTypeT own,
- const IgnoreRecord ignoreRecord,
- const TryRemoveColors tryRemoveColors)
-{
- std::string tempChannel = channel;
- toLower(tempChannel);
-
- ChatTab *tab = nullptr;
- const ChannelMap::const_iterator i = mChannels.find(tempChannel);
-
- if (i != mChannels.end())
- {
- tab = i->second;
- }
- else
- {
- tab = addChannelTab(channel, false);
- if (tab != nullptr)
- saveState();
- }
-
- if (tab != nullptr)
- tab->chatLog(line, own, ignoreRecord, tryRemoveColors);
-}
-
-void ChatWindow::initTradeFilter()
-{
- const std::string tradeListName = settings.serverConfigDir
- + "/tradefilter.txt";
-
- std::ifstream tradeFile;
- struct stat statbuf;
-
- if (stat(tradeListName.c_str(), &statbuf) == 0 &&
- S_ISREG(statbuf.st_mode))
- {
- tradeFile.open(tradeListName.c_str(), std::ios::in);
- if (tradeFile.is_open())
- {
- char line[100];
- while (tradeFile.getline(line, 100))
- {
- const std::string str = line;
- if (!str.empty())
- mTradeFilter.push_back(str);
- }
- }
- tradeFile.close();
- }
-}
-
-void ChatWindow::updateOnline(const std::set<std::string> &onlinePlayers) const
-{
- const Party *party = nullptr;
- const Guild *guild = nullptr;
- if (localPlayer != nullptr)
- {
- party = localPlayer->getParty();
- guild = localPlayer->getGuild();
- }
- FOR_EACH (TabMap::const_iterator, iter, mWhispers)
- {
- if (iter->second == nullptr)
- return;
-
- WhisperTab *const tab = static_cast<WhisperTab*>(iter->second);
- if (tab == nullptr)
- continue;
-
- if (onlinePlayers.find(tab->getNick()) != onlinePlayers.end())
- {
- tab->setWhisperTabColors();
- }
- else
- {
- const std::string &nick = tab->getNick();
- if (actorManager != nullptr)
- {
- const Being *const being = actorManager->findBeingByName(
- nick, ActorType::Player);
- if (being != nullptr)
- {
- tab->setWhisperTabColors();
- continue;
- }
- }
- if (party != nullptr)
- {
- const PartyMember *const pm = party->getMember(nick);
- if ((pm != nullptr) && pm->getOnline())
- {
- tab->setWhisperTabColors();
- continue;
- }
- }
- if (guild != nullptr)
- {
- const GuildMember *const gm = guild->getMember(nick);
- if ((gm != nullptr) && gm->getOnline())
- {
- tab->setWhisperTabColors();
- continue;
- }
- }
- tab->setWhisperTabOfflineColors();
- }
- }
-}
-
-void ChatWindow::loadState()
-{
- int num = 0;
- while (num < 50)
- {
- const std::string nick = serverConfig.getValue(
- "chatWhisper" + toString(num), "");
-
- if (nick.empty())
- break;
-
- const int flags = serverConfig.getValue(
- "chatWhisperFlags" + toString(num), 1);
-
- ChatTab *const tab = addChatTab(nick, false, false);
- if (tab != nullptr)
- {
- tab->setAllowHighlight((flags & 1) != 0);
- tab->setRemoveNames(((flags & 2) / 2) != 0);
- tab->setNoAway(((flags & 4) / 4) != 0);
- }
- num ++;
- }
-}
-
-void ChatWindow::saveState() const
-{
- int num = 0;
- for (ChannelMap::const_iterator iter = mChannels.begin(),
- iter_end = mChannels.end(); iter != iter_end && num < 50; ++iter)
- {
- if (iter->second == nullptr)
- return;
- if (!saveTab(num, iter->second))
- continue;
- num ++;
- }
-
- for (TabMap::const_iterator iter = mWhispers.begin(),
- iter_end = mWhispers.end(); iter != iter_end && num < 50; ++iter)
- {
- if (iter->second == nullptr)
- return;
- if (!saveTab(num, iter->second))
- continue;
- num ++;
- }
-
- while (num < 50)
- {
- serverConfig.deleteKey("chatWhisper" + toString(num));
- serverConfig.deleteKey("chatWhisperFlags" + toString(num));
- num ++;
- }
-}
-
-bool ChatWindow::saveTab(const int num,
- const ChatTab *const tab) const
-{
- if (tab == nullptr)
- return false;
-
- serverConfig.setValue("chatWhisper" + toString(num),
- tab->getChannelName());
-
- serverConfig.setValue("chatWhisperFlags" + toString(num),
- CAST_S32(tab->getAllowHighlight())
- + (2 * CAST_S32(tab->getRemoveNames()))
- + (4 * CAST_S32(tab->getNoAway())));
-
- return true;
-}
-
-std::string ChatWindow::doReplace(const std::string &msg)
-{
- std::string str = msg;
- replaceSpecialChars(str);
- return str;
-}
-
-void ChatWindow::loadCustomList()
-{
- std::ifstream listFile;
- struct stat statbuf;
-
- std::string listName = settings.serverConfigDir
- + "/customwords.txt";
-
- if ((stat(listName.c_str(), &statbuf) == 0) && S_ISREG(statbuf.st_mode))
- {
- listFile.open(listName.c_str(), std::ios::in);
- if (listFile.is_open())
- {
- char line[101];
- while (listFile.getline(line, 100))
- {
- std::string str = line;
- if (!str.empty())
- mCustomWords.push_back(str);
- }
- }
- listFile.close();
- }
-}
-
-void ChatWindow::addToAwayLog(const std::string &line)
-{
- if (!settings.awayMode)
- return;
-
- if (mAwayLog.size() > 20)
- mAwayLog.pop_front();
-
- if (findI(line, mHighlights) != std::string::npos)
- mAwayLog.push_back("##aaway:" + line);
-}
-
-void ChatWindow::displayAwayLog() const
-{
- if (localChatTab == nullptr)
- return;
-
- std::list<std::string>::const_iterator i = mAwayLog.begin();
- const std::list<std::string>::const_iterator i_end = mAwayLog.end();
-
- while (i != i_end)
- {
- std::string str = *i;
- localChatTab->addNewRow(str);
- ++i;
- }
-}
-
-void ChatWindow::parseHighlights()
-{
- mHighlights.clear();
- if (localPlayer == nullptr)
- return;
-
- splitToStringVector(mHighlights, config.getStringValue(
- "highlightWords"), ',');
-
- mHighlights.push_back(localPlayer->getName());
-}
-
-void ChatWindow::parseGlobalsFilter()
-{
- mGlobalsFilter.clear();
- if (localPlayer == nullptr)
- return;
-
- splitToStringVector(mGlobalsFilter, config.getStringValue(
- "globalsFilter"), ',');
-
- mHighlights.push_back(localPlayer->getName());
-}
-
-bool ChatWindow::findHighlight(const std::string &str)
-{
- return findI(str, mHighlights) != std::string::npos;
-}
-
-void ChatWindow::copyToClipboard(const int x, const int y) const
-{
- const ChatTab *const tab = getFocused();
- if (tab == nullptr)
- return;
-
- const BrowserBox *const text = tab->mTextOutput;
- if (text == nullptr)
- return;
-
- std::string str = text->getTextAtPos(x, y);
- sendBuffer(str);
-}
-
-void ChatWindow::optionChanged(const std::string &name)
-{
- if (name == "autohideChat")
- mAutoHide = config.getBoolValue("autohideChat");
- else if (name == "showBattleEvents")
- mShowBattleEvents = config.getBoolValue("showBattleEvents");
- else if (name == "globalsFilter")
- parseGlobalsFilter();
- else if (name == "enableTradeFilter")
- mEnableTradeFilter = config.getBoolValue("enableTradeFilter");
-}
-
-void ChatWindow::mouseMoved(MouseEvent &event)
-{
- mHaveMouse = true;
- Window::mouseMoved(event);
-}
-
-void ChatWindow::mouseEntered(MouseEvent& event)
-{
- mHaveMouse = true;
- Window::mouseEntered(event);
-}
-
-void ChatWindow::mouseExited(MouseEvent& event)
-{
- updateVisibility();
- Window::mouseExited(event);
-}
-
-void ChatWindow::draw(Graphics *const graphics)
-{
- BLOCK_START("ChatWindow::draw")
- if (!mAutoHide || mHaveMouse)
- {
- GLDEBUG_START("ChatWindow::draw");
- Window::draw(graphics);
- GLDEBUG_END();
- }
- BLOCK_END("ChatWindow::draw")
-}
-
-void ChatWindow::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("ChatWindow::draw")
- if (!mAutoHide || mHaveMouse)
- {
- GLDEBUG_START("ChatWindow::draw");
- Window::safeDraw(graphics);
- GLDEBUG_END();
- }
- BLOCK_END("ChatWindow::draw")
-}
-
-void ChatWindow::updateVisibility()
-{
- if (gui == nullptr)
- return;
-
- int mouseX = 0;
- int mouseY = 0;
- int x = 0;
- int y = 0;
- Gui::getMouseState(mouseX, mouseY);
- getAbsolutePosition(x, y);
- if (mChatInput->isVisible())
- {
- mHaveMouse = true;
- }
- else
- {
- mHaveMouse = mouseX >= x && mouseX <= x + getWidth()
- && mouseY >= y && mouseY <= y + getHeight();
- }
-}
-
-void ChatWindow::unHideWindow()
-{
- mHaveMouse = true;
-}
-
-#ifdef USE_PROFILER
-void ChatWindow::logicChildren()
-{
- BLOCK_START("ChatWindow::logicChildren")
- BasicContainer::logicChildren();
- BLOCK_END("ChatWindow::logicChildren")
-}
-#endif // USE_PROFILER
-
-void ChatWindow::addGlobalMessage(const std::string &line)
-{
- if (debugChatTab != nullptr &&
- findI(line, mGlobalsFilter) != std::string::npos)
- {
- debugChatTab->chatLog(line, ChatMsgType::BY_OTHER);
- }
- else
- {
- localChatTab->chatLog(line, ChatMsgType::BY_GM);
- }
-}
-
-bool ChatWindow::isTabPresent(const ChatTab *const tab) const
-{
- return mChatTabs->isTabPresent(tab);
-}
-
-void ChatWindow::debugMessage(const std::string &msg)
-{
- if (debugChatTab != nullptr)
- debugChatTab->chatLog(msg, ChatMsgType::BY_SERVER);
-}
-
-void ChatWindow::showGMTab()
-{
- if ((gmChatTab == nullptr) &&
- config.getBoolValue("enableGmTab") &&
- localPlayer->getGroupId() >= paths.getIntValue("gmTabMinimalLevel"))
- {
- addSpecialChannelTab(GM_CHANNEL, false);
- }
-}
-
-void ChatWindow::toggleChatFocus()
-{
- if (mChatInput->isVisible() && mChatInput->isFocused())
- mChatInput->processVisible(Visible_false);
- else
- requestChatFocus();
-}
-
-void ChatWindow::joinRoom(const bool isJoin)
-{
- Tab *const tab = mChatTabs->getTabByIndex(0);
- if (tab != nullptr)
- {
- std::string name;
- if (isJoin)
- {
- name = PlayerInfo::getRoomName();
- }
- else
- {
- // TRANSLATORS: chat tab name
- name = _("General");
- }
- tab->setCaption(name);
- }
-}
-
-void ChatWindow::scheduleDelete()
-{
- DebugMessageListener::removeListener(this);
- Window::scheduleDelete();
-}
diff --git a/src/gui/windows/chatwindow.h b/src/gui/windows/chatwindow.h
deleted file mode 100644
index 7d02e0fd3..000000000
--- a/src/gui/windows/chatwindow.h
+++ /dev/null
@@ -1,406 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_CHATWINDOW_H
-#define GUI_WINDOWS_CHATWINDOW_H
-
-#include "enums/gui/chatmsgtype.h"
-#include "enums/gui/chattabtype.h"
-
-#include "enums/simpletypes/ignorerecord.h"
-#include "enums/simpletypes/tryremovecolors.h"
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/attributelistener.h"
-#include "listeners/debugmessagelistener.h"
-#include "listeners/keylistener.h"
-
-class Button;
-class ChannelTab;
-class ChatTab;
-class ChatInput;
-class ColorListModel;
-class DropDown;
-class TabbedArea;
-class ItemLinkHandler;
-class WhisperTab;
-
-/**
- * The chat window.
- *
- * \ingroup Interface
- */
-class ChatWindow final : public Window,
- public ActionListener,
- public KeyListener,
- public ConfigListener,
- public AttributeListener,
- public DebugMessageListener
-{
- public:
- /**
- * Constructor.
- */
- explicit ChatWindow(const std::string &name);
-
- A_DELETE_COPY(ChatWindow)
-
- /**
- * Destructor: used to write back values to the config file
- */
- ~ChatWindow();
-
- /**
- * Gets the focused tab.
- */
- ChatTab *getFocused() const A_WARN_UNUSED;
-
- /**
- * Clear the given tab.
- */
- static void clearTab(ChatTab *const tab);
-
- /**
- * Clear the current tab.
- */
- void clearTab() const;
-
- /**
- * Switch to the previous tab in order
- */
- void prevTab();
-
- /**
- * Switch to the next tab in order
- */
- void nextTab();
-
- /**
- * Close current chat tab
- */
- void closeTab() const;
-
- /**
- * Switch to the default tab
- */
- void defaultTab();
-
- /**
- * Performs action.
- */
- void action(const ActionEvent &event) override final;
-
- /**
- * Request focus for typing chat message.
- *
- * \returns true if the input was shown
- * false otherwise
- */
- bool requestChatFocus();
-
- /**
- * Checks whether ChatWindow is Focused or not.
- */
- bool isInputFocused() const A_WARN_UNUSED;
-
- /**
- * Passes the text to the current tab as input
- *
- * @param msg The message text which is to be sent.
- */
- void chatInput(const std::string &msg) const;
-
- /**
- * Passes the text to the local chat tab as input
- *
- * @param msg The message text which is to be sent.
- */
- void localChatInput(const std::string &msg) const;
-
- /** Called when key is pressed */
- void keyPressed(KeyEvent &event) override final;
-
- /** Set the chat input as the given text. */
- void setInputText(const std::string &text);
-
- /** Add the given text to the chat input. */
- void addInputText(const std::string &text, const bool space = true);
-
- /** Called to add item to chat */
- void addItemText(const std::string &item);
-
- /** Override to reset mTmpVisible */
- void setVisible(Visible visible) override final;
-
- /**
- * Handles mouse when dragged.
- */
- void mouseDragged(MouseEvent &event) override final;
-
- /**
- * Handles mouse when pressed.
- */
- void mousePressed(MouseEvent &event) override final;
-
- /**
- * Scrolls the chat window
- *
- * @param amount direction and amount to scroll. Negative numbers scroll
- * up, positive numbers scroll down. The absolute amount indicates the
- * amount of 1/8ths of chat window real estate that should be scrolled.
- */
- void scroll(const int amount) const;
-
- /**
- * Sets the file being recorded to
- *
- * @param msg The file to write out to. If null, then stop recording.
- */
- void setRecordingFile(const std::string &msg);
-
- bool getReturnTogglesChat() const noexcept2 A_WARN_UNUSED
- { return mReturnToggles; }
-
- void setReturnTogglesChat(const bool toggles)
- { mReturnToggles = toggles; }
-
- void doPresent() const;
-
- void addWhisper(const std::string &restrict nick,
- const std::string &restrict mes,
- const ChatMsgTypeT own = ChatMsgType::BY_OTHER);
-
- WhisperTab *addWhisperTab(const std::string &caption,
- const std::string &nick,
- const bool switchTo = false) A_WARN_UNUSED;
-
- WhisperTab *getWhisperTab(const std::string &nick) const A_WARN_UNUSED;
-
- ChatTab *addChannelTab(const std::string &name,
- const bool switchTo = false);
-
- ChatTab *addSpecialChannelTab(const std::string &name,
- const bool switchTo = false);
-
- ChatTab *addChatTab(const std::string &name,
- const bool switchTo,
- const bool join) A_WARN_UNUSED;
-
- void joinRoom(const bool isJoin);
-
- void removeAllWhispers();
-
- void removeAllChannels();
-
- void ignoreAllWhispers();
-
- bool resortChatLog(std::string line, ChatMsgTypeT own,
- const std::string &channel,
- const IgnoreRecord ignoreRecord,
- const TryRemoveColors tryRemoveColors);
-
- static void battleChatLog(const std::string &line,
- ChatMsgTypeT own
- = ChatMsgType::BY_UNKNOWN,
- const IgnoreRecord ignoreRecord
- = IgnoreRecord_false,
- const TryRemoveColors tryRemoveColors
- = TryRemoveColors_true);
-
- void channelChatLog(const std::string &channel,
- const std::string &line,
- ChatMsgTypeT own,
- const IgnoreRecord ignoreRecord,
- const TryRemoveColors tryRemoveColors);
-
- void updateOnline(const std::set<std::string> &onlinePlayers) const;
-
- void loadState();
-
- void saveState() const;
-
- bool saveTab(const int num,
- const ChatTab *const tab) const;
-
- void loadCustomList();
-
- void loadGMCommands();
-
- static std::string doReplace(const std::string &msg) A_WARN_UNUSED;
-
- void adjustTabSize();
-
- void addToAwayLog(const std::string &line);
-
- void displayAwayLog() const;
-
- void clearAwayLog()
- { mAwayLog.clear(); }
-
- void parseHighlights();
-
- void parseGlobalsFilter();
-
- bool findHighlight(const std::string &str) A_WARN_UNUSED;
-
- void copyToClipboard(const int x, const int y) const;
-
- void optionChanged(const std::string &name) override final;
-
- void mouseEntered(MouseEvent& event) override final;
-
- void mouseMoved(MouseEvent &event) override final;
-
- void mouseExited(MouseEvent& event A_UNUSED) override final;
-
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void updateVisibility();
-
- void unHideWindow();
-
- void widgetResized(const Event &event) override final;
-
- void addGlobalMessage(const std::string &line);
-
- void postInit() override final;
-
- bool isTabPresent(const ChatTab *const tab) const A_WARN_UNUSED;
-
- void selectTabByType(const ChatTabTypeT &type);
-
- void attributeChanged(const AttributesT id,
- const int64_t oldVal,
- const int64_t newVal) override final;
-
- void postConnection();
-
- void showGMTab();
-
- void debugMessage(const std::string &msg) override final;
-
- void scheduleDelete() override final;
-
-#ifdef USE_PROFILER
- void logicChildren();
-#endif // USE_PROFILER
-
- protected:
- friend class ChannelTab;
- friend class ChatTab;
- friend class WhisperTab;
- friend class PopupMenu;
-
- typedef std::list<std::string> History;
-
- /** Remove the given tab from the window */
- void removeTab(ChatTab *const tab);
-
- /** Add the tab to the window */
- void addTab(ChatTab *const tab);
-
- void removeWhisper(const std::string &nick);
-
- void removeChannel(const std::string &nick);
-
- void autoComplete();
-
- std::string addColors(std::string &msg);
-
- std::string autoCompleteHistory(const std::string &partName) const;
-
- std::string autoComplete(const std::string &partName,
- const History *const words) const;
-
- static std::string autoComplete(const StringVect &names,
- std::string partName);
-
- /** Used for showing item popup on clicking links **/
- ItemLinkHandler *mItemLinkHandler A_NONNULLPOINTER;
-
- /** Tabbed area for holding each channel. */
- TabbedArea *mChatTabs A_NONNULLPOINTER;
-
- /** Input box for typing chat messages. */
- ChatInput *mChatInput A_NONNULLPOINTER;
-
- void initTradeFilter();
-
- void toggleChatFocus();
-
- unsigned int mRainbowColor;
-
- private:
- void fillCommands();
-
- void loadCommandsFile(const std::string &name);
-
- void updateTabsMargin();
-
- bool addCurrentToHistory();
-
- typedef std::map<const std::string, WhisperTab*> TabMap;
- typedef std::map<const std::string, ChannelTab*> ChannelMap;
-
- /** Manage whisper tabs */
- TabMap mWhispers;
- ChannelMap mChannels;
-
- typedef History::iterator HistoryIterator;
- History mHistory; /**< Command history. */
- HistoryIterator mCurHist; /**< History iterator. */
-
- typedef std::list<std::string> ChatCommands;
- typedef ChatCommands::iterator ChatCommandsIterator;
- History mCommands; /**< Command list. */
- History mCustomWords;
-
- StringVect mTradeFilter;
-
- ColorListModel *mColorListModel A_NONNULLPOINTER;
- DropDown *mColorPicker A_NONNULLPOINTER;
- Button *mChatButton A_NONNULLPOINTER;
- std::list<std::string> mAwayLog;
- StringVect mHighlights;
- StringVect mGlobalsFilter;
- int mChatColor;
- int mEmoteButtonSpacing;
- int mEmoteButtonY;
- unsigned int mChatHistoryIndex;
- bool mReturnToggles; // Marks whether <Return> toggles the chat log
- // or not
- bool mGMLoaded;
- bool mHaveMouse;
- bool mAutoHide;
- bool mShowBattleEvents;
- bool mShowAllLang;
- bool mEnableTradeFilter;
- bool mTmpVisible;
-};
-
-extern ChatWindow *chatWindow;
-
-#endif // GUI_WINDOWS_CHATWINDOW_H
diff --git a/src/gui/windows/confirmdialog.cpp b/src/gui/windows/confirmdialog.cpp
deleted file mode 100644
index 913fb7c41..000000000
--- a/src/gui/windows/confirmdialog.cpp
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/confirmdialog.h"
-
-#include "soundmanager.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/textbox.h"
-
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-ConfirmDialog::ConfirmDialog(const std::string &restrict title,
- const std::string &restrict msg,
- const std::string &restrict soundEvent,
- const bool ignore,
- const Modal modal,
- Window *const parent) :
- Window(title, modal, parent, "confirm.xml"),
- ActionListener(),
- mTextBox(new TextBox(this)),
- mIgnore(ignore)
-{
- mTextBox->setEditable(false);
- mTextBox->setOpaque(Opaque_false);
- mTextBox->setTextWrapped(msg, 260);
- soundManager.playGuiSound(soundEvent);
-}
-
-void ConfirmDialog::postInit()
-{
- Window::postInit();
- // TRANSLATORS: confirm dialog button
- Button *const yesButton = new Button(this, _("Yes"), "yes", this);
- // TRANSLATORS: confirm dialog button
- Button *const noButton = new Button(this, _("No"), "no", this);
- Button *const ignoreButton = mIgnore ? new Button(
- // TRANSLATORS: confirm dialog button
- this, _("Ignore"), "ignore", this) : nullptr;
-
- const int numRows = mTextBox->getNumberOfRows();
- int inWidth = yesButton->getWidth() + noButton->getWidth() +
- (2 * mPadding);
-
- if (ignoreButton != nullptr)
- inWidth += ignoreButton->getWidth();
-
- const int fontHeight = getFont()->getHeight();
- const int height = numRows * fontHeight;
- int width = getFont()->getWidth(getCaption()) + mCaptionOffsetX;
-
- if (width < mTextBox->getMinWidth())
- width = mTextBox->getMinWidth();
- if (width < inWidth)
- width = inWidth;
-
- int windowWidth = width;
- if (windowWidth < mTextBox->getMinWidth() + fontHeight)
- {
- windowWidth = mTextBox->getMinWidth() + fontHeight;
- }
- setContentSize(windowWidth,
- height + fontHeight + noButton->getHeight());
- mTextBox->setPosition(mPadding, mPadding);
-
- const int buttonPadding = getOption("buttonPadding", 8);
- yesButton->setPosition((width - inWidth) / 2, height + buttonPadding);
- noButton->setPosition(yesButton->getX() + yesButton->getWidth()
- + (2 * mPadding), height + buttonPadding);
- if (ignoreButton != nullptr)
- {
- ignoreButton->setPosition(noButton->getX() + noButton->getWidth()
- + (2 * mPadding), height + buttonPadding);
- }
-
- add(mTextBox);
- add(yesButton);
- add(noButton);
-
- if (mIgnore && (ignoreButton != nullptr))
- add(ignoreButton);
-
- if (getParent() != nullptr)
- {
- center();
- getParent()->moveToTop(this);
- }
- setVisible(Visible_true);
- yesButton->requestFocus();
-}
-
-void ConfirmDialog::action(const ActionEvent &event)
-{
- setActionEventId(event.getId());
- distributeActionEvent();
- scheduleDelete();
-}
diff --git a/src/gui/windows/confirmdialog.h b/src/gui/windows/confirmdialog.h
deleted file mode 100644
index 5d828eafb..000000000
--- a/src/gui/windows/confirmdialog.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_CONFIRMDIALOG_H
-#define GUI_WINDOWS_CONFIRMDIALOG_H
-
-#include "localconsts.h"
-
-#include "const/sound.h"
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-
-class TextBox;
-
-/**
- * An option dialog.
- *
- * \ingroup GUI
- */
-class ConfirmDialog notfinal : public Window,
- public ActionListener
-{
- public:
- /**
- * Constructor.
- *
- * @see Window::Window
- */
- ConfirmDialog(const std::string &restrict title,
- const std::string &restrict msg,
- const std::string &restrict soundEvent = SOUND_REQUEST,
- const bool ignore = false,
- const Modal modal = Modal_false,
- Window *const parent = nullptr);
-
- A_DELETE_COPY(ConfirmDialog)
-
- /**
- * Called when receiving actions from the widgets.
- */
- void action(const ActionEvent &event) override;
-
- void postInit() override final;
-
- private:
- TextBox *mTextBox A_NONNULLPOINTER;
- bool mIgnore;
-};
-
-#endif // GUI_WINDOWS_CONFIRMDIALOG_H
diff --git a/src/gui/windows/connectiondialog.cpp b/src/gui/windows/connectiondialog.cpp
deleted file mode 100644
index ec23ab646..000000000
--- a/src/gui/windows/connectiondialog.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/connectiondialog.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layoutcell.h"
-#include "gui/widgets/progressindicator.h"
-
-#include "utils/gettext.h"
-
-#include "client.h"
-
-#include "debug.h"
-
-extern bool mStatsReUpdated;
-
-ConnectionDialog::ConnectionDialog(const std::string &text,
- const StateT cancelState) :
- Window("", Modal_false, nullptr, "connection.xml"),
- ActionListener(),
- mCancelState(cancelState)
-{
- mTitleBarHeight = 0;
- setMovable(Move_false);
- setMinWidth(0);
-
- ProgressIndicator *const progressIndicator = new ProgressIndicator(this);
- Label *const label = new Label(this, text);
- Button *const cancelButton = new Button(
- // TRANSLATORS: connection dialog button
- this, _("Cancel"), "cancelButton", this);
-
- place(0, 0, progressIndicator);
- place(0, 1, label);
- place(0, 2, cancelButton).setHAlign(LayoutCell::CENTER);
- reflowLayout();
-
- center();
- if ((mSearchHash ^ 0x202020U) == 0x70E9296C)
- mStatsReUpdated = true;
-}
-
-void ConnectionDialog::postInit()
-{
- Window::postInit();
- setVisible(Visible_true);
-}
-
-void ConnectionDialog::action(const ActionEvent &event A_UNUSED)
-{
- logger->log1("Cancel pressed");
- client->setState(mCancelState);
-}
-
-void ConnectionDialog::draw(Graphics *const graphics)
-{
- BLOCK_START("ConnectionDialog::draw")
- // Don't draw the window background, only draw the children
- drawChildren(graphics);
- BLOCK_END("ConnectionDialog::draw")
-}
-
-void ConnectionDialog::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("ConnectionDialog::draw")
- // Don't draw the window background, only draw the children
- safeDrawChildren(graphics);
- BLOCK_END("ConnectionDialog::draw")
-}
diff --git a/src/gui/windows/connectiondialog.h b/src/gui/windows/connectiondialog.h
deleted file mode 100644
index ca403c477..000000000
--- a/src/gui/windows/connectiondialog.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_CONNECTIONDIALOG_H
-#define GUI_WINDOWS_CONNECTIONDIALOG_H
-
-#include "enums/state.h"
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-
-/**
- * The connection dialog.
- *
- * \ingroup Interface
- */
-class ConnectionDialog final : public Window,
- private ActionListener
-{
- public:
- /**
- * Constructor.
- *
- * @param text The text to display
- * @param cancelState The state to enter when Cancel is pressed
- *
- * @see Window::Window
- */
- ConnectionDialog(const std::string &text, const StateT cancelState);
-
- A_DELETE_COPY(ConnectionDialog)
-
- void postInit() override final;
-
- /**
- * Called when the user presses Cancel. Restores the global state to
- * the previous one.
- */
- void action(const ActionEvent &event) override final;
-
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- private:
- StateT mCancelState;
-};
-
-#endif // GUI_WINDOWS_CONNECTIONDIALOG_H
diff --git a/src/gui/windows/cutinwindow.cpp b/src/gui/windows/cutinwindow.cpp
deleted file mode 100644
index 2713dfdfc..000000000
--- a/src/gui/windows/cutinwindow.cpp
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/cutinwindow.h"
-
-#include "configuration.h"
-
-#include "const/utils/timer.h"
-
-#include "resources/sprite/animatedsprite.h"
-
-#include "utils/delete2.h"
-#include "utils/timer.h"
-
-#include "debug.h"
-
-CutInWindow *cutInWindow = nullptr;
-
-CutInWindow::CutInWindow() :
- Window("", Modal_false, nullptr, "cutin.xml"),
- mImage(nullptr),
- mOldTitleBarHeight(mTitleBarHeight)
-{
- setWindowName("CutIn");
-
- setShowTitle(false);
- setResizable(false);
- setDefaultVisible(false);
- setSaveVisible(false);
- setVisible(Visible_false);
- enableVisibleSound(false);
-}
-
-CutInWindow::~CutInWindow()
-{
- delete2(mImage);
-}
-
-void CutInWindow::draw(Graphics *const graphics)
-{
- Window::draw(graphics);
- draw2(graphics);
-}
-
-void CutInWindow::safeDraw(Graphics *const graphics)
-{
- Window::safeDraw(graphics);
- draw2(graphics);
-}
-
-void CutInWindow::draw2(Graphics *const graphics)
-{
- if (mImage != nullptr)
- mImage->drawRaw(graphics, mPadding, mTitleBarHeight);
-}
-
-void CutInWindow::show(const std::string &name,
- const CutInT cutin)
-{
- delete2(mImage);
- if (name.empty())
- {
- setVisible(Visible_false);
- }
- else
- {
- mImage = AnimatedSprite::load(
- pathJoin(paths.getStringValue("cutInsDir"),
- name).append(
- ".xml"));
- if (mImage != nullptr)
- {
- mImage->update(1);
- const bool showTitle = (cutin == CutIn::MovableClose);
- if (showTitle)
- mTitleBarHeight = mOldTitleBarHeight;
- else
- mTitleBarHeight = mPadding;
- const int width = mImage->getWidth() + 2 * mPadding;
- const int height = mImage->getHeight() + mTitleBarHeight
- + mPadding;
-
- const int screenWidth = mainGraphics->mWidth;
- const int screenHeight = mainGraphics->mHeight;
-
- if (width * 2 > screenWidth ||
- height * 2 > screenHeight)
- {
- return;
- }
- const int padding = 100;
- int x = 0;
- const int y = screenHeight - height - padding;
- switch (cutin)
- {
- case CutIn::BottomRight:
- x = screenWidth - width - padding;
- break;
- case CutIn::BottomCenter:
- case CutIn::Movable:
- case CutIn::MovableClose:
- x = (screenWidth - width) / 2;
- break;
- case CutIn::BottomLeft:
- default:
- x = padding;
- break;
- }
- setCloseButton(false);
- setVisible(Visible_true);
- setPosition(x, y);
- setCloseButton(showTitle);
- setShowTitle(showTitle);
- setSize(width, height);
- setVisible(Visible_true);
- requestMoveToTop();
- }
- }
-}
-
-void CutInWindow::hide()
-{
- delete2(mImage);
- setVisible(Visible_false);
-}
-
-void CutInWindow::logic()
-{
- if (mImage != nullptr)
- {
- const int time = tick_time * MILLISECONDS_IN_A_TICK;
- mImage->update(time);
- }
-}
diff --git a/src/gui/windows/cutinwindow.h b/src/gui/windows/cutinwindow.h
deleted file mode 100644
index c0aa81577..000000000
--- a/src/gui/windows/cutinwindow.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_CUTINWINDOW_H
-#define GUI_WINDOWS_CUTINWINDOW_H
-
-#include "gui/widgets/window.h"
-
-#include "enums/cutin.h"
-
-class AnimatedSprite;
-
-class CutInWindow final : public Window
-{
- public:
- CutInWindow();
-
- A_DELETE_COPY(CutInWindow)
-
- ~CutInWindow();
-
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void draw2(Graphics *const graphics) A_NONNULL(2);
-
- void show(const std::string &name,
- const CutInT cutin);
-
- void hide();
-
- void logic() override final;
-
- private:
- AnimatedSprite *mImage;
- int mOldTitleBarHeight;
-};
-
-extern CutInWindow *cutInWindow;
-
-#endif // GUI_WINDOWS_CUTINWINDOW_H
diff --git a/src/gui/windows/debugwindow.cpp b/src/gui/windows/debugwindow.cpp
deleted file mode 100644
index e10ad1b2c..000000000
--- a/src/gui/windows/debugwindow.cpp
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/debugwindow.h"
-
-#include "being/localplayer.h"
-
-#include "gui/windows/setupwindow.h"
-
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/tabbedarea.h"
-
-#include "gui/widgets/tabs/debugwindowtabs.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-DebugWindow *debugWindow = nullptr;
-
-DebugWindow::DebugWindow(const std::string &name) :
- // TRANSLATORS: debug window name
- Window(_("Debug"), Modal_false, nullptr, "debug.xml"),
- mTabs(CREATEWIDGETR(TabbedArea, this)),
- mMapWidget(new MapDebugTab(this)),
- mTargetWidget(new TargetDebugTab(this)),
- mNetWidget(new NetDebugTab(this))
-{
- setWindowName(name);
- if (setupWindow != nullptr)
- setupWindow->registerWindowForReset(this);
-
- setResizable(true);
- setCloseButton(true);
- setSaveVisible(true);
- setStickyButtonLock(true);
-
- setDefaultSize(400, 300, ImagePosition::CENTER);
-
- mTabs->setSelectable(false);
- mTabs->getWidgetContainer()->setSelectable(false);
- mTabs->getTabContainer()->setSelectable(false);
- // TRANSLATORS: debug window tab
- mTabs->addTab(std::string(_("Map")), mMapWidget);
- // TRANSLATORS: debug window tab
- mTabs->addTab(std::string(_("Target")), mTargetWidget);
- // TRANSLATORS: debug window tab
- mTabs->addTab(std::string(_("Net")), mNetWidget);
-
- mTabs->setDimension(Rect(0, 0, 600, 300));
-
- const int w = mDimension.width;
- const int h = mDimension.height;
- mMapWidget->resize(w, h);
- mTargetWidget->resize(w, h);
- mNetWidget->resize(w, h);
- loadWindowState();
- enableVisibleSound(true);
-}
-
-DebugWindow::~DebugWindow()
-{
- delete2(mMapWidget);
- delete2(mTargetWidget);
- delete2(mNetWidget);
-}
-
-void DebugWindow::postInit()
-{
- Window::postInit();
- add(mTabs);
-}
-
-void DebugWindow::slowLogic()
-{
- BLOCK_START("DebugWindow::slowLogic")
- if (!isWindowVisible() || (mTabs == nullptr))
- {
- BLOCK_END("DebugWindow::slowLogic")
- return;
- }
-
- switch (mTabs->getSelectedTabIndex())
- {
- default:
- case 0:
- mMapWidget->logic();
- break;
- case 1:
- mTargetWidget->logic();
- break;
- case 2:
- mNetWidget->logic();
- break;
- }
-
- if (localPlayer != nullptr)
- localPlayer->tryPingRequest();
- BLOCK_END("DebugWindow::slowLogic")
-}
-
-void DebugWindow::draw(Graphics *const g)
-{
- BLOCK_START("DebugWindow::draw")
- Window::draw(g);
-
- if (localPlayer != nullptr)
- {
- const Being *const target = localPlayer->getTarget();
- if (target != nullptr)
- {
- target->draw(g, -target->getPixelX() + mapTileSize / 2
- + mDimension.width / 2, -target->getPixelY() + mapTileSize
- + mDimension.height / 2);
- }
- }
- BLOCK_END("DebugWindow::draw")
-}
-
-void DebugWindow::safeDraw(Graphics *const g)
-{
- BLOCK_START("DebugWindow::draw")
- Window::safeDraw(g);
-
- if (localPlayer != nullptr)
- {
- const Being *const target = localPlayer->getTarget();
- if (target != nullptr)
- {
- target->draw(g, -target->getPixelX() + mapTileSize / 2
- + mDimension.width / 2, -target->getPixelY() + mapTileSize
- + mDimension.height / 2);
- }
- }
- BLOCK_END("DebugWindow::draw")
-}
-
-void DebugWindow::widgetResized(const Event &event)
-{
- Window::widgetResized(event);
-
- mTabs->setDimension(Rect(0, 0,
- mDimension.width, mDimension.height));
-}
-
-#ifdef USE_PROFILER
-void DebugWindow::logicChildren()
-{
- BLOCK_START("DebugWindow::logicChildren")
- BasicContainer::logicChildren();
- BLOCK_END("DebugWindow::logicChildren")
-}
-#endif // USE_PROFILER
diff --git a/src/gui/windows/debugwindow.h b/src/gui/windows/debugwindow.h
deleted file mode 100644
index 6350b8820..000000000
--- a/src/gui/windows/debugwindow.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_DEBUGWINDOW_H
-#define GUI_WINDOWS_DEBUGWINDOW_H
-
-#include "gui/widgets/window.h"
-
-class MapDebugTab;
-class NetDebugTab;
-class TabbedArea;
-class TargetDebugTab;
-
-/**
- * The debug window.
- *
- * \ingroup Interface
- */
-class DebugWindow final : public Window
-{
- public:
- /**
- * Constructor.
- */
- explicit DebugWindow(const std::string &name);
-
- A_DELETE_COPY(DebugWindow)
-
- ~DebugWindow();
-
- void postInit() override final;
-
- /**
- * Logic (updates components' size and infos)
- */
- void slowLogic();
-
- void draw(Graphics *const g) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const g) override final A_NONNULL(2);
-
- void setPing(int pingTime);
-
- void widgetResized(const Event &event) override final;
-
-#ifdef USE_PROFILER
- void logicChildren();
-#endif // USE_PROFILER
-
- private:
- TabbedArea *mTabs A_NONNULLPOINTER;
- MapDebugTab *mMapWidget A_NONNULLPOINTER;
- TargetDebugTab *mTargetWidget A_NONNULLPOINTER;
- NetDebugTab *mNetWidget A_NONNULLPOINTER;
-};
-
-extern DebugWindow *debugWindow;
-
-#endif // GUI_WINDOWS_DEBUGWINDOW_H
diff --git a/src/gui/windows/didyouknowwindow.cpp b/src/gui/windows/didyouknowwindow.cpp
deleted file mode 100644
index adaf6fe2f..000000000
--- a/src/gui/windows/didyouknowwindow.cpp
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/didyouknowwindow.h"
-
-#include "configuration.h"
-
-#include "enums/gui/layouttype.h"
-
-#include "gui/gui.h"
-
-#include "gui/windows/setupwindow.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/checkbox.h"
-#include "gui/widgets/itemlinkhandler.h"
-#include "gui/widgets/layout.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/staticbrowserbox.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include "utils/translation/podict.h"
-#include "utils/translation/translationmanager.h"
-
-#include "debug.h"
-
-DidYouKnowWindow *didYouKnowWindow = nullptr;
-
-static const int minTip = 1;
-static const int maxTip = 18;
-
-DidYouKnowWindow::DidYouKnowWindow() :
- // TRANSLATORS: did you know window name
- Window(_("Did You Know?"), Modal_false, nullptr, "didyouknow.xml"),
- ActionListener(),
- mItemLinkHandler(new ItemLinkHandler),
- mBrowserBox(new StaticBrowserBox(this, Opaque_true,
- "browserbox.xml")),
- mScrollArea(new ScrollArea(this, mBrowserBox,
- Opaque_true, "didyouknow_background.xml")),
- // TRANSLATORS: did you know window button
- mButtonPrev(new Button(this, _("< Previous"), "prev", this)),
- // TRANSLATORS: did you know window button
- mButtonNext(new Button(this, _("Next >"), "next", this)),
- // TRANSLATORS: did you know window checkbox
- mOpenAgainCheckBox(new CheckBox(this, _("Auto open this window"),
- config.getBoolValue("showDidYouKnow"), this, "openagain"))
-{
- setMinWidth(300);
- setMinHeight(220);
- setContentSize(455, 350);
- setWindowName("DidYouKnow");
- setCloseButton(true);
- setResizable(true);
- setStickyButtonLock(true);
-
- if (setupWindow != nullptr)
- setupWindow->registerWindowForReset(this);
- setDefaultSize(500, 400, ImagePosition::CENTER);
-
- mBrowserBox->setOpaque(Opaque_false);
- // TRANSLATORS: did you know window button
- Button *const okButton = new Button(this, _("Close"), "close", this);
-
- mBrowserBox->setLinkHandler(mItemLinkHandler);
- if (gui != nullptr)
- mBrowserBox->setFont(gui->getHelpFont());
- mBrowserBox->setProcessVars(true);
- mBrowserBox->setEnableImages(true);
- mBrowserBox->setEnableKeys(true);
- mBrowserBox->setEnableTabs(true);
-
- place(0, 0, mScrollArea, 5, 3).setPadding(3);
- place(0, 3, mOpenAgainCheckBox, 5);
- place(1, 4, mButtonPrev, 1);
- place(2, 4, mButtonNext, 1);
- place(4, 4, okButton);
-
- Layout &layout = getLayout();
- layout.setRowHeight(0, LayoutType::SET);
-
- loadWindowState();
- enableVisibleSound(true);
-}
-
-void DidYouKnowWindow::postInit()
-{
- Window::postInit();
- widgetResized(Event(nullptr));
-}
-
-DidYouKnowWindow::~DidYouKnowWindow()
-{
- delete2(mItemLinkHandler);
-}
-
-void DidYouKnowWindow::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "close")
- {
- setVisible(Visible_false);
- }
- else
- {
- const unsigned num = config.getIntValue("currentTip");
- if (eventId == "prev")
- {
- loadData(num - 1);
- }
- else if (eventId == "next")
- {
- loadData(num + 1);
- }
- else if (eventId == "openagain")
- {
- config.setValue("showDidYouKnow",
- mOpenAgainCheckBox->isSelected());
- }
- }
-}
-
-void DidYouKnowWindow::loadData(int num)
-{
- mBrowserBox->clearRows();
- if (num == 0)
- {
- const int curTip = config.getIntValue("currentTip");
- if (curTip == 1)
- num = maxTip;
- else
- num = curTip + 1;
- }
-
- if (num < minTip || num > maxTip)
- num = minTip;
-
- config.setValue("currentTip", num);
-
- loadFile(num);
-
- mBrowserBox->updateHeight();
- mScrollArea->setVerticalScrollAmount(0);
-}
-
-void DidYouKnowWindow::loadFile(const int num)
-{
- const std::string file = strprintf("tips/%d", num);
- std::string helpPath = branding.getStringValue("helpPath");
- if (helpPath.empty())
- helpPath = paths.getStringValue("help");
-
- StringVect lines;
- TranslationManager::translateFile(pathJoin(helpPath, file).append(".txt"),
- translator, lines);
-
- for (size_t i = 0, sz = lines.size(); i < sz; ++i)
- mBrowserBox->addRow(lines[i]);
-}
-
-void DidYouKnowWindow::setVisible(Visible visible)
-{
- Window::setVisible(visible);
-
- if (visible == Visible_true || isWindowVisible())
- loadData();
-}
diff --git a/src/gui/windows/didyouknowwindow.h b/src/gui/windows/didyouknowwindow.h
deleted file mode 100644
index 6d5fdf1ae..000000000
--- a/src/gui/windows/didyouknowwindow.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_DIDYOUKNOWWINDOW_H
-#define GUI_WINDOWS_DIDYOUKNOWWINDOW_H
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-
-class Button;
-class CheckBox;
-class ItemLinkHandler;
-class ScrollArea;
-class StaticBrowserBox;
-
-/**
- * The help dialog.
- */
-class DidYouKnowWindow final : public Window,
- public ActionListener
-{
- public:
- /**
- * Constructor.
- */
- DidYouKnowWindow();
-
- ~DidYouKnowWindow();
-
- A_DELETE_COPY(DidYouKnowWindow)
-
- void postInit() override final;
-
- /**
- * Called when receiving actions from the widgets.
- */
- void action(const ActionEvent &event) override final;
-
- void loadData(int num = 0);
-
- void setVisible(Visible visible) override final;
-
- private:
- void loadFile(const int num);
-
- ItemLinkHandler *mItemLinkHandler A_NONNULLPOINTER;
- StaticBrowserBox *mBrowserBox A_NONNULLPOINTER;
- ScrollArea *mScrollArea A_NONNULLPOINTER;
- Button *mButtonPrev A_NONNULLPOINTER;
- Button *mButtonNext A_NONNULLPOINTER;
- CheckBox *mOpenAgainCheckBox A_NONNULLPOINTER;
-};
-
-extern DidYouKnowWindow *didYouKnowWindow;
-
-#endif // GUI_WINDOWS_DIDYOUKNOWWINDOW_H
diff --git a/src/gui/windows/editdialog.cpp b/src/gui/windows/editdialog.cpp
deleted file mode 100644
index e14b96191..000000000
--- a/src/gui/windows/editdialog.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/editdialog.h"
-
-#include "gui/widgets/button.h"
-
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-EditDialog::EditDialog(const std::string &restrict title,
- const std::string &restrict msg,
- const std::string &restrict eventOk,
- const int width,
- Window *const parent,
- const Modal modal) :
- Window(title, modal, parent, "edit.xml"),
- ActionListener(),
- mEventOk(eventOk),
- mTextField(new TextField(this))
-{
- mDefaultWidth = width;
- mTextField->setText(msg);
-}
-
-void EditDialog::postInit()
-{
- Window::postInit();
- // TRANSLATORS: edit dialog label
- Button *const okButton = new Button(this, _("OK"), mEventOk, this);
-
- const int pad = getPadding();
- const int pad2 = pad * 2;
- mTextField->setPosition(pad, pad);
- mTextField->setWidth(mDefaultWidth - pad2);
- const int buttonPadding = getOption("buttonPadding", 8)
- + mTextField->getHeight();
- setContentSize(mDefaultWidth, okButton->getHeight()
- + buttonPadding + pad2);
- okButton->setPosition((mDefaultWidth - okButton->getWidth()) / 2,
- buttonPadding + pad);
-
- add(mTextField);
- add(okButton);
-
- center();
- setVisible(Visible_true);
- okButton->requestFocus();
-}
-
-void EditDialog::action(const ActionEvent &event)
-{
- // Proxy button events to our listeners
- FOR_EACH (ActionListenerIterator, i, mActionListeners)
- (*i)->action(event);
-
- if (event.getId() == mEventOk)
- scheduleDelete();
-}
diff --git a/src/gui/windows/editdialog.h b/src/gui/windows/editdialog.h
deleted file mode 100644
index cea7d6f78..000000000
--- a/src/gui/windows/editdialog.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_EDITDIALOG_H
-#define GUI_WINDOWS_EDITDIALOG_H
-
-#include "localconsts.h"
-
-#include "gui/widgets/window.h"
-#include "gui/widgets/textfield.h"
-
-#include "listeners/actionlistener.h"
-
-#define ACTION_EDIT_OK "edit ok"
-
-/**
- * An 'Ok' button dialog.
- *
- * \ingroup GUI
- */
-class EditDialog final : public Window,
- public ActionListener
-{
- public:
- /**
- * Constructor.
- *
- * @see Window::Window
- */
- EditDialog(const std::string &restrict title,
- const std::string &restrict msg,
- const std::string &restrict eventOk = ACTION_EDIT_OK,
- const int width = 300, Window *const parent = nullptr,
- const Modal modal = Modal_true);
-
- A_DELETE_COPY(EditDialog)
-
- void postInit() override final;
-
- /**
- * Called when receiving actions from the widgets.
- */
- void action(const ActionEvent &event) override final;
-
- std::string getMsg() const A_WARN_UNUSED
- { return mTextField->getText(); }
-
- private:
- std::string mEventOk;
- TextField *mTextField A_NONNULLPOINTER;
-};
-
-#endif // GUI_WINDOWS_EDITDIALOG_H
diff --git a/src/gui/windows/editserverdialog.cpp b/src/gui/windows/editserverdialog.cpp
deleted file mode 100644
index 37683caf5..000000000
--- a/src/gui/windows/editserverdialog.cpp
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2012 The Mana Developers
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/editserverdialog.h"
-
-#include "const/net/maxpacketversion.h"
-
-#include "gui/models/typelistmodel.h"
-
-#include "gui/windows/okdialog.h"
-#include "gui/windows/serverdialog.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/checkbox.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/dropdown.h"
-#include "gui/widgets/inttextfield.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layout.h"
-
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-EditServerDialog::EditServerDialog(ServerDialog *const parent,
- const ServerInfo &server,
- const int index) :
- // TRANSLATORS: edit server dialog name
- Window(_("Edit Server"), Modal_true, parent),
- ActionListener(),
- KeyListener(),
- mServerAddressField(new TextField(this, std::string())),
- mPortField(new TextField(this, std::string())),
- mNameField(new TextField(this, std::string())),
- mDescriptionField(new TextField(this, std::string())),
- mOnlineListUrlField(new TextField(this, std::string())),
- mPacketVersionField(new IntTextField(this, 0, 0, maxPacketVersion)),
- // TRANSLATORS: edit server dialog button
- mConnectButton(new Button(this, _("Connect"), "connect", this)),
- // TRANSLATORS: edit server dialog button
- mOkButton(new Button(this, _("OK"), "addServer", this)),
- // TRANSLATORS: edit server dialog button
- mCancelButton(new Button(this, _("Cancel"), "cancel", this)),
- // TRANSLATORS: edit server dialog label
- mPersistentIp(new CheckBox(this, _("Use same ip"),
- true, this, "persistentIp")),
- mTypeListModel(new TypeListModel),
- mTypeField(new DropDown(this, mTypeListModel, false, Modal_true)),
- mServerDialog(parent),
- mServer(server),
- mIndex(index)
-{
- setWindowName("EditServerDialog");
-
- // TRANSLATORS: edit server dialog label
- Label *const nameLabel = new Label(this, _("Name:"));
- // TRANSLATORS: edit server dialog label
- Label *const serverAdressLabel = new Label(this, _("Address:"));
- // TRANSLATORS: edit server dialog label
- Label *const portLabel = new Label(this, _("Port:"));
- // TRANSLATORS: edit server dialog label
- Label *const typeLabel = new Label(this, _("Server type:"));
- // TRANSLATORS: edit server dialog label
- Label *const descriptionLabel = new Label(this, _("Description:"));
- // TRANSLATORS: edit server dialog label
- Label *const onlineListUrlLabel = new Label(this, _("Online list url:"));
- // TRANSLATORS: edit server dialog label
- Label *const packetVersionLabel = new Label(this, _("Packet version:"));
- mPortField->setNumeric(true);
- mPortField->setRange(1, 65535);
-
- mTypeField->setSelected(0); // TmwAthena by default
-
- mServerAddressField->addActionListener(this);
- mPortField->addActionListener(this);
-
- place(0, 0, nameLabel);
- place(1, 0, mNameField, 4).setPadding(3);
- place(0, 1, serverAdressLabel);
- place(1, 1, mServerAddressField, 4).setPadding(3);
- place(0, 2, portLabel);
- place(1, 2, mPortField, 4).setPadding(3);
- place(0, 3, typeLabel);
- place(1, 3, mTypeField).setPadding(3);
- place(0, 4, descriptionLabel);
- place(1, 4, mDescriptionField, 4).setPadding(3);
- place(0, 5, onlineListUrlLabel);
- place(1, 5, mOnlineListUrlField, 4).setPadding(3);
- place(0, 6, packetVersionLabel);
- place(1, 6, mPacketVersionField, 4).setPadding(3);
- place(0, 7, mPersistentIp, 4).setPadding(3);
- place(0, 8, mConnectButton);
- place(4, 8, mOkButton);
- place(3, 8, mCancelButton);
-
- // Do this manually instead of calling reflowLayout so we can enforce a
- // minimum width.
- int width = 0;
- int height = 0;
- getLayout().reflow(width, height);
- if (width < 300)
- {
- width = 300;
- getLayout().reflow(width, height);
- }
- if (height < 120)
- {
- height = 120;
- getLayout().reflow(width, height);
- }
-
- setContentSize(width, height);
-
- setMinWidth(getWidth());
- setMinHeight(getHeight());
- setDefaultSize(getWidth(), getHeight(), ImagePosition::CENTER);
-
- setResizable(false);
- addKeyListener(this);
-
- loadWindowState();
-
- mNameField->setText(mServer.name);
- mDescriptionField->setText(mServer.description);
- mOnlineListUrlField->setText(mServer.onlineListUrl);
- mServerAddressField->setText(mServer.hostname);
- mPacketVersionField->setValue(mServer.packetVersion);
- mPortField->setText(toString(mServer.port));
- mPersistentIp->setSelected(mServer.persistentIp);
-
- switch (mServer.type)
- {
- case ServerType::EATHENA:
-#ifdef TMWA_SUPPORT
- mTypeField->setSelected(1);
-#else // TMWA_SUPPORT
- mTypeField->setSelected(0);
-#endif // TMWA_SUPPORT
- break;
- default:
- case ServerType::UNKNOWN:
- case ServerType::TMWATHENA:
- mTypeField->setSelected(0);
- break;
- case ServerType::EVOL2:
-#ifdef TMWA_SUPPORT
- mTypeField->setSelected(2);
-#else // TMWA_SUPPORT
- mTypeField->setSelected(1);
-#endif // TMWA_SUPPORT
- break;
- }
-
- setLocationRelativeTo(getParentWindow());
-}
-
-EditServerDialog::~EditServerDialog()
-{
- delete mTypeListModel;
-}
-
-void EditServerDialog::postInit()
-{
- Window::postInit();
- setVisible(Visible_true);
- mNameField->requestFocus();
-}
-
-void EditServerDialog::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
-
- if (eventId == "ok")
- {
- // Give focus back to the server dialog.
- mServerAddressField->requestFocus();
- }
- if (eventId == "addServer" || eventId == "connect")
- {
- // Check the given information
- if (mServerAddressField->getText().empty()
- || mPortField->getText().empty())
- {
- OkDialog *const dlg = CREATEWIDGETR(OkDialog,
- // TRANSLATORS: edit server dialog error header
- _("Error"),
- // TRANSLATORS: edit server dialog error message
- _("Please at least type both the address and the port "
- "of the server."),
- // TRANSLATORS: ok dialog button
- _("OK"),
- DialogType::ERROR,
- Modal_true,
- ShowCenter_true,
- nullptr,
- 260);
- dlg->addActionListener(this);
- }
- else
- {
- mCancelButton->setEnabled(false);
- mOkButton->setEnabled(false);
-
- mServer.name = mNameField->getText();
- mServer.description = mDescriptionField->getText();
- mServer.onlineListUrl = mOnlineListUrlField->getText();
- mServer.hostname = mServerAddressField->getText();
- mServer.packetVersion = mPacketVersionField->getValue();
- mServer.port = CAST_S16(atoi(
- mPortField->getText().c_str()));
- mServer.persistentIp = mPersistentIp->isSelected();
-
- if (mTypeField != nullptr)
- {
- switch (mTypeField->getSelected())
- {
-#ifdef TMWA_SUPPORT
- case 0:
- mServer.type = ServerType::TMWATHENA;
- break;
- case 1:
- mServer.type = ServerType::EATHENA;
- break;
- case 2:
- mServer.type = ServerType::EVOL2;
- break;
-#else // TMWA_SUPPORT
-
- case 0:
- mServer.type = ServerType::EATHENA;
- break;
- case 1:
- mServer.type = ServerType::EVOL2;
- break;
-#endif // TMWA_SUPPORT
-
- default:
- mServer.type = ServerType::UNKNOWN;
- break;
- }
- }
- else
- {
- mServer.type = ServerType::TMWATHENA;
- }
-
- // Tell the server has to be saved
- mServer.save = true;
-
- // Add server
- mServerDialog->updateServer(mServer, mIndex);
- if (eventId == "connect")
- mServerDialog->connectToSelectedServer();
- scheduleDelete();
- }
- }
- else if (eventId == "cancel")
- {
- scheduleDelete();
- }
-}
-
-void EditServerDialog::keyPressed(KeyEvent &event)
-{
- if (event.isConsumed())
- return;
-
- const InputActionT actionId = event.getActionId();
-
- if (actionId == InputAction::GUI_CANCEL)
- {
- scheduleDelete();
- }
- else if (actionId == InputAction::GUI_SELECT ||
- actionId == InputAction::GUI_SELECT2)
- {
- action(ActionEvent(nullptr, mOkButton->getActionEventId()));
- }
-}
diff --git a/src/gui/windows/editserverdialog.h b/src/gui/windows/editserverdialog.h
deleted file mode 100644
index e53632c00..000000000
--- a/src/gui/windows/editserverdialog.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2012 The Mana Developers
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_EDITSERVERDIALOG_H
-#define GUI_WINDOWS_EDITSERVERDIALOG_H
-
-class Button;
-class CheckBox;
-class DropDown;
-class IntTextField;
-class ServerDialog;
-class TextField;
-class TypeListModel;
-
-#include "gui/widgets/window.h"
-
-#include "net/serverinfo.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/keylistener.h"
-
-/**
- * The custom server addition dialog.
- *
- * \ingroup Interface
- */
-class EditServerDialog final : public Window,
- public ActionListener,
- public KeyListener
-{
- public:
- EditServerDialog(ServerDialog *const parent,
- const ServerInfo &server,
- const int index);
-
- A_DELETE_COPY(EditServerDialog)
-
- ~EditServerDialog();
-
- void postInit() override final;
-
- /**
- * Called when receiving actions from the widgets.
- */
- void action(const ActionEvent &event) override final;
-
- void keyPressed(KeyEvent &event) override final;
-
- private:
- TextField *mServerAddressField A_NONNULLPOINTER;
- TextField *mPortField A_NONNULLPOINTER;
- TextField *mNameField A_NONNULLPOINTER;
- TextField *mDescriptionField A_NONNULLPOINTER;
- TextField *mOnlineListUrlField A_NONNULLPOINTER;
- IntTextField *mPacketVersionField A_NONNULLPOINTER;
- Button *mConnectButton A_NONNULLPOINTER;
- Button *mOkButton A_NONNULLPOINTER;
- Button *mCancelButton A_NONNULLPOINTER;
- CheckBox *mPersistentIp A_NONNULLPOINTER;
- TypeListModel *mTypeListModel A_NONNULLPOINTER;
- DropDown *mTypeField A_NONNULLPOINTER;
-
- ServerDialog *mServerDialog;
- ServerInfo mServer;
- int mIndex;
-};
-
-#endif // GUI_WINDOWS_EDITSERVERDIALOG_H
diff --git a/src/gui/windows/eggselectiondialog.cpp b/src/gui/windows/eggselectiondialog.cpp
deleted file mode 100644
index 5e77d8ec1..000000000
--- a/src/gui/windows/eggselectiondialog.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/eggselectiondialog.h"
-
-#include "gui/models/shopitems.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/shoplistbox.h"
-
-#include "net/inventoryhandler.h"
-
-#include "utils/gettext.h"
-
-#include "resources/item/shopitem.h"
-
-#include "debug.h"
-
-EggSelectionDialog::EggSelectionDialog() :
- SellDialog(IsSell_false, Advanced_false)
-{
- // TRANSLATORS: egg selection dialog name
- setWindowName(_("Select egg"));
- // TRANSLATORS: egg selection dialog name
- setCaption(_("Select egg"));
-}
-
-void EggSelectionDialog::initButtons()
-{
- logger->log("EggSelectionDialog::initButtons");
- // TRANSLATORS: egg selection dialog button
- mSellButton->setCaption(_("Select"));
- mSellButton->adjustSize();
- mShopItems->setMergeDuplicates(false);
-}
-
-void EggSelectionDialog::sellAction(const ActionEvent &event A_UNUSED)
-{
- if (mAmountItems <= 0 || mAmountItems > mMaxItems)
- return;
-
- const int selectedItem = mShopItemList->getSelected();
- const ShopItem *const item = mShopItems->at(selectedItem);
- if (item == nullptr)
- return;
- inventoryHandler->selectEgg(item);
- scheduleDelete();
-}
diff --git a/src/gui/windows/eggselectiondialog.h b/src/gui/windows/eggselectiondialog.h
deleted file mode 100644
index 14d91a699..000000000
--- a/src/gui/windows/eggselectiondialog.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_EGGSELECTIONDIALOG_H
-#define GUI_WINDOWS_EGGSELECTIONDIALOG_H
-
-#include "gui/widgets/selldialog.h"
-
-class EggSelectionDialog final : public SellDialog
-{
- public:
- /**
- * Constructor.
- *
- * @see Window::Window
- */
- EggSelectionDialog();
-
- A_DELETE_COPY(EggSelectionDialog)
-
- protected:
- void initButtons() override final;
- void sellAction(const ActionEvent &event) override final;
-};
-
-#endif // GUI_WINDOWS_EGGSELECTIONDIALOG_H
diff --git a/src/gui/windows/emotewindow.cpp b/src/gui/windows/emotewindow.cpp
deleted file mode 100644
index f4f720535..000000000
--- a/src/gui/windows/emotewindow.cpp
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/emotewindow.h"
-
-#include "gui/models/colormodel.h"
-#include "gui/models/namesmodel.h"
-
-#include "gui/windows/setupwindow.h"
-
-#include "gui/widgets/colorpage.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/emotepage.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/tabbedarea.h"
-
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-
-#include "utils/translation/podict.h"
-
-#include "resources/imageset.h"
-
-#include "resources/db/textdb.h"
-
-#include "resources/image/image.h"
-
-#include "debug.h"
-
-EmoteWindow *emoteWindow = nullptr;
-static const int fontSizeListSize = 2;
-
-static const char *const fontSizeList[] =
-{
- // TRANSLATORS: font size
- N_("Normal font"),
- // TRANSLATORS: font size
- N_("Bold font"),
-};
-
-EmoteWindow::EmoteWindow() :
- // TRANSLATORS: emotes window name
- Window(_("Emotes"), Modal_false, nullptr, "emotes.xml"),
- mTabs(CREATEWIDGETR(TabbedArea, this)),
- mEmotePage(new EmotePage(this)),
- mColorModel(ColorModel::createDefault(this)),
- mColorPage(CREATEWIDGETR(ColorPage, this, mColorModel, "colorpage.xml")),
- mScrollColorPage(new ScrollArea(this, mColorPage, Opaque_false,
- "emotepage.xml")),
- mFontModel(new NamesModel),
- mFontPage(CREATEWIDGETR(ListBox, this, mFontModel, "")),
- mScrollFontPage(new ScrollArea(this, mFontPage, Opaque_false,
- "fontpage.xml")),
- mTextModel(new NamesModel),
- mTextPage(CREATEWIDGETR(ListBox, this, mTextModel, "")),
- mScrollTextPage(new ScrollArea(this, mTextPage, Opaque_false,
- "textpage.xml")),
- mImageSet(Theme::getImageSetFromThemeXml("emotetabs.xml", "", 17, 16))
-{
- setShowTitle(false);
- setResizable(true);
-
- if (setupWindow != nullptr)
- setupWindow->registerWindowForReset(this);
-
- addMouseListener(this);
-}
-
-void EmoteWindow::postInit()
-{
- Window::postInit();
- const int pad2 = mPadding * 2;
- const int width = 200;
- const int height = 150;
- setWidth(width + pad2);
- setHeight(height + pad2);
- add(mTabs);
- mTabs->setPosition(mPadding, mPadding);
- mTabs->setWidth(width);
- mTabs->setHeight(height);
- center();
-
- setTitleBarHeight(getPadding() + getTitlePadding());
- mScrollColorPage->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS);
- mScrollColorPage->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- mScrollFontPage->setVerticalScrollPolicy(ScrollArea::SHOW_NEVER);
- mScrollFontPage->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- mScrollTextPage->setVerticalScrollPolicy(ScrollArea::SHOW_NEVER);
- mScrollTextPage->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
-
- mFontModel->fillFromArray(&fontSizeList[0], fontSizeListSize);
-
- mFontPage->setCenter(true);
- mTextPage->setCenter(true);
-
- if ((mImageSet != nullptr) && mImageSet->size() >= 3)
- {
- for (int f = 0; f < 3; f ++)
- {
- Image *const image = mImageSet->get(f);
- if (image != nullptr)
- image->incRef();
- }
-
- mTabs->addTab(mImageSet->get(0), mEmotePage);
- mTabs->addTab(mImageSet->get(2), mScrollColorPage);
- mTabs->addTab(mImageSet->get(1), mScrollFontPage);
- }
- else
- {
- // TRANSLATORS: emotes tab name
- mTabs->addTab(_("Emotes"), mEmotePage);
- // TRANSLATORS: emotes tab name
- mTabs->addTab(_("Colors"), mScrollColorPage);
- // TRANSLATORS: emotes tab name
- mTabs->addTab(_("Fonts"), mScrollFontPage);
- }
- // TRANSLATORS: emotes tab name
- mTabs->addTab(_("T"), mScrollTextPage);
-
- mEmotePage->setActionEventId("emote");
- mColorPage->setActionEventId("color");
- mFontPage->setActionEventId("font");
- mTextPage->setActionEventId("text");
-}
-
-EmoteWindow::~EmoteWindow()
-{
- mTabs->removeAll(false);
- mTabs->removeTab(mTabs->getTabByIndex(0));
- delete2(mEmotePage);
- delete2(mColorPage);
- delete2(mColorModel);
- delete2(mScrollColorPage);
- delete2(mFontPage);
- delete2(mFontModel);
- delete2(mScrollFontPage);
- delete2(mTextPage);
- delete2(mTextModel);
- delete2(mScrollTextPage);
- if (mImageSet != nullptr)
- {
- mImageSet->decRef();
- mImageSet = nullptr;
- }
-}
-
-void EmoteWindow::show()
-{
- setVisible(Visible_true);
- if (dictionary != nullptr)
- {
- mTextModel->clear();
- const STD_VECTOR<std::string> &texts = TextDb::getTexts();
- FOR_EACH (StringVectCIter, it, texts)
- {
- mTextModel->add(dictionary->getStr(*it));
- }
- }
-}
-
-void EmoteWindow::hide()
-{
- setVisible(Visible_false);
-}
-
-std::string EmoteWindow::getSelectedEmote() const
-{
- const int index = mEmotePage->getSelectedIndex();
- if (index < 0)
- return std::string();
-
- char chr[2];
- chr[0] = CAST_8('0' + index);
- chr[1] = 0;
- return std::string("%%").append(&chr[0]);
-}
-
-void EmoteWindow::clearEmote()
-{
- const int index = mEmotePage->getSelectedIndex();
- mEmotePage->resetAction();
- if (index >= 0)
- setVisible(Visible_false);
-}
-
-std::string EmoteWindow::getSelectedColor() const
-{
- const int index = mColorPage->getSelected();
- if (index < 0)
- return std::string();
-
- char chr[2];
- chr[0] = CAST_8('0' + index);
- chr[1] = 0;
- return std::string("##").append(&chr[0]);
-}
-
-int EmoteWindow::getSelectedTextIndex() const
-{
- return mTextPage->getSelected();
-}
-
-void EmoteWindow::clearColor()
-{
- mColorPage->resetAction();
- setVisible(Visible_false);
-}
-
-std::string EmoteWindow::getSelectedFont() const
-{
- const int index = mFontPage->getSelected();
- if (index < 0)
- return std::string();
-
- if (index == 0)
- return "##b";
- return "##B";
-}
-
-void EmoteWindow::clearFont()
-{
- mFontPage->setSelected(-1);
- setVisible(Visible_false);
-}
-
-void EmoteWindow::clearText()
-{
- mTextPage->setSelected(-1);
- setVisible(Visible_false);
-}
-
-void EmoteWindow::addListeners(ActionListener *const listener)
-{
- mEmotePage->addActionListener(listener);
- mColorPage->addActionListener(listener);
- mFontPage->addActionListener(listener);
- mTextPage->addActionListener(listener);
-}
-
-void EmoteWindow::widgetResized(const Event &event)
-{
- Window::widgetResized(event);
- const int pad2 = mPadding * 2;
- const int width = mDimension.width;
- const int height = mDimension.height;
-
- mTabs->setSize(width - pad2, height - pad2);
- mTabs->adjustWidget(mEmotePage);
- mTabs->adjustWidget(mScrollColorPage);
- mColorPage->setSize(mScrollColorPage->getWidth(),
- mScrollColorPage->getHeight());
- mEmotePage->widgetResized(event);
-}
-
-void EmoteWindow::widgetMoved(const Event &event)
-{
- Window::widgetMoved(event);
- mEmotePage->widgetResized(event);
-}
diff --git a/src/gui/windows/emotewindow.h b/src/gui/windows/emotewindow.h
deleted file mode 100644
index 66fb0c83c..000000000
--- a/src/gui/windows/emotewindow.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_EMOTEWINDOW_H
-#define GUI_WINDOWS_EMOTEWINDOW_H
-
-#include "gui/widgets/window.h"
-
-class ColorModel;
-class ColorPage;
-class EmotePage;
-class ImageSet;
-class ListBox;
-class NamesModel;
-class ScrollArea;
-class TabbedArea;
-
-class EmoteWindow final : public Window
-{
- public:
- EmoteWindow();
-
- A_DELETE_COPY(EmoteWindow)
-
- ~EmoteWindow();
-
- void postInit() override final;
-
- void show();
-
- void hide();
-
- std::string getSelectedEmote() const;
-
- void clearEmote();
-
- std::string getSelectedColor() const;
-
- void clearColor();
-
- std::string getSelectedFont() const;
-
- int getSelectedTextIndex() const;
-
- void clearFont();
-
- void clearText();
-
- void addListeners(ActionListener *const listener);
-
- void widgetResized(const Event &event) override final;
-
- void widgetMoved(const Event &event) override final;
-
- private:
- TabbedArea *mTabs A_NONNULLPOINTER;
- EmotePage *mEmotePage A_NONNULLPOINTER;
- ColorModel *mColorModel A_NONNULLPOINTER;
- ColorPage *mColorPage A_NONNULLPOINTER;
- ScrollArea *mScrollColorPage A_NONNULLPOINTER;
- NamesModel *mFontModel A_NONNULLPOINTER;
- ListBox *mFontPage A_NONNULLPOINTER;
- ScrollArea *mScrollFontPage A_NONNULLPOINTER;
- NamesModel *mTextModel A_NONNULLPOINTER;
- ListBox *mTextPage A_NONNULLPOINTER;
- ScrollArea *mScrollTextPage A_NONNULLPOINTER;
- ImageSet *mImageSet;
-};
-
-extern EmoteWindow *emoteWindow;
-
-#endif // GUI_WINDOWS_EMOTEWINDOW_H
diff --git a/src/gui/windows/equipmentwindow.cpp b/src/gui/windows/equipmentwindow.cpp
deleted file mode 100644
index a859ef02b..000000000
--- a/src/gui/windows/equipmentwindow.cpp
+++ /dev/null
@@ -1,848 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/equipmentwindow.h"
-
-#include "configuration.h"
-#include "dragdrop.h"
-
-#include "being/localplayer.h"
-#include "being/playerinfo.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/popups/popupmenu.h"
-#include "gui/popups/itempopup.h"
-
-#include "gui/windows/setupwindow.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/equipmentbox.h"
-#include "gui/widgets/equipmentpage.h"
-#include "gui/widgets/playerbox.h"
-#include "gui/widgets/tabstrip.h"
-
-#include "render/vertexes/imagecollection.h"
-
-#include "resources/imageset.h"
-
-#include "utils/checkutils.h"
-#include "utils/delete2.h"
-#include "utils/dtor.h"
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-
-#include "net/inventoryhandler.h"
-
-#include "debug.h"
-
-EquipmentWindow *equipmentWindow = nullptr;
-EquipmentWindow *beingEquipmentWindow = nullptr;
-static const int BOX_COUNT = 27;
-StringIntMap EquipmentWindow::mSlotNames;
-
-EquipmentWindow::EquipmentWindow(Equipment *const equipment,
- Being *const being,
- const bool foring) :
- // TRANSLATORS: equipment window name
- Window(_("Equipment"), Modal_false, nullptr, "equipment.xml"),
- ActionListener(),
- mEquipment(equipment),
- mPlayerBox(new PlayerBox(this,
- "equipment_playerbox.xml",
- "equipment_selectedplayerbox.xml")),
- // TRANSLATORS: equipment window button
- mUnequip(new Button(this, _("Unequip"), "unequip", this)),
- mImageSet(nullptr),
- mBeing(being),
- mSlotBackground(),
- mSlotHighlightedBackground(),
- mVertexes(new ImageCollection),
- mPages(),
- mTabs(nullptr),
- mHighlightColor(getThemeColor(ThemeColorId::HIGHLIGHT)),
- mBorderColor(getThemeColor(ThemeColorId::BORDER)),
- mLabelsColor(getThemeColor(ThemeColorId::LABEL)),
- mLabelsColor2(getThemeColor(ThemeColorId::LABEL_OUTLINE)),
- mSelected(-1),
- mItemPadding(getOption("itemPadding")),
- mBoxSize(getOption("boxSize")),
- mButtonPadding(getOption("buttonPadding", 5)),
- mMinX(180),
- mMinY(345),
- mMaxX(0),
- mMaxY(0),
- mYPadding(0),
- mSelectedTab(0),
- mForing(foring),
- mHaveDefaultPage(false)
-{
- const int size = config.getIntValue("fontSize")
- + getOption("tabHeightAdjust", 16);
- mTabs = new TabStrip(this, "equipment", size);
- mTabs->addActionListener(this);
- mTabs->setActionEventId("tab_");
- mTabs->setSelectable(false);
-
- mYPadding = mTabs->getHeight() + getOption("tabPadding", 2);
-
- if (setupWindow != nullptr)
- setupWindow->registerWindowForReset(this);
-
- if (mBoxSize == 0)
- mBoxSize = 36;
-
- // Control that shows the Player
- mPlayerBox->setDimension(Rect(50, 80 + mYPadding, 74, 168));
- mPlayerBox->setPlayer(being);
- mPlayerBox->setSelectable(false);
-
- if (foring)
- setWindowName("Being equipment");
- else
- setWindowName("Equipment");
-
- setCloseButton(true);
- setSaveVisible(true);
- setStickyButtonLock(true);
-
- fillBoxes();
- recalcSize();
- updatePage();
- loadWindowState();
-}
-
-void EquipmentWindow::postInit()
-{
- Window::postInit();
- const Rect &area = getChildrenArea();
- mUnequip->setPosition(area.width - mUnequip->getWidth() - mButtonPadding,
- area.height - mUnequip->getHeight() - mButtonPadding);
- mUnequip->setEnabled(false);
-
- ImageRect rect;
- theme->loadRect(rect, "equipment_background.xml", "", 0, 1);
- mSlotBackground = rect.grid[0];
- mSlotHighlightedBackground = rect.grid[1];
- add(mTabs);
- add(mPlayerBox);
- add(mUnequip);
- enableVisibleSound(true);
- mPlayerBox->setActionEventId("playerbox");
- mPlayerBox->addActionListener(this);
-}
-
-EquipmentWindow::~EquipmentWindow()
-{
- if (this == beingEquipmentWindow)
- {
- if (mEquipment != nullptr)
- delete mEquipment->getBackend();
- delete2(mEquipment)
- }
- FOR_EACH (STD_VECTOR<EquipmentPage*>::iterator, it, mPages)
- {
- STD_VECTOR<EquipmentBox*> &boxes = (*it)->boxes;
- delete_all(boxes);
- boxes.clear();
- delete *it;
- }
- if (mImageSet != nullptr)
- {
- mImageSet->decRef();
- mImageSet = nullptr;
- }
- if (mSlotBackground != nullptr)
- mSlotBackground->decRef();
- if (mSlotHighlightedBackground != nullptr)
- mSlotHighlightedBackground->decRef();
- delete2(mVertexes);
-}
-
-void EquipmentWindow::draw(Graphics *const graphics)
-{
- BLOCK_START("EquipmentWindow::draw")
- // Draw window graphics
- Window::draw(graphics);
-
- int i = 0;
- Font *const font = getFont();
- const int fontHeight = font->getHeight();
- const STD_VECTOR<EquipmentBox*> &boxes = mPages[mSelectedTab]->boxes;
-
- if (mLastRedraw)
- {
- mVertexes->clear();
- FOR_EACH (STD_VECTOR<EquipmentBox*>::const_iterator, it, boxes)
- {
- const EquipmentBox *const box = *it;
- if (box == nullptr)
- {
- i ++;
- continue;
- }
- if (i == mSelected)
- {
- graphics->calcTileCollection(mVertexes,
- mSlotHighlightedBackground,
- box->x, box->y);
- }
- else
- {
- graphics->calcTileCollection(mVertexes,
- mSlotBackground,
- box->x, box->y);
- }
- i ++;
- }
- graphics->finalize(mVertexes);
- }
- graphics->drawTileCollection(mVertexes);
-
- if (mEquipment == nullptr)
- {
- BLOCK_END("EquipmentWindow::draw")
- return;
- }
-
- i = 0;
- const int projSlot = inventoryHandler->getProjectileSlot();
- for (STD_VECTOR<EquipmentBox*>::const_iterator it = boxes.begin(),
- it_end = boxes.end(); it != it_end; ++ it, ++ i)
- {
- const EquipmentBox *const box = *it;
- if (box == nullptr)
- continue;
- const Item *const item = mEquipment->getEquipment(i);
- if (item != nullptr)
- {
- // Draw Item.
- Image *const image = item->getImage();
- if (image != nullptr)
- {
- image->setAlpha(1.0F); // Ensure the image is drawn
- // with maximum opacity
- graphics->drawImage(image, box->x + mItemPadding,
- box->y + mItemPadding);
- if (i == projSlot)
- {
- const std::string str = toString(item->getQuantity());
- font->drawString(graphics,
- mLabelsColor,
- mLabelsColor2,
- str,
- box->x + (mBoxSize - font->getWidth(str)) / 2,
- box->y - fontHeight);
- }
- }
- }
- else if (box->image != nullptr)
- {
- graphics->drawImage(box->image,
- box->x + mItemPadding,
- box->y + mItemPadding);
- }
- }
- BLOCK_END("EquipmentWindow::draw")
-}
-
-void EquipmentWindow::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("EquipmentWindow::draw")
- // Draw window graphics
- Window::safeDraw(graphics);
-
- int i = 0;
- Font *const font = getFont();
- const int fontHeight = font->getHeight();
- const STD_VECTOR<EquipmentBox*> &boxes = mPages[mSelectedTab]->boxes;
-
- for (STD_VECTOR<EquipmentBox*>::const_iterator it = boxes.begin(),
- it_end = boxes.end(); it != it_end; ++ it, ++ i)
- {
- const EquipmentBox *const box = *it;
- if (box == nullptr)
- continue;
- if (i == mSelected)
- {
- graphics->drawImage(mSlotHighlightedBackground,
- box->x, box->y);
- }
- else
- {
- graphics->drawImage(mSlotBackground, box->x, box->y);
- }
- }
-
- if (mEquipment == nullptr)
- {
- BLOCK_END("EquipmentWindow::draw")
- return;
- }
-
- i = 0;
- const int projSlot = inventoryHandler->getProjectileSlot();
- for (STD_VECTOR<EquipmentBox*>::const_iterator it = boxes.begin(),
- it_end = boxes.end(); it != it_end; ++ it, ++ i)
- {
- const EquipmentBox *const box = *it;
- if (box == nullptr)
- continue;
- const Item *const item = mEquipment->getEquipment(i);
- if (item != nullptr)
- {
- // Draw Item.
- Image *const image = item->getImage();
- if (image != nullptr)
- {
- image->setAlpha(1.0F); // Ensure the image is drawn
- // with maximum opacity
- graphics->drawImage(image, box->x + mItemPadding,
- box->y + mItemPadding);
- if (i == projSlot)
- {
- const std::string str = toString(item->getQuantity());
- font->drawString(graphics,
- mLabelsColor,
- mLabelsColor2,
- str,
- box->x + (mBoxSize - font->getWidth(str)) / 2,
- box->y - fontHeight);
- }
- }
- }
- else if (box->image != nullptr)
- {
- graphics->drawImage(box->image,
- box->x + mItemPadding,
- box->y + mItemPadding);
- }
- }
- BLOCK_END("EquipmentWindow::draw")
-}
-
-void EquipmentWindow::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "unequip")
- {
- if ((mEquipment == nullptr) || mSelected == -1)
- return;
-
- const Item *const item = mEquipment->getEquipment(mSelected);
- PlayerInfo::unequipItem(item, Sfx_true);
- setSelected(-1);
- }
- else if (eventId.find("tab_") == 0u)
- {
- Button *const button = dynamic_cast<Button*>(event.getSource());
- if (button == nullptr)
- return;
- mSelectedTab = button->getTag();
- updatePage();
- }
- else if (eventId == "playerbox")
- {
- const DragDropSourceT src = dragDrop.getSource();
- if (dragDrop.isEmpty() || (src != DragDropSource::Inventory
- && src != DragDropSource::Equipment))
- {
- return;
- }
- Inventory *const inventory = localPlayer != nullptr
- ? PlayerInfo::getInventory() : nullptr;
- if (inventory == nullptr)
- return;
- Item *const item = inventory->findItem(dragDrop.getItem(),
- dragDrop.getItemColor());
- if (item == nullptr)
- return;
-
- if (dragDrop.getSource() == DragDropSource::Inventory)
- {
- if (item->isEquipment() == Equipm_true)
- {
- if (item->isEquipped() == Equipped_false)
- PlayerInfo::equipItem(item, Sfx_true);
- }
- }
- }
-}
-
-void EquipmentWindow::updatePage()
-{
- EquipmentPage *const page = mPages[mSelectedTab];
- const Visible visible = fromBool(page->showPlayerBox, Visible);
- mPlayerBox->setVisible(visible);
- if (visible == Visible_true)
- {
- mPlayerBox->setDimension(Rect(page->x, page->y,
- page->width, page->height));
- }
- mRedraw = true;
-}
-
-const Item *EquipmentWindow::getItem(const int x, const int y) const
-{
- if (mEquipment == nullptr)
- return nullptr;
-
- int i = 0;
-
- STD_VECTOR<EquipmentBox*> &boxes = mPages[mSelectedTab]->boxes;
- for (STD_VECTOR<EquipmentBox*>::const_iterator it = boxes.begin(),
- it_end = boxes.end(); it != it_end; ++ it, ++ i)
- {
- const EquipmentBox *const box = *it;
- if (box == nullptr)
- continue;
- const Rect tRect(box->x, box->y, mBoxSize, mBoxSize);
-
- if (tRect.isPointInRect(x, y))
- return mEquipment->getEquipment(i);
- }
- return nullptr;
-}
-
-void EquipmentWindow::mousePressed(MouseEvent& event)
-{
- if (mEquipment == nullptr)
- {
- Window::mousePressed(event);
- return;
- }
-
- const int x = event.getX();
- const int y = event.getY();
-
- if (event.getButton() == MouseButton::LEFT)
- {
- if (mForing)
- {
- Window::mousePressed(event);
- return;
- }
- // Checks if any of the presses were in the equip boxes.
- int i = 0;
-
- bool inBox(false);
-
- STD_VECTOR<EquipmentBox*> &boxes = mPages[mSelectedTab]->boxes;
- for (STD_VECTOR<EquipmentBox*>::const_iterator it = boxes.begin(),
- it_end = boxes.end(); it != it_end; ++ it, ++ i)
- {
- const EquipmentBox *const box = *it;
- if (box == nullptr)
- continue;
- const Item *const item = mEquipment->getEquipment(i);
- const Rect tRect(box->x, box->y, mBoxSize, mBoxSize);
-
- if (tRect.isPointInRect(x, y))
- {
- inBox = true;
- if (item != nullptr)
- {
- event.consume();
- setSelected(i);
- dragDrop.dragItem(item, DragDropSource::Equipment);
- return;
- }
- }
- if (inBox)
- return;
- }
- }
- else if (event.getButton() == MouseButton::RIGHT)
- {
- if (const Item *const item = getItem(x, y))
- {
- if (itemPopup != nullptr)
- itemPopup->setVisible(Visible_false);
-
- /* Convert relative to the window coordinates to absolute screen
- * coordinates.
- */
- const int mx = x + getX();
- const int my = y + getY();
- if (popupMenu != nullptr)
- {
- event.consume();
- if (mForing)
- {
- popupMenu->showUndressPopup(mx, my, mBeing, item);
- }
- else
- {
- popupMenu->showPopup(this, mx, my, item,
- InventoryType::Inventory);
- }
- return;
- }
- }
- }
- Window::mousePressed(event);
-}
-
-void EquipmentWindow::mouseReleased(MouseEvent &event)
-{
- Window::mouseReleased(event);
- const DragDropSourceT src = dragDrop.getSource();
- if (dragDrop.isEmpty() || (src != DragDropSource::Inventory
- && src != DragDropSource::Equipment))
- {
- return;
- }
- Inventory *const inventory = localPlayer != nullptr
- ? PlayerInfo::getInventory() : nullptr;
- if (inventory == nullptr)
- return;
-
- Item *const item = inventory->findItem(dragDrop.getItem(),
- dragDrop.getItemColor());
- if (item == nullptr)
- return;
-
- if (dragDrop.getSource() == DragDropSource::Inventory)
- {
- if (item->isEquipment() == Equipm_true)
- {
- if (item->isEquipped() == Equipped_false)
- PlayerInfo::equipItem(item, Sfx_true);
- }
- }
- else if (dragDrop.getSource() == DragDropSource::Equipment)
- {
- if (item->isEquipment() == Equipm_true)
- {
- const int x = event.getX();
- const int y = event.getY();
- STD_VECTOR<EquipmentBox*> &boxes = mPages[mSelectedTab]->boxes;
- for (STD_VECTOR<EquipmentBox*>::const_iterator
- it = boxes.begin(), it_end = boxes.end();
- it != it_end; ++ it)
- {
- const EquipmentBox *const box = *it;
- if (box == nullptr)
- continue;
- const Rect tRect(box->x, box->y, mBoxSize, mBoxSize);
-
- if (tRect.isPointInRect(x, y))
- return;
- }
-
- if (item->isEquipped() == Equipped_true)
- PlayerInfo::unequipItem(item, Sfx_true);
- }
- }
- dragDrop.clear();
- dragDrop.deselect();
-}
-
-// Show ItemTooltip
-void EquipmentWindow::mouseMoved(MouseEvent &event)
-{
- Window::mouseMoved(event);
-
- if (itemPopup == nullptr)
- return;
-
- const int x = event.getX();
- const int y = event.getY();
-
- const Item *const item = getItem(x, y);
-
- if (item != nullptr)
- {
- itemPopup->setItem(item, false);
- itemPopup->position(x + getX(), y + getY());
- }
- else
- {
- itemPopup->setVisible(Visible_false);
- }
-}
-
-// Hide ItemTooltip
-void EquipmentWindow::mouseExited(MouseEvent &event A_UNUSED)
-{
- if (itemPopup != nullptr)
- itemPopup->setVisible(Visible_false);
-}
-
-void EquipmentWindow::setSelected(const int index)
-{
- mSelected = index;
- mRedraw = true;
- if (mUnequip != nullptr)
- mUnequip->setEnabled(mSelected != -1);
- if (itemPopup != nullptr)
- itemPopup->setVisible(Visible_false);
-}
-
-void EquipmentWindow::setBeing(Being *const being)
-{
- mPlayerBox->setPlayer(being);
- mBeing = being;
- if (mEquipment != nullptr)
- delete mEquipment->getBackend();
- delete mEquipment;
- if (being == nullptr)
- {
- mEquipment = nullptr;
- return;
- }
- mEquipment = being->getEquipment();
-}
-
-void EquipmentWindow::updateBeing(Being *const being)
-{
- if (being == mBeing)
- setBeing(being);
-}
-
-void EquipmentWindow::resetBeing(const Being *const being)
-{
- if (being == mBeing)
- setBeing(nullptr);
-}
-
-void EquipmentWindow::fillBoxes()
-{
- XML::Document *const doc = new XML::Document(
- paths.getStringValue("equipmentWindowFile"),
- UseVirtFs_true,
- SkipError_false);
- XmlNodeConstPtr root = doc->rootNode();
- if (root == nullptr)
- {
- delete doc;
- fillDefault();
- return;
- }
-
- if (mImageSet != nullptr)
- mImageSet->decRef();
-
- mImageSet = Theme::getImageSetFromTheme(XML::getProperty(
- root, "image", "equipmentbox.png"), 32, 32);
-
- for_each_xml_child_node(node, root)
- {
- if (xmlNameEqual(node, "page"))
- {
- loadPage(node);
- }
- }
- delete doc;
- if (reportTrue(mPages.empty()))
- fillDefault();
-}
-
-void EquipmentWindow::addDefaultPage()
-{
- if (!mHaveDefaultPage)
- {
- mHaveDefaultPage = true;
- // TRANSLATORS: equipment window tab
- addPage(_("default"));
- }
-}
-
-void EquipmentWindow::loadPage(XmlNodeConstPtr node)
-{
- if (node == nullptr)
- return;
- // TRANSLATORS: unknown equipment page name
- const std::string &name = XML::langProperty(node, "name", _("Unknown"));
- const int page = addPage(name);
- for_each_xml_child_node(childNode, node)
- {
- if (xmlNameEqual(childNode, "playerbox"))
- loadPlayerBox(childNode, page);
- else if (xmlNameEqual(childNode, "slot"))
- loadSlot(childNode, mImageSet, page);
- }
-}
-
-void EquipmentWindow::loadPlayerBox(XmlNodeConstPtr playerBoxNode,
- const int page)
-{
- EquipmentPage *const data = mPages[page];
- data->x = XML::getProperty(playerBoxNode, "x", 50);
- data->y = XML::getProperty(playerBoxNode, "y", 80) + mYPadding;
- data->width = XML::getProperty(playerBoxNode, "width", 74);
- data->height = XML::getProperty(playerBoxNode, "height", 168);
-}
-
-void EquipmentWindow::loadSlot(XmlNodeConstPtr slotNode,
- const ImageSet *const imageset,
- const int page)
-{
- if (imageset == nullptr)
- return;
- const int slot = parseSlotName(XML::getProperty(slotNode, "name", ""));
- if (slot < 0)
- return;
-
- const int x = XML::getProperty(slotNode, "x", 0) + getPadding();
- const int y = XML::getProperty(slotNode, "y", 0)
- + getTitleBarHeight() + mYPadding;
- const int imageIndex = XML::getProperty(slotNode, "image", -1);
- Image *image = nullptr;
-
- if (imageIndex >= 0 && imageIndex < CAST_S32(imageset->size()))
- image = imageset->get(imageIndex);
-
- STD_VECTOR<EquipmentBox*> &boxes = mPages[page]->boxes;
- if (boxes[slot] != nullptr)
- {
- EquipmentBox *const box = boxes[slot];
- box->x = x;
- box->y = y;
- box->image = image;
- }
- else
- {
- boxes[slot] = new EquipmentBox(x, y, image);
- }
- if (x < mMinX)
- mMinX = x;
- if (y < mMinY)
- mMinY = y;
- if (x + mBoxSize > mMaxX)
- mMaxX = x + mBoxSize;
- if (y + mBoxSize > mMaxY)
- mMaxY = y + mBoxSize;
-}
-
-void EquipmentWindow::prepareSlotNames()
-{
- mSlotNames.clear();
- XML::Document doc(paths.getStringValue("equipmentSlotsFile"),
- UseVirtFs_true,
- SkipError_false);
- XmlNodeConstPtrConst root = doc.rootNode();
- if (root == nullptr)
- return;
-
- for_each_xml_child_node(slotNode, root)
- {
- if (!xmlNameEqual(slotNode, "slot"))
- continue;
- const std::string name = XML::getProperty(slotNode, "name", "");
- if (name.empty())
- {
- reportAlways("Empty slot name detected.");
- continue;
- }
-
- const int slot = XML::getProperty(slotNode, "slot", -1);
- if (slot < 0 || slot >= BOX_COUNT)
- {
- reportAlways("Wrong slot id '%d' for slot with name '%s'",
- slot,
- name.c_str());
- continue;
- }
- mSlotNames[name] = slot;
- }
-}
-
-int EquipmentWindow::parseSlotName(const std::string &name)
-{
- StringIntMapCIter it = mSlotNames.find(name);
- if (it != mSlotNames.end())
- return (*it).second;
- return -1;
-}
-
-void EquipmentWindow::fillDefault()
-{
- if (mImageSet != nullptr)
- mImageSet->decRef();
-
- addDefaultPage();
- mImageSet = Theme::getImageSetFromTheme(
- "equipmentbox.png", 32, 32);
-
- addBox(0, 90, 40, 0); // torso
- addBox(1, 8, 78, 1); // gloves
- addBox(2, 70, 0, 2); // hat
- addBox(3, 50, 253, 3); // pants
- addBox(4, 90, 253, 4); // boots
- addBox(5, 8, 213, 5); // FREE
- addBox(6, 129, 213, 6); // wings
- addBox(7, 50, 40, 5); // scarf
- addBox(8, 8, 168, 7); // weapon
- addBox(9, 129, 168, 8); // shield
- addBox(10, 129, 78, 9); // ammo
- addBox(11, 8, 123, 5); // amulet
- addBox(12, 129, 123, 5); // ring
-}
-
-void EquipmentWindow::addBox(const int idx, int x, int y, const int imageIndex)
-{
- Image *image = nullptr;
-
- if ((mImageSet != nullptr) && imageIndex >= 0 && imageIndex
- < CAST_S32(mImageSet->size()))
- {
- image = mImageSet->get(imageIndex);
- }
-
- x += getPadding();
- y += getTitleBarHeight() + mYPadding;
- STD_VECTOR<EquipmentBox*> &boxes = mPages[0]->boxes;
- boxes[idx] = new EquipmentBox(x, y, image);
-
- if (x < mMinX)
- mMinX = x;
- if (y < mMinY)
- mMinY = y;
- if (x + mBoxSize > mMaxX)
- mMaxX = x + mBoxSize;
- if (y + mBoxSize > mMaxY)
- mMaxY = y + mBoxSize;
-}
-
-void EquipmentWindow::recalcSize()
-{
- mMaxX += mMinX;
- mMaxY += mMinY;
- mTabs->setWidth(mMaxX);
- mMaxY += mUnequip->getHeight() - mYPadding;
- setDefaultSize(mMaxX, mMaxY, ImagePosition::CENTER);
-}
-
-int EquipmentWindow::addPage(const std::string &name)
-{
- EquipmentPage *const page = new EquipmentPage;
- mPages.push_back(page);
- STD_VECTOR<EquipmentBox*> &boxes = page->boxes;
-
- boxes.reserve(BOX_COUNT);
- for (int f = 0; f < BOX_COUNT; f ++)
- boxes.push_back(nullptr);
-
- mTabs->addButton(name, name, false);
- return CAST_S32(mPages.size()) - 1;
-}
diff --git a/src/gui/windows/equipmentwindow.h b/src/gui/windows/equipmentwindow.h
deleted file mode 100644
index b36174095..000000000
--- a/src/gui/windows/equipmentwindow.h
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_EQUIPMENTWINDOW_H
-#define GUI_WINDOWS_EQUIPMENTWINDOW_H
-
-#include "equipment.h"
-#include "localconsts.h"
-
-#include "gui/widgets/window.h"
-
-#include "utils/stringmap.h"
-#include "utils/xml.h"
-
-#include "listeners/actionlistener.h"
-
-class Being;
-class Button;
-class Image;
-class ImageSet;
-class Item;
-class PlayerBox;
-class TabStrip;
-
-struct EquipmentPage;
-
-/**
- * Equipment dialog.
- *
- * \ingroup Interface
- */
-class EquipmentWindow final : public Window,
- public ActionListener
-{
- public:
- /**
- * Constructor.
- */
- EquipmentWindow(Equipment *const equipment, Being *const being,
- const bool foring = false);
-
- A_DELETE_COPY(EquipmentWindow)
-
- /**
- * Destructor.
- */
- ~EquipmentWindow();
-
- void postInit() override final;
-
- /**
- * Draws the equipment window.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void action(const ActionEvent &event) override final;
-
- void mousePressed(MouseEvent& event) override final;
-
- const Item* getEquipment(const int i) const A_WARN_UNUSED
- {
- return mEquipment != nullptr ?
- mEquipment->getEquipment(i) : nullptr;
- }
-
- void setBeing(Being *const being);
-
- void updateBeing(Being *const being);
-
- void resetBeing(const Being *const being);
-
- void mouseExited(MouseEvent &event) override final;
-
- void mouseMoved(MouseEvent &event) override final;
-
- void mouseReleased(MouseEvent &event) override final;
-
- void recalcSize();
-
- static void prepareSlotNames();
-
- private:
- const Item *getItem(const int x, const int y) const A_WARN_UNUSED;
-
- void setSelected(const int index);
-
- void fillBoxes();
-
- void fillDefault();
-
- void updatePage();
-
- int addPage(const std::string &name);
-
- void addDefaultPage();
-
- void addBox(const int idx, int x, int y, const int imageIndex);
-
- void loadWindow(XmlNodeConstPtrConst windowNode);
-
- void loadPage(XmlNodeConstPtr node);
-
- void loadPlayerBox(XmlNodeConstPtr playerBoxNode, const int page);
-
- void loadSlot(XmlNodeConstPtr slotNode,
- const ImageSet *const imageset,
- const int page);
-
- static int parseSlotName(const std::string &name) A_WARN_UNUSED;
-
- static StringIntMap mSlotNames;
-
- Equipment *mEquipment;
-
- PlayerBox *mPlayerBox A_NONNULLPOINTER;
- Button *mUnequip A_NONNULLPOINTER;
-
- ImageSet *mImageSet;
- Being *mBeing;
- Image *mSlotBackground;
- Image *mSlotHighlightedBackground;
- ImageCollection *mVertexes A_NONNULLPOINTER;
- STD_VECTOR<EquipmentPage*> mPages;
- TabStrip *mTabs;
- Color mHighlightColor;
- Color mBorderColor;
- Color mLabelsColor;
- Color mLabelsColor2;
- int mSelected; /**< Index of selected item. */
- int mItemPadding;
- int mBoxSize;
- int mButtonPadding;
- int mMinX;
- int mMinY;
- int mMaxX;
- int mMaxY;
- int mYPadding;
- int mSelectedTab;
- bool mForing;
- bool mHaveDefaultPage;
-};
-
-extern EquipmentWindow *equipmentWindow;
-extern EquipmentWindow *beingEquipmentWindow;
-
-#endif // GUI_WINDOWS_EQUIPMENTWINDOW_H
diff --git a/src/gui/windows/helpwindow.cpp b/src/gui/windows/helpwindow.cpp
deleted file mode 100644
index 1cfb30e2b..000000000
--- a/src/gui/windows/helpwindow.cpp
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/helpwindow.h"
-
-#include "configuration.h"
-
-#include "enums/gui/layouttype.h"
-
-#include "fs/paths.h"
-
-#include "fs/virtfs/tools.h"
-
-#include "gui/gui.h"
-
-#include "gui/windows/setupwindow.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/staticbrowserbox.h"
-#include "gui/widgets/layout.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "input/inputmanager.h"
-
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-#include "utils/process.h"
-
-#include "utils/translation/podict.h"
-#include "utils/translation/translationmanager.h"
-
-#include "debug.h"
-
-HelpWindow *helpWindow = nullptr;
-
-HelpWindow::HelpWindow() :
- // TRANSLATORS: help window name
- Window(_("Help"), Modal_false, nullptr, "help.xml"),
- LinkHandler(),
- ActionListener(),
- // TRANSLATORS: help window. button.
- mDYKButton(new Button(this, _("Did you know..."), "DYK", this)),
- mBrowserBox(new StaticBrowserBox(this, Opaque_true,
- "browserbox.xml")),
- mScrollArea(new ScrollArea(this, mBrowserBox,
- Opaque_true, "help_background.xml")),
- mTagFileMap()
-{
- setMinWidth(300);
- setMinHeight(220);
- setContentSize(455, 350);
- setWindowName("Help");
- setCloseButton(true);
- setResizable(true);
- setStickyButtonLock(true);
-
- if (setupWindow != nullptr)
- setupWindow->registerWindowForReset(this);
-
- setDefaultSize(500, 400, ImagePosition::CENTER);
-
- mBrowserBox->setOpaque(Opaque_false);
-
- mBrowserBox->setLinkHandler(this);
- if (gui != nullptr)
- mBrowserBox->setFont(gui->getHelpFont());
- mBrowserBox->setProcessVars(true);
- mBrowserBox->setEnableImages(true);
- mBrowserBox->setEnableKeys(true);
- mBrowserBox->setEnableTabs(true);
-
- place(4, 3, mDYKButton);
- place(0, 0, mScrollArea, 5, 3).setPadding(3);
-
- Layout &layout = getLayout();
- layout.setRowHeight(0, LayoutType::SET);
-
- loadWindowState();
- loadTags();
- enableVisibleSound(true);
- widgetResized(Event(nullptr));
-}
-
-void HelpWindow::action(const ActionEvent &event)
-{
- if (event.getId() == "DYK")
- inputManager.executeAction(InputAction::WINDOW_DIDYOUKNOW);
-}
-
-void HelpWindow::handleLink(const std::string &link,
- MouseEvent *const event A_UNUSED)
-{
- if (!strStartWith(link, "http://") && !strStartWith(link, "https://"))
- {
- // need use separate variable
- const std::string helpFile = link;
- loadHelp(helpFile);
- }
- else
- {
- openBrowser(link);
- }
-}
-
-void HelpWindow::loadHelp(const std::string &helpFile)
-{
- if (!checkPath(helpFile))
- return;
- mBrowserBox->clearRows();
- loadFile("header");
- loadFile(helpFile);
- loadFile("footer");
- mScrollArea->setVerticalScrollAmount(0);
- mBrowserBox->updateHeight();
- setVisible(Visible_true);
-}
-
-void HelpWindow::loadHelpSimple(const std::string &helpFile)
-{
- if (!checkPath(helpFile))
- return;
- mBrowserBox->clearRows();
- loadFile(helpFile);
- mScrollArea->setVerticalScrollAmount(0);
- mBrowserBox->updateHeight();
- setVisible(Visible_true);
-}
-
-void HelpWindow::loadFile(std::string file)
-{
- trim(file);
- std::string helpPath = branding.getStringValue("helpPath");
- if (helpPath.empty())
- helpPath = paths.getStringValue("help");
-
- StringVect lines;
- TranslationManager::translateFile(pathJoin(helpPath, file).append(".txt"),
- translator, lines);
-
- for (size_t i = 0, sz = lines.size(); i < sz; ++i)
- mBrowserBox->addRow(lines[i]);
-}
-
-void HelpWindow::loadTags()
-{
- std::string helpPath = branding.getStringValue("tagsPath");
- if (helpPath.empty())
- helpPath = paths.getStringValue("tags");
-
- StringVect filesVect;
- VirtFs::getFilesInDir(helpPath, filesVect, ".idx");
- FOR_EACH (StringVectCIter, itVect, filesVect)
- {
- StringVect lines;
- VirtFs::loadTextFile(*itVect, lines);
- FOR_EACH (StringVectCIter, it, lines)
- {
- const std::string &str = *it;
- const size_t idx = str.find('|');
- if (idx != std::string::npos)
- mTagFileMap[str.substr(idx + 1)].insert(str.substr(0, idx));
- }
- }
-}
-
-void HelpWindow::search(const std::string &text0)
-{
- std::string text = text0;
- trim(text);
- toLower(text);
- if (mTagFileMap.find(text) == mTagFileMap.end())
- {
- loadHelp("searchnotfound");
- }
- else
- {
- const HelpNames &names = mTagFileMap[text];
- if (names.size() == 1)
- {
- loadHelp(*names.begin());
- }
- else
- {
- if (translator == nullptr)
- return;
- mBrowserBox->clearRows();
- loadFile("header");
- loadFile("searchmany");
- FOR_EACH (HelpNamesCIter, it, names)
- {
- const char *const str = (*it).c_str();
- mBrowserBox->addRow(strprintf(" -> @@%s|%s@@", str,
- translator->getChar(str)));
- }
- loadFile("footer");
- mScrollArea->setVerticalScrollAmount(0);
- mBrowserBox->updateHeight();
- setVisible(Visible_true);
- }
- }
-}
diff --git a/src/gui/windows/helpwindow.h b/src/gui/windows/helpwindow.h
deleted file mode 100644
index 2fb2407d9..000000000
--- a/src/gui/windows/helpwindow.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_HELPWINDOW_H
-#define GUI_WINDOWS_HELPWINDOW_H
-
-#include "gui/widgets/linkhandler.h"
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-
-#include "localconsts.h"
-
-class Button;
-class ScrollArea;
-class StaticBrowserBox;
-
-typedef std::set<std::string> HelpNames;
-typedef HelpNames::const_iterator HelpNamesCIter;
-typedef std::map<std::string, HelpNames> HelpTagsMap;
-
-/**
- * The help window.
- */
-class HelpWindow final : public Window,
- public LinkHandler,
- public ActionListener
-{
- public:
- /**
- * Constructor.
- */
- HelpWindow();
-
- A_DELETE_COPY(HelpWindow)
-
- /**
- * Called when receiving actions from the widgets.
- */
- void action(const ActionEvent &event) override final;
-
- /**
- * Handles link action.
- */
- void handleLink(const std::string &link,
- MouseEvent *const event A_UNUSED) override final;
-
- /**
- * Loads help in the dialog.
- */
- void loadHelp(const std::string &helpFile);
-
- void loadHelpSimple(const std::string &helpFile);
-
- /**
- * Seach for given text in tags.
- */
- void search(const std::string &text);
-
- private:
- void loadTags();
-
- void loadFile(std::string file);
-
- Button *mDYKButton A_NONNULLPOINTER;
- StaticBrowserBox *mBrowserBox A_NONNULLPOINTER;
- ScrollArea *mScrollArea A_NONNULLPOINTER;
- HelpTagsMap mTagFileMap;
-};
-
-extern HelpWindow *helpWindow;
-
-#endif // GUI_WINDOWS_HELPWINDOW_H
diff --git a/src/gui/windows/insertcarddialog.cpp b/src/gui/windows/insertcarddialog.cpp
deleted file mode 100644
index 590df6aba..000000000
--- a/src/gui/windows/insertcarddialog.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/insertcarddialog.h"
-
-#include "gui/models/shopitems.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/shoplistbox.h"
-
-#include "net/inventoryhandler.h"
-
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include "resources/item/shopitem.h"
-
-#include "debug.h"
-
-InsertCardDialog::InsertCardDialog(const int itemIndex,
- const Item *const item) :
- SellDialog(IsSell_false, Advanced_false),
- mItemIndex(itemIndex)
-{
- // TRANSLATORS: insert card dialog name
- setWindowName(_("Insert card"));
- if (item != nullptr)
- {
- // TRANSLATORS: insert card dialog name
- setCaption(strprintf(_("Insert card %s"),
- item->getName().c_str()));
- }
- else
- {
- // TRANSLATORS: insert card dialog name
- setCaption(strprintf(_("Insert card %s"),
- ""));
- }
-}
-
-void InsertCardDialog::initButtons()
-{
- // TRANSLATORS: insert card dialog button
- mSellButton->setCaption(_("Insert"));
- mSellButton->adjustSize();
- mShopItems->setMergeDuplicates(false);
-}
-
-void InsertCardDialog::sellAction(const ActionEvent &event A_UNUSED)
-{
- if (mAmountItems <= 0 || mAmountItems > mMaxItems)
- return;
-
- const int selectedItem = mShopItemList->getSelected();
- const ShopItem *const item = mShopItems->at(selectedItem);
- if (item == nullptr)
- return;
- inventoryHandler->insertCard(mItemIndex, item->getInvIndex());
- scheduleDelete();
-}
diff --git a/src/gui/windows/insertcarddialog.h b/src/gui/windows/insertcarddialog.h
deleted file mode 100644
index ba46022a2..000000000
--- a/src/gui/windows/insertcarddialog.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_INSERTCARDDIALOG_H
-#define GUI_WINDOWS_INSERTCARDDIALOG_H
-
-#include "gui/widgets/selldialog.h"
-
-class InsertCardDialog final : public SellDialog
-{
- public:
- /**
- * Constructor.
- *
- * @see Window::Window
- */
- InsertCardDialog(const int itemIndex,
- const Item *const item);
-
- A_DELETE_COPY(InsertCardDialog)
-
- protected:
- void initButtons() override final;
- void sellAction(const ActionEvent &event) override final;
-
- private:
- int mItemIndex;
-};
-
-#endif // GUI_WINDOWS_INSERTCARDDIALOG_H
diff --git a/src/gui/windows/inventorywindow.cpp b/src/gui/windows/inventorywindow.cpp
deleted file mode 100644
index f973f250f..000000000
--- a/src/gui/windows/inventorywindow.cpp
+++ /dev/null
@@ -1,1083 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/inventorywindow.h"
-
-#include "configuration.h"
-
-#include "being/playerinfo.h"
-
-#include "enums/gui/layouttype.h"
-
-#include "input/inputmanager.h"
-
-#include "gui/gui.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/models/sortlistmodelinv.h"
-
-#include "gui/popups/itempopup.h"
-#include "gui/popups/popupmenu.h"
-#include "gui/popups/textpopup.h"
-
-#include "gui/windows/confirmdialog.h"
-#include "gui/windows/itemamountwindow.h"
-#include "gui/windows/npcdialog.h"
-#include "gui/windows/setupwindow.h"
-#include "gui/windows/tradewindow.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/dropdown.h"
-#include "gui/widgets/itemcontainer.h"
-#include "gui/widgets/layout.h"
-#include "gui/widgets/progressbar.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/tabstrip.h"
-#include "gui/widgets/textfield.h"
-#include "gui/widgets/windowcontainer.h"
-
-#include "listeners/insertcardlistener.h"
-
-#include "net/npchandler.h"
-
-#include "resources/iteminfo.h"
-
-#include "resources/db/unitsdb.h"
-
-#include "resources/item/item.h"
-
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-
-#include "debug.h"
-
-InventoryWindow *inventoryWindow = nullptr;
-InventoryWindow *storageWindow = nullptr;
-InventoryWindow *cartWindow = nullptr;
-InventoryWindow::WindowList InventoryWindow::invInstances;
-InsertCardListener insertCardListener;
-
-InventoryWindow::InventoryWindow(Inventory *const inventory) :
- Window("Inventory", Modal_false, nullptr, "inventory.xml"),
- ActionListener(),
- KeyListener(),
- SelectionListener(),
- InventoryListener(),
- AttributeListener(),
- mInventory(inventory),
- mItems(new ItemContainer(this, mInventory)),
- mUseButton(nullptr),
- mDropButton(nullptr),
- mOutfitButton(nullptr),
- mShopButton(nullptr),
- mCartButton(nullptr),
- mEquipmentButton(nullptr),
- mStoreButton(nullptr),
- mRetrieveButton(nullptr),
- mInvCloseButton(nullptr),
- mWeightBar(nullptr),
- mSlotsBar(new ProgressBar(this, 0.0F, 100, 0,
- ProgressColorId::PROG_INVY_SLOTS,
- "slotsprogressbar.xml", "slotsprogressbar_fill.xml")),
- mFilter(nullptr),
- mSortModel(new SortListModelInv),
- mSortDropDown(new DropDown(this, mSortModel, false,
- Modal_false, this, "sort")),
- mNameFilter(new TextField(this, "", LoseFocusOnTab_true,
- this, "namefilter", true)),
- mSortDropDownCell(nullptr),
- mNameFilterCell(nullptr),
- mFilterCell(nullptr),
- mSlotsBarCell(nullptr),
- mSplit(false),
- mCompactMode(false)
-{
- mSlotsBar->setColor(getThemeColor(ThemeColorId::SLOTS_BAR),
- getThemeColor(ThemeColorId::SLOTS_BAR_OUTLINE));
-
- if (inventory != nullptr)
- {
- setCaption(gettext(inventory->getName().c_str()));
- setWindowName(inventory->getName());
- switch (inventory->getType())
- {
- case InventoryType::Inventory:
- case InventoryType::Trade:
- case InventoryType::Npc:
- case InventoryType::Vending:
- case InventoryType::MailEdit:
- case InventoryType::MailView:
- case InventoryType::Craft:
- case InventoryType::TypeEnd:
- default:
- mSortDropDown->setSelected(config.getIntValue(
- "inventorySortOrder"));
- break;
- case InventoryType::Storage:
- mSortDropDown->setSelected(config.getIntValue(
- "storageSortOrder"));
- break;
- case InventoryType::Cart:
- mSortDropDown->setSelected(config.getIntValue(
- "cartSortOrder"));
- break;
- };
- }
- else
- {
- // TRANSLATORS: inventory window name
- setCaption(_("Inventory"));
- setWindowName("Inventory");
- mSortDropDown->setSelected(0);
- }
-
- if ((setupWindow != nullptr) &&
- (inventory != nullptr) &&
- inventory->getType() != InventoryType::Storage)
- {
- setupWindow->registerWindowForReset(this);
- }
-
- setResizable(true);
- setCloseButton(true);
- setSaveVisible(true);
- setStickyButtonLock(true);
-
- if (mainGraphics->mWidth > 600)
- setDefaultSize(450, 310, ImagePosition::CENTER);
- else
- setDefaultSize(387, 307, ImagePosition::CENTER);
- setMinWidth(310);
- setMinHeight(179);
- addKeyListener(this);
-
- mItems->addSelectionListener(this);
-
- const int size = config.getIntValue("fontSize");
- mFilter = new TabStrip(this, "filter_" + getWindowName(), size + 16);
- mFilter->addActionListener(this);
- mFilter->setActionEventId("tag_");
- mFilter->setSelectable(false);
-
- StringVect tags = ItemDB::getTags();
- const size_t sz = tags.size();
- for (size_t f = 0; f < sz; f ++)
- mFilter->addButton(tags[f], tags[f], false);
-
- if (mInventory == nullptr)
- {
- invInstances.push_back(this);
- return;
- }
-
- ScrollArea *const invenScroll = new ScrollArea(this, mItems,
- fromBool(getOptionBool("showbackground"), Opaque),
- "inventory_background.xml");
- invenScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
-
- switch (mInventory->getType())
- {
- case InventoryType::Inventory:
- {
- // TRANSLATORS: inventory button
- const std::string equip = _("Equip");
- // TRANSLATORS: inventory button
- const std::string use = _("Use");
- // TRANSLATORS: inventory button
- const std::string unequip = _("Unequip");
-
- std::string longestUseString = getFont()->getWidth(equip) >
- getFont()->getWidth(use) ? equip : use;
-
- if (getFont()->getWidth(longestUseString) <
- getFont()->getWidth(unequip))
- {
- longestUseString = unequip;
- }
-
- mUseButton = new Button(this, longestUseString, "use", this);
- // TRANSLATORS: inventory button
- mDropButton = new Button(this, _("Drop..."), "drop", this);
- // TRANSLATORS: inventory outfits button
- mOutfitButton = new Button(this, _("O"), "outfit", this);
- // TRANSLATORS: inventory cart button
- mCartButton = new Button(this, _("C"), "cart", this);
- // TRANSLATORS: inventory shop button
- mShopButton = new Button(this, _("S"), "shop", this);
- // TRANSLATORS: inventory equipment button
- mEquipmentButton = new Button(this, _("E"), "equipment", this);
- mWeightBar = new ProgressBar(this, 0.0F, 100, 0,
- ProgressColorId::PROG_WEIGHT,
- "weightprogressbar.xml", "weightprogressbar_fill.xml");
- mWeightBar->setColor(getThemeColor(ThemeColorId::WEIGHT_BAR),
- getThemeColor(ThemeColorId::WEIGHT_BAR_OUTLINE));
-
- // TRANSLATORS: outfits button tooltip
- mOutfitButton->setDescription(_("Outfits"));
- // TRANSLATORS: cart button tooltip
- mCartButton->setDescription(_("Cart"));
- // TRANSLATORS: shop button tooltip
- mShopButton->setDescription(_("Shop"));
- // TRANSLATORS: equipment button tooltip
- mEquipmentButton->setDescription(_("Equipment"));
-
- place(0, 0, mWeightBar, 4);
- mSlotsBarCell = &place(4, 0, mSlotsBar, 4);
- mSortDropDownCell = &place(8, 0, mSortDropDown, 3);
-
- mFilterCell = &place(0, 1, mFilter, 10).setPadding(3);
- mNameFilterCell = &place(8, 1, mNameFilter, 3);
-
- place(0, 2, invenScroll, 11).setPadding(3);
- place(0, 3, mUseButton);
- place(1, 3, mDropButton);
- ContainerPlacer placer = getPlacer(10, 3);
- placer(0, 0, mShopButton);
- placer(1, 0, mOutfitButton);
- placer(2, 0, mCartButton);
- placer(3, 0, mEquipmentButton);
-
- updateWeight();
- break;
- }
-
- case InventoryType::Storage:
- {
- // TRANSLATORS: storage button
- mStoreButton = new Button(this, _("Store"), "store", this);
- // TRANSLATORS: storage button
- mRetrieveButton = new Button(this, _("Retrieve"),
- "retrieve", this);
- // TRANSLATORS: storage button
- mInvCloseButton = new Button(this, _("Close"), "close", this);
-
- mSlotsBarCell = &place(0, 0, mSlotsBar, 6);
- mSortDropDownCell = &place(6, 0, mSortDropDown, 1);
-
- mFilterCell = &place(0, 1, mFilter, 7).setPadding(3);
- mNameFilterCell = &place(6, 1, mNameFilter, 1);
-
- place(0, 2, invenScroll, 7, 4);
- place(0, 6, mStoreButton);
- place(1, 6, mRetrieveButton);
- place(6, 6, mInvCloseButton);
- break;
- }
-
- case InventoryType::Cart:
- {
- // TRANSLATORS: storage button
- mStoreButton = new Button(this, _("Store"), "store", this);
- // TRANSLATORS: storage button
- mRetrieveButton = new Button(this, _("Retrieve"),
- "retrieve", this);
- // TRANSLATORS: storage button
- mInvCloseButton = new Button(this, _("Close"), "close", this);
-
- mWeightBar = new ProgressBar(this, 0.0F, 100, 0,
- ProgressColorId::PROG_WEIGHT,
- "weightprogressbar.xml", "weightprogressbar_fill.xml");
- mWeightBar->setColor(getThemeColor(ThemeColorId::WEIGHT_BAR),
- getThemeColor(ThemeColorId::WEIGHT_BAR_OUTLINE));
-
- mSlotsBarCell = &place(3, 0, mSlotsBar, 3);
- mSortDropDownCell = &place(6, 0, mSortDropDown, 1);
-
- mFilterCell = &place(0, 1, mFilter, 7).setPadding(3);
- mNameFilterCell = &place(6, 1, mNameFilter, 1);
-
- place(0, 0, mWeightBar, 3);
- place(0, 2, invenScroll, 7, 4);
- place(0, 6, mStoreButton);
- place(1, 6, mRetrieveButton);
- place(6, 6, mInvCloseButton);
- break;
- }
-
- default:
- case InventoryType::Trade:
- case InventoryType::Npc:
- case InventoryType::Vending:
- case InventoryType::MailEdit:
- case InventoryType::MailView:
- case InventoryType::Craft:
- case InventoryType::TypeEnd:
- break;
- };
-
- Layout &layout = getLayout();
- layout.setRowHeight(2, LayoutType::SET);
-
- mInventory->addInventoyListener(this);
-
- invInstances.push_back(this);
-
- if (inventory->isMainInventory())
- {
- updateDropButton();
- }
- else
- {
- if (!invInstances.empty())
- invInstances.front()->updateDropButton();
- }
-
- loadWindowState();
- enableVisibleSound(true);
-}
-
-void InventoryWindow::postInit()
-{
- Window::postInit();
- slotsChanged(mInventory);
-
- mItems->setSortType(mSortDropDown->getSelected());
- widgetResized(Event(nullptr));
- if (mInventory != nullptr &&
- mInventory->getType() == InventoryType::Storage)
- {
- setVisible(Visible_true);
- }
-}
-
-InventoryWindow::~InventoryWindow()
-{
- invInstances.remove(this);
- if (mInventory != nullptr)
- mInventory->removeInventoyListener(this);
- if (!invInstances.empty())
- invInstances.front()->updateDropButton();
-
- mSortDropDown->hideDrop(false);
- delete2(mSortModel);
-}
-
-void InventoryWindow::storeSortOrder() const
-{
- if (mInventory != nullptr)
- {
- switch (mInventory->getType())
- {
- case InventoryType::Inventory:
- case InventoryType::Trade:
- case InventoryType::Npc:
- case InventoryType::Vending:
- case InventoryType::MailEdit:
- case InventoryType::MailView:
- case InventoryType::Craft:
- case InventoryType::TypeEnd:
- default:
- config.setValue("inventorySortOrder",
- mSortDropDown->getSelected());
- break;
- case InventoryType::Storage:
- config.setValue("storageSortOrder",
- mSortDropDown->getSelected());
- break;
- case InventoryType::Cart:
- config.setValue("cartSortOrder",
- mSortDropDown->getSelected());
- break;
- };
- }
-}
-
-void InventoryWindow::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "outfit")
- {
- inputManager.executeAction(InputAction::WINDOW_OUTFIT);
- }
- else if (eventId == "shop")
- {
- inputManager.executeAction(InputAction::WINDOW_SHOP);
- }
- else if (eventId == "equipment")
- {
- inputManager.executeAction(InputAction::WINDOW_EQUIPMENT);
- }
- else if (eventId == "cart")
- {
- inputManager.executeAction(InputAction::WINDOW_CART);
- }
- else if (eventId == "close")
- {
- close();
- }
- else if (eventId == "store")
- {
- if (inventoryWindow == nullptr || !inventoryWindow->isWindowVisible())
- return;
-
- Item *const item = inventoryWindow->getSelectedItem();
-
- if (item == nullptr)
- return;
-
- if (storageWindow != nullptr)
- {
- ItemAmountWindow::showWindow(ItemAmountWindowUsage::StoreAdd,
- this, item);
- }
- else if ((cartWindow != nullptr) && cartWindow->isWindowVisible())
- {
- ItemAmountWindow::showWindow(ItemAmountWindowUsage::CartAdd,
- this, item);
- }
- }
- else if (eventId == "sort")
- {
- mItems->setSortType(mSortDropDown->getSelected());
- storeSortOrder();
- return;
- }
- else if (eventId == "namefilter")
- {
- mItems->setName(mNameFilter->getText());
- mItems->updateMatrix();
- }
- else if (eventId.find("tag_") == 0u)
- {
- std::string tagName = event.getId().substr(4);
- mItems->setFilter(ItemDB::getTagId(tagName));
- return;
- }
-
- Item *const item = mItems->getSelectedItem();
-
- if (item == nullptr)
- return;
-
- if (eventId == "use")
- {
- PlayerInfo::useEquipItem(item, 0, Sfx_true);
- }
- if (eventId == "equip")
- {
- PlayerInfo::useEquipItem2(item, 0, Sfx_true);
- }
- else if (eventId == "drop")
- {
- if (isStorageActive())
- {
- inventoryHandler->moveItem2(InventoryType::Inventory,
- item->getInvIndex(),
- item->getQuantity(),
- InventoryType::Storage);
- }
- else if ((cartWindow != nullptr) && cartWindow->isWindowVisible())
- {
- inventoryHandler->moveItem2(InventoryType::Inventory,
- item->getInvIndex(),
- item->getQuantity(),
- InventoryType::Cart);
- }
- else
- {
- if (PlayerInfo::isItemProtected(item->getId()))
- return;
-
- if (inputManager.isActionActive(InputAction::STOP_ATTACK))
- {
- PlayerInfo::dropItem(item, item->getQuantity(), Sfx_true);
- }
- else
- {
- ItemAmountWindow::showWindow(ItemAmountWindowUsage::ItemDrop,
- this, item);
- }
- }
- }
- else if (eventId == "split")
- {
- ItemAmountWindow::showWindow(ItemAmountWindowUsage::ItemSplit,
- this, item,
- (item->getQuantity() - 1));
- }
- else if (eventId == "retrieve")
- {
- if (storageWindow != nullptr)
- {
- ItemAmountWindow::showWindow(ItemAmountWindowUsage::StoreRemove,
- this, item);
- }
- else if ((cartWindow != nullptr) && cartWindow->isWindowVisible())
- {
- ItemAmountWindow::showWindow(ItemAmountWindowUsage::CartRemove,
- this, item);
- }
- }
-}
-
-Item *InventoryWindow::getSelectedItem() const
-{
- return mItems->getSelectedItem();
-}
-
-void InventoryWindow::unselectItem()
-{
- mItems->selectNone();
-}
-
-void InventoryWindow::widgetHidden(const Event &event)
-{
- Window::widgetHidden(event);
- if (itemPopup != nullptr)
- itemPopup->setVisible(Visible_false);
-}
-
-void InventoryWindow::mouseClicked(MouseEvent &event)
-{
- Window::mouseClicked(event);
-
- const int clicks = event.getClickCount();
-
- if (clicks == 2 && (gui != nullptr))
- gui->resetClickCount();
-
- const bool mod = (isStorageActive() &&
- inputManager.isActionActive(InputAction::STOP_ATTACK));
-
- const bool mod2 = (tradeWindow != nullptr &&
- tradeWindow->isWindowVisible() &&
- inputManager.isActionActive(InputAction::STOP_ATTACK));
-
- if (mInventory != nullptr)
- {
- if (!mod && !mod2 && event.getButton() == MouseButton::RIGHT)
- {
- Item *const item = mItems->getSelectedItem();
-
- if (item == nullptr)
- return;
-
- /* Convert relative to the window coordinates to absolute screen
- * coordinates.
- */
- const int mx = event.getX() + getX();
- const int my = event.getY() + getY();
-
- if (popupMenu != nullptr)
- {
- popupMenu->showPopup(this,
- mx, my,
- item,
- mInventory->getType());
- }
- }
- }
- else
- {
- return;
- }
-
- if (event.getButton() == MouseButton::LEFT ||
- event.getButton() == MouseButton::RIGHT)
- {
- Item *const item = mItems->getSelectedItem();
-
- if (item == nullptr)
- return;
-
- if (mod)
- {
- if (mInventory->isMainInventory())
- {
- if (event.getButton() == MouseButton::RIGHT)
- {
- ItemAmountWindow::showWindow(
- ItemAmountWindowUsage::StoreAdd,
- inventoryWindow,
- item);
- }
- else
- {
- inventoryHandler->moveItem2(InventoryType::Inventory,
- item->getInvIndex(),
- item->getQuantity(),
- InventoryType::Storage);
- }
- }
- else
- {
- if (event.getButton() == MouseButton::RIGHT)
- {
- ItemAmountWindow::showWindow(
- ItemAmountWindowUsage::StoreRemove,
- inventoryWindow,
- item);
- }
- else
- {
- inventoryHandler->moveItem2(InventoryType::Storage,
- item->getInvIndex(),
- item->getQuantity(),
- InventoryType::Inventory);
- }
- }
- }
- else if (mod2 && mInventory->isMainInventory())
- {
- if (PlayerInfo::isItemProtected(item->getId()))
- return;
- if (event.getButton() == MouseButton::RIGHT)
- {
- ItemAmountWindow::showWindow(ItemAmountWindowUsage::TradeAdd,
- tradeWindow, item);
- }
- else
- {
- if (tradeWindow != nullptr)
- tradeWindow->tradeItem(item, item->getQuantity(), true);
- }
- }
- else if (clicks == 2)
- {
- if (mInventory->isMainInventory())
- {
- if (isStorageActive())
- {
- ItemAmountWindow::showWindow(
- ItemAmountWindowUsage::StoreAdd,
- inventoryWindow, item);
- }
- else if (tradeWindow != nullptr &&
- tradeWindow->isWindowVisible())
- {
- if (PlayerInfo::isItemProtected(item->getId()))
- return;
- ItemAmountWindow::showWindow(
- ItemAmountWindowUsage::TradeAdd,
- tradeWindow, item);
- }
- else
- {
- PlayerInfo::useEquipItem(item, 0, Sfx_true);
- }
- }
- else
- {
- if (isStorageActive())
- {
- ItemAmountWindow::showWindow(
- ItemAmountWindowUsage::StoreRemove,
- inventoryWindow, item);
- }
- }
- }
- }
-}
-
-void InventoryWindow::mouseMoved(MouseEvent &event)
-{
- Window::mouseMoved(event);
- if (textPopup == nullptr)
- return;
-
- const Widget *const src = event.getSource();
- if (src == nullptr)
- {
- textPopup->hide();
- return;
- }
- const int x = event.getX();
- const int y = event.getY();
- const Rect &rect = mDimension;
- if (src == mSlotsBar || src == mWeightBar)
- {
- // TRANSLATORS: money label
- textPopup->show(rect.x + x, rect.y + y, strprintf(_("Money: %s"),
- UnitsDb::formatCurrency(PlayerInfo::getAttribute(
- Attributes::MONEY)).c_str()));
- }
- else
- {
- const Button *const btn = dynamic_cast<const Button *>(src);
- if (btn == nullptr)
- {
- textPopup->hide();
- return;
- }
- const std::string text = btn->getDescription();
- if (!text.empty())
- textPopup->show(x + rect.x, y + rect.y, text);
- }
-}
-
-void InventoryWindow::mouseExited(MouseEvent &event A_UNUSED)
-{
- textPopup->hide();
-}
-
-void InventoryWindow::keyPressed(KeyEvent &event)
-{
- if (event.getActionId() == InputAction::GUI_MOD)
- mSplit = true;
-}
-
-void InventoryWindow::keyReleased(KeyEvent &event)
-{
- if (event.getActionId() == InputAction::GUI_MOD)
- mSplit = false;
-}
-
-void InventoryWindow::valueChanged(const SelectionEvent &event A_UNUSED)
-{
- if ((mInventory == nullptr) || !mInventory->isMainInventory())
- return;
-
- Item *const item = mItems->getSelectedItem();
-
- if (mSplit && (item != nullptr) && inventoryHandler->
- canSplit(mItems->getSelectedItem()))
- {
- ItemAmountWindow::showWindow(ItemAmountWindowUsage::ItemSplit,
- this, item, item->getQuantity() - 1);
- }
- updateButtons(item);
-}
-
-void InventoryWindow::updateButtons(const Item *item)
-{
- if ((mInventory == nullptr) || !mInventory->isMainInventory())
- return;
-
- const Item *const selectedItem = mItems->getSelectedItem();
- if ((item != nullptr) && selectedItem != item)
- return;
-
- if (item == nullptr)
- item = selectedItem;
-
- if ((item == nullptr) || item->getQuantity() == 0)
- {
- if (mUseButton != nullptr)
- mUseButton->setEnabled(false);
- if (mDropButton != nullptr)
- mDropButton->setEnabled(false);
- return;
- }
-
- if (mDropButton != nullptr)
- mDropButton->setEnabled(true);
-
- if (mUseButton != nullptr)
- {
- const ItemInfo &info = item->getInfo();
- const std::string &str = (item->isEquipment() == Equipm_true
- && item->isEquipped() == Equipped_true)
- ? info.getUseButton2() : info.getUseButton();
- if (str.empty())
- {
- mUseButton->setEnabled(false);
- // TRANSLATORS: default use button name
- mUseButton->setCaption(_("Use"));
- }
- else
- {
- mUseButton->setEnabled(true);
- mUseButton->setCaption(str);
- }
- }
-
- updateDropButton();
-}
-
-void InventoryWindow::close()
-{
- if (mInventory == nullptr)
- {
- Window::close();
- return;
- }
-
- switch (mInventory->getType())
- {
- case InventoryType::Inventory:
- case InventoryType::Cart:
- setVisible(Visible_false);
- break;
-
- case InventoryType::Storage:
- if (inventoryHandler != nullptr)
- {
- inventoryHandler->closeStorage();
- inventoryHandler->forgotStorage();
- }
- scheduleDelete();
- break;
-
- default:
- case InventoryType::Trade:
- case InventoryType::Npc:
- case InventoryType::Vending:
- case InventoryType::MailEdit:
- case InventoryType::MailView:
- case InventoryType::Craft:
- case InventoryType::TypeEnd:
- break;
- }
-}
-
-void InventoryWindow::updateWeight()
-{
- if ((mInventory == nullptr) || (mWeightBar == nullptr))
- return;
- const InventoryTypeT type = mInventory->getType();
- if (type != InventoryType::Inventory &&
- type != InventoryType::Cart)
- {
- return;
- }
-
- const bool isInv = type == InventoryType::Inventory;
- const int total = PlayerInfo::getAttribute(isInv
- ? Attributes::TOTAL_WEIGHT : Attributes::CART_TOTAL_WEIGHT);
- const int max = PlayerInfo::getAttribute(isInv
- ? Attributes::MAX_WEIGHT : Attributes::CART_MAX_WEIGHT);
-
- if (max <= 0)
- return;
-
- // Adjust progress bar
- mWeightBar->setProgress(static_cast<float>(total)
- / static_cast<float>(max));
- mWeightBar->setText(strprintf("%s/%s",
- UnitsDb::formatWeight(total).c_str(),
- UnitsDb::formatWeight(max).c_str()));
-}
-
-void InventoryWindow::slotsChanged(const Inventory *const inventory)
-{
- if (inventory == mInventory)
- {
- const int usedSlots = mInventory->getNumberOfSlotsUsed();
- const int maxSlots = mInventory->getSize();
-
- if (maxSlots != 0)
- {
- mSlotsBar->setProgress(static_cast<float>(usedSlots)
- / static_cast<float>(maxSlots));
- }
-
- mSlotsBar->setText(strprintf("%d/%d", usedSlots, maxSlots));
- mItems->updateMatrix();
- }
-}
-
-void InventoryWindow::updateDropButton()
-{
- if (mDropButton == nullptr)
- return;
-
- if (isStorageActive() ||
- (cartWindow != nullptr && cartWindow->isWindowVisible()))
- {
- // TRANSLATORS: inventory button
- mDropButton->setCaption(_("Store"));
- }
- else
- {
- const Item *const item = mItems->getSelectedItem();
- if ((item != nullptr) && item->getQuantity() > 1)
- {
- // TRANSLATORS: inventory button
- mDropButton->setCaption(_("Drop..."));
- }
- else
- {
- // TRANSLATORS: inventory button
- mDropButton->setCaption(_("Drop"));
- }
- }
-}
-
-bool InventoryWindow::isInputFocused() const
-{
- return (mNameFilter != nullptr) && mNameFilter->isFocused();
-}
-
-bool InventoryWindow::isAnyInputFocused()
-{
- FOR_EACH (WindowList::const_iterator, it, invInstances)
- {
- if (((*it) != nullptr) && (*it)->isInputFocused())
- return true;
- }
- return false;
-}
-
-InventoryWindow *InventoryWindow::getFirstVisible()
-{
- std::set<Widget*> list;
- FOR_EACH (WindowList::const_iterator, it, invInstances)
- {
- if (((*it) != nullptr) && (*it)->isWindowVisible())
- list.insert(*it);
- }
- return dynamic_cast<InventoryWindow*>(
- windowContainer->findFirstWidget(list));
-}
-
-void InventoryWindow::nextTab()
-{
- const InventoryWindow *const window = getFirstVisible();
- if (window != nullptr)
- window->mFilter->nextTab();
-}
-
-void InventoryWindow::prevTab()
-{
- const InventoryWindow *const window = getFirstVisible();
- if (window != nullptr)
- window->mFilter->prevTab();
-}
-
-void InventoryWindow::widgetResized(const Event &event)
-{
- Window::widgetResized(event);
-
- if (mInventory == nullptr)
- return;
- const InventoryTypeT type = mInventory->getType();
- if (type != InventoryType::Inventory &&
- type != InventoryType::Cart)
- {
- return;
- }
-
- if (getWidth() < 600)
- {
- if (!mCompactMode)
- {
- mNameFilter->setVisible(Visible_false);
- mNameFilterCell->setType(LayoutCell::NONE);
- mFilterCell->setWidth(mFilterCell->getWidth() + 3);
- mCompactMode = true;
- }
- }
- else if (mCompactMode)
- {
- mNameFilter->setVisible(Visible_true);
- mNameFilterCell->setType(LayoutCell::WIDGET);
- mFilterCell->setWidth(mFilterCell->getWidth() - 3);
- mCompactMode = false;
- }
-}
-
-void InventoryWindow::setVisible(Visible visible)
-{
- if (visible == Visible_false)
- mSortDropDown->hideDrop();
- Window::setVisible(visible);
-}
-
-void InventoryWindow::unsetInventory()
-{
- if (mInventory != nullptr)
- {
- mInventory->removeInventoyListener(this);
- if (mItems != nullptr)
- mItems->unsetInventory();
- }
- mInventory = nullptr;
-}
-
-void InventoryWindow::attributeChanged(const AttributesT id,
- const int64_t oldVal A_UNUSED,
- const int64_t newVal A_UNUSED)
-{
- if (id == Attributes::TOTAL_WEIGHT
- || id == Attributes::MAX_WEIGHT
- || id == Attributes::CART_TOTAL_WEIGHT
- || id == Attributes::CART_MAX_WEIGHT)
- {
- updateWeight();
- }
-}
-
-void InventoryWindow::combineItems(const int index1,
- const int index2)
-{
- if (mInventory == nullptr)
- return;
- const Item *item1 = mInventory->getItem(index1);
- if (item1 == nullptr)
- return;
- const Item *item2 = mInventory->getItem(index2);
- if (item2 == nullptr)
- return;
-
- if (item1->getType() != ItemType::Card)
- {
- const Item *tmpItem = item1;
- item1 = item2;
- item2 = tmpItem;
- }
-
- ConfirmDialog *const confirmDlg = CREATEWIDGETR(ConfirmDialog,
- // TRANSLATORS: question dialog title
- _("Insert card request"),
- // TRANSLATORS: question dialog message
- strprintf(_("Insert %s into %s?"),
- item1->getName().c_str(),
- item2->getName().c_str()),
- SOUND_REQUEST,
- false,
- Modal_true);
- insertCardListener.itemIndex = item2->getInvIndex();
- insertCardListener.cardIndex = item1->getInvIndex();
- confirmDlg->addActionListener(&insertCardListener);
-}
-
-void InventoryWindow::moveItemToCraft(const int craftSlot)
-{
- if (npcHandler == nullptr)
- return;
-
- Item *const item = mItems->getSelectedItem();
- if (item == nullptr)
- return;
-
- NpcDialog *const dialog = npcHandler->getCurrentNpcDialog();
- if ((dialog != nullptr) &&
- dialog->getInputState() == NpcInputState::ITEM_CRAFT)
- {
- if (item->getQuantity() > 1
- && !inputManager.isActionActive(InputAction::STOP_ATTACK))
- {
- ItemAmountWindow::showWindow(ItemAmountWindowUsage::CraftAdd,
- npcHandler->getCurrentNpcDialog(),
- item,
- 0,
- craftSlot);
- }
- else
- {
- dialog->addCraftItem(item, 1, craftSlot);
- }
- }
-}
diff --git a/src/gui/windows/inventorywindow.h b/src/gui/windows/inventorywindow.h
deleted file mode 100644
index 81cfd38e4..000000000
--- a/src/gui/windows/inventorywindow.h
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_INVENTORYWINDOW_H
-#define GUI_WINDOWS_INVENTORYWINDOW_H
-
-#include "resources/inventory/inventory.h"
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/attributelistener.h"
-#include "listeners/inventorylistener.h"
-#include "listeners/keylistener.h"
-#include "listeners/selectionlistener.h"
-
-class Button;
-class DropDown;
-class InventoryWindow;
-class Item;
-class ItemContainer;
-class LayoutCell;
-class ProgressBar;
-class SortListModelInv;
-class TabStrip;
-class TextField;
-
-extern InventoryWindow *inventoryWindow;
-extern InventoryWindow *storageWindow;
-extern InventoryWindow *cartWindow;
-
-/**
- * Inventory dialog.
- *
- * \ingroup Interface
- */
-class InventoryWindow final : public Window,
- public ActionListener,
- public KeyListener,
- public SelectionListener,
- public InventoryListener,
- public AttributeListener
-{
- public:
- /**
- * Constructor.
- */
- explicit InventoryWindow(Inventory *const inventory);
-
- A_DELETE_COPY(InventoryWindow)
-
- /**
- * Destructor.
- */
- ~InventoryWindow();
-
- void postInit() override final;
-
- void storeSortOrder() const;
-
- /**
- * Called when receiving actions from the widgets.
- */
- void action(const ActionEvent &event) override final;
-
- /**
- * Returns the selected item.
- */
- Item* getSelectedItem() const A_WARN_UNUSED;
-
- /**
- * Unselect item
- */
- void unselectItem();
-
- /**
- * Handles closing of the window
- */
- void widgetHidden(const Event &event) override final;
-
- /**
- * Handles the mouse clicks.
- */
- void mouseClicked(MouseEvent &event) override final;
-
- /**
- * Handles the key presses.
- */
- void keyPressed(KeyEvent &event) override final;
-
- /**
- * Handles the key releases.
- */
- void keyReleased(KeyEvent &event) override final;
-
- /**
- * Updates labels to currently selected item.
- */
- void valueChanged(const SelectionEvent &event) override final;
-
- /**
- * Closes the Storage Window, as well as telling the server that the
- * window has been closed.
- */
- void close() override final;
-
- void slotsChanged(const Inventory *const inventory) override final;
-
- bool isMainInventory() const A_WARN_UNUSED
- {
- return mInventory != nullptr ?
- mInventory->isMainInventory() : false;
- }
-
- /**
- * Returns true if any instances exist.
- */
- static bool isStorageActive() A_WARN_UNUSED
- { return storageWindow != nullptr; }
-
- void updateDropButton();
-
- void updateButtons(const Item *item = nullptr);
-
- bool isInputFocused() const A_WARN_UNUSED;
-
- void widgetResized(const Event &event) override final;
-
- void mouseMoved(MouseEvent &event) override final;
-
- void mouseExited(MouseEvent &event) override final;
-
- void setVisible(Visible visible) override final;
-
- void unsetInventory();
-
- void attributeChanged(const AttributesT id,
- const int64_t oldVal,
- const int64_t newVal) override final;
-
- void combineItems(const int index1,
- const int index2);
-
- void moveItemToCraft(const int craftSlot);
-
- static bool isAnyInputFocused();
-
- static InventoryWindow *getFirstVisible();
-
- static void nextTab();
-
- static void prevTab();
-
- private:
- /**
- * Updates the weight bar.
- */
- void updateWeight();
-
- typedef std::list<InventoryWindow*> WindowList;
- static WindowList invInstances;
-
- Inventory *mInventory;
- ItemContainer *mItems A_NONNULLPOINTER;
-
- Button *mUseButton;
- Button *mDropButton;
- Button *mOutfitButton;
- Button *mShopButton;
- Button *mCartButton;
- Button *mEquipmentButton;
- Button *mStoreButton;
- Button *mRetrieveButton;
- Button *mInvCloseButton;
-
- ProgressBar *mWeightBar;
- ProgressBar *mSlotsBar A_NONNULLPOINTER;
- TabStrip *mFilter;
- SortListModelInv *mSortModel A_NONNULLPOINTER;
- DropDown *mSortDropDown A_NONNULLPOINTER;
- TextField *mNameFilter A_NONNULLPOINTER;
- LayoutCell *mSortDropDownCell;
- LayoutCell *mNameFilterCell;
- LayoutCell *mFilterCell;
- LayoutCell *mSlotsBarCell;
-
- bool mSplit;
- bool mCompactMode;
-};
-
-#endif // GUI_WINDOWS_INVENTORYWINDOW_H
diff --git a/src/gui/windows/itemamountwindow.cpp b/src/gui/windows/itemamountwindow.cpp
deleted file mode 100644
index 100ad748a..000000000
--- a/src/gui/windows/itemamountwindow.cpp
+++ /dev/null
@@ -1,504 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/itemamountwindow.h"
-
-#include "settings.h"
-
-#include "being/playerinfo.h"
-
-#include "input/keyboardconfig.h"
-
-#include "gui/viewport.h"
-
-#include "gui/models/itemsmodel.h"
-
-#include "gui/popups/itempopup.h"
-
-#include "gui/windows/maileditwindow.h"
-#include "gui/windows/npcdialog.h"
-#include "gui/windows/shopwindow.h"
-#include "gui/windows/tradewindow.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/dropdown.h"
-#include "gui/widgets/icon.h"
-#include "gui/widgets/inttextfield.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/slider.h"
-
-#include "net/inventoryhandler.h"
-#include "net/mail2handler.h"
-#include "net/npchandler.h"
-
-#include "resources/item/item.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#ifndef USE_SDL2
-#include <cmath>
-#endif // USE_SDL2
-
-#include "debug.h"
-
-void ItemAmountWindow::finish(Item *const item,
- const int amount,
- const int price,
- const ItemAmountWindowUsageT usage)
-{
- if (item == nullptr)
- return;
- switch (usage)
- {
- case ItemAmountWindowUsage::TradeAdd:
- if (tradeWindow != nullptr)
- tradeWindow->tradeItem(item, amount);
- break;
- case ItemAmountWindowUsage::ItemDrop:
- PlayerInfo::dropItem(item, amount, Sfx_true);
- break;
- case ItemAmountWindowUsage::ItemSplit:
- inventoryHandler->splitItem(item, amount);
- break;
- case ItemAmountWindowUsage::StoreAdd:
- inventoryHandler->moveItem2(InventoryType::Inventory,
- item->getInvIndex(), amount, InventoryType::Storage);
- break;
- case ItemAmountWindowUsage::StoreRemove:
- inventoryHandler->moveItem2(InventoryType::Storage,
- item->getInvIndex(), amount, InventoryType::Inventory);
- break;
- case ItemAmountWindowUsage::ShopBuyAdd:
- if (shopWindow != nullptr)
- shopWindow->addBuyItem(item, amount, price);
- break;
- case ItemAmountWindowUsage::ShopSellAdd:
- if (shopWindow != nullptr)
- shopWindow->addSellItem(item, amount, price);
- break;
- case ItemAmountWindowUsage::CartAdd:
- inventoryHandler->moveItem2(InventoryType::Inventory,
- item->getInvIndex(), amount, InventoryType::Cart);
- break;
- case ItemAmountWindowUsage::CartRemove:
- inventoryHandler->moveItem2(InventoryType::Cart,
- item->getInvIndex(), amount, InventoryType::Inventory);
- break;
- case ItemAmountWindowUsage::MailAdd:
- if (settings.enableNewMailSystem)
- {
- mail2Handler->addItem(item, amount);
- }
- else if (mailEditWindow != nullptr)
- {
- mailEditWindow->addItem(item, amount);
- }
- break;
- case ItemAmountWindowUsage::CraftAdd:
- {
- NpcDialog *const dialog = npcHandler->getCurrentNpcDialog();
- if (dialog != nullptr)
- dialog->addCraftItem(item, amount, price); // price as slot
- break;
- }
- default:
- break;
- }
-}
-
-ItemAmountWindow::ItemAmountWindow(const ItemAmountWindowUsageT usage,
- Window *const parent,
- Item *const item,
- const int maxRange) :
- Window("", Modal_false, parent, "amount.xml"),
- ActionListener(),
- KeyListener(),
- mItemAmountTextField(new IntTextField(this, 1)),
- mItemPriceTextField(nullptr),
- mGPLabel(nullptr),
- mItem(item),
- mItemIcon(new Icon(this, item != nullptr ? item->getImage() : nullptr)),
- mItemAmountSlide(new Slider(this, 1.0, maxRange, 1.0)),
- mItemPriceSlide(nullptr),
- mItemDropDown(nullptr),
- mItemsModal(nullptr),
- mPrice(0),
- mMax(maxRange),
- mUsage(usage),
- mEnabledKeyboard(keyboard.isEnabled())
-{
- if (mItem == nullptr)
- return;
-
- if (usage == ItemAmountWindowUsage::ShopBuyAdd)
- mMax = 10000;
- else if (mMax == 0)
- mMax = mItem->getQuantity();
-
- keyboard.setEnabled(false);
-
- mItemAmountTextField->setRange(1, mMax);
- mItemAmountTextField->setWidth(35);
- mItemAmountTextField->addKeyListener(this);
-
- mItemAmountSlide->setHeight(10);
- mItemAmountSlide->setActionEventId("slide");
- mItemAmountSlide->addActionListener(this);
-
- if (mUsage == ItemAmountWindowUsage::ShopBuyAdd ||
- mUsage == ItemAmountWindowUsage::ShopSellAdd)
- {
- mItemPriceTextField = new IntTextField(this, 1);
- mItemPriceTextField->setRange(1, 10000000);
- mItemPriceTextField->setWidth(35);
- mItemPriceTextField->addKeyListener(this);
-
- mItemPriceSlide = new Slider(this, 1.0, 10000000, 1.0);
- mItemPriceSlide->setHeight(10);
- mItemPriceSlide->setActionEventId("slidePrice");
- mItemPriceSlide->addActionListener(this);
-
- mGPLabel = new Label(this, " GP");
- }
-
- if (mUsage == ItemAmountWindowUsage::ShopBuyAdd)
- {
- mItemsModal = new ItemsModal;
- mItemDropDown = new DropDown(this, mItemsModal);
- mItemDropDown->setActionEventId("itemType");
- mItemDropDown->addActionListener(this);
- }
-
- // Buttons
- // TRANSLATORS: item amount window button
- Button *const minusAmountButton = new Button(this, _("-"), "dec", this);
- // TRANSLATORS: item amount window button
- Button *const plusAmountButton = new Button(this, _("+"), "inc", this);
- // TRANSLATORS: item amount window button
- Button *const okButton = new Button(this, _("OK"), "ok", this);
- // TRANSLATORS: item amount window button
- Button *const cancelButton = new Button(this, _("Cancel"), "cancel", this);
- // TRANSLATORS: item amount window button
- Button *const addAllButton = new Button(this, _("All"), "all", this);
-
- minusAmountButton->adjustSize();
- minusAmountButton->setWidth(plusAmountButton->getWidth());
-
- // Set positions
- ContainerPlacer placer;
- placer = getPlacer(0, 0);
- int n = 0;
- if (mUsage == ItemAmountWindowUsage::ShopBuyAdd)
- {
- placer(0, n, mItemDropDown, 8);
- n++;
- }
- placer(1, n, minusAmountButton);
- placer(2, n, mItemAmountTextField, 3);
- placer(5, n, plusAmountButton);
- placer(6, n, addAllButton);
-
- placer(0, n, mItemIcon, 1, 3);
- placer(1, n + 1, mItemAmountSlide, 7);
-
- if (mUsage == ItemAmountWindowUsage::ShopBuyAdd ||
- mUsage == ItemAmountWindowUsage::ShopSellAdd)
- {
- Button *const minusPriceButton = new Button(
- // TRANSLATORS: item amount window button
- this, _("-"), "decPrice", this);
- Button *const plusPriceButton = new Button(
- // TRANSLATORS: item amount window button
- this, _("+"), "incPrice", this);
- minusPriceButton->adjustSize();
- minusPriceButton->setWidth(plusPriceButton->getWidth());
-
- placer(1, n + 2, minusPriceButton);
- placer(2, n + 2, mItemPriceTextField, 3);
- placer(5, n + 2, plusPriceButton);
- placer(6, n + 2, mGPLabel);
-
- placer(1, n + 3, mItemPriceSlide, 7);
- placer(4, n + 5, cancelButton);
- placer(5, n + 5, okButton);
- }
- else
- {
- placer(4, n + 2, cancelButton);
- placer(5, n + 2, okButton);
- }
-
- reflowLayout(225, 0);
-
- resetAmount();
-
- switch (usage)
- {
- case ItemAmountWindowUsage::TradeAdd:
- // TRANSLATORS: amount window message
- setCaption(_("Select amount of items to trade."));
- break;
- case ItemAmountWindowUsage::ItemDrop:
- // TRANSLATORS: amount window message
- setCaption(_("Select amount of items to drop."));
- break;
- case ItemAmountWindowUsage::StoreAdd:
- // TRANSLATORS: amount window message
- setCaption(_("Select amount of items to store."));
- break;
- case ItemAmountWindowUsage::MailAdd:
- // TRANSLATORS: amount window message
- setCaption(_("Select amount of items to send."));
- break;
- case ItemAmountWindowUsage::CraftAdd:
- // TRANSLATORS: amount window message
- setCaption(_("Select amount of items to craft."));
- break;
- case ItemAmountWindowUsage::CartAdd:
- // TRANSLATORS: amount window message
- setCaption(_("Select amount of items to store to cart."));
- break;
- case ItemAmountWindowUsage::StoreRemove:
- // TRANSLATORS: amount window message
- setCaption(_("Select amount of items to retrieve."));
- break;
- case ItemAmountWindowUsage::CartRemove:
- // TRANSLATORS: amount window message
- setCaption(_("Select amount of items to retrieve from cart."));
- break;
- case ItemAmountWindowUsage::ItemSplit:
- // TRANSLATORS: amount window message
- setCaption(_("Select amount of items to split."));
- break;
- case ItemAmountWindowUsage::ShopBuyAdd:
- // TRANSLATORS: amount window message
- setCaption(_("Add to buy shop."));
- break;
- case ItemAmountWindowUsage::ShopSellAdd:
- // TRANSLATORS: amount window message
- setCaption(_("Add to sell shop."));
- break;
- default:
- // TRANSLATORS: amount window message
- setCaption(_("Unknown."));
- break;
- }
-
- setLocationRelativeTo(getParentWindow());
-
- mItemIcon->addMouseListener(this);
-}
-
-void ItemAmountWindow::postInit()
-{
- Window::postInit();
- setVisible(fromBool(mItem, Visible));
-}
-
-ItemAmountWindow::~ItemAmountWindow()
-{
- delete2(mItemsModal);
-}
-
-// Show ItemTooltip
-void ItemAmountWindow::mouseMoved(MouseEvent &event)
-{
- Window::mouseMoved(event);
-
- if ((viewport == nullptr) || (itemPopup == nullptr))
- return;
-
- if (event.getSource() == mItemIcon)
- {
- itemPopup->setItem(mItem, false);
- itemPopup->position(viewport->mMouseX, viewport->mMouseY);
- }
-}
-
-// Hide ItemTooltip
-void ItemAmountWindow::mouseExited(MouseEvent &event A_UNUSED)
-{
- if (itemPopup != nullptr)
- itemPopup->setVisible(Visible_false);
-}
-
-void ItemAmountWindow::resetAmount()
-{
- mItemAmountTextField->setValue(1);
-}
-
-void ItemAmountWindow::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "cancel")
- {
- close();
- return;
- }
- else if (eventId == "ok")
- {
- if (mItemPriceTextField != nullptr)
- {
- finish(mItem,
- mItemAmountTextField->getValue(),
- mItemPriceTextField->getValue(),
- mUsage);
- }
- else
- {
- if (mUsage == ItemAmountWindowUsage::CraftAdd)
- {
- finish(mItem,
- mItemAmountTextField->getValue(),
- mPrice,
- mUsage);
- }
- else
- {
- finish(mItem,
- mItemAmountTextField->getValue(),
- 0,
- mUsage);
- }
- }
- close();
- return;
- }
- else if (eventId == "itemType")
- {
- if ((mItemDropDown == nullptr) || (mItemsModal == nullptr))
- return;
-
- const int id = ItemDB::get(mItemsModal->getElementAt(
- mItemDropDown->getSelected())).getId();
-
- mItem = new Item(id,
- ItemType::Unknown,
- 10000,
- 0,
- ItemColor_one,
- Identified_true,
- Damaged_true,
- Favorite_false,
- Equipm_false,
- Equipped_false);
-
- if (mUsage == ItemAmountWindowUsage::ShopBuyAdd)
- mMax = 10000;
- else if (mMax == 0)
- mMax = mItem->getQuantity();
-
- mItemIcon->setImage(mItem->getImage());
- }
-
- int amount = mItemAmountTextField->getValue();
-
- if (eventId == "inc" && amount < mMax)
- amount++;
- else if (eventId == "dec" && amount > 1)
- amount--;
- else if (eventId == "all")
- amount = mMax;
- else if (eventId == "slide")
- amount = CAST_S32(mItemAmountSlide->getValue());
- mItemAmountTextField->setValue(amount);
- mItemAmountSlide->setValue(amount);
-
- if ((mItemPriceTextField != nullptr) && (mItemPriceSlide != nullptr))
- {
- if (mPrice > 7)
- mPrice = 7;
- else if (mPrice < 0)
- mPrice = 0;
-
- int price = 0;
-
- if (eventId == "incPrice")
- {
- mPrice++;
- price = CAST_S32(pow(10.0, mPrice));
- mItemPriceTextField->setValue(price);
- mItemPriceSlide->setValue(price);
- }
- else if (eventId == "decPrice")
- {
- mPrice--;
- price = CAST_S32(pow(10.0, mPrice));
- mItemPriceTextField->setValue(price);
- mItemPriceSlide->setValue(price);
- }
- else if (eventId == "slidePrice")
- {
- price = CAST_S32(mItemPriceSlide->getValue());
- if (price != 0)
- mPrice = CAST_S32(log(static_cast<float>(price)));
- else
- mPrice = 0;
- mItemPriceTextField->setValue(price);
- mItemPriceSlide->setValue(price);
- }
- }
-}
-
-void ItemAmountWindow::close()
-{
- keyboard.setEnabled(mEnabledKeyboard);
- scheduleDelete();
-}
-
-void ItemAmountWindow::keyReleased(KeyEvent &event A_UNUSED)
-{
- mItemAmountSlide->setValue(mItemAmountTextField->getValue());
-}
-
-void ItemAmountWindow::showWindow(const ItemAmountWindowUsageT usage,
- Window *const parent,
- Item *const item,
- int maxRange,
- int tag)
-{
- if (item == nullptr)
- return;
-
- if (maxRange == 0)
- maxRange = item->getQuantity();
-
- if (usage != ItemAmountWindowUsage::ShopBuyAdd &&
- usage != ItemAmountWindowUsage::ShopSellAdd &&
- maxRange <= 1)
- {
- if (usage == ItemAmountWindowUsage::CraftAdd)
- finish(item, maxRange, tag, usage);
- else
- finish(item, maxRange, 0, usage);
- }
- else
- {
- ItemAmountWindow *const window = CREATEWIDGETR(ItemAmountWindow,
- usage, parent, item, maxRange);
- if (usage == ItemAmountWindowUsage::CraftAdd)
- window->mPrice = tag;
- }
-}
diff --git a/src/gui/windows/itemamountwindow.h b/src/gui/windows/itemamountwindow.h
deleted file mode 100644
index 97f539ac9..000000000
--- a/src/gui/windows/itemamountwindow.h
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_ITEMAMOUNTWINDOW_H
-#define GUI_WINDOWS_ITEMAMOUNTWINDOW_H
-
-#include "gui/widgets/window.h"
-
-#include "enums/gui/itemamountwindowusage.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/keylistener.h"
-
-class DropDown;
-class Icon;
-class IntTextField;
-class Item;
-class ItemsModal;
-class Label;
-class Slider;
-
-/**
- * Window used for selecting the amount of items to drop, trade or split.
- *
- * \ingroup Interface
- */
-class ItemAmountWindow final : public Window,
- public ActionListener,
- public KeyListener
-{
- public:
- A_DELETE_COPY(ItemAmountWindow)
-
- void postInit() override final;
-
- /**
- * Called when receiving actions from widget.
- */
- void action(const ActionEvent &event) override final;
-
- /**
- * Sets default amount value.
- */
- void resetAmount();
-
- // MouseListener
- void mouseMoved(MouseEvent &event) override final;
-
- void mouseExited(MouseEvent &event) override final;
-
- /**
- * Schedules the Item Amount window for deletion.
- */
- void close() override final;
-
- void keyReleased(KeyEvent &event) override final;
-
- /**
- * Creates the dialog, or bypass it if there aren't enough items.
- */
- static void showWindow(const ItemAmountWindowUsageT usage,
- Window *const parent,
- Item *const item,
- int maxRange = 0,
- const int tag = 0);
-
- ~ItemAmountWindow();
-
-#ifndef UNITTESTS
- private:
-#endif // UNITTESTS
- static void finish(Item *const item,
- const int amount,
- const int price,
- const ItemAmountWindowUsageT usage);
-
- ItemAmountWindow(const ItemAmountWindowUsageT usage,
- Window *const parent,
- Item *const item,
- const int maxRange = 0);
-
- /**< Item amount caption. */
- IntTextField *mItemAmountTextField A_NONNULLPOINTER;
- /**< Item price caption. */
- IntTextField *mItemPriceTextField;
- Label *mGPLabel;
- Item *mItem;
- Icon *mItemIcon A_NONNULLPOINTER;
-
- /**
- * Item Amount buttons.
- */
- Slider *mItemAmountSlide A_NONNULLPOINTER;
- Slider *mItemPriceSlide;
- DropDown *mItemDropDown;
- ItemsModal *mItemsModal;
-
- int mPrice;
- int mMax;
- ItemAmountWindowUsageT mUsage;
- bool mEnabledKeyboard;
-};
-
-#endif // GUI_WINDOWS_ITEMAMOUNTWINDOW_H
diff --git a/src/gui/windows/killstats.cpp b/src/gui/windows/killstats.cpp
deleted file mode 100644
index 80efb4b36..000000000
--- a/src/gui/windows/killstats.cpp
+++ /dev/null
@@ -1,479 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/killstats.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layoutcell.h"
-
-#include "gui/windows/setupwindow.h"
-
-#include "client.h"
-#include "game.h"
-
-#include "being/localplayer.h"
-#include "being/playerinfo.h"
-
-#include "utils/gettext.h"
-
-#ifdef WIN32
-#include <sys/time.h>
-#endif // WIN32
-
-#include "debug.h"
-
-KillStats *killStats = nullptr;
-
-KillStats::KillStats() :
- // TRANSLATORS: kill stats window name
- Window(_("Kill stats"), Modal_false, nullptr, "killstats.xml"),
- ActionListener(),
- AttributeListener(),
- mKillTimer(0),
- // TRANSLATORS: kill stats window button
- mResetButton(new Button(this, _("Reset stats"), "reset", this)),
- // TRANSLATORS: kill stats window button
- mTimerButton(new Button(this, _("Reset timer"), "timer", this)),
- mLine1(nullptr),
- mLine2(nullptr),
- mLine3(nullptr),
- // TRANSLATORS: kill stats window label
- mLine4(new Label(this, strprintf(_("Kills: %s, total exp: %s"),
- "?", "?"))),
- // TRANSLATORS: kill stats window label
- mLine5(new Label(this, strprintf(_("Avg Exp: %s"), "?"))),
- // TRANSLATORS: kill stats window label
- mLine6(new Label(this, strprintf(_("No. of avg mob to next level: %s"),
- "?"))),
- // TRANSLATORS: kill stats window label
- mLine7(new Label(this, strprintf(_("Kills/Min: %s, Exp/Min: %s"),
- "?", "?"))),
- mExpSpeed1Label(new Label(this, strprintf(ngettext(
- // TRANSLATORS: kill stats window label
- "Exp speed per %d min: %s", "Exp speed per %d min: %s", 1), 1, "?"))),
- mExpTime1Label(new Label(this, strprintf(ngettext(
- "Time for next level per %d min: %s",
- "Time for next level per %d min: %s", 1), 1, "?"))),
- mExpSpeed5Label(new Label(this, strprintf(ngettext(
- "Exp speed per %d min: %s", "Exp speed per %d min: %s", 5), 5, "?"))),
- mExpTime5Label(new Label(this, strprintf(ngettext(
- "Time for next level per %d min: %s",
- "Time for next level per %d min: %s", 5), 5, "?"))),
- mExpSpeed15Label(new Label(this, strprintf(ngettext(
- "Exp speed per %d min: %s", "Exp speed per %d min: %s", 15),
- 15, "?"))),
- mExpTime15Label(new Label(this, strprintf(ngettext(
- "Time for next level per %d min: %s",
- "Time for next level per %d min: %s", 15), 15, "?"))),
- // TRANSLATORS: kill stats window label
- mLastKillExpLabel(new Label(this, strprintf("%s ?", _("Last kill exp:")))),
- mKillCounter(0),
- mExpCounter(0),
- mKillTCounter(0),
- mExpTCounter(0),
- m1minExpTime(0),
- m1minExpNum(0),
- m1minSpeed(0),
- m5minExpTime(0),
- m5minExpNum(0),
- m5minSpeed(0),
- m15minExpTime(0),
- m15minExpNum(0),
- m15minSpeed(0)
-{
- setWindowName("Kill stats");
- setCloseButton(true);
- setResizable(true);
- setSaveVisible(true);
- setStickyButtonLock(true);
- setDefaultSize(250, 250, 350, 300);
-
- if (setupWindow != nullptr)
- setupWindow->registerWindowForReset(this);
-
- const int64_t xp(PlayerInfo::getAttribute64(Attributes::PLAYER_EXP));
- int64_t xpNextLevel(PlayerInfo::getAttribute64(
- Attributes::PLAYER_EXP_NEEDED));
-
- if (xpNextLevel == 0)
- xpNextLevel = 1;
-
- // TRANSLATORS: kill stats window label
- mLine1 = new Label(this, strprintf(_("Level: %d at %f%%"),
- localPlayer->getLevel(), static_cast<double>(xp)
- / static_cast<double>(xpNextLevel) * 100.0));
-
- const std::string strXp = toString(CAST_U64(xp));
- const std::string strXpNextLevel = toString(CAST_U64(xpNextLevel));
- const std::string strXpLeft = toString(CAST_U64(xpNextLevel - xp));
- const std::string strXpPercent = toString(CAST_U64(xpNextLevel / 100));
- // TRANSLATORS: kill stats window label
- mLine2 = new Label(this, strprintf(_("Exp: %s/%s Left: %s"),
- strXp.c_str(),
- strXpNextLevel.c_str(),
- strXpLeft.c_str()));
-
- // TRANSLATORS: kill stats window label
- mLine3 = new Label(this, strprintf(_("1%% = %s exp, avg mob for 1%%: %s"),
- strXpPercent.c_str(),
- "?"));
-
- place(0, 0, mLine1, 6).setPadding(0);
- place(0, 1, mLine2, 6).setPadding(0);
- place(0, 2, mLine3, 6).setPadding(0);
- place(0, 3, mLine4, 6).setPadding(0);
- place(0, 4, mLine5, 6).setPadding(0);
- place(0, 5, mLine6, 6).setPadding(0);
- place(0, 6, mLine7, 6).setPadding(0);
-
- place(0, 7, mLastKillExpLabel, 6).setPadding(0);
- place(0, 8, mExpSpeed1Label, 6).setPadding(0);
- place(0, 9, mExpTime1Label, 6).setPadding(0);
- place(0, 10, mExpSpeed5Label, 6).setPadding(0);
- place(0, 11, mExpTime5Label, 6).setPadding(0);
- place(0, 12, mExpSpeed15Label, 6).setPadding(0);
- place(0, 13, mExpTime15Label, 6).setPadding(0);
-
- place(5, 12, mTimerButton).setPadding(0);
- place(5, 13, mResetButton).setPadding(0);
-
- loadWindowState();
- enableVisibleSound(true);
-}
-
-void KillStats::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "reset")
- {
- mKillCounter = 0;
- mExpCounter = 0;
- const std::string strXpPercent = toString(CAST_U64(
- PlayerInfo::getAttribute64(Attributes::PLAYER_EXP_NEEDED) / 100));
- mLine3->setCaption(strprintf("1%% = %s exp, avg mob for 1%%: %s",
- strXpPercent.c_str(),
- "?"));
- // TRANSLATORS: kill stats window label
- mLine4->setCaption(strprintf(_("Kills: %s, total exp: %s"), "?", "?"));
- // TRANSLATORS: kill stats window label
- mLine5->setCaption(strprintf(_("Avg Exp: %s"), "?"));
- mLine6->setCaption(strprintf(
- // TRANSLATORS: kill stats window label
- _("No. of avg mob to next level: %s"), "?"));
-
- resetTimes();
- }
- else if (eventId == "timer")
- {
- mKillTimer = 0;
- mKillTCounter = 0;
- mExpTCounter = 0;
- mLine7->setCaption(strprintf(
- // TRANSLATORS: kill stats window label
- _("Kills/Min: %s, Exp/Min: %s"), "?", "?"));
-
- resetTimes();
- }
-}
-
-void KillStats::resetTimes()
-{
- m1minExpTime = 0;
- m1minExpNum = 0;
- m1minSpeed = 0;
- m5minExpTime = 0;
- m5minExpNum = 0;
- m5minSpeed = 0;
- m15minExpTime = 0;
- m15minExpNum = 0;
- m15minSpeed = 0;
-}
-
-void KillStats::gainXp(int64_t xp)
-{
- const int64_t expNeed = PlayerInfo::getAttribute64(
- Attributes::PLAYER_EXP_NEEDED);
- if (xp == expNeed)
- xp = 0;
- else if (xp == 0)
- return;
-
- mKillCounter++;
- mKillTCounter++;
-
- mExpCounter = mExpCounter + xp;
- mExpTCounter = mExpTCounter + xp;
- if (mKillCounter == 0)
- mKillCounter = 1;
-
- const float AvgExp = static_cast<float>(mExpCounter)
- / static_cast<float>(mKillCounter);
- int64_t xpNextLevel(expNeed);
-
- if (mKillTimer == 0)
- mKillTimer = cur_time;
-
- if (xpNextLevel == 0)
- xpNextLevel = 1;
-
- double timeDiff = difftime(cur_time, mKillTimer) / 60;
-
- if (timeDiff <= 0.001)
- timeDiff = 1;
-
- const int64_t exp = PlayerInfo::getAttribute64(Attributes::PLAYER_EXP);
- // TRANSLATORS: kill stats window label
- mLine1->setCaption(strprintf(_("Level: %d at %f%%"),
- localPlayer->getLevel(), static_cast<double>(exp)
- / static_cast<double>(xpNextLevel) * 100.0));
-
- const std::string strXp = toString(CAST_U64(exp));
- const std::string strXpNextLevel = toString(CAST_U64(xpNextLevel));
- const std::string strXpLeft = toString(CAST_U64(xpNextLevel - exp));
- const std::string strXpPercent = toString(CAST_U64(xpNextLevel / 100));
- // TRANSLATORS: kill stats window label
- mLine2->setCaption(strprintf(_("Exp: %s/%s Left: %s"),
- strXp.c_str(),
- strXpNextLevel.c_str(),
- strXpLeft.c_str()));
-
- if (AvgExp >= -0.001F && AvgExp <= 0.001F)
- {
- // TRANSLATORS: kill stats window label
- mLine3->setCaption(strprintf(_("1%% = %s exp, avg mob for 1%%: %s"),
- strXpPercent.c_str(),
- "?"));
-
- // TRANSLATORS: kill stats window label
- mLine5->setCaption(strprintf(_("Avg Exp: %s"),
- toString(AvgExp).c_str()));
-
- mLine6->setCaption(strprintf(
- // TRANSLATORS: kill stats window label
- _("No. of avg mob to next level: %s"), "?"));
- }
- else
- {
- // TRANSLATORS: kill stats window label
- mLine3->setCaption(strprintf(_("1%% = %s exp, avg mob for 1%%: %s"),
- strXpPercent.c_str(), toString((static_cast<float>(
- xpNextLevel) / 100) / AvgExp).c_str()));
-
- // TRANSLATORS: kill stats window label
- mLine5->setCaption(strprintf(_("Avg Exp: %s"),
- toString(AvgExp).c_str()));
-
- // TRANSLATORS: kill stats window label
- mLine6->setCaption(strprintf(_("No. of avg mob to next level: %s"),
- toString(static_cast<float>(xpNextLevel - exp) / AvgExp).c_str()));
- }
- // TRANSLATORS: kill stats window label
- mLine4->setCaption(strprintf(_("Kills: %s, total exp: %s"),
- toString(mKillCounter).c_str(),
- toString(CAST_U64(mExpCounter)).c_str()));
-
- // TRANSLATORS: kill stats window label
- mLine7->setCaption(strprintf(_("Kills/Min: %s, Exp/Min: %s"),
- toString(mKillTCounter / timeDiff).c_str(),
- toString(CAST_U64(mExpTCounter / timeDiff)).c_str()));
-
- mLastKillExpLabel->setCaption(strprintf("%s %s",
- // TRANSLATORS: kill stats window label
- _("Last kill exp:"),
- strXp.c_str()));
-
- recalcStats();
- update();
-}
-
-void KillStats::recalcStats()
-{
- BLOCK_START("KillStats::recalcStats")
- const time_t curTime = cur_time;
-
- // Need Update Exp Counter
- if (curTime - m1minExpTime > 60)
- {
- const int64_t newExp = PlayerInfo::getAttribute(
- Attributes::PLAYER_EXP);
- if (m1minExpTime != 0)
- m1minSpeed = CAST_S32(newExp - m1minExpNum);
- else
- m1minSpeed = 0;
- m1minExpTime = curTime;
- m1minExpNum = newExp;
- }
-
- if (curTime != 0 && mLastHost == 0xFF6B66 && cur_time > 1)
- {
- const int newExp = PlayerInfo::getAttribute(
- Attributes::PLAYER_EXP_NEEDED);
- if (m1minExpTime != 0)
- m1minSpeed = CAST_S32(newExp - m1minExpNum);
- mStatsReUpdated = true;
- m1minExpNum = newExp;
- }
-
- if (curTime - m5minExpTime > 60*5)
- {
- const int64_t newExp = PlayerInfo::getAttribute(
- Attributes::PLAYER_EXP);
- if (m5minExpTime != 0)
- m5minSpeed = CAST_S32(newExp - m5minExpNum);
- else
- m5minSpeed = 0;
- m5minExpTime = curTime;
- m5minExpNum = newExp;
- }
-
- if (curTime - m15minExpTime > 60*15)
- {
- const int64_t newExp = PlayerInfo::getAttribute(
- Attributes::PLAYER_EXP);
- if (m15minExpTime != 0)
- m15minSpeed = CAST_S32(newExp - m15minExpNum);
- else
- m15minSpeed = 0;
- m15minExpTime = curTime;
- m15minExpNum = newExp;
- }
- BLOCK_END("KillStats::recalcStats")
-}
-
-void KillStats::update()
-{
- BLOCK_START("KillStats::update")
-
- mExpSpeed1Label->setCaption(strprintf(ngettext("Exp speed per %d min: %s",
- "Exp speed per %d min: %s", 1),
- 1,
- toString(m1minSpeed).c_str()));
-
- if (m1minSpeed != 0)
- {
- // TRANSLATORS: kill stats window label
- mExpTime1Label->setCaption(strprintf(_(" Time for next level: %s"),
- toString(static_cast<float>((PlayerInfo::getAttribute(
- Attributes::PLAYER_EXP_NEEDED) - PlayerInfo::getAttribute(
- Attributes::PLAYER_EXP)) /
- static_cast<float>(m1minSpeed))).c_str()));
- }
- else
- {
- mExpTime1Label->setCaption(strprintf(
- // TRANSLATORS: kill stats window label
- _(" Time for next level: %s"), "?"));
- }
- mExpTime1Label->adjustSize();
-
- mExpSpeed5Label->setCaption(strprintf(ngettext("Exp speed per %d min: %s",
- "Exp speed per %d min: %s", 5),
- 5,
- toString(m5minSpeed / 5).c_str()));
- mExpSpeed5Label->adjustSize();
-
- if (m5minSpeed != 0)
- {
- // TRANSLATORS: kill stats window label
- mExpTime5Label->setCaption(strprintf(_(" Time for next level: %s"),
- toString(static_cast<float>((PlayerInfo::getAttribute(
- Attributes::PLAYER_EXP_NEEDED) - PlayerInfo::getAttribute(
- Attributes::PLAYER_EXP)) / m5minSpeed * 5)).c_str()));
- }
- else
- {
- mExpTime5Label->setCaption(strprintf(
- // TRANSLATORS: kill stats window label
- _(" Time for next level: %s"), "?"));
- }
- mExpTime5Label->adjustSize();
-
-
- mExpSpeed15Label->setCaption(strprintf(ngettext("Exp speed per %d min: %s",
- "Exp speed per %d min: %s", 15), 15, toString(
- m15minSpeed / 15).c_str()));
- mExpSpeed15Label->adjustSize();
-
- if (m15minSpeed != 0)
- {
- // TRANSLATORS: kill stats window label
- mExpTime15Label->setCaption(strprintf(_(" Time for next level: %s"),
- toString(static_cast<float>((PlayerInfo::getAttribute(
- Attributes::PLAYER_EXP_NEEDED) - PlayerInfo::getAttribute(
- Attributes::PLAYER_EXP)) / m15minSpeed * 15)).c_str()));
- }
- else
- {
- mExpTime15Label->setCaption(strprintf(
- // TRANSLATORS: kill stats window label
- _(" Time for next level: %s"), "?"));
- }
-
- BLOCK_END("KillStats::update")
-}
-
-void KillStats::attributeChanged(const AttributesT id,
- const int64_t oldVal,
- const int64_t newVal)
-{
- PRAGMA45(GCC diagnostic push)
- PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
- switch (id)
- {
- case Attributes::PLAYER_EXP:
- case Attributes::PLAYER_EXP_NEEDED:
- gainXp(newVal - oldVal);
- break;
- case Attributes::PLAYER_BASE_LEVEL:
- {
- const std::string strXpPercent = toString(CAST_U64(
- PlayerInfo::getAttribute(
- Attributes::PLAYER_EXP_NEEDED) / 100));
- mKillCounter = 0;
- mKillTCounter = 0;
- mExpCounter = 0;
- mExpTCounter = 0;
- mLine3->setCaption(strprintf("1%% = %s exp, avg mob for 1%%: %s",
- strXpPercent.c_str(),
- "?"));
- mLine4->setCaption(strprintf(
- // TRANSLATORS: kill stats window label
- _("Kills: %s, total exp: %s"), "?", "?"));
- // TRANSLATORS: kill stats window label
- mLine5->setCaption(strprintf(_("Avg Exp: %s"), "?"));
- mLine6->setCaption(strprintf(
- // TRANSLATORS: kill stats window label
- _("No. of avg mob to next level: %s"), "?"));
- mLine7->setCaption(strprintf(
- // TRANSLATORS: kill stats window label
- _("Kills/Min: %s, Exp/Min: %s"), "?", "?"));
-
- resetTimes();
- update();
- break;
- }
- default:
- break;
- }
- PRAGMA45(GCC diagnostic pop)
-}
diff --git a/src/gui/windows/killstats.h b/src/gui/windows/killstats.h
deleted file mode 100644
index c701d8430..000000000
--- a/src/gui/windows/killstats.h
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_KILLSTATS_H
-#define GUI_WINDOWS_KILLSTATS_H
-
-#include "listeners/actionlistener.h"
-#include "listeners/attributelistener.h"
-
-#include "gui/widgets/window.h"
-
-class Label;
-class Button;
-
-class KillStats final : public Window,
- public ActionListener,
- public AttributeListener
-{
- public:
- /**
- * Constructor.
- */
- KillStats();
-
- A_DELETE_COPY(KillStats)
-
- /**
- * Destructor.
- */
- ~KillStats()
- { }
-
- /**
- * Stuff.
- */
- void action(const ActionEvent &event) override final;
-
- void gainXp(int64_t Xp);
-
- /**
- * Recalc stats if needed
- */
- void recalcStats();
-
- /**
- * Updates this dialog
- */
- void update();
-
- void resetTimes();
-
- void attributeChanged(const AttributesT id,
- const int64_t oldVal,
- const int64_t newVal) override final;
-
- private:
- time_t mKillTimer; /**< Timer for kill stats. */
- Button *mResetButton A_NONNULLPOINTER;
- Button *mTimerButton A_NONNULLPOINTER;
- Label *mLine1;
- Label *mLine2;
- Label *mLine3;
- Label *mLine4 A_NONNULLPOINTER;
- Label *mLine5 A_NONNULLPOINTER;
- Label *mLine6 A_NONNULLPOINTER;
- Label *mLine7 A_NONNULLPOINTER;
-
- Label *mExpSpeed1Label A_NONNULLPOINTER;
- Label *mExpTime1Label A_NONNULLPOINTER;
- Label *mExpSpeed5Label A_NONNULLPOINTER;
- Label *mExpTime5Label A_NONNULLPOINTER;
- Label *mExpSpeed15Label A_NONNULLPOINTER;
- Label *mExpTime15Label A_NONNULLPOINTER;
-
- Label *mLastKillExpLabel A_NONNULLPOINTER;
-
- int mKillCounter; /**< Session Kill counter. */
- int64_t mExpCounter; /**< Session Exp counter. */
- int mKillTCounter; /**< Timer Kill counter. */
- int64_t mExpTCounter; /**< Timer Exp counter. */
-
- time_t m1minExpTime;
- int64_t m1minExpNum;
- int m1minSpeed;
-
- time_t m5minExpTime;
- int64_t m5minExpNum;
- int m5minSpeed;
-
- time_t m15minExpTime;
- int64_t m15minExpNum;
- int m15minSpeed;
-};
-
-extern KillStats *killStats;
-
-#endif // GUI_WINDOWS_KILLSTATS_H
diff --git a/src/gui/windows/logindialog.cpp b/src/gui/windows/logindialog.cpp
deleted file mode 100644
index 21af69b91..000000000
--- a/src/gui/windows/logindialog.cpp
+++ /dev/null
@@ -1,402 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/logindialog.h"
-
-#include "client.h"
-#include "configuration.h"
-
-#include "fs/paths.h"
-
-#include "gui/models/updatelistmodel.h"
-#include "gui/models/updatetypemodel.h"
-
-#include "gui/windows/confirmdialog.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/checkbox.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/dropdown.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/passwordfield.h"
-#include "gui/widgets/layoutcell.h"
-
-#include "listeners/openurllistener.h"
-
-#include "net/charserverhandler.h"
-#include "net/logindata.h"
-#include "net/loginhandler.h"
-#include "net/updatetypeoperators.h"
-
-#include "utils/delete2.h"
-#include "utils/stdmove.h"
-
-#include "debug.h"
-
-std::string LoginDialog::savedPassword;
-std::string LoginDialog::savedPasswordKey;
-
-namespace
-{
- OpenUrlListener urlListener;
-} // namespace
-
-LoginDialog::LoginDialog(LoginData &data,
- ServerInfo *const server,
- std::string *const updateHost) :
- // TRANSLATORS: login dialog name
- Window(_("Login"), Modal_false, nullptr, "login.xml"),
- ActionListener(),
- KeyListener(),
- mLoginData(&data),
- mServer(server),
- mUserField(new TextField(this, mLoginData->username)),
- mPassField(new PasswordField(this, mLoginData->password)),
- // TRANSLATORS: login dialog label
- mKeepCheck(new CheckBox(this, _("Remember username"),
- mLoginData->remember)),
- // TRANSLATORS: login dialog label
- mUpdateTypeLabel(new Label(this, _("Update:"))),
- mUpdateTypeModel(new UpdateTypeModel),
- mUpdateTypeDropDown(new DropDown(this, mUpdateTypeModel)),
- // TRANSLATORS: login dialog button
- mServerButton(new Button(this, _("Change Server"), "server", this)),
- // TRANSLATORS: login dialog button
- mLoginButton(new Button(this, _("Login"), "login", this)),
- // TRANSLATORS: login dialog button
- mRegisterButton(new Button(this, _("Register"), "register", this)),
- // TRANSLATORS: login dialog checkbox
- mCustomUpdateHost(new CheckBox(this, _("Custom update host"),
- (mLoginData->updateType & UpdateType::Custom) != 0,
- this, "customhost")),
- mUpdateHostText(new TextField(this, serverConfig.getValue(
- "customUpdateHost", ""))),
- mUpdateListModel(nullptr),
- mUpdateHostDropDown(nullptr),
- mUpdateHost(updateHost),
- mServerName(server->hostname)
-{
- setCloseButton(true);
- setWindowName("Login");
-
- if (charServerHandler != nullptr)
- charServerHandler->clear();
-
- mergeUpdateHosts();
-
- // TRANSLATORS: login dialog label
- Label *const serverLabel1 = new Label(this, _("Server:"));
- Label *const serverLabel2 = new Label(this, mServerName);
- serverLabel2->adjustSize();
- // TRANSLATORS: login dialog label
- Label *const userLabel = new Label(this, _("Name:"));
- // TRANSLATORS: login dialog label
- Label *const passLabel = new Label(this, _("Password:"));
- if (mServer->updateHosts.size() > 1)
- {
- mUpdateListModel = new UpdateListModel(mServer);
- mUpdateHostDropDown = new DropDown(this, mUpdateListModel,
- false, Modal_false, this, "updateselect");
- const std::string str = serverConfig.getValue("updateHost2", "");
- if (!str.empty())
- mUpdateHostDropDown->setSelectedString(str);
- }
- else
- {
- mUpdateListModel = nullptr;
- mUpdateHostDropDown = nullptr;
- }
- mUpdateHostText->adjustSize();
-
- if (mPassField->getText().empty() &&
- !LoginDialog::savedPassword.empty())
- {
- mPassField->setText(LoginDialog::savedPassword);
- }
-
- mUpdateTypeDropDown->setActionEventId("updatetype");
- mUpdateTypeDropDown->setSelected((mLoginData->updateType
- | UpdateType::Custom) ^ CAST_S32(UpdateType::Custom));
-
- if (!mCustomUpdateHost->isSelected())
- mUpdateHostText->setVisible(Visible_false);
-
- mUserField->setActionEventId("login");
- mPassField->setActionEventId("login");
-
- mUserField->addKeyListener(this);
- mPassField->addKeyListener(this);
- mUserField->addActionListener(this);
- mPassField->addActionListener(this);
-
- place(0, 0, serverLabel1);
- place(1, 0, serverLabel2, 8);
- place(0, 1, userLabel);
- place(1, 1, mUserField, 8);
- place(0, 2, passLabel);
- place(1, 2, mPassField, 8);
- place(0, 6, mUpdateTypeLabel, 1);
- place(1, 6, mUpdateTypeDropDown, 8);
- int n = 7;
- if (mUpdateHostDropDown != nullptr)
- {
- place(0, 7, mUpdateHostDropDown, 9);
- n += 1;
- }
- place(0, n, mCustomUpdateHost, 9);
- place(0, n + 1, mUpdateHostText, 9);
- place(0, n + 2, mKeepCheck, 9);
- place(0, n + 3, mRegisterButton).setHAlign(LayoutCell::LEFT);
- place(2, n + 3, mServerButton);
- place(3, n + 3, mLoginButton);
-
- addKeyListener(this);
-}
-
-void LoginDialog::postInit()
-{
- Window::postInit();
- setVisible(Visible_true);
-
- const int h = 200;
- if (mUpdateHostDropDown != nullptr)
- setContentSize(310, 250);
- setContentSize(310, h);
-#ifdef ANDROID
- setDefaultSize(310, h, ImagePosition::UPPER_CENTER, 0, 0);
-#else // ANDROID
-
- setDefaultSize(310, h, ImagePosition::CENTER, 0, 0);
-#endif // ANDROID
-
- center();
- loadWindowState();
- reflowLayout();
-
- if (mUserField->getText().empty())
- mUserField->requestFocus();
- else
- mPassField->requestFocus();
-
- mLoginButton->setEnabled(canSubmit());
- if (loginHandler != nullptr)
- {
- mRegisterButton->setEnabled(loginHandler->isRegistrationEnabled()
- || !mLoginData->registerUrl.empty());
- }
- else
- {
- mRegisterButton->setEnabled(false);
- }
-}
-
-LoginDialog::~LoginDialog()
-{
- if (mUpdateTypeDropDown != nullptr)
- mUpdateTypeDropDown->hideDrop(false);
- if (mUpdateHostDropDown != nullptr)
- mUpdateHostDropDown->hideDrop(false);
-
- delete2(mUpdateTypeModel);
- delete2(mUpdateListModel);
-}
-
-void LoginDialog::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "login" && canSubmit())
- {
- prepareUpdate();
- mLoginData->registerLogin = false;
- client->setState(State::LOGIN_ATTEMPT);
- }
- else if (eventId == "server")
- {
- close();
- }
- else if (eventId == "register")
- {
- if (loginHandler->isRegistrationEnabled())
- {
- prepareUpdate();
- client->setState(State::REGISTER_PREP);
- }
- else if (!mLoginData->registerUrl.empty())
- {
- const std::string &url = mLoginData->registerUrl;
- urlListener.url = url;
- ConfirmDialog *const confirmDlg = CREATEWIDGETR(ConfirmDialog,
- // TRANSLATORS: question dialog
- _("Open register url"),
- url,
- SOUND_REQUEST,
- false,
- Modal_true);
- confirmDlg->addActionListener(&urlListener);
- }
- }
- else if (eventId == "customhost")
- {
- mUpdateHostText->setVisible(fromBool(
- mCustomUpdateHost->isSelected(), Visible));
- }
- else if (eventId == "updateselect")
- {
- mCustomUpdateHost->setSelected(false);
- mUpdateHostText->setVisible(Visible_false);
- }
-}
-
-void LoginDialog::keyPressed(KeyEvent &event)
-{
- if (event.isConsumed())
- {
- mLoginButton->setEnabled(canSubmit());
- return;
- }
-
- const InputActionT actionId = event.getActionId();
- if (actionId == InputAction::GUI_CANCEL)
- {
- action(ActionEvent(nullptr, mServerButton->getActionEventId()));
- }
-#ifdef USE_SDL2
- else if (actionId == InputAction::GUI_SELECT2)
-#else // USE_SDL2
- else if (actionId == InputAction::GUI_SELECT ||
- actionId == InputAction::GUI_SELECT2)
-#endif // USE_SDL2
- {
- action(ActionEvent(nullptr, mLoginButton->getActionEventId()));
- }
- else
- {
- mLoginButton->setEnabled(canSubmit());
- }
-}
-
-bool LoginDialog::canSubmit() const
-{
- return !mUserField->getText().empty() &&
- !mPassField->getText().empty() &&
- client->getState() == State::LOGIN;
-}
-
-void LoginDialog::prepareUpdate()
-{
- mLoginData->username = mUserField->getText();
- mLoginData->password = mPassField->getText();
- mLoginData->remember = mKeepCheck->isSelected();
- UpdateTypeT updateType = static_cast<UpdateTypeT>(
- mUpdateTypeDropDown->getSelected());
-
- if (mCustomUpdateHost->isSelected()
- && !mUpdateHostText->getText().empty())
- {
- updateType = static_cast<UpdateTypeT>(
- updateType | UpdateType::Custom);
- serverConfig.setValue("customUpdateHost",
- mUpdateHostText->getText());
-
- if (checkPath(mUpdateHostText->getText()))
- {
- mLoginData->updateHost = mUpdateHostText->getText();
- *mUpdateHost = mLoginData->updateHost;
- }
- else
- {
- mLoginData->updateHost.clear();
- (*mUpdateHost).clear();
- }
- }
- else
- {
- std::string str;
- if (mUpdateHostDropDown != nullptr)
- {
- const int sel = mUpdateHostDropDown->getSelected();
- if (sel >= 0)
- {
- const HostsGroup &group = mServer->updateHosts[sel];
- if (!group.hosts.empty())
- {
- str = group.hosts[0];
- mLoginData->updateHosts = group.hosts;
- serverConfig.setValue("updateHost2", group.name);
- }
- else
- {
- serverConfig.setValue("updateHost2", "");
- }
- }
- }
- else if (mLoginData->updateHost.empty()
- && !mLoginData->updateHosts.empty())
- {
- str = mLoginData->updateHosts[0];
- serverConfig.setValue("updateHost2", str);
- }
- if (!str.empty() && checkPath(str))
- {
- mLoginData->updateHost = str;
- *mUpdateHost = STD_MOVE(str);
- }
- else
- {
- mLoginData->updateHost.clear();
- (*mUpdateHost).clear();
- }
- }
-
- mLoginData->updateType = updateType;
- serverConfig.setValue("updateType", CAST_S32(updateType));
-
- mRegisterButton->setEnabled(false);
- mServerButton->setEnabled(false);
- mLoginButton->setEnabled(false);
-
- LoginDialog::savedPassword = mPassField->getText();
- if (mLoginData->remember)
- LoginDialog::savedPasswordKey = mServerName;
- else
- LoginDialog::savedPasswordKey = "-";
-}
-
-void LoginDialog::close()
-{
- client->setState(State::SWITCH_SERVER);
- Window::close();
-}
-
-void LoginDialog::mergeUpdateHosts()
-{
- HostsGroup group;
-
- group.name = mServer->defaultHostName;
- if (group.name.empty())
- {
- // TRANSLATORS: update hosts group default name
- group.name = _("default updates");
- }
- group.hosts = mLoginData->updateHosts;
- mServer->updateHosts.insert(mServer->updateHosts.begin(), group);
-}
diff --git a/src/gui/windows/logindialog.h b/src/gui/windows/logindialog.h
deleted file mode 100644
index c3178f079..000000000
--- a/src/gui/windows/logindialog.h
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_LOGINDIALOG_H
-#define GUI_WINDOWS_LOGINDIALOG_H
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/keylistener.h"
-
-class Button;
-class CheckBox;
-class DropDown;
-class Label;
-class LoginData;
-class ServerInfo;
-class TextField;
-class UpdateListModel;
-class UpdateTypeModel;
-
-/**
- * The login dialog.
- *
- * \ingroup Interface
- */
-class LoginDialog final : public Window,
- public ActionListener,
- public KeyListener
-{
- public:
- /**
- * Constructor
- *
- * @see Window::Window
- */
- LoginDialog(LoginData &data,
- ServerInfo *const server,
- std::string *const updateHost) A_NONNULL(3, 4);
-
- A_DELETE_COPY(LoginDialog)
-
- ~LoginDialog();
-
- void postInit() override final;
-
- /**
- * Called when receiving actions from the widgets.
- */
- void action(const ActionEvent &event) override final;
-
- /**
- * Called when a key is pressed in one of the text fields.
- */
- void keyPressed(KeyEvent &event) override final;
-
- void close() override final;
-
- static std::string savedPasswordKey;
- static std::string savedPassword;
-
- private:
- /**
- * Returns whether submit can be enabled. This is true in the login
- * state, when all necessary fields have some text.
- */
- bool canSubmit() const;
-
- void prepareUpdate();
-
- void mergeUpdateHosts();
-
- LoginData *mLoginData A_NONNULLPOINTER;
- ServerInfo *mServer A_NONNULLPOINTER;
-
- TextField *mUserField A_NONNULLPOINTER;
- TextField *mPassField A_NONNULLPOINTER;
- CheckBox *mKeepCheck A_NONNULLPOINTER;
- Label *mUpdateTypeLabel A_NONNULLPOINTER;
- UpdateTypeModel *mUpdateTypeModel A_NONNULLPOINTER;
- DropDown *mUpdateTypeDropDown A_NONNULLPOINTER;
- Button *mServerButton A_NONNULLPOINTER;
- Button *mLoginButton A_NONNULLPOINTER;
- Button *mRegisterButton A_NONNULLPOINTER;
- CheckBox *mCustomUpdateHost A_NONNULLPOINTER;
- TextField *mUpdateHostText A_NONNULLPOINTER;
- UpdateListModel *mUpdateListModel;
- DropDown *mUpdateHostDropDown;
-
- std::string *mUpdateHost;
- std::string mServerName;
-};
-
-#endif // GUI_WINDOWS_LOGINDIALOG_H
diff --git a/src/gui/windows/maileditwindow.cpp b/src/gui/windows/maileditwindow.cpp
deleted file mode 100644
index a47b284de..000000000
--- a/src/gui/windows/maileditwindow.cpp
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/maileditwindow.h"
-
-#include "settings.h"
-
-#include "being/playerinfo.h"
-
-#include "gui/windows/inventorywindow.h"
-#include "gui/windows/itemamountwindow.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/inttextfield.h"
-#include "gui/widgets/itemcontainer.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "resources/item/item.h"
-
-#include "net/mail2handler.h"
-#include "net/mailhandler.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include <climits>
-
-#include "debug.h"
-
-MailEditWindow *mailEditWindow = nullptr;
-
-MailEditWindow::MailEditWindow() :
- // TRANSLATORS: mail edit window name
- Window(_("Edit mail"), Modal_false, nullptr, "mailedit.xml"),
- ActionListener(),
- FocusListener(),
- // TRANSLATORS: mail edit window button
- mSendButton(new Button(this, _("Send"), "send", this)),
- // TRANSLATORS: mail edit window button
- mCloseButton(new Button(this, _("Close"), "close", this)),
- // TRANSLATORS: mail edit window button
- mAddButton(new Button(this, _("Add"), "add", this)),
- // TRANSLATORS: mail edit window label
- mToLabel(new Label(this, _("To:"))),
- // TRANSLATORS: mail edit window label
- mSubjectLabel(new Label(this, _("Subject:"))),
- // TRANSLATORS: mail edit window label
- mMoneyLabel(new Label(this, _("Money:"))),
- // TRANSLATORS: mail edit window label
- mItemLabel(new Label(this, _("Item:"))),
- // TRANSLATORS: mail edit window label
- mMessageLabel(new Label(this, _("Message:"))),
- mToField(new TextField(this)),
- mSubjectField(new TextField(this)),
- mMoneyField(new IntTextField(this, 0, 0,
- settings.enableNewMailSystem ? INT_MAX : 10000000)),
- mMessageField(new TextField(this)),
- mInventory(new Inventory(InventoryType::MailEdit,
- settings.enableNewMailSystem ? -1 : 1)),
- mItemContainer(new ItemContainer(this, mInventory)),
- mItemScrollArea(new ScrollArea(this, mItemContainer,
- fromBool(getOptionBool("showitemsbackground"), Opaque),
- "mailedit_listbackground.xml")),
- mUseMail2(settings.enableNewMailSystem)
-{
- setWindowName("MailEdit");
- setCloseButton(true);
- setResizable(true);
- setCloseButton(true);
- setSaveVisible(false);
- setStickyButtonLock(true);
- setVisible(Visible_true);
-
- setDefaultSize(380, 200, ImagePosition::CENTER);
- setMinWidth(200);
- setMinHeight(200);
- center();
-
- ContainerPlacer placer;
- placer = getPlacer(0, 0);
-
- mToField->setWidth(100);
- mSubjectField->setWidth(100);
- mMessageField->setWidth(100);
- mItemScrollArea->setHeight(100);
- mItemScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- mToField->addFocusListener(this);
-
- placer(0, 0, mToLabel);
- placer(1, 0, mToField, 3);
- placer(0, 1, mSubjectLabel);
- placer(1, 1, mSubjectField, 3);
- placer(0, 2, mMoneyLabel);
- placer(1, 2, mMoneyField, 3);
- placer(0, 3, mItemLabel);
- placer(1, 3, mItemScrollArea, 2, 2);
- placer(3, 4, mAddButton, 1);
-
- placer(0, 5, mMessageLabel);
- placer(1, 5, mMessageField, 3);
- placer(0, 6, mSendButton);
- placer(3, 6, mCloseButton);
-
- loadWindowState();
- if (mUseMail2)
- mSendButton->setEnabled(false);
- enableVisibleSound(true);
-}
-
-MailEditWindow::~MailEditWindow()
-{
- mailEditWindow = nullptr;
- delete2(mInventory);
-}
-
-void MailEditWindow::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "close")
- {
- close();
- }
- else if (eventId == "send")
- {
- sendMail();
- }
- else if (eventId == "add")
- {
- Item *const item = inventoryWindow->getSelectedItem();
-
- if (item == nullptr)
- return;
-
- ItemAmountWindow::showWindow(ItemAmountWindowUsage::MailAdd,
- this, item);
- }
-}
-
-void MailEditWindow::addItem(const Item *const item,
- const int amount)
-{
- if (item == nullptr)
- return;
- mInventory->addItem(item->getId(),
- item->getType(),
- amount,
- item->getRefine(),
- item->getColor(),
- item->getIdentified(),
- item->getDamaged(),
- item->getFavorite(),
- Equipm_false,
- Equipped_false);
-}
-
-void MailEditWindow::setSubject(const std::string &str)
-{
- mSubjectField->setText(str);
-}
-
-void MailEditWindow::setTo(const std::string &str)
-{
- mToField->setText(str);
- mSendButton->setEnabled(true);
-}
-
-void MailEditWindow::setMessage(const std::string &str)
-{
- mMessageField->setText(str);
-}
-
-void MailEditWindow::close()
-{
- if (mUseMail2)
- mail2Handler->cancelWriteMail();
- mailEditWindow = nullptr;
- scheduleDelete();
-}
-
-Inventory *MailEditWindow::getInventory() const
-{
- return mInventory;
-}
-
-void MailEditWindow::sendMail()
-{
- const int money = mMoneyField->getValue();
- std::string subject = mSubjectField->getText();
- if (subject.empty())
- {
- // TRANSLATORS: empty mail message subject
- subject.append(_("empty subject"));
- }
- if (mUseMail2)
- {
- mail2Handler->sendMail(mToField->getText(),
- subject,
- mMessageField->getText(),
- money);
- }
- else
- {
- if (money != 0)
- mailHandler->setAttachMoney(money);
- const Item *const tempItem = mInventory->getItem(0);
- if (tempItem != nullptr)
- {
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv != nullptr)
- {
- const Item *const item = inv->findItem(
- tempItem->getId(), ItemColor_one);
- if (item != nullptr)
- {
- mailHandler->setAttach(item->getInvIndex(),
- tempItem->getQuantity());
- }
- }
- }
-
- mailHandler->send(mToField->getText(),
- subject,
- mMessageField->getText());
- }
-}
-
-void MailEditWindow::updateItems()
-{
- mItemContainer->updateMatrix();
-}
-
-void MailEditWindow::focusLost(const Event &event)
-{
- if (!mUseMail2)
- return;
-
- if (event.getSource() == mToField)
- {
- const std::string to = mToField->getText();
- if (to != mail2Handler->getCheckedName())
- {
- mail2Handler->queueCheckName(MailQueueType::ValidateTo,
- to,
- std::string(),
- std::string(),
- 0);
- mSendButton->setEnabled(false);
- }
- else
- {
- mSendButton->setEnabled(true);
- }
- }
-}
-
-void MailEditWindow::validatedTo()
-{
- mSendButton->setEnabled(true);
-}
diff --git a/src/gui/windows/maileditwindow.h b/src/gui/windows/maileditwindow.h
deleted file mode 100644
index 2c6c5d0ef..000000000
--- a/src/gui/windows/maileditwindow.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_MAILEDITWINDOW_H
-#define GUI_WINDOWS_MAILEDITWINDOW_H
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/focuslistener.h"
-
-class Button;
-class IntTextField;
-class Inventory;
-class Item;
-class ItemContainer;
-class Label;
-class ScrollArea;
-class TextField;
-
-class MailEditWindow final : public Window,
- public ActionListener,
- public FocusListener
-{
- public:
- MailEditWindow();
-
- A_DELETE_COPY(MailEditWindow)
-
- ~MailEditWindow();
-
- void action(const ActionEvent &event) override final;
-
- void addItem(const Item *const item, const int amount);
-
- void setSubject(const std::string &str);
-
- void setTo(const std::string &str);
-
- void setMessage(const std::string &str);
-
- void close() override final;
-
- Inventory *getInventory() const A_WARN_UNUSED;
-
- void updateItems();
-
- void focusLost(const Event &event) override final;
-
- void validatedTo();
-
- private:
- void sendMail();
-
- Button *mSendButton;
- Button *mCloseButton;
- Button *mAddButton;
- Label *mToLabel;
- Label *mSubjectLabel;
- Label *mMoneyLabel;
- Label *mItemLabel;
- Label *mMessageLabel;
- TextField *mToField;
- TextField *mSubjectField;
- IntTextField *mMoneyField;
- TextField *mMessageField;
- Inventory *mInventory;
- ItemContainer *mItemContainer;
- ScrollArea *mItemScrollArea;
- bool mUseMail2;
-};
-
-extern MailEditWindow *mailEditWindow;
-
-#endif // GUI_WINDOWS_MAILEDITWINDOW_H
diff --git a/src/gui/windows/mailviewwindow.cpp b/src/gui/windows/mailviewwindow.cpp
deleted file mode 100644
index fbe0c9112..000000000
--- a/src/gui/windows/mailviewwindow.cpp
+++ /dev/null
@@ -1,269 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/mailviewwindow.h"
-
-#include "settings.h"
-
-#include "net/mail2handler.h"
-#include "net/mailhandler.h"
-
-#include "gui/mailmessage.h"
-
-#include "gui/windows/maileditwindow.h"
-#include "gui/windows/mailwindow.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/itemcontainer.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include "resources/inventory/inventory.h"
-#include "debug.h"
-
-MailViewWindow *mailViewWindow = nullptr;
-
-MailViewWindow::MailViewWindow(MailMessage *const message,
- const int itemsCount) :
- // TRANSLATORS: mail view window name
- Window(_("View mail"), Modal_false, nullptr, "mailview.xml"),
- ActionListener(),
- mMessage(message),
- mGetAttachButton(new Button(this,
- // TRANSLATORS: mail view attach / items button
- settings.enableNewMailSystem ? _("Get items") : _("Get attach"),
- "attach", this)),
- mGetMoneyButton(nullptr),
- // TRANSLATORS: mail view window button
- mCloseButton(new Button(this, _("Close"), "close", this)),
- mPrevButton(new Button(this, "<", "prev", this)),
- mNextButton(new Button(this, ">", "next", this)),
- // TRANSLATORS: mail view window button
- mReplyButton(new Button(this, _("Reply"), "reply", this)),
- // TRANSLATORS: mail view window label
- mTimeLabel(new Label(this, strprintf("%s %s", _("Time:"),
- message->strTime.c_str()))),
- mMoneyLabel(nullptr),
- // TRANSLATORS: mail view window label
- mFromLabel(new Label(this, strprintf("%s %s", _("From:"),
- message->sender.c_str()))),
- // TRANSLATORS: mail view window label
- mSubjectLabel(new Label(this, strprintf("%s %s", _("Subject:"),
- message->title.c_str()))),
- // TRANSLATORS: mail view window label
- mMessageLabel(new Label(this, strprintf("%s %s", _("Message:"),
- message->text.c_str()))),
- mInventory(new Inventory(InventoryType::MailView, itemsCount)),
- mItemContainer(new ItemContainer(this, mInventory)),
- mItemScrollArea(new ScrollArea(this, mItemContainer,
- fromBool(getOptionBool("showitemsbackground"), Opaque),
- "mailview_listbackground.xml")),
- mUseMail2(settings.enableNewMailSystem)
-{
- setWindowName("MailView");
- setCloseButton(true);
- setResizable(true);
- setSaveVisible(false);
- setStickyButtonLock(true);
- setVisible(Visible_true);
-
- setDefaultSize(380, 370, ImagePosition::CENTER);
- setMinWidth(200);
- setMinHeight(100);
- center();
- mItemScrollArea->setHeight(100);
-
- mItemScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
-
- ContainerPlacer placer;
- placer = getPlacer(0, 0);
-
- int n = 0;
- placer(0, n++, mTimeLabel);
- placer(0, n++, mFromLabel);
- placer(0, n++, mSubjectLabel);
- if (message->money != 0)
- {
- mMoneyLabel = new Label(this, strprintf("%s %u",
- // TRANSLATORS: mail view window label
- _("Money:"),
- CAST_U32(message->money)));
- placer(0, n++, mMoneyLabel);
- }
- placer(0, n++, mMessageLabel);
- placer(0, n++, mItemScrollArea);
-
- if (mUseMail2 && message->money != 0)
- {
- mGetMoneyButton = new Button(this,
- // TRANSLATORS: mail view attached money button
- _("Get money"),
- "money", this);
- placer(0, n++, mGetMoneyButton);
- }
- placer(0, n++, mGetAttachButton);
- updateAttachButton();
-
- ContainerPlacer placer2;
- placer2 = getPlacer(0, n);
-
- placer2(0, 0, mPrevButton);
- placer2(1, 0, mNextButton);
- placer2(3, 0, mReplyButton);
- placer2(4, 0, mCloseButton);
-
- loadWindowState();
- enableVisibleSound(true);
-}
-
-MailViewWindow::~MailViewWindow()
-{
- if (mUseMail2)
- {
- mMessage = nullptr;
- }
- else
- {
- delete2(mMessage);
- delete2(mGetMoneyButton);
- }
- delete2(mInventory);
- mailViewWindow = nullptr;
-}
-
-void MailViewWindow::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "close")
- {
- scheduleDelete();
- }
- else if (eventId == "attach")
- {
- if (mUseMail2)
- {
- mail2Handler->requestItems(mailWindow->getOpenType(),
- mMessage->id);
- }
- else
- {
- mailHandler->getAttach(CAST_S32(mMessage->id));
- }
- }
- else if (eventId == "money")
- {
- if (mUseMail2)
- {
- mail2Handler->requestMoney(mailWindow->getOpenType(),
- mMessage->id);
- }
- }
- else if (eventId == "next")
- {
- if (mMessage != nullptr)
- mailWindow->viewNext(mMessage->id);
- }
- else if (eventId == "prev")
- {
- if (mMessage != nullptr)
- mailWindow->viewPrev(mMessage->id);
- }
- else if (eventId == "reply")
- {
- if (mMessage == nullptr)
- return;
- if (mailEditWindow != nullptr)
- mailEditWindow->scheduleDelete();
- CREATEWIDGETV0(mailEditWindow, MailEditWindow);
- mailEditWindow->setTo(mMessage->sender);
- mailEditWindow->setSubject("Re:" + mMessage->title);
- mailEditWindow->setMessage(">" + mMessage->text);
- scheduleDelete();
- }
-}
-
-Inventory *MailViewWindow::getInventory() const
-{
- return mInventory;
-}
-
-void MailViewWindow::updateAttachButton()
-{
- if ((mMessage->money != 0 && !mUseMail2) ||
- mInventory->getLastUsedSlot() != -1)
- {
- mGetAttachButton->setVisible(Visible_true);
- }
- else
- {
- mGetAttachButton->setVisible(Visible_false);
- }
-}
-
-void MailViewWindow::updateItems()
-{
- mItemContainer->updateMatrix();
- updateAttachButton();
-}
-
-void MailViewWindow::removeItems(const int64_t mailId)
-{
- if (mailId != mMessage->id)
- return;
- mInventory->clear();
- mMessage->type = static_cast<MailMessageType::Type>(
- CAST_S32(mMessage->type) | CAST_S32(MailMessageType::Item));
- mMessage->type = static_cast<MailMessageType::Type>(
- CAST_S32(mMessage->type) ^ CAST_S32(MailMessageType::Item));
- updateAttachButton();
- if (mailWindow != nullptr)
- mailWindow->refreshMailNames();
-}
-
-void MailViewWindow::removeMoney(const int64_t mailId)
-{
- if (mailId != mMessage->id)
- return;
- mMessage->type = static_cast<MailMessageType::Type>(
- CAST_S32(mMessage->type) | CAST_S32(MailMessageType::Money));
- mMessage->type = static_cast<MailMessageType::Type>(
- CAST_S32(mMessage->type) ^ CAST_S32(MailMessageType::Money));
-
- mMessage->money = 0;
-
- if (mMoneyLabel == nullptr)
- return;
-
- if (mGetMoneyButton != nullptr)
- mGetMoneyButton->setVisible(Visible_false);
-
- mMoneyLabel->setCaption(strprintf("%s %d",
- // TRANSLATORS: mail view window label
- _("Money:"),
- 0));
- if (mailWindow != nullptr)
- mailWindow->refreshMailNames();
-}
diff --git a/src/gui/windows/mailviewwindow.h b/src/gui/windows/mailviewwindow.h
deleted file mode 100644
index 19585de03..000000000
--- a/src/gui/windows/mailviewwindow.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_MAILVIEWWINDOW_H
-#define GUI_WINDOWS_MAILVIEWWINDOW_H
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-
-class Button;
-class Inventory;
-class ItemContainer;
-class Label;
-class ScrollArea;
-
-struct MailMessage;
-
-class MailViewWindow final : public Window,
- public ActionListener
-{
- public:
- MailViewWindow(MailMessage *const message,
- const int itemsCount) A_NONNULL(2);
-
- A_DELETE_COPY(MailViewWindow)
-
- ~MailViewWindow();
-
- void action(const ActionEvent &event) override final;
-
- Inventory *getInventory() const A_WARN_UNUSED;
-
- void updateItems();
-
- void removeItems(const int64_t mailId);
-
- void removeMoney(const int64_t mailId);
-
- private:
- void updateAttachButton();
-
- MailMessage *mMessage;
- Button *mGetAttachButton;
- Button *mGetMoneyButton;
- Button *mCloseButton;
- Button *mPrevButton;
- Button *mNextButton;
- Button *mReplyButton;
- Label *mTimeLabel;
- Label *mMoneyLabel;
- Label *mFromLabel;
- Label *mSubjectLabel;
- Label *mMessageLabel;
- Inventory *mInventory;
- ItemContainer *mItemContainer;
- ScrollArea *mItemScrollArea;
- bool mUseMail2;
-};
-
-extern MailViewWindow *mailViewWindow;
-
-#endif // GUI_WINDOWS_MAILVIEWWINDOW_H
diff --git a/src/gui/windows/mailwindow.cpp b/src/gui/windows/mailwindow.cpp
deleted file mode 100644
index 9da69fb0a..000000000
--- a/src/gui/windows/mailwindow.cpp
+++ /dev/null
@@ -1,393 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/mailwindow.h"
-
-#include "settings.h"
-
-#include "enums/gui/layouttype.h"
-
-#include "net/mail2handler.h"
-#include "net/mailhandler.h"
-
-#include "gui/models/extendednamesmodel.h"
-
-#include "gui/mailmessage.h"
-
-#include "gui/windows/maileditwindow.h"
-#include "gui/windows/mailviewwindow.h"
-#include "gui/windows/setupwindow.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/extendedlistbox.h"
-#include "gui/widgets/layout.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "utils/delete2.h"
-#include "utils/dtor.h"
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-#include "utils/stdmove.h"
-#include "utils/stringutils.h"
-
-#include "debug.h"
-
-MailWindow *mailWindow = nullptr;
-
-MailWindow::MailWindow() :
- // TRANSLATORS: mail window name
- Window(_("Mail"), Modal_false, nullptr, "mail.xml"),
- ActionListener(),
- mMessages(),
- mMessagesMap(),
- mMailModel(new ExtendedNamesModel),
- mListBox(CREATEWIDGETR(ExtendedListBox,
- this, mMailModel, "extendedlistbox.xml", 0)),
- mListScrollArea(new ScrollArea(this, mListBox,
- fromBool(getOptionBool("showlistbackground"), Opaque),
- "mail_listbackground.xml")),
- // TRANSLATORS: mail window button
- mRefreshButton(new Button(this, _("Refresh"), "refresh", this)),
- // TRANSLATORS: mail window button
- mNewButton(new Button(this, _("New"), "new", this)),
- // TRANSLATORS: mail window button
- mDeleteButton(new Button(this, _("Delete"), "delete", this)),
- mReturnButton(new Button(this,
- // TRANSLATORS: mail window button
- settings.enableNewMailSystem ? _("Get old") : _("Return"),
- "return", this)),
- // TRANSLATORS: mail window button
- mOpenButton(new Button(this, _("Open"), "open", this)),
- mOpenType(MailOpenType::Mail),
- mUseMail2(settings.enableNewMailSystem),
- mLastPage(false)
-{
- setWindowName("Mail");
- setCloseButton(true);
- setResizable(true);
- setCloseButton(true);
- setSaveVisible(true);
- setStickyButtonLock(true);
-
- if (setupWindow != nullptr)
- setupWindow->registerWindowForReset(this);
-
- setDefaultSize(310, 180, ImagePosition::CENTER);
- setMinWidth(310);
- setMinHeight(250);
- center();
-
- mListScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
-
- ContainerPlacer placer;
- placer = getPlacer(0, 0);
-
- placer(0, 0, mListScrollArea, 4, 5).setPadding(3);
- placer(4, 0, mRefreshButton);
- placer(4, 1, mOpenButton);
- placer(4, 2, mNewButton);
- placer(4, 3, mDeleteButton);
- placer(4, 4, mReturnButton);
-
- Layout &layout = getLayout();
- layout.setRowHeight(0, LayoutType::SET);
-
- loadWindowState();
- enableVisibleSound(true);
-}
-
-MailWindow::~MailWindow()
-{
- delete_all(mMessages);
- delete2(mMailModel);
- delete2(mailViewWindow);
- delete2(mailEditWindow);
-}
-
-void MailWindow::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "refresh")
- {
- refreshMails();
- }
- else if (eventId == "new")
- {
- if (mailEditWindow == nullptr)
- {
- CREATEWIDGETV0(mailEditWindow, MailEditWindow);
- }
- }
- else if (eventId == "open")
- {
- const int sel = mListBox->getSelected();
- if (sel < 0)
- return;
- const MailMessage *const mail = mMessages[sel];
- if (mUseMail2)
- mail2Handler->readMail(mOpenType, mail->id);
- else
- mailHandler->readMessage(CAST_S32(mail->id));
- }
- else if (eventId == "delete")
- {
- const int sel = mListBox->getSelected();
- if (sel < 0)
- return;
- const MailMessage *const mail = mMessages[sel];
- if (mUseMail2)
- mail2Handler->deleteMail(mOpenType, mail->id);
- else
- mailHandler->deleteMessage(CAST_S32(mail->id));
- }
- else if (eventId == "return")
- {
- if (mUseMail2)
- {
- const size_t idx = mMessages.size();
- if (idx == 0)
- mail2Handler->refreshMailList(MailOpenType::Mail, 0);
- else
- mail2Handler->nextPage(mOpenType, mMessages[idx - 1]->id);
- }
- else
- {
- const int sel = mListBox->getSelected();
- if (sel < 0)
- return;
- const MailMessage *const mail = mMessages[sel];
- mailHandler->returnMessage(CAST_S32(mail->id));
- }
- }
-}
-
-void MailWindow::clear()
-{
- delete_all(mMessages);
- mMessages.clear();
- mMessagesMap.clear();
- mMailModel->clear();
- mListBox->setSelected(-1);
-}
-
-std::string MailWindow::getMailHeader(const MailMessage *const message) const
-{
- if (mUseMail2)
- {
- std::string header;
- if (message->read)
- header.append(" ");
- else
- header.append("U");
- const MailMessageType::Type type = message->type;
- if ((type & MailMessageType::Money) != 0)
- header.append("M");
- else
- header.append(" ");
- if ((type & MailMessageType::Item) != 0)
- header.append("I");
- else
- header.append(" ");
- header.append(" ").append(message->title);
- return STD_MOVE(header);
- }
- return strprintf("%s %s",
- message->read ? " " : "U",
- message->title.c_str());
-}
-
-void MailWindow::addMail(MailMessage *const message)
-{
- if (message == nullptr)
- return;
- mMessages.push_back(message);
- mMailModel->add(getMailHeader(message));
- mMessagesMap[message->id] = message;
-}
-
-void MailWindow::removeMail(const int64_t id)
-{
- std::map<int64_t, MailMessage*>::iterator it1 = mMessagesMap.find(id);
- if (it1 != mMessagesMap.end())
- mMessagesMap.erase(it1);
-
- mMailModel->clear();
-
- FOR_EACH (STD_VECTOR<MailMessage*>::iterator, it, mMessages)
- {
- MailMessage *message = *it;
- if ((message != nullptr) && message->id == id)
- {
- mMessages.erase(it);
- delete message;
- break;
- }
- }
-
- FOR_EACH (STD_VECTOR<MailMessage*>::iterator, it, mMessages)
- {
- MailMessage *message = *it;
- if (message != nullptr)
- mMailModel->add(getMailHeader(message));
- }
-}
-
-void MailWindow::showMessage(MailMessage *const mail,
- const int itemsCount)
-{
- if (mail == nullptr)
- return;
- const std::map<int64_t, MailMessage*>::const_iterator
- it = mMessagesMap.find(mail->id);
- if (it != mMessagesMap.end())
- {
- const MailMessage *const mail2 = (*it).second;
- mail->time = mail2->time;
- mail->strTime = mail2->strTime;
- }
- delete mailViewWindow;
- CREATEWIDGETV(mailViewWindow, MailViewWindow, mail,
- itemsCount);
-}
-
-void MailWindow::viewNext(const int64_t id)
-{
- FOR_EACH (STD_VECTOR<MailMessage*>::iterator, it, mMessages)
- {
- MailMessage *message = *it;
- if (message != nullptr &&
- message->id == id)
- {
- ++ it;
- if (it == mMessages.end())
- {
- it = mMessages.begin();
- mListBox->setSelected(0);
- }
- else
- {
- mListBox->setSelected(mListBox->getSelected() + 1);
- }
- message = *it;
- if (mUseMail2)
- mail2Handler->readMail(mOpenType, message->id);
- else
- mailHandler->readMessage(CAST_S32(message->id));
- return;
- }
- }
-}
-
-void MailWindow::viewPrev(const int64_t id)
-{
- FOR_EACH (STD_VECTOR<MailMessage*>::iterator, it, mMessages)
- {
- MailMessage *message = *it;
- if (message != nullptr &&
- message->id == id)
- {
- if (it == mMessages.begin())
- {
- it = mMessages.end();
- mListBox->setSelected(CAST_S32(mMessages.size()) - 1);
- }
- else
- {
- mListBox->setSelected(mListBox->getSelected() - 1);
- }
- -- it;
- message = *it;
- if (mUseMail2)
- mail2Handler->readMail(mOpenType, message->id);
- else
- mailHandler->readMessage(CAST_S32(message->id));
- return;
- }
- }
-}
-
-void MailWindow::mouseClicked(MouseEvent &event)
-{
- if (event.getButton() == MouseButton::LEFT)
- {
- event.consume();
- if (event.getClickCount() == 2 &&
- event.getSource() == mListBox)
- {
- action(ActionEvent(mListBox, "open"));
- }
- }
-}
-
-void MailWindow::postConnection()
-{
- refreshMails();
-}
-
-void MailWindow::refreshMails()
-{
- if (mUseMail2)
- {
- clear();
- mail2Handler->refreshMailList(MailOpenType::Mail, 0);
- mLastPage = false;
- mReturnButton->setEnabled(true);
- }
- else
- {
- mailHandler->refresh();
- }
-}
-
-void MailWindow::createMail(const std::string &to)
-{
- if (mailEditWindow != nullptr)
- return;
-
- CREATEWIDGETV0(mailEditWindow, MailEditWindow);
- mailEditWindow->setTo(to);
-}
-
-MailMessage *MailWindow::findMail(const int64_t id)
-{
- std::map<int64_t, MailMessage*>::iterator it = mMessagesMap.find(id);
- if (it != mMessagesMap.end())
- return (*it).second;
- return nullptr;
-}
-
-void MailWindow::setLastPage()
-{
- mLastPage = true;
- mReturnButton->setEnabled(false);
-}
-
-void MailWindow::refreshMailNames()
-{
- mMailModel->clear();
- FOR_EACH (STD_VECTOR<MailMessage*>::iterator, it, mMessages)
- {
- MailMessage *message = *it;
- if (message != nullptr)
- mMailModel->add(getMailHeader(message));
- }
-}
diff --git a/src/gui/windows/mailwindow.h b/src/gui/windows/mailwindow.h
deleted file mode 100644
index c99236499..000000000
--- a/src/gui/windows/mailwindow.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_MAILWINDOW_H
-#define GUI_WINDOWS_MAILWINDOW_H
-
-#include "gui/widgets/window.h"
-
-#include "enums/net/mailopentype.h"
-
-#include "listeners/actionlistener.h"
-
-class Button;
-class ExtendedListBox;
-class ExtendedNamesModel;
-class ScrollArea;
-
-struct MailMessage;
-
-/**
- * A dialog to choose between buying or selling at a shop.
- *
- * \ingroup Interface
- */
-class MailWindow final : public Window,
- public ActionListener
-{
- public:
- MailWindow();
-
- A_DELETE_COPY(MailWindow)
-
- ~MailWindow();
-
- void action(const ActionEvent &event) override final;
-
- void addMail(MailMessage *const message);
-
- void clear() override final;
-
- void showMessage(MailMessage *const mail,
- const int itemsCount);
-
- void removeMail(const int64_t id);
-
- void viewNext(const int64_t id);
-
- void viewPrev(const int64_t id);
-
- void mouseClicked(MouseEvent &event) override final;
-
- void postConnection();
-
- void createMail(const std::string &to);
-
- MailMessage *findMail(const int64_t id) A_WARN_UNUSED;
-
- void setOpenType(const MailOpenTypeT &type)
- { mOpenType = type; }
-
- MailOpenTypeT getOpenType() const A_WARN_UNUSED
- { return mOpenType; }
-
- void setLastPage();
-
- void refreshMailNames();
-
- private:
- void refreshMails();
-
- std::string getMailHeader(const MailMessage *const message) const
- A_WARN_UNUSED A_NONNULL(2);
-
- STD_VECTOR<MailMessage*> mMessages;
- std::map<int64_t, MailMessage*> mMessagesMap;
- ExtendedNamesModel *mMailModel;
- ExtendedListBox *mListBox;
- ScrollArea *mListScrollArea;
- Button *mRefreshButton;
- Button *mNewButton;
- Button *mDeleteButton;
- Button *mReturnButton;
- Button *mOpenButton;
- MailOpenTypeT mOpenType;
- bool mUseMail2;
- bool mLastPage;
-};
-
-extern MailWindow *mailWindow;
-
-#endif // GUI_WINDOWS_MAILWINDOW_H
diff --git a/src/gui/windows/minimap.cpp b/src/gui/windows/minimap.cpp
deleted file mode 100644
index 7f48f4a10..000000000
--- a/src/gui/windows/minimap.cpp
+++ /dev/null
@@ -1,540 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/minimap.h"
-
-#include "actormanager.h"
-#include "configuration.h"
-#include "party.h"
-#include "settings.h"
-
-#include "being/localplayer.h"
-
-#include "enums/resources/map/blockmask.h"
-
-#include "fs/virtfs/fs.h"
-
-#include "gui/popupmanager.h"
-#include "gui/viewport.h"
-#include "gui/userpalette.h"
-
-#include "gui/popups/popupmenu.h"
-#include "gui/popups/textpopup.h"
-
-#include "gui/windows/setupwindow.h"
-
-#include "resources/imagehelper.h"
-
-#include "resources/image/image.h"
-
-#include "resources/map/map.h"
-#include "resources/map/metatile.h"
-
-#include "resources/loaders/imageloader.h"
-
-#include "utils/gettext.h"
-#include "utils/foreach.h"
-#include "utils/sdlcheckutils.h"
-#include "utils/stdmove.h"
-
-#include "debug.h"
-
-Minimap *minimap = nullptr;
-bool Minimap::mShow = true;
-
-Minimap::Minimap() :
- // TRANSLATORS: mini map window name
- Window(_("Map"), Modal_false, nullptr, "map.xml"),
- mWidthProportion(0.5),
- mHeightProportion(0.5),
- mMapImage(nullptr),
- mMapOriginX(0),
- mMapOriginY(0),
- mCustomMapImage(false),
- mAutoResize(config.getBoolValue("autoresizeminimaps"))
-{
- setWindowName("Minimap");
- mShow = config.getValueBool(getWindowName() + "Show", true);
-
- config.addListener("autoresizeminimaps", this);
-
- setDefaultSize(5, 25, 100, 100);
- // set this to false as the minimap window size is changed
- // depending on the map size
- setResizable(true);
- if (setupWindow != nullptr)
- setupWindow->registerWindowForReset(this);
-
- setDefaultVisible(true);
- setSaveVisible(true);
-
- setStickyButton(true);
- setSticky(false);
-
- loadWindowState();
- setVisible(fromBool(mShow, Visible), isSticky());
- enableVisibleSound(true);
-}
-
-Minimap::~Minimap()
-{
- config.setValue(getWindowName() + "Show", mShow);
- config.removeListeners(this);
- CHECKLISTENERS
- deleteMapImage();
-}
-
-void Minimap::deleteMapImage()
-{
- if (mMapImage != nullptr)
- {
- if (mCustomMapImage)
- delete mMapImage;
- else
- mMapImage->decRef();
- mMapImage = nullptr;
- }
-}
-
-void Minimap::setMap(const Map *const map)
-{
- BLOCK_START("Minimap::setMap")
- std::string caption;
-
- if (map != nullptr)
- caption = map->getName();
-
- if (caption.empty())
- {
- // TRANSLATORS: mini map window name
- caption = _("Map");
- }
-
- setCaption(caption);
- deleteMapImage();
-
- if (map != nullptr)
- {
- if (config.getBoolValue("showExtMinimaps"))
- {
- SDL_Surface *const surface = MSDL_CreateRGBSurface(SDL_SWSURFACE,
- map->getWidth(), map->getHeight(), 32,
- 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000);
- if (surface == nullptr)
- {
- if (!isSticky())
- setVisible(Visible_false);
- BLOCK_END("Minimap::setMap")
- return;
- }
-
- // I'm not sure if the locks are necessary since it's a SWSURFACE
- SDL_LockSurface(surface);
- int* data = static_cast<int*>(surface->pixels);
- if (data == nullptr)
- {
- if (!isSticky())
- setVisible(Visible_false);
- BLOCK_END("Minimap::setMap")
- return;
- }
- const int size = surface->h * surface->w;
- const int mask = (BlockMask::WALL |
- BlockMask::AIR |
- BlockMask::WATER |
- BlockMask::PLAYERWALL);
-
- for (int ptr = 0; ptr < size; ptr ++)
- {
- *(data ++) = (map->mMetaTiles[ptr].blockmask & mask) != 0 ?
- 0x0 : 0x00ffffff;
- }
-
- SDL_UnlockSurface(surface);
-
- mMapImage = imageHelper->loadSurface(surface);
- mMapImage->setAlpha(settings.guiAlpha);
- mCustomMapImage = true;
- MSDL_FreeSurface(surface);
- }
- else
- {
- std::string tempname = pathJoin(paths.getStringValue("minimaps"),
- map->getFilename()).append(".png");
-
- std::string minimapName = map->getProperty("minimap");
-
- if (minimapName.empty() && VirtFs::exists(tempname))
- minimapName = tempname;
-
- if (minimapName.empty())
- {
- tempname = pathJoin("graphics/minimaps",
- map->getFilename()).append(".png");
- if (VirtFs::exists(tempname))
- minimapName = STD_MOVE(tempname);
- }
-
- if (!minimapName.empty())
- mMapImage = Loader::getImage(minimapName);
- else
- mMapImage = nullptr;
- mCustomMapImage = false;
- }
- }
-
- if ((mMapImage != nullptr) && (map != nullptr))
- {
- const int width = mMapImage->mBounds.w + 2 * getPadding();
- const int height = mMapImage->mBounds.h
- + getTitleBarHeight() + getPadding();
- const int mapWidth = mMapImage->mBounds.w < 100 ? width : 100;
- const int mapHeight = mMapImage->mBounds.h < 100 ? height : 100;
- const int minWidth = mapWidth > 310 ? 310 : mapWidth;
- const int minHeight = mapHeight > 220 ? 220 : mapHeight;
-
- setMinWidth(minWidth);
- setMinHeight(minHeight);
-
- mWidthProportion = static_cast<float>(
- mMapImage->mBounds.w) / static_cast<float>(map->getWidth());
- mHeightProportion = static_cast<float>(
- mMapImage->mBounds.h) / static_cast<float>(map->getHeight());
-
- setMaxWidth(width);
- setMaxHeight(height);
- if (mAutoResize)
- {
- setWidth(width);
- setHeight(height);
- }
-
- const Rect &rect = mDimension;
- setDefaultSize(rect.x, rect.y, rect.width, rect.height);
- resetToDefaultSize();
-
- if (mShow)
- setVisible(Visible_true);
- }
- else
- {
- if (!isSticky())
- setVisible(Visible_false);
- }
- BLOCK_END("Minimap::setMap")
-}
-
-void Minimap::toggle()
-{
- setVisible(fromBool(!isWindowVisible(), Visible), isSticky());
- mShow = isWindowVisible();
-}
-
-void Minimap::draw(Graphics *const graphics)
-{
- BLOCK_START("Minimap::draw")
-
- Window::draw(graphics);
- draw2(graphics);
-}
-
-void Minimap::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("Minimap::draw")
-
- Window::safeDraw(graphics);
- draw2(graphics);
-}
-
-void Minimap::draw2(Graphics *const graphics)
-{
- if (userPalette == nullptr ||
- localPlayer == nullptr ||
- viewport == nullptr)
- {
- BLOCK_END("Minimap::draw")
- return;
- }
-
- const Rect a = getChildrenArea();
-
- graphics->pushClipArea(a);
-
- if (actorManager == nullptr)
- {
- BLOCK_END("Minimap::draw")
- return;
- }
-
- mMapOriginX = 0;
- mMapOriginY = 0;
-
- if (mMapImage != nullptr)
- {
- const SDL_Rect &rect = mMapImage->mBounds;
- const int w = rect.w;
- const int h = rect.h;
- if (w > a.width || h > a.height)
- {
- mMapOriginX = (a.width / 2) - (localPlayer->mPixelX +
- viewport->getCameraRelativeX() * mWidthProportion) / 32;
-
- mMapOriginY = (a.height / 2) - (localPlayer->mPixelY +
- viewport->getCameraRelativeY() * mHeightProportion) / 32;
-
- const int minOriginX = a.width - w;
- const int minOriginY = a.height - h;
-
- if (mMapOriginX < minOriginX)
- mMapOriginX = minOriginX;
- if (mMapOriginY < minOriginY)
- mMapOriginY = minOriginY;
- if (mMapOriginX > 0)
- mMapOriginX = 0;
- if (mMapOriginY > 0)
- mMapOriginY = 0;
- }
-
- graphics->drawImage(mMapImage, mMapOriginX, mMapOriginY);
- }
-
- const ActorSprites &actors = actorManager->getAll();
- FOR_EACH (ActorSpritesConstIterator, it, actors)
- {
- if (((*it) == nullptr) || (*it)->getType() == ActorType::FloorItem)
- continue;
-
- const Being *const being = static_cast<const Being *>(*it);
- if (being == nullptr)
- continue;
-
- int dotSize = 2;
- UserColorIdT type = UserColorId::PC;
-
- if (being == localPlayer)
- {
- type = UserColorId::SELF;
- dotSize = 3;
- }
- else if (being->isGM())
- {
- type = UserColorId::GM;
- }
- else if (being->getGuild() == localPlayer->getGuild()
- || being->getGuildName() == localPlayer->getGuildName())
- {
- type = UserColorId::GUILD;
- }
- else
- {
- switch (being->getType())
- {
- case ActorType::Monster:
- type = UserColorId::MONSTER;
- break;
-
- case ActorType::Npc:
- type = UserColorId::NPC;
- break;
-
- case ActorType::Portal:
- type = UserColorId::PORTAL_HIGHLIGHT;
- break;
-
- case ActorType::Pet:
- type = UserColorId::PET;
- break;
- case ActorType::Mercenary:
- type = UserColorId::MERCENARY;
- break;
-
- case ActorType::Homunculus:
- type = UserColorId::HOMUNCULUS;
- break;
-
- case ActorType::SkillUnit:
- type = UserColorId::SKILLUNIT;
- break;
- case ActorType::Avatar:
- case ActorType::Unknown:
- case ActorType::Player:
- case ActorType::FloorItem:
- case ActorType::Elemental:
- default:
- continue;
- }
- }
-
- if (userPalette != nullptr)
- graphics->setColor(userPalette->getColor(type));
-
- const int offsetHeight = CAST_S32(static_cast<float>(
- dotSize - 1) * mHeightProportion);
- const int offsetWidth = CAST_S32(static_cast<float>(
- dotSize - 1) * mWidthProportion);
- graphics->fillRectangle(Rect(
- (being->mPixelX * mWidthProportion) / 32
- + mMapOriginX - offsetWidth,
- (being->mPixelY * mHeightProportion) / 32
- + mMapOriginY - offsetHeight, dotSize, dotSize));
- }
-
- if (localPlayer->isInParty())
- {
- const Party *const party = localPlayer->getParty();
- if (party != nullptr)
- {
- const PartyMember *const m = party->getMember(
- localPlayer->getName());
- const Party::MemberList *const members = party->getMembers();
- if (m != nullptr)
- {
- const std::string curMap = m->getMap();
- Party::MemberList::const_iterator it = members->begin();
- const Party::MemberList::const_iterator
- it_end = members->end();
- while (it != it_end)
- {
- const PartyMember *const member = *it;
- if ((member != nullptr) && member->getMap() == curMap
- && member->getOnline() && member != m)
- {
- if (userPalette != nullptr)
- {
- graphics->setColor(userPalette->getColor(
- UserColorId::PARTY));
- }
-
- const int offsetHeight = CAST_S32(
- mHeightProportion);
- const int offsetWidth = CAST_S32(
- mWidthProportion);
-
- graphics->fillRectangle(Rect(
- CAST_S32(member->getX()
- * mWidthProportion) + mMapOriginX - offsetWidth,
- CAST_S32(member->getY()
- * mHeightProportion) + mMapOriginY - offsetHeight,
- 2, 2));
- }
- ++ it;
- }
- }
- }
- }
-
- const int gw = graphics->getWidth();
- const int gh = graphics->getHeight();
- int x = (localPlayer->mPixelX - (gw / 2)
- + viewport->getCameraRelativeX())
- * mWidthProportion / 32 + mMapOriginX;
- int y = (localPlayer->mPixelY - (gh / 2)
- + viewport->getCameraRelativeY())
- * mHeightProportion / 32 + mMapOriginY;
-
- const int w = CAST_S32(static_cast<float>(
- gw) * mWidthProportion / 32);
- const int h = CAST_S32(static_cast<float>(
- gh) * mHeightProportion / 32);
-
- if (w <= a.width)
- {
- if (x < 0 && (w != 0))
- x = 0;
- if (x + w > a.width)
- x = a.width - w;
- }
- if (h <= a.height)
- {
- if (y < 0 && (h != 0))
- y = 0;
- if (y + h > a.height)
- y = a.height - h;
- }
-
- graphics->setColor(userPalette->getColor(UserColorId::PC));
- graphics->drawRectangle(Rect(x, y, w, h));
- graphics->popClipArea();
- BLOCK_END("Minimap::draw")
-}
-
-void Minimap::mousePressed(MouseEvent &event)
-{
- if (event.getButton() == MouseButton::RIGHT)
- return;
- Window::mousePressed(event);
-}
-
-void Minimap::mouseReleased(MouseEvent &event)
-{
- Window::mouseReleased(event);
-
- if ((localPlayer == nullptr) || (popupManager == nullptr))
- return;
-
- if (event.getButton() == MouseButton::LEFT)
- {
- int x = event.getX();
- int y = event.getY();
- screenToMap(x, y);
-
- localPlayer->navigateTo(x, y);
- }
- else if (event.getButton() == MouseButton::RIGHT)
- {
- int x = event.getX();
- int y = event.getY();
- screenToMap(x, y);
- popupMenu->showMapPopup(viewport->mMouseX,
- viewport->mMouseY,
- x, y,
- true);
- }
-}
-
-void Minimap::mouseMoved(MouseEvent &event)
-{
- Window::mouseMoved(event);
- const int x = event.getX();
- const int y = event.getY();
- const Rect &rect = mDimension;
- textPopup->show(x + rect.x, y + rect.y, mCaption);
-}
-
-void Minimap::mouseExited(MouseEvent &event)
-{
- Window::mouseExited(event);
- textPopup->hide();
-}
-
-void Minimap::screenToMap(int &x, int &y)
-{
- const Rect a = getChildrenArea();
- x = (x - a.x - mMapOriginX + mWidthProportion) / mWidthProportion;
- y = (y - a.y - mMapOriginY + mHeightProportion) / mHeightProportion;
-}
-
-void Minimap::optionChanged(const std::string &name)
-{
- if (name == "autoresizeminimaps")
- mAutoResize = config.getBoolValue("autoresizeminimaps");
-}
diff --git a/src/gui/windows/minimap.h b/src/gui/windows/minimap.h
deleted file mode 100644
index 5aad6e8be..000000000
--- a/src/gui/windows/minimap.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_MINIMAP_H
-#define GUI_WINDOWS_MINIMAP_H
-
-#include "gui/widgets/window.h"
-
-class Image;
-class Map;
-
-/**
- * Minimap window. Shows a minimap image and the name of the current map.
- *
- * The name of the map is defined by the map property "name". The minimap image
- * is defined by the map property "minimap". The path to the image should be
- * given relative to the root of the client data.
- *
- * \ingroup Interface
- */
-class Minimap final : public Window, public ConfigListener
-{
- public:
- Minimap();
-
- A_DELETE_COPY(Minimap)
-
- ~Minimap();
-
- /**
- * Sets the map image that should be displayed.
- */
- void setMap(const Map *const map);
-
- /**
- * Toggles the displaying of the minimap.
- */
- void toggle();
-
- /**
- * Draws the minimap.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void draw2(Graphics *const graphics) A_NONNULL(2);
-
- void mouseMoved(MouseEvent &event) override final;
-
- void mouseReleased(MouseEvent &event) override final;
-
- void mousePressed(MouseEvent &event) override final;
-
- void mouseExited(MouseEvent &event) override final;
-
- void screenToMap(int &x, int &y);
-
- void optionChanged(const std::string &name) override final;
-
- private:
- void deleteMapImage();
-
- float mWidthProportion;
- float mHeightProportion;
- Image *mMapImage;
- int mMapOriginX;
- int mMapOriginY;
- bool mCustomMapImage;
- bool mAutoResize;
- static bool mShow;
-};
-
-extern Minimap *minimap;
-
-#endif // GUI_WINDOWS_MINIMAP_H
diff --git a/src/gui/windows/ministatuswindow.cpp b/src/gui/windows/ministatuswindow.cpp
deleted file mode 100644
index e596f1fae..000000000
--- a/src/gui/windows/ministatuswindow.cpp
+++ /dev/null
@@ -1,594 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/ministatuswindow.h"
-
-#include "configuration.h"
-
-#include "being/localplayer.h"
-#include "being/playerinfo.h"
-
-#include "gui/popupmanager.h"
-#include "gui/skin.h"
-
-#include "gui/popups/popupmenu.h"
-#include "gui/popups/statuspopup.h"
-#include "gui/popups/textpopup.h"
-
-#include "gui/windows/statuswindow.h"
-
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/progressbar.h"
-
-#include "net/playerhandler.h"
-
-#include "resources/inventory/inventory.h"
-
-#include "resources/sprite/animatedsprite.h"
-
-#include "utils/delete2.h"
-#include "utils/dtor.h"
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-MiniStatusWindow *miniStatusWindow = nullptr;
-extern volatile int tick_time;
-
-typedef STD_VECTOR <ProgressBar*>::const_iterator ProgressBarVectorCIter;
-
-MiniStatusWindow::MiniStatusWindow() :
- Window("MiniStatus", Modal_false, nullptr, "ministatus.xml"),
- InventoryListener(),
- AttributeListener(),
- StatListener(),
- ArrowsListener(),
- UpdateStatusListener(),
- mBars(),
- mBarNames(),
- mIcons(),
- mHpBar(createBar(0, 100, 0, ThemeColorId::HP_BAR, ProgressColorId::PROG_HP,
- "hpprogressbar.xml", "hpprogressbar_fill.xml",
- // TRANSLATORS: status bar name
- "hp bar", _("health bar"))),
- mMpBar(createBar(0, 100, 0, playerHandler->canUseMagic()
- ? ThemeColorId::MP_BAR : ThemeColorId::NO_MP_BAR,
- playerHandler->canUseMagic()
- ? ProgressColorId::PROG_MP : ProgressColorId::PROG_NO_MP,
- playerHandler->canUseMagic()
- ? "mpprogressbar.xml" : "nompprogressbar.xml",
- playerHandler->canUseMagic()
- ? "mpprogressbar_fill.xml" : "nompprogressbar_fill.xml",
- // TRANSLATORS: status bar name
- "mp bar", _("mana bar"))),
- mXpBar(createBar(0, 100, 0,
- ThemeColorId::XP_BAR, ProgressColorId::PROG_EXP,
- "xpprogressbar.xml", "xpprogressbar_fill.xml",
- // TRANSLATORS: status bar name
- "xp bar", _("experience bar"))),
- mJobBar(nullptr),
- mWeightBar(createBar(0, 140, 0, ThemeColorId::WEIGHT_BAR,
- ProgressColorId::PROG_WEIGHT,
- "weightprogressbar.xml", "weightprogressbar_fill.xml",
- // TRANSLATORS: status bar name
- "weight bar", _("weight bar"))),
- mInvSlotsBar(createBar(0, 45, 0,
- ThemeColorId::SLOTS_BAR, ProgressColorId::PROG_INVY_SLOTS,
- "slotsprogressbar.xml", "slotsprogressbar_fill.xml",
- "inventory slots bar",
- // TRANSLATORS: status bar name
- _("inventory slots bar"))),
- mMoneyBar(createBar(0, 130, 0, ThemeColorId::MONEY_BAR,
- ProgressColorId::PROG_MONEY,
- "moneyprogressbar.xml", "moneyprogressbar_fill.xml",
- // TRANSLATORS: status bar name
- "money bar", _("money bar"))),
- mArrowsBar(createBar(0, 50, 0, ThemeColorId::ARROWS_BAR,
- ProgressColorId::PROG_ARROWS,
- "arrowsprogressbar.xml", "arrowsprogressbar_fill.xml",
- // TRANSLATORS: status bar name
- "arrows bar", _("arrows bar"))),
- mStatusBar(createBar(100, (config.getIntValue("fontSize") > 16
- ? 270 : 180), 0, ThemeColorId::STATUS_BAR,
- ProgressColorId::PROG_STATUS,
- "statusprogressbar.xml", "statusprogressbar_fill.xml",
- // TRANSLATORS: status bar name
- "status bar", _("status bar"))),
- mStatusPopup(CREATEWIDGETR0(StatusPopup)),
- mSpacing(mSkin != nullptr ? mSkin->getOption("spacing", 3) : 3),
- mIconPadding(mSkin != nullptr ? mSkin->getOption("iconPadding", 3) : 3),
- mIconSpacing(mSkin != nullptr ? mSkin->getOption("iconSpacing", 2) : 2),
- mMaxX(0)
-{
- StatusWindow::updateHPBar(mHpBar);
-
- if (statusWindow != nullptr)
- statusWindow->updateMPBar(mMpBar);
-
- const bool job = serverConfig.getValueBool("showJob", true);
-
- StatusWindow::updateXPBar(mXpBar);
-
- if (job)
- {
- mJobBar = createBar(0, 100, 0,
- ThemeColorId::JOB_BAR,
- ProgressColorId::PROG_JOB,
- "jobprogressbar.xml", "jobprogressbar_fill.xml",
- // TRANSLATORS: status bar name
- "job bar", _("job bar"));
- StatusWindow::updateJobBar(mJobBar);
- }
-
- loadBars();
- updateBars();
-
- setVisible(Visible_true);
- addMouseListener(this);
- Inventory *const inv = PlayerInfo::getInventory();
- if (inv != nullptr)
- inv->addInventoyListener(this);
-
- StatusWindow::updateMoneyBar(mMoneyBar);
- StatusWindow::updateArrowsBar(mArrowsBar);
- updateStatus();
-}
-
-MiniStatusWindow::~MiniStatusWindow()
-{
- delete2(mStatusPopup);
- delete_all(mIcons);
- mIcons.clear();
-
- Inventory *const inv = PlayerInfo::getInventory();
- if (inv != nullptr)
- inv->removeInventoyListener(this);
-
- FOR_EACH (ProgressBarVectorCIter, it, mBars)
- {
- ProgressBar *bar = *it;
- if (bar == nullptr)
- continue;
- if (bar->mVisible == Visible_false)
- delete bar;
- }
- mBars.clear();
-}
-
-ProgressBar *MiniStatusWindow::createBar(const float progress,
- const int width,
- const int height,
- const ThemeColorIdT textColor,
- const ProgressColorIdT backColor,
- const std::string &restrict skin,
- const std::string &restrict skinFill,
- const std::string &restrict name,
- const std::string &restrict
- description)
-{
- ProgressBar *const bar = new ProgressBar(this,
- progress, width, height, backColor, skin, skinFill);
- bar->setActionEventId(name);
- bar->setId(description);
- bar->setColor(getThemeColor(textColor), getThemeColor(textColor + 1));
- mBars.push_back(bar);
- mBarNames[name] = bar;
- return bar;
-}
-
-void MiniStatusWindow::updateBars()
-{
- int x = 0;
- const ProgressBar *lastBar = nullptr;
- FOR_EACH (ProgressBarVectorCIter, it, mBars)
- remove(*it);
-
- FOR_EACH (ProgressBarVectorCIter, it, mBars)
- {
- ProgressBar *const bar = *it;
- if (bar == nullptr)
- continue;
- if (bar->mVisible == Visible_true)
- {
- bar->setPosition(x, 0);
- add(bar);
- x += bar->getWidth() + mSpacing;
- lastBar = bar;
- }
- }
-
- if (lastBar != nullptr)
- {
- setContentSize(lastBar->getX() + lastBar->getWidth(),
- lastBar->getY() + lastBar->getHeight());
- }
- mMaxX = x;
-}
-
-void MiniStatusWindow::setIcon(const int index, AnimatedSprite *const sprite)
-{
- if (index >= CAST_S32(mIcons.size()))
- mIcons.resize(index + 1, nullptr);
-
- delete mIcons[index];
- mIcons[index] = sprite;
-}
-
-void MiniStatusWindow::eraseIcon(const int index)
-{
- if (index < CAST_S32(mIcons.size()))
- {
- delete mIcons[index];
- mIcons.erase(mIcons.begin() + index);
- }
-}
-
-void MiniStatusWindow::drawIcons(Graphics *const graphics)
-{
- // Draw icons
- int icon_x = mMaxX + mIconPadding;
- for (size_t i = 0, sz = mIcons.size(); i < sz; i ++)
- {
- const AnimatedSprite *const icon = mIcons[i];
- if (icon != nullptr)
- {
- icon->draw(graphics, icon_x, mIconPadding);
- icon_x += mIconSpacing + icon->getWidth();
- }
- }
-}
-
-void MiniStatusWindow::statChanged(const AttributesT id A_UNUSED,
- const int oldVal1 A_UNUSED,
- const int oldVal2 A_UNUSED)
-{
- if (statusWindow != nullptr)
- statusWindow->updateMPBar(mMpBar);
- StatusWindow::updateJobBar(mJobBar);
-}
-
-void MiniStatusWindow::attributeChanged(const AttributesT id,
- const int64_t oldVal A_UNUSED,
- const int64_t newVal A_UNUSED)
-{
- PRAGMA45(GCC diagnostic push)
- PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
- switch (id)
- {
- case Attributes::PLAYER_HP:
- case Attributes::PLAYER_MAX_HP:
- StatusWindow::updateHPBar(mHpBar);
- break;
- case Attributes::PLAYER_MP:
- case Attributes::PLAYER_MAX_MP:
- statusWindow->updateMPBar(mMpBar);
- break;
- case Attributes::PLAYER_EXP:
- case Attributes::PLAYER_EXP_NEEDED:
- StatusWindow::updateXPBar(mXpBar);
- break;
- case Attributes::TOTAL_WEIGHT:
- case Attributes::MAX_WEIGHT:
- StatusWindow::updateWeightBar(mWeightBar);
- break;
- case Attributes::MONEY:
- StatusWindow::updateMoneyBar(mMoneyBar);
- break;
- default:
- break;
- }
- PRAGMA45(GCC diagnostic pop)
-}
-
-void MiniStatusWindow::updateStatus()
-{
- if (statusWindow != nullptr)
- statusWindow->updateStatusBar(mStatusBar);
- if ((mStatusPopup != nullptr) && mStatusPopup->isPopupVisible())
- mStatusPopup->update();
-}
-
-void MiniStatusWindow::logic()
-{
- BLOCK_START("MiniStatusWindow::logic")
- Window::logic();
-
- for (size_t i = 0, sz = mIcons.size(); i < sz; i++)
- {
- AnimatedSprite *const icon = mIcons[i];
- if (icon != nullptr)
- icon->update(tick_time * 10);
- }
- BLOCK_END("MiniStatusWindow::logic")
-}
-
-void MiniStatusWindow::draw(Graphics *const graphics)
-{
- BLOCK_START("MiniStatusWindow::draw")
- drawChildren(graphics);
- BLOCK_END("MiniStatusWindow::draw")
-}
-
-void MiniStatusWindow::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("MiniStatusWindow::draw")
- safeDrawChildren(graphics);
- BLOCK_END("MiniStatusWindow::draw")
-}
-
-void MiniStatusWindow::mouseMoved(MouseEvent &event)
-{
- Window::mouseMoved(event);
-
- const int x = event.getX();
- const int y = event.getY();
-
- const Rect &rect = mDimension;
- if (event.getSource() == mStatusBar)
- {
- mStatusPopup->view(x + rect.x, y + rect.y);
- textPopup->hide();
- }
- else if (event.getSource() == mXpBar)
- {
- std::string level;
- if ((localPlayer != nullptr) && localPlayer->isGM())
- {
- // TRANSLATORS: status bar label
- level = strprintf(_("Level: %d (GM %d)"),
- PlayerInfo::getAttribute(Attributes::PLAYER_BASE_LEVEL),
- localPlayer->getGroupId());
- }
- else
- {
- // TRANSLATORS: status bar label
- level = strprintf(_("Level: %d"),
- PlayerInfo::getAttribute(Attributes::PLAYER_BASE_LEVEL));
- }
-
- const int64_t exp = PlayerInfo::getAttribute64(Attributes::PLAYER_EXP);
- const int64_t expNeed = PlayerInfo::getAttribute64(
- Attributes::PLAYER_EXP_NEEDED);
- const std::string str = toString(CAST_U64(exp)) +
- "/" +
- toString(CAST_U64(expNeed));
- if (exp > expNeed)
- {
- textPopup->show(x + rect.x,
- y + rect.y,
- level,
- str);
- }
- else
- {
- const std::string str2 = toString(CAST_U64(expNeed - exp));
- textPopup->show(x + rect.x,
- y + rect.y,
- level,
- str,
- // TRANSLATORS: status bar label
- strprintf("%s: %s", _("Need"), str2.c_str()));
- }
- mStatusPopup->hide();
- }
- else if (event.getSource() == mHpBar)
- {
- textPopup->show(x + rect.x, y + rect.y, event.getSource()->getId(),
- strprintf("%d/%d", PlayerInfo::getAttribute(Attributes::PLAYER_HP),
- PlayerInfo::getAttribute(Attributes::PLAYER_MAX_HP)));
- mStatusPopup->hide();
- }
- else if (event.getSource() == mMpBar)
- {
- textPopup->show(x + rect.x, y + rect.y, event.getSource()->getId(),
- strprintf("%d/%d", PlayerInfo::getAttribute(Attributes::PLAYER_MP),
- PlayerInfo::getAttribute(Attributes::PLAYER_MAX_MP)));
- mStatusPopup->hide();
- }
- else if (event.getSource() == mJobBar)
- {
- const int64_t exp = PlayerInfo::getAttribute64(
- Attributes::PLAYER_JOB_EXP);
- const int64_t expNeed = PlayerInfo::getAttribute64(
- Attributes::PLAYER_JOB_EXP_NEEDED);
- const int32_t jobLevel = PlayerInfo::getAttribute(
- Attributes::PLAYER_JOB_LEVEL);
- const std::string expStr = toString(CAST_U64(exp));
- const std::string expNeedStr = toString(CAST_U64(expNeed));
- const std::string expLeftStr = toString(CAST_U64(expNeed - exp));
-
- // TRANSLATORS: job bar label
- const std::string level = strprintf(_("Job level: %d"),
- jobLevel);
-
- if (exp > expNeed)
- {
- textPopup->show(x + rect.x,
- y + rect.y,
- level,
- strprintf("%s/%s", expStr.c_str(), expNeedStr.c_str()));
- }
- else
- {
- textPopup->show(x + rect.x,
- y + rect.y,
- level,
- strprintf("%s/%s", expStr.c_str(), expNeedStr.c_str()),
- // TRANSLATORS: status bar label
- strprintf("%s: %s", _("Need"), expLeftStr.c_str()));
- }
- mStatusPopup->hide();
- }
- else if (event.getSource() == mWeightBar)
- {
- textPopup->show(x + rect.x, y + rect.y, event.getSource()->getId(),
- strprintf("%d/%d", PlayerInfo::getAttribute(
- Attributes::TOTAL_WEIGHT),
- PlayerInfo::getAttribute(Attributes::MAX_WEIGHT)));
- mStatusPopup->hide();
- }
- else if (event.getSource() == mInvSlotsBar)
- {
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv != nullptr)
- {
- const int usedSlots = inv->getNumberOfSlotsUsed();
- const int maxSlots = inv->getSize();
- textPopup->show(x + rect.x, y + rect.y,
- event.getSource()->getId(),
- strprintf("%d/%d", usedSlots, maxSlots));
- }
- mStatusPopup->hide();
- }
- else if (event.getSource() == mMoneyBar)
- {
- textPopup->show(x + rect.x, y + rect.y,
- event.getSource()->getId(),
- toString(PlayerInfo::getAttribute(Attributes::MONEY)));
- }
- else
- {
- textPopup->hide();
- mStatusPopup->hide();
- }
-}
-
-void MiniStatusWindow::mousePressed(MouseEvent &event)
-{
- if (event.getButton() == MouseButton::RIGHT)
- {
- const ProgressBar *const bar = dynamic_cast<ProgressBar*>(
- event.getSource());
- if (bar == nullptr)
- return;
- event.consume();
- if (popupManager != nullptr)
- {
- popupMenu->showPopup(getX() + event.getX(),
- getY() + event.getY(), bar);
- }
- }
-}
-
-void MiniStatusWindow::mouseExited(MouseEvent &event)
-{
- Window::mouseExited(event);
-
- textPopup->hide();
- mStatusPopup->hide();
-}
-
-void MiniStatusWindow::showBar(const std::string &name,
- const Visible visible)
-{
- ProgressBar *const bar = mBarNames[name];
- if (bar == nullptr)
- return;
- bar->setVisible(visible);
- updateBars();
- saveBars();
-}
-
-void MiniStatusWindow::loadBars()
-{
- if (config.getIntValue("ministatussaved") == 0)
- {
- if (mWeightBar != nullptr)
- mWeightBar->setVisible(Visible_false);
- if (mInvSlotsBar != nullptr)
- mInvSlotsBar->setVisible(Visible_false);
- if (mMoneyBar != nullptr)
- mMoneyBar->setVisible(Visible_false);
- if (mArrowsBar != nullptr)
- mArrowsBar->setVisible(Visible_false);
- if (mStatusBar != nullptr)
- mStatusBar->setVisible(Visible_false);
- if (mJobBar != nullptr)
- mJobBar->setVisible(Visible_true);
- return;
- }
-
- for (int f = 0; f < 10; f ++)
- {
- const std::string str = config.getValue(
- "ministatus" + toString(f), "");
- if (str.empty())
- continue;
- ProgressBar *const bar = mBarNames[str];
- if (bar == nullptr)
- continue;
- bar->setVisible(Visible_false);
- }
-}
-
-void MiniStatusWindow::saveBars() const
-{
- int i = 0;
- FOR_EACH (ProgressBarVectorCIter, it, mBars)
- {
- const ProgressBar *const bar = *it;
- if (bar->mVisible == Visible_false)
- {
- config.setValue("ministatus" + toString(i),
- bar->getActionEventId());
- i ++;
- }
- }
- for (int f = i; f < 10; f ++)
- config.deleteKey("ministatus" + toString(f));
-
- config.setValue("ministatussaved", true);
-}
-
-void MiniStatusWindow::slotsChanged(const Inventory *const inventory)
-{
- if (inventory == nullptr)
- return;
-
- if (inventory->getType() == InventoryType::Inventory)
- StatusWindow::updateInvSlotsBar(mInvSlotsBar);
-}
-
-Rect MiniStatusWindow::getChildrenArea()
-{
- const int padding = mPadding;
- const int padding2 = padding * 2;
- const Rect &rect = mDimension;
- return Rect(padding, padding,
- rect.width - padding2,
- rect.height - padding2);
-}
-
-void MiniStatusWindow::arrowsChanged()
-{
- StatusWindow::updateArrowsBar(mArrowsBar);
-}
-
-#ifdef USE_PROFILER
-void MiniStatusWindow::logicChildren()
-{
- BLOCK_START("MiniStatusWindow::logicChildren")
- BasicContainer::logicChildren();
- BLOCK_END("MiniStatusWindow::logicChildren")
-}
-#endif // USE_PROFILER
diff --git a/src/gui/windows/ministatuswindow.h b/src/gui/windows/ministatuswindow.h
deleted file mode 100644
index 9d6e19ac7..000000000
--- a/src/gui/windows/ministatuswindow.h
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_MINISTATUSWINDOW_H
-#define GUI_WINDOWS_MINISTATUSWINDOW_H
-
-#include "listeners/arrowslistener.h"
-#include "listeners/attributelistener.h"
-#include "listeners/inventorylistener.h"
-#include "listeners/statlistener.h"
-#include "listeners/updatestatuslistener.h"
-
-#include "gui/widgets/window.h"
-
-class AnimatedSprite;
-class Graphics;
-class Inventory;
-class ProgressBar;
-class StatusPopup;
-
-/**
- * The player mini-status dialog.
- *
- * \ingroup Interface
- */
-class MiniStatusWindow final : public Window,
- public InventoryListener,
- public AttributeListener,
- public StatListener,
- public ArrowsListener,
- public UpdateStatusListener
-{
- public:
- MiniStatusWindow();
-
- A_DELETE_COPY(MiniStatusWindow)
-
- ~MiniStatusWindow();
-
- /**
- * Sets one of the icons.
- */
- void setIcon(const int index, AnimatedSprite *const sprite);
-
- void eraseIcon(const int index);
-
- void drawIcons(Graphics *const graphics) A_NONNULL(2);
-
- void updateStatus() override final;
-
- void logic() override final;
-
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void mouseMoved(MouseEvent &event) override final;
-
- void mousePressed(MouseEvent &event) override final;
-
- void mouseExited(MouseEvent &event) override final;
-
- void showBar(const std::string &name, const Visible visible);
-
- void updateBars();
-
- void slotsChanged(const Inventory *const inventory) override final;
-
- STD_VECTOR <ProgressBar*> &getBars() A_WARN_UNUSED
- { return mBars; }
-
- Rect getChildrenArea() override final A_WARN_UNUSED;
-
- void attributeChanged(const AttributesT id,
- const int64_t oldVal,
- const int64_t newVal) override final;
-
- void statChanged(const AttributesT id,
- const int oldVal1,
- const int oldVal2) override final;
-
- void arrowsChanged() override final;
-
-#ifdef USE_PROFILER
- void logicChildren();
-#endif // USE_PROFILER
-
- private:
- bool isInBar(ProgressBar *bar, int x, int y) const;
-
- ProgressBar *createBar(const float progress,
- const int width,
- const int height,
- const ThemeColorIdT textColor,
- const ProgressColorIdT backColor,
- const std::string &restrict skin,
- const std::string &restrict skinFill,
- const std::string &restrict name,
- const std::string &restrict description)
- A_WARN_UNUSED;
-
- void loadBars();
-
- void saveBars() const;
-
- STD_VECTOR <ProgressBar*> mBars;
- std::map <std::string, ProgressBar*> mBarNames;
- STD_VECTOR<AnimatedSprite *> mIcons;
-
- /*
- * Mini Status Bars
- */
- ProgressBar *mHpBar;
- ProgressBar *mMpBar;
- ProgressBar *mXpBar;
- ProgressBar *mJobBar;
- ProgressBar *mWeightBar;
- ProgressBar *mInvSlotsBar;
- ProgressBar *mMoneyBar;
- ProgressBar *mArrowsBar;
- ProgressBar *mStatusBar;
- StatusPopup *mStatusPopup;
-
- int mSpacing;
- int mIconPadding;
- int mIconSpacing;
- int mMaxX;
-};
-
-extern MiniStatusWindow *miniStatusWindow;
-
-#endif // GUI_WINDOWS_MINISTATUSWINDOW_H
diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp
deleted file mode 100644
index fb38dcc72..000000000
--- a/src/gui/windows/npcdialog.cpp
+++ /dev/null
@@ -1,1395 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/npcdialog.h"
-
-#include "actormanager.h"
-#include "configuration.h"
-#include "settings.h"
-#include "soundmanager.h"
-
-#include "const/sound.h"
-
-#include "being/being.h"
-#include "being/playerinfo.h"
-
-#include "enums/gui/layouttype.h"
-
-#include "gui/gui.h"
-#include "gui/viewport.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/popups/popupmenu.h"
-
-#include "gui/windows/cutinwindow.h"
-#include "gui/windows/inventorywindow.h"
-
-#include "gui/widgets/browserbox.h"
-#include "gui/widgets/button.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/icon.h"
-#include "gui/widgets/inttextfield.h"
-#include "gui/widgets/itemcontainer.h"
-#include "gui/widgets/itemlinkhandler.h"
-#include "gui/widgets/layout.h"
-#include "gui/widgets/extendedlistbox.h"
-#include "gui/widgets/playerbox.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "resources/npcdialoginfo.h"
-
-#include "resources/db/avatardb.h"
-#include "resources/db/npcdb.h"
-#include "resources/db/npcdialogdb.h"
-
-#include "resources/inventory/complexinventory.h"
-
-#include "resources/item/complexitem.h"
-
-#include "resources/loaders/imageloader.h"
-
-#include "net/npchandler.h"
-#include "net/packetlimiter.h"
-
-#include "utils/copynpaste.h"
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-
-#include <sstream>
-
-#include "debug.h"
-
-// TRANSLATORS: npc dialog button
-#define CAPTION_WAITING _("Stop waiting")
-// TRANSLATORS: npc dialog button
-#define CAPTION_NEXT _("Next")
-// TRANSLATORS: npc dialog button
-#define CAPTION_CLOSE _("Close")
-// TRANSLATORS: npc dialog button
-#define CAPTION_SUBMIT _("Submit")
-
-NpcDialog::DialogList NpcDialog::instances;
-NpcDialogs NpcDialog::mNpcDialogs;
-
-typedef STD_VECTOR<Image *>::iterator ImageVectorIter;
-
-NpcDialog::NpcDialog(const BeingId npcId) :
- // TRANSLATORS: npc dialog name
- Window(_("NPC"), Modal_false, nullptr, "npc.xml"),
- ActionListener(),
- mNpcId(npcId),
- mDefaultInt(0),
- mDefaultString(),
- mTextBox(new BrowserBox(this, Opaque_true,
- "browserbox.xml")),
- mScrollArea(new ScrollArea(this, mTextBox,
- fromBool(getOptionBool("showtextbackground"), Opaque),
- "npc_textbackground.xml")),
- mText(),
- mNewText(),
- mItems(),
- mImages(),
- mItemList(CREATEWIDGETR(ExtendedListBox,
- this, this, "extendedlistbox.xml")),
- mListScrollArea(new ScrollArea(this, mItemList,
- fromBool(getOptionBool("showlistbackground"), Opaque),
- "npc_listbackground.xml")),
- mSkinContainer(new Container(this)),
- mSkinScrollArea(new ScrollArea(this, mSkinContainer,
- fromBool(getOptionBool("showlistbackground"), Opaque),
- "npc_listbackground.xml")),
- mItemLinkHandler(new ItemLinkHandler),
- mTextField(new TextField(this, "")),
- mIntField(new IntTextField(this)),
- // TRANSLATORS: npc dialog button
- mPlusButton(new Button(this, _("+"), "inc", this)),
- // TRANSLATORS: npc dialog button
- mMinusButton(new Button(this, _("-"), "dec", this)),
- // TRANSLATORS: npc dialog button
- mClearButton(new Button(this, _("Clear"), "clear", this)),
- mButton(new Button(this, "", "ok", this)),
- // TRANSLATORS: npc dialog button
- mButton2(new Button(this, _("Close"), "close", this)),
- // TRANSLATORS: npc dialog button
- mButton3(new Button(this, _("Add"), "add", this)),
- // TRANSLATORS: npc dialog button
- mResetButton(new Button(this, _("Reset"), "reset", this)),
- mInventory(new Inventory(InventoryType::Npc, 1)),
- mComplexInventory(new ComplexInventory(InventoryType::Craft, 1)),
- mItemContainer(new ItemContainer(this, mInventory,
- 10000, ShowEmptyRows_true)),
- mItemScrollArea(new ScrollArea(this, mItemContainer,
- fromBool(getOptionBool("showitemsbackground"), Opaque),
- "npc_listbackground.xml")),
- mInputState(NpcInputState::NONE),
- mActionState(NpcActionState::WAIT),
- mSkinControls(),
- mSkinName(),
- mPlayerBox(new PlayerBox(nullptr)),
- mAvatarBeing(nullptr),
- mDialogInfo(nullptr),
- mLastNextTime(0),
- mCameraMode(-1),
- mCameraX(0),
- mCameraY(0),
- mShowAvatar(false),
- mLogInteraction(config.getBoolValue("logNpcInGui"))
-{
- // Basic Window Setup
- setWindowName("NpcText");
- setResizable(true);
- setFocusable(true);
- setStickyButtonLock(true);
-
- setMinWidth(200);
- setMinHeight(150);
-
- setDefaultSize(300, 578, ImagePosition::LOWER_LEFT);
-
- mPlayerBox->setWidth(70);
- mPlayerBox->setHeight(100);
-
- // Setup output text box
- mTextBox->setOpaque(Opaque_false);
- mTextBox->setMaxRow(config.getIntValue("ChatLogLength"));
- mTextBox->setLinkHandler(mItemLinkHandler);
- mTextBox->setProcessVars(true);
- mTextBox->setFont(gui->getNpcFont());
- mTextBox->setEnableKeys(true);
- mTextBox->setEnableTabs(true);
- mTextBox->setEnableImages(true);
-
- mScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- mScrollArea->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS);
-
- // Setup listbox
- mItemList->setWrappingEnabled(true);
- mItemList->setActionEventId("ok");
- mItemList->addActionListener(this);
- mItemList->setDistributeMousePressed(false);
- mItemList->setFont(gui->getNpcFont());
- if (gui->getNpcFont()->getHeight() < 20)
- mItemList->setRowHeight(20);
- else
- mItemList->setRowHeight(gui->getNpcFont()->getHeight());
-
- setContentSize(260, 175);
- mListScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- mItemScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- mSkinScrollArea->setScrollPolicy(ScrollArea::SHOW_NEVER,
- ScrollArea::SHOW_NEVER);
- mItemList->setVisible(Visible_true);
- mTextField->setVisible(Visible_true);
- mIntField->setVisible(Visible_true);
-
- const Font *const fnt = mButton->getFont();
- int width = std::max(fnt->getWidth(CAPTION_WAITING),
- fnt->getWidth(CAPTION_NEXT));
- width = std::max(width, fnt->getWidth(CAPTION_CLOSE));
- width = std::max(width, fnt->getWidth(CAPTION_SUBMIT));
- mButton->setWidth(8 + width);
-
- // Place widgets
- buildLayout();
-
- center();
- loadWindowState();
-
- instances.push_back(this);
-}
-
-void NpcDialog::postInit()
-{
- Window::postInit();
- setVisible(Visible_true);
- requestFocus();
- enableVisibleSound(true);
- soundManager.playGuiSound(SOUND_SHOW_WINDOW);
-
- if (actorManager != nullptr)
- {
- const Being *const being = actorManager->findBeing(mNpcId);
- if (being != nullptr)
- {
- showAvatar(NPCDB::getAvatarFor(fromInt(
- being->getSubType(), BeingTypeId)));
- setCaption(being->getName());
- }
- }
-
- config.addListener("logNpcInGui", this);
-}
-
-NpcDialog::~NpcDialog()
-{
- config.removeListeners(this);
- CHECKLISTENERS
- clearLayout();
-
- if (mPlayerBox != nullptr)
- {
- delete mPlayerBox->getBeing();
- delete mPlayerBox;
- }
-
- deleteSkinControls();
-
- delete2(mTextBox);
- delete2(mClearButton);
- delete2(mButton);
- delete2(mButton2);
- delete2(mButton3);
- delete2(mScrollArea);
- delete2(mItemList);
- delete2(mTextField);
- delete2(mIntField);
- delete2(mResetButton);
- delete2(mPlusButton);
- delete2(mMinusButton);
- delete2(mItemLinkHandler);
- delete2(mItemContainer);
- delete2(mInventory);
- delete2(mComplexInventory);
- delete2(mItemScrollArea);
- delete2(mListScrollArea);
- delete2(mSkinScrollArea);
-
- FOR_EACH (ImageVectorIter, it, mImages)
- {
- if (*it != nullptr)
- (*it)->decRef();
- }
-
- mImages.clear();
-
- instances.remove(this);
-}
-
-void NpcDialog::addText(const std::string &text, const bool save)
-{
- if (save || mLogInteraction)
- {
- if (mText.size() > 5000)
- mText.clear();
-
- mNewText.append(text);
- mTextBox->addRow(text);
- }
- mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll());
- mActionState = NpcActionState::WAIT;
- buildLayout();
-}
-
-void NpcDialog::showNextButton()
-{
- mActionState = NpcActionState::NEXT;
- buildLayout();
-}
-
-void NpcDialog::showCloseButton()
-{
- mActionState = NpcActionState::CLOSE;
- buildLayout();
-}
-
-void NpcDialog::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "ok")
- {
- if (mActionState == NpcActionState::NEXT)
- {
- if (!PacketLimiter::limitPackets(PacketType::PACKET_NPC_NEXT))
- return;
-
- nextDialog();
- addText(std::string(), false);
- }
- else if (mActionState == NpcActionState::CLOSE
- || mActionState == NpcActionState::WAIT)
- {
- if (cutInWindow != nullptr)
- cutInWindow->hide();
- closeDialog();
- }
- else if (mActionState == NpcActionState::INPUT)
- {
- std::string printText; // Text that will get printed
- // in the textbox
- switch (mInputState)
- {
- case NpcInputState::LIST:
- {
- if (mDialogInfo != nullptr)
- return;
- if (gui != nullptr)
- gui->resetClickCount();
- const int selectedIndex = mItemList->getSelected();
-
- if (selectedIndex >= CAST_S32(mItems.size())
- || selectedIndex < 0
- || !PacketLimiter::limitPackets(
- PacketType::PACKET_NPC_INPUT))
- {
- return;
- }
- unsigned char choice = CAST_U8(
- selectedIndex + 1);
- printText = mItems[selectedIndex];
-
- npcHandler->listInput(mNpcId, choice);
- break;
- }
- case NpcInputState::STRING:
- {
- if (!PacketLimiter::limitPackets(
- PacketType::PACKET_NPC_INPUT))
- {
- return;
- }
- printText = mTextField->getText();
- npcHandler->stringInput(mNpcId, printText);
- break;
- }
- case NpcInputState::INTEGER:
- {
- if (!PacketLimiter::limitPackets(
- PacketType::PACKET_NPC_INPUT))
- {
- return;
- }
- printText = strprintf("%d", mIntField->getValue());
- npcHandler->integerInput(
- mNpcId, mIntField->getValue());
- break;
- }
- case NpcInputState::ITEM:
- {
- restoreVirtuals();
- if (!PacketLimiter::limitPackets(
- PacketType::PACKET_NPC_INPUT))
- {
- return;
- }
-
- std::string str;
- const int sz = mInventory->getSize();
- if (sz == 0)
- {
- str = "0,0";
- }
- else
- {
- const Item *item = mInventory->getItem(0);
- if (item != nullptr)
- {
- str = strprintf("%d,%d", item->getId(),
- toInt(item->getColor(), int));
- }
- else
- {
- str = "0,0";
- }
- for (int f = 1; f < sz; f ++)
- {
- str.append(";");
- item = mInventory->getItem(f);
- if (item != nullptr)
- {
- str.append(strprintf("%d,%d", item->getId(),
- toInt(item->getColor(), int)));
- }
- else
- {
- str.append("0,0");
- }
- }
- }
-
- // need send selected item
- npcHandler->stringInput(mNpcId, str);
- mInventory->clear();
- break;
- }
- case NpcInputState::ITEM_INDEX:
- {
- restoreVirtuals();
- if (!PacketLimiter::limitPackets(
- PacketType::PACKET_NPC_INPUT))
- {
- return;
- }
-
- std::string str;
- const int sz = mInventory->getSize();
- if (sz == 0)
- {
- str = "-1";
- }
- else
- {
- const Item *item = mInventory->getItem(0);
- if (item != nullptr)
- {
- str = strprintf("%d", item->getTag());
- }
- else
- {
- str = "-1";
- }
- for (int f = 1; f < sz; f ++)
- {
- str.append(";");
- item = mInventory->getItem(f);
- if (item != nullptr)
- str.append(strprintf("%d", item->getTag()));
- else
- str.append("-1");
- }
- }
-
- // need send selected item
- npcHandler->stringInput(mNpcId, str);
- mInventory->clear();
- break;
- }
- case NpcInputState::ITEM_CRAFT:
- {
- restoreVirtuals();
- if (!PacketLimiter::limitPackets(
- PacketType::PACKET_NPC_INPUT))
- {
- return;
- }
-
- std::string str;
- const int sz = mComplexInventory->getSize();
- if (sz == 0)
- {
- str.clear();
- }
- else
- {
- const ComplexItem *item = dynamic_cast<ComplexItem*>(
- mComplexInventory->getItem(0));
- str = complexItemToStr(item);
- for (int f = 1; f < sz; f ++)
- {
- str.append("|");
- item = dynamic_cast<ComplexItem*>(
- mComplexInventory->getItem(f));
- str.append(complexItemToStr(item));
- }
- }
-
- // need send selected item
- npcHandler->stringInput(mNpcId, str);
- mInventory->clear();
- break;
- }
-
- case NpcInputState::NONE:
- default:
- break;
- }
- if (mInputState != NpcInputState::ITEM &&
- mInputState != NpcInputState::ITEM_INDEX &&
- mInputState != NpcInputState::ITEM_CRAFT)
- {
- // addText will auto remove the input layout
- addText(strprintf("> \"%s\"", printText.c_str()), false);
- }
- mNewText.clear();
- }
-
- if (!mLogInteraction)
- mTextBox->clearRows();
- }
- else if (eventId == "reset")
- {
- switch (mInputState)
- {
- case NpcInputState::STRING:
- mTextField->setText(mDefaultString);
- break;
- case NpcInputState::INTEGER:
- mIntField->setValue(mDefaultInt);
- break;
- case NpcInputState::ITEM:
- case NpcInputState::ITEM_INDEX:
- mInventory->clear();
- break;
- case NpcInputState::ITEM_CRAFT:
- mComplexInventory->clear();
- break;
- case NpcInputState::NONE:
- case NpcInputState::LIST:
- default:
- break;
- }
- }
- else if (eventId == "inc")
- {
- mIntField->setValue(mIntField->getValue() + 1);
- }
- else if (eventId == "dec")
- {
- mIntField->setValue(mIntField->getValue() - 1);
- }
- else if (eventId == "clear")
- {
- switch (mInputState)
- {
- case NpcInputState::ITEM:
- case NpcInputState::ITEM_INDEX:
- mInventory->clear();
- break;
- case NpcInputState::ITEM_CRAFT:
- mComplexInventory->clear();
- break;
- case NpcInputState::STRING:
- case NpcInputState::INTEGER:
- case NpcInputState::LIST:
- case NpcInputState::NONE:
- default:
- clearRows();
- break;
- }
- }
- else if (eventId == "close")
- {
- restoreVirtuals();
- if (mActionState == NpcActionState::INPUT)
- {
- switch (mInputState)
- {
- case NpcInputState::ITEM:
- npcHandler->stringInput(mNpcId, "0,0");
- break;
- case NpcInputState::ITEM_INDEX:
- npcHandler->stringInput(mNpcId, "-1");
- break;
- case NpcInputState::ITEM_CRAFT:
- npcHandler->stringInput(mNpcId, "");
- break;
- case NpcInputState::STRING:
- case NpcInputState::INTEGER:
- case NpcInputState::NONE:
- case NpcInputState::LIST:
- default:
- npcHandler->listInput(mNpcId, 255);
- break;
- }
- if (cutInWindow != nullptr)
- cutInWindow->hide();
- closeDialog();
- }
- }
- else if (eventId == "add")
- {
- if (inventoryWindow != nullptr)
- {
- Item *const item = inventoryWindow->getSelectedItem();
- Inventory *const inventory = PlayerInfo::getInventory();
- if (inventory != nullptr)
- {
- if (mInputState == NpcInputState::ITEM_CRAFT)
- {
- if (mComplexInventory->addVirtualItem(item, -1, 1))
- inventory->virtualRemove(item, 1);
- }
- else
- {
- if (mInventory->addVirtualItem(item, -1, 1))
- inventory->virtualRemove(item, 1);
- }
- }
- }
- }
- else if (eventId.find("skin_") == 0)
- {
- const std::string cmd = eventId.substr(5);
- std::string printText;
- int cnt = 0;
- FOR_EACH (StringVectCIter, it, mItems)
- {
- if (cmd == *it)
- {
- npcHandler->listInput(mNpcId, CAST_U8(cnt + 1));
- printText = mItems[cnt];
-
- if (mInputState != NpcInputState::ITEM &&
- mInputState != NpcInputState::ITEM_INDEX &&
- mInputState != NpcInputState::ITEM_CRAFT)
- {
- // addText will auto remove the input layout
- addText(strprintf("> \"%s\"", printText.c_str()), false);
- }
- mNewText.clear();
- break;
- }
- cnt ++;
- }
- }
-}
-
-void NpcDialog::nextDialog()
-{
- npcHandler->nextDialog(mNpcId);
-}
-
-void NpcDialog::closeDialog()
-{
- restoreCamera();
- npcHandler->closeDialog(mNpcId);
-}
-
-int NpcDialog::getNumberOfElements()
-{
- return CAST_S32(mItems.size());
-}
-
-std::string NpcDialog::getElementAt(int i)
-{
- return mItems[i];
-}
-
-const Image *NpcDialog::getImageAt(int i)
-{
- return mImages[i];
-}
-
-void NpcDialog::choiceRequest()
-{
- mItems.clear();
- FOR_EACH (ImageVectorIter, it, mImages)
- {
- if (*it != nullptr)
- (*it)->decRef();
- }
- mImages.clear();
- mActionState = NpcActionState::INPUT;
- mInputState = NpcInputState::LIST;
- buildLayout();
-}
-
-void NpcDialog::addChoice(const std::string &choice)
-{
- mItems.push_back(choice);
- mImages.push_back(nullptr);
-}
-
-void NpcDialog::parseListItems(const std::string &itemString)
-{
- std::istringstream iss(itemString);
- std::string tmp;
- const std::string path = paths.getStringValue("guiIcons");
- while (getline(iss, tmp, ':'))
- {
- if (tmp.empty())
- continue;
- const size_t pos = tmp.find('|');
- if (pos == std::string::npos)
- {
- mItems.push_back(tmp);
- mImages.push_back(nullptr);
- }
- else
- {
- mItems.push_back(tmp.substr(pos + 1));
- Image *const img = Loader::getImage(pathJoin(path,
- std::string(tmp.substr(0, pos)).append(".png")));
- mImages.push_back(img);
- }
- }
-
- if (!mItems.empty())
- {
- mItemList->setSelected(0);
- mItemList->requestFocus();
- }
- else
- {
- mItemList->setSelected(-1);
- }
-}
-
-void NpcDialog::refocus()
-{
- if (!mItems.empty())
- mItemList->refocus();
-}
-
-void NpcDialog::textRequest(const std::string &defaultText)
-{
- mActionState = NpcActionState::INPUT;
- mInputState = NpcInputState::STRING;
- mDefaultString = defaultText;
- mTextField->setText(defaultText);
-
- buildLayout();
-}
-
-bool NpcDialog::isTextInputFocused() const
-{
- return mTextField->isFocused();
-}
-
-bool NpcDialog::isInputFocused() const
-{
- return mTextField->isFocused() || mIntField->isFocused()
- || mItemList->isFocused();
-}
-
-bool NpcDialog::isAnyInputFocused()
-{
- FOR_EACH (DialogList::const_iterator, it, instances)
- {
- if (((*it) != nullptr) && (*it)->isInputFocused())
- return true;
- }
-
- return false;
-}
-
-void NpcDialog::integerRequest(const int defaultValue, const int min,
- const int max)
-{
- mActionState = NpcActionState::INPUT;
- mInputState = NpcInputState::INTEGER;
- mDefaultInt = defaultValue;
- mIntField->setRange(min, max);
- mIntField->setValue(defaultValue);
- buildLayout();
-}
-
-void NpcDialog::itemRequest(const int size)
-{
- mActionState = NpcActionState::INPUT;
- mInputState = NpcInputState::ITEM;
- mInventory->resize(size);
- buildLayout();
-}
-
-void NpcDialog::itemIndexRequest(const int size)
-{
- mActionState = NpcActionState::INPUT;
- mInputState = NpcInputState::ITEM_INDEX;
- mInventory->resize(size);
- buildLayout();
-}
-
-void NpcDialog::itemCraftRequest(const int size)
-{
- mActionState = NpcActionState::INPUT;
- mInputState = NpcInputState::ITEM_CRAFT;
- mComplexInventory->resize(size);
- buildLayout();
-}
-
-void NpcDialog::move(const int amount)
-{
- if (mActionState != NpcActionState::INPUT)
- return;
-
- switch (mInputState)
- {
- case NpcInputState::INTEGER:
- mIntField->setValue(mIntField->getValue() + amount);
- break;
- case NpcInputState::LIST:
- mItemList->setSelected(mItemList->getSelected() - amount);
- break;
- case NpcInputState::NONE:
- case NpcInputState::STRING:
- case NpcInputState::ITEM:
- case NpcInputState::ITEM_INDEX:
- case NpcInputState::ITEM_CRAFT:
- default:
- break;
- }
-}
-
-void NpcDialog::setVisible(Visible visible)
-{
- Window::setVisible(visible);
-
- if (visible == Visible_false)
- scheduleDelete();
-}
-
-void NpcDialog::optionChanged(const std::string &name)
-{
- if (name == "logNpcInGui")
- mLogInteraction = config.getBoolValue("logNpcInGui");
-}
-
-NpcDialog *NpcDialog::getActive()
-{
- if (instances.size() == 1)
- return instances.front();
-
- FOR_EACH (DialogList::const_iterator, it, instances)
- {
- if (((*it) != nullptr) && (*it)->isFocused())
- return (*it);
- }
-
- return nullptr;
-}
-
-void NpcDialog::closeAll()
-{
- FOR_EACH (DialogList::const_iterator, it, instances)
- {
- if (*it != nullptr)
- (*it)->close();
- }
-}
-
-void NpcDialog::placeNormalControls()
-{
- if (mShowAvatar)
- {
- place(0, 0, mPlayerBox);
- place(1, 0, mScrollArea, 5, 3);
- place(4, 3, mClearButton);
- place(5, 3, mButton);
- }
- else
- {
- place(0, 0, mScrollArea, 5, 3);
- place(3, 3, mClearButton);
- place(4, 3, mButton);
- }
-}
-
-void NpcDialog::placeMenuControls()
-{
- if (mShowAvatar)
- {
- place(0, 0, mPlayerBox);
- place(1, 0, mScrollArea, 6, 3);
- place(0, 3, mListScrollArea, 7, 3);
- place(1, 6, mButton2, 2);
- place(3, 6, mClearButton, 2);
- place(5, 6, mButton, 2);
- }
- else
- {
- place(0, 0, mScrollArea, 6, 3);
- place(0, 3, mListScrollArea, 6, 3);
- place(0, 6, mButton2, 2);
- place(2, 6, mClearButton, 2);
- place(4, 6, mButton, 2);
- }
-}
-
-void NpcDialog::placeSkinControls()
-{
- createSkinControls();
- if ((mDialogInfo != nullptr) && mDialogInfo->hideText)
- {
- if (mShowAvatar)
- {
- place(0, 0, mPlayerBox);
- place(1, 0, mSkinScrollArea, 7, 3);
- place(1, 3, mButton2, 2);
- }
- else
- {
- place(0, 0, mSkinScrollArea, 6, 3);
- place(0, 3, mButton2, 2);
- }
- }
- else
- {
- if (mShowAvatar)
- {
- place(0, 0, mPlayerBox);
- place(1, 0, mScrollArea, 6, 3);
- place(0, 3, mSkinScrollArea, 7, 3);
- place(1, 6, mButton2, 2);
- }
- else
- {
- place(0, 0, mScrollArea, 6, 3);
- place(0, 3, mSkinScrollArea, 6, 3);
- place(0, 6, mButton2, 2);
- }
- }
-}
-
-void NpcDialog::placeTextInputControls()
-{
- if (mShowAvatar)
- {
- place(0, 0, mPlayerBox);
- place(1, 0, mScrollArea, 6, 3);
- place(1, 3, mTextField, 6);
- place(1, 4, mResetButton, 2);
- place(3, 4, mClearButton, 2);
- place(5, 4, mButton, 2);
- }
- else
- {
- place(0, 0, mScrollArea, 6, 3);
- place(0, 3, mTextField, 6);
- place(0, 4, mResetButton, 2);
- place(2, 4, mClearButton, 2);
- place(4, 4, mButton, 2);
- }
-}
-
-void NpcDialog::placeIntInputControls()
-{
- if (mShowAvatar)
- {
- place(0, 0, mPlayerBox);
- place(1, 0, mScrollArea, 6, 3);
- place(1, 3, mMinusButton, 1);
- place(2, 3, mIntField, 4);
- place(6, 3, mPlusButton, 1);
- place(1, 4, mResetButton, 2);
- place(3, 4, mClearButton, 2);
- place(5, 4, mButton, 2);
- }
- else
- {
- place(0, 0, mScrollArea, 6, 3);
- place(0, 3, mMinusButton, 1);
- place(1, 3, mIntField, 4);
- place(5, 3, mPlusButton, 1);
- place(0, 4, mResetButton, 2);
- place(2, 4, mClearButton, 2);
- place(4, 4, mButton, 2);
- }
-}
-
-void NpcDialog::placeItemInputControls()
-{
- if (mDialogInfo != nullptr)
- {
- mItemContainer->setCellBackgroundImage(mDialogInfo->inventory.cell);
- mItemContainer->setMaxColumns(mDialogInfo->inventory.columns);
- }
- else
- {
- mItemContainer->setCellBackgroundImage("inventory_cell.xml");
- mItemContainer->setMaxColumns(10000);
- }
-
- if (mInputState == NpcInputState::ITEM_CRAFT)
- mItemContainer->setInventory(mComplexInventory);
- else
- mItemContainer->setInventory(mInventory);
-
- if ((mDialogInfo != nullptr) && mDialogInfo->hideText)
- {
- if (mShowAvatar)
- {
- place(0, 0, mPlayerBox);
- place(1, 0, mItemScrollArea, 7, 3);
- place(1, 3, mButton3, 2);
- place(3, 3, mClearButton, 2);
- place(5, 3, mButton, 2);
- }
- else
- {
- place(0, 0, mItemScrollArea, 6, 3);
- place(0, 3, mButton3, 2);
- place(2, 3, mClearButton, 2);
- place(4, 3, mButton, 2);
- }
- }
- else
- {
- if (mShowAvatar)
- {
- place(0, 0, mPlayerBox);
- place(1, 0, mScrollArea, 6, 3);
- place(0, 3, mItemScrollArea, 7, 3);
- place(1, 6, mButton3, 2);
- place(3, 6, mClearButton, 2);
- place(5, 6, mButton, 2);
- }
- else
- {
- place(0, 0, mScrollArea, 6, 3);
- place(0, 3, mItemScrollArea, 6, 3);
- place(0, 6, mButton3, 2);
- place(2, 6, mClearButton, 2);
- place(4, 6, mButton, 2);
- }
- }
-}
-
-void NpcDialog::buildLayout()
-{
- clearLayout();
-
- if (mActionState != NpcActionState::INPUT)
- {
- if (mActionState == NpcActionState::WAIT)
- mButton->setCaption(CAPTION_WAITING);
- else if (mActionState == NpcActionState::NEXT)
- mButton->setCaption(CAPTION_NEXT);
- else if (mActionState == NpcActionState::CLOSE)
- mButton->setCaption(CAPTION_CLOSE);
- placeNormalControls();
- }
- else if (mInputState != NpcInputState::NONE)
- {
- mButton->setCaption(CAPTION_SUBMIT);
- switch (mInputState)
- {
- case NpcInputState::LIST:
- if (mDialogInfo == nullptr)
- placeMenuControls();
- else
- placeSkinControls();
- mItemList->setSelected(-1);
- break;
-
- case NpcInputState::STRING:
- placeTextInputControls();
- break;
-
- case NpcInputState::INTEGER:
- placeIntInputControls();
- break;
-
- case NpcInputState::ITEM:
- case NpcInputState::ITEM_INDEX:
- case NpcInputState::ITEM_CRAFT:
- placeItemInputControls();
- break;
-
- case NpcInputState::NONE:
- default:
- break;
- }
- }
-
- Layout &layout = getLayout();
- layout.setRowHeight(1, LayoutType::SET);
- redraw();
- mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll());
-}
-
-void NpcDialog::saveCamera()
-{
- if ((viewport == nullptr) || mCameraMode >= 0)
- return;
-
- mCameraMode = CAST_S32(settings.cameraMode);
- mCameraX = viewport->getCameraRelativeX();
- mCameraY = viewport->getCameraRelativeY();
-}
-
-void NpcDialog::restoreCamera()
-{
- if ((viewport == nullptr) || mCameraMode == -1)
- return;
-
- if (CAST_S32(settings.cameraMode) != mCameraMode)
- viewport->toggleCameraMode();
- if (mCameraMode != 0)
- {
- viewport->setCameraRelativeX(mCameraX);
- viewport->setCameraRelativeY(mCameraY);
- }
- mCameraMode = -1;
-}
-
-void NpcDialog::showAvatar(const BeingTypeId avatarId)
-{
- const bool needShow = (avatarId != BeingTypeId_zero);
- if (needShow)
- {
- delete mAvatarBeing;
- mAvatarBeing = Being::createBeing(BeingId_zero,
- ActorType::Avatar,
- avatarId,
- nullptr);
- mPlayerBox->setPlayer(mAvatarBeing);
- if (!mAvatarBeing->mSprites.empty())
- {
- mAvatarBeing->logic();
- const BeingInfo *const info = AvatarDB::get(avatarId);
- const int pad2 = 2 * mPadding;
- int width = 0;
- if (info != nullptr)
- {
- width = info->getWidth();
- mPlayerBox->setWidth(width + pad2);
- mPlayerBox->setHeight(info->getHeight() + pad2);
- }
- const Sprite *const sprite = mAvatarBeing->mSprites[0];
- if ((sprite != nullptr) && (width == 0))
- {
- mPlayerBox->setWidth(sprite->getWidth() + pad2);
- mPlayerBox->setHeight(sprite->getHeight() + pad2);
- }
- }
- }
- else
- {
- delete2(mAvatarBeing)
- mPlayerBox->setPlayer(nullptr);
- }
- if (needShow != mShowAvatar)
- {
- mShowAvatar = needShow;
- buildLayout();
- }
- else
- {
- mShowAvatar = needShow;
- }
-}
-
-void NpcDialog::setAvatarDirection(const uint8_t direction)
-{
- Being *const being = mPlayerBox->getBeing();
- if (being != nullptr)
- being->setDirection(direction);
-}
-
-void NpcDialog::setAvatarAction(const int actionId)
-{
- Being *const being = mPlayerBox->getBeing();
- if (being != nullptr)
- being->setAction(static_cast<BeingActionT>(actionId), 0);
-}
-
-void NpcDialog::logic()
-{
- BLOCK_START("NpcDialog::logic")
- Window::logic();
- if (mShowAvatar && (mAvatarBeing != nullptr))
- {
- mAvatarBeing->logic();
- if (mPlayerBox->getWidth() < CAST_S32(3 * getPadding()))
- {
- const Sprite *const sprite = mAvatarBeing->mSprites[0];
- if (sprite != nullptr)
- {
- mPlayerBox->setWidth(sprite->getWidth() + 2 * getPadding());
- mPlayerBox->setHeight(sprite->getHeight() + 2 * getPadding());
- buildLayout();
- }
- }
- }
- BLOCK_END("NpcDialog::logic")
-}
-
-void NpcDialog::clearRows()
-{
- mTextBox->clearRows();
-}
-
-void NpcDialog::clearDialogs()
-{
- NpcDialogs::iterator it = mNpcDialogs.begin();
- const NpcDialogs::iterator it_end = mNpcDialogs.end();
- while (it != it_end)
- {
- delete (*it).second;
- ++ it;
- }
- mNpcDialogs.clear();
-}
-
-void NpcDialog::mousePressed(MouseEvent &event)
-{
- Window::mousePressed(event);
- if (event.getButton() == MouseButton::RIGHT
- && event.getSource() == mTextBox)
- {
- event.consume();
- if (popupMenu != nullptr)
- {
- popupMenu->showNpcDialogPopup(mNpcId,
- viewport->mMouseX,
- viewport->mMouseY);
- }
- }
-}
-
-void NpcDialog::copyToClipboard(const int x, const int y) const
-{
- std::string str = mTextBox->getTextAtPos(x, y);
- sendBuffer(str);
-}
-
-void NpcDialog::setSkin(const std::string &skin)
-{
- if (skin.empty())
- {
- mSkinName = skin;
- mDialogInfo = nullptr;
- return;
- }
- const NpcDialogInfo *const dialog = NpcDialogDB::getDialog(skin);
- if (dialog == nullptr)
- {
- logger->log("Error: creating controls for not existing npc dialog %s",
- skin.c_str());
- return;
- }
- mSkinName = skin;
- mDialogInfo = dialog;
-}
-
-void NpcDialog::deleteSkinControls()
-{
- mSkinContainer->removeControls();
-}
-
-void NpcDialog::createSkinControls()
-{
- deleteSkinControls();
-
- if (mDialogInfo == nullptr)
- return;
-
- FOR_EACH (STD_VECTOR<NpcImageInfo*>::const_iterator,
- it,
- mDialogInfo->menu.images)
- {
- const NpcImageInfo *const info = *it;
- Image *const image = Theme::getImageFromTheme(info->name);
- if (image != nullptr)
- {
- Icon *const icon = new Icon(this, image, AutoRelease_true);
- icon->setPosition(info->x, info->y);
- mSkinContainer->add(icon);
- }
- }
- FOR_EACH (STD_VECTOR<NpcTextInfo*>::const_iterator,
- it,
- mDialogInfo->menu.texts)
- {
- const NpcTextInfo *const info = *it;
- BrowserBox *box = new BrowserBox(this,
- Opaque_true,
- "browserbox.xml");
- box->setOpaque(Opaque_false);
- box->setMaxRow(config.getIntValue("ChatLogLength"));
- box->setLinkHandler(mItemLinkHandler);
- box->setProcessVars(true);
- box->setFont(gui->getNpcFont());
- box->setEnableKeys(true);
- box->setEnableTabs(true);
- box->setPosition(info->x, info->y);
- mSkinContainer->add(box);
- box->setWidth(info->width);
- box->setHeight(info->height);
- StringVect parts;
- splitToStringVector(parts, info->text, '\n');
- FOR_EACH (StringVectCIter, it2, parts)
- {
- box->addRow(*it2);
- }
- }
- FOR_EACH (STD_VECTOR<NpcButtonInfo*>::const_iterator,
- it,
- mDialogInfo->menu.buttons)
- {
- const NpcButtonInfo *const info = *it;
- Button *const button = new Button(this);
- button->setCaption(info->name);
- button->setActionEventId("skin_" + info->value);
- button->addActionListener(this);
- button->setPosition(info->x, info->y);
- if (!info->image.empty())
- {
- button->setImageWidth(info->imageWidth);
- button->setImageHeight(info->imageHeight);
- button->loadImageSet(info->image);
- }
- mSkinContainer->add(button);
- button->adjustSize();
- }
-}
-
-void NpcDialog::restoreVirtuals()
-{
- Inventory *const inventory = PlayerInfo::getInventory();
- if (inventory != nullptr)
- inventory->restoreVirtuals();
-}
-
-std::string NpcDialog::complexItemToStr(const ComplexItem *const item)
-{
- std::string str;
- if (item != nullptr)
- {
- const STD_VECTOR<Item*> &items = item->getChilds();
- const size_t sz = items.size();
- if (sz == 0u)
- return str;
-
- const Item *item2 = items[0];
-
- str = strprintf("%d,%d",
- item2->getInvIndex(),
- item2->getQuantity());
- for (size_t f = 1; f < sz; f ++)
- {
- str.append(";");
- item2 = items[f];
- str.append(strprintf("%d,%d",
- item2->getInvIndex(),
- item2->getQuantity()));
- }
- }
- else
- {
- str.clear();
- }
- return str;
-}
-
-void NpcDialog::addCraftItem(Item *const item,
- const int amount,
- const int slot)
-{
- if (mInputState != NpcInputState::ITEM_CRAFT)
- return;
-
- Inventory *const inventory = PlayerInfo::getInventory();
-
- if (inventory == nullptr)
- return;
-
- if (mComplexInventory->addVirtualItem(
- item,
- slot,
- amount))
- {
- inventory->virtualRemove(item, amount);
- }
-}
diff --git a/src/gui/windows/npcdialog.h b/src/gui/windows/npcdialog.h
deleted file mode 100644
index 4680d774d..000000000
--- a/src/gui/windows/npcdialog.h
+++ /dev/null
@@ -1,324 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_NPCDIALOG_H
-#define GUI_WINDOWS_NPCDIALOG_H
-
-#include "enums/simpletypes/beingid.h"
-#include "enums/simpletypes/beingtypeid.h"
-
-#include "enums/gui/npcactionstate.h"
-#include "enums/gui/npcinputstate.h"
-
-#include "gui/models/extendedlistmodel.h"
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-
-class Being;
-class Button;
-class BrowserBox;
-class ComplexInventory;
-class ComplexItem;
-class Container;
-class ExtendedListBox;
-class Item;
-class ItemLinkHandler;
-class Inventory;
-class IntTextField;
-class ItemContainer;
-class NpcDialog;
-class PlayerBox;
-class ScrollArea;
-class TextField;
-
-struct NpcDialogInfo;
-
-typedef std::map<BeingId, NpcDialog*> NpcDialogs;
-
-/**
- * The npc dialog.
- *
- * \ingroup Interface
- */
-class NpcDialog final : public Window,
- public ActionListener,
- public ExtendedListModel,
- public ConfigListener
-{
- public:
- /**
- * Constructor.
- *
- * @see Window::Window
- */
- explicit NpcDialog(const BeingId npcId);
-
- A_DELETE_COPY(NpcDialog)
-
- ~NpcDialog();
-
- void postInit() override final;
-
- /**
- * Called when receiving actions from the widgets.
- */
- void action(const ActionEvent &event) override final;
-
- /**
- * Sets the text shows in the dialog.
- *
- * @param string The new text.
- */
-// void setText(const std::string &string);
-
- /**
- * Adds the text to the text shows in the dialog. Also adds a newline
- * to the end.
- *
- * @param string The text to add.
- */
- void addText(const std::string &string, const bool save = true);
-
- /**
- * When called, the widget will show a "Next" button.
- */
- void showNextButton();
-
- /**
- * When called, the widget will show a "Close" button and will close
- * the dialog when clicked.
- */
- void showCloseButton();
-
- /**
- * Notifies the server that client has performed a next action.
- */
- void nextDialog();
-
- /**
- * Notifies the server that the client has performed a close action.
- */
- void closeDialog();
-
- /**
- * Returns the number of items in the choices list.
- */
- int getNumberOfElements() override final A_WARN_UNUSED;
-
- /**
- * Returns the name of item number i of the choices list.
- */
- std::string getElementAt(int i) override final A_WARN_UNUSED;
-
- /**
- * Returns the image of item number i of the choices list.
- */
- const Image *getImageAt(int i) override final A_WARN_UNUSED;
-
- /**
- * Makes this dialog request a choice selection from the user.
- */
- void choiceRequest();
-
- /**
- * Adds a choice to the list box.
- */
- void addChoice(const std::string &);
-
- /**
- * Fills the options list for an NPC dialog.
- *
- * @param itemString A string with the options separated with colons.
- */
- void parseListItems(const std::string &itemString);
-
- /**
- * Requests a text string from the user.
- */
- void textRequest(const std::string &defaultText = "");
-
- bool isInputFocused() const A_WARN_UNUSED;
-
- bool isTextInputFocused() const A_WARN_UNUSED;
-
- static bool isAnyInputFocused() A_WARN_UNUSED;
-
- /**
- * Requests a interger from the user.
- */
- void integerRequest(const int defaultValue = 0, const int min = 0,
- const int max = 2147483647);
-
- void itemRequest(const int size);
-
- void itemIndexRequest(const int size);
-
- void itemCraftRequest(const int size);
-
- void move(const int amount);
-
- void setVisible(Visible visible) override final;
-
- void optionChanged(const std::string &name) override final;
-
- /**
- * Returns true if any instances exist.
- */
- static bool isActive() A_WARN_UNUSED
- { return !instances.empty(); }
-
- /**
- * Returns the first active instance. Useful for pushing user
- * interaction.
- */
- static NpcDialog *getActive() A_WARN_UNUSED;
-
- /**
- * Closes all instances.
- */
- static void closeAll();
-
- /**
- * Closes all instances and destroy also net handler dialogs.
- */
- static void destroyAll();
-
- void saveCamera();
-
- void restoreCamera();
-
- void refocus();
-
- void showAvatar(const BeingTypeId avatarId);
-
- void setAvatarDirection(const uint8_t direction);
-
- void setAvatarAction(const int actionId);
-
- void logic() override final;
-
- void clearRows();
-
- void mousePressed(MouseEvent &event) override final;
-
- int isCloseState() const
- { return static_cast<int>(mActionState == NpcActionState::CLOSE); }
-
- void setSkin(const std::string &skin);
-
- void addCraftItem(Item *const item,
- const int amount,
- const int slot);
-
- NpcInputStateT getInputState()
- { return mInputState; }
-
- void copyToClipboard(const int x, const int y) const;
-
- static NpcDialogs mNpcDialogs;
-
- static void clearDialogs();
-
- private:
- typedef std::list<NpcDialog*> DialogList;
- static DialogList instances;
-
- void buildLayout();
-
- void placeNormalControls();
-
- void placeMenuControls();
-
- void placeSkinControls();
-
- void placeTextInputControls();
-
- void placeIntInputControls();
-
- void placeItemInputControls();
-
- void createSkinControls();
-
- void deleteSkinControls();
-
- void restoreVirtuals();
-
- std::string complexItemToStr(const ComplexItem *const item);
-
- BeingId mNpcId;
-
- int mDefaultInt;
- std::string mDefaultString;
-
- // Used for the main input area
- BrowserBox *mTextBox A_NONNULLPOINTER;
- ScrollArea *mScrollArea A_NONNULLPOINTER;
- std::string mText;
- std::string mNewText;
-
- // Used for choice input
- StringVect mItems;
- STD_VECTOR<Image *> mImages;
- ExtendedListBox *mItemList A_NONNULLPOINTER;
- ScrollArea *mListScrollArea A_NONNULLPOINTER;
- Container *mSkinContainer A_NONNULLPOINTER;
- ScrollArea *mSkinScrollArea A_NONNULLPOINTER;
- ItemLinkHandler *mItemLinkHandler A_NONNULLPOINTER;
-
- // Used for string and integer input
- TextField *mTextField A_NONNULLPOINTER;
- IntTextField *mIntField A_NONNULLPOINTER;
- Button *mPlusButton A_NONNULLPOINTER;
- Button *mMinusButton A_NONNULLPOINTER;
- Button *mClearButton A_NONNULLPOINTER;
-
- // Used for the button
- Button *mButton A_NONNULLPOINTER;
- Button *mButton2 A_NONNULLPOINTER;
- Button *mButton3 A_NONNULLPOINTER;
-
- // Will reset the text and integer input to the provided default
- Button *mResetButton A_NONNULLPOINTER;
-
- Inventory *mInventory A_NONNULLPOINTER;
- ComplexInventory *mComplexInventory A_NONNULLPOINTER;
- ItemContainer *mItemContainer A_NONNULLPOINTER;
- ScrollArea *mItemScrollArea A_NONNULLPOINTER;
-
- NpcInputStateT mInputState;
- NpcActionStateT mActionState;
- STD_VECTOR<Widget*> mSkinControls;
- std::string mSkinName;
- PlayerBox *mPlayerBox A_NONNULLPOINTER;
- Being *mAvatarBeing;
- const NpcDialogInfo *mDialogInfo;
- int mLastNextTime;
- int mCameraMode;
- int mCameraX;
- int mCameraY;
- bool mShowAvatar;
- bool mLogInteraction;
-};
-
-#endif // GUI_WINDOWS_NPCDIALOG_H
diff --git a/src/gui/windows/npcselldialog.cpp b/src/gui/windows/npcselldialog.cpp
deleted file mode 100644
index c00edda6c..000000000
--- a/src/gui/windows/npcselldialog.cpp
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/npcselldialog.h"
-
-#include "being/playerinfo.h"
-
-#include "gui/windows/confirmdialog.h"
-
-#include "gui/models/shopitems.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/shoplistbox.h"
-#include "gui/widgets/slider.h"
-
-#include "net/buysellhandler.h"
-#include "net/net.h"
-#include "net/npchandler.h"
-
-#include "resources/iteminfo.h"
-
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include "debug.h"
-
-NpcSellDialog::NpcSellDialog(const BeingId npcId) :
- SellDialog(IsSell_true,
- (Net::getNetworkType() != ServerType::TMWATHENA) ?
- Advanced_true : Advanced_false),
- mNpcId(npcId)
-{
-}
-
-void NpcSellDialog::sellAction(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- const int selectedItem = mShopItemList->getSelected();
- const ShopItem *const item = mShopItems->at(selectedItem);
- if ((item == nullptr) || PlayerInfo::isItemProtected(item->getId()))
- return;
-
- if (eventId == "presell")
- {
- if (mAmountItems <= 0 || mAmountItems > mMaxItems)
- return;
-
- const ItemInfo &info = ItemDB::get(item->getId());
- if (info.isProtected())
- {
- ConfirmDialog *const dialog = CREATEWIDGETR(ConfirmDialog,
- // TRANSLATORS: sell confirmation header
- _("sell item"),
- // TRANSLATORS: sell confirmation message
- strprintf(_("Do you really want to sell %s?"),
- info.getName().c_str()),
- SOUND_REQUEST,
- false,
- Modal_true);
- dialog->addActionListener(this);
- return;
- }
- }
-
- if (mAdvanced == Advanced_true)
- sellManyItems(event.getId());
- else
- sellOneItem();
-}
-
-void NpcSellDialog::sellManyItems(const std::string &eventId)
-{
- if (eventId == "confirm")
- {
- npcHandler->sellItems(mShopItems->allItems());
- close();
- }
- else
- {
- const int selectedItem = mShopItemList->getSelected();
- ShopItem *const item = mShopItems->at(selectedItem);
- item->increaseUsedQuantity(mAmountItems);
- item->update();
- if (mConfirmButton != nullptr)
- mConfirmButton->setEnabled(true);
- }
-}
-
-void NpcSellDialog::sellOneItem()
-{
- if (mAmountItems <= 0 || mAmountItems > mMaxItems)
- return;
-
- const int selectedItem = mShopItemList->getSelected();
- ShopItem *const item = mShopItems->at(selectedItem);
- // Attempt sell
- mPlayerMoney += mAmountItems * mShopItems->at(selectedItem)->getPrice();
- mMaxItems -= mAmountItems;
- while (mAmountItems > 0)
- {
- // This order is important, item->getCurrentInvIndex() would
- // return the inventory index of the next Duplicate otherwise.
- const int itemIndex = item->getCurrentInvIndex();
- const int sellCount = item->sellCurrentDuplicate(mAmountItems);
- npcHandler->sellItem(mNpcId, itemIndex, sellCount);
- mAmountItems -= sellCount;
- }
-
- mPlayerMoney += mAmountItems * mShopItems->at(selectedItem)->getPrice();
- mAmountItems = 1;
- mSlider->setValue(0);
-
- if (mMaxItems != 0)
- {
- updateButtonsAndLabels();
- }
- else
- {
- // All were sold
- mShopItemList->setSelected(-1);
- mShopItems->del(selectedItem);
-
- Rect scroll;
- scroll.y = mShopItemList->getRowHeight() * (selectedItem + 1);
- scroll.height = mShopItemList->getRowHeight();
- mShopItemList->showPart(scroll);
- }
-}
-
-void NpcSellDialog::close()
-{
- buySellHandler->close();
- Window::close();
-}
diff --git a/src/gui/windows/npcselldialog.h b/src/gui/windows/npcselldialog.h
deleted file mode 100644
index 688932a1b..000000000
--- a/src/gui/windows/npcselldialog.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_NPCSELLDIALOG_H
-#define GUI_WINDOWS_NPCSELLDIALOG_H
-
-#include "enums/simpletypes/beingid.h"
-
-#include "gui/widgets/selldialog.h"
-
-/**
- * The sell dialog.
- *
- * \ingroup Interface
- */
-class NpcSellDialog final : public SellDialog
-{
- public:
- /**
- * Constructor.
- *
- * @see Window::Window
- */
- explicit NpcSellDialog(const BeingId npcId);
-
- A_DELETE_COPY(NpcSellDialog)
-
- void close() override final;
-
- protected:
- void sellAction(const ActionEvent &event) override final;
-
- void sellOneItem();
-
- void sellManyItems(const std::string &eventId);
-
- BeingId mNpcId;
-};
-
-#endif // GUI_WINDOWS_NPCSELLDIALOG_H
diff --git a/src/gui/windows/okdialog.cpp b/src/gui/windows/okdialog.cpp
deleted file mode 100644
index 95ea9a641..000000000
--- a/src/gui/windows/okdialog.cpp
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/okdialog.h"
-
-#include "soundmanager.h"
-
-#include "const/sound.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/textbox.h"
-
-#include "gui/fonts/font.h"
-
-#include "debug.h"
-
-OkDialog::OkDialog(const std::string &restrict title,
- const std::string &restrict msg,
- const std::string &restrict button,
- const DialogTypeT soundEvent,
- const Modal modal,
- const ShowCenter showCenter,
- Window *const parent,
- const int minWidth) :
- Window(title, modal, parent, "ok.xml"),
- ActionListener(),
- mTextBox(new TextBox(this))
-{
- mTextBox->setEditable(false);
- mTextBox->setOpaque(Opaque_false);
- mTextBox->setTextWrapped(msg, minWidth);
-
- // TRANSLATORS: ok dialog button
- Button *const okButton = new Button(this, button, "ok", this);
-
- int width = getFont()->getWidth(title);
- if (width < mTextBox->getMinWidth())
- width = mTextBox->getMinWidth();
- if (width < okButton->getWidth())
- width = okButton->getWidth();
-
- if (mTextBox->getWidth() > width)
- width = mTextBox->getWidth();
- if (okButton->getWidth() > width)
- width = okButton->getWidth();
- setContentSize(width, mTextBox->getHeight() + okButton->getHeight()
- + getOption("buttonPadding", 8));
- mTextBox->setPosition((width - mTextBox->getWidth()) / 2, 0);
- okButton->setPosition((width - okButton->getWidth()) / 2,
- mTextBox->getHeight() + getOption("buttonPadding", 8));
-
- // +++ virtual method call
- add(mTextBox);
- add(okButton);
-
- if (showCenter == ShowCenter_true)
- center();
- else
- centerHorisontally();
- // +++ virtual method call
- setVisible(Visible_true);
- okButton->requestFocus();
-
- if (soundEvent == DialogType::OK)
- soundManager.playGuiSound(SOUND_INFO);
- else if (soundEvent == DialogType::ERROR)
- soundManager.playGuiSound(SOUND_ERROR);
-}
-
-void OkDialog::action(const ActionEvent &event)
-{
- setActionEventId(event.getId());
- distributeActionEvent();
- scheduleDelete();
-}
diff --git a/src/gui/windows/okdialog.h b/src/gui/windows/okdialog.h
deleted file mode 100644
index 1cd923e14..000000000
--- a/src/gui/windows/okdialog.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_OKDIALOG_H
-#define GUI_WINDOWS_OKDIALOG_H
-
-#include "gui/widgets/window.h"
-
-#include "enums/gui/dialogtype.h"
-
-#include "enums/simpletypes/showcenter.h"
-
-#include "listeners/actionlistener.h"
-
-#include "localconsts.h"
-
-class TextBox;
-
-/**
- * An 'Ok' button dialog.
- *
- * \ingroup GUI
- */
-class OkDialog final : public Window,
- public ActionListener
-{
- public:
- /**
- * Constructor.
- *
- * @see Window::Window
- */
- OkDialog(const std::string &restrict title,
- const std::string &restrict msg,
- const std::string &restrict button,
- const DialogTypeT soundEvent,
- const Modal modal,
- const ShowCenter showCenter,
- Window *const parent,
- const int minWidth);
-
- A_DELETE_COPY(OkDialog)
-
- /**
- * Called when receiving actions from the widgets.
- */
- void action(const ActionEvent &event) override final;
-
- private:
- TextBox *mTextBox;
-};
-
-#endif // GUI_WINDOWS_OKDIALOG_H
diff --git a/src/gui/windows/outfitwindow.cpp b/src/gui/windows/outfitwindow.cpp
deleted file mode 100644
index fa288c7d9..000000000
--- a/src/gui/windows/outfitwindow.cpp
+++ /dev/null
@@ -1,749 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/outfitwindow.h"
-
-#include "configuration.h"
-#include "dragdrop.h"
-#include "game.h"
-
-#include "being/playerinfo.h"
-
-#include "const/emoteshortcut.h"
-
-#include "enums/gui/layouttype.h"
-
-#include "input/inputactionoperators.h"
-#include "input/inputmanager.h"
-
-#include "gui/viewport.h"
-
-#include "gui/popups/popupmenu.h"
-
-#include "gui/windows/setupwindow.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/checkbox.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layout.h"
-
-#include "utils/gettext.h"
-
-#include "resources/inventory/inventory.h"
-
-#include <sstream>
-
-#include "debug.h"
-
-OutfitWindow *outfitWindow = nullptr;
-
-OutfitWindow::OutfitWindow() :
- // TRANSLATORS: outfits window name
- Window(_("Outfits"), Modal_false, nullptr, "outfits.xml"),
- ActionListener(),
- // TRANSLATORS: outfits window button
- mPreviousButton(new Button(this, _("<"), "previous", this)),
- // TRANSLATORS: outfits window button
- mNextButton(new Button(this, _(">"), "next", this)),
- // TRANSLATORS: outfits window button
- mEquipBottom(new Button(this, _("Equip"), "equip", this)),
- // TRANSLATORS: outfits window label
- mCurrentLabel(new Label(this, strprintf(_("Outfit: %d"), 1))),
- // TRANSLATORS: outfits window checkbox
- mUnequipCheck(new CheckBox(this, _("Unequip first"),
- serverConfig.getValueBool("OutfitUnequip0", true))),
- // TRANSLATORS: outfits window checkbox
- mAwayOutfitCheck(new CheckBox(this, _("Away outfit"),
- serverConfig.getValue("OutfitAwayIndex", OUTFITS_COUNT - 1) != 0u)),
- // TRANSLATORS: outfits window label
- mKeyLabel(new Label(this, strprintf(_("Key: %s"),
- keyName(0).c_str()))),
- mBorderColor(getThemeColor(ThemeColorId::BORDER, 64)),
- mCurrentOutfit(0),
- mBoxWidth(33),
- mBoxHeight(33),
- mGridWidth(4),
- mGridHeight(4),
- mItems(),
- mAwayOutfit(0),
- mItemColors(),
- mItemClicked(false),
- mItemsUnequip()
-{
- setWindowName("Outfits");
- setResizable(true);
- setCloseButton(true);
- setStickyButtonLock(true);
-
- mBackgroundColor = getThemeColor(ThemeColorId::BACKGROUND, 32);
-
- setDefaultSize(250, 400, 150, 290);
- setMinWidth(145);
- setMinHeight(220);
-
- if (setupWindow != nullptr)
- setupWindow->registerWindowForReset(this);
-
- mCurrentLabel->setAlignment(Graphics::CENTER);
- mKeyLabel->setAlignment(Graphics::CENTER);
-
- mUnequipCheck->setActionEventId("unequip");
- mUnequipCheck->addActionListener(this);
-
- mAwayOutfitCheck->setActionEventId("away");
- mAwayOutfitCheck->addActionListener(this);
-
- place(1, 3, mEquipBottom, 2);
- place(0, 4, mKeyLabel, 4);
- place(0, 5, mPreviousButton, 1);
- place(1, 5, mCurrentLabel, 2);
- place(3, 5, mNextButton, 1);
- place(0, 6, mUnequipCheck, 4);
- place(0, 7, mAwayOutfitCheck, 4);
-
- Layout &layout = getLayout();
- layout.setRowHeight(0, LayoutType::SET);
- layout.setColWidth(4, Layout::CENTER);
-
- loadWindowState();
-
- enableVisibleSound(true);
- load();
-}
-
-OutfitWindow::~OutfitWindow()
-{
- save();
-}
-
-void OutfitWindow::load()
-{
- const Configuration *cfg = &serverConfig;
-
- memset(mItems, -1, sizeof(mItems));
- memset(mItemColors, 1, sizeof(mItemColors));
-
- for (unsigned o = 0; o < OUTFITS_COUNT; o++)
- {
- std::string outfit = cfg->getValue("Outfit" + toString(o), "-1");
- std::string buf;
- std::stringstream ss(outfit);
-
- STD_VECTOR<int> tokens;
-
- while (ss >> buf)
- tokens.push_back(atoi(buf.c_str()));
-
- for (size_t i = 0, sz = tokens.size();
- i < sz && i < OUTFIT_ITEM_COUNT; i++)
- {
- mItems[o][i] = tokens[i];
- }
-
- outfit = cfg->getValue("OutfitColor" + toString(o), "1");
- std::stringstream ss2(outfit);
-
- tokens.clear();
-
- STD_VECTOR<unsigned char> tokens2;
- while (ss2 >> buf)
- tokens2.push_back(CAST_U8(atoi(buf.c_str())));
-
- for (size_t i = 0, sz = tokens2.size();
- i < sz && i < OUTFIT_ITEM_COUNT; i++)
- {
- mItemColors[o][i] = fromInt(tokens2[i], ItemColor);
- }
-
- mItemsUnequip[o] = cfg->getValueBool("OutfitUnequip" + toString(o),
- true);
- }
- mAwayOutfit = cfg->getValue("OutfitAwayIndex", OUTFITS_COUNT - 1);
- if (mAwayOutfit >= CAST_S32(OUTFITS_COUNT))
- mAwayOutfit = CAST_S32(OUTFITS_COUNT) - 1;
-
- if (mAwayOutfitCheck != nullptr)
- mAwayOutfitCheck->setSelected(mAwayOutfit == mCurrentOutfit);
-}
-
-void OutfitWindow::save() const
-{
- std::string outfitStr;
- std::string outfitColorsStr;
- for (unsigned o = 0; o < OUTFITS_COUNT; o++)
- {
- bool good = false;
- for (unsigned i = 0; i < OUTFIT_ITEM_COUNT; i++)
- {
- const int val = mItems[o][i];
- const int res = val != 0 ? val : -1;
- if (res != -1)
- good = true;
- outfitStr.append(toString(res));
- if (i < OUTFIT_ITEM_COUNT - 1)
- outfitStr.append(" ");
- outfitColorsStr.append(toString(CAST_S32(
- toInt(mItemColors[o][i], int))));
- if (i < OUTFIT_ITEM_COUNT - 1)
- outfitColorsStr.append(" ");
- }
- if (good)
- {
- serverConfig.setValue("Outfit" + toString(o), outfitStr);
- serverConfig.setValue("OutfitColor" + toString(o),
- outfitColorsStr);
- }
- else
- {
- serverConfig.deleteKey("Outfit" + toString(o));
- serverConfig.deleteKey("OutfitColor" + toString(o));
- }
-
- if (mItemsUnequip[o])
- {
- serverConfig.deleteKey("OutfitUnequip" + toString(o));
- }
- else
- {
- serverConfig.setValue("OutfitUnequip" + toString(o),
- mItemsUnequip[o]);
- }
- outfitStr.clear();
- outfitColorsStr.clear();
- }
- serverConfig.setValue("OutfitAwayIndex", mAwayOutfit);
-}
-
-void OutfitWindow::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "next")
- {
- next();
- }
- else if (eventId == "previous")
- {
- previous();
- }
- else if (eventId == "unequip")
- {
- if (mCurrentOutfit >= 0 && mCurrentOutfit < CAST_S32(
- OUTFITS_COUNT))
- {
- mItemsUnequip[mCurrentOutfit] = mUnequipCheck->isSelected();
- }
- }
- else if (eventId == "equip")
- {
- wearOutfit(mCurrentOutfit);
- if (Game::instance() != nullptr)
- Game::instance()->setValidSpeed();
- }
- else if (eventId == "away")
- {
- mAwayOutfit = mCurrentOutfit;
- if (!mAwayOutfitCheck->isSelected())
- mAwayOutfitCheck->setSelected(true);
- }
-}
-
-void OutfitWindow::wearOutfit(const int outfit, const bool unwearEmpty,
- const bool select)
-{
- bool isEmpty = true;
-
- if (outfit < 0 || outfit > CAST_S32(OUTFITS_COUNT))
- return;
-
- for (unsigned i = 0; i < OUTFIT_ITEM_COUNT; i++)
- {
- const Item *const item = PlayerInfo::getInventory()->findItem(
- mItems[outfit][i],
- mItemColors[outfit][i]);
- if ((item != nullptr)
- && item->isEquipped() == Equipped_false
- && (item->getQuantity() != 0))
- {
- if (item->isEquipment() == Equipm_true)
- {
- PlayerInfo::equipItem(item, Sfx_false);
- isEmpty = false;
- }
- }
- }
-
- if ((!isEmpty || unwearEmpty) && outfit < CAST_S32(OUTFITS_COUNT)
- && mItemsUnequip[outfit])
- {
- unequipNotInOutfit(outfit);
- }
- if (select)
- {
- mCurrentOutfit = outfit;
- showCurrentOutfit();
- }
-}
-
-void OutfitWindow::copyOutfit(const int outfit)
-{
- copyOutfit(outfit, mCurrentOutfit);
-}
-
-void OutfitWindow::copyOutfit(const int src, const int dst)
-{
- if (src < 0 || src > CAST_S32(OUTFITS_COUNT)
- || dst < 0 || dst > CAST_S32(OUTFITS_COUNT))
- {
- return;
- }
-
- for (unsigned int i = 0; i < OUTFIT_ITEM_COUNT; i++)
- mItems[dst][i] = mItems[src][i];
- save();
-}
-
-void OutfitWindow::draw(Graphics *const graphics)
-{
- BLOCK_START("OutfitWindow::draw")
- Window::draw(graphics);
-
- if (mCurrentOutfit < 0 || mCurrentOutfit
- >= static_cast<signed int>(OUTFITS_COUNT))
- {
- return;
- }
-
- for (unsigned int i = 0; i < OUTFIT_ITEM_COUNT; i++)
- {
- const int itemX = mPadding + ((i % mGridWidth) * mBoxWidth);
- const int itemY = mPadding + mTitleBarHeight
- + ((i / CAST_U32(mGridWidth)) * mBoxHeight);
-
- graphics->setColor(mBorderColor);
- graphics->drawRectangle(Rect(itemX, itemY, 32, 32));
- graphics->setColor(mBackgroundColor);
- graphics->fillRectangle(Rect(itemX, itemY, 32, 32));
-
- if (mItems[mCurrentOutfit][i] < 0)
- continue;
-
- bool foundItem = false;
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv != nullptr)
- {
- const Item *const item = inv->findItem(mItems[mCurrentOutfit][i],
- mItemColors[mCurrentOutfit][i]);
- if (item != nullptr)
- {
- // Draw item icon.
- const Image *const image = item->getImage();
- if (image != nullptr)
- {
- graphics->drawImage(image, itemX, itemY);
- foundItem = true;
- }
- }
- }
- if (!foundItem)
- {
- Image *const image = Item::getImage(mItems[mCurrentOutfit][i],
- mItemColors[mCurrentOutfit][i]);
- if (image != nullptr)
- {
- graphics->drawImage(image, itemX, itemY);
- image->decRef();
- }
- }
- }
- BLOCK_END("OutfitWindow::draw")
-}
-
-void OutfitWindow::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("OutfitWindow::draw")
- Window::safeDraw(graphics);
-
- if (mCurrentOutfit < 0 || mCurrentOutfit
- >= static_cast<signed int>(OUTFITS_COUNT))
- {
- return;
- }
-
- for (unsigned int i = 0; i < OUTFIT_ITEM_COUNT; i++)
- {
- const int itemX = mPadding + ((i % mGridWidth) * mBoxWidth);
- const int itemY = mPadding + mTitleBarHeight
- + ((i / CAST_U32(mGridWidth)) * mBoxHeight);
-
- graphics->setColor(mBorderColor);
- graphics->drawRectangle(Rect(itemX, itemY, 32, 32));
- graphics->setColor(mBackgroundColor);
- graphics->fillRectangle(Rect(itemX, itemY, 32, 32));
-
- if (mItems[mCurrentOutfit][i] < 0)
- continue;
-
- bool foundItem = false;
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv != nullptr)
- {
- const Item *const item = inv->findItem(mItems[mCurrentOutfit][i],
- mItemColors[mCurrentOutfit][i]);
- if (item != nullptr)
- {
- // Draw item icon.
- const Image *const image = item->getImage();
- if (image != nullptr)
- {
- graphics->drawImage(image, itemX, itemY);
- foundItem = true;
- }
- }
- }
- if (!foundItem)
- {
- Image *const image = Item::getImage(mItems[mCurrentOutfit][i],
- mItemColors[mCurrentOutfit][i]);
- if (image != nullptr)
- {
- graphics->drawImage(image, itemX, itemY);
- image->decRef();
- }
- }
- }
- BLOCK_END("OutfitWindow::draw")
-}
-
-void OutfitWindow::mouseDragged(MouseEvent &event)
-{
- if (event.getButton() == MouseButton::LEFT)
- {
- if (dragDrop.isEmpty() && mItemClicked)
- {
- if (mCurrentOutfit < 0 || mCurrentOutfit
- >= static_cast<signed int>(OUTFITS_COUNT))
- {
- Window::mouseDragged(event);
- return;
- }
-
- const int index = getIndexFromGrid(event.getX(), event.getY());
- if (index == -1)
- {
- Window::mouseDragged(event);
- return;
- }
- const int itemId = mItems[mCurrentOutfit][index];
- const ItemColor itemColor = mItemColors[mCurrentOutfit][index];
- if (itemId < 0)
- {
- Window::mouseDragged(event);
- return;
- }
- mMoved = false;
- event.consume();
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv != nullptr)
- {
- Item *const item = inv->findItem(itemId, itemColor);
- if (item != nullptr)
- dragDrop.dragItem(item, DragDropSource::Outfit);
- else
- dragDrop.clear();
- mItems[mCurrentOutfit][index] = -1;
- }
- }
- }
- Window::mouseDragged(event);
-}
-
-void OutfitWindow::mousePressed(MouseEvent &event)
-{
- const int index = getIndexFromGrid(event.getX(), event.getY());
- if (event.getButton() == MouseButton::RIGHT && (popupMenu != nullptr))
- {
- popupMenu->showOutfitsWindowPopup(viewport->mMouseX,
- viewport->mMouseY);
- event.consume();
- return;
- }
- else if (index == -1)
- {
- Window::mousePressed(event);
- return;
- }
- mMoved = false;
- event.consume();
-
- if (mItems[mCurrentOutfit][index] > 0)
- {
- mItemClicked = true;
- }
- else
- {
- if (dragDrop.isSelected())
- {
- mItems[mCurrentOutfit][index] = dragDrop.getSelected();
- mItemColors[mCurrentOutfit][index] = dragDrop.getSelectedColor();
- dragDrop.deselect();
- save();
- }
- }
-
- Window::mousePressed(event);
-}
-
-void OutfitWindow::mouseReleased(MouseEvent &event)
-{
- if (event.getButton() == MouseButton::LEFT)
- {
- if (mCurrentOutfit < 0 || mCurrentOutfit
- >= static_cast<signed int>(OUTFITS_COUNT))
- {
- return;
- }
- const int index = getIndexFromGrid(event.getX(), event.getY());
- if (index == -1)
- {
- dragDrop.clear();
- Window::mouseReleased(event);
- return;
- }
- mMoved = false;
- event.consume();
- if (!dragDrop.isEmpty())
- {
- if (dragDrop.isSourceItemContainer())
- {
- mItems[mCurrentOutfit][index] = dragDrop.getItem();
- mItemColors[mCurrentOutfit][index] = dragDrop.getItemColor();
- dragDrop.clear();
- dragDrop.deselect();
- save();
- }
- }
- if (mItemClicked)
- mItemClicked = false;
- }
- Window::mouseReleased(event);
-}
-
-int OutfitWindow::getIndexFromGrid(const int pointX, const int pointY) const
-{
- const Rect tRect = Rect(mPadding, mTitleBarHeight,
- mGridWidth * mBoxWidth, mGridHeight * mBoxHeight);
- if (!tRect.isPointInRect(pointX, pointY))
- return -1;
- const int index = (((pointY - mTitleBarHeight) / mBoxHeight) * mGridWidth)
- + (pointX - mPadding) / mBoxWidth;
- if (index >= CAST_S32(OUTFIT_ITEM_COUNT) || index < 0)
- return -1;
- return index;
-}
-
-void OutfitWindow::unequipNotInOutfit(const int outfit) const
-{
- // here we think that outfit is correct index
-
- const Inventory *const inventory = PlayerInfo::getInventory();
- if (inventory == nullptr)
- return;
-
- const unsigned int invSize = inventory->getSize();
- for (unsigned i = 0; i < invSize; i++)
- {
- const Item *const item = inventory->getItem(i);
- if ((item != nullptr) && item->isEquipped() == Equipped_true)
- {
- bool found = false;
- for (unsigned f = 0; f < OUTFIT_ITEM_COUNT; f++)
- {
- if (item->getId() == mItems[outfit][f])
- {
- found = true;
- break;
- }
- }
- if (!found)
- PlayerInfo::unequipItem(item, Sfx_false);
- }
- }
-}
-
-std::string OutfitWindow::keyName(const int number)
-{
- if (number < 0 || number >= SHORTCUT_EMOTES)
- return "";
- return inputManager.getKeyStringLong(InputAction::OUTFIT_1 + number);
-}
-
-void OutfitWindow::next()
-{
- if (mCurrentOutfit < (CAST_S32(OUTFITS_COUNT) - 1))
- mCurrentOutfit++;
- else
- mCurrentOutfit = 0;
- showCurrentOutfit();
-}
-
-void OutfitWindow::previous()
-{
- if (mCurrentOutfit > 0)
- mCurrentOutfit--;
- else
- mCurrentOutfit = OUTFITS_COUNT - 1;
- showCurrentOutfit();
-}
-
-void OutfitWindow::showCurrentOutfit()
-{
- // TRANSLATORS: outfits window label
- mCurrentLabel->setCaption(strprintf(_("Outfit: %d"), mCurrentOutfit + 1));
- if (mCurrentOutfit < CAST_S32(OUTFITS_COUNT))
- mUnequipCheck->setSelected(mItemsUnequip[mCurrentOutfit]);
- else
- mUnequipCheck->setSelected(false);
- // TRANSLATORS: outfits window label
- mKeyLabel->setCaption(strprintf(_("Key: %s"),
- keyName(mCurrentOutfit).c_str()));
- mAwayOutfitCheck->setSelected(mAwayOutfit == mCurrentOutfit);
-}
-
-void OutfitWindow::wearNextOutfit(const bool all)
-{
- next();
- if (!all && mCurrentOutfit >= 0 && mCurrentOutfit
- < CAST_S32(OUTFITS_COUNT))
- {
- bool fromStart = false;
- while (!mItemsUnequip[mCurrentOutfit])
- {
- next();
- if (mCurrentOutfit == 0)
- {
- if (!fromStart)
- fromStart = true;
- else
- return;
- }
- }
- }
- wearOutfit(mCurrentOutfit);
-}
-
-void OutfitWindow::wearPreviousOutfit(const bool all)
-{
- previous();
- if (!all && mCurrentOutfit >= 0 && mCurrentOutfit
- < CAST_S32(OUTFITS_COUNT))
- {
- bool fromStart = false;
- while (!mItemsUnequip[mCurrentOutfit])
- {
- previous();
- if (mCurrentOutfit == 0)
- {
- if (!fromStart)
- fromStart = true;
- else
- return;
- }
- }
- }
- wearOutfit(mCurrentOutfit);
-}
-
-void OutfitWindow::copyFromEquiped()
-{
- copyFromEquiped(mCurrentOutfit);
-}
-
-void OutfitWindow::copyFromEquiped(const int dst)
-{
- const Inventory *const inventory = PlayerInfo::getInventory();
- if (inventory == nullptr)
- return;
-
- int outfitCell = 0;
- for (unsigned i = 0, sz = inventory->getSize(); i < sz; i++)
- {
- const Item *const item = inventory->getItem(i);
- if ((item != nullptr) && item->isEquipped() == Equipped_true)
- {
- mItems[dst][outfitCell] = item->getId();
- mItemColors[dst][outfitCell++] = item->getColor();
- if (outfitCell >= CAST_S32(OUTFIT_ITEM_COUNT))
- break;
- }
- }
- save();
-}
-
-void OutfitWindow::wearAwayOutfit()
-{
- copyFromEquiped(OUTFITS_COUNT);
- wearOutfit(mAwayOutfit, false);
-}
-
-void OutfitWindow::unwearAwayOutfit()
-{
- wearOutfit(OUTFITS_COUNT);
-}
-
-void OutfitWindow::clearCurrentOutfit()
-{
- if (mCurrentOutfit < 0 || mCurrentOutfit
- >= static_cast<signed int>(OUTFITS_COUNT))
- {
- return;
- }
- for (unsigned f = 0; f < OUTFIT_ITEM_COUNT; f++)
- {
- mItems[mCurrentOutfit][f] = -1;
- mItemColors[mCurrentOutfit][f] = ItemColor_one;
- }
- save();
-}
-
-std::string OutfitWindow::getOutfitString() const
-{
- std::string str;
- for (unsigned int i = 0; i < OUTFIT_ITEM_COUNT; i++)
- {
- const int id = mItems[mCurrentOutfit][i];
- if (id < 0)
- continue;
-
- const ItemColor color = mItemColors[mCurrentOutfit][i];
- STD_VECTOR<int> ids;
- ids.push_back(id);
- ids.push_back(CAST_S32(color));
-
- const std::string name = ItemDB::getNamesStr(ids);
- if (name.empty())
- continue;
- str.append("[");
- str.append(name);
- str.append("] ");
- }
- return str;
-}
diff --git a/src/gui/windows/outfitwindow.h b/src/gui/windows/outfitwindow.h
deleted file mode 100644
index cf2799d2b..000000000
--- a/src/gui/windows/outfitwindow.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_OUTFITWINDOW_H
-#define GUI_WINDOWS_OUTFITWINDOW_H
-
-#include "enums/simpletypes/itemcolor.h"
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-
-const unsigned int OUTFITS_COUNT = 100;
-const unsigned int OUTFIT_ITEM_COUNT = 16;
-
-class Button;
-class CheckBox;
-class Label;
-
-class OutfitWindow final : public Window,
- private ActionListener
-{
- public:
- /**
- * Constructor.
- */
- OutfitWindow();
-
- A_DELETE_COPY(OutfitWindow)
-
- /**
- * Destructor.
- */
- ~OutfitWindow();
-
- void action(const ActionEvent &event) override final;
-
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void mousePressed(MouseEvent &event) override final;
-
- void mouseDragged(MouseEvent &event) override final;
-
- void mouseReleased(MouseEvent &event) override final;
-
- void load();
-
- void wearOutfit(const int outfit, const bool unwearEmpty = true,
- const bool select = false);
-
- void copyOutfit(const int outfit);
-
- void copyOutfit(const int src, const int dst);
-
- void copyFromEquiped();
-
- void copyFromEquiped(const int dst);
-
- void unequipNotInOutfit(const int outfit) const;
-
- void next();
-
- void previous();
-
- void wearNextOutfit(const bool all = false);
-
- void wearPreviousOutfit(const bool all = false);
-
- void wearAwayOutfit();
-
- void unwearAwayOutfit();
-
- void showCurrentOutfit();
-
- static std::string keyName(const int number) A_WARN_UNUSED;
-
- void clearCurrentOutfit();
-
- std::string getOutfitString() const;
-
- private:
- int getIndexFromGrid(const int pointX,
- const int pointY) const A_WARN_UNUSED;
- void save() const;
-
- Button *mPreviousButton A_NONNULLPOINTER;
- Button *mNextButton A_NONNULLPOINTER;
- Button *mEquipBottom A_NONNULLPOINTER;
- Label *mCurrentLabel A_NONNULLPOINTER;
- CheckBox *mUnequipCheck A_NONNULLPOINTER;
- CheckBox *mAwayOutfitCheck A_NONNULLPOINTER;
- Label *mKeyLabel A_NONNULLPOINTER;
-
- Color mBorderColor;
-
- int mCurrentOutfit;
- int mBoxWidth;
- int mBoxHeight;
- int mGridWidth;
- int mGridHeight;
-
- int mItems[OUTFITS_COUNT + 1][OUTFIT_ITEM_COUNT];
- int mAwayOutfit;
-
- ItemColor mItemColors[OUTFITS_COUNT + 1][OUTFIT_ITEM_COUNT];
- bool mItemClicked;
- bool mItemsUnequip[OUTFITS_COUNT];
-};
-
-extern OutfitWindow *outfitWindow;
-
-#endif // GUI_WINDOWS_OUTFITWINDOW_H
diff --git a/src/gui/windows/questswindow.cpp b/src/gui/windows/questswindow.cpp
deleted file mode 100644
index 269f2aab9..000000000
--- a/src/gui/windows/questswindow.cpp
+++ /dev/null
@@ -1,483 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/questswindow.h"
-
-#include "actormanager.h"
-#include "configuration.h"
-#include "effectmanager.h"
-
-#include "being/localplayer.h"
-
-#include "enums/gui/layouttype.h"
-
-#include "gui/gui.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/models/questsmodel.h"
-
-#include "gui/windows/setupwindow.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/browserbox.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/layout.h"
-#include "gui/widgets/extendedlistbox.h"
-#include "gui/widgets/itemlinkhandler.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-
-#include "resources/questeffect.h"
-#include "resources/questitem.h"
-
-#include "resources/db/questdb.h"
-
-#include "resources/map/map.h"
-
-#include "debug.h"
-
-QuestsWindow *questsWindow = nullptr;
-
-QuestsWindow::QuestsWindow() :
- // TRANSLATORS: quests window name
- Window(_("Quests"), Modal_false, nullptr, "quests.xml"),
- ActionListener(),
- mQuestsModel(new QuestsModel),
- mQuestsListBox(CREATEWIDGETR(ExtendedListBox,
- this, mQuestsModel, "extendedlistbox.xml")),
- mQuestScrollArea(new ScrollArea(this, mQuestsListBox,
- fromBool(getOptionBool("showlistbackground"), Opaque),
- "quests_list_background.xml")),
- mItemLinkHandler(new ItemLinkHandler),
- mText(new BrowserBox(this, Opaque_true,
- "browserbox.xml")),
- mTextScrollArea(new ScrollArea(this, mText,
- fromBool(getOptionBool("showtextbackground"), Opaque),
- "quests_text_background.xml")),
- // TRANSLATORS: quests window button
- mCloseButton(new Button(this, _("Close"), "close", this)),
- mCompleteIcon(Theme::getImageFromThemeXml("complete_icon.xml", "")),
- mIncompleteIcon(Theme::getImageFromThemeXml("incomplete_icon.xml", "")),
- mMapEffects(),
- mVars(nullptr),
- mQuests(nullptr),
- mAllEffects(nullptr),
- mNpcEffects(),
- mQuestLinks(),
- mQuestReverseLinks(),
- mNewQuestEffectId(paths.getIntValue("newQuestEffectId")),
- mCompleteQuestEffectId(paths.getIntValue("completeQuestEffectId")),
- mMap(nullptr)
-{
- setWindowName("Quests");
- setResizable(true);
- setCloseButton(true);
- setStickyButtonLock(true);
- setSaveVisible(true);
-
- setDefaultSize(400, 350, ImagePosition::RIGHT);
- setMinWidth(310);
- setMinHeight(220);
-
- if (setupWindow != nullptr)
- setupWindow->registerWindowForReset(this);
-
- mQuestsListBox->setActionEventId("select");
- mQuestsListBox->addActionListener(this);
-
- mQuestScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- mText->setOpaque(Opaque_false);
- mText->setLinkHandler(mItemLinkHandler);
- mTextScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- mQuestsListBox->setWidth(500);
- if ((gui == nullptr) || gui->getNpcFont()->getHeight() < 20)
- mQuestsListBox->setRowHeight(20);
- else
- mQuestsListBox->setRowHeight(gui->getNpcFont()->getHeight());
-
- ContainerPlacer placer;
- placer = getPlacer(0, 0);
-
- placer(0, 0, mQuestScrollArea, 4, 3).setPadding(3);
- placer(4, 0, mTextScrollArea, 4, 3).setPadding(3);
- placer(7, 3, mCloseButton);
-
- Layout &layout = getLayout();
- layout.setRowHeight(0, LayoutType::SET);
-
- loadWindowState();
- enableVisibleSound(true);
- QuestDb::load();
- mVars = QuestDb::getVars();
- mQuests = QuestDb::getQuests();
- mAllEffects = QuestDb::getAllEffects();
-}
-
-QuestsWindow::~QuestsWindow()
-{
- delete2(mQuestsModel);
-
- QuestDb::unload();
-
- delete2(mItemLinkHandler);
- mQuestLinks.clear();
- mQuestReverseLinks.clear();
- if (mCompleteIcon != nullptr)
- {
- mCompleteIcon->decRef();
- mCompleteIcon = nullptr;
- }
- if (mIncompleteIcon != nullptr)
- {
- mIncompleteIcon->decRef();
- mIncompleteIcon = nullptr;
- }
-}
-
-void QuestsWindow::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "select")
- {
- const int id = mQuestsListBox->getSelected();
- if (id < 0)
- return;
- showQuest(mQuestLinks[id]);
- }
- else if (eventId == "close")
- {
- setVisible(Visible_false);
- }
-}
-
-void QuestsWindow::updateQuest(const int var,
- const int val1,
- const int val2,
- const int val3,
- const int time1)
-{
- (*mVars)[var] = QuestVar(val1, val2, val3, time1);
-}
-
-void QuestsWindow::rebuild(const bool playSound)
-{
- mQuestsModel->clear();
- mQuestLinks.clear();
- mQuestReverseLinks.clear();
- StringVect &names = mQuestsModel->getNames();
- STD_VECTOR<Image*> &images = mQuestsModel->getImages();
- STD_VECTOR<QuestItem*> complete;
- STD_VECTOR<QuestItem*> incomplete;
- STD_VECTOR<QuestItem*> hidden;
- int updatedQuest = -1;
- int newCompleteStatus = -1;
-
- FOR_EACHP (NpcQuestVarMapCIter, it, mVars)
- {
- const int var = (*it).first;
- const QuestVar &val = (*it).second;
- const STD_VECTOR<QuestItem*> &quests = (*mQuests)[var];
- FOR_EACH (STD_VECTOR<QuestItem*>::const_iterator, it2, quests)
- {
- if (*it2 == nullptr)
- continue;
- QuestItem *const quest = *it2;
- // complete quest
- if (quest->complete.find(val.var1) != quest->complete.end())
- {
- complete.push_back(quest);
- }
- // incomplete quest
- else if (quest->incomplete.find(val.var1) !=
- quest->incomplete.end())
- {
- incomplete.push_back(quest);
- }
- // hidden quest
- else
- {
- hidden.push_back(quest);
- }
- }
- }
-
- int k = 0;
-
- for (STD_VECTOR<QuestItem*>::const_iterator it = complete.begin(),
- it_end = complete.end(); it != it_end; ++ it, k ++)
- {
- QuestItem *const quest = *it;
- if (quest->completeFlag == 0 || (quest->broken
- && quest->completeFlag == -1))
- {
- updatedQuest = k;
- newCompleteStatus = 1;
- }
- quest->completeFlag = 1;
- mQuestLinks.push_back(quest);
- mQuestReverseLinks[quest->var] = k;
- names.push_back(quest->name);
- if (mCompleteIcon != nullptr)
- {
- mCompleteIcon->incRef();
- images.push_back(mCompleteIcon);
- }
- else
- {
- images.push_back(nullptr);
- }
- }
-
- for (STD_VECTOR<QuestItem*>::const_iterator it = incomplete.begin(),
- it_end = incomplete.end(); it != it_end; ++ it, k ++)
- {
- QuestItem *const quest = *it;
- if (quest->completeFlag == -1)
- {
- updatedQuest = k;
- newCompleteStatus = 0;
- }
- quest->completeFlag = 0;
- mQuestLinks.push_back(quest);
- mQuestReverseLinks[quest->var] = k;
- names.push_back(quest->name);
- if (mIncompleteIcon != nullptr)
- {
- mIncompleteIcon->incRef();
- images.push_back(mIncompleteIcon);
- }
- else
- {
- images.push_back(nullptr);
- }
- }
-
- FOR_EACH (STD_VECTOR<QuestItem*>::const_iterator, it, hidden)
- (*it)->completeFlag = -1;
-
- if (updatedQuest == -1 || updatedQuest >= CAST_S32(
- mQuestLinks.size()))
- {
- updatedQuest = CAST_S32(mQuestLinks.size() - 1);
- }
- if (updatedQuest >= 0)
- {
- mQuestsListBox->setSelected(updatedQuest);
- showQuest(mQuestLinks[updatedQuest]);
- if (playSound && (effectManager != nullptr))
- {
- switch (newCompleteStatus)
- {
- case 0:
- effectManager->trigger(mNewQuestEffectId, localPlayer);
- break;
- case 1:
- effectManager->trigger(mCompleteQuestEffectId,
- localPlayer);
- break;
- default:
- break;
- }
- }
- }
- updateEffects();
-}
-
-void QuestsWindow::showQuest(const QuestItem *const quest)
-{
- if (quest == nullptr)
- return;
-
- const STD_VECTOR<QuestItemText> &texts = quest->texts;
- const QuestVar &var = (*mVars)[quest->var];
- const std::string var1 = toString(var.var1);
- const std::string var2 = toString(var.var2);
- const std::string var3 = toString(var.var3);
- const std::string timeStr = timeDiffToString(var.time1);
- mText->clearRows();
- FOR_EACH (STD_VECTOR<QuestItemText>::const_iterator, it, texts)
- {
- const QuestItemText &data = *it;
- std::string text = data.text;
- replaceAll(text, "{@@var1}", var1);
- replaceAll(text, "{@@var2}", var2);
- replaceAll(text, "{@@var3}", var3);
- replaceAll(text, "{@@time}", timeStr);
- switch (data.type)
- {
- case QuestType::TEXT:
- default:
- mText->addRow(text);
- break;
- case QuestType::NAME:
- mText->addRow(std::string("[").append(text).append("]"));
- break;
- case QuestType::REWARD:
- mText->addRow(std::string(
- // TRANSLATORS: quest reward
- _("Reward:")).append(
- " ").append(
- text));
- break;
- case QuestType::GIVER:
- mText->addRow(std::string(
- // TRANSLATORS: quest giver name
- _("Quest Giver:")).append(
- " ").append(
- text));
- break;
- case QuestType::NPC:
- mText->addRow(std::string(
- // TRANSLATORS: quest npc name
- _("Npc:")).append(
- " ").append(
- text));
- break;
- case QuestType::COORDINATES:
- mText->addRow(std::string(
- strprintf("%s [@@=navigate %s %s|%s@@]",
- // TRANSLATORS: quest coordinates
- _("Coordinates:"),
- data.data1.c_str(),
- data.data2.c_str(),
- text.c_str())));
- break;
- }
- }
- mText->updateHeight();
-}
-
-void QuestsWindow::setMap(const Map *const map)
-{
- if (mMap != map)
- {
- mMap = map;
- mMapEffects.clear();
- if (mMap == nullptr)
- return;
-
- const std::string name = mMap->getProperty("shortName");
- FOR_EACHP (STD_VECTOR<QuestEffect*>::const_iterator, it, mAllEffects)
- {
- const QuestEffect *const effect = *it;
- if ((effect != nullptr) && name == effect->map)
- mMapEffects.push_back(effect);
- }
- updateEffects();
- }
-}
-
-void QuestsWindow::updateEffects()
-{
- NpcQuestEffectMap oldNpc = mNpcEffects;
- mNpcEffects.clear();
-
- FOR_EACH (STD_VECTOR<const QuestEffect*>::const_iterator,
- it, mMapEffects)
- {
- const QuestEffect *const effect = *it;
- if (effect != nullptr)
- {
- const NpcQuestVarMapCIter varIt = mVars->find(effect->var);
- if (varIt != mVars->end())
- {
- const std::set<int> &vals = effect->values;
- if (vals.find((*mVars)[effect->var].var1) != vals.end())
- mNpcEffects[effect->id] = effect;
- }
- }
- }
- if (actorManager == nullptr)
- return;
-
- std::set<BeingTypeId> removeEffects;
- std::map<BeingTypeId, int> addEffects;
-
- // for old effects
- FOR_EACH (NpcQuestEffectMapCIter, it, oldNpc)
- {
- const BeingTypeId id = (*it).first;
- const QuestEffect *const effect = (*it).second;
-
- const NpcQuestEffectMapCIter itNew = mNpcEffects.find(id);
- if (itNew == mNpcEffects.end())
- { // in new list no effect for this npc
- removeEffects.insert(id);
- }
- else
- { // in new list exists effect for this npc
- const QuestEffect *const newEffect = (*itNew).second;
- if (effect != newEffect)
- { // new effects is not equal to old effect
- addEffects[id] = newEffect->effectId;
- removeEffects.insert(id);
- }
- }
- }
-
- // for new effects
- FOR_EACH (NpcQuestEffectMapCIter, it, mNpcEffects)
- {
- const BeingTypeId id = (*it).first;
- const QuestEffect *const effect = (*it).second;
-
- const NpcQuestEffectMapCIter itNew = oldNpc.find(id);
- // check if old effect was not present
- if (itNew == oldNpc.end())
- addEffects[id] = effect->effectId;
- }
- if (!removeEffects.empty() || !addEffects.empty())
- actorManager->updateEffects(addEffects, removeEffects);
-}
-
-void QuestsWindow::addEffect(Being *const being)
-{
- if (being == nullptr)
- return;
- const BeingTypeId id = being->getSubType();
- const std::map<BeingTypeId, const QuestEffect*>::const_iterator
- it = mNpcEffects.find(id);
- if (it != mNpcEffects.end())
- {
- const QuestEffect *const effect = (*it).second;
- if (effect != nullptr)
- being->addSpecialEffect(effect->effectId);
- }
-}
-
-void QuestsWindow::selectQuest(const int varId)
-{
- std::map<int, int>::const_iterator it = mQuestReverseLinks.find(varId);
- if (it == mQuestReverseLinks.end())
- return;
- if (mVisible == Visible_false)
- setVisible(Visible_true);
- const int listPos = (*it).second;
- if (listPos < 0)
- return;
- showQuest(mQuestLinks[listPos]);
- mQuestsListBox->setSelected(listPos);
- requestMoveToTop();
-}
diff --git a/src/gui/windows/questswindow.h b/src/gui/windows/questswindow.h
deleted file mode 100644
index fd4175754..000000000
--- a/src/gui/windows/questswindow.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_QUESTSWINDOW_H
-#define GUI_WINDOWS_QUESTSWINDOW_H
-
-#include "localconsts.h"
-
-#include "enums/simpletypes/beingtypeid.h"
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-
-#include "resources/questvar.h"
-
-class Being;
-class BrowserBox;
-class Button;
-class ExtendedListBox;
-class ItemLinkHandler;
-class Map;
-class ScrollArea;
-class QuestsModel;
-
-struct QuestEffect;
-struct QuestItem;
-
-typedef std::map<BeingTypeId, const QuestEffect*> NpcQuestEffectMap;
-typedef NpcQuestEffectMap::const_iterator NpcQuestEffectMapCIter;
-
-class QuestsWindow final : public Window,
- public ActionListener
-{
- public:
- QuestsWindow();
-
- A_DELETE_COPY(QuestsWindow)
-
- ~QuestsWindow();
-
- void action(const ActionEvent &event) override final;
-
- void updateQuest(const int var,
- const int val1,
- const int val2,
- const int val3,
- const int time1);
-
- void rebuild(const bool playSound);
-
- void showQuest(const QuestItem *const quest);
-
- void setMap(const Map *const map);
-
- void updateEffects();
-
- void addEffect(Being *const being);
-
- void selectQuest(const int varId);
-
- private:
- QuestsModel *mQuestsModel A_NONNULLPOINTER;
- ExtendedListBox *mQuestsListBox A_NONNULLPOINTER;
- ScrollArea *mQuestScrollArea A_NONNULLPOINTER;
- ItemLinkHandler *mItemLinkHandler A_NONNULLPOINTER;
- BrowserBox *mText A_NONNULLPOINTER;
- ScrollArea *mTextScrollArea A_NONNULLPOINTER;
- Button *mCloseButton A_NONNULLPOINTER;
- Image *mCompleteIcon;
- Image *mIncompleteIcon;
- STD_VECTOR<const QuestEffect*> mMapEffects;
- NpcQuestVarMap *mVars;
- std::map<int, STD_VECTOR<QuestItem*> > *mQuests;
- STD_VECTOR<QuestEffect*> *mAllEffects;
-
- // npc effects for current map and values: npc, effect
- NpcQuestEffectMap mNpcEffects;
- STD_VECTOR<QuestItem*> mQuestLinks;
- std::map<int, int> mQuestReverseLinks;
- int mNewQuestEffectId;
- int mCompleteQuestEffectId;
- const Map *mMap;
-};
-
-extern QuestsWindow *questsWindow;
-
-#endif // GUI_WINDOWS_QUESTSWINDOW_H
diff --git a/src/gui/windows/quitdialog.cpp b/src/gui/windows/quitdialog.cpp
deleted file mode 100644
index b9ef417c3..000000000
--- a/src/gui/windows/quitdialog.cpp
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/quitdialog.h"
-
-#include "client.h"
-#include "configuration.h"
-#include "soundmanager.h"
-
-#include "const/sound.h"
-
-#include "gui/dialogsmanager.h"
-#include "gui/viewport.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/button.h"
-#include "gui/widgets/radiobutton.h"
-
-#include "net/charserverhandler.h"
-#include "net/gamehandler.h"
-
-#include "resources/map/map.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-#include "utils/process.h"
-
-#include "debug.h"
-
-QuitDialog::QuitDialog(QuitDialog **const pointerToMe) :
- // TRANSLATORS: quit dialog name
- Window(_("Quit"), Modal_true, nullptr, "quit.xml"),
- ActionListener(),
- KeyListener(),
- mOptions(),
- // TRANSLATORS: quit dialog button
- mLogoutQuit(new RadioButton(this, _("Quit"), "quitdialog")),
- // TRANSLATORS: quit dialog button
- mForceQuit(new RadioButton(this, _("Quit"), "quitdialog")),
- mSwitchAccountServer(new RadioButton(this,
- // TRANSLATORS: quit dialog button
- _("Switch server"), "quitdialog")),
- mSwitchCharacter(new RadioButton(this,
- // TRANSLATORS: quit dialog button
- _("Switch character"), "quitdialog")),
- mRate(nullptr),
- // TRANSLATORS: quit dialog button
- mOkButton(new Button(this, _("OK"), "ok", this)),
- // TRANSLATORS: quit dialog button
- mCancelButton(new Button(this, _("Cancel"), "cancel", this)),
- mMyPointer(pointerToMe),
- mNeedForceQuit(false)
-{
- addKeyListener(this);
-
- ContainerPlacer placer = getPlacer(0, 0);
- const StateT state = client->getState();
- mNeedForceQuit = (state == State::CHOOSE_SERVER
- || state == State::CONNECT_SERVER || state == State::LOGIN
- || state == State::PRE_LOGIN || state == State::LOGIN_ATTEMPT
- || state == State::UPDATE || state == State::LOAD_DATA);
-
- // All states, when we're not logged in to someone.
- if (mNeedForceQuit)
- {
- placeOption(placer, mForceQuit);
- }
- else
- {
- // Only added if we are connected to an accountserver or gameserver
- placeOption(placer, mLogoutQuit);
- placeOption(placer, mSwitchAccountServer);
-
- // Only added if we are connected to a gameserver
- if (state == State::GAME)
- placeOption(placer, mSwitchCharacter);
- }
-
-/*
-#ifdef ANDROID
- if (config.getBoolValue("rated") == false
- && config.getIntValue("gamecount") > 3)
- {
- // TRANSLATORS: rate button
- mRate = new RadioButton(this, _("Rate in google play"), "quitdialog");
- placeOption(placer, mRate);
- mOptions[mOptions.size() - 1]->setSelected(true);
- }
- else
-#endif
-*/
- {
- mOptions[0]->setSelected(true);
- }
-
- placer = getPlacer(0, 1);
- placer(1, 0, mOkButton, 1);
- placer(2, 0, mCancelButton, 1);
- reflowLayout(200, 0);
-}
-
-void QuitDialog::postInit()
-{
- Window::postInit();
- setLocationRelativeTo(getParent());
- setVisible(Visible_true);
- soundManager.playGuiSound(SOUND_SHOW_WINDOW);
- requestModalFocus();
- mOkButton->requestFocus();
-}
-
-QuitDialog::~QuitDialog()
-{
- if (mMyPointer != nullptr)
- *mMyPointer = nullptr;
- delete2(mForceQuit);
- delete2(mLogoutQuit);
- delete2(mSwitchAccountServer);
- delete2(mSwitchCharacter);
-}
-
-void QuitDialog::placeOption(ContainerPlacer &placer,
- RadioButton *const option)
-{
- placer(0, CAST_S32(mOptions.size()), option, 3);
- mOptions.push_back(option);
-}
-
-void QuitDialog::action(const ActionEvent &event)
-{
- soundManager.playGuiSound(SOUND_HIDE_WINDOW);
- if (event.getId() == "ok")
- {
- if (viewport != nullptr)
- {
- const Map *const map = viewport->getMap();
- if (map != nullptr)
- map->saveExtraLayer();
- }
-
- if (mForceQuit->isSelected())
- {
- client->setState(State::FORCE_QUIT);
- }
- else if (mLogoutQuit->isSelected())
- {
- DialogsManager::closeDialogs();
- client->setState(State::EXIT);
- }
- else if ((mRate != nullptr) && mRate->isSelected())
- {
- openBrowser("https://play.google.com/store/apps/details?"
- "id=org.evolonline.beta.manaplus");
- config.setValue("rated", true);
- if (mNeedForceQuit)
- {
- client->setState(State::FORCE_QUIT);
- }
- else
- {
- DialogsManager::closeDialogs();
- client->setState(State::EXIT);
- }
- }
- else if (gameHandler->isConnected()
- && mSwitchAccountServer->isSelected())
- {
- DialogsManager::closeDialogs();
- client->setState(State::SWITCH_SERVER);
- }
- else if (mSwitchCharacter->isSelected())
- {
- if (client->getState() == State::GAME)
- {
- charServerHandler->switchCharacter();
- DialogsManager::closeDialogs();
- serverConfig.write();
- }
- }
- }
- scheduleDelete();
-}
-
-void QuitDialog::keyPressed(KeyEvent &event)
-{
- const InputActionT actionId = event.getActionId();
- int dir = 0;
-
- PRAGMA45(GCC diagnostic push)
- PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
- switch (actionId)
- {
- case InputAction::GUI_SELECT:
- case InputAction::GUI_SELECT2:
- action(ActionEvent(nullptr, mOkButton->getActionEventId()));
- break;
- case InputAction::GUI_CANCEL:
- action(ActionEvent(nullptr, mCancelButton->getActionEventId()));
- break;
- case InputAction::GUI_UP:
- dir = -1;
- break;
- case InputAction::GUI_DOWN:
- dir = 1;
- break;
- default:
- break;
- }
- PRAGMA45(GCC diagnostic pop)
-
- if (dir != 0)
- {
- STD_VECTOR<RadioButton*>::const_iterator it = mOptions.begin();
- const STD_VECTOR<RadioButton*>::const_iterator
- it_end = mOptions.end();
-
- for (; it < it_end; ++it)
- {
- if ((*it)->isSelected())
- break;
- }
-
- if (it == mOptions.end())
- {
- if (mOptions[0] != nullptr)
- mOptions[0]->setSelected(true);
- return;
- }
- else if (it == mOptions.begin() && dir < 0)
- {
- it = mOptions.end();
- }
-
- it += dir;
-
- if (it == mOptions.end())
- it = mOptions.begin();
-
- (*it)->setSelected(true);
- }
-}
diff --git a/src/gui/windows/quitdialog.h b/src/gui/windows/quitdialog.h
deleted file mode 100644
index e12e13e7b..000000000
--- a/src/gui/windows/quitdialog.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_QUITDIALOG_H
-#define GUI_WINDOWS_QUITDIALOG_H
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/keylistener.h"
-
-class Button;
-class RadioButton;
-
-/**
- * The quit dialog.
- *
- * \ingroup Interface
- */
-class QuitDialog final : public Window,
- public ActionListener,
- public KeyListener
-{
- public:
- /**
- * Constructor
- *
- * @pointerToMe will be set to NULL when the QuitDialog is destroyed
- */
- explicit QuitDialog(QuitDialog **const pointerToMe) A_NONNULL(2);
-
- A_DELETE_COPY(QuitDialog)
-
- /**
- * Destructor
- */
- ~QuitDialog();
-
- void postInit() override final;
-
- /**
- * Called when receiving actions from the widgets.
- */
- void action(const ActionEvent &event) override final;
-
- void keyPressed(KeyEvent &event) override final;
-
- private:
- void placeOption(ContainerPlacer &placer,
- RadioButton *const option);
- STD_VECTOR<RadioButton*> mOptions;
-
- RadioButton *mLogoutQuit A_NONNULLPOINTER;
- RadioButton *mForceQuit A_NONNULLPOINTER;
- RadioButton *mSwitchAccountServer A_NONNULLPOINTER;
- RadioButton *mSwitchCharacter A_NONNULLPOINTER;
- RadioButton *mRate A_NONNULLPOINTER;
- Button *mOkButton A_NONNULLPOINTER;
- Button *mCancelButton A_NONNULLPOINTER;
-
- QuitDialog **mMyPointer A_NONNULLPOINTER;
- bool mNeedForceQuit;
-};
-
-#endif // GUI_WINDOWS_QUITDIALOG_H
diff --git a/src/gui/windows/registerdialog.cpp b/src/gui/windows/registerdialog.cpp
deleted file mode 100644
index 699023d93..000000000
--- a/src/gui/windows/registerdialog.cpp
+++ /dev/null
@@ -1,317 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/registerdialog.h"
-
-#include "client.h"
-#include "configuration.h"
-
-#include "being/being.h"
-
-#include "gui/windows/okdialog.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layoutcell.h"
-#include "gui/widgets/passwordfield.h"
-#include "gui/widgets/radiobutton.h"
-
-#include "listeners/wrongdatanoticelistener.h"
-
-#include "net/logindata.h"
-#include "net/loginhandler.h"
-#include "net/serverfeatures.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-RegisterDialog::RegisterDialog(LoginData &data) :
- // TRANSLATORS: register dialog name
- Window(_("Register"), Modal_false, nullptr, "register.xml"),
- ActionListener(),
- KeyListener(),
- mLoginData(&data),
- mUserField(new TextField(this, mLoginData->username)),
- mPasswordField(new PasswordField(this, mLoginData->password)),
- mConfirmField(new PasswordField(this)),
- mEmailField(nullptr),
- // TRANSLATORS: register dialog. button.
- mRegisterButton(new Button(this, _("Register"), "register", this)),
- // TRANSLATORS: register dialog. button.
- mCancelButton(new Button(this, _("Cancel"), "cancel", this)),
- mMaleButton(nullptr),
- mFemaleButton(nullptr),
- mWrongDataNoticeListener(new WrongDataNoticeListener)
-{
- setCloseButton(true);
-
- // TRANSLATORS: register dialog. label.
- Label *const userLabel = new Label(this, _("Name:"));
- // TRANSLATORS: register dialog. label.
- Label *const passwordLabel = new Label(this, _("Password:"));
- // TRANSLATORS: register dialog. label.
- Label *const confirmLabel = new Label(this, _("Confirm:"));
-
- ContainerPlacer placer;
- placer = getPlacer(0, 0);
- placer(0, 0, userLabel);
- placer(0, 1, passwordLabel);
- placer(0, 2, confirmLabel);
-
- placer(1, 0, mUserField, 3).setPadding(2);
- placer(1, 1, mPasswordField, 3).setPadding(2);
- placer(1, 2, mConfirmField, 3).setPadding(2);
-
- int row = 3;
-
- if (features.getIntValue("forceAccountGender") == -1)
- {
- // TRANSLATORS: register dialog. button.
- mMaleButton = new RadioButton(this, _("Male"), "sex", true);
- // TRANSLATORS: register dialog. button.
- mFemaleButton = new RadioButton(this, _("Female"), "sex", false);
- placer(1, row, mMaleButton);
- placer(2, row, mFemaleButton);
-
- row++;
- }
-
- if (serverFeatures->haveEmailOnRegister())
- {
- // TRANSLATORS: register dialog. label.
- Label *const emailLabel = new Label(this, _("Email:"));
- mEmailField = new TextField(this);
- placer(0, row, emailLabel);
- placer(1, row, mEmailField, 3).setPadding(2);
- mEmailField->addKeyListener(this);
- mEmailField->setActionEventId("register");
- mEmailField->addActionListener(this);
-// row++;
- }
-
- placer = getPlacer(0, 2);
- placer(1, 0, mRegisterButton);
- placer(2, 0, mCancelButton);
- reflowLayout(250, 0);
-
- mUserField->addKeyListener(this);
- mPasswordField->addKeyListener(this);
- mConfirmField->addKeyListener(this);
-
- mUserField->setActionEventId("register");
- mPasswordField->setActionEventId("register");
- mConfirmField->setActionEventId("register");
-
- mUserField->addActionListener(this);
- mPasswordField->addActionListener(this);
- mConfirmField->addActionListener(this);
-
- center();
-}
-
-void RegisterDialog::postInit()
-{
- Window::postInit();
- setVisible(Visible_true);
- mUserField->requestFocus();
- mUserField->setCaretPosition(CAST_U32(
- mUserField->getText().length()));
-
- mRegisterButton->setEnabled(canSubmit());
-}
-
-RegisterDialog::~RegisterDialog()
-{
- delete2(mWrongDataNoticeListener);
-}
-
-void RegisterDialog::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "cancel")
- {
- close();
- }
- else if (eventId == "register" && canSubmit())
- {
- const std::string &user = mUserField->getText();
- logger->log("RegisterDialog::register Username is %s", user.c_str());
-
- std::string errorMsg;
- int error = 0;
-
- const unsigned int minUser = loginHandler->getMinUserNameLength();
- const unsigned int maxUser = loginHandler->getMaxUserNameLength();
- const unsigned int minPass = loginHandler->getMinPasswordLength();
- const unsigned int maxPass = loginHandler->getMaxPasswordLength();
-
- if (user.length() < minUser)
- {
- // Name too short
- errorMsg = strprintf
- // TRANSLATORS: error message
- (_("The username needs to be at least %u characters long."),
- minUser);
- error = 1;
- }
- else if (user.length() > maxUser - 1)
- {
- // Name too long
- errorMsg = strprintf
- // TRANSLATORS: error message
- (_("The username needs to be less than %u characters long."),
- maxUser);
- error = 1;
- }
- else if (mPasswordField->getText().length() < minPass)
- {
- // Pass too short
- errorMsg = strprintf
- // TRANSLATORS: error message
- (_("The password needs to be at least %u characters long."),
- minPass);
- error = 2;
- }
- else if (mPasswordField->getText().length() > maxPass)
- {
- // Pass too long
- errorMsg = strprintf
- // TRANSLATORS: error message
- (_("The password needs to be less than %u characters long."),
- maxPass);
- error = 2;
- }
- else if (mPasswordField->getText() != mConfirmField->getText())
- {
- // Password does not match with the confirmation one
- // TRANSLATORS: error message
- errorMsg = _("Passwords do not match.");
- error = 2;
- }
- else if ((mEmailField != nullptr) &&
- mEmailField->getText().find('@') == std::string::npos)
- {
- // TRANSLATORS: error message
- errorMsg = _("Incorrect email.");
- error = 1;
- }
- else if (mEmailField != nullptr &&
- mEmailField->getText().size() > 40)
- {
- // TRANSLATORS: error message
- errorMsg = _("Email too long.");
- error = 1;
- }
-
- if (error > 0)
- {
- if (error == 1)
- {
- mWrongDataNoticeListener->setTarget(this->mUserField);
- }
- else if (error == 2)
- {
- // Reset password confirmation
- mPasswordField->setText("");
- mConfirmField->setText("");
- mWrongDataNoticeListener->setTarget(this->mPasswordField);
- }
-
- OkDialog *const dlg = CREATEWIDGETR(OkDialog,
- // TRANSLATORS: error message
- _("Error"), errorMsg, _("OK"),
- DialogType::ERROR,
- Modal_true,
- ShowCenter_true,
- nullptr,
- 260);
- dlg->addActionListener(mWrongDataNoticeListener);
- }
- else
- {
- // No errors detected, register the new user.
- mRegisterButton->setEnabled(false);
- mLoginData->username = mUserField->getText();
- mLoginData->password = mPasswordField->getText();
- if (features.getIntValue("forceAccountGender") == -1)
- {
- if ((mFemaleButton != nullptr) && mFemaleButton->isSelected())
- mLoginData->gender = Gender::FEMALE;
- else
- mLoginData->gender = Gender::MALE;
- }
- else
- {
- mLoginData->gender = Being::intToGender(
- CAST_U8(features.getIntValue("forceAccountGender")));
- }
-
- if (mEmailField != nullptr)
- mLoginData->email = mEmailField->getText();
- mLoginData->registerLogin = true;
-
- client->setState(State::REGISTER_ATTEMPT);
- }
- }
-}
-
-void RegisterDialog::keyPressed(KeyEvent &event)
-{
- if (event.isConsumed())
- {
- mRegisterButton->setEnabled(canSubmit());
- return;
- }
- const InputActionT actionId = event.getActionId();
- if (actionId == InputAction::GUI_CANCEL)
- {
- action(ActionEvent(nullptr, mCancelButton->getActionEventId()));
- }
- else if (actionId == InputAction::GUI_SELECT ||
- actionId == InputAction::GUI_SELECT2)
- {
- action(ActionEvent(nullptr, mRegisterButton->getActionEventId()));
- }
- else
- {
- mRegisterButton->setEnabled(canSubmit());
- }
-}
-
-bool RegisterDialog::canSubmit() const
-{
- return !mUserField->getText().empty() &&
- !mPasswordField->getText().empty() &&
- !mConfirmField->getText().empty() &&
- client->getState() == State::REGISTER &&
- ((mEmailField == nullptr) || !mEmailField->getText().empty());
-}
-
-void RegisterDialog::close()
-{
- client->setState(State::LOGIN);
- Window::close();
-}
diff --git a/src/gui/windows/registerdialog.h b/src/gui/windows/registerdialog.h
deleted file mode 100644
index d0d0d821a..000000000
--- a/src/gui/windows/registerdialog.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_REGISTERDIALOG_H
-#define GUI_WINDOWS_REGISTERDIALOG_H
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/keylistener.h"
-
-class Button;
-class LoginData;
-class RadioButton;
-class TextField;
-class WrongDataNoticeListener;
-
-/**
- * The registration dialog.
- *
- * \ingroup Interface
- */
-class RegisterDialog final : public Window,
- public ActionListener,
- public KeyListener
-{
- public:
- /**
- * Constructor. Name, password and server fields will be initialized to
- * the information already present in the LoginData instance.
- *
- * @see Window::Window
- */
- explicit RegisterDialog(LoginData &loginData);
-
- A_DELETE_COPY(RegisterDialog)
-
- /**
- * Destructor
- */
- ~RegisterDialog();
-
- void postInit() override;
-
- /**
- * Called when receiving actions from the widgets.
- */
- void action(const ActionEvent &event) override;
-
- /**
- * Called when a key is pressed in one of the text fields.
- */
- void keyPressed(KeyEvent &event) override;
-
- void close() override;
-
- private:
- /**
- * Returns whether submit can be enabled. This is true in the register
- * state, when all necessary fields have some text.
- */
- bool canSubmit() const;
-
- LoginData *mLoginData A_NONNULLPOINTER;
- TextField *mUserField A_NONNULLPOINTER;
- TextField *mPasswordField A_NONNULLPOINTER;
- TextField *mConfirmField A_NONNULLPOINTER;
- TextField *mEmailField;
- Button *mRegisterButton A_NONNULLPOINTER;
- Button *mCancelButton A_NONNULLPOINTER;
- RadioButton *mMaleButton;
- RadioButton *mFemaleButton;
- WrongDataNoticeListener *mWrongDataNoticeListener A_NONNULLPOINTER;
-};
-
-#endif // GUI_WINDOWS_REGISTERDIALOG_H
diff --git a/src/gui/windows/serverdialog.cpp b/src/gui/windows/serverdialog.cpp
deleted file mode 100644
index ab630e960..000000000
--- a/src/gui/windows/serverdialog.cpp
+++ /dev/null
@@ -1,902 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/serverdialog.h"
-
-#include "chatlogger.h"
-#include "client.h"
-#include "configuration.h"
-#include "main.h"
-#include "settings.h"
-
-#include "net/download.h"
-
-#include "fs/paths.h"
-
-#include "gui/widgets/checkbox.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/desktop.h"
-#include "gui/windows/editserverdialog.h"
-#include "gui/windows/logindialog.h"
-#include "gui/windows/serverinfowindow.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layout.h"
-#include "gui/widgets/serverslistbox.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-#include "utils/langs.h"
-
-#include "debug.h"
-
-#ifdef WIN32
-#undef ERROR
-#endif // WIN32
-
-static const int MAX_SERVERLIST = 15;
-
-static std::string serverTypeToString(const ServerTypeT type)
-{
- switch (type)
- {
- case ServerType::TMWATHENA:
-#ifdef TMWA_SUPPORT
- return "TmwAthena";
-#else // TMWA_SUPPORT
-
- return "";
-#endif // TMWA_SUPPORT
-
- case ServerType::EATHENA:
- return "eAthena";
- case ServerType::EVOL2:
- return "Evol2";
- default:
- case ServerType::UNKNOWN:
- return "";
- }
-}
-
-static uint16_t defaultPortForServerType(const ServerTypeT type)
-{
- switch (type)
- {
- default:
- case ServerType::EATHENA:
- case ServerType::EVOL2:
- return 6900;
- case ServerType::UNKNOWN:
- case ServerType::TMWATHENA:
- return 6901;
- }
-}
-
-ServerDialog::ServerDialog(ServerInfo *const serverInfo,
- const std::string &dir) :
- // TRANSLATORS: servers dialog name
- Window(_("Choose Your Server"), Modal_false, nullptr, "server.xml"),
- ActionListener(),
- KeyListener(),
- SelectionListener(),
- mMutex(),
- mServers(ServerInfos()),
- mDir(dir),
- mDescription(new Label(this, std::string())),
- // TRANSLATORS: servers dialog button
- mQuitButton(new Button(this, _("Quit"), "quit", this)),
- // TRANSLATORS: servers dialog button
- mConnectButton(new Button(this, _("Connect"), "connect", this)),
- // TRANSLATORS: servers dialog button
- mAddEntryButton(new Button(this, _("Add"), "addEntry", this)),
- // TRANSLATORS: servers dialog button
- mEditEntryButton(new Button(this, _("Edit"), "editEntry", this)),
- // TRANSLATORS: servers dialog button
- mDeleteButton(new Button(this, _("Delete"), "remove", this)),
- // TRANSLATORS: servers dialog button
- mLoadButton(new Button(this, _("Load"), "load", this)),
- // TRANSLATORS: servers dialog button
- mInfoButton(new Button(this, _("Info"), "info", this)),
- mServersListModel(new ServersListModel(&mServers, this)),
- mServersList(CREATEWIDGETR(ServersListBox, this, mServersListModel)),
- mDownload(nullptr),
- mServerInfo(serverInfo),
- mPersistentIPCheckBox(nullptr),
- mDownloadProgress(-1.0F),
- mDownloadStatus(ServerDialogDownloadStatus::UNKNOWN)
-{
- if (isSafeMode)
- {
- // TRANSLATORS: servers dialog name
- setCaption(_("Choose Your Server *** SAFE MODE ***"));
- }
-
- setWindowName("ServerDialog");
-
- setCloseButton(true);
-
- mPersistentIPCheckBox = new CheckBox(this,
- // TRANSLATORS: servers dialog checkbox
- _("Use same ip for game sub servers"),
- config.getBoolValue("usePersistentIP"),
- this, "persitent ip");
-
- loadCustomServers();
-
- mServersList->addMouseListener(this);
-
- ScrollArea *const usedScroll = new ScrollArea(this, mServersList,
- fromBool(getOptionBool("showbackground"), Opaque),
- "server_background.xml");
- usedScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
-
- mServersList->addSelectionListener(this);
- usedScroll->setVerticalScrollAmount(0);
-
- place(0, 0, usedScroll, 8, 5).setPadding(3);
- place(0, 5, mDescription, 8);
- place(0, 6, mPersistentIPCheckBox, 8);
- place(0, 7, mInfoButton);
- place(1, 7, mAddEntryButton);
- place(2, 7, mEditEntryButton);
- place(3, 7, mLoadButton);
- place(4, 7, mDeleteButton);
- place(6, 7, mQuitButton);
- place(7, 7, mConnectButton);
-
- // Make sure the list has enough height
- getLayout().setRowHeight(0, 80);
-
- // Do this manually instead of calling reflowLayout so we can enforce a
- // minimum width.
- int width = 500;
- int height = 350;
-
- getLayout().reflow(width, height);
- setContentSize(width, height);
-
- setMinWidth(310);
- setMinHeight(220);
- setDefaultSize(getWidth(), getHeight(), ImagePosition::CENTER);
-
- setResizable(true);
- addKeyListener(this);
-
- loadWindowState();
-}
-
-void ServerDialog::postInit()
-{
- Window::postInit();
- setVisible(Visible_true);
-
- mConnectButton->requestFocus();
-
- loadServers(true);
-
- mServersList->setSelected(0); // Do this after for the Delete button
-
- if (needUpdateServers())
- downloadServerList();
- else
- logger->log("Skipping servers list update");
-}
-
-ServerDialog::~ServerDialog()
-{
- if (mDownload != nullptr)
- {
- mDownload->cancel();
- delete2(mDownload)
- }
- delete2(mServersListModel);
-}
-
-void ServerDialog::connectToSelectedServer()
-{
- if (client->getState() == State::CONNECT_SERVER)
- return;
-
- const int index = mServersList->getSelected();
- if (index < 0)
- return;
-
- if (mDownload != nullptr)
- mDownload->cancel();
-
- mQuitButton->setEnabled(false);
- mConnectButton->setEnabled(false);
- mLoadButton->setEnabled(false);
-
- ServerInfo server = mServers.at(index);
- mServerInfo->hostname = server.hostname;
- mServerInfo->althostname = server.althostname;
- mServerInfo->port = server.port;
- mServerInfo->type = server.type;
- mServerInfo->name = server.name;
- mServerInfo->description = server.description;
- mServerInfo->registerUrl = server.registerUrl;
- mServerInfo->onlineListUrl = server.onlineListUrl;
- mServerInfo->supportUrl = server.supportUrl;
- mServerInfo->defaultHostName = server.defaultHostName;
- mServerInfo->save = true;
- mServerInfo->persistentIp = server.persistentIp;
- mServerInfo->freeType = server.freeType;
- mServerInfo->updateMirrors = server.updateMirrors;
- mServerInfo->packetVersion = server.packetVersion;
- mServerInfo->updateHosts = server.updateHosts;
- mServerInfo->freeSources = server.freeSources;
- mServerInfo->nonFreeSources = server.nonFreeSources;
- mServerInfo->docs = server.docs;
- mServerInfo->serverUrl = server.serverUrl;
-
- settings.persistentIp = mServerInfo->persistentIp;
- settings.supportUrl = mServerInfo->supportUrl;
- settings.updateMirrors = mServerInfo->updateMirrors;
-
- if (chatLogger != nullptr)
- chatLogger->setServerName(mServerInfo->hostname);
-
- saveCustomServers(*mServerInfo);
-
- if (!LoginDialog::savedPasswordKey.empty())
- {
- if (mServerInfo->hostname != LoginDialog::savedPasswordKey)
- {
- LoginDialog::savedPassword.clear();
- if (desktop != nullptr)
- desktop->reloadWallpaper();
- }
- }
-
- config.setValue("usePersistentIP",
- mPersistentIPCheckBox->isSelected());
- client->setState(State::CONNECT_SERVER);
-}
-
-void ServerDialog::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "connect")
- {
- connectToSelectedServer();
- }
- else if (eventId == "quit")
- {
- close();
- }
- else if (eventId == "load")
- {
- downloadServerList();
- }
- else if (eventId == "addEntry")
- {
- CREATEWIDGET(EditServerDialog, this, ServerInfo(), -1);
- }
- else if (eventId == "editEntry")
- {
- const int index = mServersList->getSelected();
- if (index >= 0)
- {
- CREATEWIDGET(EditServerDialog,
- this,
- mServers.at(index),
- index);
- }
- }
- else if (eventId == "remove")
- {
- const int index = mServersList->getSelected();
- if (index >= 0)
- {
- mServersList->setSelected(0);
- mServers.erase(mServers.begin() + index);
- saveCustomServers();
- }
- }
- else if (eventId == "info")
- {
- const int index = mServersList->getSelected();
- if (index >= 0)
- {
- if (serverInfoWindow != nullptr)
- serverInfoWindow->scheduleDelete();
- serverInfoWindow = CREATEWIDGETR(ServerInfoWindow,
- mServers.at(index));
- }
- }
-}
-
-void ServerDialog::keyPressed(KeyEvent &event)
-{
- PRAGMA45(GCC diagnostic push)
- PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
- switch (event.getActionId())
- {
- case InputAction::GUI_CANCEL:
- event.consume();
- client->setState(State::EXIT);
- return;
-
- case InputAction::GUI_SELECT:
- case InputAction::GUI_SELECT2:
- event.consume();
- action(ActionEvent(nullptr,
- mConnectButton->getActionEventId()));
- return;
-
- case InputAction::GUI_INSERT:
- CREATEWIDGET(EditServerDialog, this, ServerInfo(), -1);
- return;
-
- case InputAction::GUI_DELETE:
- {
- const int index = mServersList->getSelected();
- if (index >= 0)
- {
- mServersList->setSelected(0);
- mServers.erase(mServers.begin() + index);
- saveCustomServers();
- }
- return;
- }
-
- case InputAction::GUI_BACKSPACE:
- {
- const int index = mServersList->getSelected();
- if (index >= 0)
- {
- CREATEWIDGET(EditServerDialog, this, mServers.at(index),
- index);
- }
- return;
- }
-
- default:
- break;
- }
- PRAGMA45(GCC diagnostic pop)
- if (!event.isConsumed())
- mServersList->keyPressed(event);
-}
-
-void ServerDialog::valueChanged(const SelectionEvent &event A_UNUSED)
-{
- const int index = mServersList->getSelected();
- if (index == -1)
- {
- mDeleteButton->setEnabled(false);
- return;
- }
- mDeleteButton->setEnabled(true);
-}
-
-void ServerDialog::mouseClicked(MouseEvent &event)
-{
- if (event.getButton() == MouseButton::LEFT)
- {
- event.consume();
- if (event.getClickCount() == 2 &&
- event.getSource() == mServersList)
- {
- action(ActionEvent(mConnectButton,
- mConnectButton->getActionEventId()));
- }
- }
-}
-
-void ServerDialog::logic()
-{
- BLOCK_START("ServerDialog::logic")
- {
- MutexLocker tempLock(&mMutex);
- if (mDownloadStatus == ServerDialogDownloadStatus::COMPLETE)
- {
- loadServers();
- mDownloadStatus = ServerDialogDownloadStatus::OVER;
- mDescription->setCaption(std::string());
- logger->log("Servers list updated");
- }
- else if (mDownloadStatus == ServerDialogDownloadStatus::IN_PROGRESS)
- {
- // TRANSLATORS: servers dialog label
- mDescription->setCaption(strprintf(_("Downloading server list..."
- "%2.2f%%"), static_cast<double>(mDownloadProgress * 100)));
- }
- else if (mDownloadStatus == ServerDialogDownloadStatus::IDLE)
- {
- // TRANSLATORS: servers dialog label
- mDescription->setCaption(_("Waiting for server..."));
- }
- else if (mDownloadStatus == ServerDialogDownloadStatus::PREPARING)
- {
- // TRANSLATORS: servers dialog label
- mDescription->setCaption(_("Preparing download"));
- }
- else if (mDownloadStatus == ServerDialogDownloadStatus::ERROR)
- {
- // TRANSLATORS: servers dialog label
- mDescription->setCaption(_("Error retreiving server list!"));
- logger->log("Error: servers list updating error");
- }
- }
-
- Window::logic();
- BLOCK_END("ServerDialog::logic")
-}
-
-void ServerDialog::downloadServerList()
-{
- // Try to load the configuration value for the onlineServerList
- std::string listFile = branding.getStringValue("onlineServerList");
- std::string listFile2 = branding.getStringValue("onlineServerList2");
-
- // Fall back to manaplus.org when neither branding
- // nor config set it
- if (listFile.empty())
- listFile = "http://manaplus.org/serverlist.xml";
-
- if (mDownload != nullptr)
- {
- mDownload->cancel();
- delete2(mDownload)
- }
-
- mDownload = new Net::Download(this, listFile,
- &downloadUpdate, false, false, true);
- mDownload->setFile(pathJoin(mDir,
- branding.getStringValue("onlineServerFile")));
- if (!listFile2.empty())
- mDownload->addMirror(listFile2);
- mDownload->start();
-
- config.setValue("serverslistupdate", getDateString());
-}
-
-static void loadHostsGroup(XmlNodeConstPtr node,
- ServerInfo &server)
-{
- HostsGroup group;
- group.name = XML::langProperty(node,
- "name",
- // TRANSLATORS: unknown hosts group name
- _("Unknown"));
- for_each_xml_child_node(hostNode, node)
- {
- if (!xmlNameEqual(hostNode, "host") ||
- !XmlHaveChildContent(hostNode))
- {
- continue;
- }
- const std::string host = XmlChildContent(hostNode);
- if (host.empty())
- continue;
- if (!checkPath(host))
- {
- logger->log1("Warning: incorrect update server name");
- continue;
- }
-
- group.hosts.push_back(host);
- }
- if (!group.hosts.empty())
- server.updateHosts.push_back(group);
-}
-
-static void loadServerSourcesList(XmlNodeConstPtr node,
- STD_VECTOR<ServerUrlInfo> &list)
-{
- for_each_xml_child_node(urlNode, node)
- {
- if (!xmlNameEqual(urlNode, "url") ||
- !XmlHaveChildContent(urlNode))
- {
- continue;
- }
- const std::string name = XML::langProperty(urlNode,
- "name",
- "");
- if (name.empty())
- continue;
- const std::string url = XmlChildContent(urlNode);
- if (url.empty())
- continue;
- list.push_back(ServerUrlInfo(name, url));
- }
-}
-
-static void loadServerSources(XmlNodeConstPtr node,
- ServerInfo &server)
-{
- for_each_xml_child_node(subNode, node)
- {
- if (xmlNameEqual(subNode, "free"))
- {
- loadServerSourcesList(subNode, server.freeSources);
- }
- else if (xmlNameEqual(subNode, "nonfree"))
- {
- loadServerSourcesList(subNode, server.nonFreeSources);
- }
- }
-}
-
-void ServerDialog::loadServers(const bool addNew)
-{
- XML::Document doc(pathJoin(mDir,
- branding.getStringValue("onlineServerFile")),
- UseVirtFs_false,
- SkipError_true);
- XmlNodeConstPtr rootNode = doc.rootNode();
-
- if (rootNode == nullptr ||
- !xmlNameEqual(rootNode, "serverlist"))
- {
- logger->log1("Error loading server list!");
- return;
- }
-
- const int ver = XML::getProperty(rootNode, "version", 0);
- if (ver != 1)
- {
- logger->log("Error: unsupported online server list version: %d",
- ver);
- return;
- }
-
- const std::string lang = getLangShort();
- const std::string description2("description_" + lang);
-
- for_each_xml_child_node(serverNode, rootNode)
- {
- if (!xmlNameEqual(serverNode, "server"))
- continue;
-
- const std::string type = XML::getProperty(
- serverNode, "type", "unknown");
- ServerInfo server;
- server.type = ServerInfo::parseType(type);
- const std::string licenseType = XML::getProperty(
- serverNode, "licenseType", "notset");
- server.freeType = ServerInfo::parseFreeType(licenseType);
-
- // Ignore unknown server types
- if (server.type == ServerType::UNKNOWN)
- {
- logger->log("Ignoring server entry with unknown type: %s",
- type.c_str());
- continue;
- }
-
- server.name = XML::getProperty(serverNode, "name", std::string());
- std::string version = XML::getProperty(serverNode, "minimumVersion",
- std::string());
-
- const bool meetsMinimumVersion = (compareStrI(version, SMALL_VERSION)
- <= 0);
-
- // For display in the list
- if (meetsMinimumVersion)
- version.clear();
- else if (version.empty())
- {
- // TRANSLATORS: servers dialog label
- version = _("requires a newer version");
- }
- else
- {
- // TRANSLATORS: servers dialog label
- version = strprintf(_("requires v%s"), version.c_str());
- }
-
- const Font *const font = gui->getFont();
-
- for_each_xml_child_node(subNode, serverNode)
- {
- if (xmlNameEqual(subNode, "connection"))
- {
- server.hostname = XML::getProperty(subNode, "hostname", "");
- server.althostname = XML::getProperty(
- subNode, "althostname", "");
- server.port = CAST_U16(
- XML::getProperty(subNode, "port", 0));
- server.packetVersion = XML::getProperty(subNode,
- "packetVersion", 0);
-
- if (server.port == 0)
- {
- // If no port is given, use the default for the given type
- server.port = defaultPortForServerType(server.type);
- }
- }
- else if (XmlHaveChildContent(subNode))
- {
- if ((xmlNameEqual(subNode, "description")
- && server.description.empty()) || (!lang.empty()
- && xmlNameEqual(subNode, description2.c_str())))
- {
- server.description = XmlChildContent(subNode);
- }
- else if (xmlNameEqual(subNode, "registerurl"))
- {
- server.registerUrl = XmlChildContent(subNode);
- }
- else if (xmlNameEqual(subNode, "onlineListUrl"))
- {
- server.onlineListUrl = XmlChildContent(subNode);
- }
- else if (xmlNameEqual(subNode, "support"))
- {
- server.supportUrl = XmlChildContent(subNode);
- }
- else if (xmlNameEqual(subNode, "persistentIp"))
- {
- std::string text = XmlChildContent(subNode);
- server.persistentIp = (text == "1" || text == "true");
- }
- else if (xmlNameEqual(subNode, "updateMirror"))
- {
- server.updateMirrors.push_back(XmlChildContent(subNode));
- }
- else if (xmlNameEqual(subNode, "site"))
- {
- server.serverUrl = XmlChildContent(subNode);
- }
- }
- if (xmlNameEqual(subNode, "updates"))
- {
- loadHostsGroup(subNode, server);
- }
- else if (xmlNameEqual(subNode, "defaultUpdateHost"))
- {
- server.defaultHostName = XML::langProperty(
- // TRANSLATORS: default hosts group name
- subNode, "name", _("default"));
- }
- else if (xmlNameEqual(subNode, "sources"))
- {
- loadServerSources(subNode, server);
- }
- else if (xmlNameEqual(subNode, "docs"))
- {
- loadServerSourcesList(subNode, server.docs);
- }
- }
-
- server.version.first = font->getWidth(version);
- server.version.second = version;
-
- MutexLocker tempLock(&mMutex);
- // Add the server to the local list if it's not already present
- bool found = false;
- for (unsigned int i = 0, fsz = CAST_U32(
- mServers.size()); i < fsz; i++)
- {
- if (mServers[i] == server)
- {
- // Use the name listed in the server list
- mServers[i].name = server.name;
- mServers[i].type = server.type;
- mServers[i].freeType = server.freeType;
- mServers[i].version = server.version;
- mServers[i].description = server.description;
- mServers[i].registerUrl = server.registerUrl;
- mServers[i].onlineListUrl = server.onlineListUrl;
- mServers[i].supportUrl = server.supportUrl;
- mServers[i].serverUrl = server.serverUrl;
- mServers[i].althostname = server.althostname;
- mServers[i].persistentIp = server.persistentIp;
- mServers[i].updateMirrors = server.updateMirrors;
- mServers[i].defaultHostName = server.defaultHostName;
- mServers[i].updateHosts = server.updateHosts;
- mServers[i].packetVersion = server.packetVersion;
- mServers[i].freeSources = server.freeSources;
- mServers[i].nonFreeSources = server.nonFreeSources;
- mServers[i].docs = server.docs;
- mServersListModel->setVersionString(i, version);
- found = true;
- break;
- }
- }
- if (!found && addNew)
- mServers.push_back(server);
- }
- if (mServersList->getSelected() < 0)
- mServersList->setSelected(0);
-}
-
-void ServerDialog::loadCustomServers()
-{
- for (int i = 0; i < MAX_SERVERLIST; ++i)
- {
- const std::string index = toString(i);
- const std::string nameKey("MostUsedServerDescName" + index);
- const std::string descKey("MostUsedServerDescription" + index);
- const std::string hostKey("MostUsedServerName" + index);
- const std::string typeKey("MostUsedServerType" + index);
- const std::string portKey("MostUsedServerPort" + index);
- const std::string onlineListUrlKey
- ("MostUsedServerOnlineList" + index);
- const std::string persistentIpKey("persistentIp" + index);
- const std::string packetVersionKey
- ("MostUsedServerPacketVersion" + index);
-
- ServerInfo server;
- server.name = config.getValue(nameKey, "");
- server.description = config.getValue(descKey, "");
- server.onlineListUrl = config.getValue(onlineListUrlKey, "");
- server.hostname = config.getValue(hostKey, "");
- server.type = ServerInfo::parseType(config.getValue(typeKey, ""));
- server.persistentIp = config.getValue(
- persistentIpKey, 0) != 0 ? true : false;
- server.packetVersion = config.getValue(packetVersionKey, 0);
-
- const int defaultPort = defaultPortForServerType(server.type);
- server.port = CAST_U16(
- config.getValue(portKey, defaultPort));
-
- // skip invalid server
- if (!server.isValid())
- continue;
-
- server.save = true;
- mServers.push_back(server);
- }
-}
-
-void ServerDialog::saveCustomServers(const ServerInfo &currentServer,
- const int index)
-{
- // Make sure the current server is mentioned first
- if (currentServer.isValid())
- {
- if (index >= 0 && CAST_SIZE(index) < mServers.size())
- {
- mServers[index] = currentServer;
- }
- else
- {
- FOR_EACH (ServerInfos::iterator, i, mServers)
- {
- if (*i == currentServer)
- {
- mServers.erase(i);
- break;
- }
- }
- mServers.insert(mServers.begin(), currentServer);
- }
- }
-
- int savedServerCount = 0;
-
- for (unsigned i = 0, fsz = CAST_U32(mServers.size());
- i < fsz && savedServerCount < MAX_SERVERLIST; ++ i)
- {
- const ServerInfo &server = mServers.at(i);
-
- // Only save servers that were loaded from settings
- if (!(server.save && server.isValid()))
- continue;
-
- const std::string num = toString(savedServerCount);
- const std::string nameKey("MostUsedServerDescName" + num);
- const std::string descKey("MostUsedServerDescription" + num);
- const std::string hostKey("MostUsedServerName" + num);
- const std::string typeKey("MostUsedServerType" + num);
- const std::string portKey("MostUsedServerPort" + num);
- const std::string onlineListUrlKey
- ("MostUsedServerOnlineList" + num);
- const std::string persistentIpKey("persistentIp" + num);
- const std::string packetVersionKey
- ("MostUsedServerPacketVersion" + num);
-
- config.setValue(nameKey, server.name);
- config.setValue(descKey, server.description);
- config.setValue(onlineListUrlKey, server.onlineListUrl);
- config.setValue(hostKey, server.hostname);
- config.setValue(typeKey, serverTypeToString(server.type));
- config.setValue(portKey, toString(server.port));
- config.setValue(persistentIpKey, server.persistentIp);
- config.setValue(packetVersionKey, server.packetVersion);
- ++ savedServerCount;
- }
-
- // Insert an invalid entry at the end to make the loading stop there
- if (savedServerCount < MAX_SERVERLIST)
- config.setValue("MostUsedServerName" + toString(savedServerCount), "");
-}
-
-int ServerDialog::downloadUpdate(void *ptr,
- const DownloadStatusT status,
- size_t total,
- const size_t remaining)
-{
- if ((ptr == nullptr) || status == DownloadStatus::Cancelled)
- return -1;
-
- ServerDialog *const sd = reinterpret_cast<ServerDialog*>(ptr);
- bool finished = false;
-
- if (sd->mDownload == nullptr)
- return -1;
-
- if (status == DownloadStatus::Complete)
- {
- finished = true;
- }
- else if (CAST_S32(status) < 0)
- {
- logger->log("Error retreiving server list: %s\n",
- sd->mDownload->getError());
- sd->mDownloadStatus = ServerDialogDownloadStatus::ERROR;
- }
- else
- {
- float progress = static_cast<float>(remaining);
- if (total != 0u)
- progress /= static_cast<float>(total);
-
- if (progress != progress || progress < 0.0F)
- progress = 0.0f;
- else if (progress > 1.0F)
- progress = 1.0F;
-
- MutexLocker lock1(&sd->mMutex);
- sd->mDownloadStatus = ServerDialogDownloadStatus::IN_PROGRESS;
- sd->mDownloadProgress = progress;
- }
-
- if (finished)
- {
- MutexLocker lock1(&sd->mMutex);
- sd->mDownloadStatus = ServerDialogDownloadStatus::COMPLETE;
- }
-
- return 0;
-}
-
-void ServerDialog::updateServer(const ServerInfo &server, const int index)
-{
- saveCustomServers(server, index);
-}
-
-bool ServerDialog::needUpdateServers() const
-{
- if (mServers.empty() || config.getStringValue("serverslistupdate")
- != getDateString())
- {
- return true;
- }
-
- return false;
-}
-
-void ServerDialog::close()
-{
- if (mDownload != nullptr)
- mDownload->cancel();
- client->setState(State::FORCE_QUIT);
- Window::close();
-}
diff --git a/src/gui/windows/serverdialog.h b/src/gui/windows/serverdialog.h
deleted file mode 100644
index b541e7f65..000000000
--- a/src/gui/windows/serverdialog.h
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_SERVERDIALOG_H
-#define GUI_WINDOWS_SERVERDIALOG_H
-
-#include "gui/widgets/window.h"
-
-#include "enums/gui/serverdialogdonwloadstatus.h"
-
-#include "enums/net/downloadstatus.h"
-
-#include "net/serverinfo.h"
-
-#include "utils/mutex.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/keylistener.h"
-#include "listeners/selectionlistener.h"
-
-class Button;
-class CheckBox;
-class Label;
-class ListBox;
-class ServersListModel;
-
-namespace Net
-{
- class Download;
-} // namespace Net
-
-/**
- * The server choice dialog.
- *
- * \ingroup Interface
- */
-class ServerDialog final : public Window,
- public ActionListener,
- public KeyListener,
- public SelectionListener
-{
- public:
- /**
- * Constructor
- *
- * @see Window::Window
- */
- ServerDialog(ServerInfo *const serverInfo, const std::string &dir);
-
- A_DELETE_COPY(ServerDialog)
-
- void postInit() override final;
-
- /**
- * Destructor
- */
- ~ServerDialog();
-
- /**
- * Called when receiving actions from the widgets.
- */
- void action(const ActionEvent &event) override final;
-
- void keyPressed(KeyEvent &event) override final;
-
- /**
- * Called when the selected value changed in the servers list box.
- */
- void valueChanged(const SelectionEvent &event) override final;
-
- void mouseClicked(MouseEvent &event) override final;
-
- void logic() override final;
-
- void updateServer(const ServerInfo &server, const int index);
-
- void connectToSelectedServer();
-
- void close() override final;
-
- protected:
- friend class ServersListModel;
-
- MutexLocker lock()
- { return MutexLocker(&mMutex); }
-
- private:
- friend class EditServerDialog;
-
- /**
- * Called to load a list of available server from an online xml file.
- */
- void downloadServerList();
-
- void loadServers(const bool addNew = true);
-
- void loadCustomServers();
-
- void saveCustomServers(const ServerInfo &currentServer = ServerInfo(),
- const int index = -1);
-
- bool needUpdateServers() const;
-
- static int downloadUpdate(void *ptr,
- const DownloadStatusT status,
- size_t total,
- const size_t remaining);
-
- Mutex mMutex;
- ServerInfos mServers;
- const std::string &mDir;
- Label *mDescription A_NONNULLPOINTER;
- Button *mQuitButton A_NONNULLPOINTER;
- Button *mConnectButton A_NONNULLPOINTER;
- Button *mAddEntryButton A_NONNULLPOINTER;
- Button *mEditEntryButton A_NONNULLPOINTER;
- Button *mDeleteButton A_NONNULLPOINTER;
- Button *mLoadButton A_NONNULLPOINTER;
- Button *mInfoButton A_NONNULLPOINTER;
- ServersListModel *mServersListModel A_NONNULLPOINTER;
- ListBox *mServersList A_NONNULLPOINTER;
-
- /** Status of the current download. */
- Net::Download *mDownload;
- ServerInfo *mServerInfo;
- CheckBox *mPersistentIPCheckBox;
- float mDownloadProgress;
- ServerDialogDownloadStatusT mDownloadStatus;
-};
-
-#endif // GUI_WINDOWS_SERVERDIALOG_H
diff --git a/src/gui/windows/serverinfowindow.cpp b/src/gui/windows/serverinfowindow.cpp
deleted file mode 100644
index 20f8d5f42..000000000
--- a/src/gui/windows/serverinfowindow.cpp
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/serverinfowindow.h"
-
-#include "enums/gui/layouttype.h"
-
-#include "gui/gui.h"
-
-#include "gui/widgets/layout.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/staticbrowserbox.h"
-
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-#include "utils/process.h"
-
-#include "debug.h"
-
-ServerInfoWindow *serverInfoWindow = nullptr;
-
-ServerInfoWindow::ServerInfoWindow(ServerInfo &serverInfo) :
- // TRANSLATORS: servers dialog name
- Window(_("Server info"), Modal_false, nullptr, "serverinfo.xml"),
- LinkHandler(),
- mServerInfo(serverInfo),
- mBrowserBox(new StaticBrowserBox(this, Opaque_true,
- "browserbox.xml")),
- mScrollArea(new ScrollArea(this, mBrowserBox,
- Opaque_true, "serverinfo_background.xml"))
-{
- setMinWidth(300);
- setMinHeight(220);
- setContentSize(455, 350);
- setWindowName("ServerInfoWindow");
- setCloseButton(true);
- setResizable(true);
- setStickyButtonLock(true);
-
- setDefaultSize(500, 400, ImagePosition::CENTER);
-
- mBrowserBox->setOpaque(Opaque_false);
- mBrowserBox->setLinkHandler(this);
- if (gui != nullptr)
- mBrowserBox->setFont(gui->getHelpFont());
- mBrowserBox->setProcessVars(true);
- mBrowserBox->setEnableTabs(true);
-
- place(0, 0, mScrollArea, 5, 3).setPadding(3);
-
- Layout &layout = getLayout();
- layout.setRowHeight(0, LayoutType::SET);
-
- loadWindowState();
- enableVisibleSound(true);
- widgetResized(Event(nullptr));
-}
-
-void ServerInfoWindow::postInit()
-{
- Window::postInit();
- setVisible(Visible_true);
- showServerInfo();
-}
-
-ServerInfoWindow::~ServerInfoWindow()
-{
-}
-
-void ServerInfoWindow::handleLink(const std::string &link,
- MouseEvent *const event A_UNUSED)
-{
- if (strStartWith(link, "http://") ||
- strStartWith(link, "https://"))
- {
- openBrowser(link);
- }
-}
-
-void ServerInfoWindow::showServerInfo()
-{
- const ServerFreeTypeT type = mServerInfo.freeType;
- if (type == ServerFreeType::Free)
- {
- // TRANSLATORS: server info comment
- mBrowserBox->addRow(_("##BServer with free license."));
- }
- else if (type == ServerFreeType::NonFree)
- {
- // TRANSLATORS: server info comment
- mBrowserBox->addRow(_("##BServer with non free license."));
- }
- else if (type == ServerFreeType::Unknown ||
- type == ServerFreeType::NotSet)
- {
- // TRANSLATORS: server info comment
- mBrowserBox->addRow(_("##BServer unknown license."));
- }
- mBrowserBox->addRow("");
- addServerComment(mServerInfo.serverUrl,
- // TRANSLATORS: server info comment
- _("Server"));
- addServerComment(mServerInfo.supportUrl,
- // TRANSLATORS: server info comment
- _("Support"));
- addServerComment(mServerInfo.registerUrl,
- // TRANSLATORS: server info comment
- _("Register"));
-
- addSourcesList(mServerInfo.nonFreeSources,
- // TRANSLATORS: server info non free comment
- _("##BNon free sources"));
- addSourcesList(mServerInfo.freeSources,
- // TRANSLATORS: server info non free comment
- _("##BFree sources"));
- addSourcesList(mServerInfo.docs,
- // TRANSLATORS: server info documentation comment
- _("##BDocumentation"));
- mBrowserBox->updateHeight();
-}
-
-void ServerInfoWindow::addSourcesList(const STD_VECTOR<ServerUrlInfo> &list,
- const std::string &comment)
-{
- if (!list.empty())
- {
- mBrowserBox->addRow("");
- mBrowserBox->addRow(comment);
- FOR_EACH (STD_VECTOR<ServerUrlInfo>::const_iterator, it, list)
- {
- const ServerUrlInfo &info = *it;
- addServerComment(info.url,
- info.name);
- }
- }
-}
-
-void ServerInfoWindow::addServerComment(const std::string &url,
- const std::string &comment)
-{
- std::string str;
- if (!url.empty())
- {
- if (strStartWith(url, "http://") ||
- strStartWith(url, "https://"))
- {
- str = strprintf("%s: @@%s|@@##0",
- comment.c_str(),
- url.c_str());
- }
- else
- {
- str = strprintf("%s: %s",
- comment.c_str(),
- url.c_str());
- }
- mBrowserBox->addRow(str);
- }
-}
-
-void ServerInfoWindow::close()
-{
- Window::close();
- if (serverInfoWindow == this)
- serverInfoWindow = nullptr;
- scheduleDelete();
-}
diff --git a/src/gui/windows/serverinfowindow.h b/src/gui/windows/serverinfowindow.h
deleted file mode 100644
index d872b1fdf..000000000
--- a/src/gui/windows/serverinfowindow.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_SERVERINFOWINDOW_H
-#define GUI_WINDOWS_SERVERINFOWINDOW_H
-
-#include "gui/widgets/window.h"
-
-#include "gui/widgets/linkhandler.h"
-
-#include "net/serverinfo.h"
-
-class ScrollArea;
-class ServerInfo;
-class StaticBrowserBox;
-
-class ServerInfoWindow final : public Window,
- public LinkHandler
-{
- public:
- explicit ServerInfoWindow(ServerInfo &serverInfo);
-
- A_DELETE_COPY(ServerInfoWindow)
-
- void postInit() override final;
-
- ~ServerInfoWindow();
-
- void handleLink(const std::string &link,
- MouseEvent *const event A_UNUSED) override final;
-
- void close() override final;
-
- protected:
- void showServerInfo();
-
- void addSourcesList(const STD_VECTOR<ServerUrlInfo> &list,
- const std::string &comment);
-
- void addServerComment(const std::string &url,
- const std::string &comment);
-
- private:
- ServerInfo mServerInfo;
- StaticBrowserBox *mBrowserBox A_NONNULLPOINTER;
- ScrollArea *mScrollArea A_NONNULLPOINTER;
-};
-
-extern ServerInfoWindow *serverInfoWindow;
-
-#endif // GUI_WINDOWS_SERVERINFOWINDOW_H
diff --git a/src/gui/windows/setupwindow.cpp b/src/gui/windows/setupwindow.cpp
deleted file mode 100644
index eeb86ce7d..000000000
--- a/src/gui/windows/setupwindow.cpp
+++ /dev/null
@@ -1,335 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/setupwindow.h"
-
-#include "configuration.h"
-#include "game.h"
-#include "main.h"
-
-#include "gui/windows/chatwindow.h"
-#include "gui/windows/statuswindow.h"
-
-#include "gui/widgets/createwidget.h"
-
-#include "gui/widgets/tabs/setup_audio.h"
-#include "gui/widgets/tabs/setup_chat.h"
-#include "gui/widgets/tabs/setup_colors.h"
-#include "gui/widgets/tabs/setup_input.h"
-#include "gui/widgets/tabs/setup_joystick.h"
-#include "gui/widgets/tabs/setup_misc.h"
-#include "gui/widgets/tabs/setup_mods.h"
-#include "gui/widgets/tabs/setup_perfomance.h"
-#include "gui/widgets/tabs/setup_players.h"
-#include "gui/widgets/tabs/setup_quick.h"
-#include "gui/widgets/tabs/setup_relations.h"
-#include "gui/widgets/tabs/setup_theme.h"
-#include "gui/widgets/tabs/setup_touch.h"
-#include "gui/widgets/tabs/setup_video.h"
-#include "gui/widgets/tabs/setup_visual.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/tabbedarea.h"
-
-#include "input/touch/touchmanager.h"
-
-#include "utils/delete2.h"
-#include "utils/dtor.h"
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-SetupWindow *setupWindow = nullptr;
-
-SetupWindow::SetupWindow() :
- // TRANSLATORS: setup window name
- Window(_("Setup"), Modal_false, nullptr, "setup.xml"),
- ActionListener(),
- mTabs(),
- mWindowsToReset(),
- mButtons(),
- mModsTab(nullptr),
- mQuickTab(nullptr),
- mResetWindows(nullptr),
- mPanel(CREATEWIDGETR(TabbedArea, this)),
- mVersion(new Label(this, FULL_VERSION)),
- mButtonPadding(5)
-{
- setCloseButton(true);
- setResizable(true);
- setStickyButtonLock(true);
-}
-
-void SetupWindow::postInit()
-{
- Window::postInit();
- int width = 620;
- const int height = 450;
-
- if (config.getIntValue("screenwidth") >= 730)
- width += 100;
-
- setContentSize(width, height);
- setMinWidth(310);
- setMinHeight(210);
-
- mPanel->setSelectable(false);
- mPanel->getTabContainer()->setSelectable(false);
- mPanel->getWidgetContainer()->setSelectable(false);
-
- static const char *const buttonNames[] =
- {
- // TRANSLATORS: setup button
- N_("Apply"),
- // TRANSLATORS: setup button
- N_("Cancel"),
- // TRANSLATORS: setup button
- N_("Store"),
- // TRANSLATORS: setup button
- N_("Reset Windows"),
- nullptr
- };
- int x = width;
- mButtonPadding = getOption("buttonPadding", 5);
- for (const char *const * curBtn = buttonNames;
- *curBtn != nullptr;
- ++ curBtn)
- {
- Button *const btn = new Button(this, gettext(*curBtn), *curBtn, this);
- mButtons.push_back(btn);
- x -= btn->getWidth() + mButtonPadding;
- btn->setPosition(x, height - btn->getHeight() - mButtonPadding);
- add(btn);
-
- // Store this button, as it needs to be enabled/disabled
- if (strcmp(*curBtn, "Reset Windows") == 0)
- mResetWindows = btn;
- }
-
- mPanel->setDimension(Rect(5, 5, width - 10, height - 40));
- mPanel->enableScrollButtons(true);
-
- mTabs.push_back(new Setup_Video(this));
- mTabs.push_back(new Setup_Visual(this));
- mTabs.push_back(new Setup_Audio(this));
- mTabs.push_back(new Setup_Perfomance(this));
- mTabs.push_back(new Setup_Touch(this));
- mTabs.push_back(new Setup_Input(this));
- mTabs.push_back(new Setup_Joystick(this));
- mTabs.push_back(new Setup_Colors(this));
- mTabs.push_back(new Setup_Chat(this));
- mTabs.push_back(new Setup_Players(this));
- mTabs.push_back(new Setup_Relations(this));
- mTabs.push_back(new Setup_Theme(this));
- mTabs.push_back(new Setup_Misc(this));
-
- FOR_EACH (std::list<SetupTab*>::const_iterator, i, mTabs)
- {
- SetupTab *const tab = *i;
- mPanel->addTab(tab->getName(), tab);
- }
- add(mPanel);
-
- if (mResetWindows != nullptr)
- {
- mVersion->setPosition(9,
- height - mVersion->getHeight() - mResetWindows->getHeight() - 9);
- }
- else
- {
- mVersion->setPosition(9, height - mVersion->getHeight() - 30);
- }
- add(mVersion);
-
- center();
-
- widgetResized(Event(nullptr));
- setInGame(false);
- enableVisibleSound(true);
-}
-
-SetupWindow::~SetupWindow()
-{
- delete_all(mTabs);
- mButtons.clear();
- setupWindow = nullptr;
-}
-
-void SetupWindow::action(const ActionEvent &event)
-{
- if (Game::instance() != nullptr)
- Game::instance()->resetAdjustLevel();
- const std::string &eventId = event.getId();
-
- if (eventId == "Apply")
- {
- setVisible(Visible_false);
- for_each(mTabs.begin(), mTabs.end(), std::mem_fun(&SetupTab::apply));
- }
- else if (eventId == "Cancel")
- {
- doCancel();
- }
- else if (eventId == "Store")
- {
- if (chatWindow != nullptr)
- chatWindow->saveState();
- config.write();
- serverConfig.write();
- }
- else if (eventId == "Reset Windows")
- {
- // Bail out if this action happens to be activated before the windows
- // are created (though it should be disabled then)
- if (statusWindow == nullptr)
- return;
-
- FOR_EACH (std::list<Window*>::const_iterator, it, mWindowsToReset)
- {
- if (*it != nullptr)
- (*it)->resetToDefaultSize();
- }
- }
-}
-
-void SetupWindow::setInGame(const bool inGame)
-{
- if (mResetWindows != nullptr)
- mResetWindows->setEnabled(inGame);
-}
-
-void SetupWindow::externalUpdate()
-{
- unloadAdditionalTabs();
- mModsTab = new Setup_Mods(this);
- mTabs.push_back(mModsTab);
- mPanel->addTab(mModsTab->getName(), mModsTab);
- mQuickTab = new Setup_Quick(this);
- mTabs.push_back(mQuickTab);
- mPanel->addTab(mQuickTab->getName(), mQuickTab);
- FOR_EACH (std::list<SetupTab*>::const_iterator, it, mTabs)
- {
- if (*it != nullptr)
- (*it)->externalUpdated();
- }
-}
-
-void SetupWindow::unloadTab(SetupTab *const page)
-{
- if (page != nullptr)
- {
- mTabs.remove(page);
- mPanel->removeTab(mPanel->getTab(page->getName()));
- }
-}
-
-void SetupWindow::unloadAdditionalTabs()
-{
- unloadTab(mModsTab);
- unloadTab(mQuickTab);
- delete2(mModsTab);
- delete2(mQuickTab);
-}
-
-void SetupWindow::externalUnload()
-{
- FOR_EACH (std::list<SetupTab*>::const_iterator, it, mTabs)
- {
- if (*it != nullptr)
- (*it)->externalUnloaded();
- }
- unloadAdditionalTabs();
-}
-
-void SetupWindow::registerWindowForReset(Window *const window)
-{
- mWindowsToReset.push_back(window);
-}
-
-void SetupWindow::unregisterWindowForReset(const Window *const window)
-{
- FOR_EACH (std::list<Window*>::iterator, it, mWindowsToReset)
- {
- if (*it == window)
- {
- mWindowsToReset.erase(it);
- return;
- }
- }
-}
-
-void SetupWindow::hideWindows()
-{
- FOR_EACH (std::list<Window*>::const_iterator, it, mWindowsToReset)
- {
- Window *const window = *it;
- if ((window != nullptr) && !window->isSticky())
- window->setVisible(Visible_false);
- }
- setVisible(Visible_false);
-}
-
-void SetupWindow::doCancel()
-{
- setVisible(Visible_false);
- for_each(mTabs.begin(), mTabs.end(), std::mem_fun(&SetupTab::cancel));
-}
-
-void SetupWindow::activateTab(const std::string &name)
-{
- std::string tmp = gettext(name.c_str());
- mPanel->setSelectedTabByName(tmp);
-}
-
-void SetupWindow::setVisible(Visible visible)
-{
- touchManager.setTempHide(visible == Visible_true);
- Window::setVisible(visible);
-}
-
-void SetupWindow::widgetResized(const Event &event)
-{
- Window::widgetResized(event);
-
- const Rect area = getChildrenArea();
- int x = area.width;
- const int height = area.height;
- const int width = area.width;
- mPanel->setDimension(Rect(5, 5, width - 10, height - 40));
- FOR_EACH (STD_VECTOR<Button*>::iterator, it, mButtons)
- {
- Button *const btn = *it;
- x -= btn->getWidth() + mButtonPadding;
- btn->setPosition(x, height - btn->getHeight() - mButtonPadding);
- }
- if (mResetWindows != nullptr)
- {
- mVersion->setPosition(9,
- height - mVersion->getHeight() - mResetWindows->getHeight() - 9);
- }
- else
- {
- mVersion->setPosition(9, height - mVersion->getHeight() - 30);
- }
-}
diff --git a/src/gui/windows/setupwindow.h b/src/gui/windows/setupwindow.h
deleted file mode 100644
index 79a11a469..000000000
--- a/src/gui/windows/setupwindow.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_SETUPWINDOW_H
-#define GUI_WINDOWS_SETUPWINDOW_H
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-
-class Button;
-class Label;
-class SetupTab;
-class TabbedArea;
-
-/**
- * The setup dialog. Displays several tabs for configuring different aspects
- * of the game.
- *
- * \ingroup GUI
- */
-class SetupWindow final : public Window,
- public ActionListener
-{
- public:
- SetupWindow();
-
- A_DELETE_COPY(SetupWindow)
-
- ~SetupWindow();
-
- void postInit() override final;
-
- void action(const ActionEvent &event) override final;
-
- void setInGame(const bool inGame);
-
- void externalUpdate();
-
- void externalUnload();
-
- void registerWindowForReset(Window *const window);
-
- void unregisterWindowForReset(const Window *const window);
-
- void hideWindows();
-
- void clearWindowsForReset()
- { mWindowsToReset.clear(); }
-
- void doCancel();
-
- void activateTab(const std::string &name);
-
- void setVisible(Visible visible) override final;
-
- void widgetResized(const Event &event) override final;
-
- private:
- void unloadAdditionalTabs();
-
- void unloadTab(SetupTab *const page);
-
- std::list<SetupTab*> mTabs;
- std::list<Window*> mWindowsToReset;
- STD_VECTOR<Button*> mButtons;
- SetupTab *mModsTab;
- SetupTab *mQuickTab;
- Button *mResetWindows;
- TabbedArea *mPanel A_NONNULLPOINTER;
- Label *mVersion A_NONNULLPOINTER;
- int mButtonPadding;
-};
-
-extern SetupWindow* setupWindow;
-
-#endif // GUI_WINDOWS_SETUPWINDOW_H
diff --git a/src/gui/windows/shopselldialog.cpp b/src/gui/windows/shopselldialog.cpp
deleted file mode 100644
index 26911836b..000000000
--- a/src/gui/windows/shopselldialog.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifdef TMWA_SUPPORT
-
-#include "gui/windows/shopselldialog.h"
-
-#include "being/playerinfo.h"
-
-#include "gui/windows/tradewindow.h"
-
-#include "gui/models/shopitems.h"
-
-#include "gui/widgets/shoplistbox.h"
-
-#include "net/buysellhandler.h"
-
-#include "debug.h"
-
-ShopSellDialog::ShopSellDialog(const std::string &nick) :
- SellDialog(IsSell_true, Advanced_false),
- mNick(nick)
-{
-}
-
-void ShopSellDialog::sellAction(const ActionEvent &event A_UNUSED)
-{
- if (mAmountItems <= 0 || mAmountItems > mMaxItems)
- return;
-
- const int selectedItem = mShopItemList->getSelected();
- ShopItem *const item = mShopItems->at(selectedItem);
- if (item == nullptr || PlayerInfo::isItemProtected(item->getId()))
- return;
- buySellHandler->sendSellRequest(mNick, item, mAmountItems);
-
- if (tradeWindow != nullptr)
- tradeWindow->addAutoItem(mNick, item, mAmountItems);
-}
-
-#endif // TMWA_SUPPORT
diff --git a/src/gui/windows/shopselldialog.h b/src/gui/windows/shopselldialog.h
deleted file mode 100644
index debed53b3..000000000
--- a/src/gui/windows/shopselldialog.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_SHOPSELLDIALOG_H
-#define GUI_WINDOWS_SHOPSELLDIALOG_H
-
-#ifdef TMWA_SUPPORT
-
-#include "gui/widgets/selldialog.h"
-
-/**
- * The sell dialog.
- *
- * \ingroup Interface
- */
-class ShopSellDialog final : public SellDialog
-{
- public:
- /**
- * Constructor.
- *
- * @see Window::Window
- */
- explicit ShopSellDialog(const std::string &nick);
-
- A_DELETE_COPY(ShopSellDialog)
-
- protected:
- void sellAction(const ActionEvent &event) override final;
-
- std::string mNick;
-};
-
-#endif // TMWA_SUPPORT
-#endif // GUI_WINDOWS_SHOPSELLDIALOG_H
diff --git a/src/gui/windows/shopwindow.cpp b/src/gui/windows/shopwindow.cpp
deleted file mode 100644
index 0e55bcca1..000000000
--- a/src/gui/windows/shopwindow.cpp
+++ /dev/null
@@ -1,1175 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/shopwindow.h"
-
-#include "const/resources/currency.h"
-
-#ifdef TMWA_SUPPORT
-#include "gui/windows/buydialog.h"
-#include "gui/windows/chatwindow.h"
-#include "gui/windows/confirmdialog.h"
-#include "gui/windows/shopselldialog.h"
-#include "gui/windows/tradewindow.h"
-
-#include "const/gui/chat.h"
-#endif // TMWA_SUPPORT
-
-#include "enums/gui/layouttype.h"
-
-#include "gui/windows/editdialog.h"
-
-#include "gui/windows/itemamountwindow.h"
-#include "gui/windows/setupwindow.h"
-
-#include "gui/models/shopitems.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/checkbox.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/layout.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/shoplistbox.h"
-#include "gui/widgets/tabstrip.h"
-
-#include "listeners/shoprenamelistener.h"
-
-#ifdef TMWA_SUPPORT
-#include "actormanager.h"
-#include "soundmanager.h"
-#endif // TMWA_SUPPORT
-#include "configuration.h"
-#include "settings.h"
-
-#include "being/localplayer.h"
-#include "being/playerinfo.h"
-
-#ifdef TMWA_SUPPORT
-#include "being/playerrelations.h"
-#include "net/chathandler.h"
-#endif // TMWA_SUPPORT
-#include "net/buyingstorehandler.h"
-#include "net/vendinghandler.h"
-#include "net/net.h"
-#ifdef TMWA_SUPPORT
-#include "net/tradehandler.h"
-#endif // TMWA_SUPPORT
-
-#include "utils/checkutils.h"
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-
-#ifdef TMWA_SUPPORT
-#include "resources/iteminfo.h"
-#endif // TMWA_SUPPORT
-
-#include "resources/inventory/inventory.h"
-
-#include "resources/item/shopitem.h"
-
-#include <sys/stat.h>
-
-#include <sstream>
-
-#include "debug.h"
-
-ShopWindow *shopWindow = nullptr;
-extern std::string tradePartnerName;
-ShopWindow::DialogList ShopWindow::instances;
-
-ShopWindow::ShopWindow() :
- // TRANSLATORS: shop window name
- Window(_("Personal Shop"), Modal_false, nullptr, "shop.xml"),
- VendingModeListener(),
- VendingSlotsListener(),
- BuyingStoreModeListener(),
- BuyingStoreSlotsListener(),
- ActionListener(),
- SelectionListener(),
- // TRANSLATORS: shop window button
- mCloseButton(new Button(this, _("Close"), "close", this)),
- mBuyShopItems(new ShopItems(false, DEFAULT_CURRENCY)),
- mSellShopItems(new ShopItems(false, DEFAULT_CURRENCY)),
- mTradeItem(nullptr),
- mBuyShopItemList(CREATEWIDGETR(ShopListBox,
- this, mBuyShopItems, mBuyShopItems, ShopListBoxType::BuyShop)),
- mSellShopItemList(CREATEWIDGETR(ShopListBox,
- this, mSellShopItems, mSellShopItems, ShopListBoxType::SellShop)),
- mCurrentShopItemList(nullptr),
- mScrollArea(new ScrollArea(this, mBuyShopItemList,
- fromBool(getOptionBool("showbuybackground"), Opaque),
- "shop_buy_background.xml")),
- // TRANSLATORS: shop window label
- mAddButton(new Button(this, _("Add"), "add", this)),
- // TRANSLATORS: shop window label
- mDeleteButton(new Button(this, _("Delete"), "delete", this)),
- mAnnounceButton(nullptr),
- mPublishButton(nullptr),
- mRenameButton(nullptr),
- mAnnounceLinks(nullptr),
- mTabs(nullptr),
- mAcceptPlayer(),
- mTradeNick(),
- mSellShopName(serverConfig.getStringValue("sellShopName")),
- mSelectedItem(-1),
- mAnnonceTime(0),
- mLastRequestTimeList(0),
- mLastRequestTimeItem(0),
- mRandCounter(0),
- mTradeMoney(0),
- mSellShopSize(0),
- mBuyShopSize(0),
- isBuySelected(true),
- mHaveVending(Net::getNetworkType() != ServerType::TMWATHENA),
- mEnableBuyingStore(false),
- mEnableVending(false)
-{
- setWindowName("Personal Shop");
- setResizable(true);
- setCloseButton(true);
- setStickyButtonLock(true);
- setMinWidth(300);
- setMinHeight(220);
- if (mainGraphics->mWidth > 600)
- setDefaultSize(500, 300, ImagePosition::CENTER);
- else
- setDefaultSize(380, 300, ImagePosition::CENTER);
-
- if (setupWindow != nullptr)
- setupWindow->registerWindowForReset(this);
-
- const int size = config.getIntValue("fontSize")
- + getOption("tabHeightAdjust", 16);
- mTabs = new TabStrip(this, "shop", size);
- mTabs->addActionListener(this);
- mTabs->setActionEventId("tab_");
- // TRANSLATORS: shop window tab name
- mTabs->addButton(_("Buy"), "buy", true);
- // TRANSLATORS: shop window tab name
- mTabs->addButton(_("Sell"), "sell", false);
- mTabs->setSelectable(false);
- mScrollArea->setSelectable(false);
-
- loadList();
-
- mBuyShopItemList->setPriceCheck(false);
- mSellShopItemList->setPriceCheck(false);
-
- mScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
-
- mBuyShopItemList->addSelectionListener(this);
- mSellShopItemList->addSelectionListener(this);
-
- ContainerPlacer placer;
- placer = getPlacer(0, 0);
-
- placer(0, 0, mTabs, 8).setPadding(3);
-
- if (mHaveVending)
- {
- // TRANSLATORS: shop window button
- mPublishButton = new Button(this, _("Publish"), "publish", this);
- // TRANSLATORS: shop window button
- mRenameButton = new Button(this, _("Rename"), "rename", this);
- placer(2, 6, mPublishButton);
- placer(3, 6, mRenameButton);
- }
- else
- {
- // TRANSLATORS: shop window button
- mAnnounceButton = new Button(this, _("Announce"), "announce", this);
- // TRANSLATORS: shop window checkbox
- mAnnounceLinks = new CheckBox(this, _("Show links in announce"), false,
- this, "link announce");
-
- placer(2, 6, mAnnounceButton);
- placer(0, 7, mAnnounceLinks, 7);
- }
-
- placer(0, 1, mScrollArea, 8, 5).setPadding(3);
- placer(0, 6, mAddButton);
- placer(1, 6, mDeleteButton);
- placer(7, 6, mCloseButton);
-
- Layout &layout = getLayout();
- layout.setRowHeight(0, LayoutType::SET);
-
- center();
- loadWindowState();
- updateShopName();
- instances.push_back(this);
-}
-
-void ShopWindow::postInit()
-{
- Window::postInit();
- setVisible(Visible_false);
- enableVisibleSound(true);
- updateSelection();
-}
-
-ShopWindow::~ShopWindow()
-{
- saveList();
-
- delete2(mBuyShopItemList);
- delete2(mSellShopItemList);
- delete2(mBuyShopItems);
- delete2(mSellShopItems);
- delete2(mTradeItem);
-
- instances.remove(this);
-}
-
-void ShopWindow::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "close")
- {
- close();
- return;
- }
-#ifdef TMWA_SUPPORT
- else if (eventId == "yes")
- {
- startTrade();
- }
- else if (eventId == "no")
- {
- mTradeNick.clear();
- }
- else if (eventId == "ignore")
- {
- playerRelations.ignoreTrade(mTradeNick);
- mTradeNick.clear();
- }
- else if (eventId == "announce")
- {
- if (isBuySelected)
- {
- if (mBuyShopItems->getNumberOfElements() > 0)
- announce(mBuyShopItems, BUY);
- }
- else if (mSellShopItems->getNumberOfElements() > 0)
- {
- announce(mSellShopItems, SELL);
- }
- }
-#endif // TMWA_SUPPORT
- else if (eventId == "delete")
- {
- if (isBuySelected)
- {
- if (mBuyShopItemList != nullptr &&
- mBuyShopItemList->getSelected() >= 0)
- {
- mBuyShopItems->del(mBuyShopItemList->getSelected());
- if (isShopEmpty() && (localPlayer != nullptr))
- localPlayer->updateStatus();
- }
- }
- else if ((mSellShopItemList != nullptr)
- && mSellShopItemList->getSelected() >= 0)
- {
- mSellShopItems->del(mSellShopItemList->getSelected());
- if (isShopEmpty() && (localPlayer != nullptr))
- localPlayer->updateStatus();
- }
- }
- else if (eventId == "tab_buy")
- {
- isBuySelected = true;
- updateSelection();
- }
- else if (eventId == "tab_sell")
- {
- isBuySelected = false;
- updateSelection();
- }
- else if (eventId == "publish")
- {
- if (isBuySelected)
- {
- if (mEnableBuyingStore)
- {
- buyingStoreHandler->close();
- BuyingStoreModeListener::distributeEvent(false);
- }
- else
- {
- STD_VECTOR<ShopItem*> &items = mBuyShopItems->items();
- if (!items.empty())
- {
- buyingStoreHandler->create(mSellShopName,
- PlayerInfo::getAttribute(Attributes::MONEY),
- true,
- items);
- }
- }
- }
- else
- {
- if (mEnableVending)
- {
- vendingHandler->close();
- VendingModeListener::distributeEvent(false);
- }
- else
- {
- STD_VECTOR<ShopItem*> &oldItems = mSellShopItems->items();
- STD_VECTOR<ShopItem*> items;
- const Inventory *const inv = PlayerInfo::getCartInventory();
- if (inv == nullptr)
- return;
- FOR_EACH (STD_VECTOR<ShopItem*>::iterator, it, oldItems)
- {
- ShopItem *const item = *it;
- if (item == nullptr)
- continue;
- const Item *const cartItem = inv->findItem(item->getId(),
- item->getColor());
- if (cartItem == nullptr)
- continue;
- item->setInvIndex(cartItem->getInvIndex());
- const int amount = cartItem->getQuantity();
- if (amount == 0)
- continue;
- if (item->getQuantity() > amount)
- item->setQuantity(amount);
- items.push_back(item);
- if (static_cast<signed int>(items.size()) >= mSellShopSize)
- break;
- }
- if (!items.empty())
- vendingHandler->createShop(mSellShopName, true, items);
- }
- }
- }
- else if (eventId == "rename")
- {
- EditDialog *const dialog = CREATEWIDGETR(EditDialog,
- // TRANSLATORS: shop rename dialog title
- _("Please enter new shop name"),
- mSellShopName,
- "OK");
- shopRenameListener.setDialog(dialog);
- dialog->addActionListener(&shopRenameListener);
- }
-
- if (mSelectedItem < 1)
- return;
-
- const Inventory *const inv = mHaveVending && !isBuySelected
- ? PlayerInfo::getCartInventory() : PlayerInfo::getInventory();
- if (inv == nullptr)
- return;
-
- // +++ need support for colors
- Item *const item = inv->findItem(mSelectedItem, ItemColor_zero);
- if (item != nullptr)
- {
- if (eventId == "add")
- {
- if (isBuySelected)
- {
- ItemAmountWindow::showWindow(ItemAmountWindowUsage::ShopBuyAdd,
- this,
- item,
- sumAmount(item));
- }
- else
- {
- ItemAmountWindow::showWindow(
- ItemAmountWindowUsage::ShopSellAdd,
- this,
- item,
- sumAmount(item));
- }
- }
- }
-}
-
-void ShopWindow::valueChanged(const SelectionEvent &event A_UNUSED)
-{
- updateButtonsAndLabels();
-}
-
-void ShopWindow::updateButtonsAndLabels()
-{
- bool allowDel(false);
- bool allowAdd(false);
- const bool sellNotEmpty = mSellShopItems->getNumberOfElements() > 0;
- if (isBuySelected)
- {
- allowAdd = !mEnableBuyingStore;
- allowDel = !mEnableBuyingStore
- && mBuyShopItemList->getSelected() != -1
- && mBuyShopItems->getNumberOfElements() > 0;
- if (mPublishButton != nullptr)
- {
- if (mEnableBuyingStore)
- {
- // TRANSLATORS: unpublish shop button
- mPublishButton->setCaption(_("Unpublish"));
- }
- else
- {
- // TRANSLATORS: publish shop button
- mPublishButton->setCaption(_("Publish"));
- }
- mPublishButton->adjustSize();
- if (mBuyShopSize > 0)
- mPublishButton->setEnabled(true);
- else
- mPublishButton->setEnabled(false);
- }
- }
- else
- {
- allowAdd = !mEnableVending && mSelectedItem != -1;
- allowDel = !mEnableVending
- && mSellShopItemList->getSelected() != -1
- && sellNotEmpty;
- if (mPublishButton != nullptr)
- {
- if (mEnableVending)
- {
- // TRANSLATORS: unpublish shop button
- mPublishButton->setCaption(_("Unpublish"));
- }
- else
- {
- // TRANSLATORS: publish shop button
- mPublishButton->setCaption(_("Publish"));
- }
- mPublishButton->adjustSize();
- if (sellNotEmpty
- && mSellShopSize > 0
- && (localPlayer != nullptr)
- && localPlayer->getHaveCart())
- {
- mPublishButton->setEnabled(true);
- }
- else
- {
- mPublishButton->setEnabled(false);
- }
- }
- }
- mAddButton->setEnabled(allowAdd);
- mDeleteButton->setEnabled(allowDel);
- if (mRenameButton != nullptr)
- mRenameButton->setEnabled(!mEnableVending);
-}
-
-void ShopWindow::setVisible(Visible visible)
-{
- Window::setVisible(visible);
-}
-
-void ShopWindow::addBuyItem(const Item *const item, const int amount,
- const int price)
-{
- if (item == nullptr)
- return;
- const bool emp = isShopEmpty();
- mBuyShopItems->addItemNoDup(item->getId(),
- item->getType(),
- item->getColor(),
- amount,
- price);
- if (emp && (localPlayer != nullptr))
- localPlayer->updateStatus();
-
- updateButtonsAndLabels();
-}
-
-void ShopWindow::addSellItem(const Item *const item, const int amount,
- const int price)
-{
- if (item == nullptr)
- return;
- const bool emp = isShopEmpty();
- mSellShopItems->addItemNoDup(item->getId(),
- item->getType(),
- item->getColor(),
- amount,
- price);
- if (emp && (localPlayer != nullptr))
- localPlayer->updateStatus();
-
- updateButtonsAndLabels();
-}
-
-void ShopWindow::loadList()
-{
- std::ifstream shopFile;
- struct stat statbuf;
-
- mBuyShopItems->clear();
- mSellShopItems->clear();
-
- const std::string shopListName = settings.serverConfigDir
- + "/shoplist.txt";
-
- if (stat(shopListName.c_str(), &statbuf) == 0 &&
- S_ISREG(statbuf.st_mode))
- {
- shopFile.open(shopListName.c_str(), std::ios::in);
- if (!shopFile.is_open())
- {
- reportAlways("Error opening file for reading: %s",
- shopListName.c_str());
- shopFile.close();
- return;
- }
- char line[101];
- while (shopFile.getline(line, 100))
- {
- std::string buf;
- const std::string str = line;
- if (!str.empty())
- {
- STD_VECTOR<int> tokens;
- std::stringstream ss(str);
-
- while (ss >> buf)
- tokens.push_back(atoi(buf.c_str()));
-
- if (tokens.size() == 5 && (tokens[0] != 0))
- {
- // +++ need impliment colors?
- if ((tokens[1] != 0) && (tokens[2] != 0))
- {
- mBuyShopItems->addItem(
- tokens[0],
- ItemType::Unknown,
- ItemColor_one,
- tokens[1],
- tokens[2]);
- }
- if ((tokens[3] != 0) && (tokens[4] != 0))
- {
- mSellShopItems->addItem(
- tokens[0],
- ItemType::Unknown,
- ItemColor_one,
- tokens[3],
- tokens[4]);
- }
- }
- }
- }
- shopFile.close();
- }
-}
-
-void ShopWindow::saveList() const
-{
- std::ofstream shopFile;
- const std::string shopListName = settings.serverConfigDir
- + "/shoplist.txt";
- std::map<int, ShopItem*> mapItems;
-
- shopFile.open(shopListName.c_str(), std::ios::binary);
- if (!shopFile.is_open())
- {
- reportAlways("Error opening file writing: %s",
- shopListName.c_str());
- return;
- }
-
- STD_VECTOR<ShopItem*> items = mBuyShopItems->items();
- FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
- {
- ShopItem *const item = *(it);
- if (item != nullptr)
- mapItems[item->getId()] = item;
- }
-
- items = mSellShopItems->items();
- FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
- {
- if ((*it) == nullptr)
- continue;
- const ShopItem *const sellItem = *(it);
- const ShopItem *const buyItem = mapItems[sellItem->getId()];
-
- shopFile << sellItem->getId();
- if (buyItem != nullptr)
- {
- shopFile << strprintf(" %d %d ", buyItem->getQuantity(),
- buyItem->getPrice());
- mapItems.erase(sellItem->getId());
- }
- else
- {
- shopFile << " 0 0 ";
- }
-
- shopFile << strprintf("%d %d", sellItem->getQuantity(),
- sellItem->getPrice()) << std::endl;
- }
-
- for (std::map<int, ShopItem*>::const_iterator mapIt = mapItems.begin(),
- mapIt_fend = mapItems.end();
- mapIt != mapIt_fend;
- ++mapIt)
- {
- const ShopItem *const buyItem = (*mapIt).second;
- if (buyItem != nullptr)
- {
- shopFile << buyItem->getId();
- shopFile << strprintf(" %d %d ", buyItem->getQuantity(),
- buyItem->getPrice());
- shopFile << "0 0" << std::endl;
- }
- }
-
- shopFile.close();
-}
-
-#ifdef TMWA_SUPPORT
-void ShopWindow::announce(ShopItems *const list, const int mode)
-{
- if (list == nullptr)
- return;
-
- std::string data;
- if (mode == BUY)
- data.append("Buy ");
- else
- data.append("Sell ");
-
- if (mAnnonceTime != 0 &&
- (mAnnonceTime + (2 * 60) > cur_time || mAnnonceTime > cur_time))
- {
- return;
- }
-
- mAnnonceTime = cur_time;
- if (mAnnounceButton != nullptr)
- mAnnounceButton->setEnabled(false);
-
- STD_VECTOR<ShopItem*> items = list->items();
-
- FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
- {
- const ShopItem *const item = *(it);
- if (item->getQuantity() > 1)
- {
- if (mAnnounceLinks->isSelected())
- {
- data.append(strprintf("[@@%d|%s@@] (%dGP) %d, ", item->getId(),
- item->getInfo().getName().c_str(),
- item->getPrice(), item->getQuantity()));
- }
- else
- {
- data.append(strprintf("%s (%dGP) %d, ",
- item->getInfo().getName().c_str(),
- item->getPrice(), item->getQuantity()));
- }
- }
- else
- {
- if (mAnnounceLinks->isSelected())
- {
- data.append(strprintf("[@@%d|%s@@] (%dGP), ", item->getId(),
- item->getInfo().getName().c_str(), item->getPrice()));
- }
- else
- {
- data.append(strprintf("%s (%dGP), ",
- item->getInfo().getName().c_str(), item->getPrice()));
- }
- }
- }
-
- chatHandler->channelMessage(TRADE_CHANNEL, data);
-}
-
-void ShopWindow::startTrade()
-{
- if (actorManager == nullptr ||
- tradeWindow == nullptr)
- {
- return;
- }
-
- const Being *const being = actorManager->findBeingByName(
- mTradeNick, ActorType::Player);
- tradeWindow->clear();
- if (mTradeMoney != 0)
- {
- tradeWindow->addAutoMoney(mTradeNick, mTradeMoney);
- }
- else
- {
- tradeWindow->addAutoItem(mTradeNick, mTradeItem,
- mTradeItem->getQuantity());
- }
- tradeHandler->request(being);
- tradePartnerName = mTradeNick;
- mTradeNick.clear();
-}
-
-void ShopWindow::giveList(const std::string &nick, const int mode)
-{
- if (!checkFloodCounter(mLastRequestTimeList))
- return;
-
- std::string data("\302\202");
-
- ShopItems *list;
- if (mode == BUY)
- {
- list = mBuyShopItems;
- data.append("S1");
- }
- else
- {
- list = mSellShopItems;
- data.append("B1");
- }
- if (list == nullptr)
- return;
-
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- return;
-
- STD_VECTOR<ShopItem*> items = list->items();
-
- FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
- {
- const ShopItem *const item = *(it);
- if (item == nullptr)
- continue;
-
- if (mode == SELL)
- {
- const Item *const item2 = inv->findItem(item->getId(),
- ItemColor_zero);
- if (item2 != nullptr)
- {
- int amount = item->getQuantity();
- if (item2->getQuantity() < amount)
- amount = item2->getQuantity();
-
- if (amount != 0)
- {
- data.append(strprintf("%s%s%s",
- encodeStr(item->getId(), 2).c_str(),
- encodeStr(item->getPrice(), 4).c_str(),
- encodeStr(amount, 3).c_str()));
- }
- }
- }
- else
- {
- int amount = item->getQuantity();
- if (item->getPrice() * amount > PlayerInfo::getAttribute(
- Attributes::MONEY))
- {
- amount = PlayerInfo::getAttribute(Attributes::MONEY)
- / item->getPrice();
- }
-
- if (amount > 0)
- {
- data.append(strprintf("%s%s%s",
- encodeStr(item->getId(), 2).c_str(),
- encodeStr(item->getPrice(), 4).c_str(),
- encodeStr(amount, 3).c_str()));
- }
- }
- }
- sendMessage(nick, data, true);
-}
-
-void ShopWindow::sendMessage(const std::string &nick,
- std::string data,
- const bool random)
-{
- if (chatWindow == nullptr)
- return;
-
- if (random)
- {
- mRandCounter ++;
- if (mRandCounter > 200)
- mRandCounter = 0;
- data.append(encodeStr(mRandCounter, 2));
- }
-
- if (config.getBoolValue("hideShopMessages"))
- chatHandler->privateMessage(nick, data);
- else
- chatWindow->addWhisper(nick, data, ChatMsgType::BY_PLAYER);
-}
-
-void ShopWindow::showList(const std::string &nick, std::string data)
-{
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- return;
-
- BuyDialog *buyDialog = nullptr;
- SellDialog *sellDialog = nullptr;
- if (data.find("B1") == 0)
- {
- data = data.substr(2);
- CREATEWIDGETV(buyDialog, BuyDialog, nick, DEFAULT_CURRENCY);
- }
- else if (data.find("S1") == 0)
- {
- data = data.substr(2);
- CREATEWIDGETV(sellDialog, ShopSellDialog, nick);
- }
- else
- {
- return;
- }
-
- if (buyDialog != nullptr)
- buyDialog->setMoney(PlayerInfo::getAttribute(Attributes::MONEY));
- if (sellDialog != nullptr)
- sellDialog->setMoney(PlayerInfo::getAttribute(Attributes::MONEY));
-
- for (unsigned f = 0; f < data.length(); f += 9)
- {
- if (f + 9 > data.length())
- break;
-
- const int id = decodeStr(data.substr(f, 2));
- const int price = decodeStr(data.substr(f + 2, 4));
- int amount = decodeStr(data.substr(f + 6, 3));
- if (buyDialog != nullptr && amount > 0)
- {
- buyDialog->addItem(id,
- ItemType::Unknown,
- ItemColor_one,
- amount,
- price);
- }
- if (sellDialog != nullptr)
- {
- const Item *const item = inv->findItem(id, ItemColor_zero);
- if (item != nullptr)
- {
- if (item->getQuantity() < amount)
- amount = item->getQuantity();
- }
- else
- {
- amount = 0;
- }
- ShopItem *const shopItem = sellDialog->addItem(id,
- ItemType::Unknown,
- ItemColor_one,
- amount,
- price);
-
- if (shopItem != nullptr && amount <= 0)
- shopItem->setDisabled(true);
- }
- }
- if (buyDialog != nullptr)
- buyDialog->sort();
-}
-
-void ShopWindow::processRequest(const std::string &nick,
- std::string data,
- const int mode)
-{
- if (localPlayer == nullptr ||
- !mTradeNick.empty() ||
- PlayerInfo::isTrading() == Trading_true ||
- actorManager == nullptr ||
- actorManager->findBeingByName(nick, ActorType::Player) == nullptr)
- {
- return;
- }
-
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- return;
-
- const size_t idx = data.find(' ');
- if (idx == std::string::npos)
- return;
-
- if (!checkFloodCounter(mLastRequestTimeItem))
- return;
-
- if (!mTradeNick.empty())
- {
- sendMessage(nick,
- // TRANSLATORS: error buy/sell shop request
- _("error: player busy") + std::string(" "),
- true);
- return;
- }
-
- data = data.substr(idx + 1);
-
- std::string part1;
- std::string part2;
- std::string part3;
- std::stringstream ss(data);
- int id;
- int price;
- int amount;
-
- if (!(ss >> part1))
- return;
-
- if (!(ss >> part2))
- return;
-
- if (!(ss >> part3))
- return;
-
- id = atoi(part1.c_str());
- price = atoi(part2.c_str());
- amount = atoi(part3.c_str());
-
- delete mTradeItem;
- // +++ need impliment colors?
- mTradeItem = new ShopItem(-1,
- id,
- ItemType::Unknown,
- ItemColor_one,
- amount,
- price,
- DEFAULT_CURRENCY);
-
- if (mode == BUY)
- {
- // +++ need support for colors
- const Item *const item2 = inv->findItem(mTradeItem->getId(),
- ItemColor_zero);
- if (item2 == nullptr ||
- item2->getQuantity() < amount ||
- !findShopItem(mTradeItem, SELL))
- {
- sendMessage(nick,
- // TRANSLATORS: error buy/sell shop request
- _("error: Can't sell this item") + std::string(" "),
- true);
- return;
- }
- mTradeMoney = 0;
- }
- else
- {
- if (!findShopItem(mTradeItem, BUY))
- {
- sendMessage(nick,
- // TRANSLATORS: error buy/sell shop request
- _("error: Can't buy this item") + std::string(" "),
- true);
- return;
- }
- mTradeMoney = mTradeItem->getPrice() * mTradeItem->getQuantity();
- }
-
- mTradeNick = nick;
-
- if (config.getBoolValue("autoShop"))
- {
- soundManager.playGuiSound(SOUND_TRADE);
- startTrade();
- }
- else
- {
- std::string msg;
- if (mode == BUY)
- {
- // TRANSLATORS: buy shop request (nick, item)
- msg = strprintf(_("%s wants to buy %s do you accept?"),
- nick.c_str(),
- mTradeItem->getInfo().getName().c_str());
- }
- else
- {
- // TRANSLATORS: sell shop request (nick, item)
- msg = strprintf(_("%s wants to sell %s do you accept?"),
- nick.c_str(),
- mTradeItem->getInfo().getName().c_str());
- }
-
- ConfirmDialog *const confirmDlg = CREATEWIDGETR(ConfirmDialog,
- // TRANSLATORS: shop window dialog
- _("Request for Trade"),
- msg,
- SOUND_REQUEST,
- true);
- confirmDlg->addActionListener(this);
- }
-}
-
-void ShopWindow::updateTimes()
-{
- BLOCK_START("ShopWindow::updateTimes")
- if (mAnnounceButton == nullptr)
- {
- BLOCK_END("ShopWindow::updateTimes")
- return;
- }
- if (mAnnonceTime + (2 * 60) < cur_time ||
- mAnnonceTime > cur_time)
- {
- mAnnounceButton->setEnabled(true);
- }
- BLOCK_END("ShopWindow::updateTimes")
-}
-
-bool ShopWindow::checkFloodCounter(time_t &counterTime)
-{
- if (counterTime == 0 || counterTime > cur_time)
- counterTime = cur_time;
- else if (counterTime + 10 > cur_time)
- return false;
- else
- counterTime = cur_time;
- return true;
-}
-
-bool ShopWindow::findShopItem(const ShopItem *const shopItem,
- const int mode) const
-{
- if (shopItem == nullptr)
- return false;
-
- STD_VECTOR<ShopItem*> items;
- if (mode == SELL)
- items = mSellShopItems->items();
- else
- items = mBuyShopItems->items();
-
- FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
- {
- const ShopItem *const item = *(it);
- if (item == nullptr)
- continue;
-
- if (item->getId() == shopItem->getId()
- && item->getPrice() == shopItem->getPrice()
- && item->getQuantity() >= shopItem->getQuantity())
- {
- return true;
- }
- }
- return false;
-}
-#endif // TMWA_SUPPORT
-
-int ShopWindow::sumAmount(const Item *const shopItem)
-{
- if ((localPlayer == nullptr) || (shopItem == nullptr))
- return 0;
-
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- return 0;
- int sum = 0;
-
- for (unsigned f = 0; f < inv->getSize(); f ++)
- {
- const Item *const item = inv->getItem(f);
- if ((item != nullptr) && item->getId() == shopItem->getId())
- sum += item->getQuantity();
- }
- return sum;
-}
-
-bool ShopWindow::isShopEmpty() const
-{
- if (mBuyShopItems->empty() && mSellShopItems->empty())
- return true;
- return false;
-}
-
-void ShopWindow::updateSelection()
-{
- if (isBuySelected)
- mCurrentShopItemList = mBuyShopItemList;
- else
- mCurrentShopItemList = mSellShopItemList;
- mScrollArea->setContent(mCurrentShopItemList);
- updateButtonsAndLabels();
-}
-
-void ShopWindow::updateShopName()
-{
- if (mSellShopName.empty())
- {
- // TRANSLATORS: shop window name
- setCaption(_("Personal Shop"));
- }
- else
- {
- // TRANSLATORS: shop window name
- setCaption(strprintf(_("Personal Shop - %s"), mSellShopName.c_str()));
- }
-}
-
-void ShopWindow::setShopName(const std::string &name)
-{
- mSellShopName = name;
- serverConfig.setValue("sellShopName", mSellShopName);
- updateShopName();
-}
-
-void ShopWindow::vendingSlotsChanged(const int slots)
-{
- mSellShopSize = slots;
- updateButtonsAndLabels();
-}
-
-void ShopWindow::vendingEnabled(const bool b)
-{
- mEnableVending = b;
- localPlayer->enableShop(b);
- if (!b)
- mSellShopSize = 0;
- updateButtonsAndLabels();
-}
-
-void ShopWindow::buyingStoreSlotsChanged(const int slots)
-{
- mBuyShopSize = slots;
- updateButtonsAndLabels();
-}
-
-void ShopWindow::buyingStoreEnabled(const bool b)
-{
- mEnableBuyingStore = b;
- localPlayer->enableShop(b);
- if (!b)
- mBuyShopSize = 0;
- updateButtonsAndLabels();
-}
diff --git a/src/gui/windows/shopwindow.h b/src/gui/windows/shopwindow.h
deleted file mode 100644
index e96ab3de8..000000000
--- a/src/gui/windows/shopwindow.h
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_SHOPWINDOW_H
-#define GUI_WINDOWS_SHOPWINDOW_H
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/buyingstoremodelistener.h"
-#include "listeners/buyingstoreslotslistener.h"
-#include "listeners/selectionlistener.h"
-#include "listeners/vendingmodelistener.h"
-#include "listeners/vendingslotslistener.h"
-
-class Button;
-class CheckBox;
-class Item;
-class ScrollArea;
-class ShopItem;
-class ShopItems;
-class ShopListBox;
-class TabStrip;
-
-/**
- * The buy dialog.
- *
- * \ingroup Interface
- */
-class ShopWindow final : public Window,
- public VendingModeListener,
- public VendingSlotsListener,
- public BuyingStoreModeListener,
- public BuyingStoreSlotsListener,
- public ActionListener,
- public SelectionListener
-{
- public:
- enum ShopMode
- {
- BUY = 0,
- SELL = 1
- };
-
- /**
- * Constructor.
- *
- * @see Window::Window
- */
- ShopWindow();
-
- A_DELETE_COPY(ShopWindow)
-
- /**
- * Destructor
- */
- ~ShopWindow();
-
- void postInit() override final;
-
- /**
- * Called when receiving actions from the widgets.
- */
- void action(const ActionEvent &event) override final;
-
- /**
- * Updates the labels according to the selected item.
- */
- void valueChanged(const SelectionEvent &event) override final;
-
- /**
- * Updates the state of buttons and labels.
- */
- void updateButtonsAndLabels();
-
- /**
- * Sets the visibility of this window.
- */
- void setVisible(Visible visible) override final;
-
- /**
- * Returns true if any instances exist.
- */
- static bool isActive() A_WARN_UNUSED
- { return !instances.empty(); }
-
- void setItemSelected(const int id)
- { mSelectedItem = id; updateButtonsAndLabels(); }
-
- void addBuyItem(const Item *const item, const int amount,
- const int price);
-
- void addSellItem(const Item *const item, const int amount,
- const int price);
-
- void loadList();
-
- void saveList() const;
-
-#ifdef TMWA_SUPPORT
- void setAcceptPlayer(const std::string &name)
- { mAcceptPlayer = name; }
-
- const std::string &getAcceptPlayer() const noexcept2 A_WARN_UNUSED
- { return mAcceptPlayer; }
-
- void announce(ShopItems *const list, const int mode);
-
- void giveList(const std::string &nick, const int mode);
-
- void sendMessage(const std::string &nick, std::string data,
- const bool random = false);
-
- static void showList(const std::string &nick, std::string data);
-
- void processRequest(const std::string &nick, std::string data,
- const int mode);
- void updateTimes();
-
- static bool checkFloodCounter(time_t &counterTime) A_WARN_UNUSED;
-
- bool findShopItem(const ShopItem *const shopItem,
- const int mode) const A_WARN_UNUSED;
-#endif // TMWA_SUPPORT
-
- static int sumAmount(const Item *const shopItem) A_WARN_UNUSED;
-
- bool isShopEmpty() const A_WARN_UNUSED;
-
- void vendingEnabled(const bool b) override final;
-
- void vendingSlotsChanged(const int slots) override final;
-
- void buyingStoreEnabled(const bool b) override final;
-
- void buyingStoreSlotsChanged(const int slots) override final;
-
- void setShopName(const std::string &name);
-
- private:
-#ifdef TMWA_SUPPORT
- void startTrade();
-#endif // TMWA_SUPPORT
-
- void updateSelection();
-
- void updateShopName();
-
- typedef std::list<ShopWindow*> DialogList;
- static DialogList instances;
-
- Button *mCloseButton A_NONNULLPOINTER;
-
- ShopItems *mBuyShopItems A_NONNULLPOINTER;
- ShopItems *mSellShopItems A_NONNULLPOINTER;
- ShopItem *mTradeItem;
-
- ShopListBox *mBuyShopItemList A_NONNULLPOINTER;
- ShopListBox *mSellShopItemList A_NONNULLPOINTER;
- ShopListBox *mCurrentShopItemList;
- ScrollArea *mScrollArea A_NONNULLPOINTER;
- Button *mAddButton A_NONNULLPOINTER;
- Button *mDeleteButton A_NONNULLPOINTER;
- Button *mAnnounceButton;
- Button *mPublishButton;
- Button *mRenameButton;
- CheckBox *mAnnounceLinks;
- TabStrip *mTabs;
- std::string mAcceptPlayer;
- std::string mTradeNick;
- std::string mSellShopName;
- int mSelectedItem;
- time_t mAnnonceTime;
- time_t mLastRequestTimeList;
- time_t mLastRequestTimeItem;
- int mRandCounter;
- int mTradeMoney;
- int mSellShopSize;
- int mBuyShopSize;
- bool isBuySelected;
- bool mHaveVending;
- bool mEnableBuyingStore;
- bool mEnableVending;
-};
-
-extern ShopWindow *shopWindow;
-
-#endif // GUI_WINDOWS_SHOPWINDOW_H
diff --git a/src/gui/windows/shortcutwindow.cpp b/src/gui/windows/shortcutwindow.cpp
deleted file mode 100644
index 1bb35d3f1..000000000
--- a/src/gui/windows/shortcutwindow.cpp
+++ /dev/null
@@ -1,269 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/shortcutwindow.h"
-
-#include "enums/gui/layouttype.h"
-
-#include "gui/windows/setupwindow.h"
-#include "gui/widgets/tabbedarea.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/layout.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/shortcutcontainer.h"
-
-#include "gui/widgets/tabs/shortcuttab.h"
-
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-
-#include "debug.h"
-
-ShortcutWindow *dropShortcutWindow = nullptr;
-ShortcutWindow *emoteShortcutWindow = nullptr;
-ShortcutWindow *itemShortcutWindow = nullptr;
-ShortcutWindow *spellShortcutWindow = nullptr;
-static const int SCROLL_PADDING = 0;
-
-int ShortcutWindow::mBoxesWidth = 0;
-
-ShortcutWindow::ShortcutWindow(const std::string &restrict title,
- ShortcutContainer *restrict const content,
- const std::string &restrict skinFile,
- int width, int height) :
- Window("Window", Modal_false, nullptr, skinFile),
- mItems(content),
- mScrollArea(new ScrollArea(this, mItems, Opaque_false)),
- mTabs(nullptr),
- mPages(),
- mButtonIndex(0)
-{
- setWindowName(title);
- setTitleBarHeight(getPadding() + getTitlePadding());
-
- setShowTitle(false);
- setResizable(true);
- setDefaultVisible(false);
- setSaveVisible(true);
- setAllowClose(true);
-
- mDragOffsetX = 0;
- mDragOffsetY = 0;
-
- if (content != nullptr)
- content->setWidget2(this);
- if (setupWindow != nullptr)
- setupWindow->registerWindowForReset(this);
-
- setMinWidth(32);
- setMinHeight(32);
- const int border = SCROLL_PADDING * 2 + getPadding() * 2;
- if (mItems != nullptr)
- {
- const int bw = mItems->getBoxWidth();
- const int bh = mItems->getBoxHeight();
- const int maxItems = mItems->getMaxItems();
- setMaxWidth(bw * maxItems + border);
- setMaxHeight(bh * maxItems + border);
-
- if (width == 0)
- width = bw + border;
- if (height == 0)
- height = bh * maxItems + border;
-
- setDefaultSize(width, height, ImagePosition::LOWER_RIGHT);
-
- mBoxesWidth += bw + border;
- }
-
- mScrollArea->setPosition(SCROLL_PADDING, SCROLL_PADDING);
- mScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
-
- place(0, 0, mScrollArea, 5, 5).setPadding(0);
-
- Layout &layout = getLayout();
- layout.setRowHeight(0, LayoutType::SET);
- layout.setMargin(0);
-
- loadWindowState();
- enableVisibleSound(true);
-}
-
-ShortcutWindow::ShortcutWindow(const std::string &restrict title,
- const std::string &restrict skinFile,
- const int width, const int height) :
- Window("Window", Modal_false, nullptr, skinFile),
- mItems(nullptr),
- mScrollArea(nullptr),
- mTabs(CREATEWIDGETR(TabbedArea, this)),
- mPages(),
- mButtonIndex(0)
-{
- setWindowName(title);
- setTitleBarHeight(getPadding() + getTitlePadding());
- setShowTitle(false);
- setResizable(true);
- setDefaultVisible(false);
- setSaveVisible(true);
- setAllowClose(true);
-
- mDragOffsetX = 0;
- mDragOffsetY = 0;
-
- if (setupWindow != nullptr)
- setupWindow->registerWindowForReset(this);
-
- if ((width != 0) && (height != 0))
- setDefaultSize(width, height, ImagePosition::LOWER_RIGHT);
-
- setMinWidth(32);
- setMinHeight(32);
-
- place(0, 0, mTabs, 5, 5);
-
- Layout &layout = getLayout();
- layout.setRowHeight(0, LayoutType::SET);
- layout.setMargin(0);
-
- loadWindowState();
- enableVisibleSound(true);
-}
-
-ShortcutWindow::~ShortcutWindow()
-{
- if (mTabs != nullptr)
- mTabs->removeAll();
- delete2(mTabs);
- delete2(mItems);
-}
-
-void ShortcutWindow::addButton(const std::string &text,
- const std::string &eventName,
- ActionListener *const listener)
-{
- place(mButtonIndex++, 5, new Button(this, text, eventName, listener));
- Window::widgetResized(Event(nullptr));
-}
-
-void ShortcutWindow::addTab(const std::string &name,
- ShortcutContainer *const content)
-{
- if ((content == nullptr) || (mTabs == nullptr))
- return;
- ScrollArea *const scroll = new ScrollArea(this, content, Opaque_false);
- scroll->setPosition(SCROLL_PADDING, SCROLL_PADDING);
- scroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- content->setWidget2(this);
- Tab *const tab = new ShortcutTab(this, name, content);
- mTabs->addTab(tab, scroll);
- mPages.push_back(content);
-}
-
-int ShortcutWindow::getTabIndex() const
-{
- if (mTabs == nullptr)
- return 0;
- return mTabs->getSelectedTabIndex();
-}
-
-void ShortcutWindow::widgetHidden(const Event &event)
-{
- Window::widgetHidden(event);
- if (mItems != nullptr)
- mItems->widgetHidden(event);
- if (mTabs != nullptr)
- {
- ScrollArea *const scroll = static_cast<ScrollArea *>(
- mTabs->getCurrentWidget());
- if (scroll != nullptr)
- {
- ShortcutContainer *const content = static_cast<ShortcutContainer*>(
- scroll->getContent());
-
- if (content != nullptr)
- content->widgetHidden(event);
- }
- }
-}
-
-void ShortcutWindow::mousePressed(MouseEvent &event)
-{
- Window::mousePressed(event);
-
- if (event.isConsumed())
- return;
-
- if (event.getButton() == MouseButton::LEFT)
- {
- mDragOffsetX = event.getX();
- mDragOffsetY = event.getY();
- }
-}
-
-void ShortcutWindow::mouseDragged(MouseEvent &event)
-{
- Window::mouseDragged(event);
-
- if (event.isConsumed())
- return;
-
- if (canMove() && isMovable() && mMoved)
- {
- int newX = std::max(0, getX() + event.getX() - mDragOffsetX);
- int newY = std::max(0, getY() + event.getY() - mDragOffsetY);
- newX = std::min(mainGraphics->mWidth - getWidth(), newX);
- newY = std::min(mainGraphics->mHeight - getHeight(), newY);
- setPosition(newX, newY);
- }
-}
-
-void ShortcutWindow::widgetMoved(const Event& event)
-{
- Window::widgetMoved(event);
- if (mItems != nullptr)
- mItems->setRedraw(true);
- FOR_EACH (STD_VECTOR<ShortcutContainer*>::iterator, it, mPages)
- (*it)->setRedraw(true);
-}
-
-void ShortcutWindow::nextTab()
-{
- if (mTabs != nullptr)
- mTabs->selectNextTab();
-}
-
-void ShortcutWindow::prevTab()
-{
- if (mTabs != nullptr)
- mTabs->selectPrevTab();
-}
-
-#ifdef USE_PROFILER
-void ShortcutWindow::logicChildren()
-{
- BLOCK_START("ShortcutWindow::logicChildren")
- BasicContainer::logicChildren();
- BLOCK_END("ShortcutWindow::logicChildren")
-}
-#endif // USE_PROFILER
diff --git a/src/gui/windows/shortcutwindow.h b/src/gui/windows/shortcutwindow.h
deleted file mode 100644
index f21c505c5..000000000
--- a/src/gui/windows/shortcutwindow.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_SHORTCUTWINDOW_H
-#define GUI_WINDOWS_SHORTCUTWINDOW_H
-
-#include "gui/widgets/window.h"
-
-class ScrollArea;
-class ShortcutContainer;
-class TabbedArea;
-
-/**
- * A window around a ShortcutContainer.
- *
- * \ingroup Interface
- */
-class ShortcutWindow final : public Window
-{
- public:
- /**
- * Constructor.
- */
- ShortcutWindow(const std::string &restrict title,
- ShortcutContainer *restrict const content,
- const std::string &restrict skinFile = "",
- int width = 0, int height = 0);
-
- explicit ShortcutWindow(const std::string &restrict title,
- const std::string &restrict skinFile = "",
- const int width = 0, const int height = 0);
-
- A_DELETE_COPY(ShortcutWindow)
-
- /**
- * Destructor.
- */
- ~ShortcutWindow();
-
- void addTab(const std::string &name, ShortcutContainer *const content);
-
- int getTabIndex() const A_WARN_UNUSED;
-
- void widgetHidden(const Event &event) override final;
-
- void widgetMoved(const Event& event) override final;
-
- void mousePressed(MouseEvent &event) override final;
-
- void mouseDragged(MouseEvent &event) override final;
-
- void nextTab();
-
- void prevTab();
-
- void addButton(const std::string &text,
- const std::string &eventName,
- ActionListener *const listener);
-
-#ifdef USE_PROFILER
- void logicChildren();
-#endif // USE_PROFILER
-
- private:
- ShortcutWindow();
- ShortcutContainer *mItems;
-
- ScrollArea *mScrollArea A_NONNULLPOINTER;
- TabbedArea *mTabs;
- STD_VECTOR<ShortcutContainer*> mPages;
- int mButtonIndex;
-
- static int mBoxesWidth;
-};
-
-extern ShortcutWindow *dropShortcutWindow;
-extern ShortcutWindow *emoteShortcutWindow;
-extern ShortcutWindow *itemShortcutWindow;
-extern ShortcutWindow *spellShortcutWindow;
-
-#endif // GUI_WINDOWS_SHORTCUTWINDOW_H
diff --git a/src/gui/windows/skilldialog.cpp b/src/gui/windows/skilldialog.cpp
deleted file mode 100644
index 9f11605ef..000000000
--- a/src/gui/windows/skilldialog.cpp
+++ /dev/null
@@ -1,1432 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/skilldialog.h"
-
-#include "configuration.h"
-#include "effectmanager.h"
-#include "spellmanager.h"
-
-#include "being/localplayer.h"
-#include "being/playerinfo.h"
-
-#include "const/resources/spriteaction.h"
-
-#include "enums/resources/skill/skillsettype.h"
-
-#include "gui/shortcut/itemshortcut.h"
-
-#include "gui/windows/setupwindow.h"
-#include "gui/windows/shortcutwindow.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/tabbedarea.h"
-
-#include "gui/widgets/tabs/skilltab.h"
-
-#include "gui/windows/textdialog.h"
-
-#include "listeners/textskilllistener.h"
-
-#include "net/playerhandler.h"
-#include "net/skillhandler.h"
-
-#include "utils/checkutils.h"
-#include "utils/dtor.h"
-#include "utils/gettext.h"
-#include "utils/timer.h"
-
-#include "resources/beingcommon.h"
-
-#include "debug.h"
-
-SkillDialog *skillDialog = nullptr;
-
-namespace
-{
- TextSkillListener textSkillListener;
-} // namespace
-
-static SkillOwner::Type parseOwner(const std::string &str)
-{
- if (str == "player")
- return SkillOwner::Player;
- else if (str == "mercenary")
- return SkillOwner::Mercenary;
- else if (str == "homunculus")
- return SkillOwner::Homunculus;
- return SkillOwner::Player;
-}
-
-SkillDialog::SkillDialog() :
- // TRANSLATORS: skills dialog name
- Window(_("Skills"), Modal_false, nullptr, "skills.xml"),
- ActionListener(),
- mSkills(),
- mDurations(),
- mTabs(CREATEWIDGETR(TabbedArea, this)),
- mDeleteTabs(),
- mPointsLabel(new Label(this, "0")),
- // TRANSLATORS: skills dialog button
- mUseButton(new Button(this, _("Use"), "use", this)),
- // TRANSLATORS: skills dialog button
- mIncreaseButton(new Button(this, _("Up"), "inc", this)),
- mDefaultModel(nullptr),
- mDefaultTab(nullptr)
-{
- setWindowName("Skills");
- setCloseButton(true);
- setResizable(true);
- setSaveVisible(true);
- setStickyButtonLock(true);
- setDefaultSize(windowContainer->getWidth() - 280, 30, 275, 425);
- if (setupWindow != nullptr)
- setupWindow->registerWindowForReset(this);
-
- mUseButton->setEnabled(false);
- mIncreaseButton->setEnabled(false);
- mTabs->setSelectable(false);
- mTabs->getTabContainer()->setSelectable(false);
- mTabs->getWidgetContainer()->setSelectable(false);
-
- place(0, 0, mTabs, 5, 5);
- place(0, 5, mPointsLabel, 4);
- place(3, 5, mUseButton);
- place(4, 5, mIncreaseButton);
-}
-
-void SkillDialog::postInit()
-{
- Window::postInit();
- setLocationRelativeTo(getParent());
- loadWindowState();
- enableVisibleSound(true);
-}
-
-SkillDialog::~SkillDialog()
-{
- clearSkills();
-}
-
-void SkillDialog::addDefaultTab()
-{
- mDefaultModel = new SkillModel;
- SkillListBox *const listbox = new SkillListBox(this,
- mDefaultModel);
- listbox->setActionEventId("sel");
- listbox->addActionListener(this);
- ScrollArea *const scroll = new ScrollArea(this,
- listbox,
- Opaque_false);
- scroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- scroll->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS);
- // TRANSLATORS: unknown skills tab name
- mDefaultTab = new SkillTab(this, _("Unknown"), listbox);
- mDeleteTabs.push_back(mDefaultTab);
- mDefaultTab->setVisible(Visible_false);
- mTabs->addTab(mDefaultTab, scroll);
- mTabs->adjustTabPositions();
- mTabs->setSelectedTabDefault();
-}
-
-void SkillDialog::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "inc")
- {
- if (playerHandler == nullptr)
- return;
- const SkillTab *const tab = static_cast<const SkillTab *>(
- mTabs->getSelectedTab());
- if (tab != nullptr)
- {
- if (const SkillInfo *const info = tab->getSelectedInfo())
- playerHandler->increaseSkill(CAST_U16(info->id));
- }
- }
- else if (eventId == "sel")
- {
- const SkillTab *const tab = static_cast<const SkillTab *>(
- mTabs->getSelectedTab());
- if (tab != nullptr)
- {
- if (const SkillInfo *const info = tab->getSelectedInfo())
- {
- mUseButton->setEnabled(info->isUsable());
- mUseButton->setCaption(info->useButton);
- mIncreaseButton->setEnabled(info->id < SKILL_VAR_MIN_ID);
- const int num = itemShortcutWindow->getTabIndex();
- if (num >= 0 && num < CAST_S32(SHORTCUT_TABS)
- && (itemShortcut[num] != nullptr))
- {
- itemShortcut[num]->setItemSelected(
- info->id + SKILL_MIN_ID);
- }
- }
- else
- {
- mUseButton->setEnabled(false);
- mIncreaseButton->setEnabled(false);
- // TRANSLATORS: skills dialog button
- mUseButton->setCaption(_("Use"));
- }
- }
- }
- else if (eventId == "use")
- {
- const SkillTab *const tab = static_cast<const SkillTab *>(
- mTabs->getSelectedTab());
- if (tab != nullptr)
- {
- const SkillInfo *const info = tab->getSelectedInfo();
- if (info == nullptr)
- return;
- useSkill(info,
- fromBool(config.getBoolValue("skillAutotarget"), AutoTarget),
- info->customSelectedLevel,
- info->useTextParameter,
- std::string(),
- info->customCastType,
- info->customOffsetX,
- info->customOffsetY);
- }
- }
- else if (eventId == "close")
- {
- setVisible(Visible_false);
- }
-}
-
-std::string SkillDialog::update(const int id)
-{
- const SkillMap::const_iterator i = mSkills.find(id);
-
- if (i != mSkills.end())
- {
- SkillInfo *const info = i->second;
- if (info != nullptr)
- {
- info->update();
- return info->data->name;
- }
- }
-
- return std::string();
-}
-
-void SkillDialog::update()
-{
- // TRANSLATORS: skills dialog label
- mPointsLabel->setCaption(strprintf(_("Skill points available: %d"),
- PlayerInfo::getAttribute(Attributes::PLAYER_SKILL_POINTS)));
- mPointsLabel->adjustSize();
-
- ItemShortcut *const shortcuts = itemShortcut[SHORTCUT_AUTO_TAB];
- shortcuts->clear();
- size_t idx = 0;
-
- FOR_EACH (SkillMap::const_iterator, it, mSkills)
- {
- SkillInfo *const info = (*it).second;
- if (info == nullptr)
- continue;
- if (info->modifiable == Modifiable_true)
- info->update();
- if (info->visible == Visible_false ||
- idx >= SHORTCUT_ITEMS ||
- !info->data->autoTab)
- {
- continue;
- }
- const SkillType::SkillType type = info->type;
- if (type == SkillType::Attack ||
- type == SkillType::Ground ||
- type == SkillType::Self ||
- type == SkillType::Support)
- {
- shortcuts->setItemFast(idx,
- info->id + SKILL_MIN_ID,
- fromInt(info->customSelectedLevel, ItemColor));
-
- shortcuts->setItemData(idx,
- info->toDataStr());
- idx ++;
- }
- }
-
- skillPopup->reset();
-}
-
-void SkillDialog::updateModels()
-{
- std::set<SkillModel*> models;
-
- FOR_EACH (SkillMap::const_iterator, it, mSkills)
- {
- SkillInfo *const info = (*it).second;
- if (info != nullptr)
- {
- SkillModel *const model = info->model;
- if (model != nullptr)
- models.insert(model);
- }
- }
- FOR_EACH (std::set<SkillModel*>::iterator, it, models)
- {
- SkillModel *const model = *it;
- if (model != nullptr)
- model->updateVisibilities();
- }
-}
-
-void SkillDialog::clearSkills()
-{
- mTabs->removeAll();
- mDeleteTabs.clear();
- mDefaultTab = nullptr;
- mDefaultModel = nullptr;
-
- delete_all(mSkills);
- mSkills.clear();
- mDurations.clear();
-}
-
-void SkillDialog::hideSkills(const SkillOwner::Type owner)
-{
- FOR_EACH (SkillMap::iterator, it, mSkills)
- {
- SkillInfo *const info = (*it).second;
- if ((info != nullptr) && info->owner == owner)
- {
- PlayerInfo::setSkillLevel(info->id, 0);
- if (info->alwaysVisible == Visible_false)
- info->visible = Visible_false;
- }
- }
-}
-
-void SkillDialog::loadSkills()
-{
- clearSkills();
- loadXmlFile(paths.getStringValue("skillsFile"), SkipError_false);
- if (mSkills.empty())
- loadXmlFile(paths.getStringValue("skillsFile2"), SkipError_false);
- loadXmlFile(paths.getStringValue("skillsPatchFile"), SkipError_true);
- loadXmlDir("skillsPatchDir", loadXmlFile);
- addDefaultTab();
-
- update();
-}
-
-void SkillDialog::loadXmlFile(const std::string &fileName,
- const SkipError skipError)
-{
- XML::Document doc(fileName,
- UseVirtFs_true,
- skipError);
- XmlNodePtrConst root = doc.rootNode();
-
- int setCount = 0;
-
- if ((root == nullptr) || !xmlNameEqual(root, "skills"))
- {
- logger->log("Error loading skills: " + fileName);
- return;
- }
-
- for_each_xml_child_node(set, root)
- {
- if (xmlNameEqual(set, "include"))
- {
- const std::string name = XML::getProperty(set, "name", "");
- if (!name.empty())
- loadXmlFile(name, skipError);
- continue;
- }
- else if (xmlNameEqual(set, "set"))
- {
- setCount++;
- const std::string setName = XML::getProperty(set, "name",
- // TRANSLATORS: skills dialog default skill tab
- strprintf(_("Skill Set %d"), setCount));
-
- const std::string setTypeStr = XML::getProperty(set, "type", "");
- SkillSetTypeT setType = SkillSetType::VerticalList;
- if (setTypeStr.empty() ||
- setTypeStr == "list" ||
- setTypeStr == "vertical")
- {
- setType = SkillSetType::VerticalList;
- }
- else if (setTypeStr == "rectangle")
- {
- setType = SkillSetType::Rectangle;
- }
-
- bool alwaysVisible = false;
- SkillModel *const model = new SkillModel;
- SkillTab *tab = nullptr;
- ScrollArea *scroll = nullptr;
-
- switch (setType)
- {
- case SkillSetType::VerticalList:
- {
- // possible leak listbox, scroll
- SkillListBox *const listbox = new SkillListBox(this,
- model);
- listbox->setActionEventId("sel");
- listbox->addActionListener(this);
- scroll = new ScrollArea(this,
- listbox,
- Opaque_false);
- scroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- scroll->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS);
- tab = new SkillTab(this, setName, listbox);
- break;
- }
- case SkillSetType::Rectangle:
- {
- SkillRectangleListBox *const listbox =
- new SkillRectangleListBox(this,
- model);
- listbox->setActionEventId("sel");
- listbox->addActionListener(this);
- scroll = new ScrollArea(this,
- listbox,
- Opaque_false);
- scroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- scroll->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS);
- tab = new SkillTab(this, setName, listbox);
- break;
- }
- default:
- reportAlways("Unsupported skillset type: %s",
- setTypeStr.c_str());
- return;
- }
- if (mDefaultModel == nullptr)
- {
- mDefaultModel = model;
- mDefaultTab = tab;
- }
-
- mDeleteTabs.push_back(tab);
- if (alwaysVisible == true)
- tab->setVisible(Visible_true);
- else
- tab->setVisible(Visible_false);
- mTabs->addTab(tab, scroll);
-
- for_each_xml_child_node(node, set)
- {
- if (xmlNameEqual(node, "skill"))
- {
- SkillInfo *const skill = loadSkill(node, model);
- if (skill == nullptr)
- continue;
- if (skill->alwaysVisible == Visible_true)
- alwaysVisible = true;
- skill->tab = tab;
- for_each_xml_child_node(levelNode, node)
- {
- if (!xmlNameEqual(levelNode, "level"))
- continue;
- loadSkillData(node, skill);
- }
- }
- }
-
- model->updateVisibilities();
- }
- }
-}
-
-SkillInfo *SkillDialog::loadSkill(XmlNodeConstPtr node,
- SkillModel *const model)
-{
- int id = XML::getIntProperty(node, "id", -1, -1, 1000000);
- if (id == -1)
- {
- id = XML::getIntProperty(node, "var", -1, -1, 100000);
- if (id == -1)
- return nullptr;
- id += SKILL_VAR_MIN_ID;
- }
-
- SkillInfo *skill = getSkill(id);
- if (skill == nullptr)
- {
- std::string name = XML::langProperty(node, "name",
- // TRANSLATORS: skills dialog. skill id
- strprintf(_("Skill %d"), id));
-
- skill = new SkillInfo;
- skill->id = CAST_U32(id);
- skill->modifiable = Modifiable_false;
- skill->model = model;
- skill->update();
- skill->useButton = XML::getProperty(
- // TRANSLATORS: skills dialog button
- node, "useButton", _("Use"));
- skill->owner = parseOwner(XML::getProperty(
- node, "owner", "player"));
- skill->errorText = XML::getProperty(
- node, "errorText", name);
- skill->alwaysVisible = fromBool(XML::getBoolProperty(
- node, "alwaysVisible", false), Visible);
- skill->castingAction = XML::getProperty(node,
- "castingAction", SpriteAction::CAST);
- skill->castingRideAction = XML::getProperty(node,
- "castingRideAction", SpriteAction::CASTRIDE);
- skill->castingSkyAction = XML::getProperty(node,
- "castingSkyAction", SpriteAction::CASTSKY);
- skill->castingWaterAction = XML::getProperty(node,
- "castingWaterAction", SpriteAction::CASTWATER);
- skill->useTextParameter = XML::getBoolProperty(
- node, "useTextParameter", false);
- skill->x = XML::getProperty(node,
- "x", 0);
- skill->y = XML::getProperty(node,
- "y", 0);
- skill->visible = skill->alwaysVisible;
- model->addSkill(skill);
- mSkills[id] = skill;
- }
-
- loadSkillData(node, skill);
- return skill;
-}
-
-void SkillDialog::loadSkillData(XmlNodeConstPtr node,
- SkillInfo *const skill)
-{
- if (skill == nullptr)
- return;
- const int level = (skill->alwaysVisible == Visible_true) ?
- 0 : XML::getProperty(node, "level", 0);
- SkillData *data = skill->getData(level);
- if (data == nullptr)
- data = new SkillData;
-
- const std::string name = XML::langProperty(node, "name",
- // TRANSLATORS: skills dialog. skill id
- strprintf(_("Skill %u"), skill->id));
- data->name = name;
- const std::string icon = XML::getProperty(node, "icon", "");
- if (icon.empty())
- {
- data->setIcon(paths.getStringValue("missingSkillIcon"));
- data->haveIcon = false;
- }
- else
- {
- data->setIcon(icon);
- data->haveIcon = true;
- }
- if (skill->id < SKILL_VAR_MIN_ID)
- {
- data->dispName = strprintf("%s, %u",
- name.c_str(),
- skill->id);
- }
- else
- {
- data->dispName = strprintf("%s, (%u)",
- name.c_str(),
- skill->id - SKILL_VAR_MIN_ID);
- }
- data->shortName = XML::langProperty(node,
- "shortName", name.substr(0, 3));
- data->description = XML::langProperty(
- node, "description", "");
-
- MissileInfo &missile = data->missile;
- missile.particle = XML::getProperty(
- node, "missile-particle", "");
- missile.z = XML::getFloatProperty(
- node, "missile-z", 32.0f);
- missile.lifeTime = XML::getProperty(
- node, "missile-lifetime", 500);
- missile.speed = XML::getFloatProperty(
- node, "missile-speed", 7.0f);
- missile.dieDistance = XML::getFloatProperty(
- node, "missile-diedistance", 8.0f);
-
- MissileInfo &castingMissile = data->castingMissile;
- castingMissile.particle = XML::getProperty(
- node, "castingMissile-particle", "");
- castingMissile.z = XML::getFloatProperty(
- node, "castingMissile-z", 32.0f);
- castingMissile.lifeTime = XML::getProperty(
- node, "castingMissile-lifetime", 500);
- castingMissile.speed = XML::getFloatProperty(
- node, "castingMissile-speed", 7.0f);
- castingMissile.dieDistance = XML::getFloatProperty(
- node, "castingMissile-diedistance", 8.0f);
-
- data->castingAnimation = XML::getProperty(
- node,
- "castingAnimation",
- paths.getStringValue("skillCastingAnimation"));
-
- data->soundHit.sound = XML::getProperty(
- node, "soundHit", "");
- data->soundHit.delay = XML::getProperty(
- node, "soundHitDelay", 0);
- data->soundMiss.sound = XML::getProperty(
- node, "soundMiss", "");
- data->soundMiss.delay = XML::getProperty(
- node, "soundMissDelay", 0);
- data->invokeCmd = XML::getProperty(
- node, "invokeCmd", "");
- data->updateEffectId = XML::getProperty(
- node, "levelUpEffectId", -1);
- data->removeEffectId = XML::getProperty(
- node, "removeEffectId", -1);
- data->hitEffectId = XML::getProperty(
- node, "hitEffectId", -1);
- data->missEffectId = XML::getProperty(
- node, "missEffectId", -1);
- data->castingSrcEffectId = XML::getProperty(
- node, "castingSrcEffectId", -1);
- data->castingDstEffectId = XML::getProperty(
- node, "castingDstEffectId", -1);
- data->srcEffectId = XML::getProperty(
- node, "srcEffectId", -1);
- data->dstEffectId = XML::getProperty(
- node, "dstEffectId", -1);
- data->castingGroundEffectId = XML::getProperty(
- node, "castingGroundEffectId", -1);
- data->autoTab = XML::getBoolProperty(
- node, "autoTab", true);
-
- skill->addData(level, data);
-}
-
-void SkillDialog::removeSkill(const int id)
-{
- const SkillMap::const_iterator it = mSkills.find(id);
-
- if (it != mSkills.end())
- {
- SkillInfo *const info = it->second;
- if (info != nullptr)
- {
- info->level = 0;
- info->update();
- PlayerInfo::setSkillLevel(id, 0);
- if (info->alwaysVisible == Visible_false)
- info->visible = Visible_false;
- }
- }
-}
-
-bool SkillDialog::updateSkill(const int id,
- const int range,
- const Modifiable modifiable,
- const SkillType::SkillType type,
- const int sp)
-{
- const SkillMap::const_iterator it = mSkills.find(id);
-
- if (it != mSkills.end())
- {
- SkillInfo *const info = it->second;
- if (info != nullptr)
- {
- info->modifiable = modifiable;
- info->range = range;
- info->type = type;
- info->sp = sp;
- info->update();
- if (info->tab != nullptr)
- {
- info->tab->setVisible(Visible_true);
- mTabs->adjustTabPositions();
- mTabs->setSelectedTabDefault();
- }
- }
- return true;
- }
- return false;
-}
-
-std::string SkillDialog::getDefaultSkillIcon(const SkillType::SkillType type)
-{
- std::string icon;
- switch (type)
- {
- case SkillType::Attack:
- icon = paths.getStringValue("attackSkillIcon");
- break;
- case SkillType::Ground:
- icon = paths.getStringValue("groundSkillIcon");
- break;
- case SkillType::Self:
- icon = paths.getStringValue("selfSkillIcon");
- break;
- case SkillType::Unused:
- icon = paths.getStringValue("unusedSkillIcon");
- break;
- case SkillType::Support:
- icon = paths.getStringValue("supportSkillIcon");
- break;
- case SkillType::TargetTrap:
- icon = paths.getStringValue("trapSkillIcon");
- break;
- case SkillType::Unknown:
- icon = paths.getStringValue("unknownSkillIcon");
- break;
- default:
- break;
- }
- return icon;
-}
-
-void SkillDialog::addSkill(const SkillOwner::Type owner,
- const int id,
- const std::string &name,
- const int level,
- const int range,
- const Modifiable modifiable,
- const SkillType::SkillType type,
- const int sp)
-{
- if (mDefaultModel != nullptr)
- {
- SkillInfo *const skill = new SkillInfo;
- skill->id = CAST_U32(id);
- skill->type = type;
- skill->owner = owner;
- SkillData *const data = skill->data;
- if (name.empty())
- {
- data->name = "Unknown skill Id: " + toString(id);
- data->dispName = data->name;
- }
- else
- {
- data->name = name;
- data->dispName = strprintf("%s, %u", name.c_str(), skill->id);
- }
- data->description.clear();
- const std::string icon = getDefaultSkillIcon(type);
- if (icon.empty())
- {
- data->setIcon(paths.getStringValue("missingSkillIcon"));
- data->haveIcon = false;
- }
- else
- {
- data->setIcon(icon);
- data->haveIcon = true;
- }
- data->autoTab = settings.unknownSkillsAutoTab;
- data->shortName = toString(skill->id);
- skill->modifiable = modifiable;
- skill->visible = Visible_false;
- skill->alwaysVisible = Visible_false;
- skill->model = mDefaultModel;
- skill->level = level;
- // TRANSLATORS: skills dialog. skill level
- skill->skillLevel = strprintf(_("Lvl: %d"), level);
- skill->range = range;
- skill->sp = sp;
- skill->update();
- // TRANSLATORS: skills dialog button
- skill->useButton = _("Use");
- // TRANSLATORS: skill error message
- skill->errorText = strprintf(_("Failed skill: %s"), name.c_str());
- skill->tab = mDefaultTab;
- mDefaultModel->addSkill(skill);
- mDefaultTab->setVisible(Visible_true);
- mTabs->adjustTabPositions();
- mTabs->setSelectedTabDefault();
-
- mSkills[id] = skill;
- mDefaultModel->updateVisibilities();
- }
-}
-
-SkillInfo* SkillDialog::getSkill(const int id) const
-{
- SkillMap::const_iterator it = mSkills.find(id);
- if (it != mSkills.end())
- return (*it).second;
- return nullptr;
-}
-
-SkillInfo* SkillDialog::getSkillByItem(const int itemId) const
-{
- SkillMap::const_iterator it = mSkills.find(itemId - SKILL_MIN_ID);
- if (it != mSkills.end())
- return (*it).second;
- return nullptr;
-}
-
-void SkillDialog::setSkillDuration(const SkillOwner::Type owner,
- const int id,
- const int duration)
-{
- SkillMap::const_iterator it = mSkills.find(id);
- SkillInfo *info = nullptr;
- if (it == mSkills.end())
- {
- addSkill(owner, id, "", 0, 0, Modifiable_false, SkillType::Unknown, 0);
- it = mSkills.find(id);
- }
- if (it != mSkills.end())
- {
- info = (*it).second;
- }
- if (info != nullptr)
- {
- info->duration = duration;
- info->durationTime = tick_time;
- addSkillDuration(info);
- }
-}
-
-void SkillDialog::widgetResized(const Event &event)
-{
- Window::widgetResized(event);
-
- if (mTabs != nullptr)
- mTabs->adjustSize();
-}
-
-void SkillDialog::useItem(const int itemId,
- const AutoTarget autoTarget,
- const int level,
- const std::string &data) const
-{
- const std::map<int, SkillInfo*>::const_iterator
- it = mSkills.find(itemId - SKILL_MIN_ID);
- if (it == mSkills.end())
- return;
-
- const SkillInfo *const info = (*it).second;
- CastTypeT castType = CastType::Default;
- int offsetX = 0;
- int offsetY = 0;
-
- if (!data.empty())
- {
- STD_VECTOR<int> vect;
- splitToIntVector(vect, data, ' ');
- const size_t sz = vect.size();
- if (sz > 0)
- castType = static_cast<CastTypeT>(vect[0]);
- if (sz > 2)
- {
- offsetX = vect[1];
- offsetY = vect[2];
- }
- }
- useSkill(info,
- autoTarget,
- level,
- false,
- std::string(),
- castType,
- offsetX,
- offsetY);
-}
-
-void SkillDialog::updateTabSelection()
-{
- const SkillTab *const tab = static_cast<SkillTab*>(
- mTabs->getSelectedTab());
- if (tab != nullptr)
- {
- if (const SkillInfo *const info = tab->getSelectedInfo())
- {
- mUseButton->setEnabled(info->range > 0);
- mIncreaseButton->setEnabled(info->id < SKILL_VAR_MIN_ID);
- mUseButton->setCaption(info->useButton);
- }
- else
- {
- mUseButton->setEnabled(false);
- // TRANSLATORS: inventory button
- mUseButton->setCaption(_("Use"));
- }
- }
-}
-
-void SkillDialog::updateQuest(const int var,
- const int val1,
- const int val2 A_UNUSED,
- const int val3 A_UNUSED,
- const int time1 A_UNUSED)
-{
- const int id = var + SKILL_VAR_MIN_ID;
- const SkillMap::const_iterator it = mSkills.find(id);
-
- if (it != mSkills.end())
- {
- SkillInfo *const info = it->second;
- if (info != nullptr)
- {
- PlayerInfo::setSkillLevel(id, val1);
- info->level = val1;
- info->update();
- }
- }
-}
-
-SkillData *SkillDialog::getSkillData(const int id) const
-{
- const SkillMap::const_iterator it = mSkills.find(id);
- if (it != mSkills.end())
- {
- SkillInfo *const info = it->second;
- if (info != nullptr)
- return info->data;
- }
- return nullptr;
-}
-
-SkillData *SkillDialog::getSkillDataByLevel(const int id,
- const int level) const
-{
- const SkillMap::const_iterator it = mSkills.find(id);
- if (it != mSkills.end())
- {
- SkillInfo *const info = it->second;
- if (info != nullptr)
- return info->getData1(level);
- }
- return nullptr;
-}
-
-void SkillDialog::playUpdateEffect(const int id) const
-{
- if (effectManager == nullptr)
- return;
- const SkillData *const data = getSkillData(id);
- if (data == nullptr)
- return;
- effectManager->triggerDefault(data->updateEffectId,
- localPlayer,
- paths.getIntValue("skillLevelUpEffectId"));
-}
-
-void SkillDialog::playRemoveEffect(const int id) const
-{
- if (effectManager == nullptr)
- return;
- const SkillData *const data = getSkillData(id);
- if (data == nullptr)
- return;
- effectManager->triggerDefault(data->removeEffectId,
- localPlayer,
- paths.getIntValue("skillRemoveEffectId"));
-}
-
-void SkillDialog::playCastingDstTileEffect(const int id,
- const int level,
- const int x,
- const int y,
- const int delay) const
-{
- if (effectManager == nullptr)
- return;
- SkillData *const data = getSkillDataByLevel(id, level);
- if (data == nullptr)
- return;
- effectManager->triggerDefault(data->castingGroundEffectId,
- x * 32,
- y * 32,
- cur_time + delay / 1000, // end time in seconds
- paths.getIntValue("skillCastingGroundEffectId"));
-}
-
-void SkillDialog::useSkill(const int skillId,
- const AutoTarget autoTarget,
- int level,
- const bool withText,
- const std::string &text,
- CastTypeT castType,
- const int offsetX,
- const int offsetY)
-{
- SkillInfo *const info = skillDialog->getSkill(skillId);
- if (info == nullptr)
- return;
- if (castType == CastType::Default)
- castType = info->customCastType;
- useSkill(info,
- autoTarget,
- level,
- withText,
- text,
- castType,
- offsetX,
- offsetY);
-}
-
-void SkillDialog::useSkill(const SkillInfo *const info,
- const AutoTarget autoTarget,
- int level,
- const bool withText,
- const std::string &text,
- const CastTypeT castType,
- const int offsetX,
- const int offsetY)
-{
- if ((info == nullptr) || (localPlayer == nullptr))
- return;
- if (level == 0)
- level = info->level;
-
- const SkillData *data = info->getData1(level);
- if (data != nullptr)
- {
- const std::string cmd = data->invokeCmd;
- if (!cmd.empty())
- SpellManager::invokeCommand(cmd, localPlayer->getTarget());
- }
- switch (castType)
- {
- default:
- case CastType::Default:
- useSkillDefault(info,
- autoTarget,
- level,
- withText,
- text,
- offsetX,
- offsetY);
- break;
- case CastType::Target:
- {
- const Being *const being = localPlayer->getTarget();
- useSkillTarget(info,
- autoTarget,
- level,
- withText,
- text,
- being,
- offsetX,
- offsetY);
- break;
- }
- case CastType::Position:
- {
- int x = 0;
- int y = 0;
- viewport->getMouseTile(x, y);
- useSkillPosition(info,
- level,
- withText,
- text,
- x,
- y,
- offsetX,
- offsetY);
- break;
- }
- case CastType::Self:
- // +++ probably need call useSkillSelf
- useSkillTarget(info,
- autoTarget,
- level,
- withText,
- text,
- localPlayer,
- offsetX,
- offsetY);
- break;
- }
-}
-
-void SkillDialog::useSkillTarget(const SkillInfo *const info,
- const AutoTarget autoTarget,
- int level,
- const bool withText,
- const std::string &text,
- const Being *being,
- int offsetX,
- int offsetY)
-{
- SkillType::SkillType type = info->type;
- if ((type & SkillType::Attack) != 0)
- {
- if ((being == nullptr) && autoTarget == AutoTarget_true)
- {
- if (localPlayer != nullptr)
- {
- being = localPlayer->setNewTarget(ActorType::Monster,
- AllowSort_true);
- }
- }
- if (being != nullptr)
- {
- skillHandler->useBeing(info->id,
- level,
- being->getId());
- }
- }
- else if ((type & SkillType::Support) != 0)
- {
- if (being == nullptr)
- being = localPlayer;
- if (being != nullptr)
- {
- skillHandler->useBeing(info->id,
- level,
- being->getId());
- }
- }
- else if ((type & SkillType::Self) != 0)
- {
- skillHandler->useBeing(info->id,
- level,
- localPlayer->getId());
- }
- else if ((type & SkillType::Ground) != 0)
- {
- if (being == nullptr)
- return;
- being->fixDirectionOffsets(offsetX, offsetY);
- const int x = being->getTileX() + offsetX;
- const int y = being->getTileY() + offsetY;
- if (info->useTextParameter)
- {
- if (withText)
- {
- skillHandler->usePos(info->id,
- level,
- x, y,
- text);
- }
- else
- {
- const SkillData *data = info->getData1(level);
- textSkillListener.setSkill(info->id,
- x,
- y,
- level);
- TextDialog *const dialog = CREATEWIDGETR(TextDialog,
- // TRANSLATORS: text skill dialog header
- strprintf(_("Add text to skill %s"),
- data->name.c_str()),
- // TRANSLATORS: text skill dialog field
- _("Text: "));
- dialog->setModal(Modal_true);
- textSkillListener.setDialog(dialog);
- dialog->setActionEventId("ok");
- dialog->addActionListener(&textSkillListener);
- }
- }
- else
- {
- skillHandler->usePos(info->id,
- level,
- x, y);
- }
- }
- else if ((type & SkillType::TargetTrap) != 0)
- {
- // for now unused
- }
- else if (type == SkillType::Unknown ||
- type == SkillType::Unused)
- {
- // unknown / unused
- }
- else
- {
- reportAlways("Unsupported skill type: %d", type);
- }
-}
-
-void SkillDialog::useSkillPosition(const SkillInfo *const info,
- int level,
- const bool withText,
- const std::string &text,
- const int x,
- const int y,
- int offsetX,
- int offsetY)
-{
- SkillType::SkillType type = info->type;
- if ((type & SkillType::Ground) != 0)
- {
- localPlayer->fixDirectionOffsets(offsetX, offsetY);
- if (info->useTextParameter)
- {
- if (withText)
- {
- skillHandler->usePos(info->id,
- level,
- x + offsetX,
- y + offsetY,
- text);
- }
- else
- {
- const SkillData *data = info->getData1(level);
- textSkillListener.setSkill(info->id,
- x + offsetX,
- y + offsetY,
- level);
- TextDialog *const dialog = CREATEWIDGETR(TextDialog,
- // TRANSLATORS: text skill dialog header
- strprintf(_("Add text to skill %s"),
- data->name.c_str()),
- // TRANSLATORS: text skill dialog field
- _("Text: "));
- dialog->setModal(Modal_true);
- textSkillListener.setDialog(dialog);
- dialog->setActionEventId("ok");
- dialog->addActionListener(&textSkillListener);
- }
- }
- else
- {
- skillHandler->usePos(info->id,
- level,
- x + offsetX,
- y + offsetY);
- }
- }
- else if ((type & SkillType::Support) != 0)
- {
- // wrong type
- skillHandler->useBeing(info->id,
- level,
- localPlayer->getId());
- }
- else if ((type & SkillType::Self) != 0)
- {
- skillHandler->useBeing(info->id,
- level,
- localPlayer->getId());
- }
- else if ((type & SkillType::Attack) != 0)
- {
- // do nothing
- // +++ probably need select some target on x,y position?
- }
- else if ((type & SkillType::TargetTrap) != 0)
- {
- // for now unused
- }
- else if (type == SkillType::Unknown ||
- type == SkillType::Unused)
- {
- // unknown / unused
- }
- else
- {
- reportAlways("Unsupported skill type: %d", type);
- }
-}
-
-void SkillDialog::useSkillDefault(const SkillInfo *const info,
- const AutoTarget autoTarget,
- int level,
- const bool withText,
- const std::string &text,
- int offsetX,
- int offsetY)
-{
- SkillType::SkillType type = info->type;
- if ((type & SkillType::Attack) != 0)
- {
- const Being *being = localPlayer->getTarget();
- if ((being == nullptr) && autoTarget == AutoTarget_true)
- {
- being = localPlayer->setNewTarget(ActorType::Monster,
- AllowSort_true);
- }
- if (being != nullptr)
- {
- skillHandler->useBeing(info->id,
- level,
- being->getId());
- }
- }
- else if ((type & SkillType::Support) != 0)
- {
- const Being *being = localPlayer->getTarget();
- if (being == nullptr)
- being = localPlayer;
- if (being != nullptr)
- {
- skillHandler->useBeing(info->id,
- level,
- being->getId());
- }
- }
- else if ((type & SkillType::Self) != 0)
- {
- skillHandler->useBeing(info->id,
- level,
- localPlayer->getId());
- }
- else if ((type & SkillType::Ground) != 0)
- {
- int x = 0;
- int y = 0;
- viewport->getMouseTile(x, y);
- localPlayer->fixDirectionOffsets(offsetX, offsetY);
- x += offsetX;
- y += offsetY;
- if (info->useTextParameter)
- {
- if (withText)
- {
- skillHandler->usePos(info->id,
- level,
- x, y,
- text);
- }
- else
- {
- const SkillData *data = info->getData1(level);
- textSkillListener.setSkill(info->id,
- x,
- y,
- level);
- TextDialog *const dialog = CREATEWIDGETR(TextDialog,
- // TRANSLATORS: text skill dialog header
- strprintf(_("Add text to skill %s"),
- data->name.c_str()),
- // TRANSLATORS: text skill dialog field
- _("Text: "));
- dialog->setModal(Modal_true);
- textSkillListener.setDialog(dialog);
- dialog->setActionEventId("ok");
- dialog->addActionListener(&textSkillListener);
- }
- }
- else
- {
- skillHandler->usePos(info->id,
- level,
- x, y);
- }
- }
- else if ((type & SkillType::TargetTrap) != 0)
- {
- // for now unused
- }
- else if (type == SkillType::Unknown ||
- type == SkillType::Unused)
- {
- // unknown / unused
- }
- else
- {
- reportAlways("Unsupported skill type: %d", type);
- }
-}
-
-void SkillDialog::addSkillDuration(SkillInfo *const skill)
-{
- if (skill == nullptr)
- return;
-
- FOR_EACH (STD_VECTOR<SkillInfo*>::const_iterator, it, mDurations)
- {
- if ((*it)->id == skill->id)
- return;
- }
- mDurations.push_back(skill);
-}
-
-void SkillDialog::slowLogic()
-{
- FOR_EACH_SAFE (STD_VECTOR<SkillInfo*>::iterator, it, mDurations)
- {
- SkillInfo *const skill = *it;
- if (skill != nullptr)
- {
- const int time = get_elapsed_time(skill->durationTime);
- if (time >= skill->duration)
- {
- it = mDurations.erase(it);
- skill->cooldown = 0;
- skill->duration = 0;
- skill->durationTime = 0;
- if (it == mDurations.end())
- return;
- if (it != mDurations.begin())
- -- it;
- }
- else if (time != 0)
- {
- skill->cooldown = skill->duration * 100 / time;
- }
- }
- }
-}
-
-void SkillDialog::selectSkillLevel(const int skillId,
- const int level)
-{
- SkillInfo *const info = getSkill(skillId);
- if (info == nullptr)
- return;
- if (level > info->level)
- info->customSelectedLevel = info->level;
- else
- info->customSelectedLevel = level;
- info->update();
-}
-
-void SkillDialog::selectSkillCastType(const int skillId,
- const CastTypeT type)
-{
- SkillInfo *const info = getSkill(skillId);
- if (info == nullptr)
- return;
- info->customCastType = type;
- info->update();
-}
-
-void SkillDialog::setSkillOffsetX(const int skillId,
- const int offset)
-{
- SkillInfo *const info = getSkill(skillId);
- if (info == nullptr)
- return;
- info->customOffsetX = offset;
- info->update();
-}
-
-void SkillDialog::setSkillOffsetY(const int skillId,
- const int offset)
-{
- SkillInfo *const info = getSkill(skillId);
- if (info == nullptr)
- return;
- info->customOffsetY = offset;
- info->update();
-}
diff --git a/src/gui/windows/skilldialog.h b/src/gui/windows/skilldialog.h
deleted file mode 100644
index 2273125f0..000000000
--- a/src/gui/windows/skilldialog.h
+++ /dev/null
@@ -1,237 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_SKILLDIALOG_H
-#define GUI_WINDOWS_SKILLDIALOG_H
-
-#include "gui/widgets/window.h"
-
-#include "enums/simpletypes/autotarget.h"
-#include "enums/simpletypes/modifiable.h"
-
-#include "enums/resources/skill/casttype.h"
-#include "enums/resources/skill/skillowner.h"
-#include "enums/resources/skill/skilltype.h"
-
-#include "listeners/actionlistener.h"
-
-#include "utils/xml.h"
-
-class Being;
-class Button;
-class Label;
-class SkillModel;
-class SkillTab;
-class Tab;
-class TabbedArea;
-
-struct SkillData;
-struct SkillInfo;
-
-/**
- * The skill dialog.
- *
- * \ingroup Interface
- */
-class SkillDialog final : public Window,
- public ActionListener
-{
- public:
- SkillDialog();
-
- A_DELETE_COPY(SkillDialog)
-
- ~SkillDialog();
-
- void postInit() override final;
-
- /**
- * Called when receiving actions from widget.
- */
- void action(const ActionEvent &event) override final;
-
- /**
- * Update the given skill's display
- */
- std::string update(const int id);
-
- /**
- * Update other parts of the display
- */
- void update();
-
- void updateModels();
-
- void loadXmlFile(const std::string &fileName,
- const SkipError skipError);
-
- void clearSkills();
-
- void hideSkills(const SkillOwner::Type owner);
-
- void loadSkills();
-
- bool updateSkill(const int id,
- const int range,
- const Modifiable modifiable,
- const SkillType::SkillType type,
- const int sp);
-
- void addSkill(const SkillOwner::Type owner,
- const int id,
- const std::string &name,
- const int level,
- const int range,
- const Modifiable modifiable,
- const SkillType::SkillType type,
- const int sp);
-
- SkillInfo* getSkill(const int id) const A_WARN_UNUSED;
-
- SkillInfo* getSkillByItem(const int itemId) const A_WARN_UNUSED;
-
- void setSkillDuration(const SkillOwner::Type owner,
- const int id,
- const int duration);
-
- bool hasSkills() const noexcept2 A_WARN_UNUSED
- { return !mSkills.empty(); }
-
- void widgetResized(const Event &event) override final;
-
- void useItem(const int itemId,
- const AutoTarget autoTarget,
- const int level,
- const std::string &data) const;
-
- void updateTabSelection();
-
- void updateQuest(const int var,
- const int val1,
- const int val2,
- const int val3,
- const int time1);
-
- void playUpdateEffect(const int id) const;
-
- void playRemoveEffect(const int id) const;
-
- void playCastingDstTileEffect(const int id,
- const int level,
- const int x,
- const int y,
- const int delay) const;
-
- void slowLogic();
-
- void removeSkill(const int id);
-
- static void useSkill(const int skillId,
- const AutoTarget autoTarget,
- int level,
- const bool withText,
- const std::string &text,
- CastTypeT castType,
- const int offsetX,
- const int offsetY);
-
- static void useSkill(const SkillInfo *const info,
- const AutoTarget autoTarget,
- int level,
- const bool withText,
- const std::string &text,
- const CastTypeT castType,
- const int offsetX,
- const int offsetY);
-
- SkillData *getSkillData(const int id) const;
-
- SkillData *getSkillDataByLevel(const int id,
- const int level) const;
-
- void selectSkillLevel(const int skillId,
- const int level);
-
- void selectSkillCastType(const int skillId,
- const CastTypeT type);
-
- void setSkillOffsetX(const int skillId,
- const int offset);
-
- void setSkillOffsetY(const int skillId,
- const int offset);
-
- private:
- static void useSkillDefault(const SkillInfo *const info,
- const AutoTarget autoTarget,
- int level,
- const bool withText,
- const std::string &text,
- int offsetX,
- int offsetY);
-
- static void useSkillTarget(const SkillInfo *const info,
- const AutoTarget autoTarget,
- int level,
- const bool withText,
- const std::string &text,
- const Being *being,
- int offsetX,
- int offsetY);
-
- static void useSkillPosition(const SkillInfo *const info,
- int level,
- const bool withText,
- const std::string &text,
- const int x,
- const int y,
- int offsetX,
- int offsetY);
-
- static std::string getDefaultSkillIcon(const SkillType::SkillType
- type);
-
- void addSkillDuration(SkillInfo *const skill);
-
- SkillInfo *loadSkill(XmlNodeConstPtr node,
- SkillModel *const model);
-
- void loadSkillData(XmlNodeConstPtr node,
- SkillInfo *const skill);
-
- void addDefaultTab();
-
- typedef std::map<int, SkillInfo*> SkillMap;
- SkillMap mSkills;
- STD_VECTOR<SkillInfo*> mDurations;
- TabbedArea *mTabs A_NONNULLPOINTER;
- std::list<Tab*> mDeleteTabs;
- Label *mPointsLabel A_NONNULLPOINTER;
- Button *mUseButton A_NONNULLPOINTER;
- Button *mIncreaseButton A_NONNULLPOINTER;
- SkillModel *mDefaultModel;
- SkillTab *mDefaultTab;
-};
-
-extern SkillDialog *skillDialog;
-
-#endif // GUI_WINDOWS_SKILLDIALOG_H
diff --git a/src/gui/windows/socialwindow.cpp b/src/gui/windows/socialwindow.cpp
deleted file mode 100644
index 174762100..000000000
--- a/src/gui/windows/socialwindow.cpp
+++ /dev/null
@@ -1,659 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/socialwindow.h"
-
-#include "gui/popups/popupmenu.h"
-
-#include "gui/windows/setupwindow.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/tabbedarea.h"
-
-#include "gui/widgets/tabs/socialattacktab.h"
-#include "gui/widgets/tabs/socialfriendstab.h"
-#include "gui/widgets/tabs/socialguildtab.h"
-#include "gui/widgets/tabs/socialnavigationtab.h"
-#include "gui/widgets/tabs/socialpartytab.h"
-#include "gui/widgets/tabs/socialpickuptab.h"
-#include "gui/widgets/tabs/socialplayerstab.h"
-
-#ifdef TMWA_SUPPORT
-#include "gui/widgets/tabs/socialguildtab2.h"
-
-#include "net/tmwa/guildmanager.h"
-#endif // TMWA_SUPPORT
-
-#include "debug.h"
-
-SocialWindow *socialWindow = nullptr;
-
-SocialWindow::SocialWindow() :
- // TRANSLATORS: social window name
- Window(_("Social"), Modal_false, nullptr, "social.xml"),
- ActionListener(),
- PlayerRelationsListener(),
- mGuildInvited(0),
- mGuildAcceptDialog(nullptr),
- mGuildCreateDialog(nullptr),
- mPartyInviter(),
- mGuilds(),
- mParties(),
- mPartyAcceptDialog(nullptr),
- mAttackFilter(nullptr),
- mPickupFilter(nullptr),
- // TRANSLATORS: here P is title for visible players tab in social window
- mPlayers(new SocialPlayersTab(this, _("P"),
- fromBool(getOptionBool("showtabbackground"), Opaque))),
- mNavigation(new SocialNavigationTab(this,
- fromBool(getOptionBool("showtabbackground"), Opaque))),
- // TRANSLATORS: here F is title for friends tab in social window
- mFriends(new SocialFriendsTab(this, _("F"),
- fromBool(getOptionBool("showtabbackground"), Opaque))),
- // TRANSLATORS: social window button
- mMenuButton(new Button(this, _("Menu"), "menu", this)),
- mCountLabel(new Label(this, "1000 / 1000")),
- mTabs(CREATEWIDGETR(TabbedArea, this)),
- mMap(nullptr),
- mLastUpdateTime(0),
- mPartyId(0),
- mNeedUpdate(false),
- mProcessedPortals(false)
-{
-}
-
-void SocialWindow::postInit()
-{
- Window::postInit();
- setWindowName("Social");
- setVisible(Visible_false);
- setSaveVisible(true);
- setResizable(true);
- setSaveVisible(true);
- setCloseButton(true);
- setStickyButtonLock(true);
-
- setMinWidth(120);
- setMinHeight(55);
- setDefaultSize(590, 200, 180, 300);
- if (setupWindow != nullptr)
- setupWindow->registerWindowForReset(this);
-
- place(0, 0, mMenuButton);
- place(0, 1, mCountLabel);
- place(0, 2, mTabs, 2, 4);
-
- widgetResized(Event(nullptr));
-
- loadWindowState();
-
- mTabs->addTab(mPlayers, mPlayers->mScroll);
- mTabs->addTab(mFriends, mFriends->mScroll);
- mTabs->addTab(mNavigation, mNavigation->mScroll);
- mTabs->setSelectable(false);
- mTabs->getTabContainer()->setSelectable(false);
- mTabs->getWidgetContainer()->setSelectable(false);
-
- if (config.getBoolValue("enableAttackFilter"))
- {
- mAttackFilter = new SocialAttackTab(this,
- fromBool(getOptionBool("showtabbackground"), Opaque));
- mTabs->addTab(mAttackFilter, mAttackFilter->mScroll);
- }
- else
- {
- mAttackFilter = nullptr;
- }
-
- if (config.getBoolValue("enablePickupFilter"))
- {
- mPickupFilter = new SocialPickupTab(this,
- fromBool(getOptionBool("showtabbackground"), Opaque));
- mTabs->addTab(mPickupFilter, mPickupFilter->mScroll);
- }
- else
- {
- mPickupFilter = nullptr;
- }
-
- if ((localPlayer != nullptr) && (localPlayer->getParty() != nullptr))
- addTab(localPlayer->getParty());
-
- if ((localPlayer != nullptr) && (localPlayer->getGuild() != nullptr))
- addTab(localPlayer->getGuild());
-
- enableVisibleSound(true);
- updateButtons();
- playerRelations.addListener(this);
-}
-
-SocialWindow::~SocialWindow()
-{
- playerRelations.removeListener(this);
- if (mGuildAcceptDialog != nullptr)
- {
- mGuildAcceptDialog->close();
- mGuildAcceptDialog->scheduleDelete();
- mGuildAcceptDialog = nullptr;
-
- mGuildInvited = 0;
- }
-
- if (mPartyAcceptDialog != nullptr)
- {
- mPartyAcceptDialog->close();
- mPartyAcceptDialog->scheduleDelete();
- mPartyAcceptDialog = nullptr;
-
- mPartyInviter.clear();
- }
- delete2(mPlayers);
- delete2(mNavigation);
- delete2(mAttackFilter);
- delete2(mPickupFilter);
- delete2(mFriends);
- FOR_EACH (GuildMap::iterator, it, mGuilds)
- {
- delete (*it).second;
- }
- mGuilds.clear();
- FOR_EACH (PartyMap::iterator, it, mParties)
- {
- delete (*it).second;
- }
- mParties.clear();
-}
-
-bool SocialWindow::addTab(Guild *const guild)
-{
- if (guild == nullptr)
- return false;
-
- if (mGuilds.find(guild) != mGuilds.end())
- return false;
-
- SocialTab *tab = nullptr;
- if (guild->getServerGuild())
- {
- tab = new SocialGuildTab(this, guild,
- fromBool(getOptionBool("showtabbackground"), Opaque));
- }
-#ifdef TMWA_SUPPORT
- else
- {
- tab = new SocialGuildTab2(this, guild,
- fromBool(getOptionBool("showtabbackground"), Opaque));
- }
-#endif // TMWA_SUPPORT
-
- mGuilds[guild] = tab;
- mTabs->addTab(tab, tab->mScroll);
-
- updateButtons();
-
- return true;
-}
-
-bool SocialWindow::removeTab(Guild *const guild)
-{
- const GuildMap::iterator it = mGuilds.find(guild);
- if (it == mGuilds.end())
- return false;
-
- mTabs->removeTab(it->second);
- delete it->second;
- mGuilds.erase(it);
-
- updateButtons();
-
- return true;
-}
-
-bool SocialWindow::addTab(Party *const party)
-{
- if (party == nullptr)
- return false;
-
- if (mParties.find(party) != mParties.end())
- return false;
-
- SocialPartyTab *const tab = new SocialPartyTab(this, party,
- fromBool(getOptionBool("showtabbackground"), Opaque));
- mParties[party] = tab;
-
- mTabs->addTab(tab, tab->mScroll);
-
- updateButtons();
-
- return true;
-}
-
-bool SocialWindow::removeTab(Party *const party)
-{
- const PartyMap::iterator it = mParties.find(party);
- if (it == mParties.end())
- return false;
-
- mTabs->removeTab(it->second);
- delete it->second;
- mParties.erase(it);
-
- updateButtons();
-
- return true;
-}
-
-void SocialWindow::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
-
- if (event.getSource() == mPartyAcceptDialog)
- {
- if (eventId == "yes")
- {
- if (localChatTab != nullptr)
- {
- localChatTab->chatLog(
- // TRANSLATORS: chat message
- strprintf(_("Accepted party invite from %s."),
- mPartyInviter.c_str()),
- ChatMsgType::BY_SERVER);
- }
- partyHandler->inviteResponse(mPartyId, true);
- }
- else if (eventId == "no")
- {
- if (localChatTab != nullptr)
- {
- localChatTab->chatLog(
- // TRANSLATORS: chat message
- strprintf(_("Rejected party invite from %s."),
- mPartyInviter.c_str()),
- ChatMsgType::BY_SERVER);
- }
- partyHandler->inviteResponse(mPartyId, false);
- }
-
- mPartyInviter.clear();
- mPartyAcceptDialog = nullptr;
- }
- else if (event.getSource() == mGuildAcceptDialog)
- {
- if (eventId == "yes")
- {
- if (localChatTab != nullptr)
- {
- localChatTab->chatLog(
- // TRANSLATORS: chat message
- strprintf(_("Accepted guild invite from %s."),
- mPartyInviter.c_str()),
- ChatMsgType::BY_SERVER);
- }
-#ifdef TMWA_SUPPORT
- if (guildManager == nullptr || !GuildManager::getEnableGuildBot())
- guildHandler->inviteResponse(mGuildInvited, true);
- else
- GuildManager::inviteResponse(true);
-#else // TMWA_SUPPORT
-
- guildHandler->inviteResponse(mGuildInvited, true);
-#endif // TMWA_SUPPORT
- }
- else if (eventId == "no")
- {
- if (localChatTab != nullptr)
- {
- localChatTab->chatLog(
- // TRANSLATORS: chat message
- strprintf(_("Rejected guild invite from %s."),
- mPartyInviter.c_str()),
- ChatMsgType::BY_SERVER);
- }
-#ifdef TMWA_SUPPORT
- if (guildManager == nullptr || !GuildManager::getEnableGuildBot())
- guildHandler->inviteResponse(mGuildInvited, false);
- else
- GuildManager::inviteResponse(false);
-#else // TMWA_SUPPORT
-
- guildHandler->inviteResponse(mGuildInvited, false);
-#endif // TMWA_SUPPORT
- }
-
- mGuildInvited = 0;
- mGuildAcceptDialog = nullptr;
- }
- else if (eventId == "party")
- {
- popupMenu->showPartyPopup();
- }
- else if (eventId == "guild")
- {
- popupMenu->showGuildPopup();
- }
- else if (eventId == "attack")
- {
- popupMenu->showAttackPopup();
- }
- else if (eventId == "friends")
- {
- popupMenu->showFriendsPopup();
- }
- else if (eventId == "navigation")
- {
- popupMenu->showNavigationPopup();
- }
- else if (eventId == "pickup")
- {
- popupMenu->showPickupPopup();
- }
- else if (eventId == "players")
- {
- popupMenu->showPlayersPopup();
- }
-}
-
-void SocialWindow::showGuildInvite(const std::string &restrict guildName,
- const int guildId,
- const std::string &restrict inviterName)
-{
- // check there isnt already an invite showing
- if (mGuildInvited != 0)
- {
- if (localChatTab != nullptr)
- {
- // TRANSLATORS: chat message
- localChatTab->chatLog(_("Received guild request, but one already "
- "exists."),
- ChatMsgType::BY_SERVER);
- }
- return;
- }
-
- const std::string msg = strprintf(
- // TRANSLATORS: chat message
- _("%s has invited you to join the guild %s."),
- inviterName.c_str(), guildName.c_str());
-
- if (localChatTab != nullptr)
- localChatTab->chatLog(msg, ChatMsgType::BY_SERVER);
-
- CREATEWIDGETV(mGuildAcceptDialog, ConfirmDialog,
- // TRANSLATORS: guild invite message
- _("Accept Guild Invite"),
- msg,
- SOUND_REQUEST,
- false,
- Modal_false,
- this);
- mGuildAcceptDialog->addActionListener(this);
- mGuildInvited = guildId;
-}
-
-void SocialWindow::showPartyInvite(const std::string &restrict partyName,
- const std::string &restrict inviter,
- const int partyId)
-{
- // check there isnt already an invite showing
- if (!mPartyInviter.empty())
- {
- if (localChatTab != nullptr)
- {
- // TRANSLATORS: chat message
- localChatTab->chatLog(_("Received party request, but one already "
- "exists."),
- ChatMsgType::BY_SERVER);
- }
- return;
- }
-
- std::string msg;
- if (inviter.empty())
- {
- if (partyName.empty())
- {
- // TRANSLATORS: party invite message
- msg = _("You have been invited you to join a party.");
- }
- else
- {
- // TRANSLATORS: party invite message
- msg = strprintf(_("You have been invited to join the %s party."),
- partyName.c_str());
- }
- }
- else
- {
- if (partyName.empty())
- {
- // TRANSLATORS: party invite message
- msg = strprintf(_("%s has invited you to join their party."),
- inviter.c_str());
- }
- else
- {
- // TRANSLATORS: party invite message
- msg = strprintf(_("%s has invited you to join the %s party."),
- inviter.c_str(), partyName.c_str());
- }
- }
-
- if (localChatTab != nullptr)
- localChatTab->chatLog(msg, ChatMsgType::BY_SERVER);
-
- // show invite
- CREATEWIDGETV(mPartyAcceptDialog, ConfirmDialog,
- // TRANSLATORS: party invite message
- _("Accept Party Invite"),
- msg,
- SOUND_REQUEST,
- false,
- Modal_false,
- this);
- mPartyAcceptDialog->addActionListener(this);
- mPartyInviter = inviter;
- mPartyId = partyId;
-}
-
-void SocialWindow::updateActiveList()
-{
- mNeedUpdate = true;
-}
-
-void SocialWindow::slowLogic()
-{
- BLOCK_START("SocialWindow::slowLogic")
- const time_t nowTime = cur_time;
- if (mNeedUpdate && nowTime - mLastUpdateTime > 1)
- {
- mPlayers->updateList();
- mFriends->updateList();
- mNeedUpdate = false;
- mLastUpdateTime = nowTime;
- }
- else if (nowTime - mLastUpdateTime > 5)
- {
- mPlayers->updateList();
- mNeedUpdate = false;
- mLastUpdateTime = nowTime;
- }
- BLOCK_END("SocialWindow::slowLogic")
-}
-
-void SocialWindow::updateAvatar(const std::string &name)
-{
- mPlayers->updateAvatar(name);
-}
-
-void SocialWindow::resetDamage(const std::string &name)
-{
- mPlayers->resetDamage(name);
-}
-
-void SocialWindow::updateButtons()
-{
-// if (!mTabs)
-// return;
-
-// const bool hasTabs = mTabs->getNumberOfTabs() > 0;
-}
-
-void SocialWindow::updatePortals()
-{
- if (mNavigation != nullptr)
- mNavigation->updateList();
-}
-
-void SocialWindow::updatePortalNames()
-{
- if (mNavigation != nullptr)
- static_cast<SocialNavigationTab*>(mNavigation)->updateNames();
-}
-
-void SocialWindow::selectPortal(const unsigned num)
-{
- if (mNavigation != nullptr)
- mNavigation->selectIndex(num);
-}
-
-int SocialWindow::getPortalIndex(const int x, const int y)
-{
- if (mNavigation != nullptr)
- {
- return static_cast<SocialNavigationTab*>(
- mNavigation)->getPortalIndex(x, y);
- }
- return -1;
-}
-
-void SocialWindow::addPortal(const int x, const int y)
-{
- if (mNavigation != nullptr)
- static_cast<SocialNavigationTab*>(mNavigation)->addPortal(x, y);
-}
-
-void SocialWindow::removePortal(const int x, const int y)
-{
- if (mNavigation != nullptr)
- static_cast<SocialNavigationTab*>(mNavigation)->removePortal(x, y);
-}
-
-void SocialWindow::nextTab()
-{
- if (mTabs != nullptr)
- mTabs->selectNextTab();
-}
-
-void SocialWindow::prevTab()
-{
- if (mTabs != nullptr)
- mTabs->selectPrevTab();
-}
-
-void SocialWindow::updateAttackFilter()
-{
- if (mAttackFilter != nullptr)
- mAttackFilter->updateList();
-}
-
-void SocialWindow::updatePickupFilter()
-{
- if (mPickupFilter != nullptr)
- mPickupFilter->updateList();
-}
-
-void SocialWindow::updateParty()
-{
- if (localPlayer == nullptr)
- return;
-
- Party *const party = localPlayer->getParty();
- if (party != nullptr)
- {
- const PartyMap::iterator it = mParties.find(party);
- if (it != mParties.end())
- {
- SocialTab *const tab = (*it).second;
- tab->buildCounter(0, 0);
- }
- }
-}
-
-void SocialWindow::widgetResized(const Event &event)
-{
- Window::widgetResized(event);
- if (mTabs != nullptr)
- mTabs->adjustSize();
-}
-
-void SocialWindow::updateCounter(const SocialTab *const tab,
- const std::string &counter)
-{
- if (mTabs->getSelectedTab() == tab)
- {
- mCountLabel->setCaption(counter);
- mCountLabel->adjustSize();
- }
-}
-
-void SocialWindow::updateMenu(const SocialTab *const tab,
- const std::string &menu)
-{
- if (mTabs->getSelectedTab() == tab)
- mMenuButton->setActionEventId(menu);
-}
-
-void SocialWindow::updateGuildCounter(const int online, const int total)
-{
- if (localPlayer == nullptr)
- return;
-
- Guild *const guild = localPlayer->getGuild();
- if (guild != nullptr)
- {
- const GuildMap::iterator it = mGuilds.find(guild);
- if (it != mGuilds.end())
- {
- SocialTab *const tab = (*it).second;
- tab->buildCounter(online, total);
- }
- }
-}
-
-void SocialWindow::updatedPlayer(const std::string &name A_UNUSED)
-{
- mNeedUpdate = true;
-}
-
-void SocialWindow::updateAll()
-{
- mNeedUpdate = true;
-}
-
-#ifdef USE_PROFILER
-void SocialWindow::logicChildren()
-{
- BLOCK_START("SocialWindow::logicChildren")
- BasicContainer::logicChildren();
- BLOCK_END("SocialWindow::logicChildren")
-}
-#endif // USE_PROFILER
diff --git a/src/gui/windows/socialwindow.h b/src/gui/windows/socialwindow.h
deleted file mode 100644
index 2abee7170..000000000
--- a/src/gui/windows/socialwindow.h
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_SOCIALWINDOW_H
-#define GUI_WINDOWS_SOCIALWINDOW_H
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/playerrelationslistener.h"
-
-class Button;
-class ConfirmDialog;
-class Guild;
-class Label;
-class Map;
-class Party;
-class SocialTab;
-class TabbedArea;
-class TextDialog;
-
-/**
- * Party window.
- *
- * \ingroup Interface
- */
-class SocialWindow final : public Window,
- private ActionListener,
- public PlayerRelationsListener
-{
- public:
- SocialWindow();
-
- A_DELETE_COPY(SocialWindow)
-
- ~SocialWindow();
-
- void postInit() override final;
-
- bool addTab(Guild *const guild);
-
- bool removeTab(Guild *const guild);
-
- bool addTab(Party *const party);
-
- bool removeTab(Party *const party);
-
- void action(const ActionEvent &event) override final;
-
- void showGuildInvite(const std::string &restrict guildName,
- const int guildId,
- const std::string &restrict inviterName);
-
- void showPartyInvite(const std::string &restrict partyName,
- const std::string &restrict inviter,
- const int partyId);
-
- void updateActiveList();
-
- void updateAvatar(const std::string &name);
-
- void resetDamage(const std::string &name);
-
- void slowLogic();
-
- void updatePortals();
-
- void updatePortalNames();
-
- void updateParty();
-
- int getPortalIndex(const int x, const int y) A_WARN_UNUSED;
-
- void addPortal(const int x, const int y);
-
- void removePortal(const int x, const int y);
-
- void nextTab();
-
- void prevTab();
-
- const Map* getMap() const noexcept2 A_WARN_UNUSED
- { return mMap; }
-
- void setMap(Map *const map)
- { mMap = map; mProcessedPortals = false; }
-
- bool getProcessedPortals() const noexcept2 A_WARN_UNUSED
- { return mProcessedPortals; }
-
- void setProcessedPortals(const bool n) noexcept2
- { mProcessedPortals = n; }
-
- void selectPortal(const unsigned num);
-
- void updateAttackFilter();
-
- void updatePickupFilter();
-
- void widgetResized(const Event &event) override final;
-
- void updateCounter(const SocialTab *const tab,
- const std::string &count);
-
- void updateMenu(const SocialTab *const tab,
- const std::string &menu);
-
- void updateGuildCounter(const int online = 0, const int total = 0);
-
- void updatedPlayer(const std::string &name) override final;
-
- void updateAll() override final;
-
-#ifdef USE_PROFILER
- void logicChildren();
-#endif // USE_PROFILER
-
- protected:
- friend class SocialTab;
- typedef std::map<Guild*, SocialTab*> GuildMap;
- typedef std::map<Party*, SocialTab*> PartyMap;
-
- void updateButtons();
-
- int mGuildInvited;
- ConfirmDialog *mGuildAcceptDialog;
- TextDialog *mGuildCreateDialog;
- std::string mPartyInviter;
- GuildMap mGuilds;
- PartyMap mParties;
-
- ConfirmDialog *mPartyAcceptDialog;
-
- SocialTab *mAttackFilter;
- SocialTab *mPickupFilter;
- SocialTab *mPlayers A_NONNULLPOINTER;
- SocialTab *mNavigation A_NONNULLPOINTER;
- SocialTab *mFriends A_NONNULLPOINTER;
-
- Button *mMenuButton A_NONNULLPOINTER;
- Label *mCountLabel A_NONNULLPOINTER;
- TabbedArea *mTabs A_NONNULLPOINTER;
- Map *mMap;
-
- time_t mLastUpdateTime;
- int mPartyId;
- bool mNeedUpdate;
- bool mProcessedPortals;
-};
-
-extern SocialWindow *socialWindow;
-
-#endif // GUI_WINDOWS_SOCIALWINDOW_H
diff --git a/src/gui/windows/statuswindow.cpp b/src/gui/windows/statuswindow.cpp
deleted file mode 100644
index 092e401c2..000000000
--- a/src/gui/windows/statuswindow.cpp
+++ /dev/null
@@ -1,652 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/statuswindow.h"
-
-#include "configuration.h"
-#include "gamemodifiers.h"
-#include "settings.h"
-
-#include "being/localplayer.h"
-#include "being/playerinfo.h"
-
-#include "enums/gui/layouttype.h"
-
-#include "gui/windows/chatwindow.h"
-
-#include "gui/windows/equipmentwindow.h"
-#include "gui/windows/setupwindow.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/layout.h"
-#include "gui/widgets/progressbar.h"
-#include "gui/widgets/statspage.h"
-#include "gui/widgets/statspagebasic.h"
-#include "gui/widgets/tabbedarea.h"
-#include "gui/widgets/windowcontainer.h"
-
-#include "net/inventoryhandler.h"
-#include "net/playerhandler.h"
-
-#include "resources/db/groupdb.h"
-#include "resources/db/unitsdb.h"
-#include "resources/db/statdb.h"
-
-#include "resources/item/item.h"
-
-#include "utils/delete2.h"
-#include "utils/dtor.h"
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-StatusWindow *statusWindow = nullptr;
-
-StatusWindow::StatusWindow() :
- Window(localPlayer != nullptr ? localPlayer->getName() :
- "?", Modal_false, nullptr, "status.xml"),
- ActionListener(),
- AttributeListener(),
- mPages(),
- mTabs(CREATEWIDGETR(TabbedArea, this)),
- // TRANSLATORS: status window label
- mLvlLabel(new Label(this, strprintf(_("Level: %d"), 0))),
- // TRANSLATORS: status window label
- mMoneyLabel(new Label(this, strprintf(_("Money: %s"), ""))),
- // TRANSLATORS: status window label
- mHpLabel(new Label(this, _("HP:"))),
- mMpLabel(nullptr),
- // TRANSLATORS: status window label
- mXpLabel(new Label(this, _("Exp:"))),
- mHpBar(nullptr),
- mMpBar(nullptr),
- mXpBar(nullptr),
- mJobLvlLabel(nullptr),
- mJobLabel(nullptr),
- mJobBar(nullptr),
- mBasicStatsPage(new StatsPageBasic(this)),
- // TRANSLATORS: status window button
- mCopyButton(new Button(this, _("Copy to chat"), "copy", this))
-{
- setWindowName("Status");
- if (setupWindow != nullptr)
- setupWindow->registerWindowForReset(this);
- setResizable(true);
- setCloseButton(true);
- setSaveVisible(true);
- setStickyButtonLock(true);
- setDefaultSize((windowContainer->getWidth() - 480) / 2,
- (windowContainer->getHeight() - 500) / 2, 480, 500);
-
- mTabs->setSelectable(false);
- mTabs->getWidgetContainer()->setSelectable(false);
- mTabs->getTabContainer()->setSelectable(false);
-
- if ((localPlayer != nullptr) && !localPlayer->getRaceName().empty())
- {
- setCaption(strprintf("%s (%s)", localPlayer->getName().c_str(),
- localPlayer->getRaceName().c_str()));
- }
-
- int max = PlayerInfo::getAttribute(Attributes::PLAYER_MAX_HP);
- if (max == 0)
- max = 1;
-
- mHpBar = new ProgressBar(this,
- static_cast<float>(PlayerInfo::getAttribute(Attributes::PLAYER_HP))
- / static_cast<float>(max),
- 80,
- 0,
- ProgressColorId::PROG_HP,
- "hpprogressbar.xml", "hpprogressbar_fill.xml");
- mHpBar->setColor(getThemeColor(ThemeColorId::HP_BAR),
- getThemeColor(ThemeColorId::HP_BAR_OUTLINE));
- mHpBar->setSelectable(false);
-
- const int64_t maxExp = PlayerInfo::getAttribute64(
- Attributes::PLAYER_EXP_NEEDED);
- mXpBar = new ProgressBar(this,
- maxExp != 0 ?
- static_cast<float>(PlayerInfo::getAttribute64(
- Attributes::PLAYER_EXP)) /
- static_cast<float>(maxExp) : static_cast<float>(0),
- 80,
- 0,
- ProgressColorId::PROG_EXP,
- "xpprogressbar.xml", "xpprogressbar_fill.xml");
- mXpBar->setColor(getThemeColor(ThemeColorId::XP_BAR),
- getThemeColor(ThemeColorId::XP_BAR_OUTLINE));
- mXpBar->setSelectable(false);
-
- const bool job = serverConfig.getValueBool("showJob", true);
-
- max = PlayerInfo::getAttribute(Attributes::PLAYER_MAX_MP);
- // TRANSLATORS: status window label
- mMpLabel = new Label(this, _("MP:"));
- const bool useMagic = playerHandler->canUseMagic();
- mMpBar = new ProgressBar(this,
- max != 0 ? static_cast<float>(PlayerInfo::getAttribute(
- Attributes::PLAYER_MAX_MP)) / static_cast<float>(max)
- : static_cast<float>(0),
- 80,
- 0,
- useMagic ? ProgressColorId::PROG_MP : ProgressColorId::PROG_NO_MP,
- useMagic ? "mpprogressbar.xml" : "nompprogressbar.xml",
- useMagic ? "mpprogressbar_fill.xml" : "nompprogressbar_fill.xml");
- mMpBar->setSelectable(false);
- if (useMagic)
- {
- mMpBar->setColor(getThemeColor(ThemeColorId::MP_BAR),
- getThemeColor(ThemeColorId::MP_BAR_OUTLINE));
- }
- else
- {
- mMpBar->setColor(getThemeColor(ThemeColorId::NO_MP_BAR),
- getThemeColor(ThemeColorId::NO_MP_BAR_OUTLINE));
- }
-
- place(0, 0, mLvlLabel, 3);
- place(0, 1, mHpLabel).setPadding(3);
- place(1, 1, mHpBar, 4);
- place(5, 1, mXpLabel).setPadding(3);
- place(6, 1, mXpBar, 5);
- place(0, 2, mMpLabel).setPadding(3);
- // 5, 2 and 6, 2 Job Progress Bar
- if (job)
- place(1, 2, mMpBar, 4);
- else
- place(1, 2, mMpBar, 10);
-
- if (job)
- {
- // TRANSLATORS: status window label
- mJobLvlLabel = new Label(this, strprintf(_("Job: %d"), 0));
- // TRANSLATORS: status window label
- mJobLabel = new Label(this, _("Job:"));
- mJobBar = new ProgressBar(this, 0.0F, 80, 0, ProgressColorId::PROG_JOB,
- "jobprogressbar.xml", "jobprogressbar_fill.xml");
- mJobBar->setColor(getThemeColor(ThemeColorId::JOB_BAR),
- getThemeColor(ThemeColorId::JOB_BAR_OUTLINE));
- mJobBar->setSelectable(false);
-
- place(3, 0, mJobLvlLabel, 3);
- place(5, 2, mJobLabel).setPadding(3);
- place(6, 2, mJobBar, 5);
- place(6, 0, mMoneyLabel, 3);
- }
- else
- {
- mJobLvlLabel = nullptr;
- mJobLabel = nullptr;
- mJobBar = nullptr;
- place(3, 0, mMoneyLabel, 3);
- }
-
- place(0, 3, mTabs, 11, 3);
-
- getLayout().setRowHeight(3, LayoutType::SET);
-
- place(0, 5, mCopyButton);
-
- loadWindowState();
- enableVisibleSound(true);
-
- // Update bars
- updateHPBar(mHpBar, true);
- updateMPBar(mMpBar, true);
- updateXPBar(mXpBar, false);
-
- // TRANSLATORS: status window label
- mMoneyLabel->setCaption(strprintf(_("Money: %s"),
- UnitsDb::formatCurrency(PlayerInfo::getAttribute(
- Attributes::MONEY)).c_str()));
- mMoneyLabel->adjustSize();
-
- updateLevelLabel();
- addTabs();
-}
-
-StatusWindow::~StatusWindow()
-{
- delete2(mBasicStatsPage);
- delete_all(mPages);
-}
-
-void StatusWindow::addTabs()
-{
- // TRANSLATORS: status window tab name
- addTabBasic(_("Basic"));
- const STD_VECTOR<std::string> &pages = StatDb::getPages();
- FOR_EACH(STD_VECTOR<std::string>::const_iterator, it, pages)
- {
- addTab(*it);
- }
- mTabs->adjustSize();
-}
-
-void StatusWindow::addTab(const std::string &name)
-{
- StatsPage *const page = new StatsPage(this, name);
- mTabs->addTab(name,
- page);
- mPages.push_back(page);
-}
-
-void StatusWindow::addTabBasic(const std::string &name)
-{
- mTabs->addTab(name,
- mBasicStatsPage);
-}
-
-void StatusWindow::updateLevelLabel()
-{
- if (localPlayer == nullptr)
- return;
-
- const int groupId = localPlayer->getGroupId();
- const std::string &name = GroupDb::getName(groupId);
- if (!name.empty())
- {
- // TRANSLATORS: status window label
- mLvlLabel->setCaption(strprintf(_("Level: %d (%s %d)"),
- PlayerInfo::getAttribute(Attributes::PLAYER_BASE_LEVEL),
- name.c_str(),
- groupId));
- }
- else
- {
- // TRANSLATORS: status window label
- mLvlLabel->setCaption(strprintf(_("Level: %d"),
- PlayerInfo::getAttribute(Attributes::PLAYER_BASE_LEVEL)));
- }
- mLvlLabel->adjustSize();
-}
-
-void StatusWindow::attributeChanged(const AttributesT id,
- const int64_t oldVal,
- const int64_t newVal)
-{
- static bool blocked = false;
-
- PRAGMA45(GCC diagnostic push)
- PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
- switch (id)
- {
- case Attributes::PLAYER_HP:
- case Attributes::PLAYER_MAX_HP:
- updateHPBar(mHpBar, true);
- break;
-
- case Attributes::PLAYER_MP:
- case Attributes::PLAYER_MAX_MP:
- updateMPBar(mMpBar, true);
- break;
-
- case Attributes::PLAYER_EXP:
- case Attributes::PLAYER_EXP_NEEDED:
- updateXPBar(mXpBar, false);
- break;
-
- case Attributes::MONEY:
- // TRANSLATORS: status window label
- mMoneyLabel->setCaption(strprintf(_("Money: %s"),
- UnitsDb::formatCurrency64(newVal).c_str()));
- mMoneyLabel->adjustSize();
- break;
-
- case Attributes::PLAYER_BASE_LEVEL:
- // TRANSLATORS: status window label
- mLvlLabel->setCaption(strprintf(_("Level: %d"),
- CAST_S32(newVal)));
- mLvlLabel->adjustSize();
- break;
-
- // +++ probable need use only some attributes here
- case Attributes::PLAYER_JOB_LEVEL:
- case Attributes::PLAYER_JOB_EXP:
- case Attributes::PLAYER_JOB_EXP_NEEDED:
- if (blocked)
- return;
- if (mJobLvlLabel != nullptr)
- {
- int lvl = PlayerInfo::getAttribute(
- Attributes::PLAYER_JOB_LEVEL);
- const int64_t exp = PlayerInfo::getAttribute(
- Attributes::PLAYER_JOB_EXP);
- const int64_t expNeed = PlayerInfo::getAttribute(
- Attributes::PLAYER_JOB_EXP_NEEDED);
-
- if (lvl == 0)
- {
- // possible server broken and don't send job level,
- // then we fixing it.
- if (expNeed < 20000)
- {
- lvl = 0;
- }
- else
- {
- lvl = CAST_S32((expNeed - 20000) / 150);
- blocked = true;
- PlayerInfo::setAttribute(Attributes::PLAYER_JOB_LEVEL,
- lvl);
- blocked = false;
- }
- }
-
- if (id == Attributes::PLAYER_JOB_EXP &&
- exp < oldVal &&
- expNeed >= 20000)
- { // possible job level up. but server broken and don't send
- // new job exp limit, we fixing it
- lvl ++;
- blocked = true;
- PlayerInfo::setAttribute(Attributes::PLAYER_JOB_EXP_NEEDED,
- 20000 + lvl * 150);
- PlayerInfo::setAttribute(Attributes::PLAYER_JOB_LEVEL,
- lvl);
- blocked = false;
- }
-
- // TRANSLATORS: status window label
- mJobLvlLabel->setCaption(strprintf(_("Job: %d"), lvl));
- mJobLvlLabel->adjustSize();
-
- updateJobBar(mJobBar, false);
- }
- break;
-
- default:
- break;
- }
- PRAGMA45(GCC diagnostic pop)
-}
-
-void StatusWindow::setPointsNeeded(const AttributesT id,
- const int needed)
-{
- mBasicStatsPage->setPointsNeeded(id, needed);
-}
-
-void StatusWindow::updateHPBar(ProgressBar *const bar, const bool showMax)
-{
- if (bar == nullptr)
- return;
-
- const int hp = PlayerInfo::getAttribute(Attributes::PLAYER_HP);
- const int maxHp = PlayerInfo::getAttribute(Attributes::PLAYER_MAX_HP);
- if (showMax)
- bar->setText(toString(hp).append("/").append(toString(maxHp)));
- else
- bar->setText(toString(hp));
-
- float prog = 1.0;
- if (maxHp > 0)
- prog = static_cast<float>(hp) / static_cast<float>(maxHp);
- bar->setProgress(prog);
-}
-
-void StatusWindow::updateMPBar(ProgressBar *const bar,
- const bool showMax) const
-{
- if (bar == nullptr)
- return;
-
- const int mp = PlayerInfo::getAttribute(Attributes::PLAYER_MP);
- const int maxMp = PlayerInfo::getAttribute(Attributes::PLAYER_MAX_MP);
- if (showMax)
- bar->setText(toString(mp).append("/").append(toString(maxMp)));
- else
- bar->setText(toString(mp));
-
- float prog = 1.0F;
- if (maxMp > 0)
- prog = static_cast<float>(mp) / static_cast<float>(maxMp);
-
- if (playerHandler->canUseMagic())
- {
- bar->setColor(getThemeColor(ThemeColorId::MP_BAR),
- getThemeColor(ThemeColorId::MP_BAR_OUTLINE));
- bar->setProgressPalette(ProgressColorId::PROG_MP);
- }
- else
- {
- bar->setColor(getThemeColor(ThemeColorId::NO_MP_BAR),
- getThemeColor(ThemeColorId::NO_MP_BAR_OUTLINE));
- bar->setProgressPalette(ProgressColorId::PROG_NO_MP);
- }
-
- bar->setProgress(prog);
-}
-
-void StatusWindow::updateProgressBar(ProgressBar *const bar,
- const int64_t value,
- const int64_t max,
- const bool percent)
-{
- if (bar == nullptr)
- return;
-
- if (max == 0)
- {
- // TRANSLATORS: status bar label
- bar->setText(_("Max"));
- bar->setProgress(1);
- bar->setText(toString(CAST_U64(value)));
- }
- else
- {
- const float progress = static_cast<float>(value)
- / static_cast<float>(max);
- if (percent)
- {
- bar->setText(strprintf("%2.5f%%",
- static_cast<double>(100 * progress)));
- }
- else
- {
- bar->setText(toString(
- CAST_U64(value)).append(
- "/").append(toString(
- CAST_U64(max))));
- }
- bar->setProgress(progress);
- }
-}
-
-void StatusWindow::updateXPBar(ProgressBar *const bar, const bool percent)
-{
- if (bar == nullptr)
- return;
-
- updateProgressBar(bar,
- PlayerInfo::getAttribute(Attributes::PLAYER_EXP),
- PlayerInfo::getAttribute(Attributes::PLAYER_EXP_NEEDED),
- percent);
-}
-
-void StatusWindow::updateJobBar(ProgressBar *const bar, const bool percent)
-{
- if (bar == nullptr)
- return;
-
- updateProgressBar(bar,
- PlayerInfo::getAttribute(Attributes::PLAYER_JOB_EXP),
- PlayerInfo::getAttribute(Attributes::PLAYER_JOB_EXP_NEEDED),
- percent);
-}
-
-void StatusWindow::updateProgressBar(ProgressBar *const bar,
- const AttributesT id,
- const bool percent)
-{
- const std::pair<int, int> exp = PlayerInfo::getStatExperience(id);
- updateProgressBar(bar, exp.first, exp.second, percent);
-}
-
-void StatusWindow::updateWeightBar(ProgressBar *const bar)
-{
- if (bar == nullptr)
- return;
-
- if (PlayerInfo::getAttribute(Attributes::MAX_WEIGHT) == 0)
- {
- // TRANSLATORS: status bar label
- bar->setText(_("Max"));
- bar->setProgress(1.0);
- }
- else
- {
- const int totalWeight = PlayerInfo::getAttribute(
- Attributes::TOTAL_WEIGHT);
- const int maxWeight = PlayerInfo::getAttribute(Attributes::MAX_WEIGHT);
- float progress = 1.0F;
- if (maxWeight != 0)
- {
- progress = static_cast<float>(totalWeight)
- / static_cast<float>(maxWeight);
- }
- bar->setText(strprintf("%s/%s",
- UnitsDb::formatWeight(totalWeight).c_str(),
- UnitsDb::formatWeight(maxWeight).c_str()));
- bar->setProgress(progress);
- }
-}
-
-void StatusWindow::updateMoneyBar(ProgressBar *const bar)
-{
- if (bar == nullptr)
- return;
-
- const int money = PlayerInfo::getAttribute(Attributes::MONEY);
- bar->setText(UnitsDb::formatCurrency(money));
- if (money > 0)
- {
- const float progress = static_cast<float>(money)
- / static_cast<float>(1000000000);
- bar->setProgress(progress);
- }
- else
- {
- bar->setProgress(1.0);
- }
-}
-
-void StatusWindow::updateArrowsBar(ProgressBar *const bar)
-{
- if ((bar == nullptr) || (equipmentWindow == nullptr))
- return;
-
- const Item *const item = equipmentWindow->getEquipment(
- inventoryHandler->getProjectileSlot());
-
- if ((item != nullptr) && item->getQuantity() > 0)
- bar->setText(toString(item->getQuantity()));
- else
- bar->setText("0");
-}
-
-void StatusWindow::updateInvSlotsBar(ProgressBar *const bar)
-{
- if (bar == nullptr)
- return;
-
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- return;
-
- const int usedSlots = inv->getNumberOfSlotsUsed();
- const int maxSlots = inv->getSize();
-
- if (maxSlots != 0)
- {
- bar->setProgress(static_cast<float>(usedSlots)
- / static_cast<float>(maxSlots));
- }
-
- bar->setText(strprintf("%d", usedSlots));
-}
-
-std::string StatusWindow::translateLetter(const char *const letters)
-{
- char buf[2];
- char *const str = gettext(letters);
- if ((str == nullptr) || strlen(str) != 3)
- return letters;
-
- buf[0] = str[1];
- buf[1] = 0;
- return std::string(buf);
-}
-
-std::string StatusWindow::translateLetter2(const std::string &letters)
-{
- if (letters.size() < 5)
- return "";
-
- return std::string(gettext(letters.substr(1, 1).c_str()));
-}
-
-void StatusWindow::updateStatusBar(ProgressBar *const bar,
- const bool percent A_UNUSED) const
-{
- if (bar == nullptr)
- return;
- bar->setText(translateLetter2(GameModifiers::getMoveTypeString())
- .append(translateLetter2(GameModifiers::getCrazyMoveTypeString()))
- .append(translateLetter2(GameModifiers::getMoveToTargetTypeString()))
- .append(translateLetter2(GameModifiers::getFollowModeString()))
- .append(" ").append(translateLetter2(
- GameModifiers::getAttackWeaponTypeString()))
- .append(translateLetter2(GameModifiers::getAttackTypeString()))
- .append(translateLetter2(GameModifiers::getMagicAttackTypeString()))
- .append(translateLetter2(GameModifiers::getPvpAttackTypeString()))
- .append(" ").append(translateLetter2(
- GameModifiers::getQuickDropCounterString()))
- .append(translateLetter2(GameModifiers::getPickUpTypeString()))
- .append(" ").append(translateLetter2(
- GameModifiers::getMapDrawTypeString()))
- .append(" ").append(translateLetter2(
- GameModifiers::getImitationModeString()))
- .append(translateLetter2(GameModifiers::getCameraModeString()))
- .append(translateLetter2(GameModifiers::getAwayModeString()))
- .append(translateLetter2(GameModifiers::getTargetingTypeString())));
-
- bar->setProgress(50);
- if (settings.disableGameModifiers)
- bar->setBackgroundColor(getThemeColor(ThemeColorId::STATUSBAR_ON));
- else
- bar->setBackgroundColor(getThemeColor(ThemeColorId::STATUSBAR_OFF));
-}
-
-void StatusWindow::action(const ActionEvent &event)
-{
- if (chatWindow == nullptr)
- return;
-
- if (event.getId() == "copy")
- {
- chatWindow->addInputText(mBasicStatsPage->getStatsStr());
- }
-}
diff --git a/src/gui/windows/statuswindow.h b/src/gui/windows/statuswindow.h
deleted file mode 100644
index 233840d17..000000000
--- a/src/gui/windows/statuswindow.h
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_STATUSWINDOW_H
-#define GUI_WINDOWS_STATUSWINDOW_H
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/attributelistener.h"
-
-class Button;
-class Label;
-class ProgressBar;
-class StatsPage;
-class StatsPageBasic;
-class TabbedArea;
-
-/**
- * The player status dialog.
- *
- * \ingroup Interface
- */
-class StatusWindow final : public Window,
- public ActionListener,
- public AttributeListener
-{
- public:
- /**
- * Constructor.
- */
- StatusWindow();
-
- A_DELETE_COPY(StatusWindow)
-
- ~StatusWindow();
-
- void setPointsNeeded(const AttributesT id,
- const int needed);
-
- static void updateHPBar(ProgressBar *const bar,
- const bool showMax = false);
- void updateMPBar(ProgressBar *bar, const bool showMax = false) const;
- static void updateJobBar(ProgressBar *const bar,
- const bool percent = true);
- static void updateXPBar(ProgressBar *const bar,
- const bool percent = true);
- static void updateWeightBar(ProgressBar *const bar);
- static void updateInvSlotsBar(ProgressBar *const bar);
- static void updateMoneyBar(ProgressBar *const bar);
- static void updateArrowsBar(ProgressBar *const bar);
- void updateStatusBar(ProgressBar *const bar,
- const bool percent = true) const;
- static void updateProgressBar(ProgressBar *const bar,
- const int64_t value,
- const int64_t max,
- const bool percent);
- static void updateProgressBar(ProgressBar *const bar,
- const AttributesT id,
- const bool percent = true);
-
- void action(const ActionEvent &event) override;
-
- void attributeChanged(const AttributesT id,
- const int64_t oldVal,
- const int64_t newVal) override final;
-
- void updateLevelLabel();
-
- private:
- void addTabs();
- void addTab(const std::string &name);
- void addTabBasic(const std::string &name);
-
- static std::string translateLetter(const char *const letters);
- static std::string translateLetter2(const std::string &letters);
-
- STD_VECTOR<StatsPage*> mPages;
-
- TabbedArea *mTabs A_NONNULLPOINTER;
- Label *mLvlLabel A_NONNULLPOINTER;
- Label *mMoneyLabel A_NONNULLPOINTER;
- Label *mHpLabel A_NONNULLPOINTER;
- Label *mMpLabel A_NONNULLPOINTER;
- Label *mXpLabel A_NONNULLPOINTER;
- ProgressBar *mHpBar A_NONNULLPOINTER;
- ProgressBar *mMpBar A_NONNULLPOINTER;
- ProgressBar *mXpBar A_NONNULLPOINTER;
-
- Label *mJobLvlLabel;
- Label *mJobLabel;
- ProgressBar *mJobBar;
-
- StatsPageBasic *mBasicStatsPage;
- Button *mCopyButton;
-};
-
-extern StatusWindow *statusWindow;
-
-#endif // GUI_WINDOWS_STATUSWINDOW_H
diff --git a/src/gui/windows/textcommandeditor.cpp b/src/gui/windows/textcommandeditor.cpp
deleted file mode 100644
index 88d88af8a..000000000
--- a/src/gui/windows/textcommandeditor.cpp
+++ /dev/null
@@ -1,344 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/textcommandeditor.h"
-
-#include "spellmanager.h"
-#include "textcommand.h"
-
-#include "input/keyboardconfig.h"
-
-#include "gui/models/iconsmodel.h"
-#include "gui/models/targettypemodel.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/dropdown.h"
-#include "gui/widgets/inttextfield.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layoutcell.h"
-
-#ifdef TMWA_SUPPORT
-#include "gui/models/magicschoolmodel.h"
-
-#include "gui/widgets/radiobutton.h"
-#endif // TMWA_SUPPORT
-
-#include "utils/delete2.h"
-
-#include "debug.h"
-
-#ifdef TMWA_SUPPORT
-const unsigned int MAGIC_START_ID = 340;
-#endif // TMWA_SUPPORT
-
-TextCommandEditor::TextCommandEditor(TextCommand *const command) :
- // TRANSLATORS: command editor name
- Window(_("Command Editor"), Modal_false, nullptr, "commandeditor.xml"),
- ActionListener(),
-#ifdef TMWA_SUPPORT
- mIsMagicCommand(command != nullptr ?
- (command->getCommandType() == TextCommandType::Magic) : false),
-#endif // TMWA_SUPPORT
- mCommand(command),
-#ifdef TMWA_SUPPORT
- // TRANSLATORS: command editor button
- mIsMagic(new RadioButton(this, _("magic"), "magic", mIsMagicCommand)),
- // TRANSLATORS: command editor button
- mIsOther(new RadioButton(this, _("other"), "magic", !mIsMagicCommand)),
-#endif // TMWA_SUPPORT
- // TRANSLATORS: command editor label
- mSymbolLabel(new Label(this, _("Symbol:"))),
- mSymbolTextField(new TextField(this)),
- // TRANSLATORS: command editor label
- mCommandLabel(new Label(this, _("Command:"))),
- mCommandTextField(new TextField(this)),
- // TRANSLATORS: command editor label
- mCommentLabel(new Label(this, _("Comment:"))),
- mCommentTextField(new TextField(this)),
- mTargetTypeModel(new TargetTypeModel),
- // TRANSLATORS: command editor label
- mTypeLabel(new Label(this, _("Target Type:"))),
- mTypeDropDown(new DropDown(this, mTargetTypeModel)),
- mIconsModel(new IconsModel),
- // TRANSLATORS: command editor label
- mIconLabel(new Label(this, _("Icon:"))),
- mIconDropDown(new DropDown(this, mIconsModel)),
-#ifdef TMWA_SUPPORT
- // TRANSLATORS: command editor label
- mManaLabel(new Label(this, _("Mana:"))),
- mManaField(new IntTextField(this, 0)),
- // TRANSLATORS: command editor label
- mMagicLvlLabel(new Label(this, _("Magic level:"))),
- mMagicLvlField(new IntTextField(this, 0)),
- mMagicSchoolModel(new MagicSchoolModel),
- // TRANSLATORS: command editor label
- mSchoolLabel(new Label(this, _("Magic School:"))),
- mSchoolDropDown(new DropDown(this, mMagicSchoolModel)),
- // TRANSLATORS: command editor label
- mSchoolLvlLabel(new Label(this, _("School level:"))),
- mSchoolLvlField(new IntTextField(this, 0)),
-#endif // TMWA_SUPPORT
- // TRANSLATORS: command editor button
- mCancelButton(new Button(this, _("Cancel"), "cancel", this)),
- // TRANSLATORS: command editor button
- mSaveButton(new Button(this, _("Save"), "save", this)),
- // TRANSLATORS: command editor button
- mDeleteButton(new Button(this, _("Delete"), "delete", this)),
- mEnabledKeyboard(keyboard.isEnabled())
-{
- const int w = 350;
- const int h = 370;
-
- keyboard.setEnabled(false);
-
- setWindowName("TextCommandEditor");
- setDefaultSize(w, h, ImagePosition::CENTER);
-
-#ifdef TMWA_SUPPORT
- mIsMagic->setActionEventId("magic");
- mIsMagic->addActionListener(this);
-
- mIsOther->setActionEventId("other");
- mIsOther->addActionListener(this);
-
- mManaField->setRange(0, 500);
- mManaField->setWidth(20);
-
- mMagicLvlField->setRange(0, 5);
- mMagicLvlField->setWidth(20);
-
- mSchoolDropDown->setActionEventId("school");
- mSchoolDropDown->addActionListener(this);
- mSchoolDropDown->setSelected(0);
-
- mSchoolLvlField->setRange(0, 5);
- mSchoolLvlField->setWidth(20);
-#endif // TMWA_SUPPORT
-
- mTypeDropDown->setActionEventId("type");
- mTypeDropDown->addActionListener(this);
-
- mIconDropDown->setActionEventId("icon");
- mIconDropDown->addActionListener(this);
- if (mCommand != nullptr)
- mIconDropDown->setSelectedString(mCommand->getIcon());
-
- mSaveButton->adjustSize();
- mCancelButton->adjustSize();
- mDeleteButton->adjustSize();
-
- if (command != nullptr)
- {
-#ifdef TMWA_SUPPORT
- if (command->getCommandType() == TextCommandType::Magic)
- showControls(Visible_true);
- else
- showControls(Visible_false);
-
- mManaField->setValue(command->getMana());
- mMagicLvlField->setValue(command->getBaseLvl());
- mSchoolDropDown->setSelected(CAST_S32(command->getSchool())
- - MAGIC_START_ID);
- mSchoolLvlField->setValue(command->getSchoolLvl());
-#endif // TMWA_SUPPORT
- }
-
- ContainerPlacer placer;
- placer = getPlacer(0, 0);
-
-#ifdef TMWA_SUPPORT
- placer(0, 0, mIsMagic, 1);
- placer(2, 0, mIsOther, 1);
- placer(0, 1, mSymbolLabel, 2).setPadding(3);
- placer(2, 1, mSymbolTextField, 3).setPadding(3);
- placer(0, 2, mCommandLabel, 2).setPadding(3);
- placer(2, 2, mCommandTextField, 4).setPadding(3);
-
- placer(0, 3, mCommentLabel, 2).setPadding(3);
- placer(2, 3, mCommentTextField, 4).setPadding(3);
-
- placer(0, 4, mTypeLabel, 2).setPadding(3);
- placer(2, 4, mTypeDropDown, 3).setPadding(3);
-
- placer(0, 5, mIconLabel, 2).setPadding(3);
- placer(2, 5, mIconDropDown, 3).setPadding(3);
-
- placer(0, 6, mManaLabel, 2).setPadding(3);
- placer(2, 6, mManaField, 3).setPadding(3);
- placer(0, 7, mMagicLvlLabel, 2).setPadding(3);
- placer(2, 7, mMagicLvlField, 3).setPadding(3);
-
- placer(0, 8, mSchoolLabel, 2).setPadding(3);
- placer(2, 8, mSchoolDropDown, 3).setPadding(3);
- placer(0, 9, mSchoolLvlLabel, 2).setPadding(3);
- placer(2, 9, mSchoolLvlField, 3).setPadding(3);
-
- placer(0, 10, mSaveButton, 2).setPadding(3);
- placer(2, 10, mCancelButton, 2).setPadding(3);
- placer(4, 10, mDeleteButton, 2).setPadding(3);
-#else // TMWA_SUPPORT
-
- placer(0, 0, mSymbolLabel, 2).setPadding(3);
- placer(2, 0, mSymbolTextField, 3).setPadding(3);
- placer(0, 1, mCommandLabel, 2).setPadding(3);
- placer(2, 1, mCommandTextField, 4).setPadding(3);
-
- placer(0, 2, mCommentLabel, 2).setPadding(3);
- placer(2, 2, mCommentTextField, 4).setPadding(3);
-
- placer(0, 3, mTypeLabel, 2).setPadding(3);
- placer(2, 3, mTypeDropDown, 3).setPadding(3);
-
- placer(0, 4, mIconLabel, 2).setPadding(3);
- placer(2, 4, mIconDropDown, 3).setPadding(3);
-
- placer(0, 5, mSaveButton, 2).setPadding(3);
- placer(2, 5, mCancelButton, 2).setPadding(3);
- placer(4, 5, mDeleteButton, 2).setPadding(3);
-#endif // TMWA_SUPPORT
-
- setWidth(w);
- setHeight(h);
-
- reflowLayout(w);
-
- center();
-}
-
-void TextCommandEditor::postInit()
-{
- Window::postInit();
- enableVisibleSound(true);
- setVisible(Visible_true);
-}
-
-TextCommandEditor::~TextCommandEditor()
-{
- delete2(mIconsModel);
- delete2(mTargetTypeModel);
-#ifdef TMWA_SUPPORT
- delete2(mMagicSchoolModel);
-#endif // TMWA_SUPPORT
-}
-
-void TextCommandEditor::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "save")
- {
- save();
- scheduleDelete();
- }
- else if (eventId == "cancel")
- {
- scheduleDelete();
- }
- else if (eventId == "delete")
- {
- deleteCommand();
- scheduleDelete();
- }
-#ifdef TMWA_SUPPORT
- else if (eventId == "magic")
- {
- mIsMagicCommand = true;
- showControls(Visible_true);
- }
- else if (eventId == "other")
- {
- mIsMagicCommand = false;
- showControls(Visible_false);
- }
-#endif // TMWA_SUPPORT
-}
-
-#ifdef TMWA_SUPPORT
-void TextCommandEditor::showControls(const Visible show)
-{
- mManaField->setVisible(show);
- mManaLabel->setVisible(show);
- mMagicLvlLabel->setVisible(show);
- mMagicLvlField->setVisible(show);
- mSchoolLabel->setVisible(show);
- mSchoolDropDown->setVisible(show);
- mSchoolLvlLabel->setVisible(show);
- mSchoolLvlField->setVisible(show);
-}
-#endif // TMWA_SUPPORT
-
-void TextCommandEditor::scheduleDelete()
-{
- keyboard.setEnabled(mEnabledKeyboard);
- Window::scheduleDelete();
-}
-
-void TextCommandEditor::save()
-{
- if (mCommand == nullptr)
- return;
-#ifdef TMWA_SUPPORT
- if (mIsMagicCommand)
- mCommand->setCommandType(TextCommandType::Magic);
- else
- mCommand->setCommandType(TextCommandType::Text);
-#endif // TMWA_SUPPORT
-
- mCommand->setSymbol(mSymbolTextField->getText());
- mCommand->setCommand(mCommandTextField->getText());
- mCommand->setComment(mCommentTextField->getText());
- mCommand->setTargetType(
- static_cast<CommandTargetT>(mTypeDropDown->getSelected()));
- mCommand->setIcon(mIconDropDown->getSelectedString());
-
-#ifdef TMWA_SUPPORT
- mCommand->setMana(mManaField->getValue());
- mCommand->setBaseLvl(mMagicLvlField->getValue());
- mCommand->setSchool(static_cast<MagicSchoolT>(
- mSchoolDropDown->getSelected() + MAGIC_START_ID));
- mCommand->setSchoolLvl(mSchoolLvlField->getValue());
-#endif // TMWA_SUPPORT
-
- if (spellManager != nullptr)
- spellManager->save();
-}
-
-void TextCommandEditor::deleteCommand()
-{
- if (mCommand == nullptr)
- return;
- mCommand->setSymbol("");
- mCommand->setCommand("");
- mCommand->setComment("");
- mCommand->setTargetType(CommandTarget::NoTarget);
- mCommand->setIcon("");
-#ifdef TMWA_SUPPORT
- mCommand->setCommandType(TextCommandType::Text);
- mCommand->setMana(0);
- mCommand->setBaseLvl(0);
- mCommand->setSchool(MagicSchool::SkillMagic);
- mCommand->setSchoolLvl(0);
-#endif // TMWA_SUPPORT
-
- if (spellManager != nullptr)
- spellManager->save();
-}
diff --git a/src/gui/windows/textcommandeditor.h b/src/gui/windows/textcommandeditor.h
deleted file mode 100644
index 88bfd48d4..000000000
--- a/src/gui/windows/textcommandeditor.h
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_TEXTCOMMANDEDITOR_H
-#define GUI_WINDOWS_TEXTCOMMANDEDITOR_H
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-
-class Button;
-class DropDown;
-class IconsModel;
-class IntTextField;
-class Label;
-#ifdef TMWA_SUPPORT
-class MagicSchoolModel;
-#endif // TMWA_SUPPORT
-
-class RadioButton;
-class TargetTypeModel;
-class TextCommand;
-class TextField;
-
-class TextCommandEditor final : public Window,
- public ActionListener
-{
- public:
- /**
- * Constructor.
- */
- explicit TextCommandEditor(TextCommand *const command);
-
- A_DELETE_COPY(TextCommandEditor)
-
- /**
- * Destructor.
- */
- ~TextCommandEditor();
-
- void postInit() override final;
-
- void action(const ActionEvent &event) override final;
-
- void scheduleDelete() override final;
-
- private:
-#ifdef TMWA_SUPPORT
- void showControls(const Visible show);
-#endif // TMWA_SUPPORT
-
- void save();
-
- void deleteCommand();
-
-#ifdef TMWA_SUPPORT
- bool mIsMagicCommand;
-#endif // TMWA_SUPPORT
-
- TextCommand* mCommand;
-#ifdef TMWA_SUPPORT
- RadioButton* mIsMagic A_NONNULLPOINTER;
-#endif // TMWA_SUPPORT
-
- RadioButton* mIsOther A_NONNULLPOINTER;
- Label* mSymbolLabel A_NONNULLPOINTER;
- TextField* mSymbolTextField A_NONNULLPOINTER;
- Label* mCommandLabel A_NONNULLPOINTER;
- TextField* mCommandTextField A_NONNULLPOINTER;
- Label* mCommentLabel A_NONNULLPOINTER;
- TextField* mCommentTextField A_NONNULLPOINTER;
- TargetTypeModel* mTargetTypeModel A_NONNULLPOINTER;
- Label* mTypeLabel A_NONNULLPOINTER;
- DropDown* mTypeDropDown A_NONNULLPOINTER;
- IconsModel* mIconsModel A_NONNULLPOINTER;
- Label* mIconLabel A_NONNULLPOINTER;
- DropDown* mIconDropDown A_NONNULLPOINTER;
-#ifdef TMWA_SUPPORT
- Label* mManaLabel A_NONNULLPOINTER;
- IntTextField* mManaField A_NONNULLPOINTER;
- Label* mMagicLvlLabel A_NONNULLPOINTER;
- IntTextField* mMagicLvlField A_NONNULLPOINTER;
- MagicSchoolModel* mMagicSchoolModel A_NONNULLPOINTER;
- Label* mSchoolLabel A_NONNULLPOINTER;
- DropDown* mSchoolDropDown A_NONNULLPOINTER;
- Label* mSchoolLvlLabel A_NONNULLPOINTER;
- IntTextField* mSchoolLvlField A_NONNULLPOINTER;
-#endif // TMWA_SUPPORT
-
- Button* mCancelButton A_NONNULLPOINTER;
- Button* mSaveButton A_NONNULLPOINTER;
- Button* mDeleteButton A_NONNULLPOINTER;
-
- bool mEnabledKeyboard;
-};
-
-#endif // GUI_WINDOWS_TEXTCOMMANDEDITOR_H
diff --git a/src/gui/windows/textdialog.cpp b/src/gui/windows/textdialog.cpp
deleted file mode 100644
index 87c9dcfa8..000000000
--- a/src/gui/windows/textdialog.cpp
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/textdialog.h"
-
-#include "input/keyboardconfig.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/passwordfield.h"
-
-#include "utils/gettext.h"
-
-#include "gui/fonts/font.h"
-
-#include "debug.h"
-
-int TextDialog::instances = 0;
-
-namespace
-{
- const std::string emptyStr;
-} // namespace
-
-TextDialog::TextDialog(const std::string &restrict title,
- const std::string &restrict msg,
- Window *const parent,
- const bool isPassword) :
- Window(title, Modal_true, parent, "textdialog.xml"),
- ActionListener(),
- mTextField(nullptr),
- mPasswordField(nullptr),
- // TRANSLATORS: text dialog button
- mOkButton(new Button(this, _("OK"), "OK", this)),
- mEnabledKeyboard(keyboard.isEnabled())
-{
- keyboard.setEnabled(false);
-
- Label *const textLabel = new Label(this, msg);
- // TRANSLATORS: text dialog button
- Button *const cancelButton = new Button(this, _("Cancel"), "CANCEL", this);
-
- place(0, 0, textLabel, 4);
- if (isPassword)
- {
- mPasswordField = new PasswordField(this);
- place(0, 1, mPasswordField, 4);
- }
- else
- {
- mTextField = new TextField(this);
- place(0, 1, mTextField, 4);
- }
- place(2, 2, mOkButton);
- place(3, 2, cancelButton);
-
- int width = getFont()->getWidth(title);
- if (width < textLabel->getWidth())
- width = textLabel->getWidth();
- reflowLayout(CAST_S32(width + 20));
-}
-
-void TextDialog::postInit()
-{
- Window::postInit();
- if (getParent() != nullptr)
- {
- setLocationRelativeTo(getParent());
- getParent()->moveToTop(this);
- }
- setVisible(Visible_true);
- requestModalFocus();
- if (mPasswordField != nullptr)
- mPasswordField->requestFocus();
- else if (mTextField != nullptr)
- mTextField->requestFocus();
-
- instances++;
-}
-
-TextDialog::~TextDialog()
-{
- instances--;
-}
-
-void TextDialog::action(const ActionEvent &event)
-{
- if (event.getId() == "CANCEL")
- setActionEventId("~" + getActionEventId());
-
- distributeActionEvent();
- close();
-}
-
-const std::string &TextDialog::getText() const
-{
- if (mTextField != nullptr)
- return mTextField->getText();
- else if (mPasswordField != nullptr)
- return mPasswordField->getText();
- return emptyStr;
-}
-
-void TextDialog::setText(const std::string &text)
-{
- if (mTextField != nullptr)
- mTextField->setText(text);
- else if (mPasswordField != nullptr)
- mPasswordField->setText(text);
-}
-
-void TextDialog::close()
-{
- keyboard.setEnabled(mEnabledKeyboard);
- scheduleDelete();
-}
diff --git a/src/gui/windows/textdialog.h b/src/gui/windows/textdialog.h
deleted file mode 100644
index a2901e04e..000000000
--- a/src/gui/windows/textdialog.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_TEXTDIALOG_H
-#define GUI_WINDOWS_TEXTDIALOG_H
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-
-class Button;
-class PasswordField;
-class TextField;
-
-/**
-* An option dialog.
- *
- * \ingroup GUI
- */
-class TextDialog final : public Window,
- public ActionListener
-{
- public:
- /**
- * Constructor.
- *
- * @see Window::Window
- */
- TextDialog(const std::string &restrict title,
- const std::string &restrict msg,
- Window *const parent = nullptr,
- const bool isPassword = false);
-
- A_DELETE_COPY(TextDialog)
-
- ~TextDialog();
-
- void postInit() override final;
-
- /**
- * Called when receiving actions from the widgets.
- */
- void action(const ActionEvent &event) override final;
-
- /**
- * Get the text in the textfield
- */
- const std::string &getText() const A_WARN_UNUSED;
-
- void setText(const std::string &text);
-
- static bool isActive() noexcept2 A_WARN_UNUSED
- { return instances != 0; }
-
- void close() override final;
-
- private:
- static int instances;
-
- TextField *mTextField;
- PasswordField *mPasswordField;
- Button *mOkButton;
- bool mEnabledKeyboard;
-};
-
-#endif // GUI_WINDOWS_TEXTDIALOG_H
diff --git a/src/gui/windows/textselectdialog.cpp b/src/gui/windows/textselectdialog.cpp
deleted file mode 100644
index 11100d2d8..000000000
--- a/src/gui/windows/textselectdialog.cpp
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/textselectdialog.h"
-
-#include "enums/gui/layouttype.h"
-
-#include "gui/windows/setupwindow.h"
-
-#include "gui/models/namesmodel.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/layout.h"
-#include "gui/widgets/listbox.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-TextSelectDialog::TextSelectDialog(const std::string &name,
- const std::string &selectButton,
- const AllowQuit allowQuit) :
- // TRANSLATORS: sell dialog name
- Window(name, Modal_false, nullptr, "sell.xml"),
- ActionListener(),
- SelectionListener(),
- mSelectButtonName(selectButton),
- mText(),
- mSelectButton(nullptr),
- mQuitButton(nullptr),
- mItemList(nullptr),
- mScrollArea(nullptr),
- mModel(nullptr),
- mAllowQuit(allowQuit),
- mTag(0)
-{
-}
-
-void TextSelectDialog::postInit()
-{
- Window::postInit();
- setWindowName("TextSelectDialog");
- setResizable(true);
- setCloseButton(mAllowQuit == AllowQuit_true);
- setStickyButtonLock(true);
- setMinWidth(260);
- setMinHeight(220);
- setDefaultSize(260, 230, ImagePosition::CENTER);
-
- if (setupWindow != nullptr)
- setupWindow->registerWindowForReset(this);
-
- setActionEventId("OK");
- mModel = new NamesModel;
- mItemList = CREATEWIDGETR(ListBox,
- this,
- mModel,
- "listbox.xml");
- mScrollArea = new ScrollArea(this, mItemList,
- fromBool(getOptionBool("showbackground"), Opaque),
- "sell_background.xml");
- mScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
-
- mSelectButton = new Button(this,
- mSelectButtonName,
- "select",
- this);
- if (mAllowQuit == AllowQuit_true)
- {
- // TRANSLATORS: sell dialog button
- mQuitButton = new Button(this, _("Quit"), "quit", this);
- }
-
- mSelectButton->setEnabled(false);
-
- mItemList->setDistributeMousePressed(false);
- mItemList->addSelectionListener(this);
- mItemList->setActionEventId("item");
- mItemList->addActionListener(this);
-
- ContainerPlacer placer;
- placer = getPlacer(0, 0);
-
- placer(0, 0, mScrollArea, 8, 5).setPadding(3);
- if (mQuitButton != nullptr)
- {
- placer(6, 5, mSelectButton);
- placer(7, 5, mQuitButton);
- }
- else
- {
- placer(7, 5, mSelectButton);
- }
-
- Layout &layout = getLayout();
- layout.setRowHeight(0, LayoutType::SET);
-
- center();
- loadWindowState();
-
- setVisible(Visible_true);
- enableVisibleSound(true);
-}
-
-TextSelectDialog::~TextSelectDialog()
-{
- delete2(mModel);
-}
-
-void TextSelectDialog::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
-
- if (eventId == "quit")
- {
- close();
- return;
- }
-
- const int selectedItem = mItemList->getSelected();
-
- // The following actions require a valid item selection
- if (selectedItem == -1 ||
- selectedItem >= mModel->getNumberOfElements())
- {
- return;
- }
- else if (eventId == "select")
- {
- const int index = mItemList->getSelected();
- if (index < 0 || index >= CAST_S32(mModel->size()))
- return;
- mText = mModel->getElementAt(index);
- distributeActionEvent();
- close();
- }
-}
-
-void TextSelectDialog::updateButtonsAndLabels()
-{
- mSelectButton->setEnabled(mItemList->getSelected() > -1);
-}
-
-void TextSelectDialog::valueChanged(const SelectionEvent &event A_UNUSED)
-{
- updateButtonsAndLabels();
-}
-
-void TextSelectDialog::setVisible(Visible visible)
-{
- Window::setVisible(visible);
-
- if (visible == Visible_true)
- {
- if (mItemList != nullptr)
- mItemList->requestFocus();
- }
- else
- {
- scheduleDelete();
- }
-}
-
-void TextSelectDialog::addText(const std::string &text)
-{
- if (text.empty())
- return;
- mModel->add(text);
-}
diff --git a/src/gui/windows/textselectdialog.h b/src/gui/windows/textselectdialog.h
deleted file mode 100644
index 30e596d32..000000000
--- a/src/gui/windows/textselectdialog.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_TEXTSELECTDIALOG_H
-#define GUI_WINDOWS_TEXTSELECTDIALOG_H
-
-#include "gui/widgets/window.h"
-
-#include "enums/simpletypes/allowquit.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/selectionlistener.h"
-
-class Button;
-class ScrollArea;
-class NamesModel;
-class ListBox;
-
-class TextSelectDialog notfinal : public Window,
- public ActionListener,
- private SelectionListener
-{
- public:
- /**
- * Constructor.
- */
- TextSelectDialog(const std::string &name,
- const std::string &selectButton,
- const AllowQuit allowQuit);
-
- A_DELETE_COPY(TextSelectDialog)
-
- /**
- * Destructor
- */
- ~TextSelectDialog();
-
- /**
- * Called when receiving actions from the widgets.
- */
- void action(const ActionEvent &event) override final;
-
- /**
- * Updates labels according to selected item.
- *
- * @see SelectionListener::selectionChanged
- */
- void valueChanged(const SelectionEvent &event) override final;
-
- /**
- * Sets the visibility of this window.
- */
- void setVisible(Visible visible) override final;
-
- void postInit() override;
-
- void addText(const std::string &text);
-
- std::string getText() const noexcept2 A_WARN_UNUSED
- { return mText; }
-
- void setTag(const int tag) noexcept2
- { mTag = tag; }
-
- int getTag() const noexcept2 A_WARN_UNUSED
- { return mTag; }
-
- protected:
- /**
- * Updates the state of buttons and labels.
- */
- void updateButtonsAndLabels();
-
- std::string mSelectButtonName;
- std::string mText;
- Button *mSelectButton A_NONNULLPOINTER;
- Button *mQuitButton A_NONNULLPOINTER;
- ListBox *mItemList A_NONNULLPOINTER;
- ScrollArea *mScrollArea A_NONNULLPOINTER;
- NamesModel *mModel A_NONNULLPOINTER;
- AllowQuit mAllowQuit;
- int mTag;
-};
-
-#endif // GUI_WINDOWS_TEXTSELECTDIALOG_H
diff --git a/src/gui/windows/tradewindow.cpp b/src/gui/windows/tradewindow.cpp
deleted file mode 100644
index 66f4e0550..000000000
--- a/src/gui/windows/tradewindow.cpp
+++ /dev/null
@@ -1,553 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/tradewindow.h"
-
-#include "configuration.h"
-#include "game.h"
-
-#include "being/localplayer.h"
-#include "being/playerinfo.h"
-#include "being/playerrelations.h"
-
-#include "enums/gui/layouttype.h"
-
-#include "gui/gui.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/windows/inventorywindow.h"
-#include "gui/windows/itemamountwindow.h"
-#include "gui/windows/setupwindow.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/itemcontainer.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layout.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/textfield.h"
-
-#include "gui/widgets/tabs/chat/chattab.h"
-
-#include "resources/db/unitsdb.h"
-
-#include "resources/item/item.h"
-
-#include "net/net.h"
-#include "net/tradehandler.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-TradeWindow *tradeWindow = nullptr;
-
-// TRANSLATORS: trade window button
-#define CAPTION_PROPOSE _("Propose trade")
-// TRANSLATORS: trade window button
-#define CAPTION_CONFIRMED _("Confirmed. Waiting...")
-// TRANSLATORS: trade window button
-#define CAPTION_ACCEPT _("Agree trade")
-// TRANSLATORS: trade window button
-#define CAPTION_ACCEPTED _("Agreed. Waiting...")
-
-TradeWindow::TradeWindow() :
- // TRANSLATORS: trade window caption
- Window(_("Trade: You"), Modal_false, nullptr, "trade.xml"),
- ActionListener(),
- SelectionListener(),
- mMyInventory(new Inventory(InventoryType::Trade)),
- mPartnerInventory(new Inventory(InventoryType::Trade)),
- mMyItemContainer(new ItemContainer(this, mMyInventory)),
- mPartnerItemContainer(new ItemContainer(this, mPartnerInventory)),
- // TRANSLATORS: trade window money label
- mMoneyLabel(new Label(this, strprintf(_("You get %s"), ""))),
- // TRANSLATORS: trade window button
- mAddButton(new Button(this, _("Add"), "add", this)),
- mOkButton(new Button(this, "", "", this)), // Will be filled in later
- // TRANSLATORS: trade window money change button
- mMoneyChangeButton(new Button(this, _("Change"), "money", this)),
- mMoneyField(new TextField(this)),
- mAutoAddItem(nullptr),
- mAutoAddToNick(""),
- mGotMoney(0),
- mGotMaxMoney(0),
- mAutoMoney(0),
- mAutoAddAmount(0),
- mStatus(PROPOSING),
- mOkOther(false),
- mOkMe(false)
-{
- setWindowName("Trade");
- setResizable(true);
- setCloseButton(true);
- setStickyButtonLock(true);
- setDefaultSize(386, 180, ImagePosition::CENTER);
- setMinWidth(310);
- setMinHeight(180);
-
- if (setupWindow != nullptr)
- setupWindow->registerWindowForReset(this);
-
- const Font *const fnt = mOkButton->getFont();
- int width = std::max(fnt->getWidth(CAPTION_PROPOSE),
- fnt->getWidth(CAPTION_CONFIRMED));
- width = std::max(width, fnt->getWidth(CAPTION_ACCEPT));
- width = std::max(width, fnt->getWidth(CAPTION_ACCEPTED));
-
- mOkButton->setWidth(8 + width);
-
- mMyItemContainer->addSelectionListener(this);
-
- ScrollArea *const myScroll = new ScrollArea(this, mMyItemContainer,
- Opaque_true, "trade_background.xml");
- myScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
-
- mPartnerItemContainer->addSelectionListener(this);
-
- ScrollArea *const partnerScroll = new ScrollArea(this,
- mPartnerItemContainer,
- Opaque_true, "trade_background.xml");
- partnerScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
-
- // TRANSLATORS: trade window money label
- Label *const moneyLabel2 = new Label(this, _("You give:"));
-
- mMoneyField->setWidth(40);
-
- place(1, 0, mMoneyLabel);
- place(0, 1, myScroll).setPadding(3);
- place(1, 1, partnerScroll).setPadding(3);
- ContainerPlacer placer = getPlacer(0, 0);
- placer(0, 0, moneyLabel2);
- placer(1, 0, mMoneyField, 2);
- placer(3, 0, mMoneyChangeButton).setHAlign(LayoutCell::LEFT);
- placer = getPlacer(0, 2);
- placer(0, 0, mAddButton);
- placer(1, 0, mOkButton);
- Layout &layout = getLayout();
- layout.extend(0, 2, 2, 1);
- layout.setRowHeight(1, LayoutType::SET);
- layout.setRowHeight(2, 0);
- layout.setColWidth(0, LayoutType::SET);
- layout.setColWidth(1, LayoutType::SET);
-
- loadWindowState();
- enableVisibleSound(true);
-
- reset();
-}
-
-TradeWindow::~TradeWindow()
-{
- delete2(mMyInventory);
- delete2(mPartnerInventory);
-}
-
-void TradeWindow::setMoney(const int amount)
-{
- if (amount < 0 || amount < mGotMaxMoney)
- {
- if (config.getBoolValue("securetrades"))
- {
- close();
- return;
- }
- mMoneyLabel->setForegroundColorAll(
- getThemeColor(ThemeColorId::WARNING),
- getThemeColor(ThemeColorId::WARNING_OUTLINE));
- }
- else
- {
- mMoneyLabel->setForegroundColorAll(
- getThemeColor(ThemeColorId::LABEL),
- getThemeColor(ThemeColorId::LABEL_OUTLINE));
- mGotMaxMoney = amount;
- }
-
- mGotMoney = amount;
- // TRANSLATORS: trade window money label
- mMoneyLabel->setCaption(strprintf(_("You get %s"),
- UnitsDb::formatCurrency(amount).c_str()));
- mMoneyLabel->adjustSize();
-}
-
-void TradeWindow::addItem(const int id,
- const ItemTypeT type,
- const bool own,
- const int quantity,
- const uint8_t refine,
- const ItemColor color,
- const Identified identified,
- const Damaged damaged,
- const Favorite favorite) const
-{
- Inventory *const inv = own ? mMyInventory : mPartnerInventory;
- inv->addItem(id,
- type,
- quantity,
- refine,
- color,
- identified,
- damaged,
- favorite,
- Equipm_false,
- Equipped_false);
-}
-
-void TradeWindow::addItem2(const int id,
- const ItemTypeT type,
- const int *const cards,
- const ItemOptionsList *const options,
- const int sz,
- const bool own,
- const int quantity,
- const uint8_t refine,
- const ItemColor color,
- const Identified identified,
- const Damaged damaged,
- const Favorite favorite,
- const Equipm equipment) const
-{
- Inventory *const inv = own ? mMyInventory : mPartnerInventory;
- const int slot = inv->addItem(id,
- type,
- quantity,
- refine,
- color,
- identified,
- damaged,
- favorite,
- equipment,
- Equipped_false);
- if (slot >= 0)
- {
- inv->setCards(slot, cards, sz);
- inv->setOptions(slot, options);
- }
-}
-
-void TradeWindow::changeQuantity(const int index, const bool own,
- const int quantity) const
-{
- Item *item;
- if (own)
- item = mMyInventory->getItem(index);
- else
- item = mPartnerInventory->getItem(index);
- if (item != nullptr)
- item->setQuantity(quantity);
-}
-
-void TradeWindow::increaseQuantity(const int index, const bool own,
- const int quantity) const
-{
- Item *item;
- if (own)
- item = mMyInventory->getItem(index);
- else
- item = mPartnerInventory->getItem(index);
- if (item != nullptr)
- item->increaseQuantity(quantity);
-}
-
-void TradeWindow::reset()
-{
- mMyInventory->clear();
- mPartnerInventory->clear();
- mOkOther = false;
- mOkMe = false;
- setMoney(0);
- mMoneyField->setEnabled(true);
- mMoneyField->setText("");
- mMoneyLabel->setForegroundColorAll(
- getThemeColor(ThemeColorId::LABEL),
- getThemeColor(ThemeColorId::LABEL_OUTLINE));
- mAddButton->setEnabled(true);
- mMoneyChangeButton->setEnabled(true);
- mGotMoney = 0;
- mGotMaxMoney = 0;
- setStatus(PREPARING);
-}
-
-void TradeWindow::receivedOk(const bool own)
-{
- if (own)
- mOkMe = true;
- else
- mOkOther = true;
-
- if (mOkMe && mOkOther)
- setStatus(ACCEPTING);
-}
-
-void TradeWindow::completeTrade()
-{
- if (config.getBoolValue("tradescreenshot"))
- Game::createScreenshot(std::string());
- setVisible(Visible_false);
- reset();
-}
-
-void TradeWindow::tradeItem(const Item *const item, const int quantity,
- const bool check) const
-{
- if (check && !checkItem(item))
- return;
-
- tradeHandler->addItem(item, quantity);
-}
-
-void TradeWindow::valueChanged(const SelectionEvent &event)
-{
- if ((mMyItemContainer == nullptr) || (mPartnerItemContainer == nullptr))
- return;
-
- /* If an item is selected in one container, make sure no item is selected
- * in the other container.
- */
- if (event.getSource() == mMyItemContainer &&
- (mMyItemContainer->getSelectedItem() != nullptr))
- {
- mPartnerItemContainer->selectNone();
- }
- else if (mPartnerItemContainer->getSelectedItem() != nullptr)
- {
- mMyItemContainer->selectNone();
- }
-}
-
-void TradeWindow::setStatus(const Status s)
-{
- if (s == mStatus)
- return;
- mStatus = s;
-
- switch (s)
- {
- case PREPARING:
- mOkButton->setCaption(CAPTION_PROPOSE);
- mOkButton->setActionEventId("ok");
- break;
- case PROPOSING:
- mOkButton->setCaption(CAPTION_CONFIRMED);
- mOkButton->setActionEventId("");
- break;
- case ACCEPTING:
- mOkButton->setCaption(CAPTION_ACCEPT);
- mOkButton->setActionEventId("trade");
- break;
- case ACCEPTED:
- mOkButton->setCaption(CAPTION_ACCEPTED);
- mOkButton->setActionEventId("");
- break;
- default:
- break;
- }
-
- mOkButton->setEnabled((s != PROPOSING && s != ACCEPTED));
-}
-
-void TradeWindow::action(const ActionEvent &event)
-{
- if (inventoryWindow == nullptr)
- return;
-
- Item *const item = inventoryWindow->getSelectedItem();
- const std::string &eventId = event.getId();
-
- if (eventId == "add")
- {
- if (mStatus != PREPARING)
- return;
-
- if (!inventoryWindow->isWindowVisible())
- {
- inventoryWindow->setVisible(Visible_true);
- return;
- }
-
- if (item == nullptr)
- return;
-
- if (mMyInventory->getFreeSlot() == -1)
- return;
-
- if (!checkItem(item))
- return;
-
- // Choose amount of items to trade
- ItemAmountWindow::showWindow(ItemAmountWindowUsage::TradeAdd,
- this, item);
-
- setStatus(PREPARING);
- }
- else if (eventId == "cancel")
- {
- setVisible(Visible_false);
- reset();
- PlayerInfo::setTrading(Trading_false);
- tradeHandler->cancel();
- }
- else if (eventId == "ok")
- {
- mMoneyField->setEnabled(false);
- mAddButton->setEnabled(false);
- mMoneyChangeButton->setEnabled(false);
- receivedOk(true);
- setStatus(PROPOSING);
- tradeHandler->confirm();
- }
- else if (eventId == "trade")
- {
- receivedOk(true);
- setStatus(ACCEPTED);
- tradeHandler->finish();
- }
- else if (eventId == "money")
- {
- if (mStatus != PREPARING)
- return;
-
- int v = atoi(mMoneyField->getText().c_str());
- const int curMoney = PlayerInfo::getAttribute(Attributes::MONEY);
- if (v > curMoney)
- {
- if (localChatTab != nullptr)
- {
- // TRANSLATORS: trade error
- localChatTab->chatLog(_("You don't have enough money."),
- ChatMsgType::BY_SERVER);
- }
- v = curMoney;
- }
- tradeHandler->setMoney(v);
- mMoneyField->setText(strprintf("%d", v));
- }
-}
-
-void TradeWindow::close()
-{
- tradeHandler->cancel();
- clear();
-}
-
-void TradeWindow::clear()
-{
- mAutoAddItem = nullptr;
- mAutoAddToNick.clear();
- mAutoMoney = 0;
- mAutoAddAmount = 0;
- mGotMoney = 0;
- mGotMaxMoney = 0;
- mMoneyLabel->setForegroundColorAll(
- getThemeColor(ThemeColorId::LABEL),
- getThemeColor(ThemeColorId::LABEL_OUTLINE));
-}
-
-void TradeWindow::addAutoItem(const std::string &nick, Item* const item,
- const int amount)
-{
- mAutoAddToNick = nick;
- mAutoAddItem = item;
- mAutoAddAmount = amount;
-}
-
-void TradeWindow::addAutoMoney(const std::string &nick, const int money)
-{
- mAutoAddToNick = nick;
- mAutoMoney = money;
-}
-
-void TradeWindow::initTrade(const std::string &nick)
-{
- if (localPlayer == nullptr)
- return;
-
- if (!mAutoAddToNick.empty() && mAutoAddToNick == nick)
- {
- if ((mAutoAddItem != nullptr) && (mAutoAddItem->getQuantity() != 0))
- {
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv != nullptr)
- {
- const Item *const item = inv->findItem(mAutoAddItem->getId(),
- mAutoAddItem->getColor());
- if (item != nullptr)
- tradeItem(item, mAutoAddAmount);
- }
- }
- if (mAutoMoney != 0)
- {
- tradeHandler->setMoney(mAutoMoney);
- mMoneyField->setText(strprintf("%d", mAutoMoney));
- }
- }
- clear();
- if (!playerRelations.isGoodName(nick))
- setCaptionFont(gui->getSecureFont());
-}
-
-bool TradeWindow::checkItem(const Item *const item) const
-{
- if (item == nullptr)
- return false;
-
- const int itemId = item->getId();
- if (PlayerInfo::isItemProtected(itemId))
- return false;
- const Item *const tItem = mMyInventory->findItem(
- itemId, item->getColor());
-
- if ((tItem != nullptr) && (tItem->getQuantity() > 1
- || item->getQuantity() > 1))
- {
- if (localChatTab != nullptr)
- {
- // TRANSLATORS: trade error
- localChatTab->chatLog(_("Failed adding item. You can not "
- "overlap one kind of item on the window."),
- ChatMsgType::BY_SERVER);
- }
- return false;
- }
- if (Net::getNetworkType() != ServerType::TMWATHENA &&
- item->isEquipped() == Equipped_true)
- {
- if (localChatTab != nullptr)
- {
- localChatTab->chatLog(
- // TRANSLATORS: trade error
- _("Failed adding item. You can not trade equipped items."),
- ChatMsgType::BY_SERVER);
- }
- return false;
- }
- return true;
-}
-
-bool TradeWindow::isInpupFocused() const
-{
- return mMoneyField != nullptr && mMoneyField->isFocused();
-}
diff --git a/src/gui/windows/tradewindow.h b/src/gui/windows/tradewindow.h
deleted file mode 100644
index 6cfc89a3f..000000000
--- a/src/gui/windows/tradewindow.h
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_TRADEWINDOW_H
-#define GUI_WINDOWS_TRADEWINDOW_H
-
-#include "gui/widgets/window.h"
-
-#include "enums/resources/item/itemtype.h"
-
-#include "enums/simpletypes/damaged.h"
-#include "enums/simpletypes/equipm.h"
-#include "enums/simpletypes/favorite.h"
-#include "enums/simpletypes/identified.h"
-#include "enums/simpletypes/itemcolor.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/selectionlistener.h"
-
-class Button;
-class Inventory;
-class Item;
-class ItemContainer;
-class Label;
-class TextField;
-
-struct ItemOptionsList;
-
-/**
- * Trade dialog.
- *
- * \ingroup Interface
- */
-class TradeWindow final : public Window,
- private ActionListener,
- private SelectionListener
-{
- public:
- /**
- * Constructor.
- */
- TradeWindow();
-
- A_DELETE_COPY(TradeWindow)
-
- /**
- * Destructor.
- */
- ~TradeWindow();
-
- /**
- * Displays expected money in the trade window.
- */
- void setMoney(const int quantity);
-
- /**
- * Add an item to the trade window.
- */
- void addItem(const int id,
- const ItemTypeT type,
- const bool own,
- const int quantity,
- const uint8_t refine,
- const ItemColor color,
- const Identified identified,
- const Damaged damaged,
- const Favorite favorite) const;
-
- /**
- * Reset both item containers
- */
- void reset();
-
- /**
- * Add an item to the trade window.
- */
- void addItem2(const int id,
- const ItemTypeT type,
- const int *const cards,
- const ItemOptionsList *const options,
- const int sz,
- const bool own,
- const int quantity,
- const uint8_t refine,
- const ItemColor color,
- const Identified identified,
- const Damaged damaged,
- const Favorite favorite,
- const Equipm equipment) const;
-
- /**
- * Change quantity of an item.
- */
- void changeQuantity(const int index, const bool own,
- const int quantity) const;
-
- /**
- * Increase quantity of an item.
- */
- void increaseQuantity(const int index, const bool own,
- const int quantity) const;
-
- /**
- * Player received ok message from server
- */
- void receivedOk(const bool own);
-
- /**
- * Send trade packet.
- */
- void tradeItem(const Item *const item,
- const int quantity,
- const bool check = false) const;
-
- /**
- * Updates the labels and makes sure only one item is selected in
- * either my inventory or partner inventory.
- */
- void valueChanged(const SelectionEvent &event) override final;
-
- /**
- * Called when receiving actions from the widgets.
- */
- void action(const ActionEvent &event) override final;
-
- /**
- * Closes the Trade Window, as well as telling the server that the
- * window has been closed.
- */
- void close() override final;
-
- /**
- * Clear auto trade items.
- */
- void clear() override final;
-
- /**
- * Add item what will be added to trade.
- */
- void addAutoItem(const std::string &nick, Item *const item,
- const int amount);
-
- void addAutoMoney(const std::string &nick, const int money);
-
- void initTrade(const std::string &nick);
-
- std::string getAutoTradeNick() const noexcept2 A_WARN_UNUSED
- { return mAutoAddToNick; }
-
- bool checkItem(const Item *const item) const A_WARN_UNUSED;
-
- bool isInpupFocused() const A_WARN_UNUSED;
-
- void completeTrade();
-
- private:
- enum Status
- {
- PREPARING = 0, /**< Players are adding items. (1) */
- PROPOSING, /**< Local player has confirmed the trade. (1) */
- ACCEPTING, /**< Accepting the trade. (2) */
- ACCEPTED /**< Local player has accepted the trade. */
- };
-
- /**
- * Sets the current status of the trade.
- */
- void setStatus(const Status s);
-
- Inventory *mMyInventory A_NONNULLPOINTER;
- Inventory *mPartnerInventory A_NONNULLPOINTER;
-
- ItemContainer *mMyItemContainer A_NONNULLPOINTER;
- ItemContainer *mPartnerItemContainer A_NONNULLPOINTER;
-
- Label *mMoneyLabel A_NONNULLPOINTER;
- Button *mAddButton A_NONNULLPOINTER;
- Button *mOkButton A_NONNULLPOINTER;
- Button *mMoneyChangeButton A_NONNULLPOINTER;
- TextField *mMoneyField A_NONNULLPOINTER;
-
- Item* mAutoAddItem;
- std::string mAutoAddToNick;
- int mGotMoney;
- int mGotMaxMoney;
- int mAutoMoney;
- int mAutoAddAmount;
- Status mStatus;
- bool mOkOther;
- bool mOkMe;
-};
-
-extern TradeWindow *tradeWindow;
-
-#endif // GUI_WINDOWS_TRADEWINDOW_H
diff --git a/src/gui/windows/updaterwindow.cpp b/src/gui/windows/updaterwindow.cpp
deleted file mode 100644
index 3858b0a5e..000000000
--- a/src/gui/windows/updaterwindow.cpp
+++ /dev/null
@@ -1,1217 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/updaterwindow.h"
-
-#include "client.h"
-#include "configuration.h"
-#include "main.h"
-#include "settings.h"
-
-#include "enums/gui/layouttype.h"
-
-#include "fs/files.h"
-#include "fs/mkdir.h"
-#include "fs/paths.h"
-
-#include "fs/virtfs/fs.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/itemlinkhandler.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layout.h"
-#include "gui/widgets/progressbar.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/staticbrowserbox.h"
-
-#include "net/download.h"
-#include "net/updatetypeoperators.h"
-
-#include "resources/db/moddb.h"
-
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-
-#include <sys/stat.h>
-
-#include <sstream>
-
-#include "debug.h"
-
-UpdaterWindow *updaterWindow = nullptr;
-
-const std::string xmlUpdateFile("resources.xml");
-const std::string txtUpdateFile("resources2.txt");
-const std::string updateServer2
- ("http://download.manaplus.org/manaplus/updates/");
-const std::string updateServer3
- ("http://download2.manaplus.org/manaplus/updates/");
-const std::string updateServer4
- ("http://download.evolonline.org/manaplus/updates/");
-const std::string updateServer5
- ("http://download3.manaplus.org/manaplus/updates/");
-
-/**
- * Load the given file into a vector of updateFiles.
- */
-static STD_VECTOR<UpdateFile> loadXMLFile(const std::string &fileName,
- const bool loadMods)
-{
- STD_VECTOR<UpdateFile> files;
- XML::Document doc(fileName, UseVirtFs_false, SkipError_false);
- XmlNodeConstPtrConst rootNode = doc.rootNode();
-
- if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "updates"))
- {
- logger->log("Error loading update file: %s", fileName.c_str());
- return files;
- }
-
- for_each_xml_child_node(fileNode, rootNode)
- {
- const bool isMod = xmlNameEqual(fileNode, "mod");
- if (!xmlNameEqual(fileNode, "update") && !isMod)
- continue;
-
- UpdateFile file;
- file.name = XML::getProperty(fileNode, "file", "");
- file.hash = XML::getProperty(fileNode, "hash", "");
- file.type = XML::getProperty(fileNode, "type", "data");
- file.desc = XML::getProperty(fileNode, "description", "");
- file.group = XML::getProperty(fileNode, "group", "");
- if (!file.group.empty() && (!isMod || !loadMods))
- continue;
-
- const std::string version = XML::getProperty(
- fileNode, "version", "");
- if (!version.empty())
- {
- if (version > CHECK_VERSION)
- continue;
- }
- const std::string notVersion = XML::getProperty(
- fileNode, "notVersion", "");
- if (!notVersion.empty())
- {
- if (notVersion <= CHECK_VERSION)
- continue;
- }
- if (XML::getProperty(fileNode, "required", "yes") == "yes")
- file.required = true;
- else
- file.required = false;
-
- if (checkPath(file.name))
- files.push_back(file);
- }
-
- return files;
-}
-
-static STD_VECTOR<UpdateFile> loadTxtFile(const std::string &fileName)
-{
- STD_VECTOR<UpdateFile> files;
- std::ifstream fileHandler;
- fileHandler.open(fileName.c_str(), std::ios::in);
-
- if (fileHandler.is_open())
- {
- while (fileHandler.good())
- {
- char name[256];
- char hash[50];
- fileHandler.getline(name, 256, ' ');
- fileHandler.getline(hash, 50);
-
- UpdateFile thisFile;
- thisFile.name = name;
- thisFile.hash = hash;
- thisFile.type = "data";
- thisFile.group.clear();
- thisFile.required = true;
- thisFile.desc.clear();
-
- if (!thisFile.name.empty() && checkPath(thisFile.name))
- files.push_back(thisFile);
- }
- }
- else
- {
- logger->log("Error loading update file: %s", fileName.c_str());
- }
- fileHandler.close();
-
- return files;
-}
-
-UpdaterWindow::UpdaterWindow(const std::string &restrict updateHost,
- const std::string &restrict updatesDir,
- const bool applyUpdates,
- const UpdateTypeT updateType) :
- // TRANSLATORS: updater window name
- Window(_("Updating..."), Modal_false, nullptr, "update.xml"),
- ActionListener(),
- KeyListener(),
- mDownloadProgress(0.0F),
- mUpdateHost(updateHost),
- mUpdatesDir(updatesDir),
- mUpdatesDirReal(updatesDir),
- mCurrentFile("news.txt"),
- mNewLabelCaption(),
- mDownloadMutex(),
- mCurrentChecksum(0),
- mMemoryBuffer(nullptr),
- mDownload(nullptr),
- mUpdateFiles(),
- mTempUpdateFiles(),
- mUpdateServerPath(mUpdateHost),
- mItemLinkHandler(new ItemLinkHandler),
- // TRANSLATORS: updater window label
- mLabel(new Label(this, _("Connecting..."))),
- // TRANSLATORS: updater window button
- mCancelButton(new Button(this, _("Cancel"), "cancel", this)),
- // TRANSLATORS: updater window button
- mPlayButton(new Button(this, _("Play"), "play", this)),
- mProgressBar(new ProgressBar(this, 0.0, 310, 0,
- ProgressColorId::PROG_UPDATE,
- "updateprogressbar.xml", "updateprogressbar_fill.xml")),
- mBrowserBox(new StaticBrowserBox(this, Opaque_true,
- "browserbox.xml")),
- mScrollArea(new ScrollArea(this, mBrowserBox,
- Opaque_true, "update_background.xml")),
- mDownloadStatus(UpdateDownloadStatus::UPDATE_NEWS),
- mDownloadedBytes(0),
- mUpdateIndex(0),
- mUpdateIndexOffset(0),
- mUpdateType(updateType),
- mStoreInMemory(true),
- mDownloadComplete(true),
- mUserCancel(false),
- mLoadUpdates(applyUpdates),
- mValidateXml(false),
- mSkipPatches(false)
-{
- setWindowName("UpdaterWindow");
- setResizable(true);
- setDefaultSize(450, 400, ImagePosition::CENTER);
- setMinWidth(310);
- setMinHeight(220);
-
- mProgressBar->setSmoothProgress(false);
- mBrowserBox->setOpaque(Opaque_false);
- mBrowserBox->setLinkHandler(mItemLinkHandler);
- mBrowserBox->setProcessVars(true);
- mBrowserBox->setEnableKeys(true);
- mBrowserBox->setEnableTabs(true);
- mPlayButton->setEnabled(false);
-
- ContainerPlacer placer;
- placer = getPlacer(0, 0);
-
- placer(0, 0, mScrollArea, 5, 3).setPadding(3);
- placer(0, 3, mLabel, 5);
- placer(0, 4, mProgressBar, 5);
- placer(3, 5, mCancelButton);
- placer(4, 5, mPlayButton);
-
- Layout &layout = getLayout();
- layout.setRowHeight(0, LayoutType::SET);
-
- addKeyListener(this);
-
- if (mUpdateHost.empty())
- {
- const STD_VECTOR<std::string> &mirrors = settings.updateMirrors;
- if (mirrors.begin() != mirrors.end())
- mUpdateHost = *mirrors.begin();
- mSkipPatches = true;
- }
-
- loadWindowState();
-}
-
-void UpdaterWindow::postInit()
-{
- Window::postInit();
- setVisible(Visible_true);
- mCancelButton->requestFocus();
- removeProtocol(mUpdateServerPath);
-
- download();
-}
-
-UpdaterWindow::~UpdaterWindow()
-{
- if (mLoadUpdates)
- loadUpdates();
-
- if (mDownload != nullptr)
- {
- mDownload->cancel();
-
- delete2(mDownload)
- }
- free(mMemoryBuffer);
- delete2(mItemLinkHandler);
-}
-
-void UpdaterWindow::setProgress(const float p)
-{
- // Do delayed progress bar update, since Guichan isn't thread-safe
- MutexLocker lock(&mDownloadMutex);
- mDownloadProgress = p;
-}
-
-void UpdaterWindow::setLabel(const std::string &str)
-{
- // Do delayed label text update, since Guichan isn't thread-safe
- MutexLocker lock(&mDownloadMutex);
- mNewLabelCaption = str;
-}
-
-void UpdaterWindow::enable()
-{
- mCancelButton->setEnabled(false);
- mPlayButton->setEnabled(true);
- mPlayButton->requestFocus();
-
- if (client->getState() != State::GAME)
- {
- if ((mUpdateType & UpdateType::Close) != 0)
- client->setState(State::LOAD_DATA);
- }
- else
- {
- deleteSelf();
- }
-}
-
-void UpdaterWindow::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "cancel")
- {
- // Register the user cancel
- mUserCancel = true;
- // Skip the updating process
- if (mDownloadStatus != UpdateDownloadStatus::UPDATE_COMPLETE)
- {
- if (mDownload != nullptr)
- mDownload->cancel();
- mDownloadStatus = UpdateDownloadStatus::UPDATE_ERROR;
- }
- }
- else if (eventId == "play")
- {
- if (client->getState() != State::GAME)
- client->setState(State::LOAD_DATA);
- else
- deleteSelf();
- }
-}
-
-void UpdaterWindow::keyPressed(KeyEvent &event)
-{
- const InputActionT actionId = event.getActionId();
- if (actionId == InputAction::GUI_CANCEL)
- {
- action(ActionEvent(nullptr, mCancelButton->getActionEventId()));
- if (client->getState() != State::GAME)
- client->setState(State::LOGIN);
- else
- deleteSelf();
- }
- else if (actionId == InputAction::GUI_SELECT ||
- actionId == InputAction::GUI_SELECT2)
- {
- if (mDownloadStatus == UpdateDownloadStatus::UPDATE_COMPLETE ||
- mDownloadStatus == UpdateDownloadStatus::UPDATE_ERROR ||
- mDownloadStatus == UpdateDownloadStatus::UPDATE_IDLE)
- {
- action(ActionEvent(nullptr, mPlayButton->getActionEventId()));
- }
- else
- {
- action(ActionEvent(nullptr, mCancelButton->getActionEventId()));
- }
- }
-}
-
-void UpdaterWindow::loadNews()
-{
- if (mMemoryBuffer == nullptr)
- {
- logger->log1("Couldn't load news");
- return;
- }
-
- // Reallocate and include terminating 0 character
- mMemoryBuffer = static_cast<char*>(realloc(
- mMemoryBuffer, mDownloadedBytes + 1));
- if (mMemoryBuffer == nullptr)
- {
- logger->log1("Couldn't load news");
- return;
- }
- mMemoryBuffer[mDownloadedBytes] = '\0';
- mBrowserBox->clearRows();
-
- std::string newsName = mUpdatesDir + "/local/help/news.txt";
- mkdir_r((mUpdatesDir + "/local/help/").c_str());
- bool firstLine(true);
- std::ofstream file;
- std::stringstream ss(mMemoryBuffer);
- std::string line;
- file.open(newsName.c_str(), std::ios::out);
- int cnt = 0;
- const int maxNews = 50;
- while (std::getline(ss, line, '\n'))
- {
- cnt ++;
- if (firstLine)
- {
- firstLine = false;
- const size_t i = line.find("##9 Latest client version: ##6");
- if (i == 0u)
- continue;
-
- if (file.is_open())
- file << line << std::endl;
- if (cnt < maxNews)
- mBrowserBox->addRow(line);
- }
- else
- {
- if (file.is_open())
- file << line << std::endl;
- if (cnt < maxNews)
- mBrowserBox->addRow(line);
- }
- }
-
- file.close();
- if (cnt > maxNews)
- {
- mBrowserBox->addRow("");
- // TRANSLATORS: updater window checkbox
- mBrowserBox->addRow("news", _("Show all news (can be slow)"));
- mBrowserBox->addRow("");
- }
- // Free the memory buffer now that we don't need it anymore
- free(mMemoryBuffer);
- mMemoryBuffer = nullptr;
- mDownloadedBytes = 0;
-
- mBrowserBox->updateHeight();
- mScrollArea->setVerticalScrollAmount(0);
-}
-
-void UpdaterWindow::loadPatch()
-{
- if (mMemoryBuffer == nullptr)
- {
- logger->log1("Couldn't load patch");
- return;
- }
-
- // Reallocate and include terminating 0 character
- mMemoryBuffer = static_cast<char*>(
- realloc(mMemoryBuffer, mDownloadedBytes + 1));
- if (mMemoryBuffer == nullptr)
- {
- logger->log1("Couldn't load patch");
- return;
- }
- mMemoryBuffer[mDownloadedBytes] = '\0';
-
- std::string version;
-
- // Tokenize and add each line separately
- char *line = strtok(mMemoryBuffer, "\n");
- if (line != nullptr)
- {
- version = line;
- if (serverVersion < 1)
- {
- line = strtok(nullptr, "\n");
- if (line != nullptr)
- {
- mBrowserBox->addRow(strprintf("##9 Latest client version: "
- "##6ManaPlus %s##0", line), true);
- }
- }
- if (version > CHECK_VERSION)
- {
- mBrowserBox->addRow("", true);
-#if defined(ANDROID)
- const std::string url = "androidDownloadUrl";
- const std::string text = "androidDownloadUrl";
-#elif defined(WIN32)
- const std::string url = "windowsDownloadUrl";
- const std::string text = "windowsDownloadUrl";
-#else // defined(ANDROID)
-
- const std::string url = "otherDownloadUrl";
- const std::string text = "otherDownloadUrl";
-#endif // defined(ANDROID)
-
- mBrowserBox->addRow(std::string(" ##1[@@").append(
- branding.getStringValue(url)).append("|").append(
- branding.getStringValue(text)).append("@@]"), true);
- mBrowserBox->addRow("##1You can download it from", true);
- mBrowserBox->addRow("##1ManaPlus updated.", true);
- }
- else
- {
- mBrowserBox->addRow("You have latest client version.", true);
- }
- }
-
- // Free the memory buffer now that we don't need it anymore
- free(mMemoryBuffer);
- mMemoryBuffer = nullptr;
- mDownloadedBytes = 0;
-
- mBrowserBox->updateHeight();
- mScrollArea->setVerticalScrollAmount(0);
-}
-
-int UpdaterWindow::updateProgress(void *ptr,
- const DownloadStatusT status,
- size_t dt,
- const size_t dn)
-{
- UpdaterWindow *const uw = reinterpret_cast<UpdaterWindow *>(ptr);
- if (uw == nullptr)
- return -1;
-
- if (status == DownloadStatus::Complete)
- {
- uw->mDownloadComplete = true;
- }
- else if (status == DownloadStatus::Error ||
- status == DownloadStatus::Cancelled)
- {
- if (uw->mDownloadStatus == UpdateDownloadStatus::UPDATE_COMPLETE ||
- uw->mDownloadStatus == UpdateDownloadStatus::UPDATE_NEWS)
- { // ignoring error in last state (was UPDATE_PATCH)
- uw->mDownloadStatus = UpdateDownloadStatus::UPDATE_COMPLETE;
- uw->mDownloadComplete = true;
- free(uw->mMemoryBuffer);
- uw->mMemoryBuffer = nullptr;
- }
- else
- {
- uw->mDownloadStatus = UpdateDownloadStatus::UPDATE_ERROR;
- }
- }
-
- if (dt == 0u)
- dt = 1;
-
- float progress = static_cast<float>(dn) /
- static_cast<float>(dt);
-
- if (progress != progress)
- progress = 0.0F; // check for NaN
- if (progress < 0.0F)
- progress = 0.0F; // no idea how this could ever happen,
- // but why not check for it anyway.
- if (progress > 1.0F)
- progress = 1.0F;
-
- uw->setLabel(std::string(uw->mCurrentFile).append(" (")
- .append(toString(CAST_S32(progress * 100))).append("%)"));
-
- uw->setProgress(progress);
-
- if ((client->getState() != State::UPDATE &&
- client->getState() != State::GAME) ||
- uw->mDownloadStatus == UpdateDownloadStatus::UPDATE_ERROR)
- {
- // If the action was canceled return an error code to stop the mThread
- return -1;
- }
-
- return 0;
-}
-
-size_t UpdaterWindow::memoryWrite(void *ptr, size_t size,
- size_t nmemb, void *stream)
-{
- UpdaterWindow *const uw = reinterpret_cast<UpdaterWindow *>(stream);
- const size_t totalMem = size * nmemb;
- if (uw == nullptr)
- return 0;
- uw->mMemoryBuffer = static_cast<char*>(realloc(uw->mMemoryBuffer,
- CAST_SIZE(uw->mDownloadedBytes) + totalMem));
- if (uw->mMemoryBuffer != nullptr)
- {
- memcpy(&(uw->mMemoryBuffer[uw->mDownloadedBytes]), ptr, totalMem);
- uw->mDownloadedBytes += CAST_S32(totalMem);
- }
-
- return totalMem;
-}
-
-void UpdaterWindow::download()
-{
- if (mDownload != nullptr)
- {
- mDownload->cancel();
- delete mDownload;
- }
- if (mDownloadStatus == UpdateDownloadStatus::UPDATE_PATCH)
- {
- mDownload = new Net::Download(this,
- branding.getStringValue("updateMirror1") + mCurrentFile,
- &updateProgress,
- true, false, mValidateXml);
- for (int f = 2; f < 8; f ++)
- {
- const std::string url = branding.getStringValue(
- "updateMirror" + toString(f));
- if (!url.empty())
- mDownload->addMirror(url + mCurrentFile);
- }
- }
- else
- {
- mDownload = new Net::Download(this,
- urlJoin(mUpdateHost, mCurrentFile),
- &updateProgress,
- false, false, mValidateXml);
-
- if (mDownloadStatus == UpdateDownloadStatus::UPDATE_LIST2 ||
- mDownloadStatus == UpdateDownloadStatus::UPDATE_RESOURCES2)
- {
- const std::string str = urlJoin(mUpdateServerPath, mCurrentFile);
- mDownload->addMirror(updateServer3 + str);
- mDownload->addMirror(updateServer4 + str);
- mDownload->addMirror(updateServer5 + str);
- }
- else
- {
- const STD_VECTOR<std::string> &mirrors = settings.updateMirrors;
- FOR_EACH (STD_VECTOR<std::string>::const_iterator, it, mirrors)
- {
- mDownload->addMirror(pathJoin(*it,
- mCurrentFile));
- }
- }
- }
-
- if (mStoreInMemory)
- {
- mDownload->setWriteFunction(&UpdaterWindow::memoryWrite);
- }
- else
- {
- if (mDownloadStatus == UpdateDownloadStatus::UPDATE_RESOURCES)
- {
- mDownload->setFile(pathJoin(mUpdatesDir, mCurrentFile),
- mCurrentChecksum);
- }
- else
- {
- mDownload->setFile(pathJoin(mUpdatesDir,
- mCurrentFile));
- }
- }
-
- if (mDownloadStatus != UpdateDownloadStatus::UPDATE_RESOURCES)
- mDownload->noCache();
-
- setLabel(mCurrentFile + " (0%)");
- mDownloadComplete = false;
-
- mDownload->start();
-}
-
-void UpdaterWindow::loadUpdates()
-{
- if (mUpdateFiles.empty())
- { // updates not downloaded
- mUpdateFiles = loadXMLFile(pathJoin(mUpdatesDir, xmlUpdateFile),
- false);
- if (mUpdateFiles.empty())
- {
- logger->log("Warning this server does not have a"
- " %s file falling back to %s", xmlUpdateFile.c_str(),
- txtUpdateFile.c_str());
- mUpdateFiles = loadTxtFile(pathJoin(mUpdatesDir,
- txtUpdateFile));
- }
- }
-
- std::string fixPath = mUpdatesDir + "/fix";
- const unsigned sz = CAST_U32(mUpdateFiles.size());
- for (mUpdateIndex = 0; mUpdateIndex < sz; mUpdateIndex++)
- {
- const UpdateFile &file = mUpdateFiles[mUpdateIndex];
- if (!file.group.empty())
- continue;
- UpdaterWindow::addUpdateFile(mUpdatesDir,
- fixPath,
- file.name,
- Append_false);
- }
- loadManaPlusUpdates(mUpdatesDir);
- loadMods(mUpdatesDir, mUpdateFiles);
-}
-
-void UpdaterWindow::loadLocalUpdates(const std::string &dir)
-{
- STD_VECTOR<UpdateFile> updateFiles = loadXMLFile(
- pathJoin(dir, xmlUpdateFile),
- false);
-
- if (updateFiles.empty())
- {
- logger->log("Warning this server does not have a"
- " %s file falling back to %s", xmlUpdateFile.c_str(),
- txtUpdateFile.c_str());
- updateFiles = loadTxtFile(pathJoin(dir,
- txtUpdateFile));
- }
-
- const std::string fixPath = dir + "/fix";
- for (unsigned int updateIndex = 0,
- fsz = CAST_U32(updateFiles.size());
- updateIndex < fsz;
- updateIndex++)
- {
- const UpdateFile &file = updateFiles[updateIndex];
- if (!file.group.empty())
- continue;
- UpdaterWindow::addUpdateFile(dir,
- fixPath,
- file.name,
- Append_false);
- }
- loadManaPlusUpdates(dir);
- loadMods(dir, updateFiles);
-}
-
-void UpdaterWindow::unloadUpdates(const std::string &dir)
-{
- STD_VECTOR<UpdateFile> updateFiles = loadXMLFile(
- pathJoin(dir, xmlUpdateFile),
- true);
-
- if (updateFiles.empty())
- {
- updateFiles = loadTxtFile(pathJoin(dir,
- txtUpdateFile));
- }
-
- const std::string fixPath = dir + "/fix";
- for (unsigned int updateIndex = 0,
- fsz = CAST_U32(updateFiles.size());
- updateIndex < fsz;
- updateIndex++)
- {
- UpdaterWindow::removeUpdateFile(dir,
- fixPath,
- updateFiles[updateIndex].name);
- }
- unloadManaPlusUpdates(dir);
-}
-
-void UpdaterWindow::loadManaPlusUpdates(const std::string &dir)
-{
- std::string fixPath = dir + "/fix";
- STD_VECTOR<UpdateFile> updateFiles = loadXMLFile(
- pathJoin(fixPath, xmlUpdateFile),
- false);
-
- for (unsigned int updateIndex = 0,
- fsz = CAST_U32(updateFiles.size());
- updateIndex < fsz;
- updateIndex++)
- {
- const UpdateFile &file = updateFiles[updateIndex];
- if (!file.group.empty())
- continue;
- const std::string name = file.name;
- if (strStartWith(name, "manaplus_"))
- {
- struct stat statbuf;
- std::string fileName = pathJoin(fixPath,
- name);
- if (stat(fileName.c_str(), &statbuf) == 0)
- {
- VirtFs::mountZip(fileName,
- Append_false);
- }
- }
- }
-}
-
-void UpdaterWindow::unloadManaPlusUpdates(const std::string &dir)
-{
- const std::string fixPath = dir + "/fix";
- const STD_VECTOR<UpdateFile> updateFiles = loadXMLFile(
- pathJoin(fixPath, xmlUpdateFile),
- true);
-
- for (unsigned int updateIndex = 0,
- fsz = CAST_U32(updateFiles.size());
- updateIndex < fsz;
- updateIndex++)
- {
- std::string name = updateFiles[updateIndex].name;
- if (strStartWith(name, "manaplus_"))
- {
- struct stat statbuf;
- const std::string file = pathJoin(
- fixPath, name);
- if (stat(file.c_str(), &statbuf) == 0)
- VirtFs::unmountZip(file);
- }
- }
-}
-
-void UpdaterWindow::addUpdateFile(const std::string &restrict path,
- const std::string &restrict fixPath,
- const std::string &restrict file,
- const Append append)
-{
- const std::string tmpPath = pathJoin(path, file);
- if (append == Append_false)
- VirtFs::mountZip(tmpPath, append);
-
- const std::string fixFile = pathJoin(fixPath, file);
- struct stat statbuf;
- if (stat(fixFile.c_str(), &statbuf) == 0)
- VirtFs::mountZip(fixFile, append);
-
- if (append == Append_true)
- VirtFs::mountZip(tmpPath, append);
-}
-
-void UpdaterWindow::removeUpdateFile(const std::string &restrict path,
- const std::string &restrict fixPath,
- const std::string &restrict file)
-{
- VirtFs::unmountZip(pathJoin(path, file));
- const std::string fixFile = pathJoin(fixPath, file);
- struct stat statbuf;
- if (stat(fixFile.c_str(), &statbuf) == 0)
- VirtFs::unmountZip(fixFile);
-}
-
-void UpdaterWindow::logic()
-{
- BLOCK_START("UpdaterWindow::logic")
- // Update Scroll logic
- mScrollArea->logic();
-
- // Synchronize label caption when necessary
- {
- MutexLocker lock(&mDownloadMutex);
-
- if (mLabel->getCaption() != mNewLabelCaption)
- {
- mLabel->setCaption(mNewLabelCaption);
- mLabel->adjustSize();
- }
-
- mProgressBar->setProgress(mDownloadProgress);
- if (!mUpdateFiles.empty() &&
- CAST_SIZE(mUpdateIndex) <= mUpdateFiles.size())
- {
- mProgressBar->setText(strprintf("%u/%u", mUpdateIndex
- + mUpdateIndexOffset + 1, CAST_U32(
- mUpdateFiles.size()) + CAST_S32(
- mTempUpdateFiles.size()) + 1));
- }
- else
- {
- mProgressBar->setText("");
- }
- }
-
- switch (mDownloadStatus)
- {
- case UpdateDownloadStatus::UPDATE_ERROR:
- mBrowserBox->addRow("");
- // TRANSLATORS: update message
- mBrowserBox->addRow(_("##1 The update process is incomplete."));
- // TRANSLATORS: Continues "The update process is incomplete.".
- mBrowserBox->addRow(_("##1 It is strongly recommended that"));
- // TRANSLATORS: Begins "It is strongly recommended that".
- mBrowserBox->addRow(_("##1 you try again later."));
- if (mDownload != nullptr)
- mBrowserBox->addRow(mDownload->getError());
- mBrowserBox->updateHeight();
- mScrollArea->setVerticalScrollAmount(
- mScrollArea->getVerticalMaxScroll());
- mDownloadStatus = UpdateDownloadStatus::UPDATE_COMPLETE;
- break;
- case UpdateDownloadStatus::UPDATE_NEWS:
- if (mDownloadComplete)
- {
- // Parse current memory buffer as news and dispose of the data
- loadNews();
-
- mValidateXml = true;
- mCurrentFile = xmlUpdateFile;
- mStoreInMemory = false;
- mDownloadStatus = UpdateDownloadStatus::UPDATE_LIST;
- download(); // download() changes mDownloadComplete to false
- }
- break;
- case UpdateDownloadStatus::UPDATE_PATCH:
- if (mDownloadComplete)
- {
- // Parse current memory buffer as news and dispose of the data
- loadPatch();
-
- mUpdateHost = updateServer2 + mUpdateServerPath;
- mUpdatesDir = pathJoin(mUpdatesDir, "fix");
- mCurrentFile = xmlUpdateFile;
- mValidateXml = true;
- mStoreInMemory = false;
- mDownloadStatus = UpdateDownloadStatus::UPDATE_LIST2;
- download();
- }
- break;
-
- case UpdateDownloadStatus::UPDATE_LIST:
- if (mDownloadComplete)
- {
- if (mCurrentFile == xmlUpdateFile)
- {
- mUpdateFiles = loadXMLFile(pathJoin(
- mUpdatesDir, xmlUpdateFile),
- true);
-
- if (mUpdateFiles.empty())
- {
- logger->log("Warning this server does not have a %s"
- " file falling back to %s",
- xmlUpdateFile.c_str(),
- txtUpdateFile.c_str());
-
- // If the resources.xml file fails,
- // fall back onto a older version
- mCurrentFile = txtUpdateFile;
- mValidateXml = false;
- mStoreInMemory = false;
- mDownloadStatus = UpdateDownloadStatus::UPDATE_LIST;
- download();
- break;
- }
- }
- else if (mCurrentFile == txtUpdateFile)
- {
- mValidateXml = true;
- mUpdateFiles = loadTxtFile(pathJoin(mUpdatesDir,
- txtUpdateFile));
- }
- mStoreInMemory = false;
- mDownloadStatus = UpdateDownloadStatus::UPDATE_RESOURCES;
- }
- break;
- case UpdateDownloadStatus::UPDATE_RESOURCES:
- if (mDownloadComplete)
- {
- if (CAST_SIZE(mUpdateIndex) < mUpdateFiles.size())
- {
- UpdateFile thisFile = mUpdateFiles[mUpdateIndex];
- if (thisFile.type == "music"
- && !config.getBoolValue("download-music"))
- {
- mUpdateIndex++;
- break;
- }
- mCurrentFile = thisFile.name;
- std::string checksum;
- checksum = thisFile.hash;
- std::stringstream ss(checksum);
- ss >> std::hex >> mCurrentChecksum;
-
- std::ifstream temp(pathJoin(mUpdatesDir,
- mCurrentFile).c_str());
-
- mValidateXml = false;
- if (!temp.is_open() || !validateFile(pathJoin(
- mUpdatesDir, mCurrentFile),
- mCurrentChecksum))
- {
- temp.close();
- download();
- }
- else
- {
- temp.close();
- logger->log("%s already here", mCurrentFile.c_str());
- }
- mUpdateIndex++;
- }
- else
- {
- if (!mSkipPatches)
- {
- // Download of updates completed
- mCurrentFile = "latest.txt";
- mStoreInMemory = true;
- mDownloadStatus = UpdateDownloadStatus::UPDATE_PATCH;
- mValidateXml = false;
- download(); // download() changes
- // mDownloadComplete to false
- }
- else
- {
- mDownloadStatus =
- UpdateDownloadStatus::UPDATE_COMPLETE;
- }
- }
- }
- break;
- case UpdateDownloadStatus::UPDATE_LIST2:
- if (mDownloadComplete)
- {
- if (mCurrentFile == xmlUpdateFile)
- {
- mTempUpdateFiles = loadXMLFile(pathJoin(
- mUpdatesDir, xmlUpdateFile),
- true);
- }
- mUpdateIndexOffset = mUpdateIndex;
- mUpdateIndex = 0;
- mValidateXml = true;
- mStoreInMemory = false;
- mDownloadStatus = UpdateDownloadStatus::UPDATE_RESOURCES2;
- download();
- }
- break;
- case UpdateDownloadStatus::UPDATE_RESOURCES2:
- if (mDownloadComplete)
- {
- mValidateXml = false;
- if (CAST_SIZE(mUpdateIndex)
- < mTempUpdateFiles.size())
- {
- const UpdateFile thisFile = mTempUpdateFiles[mUpdateIndex];
- mCurrentFile = thisFile.name;
- std::string checksum;
- checksum = thisFile.hash;
- std::stringstream ss(checksum);
- ss >> std::hex >> mCurrentChecksum;
-
- std::ifstream temp((pathJoin(mUpdatesDir,
- mCurrentFile)).c_str());
-
- if (!temp.is_open() || !validateFile(pathJoin(
- mUpdatesDir, mCurrentFile),
- mCurrentChecksum))
- {
- temp.close();
- download();
- }
- else
- {
- temp.close();
- logger->log("%s already here", mCurrentFile.c_str());
- }
- mUpdateIndex++;
- }
- else
- {
- mUpdatesDir = mUpdatesDirReal;
- mDownloadStatus = UpdateDownloadStatus::UPDATE_COMPLETE;
- }
- }
- break;
- case UpdateDownloadStatus::UPDATE_COMPLETE:
- mUpdatesDir = mUpdatesDirReal;
- enable();
- // TRANSLATORS: updater window label
- setLabel(_("Completed"));
- mDownloadStatus = UpdateDownloadStatus::UPDATE_IDLE;
- break;
- case UpdateDownloadStatus::UPDATE_IDLE:
- break;
- default:
- logger->log("UpdaterWindow::logic unknown status: "
- + toString(CAST_U32(mDownloadStatus)));
- break;
- }
- BLOCK_END("UpdaterWindow::logic")
-}
-
-bool UpdaterWindow::validateFile(const std::string &filePath,
- const unsigned long hash)
-{
- FILE *const file = fopen(filePath.c_str(), "rb");
- if (file == nullptr)
- return false;
-
- const unsigned long adler = Net::Download::fadler32(file);
- fclose(file);
- return adler == hash;
-}
-
-unsigned long UpdaterWindow::getFileHash(const std::string &filePath)
-{
- int size = 0;
- const char *const buf = VirtFs::loadFile(filePath, size);
- if (buf == nullptr)
- return 0;
- unsigned long res = Net::Download::adlerBuffer(buf, size);
- delete [] buf;
- return res;
-}
-
-void UpdaterWindow::loadFile(std::string file)
-{
- mBrowserBox->clearRows();
- trim(file);
-
- StringVect lines;
- Files::loadTextFileLocal(mUpdatesDir + "/local/help/news.txt", lines);
-
- for (size_t i = 0, sz = lines.size(); i < sz; ++i)
- mBrowserBox->addRow(lines[i]);
- mBrowserBox->updateHeight();
-}
-
-void UpdaterWindow::loadMods(const std::string &dir,
- const STD_VECTOR<UpdateFile> &updateFiles)
-{
- ModDB::load();
- std::string modsString = serverConfig.getValue("mods", "");
- std::set<std::string> modsList;
- splitToStringSet(modsList, modsString, '|');
-
- const std::string fixPath = dir + "/fix";
- for (unsigned int updateIndex = 0,
- fsz = CAST_U32(updateFiles.size());
- updateIndex < fsz;
- updateIndex ++)
- {
- const UpdateFile &file = updateFiles[updateIndex];
- if (file.group.empty())
- continue;
- const std::set<std::string>::const_iterator
- it = modsList.find(file.group);
- if (it != modsList.end())
- {
- UpdaterWindow::addUpdateFile(dir,
- fixPath,
- file.name,
- Append_false);
- }
- }
-
- STD_VECTOR<UpdateFile> updateFiles2 = loadXMLFile(
- pathJoin(fixPath, xmlUpdateFile),
- true);
-
- for (unsigned int updateIndex = 0,
- fsz = CAST_U32(updateFiles2.size());
- updateIndex < fsz;
- updateIndex++)
- {
- const UpdateFile &file = updateFiles2[updateIndex];
- if (file.group.empty())
- continue;
- std::string name = file.name;
- if (strStartWith(name, "manaplus_"))
- {
- const std::set<std::string>::const_iterator
- it = modsList.find(file.group);
- if (it != modsList.end())
- {
- struct stat statbuf;
- std::string fileName = pathJoin(fixPath,
- name);
- if (stat(fileName.c_str(), &statbuf) == 0)
- {
- VirtFs::mountZip(fileName,
- Append_false);
- }
- }
- }
- }
-
- loadDirMods(dir + "/local/");
-}
-
-void UpdaterWindow::loadDirMods(const std::string &dir)
-{
- ModDB::load();
- const ModInfos &mods = ModDB::getAll();
-
- std::string modsString = serverConfig.getValue("mods", "");
- StringVect modsList;
- splitToStringVector(modsList, modsString, '|');
- FOR_EACH (StringVectCIter, it, modsList)
- {
- const std::string &name = *it;
- const ModInfoCIterator modIt = mods.find(name);
- if (modIt == mods.end())
- continue;
- const ModInfo *const mod = (*modIt).second;
- if (mod != nullptr)
- {
- const std::string &localDir = mod->getLocalDir();
- if (!localDir.empty())
- {
- VirtFs::mountDir(pathJoin(dir, localDir),
- Append_false);
- }
- }
- }
-}
-
-void UpdaterWindow::unloadMods(const std::string &dir)
-{
- const ModInfos &mods = ModDB::getAll();
- std::string modsString = serverConfig.getValue("mods", "");
- StringVect modsList;
- splitToStringVector(modsList, modsString, '|');
- FOR_EACH (StringVectCIter, it, modsList)
- {
- const std::string &name = *it;
- const ModInfoCIterator modIt = mods.find(name);
- if (modIt == mods.end())
- continue;
- const ModInfo *const mod = (*modIt).second;
- if (mod != nullptr)
- {
- const std::string &localDir = mod->getLocalDir();
- if (!localDir.empty())
- VirtFs::unmountDir(pathJoin(dir, localDir));
- }
- }
-}
-
-void UpdaterWindow::deleteSelf()
-{
- scheduleDelete();
- updaterWindow = nullptr;
-}
diff --git a/src/gui/windows/updaterwindow.h b/src/gui/windows/updaterwindow.h
deleted file mode 100644
index 661168a9f..000000000
--- a/src/gui/windows/updaterwindow.h
+++ /dev/null
@@ -1,252 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_UPDATERWINDOW_H
-#define GUI_WINDOWS_UPDATERWINDOW_H
-
-#include "enums/gui/updatedownloadstatus.h"
-
-#include "enums/net/downloadstatus.h"
-#include "enums/net/updatetype.h"
-
-#include "enums/simpletypes/append.h"
-
-#include "gui/widgets/window.h"
-
-#include "resources/updatefile.h"
-
-#include "utils/mutex.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/keylistener.h"
-
-class Button;
-class ItemLinkHandler;
-class Label;
-class ProgressBar;
-class ScrollArea;
-class StaticBrowserBox;
-
-namespace Net
-{
- class Download;
-} // namespace Net
-
-/**
- * Update progress window GUI
- *
- * \ingroup GUI
- */
-class UpdaterWindow final : public Window,
- public ActionListener,
- public KeyListener
-{
- public:
- /**
- * Constructor.
- *
- * @param updateHost Host where to get the updated files.
- * @param updatesDir Directory where to store updates (should be
- * absolute and already created).
- * @param applyUpdates If true, the update window will pass the updates
- * to teh resource manager.
- */
- UpdaterWindow(const std::string &restrict updateHost,
- const std::string &restrict updatesDir,
- const bool applyUpdates,
- const UpdateTypeT updateType);
-
- A_DELETE_COPY(UpdaterWindow)
-
- /**
- * Destructor
- */
- ~UpdaterWindow();
-
- void postInit() override final;
-
- /**
- * Set's progress bar status
- */
- void setProgress(const float p);
-
- /**
- * Set's label above progress
- */
- void setLabel(const std::string &);
-
- /**
- * Enables play button
- */
- void enable();
-
- /**
- * Loads and display news. Assumes the news file contents have been
- * loaded into the memory buffer.
- */
- void loadNews();
-
- void loadPatch();
-
- void action(const ActionEvent &event) override final;
-
- void keyPressed(KeyEvent &event) override final;
-
- void logic() override final;
-
- void loadFile(std::string file);
-
- void deleteSelf();
-
- static void loadLocalUpdates(const std::string &dir);
-
- static void unloadUpdates(const std::string &dir);
-
- static void addUpdateFile(const std::string &restrict path,
- const std::string &restrict fixPath,
- const std::string &restrict file,
- const Append append);
-
- static void removeUpdateFile(const std::string &restrict path,
- const std::string &restrict fixPath,
- const std::string &filerestrict);
-
- static void loadManaPlusUpdates(const std::string &dir);
-
- static void unloadManaPlusUpdates(const std::string &dir);
-
- static unsigned long getFileHash(const std::string &filePath);
-
- static void loadMods(const std::string &dir,
- const STD_VECTOR<UpdateFile> &updateFiles);
-
- static void loadDirMods(const std::string &dir);
-
- static void unloadMods(const std::string &dir);
-
- private:
- void download();
-
- /**
- * Loads the updates this window has gotten into the resource manager
- */
- void loadUpdates();
-
- /**
- * A download callback for progress updates.
- */
- static int updateProgress(void *ptr,
- const DownloadStatusT status,
- size_t dt,
- const size_t dn);
-
- /**
- * A libcurl callback for writing to memory.
- */
- static size_t memoryWrite(void *ptr, size_t size, size_t nmemb,
- void *stream);
-
- static bool validateFile(const std::string &filePath,
- const unsigned long hash) A_WARN_UNUSED;
-
- /** The new progress value to be set in the logic method. */
- float mDownloadProgress;
-
- /** Host where we get the updated files. */
- std::string mUpdateHost;
-
- /** Place where the updates are stored (absolute path). */
- std::string mUpdatesDir;
-
- std::string mUpdatesDirReal;
-
- /** The file currently downloading. */
- std::string mCurrentFile;
-
- /** The new label caption to be set in the logic method. */
- std::string mNewLabelCaption;
-
- // The mutex used to guard access to mNewLabelCaption
- // and mDownloadProgress.
- Mutex mDownloadMutex;
-
- /** The Adler32 checksum of the file currently downloading. */
- unsigned long mCurrentChecksum;
-
- /** Buffer for files downloaded to memory. */
- char *mMemoryBuffer;
-
- /** Download handle. */
- Net::Download *mDownload;
-
- /** List of files to download. */
- STD_VECTOR<UpdateFile> mUpdateFiles;
-
- /** List of temp files to download. */
- STD_VECTOR<UpdateFile> mTempUpdateFiles;
-
- std::string mUpdateServerPath;
-
- ItemLinkHandler *mItemLinkHandler A_NONNULLPOINTER;
- Label *mLabel A_NONNULLPOINTER;
- Button *mCancelButton A_NONNULLPOINTER;
- Button *mPlayButton A_NONNULLPOINTER;
- ProgressBar *mProgressBar A_NONNULLPOINTER;
- StaticBrowserBox *mBrowserBox A_NONNULLPOINTER;
- ScrollArea *mScrollArea A_NONNULLPOINTER;
-
- /** Status of the current download. */
- UpdateDownloadStatusT mDownloadStatus;
-
- /** Byte count currently downloaded in mMemoryBuffer. */
- int mDownloadedBytes;
-
- /** Index of the file to be downloaded. */
- unsigned int mUpdateIndex;
-
- /** Index offset for disaplay downloaded file. */
- unsigned int mUpdateIndexOffset;
-
- UpdateTypeT mUpdateType;
-
- /** A flag to indicate whether to use a memory buffer or a regular
- * file.
- */
- bool mStoreInMemory;
-
- /** Flag that show if current download is complete. */
- bool mDownloadComplete;
-
- /** Flag that show if the user has canceled the update. */
- bool mUserCancel;
-
- /** Tells ~UpdaterWindow() if it should load updates */
- bool mLoadUpdates;
-
- bool mValidateXml;
-
- bool mSkipPatches;
-};
-
-extern UpdaterWindow *updaterWindow;
-
-#endif // GUI_WINDOWS_UPDATERWINDOW_H
diff --git a/src/gui/windows/whoisonline.cpp b/src/gui/windows/whoisonline.cpp
deleted file mode 100644
index e123d3941..000000000
--- a/src/gui/windows/whoisonline.cpp
+++ /dev/null
@@ -1,909 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/whoisonline.h"
-
-#include "actormanager.h"
-#include "configuration.h"
-#include "guild.h"
-#include "party.h"
-#ifdef TMWA_SUPPORT
-#include "settings.h"
-#endif // TMWA_SUPPORT
-
-#include "gui/onlineplayer.h"
-#include "gui/popupmanager.h"
-#include "gui/viewport.h"
-
-#include "gui/popups/popupmenu.h"
-
-#include "gui/windows/chatwindow.h"
-#include "gui/windows/setupwindow.h"
-#include "gui/windows/socialwindow.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/staticbrowserbox.h"
-
-#include "being/beingflag.h"
-#include "being/localplayer.h"
-#include "being/playerrelations.h"
-
-#ifdef TMWA_SUPPORT
-#include "net/download.h"
-#endif // TMWA_SUPPORT
-#include "net/packetlimiter.h"
-#include "net/playerhandler.h"
-#include "net/serverfeatures.h"
-
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-#include "utils/sdlhelper.h"
-
-#ifdef TMWA_SUPPORT
-#include "net/net.h"
-#else // TMWA_SUPPORT
-#include <curl/curl.h>
-#endif // TMWA_SUPPORT
-
-#include "debug.h"
-
-#ifdef free
-#undef free
-#endif // free
-
-#ifdef malloc
-#undef malloc
-#endif // malloc
-
-WhoIsOnline *whoIsOnline = nullptr;
-
-namespace
-{
- class NameFunctuator final
- {
- public:
- A_DEFAULT_COPY(NameFunctuator)
-
- bool operator()(const OnlinePlayer *left,
- const OnlinePlayer *right) const
- {
- return (compareStrI(left->getNick(), right->getNick()) < 0);
- }
- } nameCompare;
-} // namespace
-
-WhoIsOnline::WhoIsOnline() :
- // TRANSLATORS: who is online window name
- Window(_("Who Is Online - Updating"),
- Modal_false,
- nullptr,
- "whoisonline.xml"),
- mUpdateTimer(0),
- mThread(nullptr),
- mMemoryBuffer(nullptr),
- mCurlError(new char[CURL_ERROR_SIZE]),
- mBrowserBox(new StaticBrowserBox(this, Opaque_true,
- "onlinebrowserbox.xml")),
- mScrollArea(new ScrollArea(this, mBrowserBox, Opaque_false)),
- // TRANSLATORS: who is online. button.
- mUpdateButton(new Button(this, _("Update"), "update", this)),
- mOnlinePlayers(),
- mOnlineNicks(),
- mFriends(),
- mNeutral(),
- mDisregard(),
- mEnemy(),
- mDownloadedBytes(0),
- mDownloadStatus(UPDATE_LIST),
- mDownloadComplete(true),
- mAllowUpdate(true),
- mShowLevel(false),
- mUpdateOnlineList(config.getBoolValue("updateOnlineList")),
- mGroupFriends(true),
-#ifdef TMWA_SUPPORT
- mWebList(Net::getNetworkType() == ServerType::TMWATHENA),
-#endif
- mServerSideList(serverFeatures->haveServerOnlineList())
-{
- mCurlError[0] = 0;
- setWindowName("WhoIsOnline");
-}
-
-void WhoIsOnline::postInit()
-{
- Window::postInit();
- const int h = 350;
- const int w = 200;
- setDefaultSize(w, h, ImagePosition::CENTER);
-
- setVisible(Visible_false);
- setCloseButton(true);
- setResizable(true);
- setStickyButtonLock(true);
- setSaveVisible(true);
-
- if (setupWindow != nullptr)
- setupWindow->registerWindowForReset(this);
-
- mUpdateButton->setEnabled(false);
- mUpdateButton->setDimension(Rect(5, 5, w - 10, 20 + 5));
-
- mBrowserBox->setOpaque(Opaque_false);
- mScrollArea->setDimension(Rect(5, 20 + 10, w - 10, h - 10 - 30));
- mScrollArea->setSize(w - 10, h - 10 - 30);
- mScrollArea->setSelectable(false);
- mBrowserBox->setLinkHandler(this);
-
- add(mUpdateButton);
- add(mScrollArea);
-
- setLocationRelativeTo(getParent());
-
- loadWindowState();
- enableVisibleSound(true);
-
- download();
-
- widgetResized(Event(nullptr));
- config.addListener("updateOnlineList", this);
- config.addListener("groupFriends", this);
- mGroupFriends = config.getBoolValue("groupFriends");
-}
-
-WhoIsOnline::~WhoIsOnline()
-{
- config.removeListeners(this);
- CHECKLISTENERS
-
- SDL::WaitThread(mThread);
- mThread = nullptr;
- free(mMemoryBuffer);
- mMemoryBuffer = nullptr;
-
- // Remove possibly leftover temporary download
- delete []mCurlError;
-
- FOR_EACH (std::set<OnlinePlayer*>::iterator, itd, mOnlinePlayers)
- delete *itd;
- mOnlinePlayers.clear();
- mOnlineNicks.clear();
-}
-
-void WhoIsOnline::handleLink(const std::string& link, MouseEvent *event)
-{
- if ((event == nullptr) || event->getButton() == MouseButton::LEFT)
- {
- if (chatWindow != nullptr)
- {
- const std::string text = decodeLinkText(link);
- if (config.getBoolValue("whispertab"))
- {
- chatWindow->localChatInput("/q " + text);
- }
- else
- {
- chatWindow->addInputText(std::string("/w \"").append(
- text).append("\" "));
- }
- }
- }
- else if (event->getButton() == MouseButton::RIGHT)
- {
- if ((localPlayer != nullptr) && link == localPlayer->getName())
- return;
-
- if (popupMenu != nullptr)
- {
- if (actorManager != nullptr)
- {
- const std::string text = decodeLinkText(link);
- Being *const being = actorManager->findBeingByName(
- text, ActorType::Player);
-
- if ((being != nullptr) && (popupManager != nullptr))
- {
- popupMenu->showPopup(viewport->mMouseX,
- viewport->mMouseY,
- being);
- return;
- }
- }
- popupMenu->showPlayerPopup(link);
- }
- }
-}
-
-void WhoIsOnline::updateWindow(size_t numOnline)
-{
- // Set window caption
- // TRANSLATORS: who is online window name
- setCaption(_("Who Is Online - ") + toString(CAST_U32(numOnline)));
-
- // List the online people
- std::sort(mFriends.begin(), mFriends.end(), nameCompare);
- std::sort(mNeutral.begin(), mNeutral.end(), nameCompare);
- std::sort(mDisregard.begin(), mDisregard.end(), nameCompare);
- bool addedFromSection(false);
- FOR_EACH (STD_VECTOR<OnlinePlayer*>::const_iterator, it, mFriends)
- {
- mBrowserBox->addRow((*it)->getText());
- addedFromSection = true;
- }
- if (addedFromSection == true)
- {
- mBrowserBox->addRow("---");
- addedFromSection = false;
- }
- FOR_EACH (STD_VECTOR<OnlinePlayer*>::const_iterator, it, mEnemy)
- {
- mBrowserBox->addRow((*it)->getText());
- addedFromSection = true;
- }
- if (addedFromSection == true)
- {
- mBrowserBox->addRow("---");
- addedFromSection = false;
- }
- FOR_EACH (STD_VECTOR<OnlinePlayer*>::const_iterator, it, mNeutral)
- {
- mBrowserBox->addRow((*it)->getText());
- addedFromSection = true;
- }
- if (addedFromSection == true && !mDisregard.empty())
- mBrowserBox->addRow("---");
-
- FOR_EACH (STD_VECTOR<OnlinePlayer*>::const_iterator, it, mDisregard)
- mBrowserBox->addRow((*it)->getText());
-
- if (mScrollArea->getVerticalMaxScroll() <
- mScrollArea->getVerticalScrollAmount())
- {
- mScrollArea->setVerticalScrollAmount(
- mScrollArea->getVerticalMaxScroll());
- }
- mBrowserBox->updateHeight();
-}
-
-void WhoIsOnline::handlerPlayerRelation(const std::string &nick,
- OnlinePlayer *const player)
-{
- if (player == nullptr)
- return;
- switch (playerRelations.getRelation(nick))
- {
- case Relation::NEUTRAL:
- default:
- setNeutralColor(player);
- mNeutral.push_back(player);
- break;
-
- case Relation::FRIEND:
- player->setText("2");
- if (mGroupFriends)
- mFriends.push_back(player);
- else
- mNeutral.push_back(player);
- break;
-
- case Relation::DISREGARDED:
- case Relation::BLACKLISTED:
- player->setText("8");
- mDisregard.push_back(player);
- break;
-
- case Relation::ENEMY2:
- player->setText("1");
- mEnemy.push_back(player);
- break;
-
- case Relation::IGNORED:
- case Relation::ERASED:
- // Ignore the ignored.
- break;
- }
-}
-
-void WhoIsOnline::loadList(const STD_VECTOR<OnlinePlayer*> &list)
-{
- mBrowserBox->clearRows();
- const size_t numOnline = list.size();
-
- FOR_EACH (std::set<OnlinePlayer*>::iterator, itd, mOnlinePlayers)
- delete *itd;
- mOnlinePlayers.clear();
- mOnlineNicks.clear();
-
- mShowLevel = config.getBoolValue("showlevel");
-
- FOR_EACH (STD_VECTOR<OnlinePlayer*>::const_iterator, it, list)
- {
- OnlinePlayer *player = *it;
- const std::string nick = player->getNick();
- mOnlinePlayers.insert(player);
- mOnlineNicks.insert(nick);
-
- if (!mShowLevel)
- player->setLevel(0);
-
- handlerPlayerRelation(nick, player);
- }
-
- updateWindow(numOnline);
- if (!mOnlineNicks.empty())
- {
- if (chatWindow != nullptr)
- chatWindow->updateOnline(mOnlineNicks);
- if (socialWindow != nullptr)
- socialWindow->updateActiveList();
- if (actorManager != nullptr)
- actorManager->updateSeenPlayers(mOnlineNicks);
- }
- updateSize();
- mFriends.clear();
- mNeutral.clear();
- mDisregard.clear();
- mEnemy.clear();
-}
-
-#ifdef TMWA_SUPPORT
-void WhoIsOnline::loadWebList()
-{
- if (mMemoryBuffer == nullptr)
- return;
-
- // Reallocate and include terminating 0 character
- mMemoryBuffer = static_cast<char*>(
- realloc(mMemoryBuffer, mDownloadedBytes + 1));
- if (mMemoryBuffer == nullptr)
- return;
-
- mMemoryBuffer[mDownloadedBytes] = '\0';
-
- mBrowserBox->clearRows();
- bool listStarted(false);
- std::string lineStr;
- size_t numOnline(0U);
-
- // Tokenize and add each line separately
- char *line = strtok(mMemoryBuffer, "\n");
- const std::string gmText("(GM)");
- const std::string gmText2("(gm)");
-
- FOR_EACH (std::set<OnlinePlayer*>::iterator, itd, mOnlinePlayers)
- delete *itd;
-
- mOnlinePlayers.clear();
- mOnlineNicks.clear();
-
- mShowLevel = config.getBoolValue("showlevel");
-
- while (line != nullptr)
- {
- std::string nick;
- lineStr = line;
- trim(lineStr);
- if (listStarted == true)
- {
- if (lineStr.find(" users are online.") == std::string::npos)
- {
- if (lineStr.length() > 24)
- {
- nick = lineStr.substr(0, 24);
- lineStr = lineStr.substr(25);
- }
- else
- {
- nick = lineStr;
- lineStr.clear();
- }
- trim(nick);
-
- bool isGM(false);
- size_t pos = lineStr.find(gmText, 0);
- if (pos != std::string::npos)
- {
- lineStr = lineStr.substr(pos + gmText.length());
- isGM = true;
- }
- else
- {
- pos = lineStr.find(gmText2, 0);
- if (pos != std::string::npos)
- {
- lineStr = lineStr.substr(pos + gmText.length());
- isGM = true;
- }
- }
-
- trim(lineStr);
- pos = lineStr.find('/', 0);
-
- if (pos != std::string::npos)
- lineStr = lineStr.substr(0, pos);
-
- int level = 0;
- if (!lineStr.empty())
- level = atoi(lineStr.c_str());
-
- if (actorManager != nullptr)
- {
- Being *const being = actorManager->findBeingByName(
- nick, ActorType::Player);
- if (being != nullptr)
- {
- if (level > 0)
- {
- being->setLevel(level);
- being->updateName();
- }
- else
- {
- if (being->getLevel() > 1)
- level = being->getLevel();
- }
- }
- }
-
- if (!mShowLevel)
- level = 0;
-
- OnlinePlayer *const player = new OnlinePlayer(nick,
- CAST_U8(255), level,
- Gender::UNSPECIFIED, -1);
- mOnlinePlayers.insert(player);
- mOnlineNicks.insert(nick);
-
- if (isGM)
- player->setIsGM(true);
-
- numOnline++;
- handlerPlayerRelation(nick, player);
- }
- }
- else if (lineStr.find("------------------------------")
- != std::string::npos)
- {
- listStarted = true;
- }
- line = strtok(nullptr, "\n");
- }
-
- updateWindow(numOnline);
- mBrowserBox->updateHeight();
-
- // Free the memory buffer now that we don't need it anymore
- free(mMemoryBuffer);
- mMemoryBuffer = nullptr;
- mFriends.clear();
- mNeutral.clear();
- mDisregard.clear();
- mEnemy.clear();
-}
-
-size_t WhoIsOnline::memoryWrite(void *restrict ptr,
- size_t size,
- size_t nmemb,
- FILE *restrict stream)
-{
- if (stream == nullptr)
- return 0;
-
- WhoIsOnline *restrict const wio =
- reinterpret_cast<WhoIsOnline *restrict>(stream);
- const size_t totalMem = size * nmemb;
- wio->mMemoryBuffer = static_cast<char*>(realloc(wio->mMemoryBuffer,
- CAST_SIZE(wio->mDownloadedBytes) + totalMem));
- if (wio->mMemoryBuffer != nullptr)
- {
- memcpy(&(wio->mMemoryBuffer[wio->mDownloadedBytes]), ptr, totalMem);
- wio->mDownloadedBytes += CAST_S32(totalMem);
- }
-
- return totalMem;
-}
-
-int WhoIsOnline::downloadThread(void *ptr)
-{
- int attempts = 0;
- WhoIsOnline *const wio = reinterpret_cast<WhoIsOnline *>(ptr);
- if (wio == nullptr)
- return 0;
- CURLcode res;
- const std::string url(settings.onlineListUrl + "/online.txt");
-
- while (attempts < 1 && !wio->mDownloadComplete)
- {
- CURL *curl = curl_easy_init();
- if (curl != nullptr)
- {
- if (!wio->mAllowUpdate)
- {
- curl_easy_cleanup(curl);
- curl = nullptr;
- break;
- }
- wio->mDownloadedBytes = 0;
- curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
- curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
- &WhoIsOnline::memoryWrite);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, ptr);
-
- curl_easy_setopt(curl,
- CURLOPT_USERAGENT,
- settings.userAgent.c_str());
-
- curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, wio->mCurlError);
- curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
- curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
- curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, ptr);
-
-#if LIBCURL_VERSION_NUM >= 0x070a00
- curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
-#endif // LIBCURL_VERSION_NUM >= 0x070a00
- curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 7);
- curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30);
- Net::Download::addHeaders(curl);
- Net::Download::addProxy(curl);
- Net::Download::secureCurl(curl);
-
- // Make sure the resources2.txt and news.txt aren't cached,
- // in order to always get the latest version.
- struct curl_slist *pHeaders = nullptr;
- pHeaders = curl_slist_append(
- pHeaders, "pragma: no-cache");
- pHeaders = curl_slist_append(pHeaders,
- "Cache-Control: no-cache");
- curl_easy_setopt(curl, CURLOPT_HTTPHEADER, pHeaders);
-
- if ((res = curl_easy_perform(curl)) != 0)
- {
- wio->mDownloadStatus = UPDATE_ERROR;
- PRAGMA45(GCC diagnostic push)
- PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
- switch (res)
- {
- case CURLE_COULDNT_CONNECT:
- default:
- std::cerr << "curl error "
- << CAST_U32(res) << ": "
- << wio->mCurlError << " host: "
- << url.c_str() << std::endl;
- break;
- }
- PRAGMA45(GCC diagnostic pop)
- attempts++;
- curl_easy_cleanup(curl);
- curl_slist_free_all(pHeaders);
- curl = nullptr;
- continue;
- }
-
- curl_easy_cleanup(curl);
- curl_slist_free_all(pHeaders);
-
- // It's stored in memory, we're done
- wio->mDownloadComplete = true;
- }
- if (!wio->mAllowUpdate)
- break;
- attempts++;
- }
-
- if (!wio->mDownloadComplete)
- wio->mDownloadStatus = UPDATE_ERROR;
- return 0;
-}
-#endif // TMWA_SUPPORT
-
-void WhoIsOnline::download()
-{
- if (mServerSideList)
- {
- if (PacketLimiter::limitPackets(PacketType::PACKET_ONLINELIST))
- playerHandler->requestOnlineList();
- }
-#ifdef TMWA_SUPPORT
- else if (mWebList)
- {
- mDownloadComplete = true;
- SDL::WaitThread(mThread);
- mThread = nullptr;
- mDownloadComplete = false;
- mThread = SDL::createThread(&WhoIsOnline::downloadThread,
- "whoisonline", this);
- if (mThread == nullptr)
- mDownloadStatus = UPDATE_ERROR;
- }
-#endif // TMWA_SUPPORT
-}
-
-void WhoIsOnline::logic()
-{
- BLOCK_START("WhoIsOnline::logic")
- mScrollArea->logic();
- BLOCK_END("WhoIsOnline::logic")
-}
-
-void WhoIsOnline::slowLogic()
-{
- if (!mAllowUpdate)
- return;
-
- BLOCK_START("WhoIsOnline::slowLogic")
- if (mUpdateTimer == 0)
- mUpdateTimer = cur_time;
-
- const double timeDiff = difftime(cur_time, mUpdateTimer);
- const int timeLimit = isWindowVisible() ? 20 : 120;
-
- if (mUpdateOnlineList && timeDiff >= timeLimit
- && mDownloadStatus != UPDATE_LIST)
- {
- if (mDownloadComplete == true)
- {
- // TRANSLATORS: who is online window name
- setCaption(_("Who Is Online - Updating"));
- mUpdateTimer = 0;
- mDownloadStatus = UPDATE_LIST;
- download();
- }
- }
-
-#ifdef TMWA_SUPPORT
- switch (mDownloadStatus)
- {
- case UPDATE_ERROR:
- logger->assertLog("Failed to fetch the online list:");
- if (mCurlError != nullptr)
- logger->assertLog("%s", mCurlError);
- mDownloadStatus = UPDATE_COMPLETE;
- // TRANSLATORS: who is online window name
- setCaption(_("Who Is Online - error"));
- mUpdateButton->setEnabled(true);
- mUpdateTimer = cur_time + 240;
- mDownloadComplete = true;
- updateSize();
- break;
- case UPDATE_LIST:
- if (mDownloadComplete == true)
- {
- loadWebList();
- mDownloadStatus = UPDATE_COMPLETE;
- mUpdateButton->setEnabled(true);
- mUpdateTimer = 0;
- updateSize();
- if (!mOnlineNicks.empty())
- {
- if (chatWindow != nullptr)
- chatWindow->updateOnline(mOnlineNicks);
- if (socialWindow != nullptr)
- socialWindow->updateActiveList();
- if (actorManager != nullptr)
- actorManager->updateSeenPlayers(mOnlineNicks);
- }
- }
- break;
- case UPDATE_COMPLETE:
- default:
- break;
- }
-#endif // TMWA_SUPPORT
-
- BLOCK_END("WhoIsOnline::slowLogic")
-}
-
-void WhoIsOnline::action(const ActionEvent &event)
-{
- if (event.getId() == "update")
- {
-#ifdef TMWA_SUPPORT
- if (!mServerSideList)
- {
- if (mDownloadStatus == UPDATE_COMPLETE)
- {
- mUpdateTimer = cur_time - 20;
- if (mUpdateButton != nullptr)
- mUpdateButton->setEnabled(false);
- // TRANSLATORS: who is online window name
- setCaption(_("Who Is Online - Update"));
- SDL::WaitThread(mThread);
- mThread = nullptr;
- mDownloadComplete = true;
- }
- }
- else
-#endif // TMWA_SUPPORT
- {
- if (PacketLimiter::limitPackets(PacketType::PACKET_ONLINELIST))
- {
- mUpdateTimer = cur_time;
- playerHandler->requestOnlineList();
- }
- }
- }
-}
-
-void WhoIsOnline::widgetResized(const Event &event)
-{
- Window::widgetResized(event);
- updateSize();
-}
-
-void WhoIsOnline::updateSize()
-{
- const Rect area = getChildrenArea();
- if (mUpdateButton != nullptr)
- mUpdateButton->setWidth(area.width - 10);
-
- if (mScrollArea != nullptr)
- mScrollArea->setSize(area.width - 10, area.height - 10 - 30);
-}
-
-const std::string WhoIsOnline::prepareNick(const std::string &restrict nick,
- const int level,
- const std::string &restrict
- color) const
-{
- const std::string text = encodeLinkText(nick);
- if (mShowLevel && level > 1)
- {
- return strprintf("@@%s|##%s%s (%d)@@", text.c_str(),
- color.c_str(), text.c_str(), level);
- }
- return strprintf("@@%s|##%s%s@@", text.c_str(),
- color.c_str(), text.c_str());
-}
-
-void WhoIsOnline::optionChanged(const std::string &name)
-{
- if (name == "updateOnlineList")
- mUpdateOnlineList = config.getBoolValue("updateOnlineList");
- else if (name == "groupFriends")
- mGroupFriends = config.getBoolValue("groupFriends");
-}
-
-void WhoIsOnline::setNeutralColor(OnlinePlayer *const player)
-{
- if (player == nullptr)
- return;
-
- if ((actorManager != nullptr) && (localPlayer != nullptr))
- {
- const std::string &nick = player->getNick();
- if (nick == localPlayer->getName())
- {
- player->setText("s");
- return;
- }
- if (localPlayer->isInParty())
- {
- const Party *const party = localPlayer->getParty();
- if (party != nullptr)
- {
- if (party->getMember(nick) != nullptr)
- {
- player->setText("P");
- return;
- }
- }
- }
-
- const Being *const being = actorManager->findBeingByName(nick);
- if (being != nullptr)
- {
- const Guild *const guild2 = localPlayer->getGuild();
- if (guild2 != nullptr)
- {
- const Guild *const guild1 = being->getGuild();
- if (guild1 != nullptr)
- {
- if (guild1->getId() == guild2->getId()
- || (guild2->getMember(nick) != nullptr))
- {
- player->setText("U");
- return;
- }
- }
- else if (guild2->isMember(nick))
- {
- player->setText("U");
- return;
- }
- }
- }
- const Guild *const guild3 = Guild::getGuild(1);
- if ((guild3 != nullptr) && guild3->isMember(nick))
- {
- player->setText("U");
- return;
- }
- }
- player->setText("0");
-}
-
-void WhoIsOnline::getPlayerNames(StringVect &names)
-{
- names.clear();
- FOR_EACH (std::set<std::string>::const_iterator, it, mOnlineNicks)
- names.push_back(*it);
-}
-
-void OnlinePlayer::setText(std::string color)
-{
- mText.clear();
-
- if (mStatus != 255 && (actorManager != nullptr))
- {
- Being *const being = actorManager->findBeingByName(
- mNick, ActorType::Player);
- if (being != nullptr)
- {
- being->setState(mStatus);
- // for now highlight versions > 3
- if (mVersion > 3)
- being->setAdvanced(true);
- }
- }
-
- if ((mStatus != 255 && ((mStatus & BeingFlag::GM) != 0)) || mIsGM)
- mText.append("(GM) ");
-
- if (mLevel > 0)
- mText.append(strprintf("%d", mLevel));
-
- if (mGender == Gender::FEMALE)
- mText.append("\u2640");
- else if (mGender == Gender::MALE)
- mText.append("\u2642");
-
- if (mStatus > 0 && mStatus != 255)
- {
- if ((mStatus & BeingFlag::SHOP) != 0)
- mText.append("$");
- if ((mStatus & BeingFlag::AWAY) != 0)
- {
- // TRANSLATORS: this away status writed in player nick
- mText.append(_("A"));
- }
- if ((mStatus & BeingFlag::INACTIVE) != 0)
- {
- // TRANSLATORS: this inactive status writed in player nick
- mText.append(_("I"));
- }
-
- if (((mStatus & BeingFlag::GM) != 0) && color == "0")
- color = "2";
- }
- else if (mIsGM && color == "0")
- {
- color = "2";
- }
-
- if (mVersion > 0)
- mText.append(strprintf(" - %d", mVersion));
-
- const std::string text = encodeLinkText(mNick);
- mText = strprintf("@@%s|##%s%s %s@@", text.c_str(), color.c_str(),
- text.c_str(), mText.c_str());
-}
diff --git a/src/gui/windows/whoisonline.h b/src/gui/windows/whoisonline.h
deleted file mode 100644
index afdb43785..000000000
--- a/src/gui/windows/whoisonline.h
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_WHOISONLINE_H
-#define GUI_WINDOWS_WHOISONLINE_H
-
-#include "gui/widgets/linkhandler.h"
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-
-class Button;
-class OnlinePlayer;
-class ScrollArea;
-class StaticBrowserBox;
-
-/**
- * Update progress window GUI
- *
- * \ingroup GUI
- */
-class WhoIsOnline final : public Window,
- public LinkHandler,
- public ActionListener,
- public ConfigListener
-{
- public:
- /**
- * Constructor.
- */
- WhoIsOnline();
-
- A_DELETE_COPY(WhoIsOnline)
-
- /**
- * Destructor
- */
- ~WhoIsOnline();
-
- void postInit() override final;
-
-#ifdef TMWA_SUPPORT
- /**
- * Loads and display online list from the memory buffer.
- */
- void loadWebList();
-#endif // TMWA_SUPPORT
-
- void loadList(const STD_VECTOR<OnlinePlayer*> &list);
-
- void handleLink(const std::string& link,
- MouseEvent *event) override final;
-
- void logic() override final;
-
- void slowLogic();
-
- void action(const ActionEvent &event) override final;
-
- void widgetResized(const Event &event) override final;
-
- const std::set<OnlinePlayer*> &getOnlinePlayers() const noexcept2
- A_WARN_UNUSED
- { return mOnlinePlayers; }
-
- const std::set<std::string> &getOnlineNicks() const noexcept2
- A_WARN_UNUSED
- { return mOnlineNicks; }
-
- void setAllowUpdate(const bool n) noexcept2
- { mAllowUpdate = n; }
-
- void optionChanged(const std::string &name) override final;
-
- void updateList(StringVect &list);
-
- void readFromWeb();
-
- static void setNeutralColor(OnlinePlayer *const player);
-
- void getPlayerNames(StringVect &names);
-
- private:
- void download();
-
- void updateSize();
-
- void handlerPlayerRelation(const std::string &nick,
- OnlinePlayer *const player);
-
-#ifdef TMWA_SUPPORT
- /**
- * The thread function that download the files.
- */
- static int downloadThread(void *ptr);
-
- /**
- * A libcurl callback for writing to memory.
- */
- static size_t memoryWrite(void *restrict ptr,
- size_t size,
- size_t nmemb,
- FILE *restrict stream);
-#endif // TMWA_SUPPORT
-
- const std::string prepareNick(const std::string &restrict nick,
- const int level,
- const std::string &restrict color)
- const A_WARN_UNUSED;
-
- void updateWindow(size_t numOnline);
-
- enum DownloadStatus
- {
- UPDATE_ERROR = 0,
- UPDATE_COMPLETE,
- UPDATE_LIST
- };
-
- time_t mUpdateTimer;
-
- /** A thread that use libcurl to download updates. */
- SDL_Thread *mThread;
-
- /** Buffer for files downloaded to memory. */
- char *mMemoryBuffer;
-
- /** Buffer to handler human readable error provided by curl. */
- char *mCurlError A_NONNULLPOINTER;
-
- StaticBrowserBox *mBrowserBox A_NONNULLPOINTER;
- ScrollArea *mScrollArea A_NONNULLPOINTER;
- Button *mUpdateButton A_NONNULLPOINTER;
-
- std::set<OnlinePlayer*> mOnlinePlayers;
- std::set<std::string> mOnlineNicks;
-
- STD_VECTOR<OnlinePlayer*> mFriends;
- STD_VECTOR<OnlinePlayer*> mNeutral;
- STD_VECTOR<OnlinePlayer*> mDisregard;
- STD_VECTOR<OnlinePlayer*> mEnemy;
-
- /** Byte count currently downloaded in mMemoryBuffer. */
- int mDownloadedBytes;
-
- /** Status of the current download. */
- WhoIsOnline::DownloadStatus mDownloadStatus;
-
- /** Flag that show if current download is complete. */
- bool mDownloadComplete;
- bool mAllowUpdate;
- bool mShowLevel;
- bool mUpdateOnlineList;
- bool mGroupFriends;
-#ifdef TMWA_SUPPORT
- bool mWebList;
-#endif
- bool mServerSideList;
-};
-
-extern WhoIsOnline *whoIsOnline;
-
-#endif // GUI_WINDOWS_WHOISONLINE_H
diff --git a/src/gui/windows/worldselectdialog.cpp b/src/gui/windows/worldselectdialog.cpp
deleted file mode 100644
index 919440a40..000000000
--- a/src/gui/windows/worldselectdialog.cpp
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/windows/worldselectdialog.h"
-
-#include "client.h"
-#include "settings.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/layout.h"
-#include "gui/widgets/listbox.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "gui/models/worldlistmodel.h"
-
-#include "net/loginhandler.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-extern WorldInfo **server_info;
-
-WorldSelectDialog::WorldSelectDialog(const Worlds &worlds) :
- // TRANSLATORS: world select dialog name
- Window(_("Select World"), Modal_false, nullptr, "world.xml"),
- ActionListener(),
- KeyListener(),
- mWorldListModel(new WorldListModel(worlds)),
- mWorldList(CREATEWIDGETR(ListBox, this, mWorldListModel, "")),
- // TRANSLATORS: world dialog button
- mChangeLoginButton(new Button(this, _("Change Login"), "login", this)),
- // TRANSLATORS: world dialog button
- mChooseWorld(new Button(this, _("Choose World"), "world", this))
-{
- ScrollArea *const worldsScroll = new ScrollArea(this, mWorldList,
- fromBool(getOptionBool("showbackground"), Opaque),
- "world_background.xml");
-
- worldsScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
-
- place(0, 0, worldsScroll, 3, 5).setPadding(2);
- place(1, 5, mChangeLoginButton);
- place(2, 5, mChooseWorld);
-
- // Make sure the list has enough height
- getLayout().setRowHeight(0, 60);
-
- reflowLayout(0, 0);
-
- if (worlds.empty())
- {
- // Disable Ok button
- mChooseWorld->setEnabled(false);
- }
- else
- {
- // Select first server
- mWorldList->setSelected(0);
- }
-
- addKeyListener(this);
-
- center();
-}
-
-void WorldSelectDialog::postInit()
-{
- Window::postInit();
- setVisible(Visible_true);
- mChooseWorld->requestFocus();
-}
-
-WorldSelectDialog::~WorldSelectDialog()
-{
- delete2(mWorldListModel);
-}
-
-void WorldSelectDialog::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "world")
- {
- mChangeLoginButton->setEnabled(false);
- mChooseWorld->setEnabled(false);
- loginHandler->chooseServer(mWorldList->getSelected(),
- settings.persistentIp);
-
- // Check in case netcode moves us forward
- if (client->getState() == State::WORLD_SELECT)
- client->setState(State::WORLD_SELECT_ATTEMPT);
- }
- else if (eventId == "login")
- {
- client->setState(State::PRE_LOGIN);
- }
-}
-
-void WorldSelectDialog::keyPressed(KeyEvent &event)
-{
- const InputActionT actionId = event.getActionId();
-
- if (actionId == InputAction::GUI_CANCEL)
- {
- action(ActionEvent(nullptr,
- mChangeLoginButton->getActionEventId()));
- }
- else if (actionId == InputAction::GUI_SELECT ||
- actionId == InputAction::GUI_SELECT2)
- {
- action(ActionEvent(nullptr, mChooseWorld->getActionEventId()));
- }
-}
diff --git a/src/gui/windows/worldselectdialog.h b/src/gui/windows/worldselectdialog.h
deleted file mode 100644
index 4c6dc0f8c..000000000
--- a/src/gui/windows/worldselectdialog.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WINDOWS_WORLDSELECTDIALOG_H
-#define GUI_WINDOWS_WORLDSELECTDIALOG_H
-
-#include "gui/widgets/window.h"
-
-#include "net/worldinfo.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/keylistener.h"
-
-class Button;
-class ListBox;
-class WorldListModel;
-
-/**
- * The server select dialog.
- *
- * \ingroup Interface
- */
-class WorldSelectDialog final : public Window,
- public ActionListener,
- public KeyListener
-{
- public:
- /**
- * Constructor
- *
- * @see Window::Window
- */
- explicit WorldSelectDialog(const Worlds &worlds);
-
- A_DELETE_COPY(WorldSelectDialog)
-
- void postInit() override final;
-
- /**
- * Destructor.
- */
- ~WorldSelectDialog();
-
- /**
- * Called when receiving actions from the widgets.
- */
- void action(const ActionEvent &event) override final;
-
- void keyPressed(KeyEvent &event) override final;
-
- private:
- WorldListModel *mWorldListModel A_NONNULLPOINTER;
- ListBox *mWorldList A_NONNULLPOINTER;
- Button *mChangeLoginButton A_NONNULLPOINTER;
- Button *mChooseWorld A_NONNULLPOINTER;
-};
-
-#endif // GUI_WINDOWS_WORLDSELECTDIALOG_H