BUG Screen Class?

ruff_hi

Live 4ever! Or die trying
Joined
Oct 24, 2005
Messages
9,135
Location
an Aussie in Boston
(copied from an earlier pm to EF) ...

The way I see it, we should great a screen class that controls:

- title
- tabs along bottom (and spacing)
- events driven off tabs along bottom (non handled events need to be returned to the screen for it to handle)
- which tab is active
- title / tab placement and formatting
- screen height, width, etc
- all associated things (eg widgets) with the above

Is there anything else that a class could handle? If not, I am pretty sure (haha!) that I could handle this - or at least have a stab at it. We will also want to include if a tab is enabled / disabled (think F7 when you change religions - it changes the tabs).

Am I horribly off base on this?

Ruff
 
and his reply (he can shot me later for posting on his behalf) ...

This is essentially what's needed. I hadn't thought of the F7 nastiness. I never liked it anyway. Perhaps we could change that?

Also, F5 puts the GG bar on the tab area now.

As for widgets, some screens name their widgets (tough to remove) while others use generic 1, 2, 3 names. It would be good if the screen could allow either.

As for how to build it, I would make a screen base class, BugScreen. Each actual screen would subclass it and add tabs to it. I would also create a BugTab base class for an individual tab. BugScreen would then manage the many BugTabs on it.

Finally, BugScreen should manage the minimap and provide functions for hiding/showing it based on the tab. Perhaps BugTab should have a "needsMinimap" function that returns True if it uses it. This way the screen knows whether or not to hide it when switching tabs.

BugScreen:
addTab
draw
erase
close
handleInput
selectTab(#)

BugTab:
draw
erase
handleInput
needsMinimap

EF
 
As for how to build it, I would make a screen base class, BugScreen. Each actual screen would subclass it and add tabs to it. I would also create a BugTab base class for an individual tab. BugScreen would then manage the many BugTabs on it.
Not to say that you don't know what you are doing, but isn't each tab (almost) unique. Would a class structure really help there? Or are you looking for the tab class to change the title (if required), kill the widgets, update the yellow / white tab names, tell the screen class which tab is active, etc.

Are you talking about something like this ...

Screen
|- Title
|- TabClass(es)
|- handleInput (see below)
|- current active tab
|- draw (but only the title, tabs, width, height, etc)

I see the 'handleinput' section as setting the active-tab variable.

so (fake code following) ...

Code:
def handle input()

  iScreenInputResult = screenclass.handleinput()
  if iScreenInputResult != -1:
    self.iActiveTab = iScreenInputResult
    return

  <other screen / tab specific code to handle the input>
  return

... and the code that draws the screen (inside the screen python file) ...

Code:
def drawscreen()
  screenclass.draw()
  if screenclass.activetab == 1:
    drawtab1()
  elif screenclass.activetab == 2:
    drawtab2()
 
Your description at the top about the tab class sounds more like what I would have the screen class do. The screen class should manage all of the non-tab-specifics: title, which tab is active, closing, etc. It should dispatch the draw() call to the selected tab, and handle hiding the previous tab when switching tabs. Its handleInput() should check for clicks on the tab headings to call switchTab(), the exit button to close, otherwise dispatching to the visible tab's handleInput() function.

BugScreen

  • tabs - list of tabs
  • activeTab - index of the tab that's active, -1 if none active
  • minimapActive - True if the minimap is visible
Most of the functionality this class provides will control what happens to the screen itself. We would create a subclass for each screen, but it would only need to add the specific tabs for the screen.

BugTab

  • key - used to look up its text label
  • title - its text label
This would be more of a skeleton base class. Most of the functionality will be provided in the subclasses: draw() and handleInput().

Now, this is how I would code it, but that doesn't mean it's the right or only way. The idea is to have as much common functionality provided by the base classes. For ideas on this, take a look at the Strategy Layer. It manages a list of multiple layer types (though there's only one so far). The base layer class has stub functions for hiding and showing itself and controlling edit mode. The actual DotMapLayer subclass does the actual drawing but doesn't keep track of whether or not it's visible.
 
For ideas on this, take a look at the Strategy Layer. It manages a list of multiple layer types (though there's only one so far).
:run: don't make me read your code ... it hurts my eyes it does ...

gollum-precious.jpg


Seriously, not because it is bad or ugly code but because I don't really understand all of this class stuff ... and don't try to explain ... just leave the old dog be.

Anyway, I am going to take a stab at it using a pretty simple screen (F7 - Religious) to see what I can come up with ... then you can laugh and fix it :D. Pretty much what we did with the progress bar class thingo.

I guess I should park this screen class stuff in ScreenUtil.py?
 
Sounds like a good plan. I'd probably call the module BugScreen.py. I try to reserve "Util" for collections of semi-related functions.
 
I looked at setting up the base classes last night but got myself all tied up in knots. So, let me try and attack it from the other end ... basically looking at what each screen will do ...

Code:
class CvReligionScreen:
	"Religion Advisor Screen"

	def __init__(self):

		<snip>

	def interfaceScreen (self):

		F7RelScn = BUGScreen.BUGScreen(screen dimensions and other stuff)

		F7RelScn.addTitle("TXT_KEY_RELIGION_SCREEN_TITLE")
		F7RelScn.addTab(0, "TXT_KEY_RELIGION_CONVERT", self.ReligionConvert)
		F7RelScn.addTab(1, "TXT_KEY_SCREEN_CANCEL", self.ReligionCancel)
		etc

		screen = self.getScreen()
		if screen.isActive():
			return
		else:
			F7RelScn.draw() # this draws the normal stuff (title, tab names, etc)
			F7RelScn.drawActiveTab()   # this calls the required function in the file to show the actual tab details
 
Back
Top Bottom