Permalink
Browse files

fixed multiplayer's menu

  • Loading branch information...
cflavio committed Oct 4, 2017
1 parent 13e3ebd commit 1298ce6470f30c11623d33dc429859d261f3cf19
Showing with 71 additions and 76 deletions.
  1. +15 −15 menu/carpage.py
  2. +13 −15 menu/clientpage.py
  3. +2 −2 menu/mainpage.py
  4. +21 −3 menu/menu.py
  5. +8 −18 menu/multiplayerpage.py
  6. +9 −19 menu/serverpage.py
  7. +2 −3 menu/trackpage.py
  8. +1 −1 yyagl
View
@@ -105,17 +105,17 @@ class CarPageGuiServer(CarPageGui):
def bld_page(self):
CarPageGui.bld_page(self)
self.eng.register_server_cb(self.process_srv)
self.eng.server.register_cb(self.process_srv)
self.eng.car_mapping = {}
def on_car(self, car):
self.eng.log('car selected: ' + car)
self.eng.log_mgr.log('car selected: ' + car)
self.eng.server.send([NetMsgs.car_selection, car])
for btn in self._buttons(car):
btn.disable()
if self in self.current_cars:
curr_car = self.current_cars[self]
self.eng.log('car deselected: ' + curr_car)
self.eng.log_mgr.log('car deselected: ' + curr_car)
self.eng.server.send([NetMsgs.car_deselection, curr_car])
for btn in self._buttons(curr_car):
btn.enable()
@@ -124,7 +124,7 @@ def on_car(self, car):
self.evaluate_starting()
def evaluate_starting(self):
connections = self.eng.connections + [self]
connections = self.eng.server.connections + [self]
if not all(conn in self.current_cars for conn in connections): return
packet = [NetMsgs.start_race, len(self.current_cars)]
@@ -134,7 +134,7 @@ def process(k):
for k, val in self.current_cars.items():
packet += [process(k), val]
self.eng.server.send(packet)
self.eng.log('start race: ' + str(packet))
self.eng.log_mgr.log('start race: ' + str(packet))
curr_car = self.current_cars[self]
# manage as event
#game.logic.season = SingleRaceSeason()
@@ -143,13 +143,13 @@ def process(k):
def process_srv(self, data_lst, sender):
if data_lst[0] != NetMsgs.car_request: return
car = data_lst[1]
self.eng.log('car requested: ' + car)
self.eng.log_mgr.log('car requested: ' + car)
btn = self._buttons(car)[0]
if btn['state'] == DISABLED:
self.eng.server.send([NetMsgs.car_deny], sender)
self.eng.log('car already selected: ' + car)
self.eng.log_mgr.log('car already selected: ' + car)
elif btn['state'] == NORMAL:
self.eng.log('car selected: ' + car)
self.eng.log_mgr.log('car selected: ' + car)
if sender in self.current_cars:
_btn = self._buttons(self.current_cars[sender])[0]
_btn.enable()
@@ -165,10 +165,10 @@ class CarPageGuiClient(CarPageGui):
def bld_page(self):
CarPageGui.bld_page(self)
self.eng.register_client_cb(self.process_client)
self.eng.client.register_cb(self.process_client)
def on_car(self, car):
self.eng.log('car request: ' + car)
self.eng.log_mgr.log('car request: ' + car)
self.eng.client.send([NetMsgs.car_request, car])
def process_client(self, data_lst, sender):
@@ -177,23 +177,23 @@ def process_client(self, data_lst, sender):
_btn = self._buttons(self.car)[0]
_btn.enable()
self.car = car = data_lst[1]
self.eng.log('car confirmed: ' + car)
self.eng.log_mgr.log('car confirmed: ' + car)
btn = self._buttons(car)[0]
btn.disable()
if data_lst[0] == NetMsgs.car_deny:
self.eng.log('car denied')
self.eng.log_mgr.log('car denied')
if data_lst[0] == NetMsgs.car_selection:
car = data_lst[1]
self.eng.log('car selection: ' + car)
self.eng.log_mgr.log('car selection: ' + car)
btn = self._buttons(car)[0]
btn.disable()
if data_lst[0] == NetMsgs.car_deselection:
car = data_lst[1]
self.eng.log('car deselection: ' + car)
self.eng.log_mgr.log('car deselection: ' + car)
btn = self._buttons(car)[0]
btn.enable()
if data_lst[0] == NetMsgs.start_race:
self.eng.log('start_race: ' + str(data_lst))
self.eng.log_mgr.log('start_race: ' + str(data_lst))
# manage as event
#game.logic.season = SingleRaceSeason()
#game.fsm.demand('Race', self.track_path, self.car, data_lst[2:])
View
@@ -3,7 +3,6 @@
from direct.gui.DirectGui import DirectEntry
from yyagl.engine.gui.page import Page, PageEvent
from yyagl.engine.network.client import ClientError
from .carpage import CarPageClient
from .netmsgs import NetMsgs
from .thankspage import ThanksPageGui
@@ -16,45 +15,44 @@ def on_back(self):
def process_msg(self, data_lst, sender):
if data_lst[0] == NetMsgs.track_selected:
self.eng.log('track selected: ' + data_lst[1])
self.mdt.gui.menu.track = data_lst[1]
self.mdt.gui.menu.push_page(CarPageClient(self.mdt.gui.menu))
self.eng.log_mgr.log('track selected: ' + data_lst[1])
self.notify('on_track_selected', data_lst[1])
self.mdt.gui.notify('on_push_page', 'carpageclient', [self.mdt.gui.props])
class ClientPageGui(ThanksPageGui):
def __init__(self, mdt):
def __init__(self, mdt, props):
self.ent = None
ThanksPageGui.__init__(self, mdt)
self.props = props
ThanksPageGui.__init__(self, mdt, props.gameprops.menu_args)
def bld_page(self):
menu_gui = self.mdt.menu.gui
menu_args = self.mdt.menu.gui.menu_args
menu_args = self.props.gameprops.menu_args
txt = OnscreenText(text=_('Client'), pos=(0, .4),
**menu_gui.menu_args.text_args)
**menu_args.text_args)
self.ent = DirectEntry(
scale=.12, pos=(-.68, 1, .2), entryFont=menu_args.font, width=12,
frameColor=menu_args.btn_color,
initialText=_('insert the server address'))
self.ent.onscreenText['fg'] = menu_args.text_fg
btn = DirectButton(text=_('Connect'), pos=(0, 1, -.2),
command=self.connect, **menu_gui.menu_args.btn_args)
command=self.connect, **menu_args.btn_args)
map(self.add_widget, [txt, self.ent, btn])
ThanksPageGui.bld_page(self)
def connect(self):
menu_gui = self.mdt.menu.gui
menu_args = self.props.gameprops.menu_args
try:
self.eng.log(self.ent.get())
self.eng.log_mgr.log(self.ent.get())
self.eng.client.start(self.mdt.event.process_msg, self.ent.get())
menu_args = self.mdt.menu.gui.menu_args
wait_txt = OnscreenText(
text=_('Waiting for the server'), scale=.12, pos=(0, -.5),
font=menu_gui.font, fg=menu_args.text_fg)
font=menu_args.font, fg=menu_args.text_fg)
self.add_widget(wait_txt)
except ClientError:
txt = OnscreenText(_('Error'), pos=(0, -.05), fg=(1, 0, 0, 1),
scale=.16, font=menu_gui.menu_args.font)
scale=.16, font=menu_args.font)
self.eng.do_later(5, txt.destroy)
View
@@ -35,8 +35,8 @@ def load_settings(self):
def bld_page(self):
sp_cb = lambda: self.notify('on_push_page', 'singleplayer',
[self.props])
mp_cb = lambda: self.menu.push_page(MultiplayerPage(
self.menu.gui.menu_args, self.props, self.menu))
mp_cb = lambda: self.notify('on_push_page', 'multiplayer',
[self.props])
supp_cb = lambda: self.eng.open_browser(self.props.support_url)
cred_cb = lambda: self.notify('on_push_page', 'credits')
menu_data = [
View
@@ -2,9 +2,11 @@
from yyagl.engine.gui.menu import Menu, MenuLogic, MenuGui
from .mainpage import YorgMainPage
from .singleplayerpage import SingleplayerPage
from .trackpage import TrackPage
from .carpage import CarPage
from .carpage import CarPageSeason
from .multiplayerpage import MultiplayerPage
from .serverpage import ServerPage
from .clientpage import ClientPage
from .trackpage import TrackPage, TrackPageServer
from .carpage import CarPage, CarPageServer, CarPageClient, CarPageSeason
from .driverpage import DriverPage
from .optionpage import OptionPage
from .inputpage import InputPage
@@ -24,15 +26,31 @@ def on_push_page(self, page_code, args=[]):
page = SingleplayerPage(args[0])
page.gui.attach(self.on_track_selected)
page.gui.attach(self.on_continue)
if page_code == 'multiplayer':
page = MultiplayerPage(args[0])
if page_code == 'server':
page = ServerPage(args[0])
if page_code == 'client':
page = ClientPage(args[0])
page.event.attach(self.on_track_selected)
if page_code == 'single_race':
page = TrackPage(args[0])
page.gui.attach(self.on_track_selected)
if page_code == 'trackpageserver':
page = TrackPageServer(args[0])
page.gui.attach(self.on_track_selected)
if page_code == 'new_season':
page = CarPageSeason(args[0], self.mdt.track)
page.gui.attach(self.on_car_selected_season)
if page_code == 'car_page':
page = CarPage(args[0], self.mdt.track)
page.gui.attach(self.on_car_selected)
if page_code == 'carpageserver':
page = CarPageServer(args[0], self.mdt.track)
page.gui.attach(self.on_car_selected)
if page_code == 'carpageclient':
page = CarPageClient(args[0], self.mdt.track)
page.gui.attach(self.on_car_selected)
if page_code == 'driver_page':
page = DriverPage(args[0], args[1], args[2])
page.gui.attach(self.on_driver_selected)
View
@@ -1,33 +1,24 @@
from direct.gui.DirectButton import DirectButton
from yyagl.engine.gui.page import Page, PageFacade
from yyagl.gameobject import GameObject
from .serverpage import ServerPage
from .clientpage import ClientPage
from .thankspage import ThanksPageGui
class MultiplayerPageGui(ThanksPageGui):
def __init__(self, mdt, menu_args, mp_props):
def __init__(self, mdt, mp_props):
self.props = mp_props
ThanksPageGui.__init__(self, mdt, menu_args)
ThanksPageGui.__init__(self, mdt, mp_props.gameprops.menu_args)
def bld_page(self):
menu_gui = self.mdt.menu.gui
serverpage_props = ServerPageProps(
self.props.cars, self.props.car_path, self.props.phys_path,
self.props.tracks, self.props.tracks_tr, self.props.track_img,
self.props.player_name, self.props.drivers_img,
self.props.cars_img, self.props.drivers)
scb = lambda: self.mdt.menu.push_page(ServerPage(
self.mdt.menu.gui.menu_args, serverpage_props, self.mdt.menu))
scb = lambda: self.notify('on_push_page', 'server', [self.props])
ccb = lambda: self.notify('on_push_page', 'client', [self.props])
menu_data = [
('Server', scb),
('Client', lambda: self.mdt.menu.push_page(ClientPage(
self.mdt.menu.gui.menu_args, self.mdt.menu)))]
('Client', ccb)]
widgets = [
DirectButton(text=menu[0], pos=(0, 1, .4-i*.28), command=menu[1],
**menu_gui.menu_args.btn_args)
**self.props.gameprops.menu_args.btn_args)
for i, menu in enumerate(menu_data)]
map(self.add_widget, widgets)
ThanksPageGui.bld_page(self)
@@ -36,11 +27,10 @@ def bld_page(self):
class MultiplayerPage(Page):
gui_cls = MultiplayerPageGui
def __init__(self, menu_args, mp_props):
self.menu_args = menu_args
def __init__(self, mp_props):
init_lst = [
[('event', self.event_cls, [self])],
[('gui', self.gui_cls, [self, self.menu_args, mp_props])]]
[('gui', self.gui_cls, [self, mp_props])]]
GameObject.__init__(self, init_lst)
PageFacade.__init__(self)
# invoke Page's __init__
View
@@ -5,7 +5,6 @@
from direct.gui.OnscreenText import OnscreenText
from yyagl.engine.gui.page import Page, PageEvent, PageFacade
from yyagl.gameobject import GameObject
from .trackpage import TrackPageServer
from .thankspage import ThanksPageGui
@@ -20,20 +19,19 @@ def process_msg(data_lst):
print data_lst
def process_connection(self, client_address):
self.eng.log('connection from ' + client_address)
self.eng.log_mgr.log('connection from ' + client_address)
self.mdt.gui.conn_txt.setText(_('connection from ') + client_address)
class ServerPageGui(ThanksPageGui):
def __init__(self, mdt, menu_args, serverpage_props):
def __init__(self, mdt, serverpage_props):
self.conn_txt = None
self.props = serverpage_props
ThanksPageGui.__init__(self, mdt, menu_args)
ThanksPageGui.__init__(self, mdt, serverpage_props.gameprops.menu_args)
def bld_page(self):
menu_gui = self.menu.gui
menu_args = self.menu.gui.menu_args
menu_args = self.props.gameprops.menu_args
sock = socket(AF_INET, SOCK_DGRAM)
try:
sock.connect(('ya2.it', 0))
@@ -44,20 +42,13 @@ def bld_page(self):
text=addr, scale=.12, pos=(0, .4), font=menu_args.font,
fg=menu_args.text_fg))
except gaierror:
self.eng.log('no connection')
self.eng.log_mgr.log('no connection')
self.conn_txt = OnscreenText(
scale=.12, pos=(0, .2), font=menu_args.font, fg=menu_args.text_fg)
self.add_widget(self.conn_txt)
tp_props = TrackPageProps(
self.props.cars, self.props.car_path, self.props.phys_path,
self.props.tracks, self.props.tracks_tr, self.props.track_img,
self.props.player_name, self.props.drivers_img,
self.props.cars_img, self.props.drivers)
scb = lambda: self.notify('on_push_page', 'trackpageserver', [self.props])
self.add_widget(DirectButton(
text=_('Start'), pos=(0, 1, -.5),
command=lambda: self.menu.push_page(
TrackPageServer(menu_args, tp_props, self.menu)),
**menu_gui.menu_args.btn_args))
text=_('Start'), pos=(0, 1, -.5), command=scb, **menu_args.btn_args))
ThanksPageGui.bld_page(self)
evt = self.mdt.event
self.eng.server.start(evt.process_msg, evt.process_connection)
@@ -67,11 +58,10 @@ class ServerPage(Page):
gui_cls = ServerPageGui
event_cls = ServerEvent
def __init__(self, menu_args, serverpage_props):
self.menu_args = menu_args
def __init__(self, serverpage_props):
init_lst = [
[('event', self.event_cls, [self])],
[('gui', self.gui_cls, [self, self.menu_args, serverpage_props])]]
[('gui', self.gui_cls, [self, serverpage_props])]]
GameObject.__init__(self, init_lst)
PageFacade.__init__(self)
# invoke Page's __init__
View
@@ -3,7 +3,6 @@
from yyagl.engine.gui.page import Page, PageFacade
from yyagl.engine.gui.imgbtn import ImgBtn
from yyagl.gameobject import GameObject
from .carpage import CarPageServer
from .netmsgs import NetMsgs
from .thankspage import ThanksPageGui
@@ -53,8 +52,8 @@ def on_track(self, track):
class TrackPageGuiServer(TrackPageGui):
def on_track(self, track):
self.menu.track = track
self.menu.push_page(CarPageServer())
self.notify('on_track_selected', track)
self.notify('on_push_page', 'carpageserver', [self.props])
self.eng.server.send([NetMsgs.track_selected, track])
2 yyagl

0 comments on commit 1298ce6

Please sign in to comment.