Skip to content

Commit

Permalink
Added support for printing desciprions on command deck description mi…
Browse files Browse the repository at this point in the history
…ni window.

The command panel has a description field above the cube, which displays button names, the cube side button pressed, and also the same on mouseover.  It is a primitive form of tool-tip.

class Cubeside has been updated to store and return descriptions for individual buttons and the facit itself.  An update function has been added, in case we need to update a facit name dynamically.

The class cube file loading routine now loads the additional description data, and populates the correct areas accordingly.

In the CommandDeck class, the interaction function will now update the descriptions on mouse-click on a valid button; no mouseover yet.

A new font entry was added to globals and populated in the main ironseed class.  The commanddeck class will now render descriptions using this double-sized font during the rendering phase.
  • Loading branch information
nukebloodaxe committed Jan 11, 2023
1 parent 906cf28 commit 294eca9
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 9 deletions.
78 changes: 69 additions & 9 deletions commandDeck.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import helper_functions as h

# The side of a cube, including buttons.


class CubeSide(object):

def __init__(self):
Expand All @@ -32,35 +30,58 @@ def __init__(self):
self.left = None
self.right = None
self.buttons = []
self.sideName = "BAD FACET"

# Add a button to this facet, and also convert for current resolution.
def addButton(self, height, width, x, y, returnValue):
def addButton(self, height, width, x, y, returnValue, description):

self.buttons.append((returnValue, buttons.Button(int((g.height/200)*height),
self.buttons.append((returnValue,
buttons.Button(int((g.height/200)*height),
int((g.width/320)
* width),
(int((g.width/320)*x),
int((g.height/200)*y)))))
int((g.height/200)*y))),
description))

# Update facet name.
def updateSideName(self, name):

self.sideName = name

# Return tuple of False and 0 when nothing matched.
def checkButtonPress(self, position):

match = False
buttonType = 0
buttonDescription = ""

for button in self.buttons:

if button[1].within(position):

match = True
buttonType = button[0]
buttonDescription = button[2]
break

return (match, buttonType)
return (match, buttonType, buttonDescription)

# A cube in memory, stores and interacts with the cube used on the command deck.
# Return a facit description name.
def getSideDescription(self):

return self.sideName

# Return a button description string according to the facit type.
def buttonDescription(self, buttonType):

for button in self.buttons:

if button[0] == buttonType:

return button[2]


# A cube in memory, stores and interacts with the cube used on the command deck.
class Cube(object):

def __init__(self):
Expand Down Expand Up @@ -110,6 +131,25 @@ def loadCubeData(self, file):
temp = (cubeFacetFile.readline().split(
'\n')[0]).split('\t') # Data Line

# Add description text to facets.
while temp[0] != "ENDDESC":

# print(temp)

try:

self.sides[int(temp[0])].updateSideName(temp[1])

except:

print("Absolutely fatal Error loading cube description data!")

temp = (cubeFacetFile.readline().split(
'\n')[0]).split('\t') # Data Line

temp = (cubeFacetFile.readline().split(
'\n')[0]).split('\t') # Data Line

# Add buttons to facets.
while temp[0] != "ENDF":

Expand All @@ -119,7 +159,7 @@ def loadCubeData(self, file):

self.sides[int(temp[0])].addButton(int(temp[1]), int(temp[2]),
int(temp[3]), int(temp[4]),
int(temp[5]))
int(temp[5]), str(temp[6]))
except:

print("Absolutely fatal Error loading cube data!")
Expand Down Expand Up @@ -183,6 +223,7 @@ def __init__(self, ship, crew):
self.cubeFirstDrawXY = (0, 0)
self.subFunctions = [] # sub-functions in operation.
self.buttons = [] # Command deck buttons, not on cube.
self.cubeFocusText = "" # Title of what we are mousing over on cube.

# Load Graphics Layers

Expand Down Expand Up @@ -292,6 +333,11 @@ def __init__(self, ship, crew):

# Position where the date and time should be printed
self.timePosition = (int((g.width/320)*45), int((g.height/200)*194))

# Position where the description text for command buttons should be
# printed.
self.descriptionPosition = (int((g.width/320)*192),
int((g.height/200)*125))

# Planet prerender ; placeholder
self.planetPrerender = object
Expand Down Expand Up @@ -648,9 +694,10 @@ def interact(self, mouseButton):
if cubeCheck[0]:

self.systemState = self.theCube[self.cube.currentSide](cubeCheck[1])
self.cubeFocusText = cubeCheck[2]

# Debug.
print("Cube Check: ", cubeCheck[0], " State: ", cubeCheck[1])
print("Cube Check: ", cubeCheck[0], " State: ", cubeCheck[1], "NAME: ", cubeCheck[2])

# self.systemState = self.theCube[self.cubeFacet](currentPosition)

Expand All @@ -662,6 +709,11 @@ def interact(self, mouseButton):
if changeFacet:

self.cube.changeFacet(button[0])
self.cubeFocusText = self.cube.sides[self.cube.currentSide].getSideDescription()

# Debug
print("Focus Text: ", self.cubeFocusText)

break

return self.systemState
Expand Down Expand Up @@ -746,6 +798,12 @@ def drawInterface(self, displaySurface):
h.renderText([str(g.gameDate)], g.font, displaySurface, g.BLUE,
0, self.timePosition[0], self.timePosition[1])

# Draw the current description of what has been clicked/focussed
# to the text field above the command cube.
h.renderText([self.cubeFocusText], g.font2, displaySurface, g.BLUE,
0, self.descriptionPosition[0],
self.descriptionPosition[1])


# Check stage and run routines for initialization, ongoing ops or exit.
def runCommandDeck(self, displaySurface):
Expand All @@ -766,6 +824,8 @@ def runCommandDeck(self, displaySurface):
# Construct the cube.
self.cube.constructCube(os.path.join('Data_Generators', 'Other', 'IronPy_CubeFacets.tab'))
self.cubeFunctionLoading()
# We default to side 0 for the description at the start.
self.cubeFocusText = self.cube.sides[0].getSideDescription()

elif self.commandStage == 1:

Expand Down
1 change: 1 addition & 0 deletions global_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

# Font global placeholders, initialized in ironseed.py
font = object
font2 = object
offset = object # for this font.

# Totals for items
Expand Down
6 changes: 6 additions & 0 deletions ironSeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def __init__(self):
# Fonts: this is a temporary google font, get it from them.
g.font = pygame.font.Font(os.path.join('Fonts', 'Inconsolata-ExtraBold.ttf'), 14)
g.offset = 15
# Note: temporary doubling, for the command deck.
g.font2 = pygame.font.Font(os.path.join('Fonts', 'Inconsolata-ExtraBold.ttf'), 28)

# Set Window version and Display surface
print("Initialize Screen.")
Expand Down Expand Up @@ -202,6 +204,9 @@ def main_loop(self):
pygame.display.update() # update displayed frames.
break # skip for now.

# create and initialise the game engine clock.
#runningSpeed = pygame.time.Clock()

# Enter main state and logic loop.
while 1:

Expand All @@ -221,3 +226,4 @@ def main_loop(self):
self.state = self.states[self.state](self.displaySurface)
# self.state(self.displaySurface)
pygame.display.update()
#runningSpeed.tick(60) # Run at 60fps.

0 comments on commit 294eca9

Please sign in to comment.